9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 37580425501e68b35e0e5b2814c2f815eae83b88
parent 548f490090944f6f774e0833bef40f9c8bfce6e8
Author: Roberto Vargas <roberto.vargas@arm.com>
Date:   Thu, 18 Oct 2018 09:29:41 +0100

[libc] Add support for errno in syscalls

Change-Id: I7473b4a14cc2c8cb6800f962d41e0d4c4fedb827

Diffstat:
Msrc/libc/Makefile | 5++---
Msrc/libc/arch/amd64/bsd/Makefile | 6++----
Msrc/libc/arch/amd64/bsd/gensys.sh | 27+++++++++++++++++++--------
Msrc/libc/arch/amd64/linux/Makefile | 8+++-----
Asrc/libc/arch/amd64/linux/_cerrno.s | 12++++++++++++
Msrc/libc/arch/amd64/linux/gensys.sh | 22++++++++++++++--------
Msrc/libc/arch/amd64/linux/objlst.mk | 1+
Msrc/libc/arch/arm64/linux/Makefile | 4++--
Asrc/libc/arch/arm64/linux/_cerrno.s | 13+++++++++++++
Msrc/libc/arch/arm64/linux/gensys.sh | 25++++++++++++++++---------
Msrc/libc/arch/arm64/linux/objlst.mk | 1+
11 files changed, 85 insertions(+), 39 deletions(-)

diff --git a/src/libc/Makefile b/src/libc/Makefile @@ -66,9 +66,8 @@ COBJ = abort.o \ OBJS = $(COBJ) $(SYSOBJ) TARGET = $(PROJECTDIR)/lib/libc.a -all: $(TARGET) - -$(SYSOBJ): arch/$(ARCH)/$(SYS) +all: $(COBJS) arch/$(ARCH)/$(SYS) + +@$(MAKE) $(TARGET) arch/$(ARCH)/$(SYS): FORCE +@cd $@ && $(MAKE) diff --git a/src/libc/arch/amd64/bsd/Makefile b/src/libc/arch/amd64/bsd/Makefile @@ -12,10 +12,8 @@ SRC = _Exit.s \ all: $(SRC:.s=.o) -$(SRC): gen - -gen: FORCE +$(SRC): syscall.lst ./gensys.sh syscall.lst clean: - rm -f *.s + rm -f `awk '/[0-9]* _/ {print $$2".s"}' syscall.lst` diff --git a/src/libc/arch/amd64/bsd/gensys.sh b/src/libc/arch/amd64/bsd/gensys.sh @@ -5,11 +5,22 @@ # 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 +sed 's/[ ]*#.*// + /^$/d' syscall.lst | +while read num name +do +cat <<EOF > $name.s + .file "$name.s" + + .globl $name +$name: + movq \$$num,%rax + syscall + jb 1f + retq + +1: movl %eax,(errno) + movl $-1,%eax + retq +EOF +done diff --git a/src/libc/arch/amd64/linux/Makefile b/src/libc/arch/amd64/linux/Makefile @@ -10,12 +10,10 @@ SRC = _Exit.s \ _read.s \ _write.s \ -all: $(SRC:.s=.o) +all: $(SRC:.s=.o) _cerrno.o -$(SRC): gen - -gen: FORCE +$(SRC): syscall.lst ./gensys.sh syscall.lst clean: - rm -f *.s + rm -f `awk '/[0-9]* _/ {print $$2".s"}' syscall.lst` diff --git a/src/libc/arch/amd64/linux/_cerrno.s b/src/libc/arch/amd64/linux/_cerrno.s @@ -0,0 +1,12 @@ + .file "_cerrno.s" + .globl _cerrno + +_cerrno: + cmpq $0,%rax + js 1f + retq + +1: neg %rax + mov %eax,(errno) + mov $-1,%eax + retq diff --git a/src/libc/arch/amd64/linux/gensys.sh b/src/libc/arch/amd64/linux/gensys.sh @@ -5,11 +5,17 @@ # 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 +sed 's/[ ]*#.*// + /^$/d' syscall.lst | +while read num name +do +cat <<EOF > $name.s + .file "$name.s" + + .globl $name +$name: + movq \$$num,%rax + syscall + jmp _cerrno +EOF +done diff --git a/src/libc/arch/amd64/linux/objlst.mk b/src/libc/arch/amd64/linux/objlst.mk @@ -7,5 +7,6 @@ SYSOBJ = $(LIBSYS)/_Exit.o \ $(LIBSYS)/_read.o \ $(LIBSYS)/_write.o \ $(LIBSYS)/_lseek.o \ + $(LIBSYS)/_cerrno.o \ $(LIBARCH)/setjmp.o \ $(LIBARCH)/longjmp.o \ diff --git a/src/libc/arch/arm64/linux/Makefile b/src/libc/arch/arm64/linux/Makefile @@ -10,10 +10,10 @@ SRC = _Exit.s \ _read.s \ _write.s \ -all: $(SRC:.s=.o) _open.o +all: $(SRC:.s=.o) _open.o _cerrno.o $(SRC): syscall.lst ./gensys.sh syscall.lst clean: - rm -f *.s + rm -f `awk '/[0-9]* _/ {print $$2".s"}' syscall.lst` diff --git a/src/libc/arch/arm64/linux/_cerrno.s b/src/libc/arch/arm64/linux/_cerrno.s @@ -0,0 +1,13 @@ + .file "_cerrno.s" + .globl _cerrno + +_cerrno: + cmp x0,#0 + b.lt 1f + ret + +1: neg x0,x0 + adr x1,errno + str w1,[x0] + mov x0,#-1 + ret diff --git a/src/libc/arch/arm64/linux/gensys.sh b/src/libc/arch/arm64/linux/gensys.sh @@ -2,13 +2,20 @@ # # 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 ".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 +sed 's/[ ]*#.*// + /^$/d' syscall.lst | +while read num name +do +cat <<EOF > $name.s + .file "$name.s" + + .globl $name +$name: + mov x8,#$num + svc 0 + b _cerrno +EOF +done diff --git a/src/libc/arch/arm64/linux/objlst.mk b/src/libc/arch/arm64/linux/objlst.mk @@ -7,5 +7,6 @@ SYSOBJ = $(LIBSYS)/_Exit.o \ $(LIBSYS)/_openat.o \ $(LIBSYS)/_read.o \ $(LIBSYS)/_write.o \ + $(LIBSYS)/_cerrno.o \ $(LIBARCH)/setjmp.o \ $(LIBARCH)/longjmp.o \