shithub: scc

Download patch

ref: a90c5a46440cc4c6527b9b2c28d7d03b4553d82c
parent: e7d19b604ceba9e4d387cc837961a7138008b18a
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Oct 6 05:51:11 EDT 2019

[libcrt] Add libcrt

This library is intended for the C runtime. The C runtime must
supply the code needed to support the language.

diff: cannot open b/src/libcrt/amd64//null: file does not exist: 'b/src/libcrt/amd64//null' diff: cannot open b/src/libcrt/arm32//null: file does not exist: 'b/src/libcrt/arm32//null' diff: cannot open b/src/libcrt/arm64//null: file does not exist: 'b/src/libcrt/arm64//null' diff: cannot open b/src/libcrt/i386//null: file does not exist: 'b/src/libcrt/i386//null' diff: cannot open b/src/libcrt//null: file does not exist: 'b/src/libcrt//null'
--- a/src/Makefile
+++ b/src/Makefile
@@ -3,7 +3,7 @@
 PROJECTDIR = ..
 include $(PROJECTDIR)/scripts/rules.mk
 
-LIBS  = libscc libc libmach
+LIBS  = libcrt libscc libc libmach
 DIRS  = cmd $(LIBS)
 
 all: cmd
--- a/src/libc/Makefile.libc
+++ b/src/libc/Makefile.libc
@@ -4,14 +4,9 @@
 include rules.mk
 include objlst.mk
 
-LIBC   = $(LIBCDIR)/libc.a
-CRT    = $(LIBCDIR)/crt.o
-TARGET = $(LIBC) $(CRT)
+TARGET = $(LIBCDIR)/libc.a
 
 all: $(TARGET)
 
-$(LIBC): $(OBJS)
+$(TARGET): $(OBJS)
 	mklib -o $@ $?
-
-$(CRT): arch/$(ARCH)/$(SYS)/crt.o
-	cp arch/$(ARCH)/$(SYS)/crt.o $@
--- a/src/libc/arch/amd64/crt-posix.s
+++ /dev/null
@@ -1,19 +1,0 @@
-	.bss
-	.globl	_environ
-_environ:
-	.quad	0
-
-	.text
-	.globl	_start
-_start:
-	movq	%rsp,%rbp
-
-	/* load argc, argv, envp from stack */
-	movq	(%rbp),%rdi             /* argc */
-	leaq	8(%rbp),%rsi            /* argv */
-	leaq	16(%rbp,%rdi,8),%rdx    /* envp = argv + 8*argc + 8 */
-	movq	%rdx,_environ(%rip)
-
-	call	main
-	movl	%eax,%edi
-	jmp	exit
--- a/src/libc/arch/amd64/darwin/Makefile
+++ b/src/libc/arch/amd64/darwin/Makefile
@@ -19,14 +19,11 @@
         signal.o \
         time.o \
         _sys_errlist.o \
-        crt.o \
 
 all: syscall
 	$(MAKE) objs
 
 objs: $(OBJS)
-
-crt.o: ../crt-posix.s
 
 syscall: syscall.lst
 	gensys.sh syscall.lst
--- a/src/libc/arch/amd64/darwin/crt.s
+++ /dev/null
@@ -1,19 +1,0 @@
-	.bss
-	.globl	__environ
-__environ:
-	.quad	0
-
-	.text
-	.global	start
-start:
-	movq	%rsp,%rbp
-
-	/* load argc, argv, envp from stack */
-	movq	(%rbp),%rdi             /* argc */
-	leaq	8(%rbp),%rsi            /* argv */
-	leaq	16(%rbp,%rdi,8),%rdx    /* envp = argv + 8*argc + 8 */
-	movq	%rdx,__environ(%rip)
-
-	call	_main
-	movl	%eax,%edi
-	jmp	_exit
--- a/src/libc/arch/amd64/dragonfly/Makefile
+++ b/src/libc/arch/amd64/dragonfly/Makefile
@@ -20,14 +20,11 @@
         signal.o \
         time.o \
         _sys_errlist.o \
-        crt.o \
 
 all: syscall
 	$(MAKE) objs
 
 objs: $(OBJS)
-
-crt.o: crt-posix.s
 
 syscall: syscall.lst
 	gensys.sh syscall.lst
