Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split GM9 across two sections in memory. #837

Closed
wants to merge 6 commits into from
Closed

Conversation

DarkRTA
Copy link

@DarkRTA DarkRTA commented Jan 20, 2024

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.

This is needed to implement support for Lua. Lua is way to big to fit in
a single contigious 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.

This uses the following memory map:

```
AHBWRAM: 0x08000000 - 0x08080000
    .vectors
    .text
    .ARM.exidx

AHBWRAM2: 0x080a0000 - 0x08100000
    .text (files in arm9/source/lua)
    .rodata
    .data
    .bss
```
Makefile Outdated
Comment on lines 94 to 112
$(OUTDIR)/AHBWRAM.bin: $(ELF)
@$(OBJCOPY) -O binary arm9/arm9.elf --only-section=AHBWRAM $@

$(OUTDIR)/AHBWRAM2.bin: $(ELF)
@$(OBJCOPY) -O binary arm9/arm9.elf --only-section=AHBWRAM2 $@

BINS := $(OUTDIR)/AHBWRAM.bin $(OUTDIR)/AHBWRAM2.bin

firm: $(ELF) $(BINS)
@mkdir -p $(call dirname,"$(FIRM)") $(call dirname,"$(FIRMD)")
@echo "[FLAVOR] $(FLAVOR)"
@echo "[VERSION] $(VERSION)"
@echo "[BUILD] $(DBUILTL)"
@echo "[FIRM] $(FIRM)"
@$(PY3) -m firmtool build $(FIRM) $(FTFLAGS) -g -D $(ELF) -C NDMA XDMA
@$(PY3) -m firmtool build $(FIRM) $(FTFLAGS) -g -D $(BINS) arm11/arm11.elf \
-A 0x08000000 0x080a0000 -C NDMA NDMA XDMA -n 0x08000040
@echo "[FIRM] $(FIRMD)"
@$(PY3) -m firmtool build $(FIRMD) $(FTDFLAGS) -g -D $(ELF) -C NDMA XDMA
@$(PY3) -m firmtool build $(FIRMD) $(FTDFLAGS) -g -D $(BINS) arm11/arm11.elf \
-A 0x08000000 0x080a0000 -C NDMA NDMA XDMA -n 0x08000040
Copy link
Author

@DarkRTA DarkRTA Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity, is there way you'd like for this to actually be done?

Hardcoding the the entry-point here also seems quite fragile but I doubt that will suddenly break us unless for some reason we move move _start or increase the size of .vectors.

Makefile Outdated Show resolved Hide resolved
arm9/Makefile Show resolved Hide resolved
arm9/link.ld Outdated Show resolved Hide resolved
arm9/link.ld Outdated Show resolved Hide resolved
Comment on lines +94 to +98
$(OUTDIR)/AHBWRAM_LO.elf: $(ELF)
@$(OBJCOPY) arm9/arm9.elf -j AHBWRAM_LO $@

$(OUTDIR)/AHBWRAM_HI.elf: $(ELF)
@$(OBJCOPY) arm9/arm9.elf -j AHBWRAM_HI $@
Copy link
Author

@DarkRTA DarkRTA Jan 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

objcopy is now throwing a warning and it does not provide any option to silence it.
Since this doesn't break the build, do you have any suggestions on how I can silence its output, or if we can even do so?

@ihaveamac
Copy link
Contributor

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.

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
Copy link
Contributor

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

@DarkRTA
Copy link
Author

DarkRTA commented Jan 23, 2024

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

@DarkRTA
Copy link
Author

DarkRTA commented Jan 24, 2024

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

@DarkRTA
Copy link
Author

DarkRTA commented Sep 30, 2024

Wolfvak has offered a much better solution than what is present here. Closing this.

@DarkRTA DarkRTA closed this Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants