From 090b997d35498044beb5de865202adadaeac24bf Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Thu, 12 Sep 2024 12:59:18 -0400 Subject: [PATCH] add sys_add_three_integers --- kern/arch/mips/syscall/syscall.c | 6 ++++++ kern/conf/conf.kern | 1 + kern/include/kern/syscall.h | 1 + kern/include/syscall.h | 2 ++ kern/syscall/add_three_integers.c | 8 ++++++++ userland/include/unistd.h | 1 + userland/testbin/Makefile | 2 +- userland/testbin/add_three_integers/Makefile | 10 ++++++++++ .../testbin/add_three_integers/add_three_integers.c | 10 ++++++++++ 9 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 kern/syscall/add_three_integers.c create mode 100644 userland/testbin/add_three_integers/Makefile create mode 100644 userland/testbin/add_three_integers/add_three_integers.c diff --git a/kern/arch/mips/syscall/syscall.c b/kern/arch/mips/syscall/syscall.c index 8b25ec5..362eb90 100644 --- a/kern/arch/mips/syscall/syscall.c +++ b/kern/arch/mips/syscall/syscall.c @@ -114,6 +114,12 @@ void syscall(struct trapframe *tf) { err = sys_printchar((char)tf->tf_a0); break; + case SYS_add_three_integers: + err = sys_add_three_integers((int)tf->tf_a0, (int)tf->tf_a1, (int)tf->tf_a2, + &retval); + kprintf("%d\n", retval); + break; + /* Add stuff here */ default: diff --git a/kern/conf/conf.kern b/kern/conf/conf.kern index dd1db07..28127dd 100644 --- a/kern/conf/conf.kern +++ b/kern/conf/conf.kern @@ -380,6 +380,7 @@ file syscall/loadelf.c file syscall/runprogram.c file syscall/time_syscalls.c file syscall/printchar.c +file syscall/add_three_integers.c # # Startup and initialization diff --git a/kern/include/kern/syscall.h b/kern/include/kern/syscall.h index 64cb40f..ae82573 100644 --- a/kern/include/kern/syscall.h +++ b/kern/include/kern/syscall.h @@ -95,6 +95,7 @@ // #define SYS_setpriority 39 // (process groups, sessions, and job control) #define SYS_printchar 41 +#define SYS_add_three_integers 42 // #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 1098a55..dd2eb2b 100644 --- a/kern/include/syscall.h +++ b/kern/include/syscall.h @@ -59,4 +59,6 @@ int sys___time(userptr_t user_seconds, userptr_t user_nanoseconds); int sys_printchar(char c); +int sys_add_three_integers(int a, int b, int c, int *ret); + #endif /* _SYSCALL_H_ */ diff --git a/kern/syscall/add_three_integers.c b/kern/syscall/add_three_integers.c new file mode 100644 index 0000000..0d3994d --- /dev/null +++ b/kern/syscall/add_three_integers.c @@ -0,0 +1,8 @@ +#include +#include +#include + +int sys_add_three_integers(int a, int b, int c, int *ret) { + *ret = a + b + c; + return 0; +} diff --git a/userland/include/unistd.h b/userland/include/unistd.h index 2d05a92..7d21177 100644 --- a/userland/include/unistd.h +++ b/userland/include/unistd.h @@ -157,5 +157,6 @@ char *getcwd(char *buf, size_t buflen); /* calls __getcwd */ time_t time(time_t *seconds); /* calls __time */ int printchar(char c); +int add_three_integers(int a, int b, int c); #endif /* _UNISTD_H_ */ diff --git a/userland/testbin/Makefile b/userland/testbin/Makefile index 14f7f02..c364faa 100644 --- a/userland/testbin/Makefile +++ b/userland/testbin/Makefile @@ -5,7 +5,7 @@ TOP=../.. .include "$(TOP)/mk/os161.config.mk" -SUBDIRS=add argtest badcall bigexec bigfile bigfork bigseek bloat conman \ +SUBDIRS=add add_three_integers 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 \ malloctest matmult multiexec palin parallelvm poisondisk printchartest psort \ diff --git a/userland/testbin/add_three_integers/Makefile b/userland/testbin/add_three_integers/Makefile new file mode 100644 index 0000000..ceb56d3 --- /dev/null +++ b/userland/testbin/add_three_integers/Makefile @@ -0,0 +1,10 @@ +# Makefile for add_three_integers + +TOP=../../.. +.include "$(TOP)/mk/os161.config.mk" + +PROG=add_three_integers +SRCS=add_three_integers.c +BINDIR=/testbin + +.include "$(TOP)/mk/os161.prog.mk" diff --git a/userland/testbin/add_three_integers/add_three_integers.c b/userland/testbin/add_three_integers/add_three_integers.c new file mode 100644 index 0000000..3a156ea --- /dev/null +++ b/userland/testbin/add_three_integers/add_three_integers.c @@ -0,0 +1,10 @@ +#include + +extern int add_three_integers(int a, int b, int c); + +int main() { + add_three_integers(3, 5, 2); // should output 10 + add_three_integers(-5, 3, 1); // should output -1 + + return 0; +}