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 

User mode ASM sceKernelDcacheWritebackInvalidateAll

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



Joined: 08 Apr 2006
Posts: 6

PostPosted: Thu Nov 16, 2006 9:37 am    Post subject: User mode ASM sceKernelDcacheWritebackInvalidateAll Reply with quote

Whilst trying to get the TIFF's more reliable for eLoader, we worked on getting an assembly version of sceKernelDcacheWritebackInvalidateAll and based on this thread http://forums.ps2dev.org/viewtopic.php?t=6317&highlight=cache, we determined that it should be possible to do the functionality that we required in user mode. We found that in sceKernelDcacheInvalidateAll the only thing that would not work in user mode was getting the size of the cache, therefore we need to hardcode this in the procedure. This is what we ended up using as a basis for the new tiff:

Code:
void asmKernelDcacheWritebackInvalidateAll(void)
{
   asm(".set    noreorder\n"
      "move      $t0,  $0\n"
      "addiu     $t1,  $0, 0x4000\n"
      "loop:\n"
      "cache     0x14, 0($t0)\n"
      "addiu     $t0,  $t0, 0x40\n"
      "bne       $t0,  $t1, loop\n"
      "cache     0x14, -0x40($t0)\n"
      "sync");
}


The above code should be able to run on all firmwares and makes life easier when you do not have syscalls available, but you need to clear the cache. I would expect that the same could be done very easily with icache.



Chris


Last edited by cswindle on Fri Nov 17, 2006 5:36 pm; edited 1 time in total
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Thu Nov 16, 2006 5:10 pm    Post subject: Reply with quote

why do you need to invalidate twice a cache entry at each iteration ?
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Thu Nov 16, 2006 10:23 pm    Post subject: Re: User mode ASM version of sceKernelDcacheInvalidateAll Reply with quote

Can you explain why you need to invalidate all d-cache entries for you TIFF loader ? I dunno if you TIFF loader uses stack overflow but what you need in fact is to WRITEBACK d-cache (overflow stack being in d-cache) then to INVALIDATE i-cache so you can run instructions poked in the stack.

If you only invalidate (that is without writeback) some data modified in d-cache would not be written back to real memory and arises some incoherencies when trying to run them.

On the contrary, if you only need to be sure that d-cache contents are written back to real memory simple d-cache writebacks can be done instead of invalidating them too. the code is : "cache 0x1A, 0($t0)", if i'm not wrong.

Maybe what you want to do is :
Code:

void asmKernelSyncICacheAndDcache(void)
{
   asm(
      ".set push\n"
      ".set noreorder\n"
      "move $t0, $0\n"
      "addiu $t1, $0, 0x4000\n"
      "0:\n" // avoid to name loop if you plan to inline this function
      "cache 0x1a, 0($t0)\n" // D-cache writeback
      "addiu $t0, $t0, 0x40\n"
      "bne $t0, $t1, 0b\n"
      "cache 0x08, -0x40($t0)\n" // I-cache invalidate
      "sync\n" // reason to do so ?
      ".set pop"
   );
}
Back to top
View user's profile Send private message
jonny



Joined: 22 Sep 2005
Posts: 351

PostPosted: Thu Nov 16, 2006 11:33 pm    Post subject: Reply with quote

hlide wrote:
why do you need to invalidate twice a cache entry at each iteration ?


i suppose it's because the cache is 2-way set associative
Back to top
View user's profile Send private message Visit poster's website
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Fri Nov 17, 2006 12:40 am    Post subject: Reply with quote

jonny wrote:
hlide wrote:
why do you need to invalidate twice a cache entry at each iteration ?


i suppose it's because the cache is 2-way set associative


okay, I think I can understand why now. I thought a cache instruction would affect ALL candidates and not only the FIRST candidate. But I do remember now to have seen an assembly code where cache instructions were executed twice and I was wondering why. It makes sense, you cannot simultaneously write back two entries having the same index in the main memory. Thx for this piece of information, I probably need to update my codes with this fact.
Back to top
View user's profile Send private message
cswindle



Joined: 08 Apr 2006
Posts: 6

PostPosted: Fri Nov 17, 2006 5:46 pm    Post subject: Re: User mode ASM version of sceKernelDcacheInvalidateAll Reply with quote

hlide wrote:
Can you explain why you need to invalidate all d-cache entries for you TIFF loader ? I dunno if you TIFF loader uses stack overflow but what you need in fact is to WRITEBACK d-cache (overflow stack being in d-cache) then to INVALIDATE i-cache so you can run instructions poked in the stack.
It was meant to be sceKernelDcacheWritebackInvalidateAll (I have updated the main post). As far as clearing the i-cache, there was no need for us to clear the cache because of the way we were using it.


Chris
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