]> git.saurik.com Git - apple/xnu.git/blob - osfmk/ppc/lowmem_vectors.s
xnu-201.5.tar.gz
[apple/xnu.git] / osfmk / ppc / lowmem_vectors.s
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25
26 /*
27 * Low-memory exception vector code for PowerPC MACH
28 *
29 * These are the only routines that are ever run with
30 * VM instruction translation switched off.
31 *
32 * The PowerPC is quite strange in that rather than having a set
33 * of exception vectors, the exception handlers are installed
34 * in well-known addresses in low memory. This code must be loaded
35 * at ZERO in physical memory. The simplest way of doing this is
36 * to load the kernel at zero, and specify this as the first file
37 * on the linker command line.
38 *
39 * When this code is loaded into place, it is loaded at virtual
40 * address KERNELBASE, which is mapped to zero (physical).
41 *
42 * This code handles all powerpc exceptions and is always entered
43 * in supervisor mode with translation off. It saves the minimum
44 * processor state before switching back on translation and
45 * jumping to the approprate routine.
46 *
47 * Vectors from 0x100 to 0x3fff occupy 0x100 bytes each (64 instructions)
48 *
49 * We use some of this space to decide which stack to use, and where to
50 * save the context etc, before jumping to a generic handler.
51 */
52
53 #include <assym.s>
54 #include <debug.h>
55 #include <cpus.h>
56 #include <db_machine_commands.h>
57 #include <mach_rt.h>
58
59 #include <mach_debug.h>
60 #include <ppc/asm.h>
61 #include <ppc/proc_reg.h>
62 #include <ppc/exception.h>
63 #include <ppc/Performance.h>
64 #include <mach/ppc/vm_param.h>
65 #include <ppc/POWERMAC/mp/MPPlugIn.h>
66
67 #define TRCSAVE 0
68 #define CHECKSAVE 0
69 #define PERFTIMES 0
70 #define ESPDEBUG 0
71
72 #if TRCSAVE
73 #error The TRCSAVE option is broken.... Fix it
74 #endif
75
76 #define featL1ena 24
77 #define featSMP 25
78 #define featAltivec 26
79 #define wasNapping 27
80 #define featFP 28
81
82 #define VECTOR_SEGMENT .section __VECTORS, __interrupts
83
84 VECTOR_SEGMENT
85
86
87 .globl EXT(ExceptionVectorsStart)
88
89 EXT(ExceptionVectorsStart): /* Used if relocating the exception vectors */
90 baseR: /* Used so we have more readable code */
91
92 /*
93 * System reset - call debugger
94 */
95 . = 0xf0
96 .globl EXT(ResetHandler)
97 EXT(ResetHandler):
98 .long 0x0
99 .long 0x0
100 .long 0x0
101
102 . = 0x100
103 .L_handler100:
104 mtsprg 2,r13 /* Save R13 */
105 mtsprg 3,r11 /* Save R11 */
106 lwz r13,lo16(EXT(ResetHandler)-EXT(ExceptionVectorsStart)+RESETHANDLER_TYPE)(br0) ; Get reset type
107 mfcr r11
108 cmpi cr0,r13,RESET_HANDLER_START
109 bne resetexc
110
111 li r11,RESET_HANDLER_NULL
112 stw r11,lo16(EXT(ResetHandler)-EXT(ExceptionVectorsStart)+RESETHANDLER_TYPE)(br0) ; Clear reset type
113
114 lwz r4,lo16(EXT(ResetHandler)-EXT(ExceptionVectorsStart)+RESETHANDLER_CALL)(br0)
115 lwz r3,lo16(EXT(ResetHandler)-EXT(ExceptionVectorsStart)+RESETHANDLER_ARG)(br0)
116 mtlr r4
117 blr
118
119 resetexc:
120 mtcr r11
121 mfsprg r13,1 /* Get the exception save area */
122 li r11,T_RESET /* Set 'rupt code */
123 b .L_exception_entry /* Join common... */
124
125 /*
126 * Machine check
127 */
128
129 . = 0x200
130 .L_handler200:
131 mtsprg 2,r13 /* Save R13 */
132 mtsprg 3,r11 /* Save R11 */
133 mfsprg r13,1 /* Get the exception save area */
134 li r11,T_MACHINE_CHECK /* Set 'rupt code */
135 b .L_exception_entry /* Join common... */
136
137 /*
138 * Data access - page fault, invalid memory rights for operation
139 */
140
141 . = 0x300
142 .L_handler300:
143 mtsprg 2,r13 /* Save R13 */
144 mtsprg 3,r11 /* Save R11 */
145 mfsprg r13,1 /* Get the exception save area */
146 li r11,T_DATA_ACCESS /* Set 'rupt code */
147 b .L_exception_entry /* Join common... */
148
149 /*
150 * Instruction access - as for data access
151 */
152
153 . = 0x400
154 .L_handler400:
155 mtsprg 2,r13 /* Save R13 */
156 mtsprg 3,r11 /* Save R11 */
157 mfsprg r13,1 /* Get the exception save area */
158 li r11,T_INSTRUCTION_ACCESS /* Set 'rupt code */
159 b .L_exception_entry /* Join common... */
160
161 /*
162 * External interrupt
163 */
164
165 . = 0x500
166 .L_handler500:
167 mtsprg 2,r13 /* Save R13 */
168 mtsprg 3,r11 /* Save R11 */
169 mfsprg r13,1 /* Get the exception save area */
170 li r11,T_INTERRUPT /* Set 'rupt code */
171 b .L_exception_entry /* Join common... */
172
173 /*
174 * Alignment - many reasons
175 */
176
177 . = 0x600
178 .L_handler600:
179 mtsprg 2,r13 /* Save R13 */
180 mtsprg 3,r11 /* Save R11 */
181 mfsprg r13,1 /* Get the exception save area */
182 li r11,T_ALIGNMENT /* Set 'rupt code */
183 b .L_exception_entry /* Join common... */
184
185 /*
186 * Program - floating point exception, illegal inst, priv inst, user trap
187 */
188
189 . = 0x700
190 .L_handler700:
191 mtsprg 2,r13 /* Save R13 */
192 mtsprg 3,r11 /* Save R11 */
193 mfsprg r13,1 /* Get the exception save area */
194 li r11,T_PROGRAM /* Set 'rupt code */
195 b .L_exception_entry /* Join common... */
196
197 /*
198 * Floating point disabled
199 */
200
201 . = 0x800
202 .L_handler800:
203 mtsprg 2,r13 /* Save R13 */
204 mtsprg 3,r11 /* Save R11 */
205 mfsprg r13,1 /* Get the exception save area */
206 li r11,T_FP_UNAVAILABLE /* Set 'rupt code */
207 b .L_exception_entry /* Join common... */
208
209
210 /*
211 * Decrementer - DEC register has passed zero.
212 */
213
214 . = 0x900
215 .L_handler900:
216 mtsprg 2,r13 /* Save R13 */
217 mtsprg 3,r11 /* Save R11 */
218 mfsprg r13,1 /* Get the exception save area */
219 li r11,T_DECREMENTER /* Set 'rupt code */
220 b .L_exception_entry /* Join common... */
221
222 /*
223 * I/O controller interface error - MACH does not use this
224 */
225
226 . = 0xA00
227 .L_handlerA00:
228 mtsprg 2,r13 /* Save R13 */
229 mtsprg 3,r11 /* Save R11 */
230 mfsprg r13,1 /* Get the exception save area */
231 li r11,T_IO_ERROR /* Set 'rupt code */
232 b .L_exception_entry /* Join common... */
233
234 /*
235 * Reserved
236 */
237
238 . = 0xB00
239 .L_handlerB00:
240 mtsprg 2,r13 /* Save R13 */
241 mtsprg 3,r11 /* Save R11 */
242 mfsprg r13,1 /* Get the exception save area */
243 li r11,T_RESERVED /* Set 'rupt code */
244 b .L_exception_entry /* Join common... */
245
246 #if 0
247 hackxxxx1:
248 stmw r29,4(br0)
249 lwz r29,0(br0)
250 mr. r29,r29
251 bne+ xxxx1
252 lis r29,0x4000
253
254 xxxx1:
255 stw r0,0(r29)
256 mfsrr0 r30
257 stw r30,4(r29)
258 mtlr r30
259 stw r30,8(r29)
260
261 addi r29,r29,12
262 stw r29,0(br0)
263
264 lmw r29,4(br0)
265 b hackxxxx2
266 #endif
267
268
269 ;
270 ; System call - generated by the sc instruction
271 ;
272 ; We handle the ultra-fast traps right here. They are:
273 ;
274 ; 0xFFFFFFFF - BlueBox only - MKIsPreemptiveTask
275 ; 0xFFFFFFFE - BlueBox only - kcNKIsPreemptiveTaskEnv
276 ; 0x00007FF2 - User state only - thread info
277 ; 0x00007FF3 - User state only - floating point / vector facility status
278 ; 0x00007FF4 - Kernel only - loadMSR
279 ;
280 ; Note: none handled if virtual machine is running
281 ;
282
283 . = 0xC00
284 .L_handlerC00:
285 mtsprg 2,r13 ; Save R13
286 mfsrr1 r13 ; Get SRR1 for loadMSR
287 mtsprg 3,r11 ; Save R11
288 mfcr r11 ; Save the CR
289 rlwinm. r13,r13,0,MSR_PR_BIT,MSR_PR_BIT ; From problem state?
290 mfsprg r13,0 ; Get the per_proc_area
291 beq- uftInKern ; We are in the kernel...
292
293 cmplwi cr5,r0,0x7FF2 ; Ultra fast path cthread info call?
294 cmpwi cr6,r0,0x7FF3 ; Ultra fast path facility status?
295 cror cr1_eq,cr5_lt,cr6_gt ; Set true if not 0x7FF2 and not 0x7FF3 and not negative
296 lwz r13,spcFlags(r13) ; Get the special flags
297 bt- cr1_eq,notufp ; Exit if we can not be ultra fast...
298
299 rlwimi r13,r13,runningVMbit+1,31,31 ; Move VM flag after the 3 blue box flags
300 not. r0,r0 ; Flip bits and kind of subtract 1
301 mtcrf 1,r13 ; Set BB and VMM flags in CR7
302
303 cmplwi cr1,r0,1 ; Is this a bb fast path?
304 not r0,r0 ; Restore to entry state
305 bt- 31,notufp ; No fast paths if running VM (assume not)...
306 bf- bbNoMachSCbit,ufpUSuft ; We are not running BlueBox...
307 bgt cr1,notufp ; This can not be a bb ufp...
308 #if 0
309 b hackxxxx1
310 hackxxxx2:
311 #endif
312
313 rlwimi r11,r13,bbPreemptivebit-cr0_eq,cr0_eq,cr0_eq ; Copy preemptive task flag into user cr0_eq
314 mfsprg r13,0 ; Get back pre_proc
315
316
317 bne cr1,ufpIsBBpre ; This is the "isPreemptiveTask" call...
318
319 lwz r0,ppbbTaskEnv(r13) ; Get the shadowed taskEnv from per_proc_area
320
321 ufpIsBBpre:
322 mtcrf 0xFF,r11 ; Restore CR
323 mfsprg r11,3 ; Restore R11
324 mfsprg r13,2 ; Restore R13
325 rfi ; All done, go back...
326
327 ;
328 ; Normal fast path...
329 ;
330
331 ufpUSuft: bge+ notufp ; Bail if negative... (ARRRGGG -- BRANCH TO A BRANCH!!!!!)
332 mfsprg r11,3 ; Restore R11
333 mfsprg r3,0 ; Get the per_proc_area
334 mfsprg r13,2 ; Restore R13
335 bne- cr5,isvecfp ; This is the facility stat call
336 lwz r3,UAW(r3) ; Get the assist word
337 rfi ; All done, scream back... (no need to restore CR or R11, they are volatile)
338 ;
339 isvecfp: lwz r3,spcFlags(r3) ; Get the facility status
340 rfi ; Bail back...
341 ;
342 notufp: mtcrf 0xFF,r11 ; Restore the used CRs
343 li r11,T_SYSTEM_CALL ; Set interrupt code
344 mfsprg r13,1 ; Get the exception save area
345 b .L_exception_entry ; Join common...
346
347 uftInKern: cmplwi r0,0x7FF4 ; Ultra fast path loadMSR?
348 bne- notufp ; Someone is trying to cheat...
349
350 mtcrf 0xFF,r11 ; Restore CR
351 lwz r11,pfAvailable(r13) ; Pick up the feature flags
352 mtsrr1 r3 ; Set new MSR
353 mfsprg r13,2 ; Restore R13
354 mtsprg 2,r11 ; Set the feature flags into sprg2
355 mfsprg r11,3 ; Restore R11
356 rfi ; Blast back
357
358
359 /*
360 * Trace - generated by single stepping
361 * performance monitor BE branch enable tracing/logging
362 * is also done here now. while this is permanently in the
363 * system the impact is completely unnoticable as this code is
364 * only executed when (a) a single step or branch exception is
365 * hit, (b) in the single step debugger case there is so much
366 * overhead already the few extra instructions for testing for BE
367 * are not even noticable, (c) the BE logging code is *only* run
368 * when it is enabled by the tool which will not happen during
369 * normal system usage
370 *
371 * Note that this trace is available only to user state so we do not
372 * need to set sprg2 before returning.
373 */
374
375 . = 0xD00
376 .L_handlerD00:
377 mtsprg 2,r13 ; Save R13
378 mtsprg 3,r11 ; Save R11
379 mfsrr1 r13 ; Get the old MSR
380 mfcr r11 ; Get the CR
381 rlwinm. r13,r13,0,MSR_PR_BIT,MSR_PR_BIT ; Are we in supervisor state?
382 beq- notspectr ; Yes, not special trace...
383 mfsprg r13,0 ; Get the per_proc area
384 lhz r13,PP_CPU_FLAGS(r13) ; Get the flags
385 rlwinm. r13,r13,0,traceBEb+16,traceBEb+16 ; Special trace enabled?
386 bne+ specbrtr ; Yeah...
387
388 notspectr: mtcr r11 ; Restore CR
389 mfsprg r13,1 ; Get the savearea
390 li r11,T_TRACE ; Set interrupt code
391 b .L_exception_entry ; Join common...
392
393 ;
394 ; We are doing the special branch trace
395 ;
396
397 specbrtr: mfsprg r13,0 ; Get the per_proc area
398 stw r1,emfp0(r13) ; Save in a scratch area
399 stw r2,emfp0+4(r13) ; Save in a scratch area
400 stw r3,emfp0+8(r13) ; Save in a scratch area
401
402 lis r2,hi16(EXT(pc_trace_buf)) ; Get the top of the buffer
403 lwz r3,spcTRp(r13) ; Pick up buffer position
404 mr. r1,r1 ; Is it time to count?
405 ori r2,r2,lo16(EXT(pc_trace_buf)) ; Get the bottom of the buffer
406 cmplwi cr1,r3,4092 ; Set cr1_eq if we should take exception
407 mfsrr0 r1 ; Get the pc
408 stwx r1,r2,r3 ; Save it in the buffer
409 addi r3,r3,4 ; Point to the next slot
410 rlwinm r3,r3,0,20,31 ; Wrap the slot at one page
411 stw r3,spcTRp(r13) ; Save the new slot
412 lwz r1,emfp0(r13) ; Restore work register
413 lwz r2,emfp0+4(r13) ; Restore work register
414 lwz r3,emfp0+8(r13) ; Restore work register
415 beq cr1,notspectr ; Buffer filled, make a rupt...
416
417 mtcr r11 ; Restore the CR
418 mfsprg r13,2 ; Restore R13
419 mfsprg r11,3 ; Restore R11
420 rfi ; Bail back...
421
422 /*
423 * Floating point assist
424 */
425
426 . = 0xe00
427 .L_handlerE00:
428 mtsprg 2,r13 /* Save R13 */
429 mtsprg 3,r11 /* Save R11 */
430 mfsprg r13,1 /* Get the exception save area */
431 li r11,T_FP_ASSIST /* Set 'rupt code */
432 b .L_exception_entry /* Join common... */
433
434
435 /*
436 * Performance monitor interruption
437 */
438
439 . = 0xF00
440 PMIhandler:
441 mtsprg 2,r13 /* Save R13 */
442 mtsprg 3,r11 /* Save R11 */
443 mfsprg r13,1 /* Get the exception save area */
444 li r11,T_PERF_MON /* Set 'rupt code */
445 b .L_exception_entry /* Join common... */
446
447
448 /*
449 * VMX exception
450 */
451
452 . = 0xF20
453 VMXhandler:
454 mtsprg 2,r13 /* Save R13 */
455 mtsprg 3,r11 /* Save R11 */
456 mfsprg r13,1 /* Get the exception save area */
457 li r11,T_VMX /* Set 'rupt code */
458 b .L_exception_entry /* Join common... */
459
460
461
462 /*
463 * Instruction translation miss - we inline this code.
464 * Upon entry (done for us by the machine):
465 * srr0 : addr of instruction that missed
466 * srr1 : bits 0-3 = saved CR0
467 * 4 = lru way bit
468 * 16-31 = saved msr
469 * msr[tgpr] = 1 (so gpr0-3 become our temporary variables)
470 * imiss: ea that missed
471 * icmp : the compare value for the va that missed
472 * hash1: pointer to first hash pteg
473 * hash2: pointer to 2nd hash pteg
474 *
475 * Register usage:
476 * tmp0: saved counter
477 * tmp1: junk
478 * tmp2: pointer to pteg
479 * tmp3: current compare value
480 *
481 * This code is taken from the 603e User's Manual with
482 * some bugfixes and minor improvements to save bytes and cycles
483 *
484 * NOTE: Do not touch sprg2 in here
485 */
486
487 . = 0x1000
488 .L_handler1000:
489 mfspr tmp2, hash1
490 mfctr tmp0 /* use tmp0 to save ctr */
491 mfspr tmp3, icmp
492
493 .L_imiss_find_pte_in_pteg:
494 li tmp1, 8 /* count */
495 subi tmp2, tmp2, 8 /* offset for lwzu */
496 mtctr tmp1 /* count... */
497
498 .L_imiss_pteg_loop:
499 lwz tmp1, 8(tmp2) /* check pte0 for match... */
500 addi tmp2, tmp2, 8
501 cmpw cr0, tmp1, tmp3
502 #if 0
503 bdnzf+ cr0, .L_imiss_pteg_loop
504 #else
505 bc 0,2, .L_imiss_pteg_loop
506 #endif
507 beq+ cr0, .L_imiss_found_pte
508
509 /* Not found in PTEG, we must scan 2nd then give up */
510
511 andi. tmp1, tmp3, MASK(PTE0_HASH_ID)
512 bne- .L_imiss_do_no_hash_exception /* give up */
513
514 mfspr tmp2, hash2
515 ori tmp3, tmp3, MASK(PTE0_HASH_ID)
516 b .L_imiss_find_pte_in_pteg
517
518 .L_imiss_found_pte:
519
520 lwz tmp1, 4(tmp2) /* get pte1_t */
521 andi. tmp3, tmp1, MASK(PTE1_WIMG_GUARD) /* Fault? */
522 bne- .L_imiss_do_prot_exception /* Guarded - illegal */
523
524 /* Ok, we've found what we need to, restore and rfi! */
525
526 mtctr tmp0 /* restore ctr */
527 mfsrr1 tmp3
528 mfspr tmp0, imiss
529 mtcrf 0x80, tmp3 /* Restore CR0 */
530 mtspr rpa, tmp1 /* set the pte */
531 ori tmp1, tmp1, MASK(PTE1_REFERENCED) /* set referenced */
532 tlbli tmp0
533 sth tmp1, 6(tmp2)
534 rfi
535
536 .L_imiss_do_prot_exception:
537 /* set up srr1 to indicate protection exception... */
538 mfsrr1 tmp3
539 andi. tmp2, tmp3, 0xffff
540 addis tmp2, tmp2, MASK(SRR1_TRANS_PROT) >> 16
541 b .L_imiss_do_exception
542
543 .L_imiss_do_no_hash_exception:
544 /* clean up registers for protection exception... */
545 mfsrr1 tmp3
546 andi. tmp2, tmp3, 0xffff
547 addis tmp2, tmp2, MASK(SRR1_TRANS_HASH) >> 16
548
549 /* And the entry into the usual instruction fault handler ... */
550 .L_imiss_do_exception:
551
552 mtctr tmp0 /* Restore ctr */
553 mtsrr1 tmp2 /* Set up srr1 */
554 mfmsr tmp0
555 xoris tmp0, tmp0, MASK(MSR_TGPR)>>16 /* no TGPR */
556 mtcrf 0x80, tmp3 /* Restore CR0 */
557 mtmsr tmp0 /* reset MSR[TGPR] */
558 b .L_handler400 /* Instr Access */
559
560 /*
561 * Data load translation miss
562 *
563 * Upon entry (done for us by the machine):
564 * srr0 : addr of instruction that missed
565 * srr1 : bits 0-3 = saved CR0
566 * 4 = lru way bit
567 * 5 = 1 if store
568 * 16-31 = saved msr
569 * msr[tgpr] = 1 (so gpr0-3 become our temporary variables)
570 * dmiss: ea that missed
571 * dcmp : the compare value for the va that missed
572 * hash1: pointer to first hash pteg
573 * hash2: pointer to 2nd hash pteg
574 *
575 * Register usage:
576 * tmp0: saved counter
577 * tmp1: junk
578 * tmp2: pointer to pteg
579 * tmp3: current compare value
580 *
581 * This code is taken from the 603e User's Manual with
582 * some bugfixes and minor improvements to save bytes and cycles
583 *
584 * NOTE: Do not touch sprg2 in here
585 */
586
587 . = 0x1100
588 .L_handler1100:
589 mfspr tmp2, hash1
590 mfctr tmp0 /* use tmp0 to save ctr */
591 mfspr tmp3, dcmp
592
593 .L_dlmiss_find_pte_in_pteg:
594 li tmp1, 8 /* count */
595 subi tmp2, tmp2, 8 /* offset for lwzu */
596 mtctr tmp1 /* count... */
597
598 .L_dlmiss_pteg_loop:
599 lwz tmp1, 8(tmp2) /* check pte0 for match... */
600 addi tmp2, tmp2, 8
601 cmpw cr0, tmp1, tmp3
602 #if 0 /* How to write this correctly? */
603 bdnzf+ cr0, .L_dlmiss_pteg_loop
604 #else
605 bc 0,2, .L_dlmiss_pteg_loop
606 #endif
607 beq+ cr0, .L_dmiss_found_pte
608
609 /* Not found in PTEG, we must scan 2nd then give up */
610
611 andi. tmp1, tmp3, MASK(PTE0_HASH_ID) /* already at 2nd? */
612 bne- .L_dmiss_do_no_hash_exception /* give up */
613
614 mfspr tmp2, hash2
615 ori tmp3, tmp3, MASK(PTE0_HASH_ID)
616 b .L_dlmiss_find_pte_in_pteg
617
618 .L_dmiss_found_pte:
619
620 lwz tmp1, 4(tmp2) /* get pte1_t */
621
622 /* Ok, we've found what we need to, restore and rfi! */
623
624 mtctr tmp0 /* restore ctr */
625 mfsrr1 tmp3
626 mfspr tmp0, dmiss
627 mtcrf 0x80, tmp3 /* Restore CR0 */
628 mtspr rpa, tmp1 /* set the pte */
629 ori tmp1, tmp1, MASK(PTE1_REFERENCED) /* set referenced */
630 tlbld tmp0 /* load up tlb */
631 sth tmp1, 6(tmp2) /* sth is faster? */
632 rfi
633
634 /* This code is shared with data store translation miss */
635
636 .L_dmiss_do_no_hash_exception:
637 /* clean up registers for protection exception... */
638 mfsrr1 tmp3
639 /* prepare to set DSISR_WRITE_BIT correctly from srr1 info */
640 rlwinm tmp1, tmp3, 9, 6, 6
641 addis tmp1, tmp1, MASK(DSISR_HASH) >> 16
642
643 /* And the entry into the usual data fault handler ... */
644
645 mtctr tmp0 /* Restore ctr */
646 andi. tmp2, tmp3, 0xffff /* Clean up srr1 */
647 mtsrr1 tmp2 /* Set srr1 */
648 mtdsisr tmp1
649 mfspr tmp2, dmiss
650 mtdar tmp2
651 mfmsr tmp0
652 xoris tmp0, tmp0, MASK(MSR_TGPR)>>16 /* no TGPR */
653 mtcrf 0x80, tmp3 /* Restore CR0 */
654 sync /* Needed on some */
655 mtmsr tmp0 /* reset MSR[TGPR] */
656 b .L_handler300 /* Data Access */
657
658 /*
659 * Data store translation miss (similar to data load)
660 *
661 * Upon entry (done for us by the machine):
662 * srr0 : addr of instruction that missed
663 * srr1 : bits 0-3 = saved CR0
664 * 4 = lru way bit
665 * 5 = 1 if store
666 * 16-31 = saved msr
667 * msr[tgpr] = 1 (so gpr0-3 become our temporary variables)
668 * dmiss: ea that missed
669 * dcmp : the compare value for the va that missed
670 * hash1: pointer to first hash pteg
671 * hash2: pointer to 2nd hash pteg
672 *
673 * Register usage:
674 * tmp0: saved counter
675 * tmp1: junk
676 * tmp2: pointer to pteg
677 * tmp3: current compare value
678 *
679 * This code is taken from the 603e User's Manual with
680 * some bugfixes and minor improvements to save bytes and cycles
681 *
682 * NOTE: Do not touch sprg2 in here
683 */
684
685 . = 0x1200
686 .L_handler1200:
687 mfspr tmp2, hash1
688 mfctr tmp0 /* use tmp0 to save ctr */
689 mfspr tmp3, dcmp
690
691 .L_dsmiss_find_pte_in_pteg:
692 li tmp1, 8 /* count */
693 subi tmp2, tmp2, 8 /* offset for lwzu */
694 mtctr tmp1 /* count... */
695
696 .L_dsmiss_pteg_loop:
697 lwz tmp1, 8(tmp2) /* check pte0 for match... */
698 addi tmp2, tmp2, 8
699
700 cmpw cr0, tmp1, tmp3
701 #if 0 /* I don't know how to write this properly */
702 bdnzf+ cr0, .L_dsmiss_pteg_loop
703 #else
704 bc 0,2, .L_dsmiss_pteg_loop
705 #endif
706 beq+ cr0, .L_dsmiss_found_pte
707
708 /* Not found in PTEG, we must scan 2nd then give up */
709
710 andi. tmp1, tmp3, MASK(PTE0_HASH_ID) /* already at 2nd? */
711 bne- .L_dmiss_do_no_hash_exception /* give up */
712
713 mfspr tmp2, hash2
714 ori tmp3, tmp3, MASK(PTE0_HASH_ID)
715 b .L_dsmiss_find_pte_in_pteg
716
717 .L_dsmiss_found_pte:
718
719 lwz tmp1, 4(tmp2) /* get pte1_t */
720 andi. tmp3, tmp1, MASK(PTE1_CHANGED) /* unchanged, check? */
721 beq- .L_dsmiss_check_prot /* yes, check prot */
722
723 .L_dsmiss_resolved:
724 /* Ok, we've found what we need to, restore and rfi! */
725
726 mtctr tmp0 /* restore ctr */
727 mfsrr1 tmp3
728 mfspr tmp0, dmiss
729 mtcrf 0x80, tmp3 /* Restore CR0 */
730 mtspr rpa, tmp1 /* set the pte */
731 tlbld tmp0 /* load up tlb */
732 rfi
733
734 .L_dsmiss_check_prot:
735 /* PTE is unchanged, we must check that we can write */
736 rlwinm. tmp3, tmp1, 30, 0, 1 /* check PP[1] */
737 bge- .L_dsmiss_check_prot_user_kern
738 andi. tmp3, tmp1, 1 /* check PP[0] */
739 beq+ .L_dsmiss_check_prot_ok
740
741 .L_dmiss_do_prot_exception:
742 /* clean up registers for protection exception... */
743 mfsrr1 tmp3
744 /* prepare to set DSISR_WRITE_BIT correctly from srr1 info */
745 rlwinm tmp1, tmp3, 9, 6, 6
746 addis tmp1, tmp1, MASK(DSISR_PROT) >> 16
747
748 /* And the entry into the usual data fault handler ... */
749
750 mtctr tmp0 /* Restore ctr */
751 andi. tmp2, tmp3, 0xffff /* Clean up srr1 */
752 mtsrr1 tmp2 /* Set srr1 */
753 mtdsisr tmp1
754 mfspr tmp2, dmiss
755 mtdar tmp2
756 mfmsr tmp0
757 xoris tmp0, tmp0, MASK(MSR_TGPR)>>16 /* no TGPR */
758 mtcrf 0x80, tmp3 /* Restore CR0 */
759 sync /* Needed on some */
760 mtmsr tmp0 /* reset MSR[TGPR] */
761 b .L_handler300 /* Data Access */
762
763 /* NB - if we knew we were on a 603e we could test just the MSR_KEY bit */
764 .L_dsmiss_check_prot_user_kern:
765 mfsrr1 tmp3
766 andi. tmp3, tmp3, MASK(MSR_PR)
767 beq+ .L_dsmiss_check_prot_kern
768 mfspr tmp3, dmiss /* check user privs */
769 mfsrin tmp3, tmp3 /* get excepting SR */
770 andis. tmp3, tmp3, 0x2000 /* Test SR ku bit */
771 beq+ .L_dsmiss_check_prot_ok
772 b .L_dmiss_do_prot_exception
773
774 .L_dsmiss_check_prot_kern:
775 mfspr tmp3, dmiss /* check kern privs */
776 mfsrin tmp3, tmp3
777 andis. tmp3, tmp3, 0x4000 /* Test SR Ks bit */
778 bne- .L_dmiss_do_prot_exception
779
780 .L_dsmiss_check_prot_ok:
781 /* Ok, mark as referenced and changed before resolving the fault */
782 ori tmp1, tmp1, (MASK(PTE1_REFERENCED)|MASK(PTE1_CHANGED))
783 sth tmp1, 6(tmp2)
784 b .L_dsmiss_resolved
785
786 /*
787 * Instruction address breakpoint
788 */
789
790 . = 0x1300
791 .L_handler1300:
792 mtsprg 2,r13 /* Save R13 */
793 mtsprg 3,r11 /* Save R11 */
794 mfsprg r13,1 /* Get the exception save area */
795 li r11,T_INSTRUCTION_BKPT /* Set 'rupt code */
796 b .L_exception_entry /* Join common... */
797
798 /*
799 * System management interrupt
800 */
801
802 . = 0x1400
803 .L_handler1400:
804 mtsprg 2,r13 /* Save R13 */
805 mtsprg 3,r11 /* Save R11 */
806 mfsprg r13,1 /* Get the exception save area */
807 li r11,T_SYSTEM_MANAGEMENT /* Set 'rupt code */
808 b .L_exception_entry /* Join common... */
809
810 ;
811 ; Altivec Java Mode Assist interrupt
812 ;
813
814 . = 0x1600
815 .L_handler1600:
816 mtsprg 2,r13 /* Save R13 */
817 mtsprg 3,r11 /* Save R11 */
818 mfsprg r13,1 /* Get the exception save area */
819 li r11,T_ALTIVEC_ASSIST /* Set 'rupt code */
820 b .L_exception_entry /* Join common... */
821
822 ;
823 ; Thermal interruption
824 ;
825
826 . = 0x1700
827 .L_handler1700:
828 mtsprg 2,r13 /* Save R13 */
829 mtsprg 3,r11 /* Save R11 */
830 mfsprg r13,1 /* Get the exception save area */
831 li r11,T_THERMAL /* Set 'rupt code */
832 b .L_exception_entry /* Join common... */
833
834 /*
835 * There is now a large gap of reserved traps
836 */
837
838 /*
839 * Run mode/ trace exception - single stepping on 601 processors
840 */
841
842 . = 0x2000
843 .L_handler2000:
844 mtsprg 2,r13 /* Save R13 */
845 mtsprg 3,r11 /* Save R11 */
846 mfsprg r13,1 /* Get the exception save area */
847 li r11,T_RUNMODE_TRACE /* Set 'rupt code */
848 b .L_exception_entry /* Join common... */
849
850 /*
851 * .L_exception_entry(type)
852 *
853 * This is the common exception handling routine called by any
854 * type of system exception.
855 *
856 * ENTRY: via a system exception handler, thus interrupts off, VM off.
857 * r3 has been saved in sprg3 and now contains a number
858 * representing the exception's origins
859 *
860 */
861
862 .data
863 .align ALIGN
864 .globl EXT(exception_entry)
865 EXT(exception_entry):
866 .long .L_exception_entry-EXT(ExceptionVectorsStart) /* phys addr of fn */
867
868 VECTOR_SEGMENT
869 .align 5
870
871 .L_exception_entry:
872
873 /*
874 *
875 * Here we will save off a mess of registers, the special ones and R0-R12. We use the DCBZ
876 * instruction to clear and allcoate a line in the cache. This way we won't take any cache
877 * misses, so these stores won't take all that long. Except the first line that is because
878 * we can't do a DCBZ if the L1 D-cache is off. The rest we will skip if they are
879 * off also.
880 *
881 * Note that if we are attempting to sleep (as opposed to nap or doze) all interruptions
882 * are ignored.
883 */
884
885 stw r1,saver1(r13) ; Save register 1
886 stw r0,saver0(r13) ; Save register 0
887 mfspr r1,hid0 ; Get HID0
888 mfcr r0 ; Save the CR
889 mtcrf 255,r1 ; Get set to test for cache and sleep
890 bf sleep,notsleep ; Skip if we are not trying to sleep
891
892 mtcrf 255,r0 ; Restore the CR
893 lwz r0,saver0(r13) ; Restore R0
894 lwz r1,saver1(r13) ; Restore R1
895 mfsprg r13,0 ; Get the per_proc
896 lwz r11,pfAvailable(r13) ; Get back the feature flags
897 mfsprg r13,2 ; Restore R13
898 mtsprg 2,r11 ; Set sprg2 to the features
899 mfsprg r11,3 ; Restore R11
900 rfi ; Jump back into sleep code...
901 .long 0 ; Leave these here please...
902 .long 0
903 .long 0
904 .long 0
905 .long 0
906 .long 0
907 .long 0
908 .long 0
909
910 .align 5
911
912 notsleep: stw r2,saver2(r13) ; Save this one
913 crmove featL1ena,dce ; Copy the cache enable bit
914 rlwinm r2,r1,0,nap+1,doze-1 ; Clear any possible nap and doze bits
915 mtspr hid0,r2 ; Clear the nap/doze bits
916 cmplw r2,r1 ; See if we were napping
917 li r1,32 ; Point to the next line in case we need it
918 crnot wasNapping,cr0_eq ; Remember if we were napping
919 mfsprg r2,0 ; Get the per_proc area
920 bf- featL1ena,skipz1 ; L1 cache is disabled...
921 dcbz r1,r13 ; Reserve our line in cache
922
923 ;
924 ; Remember, we are setting up CR6 with feature flags
925 ;
926 skipz1: lwz r1,pfAvailable(r2) ; Get the CPU features flags
927 stw r3,saver3(r13) ; Save this one
928 mtcrf 0xE0,r1 ; Put the features flags (that we care about) in the CR
929 stw r4,saver4(r13) ; Save this one
930 stw r6,saver6(r13) ; Save this one
931 crmove featSMP,pfSMPcapb ; See if we have a PIR
932 stw r8,saver8(r13) ; Save this one
933 crmove featAltivec,pfAltivecb ; Set the Altivec flag
934 mfsrr0 r6 /* Get the interruption SRR0 */
935 stw r8,saver8(r13) /* Save this one */
936 crmove featFP,pfFloatb ; Remember that we have floating point
937 stw r7,saver7(r13) /* Save this one */
938 lhz r8,PP_CPU_FLAGS(r2) ; Get the flags
939 mfsrr1 r7 /* Get the interrupt SRR1 */
940 rlwinm r8,r8,(((31-MSR_BE_BIT)+(traceBEb+16+1))&31),MSR_BE_BIT,MSR_BE_BIT ; Set BE bit if special trace is on
941 stw r6,savesrr0(r13) /* Save the SRR0 */
942 rlwinm r6,r7,(((31-MSR_BE_BIT)+(MSR_PR_BIT+1))&31),MSR_BE_BIT,MSR_BE_BIT ; Move PR bit to BE bit
943 stw r5,saver5(r13) /* Save this one */
944 and r8,r6,r8 ; Remove BE bit only if problem state and special tracing on
945 mfsprg r6,2 ; Get interrupt time R13
946 mtsprg 2,r1 ; Set the feature flags
947 andc r7,r7,r8 ; Clear BE bit if special trace is on and PR is set
948 mfsprg r8,3 /* Get 'rupt time R11 */
949 stw r7,savesrr1(r13) /* Save SRR1 */
950 stw r6,saver13(r13) /* Save 'rupt R1 */
951 stw r8,saver11(r13) /* Save 'rupt time R11 */
952
953 getTB: mftbu r6 ; Get the upper timebase
954 mftb r7 ; Get the lower timebase
955 mftbu r8 ; Get the upper one again
956 cmplw r6,r8 ; Did the top tick?
957 bne- getTB ; Yeah, need to get it again...
958
959 stw r8,ruptStamp(r2) ; Save the top of time stamp
960 la r6,saver14(r13) ; Point to the next cache line
961 stw r7,ruptStamp+4(r2) ; Save the bottom of time stamp
962 bf- featL1ena,skipz2 ; L1 cache is disabled...
963 dcbz 0,r6 /* Allocate in cache */
964 skipz2:
965 stw r9,saver9(r13) /* Save this one */
966
967 la r9,saver30(r13) /* Point to the trailing end */
968 stw r10,saver10(r13) /* Save this one */
969 mflr r4 /* Get the LR */
970 mfxer r10 ; Get the XER
971
972 bf+ wasNapping,notNapping ; Skip if not waking up from nap...
973
974 lwz r6,napStamp+4(r2) ; Pick up low order nap stamp
975 lis r3,hi16(EXT(machine_idle_ret)) ; Get high part of nap/doze return
976 lwz r5,napStamp(r2) ; and high order
977 subfc r7,r6,r7 ; Subtract low stamp from now
978 lwz r6,napTotal+4(r2) ; Pick up low total
979 subfe r5,r5,r8 ; Subtract high stamp and borrow from now
980 lwz r8,napTotal(r2) ; Pick up the high total
981 addc r6,r6,r7 ; Add low to total
982 ori r3,r3,lo16(EXT(machine_idle_ret)) ; Get low part of nap/doze return
983 adde r8,r8,r5 ; Add high and carry to total
984 stw r6,napTotal+4(r2) ; Save the low total
985 stw r8,napTotal(r2) ; Save the high total
986 stw r3,savesrr0(r13) ; Modify to return to nap/doze exit
987
988 notNapping: stw r12,saver12(r13) /* Save this one */
989
990 bf- featL1ena,skipz3 ; L1 cache is disabled...
991 dcbz 0,r9 /* Allocate the last in the area */
992 skipz3:
993 stw r14,saver14(r13) /* Save this one */
994 stw r15,saver15(r13) /* Save this one */
995 la r14,saver22(r13) /* Point to the next block to save into */
996 stw r0,savecr(r13) ; Save rupt CR
997 mfctr r6 /* Get the CTR */
998 stw r16,saver16(r13) /* Save this one */
999 stw r4,savelr(r13) /* Save 'rupt LR */
1000
1001 bf- featL1ena,skipz4 ; L1 cache is disabled...
1002 dcbz 0,r14 /* Allocate next save area line */
1003 skipz4:
1004 stw r17,saver17(r13) /* Save this one */
1005 stw r18,saver18(r13) /* Save this one */
1006 stw r6,savectr(r13) /* Save 'rupt CTR */
1007 stw r19,saver19(r13) /* Save this one */
1008 lis r12,HIGH_ADDR(KERNEL_SEG_REG0_VALUE) /* Get the high half of the kernel SR0 value */
1009 mfdar r6 /* Get the 'rupt DAR */
1010 stw r20,saver20(r13) /* Save this one */
1011 #if 0
1012 mfsr r14,sr0 ; (TEST/DEBUG)
1013 stw r14,savesr0(r13) ; (TEST/DEBUG)
1014 mfsr r14,sr1 ; (TEST/DEBUG)
1015 stw r14,savesr1(r13) ; (TEST/DEBUG)
1016 mfsr r14,sr2 ; (TEST/DEBUG)
1017 stw r14,savesr2(r13) ; (TEST/DEBUG)
1018 mfsr r14,sr3 ; (TEST/DEBUG)
1019 stw r14,savesr3(r13) ; (TEST/DEBUG)
1020 mfsr r14,sr4 ; (TEST/DEBUG)
1021 stw r14,savesr4(r13) ; (TEST/DEBUG)
1022 mfsr r14,sr5 ; (TEST/DEBUG)
1023 stw r14,savesr5(r13) ; (TEST/DEBUG)
1024 mfsr r14,sr6 ; (TEST/DEBUG)
1025 stw r14,savesr6(r13) ; (TEST/DEBUG)
1026 mfsr r14,sr7 ; (TEST/DEBUG)
1027 stw r14,savesr7(r13) ; (TEST/DEBUG)
1028 mfsr r14,sr8 ; (TEST/DEBUG)
1029 stw r14,savesr8(r13) ; (TEST/DEBUG)
1030 mfsr r14,sr9 ; (TEST/DEBUG)
1031 stw r14,savesr9(r13) ; (TEST/DEBUG)
1032 mfsr r14,sr10 ; (TEST/DEBUG)
1033 stw r14,savesr10(r13) ; (TEST/DEBUG)
1034 mfsr r14,sr11 ; (TEST/DEBUG)
1035 stw r14,savesr11(r13) ; (TEST/DEBUG)
1036 mfsr r14,sr12 ; (TEST/DEBUG)
1037 stw r14,savesr12(r13) ; (TEST/DEBUG)
1038 mfsr r14,sr13 ; (TEST/DEBUG)
1039 stw r14,savesr13(r13) ; (TEST/DEBUG)
1040 mfsr r14,sr15 ; (TEST/DEBUG)
1041 stw r14,savesr15(r13) ; (TEST/DEBUG)
1042 #endif
1043
1044 mtsr sr0,r12 /* Set the kernel SR0 */
1045 stw r21,saver21(r13) /* Save this one */
1046 addis r12,r12,0x0010 ; Point to the second segment of kernel
1047 stw r10,savexer(r13) ; Save the rupt XER
1048 mtsr sr1,r12 /* Set the kernel SR1 */
1049 stw r30,saver30(r13) /* Save this one */
1050 addis r12,r12,0x0010 ; Point to the third segment of kernel
1051 stw r31,saver31(r13) /* Save this one */
1052 mtsr sr2,r12 /* Set the kernel SR2 */
1053 stw r22,saver22(r13) /* Save this one */
1054 addis r12,r12,0x0010 ; Point to the third segment of kernel
1055 la r10,savedar(r13) /* Point to exception info block */
1056 stw r23,saver23(r13) /* Save this one */
1057 mtsr sr3,r12 /* Set the kernel SR3 */
1058 stw r24,saver24(r13) /* Save this one */
1059 stw r25,saver25(r13) /* Save this one */
1060 mfdsisr r7 /* Get the 'rupt DSISR */
1061 stw r26,saver26(r13) /* Save this one */
1062
1063 bf- featL1ena,skipz5 ; L1 cache is disabled...
1064 dcbz 0,r10 /* Allocate exception info line */
1065 skipz5:
1066
1067 stw r27,saver27(r13) /* Save this one */
1068 li r10,emfp0 ; Point to floating point save
1069 stw r28,saver28(r13) /* Save this one */
1070 stw r29,saver29(r13) /* Save this one */
1071 mfsr r14,sr14 ; Get the copyin/out segment register
1072 stw r6,savedar(r13) /* Save the 'rupt DAR */
1073 bf- featL1ena,skipz5a ; Do not do this if no L1...
1074 dcbz r10,r2 ; Clear and allocate an L1 slot
1075
1076 skipz5a: stw r7,savedsisr(r13) /* Save the 'rupt code DSISR */
1077 stw r11,saveexception(r13) /* Save the exception code */
1078 stw r14,savesr14(r13) ; Save copyin/copyout
1079
1080 lis r8,HIGH_ADDR(EXT(saveanchor)) /* Get the high part of the anchor */
1081 li r19,0 ; Assume no Altivec
1082 ori r8,r8,LOW_ADDR(EXT(saveanchor)) /* Bottom half of the anchor */
1083
1084 bf featAltivec,noavec ; No Altivec on this CPU...
1085 li r9,0 ; Get set to clear VRSAVE
1086 mfspr r19,vrsave ; Get the VRSAVE register
1087 mtspr vrsave,r9 ; Clear VRSAVE for each interrupt level
1088 ;
1089 ; We need to save the FPSCR as if it is normal context.
1090 ; This is because pending exceptions will cause an exception even if
1091 ; FP is disabled. We need to clear the FPSCR when we first start running in the
1092 ; kernel.
1093 ;
1094 noavec: stw r19,savevrsave(r13) ; Save the vector register usage flags
1095
1096 bf- featFP,nofpexe ; No possible floating point exceptions...
1097
1098 mfmsr r9 ; Get the MSR value
1099 ori r7,r9,lo16(MASK(MSR_FP)) ; Enable floating point
1100 mtmsr r7 ; Do it
1101 isync
1102 stfd f0,emfp0(r2) ; Save FPR0
1103 stfd f1,emfp1(r2) ; Save FPR1
1104 mffs f0 ; Get the FPSCR
1105 fsub f1,f1,f1 ; Make a 0
1106 stfd f0,savexfpscrpad(r13) ; Save the FPSCR
1107 mtfsf 0xFF,f1 ; Clear it
1108 lfd f0,emfp0(r2) ; Restore FPR0
1109 lfd f1,emfp1(r2) ; Restore FPR1
1110 mtmsr r9 ; Turn off FP
1111 isync
1112 nofpexe:
1113
1114 /*
1115 * Everything is saved at this point, except for FPRs, and VMX registers
1116 *
1117 * Time for a new save area. Allocate the trace table entry now also
1118 * Note that we haven't touched R0-R5 yet. Except for R0 & R1, that's in the save
1119 */
1120
1121
1122 lllck: lwarx r9,0,r8 /* Grab the lock value */
1123 li r7,1 /* Use part of the delay time */
1124 mr. r9,r9 /* Is it locked? */
1125 bne- lllcks /* Yeah, wait for it to clear... */
1126 stwcx. r7,0,r8 /* Try to seize that there durn lock */
1127 beq+ lllckd /* Got it... */
1128 b lllck /* Collision, try again... */
1129
1130 lllcks: lwz r9,SVlock(r8) /* Get that lock in here */
1131 mr. r9,r9 /* Is it free yet? */
1132 beq+ lllck /* Yeah, try for it again... */
1133 b lllcks /* Sniff away... */
1134
1135 lllckd: isync /* Purge any speculative executions here */
1136 lis r23,hi16(EXT(trcWork)) ; Get the work area address
1137 rlwinm r7,r11,30,0,31 /* Save 'rupt code shifted right 2 */
1138 ori r23,r23,lo16(EXT(trcWork)) ; Get the rest
1139 #if 1
1140 lwz r14,traceMask(r23) /* Get the trace mask */
1141 #else
1142 li r14,-1 /* (TEST/DEBUG) */
1143 #endif
1144 addi r7,r7,10 /* Adjust for CR5_EQ position */
1145 lwz r15,SVfree(r8) /* Get the head of the save area list */
1146 lwz r25,SVinuse(r8) /* Get the in use count */
1147 rlwnm r7,r14,r7,22,22 /* Set CR5_EQ bit position to 0 if tracing allowed */
1148 lwz r20,traceCurr(r23) /* Pick up the current trace entry */
1149 mtcrf 0x04,r7 /* Set CR5 to show trace or not */
1150
1151 lwz r14,SACalloc(r15) /* Pick up the allocation bits */
1152 addi r25,r25,1 /* Bump up the in use count for the new savearea */
1153 lwz r21,traceEnd(r23) /* Grab up the end of it all */
1154 mr. r14,r14 /* Can we use the first one? */
1155 blt use1st /* Yeah... */
1156
1157 andis. r14,r14,0x8000 /* Show we used the second and remember if it was the last */
1158 addi r10,r15,0x0800 /* Point to the first one */
1159 b gotsave /* We have the area now... */
1160
1161 use1st: andis. r14,r14,0x4000 /* Mark first gone and remember if empty */
1162 mr r10,r15 /* Set the save area */
1163
1164 gotsave: stw r14,SACalloc(r15) /* Put back the allocation bits */
1165 bne nodqsave /* There's still an empty slot, don't dequeue... */
1166
1167 lwz r16,SACnext(r15) /* Get the next in line */
1168 stw r16,SVfree(r8) /* Dequeue our now empty save area block */
1169
1170 nodqsave: addi r22,r20,LTR_size /* Point to the next trace entry */
1171 stw r25,SVinuse(r8) /* Set the in use count */
1172 li r17,0 /* Clear this for the lock */
1173 cmplw r22,r21 /* Do we need to wrap the trace table? */
1174 stw r17,SAVprev(r10) /* Clear back pointer for the newly allocated guy */
1175 mtsprg 1,r10 /* Get set for the next 'rupt */
1176 bne+ gotTrcEnt /* We got a trace entry... */
1177
1178 lwz r22,traceStart(r23) /* Wrap back to the top */
1179
1180 gotTrcEnt: bne- cr5,skipTrace1 /* Don't want to trace this kind... */
1181
1182 stw r22,traceCurr(r23) /* Set the next entry for the next guy */
1183
1184 #if ESPDEBUG
1185 dcbst br0,r23 ; (TEST/DEBUG)
1186 sync ; (TEST/DEBUG)
1187 #endif
1188
1189 bf- featL1ena,skipz6 ; L1 cache is disabled...
1190 dcbz 0,r20 /* Allocate cache for the entry */
1191 skipz6:
1192
1193 skipTrace1: sync /* Make sure all stores are done */
1194 stw r17,SVlock(r8) /* Unlock both save and trace areas */
1195
1196
1197 /*
1198 * At this point, we can take another exception and lose nothing.
1199 *
1200 * We still have the current savearea pointed to by R13, the next by R10 and
1201 * sprg1. R20 contains the pointer to a trace entry and CR5_eq says
1202 * to do the trace or not.
1203 *
1204 * Note that R13 was chosen as the save area pointer because the SIGP,
1205 * firmware, and DSI/ISI handlers aren't supposed to touch anything
1206 * over R12. But, actually, the DSI/ISI stuff does.
1207 *
1208 *
1209 * Let's cut that trace entry now.
1210 */
1211
1212 lwz r0,saver0(r13) ; Get back interrupt time R0
1213 bne- cr5,skipTrace2 /* Don't want to trace this kind... */
1214
1215 mfsprg r2,0 ; Get the per_proc
1216 li r14,32 /* Second line of entry */
1217
1218 lwz r16,ruptStamp(r2) ; Get top of time base
1219 lwz r17,ruptStamp+4(r2) ; Get the bottom of time stamp
1220
1221 bf- featL1ena,skipz7 ; L1 cache is disabled...
1222 dcbz r14,r20 /* Zap the second half */
1223
1224 skipz7: stw r16,LTR_timeHi(r20) /* Set the upper part of TB */
1225 bf featSMP,nopir4 ; Is there a processor ID register on this guy?
1226 mfspr r19,pir /* Get the processor address */
1227 b gotpir4 /* Got it... */
1228 nopir4: li r19,0 /* Assume processor 0 for those underprivileged folks */
1229 gotpir4:
1230 lwz r1,saver1(r13) ; Get back interrupt time R1
1231 stw r17,LTR_timeLo(r20) /* Set the lower part of TB */
1232 rlwinm r19,r19,0,27,31 /* Cut the junk */
1233 lwz r2,saver2(r13) ; Get back interrupt time R2
1234 stw r0,LTR_r0(r20) /* Save off register 0 */
1235 lwz r3,saver3(r13) ; Restore this one
1236 sth r19,LTR_cpu(r20) /* Stash the cpu address */
1237 stw r1,LTR_r1(r20) /* Save off register 1 */
1238 lwz r4,saver4(r13) ; Restore this one
1239 stw r2,LTR_r2(r20) /* Save off register 2 */
1240 lwz r5,saver5(r13) ; Restore this one
1241 stw r3,LTR_r3(r20) /* Save off register 3 */
1242 lwz r16,savecr(r13) /* We don't remember the CR anymore, get it */
1243 stw r4,LTR_r4(r20) /* Save off register 4 */
1244 mfsrr0 r17 /* Get this back, it's still good */
1245 stw r5,LTR_r5(r20) /* Save off register 5 */
1246 mfsrr1 r18 /* This is still good in here also */
1247
1248 stw r16,LTR_cr(r20) /* Save the CR (or dec) */
1249 stw r17,LTR_srr0(r20) /* Save the SSR0 */
1250 stw r18,LTR_srr1(r20) /* Save the SRR1 */
1251 mfdar r17 /* Get this back */
1252
1253 mflr r16 /* Get the LR */
1254 stw r17,LTR_dar(r20) /* Save the DAR */
1255 mfctr r17 /* Get the CTR */
1256 stw r16,LTR_lr(r20) /* Save the LR */
1257 #if 0
1258 lis r17,HIGH_ADDR(EXT(saveanchor)) ; (TEST/DEBUG)
1259 ori r17,r17,LOW_ADDR(EXT(saveanchor)) ; (TEST/DEBUG)
1260 lwz r16,SVcount(r17) ; (TEST/DEBUG)
1261 lwz r17,SVinuse(r17) ; (TEST/DEBUG)
1262 rlwimi r17,r16,16,0,15 ; (TEST/DEBUG)
1263 #endif
1264 stw r17,LTR_ctr(r20) /* Save off the CTR */
1265 stw r13,LTR_save(r20) /* Save the savearea */
1266 sth r11,LTR_excpt(r20) /* Save the exception type */
1267 #if ESPDEBUG
1268 addi r17,r20,32 ; (TEST/DEBUG)
1269 dcbst br0,r20 ; (TEST/DEBUG)
1270 dcbst br0,r17 ; (TEST/DEBUG)
1271 sync ; (TEST/DEBUG)
1272 #endif
1273
1274 /*
1275 * We're done with the trace, except for maybe modifying the exception
1276 * code later on. So, that means that we need to save R20 and CR5, but
1277 * R0 to R5 are clear now.
1278 *
1279 * So, let's finish setting up the kernel registers now.
1280 */
1281
1282 skipTrace2:
1283
1284 #if PERFTIMES && DEBUG
1285 li r3,68 ; Indicate interrupt
1286 mr r4,r11 ; Get code to log
1287 mr r5,r13 ; Get savearea to log
1288 mr r8,r0 ; Save R0
1289 bl EXT(dbgLog2) ; Cut log entry
1290 mr r0,r8 ; Restore R0
1291 #endif
1292
1293 mfsprg r2,0 /* Get the per processor block */
1294
1295 #if CHECKSAVE
1296
1297 lis r4,0x7FFF /* (TEST/DEBUG) */
1298 mfdec r12 /* (TEST/DEBUG) */
1299 or r4,r4,r12 /* (TEST/DEBUG) */
1300 mtdec r4 /* (TEST/DEBUG) */
1301 li r4,0x20 /* (TEST/DEBUG) */
1302
1303 lwarx r8,0,r4 ; ?
1304
1305 mpwait2: lwarx r8,0,r4 /* (TEST/DEBUG) */
1306 mr. r8,r8 /* (TEST/DEBUG) */
1307 bne- mpwait2 /* (TEST/DEBUG) */
1308 stwcx. r4,0,r4 /* (TEST/DEBUG) */
1309 bne- mpwait2 /* (TEST/DEBUG) */
1310
1311 isync /* (TEST/DEBUG) */
1312 lwz r4,0xE80(br0) /* (TEST/DEBUG) */
1313 mr. r4,r4 /* (TEST/DEBUG) */
1314 li r4,1 /* (TEST/DEBUG) */
1315 bne- doncheksv /* (TEST/DEBUG) */
1316
1317 lis r8,HIGH_ADDR(EXT(saveanchor)) /* (TEST/DEBUG) */
1318 ori r8,r8,LOW_ADDR(EXT(saveanchor)) /* (TEST/DEBUG) */
1319
1320 stw r4,0xE80(br0) /* (TEST/DEBUG) */
1321
1322 lwarx r4,0,r8 ; ?
1323
1324 mpwait2x: lwarx r4,0,r8 /* (TEST/DEBUG) */
1325 mr. r4,r4 /* (TEST/DEBUG) */
1326 bne- mpwait2x /* (TEST/DEBUG) */
1327 stwcx. r8,0,r8 /* (TEST/DEBUG) */
1328 bne- mpwait2x /* (TEST/DEBUG) */
1329
1330 isync /* (TEST/DEBUG) */
1331
1332 rlwinm r4,r13,0,0,19 /* (TEST/DEBUG) */
1333 lwz r21,SACflags(r4) /* (TEST/DEBUG) */
1334 rlwinm r22,r21,24,24,31 /* (TEST/DEBUG) */
1335 cmplwi r22,0x00EE /* (TEST/DEBUG) */
1336 lwz r22,SACvrswap(r4) /* (TEST/DEBUG) */
1337 bnel- currbad /* (TEST/DEBUG) */
1338 andis. r21,r21,hi16(sac_perm) /* (TEST/DEBUG) */
1339 bne- currnotbad /* (TEST/DEBUG) */
1340 mr. r22,r22 /* (TEST/DEBUG) */
1341 bne+ currnotbad /* (TEST/DEBUG) */
1342
1343 currbad: lis r23,hi16(EXT(debugbackpocket)) /* (TEST/DEBUG) */
1344 ori r23,r23,lo16(EXT(debugbackpocket)) /* (TEST/DEBUG) */
1345 lwz r23,0(r23) ; (TEST/DEBUG)
1346 stw r23,SVfree(r8) /* (TEST/DEBUG) */
1347
1348 mfsprg r25,1 /* (TEST/DEBUG) */
1349 mtsprg 1,r23 /* (TEST/DEBUG) */
1350 lwz r26,SACalloc(r23) /* (TEST/DEBUG) */
1351 rlwinm r26,r26,0,1,31 /* (TEST/DEBUG) */
1352 stw r26,SACalloc(r23) /* (TEST/DEBUG) */
1353
1354 sync /* (TEST/DEBUG) */
1355
1356 li r3,0 /* (TEST/DEBUG) */
1357 stw r3,0x20(br0) /* (TEST/DEBUG) */
1358 stw r3,0(r8) /* (TEST/DEBUG) */
1359 lis r0,hi16(Choke) ; (TEST/DEBUG)
1360 ori r0,r0,lo16(Choke) ; (TEST/DEBUG)
1361 sc ; System ABEND
1362
1363 currnotbad:
1364 lwz r28,SVcount(r8) /* (TEST/DEBUG) */
1365 lwz r21,SVinuse(r8) /* (TEST/DEBUG) */
1366 lwz r23,SVmin(r8) /* (TEST/DEBUG) */
1367 sub r22,r28,r21 /* (TEST/DEBUG) */
1368 cmpw r22,r23 /* (TEST/DEBUG) */
1369 bge+ cksave0 /* (TEST/DEBUG) */
1370
1371 bl currbad ; (TEST/DEBUG)
1372
1373 cksave0: lwz r28,SVfree(r8) /* (TEST/DEBUG) */
1374 li r24,0 /* (TEST/DEBUG) */
1375 li r29,1 /* (TEST/SAVE) */
1376
1377 cksave0a: mr. r28,r28 /* (TEST/DEBUG) */
1378 beq- cksave3 /* (TEST/DEBUG) */
1379
1380 rlwinm. r21,r28,0,4,19 /* (TEST/DEBUG) */
1381 bne+ cksave1 /* (TEST/DEBUG) */
1382
1383 bl currbad ; (TEST/DEBUG)
1384
1385 cksave1: rlwinm. r21,r28,0,21,3 /* (TEST/DEBUG) */
1386 beq+ cksave2 /* (TEST/DEBUG) */
1387
1388 bl currbad ; (TEST/DEBUG)
1389
1390 cksave2: lwz r25,SACalloc(r28) /* (TEST/DEBUG) */
1391 lbz r26,SACflags+2(r28) /* (TEST/DEBUG) */
1392 lbz r21,SACflags+3(r28) /* (TEST/DEBUG) */
1393 cmplwi r26,0x00EE /* (TEST/DEBUG) */
1394 stb r29,SACflags+3(r28) /* (TEST/DEBUG) */
1395 beq+ cksave2z
1396
1397 bl currbad ; (TEST/DEBUG)
1398
1399 cksave2z: mr. r21,r21 /* (TEST/DEBUG) */
1400 beq+ cksave2a /* (TEST/DEBUG) */
1401
1402 bl currbad ; (TEST/DEBUG)
1403
1404 cksave2a: rlwinm r26,r25,1,31,31 /* (TEST/DEBUG) */
1405 rlwinm r27,r25,2,31,31 /* (TEST/DEBUG) */
1406 add r24,r24,r26 /* (TEST/DEBUG) */
1407 add r24,r24,r27 /* (TEST/DEBUG) */
1408 lwz r28,SACnext(r28) /* (TEST/DEBUG) */
1409 b cksave0a /* (TEST/DEBUG) */
1410
1411 cksave3: cmplw r24,r22 /* (TEST/DEBUG) */
1412 beq+ cksave4 /* (TEST/DEBUG) */
1413
1414 bl currbad ; (TEST/DEBUG)
1415
1416 cksave4: lwz r28,SVfree(r8) /* (TEST/DEBUG) */
1417 li r24,0 /* (TEST/DEBUG) */
1418
1419 cksave5: mr. r28,r28 /* (TEST/DEBUG) */
1420 beq- cksave6 /* (TEST/DEBUG) */
1421 stb r24,SACflags+3(r28) /* (TEST/DEBUG) */
1422 lwz r28,SACnext(r28) /* (TEST/DEBUG) */
1423 b cksave5 /* (TEST/DEBUG) */
1424
1425 cksave6:
1426
1427 li r4,0 /* (TEST/DEBUG) */
1428 stw r4,0xE80(br0) /* (TEST/DEBUG) */
1429 stw r4,0(r8) /* (TEST/DEBUG) */
1430
1431 doncheksv:
1432 li r4,0 /* (TEST/DEBUG) */
1433 stw r4,0x20(br0) /* (TEST/DEBUG) */
1434 mtdec r12 /* (TEST/DEBUG) */
1435 #endif
1436
1437 lis r4,HIGH_ADDR(EXT(MPspec)) /* Get the MP control block */
1438 dcbt 0,r2 /* We'll need the per_proc in a sec */
1439 cmplwi cr0,r11,T_INTERRUPT /* Do we have an external interrupt? */
1440 ori r4,r4,LOW_ADDR(EXT(MPspec)) /* Get the bottom half of the MP control block */
1441 bne+ notracex /* Not an external... */
1442
1443 /*
1444 * Here we check to see if there was a interprocessor signal
1445 */
1446
1447 lwz r4,MPSSIGPhandler(r4) /* Get the address of the SIGP interrupt filter */
1448 lhz r3,PP_CPU_FLAGS(r2) /* Get the CPU flags */
1449 cmplwi cr1,r4,0 /* Check if signal filter is initialized yet */
1450 andi. r3,r3,LOW_ADDR(SIGPactive) /* See if this processor has started up */
1451 mtlr r4 /* Load up filter address */
1452 beq- cr1,notracex /* We don't have a filter yet... */
1453 beq- notracex /* This processor hasn't started filtering yet... */
1454
1455 blrl /* Filter the interrupt */
1456
1457 mfsprg r2,0 /* Make sure we have the per processor block */
1458 cmplwi cr0,r3,kMPIOInterruptPending /* See what the filter says */
1459 li r11,T_INTERRUPT /* Assume we have a regular external 'rupt */
1460 beq+ modRupt /* Yeah, we figured it would be... */
1461 li r11,T_SIGP /* Assume we had a signal processor interrupt */
1462 bgt+ modRupt /* Yeah, at this point we would assume so... */
1463 li r11,T_IN_VAIN /* Nothing there actually, so eat it */
1464
1465 modRupt: stw r11,PP_SAVE_EXCEPTION_TYPE(r2) /* Set that it was either in vain or a SIGP */
1466 stw r11,saveexception(r13) /* Save the exception code here also */
1467 bne- cr5,notracex /* Jump if no tracing... */
1468 sth r11,LTR_excpt(r20) /* Save the exception type */
1469
1470 notracex:
1471
1472 #if 0
1473 bf featSMP,nopir6 /* (TEST/DEBUG) */
1474 mfspr r7,pir /* (TEST/DEBUG) */
1475 b gotpir6 /* (TEST/DEBUG) */
1476 nopir6: li r7,0 /* (TEST/DEBUG) */
1477 gotpir6: /* (TEST/DEBUG) */
1478 lis r6,HIGH_ADDR(EXT(RuptCtrs)) /* (TEST/DEBUG) */
1479 rlwinm r7,r7,8,23,23 /* (TEST/DEBUG) */
1480 lis r12,HIGH_ADDR(EXT(GratefulDeb)) /* (TEST/DEBUG) */
1481 rlwimi r7,r7,1,22,22 /* (TEST/DEBUG) */
1482 ori r6,r6,LOW_ADDR(EXT(RuptCtrs)) /* (TEST/DEBUG) */
1483 rlwinm r1,r11,2,0,29 /* (TEST/DEBUG) */
1484 add r6,r6,r7 /* (TEST/DEBUG) */
1485 ori r12,r12,LOW_ADDR(EXT(GratefulDeb)) /* (TEST/DEBUG) */
1486 lwz r21,(47*16)+8(r6) /* (TEST/DEBUG) */
1487 lwz r22,(47*16)+12(r6) /* (TEST/DEBUG) */
1488 add r1,r1,r6 /* (TEST/DEBUG) */
1489 mftb r24 /* (TEST/DEBUG) */
1490 sub r22,r24,r22 /* (TEST/DEBUG) */
1491 lwz r4,4(r6) /* (TEST/DEBUG) */
1492 cmplw cr2,r22,r21 /* (TEST/DEBUG) */
1493 lwz r7,4(r1) /* (TEST/DEBUG) */
1494 lwz r21,8(r6) /* (TEST/DEBUG) */
1495 blt+ cr2,nottime /* (TEST/DEBUG) */
1496 stw r24,(47*16)+12(r6) /* (TEST/DEBUG) */
1497
1498 nottime: addi r4,r4,1 /* (TEST/DEBUG) */
1499 lwz r22,8(r1) /* (TEST/DEBUG) */
1500 addi r7,r7,1 /* (TEST/DEBUG) */
1501 stw r4,4(r6) /* (TEST/DEBUG) */
1502 lwz r3,0(r6) /* (TEST/DEBUG) */
1503 mr. r21,r21 /* (TEST/DEBUG) */
1504 stw r7,4(r1) /* (TEST/DEBUG) */
1505 mtlr r12 /* (TEST/DEBUG) */
1506 lwz r1,0(r1) /* (TEST/DEBUG) */
1507 beq- nottimed1 /* (TEST/DEBUG) */
1508 blt+ cr2,isnttime1 /* (TEST/DEBUG) */
1509
1510 nottimed1: mr. r3,r3 /* (TEST/DEBUG) */
1511 bgelrl+ /* (TEST/DEBUG) */
1512
1513 isnttime1: mr. r22,r22 /* (TEST/DEBUG) */
1514 beq- nottimed2 /* (TEST/DEBUG) */
1515 blt+ cr2,isnttime2 /* (TEST/DEBUG) */
1516
1517 nottimed2: mr. r3,r1 /* (TEST/DEBUG) */
1518 mtlr r12 /* (TEST/DEBUG) */
1519 mr r4,r7 /* (TEST/DEBUG) */
1520 bgelrl+ /* (TEST/DEBUG) */
1521 mr r3,r11 /* (TEST/DEBUG) */
1522
1523 isnttime2: cmplwi r11,T_DATA_ACCESS /* (TEST/DEBUG) */
1524 lis r12,HIGH_ADDR(EXT(GratefulDeb)) /* (TEST/DEBUG) */
1525 bne+ nodsidisp /* (TEST/DEBUG) */
1526 mr. r22,r22 /* (TEST/DEBUG) */
1527 beq- nottimed3 /* (TEST/DEBUG) */
1528 blt+ cr2,nodsidisp /* (TEST/DEBUG) */
1529
1530 nottimed3: li r3,5 /* (TEST/DEBUG) */
1531 ori r12,r12,LOW_ADDR(EXT(GratefulDeb)) /* (TEST/DEBUG) */
1532 lwz r4,savesrr0(r13) /* (TEST/DEBUG) */
1533 mtlr r12 /* (TEST/DEBUG) */
1534 blrl /* (TEST/DEBUG) */
1535
1536 lis r12,HIGH_ADDR(EXT(GratefulDeb)) /* (TEST/DEBUG) */
1537 ori r12,r12,LOW_ADDR(EXT(GratefulDeb)) /* (TEST/DEBUG) */
1538 lis r3,9 /* (TEST/DEBUG) */
1539 ori r3,r3,5 /* (TEST/DEBUG) */
1540 mtlr r12 /* (TEST/DEBUG) */
1541 lwz r4,savedar(r13) /* (TEST/DEBUG) */
1542 blrl /* (TEST/DEBUG) */
1543
1544 nodsidisp: cmplwi r11,T_INSTRUCTION_ACCESS /* (TEST/DEBUG) */
1545 lis r12,HIGH_ADDR(EXT(GratefulDeb)) /* (TEST/DEBUG) */
1546 bne+ noisidisp /* (TEST/DEBUG) */
1547 mr. r22,r22 /* (TEST/DEBUG) */
1548 beq- nottimed4 /* (TEST/DEBUG) */
1549 blt+ cr2,noisidisp /* (TEST/DEBUG) */
1550
1551 nottimed4: li r3,6 /* (TEST/DEBUG) */
1552 ori r12,r12,LOW_ADDR(EXT(GratefulDeb)) /* (TEST/DEBUG) */
1553 lwz r4,savesrr0(r13) /* (TEST/DEBUG) */
1554 mtlr r12 /* (TEST/DEBUG) */
1555 blrl /* (TEST/DEBUG) */
1556
1557 noisidisp: mr r3,r11 /* (TEST/DEBUG) */
1558 #endif
1559
1560 #if 0
1561 cmplwi r11,T_PROGRAM /* (TEST/DEBUG) */
1562 lis r12,HIGH_ADDR(EXT(GratefulDeb)) /* (TEST/DEBUG) */
1563 bne+ nopgmdisp /* (TEST/DEBUG) */
1564 li r3,7 /* (TEST/DEBUG) */
1565 ori r12,r12,LOW_ADDR(EXT(GratefulDeb)) /* (TEST/DEBUG) */
1566 lwz r4,savesrr0(r13) /* (TEST/DEBUG) */
1567 mtlr r12 /* (TEST/DEBUG) */
1568 blrl /* (TEST/DEBUG) */
1569
1570 nopgmdisp: mr r3,r11 /* (TEST/DEBUG) */
1571 #endif
1572
1573 li r21,0 ; Assume no processor register for now
1574 lis r12,hi16(EXT(hw_counts)) ; Get the high part of the interrupt counters
1575 bf featSMP,nopirhere ; Jump if this processor does not have a PIR...
1576 mfspr r21,pir ; Get the PIR
1577
1578 nopirhere: ori r12,r12,lo16(EXT(hw_counts)) ; Get the low part of the interrupt counters
1579 lwz r7,savesrr1(r13) ; Get the entering MSR
1580 rlwinm r21,r21,8,20,23 ; Get index to processor counts
1581 mtcrf 0x80,r0 /* Set our CR0 to the high nybble of the request code */
1582 rlwinm r6,r0,1,0,31 /* Move sign bit to the end */
1583 cmplwi cr1,r11,T_SYSTEM_CALL /* Did we get a system call? */
1584 crandc cr0_lt,cr0_lt,cr0_gt /* See if we have R0 equal to 0b10xx...x */
1585 add r12,r12,r21 ; Point to the processor count area
1586 cmplwi cr3,r11,T_IN_VAIN /* Was this all in vain? All for nothing? */
1587 lwzx r22,r12,r11 ; Get the old value
1588 cmplwi cr2,r6,1 /* See if original R0 had the CutTrace request code in it */
1589 addi r22,r22,1 ; Count this one
1590 cmplwi cr4,r11,T_SIGP /* Indicate if we had a SIGP 'rupt */
1591 stwx r22,r12,r11 ; Store it back
1592
1593 beq- cr3,EatRupt /* Interrupt was all for nothing... */
1594 cmplwi cr3,r11,T_MACHINE_CHECK ; Did we get a machine check?
1595 bne+ cr1,noCutT /* Not a system call... */
1596 bnl+ cr0,noCutT /* R0 not 0b10xxx...x, can't be any kind of magical system call... */
1597 rlwinm. r7,r7,0,MSR_PR_BIT,MSR_PR_BIT ; Did we come from user state?
1598 lis r1,hi16(EXT(dgWork)) ; Get the diagnostics flags
1599 beq+ FCisok ; From supervisor state...
1600
1601 ori r1,r1,lo16(EXT(dgWork)) ; Again
1602 lwz r1,dgFlags(r1) ; Get the flags
1603 rlwinm. r1,r1,0,enaUsrFCallb,enaUsrFCallb ; Are they valid?
1604 beq- noCutT ; No...
1605
1606 FCisok: beq- cr2,isCutTrace /* This is a CutTrace system call */
1607
1608 /*
1609 * Here's where we call the firmware. If it returns T_IN_VAIN, that means
1610 * that it has handled the interruption. Remember: thou shalt not trash R13
1611 * or R20 while you are away. Anything else is ok.
1612 */
1613
1614 lis r1,hi16(EXT(FirmwareCall)) /* Top half of firmware call handler */
1615 ori r1,r1,lo16(EXT(FirmwareCall)) /* Bottom half of it */
1616 lwz r3,saver3(r13) /* Restore the first parameter, the rest are ok already */
1617 mtlr r1 /* Get it in the link register */
1618 blrl /* Call the handler */
1619
1620 cmplwi r3,T_IN_VAIN /* Was it handled? */
1621 mfsprg r2,0 /* Restore the per_processor area */
1622 beq+ EatRupt /* Interrupt was handled... */
1623 mr r11,r3 /* Put the 'rupt code in the right register */
1624 b noSIGP /* Go to the normal system call handler */
1625
1626 isCutTrace:
1627 li r7,-32768 /* Get a 0x8000 for the exception code */
1628 bne- cr5,EatRupt /* Tracing is disabled... */
1629 sth r7,LTR_excpt(r20) /* Modify the exception type to a CutTrace */
1630 b EatRupt /* Time to go home... */
1631
1632 /* We are here 'cause we didn't have a CutTrace system call */
1633
1634 noCutT: beq- cr3,MachineCheck ; Whoa... Machine check...
1635 bne+ cr4,noSIGP /* Skip away if we didn't get a SIGP... */
1636
1637 lis r6,HIGH_ADDR(EXT(MPsignalFW)) /* Top half of SIGP handler */
1638 ori r6,r6,LOW_ADDR(EXT(MPsignalFW)) /* Bottom half of it */
1639 mtlr r6 /* Get it in the link register */
1640
1641 blrl /* Call the handler - we'll only come back if this is an AST, */
1642 /* 'cause FW can't handle that */
1643 mfsprg r2,0 /* Restore the per_processor area */
1644 ;
1645 ; The following interrupts are the only ones that can be redriven
1646 ; by the higher level code or emulation routines.
1647 ;
1648
1649 Redrive: cmplwi cr0,r3,T_IN_VAIN /* Did the signal handler eat the signal? */
1650 mr r11,r3 /* Move it to the right place */
1651 beq+ cr0,EatRupt /* Bail now if the signal handler processed the signal... */
1652
1653
1654 /*
1655 * Here's where we check for the other fast-path exceptions: translation exceptions,
1656 * emulated instructions, etc.
1657 */
1658
1659 noSIGP: cmplwi cr3,r11,T_ALTIVEC_ASSIST ; Check for an Altivec denorm assist
1660 cmplwi cr1,r11,T_PROGRAM /* See if we got a program exception */
1661 cmplwi cr2,r11,T_INSTRUCTION_ACCESS /* Check on an ISI */
1662 bne+ cr3,noAltivecAssist ; It is not an assist...
1663 b EXT(AltivecAssist) ; It is an assist...
1664
1665 noAltivecAssist:
1666 bne+ cr1,noEmulate ; No emulation here...
1667 b EXT(Emulate) ; Go try to emulate...
1668
1669 noEmulate: cmplwi cr3,r11,T_CSWITCH /* Are we context switching */
1670 cmplwi r11,T_DATA_ACCESS /* Check on a DSI */
1671 beq- cr2,DSIorISI /* It's a PTE fault... */
1672 beq- cr3,conswtch /* It's a context switch... */
1673 bne+ PassUp /* It's not a PTE fault... */
1674
1675 /*
1676 * This call will either handle the fault, in which case it will not
1677 * return, or return to pass the fault up the line.
1678 */
1679
1680 DSIorISI:
1681 lis r7,HIGH_ADDR(EXT(handlePF)) /* Top half of DSI handler */
1682 ori r7,r7,LOW_ADDR(EXT(handlePF)) /* Bottom half of it */
1683 mtlr r7 /* Get it in the link register */
1684 mr r3,r11 /* Move the 'rupt code */
1685
1686 blrl /* See if we can handle this fault */
1687
1688 lwz r0,savesrr1(r13) ; Get the MSR in use at exception time
1689 mfsprg r2, 0 /* Get back per_proc */
1690 cmplwi cr1,r3,T_IN_VAIN ; Was it handled?
1691 andi. r4,r0,lo16(MASK(MSR_RI)) ; See if the recover bit is on
1692 mr r11,r3 /* Make sure we can find this later */
1693 beq+ cr1,EatRupt ; Yeah, just blast back to the user...
1694 andc r0,r0,r4 ; Remove the recover bit
1695 beq+ PassUp ; Not on, normal case...
1696 lwz r4,savesrr0(r13) ; Get the failing instruction address
1697 lwz r5,savecr(r13) ; Get the condition register
1698 stw r0,savesrr1(r13) ; Save the result MSR
1699 addi r4,r4,4 ; Skip failing instruction
1700 rlwinm r5,r5,0,3,1 ; Clear CR0_EQ to let emulation code know we failed
1701 stw r4,savesrr0(r13) ; Save instruction address
1702 stw r4,savecr(r13) ; And the resume CR
1703 b EatRupt ; Resume emulated code
1704
1705 /*
1706 * Here is where we handle the context switch firmware call. The old
1707 * context has been saved, and the new savearea in in saver3. We'll just
1708 * muck around with the savearea pointers, and then join the exit routine
1709 */
1710 conswtch: lwz r28,SAVflags(r13) /* The the flags of the current */
1711 mr r29,r13 /* Save the save */
1712 rlwinm r30,r13,0,0,19 /* Get the start of the savearea block */
1713 lwz r5,saver3(r13) /* Switch to the new savearea */
1714 oris r28,r28,HIGH_ADDR(SAVattach) /* Turn on the attached flag */
1715 lwz r30,SACvrswap(r30) /* get real to virtual translation */
1716 mr r13,r5 /* Switch saveareas */
1717 xor r27,r29,r30 /* Flip to virtual */
1718 stw r28,SAVflags(r29) /* Stash it back */
1719 stw r27,saver3(r5) /* Push the new savearea to the switch to routine */
1720 b EatRupt /* Start 'er up... */
1721
1722 ;
1723 ; Handle machine check here.
1724 ;
1725 ; ?
1726 ;
1727 MachineCheck:
1728 lwz r27,savesrr1(r13) ; ?
1729 rlwinm. r11,r27,0,dcmck,dcmck ; ?
1730 beq+ notDCache ; ?
1731
1732 mfspr r11,msscr0 ; ?
1733 dssall ; ?
1734 sync
1735
1736 lwz r27,savesrr1(r13) ; ?
1737
1738 hiccup: cmplw r27,r27 ; ?
1739 bne- hiccup ; ?
1740 isync ; ?
1741
1742 oris r11,r11,hi16(dl1hwfm) ; ?
1743 mtspr msscr0,r11 ; ?
1744
1745 rstbsy: mfspr r11,msscr0 ; ?
1746
1747 rlwinm. r11,r11,0,dl1hwf,dl1hwf ; ?
1748 bne rstbsy ; ?
1749
1750 sync ; ?
1751
1752 li r11,T_IN_VAIN ; ?
1753 b EatRupt ; ?
1754
1755
1756 notDCache:
1757 ;
1758 ; Check if the failure was in
1759 ; ml_probe_read. If so, this is expected, so modify the PC to
1760 ; ml_proble_read_mck and then eat the exception.
1761 ;
1762 lwz r30,savesrr0(r13) ; Get the failing PC
1763 lis r28,hi16(EXT(ml_probe_read_mck)) ; High order part
1764 lis r27,hi16(EXT(ml_probe_read)) ; High order part
1765 ori r28,r28,lo16(EXT(ml_probe_read_mck)) ; Get the low part
1766 ori r27,r27,lo16(EXT(ml_probe_read)) ; Get the low part
1767 cmplw r30,r28 ; Check highest possible
1768 cmplw cr1,r30,r27 ; Check lowest
1769 bge- PassUp ; Outside of range
1770 blt- cr1,PassUp ; Outside of range
1771 ;
1772 ; We need to fix up the BATs here because the probe
1773 ; routine messed them all up... As long as we are at it,
1774 ; fix up to return directly to caller of probe.
1775 ;
1776
1777 lwz r30,saver5(r13) ; Get proper DBAT values
1778 lwz r28,saver6(r13)
1779 lwz r27,saver7(r13)
1780 lwz r11,saver8(r13)
1781 lwz r18,saver9(r13)
1782
1783 sync
1784 mtdbatu 0,r30 ; Restore DBAT 0 high
1785 mtdbatl 0,r28 ; Restore DBAT 0 low
1786 mtdbatu 1,r27 ; Restore DBAT 1 high
1787 mtdbatu 2,r11 ; Restore DBAT 2 high
1788 mtdbatu 3,r18 ; Restore DBAT 3 high
1789 sync
1790
1791 lwz r28,savelr(r13) ; Get return point
1792 lwz r27,saver0(r13) ; Get the saved MSR
1793 li r30,0 ; Get a failure RC
1794 stw r28,savesrr0(r13) ; Set the return point
1795 stw r27,savesrr1(r13) ; Set the continued MSR
1796 stw r30,saver3(r13) ; Set return code
1797 li r11,T_IN_VAIN ; Set new interrupt code
1798 b EatRupt ; Yum, yum, eat it all up...
1799
1800 /*
1801 * Here's where we come back from some instruction emulator. If we come back with
1802 * T_IN_VAIN, the emulation is done and we should just reload state and directly
1803 * go back to the interrupted code. Otherwise, we'll check to see if
1804 * we need to redrive with a different interrupt, i.e., DSI.
1805 */
1806
1807 .align 5
1808 .globl EXT(EmulExit)
1809
1810 LEXT(EmulExit)
1811
1812 cmplwi r11,T_IN_VAIN /* Was it emulated? */
1813 lis r1,hi16(SAVredrive) ; Get redrive request
1814 mfsprg r2,0 ; Restore the per_proc area
1815 beq+ EatRupt /* Yeah, just blast back to the user... */
1816 lwz r4,SAVflags(r13) ; Pick up the flags
1817
1818 and. r0,r4,r1 ; Check if redrive requested
1819 andc r4,r4,r1 ; Clear redrive
1820
1821 beq+ PassUp ; No redrive, just keep on going...
1822
1823 lwz r3,saveexception(r13) ; Restore exception code
1824 stw r4,SAVflags(r13) ; Set the flags
1825 b Redrive ; Redrive the exception...
1826
1827 /* Jump into main handler code switching on VM at the same time */
1828
1829 /* We assume kernel data is mapped contiguously in physical
1830 * memory, otherwise we'd need to switch on (at least) virtual data.
1831 * SRs are already set up.
1832 */
1833 PassUp: lis r2,hi16(EXT(exception_handlers)) ; Get exception vector address
1834 ori r2,r2,lo16(EXT(exception_handlers)) ; And low half
1835 lwzx r6,r2,r11 /* Get the actual exception handler address */
1836
1837 PassUpDeb: lwz r8,SAVflags(r13) /* Get the flags */
1838 mtsrr0 r6 /* Set up the handler address */
1839 oris r8,r8,HIGH_ADDR(SAVattach) /* Since we're passing it up, attach it */
1840 rlwinm r5,r13,0,0,19 /* Back off to the start of savearea block */
1841
1842 mfmsr r3 /* Get our MSR */
1843 stw r8,SAVflags(r13) /* Pass up the flags */
1844 rlwinm r3,r3,0,MSR_BE_BIT+1,MSR_SE_BIT-1 /* Clear all but the trace bits */
1845 li r2,MSR_SUPERVISOR_INT_OFF /* Get our normal MSR value */
1846 lwz r5,SACvrswap(r5) /* Get real to virtual conversion */
1847 or r2,r2,r3 /* Keep the trace bits if they're on */
1848 mr r3,r11 /* Pass the exception code in the paramter reg */
1849 mtsrr1 r2 /* Set up our normal MSR value */
1850 xor r4,r13,r5 /* Pass up the virtual address of context savearea */
1851
1852 rfi /* Launch the exception handler */
1853
1854 .long 0 /* Leave these here gol durn it! */
1855 .long 0
1856 .long 0
1857 .long 0
1858 .long 0
1859 .long 0
1860 .long 0
1861 .long 0
1862
1863 /*
1864 * This routine is the only place where we return from an interruption.
1865 * Anyplace else is wrong. Even if I write the code, it's still wrong.
1866 * Feel free to come by and slap me if I do do it--even though I may
1867 * have had a good reason to do it.
1868 *
1869 * All we need to remember here is that R13 must point to the savearea
1870 * that has the context we need to load up. Translation and interruptions
1871 * must be disabled.
1872 *
1873 * This code always loads the context in the savearea pointed to
1874 * by R13. In the process, it throws away the savearea. If there
1875 * is any tomfoolery with savearea stacks, it must be taken care of
1876 * before we get here.
1877 *
1878 * Speaking of tomfoolery, this is where we synthesize interruptions
1879 * if any need to be.
1880 */
1881
1882 .align 5
1883
1884 EatRupt: mr r31,r13 /* Move the savearea pointer to the far end of the register set */
1885
1886 EatRupt2: mfsprg r2,0 /* Get the per_proc block */
1887 dcbt 0,r31 ; Get this because we need it very soon
1888
1889 #if TRCSAVE
1890 lwz r30,saver0(r31) ; (TEST/DEBUG) Get users R0
1891 lwz r20,saveexception(r31) ; (TEST/DEBUG) Returning from trace?
1892 xor r30,r20,r30 ; (TEST/DEBUG) Make code
1893 rlwinm r30,r30,1,0,31 ; (TEST/DEBUG) Make an easy test
1894 cmplwi cr5,r30,0x61 ; (TEST/DEBUG) See if this is a trace
1895 #endif
1896
1897 /*
1898 * First we see if we are able to free the new savearea.
1899 * If it is not attached to anything, put it on the free list.
1900 * This is real dangerous, we haven't restored context yet...
1901 * So, the free savearea chain lock must stay until the bitter end!
1902 */
1903
1904 /*
1905 * It's dangerous here. We haven't restored anything from the current savearea yet.
1906 * And, we mark it the active one. So, if we get an exception in here, it is
1907 * unrecoverable. Unless we mess up, we can't get any kind of exception. So,
1908 * it is important to assay this code as only the purest of gold.
1909 *
1910 * But first, see if there is a savearea hanging off of quickfret. If so,
1911 * we release that one first and then come back for the other. We should rarely
1912 * see one, they appear when FPU or VMX context is discarded by either returning
1913 * to a higher exception level, or explicitly.
1914 *
1915 * A word about QUICKFRET: Multiple saveareas may be queued for release. It is
1916 * the responsibility of the queuer to insure that the savearea is not multiply
1917 * queued and that the appropriate inuse bits are reset.
1918 */
1919
1920
1921
1922 mfsprg r27,2 ; Get the processor features
1923 lwz r1,savesrr1(r31) ; Get destination MSR
1924 mtcrf 0x60,r27 ; Set CRs with thermal facilities
1925 mr r18,r31 ; Save the savearea pointer
1926 rlwinm. r0,r1,0,MSR_EE_BIT,MSR_EE_BIT ; Are interruptions going to be enabled?
1927 lwz r19,PP_QUICKFRET(r2) ; Get the quick release savearea
1928 crandc 31,pfThermalb,pfThermIntb ; See if we have both thermometer and not interrupt facility
1929 li r0,0 ; Get a zero
1930 crandc 31,31,cr0_eq ; Factor in enablement
1931 la r21,savesr0(r18) ; Point to the first thing we restore
1932 bf 31,tempisok ; No thermal checking needed...
1933
1934 ;
1935 ; We get to here if 1) there is a thermal facility, and 2) the hardware
1936 ; will or cannot interrupt, and 3) the interrupt will be enabled after this point.
1937 ;
1938
1939 mfspr r16,thrm3 ; Get thermal 3
1940 mfspr r14,thrm1 ; Get thermal 2
1941 rlwinm. r16,r16,0,thrme,thrme ; Is the themometer enabled?
1942 mfspr r15,thrm2 ; Get thermal 2
1943 beq- tempisok ; No thermometer...
1944 rlwinm r16,r14,2,28,31 ; Cluster THRM1s TIE, V, TIN, and TIV at bottom 4 bits
1945 srawi r0,r15,31 ; Make a mask of 1s if temprature over
1946 rlwinm r30,r15,2,28,31 ; Cluster THRM2s TIE, V, TIN, and TIV at bottom 4 bits
1947 ;
1948 ; Note that the following compare check that V, TIN, and TIV are set and that TIE is cleared.
1949 ; This insures that we only emulate when the hardware is not set to interrupt.
1950 ;
1951 cmplwi cr0,r16,7 ; Is there a valid pending interruption for THRM1?
1952 cmplwi cr1,r30,7 ; Is there a valid pending interruption for THRM2?
1953 and r15,r15,r0 ; Keep high temp if that interrupted, zero if not
1954 cror cr0_eq,cr0_eq,cr1_eq ; Merge both
1955 andc r14,r14,r0 ; Keep low if high did not interrupt, zero if it did
1956 bne+ tempisok ; Nope, temprature is in range
1957
1958 li r3,T_THERMAL ; Time to emulate a thermal interruption
1959 or r14,r14,r15 ; Get contents of interrupting register
1960 mr r13,r31 ; Make sure savearea is pointed to correctly
1961 stw r3,saveexception(r31) ; Restore exception code
1962 stw r14,savedar(r31) ; Set the contents of the interrupting register into the dar
1963 b Redrive ; Go process this new interruption...
1964
1965
1966 tempisok: lis r30,HIGH_ADDR(EXT(saveanchor)) /* Get the high part of the anchor */
1967 stw r0,PP_QUICKFRET(r2) /* Clear quickfret pointer */
1968 ori r30,r30,LOW_ADDR(EXT(saveanchor)) /* Bottom half of the anchor */
1969 dcbt 0,r21 /* Touch in the first thing */
1970
1971 #if 0
1972 li r23,0 ; (TEST/DEBUG)
1973 rlwinm r14,r31,0,0,19 ; (TEST/DEBUG)
1974 lwz r21,SACflags(r14) ; (TEST/DEBUG)
1975 rlwinm r22,r21,24,24,31 ; (TEST/DEBUG)
1976 cmplwi r22,0x00EE ; (TEST/DEBUG)
1977 beq+ nodienodie1 ; (TEST/DEBUG)
1978
1979 dodiedodie: li r1,0x666 ; (TEST/DEBUG)
1980 BREAKPOINT_TRAP ; (TEST/DEBUG)
1981
1982 nodienodie1:
1983 mr r23,r19 ; (TEST/DEBUG)
1984
1985 chkitagain: mr. r23,r23 ; (TEST/DEBUG)
1986 beq nodienodie2 ; (TEST/DEBUG)
1987 rlwinm r14,r23,0,0,19 ; (TEST/DEBUG)
1988 lwz r21,SACflags(r14) ; (TEST/DEBUG)
1989 rlwinm r22,r21,24,24,31 ; (TEST/DEBUG)
1990 cmplwi r22,0x00EE ; (TEST/DEBUG)
1991 bne- dodiedodie ; (TEST/DEBUG)
1992 lwz r23,SAVqfret(r23) ; (TEST/DEBUG)
1993 b chkitagain ; (TEST/DEBUG)
1994
1995 nodienodie2:
1996 #endif
1997
1998 #if TRCSAVE
1999 beq- cr5,trkill0 ; (TEST/DEBUG) Do not trace this type
2000 lwz r14,LOW_ADDR(traceMask-EXT(ExceptionVectorsStart))(br0) ; (TEST/DEBUG) Get the trace mask
2001 mr. r14,r14 ; (TEST/DEBUG) Is it stopped?
2002 beq- trkill0 ; (TEST/DEBUG) yes...
2003 bl cte ; (TEST/DEBUG) Trace this
2004 stw r18,LTR_r1(r20) ; (TEST/DEBUG) Normal savearea
2005 stw r19,LTR_r2(r20) ; (TEST/DEBUG) Quickfret savearea
2006 trkill0:
2007 #endif
2008
2009 rtlck: lwarx r22,0,r30 /* Grab the lock value */
2010 li r23,1 /* Use part of the delay time */
2011 mr. r22,r22 /* Is it locked? */
2012 bne- rtlcks /* Yeah, wait for it to clear... */
2013 stwcx. r23,0,r30 /* Try to seize that there durn lock */
2014 beq+ fretagain ; Got it...
2015 b rtlck /* Collision, try again... */
2016
2017 rtlcks: lwz r22,SVlock(r30) /* Get that lock in here */
2018 mr. r22,r22 /* Is it free yet? */
2019 beq+ rtlck /* Yeah, try for it again... */
2020 b rtlcks /* Sniff away... */
2021
2022 ;
2023 ; Lock gotten, toss the saveareas
2024 ;
2025 fretagain: isync ; Toss those prefetches
2026 #if TRCSAVE
2027 beq- cr5,trkill1 ; (TEST/DEBUG) Do not trace this type
2028 lwz r14,LOW_ADDR(traceMask-EXT(ExceptionVectorsStart))(br0) ; (TEST/DEBUG) Get the trace mask
2029 mr. r14,r14 ; (TEST/DEBUG) Is it stopped?
2030 beq- trkill1 ; (TEST/DEBUG) yes...
2031 li r0,1 ; (TEST/DEBUG) ID number
2032 bl cte ; (TEST/DEBUG) Trace this
2033 stw r18,LTR_r1(r20) ; (TEST/DEBUG) Normal savearea
2034 stw r19,LTR_r2(r20) ; (TEST/DEBUG) Quickfret savearea
2035 trkill1:
2036 #endif
2037
2038 mr. r18,r18 ; Are we actually done here?
2039 beq- donefret ; Yeah...
2040 mr. r31,r19 ; Is there a quickfret to do?
2041 beq+ noqfrt ; Nope...
2042 lwz r19,SAVqfret(r19) ; Yes, get the next in line
2043 #if TRCSAVE
2044 beq- cr5,trkill2 ; (TEST/DEBUG) Do not trace this type
2045 lwz r14,LOW_ADDR(traceMask-EXT(ExceptionVectorsStart))(br0) ; (TEST/DEBUG) Get the trace mask
2046 mr. r14,r14 ; (TEST/DEBUG) Is it stopped?
2047 beq- trkill2 ; (TEST/DEBUG) yes...
2048 li r0,2 ; (TEST/DEBUG) ID number
2049 bl cte ; (TEST/DEBUG) Trace this
2050 stw r18,LTR_r1(r20) ; (TEST/DEBUG) Normal savearea
2051 stw r19,LTR_r2(r20) ; (TEST/DEBUG) next quickfret savearea
2052 stw r31,LTR_r3(r20) ; (TEST/DEBUG) Current one to toss
2053 trkill2:
2054 #endif
2055 b doqfrt ; Go do it...
2056
2057 noqfrt: mr r31,r18 ; Set the area to release
2058 li r18,0 ; Show we have done it
2059 #if TRCSAVE
2060 beq- cr5,trkill3 ; (TEST/DEBUG) Do not trace this type
2061 lwz r14,LOW_ADDR(traceMask-EXT(ExceptionVectorsStart))(br0) ; (TEST/DEBUG) Get the trace mask
2062 mr. r14,r14 ; (TEST/DEBUG) Is it stopped?
2063 beq- trkill3 ; (TEST/DEBUG) yes...
2064 li r0,3 ; (TEST/DEBUG) ID number
2065 bl cte ; (TEST/DEBUG) Trace this
2066 stw r18,LTR_r1(r20) ; (TEST/DEBUG) Normal savearea
2067 stw r19,LTR_r2(r20) ; (TEST/DEBUG) next quickfret savearea
2068 stw r31,LTR_r3(r20) ; (TEST/DEBUG) Current one to toss
2069 trkill3:
2070 #endif
2071
2072 doqfrt: li r0,0 ; Get a constant 0
2073 lis r26,0x8000 /* Build a bit mask and assume first savearea */
2074 stw r0,SAVqfret(r31) ; Make sure back chain is unlinked
2075 lwz r28,SAVflags(r31) ; Get the flags for the old active one
2076 #if TRCSAVE
2077 beq- cr5,trkill4 ; (TEST/DEBUG) Do not trace this type
2078 lwz r14,LOW_ADDR(traceMask-EXT(ExceptionVectorsStart))(br0) ; (TEST/DEBUG) Get the trace mask
2079 mr. r14,r14 ; (TEST/DEBUG) Is it stopped?
2080 beq- trkill4 ; (TEST/DEBUG) yes...
2081 li r0,4 ; (TEST/DEBUG) ID number
2082 bl cte ; (TEST/DEBUG) Trace this
2083 stw r18,LTR_r1(r20) ; (TEST/DEBUG) Normal savearea
2084 stw r19,LTR_r2(r20) ; (TEST/DEBUG) next quickfret savearea
2085 stw r31,LTR_r3(r20) ; (TEST/DEBUG) Current one to toss
2086 stw r28,LTR_r4(r20) ; (TEST/DEBUG) Save current flags
2087 trkill4:
2088 #endif
2089 rlwinm r25,r31,21,31,31 /* Get position of savearea in block */
2090 andis. r28,r28,HIGH_ADDR(SAVinuse) /* See if we need to free it */
2091 srw r26,r26,r25 /* Get bit position to deallocate */
2092 rlwinm r29,r31,0,0,19 /* Round savearea pointer to even page address */
2093
2094 bne- fretagain /* Still in use, we can't free this one... */
2095
2096 lwz r23,SACalloc(r29) /* Get the allocation for this block */
2097 lwz r24,SVinuse(r30) /* Get the in use count */
2098 mr r28,r23 ; (TEST/DEBUG) save for trace
2099 or r23,r23,r26 /* Turn on our bit */
2100 subi r24,r24,1 /* Show that this one is free */
2101 cmplw r23,r26 /* Is our's the only one free? */
2102 stw r23,SACalloc(r29) /* Save it out */
2103 bne+ rstrest /* Nope, then the block is already on the free list */
2104
2105 lwz r22,SVfree(r30) /* Get the old head of the free list */
2106 stw r29,SVfree(r30) /* Point the head at us now */
2107 stw r22,SACnext(r29) ; Point us to the old last
2108
2109 rstrest: stw r24,SVinuse(r30) /* Set the in use count */
2110 #if TRCSAVE
2111 beq- cr5,trkill5 ; (TEST/DEBUG) Do not trace this type
2112 lwz r14,LOW_ADDR(traceMask-EXT(ExceptionVectorsStart))(br0) ; (TEST/DEBUG) Get the trace mask
2113 mr. r14,r14 ; (TEST/DEBUG) Is it stopped?
2114 beq- trkill5 ; (TEST/DEBUG) yes...
2115 li r0,5 ; (TEST/DEBUG) ID number
2116 bl cte ; (TEST/DEBUG) Trace this
2117 stw r18,LTR_r1(r20) ; (TEST/DEBUG) Normal savearea
2118 stw r19,LTR_r2(r20) ; (TEST/DEBUG) Next quickfret savearea
2119 stw r31,LTR_r3(r20) ; (TEST/DEBUG) Current one to toss
2120 stw r28,LTR_srr1(r20) ; (TEST/DEBUG) Save the original allocation
2121 stw r23,LTR_dar(r20) ; (TEST/DEBUG) Save the new allocation
2122 stw r24,LTR_save(r20) ; (TEST/DEBUG) Save the new in use count
2123 stw r22,LTR_lr(r20) ; (TEST/DEBUG) Save the old top of free list
2124 stw r29,LTR_ctr(r20) ; (TEST/DEBUG) Save the new top of free list
2125 trkill5:
2126 #endif
2127 b fretagain ; Go finish up the rest...
2128
2129 ;
2130 ; Build the SR values depending upon destination. If we are going to the kernel,
2131 ; the SRs are almost all the way set up. SR14 (or the currently used copyin/out register)
2132 ; must be set to whatever it was at the last exception because it varies. All the rest
2133 ; have been set up already.
2134 ;
2135 ; If we are going into user space, we need to check a bit more. SR0, SR1, SR2, and
2136 ; SR14 (current implementation) must be restored always. The others must be set if
2137 ; they are different that what was loaded last time (i.e., tasks have switched).
2138 ; We check the last loaded address space ID and if the same, we skip the loads.
2139 ; This is a performance gain because SR manipulations are slow.
2140 ;
2141
2142 .align 5
2143
2144 donefret: lwz r26,savesrr1(r31) ; Get destination state flags
2145 lwz r7,PP_USERPMAP(r2) ; Pick up the user pmap we may launch
2146 cmplw cr3,r14,r14 ; Set that we do not need to stop streams
2147 rlwinm. r17,r26,0,MSR_PR_BIT,MSR_PR_BIT ; See if we are going to user or system
2148 li r14,PMAP_SEGS ; Point to segments
2149 bne+ gotouser ; We are going into user state...
2150
2151 lwz r14,savesr14(r31) ; Get the copyin/out register at interrupt time
2152 mtsr sr14,r14 ; Set SR14
2153 b segsdone ; We are all set up now...
2154
2155 .align 5
2156
2157 gotouser: dcbt r14,r7 ; Touch the segment register contents
2158 lwz r9,spcFlags(r2) ; Pick up the special flags
2159 lwz r16,PP_LASTPMAP(r2) ; Pick up the last loaded pmap
2160 addi r14,r14,32 ; Second half of pmap segments
2161 rlwinm r9,r9,userProtKeybit-2,2,2 ; Isolate the user state protection key
2162 lwz r15,PMAP_SPACE(r7) ; Get the primary space
2163 lwz r13,PMAP_VFLAGS(r7) ; Get the flags
2164 dcbt r14,r7 ; Touch second page
2165 oris r15,r15,hi16(SEG_REG_PROT) ; Set segment 0 SR value
2166 mtcrf 0x0F,r13 ; Set CRs to correspond to the subordinate spaces
2167 xor r15,r15,r9 ; Flip to proper segment register key
2168 lhz r9,PP_CPU_FLAGS(r2) ; Get the processor flags
2169
2170 addis r13,r15,0x0000 ; Get SR0 value
2171 bf 16,nlsr0 ; No alternate here...
2172 lwz r13,PMAP_SEGS+(0*4)(r7) ; Get SR0 value
2173
2174 nlsr0: mtsr sr0,r13 ; Load up the SR
2175 rlwinm r9,r9,(((31-MSR_BE_BIT)+(traceBEb+16+1))&31),MSR_BE_BIT,MSR_BE_BIT ; Set BE bit if special trace is on
2176
2177 addis r13,r15,0x0010 ; Get SR1 value
2178 bf 17,nlsr1 ; No alternate here...
2179 lwz r13,PMAP_SEGS+(1*4)(r7) ; Get SR1 value
2180
2181 nlsr1: mtsr sr1,r13 ; Load up the SR
2182 or r26,r26,r9 ; Flip on the BE bit for special trace if needed
2183
2184 cmplw r7,r16 ; Are we running the same segs as last time?
2185
2186 addis r13,r15,0x0020 ; Get SR2 value
2187 bf 18,nlsr2 ; No alternate here...
2188 lwz r13,PMAP_SEGS+(2*4)(r7) ; Get SR2 value
2189
2190 nlsr2: mtsr sr2,r13 ; Load up the SR
2191
2192 addis r13,r15,0x0030 ; Get SR3 value
2193 bf 19,nlsr3 ; No alternate here...
2194 lwz r13,PMAP_SEGS+(3*4)(r7) ; Get SR3 value
2195
2196 nlsr3: mtsr sr3,r13 ; Load up the SR
2197
2198 addis r13,r15,0x00E0 ; Get SR14 value
2199 bf 30,nlsr14 ; No alternate here...
2200 lwz r13,PMAP_SEGS+(14*4)(r7) ; Get SR14 value
2201
2202 nlsr14: mtsr sr14,r13 ; Load up the SR
2203
2204 beq+ segsdone ; All done if same pmap as last time...
2205
2206 stw r7,PP_LASTPMAP(r2) ; Remember what we just loaded
2207
2208 addis r13,r15,0x0040 ; Get SR4 value
2209 bf 20,nlsr4 ; No alternate here...
2210 lwz r13,PMAP_SEGS+(4*4)(r7) ; Get SR4 value
2211
2212 nlsr4: mtsr sr4,r13 ; Load up the SR
2213
2214 addis r13,r15,0x0050 ; Get SR5 value
2215 bf 21,nlsr5 ; No alternate here...
2216 lwz r13,PMAP_SEGS+(5*4)(r7) ; Get SR5 value
2217
2218 nlsr5: mtsr sr5,r13 ; Load up the SR
2219
2220 addis r13,r15,0x0060 ; Get SR6 value
2221 bf 22,nlsr6 ; No alternate here...
2222 lwz r13,PMAP_SEGS+(6*4)(r7) ; Get SR6 value
2223
2224 nlsr6: mtsr sr6,r13 ; Load up the SR
2225
2226 addis r13,r15,0x0070 ; Get SR7 value
2227 bf 23,nlsr7 ; No alternate here...
2228 lwz r13,PMAP_SEGS+(7*4)(r7) ; Get SR7 value
2229
2230 nlsr7: mtsr sr7,r13 ; Load up the SR
2231
2232 addis r13,r15,0x0080 ; Get SR8 value
2233 bf 24,nlsr8 ; No alternate here...
2234 lwz r13,PMAP_SEGS+(8*4)(r7) ; Get SR8 value
2235
2236 nlsr8: mtsr sr8,r13 ; Load up the SR
2237
2238 addis r13,r15,0x0090 ; Get SR9 value
2239 bf 25,nlsr9 ; No alternate here...
2240 lwz r13,PMAP_SEGS+(9*4)(r7) ; Get SR9 value
2241
2242 nlsr9: mtsr sr9,r13 ; Load up the SR
2243
2244 addis r13,r15,0x00A0 ; Get SR10 value
2245 bf 26,nlsr10 ; No alternate here...
2246 lwz r13,PMAP_SEGS+(10*4)(r7) ; Get SR10 value
2247
2248 nlsr10: mtsr sr10,r13 ; Load up the SR
2249
2250 addis r13,r15,0x00B0 ; Get SR11 value
2251 bf 27,nlsr11 ; No alternate here...
2252 lwz r13,PMAP_SEGS+(11*4)(r7) ; Get SR11 value
2253
2254 nlsr11: mtsr sr11,r13 ; Load up the SR
2255
2256 addis r13,r15,0x00C0 ; Get SR12 value
2257 bf 28,nlsr12 ; No alternate here...
2258 lwz r13,PMAP_SEGS+(12*4)(r7) ; Get SR12 value
2259
2260 nlsr12: mtsr sr12,r13 ; Load up the SR
2261
2262 addis r13,r15,0x00D0 ; Get SR13 value
2263 bf 29,nlsr13 ; No alternate here...
2264 lwz r13,PMAP_SEGS+(13*4)(r7) ; Get SR13 value
2265
2266 nlsr13: mtsr sr13,r13 ; Load up the SR
2267
2268 addis r13,r15,0x00F0 ; Get SR15 value
2269 bf 31,nlsr15 ; No alternate here...
2270 lwz r13,PMAP_SEGS+(15*4)(r7) ; Get SR15 value
2271
2272 nlsr15: mtsr sr15,r13 ; Load up the SR
2273
2274 segsdone: li r1,emfp0 ; Point to the fp savearea
2275 lwz r25,savesrr0(r31) ; Get the SRR0 to use
2276 la r28,saver6(r31) /* Point to the next line to use */
2277 dcbt r1,r2 ; Start moving in a work area
2278 lwz r0,saver0(r31) /* Restore */
2279 dcbt 0,r28 /* Touch it in */
2280 mr r29,r2 ; Save the per_proc
2281 lwz r1,saver1(r31) /* Restore */
2282 lwz r2,saver2(r31) /* Restore */
2283 la r28,saver14(r31) /* Point to the next line to get */
2284 lwz r3,saver3(r31) /* Restore */
2285 mtcrf 0x80,r27 ; Get facility availability flags (do not touch CR1-7)
2286 lwz r4,saver4(r31) /* Restore */
2287 mtsrr0 r25 /* Restore the SRR0 now */
2288 lwz r5,saver5(r31) /* Restore */
2289 mtsrr1 r26 /* Restore the SRR1 now */
2290 lwz r6,saver6(r31) /* Restore */
2291
2292 dcbt 0,r28 /* Touch that next line on in */
2293 la r28,savexfpscrpad(r31) ; Point to the saved fpscr
2294
2295 lwz r7,saver7(r31) /* Restore */
2296 dcbt 0,r28 ; Touch saved fpscr
2297 lwz r8,saver8(r31) /* Restore */
2298 lwz r9,saver9(r31) /* Restore */
2299 lwz r10,saver10(r31) /* Restore */
2300 lwz r11,saver11(r31) /* Restore */
2301 lwz r12,saver12(r31) /* Restore */
2302 lwz r13,saver13(r31) /* Restore */
2303 la r28,saver22(r31) /* Point to the next line to do */
2304 lwz r14,saver14(r31) /* Restore */
2305 lwz r15,saver15(r31) /* Restore */
2306
2307 ;
2308 ; Note that floating point will be enabled from here on until the RFI
2309 ;
2310
2311 bf- pfFloatb,nofphere ; Skip if no floating point...
2312 mfmsr r27 ; Save the MSR
2313 ori r27,r27,lo16(MASK(MSR_FP)) ; Enable floating point
2314 mtmsr r27 ; Really enable
2315 isync
2316 stfd f0,emfp0(r29) ; Save FP0
2317 lfd f0,savexfpscrpad(r31) ; Get the fpscr
2318 mtfsf 0xFF,f0 ; Restore fpscr
2319 lfd f0,emfp0(r29) ; Restore the used register
2320
2321 nofphere: dcbt 0,r28 /* Touch in another line of context */
2322
2323 lwz r16,saver16(r31) /* Restore */
2324 lwz r17,saver17(r31) /* Restore */
2325 lwz r18,saver18(r31) /* Restore */
2326 lwz r19,saver19(r31) /* Restore */
2327 lwz r20,saver20(r31) /* Restore */
2328 lwz r21,saver21(r31) /* Restore */
2329 la r28,saver30(r31) /* Point to the final line */
2330 lwz r22,saver22(r31) /* Restore */
2331
2332 dcbt 0,r28 /* Suck it in */
2333
2334 lwz r23,saver23(r31) /* Restore */
2335 lwz r24,saver24(r31) /* Restore */
2336 lwz r25,saver25(r31) /* Restore */
2337 lwz r26,saver26(r31) /* Restore */
2338 lwz r27,saver27(r31) /* Restore */
2339
2340 lwz r28,savecr(r31) /* Get CR to restore */
2341 bf pfAltivecb,noavec4 ; No vector on this machine
2342 lwz r29,savevrsave(r31) ; Get the vrsave
2343 beq+ cr3,noavec3 ; SRs have not changed, no need to stop the streams...
2344 dssall ; Kill all data streams
2345 ; The streams should be suspended
2346 ; already, and we do a bunch of
2347 ; dependent loads and a sync later
2348 ; so we should be cool.
2349
2350 noavec3: mtspr vrsave,r29 ; Set the vrsave
2351
2352 noavec4: lwz r29,savexer(r31) /* Get XER to restore */
2353 mtcr r28 /* Restore the CR */
2354 lwz r28,savelr(r31) /* Get LR to restore */
2355 mtxer r29 /* Restore the XER */
2356 lwz r29,savectr(r31) /* Get the CTR to restore */
2357 mtlr r28 /* Restore the LR */
2358 lwz r28,saver30(r31) /* Restore */
2359 mtctr r29 /* Restore the CTR */
2360 lwz r29,saver31(r31) /* Restore */
2361 mtsprg 2,r28 /* Save R30 */
2362 lwz r28,saver28(r31) /* Restore */
2363 mtsprg 3,r29 /* Save R31 */
2364 lwz r29,saver29(r31) /* Restore */
2365
2366 #if PERFTIMES && DEBUG
2367 stmw r1,0x280(br0) ; Save all registers
2368 mfcr r20 ; Save the CR
2369 mflr r21 ; Save the LR
2370 mfsrr0 r9 ; Save SRR0
2371 mfsrr1 r11 ; Save SRR1
2372 mr r8,r0 ; Save R0
2373 li r3,69 ; Indicate interrupt
2374 mr r4,r11 ; Set MSR to log
2375 mr r5,r31 ; Get savearea to log
2376 bl EXT(dbgLog2) ; Cut log entry
2377 mr r0,r8 ; Restore R0
2378 mtsrr0 r9 ; Restore SRR0
2379 mtsrr1 r11 ; Restore SRR1
2380 mtlr r21 ; Restore the LR
2381 mtcr r20 ; Restore the CR
2382 lmw r1,0x280(br0) ; Restore all the rest
2383 #endif
2384
2385 li r31,0 /* Get set to clear lock */
2386 sync /* Make sure it's all out there */
2387 stw r31,SVlock(r30) /* Unlock it */
2388 mfsprg r30,2 /* Restore R30 */
2389 mfsprg r31,0 ; Get per_proc
2390 lwz r31,pfAvailable(r31) ; Get the feature flags
2391 mtsprg 2,r31 ; Set the feature flags
2392 mfsprg r31,3 /* Restore R31 */
2393
2394 rfi /* Click heels three times and think very hard that there's no place like home */
2395
2396 .long 0 /* For old 601 bug */
2397 .long 0
2398 .long 0
2399 .long 0
2400 .long 0
2401 .long 0
2402 .long 0
2403 .long 0
2404
2405
2406
2407
2408 /*
2409 * exception_exit(savearea *)
2410 *
2411 *
2412 * ENTRY : IR and/or DR and/or interruptions can be on
2413 * R3 points to the physical address of a savearea
2414 */
2415
2416 .align 5
2417 .globl EXT(exception_exit)
2418
2419 LEXT(exception_exit)
2420
2421 mfsprg r29,2 ; Get feature flags
2422 mfmsr r30 /* Get the current MSR */
2423 mtcrf 0x04,r29 ; Set the features
2424 mr r31,r3 /* Get the savearea in the right register */
2425 andi. r30,r30,0x7FCF /* Turn off externals, IR, and DR */
2426 lis r1,hi16(SAVredrive) ; Get redrive request
2427
2428 bt pfNoMSRirb,eeNoMSR ; No MSR...
2429
2430 mtmsr r30 ; Translation and all off
2431 isync ; Toss prefetch
2432 b eeNoMSRx
2433
2434 eeNoMSR: li r0,loadMSR ; Get the MSR setter SC
2435 mr r3,r30 ; Get new MSR
2436 sc ; Set it
2437
2438 eeNoMSRx:
2439 mfsprg r2,0 ; Get the per_proc block
2440 lwz r4,SAVflags(r31) ; Pick up the flags
2441 mr r13,r31 ; Put savearea here also
2442
2443 and. r0,r4,r1 ; Check if redrive requested
2444 andc r4,r4,r1 ; Clear redrive
2445
2446 dcbt br0,r2 ; We will need this in just a sec
2447
2448 beq+ EatRupt ; No redrive, just exit...
2449
2450 lwz r3,saveexception(r13) ; Restore exception code
2451 stw r4,SAVflags(r13) ; Set the flags
2452 b Redrive ; Redrive the exception...
2453
2454 ;
2455 ; Make trace entry for lowmem_vectors internal debug
2456 ;
2457 #if TRCSAVE
2458 cte:
2459 lwz r20,LOW_ADDR(EXT(traceCurr)-EXT(ExceptionVectorsStart))(br0) ; Pick up the current trace entry
2460 lwz r16,LOW_ADDR(EXT(traceEnd)-EXT(ExceptionVectorsStart))(br0) ; Grab up the end of it all
2461 addi r17,r20,LTR_size ; Point to the next trace entry
2462 cmplw r17,r16 ; Do we need to wrap the trace table?
2463 li r15,32 ; Second line of entry
2464 bne+ ctenwrap ; We got a trace entry...
2465 lwz r17,LOW_ADDR(EXT(traceStart)-EXT(ExceptionVectorsStart))(br0) ; Wrap back to the top
2466
2467 ctenwrap: stw r17,LOW_ADDR(EXT(traceCurr)-EXT(ExceptionVectorsStart))(br0) ; Set the next entry for the next guy
2468
2469 bf- featL1ena,skipz8 ; L1 cache is disabled...
2470 dcbz 0,r20 ; Allocate cache for the entry
2471 dcbz r15,r20 ; Zap the second half
2472 skipz8:
2473
2474 ctegetTB: mftbu r16 ; Get the upper timebase
2475 mftb r17 ; Get the lower timebase
2476 mftbu r15 ; Get the upper one again
2477 cmplw r16,r15 ; Did the top tick?
2478 bne- ctegetTB ; Yeah, need to get it again...
2479
2480 li r15,0x111 ; Get the special trace ID code
2481 stw r0,LTR_r0(r20) ; Save R0 (usually used as an ID number
2482 stw r16,LTR_timeHi(r20) ; Set the upper part of TB
2483 mflr r16 ; Get the return point
2484 stw r17,LTR_timeLo(r20) ; Set the lower part of TB
2485 sth r15,LTR_excpt(r20) ; Save the exception type
2486 stw r16,LTR_srr0(r20) ; Save the return point
2487 blr ; Leave...
2488 #endif
2489
2490 /*
2491 * Start of the trace table
2492 */
2493
2494 .align 12 /* Align to 4k boundary */
2495
2496 .globl EXT(traceTableBeg)
2497 EXT(traceTableBeg): /* Start of trace table */
2498 /* .fill 2048,4,0 Make an 8k trace table for now */
2499 .fill 13760,4,0 /* Make an .trace table for now */
2500 /* .fill 240000,4,0 Make an .trace table for now */
2501 .globl EXT(traceTableEnd)
2502 EXT(traceTableEnd): /* End of trace table */
2503
2504 .globl EXT(ExceptionVectorsEnd)
2505 EXT(ExceptionVectorsEnd): /* Used if relocating the exception vectors */
2506 #ifndef HACKALERTHACKALERT
2507 /*
2508 * This .long needs to be here because the linker gets confused and tries to
2509 * include the final label in a section in the next section if there is nothing
2510 * after it
2511 */
2512 .long 0 /* (HACK/HACK/HACK) */
2513 #endif
2514
2515 .data
2516 .align ALIGN
2517 .globl EXT(exception_end)
2518 EXT(exception_end):
2519 .long EXT(ExceptionVectorsEnd) -EXT(ExceptionVectorsStart) /* phys fn */
2520
2521