scc

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

commit d1e9a55df1fc8d7444569033f72042fdd208f0b6
parent 38525701a87109668c97a64fa7d39a54e6ebb84c
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 19 Dec 2018 11:16:38 +0000

[libc] Add basic support for Darwin

Diffstat:
Mconfig/amd64-linux.mk | 1+
Mconfig/i386-linux.mk | 1+
Mscripts/rules.mk | 2++
Msrc/libc/arch/amd64/Makefile | 2+-
Asrc/libc/arch/amd64/darwin/Makefile | 34++++++++++++++++++++++++++++++++++
Asrc/libc/arch/amd64/darwin/_getheap.c | 18++++++++++++++++++
Asrc/libc/arch/amd64/darwin/_tzone.c | 1+
Asrc/libc/arch/amd64/darwin/gensys.sh | 25+++++++++++++++++++++++++
Asrc/libc/arch/amd64/darwin/getenv.c | 1+
Asrc/libc/arch/amd64/darwin/raise.c | 1+
Asrc/libc/arch/amd64/darwin/signal.c | 1+
Asrc/libc/arch/amd64/darwin/syscall.lst | 9+++++++++
Asrc/libc/arch/amd64/darwin/time.c | 1+
13 files changed, 96 insertions(+), 1 deletion(-)

diff --git a/config/amd64-linux.mk b/config/amd64-linux.mk @@ -6,3 +6,4 @@ STD = c99 PREFIX = $(PWD)/$(PROJECTDIR)/root MANPREFIX = $(PREFIX)/share/man AS = as +RANLIB = ranlib diff --git a/config/i386-linux.mk b/config/i386-linux.mk @@ -3,3 +3,4 @@ STD = c99 PREFIX = $(PWD)/$(PROJECTDIR)/root MANPREFIX = $(PREFIX)/share/man AS = as +RANLIB = ranlib diff --git a/scripts/rules.mk b/scripts/rules.mk @@ -11,6 +11,8 @@ CRTDIR = $(PROJECTDIR)/lib/scc INCLUDE = -I$(INCDIR)/scc \ +RL = $(RANLIB) + SCC_CFLAGS = $(MORECFLAGS) \ $(SYSCFLAGS) \ $(INCLUDE) \ diff --git a/src/libc/arch/amd64/Makefile b/src/libc/arch/amd64/Makefile @@ -4,7 +4,7 @@ include $(PROJECTDIR)/scripts/rules.mk include ../../rules.mk OBJS = longjmp.o setjmp.o -DIRS = netbsd openbsd dragonfly linux +DIRS = netbsd openbsd dragonfly linux darwin all: $(OBJS) $(SYS) diff --git a/src/libc/arch/amd64/darwin/Makefile b/src/libc/arch/amd64/darwin/Makefile @@ -0,0 +1,34 @@ +.POSIX: +PROJECTDIR =../../../../.. +include $(PROJECTDIR)/scripts/rules.mk +include ../../../rules.mk + +OBJS = __Exit.o \ + __close.o \ + __getpid.o \ + __kill.o \ + __lseek.o \ + __open.o \ + __read.o \ + __write.o \ + __sigaction.o\ + _getheap.o \ + _tzone.o \ + getenv.o \ + raise.o \ + signal.o \ + time.o \ + _sys_errlist.o \ + +all: syscall + $(MAKE) objs + +objs: $(OBJS) + +syscall: syscall.lst + ./gensys.sh syscall.lst + touch syscall + +clean: + rm -f `awk '$$2 ~ /^__/ {print $$2".s"}' syscall.lst` + rm -f syscall _sys_errlist.c diff --git a/src/libc/arch/amd64/darwin/_getheap.c b/src/libc/arch/amd64/darwin/_getheap.c @@ -0,0 +1,18 @@ +static char heap[16384]; + +void * +_getheap(void) +{ + return heap; +} + +void * +_brk(void *addr) +{ + static char *cur = heap; + char *p = addr; + + if (p < heap || p > &heap[sizeof(heap) - 1]) + return (void *)-1; + return cur = p; +} diff --git a/src/libc/arch/amd64/darwin/_tzone.c b/src/libc/arch/amd64/darwin/_tzone.c @@ -0,0 +1 @@ +#include "../../posix/_tzone.c" diff --git a/src/libc/arch/amd64/darwin/gensys.sh b/src/libc/arch/amd64/darwin/gensys.sh @@ -0,0 +1,25 @@ +#!/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 'NF == 2 {printf("0x%x\t%s\n", 33554432 + $1, $2)}' 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: movq %rax,_errno(%rip) + movq \$-1,%rax + retq +EOF +done diff --git a/src/libc/arch/amd64/darwin/getenv.c b/src/libc/arch/amd64/darwin/getenv.c @@ -0,0 +1 @@ +#include "../../posix/getenv.c" diff --git a/src/libc/arch/amd64/darwin/raise.c b/src/libc/arch/amd64/darwin/raise.c @@ -0,0 +1 @@ +#include "../../posix/raise.c" diff --git a/src/libc/arch/amd64/darwin/signal.c b/src/libc/arch/amd64/darwin/signal.c @@ -0,0 +1 @@ +#include "../../posix/signal.c" diff --git a/src/libc/arch/amd64/darwin/syscall.lst b/src/libc/arch/amd64/darwin/syscall.lst @@ -0,0 +1,9 @@ +1 __Exit +3 __read +4 __write +5 __open +6 __close +20 __getpid +46 __sigaction +37 __kill +199 __lseek diff --git a/src/libc/arch/amd64/darwin/time.c b/src/libc/arch/amd64/darwin/time.c @@ -0,0 +1 @@ +#include "../../posix/time.c"