From ea779d534f745f98265216d5ae4606664f565bf7 Mon Sep 17 00:00:00 2001 From: DizzyEggg Date: Sun, 15 Dec 2024 12:35:09 +0100 Subject: [PATCH] start work on ewram init --- data/data_8270000.s | 2 - include/gba/defines.h | 1 + ld_script.txt | 109 +++++++++++++++++++++++++----------------- src/code_2.c | 5 +- src/main.c | 4 +- sym_ewram2.txt | 16 ------- 6 files changed, 71 insertions(+), 66 deletions(-) diff --git a/data/data_8270000.s b/data/data_8270000.s index fb475c2a1..a9ff4693a 100644 --- a/data/data_8270000.s +++ b/data/data_8270000.s @@ -4,8 +4,6 @@ gUnknown_8270000: @ 8270000 @ replacing .incbin "baserom.gba", 0x00270000, 0x2724 .byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 -.byte 0x00, 0x00, 0x00, 0x00 .byte 0x04, 0x00, 0x07, 0x00 .byte 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00 diff --git a/include/gba/defines.h b/include/gba/defines.h index 71dcbcde6..5ea69e969 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -9,6 +9,7 @@ #define IWRAM_DATA __attribute__((section("iwram_data"))) #define EWRAM_DATA __attribute__((section("ewram_data"))) #define EWRAM_DATA_2 __attribute__((section("ewram_data_2"))) +#define EWRAM_INIT __attribute__((section("ewram_init"))) #define UNUSED __attribute__((unused)) #define NAKED __attribute__((naked)) diff --git a/ld_script.txt b/ld_script.txt index e576aa391..8b4491a2d 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -3,10 +3,17 @@ ENTRY(Start) gNumMusicPlayers = 8; gMaxLines = 0; -SECTIONS { - . = 0x2000000; +MEMORY +{ + EWRAM (rwx) : ORIGIN = 0x2000000, LENGTH = 256K + IWRAM (rwx) : ORIGIN = 0x3000000, LENGTH = 32K + ROM (rx) : ORIGIN = 0x8000000, LENGTH = 32M +} - ewram (NOLOAD) : +SECTIONS { + + ewram 0x2000000 (NOLOAD) : + ALIGN(4) { ewram_start = .; @@ -17,24 +24,20 @@ SECTIONS { *libgcc.a:dp-bit.o(.bss); *libc.a:syscalls.o(.bss); . = ALIGN(16); - INCLUDE "sym_ewram2.ld" - *libc.a:impure.o(.data); - *libc.a:locale.o(.data); - *libc.a:mallocr.o(.data); - ewram2_end = .; - . = 0x40000; - } + src/m4a.o(ewram_data_2); + src/agb_flash.o(ewram_data_2); + *libc.a:sbrkr.o(COMMON); + } > EWRAM - . = 0x3000000; - - iwram (NOLOAD) : + iwram 0x3000000 (NOLOAD) : ALIGN(4) { iwram_start = .; INCLUDE "sym_iwram.ld" . = 0x8000; - } + } > IWRAM + /* BEGIN ROM DATA */ . = 0x8000000; .text : @@ -407,7 +410,7 @@ SECTIONS { *libc.a:lseekr.o(.text); *libc.a:readr.o(.text); *libgcc.a:_udivsi3.o(.text); - } =0 + } > ROM =0 .rodata : ALIGN(4) @@ -716,9 +719,35 @@ SECTIONS { *libc.a:locale.o(.rodata); *libc.a:mprec.o(.rodata); *libc.a:syscalls.o(.rodata); - . = ALIGN(4); - data/data_8270000.o(.rodata); - } =0 + . = ALIGN(4); + } > ROM =0 + + ewram_init : + ALIGN(4) + { + ewramClearEnd = .; + ewramClearEnd2 = .; + + src/code_2.o(ewram_init); + } > EWRAM AT>ROM + + EWRAM_INIT_ROM_START = LOADADDR(ewram_init); + + ewram_init_temp : + ALIGN(4) + { + data/data_8270000.o(.rodata); + } > ROM =0 + + ewram_temp (NOLOAD) : + ALIGN(4) + { + INCLUDE "sym_ewram2.ld" + *libc.a:impure.o(.data); + *libc.a:locale.o(.data); + *libc.a:mallocr.o(.data); + ewram2_end = .; + } > EWRAM unk_code_section : ALIGN(4) @@ -728,73 +757,65 @@ SECTIONS { src/code_8272724.o(.text); asm/code_8272724.o(.text); unk_code_end = .; - } + } > ROM =0 unk_code_section_size = (unk_code_end - unk_code); unk_code_ram_end = unk_code_ram + unk_code_section_size; end = unk_code_ram_end; - . = 0x8300000; - unk_data : + unk_data 0x8300000 : ALIGN(4) { data/unk_data.o(.rodata); - } + } > ROM =0 - . = 0x8300500; - system_sbin_section : + system_sbin_section 0x8300500 : ALIGN(4) { data/system_sbin.o(.rodata); - } + } > ROM =0 - . = 0x8380000; - titlemenu_sbin_section : + titlemenu_sbin_section 0x8380000 : ALIGN(4) { data/titlemenu_sbin.o(.rodata); - } + } > ROM =0 - . = 0x83B0000; - dungeon_sbin_section : + dungeon_sbin_section 0x83B0000 : ALIGN(4) { data/dungeon_sbin.o(.rodata); - } + } > ROM =0 - . = 0x8510000; - monster_sbin_section : + monster_sbin_section 0x8510000 : ALIGN(4) { data/monster_sbin.o(.rodata); - } + } > ROM =0 - . = 0x9740000; - effect_sbin_section : + effect_sbin_section 0x9740000 : ALIGN(4) { data/effect_sbin.o(.rodata); - } + } > ROM =0 - . = 0x9890000; - ground_sbin_section : + ground_sbin_section 0x9890000 : ALIGN(4) { data/ground_sbin.o(.rodata); - } + } > ROM =0 - . = 0x9E60000; - ornament_sbin_section : + ornament_sbin_section 0x9E60000 : ALIGN(4) { data/ornament_sbin.o(.rodata); - } + } > ROM =0 sound_data : ALIGN(4) { data/sound_data.o(.rodata); - } + } > ROM =0 /* DWARF 2 sections */ .debug_aranges 0 : { *(.debug_aranges) } diff --git a/src/code_2.c b/src/code_2.c index 504c999bb..21d74bf3c 100644 --- a/src/code_2.c +++ b/src/code_2.c @@ -38,10 +38,11 @@ extern void LoadTitleScreen(void); extern void nullsub_33(void); extern u32 sub_80009D0(u32); -extern u32 gUnknown_203B03C; extern u16 gUnknown_2026E4E; extern s32 gTitleBrightness; -extern OpenedFile *gTitlePaletteFile; + +EWRAM_INIT OpenedFile *gTitlePaletteFile = NULL; +EWRAM_INIT u32 gUnknown_203B03C = 0; extern char gPMDBuildVersion[]; diff --git a/src/main.c b/src/main.c index 325ea2ba2..ee9aa49d9 100644 --- a/src/main.c +++ b/src/main.c @@ -28,7 +28,7 @@ extern u8 unk_code_ram[]; extern u8 unk_code_ram_end[]; // data_8270000.s -extern const u8 gUnknown_8270000[]; +extern const u8 EWRAM_INIT_ROM_START[]; UNUSED static const char sStringRomUserData[] = "PKD ROM USER DATA 000000"; @@ -50,7 +50,7 @@ void AgbMain(void) DmaStop(3); if (ewram2_end - ewramClearEnd > 0) - CpuCopy32(gUnknown_8270000, ewramClearEnd, ewram2_end - ewramClearEnd); + CpuCopy32(EWRAM_INIT_ROM_START, ewramClearEnd, ewram2_end - ewramClearEnd); if (ewramClearEnd2 - ewram_start > 0) { memset(value, 0, 4); diff --git a/sym_ewram2.txt b/sym_ewram2.txt index 2b0b60b8b..55d96c8a8 100644 --- a/sym_ewram2.txt +++ b/sym_ewram2.txt @@ -1,23 +1,9 @@ .align 2 -.include "src/m4a.o" -.include "src/agb_flash.o" - -errno: /* 203B034 */ - .space 0x4 - -ewramClearEnd: -ewramClearEnd2: -gTitlePaletteFile: /* 203B038 (GameLoop) */ - .space 0x4 -gUnknown_203B03C: /* 203B03C */ - .space 0x4 gPersonalityRelated_203B040: /* 203B040 */ .space 0x30 .include "src/other_random.o" - .space 0x2 - .include "src/sprite.o" gUnknown_203B078: /* 203B078 (sub_80057E8 - SaveUnkTextStructAndXXX_8006438) */ @@ -44,8 +30,6 @@ gUnknown_203B090: /* 203B090 (InitGraphics) */ .include "src/main.o" .include "src/reg_control.o" .include "src/flash.o" - .space 0x3 - .include "src/code_800C9CC.o" gUnknown_203B0BE: /* 203B0BE (sub_800CDA8) */