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 

ctc0 and cfc0

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



Joined: 24 Mar 2008
Posts: 140

PostPosted: Wed Dec 16, 2009 6:34 am    Post subject: ctc0 and cfc0 Reply with quote

what do those opcodes do?

the very first instruction executed by the psp when turned on is

0xBFC00000: 0x40C22000 '. .@' - ctc0 $v0, $4

what does it mean?
any help is appreciated
_________________
Ciao! from Italy
Back to top
View user's profile Send private message
sauron_le_noir



Joined: 05 Jul 2008
Posts: 229

PostPosted: Wed Dec 16, 2009 7:23 am    Post subject: Reply with quote

CTC0 is a COP0 control register

COP0:
MFC0(010000:00000:rt:c0dr:00000:000000)
CFC0(010000:00010:rt:c0cr:00000:000000)
MTC0(010000:00100:rt:c0dr:00000:000000)
CTC0(010000:00110:rt:c0cr:00000:000000)

look at : http://www.gp32x.com/board/index.php?/topic/47270-pandora-psp/page__st__135__p__720831&#entry720831

ask hlide
Back to top
View user's profile Send private message Send e-mail MSN Messenger
phobox



Joined: 24 Mar 2008
Posts: 140

PostPosted: Thu Dec 17, 2009 1:59 am    Post subject: Reply with quote

Well does it mean that it copies value from general purpose register $v0 to CP0 control register $4?

but.. since this is the very first instruction executed... what value is contained in $v0??


and then.. what is the meaning of control register $4? where can i find a list of all functions?
_________________
Ciao! from Italy
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Thu Dec 17, 2009 7:52 pm    Post subject: Reply with quote

when calling an interrupt/exception handler, psp uses to save $v0 and $v1 into COP0 $4 and $5(not sure for it) so the handler can use $v0 and $v1 for temporary need. At the end of the handler, it restores original values of $v0 and $v1 through those both COP0 registers.

Normally MIPS uses $k0 and $k1 for this purpose. But psp firmware choses to use them for another purpose.
Back to top
View user's profile Send private message
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Thu Dec 17, 2009 10:53 pm    Post subject: Reply with quote

And what's the purpose of $k0 and $k1 on PSP firmware if I may ask?
_________________
The Incredible Bill Gates wrote:
The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Back to top
View user's profile Send private message
phobox



Joined: 24 Mar 2008
Posts: 140

PostPosted: Fri Dec 18, 2009 3:39 am    Post subject: Reply with quote

thanks for the info,
but

ctc0 $v0 $4 means copy data FROM $v0 to $4 right?, but this is the first instruction executed by the psp (the first instruction of the preipl).. how is it possible to copy v0 to $4? what is it stored in v0?

is the $4 the register that in standard MIPS R4000 processor is used for the TLB ? (which is not implemented in Allegrex)
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Sun Dec 20, 2009 4:49 am    Post subject: Reply with quote

@m0skit0:

$k0 and $k1 : kernel registers - those registers used to be reserved by the an OS as temporary save/restore registers in a interrupt/exception handler. PSP firmware uses them for another purpose : $k0, something like KTLS probably (not sure about it as i don't care about) and $k1 to contain special flags for access protection when calling a kernel firmware function.

@phobox:
don't be confused : ctc0 is not mtc0, both don't use the same COP0 register set. cfc0/ctc0 is for moving from/to one register of the second COP0 registers set. Those registers are specifical to PSP indeed. Whereas the first set (through mfc0/mtc0) is almost compatible with the standard MIPS R4000 COP0. One point : there is no MMU, i.e, no TLB in Allegrex (PSP processor) so those TBL registers you're refering are not implemented.
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Sun Dec 20, 2009 5:04 am    Post subject: Reply with quote

phobox wrote:
but this is the first instruction executed by the psp (the first instruction of the preipl).. how is it possible to copy v0 to $4? what is it stored in v0?


ok, you don't know how the hardware of a processor runs.

When resetting, you call a interrupt handler. Under a very specific condition, when setting a special bit, you can initiate this preipl handler (it's just an interrupt). I guess the programmer codes it as a generic handler : you need to save some registers before running an asynchronous code then restore them at the end. In psp firmware, they choose to save register $v0 and $v1 (instead using $k0 and$k1) into two special COP0 registers so they can use $v0 and $v1 as temporary registers in the handler. At the end of your generic interrupt handler, you must restore the original $v0 and $v1.

You don't understand ? ok, let's consider an hardware timer : you configure a period so the timer will issue a call to the timer interrupt handler. As it can occur at any place of your running code, you cannot let the interrupts to scratch the registers. But the issue is the handler also needs some temporary registers to execute its tasks so you need to save some registers and then restore them at the end so it can retrieve the original values in the registers when resuming the interrupted code.
Back to top
View user's profile Send private message
m0skit0



Joined: 02 Jun 2009
Posts: 226

PostPosted: Sun Dec 20, 2009 10:41 am    Post subject: Reply with quote

I knew what the MIPS standard said about it, but not what PSP firmware used them for. Thanks for info.
_________________
The Incredible Bill Gates wrote:
The obvious mathematical breakthrough would be development of an easy way to factor large prime numbers.
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Tue Dec 22, 2009 5:08 am    Post subject: Reply with quote

m0skit0 wrote:
I knew what the MIPS standard said about it, but not what PSP firmware used them for. Thanks for info.

yeah, i realised too late. But let's say it might be instructive for other people ;).
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