On my box the problem seem to be another...
(gdb) disass get_sp
Dump of assembler code for function get_sp:
0x00010dd8 <get_sp+0>: mov %sp, %i0
0x00010ddc <get_sp+4>: retl
0x00010de0 <get_sp+8>: nop
End of assembler dump.
(gdb)
but doesn't work...
Another way to get SP (maybe more simple) it's get the ARGV[0] of out
program... work fine, but now I would try to undestand why with gcc
3.3.2 doesn't work this function...
Inode
Jonathon Giffin ha scritto:
> My reply is based on my experimentation on my machine; results elsewhere
> may differ.
>
> I don't know why, but 3.3.2 (with no optimization) inserts an extra
> assembly instruction into get_sp:
> save %sp, -112, %sp
> mov %sp,%i0
> mov %g1, %i0
> ret
> restore
>
> The return value gets overwritten with whatever is in %g1. This need not
> be the current pc. The 3.2 compiler does not insert the extra mov
> instruction, so you get the behavior that you expected.
>
> For code that works with both compilers and no optimization, use:
>
> unsigned long get_sp (void)
> {
> __asm__("mov %sp,%g1");
> __asm__("mov %g1,%i0");
> }
>
> If you compile with -O (optimization), then 3.3.2 will not insert the
> extra mov instruction and you can use
>
> unsigned long get_sp (void)
> {
> __asm__("mov %sp,%o0");
> }
>
> with both compilers. Note that the mov destination must be OUTPUT register
> 0 because optimization will produce a leaf function.
>
> Thanks,
>
> Jon
>
>
>
Received on Jan 13 2004