--- a/src/libc/arch/amd64/dragonfly/crt.s
+++ /dev/null
@@ -1,1 +1,0 @@
-	.include	"../crt-posix.s"
--- a/src/libc/arch/amd64/linux/Makefile
+++ b/src/libc/arch/amd64/linux/Makefile
@@ -22,14 +22,11 @@
         signal.o \
         time.o \
         _sys_errlist.o \
-        crt.o \
 
 all: syscall
 	$(MAKE) objs
 
 objs: $(OBJS)
-
-crt.o: ../crt-posix.s
 
 syscall: syscall.lst
 	gensys.sh syscall.lst
--- a/src/libc/arch/amd64/linux/crt.s
+++ /dev/null
@@ -1,1 +1,0 @@
-	.include	"../crt-posix.s"
--- a/src/libc/arch/amd64/netbsd/Makefile
+++ b/src/libc/arch/amd64/netbsd/Makefile
@@ -23,14 +23,11 @@
         signal.o \
         time.o \
         _sys_errlist.o \
-        crt.o \
 
 all: syscall
 	$(MAKE) objs
 
 objs: $(OBJS)
-
-crt.o: ../crt-posix.s ../../crt-netbsd.s
 
 syscall: syscall.lst
 	gensys.sh syscall.lst
--- a/src/libc/arch/amd64/netbsd/crt.s
+++ /dev/null
@@ -1,2 +1,0 @@
-	.include	"../../crt-netbsd.s"
-	.include	"../crt-posix.s"
--- a/src/libc/arch/amd64/openbsd/Makefile
+++ b/src/libc/arch/amd64/openbsd/Makefile
@@ -20,14 +20,11 @@
         signal.o \
         time.o \
         _sys_errlist.o \
-        crt.o \
 
 all: syscall
 	$(MAKE) objs
 
 objs: $(OBJS)
-
-crt.o: ../crt-posix.s ../../crt-openbsd.s
 
 syscall: syscall.lst
 	gensys.sh syscall.lst
--- a/src/libc/arch/amd64/openbsd/crt.s
+++ /dev/null
@@ -1,2 +1,0 @@
-	.include	"../../crt-openbsd.s"
-	.include	"../crt-posix.s"
--- a/src/libc/arch/arm32/crt-posix.s
+++ /dev/null
@@ -1,16 +1,0 @@
-	.bss
-	.globl	_environ
-_environ:
-	.word	0
-
-	.text
-	.globl	_start
-_start:
-	ldr	r0,[sp]		/* argc */
-	add	r1,sp,#4	/* argv */
-	add	r2,r1,r0,lsl #2	/* argv = argc + 4*argc + 4 */
-	add	r2,r2,#4
-	ldr	r3,=_environ
-	str	r2,[r3]
-	bl	main
-	b	exit
--- a/src/libc/arch/arm32/linux/Makefile
+++ b/src/libc/arch/arm32/linux/Makefile
@@ -22,14 +22,11 @@
         signal.o \
         time.o \
         _sys_errlist.o \
-        crt.o \
 
 all: syscall
 	$(MAKE) objs
 
 objs: $(OBJS)
-
-crt.o: ../crt-posix.s
 
 syscall: syscall.lst
 	gensys.sh syscall.lst
--- a/src/libc/arch/arm32/linux/crt.s
+++ /dev/null
@@ -1,1 +1,0 @@
-	.include	"../crt-posix.s"
--- a/src/libc/arch/arm64/crt-posix.s
+++ /dev/null
@@ -1,16 +1,0 @@
-	.bss
-	.globl	_environ
-_environ:
-	.quad	0
-
-	.text
-	.globl	_start
-_start:
-	ldr	x0,[sp]		/* argc */
-	add	x1,sp,#8	/* argv */
-	add	x2,x1,x0,lsl #3	/* argv = argc + 8*argc + 8 */
-	add	x2,x2,#8
-	adr	x3,_environ
-	str	x2,[x3]
-	bl	main
-	b	exit
--- a/src/libc/arch/arm64/linux/Makefile
+++ b/src/libc/arch/arm64/linux/Makefile
@@ -22,14 +22,11 @@
         signal.o \
         time.o \
         _sys_errlist.o \
-        crt.o \
 
 all: syscall
 	$(MAKE) objs
 
 objs: $(OBJS)
-
-crt.o: ../crt-posix.s
 
 syscall: syscall.lst
 	gensys.sh syscall.lst
