fix libgcc and add include dir

This commit is contained in:
a
2025-06-23 21:34:42 -04:00
parent 7d63a123d8
commit d71d700d1e
3 changed files with 87 additions and 5 deletions

View File

@@ -284,7 +284,7 @@ ifeq ($(TARGET_N64),1)
CC_CFLAGS := -fno-builtin
endif
INCLUDE_DIRS := include $(BUILD_DIR) $(BUILD_DIR)/include src .
INCLUDE_DIRS := include $(BUILD_DIR) $(BUILD_DIR)/include src lib/n64-libc .
ifeq ($(TARGET_N64),1)
INCLUDE_DIRS += include/gcc
endif

View File

@@ -52,7 +52,7 @@ SECTIONS
AUDIO_DIR*.o(.text);
ULTRA_BUILD_DIR/libgultra_rom.a:*.o(.text);
BUILD_DIR/src/audio/external.o(.text);
BUILD_DIR/n64-libc.a*:.o(.text);
BUILD_DIR/n64-libc.a:*.o(.text);
BUILD_DIR/lib/rsp.o(.text);
BUILD_DIR/asm/entry.o(.data*);
@@ -62,7 +62,7 @@ SECTIONS
AUDIO_DIR*.o(.data*);
ULTRA_BUILD_DIR/libgultra_rom.a:*.o(.data*);
BUILD_DIR/src/audio/external.o(.data*);
BUILD_DIR/n64-libc.a*:.o(.data*);
BUILD_DIR/n64-libc.a:*.o(.data*);
BUILD_DIR/lib/rsp.o(.data*);
BUILD_DIR/asm/entry.o(.rodata*);
@@ -72,7 +72,7 @@ SECTIONS
AUDIO_DIR*.o(.rodata*);
ULTRA_BUILD_DIR/libgultra_rom.a:*.o(.rodata*);
BUILD_DIR/src/audio/external.o(.rodata*);
BUILD_DIR/n64-libc.a*:.o(.rodata*);
BUILD_DIR/n64-libc.a:*.o(.rodata*);
BUILD_DIR/lib/rsp.o(.rodata*);
#ifdef LIBDRAGON_IPL3
BUILD_DIR/src/game*.o(.text);
@@ -96,7 +96,7 @@ SECTIONS
AUDIO_DIR/data.o(.bss*);
AUDIO_DIR*.o(.bss*);
BUILD_DIR/src/audio/external.o(.bss*);
BUILD_DIR/n64-libc.a*:.o(.bss*);
BUILD_DIR/n64-libc.a:*.o(.bss*);
ULTRA_BUILD_DIR/libgultra_rom.a:*.o(.bss*);
BUILD_DIR/src/game*.o(.bss*);
. = ALIGN(0x10);

View File

@@ -5,6 +5,8 @@
/* This file is NOT a part of the original game and only exists to help gcc work. */
/* --------------------------------------------------------------------------------*/
// Frankenstein monster because GCC wants to ruin our lives.
#include <ultra64.h>
// Self-hosted libc memory functions, gcc assumes these exist even in a freestanding
@@ -212,6 +214,86 @@ s64 __lshrdi3(s64 a, s32 b) {
return result.all;
}
#define arith64_u64 unsigned long long int
#define arith64_s64 signed long long int
#define arith64_u32 unsigned int
#define arith64_s32 int
typedef union
{
arith64_u64 u64;
arith64_s64 s64;
struct
{
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
arith64_u32 hi; arith64_u32 lo;
#else
arith64_u32 lo; arith64_u32 hi;
#endif
} u32;
struct
{
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
arith64_s32 hi; arith64_s32 lo;
#else
arith64_s32 lo; arith64_s32 hi;
#endif
} s32;
} arith64_word;
// extract hi and lo 32-bit words from 64-bit value
#define arith64_hi(n) (arith64_word){.u64=n}.u32.hi
#define arith64_lo(n) (arith64_word){.u64=n}.u32.lo
// Negate a if b is negative, via invert and increment.
#define arith64_neg(a, b) (((a) ^ ((((arith64_s64)(b)) >= 0) - 1)) + (((arith64_s64)(b)) < 0))
#define arith64_abs(a) arith64_neg(a, a)
// Return the absolute value of a.
// Note LLINT_MIN cannot be negated.
arith64_s64 __absvdi2(arith64_s64 a)
{
return arith64_abs(a);
}
// Return the result of shifting a left by b bits.
arith64_s64 __ashldi3(arith64_s64 a, int b)
{
arith64_word w = {.s64 = a};
b &= 63;
if (b >= 32)
{
w.u32.hi = w.u32.lo << (b - 32);
w.u32.lo = 0;
} else if (b)
{
w.u32.hi = (w.u32.lo >> (32 - b)) | (w.u32.hi << b);
w.u32.lo <<= b;
}
return w.s64;
}
// Return the result of arithmetically shifting a right by b bits.
arith64_s64 __ashrdi3(arith64_s64 a, int b)
{
arith64_word w = {.s64 = a};
b &= 63;
if (b >= 32)
{
w.s32.lo = w.s32.hi >> (b - 32);
w.s32.hi >>= 31; // 0xFFFFFFFF or 0
} else if (b)
{
w.u32.lo = (w.u32.hi << (32 - b)) | (w.u32.lo >> b);
w.s32.hi >>= b;
}
return w.s64;
}
// Compute division and modulo of 64-bit signed and unsigned integers
__asm__(" \n\