| 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 | * | F14 | F15 | F16 | F17 | *
|
|---|
| 16 | * ------------------------------------------------- *
|
|---|
| 17 | * ------------------------------------------------- *
|
|---|
| 18 | * | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | *
|
|---|
| 19 | * ------------------------------------------------- *
|
|---|
| 20 | * | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | *
|
|---|
| 21 | * ------------------------------------------------- *
|
|---|
| 22 | * | F18 | F19 | F20 | F21 | *
|
|---|
| 23 | * ------------------------------------------------- *
|
|---|
| 24 | * ------------------------------------------------- *
|
|---|
| 25 | * | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | *
|
|---|
| 26 | * ------------------------------------------------- *
|
|---|
| 27 | * | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | *
|
|---|
| 28 | * ------------------------------------------------- *
|
|---|
| 29 | * | F22 | F23 | F24 | F25 | *
|
|---|
| 30 | * ------------------------------------------------- *
|
|---|
| 31 | * ------------------------------------------------- *
|
|---|
| 32 | * | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | *
|
|---|
| 33 | * ------------------------------------------------- *
|
|---|
| 34 | * | 96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 | *
|
|---|
| 35 | * ------------------------------------------------- *
|
|---|
| 36 | * | F26 | F27 | F28 | F29 | *
|
|---|
| 37 | * ------------------------------------------------- *
|
|---|
| 38 | * ------------------------------------------------- *
|
|---|
| 39 | * | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
|
|---|
| 40 | * ------------------------------------------------- *
|
|---|
| 41 | * | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
|
|---|
| 42 | * ------------------------------------------------- *
|
|---|
| 43 | * | F30 | F31 | fpscr | TOC | *
|
|---|
| 44 | * ------------------------------------------------- *
|
|---|
| 45 | * ------------------------------------------------- *
|
|---|
| 46 | * | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | *
|
|---|
| 47 | * ------------------------------------------------- *
|
|---|
| 48 | * | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 | *
|
|---|
| 49 | * ------------------------------------------------- *
|
|---|
| 50 | * | R14 | R15 | R16 | R17 | *
|
|---|
| 51 | * ------------------------------------------------- *
|
|---|
| 52 | * ------------------------------------------------- *
|
|---|
| 53 | * | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | *
|
|---|
| 54 | * ------------------------------------------------- *
|
|---|
| 55 | * | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 | *
|
|---|
| 56 | * ------------------------------------------------- *
|
|---|
| 57 | * | R18 | R19 | R20 | R21 | *
|
|---|
| 58 | * ------------------------------------------------- *
|
|---|
| 59 | * ------------------------------------------------- *
|
|---|
| 60 | * | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | *
|
|---|
| 61 | * ------------------------------------------------- *
|
|---|
| 62 | * | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 | *
|
|---|
| 63 | * ------------------------------------------------- *
|
|---|
| 64 | * | R22 | R23 | R24 | R25 | *
|
|---|
| 65 | * ------------------------------------------------- *
|
|---|
| 66 | * ------------------------------------------------- *
|
|---|
| 67 | * | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | *
|
|---|
| 68 | * ------------------------------------------------- *
|
|---|
| 69 | * | 256 | 260 | 264 | 268 | 272 | 276 | 280 | 284 | *
|
|---|
| 70 | * ------------------------------------------------- *
|
|---|
| 71 | * | R26 | R27 | R28 | R29 | *
|
|---|
| 72 | * ------------------------------------------------- *
|
|---|
| 73 | * ------------------------------------------------- *
|
|---|
| 74 | * | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | *
|
|---|
| 75 | * ------------------------------------------------- *
|
|---|
| 76 | * | 288 | 292 | 296 | 300 | 304 | 308 | 312 | 316 | *
|
|---|
| 77 | * ------------------------------------------------- *
|
|---|
| 78 | * ------------------------------------------------- *
|
|---|
| 79 | * | R30 | R31 | CR | LR | *
|
|---|
| 80 | * ------------------------------------------------- *
|
|---|
| 81 | * ------------------------------------------------- *
|
|---|
| 82 | * | 80 | 81 | | *
|
|---|
| 83 | * ------------------------------------------------- *
|
|---|
| 84 | * | 320 | 324 | | *
|
|---|
| 85 | * ------------------------------------------------- *
|
|---|
| 86 | * | PC | | *
|
|---|
| 87 | * ------------------------------------------------- *
|
|---|
| 88 | * *
|
|---|
| 89 | *******************************************************/
|
|---|
| 90 |
|
|---|
| 91 | .globl make_fcontext
|
|---|
| 92 | #if _CALL_ELF == 2
|
|---|
| 93 | .text
|
|---|
| 94 | .align 2
|
|---|
| 95 | make_fcontext:
|
|---|
| 96 | addis %r2, %r12, .TOC.-make_fcontext@ha
|
|---|
| 97 | addi %r2, %r2, .TOC.-make_fcontext@l
|
|---|
| 98 | .localentry make_fcontext, . - make_fcontext
|
|---|
| 99 | #else
|
|---|
| 100 | .section ".opd","aw"
|
|---|
| 101 | .align 3
|
|---|
| 102 | make_fcontext:
|
|---|
| 103 | # ifdef _CALL_LINUX
|
|---|
| 104 | .quad .L.make_fcontext,.TOC.@tocbase,0
|
|---|
| 105 | .type make_fcontext,@function
|
|---|
| 106 | .text
|
|---|
| 107 | .align 2
|
|---|
| 108 | .L.make_fcontext:
|
|---|
| 109 | # else
|
|---|
| 110 | .hidden .make_fcontext
|
|---|
| 111 | .globl .make_fcontext
|
|---|
| 112 | .quad .make_fcontext,.TOC.@tocbase,0
|
|---|
| 113 | .size make_fcontext,24
|
|---|
| 114 | .type .make_fcontext,@function
|
|---|
| 115 | .text
|
|---|
| 116 | .align 2
|
|---|
| 117 | .make_fcontext:
|
|---|
| 118 | # endif
|
|---|
| 119 | #endif
|
|---|
| 120 | # save return address into R6
|
|---|
| 121 | mflr %r6
|
|---|
| 122 |
|
|---|
| 123 | # first arg of make_fcontext() == top address of context-stack
|
|---|
| 124 | # shift address in R3 to lower 16 byte boundary
|
|---|
| 125 | clrrdi %r3, %r3, 4
|
|---|
| 126 |
|
|---|
| 127 | # reserve space for context-data on context-stack
|
|---|
| 128 | # including 64 byte of linkage + parameter area (R1 % 16 == 0)
|
|---|
| 129 | subi %r3, %r3, 392
|
|---|
| 130 |
|
|---|
| 131 | # third arg of make_fcontext() == address of context-function
|
|---|
| 132 | # entry point (ELFv2) or descriptor (ELFv1)
|
|---|
| 133 | #if _CALL_ELF == 2
|
|---|
| 134 | # save address of context-function entry point
|
|---|
| 135 | std %r5, 320(%r3)
|
|---|
| 136 | #else
|
|---|
| 137 | # save address of context-function entry point
|
|---|
| 138 | ld %r4, 0(%r5)
|
|---|
| 139 | std %r4, 320(%r3)
|
|---|
| 140 | # save TOC of context-function
|
|---|
| 141 | ld %r4, 8(%r5)
|
|---|
| 142 | std %r4, 152(%r3)
|
|---|
| 143 | #endif
|
|---|
| 144 |
|
|---|
| 145 | # load LR
|
|---|
| 146 | mflr %r0
|
|---|
| 147 | # jump to label 1
|
|---|
| 148 | bl 1f
|
|---|
| 149 | 1:
|
|---|
| 150 | # load LR into R4
|
|---|
| 151 | mflr %r4
|
|---|
| 152 | # compute abs address of label finish
|
|---|
| 153 | addi %r4, %r4, finish - 1b
|
|---|
| 154 | # restore LR
|
|---|
| 155 | mtlr %r0
|
|---|
| 156 | # save address of finish as return-address for context-function
|
|---|
| 157 | # will be entered after context-function returns
|
|---|
| 158 | std %r4, 312(%r3)
|
|---|
| 159 |
|
|---|
| 160 | # restore return address from R6
|
|---|
| 161 | mtlr %r6
|
|---|
| 162 |
|
|---|
| 163 | blr # return pointer to context-data
|
|---|
| 164 |
|
|---|
| 165 | finish:
|
|---|
| 166 | # save return address into R0
|
|---|
| 167 | mflr %r0
|
|---|
| 168 | # save return address on stack, set up stack frame
|
|---|
| 169 | std %r0, 8(%r1)
|
|---|
| 170 | # allocate stack space, R1 % 16 == 0
|
|---|
| 171 | stdu %r1, -32(%r1)
|
|---|
| 172 |
|
|---|
| 173 | # exit code is zero
|
|---|
| 174 | li %r3, 0
|
|---|
| 175 | # exit application
|
|---|
| 176 | bl _exit
|
|---|
| 177 | nop
|
|---|
| 178 | #if _CALL_ELF == 2
|
|---|
| 179 | .size make_fcontext, .-make_fcontext
|
|---|
| 180 | #else
|
|---|
| 181 | # ifdef _CALL_LINUX
|
|---|
| 182 | .size .make_fcontext, .-.L.make_fcontext
|
|---|
| 183 | # else
|
|---|
| 184 | .size .make_fcontext, .-.make_fcontext
|
|---|
| 185 | # endif
|
|---|
| 186 | #endif
|
|---|
| 187 |
|
|---|
| 188 | /* Mark that we don't need executable stack. */
|
|---|
| 189 | .section .note.GNU-stack,"",%progbits
|
|---|