<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:΢ÈíÑźÚ
}
--></style></head>
<body class='hmmessage'><div dir='ltr'>
Hi:<BR> <BR> the SWI is used for system APIs such as open, read, write. user mode applications call system APIs via SWI, which will change ARM mode from USER to SVC.<BR> so when vector_swi is called, Linux will do as below:<BR> 1. store r0~r12, these registers are universal for USR mode SVC mode.<BR> 2. store r13 and r14 of USER mode. Note, SWI is triggered from USER mode, so here Linux store USER mode's r13 and r14, rather than SVC's.<BR> <BR> for your two questions: <BR> 1. the ^ means to get USER mode registers, rather than current mode.<br> 2. no matter how you arrange registers in opcode {}, stmdb will always push lr first, then sp. so after line 348, the stack view is as below:<BR>lr_usr<BR>sp_usr<BR>r12<BR>...<BR>r0<BR> <BR> <BR><div><div id="SkyDrivePlaceholder"></div>> Date: Thu, 16 Feb 2012 19:35:17 -0700<br>> Subject: Re: arm assembly doubt<br>> From: subingangadharan@gmail.com<br>> To: suren@gatech.edu<br>> CC: kernelnewbies@kernelnewbies.org<br>> <br>> Thanks for the answer. Actually this is what I am trying to understand.<br>> <br>> ENTRY(vector_swi)<br>> 345 sub sp, sp, #S_FRAME_SIZE<br>> 346 stmia sp, {r0 - r12} @ Calling r0 - r12<br>> 347 ARM( add r8, sp, #S_PC )<br>> 348 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr<br>> 349 THUMB( mov r8, sp )<br>> 350 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr<br>> 351 mrs r8, spsr @ called from<br>> non-FIQ mode, so ok.<br>> 352 str lr, [sp, #S_PC] @ Save calling PC<br>> 353 str r8, [sp, #S_PSR] @ Save CPSR<br>> 354 str r0, [sp, #S_OLD_R0]<br>> <br>> In this case after the line number 348(if its in arm mode),will the<br>> kernel stack have the contents<br>> r0-r12,sp,lr in this order or r0-r12,lr,sp this one. Beccause I<br>> believe stmdb r8, {sp, lr}^ will push the sp first then lr. In that<br>> case sp and lr will be interchanged in struct pt_regs.<br>> <br>> Please correct me if I am wrong.<br>> <br>> <br>> <br>> <br>> <br>> On Wed, Feb 15, 2012 at 9:34 PM, Surenkumar Nihalani <suren@gatech.edu> wrote:<br>> > Hi,<br>> > On Feb 15, 2012, at 11:30 PM, subin gangadharan wrote:<br>> ><br>> >> Hi ,<br>> >><br>> >> I am trying to understand how system call is implmented in linux for<br>> >> arm.And I am not that familiar with arm assembly.<br>> >><br>> >> Could any body please help me to understand what exactly this ^ does<br>> >> in this instruction stmdb r8,{sp,lr}^<br>> >><br>> >> --<br>> >> With Regards<br>> >> Subin Gangadharan<br>> >><br>> >> I am not afraid and I am also not afraid of being afraid.<br>> >><br>> >> _______________________________________________<br>> >> Kernelnewbies mailing list<br>> >> Kernelnewbies@kernelnewbies.org<br>> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies<br>> ><br>> > Example:<br>> > LDFMD sp!, {r0-r12, pc}^<br>> > - The ^ qualifier specifies that the CPSR is restored from the SPSR.<br>> > It must be used only from a privileged mode.<br>> ><br>> <br>> <br>> <br>> -- <br>> With Regards<br>> Subin Gangadharan<br>> <br>> I am not afraid and I am also not afraid of being afraid.<br>> <br>> _______________________________________________<br>> Kernelnewbies mailing list<br>> Kernelnewbies@kernelnewbies.org<br>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies<br></div>                                            </div></body>
</html>