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>
43 * Save/restore segment registers
47 * Restore SRs for a pmap
49 * Requires that r28-r31 be scratch, with r28 initialized to the SLB cache
53 * User SRs are loaded through a pointer to the current pmap.
57 ld %r28,PC_USERSLB(%r28)
58 li %r29, 0 /* Set the counter to zero */
64 1: ld %r31, 0(%r28) /* Load SLB entry pointer */
65 cmpli 0, %r31, 0 /* If NULL, stop */
68 ld %r30, 0(%r31) /* Load SLBV */
69 ld %r31, 8(%r31) /* Load SLBE */
70 or %r31, %r31, %r29 /* Set SLBE slot */
71 slbmte %r30, %r31 /* Install SLB entry */
73 addi %r28, %r28, 8 /* Advance pointer */
78 * Kernel SRs are loaded directly from the PCPU fields
82 addi %r28,%r28,PC_KERNSLB
83 li %r29, 0 /* Set the counter to zero */
89 1: cmpli 0, %r29, USER_SLB_SLOT /* Skip the user slot */
92 ld %r31, 8(%r28) /* Load SLBE */
93 cmpli 0, %r31, 0 /* If SLBE is not valid, stop */
95 ld %r30, 0(%r28) /* Load SLBV */
96 slbmte %r30, %r31 /* Install SLB entry */
98 2: addi %r28, %r28, 16 /* Advance pointer */
100 cmpli 0, %r29, 64 /* Repeat if we are not at the end */
105 * FRAME_SETUP assumes:
108 * savearea r27-r31,DAR,DSISR (DAR & DSISR only for DSI traps)
114 * SRR0/1 as at start of trap
116 * NOTE: SPRG1 is never used while the MMU is on, making it safe to reuse
117 * in any real-mode fault handler, including those handling double faults.
119 #define FRAME_SETUP(savearea) \
120 /* Have to enable translation to allow access of kernel stack: */ \
123 std %r30,(savearea+CPUSAVE_SRR0)(%r31); /* save SRR0 */ \
125 std %r30,(savearea+CPUSAVE_SRR1)(%r31); /* save SRR1 */ \
126 mfsprg1 %r31; /* get saved SP (clears SPRG1) */ \
128 ori %r30,%r30,(PSL_DR|PSL_IR|PSL_RI)@l; /* relocation on */ \
129 mtmsr %r30; /* stack can now be accessed */ \
131 stdu %r31,-(FRAMELEN+288)(%r1); /* save it in the callframe */ \
132 std %r0, FRAME_0+48(%r1); /* save r0 in the trapframe */ \
133 std %r31,FRAME_1+48(%r1); /* save SP " " */ \
134 std %r2, FRAME_2+48(%r1); /* save r2 " " */ \
135 std %r28,FRAME_LR+48(%r1); /* save LR " " */ \
136 std %r29,FRAME_CR+48(%r1); /* save CR " " */ \
138 ld %r27,(savearea+CPUSAVE_R27)(%r2); /* get saved r27 */ \
139 ld %r28,(savearea+CPUSAVE_R28)(%r2); /* get saved r28 */ \
140 ld %r29,(savearea+CPUSAVE_R29)(%r2); /* get saved r29 */ \
141 ld %r30,(savearea+CPUSAVE_R30)(%r2); /* get saved r30 */ \
142 ld %r31,(savearea+CPUSAVE_R31)(%r2); /* get saved r31 */ \
143 std %r3, FRAME_3+48(%r1); /* save r3-r31 */ \
144 std %r4, FRAME_4+48(%r1); \
145 std %r5, FRAME_5+48(%r1); \
146 std %r6, FRAME_6+48(%r1); \
147 std %r7, FRAME_7+48(%r1); \
148 std %r8, FRAME_8+48(%r1); \
149 std %r9, FRAME_9+48(%r1); \
150 std %r10, FRAME_10+48(%r1); \
151 std %r11, FRAME_11+48(%r1); \
152 std %r12, FRAME_12+48(%r1); \
153 std %r13, FRAME_13+48(%r1); \
154 std %r14, FRAME_14+48(%r1); \
155 std %r15, FRAME_15+48(%r1); \
156 std %r16, FRAME_16+48(%r1); \
157 std %r17, FRAME_17+48(%r1); \
158 std %r18, FRAME_18+48(%r1); \
159 std %r19, FRAME_19+48(%r1); \
160 std %r20, FRAME_20+48(%r1); \
161 std %r21, FRAME_21+48(%r1); \
162 std %r22, FRAME_22+48(%r1); \
163 std %r23, FRAME_23+48(%r1); \
164 std %r24, FRAME_24+48(%r1); \
165 std %r25, FRAME_25+48(%r1); \
166 std %r26, FRAME_26+48(%r1); \
167 std %r27, FRAME_27+48(%r1); \
168 std %r28, FRAME_28+48(%r1); \
169 std %r29, FRAME_29+48(%r1); \
170 std %r30, FRAME_30+48(%r1); \
171 std %r31, FRAME_31+48(%r1); \
172 ld %r28,(savearea+CPUSAVE_AIM_DAR)(%r2); /* saved DAR */ \
173 ld %r29,(savearea+CPUSAVE_AIM_DSISR)(%r2);/* saved DSISR */\
174 ld %r30,(savearea+CPUSAVE_SRR0)(%r2); /* saved SRR0 */ \
175 ld %r31,(savearea+CPUSAVE_SRR1)(%r2); /* saved SRR1 */ \
179 std %r3, FRAME_XER+48(1); /* save xer/ctr/exc */ \
180 std %r4, FRAME_CTR+48(1); \
181 std %r5, FRAME_EXC+48(1); \
182 std %r28,FRAME_AIM_DAR+48(1); \
183 std %r29,FRAME_AIM_DSISR+48(1); /* save dsisr/srr0/srr1 */ \
184 std %r30,FRAME_SRR0+48(1); \
185 std %r31,FRAME_SRR1+48(1); \
186 ld %r13,PC_CURTHREAD(%r2) /* set kernel curthread */
188 #define FRAME_LEAVE(savearea) \
189 /* Disable exceptions: */ \
191 andi. %r2,%r2,~PSL_EE@l; \
194 /* Now restore regs: */ \
195 ld %r2,FRAME_SRR0+48(%r1); \
196 ld %r3,FRAME_SRR1+48(%r1); \
197 ld %r4,FRAME_CTR+48(%r1); \
198 ld %r5,FRAME_XER+48(%r1); \
199 ld %r6,FRAME_LR+48(%r1); \
201 std %r2,(savearea+CPUSAVE_SRR0)(%r7); /* save SRR0 */ \
202 std %r3,(savearea+CPUSAVE_SRR1)(%r7); /* save SRR1 */ \
203 ld %r7,FRAME_CR+48(%r1); \
207 mtsprg2 %r7; /* save cr */ \
208 ld %r31,FRAME_31+48(%r1); /* restore r0-31 */ \
209 ld %r30,FRAME_30+48(%r1); \
210 ld %r29,FRAME_29+48(%r1); \
211 ld %r28,FRAME_28+48(%r1); \
212 ld %r27,FRAME_27+48(%r1); \
213 ld %r26,FRAME_26+48(%r1); \
214 ld %r25,FRAME_25+48(%r1); \
215 ld %r24,FRAME_24+48(%r1); \
216 ld %r23,FRAME_23+48(%r1); \
217 ld %r22,FRAME_22+48(%r1); \
218 ld %r21,FRAME_21+48(%r1); \
219 ld %r20,FRAME_20+48(%r1); \
220 ld %r19,FRAME_19+48(%r1); \
221 ld %r18,FRAME_18+48(%r1); \
222 ld %r17,FRAME_17+48(%r1); \
223 ld %r16,FRAME_16+48(%r1); \
224 ld %r15,FRAME_15+48(%r1); \
225 ld %r14,FRAME_14+48(%r1); \
226 ld %r13,FRAME_13+48(%r1); \
227 ld %r12,FRAME_12+48(%r1); \
228 ld %r11,FRAME_11+48(%r1); \
229 ld %r10,FRAME_10+48(%r1); \
230 ld %r9, FRAME_9+48(%r1); \
231 ld %r8, FRAME_8+48(%r1); \
232 ld %r7, FRAME_7+48(%r1); \
233 ld %r6, FRAME_6+48(%r1); \
234 ld %r5, FRAME_5+48(%r1); \
235 ld %r4, FRAME_4+48(%r1); \
236 ld %r3, FRAME_3+48(%r1); \
237 ld %r2, FRAME_2+48(%r1); \
238 ld %r0, FRAME_0+48(%r1); \
239 ld %r1, FRAME_1+48(%r1); \
240 /* Can't touch %r1 from here on */ \
241 mtsprg3 %r3; /* save r3 */ \
242 /* Disable translation, machine check and recoverability: */ \
244 andi. %r3,%r3,~(PSL_DR|PSL_IR|PSL_ME|PSL_RI)@l; \
247 /* Decide whether we return to user mode: */ \
249 ld %r3,(savearea+CPUSAVE_SRR1)(%r3); \
251 bf 17,1f; /* branch if PSL_PR is false */ \
252 /* Restore user SRs */ \
254 std %r27,(savearea+CPUSAVE_R27)(%r3); \
255 std %r28,(savearea+CPUSAVE_R28)(%r3); \
256 std %r29,(savearea+CPUSAVE_R29)(%r3); \
257 std %r30,(savearea+CPUSAVE_R30)(%r3); \
258 std %r31,(savearea+CPUSAVE_R31)(%r3); \
259 mflr %r27; /* preserve LR */ \
260 bl restore_usersrs; /* uses r28-r31 */ \
262 ld %r31,(savearea+CPUSAVE_R31)(%r3); \
263 ld %r30,(savearea+CPUSAVE_R30)(%r3); \
264 ld %r29,(savearea+CPUSAVE_R29)(%r3); \
265 ld %r28,(savearea+CPUSAVE_R28)(%r3); \
266 ld %r27,(savearea+CPUSAVE_R27)(%r3); \
267 1: mfsprg2 %r3; /* restore cr */ \
270 ld %r3,(savearea+CPUSAVE_SRR0)(%r3); /* restore srr0 */ \
273 ld %r3,(savearea+CPUSAVE_SRR1)(%r3); /* restore srr1 */ \
275 mfsprg3 %r3 /* restore r3 */
279 .globl dtrace_invop_jump_addr
281 .type dtrace_invop_jump_addr, @object
282 .size dtrace_invop_jump_addr, 8
283 dtrace_invop_jump_addr:
286 .globl dtrace_invop_calltrap_addr
288 .type dtrace_invop_calltrap_addr, @object
289 .size dtrace_invop_calltrap_addr, 8
290 dtrace_invop_calltrap_addr:
299 * Processor reset exception handler. These are typically
300 * the first instructions the processor executes after a
301 * software reset. We do this in two bits so that we are
302 * not still hanging around in the trap handling region
303 * once the MMU is turned on.
305 .globl CNAME(rstcode), CNAME(rstsize)
307 /* Explicitly set MSR[SF] */
315 CNAME(rstsize) = . - CNAME(rstcode)
318 lis %r1,(tmpstk+TMPSTKSZ-48)@ha /* get new SP */
319 addi %r1,%r1,(tmpstk+TMPSTKSZ-48)@l
322 ld %r2,tocbase@l(%r3)
324 bl CNAME(cpudep_ap_early_bootstrap) /* Set PCPU */
327 bl CNAME(pmap_cpu_bootstrap) /* Turn on virtual memory */
329 bl CNAME(cpudep_ap_bootstrap) /* Set up PCPU and stack */
331 mr %r1,%r3 /* Use new stack */
332 bl CNAME(machdep_ap_bootstrap) /* And away! */
335 /* Should not be reached */
341 * This code gets copied to all the trap vectors
342 * (except ISI/DSI, ALI, and the interrupts)
345 .globl CNAME(trapcode),CNAME(trapsize)
347 mtsprg1 %r1 /* save SP */
348 mflr %r1 /* Save the old LR in r1 */
349 mtsprg2 %r1 /* And then in SPRG2 */
350 li %r1, 0xA0 /* How to get the vector from LR */
351 bla generictrap /* LR & SPRG3 is exception # */
352 CNAME(trapsize) = .-CNAME(trapcode)
355 * For SLB misses: do special things for the kernel
357 * Note: SPRG1 is always safe to overwrite any time the MMU is on, which is
358 * the only time this can be called.
360 .globl CNAME(slbtrap),CNAME(slbtrapsize)
362 mtsprg1 %r1 /* save SP */
364 std %r2,(PC_SLBSAVE+16)(%r1)
365 mfcr %r2 /* save CR */
366 std %r2,(PC_SLBSAVE+104)(%r1)
367 mfsrr1 %r2 /* test kernel mode */
369 bf 17,1f /* branch if PSL_PR is false */
371 ld %r2,(PC_SLBSAVE+104)(%r1) /* Restore CR */
373 ld %r2,(PC_SLBSAVE+16)(%r1) /* Restore R2 */
374 mflr %r1 /* Save the old LR in r1 */
375 mtsprg2 %r1 /* And then in SPRG2 */
376 li %r1, 0x80 /* How to get the vector from LR */
377 bla generictrap /* LR & SPRG3 is exception # */
378 1: mflr %r2 /* Save the old LR in r2 */
380 CNAME(slbtrapsize) = .-CNAME(slbtrap)
383 std %r2,(PC_SLBSAVE+136)(%r1) /* old LR */
384 std %r3,(PC_SLBSAVE+24)(%r1) /* save R3 */
386 /* Check if this needs to be handled as a regular trap (userseg miss) */
394 2: /* r2 now contains the fault address */
395 lis %r3,SEGMENT_MASK@highesta
396 ori %r3,%r3,SEGMENT_MASK@highera
398 oris %r3,%r3,SEGMENT_MASK@ha
399 ori %r3,%r3,SEGMENT_MASK@l
400 and %r2,%r2,%r3 /* R2 = segment base address */
401 lis %r3,USER_ADDR@highesta
402 ori %r3,%r3,USER_ADDR@highera
404 oris %r3,%r3,USER_ADDR@ha
405 ori %r3,%r3,USER_ADDR@l
406 cmpd %r2,%r3 /* Compare fault base to USER_ADDR */
409 /* User seg miss, handle as a regular trap */
410 ld %r2,(PC_SLBSAVE+104)(%r1) /* Restore CR */
412 ld %r2,(PC_SLBSAVE+16)(%r1) /* Restore R2,R3 */
413 ld %r3,(PC_SLBSAVE+24)(%r1)
414 ld %r1,(PC_SLBSAVE+136)(%r1) /* Save the old LR in r1 */
415 mtsprg2 %r1 /* And then in SPRG2 */
416 li %r1, 0x80 /* How to get the vector from LR */
417 b generictrap /* Retain old LR using b */
419 3: /* Real kernel SLB miss */
420 std %r0,(PC_SLBSAVE+0)(%r1) /* free all volatile regs */
421 mfsprg1 %r2 /* Old R1 */
422 std %r2,(PC_SLBSAVE+8)(%r1)
423 /* R2,R3 already saved */
424 std %r4,(PC_SLBSAVE+32)(%r1)
425 std %r5,(PC_SLBSAVE+40)(%r1)
426 std %r6,(PC_SLBSAVE+48)(%r1)
427 std %r7,(PC_SLBSAVE+56)(%r1)
428 std %r8,(PC_SLBSAVE+64)(%r1)
429 std %r9,(PC_SLBSAVE+72)(%r1)
430 std %r10,(PC_SLBSAVE+80)(%r1)
431 std %r11,(PC_SLBSAVE+88)(%r1)
432 std %r12,(PC_SLBSAVE+96)(%r1)
433 /* CR already saved */
434 mfxer %r2 /* save XER */
435 std %r2,(PC_SLBSAVE+112)(%r1)
436 mflr %r2 /* save LR (SP already saved) */
437 std %r2,(PC_SLBSAVE+120)(%r1)
438 mfctr %r2 /* save CTR */
439 std %r2,(PC_SLBSAVE+128)(%r1)
442 addi %r1,%r1,PC_SLBSTACK-48+1024
446 ld %r2,tocbase@l(%r3)
451 bl handle_kernel_slb_spill
454 /* Save r28-31, restore r4-r12 */
456 ld %r4,(PC_SLBSAVE+32)(%r1)
457 ld %r5,(PC_SLBSAVE+40)(%r1)
458 ld %r6,(PC_SLBSAVE+48)(%r1)
459 ld %r7,(PC_SLBSAVE+56)(%r1)
460 ld %r8,(PC_SLBSAVE+64)(%r1)
461 ld %r9,(PC_SLBSAVE+72)(%r1)
462 ld %r10,(PC_SLBSAVE+80)(%r1)
463 ld %r11,(PC_SLBSAVE+88)(%r1)
464 ld %r12,(PC_SLBSAVE+96)(%r1)
465 std %r28,(PC_SLBSAVE+64)(%r1)
466 std %r29,(PC_SLBSAVE+72)(%r1)
467 std %r30,(PC_SLBSAVE+80)(%r1)
468 std %r31,(PC_SLBSAVE+88)(%r1)
470 /* Restore kernel mapping */
473 /* Restore remaining registers */
474 ld %r28,(PC_SLBSAVE+64)(%r1)
475 ld %r29,(PC_SLBSAVE+72)(%r1)
476 ld %r30,(PC_SLBSAVE+80)(%r1)
477 ld %r31,(PC_SLBSAVE+88)(%r1)
479 ld %r2,(PC_SLBSAVE+104)(%r1)
481 ld %r2,(PC_SLBSAVE+112)(%r1)
483 ld %r2,(PC_SLBSAVE+120)(%r1)
485 ld %r2,(PC_SLBSAVE+128)(%r1)
487 ld %r2,(PC_SLBSAVE+136)(%r1)
491 ld %r0,(PC_SLBSAVE+0)(%r1)
492 ld %r2,(PC_SLBSAVE+16)(%r1)
493 ld %r3,(PC_SLBSAVE+24)(%r1)
496 /* Back to whatever we were doing */
500 * For ALI: has to save DSISR and DAR
502 .globl CNAME(alitrap),CNAME(alisize)
504 mtsprg1 %r1 /* save SP */
506 std %r27,(PC_TEMPSAVE+CPUSAVE_R27)(%r1) /* free r27-r31 */
507 std %r28,(PC_TEMPSAVE+CPUSAVE_R28)(%r1)
508 std %r29,(PC_TEMPSAVE+CPUSAVE_R29)(%r1)
509 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1)
510 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1)
513 std %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1)
514 std %r31,(PC_TEMPSAVE+CPUSAVE_AIM_DSISR)(%r1)
515 mfsprg1 %r1 /* restore SP, in case of branch */
516 mflr %r28 /* save LR */
517 mfcr %r29 /* save CR */
519 /* Put our exception vector in SPRG3 */
523 /* Test whether we already had PR set */
527 CNAME(alisize) = .-CNAME(alitrap)
530 * Similar to the above for DSI
531 * Has to handle BAT spills
532 * and standard pagetable spills
534 .globl CNAME(dsitrap),CNAME(dsisize)
536 mtsprg1 %r1 /* save SP */
538 std %r27,(PC_DISISAVE+CPUSAVE_R27)(%r1) /* free r27-r31 */
539 std %r28,(PC_DISISAVE+CPUSAVE_R28)(%r1)
540 std %r29,(PC_DISISAVE+CPUSAVE_R29)(%r1)
541 std %r30,(PC_DISISAVE+CPUSAVE_R30)(%r1)
542 std %r31,(PC_DISISAVE+CPUSAVE_R31)(%r1)
543 mfsprg1 %r1 /* restore SP */
544 mfcr %r29 /* save CR */
545 mfxer %r30 /* save XER */
546 mtsprg2 %r30 /* in SPRG2 */
547 mfsrr1 %r31 /* test kernel mode */
549 mflr %r28 /* save LR (SP already saved) */
551 CNAME(dsisize) = .-CNAME(dsitrap)
554 * Preamble code for DSI/ISI traps
557 /* Write the trap vector to SPRG3 by computing LR & 0xff00 */
563 ld %r31,(PC_DISISAVE+CPUSAVE_R27)(%r1)
564 std %r31,(PC_TEMPSAVE+CPUSAVE_R27)(%r1)
565 ld %r30,(PC_DISISAVE+CPUSAVE_R28)(%r1)
566 std %r30,(PC_TEMPSAVE+CPUSAVE_R28)(%r1)
567 ld %r31,(PC_DISISAVE+CPUSAVE_R29)(%r1)
568 std %r31,(PC_TEMPSAVE+CPUSAVE_R29)(%r1)
569 ld %r30,(PC_DISISAVE+CPUSAVE_R30)(%r1)
570 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1)
571 ld %r31,(PC_DISISAVE+CPUSAVE_R31)(%r1)
572 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1)
575 std %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1)
576 std %r31,(PC_TEMPSAVE+CPUSAVE_AIM_DSISR)(%r1)
579 /* Try and detect a kernel stack overflow */
582 bt 17,realtrap /* branch is user mode */
583 mfsprg1 %r31 /* get old SP */
584 sub. %r30,%r31,%r30 /* SP - DAR */
586 neg %r30,%r30 /* modulo value */
587 1: cmpldi %cr0,%r30,4096 /* is DAR within a page of SP? */
588 bge %cr0,realtrap /* no, too far away. */
590 /* Now convert this DSI into a DDB trap. */
592 ld %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1) /* get DAR */
593 std %r30,(PC_DBSAVE +CPUSAVE_AIM_DAR)(%r1) /* save DAR */
594 ld %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DSISR)(%r1) /* get DSISR */
595 std %r30,(PC_DBSAVE +CPUSAVE_AIM_DSISR)(%r1) /* save DSISR */
596 ld %r31,(PC_DISISAVE+CPUSAVE_R27)(%r1) /* get r27 */
597 std %r31,(PC_DBSAVE +CPUSAVE_R27)(%r1) /* save r27 */
598 ld %r30,(PC_DISISAVE+CPUSAVE_R28)(%r1) /* get r28 */
599 std %r30,(PC_DBSAVE +CPUSAVE_R28)(%r1) /* save r28 */
600 ld %r31,(PC_DISISAVE+CPUSAVE_R29)(%r1) /* get r29 */
601 std %r31,(PC_DBSAVE +CPUSAVE_R29)(%r1) /* save r29 */
602 ld %r30,(PC_DISISAVE+CPUSAVE_R30)(%r1) /* get r30 */
603 std %r30,(PC_DBSAVE +CPUSAVE_R30)(%r1) /* save r30 */
604 ld %r31,(PC_DISISAVE+CPUSAVE_R31)(%r1) /* get r31 */
605 std %r31,(PC_DBSAVE +CPUSAVE_R31)(%r1) /* save r31 */
609 /* XXX need stack probe here */
611 /* Test whether we already had PR set */
614 mfsprg1 %r1 /* restore SP (might have been
616 bf 17,k_trap /* branch if PSL_PR is false */
618 ld %r1,PC_CURPCB(%r1)
619 mr %r27,%r28 /* Save LR, r29 */
621 bl restore_kernsrs /* enable kernel mapping */
627 * generictrap does some standard setup for trap handling to minimize
628 * the code that need be installed in the actual vectors. It expects
629 * the following conditions.
631 * R1 - Trap vector = LR & (0xff00 | R1)
632 * SPRG1 - Original R1 contents
633 * SPRG2 - Original LR
637 /* Save R1 for computing the exception vector */
640 /* Save interesting registers */
642 std %r27,(PC_TEMPSAVE+CPUSAVE_R27)(%r1) /* free r27-r31 */
643 std %r28,(PC_TEMPSAVE+CPUSAVE_R28)(%r1)
644 std %r29,(PC_TEMPSAVE+CPUSAVE_R29)(%r1)
645 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1)
646 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1)
648 std %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1)
649 mfsprg1 %r1 /* restore SP, in case of branch */
650 mfsprg2 %r28 /* save LR */
651 mfcr %r29 /* save CR */
653 /* Compute the exception vector from the link register */
660 /* Test whether we already had PR set */
665 bf 17,k_trap /* branch if PSL_PR is false */
668 ld %r1,PC_CURPCB(%r1)
669 mr %r27,%r28 /* Save LR, r29 */
671 bl restore_kernsrs /* enable kernel mapping */
676 * Now the common trap catching code.
679 FRAME_SETUP(PC_TEMPSAVE)
680 /* Call C interrupt dispatcher: */
683 ld %r2,tocbase@l(%r3)
685 bl CNAME(powerpc_interrupt)
688 .globl CNAME(trapexit) /* backtrace code sentinel */
690 /* Disable interrupts: */
692 andi. %r3,%r3,~PSL_EE@l
695 /* Test AST pending: */
696 ld %r5,FRAME_SRR1+48(%r1)
698 bf 17,1f /* branch if PSL_PR is false */
700 GET_CPUINFO(%r3) /* get per-CPU pointer */
701 lwz %r4, TD_FLAGS(%r13) /* get thread flags value */
702 lis %r5, (TDF_ASTPENDING|TDF_NEEDRESCHED)@h
703 ori %r5,%r5, (TDF_ASTPENDING|TDF_NEEDRESCHED)@l
706 mfmsr %r3 /* re-enable interrupts */
711 ld %r2,tocbase@l(%r3)
715 .globl CNAME(asttrapexit) /* backtrace code sentinel #2 */
717 b trapexit /* test ast ret value ? */
719 FRAME_LEAVE(PC_TEMPSAVE)
724 * Deliberate entry to dbtrap
726 ASENTRY_NOPROF(breakpoint)
730 andi. %r3,%r3,~(PSL_EE|PSL_ME)@l
731 mtmsr %r3 /* disable interrupts */
734 std %r27,(PC_DBSAVE+CPUSAVE_R27)(%r3)
735 std %r28,(PC_DBSAVE+CPUSAVE_R28)(%r3)
736 std %r29,(PC_DBSAVE+CPUSAVE_R29)(%r3)
737 std %r30,(PC_DBSAVE+CPUSAVE_R30)(%r3)
738 std %r31,(PC_DBSAVE+CPUSAVE_R31)(%r3)
746 * Now the kdb trap catching code.
749 /* Write the trap vector to SPRG3 by computing LR & 0xff00 */
754 lis %r1,(tmpstk+TMPSTKSZ-48)@ha /* get new SP */
755 addi %r1,%r1,(tmpstk+TMPSTKSZ-48)@l
757 FRAME_SETUP(PC_DBSAVE)
758 /* Call C trap code: */
760 ld %r2,tocbase@l(%r3)
762 bl CNAME(db_trap_glue)
766 /* This wasn't for KDB, so switch to real trap: */
767 ld %r3,FRAME_EXC+48(%r1) /* save exception */
769 std %r3,(PC_DBSAVE+CPUSAVE_R31)(%r4)
770 FRAME_LEAVE(PC_DBSAVE)
771 mtsprg1 %r1 /* prepare for entrance to realtrap */
773 std %r27,(PC_TEMPSAVE+CPUSAVE_R27)(%r1)
774 std %r28,(PC_TEMPSAVE+CPUSAVE_R28)(%r1)
775 std %r29,(PC_TEMPSAVE+CPUSAVE_R29)(%r1)
776 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1)
777 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1)
780 ld %r31,(PC_DBSAVE+CPUSAVE_R31)(%r1)
781 mtsprg3 %r31 /* SPRG3 was clobbered by FRAME_LEAVE */
785 FRAME_LEAVE(PC_DBSAVE)
789 * In case of KDB we want a separate trap catcher for it
791 .globl CNAME(dblow),CNAME(dbsize)
793 mtsprg1 %r1 /* save SP */
794 mtsprg2 %r29 /* save r29 */
795 mfcr %r29 /* save CR in r29 */
798 bf 17,1f /* branch if privileged */
800 /* Unprivileged case */
801 mtcr %r29 /* put the condition register back */
802 mfsprg2 %r29 /* ... and r29 */
803 mflr %r1 /* save LR */
804 mtsprg2 %r1 /* And then in SPRG2 */
805 li %r1, 0 /* How to get the vector from LR */
807 bla generictrap /* and we look like a generic trap */
809 /* Privileged, so drop to KDB */
811 std %r27,(PC_DBSAVE+CPUSAVE_R27)(%r1) /* free r27 */
812 std %r28,(PC_DBSAVE+CPUSAVE_R28)(%r1) /* free r28 */
813 mfsprg2 %r28 /* r29 holds cr... */
814 std %r28,(PC_DBSAVE+CPUSAVE_R29)(%r1) /* free r29 */
815 std %r30,(PC_DBSAVE+CPUSAVE_R30)(%r1) /* free r30 */
816 std %r31,(PC_DBSAVE+CPUSAVE_R31)(%r1) /* free r31 */
817 mflr %r28 /* save LR */
819 CNAME(dbsize) = .-CNAME(dblow)