Tuesday, August 27, 2019

Re: boost md context switching on macppc

On Tue, 27 Aug 2019 14:30:50 +0200
Otto Moerbeek <otto@drijf.net> wrote:

> What I'm seeing is (in jump_ppc32_sysv_elf_gas.S/jump_context)
> register r3 that is supposed to point to the memory that will receive
> the transfer_t (the return value of jump_fcontext()) is 0.
>
> # return transfer_t
> stw %r6, 0(%r3)
> stw %r5, 4(%r3)

Ouch. This code is for Linux; there is a secret incompatibility
between BSD and Linux on 32-bit PowerPC. These systems have almost
the same System V ABI, but differ when returning a small struct of up
to 8 bytes. transfer_t from <boost/context/detail/fcontext.hpp> is
such a struct: its 2 pointers measure 8 bytes. BSD has no return area
in %r3; the callee should return the transfer_t in %r3 and %r4. The
params were in %r4 and %r5 in Linux, but are in %r3 and %r4 in BSD.

The fixes might be to

- delete the lines `stw %r3, 228(%r1)` and `lwz %r3, 228(%r1)`,
because the return area no longer exists.
- change `mr %r1, %r4` to `mr %r1, %r3`, because first param is %r3.
- change `stw %r6, 0(%r3)` to `mr %r3, %r6` (move to %r3 from %r6),
because first word of transfer_t is %r3.
- delete `stw %r5, 4(%r3)`, because second param is %r4, and second
word of transfer_t is %r4, so we would move %r4 to itself.

One might guard the changes with #ifdef __Linux__ ... #else ...

No comments:

Post a Comment