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.

Coding > Cartridge Startup Behavior

#46251 - Digeraticus - Wed Jun 22, 2005 9:02 am

How does the startup sequence work? What is loaded to where at cartridge startup? Is stuff labeled with ?.iwram? and so on loaded into the GBA/DS on startup into their respective locations, or is this just a label that tells the compiler to optimize the code for that environment, and we have to load it manually?

#46270 - poslundc - Wed Jun 22, 2005 5:43 pm

The short version:

After the GBA starts up it begins executing the code at 0x08000000. The code that it executes here can be found in crt0, which is usually a file written in assembly (.s or .S) and custom-tailored to the GBA. This code is responsible for copying any necessary code into RAM, initializing variables, etc.

The section labels are used by the linker in order to set up the addresses that the code/variables/etc. are found at (and can from there be copied into IWRAM, EWRAM, etc.). When your various .o files are linked together into a .elf file, a linkscript configured for the GBA is used to tell the linker what the various sections are and where the relevant code needs to go.

Dan.

#46292 - Digeraticus - Wed Jun 22, 2005 8:00 pm

So is that to say that the ?.section? directives DO cause that section to be loaded on startup? And if you have more than one of the same section, and it exceeds the memory for that space on the system, what happens?

#46318 - tepples - Thu Jun 23, 2005 3:24 am

In a perfect world, the linker would notify you when your code overflows a section boundary, but with the version of the linker script shipped in devkitARM, your program will just crash or otherwise misbehave.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#46339 - wintermute - Thu Jun 23, 2005 2:04 pm

tepples wrote:
In a perfect world, the linker would notify you when your code overflows a section boundary, but with the version of the linker script shipped in devkitARM, your program will just crash or otherwise misbehave.


actually, release 12 onwards notifies you :)

#46389 - Digeraticus - Fri Jun 24, 2005 2:51 am

So it does automatically load the code into their correct sections on startup? Or not?

#46393 - wintermute - Fri Jun 24, 2005 2:56 am

Digeraticus wrote:
So it does automatically load the code into their correct sections on startup? Or not?


if you use devkitARM and the appropriate linker switch then it all happens automatically