scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit cc91dc2eb3036c06b19a4388b44302b84fc94787
parent 2ef97adeb24a81cc0fc756c07b43d34644febf0d
Author: zerous Naveen Narayanan <zerous@nocebo.space>
Date:   Sat, 16 Nov 2019 13:43:49 +0100

Update gensys.sh for i386/linux

awk script generates code that sets the respective registers with
parameters for i386 syscalls.
Fix syscalls

Diffstat:
Msrc/libc/arch/i386/linux/Makefile | 1+
Msrc/libc/arch/i386/linux/gensys.sh | 52+++++++++++++++++++++++++++++++++++-----------------
Msrc/libc/arch/i386/linux/syscall.lst | 22+++++++++++-----------
3 files changed, 47 insertions(+), 28 deletions(-)

diff --git a/src/libc/arch/i386/linux/Makefile b/src/libc/arch/i386/linux/Makefile @@ -16,6 +16,7 @@ OBJS =\ _Exit.o\ _kill.o\ crt.o\ + signal.o\ all: syscall $(MAKE) objs diff --git 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 diff --git 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