On 15/07/13 07:58, minux wrote:
On Mon, Jul 15, 2013 at 3:45 AM, Nick Craig-Wood wrote:
0(FP) works very well for accessing the arguments, however I'm having
difficulty accessing the local stack variables.
According to the documentation herehttp://www.vitanuova.com/inferno/papers/asm.html
The first automatic variable should be at 4(SP). However that seems to
refer to the same memory location as 4(FP) which is confusing! What
does appear to work is using 4(R13) for accessing local variables.
Is that correct?
correct. 5l is different in this respect from other linkers (8l/6l)
do refer to the local variable with the lowest address.
I've come to the conclusion that that is probably a bug! If FP == SP
then it breaks the assumptions of assembly code writers by making ARM
different and makes the assembler less convenient to use because the
variable+4(R13) form isn't allowed.
Here is an example from ./pkg/runtime/memmove_arm.s which is only
working by good luck!
TEXT runtime·memmove(SB), 7, $4-12
MOVW to+0(FP), R(TS)
MOVW from+4(FP), R(FROM)
MOVW n+8(FP), R(N)
_b4aligned: /* is source now aligned? */
AND.S $3, R(FROM), R(TMP)
ADD $31, R(TS), R(TMP) /* do 32-byte chunks if possible */
MOVW R(TS), savedts+4(SP) // <------ THIS IS WRONG!
CMP R(TMP), R(TE)
Which disassembles to
3a370: e52de008 str r14, [r13, #-8]!
3a374: e59d000c ldr r0, [r13, #12] // to argument
3a378: e59db010 ldr r11, [r13, #16]
3a37c: e59dc014 ldr r12, [r13, #20]
3a3b0: e21bc003 ands r12, r11, #3
3a3b4: 1a000015 bne 3a410 <runtime.memmove+0xa0>
3a3b8: e280c01f add r12, r0, #31
3a3bc: e58d000c str r0, [r13, #12] // should be #4
3a3c0: e158000c cmp r8, r12
3a3c4: 9a000002 bls 3a3d4 <runtime.memmove+0x64>
It was clearly the intention of the author to save R(TS) in the stack
frame (otherwise why allocate it) but actually it is being saved in the
to argument. In fact the allocated word in the stack frame 4(R13) is
This could be corrected by changing it to this (can't use savedts+ on
(R13) for some reason which is another argument for fixing SP)
MOVW R(TS), 4(R13)
The ARM code seems to use FP and SP interchangeably so a lot of code
would need to be reviewed if this were to be changed.
Anyway if we are stuck with FP == SP then memmove surely needs to be fixed!
Nick Craig-Wood <email@example.com
> -- http://www.craig-wood.com/nick
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firstname.lastname@example.org.
For more options, visit https://groups.google.com/groups/opt_out.