1/* $FreeBSD$ */ 2/* $NetBSD: trap_subr.S,v 1.20 2002/04/22 23:20:08 kleink Exp $ */ 3 4/*- 5 * Copyright (C) 1995, 1996 Wolfgang Solfrank. 6 * Copyright (C) 1995, 1996 TooLs GmbH. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 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. 22 * 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. 33 */ 34 35/* 36 * NOTICE: This is not a standalone file. to use it, #include it in 37 * your port's locore.S, like so: 38 * 39 * #include <powerpc/aim/trap_subr.S> 40 */ 41 42/* 43 * Save/restore segment registers 44 */ 45 46/* 47 * Restore SRs for a pmap 48 * 49 * Requires that r28-r31 be scratch, with r28 initialized to the SLB cache 50 */ 51 52/* 53 * User SRs are loaded through a pointer to the current pmap. 54 */ 55restore_usersrs: 56 GET_CPUINFO(%r28) 57 ld %r28,PC_USERSLB(%r28) 58 li %r29, 0 /* Set the counter to zero */ 59 60 slbia 61 slbmfee %r31,%r29 62 clrrdi %r31,%r31,28 63 slbie %r31 641: ld %r31, 0(%r28) /* Load SLB entry pointer */ 65 cmpli 0, %r31, 0 /* If NULL, stop */ 66 beqlr 67 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 */ 72 73 addi %r28, %r28, 8 /* Advance pointer */ 74 addi %r29, %r29, 1 75 b 1b /* Repeat */ 76 77/* 78 * Kernel SRs are loaded directly from the PCPU fields 79 */ 80restore_kernsrs: 81 GET_CPUINFO(%r28) 82 addi %r28,%r28,PC_KERNSLB 83 li %r29, 0 /* Set the counter to zero */ 84 85 slbia 86 slbmfee %r31,%r29 87 clrrdi %r31,%r31,28 88 slbie %r31 891: cmpli 0, %r29, USER_SLB_SLOT /* Skip the user slot */ 90 beq- 2f 91 92 ld %r31, 8(%r28) /* Load SLBE */ 93 cmpli 0, %r31, 0 /* If SLBE is not valid, stop */ 94 beqlr 95 ld %r30, 0(%r28) /* Load SLBV */ 96 slbmte %r30, %r31 /* Install SLB entry */ 97 982: addi %r28, %r28, 16 /* Advance pointer */ 99 addi %r29, %r29, 1 100 cmpli 0, %r29, 64 /* Repeat if we are not at the end */ 101 blt 1b 102 blr 103 104/* 105 * FRAME_SETUP assumes: 106 * SPRG1 SP (1) 107 * SPRG3 trap type 108 * savearea r27-r31,DAR,DSISR (DAR & DSISR only for DSI traps) 109 * r28 LR 110 * r29 CR 111 * r30 scratch 112 * r31 scratch 113 * r1 kernel stack 114 * SRR0/1 as at start of trap 115 */ 116#define FRAME_SETUP(savearea) \ 117/* Have to enable translation to allow access of kernel stack: */ \ 118 GET_CPUINFO(%r31); \ 119 mfsrr0 %r30; \ 120 std %r30,(savearea+CPUSAVE_SRR0)(%r31); /* save SRR0 */ \ 121 mfsrr1 %r30; \ 122 std %r30,(savearea+CPUSAVE_SRR1)(%r31); /* save SRR1 */ \ 123 mfmsr %r30; \ 124 ori %r30,%r30,(PSL_DR|PSL_IR|PSL_RI)@l; /* relocation on */ \ 125 mtmsr %r30; /* stack can now be accessed */ \ 126 isync; \ 127 mfsprg1 %r31; /* get saved SP */ \ 128 stdu %r31,-(FRAMELEN+288)(%r1); /* save it in the callframe */ \ 129 std %r0, FRAME_0+48(%r1); /* save r0 in the trapframe */ \ 130 std %r31,FRAME_1+48(%r1); /* save SP " " */ \ 131 std %r2, FRAME_2+48(%r1); /* save r2 " " */ \ 132 std %r28,FRAME_LR+48(%r1); /* save LR " " */ \ 133 std %r29,FRAME_CR+48(%r1); /* save CR " " */ \ 134 GET_CPUINFO(%r2); \ 135 ld %r27,(savearea+CPUSAVE_R27)(%r2); /* get saved r27 */ \ 136 ld %r28,(savearea+CPUSAVE_R28)(%r2); /* get saved r28 */ \ 137 ld %r29,(savearea+CPUSAVE_R29)(%r2); /* get saved r29 */ \ 138 ld %r30,(savearea+CPUSAVE_R30)(%r2); /* get saved r30 */ \ 139 ld %r31,(savearea+CPUSAVE_R31)(%r2); /* get saved r31 */ \ 140 std %r3, FRAME_3+48(%r1); /* save r3-r31 */ \ 141 std %r4, FRAME_4+48(%r1); \ 142 std %r5, FRAME_5+48(%r1); \ 143 std %r6, FRAME_6+48(%r1); \ 144 std %r7, FRAME_7+48(%r1); \ 145 std %r8, FRAME_8+48(%r1); \ 146 std %r9, FRAME_9+48(%r1); \ 147 std %r10, FRAME_10+48(%r1); \ 148 std %r11, FRAME_11+48(%r1); \ 149 std %r12, FRAME_12+48(%r1); \ 150 std %r13, FRAME_13+48(%r1); \ 151 std %r14, FRAME_14+48(%r1); \ 152 std %r15, FRAME_15+48(%r1); \ 153 std %r16, FRAME_16+48(%r1); \ 154 std %r17, FRAME_17+48(%r1); \ 155 std %r18, FRAME_18+48(%r1); \ 156 std %r19, FRAME_19+48(%r1); \ 157 std %r20, FRAME_20+48(%r1); \ 158 std %r21, FRAME_21+48(%r1); \ 159 std %r22, FRAME_22+48(%r1); \ 160 std %r23, FRAME_23+48(%r1); \ 161 std %r24, FRAME_24+48(%r1); \ 162 std %r25, FRAME_25+48(%r1); \ 163 std %r26, FRAME_26+48(%r1); \ 164 std %r27, FRAME_27+48(%r1); \ 165 std %r28, FRAME_28+48(%r1); \ 166 std %r29, FRAME_29+48(%r1); \ 167 std %r30, FRAME_30+48(%r1); \ 168 std %r31, FRAME_31+48(%r1); \ 169 ld %r28,(savearea+CPUSAVE_AIM_DAR)(%r2); /* saved DAR */ \ 170 ld %r29,(savearea+CPUSAVE_AIM_DSISR)(%r2);/* saved DSISR */\ 171 ld %r30,(savearea+CPUSAVE_SRR0)(%r2); /* saved SRR0 */ \ 172 ld %r31,(savearea+CPUSAVE_SRR1)(%r2); /* saved SRR1 */ \ 173 mfxer %r3; \ 174 mfctr %r4; \ 175 mfsprg3 %r5; \ 176 std %r3, FRAME_XER+48(1); /* save xer/ctr/exc */ \ 177 std %r4, FRAME_CTR+48(1); \ 178 std %r5, FRAME_EXC+48(1); \ 179 std %r28,FRAME_AIM_DAR+48(1); \ 180 std %r29,FRAME_AIM_DSISR+48(1); /* save dsisr/srr0/srr1 */ \ 181 std %r30,FRAME_SRR0+48(1); \ 182 std %r31,FRAME_SRR1+48(1); \ 183 ld %r13,PC_CURTHREAD(%r2) /* set kernel curthread */ 184 185#define FRAME_LEAVE(savearea) \ 186/* Disable exceptions: */ \ 187 mfmsr %r2; \ 188 andi. %r2,%r2,~PSL_EE@l; \ 189 mtmsr %r2; \ 190 isync; \ 191/* Now restore regs: */ \ 192 ld %r2,FRAME_SRR0+48(%r1); \ 193 ld %r3,FRAME_SRR1+48(%r1); \ 194 ld %r4,FRAME_CTR+48(%r1); \ 195 ld %r5,FRAME_XER+48(%r1); \ 196 ld %r6,FRAME_LR+48(%r1); \ 197 GET_CPUINFO(%r7); \ 198 std %r2,(savearea+CPUSAVE_SRR0)(%r7); /* save SRR0 */ \ 199 std %r3,(savearea+CPUSAVE_SRR1)(%r7); /* save SRR1 */ \ 200 ld %r7,FRAME_CR+48(%r1); \ 201 mtctr %r4; \ 202 mtxer %r5; \ 203 mtlr %r6; \ 204 mtsprg1 %r7; /* save cr */ \ 205 ld %r31,FRAME_31+48(%r1); /* restore r0-31 */ \ 206 ld %r30,FRAME_30+48(%r1); \ 207 ld %r29,FRAME_29+48(%r1); \ 208 ld %r28,FRAME_28+48(%r1); \ 209 ld %r27,FRAME_27+48(%r1); \ 210 ld %r26,FRAME_26+48(%r1); \ 211 ld %r25,FRAME_25+48(%r1); \ 212 ld %r24,FRAME_24+48(%r1); \ 213 ld %r23,FRAME_23+48(%r1); \ 214 ld %r22,FRAME_22+48(%r1); \ 215 ld %r21,FRAME_21+48(%r1); \ 216 ld %r20,FRAME_20+48(%r1); \ 217 ld %r19,FRAME_19+48(%r1); \ 218 ld %r18,FRAME_18+48(%r1); \ 219 ld %r17,FRAME_17+48(%r1); \ 220 ld %r16,FRAME_16+48(%r1); \ 221 ld %r15,FRAME_15+48(%r1); \ 222 ld %r14,FRAME_14+48(%r1); \ 223 ld %r13,FRAME_13+48(%r1); \ 224 ld %r12,FRAME_12+48(%r1); \ 225 ld %r11,FRAME_11+48(%r1); \ 226 ld %r10,FRAME_10+48(%r1); \ 227 ld %r9, FRAME_9+48(%r1); \ 228 ld %r8, FRAME_8+48(%r1); \ 229 ld %r7, FRAME_7+48(%r1); \ 230 ld %r6, FRAME_6+48(%r1); \ 231 ld %r5, FRAME_5+48(%r1); \ 232 ld %r4, FRAME_4+48(%r1); \ 233 ld %r3, FRAME_3+48(%r1); \ 234 ld %r2, FRAME_2+48(%r1); \ 235 ld %r0, FRAME_0+48(%r1); \ 236 ld %r1, FRAME_1+48(%r1); \ 237/* Can't touch %r1 from here on */ \ 238 mtsprg2 %r2; /* save r2 & r3 */ \ 239 mtsprg3 %r3; \ 240/* Disable translation, machine check and recoverability: */ \ 241 mfmsr %r2; \ 242 andi. %r2,%r2,~(PSL_DR|PSL_IR|PSL_ME|PSL_RI)@l; \ 243 mtmsr %r2; \ 244 isync; \ 245/* Decide whether we return to user mode: */ \ 246 GET_CPUINFO(%r2); \ 247 ld %r3,(savearea+CPUSAVE_SRR1)(%r2); \ 248 mtcr %r3; \ 249 bf 17,1f; /* branch if PSL_PR is false */ \ 250/* Restore user SRs */ \ 251 GET_CPUINFO(%r3); \ 252 std %r27,(savearea+CPUSAVE_R27)(%r3); \ 253 std %r28,(savearea+CPUSAVE_R28)(%r3); \ 254 std %r29,(savearea+CPUSAVE_R29)(%r3); \ 255 std %r30,(savearea+CPUSAVE_R30)(%r3); \ 256 std %r31,(savearea+CPUSAVE_R31)(%r3); \ 257 mflr %r27; /* preserve LR */ \ 258 bl restore_usersrs; /* uses r28-r31 */ \ 259 mtlr %r27; \ 260 ld %r31,(savearea+CPUSAVE_R31)(%r3); \ 261 ld %r30,(savearea+CPUSAVE_R30)(%r3); \ 262 ld %r29,(savearea+CPUSAVE_R29)(%r3); \ 263 ld %r28,(savearea+CPUSAVE_R28)(%r3); \ 264 ld %r27,(savearea+CPUSAVE_R27)(%r3); \ 2651: mfsprg1 %r2; /* restore cr */ \ 266 mtcr %r2; \ 267 GET_CPUINFO(%r2); \ 268 ld %r3,(savearea+CPUSAVE_SRR0)(%r2); /* restore srr0 */ \ 269 mtsrr0 %r3; \ 270 ld %r3,(savearea+CPUSAVE_SRR1)(%r2); /* restore srr1 */ \ 271 mtsrr1 %r3; \ 272 mfsprg2 %r2; /* restore r2 & r3 */ \ 273 mfsprg3 %r3 274 275#ifdef SMP 276/* 277 * Processor reset exception handler. These are typically 278 * the first instructions the processor executes after a 279 * software reset. We do this in two bits so that we are 280 * not still hanging around in the trap handling region 281 * once the MMU is turned on. 282 */ 283 .globl CNAME(rstcode), CNAME(rstsize) 284CNAME(rstcode): 285 /* Explicitly set MSR[SF] */ 286 mfmsr %r9 287 li %r8,1 288 insrdi %r9,%r8,1,0 289 mtmsrd %r9 290 isync 291 292 ba cpu_reset 293CNAME(rstsize) = . - CNAME(rstcode) 294 295cpu_reset: 296 lis %r1,(tmpstk+TMPSTKSZ-48)@ha /* get new SP */ 297 addi %r1,%r1,(tmpstk+TMPSTKSZ-48)@l 298 299 lis %r3,tocbase@ha 300 ld %r2,tocbase@l(%r3) 301 lis %r3,1@l 302 bl CNAME(cpudep_ap_early_bootstrap) /* Set PCPU */ 303 nop 304 lis %r3,1@l 305 bl CNAME(pmap_cpu_bootstrap) /* Turn on virtual memory */ 306 nop 307 bl CNAME(cpudep_ap_bootstrap) /* Set up PCPU and stack */ 308 nop 309 mr %r1,%r3 /* Use new stack */ 310 bl CNAME(machdep_ap_bootstrap) /* And away! */ 311 nop 312 313 /* Should not be reached */ 3149: 315 b 9b 316#endif 317 318/* 319 * This code gets copied to all the trap vectors 320 * (except ISI/DSI, ALI, and the interrupts) 321 */ 322 323 .globl CNAME(trapcode),CNAME(trapsize) 324CNAME(trapcode): 325 mtsprg1 %r1 /* save SP */ 326 mflr %r1 /* Save the old LR in r1 */ 327 mtsprg2 %r1 /* And then in SPRG2 */ 328 li %r1, 0xA0 /* How to get the vector from LR */ 329 bla generictrap /* LR & SPRG3 is exception # */ 330CNAME(trapsize) = .-CNAME(trapcode) 331 332/* 333 * For ALI: has to save DSISR and DAR 334 */ 335 .globl CNAME(alitrap),CNAME(alisize) 336CNAME(alitrap): 337 mtsprg1 %r1 /* save SP */ 338 GET_CPUINFO(%r1) 339 std %r27,(PC_TEMPSAVE+CPUSAVE_R27)(%r1) /* free r27-r31 */ 340 std %r28,(PC_TEMPSAVE+CPUSAVE_R28)(%r1) 341 std %r29,(PC_TEMPSAVE+CPUSAVE_R29)(%r1) 342 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1) 343 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1) 344 mfdar %r30 345 mfdsisr %r31 346 std %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1) 347 std %r31,(PC_TEMPSAVE+CPUSAVE_AIM_DSISR)(%r1) 348 mfsprg1 %r1 /* restore SP, in case of branch */ 349 mflr %r28 /* save LR */ 350 mfcr %r29 /* save CR */ 351 352 /* Put our exception vector in SPRG3 */ 353 li %r31, EXC_ALI 354 mtsprg3 %r31 355 356 /* Test whether we already had PR set */ 357 mfsrr1 %r31 358 mtcr %r31 359 bla s_trap 360CNAME(alisize) = .-CNAME(alitrap) 361 362/* 363 * Similar to the above for DSI 364 * Has to handle BAT spills 365 * and standard pagetable spills 366 */ 367 .globl CNAME(dsitrap),CNAME(dsisize) 368CNAME(dsitrap): 369 mtsprg1 %r1 /* save SP */ 370 GET_CPUINFO(%r1) 371 std %r27,(PC_DISISAVE+CPUSAVE_R27)(%r1) /* free r27-r31 */ 372 std %r28,(PC_DISISAVE+CPUSAVE_R28)(%r1) 373 std %r29,(PC_DISISAVE+CPUSAVE_R29)(%r1) 374 std %r30,(PC_DISISAVE+CPUSAVE_R30)(%r1) 375 std %r31,(PC_DISISAVE+CPUSAVE_R31)(%r1) 376 mfsprg1 %r1 /* restore SP */ 377 mfcr %r29 /* save CR */ 378 mfxer %r30 /* save XER */ 379 mtsprg2 %r30 /* in SPRG2 */ 380 mfsrr1 %r31 /* test kernel mode */ 381 mtcr %r31 382 mflr %r28 /* save LR (SP already saved) */ 383 bla disitrap 384CNAME(dsisize) = .-CNAME(dsitrap) 385 386/* 387 * Preamble code for DSI/ISI traps 388 */ 389disitrap: 390 /* Write the trap vector to SPRG3 by computing LR & 0xff00 */ 391 mflr %r1 392 andi. %r1,%r1,0xff00 393 mtsprg3 %r1 394 395 GET_CPUINFO(%r1) 396 ld %r31,(PC_DISISAVE+CPUSAVE_R27)(%r1) 397 std %r31,(PC_TEMPSAVE+CPUSAVE_R27)(%r1) 398 ld %r30,(PC_DISISAVE+CPUSAVE_R28)(%r1) 399 std %r30,(PC_TEMPSAVE+CPUSAVE_R28)(%r1) 400 ld %r31,(PC_DISISAVE+CPUSAVE_R29)(%r1) 401 std %r31,(PC_TEMPSAVE+CPUSAVE_R29)(%r1) 402 ld %r30,(PC_DISISAVE+CPUSAVE_R30)(%r1) 403 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1) 404 ld %r31,(PC_DISISAVE+CPUSAVE_R31)(%r1) 405 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1) 406 mfdar %r30 407 mfdsisr %r31 408 std %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1) 409 std %r31,(PC_TEMPSAVE+CPUSAVE_AIM_DSISR)(%r1) 410 411#ifdef KDB 412 /* Try and detect a kernel stack overflow */ 413 mfsrr1 %r31 414 mtcr %r31 415 bt 17,realtrap /* branch is user mode */ 416 mfsprg1 %r31 /* get old SP */ 417 sub. %r30,%r31,%r30 /* SP - DAR */ 418 bge 1f 419 neg %r30,%r30 /* modulo value */ 4201: cmpldi %cr0,%r30,4096 /* is DAR within a page of SP? */ 421 bge %cr0,realtrap /* no, too far away. */ 422 423 /* Now convert this DSI into a DDB trap. */ 424 GET_CPUINFO(%r1) 425 ld %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1) /* get DAR */ 426 std %r30,(PC_DBSAVE +CPUSAVE_AIM_DAR)(%r1) /* save DAR */ 427 ld %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DSISR)(%r1) /* get DSISR */ 428 std %r30,(PC_DBSAVE +CPUSAVE_AIM_DSISR)(%r1) /* save DSISR */ 429 ld %r31,(PC_DISISAVE+CPUSAVE_R27)(%r1) /* get r27 */ 430 std %r31,(PC_DBSAVE +CPUSAVE_R27)(%r1) /* save r27 */ 431 ld %r30,(PC_DISISAVE+CPUSAVE_R28)(%r1) /* get r28 */ 432 std %r30,(PC_DBSAVE +CPUSAVE_R28)(%r1) /* save r28 */ 433 ld %r31,(PC_DISISAVE+CPUSAVE_R29)(%r1) /* get r29 */ 434 std %r31,(PC_DBSAVE +CPUSAVE_R29)(%r1) /* save r29 */ 435 ld %r30,(PC_DISISAVE+CPUSAVE_R30)(%r1) /* get r30 */ 436 std %r30,(PC_DBSAVE +CPUSAVE_R30)(%r1) /* save r30 */ 437 ld %r31,(PC_DISISAVE+CPUSAVE_R31)(%r1) /* get r31 */ 438 std %r31,(PC_DBSAVE +CPUSAVE_R31)(%r1) /* save r31 */ 439 b dbtrap 440#endif 441 442 /* XXX need stack probe here */ 443realtrap: 444/* Test whether we already had PR set */ 445 mfsrr1 %r1 446 mtcr %r1 447 mfsprg1 %r1 /* restore SP (might have been 448 overwritten) */ 449 bf 17,k_trap /* branch if PSL_PR is false */ 450 GET_CPUINFO(%r1) 451 ld %r1,PC_CURPCB(%r1) 452 mr %r27,%r28 /* Save LR, r29 */ 453 mtsprg2 %r29 454 bl restore_kernsrs /* enable kernel mapping */ 455 mfsprg2 %r29 456 mr %r28,%r27 457 ba s_trap 458 459/* 460 * generictrap does some standard setup for trap handling to minimize 461 * the code that need be installed in the actual vectors. It expects 462 * the following conditions. 463 * 464 * R1 - Trap vector = LR & (0xff00 | R1) 465 * SPRG1 - Original R1 contents 466 * SPRG2 - Original LR 467 */ 468 469generictrap: 470 /* Save R1 for computing the exception vector */ 471 mtsprg3 %r1 472 473 /* Save interesting registers */ 474 GET_CPUINFO(%r1) 475 std %r27,(PC_TEMPSAVE+CPUSAVE_R27)(%r1) /* free r27-r31 */ 476 std %r28,(PC_TEMPSAVE+CPUSAVE_R28)(%r1) 477 std %r29,(PC_TEMPSAVE+CPUSAVE_R29)(%r1) 478 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1) 479 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1) 480 mfdar %r30 481 std %r30,(PC_TEMPSAVE+CPUSAVE_AIM_DAR)(%r1) 482 mfsprg1 %r1 /* restore SP, in case of branch */ 483 mfsprg2 %r28 /* save LR */ 484 mfcr %r29 /* save CR */ 485 486 /* Compute the exception vector from the link register */ 487 mfsprg3 %r31 488 ori %r31,%r31,0xff00 489 mflr %r30 490 and %r30,%r30,%r31 491 mtsprg3 %r30 492 493 /* Test whether we already had PR set */ 494 mfsrr1 %r31 495 mtcr %r31 496 497s_trap: 498 bf 17,k_trap /* branch if PSL_PR is false */ 499 GET_CPUINFO(%r1) 500u_trap: 501 ld %r1,PC_CURPCB(%r1) 502 mr %r27,%r28 /* Save LR, r29 */ 503 mtsprg2 %r29 504 bl restore_kernsrs /* enable kernel mapping */ 505 mfsprg2 %r29 506 mr %r28,%r27 507 508/* 509 * Now the common trap catching code. 510 */ 511k_trap: 512 FRAME_SETUP(PC_TEMPSAVE) 513/* Call C interrupt dispatcher: */ 514trapagain: 515 lis %r3,tocbase@ha 516 ld %r2,tocbase@l(%r3) 517 addi %r3,%r1,48 518 bl CNAME(powerpc_interrupt) 519 nop 520 521 .globl CNAME(trapexit) /* backtrace code sentinel */ 522CNAME(trapexit): 523/* Disable interrupts: */ 524 mfmsr %r3 525 andi. %r3,%r3,~PSL_EE@l 526 mtmsr %r3 527 isync 528/* Test AST pending: */ 529 ld %r5,FRAME_SRR1+48(%r1) 530 mtcr %r5 531 bf 17,1f /* branch if PSL_PR is false */ 532 533 GET_CPUINFO(%r3) /* get per-CPU pointer */ 534 lwz %r4, TD_FLAGS(%r13) /* get thread flags value */ 535 lis %r5, (TDF_ASTPENDING|TDF_NEEDRESCHED)@h 536 ori %r5,%r5, (TDF_ASTPENDING|TDF_NEEDRESCHED)@l 537 and. %r4,%r4,%r5 538 beq 1f 539 mfmsr %r3 /* re-enable interrupts */ 540 ori %r3,%r3,PSL_EE@l 541 mtmsr %r3 542 isync 543 lis %r3,tocbase@ha 544 ld %r2,tocbase@l(%r3) 545 addi %r3,%r1,48 546 bl CNAME(ast) 547 nop 548 .globl CNAME(asttrapexit) /* backtrace code sentinel #2 */ 549CNAME(asttrapexit): 550 b trapexit /* test ast ret value ? */ 5511: 552 FRAME_LEAVE(PC_TEMPSAVE) 553 rfid 554 555#if defined(KDB) 556/* 557 * Deliberate entry to dbtrap 558 */ 559ASENTRY(breakpoint) 560 mtsprg1 %r1 561 mfmsr %r3 562 mtsrr1 %r3 563 andi. %r3,%r3,~(PSL_EE|PSL_ME)@l 564 mtmsr %r3 /* disable interrupts */ 565 isync 566 GET_CPUINFO(%r3) 567 std %r27,(PC_DBSAVE+CPUSAVE_R27)(%r3) 568 std %r28,(PC_DBSAVE+CPUSAVE_R28)(%r3) 569 std %r29,(PC_DBSAVE+CPUSAVE_R29)(%r3) 570 std %r30,(PC_DBSAVE+CPUSAVE_R30)(%r3) 571 std %r31,(PC_DBSAVE+CPUSAVE_R31)(%r3) 572 mflr %r28 573 li %r29,EXC_BPT 574 mtlr %r29 575 mfcr %r29 576 mtsrr0 %r28 577 578/* 579 * Now the kdb trap catching code. 580 */ 581dbtrap: 582 /* Write the trap vector to SPRG3 by computing LR & 0xff00 */ 583 mflr %r1 584 andi. %r1,%r1,0xff00 585 mtsprg3 %r1 586 587 lis %r1,(tmpstk+TMPSTKSZ-48)@ha /* get new SP */ 588 addi %r1,%r1,(tmpstk+TMPSTKSZ-48)@l 589 590 FRAME_SETUP(PC_DBSAVE) 591/* Call C trap code: */ 592 lis %r3,tocbase@ha 593 ld %r2,tocbase@l(%r3) 594 addi %r3,%r1,48 595 bl CNAME(db_trap_glue) 596 nop 597 or. %r3,%r3,%r3 598 bne dbleave 599/* This wasn't for KDB, so switch to real trap: */ 600 ld %r3,FRAME_EXC+48(%r1) /* save exception */ 601 GET_CPUINFO(%r4) 602 std %r3,(PC_DBSAVE+CPUSAVE_R31)(%r4) 603 FRAME_LEAVE(PC_DBSAVE) 604 mtsprg1 %r1 /* prepare for entrance to realtrap */ 605 GET_CPUINFO(%r1) 606 std %r27,(PC_TEMPSAVE+CPUSAVE_R27)(%r1) 607 std %r28,(PC_TEMPSAVE+CPUSAVE_R28)(%r1) 608 std %r29,(PC_TEMPSAVE+CPUSAVE_R29)(%r1) 609 std %r30,(PC_TEMPSAVE+CPUSAVE_R30)(%r1) 610 std %r31,(PC_TEMPSAVE+CPUSAVE_R31)(%r1) 611 mflr %r28 612 mfcr %r29 613 ld %r31,(PC_DBSAVE+CPUSAVE_R31)(%r1) 614 mtsprg3 %r31 /* SPRG3 was clobbered by FRAME_LEAVE */ 615 mfsprg1 %r1 616 b realtrap 617dbleave: 618 FRAME_LEAVE(PC_DBSAVE) 619 rfid 620 621/* 622 * In case of KDB we want a separate trap catcher for it 623 */ 624 .globl CNAME(dblow),CNAME(dbsize) 625CNAME(dblow): 626 mtsprg1 %r1 /* save SP */ 627 mtsprg2 %r29 /* save r29 */ 628 mfcr %r29 /* save CR in r29 */ 629 mfsrr1 %r1 630 mtcr %r1 631 bf 17,1f /* branch if privileged */ 632 633 /* Unprivileged case */ 634 mtcr %r29 /* put the condition register back */ 635 mfsprg2 %r29 /* ... and r29 */ 636 mflr %r1 /* save LR */ 637 mtsprg2 %r1 /* And then in SPRG2 */ 638 li %r1, 0 /* How to get the vector from LR */ 639 640 bla generictrap /* and we look like a generic trap */ 6411: 642 /* Privileged, so drop to KDB */ 643 GET_CPUINFO(%r1) 644 std %r27,(PC_DBSAVE+CPUSAVE_R27)(%r1) /* free r27 */ 645 std %r28,(PC_DBSAVE+CPUSAVE_R28)(%r1) /* free r28 */ 646 mfsprg2 %r28 /* r29 holds cr... */ 647 std %r28,(PC_DBSAVE+CPUSAVE_R29)(%r1) /* free r29 */ 648 std %r30,(PC_DBSAVE+CPUSAVE_R30)(%r1) /* free r30 */ 649 std %r31,(PC_DBSAVE+CPUSAVE_R31)(%r1) /* free r31 */ 650 mflr %r28 /* save LR */ 651 bla dbtrap 652CNAME(dbsize) = .-CNAME(dblow) 653#endif /* KDB */ 654