#153890 - naleksiev - Mon Apr 07, 2008 11:09 pm
Is it possible to execute code from the ROM on DS without moving it to the RAM?
Q: Why I need this?
A: Imagine a library that is not much time consuming and working a little slower won't be a problem, but in the RAM it will take too much space.
I did some research and these are my thoughts.
- I also know how the overlays are working but this is not my case
- I know it's possible on GBA - From what I understand if I don't specify IWRAM or EWRAM it will be running from the ROM (I could be wrong here)
- I can imagine that if the ROM can't be addressed than this is impossible. But I couldn't really understand how it works on DS.
- Knowing that it's not a good idea to link resources on DS the way it used to be on GBA I assume the ROM can't be addressed directly.
I hope you guys prove me wrong, so I can find a solution :)
#153892 - simonjhall - Mon Apr 07, 2008 11:37 pm
Are you talking about running part of the program from ROM or the *entire* thing? I've played around with running code from slot-2 memory and can confirm that it works, but it was pretty hairy. I don't think you'll be able to run code directly from slot-1, as that's not memory-mapped.
_________________
Big thanks to everyone who donated for Quake2
#153893 - naleksiev - Mon Apr 07, 2008 11:55 pm
simonjhall wrote: |
Are you talking about running part of the program from ROM or the *entire* thing? |
Just part
simonjhall wrote: |
I don't think you'll be able to run code directly from slot-1, as that's not memory-mapped. |
Unfortunately that's what I thought, but I was hopping that there is something I'm missing :)
#153898 - Dwedit - Tue Apr 08, 2008 12:53 am
Sounds more like a task for overlays than anything else. Overlays are where you swap in one block of code for another, possibly by reading it from the disk (ds card).
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#153933 - naleksiev - Tue Apr 08, 2008 4:27 pm
Dwedit wrote: |
Sounds more like a task for overlays than anything else. Overlays are where you swap in one block of code for another, possibly by reading it from the disk (ds card). |
I understand the overlays. But this is not the case. Imagine you have 5MB library. Does anyone can come with idea how it can be used?
#153935 - eKid - Tue Apr 08, 2008 4:39 pm
The library will have to be modified to have a smaller memory footprint.
#153938 - kusma - Tue Apr 08, 2008 4:50 pm
I guess the MPU could even be used to automatically swap the overlays, but I must admit that my attempts at messing with the MPU so far has failed horribly.
#153939 - simonjhall - Tue Apr 08, 2008 4:53 pm
Slot-2 RAM, baby. I tried loading in a phat bit of code into this memory, figured out my entry point, returned some function pointers - it's all hunky dorey.
You've got to be careful about
a) linking your code so that it knows it's going into a variable address - slot-2 memory isn't fixed at 0x80... etc
b) making sure your code can call things from libc and other code that's in main memory
c) making sure that if you've got any globals there are no 8-bit writes OR you have to adjust the link scripts to ensure your data goes into main memory
World of pain, but it's all in the linking ;-)
_________________
Big thanks to everyone who donated for Quake2
#153941 - naleksiev - Tue Apr 08, 2008 5:09 pm
eKid wrote: |
The library will have to be modified to have a smaller memory footprint. |
Of course this is a solution:)
kusma wrote: |
I guess the MPU could even be used to automatically swap the overlays, but I must admit that my attempts at messing with the MPU so far has failed horribly. |
I'll look at the MPU it sounds interesting
simonjhall wrote: |
Slot-2 RAM, baby. |
Thanks simonjhall but I'll pass on this one. I love game consoles because I "can't" upgrade them and if something works on my NDS it should works on your. I better use PC instead of trying to make my DS a PC
#153942 - M3d10n - Tue Apr 08, 2008 5:12 pm
naleksiev wrote: |
Is it possible to execute code from the ROM on DS without moving it to the RAM? |
No. Slot-1 ROM is not memory mapped. It's no different than optical media when it comes to executing code from it.
(Posting this just because it hasn't been said yet.)
#153944 - kusma - Tue Apr 08, 2008 5:21 pm
I believe MightyMax had some virtual memory with loading from disk on request code working in the tiny kernel-thingie he wrote. Damn skilled guy.
#153946 - naleksiev - Tue Apr 08, 2008 5:33 pm
M3d10n wrote: |
Slot-1 ROM is not memory mapped. |
Just from curiosity, why did Nintendo design the hardware this way? Especially if it was memory mapped in GBA.
My only guess will be to break the 4GB limit for 32bit pointer.
#153955 - M3d10n - Tue Apr 08, 2008 5:56 pm
naleksiev wrote: |
M3d10n wrote: | Slot-1 ROM is not memory mapped. |
Just from curiosity, why did Nintendo design the hardware this way? Especially if it was memory mapped in GBA.
My only guess will be to break the 4GB limit for 32bit pointer. |
GBA carts (and probably all past consoles' carts) are memory mapped because they are memory mapped devices with a parallel interface, not much different than RAM sticks in your computer.
NDS carts are block-devices with serial interface, similar to SD-cards, hard-disks and CD-ROMs. They are slower to access than memory-mapped carts, but the serial interface is much cheaper to produce and allows cartridges to be smaller and use a wider range of storage methods.
#153964 - Miked0801 - Tue Apr 08, 2008 6:50 pm
And man is that interface slow :(
#153966 - simonjhall - Tue Apr 08, 2008 6:55 pm
How fast is it anyway? I've done FA with slot-1 besides point my fat that way (heh) and haven't really paid attention to the interface speed. Slot-2 is < 10 megs / second, how does slot-1 compare?
_________________
Big thanks to everyone who donated for Quake2
#153978 - tepples - Tue Apr 08, 2008 9:51 pm
naleksiev wrote: |
I better use PC instead of trying to make my DS a PC |
Which handheld PC do you plan to code for?
naleksiev wrote: |
M3d10n wrote: | Slot-1 ROM is not memory mapped. |
Just from curiosity, why did Nintendo design the hardware this way? Especially if it was memory mapped in GBA. |
Cost. Word-addressed memory, such as that used in the N64 and GBA, is more expensive than block-addressed memory, such as that used in the GameCube, DS, and digital cameras. Compare the prices of a 512 Mbit GBA card and a 64 MB CompactFlash card during the GBA's commercial life.
Quote: |
My only guess will be to break the 4GB limit for 32bit pointer. |
Address space wasn't the issue. There was a 40 KiB limit for NES Game Paks, yet they approached 1 MiB by the end of the system's commercial life. See Bank switching on Wikipedia and Mappers on NESdevWiki.
simonjhall wrote: |
Slot-2 is < 10 megs / second, how does slot-1 compare? |
DS SLOT-1 is an 8-bit channel. To see how fast it can transfer, take your favorite SLOT-1 microSD adapter, such as R4 or CycloDS Evolution, and run my speed tester. The value you get isn't exact, as the flash cards aren't exactly the same as an authentic Game Card, but it's in the ballpark.
Datel Games n Music, on the other hand, uses the 1-bit side channel that authentic Game Cards use for save data, so it'll be about 8 times slower. Results from my speed tester bear this out.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#153983 - simonjhall - Tue Apr 08, 2008 11:19 pm
I realise I'm pretty off-topic here, so feel free to fork if you care.
tepples wrote: |
DS SLOT-1 is an 8-bit channel. To see how fast it can transfer, take your favorite SLOT-1 microSD adapter, such as R4 or CycloDS Evolution, and run my speed tester. The value you get isn't exact, as the flash cards aren't exactly the same as an authentic Game Card, but it's in the ballpark.
Datel Games n Music, on the other hand, uses the 1-bit side channel that authentic Game Cards use for save data, so it'll be about 8 times slower. Results from my speed tester bear this out. |
Right, thanks for clarifying. I knew there was some beef with the interface to the GnM (hence the slow speed) but was unsure what. They must have done the 1-bit do-dah because of cost, but it does seem a bit of an odd way to do it! So what's the peak speed that you can get out of the interface sans latency issues?
With the gba slot I'd imagine it's something like 16MHz @ 16 bit, so something like 32 meg / second. I'm probably wrong though, cos I've not coded in quite a few months now ;-)
_________________
Big thanks to everyone who donated for Quake2
#153984 - Dwedit - Tue Apr 08, 2008 11:46 pm
Waitstates waitstates waitstates.
There are 8 cycles in a 4 byte cartridge memory access, not 1.
2^24Hz clockspeed and 8 cycles per 32-bit memory read.
Works out to 8MB/sec.
There are more waitstates in NDS mode.
_________________
"We are merely sprites that dance at the beck and call of our button pressing overlord."
#153986 - tepples - Wed Apr 09, 2008 12:00 am
simonjhall wrote: |
I realise I'm pretty off-topic here, so feel free to fork if you care. |
As far as I can tell, we're still within the topic of the motivation to execute code directly from ROM or not to do so.
simonjhall wrote: |
I knew there was some beef with the interface to the GnM (hence the slow speed) but was unsure what. They must have done the 1-bit do-dah because of cost, but it does seem a bit of an odd way to do it! So what's the peak speed that you can get out of the interface sans latency issues? |
With quality microSD cards, people in the speed tester topic have reported getting roughly 6000 microseconds for 16 KiB, or about 2.8 MB per second. I haven't tried testing with actual DS Game Cards, for reasons that I also explained in the speed tester topic.
Quote: |
With the gba slot I'd imagine it's something like 16MHz @ 16 bit, so something like 32 meg / second. I'm probably wrong though, cos I've not coded in quite a few months now ;-) |
Dwedit is right. At 2,1 wait state, which is the fastest that SLOT-2 supports, the interface runs at is 5.6 MHz for random access or 8.4 MHz for sequential access.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.