Ticket #9743: make_ppc64_sysv_elf_gas.S

File make_ppc64_sysv_elf_gas.S, 7.8 KB (added by Tony Reix <tony.reix@…>, 9 years ago)
Line 
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 | 8 | 9 | *
12 * ------------------------------------------------------------- *
13 * | 0 | 4 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | *
14 * ------------------------------------------------------------- *
15PPC64 Big-Endian:
16 * | R13 | R14 | R15 | R16 | R17 | *
17PPC64 Little-Endian:
18 * | TOC | R14 | R15 | R16 | R17 | *
19 * ------------------------------------------------------------- *
20 * ------------------------------------------------------------- *
21 * | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | *
22 * ------------------------------------------------------------- *
23 * | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | *
24 * ------------------------------------------------------------- *
25 * | R18 | R19 | R20 | R21 | R22 | *
26 * ------------------------------------------------------------- *
27 * ------------------------------------------------------------- *
28 * | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | *
29 * ------------------------------------------------------------- *
30 * | 80 | 84 | 88 | 92 | 96 | 100 | 104 | 108 | 112 | 116 | *
31 * ------------------------------------------------------------- *
32 * | R23 | R24 | R25 | R26 | R27 | *
33 * ------------------------------------------------------------- *
34 * ------------------------------------------------------------- *
35 * | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | *
36 * ------------------------------------------------------------- *
37 * | 120 | 124 | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 | *
38 * ------------------------------------------------------------- *
39 * | R28 | R29 | R30 | R31 | SP | *
40 * ------------------------------------------------------------- *
41 * ------------------------------------------------------------- *
42 * | 40 | 41 | 42 | 43 | 44 | 45 | | *
43 * ------------------------------------------------------------- *
44 * | 160 | 164 | 168 | 172 | 176 | 180 | | *
45 * ------------------------------------------------------------- *
46 * | CR | LR | PC | | *
47 * ------------------------------------------------------------- *
48 * ------------------------------------------------------------- *
49 * | 46 | 47 | 48 | 49 | | *
50 * ------------------------------------------------------------- *
51 * | 184 | 188 | 192 | 196 | | *
52 * ------------------------------------------------------------- *
53 * | sp | size | | *
54 * ------------------------------------------------------------- *
55 * ------------------------------------------------------------- *
56 * | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | *
57 * ------------------------------------------------------------- *
58 * | 200 | 204 | 208 | 212 | 216 | 220 | 224 | 228 | 232 | 236 | *
59 * ------------------------------------------------------------- *
60 * | F14 | F15 | F16 | F17 | F18 | *
61 * ------------------------------------------------------------- *
62 * ------------------------------------------------------------- *
63 * | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | *
64 * ------------------------------------------------------------- *
65 * | 240 | 244 | 248 | 252 | 256 | 260 | 264 | 268 | 272 | 276 | *
66 * ------------------------------------------------------------- *
67 * | F19 | F20 | F21 | F22 | F23 | *
68 * ------------------------------------------------------------- *
69 * ------------------------------------------------------------- *
70 * | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | *
71 * ------------------------------------------------------------- *
72 * | 280 | 284 | 288 | 292 | 296 | 300 | 304 | 308 | 312 | 316 | *
73 * ------------------------------------------------------------- *
74PPC64 Big-Endian:
75 * | F24 | F25 | F26 | F27 | F28 | *
76 * ------------------------------------------------------------- *
77 * ------------------------------------------------------------- *
78 * | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | | *
79 * ------------------------------------------------------------- *
80 * | 320 | 324 | 328 | 332 | 336 | 340 | 344 | 348 | | *
81 * ------------------------------------------------------------- *
82 * | F29 | F30 | F31 | fpscr | | *
83 * ------------------------------------------------------------- *
84PPC64 Big-Endian:
85 * *
86 * *****************************************************************/
87
88#ifdef __LITTLE_ENDIAN__
89.abiversion 2
90#endif
91
92.section ".text"
93.align 2
94.globl make_fcontext
95
96#ifdef __BIG_ENDIAN__
97.section ".opd","aw"
98.align 3
99#else
100.type make_fcontext,@function
101#endif
102
103make_fcontext:
104#ifdef __BIG_ENDIAN__
105.quad .make_fcontext,.TOC.@tocbase,0
106.previous
107.size make_fcontext,24
108.type .make_fcontext,@function
109.globl .make_fcontext
110.make_fcontext:
111#else
112 addis %r2,%r12,.TOC.-make_fcontext@ha
113 addi %r2,%r2,.TOC.-make_fcontext@l
114.localentry make_fcontext,.-make_fcontext
115#endif
116
117 mflr %r6 # save return address into R6
118
119 mr %r0, %r3
120 subi %r3, %r3, 352 # reserve space for fcontext_t at top of context stack
121
122 # call align_stack, R3 contains address at 16 byte boundary after return
123 # == pointer to fcontext_t and address of context stack
124 clrrdi %r3, %r3, 4
125
126 std %r0, 184(%r3) # save address of context stack (base) in fcontext_t
127 std %r4, 192(%r3) # save context stack size in fcontext_t
128
129#ifdef __BIG_ENDIAN__
130 ld %r4, 0(%r5) # save address of context function in fcontext_t
131 std %r4, 176(%r3)
132#else
133 std %r5, 176(%r3) # save entry point of context function in fcontext_t
134#endif
135
136 subi %r0, %r3, 64 # 64 bytes on stack for parameter area (== 8 registers)
137 std %r0, 152(%r3) # save the stack base
138
139 mflr %r0 # load LR
140 bl 1f # jump to label 1
1411:
142 mflr %r4 # load LR into R4
143 addi %r4, %r4, finish - 1b # compute abs address of label finish
144 mtlr %r0 # restore LR
145 std %r4, 168(%r3) # save address of finish as return address for context function
146 # entered after context function returns
147
148 mtlr %r6 # restore return address from R6
149
150 blr
151
152finish:
153 # SP points to same address as SP on entry of context function
154 mflr %r0 # save return address into R0
155 stw %r0, 8(%r1) # save return address on stack, set up stack frame
156 stwu %r1, -32(%r1) # allocate stack space, SP % 16 == 0
157
158 li %r3, 0 # set return value to zero
159 bl _exit # exit application
160 nop
161#ifdef __BIG_ENDIAN__
162.size .make_fcontext, .-.make_fcontext
163#else
164.size make_fcontext,.-make_fcontext
165#endif
166
167/* Mark that we don't need executable stack. */
168.section .note.GNU-stack,"",%progbits