summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorDanny Holman <dholman@gymli.org>2024-06-05 13:47:01 -0500
committerDanny Holman <dholman@gymli.org>2024-06-05 13:47:01 -0500
commit5db066eb5184cc45e7634838b5b0b8c67cb2ae25 (patch)
tree9201570bb47cf57cd41f7efc8bf764b3ec70b802 /libc
parente5aff92e72a0d0e1c18ddaab80b2efe370f04588 (diff)
libc: create a skeleton libc and build targetsHEADmaster
Create build targets for a skeleton libc that only includes enough functionality to get a cross compiler running. Signed-off-by: Danny Holman <dholman@gymli.org>
Diffstat (limited to 'libc')
-rw-r--r--libc/Makefile70
-rw-r--r--libc/arch/i386/crti.s14
-rw-r--r--libc/arch/i386/crtn.s7
-rw-r--r--libc/arch/i386/include/bits/types.h41
-rw-r--r--libc/arch/i386/make.config6
-rw-r--r--libc/init.c2
-rw-r--r--libc/unistd.c4
7 files changed, 144 insertions, 0 deletions
diff --git a/libc/Makefile b/libc/Makefile
new file mode 100644
index 0000000..cc7fa8d
--- /dev/null
+++ b/libc/Makefile
@@ -0,0 +1,70 @@
+INCLUDE?=$(SYS_INCLUDE)
+CFLAGS?=-fPIC
+LDFLAGS?=-nostdlib -shared
+LIBS?=-lgcc
+
+# -- Do not edit below this line --
+
+CC:=i686-boxos-gcc
+VERSION:="$(shell git describe --abbrev=4 --dirty --always --tags)"
+INCLUDE:=$(INCLUDE)
+CFLAGS:=$(CFLAGS) -Wall -Wextra -DVERSION=\"$(VERSION)\" -ggdb
+LDFLAGS:=$(LDFLAGS)
+LIBS:=$(LIBS)
+
+ARCHDIR=arch/$(ARCH)
+
+include $(ARCHDIR)/make.config
+
+CFLAGS:=$(CFLAGS) $(LIBC_ARCH_CFLAGS)
+LDFLAGS:=$(LDFLAGS) $(LIBC_ARCH_LDFLAGS)
+LIBS:=$(LIBS) $(LIBC_ARCH_LIBS)
+
+LIBC=libc.so
+
+LIBC_OBJS=$(LIBC_ARCH_OBJS) \
+ init.o \
+ unistd.o \
+
+OBJS=$(ARCHDIR)/crti.o \
+ $(LIBC_OBJS) \
+ $(ARCHDIR)/crtn.o \
+
+LINK_LIST=$(LDFLAGS) \
+ $(OBJS) \
+ $(LIBS) \
+
+.PHONY: all clean install install-headers
+.SUFFIXES: .o .c .s
+
+all: $(LIBC)
+
+$(LIBC): $(OBJS)
+ @$(CC) -o $@ $(LINK_LIST)
+ @echo [LD] $@
+
+.c.o:
+ @$(CC) -MD -c $< -o $@ $(CFLAGS) $(INCLUDE)
+ @echo [CC] $@
+
+.s.o:
+ @$(CC) -MD -c $< -o $@ $(CFLAGS) $(INCLUDE)
+ @echo [AS] $@
+
+install: install-headers
+ install -m 755 $(LIBC) $(SYS_ROOT)/lib
+
+install-headers:
+ install -d $(SYS_ROOT)/usr/include
+ install -d $(SYS_ROOT)/usr/include/sys
+ install -d $(SYS_ROOT)/usr/include/arpa
+ for f in $(ROOT)/include/*; do install -m 644 "$$f" $(SYS_ROOT)/usr/include/; done
+ for f in $(ROOT)/include/sys/*; do install -m 644 "$$f" $(SYS_ROOT)/usr/include/sys/; done
+ for f in $(ROOT)/include/arpa/*; do install -m 644 "$$f" $(SYS_ROOT)/usr/include/arpa/; done
+
+clean:
+ $(RM) $(LIBC)
+ $(RM) $(OBJS) *.o */*.o */*/*.o
+ $(RM) $(OBJS:.o=.d) *.d */*.d */*/*.d
+
+-include $(OBJS:.o=.d)
diff --git a/libc/arch/i386/crti.s b/libc/arch/i386/crti.s
new file mode 100644
index 0000000..906414b
--- /dev/null
+++ b/libc/arch/i386/crti.s
@@ -0,0 +1,14 @@
+.section .init
+
+.global _init
+.type _init, @function
+_init:
+ pushl %ebp
+ movl %esp, %ebp
+
+.section .fini
+
+.global _fini
+_fini:
+ pushl %ebp
+ movl %esp, %ebp
diff --git a/libc/arch/i386/crtn.s b/libc/arch/i386/crtn.s
new file mode 100644
index 0000000..447afb1
--- /dev/null
+++ b/libc/arch/i386/crtn.s
@@ -0,0 +1,7 @@
+.section .init
+ popl %ebp
+ ret
+
+.section .fini
+ popl %ebp
+ ret
diff --git a/libc/arch/i386/include/bits/types.h b/libc/arch/i386/include/bits/types.h
new file mode 100644
index 0000000..99946ff
--- /dev/null
+++ b/libc/arch/i386/include/bits/types.h
@@ -0,0 +1,41 @@
+#ifndef BITS_TYPES_H
+
+typedef unsigned char __u_char;
+typedef unsigned short __u_short;
+typedef unsigned int __u_int;
+typedef unsigned long __u_long;
+
+typedef signed char __int8_t;
+typedef signed short int __int16_t;
+typedef signed int __int32_t;
+typedef signed long __int64_t;
+
+typedef unsigned char __uint8_t;
+typedef unsigned short int __uint16_t;
+typedef unsigned int __uint32_t;
+typedef unsigned long __uint64_t;
+
+typedef __int8_t __int_least8_t;
+typedef __int16_t __int_least16_t;
+typedef __int32_t __int_least32_t;
+typedef __int64_t __int_least64_t;
+
+typedef __uint8_t __uint_least8_t;
+typedef __uint16_t __uint_least16_t;
+typedef __uint32_t __uint_least32_t;
+typedef __uint64_t __uint_least64_t;
+
+typedef __int8_t int8_t;
+typedef __int16_t int16_t;
+typedef __int32_t int32_t;
+typedef __int64_t int64_t;
+
+typedef __uint8_t uint8_t;
+typedef __uint16_t uint16_t;
+typedef __uint32_t uint32_t;
+typedef __uint64_t uint64_t;
+
+typedef __int32_t intptr_t;
+typedef __uint32_t uintptr_t;
+
+#endif
diff --git a/libc/arch/i386/make.config b/libc/arch/i386/make.config
new file mode 100644
index 0000000..25c1254
--- /dev/null
+++ b/libc/arch/i386/make.config
@@ -0,0 +1,6 @@
+LIBC_ARCH_INCLUDE=$(ARCHDIR)/include
+LIBC_ARCH_CFLAGS=-I$(LIBC_ARCH_INCLUDE)
+LIBC_ARCH_LDFLAGS=
+LIBC_ARCH_LIBS=
+
+LIBC_ARCH_OBJS=
diff --git a/libc/init.c b/libc/init.c
new file mode 100644
index 0000000..b6c636b
--- /dev/null
+++ b/libc/init.c
@@ -0,0 +1,2 @@
+void libc_init(void) {
+}
diff --git a/libc/unistd.c b/libc/unistd.c
new file mode 100644
index 0000000..5cca686
--- /dev/null
+++ b/libc/unistd.c
@@ -0,0 +1,4 @@
+#include <unistd.h>
+
+void _exit(int status) {
+}