Remove dependence on perl, depend on python instead

This commit is contained in:
Imbus 2025-01-14 20:29:50 +01:00
parent 1825a89ab5
commit 20551ae040
3 changed files with 49 additions and 42 deletions

View file

@ -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

View file

@ -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");

47
user/usys.py Executable file
View file

@ -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)