/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/fps2bios/kernel/eeload/eeinit.c
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/fps2bios/kernel/eeload/eeinit.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (10 years, 10 months ago) by william
File MIME type: text/plain
File size: 12762 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 // EE initialization functions
2 // [made by] [RO]man, zerofrog
3 #include <tamtypes.h>
4 #include <stdio.h>
5
6 #include "eekernel.h"
7 #include "eeirq.h"
8
9 void InitializeGS();
10 void InitializeGIF();
11 void InitializeDMAC(int code);
12 void InitializeVU1();
13 void InitializeVIF1();
14 void InitializeIPU();
15 void InitializeVIF0();
16 void InitializeVU0();
17 void InitializeFPU();
18 void InitializeScratchPad();
19 void InitializeUserMemory(u32 base);
20 void InitializeINTC(int a);
21 void InitializeTIMER();
22
23 ////////////////////////////////////////////////////////////////////
24 //8000AA60
25 ////////////////////////////////////////////////////////////////////
26 void InitializeGS()
27 {
28 }
29
30 ////////////////////////////////////////////////////////////////////
31 //8000AB98
32 ////////////////////////////////////////////////////////////////////
33 void InitializeGIF()
34 {
35 GIF_CTRL = 1;
36 __asm__ ("sync\n");
37 GIF_FIFO = 0;
38 }
39
40 ////////////////////////////////////////////////////////////////////
41 //8000AD68 SYSCALL 001 ResetEE
42 ////////////////////////////////////////////////////////////////////
43 int _ResetEE(int init)
44 {
45 if (init & 0x01) { __printf("# Initialize DMAC ...\n"); InitializeDMAC(0x31F); }
46 if (init & 0x02) { __printf("# Initialize VU1 ...\n"); InitializeVU1(); }
47 if (init & 0x04) { __printf("# Initialize VIF1 ...\n"); InitializeVIF1(); }
48 if (init & 0x08) { __printf("# Initialize GIF ...\n"); InitializeGIF(); }
49 if (init & 0x10) { __printf("# Initialize VU0 ...\n"); InitializeVU0(); }
50 if (init & 0x04) { __printf("# Initialize VIF0 ...\n"); InitializeVIF0(); }
51 if (init & 0x40) { __printf("# Initialize IPU ...\n"); InitializeIPU(); }
52
53 InitializeINTC(0xC);
54 // return (*(int*)0x1000F410 &= 0xFFFBFFFF); code never reached :)
55 }
56
57 ////////////////////////////////////////////////////////////////////
58 //8000AE88
59 ////////////////////////////////////////////////////////////////////
60 int Initialize()
61 {
62 __printf("# Initialize Start.\n");
63 __printf("# Initialize GS ...");
64
65 InitializeGS();
66 _SetGsCrt(1, 2, 1);
67 __printf("\n");
68
69 __printf("# Initialize INTC ...\n");
70 InitializeINTC(0xFFFF);
71
72 __printf("# Initialize TIMER ...\n");
73 InitializeTIMER();
74
75 ResetEE(0x7F);
76
77 __printf("# Initialize FPU ...\n");
78 InitializeFPU();
79
80 __printf("# Initialize User Memory ...\n");
81 InitializeUserMemory(0x80000);
82
83 __printf("# Initialize Scratch Pad ...\n");
84 InitializeScratchPad();
85
86 __printf("# Initialize Done.\n");
87 }
88
89 ////////////////////////////////////////////////////////////////////
90 //8000AF50
91 ////////////////////////////////////////////////////////////////////
92 int Restart()
93 {
94 __printf("# Restart.\n");
95 __printf("# Initialize GS ...");
96
97 INTC_STAT = 4;
98 while (INTC_STAT & 4) { __asm__ ("nop\nnop\nnop\n"); }
99 INTC_STAT = 4;
100
101 InitializeGS();
102 _SetGsCrt(1, 2, 1);
103 __printf("\n");
104
105 __printf("# Initialize INTC ...\n");
106 InitializeINTC(0xDFFD);
107
108 __printf("# Initialize TIMER ...\n");
109 InitializeTIMER();
110
111 ResetEE(0x7F);
112
113 __printf("# Initialize FPU ...\n");
114 InitializeFPU();
115
116 __printf("# Initialize User Memory ...\n");
117 InitializeUserMemory(0x82000);
118
119 __printf("# Initialize Scratch Pad ...\n");
120 InitializeScratchPad();
121
122 __printf("# Restart Done.\n");
123
124 //wait for syncing IOP
125 while (SBUS_SMFLG & SBFLG_IOPSYNC) { __asm__ ("nop\nnop\nnop\n"); }
126
127 SBUS_SMFLG=SBFLG_IOPSYNC;
128 }
129
130 ////////////////////////////////////////////////////////////////////
131 //8000B0A0
132 ////////////////////////////////////////////////////////////////////
133 void InitializeDMAC(int code)
134 {
135 int i;
136 int *addr;
137
138 for (i=0; i<10; i++) {
139 if (!(code & (1<<i))) continue;
140
141 addr = (int*)dmac_CHCR[i];
142 addr[0x80/4] = 0;
143 addr[0x00/4] = 0;
144 addr[0x30/4] = 0;
145 addr[0x10/4] = 0;
146 addr[0x50/4] = 0;
147 addr[0x40/4] = 0;
148 }
149
150 DMAC_STAT = (code & 0xFFFF) | 0xE000;
151 DMAC_STAT = (DMAC_STAT & 0xFFFF0000) & ((code | 0x6000) << 16);
152
153 if ((code & 0x7F) == 0x7F) {
154 DMAC_CTRL = 0;
155 DMAC_PCR = 0;
156 } else {
157 DMAC_CTRL = 0;
158 DMAC_PCR = DMAC_PCR & (((~code) << 16) | (~code));
159 }
160
161 DMAC_SQWC = 0;
162 DMAC_RBSR = 0;
163 DMAC_RBOR = 0;
164 }
165
166 ////////////////////////////////////////////////////////////////////
167 //8000B1F0
168 ////////////////////////////////////////////////////////////////////
169 void InitializeVU1()
170 {
171 }
172
173 ////////////////////////////////////////////////////////////////////
174 //8000B2D8
175 ////////////////////////////////////////////////////////////////////
176 void InitializeVIF1()
177 {
178 }
179
180 ////////////////////////////////////////////////////////////////////
181 //8000B3B0
182 ////////////////////////////////////////////////////////////////////
183 void InitializeIPU()
184 {
185 }
186
187 ////////////////////////////////////////////////////////////////////
188 //8000B6F8
189 ////////////////////////////////////////////////////////////////////
190 void InitializeVIF0()
191 {
192 }
193
194 ////////////////////////////////////////////////////////////////////
195 //8000B778
196 ////////////////////////////////////////////////////////////////////
197 void InitializeVU0()
198 {
199 }
200
201 ////////////////////////////////////////////////////////////////////
202 //8000B7A8
203 ////////////////////////////////////////////////////////////////////
204 void InitializeFPU()
205 {
206 __asm__ (
207 "mtc1 $0, $0\n"
208 "mtc1 $0, $1\n"
209 "mtc1 $0, $2\n"
210 "mtc1 $0, $3\n"
211 "mtc1 $0, $4\n"
212 "mtc1 $0, $5\n"
213 "mtc1 $0, $6\n"
214 "mtc1 $0, $7\n"
215 "mtc1 $0, $8\n"
216 "mtc1 $0, $9\n"
217 "mtc1 $0, $10\n"
218 "mtc1 $0, $11\n"
219 "mtc1 $0, $12\n"
220 "mtc1 $0, $13\n"
221 "mtc1 $0, $14\n"
222 "mtc1 $0, $15\n"
223 "mtc1 $0, $16\n"
224 "mtc1 $0, $17\n"
225 "mtc1 $0, $18\n"
226 "mtc1 $0, $19\n"
227 "mtc1 $0, $20\n"
228 "mtc1 $0, $21\n"
229 "mtc1 $0, $22\n"
230 "mtc1 $0, $23\n"
231 "mtc1 $0, $24\n"
232 "mtc1 $0, $25\n"
233 "mtc1 $0, $26\n"
234 "mtc1 $0, $27\n"
235 "mtc1 $0, $28\n"
236 "mtc1 $0, $29\n"
237 "mtc1 $0, $30\n"
238 "mtc1 $0, $31\n"
239 "adda.s $f0, $f1\n"
240 "sync\n"
241 "ctc1 $0, $31\n"
242 );
243 }
244
245 ////////////////////////////////////////////////////////////////////
246 //8000B840
247 ////////////////////////////////////////////////////////////////////
248 void InitializeScratchPad()
249 {
250 u128 *p;
251
252 for (p=(u128*)0x70000000; (u32)p<0x70004000; p++) *p=0;
253 }
254
255 ////////////////////////////////////////////////////////////////////
256 //8000B878
257 ////////////////////////////////////////////////////////////////////
258 void InitializeUserMemory(u32 base)
259 {
260 u128 *memsz;
261 u128 *p = (u128*)base;
262
263 for (memsz=(u128*)_GetMemorySize(); p<memsz; p++)
264 *p = 0;
265 }
266
267 ////////////////////////////////////////////////////////////////////
268 //8000B8D0
269 ////////////////////////////////////////////////////////////////////
270 void InitializeINTC(int a)
271 {
272 a &= 0xDFFD;
273 INTC_STAT &= a;
274 INTC_MASK &= a;
275 }
276
277 ////////////////////////////////////////////////////////////////////
278 //8000B900
279 ////////////////////////////////////////////////////////////////////
280 void InitializeTIMER()
281 {
282 RCNT0_MODE = 0xC00;
283 RCNT0_COUNT = 0;
284 RCNT0_TARGET = 0xFFFF;
285 RCNT0_HOLD = 0;
286
287 RCNT1_MODE = 0xC00;
288 RCNT1_COUNT = 0;
289 RCNT1_TARGET = 0xFFFF;
290 RCNT1_HOLD = 0;
291
292 RCNT2_MODE = 0xC80;
293 RCNT2_COUNT = 0;
294 RCNT2_TARGET = 0xFFFF;
295
296 RCNT3_MODE = 0xC83;
297 RCNT3_COUNT = 0;
298 RCNT3_TARGET = 0xFFFF;
299
300 InitializeINTC(0x1E00);
301 _InitRCNT3();
302 }
303
304 u32 tlb1_data[] = {
305 0x00000000, 0x70000000, 0x80000007, 0x00000007,
306 0x00006000, 0xFFFF8000, 0x00001E1F, 0x00001F1F,
307 0x00000000, 0x10000000, 0x00400017, 0x00400053,
308 0x00000000, 0x10002000, 0x00400097, 0x004000D7,
309 0x00000000, 0x10004000, 0x00400117, 0x00400157,
310 0x00000000, 0x10006000, 0x00400197, 0x004001D7,
311 0x00000000, 0x10008000, 0x00400217, 0x00400257,
312 0x00000000, 0x1000A000, 0x00400297, 0x004002D7,
313 0x00000000, 0x1000C000, 0x00400313, 0x00400357,
314 0x00000000, 0x1000E000, 0x00400397, 0x004003D7,
315 0x0001E000, 0x11000000, 0x00440017, 0x00440415,
316 0x0001E000, 0x12000000, 0x00480017, 0x00480415,
317 0x01FFE000, 0x1E000000, 0x00780017, 0x007C0017,
318 };
319
320 u32 tlb2_data[] = {
321 0x0007E000, 0x00080000, 0x0000201F, 0x0000301F,
322 0x0007E000, 0x00100000, 0x0000401F, 0x0000501F,
323 0x0007E000, 0x00180000, 0x0000601F, 0x0000701F,
324 0x001FE000, 0x00200000, 0x0000801F, 0x0000C01F,
325 0x001FE000, 0x00400000, 0x0001001F, 0x0001401F,
326 0x001FE000, 0x00600000, 0x0001801F, 0x0001C01F,
327 0x007FE000, 0x00800000, 0x0002001F, 0x0003001F,
328 0x007FE000, 0x01000000, 0x0004001F, 0x0005001F,
329 0x007FE000, 0x01800000, 0x0006001F, 0x0007001F,
330 0x0007E000, 0x20080000, 0x00002017, 0x00003017,
331 0x0007E000, 0x20100000, 0x00004017, 0x00005017,
332 0x0007E000, 0x20180000, 0x00006017, 0x00007017,
333 0x001FE000, 0x20200000, 0x00008017, 0x0000C017,
334 0x001FE000, 0x20400000, 0x00010017, 0x00014017,
335 0x001FE000, 0x20600000, 0x00018017, 0x0001C017,
336 0x007FE000, 0x20800000, 0x00020017, 0x00030017,
337 0x007FE000, 0x21000000, 0x00040017, 0x00050017,
338 0x007FE000, 0x21800000, 0x00060017, 0x00070017,
339 };
340
341 u32 tlb3_data[] = {
342 0x0007E000, 0x30100000, 0x0000403F, 0x0000503F,
343 0x0007E000, 0x30180000, 0x0000603F, 0x0000703F,
344 0x001FE000, 0x30200000, 0x0000803F, 0x0000C03F,
345 0x001FE000, 0x30400000, 0x0001003F, 0x0001403F,
346 0x001FE000, 0x30600000, 0x0001803F, 0x0001C03F,
347 0x007FE000, 0x30800000, 0x0002003F, 0x0003003F,
348 0x007FE000, 0x31000000, 0x0004003F, 0x0005003F,
349 0x007FE000, 0x31800000, 0x0006003F, 0x0007003F,
350 };
351
352 u32 tlb_config[] = {
353 0xD, 0x12, 8, 0,
354 0x80012708, 0x800127D8, 0x800128F8
355 };
356
357
358 void _TlbSet(u32 Index, u32 PageMask, u32 EntryHi, u32 EntryLo0, u32 EntryLo1) {
359 __asm__ (
360 "mtc0 $4, $0\n"
361 "mtc0 $5, $5\n"
362 "mtc0 $6, $10\n"
363 "mtc0 $7, $2\n"
364 "mtc0 $8, $3\n"
365 "sync\n"
366 "tlbwi\n"
367 "sync\n"
368 );
369 }
370
371 void TlbInit() {
372 int i, last;
373 u32 *ptr;
374
375 __printf("TlbInit... ");
376
377 __asm__ ("mtc0 $0, $6\n");
378
379 _TlbSet(1, 0, 0xE0000000, 0, 0);
380 for (i=2; i<48; i++) {
381 _TlbSet(i, 0, 0xE0002000, 0, 0);
382 }
383
384 last = tlb_config[0];
385 if (last > 48) {
386 __printf("# TLB over flow (1)\n");
387 }
388
389 ptr = (u32*)(tlb_config[4] + 0x10);
390 for (i=1; i<last; i++, ptr+= 4) {
391 _TlbSet(i, ptr[0], ptr[1], ptr[2], ptr[3]);
392 }
393
394 last = tlb_config[1] + i;
395 if (last > 48) {
396 __printf("# TLB over flow (2)\n");
397 }
398
399 if (tlb_config[1]) {
400 ptr = (u32*)(tlb_config[5]);
401 for (; i<last; i++, ptr+= 4) {
402 _TlbSet(i, ptr[0], ptr[1], ptr[2], ptr[3]);
403 }
404 }
405
406 __asm__ (
407 "mtc0 %0, $6\n"
408 "sync\n"
409 : : "r"(tlb_config[3])
410 );
411 // if (tlb_config[2] <= 0) return;
412
413 last = tlb_config[2] + i;
414 if (last > 48) {
415 __printf("# TLB over flow (3)\n");
416 }
417
418 ptr = (u32*)(tlb_config[6]);
419 for (; i<last; i++, ptr+= 4) {
420 _TlbSet(i, ptr[0], ptr[1], ptr[2], ptr[3]);
421 }
422 __printf("Ok\n");
423 }
424
425 void DefaultINTCHandler(int n);
426 void DefaultDMACHandler(int n);
427 void rcnt3Handler();
428 void sbusHandler();
429
430 ////////////////////////////////////////////////////////////////////
431 //80002050
432 ////////////////////////////////////////////////////////////////////
433 int InitPgifHandler() {
434 int i;
435
436 _HandlersCount = 0;
437
438 for (i=0; i<15; i++) {
439 intcs_array[i].count = 0;
440 // intcs_array[-1] = ihandlers_last,first
441 intcs_array[i-1].l.prev = (struct ll*)&intcs_array[i-1].l.next;
442 intcs_array[i-1].l.next = (struct ll*)&intcs_array[i-1].l.next;
443 setINTCHandler(i, DefaultINTCHandler);
444 }
445
446 setINTCHandler(12, rcnt3Handler);
447 setINTCHandler(1, sbusHandler);
448
449 for (i=0; i<32; i++) {
450 sbus_handlers[i] = 0;
451 }
452
453 __EnableIntc(INTC_SBUS);
454
455 for (i=0; i<16; i++) {
456 dmacs_array[i].count = 0;
457 dmacs_array[i-1].l.prev = (struct ll*)&dmacs_array[i-1].l.next;
458 dmacs_array[i-1].l.next = (struct ll*)&dmacs_array[i-1].l.next;
459 setDMACHandler(i, DefaultDMACHandler);
460 }
461
462 handler_ll_free.next = &handler_ll_free;
463 handler_ll_free.prev = &handler_ll_free;
464 for (i=0; i<160; i++) {
465 pgifhandlers_array[i+1].handler = 0;
466 pgifhandlers_array[i+1].flag = 3;
467 LL_add(&handler_ll_free, (struct ll*)&pgifhandlers_array[i+1].next);
468 }
469
470 return 0x81;
471 }
472
473 ////////////////////////////////////////////////////////////////////
474 //800021B0
475 // asme as InitPgifHandler except don't reset sbus
476 ////////////////////////////////////////////////////////////////////
477 int InitPgifHandler2()
478 {
479 int i;
480
481 _HandlersCount = 0;
482
483 for(i = 0; i < 15; ++i) {
484 if(i != 1 ) {
485 intcs_array[i].count = 0;
486 // intcs_array[-1] = ihandlers_last,first
487 intcs_array[i-1].l.prev = (struct ll*)&intcs_array[i-1].l.next;
488 intcs_array[i-1].l.next = (struct ll*)&intcs_array[i-1].l.next;
489 setINTCHandler(i, DefaultINTCHandler);
490 }
491 }
492
493 setINTCHandler(12, rcnt3Handler);
494
495 for (i=0; i<16; i++) {
496 dmacs_array[i].count = 0;
497 dmacs_array[i-1].l.prev = (struct ll*)&dmacs_array[i-1].l.next;
498 dmacs_array[i-1].l.next = (struct ll*)&dmacs_array[i-1].l.next;
499 setDMACHandler(i, DefaultDMACHandler);
500 }
501
502 handler_ll_free.next = &handler_ll_free;
503 handler_ll_free.prev = &handler_ll_free;
504 for (i=0; i<160; i++) {
505 pgifhandlers_array[i+1].handler = 0;
506 pgifhandlers_array[i+1].flag = 3;
507 LL_add(&handler_ll_free, (struct ll*)&pgifhandlers_array[i+1].next);
508 }
509
510 return 0x81;
511 }

  ViewVC Help
Powered by ViewVC 1.1.22