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 > Executing code from sram?

#55589 - Dwedit - Thu Sep 29, 2005 7:27 pm

I know that SRAM is only 8 bits wide, but if you read words from it, will it mirror the 8 bits up to 32 bits? If so, is it possible to get any useful instructrions out of mirrored byte patterns? Any set of instructions that could copy code and run it from a better memory area?
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."

#55590 - tepples - Thu Sep 29, 2005 7:43 pm

Yes, it's possible to execute from SRAM. For instance, the version of PassMe for the new DS firmware does just this.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#55596 - wintermute - Thu Sep 29, 2005 8:35 pm

tepples wrote:
Yes, it's possible to execute from SRAM. For instance, the version of PassMe for the new DS firmware does just this.


The SRAM referred to on that page is DS main memory not gba cart save ram.

#55604 - tepples - Thu Sep 29, 2005 10:29 pm

wintermute wrote:
tepples wrote:
Yes, it's possible to execute from SRAM. For instance, the version of PassMe for the new DS firmware does just this.

The SRAM referred to on that page is DS main memory not gba cart save ram.

Given this forum post, and the fact that consecutive bytes are identical, what makes you think "SRAM" in this case is Nintendo DS EWRAM?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#55742 - wintermute - Sat Oct 01, 2005 12:20 pm

tepples wrote:
wintermute wrote:
tepples wrote:
Yes, it's possible to execute from SRAM. For instance, the version of PassMe for the new DS firmware does just this.

The SRAM referred to on that page is DS main memory not gba cart save ram.

Given this forum post, and the fact that consecutive bytes are identical, what makes you think "SRAM" in this case is Nintendo DS EWRAM?


What led me to that conclusion was that the DS RAM chip is labelled SRAM, the range of acceptable start addresses are in main memory and no mention is made of a GBA cart. Given the comments in that thread about the difficulty of coding for SRAM and that the code is a collection of identical byte pairs it obviously *is* cart SRAM, apologies.

#56035 - Miked0801 - Wed Oct 05, 2005 5:23 pm

Keep in mind that executing code from SRAM is not a "good idea." If you are also storing sensitive save information in the SRAM along with the executed code, there is a small chance that the save information will be corrupted on a power cycle.

Now that I think about this, I'm wondering if I'm remembering GBC docs instead of GBA. Can anyone else chime in on this?

#56068 - tepples - Wed Oct 05, 2005 9:26 pm

Yes, any code that directly accesses savegame hardware even on the GBA is supposed to run from EWRAM so that the memory controllers on the GBA and the Game Pak doesn't get confused between ROM accesses (which use GBA 16-bit seek/read protocol) and SRAM/flash accesses (which use GBC 8-bit protocol with separate address and data pins). There are lots of icky corner cases related to this, and it was probably easier for Nintendo just to put the savegame code library in EWRAM than to fully verify that all corner cases were handled correctly in hardware. For homebrew, all you need to do is put bytecpy() (mentioned in the GBA beginners' FAQ) as CODE_IN_EWRAM.

Still, even with the best precautions, a power failure can still result in inconsistent savegame data if it occurs during saving. NES and Super NES games typically solved this by providing for one more save slot than the game let players use, and then saving to slot 0 before saving to slot 1, 2, or 3. Then if the game notices an incorrect checksum on the data in a save slot, it would assume that a power failure occurred during saving and then copy from slot 0 (which has likely been saved correctly) to that slot. Even Nintendogs for DS uses this, with two 1 Mbit save slots on its 2 Mbit flash chip.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.