This source file includes following definitions.
- fetch_regs_from_mem
- restore_upper_240kb
- restore_decr
- write_ppu_mb
- write_ppuint_mb
- restore_fpcr
- restore_srr0
- restore_event_mask
- restore_tag_mask
- restore_complete
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #ifndef LS_SIZE
15 #define LS_SIZE 0x40000
16 #endif
17
18 typedef unsigned int u32;
19 typedef unsigned long long u64;
20
21 #include <spu_intrinsics.h>
22 #include <asm/spu_csa.h>
23 #include "spu_utils.h"
24
25 #define BR_INSTR 0x327fff80
26 #define NOP_INSTR 0x40200000
27 #define HEQ_INSTR 0x7b000000
28 #define STOP_INSTR 0x00000000
29 #define ILLEGAL_INSTR 0x00800000
30 #define RESTORE_COMPLETE 0x00003ffc
31
32 static inline void fetch_regs_from_mem(addr64 lscsa_ea)
33 {
34 unsigned int ls = (unsigned int)®s_spill[0];
35 unsigned int size = sizeof(regs_spill);
36 unsigned int tag_id = 0;
37 unsigned int cmd = 0x40;
38
39 spu_writech(MFC_LSA, ls);
40 spu_writech(MFC_EAH, lscsa_ea.ui[0]);
41 spu_writech(MFC_EAL, lscsa_ea.ui[1]);
42 spu_writech(MFC_Size, size);
43 spu_writech(MFC_TagID, tag_id);
44 spu_writech(MFC_Cmd, cmd);
45 }
46
47 static inline void restore_upper_240kb(addr64 lscsa_ea)
48 {
49 unsigned int ls = 16384;
50 unsigned int list = (unsigned int)&dma_list[0];
51 unsigned int size = sizeof(dma_list);
52 unsigned int tag_id = 0;
53 unsigned int cmd = 0x44;
54
55
56
57
58
59 spu_writech(MFC_LSA, ls);
60 spu_writech(MFC_EAH, lscsa_ea.ui[0]);
61 spu_writech(MFC_EAL, list);
62 spu_writech(MFC_Size, size);
63 spu_writech(MFC_TagID, tag_id);
64 spu_writech(MFC_Cmd, cmd);
65 }
66
67 static inline void restore_decr(void)
68 {
69 unsigned int offset;
70 unsigned int decr_running;
71 unsigned int decr;
72
73
74
75
76
77
78 offset = LSCSA_QW_OFFSET(decr_status);
79 decr_running = regs_spill[offset].slot[0] & SPU_DECR_STATUS_RUNNING;
80 if (decr_running) {
81 offset = LSCSA_QW_OFFSET(decr);
82 decr = regs_spill[offset].slot[0];
83 spu_writech(SPU_WrDec, decr);
84 }
85 }
86
87 static inline void write_ppu_mb(void)
88 {
89 unsigned int offset;
90 unsigned int data;
91
92
93
94
95
96 offset = LSCSA_QW_OFFSET(ppu_mb);
97 data = regs_spill[offset].slot[0];
98 spu_writech(SPU_WrOutMbox, data);
99 }
100
101 static inline void write_ppuint_mb(void)
102 {
103 unsigned int offset;
104 unsigned int data;
105
106
107
108
109
110 offset = LSCSA_QW_OFFSET(ppuint_mb);
111 data = regs_spill[offset].slot[0];
112 spu_writech(SPU_WrOutIntrMbox, data);
113 }
114
115 static inline void restore_fpcr(void)
116 {
117 unsigned int offset;
118 vector unsigned int fpcr;
119
120
121
122
123
124 offset = LSCSA_QW_OFFSET(fpcr);
125 fpcr = regs_spill[offset].v;
126 spu_mtfpscr(fpcr);
127 }
128
129 static inline void restore_srr0(void)
130 {
131 unsigned int offset;
132 unsigned int srr0;
133
134
135
136
137 offset = LSCSA_QW_OFFSET(srr0);
138 srr0 = regs_spill[offset].slot[0];
139 spu_writech(SPU_WrSRR0, srr0);
140 }
141
142 static inline void restore_event_mask(void)
143 {
144 unsigned int offset;
145 unsigned int event_mask;
146
147
148
149
150 offset = LSCSA_QW_OFFSET(event_mask);
151 event_mask = regs_spill[offset].slot[0];
152 spu_writech(SPU_WrEventMask, event_mask);
153 }
154
155 static inline void restore_tag_mask(void)
156 {
157 unsigned int offset;
158 unsigned int tag_mask;
159
160
161
162
163 offset = LSCSA_QW_OFFSET(tag_mask);
164 tag_mask = regs_spill[offset].slot[0];
165 spu_writech(MFC_WrTagMask, tag_mask);
166 }
167
168 static inline void restore_complete(void)
169 {
170 extern void exit_fini(void);
171 unsigned int *exit_instrs = (unsigned int *)exit_fini;
172 unsigned int offset;
173 unsigned int stopped_status;
174 unsigned int stopped_code;
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191 offset = LSCSA_QW_OFFSET(stopped_status);
192 stopped_status = regs_spill[offset].slot[0];
193 stopped_code = regs_spill[offset].slot[1];
194
195 switch (stopped_status) {
196 case SPU_STOPPED_STATUS_P_I:
197
198
199
200
201 exit_instrs[0] = RESTORE_COMPLETE;
202 exit_instrs[1] = ILLEGAL_INSTR;
203 exit_instrs[2] = STOP_INSTR | stopped_code;
204 break;
205 case SPU_STOPPED_STATUS_P_H:
206
207
208
209
210 exit_instrs[0] = RESTORE_COMPLETE;
211 exit_instrs[1] = HEQ_INSTR;
212 exit_instrs[2] = STOP_INSTR | stopped_code;
213 break;
214 case SPU_STOPPED_STATUS_S_P:
215
216
217
218
219 exit_instrs[0] = RESTORE_COMPLETE;
220 exit_instrs[1] = STOP_INSTR | stopped_code;
221 exit_instrs[2] = NOP_INSTR;
222 exit_instrs[3] = BR_INSTR;
223 break;
224 case SPU_STOPPED_STATUS_S_I:
225
226
227
228 exit_instrs[0] = RESTORE_COMPLETE;
229 exit_instrs[1] = ILLEGAL_INSTR;
230 exit_instrs[2] = NOP_INSTR;
231 exit_instrs[3] = BR_INSTR;
232 break;
233 case SPU_STOPPED_STATUS_I:
234
235
236
237 exit_instrs[0] = RESTORE_COMPLETE;
238 exit_instrs[1] = ILLEGAL_INSTR;
239 exit_instrs[2] = NOP_INSTR;
240 exit_instrs[3] = BR_INSTR;
241 break;
242 case SPU_STOPPED_STATUS_S:
243
244 exit_instrs[0] = RESTORE_COMPLETE;
245 exit_instrs[1] = NOP_INSTR;
246 exit_instrs[2] = NOP_INSTR;
247 exit_instrs[3] = BR_INSTR;
248 break;
249 case SPU_STOPPED_STATUS_H:
250
251
252
253 exit_instrs[0] = RESTORE_COMPLETE;
254 exit_instrs[1] = HEQ_INSTR;
255 exit_instrs[2] = NOP_INSTR;
256 exit_instrs[3] = BR_INSTR;
257 break;
258 case SPU_STOPPED_STATUS_P:
259
260
261
262 exit_instrs[0] = RESTORE_COMPLETE;
263 exit_instrs[1] = STOP_INSTR | stopped_code;
264 break;
265 case SPU_STOPPED_STATUS_R:
266
267 exit_instrs[0] = RESTORE_COMPLETE;
268 exit_instrs[1] = NOP_INSTR;
269 exit_instrs[2] = NOP_INSTR;
270 exit_instrs[3] = BR_INSTR;
271 break;
272 default:
273
274 break;
275 }
276 spu_sync();
277 }
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294 int main()
295 {
296 addr64 lscsa_ea;
297
298 lscsa_ea.ui[0] = spu_readch(SPU_RdSigNotify1);
299 lscsa_ea.ui[1] = spu_readch(SPU_RdSigNotify2);
300 fetch_regs_from_mem(lscsa_ea);
301
302 set_event_mask();
303 set_tag_mask();
304 build_dma_list(lscsa_ea);
305 restore_upper_240kb(lscsa_ea);
306
307 enqueue_putllc(lscsa_ea);
308 set_tag_update();
309 read_tag_status();
310 restore_decr();
311 read_llar_status();
312 write_ppu_mb();
313 write_ppuint_mb();
314 restore_fpcr();
315 restore_srr0();
316 restore_event_mask();
317 restore_tag_mask();
318
319 restore_complete();
320
321 return 0;
322 }