From 50392995d6e7f3a10fb74bb2f9073a4790f8933c Mon Sep 17 00:00:00 2001 From: Jon Santmyer Date: Mon, 11 Mar 2024 21:40:28 -0400 Subject: simple env with basic test init program --- lib/crt/Makefile | 8 ++++++++ lib/crt/x86_64/crt0.s | 22 ++++++++++++++++++++++ lib/crt/x86_64/crti.s | 11 +++++++++++ lib/crt/x86_64/crtn.s | 7 +++++++ lib/jlibc/Makefile | 12 ++++++++++++ lib/jlibc/stdlib/exit.c | 5 +++++ 6 files changed, 65 insertions(+) create mode 100644 lib/crt/Makefile create mode 100644 lib/crt/x86_64/crt0.s create mode 100644 lib/crt/x86_64/crti.s create mode 100644 lib/crt/x86_64/crtn.s create mode 100644 lib/jlibc/Makefile create mode 100644 lib/jlibc/stdlib/exit.c (limited to 'lib') diff --git a/lib/crt/Makefile b/lib/crt/Makefile new file mode 100644 index 0000000..8b809fa --- /dev/null +++ b/lib/crt/Makefile @@ -0,0 +1,8 @@ +SFILES := $(wildcard $(TARGET_MACHINE)/*.s) +OFILES := $(patsubst %.s,%.o,$(SFILES)) + +all: ${OFILES} + cp ${OFILES} $(LIBDIR)/ + +%.o:%.s + $(AS) $< -o $@ diff --git a/lib/crt/x86_64/crt0.s b/lib/crt/x86_64/crt0.s new file mode 100644 index 0000000..c5a0ba9 --- /dev/null +++ b/lib/crt/x86_64/crt0.s @@ -0,0 +1,22 @@ +.section .text +.global _start +_start: + #Setup start of stack frame + xorq %rbp, %rbp + pushq %rbp + pushq %rbp + movq %rsp, %rbp + + #Save arguments passed to main + pushq %rdi + pushq %rsi + + #Setup libc and call global constructors + + #Call main + call main + + #Exit + movq %rax, %rdi + call exit +.size _start, . - _start diff --git a/lib/crt/x86_64/crti.s b/lib/crt/x86_64/crti.s new file mode 100644 index 0000000..0f06273 --- /dev/null +++ b/lib/crt/x86_64/crti.s @@ -0,0 +1,11 @@ +.section .init +.global _init +_init: + pushq %rbp + movq %rsp, %rbp + +.section .fini +.global _fini +_fini: + pushq %rbp + movq %rsp, %rbp diff --git a/lib/crt/x86_64/crtn.s b/lib/crt/x86_64/crtn.s new file mode 100644 index 0000000..9e31c23 --- /dev/null +++ b/lib/crt/x86_64/crtn.s @@ -0,0 +1,7 @@ +.section .init + popq %rbp + ret + +.section .fini + popq %rbp + ret diff --git a/lib/jlibc/Makefile b/lib/jlibc/Makefile new file mode 100644 index 0000000..65e645c --- /dev/null +++ b/lib/jlibc/Makefile @@ -0,0 +1,12 @@ +CFILES := $(wildcard *.c) +CFILES += $(wildcard */*.c) + +OFILES := $(patsubst %.c,%.o,$(CFILES)) + +all: $(OUT) + +$(OUT): ${OFILES} + ar rcs $@ ${OFILES} + +%.o:%.c + $(CC) $(CFLAGS) -c $< -o $@ diff --git a/lib/jlibc/stdlib/exit.c b/lib/jlibc/stdlib/exit.c new file mode 100644 index 0000000..225f74e --- /dev/null +++ b/lib/jlibc/stdlib/exit.c @@ -0,0 +1,5 @@ +__attribute__((noreturn)) +void exit(int status) +{ + +} -- cgit v1.2.1