114cf11afSPaul Mackerras/* 214cf11afSPaul Mackerras * Kernel execution entry point code. 314cf11afSPaul Mackerras * 414cf11afSPaul Mackerras * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org> 514cf11afSPaul Mackerras * Initial PowerPC version. 614cf11afSPaul Mackerras * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu> 714cf11afSPaul Mackerras * Rewritten for PReP 814cf11afSPaul Mackerras * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au> 914cf11afSPaul Mackerras * Low-level exception handers, MMU support, and rewrite. 1014cf11afSPaul Mackerras * Copyright (c) 1997 Dan Malek <dmalek@jlc.net> 1114cf11afSPaul Mackerras * PowerPC 8xx modifications. 1214cf11afSPaul Mackerras * Copyright (c) 1998-1999 TiVo, Inc. 1314cf11afSPaul Mackerras * PowerPC 403GCX modifications. 1414cf11afSPaul Mackerras * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu> 1514cf11afSPaul Mackerras * PowerPC 403GCX/405GP modifications. 1614cf11afSPaul Mackerras * Copyright 2000 MontaVista Software Inc. 1714cf11afSPaul Mackerras * PPC405 modifications 1814cf11afSPaul Mackerras * PowerPC 403GCX/405GP modifications. 1914cf11afSPaul Mackerras * Author: MontaVista Software, Inc. 2014cf11afSPaul Mackerras * frank_rowand@mvista.com or source@mvista.com 2114cf11afSPaul Mackerras * debbie_chu@mvista.com 2214cf11afSPaul Mackerras * Copyright 2002-2005 MontaVista Software, Inc. 2314cf11afSPaul Mackerras * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org> 2414cf11afSPaul Mackerras * 2514cf11afSPaul Mackerras * This program is free software; you can redistribute it and/or modify it 2614cf11afSPaul Mackerras * under the terms of the GNU General Public License as published by the 2714cf11afSPaul Mackerras * Free Software Foundation; either version 2 of the License, or (at your 2814cf11afSPaul Mackerras * option) any later version. 2914cf11afSPaul Mackerras */ 3014cf11afSPaul Mackerras 31*e7039845STim Abbott#include <linux/init.h> 3214cf11afSPaul Mackerras#include <asm/processor.h> 3314cf11afSPaul Mackerras#include <asm/page.h> 3414cf11afSPaul Mackerras#include <asm/mmu.h> 3514cf11afSPaul Mackerras#include <asm/pgtable.h> 3614cf11afSPaul Mackerras#include <asm/cputable.h> 3714cf11afSPaul Mackerras#include <asm/thread_info.h> 3814cf11afSPaul Mackerras#include <asm/ppc_asm.h> 3914cf11afSPaul Mackerras#include <asm/asm-offsets.h> 4014cf11afSPaul Mackerras#include "head_booke.h" 4114cf11afSPaul Mackerras 4214cf11afSPaul Mackerras 4314cf11afSPaul Mackerras/* As with the other PowerPC ports, it is expected that when code 4414cf11afSPaul Mackerras * execution begins here, the following registers contain valid, yet 4514cf11afSPaul Mackerras * optional, information: 4614cf11afSPaul Mackerras * 4714cf11afSPaul Mackerras * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.) 4814cf11afSPaul Mackerras * r4 - Starting address of the init RAM disk 4914cf11afSPaul Mackerras * r5 - Ending address of the init RAM disk 5014cf11afSPaul Mackerras * r6 - Start of kernel command line string (e.g. "mem=128") 5114cf11afSPaul Mackerras * r7 - End of kernel command line string 5214cf11afSPaul Mackerras * 5314cf11afSPaul Mackerras */ 54*e7039845STim Abbott __HEAD 55748a7683SKumar Gala_ENTRY(_stext); 56748a7683SKumar Gala_ENTRY(_start); 5714cf11afSPaul Mackerras /* 5814cf11afSPaul Mackerras * Reserve a word at a fixed location to store the address 5914cf11afSPaul Mackerras * of abatron_pteptrs 6014cf11afSPaul Mackerras */ 6114cf11afSPaul Mackerras nop 6214cf11afSPaul Mackerras/* 6314cf11afSPaul Mackerras * Save parameters we are passed 6414cf11afSPaul Mackerras */ 6514cf11afSPaul Mackerras mr r31,r3 6614cf11afSPaul Mackerras mr r30,r4 6714cf11afSPaul Mackerras mr r29,r5 6814cf11afSPaul Mackerras mr r28,r6 6914cf11afSPaul Mackerras mr r27,r7 7014cf11afSPaul Mackerras li r24,0 /* CPU number */ 7114cf11afSPaul Mackerras 7214cf11afSPaul Mackerras/* 739dce3ce5SBenjamin Herrenschmidt * In case the firmware didn't do it, we apply some workarounds 749dce3ce5SBenjamin Herrenschmidt * that are good for all 440 core variants here 759dce3ce5SBenjamin Herrenschmidt */ 769dce3ce5SBenjamin Herrenschmidt mfspr r3,SPRN_CCR0 779dce3ce5SBenjamin Herrenschmidt rlwinm r3,r3,0,0,27 /* disable icache prefetch */ 789dce3ce5SBenjamin Herrenschmidt isync 799dce3ce5SBenjamin Herrenschmidt mtspr SPRN_CCR0,r3 809dce3ce5SBenjamin Herrenschmidt isync 819dce3ce5SBenjamin Herrenschmidt sync 829dce3ce5SBenjamin Herrenschmidt 839dce3ce5SBenjamin Herrenschmidt/* 8414cf11afSPaul Mackerras * Set up the initial MMU state 8514cf11afSPaul Mackerras * 8614cf11afSPaul Mackerras * We are still executing code at the virtual address 8714cf11afSPaul Mackerras * mappings set by the firmware for the base of RAM. 8814cf11afSPaul Mackerras * 8914cf11afSPaul Mackerras * We first invalidate all TLB entries but the one 9014cf11afSPaul Mackerras * we are running from. We then load the KERNELBASE 9114cf11afSPaul Mackerras * mappings so we can begin to use kernel addresses 9214cf11afSPaul Mackerras * natively and so the interrupt vector locations are 9314cf11afSPaul Mackerras * permanently pinned (necessary since Book E 9414cf11afSPaul Mackerras * implementations always have translation enabled). 9514cf11afSPaul Mackerras * 9614cf11afSPaul Mackerras * TODO: Use the known TLB entry we are running from to 9714cf11afSPaul Mackerras * determine which physical region we are located 9814cf11afSPaul Mackerras * in. This can be used to determine where in RAM 9914cf11afSPaul Mackerras * (on a shared CPU system) or PCI memory space 10014cf11afSPaul Mackerras * (on a DRAMless system) we are located. 10114cf11afSPaul Mackerras * For now, we assume a perfect world which means 10214cf11afSPaul Mackerras * we are located at the base of DRAM (physical 0). 10314cf11afSPaul Mackerras */ 10414cf11afSPaul Mackerras 10514cf11afSPaul Mackerras/* 10614cf11afSPaul Mackerras * Search TLB for entry that we are currently using. 10714cf11afSPaul Mackerras * Invalidate all entries but the one we are using. 10814cf11afSPaul Mackerras */ 10914cf11afSPaul Mackerras /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ 11014cf11afSPaul Mackerras mfspr r3,SPRN_PID /* Get PID */ 11114cf11afSPaul Mackerras mfmsr r4 /* Get MSR */ 11214cf11afSPaul Mackerras andi. r4,r4,MSR_IS@l /* TS=1? */ 11314cf11afSPaul Mackerras beq wmmucr /* If not, leave STS=0 */ 11414cf11afSPaul Mackerras oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */ 11514cf11afSPaul Mackerraswmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ 11614cf11afSPaul Mackerras sync 11714cf11afSPaul Mackerras 11814cf11afSPaul Mackerras bl invstr /* Find our address */ 11914cf11afSPaul Mackerrasinvstr: mflr r5 /* Make it accessible */ 12014cf11afSPaul Mackerras tlbsx r23,0,r5 /* Find entry we are in */ 12114cf11afSPaul Mackerras li r4,0 /* Start at TLB entry 0 */ 12214cf11afSPaul Mackerras li r3,0 /* Set PAGEID inval value */ 12314cf11afSPaul Mackerras1: cmpw r23,r4 /* Is this our entry? */ 12414cf11afSPaul Mackerras beq skpinv /* If so, skip the inval */ 12514cf11afSPaul Mackerras tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */ 12614cf11afSPaul Mackerrasskpinv: addi r4,r4,1 /* Increment */ 12714cf11afSPaul Mackerras cmpwi r4,64 /* Are we done? */ 12814cf11afSPaul Mackerras bne 1b /* If not, repeat */ 12914cf11afSPaul Mackerras isync /* If so, context change */ 13014cf11afSPaul Mackerras 13114cf11afSPaul Mackerras/* 13214cf11afSPaul Mackerras * Configure and load pinned entry into TLB slot 63. 13314cf11afSPaul Mackerras */ 13414cf11afSPaul Mackerras 13557d7909eSDavid Gibson lis r3,PAGE_OFFSET@h 13657d7909eSDavid Gibson ori r3,r3,PAGE_OFFSET@l 13714cf11afSPaul Mackerras 13814cf11afSPaul Mackerras /* Kernel is at the base of RAM */ 13914cf11afSPaul Mackerras li r4, 0 /* Load the kernel physical address */ 14014cf11afSPaul Mackerras 14114cf11afSPaul Mackerras /* Load the kernel PID = 0 */ 14214cf11afSPaul Mackerras li r0,0 14314cf11afSPaul Mackerras mtspr SPRN_PID,r0 14414cf11afSPaul Mackerras sync 14514cf11afSPaul Mackerras 14614cf11afSPaul Mackerras /* Initialize MMUCR */ 14714cf11afSPaul Mackerras li r5,0 14814cf11afSPaul Mackerras mtspr SPRN_MMUCR,r5 14914cf11afSPaul Mackerras sync 15014cf11afSPaul Mackerras 15114cf11afSPaul Mackerras /* pageid fields */ 15214cf11afSPaul Mackerras clrrwi r3,r3,10 /* Mask off the effective page number */ 15314cf11afSPaul Mackerras ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M 15414cf11afSPaul Mackerras 15514cf11afSPaul Mackerras /* xlat fields */ 15614cf11afSPaul Mackerras clrrwi r4,r4,10 /* Mask off the real page number */ 15714cf11afSPaul Mackerras /* ERPN is 0 for first 4GB page */ 15814cf11afSPaul Mackerras 15914cf11afSPaul Mackerras /* attrib fields */ 16014cf11afSPaul Mackerras /* Added guarded bit to protect against speculative loads/stores */ 16114cf11afSPaul Mackerras li r5,0 16214cf11afSPaul Mackerras ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G) 16314cf11afSPaul Mackerras 16414cf11afSPaul Mackerras li r0,63 /* TLB slot 63 */ 16514cf11afSPaul Mackerras 16614cf11afSPaul Mackerras tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */ 16714cf11afSPaul Mackerras tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */ 16814cf11afSPaul Mackerras tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */ 16914cf11afSPaul Mackerras 17014cf11afSPaul Mackerras /* Force context change */ 17114cf11afSPaul Mackerras mfmsr r0 17214cf11afSPaul Mackerras mtspr SPRN_SRR1, r0 17314cf11afSPaul Mackerras lis r0,3f@h 17414cf11afSPaul Mackerras ori r0,r0,3f@l 17514cf11afSPaul Mackerras mtspr SPRN_SRR0,r0 17614cf11afSPaul Mackerras sync 17714cf11afSPaul Mackerras rfi 17814cf11afSPaul Mackerras 17914cf11afSPaul Mackerras /* If necessary, invalidate original entry we used */ 18014cf11afSPaul Mackerras3: cmpwi r23,63 18114cf11afSPaul Mackerras beq 4f 18214cf11afSPaul Mackerras li r6,0 18314cf11afSPaul Mackerras tlbwe r6,r23,PPC44x_TLB_PAGEID 18414cf11afSPaul Mackerras isync 18514cf11afSPaul Mackerras 18614cf11afSPaul Mackerras4: 187d9b55a03SDavid Gibson#ifdef CONFIG_PPC_EARLY_DEBUG_44x 188d9b55a03SDavid Gibson /* Add UART mapping for early debug. */ 189d9b55a03SDavid Gibson 19014cf11afSPaul Mackerras /* pageid fields */ 191d9b55a03SDavid Gibson lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h 192d9b55a03SDavid Gibson ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K 19314cf11afSPaul Mackerras 19414cf11afSPaul Mackerras /* xlat fields */ 195d9b55a03SDavid Gibson lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h 196d9b55a03SDavid Gibson ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH 19714cf11afSPaul Mackerras 19814cf11afSPaul Mackerras /* attrib fields */ 199d9b55a03SDavid Gibson li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G) 200d9b55a03SDavid Gibson li r0,62 /* TLB slot 0 */ 20114cf11afSPaul Mackerras 202d9b55a03SDavid Gibson tlbwe r3,r0,PPC44x_TLB_PAGEID 203d9b55a03SDavid Gibson tlbwe r4,r0,PPC44x_TLB_XLAT 204d9b55a03SDavid Gibson tlbwe r5,r0,PPC44x_TLB_ATTRIB 20514cf11afSPaul Mackerras 20614cf11afSPaul Mackerras /* Force context change */ 20714cf11afSPaul Mackerras isync 208d9b55a03SDavid Gibson#endif /* CONFIG_PPC_EARLY_DEBUG_44x */ 20914cf11afSPaul Mackerras 21014cf11afSPaul Mackerras /* Establish the interrupt vector offsets */ 21114cf11afSPaul Mackerras SET_IVOR(0, CriticalInput); 21214cf11afSPaul Mackerras SET_IVOR(1, MachineCheck); 21314cf11afSPaul Mackerras SET_IVOR(2, DataStorage); 21414cf11afSPaul Mackerras SET_IVOR(3, InstructionStorage); 21514cf11afSPaul Mackerras SET_IVOR(4, ExternalInput); 21614cf11afSPaul Mackerras SET_IVOR(5, Alignment); 21714cf11afSPaul Mackerras SET_IVOR(6, Program); 21814cf11afSPaul Mackerras SET_IVOR(7, FloatingPointUnavailable); 21914cf11afSPaul Mackerras SET_IVOR(8, SystemCall); 22014cf11afSPaul Mackerras SET_IVOR(9, AuxillaryProcessorUnavailable); 22114cf11afSPaul Mackerras SET_IVOR(10, Decrementer); 22214cf11afSPaul Mackerras SET_IVOR(11, FixedIntervalTimer); 22314cf11afSPaul Mackerras SET_IVOR(12, WatchdogTimer); 22414cf11afSPaul Mackerras SET_IVOR(13, DataTLBError); 22514cf11afSPaul Mackerras SET_IVOR(14, InstructionTLBError); 226eb0cd5fdSKumar Gala SET_IVOR(15, DebugCrit); 22714cf11afSPaul Mackerras 22814cf11afSPaul Mackerras /* Establish the interrupt vector base */ 22914cf11afSPaul Mackerras lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */ 23014cf11afSPaul Mackerras mtspr SPRN_IVPR,r4 23114cf11afSPaul Mackerras 23214cf11afSPaul Mackerras /* 23314cf11afSPaul Mackerras * This is where the main kernel code starts. 23414cf11afSPaul Mackerras */ 23514cf11afSPaul Mackerras 23614cf11afSPaul Mackerras /* ptr to current */ 23714cf11afSPaul Mackerras lis r2,init_task@h 23814cf11afSPaul Mackerras ori r2,r2,init_task@l 23914cf11afSPaul Mackerras 24014cf11afSPaul Mackerras /* ptr to current thread */ 24114cf11afSPaul Mackerras addi r4,r2,THREAD /* init task's THREAD */ 24214cf11afSPaul Mackerras mtspr SPRN_SPRG3,r4 24314cf11afSPaul Mackerras 24414cf11afSPaul Mackerras /* stack */ 24514cf11afSPaul Mackerras lis r1,init_thread_union@h 24614cf11afSPaul Mackerras ori r1,r1,init_thread_union@l 24714cf11afSPaul Mackerras li r0,0 24814cf11afSPaul Mackerras stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) 24914cf11afSPaul Mackerras 25014cf11afSPaul Mackerras bl early_init 25114cf11afSPaul Mackerras 25214cf11afSPaul Mackerras/* 25314cf11afSPaul Mackerras * Decide what sort of machine this is and initialize the MMU. 25414cf11afSPaul Mackerras */ 25514cf11afSPaul Mackerras mr r3,r31 25614cf11afSPaul Mackerras mr r4,r30 25714cf11afSPaul Mackerras mr r5,r29 25814cf11afSPaul Mackerras mr r6,r28 25914cf11afSPaul Mackerras mr r7,r27 26014cf11afSPaul Mackerras bl machine_init 26114cf11afSPaul Mackerras bl MMU_init 26214cf11afSPaul Mackerras 26314cf11afSPaul Mackerras /* Setup PTE pointers for the Abatron bdiGDB */ 26414cf11afSPaul Mackerras lis r6, swapper_pg_dir@h 26514cf11afSPaul Mackerras ori r6, r6, swapper_pg_dir@l 26614cf11afSPaul Mackerras lis r5, abatron_pteptrs@h 26714cf11afSPaul Mackerras ori r5, r5, abatron_pteptrs@l 26814cf11afSPaul Mackerras lis r4, KERNELBASE@h 26914cf11afSPaul Mackerras ori r4, r4, KERNELBASE@l 27014cf11afSPaul Mackerras stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */ 27114cf11afSPaul Mackerras stw r6, 0(r5) 27214cf11afSPaul Mackerras 27314cf11afSPaul Mackerras /* Let's move on */ 27414cf11afSPaul Mackerras lis r4,start_kernel@h 27514cf11afSPaul Mackerras ori r4,r4,start_kernel@l 27614cf11afSPaul Mackerras lis r3,MSR_KERNEL@h 27714cf11afSPaul Mackerras ori r3,r3,MSR_KERNEL@l 27814cf11afSPaul Mackerras mtspr SPRN_SRR0,r4 27914cf11afSPaul Mackerras mtspr SPRN_SRR1,r3 28014cf11afSPaul Mackerras rfi /* change context and jump to start_kernel */ 28114cf11afSPaul Mackerras 28214cf11afSPaul Mackerras/* 28314cf11afSPaul Mackerras * Interrupt vector entry code 28414cf11afSPaul Mackerras * 28514cf11afSPaul Mackerras * The Book E MMUs are always on so we don't need to handle 28614cf11afSPaul Mackerras * interrupts in real mode as with previous PPC processors. In 28714cf11afSPaul Mackerras * this case we handle interrupts in the kernel virtual address 28814cf11afSPaul Mackerras * space. 28914cf11afSPaul Mackerras * 29014cf11afSPaul Mackerras * Interrupt vectors are dynamically placed relative to the 29114cf11afSPaul Mackerras * interrupt prefix as determined by the address of interrupt_base. 29214cf11afSPaul Mackerras * The interrupt vectors offsets are programmed using the labels 29314cf11afSPaul Mackerras * for each interrupt vector entry. 29414cf11afSPaul Mackerras * 29514cf11afSPaul Mackerras * Interrupt vectors must be aligned on a 16 byte boundary. 29614cf11afSPaul Mackerras * We align on a 32 byte cache line boundary for good measure. 29714cf11afSPaul Mackerras */ 29814cf11afSPaul Mackerras 29914cf11afSPaul Mackerrasinterrupt_base: 30014cf11afSPaul Mackerras /* Critical Input Interrupt */ 301dc1c1ca3SStephen Rothwell CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception) 30214cf11afSPaul Mackerras 30314cf11afSPaul Mackerras /* Machine Check Interrupt */ 304dc1c1ca3SStephen Rothwell CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception) 30547c0bd1aSBenjamin Herrenschmidt MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception) 30614cf11afSPaul Mackerras 30714cf11afSPaul Mackerras /* Data Storage Interrupt */ 3081bc54c03SBenjamin Herrenschmidt DATA_STORAGE_EXCEPTION 30914cf11afSPaul Mackerras 31014cf11afSPaul Mackerras /* Instruction Storage Interrupt */ 31114cf11afSPaul Mackerras INSTRUCTION_STORAGE_EXCEPTION 31214cf11afSPaul Mackerras 31314cf11afSPaul Mackerras /* External Input Interrupt */ 31414cf11afSPaul Mackerras EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE) 31514cf11afSPaul Mackerras 31614cf11afSPaul Mackerras /* Alignment Interrupt */ 31714cf11afSPaul Mackerras ALIGNMENT_EXCEPTION 31814cf11afSPaul Mackerras 31914cf11afSPaul Mackerras /* Program Interrupt */ 32014cf11afSPaul Mackerras PROGRAM_EXCEPTION 32114cf11afSPaul Mackerras 32214cf11afSPaul Mackerras /* Floating Point Unavailable Interrupt */ 32314cf11afSPaul Mackerras#ifdef CONFIG_PPC_FPU 32414cf11afSPaul Mackerras FP_UNAVAILABLE_EXCEPTION 32514cf11afSPaul Mackerras#else 326dc1c1ca3SStephen Rothwell EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE) 32714cf11afSPaul Mackerras#endif 32814cf11afSPaul Mackerras /* System Call Interrupt */ 32914cf11afSPaul Mackerras START_EXCEPTION(SystemCall) 33014cf11afSPaul Mackerras NORMAL_EXCEPTION_PROLOG 33114cf11afSPaul Mackerras EXC_XFER_EE_LITE(0x0c00, DoSyscall) 33214cf11afSPaul Mackerras 33314cf11afSPaul Mackerras /* Auxillary Processor Unavailable Interrupt */ 334dc1c1ca3SStephen Rothwell EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE) 33514cf11afSPaul Mackerras 33614cf11afSPaul Mackerras /* Decrementer Interrupt */ 33714cf11afSPaul Mackerras DECREMENTER_EXCEPTION 33814cf11afSPaul Mackerras 33914cf11afSPaul Mackerras /* Fixed Internal Timer Interrupt */ 34014cf11afSPaul Mackerras /* TODO: Add FIT support */ 341dc1c1ca3SStephen Rothwell EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE) 34214cf11afSPaul Mackerras 34314cf11afSPaul Mackerras /* Watchdog Timer Interrupt */ 34414cf11afSPaul Mackerras /* TODO: Add watchdog support */ 34514cf11afSPaul Mackerras#ifdef CONFIG_BOOKE_WDT 34614cf11afSPaul Mackerras CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException) 34714cf11afSPaul Mackerras#else 348dc1c1ca3SStephen Rothwell CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception) 34914cf11afSPaul Mackerras#endif 35014cf11afSPaul Mackerras 35114cf11afSPaul Mackerras /* Data TLB Error Interrupt */ 35214cf11afSPaul Mackerras START_EXCEPTION(DataTLBError) 35314cf11afSPaul Mackerras mtspr SPRN_SPRG0, r10 /* Save some working registers */ 35414cf11afSPaul Mackerras mtspr SPRN_SPRG1, r11 35514cf11afSPaul Mackerras mtspr SPRN_SPRG4W, r12 35614cf11afSPaul Mackerras mtspr SPRN_SPRG5W, r13 35714cf11afSPaul Mackerras mfcr r11 35814cf11afSPaul Mackerras mtspr SPRN_SPRG7W, r11 35914cf11afSPaul Mackerras mfspr r10, SPRN_DEAR /* Get faulting address */ 36014cf11afSPaul Mackerras 36114cf11afSPaul Mackerras /* If we are faulting a kernel address, we have to use the 36214cf11afSPaul Mackerras * kernel page tables. 36314cf11afSPaul Mackerras */ 3648a13c4f9SKumar Gala lis r11, PAGE_OFFSET@h 36514cf11afSPaul Mackerras cmplw r10, r11 36614cf11afSPaul Mackerras blt+ 3f 36714cf11afSPaul Mackerras lis r11, swapper_pg_dir@h 36814cf11afSPaul Mackerras ori r11, r11, swapper_pg_dir@l 36914cf11afSPaul Mackerras 37014cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 37114cf11afSPaul Mackerras rlwinm r12,r12,0,0,23 /* Clear TID */ 37214cf11afSPaul Mackerras 37314cf11afSPaul Mackerras b 4f 37414cf11afSPaul Mackerras 37514cf11afSPaul Mackerras /* Get the PGD for the current thread */ 37614cf11afSPaul Mackerras3: 37714cf11afSPaul Mackerras mfspr r11,SPRN_SPRG3 37814cf11afSPaul Mackerras lwz r11,PGDIR(r11) 37914cf11afSPaul Mackerras 38014cf11afSPaul Mackerras /* Load PID into MMUCR TID */ 38114cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 38214cf11afSPaul Mackerras mfspr r13,SPRN_PID /* Get PID */ 38314cf11afSPaul Mackerras rlwimi r12,r13,0,24,31 /* Set TID */ 38414cf11afSPaul Mackerras 38514cf11afSPaul Mackerras4: 38614cf11afSPaul Mackerras mtspr SPRN_MMUCR,r12 38714cf11afSPaul Mackerras 3881bc54c03SBenjamin Herrenschmidt /* Mask of required permission bits. Note that while we 3891bc54c03SBenjamin Herrenschmidt * do copy ESR:ST to _PAGE_RW position as trying to write 3901bc54c03SBenjamin Herrenschmidt * to an RO page is pretty common, we don't do it with 3911bc54c03SBenjamin Herrenschmidt * _PAGE_DIRTY. We could do it, but it's a fairly rare 3921bc54c03SBenjamin Herrenschmidt * event so I'd rather take the overhead when it happens 3931bc54c03SBenjamin Herrenschmidt * rather than adding an instruction here. We should measure 3941bc54c03SBenjamin Herrenschmidt * whether the whole thing is worth it in the first place 3951bc54c03SBenjamin Herrenschmidt * as we could avoid loading SPRN_ESR completely in the first 3961bc54c03SBenjamin Herrenschmidt * place... 3971bc54c03SBenjamin Herrenschmidt * 3981bc54c03SBenjamin Herrenschmidt * TODO: Is it worth doing that mfspr & rlwimi in the first 3991bc54c03SBenjamin Herrenschmidt * place or can we save a couple of instructions here ? 4001bc54c03SBenjamin Herrenschmidt */ 4011bc54c03SBenjamin Herrenschmidt mfspr r12,SPRN_ESR 4021bc54c03SBenjamin Herrenschmidt li r13,_PAGE_PRESENT|_PAGE_ACCESSED 4031bc54c03SBenjamin Herrenschmidt rlwimi r13,r12,10,30,30 4041bc54c03SBenjamin Herrenschmidt 4051bc54c03SBenjamin Herrenschmidt /* Load the PTE */ 406ca9153a3SIlya Yanok /* Compute pgdir/pmd offset */ 407ca9153a3SIlya Yanok rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 40814cf11afSPaul Mackerras lwzx r11, r12, r11 /* Get pgd/pmd entry */ 40914cf11afSPaul Mackerras rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ 41014cf11afSPaul Mackerras beq 2f /* Bail if no table */ 41114cf11afSPaul Mackerras 412ca9153a3SIlya Yanok /* Compute pte address */ 413ca9153a3SIlya Yanok rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 4141bc54c03SBenjamin Herrenschmidt lwz r11, 0(r12) /* Get high word of pte entry */ 4151bc54c03SBenjamin Herrenschmidt lwz r12, 4(r12) /* Get low word of pte entry */ 41614cf11afSPaul Mackerras 4171bc54c03SBenjamin Herrenschmidt lis r10,tlb_44x_index@ha 4181bc54c03SBenjamin Herrenschmidt 4191bc54c03SBenjamin Herrenschmidt andc. r13,r13,r12 /* Check permission */ 4201bc54c03SBenjamin Herrenschmidt 4211bc54c03SBenjamin Herrenschmidt /* Load the next available TLB index */ 4221bc54c03SBenjamin Herrenschmidt lwz r13,tlb_44x_index@l(r10) 4231bc54c03SBenjamin Herrenschmidt 4241bc54c03SBenjamin Herrenschmidt bne 2f /* Bail if permission mismach */ 4251bc54c03SBenjamin Herrenschmidt 4261bc54c03SBenjamin Herrenschmidt /* Increment, rollover, and store TLB index */ 4271bc54c03SBenjamin Herrenschmidt addi r13,r13,1 4281bc54c03SBenjamin Herrenschmidt 4291bc54c03SBenjamin Herrenschmidt /* Compare with watermark (instruction gets patched) */ 4301bc54c03SBenjamin Herrenschmidt .globl tlb_44x_patch_hwater_D 4311bc54c03SBenjamin Herrenschmidttlb_44x_patch_hwater_D: 4321bc54c03SBenjamin Herrenschmidt cmpwi 0,r13,1 /* reserve entries */ 4331bc54c03SBenjamin Herrenschmidt ble 5f 4341bc54c03SBenjamin Herrenschmidt li r13,0 4351bc54c03SBenjamin Herrenschmidt5: 4361bc54c03SBenjamin Herrenschmidt /* Store the next available TLB index */ 4371bc54c03SBenjamin Herrenschmidt stw r13,tlb_44x_index@l(r10) 4381bc54c03SBenjamin Herrenschmidt 4391bc54c03SBenjamin Herrenschmidt /* Re-load the faulting address */ 4401bc54c03SBenjamin Herrenschmidt mfspr r10,SPRN_DEAR 44114cf11afSPaul Mackerras 44214cf11afSPaul Mackerras /* Jump to common tlb load */ 44314cf11afSPaul Mackerras b finish_tlb_load 44414cf11afSPaul Mackerras 44514cf11afSPaul Mackerras2: 44614cf11afSPaul Mackerras /* The bailout. Restore registers to pre-exception conditions 44714cf11afSPaul Mackerras * and call the heavyweights to help us out. 44814cf11afSPaul Mackerras */ 44914cf11afSPaul Mackerras mfspr r11, SPRN_SPRG7R 45014cf11afSPaul Mackerras mtcr r11 45114cf11afSPaul Mackerras mfspr r13, SPRN_SPRG5R 45214cf11afSPaul Mackerras mfspr r12, SPRN_SPRG4R 45314cf11afSPaul Mackerras mfspr r11, SPRN_SPRG1 45414cf11afSPaul Mackerras mfspr r10, SPRN_SPRG0 4551bc54c03SBenjamin Herrenschmidt b DataStorage 45614cf11afSPaul Mackerras 45714cf11afSPaul Mackerras /* Instruction TLB Error Interrupt */ 45814cf11afSPaul Mackerras /* 45914cf11afSPaul Mackerras * Nearly the same as above, except we get our 46014cf11afSPaul Mackerras * information from different registers and bailout 46114cf11afSPaul Mackerras * to a different point. 46214cf11afSPaul Mackerras */ 46314cf11afSPaul Mackerras START_EXCEPTION(InstructionTLBError) 46414cf11afSPaul Mackerras mtspr SPRN_SPRG0, r10 /* Save some working registers */ 46514cf11afSPaul Mackerras mtspr SPRN_SPRG1, r11 46614cf11afSPaul Mackerras mtspr SPRN_SPRG4W, r12 46714cf11afSPaul Mackerras mtspr SPRN_SPRG5W, r13 46814cf11afSPaul Mackerras mfcr r11 46914cf11afSPaul Mackerras mtspr SPRN_SPRG7W, r11 47014cf11afSPaul Mackerras mfspr r10, SPRN_SRR0 /* Get faulting address */ 47114cf11afSPaul Mackerras 47214cf11afSPaul Mackerras /* If we are faulting a kernel address, we have to use the 47314cf11afSPaul Mackerras * kernel page tables. 47414cf11afSPaul Mackerras */ 4758a13c4f9SKumar Gala lis r11, PAGE_OFFSET@h 47614cf11afSPaul Mackerras cmplw r10, r11 47714cf11afSPaul Mackerras blt+ 3f 47814cf11afSPaul Mackerras lis r11, swapper_pg_dir@h 47914cf11afSPaul Mackerras ori r11, r11, swapper_pg_dir@l 48014cf11afSPaul Mackerras 48114cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 48214cf11afSPaul Mackerras rlwinm r12,r12,0,0,23 /* Clear TID */ 48314cf11afSPaul Mackerras 48414cf11afSPaul Mackerras b 4f 48514cf11afSPaul Mackerras 48614cf11afSPaul Mackerras /* Get the PGD for the current thread */ 48714cf11afSPaul Mackerras3: 48814cf11afSPaul Mackerras mfspr r11,SPRN_SPRG3 48914cf11afSPaul Mackerras lwz r11,PGDIR(r11) 49014cf11afSPaul Mackerras 49114cf11afSPaul Mackerras /* Load PID into MMUCR TID */ 49214cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 49314cf11afSPaul Mackerras mfspr r13,SPRN_PID /* Get PID */ 49414cf11afSPaul Mackerras rlwimi r12,r13,0,24,31 /* Set TID */ 49514cf11afSPaul Mackerras 49614cf11afSPaul Mackerras4: 49714cf11afSPaul Mackerras mtspr SPRN_MMUCR,r12 49814cf11afSPaul Mackerras 4991bc54c03SBenjamin Herrenschmidt /* Make up the required permissions */ 5001bc54c03SBenjamin Herrenschmidt li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_HWEXEC 5011bc54c03SBenjamin Herrenschmidt 502ca9153a3SIlya Yanok /* Compute pgdir/pmd offset */ 503ca9153a3SIlya Yanok rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 50414cf11afSPaul Mackerras lwzx r11, r12, r11 /* Get pgd/pmd entry */ 50514cf11afSPaul Mackerras rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ 50614cf11afSPaul Mackerras beq 2f /* Bail if no table */ 50714cf11afSPaul Mackerras 508ca9153a3SIlya Yanok /* Compute pte address */ 509ca9153a3SIlya Yanok rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 5101bc54c03SBenjamin Herrenschmidt lwz r11, 0(r12) /* Get high word of pte entry */ 5111bc54c03SBenjamin Herrenschmidt lwz r12, 4(r12) /* Get low word of pte entry */ 51214cf11afSPaul Mackerras 5131bc54c03SBenjamin Herrenschmidt lis r10,tlb_44x_index@ha 5141bc54c03SBenjamin Herrenschmidt 5151bc54c03SBenjamin Herrenschmidt andc. r13,r13,r12 /* Check permission */ 5161bc54c03SBenjamin Herrenschmidt 5171bc54c03SBenjamin Herrenschmidt /* Load the next available TLB index */ 5181bc54c03SBenjamin Herrenschmidt lwz r13,tlb_44x_index@l(r10) 5191bc54c03SBenjamin Herrenschmidt 5201bc54c03SBenjamin Herrenschmidt bne 2f /* Bail if permission mismach */ 5211bc54c03SBenjamin Herrenschmidt 5221bc54c03SBenjamin Herrenschmidt /* Increment, rollover, and store TLB index */ 5231bc54c03SBenjamin Herrenschmidt addi r13,r13,1 5241bc54c03SBenjamin Herrenschmidt 5251bc54c03SBenjamin Herrenschmidt /* Compare with watermark (instruction gets patched) */ 5261bc54c03SBenjamin Herrenschmidt .globl tlb_44x_patch_hwater_I 5271bc54c03SBenjamin Herrenschmidttlb_44x_patch_hwater_I: 5281bc54c03SBenjamin Herrenschmidt cmpwi 0,r13,1 /* reserve entries */ 5291bc54c03SBenjamin Herrenschmidt ble 5f 5301bc54c03SBenjamin Herrenschmidt li r13,0 5311bc54c03SBenjamin Herrenschmidt5: 5321bc54c03SBenjamin Herrenschmidt /* Store the next available TLB index */ 5331bc54c03SBenjamin Herrenschmidt stw r13,tlb_44x_index@l(r10) 5341bc54c03SBenjamin Herrenschmidt 5351bc54c03SBenjamin Herrenschmidt /* Re-load the faulting address */ 5361bc54c03SBenjamin Herrenschmidt mfspr r10,SPRN_SRR0 53714cf11afSPaul Mackerras 53814cf11afSPaul Mackerras /* Jump to common TLB load point */ 53914cf11afSPaul Mackerras b finish_tlb_load 54014cf11afSPaul Mackerras 54114cf11afSPaul Mackerras2: 54214cf11afSPaul Mackerras /* The bailout. Restore registers to pre-exception conditions 54314cf11afSPaul Mackerras * and call the heavyweights to help us out. 54414cf11afSPaul Mackerras */ 54514cf11afSPaul Mackerras mfspr r11, SPRN_SPRG7R 54614cf11afSPaul Mackerras mtcr r11 54714cf11afSPaul Mackerras mfspr r13, SPRN_SPRG5R 54814cf11afSPaul Mackerras mfspr r12, SPRN_SPRG4R 54914cf11afSPaul Mackerras mfspr r11, SPRN_SPRG1 55014cf11afSPaul Mackerras mfspr r10, SPRN_SPRG0 55114cf11afSPaul Mackerras b InstructionStorage 55214cf11afSPaul Mackerras 55314cf11afSPaul Mackerras /* Debug Interrupt */ 554eb0cd5fdSKumar Gala DEBUG_CRIT_EXCEPTION 55514cf11afSPaul Mackerras 55614cf11afSPaul Mackerras/* 55714cf11afSPaul Mackerras * Local functions 55814cf11afSPaul Mackerras */ 55914cf11afSPaul Mackerras 56014cf11afSPaul Mackerras/* 56114cf11afSPaul Mackerras 56214cf11afSPaul Mackerras * Both the instruction and data TLB miss get to this 56314cf11afSPaul Mackerras * point to load the TLB. 56414cf11afSPaul Mackerras * r10 - EA of fault 5651bc54c03SBenjamin Herrenschmidt * r11 - PTE high word value 5661bc54c03SBenjamin Herrenschmidt * r12 - PTE low word value 5671bc54c03SBenjamin Herrenschmidt * r13 - TLB index 56814cf11afSPaul Mackerras * MMUCR - loaded with proper value when we get here 56914cf11afSPaul Mackerras * Upon exit, we reload everything and RFI. 57014cf11afSPaul Mackerras */ 57114cf11afSPaul Mackerrasfinish_tlb_load: 5721bc54c03SBenjamin Herrenschmidt /* Combine RPN & ERPN an write WS 0 */ 573ca9153a3SIlya Yanok rlwimi r11,r12,0,0,31-PAGE_SHIFT 5741bc54c03SBenjamin Herrenschmidt tlbwe r11,r13,PPC44x_TLB_XLAT 57514cf11afSPaul Mackerras 57614cf11afSPaul Mackerras /* 5771bc54c03SBenjamin Herrenschmidt * Create WS1. This is the faulting address (EPN), 57814cf11afSPaul Mackerras * page size, and valid flag. 57914cf11afSPaul Mackerras */ 580ca9153a3SIlya Yanok li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE 581ca9153a3SIlya Yanok /* Insert valid and page size */ 582ca9153a3SIlya Yanok rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31 58314cf11afSPaul Mackerras tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */ 58414cf11afSPaul Mackerras 5851bc54c03SBenjamin Herrenschmidt /* And WS 2 */ 5861bc54c03SBenjamin Herrenschmidt li r10,0xf85 /* Mask to apply from PTE */ 5871bc54c03SBenjamin Herrenschmidt rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */ 5881bc54c03SBenjamin Herrenschmidt and r11,r12,r10 /* Mask PTE bits to keep */ 5891bc54c03SBenjamin Herrenschmidt andi. r10,r12,_PAGE_USER /* User page ? */ 5901bc54c03SBenjamin Herrenschmidt beq 1f /* nope, leave U bits empty */ 5911bc54c03SBenjamin Herrenschmidt rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ 5921bc54c03SBenjamin Herrenschmidt1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */ 59314cf11afSPaul Mackerras 59414cf11afSPaul Mackerras /* Done...restore registers and get out of here. 59514cf11afSPaul Mackerras */ 59614cf11afSPaul Mackerras mfspr r11, SPRN_SPRG7R 59714cf11afSPaul Mackerras mtcr r11 59814cf11afSPaul Mackerras mfspr r13, SPRN_SPRG5R 59914cf11afSPaul Mackerras mfspr r12, SPRN_SPRG4R 60014cf11afSPaul Mackerras mfspr r11, SPRN_SPRG1 60114cf11afSPaul Mackerras mfspr r10, SPRN_SPRG0 60214cf11afSPaul Mackerras rfi /* Force context change */ 60314cf11afSPaul Mackerras 60414cf11afSPaul Mackerras/* 60514cf11afSPaul Mackerras * Global functions 60614cf11afSPaul Mackerras */ 60714cf11afSPaul Mackerras 60814cf11afSPaul Mackerras/* 60947c0bd1aSBenjamin Herrenschmidt * Adjust the machine check IVOR on 440A cores 61047c0bd1aSBenjamin Herrenschmidt */ 61147c0bd1aSBenjamin Herrenschmidt_GLOBAL(__fixup_440A_mcheck) 61247c0bd1aSBenjamin Herrenschmidt li r3,MachineCheckA@l 61347c0bd1aSBenjamin Herrenschmidt mtspr SPRN_IVOR1,r3 61447c0bd1aSBenjamin Herrenschmidt sync 61547c0bd1aSBenjamin Herrenschmidt blr 61647c0bd1aSBenjamin Herrenschmidt 61747c0bd1aSBenjamin Herrenschmidt/* 61814cf11afSPaul Mackerras * extern void giveup_altivec(struct task_struct *prev) 61914cf11afSPaul Mackerras * 62014cf11afSPaul Mackerras * The 44x core does not have an AltiVec unit. 62114cf11afSPaul Mackerras */ 62214cf11afSPaul Mackerras_GLOBAL(giveup_altivec) 62314cf11afSPaul Mackerras blr 62414cf11afSPaul Mackerras 62514cf11afSPaul Mackerras/* 62614cf11afSPaul Mackerras * extern void giveup_fpu(struct task_struct *prev) 62714cf11afSPaul Mackerras * 62814cf11afSPaul Mackerras * The 44x core does not have an FPU. 62914cf11afSPaul Mackerras */ 63014cf11afSPaul Mackerras#ifndef CONFIG_PPC_FPU 63114cf11afSPaul Mackerras_GLOBAL(giveup_fpu) 63214cf11afSPaul Mackerras blr 63314cf11afSPaul Mackerras#endif 63414cf11afSPaul Mackerras 63514cf11afSPaul Mackerras_GLOBAL(set_context) 63614cf11afSPaul Mackerras 63714cf11afSPaul Mackerras#ifdef CONFIG_BDI_SWITCH 63814cf11afSPaul Mackerras /* Context switch the PTE pointer for the Abatron BDI2000. 63914cf11afSPaul Mackerras * The PGDIR is the second parameter. 64014cf11afSPaul Mackerras */ 64114cf11afSPaul Mackerras lis r5, abatron_pteptrs@h 64214cf11afSPaul Mackerras ori r5, r5, abatron_pteptrs@l 64314cf11afSPaul Mackerras stw r4, 0x4(r5) 64414cf11afSPaul Mackerras#endif 64514cf11afSPaul Mackerras mtspr SPRN_PID,r3 64614cf11afSPaul Mackerras isync /* Force context change */ 64714cf11afSPaul Mackerras blr 64814cf11afSPaul Mackerras 64914cf11afSPaul Mackerras/* 65014cf11afSPaul Mackerras * We put a few things here that have to be page-aligned. This stuff 65114cf11afSPaul Mackerras * goes at the beginning of the data segment, which is page-aligned. 65214cf11afSPaul Mackerras */ 65314cf11afSPaul Mackerras .data 654ca9153a3SIlya Yanok .align PAGE_SHIFT 655ea703ce2SKumar Gala .globl sdata 656ea703ce2SKumar Galasdata: 657ea703ce2SKumar Gala .globl empty_zero_page 658ea703ce2SKumar Galaempty_zero_page: 659ca9153a3SIlya Yanok .space PAGE_SIZE 66014cf11afSPaul Mackerras 66114cf11afSPaul Mackerras/* 66214cf11afSPaul Mackerras * To support >32-bit physical addresses, we use an 8KB pgdir. 66314cf11afSPaul Mackerras */ 664ea703ce2SKumar Gala .globl swapper_pg_dir 665ea703ce2SKumar Galaswapper_pg_dir: 666bee86f14SKumar Gala .space PGD_TABLE_SIZE 66714cf11afSPaul Mackerras 66814cf11afSPaul Mackerras/* 66914cf11afSPaul Mackerras * Room for two PTE pointers, usually the kernel and current user pointers 67014cf11afSPaul Mackerras * to their respective root page table. 67114cf11afSPaul Mackerras */ 67214cf11afSPaul Mackerrasabatron_pteptrs: 67314cf11afSPaul Mackerras .space 8 674