kern

annotate src/syscall.c @ 54:4eaecb14fe31

bringing the task switching thing into shape with proper per-process kernel stacks and shit
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 14 Aug 2011 16:57:23 +0300
parents fa65b4f45366
children 0be4615594df
rev   line source
nuclear@51 1 #include <stdio.h>
nuclear@51 2 #include "syscall.h"
nuclear@51 3 #include "intr.h"
nuclear@51 4 #include "proc.h"
nuclear@51 5 #include "sched.h"
nuclear@51 6 #include "timer.h"
nuclear@51 7
nuclear@51 8 static int (*sys_func[NUM_SYSCALLS])();
nuclear@51 9
nuclear@52 10 static void syscall(int inum);
nuclear@51 11
nuclear@51 12 static int sys_exit(int status);
nuclear@51 13 static int sys_hello(void);
nuclear@51 14 static int sys_sleep(int sec);
nuclear@51 15
nuclear@51 16 void init_syscall(void)
nuclear@51 17 {
nuclear@51 18 sys_func[SYS_EXIT] = sys_exit;
nuclear@51 19 sys_func[SYS_HELLO] = sys_hello;
nuclear@51 20 sys_func[SYS_SLEEP] = sys_sleep;
nuclear@51 21
nuclear@51 22 interrupt(SYSCALL_INT, syscall);
nuclear@51 23 }
nuclear@51 24
nuclear@52 25 static void syscall(int inum)
nuclear@51 26 {
nuclear@52 27 struct intr_frame *frm;
nuclear@52 28 int idx;
nuclear@52 29
nuclear@52 30 frm = get_intr_frame();
nuclear@52 31 idx = frm->regs.eax;
nuclear@51 32
nuclear@51 33 if(idx < 0 || idx >= NUM_SYSCALLS) {
nuclear@51 34 printf("invalid syscall: %d\n", idx);
nuclear@51 35 return;
nuclear@51 36 }
nuclear@51 37
nuclear@54 38 /* the return value goes into the interrupt frame copy of the user's eax
nuclear@54 39 * so that it'll be restored into eax before returning to userland.
nuclear@54 40 */
nuclear@51 41 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
nuclear@51 42 }
nuclear@51 43
nuclear@51 44 static int sys_exit(int status)
nuclear@51 45 {
nuclear@54 46 printf("SYSCALL: exit\n");
nuclear@51 47 return -1; /* not implemented yet */
nuclear@51 48 }
nuclear@51 49
nuclear@51 50 static int sys_hello(void)
nuclear@51 51 {
nuclear@54 52 printf("process %d says hello!\n", get_current_pid());
nuclear@51 53 return 0;
nuclear@51 54 }
nuclear@51 55
nuclear@51 56 static int sys_sleep(int sec)
nuclear@51 57 {
nuclear@54 58 printf("SYSCALL: sleep\n");
nuclear@54 59 return -1;
nuclear@51 60 }