summaryrefslogtreecommitdiffstats
path: root/src/userprog/syscall.c
blob: e15555e240a34da3ce9bb013c40254efc81648ec (plain) (blame)
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
#include "userprog/syscall.h"
#include <stdio.h>
#include <syscall-nr.h>
#include "threads/interrupt.h"
#include "threads/thread.h"

static void syscall_handler (struct intr_frame *);

void
syscall_init (void) 
{
  intr_register_int (0x30, 3, INTR_ON, syscall_handler, "syscall");
}

static void
syscall_handler (struct intr_frame *f UNUSED) 
{
  int syscall_number = *((int *)f->esp);
  switch (syscall_number) {
    case 9:
      // printf
      printf ("printf: %s", *((char **)(f->esp+8)));
      break;
    default:
      printf ("kernel: unknown syscall '%d'\n", syscall_number);
      break;
  }
  thread_exit ();
}