From ef6ef5865b83ff2546e0b64c266bfaf94abbdb35 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Wed, 9 Sep 2020 16:04:06 +0200 Subject: [PATCH] Implement support functions ourselves instead of relying on libgcc --- src/Makefile | 6 +----- src/decompressor/Makefile | 2 +- src/lib/builtins.asm | 45 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/src/Makefile b/src/Makefile index 26b9883e..32684a2a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -32,16 +32,12 @@ limine.bin: libgcc.a $(BC) $(ASM_OBJ) llvm-link $(BC) -o bundle.bc opt --O$(OPT_LEVEL) bundle.bc -o optimised_bundle.bc clang --target=i386-elf -O$(OPT_LEVEL) -c optimised_bundle.bc -o optimised_bundle.o - ld.lld optimised_bundle.o $(ASM_OBJ) libgcc.a $(INTERNAL_LDFLAGS) -o stage2.elf + ld.lld optimised_bundle.o $(ASM_OBJ) $(INTERNAL_LDFLAGS) -o stage2.elf llvm-objcopy -O binary stage2.elf stage2.bin gzip -9 stage2.bin $(MAKE) -C decompressor cd bootsect && nasm bootsect.asm -fbin -o ../limine.bin -libgcc.a: - curl https://mirror.netcologne.de/archlinux/core/os/x86_64/gcc-10.2.0-2-x86_64.pkg.tar.zst | \ - tar -I zstd -xv --strip-components=6 --occurrence=1 usr/lib/gcc/x86_64-pc-linux-gnu/10.2.0/32/libgcc.a - %.bc: %.c clang --target=i386-elf $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@ diff --git a/src/decompressor/Makefile b/src/decompressor/Makefile index 7115eb4c..4a774b94 100644 --- a/src/decompressor/Makefile +++ b/src/decompressor/Makefile @@ -30,7 +30,7 @@ decompressor.bin: $(BC) llvm-link $(BC) -o bundle.bc opt --O$(OPT_LEVEL) bundle.bc -o optimised_bundle.bc clang --target=i386-elf -O$(OPT_LEVEL) -c optimised_bundle.bc -o optimised_bundle.o - ld.lld optimised_bundle.o ../libgcc.a $(INTERNAL_LDFLAGS) -o decompressor.elf + ld.lld optimised_bundle.o $(INTERNAL_LDFLAGS) -o decompressor.elf llvm-objcopy -O binary decompressor.elf decompressor.bin %.bc: %.c diff --git a/src/lib/builtins.asm b/src/lib/builtins.asm index 924cbe16..3f10e503 100644 --- a/src/lib/builtins.asm +++ b/src/lib/builtins.asm @@ -1,5 +1,50 @@ section .text +global __ashldi3 +__ashldi3: + push ebx + mov eax, dword [esp+8] + mov edx, dword [esp+12] + mov ecx, dword [esp+16] + + test ecx, ecx + jz .done + .next: + shl edx, 1 + shl eax, 1 + setc bl + or dl, bl + loop .next + + .done: + pop ebx + ret + +global __udivdi3 +__udivdi3: + mov eax, dword [esp+4] + mov edx, dword [esp+8] + div dword [esp+12] + xor edx, edx + ret + +global __divdi3 +__divdi3: + mov eax, dword [esp+4] + mov edx, dword [esp+8] + idiv dword [esp+12] + xor edx, edx + ret + +global __umoddi3 +__umoddi3: + mov eax, dword [esp+4] + mov edx, dword [esp+8] + div dword [esp+12] + mov eax, edx + xor edx, edx + ret + global memcpy memcpy: push esi