diff options
author | Marvin Borner | 2020-08-21 20:39:48 +0200 |
---|---|---|
committer | Marvin Borner | 2020-08-21 20:39:48 +0200 |
commit | f700ba6668dbdb91a03b2c5aa387eb4cabae8fcd (patch) | |
tree | b04a80efabb09c9da9726332ccd22cb5a325fe39 /libc | |
parent | 1339d96cea2c647991c178587008d6fc40772a78 (diff) |
Some things here and some things there
Diffstat (limited to 'libc')
-rw-r--r-- | libc/Makefile | 14 | ||||
-rw-r--r-- | libc/cpu.c | 2 | ||||
-rw-r--r-- | libc/crt/crt0.asm | 15 | ||||
-rw-r--r-- | libc/crt/crti.asm | 13 | ||||
-rw-r--r-- | libc/crt/crtn.asm | 9 | ||||
-rw-r--r-- | libc/inc/sys.h | 4 |
6 files changed, 50 insertions, 7 deletions
diff --git a/libc/Makefile b/libc/Makefile index f4286ae..d57b9c4 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -12,25 +12,29 @@ COBJS = str.o \ list.o CC = ../cross/opt/bin/i686-elf-gcc LD = ../cross/opt/bin/i686-elf-ld -OC = ../cross/opt/bin/i686-elf-ar +AR = ../cross/opt/bin/i686-elf-ar +AS = nasm # Flags to make the binary smaller TODO: Remove after indirect pointer support! CSFLAGS = -mpreferred-stack-boundary=2 -fno-asynchronous-unwind-tables -Os -CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -ffreestanding -fno-builtin -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Iinc/ +CFLAGS = $(CSFLAGS) -Wall -Wextra -nostdlib -nostdinc -fno-builtin -mno-red-zone -mgeneral-regs-only -std=c99 -m32 -pedantic-errors -Iinc/ + +ASFLAGS = -f elf32 %.o: %.c @$(CC) -c $(CFLAGS) $< -o $@ libc: CFLAGS += -Duserspace -fPIE libc: $(COBJS) + @$(AS) $(ASFLAGS) crt/crt0.asm -o crt0.o @mkdir -p ../build/ - @$(AR) qc ../build/libc.a $+ + @$(AR) rcs ../build/libc.a crt0.o $+ -libk: CFLAGS += -Dkernel +libk: CFLAGS += -Dkernel -ffreestanding libk: $(COBJS) @mkdir -p ../build/ - @$(AR) qc ../build/libk.a $+ + @$(AR) rcs ../build/libk.a $+ clean: @find . -name "*.o" -type f -delete @@ -47,6 +47,7 @@ void outl(u16 port, u32 data) __asm__ volatile("outl %0, %1" ::"a"(data), "Nd"(port)); } +#ifdef kernel void cli() { __asm__ volatile("cli"); @@ -73,3 +74,4 @@ void loop() cli(); idle(); } +#endif diff --git a/libc/crt/crt0.asm b/libc/crt/crt0.asm new file mode 100644 index 0000000..4d473ec --- /dev/null +++ b/libc/crt/crt0.asm @@ -0,0 +1,15 @@ +; MIT License, Copyright (c) 2020 Marvin Borner + +section .text + +extern main +extern sys1 + +global _start +_start: + call main + + push edi + push 6 + call sys1 + jmp $ diff --git a/libc/crt/crti.asm b/libc/crt/crti.asm new file mode 100644 index 0000000..394aaea --- /dev/null +++ b/libc/crt/crti.asm @@ -0,0 +1,13 @@ +; MIT License, Copyright (c) 2020 Marvin Borner + +section .init +global _init +_init: + push ebp + mov ebp, esp + +section .fini +global _fini +fini: + push ebp + mov ebp, esp diff --git a/libc/crt/crtn.asm b/libc/crt/crtn.asm new file mode 100644 index 0000000..f20ec6a --- /dev/null +++ b/libc/crt/crtn.asm @@ -0,0 +1,9 @@ +; MIT License, Copyright (c) 2020 Marvin Borner + +section .init + pop ebp + ret + +section .fini + pop ebp + ret diff --git a/libc/inc/sys.h b/libc/inc/sys.h index 88d83df..e776f44 100644 --- a/libc/inc/sys.h +++ b/libc/inc/sys.h @@ -35,9 +35,9 @@ int sysv(enum sys num, ...); #define read(path) (void *)sys1(SYS_READ, (int)path) #define write(path, buf) sys2(SYS_WRITE, (int)path, buf) #define exec(path, ...) sysv(SYS_EXEC, (int)path, ##__VA_ARGS__) -#define exit() \ +#define exit(status) \ { \ - sys0(SYS_EXIT); \ + sys1(SYS_EXIT, (int)status); \ while (1) { \ } \ } |