1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#include <stdio.h>
#include <syscall-nr.h>
#include "userprog/syscall.h"
#include "threads/interrupt.h"
#include "threads/thread.h"
/* header files you probably need, they are not used yet */
#include <string.h>
#include "filesys/filesys.h"
#include "filesys/file.h"
#include "threads/vaddr.h"
#include "threads/init.h"
#include "userprog/pagedir.h"
#include "userprog/process.h"
#include "devices/input.h"
static void syscall_handler (struct intr_frame *);
void
syscall_init (void)
{
intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
}
/* This array defined the number of arguments each syscall expects.
For example, if you want to find out the number of arguments for
the read system call you shall write:
int sys_read_arg_count = argc[ SYS_READ ];
All system calls have a name such as SYS_READ defined as an enum
type, see `lib/syscall-nr.h'. Use them instead of numbers.
*/
const int argc[] = {
/* basic calls */
0, 1, 1, 1, 2, 1, 1, 1, 3, 3, 2, 1, 1,
/* not implemented */
2, 1, 1, 1, 2, 1, 1,
/* extended */
0
};
static void
syscall_handler (struct intr_frame *f)
{
int32_t* esp = (int32_t*)f->esp;
switch ( 0 /* retrive syscall number */ )
{
default:
{
printf ("Executed an unknown system call!\n");
printf ("Stack top + 0: %d\n", esp[0]);
printf ("Stack top + 1: %d\n", esp[1]);
thread_exit ();
}
}
}
|