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 "jump_ppc64_sysv_elf_gas.S"
70.globl jump_fcontext
71#if _CALL_ELF == 2
72	.text
73	.align 2
74jump_fcontext:
75        addis   %r2, %r12, .TOC.-jump_fcontext@ha
76        addi    %r2, %r2, .TOC.-jump_fcontext@l
77        .localentry jump_fcontext, . - jump_fcontext
78#else
79	.section ".opd","aw"
80	.align 3
81jump_fcontext:
82# ifdef _CALL_LINUX
83        .quad   .L.jump_fcontext,.TOC.@tocbase,0
84        .type   jump_fcontext,@function
85        .text
86        .align 2
87.L.jump_fcontext:
88# else
89        .hidden .jump_fcontext
90        .globl  .jump_fcontext
91        .quad   .jump_fcontext,.TOC.@tocbase,0
92        .size   jump_fcontext,24
93        .type   .jump_fcontext,@function
94        .text
95        .align 2
96.jump_fcontext:
97# endif
98#endif
99    # reserve space on stack
100    subi  %r1, %r1, 184
101
102#if _CALL_ELF != 2
103    std  %r2,  0(%r1)  # save TOC
104#endif
105    std  %r14, 8(%r1)  # save R14
106    std  %r15, 16(%r1)  # save R15
107    std  %r16, 24(%r1)  # save R16
108    std  %r17, 32(%r1)  # save R17
109    std  %r18, 40(%r1)  # save R18
110    std  %r19, 48(%r1)  # save R19
111    std  %r20, 56(%r1)  # save R20
112    std  %r21, 64(%r1)  # save R21
113    std  %r22, 72(%r1)  # save R22
114    std  %r23, 80(%r1)  # save R23
115    std  %r24, 88(%r1)  # save R24
116    std  %r25, 96(%r1)  # save R25
117    std  %r26, 104(%r1)  # save R26
118    std  %r27, 112(%r1)  # save R27
119    std  %r28, 120(%r1)  # save R28
120    std  %r29, 128(%r1)  # save R29
121    std  %r30, 136(%r1)  # save R30
122    std  %r31, 144(%r1)  # save R31
123#if _CALL_ELF != 2
124    std  %r3,  152(%r1)  # save hidden
125#endif
126
127    # save CR
128    mfcr  %r0
129    std   %r0, 160(%r1)
130    # save LR
131    mflr  %r0
132    std   %r0, 168(%r1)
133    # save LR as PC
134    std   %r0, 176(%r1)
135
136    # store RSP (pointing to context-data) in R6
137    mr  %r6, %r1
138
139#if _CALL_ELF == 2
140    # restore RSP (pointing to context-data) from R3
141    mr  %r1, %r3
142#else
143    # restore RSP (pointing to context-data) from R4
144    mr  %r1, %r4
145
146    ld  %r2,  0(%r1)  # restore TOC
147#endif
148    ld  %r14, 8(%r1)  # restore R14
149    ld  %r15, 16(%r1)  # restore R15
150    ld  %r16, 24(%r1)  # restore R16
151    ld  %r17, 32(%r1)  # restore R17
152    ld  %r18, 40(%r1)  # restore R18
153    ld  %r19, 48(%r1)  # restore R19
154    ld  %r20, 56(%r1)  # restore R20
155    ld  %r21, 64(%r1)  # restore R21
156    ld  %r22, 72(%r1)  # restore R22
157    ld  %r23, 80(%r1)  # restore R23
158    ld  %r24, 88(%r1)  # restore R24
159    ld  %r25, 96(%r1)  # restore R25
160    ld  %r26, 104(%r1)  # restore R26
161    ld  %r27, 112(%r1)  # restore R27
162    ld  %r28, 120(%r1)  # restore R28
163    ld  %r29, 128(%r1)  # restore R29
164    ld  %r30, 136(%r1)  # restore R30
165    ld  %r31, 144(%r1)  # restore R31
166#if _CALL_ELF != 2
167    ld  %r3,  152(%r1)  # restore hidden
168#endif
169
170    # restore CR
171    ld  %r0, 160(%r1)
172    mtcr  %r0
173    # restore LR
174    ld  %r0, 168(%r1)
175    mtlr  %r0
176
177    # load PC
178    ld  %r12, 176(%r1)
179    # restore CTR
180    mtctr  %r12
181
182    # adjust stack
183    addi  %r1, %r1, 184
184
185#if _CALL_ELF == 2
186    # copy transfer_t into transfer_fn arg registers
187    mr  %r3, %r6
188    # arg pointer already in %r4
189
190    # jump to context
191    bctr
192	.size jump_fcontext, .-jump_fcontext
193#else
194    # zero in r3 indicates first jump to context-function
195    cmpdi %r3, 0
196    beq use_entry_arg
197
198    # return transfer_t
199    std  %r6, 0(%r3)
200    std  %r5, 8(%r3)
201
202    # jump to context
203    bctr
204
205use_entry_arg:
206    # copy transfer_t into transfer_fn arg registers
207    mr  %r3, %r6
208    mr  %r4, %r5
209
210    # jump to context
211    bctr
212# ifdef _CALL_LINUX
213	.size .jump_fcontext, .-.L.jump_fcontext
214# else
215	.size .jump_fcontext, .-.jump_fcontext
216# endif
217#endif
218
219
220/* Mark that we don't need executable stack.  */
221.section .note.GNU-stack,"",%progbits
222