114cf11afSPaul Mackerras/* 214cf11afSPaul Mackerras * PowerPC version 314cf11afSPaul Mackerras * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 414cf11afSPaul Mackerras * 514cf11afSPaul Mackerras * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP 614cf11afSPaul Mackerras * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu> 714cf11afSPaul Mackerras * Adapted for Power Macintosh by Paul Mackerras. 814cf11afSPaul Mackerras * Low-level exception handlers and MMU support 914cf11afSPaul Mackerras * rewritten by Paul Mackerras. 1014cf11afSPaul Mackerras * Copyright (C) 1996 Paul Mackerras. 1114cf11afSPaul Mackerras * 1214cf11afSPaul Mackerras * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and 1314cf11afSPaul Mackerras * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com 1414cf11afSPaul Mackerras * 1514cf11afSPaul Mackerras * This file contains the low-level support and setup for the 1614cf11afSPaul Mackerras * PowerPC-64 platform, including trap and interrupt dispatch. 1714cf11afSPaul Mackerras * 1814cf11afSPaul Mackerras * This program is free software; you can redistribute it and/or 1914cf11afSPaul Mackerras * modify it under the terms of the GNU General Public License 2014cf11afSPaul Mackerras * as published by the Free Software Foundation; either version 2114cf11afSPaul Mackerras * 2 of the License, or (at your option) any later version. 2214cf11afSPaul Mackerras */ 2314cf11afSPaul Mackerras 2414cf11afSPaul Mackerras#include <linux/threads.h> 25b5bbeb23SPaul Mackerras#include <asm/reg.h> 2614cf11afSPaul Mackerras#include <asm/page.h> 2714cf11afSPaul Mackerras#include <asm/mmu.h> 2814cf11afSPaul Mackerras#include <asm/ppc_asm.h> 2914cf11afSPaul Mackerras#include <asm/asm-offsets.h> 3014cf11afSPaul Mackerras#include <asm/bug.h> 3114cf11afSPaul Mackerras#include <asm/cputable.h> 3214cf11afSPaul Mackerras#include <asm/setup.h> 3314cf11afSPaul Mackerras#include <asm/hvcall.h> 34c43a55ffSKelly Daly#include <asm/iseries/lpar_map.h> 356cb7bfebSDavid Gibson#include <asm/thread_info.h> 363f639ee8SStephen Rothwell#include <asm/firmware.h> 3714cf11afSPaul Mackerras 3814cf11afSPaul Mackerras#define DO_SOFT_DISABLE 3914cf11afSPaul Mackerras 4014cf11afSPaul Mackerras/* 4114cf11afSPaul Mackerras * We layout physical memory as follows: 4214cf11afSPaul Mackerras * 0x0000 - 0x00ff : Secondary processor spin code 4314cf11afSPaul Mackerras * 0x0100 - 0x2fff : pSeries Interrupt prologs 4414cf11afSPaul Mackerras * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs 4514cf11afSPaul Mackerras * 0x6000 - 0x6fff : Initial (CPU0) segment table 4614cf11afSPaul Mackerras * 0x7000 - 0x7fff : FWNMI data area 4714cf11afSPaul Mackerras * 0x8000 - : Early init and support code 4814cf11afSPaul Mackerras */ 4914cf11afSPaul Mackerras 5014cf11afSPaul Mackerras/* 5114cf11afSPaul Mackerras * SPRG Usage 5214cf11afSPaul Mackerras * 5314cf11afSPaul Mackerras * Register Definition 5414cf11afSPaul Mackerras * 5514cf11afSPaul Mackerras * SPRG0 reserved for hypervisor 5614cf11afSPaul Mackerras * SPRG1 temp - used to save gpr 5714cf11afSPaul Mackerras * SPRG2 temp - used to save gpr 5814cf11afSPaul Mackerras * SPRG3 virt addr of paca 5914cf11afSPaul Mackerras */ 6014cf11afSPaul Mackerras 6114cf11afSPaul Mackerras/* 6214cf11afSPaul Mackerras * Entering into this code we make the following assumptions: 6314cf11afSPaul Mackerras * For pSeries: 6414cf11afSPaul Mackerras * 1. The MMU is off & open firmware is running in real mode. 6514cf11afSPaul Mackerras * 2. The kernel is entered at __start 6614cf11afSPaul Mackerras * 6714cf11afSPaul Mackerras * For iSeries: 6814cf11afSPaul Mackerras * 1. The MMU is on (as it always is for iSeries) 6914cf11afSPaul Mackerras * 2. The kernel is entered at system_reset_iSeries 7014cf11afSPaul Mackerras */ 7114cf11afSPaul Mackerras 7214cf11afSPaul Mackerras .text 7314cf11afSPaul Mackerras .globl _stext 7414cf11afSPaul Mackerras_stext: 7514cf11afSPaul Mackerras#ifdef CONFIG_PPC_MULTIPLATFORM 7614cf11afSPaul Mackerras_GLOBAL(__start) 7714cf11afSPaul Mackerras /* NOP this out unconditionally */ 7814cf11afSPaul MackerrasBEGIN_FTR_SECTION 7914cf11afSPaul Mackerras b .__start_initialization_multiplatform 8014cf11afSPaul MackerrasEND_FTR_SECTION(0, 1) 8114cf11afSPaul Mackerras#endif /* CONFIG_PPC_MULTIPLATFORM */ 8214cf11afSPaul Mackerras 8314cf11afSPaul Mackerras /* Catch branch to 0 in real mode */ 8414cf11afSPaul Mackerras trap 8514cf11afSPaul Mackerras 8614cf11afSPaul Mackerras /* Secondary processors spin on this value until it goes to 1. */ 8714cf11afSPaul Mackerras .globl __secondary_hold_spinloop 8814cf11afSPaul Mackerras__secondary_hold_spinloop: 8914cf11afSPaul Mackerras .llong 0x0 9014cf11afSPaul Mackerras 9114cf11afSPaul Mackerras /* Secondary processors write this value with their cpu # */ 9214cf11afSPaul Mackerras /* after they enter the spin loop immediately below. */ 9314cf11afSPaul Mackerras .globl __secondary_hold_acknowledge 9414cf11afSPaul Mackerras__secondary_hold_acknowledge: 9514cf11afSPaul Mackerras .llong 0x0 9614cf11afSPaul Mackerras 971dce0e30SMichael Ellerman#ifdef CONFIG_PPC_ISERIES 981dce0e30SMichael Ellerman /* 991dce0e30SMichael Ellerman * At offset 0x20, there is a pointer to iSeries LPAR data. 1001dce0e30SMichael Ellerman * This is required by the hypervisor 1011dce0e30SMichael Ellerman */ 1021dce0e30SMichael Ellerman . = 0x20 1031dce0e30SMichael Ellerman .llong hvReleaseData-KERNELBASE 1041dce0e30SMichael Ellerman#endif /* CONFIG_PPC_ISERIES */ 1051dce0e30SMichael Ellerman 10614cf11afSPaul Mackerras . = 0x60 10714cf11afSPaul Mackerras/* 10814cf11afSPaul Mackerras * The following code is used on pSeries to hold secondary processors 10914cf11afSPaul Mackerras * in a spin loop after they have been freed from OpenFirmware, but 11014cf11afSPaul Mackerras * before the bulk of the kernel has been relocated. This code 11114cf11afSPaul Mackerras * is relocated to physical address 0x60 before prom_init is run. 11214cf11afSPaul Mackerras * All of it must fit below the first exception vector at 0x100. 11314cf11afSPaul Mackerras */ 11414cf11afSPaul Mackerras_GLOBAL(__secondary_hold) 11514cf11afSPaul Mackerras mfmsr r24 11614cf11afSPaul Mackerras ori r24,r24,MSR_RI 11714cf11afSPaul Mackerras mtmsrd r24 /* RI on */ 11814cf11afSPaul Mackerras 119f1870f77SAnton Blanchard /* Grab our physical cpu number */ 12014cf11afSPaul Mackerras mr r24,r3 12114cf11afSPaul Mackerras 12214cf11afSPaul Mackerras /* Tell the master cpu we're here */ 12314cf11afSPaul Mackerras /* Relocation is off & we are located at an address less */ 12414cf11afSPaul Mackerras /* than 0x100, so only need to grab low order offset. */ 12514cf11afSPaul Mackerras std r24,__secondary_hold_acknowledge@l(0) 12614cf11afSPaul Mackerras sync 12714cf11afSPaul Mackerras 12814cf11afSPaul Mackerras /* All secondary cpus wait here until told to start. */ 12914cf11afSPaul Mackerras100: ld r4,__secondary_hold_spinloop@l(0) 13014cf11afSPaul Mackerras cmpdi 0,r4,1 13114cf11afSPaul Mackerras bne 100b 13214cf11afSPaul Mackerras 133f1870f77SAnton Blanchard#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC) 134f39b7a55SOlof Johansson LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init) 135758438a7SMichael Ellerman mtctr r4 13614cf11afSPaul Mackerras mr r3,r24 137758438a7SMichael Ellerman bctr 13814cf11afSPaul Mackerras#else 13914cf11afSPaul Mackerras BUG_OPCODE 14014cf11afSPaul Mackerras#endif 14114cf11afSPaul Mackerras 14214cf11afSPaul Mackerras/* This value is used to mark exception frames on the stack. */ 14314cf11afSPaul Mackerras .section ".toc","aw" 14414cf11afSPaul Mackerrasexception_marker: 14514cf11afSPaul Mackerras .tc ID_72656773_68657265[TC],0x7265677368657265 14614cf11afSPaul Mackerras .text 14714cf11afSPaul Mackerras 14814cf11afSPaul Mackerras/* 14914cf11afSPaul Mackerras * The following macros define the code that appears as 15014cf11afSPaul Mackerras * the prologue to each of the exception handlers. They 15114cf11afSPaul Mackerras * are split into two parts to allow a single kernel binary 15214cf11afSPaul Mackerras * to be used for pSeries and iSeries. 15314cf11afSPaul Mackerras * LOL. One day... - paulus 15414cf11afSPaul Mackerras */ 15514cf11afSPaul Mackerras 15614cf11afSPaul Mackerras/* 15714cf11afSPaul Mackerras * We make as much of the exception code common between native 15814cf11afSPaul Mackerras * exception handlers (including pSeries LPAR) and iSeries LPAR 15914cf11afSPaul Mackerras * implementations as possible. 16014cf11afSPaul Mackerras */ 16114cf11afSPaul Mackerras 16214cf11afSPaul Mackerras/* 16314cf11afSPaul Mackerras * This is the start of the interrupt handlers for pSeries 16414cf11afSPaul Mackerras * This code runs with relocation off. 16514cf11afSPaul Mackerras */ 16614cf11afSPaul Mackerras#define EX_R9 0 16714cf11afSPaul Mackerras#define EX_R10 8 16814cf11afSPaul Mackerras#define EX_R11 16 16914cf11afSPaul Mackerras#define EX_R12 24 17014cf11afSPaul Mackerras#define EX_R13 32 17114cf11afSPaul Mackerras#define EX_SRR0 40 17214cf11afSPaul Mackerras#define EX_DAR 48 17314cf11afSPaul Mackerras#define EX_DSISR 56 17414cf11afSPaul Mackerras#define EX_CCR 60 1753c726f8dSBenjamin Herrenschmidt#define EX_R3 64 1763c726f8dSBenjamin Herrenschmidt#define EX_LR 72 17714cf11afSPaul Mackerras 178758438a7SMichael Ellerman/* 179e58c3495SDavid Gibson * We're short on space and time in the exception prolog, so we can't 180e58c3495SDavid Gibson * use the normal SET_REG_IMMEDIATE macro. Normally we just need the 181e58c3495SDavid Gibson * low halfword of the address, but for Kdump we need the whole low 182e58c3495SDavid Gibson * word. 183758438a7SMichael Ellerman */ 184758438a7SMichael Ellerman#ifdef CONFIG_CRASH_DUMP 185758438a7SMichael Ellerman#define LOAD_HANDLER(reg, label) \ 186758438a7SMichael Ellerman oris reg,reg,(label)@h; /* virt addr of handler ... */ \ 187758438a7SMichael Ellerman ori reg,reg,(label)@l; /* .. and the rest */ 188758438a7SMichael Ellerman#else 189758438a7SMichael Ellerman#define LOAD_HANDLER(reg, label) \ 190758438a7SMichael Ellerman ori reg,reg,(label)@l; /* virt addr of handler ... */ 191758438a7SMichael Ellerman#endif 192758438a7SMichael Ellerman 1939fc0a92cSOlaf Hering/* 1949fc0a92cSOlaf Hering * Equal to EXCEPTION_PROLOG_PSERIES, except that it forces 64bit mode. 1959fc0a92cSOlaf Hering * The firmware calls the registered system_reset_fwnmi and 1969fc0a92cSOlaf Hering * machine_check_fwnmi handlers in 32bit mode if the cpu happens to run 1979fc0a92cSOlaf Hering * a 32bit application at the time of the event. 1989fc0a92cSOlaf Hering * This firmware bug is present on POWER4 and JS20. 1999fc0a92cSOlaf Hering */ 2009fc0a92cSOlaf Hering#define EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(area, label) \ 2019fc0a92cSOlaf Hering mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \ 2029fc0a92cSOlaf Hering std r9,area+EX_R9(r13); /* save r9 - r12 */ \ 2039fc0a92cSOlaf Hering std r10,area+EX_R10(r13); \ 2049fc0a92cSOlaf Hering std r11,area+EX_R11(r13); \ 2059fc0a92cSOlaf Hering std r12,area+EX_R12(r13); \ 2069fc0a92cSOlaf Hering mfspr r9,SPRN_SPRG1; \ 2079fc0a92cSOlaf Hering std r9,area+EX_R13(r13); \ 2089fc0a92cSOlaf Hering mfcr r9; \ 2099fc0a92cSOlaf Hering clrrdi r12,r13,32; /* get high part of &label */ \ 2109fc0a92cSOlaf Hering mfmsr r10; \ 2119fc0a92cSOlaf Hering /* force 64bit mode */ \ 2129fc0a92cSOlaf Hering li r11,5; /* MSR_SF_LG|MSR_ISF_LG */ \ 2139fc0a92cSOlaf Hering rldimi r10,r11,61,0; /* insert into top 3 bits */ \ 2149fc0a92cSOlaf Hering /* done 64bit mode */ \ 2159fc0a92cSOlaf Hering mfspr r11,SPRN_SRR0; /* save SRR0 */ \ 2169fc0a92cSOlaf Hering LOAD_HANDLER(r12,label) \ 2179fc0a92cSOlaf Hering ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \ 2189fc0a92cSOlaf Hering mtspr SPRN_SRR0,r12; \ 2199fc0a92cSOlaf Hering mfspr r12,SPRN_SRR1; /* and SRR1 */ \ 2209fc0a92cSOlaf Hering mtspr SPRN_SRR1,r10; \ 2219fc0a92cSOlaf Hering rfid; \ 2229fc0a92cSOlaf Hering b . /* prevent speculative execution */ 2239fc0a92cSOlaf Hering 22414cf11afSPaul Mackerras#define EXCEPTION_PROLOG_PSERIES(area, label) \ 225b5bbeb23SPaul Mackerras mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \ 22614cf11afSPaul Mackerras std r9,area+EX_R9(r13); /* save r9 - r12 */ \ 22714cf11afSPaul Mackerras std r10,area+EX_R10(r13); \ 22814cf11afSPaul Mackerras std r11,area+EX_R11(r13); \ 22914cf11afSPaul Mackerras std r12,area+EX_R12(r13); \ 230b5bbeb23SPaul Mackerras mfspr r9,SPRN_SPRG1; \ 23114cf11afSPaul Mackerras std r9,area+EX_R13(r13); \ 23214cf11afSPaul Mackerras mfcr r9; \ 23314cf11afSPaul Mackerras clrrdi r12,r13,32; /* get high part of &label */ \ 23414cf11afSPaul Mackerras mfmsr r10; \ 235b5bbeb23SPaul Mackerras mfspr r11,SPRN_SRR0; /* save SRR0 */ \ 236758438a7SMichael Ellerman LOAD_HANDLER(r12,label) \ 23714cf11afSPaul Mackerras ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \ 238b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r12; \ 239b5bbeb23SPaul Mackerras mfspr r12,SPRN_SRR1; /* and SRR1 */ \ 240b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r10; \ 24114cf11afSPaul Mackerras rfid; \ 24214cf11afSPaul Mackerras b . /* prevent speculative execution */ 24314cf11afSPaul Mackerras 24414cf11afSPaul Mackerras/* 24514cf11afSPaul Mackerras * This is the start of the interrupt handlers for iSeries 24614cf11afSPaul Mackerras * This code runs with relocation on. 24714cf11afSPaul Mackerras */ 24814cf11afSPaul Mackerras#define EXCEPTION_PROLOG_ISERIES_1(area) \ 249b5bbeb23SPaul Mackerras mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \ 25014cf11afSPaul Mackerras std r9,area+EX_R9(r13); /* save r9 - r12 */ \ 25114cf11afSPaul Mackerras std r10,area+EX_R10(r13); \ 25214cf11afSPaul Mackerras std r11,area+EX_R11(r13); \ 25314cf11afSPaul Mackerras std r12,area+EX_R12(r13); \ 254b5bbeb23SPaul Mackerras mfspr r9,SPRN_SPRG1; \ 25514cf11afSPaul Mackerras std r9,area+EX_R13(r13); \ 25614cf11afSPaul Mackerras mfcr r9 25714cf11afSPaul Mackerras 25814cf11afSPaul Mackerras#define EXCEPTION_PROLOG_ISERIES_2 \ 25914cf11afSPaul Mackerras mfmsr r10; \ 2603356bb9fSDavid Gibson ld r12,PACALPPACAPTR(r13); \ 2613356bb9fSDavid Gibson ld r11,LPPACASRR0(r12); \ 2623356bb9fSDavid Gibson ld r12,LPPACASRR1(r12); \ 26314cf11afSPaul Mackerras ori r10,r10,MSR_RI; \ 26414cf11afSPaul Mackerras mtmsrd r10,1 26514cf11afSPaul Mackerras 26614cf11afSPaul Mackerras/* 26714cf11afSPaul Mackerras * The common exception prolog is used for all except a few exceptions 26814cf11afSPaul Mackerras * such as a segment miss on a kernel address. We have to be prepared 26914cf11afSPaul Mackerras * to take another exception from the point where we first touch the 27014cf11afSPaul Mackerras * kernel stack onwards. 27114cf11afSPaul Mackerras * 27214cf11afSPaul Mackerras * On entry r13 points to the paca, r9-r13 are saved in the paca, 27314cf11afSPaul Mackerras * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and 27414cf11afSPaul Mackerras * SRR1, and relocation is on. 27514cf11afSPaul Mackerras */ 27614cf11afSPaul Mackerras#define EXCEPTION_PROLOG_COMMON(n, area) \ 27714cf11afSPaul Mackerras andi. r10,r12,MSR_PR; /* See if coming from user */ \ 27814cf11afSPaul Mackerras mr r10,r1; /* Save r1 */ \ 27914cf11afSPaul Mackerras subi r1,r1,INT_FRAME_SIZE; /* alloc frame on kernel stack */ \ 28014cf11afSPaul Mackerras beq- 1f; \ 28114cf11afSPaul Mackerras ld r1,PACAKSAVE(r13); /* kernel stack to use */ \ 28214cf11afSPaul Mackerras1: cmpdi cr1,r1,0; /* check if r1 is in userspace */ \ 28314cf11afSPaul Mackerras bge- cr1,bad_stack; /* abort if it is */ \ 28414cf11afSPaul Mackerras std r9,_CCR(r1); /* save CR in stackframe */ \ 28514cf11afSPaul Mackerras std r11,_NIP(r1); /* save SRR0 in stackframe */ \ 28614cf11afSPaul Mackerras std r12,_MSR(r1); /* save SRR1 in stackframe */ \ 28714cf11afSPaul Mackerras std r10,0(r1); /* make stack chain pointer */ \ 28814cf11afSPaul Mackerras std r0,GPR0(r1); /* save r0 in stackframe */ \ 28914cf11afSPaul Mackerras std r10,GPR1(r1); /* save r1 in stackframe */ \ 290c6622f63SPaul Mackerras ACCOUNT_CPU_USER_ENTRY(r9, r10); \ 29114cf11afSPaul Mackerras std r2,GPR2(r1); /* save r2 in stackframe */ \ 29214cf11afSPaul Mackerras SAVE_4GPRS(3, r1); /* save r3 - r6 in stackframe */ \ 29314cf11afSPaul Mackerras SAVE_2GPRS(7, r1); /* save r7, r8 in stackframe */ \ 29414cf11afSPaul Mackerras ld r9,area+EX_R9(r13); /* move r9, r10 to stackframe */ \ 29514cf11afSPaul Mackerras ld r10,area+EX_R10(r13); \ 29614cf11afSPaul Mackerras std r9,GPR9(r1); \ 29714cf11afSPaul Mackerras std r10,GPR10(r1); \ 29814cf11afSPaul Mackerras ld r9,area+EX_R11(r13); /* move r11 - r13 to stackframe */ \ 29914cf11afSPaul Mackerras ld r10,area+EX_R12(r13); \ 30014cf11afSPaul Mackerras ld r11,area+EX_R13(r13); \ 30114cf11afSPaul Mackerras std r9,GPR11(r1); \ 30214cf11afSPaul Mackerras std r10,GPR12(r1); \ 30314cf11afSPaul Mackerras std r11,GPR13(r1); \ 30414cf11afSPaul Mackerras ld r2,PACATOC(r13); /* get kernel TOC into r2 */ \ 30514cf11afSPaul Mackerras mflr r9; /* save LR in stackframe */ \ 30614cf11afSPaul Mackerras std r9,_LINK(r1); \ 30714cf11afSPaul Mackerras mfctr r10; /* save CTR in stackframe */ \ 30814cf11afSPaul Mackerras std r10,_CTR(r1); \ 309*d04c56f7SPaul Mackerras lbz r10,PACASOFTIRQEN(r13); \ 310b5bbeb23SPaul Mackerras mfspr r11,SPRN_XER; /* save XER in stackframe */ \ 311*d04c56f7SPaul Mackerras std r10,SOFTE(r1); \ 31214cf11afSPaul Mackerras std r11,_XER(r1); \ 31314cf11afSPaul Mackerras li r9,(n)+1; \ 31414cf11afSPaul Mackerras std r9,_TRAP(r1); /* set trap number */ \ 31514cf11afSPaul Mackerras li r10,0; \ 31614cf11afSPaul Mackerras ld r11,exception_marker@toc(r2); \ 31714cf11afSPaul Mackerras std r10,RESULT(r1); /* clear regs->result */ \ 31814cf11afSPaul Mackerras std r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame */ 31914cf11afSPaul Mackerras 32014cf11afSPaul Mackerras/* 32114cf11afSPaul Mackerras * Exception vectors. 32214cf11afSPaul Mackerras */ 32314cf11afSPaul Mackerras#define STD_EXCEPTION_PSERIES(n, label) \ 32414cf11afSPaul Mackerras . = n; \ 32514cf11afSPaul Mackerras .globl label##_pSeries; \ 32614cf11afSPaul Mackerraslabel##_pSeries: \ 32714cf11afSPaul Mackerras HMT_MEDIUM; \ 328b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13; /* save r13 */ \ 32914cf11afSPaul Mackerras EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common) 33014cf11afSPaul Mackerras 331acf7d768SBenjamin Herrenschmidt#define HSTD_EXCEPTION_PSERIES(n, label) \ 332acf7d768SBenjamin Herrenschmidt . = n; \ 333acf7d768SBenjamin Herrenschmidt .globl label##_pSeries; \ 334acf7d768SBenjamin Herrenschmidtlabel##_pSeries: \ 335acf7d768SBenjamin Herrenschmidt HMT_MEDIUM; \ 336acf7d768SBenjamin Herrenschmidt mtspr SPRN_SPRG1,r20; /* save r20 */ \ 337acf7d768SBenjamin Herrenschmidt mfspr r20,SPRN_HSRR0; /* copy HSRR0 to SRR0 */ \ 338acf7d768SBenjamin Herrenschmidt mtspr SPRN_SRR0,r20; \ 339acf7d768SBenjamin Herrenschmidt mfspr r20,SPRN_HSRR1; /* copy HSRR0 to SRR0 */ \ 340acf7d768SBenjamin Herrenschmidt mtspr SPRN_SRR1,r20; \ 341acf7d768SBenjamin Herrenschmidt mfspr r20,SPRN_SPRG1; /* restore r20 */ \ 342acf7d768SBenjamin Herrenschmidt mtspr SPRN_SPRG1,r13; /* save r13 */ \ 343acf7d768SBenjamin Herrenschmidt EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common) 344acf7d768SBenjamin Herrenschmidt 345acf7d768SBenjamin Herrenschmidt 346*d04c56f7SPaul Mackerras#define MASKABLE_EXCEPTION_PSERIES(n, label) \ 347*d04c56f7SPaul Mackerras . = n; \ 348*d04c56f7SPaul Mackerras .globl label##_pSeries; \ 349*d04c56f7SPaul Mackerraslabel##_pSeries: \ 350*d04c56f7SPaul Mackerras HMT_MEDIUM; \ 351*d04c56f7SPaul Mackerras mtspr SPRN_SPRG1,r13; /* save r13 */ \ 352*d04c56f7SPaul Mackerras mfspr r13,SPRN_SPRG3; /* get paca address into r13 */ \ 353*d04c56f7SPaul Mackerras std r9,PACA_EXGEN+EX_R9(r13); /* save r9, r10 */ \ 354*d04c56f7SPaul Mackerras std r10,PACA_EXGEN+EX_R10(r13); \ 355*d04c56f7SPaul Mackerras lbz r10,PACASOFTIRQEN(r13); \ 356*d04c56f7SPaul Mackerras mfcr r9; \ 357*d04c56f7SPaul Mackerras cmpwi r10,0; \ 358*d04c56f7SPaul Mackerras beq masked_interrupt; \ 359*d04c56f7SPaul Mackerras mfspr r10,SPRN_SPRG1; \ 360*d04c56f7SPaul Mackerras std r10,PACA_EXGEN+EX_R13(r13); \ 361*d04c56f7SPaul Mackerras std r11,PACA_EXGEN+EX_R11(r13); \ 362*d04c56f7SPaul Mackerras std r12,PACA_EXGEN+EX_R12(r13); \ 363*d04c56f7SPaul Mackerras clrrdi r12,r13,32; /* get high part of &label */ \ 364*d04c56f7SPaul Mackerras mfmsr r10; \ 365*d04c56f7SPaul Mackerras mfspr r11,SPRN_SRR0; /* save SRR0 */ \ 366*d04c56f7SPaul Mackerras LOAD_HANDLER(r12,label##_common) \ 367*d04c56f7SPaul Mackerras ori r10,r10,MSR_IR|MSR_DR|MSR_RI; \ 368*d04c56f7SPaul Mackerras mtspr SPRN_SRR0,r12; \ 369*d04c56f7SPaul Mackerras mfspr r12,SPRN_SRR1; /* and SRR1 */ \ 370*d04c56f7SPaul Mackerras mtspr SPRN_SRR1,r10; \ 371*d04c56f7SPaul Mackerras rfid; \ 372*d04c56f7SPaul Mackerras b . /* prevent speculative execution */ 373*d04c56f7SPaul Mackerras 37414cf11afSPaul Mackerras#define STD_EXCEPTION_ISERIES(n, label, area) \ 37514cf11afSPaul Mackerras .globl label##_iSeries; \ 37614cf11afSPaul Mackerraslabel##_iSeries: \ 37714cf11afSPaul Mackerras HMT_MEDIUM; \ 378b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13; /* save r13 */ \ 37914cf11afSPaul Mackerras EXCEPTION_PROLOG_ISERIES_1(area); \ 38014cf11afSPaul Mackerras EXCEPTION_PROLOG_ISERIES_2; \ 38114cf11afSPaul Mackerras b label##_common 38214cf11afSPaul Mackerras 38314cf11afSPaul Mackerras#define MASKABLE_EXCEPTION_ISERIES(n, label) \ 38414cf11afSPaul Mackerras .globl label##_iSeries; \ 38514cf11afSPaul Mackerraslabel##_iSeries: \ 38614cf11afSPaul Mackerras HMT_MEDIUM; \ 387b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13; /* save r13 */ \ 38814cf11afSPaul Mackerras EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN); \ 389*d04c56f7SPaul Mackerras lbz r10,PACASOFTIRQEN(r13); \ 39014cf11afSPaul Mackerras cmpwi 0,r10,0; \ 39114cf11afSPaul Mackerras beq- label##_iSeries_masked; \ 39214cf11afSPaul Mackerras EXCEPTION_PROLOG_ISERIES_2; \ 39314cf11afSPaul Mackerras b label##_common; \ 39414cf11afSPaul Mackerras 395*d04c56f7SPaul Mackerras#ifdef CONFIG_PPC_ISERIES 39614cf11afSPaul Mackerras#define DISABLE_INTS \ 39714cf11afSPaul Mackerras li r11,0; \ 398*d04c56f7SPaul Mackerras stb r11,PACASOFTIRQEN(r13); \ 399*d04c56f7SPaul MackerrasBEGIN_FW_FTR_SECTION; \ 400*d04c56f7SPaul Mackerras stb r11,PACAHARDIRQEN(r13); \ 401*d04c56f7SPaul MackerrasEND_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES); \ 402*d04c56f7SPaul MackerrasBEGIN_FW_FTR_SECTION; \ 40314cf11afSPaul Mackerras mfmsr r10; \ 40414cf11afSPaul Mackerras ori r10,r10,MSR_EE; \ 4053f639ee8SStephen Rothwell mtmsrd r10,1; \ 4063f639ee8SStephen RothwellEND_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) 40714cf11afSPaul Mackerras 408*d04c56f7SPaul Mackerras#else 409*d04c56f7SPaul Mackerras#define DISABLE_INTS \ 410*d04c56f7SPaul Mackerras li r11,0; \ 411*d04c56f7SPaul Mackerras stb r11,PACASOFTIRQEN(r13); \ 412*d04c56f7SPaul Mackerras stb r11,PACAHARDIRQEN(r13) 41314cf11afSPaul Mackerras 414*d04c56f7SPaul Mackerras#endif /* CONFIG_PPC_ISERIES */ 41514cf11afSPaul Mackerras 41614cf11afSPaul Mackerras#define ENABLE_INTS \ 41714cf11afSPaul Mackerras ld r12,_MSR(r1); \ 41814cf11afSPaul Mackerras mfmsr r11; \ 41914cf11afSPaul Mackerras rlwimi r11,r12,0,MSR_EE; \ 42014cf11afSPaul Mackerras mtmsrd r11,1 42114cf11afSPaul Mackerras 42214cf11afSPaul Mackerras#define STD_EXCEPTION_COMMON(trap, label, hdlr) \ 42314cf11afSPaul Mackerras .align 7; \ 42414cf11afSPaul Mackerras .globl label##_common; \ 42514cf11afSPaul Mackerraslabel##_common: \ 42614cf11afSPaul Mackerras EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \ 42714cf11afSPaul Mackerras DISABLE_INTS; \ 42814cf11afSPaul Mackerras bl .save_nvgprs; \ 42914cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD; \ 43014cf11afSPaul Mackerras bl hdlr; \ 43114cf11afSPaul Mackerras b .ret_from_except 43214cf11afSPaul Mackerras 433f39224a8SPaul Mackerras/* 434f39224a8SPaul Mackerras * Like STD_EXCEPTION_COMMON, but for exceptions that can occur 435f39224a8SPaul Mackerras * in the idle task and therefore need the special idle handling. 436f39224a8SPaul Mackerras */ 437f39224a8SPaul Mackerras#define STD_EXCEPTION_COMMON_IDLE(trap, label, hdlr) \ 438f39224a8SPaul Mackerras .align 7; \ 439f39224a8SPaul Mackerras .globl label##_common; \ 440f39224a8SPaul Mackerraslabel##_common: \ 441f39224a8SPaul Mackerras EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \ 442f39224a8SPaul Mackerras FINISH_NAP; \ 443f39224a8SPaul Mackerras DISABLE_INTS; \ 444f39224a8SPaul Mackerras bl .save_nvgprs; \ 445f39224a8SPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD; \ 446f39224a8SPaul Mackerras bl hdlr; \ 447f39224a8SPaul Mackerras b .ret_from_except 448f39224a8SPaul Mackerras 44914cf11afSPaul Mackerras#define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr) \ 45014cf11afSPaul Mackerras .align 7; \ 45114cf11afSPaul Mackerras .globl label##_common; \ 45214cf11afSPaul Mackerraslabel##_common: \ 45314cf11afSPaul Mackerras EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN); \ 454f39224a8SPaul Mackerras FINISH_NAP; \ 45514cf11afSPaul Mackerras DISABLE_INTS; \ 456cb2c9b27SAnton Blanchard bl .ppc64_runlatch_on; \ 45714cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD; \ 45814cf11afSPaul Mackerras bl hdlr; \ 45914cf11afSPaul Mackerras b .ret_from_except_lite 46014cf11afSPaul Mackerras 46114cf11afSPaul Mackerras/* 462f39224a8SPaul Mackerras * When the idle code in power4_idle puts the CPU into NAP mode, 463f39224a8SPaul Mackerras * it has to do so in a loop, and relies on the external interrupt 464f39224a8SPaul Mackerras * and decrementer interrupt entry code to get it out of the loop. 465f39224a8SPaul Mackerras * It sets the _TLF_NAPPING bit in current_thread_info()->local_flags 466f39224a8SPaul Mackerras * to signal that it is in the loop and needs help to get out. 467f39224a8SPaul Mackerras */ 468f39224a8SPaul Mackerras#ifdef CONFIG_PPC_970_NAP 469f39224a8SPaul Mackerras#define FINISH_NAP \ 470f39224a8SPaul MackerrasBEGIN_FTR_SECTION \ 471f39224a8SPaul Mackerras clrrdi r11,r1,THREAD_SHIFT; \ 472f39224a8SPaul Mackerras ld r9,TI_LOCAL_FLAGS(r11); \ 473f39224a8SPaul Mackerras andi. r10,r9,_TLF_NAPPING; \ 474f39224a8SPaul Mackerras bnel power4_fixup_nap; \ 475f39224a8SPaul MackerrasEND_FTR_SECTION_IFSET(CPU_FTR_CAN_NAP) 476f39224a8SPaul Mackerras#else 477f39224a8SPaul Mackerras#define FINISH_NAP 478f39224a8SPaul Mackerras#endif 479f39224a8SPaul Mackerras 480f39224a8SPaul Mackerras/* 48114cf11afSPaul Mackerras * Start of pSeries system interrupt routines 48214cf11afSPaul Mackerras */ 48314cf11afSPaul Mackerras . = 0x100 48414cf11afSPaul Mackerras .globl __start_interrupts 48514cf11afSPaul Mackerras__start_interrupts: 48614cf11afSPaul Mackerras 48714cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0x100, system_reset) 48814cf11afSPaul Mackerras 48914cf11afSPaul Mackerras . = 0x200 49014cf11afSPaul Mackerras_machine_check_pSeries: 49114cf11afSPaul Mackerras HMT_MEDIUM 492b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13 /* save r13 */ 49314cf11afSPaul Mackerras EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common) 49414cf11afSPaul Mackerras 49514cf11afSPaul Mackerras . = 0x300 49614cf11afSPaul Mackerras .globl data_access_pSeries 49714cf11afSPaul Mackerrasdata_access_pSeries: 49814cf11afSPaul Mackerras HMT_MEDIUM 499b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13 50014cf11afSPaul MackerrasBEGIN_FTR_SECTION 501b5bbeb23SPaul Mackerras mtspr SPRN_SPRG2,r12 502b5bbeb23SPaul Mackerras mfspr r13,SPRN_DAR 503b5bbeb23SPaul Mackerras mfspr r12,SPRN_DSISR 50414cf11afSPaul Mackerras srdi r13,r13,60 50514cf11afSPaul Mackerras rlwimi r13,r12,16,0x20 50614cf11afSPaul Mackerras mfcr r12 50714cf11afSPaul Mackerras cmpwi r13,0x2c 50814cf11afSPaul Mackerras beq .do_stab_bolted_pSeries 50914cf11afSPaul Mackerras mtcrf 0x80,r12 510b5bbeb23SPaul Mackerras mfspr r12,SPRN_SPRG2 51114cf11afSPaul MackerrasEND_FTR_SECTION_IFCLR(CPU_FTR_SLB) 51214cf11afSPaul Mackerras EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common) 51314cf11afSPaul Mackerras 51414cf11afSPaul Mackerras . = 0x380 51514cf11afSPaul Mackerras .globl data_access_slb_pSeries 51614cf11afSPaul Mackerrasdata_access_slb_pSeries: 51714cf11afSPaul Mackerras HMT_MEDIUM 518b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13 519b5bbeb23SPaul Mackerras mfspr r13,SPRN_SPRG3 /* get paca address into r13 */ 5203c726f8dSBenjamin Herrenschmidt std r3,PACA_EXSLB+EX_R3(r13) 5213c726f8dSBenjamin Herrenschmidt mfspr r3,SPRN_DAR 52214cf11afSPaul Mackerras std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */ 5233c726f8dSBenjamin Herrenschmidt mfcr r9 5243c726f8dSBenjamin Herrenschmidt#ifdef __DISABLED__ 5253c726f8dSBenjamin Herrenschmidt /* Keep that around for when we re-implement dynamic VSIDs */ 5263c726f8dSBenjamin Herrenschmidt cmpdi r3,0 5273c726f8dSBenjamin Herrenschmidt bge slb_miss_user_pseries 5283c726f8dSBenjamin Herrenschmidt#endif /* __DISABLED__ */ 52914cf11afSPaul Mackerras std r10,PACA_EXSLB+EX_R10(r13) 53014cf11afSPaul Mackerras std r11,PACA_EXSLB+EX_R11(r13) 53114cf11afSPaul Mackerras std r12,PACA_EXSLB+EX_R12(r13) 5323c726f8dSBenjamin Herrenschmidt mfspr r10,SPRN_SPRG1 5333c726f8dSBenjamin Herrenschmidt std r10,PACA_EXSLB+EX_R13(r13) 534b5bbeb23SPaul Mackerras mfspr r12,SPRN_SRR1 /* and SRR1 */ 5353c726f8dSBenjamin Herrenschmidt b .slb_miss_realmode /* Rel. branch works in real mode */ 53614cf11afSPaul Mackerras 53714cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0x400, instruction_access) 53814cf11afSPaul Mackerras 53914cf11afSPaul Mackerras . = 0x480 54014cf11afSPaul Mackerras .globl instruction_access_slb_pSeries 54114cf11afSPaul Mackerrasinstruction_access_slb_pSeries: 54214cf11afSPaul Mackerras HMT_MEDIUM 543b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13 544b5bbeb23SPaul Mackerras mfspr r13,SPRN_SPRG3 /* get paca address into r13 */ 5453c726f8dSBenjamin Herrenschmidt std r3,PACA_EXSLB+EX_R3(r13) 5463c726f8dSBenjamin Herrenschmidt mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */ 54714cf11afSPaul Mackerras std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */ 5483c726f8dSBenjamin Herrenschmidt mfcr r9 5493c726f8dSBenjamin Herrenschmidt#ifdef __DISABLED__ 5503c726f8dSBenjamin Herrenschmidt /* Keep that around for when we re-implement dynamic VSIDs */ 5513c726f8dSBenjamin Herrenschmidt cmpdi r3,0 5523c726f8dSBenjamin Herrenschmidt bge slb_miss_user_pseries 5533c726f8dSBenjamin Herrenschmidt#endif /* __DISABLED__ */ 55414cf11afSPaul Mackerras std r10,PACA_EXSLB+EX_R10(r13) 55514cf11afSPaul Mackerras std r11,PACA_EXSLB+EX_R11(r13) 55614cf11afSPaul Mackerras std r12,PACA_EXSLB+EX_R12(r13) 5573c726f8dSBenjamin Herrenschmidt mfspr r10,SPRN_SPRG1 5583c726f8dSBenjamin Herrenschmidt std r10,PACA_EXSLB+EX_R13(r13) 559b5bbeb23SPaul Mackerras mfspr r12,SPRN_SRR1 /* and SRR1 */ 5603c726f8dSBenjamin Herrenschmidt b .slb_miss_realmode /* Rel. branch works in real mode */ 56114cf11afSPaul Mackerras 562*d04c56f7SPaul Mackerras MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt) 56314cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0x600, alignment) 56414cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0x700, program_check) 56514cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0x800, fp_unavailable) 566*d04c56f7SPaul Mackerras MASKABLE_EXCEPTION_PSERIES(0x900, decrementer) 56714cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0xa00, trap_0a) 56814cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0xb00, trap_0b) 56914cf11afSPaul Mackerras 57014cf11afSPaul Mackerras . = 0xc00 57114cf11afSPaul Mackerras .globl system_call_pSeries 57214cf11afSPaul Mackerrassystem_call_pSeries: 57314cf11afSPaul Mackerras HMT_MEDIUM 57414cf11afSPaul Mackerras mr r9,r13 57514cf11afSPaul Mackerras mfmsr r10 576b5bbeb23SPaul Mackerras mfspr r13,SPRN_SPRG3 577b5bbeb23SPaul Mackerras mfspr r11,SPRN_SRR0 57814cf11afSPaul Mackerras clrrdi r12,r13,32 57914cf11afSPaul Mackerras oris r12,r12,system_call_common@h 58014cf11afSPaul Mackerras ori r12,r12,system_call_common@l 581b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r12 58214cf11afSPaul Mackerras ori r10,r10,MSR_IR|MSR_DR|MSR_RI 583b5bbeb23SPaul Mackerras mfspr r12,SPRN_SRR1 584b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r10 58514cf11afSPaul Mackerras rfid 58614cf11afSPaul Mackerras b . /* prevent speculative execution */ 58714cf11afSPaul Mackerras 58814cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0xd00, single_step) 58914cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0xe00, trap_0e) 59014cf11afSPaul Mackerras 59114cf11afSPaul Mackerras /* We need to deal with the Altivec unavailable exception 59214cf11afSPaul Mackerras * here which is at 0xf20, thus in the middle of the 59314cf11afSPaul Mackerras * prolog code of the PerformanceMonitor one. A little 59414cf11afSPaul Mackerras * trickery is thus necessary 59514cf11afSPaul Mackerras */ 59614cf11afSPaul Mackerras . = 0xf00 59714cf11afSPaul Mackerras b performance_monitor_pSeries 59814cf11afSPaul Mackerras 59914cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable) 60014cf11afSPaul Mackerras 601acf7d768SBenjamin Herrenschmidt#ifdef CONFIG_CBE_RAS 602acf7d768SBenjamin Herrenschmidt HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error) 603acf7d768SBenjamin Herrenschmidt#endif /* CONFIG_CBE_RAS */ 60414cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint) 605acf7d768SBenjamin Herrenschmidt#ifdef CONFIG_CBE_RAS 606acf7d768SBenjamin Herrenschmidt HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance) 607acf7d768SBenjamin Herrenschmidt#endif /* CONFIG_CBE_RAS */ 60814cf11afSPaul Mackerras STD_EXCEPTION_PSERIES(0x1700, altivec_assist) 609acf7d768SBenjamin Herrenschmidt#ifdef CONFIG_CBE_RAS 610acf7d768SBenjamin Herrenschmidt HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal) 611acf7d768SBenjamin Herrenschmidt#endif /* CONFIG_CBE_RAS */ 61214cf11afSPaul Mackerras 61314cf11afSPaul Mackerras . = 0x3000 61414cf11afSPaul Mackerras 61514cf11afSPaul Mackerras/*** pSeries interrupt support ***/ 61614cf11afSPaul Mackerras 61714cf11afSPaul Mackerras /* moved from 0xf00 */ 618*d04c56f7SPaul Mackerras MASKABLE_EXCEPTION_PSERIES(., performance_monitor) 619*d04c56f7SPaul Mackerras 620*d04c56f7SPaul Mackerras/* 621*d04c56f7SPaul Mackerras * An interrupt came in while soft-disabled; clear EE in SRR1, 622*d04c56f7SPaul Mackerras * clear paca->hard_enabled and return. 623*d04c56f7SPaul Mackerras */ 624*d04c56f7SPaul Mackerrasmasked_interrupt: 625*d04c56f7SPaul Mackerras stb r10,PACAHARDIRQEN(r13) 626*d04c56f7SPaul Mackerras mtcrf 0x80,r9 627*d04c56f7SPaul Mackerras ld r9,PACA_EXGEN+EX_R9(r13) 628*d04c56f7SPaul Mackerras mfspr r10,SPRN_SRR1 629*d04c56f7SPaul Mackerras rldicl r10,r10,48,1 /* clear MSR_EE */ 630*d04c56f7SPaul Mackerras rotldi r10,r10,16 631*d04c56f7SPaul Mackerras mtspr SPRN_SRR1,r10 632*d04c56f7SPaul Mackerras ld r10,PACA_EXGEN+EX_R10(r13) 633*d04c56f7SPaul Mackerras mfspr r13,SPRN_SPRG1 634*d04c56f7SPaul Mackerras rfid 635*d04c56f7SPaul Mackerras b . 63614cf11afSPaul Mackerras 63714cf11afSPaul Mackerras .align 7 63814cf11afSPaul Mackerras_GLOBAL(do_stab_bolted_pSeries) 63914cf11afSPaul Mackerras mtcrf 0x80,r12 640b5bbeb23SPaul Mackerras mfspr r12,SPRN_SPRG2 64114cf11afSPaul Mackerras EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted) 64214cf11afSPaul Mackerras 64314cf11afSPaul Mackerras/* 6443c726f8dSBenjamin Herrenschmidt * We have some room here we use that to put 6453c726f8dSBenjamin Herrenschmidt * the peries slb miss user trampoline code so it's reasonably 6463c726f8dSBenjamin Herrenschmidt * away from slb_miss_user_common to avoid problems with rfid 6473c726f8dSBenjamin Herrenschmidt * 6483c726f8dSBenjamin Herrenschmidt * This is used for when the SLB miss handler has to go virtual, 6493c726f8dSBenjamin Herrenschmidt * which doesn't happen for now anymore but will once we re-implement 6503c726f8dSBenjamin Herrenschmidt * dynamic VSIDs for shared page tables 6513c726f8dSBenjamin Herrenschmidt */ 6523c726f8dSBenjamin Herrenschmidt#ifdef __DISABLED__ 6533c726f8dSBenjamin Herrenschmidtslb_miss_user_pseries: 6543c726f8dSBenjamin Herrenschmidt std r10,PACA_EXGEN+EX_R10(r13) 6553c726f8dSBenjamin Herrenschmidt std r11,PACA_EXGEN+EX_R11(r13) 6563c726f8dSBenjamin Herrenschmidt std r12,PACA_EXGEN+EX_R12(r13) 6573c726f8dSBenjamin Herrenschmidt mfspr r10,SPRG1 6583c726f8dSBenjamin Herrenschmidt ld r11,PACA_EXSLB+EX_R9(r13) 6593c726f8dSBenjamin Herrenschmidt ld r12,PACA_EXSLB+EX_R3(r13) 6603c726f8dSBenjamin Herrenschmidt std r10,PACA_EXGEN+EX_R13(r13) 6613c726f8dSBenjamin Herrenschmidt std r11,PACA_EXGEN+EX_R9(r13) 6623c726f8dSBenjamin Herrenschmidt std r12,PACA_EXGEN+EX_R3(r13) 6633c726f8dSBenjamin Herrenschmidt clrrdi r12,r13,32 6643c726f8dSBenjamin Herrenschmidt mfmsr r10 6653c726f8dSBenjamin Herrenschmidt mfspr r11,SRR0 /* save SRR0 */ 6663c726f8dSBenjamin Herrenschmidt ori r12,r12,slb_miss_user_common@l /* virt addr of handler */ 6673c726f8dSBenjamin Herrenschmidt ori r10,r10,MSR_IR|MSR_DR|MSR_RI 6683c726f8dSBenjamin Herrenschmidt mtspr SRR0,r12 6693c726f8dSBenjamin Herrenschmidt mfspr r12,SRR1 /* and SRR1 */ 6703c726f8dSBenjamin Herrenschmidt mtspr SRR1,r10 6713c726f8dSBenjamin Herrenschmidt rfid 6723c726f8dSBenjamin Herrenschmidt b . /* prevent spec. execution */ 6733c726f8dSBenjamin Herrenschmidt#endif /* __DISABLED__ */ 6743c726f8dSBenjamin Herrenschmidt 6753c726f8dSBenjamin Herrenschmidt/* 67614cf11afSPaul Mackerras * Vectors for the FWNMI option. Share common code. 67714cf11afSPaul Mackerras */ 67814cf11afSPaul Mackerras .globl system_reset_fwnmi 6798c4f1f29SMichael Ellerman .align 7 68014cf11afSPaul Mackerrassystem_reset_fwnmi: 68114cf11afSPaul Mackerras HMT_MEDIUM 682b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13 /* save r13 */ 6839fc0a92cSOlaf Hering EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common) 68414cf11afSPaul Mackerras 68514cf11afSPaul Mackerras .globl machine_check_fwnmi 6868c4f1f29SMichael Ellerman .align 7 68714cf11afSPaul Mackerrasmachine_check_fwnmi: 68814cf11afSPaul Mackerras HMT_MEDIUM 689b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13 /* save r13 */ 6909fc0a92cSOlaf Hering EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common) 69114cf11afSPaul Mackerras 69214cf11afSPaul Mackerras#ifdef CONFIG_PPC_ISERIES 69314cf11afSPaul Mackerras/*** ISeries-LPAR interrupt handlers ***/ 69414cf11afSPaul Mackerras 69514cf11afSPaul Mackerras STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC) 69614cf11afSPaul Mackerras 69714cf11afSPaul Mackerras .globl data_access_iSeries 69814cf11afSPaul Mackerrasdata_access_iSeries: 699b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13 70014cf11afSPaul MackerrasBEGIN_FTR_SECTION 701b5bbeb23SPaul Mackerras mtspr SPRN_SPRG2,r12 702b5bbeb23SPaul Mackerras mfspr r13,SPRN_DAR 703b5bbeb23SPaul Mackerras mfspr r12,SPRN_DSISR 70414cf11afSPaul Mackerras srdi r13,r13,60 70514cf11afSPaul Mackerras rlwimi r13,r12,16,0x20 70614cf11afSPaul Mackerras mfcr r12 70714cf11afSPaul Mackerras cmpwi r13,0x2c 70814cf11afSPaul Mackerras beq .do_stab_bolted_iSeries 70914cf11afSPaul Mackerras mtcrf 0x80,r12 710b5bbeb23SPaul Mackerras mfspr r12,SPRN_SPRG2 71114cf11afSPaul MackerrasEND_FTR_SECTION_IFCLR(CPU_FTR_SLB) 71214cf11afSPaul Mackerras EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN) 71314cf11afSPaul Mackerras EXCEPTION_PROLOG_ISERIES_2 71414cf11afSPaul Mackerras b data_access_common 71514cf11afSPaul Mackerras 71614cf11afSPaul Mackerras.do_stab_bolted_iSeries: 71714cf11afSPaul Mackerras mtcrf 0x80,r12 718b5bbeb23SPaul Mackerras mfspr r12,SPRN_SPRG2 71914cf11afSPaul Mackerras EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB) 72014cf11afSPaul Mackerras EXCEPTION_PROLOG_ISERIES_2 72114cf11afSPaul Mackerras b .do_stab_bolted 72214cf11afSPaul Mackerras 72314cf11afSPaul Mackerras .globl data_access_slb_iSeries 72414cf11afSPaul Mackerrasdata_access_slb_iSeries: 725b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13 /* save r13 */ 7263c726f8dSBenjamin Herrenschmidt mfspr r13,SPRN_SPRG3 /* get paca address into r13 */ 72714cf11afSPaul Mackerras std r3,PACA_EXSLB+EX_R3(r13) 728b5bbeb23SPaul Mackerras mfspr r3,SPRN_DAR 7293c726f8dSBenjamin Herrenschmidt std r9,PACA_EXSLB+EX_R9(r13) 7303c726f8dSBenjamin Herrenschmidt mfcr r9 7313c726f8dSBenjamin Herrenschmidt#ifdef __DISABLED__ 7323c726f8dSBenjamin Herrenschmidt cmpdi r3,0 7333c726f8dSBenjamin Herrenschmidt bge slb_miss_user_iseries 7343c726f8dSBenjamin Herrenschmidt#endif 7353c726f8dSBenjamin Herrenschmidt std r10,PACA_EXSLB+EX_R10(r13) 7363c726f8dSBenjamin Herrenschmidt std r11,PACA_EXSLB+EX_R11(r13) 7373c726f8dSBenjamin Herrenschmidt std r12,PACA_EXSLB+EX_R12(r13) 7383c726f8dSBenjamin Herrenschmidt mfspr r10,SPRN_SPRG1 7393c726f8dSBenjamin Herrenschmidt std r10,PACA_EXSLB+EX_R13(r13) 7403356bb9fSDavid Gibson ld r12,PACALPPACAPTR(r13) 7413356bb9fSDavid Gibson ld r12,LPPACASRR1(r12) 7423c726f8dSBenjamin Herrenschmidt b .slb_miss_realmode 74314cf11afSPaul Mackerras 74414cf11afSPaul Mackerras STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN) 74514cf11afSPaul Mackerras 74614cf11afSPaul Mackerras .globl instruction_access_slb_iSeries 74714cf11afSPaul Mackerrasinstruction_access_slb_iSeries: 748b5bbeb23SPaul Mackerras mtspr SPRN_SPRG1,r13 /* save r13 */ 7493c726f8dSBenjamin Herrenschmidt mfspr r13,SPRN_SPRG3 /* get paca address into r13 */ 75014cf11afSPaul Mackerras std r3,PACA_EXSLB+EX_R3(r13) 7513356bb9fSDavid Gibson ld r3,PACALPPACAPTR(r13) 7523356bb9fSDavid Gibson ld r3,LPPACASRR0(r3) /* get SRR0 value */ 7533c726f8dSBenjamin Herrenschmidt std r9,PACA_EXSLB+EX_R9(r13) 7543c726f8dSBenjamin Herrenschmidt mfcr r9 7553c726f8dSBenjamin Herrenschmidt#ifdef __DISABLED__ 7563c726f8dSBenjamin Herrenschmidt cmpdi r3,0 7573c726f8dSBenjamin Herrenschmidt bge .slb_miss_user_iseries 7583c726f8dSBenjamin Herrenschmidt#endif 7593c726f8dSBenjamin Herrenschmidt std r10,PACA_EXSLB+EX_R10(r13) 7603c726f8dSBenjamin Herrenschmidt std r11,PACA_EXSLB+EX_R11(r13) 7613c726f8dSBenjamin Herrenschmidt std r12,PACA_EXSLB+EX_R12(r13) 7623c726f8dSBenjamin Herrenschmidt mfspr r10,SPRN_SPRG1 7633c726f8dSBenjamin Herrenschmidt std r10,PACA_EXSLB+EX_R13(r13) 7643356bb9fSDavid Gibson ld r12,PACALPPACAPTR(r13) 7653356bb9fSDavid Gibson ld r12,LPPACASRR1(r12) 7663c726f8dSBenjamin Herrenschmidt b .slb_miss_realmode 7673c726f8dSBenjamin Herrenschmidt 7683c726f8dSBenjamin Herrenschmidt#ifdef __DISABLED__ 7693c726f8dSBenjamin Herrenschmidtslb_miss_user_iseries: 7703c726f8dSBenjamin Herrenschmidt std r10,PACA_EXGEN+EX_R10(r13) 7713c726f8dSBenjamin Herrenschmidt std r11,PACA_EXGEN+EX_R11(r13) 7723c726f8dSBenjamin Herrenschmidt std r12,PACA_EXGEN+EX_R12(r13) 7733c726f8dSBenjamin Herrenschmidt mfspr r10,SPRG1 7743c726f8dSBenjamin Herrenschmidt ld r11,PACA_EXSLB+EX_R9(r13) 7753c726f8dSBenjamin Herrenschmidt ld r12,PACA_EXSLB+EX_R3(r13) 7763c726f8dSBenjamin Herrenschmidt std r10,PACA_EXGEN+EX_R13(r13) 7773c726f8dSBenjamin Herrenschmidt std r11,PACA_EXGEN+EX_R9(r13) 7783c726f8dSBenjamin Herrenschmidt std r12,PACA_EXGEN+EX_R3(r13) 7793c726f8dSBenjamin Herrenschmidt EXCEPTION_PROLOG_ISERIES_2 7803c726f8dSBenjamin Herrenschmidt b slb_miss_user_common 7813c726f8dSBenjamin Herrenschmidt#endif 78214cf11afSPaul Mackerras 78314cf11afSPaul Mackerras MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt) 78414cf11afSPaul Mackerras STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN) 78514cf11afSPaul Mackerras STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN) 78614cf11afSPaul Mackerras STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN) 78714cf11afSPaul Mackerras MASKABLE_EXCEPTION_ISERIES(0x900, decrementer) 78814cf11afSPaul Mackerras STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN) 78914cf11afSPaul Mackerras STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN) 79014cf11afSPaul Mackerras 79114cf11afSPaul Mackerras .globl system_call_iSeries 79214cf11afSPaul Mackerrassystem_call_iSeries: 79314cf11afSPaul Mackerras mr r9,r13 794b5bbeb23SPaul Mackerras mfspr r13,SPRN_SPRG3 79514cf11afSPaul Mackerras EXCEPTION_PROLOG_ISERIES_2 79614cf11afSPaul Mackerras b system_call_common 79714cf11afSPaul Mackerras 79814cf11afSPaul Mackerras STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN) 79914cf11afSPaul Mackerras STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN) 80014cf11afSPaul Mackerras STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN) 80114cf11afSPaul Mackerras 80214cf11afSPaul Mackerras .globl system_reset_iSeries 80314cf11afSPaul Mackerrassystem_reset_iSeries: 804b5bbeb23SPaul Mackerras mfspr r13,SPRN_SPRG3 /* Get paca address */ 80514cf11afSPaul Mackerras mfmsr r24 80614cf11afSPaul Mackerras ori r24,r24,MSR_RI 80714cf11afSPaul Mackerras mtmsrd r24 /* RI on */ 80814cf11afSPaul Mackerras lhz r24,PACAPACAINDEX(r13) /* Get processor # */ 80914cf11afSPaul Mackerras cmpwi 0,r24,0 /* Are we processor 0? */ 81014cf11afSPaul Mackerras beq .__start_initialization_iSeries /* Start up the first processor */ 81114cf11afSPaul Mackerras mfspr r4,SPRN_CTRLF 81214cf11afSPaul Mackerras li r5,CTRL_RUNLATCH /* Turn off the run light */ 81314cf11afSPaul Mackerras andc r4,r4,r5 81414cf11afSPaul Mackerras mtspr SPRN_CTRLT,r4 81514cf11afSPaul Mackerras 81614cf11afSPaul Mackerras1: 81714cf11afSPaul Mackerras HMT_LOW 81814cf11afSPaul Mackerras#ifdef CONFIG_SMP 81914cf11afSPaul Mackerras lbz r23,PACAPROCSTART(r13) /* Test if this processor 82014cf11afSPaul Mackerras * should start */ 82114cf11afSPaul Mackerras sync 822e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r3,current_set) 82314cf11afSPaul Mackerras sldi r28,r24,3 /* get current_set[cpu#] */ 82414cf11afSPaul Mackerras ldx r3,r3,r28 82514cf11afSPaul Mackerras addi r1,r3,THREAD_SIZE 82614cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 82714cf11afSPaul Mackerras 82814cf11afSPaul Mackerras cmpwi 0,r23,0 82914cf11afSPaul Mackerras beq iSeries_secondary_smp_loop /* Loop until told to go */ 83014cf11afSPaul Mackerras bne .__secondary_start /* Loop until told to go */ 83114cf11afSPaul MackerrasiSeries_secondary_smp_loop: 83214cf11afSPaul Mackerras /* Let the Hypervisor know we are alive */ 83314cf11afSPaul Mackerras /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */ 83414cf11afSPaul Mackerras lis r3,0x8002 83514cf11afSPaul Mackerras rldicr r3,r3,32,15 /* r0 = (r3 << 32) & 0xffff000000000000 */ 83614cf11afSPaul Mackerras#else /* CONFIG_SMP */ 83714cf11afSPaul Mackerras /* Yield the processor. This is required for non-SMP kernels 83814cf11afSPaul Mackerras which are running on multi-threaded machines. */ 83914cf11afSPaul Mackerras lis r3,0x8000 84014cf11afSPaul Mackerras rldicr r3,r3,32,15 /* r3 = (r3 << 32) & 0xffff000000000000 */ 84114cf11afSPaul Mackerras addi r3,r3,18 /* r3 = 0x8000000000000012 which is "yield" */ 84214cf11afSPaul Mackerras li r4,0 /* "yield timed" */ 84314cf11afSPaul Mackerras li r5,-1 /* "yield forever" */ 84414cf11afSPaul Mackerras#endif /* CONFIG_SMP */ 84514cf11afSPaul Mackerras li r0,-1 /* r0=-1 indicates a Hypervisor call */ 84614cf11afSPaul Mackerras sc /* Invoke the hypervisor via a system call */ 847b5bbeb23SPaul Mackerras mfspr r13,SPRN_SPRG3 /* Put r13 back ???? */ 84814cf11afSPaul Mackerras b 1b /* If SMP not configured, secondaries 84914cf11afSPaul Mackerras * loop forever */ 85014cf11afSPaul Mackerras 85114cf11afSPaul Mackerras .globl decrementer_iSeries_masked 85214cf11afSPaul Mackerrasdecrementer_iSeries_masked: 853f9b4045dSMichael Ellerman /* We may not have a valid TOC pointer in here. */ 85414cf11afSPaul Mackerras li r11,1 8553356bb9fSDavid Gibson ld r12,PACALPPACAPTR(r13) 8563356bb9fSDavid Gibson stb r11,LPPACADECRINT(r12) 857f9b4045dSMichael Ellerman LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy) 858f9b4045dSMichael Ellerman lwz r12,0(r12) 85914cf11afSPaul Mackerras mtspr SPRN_DEC,r12 86014cf11afSPaul Mackerras /* fall through */ 86114cf11afSPaul Mackerras 86214cf11afSPaul Mackerras .globl hardware_interrupt_iSeries_masked 86314cf11afSPaul Mackerrashardware_interrupt_iSeries_masked: 86414cf11afSPaul Mackerras mtcrf 0x80,r9 /* Restore regs */ 8653356bb9fSDavid Gibson ld r12,PACALPPACAPTR(r13) 8663356bb9fSDavid Gibson ld r11,LPPACASRR0(r12) 8673356bb9fSDavid Gibson ld r12,LPPACASRR1(r12) 868b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r11 869b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r12 87014cf11afSPaul Mackerras ld r9,PACA_EXGEN+EX_R9(r13) 87114cf11afSPaul Mackerras ld r10,PACA_EXGEN+EX_R10(r13) 87214cf11afSPaul Mackerras ld r11,PACA_EXGEN+EX_R11(r13) 87314cf11afSPaul Mackerras ld r12,PACA_EXGEN+EX_R12(r13) 87414cf11afSPaul Mackerras ld r13,PACA_EXGEN+EX_R13(r13) 87514cf11afSPaul Mackerras rfid 87614cf11afSPaul Mackerras b . /* prevent speculative execution */ 87714cf11afSPaul Mackerras#endif /* CONFIG_PPC_ISERIES */ 87814cf11afSPaul Mackerras 87914cf11afSPaul Mackerras/*** Common interrupt handlers ***/ 88014cf11afSPaul Mackerras 88114cf11afSPaul Mackerras STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception) 88214cf11afSPaul Mackerras 88314cf11afSPaul Mackerras /* 88414cf11afSPaul Mackerras * Machine check is different because we use a different 88514cf11afSPaul Mackerras * save area: PACA_EXMC instead of PACA_EXGEN. 88614cf11afSPaul Mackerras */ 88714cf11afSPaul Mackerras .align 7 88814cf11afSPaul Mackerras .globl machine_check_common 88914cf11afSPaul Mackerrasmachine_check_common: 89014cf11afSPaul Mackerras EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC) 891f39224a8SPaul Mackerras FINISH_NAP 89214cf11afSPaul Mackerras DISABLE_INTS 89314cf11afSPaul Mackerras bl .save_nvgprs 89414cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD 89514cf11afSPaul Mackerras bl .machine_check_exception 89614cf11afSPaul Mackerras b .ret_from_except 89714cf11afSPaul Mackerras 89814cf11afSPaul Mackerras STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt) 89914cf11afSPaul Mackerras STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception) 90014cf11afSPaul Mackerras STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception) 90114cf11afSPaul Mackerras STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception) 90214cf11afSPaul Mackerras STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception) 903f39224a8SPaul Mackerras STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception) 90414cf11afSPaul Mackerras STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception) 90514cf11afSPaul Mackerras#ifdef CONFIG_ALTIVEC 90614cf11afSPaul Mackerras STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception) 90714cf11afSPaul Mackerras#else 90814cf11afSPaul Mackerras STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception) 90914cf11afSPaul Mackerras#endif 910acf7d768SBenjamin Herrenschmidt#ifdef CONFIG_CBE_RAS 911acf7d768SBenjamin Herrenschmidt STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception) 912acf7d768SBenjamin Herrenschmidt STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception) 913acf7d768SBenjamin Herrenschmidt STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception) 914acf7d768SBenjamin Herrenschmidt#endif /* CONFIG_CBE_RAS */ 91514cf11afSPaul Mackerras 91614cf11afSPaul Mackerras/* 91714cf11afSPaul Mackerras * Here we have detected that the kernel stack pointer is bad. 91814cf11afSPaul Mackerras * R9 contains the saved CR, r13 points to the paca, 91914cf11afSPaul Mackerras * r10 contains the (bad) kernel stack pointer, 92014cf11afSPaul Mackerras * r11 and r12 contain the saved SRR0 and SRR1. 92114cf11afSPaul Mackerras * We switch to using an emergency stack, save the registers there, 92214cf11afSPaul Mackerras * and call kernel_bad_stack(), which panics. 92314cf11afSPaul Mackerras */ 92414cf11afSPaul Mackerrasbad_stack: 92514cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 92614cf11afSPaul Mackerras subi r1,r1,64+INT_FRAME_SIZE 92714cf11afSPaul Mackerras std r9,_CCR(r1) 92814cf11afSPaul Mackerras std r10,GPR1(r1) 92914cf11afSPaul Mackerras std r11,_NIP(r1) 93014cf11afSPaul Mackerras std r12,_MSR(r1) 931b5bbeb23SPaul Mackerras mfspr r11,SPRN_DAR 932b5bbeb23SPaul Mackerras mfspr r12,SPRN_DSISR 93314cf11afSPaul Mackerras std r11,_DAR(r1) 93414cf11afSPaul Mackerras std r12,_DSISR(r1) 93514cf11afSPaul Mackerras mflr r10 93614cf11afSPaul Mackerras mfctr r11 93714cf11afSPaul Mackerras mfxer r12 93814cf11afSPaul Mackerras std r10,_LINK(r1) 93914cf11afSPaul Mackerras std r11,_CTR(r1) 94014cf11afSPaul Mackerras std r12,_XER(r1) 94114cf11afSPaul Mackerras SAVE_GPR(0,r1) 94214cf11afSPaul Mackerras SAVE_GPR(2,r1) 94314cf11afSPaul Mackerras SAVE_4GPRS(3,r1) 94414cf11afSPaul Mackerras SAVE_2GPRS(7,r1) 94514cf11afSPaul Mackerras SAVE_10GPRS(12,r1) 94614cf11afSPaul Mackerras SAVE_10GPRS(22,r1) 94714cf11afSPaul Mackerras addi r11,r1,INT_FRAME_SIZE 94814cf11afSPaul Mackerras std r11,0(r1) 94914cf11afSPaul Mackerras li r12,0 95014cf11afSPaul Mackerras std r12,0(r11) 95114cf11afSPaul Mackerras ld r2,PACATOC(r13) 95214cf11afSPaul Mackerras1: addi r3,r1,STACK_FRAME_OVERHEAD 95314cf11afSPaul Mackerras bl .kernel_bad_stack 95414cf11afSPaul Mackerras b 1b 95514cf11afSPaul Mackerras 95614cf11afSPaul Mackerras/* 95714cf11afSPaul Mackerras * Return from an exception with minimal checks. 95814cf11afSPaul Mackerras * The caller is assumed to have done EXCEPTION_PROLOG_COMMON. 95914cf11afSPaul Mackerras * If interrupts have been enabled, or anything has been 96014cf11afSPaul Mackerras * done that might have changed the scheduling status of 96114cf11afSPaul Mackerras * any task or sent any task a signal, you should use 96214cf11afSPaul Mackerras * ret_from_except or ret_from_except_lite instead of this. 96314cf11afSPaul Mackerras */ 96440ef8cbcSPaul Mackerras .globl fast_exception_return 96514cf11afSPaul Mackerrasfast_exception_return: 96614cf11afSPaul Mackerras ld r12,_MSR(r1) 96714cf11afSPaul Mackerras ld r11,_NIP(r1) 96814cf11afSPaul Mackerras andi. r3,r12,MSR_RI /* check if RI is set */ 96914cf11afSPaul Mackerras beq- unrecov_fer 970c6622f63SPaul Mackerras 971c6622f63SPaul Mackerras#ifdef CONFIG_VIRT_CPU_ACCOUNTING 972c6622f63SPaul Mackerras andi. r3,r12,MSR_PR 973c6622f63SPaul Mackerras beq 2f 974c6622f63SPaul Mackerras ACCOUNT_CPU_USER_EXIT(r3, r4) 975c6622f63SPaul Mackerras2: 976c6622f63SPaul Mackerras#endif 977c6622f63SPaul Mackerras 97814cf11afSPaul Mackerras ld r3,_CCR(r1) 97914cf11afSPaul Mackerras ld r4,_LINK(r1) 98014cf11afSPaul Mackerras ld r5,_CTR(r1) 98114cf11afSPaul Mackerras ld r6,_XER(r1) 98214cf11afSPaul Mackerras mtcr r3 98314cf11afSPaul Mackerras mtlr r4 98414cf11afSPaul Mackerras mtctr r5 98514cf11afSPaul Mackerras mtxer r6 98614cf11afSPaul Mackerras REST_GPR(0, r1) 98714cf11afSPaul Mackerras REST_8GPRS(2, r1) 98814cf11afSPaul Mackerras 98914cf11afSPaul Mackerras mfmsr r10 990*d04c56f7SPaul Mackerras rldicl r10,r10,48,1 /* clear EE */ 991*d04c56f7SPaul Mackerras rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */ 99214cf11afSPaul Mackerras mtmsrd r10,1 99314cf11afSPaul Mackerras 994b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r12 995b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r11 99614cf11afSPaul Mackerras REST_4GPRS(10, r1) 99714cf11afSPaul Mackerras ld r1,GPR1(r1) 99814cf11afSPaul Mackerras rfid 99914cf11afSPaul Mackerras b . /* prevent speculative execution */ 100014cf11afSPaul Mackerras 100114cf11afSPaul Mackerrasunrecov_fer: 100214cf11afSPaul Mackerras bl .save_nvgprs 100314cf11afSPaul Mackerras1: addi r3,r1,STACK_FRAME_OVERHEAD 100414cf11afSPaul Mackerras bl .unrecoverable_exception 100514cf11afSPaul Mackerras b 1b 100614cf11afSPaul Mackerras 100714cf11afSPaul Mackerras/* 100814cf11afSPaul Mackerras * Here r13 points to the paca, r9 contains the saved CR, 100914cf11afSPaul Mackerras * SRR0 and SRR1 are saved in r11 and r12, 101014cf11afSPaul Mackerras * r9 - r13 are saved in paca->exgen. 101114cf11afSPaul Mackerras */ 101214cf11afSPaul Mackerras .align 7 101314cf11afSPaul Mackerras .globl data_access_common 101414cf11afSPaul Mackerrasdata_access_common: 1015b5bbeb23SPaul Mackerras mfspr r10,SPRN_DAR 101614cf11afSPaul Mackerras std r10,PACA_EXGEN+EX_DAR(r13) 1017b5bbeb23SPaul Mackerras mfspr r10,SPRN_DSISR 101814cf11afSPaul Mackerras stw r10,PACA_EXGEN+EX_DSISR(r13) 101914cf11afSPaul Mackerras EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN) 102014cf11afSPaul Mackerras ld r3,PACA_EXGEN+EX_DAR(r13) 102114cf11afSPaul Mackerras lwz r4,PACA_EXGEN+EX_DSISR(r13) 102214cf11afSPaul Mackerras li r5,0x300 102314cf11afSPaul Mackerras b .do_hash_page /* Try to handle as hpte fault */ 102414cf11afSPaul Mackerras 102514cf11afSPaul Mackerras .align 7 102614cf11afSPaul Mackerras .globl instruction_access_common 102714cf11afSPaul Mackerrasinstruction_access_common: 102814cf11afSPaul Mackerras EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN) 102914cf11afSPaul Mackerras ld r3,_NIP(r1) 103014cf11afSPaul Mackerras andis. r4,r12,0x5820 103114cf11afSPaul Mackerras li r5,0x400 103214cf11afSPaul Mackerras b .do_hash_page /* Try to handle as hpte fault */ 103314cf11afSPaul Mackerras 10343c726f8dSBenjamin Herrenschmidt/* 10353c726f8dSBenjamin Herrenschmidt * Here is the common SLB miss user that is used when going to virtual 10363c726f8dSBenjamin Herrenschmidt * mode for SLB misses, that is currently not used 10373c726f8dSBenjamin Herrenschmidt */ 10383c726f8dSBenjamin Herrenschmidt#ifdef __DISABLED__ 10393c726f8dSBenjamin Herrenschmidt .align 7 10403c726f8dSBenjamin Herrenschmidt .globl slb_miss_user_common 10413c726f8dSBenjamin Herrenschmidtslb_miss_user_common: 10423c726f8dSBenjamin Herrenschmidt mflr r10 10433c726f8dSBenjamin Herrenschmidt std r3,PACA_EXGEN+EX_DAR(r13) 10443c726f8dSBenjamin Herrenschmidt stw r9,PACA_EXGEN+EX_CCR(r13) 10453c726f8dSBenjamin Herrenschmidt std r10,PACA_EXGEN+EX_LR(r13) 10463c726f8dSBenjamin Herrenschmidt std r11,PACA_EXGEN+EX_SRR0(r13) 10473c726f8dSBenjamin Herrenschmidt bl .slb_allocate_user 10483c726f8dSBenjamin Herrenschmidt 10493c726f8dSBenjamin Herrenschmidt ld r10,PACA_EXGEN+EX_LR(r13) 10503c726f8dSBenjamin Herrenschmidt ld r3,PACA_EXGEN+EX_R3(r13) 10513c726f8dSBenjamin Herrenschmidt lwz r9,PACA_EXGEN+EX_CCR(r13) 10523c726f8dSBenjamin Herrenschmidt ld r11,PACA_EXGEN+EX_SRR0(r13) 10533c726f8dSBenjamin Herrenschmidt mtlr r10 10543c726f8dSBenjamin Herrenschmidt beq- slb_miss_fault 10553c726f8dSBenjamin Herrenschmidt 10563c726f8dSBenjamin Herrenschmidt andi. r10,r12,MSR_RI /* check for unrecoverable exception */ 10573c726f8dSBenjamin Herrenschmidt beq- unrecov_user_slb 10583c726f8dSBenjamin Herrenschmidt mfmsr r10 10593c726f8dSBenjamin Herrenschmidt 10603c726f8dSBenjamin Herrenschmidt.machine push 10613c726f8dSBenjamin Herrenschmidt.machine "power4" 10623c726f8dSBenjamin Herrenschmidt mtcrf 0x80,r9 10633c726f8dSBenjamin Herrenschmidt.machine pop 10643c726f8dSBenjamin Herrenschmidt 10653c726f8dSBenjamin Herrenschmidt clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */ 10663c726f8dSBenjamin Herrenschmidt mtmsrd r10,1 10673c726f8dSBenjamin Herrenschmidt 10683c726f8dSBenjamin Herrenschmidt mtspr SRR0,r11 10693c726f8dSBenjamin Herrenschmidt mtspr SRR1,r12 10703c726f8dSBenjamin Herrenschmidt 10713c726f8dSBenjamin Herrenschmidt ld r9,PACA_EXGEN+EX_R9(r13) 10723c726f8dSBenjamin Herrenschmidt ld r10,PACA_EXGEN+EX_R10(r13) 10733c726f8dSBenjamin Herrenschmidt ld r11,PACA_EXGEN+EX_R11(r13) 10743c726f8dSBenjamin Herrenschmidt ld r12,PACA_EXGEN+EX_R12(r13) 10753c726f8dSBenjamin Herrenschmidt ld r13,PACA_EXGEN+EX_R13(r13) 10763c726f8dSBenjamin Herrenschmidt rfid 10773c726f8dSBenjamin Herrenschmidt b . 10783c726f8dSBenjamin Herrenschmidt 10793c726f8dSBenjamin Herrenschmidtslb_miss_fault: 10803c726f8dSBenjamin Herrenschmidt EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN) 10813c726f8dSBenjamin Herrenschmidt ld r4,PACA_EXGEN+EX_DAR(r13) 10823c726f8dSBenjamin Herrenschmidt li r5,0 10833c726f8dSBenjamin Herrenschmidt std r4,_DAR(r1) 10843c726f8dSBenjamin Herrenschmidt std r5,_DSISR(r1) 10853c726f8dSBenjamin Herrenschmidt b .handle_page_fault 10863c726f8dSBenjamin Herrenschmidt 10873c726f8dSBenjamin Herrenschmidtunrecov_user_slb: 10883c726f8dSBenjamin Herrenschmidt EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN) 10893c726f8dSBenjamin Herrenschmidt DISABLE_INTS 10903c726f8dSBenjamin Herrenschmidt bl .save_nvgprs 10913c726f8dSBenjamin Herrenschmidt1: addi r3,r1,STACK_FRAME_OVERHEAD 10923c726f8dSBenjamin Herrenschmidt bl .unrecoverable_exception 10933c726f8dSBenjamin Herrenschmidt b 1b 10943c726f8dSBenjamin Herrenschmidt 10953c726f8dSBenjamin Herrenschmidt#endif /* __DISABLED__ */ 10963c726f8dSBenjamin Herrenschmidt 10973c726f8dSBenjamin Herrenschmidt 10983c726f8dSBenjamin Herrenschmidt/* 10993c726f8dSBenjamin Herrenschmidt * r13 points to the PACA, r9 contains the saved CR, 11003c726f8dSBenjamin Herrenschmidt * r12 contain the saved SRR1, SRR0 is still ready for return 11013c726f8dSBenjamin Herrenschmidt * r3 has the faulting address 11023c726f8dSBenjamin Herrenschmidt * r9 - r13 are saved in paca->exslb. 11033c726f8dSBenjamin Herrenschmidt * r3 is saved in paca->slb_r3 11043c726f8dSBenjamin Herrenschmidt * We assume we aren't going to take any exceptions during this procedure. 11053c726f8dSBenjamin Herrenschmidt */ 11063c726f8dSBenjamin Herrenschmidt_GLOBAL(slb_miss_realmode) 11073c726f8dSBenjamin Herrenschmidt mflr r10 11083c726f8dSBenjamin Herrenschmidt 11093c726f8dSBenjamin Herrenschmidt stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */ 11103c726f8dSBenjamin Herrenschmidt std r10,PACA_EXSLB+EX_LR(r13) /* save LR */ 11113c726f8dSBenjamin Herrenschmidt 11123c726f8dSBenjamin Herrenschmidt bl .slb_allocate_realmode 11133c726f8dSBenjamin Herrenschmidt 11143c726f8dSBenjamin Herrenschmidt /* All done -- return from exception. */ 11153c726f8dSBenjamin Herrenschmidt 11163c726f8dSBenjamin Herrenschmidt ld r10,PACA_EXSLB+EX_LR(r13) 11173c726f8dSBenjamin Herrenschmidt ld r3,PACA_EXSLB+EX_R3(r13) 11183c726f8dSBenjamin Herrenschmidt lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */ 11193c726f8dSBenjamin Herrenschmidt#ifdef CONFIG_PPC_ISERIES 11203f639ee8SStephen RothwellBEGIN_FW_FTR_SECTION 11213356bb9fSDavid Gibson ld r11,PACALPPACAPTR(r13) 11223356bb9fSDavid Gibson ld r11,LPPACASRR0(r11) /* get SRR0 value */ 11233f639ee8SStephen RothwellEND_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) 11243c726f8dSBenjamin Herrenschmidt#endif /* CONFIG_PPC_ISERIES */ 11253c726f8dSBenjamin Herrenschmidt 11263c726f8dSBenjamin Herrenschmidt mtlr r10 11273c726f8dSBenjamin Herrenschmidt 11283c726f8dSBenjamin Herrenschmidt andi. r10,r12,MSR_RI /* check for unrecoverable exception */ 11293c726f8dSBenjamin Herrenschmidt beq- unrecov_slb 11303c726f8dSBenjamin Herrenschmidt 11313c726f8dSBenjamin Herrenschmidt.machine push 11323c726f8dSBenjamin Herrenschmidt.machine "power4" 11333c726f8dSBenjamin Herrenschmidt mtcrf 0x80,r9 11343c726f8dSBenjamin Herrenschmidt mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */ 11353c726f8dSBenjamin Herrenschmidt.machine pop 11363c726f8dSBenjamin Herrenschmidt 11373c726f8dSBenjamin Herrenschmidt#ifdef CONFIG_PPC_ISERIES 11383f639ee8SStephen RothwellBEGIN_FW_FTR_SECTION 11393c726f8dSBenjamin Herrenschmidt mtspr SPRN_SRR0,r11 11403c726f8dSBenjamin Herrenschmidt mtspr SPRN_SRR1,r12 11413f639ee8SStephen RothwellEND_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) 11423c726f8dSBenjamin Herrenschmidt#endif /* CONFIG_PPC_ISERIES */ 11433c726f8dSBenjamin Herrenschmidt ld r9,PACA_EXSLB+EX_R9(r13) 11443c726f8dSBenjamin Herrenschmidt ld r10,PACA_EXSLB+EX_R10(r13) 11453c726f8dSBenjamin Herrenschmidt ld r11,PACA_EXSLB+EX_R11(r13) 11463c726f8dSBenjamin Herrenschmidt ld r12,PACA_EXSLB+EX_R12(r13) 11473c726f8dSBenjamin Herrenschmidt ld r13,PACA_EXSLB+EX_R13(r13) 11483c726f8dSBenjamin Herrenschmidt rfid 11493c726f8dSBenjamin Herrenschmidt b . /* prevent speculative execution */ 11503c726f8dSBenjamin Herrenschmidt 11513c726f8dSBenjamin Herrenschmidtunrecov_slb: 11523c726f8dSBenjamin Herrenschmidt EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB) 11533c726f8dSBenjamin Herrenschmidt DISABLE_INTS 11543c726f8dSBenjamin Herrenschmidt bl .save_nvgprs 11553c726f8dSBenjamin Herrenschmidt1: addi r3,r1,STACK_FRAME_OVERHEAD 11563c726f8dSBenjamin Herrenschmidt bl .unrecoverable_exception 11573c726f8dSBenjamin Herrenschmidt b 1b 11583c726f8dSBenjamin Herrenschmidt 115914cf11afSPaul Mackerras .align 7 116014cf11afSPaul Mackerras .globl hardware_interrupt_common 116114cf11afSPaul Mackerras .globl hardware_interrupt_entry 116214cf11afSPaul Mackerrashardware_interrupt_common: 116314cf11afSPaul Mackerras EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN) 1164f39224a8SPaul Mackerras FINISH_NAP 116514cf11afSPaul Mackerrashardware_interrupt_entry: 116614cf11afSPaul Mackerras DISABLE_INTS 1167cb2c9b27SAnton Blanchard bl .ppc64_runlatch_on 116814cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD 116914cf11afSPaul Mackerras bl .do_IRQ 117014cf11afSPaul Mackerras b .ret_from_except_lite 117114cf11afSPaul Mackerras 1172f39224a8SPaul Mackerras#ifdef CONFIG_PPC_970_NAP 1173f39224a8SPaul Mackerraspower4_fixup_nap: 1174f39224a8SPaul Mackerras andc r9,r9,r10 1175f39224a8SPaul Mackerras std r9,TI_LOCAL_FLAGS(r11) 1176f39224a8SPaul Mackerras ld r10,_LINK(r1) /* make idle task do the */ 1177f39224a8SPaul Mackerras std r10,_NIP(r1) /* equivalent of a blr */ 1178f39224a8SPaul Mackerras blr 1179f39224a8SPaul Mackerras#endif 1180f39224a8SPaul Mackerras 118114cf11afSPaul Mackerras .align 7 118214cf11afSPaul Mackerras .globl alignment_common 118314cf11afSPaul Mackerrasalignment_common: 1184b5bbeb23SPaul Mackerras mfspr r10,SPRN_DAR 118514cf11afSPaul Mackerras std r10,PACA_EXGEN+EX_DAR(r13) 1186b5bbeb23SPaul Mackerras mfspr r10,SPRN_DSISR 118714cf11afSPaul Mackerras stw r10,PACA_EXGEN+EX_DSISR(r13) 118814cf11afSPaul Mackerras EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN) 118914cf11afSPaul Mackerras ld r3,PACA_EXGEN+EX_DAR(r13) 119014cf11afSPaul Mackerras lwz r4,PACA_EXGEN+EX_DSISR(r13) 119114cf11afSPaul Mackerras std r3,_DAR(r1) 119214cf11afSPaul Mackerras std r4,_DSISR(r1) 119314cf11afSPaul Mackerras bl .save_nvgprs 119414cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD 119514cf11afSPaul Mackerras ENABLE_INTS 119614cf11afSPaul Mackerras bl .alignment_exception 119714cf11afSPaul Mackerras b .ret_from_except 119814cf11afSPaul Mackerras 119914cf11afSPaul Mackerras .align 7 120014cf11afSPaul Mackerras .globl program_check_common 120114cf11afSPaul Mackerrasprogram_check_common: 120214cf11afSPaul Mackerras EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN) 120314cf11afSPaul Mackerras bl .save_nvgprs 120414cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD 120514cf11afSPaul Mackerras ENABLE_INTS 120614cf11afSPaul Mackerras bl .program_check_exception 120714cf11afSPaul Mackerras b .ret_from_except 120814cf11afSPaul Mackerras 120914cf11afSPaul Mackerras .align 7 121014cf11afSPaul Mackerras .globl fp_unavailable_common 121114cf11afSPaul Mackerrasfp_unavailable_common: 121214cf11afSPaul Mackerras EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN) 121314cf11afSPaul Mackerras bne .load_up_fpu /* if from user, just load it up */ 121414cf11afSPaul Mackerras bl .save_nvgprs 121514cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD 121614cf11afSPaul Mackerras ENABLE_INTS 121714cf11afSPaul Mackerras bl .kernel_fp_unavailable_exception 121814cf11afSPaul Mackerras BUG_OPCODE 121914cf11afSPaul Mackerras 122014cf11afSPaul Mackerras .align 7 122114cf11afSPaul Mackerras .globl altivec_unavailable_common 122214cf11afSPaul Mackerrasaltivec_unavailable_common: 122314cf11afSPaul Mackerras EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN) 122414cf11afSPaul Mackerras#ifdef CONFIG_ALTIVEC 122514cf11afSPaul MackerrasBEGIN_FTR_SECTION 122614cf11afSPaul Mackerras bne .load_up_altivec /* if from user, just load it up */ 122714cf11afSPaul MackerrasEND_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) 122814cf11afSPaul Mackerras#endif 122914cf11afSPaul Mackerras bl .save_nvgprs 123014cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD 123114cf11afSPaul Mackerras ENABLE_INTS 123214cf11afSPaul Mackerras bl .altivec_unavailable_exception 123314cf11afSPaul Mackerras b .ret_from_except 123414cf11afSPaul Mackerras 123514cf11afSPaul Mackerras#ifdef CONFIG_ALTIVEC 123614cf11afSPaul Mackerras/* 123714cf11afSPaul Mackerras * load_up_altivec(unused, unused, tsk) 123814cf11afSPaul Mackerras * Disable VMX for the task which had it previously, 123914cf11afSPaul Mackerras * and save its vector registers in its thread_struct. 124014cf11afSPaul Mackerras * Enables the VMX for use in the kernel on return. 124114cf11afSPaul Mackerras * On SMP we know the VMX is free, since we give it up every 124214cf11afSPaul Mackerras * switch (ie, no lazy save of the vector registers). 124314cf11afSPaul Mackerras * On entry: r13 == 'current' && last_task_used_altivec != 'current' 124414cf11afSPaul Mackerras */ 124514cf11afSPaul Mackerras_STATIC(load_up_altivec) 124614cf11afSPaul Mackerras mfmsr r5 /* grab the current MSR */ 124714cf11afSPaul Mackerras oris r5,r5,MSR_VEC@h 124814cf11afSPaul Mackerras mtmsrd r5 /* enable use of VMX now */ 124914cf11afSPaul Mackerras isync 125014cf11afSPaul Mackerras 125114cf11afSPaul Mackerras/* 125214cf11afSPaul Mackerras * For SMP, we don't do lazy VMX switching because it just gets too 125314cf11afSPaul Mackerras * horrendously complex, especially when a task switches from one CPU 125414cf11afSPaul Mackerras * to another. Instead we call giveup_altvec in switch_to. 125514cf11afSPaul Mackerras * VRSAVE isn't dealt with here, that is done in the normal context 125614cf11afSPaul Mackerras * switch code. Note that we could rely on vrsave value to eventually 125714cf11afSPaul Mackerras * avoid saving all of the VREGs here... 125814cf11afSPaul Mackerras */ 125914cf11afSPaul Mackerras#ifndef CONFIG_SMP 126014cf11afSPaul Mackerras ld r3,last_task_used_altivec@got(r2) 126114cf11afSPaul Mackerras ld r4,0(r3) 126214cf11afSPaul Mackerras cmpdi 0,r4,0 126314cf11afSPaul Mackerras beq 1f 126414cf11afSPaul Mackerras /* Save VMX state to last_task_used_altivec's THREAD struct */ 126514cf11afSPaul Mackerras addi r4,r4,THREAD 126614cf11afSPaul Mackerras SAVE_32VRS(0,r5,r4) 126714cf11afSPaul Mackerras mfvscr vr0 126814cf11afSPaul Mackerras li r10,THREAD_VSCR 126914cf11afSPaul Mackerras stvx vr0,r10,r4 127014cf11afSPaul Mackerras /* Disable VMX for last_task_used_altivec */ 127114cf11afSPaul Mackerras ld r5,PT_REGS(r4) 127214cf11afSPaul Mackerras ld r4,_MSR-STACK_FRAME_OVERHEAD(r5) 127314cf11afSPaul Mackerras lis r6,MSR_VEC@h 127414cf11afSPaul Mackerras andc r4,r4,r6 127514cf11afSPaul Mackerras std r4,_MSR-STACK_FRAME_OVERHEAD(r5) 127614cf11afSPaul Mackerras1: 127714cf11afSPaul Mackerras#endif /* CONFIG_SMP */ 127814cf11afSPaul Mackerras /* Hack: if we get an altivec unavailable trap with VRSAVE 127914cf11afSPaul Mackerras * set to all zeros, we assume this is a broken application 128014cf11afSPaul Mackerras * that fails to set it properly, and thus we switch it to 128114cf11afSPaul Mackerras * all 1's 128214cf11afSPaul Mackerras */ 128314cf11afSPaul Mackerras mfspr r4,SPRN_VRSAVE 128414cf11afSPaul Mackerras cmpdi 0,r4,0 128514cf11afSPaul Mackerras bne+ 1f 128614cf11afSPaul Mackerras li r4,-1 128714cf11afSPaul Mackerras mtspr SPRN_VRSAVE,r4 128814cf11afSPaul Mackerras1: 128914cf11afSPaul Mackerras /* enable use of VMX after return */ 129014cf11afSPaul Mackerras ld r4,PACACURRENT(r13) 129114cf11afSPaul Mackerras addi r5,r4,THREAD /* Get THREAD */ 129214cf11afSPaul Mackerras oris r12,r12,MSR_VEC@h 129314cf11afSPaul Mackerras std r12,_MSR(r1) 129414cf11afSPaul Mackerras li r4,1 129514cf11afSPaul Mackerras li r10,THREAD_VSCR 129614cf11afSPaul Mackerras stw r4,THREAD_USED_VR(r5) 129714cf11afSPaul Mackerras lvx vr0,r10,r5 129814cf11afSPaul Mackerras mtvscr vr0 129914cf11afSPaul Mackerras REST_32VRS(0,r4,r5) 130014cf11afSPaul Mackerras#ifndef CONFIG_SMP 130114cf11afSPaul Mackerras /* Update last_task_used_math to 'current' */ 130214cf11afSPaul Mackerras subi r4,r5,THREAD /* Back to 'current' */ 130314cf11afSPaul Mackerras std r4,0(r3) 130414cf11afSPaul Mackerras#endif /* CONFIG_SMP */ 130514cf11afSPaul Mackerras /* restore registers and return */ 130614cf11afSPaul Mackerras b fast_exception_return 130714cf11afSPaul Mackerras#endif /* CONFIG_ALTIVEC */ 130814cf11afSPaul Mackerras 130914cf11afSPaul Mackerras/* 131014cf11afSPaul Mackerras * Hash table stuff 131114cf11afSPaul Mackerras */ 131214cf11afSPaul Mackerras .align 7 131314cf11afSPaul Mackerras_GLOBAL(do_hash_page) 131414cf11afSPaul Mackerras std r3,_DAR(r1) 131514cf11afSPaul Mackerras std r4,_DSISR(r1) 131614cf11afSPaul Mackerras 131714cf11afSPaul Mackerras andis. r0,r4,0xa450 /* weird error? */ 131814cf11afSPaul Mackerras bne- .handle_page_fault /* if not, try to insert a HPTE */ 131914cf11afSPaul MackerrasBEGIN_FTR_SECTION 132014cf11afSPaul Mackerras andis. r0,r4,0x0020 /* Is it a segment table fault? */ 132114cf11afSPaul Mackerras bne- .do_ste_alloc /* If so handle it */ 132214cf11afSPaul MackerrasEND_FTR_SECTION_IFCLR(CPU_FTR_SLB) 132314cf11afSPaul Mackerras 132414cf11afSPaul Mackerras /* 132514cf11afSPaul Mackerras * We need to set the _PAGE_USER bit if MSR_PR is set or if we are 132614cf11afSPaul Mackerras * accessing a userspace segment (even from the kernel). We assume 132714cf11afSPaul Mackerras * kernel addresses always have the high bit set. 132814cf11afSPaul Mackerras */ 132914cf11afSPaul Mackerras rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */ 133014cf11afSPaul Mackerras rotldi r0,r3,15 /* Move high bit into MSR_PR posn */ 133114cf11afSPaul Mackerras orc r0,r12,r0 /* MSR_PR | ~high_bit */ 133214cf11afSPaul Mackerras rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */ 133314cf11afSPaul Mackerras ori r4,r4,1 /* add _PAGE_PRESENT */ 133414cf11afSPaul Mackerras rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */ 133514cf11afSPaul Mackerras 133614cf11afSPaul Mackerras /* 133714cf11afSPaul Mackerras * On iSeries, we soft-disable interrupts here, then 133814cf11afSPaul Mackerras * hard-enable interrupts so that the hash_page code can spin on 133914cf11afSPaul Mackerras * the hash_table_lock without problems on a shared processor. 134014cf11afSPaul Mackerras */ 134114cf11afSPaul Mackerras DISABLE_INTS 134214cf11afSPaul Mackerras 134314cf11afSPaul Mackerras /* 134414cf11afSPaul Mackerras * r3 contains the faulting address 134514cf11afSPaul Mackerras * r4 contains the required access permissions 134614cf11afSPaul Mackerras * r5 contains the trap number 134714cf11afSPaul Mackerras * 134814cf11afSPaul Mackerras * at return r3 = 0 for success 134914cf11afSPaul Mackerras */ 135014cf11afSPaul Mackerras bl .hash_page /* build HPTE if possible */ 135114cf11afSPaul Mackerras cmpdi r3,0 /* see if hash_page succeeded */ 135214cf11afSPaul Mackerras 135314cf11afSPaul Mackerras#ifdef DO_SOFT_DISABLE 13543f639ee8SStephen RothwellBEGIN_FW_FTR_SECTION 135514cf11afSPaul Mackerras /* 135614cf11afSPaul Mackerras * If we had interrupts soft-enabled at the point where the 135714cf11afSPaul Mackerras * DSI/ISI occurred, and an interrupt came in during hash_page, 135814cf11afSPaul Mackerras * handle it now. 135914cf11afSPaul Mackerras * We jump to ret_from_except_lite rather than fast_exception_return 136014cf11afSPaul Mackerras * because ret_from_except_lite will check for and handle pending 136114cf11afSPaul Mackerras * interrupts if necessary. 136214cf11afSPaul Mackerras */ 136314cf11afSPaul Mackerras beq .ret_from_except_lite 136414cf11afSPaul Mackerras /* For a hash failure, we don't bother re-enabling interrupts */ 136514cf11afSPaul Mackerras ble- 12f 136614cf11afSPaul Mackerras 136714cf11afSPaul Mackerras /* 136814cf11afSPaul Mackerras * hash_page couldn't handle it, set soft interrupt enable back 136914cf11afSPaul Mackerras * to what it was before the trap. Note that .local_irq_restore 137014cf11afSPaul Mackerras * handles any interrupts pending at this point. 137114cf11afSPaul Mackerras */ 137214cf11afSPaul Mackerras ld r3,SOFTE(r1) 137314cf11afSPaul Mackerras bl .local_irq_restore 137414cf11afSPaul Mackerras b 11f 13753f639ee8SStephen RothwellEND_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) 13763f639ee8SStephen Rothwell#endif 13773f639ee8SStephen RothwellBEGIN_FW_FTR_SECTION 137814cf11afSPaul Mackerras beq fast_exception_return /* Return from exception on success */ 137914cf11afSPaul Mackerras ble- 12f /* Failure return from hash_page */ 138014cf11afSPaul Mackerras 138114cf11afSPaul Mackerras /* fall through */ 13823f639ee8SStephen RothwellEND_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES) 138314cf11afSPaul Mackerras 138414cf11afSPaul Mackerras/* Here we have a page fault that hash_page can't handle. */ 138514cf11afSPaul Mackerras_GLOBAL(handle_page_fault) 138614cf11afSPaul Mackerras ENABLE_INTS 138714cf11afSPaul Mackerras11: ld r4,_DAR(r1) 138814cf11afSPaul Mackerras ld r5,_DSISR(r1) 138914cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD 139014cf11afSPaul Mackerras bl .do_page_fault 139114cf11afSPaul Mackerras cmpdi r3,0 139214cf11afSPaul Mackerras beq+ .ret_from_except_lite 139314cf11afSPaul Mackerras bl .save_nvgprs 139414cf11afSPaul Mackerras mr r5,r3 139514cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD 139614cf11afSPaul Mackerras lwz r4,_DAR(r1) 139714cf11afSPaul Mackerras bl .bad_page_fault 139814cf11afSPaul Mackerras b .ret_from_except 139914cf11afSPaul Mackerras 140014cf11afSPaul Mackerras/* We have a page fault that hash_page could handle but HV refused 140114cf11afSPaul Mackerras * the PTE insertion 140214cf11afSPaul Mackerras */ 140314cf11afSPaul Mackerras12: bl .save_nvgprs 140414cf11afSPaul Mackerras addi r3,r1,STACK_FRAME_OVERHEAD 140514cf11afSPaul Mackerras lwz r4,_DAR(r1) 140614cf11afSPaul Mackerras bl .low_hash_fault 140714cf11afSPaul Mackerras b .ret_from_except 140814cf11afSPaul Mackerras 140914cf11afSPaul Mackerras /* here we have a segment miss */ 141014cf11afSPaul Mackerras_GLOBAL(do_ste_alloc) 141114cf11afSPaul Mackerras bl .ste_allocate /* try to insert stab entry */ 141214cf11afSPaul Mackerras cmpdi r3,0 141314cf11afSPaul Mackerras beq+ fast_exception_return 141414cf11afSPaul Mackerras b .handle_page_fault 141514cf11afSPaul Mackerras 141614cf11afSPaul Mackerras/* 141714cf11afSPaul Mackerras * r13 points to the PACA, r9 contains the saved CR, 141814cf11afSPaul Mackerras * r11 and r12 contain the saved SRR0 and SRR1. 141914cf11afSPaul Mackerras * r9 - r13 are saved in paca->exslb. 142014cf11afSPaul Mackerras * We assume we aren't going to take any exceptions during this procedure. 142114cf11afSPaul Mackerras * We assume (DAR >> 60) == 0xc. 142214cf11afSPaul Mackerras */ 142314cf11afSPaul Mackerras .align 7 142414cf11afSPaul Mackerras_GLOBAL(do_stab_bolted) 142514cf11afSPaul Mackerras stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */ 142614cf11afSPaul Mackerras std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */ 142714cf11afSPaul Mackerras 142814cf11afSPaul Mackerras /* Hash to the primary group */ 142914cf11afSPaul Mackerras ld r10,PACASTABVIRT(r13) 1430b5bbeb23SPaul Mackerras mfspr r11,SPRN_DAR 143114cf11afSPaul Mackerras srdi r11,r11,28 143214cf11afSPaul Mackerras rldimi r10,r11,7,52 /* r10 = first ste of the group */ 143314cf11afSPaul Mackerras 143414cf11afSPaul Mackerras /* Calculate VSID */ 143514cf11afSPaul Mackerras /* This is a kernel address, so protovsid = ESID */ 143614cf11afSPaul Mackerras ASM_VSID_SCRAMBLE(r11, r9) 143714cf11afSPaul Mackerras rldic r9,r11,12,16 /* r9 = vsid << 12 */ 143814cf11afSPaul Mackerras 143914cf11afSPaul Mackerras /* Search the primary group for a free entry */ 144014cf11afSPaul Mackerras1: ld r11,0(r10) /* Test valid bit of the current ste */ 144114cf11afSPaul Mackerras andi. r11,r11,0x80 144214cf11afSPaul Mackerras beq 2f 144314cf11afSPaul Mackerras addi r10,r10,16 144414cf11afSPaul Mackerras andi. r11,r10,0x70 144514cf11afSPaul Mackerras bne 1b 144614cf11afSPaul Mackerras 144714cf11afSPaul Mackerras /* Stick for only searching the primary group for now. */ 144814cf11afSPaul Mackerras /* At least for now, we use a very simple random castout scheme */ 144914cf11afSPaul Mackerras /* Use the TB as a random number ; OR in 1 to avoid entry 0 */ 145014cf11afSPaul Mackerras mftb r11 145114cf11afSPaul Mackerras rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */ 145214cf11afSPaul Mackerras ori r11,r11,0x10 145314cf11afSPaul Mackerras 145414cf11afSPaul Mackerras /* r10 currently points to an ste one past the group of interest */ 145514cf11afSPaul Mackerras /* make it point to the randomly selected entry */ 145614cf11afSPaul Mackerras subi r10,r10,128 145714cf11afSPaul Mackerras or r10,r10,r11 /* r10 is the entry to invalidate */ 145814cf11afSPaul Mackerras 145914cf11afSPaul Mackerras isync /* mark the entry invalid */ 146014cf11afSPaul Mackerras ld r11,0(r10) 146114cf11afSPaul Mackerras rldicl r11,r11,56,1 /* clear the valid bit */ 146214cf11afSPaul Mackerras rotldi r11,r11,8 146314cf11afSPaul Mackerras std r11,0(r10) 146414cf11afSPaul Mackerras sync 146514cf11afSPaul Mackerras 146614cf11afSPaul Mackerras clrrdi r11,r11,28 /* Get the esid part of the ste */ 146714cf11afSPaul Mackerras slbie r11 146814cf11afSPaul Mackerras 146914cf11afSPaul Mackerras2: std r9,8(r10) /* Store the vsid part of the ste */ 147014cf11afSPaul Mackerras eieio 147114cf11afSPaul Mackerras 1472b5bbeb23SPaul Mackerras mfspr r11,SPRN_DAR /* Get the new esid */ 147314cf11afSPaul Mackerras clrrdi r11,r11,28 /* Permits a full 32b of ESID */ 147414cf11afSPaul Mackerras ori r11,r11,0x90 /* Turn on valid and kp */ 147514cf11afSPaul Mackerras std r11,0(r10) /* Put new entry back into the stab */ 147614cf11afSPaul Mackerras 147714cf11afSPaul Mackerras sync 147814cf11afSPaul Mackerras 147914cf11afSPaul Mackerras /* All done -- return from exception. */ 148014cf11afSPaul Mackerras lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */ 148114cf11afSPaul Mackerras ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */ 148214cf11afSPaul Mackerras 148314cf11afSPaul Mackerras andi. r10,r12,MSR_RI 148414cf11afSPaul Mackerras beq- unrecov_slb 148514cf11afSPaul Mackerras 148614cf11afSPaul Mackerras mtcrf 0x80,r9 /* restore CR */ 148714cf11afSPaul Mackerras 148814cf11afSPaul Mackerras mfmsr r10 148914cf11afSPaul Mackerras clrrdi r10,r10,2 149014cf11afSPaul Mackerras mtmsrd r10,1 149114cf11afSPaul Mackerras 1492b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r11 1493b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r12 149414cf11afSPaul Mackerras ld r9,PACA_EXSLB+EX_R9(r13) 149514cf11afSPaul Mackerras ld r10,PACA_EXSLB+EX_R10(r13) 149614cf11afSPaul Mackerras ld r11,PACA_EXSLB+EX_R11(r13) 149714cf11afSPaul Mackerras ld r12,PACA_EXSLB+EX_R12(r13) 149814cf11afSPaul Mackerras ld r13,PACA_EXSLB+EX_R13(r13) 149914cf11afSPaul Mackerras rfid 150014cf11afSPaul Mackerras b . /* prevent speculative execution */ 150114cf11afSPaul Mackerras 150214cf11afSPaul Mackerras/* 150314cf11afSPaul Mackerras * Space for CPU0's segment table. 150414cf11afSPaul Mackerras * 150514cf11afSPaul Mackerras * On iSeries, the hypervisor must fill in at least one entry before 150614cf11afSPaul Mackerras * we get control (with relocate on). The address is give to the hv 1507ee400b63SStephen Rothwell * as a page number (see xLparMap in lpardata.c), so this must be at a 150814cf11afSPaul Mackerras * fixed address (the linker can't compute (u64)&initial_stab >> 150914cf11afSPaul Mackerras * PAGE_SHIFT). 151014cf11afSPaul Mackerras */ 1511758438a7SMichael Ellerman . = STAB0_OFFSET /* 0x6000 */ 151214cf11afSPaul Mackerras .globl initial_stab 151314cf11afSPaul Mackerrasinitial_stab: 151414cf11afSPaul Mackerras .space 4096 151514cf11afSPaul Mackerras 151614cf11afSPaul Mackerras/* 151714cf11afSPaul Mackerras * Data area reserved for FWNMI option. 151814cf11afSPaul Mackerras * This address (0x7000) is fixed by the RPA. 151914cf11afSPaul Mackerras */ 152014cf11afSPaul Mackerras .= 0x7000 152114cf11afSPaul Mackerras .globl fwnmi_data_area 152214cf11afSPaul Mackerrasfwnmi_data_area: 152314cf11afSPaul Mackerras 152414cf11afSPaul Mackerras /* iSeries does not use the FWNMI stuff, so it is safe to put 152514cf11afSPaul Mackerras * this here, even if we later allow kernels that will boot on 152614cf11afSPaul Mackerras * both pSeries and iSeries */ 152714cf11afSPaul Mackerras#ifdef CONFIG_PPC_ISERIES 152814cf11afSPaul Mackerras . = LPARMAP_PHYS 152914cf11afSPaul Mackerras#include "lparmap.s" 153014cf11afSPaul Mackerras/* 153114cf11afSPaul Mackerras * This ".text" is here for old compilers that generate a trailing 153214cf11afSPaul Mackerras * .note section when compiling .c files to .s 153314cf11afSPaul Mackerras */ 153414cf11afSPaul Mackerras .text 153514cf11afSPaul Mackerras#endif /* CONFIG_PPC_ISERIES */ 153614cf11afSPaul Mackerras 153714cf11afSPaul Mackerras . = 0x8000 153814cf11afSPaul Mackerras 153914cf11afSPaul Mackerras/* 1540f39b7a55SOlof Johansson * On pSeries and most other platforms, secondary processors spin 1541f39b7a55SOlof Johansson * in the following code. 154214cf11afSPaul Mackerras * At entry, r3 = this processor's number (physical cpu id) 154314cf11afSPaul Mackerras */ 1544f39b7a55SOlof Johansson_GLOBAL(generic_secondary_smp_init) 154514cf11afSPaul Mackerras mr r24,r3 154614cf11afSPaul Mackerras 154714cf11afSPaul Mackerras /* turn on 64-bit mode */ 154814cf11afSPaul Mackerras bl .enable_64b_mode 154914cf11afSPaul Mackerras isync 155014cf11afSPaul Mackerras 155114cf11afSPaul Mackerras /* Set up a paca value for this processor. Since we have the 155214cf11afSPaul Mackerras * physical cpu id in r24, we need to search the pacas to find 155314cf11afSPaul Mackerras * which logical id maps to our physical one. 155414cf11afSPaul Mackerras */ 1555e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */ 155614cf11afSPaul Mackerras li r5,0 /* logical cpu id */ 155714cf11afSPaul Mackerras1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */ 155814cf11afSPaul Mackerras cmpw r6,r24 /* Compare to our id */ 155914cf11afSPaul Mackerras beq 2f 156014cf11afSPaul Mackerras addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */ 156114cf11afSPaul Mackerras addi r5,r5,1 156214cf11afSPaul Mackerras cmpwi r5,NR_CPUS 156314cf11afSPaul Mackerras blt 1b 156414cf11afSPaul Mackerras 156514cf11afSPaul Mackerras mr r3,r24 /* not found, copy phys to r3 */ 156614cf11afSPaul Mackerras b .kexec_wait /* next kernel might do better */ 156714cf11afSPaul Mackerras 1568b5bbeb23SPaul Mackerras2: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */ 156914cf11afSPaul Mackerras /* From now on, r24 is expected to be logical cpuid */ 157014cf11afSPaul Mackerras mr r24,r5 157114cf11afSPaul Mackerras3: HMT_LOW 157214cf11afSPaul Mackerras lbz r23,PACAPROCSTART(r13) /* Test if this processor should */ 157314cf11afSPaul Mackerras /* start. */ 157414cf11afSPaul Mackerras sync 157514cf11afSPaul Mackerras 1576f39b7a55SOlof Johansson#ifndef CONFIG_SMP 1577f39b7a55SOlof Johansson b 3b /* Never go on non-SMP */ 1578f39b7a55SOlof Johansson#else 1579f39b7a55SOlof Johansson cmpwi 0,r23,0 1580f39b7a55SOlof Johansson beq 3b /* Loop until told to go */ 1581f39b7a55SOlof Johansson 1582f39b7a55SOlof Johansson /* See if we need to call a cpu state restore handler */ 1583f39b7a55SOlof Johansson LOAD_REG_IMMEDIATE(r23, cur_cpu_spec) 1584f39b7a55SOlof Johansson ld r23,0(r23) 1585f39b7a55SOlof Johansson ld r23,CPU_SPEC_RESTORE(r23) 1586f39b7a55SOlof Johansson cmpdi 0,r23,0 1587f39b7a55SOlof Johansson beq 4f 1588f39b7a55SOlof Johansson ld r23,0(r23) 1589f39b7a55SOlof Johansson mtctr r23 1590f39b7a55SOlof Johansson bctrl 1591f39b7a55SOlof Johansson 1592f39b7a55SOlof Johansson4: /* Create a temp kernel stack for use before relocation is on. */ 159314cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 159414cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 159514cf11afSPaul Mackerras 1596f39b7a55SOlof Johansson b .__secondary_start 159714cf11afSPaul Mackerras#endif 159814cf11afSPaul Mackerras 159914cf11afSPaul Mackerras#ifdef CONFIG_PPC_ISERIES 160014cf11afSPaul Mackerras_STATIC(__start_initialization_iSeries) 160114cf11afSPaul Mackerras /* Clear out the BSS */ 1602e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r11,__bss_stop) 1603e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r8,__bss_start) 160414cf11afSPaul Mackerras sub r11,r11,r8 /* bss size */ 160514cf11afSPaul Mackerras addi r11,r11,7 /* round up to an even double word */ 160614cf11afSPaul Mackerras rldicl. r11,r11,61,3 /* shift right by 3 */ 160714cf11afSPaul Mackerras beq 4f 160814cf11afSPaul Mackerras addi r8,r8,-8 160914cf11afSPaul Mackerras li r0,0 161014cf11afSPaul Mackerras mtctr r11 /* zero this many doublewords */ 161114cf11afSPaul Mackerras3: stdu r0,8(r8) 161214cf11afSPaul Mackerras bdnz 3b 161314cf11afSPaul Mackerras4: 1614e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r1,init_thread_union) 161514cf11afSPaul Mackerras addi r1,r1,THREAD_SIZE 161614cf11afSPaul Mackerras li r0,0 161714cf11afSPaul Mackerras stdu r0,-STACK_FRAME_OVERHEAD(r1) 161814cf11afSPaul Mackerras 1619e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r3,cpu_specs) 1620e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4,cur_cpu_spec) 162114cf11afSPaul Mackerras li r5,0 162214cf11afSPaul Mackerras bl .identify_cpu 162314cf11afSPaul Mackerras 1624e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r2,__toc_start) 162514cf11afSPaul Mackerras addi r2,r2,0x4000 162614cf11afSPaul Mackerras addi r2,r2,0x4000 162714cf11afSPaul Mackerras 162814cf11afSPaul Mackerras bl .iSeries_early_setup 1629ee400b63SStephen Rothwell bl .early_setup 163014cf11afSPaul Mackerras 163114cf11afSPaul Mackerras /* relocation is on at this point */ 163214cf11afSPaul Mackerras 163314cf11afSPaul Mackerras b .start_here_common 163414cf11afSPaul Mackerras#endif /* CONFIG_PPC_ISERIES */ 163514cf11afSPaul Mackerras 163614cf11afSPaul Mackerras#ifdef CONFIG_PPC_MULTIPLATFORM 163714cf11afSPaul Mackerras 163814cf11afSPaul Mackerras_STATIC(__mmu_off) 163914cf11afSPaul Mackerras mfmsr r3 164014cf11afSPaul Mackerras andi. r0,r3,MSR_IR|MSR_DR 164114cf11afSPaul Mackerras beqlr 164214cf11afSPaul Mackerras andc r3,r3,r0 164314cf11afSPaul Mackerras mtspr SPRN_SRR0,r4 164414cf11afSPaul Mackerras mtspr SPRN_SRR1,r3 164514cf11afSPaul Mackerras sync 164614cf11afSPaul Mackerras rfid 164714cf11afSPaul Mackerras b . /* prevent speculative execution */ 164814cf11afSPaul Mackerras 164914cf11afSPaul Mackerras 165014cf11afSPaul Mackerras/* 165114cf11afSPaul Mackerras * Here is our main kernel entry point. We support currently 2 kind of entries 165214cf11afSPaul Mackerras * depending on the value of r5. 165314cf11afSPaul Mackerras * 165414cf11afSPaul Mackerras * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content 165514cf11afSPaul Mackerras * in r3...r7 165614cf11afSPaul Mackerras * 165714cf11afSPaul Mackerras * r5 == NULL -> kexec style entry. r3 is a physical pointer to the 165814cf11afSPaul Mackerras * DT block, r4 is a physical pointer to the kernel itself 165914cf11afSPaul Mackerras * 166014cf11afSPaul Mackerras */ 166114cf11afSPaul Mackerras_GLOBAL(__start_initialization_multiplatform) 1662be42d5faSPaul Mackerras#ifdef CONFIG_PPC_MULTIPLATFORM 166314cf11afSPaul Mackerras /* 166414cf11afSPaul Mackerras * Are we booted from a PROM Of-type client-interface ? 166514cf11afSPaul Mackerras */ 166614cf11afSPaul Mackerras cmpldi cr0,r5,0 166714cf11afSPaul Mackerras bne .__boot_from_prom /* yes -> prom */ 1668be42d5faSPaul Mackerras#endif 166914cf11afSPaul Mackerras 167014cf11afSPaul Mackerras /* Save parameters */ 167114cf11afSPaul Mackerras mr r31,r3 167214cf11afSPaul Mackerras mr r30,r4 167314cf11afSPaul Mackerras 167414cf11afSPaul Mackerras /* Make sure we are running in 64 bits mode */ 167514cf11afSPaul Mackerras bl .enable_64b_mode 167614cf11afSPaul Mackerras 167714cf11afSPaul Mackerras /* Setup some critical 970 SPRs before switching MMU off */ 1678f39b7a55SOlof Johansson mfspr r0,SPRN_PVR 1679f39b7a55SOlof Johansson srwi r0,r0,16 1680f39b7a55SOlof Johansson cmpwi r0,0x39 /* 970 */ 1681f39b7a55SOlof Johansson beq 1f 1682f39b7a55SOlof Johansson cmpwi r0,0x3c /* 970FX */ 1683f39b7a55SOlof Johansson beq 1f 1684f39b7a55SOlof Johansson cmpwi r0,0x44 /* 970MP */ 1685f39b7a55SOlof Johansson bne 2f 1686f39b7a55SOlof Johansson1: bl .__cpu_preinit_ppc970 1687f39b7a55SOlof Johansson2: 168814cf11afSPaul Mackerras 168914cf11afSPaul Mackerras /* Switch off MMU if not already */ 1690e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE) 169114cf11afSPaul Mackerras add r4,r4,r30 169214cf11afSPaul Mackerras bl .__mmu_off 169314cf11afSPaul Mackerras b .__after_prom_start 169414cf11afSPaul Mackerras 1695be42d5faSPaul Mackerras#ifdef CONFIG_PPC_MULTIPLATFORM 169614cf11afSPaul Mackerras_STATIC(__boot_from_prom) 169714cf11afSPaul Mackerras /* Save parameters */ 169814cf11afSPaul Mackerras mr r31,r3 169914cf11afSPaul Mackerras mr r30,r4 170014cf11afSPaul Mackerras mr r29,r5 170114cf11afSPaul Mackerras mr r28,r6 170214cf11afSPaul Mackerras mr r27,r7 170314cf11afSPaul Mackerras 17046088857bSOlaf Hering /* 17056088857bSOlaf Hering * Align the stack to 16-byte boundary 17066088857bSOlaf Hering * Depending on the size and layout of the ELF sections in the initial 17076088857bSOlaf Hering * boot binary, the stack pointer will be unalignet on PowerMac 17086088857bSOlaf Hering */ 1709c05b4770SLinus Torvalds rldicr r1,r1,0,59 1710c05b4770SLinus Torvalds 171114cf11afSPaul Mackerras /* Make sure we are running in 64 bits mode */ 171214cf11afSPaul Mackerras bl .enable_64b_mode 171314cf11afSPaul Mackerras 171414cf11afSPaul Mackerras /* put a relocation offset into r3 */ 171514cf11afSPaul Mackerras bl .reloc_offset 171614cf11afSPaul Mackerras 1717e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r2,__toc_start) 171814cf11afSPaul Mackerras addi r2,r2,0x4000 171914cf11afSPaul Mackerras addi r2,r2,0x4000 172014cf11afSPaul Mackerras 172114cf11afSPaul Mackerras /* Relocate the TOC from a virt addr to a real addr */ 17225a408329SPaul Mackerras add r2,r2,r3 172314cf11afSPaul Mackerras 172414cf11afSPaul Mackerras /* Restore parameters */ 172514cf11afSPaul Mackerras mr r3,r31 172614cf11afSPaul Mackerras mr r4,r30 172714cf11afSPaul Mackerras mr r5,r29 172814cf11afSPaul Mackerras mr r6,r28 172914cf11afSPaul Mackerras mr r7,r27 173014cf11afSPaul Mackerras 173114cf11afSPaul Mackerras /* Do all of the interaction with OF client interface */ 173214cf11afSPaul Mackerras bl .prom_init 173314cf11afSPaul Mackerras /* We never return */ 173414cf11afSPaul Mackerras trap 1735be42d5faSPaul Mackerras#endif 173614cf11afSPaul Mackerras 173714cf11afSPaul Mackerras/* 173814cf11afSPaul Mackerras * At this point, r3 contains the physical address we are running at, 173914cf11afSPaul Mackerras * returned by prom_init() 174014cf11afSPaul Mackerras */ 174114cf11afSPaul Mackerras_STATIC(__after_prom_start) 174214cf11afSPaul Mackerras 174314cf11afSPaul Mackerras/* 1744758438a7SMichael Ellerman * We need to run with __start at physical address PHYSICAL_START. 174514cf11afSPaul Mackerras * This will leave some code in the first 256B of 174614cf11afSPaul Mackerras * real memory, which are reserved for software use. 174714cf11afSPaul Mackerras * The remainder of the first page is loaded with the fixed 174814cf11afSPaul Mackerras * interrupt vectors. The next two pages are filled with 174914cf11afSPaul Mackerras * unknown exception placeholders. 175014cf11afSPaul Mackerras * 175114cf11afSPaul Mackerras * Note: This process overwrites the OF exception vectors. 175214cf11afSPaul Mackerras * r26 == relocation offset 175314cf11afSPaul Mackerras * r27 == KERNELBASE 175414cf11afSPaul Mackerras */ 175514cf11afSPaul Mackerras bl .reloc_offset 175614cf11afSPaul Mackerras mr r26,r3 1757e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r27, KERNELBASE) 175814cf11afSPaul Mackerras 1759e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */ 176014cf11afSPaul Mackerras 176114cf11afSPaul Mackerras // XXX FIXME: Use phys returned by OF (r30) 17625a408329SPaul Mackerras add r4,r27,r26 /* source addr */ 176314cf11afSPaul Mackerras /* current address of _start */ 176414cf11afSPaul Mackerras /* i.e. where we are running */ 176514cf11afSPaul Mackerras /* the source addr */ 176614cf11afSPaul Mackerras 1767d0b79c54SJimi Xenidis cmpdi r4,0 /* In some cases the loader may */ 1768d0b79c54SJimi Xenidis beq .start_here_multiplatform /* have already put us at zero */ 1769d0b79c54SJimi Xenidis /* so we can skip the copy. */ 1770e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */ 177114cf11afSPaul Mackerras sub r5,r5,r27 177214cf11afSPaul Mackerras 177314cf11afSPaul Mackerras li r6,0x100 /* Start offset, the first 0x100 */ 177414cf11afSPaul Mackerras /* bytes were copied earlier. */ 177514cf11afSPaul Mackerras 177614cf11afSPaul Mackerras bl .copy_and_flush /* copy the first n bytes */ 177714cf11afSPaul Mackerras /* this includes the code being */ 177814cf11afSPaul Mackerras /* executed here. */ 177914cf11afSPaul Mackerras 1780e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */ 178114cf11afSPaul Mackerras mtctr r0 /* that we just made/relocated */ 178214cf11afSPaul Mackerras bctr 178314cf11afSPaul Mackerras 1784e58c3495SDavid Gibson4: LOAD_REG_IMMEDIATE(r5,klimit) 17855a408329SPaul Mackerras add r5,r5,r26 178614cf11afSPaul Mackerras ld r5,0(r5) /* get the value of klimit */ 178714cf11afSPaul Mackerras sub r5,r5,r27 178814cf11afSPaul Mackerras bl .copy_and_flush /* copy the rest */ 178914cf11afSPaul Mackerras b .start_here_multiplatform 179014cf11afSPaul Mackerras 179114cf11afSPaul Mackerras#endif /* CONFIG_PPC_MULTIPLATFORM */ 179214cf11afSPaul Mackerras 179314cf11afSPaul Mackerras/* 179414cf11afSPaul Mackerras * Copy routine used to copy the kernel to start at physical address 0 179514cf11afSPaul Mackerras * and flush and invalidate the caches as needed. 179614cf11afSPaul Mackerras * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset 179714cf11afSPaul Mackerras * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5. 179814cf11afSPaul Mackerras * 179914cf11afSPaul Mackerras * Note: this routine *only* clobbers r0, r6 and lr 180014cf11afSPaul Mackerras */ 180114cf11afSPaul Mackerras_GLOBAL(copy_and_flush) 180214cf11afSPaul Mackerras addi r5,r5,-8 180314cf11afSPaul Mackerras addi r6,r6,-8 18045a2fe38dSOlof Johansson4: li r0,8 /* Use the smallest common */ 180514cf11afSPaul Mackerras /* denominator cache line */ 180614cf11afSPaul Mackerras /* size. This results in */ 180714cf11afSPaul Mackerras /* extra cache line flushes */ 180814cf11afSPaul Mackerras /* but operation is correct. */ 180914cf11afSPaul Mackerras /* Can't get cache line size */ 181014cf11afSPaul Mackerras /* from NACA as it is being */ 181114cf11afSPaul Mackerras /* moved too. */ 181214cf11afSPaul Mackerras 181314cf11afSPaul Mackerras mtctr r0 /* put # words/line in ctr */ 181414cf11afSPaul Mackerras3: addi r6,r6,8 /* copy a cache line */ 181514cf11afSPaul Mackerras ldx r0,r6,r4 181614cf11afSPaul Mackerras stdx r0,r6,r3 181714cf11afSPaul Mackerras bdnz 3b 181814cf11afSPaul Mackerras dcbst r6,r3 /* write it to memory */ 181914cf11afSPaul Mackerras sync 182014cf11afSPaul Mackerras icbi r6,r3 /* flush the icache line */ 182114cf11afSPaul Mackerras cmpld 0,r6,r5 182214cf11afSPaul Mackerras blt 4b 182314cf11afSPaul Mackerras sync 182414cf11afSPaul Mackerras addi r5,r5,8 182514cf11afSPaul Mackerras addi r6,r6,8 182614cf11afSPaul Mackerras blr 182714cf11afSPaul Mackerras 182814cf11afSPaul Mackerras.align 8 182914cf11afSPaul Mackerrascopy_to_here: 183014cf11afSPaul Mackerras 183114cf11afSPaul Mackerras#ifdef CONFIG_SMP 183214cf11afSPaul Mackerras#ifdef CONFIG_PPC_PMAC 183314cf11afSPaul Mackerras/* 183414cf11afSPaul Mackerras * On PowerMac, secondary processors starts from the reset vector, which 183514cf11afSPaul Mackerras * is temporarily turned into a call to one of the functions below. 183614cf11afSPaul Mackerras */ 183714cf11afSPaul Mackerras .section ".text"; 183814cf11afSPaul Mackerras .align 2 ; 183914cf11afSPaul Mackerras 184035499c01SPaul Mackerras .globl __secondary_start_pmac_0 184135499c01SPaul Mackerras__secondary_start_pmac_0: 184235499c01SPaul Mackerras /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */ 184335499c01SPaul Mackerras li r24,0 184435499c01SPaul Mackerras b 1f 184514cf11afSPaul Mackerras li r24,1 184635499c01SPaul Mackerras b 1f 184714cf11afSPaul Mackerras li r24,2 184835499c01SPaul Mackerras b 1f 184914cf11afSPaul Mackerras li r24,3 185035499c01SPaul Mackerras1: 185114cf11afSPaul Mackerras 185214cf11afSPaul Mackerras_GLOBAL(pmac_secondary_start) 185314cf11afSPaul Mackerras /* turn on 64-bit mode */ 185414cf11afSPaul Mackerras bl .enable_64b_mode 185514cf11afSPaul Mackerras isync 185614cf11afSPaul Mackerras 185714cf11afSPaul Mackerras /* Copy some CPU settings from CPU 0 */ 1858f39b7a55SOlof Johansson bl .__restore_cpu_ppc970 185914cf11afSPaul Mackerras 186014cf11afSPaul Mackerras /* pSeries do that early though I don't think we really need it */ 186114cf11afSPaul Mackerras mfmsr r3 186214cf11afSPaul Mackerras ori r3,r3,MSR_RI 186314cf11afSPaul Mackerras mtmsrd r3 /* RI on */ 186414cf11afSPaul Mackerras 186514cf11afSPaul Mackerras /* Set up a paca value for this processor. */ 1866e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */ 186714cf11afSPaul Mackerras mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */ 186814cf11afSPaul Mackerras add r13,r13,r4 /* for this processor. */ 1869b5bbeb23SPaul Mackerras mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */ 187014cf11afSPaul Mackerras 187114cf11afSPaul Mackerras /* Create a temp kernel stack for use before relocation is on. */ 187214cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 187314cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 187414cf11afSPaul Mackerras 187514cf11afSPaul Mackerras b .__secondary_start 187614cf11afSPaul Mackerras 187714cf11afSPaul Mackerras#endif /* CONFIG_PPC_PMAC */ 187814cf11afSPaul Mackerras 187914cf11afSPaul Mackerras/* 188014cf11afSPaul Mackerras * This function is called after the master CPU has released the 188114cf11afSPaul Mackerras * secondary processors. The execution environment is relocation off. 188214cf11afSPaul Mackerras * The paca for this processor has the following fields initialized at 188314cf11afSPaul Mackerras * this point: 188414cf11afSPaul Mackerras * 1. Processor number 188514cf11afSPaul Mackerras * 2. Segment table pointer (virtual address) 188614cf11afSPaul Mackerras * On entry the following are set: 188714cf11afSPaul Mackerras * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries 188814cf11afSPaul Mackerras * r24 = cpu# (in Linux terms) 188914cf11afSPaul Mackerras * r13 = paca virtual address 189014cf11afSPaul Mackerras * SPRG3 = paca virtual address 189114cf11afSPaul Mackerras */ 189214cf11afSPaul Mackerras_GLOBAL(__secondary_start) 1893799d6046SPaul Mackerras /* Set thread priority to MEDIUM */ 1894799d6046SPaul Mackerras HMT_MEDIUM 189514cf11afSPaul Mackerras 1896799d6046SPaul Mackerras /* Load TOC */ 189714cf11afSPaul Mackerras ld r2,PACATOC(r13) 189814cf11afSPaul Mackerras 1899799d6046SPaul Mackerras /* Do early setup for that CPU (stab, slb, hash table pointer) */ 1900799d6046SPaul Mackerras bl .early_setup_secondary 190114cf11afSPaul Mackerras 190214cf11afSPaul Mackerras /* Initialize the kernel stack. Just a repeat for iSeries. */ 1903e58c3495SDavid Gibson LOAD_REG_ADDR(r3, current_set) 190414cf11afSPaul Mackerras sldi r28,r24,3 /* get current_set[cpu#] */ 190514cf11afSPaul Mackerras ldx r1,r3,r28 190614cf11afSPaul Mackerras addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD 190714cf11afSPaul Mackerras std r1,PACAKSAVE(r13) 190814cf11afSPaul Mackerras 1909799d6046SPaul Mackerras /* Clear backchain so we get nice backtraces */ 191014cf11afSPaul Mackerras li r7,0 191114cf11afSPaul Mackerras mtlr r7 191214cf11afSPaul Mackerras 191314cf11afSPaul Mackerras /* enable MMU and jump to start_secondary */ 1914e58c3495SDavid Gibson LOAD_REG_ADDR(r3, .start_secondary_prolog) 1915e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4, MSR_KERNEL) 1916*d04c56f7SPaul Mackerras#ifdef CONFIG_PPC_ISERIES 19173f639ee8SStephen RothwellBEGIN_FW_FTR_SECTION 191814cf11afSPaul Mackerras ori r4,r4,MSR_EE 19193f639ee8SStephen RothwellEND_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) 192014cf11afSPaul Mackerras#endif 1921*d04c56f7SPaul MackerrasBEGIN_FW_FTR_SECTION 1922*d04c56f7SPaul Mackerras stb r7,PACASOFTIRQEN(r13) 1923*d04c56f7SPaul Mackerras stb r7,PACAHARDIRQEN(r13) 1924*d04c56f7SPaul MackerrasEND_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES) 1925*d04c56f7SPaul Mackerras 1926b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r3 1927b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r4 192814cf11afSPaul Mackerras rfid 192914cf11afSPaul Mackerras b . /* prevent speculative execution */ 193014cf11afSPaul Mackerras 193114cf11afSPaul Mackerras/* 193214cf11afSPaul Mackerras * Running with relocation on at this point. All we want to do is 193314cf11afSPaul Mackerras * zero the stack back-chain pointer before going into C code. 193414cf11afSPaul Mackerras */ 193514cf11afSPaul Mackerras_GLOBAL(start_secondary_prolog) 193614cf11afSPaul Mackerras li r3,0 193714cf11afSPaul Mackerras std r3,0(r1) /* Zero the stack frame pointer */ 193814cf11afSPaul Mackerras bl .start_secondary 1939799d6046SPaul Mackerras b . 194014cf11afSPaul Mackerras#endif 194114cf11afSPaul Mackerras 194214cf11afSPaul Mackerras/* 194314cf11afSPaul Mackerras * This subroutine clobbers r11 and r12 194414cf11afSPaul Mackerras */ 194514cf11afSPaul Mackerras_GLOBAL(enable_64b_mode) 194614cf11afSPaul Mackerras mfmsr r11 /* grab the current MSR */ 194714cf11afSPaul Mackerras li r12,1 194814cf11afSPaul Mackerras rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG) 194914cf11afSPaul Mackerras or r11,r11,r12 195014cf11afSPaul Mackerras li r12,1 195114cf11afSPaul Mackerras rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG) 195214cf11afSPaul Mackerras or r11,r11,r12 195314cf11afSPaul Mackerras mtmsrd r11 195414cf11afSPaul Mackerras isync 195514cf11afSPaul Mackerras blr 195614cf11afSPaul Mackerras 195714cf11afSPaul Mackerras#ifdef CONFIG_PPC_MULTIPLATFORM 195814cf11afSPaul Mackerras/* 195914cf11afSPaul Mackerras * This is where the main kernel code starts. 196014cf11afSPaul Mackerras */ 196114cf11afSPaul Mackerras_STATIC(start_here_multiplatform) 196214cf11afSPaul Mackerras /* get a new offset, now that the kernel has moved. */ 196314cf11afSPaul Mackerras bl .reloc_offset 196414cf11afSPaul Mackerras mr r26,r3 196514cf11afSPaul Mackerras 196614cf11afSPaul Mackerras /* Clear out the BSS. It may have been done in prom_init, 196714cf11afSPaul Mackerras * already but that's irrelevant since prom_init will soon 196814cf11afSPaul Mackerras * be detached from the kernel completely. Besides, we need 196914cf11afSPaul Mackerras * to clear it now for kexec-style entry. 197014cf11afSPaul Mackerras */ 1971e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r11,__bss_stop) 1972e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r8,__bss_start) 197314cf11afSPaul Mackerras sub r11,r11,r8 /* bss size */ 197414cf11afSPaul Mackerras addi r11,r11,7 /* round up to an even double word */ 197514cf11afSPaul Mackerras rldicl. r11,r11,61,3 /* shift right by 3 */ 197614cf11afSPaul Mackerras beq 4f 197714cf11afSPaul Mackerras addi r8,r8,-8 197814cf11afSPaul Mackerras li r0,0 197914cf11afSPaul Mackerras mtctr r11 /* zero this many doublewords */ 198014cf11afSPaul Mackerras3: stdu r0,8(r8) 198114cf11afSPaul Mackerras bdnz 3b 198214cf11afSPaul Mackerras4: 198314cf11afSPaul Mackerras 198414cf11afSPaul Mackerras mfmsr r6 198514cf11afSPaul Mackerras ori r6,r6,MSR_RI 198614cf11afSPaul Mackerras mtmsrd r6 /* RI on */ 198714cf11afSPaul Mackerras 198814cf11afSPaul Mackerras /* The following gets the stack and TOC set up with the regs */ 198914cf11afSPaul Mackerras /* pointing to the real addr of the kernel stack. This is */ 199014cf11afSPaul Mackerras /* all done to support the C function call below which sets */ 199114cf11afSPaul Mackerras /* up the htab. This is done because we have relocated the */ 199214cf11afSPaul Mackerras /* kernel but are still running in real mode. */ 199314cf11afSPaul Mackerras 1994e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r3,init_thread_union) 19955a408329SPaul Mackerras add r3,r3,r26 199614cf11afSPaul Mackerras 199714cf11afSPaul Mackerras /* set up a stack pointer (physical address) */ 199814cf11afSPaul Mackerras addi r1,r3,THREAD_SIZE 199914cf11afSPaul Mackerras li r0,0 200014cf11afSPaul Mackerras stdu r0,-STACK_FRAME_OVERHEAD(r1) 200114cf11afSPaul Mackerras 200214cf11afSPaul Mackerras /* set up the TOC (physical address) */ 2003e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r2,__toc_start) 200414cf11afSPaul Mackerras addi r2,r2,0x4000 200514cf11afSPaul Mackerras addi r2,r2,0x4000 20065a408329SPaul Mackerras add r2,r2,r26 200714cf11afSPaul Mackerras 2008e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r3, cpu_specs) 20095a408329SPaul Mackerras add r3,r3,r26 2010e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4,cur_cpu_spec) 20115a408329SPaul Mackerras add r4,r4,r26 201214cf11afSPaul Mackerras mr r5,r26 201314cf11afSPaul Mackerras bl .identify_cpu 201414cf11afSPaul Mackerras 201514cf11afSPaul Mackerras /* Do very early kernel initializations, including initial hash table, 201614cf11afSPaul Mackerras * stab and slb setup before we turn on relocation. */ 201714cf11afSPaul Mackerras 201814cf11afSPaul Mackerras /* Restore parameters passed from prom_init/kexec */ 201914cf11afSPaul Mackerras mr r3,r31 202014cf11afSPaul Mackerras bl .early_setup 202114cf11afSPaul Mackerras 2022e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r3, .start_here_common) 2023e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4, MSR_KERNEL) 2024b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r3 2025b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r4 202614cf11afSPaul Mackerras rfid 202714cf11afSPaul Mackerras b . /* prevent speculative execution */ 202814cf11afSPaul Mackerras#endif /* CONFIG_PPC_MULTIPLATFORM */ 202914cf11afSPaul Mackerras 203014cf11afSPaul Mackerras /* This is where all platforms converge execution */ 203114cf11afSPaul Mackerras_STATIC(start_here_common) 203214cf11afSPaul Mackerras /* relocation is on at this point */ 203314cf11afSPaul Mackerras 203414cf11afSPaul Mackerras /* The following code sets up the SP and TOC now that we are */ 203514cf11afSPaul Mackerras /* running with translation enabled. */ 203614cf11afSPaul Mackerras 2037e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r3,init_thread_union) 203814cf11afSPaul Mackerras 203914cf11afSPaul Mackerras /* set up the stack */ 204014cf11afSPaul Mackerras addi r1,r3,THREAD_SIZE 204114cf11afSPaul Mackerras li r0,0 204214cf11afSPaul Mackerras stdu r0,-STACK_FRAME_OVERHEAD(r1) 204314cf11afSPaul Mackerras 204414cf11afSPaul Mackerras /* Apply the CPUs-specific fixups (nop out sections not relevant 204514cf11afSPaul Mackerras * to this CPU 204614cf11afSPaul Mackerras */ 204714cf11afSPaul Mackerras li r3,0 204814cf11afSPaul Mackerras bl .do_cpu_ftr_fixups 20493f639ee8SStephen Rothwell bl .do_fw_ftr_fixups 205014cf11afSPaul Mackerras 205114cf11afSPaul Mackerras /* ptr to current */ 2052e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4, init_task) 205314cf11afSPaul Mackerras std r4,PACACURRENT(r13) 205414cf11afSPaul Mackerras 205514cf11afSPaul Mackerras /* Load the TOC */ 205614cf11afSPaul Mackerras ld r2,PACATOC(r13) 205714cf11afSPaul Mackerras std r1,PACAKSAVE(r13) 205814cf11afSPaul Mackerras 205914cf11afSPaul Mackerras bl .setup_system 206014cf11afSPaul Mackerras 206114cf11afSPaul Mackerras /* Load up the kernel context */ 206214cf11afSPaul Mackerras5: 206314cf11afSPaul Mackerras li r5,0 2064*d04c56f7SPaul Mackerras stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */ 2065*d04c56f7SPaul Mackerras#ifdef CONFIG_PPC_ISERIES 2066*d04c56f7SPaul MackerrasBEGIN_FW_FTR_SECTION 206714cf11afSPaul Mackerras mfmsr r5 206814cf11afSPaul Mackerras ori r5,r5,MSR_EE /* Hard Enabled */ 206914cf11afSPaul Mackerras mtmsrd r5 20703f639ee8SStephen RothwellEND_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) 207114cf11afSPaul Mackerras#endif 2072*d04c56f7SPaul MackerrasBEGIN_FW_FTR_SECTION 2073*d04c56f7SPaul Mackerras stb r5,PACAHARDIRQEN(r13) 2074*d04c56f7SPaul MackerrasEND_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES) 207514cf11afSPaul Mackerras 207614cf11afSPaul Mackerras bl .start_kernel 207714cf11afSPaul Mackerras 2078f1870f77SAnton Blanchard /* Not reached */ 2079f1870f77SAnton Blanchard BUG_OPCODE 208014cf11afSPaul Mackerras 208114cf11afSPaul Mackerras/* 208214cf11afSPaul Mackerras * We put a few things here that have to be page-aligned. 208314cf11afSPaul Mackerras * This stuff goes at the beginning of the bss, which is page-aligned. 208414cf11afSPaul Mackerras */ 208514cf11afSPaul Mackerras .section ".bss" 208614cf11afSPaul Mackerras 208714cf11afSPaul Mackerras .align PAGE_SHIFT 208814cf11afSPaul Mackerras 208914cf11afSPaul Mackerras .globl empty_zero_page 209014cf11afSPaul Mackerrasempty_zero_page: 209114cf11afSPaul Mackerras .space PAGE_SIZE 209214cf11afSPaul Mackerras 209314cf11afSPaul Mackerras .globl swapper_pg_dir 209414cf11afSPaul Mackerrasswapper_pg_dir: 209514cf11afSPaul Mackerras .space PAGE_SIZE 209614cf11afSPaul Mackerras 209714cf11afSPaul Mackerras/* 209814cf11afSPaul Mackerras * This space gets a copy of optional info passed to us by the bootstrap 209914cf11afSPaul Mackerras * Used to pass parameters into the kernel like root=/dev/sda1, etc. 210014cf11afSPaul Mackerras */ 210114cf11afSPaul Mackerras .globl cmd_line 210214cf11afSPaul Mackerrascmd_line: 210314cf11afSPaul Mackerras .space COMMAND_LINE_SIZE 2104