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 *  |    F14    |    F15    |    F16    |    F17    |  *
16 *  -------------------------------------------------  *
17 *  -------------------------------------------------  *
18 *  |  8  |  9  |  10 |  11 |  12 |  13 |  14 |  15 |  *
19 *  -------------------------------------------------  *
20 *  |  32 |  36 |  40 |  44 |  48 |  52 |  56 |  60 |  *
21 *  -------------------------------------------------  *
22 *  |    F18    |    F19    |    F20    |    F21    |  *
23 *  -------------------------------------------------  *
24 *  -------------------------------------------------  *
25 *  |  16 |  17 |  18 |  19 |  20 |  21 |  22 |  23 |  *
26 *  -------------------------------------------------  *
27 *  |  64 |  68 |  72 |  76 |  80 |  84 |  88 |  92 |  *
28 *  -------------------------------------------------  *
29 *  |    F22    |    F23    |    F24    |    F25    |  *
30 *  -------------------------------------------------  *
31 *  -------------------------------------------------  *
32 *  |  24 |  25 |  26 |  27 |  28 |  29 |  30 |  31 |  *
33 *  -------------------------------------------------  *
34 *  |  96 | 100 | 104 | 108 | 112 | 116 | 120 | 124 |  *
35 *  -------------------------------------------------  *
36 *  |    F26    |    F27    |    F28    |    F29    |  *
37 *  -------------------------------------------------  *
38 *  -------------------------------------------------  *
39 *  |  32 |  33 |  34 |  35 |  36 |  37 |  38 |  39 |  *
40 *  -------------------------------------------------  *
41 *  | 128 | 132 | 136 | 140 | 144 | 148 | 152 | 156 |  *
42 *  -------------------------------------------------  *
43 *  |    F30    |    F31    |   fpscr   | R13 | R14 |  *
44 *  -------------------------------------------------  *
45 *  -------------------------------------------------  *
46 *  |  40 |  41 |  42 |  43 |  44 |  45 |  46 |  47 |  *
47 *  -------------------------------------------------  *
48 *  | 160 | 164 | 168 | 172 | 176 | 180 | 184 | 188 |  *
49 *  -------------------------------------------------  *
50 *  | R15 | R16 | R17 | R18 | R19 | R20 | R21 | R22 |  *
51 *  -------------------------------------------------  *
52 *  -------------------------------------------------  *
53 *  |  48 |  49 |  50 |  51 |  52 |  53 |  54 |  55 |  *
54 *  -------------------------------------------------  *
55 *  | 192 | 196 | 200 | 204 | 208 | 212 | 216 | 220 |  *
56 *  -------------------------------------------------  *
57 *  | R23 | R24 | R25 | R26 | R27 | R28 | R29 | R30 |  *
58 *  -------------------------------------------------  *
59 *  -------------------------------------------------  *
60 *  |  56 |  57 |  58 |  59 |  60 |  61 |  62 |  63 |  *
61 *  -------------------------------------------------  *
62 *  | 224 | 228 | 232 | 236 | 240 | 244 | 248 | 252 |  *
63 *  -------------------------------------------------  *
64 *  | R31 |hiddn|  CR |  LR |  PC |bchai|linkr| FCTX|  *
65 *  -------------------------------------------------  *
66 *  -------------------------------------------------  *
67 *  |  64 |                                         |  *
68 *  -------------------------------------------------  *
69 *  | 256 |                                         |  *
70 *  -------------------------------------------------  *
71 *  | DATA|                                         |  *
72 *  -------------------------------------------------  *
73 *                                                     *
74 *******************************************************/
75
76.text
77.globl _jump_fcontext
78.align 2
79_jump_fcontext:
80    ; reserve space on stack
81    subi  r1, r1, 244
82
83    stfd  f14, 0(r1)  # save F14
84    stfd  f15, 8(r1)  # save F15
85    stfd  f16, 16(r1)  # save F16
86    stfd  f17, 24(r1)  # save F17
87    stfd  f18, 32(r1)  # save F18
88    stfd  f19, 40(r1)  # save F19
89    stfd  f20, 48(r1)  # save F20
90    stfd  f21, 56(r1)  # save F21
91    stfd  f22, 64(r1)  # save F22
92    stfd  f23, 72(r1)  # save F23
93    stfd  f24, 80(r1)  # save F24
94    stfd  f25, 88(r1)  # save F25
95    stfd  f26, 96(r1)  # save F26
96    stfd  f27, 104(r1)  # save F27
97    stfd  f28, 112(r1)  # save F28
98    stfd  f29, 120(r1)  # save F29
99    stfd  f30, 128(r1)  # save F30
100    stfd  f31, 136(r1)  # save F31
101    mffs  f0  # load FPSCR
102    stfd  f0, 144(r1)  # save FPSCR
103
104    stw  r13, 152(r1)  # save R13
105    stw  r14, 156(r1)  # save R14
106    stw  r15, 160(r1)  # save R15
107    stw  r16, 164(r1)  # save R16
108    stw  r17, 168(r1)  # save R17
109    stw  r18, 172(r1)  # save R18
110    stw  r19, 176(r1)  # save R19
111    stw  r20, 180(r1)  # save R20
112    stw  r21, 184(r1)  # save R21
113    stw  r22, 188(r1)  # save R22
114    stw  r23, 192(r1)  # save R23
115    stw  r24, 196(r1)  # save R24
116    stw  r25, 200(r1)  # save R25
117    stw  r26, 204(r1)  # save R26
118    stw  r27, 208(r1)  # save R27
119    stw  r28, 212(r1)  # save R28
120    stw  r29, 216(r1)  # save R29
121    stw  r30, 220(r1)  # save R30
122    stw  r31, 224(r1)  # save R31
123    stw  r3,  228(r1)  # save hidden
124
125    # save CR
126    mfcr  r0
127    stw   r0, 232(r1)
128    # save LR
129    mflr  r0
130    stw   r0, 236(r1)
131    # save LR as PC
132    stw   r0, 240(r1)
133
134    # store RSP (pointing to context-data) in R6
135    mr  r6, r1
136
137    # restore RSP (pointing to context-data) from R4
138    mr  r1, r4
139
140    lfd  f14, 0(r1)  # restore F14
141    lfd  f15, 8(r1)  # restore F15
142    lfd  f16, 16(r1)  # restore F16
143    lfd  f17, 24(r1)  # restore F17
144    lfd  f18, 32(r1)  # restore F18
145    lfd  f19, 40(r1)  # restore F19
146    lfd  f20, 48(r1)  # restore F20
147    lfd  f21, 56(r1)  # restore F21
148    lfd  f22, 64(r1)  # restore F22
149    lfd  f23, 72(r1)  # restore F23
150    lfd  f24, 80(r1)  # restore F24
151    lfd  f25, 88(r1)  # restore F25
152    lfd  f26, 96(r1)  # restore F26
153    lfd  f27, 104(r1)  # restore F27
154    lfd  f28, 112(r1)  # restore F28
155    lfd  f29, 120(r1)  # restore F29
156    lfd  f30, 128(r1)  # restore F30
157    lfd  f31, 136(r1)  # restore F31
158    lfd  f0,  144(r1)  # load FPSCR
159    mtfsf  0xff, f0  # restore FPSCR
160
161    lwz  r13, 152(r1)  # restore R13
162    lwz  r14, 156(r1)  # restore R14
163    lwz  r15, 160(r1)  # restore R15
164    lwz  r16, 164(r1)  # restore R16
165    lwz  r17, 168(r1)  # restore R17
166    lwz  r18, 172(r1)  # restore R18
167    lwz  r19, 176(r1)  # restore R19
168    lwz  r20, 180(r1)  # restore R20
169    lwz  r21, 184(r1)  # restore R21
170    lwz  r22, 188(r1)  # restore R22
171    lwz  r23, 192(r1)  # restore R23
172    lwz  r24, 196(r1)  # restore R24
173    lwz  r25, 200(r1)  # restore R25
174    lwz  r26, 204(r1)  # restore R26
175    lwz  r27, 208(r1)  # restore R27
176    lwz  r28, 212(r1)  # restore R28
177    lwz  r29, 216(r1)  # restore R29
178    lwz  r30, 220(r1)  # restore R30
179    lwz  r31, 224(r1)  # restore R31
180    lwz  r3,  228(r1)  # restore hidden
181
182    # restore CR
183    lwz   r0, 232(r1)
184    mtcr  r0
185    # restore LR
186    lwz   r0, 236(r1)
187    mtlr  r0
188    # load PC
189    lwz   r0, 240(r1)
190    # restore CTR
191    mtctr r0
192
193    # adjust stack
194    addi  r1, r1, 244
195
196    # return transfer_t
197    stw  r6, 0(r3)
198    stw  r5, 4(r3)
199
200    # jump to context
201    bctr
202