diff options
Diffstat (limited to 'kernel/usermode.c')
| -rw-r--r-- | kernel/usermode.c | 99 |
1 files changed, 76 insertions, 23 deletions
diff --git a/kernel/usermode.c b/kernel/usermode.c index afad9df..339045d 100644 --- a/kernel/usermode.c +++ b/kernel/usermode.c @@ -1,32 +1,85 @@ #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; - // now set the IO bitmap (not necessary, so set above limit) - sys_tss.iomap = ( unsigned short ) sizeof( tss_struct ); + sys_tss.ss0 = 0x10; //kernel data + sys_tss.esp0 = 0x9000; //kernel stack + + // now set the IO bitmap (not necessary, so set above limit) + // sys_tss.iomap = ( unsigned short ) sizeof( tss_struct ); +} + + +void switch_to_user_mode() +{ + char text[]="internal"; + write(1,text,10); + asm_usermode(); + while(1); // will not be reached? } -void switch_to_user_mode() { - // Set up a stack structure for switching to user mode. - asm volatile(" \ - cli; \ - mov $0x23, %ax; \ - mov %ax, %ds; \ - mov %ax, %es; \ - mov %ax, %fs; \ - mov %ax, %gs; \ - \ - mov %esp, %eax; \ - pushl $0x23; \ - pushl %eax; \ - pushf; \ - mov $0x200, %eax; \ - push %eax; \ - pushl $0x1B; \ - push $1f; \ - iret; \ 1: \ - "); +char *argv_init[]={"/bin/init",NULL}; +char *env_init[]={NULL}; + +// THIS WILL BE RUN IN RING 3! +void userfunc() +{ + + execve("/bin/init",argv_init,env_init); + + for(int i=0;i<3;i++) + { + log(FOOLOS_MODULE_NAME,FOOLOS_LOG_INFO,"we are usermode!"); + } + + + while(1) + { + + char text[]="syscalling!"; + write(1,text,10); + } } |
