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 31e7039845STim 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> 4046f52210SStephen Rothwell#include <asm/ptrace.h> 41e7f75ad0SDave Kleikamp#include <asm/synch.h> 4214cf11afSPaul Mackerras#include "head_booke.h" 4314cf11afSPaul Mackerras 4414cf11afSPaul Mackerras 4514cf11afSPaul Mackerras/* As with the other PowerPC ports, it is expected that when code 4614cf11afSPaul Mackerras * execution begins here, the following registers contain valid, yet 4714cf11afSPaul Mackerras * optional, information: 4814cf11afSPaul Mackerras * 4914cf11afSPaul Mackerras * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.) 5014cf11afSPaul Mackerras * r4 - Starting address of the init RAM disk 5114cf11afSPaul Mackerras * r5 - Ending address of the init RAM disk 5214cf11afSPaul Mackerras * r6 - Start of kernel command line string (e.g. "mem=128") 5314cf11afSPaul Mackerras * r7 - End of kernel command line string 5414cf11afSPaul Mackerras * 5514cf11afSPaul Mackerras */ 56e7039845STim Abbott __HEAD 57748a7683SKumar Gala_ENTRY(_stext); 58748a7683SKumar Gala_ENTRY(_start); 5914cf11afSPaul Mackerras /* 6014cf11afSPaul Mackerras * Reserve a word at a fixed location to store the address 6114cf11afSPaul Mackerras * of abatron_pteptrs 6214cf11afSPaul Mackerras */ 6314cf11afSPaul Mackerras nop 646dece0ebSScott Wood mr r31,r3 /* save device tree ptr */ 6514cf11afSPaul Mackerras li r24,0 /* CPU number */ 6614cf11afSPaul Mackerras 67795033c3SDave Kleikamp bl init_cpu_state 6814cf11afSPaul Mackerras 6914cf11afSPaul Mackerras /* 7014cf11afSPaul Mackerras * This is where the main kernel code starts. 7114cf11afSPaul Mackerras */ 7214cf11afSPaul Mackerras 7314cf11afSPaul Mackerras /* ptr to current */ 7414cf11afSPaul Mackerras lis r2,init_task@h 7514cf11afSPaul Mackerras ori r2,r2,init_task@l 7614cf11afSPaul Mackerras 7714cf11afSPaul Mackerras /* ptr to current thread */ 7814cf11afSPaul Mackerras addi r4,r2,THREAD /* init task's THREAD */ 79ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_THREAD,r4 8014cf11afSPaul Mackerras 8114cf11afSPaul Mackerras /* stack */ 8214cf11afSPaul Mackerras lis r1,init_thread_union@h 8314cf11afSPaul Mackerras ori r1,r1,init_thread_union@l 8414cf11afSPaul Mackerras li r0,0 8514cf11afSPaul Mackerras stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1) 8614cf11afSPaul Mackerras 8714cf11afSPaul Mackerras bl early_init 8814cf11afSPaul Mackerras 89*0f890c8dSSuzuki Poulose#ifdef CONFIG_DYNAMIC_MEMSTART 909661534dSDave Kleikamp /* 91*0f890c8dSSuzuki Poulose * Mapping based, page aligned dynamic kernel loading. 92*0f890c8dSSuzuki Poulose * 939661534dSDave Kleikamp * r25 will contain RPN/ERPN for the start address of memory 949661534dSDave Kleikamp * 959661534dSDave Kleikamp * Add the difference between KERNELBASE and PAGE_OFFSET to the 969661534dSDave Kleikamp * start of physical memory to get kernstart_addr. 979661534dSDave Kleikamp */ 989661534dSDave Kleikamp lis r3,kernstart_addr@ha 999661534dSDave Kleikamp la r3,kernstart_addr@l(r3) 1009661534dSDave Kleikamp 1019661534dSDave Kleikamp lis r4,KERNELBASE@h 1029661534dSDave Kleikamp ori r4,r4,KERNELBASE@l 1039661534dSDave Kleikamp lis r5,PAGE_OFFSET@h 1049661534dSDave Kleikamp ori r5,r5,PAGE_OFFSET@l 1059661534dSDave Kleikamp subf r4,r5,r4 1069661534dSDave Kleikamp 1079661534dSDave Kleikamp rlwinm r6,r25,0,28,31 /* ERPN */ 1089661534dSDave Kleikamp rlwinm r7,r25,0,0,3 /* RPN - assuming 256 MB page size */ 1099661534dSDave Kleikamp add r7,r7,r4 1109661534dSDave Kleikamp 1119661534dSDave Kleikamp stw r6,0(r3) 1129661534dSDave Kleikamp stw r7,4(r3) 1139661534dSDave Kleikamp#endif 1149661534dSDave Kleikamp 11514cf11afSPaul Mackerras/* 11614cf11afSPaul Mackerras * Decide what sort of machine this is and initialize the MMU. 11714cf11afSPaul Mackerras */ 1186dece0ebSScott Wood li r3,0 1196dece0ebSScott Wood mr r4,r31 12014cf11afSPaul Mackerras bl machine_init 12114cf11afSPaul Mackerras bl MMU_init 12214cf11afSPaul Mackerras 12314cf11afSPaul Mackerras /* Setup PTE pointers for the Abatron bdiGDB */ 12414cf11afSPaul Mackerras lis r6, swapper_pg_dir@h 12514cf11afSPaul Mackerras ori r6, r6, swapper_pg_dir@l 12614cf11afSPaul Mackerras lis r5, abatron_pteptrs@h 12714cf11afSPaul Mackerras ori r5, r5, abatron_pteptrs@l 12814cf11afSPaul Mackerras lis r4, KERNELBASE@h 12914cf11afSPaul Mackerras ori r4, r4, KERNELBASE@l 13014cf11afSPaul Mackerras stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */ 13114cf11afSPaul Mackerras stw r6, 0(r5) 13214cf11afSPaul Mackerras 133029b8f66SDave Kleikamp /* Clear the Machine Check Syndrome Register */ 134029b8f66SDave Kleikamp li r0,0 135029b8f66SDave Kleikamp mtspr SPRN_MCSR,r0 136029b8f66SDave Kleikamp 13714cf11afSPaul Mackerras /* Let's move on */ 13814cf11afSPaul Mackerras lis r4,start_kernel@h 13914cf11afSPaul Mackerras ori r4,r4,start_kernel@l 14014cf11afSPaul Mackerras lis r3,MSR_KERNEL@h 14114cf11afSPaul Mackerras ori r3,r3,MSR_KERNEL@l 14214cf11afSPaul Mackerras mtspr SPRN_SRR0,r4 14314cf11afSPaul Mackerras mtspr SPRN_SRR1,r3 14414cf11afSPaul Mackerras rfi /* change context and jump to start_kernel */ 14514cf11afSPaul Mackerras 14614cf11afSPaul Mackerras/* 14714cf11afSPaul Mackerras * Interrupt vector entry code 14814cf11afSPaul Mackerras * 14914cf11afSPaul Mackerras * The Book E MMUs are always on so we don't need to handle 15014cf11afSPaul Mackerras * interrupts in real mode as with previous PPC processors. In 15114cf11afSPaul Mackerras * this case we handle interrupts in the kernel virtual address 15214cf11afSPaul Mackerras * space. 15314cf11afSPaul Mackerras * 15414cf11afSPaul Mackerras * Interrupt vectors are dynamically placed relative to the 15514cf11afSPaul Mackerras * interrupt prefix as determined by the address of interrupt_base. 15614cf11afSPaul Mackerras * The interrupt vectors offsets are programmed using the labels 15714cf11afSPaul Mackerras * for each interrupt vector entry. 15814cf11afSPaul Mackerras * 15914cf11afSPaul Mackerras * Interrupt vectors must be aligned on a 16 byte boundary. 16014cf11afSPaul Mackerras * We align on a 32 byte cache line boundary for good measure. 16114cf11afSPaul Mackerras */ 16214cf11afSPaul Mackerras 16314cf11afSPaul Mackerrasinterrupt_base: 16414cf11afSPaul Mackerras /* Critical Input Interrupt */ 165dc1c1ca3SStephen Rothwell CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception) 16614cf11afSPaul Mackerras 16714cf11afSPaul Mackerras /* Machine Check Interrupt */ 168dc1c1ca3SStephen Rothwell CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception) 16947c0bd1aSBenjamin Herrenschmidt MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception) 17014cf11afSPaul Mackerras 17114cf11afSPaul Mackerras /* Data Storage Interrupt */ 1721bc54c03SBenjamin Herrenschmidt DATA_STORAGE_EXCEPTION 17314cf11afSPaul Mackerras 17414cf11afSPaul Mackerras /* Instruction Storage Interrupt */ 17514cf11afSPaul Mackerras INSTRUCTION_STORAGE_EXCEPTION 17614cf11afSPaul Mackerras 17714cf11afSPaul Mackerras /* External Input Interrupt */ 17814cf11afSPaul Mackerras EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE) 17914cf11afSPaul Mackerras 18014cf11afSPaul Mackerras /* Alignment Interrupt */ 18114cf11afSPaul Mackerras ALIGNMENT_EXCEPTION 18214cf11afSPaul Mackerras 18314cf11afSPaul Mackerras /* Program Interrupt */ 18414cf11afSPaul Mackerras PROGRAM_EXCEPTION 18514cf11afSPaul Mackerras 18614cf11afSPaul Mackerras /* Floating Point Unavailable Interrupt */ 18714cf11afSPaul Mackerras#ifdef CONFIG_PPC_FPU 18814cf11afSPaul Mackerras FP_UNAVAILABLE_EXCEPTION 18914cf11afSPaul Mackerras#else 190dc1c1ca3SStephen Rothwell EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE) 19114cf11afSPaul Mackerras#endif 19214cf11afSPaul Mackerras /* System Call Interrupt */ 19314cf11afSPaul Mackerras START_EXCEPTION(SystemCall) 19414cf11afSPaul Mackerras NORMAL_EXCEPTION_PROLOG 19514cf11afSPaul Mackerras EXC_XFER_EE_LITE(0x0c00, DoSyscall) 19614cf11afSPaul Mackerras 19725985edcSLucas De Marchi /* Auxiliary Processor Unavailable Interrupt */ 198dc1c1ca3SStephen Rothwell EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE) 19914cf11afSPaul Mackerras 20014cf11afSPaul Mackerras /* Decrementer Interrupt */ 20114cf11afSPaul Mackerras DECREMENTER_EXCEPTION 20214cf11afSPaul Mackerras 20314cf11afSPaul Mackerras /* Fixed Internal Timer Interrupt */ 20414cf11afSPaul Mackerras /* TODO: Add FIT support */ 205dc1c1ca3SStephen Rothwell EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE) 20614cf11afSPaul Mackerras 20714cf11afSPaul Mackerras /* Watchdog Timer Interrupt */ 20814cf11afSPaul Mackerras /* TODO: Add watchdog support */ 20914cf11afSPaul Mackerras#ifdef CONFIG_BOOKE_WDT 21014cf11afSPaul Mackerras CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException) 21114cf11afSPaul Mackerras#else 212dc1c1ca3SStephen Rothwell CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception) 21314cf11afSPaul Mackerras#endif 21414cf11afSPaul Mackerras 21514cf11afSPaul Mackerras /* Data TLB Error Interrupt */ 216e7f75ad0SDave Kleikamp START_EXCEPTION(DataTLBError44x) 217ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */ 218ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH1, r11 219ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH2, r12 220ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH3, r13 22114cf11afSPaul Mackerras mfcr r11 222ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH4, r11 22314cf11afSPaul Mackerras mfspr r10, SPRN_DEAR /* Get faulting address */ 22414cf11afSPaul Mackerras 22514cf11afSPaul Mackerras /* If we are faulting a kernel address, we have to use the 22614cf11afSPaul Mackerras * kernel page tables. 22714cf11afSPaul Mackerras */ 2288a13c4f9SKumar Gala lis r11, PAGE_OFFSET@h 22914cf11afSPaul Mackerras cmplw r10, r11 23014cf11afSPaul Mackerras blt+ 3f 23114cf11afSPaul Mackerras lis r11, swapper_pg_dir@h 23214cf11afSPaul Mackerras ori r11, r11, swapper_pg_dir@l 23314cf11afSPaul Mackerras 23414cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 23514cf11afSPaul Mackerras rlwinm r12,r12,0,0,23 /* Clear TID */ 23614cf11afSPaul Mackerras 23714cf11afSPaul Mackerras b 4f 23814cf11afSPaul Mackerras 23914cf11afSPaul Mackerras /* Get the PGD for the current thread */ 24014cf11afSPaul Mackerras3: 241ee43eb78SBenjamin Herrenschmidt mfspr r11,SPRN_SPRG_THREAD 24214cf11afSPaul Mackerras lwz r11,PGDIR(r11) 24314cf11afSPaul Mackerras 24414cf11afSPaul Mackerras /* Load PID into MMUCR TID */ 24514cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 24614cf11afSPaul Mackerras mfspr r13,SPRN_PID /* Get PID */ 24714cf11afSPaul Mackerras rlwimi r12,r13,0,24,31 /* Set TID */ 24814cf11afSPaul Mackerras 24914cf11afSPaul Mackerras4: 25014cf11afSPaul Mackerras mtspr SPRN_MMUCR,r12 25114cf11afSPaul Mackerras 2521bc54c03SBenjamin Herrenschmidt /* Mask of required permission bits. Note that while we 2531bc54c03SBenjamin Herrenschmidt * do copy ESR:ST to _PAGE_RW position as trying to write 2541bc54c03SBenjamin Herrenschmidt * to an RO page is pretty common, we don't do it with 2551bc54c03SBenjamin Herrenschmidt * _PAGE_DIRTY. We could do it, but it's a fairly rare 2561bc54c03SBenjamin Herrenschmidt * event so I'd rather take the overhead when it happens 2571bc54c03SBenjamin Herrenschmidt * rather than adding an instruction here. We should measure 2581bc54c03SBenjamin Herrenschmidt * whether the whole thing is worth it in the first place 2591bc54c03SBenjamin Herrenschmidt * as we could avoid loading SPRN_ESR completely in the first 2601bc54c03SBenjamin Herrenschmidt * place... 2611bc54c03SBenjamin Herrenschmidt * 2621bc54c03SBenjamin Herrenschmidt * TODO: Is it worth doing that mfspr & rlwimi in the first 2631bc54c03SBenjamin Herrenschmidt * place or can we save a couple of instructions here ? 2641bc54c03SBenjamin Herrenschmidt */ 2651bc54c03SBenjamin Herrenschmidt mfspr r12,SPRN_ESR 2661bc54c03SBenjamin Herrenschmidt li r13,_PAGE_PRESENT|_PAGE_ACCESSED 2671bc54c03SBenjamin Herrenschmidt rlwimi r13,r12,10,30,30 2681bc54c03SBenjamin Herrenschmidt 2691bc54c03SBenjamin Herrenschmidt /* Load the PTE */ 270ca9153a3SIlya Yanok /* Compute pgdir/pmd offset */ 271ca9153a3SIlya Yanok rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 27214cf11afSPaul Mackerras lwzx r11, r12, r11 /* Get pgd/pmd entry */ 27314cf11afSPaul Mackerras rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ 27414cf11afSPaul Mackerras beq 2f /* Bail if no table */ 27514cf11afSPaul Mackerras 276ca9153a3SIlya Yanok /* Compute pte address */ 277ca9153a3SIlya Yanok rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 2781bc54c03SBenjamin Herrenschmidt lwz r11, 0(r12) /* Get high word of pte entry */ 2791bc54c03SBenjamin Herrenschmidt lwz r12, 4(r12) /* Get low word of pte entry */ 28014cf11afSPaul Mackerras 2811bc54c03SBenjamin Herrenschmidt lis r10,tlb_44x_index@ha 2821bc54c03SBenjamin Herrenschmidt 2831bc54c03SBenjamin Herrenschmidt andc. r13,r13,r12 /* Check permission */ 2841bc54c03SBenjamin Herrenschmidt 2851bc54c03SBenjamin Herrenschmidt /* Load the next available TLB index */ 2861bc54c03SBenjamin Herrenschmidt lwz r13,tlb_44x_index@l(r10) 2871bc54c03SBenjamin Herrenschmidt 2881bc54c03SBenjamin Herrenschmidt bne 2f /* Bail if permission mismach */ 2891bc54c03SBenjamin Herrenschmidt 2901bc54c03SBenjamin Herrenschmidt /* Increment, rollover, and store TLB index */ 2911bc54c03SBenjamin Herrenschmidt addi r13,r13,1 2921bc54c03SBenjamin Herrenschmidt 2931bc54c03SBenjamin Herrenschmidt /* Compare with watermark (instruction gets patched) */ 2941bc54c03SBenjamin Herrenschmidt .globl tlb_44x_patch_hwater_D 2951bc54c03SBenjamin Herrenschmidttlb_44x_patch_hwater_D: 2961bc54c03SBenjamin Herrenschmidt cmpwi 0,r13,1 /* reserve entries */ 2971bc54c03SBenjamin Herrenschmidt ble 5f 2981bc54c03SBenjamin Herrenschmidt li r13,0 2991bc54c03SBenjamin Herrenschmidt5: 3001bc54c03SBenjamin Herrenschmidt /* Store the next available TLB index */ 3011bc54c03SBenjamin Herrenschmidt stw r13,tlb_44x_index@l(r10) 3021bc54c03SBenjamin Herrenschmidt 3031bc54c03SBenjamin Herrenschmidt /* Re-load the faulting address */ 3041bc54c03SBenjamin Herrenschmidt mfspr r10,SPRN_DEAR 30514cf11afSPaul Mackerras 30614cf11afSPaul Mackerras /* Jump to common tlb load */ 307e7f75ad0SDave Kleikamp b finish_tlb_load_44x 30814cf11afSPaul Mackerras 30914cf11afSPaul Mackerras2: 31014cf11afSPaul Mackerras /* The bailout. Restore registers to pre-exception conditions 31114cf11afSPaul Mackerras * and call the heavyweights to help us out. 31214cf11afSPaul Mackerras */ 313ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH4 31414cf11afSPaul Mackerras mtcr r11 315ee43eb78SBenjamin Herrenschmidt mfspr r13, SPRN_SPRG_RSCRATCH3 316ee43eb78SBenjamin Herrenschmidt mfspr r12, SPRN_SPRG_RSCRATCH2 317ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH1 318ee43eb78SBenjamin Herrenschmidt mfspr r10, SPRN_SPRG_RSCRATCH0 3191bc54c03SBenjamin Herrenschmidt b DataStorage 32014cf11afSPaul Mackerras 32114cf11afSPaul Mackerras /* Instruction TLB Error Interrupt */ 32214cf11afSPaul Mackerras /* 32314cf11afSPaul Mackerras * Nearly the same as above, except we get our 32414cf11afSPaul Mackerras * information from different registers and bailout 32514cf11afSPaul Mackerras * to a different point. 32614cf11afSPaul Mackerras */ 327e7f75ad0SDave Kleikamp START_EXCEPTION(InstructionTLBError44x) 328ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */ 329ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH1, r11 330ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH2, r12 331ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH3, r13 33214cf11afSPaul Mackerras mfcr r11 333ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_WSCRATCH4, r11 33414cf11afSPaul Mackerras mfspr r10, SPRN_SRR0 /* Get faulting address */ 33514cf11afSPaul Mackerras 33614cf11afSPaul Mackerras /* If we are faulting a kernel address, we have to use the 33714cf11afSPaul Mackerras * kernel page tables. 33814cf11afSPaul Mackerras */ 3398a13c4f9SKumar Gala lis r11, PAGE_OFFSET@h 34014cf11afSPaul Mackerras cmplw r10, r11 34114cf11afSPaul Mackerras blt+ 3f 34214cf11afSPaul Mackerras lis r11, swapper_pg_dir@h 34314cf11afSPaul Mackerras ori r11, r11, swapper_pg_dir@l 34414cf11afSPaul Mackerras 34514cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 34614cf11afSPaul Mackerras rlwinm r12,r12,0,0,23 /* Clear TID */ 34714cf11afSPaul Mackerras 34814cf11afSPaul Mackerras b 4f 34914cf11afSPaul Mackerras 35014cf11afSPaul Mackerras /* Get the PGD for the current thread */ 35114cf11afSPaul Mackerras3: 352ee43eb78SBenjamin Herrenschmidt mfspr r11,SPRN_SPRG_THREAD 35314cf11afSPaul Mackerras lwz r11,PGDIR(r11) 35414cf11afSPaul Mackerras 35514cf11afSPaul Mackerras /* Load PID into MMUCR TID */ 35614cf11afSPaul Mackerras mfspr r12,SPRN_MMUCR 35714cf11afSPaul Mackerras mfspr r13,SPRN_PID /* Get PID */ 35814cf11afSPaul Mackerras rlwimi r12,r13,0,24,31 /* Set TID */ 35914cf11afSPaul Mackerras 36014cf11afSPaul Mackerras4: 36114cf11afSPaul Mackerras mtspr SPRN_MMUCR,r12 36214cf11afSPaul Mackerras 3631bc54c03SBenjamin Herrenschmidt /* Make up the required permissions */ 364ea3cc330SBenjamin Herrenschmidt li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC 3651bc54c03SBenjamin Herrenschmidt 366ca9153a3SIlya Yanok /* Compute pgdir/pmd offset */ 367ca9153a3SIlya Yanok rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29 36814cf11afSPaul Mackerras lwzx r11, r12, r11 /* Get pgd/pmd entry */ 36914cf11afSPaul Mackerras rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */ 37014cf11afSPaul Mackerras beq 2f /* Bail if no table */ 37114cf11afSPaul Mackerras 372ca9153a3SIlya Yanok /* Compute pte address */ 373ca9153a3SIlya Yanok rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28 3741bc54c03SBenjamin Herrenschmidt lwz r11, 0(r12) /* Get high word of pte entry */ 3751bc54c03SBenjamin Herrenschmidt lwz r12, 4(r12) /* Get low word of pte entry */ 37614cf11afSPaul Mackerras 3771bc54c03SBenjamin Herrenschmidt lis r10,tlb_44x_index@ha 3781bc54c03SBenjamin Herrenschmidt 3791bc54c03SBenjamin Herrenschmidt andc. r13,r13,r12 /* Check permission */ 3801bc54c03SBenjamin Herrenschmidt 3811bc54c03SBenjamin Herrenschmidt /* Load the next available TLB index */ 3821bc54c03SBenjamin Herrenschmidt lwz r13,tlb_44x_index@l(r10) 3831bc54c03SBenjamin Herrenschmidt 3841bc54c03SBenjamin Herrenschmidt bne 2f /* Bail if permission mismach */ 3851bc54c03SBenjamin Herrenschmidt 3861bc54c03SBenjamin Herrenschmidt /* Increment, rollover, and store TLB index */ 3871bc54c03SBenjamin Herrenschmidt addi r13,r13,1 3881bc54c03SBenjamin Herrenschmidt 3891bc54c03SBenjamin Herrenschmidt /* Compare with watermark (instruction gets patched) */ 3901bc54c03SBenjamin Herrenschmidt .globl tlb_44x_patch_hwater_I 3911bc54c03SBenjamin Herrenschmidttlb_44x_patch_hwater_I: 3921bc54c03SBenjamin Herrenschmidt cmpwi 0,r13,1 /* reserve entries */ 3931bc54c03SBenjamin Herrenschmidt ble 5f 3941bc54c03SBenjamin Herrenschmidt li r13,0 3951bc54c03SBenjamin Herrenschmidt5: 3961bc54c03SBenjamin Herrenschmidt /* Store the next available TLB index */ 3971bc54c03SBenjamin Herrenschmidt stw r13,tlb_44x_index@l(r10) 3981bc54c03SBenjamin Herrenschmidt 3991bc54c03SBenjamin Herrenschmidt /* Re-load the faulting address */ 4001bc54c03SBenjamin Herrenschmidt mfspr r10,SPRN_SRR0 40114cf11afSPaul Mackerras 40214cf11afSPaul Mackerras /* Jump to common TLB load point */ 403e7f75ad0SDave Kleikamp b finish_tlb_load_44x 40414cf11afSPaul Mackerras 40514cf11afSPaul Mackerras2: 40614cf11afSPaul Mackerras /* The bailout. Restore registers to pre-exception conditions 40714cf11afSPaul Mackerras * and call the heavyweights to help us out. 40814cf11afSPaul Mackerras */ 409ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH4 41014cf11afSPaul Mackerras mtcr r11 411ee43eb78SBenjamin Herrenschmidt mfspr r13, SPRN_SPRG_RSCRATCH3 412ee43eb78SBenjamin Herrenschmidt mfspr r12, SPRN_SPRG_RSCRATCH2 413ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH1 414ee43eb78SBenjamin Herrenschmidt mfspr r10, SPRN_SPRG_RSCRATCH0 41514cf11afSPaul Mackerras b InstructionStorage 41614cf11afSPaul Mackerras 41714cf11afSPaul Mackerras/* 41814cf11afSPaul Mackerras * Both the instruction and data TLB miss get to this 41914cf11afSPaul Mackerras * point to load the TLB. 42014cf11afSPaul Mackerras * r10 - EA of fault 4211bc54c03SBenjamin Herrenschmidt * r11 - PTE high word value 4221bc54c03SBenjamin Herrenschmidt * r12 - PTE low word value 4231bc54c03SBenjamin Herrenschmidt * r13 - TLB index 42414cf11afSPaul Mackerras * MMUCR - loaded with proper value when we get here 42514cf11afSPaul Mackerras * Upon exit, we reload everything and RFI. 42614cf11afSPaul Mackerras */ 427e7f75ad0SDave Kleikampfinish_tlb_load_44x: 4281bc54c03SBenjamin Herrenschmidt /* Combine RPN & ERPN an write WS 0 */ 429ca9153a3SIlya Yanok rlwimi r11,r12,0,0,31-PAGE_SHIFT 4301bc54c03SBenjamin Herrenschmidt tlbwe r11,r13,PPC44x_TLB_XLAT 43114cf11afSPaul Mackerras 43214cf11afSPaul Mackerras /* 4331bc54c03SBenjamin Herrenschmidt * Create WS1. This is the faulting address (EPN), 43414cf11afSPaul Mackerras * page size, and valid flag. 43514cf11afSPaul Mackerras */ 436ca9153a3SIlya Yanok li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE 437ca9153a3SIlya Yanok /* Insert valid and page size */ 438ca9153a3SIlya Yanok rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31 43914cf11afSPaul Mackerras tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */ 44014cf11afSPaul Mackerras 4411bc54c03SBenjamin Herrenschmidt /* And WS 2 */ 4421bc54c03SBenjamin Herrenschmidt li r10,0xf85 /* Mask to apply from PTE */ 4431bc54c03SBenjamin Herrenschmidt rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */ 4441bc54c03SBenjamin Herrenschmidt and r11,r12,r10 /* Mask PTE bits to keep */ 4451bc54c03SBenjamin Herrenschmidt andi. r10,r12,_PAGE_USER /* User page ? */ 4461bc54c03SBenjamin Herrenschmidt beq 1f /* nope, leave U bits empty */ 4471bc54c03SBenjamin Herrenschmidt rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ 4481bc54c03SBenjamin Herrenschmidt1: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */ 44914cf11afSPaul Mackerras 45014cf11afSPaul Mackerras /* Done...restore registers and get out of here. 45114cf11afSPaul Mackerras */ 452ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH4 45314cf11afSPaul Mackerras mtcr r11 454ee43eb78SBenjamin Herrenschmidt mfspr r13, SPRN_SPRG_RSCRATCH3 455ee43eb78SBenjamin Herrenschmidt mfspr r12, SPRN_SPRG_RSCRATCH2 456ee43eb78SBenjamin Herrenschmidt mfspr r11, SPRN_SPRG_RSCRATCH1 457ee43eb78SBenjamin Herrenschmidt mfspr r10, SPRN_SPRG_RSCRATCH0 45814cf11afSPaul Mackerras rfi /* Force context change */ 45914cf11afSPaul Mackerras 460e7f75ad0SDave Kleikamp/* TLB error interrupts for 476 461e7f75ad0SDave Kleikamp */ 462e7f75ad0SDave Kleikamp#ifdef CONFIG_PPC_47x 463e7f75ad0SDave Kleikamp START_EXCEPTION(DataTLBError47x) 464e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */ 465e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH1,r11 466e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH2,r12 467e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH3,r13 468e7f75ad0SDave Kleikamp mfcr r11 469e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH4,r11 470e7f75ad0SDave Kleikamp mfspr r10,SPRN_DEAR /* Get faulting address */ 471e7f75ad0SDave Kleikamp 472e7f75ad0SDave Kleikamp /* If we are faulting a kernel address, we have to use the 473e7f75ad0SDave Kleikamp * kernel page tables. 474e7f75ad0SDave Kleikamp */ 475e7f75ad0SDave Kleikamp lis r11,PAGE_OFFSET@h 476e7f75ad0SDave Kleikamp cmplw cr0,r10,r11 477e7f75ad0SDave Kleikamp blt+ 3f 478e7f75ad0SDave Kleikamp lis r11,swapper_pg_dir@h 479e7f75ad0SDave Kleikamp ori r11,r11, swapper_pg_dir@l 480e7f75ad0SDave Kleikamp li r12,0 /* MMUCR = 0 */ 481e7f75ad0SDave Kleikamp b 4f 482e7f75ad0SDave Kleikamp 483e7f75ad0SDave Kleikamp /* Get the PGD for the current thread and setup MMUCR */ 484e7f75ad0SDave Kleikamp3: mfspr r11,SPRN_SPRG3 485e7f75ad0SDave Kleikamp lwz r11,PGDIR(r11) 486e7f75ad0SDave Kleikamp mfspr r12,SPRN_PID /* Get PID */ 487e7f75ad0SDave Kleikamp4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */ 488e7f75ad0SDave Kleikamp 489e7f75ad0SDave Kleikamp /* Mask of required permission bits. Note that while we 490e7f75ad0SDave Kleikamp * do copy ESR:ST to _PAGE_RW position as trying to write 491e7f75ad0SDave Kleikamp * to an RO page is pretty common, we don't do it with 492e7f75ad0SDave Kleikamp * _PAGE_DIRTY. We could do it, but it's a fairly rare 493e7f75ad0SDave Kleikamp * event so I'd rather take the overhead when it happens 494e7f75ad0SDave Kleikamp * rather than adding an instruction here. We should measure 495e7f75ad0SDave Kleikamp * whether the whole thing is worth it in the first place 496e7f75ad0SDave Kleikamp * as we could avoid loading SPRN_ESR completely in the first 497e7f75ad0SDave Kleikamp * place... 498e7f75ad0SDave Kleikamp * 499e7f75ad0SDave Kleikamp * TODO: Is it worth doing that mfspr & rlwimi in the first 500e7f75ad0SDave Kleikamp * place or can we save a couple of instructions here ? 501e7f75ad0SDave Kleikamp */ 502e7f75ad0SDave Kleikamp mfspr r12,SPRN_ESR 503e7f75ad0SDave Kleikamp li r13,_PAGE_PRESENT|_PAGE_ACCESSED 504e7f75ad0SDave Kleikamp rlwimi r13,r12,10,30,30 505e7f75ad0SDave Kleikamp 506e7f75ad0SDave Kleikamp /* Load the PTE */ 507e7f75ad0SDave Kleikamp /* Compute pgdir/pmd offset */ 508e7f75ad0SDave Kleikamp rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29 509e7f75ad0SDave Kleikamp lwzx r11,r12,r11 /* Get pgd/pmd entry */ 510e7f75ad0SDave Kleikamp 511e7f75ad0SDave Kleikamp /* Word 0 is EPN,V,TS,DSIZ */ 512e7f75ad0SDave Kleikamp li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE 513e7f75ad0SDave Kleikamp rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/ 514e7f75ad0SDave Kleikamp li r12,0 515e7f75ad0SDave Kleikamp tlbwe r10,r12,0 516e7f75ad0SDave Kleikamp 517e7f75ad0SDave Kleikamp /* XXX can we do better ? Need to make sure tlbwe has established 518e7f75ad0SDave Kleikamp * latch V bit in MMUCR0 before the PTE is loaded further down */ 519e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 520e7f75ad0SDave Kleikamp isync 521e7f75ad0SDave Kleikamp#endif 522e7f75ad0SDave Kleikamp 523e7f75ad0SDave Kleikamp rlwinm. r12,r11,0,0,20 /* Extract pt base address */ 524e7f75ad0SDave Kleikamp /* Compute pte address */ 525e7f75ad0SDave Kleikamp rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28 526e7f75ad0SDave Kleikamp beq 2f /* Bail if no table */ 527e7f75ad0SDave Kleikamp lwz r11,0(r12) /* Get high word of pte entry */ 528e7f75ad0SDave Kleikamp 529e7f75ad0SDave Kleikamp /* XXX can we do better ? maybe insert a known 0 bit from r11 into the 530e7f75ad0SDave Kleikamp * bottom of r12 to create a data dependency... We can also use r10 531e7f75ad0SDave Kleikamp * as destination nowadays 532e7f75ad0SDave Kleikamp */ 533e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 534e7f75ad0SDave Kleikamp lwsync 535e7f75ad0SDave Kleikamp#endif 536e7f75ad0SDave Kleikamp lwz r12,4(r12) /* Get low word of pte entry */ 537e7f75ad0SDave Kleikamp 538e7f75ad0SDave Kleikamp andc. r13,r13,r12 /* Check permission */ 539e7f75ad0SDave Kleikamp 540e7f75ad0SDave Kleikamp /* Jump to common tlb load */ 541e7f75ad0SDave Kleikamp beq finish_tlb_load_47x 542e7f75ad0SDave Kleikamp 543e7f75ad0SDave Kleikamp2: /* The bailout. Restore registers to pre-exception conditions 544e7f75ad0SDave Kleikamp * and call the heavyweights to help us out. 545e7f75ad0SDave Kleikamp */ 546e7f75ad0SDave Kleikamp mfspr r11,SPRN_SPRG_RSCRATCH4 547e7f75ad0SDave Kleikamp mtcr r11 548e7f75ad0SDave Kleikamp mfspr r13,SPRN_SPRG_RSCRATCH3 549e7f75ad0SDave Kleikamp mfspr r12,SPRN_SPRG_RSCRATCH2 550e7f75ad0SDave Kleikamp mfspr r11,SPRN_SPRG_RSCRATCH1 551e7f75ad0SDave Kleikamp mfspr r10,SPRN_SPRG_RSCRATCH0 552e7f75ad0SDave Kleikamp b DataStorage 553e7f75ad0SDave Kleikamp 554e7f75ad0SDave Kleikamp /* Instruction TLB Error Interrupt */ 555e7f75ad0SDave Kleikamp /* 556e7f75ad0SDave Kleikamp * Nearly the same as above, except we get our 557e7f75ad0SDave Kleikamp * information from different registers and bailout 558e7f75ad0SDave Kleikamp * to a different point. 559e7f75ad0SDave Kleikamp */ 560e7f75ad0SDave Kleikamp START_EXCEPTION(InstructionTLBError47x) 561e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */ 562e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH1,r11 563e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH2,r12 564e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH3,r13 565e7f75ad0SDave Kleikamp mfcr r11 566e7f75ad0SDave Kleikamp mtspr SPRN_SPRG_WSCRATCH4,r11 567e7f75ad0SDave Kleikamp mfspr r10,SPRN_SRR0 /* Get faulting address */ 568e7f75ad0SDave Kleikamp 569e7f75ad0SDave Kleikamp /* If we are faulting a kernel address, we have to use the 570e7f75ad0SDave Kleikamp * kernel page tables. 571e7f75ad0SDave Kleikamp */ 572e7f75ad0SDave Kleikamp lis r11,PAGE_OFFSET@h 573e7f75ad0SDave Kleikamp cmplw cr0,r10,r11 574e7f75ad0SDave Kleikamp blt+ 3f 575e7f75ad0SDave Kleikamp lis r11,swapper_pg_dir@h 576e7f75ad0SDave Kleikamp ori r11,r11, swapper_pg_dir@l 577e7f75ad0SDave Kleikamp li r12,0 /* MMUCR = 0 */ 578e7f75ad0SDave Kleikamp b 4f 579e7f75ad0SDave Kleikamp 580e7f75ad0SDave Kleikamp /* Get the PGD for the current thread and setup MMUCR */ 581e7f75ad0SDave Kleikamp3: mfspr r11,SPRN_SPRG_THREAD 582e7f75ad0SDave Kleikamp lwz r11,PGDIR(r11) 583e7f75ad0SDave Kleikamp mfspr r12,SPRN_PID /* Get PID */ 584e7f75ad0SDave Kleikamp4: mtspr SPRN_MMUCR,r12 /* Set MMUCR */ 585e7f75ad0SDave Kleikamp 586e7f75ad0SDave Kleikamp /* Make up the required permissions */ 587e7f75ad0SDave Kleikamp li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC 588e7f75ad0SDave Kleikamp 589e7f75ad0SDave Kleikamp /* Load PTE */ 590e7f75ad0SDave Kleikamp /* Compute pgdir/pmd offset */ 591e7f75ad0SDave Kleikamp rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29 592e7f75ad0SDave Kleikamp lwzx r11,r12,r11 /* Get pgd/pmd entry */ 593e7f75ad0SDave Kleikamp 594e7f75ad0SDave Kleikamp /* Word 0 is EPN,V,TS,DSIZ */ 595e7f75ad0SDave Kleikamp li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE 596e7f75ad0SDave Kleikamp rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/ 597e7f75ad0SDave Kleikamp li r12,0 598e7f75ad0SDave Kleikamp tlbwe r10,r12,0 599e7f75ad0SDave Kleikamp 600e7f75ad0SDave Kleikamp /* XXX can we do better ? Need to make sure tlbwe has established 601e7f75ad0SDave Kleikamp * latch V bit in MMUCR0 before the PTE is loaded further down */ 602e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 603e7f75ad0SDave Kleikamp isync 604e7f75ad0SDave Kleikamp#endif 605e7f75ad0SDave Kleikamp 606e7f75ad0SDave Kleikamp rlwinm. r12,r11,0,0,20 /* Extract pt base address */ 607e7f75ad0SDave Kleikamp /* Compute pte address */ 608e7f75ad0SDave Kleikamp rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28 609e7f75ad0SDave Kleikamp beq 2f /* Bail if no table */ 610e7f75ad0SDave Kleikamp 611e7f75ad0SDave Kleikamp lwz r11,0(r12) /* Get high word of pte entry */ 612e7f75ad0SDave Kleikamp /* XXX can we do better ? maybe insert a known 0 bit from r11 into the 613e7f75ad0SDave Kleikamp * bottom of r12 to create a data dependency... We can also use r10 614e7f75ad0SDave Kleikamp * as destination nowadays 615e7f75ad0SDave Kleikamp */ 616e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 617e7f75ad0SDave Kleikamp lwsync 618e7f75ad0SDave Kleikamp#endif 619e7f75ad0SDave Kleikamp lwz r12,4(r12) /* Get low word of pte entry */ 620e7f75ad0SDave Kleikamp 621e7f75ad0SDave Kleikamp andc. r13,r13,r12 /* Check permission */ 622e7f75ad0SDave Kleikamp 623e7f75ad0SDave Kleikamp /* Jump to common TLB load point */ 624e7f75ad0SDave Kleikamp beq finish_tlb_load_47x 625e7f75ad0SDave Kleikamp 626e7f75ad0SDave Kleikamp2: /* The bailout. Restore registers to pre-exception conditions 627e7f75ad0SDave Kleikamp * and call the heavyweights to help us out. 628e7f75ad0SDave Kleikamp */ 629e7f75ad0SDave Kleikamp mfspr r11, SPRN_SPRG_RSCRATCH4 630e7f75ad0SDave Kleikamp mtcr r11 631e7f75ad0SDave Kleikamp mfspr r13, SPRN_SPRG_RSCRATCH3 632e7f75ad0SDave Kleikamp mfspr r12, SPRN_SPRG_RSCRATCH2 633e7f75ad0SDave Kleikamp mfspr r11, SPRN_SPRG_RSCRATCH1 634e7f75ad0SDave Kleikamp mfspr r10, SPRN_SPRG_RSCRATCH0 635e7f75ad0SDave Kleikamp b InstructionStorage 636e7f75ad0SDave Kleikamp 637e7f75ad0SDave Kleikamp/* 638e7f75ad0SDave Kleikamp * Both the instruction and data TLB miss get to this 639e7f75ad0SDave Kleikamp * point to load the TLB. 640e7f75ad0SDave Kleikamp * r10 - free to use 641e7f75ad0SDave Kleikamp * r11 - PTE high word value 642e7f75ad0SDave Kleikamp * r12 - PTE low word value 643e7f75ad0SDave Kleikamp * r13 - free to use 644e7f75ad0SDave Kleikamp * MMUCR - loaded with proper value when we get here 645e7f75ad0SDave Kleikamp * Upon exit, we reload everything and RFI. 646e7f75ad0SDave Kleikamp */ 647e7f75ad0SDave Kleikampfinish_tlb_load_47x: 648e7f75ad0SDave Kleikamp /* Combine RPN & ERPN an write WS 1 */ 649e7f75ad0SDave Kleikamp rlwimi r11,r12,0,0,31-PAGE_SHIFT 650e7f75ad0SDave Kleikamp tlbwe r11,r13,1 651e7f75ad0SDave Kleikamp 652e7f75ad0SDave Kleikamp /* And make up word 2 */ 653e7f75ad0SDave Kleikamp li r10,0xf85 /* Mask to apply from PTE */ 654e7f75ad0SDave Kleikamp rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */ 655e7f75ad0SDave Kleikamp and r11,r12,r10 /* Mask PTE bits to keep */ 656e7f75ad0SDave Kleikamp andi. r10,r12,_PAGE_USER /* User page ? */ 657e7f75ad0SDave Kleikamp beq 1f /* nope, leave U bits empty */ 658e7f75ad0SDave Kleikamp rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */ 659e7f75ad0SDave Kleikamp1: tlbwe r11,r13,2 660e7f75ad0SDave Kleikamp 661e7f75ad0SDave Kleikamp /* Done...restore registers and get out of here. 662e7f75ad0SDave Kleikamp */ 663e7f75ad0SDave Kleikamp mfspr r11, SPRN_SPRG_RSCRATCH4 664e7f75ad0SDave Kleikamp mtcr r11 665e7f75ad0SDave Kleikamp mfspr r13, SPRN_SPRG_RSCRATCH3 666e7f75ad0SDave Kleikamp mfspr r12, SPRN_SPRG_RSCRATCH2 667e7f75ad0SDave Kleikamp mfspr r11, SPRN_SPRG_RSCRATCH1 668e7f75ad0SDave Kleikamp mfspr r10, SPRN_SPRG_RSCRATCH0 669e7f75ad0SDave Kleikamp rfi 670e7f75ad0SDave Kleikamp 671e7f75ad0SDave Kleikamp#endif /* CONFIG_PPC_47x */ 672e7f75ad0SDave Kleikamp 673e7f75ad0SDave Kleikamp /* Debug Interrupt */ 674e7f75ad0SDave Kleikamp /* 675e7f75ad0SDave Kleikamp * This statement needs to exist at the end of the IVPR 676e7f75ad0SDave Kleikamp * definition just in case you end up taking a debug 677e7f75ad0SDave Kleikamp * exception within another exception. 678e7f75ad0SDave Kleikamp */ 679e7f75ad0SDave Kleikamp DEBUG_CRIT_EXCEPTION 680e7f75ad0SDave Kleikamp 68114cf11afSPaul Mackerras/* 68214cf11afSPaul Mackerras * Global functions 68314cf11afSPaul Mackerras */ 68414cf11afSPaul Mackerras 68514cf11afSPaul Mackerras/* 68647c0bd1aSBenjamin Herrenschmidt * Adjust the machine check IVOR on 440A cores 68747c0bd1aSBenjamin Herrenschmidt */ 68847c0bd1aSBenjamin Herrenschmidt_GLOBAL(__fixup_440A_mcheck) 68947c0bd1aSBenjamin Herrenschmidt li r3,MachineCheckA@l 69047c0bd1aSBenjamin Herrenschmidt mtspr SPRN_IVOR1,r3 69147c0bd1aSBenjamin Herrenschmidt sync 69247c0bd1aSBenjamin Herrenschmidt blr 69347c0bd1aSBenjamin Herrenschmidt 69447c0bd1aSBenjamin Herrenschmidt/* 69514cf11afSPaul Mackerras * extern void giveup_altivec(struct task_struct *prev) 69614cf11afSPaul Mackerras * 69714cf11afSPaul Mackerras * The 44x core does not have an AltiVec unit. 69814cf11afSPaul Mackerras */ 69914cf11afSPaul Mackerras_GLOBAL(giveup_altivec) 70014cf11afSPaul Mackerras blr 70114cf11afSPaul Mackerras 70214cf11afSPaul Mackerras/* 70314cf11afSPaul Mackerras * extern void giveup_fpu(struct task_struct *prev) 70414cf11afSPaul Mackerras * 70514cf11afSPaul Mackerras * The 44x core does not have an FPU. 70614cf11afSPaul Mackerras */ 70714cf11afSPaul Mackerras#ifndef CONFIG_PPC_FPU 70814cf11afSPaul Mackerras_GLOBAL(giveup_fpu) 70914cf11afSPaul Mackerras blr 71014cf11afSPaul Mackerras#endif 71114cf11afSPaul Mackerras 71214cf11afSPaul Mackerras_GLOBAL(set_context) 71314cf11afSPaul Mackerras 71414cf11afSPaul Mackerras#ifdef CONFIG_BDI_SWITCH 71514cf11afSPaul Mackerras /* Context switch the PTE pointer for the Abatron BDI2000. 71614cf11afSPaul Mackerras * The PGDIR is the second parameter. 71714cf11afSPaul Mackerras */ 71814cf11afSPaul Mackerras lis r5, abatron_pteptrs@h 71914cf11afSPaul Mackerras ori r5, r5, abatron_pteptrs@l 72014cf11afSPaul Mackerras stw r4, 0x4(r5) 72114cf11afSPaul Mackerras#endif 72214cf11afSPaul Mackerras mtspr SPRN_PID,r3 72314cf11afSPaul Mackerras isync /* Force context change */ 72414cf11afSPaul Mackerras blr 72514cf11afSPaul Mackerras 72614cf11afSPaul Mackerras/* 727795033c3SDave Kleikamp * Init CPU state. This is called at boot time or for secondary CPUs 728795033c3SDave Kleikamp * to setup initial TLB entries, setup IVORs, etc... 729e7f75ad0SDave Kleikamp * 730795033c3SDave Kleikamp */ 731795033c3SDave Kleikamp_GLOBAL(init_cpu_state) 732795033c3SDave Kleikamp mflr r22 733e7f75ad0SDave Kleikamp#ifdef CONFIG_PPC_47x 734e7f75ad0SDave Kleikamp /* We use the PVR to differenciate 44x cores from 476 */ 735e7f75ad0SDave Kleikamp mfspr r3,SPRN_PVR 736e7f75ad0SDave Kleikamp srwi r3,r3,16 737df777bd3STony Breeds cmplwi cr0,r3,PVR_476FPE@h 738df777bd3STony Breeds beq head_start_47x 739e7f75ad0SDave Kleikamp cmplwi cr0,r3,PVR_476@h 740e7f75ad0SDave Kleikamp beq head_start_47x 741b4e8c8ddSTorez Smith cmplwi cr0,r3,PVR_476_ISS@h 742b4e8c8ddSTorez Smith beq head_start_47x 743e7f75ad0SDave Kleikamp#endif /* CONFIG_PPC_47x */ 744e7f75ad0SDave Kleikamp 745795033c3SDave Kleikamp/* 746795033c3SDave Kleikamp * In case the firmware didn't do it, we apply some workarounds 747795033c3SDave Kleikamp * that are good for all 440 core variants here 748795033c3SDave Kleikamp */ 749795033c3SDave Kleikamp mfspr r3,SPRN_CCR0 750795033c3SDave Kleikamp rlwinm r3,r3,0,0,27 /* disable icache prefetch */ 751795033c3SDave Kleikamp isync 752795033c3SDave Kleikamp mtspr SPRN_CCR0,r3 753795033c3SDave Kleikamp isync 754795033c3SDave Kleikamp sync 755795033c3SDave Kleikamp 756795033c3SDave Kleikamp/* 757e7f75ad0SDave Kleikamp * Set up the initial MMU state for 44x 758795033c3SDave Kleikamp * 759795033c3SDave Kleikamp * We are still executing code at the virtual address 760795033c3SDave Kleikamp * mappings set by the firmware for the base of RAM. 761795033c3SDave Kleikamp * 762795033c3SDave Kleikamp * We first invalidate all TLB entries but the one 763795033c3SDave Kleikamp * we are running from. We then load the KERNELBASE 764795033c3SDave Kleikamp * mappings so we can begin to use kernel addresses 765795033c3SDave Kleikamp * natively and so the interrupt vector locations are 766795033c3SDave Kleikamp * permanently pinned (necessary since Book E 767795033c3SDave Kleikamp * implementations always have translation enabled). 768795033c3SDave Kleikamp * 769795033c3SDave Kleikamp * TODO: Use the known TLB entry we are running from to 770795033c3SDave Kleikamp * determine which physical region we are located 771795033c3SDave Kleikamp * in. This can be used to determine where in RAM 772795033c3SDave Kleikamp * (on a shared CPU system) or PCI memory space 773795033c3SDave Kleikamp * (on a DRAMless system) we are located. 774795033c3SDave Kleikamp * For now, we assume a perfect world which means 775795033c3SDave Kleikamp * we are located at the base of DRAM (physical 0). 776795033c3SDave Kleikamp */ 777795033c3SDave Kleikamp 778795033c3SDave Kleikamp/* 779795033c3SDave Kleikamp * Search TLB for entry that we are currently using. 780795033c3SDave Kleikamp * Invalidate all entries but the one we are using. 781795033c3SDave Kleikamp */ 782795033c3SDave Kleikamp /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ 783795033c3SDave Kleikamp mfspr r3,SPRN_PID /* Get PID */ 784795033c3SDave Kleikamp mfmsr r4 /* Get MSR */ 785795033c3SDave Kleikamp andi. r4,r4,MSR_IS@l /* TS=1? */ 786795033c3SDave Kleikamp beq wmmucr /* If not, leave STS=0 */ 787795033c3SDave Kleikamp oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */ 788795033c3SDave Kleikampwmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ 789795033c3SDave Kleikamp sync 790795033c3SDave Kleikamp 791795033c3SDave Kleikamp bl invstr /* Find our address */ 792795033c3SDave Kleikampinvstr: mflr r5 /* Make it accessible */ 793795033c3SDave Kleikamp tlbsx r23,0,r5 /* Find entry we are in */ 794795033c3SDave Kleikamp li r4,0 /* Start at TLB entry 0 */ 795795033c3SDave Kleikamp li r3,0 /* Set PAGEID inval value */ 796795033c3SDave Kleikamp1: cmpw r23,r4 /* Is this our entry? */ 797795033c3SDave Kleikamp beq skpinv /* If so, skip the inval */ 798795033c3SDave Kleikamp tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */ 799795033c3SDave Kleikampskpinv: addi r4,r4,1 /* Increment */ 800795033c3SDave Kleikamp cmpwi r4,64 /* Are we done? */ 801795033c3SDave Kleikamp bne 1b /* If not, repeat */ 802795033c3SDave Kleikamp isync /* If so, context change */ 803795033c3SDave Kleikamp 804795033c3SDave Kleikamp/* 805795033c3SDave Kleikamp * Configure and load pinned entry into TLB slot 63. 806795033c3SDave Kleikamp */ 807795033c3SDave Kleikamp 808795033c3SDave Kleikamp lis r3,PAGE_OFFSET@h 809795033c3SDave Kleikamp ori r3,r3,PAGE_OFFSET@l 810795033c3SDave Kleikamp 811795033c3SDave Kleikamp /* Kernel is at the base of RAM */ 812795033c3SDave Kleikamp li r4, 0 /* Load the kernel physical address */ 813795033c3SDave Kleikamp 814795033c3SDave Kleikamp /* Load the kernel PID = 0 */ 815795033c3SDave Kleikamp li r0,0 816795033c3SDave Kleikamp mtspr SPRN_PID,r0 817795033c3SDave Kleikamp sync 818795033c3SDave Kleikamp 819795033c3SDave Kleikamp /* Initialize MMUCR */ 820795033c3SDave Kleikamp li r5,0 821795033c3SDave Kleikamp mtspr SPRN_MMUCR,r5 822795033c3SDave Kleikamp sync 823795033c3SDave Kleikamp 824795033c3SDave Kleikamp /* pageid fields */ 825795033c3SDave Kleikamp clrrwi r3,r3,10 /* Mask off the effective page number */ 826795033c3SDave Kleikamp ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M 827795033c3SDave Kleikamp 828795033c3SDave Kleikamp /* xlat fields */ 829795033c3SDave Kleikamp clrrwi r4,r4,10 /* Mask off the real page number */ 830795033c3SDave Kleikamp /* ERPN is 0 for first 4GB page */ 831795033c3SDave Kleikamp 832795033c3SDave Kleikamp /* attrib fields */ 833795033c3SDave Kleikamp /* Added guarded bit to protect against speculative loads/stores */ 834795033c3SDave Kleikamp li r5,0 835795033c3SDave Kleikamp ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G) 836795033c3SDave Kleikamp 837795033c3SDave Kleikamp li r0,63 /* TLB slot 63 */ 838795033c3SDave Kleikamp 839795033c3SDave Kleikamp tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */ 840795033c3SDave Kleikamp tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */ 841795033c3SDave Kleikamp tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */ 842795033c3SDave Kleikamp 843795033c3SDave Kleikamp /* Force context change */ 844795033c3SDave Kleikamp mfmsr r0 845795033c3SDave Kleikamp mtspr SPRN_SRR1, r0 846795033c3SDave Kleikamp lis r0,3f@h 847795033c3SDave Kleikamp ori r0,r0,3f@l 848795033c3SDave Kleikamp mtspr SPRN_SRR0,r0 849795033c3SDave Kleikamp sync 850795033c3SDave Kleikamp rfi 851795033c3SDave Kleikamp 852795033c3SDave Kleikamp /* If necessary, invalidate original entry we used */ 853795033c3SDave Kleikamp3: cmpwi r23,63 854795033c3SDave Kleikamp beq 4f 855795033c3SDave Kleikamp li r6,0 856795033c3SDave Kleikamp tlbwe r6,r23,PPC44x_TLB_PAGEID 857795033c3SDave Kleikamp isync 858795033c3SDave Kleikamp 859795033c3SDave Kleikamp4: 860795033c3SDave Kleikamp#ifdef CONFIG_PPC_EARLY_DEBUG_44x 861795033c3SDave Kleikamp /* Add UART mapping for early debug. */ 862795033c3SDave Kleikamp 863795033c3SDave Kleikamp /* pageid fields */ 864795033c3SDave Kleikamp lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h 865795033c3SDave Kleikamp ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K 866795033c3SDave Kleikamp 867795033c3SDave Kleikamp /* xlat fields */ 868795033c3SDave Kleikamp lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h 869795033c3SDave Kleikamp ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH 870795033c3SDave Kleikamp 871795033c3SDave Kleikamp /* attrib fields */ 872795033c3SDave Kleikamp li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G) 873795033c3SDave Kleikamp li r0,62 /* TLB slot 0 */ 874795033c3SDave Kleikamp 875795033c3SDave Kleikamp tlbwe r3,r0,PPC44x_TLB_PAGEID 876795033c3SDave Kleikamp tlbwe r4,r0,PPC44x_TLB_XLAT 877795033c3SDave Kleikamp tlbwe r5,r0,PPC44x_TLB_ATTRIB 878795033c3SDave Kleikamp 879795033c3SDave Kleikamp /* Force context change */ 880795033c3SDave Kleikamp isync 881795033c3SDave Kleikamp#endif /* CONFIG_PPC_EARLY_DEBUG_44x */ 882795033c3SDave Kleikamp 883795033c3SDave Kleikamp /* Establish the interrupt vector offsets */ 884795033c3SDave Kleikamp SET_IVOR(0, CriticalInput); 885795033c3SDave Kleikamp SET_IVOR(1, MachineCheck); 886795033c3SDave Kleikamp SET_IVOR(2, DataStorage); 887795033c3SDave Kleikamp SET_IVOR(3, InstructionStorage); 888795033c3SDave Kleikamp SET_IVOR(4, ExternalInput); 889795033c3SDave Kleikamp SET_IVOR(5, Alignment); 890795033c3SDave Kleikamp SET_IVOR(6, Program); 891795033c3SDave Kleikamp SET_IVOR(7, FloatingPointUnavailable); 892795033c3SDave Kleikamp SET_IVOR(8, SystemCall); 893795033c3SDave Kleikamp SET_IVOR(9, AuxillaryProcessorUnavailable); 894795033c3SDave Kleikamp SET_IVOR(10, Decrementer); 895795033c3SDave Kleikamp SET_IVOR(11, FixedIntervalTimer); 896795033c3SDave Kleikamp SET_IVOR(12, WatchdogTimer); 897e7f75ad0SDave Kleikamp SET_IVOR(13, DataTLBError44x); 898e7f75ad0SDave Kleikamp SET_IVOR(14, InstructionTLBError44x); 899795033c3SDave Kleikamp SET_IVOR(15, DebugCrit); 900795033c3SDave Kleikamp 901e7f75ad0SDave Kleikamp b head_start_common 902e7f75ad0SDave Kleikamp 903e7f75ad0SDave Kleikamp 904e7f75ad0SDave Kleikamp#ifdef CONFIG_PPC_47x 905e7f75ad0SDave Kleikamp 906e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 907e7f75ad0SDave Kleikamp 908e7f75ad0SDave Kleikamp/* Entry point for secondary 47x processors */ 909e7f75ad0SDave Kleikamp_GLOBAL(start_secondary_47x) 910e7f75ad0SDave Kleikamp mr r24,r3 /* CPU number */ 911e7f75ad0SDave Kleikamp 912e7f75ad0SDave Kleikamp bl init_cpu_state 913e7f75ad0SDave Kleikamp 914e7f75ad0SDave Kleikamp /* Now we need to bolt the rest of kernel memory which 915e7f75ad0SDave Kleikamp * is done in C code. We must be careful because our task 916e7f75ad0SDave Kleikamp * struct or our stack can (and will probably) be out 917e7f75ad0SDave Kleikamp * of reach of the initial 256M TLB entry, so we use a 918e7f75ad0SDave Kleikamp * small temporary stack in .bss for that. This works 919e7f75ad0SDave Kleikamp * because only one CPU at a time can be in this code 920e7f75ad0SDave Kleikamp */ 921e7f75ad0SDave Kleikamp lis r1,temp_boot_stack@h 922e7f75ad0SDave Kleikamp ori r1,r1,temp_boot_stack@l 923e7f75ad0SDave Kleikamp addi r1,r1,1024-STACK_FRAME_OVERHEAD 924e7f75ad0SDave Kleikamp li r0,0 925e7f75ad0SDave Kleikamp stw r0,0(r1) 926e7f75ad0SDave Kleikamp bl mmu_init_secondary 927e7f75ad0SDave Kleikamp 928e7f75ad0SDave Kleikamp /* Now we can get our task struct and real stack pointer */ 929e7f75ad0SDave Kleikamp 930e7f75ad0SDave Kleikamp /* Get current_thread_info and current */ 931e7f75ad0SDave Kleikamp lis r1,secondary_ti@ha 932e7f75ad0SDave Kleikamp lwz r1,secondary_ti@l(r1) 933e7f75ad0SDave Kleikamp lwz r2,TI_TASK(r1) 934e7f75ad0SDave Kleikamp 935e7f75ad0SDave Kleikamp /* Current stack pointer */ 936e7f75ad0SDave Kleikamp addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD 937e7f75ad0SDave Kleikamp li r0,0 938e7f75ad0SDave Kleikamp stw r0,0(r1) 939e7f75ad0SDave Kleikamp 940e7f75ad0SDave Kleikamp /* Kernel stack for exception entry in SPRG3 */ 941e7f75ad0SDave Kleikamp addi r4,r2,THREAD /* init task's THREAD */ 942e7f75ad0SDave Kleikamp mtspr SPRN_SPRG3,r4 943e7f75ad0SDave Kleikamp 944e7f75ad0SDave Kleikamp b start_secondary 945e7f75ad0SDave Kleikamp 946e7f75ad0SDave Kleikamp#endif /* CONFIG_SMP */ 947e7f75ad0SDave Kleikamp 948e7f75ad0SDave Kleikamp/* 949e7f75ad0SDave Kleikamp * Set up the initial MMU state for 44x 950e7f75ad0SDave Kleikamp * 951e7f75ad0SDave Kleikamp * We are still executing code at the virtual address 952e7f75ad0SDave Kleikamp * mappings set by the firmware for the base of RAM. 953e7f75ad0SDave Kleikamp */ 954e7f75ad0SDave Kleikamp 955e7f75ad0SDave Kleikamphead_start_47x: 956e7f75ad0SDave Kleikamp /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */ 957e7f75ad0SDave Kleikamp mfspr r3,SPRN_PID /* Get PID */ 958e7f75ad0SDave Kleikamp mfmsr r4 /* Get MSR */ 959e7f75ad0SDave Kleikamp andi. r4,r4,MSR_IS@l /* TS=1? */ 960e7f75ad0SDave Kleikamp beq 1f /* If not, leave STS=0 */ 961e7f75ad0SDave Kleikamp oris r3,r3,PPC47x_MMUCR_STS@h /* Set STS=1 */ 962e7f75ad0SDave Kleikamp1: mtspr SPRN_MMUCR,r3 /* Put MMUCR */ 963e7f75ad0SDave Kleikamp sync 964e7f75ad0SDave Kleikamp 965e7f75ad0SDave Kleikamp /* Find the entry we are running from */ 966e7f75ad0SDave Kleikamp bl 1f 967e7f75ad0SDave Kleikamp1: mflr r23 968e7f75ad0SDave Kleikamp tlbsx r23,0,r23 969e7f75ad0SDave Kleikamp tlbre r24,r23,0 970e7f75ad0SDave Kleikamp tlbre r25,r23,1 971e7f75ad0SDave Kleikamp tlbre r26,r23,2 972e7f75ad0SDave Kleikamp 973e7f75ad0SDave Kleikamp/* 974e7f75ad0SDave Kleikamp * Cleanup time 975e7f75ad0SDave Kleikamp */ 976e7f75ad0SDave Kleikamp 977e7f75ad0SDave Kleikamp /* Initialize MMUCR */ 978e7f75ad0SDave Kleikamp li r5,0 979e7f75ad0SDave Kleikamp mtspr SPRN_MMUCR,r5 980e7f75ad0SDave Kleikamp sync 981e7f75ad0SDave Kleikamp 982e7f75ad0SDave Kleikampclear_all_utlb_entries: 983e7f75ad0SDave Kleikamp 984e7f75ad0SDave Kleikamp #; Set initial values. 985e7f75ad0SDave Kleikamp 986e7f75ad0SDave Kleikamp addis r3,0,0x8000 987e7f75ad0SDave Kleikamp addi r4,0,0 988e7f75ad0SDave Kleikamp addi r5,0,0 989e7f75ad0SDave Kleikamp b clear_utlb_entry 990e7f75ad0SDave Kleikamp 991e7f75ad0SDave Kleikamp #; Align the loop to speed things up. 992e7f75ad0SDave Kleikamp 993e7f75ad0SDave Kleikamp .align 6 994e7f75ad0SDave Kleikamp 995e7f75ad0SDave Kleikampclear_utlb_entry: 996e7f75ad0SDave Kleikamp 997e7f75ad0SDave Kleikamp tlbwe r4,r3,0 998e7f75ad0SDave Kleikamp tlbwe r5,r3,1 999e7f75ad0SDave Kleikamp tlbwe r5,r3,2 1000e7f75ad0SDave Kleikamp addis r3,r3,0x2000 1001e7f75ad0SDave Kleikamp cmpwi r3,0 1002e7f75ad0SDave Kleikamp bne clear_utlb_entry 1003e7f75ad0SDave Kleikamp addis r3,0,0x8000 1004e7f75ad0SDave Kleikamp addis r4,r4,0x100 1005e7f75ad0SDave Kleikamp cmpwi r4,0 1006e7f75ad0SDave Kleikamp bne clear_utlb_entry 1007e7f75ad0SDave Kleikamp 1008e7f75ad0SDave Kleikamp #; Restore original entry. 1009e7f75ad0SDave Kleikamp 1010e7f75ad0SDave Kleikamp oris r23,r23,0x8000 /* specify the way */ 1011e7f75ad0SDave Kleikamp tlbwe r24,r23,0 1012e7f75ad0SDave Kleikamp tlbwe r25,r23,1 1013e7f75ad0SDave Kleikamp tlbwe r26,r23,2 1014e7f75ad0SDave Kleikamp 1015e7f75ad0SDave Kleikamp/* 1016e7f75ad0SDave Kleikamp * Configure and load pinned entry into TLB for the kernel core 1017e7f75ad0SDave Kleikamp */ 1018e7f75ad0SDave Kleikamp 1019e7f75ad0SDave Kleikamp lis r3,PAGE_OFFSET@h 1020e7f75ad0SDave Kleikamp ori r3,r3,PAGE_OFFSET@l 1021e7f75ad0SDave Kleikamp 1022e7f75ad0SDave Kleikamp /* Load the kernel PID = 0 */ 1023e7f75ad0SDave Kleikamp li r0,0 1024e7f75ad0SDave Kleikamp mtspr SPRN_PID,r0 1025e7f75ad0SDave Kleikamp sync 1026e7f75ad0SDave Kleikamp 1027e7f75ad0SDave Kleikamp /* Word 0 */ 1028e7f75ad0SDave Kleikamp clrrwi r3,r3,12 /* Mask off the effective page number */ 1029e7f75ad0SDave Kleikamp ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_256M 1030e7f75ad0SDave Kleikamp 10319661534dSDave Kleikamp /* Word 1 - use r25. RPN is the same as the original entry */ 10329661534dSDave Kleikamp 1033e7f75ad0SDave Kleikamp /* Word 2 */ 1034e7f75ad0SDave Kleikamp li r5,0 1035e7f75ad0SDave Kleikamp ori r5,r5,PPC47x_TLB2_S_RWX 1036e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 1037e7f75ad0SDave Kleikamp ori r5,r5,PPC47x_TLB2_M 1038e7f75ad0SDave Kleikamp#endif 1039e7f75ad0SDave Kleikamp 1040e7f75ad0SDave Kleikamp /* We write to way 0 and bolted 0 */ 1041e7f75ad0SDave Kleikamp lis r0,0x8800 1042e7f75ad0SDave Kleikamp tlbwe r3,r0,0 10439661534dSDave Kleikamp tlbwe r25,r0,1 1044e7f75ad0SDave Kleikamp tlbwe r5,r0,2 1045e7f75ad0SDave Kleikamp 1046e7f75ad0SDave Kleikamp/* 1047e7f75ad0SDave Kleikamp * Configure SSPCR, ISPCR and USPCR for now to search everything, we can fix 1048e7f75ad0SDave Kleikamp * them up later 1049e7f75ad0SDave Kleikamp */ 1050e7f75ad0SDave Kleikamp LOAD_REG_IMMEDIATE(r3, 0x9abcdef0) 1051e7f75ad0SDave Kleikamp mtspr SPRN_SSPCR,r3 1052e7f75ad0SDave Kleikamp mtspr SPRN_USPCR,r3 1053e7f75ad0SDave Kleikamp LOAD_REG_IMMEDIATE(r3, 0x12345670) 1054e7f75ad0SDave Kleikamp mtspr SPRN_ISPCR,r3 1055e7f75ad0SDave Kleikamp 1056e7f75ad0SDave Kleikamp /* Force context change */ 1057e7f75ad0SDave Kleikamp mfmsr r0 1058e7f75ad0SDave Kleikamp mtspr SPRN_SRR1, r0 1059e7f75ad0SDave Kleikamp lis r0,3f@h 1060e7f75ad0SDave Kleikamp ori r0,r0,3f@l 1061e7f75ad0SDave Kleikamp mtspr SPRN_SRR0,r0 1062e7f75ad0SDave Kleikamp sync 1063e7f75ad0SDave Kleikamp rfi 1064e7f75ad0SDave Kleikamp 1065e7f75ad0SDave Kleikamp /* Invalidate original entry we used */ 1066e7f75ad0SDave Kleikamp3: 1067e7f75ad0SDave Kleikamp rlwinm r24,r24,0,21,19 /* clear the "valid" bit */ 1068e7f75ad0SDave Kleikamp tlbwe r24,r23,0 1069e7f75ad0SDave Kleikamp addi r24,0,0 1070e7f75ad0SDave Kleikamp tlbwe r24,r23,1 1071e7f75ad0SDave Kleikamp tlbwe r24,r23,2 1072e7f75ad0SDave Kleikamp isync /* Clear out the shadow TLB entries */ 1073e7f75ad0SDave Kleikamp 1074e7f75ad0SDave Kleikamp#ifdef CONFIG_PPC_EARLY_DEBUG_44x 1075e7f75ad0SDave Kleikamp /* Add UART mapping for early debug. */ 1076e7f75ad0SDave Kleikamp 1077e7f75ad0SDave Kleikamp /* Word 0 */ 1078e7f75ad0SDave Kleikamp lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h 1079e7f75ad0SDave Kleikamp ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_TS | PPC47x_TLB0_1M 1080e7f75ad0SDave Kleikamp 1081e7f75ad0SDave Kleikamp /* Word 1 */ 1082e7f75ad0SDave Kleikamp lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h 1083e7f75ad0SDave Kleikamp ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH 1084e7f75ad0SDave Kleikamp 1085e7f75ad0SDave Kleikamp /* Word 2 */ 1086e7f75ad0SDave Kleikamp li r5,(PPC47x_TLB2_S_RW | PPC47x_TLB2_IMG) 1087e7f75ad0SDave Kleikamp 1088e7f75ad0SDave Kleikamp /* Bolted in way 0, bolt slot 5, we -hope- we don't hit the same 1089e7f75ad0SDave Kleikamp * congruence class as the kernel, we need to make sure of it at 1090e7f75ad0SDave Kleikamp * some point 1091e7f75ad0SDave Kleikamp */ 1092e7f75ad0SDave Kleikamp lis r0,0x8d00 1093e7f75ad0SDave Kleikamp tlbwe r3,r0,0 1094e7f75ad0SDave Kleikamp tlbwe r4,r0,1 1095e7f75ad0SDave Kleikamp tlbwe r5,r0,2 1096e7f75ad0SDave Kleikamp 1097e7f75ad0SDave Kleikamp /* Force context change */ 1098e7f75ad0SDave Kleikamp isync 1099e7f75ad0SDave Kleikamp#endif /* CONFIG_PPC_EARLY_DEBUG_44x */ 1100e7f75ad0SDave Kleikamp 1101e7f75ad0SDave Kleikamp /* Establish the interrupt vector offsets */ 1102e7f75ad0SDave Kleikamp SET_IVOR(0, CriticalInput); 1103e7f75ad0SDave Kleikamp SET_IVOR(1, MachineCheckA); 1104e7f75ad0SDave Kleikamp SET_IVOR(2, DataStorage); 1105e7f75ad0SDave Kleikamp SET_IVOR(3, InstructionStorage); 1106e7f75ad0SDave Kleikamp SET_IVOR(4, ExternalInput); 1107e7f75ad0SDave Kleikamp SET_IVOR(5, Alignment); 1108e7f75ad0SDave Kleikamp SET_IVOR(6, Program); 1109e7f75ad0SDave Kleikamp SET_IVOR(7, FloatingPointUnavailable); 1110e7f75ad0SDave Kleikamp SET_IVOR(8, SystemCall); 1111e7f75ad0SDave Kleikamp SET_IVOR(9, AuxillaryProcessorUnavailable); 1112e7f75ad0SDave Kleikamp SET_IVOR(10, Decrementer); 1113e7f75ad0SDave Kleikamp SET_IVOR(11, FixedIntervalTimer); 1114e7f75ad0SDave Kleikamp SET_IVOR(12, WatchdogTimer); 1115e7f75ad0SDave Kleikamp SET_IVOR(13, DataTLBError47x); 1116e7f75ad0SDave Kleikamp SET_IVOR(14, InstructionTLBError47x); 1117e7f75ad0SDave Kleikamp SET_IVOR(15, DebugCrit); 1118e7f75ad0SDave Kleikamp 1119e7f75ad0SDave Kleikamp /* We configure icbi to invalidate 128 bytes at a time since the 1120e7f75ad0SDave Kleikamp * current 32-bit kernel code isn't too happy with icache != dcache 1121e7f75ad0SDave Kleikamp * block size 1122e7f75ad0SDave Kleikamp */ 1123e7f75ad0SDave Kleikamp mfspr r3,SPRN_CCR0 1124e7f75ad0SDave Kleikamp oris r3,r3,0x0020 1125e7f75ad0SDave Kleikamp mtspr SPRN_CCR0,r3 1126e7f75ad0SDave Kleikamp isync 1127e7f75ad0SDave Kleikamp 1128e7f75ad0SDave Kleikamp#endif /* CONFIG_PPC_47x */ 1129e7f75ad0SDave Kleikamp 1130e7f75ad0SDave Kleikamp/* 1131e7f75ad0SDave Kleikamp * Here we are back to code that is common between 44x and 47x 1132e7f75ad0SDave Kleikamp * 1133e7f75ad0SDave Kleikamp * We proceed to further kernel initialization and return to the 1134e7f75ad0SDave Kleikamp * main kernel entry 1135e7f75ad0SDave Kleikamp */ 1136e7f75ad0SDave Kleikamphead_start_common: 1137795033c3SDave Kleikamp /* Establish the interrupt vector base */ 1138795033c3SDave Kleikamp lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */ 1139795033c3SDave Kleikamp mtspr SPRN_IVPR,r4 1140795033c3SDave Kleikamp 11419661534dSDave Kleikamp /* 11429661534dSDave Kleikamp * If the kernel was loaded at a non-zero 256 MB page, we need to 11439661534dSDave Kleikamp * mask off the most significant 4 bits to get the relative address 11449661534dSDave Kleikamp * from the start of physical memory 11459661534dSDave Kleikamp */ 11469661534dSDave Kleikamp rlwinm r22,r22,0,4,31 11479661534dSDave Kleikamp addis r22,r22,PAGE_OFFSET@h 1148795033c3SDave Kleikamp mtlr r22 1149e7f75ad0SDave Kleikamp isync 1150795033c3SDave Kleikamp blr 1151795033c3SDave Kleikamp 1152795033c3SDave Kleikamp/* 115314cf11afSPaul Mackerras * We put a few things here that have to be page-aligned. This stuff 115414cf11afSPaul Mackerras * goes at the beginning of the data segment, which is page-aligned. 115514cf11afSPaul Mackerras */ 115614cf11afSPaul Mackerras .data 1157ca9153a3SIlya Yanok .align PAGE_SHIFT 1158ea703ce2SKumar Gala .globl sdata 1159ea703ce2SKumar Galasdata: 1160ea703ce2SKumar Gala .globl empty_zero_page 1161ea703ce2SKumar Galaempty_zero_page: 1162ca9153a3SIlya Yanok .space PAGE_SIZE 116314cf11afSPaul Mackerras 116414cf11afSPaul Mackerras/* 116514cf11afSPaul Mackerras * To support >32-bit physical addresses, we use an 8KB pgdir. 116614cf11afSPaul Mackerras */ 1167ea703ce2SKumar Gala .globl swapper_pg_dir 1168ea703ce2SKumar Galaswapper_pg_dir: 1169bee86f14SKumar Gala .space PGD_TABLE_SIZE 117014cf11afSPaul Mackerras 117114cf11afSPaul Mackerras/* 117214cf11afSPaul Mackerras * Room for two PTE pointers, usually the kernel and current user pointers 117314cf11afSPaul Mackerras * to their respective root page table. 117414cf11afSPaul Mackerras */ 117514cf11afSPaul Mackerrasabatron_pteptrs: 117614cf11afSPaul Mackerras .space 8 1177e7f75ad0SDave Kleikamp 1178e7f75ad0SDave Kleikamp#ifdef CONFIG_SMP 1179e7f75ad0SDave Kleikamp .align 12 1180e7f75ad0SDave Kleikamptemp_boot_stack: 1181e7f75ad0SDave Kleikamp .space 1024 1182e7f75ad0SDave Kleikamp#endif /* CONFIG_SMP */ 1183