1
2/*
3            Copyright Oliver Kowalke 2009.
4   Distributed under the Boost Software License, Version 1.0.
5      (See accompanying file LICENSE_1_0.txt or copy at
6          http://www.boost.org/LICENSE_1_0.txt)
7*/
8
9/*******************************************************
10 *                                                     *
11 *  -------------------------------------------------  *
12 *  |  0  |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  *
13 *  -------------------------------------------------  *
14 *  |  0  |  4  |  8  |  12 |  16 |  20 |  24 |  28 |  *
15 *  -------------------------------------------------  *
16 *  |    TOC    |    R14    |    R15    |    R16    |  *
17 *  -------------------------------------------------  *
18 *  -------------------------------------------------  *
19 *  |  8  |  9  |  10 |  11 |  12 |  13 |  14 |  15 |  *
20 *  -------------------------------------------------  *
21 *  |  32 |  36 |  40 |  44 |  48 |  52 |  56 |  60 |  *
22 *  -------------------------------------------------  *
23 *  |    R17    |    R18    |     R19   |    R20    |  *
24 *  -------------------------------------------------  *
25 *  -------------------------------------------------  *
26 *  |  16 |  17 |  18 |  19 |  20 |  21 |  22 |  23 |  *
27 *  -------------------------------------------------  *
28 *  |  64 |  68 |  72 |  76 |  80 |  84 |  88 |  92 |  *
29 *  -------------------------------------------------  *
30 *  |    R21    |    R22    |    R23    |    R24    |  *
31 *  -------------------------------------------------  *
32 *  -------------------------------------------------  *
33 *  |  24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  *
34 *  -------------------------------------------------  *
35 *  |  96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 |  *
36 *  -------------------------------------------------  *
37 *  |    R25    |    R26    |    R27    |    R28    |  *
38 *  -------------------------------------------------  *
39 *  -------------------------------------------------  *
40 *  |  32 |  33 |  34 |  35 |  36 |  37 |  38 |  39 |  *
41 *  -------------------------------------------------  *
42 *  | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 |  *
43 *  -------------------------------------------------  *
44 *  |    R29    |    R30    |    R31    |   hidden  |  *
45 *  -------------------------------------------------  *
46 *  -------------------------------------------------  *
47 *  |  40 |  41 |  42 |  43 |  44 |  45 |  46 |  47 |  *
48 *  -------------------------------------------------  *
49 *  | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 |  *
50 *  -------------------------------------------------  *
51 *  |     CR    |     LR    |     PC    | back-chain|  *
52 *  -------------------------------------------------  *
53 *  -------------------------------------------------  *
54 *  |  48 |  49 |  50 |  51 |  52 |  53 |  54 |  55 |  *
55 *  -------------------------------------------------  *
56 *  | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 |  *
57 *  -------------------------------------------------  *
58 *  |  cr saved |  lr saved |  compiler |   linker  |  *
59 *  -------------------------------------------------  *
60 *  -------------------------------------------------  *
61 *  |  56 |  57 |  58 |  59 |  60 |  61 |  62 |  63 |  *
62 *  -------------------------------------------------  *
63 *  | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 |  *
64 *  -------------------------------------------------  *
65 *  | TOC saved |    FCTX   |    DATA   |           |  *
66 *  -------------------------------------------------  *
67 *                                                     *
68 *******************************************************/
69
70    .file "jump_ppc64_sysv_xcoff_gas.S"
71    .toc
72    .csect .text[PR], 5
73    .align 2
74    .globl  jump_fcontext[DS]
75    .globl .jump_fcontext
76    .csect  jump_fcontext[DS], 3
77jump_fcontext:
78    .llong .jump_fcontext[PR], TOC[tc0], 0
79    .csect .text[PR], 5
80.jump_fcontext:
81    # reserve space on stack
82    subi  1, 1, 184
83
84    std  2, 0(1)  # save TOC
85    std  14, 8(1)  # save R14
86    std  15, 16(1)  # save R15
87    std  16, 24(1)  # save R16
88    std  17, 32(1)  # save R17
89    std  18, 40(1)  # save R18
90    std  19, 48(1)  # save R19
91    std  20, 56(1)  # save R20
92    std  21, 64(1)  # save R21
93    std  22, 72(1)  # save R22
94    std  23, 80(1)  # save R23
95    std  24, 88(1)  # save R24
96    std  25, 96(1)  # save R25
97    std  26, 104(1)  # save R26
98    std  27, 112(1)  # save R27
99    std  28, 120(1)  # save R28
100    std  29, 128(1)  # save R29
101    std  30, 136(1)  # save R30
102    std  31, 144(1)  # save R31
103    std  3,  152(1)  # save hidden
104
105    # save CR
106    mfcr  0
107    std  0, 160(1)
108    # save LR
109    mflr  0
110    std  0, 168(1)
111    # save LR as PC
112    std  0, 176(1)
113
114    # store RSP (pointing to context-data) in R6
115    mr  6, 1
116
117    # restore RSP (pointing to context-data) from R4
118    mr  1, 4
119
120    ld  2, 0(1)  # restore TOC
121    ld  14, 8(1)  # restore R14
122    ld  15, 16(1)  # restore R15
123    ld  16, 24(1)  # restore R16
124    ld  17, 32(1)  # restore R17
125    ld  18, 40(1)  # restore R18
126    ld  19, 48(1)  # restore R19
127    ld  20, 56(1)  # restore R20
128    ld  21, 64(1)  # restore R21
129    ld  22, 72(1)  # restore R22
130    ld  23, 80(1)  # restore R23
131    ld  24, 88(1)  # restore R24
132    ld  25, 96(1)  # restore R25
133    ld  26, 104(1)  # restore R26
134    ld  27, 112(1)  # restore R27
135    ld  28, 120(1)  # restore R28
136    ld  29, 128(1)  # restore R29
137    ld  30, 136(1)  # restore R30
138    ld  31, 144(1)  # restore R31
139    ld  3,  152(1)  # restore hidden
140
141    # restore CR
142    ld  0, 160(1)
143    mtcr  0
144    # restore LR
145    ld  0, 168(1)
146    mtlr  0
147
148    # load PC
149    ld  0, 176(1)
150    # restore CTR
151    mtctr  0
152
153    # adjust stack
154    addi  1, 1, 184
155
156    # zero in r3 indicates first jump to context-function
157    cmpdi 3, 0
158    beq use_entry_arg
159
160    # return transfer_t
161    std  6, 0(3)
162    std  5, 8(3)
163
164    # jump to context
165    bctr
166
167use_entry_arg:
168    # copy transfer_t into transfer_fn arg registers
169    mr  3, 6
170    mr  4, 5
171
172    # jump to context
173    bctr
174