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.

DS development > running code from exram

#167040 - elhobbs - Fri Feb 27, 2009 3:39 pm

is there anything special that needs to be done to run code from exram (the supercard 32MB slot2 card). the code is compiled as PIC and it is relocated to the new base address. however, I experience random crashes in the code - always in random spots. this is occuring during an init sequence so it is fairly deterministic and I would expect the issue to occur at the same spot each time - but no. Is there something simple that I am missing - like do I need to enable/disable some sort of caching for the slot 2 memory?

I am using an ezflash5 slot1 for fat and a supercard lite ram/rumble in slot2.

and yes, I know that trying to use that much code on the ds is probably a bad idea;)

#167109 - simonjhall - Sun Mar 01, 2009 6:18 pm

I tried this and seem to have had the same experience that you have! I spent quite some time doing this yet eventually gave up. One thing that did affect me though was there were many global variables in the data segment that was relocated and the byte-write problems were an issue - could this be affecting you too?
_________________
Big thanks to everyone who donated for Quake2

#167112 - elhobbs - Sun Mar 01, 2009 10:21 pm

it looks like you are right. I thought that I had been quite careful removing all of the byte writes to exram (using your byte_write function from quake 2 - thank you very much), but it does not appear to be the case - I missed a lot. it is very hard to track down as it does not always produce immediate bad results - so, it crashes in a totally different location.

I tried looking at the swpb patch for gcc, but that proved to be beyond my abilities. just getting the toolchain to compile was hard enough :(

#167113 - kusma - Sun Mar 01, 2009 10:43 pm

Shouldn't the data-segment simply be moved to mainram instead of trying to hack byte-writes into the exram?

#167124 - simonjhall - Mon Mar 02, 2009 2:26 pm

Yes, that'd be best. However I'm a bit unsure of how to compile that, since all the data loads would be done relative to the current pc (right?) yet main memory is miles away in the address space and that offset would be too large to encode correctly.
_________________
Big thanks to everyone who donated for Quake2

#167126 - kusma - Mon Mar 02, 2009 3:52 pm

simonjhall wrote:
Yes, that'd be best. However I'm a bit unsure of how to compile that, since all the data loads would be done relative to the current pc (right?) yet main memory is miles away in the address space and that offset would be too large to encode correctly.

I'd go for relocating the code instead of making it position independent. It's a bit more hassle up-front, but gives you great flexibility and is more robust (wrt cases like this).