Implement support functions ourselves instead of relying on libgcc

This commit is contained in:
mintsuki 2020-09-09 16:04:06 +02:00
parent c53122516a
commit ef6ef5865b
3 changed files with 47 additions and 6 deletions

View File

@ -32,16 +32,12 @@ limine.bin: libgcc.a $(BC) $(ASM_OBJ)
llvm-link $(BC) -o bundle.bc llvm-link $(BC) -o bundle.bc
opt --O$(OPT_LEVEL) bundle.bc -o optimised_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 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 llvm-objcopy -O binary stage2.elf stage2.bin
gzip -9 stage2.bin gzip -9 stage2.bin
$(MAKE) -C decompressor $(MAKE) -C decompressor
cd bootsect && nasm bootsect.asm -fbin -o ../limine.bin 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 %.bc: %.c
clang --target=i386-elf $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@ clang --target=i386-elf $(CFLAGS) $(INTERNAL_CFLAGS) -c $< -o $@

View File

@ -30,7 +30,7 @@ decompressor.bin: $(BC)
llvm-link $(BC) -o bundle.bc llvm-link $(BC) -o bundle.bc
opt --O$(OPT_LEVEL) bundle.bc -o optimised_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 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 llvm-objcopy -O binary decompressor.elf decompressor.bin
%.bc: %.c %.bc: %.c

View File

@ -1,5 +1,50 @@
section .text 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 global memcpy
memcpy: memcpy:
push esi push esi