diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c index 04635159d30520fa11296dc922e622f2ad2553d5..a2a711ef4893613aa9d81d1cb36a34422a5e668c 100644 --- a/src/userprog/syscall.c +++ b/src/userprog/syscall.c @@ -4,7 +4,53 @@ #include "threads/interrupt.h" #include "threads/thread.h" -static void syscall_handler (struct intr_frame *); +void sys_halt (void); +void sys_exit (int status); +pid_t sys_exec (const char *cmd_line); +int sys_wait (pid_t pid); +bool sys_create (const char *name, unsigned int initial_size); +bool sys_remove (const char *file) +int sys_open (const char *file); +int sys_filesize (int fd); +int sys_read (int fd, void *buffer, unsigned length); +void sys_write (int fd, const void *buffer, unsigned int length); +void sys_seek (int fd, unsigned position); +unsigned sys_tell (int fd); +void sys_close (int fd); + +static void syscall_handler (struct intr_frame *f);{ + int code = (int) load_stack (f, ARG_CODE); + + switch (code) + { + case SYS_HALT: + sys_halt(); + break; + case SYS_EXIT: + sys_exit ((int) load_stack (f, ARG_0)); + break; + case SYS_CLOSE: + sys_close ((int) load_stack (f, ARG_0)); + break; + } +} + +void sys_halt (void) +{ + shutdown_power_off(); +} + +void sys_exit (int status) +{ + struct thread *cur = thread_current (); + cur->exit_status = status + thread_exit(); +} + +int sys_wait (pid_t pid) +{ + return process_wait (pid); +} void syscall_init (void) diff --git a/src/userprog/syscall.h b/src/userprog/syscall.h index 90590967a9f96f9ea359d15c672b815dfb4379cb..8b86e15f8576dcfbb16a0b31edfd39ecbd88da3e 100644 --- a/src/userprog/syscall.h +++ b/src/userprog/syscall.h @@ -1,6 +1,49 @@ #ifndef USERPROG_SYSCALL_H #define USERPROG_SYSCALL_H +#include <stdbool.h> +#include <debug.h> + +/* Process identifier*/ +typedef int pid_t; +#define PID_ERROR ((pid_t) -1) + +/* Map region identifier*/ +typedef int mapid_t; +#define MAP_FAILED ((mapid_t) -1) + +/* Maximum characters in a filename written by readdir(). */ +#define READDIR_MAX_LEN 14 + +/* Typical return values from main() and arguments to exit(). */ +#define EXIT_SUCCESS 0 /* Successful execution*/ +#define EXIT_FAILURE 1 /* Unsuccessful execution*/ + +/* Projects 2 and later */ +void halt (void) NO_RETURN; +void exit (int status) NO_RETURN; +pid_t exec (const char *file); +int wait (pid_t); +bool create (const char *file, unsigned initial_size); +bool remove (const char *file); +int open (const char *file); +int filesize (int fd); +int read (int fd, void *buffer, unsigned length); +int write (int fd, const void *buffer, unsigned length); +void seek (int fd, unsigned position); +unsigned tell (int fd); +void close (int fd); + +/* Project 3 and optionally project 4 */ +mapid_t mmap (int fd, void *addr); +void munmap (mapid_t); + +/* Project 4 only */ +bool chdir (const char *dir); +bool mkdir (const char *dir); +bool readdir (int fd, char name[READDIR_MAX_LEN + 1]); +bool isdir (int fd); +int inumber (int fd); void syscall_init (void); #endif /* userprog/syscall.h */