--- a/src/libc/arch/arm64/linux/crt.s
+++ /dev/null
@@ -1,1 +1,0 @@
-	.include	"../crt-posix.c"
--- a/src/libc/arch/crt-netbsd.s
+++ /dev/null
@@ -1,9 +1,0 @@
-	.file	"crt-netbsd.s"
-	.section	".note.netbsd.ident", "a"
-	.p2align	2
-
-	.long	7
-	.long	4
-	.long	1
-	.ascii	"NetBSD\0\0"
-	.long	800000000
--- a/src/libc/arch/crt-openbsd.s
+++ /dev/null
@@ -1,9 +1,0 @@
-	.file	"crt-openbsd.s"
-	.section	".note.openbsd.ident", "a"
-	.p2align	2
-	.long	8
-	.long	4
-	.long	1
-	.ascii	"OpenBSD\0"
-	.long	0
-	.p2align	2
--- a/src/libc/arch/i386/crt-posix.s
+++ /dev/null
@@ -1,18 +1,0 @@
-	.bss
-	.globl	_environ
-_environ:
-	.long	0
-
-	.text
-	.global	start
-_start:
-	movl	%esp,%ebp
-
-	movl	(%ebp),%edi
-	leal	8(%ebp),%esi
-	leal	16(%ebp,%edi,8),%edx
-	movl	%edx,_environ
-
-	call 	main
-	movl	%eax,%edi
-	jmp	exit
--- a/src/libc/arch/i386/linux/Makefile
+++ b/src/libc/arch/i386/linux/Makefile
@@ -15,14 +15,11 @@
 	_getpid.o\
 	_Exit.o\
 	_kill.o\
-	crt.o\
 
 all: syscall
 	$(MAKE) objs
 
 objs: $(OBJS)
-
-crt.o:	../crt-posix.s
 
 syscall: syscall.lst
 	gensys.sh syscall.lst
