kern

annotate src/syscall.c @ 56:0be4615594df

finally, runqueues, blocking, waking up, idle loop etc, all seem to work fine on a single user process... Next up: try forking another one :)
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 15 Aug 2011 06:17:58 +0300
parents 4eaecb14fe31
children 437360696883
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@56 58 printf("process %d will sleep for %d seconds\n", get_current_pid(), sec);
nuclear@56 59
nuclear@56 60 sleep(sec * 1000);
nuclear@56 61
nuclear@56 62 return 0;
nuclear@51 63 }