commit edba2453ded15fda8c0302757cafbc994003773c parent b641412507fd991518097a7326910ff516df5da4 Author: Roberto Vargas <roberto.vargas@arm.com> Date: Wed, 17 Oct 2018 18:14:42 +0100 [libc] Autogenerate the syscalls The number of syscall is growing and it means that the original approach using hand written assembly files doesn't work anymore. With this new skin all the syscalls are autogenerated from a table. Change-Id: I1e6cadd286a2c5617c770c7e1afd3ba9b9d30380 Diffstat:
43 files changed, 306 insertions(+), 157 deletions(-)
diff --git a/src/libc/Makefile b/src/libc/Makefile @@ -1,10 +1,12 @@ PROJECTDIR =../.. include $(PROJECTDIR)/scripts/rules.mk +include arch/$(ARCH)/$(SYS)/objlst.mk -LIBCARCH = arch/$(ARCH) +LIBSYS = arch/$(ARCH)/$(SYS) +LIBARCH = arch/$(ARCH) MORECFLAGS = -I. -OBJS = abort.o \ +COBJ = abort.o \ __assert.o \ memchr.o \ memcmp.o \ @@ -59,20 +61,20 @@ OBJS = abort.o \ rand.o \ raise.o \ malloc.o \ - $(LIBCARCH)/setjmp.o \ - $(LIBCARCH)/longjmp.o \ - $(LIBCARCH)/_Exit-$(SYS).o \ - $(LIBCARCH)/_write-$(SYS).o \ - $(LIBCARCH)/_getpid-$(SYS).o \ - $(LIBCARCH)/_kill-$(SYS).o +OBJS = $(COBJ) $(SYSOBJ) TARGET = $(PROJECTDIR)/lib/libc.a all: $(TARGET) +$(SYSOBJ): arch/$(ARCH)/$(SYS) + +arch/$(ARCH)/$(SYS): FORCE + +@cd $@ && $(MAKE) + $(TARGET): $(OBJS) $(AR) $(ARFLAGS) $@ $? ranlib $@ clean: - rm -f arch/*/*.o arch/*/*.d + +@cd arch && $(MAKE) clean diff --git a/src/libc/arch/Makefile b/src/libc/arch/Makefile @@ -0,0 +1,10 @@ +PROJECTDIR =../../.. +include $(PROJECTDIR)/scripts/rules.mk + +DIRS = amd64 arm64 + +all: + +@cd $(ARCH) && $(MAKE) + +clean: + $(FORALL) diff --git a/src/libc/arch/amd64/Makefile b/src/libc/arch/amd64/Makefile @@ -0,0 +1,13 @@ +PROJECTDIR =../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = longjmp.o setjmp.o +DIRS = bsd linux + +all: $(OBJS) $(SYS) + +$(SYS): FORCE + +@cd $@ && $(MAKE) + +clean: + $(FORALL) diff --git a/src/libc/arch/amd64/_Exit-bsd.s b/src/libc/arch/amd64/_Exit-bsd.s @@ -1,8 +0,0 @@ - .file "_Exit-bsd.s" - - .text - .globl _Exit -_Exit: - movq $1,%rax - syscall - ret diff --git a/src/libc/arch/amd64/_Exit-linux.s b/src/libc/arch/amd64/_Exit-linux.s @@ -1,8 +0,0 @@ - .file "_Exit-linux.s" - - .text - .globl _Exit -_Exit: - movq $60,%rax - syscall - ret diff --git a/src/libc/arch/amd64/_getpid-bsd.s b/src/libc/arch/amd64/_getpid-bsd.s @@ -1,8 +0,0 @@ - .file "_getpid-bsd.s" - - .text - .globl _getpid -_getpid: - movq $20,%rax - syscall - ret diff --git a/src/libc/arch/amd64/_getpid-linux.s b/src/libc/arch/amd64/_getpid-linux.s @@ -1,8 +0,0 @@ - .file "_getpid-linux.s" - - .text - .globl _getpid -_getpid: - movq $20,%rax - syscall - ret diff --git a/src/libc/arch/amd64/_kill-bsd.s b/src/libc/arch/amd64/_kill-bsd.s @@ -1,8 +0,0 @@ - .file "_kill-bsd.s" - - .text - .globl _kill -_kill: - movq $37,%rax - syscall - ret diff --git a/src/libc/arch/amd64/_kill-linux.s b/src/libc/arch/amd64/_kill-linux.s @@ -1,8 +0,0 @@ - .file "_kill-linux.s" - - .text - .globl _kill -_kill: - movq $37,%rax - syscall - ret diff --git a/src/libc/arch/amd64/_write-bsd.s b/src/libc/arch/amd64/_write-bsd.s @@ -1,8 +0,0 @@ - .file "_write-bsd.s" - - .text - .globl _write -_write: - movq $4,%rax - syscall - ret diff --git a/src/libc/arch/amd64/_write-linux.s b/src/libc/arch/amd64/_write-linux.s @@ -1,8 +0,0 @@ - .file "_write-linux.s" - - .text - .globl _write -_write: - movq $1,%rax - syscall - ret diff --git a/src/libc/arch/amd64/bsd/.gitignore b/src/libc/arch/amd64/bsd/.gitignore @@ -0,0 +1,8 @@ +_Exit.s +_close.s +_getpid.s +_kill.s +_lseek.s +_open.s +_read.s +_write.s diff --git a/src/libc/arch/amd64/bsd/Makefile b/src/libc/arch/amd64/bsd/Makefile @@ -0,0 +1,21 @@ +PROJECTDIR =../../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +SRC = _Exit.s \ + _close.s \ + _getpid.s \ + _kill.s \ + _lseek.s \ + _open.s \ + _read.s \ + _write.s \ + +all: $(SRC:.s=.o) + +$(SRC): gen + +gen: FORCE + ./gensys.sh syscall.lst + +clean: + rm -f *.s diff --git a/src/libc/arch/amd64/bsd/gensys.sh b/src/libc/arch/amd64/bsd/gensys.sh @@ -0,0 +1,15 @@ +#!/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 rax + +awk '/^#/ {next} + {name=$2 ".s" + printf ".global %s\n" \ + "%s:\n" \ + "\tmovq\t$%d,%%rax\n" \ + "\tsyscall\n" \ + "\tret\n", $2, $2, $1 > name + close(name)}' syscall.lst diff --git a/src/libc/arch/amd64/bsd/objlst.mk b/src/libc/arch/amd64/bsd/objlst.mk @@ -0,0 +1,10 @@ +SYSOBJ = $(LIBSYS)/_Exit.o \ + $(LIBSYS)/_close.o \ + $(LIBSYS)/_getpid.o \ + $(LIBSYS)/_kill.o \ + $(LIBSYS)/_lseek.o \ + $(LIBSYS)/_open.o \ + $(LIBSYS)/_read.o \ + $(LIBSYS)/_write.o \ + $(LIBARCH)/setjmp.o \ + $(LIBARCH)/longjmp.o \ diff --git a/src/libc/arch/amd64/bsd/syscall.lst b/src/libc/arch/amd64/bsd/syscall.lst @@ -0,0 +1,9 @@ +#number name +1 _Exit +3 _read +4 _write +5 _open +6 _close +20 _getpid +37 _kill +199 _lseek diff --git a/src/libc/arch/amd64/linux/.gitignore b/src/libc/arch/amd64/linux/.gitignore @@ -0,0 +1,8 @@ +_Exit.s +_close.s +_getpid.s +_kill.s +_lseek.s +_open.s +_read.s +_write.s diff --git a/src/libc/arch/amd64/linux/Makefile b/src/libc/arch/amd64/linux/Makefile @@ -0,0 +1,21 @@ +PROJECTDIR =../../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +SRC = _Exit.s \ + _close.s \ + _getpid.s \ + _kill.s \ + _lseek.s \ + _open.s \ + _read.s \ + _write.s \ + +all: $(SRC:.s=.o) + +$(SRC): gen + +gen: FORCE + ./gensys.sh syscall.lst + +clean: + rm -f *.s diff --git a/src/libc/arch/amd64/linux/gensys.sh b/src/libc/arch/amd64/linux/gensys.sh @@ -0,0 +1,15 @@ +#!/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 rax + +awk '/^#/ {next} + {name=$2 ".s" + printf ".global %s\n" \ + "%s:\n" \ + "\tmovq\t$%d,%%rax\n" \ + "\tsyscall\n" \ + "\tret\n", $2, $2, $1 > name + close(name)}' syscall.lst diff --git a/src/libc/arch/amd64/linux/objlst.mk b/src/libc/arch/amd64/linux/objlst.mk @@ -0,0 +1,11 @@ +SYSOBJ = $(LIBSYS)/_Exit.o \ + $(LIBSYS)/_close.o \ + $(LIBSYS)/_getpid.o \ + $(LIBSYS)/_kill.o \ + $(LIBSYS)/_lseek.o \ + $(LIBSYS)/_open.o \ + $(LIBSYS)/_read.o \ + $(LIBSYS)/_write.o \ + $(LIBSYS)/_lseek.o \ + $(LIBARCH)/setjmp.o \ + $(LIBARCH)/longjmp.o \ diff --git a/src/libc/arch/amd64/linux/syscall.lst b/src/libc/arch/amd64/linux/syscall.lst @@ -0,0 +1,9 @@ +#number name +0 _read +1 _write +2 _open +3 _close +3 _lseek +38 _getpid +60 _Exit +32 _kill diff --git a/src/libc/arch/arm64/Makefile b/src/libc/arch/arm64/Makefile @@ -0,0 +1,13 @@ +PROJECTDIR =../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = longjmp.o setjmp.o +DIRS = none linux + +all: $(OBJS) $(SYS) + +$(SYS): FORCE + +@cd $@ && $(MAKE) + +clean: + $(FORALL) diff --git a/src/libc/arch/arm64/_Exit-linux.s b/src/libc/arch/arm64/_Exit-linux.s @@ -1,8 +0,0 @@ - .file "_Exit-linux.s" - - .text - .globl _Exit -_Exit: - mov x8,#93 - svc 0 - ret diff --git a/src/libc/arch/arm64/_Exit-none.s b/src/libc/arch/arm64/_Exit-none.s @@ -1,10 +0,0 @@ - .file "_Exit-none.s" - - .text - .globl _Exit -_Exit: - ldr x0,=msg - b panic - - .section .rodata -msg: .asciz "_Exit" diff --git a/src/libc/arch/arm64/_getpid-linux.s b/src/libc/arch/arm64/_getpid-linux.s @@ -1,8 +0,0 @@ - .file "_getpid-linux.s" - - .text - .globl _getpid -_getpid: - mov x8,#172 - svc 0 - ret diff --git a/src/libc/arch/arm64/_getpid-none.s b/src/libc/arch/arm64/_getpid-none.s @@ -1,10 +0,0 @@ - .file "_getpid-none.s" - - .text - .globl _getpid -_getpid: - ldr x0,=msg - b panic - - .section .rodata -msg: .asciz "_getpid" diff --git a/src/libc/arch/arm64/_kill-linux.s b/src/libc/arch/arm64/_kill-linux.s @@ -1,8 +0,0 @@ - .file "_kill-linux.s" - - .text - .globl _kill -_kill: - mov x8,#129 - svc 0 - ret diff --git a/src/libc/arch/arm64/_kill-none.s b/src/libc/arch/arm64/_kill-none.s @@ -1,10 +0,0 @@ - .file "_kill-none.s" - - .text - .globl _kill -_kill: - ldr x0,=msg - b panic - - .section .rodata -msg: .asciz "_kill" diff --git a/src/libc/arch/arm64/_write-linux.s b/src/libc/arch/arm64/_write-linux.s @@ -1,8 +0,0 @@ - .file "_write-linux.s" - - .text - .globl _write -_write: - mov x8,#64 - svc 0 - ret diff --git a/src/libc/arch/arm64/_write-none.s b/src/libc/arch/arm64/_write-none.s @@ -1,13 +0,0 @@ - .file "_write-none.s" - - .text - .globl _write -/* - * x0 = fd (unused) - * x1 = buf - * x2 = cnt - */ -_write: - mov x0,x1 - mov x1,x2 - b uartwrite diff --git a/src/libc/arch/arm64/linux/.gitignore b/src/libc/arch/arm64/linux/.gitignore @@ -0,0 +1,8 @@ +_Exit.s +_close.s +_getpid.s +_kill.s +_lseek.s +_openat.s +_read.s +_write.s diff --git a/src/libc/arch/arm64/linux/Makefile b/src/libc/arch/arm64/linux/Makefile @@ -0,0 +1,19 @@ +PROJECTDIR =../../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +SRC = _Exit.s \ + _close.s \ + _getpid.s \ + _kill.s \ + _lseek.s \ + _openat.s \ + _read.s \ + _write.s \ + +all: $(SRC:.s=.o) _open.o + +$(SRC): syscall.lst + ./gensys.sh syscall.lst + +clean: + rm -f *.s diff --git a/src/libc/arch/arm64/linux/_open.c b/src/libc/arch/arm64/linux/_open.c @@ -0,0 +1,13 @@ +#include <stddef.h> + +#include "../../../syscall.h" + +#define AT_FDCWD -100 + +extern int _openat(int fd, const char *fname, int flags); + +int +_open(const char *fname, int flags) +{ + return _openat(AT_FDCWD, fname, flags); +} diff --git a/src/libc/arch/arm64/linux/gensys.sh b/src/libc/arch/arm64/linux/gensys.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# +# This job is very easy because app and kernel ABI are identical + +awk '/^#/ {next} + {name=$2 ".s" + printf ".file\t\"%s\"\n\n" \ + ".global %s\n" \ + "%s:\n" \ + "\tmov\tx8,#%d\n"\ + "\tsvc\t0\n" \ + "\tret\n", name, $2, $2, $1 > name + close(name)}' syscall.lst diff --git a/src/libc/arch/arm64/linux/objlst.mk b/src/libc/arch/arm64/linux/objlst.mk @@ -0,0 +1,11 @@ +SYSOBJ = $(LIBSYS)/_Exit.o \ + $(LIBSYS)/_close.o \ + $(LIBSYS)/_getpid.o \ + $(LIBSYS)/_kill.o \ + $(LIBSYS)/_lseek.o \ + $(LIBSYS)/_open.o \ + $(LIBSYS)/_openat.o \ + $(LIBSYS)/_read.o \ + $(LIBSYS)/_write.o \ + $(LIBARCH)/setjmp.o \ + $(LIBARCH)/longjmp.o \ diff --git a/src/libc/arch/arm64/linux/syscall.lst b/src/libc/arch/arm64/linux/syscall.lst @@ -0,0 +1,9 @@ +#number name +56 _openat +57 _close +63 _read +64 _write +93 _Exit +172 _getpid +129 _kill +62 _lseek diff --git a/src/libc/arch/arm64/none/Makefile b/src/libc/arch/arm64/none/Makefile @@ -0,0 +1,9 @@ +PROJECTDIR =../../../../.. +include $(PROJECTDIR)/scripts/rules.mk + +OBJS = _Exit.o \ + _getpid.o \ + _kill.o \ + _write.o \ + +all: $(OBJS) diff --git a/src/libc/arch/arm64/none/_Exit.s b/src/libc/arch/arm64/none/_Exit.s @@ -0,0 +1,10 @@ + .file "_Exit.s" + + .text + .globl _Exit +_Exit: + adr x0,msg + b panic + + .section .rodata +msg: .asciz "_Exit" diff --git a/src/libc/arch/arm64/none/_getpid.s b/src/libc/arch/arm64/none/_getpid.s @@ -0,0 +1,10 @@ + .file "_getpid.s" + + .text + .globl _getpid +_getpid: + adr x0,msg + b panic + + .section .rodata +msg: .asciz "_getpid" diff --git a/src/libc/arch/arm64/none/_kill.s b/src/libc/arch/arm64/none/_kill.s @@ -0,0 +1,10 @@ + .file "_kill.s" + + .text + .globl _kill +_kill: + adr x0,msg + b panic + + .section .rodata +msg: .asciz "_kill" diff --git a/src/libc/arch/arm64/none/_write.s b/src/libc/arch/arm64/none/_write.s @@ -0,0 +1,13 @@ + .file "_write.s" + + .text + .globl _write +/* + * x0 = fd (unused) + * x1 = buf + * x2 = cnt + */ +_write: + mov x0,x1 + mov x1,x2 + b uartwrite diff --git a/src/libc/arch/arm64/none/objlst.mk b/src/libc/arch/arm64/none/objlst.mk @@ -0,0 +1,6 @@ +SYSOBJ = $(LIBSYS)/_Exit.o \ + $(LIBSYS)/_getpid.o \ + $(LIBSYS)/_kill.o \ + $(LIBSYS)/_write.o \ + $(LIBARCH)/setjmp.o \ + $(LIBARCH)/longjmp.o \ diff --git a/src/libc/arch/arm64/raise.c b/src/libc/arch/arm64/raise.c @@ -1,9 +0,0 @@ -#include "signal.h" - -#undef raise - -int -raise(int signum) -{ - panic("aborted"); -}