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 

How user mode program make a system call

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



Joined: 20 Oct 2005
Posts: 2

PostPosted: Thu Oct 20, 2005 3:17 am    Post subject: How user mode program make a system call Reply with quote

I am a newbie with psp programming.
After checking the kernal library implementation, I found all the entry stub of system call is replace as 03e00008 jr ra. I am really confused how the system call is made.
Hope some one here can give me the answer. Thanks.
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Thu Oct 20, 2005 3:53 am    Post subject: Reply with quote

The PSP's kernel fixes up the system calls according to the import definitions present in the executable at load time. You really shouldn't need to worry about it for the most part as the psp kernel and pspsdk handle it all for you.

If you must know more then load a program and dump the instructions (which in the ELF was just jr $ra) to a file on the ms and disassemble them, you will then see the actual syscall instructions.
Back to top
View user's profile Send private message
Fanjita



Joined: 28 Sep 2005
Posts: 217

PostPosted: Thu Oct 20, 2005 8:26 pm    Post subject: Reply with quote

You're probably being confused by the way the MIPS processor handles jump instructions.

Basically, it will always execute the next instruction following the jump, before making the jump itself.

So, you'll probably find that the entry stub really looks like this:

jr $ra
sycall 0xnnnn

which will actually execute the syscall before the jump takes effect.

It's really confusing the first few times you see it, then you get used to it.

If I remember right then branch instructions do the same thing.
Back to top
View user's profile Send private message
li__paul



Joined: 20 Oct 2005
Posts: 2

PostPosted: Fri Oct 21, 2005 12:53 am    Post subject: Thanks for your replies Reply with quote

After reading your explanation about load time fixup and misp jump instruction, I still have some questions.

At the link time the import stub of system call looks like:
jr ra
nop

The psp system loader will do the load time fixup and change the stub to what looks like:
jr ra
system call

If the system call is put in the defer slot of the return instruction jr ra, it means that the system call is made and the control returns to the caller at the same time.

But I think the control should not return to caller until the system call is completed. Another thing is that the control transfer instruction usually should not be put in jump instruction's defer slot.
Back to top
View user's profile Send private message
Fanjita



Joined: 28 Sep 2005
Posts: 217

PostPosted: Fri Oct 21, 2005 3:34 am    Post subject: Reply with quote

The final resolution of the jump call, and setting of $PC to the destination address, only happens after the defer slot instruction is completed.

So you don't get the syscall and the JR happening at the same time - they're executed in order, it's just that the order is the opposite to what you'd think when looking at the disassembly naively.

It does seem odd (and confusing) that syscalls are used in the defer slot, but it does work and it's just the way that things are done.
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