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 Misc > Techdemo: Paging & Swapping

#78753 - Mighty Max - Sun Apr 09, 2006 2:56 pm

It's me, Ma...Mighty Max :D

I have made a little Techdemo about using the Arm9 MPU to create a virtual memspace. Several ppl told me that this was impossible/ too complex todo as the MPU is no MMU and does not provide the needed hardware registers (pagetables & fault address register i.e.)

The uploaded demo will proove that this is at least for data access wrong.

The demo contains 2 .NDS files. One should be known by all, it's doublec's Tutorial 1 demo. The second, Paging.nds, implements the swapping.

This is what Paging.nds will do:
- Create a 2 MB swap file. (1MB to cascade the buffer & codespace for itself) and 1 MB virtual RAM at the GBA-Cardspace
- load the demo1.nds into the GBA-Cardspace
- extracts the arm9 binary from the cardspace again and runs it in the controlled environment (start just after MPU init of crt0)
- responds to A+B+R+L keypresses when demo1 is running, no matter if demo1 installes IRQ handler itself (unless it changes the keys IRQ yet)


Every access to a paged memory area will cause the access to be relocated. Every access to a hardware register will inform the Paging.nds to react to it.


There are several points i still need working on. About 80% of all instructions that might access the ram are handled, some thumb instructions as well as LD/STM over a page border are not yet done.

The process locks the GBAMP other FAT devices behind the protection. A emulation of the GBAMP hardware registers should not be a problem.


hrm, looks like my isp has problem with the ftp. I'll upload the archive as soon as the access is up again. For now, just take a look at the yesterday's testrelease (just bin, return from keypressed info not done) http://mightymax.org/Stage1.rar . It will work on none of the emulators, a read/write-FAT_device (supported by chishm's lib) is needed.

If any emulator coder wants to have input of what is needed get it running in emulator too, query me.
_________________
GBAMP Multiboot

#78876 - Mighty Max - Mon Apr 10, 2006 10:22 am

The source is uploaded, http://www.mightymax.org/PagingRC1.zip

Have fun.
_________________
GBAMP Multiboot

#78877 - Dark Knight ez - Mon Apr 10, 2006 10:25 am

Nice project. Good job on pushing the DS's limits. :)

#78913 - thoduv - Mon Apr 10, 2006 3:43 pm

It's clearly a great step for the DS homebrew ! WELL DONE MIGHTYMAX ! \o/

#78923 - JaJa - Mon Apr 10, 2006 4:46 pm

An interesting little tech demo.
But does it have any practical use?
I mean, i saw you talking to pepsiman in #dsdev today, and you admitted it was very slow.

#78927 - Mighty Max - Mon Apr 10, 2006 5:39 pm

For the most projects it would be much wiser to utilize the fat devices directly to outsource data.

But i guess it proves that such things are not impossible :D

What it could be used for, are on-hardware debugger (trapping access to hw register, cascading it's own code/data against the guest binary) or maybe to run old .nds with gbfs > 4MB on GBAMP (TickleGirl i.e.)
_________________
GBAMP Multiboot

#78948 - kenny - Mon Apr 10, 2006 9:00 pm

Looks good, but it's kinda... slow...
Would it work if i replaced demo1.nds with something like "TickleGirl" that's too big for the GBAMP?

#78986 - Sebbo - Tue Apr 11, 2006 12:39 am

once its optimised i'm sure we could see this being used in DSLinux, or any homebrew OS
_________________
Here's some ideas I have for when I know enough to act on them, or for others to have a look at when they're bored: www.wayne.sebbens.com/ds_ideas.htm

#78994 - quadomatic - Tue Apr 11, 2006 1:23 am

wait, this means that we can run homebrew larger than 4 mb on gbamp?

#79139 - derula - Tue Apr 11, 2006 8:43 pm

As chishm has stated more than once, NDS MP already can execute files larger than 4 MB, TickleGirl just don't work because it tries to read from the GBA slot if it was a GBA flashcard. I don't believe it really, but this is at least what chishm says, and he should actually know it because he wrote it.
_________________
visit my blog. please.

#79143 - Mighty Max - Tue Apr 11, 2006 9:19 pm

Derula, this is on a complete other level.

Indeed the MP can load homebrew bigger then 4MB, unless it is in one big block. The software that does so has to be CF/SD aware.

If the software does not manage this by itself, such method as posted above is the only way to run >4MB monolithic binaries. Except you build a hardware solution for the missing memory space (as the M3/Supercard does)

As you stated yourself, the GBAMP does not work if there is a GBA Romspace memory needed. (As tickle girl expects it) and this is exactly what the demo method fakes.
_________________
GBAMP Multiboot

#79168 - quadomatic - Tue Apr 11, 2006 11:45 pm

Mighty Max wrote:

As you stated yourself, the GBAMP does not work if there is a GBA Romspace memory needed. (As tickle girl expects it) and this is exactly what the demo method fakes.


So this means that GBAMP will now run ANY homebrew? Or is this just a tech demo and it's not quite finalized yet, but once it is it will run any homebrew?

Regardless, this is awesome Mighty Max, great job, we all REALLY appreciate it!

#79173 - tepples - Wed Apr 12, 2006 12:32 am

Because of the lack of true virtual memory, it's not likely to run at anywhere near full speed. Imagine running a DS emulator on a DS.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#79299 - Mighty Max - Wed Apr 12, 2006 7:14 pm

quadomatic wrote:

So this means that GBAMP will now run ANY homebrew? Or is this just a tech demo and it's not quite finalized yet, but once it is it will run any homebrew?

Regardless, this is awesome Mighty Max, great job, we all REALLY appreciate it!


If you'd include the most binaries instead of "demo1.nds" aou most likely get a "Fatal Page Fault: Access to HW Register", which comes up when the child NDS accesses an unknown access into the registerspace.

So no, this is really just a demo how to relocate memory accesses / gain the fault address from the cpu-state & faulting opcode. Unfortunally the cp15 of the ds does not support it directly.

For a complete and useable loader for >4MB monolithic binaries several things are still missing. #1 to #5 on that list would indeed speeding up, speeding up, ... ;) (i guess about 50:1 [instructions/faulting instruction] would be totally possible, but thats still mighty slow.

Other things to solve would be to prevent the client NDS to set the cp15 registers (Atm it just jumps over the first cp15 inits) and such.

I most likely won't do much in this direction. It solved its purpose to prove it's possible.

And thanks :) for the words
_________________
GBAMP Multiboot