Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Kernel execution entry point code. |
| 3 | * |
| 4 | * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org> |
| 5 | * Initial PowerPC version. |
| 6 | * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu> |
| 7 | * Rewritten for PReP |
| 8 | * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au> |
| 9 | * Low-level exception handers, MMU support, and rewrite. |
| 10 | * Copyright (c) 1997 Dan Malek <dmalek@jlc.net> |
| 11 | * PowerPC 8xx modifications. |
| 12 | * Copyright (c) 1998-1999 TiVo, Inc. |
| 13 | * PowerPC 403GCX modifications. |
| 14 | * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu> |
| 15 | * PowerPC 403GCX/405GP modifications. |
| 16 | * Copyright 2000 MontaVista Software Inc. |
| 17 | * PPC405 modifications |
| 18 | * PowerPC 403GCX/405GP modifications. |
| 19 | * Author: MontaVista Software, Inc. |
| 20 | * frank_rowand@mvista.com or source@mvista.com |
| 21 | * debbie_chu@mvista.com |
| 22 | * Copyright 2002-2005 MontaVista Software, Inc. |
| 23 | * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org> |
| 24 | * |
| 25 | * This program is free software; you can redistribute it and/or modify it |
| 26 | * under the terms of the GNU General Public License as published by the |
| 27 | * Free Software Foundation; either version 2 of the License, or (at your |
| 28 | * option) any later version. |
| 29 | */ |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/processor.h> |
| 32 | #include <asm/page.h> |
| 33 | #include <asm/mmu.h> |
| 34 | #include <asm/pgtable.h> |
| 35 | #include <asm/ibm4xx.h> |
| 36 | #include <asm/ibm44x.h> |
| 37 | #include <asm/cputable.h> |
| 38 | #include <asm/thread_info.h> |
| 39 | #include <asm/ppc_asm.h> |
Sam Ravnborg | 0013a85 | 2005-09-09 20:57:26 +0200 | [diff] [blame] | 40 | #include <asm/asm-offsets.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include "head_booke.h" |
| 42 | |
| 43 | |
| 44 | /* As with the other PowerPC ports, it is expected that when code |
| 45 | * execution begins here, the following registers contain valid, yet |
| 46 | * optional, information: |
| 47 | * |
| 48 | * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.) |
| 49 | * r4 - Starting address of the init RAM disk |
| 50 | * r5 - Ending address of the init RAM disk |
| 51 | * r6 - Start of kernel command line string (e.g. "mem=128") |
| 52 | * r7 - End of kernel command line string |
| 53 | * |
| 54 | */ |
| 55 | .text |
| 56 | _GLOBAL(_stext) |
| 57 | _GLOBAL(_start) |
| 58 | /* |
| 59 | * Reserve a word at a fixed location to store the address |
| 60 | * of abatron_pteptrs |
| 61 | */ |
| 62 | nop |
| 63 | /* |
| 64 | * Save parameters we are passed |
| 65 | */ |
| 66 | mr r31,r3 |
| 67 | mr r30,r4 |
| 68 | mr r29,r5 |
| 69 | mr r28,r6 |
| 70 | mr r27,r7 |
| 71 | li r24,0 /* CPU number */ |
| 72 | |
| 73 | /* |
| 74 | * Set up the initial MMU state |
| 75 | * |
| 76 | * We are still executing code at the virtual address |
| 77 | * mappings set by the firmware for the base of RAM. |
| 78 | * |
| 79 | * We first invalidate all TLB entries but the one |
| 80 | * we are running from. We then load the KERNELBASE |
| 81 | * mappings so we can begin to use kernel addresses |
| 82 | * natively and so the interrupt vector locations are |
| 83 | * permanently pinned (necessary since Book E |
| 84 | * implementations always have translation enabled). |
| 85 | * |
| 86 | * TODO: Use the known TLB entry we are running from to |
| 87 | * determine which physical region we are located |
| 88 | * in. This can be used to determine where in RAM |
| 89 | * (on a shared CPU system) or PCI memory space |
| 90 | * (on a DRAMless system) we are located. |
| 91 | * For now, we assume a perfect world which means |
| 92 | * we are located at the base of DRAM (physical 0). |
| 93 | */ |
| 94 | |
| 95 | /* |
| 96 | * Search TLB for entry that we are currently using. |
| 97 | * Invalidate all entries but the one we are using. |
| 98 | */ |
| 99 | /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ |
| 100 | mfspr r3,SPRN_PID /* Get PID */ |
| 101 | mfmsr r4 /* Get MSR */ |
| 102 | andi. r4,r4,MSR_IS@l /* TS=1? */ |
| 103 | beq wmmucr /* If not, leave STS=0 */ |
| 104 | oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */ |
| 105 | wmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ |
| 106 | sync |
| 107 | |
| 108 | bl invstr /* Find our address */ |
| 109 | invstr: mflr r5 /* Make it accessible */ |
| 110 | tlbsx r23,0,r5 /* Find entry we are in */ |
| 111 | li r4,0 /* Start at TLB entry 0 */ |
| 112 | li r3,0 /* Set PAGEID inval value */ |
| 113 | 1: cmpw r23,r4 /* Is this our entry? */ |
| 114 | beq skpinv /* If so, skip the inval */ |
| 115 | tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */ |
| 116 | skpinv: addi r4,r4,1 /* Increment */ |
| 117 | cmpwi r4,64 /* Are we done? */ |
| 118 | bne 1b /* If not, repeat */ |
| 119 | isync /* If so, context change */ |
| 120 | |
| 121 | /* |
| 122 | * Configure and load pinned entry into TLB slot 63. |
| 123 | */ |
| 124 | |
| 125 | lis r3,KERNELBASE@h /* Load the kernel virtual address */ |
| 126 | ori r3,r3,KERNELBASE@l |
| 127 | |
| 128 | /* Kernel is at the base of RAM */ |
| 129 | li r4, 0 /* Load the kernel physical address */ |
| 130 | |
| 131 | /* Load the kernel PID = 0 */ |
| 132 | li r0,0 |
| 133 | mtspr SPRN_PID,r0 |
| 134 | sync |
| 135 | |
| 136 | /* Initialize MMUCR */ |
| 137 | li r5,0 |
| 138 | mtspr SPRN_MMUCR,r5 |
| 139 | sync |
| 140 | |
| 141 | /* pageid fields */ |
| 142 | clrrwi r3,r3,10 /* Mask off the effective page number */ |
| 143 | ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M |
| 144 | |
| 145 | /* xlat fields */ |
| 146 | clrrwi r4,r4,10 /* Mask off the real page number */ |
| 147 | /* ERPN is 0 for first 4GB page */ |
| 148 | |
| 149 | /* attrib fields */ |
| 150 | /* Added guarded bit to protect against speculative loads/stores */ |
| 151 | li r5,0 |
| 152 | ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G) |
| 153 | |
| 154 | li r0,63 /* TLB slot 63 */ |
| 155 | |
| 156 | tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */ |
| 157 | tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */ |
| 158 | tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */ |
| 159 | |
| 160 | /* Force context change */ |
| 161 | mfmsr r0 |
| 162 | mtspr SPRN_SRR1, r0 |
| 163 | lis r0,3f@h |
| 164 | ori r0,r0,3f@l |
| 165 | mtspr SPRN_SRR0,r0 |
| 166 | sync |
| 167 | rfi |
| 168 | |
| 169 | /* If necessary, invalidate original entry we used */ |
| 170 | 3: cmpwi r23,63 |
| 171 | beq 4f |
| 172 | li r6,0 |
| 173 | tlbwe r6,r23,PPC44x_TLB_PAGEID |
| 174 | isync |
| 175 | |
| 176 | 4: |
| 177 | #ifdef CONFIG_SERIAL_TEXT_DEBUG |
| 178 | /* |
Eugene Surovegin | 5ce17b1 | 2005-07-29 22:59:19 -0700 | [diff] [blame] | 179 | * Add temporary UART mapping for early debug. |
| 180 | * We can map UART registers wherever we want as long as they don't |
| 181 | * interfere with other system mappings (e.g. with pinned entries). |
| 182 | * For an example of how we handle this - see ocotea.h. --ebs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | */ |
| 184 | /* pageid fields */ |
| 185 | lis r3,UART0_IO_BASE@h |
Eugene Surovegin | 5ce17b1 | 2005-07-29 22:59:19 -0700 | [diff] [blame] | 186 | ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_4K |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | /* xlat fields */ |
| 189 | lis r4,UART0_PHYS_IO_BASE@h /* RPN depends on SoC */ |
Roland Dreier | fcc188e | 2005-11-07 00:58:11 -0800 | [diff] [blame] | 190 | #ifdef UART0_PHYS_ERPN |
| 191 | ori r4,r4,UART0_PHYS_ERPN /* Add ERPN if above 4GB */ |
Matt Porter | c9cf73a | 2005-07-31 22:34:52 -0700 | [diff] [blame] | 192 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
| 194 | /* attrib fields */ |
| 195 | li r5,0 |
| 196 | ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_I | PPC44x_TLB_G) |
| 197 | |
Stefan Roese | f4151b9 | 2007-11-20 21:19:16 +1100 | [diff] [blame] | 198 | li r0,62 /* TLB slot 62 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */ |
| 201 | tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */ |
| 202 | tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */ |
| 203 | |
| 204 | /* Force context change */ |
| 205 | isync |
| 206 | #endif /* CONFIG_SERIAL_TEXT_DEBUG */ |
| 207 | |
| 208 | /* Establish the interrupt vector offsets */ |
| 209 | SET_IVOR(0, CriticalInput); |
| 210 | SET_IVOR(1, MachineCheck); |
| 211 | SET_IVOR(2, DataStorage); |
| 212 | SET_IVOR(3, InstructionStorage); |
| 213 | SET_IVOR(4, ExternalInput); |
| 214 | SET_IVOR(5, Alignment); |
| 215 | SET_IVOR(6, Program); |
| 216 | SET_IVOR(7, FloatingPointUnavailable); |
| 217 | SET_IVOR(8, SystemCall); |
| 218 | SET_IVOR(9, AuxillaryProcessorUnavailable); |
| 219 | SET_IVOR(10, Decrementer); |
| 220 | SET_IVOR(11, FixedIntervalTimer); |
| 221 | SET_IVOR(12, WatchdogTimer); |
| 222 | SET_IVOR(13, DataTLBError); |
| 223 | SET_IVOR(14, InstructionTLBError); |
| 224 | SET_IVOR(15, Debug); |
| 225 | |
| 226 | /* Establish the interrupt vector base */ |
| 227 | lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */ |
| 228 | mtspr SPRN_IVPR,r4 |
| 229 | |
| 230 | /* |
| 231 | * This is where the main kernel code starts. |
| 232 | */ |
| 233 | |
| 234 | /* ptr to current */ |
| 235 | lis r2,init_task@h |
| 236 | ori r2,r2,init_task@l |
| 237 | |
| 238 | /* ptr to current thread */ |
| 239 | addi r4,r2,THREAD /* init task's THREAD */ |
| 240 | mtspr SPRN_SPRG3,r4 |
| 241 | |
| 242 | /* stack */ |
| 243 | lis r1,init_thread_union@h |
| 244 | ori r1,r1,init_thread_union@l |
| 245 | li r0,0 |
| 246 | stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) |
| 247 | |
| 248 | bl early_init |
| 249 | |
| 250 | /* |
| 251 | * Decide what sort of machine this is and initialize the MMU. |
| 252 | */ |
| 253 | mr r3,r31 |
| 254 | mr r4,r30 |
| 255 | mr r5,r29 |
| 256 | mr r6,r28 |
| 257 | mr r7,r27 |
| 258 | bl machine_init |
| 259 | bl MMU_init |
| 260 | |
| 261 | /* Setup PTE pointers for the Abatron bdiGDB */ |
| 262 | lis r6, swapper_pg_dir@h |
| 263 | ori r6, r6, swapper_pg_dir@l |
| 264 | lis r5, abatron_pteptrs@h |
| 265 | ori r5, r5, abatron_pteptrs@l |
| 266 | lis r4, KERNELBASE@h |
| 267 | ori r4, r4, KERNELBASE@l |
| 268 | stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */ |
| 269 | stw r6, 0(r5) |
| 270 | |
| 271 | /* Let's move on */ |
| 272 | lis r4,start_kernel@h |
| 273 | ori r4,r4,start_kernel@l |
| 274 | lis r3,MSR_KERNEL@h |
| 275 | ori r3,r3,MSR_KERNEL@l |
| 276 | mtspr SPRN_SRR0,r4 |
| 277 | mtspr SPRN_SRR1,r3 |
| 278 | rfi /* change context and jump to start_kernel */ |
| 279 | |
| 280 | /* |
| 281 | * Interrupt vector entry code |
| 282 | * |
| 283 | * The Book E MMUs are always on so we don't need to handle |
| 284 | * interrupts in real mode as with previous PPC processors. In |
| 285 | * this case we handle interrupts in the kernel virtual address |
| 286 | * space. |
| 287 | * |
| 288 | * Interrupt vectors are dynamically placed relative to the |
| 289 | * interrupt prefix as determined by the address of interrupt_base. |
| 290 | * The interrupt vectors offsets are programmed using the labels |
| 291 | * for each interrupt vector entry. |
| 292 | * |
| 293 | * Interrupt vectors must be aligned on a 16 byte boundary. |
| 294 | * We align on a 32 byte cache line boundary for good measure. |
| 295 | */ |
| 296 | |
| 297 | interrupt_base: |
| 298 | /* Critical Input Interrupt */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 299 | CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | /* Machine Check Interrupt */ |
| 302 | #ifdef CONFIG_440A |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 303 | MCHECK_EXCEPTION(0x0200, MachineCheck, machine_check_exception) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | #else |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 305 | CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | #endif |
| 307 | |
| 308 | /* Data Storage Interrupt */ |
| 309 | START_EXCEPTION(DataStorage) |
| 310 | mtspr SPRN_SPRG0, r10 /* Save some working registers */ |
| 311 | mtspr SPRN_SPRG1, r11 |
| 312 | mtspr SPRN_SPRG4W, r12 |
| 313 | mtspr SPRN_SPRG5W, r13 |
| 314 | mfcr r11 |
| 315 | mtspr SPRN_SPRG7W, r11 |
| 316 | |
| 317 | /* |
| 318 | * Check if it was a store fault, if not then bail |
| 319 | * because a user tried to access a kernel or |
| 320 | * read-protected page. Otherwise, get the |
| 321 | * offending address and handle it. |
| 322 | */ |
| 323 | mfspr r10, SPRN_ESR |
| 324 | andis. r10, r10, ESR_ST@h |
| 325 | beq 2f |
| 326 | |
| 327 | mfspr r10, SPRN_DEAR /* Get faulting address */ |
| 328 | |
| 329 | /* If we are faulting a kernel address, we have to use the |
| 330 | * kernel page tables. |
| 331 | */ |
Matt Porter | b2665f9 | 2005-05-20 13:59:14 -0700 | [diff] [blame] | 332 | lis r11, TASK_SIZE@h |
| 333 | cmplw r10, r11 |
| 334 | blt+ 3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | lis r11, swapper_pg_dir@h |
| 336 | ori r11, r11, swapper_pg_dir@l |
| 337 | |
| 338 | mfspr r12,SPRN_MMUCR |
| 339 | rlwinm r12,r12,0,0,23 /* Clear TID */ |
| 340 | |
| 341 | b 4f |
| 342 | |
| 343 | /* Get the PGD for the current thread */ |
| 344 | 3: |
| 345 | mfspr r11,SPRN_SPRG3 |
| 346 | lwz r11,PGDIR(r11) |
| 347 | |
| 348 | /* Load PID into MMUCR TID */ |
| 349 | mfspr r12,SPRN_MMUCR /* Get MMUCR */ |
| 350 | mfspr r13,SPRN_PID /* Get PID */ |
| 351 | rlwimi r12,r13,0,24,31 /* Set TID */ |
| 352 | |
| 353 | 4: |
| 354 | mtspr SPRN_MMUCR,r12 |
| 355 | |
| 356 | rlwinm r12, r10, 13, 19, 29 /* Compute pgdir/pmd offset */ |
| 357 | lwzx r11, r12, r11 /* Get pgd/pmd entry */ |
| 358 | rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ |
| 359 | beq 2f /* Bail if no table */ |
| 360 | |
| 361 | rlwimi r12, r10, 23, 20, 28 /* Compute pte address */ |
| 362 | lwz r11, 4(r12) /* Get pte entry */ |
| 363 | |
| 364 | andi. r13, r11, _PAGE_RW /* Is it writeable? */ |
| 365 | beq 2f /* Bail if not */ |
| 366 | |
| 367 | /* Update 'changed'. |
| 368 | */ |
| 369 | ori r11, r11, _PAGE_DIRTY|_PAGE_ACCESSED|_PAGE_HWWRITE |
| 370 | stw r11, 4(r12) /* Update Linux page table */ |
| 371 | |
| 372 | li r13, PPC44x_TLB_SR@l /* Set SR */ |
| 373 | rlwimi r13, r11, 29, 29, 29 /* SX = _PAGE_HWEXEC */ |
| 374 | rlwimi r13, r11, 0, 30, 30 /* SW = _PAGE_RW */ |
| 375 | rlwimi r13, r11, 29, 28, 28 /* UR = _PAGE_USER */ |
| 376 | rlwimi r12, r11, 31, 26, 26 /* (_PAGE_USER>>1)->r12 */ |
| 377 | rlwimi r12, r11, 29, 30, 30 /* (_PAGE_USER>>3)->r12 */ |
| 378 | and r12, r12, r11 /* HWEXEC/RW & USER */ |
| 379 | rlwimi r13, r12, 0, 26, 26 /* UX = HWEXEC & USER */ |
| 380 | rlwimi r13, r12, 3, 27, 27 /* UW = RW & USER */ |
| 381 | |
| 382 | rlwimi r11,r13,0,26,31 /* Insert static perms */ |
| 383 | |
| 384 | rlwinm r11,r11,0,20,15 /* Clear U0-U3 */ |
| 385 | |
| 386 | /* find the TLB index that caused the fault. It has to be here. */ |
| 387 | tlbsx r10, 0, r10 |
| 388 | |
| 389 | tlbwe r11, r10, PPC44x_TLB_ATTRIB /* Write ATTRIB */ |
| 390 | |
| 391 | /* Done...restore registers and get out of here. |
| 392 | */ |
| 393 | mfspr r11, SPRN_SPRG7R |
| 394 | mtcr r11 |
| 395 | mfspr r13, SPRN_SPRG5R |
| 396 | mfspr r12, SPRN_SPRG4R |
| 397 | |
| 398 | mfspr r11, SPRN_SPRG1 |
| 399 | mfspr r10, SPRN_SPRG0 |
| 400 | rfi /* Force context change */ |
| 401 | |
| 402 | 2: |
| 403 | /* |
| 404 | * The bailout. Restore registers to pre-exception conditions |
| 405 | * and call the heavyweights to help us out. |
| 406 | */ |
| 407 | mfspr r11, SPRN_SPRG7R |
| 408 | mtcr r11 |
| 409 | mfspr r13, SPRN_SPRG5R |
| 410 | mfspr r12, SPRN_SPRG4R |
| 411 | |
| 412 | mfspr r11, SPRN_SPRG1 |
| 413 | mfspr r10, SPRN_SPRG0 |
| 414 | b data_access |
| 415 | |
| 416 | /* Instruction Storage Interrupt */ |
| 417 | INSTRUCTION_STORAGE_EXCEPTION |
| 418 | |
| 419 | /* External Input Interrupt */ |
| 420 | EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE) |
| 421 | |
| 422 | /* Alignment Interrupt */ |
| 423 | ALIGNMENT_EXCEPTION |
| 424 | |
| 425 | /* Program Interrupt */ |
| 426 | PROGRAM_EXCEPTION |
| 427 | |
| 428 | /* Floating Point Unavailable Interrupt */ |
Paul Mackerras | 443a848 | 2005-05-01 08:58:40 -0700 | [diff] [blame] | 429 | #ifdef CONFIG_PPC_FPU |
| 430 | FP_UNAVAILABLE_EXCEPTION |
| 431 | #else |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 432 | EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE) |
Paul Mackerras | 443a848 | 2005-05-01 08:58:40 -0700 | [diff] [blame] | 433 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | /* System Call Interrupt */ |
| 436 | START_EXCEPTION(SystemCall) |
| 437 | NORMAL_EXCEPTION_PROLOG |
| 438 | EXC_XFER_EE_LITE(0x0c00, DoSyscall) |
| 439 | |
| 440 | /* Auxillary Processor Unavailable Interrupt */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 441 | EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | /* Decrementer Interrupt */ |
| 444 | DECREMENTER_EXCEPTION |
| 445 | |
| 446 | /* Fixed Internal Timer Interrupt */ |
| 447 | /* TODO: Add FIT support */ |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 448 | EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | /* Watchdog Timer Interrupt */ |
| 451 | /* TODO: Add watchdog support */ |
Kumar Gala | a2f40cc | 2005-09-03 15:55:33 -0700 | [diff] [blame] | 452 | #ifdef CONFIG_BOOKE_WDT |
| 453 | CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException) |
| 454 | #else |
Stephen Rothwell | dc1c1ca | 2005-10-01 18:43:42 +1000 | [diff] [blame] | 455 | CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception) |
Kumar Gala | a2f40cc | 2005-09-03 15:55:33 -0700 | [diff] [blame] | 456 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
| 458 | /* Data TLB Error Interrupt */ |
| 459 | START_EXCEPTION(DataTLBError) |
| 460 | mtspr SPRN_SPRG0, r10 /* Save some working registers */ |
| 461 | mtspr SPRN_SPRG1, r11 |
| 462 | mtspr SPRN_SPRG4W, r12 |
| 463 | mtspr SPRN_SPRG5W, r13 |
| 464 | mfcr r11 |
| 465 | mtspr SPRN_SPRG7W, r11 |
| 466 | mfspr r10, SPRN_DEAR /* Get faulting address */ |
| 467 | |
| 468 | /* If we are faulting a kernel address, we have to use the |
| 469 | * kernel page tables. |
| 470 | */ |
Matt Porter | b2665f9 | 2005-05-20 13:59:14 -0700 | [diff] [blame] | 471 | lis r11, TASK_SIZE@h |
| 472 | cmplw r10, r11 |
| 473 | blt+ 3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | lis r11, swapper_pg_dir@h |
| 475 | ori r11, r11, swapper_pg_dir@l |
| 476 | |
| 477 | mfspr r12,SPRN_MMUCR |
| 478 | rlwinm r12,r12,0,0,23 /* Clear TID */ |
| 479 | |
| 480 | b 4f |
| 481 | |
| 482 | /* Get the PGD for the current thread */ |
| 483 | 3: |
| 484 | mfspr r11,SPRN_SPRG3 |
| 485 | lwz r11,PGDIR(r11) |
| 486 | |
| 487 | /* Load PID into MMUCR TID */ |
| 488 | mfspr r12,SPRN_MMUCR |
| 489 | mfspr r13,SPRN_PID /* Get PID */ |
| 490 | rlwimi r12,r13,0,24,31 /* Set TID */ |
| 491 | |
| 492 | 4: |
| 493 | mtspr SPRN_MMUCR,r12 |
| 494 | |
| 495 | rlwinm r12, r10, 13, 19, 29 /* Compute pgdir/pmd offset */ |
| 496 | lwzx r11, r12, r11 /* Get pgd/pmd entry */ |
| 497 | rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ |
| 498 | beq 2f /* Bail if no table */ |
| 499 | |
| 500 | rlwimi r12, r10, 23, 20, 28 /* Compute pte address */ |
| 501 | lwz r11, 4(r12) /* Get pte entry */ |
| 502 | andi. r13, r11, _PAGE_PRESENT /* Is the page present? */ |
| 503 | beq 2f /* Bail if not present */ |
| 504 | |
| 505 | ori r11, r11, _PAGE_ACCESSED |
| 506 | stw r11, 4(r12) |
| 507 | |
| 508 | /* Jump to common tlb load */ |
| 509 | b finish_tlb_load |
| 510 | |
| 511 | 2: |
| 512 | /* The bailout. Restore registers to pre-exception conditions |
| 513 | * and call the heavyweights to help us out. |
| 514 | */ |
| 515 | mfspr r11, SPRN_SPRG7R |
| 516 | mtcr r11 |
| 517 | mfspr r13, SPRN_SPRG5R |
| 518 | mfspr r12, SPRN_SPRG4R |
| 519 | mfspr r11, SPRN_SPRG1 |
| 520 | mfspr r10, SPRN_SPRG0 |
| 521 | b data_access |
| 522 | |
| 523 | /* Instruction TLB Error Interrupt */ |
| 524 | /* |
| 525 | * Nearly the same as above, except we get our |
| 526 | * information from different registers and bailout |
| 527 | * to a different point. |
| 528 | */ |
| 529 | START_EXCEPTION(InstructionTLBError) |
| 530 | mtspr SPRN_SPRG0, r10 /* Save some working registers */ |
| 531 | mtspr SPRN_SPRG1, r11 |
| 532 | mtspr SPRN_SPRG4W, r12 |
| 533 | mtspr SPRN_SPRG5W, r13 |
| 534 | mfcr r11 |
| 535 | mtspr SPRN_SPRG7W, r11 |
| 536 | mfspr r10, SPRN_SRR0 /* Get faulting address */ |
| 537 | |
| 538 | /* If we are faulting a kernel address, we have to use the |
| 539 | * kernel page tables. |
| 540 | */ |
Matt Porter | b2665f9 | 2005-05-20 13:59:14 -0700 | [diff] [blame] | 541 | lis r11, TASK_SIZE@h |
| 542 | cmplw r10, r11 |
| 543 | blt+ 3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | lis r11, swapper_pg_dir@h |
| 545 | ori r11, r11, swapper_pg_dir@l |
| 546 | |
| 547 | mfspr r12,SPRN_MMUCR |
| 548 | rlwinm r12,r12,0,0,23 /* Clear TID */ |
| 549 | |
| 550 | b 4f |
| 551 | |
| 552 | /* Get the PGD for the current thread */ |
| 553 | 3: |
| 554 | mfspr r11,SPRN_SPRG3 |
| 555 | lwz r11,PGDIR(r11) |
| 556 | |
| 557 | /* Load PID into MMUCR TID */ |
| 558 | mfspr r12,SPRN_MMUCR |
| 559 | mfspr r13,SPRN_PID /* Get PID */ |
| 560 | rlwimi r12,r13,0,24,31 /* Set TID */ |
| 561 | |
| 562 | 4: |
| 563 | mtspr SPRN_MMUCR,r12 |
| 564 | |
| 565 | rlwinm r12, r10, 13, 19, 29 /* Compute pgdir/pmd offset */ |
| 566 | lwzx r11, r12, r11 /* Get pgd/pmd entry */ |
| 567 | rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ |
| 568 | beq 2f /* Bail if no table */ |
| 569 | |
| 570 | rlwimi r12, r10, 23, 20, 28 /* Compute pte address */ |
| 571 | lwz r11, 4(r12) /* Get pte entry */ |
| 572 | andi. r13, r11, _PAGE_PRESENT /* Is the page present? */ |
| 573 | beq 2f /* Bail if not present */ |
| 574 | |
| 575 | ori r11, r11, _PAGE_ACCESSED |
| 576 | stw r11, 4(r12) |
| 577 | |
| 578 | /* Jump to common TLB load point */ |
| 579 | b finish_tlb_load |
| 580 | |
| 581 | 2: |
| 582 | /* The bailout. Restore registers to pre-exception conditions |
| 583 | * and call the heavyweights to help us out. |
| 584 | */ |
| 585 | mfspr r11, SPRN_SPRG7R |
| 586 | mtcr r11 |
| 587 | mfspr r13, SPRN_SPRG5R |
| 588 | mfspr r12, SPRN_SPRG4R |
| 589 | mfspr r11, SPRN_SPRG1 |
| 590 | mfspr r10, SPRN_SPRG0 |
| 591 | b InstructionStorage |
| 592 | |
| 593 | /* Debug Interrupt */ |
| 594 | DEBUG_EXCEPTION |
| 595 | |
| 596 | /* |
| 597 | * Local functions |
| 598 | */ |
| 599 | /* |
| 600 | * Data TLB exceptions will bail out to this point |
| 601 | * if they can't resolve the lightweight TLB fault. |
| 602 | */ |
| 603 | data_access: |
| 604 | NORMAL_EXCEPTION_PROLOG |
| 605 | mfspr r5,SPRN_ESR /* Grab the ESR, save it, pass arg3 */ |
| 606 | stw r5,_ESR(r11) |
| 607 | mfspr r4,SPRN_DEAR /* Grab the DEAR, save it, pass arg2 */ |
| 608 | EXC_XFER_EE_LITE(0x0300, handle_page_fault) |
| 609 | |
| 610 | /* |
| 611 | |
| 612 | * Both the instruction and data TLB miss get to this |
| 613 | * point to load the TLB. |
| 614 | * r10 - EA of fault |
| 615 | * r11 - available to use |
| 616 | * r12 - Pointer to the 64-bit PTE |
| 617 | * r13 - available to use |
| 618 | * MMUCR - loaded with proper value when we get here |
| 619 | * Upon exit, we reload everything and RFI. |
| 620 | */ |
| 621 | finish_tlb_load: |
| 622 | /* |
| 623 | * We set execute, because we don't have the granularity to |
| 624 | * properly set this at the page level (Linux problem). |
| 625 | * If shared is set, we cause a zero PID->TID load. |
| 626 | * Many of these bits are software only. Bits we don't set |
| 627 | * here we (properly should) assume have the appropriate value. |
| 628 | */ |
| 629 | |
| 630 | /* Load the next available TLB index */ |
| 631 | lis r13, tlb_44x_index@ha |
| 632 | lwz r13, tlb_44x_index@l(r13) |
| 633 | /* Load the TLB high watermark */ |
| 634 | lis r11, tlb_44x_hwater@ha |
| 635 | lwz r11, tlb_44x_hwater@l(r11) |
| 636 | |
| 637 | /* Increment, rollover, and store TLB index */ |
| 638 | addi r13, r13, 1 |
| 639 | cmpw 0, r13, r11 /* reserve entries */ |
| 640 | ble 7f |
| 641 | li r13, 0 |
| 642 | 7: |
| 643 | /* Store the next available TLB index */ |
| 644 | lis r11, tlb_44x_index@ha |
| 645 | stw r13, tlb_44x_index@l(r11) |
| 646 | |
| 647 | lwz r11, 0(r12) /* Get MS word of PTE */ |
| 648 | lwz r12, 4(r12) /* Get LS word of PTE */ |
| 649 | rlwimi r11, r12, 0, 0 , 19 /* Insert RPN */ |
| 650 | tlbwe r11, r13, PPC44x_TLB_XLAT /* Write XLAT */ |
| 651 | |
| 652 | /* |
| 653 | * Create PAGEID. This is the faulting address, |
| 654 | * page size, and valid flag. |
| 655 | */ |
| 656 | li r11, PPC44x_TLB_VALID | PPC44x_TLB_4K |
| 657 | rlwimi r10, r11, 0, 20, 31 /* Insert valid and page size */ |
| 658 | tlbwe r10, r13, PPC44x_TLB_PAGEID /* Write PAGEID */ |
| 659 | |
| 660 | li r10, PPC44x_TLB_SR@l /* Set SR */ |
| 661 | rlwimi r10, r12, 0, 30, 30 /* Set SW = _PAGE_RW */ |
| 662 | rlwimi r10, r12, 29, 29, 29 /* SX = _PAGE_HWEXEC */ |
| 663 | rlwimi r10, r12, 29, 28, 28 /* UR = _PAGE_USER */ |
| 664 | rlwimi r11, r12, 31, 26, 26 /* (_PAGE_USER>>1)->r12 */ |
| 665 | and r11, r12, r11 /* HWEXEC & USER */ |
| 666 | rlwimi r10, r11, 0, 26, 26 /* UX = HWEXEC & USER */ |
| 667 | |
| 668 | rlwimi r12, r10, 0, 26, 31 /* Insert static perms */ |
| 669 | rlwinm r12, r12, 0, 20, 15 /* Clear U0-U3 */ |
| 670 | tlbwe r12, r13, PPC44x_TLB_ATTRIB /* Write ATTRIB */ |
| 671 | |
| 672 | /* Done...restore registers and get out of here. |
| 673 | */ |
| 674 | mfspr r11, SPRN_SPRG7R |
| 675 | mtcr r11 |
| 676 | mfspr r13, SPRN_SPRG5R |
| 677 | mfspr r12, SPRN_SPRG4R |
| 678 | mfspr r11, SPRN_SPRG1 |
| 679 | mfspr r10, SPRN_SPRG0 |
| 680 | rfi /* Force context change */ |
| 681 | |
| 682 | /* |
| 683 | * Global functions |
| 684 | */ |
| 685 | |
| 686 | /* |
| 687 | * extern void giveup_altivec(struct task_struct *prev) |
| 688 | * |
| 689 | * The 44x core does not have an AltiVec unit. |
| 690 | */ |
| 691 | _GLOBAL(giveup_altivec) |
| 692 | blr |
| 693 | |
| 694 | /* |
| 695 | * extern void giveup_fpu(struct task_struct *prev) |
| 696 | * |
| 697 | * The 44x core does not have an FPU. |
| 698 | */ |
Paul Mackerras | 443a848 | 2005-05-01 08:58:40 -0700 | [diff] [blame] | 699 | #ifndef CONFIG_PPC_FPU |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | _GLOBAL(giveup_fpu) |
| 701 | blr |
Paul Mackerras | 443a848 | 2005-05-01 08:58:40 -0700 | [diff] [blame] | 702 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
| 704 | /* |
| 705 | * extern void abort(void) |
| 706 | * |
| 707 | * At present, this routine just applies a system reset. |
| 708 | */ |
| 709 | _GLOBAL(abort) |
| 710 | mfspr r13,SPRN_DBCR0 |
| 711 | oris r13,r13,DBCR0_RST_SYSTEM@h |
| 712 | mtspr SPRN_DBCR0,r13 |
| 713 | |
| 714 | _GLOBAL(set_context) |
| 715 | |
| 716 | #ifdef CONFIG_BDI_SWITCH |
| 717 | /* Context switch the PTE pointer for the Abatron BDI2000. |
| 718 | * The PGDIR is the second parameter. |
| 719 | */ |
| 720 | lis r5, abatron_pteptrs@h |
| 721 | ori r5, r5, abatron_pteptrs@l |
| 722 | stw r4, 0x4(r5) |
| 723 | #endif |
| 724 | mtspr SPRN_PID,r3 |
| 725 | isync /* Force context change */ |
| 726 | blr |
| 727 | |
| 728 | /* |
| 729 | * We put a few things here that have to be page-aligned. This stuff |
| 730 | * goes at the beginning of the data segment, which is page-aligned. |
| 731 | */ |
| 732 | .data |
Kumar Gala | 3d904ee | 2005-10-18 17:42:41 -0500 | [diff] [blame] | 733 | .align 12 |
| 734 | .globl sdata |
| 735 | sdata: |
| 736 | .globl empty_zero_page |
| 737 | empty_zero_page: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | .space 4096 |
| 739 | |
| 740 | /* |
| 741 | * To support >32-bit physical addresses, we use an 8KB pgdir. |
| 742 | */ |
Kumar Gala | 3d904ee | 2005-10-18 17:42:41 -0500 | [diff] [blame] | 743 | .globl swapper_pg_dir |
| 744 | swapper_pg_dir: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | .space 8192 |
| 746 | |
| 747 | /* Reserved 4k for the critical exception stack & 4k for the machine |
| 748 | * check stack per CPU for kernel mode exceptions */ |
| 749 | .section .bss |
| 750 | .align 12 |
| 751 | exception_stack_bottom: |
| 752 | .space BOOKE_EXCEPTION_STACK_SIZE |
Kumar Gala | 3d904ee | 2005-10-18 17:42:41 -0500 | [diff] [blame] | 753 | .globl exception_stack_top |
| 754 | exception_stack_top: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | |
| 756 | /* |
| 757 | * This space gets a copy of optional info passed to us by the bootstrap |
| 758 | * which is used to pass parameters into the kernel like root=/dev/sda1, etc. |
| 759 | */ |
Kumar Gala | 3d904ee | 2005-10-18 17:42:41 -0500 | [diff] [blame] | 760 | .globl cmd_line |
| 761 | cmd_line: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | .space 512 |
| 763 | |
| 764 | /* |
| 765 | * Room for two PTE pointers, usually the kernel and current user pointers |
| 766 | * to their respective root page table. |
| 767 | */ |
| 768 | abatron_pteptrs: |
| 769 | .space 8 |