1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-02-19 05:15:18 +00:00

finish up missing_gcc_functions

This commit is contained in:
fig02 2022-02-12 23:22:37 -05:00
parent fd2d669fbf
commit c9357cc005
2 changed files with 122 additions and 103 deletions

View file

@ -117,7 +117,7 @@ endif
ASFLAGS := -march=vr4300 -32 -Iinclude ASFLAGS := -march=vr4300 -32 -Iinclude
ifeq ($(COMPILER),gcc) ifeq ($(COMPILER),gcc)
CFLAGS += -G 0 -nostdinc $(INC) -D AVOID_UB -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-zero-initialized-in-bss -fno-toplevel-reorder -ffreestanding -fno-common -fno-merge-constants -mno-explicit-relocs -mno-split-addresses $(CHECK_WARNINGS) -funsigned-char CFLAGS += -G 0 -nostdinc $(INC) -DAVOID_UB -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-zero-initialized-in-bss -fno-toplevel-reorder -ffreestanding -fno-common -fno-merge-constants -mno-explicit-relocs -mno-split-addresses $(CHECK_WARNINGS) -funsigned-char
MIPS_VERSION := -mips3 MIPS_VERSION := -mips3
else else
# we support Microsoft extensions such as anonymous structs, which the compiler does support but warns for their usage. Surpress the warnings with -woff. # we support Microsoft extensions such as anonymous structs, which the compiler does support but warns for their usage. Surpress the warnings with -woff.

View file

@ -1,14 +1,19 @@
/* --------------------------------------------------------------------------------*/
/* Depending on the toolchain used, an appropriate precompiled libgcc library */
/* may not exist and cannot be linked against. Until we have a better work around, */
/* necessary gcc functions are hosted here in order to properly compile. */
/* --------------------------------------------------------------------------------*/
#ifdef __GNUC__ #ifdef __GNUC__
#include "global.h" #include "global.h"
// Define functions needed for the GCC build here.
// Self-hosted memcmp. // Self-hosted memcmp.
int memcmp(void* s1, const void* s2, size_t n) { int memcmp(void* s1, const void* s2, size_t n) {
u8* m1 = (u8*)s1; u8* m1 = (u8*)s1;
u8* m2 = (u8*)s2; u8* m2 = (u8*)s2;
u32 i; u32 i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
if (m1[i] < m2[i]) { if (m1[i] < m2[i]) {
return -1; return -1;
@ -16,15 +21,18 @@ int memcmp(void* s1, const void* s2, size_t n) {
return 1; return 1;
} }
} }
return 0; return 0;
} }
void* memset(void* str, s32 c, size_t n) { void* memset(void* str, s32 c, size_t n) {
u8* m1 = (u8*)str; u8* m1 = (u8*)str;
u32 i; u32 i;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
m1[i] = c; m1[i] = c;
} }
return str; return str;
} }
@ -34,6 +42,7 @@ u32 __fixunssfdi(f32 a) {
if (a < 0.0f) { if (a < 0.0f) {
a = 0.0f; a = 0.0f;
} }
return (u32)a; return (u32)a;
} }
@ -41,6 +50,7 @@ u32 __fixunsdfdi(f64 a) {
if (a < 0.0) { if (a < 0.0) {
a = 0.0; a = 0.0;
} }
return (u32)a; return (u32)a;
} }
@ -91,105 +101,114 @@ f32 __powisf2(f32 a, s32 b) {
return recip ? 1 / r : r; return recip ? 1 / r : r;
} }
unsigned long __umoddi3(unsigned long a, unsigned long b) { __asm__(" \n\
__asm__(".set push;" .set push \n\
".set noat;" .set noat \n\
".set noreorder;" .set noreorder \n\
".set gp=64;" .set gp=64 \n\
"sw $a0, ($sp);" \n\
"sw $a1, 4($sp);" .global __umoddi3 \n\
"sw $a2, 8($sp);" __umoddi3: \n\
"sw $a3, 0xc($sp);" .type __umoddi3, @function \n\
"ld $t7, 8($sp);" .ent __umoddi3 \n\
"ld $t6, ($sp);" sw $a0, ($sp) \n\
"ddivu $zero, $t6, $t7;" sw $a1, 4($sp) \n\
"bnez $t7, .L80324144;" sw $a2, 8($sp) \n\
" nop;" sw $a3, 0xc($sp) \n\
"break 7;" ld $t7, 8($sp) \n\
".L80324144:" ld $t6, ($sp) \n\
"mfhi $v0;" ddivu $zero, $t6, $t7 \n\
"dsll32 $v1, $v0, 0;" bnez $t7, 1f \n\
"dsra32 $v1, $v1, 0;" nop \n\
"dsra32 $v0, $v0, 0;" break 7 \n\
".set pop;"); 1: \n\
} mfhi $v0 \n\
dsll32 $v1, $v0, 0 \n\
unsigned long __udivdi3(unsigned long a, unsigned long b) { dsra32 $v1, $v1, 0 \n\
__asm__(".set push;" jr $ra \n\
".set noat;" dsra32 $v0, $v0, 0 \n\
".set noreorder;" .end __umoddi3 \n\
".set gp=64;" .size __umoddi3, . - __umoddi3 \n\
"sw $a0, ($sp);" \n\
"sw $a1, 4($sp);" .global __udivdi3 \n\
"sw $a2, 8($sp);" __udivdi3: \n\
"sw $a3, 0xc($sp);" .type __udivdi3, @function \n\
"ld $t7, 8($sp);" .ent __udivdi3 \n\
"ld $t6, ($sp);" sw $a0, ($sp) \n\
"ddivu $zero, $t6, $t7;" sw $a1, 4($sp) \n\
"bnez $t7, .L80324180;" sw $a2, 8($sp) \n\
" nop;" sw $a3, 0xc($sp) \n\
"break 7;" ld $t7, 8($sp) \n\
".L80324180:" ld $t6, ($sp) \n\
"mflo $v0;" ddivu $zero, $t6, $t7 \n\
"dsll32 $v1, $v0, 0;" bnez $t7, 1f \n\
"dsra32 $v1, $v1, 0;" nop \n\
" dsra32 $v0, $v0, 0;" break 7 \n\
".set pop;"); 1: \n\
} mflo $v0 \n\
dsll32 $v1, $v0, 0 \n\
long __moddi3(long a, long b) { dsra32 $v1, $v1, 0 \n\
__asm__(".set push;" jr $ra \n\
".set noat;" dsra32 $v0, $v0, 0 \n\
".set noreorder;" .end __udivdi3 \n\
".set gp=64;" .size __udivdi3, . - __udivdi3 \n\
"sw $a0, ($sp);" \n\
"sw $a1, 4($sp);" .global __moddi3 \n\
"sw $a2, 8($sp);" __moddi3: \n\
"sw $a3, 0xc($sp);" .type __moddi3, @function \n\
"ld $t7, 8($sp);" .ent __moddi3 \n\
"ld $t6, ($sp);" sw $a0, ($sp) \n\
"ddivu $zero, $t6, $t7;" sw $a1, 4($sp) \n\
"bnez $t7, .L803241E8;" sw $a2, 8($sp) \n\
" nop;" sw $a3, 0xc($sp) \n\
"break 7;" ld $t7, 8($sp) \n\
".L803241E8:" ld $t6, ($sp) \n\
"mfhi $v0;" ddivu $zero, $t6, $t7 \n\
"dsll32 $v1, $v0, 0;" bnez $t7, 1f \n\
"dsra32 $v1, $v1, 0;" nop \n\
" dsra32 $v0, $v0, 0;" break 7 \n\
".set pop;"); 1: \n\
} mfhi $v0 \n\
dsll32 $v1, $v0, 0 \n\
long __divdi3(long a, long b) { dsra32 $v1, $v1, 0 \n\
__asm__(".set push;" jr $ra \n\
".set noat;" dsra32 $v0, $v0, 0 \n\
".set noreorder;" .end __moddi3 \n\
".set gp=64;" .size __moddi3, . - __moddi3 \n\
"sw $a0, ($sp);" \n\
"sw $a1, 4($sp);" .global __divdi3 \n\
"sw $a2, 8($sp);" __divdi3: \n\
"sw $a3, 0xc($sp);" .type __divdi3, @function \n\
"ld $t7, 8($sp);" .ent __divdi3 \n\
"ld $t6, ($sp);" sw $a0, ($sp) \n\
"ddiv $zero, $t6, $t7;" sw $a1, 4($sp) \n\
"nop;" sw $a2, 8($sp) \n\
"bnez $t7, .L80324228;" sw $a3, 0xc($sp) \n\
" nop;" ld $t7, 8($sp) \n\
"break 7;" ld $t6, ($sp) \n\
".L80324228:" ddiv $zero, $t6, $t7 \n\
"daddiu $at, $zero, -1;" nop \n\
"bne $t7, $at, .L80324244;" bnez $t7, 1f \n\
" daddiu $at, $zero, 1;" nop \n\
"dsll32 $at, $at, 0x1f;" break 7 \n\
"bne $t6, $at, .L80324244;" 1: \n\
" nop;" daddiu $at, $zero, -1 \n\
"break 6;" bne $t7, $at, 2f \n\
".L80324244:" daddiu $at, $zero, 1 \n\
"mflo $v0;" dsll32 $at, $at, 0x1f \n\
"dsll32 $v1, $v0, 0;" bne $t6, $at, 2f \n\
"dsra32 $v1, $v1, 0;" nop \n\
" dsra32 $v0, $v0, 0;" break 6 \n\
".set pop;"); 2: \n\
} mflo $v0 \n\
dsll32 $v1, $v0, 0 \n\
dsra32 $v1, $v1, 0 \n\
jr $ra \n\
dsra32 $v0, $v0, 0 \n\
.end __divdi3 \n\
.size __divdi3, . - __divdi3 \n\
\n\
.set pop \n\
\n");
#endif #endif