kern

annotate src/syscall.c @ 67:ebca81749ef5

added strcmp
author John Tsiombikas <nuclear@mutantstargoat.com>
date Sun, 09 Oct 2011 20:38:35 +0300
parents 437360696883
children 3941e82b07f2
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_hello(void);
nuclear@51 13 static int sys_sleep(int sec);
nuclear@57 14 static int sys_fork(void);
nuclear@57 15 static int sys_getpid(void);
nuclear@51 16
nuclear@51 17 void init_syscall(void)
nuclear@51 18 {
nuclear@51 19 sys_func[SYS_HELLO] = sys_hello;
nuclear@51 20 sys_func[SYS_SLEEP] = sys_sleep;
nuclear@57 21 sys_func[SYS_FORK] = sys_fork;
nuclear@57 22 sys_func[SYS_GETPID] = sys_getpid;
nuclear@51 23
nuclear@51 24 interrupt(SYSCALL_INT, syscall);
nuclear@51 25 }
nuclear@51 26
nuclear@52 27 static void syscall(int inum)
nuclear@51 28 {
nuclear@52 29 struct intr_frame *frm;
nuclear@52 30 int idx;
nuclear@52 31
nuclear@52 32 frm = get_intr_frame();
nuclear@52 33 idx = frm->regs.eax;
nuclear@51 34
nuclear@51 35 if(idx < 0 || idx >= NUM_SYSCALLS) {
nuclear@51 36 printf("invalid syscall: %d\n", idx);
nuclear@51 37 return;
nuclear@51 38 }
nuclear@51 39
nuclear@54 40 /* the return value goes into the interrupt frame copy of the user's eax
nuclear@54 41 * so that it'll be restored into eax before returning to userland.
nuclear@54 42 */
nuclear@51 43 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
nuclear@51 44 }
nuclear@51 45
nuclear@51 46 static int sys_hello(void)
nuclear@51 47 {
nuclear@54 48 printf("process %d says hello!\n", get_current_pid());
nuclear@51 49 return 0;
nuclear@51 50 }
nuclear@51 51
nuclear@51 52 static int sys_sleep(int sec)
nuclear@51 53 {
nuclear@56 54 printf("process %d will sleep for %d seconds\n", get_current_pid(), sec);
nuclear@57 55 sleep(sec * 1000); /* timer.c */
nuclear@56 56 return 0;
nuclear@51 57 }
nuclear@57 58
nuclear@57 59 static int sys_fork(void)
nuclear@57 60 {
nuclear@57 61 printf("process %d is forking\n", get_current_pid());
nuclear@57 62 return fork(); /* proc.c */
nuclear@57 63 }
nuclear@57 64
nuclear@57 65 static int sys_getpid(void)
nuclear@57 66 {
nuclear@57 67 int pid = get_current_pid();
nuclear@57 68 printf("process %d getpid\n", pid);
nuclear@57 69 return pid;
nuclear@57 70 }