ref: ab6005654710cbe137c97f50c015271ea1bf315b
parent: 675581f2a90f86ee912f4576ccaadca0f7f08ebf
author: zerous Naveen Narayanan <[email protected]>
date: Sat Nov 16 08:43:49 EST 2019
Update gensys.sh for i386/linux awk script generates code that sets the respective registers with parameters for i386 syscalls. Fix syscalls
--- a/src/libc/arch/i386/linux/Makefile
+++ b/src/libc/arch/i386/linux/Makefile
@@ -16,6 +16,7 @@
_Exit.o\
_kill.o\
crt.o\
+ signal.o\
all: syscall
$(MAKE) objs
--- a/src/libc/arch/i386/linux/gensys.sh
+++ b/src/libc/arch/i386/linux/gensys.sh
@@ -1,20 +1,38 @@
#!/bin/sh
-#
-# This job is very easy because app and kernel ABI are identical
-# until the 4th parameter, so we only have to set the syscall
-# number in eax
-sed 's/[ ]*#.*//
- /^$/d' syscall.lst |
-while read num name
-do
-cat <<EOF > $name.s
- .file "$name.s"
+awk '
+NR > 1 {syscall=$2
+ fname=$2".s"
+ noper=$3
- .globl $name
-$name:
- movl \$$num,%eax
- syscall
- jmp _cerrno
-EOF
-done
+ printf "\t.file\t"
+ "\"fname\"\n"
+ "\t.globl\t%s\n"
+ "%s:\n"
+ "\tpushl\t%%ebp\n"
+ "\tpushl\t%%ebx\n"
+ "\tpushl\t%%esi\n\n",
+ "\tpushl\t%%edi\n"
+ "\tmovl\t%%esp,%%ebp\n"
+ syscall, syscall > fname
+
+ if (noper > 0)
+ printf "\tmovl\t20(%%ebp),%%ebx\n" >> fname
+ if (noper > 1)
+ printf "\tmovl\t24(%%ebp),%%ecx\n" >> fname
+ if (noper > 2)
+ printf "\tmovl\t28(%%ebp),%%edx\n" >> fname
+ if (noper > 3)
+ printf "\tmovl\t28(%%ebp),%%esi\n" >> fname
+ if (noper > 4)
+ printf "\tmovl\t28(%%ebp),%%edi\n" >> fname
+
+ printf "\tmovl\t$%d,%%eax\n"
+ "\tint\t$0x80\n"
+ "\tpopl\t%%edi\n"
+ "\tpopl\t%%esi\n"
+ "\tpopl\t%%ebx\n"
+ "\tpopl\t%%ebp\n"
+ "\tjmp\t_cerrno\n", $1 >> fname
+
+} ' syscall.lst
--- a/src/libc/arch/i386/linux/syscall.lst
+++ b/src/libc/arch/i386/linux/syscall.lst
@@ -1,11 +1,11 @@
-#number name
-3 _read
-4 _write
-5 _open
-6 _close
-19 _lseek
-45 _brk
-67 _sigaction
-20 _getpid
-1 _Exit
-37 _kill
+#number name num_of_op
+1 _Exit 1
+3 _read 3
+4 _write 3
+5 _open 2
+6 _close 1
+19 _lseek 3
+20 _getpid 0
+37 _kill 2
+45 _brk 1
+67 _sigaction 3