Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / context / src / asm / make_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 make_fcontext
70 #if _CALL_ELF == 2
71         .text
72         .align 2
73 make_fcontext:
74         addis   %r2, %r12, .TOC.-make_fcontext@ha
75         addi    %r2, %r2, .TOC.-make_fcontext@l
76         .localentry make_fcontext, . - make_fcontext
77 #else
78         .section ".opd","aw"
79         .align 3
80 make_fcontext:
81 # ifdef _CALL_LINUX
82         .quad   .L.make_fcontext,.TOC.@tocbase,0
83         .type   make_fcontext,@function
84         .text
85         .align 2
86 .L.make_fcontext:
87 # else
88         .hidden .make_fcontext
89         .globl  .make_fcontext
90         .quad   .make_fcontext,.TOC.@tocbase,0
91         .size   make_fcontext,24
92         .type   .make_fcontext,@function
93         .text
94         .align 2
95 .make_fcontext:
96 # endif
97 #endif
98     # save return address into R6
99     mflr  %r6
100
101     # first arg of make_fcontext() == top address of context-stack
102     # shift address in R3 to lower 16 byte boundary
103     clrrdi  %r3, %r3, 4
104
105     # reserve space for context-data on context-stack
106     # including 64 byte of linkage + parameter area (R1 % 16 == 0)
107     subi  %r3, %r3, 248
108
109     # third arg of make_fcontext() == address of context-function
110     # entry point (ELFv2) or descriptor (ELFv1)
111 #if _CALL_ELF == 2
112     # save address of context-function entry point
113     std  %r5, 176(%r3)
114 #else
115     # save address of context-function entry point
116     ld   %r4, 0(%r5)
117     std  %r4, 176(%r3)
118     # save TOC of context-function
119     ld   %r4, 8(%r5)
120     std  %r4, 0(%r3)
121 #endif
122
123     # set back-chain to zero
124     li   %r0, 0
125     std  %r0, 184(%r3)
126
127     # zero in r3 indicates first jump to context-function
128     std  %r0, 152(%r3)
129
130     # load LR
131     mflr  %r0
132     # jump to label 1
133     bl  1f
134 1:
135     # load LR into R4
136     mflr  %r4
137     # compute abs address of label finish
138     addi  %r4, %r4, finish - 1b
139     # restore LR
140     mtlr  %r0
141     # save address of finish as return-address for context-function
142     # will be entered after context-function returns
143     std  %r4, 168(%r3)
144
145     # restore return address from R6
146     mtlr  %r6
147
148     blr  # return pointer to context-data
149
150 finish:
151     # save return address into R0
152     mflr  %r0
153     # save return address on stack, set up stack frame
154     std  %r0, 8(%r1)
155     # allocate stack space, R1 % 16 == 0
156     stdu  %r1, -32(%r1)
157
158     # exit code is zero
159     li  %r3, 0
160     # exit application
161     bl  _exit
162     nop
163 #if _CALL_ELF == 2
164         .size make_fcontext, .-make_fcontext
165 #else
166 # ifdef _CALL_LINUX
167         .size .make_fcontext, .-.L.make_fcontext
168 # else
169         .size .make_fcontext, .-.make_fcontext
170 # endif
171 #endif
172
173 /* Mark that we don't need executable stack.  */
174 .section .note.GNU-stack,"",%progbits