Use libgcc.

This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-28 23:37:32 +02:00
parent 83ecf895d7
commit 24c89ec673
2 changed files with 4 additions and 123 deletions

View File

@ -28,123 +28,3 @@ extern "C" void __attribute__ ((weak)) __cxa_pure_virtual()
{
// This shouldn't happen. TODO: Possibly crash the kernel here.
}
#if defined(__i386__)
extern "C" uint64_t __attribute__ ((weak)) __udivdi3(uint64_t a, uint64_t b)
{
uint64_t result = 0;
uint64_t power = 1;
uint64_t remainder = a;
uint64_t divisor = b;
while ( divisor * 2 <= remainder )
{
power *= 2;
divisor *= 2;
}
while ( divisor <= remainder )
{
remainder -= divisor;
result += power;
while ( power > 1 && remainder < divisor )
{
divisor /= 2;
power /= 2;
}
}
return result;
}
extern "C" uint64_t __attribute__ ((weak)) __umoddi3(uint64_t a, uint64_t b)
{
uint64_t result = 0;
uint64_t power = 1;
uint64_t remainder = a;
uint64_t divisor = b;
while ( divisor * 2 <= remainder )
{
power *= 2;
divisor *= 2;
}
while ( divisor <= remainder )
{
remainder -= divisor;
result += power;
while ( power > 1 && remainder < divisor )
{
divisor /= 2;
power /= 2;
}
}
return remainder;
}
extern "C" int64_t __attribute__ ((weak)) __divdi3(int64_t a, int64_t b)
{
if ( a >= 0 && b >= 0 )
{
uint64_t numer = a;
uint64_t denom = b;
uint64_t result = __udivdi3(numer, denom);
return +((int64_t) result);
}
else if ( a < 0 && b >= 0 )
{
uint64_t numer = -a;
uint64_t denom = b;
uint64_t result = __udivdi3(numer, denom);
return -((int64_t) result);
}
else if ( a >= 0 && b < 0 )
{
uint64_t numer = a;
uint64_t denom = -b;
uint64_t result = __udivdi3(numer, denom);
return -((int64_t) result);
}
else // if ( a < 0 && b < 0 )
{
uint64_t numer = -a;
uint64_t denom = -b;
uint64_t result = __udivdi3(numer, denom);
return +((int64_t) result);
}
}
extern "C" int64_t __attribute__ ((weak)) __moddi3(int64_t a, int64_t b)
{
if ( a >= 0 && b >= 0 )
{
uint64_t numer = a;
uint64_t denom = b;
uint64_t result = __umoddi3(numer, denom);
return +((int64_t) result);
}
else if ( a < 0 && b >= 0 )
{
uint64_t numer = -a;
uint64_t denom = b;
uint64_t result = __umoddi3(numer, denom);
return -((int64_t) result);
}
else if ( a >= 0 && b < 0 )
{
uint64_t numer = a;
uint64_t denom = -b;
uint64_t result = __umoddi3(numer, denom);
return +((int64_t) result);
}
else // if ( a < 0 && b < 0 )
{
uint64_t numer = -a;
uint64_t denom = -b;
uint64_t result = __umoddi3(numer, denom);
return -((int64_t) result);
}
}
#endif

View File

@ -19,7 +19,7 @@ ifeq ($(CPU),x64)
BUILDID=x64
X86FAMILY=1
CPUFLAGS=-ffreestanding -mno-red-zone
CPULDFLAGS=-z max-page-size=0x1000
CPULDFLAGS=
CPUNASMFLAGS=-felf64
CPUOBJS:=$(CPU)/base.o $(CPU)/x64.o
endif
@ -79,6 +79,7 @@ NASMFLAGS=$(CPUNASMFLAGS)
STATICLIBS=\
-lc-sortix \
-lgcc \
HEADERDIRS:=$(shell find include -type d)
HEADERS:=$(shell find include -type f)
@ -156,13 +157,13 @@ x64/boot.o: x64/boot.s
$(HOSTAS) -64 $< -o $@
sortix-x64.tmp: $(ALLOBJS) x64/boot.o
$(HOSTLD) -N -melf_x86_64_sortix -Ttext 100000 -o sortix-x64-internal.out x64/boot.o $(OBJS) $(STATICLIBS) end.o
$(HOSTCXX) -nodefaultlibs -nostartfiles -Wl,-N -Wl,-melf_x86_64_sortix -Wl,-Ttext -Wl,100000 -Wl,-z -Wl,max-page-size=0x1000 -o sortix-x64-internal.out x64/boot.o $(OBJS) $(STATICLIBS) end.o
$(HOSTOBJCOPY) sortix-x64-internal.out -O elf32-i386 sortix-x64.tmp
# x86 compilation
sortix-x86.tmp: $(ALLOBJS)
$(HOSTLD) -melf_i386_sortix -Ttext 100000 -o $@ $(OBJS) $(STATICLIBS) end.o
$(HOSTCXX) -nodefaultlibs -nostartfiles -Wl,-melf_i386_sortix -Wl,-Ttext -Wl,100000 -o $@ $(OBJS) $(STATICLIBS) end.o
# general rules