From f2052ca8ef06f858037d6657b377197dd8772f4c Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 12 Apr 2020 17:17:21 -0400 Subject: more work --- Makefile | 9 ++++++--- asm/main.s | 4 ++-- asm/rom_header.s | 6 +++--- ld_script.txt | 40 ++++++++++++++++++++++++++++------------ main.c | 7 ------- 5 files changed, 39 insertions(+), 27 deletions(-) delete mode 100644 main.c diff --git a/Makefile b/Makefile index 738cc646..cb5149ba 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ MWCCVERSION := 2.0/base CROSS := arm-linux-gnueabi- -MWCCARM := tools/mwccarm/2.0/base/mwccarm.exe +MWCCARM := tools/mwccarm/$(MWCCVERSION)/mwccarm.exe AS := $(CROSS)as CC := $(MWCCARM) @@ -65,8 +65,11 @@ $(BUILD_DIR)/%.o: %.c $(BUILD_DIR)/%.o: %.s $(AS) $(ASFLAGS) -MD $(BUILD_DIR)/$*.d -o $@ $< -$(ELF): $(O_FILES) $(LD_SCRIPT) undefined_syms.txt - $(LD) -T undefined_syms.txt -T $(LD_SCRIPT) -o $(ELF) +$(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT) + $(CPP) $(VERSION_CFLAGS) -MMD -MP -MT $@ -MF $@.d -I include/ -I . -DBUILD_DIR=$(BUILD_DIR) -o $@ $< + +$(ELF): $(O_FILES) $(BUILD_DIR)/$(LD_SCRIPT) undefined_syms.txt + $(LD) -T undefined_syms.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -o $(ELF) -Map $(BUILD_DIR)/$(TARGET).map $(ROM): $(ELF) $(OBJCOPY) -O binary $< $@ diff --git a/asm/main.s b/asm/main.s index 80f388cd..e069ed79 100644 --- a/asm/main.s +++ b/asm/main.s @@ -2,8 +2,8 @@ .text - arm_func_start Main -Main: @ 0x02000800 + arm_func_start Entry +Entry: @ 0x02000800 mov ip, #0x4000000 str ip, [ip, #0x208] _02000808: diff --git a/asm/rom_header.s b/asm/rom_header.s index e850d0f8..a8583e2b 100644 --- a/asm/rom_header.s +++ b/asm/rom_header.s @@ -29,11 +29,11 @@ RomVersion: .space 1 ARM9ROMOffset: -.word 0x00004000 +.word _rom_codeSegmentRomStart ARM9EntryAddress: -.word 0x02000800 +.word Entry ARM9RAMAddress: -.word 0x02000000 +.word _rom_codeSegmentStart ARM9CodeSize: .word 0x00107724 ARM7ROMOffset: diff --git a/ld_script.txt b/ld_script.txt index e904d75e..ec6e4c0c 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -1,16 +1,32 @@ +/* Linker Script to build Pokemon Diamond */ + +#define BEGIN_SEG(name, addr) \ + _##name##SegmentStart = ADDR(.name); \ + _##name##SegmentRomStart = __romPos; \ + .name addr : AT(__romPos) + +#define END_SEG(name) \ + _##name##SegmentEnd = ADDR(.name) + SIZEOF(.name); \ + _##name##SegmentRomEnd = __romPos + SIZEOF(.name); \ + __romPos += SIZEOF(.name); + SECTIONS { - header : - { - build/asm/rom_header.o(.text); - } + __romPos = 0; + BEGIN_SEG(header, 0x0) + { + build/asm/rom_header.o(.text); + } + END_SEG(header) - . = 0x4000; - rom_code : - { + __romPos += 0x3E00; + + BEGIN_SEG(rom_code, 0x2000000) + { build/asm/secure.o(.text); - build/asm/main.o(.text); - build/asm/rom.o(.text); - build/src/sub_02000DF4.o(.text); - build/asm/rom2.o(.text); - } + build/asm/main.o(.text); + build/asm/rom.o(.text); + build/src/sub_02000DF4.o(.text); + build/asm/rom2.o(.text); + } + END_SEG(rom_code) } diff --git a/main.c b/main.c deleted file mode 100644 index 17e69b3d..00000000 --- a/main.c +++ /dev/null @@ -1,7 +0,0 @@ -// Just includes for now so CLion sees the files -#include "structs/structs.h" -#include "nitro/nitro.h" - -void main() { - int x = NULL; -} -- cgit v1.2.3 From 09fa95f0e27e9a835f5535a776f6a22861c7c4a0 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 12 Apr 2020 17:26:03 -0400 Subject: arm9 segment work --- asm/rom2.s | 2 +- asm/rom3.s | 5 +++++ asm/rom_header.s | 6 +++--- ld_script.txt | 11 +++++++++-- main.c | 7 +++++++ 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 asm/rom3.s create mode 100644 main.c diff --git a/asm/rom2.s b/asm/rom2.s index 81eaddea..03b89938 100644 --- a/asm/rom2.s +++ b/asm/rom2.s @@ -2,4 +2,4 @@ .section .text -.incbin "baserom.nds", 0x4E0C, 0x3FFB1F4 +.incbin "baserom.nds", 0x4E0C, 0x106918 diff --git a/asm/rom3.s b/asm/rom3.s new file mode 100644 index 00000000..ddb524ba --- /dev/null +++ b/asm/rom3.s @@ -0,0 +1,5 @@ +/* rom3.s TODO: Disassemble */ + +.section .text + +.incbin "baserom.nds", 0x10B724, 0x3EF48DC diff --git a/asm/rom_header.s b/asm/rom_header.s index a8583e2b..2dc62ad5 100644 --- a/asm/rom_header.s +++ b/asm/rom_header.s @@ -29,13 +29,13 @@ RomVersion: .space 1 ARM9ROMOffset: -.word _rom_codeSegmentRomStart +.word _arm9SegmentRomStart ARM9EntryAddress: .word Entry ARM9RAMAddress: -.word _rom_codeSegmentStart +.word _arm9SegmentStart ARM9CodeSize: -.word 0x00107724 +.word _arm9SegmentSize ARM7ROMOffset: .word 0x0030D000 ARM7EntryAddress: diff --git a/ld_script.txt b/ld_script.txt index ec6e4c0c..4a5c4e3a 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -8,6 +8,7 @@ #define END_SEG(name) \ _##name##SegmentEnd = ADDR(.name) + SIZEOF(.name); \ _##name##SegmentRomEnd = __romPos + SIZEOF(.name); \ + _##name##SegmentSize = SIZEOF(.name); \ __romPos += SIZEOF(.name); SECTIONS { @@ -20,7 +21,7 @@ SECTIONS { __romPos += 0x3E00; - BEGIN_SEG(rom_code, 0x2000000) + BEGIN_SEG(arm9, 0x2000000) { build/asm/secure.o(.text); build/asm/main.o(.text); @@ -28,5 +29,11 @@ SECTIONS { build/src/sub_02000DF4.o(.text); build/asm/rom2.o(.text); } - END_SEG(rom_code) + END_SEG(arm9) + + BEGIN_SEG(rom3, 0x2000000 + SIZEOF(arm9)) + { + build/asm/rom3.o(.text); + } + END_SEG(rom3) } diff --git a/main.c b/main.c new file mode 100644 index 00000000..17e69b3d --- /dev/null +++ b/main.c @@ -0,0 +1,7 @@ +// Just includes for now so CLion sees the files +#include "structs/structs.h" +#include "nitro/nitro.h" + +void main() { + int x = NULL; +} -- cgit v1.2.3 From 09d4bbd57a8d810e2765f77ac7431848ca4328b2 Mon Sep 17 00:00:00 2001 From: ProjectRevoTPP Date: Sun, 12 Apr 2020 17:26:49 -0400 Subject: ld script formatting --- ld_script.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ld_script.txt b/ld_script.txt index 4a5c4e3a..33584719 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -8,7 +8,7 @@ #define END_SEG(name) \ _##name##SegmentEnd = ADDR(.name) + SIZEOF(.name); \ _##name##SegmentRomEnd = __romPos + SIZEOF(.name); \ - _##name##SegmentSize = SIZEOF(.name); \ + _##name##SegmentSize = SIZEOF(.name); \ __romPos += SIZEOF(.name); SECTIONS { @@ -17,23 +17,23 @@ SECTIONS { { build/asm/rom_header.o(.text); } - END_SEG(header) - - __romPos += 0x3E00; + END_SEG(header) + + __romPos += 0x3E00; BEGIN_SEG(arm9, 0x2000000) { - build/asm/secure.o(.text); + build/asm/secure.o(.text); build/asm/main.o(.text); build/asm/rom.o(.text); build/src/sub_02000DF4.o(.text); build/asm/rom2.o(.text); } - END_SEG(arm9) - - BEGIN_SEG(rom3, 0x2000000 + SIZEOF(arm9)) - { - build/asm/rom3.o(.text); - } - END_SEG(rom3) + END_SEG(arm9) + + BEGIN_SEG(rom3, 0x2000000 + SIZEOF(arm9)) + { + build/asm/rom3.o(.text); + } + END_SEG(rom3) } -- cgit v1.2.3