kern

annotate src/syscall.c @ 97:8717eb590727

ok stopping with the filesystem to manage to write the article in time
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 17 Dec 2011 14:09:17 +0200
parents 3941e82b07f2
children
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@90 7 #include "fs.h"
nuclear@51 8
nuclear@51 9 static int (*sys_func[NUM_SYSCALLS])();
nuclear@51 10
nuclear@52 11 static void syscall(int inum);
nuclear@51 12
nuclear@51 13 static int sys_hello(void);
nuclear@51 14
nuclear@51 15 void init_syscall(void)
nuclear@51 16 {
nuclear@51 17 sys_func[SYS_HELLO] = sys_hello;
nuclear@72 18 sys_func[SYS_SLEEP] = sys_sleep; /* timer.c */
nuclear@72 19 sys_func[SYS_FORK] = sys_fork; /* proc.c */
nuclear@72 20 sys_func[SYS_EXIT] = sys_exit; /* proc.c */
nuclear@72 21 sys_func[SYS_WAITPID] = sys_waitpid; /* proc.c */
nuclear@72 22 sys_func[SYS_GETPID] = sys_getpid; /* proc.c */
nuclear@72 23 sys_func[SYS_GETPPID] = sys_getppid; /* proc.c */
nuclear@51 24
nuclear@90 25 sys_func[SYS_MOUNT] = sys_mount; /* fs.c */
nuclear@90 26 sys_func[SYS_UMOUNT] = sys_umount; /* fs.c */
nuclear@90 27 sys_func[SYS_OPEN] = sys_open; /* fs.c */
nuclear@90 28 sys_func[SYS_CLOSE] = sys_close; /* fs.c */
nuclear@90 29 sys_func[SYS_READ] = sys_read; /* fs.c */
nuclear@90 30 sys_func[SYS_WRITE] = sys_write; /* fs.c */
nuclear@90 31 sys_func[SYS_LSEEK] = sys_lseek; /* fs.c */
nuclear@90 32
nuclear@51 33 interrupt(SYSCALL_INT, syscall);
nuclear@51 34 }
nuclear@51 35
nuclear@52 36 static void syscall(int inum)
nuclear@51 37 {
nuclear@52 38 struct intr_frame *frm;
nuclear@52 39 int idx;
nuclear@52 40
nuclear@52 41 frm = get_intr_frame();
nuclear@52 42 idx = frm->regs.eax;
nuclear@51 43
nuclear@51 44 if(idx < 0 || idx >= NUM_SYSCALLS) {
nuclear@51 45 printf("invalid syscall: %d\n", idx);
nuclear@51 46 return;
nuclear@51 47 }
nuclear@51 48
nuclear@54 49 /* the return value goes into the interrupt frame copy of the user's eax
nuclear@54 50 * so that it'll be restored into eax before returning to userland.
nuclear@54 51 */
nuclear@51 52 frm->regs.eax = sys_func[idx](frm->regs.ebx, frm->regs.ecx, frm->regs.edx, frm->regs.esi, frm->regs.edi);
nuclear@72 53
nuclear@72 54 /* we don't necessarily want to return to the same process
nuclear@72 55 * might have blocked or exited or whatever, so call schedule
nuclear@72 56 * to decide what's going to run next.
nuclear@72 57 */
nuclear@72 58 schedule();
nuclear@51 59 }
nuclear@51 60
nuclear@51 61 static int sys_hello(void)
nuclear@51 62 {
nuclear@54 63 printf("process %d says hello!\n", get_current_pid());
nuclear@51 64 return 0;
nuclear@51 65 }