1/* 2 Copyright Oliver Kowalke 2009. 3 Distributed under the Boost Software License, Version 1.0. 4 (See accompanying file LICENSE_1_0.txt or copy at 5 http://www.boost.org/LICENSE_1_0.txt) 6*/ 7 8/******************************************************* 9 * * 10 * ------------------------------------------------- * 11 * | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | * 12 * ------------------------------------------------- * 13 * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | * 14 * ------------------------------------------------- * 15 * | TOC | R14 | R15 | R16 | * 16 * ------------------------------------------------- * 17 * ------------------------------------------------- * 18 * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | * 19 * ------------------------------------------------- * 20 * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | * 21 * ------------------------------------------------- * 22 * | R17 | R18 | R19 | R20 | * 23 * ------------------------------------------------- * 24 * ------------------------------------------------- * 25 * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | * 26 * ------------------------------------------------- * 27 * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | * 28 * ------------------------------------------------- * 29 * | R21 | R22 | R23 | R24 | * 30 * ------------------------------------------------- * 31 * ------------------------------------------------- * 32 * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | * 33 * ------------------------------------------------- * 34 * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | * 35 * ------------------------------------------------- * 36 * | R25 | R26 | R27 | R28 | * 37 * ------------------------------------------------- * 38 * ------------------------------------------------- * 39 * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | * 40 * ------------------------------------------------- * 41 * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | * 42 * ------------------------------------------------- * 43 * | R29 | R30 | R31 | hidden | * 44 * ------------------------------------------------- * 45 * ------------------------------------------------- * 46 * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | * 47 * ------------------------------------------------- * 48 * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | * 49 * ------------------------------------------------- * 50 * | CR | LR | PC | back-chain| * 51 * ------------------------------------------------- * 52 * ------------------------------------------------- * 53 * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | * 54 * ------------------------------------------------- * 55 * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | * 56 * ------------------------------------------------- * 57 * | cr saved | lr saved | compiler | linker | * 58 * ------------------------------------------------- * 59 * ------------------------------------------------- * 60 * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | * 61 * ------------------------------------------------- * 62 * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | * 63 * ------------------------------------------------- * 64 * | TOC saved | FCTX | DATA | | * 65 * ------------------------------------------------- * 66 * * 67 *******************************************************/ 68 69 .file "make_ppc64_sysv_xcoff_gas.S" 70 .toc 71 .csect .text[PR], 5 72 .align 2 73 .globl make_fcontext[DS] 74 .globl .make_fcontext 75 .csect make_fcontext[DS], 3 76make_fcontext: 77 .llong .make_fcontext[PR], TOC[tc0], 0 78 .csect .text[PR], 5 79.make_fcontext: 80 # save return address into R6 81 mflr 6 82 83 # first arg of make_fcontext() == top address of context-function 84 # shift address in R3 to lower 16 byte boundary 85 clrrdi 3, 3, 4 86 87 # reserve space for context-data on context-stack 88 # including 64 byte of linkage + parameter area (R1 % 16 == 0) 89 subi 3, 3, 248 90 91 # third arg of make_fcontext() == address of context-function descriptor 92 ld 4, 0(5) 93 std 4, 176(3) 94 # save TOC of context-function 95 ld 4, 8(5) 96 std 4, 0(3) 97 98 # set back-chain to zero 99 li 0, 0 100 std 0, 184(3) 101 102 # zero in r3 indicates first jump to context-function 103 std 0, 152(3) 104 105 # load LR 106 mflr 0 107 # jump to label 1 108 bl .Label 109.Label: 110 # load LR into R4 111 mflr 4 112 # compute abs address of label .L_finish 113 addi 4, 4, .L_finish - .Label 114 # restore LR 115 mtlr 0 116 # save address of finish as return-address for context-function 117 # will be entered after context-function returns 118 std 4, 168(3) 119 120 # restore return address from R6 121 mtlr 6 122 123 blr # return pointer to context-data 124 125.L_finish: 126 # save return address into R0 127 mflr 0 128 # save return address on stack, set up stack frame 129 std 0, 8(1) 130 # allocate stack space, R1 % 16 == 0 131 stdu 1, -32(1) 132 133 # exit code is zero 134 li 3, 0 135 # exit application 136 bl ._exit 137 nop 138