#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 = 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? } 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); } }