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 > EWRAM

#11352 - regularkid - Fri Oct 03, 2003 12:55 am

If I have too much data/common symbols that takes up more than 32K (more than the size of IWRAM), will the compiler/linker automatically put the extra data into EWRAM? I am using the latest crt0.o and lnkscript files from gbadevrs.Thanks!
_________________
- RegularKid

#11355 - DekuTree64 - Fri Oct 03, 2003 2:53 am

Nope, it just keeps puting stuff at higher addresses, and since IWRAM mirrors every 32K, it will wrap around and cover the lower data. Not to mention the BIOS stuff that's stored in the last bit of IWRAM will get messed up and then the stack will overwrite your data.
You have to specifically put something in EWRAM if you want it there. Use an __attribute, I don't remember the exact syntax off hand, but it's like putting functions in IWRAM, except use .ewram, and skip the long_call.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#11357 - poslundc - Fri Oct 03, 2003 3:59 am

Hm...

Are global variables placed in EWRAM by default then?

Dan.

#11359 - tepples - Fri Oct 03, 2003 4:25 am

Global variables are placed in IWRAM by default.

There is, however, a bug somewhere in the toolchain that aligns all global variables to 32-byte increments. It'd be best to put all your global variables in a struct; not only will this conserve RAM, but it'll also make things easier to move around should you want to move things to another part of memory, should you want to add more than one of something, or should you want to use overlays.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#11360 - regularkid - Fri Oct 03, 2003 4:34 am

Great, thanks. Good idea about the global structure too. Should help. By the way, how much slower is EWRAM compared to RAM and ROM?
_________________
- RegularKid

#11363 - tepples - Fri Oct 03, 2003 6:50 am

In order from fastest to slowest:

IWRAM: 32 KB, 32-bit, 1 cycle to access
VRAM: 96 KB, 16-bit, 1 cycle to access, 8-bit writes write to both bytes in a word
Game Pak ROM[1]: 4 to 32 MB, 16-bit, 4 cycles for a random access, 2 cycles for a sequential access
EWRAM: 256 KB, 16-bit, 3 cycles to access
Game Pak SRAM: 4 to 64 KB, 8-bit, 9 cycles to access, 16-bit and 32-bit writes don't work

You may hear memory access times quoted in "wait states." This number refers to the additional cycles tacked on to an access in addition to the one cycle used to put the data on the bus.

A memory with "16-bit" word size takes two transfers to read or write a 32-bit value. In the case of ROM, the second transfer of a 32-bit read or write is considered sequential.

[1] Assumes ROM is set to most common 3/1 wait state setting; however, the power-on default is 4/2 just in case larger but slower memories become available.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.