> Although I know that the Plan9 compilers and gcc organize
> function calls differently, I thought it would be helpful to
> understand what /sys/src/libc/arm/getcallerpc.s does -
> after having a look at A Manual for the Plan 9 assembler:
> 
>       MOVW    0(R13), R0
>       RET
> 
> Does this mean that it is just returning the contents of the
> first word on the Stack (R13) - and not interpreting &firstarg
> at all?

This appears to be wrong, but I don't have time to dig in.

The pointer is intended to be used on architectures like the x86
that automatically push the return address on the stack.

On architectures that don't push the return address on the 
stack during the call instruction, the caller of getcallerpc
will have saved the desired return address somewhere in
its stack frame, and getcallerpc must root it out.

vc (the MIPS compiler) saves the return PC in the very last
word of the stack frame, so that /sys/src/libc/mips/getcallerpc.s:

        TEXT    getcallerpc(SB), $0
                MOVW    0(SP), R1
                RET

is correct.  

It appears that 5c (the ARM compiler) saves the return PC
as the first word of the stack frame, which may be somewhat
hard to locate.

Russ


Reply via email to