--- a/src/libc/arch/i386/linux/crt.s
+++ /dev/null
@@ -1,1 +1,0 @@
-	.include	"../crt-posix.s"
--- /dev/null
+++ b/src/libcrt/Makefile
@@ -1,0 +1,6 @@
+.POSIX:
+PROJECTDIR=../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+all clean dep:
+	cd $(ARCH) && $(MAKE) $@
--- /dev/null
+++ b/src/libcrt/amd64/Makefile
@@ -1,0 +1,11 @@
+.POSIX:
+PROJECTDIR=../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS = crt-$(SYS).o
+TARGET = $(LIBCDIR)/libcrt.a
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+	mklib -o $@ $?
--- /dev/null
+++ b/src/libcrt/amd64/crt-darwin.s
@@ -1,0 +1,19 @@
+	.bss
+	.globl	__environ
+__environ:
+	.quad	0
+
+	.text
+	.global	start
+start:
+	movq	%rsp,%rbp
+
+	/* load argc, argv, envp from stack */
+	movq	(%rbp),%rdi             /* argc */
+	leaq	8(%rbp),%rsi            /* argv */
+	leaq	16(%rbp,%rdi,8),%rdx    /* envp = argv + 8*argc + 8 */
+	movq	%rdx,__environ(%rip)
+
+	call	_main
+	movl	%eax,%edi
+	jmp	_exit
--- /dev/null
+++ b/src/libcrt/amd64/crt-dragonfly.s
@@ -1,0 +1,1 @@
+	.include	"crt-posix.s"
--- /dev/null
+++ b/src/libcrt/amd64/crt-linux.s
@@ -1,0 +1,1 @@
+	.include	"crt-posix.s"
--- /dev/null
+++ b/src/libcrt/amd64/crt-netbsd.s
@@ -1,0 +1,2 @@
+	.include	"../netbsd-ident.s"
+	.include	"crt-posix.s"
--- /dev/null
+++ b/src/libcrt/amd64/crt-openbsd.s
@@ -1,0 +1,2 @@
+	.include	"../openbsd-ident.s"
+	.include	"crt-posix.s"
--- /dev/null
+++ b/src/libcrt/amd64/crt-posix.s
@@ -1,0 +1,19 @@
+	.bss
+	.globl	_environ
+_environ:
+	.quad	0
+
+	.text
+	.globl	_start
+_start:
+	movq	%rsp,%rbp
+
+	/* load argc, argv, envp from stack */
+	movq	(%rbp),%rdi             /* argc */
+	leaq	8(%rbp),%rsi            /* argv */
+	leaq	16(%rbp,%rdi,8),%rdx    /* envp = argv + 8*argc + 8 */
+	movq	%rdx,_environ(%rip)
+
+	call	main
+	movl	%eax,%edi
+	jmp	exit
--- /dev/null
+++ b/src/libcrt/arm32/Makefile
@@ -1,0 +1,11 @@
+.POSIX:
+PROJECTDIR=../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS = crt-$(SYS).o
+TARGET = $(LIBCDIR)/libcrt.a
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+	mklib -o $@ $?
--- /dev/null
+++ b/src/libcrt/arm32/crt-linux.s
@@ -1,0 +1,1 @@
+	.include	"crt-posix.s"
--- /dev/null
+++ b/src/libcrt/arm32/crt-posix.s
@@ -1,0 +1,16 @@
+	.bss
+	.globl	_environ
+_environ:
+	.word	0
+
+	.text
+	.globl	_start
+_start:
+	ldr	r0,[sp]		/* argc */
+	add	r1,sp,#4	/* argv */
+	add	r2,r1,r0,lsl #2	/* argv = argc + 4*argc + 4 */
+	add	r2,r2,#4
+	ldr	r3,=_environ
+	str	r2,[r3]
+	bl	main
+	b	exit
--- /dev/null
+++ b/src/libcrt/arm64/Makefile
@@ -1,0 +1,11 @@
+.POSIX:
+PROJECTDIR=../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS = crt-$(SYS).o
+TARGET = $(LIBCDIR)/libcrt.a
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+	mklib -o $@ $?
--- /dev/null
+++ b/src/libcrt/arm64/crt-linux.s
@@ -1,0 +1,1 @@
+	.include	"crt-posix.c"
--- /dev/null
+++ b/src/libcrt/arm64/crt-posix.s
@@ -1,0 +1,16 @@
+	.bss
+	.globl	_environ
+_environ:
+	.quad	0
+
+	.text
+	.globl	_start
+_start:
+	ldr	x0,[sp]		/* argc */
+	add	x1,sp,#8	/* argv */
+	add	x2,x1,x0,lsl #3	/* argv = argc + 8*argc + 8 */
+	add	x2,x2,#8
+	adr	x3,_environ
+	str	x2,[x3]
+	bl	main
+	b	exit
--- /dev/null
+++ b/src/libcrt/i386/Makefile
@@ -1,0 +1,11 @@
+.POSIX:
+PROJECTDIR=../../..
+include $(PROJECTDIR)/scripts/rules.mk
+
+OBJS = crt-$(SYS).o
+TARGET = $(LIBCDIR)/libcrt.a
+
+all: $(TARGET)
+
+$(TARGET): $(OBJS)
+	mklib -o $@ $?
--- /dev/null
+++ b/src/libcrt/i386/crt-linux.s
@@ -1,0 +1,1 @@
+	.include	"crt-posix.s"
--- /dev/null
+++ b/src/libcrt/i386/crt-posix.s
@@ -1,0 +1,18 @@
+	.bss
+	.globl	_environ
+_environ:
+	.long	0
+
+	.text
+	.global	_start
+_start:
+	movl	%esp,%ebp
+
+	movl	(%ebp),%edi
+	leal	8(%ebp),%esi
+	leal	16(%ebp,%edi,8),%edx
+	movl	%edx,_environ
+
+	call 	main
+	movl	%eax,%edi
+	jmp	exit
--- /dev/null
+++ b/src/libcrt/netbsd-ident.s
@@ -1,0 +1,9 @@
+	.file	"crt-netbsd.s"
+	.section	".note.netbsd.ident", "a"
+	.p2align	2
+
+	.long	7
+	.long	4
+	.long	1
+	.ascii	"NetBSD\0\0"
+	.long	800000000
--- /dev/null
+++ b/src/libcrt/openbsd-ident.s
@@ -1,0 +1,9 @@
+	.file	"crt-openbsd.s"
+	.section	".note.openbsd.ident", "a"
+	.p2align	2
+	.long	8
+	.long	4
+	.long	1
+	.ascii	"OpenBSD\0"
+	.long	0
+	.p2align	2