forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Virtual memory on psp need help !!!!

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
pspd3vil



Joined: 28 Nov 2005
Posts: 5
Location: France

PostPosted: Mon Nov 28, 2005 11:52 pm    Post subject: Virtual memory on psp need help !!!! Reply with quote

Hi i would like to create a malloc the wouldn't use the ram, but instead uses a .bin in the MS like an mmu-page.

because I want to port emulators such as mame or neogeo cartridge i've already ported this emu's but now i need a lot of memory i already play with the cps1 system an some roms Neogeo MVS of 6Mb zipped .

can anyone help ?


Thx
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
ReKleSS



Joined: 18 Jun 2005
Posts: 73
Location: Melbourne, Australia

PostPosted: Tue Nov 29, 2005 1:00 pm    Post subject: Reply with quote

Somehow, I don't think this is going to work. The psp has no MMU. I can't think of any feasible way to fake one...
-ReK
Back to top
View user's profile Send private message
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Tue Nov 29, 2005 2:04 pm    Post subject: Reply with quote

...And don't forget that using flash for virtual memory will tend to wear it out more quickly. A typical flash memory location can only be written to about one million times before it wears out. If you publish software that does a lot of writing to flash, you should post a warning to the user that it may shorten the life of the memory card.

By the way, there is a company now (Max?) that sells a 4 gigabyte hard drive that plugs into the memory slot on the PSP. The drive itself is mounted inside an "ergonomic" bump that snaps onto the underside of the PSP. This uses more power than a memory stick, but it is cheaper per megabyte and can be re-written many more times. Something to consider. (And no, I don't work for them or have any financial stake in the company.)

EDIT:
You can do this kind of thing without dedicated MMU hardware, but you would have to use handles instead of pointers. Your allocation routine would return an integer that identifies the memory block to the memory management system. To use the memory, you pass the handle to a "lock" routine, which finds space in RAM and copies the memory block in from VM (if it is not already resident) before incrementing a lock count and returning an actual pointer to the buffer in RAM. When you are done accessing the memory, you pass the handle to an "unlock" routine, which would decrement the lock count for that buffer. When the memory manager needs more RAM to lock a buffer, it can reclaim the RAM used by any handle whose lock count is zero simply by copying the block back into virtual (aka flash) memory.

It sounds ugly, but it's really not that bad:

Code:

// Rough pseudocode compiled only in my cranium...
typedef unsigned int HANDLE;

HANDLE VirtualAlloc(size_t bytesToAllocate);
void* VirtualLock(HANDLE handleToLock);
void VirtualUnlock(HANDLE handleToUnlock);
void VirtualFree(HANDLE handleToFree);

HANDLE h = VirtualAlloc(sizeof(someStruct));
someStruct* p = (someStruct*)VirtualLock(h);
if (p != NULL)
{
     // Access the structure using pointer 'p' here...

     // ...When finished using the structure:
     VirtualUnlock(h);
}

VirtualFree(h);


Actually writing the guts of the four Virtual****() functions is left as an exercise for the reader.
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Tue Nov 29, 2005 8:09 pm    Post subject: Reply with quote

Dr. Vegetable wrote:
...And don't forget that using flash for virtual memory will tend to wear it out more quickly. A typical flash memory location can only be written to about one million times before it wears out. If you publish software that does a lot of writing to flash, you should post a warning to the user that it may shorten the life of the memory card.

He's talking about paging in ROMs, so he doesn't need to flush discarded pages if they never would change. Virtual memory doesn't always equal a "page file", Dr. Windows Guy... Anyway, typically on consoles virtual memory is used to make what would normally be heap allocations contiguous. There's a good chapter on the subject (dealing with arrays) in GPG4.

Not that it does the PSP any good, as there's no conventional MMU.
Back to top
View user's profile Send private message
Dr. Vegetable



Joined: 14 Nov 2005
Posts: 171
Location: Boston, Massachusetts

PostPosted: Wed Nov 30, 2005 12:42 am    Post subject: Reply with quote

Yeah, I realized that he is talking about paging in ROMs which is a different story altogether. The way the question was framed, I thought he was simply looking to allocate more memory than the PSP physically has.

Yikes - I guess 18 years as a Windows programmer have warped my mind. I just didn't realize it was that obvious! How's this:

Code:

/* rough pseudocode compiled only in my micro$oft-addled cranium... */
typedef unsigned int COOKIE;

COOKIE virtual_memory_allocate(size_t number_of_bytes);
void* virtual_memory_lock(COOKIE cookie_to_lock);
void* virtual_memory_lock_read_only(COOKIE cookie_to_lock);
void virtual_memory_unlock(COOKIE cookie_crumb);
void virtual_memory_free(COOKIE cookie_gone_stale);

COOKIE monster = virtual_memory_allocate(sizeof(someStruct));
someStruct* p = (someStruct*)virtual_memory_lock_read_only(monster);
if (p)
{
     /* access the structure using pointer 'p' here...  */

     /* ...when finished using the structure: */
     virtual_memory_unlock(monster);
     /* NOTE: since 'monster' was only locked "read only", it doesn't
         need to be paged back to flash. */
}

virtual_memory_free(monster);

/*  ;-)  */


(This doesn't really solve his original problem, either. I should just crawl back into my Windows box and shut up.)

But if he's emulating another console, couldn't he also emulate an MMU? I'm not saying it would be fast, but at least possible?
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger
AnonymousTipster



Joined: 01 Jul 2005
Posts: 197

PostPosted: Wed Nov 30, 2005 7:32 pm    Post subject: Reply with quote

Is it actually feasible to write to the memory stick this often? When saving a 480x272 sized image, it takes about 6+ seconds, which makes using the standard fopen() functions unusable, because they are too slow. Is there a faster way to write to the memory stick, in order to swap files above 1mb in under a second?
Reading a file seems fast enough, but writing seems very slow.


Last edited by AnonymousTipster on Mon Dec 05, 2005 7:33 am; edited 1 time in total
Back to top
View user's profile Send private message
pspd3vil



Joined: 28 Nov 2005
Posts: 5
Location: France

PostPosted: Wed Nov 30, 2005 9:19 pm    Post subject: Reply with quote

Hi thanks for all answer but i've found teh user manual for Mips R4000 and R4400 and on it you can see all info about the MMU , virtual addr ,virtual memory ,ect..... .

Now i need to understand why a psp cant use it thank's .

you can get it here :

http://cag.csail.mit.edu/raw/documents/R4400_Uman_book_Ed2.pdf
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Wed Nov 30, 2005 10:05 pm    Post subject: Reply with quote

pspd3vil wrote:
Hi thanks for all answer but i've found teh user manual for Mips R4000 and R4400 and on it you can see all info about the MMU , virtual addr ,virtual memory ,ect..... .

The PSP's ALLEGREX CPU is not a R4000. You have Sony marketing drones to thank for the confusion. The ALLEGREX does not have a MMU, but instead has some freakish memory mapping hardware that doesn't allow you to do virtual memory. All in the interest of saving silicon, I suppose.
Back to top
View user's profile Send private message
pspd3vil



Joined: 28 Nov 2005
Posts: 5
Location: France

PostPosted: Wed Nov 30, 2005 10:25 pm    Post subject: Reply with quote

Thx mrbrown and bad new :( .
Back to top
View user's profile Send private message Send e-mail Yahoo Messenger
siso



Joined: 22 Sep 2005
Posts: 7

PostPosted: Mon Dec 05, 2005 5:14 am    Post subject: Reply with quote

Hi, but the project is dead? The cps1 system is very good!!!!
Back to top
View user's profile Send private message
sherpya



Joined: 03 Oct 2005
Posts: 61

PostPosted: Tue Dec 06, 2005 10:18 am    Post subject: Reply with quote

does psp have mmap ? then a large file can be used as read/write operation as in real memory
Back to top
View user's profile Send private message
groepaz



Joined: 01 Sep 2005
Posts: 305

PostPosted: Tue Dec 06, 2005 3:37 pm    Post subject: Reply with quote

and without a MMU mmap would work how? o_O
_________________
http://www.hitmen-console.org
http://hitmen.c02.at/files/yapspd/
Back to top
View user's profile Send private message Visit poster's website
sherpya



Joined: 03 Oct 2005
Posts: 61

PostPosted: Wed Dec 21, 2005 6:42 am    Post subject: Reply with quote

groepaz wrote:
and without a MMU mmap would work how? o_O

dunno maybe an ugly emulation ? :)
Back to top
View user's profile Send private message
siso



Joined: 22 Sep 2005
Posts: 7

PostPosted: Wed Dec 21, 2005 5:57 pm    Post subject: Reply with quote

Why? The cps1 has more interesting games
Back to top
View user's profile Send private message
Sharkus



Joined: 19 Jun 2005
Posts: 27

PostPosted: Sat Mar 25, 2006 3:53 am    Post subject: Reply with quote

Couldn't you "emulate" read only virtual memory (i.e. ROMS) with the following:

- Create a memory pool outside of the PSP address space
- Create an exception handler for bus errors (data)
- When this area is accessed, an exception will occur, the exception handler looks at the badvaddr, pulls the value from a cache in ram (or mem stick if location is not currently cached in memory), loads the value into the appropriate register, jumps back to main code

This of course would cause an exception to happen for each memory access.

-Sharkus
Back to top
View user's profile Send private message
BlackDiamond



Joined: 02 Jul 2005
Posts: 16
Location: Paris, FRANCE

PostPosted: Sat Mar 25, 2006 5:14 am    Post subject: Reply with quote

End then you'll need to use kernel mode and say goodbye to 2.00+ psps. I don't really care myself, but a lot of people do and it's something to consider if you like you're emulator to be 'popular'.
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Sat Mar 25, 2006 5:26 am    Post subject: Reply with quote

Not even considering how truely awful the performace would be :)
Back to top
View user's profile Send private message
Gary13579



Joined: 15 Aug 2005
Posts: 93

PostPosted: Sun Mar 26, 2006 1:02 pm    Post subject: Reply with quote

AnonymousTipster wrote:
Is it actually feasible to write to the memory stick this often? When saving a 480x272 sized image, it takes about 6+ seconds, which makes using the standard fopen() functions unusable, because they are too slow. Is there a faster way to write to the memory stick, in order to swap files above 1mb in under a second?
Reading a file seems fast enough, but writing seems very slow.

I know it's a bit late...
but tests have shown that the sceIoOpen, sceIoWrite, and sceIoClose functions are faster then the fopen/fwrite/fclose functions.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group