ref: b7e9430d7f6df2b479baba4470474d130039e8c6
parent: 7e3c35928ca0acac963e16b7d0194a8896d0989c
author: Roberto E. Vargas Caballero <[email protected]>
date: Wed Dec 19 06:16:38 EST 2018
[libc] Add basic support for Darwin
--- a/config/amd64-linux.mk
+++ b/config/amd64-linux.mk
@@ -6,3 +6,4 @@
PREFIX = $(PWD)/$(PROJECTDIR)/root
MANPREFIX = $(PREFIX)/share/man
AS = as
+RANLIB = ranlib
--- a/config/i386-linux.mk
+++ b/config/i386-linux.mk
@@ -3,3 +3,4 @@
PREFIX = $(PWD)/$(PROJECTDIR)/root
MANPREFIX = $(PREFIX)/share/man
AS = as
+RANLIB = ranlib
--- a/scripts/rules.mk
+++ b/scripts/rules.mk
@@ -11,6 +11,8 @@
INCLUDE = -I$(INCDIR)/scc \
+RL = $(RANLIB)
+
SCC_CFLAGS = $(MORECFLAGS) \
$(SYSCFLAGS) \
$(INCLUDE) \
--- a/src/libc/arch/amd64/Makefile
+++ b/src/libc/arch/amd64/Makefile
@@ -4,7 +4,7 @@
include ../../rules.mk
OBJS = longjmp.o setjmp.o
-DIRS = netbsd openbsd dragonfly linux
+DIRS = netbsd openbsd dragonfly linux darwin
all: $(OBJS) $(SYS)
--- /dev/null
+++ b/src/libc/arch/amd64/darwin/Makefile
@@ -1,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
--- /dev/null
+++ b/src/libc/arch/amd64/darwin/_getheap.c
@@ -1,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;
+}
--- /dev/null
+++ b/src/libc/arch/amd64/darwin/_tzone.c
@@ -1,0 +1,1 @@
+#include "../../posix/_tzone.c"
--- /dev/null
+++ b/src/libc/arch/amd64/darwin/gensys.sh
@@ -1,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
--- /dev/null
+++ b/src/libc/arch/amd64/darwin/getenv.c
@@ -1,0 +1,1 @@
+#include "../../posix/getenv.c"
--- /dev/null
+++ b/src/libc/arch/amd64/darwin/raise.c
@@ -1,0 +1,1 @@
+#include "../../posix/raise.c"
--- /dev/null
+++ b/src/libc/arch/amd64/darwin/signal.c
@@ -1,0 +1,1 @@
+#include "../../posix/signal.c"
--- /dev/null
+++ b/src/libc/arch/amd64/darwin/syscall.lst
@@ -1,0 +1,9 @@
+1 __Exit
+3 __read
+4 __write
+5 __open
+6 __close
+20 __getpid
+46 __sigaction
+37 __kill
+199 __lseek
--- /dev/null
+++ b/src/libc/arch/amd64/darwin/time.c
@@ -1,0 +1,1 @@
+#include "../../posix/time.c"