d0k3 / GodMode9

GodMode9 Explorer - A full access file browser for the Nintendo 3DS console :godmode:
GNU General Public License v3.0
2.07k stars 192 forks source link

Split GM9 across two sections in memory. #837

Open DarkRTA opened 5 months ago

DarkRTA commented 5 months ago

This is needed to implement support for Lua. Lua is way to big to fit in a single contiguous section of memory without overwriting our copy of boot9 and boot11, so some clever linker manipulation was used to place things in the free space after it. LTO also had to be disabled as we won't be able to split .text later with it.

This uses the following memory map:

AHBWRAM: 0x08000040 - 0x08080000
    .vectors
    .text
    .rodata
    .data
    .bss
    .rodata
    .data
    .bss

AHBWRAM2: 0x080a0000 - 0x08100000
    .text (files in arm9/source/lua)
    .text (libm)
    .rodata.vram_data

This has been tested on actual hardware and seems to boot up and work fine.

ihaveamac commented 5 months ago

Trying some stuff with this PR and I think a few features aren't working properly. Specifically I tried building a CIA for a built-in title (Activity Log USA 0004001000021200), and it froze. Building the latest commit of the main repo (ad8b5e0a8c7c9d7dd590fb76a29fe5d6ab18e22f) and it works fine.

Is there a chance something else is using arm9 memory? Or is something just weird with my setup? I don't know what else could have broken.

ihaveamac commented 5 months ago

Maybe related to lto? Because building the latest mainline commit without lto results in a crash: IMG_0238

DarkRTA commented 5 months ago

I'd consider opening a separate issue for that. This reeks of UB.

DarkRTA commented 5 months ago

Trying some stuff with this PR and I think a few features aren't working properly. Specifically I tried building a CIA for a built-in title (Activity Log USA 0004001000021200), and it froze. Building the latest commit of the main repo (ad8b5e0) and it works fine.

turns out the freeze here was actually the exception handler being broken due to a typo in the linker script. this has been fixed