2 /* $NetBSD: trap_subr.S,v 1.20 2002/04/22 23:20:08 kleink Exp $ */
5 * Copyright (C) 1995, 1996 Wolfgang Solfrank.
6 * Copyright (C) 1995, 1996 TooLs GmbH.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by TooLs GmbH.
20 * 4. The name of TooLs GmbH may not be used to endorse or promote products
21 * derived from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * NOTICE: This is not a standalone file. to use it, #include it in
37 * your port's locore.S, like so:
39 * #include <powerpc/aim/trap_subr.S>
42 /* Locate the per-CPU data structure */
43 #define GET_CPUINFO(r) \
45 #define GET_TOCBASE(r) \
46 lis r,DMAP_BASE_ADDRESS@highesta; /* To real-mode alias/dmap */ \
48 ori r,r,TRAP_TOCBASE; /* Magic address for TOC */ \
52 * Restore SRs for a pmap
54 * Requires that r28-r31 be scratch, with r28 initialized to the SLB cache
58 * User SRs are loaded through a pointer to the current pmap.
62 ld %r28,PC_USERSLB(%r3)
63 cmpdi %r28, 0 /* If user SLB pointer NULL, exit */
66 li %r29, 0 /* Set the counter to zero */
72 1: ld %r31, 0(%r28) /* Load SLB entry pointer */
73 cmpdi %r31, 0 /* If NULL, stop */
76 ld %r30, 0(%r31) /* Load SLBV */
77 ld %r31, 8(%r31) /* Load SLBE */
78 or %r31, %r31, %r29 /* Set SLBE slot */
79 slbmte %r30, %r31 /* Install SLB entry */
81 addi %r28, %r28, 8 /* Advance pointer */
86 * Kernel SRs are loaded directly from the PCPU fields
90 lwz %r29, PC_FLAGS(%r1)
93 addi %r28,%r1,PC_KERNSLB
94 ld %r29,16(%r28) /* One past USER_SLB_SLOT */
96 beqlr /* If first kernel entry is invalid,
97 * SLBs not in use, so exit early */
99 /* Otherwise, set up SLBs */
100 li %r29, 0 /* Set the counter to zero */
106 1: cmpdi %r29, USER_SLB_SLOT /* Skip the user slot */
109 ld %r31, 8(%r28) /* Load SLBE */
110 cmpdi %r31, 0 /* If SLBE is not valid, stop */
112 ld %r30, 0(%r28) /* Load SLBV */
113 slbmte %r30, %r31 /* Install SLB entry */
115 2: addi %r28, %r28, 16 /* Advance pointer */
117 cmpdi %r29, 64 /* Repeat if we are not at the end */
122 * FRAME_SETUP assumes:
125 * savearea r27-r31,DAR,DSISR (DAR & DSISR only for DSI traps)
131 * SRR0/1 as at start of trap
133 * NOTE: SPRG1 is never used while the MMU is on, making it safe to reuse
134 * in any real-mode fault handler, including those handling double faults.
136 #define FRAME_SETUP(savearea) \
137 /* Have to enable translation to allow access of kernel stack: */ \
140 std %r30,(savearea+CPUSAVE_SRR0)(%r31); /* save SRR0 */ \
142 std %r30,(savearea+CPUSAVE_SRR1)(%r31); /* save SRR1 */ \
143 mfsprg1 %r31; /* get saved SP (clears SPRG1) */ \
145 ori %r30,%r30,(PSL_DR|PSL_IR|PSL_RI)@l; /* relocation on */ \
146 mtmsr %r30; /* stack can now be accessed */ \
148 stdu %r31,-(FRAMELEN+288)(%r1); /* save it in the callframe */ \
149 std %r0, FRAME_0+48(%r1); /* save r0 in the trapframe */ \
150 std %r31,FRAME_1+48(%r1); /* save SP " " */ \
151 std %r2, FRAME_2+48(%r1); /* save r2 " " */ \
152 std %r28,FRAME_LR+48(%r1); /* save LR " " */ \
153 std %r29,FRAME_CR+48(%r1); /* save CR " " */ \
155 ld %r27,(savearea+CPUSAVE_R27)(%r2); /* get saved r27 */ \
156 ld %r28,(savearea+CPUSAVE_R28)(%r2); /* get saved r28 */ \
157 ld %r29,(savearea+CPUSAVE_R29)(%r2); /* get saved r29 */ \
158 ld %r30,(savearea+CPUSAVE_R30)(%r2); /* get saved r30 */ \
159 ld %r31,(savearea+CPUSAVE_R31)(%r2); /* get saved r31 */ \
160 std %r3, FRAME_3+48(%r1); /* save r3-r31 */ \
161 std %r4, FRAME_4+48(%r1); \
162 std %r5, FRAME_5+48(%r1); \
163 std %r6, FRAME_6+48(%r1); \
164 std %r7, FRAME_7+48(%r1); \
165 std %r8, FRAME_8+48(%r1); \
166 std %r9, FRAME_9+48(%r1); \
167 std %r10, FRAME_10+48(%r1); \
168 std %r11, FRAME_11+48(%r1); \
169 std %r12, FRAME_12+48(%r1); \
170 std %r13, FRAME_13+48(%r1); \
171 std %r14, FRAME_14+48(%r1); \
172 std %r15, FRAME_15+48(%r1); \
173 std %r16, FRAME_16+48(%r1); \
174 std %r17, FRAME_17+48(%r1); \
175 std %r18, FRAME_18+48(%r1); \
176 std %r19, FRAME_19+48(%r1); \
177 std %r20, FRAME_20+48(%r1); \
178 std %r21, FRAME_21+48(%r1); \
179 std %r22, FRAME_22+48(%r1); \
180 std %r23, FRAME_23+48(%r1); \
181 std %r24, FRAME_24+48(%r1); \
182 std %r25, FRAME_25+48(%r1); \
183 std %r26, FRAME_26+48(%r1); \
184 std %r27, FRAME_27+48(%r1); \
185 std %r28, FRAME_28+48(%r1); \
186 std %r29, FRAME_29+48(%r1); \
187 std %r30, FRAME_30+48(%r1); \
188 std %r31, FRAME_31+48(%r1); \
189 ld %r28,(savearea+CPUSAVE_AIM_DAR)(%r2); /* saved DAR */ \
190 ld %r29,(savearea+CPUSAVE_AIM_DSISR)(%r2);/* saved DSISR */\
191 ld %r30,(savearea+CPUSAVE_SRR0)(%r2); /* saved SRR0 */ \
192 ld %r31,(savearea+CPUSAVE_SRR1)(%r2); /* saved SRR1 */ \
196 std %r3, FRAME_XER+48(1); /* save xer/ctr/exc */ \
197 std %r4, FRAME_CTR+48(1); \
198 std %r5, FRAME_EXC+48(1); \
199 std %r28,FRAME_AIM_DAR+48(1); \
200 std %r29,FRAME_AIM_DSISR+48(1); /* save dsisr/srr0/srr1 */ \
201 std %r30,FRAME_SRR0+48(1); \
202 std %r31,FRAME_SRR1+48(1); \
203 ld %r13,PC_CURTHREAD(%r2) /* set kernel curthread */
205 #define FRAME_LEAVE(savearea) \
206 /* Disable exceptions: */ \
208 andi. %r2,%r2,~PSL_EE@l; \
211 /* Now restore regs: */ \
212 ld %r2,FRAME_SRR0+48(%r1); \
213 ld %r3,FRAME_SRR1+48(%r1); \
214 ld %r4,FRAME_CTR+48(%r1); \
215 ld %r5,FRAME_XER+48(%r1); \
216 ld %r6,FRAME_LR+48(%r1); \
218 std %r2,(savearea+CPUSAVE_SRR0)(%r7); /* save SRR0 */ \
219 std %r3,(savearea+CPUSAVE_SRR1)(%r7); /* save SRR1 */ \
220 ld %r7,FRAME_CR+48(%r1); \
224 mtsprg2 %r7; /* save cr */ \
225 ld %r31,FRAME_31+48(%r1); /* restore r0-31 */ \
226 ld %r30,FRAME_30+48(%r1); \
227 ld %r29,FRAME_29+48(%r1); \
228 ld %r28,FRAME_28+48(%r1); \
229 ld %r27,FRAME_27+48(%r1); \
230 ld %r26,FRAME_26+48(%r1); \
231 ld %r25,FRAME_25+48(%r1); \
232 ld %r24,FRAME_24+48(%r1); \
233 ld %r23,FRAME_23+48(%r1); \
234 ld %r22,FRAME_22+48(%r1); \
235 ld %r21,FRAME_21+48(%r1); \
236 ld %r20,FRAME_20+48(%r1); \
237 ld %r19,FRAME_19+48(%r1); \
238 ld %r18,FRAME_18+48(%r1); \
239 ld %r17,FRAME_17+48(%r1); \
240 ld %r16,FRAME_16+48(%r1); \
241 ld %r15,FRAME_15+48(%r1); \
242 ld %r14,FRAME_14+48(%r1); \
243 ld %r13,FRAME_13+48(%r1); \
244 ld %r12,FRAME_12+48(%r1); \
245 ld %r11,FRAME_11+48(%r1); \
246 ld %r10,FRAME_10+48(%r1); \
247 ld %r9, FRAME_9+48(%r1); \
248 ld %r8, FRAME_8+48(%r1); \
249 ld %r7, FRAME_7+48(%r1); \
250 ld %r6, FRAME_6+48(%r1); \
251 ld %r5, FRAME_5+48(%r1); \
252 ld %r4, FRAME_4+48(%r1); \
253 ld %r3, FRAME_3+48(%r1); \
254 ld %r2, FRAME_2+48(%r1); \
255 ld %r0, FRAME_0+48(%r1); \
256 ld %r1, FRAME_1+48(%r1); \
257 /* Can't touch %r1 from here on */ \
258 mtsprg3 %r3; /* save r3 */ \
259 /* Disable translation, machine check and recoverability: */ \
261 andi. %r3,%r3,~(PSL_DR|PSL_IR|PSL_ME|PSL_RI)@l; \
264 /* Decide whether we return to user mode: */ \
266 ld %r3,(savearea+CPUSAVE_SRR1)(%r3); \
268 bf 17,1f; /* branch if PSL_PR is false */ \
269 /* Restore user SRs */ \
271 std %r27,(savearea+CPUSAVE_R27)(%r3); \
272 lwz %r27,PC_FLAGS(%r3); \
274 bt 0, 0f; /* Check to skip restoring SRs. */ \
275 std %r28,(savearea+CPUSAVE_R28)(%r3); \
276 std %r29,(savearea+CPUSAVE_R29)(%r3); \
277 std %r30,(savearea+CPUSAVE_R30)(%r3); \
278 std %r31,(savearea+CPUSAVE_R31)(%r3); \
279 mflr %r27; /* preserve LR */ \
280 bl restore_usersrs; /* uses r28-r31 */ \
282 ld %r31,(savearea+CPUSAVE_R31)(%r3); \
283 ld %r30,(savearea+CPUSAVE_R30)(%r3); \
284 ld %r29,(savearea+CPUSAVE_R29)(%r3); \
285 ld %r28,(savearea+CPUSAVE_R28)(%r3); \
287 ld %r27,(savearea+CPUSAVE_R27)(%r3); \
288 1: mfsprg2 %r3; /* restore cr */ \
291 ld %r3,(savearea+CPUSAVE_SRR0)(%r3); /* restore srr0 */ \
294 ld %r3,(savearea+CPUSAVE_SRR1)(%r3); /* restore srr1 */ \
296 mfsprg3 %r3 /* restore r3 */
300 .globl dtrace_invop_calltrap_addr
302 .type dtrace_invop_calltrap_addr, @object
303 .size dtrace_invop_calltrap_addr, 8
304 dtrace_invop_calltrap_addr:
312 * Processor reset exception handler. These are typically
313 * the first instructions the processor executes after a
314 * software reset. We do this in two bits so that we are
315 * not still hanging around in the trap handling region
316 * once the MMU is turned on.
318 .globl CNAME(rstcode), CNAME(rstcodeend), CNAME(cpu_reset_handler)
319 .globl CNAME(cpu_wakeup_handler)
322 #ifdef __LITTLE_ENDIAN__
324 * XXX This shouldn't be necessary.
326 * According to the ISA documentation, LE should be set from HILE
327 * or the LPCR ILE bit automatically. However, the entry into this
328 * vector from OPAL_START_CPU does not honor this correctly.
330 * We should be able to define an alternate entry for opal's
331 * start_kernel_secondary asm code to branch to.
333 RETURN_TO_NATIVE_ENDIAN
336 * Check if this is software reset or
337 * processor is waking up from power saving mode
338 * It is software reset when 46:47 = 0b00
341 ld %r2,TRAP_GENTRAP(0) /* Real-mode &generictrap */
342 mfsrr1 %r9 /* Load SRR1 into r9 */
343 andis. %r9,%r9,0x3 /* Logic AND with 46:47 bits */
345 beq 2f /* Branch if software reset */
347 /* Reset was wakeup */
348 addi %r9,%r2,(cpu_wakeup_handler-generictrap)
349 b 1f /* Was power save, do the wakeup */
351 /* Reset was software reset */
352 /* Explicitly set MSR[SF] */
360 addi %r9,%r2,(cpu_reset_handler-generictrap)
364 blr /* Branch to either cpu_reset_handler
365 * or cpu_wakeup_handler.
372 addis %r1,%r2,TOC_REF(tmpstk)@ha
373 ld %r1,TOC_REF(tmpstk)@l(%r1) /* get new SP */
374 addi %r1,%r1,(TMPSTKSZ-48)
376 bl CNAME(cpudep_ap_early_bootstrap) /* Set PCPU */
379 bl CNAME(pmap_cpu_bootstrap) /* Turn on virtual memory */
381 bl CNAME(cpudep_ap_bootstrap) /* Set up PCPU and stack */
383 mr %r1,%r3 /* Use new stack */
384 bl CNAME(cpudep_ap_setup)
387 ld %r3,(PC_RESTORE)(%r5)
396 bl CNAME(machdep_ap_bootstrap) /* And away! */
400 /* Should not be reached */
407 /* Check for false wake up due to badly SRR1 set (eg. by OPAL) */
408 addis %r3,%r2,TOC_REF(can_wakeup)@ha
409 ld %r3,TOC_REF(can_wakeup)@l(%r3)
412 beq cpu_reset_handler
414 /* Turn on MMU after return from interrupt */
416 ori %r3,%r3,(PSL_IR | PSL_DR)
419 /* Turn on MMU (needed to access PCB) */
421 ori %r3,%r3,(PSL_IR | PSL_DR)
427 ld %r3,PC_CURTHREAD(%r3) /* Get current thread */
428 ld %r3,TD_PCB(%r3) /* Get PCB of current thread */
429 ld %r12,PCB_CONTEXT(%r3) /* Load the non-volatile GP regs. */
430 ld %r13,PCB_CONTEXT+1*8(%r3)
431 ld %r14,PCB_CONTEXT+2*8(%r3)
432 ld %r15,PCB_CONTEXT+3*8(%r3)
433 ld %r16,PCB_CONTEXT+4*8(%r3)
434 ld %r17,PCB_CONTEXT+5*8(%r3)
435 ld %r18,PCB_CONTEXT+6*8(%r3)
436 ld %r19,PCB_CONTEXT+7*8(%r3)
437 ld %r20,PCB_CONTEXT+8*8(%r3)
438 ld %r21,PCB_CONTEXT+9*8(%r3)
439 ld %r22,PCB_CONTEXT+10*8(%r3)
440 ld %r23,PCB_CONTEXT+11*8(%r3)
441 ld %r24,PCB_CONTEXT+12*8(%r3)
442 ld %r25,PCB_CONTEXT+13*8(%r3)
443 ld %r26,PCB_CONTEXT+14*8(%r3)
444 ld %r27,PCB_CONTEXT+15*8(%r3)
445 ld %r28,PCB_CONTEXT+16*8(%r3)
446 ld %r29,PCB_CONTEXT+17*8(%r3)
447 ld %r30,PCB_CONTEXT+18*8(%r3)
448 ld %r31,PCB_CONTEXT+19*8(%r3)
449 ld %r5,PCB_CR(%r3) /* Load the condition register */
451 ld %r5,PCB_LR(%r3) /* Load the link register */
453 ld %r1,PCB_SP(%r3) /* Load the stack pointer */
454 ld %r2,PCB_TOC(%r3) /* Load the TOC pointer */
459 * This code gets copied to all the trap vectors
460 * (except ISI/DSI, ALI, and the interrupts). Has to fit in 8 instructions!
463 .globl CNAME(trapcode),CNAME(trapcodeend)
466 mtsprg1 %r1 /* save SP */
467 mflr %r1 /* Save the old LR in r1 */
468 mtsprg2 %r1 /* And then in SPRG2 */
471 li %r1, 0xe0 /* How to get the vector from LR */
472 blrl /* Branch to generictrap */
475 /* Same thing for traps setting HSRR0/HSRR1 */
476 .globl CNAME(hypertrapcode),CNAME(hypertrapcodeend)
478 CNAME(hypertrapcode):
479 mtsprg1 %r1 /* save SP */
480 mflr %r1 /* Save the old LR in r1 */
481 mtsprg2 %r1 /* And then in SPRG2 */
482 ld %r1,TRAP_GENTRAP(0)
483 addi %r1,%r1,(generichypertrap-generictrap)
485 li %r1, 0xe0 /* How to get the vector from LR */
486 blrl /* Branch to generichypertrap */
487 CNAME(hypertrapcodeend):
490 * For SLB misses: do special things for the kernel
492 * Note: SPRG1 is always safe to overwrite any time the MMU was on, which is
493 * the only time this can be called.
495 .globl CNAME(slbtrap),CNAME(slbtrapend)
499 mtsprg1 %r1 /* save SP */
501 std %r2,(PC_SLBSAVE+16)(%r1) /* save r2 */
504 std %r2,(PC_SLBSAVE+104)(%r1) /* save CR */
505 mfsrr1 %r2 /* test kernel mode */
507 bf 17,2f /* branch if PSL_PR is false */
510 ld %r2,(PC_SLBSAVE+104)(%r1)
511 mtcr %r2 /* restore CR */
512 ld %r2,(PC_SLBSAVE+16)(%r1) /* restore r2 */
515 mtsprg2 %r1 /* save LR in SPRG2 */
516 ld %r1,TRAP_ENTRY(0) /* real-mode &generictrap */
518 li %r1, 0x80 /* How to get the vector from LR */
520 blrl /* Branch to generictrap */
521 2: mflr %r2 /* Save the old LR in r2 */
523 ld %r1,TRAP_GENTRAP(0) /* Real-mode &generictrap */
524 addi %r1,%r1,(kern_slbtrap-generictrap)
528 blrl /* Branch to kern_slbtrap */
529 /* must fit in 128 bytes! */
537 * LR: branch address in trap region
540 std %r2,(PC_SLBSAVE+136)(%r1) /* old LR */
541 std %r3,(PC_SLBSAVE+24)(%r1) /* save R3 */
543 /* Check if this needs to be handled as a regular trap (userseg miss) */
551 2: /* r2 now contains the fault address */
552 lis %r3,SEGMENT_MASK@highesta
553 ori %r3,%r3,SEGMENT_MASK@highera
555 oris %r3,%r3,SEGMENT_MASK@ha
556 ori %r3,%r3,SEGMENT_MASK@l
557 and %r2,%r2,%r3 /* R2 = segment base address */
558 lis %r3,USER_ADDR@highesta
559 ori %r3,%r3,USER_ADDR@highera
561 oris %r3,%r3,USER_ADDR@ha
562 ori %r3,%r3,USER_ADDR@l
563 cmpd %r2,%r3 /* Compare fault base to USER_ADDR */
566 /* User seg miss, handle as a regular trap */
567 ld %r2,(PC_SLBSAVE+104)(%r1) /* Restore CR */
569 ld %r2,(PC_SLBSAVE+16)(%r1) /* Restore R2,R3 */
570 ld %r3,(PC_SLBSAVE+24)(%r1)
571 ld %r1,(PC_SLBSAVE+136)(%r1) /* Save the old LR in r1 */
572 mtsprg2 %r1 /* And then in SPRG2 */
573 li %r1, 0x80 /* How to get the vector from LR */
574 b generictrap /* Retain old LR using b */
576 3: /* Real kernel SLB miss */
577 std %r0,(PC_SLBSAVE+0)(%r1) /* free all volatile regs */
578 mfsprg1 %r2 /* Old R1 */
579 std %r2,(PC_SLBSAVE+8)(%r1)
580 /* R2,R3 already saved */
581 std %r4,(PC_SLBSAVE+32)(%r1)
582 std %r5,(PC_SLBSAVE+40)(%r1)
583 std %r6,(PC_SLBSAVE+48)(%r1)
584 std %r7,(PC_SLBSAVE+56)(%r1)
585 std %r8,(PC_SLBSAVE+64)(%r1)
586 std %r9,(PC_SLBSAVE+72)(%r1)
587 std %r10,(PC_SLBSAVE+80)(%r1)
588 std %r11,(PC_SLBSAVE+88)(%r1)
589 std %r12,(PC_SLBSAVE+96)(%r1)
590 /* CR already saved */
591 mfxer %r2 /* save XER */
592 std %r2,(PC_SLBSAVE+112)(%r1)
593 mflr %r2 /* save LR (SP already saved) */
594 std %r2,(PC_SLBSAVE+120)(%r1)
595 mfctr %r2 /* save CTR */
596 std %r2,(PC_SLBSAVE+128)(%r1)
599 addi %r1,%r1,PC_SLBSTACK-48+1024
607 bl handle_kernel_slb_spill
610 /* Save r28-31, restore r4-r12 */
612 ld %r4,(PC_SLBSAVE+32)(%r1)
613 ld %r5,(PC_SLBSAVE+40)(%r1)
614 ld %r6,(PC_SLBSAVE+48)(%r1)
615 ld %r7,(PC_SLBSAVE+56)(%r1)
616 ld %r8,(PC_SLBSAVE+64)(%r1)
617 ld %r9,(PC_SLBSAVE+72)(%r1)
618 ld %r10,(PC_SLBSAVE+80)(%r1)
619 ld %r11,(PC_SLBSAVE+88)(%r1)
620 ld %r12,(PC_SLBSAVE+96)(%r1)
621 std %r28,(PC_SLBSAVE+64)(%r1)
622 std %r29,(PC_SLBSAVE+72)(%r1)
623 std %r30,(PC_SLBSAVE+80)(%r1)
624 std %r31,(PC_SLBSAVE+88)(%r1)
626 /* Restore kernel mapping */
629 /* Restore remaining registers */
630 ld %r28,(PC_SLBSAVE+64)(%r1)
631 ld %r29,(PC_SLBSAVE+72)(%r1)
632 ld %r30,(PC_SLBSAVE+80)(%r1)
633 ld %r31,(PC_SLBSAVE+88)(%r1)
635 ld %r2,(PC_SLBSAVE+104)(%r1)
637 ld %r2,(PC_SLBSAVE+112)(%r1)
639 ld %r2,(PC_SLBSAVE+120)(%r1)
641 ld %r2,(PC_SLBSAVE+128)(%r1)
643 ld %r2,(PC_SLBSAVE+136)(%r1)
647 ld %r0,(PC_SLBSAVE+0)(%r1)
648 ld %r2,(PC_SLBSAVE+16)(%r1)
649 ld %r3,(PC_SLBSAVE+24)(%r1)
652 /* Back to whatever we were doing */
656 * For ALI: has to save DSISR and DAR
658 .globl CNAME(alitrap),CNAME(aliend)
660 mtsprg1 %r1 /* save SP */
662 std %r27,(PC_TEMPSAVE+CPUSAVE_R27)(%r1) /* free r27-r31 */
663 std %r28,(PC_TEMPSAVE+CPUSAVE_R28)(%r1)
664 std %r29,(PC_TEMPSAVE+CPUSAVE_R29)(%r1)
665 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1)
666 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1)
669 std %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1)
670 std %r31,(PC_TEMPSAVE+CPUSAVE_AIM_DSISR)(%r1)
671 mfsprg1 %r1 /* restore SP, in case of branch */
672 mflr %r28 /* save LR */
673 mfcr %r29 /* save CR */
675 ld %r31,TRAP_GENTRAP(0)
676 addi %r31,%r31,(s_trap - generictrap)
679 /* Put our exception vector in SPRG3 */
683 /* Test whether we already had PR set */
686 blrl /* Branch to s_trap */
690 * Similar to the above for DSI
691 * Has to handle standard pagetable spills
693 .globl CNAME(dsitrap),CNAME(dsiend)
696 mtsprg1 %r1 /* save SP */
698 std %r27,(PC_DISISAVE+CPUSAVE_R27)(%r1) /* free r27-r31 */
699 std %r28,(PC_DISISAVE+CPUSAVE_R28)(%r1)
700 std %r29,(PC_DISISAVE+CPUSAVE_R29)(%r1)
701 std %r30,(PC_DISISAVE+CPUSAVE_R30)(%r1)
702 std %r31,(PC_DISISAVE+CPUSAVE_R31)(%r1)
703 mfcr %r29 /* save CR */
704 mfxer %r30 /* save XER */
705 mtsprg2 %r30 /* in SPRG2 */
706 mfsrr1 %r31 /* test kernel mode */
708 mflr %r28 /* save LR (SP already saved) */
709 ld %r1,TRAP_GENTRAP(0)
710 addi %r1,%r1,(disitrap-generictrap)
712 blrl /* Branch to disitrap */
716 * Preamble code for DSI/ISI traps
719 /* Write the trap vector to SPRG3 by computing LR & 0xff00 */
725 ld %r31,(PC_DISISAVE+CPUSAVE_R27)(%r1)
726 std %r31,(PC_TEMPSAVE+CPUSAVE_R27)(%r1)
727 ld %r30,(PC_DISISAVE+CPUSAVE_R28)(%r1)
728 std %r30,(PC_TEMPSAVE+CPUSAVE_R28)(%r1)
729 ld %r31,(PC_DISISAVE+CPUSAVE_R29)(%r1)
730 std %r31,(PC_TEMPSAVE+CPUSAVE_R29)(%r1)
731 ld %r30,(PC_DISISAVE+CPUSAVE_R30)(%r1)
732 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1)
733 ld %r31,(PC_DISISAVE+CPUSAVE_R31)(%r1)
734 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1)
737 std %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1)
738 std %r31,(PC_TEMPSAVE+CPUSAVE_AIM_DSISR)(%r1)
741 /* Try to detect a kernel stack overflow */
744 bt 17,realtrap /* branch is user mode */
745 mfsprg1 %r31 /* get old SP */
746 clrrdi %r31,%r31,12 /* Round SP down to nearest page */
747 sub. %r30,%r31,%r30 /* SP - DAR */
749 neg %r30,%r30 /* modulo value */
750 1: cmpldi %cr0,%r30,4096 /* is DAR within a page of SP? */
751 bge %cr0,realtrap /* no, too far away. */
753 /* Now convert this DSI into a DDB trap. */
755 ld %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1) /* get DAR */
756 std %r30,(PC_DBSAVE +CPUSAVE_AIM_DAR)(%r1) /* save DAR */
757 ld %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DSISR)(%r1) /* get DSISR */
758 std %r30,(PC_DBSAVE +CPUSAVE_AIM_DSISR)(%r1) /* save DSISR */
759 ld %r31,(PC_DISISAVE+CPUSAVE_R27)(%r1) /* get r27 */
760 std %r31,(PC_DBSAVE +CPUSAVE_R27)(%r1) /* save r27 */
761 ld %r30,(PC_DISISAVE+CPUSAVE_R28)(%r1) /* get r28 */
762 std %r30,(PC_DBSAVE +CPUSAVE_R28)(%r1) /* save r28 */
763 ld %r31,(PC_DISISAVE+CPUSAVE_R29)(%r1) /* get r29 */
764 std %r31,(PC_DBSAVE +CPUSAVE_R29)(%r1) /* save r29 */
765 ld %r30,(PC_DISISAVE+CPUSAVE_R30)(%r1) /* get r30 */
766 std %r30,(PC_DBSAVE +CPUSAVE_R30)(%r1) /* save r30 */
767 ld %r31,(PC_DISISAVE+CPUSAVE_R31)(%r1) /* get r31 */
768 std %r31,(PC_DBSAVE +CPUSAVE_R31)(%r1) /* save r31 */
772 /* XXX need stack probe here */
774 /* Test whether we already had PR set */
777 mfsprg1 %r1 /* restore SP (might have been
779 bf 17,k_trap /* branch if PSL_PR is false */
781 mr %r27,%r28 /* Save LR, r29 */
783 bl restore_kernsrs /* enable kernel mapping */
786 ld %r1,PC_CURPCB(%r1)
790 * generictrap does some standard setup for trap handling to minimize
791 * the code that need be installed in the actual vectors. It expects
792 * the following conditions.
794 * R1 - Trap vector = LR & (0xff00 | R1)
795 * SPRG1 - Original R1 contents
796 * SPRG2 - Original LR
806 .globl CNAME(generictrap)
808 /* Save R1 for computing the exception vector */
811 /* Save interesting registers */
813 std %r27,(PC_TEMPSAVE+CPUSAVE_R27)(%r1) /* free r27-r31 */
814 std %r28,(PC_TEMPSAVE+CPUSAVE_R28)(%r1)
815 std %r29,(PC_TEMPSAVE+CPUSAVE_R29)(%r1)
816 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1)
817 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1)
819 std %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1)
821 std %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DSISR)(%r1)
822 mfsprg1 %r1 /* restore SP, in case of branch */
823 mfsprg2 %r28 /* save LR */
824 mfcr %r29 /* save CR */
826 /* Compute the exception vector from the link register */
830 addi %r30,%r30,-4 /* The branch instruction, not the next */
834 /* Test whether we already had PR set */
839 bf 17,k_trap /* branch if PSL_PR is false */
842 mr %r27,%r28 /* Save LR, r29 */
844 bl restore_kernsrs /* enable kernel mapping */
847 ld %r1,PC_CURPCB(%r1)
850 * Now the common trap catching code.
853 FRAME_SETUP(PC_TEMPSAVE)
854 /* Call C interrupt dispatcher: */
858 bl CNAME(powerpc_interrupt)
861 .globl CNAME(trapexit) /* backtrace code sentinel */
863 /* Disable interrupts: */
865 andi. %r3,%r3,~PSL_EE@l
868 /* Test AST pending: */
869 ld %r5,FRAME_SRR1+48(%r1)
871 bf 17,1f /* branch if PSL_PR is false */
873 GET_CPUINFO(%r3) /* get per-CPU pointer */
874 lwz %r4, TD_FLAGS(%r13) /* get thread flags value */
875 lis %r5, (TDF_ASTPENDING|TDF_NEEDRESCHED)@h
876 ori %r5,%r5, (TDF_ASTPENDING|TDF_NEEDRESCHED)@l
879 mfmsr %r3 /* re-enable interrupts */
887 .globl CNAME(asttrapexit) /* backtrace code sentinel #2 */
889 b trapexit /* test ast ret value ? */
891 FRAME_LEAVE(PC_TEMPSAVE)
896 * Deliberate entry to dbtrap
898 ASENTRY_NOPROF(breakpoint)
902 andi. %r3,%r3,~(PSL_EE|PSL_ME)@l
903 mtmsr %r3 /* disable interrupts */
906 std %r27,(PC_DBSAVE+CPUSAVE_R27)(%r3)
907 std %r28,(PC_DBSAVE+CPUSAVE_R28)(%r3)
908 std %r29,(PC_DBSAVE+CPUSAVE_R29)(%r3)
909 std %r30,(PC_DBSAVE+CPUSAVE_R30)(%r3)
910 std %r31,(PC_DBSAVE+CPUSAVE_R31)(%r3)
918 * Now the kdb trap catching code.
921 /* Write the trap vector to SPRG3 by computing LR & 0xff00 */
926 GET_TOCBASE(%r1) /* get new SP */
927 addis %r1,%r1,TOC_REF(trapstk)@ha
928 ld %r1,TOC_REF(trapstk)@l(%r1)
929 addi %r1,%r1,(TRAPSTKSZ-48)
931 FRAME_SETUP(PC_DBSAVE)
932 /* Call C trap code: */
935 bl CNAME(db_trap_glue)
939 /* This wasn't for KDB, so switch to real trap: */
940 ld %r3,FRAME_EXC+48(%r1) /* save exception */
942 std %r3,(PC_DBSAVE+CPUSAVE_R31)(%r4)
943 FRAME_LEAVE(PC_DBSAVE)
944 mtsprg1 %r1 /* prepare for entrance to realtrap */
946 std %r27,(PC_TEMPSAVE+CPUSAVE_R27)(%r1)
947 std %r28,(PC_TEMPSAVE+CPUSAVE_R28)(%r1)
948 std %r29,(PC_TEMPSAVE+CPUSAVE_R29)(%r1)
949 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1)
950 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1)
953 ld %r31,(PC_DBSAVE+CPUSAVE_R31)(%r1)
954 mtsprg3 %r31 /* SPRG3 was clobbered by FRAME_LEAVE */
958 FRAME_LEAVE(PC_DBSAVE)
963 * In case of KDB we want a separate trap catcher for it
965 .globl CNAME(dblow),CNAME(dbend)
968 mtsprg1 %r1 /* save SP */
969 mtsprg2 %r29 /* save r29 */
970 mfcr %r29 /* save CR in r29 */
973 bf 17,1f /* branch if privileged */
975 /* Unprivileged case */
976 mtcr %r29 /* put the condition register back */
977 mfsprg2 %r29 /* ... and r29 */
978 mflr %r1 /* save LR */
979 mtsprg2 %r1 /* And then in SPRG2 */
981 ld %r1, TRAP_ENTRY(0) /* Get branch address */
983 li %r1, 0 /* How to get the vector from LR */
984 blrl /* Branch to generictrap */
988 std %r27,(PC_DBSAVE+CPUSAVE_R27)(%r1) /* free r27 */
989 std %r28,(PC_DBSAVE+CPUSAVE_R28)(%r1) /* free r28 */
990 mfsprg2 %r28 /* r29 holds cr... */
991 std %r28,(PC_DBSAVE+CPUSAVE_R29)(%r1) /* free r29 */
992 std %r30,(PC_DBSAVE+CPUSAVE_R30)(%r1) /* free r30 */
993 std %r31,(PC_DBSAVE+CPUSAVE_R31)(%r1) /* free r31 */
994 mflr %r28 /* save LR */
995 ld %r1,TRAP_GENTRAP(0)
996 addi %r1,%r1,(dbtrap-generictrap)
998 blrl /* Branch to dbtrap */