linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Is it possible to call a C function in transfer_to_handler(arch/ppc/kernel/entry.S)?
       [not found] <200705281730.39257.wangbj@lzu.edu.cn>
@ 2007-05-28  9:30 ` Wang, Baojun
  2007-05-28 15:25   ` Nicholas Mc Guire
  2007-05-28 11:28 ` Paul Mackerras
  1 sibling, 1 reply; 3+ messages in thread
From: Wang, Baojun @ 2007-05-28  9:30 UTC (permalink / raw)
  To: ppc-dev; +Cc: Nicholas McGuire

[-- Attachment #1: Type: text/plain, Size: 1885 bytes --]

hi, list

  I'm sorry to ask this topic in this mailling list. I've spend more than 2 
days try to add a C function call in transfer_to_handler(in 
arch/ppc/kernel/entry.S) like this:

/* cut from arch/ppc/kernel/entry.S */
transfer_to_handler:
        stw     r2,GPR2(r11)
        stw     r12,_NIP(r11)
        stw     r9,_MSR(r11)
        andi.   r2,r9,MSR_PR
        mfctr   r12
        mfspr   r2,SPRN_XER
        stw     r12,_CTR(r11)
        stw     r2,_XER(r11)
        mfspr   r12,SPRN_SPRG3
        addi    r2,r12,-THREAD
        tovirt(r2,r2)                   /* set r2 to current */
        beq     2f                      /* if from user, fix up THREAD.regs */
#if 1	/* this is add by me */
        stwu    r1, -16(r1)
        mflr    r0
        stw     r0, 20(r1)
        bl      emulate_iret
        lwz     r0, 20(r1)
        mtlr    r0
        addi    r1, r1, 16
#endif
        addi    r11,r1,STACK_FRAME_OVERHEAD
        stw     r11,PT_REGS(r12)


The function prolog is taken from a userspace program. this code freeze the 
system after prints out `emulate_iret' (The only thing function emulate_iret 
do is print that message). 

I read the source code from head_44x.S to entry.S, sounds like all registers 
(r0-r32, and even more such as _LINK, _CTR, etc..) are being saved, does that 
mean I shouldn't call any C function in transfer_to_handler()? Is there 
something tricky (or is it possible) to add a C function call? 

Thanks in advance!

regards

-- 
Wang, Baojun                                        Lanzhou University
Distributed & Embedded System Lab              http://dslab.lzu.edu.cn
School of Information Science and Engeneering        wangbj@lzu.edu.cn
Tianshui South Road 222. Lanzhou 730000                     .P.R.China
Tel:+86-931-8912025                                Fax:+86-931-8912022

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is it possible to call a C function in transfer_to_handler(arch/ppc/kernel/entry.S)?
       [not found] <200705281730.39257.wangbj@lzu.edu.cn>
  2007-05-28  9:30 ` Is it possible to call a C function in transfer_to_handler(arch/ppc/kernel/entry.S)? Wang, Baojun
@ 2007-05-28 11:28 ` Paul Mackerras
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Mackerras @ 2007-05-28 11:28 UTC (permalink / raw)
  To: Wang, Baojun; +Cc: ppc-dev, Nicholas McGuire

Wang, Baojun writes:

>   I'm sorry to ask this topic in this mailling list. I've spend more than 2 
> days try to add a C function call in transfer_to_handler(in 
> arch/ppc/kernel/entry.S) like this:

It's not going to work, because the MMU is off at this point.  It will
explode as soon as the C code tries to touch any external variable.

Paul.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is it possible to call a C function in transfer_to_handler(arch/ppc/kernel/entry.S)?
  2007-05-28  9:30 ` Is it possible to call a C function in transfer_to_handler(arch/ppc/kernel/entry.S)? Wang, Baojun
@ 2007-05-28 15:25   ` Nicholas Mc Guire
  0 siblings, 0 replies; 3+ messages in thread
From: Nicholas Mc Guire @ 2007-05-28 15:25 UTC (permalink / raw)
  To: Wang, Baojun; +Cc: ppc-dev, Nicholas McGuire

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

>
>  I'm sorry to ask this topic in this mailling list. I've spend more than 2
> days try to add a C function call in transfer_to_handler(in
> arch/ppc/kernel/entry.S) like this:
>

Why are you sorry ? This is what this list is for - and if nobody can
answer it then its good you sent it - thanks !

<snip...>
> #if 1	/* this is add by me */

could you change this to use onle R3-R13 as these are caller safe - My
suspicion i sthat you are using R0/1/2 and that is not healthy here.

>        stwu    r1, -16(r1)
>        mflr    r0
>        stw     r0, 20(r1)
>        bl      emulate_iret
>        lwz     r0, 20(r1)
>        mtlr    r0
>        addi    r1, r1, 16
> #endif
>        addi    r11,r1,STACK_FRAME_OVERHEAD
>        stw     r11,PT_REGS(r12)
>
out of PPC too long - but will see if I can find something.

hofrat
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFGWvR4nU7rXZKfY2oRArQDAJ99xJOrUlqYpPPuJtoqH27lGeDJ9ACeIj97
1bPlGITc1bVMw1V5YmXnG34=
=hvub
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-05-28 17:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <200705281730.39257.wangbj@lzu.edu.cn>
2007-05-28  9:30 ` Is it possible to call a C function in transfer_to_handler(arch/ppc/kernel/entry.S)? Wang, Baojun
2007-05-28 15:25   ` Nicholas Mc Guire
2007-05-28 11:28 ` Paul Mackerras

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).