summaryrefslogtreecommitdiff
path: root/kernel/usermode.c
blob: e6568a48e477b5820b0dd54a00c6f3384d1b17ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "usermode.h"
#define FOOLOS_MODULE_NAME "usermode"
#include "lib/logger/log.h"
#include "syscalls.h"



tss_struct sys_tss; //Define the TSS as a global structure


// generic syscall interface!
int syscall(int call, int p1, int p2, int p3)
{
	int ebx; // will hold return value;

	asm("pusha");

	// select syscall
	asm("mov %0, %%eax"::"m"(call)); 

	// pass params
	asm("mov %0,%%edx"::"m"(p1));
	asm("mov %0,%%ecx"::"m"(p2));
	asm("mov %0,%%ebx"::"m"(p3));

	// interrrupt
	asm("int $0x80");

	// get return value
        asm("mov %%ebx, %0": "=b" (ebx));

	asm("popa");

	return ebx;
}
int write(int file, char *ptr, int len) 
{
    return syscall(SYSCALL_WRITE,file,ptr,len);
}
int execve(char *name, char **argv, char **env) 
{
    return syscall(SYSCALL_EXECVE,name,argv,env);
}

void install_tss(int cpu_no){

    // now fill each value
    // set values necessary
    sys_tss.ss0 = 0x10; //kernel data
    sys_tss.esp0 = kballoc(4);

    // now set the IO bitmap (not necessary, so set above limit)       
    // sys_tss.iomap = ( unsigned short ) sizeof( tss_struct ); 
}


void switch_to_user_mode() 
{
    asm_usermode(); 
 //   userfunc();

}

char *argv_init[]={"/bin/init",NULL};
char *env_init[]={"var1=dupa","var2=mundl",NULL};

// THIS WILL BE RUN IN RING 3!
void userfunc()
{
    execve("/bin/init",argv_init,env_init); 
    while(1); // we should never get here.
}