Skip to content

Commit 4c88cfd

Browse files
authored
[iQue] Match makerom (#2397)
1 parent 9dafc2f commit 4c88cfd

File tree

4 files changed

+70
-14
lines changed

4 files changed

+70
-14
lines changed

Makefile

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ ifeq ($(ORIG_COMPILER),1)
281281
CCAS := $(CC)
282282
endif
283283

284+
# EGCS Compiler
284285
EGCS_PREFIX := tools/egcs/$(DETECTED_OS)/
285286
EGCS_CC := $(EGCS_PREFIX)gcc -B $(EGCS_PREFIX)
287+
EGCS_CCAS := $(EGCS_CC) -x assembler-with-cpp
286288

287289
AS := $(MIPS_BINUTILS_PREFIX)as
288290
LD := $(MIPS_BINUTILS_PREFIX)ld
@@ -368,6 +370,9 @@ else
368370
CCASFLAGS += $(CPP_DEFINES) $(GBI_DEFINES) -G 0 -non_shared -fullwarn -verbose -Xcpluscomm $(INC) -Wab,-r4300_mul -woff 516,609,649,838,712,807 -o32
369371
EGCS_CFLAGS += $(CPP_DEFINES) $(GBI_DEFINES) -G 0 -nostdinc $(INC) -mcpu=vr4300 -mabi=32 -mgp32 -mfp32 -fno-PIC
370372
MIPS_VERSION := -mips2
373+
374+
EGCS_CCASFLAGS := -Wall -nostdinc $(CPP_DEFINES) $(INC) -c -G 0 -Wa,-irix-symtab -D_ABIO32=1 -D_ABI64=3 -D_MIPS_SIM_ABI64=_ABI64 -D_MIPS_SIM_ABI32=_ABIO32 -DMIPSEB -D_LANGUAGE_ASSEMBLY -fno-PIC -non_shared -mcpu=4300 -mfix4300
375+
EGCS_ASOPTFLAGS :=
371376
endif
372377

373378
ifeq ($(COMPILER),ido)
@@ -516,7 +521,8 @@ TEXTURE_FILES_OUT := $(foreach f,$(TEXTURE_FILES_PNG_EXTRACTED:.png=.inc.c),$(f:
516521

517522
# create build directories
518523
$(shell mkdir -p $(BUILD_DIR)/baserom \
519-
$(BUILD_DIR)/assets/text)
524+
$(BUILD_DIR)/assets/text \
525+
$(BUILD_DIR)/linker_scripts)
520526
$(shell mkdir -p $(foreach dir, \
521527
$(SRC_DIRS) \
522528
$(UNDECOMPILED_DATA_DIRS) \
@@ -681,6 +687,14 @@ endif
681687

682688
$(BUILD_DIR)/assets/misc/z_select_static/%.o: GBI_DEFINES := -DF3DEX_GBI
683689

690+
ifeq ($(PLATFORM),IQUE)
691+
692+
$(BUILD_DIR)/src/makerom/%.o: CCAS := $(EGCS_CCAS)
693+
$(BUILD_DIR)/src/makerom/%.o: CCASFLAGS := $(EGCS_CCASFLAGS)
694+
$(BUILD_DIR)/src/makerom/%.o: ASOPTFLAGS := $(EGCS_ASOPTFLAGS)
695+
696+
endif
697+
684698
# For using asm_processor on some files:
685699
#$(BUILD_DIR)/.../%.o: CC := $(PYTHON) tools/asm_processor/build.py $(CC) -- $(AS) $(ASFLAGS) --
686700

@@ -784,10 +798,13 @@ $(ROMC): $(ROM) $(ELF) $(BUILD_DIR)/compress_ranges.txt
784798
$(PYTHON) tools/compress.py --in $(ROM) --out $@ --dmadata-start `./tools/dmadata_start.sh $(NM) $(ELF)` --compress `cat $(BUILD_DIR)/compress_ranges.txt` --threads $(N_THREADS) $(COMPRESS_ARGS)
785799
$(PYTHON) -m ipl3checksum sum --cic $(CIC) --update $@
786800

787-
$(ELF): $(TEXTURE_FILES_OUT) $(ASSET_FILES_OUT) $(O_FILES) $(OVL_RELOC_FILES) $(LDSCRIPT) $(BUILD_DIR)/undefined_syms.txt \
801+
$(ELF): $(TEXTURE_FILES_OUT) $(ASSET_FILES_OUT) $(O_FILES) $(OVL_RELOC_FILES) $(LDSCRIPT) $(BUILD_DIR)/linker_scripts/makerom.ld $(BUILD_DIR)/undefined_syms.txt \
788802
$(SAMPLEBANK_O_FILES) $(SOUNDFONT_O_FILES) $(SEQUENCE_O_FILES) \
789803
$(BUILD_DIR)/assets/audio/sequence_font_table.o $(BUILD_DIR)/assets/audio/audiobank_padding.o
790-
$(LD) -T $(LDSCRIPT) -T $(BUILD_DIR)/undefined_syms.txt --no-check-sections --accept-unknown-input-arch --emit-relocs -Map $(MAP) -o $@
804+
$(LD) -T $(LDSCRIPT) -T $(BUILD_DIR)/linker_scripts/makerom.ld -T $(BUILD_DIR)/undefined_syms.txt --no-check-sections --accept-unknown-input-arch --emit-relocs -Map $(MAP) -o $@
805+
806+
$(BUILD_DIR)/linker_scripts/makerom.ld: linker_scripts/makerom.ld
807+
$(CPP) -I include $(CPPFLAGS) $< > $@
791808

792809
## Order-only prerequisites
793810
# These ensure e.g. the O_FILES are built before the OVL_RELOC_FILES.

linker_scripts/makerom.ld

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "boot.h"
2+
3+
/* These are only here due to iQue entry.s using ori to load the lower halves of symbols
4+
* rather than addiu, so the usual relocation operators %hi() and %lo() can't be used. */
5+
6+
_bootSegmentBssStart_HI = _bootSegmentBssStart >> 16;
7+
8+
_bootSegmentBssSize_HI = _bootSegmentBssSize >> 16;
9+
10+
bootproc_HI = bootproc >> 16;
11+
12+
BOOT_STACK_TOP = (sBootThreadStack + BOOT_STACK_SIZE);
13+
BOOT_STACK_TOP_HI = BOOT_STACK_TOP >> 16;

src/makerom/entry.s

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,38 @@
44

55
.text
66

7-
#if defined(__sgi) && !defined(AVOID_UB)
8-
/* IDO assembler workaround: The makerom tool in the N64 SDK was given the bss segment size as a const
7+
#if defined(NON_MATCHING) || defined(__sgi)
8+
/* Non-matching builds or IDO */
9+
#define PAD_TO 0x60
10+
#define LA(reg, sym) la reg, sym
11+
#define BOOT_STACK_TOP sBootThreadStack + BOOT_STACK_SIZE
12+
#else
13+
/* EGCS */
14+
#define PAD_TO 0x50
15+
#define LA(reg, sym) \
16+
lui reg, %lo(sym##_HI); \
17+
ori reg, %lo(sym)
18+
#endif
19+
20+
#if !defined(AVOID_UB)
21+
/* Old assembler workarounds: The makerom tool in the N64 SDK was given the bss segment size as a const
922
* literal, and since this literal was < 0x10000 it was loaded in one instruction. We don't have access
1023
* to the bss segment size until we link everything so we cannot do the same thing. Instead we must load
1124
* only the lower 16 bits of the bss size for matching.
1225
* When AVOID_UB is enabled, don't do this and instead load the full symbol value, otherwise not all of
1326
* bss may be cleared. */
27+
#if defined(__sgi)
1428
#define LOAD_BSS_SIZE(reg) li reg, %half(_bootSegmentBssSize)
1529
#else
16-
#define LOAD_BSS_SIZE(reg) la reg, _bootSegmentBssSize
30+
#define LOAD_BSS_SIZE(reg) ori reg, zero, %lo(_bootSegmentBssSize)
31+
#endif
32+
#else
33+
#define LOAD_BSS_SIZE(reg) LA(reg, _bootSegmentBssSize)
1734
#endif
1835

1936
LEAF(entrypoint)
2037
/* Clear boot segment .bss */
21-
la t0, _bootSegmentBssStart
38+
LA( t0, _bootSegmentBssStart)
2239
LOAD_BSS_SIZE(t1)
2340
.clear_bss:
2441
sw zero, 0(t0)
@@ -28,17 +45,17 @@ LEAF(entrypoint)
2845
bnez t1, .clear_bss
2946

3047
/* Set up stack and enter program code */
31-
la sp, sBootThreadStack + BOOT_STACK_SIZE
32-
la t2, bootproc
48+
LA( sp, BOOT_STACK_TOP)
49+
LA( t2, bootproc)
3350
jr t2
3451
END(entrypoint)
3552

36-
#ifdef __GNUC__
37-
/* Pad to a total size of 0x60 */
38-
.fill 0x60 - (. - entrypoint)
39-
#else
40-
/* IDO can't take absolute differences of symbols.. */
53+
#ifdef __sgi
54+
/* IDO can't take absolute differences of symbols so the size of the above is hardcoded */
4155
.repeat (0x60 - 0x34)
4256
.byte 0
4357
.endr
58+
#else
59+
/* Pad to a total size taking into account the size of the above */
60+
.fill PAD_TO - (. - entrypoint)
4461
#endif

src/makerom/rom_header.s

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
/* 0x08 */ ENTRYPOINT(0x80000400)
1010
/* 0x0C */ OS_VERSION(2, 0, LIBULTRA_VERSION)
1111
/* 0x10 */ CHECKSUM()
12+
13+
#if !PLATFORM_IQUE
14+
1215
/* 0x18 */ PADDING(8)
1316
/* 0x20 */ ROM_NAME("THE LEGEND OF ZELDA")
1417
/* 0x34 */ PADDING(7)
@@ -26,3 +29,9 @@
2629
/* 0x3E */ REGION(PAL)
2730
#endif
2831
/* 0x3F */ GAME_REVISION(OOT_REVISION)
32+
33+
#else
34+
35+
.fill 0x40 - 0x18
36+
37+
#endif

0 commit comments

Comments
 (0)