From f1f63b73d42e9cfb3b47bf1c219e6d0387d28431 Mon Sep 17 00:00:00 2001 From: patataofcourse Date: Sat, 13 Aug 2022 16:58:38 +0200 Subject: [PATCH] manage TCM, bss and overlays should work fine now --- arm9/Makefile | 14 ++++++-- arm9/arm9.ld | 81 ++++++++++++++++++++++++++++++++------------ arm9/data/autoload.s | 10 +++++- arm9/data/dtcm.s | 9 +++++ arm9/data/itcm.s | 4 +++ arm9/data/sbss.s | 3 -- 6 files changed, 93 insertions(+), 28 deletions(-) create mode 100644 arm9/data/dtcm.s create mode 100644 arm9/data/itcm.s delete mode 100644 arm9/data/sbss.s diff --git a/arm9/Makefile b/arm9/Makefile index 5649c8d..99e71d8 100644 --- a/arm9/Makefile +++ b/arm9/Makefile @@ -18,6 +18,7 @@ CFILES := $(foreach dir,$(SOURCE),$(wildcard $(dir)/*.c)) CPPFILES := $(foreach dir,$(SOURCE),$(wildcard $(dir)/*.cpp)) ASMFILES := $(foreach dir,$(ASM),$(wildcard $(dir)/*.s)) DATAFILES := $(foreach dir,$(DATA),$(wildcard $(dir)/*.s)) +LINKSCRIPT := arm9.ld OFILES := $(addprefix $(BUILD)/,$(ASMFILES:.s=.o)) $(addprefix $(BUILD)/,$(CFILES:.c=.o)) OFILES += $(addprefix $(BUILD)/,$(CPPFILES:.cpp=.o)) $(addprefix $(BUILD)/,$(DATAFILES:.s=.o)) @@ -26,9 +27,16 @@ OFILES += $(addprefix $(BUILD)/,$(CPPFILES:.cpp=.o)) $(addprefix $(BUILD)/,$(D all: $(BUILD)/arm9.bin -$(BUILD)/arm9.bin: $(OFILES) - @$(LD) $(LD_FLAGS) $< -T arm9.ld -T undefined.ld -o $(BUILD)/arm9.elf - @$(OBJCOPY) -O binary $(BUILD)/arm9.elf $(BUILD)/arm9.bin +$(BUILD)/arm9.bin: $(OFILES) | $(LINKSCRIPT) + @$(LD) $(LD_FLAGS) $< -T $(LINKSCRIPT) -T undefined.ld -o $(BUILD)/arm9.elf + @$(OBJCOPY) -O binary $(BUILD)/arm9.elf -j .arm9 $(BUILD)/arm9.main.bin + @$(OBJCOPY) -O binary $(BUILD)/arm9.elf -j .itcm $(BUILD)/arm9.itcm.bin + @$(OBJCOPY) -O binary $(BUILD)/arm9.elf -j .dtcm $(BUILD)/arm9.dtcm.bin + @$(OBJCOPY) -O binary $(BUILD)/arm9.elf -j .autoload_list $(BUILD)/arm9.auto.bin + @cat $(BUILD)/arm9.main.bin > $(BUILD)/arm9.bin + @cat $(BUILD)/arm9.itcm.bin >> $(BUILD)/arm9.bin + @cat $(BUILD)/arm9.dtcm.bin >> $(BUILD)/arm9.bin + @cat $(BUILD)/arm9.auto.bin >> $(BUILD)/arm9.bin clean: @rm -rf $(BUILD) diff --git a/arm9/arm9.ld b/arm9/arm9.ld index 9f7905a..ad64ad7 100644 --- a/arm9/arm9.ld +++ b/arm9/arm9.ld @@ -2,34 +2,73 @@ OUTPUT_ARCH(arm) _start = _entry_arm9; +MEMORY { + main (RWX) : ORIGIN = 0x02000000, LENGTH = 4M + itcm (RWX) : ORIGIN = 0x01ff8000, LENGTH = 32K + dtcm (RWX) : ORIGIN = 0x027e0000, LENGTH = 16K + autoload (R) : ORIGIN = 0, LENGTH = 0x18 +} + SECTIONS { - . = 0x02000000; - .rom_start . : { + . = ORIGIN(main); + .arm9 : { + # libsyscall / crt0 build/asm/_secure.o(.text); build/asm/entry.o(.text); build/asm/entry.o(.rodata); - } - .text . : { + . = ALIGN(4); + + # .text build/asm/main.o(.text); build/asm/string.o(.text); build/asm/code_020017b0.o(.text); - } - .non_dism . : { + . = ALIGN(4); + + # non-disassembled build/data/rest.o(.data); - } - SDK_STATIC_BSS_START = .; - SDK_AUTOLOAD_START = .; - .sbss . : { - build/data/sbss.o(.sbss); - } - SDK_AUTOLOAD_LIST = .; - .sbss . : { - build/data/autoload.o(.data); - } - SDK_AUTOLOAD_LIST_END = .; - .bss . : { + . = ALIGN(4); - } - . = 0x0227cb20; # Remove after BSS is done - SDK_STATIC_BSS_END = .; + } > main + + SDK_AUTOLOAD_START = .; + + .itcm : { + build/data/itcm.o(.text); + build/data/itcm.o(.rodata); + build/data/itcm.o(.data); + } > itcm + .itcm_bss : { + build/data/itcm.o(.bss); + } > itcm + + .dtcm : { + build/data/dtcm.o(.text); + build/data/dtcm.o(.rodata); + build/data/dtcm.o(.data); + } > dtcm + .dtcm_bss : { + build/data/dtcm.o(.bss); + } > dtcm + + SDK_AUTOLOAD_ITCM_ADDR = ADDR(.itcm); + SDK_AUTOLOAD_ITCM_SIZE = SIZEOF(.itcm); + SDK_AUTOLOAD_ITCM_BSS_SIZE = SIZEOF(.itcm_bss); + SDK_AUTOLOAD_DTCM_ADDR = ADDR(.dtcm); + SDK_AUTOLOAD_DTCM_SIZE = SIZEOF(.dtcm); + SDK_AUTOLOAD_DTCM_BSS_SIZE = SIZEOF(.dtcm_bss); + + SDK_AUTOLOAD_LIST = ADDR(.arm9) + SIZEOF(.arm9) + SIZEOF(.itcm) + SIZEOF(.dtcm); + .autoload_list : { + build/data/autoload.o(.data); + . = ALIGN(4); + } > autoload + SDK_AUTOLOAD_LIST_END = SDK_AUTOLOAD_LIST + SIZEOF(.autoload_list); + + .bss : { + SDK_STATIC_BSS_START = .; + . = 0x27cb20 - SIZEOF(.arm9); # Remove after BSS is done + . = ALIGN(4); + + SDK_STATIC_BSS_END = .; + } > main } \ No newline at end of file diff --git a/arm9/data/autoload.s b/arm9/data/autoload.s index 340e873..d581da3 100644 --- a/arm9/data/autoload.s +++ b/arm9/data/autoload.s @@ -1,3 +1,11 @@ .section .data -.incbin "../extract/arm9.bin", 0x53b80, 0x18 +#.incbin "../extract/arm9.bin", 0x53b80, 0x18 + +.word SDK_AUTOLOAD_ITCM_ADDR +.word SDK_AUTOLOAD_ITCM_SIZE +.word SDK_AUTOLOAD_ITCM_BSS_SIZE + +.word SDK_AUTOLOAD_DTCM_ADDR +.word SDK_AUTOLOAD_DTCM_SIZE +.word SDK_AUTOLOAD_DTCM_BSS_SIZE diff --git a/arm9/data/dtcm.s b/arm9/data/dtcm.s new file mode 100644 index 0000000..3e5708c --- /dev/null +++ b/arm9/data/dtcm.s @@ -0,0 +1,9 @@ +@ dtcm.s - "I Will Disassemble DTCM Stuff Later tm" + +.section .text + +.incbin "../extract/arm9.bin", 0x53b20, 0x60 + +.section .bss + +.space 0x20 diff --git a/arm9/data/itcm.s b/arm9/data/itcm.s new file mode 100644 index 0000000..c27e08b --- /dev/null +++ b/arm9/data/itcm.s @@ -0,0 +1,4 @@ +@ itcm.s - "I Will Disassemble ITCM Stuff Later tm" + +.section .text +.incbin "../extract/arm9.bin", 0x53560, 0x5c0 diff --git a/arm9/data/sbss.s b/arm9/data/sbss.s deleted file mode 100644 index 5b86ab6..0000000 --- a/arm9/data/sbss.s +++ /dev/null @@ -1,3 +0,0 @@ -.section .sbss, #alloc - -.incbin "../extract/arm9.bin", 0x53560, 0x620