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