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

Support building Multiboot-ROMs #122

Open
phijor opened this issue Mar 21, 2021 · 5 comments
Open

Support building Multiboot-ROMs #122

phijor opened this issue Mar 21, 2021 · 5 comments

Comments

@phijor
Copy link

phijor commented Mar 21, 2021

I'm currently dabbling with the GBA's support for loading ROMs from serial (i.e. multibooting).
To build a Multiboot ROM, one must put .text and .rodata into IWRAM EWRAM (with the entrypoint at 0x0200_0000).

Would it be possible to support this usecase in this crate?

I can imagine the following approach:

  1. Supply a Multiboot start script (rsrt0_multiboot.S).
  2. Build it by default in build.rs
  3. Instruct the user to adapt their linker scripts to include the multiboot rutime instead of rsrt0.o and put everything in IWRAM EWRAM.
@Lokathor
Copy link
Member

Yes.

I don't recall who, but I recall one user getting multi-boot working with this crate by modifying the linker script and boot shim. They were able to make some pixels show up on actual GBA hardware by using a GBA/GCN link cable hooked to a Wii using some sort of Homebrew thing to send the rom from the Wii to the GBA.

So, it's possible.

@phijor
Copy link
Author

phijor commented Mar 22, 2021

I got it to work:

Multiboot ROM output

Looking at the libgba linker scripts, the only modifications I had to make were the following (in linker.ld):

  1. Change VMA for sections .text and .rodata from >rom to >ewram
  2. Change LMA for section .iwram from AT>rom to AT>ewram so .data gets loaded from EWRAM to IWRAM

I did not have to touch the start script (rsrt0.S). For some reason mgba would not load the ROM, but I guess this is just Multiboot autodetection being flakey; it works on real hardware.

Should this be documented somewhere? I can make a PR if you point me in the correct direction.

@Lokathor
Copy link
Member

I for now just make a file called multiboot.md in the repository root and write up the steps there. Keeping things like this in markdown files seems like the simplest way to get started with it.

@TheHans255
Copy link

I've been dabbling in this lately - I recently wrote a sample that deploys an already-written multiboot payload to another GBA over MultiPlay: https://github.com/TheHans255/rust-gba-multiboot-test. Ideally, we'd have a way to build a multiboot executable that shares code with a cartridge executable to let us efficiently make updates to both, which would likely happen via a shared library crate and two executable crates.

I did not have to touch the start script (rsrt0.S). For some reason mgba would not load the ROM, but I guess this is just Multiboot autodetection being flakey; it works on real hardware.

I believe this is correct for SPI mode, but not for MultiPlay (GBA Link Cable) or JOYBUS (Wii/GameCube) mode. Execution starts at 0x0200_00c0 for a Multiboot payload from SPI or MultiPlay, but the GBA BIOS writes to 0x0200_00c4 and 0x0200_00c5 in MultiPlay mode to indicate the boot mode and the player number, respectively, which will corrupt any instructions written there. As for JOYBUS mode, execution starts further down at 0x0200_00e0. A proper rsrt0.S start script will have its header augmented to add b instructions to those locations.

@TheHans255
Copy link

Also, an idea that I saw in the GBATEK document (https://www.problemkaputt.de/gbatek.htm#biosmultibootsinglegamepak) is that if a game is less than 256K, it could be compiled in a "hybrid" mode where the same payload is valid for both cartridge and multiboot - in this mode, the cartridge entry point at 0x0800_0000 leads to a small shim that copies the cartridge into EWRAM. If we need to provide sample linker scripts and start scripts for multiboot, it might be interesting to consider adding samples for the hybrid mode as well.

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

No branches or pull requests

3 participants