From a12509ef03370c3043c7bf3dc2df9a1155fd3149 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Tue, 12 Aug 2025 13:33:51 -0400 Subject: [PATCH 1/7] Fix assembly func definitions when building with `COMPARE=0` or modern gcc --- Makefile | 6 ++++++ include/sys/asm.h | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 401c3d4c..3bf7081f 100644 --- a/Makefile +++ b/Makefile @@ -62,6 +62,12 @@ ifeq ($(findstring _rom,$(TARGET)),_rom) CPPFLAGS += -D_FINALROM endif +ifeq ($(COMPARE),0) +CPPFLAGS += -D COMPARE=0 +else +CPPFLAGS += -D COMPARE=1 +endif + SRC_DIRS := $(shell find src -type d) C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s)) diff --git a/include/sys/asm.h b/include/sys/asm.h index 60e6ccd2..1b911b9d 100644 --- a/include/sys/asm.h +++ b/include/sys/asm.h @@ -34,7 +34,7 @@ extern "C" { /* libgultra doesn't match with the .type directive but iQue sdk asm.h uses it */ -#ifdef BBPLAYER +#if defined(BBPLAYER) || defined(MODERN_CC) || (COMPARE == 0) #define ASM_TYPE_FUNC(x) .type x, @function #else #define ASM_TYPE_FUNC(x) @@ -48,7 +48,7 @@ extern "C" { x: ;\ .frame sp,0,ra -#if defined(BBPLAYER) || defined(__sgi) +#if defined(BBPLAYER) || defined(__sgi) || defined(MODERN_CC) || (COMPARE == 0) #define XLEAF(x) \ .globl x ;\ .aent x,0 ;\ @@ -58,7 +58,7 @@ extern "C" { .globl x #endif -#ifdef BBPLAYER +#if defined(BBPLAYER) || defined(MODERN_CC) || (COMPARE == 0) #define END(proc) \ .end proc ;\ .size proc, . - proc @@ -75,7 +75,7 @@ extern "C" { .globl x ;\ x: -#if defined(BBPLAYER) || defined(__sgi) +#if defined(BBPLAYER) || defined(__sgi) || defined(MODERN_CC) || (COMPARE == 0) #define WEAK(x, y) \ .weakext x, y #else From ea7438f41f4b15eddd37e79169949cdb7eef206e Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Tue, 12 Aug 2025 13:55:21 -0400 Subject: [PATCH 2/7] Fix? --- Makefile | 8 ++++---- include/sys/asm.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 3bf7081f..3babc729 100644 --- a/Makefile +++ b/Makefile @@ -62,10 +62,10 @@ ifeq ($(findstring _rom,$(TARGET)),_rom) CPPFLAGS += -D_FINALROM endif -ifeq ($(COMPARE),0) -CPPFLAGS += -D COMPARE=0 -else -CPPFLAGS += -D COMPARE=1 +ifneq ($(COMPILER),ido) + ifneq ($(COMPARE),0) + CPPFLAGS += -D ASM_FIXUPS=1 + endif endif SRC_DIRS := $(shell find src -type d) diff --git a/include/sys/asm.h b/include/sys/asm.h index 1b911b9d..e0bc0231 100644 --- a/include/sys/asm.h +++ b/include/sys/asm.h @@ -34,7 +34,7 @@ extern "C" { /* libgultra doesn't match with the .type directive but iQue sdk asm.h uses it */ -#if defined(BBPLAYER) || defined(MODERN_CC) || (COMPARE == 0) +#if defined(BBPLAYER) || defined(MODERN_CC) || (defined(ASM_FIXUPS) && !defined(__sgi)) #define ASM_TYPE_FUNC(x) .type x, @function #else #define ASM_TYPE_FUNC(x) @@ -48,7 +48,7 @@ extern "C" { x: ;\ .frame sp,0,ra -#if defined(BBPLAYER) || defined(__sgi) || defined(MODERN_CC) || (COMPARE == 0) +#if defined(BBPLAYER) || defined(__sgi) || defined(MODERN_CC) || defined(ASM_FIXUPS) #define XLEAF(x) \ .globl x ;\ .aent x,0 ;\ @@ -58,7 +58,7 @@ extern "C" { .globl x #endif -#if defined(BBPLAYER) || defined(MODERN_CC) || (COMPARE == 0) +#if defined(BBPLAYER) || defined(MODERN_CC) || (defined(ASM_FIXUPS) && !defined(__sgi)) #define END(proc) \ .end proc ;\ .size proc, . - proc @@ -75,7 +75,7 @@ extern "C" { .globl x ;\ x: -#if defined(BBPLAYER) || defined(__sgi) || defined(MODERN_CC) || (COMPARE == 0) +#if defined(BBPLAYER) || defined(__sgi) || defined(MODERN_CC) || defined(ASM_FIXUPS) #define WEAK(x, y) \ .weakext x, y #else From a7c44c2fc6f46311f0cbdd9d329178f3a17f6b13 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Tue, 12 Aug 2025 13:59:22 -0400 Subject: [PATCH 3/7] I'm silly --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3babc729..8a2f092b 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ CPPFLAGS += -D_FINALROM endif ifneq ($(COMPILER),ido) - ifneq ($(COMPARE),0) + ifeq ($(COMPARE),0) CPPFLAGS += -D ASM_FIXUPS=1 endif endif From 5a02e0b21ed01382a63564ca02cf94dd1675b654 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Tue, 12 Aug 2025 14:16:23 -0400 Subject: [PATCH 4/7] Use `END` macro for remaining asm files --- src/libc/bcmp.s | 2 +- src/libc/bcopy.s | 2 +- src/libc/bzero.s | 2 +- src/mgu/mtxcatf.s | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libc/bcmp.s b/src/libc/bcmp.s index def32355..47283131 100644 --- a/src/libc/bcmp.s +++ b/src/libc/bcmp.s @@ -93,4 +93,4 @@ cmpne: li v0, 1 jr ra -.end _bcmp +END(_bcmp) diff --git a/src/libc/bcopy.s b/src/libc/bcopy.s index 08757413..efcc6c8b 100644 --- a/src/libc/bcopy.s +++ b/src/libc/bcopy.s @@ -217,4 +217,4 @@ backwards_4: addiu a2, a2, -4 b backwards_4 -.end _bcopy +END(_bcopy) diff --git a/src/libc/bzero.s b/src/libc/bzero.s index c3deec0a..3a67a2e3 100644 --- a/src/libc/bzero.s +++ b/src/libc/bzero.s @@ -69,4 +69,4 @@ bytezero: zerodone: jr ra -.end _bzero +END(_bzero) diff --git a/src/mgu/mtxcatf.s b/src/mgu/mtxcatf.s index 4b96124b..48a1c82d 100644 --- a/src/mgu/mtxcatf.s +++ b/src/mgu/mtxcatf.s @@ -98,6 +98,6 @@ label_loop_j: addu sp , FRAME_SIZE j ra - .end guMtxCatF + END(guMtxCatF) /* end of file */ From c248354614015356db15f36c1429f009f6f72380 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Wed, 13 Aug 2025 14:53:14 -0400 Subject: [PATCH 5/7] `END2` macro --- .gitignore | 3 +++ include/sys/asm.h | 12 ++++++++++++ src/libc/bcmp.s | 2 +- src/libc/bcopy.s | 2 +- src/libc/bzero.s | 2 +- src/mgu/mtxcatf.s | 2 +- 6 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 1193e995..a2e9d718 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ build/ expected/ notes/ tools/gcc +tools/egcs +tools/egcs_original tools/ido *.elf *.o @@ -25,5 +27,6 @@ tools/ido # Tool artifacts ctx.c +ctx.c.m2c libultra_collection/ diff --git a/include/sys/asm.h b/include/sys/asm.h index e0bc0231..10bf79eb 100644 --- a/include/sys/asm.h +++ b/include/sys/asm.h @@ -67,6 +67,18 @@ extern "C" { .end proc #endif +/* Some specific asm functions (guMtxCatF, _bcmp, _bcopy, _bzero) do not use a .size directive + in any known libultra version, so this macro is used to allow using said directive on those + functions without breaking matching the archives. */ +#if defined(MODERN_CC) || (defined(ASM_FIXUPS) && !defined(__sgi)) +#define END2(proc) \ + .end proc ;\ + .size proc, . - proc +#else +#define END2(proc) \ + .end proc +#endif + #define ABS(x, y) \ .globl x ;\ x = y diff --git a/src/libc/bcmp.s b/src/libc/bcmp.s index 47283131..6bee1012 100644 --- a/src/libc/bcmp.s +++ b/src/libc/bcmp.s @@ -93,4 +93,4 @@ cmpne: li v0, 1 jr ra -END(_bcmp) +END2(_bcmp) diff --git a/src/libc/bcopy.s b/src/libc/bcopy.s index efcc6c8b..7dae5cf8 100644 --- a/src/libc/bcopy.s +++ b/src/libc/bcopy.s @@ -217,4 +217,4 @@ backwards_4: addiu a2, a2, -4 b backwards_4 -END(_bcopy) +END2(_bcopy) diff --git a/src/libc/bzero.s b/src/libc/bzero.s index 3a67a2e3..91ad302a 100644 --- a/src/libc/bzero.s +++ b/src/libc/bzero.s @@ -69,4 +69,4 @@ bytezero: zerodone: jr ra -END(_bzero) +END2(_bzero) diff --git a/src/mgu/mtxcatf.s b/src/mgu/mtxcatf.s index 48a1c82d..d323987c 100644 --- a/src/mgu/mtxcatf.s +++ b/src/mgu/mtxcatf.s @@ -98,6 +98,6 @@ label_loop_j: addu sp , FRAME_SIZE j ra - END(guMtxCatF) + END2(guMtxCatF) /* end of file */ From 077463d488153d3367820826669a6287d9d7dc30 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Wed, 13 Aug 2025 15:10:31 -0400 Subject: [PATCH 6/7] fix? --- src/mgu/asm.h | 13 +++++++++++++ src/mgu/mtxcatf.s | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mgu/asm.h b/src/mgu/asm.h index 0c417fae..df4749ee 100644 --- a/src/mgu/asm.h +++ b/src/mgu/asm.h @@ -32,14 +32,27 @@ extern "C" { /* NABI32 is 64bit calling convention but 32bit type sizes) */ #define _MIPS_SIM_ABI64 3 /* MIPS 64 calling convention */ +#if defined(MODERN_CC) || (defined(ASM_FIXUPS) && !defined(__sgi)) +#define ASM_TYPE_FUNC(x) .type x, @function +#else +#define ASM_TYPE_FUNC(x) +#endif + #define LEAF(x) \ .globl x; \ + ASM_TYPE_FUNC(x) ;\ .ent x,0; \ x:; \ .frame sp,0,ra +#if defined(MODERN_CC) || (defined(ASM_FIXUPS) && !defined(__sgi)) +#define END(proc) \ + .end proc ;\ + .size proc, . - proc +#else #define END(proc) \ .end proc +#endif #ifdef __cplusplus diff --git a/src/mgu/mtxcatf.s b/src/mgu/mtxcatf.s index d323987c..48a1c82d 100644 --- a/src/mgu/mtxcatf.s +++ b/src/mgu/mtxcatf.s @@ -98,6 +98,6 @@ label_loop_j: addu sp , FRAME_SIZE j ra - END2(guMtxCatF) + END(guMtxCatF) /* end of file */ From bcafaf1cbf3d28df613eb2bef29cf517325b1b49 Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Thu, 14 Aug 2025 13:59:23 -0400 Subject: [PATCH 7/7] Set `ASM_FIXUPS` when using modern gcc instead of explicitly checking for it --- include/sys/asm.h | 10 +++++----- makefiles/modern_gcc.mk | 2 +- src/mgu/asm.h | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/sys/asm.h b/include/sys/asm.h index 10bf79eb..be0b5c3a 100644 --- a/include/sys/asm.h +++ b/include/sys/asm.h @@ -34,7 +34,7 @@ extern "C" { /* libgultra doesn't match with the .type directive but iQue sdk asm.h uses it */ -#if defined(BBPLAYER) || defined(MODERN_CC) || (defined(ASM_FIXUPS) && !defined(__sgi)) +#if defined(BBPLAYER) || (defined(ASM_FIXUPS) && !defined(__sgi)) #define ASM_TYPE_FUNC(x) .type x, @function #else #define ASM_TYPE_FUNC(x) @@ -48,7 +48,7 @@ extern "C" { x: ;\ .frame sp,0,ra -#if defined(BBPLAYER) || defined(__sgi) || defined(MODERN_CC) || defined(ASM_FIXUPS) +#if defined(BBPLAYER) || defined(__sgi) || defined(ASM_FIXUPS) #define XLEAF(x) \ .globl x ;\ .aent x,0 ;\ @@ -58,7 +58,7 @@ extern "C" { .globl x #endif -#if defined(BBPLAYER) || defined(MODERN_CC) || (defined(ASM_FIXUPS) && !defined(__sgi)) +#if defined(BBPLAYER) || (defined(ASM_FIXUPS) && !defined(__sgi)) #define END(proc) \ .end proc ;\ .size proc, . - proc @@ -70,7 +70,7 @@ extern "C" { /* Some specific asm functions (guMtxCatF, _bcmp, _bcopy, _bzero) do not use a .size directive in any known libultra version, so this macro is used to allow using said directive on those functions without breaking matching the archives. */ -#if defined(MODERN_CC) || (defined(ASM_FIXUPS) && !defined(__sgi)) +#if (defined(ASM_FIXUPS) && !defined(__sgi)) #define END2(proc) \ .end proc ;\ .size proc, . - proc @@ -87,7 +87,7 @@ extern "C" { .globl x ;\ x: -#if defined(BBPLAYER) || defined(__sgi) || defined(MODERN_CC) || defined(ASM_FIXUPS) +#if defined(BBPLAYER) || defined(__sgi) || defined(ASM_FIXUPS) #define WEAK(x, y) \ .weakext x, y #else diff --git a/makefiles/modern_gcc.mk b/makefiles/modern_gcc.mk index a914d78e..48dbfc95 100644 --- a/makefiles/modern_gcc.mk +++ b/makefiles/modern_gcc.mk @@ -9,7 +9,7 @@ WARNINGS += -Wno-int-conversion -Wno-incompatible-pointer-types -Wno-implicit-fu CFLAGS := -G 0 -c -nostdinc -march=vr4300 -mfix4300 -mabi=32 -mno-abicalls -mdivide-breaks -fno-PIC -fno-common -ffreestanding -fbuiltin -fno-builtin-sinf -fno-builtin-cosf -funsigned-char $(WARNINGS) CFLAGS += -fno-strict-aliasing # TODO: Try adjusting code to remove this ASFLAGS := -w -nostdinc -c -G 0 -march=vr4300 -mgp32 -mfp32 -DMIPSEB -D_LANGUAGE_ASSEMBLY -D_MIPS_SIM=1 -D_ULTRA64 -CPPFLAGS = -DMODERN_CC -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(GBIDEFINE) $(VERSION_DEFINE) $(DEBUGFLAG) +CPPFLAGS = -DMODERN_CC -D ASM_FIXUPS=1 -D_MIPS_SZLONG=32 -D__USE_ISOC99 $(GBIDEFINE) $(VERSION_DEFINE) $(DEBUGFLAG) IINC = -I . -I $(WORKING_DIR)/include -I $(WORKING_DIR)/include/compiler/modern_gcc -I $(WORKING_DIR)/include/PR MIPS_VERSION := -mips3 ASOPTFLAGS := diff --git a/src/mgu/asm.h b/src/mgu/asm.h index df4749ee..099fa417 100644 --- a/src/mgu/asm.h +++ b/src/mgu/asm.h @@ -32,7 +32,7 @@ extern "C" { /* NABI32 is 64bit calling convention but 32bit type sizes) */ #define _MIPS_SIM_ABI64 3 /* MIPS 64 calling convention */ -#if defined(MODERN_CC) || (defined(ASM_FIXUPS) && !defined(__sgi)) +#if (defined(ASM_FIXUPS) && !defined(__sgi)) #define ASM_TYPE_FUNC(x) .type x, @function #else #define ASM_TYPE_FUNC(x) @@ -45,7 +45,7 @@ extern "C" { x:; \ .frame sp,0,ra -#if defined(MODERN_CC) || (defined(ASM_FIXUPS) && !defined(__sgi)) +#if (defined(ASM_FIXUPS) && !defined(__sgi)) #define END(proc) \ .end proc ;\ .size proc, . - proc