From 497ee84c25540b47216a91dd55fe039af80f030f Mon Sep 17 00:00:00 2001 From: AZero13 <83477269+SiliconA-Z@users.noreply.github.com> Date: Sat, 4 Apr 2026 23:47:36 -0400 Subject: [PATCH 1/2] Make codebase more friendly to modern ARM compilers LLVM whines over dumb things like no # before constants in asm and OAM_BUFFER because of the fastcopy thing. --- include/gba/types.h | 3 ++- include/global.h | 9 +++++---- src/multiboot.c | 14 +++++++------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/include/gba/types.h b/include/gba/types.h index 2e92bbe86e56..1308846a99e5 100644 --- a/include/gba/types.h +++ b/include/gba/types.h @@ -2,6 +2,7 @@ #define GUARD_GBA_TYPES_H #include +#include "gba/defines.h" typedef uint8_t u8; typedef uint16_t u16; @@ -69,7 +70,7 @@ struct OamData u16 priority:2; // 0x400, 0x800 -> 0xC00 u16 paletteNum:4; /*0x06*/ u16 affineParam; -}; +} ALIGNED(4); // Modern compilers will use wrong align-of sometimes. #define ST_OAM_HFLIP 0x08 #define ST_OAM_VFLIP 0x10 diff --git a/include/global.h b/include/global.h index bdfc426fb93c..93b13872aac6 100644 --- a/include/global.h +++ b/include/global.h @@ -17,11 +17,12 @@ #include "constants/easy_chat.h" #include "constants/trainer_hill.h" -// Prevent cross-jump optimization. -#define BLOCK_CROSS_JUMP asm(""); - -// to help in decompiling +// Unified Thumb/ARM asm. Modern (Clang): no .syntax divided — Clang rejects it. Legacy agbcc output still expects divided after the block. +#if MODERN +#define asm_unified(x) asm(".syntax unified\n" x) +#else #define asm_unified(x) asm(".syntax unified\n" x "\n.syntax divided") +#endif #define NAKED __attribute__((naked)) #if MODERN diff --git a/src/multiboot.c b/src/multiboot.c index 15b062ed65ee..f452616521d6 100644 --- a/src/multiboot.c +++ b/src/multiboot.c @@ -441,16 +441,16 @@ static void MultiBootWaitCycles(u32 cycles) { asm_unified("\ mov r2, pc\n\ - lsrs r2, 24\n\ - movs r1, 12\n\ - cmp r2, 2\n\ + lsrs r2, r2, #24\n\ + movs r1, #12\n\ + cmp r2, #2\n\ beq MultiBootWaitCyclesLoop\n\ - movs r1, 13\n\ - cmp r2, 8\n\ + movs r1, #13\n\ + cmp r2, #8\n\ beq MultiBootWaitCyclesLoop\n\ - movs r1, 4\n\ + movs r1, #4\n\ MultiBootWaitCyclesLoop:\n\ - subs r0, r1\n\ + subs r0, r0, r1\n\ bgt MultiBootWaitCyclesLoop\n\ bx lr\n"); } From 22b7864531442e29ba0e096a97fafb51843b0e1b Mon Sep 17 00:00:00 2001 From: AZero13 <83477269+SiliconA-Z@users.noreply.github.com> Date: Mon, 23 Mar 2026 13:44:44 -0400 Subject: [PATCH 2/2] makefile: For modern, use -fno-strict-aliasing So much type-punning causes things to not work on modern compilers. Additionally, -fno-toplevel-reorder is only needed for files with COMMON, as otherwise gcc will break this, so only have them for the two files that need it. Resulting rom tested on real hardware and mGBA. --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 754ecebe360c..0ae0ccd325de 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,7 @@ else MODERNCC := $(PREFIX)gcc PATH_MODERNCC := PATH="$(PATH)" $(MODERNCC) CC1 := $(shell $(PATH_MODERNCC) --print-prog-name=cc1) -quiet - override CFLAGS += -mthumb -mthumb-interwork -O$(O_LEVEL) -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast + override CFLAGS += -mthumb -mthumb-interwork -O$(O_LEVEL) -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-strict-aliasing -Wno-pointer-to-int-cast LIBPATH := -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libnosys.a))" -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libc.a))" LIB := $(LIBPATH) -lc -lnosys -lgcc -L../../libagbsyscall -lagbsyscall endif @@ -293,7 +293,9 @@ $(C_BUILDDIR)/record_mixing.o: CFLAGS += -ffreestanding $(C_BUILDDIR)/librfu_intr.o: CC1 := $(TOOLS_DIR)/agbcc/bin/agbcc_arm$(EXE) $(C_BUILDDIR)/librfu_intr.o: CFLAGS := -O2 -mthumb-interwork -quiet else -$(C_BUILDDIR)/librfu_intr.o: CFLAGS := -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast +$(C_BUILDDIR)/m4a.o: CFLAGS += -fno-toplevel-reorder +$(C_BUILDDIR)/librfu_intr.o: CFLAGS := -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -fno-strict-aliasing -Wno-pointer-to-int-cast +$(C_BUILDDIR)/agb_flash.o: CFLAGS += -fno-toplevel-reorder $(C_BUILDDIR)/berry_crush.o: override CFLAGS += -Wno-address-of-packed-member endif