From 20551ae04073fb33114b7bc6b89219a6ce94c4ab Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Tue, 14 Jan 2025 20:29:50 +0100 Subject: [PATCH] Remove dependence on perl, depend on python instead --- Makefile | 4 ++-- user/usys.pl | 40 ---------------------------------------- user/usys.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 42 deletions(-) delete mode 100755 user/usys.pl create mode 100755 user/usys.py diff --git a/Makefile b/Makefile index 14ca555..ed77f93 100644 --- a/Makefile +++ b/Makefile @@ -96,8 +96,8 @@ _%: %.o $(ULIB) $(OBJDUMP) -S $@ > $*.asm $(OBJDUMP) -t $@ | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $*.sym -$U/usys.S : $U/usys.pl - perl $U/usys.pl > $U/usys.S +$U/usys.S : $U/usys.py + python3 $U/usys.py > $U/usys.S $U/usys.o : $U/usys.S $(CC) $(CFLAGS) -c -o $U/usys.o $U/usys.S diff --git a/user/usys.pl b/user/usys.pl deleted file mode 100755 index cdaec02..0000000 --- a/user/usys.pl +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/perl -w - -# Generate usys.S, the stubs for syscalls. - -print "# generated by usys.pl - do not edit\n"; - -print "#include \"kernel/syscall.h\"\n"; - -sub entry { - my $name = shift; - print ".global $name\n"; - print "${name}:\n"; - print " li a7, SYS_${name}\n"; - print " ecall\n"; - print " ret\n"; -} - -entry("fork"); -entry("exit"); -entry("wait"); -entry("pipe"); -entry("read"); -entry("write"); -entry("close"); -entry("kill"); -entry("exec"); -entry("open"); -entry("mknod"); -entry("unlink"); -entry("fstat"); -entry("link"); -entry("mkdir"); -entry("chdir"); -entry("dup"); -entry("getpid"); -entry("sbrk"); -entry("sleep"); -entry("uptime"); -entry("trace"); -entry("halt"); diff --git a/user/usys.py b/user/usys.py new file mode 100755 index 0000000..21ecd2d --- /dev/null +++ b/user/usys.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +template = """.global {name} +{name}: + li a7, SYS_{name} + ecall + ret""" + + +def genstub(syscall: str): + return template.format(name=syscall) + + +syscalls = [ + "fork", + "exit", + "wait", + "pipe", + "read", + "write", + "close", + "kill", + "exec", + "open", + "mknod", + "unlink", + "fstat", + "link", + "mkdir", + "chdir", + "dup", + "getpid", + "sbrk", + "sleep", + "uptime", + "trace", + "halt", +] + +assembly = "\n\n".join(map(genstub, syscalls)) + +# TODO: Perhaps do some more specific assertions on the code here +assert len(assembly) > 0, "No assembly code generated. Something is fishy" + +print("# generated by usys.py - do not edit\n") +print('#include "kernel/syscall.h"\n') +print(assembly)