diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-02-05 14:21:31 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-02-05 14:21:31 +0100 |
| commit | 35c70f514119c5cf786643597a7ebeb03a6d86f8 (patch) | |
| tree | a801816a2f1ebb72c27539eda65fdac8112b2a9e /src/userprog/syscall.c | |
| parent | 99f4a170a4a76b49ad7281ac6e05264c8cf557ad (diff) | |
| download | pintos-35c70f514119c5cf786643597a7ebeb03a6d86f8.tar.gz | |
move syscall handlers to own functions
Diffstat (limited to 'src/userprog/syscall.c')
| -rw-r--r-- | src/userprog/syscall.c | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 5e5a6f1..9bb42fa 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -16,6 +16,24 @@ syscall_init (void) intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall"); } +static void +halt (void) +{ + power_off(); +} + +static bool +create (const char *filename, off_t initial_size) +{ + return filesys_create (filename, initial_size); +} + +static void +write (const char *buf) +{ + printf ("printf: %s", buf); +} + // cast to TYPE and deref argument N from f->esp #define INTR_ESP(N, TYPE) *(TYPE *)(f->esp+(4*(N))) @@ -26,21 +44,14 @@ syscall_handler (struct intr_frame *f UNUSED) switch (syscall_number) { case 0: // halt - power_off (); + halt (); break; case 1: // exit break; case 4: // create - ; // empty statement because c-grammar doesn't allow declarations following labels - printf("kernel: create\n"); - char *filename = INTR_ESP(1, char *); - printf("create: read filename '%s'\n", filename); - off_t initial_size = INTR_ESP(2, off_t); - printf("create: read initial_size '%d'\n", initial_size); - f->eax = filesys_create(filename, initial_size); - printf("create: result (%d) put in f->eax\n", f->eax); + f->eax = create(INTR_ESP(1, char *), INTR_ESP(2, off_t)); break; case 6: // open @@ -50,7 +61,7 @@ syscall_handler (struct intr_frame *f UNUSED) break; case 9: // write - printf ("printf: %s", INTR_ESP(2, char *)); + write(INTR_ESP(2, char *)); break; case 12: // close |
