From c67c34e0eaa697da81de80e46547893950b28a83 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Tue, 10 Sep 2024 13:08:41 -0400 Subject: [PATCH] Add sys_hello and testbin/hellotest `sys_hello` is a new syscall that just prints some text in the terminal. `testbin/hellotest` is a userland binary that just calls `sys_hello` --- kern/arch/mips/syscall/syscall.c | 3 +++ kern/conf/conf.kern | 1 + kern/include/kern/syscall.h | 1 + kern/include/syscall.h | 2 ++ kern/syscall/hello.c | 7 +++++++ userland/include/unistd.h | 2 ++ userland/testbin/Makefile | 2 +- userland/testbin/hellotest/Makefile | 11 +++++++++++ userland/testbin/hellotest/hello.c | 8 ++++++++ 9 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 kern/syscall/hello.c create mode 100644 userland/testbin/hellotest/Makefile create mode 100644 userland/testbin/hellotest/hello.c diff --git a/kern/arch/mips/syscall/syscall.c b/kern/arch/mips/syscall/syscall.c index b42d9c0..5c13836 100644 --- a/kern/arch/mips/syscall/syscall.c +++ b/kern/arch/mips/syscall/syscall.c @@ -104,6 +104,9 @@ void syscall(struct trapframe *tf) { case SYS___time: err = sys___time((userptr_t)tf->tf_a0, (userptr_t)tf->tf_a1); break; + case SYS_hello: + err = sys_hello(); + break; case SYS__exit: err = 0; diff --git a/kern/conf/conf.kern b/kern/conf/conf.kern index ad58977..1edca92 100644 --- a/kern/conf/conf.kern +++ b/kern/conf/conf.kern @@ -379,6 +379,7 @@ file vfs/devnull.c file syscall/loadelf.c file syscall/runprogram.c file syscall/time_syscalls.c +file syscall/hello.c # # Startup and initialization diff --git a/kern/include/kern/syscall.h b/kern/include/kern/syscall.h index 53a2b45..94b17c0 100644 --- a/kern/include/kern/syscall.h +++ b/kern/include/kern/syscall.h @@ -94,6 +94,7 @@ // #define SYS_getpriority 38 // #define SYS_setpriority 39 // (process groups, sessions, and job control) +#define SYS_hello 41 // #define SYS_getpgid 40 // #define SYS_setpgid 41 // #define SYS_getsid 42 diff --git a/kern/include/syscall.h b/kern/include/syscall.h index 6cd517b..b5620a9 100644 --- a/kern/include/syscall.h +++ b/kern/include/syscall.h @@ -57,4 +57,6 @@ __DEAD void enter_new_process(int argc, userptr_t argv, userptr_t env, int sys_reboot(int code); int sys___time(userptr_t user_seconds, userptr_t user_nanoseconds); +int sys_hello(void); + #endif /* _SYSCALL_H_ */ diff --git a/kern/syscall/hello.c b/kern/syscall/hello.c new file mode 100644 index 0000000..842ff45 --- /dev/null +++ b/kern/syscall/hello.c @@ -0,0 +1,7 @@ +#include +#include +#include +int sys_hello(void) { + kprintf("Hello CSE4001!\n"); + return 0; +} diff --git a/userland/include/unistd.h b/userland/include/unistd.h index 9739344..70f68b5 100644 --- a/userland/include/unistd.h +++ b/userland/include/unistd.h @@ -156,4 +156,6 @@ int execvp(const char *prog, char *const *args); /* calls execv */ char *getcwd(char *buf, size_t buflen); /* calls __getcwd */ time_t time(time_t *seconds); /* calls __time */ +int hello(void); + #endif /* _UNISTD_H_ */ diff --git a/userland/testbin/Makefile b/userland/testbin/Makefile index 647f229..0ddc3e8 100644 --- a/userland/testbin/Makefile +++ b/userland/testbin/Makefile @@ -7,7 +7,7 @@ TOP=../.. SUBDIRS=add argtest badcall bigexec bigfile bigfork bigseek bloat conman \ crash ctest dirconc dirseek dirtest f_test factorial farm faulter \ - filetest forkbomb forktest frack hash hog huge \ + filetest forkbomb forktest frack hash hellotest hog huge \ malloctest matmult multiexec palin parallelvm poisondisk psort \ randcall redirect rmdirtest rmtest \ sbrktest schedpong sort sparsefile tail tictac triplehuge \ diff --git a/userland/testbin/hellotest/Makefile b/userland/testbin/hellotest/Makefile new file mode 100644 index 0000000..3768414 --- /dev/null +++ b/userland/testbin/hellotest/Makefile @@ -0,0 +1,11 @@ +# Makefile for hello + +TOP=../../.. +.include "$(TOP)/mk/os161.config.mk" + +PROG=hellotest +SRCS=hello.c +BINDIR=/testbin + +.include "$(TOP)/mk/os161.prog.mk" + diff --git a/userland/testbin/hellotest/hello.c b/userland/testbin/hellotest/hello.c new file mode 100644 index 0000000..fbea19a --- /dev/null +++ b/userland/testbin/hellotest/hello.c @@ -0,0 +1,8 @@ +#include + +extern int hello(void); + +int main() { + hello(); + return 0; +}