diff --git a/Makefile b/Makefile index f8cc863..1363245 100644 --- a/Makefile +++ b/Makefile @@ -135,6 +135,7 @@ UPROGS=\ $U/_wc\ $U/_zombie\ $U/_clear\ + $U/_halt\ fs.img: mkfs/mkfs README.md $(UPROGS) mkfs/mkfs fs.img README.md $(UPROGS) diff --git a/kernel/syscall.c b/kernel/syscall.c index 075fb36..a027276 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -102,6 +102,7 @@ extern u64 sys_link(void); extern u64 sys_mkdir(void); extern u64 sys_close(void); extern u64 sys_trace(void); +extern u64 sys_halt(void); // An array mapping syscall numbers from syscall.h // to the function that handles the system call. @@ -111,7 +112,7 @@ static u64 (*syscalls[])(void) = { [SYS_chdir] = sys_chdir, [SYS_dup] = sys_dup, [SYS_getpid] = sys_getpid, [SYS_sbrk] = sys_sbrk, [SYS_sleep] = sys_sleep, [SYS_uptime] = sys_uptime, [SYS_open] = sys_open, [SYS_write] = sys_write, [SYS_mknod] = sys_mknod, [SYS_unlink] = sys_unlink, [SYS_link] = sys_link, [SYS_mkdir] = sys_mkdir, - [SYS_close] = sys_close, [SYS_trace] = sys_trace, + [SYS_close] = sys_close, [SYS_trace] = sys_trace, [SYS_halt] = sys_halt, }; void diff --git a/kernel/syscall.h b/kernel/syscall.h index dfc9645..0162584 100644 --- a/kernel/syscall.h +++ b/kernel/syscall.h @@ -23,3 +23,4 @@ #define SYS_mkdir 20 #define SYS_close 21 #define SYS_trace 22 +#define SYS_halt 23 diff --git a/kernel/sysproc.c b/kernel/sysproc.c index 5645c72..ba0aeb9 100644 --- a/kernel/sysproc.c +++ b/kernel/sysproc.c @@ -96,3 +96,9 @@ sys_trace(void) /* TODO: Implement sys_trace */ return 0; } + +void +sys_halt(void) +{ + /* TODO: Implement sys_halt */ +} diff --git a/user/halt.c b/user/halt.c new file mode 100644 index 0000000..ab73dd3 --- /dev/null +++ b/user/halt.c @@ -0,0 +1,9 @@ +#include "user.h" + +/** Stops the machine */ +int +main(int argc, char *argv[]) +{ + halt(); + return 0; +} diff --git a/user/user.h b/user/user.h index 1e56f3d..ed10ca8 100644 --- a/user/user.h +++ b/user/user.h @@ -74,6 +74,9 @@ int uptime(void); /** trace */ int trace(int); +/** halt */ +void halt(void); + /** * Library functions (ulib.c) */ diff --git a/user/usys.pl b/user/usys.pl index 9c97b05..cdaec02 100755 --- a/user/usys.pl +++ b/user/usys.pl @@ -14,7 +14,7 @@ sub entry { print " ecall\n"; print " ret\n"; } - + entry("fork"); entry("exit"); entry("wait"); @@ -37,3 +37,4 @@ entry("sbrk"); entry("sleep"); entry("uptime"); entry("trace"); +entry("halt");