gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > startup/multiboot

#120855 - KayH - Tue Mar 06, 2007 8:07 pm

I've tested my chessgame with No$Gba and it reported some strange issues. After hunting these errors (access to invalid memory) I found the suspicious part (stmia/ldmia) inside the startup sequence introduced from the crt...
There was written from dark_fader, that emulators seems to have issues on that.
My questions:
1) can someone please explain or link to a document explaining the startup sequence?
2) Who is right: dark_fader or martin korth? or both? :-)

I could avoid this issue when I compile for "not multiboot". This points me to the next questions ...
"Vars" defined as "const" go into the ROM space. If I have multiboot activated, all is placed in WRAM. How is this handled? The "const" is only a hint to the compiler, right?
Currently I need to places to define multiboot or not. The first is in the main.c where the multiboot statement is on top of the file. The second is in the makefile to define the needed specs. Is it possible to have only one define to activate/deactivate it on both places?

#120867 - Cearn - Tue Mar 06, 2007 10:19 pm

KayH wrote:
I've tested my chessgame with No$Gba and it reported some strange issues. After hunting these errors (access to invalid memory) I found the suspicious part (stmia/ldmia) inside the startup sequence introduced from the crt...
There was written from dark_fader, that emulators seems to have issues on that.
My questions:
1) can someone please explain or link to a document explaining the startup sequence?
2) Who is right: dark_fader or martin korth? or both? :-)

The start-up sequence is in a file called crt0.S (in particular gba_crt0.S) and , which can be found in devkitARM/arm-eabi/lib . It contains the GBA header and is responsible for initializing the stack(s) and clearing RAM and filling it with data/code if there's any.
If you want any specifics, you'd need to clarify the issue you've been having. In particular "the startup sequence introduced from the crt...There was written from dark_fader, that emulators seems to have issues on that." doesn't parse right.
There have been some issues with range-checks of ctr0.S in older devkitARM's, but those have been solved long ago, AFAIK.

KayH wrote:
I could avoid this issue when I compile for "not multiboot". This points me to the next questions ...
"Vars" defined as "const" go into the ROM space. If I have multiboot activated, all is placed in WRAM. How is this handled? The "const" is only a hint to the compiler, right?

Every item you make has a specific section. Normal global variables go into .data, code goes into .text and const data goes into .rodata. A linkscript tells the linker what the addresses of these sections are: .data into IWRAM and .text/.rodata into ROM/EWRAM depending on boot-mode. The start-up sequence in crt0.S can tell whether it should be ROM or multiboot code (by looking at the addresses the linker gives to the sections). If it's the latter, the contents are copied into EWRAM from the binary file.

KayH wrote:
Currently I need to places to define multiboot or not. The first is in the main.c where the multiboot statement is on top of the file. The second is in the makefile to define the needed specs. Is it possible to have only one define to activate/deactivate it on both places?

Using the 'multiboot' variable was the old way: the linker needed something to show the difference between ROM and multiboot, and the existence of a variable by that name was it. This has been replaced by the specs variable, which is cleaner as deciding on multibootability is really a linker issue, not a compiler one. TThe older devkits (HAM, devkitAdv) still use the older multiboot method, but under devkitARM it's not necessary.

#121141 - KayH - Fri Mar 09, 2007 12:44 pm

Dear Cearn,
thank you very much for your explanation!

Until now I used the devkitARM r18, but yesterday I changed to r20. After recompiling the game and lib the issues were gone.

Regarding the multiboot-define I probably mixed old and new things together. Thank you for pointing me in the right direction. Now I only specify this option only within the makefile (spec=...).

Is there any significant difference between libtonc and libgba? I think the main functionality will be the same, but there could be some special things which one of them handles better than the other one.