* arm assembly doubt
@ 2012-02-16 4:30 subin gangadharan
2012-02-16 4:34 ` Surenkumar Nihalani
0 siblings, 1 reply; 5+ messages in thread
From: subin gangadharan @ 2012-02-16 4:30 UTC (permalink / raw)
To: kernelnewbies
Hi ,
I am trying to understand how system call is implmented in linux for
arm.And I am not that familiar with arm assembly.
Could any body please help me to understand what exactly this ^ does
in this instruction stmdb r8,{sp,lr}^
--
With Regards
Subin Gangadharan
I am not afraid and I am also not afraid of being afraid.
^ permalink raw reply [flat|nested] 5+ messages in thread
* arm assembly doubt
2012-02-16 4:30 arm assembly doubt subin gangadharan
@ 2012-02-16 4:34 ` Surenkumar Nihalani
2012-02-17 2:35 ` subin gangadharan
0 siblings, 1 reply; 5+ messages in thread
From: Surenkumar Nihalani @ 2012-02-16 4:34 UTC (permalink / raw)
To: kernelnewbies
Hi,
On Feb 15, 2012, at 11:30 PM, subin gangadharan wrote:
> Hi ,
>
> I am trying to understand how system call is implmented in linux for
> arm.And I am not that familiar with arm assembly.
>
> Could any body please help me to understand what exactly this ^ does
> in this instruction stmdb r8,{sp,lr}^
>
> --
> With Regards
> Subin Gangadharan
>
> I am not afraid and I am also not afraid of being afraid.
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Example:
LDFMD sp!, {r0-r12, pc}^
- The ^ qualifier specifies that the CPSR is restored from the SPSR.
It must be used only from a privileged mode.
^ permalink raw reply [flat|nested] 5+ messages in thread
* arm assembly doubt
2012-02-16 4:34 ` Surenkumar Nihalani
@ 2012-02-17 2:35 ` subin gangadharan
2012-02-18 13:36 ` 卜弋天
0 siblings, 1 reply; 5+ messages in thread
From: subin gangadharan @ 2012-02-17 2:35 UTC (permalink / raw)
To: kernelnewbies
Thanks for the answer. Actually this is what I am trying to understand.
ENTRY(vector_swi)
345 sub sp, sp, #S_FRAME_SIZE
346 stmia sp, {r0 - r12} @ Calling r0 - r12
347 ARM( add r8, sp, #S_PC )
348 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
349 THUMB( mov r8, sp )
350 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
351 mrs r8, spsr @ called from
non-FIQ mode, so ok.
352 str lr, [sp, #S_PC] @ Save calling PC
353 str r8, [sp, #S_PSR] @ Save CPSR
354 str r0, [sp, #S_OLD_R0]
In this case after the line number 348(if its in arm mode),will the
kernel stack have the contents
r0-r12,sp,lr in this order or r0-r12,lr,sp this one. Beccause I
believe stmdb r8, {sp, lr}^ will push the sp first then lr. In that
case sp and lr will be interchanged in struct pt_regs.
Please correct me if I am wrong.
On Wed, Feb 15, 2012 at 9:34 PM, Surenkumar Nihalani <suren@gatech.edu> wrote:
> Hi,
> On Feb 15, 2012, at 11:30 PM, subin gangadharan wrote:
>
>> Hi ,
>>
>> I am trying to understand how system call is implmented in linux for
>> arm.And I am not that familiar with arm assembly.
>>
>> Could any body please help me to understand what exactly this ^ does
>> in this instruction stmdb r8,{sp,lr}^
>>
>> --
>> With Regards
>> Subin Gangadharan
>>
>> I am not afraid and I am also not afraid of being afraid.
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
> Example:
> ? ? ? ?LDFMD sp!, {r0-r12, pc}^
> - The ^ qualifier specifies that the CPSR is restored from the SPSR.
> ? It must be used only from a privileged mode.
>
--
With Regards
Subin Gangadharan
I am not afraid and I am also not afraid of being afraid.
^ permalink raw reply [flat|nested] 5+ messages in thread
* arm assembly doubt
2012-02-17 2:35 ` subin gangadharan
@ 2012-02-18 13:36 ` 卜弋天
2012-02-18 16:44 ` subin gangadharan
0 siblings, 1 reply; 5+ messages in thread
From: 卜弋天 @ 2012-02-18 13:36 UTC (permalink / raw)
To: kernelnewbies
Hi: 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. so when vector_swi is called, Linux will do as below: 1. store r0~r12, these registers are universal for USR mode SVC mode. 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. for your two questions: 1. the ^ means to get USER mode registers, rather than current mode.
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:lr_usrsp_usrr12...r0 > Date: Thu, 16 Feb 2012 19:35:17 -0700
> Subject: Re: arm assembly doubt
> From: subingangadharan at gmail.com
> To: suren at gatech.edu
> CC: kernelnewbies at kernelnewbies.org
>
> Thanks for the answer. Actually this is what I am trying to understand.
>
> ENTRY(vector_swi)
> 345 sub sp, sp, #S_FRAME_SIZE
> 346 stmia sp, {r0 - r12} @ Calling r0 - r12
> 347 ARM( add r8, sp, #S_PC )
> 348 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
> 349 THUMB( mov r8, sp )
> 350 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
> 351 mrs r8, spsr @ called from
> non-FIQ mode, so ok.
> 352 str lr, [sp, #S_PC] @ Save calling PC
> 353 str r8, [sp, #S_PSR] @ Save CPSR
> 354 str r0, [sp, #S_OLD_R0]
>
> In this case after the line number 348(if its in arm mode),will the
> kernel stack have the contents
> r0-r12,sp,lr in this order or r0-r12,lr,sp this one. Beccause I
> believe stmdb r8, {sp, lr}^ will push the sp first then lr. In that
> case sp and lr will be interchanged in struct pt_regs.
>
> Please correct me if I am wrong.
>
>
>
>
>
> On Wed, Feb 15, 2012 at 9:34 PM, Surenkumar Nihalani <suren@gatech.edu> wrote:
> > Hi,
> > On Feb 15, 2012, at 11:30 PM, subin gangadharan wrote:
> >
> >> Hi ,
> >>
> >> I am trying to understand how system call is implmented in linux for
> >> arm.And I am not that familiar with arm assembly.
> >>
> >> Could any body please help me to understand what exactly this ^ does
> >> in this instruction stmdb r8,{sp,lr}^
> >>
> >> --
> >> With Regards
> >> Subin Gangadharan
> >>
> >> I am not afraid and I am also not afraid of being afraid.
> >>
> >> _______________________________________________
> >> Kernelnewbies mailing list
> >> Kernelnewbies at kernelnewbies.org
> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
> >
> > Example:
> > LDFMD sp!, {r0-r12, pc}^
> > - The ^ qualifier specifies that the CPSR is restored from the SPSR.
> > It must be used only from a privileged mode.
> >
>
>
>
> --
> With Regards
> Subin Gangadharan
>
> I am not afraid and I am also not afraid of being afraid.
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120218/ba921841/attachment.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* arm assembly doubt
2012-02-18 13:36 ` 卜弋天
@ 2012-02-18 16:44 ` subin gangadharan
0 siblings, 0 replies; 5+ messages in thread
From: subin gangadharan @ 2012-02-18 16:44 UTC (permalink / raw)
To: kernelnewbies
Hi ,
Thanks alot for sharing the information.
2012/2/18 ??? <buyit@live.cn>:
> Hi:
>
> 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.
> so when vector_swi is called, Linux will do as below:
> 1. store r0~r12, these registers are universal for USR mode SVC mode.
> 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.
>
> for your two questions:
> 1. the ^ means to get USER mode registers, rather than current mode.
> 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:
> lr_usr
> sp_usr
> r12
> ...
> r0
This is where I really got confused,I was thinking sp will be pushed
first in that case stack view will be completely different. However
the system is working fine,so was sure there is some secret behind
this instruction.Thanks for revealing this mystery.
>
>> Date: Thu, 16 Feb 2012 19:35:17 -0700
>> Subject: Re: arm assembly doubt
>> From: subingangadharan at gmail.com
>> To: suren at gatech.edu
>> CC: kernelnewbies at kernelnewbies.org
>
>>
>> Thanks for the answer. Actually this is what I am trying to understand.
>>
>> ENTRY(vector_swi)
>> 345 sub sp, sp, #S_FRAME_SIZE
>> 346 stmia sp, {r0 - r12} @ Calling r0 - r12
>> 347 ARM( add r8, sp, #S_PC )
>> 348 ARM( stmdb r8, {sp, lr}^ ) @ Calling sp, lr
>> 349 THUMB( mov r8, sp )
>> 350 THUMB( store_user_sp_lr r8, r10, S_SP ) @ calling sp, lr
>> 351 mrs r8, spsr @ called from
>> non-FIQ mode, so ok.
>> 352 str lr, [sp, #S_PC] @ Save calling PC
>> 353 str r8, [sp, #S_PSR] @ Save CPSR
>> 354 str r0, [sp, #S_OLD_R0]
>>
>> In this case after the line number 348(if its in arm mode),will the
>> kernel stack have the contents
>> r0-r12,sp,lr in this order or r0-r12,lr,sp this one. Beccause I
>> believe stmdb r8, {sp, lr}^ will push the sp first then lr. In that
>> case sp and lr will be interchanged in struct pt_regs.
>>
>> Please correct me if I am wrong.
>>
>>
>>
>>
>>
>> On Wed, Feb 15, 2012 at 9:34 PM, Surenkumar Nihalani <suren@gatech.edu>
>> wrote:
>> > Hi,
>> > On Feb 15, 2012, at 11:30 PM, subin gangadharan wrote:
>> >
>> >> Hi ,
>> >>
>> >> I am trying to understand how system call is implmented in linux for
>> >> arm.And I am not that familiar with arm assembly.
>> >>
>> >> Could any body please help me to understand what exactly this ^ does
>> >> in this instruction stmdb r8,{sp,lr}^
>> >>
>> >> --
>> >> With Regards
>> >> Subin Gangadharan
>> >>
>> >> I am not afraid and I am also not afraid of being afraid.
>> >>
>> >> _______________________________________________
>> >> Kernelnewbies mailing list
>> >> Kernelnewbies at kernelnewbies.org
>> >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>> >
>> > Example:
>> > LDFMD sp!, {r0-r12, pc}^
>> > - The ^ qualifier specifies that the CPSR is restored from the SPSR.
>> > It must be used only from a privileged mode.
>> >
>>
>>
>>
>> --
>> With Regards
>> Subin Gangadharan
>>
>> I am not afraid and I am also not afraid of being afraid.
>>
>> _______________________________________________
>> Kernelnewbies mailing list
>> Kernelnewbies at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
--
With Regards
Subin Gangadharan
I am not afraid and I am also not afraid of being afraid.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-02-18 16:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-16 4:30 arm assembly doubt subin gangadharan
2012-02-16 4:34 ` Surenkumar Nihalani
2012-02-17 2:35 ` subin gangadharan
2012-02-18 13:36 ` 卜弋天
2012-02-18 16:44 ` subin gangadharan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).