Add libdragon ipl3 as makefile option

This commit is contained in:
a
2025-06-22 22:01:46 -04:00
parent b8ca566e42
commit 8d971cd81d
6 changed files with 28 additions and 35 deletions

View File

@@ -5,9 +5,19 @@ include util.mk
# Default target # Default target
default: all default: all
# Use Libdragon IPL3
# WARNING: This CAN and WILL break certain (most) emulators.
# Use if you care about console or ares boot times.
LIBDRAGON_IPL3 := 0
# Preprocessor definitions # Preprocessor definitions
DEFINES := DEFINES :=
ifeq ($(LIBDRAGON_IPL3), 1)
DEFINES += LIBDRAGON_IPL3=1
endif
#==============================================================================# #==============================================================================#
# Build Options # # Build Options #
#==============================================================================# #==============================================================================#
@@ -111,7 +121,7 @@ ifeq ($(filter $(TARGET_STRING), sm64.jp.f3d_old sm64.us.f3d_old sm64.eu.f3d_new
endif endif
# Whether to hide commands or not # Whether to hide commands or not
VERBOSE ?= 1 VERBOSE ?= 0
ifeq ($(VERBOSE),0) ifeq ($(VERBOSE),0)
V := @ V := @
endif endif
@@ -125,15 +135,10 @@ ifeq ($(filter clean distclean,$(MAKECMDGOALS)),)
$(info Version: $(VERSION)) $(info Version: $(VERSION))
$(info Microcode: $(GRUCODE)) $(info Microcode: $(GRUCODE))
$(info Target: $(TARGET)) $(info Target: $(TARGET))
ifeq ($(COMPARE),1) ifeq ($(LIBDRAGON_IPL3),1)
$(info Compare ROM: yes) $(info IPL: Libdragon IPL3 Compat)
else else
$(info Compare ROM: no) $(info IPL: Nintendo IPL3)
endif
ifeq ($(NON_MATCHING),1)
$(info Build Matching: no)
else
$(info Build Matching: yes)
endif endif
$(info =======================) $(info =======================)
endif endif
@@ -657,8 +662,12 @@ $(ELF): $(LIBULTRA_BUILD_DIR)/libgultra_rom.a $(O_FILES) $(MIO0_OBJ_FILES) $(SEG
$(ROM): $(ELF) $(ROM): $(ELF)
$(call print,Building ROM:,$<,$@) $(call print,Building ROM:,$<,$@)
ifeq ($(LIBDRAGON_IPL3), 0)
$(V)$(OBJCOPY) $(PAD_TO_GAP_FILL) $< $(@:.z64=.bin) -O binary $(V)$(OBJCOPY) $(PAD_TO_GAP_FILL) $< $(@:.z64=.bin) -O binary
$(V)$(N64CKSUM) $(@:.z64=.bin) $@ $(V)$(N64CKSUM) $(@:.z64=.bin) $@
else
$(V)$(OBJCOPY) $(PAD_TO_GAP_FILL) $< $@ -O binary
endif
$(BUILD_DIR)/$(TARGET).objdump: $(ELF) $(BUILD_DIR)/$(TARGET).objdump: $(ELF)
$(OBJDUMP) -D $< > $@ $(OBJDUMP) -D $< > $@

View File

@@ -4,7 +4,6 @@
#include "macros.inc" #include "macros.inc"
#include <PR/rcp.h> #include <PR/rcp.h>
#define PHYS_TO_CART(addr) ((addr) | 0xB0000000) #define PHYS_TO_CART(addr) ((addr) | 0xB0000000)
.equ CART_ENTRYPOINT, 0x00000008 .equ CART_ENTRYPOINT, 0x00000008
.equ CART_CHECKSUM0, 0x00000010 .equ CART_CHECKSUM0, 0x00000010
@@ -38,7 +37,7 @@
// 0xA4000000-0xA4000FFF: RSP DMEM // 0xA4000000-0xA4000FFF: RSP DMEM
.section .text, "ax" .section .text, "ax"
#ifndef LIBDRAGON_IPL3
// 0xA4000040-0xA4000B6F: IPL3 // 0xA4000040-0xA4000B6F: IPL3
// IPL3 entry point jumped to from IPL2 // IPL3 entry point jumped to from IPL2
@@ -1158,3 +1157,7 @@ func_A4000AD0:
#endif #endif
.end ipl3_entry .end ipl3_entry
#else
.section .text, "ax"
.incbin "asm/libdragon_ipl3.bin"
#endif

View File

@@ -7,28 +7,7 @@
.section .text, "ax" .section .text, "ax"
glabel entry_point glabel entry_point
#ifdef VERSION_CN #ifndef LIBDRAGON_IPL3
// Get main segment bss address and size
lui $t0, %lo(_mainSegmentNoloadStartHi)
ori $t0, %lo(_mainSegmentNoloadStartLo)
lui $t1, %lo(_mainSegmentNoloadSizeHi)
ori $t1, %lo(_mainSegmentNoloadSizeLo)
.clear_bytes:
// Clear bss section until they are zeroed out
sw $zero, ($t0) // Clear 4 bytes
sw $zero, 4($t0) // Clear the next 4 bytes
addi $t0, $t0, 8 // Increment the address of bytes to clear
addi $t1, $t1, -8 // Subtract 8 bytes from the amount remaining
bnez $t1, .clear_bytes // Continue clearing until clear_bytes is 0
nop
// Get init function and idle thread stack
lui $sp, %lo(gIdleThreadStackHi)
ori $sp, %lo(gIdleThreadStackLo)
lui $t2, %lo(main_funcHi)
ori $t2, %lo(main_funcLo)
jr $t2 // Jump to the init function
nop
#else
// Get main segment bss address and size // Get main segment bss address and size
lui $t0, %hi(_mainSegmentNoloadStart) lui $t0, %hi(_mainSegmentNoloadStart)
lui $t1, %lo(_mainSegmentNoloadSizeHi) lui $t1, %lo(_mainSegmentNoloadSizeHi)
@@ -41,13 +20,13 @@ glabel entry_point
sw $zero, 4($t0) // Clear the next 4 bytes sw $zero, 4($t0) // Clear the next 4 bytes
bnez $t1, .clear_bytes // Continue clearing until clear_bytes is 0 bnez $t1, .clear_bytes // Continue clearing until clear_bytes is 0
addi $t0, $t0, 8 // Increment the address of bytes to clear addi $t0, $t0, 8 // Increment the address of bytes to clear
#endif
// Get init function and idle thread stack // Get init function and idle thread stack
lui $t2, %hi(main_func) lui $t2, %hi(main_func)
lui $sp, %hi(gIdleThreadStack) lui $sp, %hi(gIdleThreadStack)
addiu $t2, %lo(main_func) addiu $t2, %lo(main_func)
jr $t2 // Jump to the init function jr $t2 // Jump to the init function
addiu $sp, %lo(gIdleThreadStack) addiu $sp, %lo(gIdleThreadStack)
#endif
nop nop
nop nop
nop nop

BIN
asm/libdragon_ipl3.bin Normal file

Binary file not shown.

View File

@@ -16,7 +16,7 @@
.fill 0x30 .fill 0x30
#else #else
.word 0x4EAA3D0E /* Checksum 1 */ .word _mainSegmentRomEnd /* Checksum 1 / Libdragon IPL3 load end */
.word 0x74757C24 /* Checksum 2 */ .word 0x74757C24 /* Checksum 2 */
.word 0x00000000 /* Unknown */ .word 0x00000000 /* Unknown */
.word 0x00000000 /* Unknown */ .word 0x00000000 /* Unknown */

View File

@@ -17,7 +17,9 @@ SECTIONS
{ {
BUILD_DIR/asm/rom_header.o(.text); BUILD_DIR/asm/rom_header.o(.text);
BUILD_DIR/asm/boot.o(.text); BUILD_DIR/asm/boot.o(.text);
#ifndef LIBDRAGON_IPL3
BUILD_DIR/asm/ipl3_font.o(.text); BUILD_DIR/asm/ipl3_font.o(.text);
#endif
} }
END_SEG(boot) END_SEG(boot)