scc

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

gensys.sh (526B)


      1 #!/bin/sh
      2 
      3 #
      4 # This job is very easy because app and kernel ABI are identical
      5 # until the 4th parameter, so we only have to set the syscall
      6 # number in rax
      7 
      8 sed -n "
      9      s/[ 	]*#.*//
     10      /$1/p" syscall.lst |
     11 while read num name nargs
     12 do
     13 cat <<EOF > $name.s
     14 	.file	"$name.s"
     15 
     16 	.globl	$name
     17 $name:
     18 	`case $nargs in 4|5|6)
     19 		echo "movq       %rcx,%r10"
     20 		;;
     21 	esac`
     22 	movq	\$$num,%rax
     23 1:	syscall
     24 	jb	2f
     25 	retq
     26 
     27 2:	movq	%rax,(errno)
     28 	movq	\$-1,%rax
     29 	retq
     30 
     31 	.section .openbsd.syscalls, "a", @progbits
     32 	.long 1b
     33 	.long $num
     34 EOF
     35 done