1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
|
/* #pragma comment(exestr, "@(#) NEC(MIPS) r94anmi.s 1.2 95/10/17 01:19:11" ) */
//
// TITLE("R94A NMI routine")
//++
//
// Copyright (c) 1995 NEC Corporation
//
// Module Name:
//
// r94anmi.s
//
// Abstract:
//
// This routine support for dump switch.
//
// Author:
//
// Akitoshi Kuriyama (NEC Software Kobe,Inc)
//
// Environment:
//
// Kernel mode only.
//
// R4400 based only.
//
// Revision History:
//
// kuriyama@oa2.kbnes.nec.co.jp Sun Oct 15 20:11:38 JST 1995
// - new code for J94D (!_MRCDUMP_ _MRCPOWER_ compile option need)
//
//--
#include "halmips.h"
SBTTL("NMI dispatch routine")
//++
//
// VOID
// HalpNMIDispatch (
// VOID
// )
//
// Routine Description:
//
// This function was called by firmware when NMI occuerd.
//
// Arguments:
//
// none.
//
// Return Value:
//
// none.
//
//--
LEAF_ENTRY(HalpNMIDispatch)
.set noreorder
.set noat
//
// Save temporary Registers for use.
// save area shoud have for every processros.
//
li k0,0xffffc070 // get processor number.
lw k0,(k0) //
bne k0,zero,10f //
nop // fill
la k1,HalpNMISave0 // set save address.
j 20f //
nop // fill
10:
la k1,HalpNMISave1 // set save address.
nop // 1 cycle hazzerd
20:
sw AT,0x0(k1) // register save.
sw v0,0x4(k1) //
sw v1,0x8(k1) //
sw a0,0xc(k1) //
sw a1,0x10(k1) //
sw a2,0x14(k1) //
sw a3,0x18(k1) //
sw t0,0x1c(k1) //
sw t1,0x20(k1) //
sw t2,0x24(k1) //
sw t3,0x28(k1) //
sw t4,0x2c(k1) //
sw t5,0x30(k1) //
sw t6,0x34(k1) //
sw t7,0x38(k1) //
sw t8,0x3c(k1) //
sw t9,0x40(k1) //
sw gp,0x44(k1) //
sw sp,0x48(k1) //
sw s8,0x4c(k1) //
sw ra,0x50(k1) //
mfc0 k0,psr //
nop //
nop //
sw k0,0x54(k1) //
nop //
mfc0 k0,cause //
nop //
nop //
sw k0,0x58(k1) //
nop //
mfc0 k0,epc //
nop //
nop //
sw k0,0x5c(k1) //
nop //
mfc0 k0,errorepc //
nop //
nop //
sw k0,0x60(k1) //
nop //
mfc0 k0,cacheerr //
nop //
nop //
sw k0,0x64(k1) //
sdc1 f0,0x68(k1) //
//
// Set Dump Switch Status register to tlb fixed entry
//
li t0,4 // set index 4(hurricane register)
li t1,0x80012 << 6 // set MRC register
li t2,0x8000e << 6 // set Self-Test address
mfc0 t3,index // save tlb registers
mfc0 t4,entryhi //
mfc0 t5,entrylo0 //
mfc0 t6,entrylo1 //
mfc0 t7,pagemask //
mtc0 t0,index //
nop
nop
nop
tlbr // read index 4 tlb
nop
nop
nop
nop
mfc0 t8,entrylo0 // Get entrylo0
mfc0 t9,entrylo1 // Get entrylo1
nop
nop
nop
or t1,t8,t1 // set MRC address
or t2,t8,t2 // set Self-test address
nop
mtc0 t1,entrylo0 // set MRC to tlb 4 0
mtc0 t2,entrylo1 // set Self-test to tlb 4 1
nop //
nop //
nop //
nop //
tlbwi // write to tlb entry
nop //
nop //
nop //
nop //
//
// read dump status
//
#if defined(_MRCDUMP_)
li t1,0xffffc108 // load MRC Mode value
#else // SELFTEST DUMP
li t1,0xffffd000 // load Self-Test value
li k0,0x1b // set dash
sb k0,(t1) // display led
sync
#endif // _MRCDUMP_
lb k0,(t1) // load Dump switch status.
nop //
lb k0,(t1) // wait
nop //
//
// Check dump status
//
li t1,2 // check for dump switch
and k0,k0,t1 //
#if defined(_MRCDUMP_)
beq k0,zero,30f // if 0 dump swith was not pressed
#else // _MRCDUMP_
bne k0,zero,30f // if 0 dump swith was pressed
#endif // _MRCDUMP_
nop //
#if !defined(_MRCDUMP_)
li t1,0xffffd000 // set dump switch status address
li t2,0x1b // display LED dash
sb t2,(t1) //
sync //
#endif // not _MRCDUMP_
//
// enable powoff NMI
//
#if defined(_MRCPOWER_)
li t1,0xffffc108 //
li t0,0x82 //
nop //
sb t0,(t1) //
nop //
li t0,0x80 //
nop //
sb t0,(t1) //
nop //
li t0,0x02 //
nop //
sb t0,(t1) //
nop //
#endif // _MRCPOWER_
//
// restore tlb 4 entry
//
mtc0 t8,entrylo0 // restore tlb 4 0
mtc0 t9,entrylo1 // restore tlb 4 1
nop //
nop //
nop //
nop //
tlbwi // write to tlb entry
nop //
nop //
nop //
nop //
//
// restore tlb registers
//
mtc0 t3,index //
mtc0 t4,entryhi //
mtc0 t5,entrylo0 //
mtc0 t6,entrylo1 //
mtc0 t7,pagemask //
#if !defined(_MRCDUMP_)
la k0,0xffffc5b8 // get NEC I/O port value
lb t0,(k0) //
nop // 1 cycle hazzerd
li t1,0xfd // clear dump enable bit
and t0,t0,t1
sb t0,(k0) // set NEC I/O port value
#endif // not _MRCDUMP_
//
// set NMI flag 1
//
la t2,HalpNMIFlag // set NMI flag address
li t3,0xa0000000 // set KSEG1_BASE
or t2,t2,t3 //
li t3,1 //
sw t3,(t2) // set NMI flag 1
//
// set dump flag 1
//
la t2,HalpDumpNMIFlag // set Dump NMI flag address
li t3,0xa0000000 // set KSEG1_BASE
or t2,t2,t3 //
li t3,1 //
sw t3,(t2) // set NMI flag 1
//
// clear psr BEV bit
//
mfc0 t0,psr // get psr
li t2,0xffbfffff // clear BEV bit
nop // fill
nop // fill
and t0,t0,t2 //
nop //
mtc0 t0,psr // set psr
lw t0,0x1c(k1) // restore temporary registers
lw t1,0x20(k1) //
lw t2,0x24(k1) //
lw t3,0x28(k1) //
lw t4,0x2c(k1) //
lw t5,0x30(k1) //
lw t6,0x34(k1) //
lw t7,0x38(k1) //
lw t8,0x3c(k1) //
lw t9,0x40(k1) //
lw AT,0x0(k1) //
eret // return to error epc
nop // errata
nop //
nop //
eret //
nop //
30:
//
// No Dump Switch.
//
// Check Power Switch
#if defined(_MRCPOWER_)
li t1,0xffffc108
nop
li t0,0x02
nop
sb t0,(t1)
nop
#endif // _MRCPOWER_
mtc0 t8,entrylo0 // restore tlb 4
mtc0 t9,entrylo1 // restore tlb 4
nop //
nop //
nop //
nop //
tlbwi // write to tlb entry
nop //
nop //
nop //
nop //
mtc0 t3,index // restore tlb registers
mtc0 t4,entryhi //
mtc0 t5,entrylo0 //
mtc0 t6,entrylo1 //
mtc0 t7,pagemask //
//
// set NMI flag 1
//
la t2,HalpNMIFlag // set NMI flag address
li t3,0xa0000000 // set KSEG1_BASE
or t2,t2,t3 //
li t3,1 //
sw t3,(t2) // set NMI flag 1
// S003 +++
li t1,0xffffc078 // check NMI source
lw t0,(t1) // check NMI source
nop //
beq t0,zero,40f //
nop //
li t1,0xffffc020
nop
ldc1 f0,(t1) // clear processor invalid
nop
sdc1 f0,0x70(k1) // save processor invalid
40:
// S003 ---
mfc0 t0,psr // get psr
li t2,0xffbfffff // clear BEV bit
nop // fill
nop // fill
and t0,t0,t2 //
nop //
mtc0 t0,psr // set psr
lw t0,0x1c(k1) // restore temporary registers
lw t1,0x20(k1) //
lw t2,0x24(k1) //
lw t3,0x28(k1) //
lw t4,0x2c(k1) //
lw t5,0x30(k1) //
lw t6,0x34(k1) //
lw t7,0x38(k1) //
lw t8,0x3c(k1) //
lw t9,0x40(k1) //
lw AT,0x0(k1) //
ldc1 f0,0x68(k1) //
nop
eret // return to errorepc
nop // errata
nop //
nop //
eret //
nop //
// L001 ---
.set at
.set reorder
.end HalpNMIDispatch
// Start M008
SBTTL("Software Power Off")
//++
//
// VOID
// HalpPowOffNMIDispatch (
// VOID
// )
//
// Routine Description:
//
// This function was called by firmware when NMI occuerd.
//
// Arguments:
//
// none.
//
// Return Value:
//
// none.
//
//--
LEAF_ENTRY(HalpPowOffNMIDispatch)
.set noat
.set noreorder
//
// Save temporary Registers for use.
// save area shoud have for every processros.
//
li k0,0xffffc070 // get processor number.
lw k0,(k0) //
bne k0,zero,60f //
nop // fill
la k1,HalpNMISave0 // set save address.
j 70f //
nop // fill
60:
la k1,HalpNMISave1 // set save address.
nop // 1 cycle hazzerd
70:
sw t0,0(k1) // save temporary registers
sw t1,4(k1) //
sw t2,8(k1) //
sw t3,12(k1) //
sw t4,16(k1) //
sw t5,20(k1) //
sw t6,24(k1) //
sw t7,28(k1) //
sw AT,32(k1) //
//
// Set Power Switch Status register to tlb fixed entry
//
li t0,4 // set index 4(hurricane register)
li t1,0x80012 << 6 // set MRC register
mfc0 t3,index // save tlb registers
mfc0 t4,entryhi //
mfc0 t5,entrylo0 //
mfc0 t6,entrylo1 //
mfc0 t7,pagemask //
mtc0 t0,index //
nop
nop
nop
tlbr // read index 4 tlb
nop
nop
nop
nop
mfc0 t2,entrylo0 // set Self-test address to tlb
nop
nop
nop
or t1,t2,t1
nop
mtc0 t1,entrylo0 // set Self-Test to tlb 4
nop //
nop //
nop //
nop //
tlbwi // write to tlb entry
nop //
nop //
nop //
nop //
li t1,0xffffc100 // load MRC Int value
nop
lb k0,(t1) // load Interrupt status.
nop
lb k0,(t1) // wait
nop
li t0,0x01 // set clear value
sb t0,(t1) // clear OffSw bit
li t1,0x4 // check for OffSw switch
nop //
and k0,k0,t1 //
beq k0,zero,80f // 0 means Power switch was not pressed
nop //
li t1,0xffffc130 // load MRC Software PowerOff Register
nop
lb t0,0x1 // set PowerOff Value
90:
sb t0,(t1) // write PowerOff bit
beq zero,zero,90b
nop
eret
nop
nop
nop
eret
nop
80:
//
// No Power Switch.
//
mtc0 t2,entrylo0 // restore tlb 4
nop //
nop //
nop //
nop //
tlbwi // write to tlb entry
nop //
nop //
nop //
nop //
mtc0 t3,index // restore tlb registers
mtc0 t4,entryhi //
mtc0 t5,entrylo0 //
mtc0 t6,entrylo1 //
mtc0 t7,pagemask //
la t2,HalpNMIFlag // set NMI flag address
li t3,0xa0000000 // set KSEG1_BASE
or t2,t2,t3 //
li t3,1 //
sw t3,(t2) // set NMI flag 1
lw t0,0xffffc078 // check NMI source
nop //
beq t0,zero,45f //
nop //
lw t0,0xffffc020 // clear processor invalid
45:
mfc0 t0,psr // get psr
li t2,0xffbfffff // clear BEV bit
nop // fill
nop // fill
and t0,t0,t2 //
nop //
mtc0 t0,psr // set psr
lw t0,0(k1) // restore temporary registers
lw t1,4(k1) //
lw t2,8(k1) //
lw t3,12(k1) //
lw t4,16(k1) //
lw t5,20(k1) //
lw t6,24(k1) //
lw t7,28(k1) //
lw AT,32(k1) //
eret // return to errorepc
nop // errata
nop //
nop //
eret //
nop //
.set reorder
.set at
.end HalpPowOffNMIDispatch
// End M008
|