manage TCM, bss and overlays should work fine now

This commit is contained in:
patataofcourse 2022-08-13 16:58:38 +02:00
parent e458e02562
commit f1f63b73d4
6 changed files with 93 additions and 28 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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

9
arm9/data/dtcm.s Normal file
View File

@ -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

4
arm9/data/itcm.s Normal file
View File

@ -0,0 +1,4 @@
@ itcm.s - "I Will Disassemble ITCM Stuff Later tm"
.section .text
.incbin "../extract/arm9.bin", 0x53560, 0x5c0

View File

@ -1,3 +0,0 @@
.section .sbss, #alloc
.incbin "../extract/arm9.bin", 0x53560, 0x620