/*1* Copyright (c) 1995-1996 Gary Thomas <[email protected]>2* Initial PowerPC version.3* Copyright (c) 1996 Cort Dougan <[email protected]>4* Rewritten for PReP5* Copyright (c) 1996 Paul Mackerras <[email protected]>6* Low-level exception handers, MMU support, and rewrite.7* Copyright (c) 1997 Dan Malek <[email protected]>8* PowerPC 8xx modifications.9* Copyright (c) 1998-1999 TiVo, Inc.10* PowerPC 403GCX modifications.11* Copyright (c) 1999 Grant Erickson <[email protected]>12* PowerPC 403GCX/405GP modifications.13* Copyright 2000 MontaVista Software Inc.14* PPC405 modifications15* PowerPC 403GCX/405GP modifications.16* Author: MontaVista Software, Inc.17* [email protected] or [email protected]18* [email protected]19*20*21* Module name: head_4xx.S22*23* Description:24* Kernel execution entry point code.25*26* This program is free software; you can redistribute it and/or27* modify it under the terms of the GNU General Public License28* as published by the Free Software Foundation; either version29* 2 of the License, or (at your option) any later version.30*31*/3233#include <linux/init.h>34#include <asm/processor.h>35#include <asm/page.h>36#include <asm/mmu.h>37#include <asm/pgtable.h>38#include <asm/cputable.h>39#include <asm/thread_info.h>40#include <asm/ppc_asm.h>41#include <asm/asm-offsets.h>42#include <asm/ptrace.h>4344/* As with the other PowerPC ports, it is expected that when code45* execution begins here, the following registers contain valid, yet46* optional, information:47*48* r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)49* r4 - Starting address of the init RAM disk50* r5 - Ending address of the init RAM disk51* r6 - Start of kernel command line string (e.g. "mem=96m")52* r7 - End of kernel command line string53*54* This is all going to change RSN when we add bi_recs....... -- Dan55*/56__HEAD57_ENTRY(_stext);58_ENTRY(_start);5960/* Save parameters we are passed.61*/62mr r31,r363mr r30,r464mr r29,r565mr r28,r666mr r27,r76768/* We have to turn on the MMU right away so we get cache modes69* set correctly.70*/71bl initial_mmu7273/* We now have the lower 16 Meg mapped into TLB entries, and the caches74* ready to work.75*/76turn_on_mmu:77lis r0,MSR_KERNEL@h78ori r0,r0,MSR_KERNEL@l79mtspr SPRN_SRR1,r080lis r0,start_here@h81ori r0,r0,start_here@l82mtspr SPRN_SRR0,r083SYNC84rfi /* enables MMU */85b . /* prevent prefetch past rfi */8687/*88* This area is used for temporarily saving registers during the89* critical exception prolog.90*/91. = 0xc092crit_save:93_ENTRY(crit_r10)94.space 495_ENTRY(crit_r11)96.space 497_ENTRY(crit_srr0)98.space 499_ENTRY(crit_srr1)100.space 4101_ENTRY(saved_ksp_limit)102.space 4103104/*105* Exception vector entry code. This code runs with address translation106* turned off (i.e. using physical addresses). We assume SPRG_THREAD has107* the physical address of the current task thread_struct.108* Note that we have to have decremented r1 before we write to any fields109* of the exception frame, since a critical interrupt could occur at any110* time, and it will write to the area immediately below the current r1.111*/112#define NORMAL_EXCEPTION_PROLOG \113mtspr SPRN_SPRG_SCRATCH0,r10; /* save two registers to work with */\114mtspr SPRN_SPRG_SCRATCH1,r11; \115mtspr SPRN_SPRG_SCRATCH2,r1; \116mfcr r10; /* save CR in r10 for now */\117mfspr r11,SPRN_SRR1; /* check whether user or kernel */\118andi. r11,r11,MSR_PR; \119beq 1f; \120mfspr r1,SPRN_SPRG_THREAD; /* if from user, start at top of */\121lwz r1,THREAD_INFO-THREAD(r1); /* this thread's kernel stack */\122addi r1,r1,THREAD_SIZE; \1231: subi r1,r1,INT_FRAME_SIZE; /* Allocate an exception frame */\124tophys(r11,r1); \125stw r10,_CCR(r11); /* save various registers */\126stw r12,GPR12(r11); \127stw r9,GPR9(r11); \128mfspr r10,SPRN_SPRG_SCRATCH0; \129stw r10,GPR10(r11); \130mfspr r12,SPRN_SPRG_SCRATCH1; \131stw r12,GPR11(r11); \132mflr r10; \133stw r10,_LINK(r11); \134mfspr r10,SPRN_SPRG_SCRATCH2; \135mfspr r12,SPRN_SRR0; \136stw r10,GPR1(r11); \137mfspr r9,SPRN_SRR1; \138stw r10,0(r11); \139rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\140stw r0,GPR0(r11); \141SAVE_4GPRS(3, r11); \142SAVE_2GPRS(7, r11)143144/*145* Exception prolog for critical exceptions. This is a little different146* from the normal exception prolog above since a critical exception147* can potentially occur at any point during normal exception processing.148* Thus we cannot use the same SPRG registers as the normal prolog above.149* Instead we use a couple of words of memory at low physical addresses.150* This is OK since we don't support SMP on these processors.151*/152#define CRITICAL_EXCEPTION_PROLOG \153stw r10,crit_r10@l(0); /* save two registers to work with */\154stw r11,crit_r11@l(0); \155mfcr r10; /* save CR in r10 for now */\156mfspr r11,SPRN_SRR3; /* check whether user or kernel */\157andi. r11,r11,MSR_PR; \158lis r11,critirq_ctx@ha; \159tophys(r11,r11); \160lwz r11,critirq_ctx@l(r11); \161beq 1f; \162/* COMING FROM USER MODE */ \163mfspr r11,SPRN_SPRG_THREAD; /* if from user, start at top of */\164lwz r11,THREAD_INFO-THREAD(r11); /* this thread's kernel stack */\1651: addi r11,r11,THREAD_SIZE-INT_FRAME_SIZE; /* Alloc an excpt frm */\166tophys(r11,r11); \167stw r10,_CCR(r11); /* save various registers */\168stw r12,GPR12(r11); \169stw r9,GPR9(r11); \170mflr r10; \171stw r10,_LINK(r11); \172mfspr r12,SPRN_DEAR; /* save DEAR and ESR in the frame */\173stw r12,_DEAR(r11); /* since they may have had stuff */\174mfspr r9,SPRN_ESR; /* in them at the point where the */\175stw r9,_ESR(r11); /* exception was taken */\176mfspr r12,SPRN_SRR2; \177stw r1,GPR1(r11); \178mfspr r9,SPRN_SRR3; \179stw r1,0(r11); \180tovirt(r1,r11); \181rlwinm r9,r9,0,14,12; /* clear MSR_WE (necessary?) */\182stw r0,GPR0(r11); \183SAVE_4GPRS(3, r11); \184SAVE_2GPRS(7, r11)185186/*187* State at this point:188* r9 saved in stack frame, now saved SRR3 & ~MSR_WE189* r10 saved in crit_r10 and in stack frame, trashed190* r11 saved in crit_r11 and in stack frame,191* now phys stack/exception frame pointer192* r12 saved in stack frame, now saved SRR2193* CR saved in stack frame, CR0.EQ = !SRR3.PR194* LR, DEAR, ESR in stack frame195* r1 saved in stack frame, now virt stack/excframe pointer196* r0, r3-r8 saved in stack frame197*/198199/*200* Exception vectors.201*/202#define START_EXCEPTION(n, label) \203. = n; \204label:205206#define EXCEPTION(n, label, hdlr, xfer) \207START_EXCEPTION(n, label); \208NORMAL_EXCEPTION_PROLOG; \209addi r3,r1,STACK_FRAME_OVERHEAD; \210xfer(n, hdlr)211212#define CRITICAL_EXCEPTION(n, label, hdlr) \213START_EXCEPTION(n, label); \214CRITICAL_EXCEPTION_PROLOG; \215addi r3,r1,STACK_FRAME_OVERHEAD; \216EXC_XFER_TEMPLATE(hdlr, n+2, (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \217NOCOPY, crit_transfer_to_handler, \218ret_from_crit_exc)219220#define EXC_XFER_TEMPLATE(hdlr, trap, msr, copyee, tfer, ret) \221li r10,trap; \222stw r10,_TRAP(r11); \223lis r10,msr@h; \224ori r10,r10,msr@l; \225copyee(r10, r9); \226bl tfer; \227.long hdlr; \228.long ret229230#define COPY_EE(d, s) rlwimi d,s,0,16,16231#define NOCOPY(d, s)232233#define EXC_XFER_STD(n, hdlr) \234EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, NOCOPY, transfer_to_handler_full, \235ret_from_except_full)236237#define EXC_XFER_LITE(n, hdlr) \238EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, NOCOPY, transfer_to_handler, \239ret_from_except)240241#define EXC_XFER_EE(n, hdlr) \242EXC_XFER_TEMPLATE(hdlr, n, MSR_KERNEL, COPY_EE, transfer_to_handler_full, \243ret_from_except_full)244245#define EXC_XFER_EE_LITE(n, hdlr) \246EXC_XFER_TEMPLATE(hdlr, n+1, MSR_KERNEL, COPY_EE, transfer_to_handler, \247ret_from_except)248249250/*251* 0x0100 - Critical Interrupt Exception252*/253CRITICAL_EXCEPTION(0x0100, CriticalInterrupt, unknown_exception)254255/*256* 0x0200 - Machine Check Exception257*/258CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception)259260/*261* 0x0300 - Data Storage Exception262* This happens for just a few reasons. U0 set (but we don't do that),263* or zone protection fault (user violation, write to protected page).264* If this is just an update of modified status, we do that quickly265* and exit. Otherwise, we call heavywight functions to do the work.266*/267START_EXCEPTION(0x0300, DataStorage)268mtspr SPRN_SPRG_SCRATCH0, r10 /* Save some working registers */269mtspr SPRN_SPRG_SCRATCH1, r11270#ifdef CONFIG_403GCX271stw r12, 0(r0)272stw r9, 4(r0)273mfcr r11274mfspr r12, SPRN_PID275stw r11, 8(r0)276stw r12, 12(r0)277#else278mtspr SPRN_SPRG_SCRATCH3, r12279mtspr SPRN_SPRG_SCRATCH4, r9280mfcr r11281mfspr r12, SPRN_PID282mtspr SPRN_SPRG_SCRATCH6, r11283mtspr SPRN_SPRG_SCRATCH5, r12284#endif285286/* First, check if it was a zone fault (which means a user287* tried to access a kernel or read-protected page - always288* a SEGV). All other faults here must be stores, so no289* need to check ESR_DST as well. */290mfspr r10, SPRN_ESR291andis. r10, r10, ESR_DIZ@h292bne 2f293294mfspr r10, SPRN_DEAR /* Get faulting address */295296/* If we are faulting a kernel address, we have to use the297* kernel page tables.298*/299lis r11, PAGE_OFFSET@h300cmplw r10, r11301blt+ 3f302lis r11, swapper_pg_dir@h303ori r11, r11, swapper_pg_dir@l304li r9, 0305mtspr SPRN_PID, r9 /* TLB will have 0 TID */306b 4f307308/* Get the PGD for the current thread.309*/3103:311mfspr r11,SPRN_SPRG_THREAD312lwz r11,PGDIR(r11)3134:314tophys(r11, r11)315rlwimi r11, r10, 12, 20, 29 /* Create L1 (pgdir/pmd) address */316lwz r11, 0(r11) /* Get L1 entry */317rlwinm. r12, r11, 0, 0, 19 /* Extract L2 (pte) base address */318beq 2f /* Bail if no table */319320rlwimi r12, r10, 22, 20, 29 /* Compute PTE address */321lwz r11, 0(r12) /* Get Linux PTE */322323andi. r9, r11, _PAGE_RW /* Is it writeable? */324beq 2f /* Bail if not */325326/* Update 'changed'.327*/328ori r11, r11, _PAGE_DIRTY|_PAGE_ACCESSED|_PAGE_HWWRITE329stw r11, 0(r12) /* Update Linux page table */330331/* Most of the Linux PTE is ready to load into the TLB LO.332* We set ZSEL, where only the LS-bit determines user access.333* We set execute, because we don't have the granularity to334* properly set this at the page level (Linux problem).335* If shared is set, we cause a zero PID->TID load.336* Many of these bits are software only. Bits we don't set337* here we (properly should) assume have the appropriate value.338*/339li r12, 0x0ce2340andc r11, r11, r12 /* Make sure 20, 21 are zero */341342/* find the TLB index that caused the fault. It has to be here.343*/344tlbsx r9, 0, r10345346tlbwe r11, r9, TLB_DATA /* Load TLB LO */347348/* Done...restore registers and get out of here.349*/350#ifdef CONFIG_403GCX351lwz r12, 12(r0)352lwz r11, 8(r0)353mtspr SPRN_PID, r12354mtcr r11355lwz r9, 4(r0)356lwz r12, 0(r0)357#else358mfspr r12, SPRN_SPRG_SCRATCH5359mfspr r11, SPRN_SPRG_SCRATCH6360mtspr SPRN_PID, r12361mtcr r11362mfspr r9, SPRN_SPRG_SCRATCH4363mfspr r12, SPRN_SPRG_SCRATCH3364#endif365mfspr r11, SPRN_SPRG_SCRATCH1366mfspr r10, SPRN_SPRG_SCRATCH0367PPC405_ERR77_SYNC368rfi /* Should sync shadow TLBs */369b . /* prevent prefetch past rfi */3703712:372/* The bailout. Restore registers to pre-exception conditions373* and call the heavyweights to help us out.374*/375#ifdef CONFIG_403GCX376lwz r12, 12(r0)377lwz r11, 8(r0)378mtspr SPRN_PID, r12379mtcr r11380lwz r9, 4(r0)381lwz r12, 0(r0)382#else383mfspr r12, SPRN_SPRG_SCRATCH5384mfspr r11, SPRN_SPRG_SCRATCH6385mtspr SPRN_PID, r12386mtcr r11387mfspr r9, SPRN_SPRG_SCRATCH4388mfspr r12, SPRN_SPRG_SCRATCH3389#endif390mfspr r11, SPRN_SPRG_SCRATCH1391mfspr r10, SPRN_SPRG_SCRATCH0392b DataAccess393394/*395* 0x0400 - Instruction Storage Exception396* This is caused by a fetch from non-execute or guarded pages.397*/398START_EXCEPTION(0x0400, InstructionAccess)399NORMAL_EXCEPTION_PROLOG400mr r4,r12 /* Pass SRR0 as arg2 */401li r5,0 /* Pass zero as arg3 */402EXC_XFER_EE_LITE(0x400, handle_page_fault)403404/* 0x0500 - External Interrupt Exception */405EXCEPTION(0x0500, HardwareInterrupt, do_IRQ, EXC_XFER_LITE)406407/* 0x0600 - Alignment Exception */408START_EXCEPTION(0x0600, Alignment)409NORMAL_EXCEPTION_PROLOG410mfspr r4,SPRN_DEAR /* Grab the DEAR and save it */411stw r4,_DEAR(r11)412addi r3,r1,STACK_FRAME_OVERHEAD413EXC_XFER_EE(0x600, alignment_exception)414415/* 0x0700 - Program Exception */416START_EXCEPTION(0x0700, ProgramCheck)417NORMAL_EXCEPTION_PROLOG418mfspr r4,SPRN_ESR /* Grab the ESR and save it */419stw r4,_ESR(r11)420addi r3,r1,STACK_FRAME_OVERHEAD421EXC_XFER_STD(0x700, program_check_exception)422423EXCEPTION(0x0800, Trap_08, unknown_exception, EXC_XFER_EE)424EXCEPTION(0x0900, Trap_09, unknown_exception, EXC_XFER_EE)425EXCEPTION(0x0A00, Trap_0A, unknown_exception, EXC_XFER_EE)426EXCEPTION(0x0B00, Trap_0B, unknown_exception, EXC_XFER_EE)427428/* 0x0C00 - System Call Exception */429START_EXCEPTION(0x0C00, SystemCall)430NORMAL_EXCEPTION_PROLOG431EXC_XFER_EE_LITE(0xc00, DoSyscall)432433EXCEPTION(0x0D00, Trap_0D, unknown_exception, EXC_XFER_EE)434EXCEPTION(0x0E00, Trap_0E, unknown_exception, EXC_XFER_EE)435EXCEPTION(0x0F00, Trap_0F, unknown_exception, EXC_XFER_EE)436437/* 0x1000 - Programmable Interval Timer (PIT) Exception */438START_EXCEPTION(0x1000, Decrementer)439NORMAL_EXCEPTION_PROLOG440lis r0,TSR_PIS@h441mtspr SPRN_TSR,r0 /* Clear the PIT exception */442addi r3,r1,STACK_FRAME_OVERHEAD443EXC_XFER_LITE(0x1000, timer_interrupt)444445#if 0446/* NOTE:447* FIT and WDT handlers are not implemented yet.448*/449450/* 0x1010 - Fixed Interval Timer (FIT) Exception451*/452STND_EXCEPTION(0x1010, FITException, unknown_exception)453454/* 0x1020 - Watchdog Timer (WDT) Exception455*/456#ifdef CONFIG_BOOKE_WDT457CRITICAL_EXCEPTION(0x1020, WDTException, WatchdogException)458#else459CRITICAL_EXCEPTION(0x1020, WDTException, unknown_exception)460#endif461#endif462463/* 0x1100 - Data TLB Miss Exception464* As the name implies, translation is not in the MMU, so search the465* page tables and fix it. The only purpose of this function is to466* load TLB entries from the page table if they exist.467*/468START_EXCEPTION(0x1100, DTLBMiss)469mtspr SPRN_SPRG_SCRATCH0, r10 /* Save some working registers */470mtspr SPRN_SPRG_SCRATCH1, r11471#ifdef CONFIG_403GCX472stw r12, 0(r0)473stw r9, 4(r0)474mfcr r11475mfspr r12, SPRN_PID476stw r11, 8(r0)477stw r12, 12(r0)478#else479mtspr SPRN_SPRG_SCRATCH3, r12480mtspr SPRN_SPRG_SCRATCH4, r9481mfcr r11482mfspr r12, SPRN_PID483mtspr SPRN_SPRG_SCRATCH6, r11484mtspr SPRN_SPRG_SCRATCH5, r12485#endif486mfspr r10, SPRN_DEAR /* Get faulting address */487488/* If we are faulting a kernel address, we have to use the489* kernel page tables.490*/491lis r11, PAGE_OFFSET@h492cmplw r10, r11493blt+ 3f494lis r11, swapper_pg_dir@h495ori r11, r11, swapper_pg_dir@l496li r9, 0497mtspr SPRN_PID, r9 /* TLB will have 0 TID */498b 4f499500/* Get the PGD for the current thread.501*/5023:503mfspr r11,SPRN_SPRG_THREAD504lwz r11,PGDIR(r11)5054:506tophys(r11, r11)507rlwimi r11, r10, 12, 20, 29 /* Create L1 (pgdir/pmd) address */508lwz r12, 0(r11) /* Get L1 entry */509andi. r9, r12, _PMD_PRESENT /* Check if it points to a PTE page */510beq 2f /* Bail if no table */511512rlwimi r12, r10, 22, 20, 29 /* Compute PTE address */513lwz r11, 0(r12) /* Get Linux PTE */514andi. r9, r11, _PAGE_PRESENT515beq 5f516517ori r11, r11, _PAGE_ACCESSED518stw r11, 0(r12)519520/* Create TLB tag. This is the faulting address plus a static521* set of bits. These are size, valid, E, U0.522*/523li r12, 0x00c0524rlwimi r10, r12, 0, 20, 31525526b finish_tlb_load5275282: /* Check for possible large-page pmd entry */529rlwinm. r9, r12, 2, 22, 24530beq 5f531532/* Create TLB tag. This is the faulting address, plus a static533* set of bits (valid, E, U0) plus the size from the PMD.534*/535ori r9, r9, 0x40536rlwimi r10, r9, 0, 20, 31537mr r11, r12538539b finish_tlb_load5405415:542/* The bailout. Restore registers to pre-exception conditions543* and call the heavyweights to help us out.544*/545#ifdef CONFIG_403GCX546lwz r12, 12(r0)547lwz r11, 8(r0)548mtspr SPRN_PID, r12549mtcr r11550lwz r9, 4(r0)551lwz r12, 0(r0)552#else553mfspr r12, SPRN_SPRG_SCRATCH5554mfspr r11, SPRN_SPRG_SCRATCH6555mtspr SPRN_PID, r12556mtcr r11557mfspr r9, SPRN_SPRG_SCRATCH4558mfspr r12, SPRN_SPRG_SCRATCH3559#endif560mfspr r11, SPRN_SPRG_SCRATCH1561mfspr r10, SPRN_SPRG_SCRATCH0562b DataAccess563564/* 0x1200 - Instruction TLB Miss Exception565* Nearly the same as above, except we get our information from different566* registers and bailout to a different point.567*/568START_EXCEPTION(0x1200, ITLBMiss)569mtspr SPRN_SPRG_SCRATCH0, r10 /* Save some working registers */570mtspr SPRN_SPRG_SCRATCH1, r11571#ifdef CONFIG_403GCX572stw r12, 0(r0)573stw r9, 4(r0)574mfcr r11575mfspr r12, SPRN_PID576stw r11, 8(r0)577stw r12, 12(r0)578#else579mtspr SPRN_SPRG_SCRATCH3, r12580mtspr SPRN_SPRG_SCRATCH4, r9581mfcr r11582mfspr r12, SPRN_PID583mtspr SPRN_SPRG_SCRATCH6, r11584mtspr SPRN_SPRG_SCRATCH5, r12585#endif586mfspr r10, SPRN_SRR0 /* Get faulting address */587588/* If we are faulting a kernel address, we have to use the589* kernel page tables.590*/591lis r11, PAGE_OFFSET@h592cmplw r10, r11593blt+ 3f594lis r11, swapper_pg_dir@h595ori r11, r11, swapper_pg_dir@l596li r9, 0597mtspr SPRN_PID, r9 /* TLB will have 0 TID */598b 4f599600/* Get the PGD for the current thread.601*/6023:603mfspr r11,SPRN_SPRG_THREAD604lwz r11,PGDIR(r11)6054:606tophys(r11, r11)607rlwimi r11, r10, 12, 20, 29 /* Create L1 (pgdir/pmd) address */608lwz r12, 0(r11) /* Get L1 entry */609andi. r9, r12, _PMD_PRESENT /* Check if it points to a PTE page */610beq 2f /* Bail if no table */611612rlwimi r12, r10, 22, 20, 29 /* Compute PTE address */613lwz r11, 0(r12) /* Get Linux PTE */614andi. r9, r11, _PAGE_PRESENT615beq 5f616617ori r11, r11, _PAGE_ACCESSED618stw r11, 0(r12)619620/* Create TLB tag. This is the faulting address plus a static621* set of bits. These are size, valid, E, U0.622*/623li r12, 0x00c0624rlwimi r10, r12, 0, 20, 31625626b finish_tlb_load6276282: /* Check for possible large-page pmd entry */629rlwinm. r9, r12, 2, 22, 24630beq 5f631632/* Create TLB tag. This is the faulting address, plus a static633* set of bits (valid, E, U0) plus the size from the PMD.634*/635ori r9, r9, 0x40636rlwimi r10, r9, 0, 20, 31637mr r11, r12638639b finish_tlb_load6406415:642/* The bailout. Restore registers to pre-exception conditions643* and call the heavyweights to help us out.644*/645#ifdef CONFIG_403GCX646lwz r12, 12(r0)647lwz r11, 8(r0)648mtspr SPRN_PID, r12649mtcr r11650lwz r9, 4(r0)651lwz r12, 0(r0)652#else653mfspr r12, SPRN_SPRG_SCRATCH5654mfspr r11, SPRN_SPRG_SCRATCH6655mtspr SPRN_PID, r12656mtcr r11657mfspr r9, SPRN_SPRG_SCRATCH4658mfspr r12, SPRN_SPRG_SCRATCH3659#endif660mfspr r11, SPRN_SPRG_SCRATCH1661mfspr r10, SPRN_SPRG_SCRATCH0662b InstructionAccess663664EXCEPTION(0x1300, Trap_13, unknown_exception, EXC_XFER_EE)665EXCEPTION(0x1400, Trap_14, unknown_exception, EXC_XFER_EE)666EXCEPTION(0x1500, Trap_15, unknown_exception, EXC_XFER_EE)667EXCEPTION(0x1600, Trap_16, unknown_exception, EXC_XFER_EE)668#ifdef CONFIG_IBM405_ERR51669/* 405GP errata 51 */670START_EXCEPTION(0x1700, Trap_17)671b DTLBMiss672#else673EXCEPTION(0x1700, Trap_17, unknown_exception, EXC_XFER_EE)674#endif675EXCEPTION(0x1800, Trap_18, unknown_exception, EXC_XFER_EE)676EXCEPTION(0x1900, Trap_19, unknown_exception, EXC_XFER_EE)677EXCEPTION(0x1A00, Trap_1A, unknown_exception, EXC_XFER_EE)678EXCEPTION(0x1B00, Trap_1B, unknown_exception, EXC_XFER_EE)679EXCEPTION(0x1C00, Trap_1C, unknown_exception, EXC_XFER_EE)680EXCEPTION(0x1D00, Trap_1D, unknown_exception, EXC_XFER_EE)681EXCEPTION(0x1E00, Trap_1E, unknown_exception, EXC_XFER_EE)682EXCEPTION(0x1F00, Trap_1F, unknown_exception, EXC_XFER_EE)683684/* Check for a single step debug exception while in an exception685* handler before state has been saved. This is to catch the case686* where an instruction that we are trying to single step causes687* an exception (eg ITLB/DTLB miss) and thus the first instruction of688* the exception handler generates a single step debug exception.689*690* If we get a debug trap on the first instruction of an exception handler,691* we reset the MSR_DE in the _exception handler's_ MSR (the debug trap is692* a critical exception, so we are using SPRN_CSRR1 to manipulate the MSR).693* The exception handler was handling a non-critical interrupt, so it will694* save (and later restore) the MSR via SPRN_SRR1, which will still have695* the MSR_DE bit set.696*/697/* 0x2000 - Debug Exception */698START_EXCEPTION(0x2000, DebugTrap)699CRITICAL_EXCEPTION_PROLOG700701/*702* If this is a single step or branch-taken exception in an703* exception entry sequence, it was probably meant to apply to704* the code where the exception occurred (since exception entry705* doesn't turn off DE automatically). We simulate the effect706* of turning off DE on entry to an exception handler by turning707* off DE in the SRR3 value and clearing the debug status.708*/709mfspr r10,SPRN_DBSR /* check single-step/branch taken */710andis. r10,r10,DBSR_IC@h711beq+ 2f712713andi. r10,r9,MSR_IR|MSR_PR /* check supervisor + MMU off */714beq 1f /* branch and fix it up */715716mfspr r10,SPRN_SRR2 /* Faulting instruction address */717cmplwi r10,0x2100718bgt+ 2f /* address above exception vectors */719720/* here it looks like we got an inappropriate debug exception. */7211: rlwinm r9,r9,0,~MSR_DE /* clear DE in the SRR3 value */722lis r10,DBSR_IC@h /* clear the IC event */723mtspr SPRN_DBSR,r10724/* restore state and get out */725lwz r10,_CCR(r11)726lwz r0,GPR0(r11)727lwz r1,GPR1(r11)728mtcrf 0x80,r10729mtspr SPRN_SRR2,r12730mtspr SPRN_SRR3,r9731lwz r9,GPR9(r11)732lwz r12,GPR12(r11)733lwz r10,crit_r10@l(0)734lwz r11,crit_r11@l(0)735PPC405_ERR77_SYNC736rfci737b .738739/* continue normal handling for a critical exception... */7402: mfspr r4,SPRN_DBSR741addi r3,r1,STACK_FRAME_OVERHEAD742EXC_XFER_TEMPLATE(DebugException, 0x2002, \743(MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \744NOCOPY, crit_transfer_to_handler, ret_from_crit_exc)745746/*747* The other Data TLB exceptions bail out to this point748* if they can't resolve the lightweight TLB fault.749*/750DataAccess:751NORMAL_EXCEPTION_PROLOG752mfspr r5,SPRN_ESR /* Grab the ESR, save it, pass arg3 */753stw r5,_ESR(r11)754mfspr r4,SPRN_DEAR /* Grab the DEAR, save it, pass arg2 */755EXC_XFER_EE_LITE(0x300, handle_page_fault)756757/* Other PowerPC processors, namely those derived from the 6xx-series758* have vectors from 0x2100 through 0x2F00 defined, but marked as reserved.759* However, for the 4xx-series processors these are neither defined nor760* reserved.761*/762763/* Damn, I came up one instruction too many to fit into the764* exception space :-). Both the instruction and data TLB765* miss get to this point to load the TLB.766* r10 - TLB_TAG value767* r11 - Linux PTE768* r12, r9 - available to use769* PID - loaded with proper value when we get here770* Upon exit, we reload everything and RFI.771* Actually, it will fit now, but oh well.....a common place772* to load the TLB.773*/774tlb_4xx_index:775.long 0776finish_tlb_load:777/* load the next available TLB index.778*/779lwz r9, tlb_4xx_index@l(0)780addi r9, r9, 1781andi. r9, r9, (PPC40X_TLB_SIZE-1)782stw r9, tlb_4xx_index@l(0)7837846:785/*786* Clear out the software-only bits in the PTE to generate the787* TLB_DATA value. These are the bottom 2 bits of the RPM, the788* top 3 bits of the zone field, and M.789*/790li r12, 0x0ce2791andc r11, r11, r12792793tlbwe r11, r9, TLB_DATA /* Load TLB LO */794tlbwe r10, r9, TLB_TAG /* Load TLB HI */795796/* Done...restore registers and get out of here.797*/798#ifdef CONFIG_403GCX799lwz r12, 12(r0)800lwz r11, 8(r0)801mtspr SPRN_PID, r12802mtcr r11803lwz r9, 4(r0)804lwz r12, 0(r0)805#else806mfspr r12, SPRN_SPRG_SCRATCH5807mfspr r11, SPRN_SPRG_SCRATCH6808mtspr SPRN_PID, r12809mtcr r11810mfspr r9, SPRN_SPRG_SCRATCH4811mfspr r12, SPRN_SPRG_SCRATCH3812#endif813mfspr r11, SPRN_SPRG_SCRATCH1814mfspr r10, SPRN_SPRG_SCRATCH0815PPC405_ERR77_SYNC816rfi /* Should sync shadow TLBs */817b . /* prevent prefetch past rfi */818819/* extern void giveup_fpu(struct task_struct *prev)820*821* The PowerPC 4xx family of processors do not have an FPU, so this just822* returns.823*/824_ENTRY(giveup_fpu)825blr826827/* This is where the main kernel code starts.828*/829start_here:830831/* ptr to current */832lis r2,init_task@h833ori r2,r2,init_task@l834835/* ptr to phys current thread */836tophys(r4,r2)837addi r4,r4,THREAD /* init task's THREAD */838mtspr SPRN_SPRG_THREAD,r4839840/* stack */841lis r1,init_thread_union@ha842addi r1,r1,init_thread_union@l843li r0,0844stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)845846bl early_init /* We have to do this with MMU on */847848/*849* Decide what sort of machine this is and initialize the MMU.850*/851mr r3,r31852mr r4,r30853mr r5,r29854mr r6,r28855mr r7,r27856bl machine_init857bl MMU_init858859/* Go back to running unmapped so we can load up new values860* and change to using our exception vectors.861* On the 4xx, all we have to do is invalidate the TLB to clear862* the old 16M byte TLB mappings.863*/864lis r4,2f@h865ori r4,r4,2f@l866tophys(r4,r4)867lis r3,(MSR_KERNEL & ~(MSR_IR|MSR_DR))@h868ori r3,r3,(MSR_KERNEL & ~(MSR_IR|MSR_DR))@l869mtspr SPRN_SRR0,r4870mtspr SPRN_SRR1,r3871rfi872b . /* prevent prefetch past rfi */873874/* Load up the kernel context */8752:876sync /* Flush to memory before changing TLB */877tlbia878isync /* Flush shadow TLBs */879880/* set up the PTE pointers for the Abatron bdiGDB.881*/882lis r6, swapper_pg_dir@h883ori r6, r6, swapper_pg_dir@l884lis r5, abatron_pteptrs@h885ori r5, r5, abatron_pteptrs@l886stw r5, 0xf0(r0) /* Must match your Abatron config file */887tophys(r5,r5)888stw r6, 0(r5)889890/* Now turn on the MMU for real! */891lis r4,MSR_KERNEL@h892ori r4,r4,MSR_KERNEL@l893lis r3,start_kernel@h894ori r3,r3,start_kernel@l895mtspr SPRN_SRR0,r3896mtspr SPRN_SRR1,r4897rfi /* enable MMU and jump to start_kernel */898b . /* prevent prefetch past rfi */899900/* Set up the initial MMU state so we can do the first level of901* kernel initialization. This maps the first 16 MBytes of memory 1:1902* virtual to physical and more importantly sets the cache mode.903*/904initial_mmu:905tlbia /* Invalidate all TLB entries */906isync907908/* We should still be executing code at physical address 0x0000xxxx909* at this point. However, start_here is at virtual address910* 0xC000xxxx. So, set up a TLB mapping to cover this once911* translation is enabled.912*/913914lis r3,KERNELBASE@h /* Load the kernel virtual address */915ori r3,r3,KERNELBASE@l916tophys(r4,r3) /* Load the kernel physical address */917918iccci r0,r3 /* Invalidate the i-cache before use */919920/* Load the kernel PID.921*/922li r0,0923mtspr SPRN_PID,r0924sync925926/* Configure and load one entry into TLB slots 63 */927clrrwi r4,r4,10 /* Mask off the real page number */928ori r4,r4,(TLB_WR | TLB_EX) /* Set the write and execute bits */929930clrrwi r3,r3,10 /* Mask off the effective page number */931ori r3,r3,(TLB_VALID | TLB_PAGESZ(PAGESZ_16M))932933li r0,63 /* TLB slot 63 */934935tlbwe r4,r0,TLB_DATA /* Load the data portion of the entry */936tlbwe r3,r0,TLB_TAG /* Load the tag portion of the entry */937938#if defined(CONFIG_SERIAL_TEXT_DEBUG) && defined(SERIAL_DEBUG_IO_BASE)939940/* Load a TLB entry for the UART, so that ppc4xx_progress() can use941* the UARTs nice and early. We use a 4k real==virtual mapping. */942943lis r3,SERIAL_DEBUG_IO_BASE@h944ori r3,r3,SERIAL_DEBUG_IO_BASE@l945mr r4,r3946clrrwi r4,r4,12947ori r4,r4,(TLB_WR|TLB_I|TLB_M|TLB_G)948949clrrwi r3,r3,12950ori r3,r3,(TLB_VALID | TLB_PAGESZ(PAGESZ_4K))951952li r0,0 /* TLB slot 0 */953tlbwe r4,r0,TLB_DATA954tlbwe r3,r0,TLB_TAG955#endif /* CONFIG_SERIAL_DEBUG_TEXT && SERIAL_DEBUG_IO_BASE */956957isync958959/* Establish the exception vector base960*/961lis r4,KERNELBASE@h /* EVPR only uses the high 16-bits */962tophys(r0,r4) /* Use the physical address */963mtspr SPRN_EVPR,r0964965blr966967_GLOBAL(abort)968mfspr r13,SPRN_DBCR0969oris r13,r13,DBCR0_RST_SYSTEM@h970mtspr SPRN_DBCR0,r13971972_GLOBAL(set_context)973974#ifdef CONFIG_BDI_SWITCH975/* Context switch the PTE pointer for the Abatron BDI2000.976* The PGDIR is the second parameter.977*/978lis r5, KERNELBASE@h979lwz r5, 0xf0(r5)980stw r4, 0x4(r5)981#endif982sync983mtspr SPRN_PID,r3984isync /* Need an isync to flush shadow */985/* TLBs after changing PID */986blr987988/* We put a few things here that have to be page-aligned. This stuff989* goes at the beginning of the data segment, which is page-aligned.990*/991.data992.align 12993.globl sdata994sdata:995.globl empty_zero_page996empty_zero_page:997.space 4096998.globl swapper_pg_dir999swapper_pg_dir:1000.space PGD_TABLE_SIZE10011002/* Room for two PTE pointers, usually the kernel and current user pointers1003* to their respective root page table.1004*/1005abatron_pteptrs:1006.space 8100710081009