Select Git revision
a2-stratford authored
syscall.c 2.54 KiB
#include "userprog/syscall.h"
#include <stdio.h>
#include <syscall-nr.h>
#include "system_calls.h"
#include "threads/interrupt.h"
#include "threads/thread.h"
/* System call numbers. */
typedef enum syscall_t {
/* Projects 2 and later. */
SYSCALL_HALT, /* Halt the operating system. */
SYSCALL_EXIT, /* Terminate this process. */
SYSCALL_EXEC, /* Start another process. */
SYSCALL_WAIT, /* Wait for a child process to die. */
SYSCALL_CREATE, /* Create a file. */
SYSCALL_REMOVE, /* Delete a file. */
SYSCALL_OPEN, /* Open a file. */
SYSCALL_FILESIZE, /* Obtain a file's size. */
SYSCALL_READ, /* Read from a file. */
SYSCALL_WRITE, /* Write to a file. */
SYSCALL_SEEK, /* Change position in a file. */
SYSCALL_TELL, /* Report current position in a file. */
SYSCALL_CLOSE, /* Close a file. */
/* Project 3 and optionally project 4. */
SYSCALL_MMAP, /* Map a file into memory. */
SYSCALL_MUNMAP, /* Remove a memory mapping. */
/* Project 4 only. */
SYSCALL_CHDIR, /* Change the current directory. */
SYSCALL_MKDIR, /* Create a directory. */
SYSCALL_READDIR, /* Reads a directory entry. */
SYSCALL_ISDIR, /* Tests if a fd represents a directory. */
SYSCALL_INUMBER /* Returns the inode number for a fd. */
} syscall_t;
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)
{
/*
* the syscall number is addressed by f->esp (pointer to void)
* here we cast it to a pointer to int and then dereference that
* to get the system call number
* --Joshua Saxby
*/
int syscall_number = *((int*)f->esp);
switch (syscall_number) {
case SYSCALL_HALT:
syscall_halt(f);
break;
case SYSCALL_EXIT:
syscall_exit(f);
break;
case SYSCALL_EXEC:
syscall_exec(f);
break;
case SYSCALL_WAIT:
syscall_wait(f);
break;
case SYSCALL_CREATE:
syscall_create(f);
break;
case SYSCALL_WRITE:
syscall_write(f);
break;
case SYSCALL_OPEN:
syscall_open(f);
break;
default:
printf ("WARNING: Invalid Syscall (%d)\n", syscall_number);
thread_exit ();
}
}