PowerPC assembler question

Benjamin Herrenschmidt benh at kernel.crashing.org
Mon Jun 17 12:55:55 EST 2013


On Sun, 2013-06-16 at 16:30 +1000, Erik de Castro Lopo wrote:
> Been busy, but I'm back looking at this.
> 
> David Laight wrote:
> 
> > With a scratch register there are some two instruction sequences.
> > Reusing the destination register something like:
> >
> > 	addis	%r30,%r31,hi(.label - 1b)
> > 	lwzx	%r30,lo(.label - 1b)(%r30)
> >
> 
> I've managed to convert that into something gcc understands:
> 
> 	addis	30, 31, (.label-(1b))@ha
> 	lwz	30, (.label-(1b))@l(30)
> 
> The "@l" is the equivalent of lo() and "@ha" is the sign extending
> verions of hi(). Unfortunately, this code segfaults on executiion.
> I suspect that is because I have used the LWZ instruction instead
> of LWZX suggested by David.

No, lwz is the right instruction. The above should work, tried
stepping it in something like gdb to see waht exactly is going on ?

lwzx is a form that takes only registers (adds two registers to make
the address to load from). lwz takes a register and an immediate offset.

Cheers,
Ben.


> Unfortunately gcc doesn't accept LWZX which I found documented
> here:
> 
>      http://pds.twi.tudelft.nl/vakken/in101/labcourse/instruction-set/lwzx.html
> 
> and seems to have LX as a synonym, but that instruction only seems
> to work on registers, not on addresses as we have here.
> 
> I'm actually beginning to have a better understanding of the code
> and I've pulled out these snippets code code into a small assember
> program I'm compiling with gcc and running under gdb.
> 
> Cheers,
> Erik




More information about the Linuxppc-dev mailing list