Skip to content

Commit

Permalink
Fixes for Darwin PPC32
Browse files Browse the repository at this point in the history
For make_fcontext, use the diff provided here:

boostorg#211 (comment)

For ontop_context, adapt the Linux PPC32 fixes from here:

boostorg@df8fb6b

Co-authored-by: George Koehler <[email protected]>
  • Loading branch information
evanmiller and kernigh committed Dec 27, 2022
1 parent 5bcc1ab commit 565c3ae
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
1 change: 1 addition & 0 deletions build/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ alias asm_sources
: asm/make_ppc32_sysv_macho_gas.S
asm/jump_ppc32_sysv_macho_gas.S
asm/ontop_ppc32_sysv_macho_gas.S
asm/tail_ppc32_sysv_elf_gas.cpp
: <abi>sysv
<address-model>32
<architecture>power
Expand Down
43 changes: 30 additions & 13 deletions src/asm/make_ppc32_sysv_macho_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,12 @@ _make_fcontext:
clrrwi r3, r3, 4

; reserve space for context-data on context-stack
; including 64 byte of linkage + parameter area (R1 16 == 0)
; including 64 byte of linkage + parameter area (R1 % 16 == 0)
subi r3, r3, 336

; third arg of make_fcontext() == address of context-function
stw r5, 240(r3)
; store as trampoline's R31
stw r5, 224(r3)

; set back-chain to zero
li r0, 0
Expand All @@ -106,12 +107,15 @@ _make_fcontext:
; load LR
mflr r0
; jump to label 1
bl l1
l1:
bcl 20, 31, L1
L1:
; load LR into R4
mflr r4
; compute abs address of trampoline, use as PC
addi r5, r4, lo16(Ltrampoline - L1)
stw r5, 240(r3)
; compute abs address of label finish
addi r4, r4, lo16((finish - .) + 4)
addi r4, r4, lo16(Lfinish - L1)
; restore LR
mtlr r0
; save address of finish as return-address for context-function
Expand All @@ -123,15 +127,28 @@ l1:

blr ; return pointer to context-data

finish:
; save return address into R0
mflr r0
; save return address on stack, set up stack frame
stw r0, 4(r1)
; allocate stack space, R1 16 == 0
stwu r1, -16(r1)
Ltrampoline:
; We get R31 = context-function, R3 = address of transfer_t,
; but we need to pass R3:R4 = transfer_t.
mtctr r31
lwz r4, 4(r3)
lwz r3, 0(r3)
bctr

Lfinish:
; load address of _exit into CTR
bcl 20, 31, L2
L2:
mflr r4
addis r4, r4, ha16(Lexitp - L2)
lwz r4, lo16(Lexitp - L2)(r4)
mtctr r4
; exit code is zero
li r3, 0
; exit application
bl _exit
bctr

.const_data
.align 2
Lexitp:
.long __exit
20 changes: 10 additions & 10 deletions src/asm/ontop_ppc32_sysv_macho_gas.S
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ _ontop_fcontext:
lwz r29, 216(r1) ; restore R29
lwz r30, 220(r1) ; restore R30
lwz r31, 224(r1) ; restore R31
lwz r4, 228(r1) ; restore hidden
lwz r3, 228(r1) ; restore hidden

; restore CR
lwz r0, 232(r1)
Expand All @@ -190,12 +190,12 @@ _ontop_fcontext:
; adjust stack
addi r1, r1, 244

; return transfer_t
stw r7, 0(r4)
stw r5, 4(r4)

; restore CTR
mtctr r6

; jump to ontop-function
bctr
; Need to pass ontop_fcontext_tail(
; hidden R3,
; R4 = ignore,
; R5 = data,
; R6 = ontop-function,
; R7 = fcontext_t
; )
; All of these registers are correctly set at this point
b _ontop_fcontext_tail

0 comments on commit 565c3ae

Please sign in to comment.