On 04/05/16 16:31, Segher Boessenkool wrote:
Can you explain further? The v2 patch uses a single register marked as clobber for mflr/mtlr and the volatile modifier for __context ensures that the old value being written to the stack doesn't get optimised away by the compiler. What else am I missing?
A normal (ABI-following) function can clobber all of r9..r12, so that "bl" instruction can, too. If the function it calls is special (so at least written as assembler), things are different of course.
Right, we're talking about this section of code in the caller:
asm __volatile__ ("mflr %%r9\n\t" "stw %%r9, %0\n\t" "bl __switch_context\n\t" "lwz %%r9, %0\n\t" "mtlr %%r9\n\t" : "=m" (lr) : "m" (lr) : "%r9" );
The mflr/mtlr are being used to preserve the original link register before branching to the assembler routine at __switch_context which does all the hard work.
ATB,
Mark.