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 * 150ebc4cdaSBenjamin Herrenschmidt * This file contains the entry point for the 64-bit kernel along 160ebc4cdaSBenjamin Herrenschmidt * with some early initialization code common to all 64-bit powerpc 170ebc4cdaSBenjamin Herrenschmidt * variants. 1814cf11afSPaul Mackerras * 1914cf11afSPaul Mackerras * This program is free software; you can redistribute it and/or 2014cf11afSPaul Mackerras * modify it under the terms of the GNU General Public License 2114cf11afSPaul Mackerras * as published by the Free Software Foundation; either version 2214cf11afSPaul Mackerras * 2 of the License, or (at your option) any later version. 2314cf11afSPaul Mackerras */ 2414cf11afSPaul Mackerras 2514cf11afSPaul Mackerras#include <linux/threads.h> 26b5bbeb23SPaul Mackerras#include <asm/reg.h> 2714cf11afSPaul Mackerras#include <asm/page.h> 2814cf11afSPaul Mackerras#include <asm/mmu.h> 2914cf11afSPaul Mackerras#include <asm/ppc_asm.h> 3014cf11afSPaul Mackerras#include <asm/asm-offsets.h> 3114cf11afSPaul Mackerras#include <asm/bug.h> 3214cf11afSPaul Mackerras#include <asm/cputable.h> 3314cf11afSPaul Mackerras#include <asm/setup.h> 3414cf11afSPaul Mackerras#include <asm/hvcall.h> 356cb7bfebSDavid Gibson#include <asm/thread_info.h> 363f639ee8SStephen Rothwell#include <asm/firmware.h> 3716a15a30SStephen Rothwell#include <asm/page_64.h> 38945feb17SBenjamin Herrenschmidt#include <asm/irqflags.h> 392191d657SAlexander Graf#include <asm/kvm_book3s_asm.h> 4046f52210SStephen Rothwell#include <asm/ptrace.h> 41*7230c564SBenjamin Herrenschmidt#include <asm/hw_irq.h> 4214cf11afSPaul Mackerras 4325985edcSLucas De Marchi/* The physical memory is laid out such that the secondary processor 440ebc4cdaSBenjamin Herrenschmidt * spin code sits at 0x0000...0x00ff. On server, the vectors follow 450ebc4cdaSBenjamin Herrenschmidt * using the layout described in exceptions-64s.S 4614cf11afSPaul Mackerras */ 4714cf11afSPaul Mackerras 4814cf11afSPaul Mackerras/* 4914cf11afSPaul Mackerras * Entering into this code we make the following assumptions: 500ebc4cdaSBenjamin Herrenschmidt * 510ebc4cdaSBenjamin Herrenschmidt * For pSeries or server processors: 5214cf11afSPaul Mackerras * 1. The MMU is off & open firmware is running in real mode. 5314cf11afSPaul Mackerras * 2. The kernel is entered at __start 5427f44888SBenjamin Herrenschmidt * -or- For OPAL entry: 5527f44888SBenjamin Herrenschmidt * 1. The MMU is off, processor in HV mode, primary CPU enters at 0 56daea1175SBenjamin Herrenschmidt * with device-tree in gpr3. We also get OPAL base in r8 and 57daea1175SBenjamin Herrenschmidt * entry in r9 for debugging purposes 5827f44888SBenjamin Herrenschmidt * 2. Secondary processors enter at 0x60 with PIR in gpr3 5914cf11afSPaul Mackerras * 600ebc4cdaSBenjamin Herrenschmidt * For Book3E processors: 610ebc4cdaSBenjamin Herrenschmidt * 1. The MMU is on running in AS0 in a state defined in ePAPR 620ebc4cdaSBenjamin Herrenschmidt * 2. The kernel is entered at __start 6314cf11afSPaul Mackerras */ 6414cf11afSPaul Mackerras 6514cf11afSPaul Mackerras .text 6614cf11afSPaul Mackerras .globl _stext 6714cf11afSPaul Mackerras_stext: 6814cf11afSPaul Mackerras_GLOBAL(__start) 6914cf11afSPaul Mackerras /* NOP this out unconditionally */ 7014cf11afSPaul MackerrasBEGIN_FTR_SECTION 7114cf11afSPaul Mackerras b .__start_initialization_multiplatform 7214cf11afSPaul MackerrasEND_FTR_SECTION(0, 1) 7314cf11afSPaul Mackerras 7414cf11afSPaul Mackerras /* Catch branch to 0 in real mode */ 7514cf11afSPaul Mackerras trap 7614cf11afSPaul Mackerras 771f6a93e4SPaul Mackerras /* Secondary processors spin on this value until it becomes nonzero. 781f6a93e4SPaul Mackerras * When it does it contains the real address of the descriptor 791f6a93e4SPaul Mackerras * of the function that the cpu should jump to to continue 801f6a93e4SPaul Mackerras * initialization. 811f6a93e4SPaul Mackerras */ 8214cf11afSPaul Mackerras .globl __secondary_hold_spinloop 8314cf11afSPaul Mackerras__secondary_hold_spinloop: 8414cf11afSPaul Mackerras .llong 0x0 8514cf11afSPaul Mackerras 8614cf11afSPaul Mackerras /* Secondary processors write this value with their cpu # */ 8714cf11afSPaul Mackerras /* after they enter the spin loop immediately below. */ 8814cf11afSPaul Mackerras .globl __secondary_hold_acknowledge 8914cf11afSPaul Mackerras__secondary_hold_acknowledge: 9014cf11afSPaul Mackerras .llong 0x0 9114cf11afSPaul Mackerras 92928a3197SSonny Rao#ifdef CONFIG_RELOCATABLE 938b8b0cc1SMilton Miller /* This flag is set to 1 by a loader if the kernel should run 948b8b0cc1SMilton Miller * at the loaded address instead of the linked address. This 958b8b0cc1SMilton Miller * is used by kexec-tools to keep the the kdump kernel in the 968b8b0cc1SMilton Miller * crash_kernel region. The loader is responsible for 978b8b0cc1SMilton Miller * observing the alignment requirement. 988b8b0cc1SMilton Miller */ 998b8b0cc1SMilton Miller /* Do not move this variable as kexec-tools knows about it. */ 1008b8b0cc1SMilton Miller . = 0x5c 1018b8b0cc1SMilton Miller .globl __run_at_load 1028b8b0cc1SMilton Miller__run_at_load: 1038b8b0cc1SMilton Miller .long 0x72756e30 /* "run0" -- relocate to 0 by default */ 1048b8b0cc1SMilton Miller#endif 1058b8b0cc1SMilton Miller 10614cf11afSPaul Mackerras . = 0x60 10714cf11afSPaul Mackerras/* 10875423b7bSGeoff Levand * The following code is used to hold secondary processors 10975423b7bSGeoff Levand * in a spin loop after they have entered the kernel, 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. 1131f6a93e4SPaul Mackerras * Use .globl here not _GLOBAL because we want __secondary_hold 1141f6a93e4SPaul Mackerras * to be the actual text address, not a descriptor. 11514cf11afSPaul Mackerras */ 1161f6a93e4SPaul Mackerras .globl __secondary_hold 1171f6a93e4SPaul Mackerras__secondary_hold: 1182d27cfd3SBenjamin Herrenschmidt#ifndef CONFIG_PPC_BOOK3E 11914cf11afSPaul Mackerras mfmsr r24 12014cf11afSPaul Mackerras ori r24,r24,MSR_RI 12114cf11afSPaul Mackerras mtmsrd r24 /* RI on */ 1222d27cfd3SBenjamin Herrenschmidt#endif 123f1870f77SAnton Blanchard /* Grab our physical cpu number */ 12414cf11afSPaul Mackerras mr r24,r3 12514cf11afSPaul Mackerras 12614cf11afSPaul Mackerras /* Tell the master cpu we're here */ 12714cf11afSPaul Mackerras /* Relocation is off & we are located at an address less */ 12814cf11afSPaul Mackerras /* than 0x100, so only need to grab low order offset. */ 129e31aa453SPaul Mackerras std r24,__secondary_hold_acknowledge-_stext(0) 13014cf11afSPaul Mackerras sync 13114cf11afSPaul Mackerras 13214cf11afSPaul Mackerras /* All secondary cpus wait here until told to start. */ 133e31aa453SPaul Mackerras100: ld r4,__secondary_hold_spinloop-_stext(0) 1341f6a93e4SPaul Mackerras cmpdi 0,r4,0 1351f6a93e4SPaul Mackerras beq 100b 13614cf11afSPaul Mackerras 137f1870f77SAnton Blanchard#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC) 1381f6a93e4SPaul Mackerras ld r4,0(r4) /* deref function descriptor */ 139758438a7SMichael Ellerman mtctr r4 14014cf11afSPaul Mackerras mr r3,r24 1412d27cfd3SBenjamin Herrenschmidt li r4,0 142dd797738SBenjamin Herrenschmidt /* Make sure that patched code is visible */ 143dd797738SBenjamin Herrenschmidt isync 144758438a7SMichael Ellerman bctr 14514cf11afSPaul Mackerras#else 14614cf11afSPaul Mackerras BUG_OPCODE 14714cf11afSPaul Mackerras#endif 14814cf11afSPaul Mackerras 14914cf11afSPaul Mackerras/* This value is used to mark exception frames on the stack. */ 15014cf11afSPaul Mackerras .section ".toc","aw" 15114cf11afSPaul Mackerrasexception_marker: 15214cf11afSPaul Mackerras .tc ID_72656773_68657265[TC],0x7265677368657265 15314cf11afSPaul Mackerras .text 15414cf11afSPaul Mackerras 15514cf11afSPaul Mackerras/* 1560ebc4cdaSBenjamin Herrenschmidt * On server, we include the exception vectors code here as it 1570ebc4cdaSBenjamin Herrenschmidt * relies on absolute addressing which is only possible within 1580ebc4cdaSBenjamin Herrenschmidt * this compilation unit 15914cf11afSPaul Mackerras */ 1600ebc4cdaSBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3S 1610ebc4cdaSBenjamin Herrenschmidt#include "exceptions-64s.S" 1621f6a93e4SPaul Mackerras#endif 16314cf11afSPaul Mackerras 1642d27cfd3SBenjamin Herrenschmidt_GLOBAL(generic_secondary_thread_init) 16514cf11afSPaul Mackerras mr r24,r3 16614cf11afSPaul Mackerras 16714cf11afSPaul Mackerras /* turn on 64-bit mode */ 16814cf11afSPaul Mackerras bl .enable_64b_mode 16914cf11afSPaul Mackerras 1702d27cfd3SBenjamin Herrenschmidt /* get a valid TOC pointer, wherever we're mapped at */ 171e31aa453SPaul Mackerras bl .relative_toc 172e31aa453SPaul Mackerras 1732d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 1742d27cfd3SBenjamin Herrenschmidt /* Book3E initialization */ 1752d27cfd3SBenjamin Herrenschmidt mr r3,r24 1762d27cfd3SBenjamin Herrenschmidt bl .book3e_secondary_thread_init 1772d27cfd3SBenjamin Herrenschmidt#endif 1782d27cfd3SBenjamin Herrenschmidt b generic_secondary_common_init 1792d27cfd3SBenjamin Herrenschmidt 1802d27cfd3SBenjamin Herrenschmidt/* 1812d27cfd3SBenjamin Herrenschmidt * On pSeries and most other platforms, secondary processors spin 1822d27cfd3SBenjamin Herrenschmidt * in the following code. 1832d27cfd3SBenjamin Herrenschmidt * At entry, r3 = this processor's number (physical cpu id) 1842d27cfd3SBenjamin Herrenschmidt * 1852d27cfd3SBenjamin Herrenschmidt * On Book3E, r4 = 1 to indicate that the initial TLB entry for 1862d27cfd3SBenjamin Herrenschmidt * this core already exists (setup via some other mechanism such 1872d27cfd3SBenjamin Herrenschmidt * as SCOM before entry). 1882d27cfd3SBenjamin Herrenschmidt */ 1892d27cfd3SBenjamin Herrenschmidt_GLOBAL(generic_secondary_smp_init) 1902d27cfd3SBenjamin Herrenschmidt mr r24,r3 1912d27cfd3SBenjamin Herrenschmidt mr r25,r4 1922d27cfd3SBenjamin Herrenschmidt 1932d27cfd3SBenjamin Herrenschmidt /* turn on 64-bit mode */ 1942d27cfd3SBenjamin Herrenschmidt bl .enable_64b_mode 1952d27cfd3SBenjamin Herrenschmidt 1962d27cfd3SBenjamin Herrenschmidt /* get a valid TOC pointer, wherever we're mapped at */ 1972d27cfd3SBenjamin Herrenschmidt bl .relative_toc 1982d27cfd3SBenjamin Herrenschmidt 1992d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 2002d27cfd3SBenjamin Herrenschmidt /* Book3E initialization */ 2012d27cfd3SBenjamin Herrenschmidt mr r3,r24 2022d27cfd3SBenjamin Herrenschmidt mr r4,r25 2032d27cfd3SBenjamin Herrenschmidt bl .book3e_secondary_core_init 2042d27cfd3SBenjamin Herrenschmidt#endif 2052d27cfd3SBenjamin Herrenschmidt 2062d27cfd3SBenjamin Herrenschmidtgeneric_secondary_common_init: 20714cf11afSPaul Mackerras /* Set up a paca value for this processor. Since we have the 20814cf11afSPaul Mackerras * physical cpu id in r24, we need to search the pacas to find 20914cf11afSPaul Mackerras * which logical id maps to our physical one. 21014cf11afSPaul Mackerras */ 2111426d5a3SMichael Ellerman LOAD_REG_ADDR(r13, paca) /* Load paca pointer */ 2121426d5a3SMichael Ellerman ld r13,0(r13) /* Get base vaddr of paca array */ 213768d18adSMilton Miller#ifndef CONFIG_SMP 214768d18adSMilton Miller addi r13,r13,PACA_SIZE /* know r13 if used accidentally */ 215768d18adSMilton Miller b .kexec_wait /* wait for next kernel if !SMP */ 216768d18adSMilton Miller#else 217768d18adSMilton Miller LOAD_REG_ADDR(r7, nr_cpu_ids) /* Load nr_cpu_ids address */ 218768d18adSMilton Miller lwz r7,0(r7) /* also the max paca allocated */ 21914cf11afSPaul Mackerras li r5,0 /* logical cpu id */ 22014cf11afSPaul Mackerras1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */ 22114cf11afSPaul Mackerras cmpw r6,r24 /* Compare to our id */ 22214cf11afSPaul Mackerras beq 2f 22314cf11afSPaul Mackerras addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */ 22414cf11afSPaul Mackerras addi r5,r5,1 225768d18adSMilton Miller cmpw r5,r7 /* Check if more pacas exist */ 22614cf11afSPaul Mackerras blt 1b 22714cf11afSPaul Mackerras 22814cf11afSPaul Mackerras mr r3,r24 /* not found, copy phys to r3 */ 22914cf11afSPaul Mackerras b .kexec_wait /* next kernel might do better */ 23014cf11afSPaul Mackerras 2312dd60d79SBenjamin Herrenschmidt2: SET_PACA(r13) 2322d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 2332d27cfd3SBenjamin Herrenschmidt addi r12,r13,PACA_EXTLB /* and TLB exc frame in another */ 2342d27cfd3SBenjamin Herrenschmidt mtspr SPRN_SPRG_TLB_EXFRAME,r12 2352d27cfd3SBenjamin Herrenschmidt#endif 2362d27cfd3SBenjamin Herrenschmidt 23714cf11afSPaul Mackerras /* From now on, r24 is expected to be logical cpuid */ 23814cf11afSPaul Mackerras mr r24,r5 239b6f6b98aSSonny Rao 240f39b7a55SOlof Johansson /* See if we need to call a cpu state restore handler */ 241e31aa453SPaul Mackerras LOAD_REG_ADDR(r23, cur_cpu_spec) 242f39b7a55SOlof Johansson ld r23,0(r23) 243f39b7a55SOlof Johansson ld r23,CPU_SPEC_RESTORE(r23) 244f39b7a55SOlof Johansson cmpdi 0,r23,0 2459d07bc84SBenjamin Herrenschmidt beq 3f 246f39b7a55SOlof Johansson ld r23,0(r23) 247f39b7a55SOlof Johansson mtctr r23 248f39b7a55SOlof Johansson bctrl 249f39b7a55SOlof Johansson 2507ac87abbSMatt Evans3: LOAD_REG_ADDR(r3, spinning_secondaries) /* Decrement spinning_secondaries */ 2519d07bc84SBenjamin Herrenschmidt lwarx r4,0,r3 2529d07bc84SBenjamin Herrenschmidt subi r4,r4,1 2539d07bc84SBenjamin Herrenschmidt stwcx. r4,0,r3 2549d07bc84SBenjamin Herrenschmidt bne 3b 2559d07bc84SBenjamin Herrenschmidt isync 2569d07bc84SBenjamin Herrenschmidt 2579d07bc84SBenjamin Herrenschmidt4: HMT_LOW 258ad0693eeSBenjamin Herrenschmidt lbz r23,PACAPROCSTART(r13) /* Test if this processor should */ 259ad0693eeSBenjamin Herrenschmidt /* start. */ 260ad0693eeSBenjamin Herrenschmidt cmpwi 0,r23,0 2619d07bc84SBenjamin Herrenschmidt beq 4b /* Loop until told to go */ 262ad0693eeSBenjamin Herrenschmidt 263ad0693eeSBenjamin Herrenschmidt sync /* order paca.run and cur_cpu_spec */ 2649d07bc84SBenjamin Herrenschmidt isync /* In case code patching happened */ 265ad0693eeSBenjamin Herrenschmidt 2669d07bc84SBenjamin Herrenschmidt /* Create a temp kernel stack for use before relocation is on. */ 26714cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 26814cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 26914cf11afSPaul Mackerras 270c705677eSStephen Rothwell b __secondary_start 271768d18adSMilton Miller#endif /* SMP */ 27214cf11afSPaul Mackerras 273e31aa453SPaul Mackerras/* 274e31aa453SPaul Mackerras * Turn the MMU off. 275e31aa453SPaul Mackerras * Assumes we're mapped EA == RA if the MMU is on. 276e31aa453SPaul Mackerras */ 2772d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3S 27814cf11afSPaul Mackerras_STATIC(__mmu_off) 27914cf11afSPaul Mackerras mfmsr r3 28014cf11afSPaul Mackerras andi. r0,r3,MSR_IR|MSR_DR 28114cf11afSPaul Mackerras beqlr 282e31aa453SPaul Mackerras mflr r4 28314cf11afSPaul Mackerras andc r3,r3,r0 28414cf11afSPaul Mackerras mtspr SPRN_SRR0,r4 28514cf11afSPaul Mackerras mtspr SPRN_SRR1,r3 28614cf11afSPaul Mackerras sync 28714cf11afSPaul Mackerras rfid 28814cf11afSPaul Mackerras b . /* prevent speculative execution */ 2892d27cfd3SBenjamin Herrenschmidt#endif 29014cf11afSPaul Mackerras 29114cf11afSPaul Mackerras 29214cf11afSPaul Mackerras/* 29314cf11afSPaul Mackerras * Here is our main kernel entry point. We support currently 2 kind of entries 29414cf11afSPaul Mackerras * depending on the value of r5. 29514cf11afSPaul Mackerras * 29614cf11afSPaul Mackerras * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content 29714cf11afSPaul Mackerras * in r3...r7 29814cf11afSPaul Mackerras * 29914cf11afSPaul Mackerras * r5 == NULL -> kexec style entry. r3 is a physical pointer to the 30014cf11afSPaul Mackerras * DT block, r4 is a physical pointer to the kernel itself 30114cf11afSPaul Mackerras * 30214cf11afSPaul Mackerras */ 30314cf11afSPaul Mackerras_GLOBAL(__start_initialization_multiplatform) 304e31aa453SPaul Mackerras /* Make sure we are running in 64 bits mode */ 305e31aa453SPaul Mackerras bl .enable_64b_mode 306e31aa453SPaul Mackerras 307e31aa453SPaul Mackerras /* Get TOC pointer (current runtime address) */ 308e31aa453SPaul Mackerras bl .relative_toc 309e31aa453SPaul Mackerras 310e31aa453SPaul Mackerras /* find out where we are now */ 311e31aa453SPaul Mackerras bcl 20,31,$+4 312e31aa453SPaul Mackerras0: mflr r26 /* r26 = runtime addr here */ 313e31aa453SPaul Mackerras addis r26,r26,(_stext - 0b)@ha 314e31aa453SPaul Mackerras addi r26,r26,(_stext - 0b)@l /* current runtime base addr */ 315e31aa453SPaul Mackerras 31614cf11afSPaul Mackerras /* 31714cf11afSPaul Mackerras * Are we booted from a PROM Of-type client-interface ? 31814cf11afSPaul Mackerras */ 31914cf11afSPaul Mackerras cmpldi cr0,r5,0 320939e60f6SStephen Rothwell beq 1f 321939e60f6SStephen Rothwell b .__boot_from_prom /* yes -> prom */ 322939e60f6SStephen Rothwell1: 32314cf11afSPaul Mackerras /* Save parameters */ 32414cf11afSPaul Mackerras mr r31,r3 32514cf11afSPaul Mackerras mr r30,r4 326daea1175SBenjamin Herrenschmidt#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL 327daea1175SBenjamin Herrenschmidt /* Save OPAL entry */ 328daea1175SBenjamin Herrenschmidt mr r28,r8 329daea1175SBenjamin Herrenschmidt mr r29,r9 330daea1175SBenjamin Herrenschmidt#endif 33114cf11afSPaul Mackerras 3322d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 3332d27cfd3SBenjamin Herrenschmidt bl .start_initialization_book3e 3342d27cfd3SBenjamin Herrenschmidt b .__after_prom_start 3352d27cfd3SBenjamin Herrenschmidt#else 33614cf11afSPaul Mackerras /* Setup some critical 970 SPRs before switching MMU off */ 337f39b7a55SOlof Johansson mfspr r0,SPRN_PVR 338f39b7a55SOlof Johansson srwi r0,r0,16 339f39b7a55SOlof Johansson cmpwi r0,0x39 /* 970 */ 340f39b7a55SOlof Johansson beq 1f 341f39b7a55SOlof Johansson cmpwi r0,0x3c /* 970FX */ 342f39b7a55SOlof Johansson beq 1f 343f39b7a55SOlof Johansson cmpwi r0,0x44 /* 970MP */ 344190a24f5SOlof Johansson beq 1f 345190a24f5SOlof Johansson cmpwi r0,0x45 /* 970GX */ 346f39b7a55SOlof Johansson bne 2f 347f39b7a55SOlof Johansson1: bl .__cpu_preinit_ppc970 348f39b7a55SOlof Johansson2: 34914cf11afSPaul Mackerras 350e31aa453SPaul Mackerras /* Switch off MMU if not already off */ 35114cf11afSPaul Mackerras bl .__mmu_off 35214cf11afSPaul Mackerras b .__after_prom_start 3532d27cfd3SBenjamin Herrenschmidt#endif /* CONFIG_PPC_BOOK3E */ 35414cf11afSPaul Mackerras 355939e60f6SStephen Rothwell_INIT_STATIC(__boot_from_prom) 35628794d34SBenjamin Herrenschmidt#ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE 35714cf11afSPaul Mackerras /* Save parameters */ 35814cf11afSPaul Mackerras mr r31,r3 35914cf11afSPaul Mackerras mr r30,r4 36014cf11afSPaul Mackerras mr r29,r5 36114cf11afSPaul Mackerras mr r28,r6 36214cf11afSPaul Mackerras mr r27,r7 36314cf11afSPaul Mackerras 3646088857bSOlaf Hering /* 3656088857bSOlaf Hering * Align the stack to 16-byte boundary 3666088857bSOlaf Hering * Depending on the size and layout of the ELF sections in the initial 367e31aa453SPaul Mackerras * boot binary, the stack pointer may be unaligned on PowerMac 3686088857bSOlaf Hering */ 369c05b4770SLinus Torvalds rldicr r1,r1,0,59 370c05b4770SLinus Torvalds 371549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 372549e8152SPaul Mackerras /* Relocate code for where we are now */ 373549e8152SPaul Mackerras mr r3,r26 374549e8152SPaul Mackerras bl .relocate 375549e8152SPaul Mackerras#endif 376549e8152SPaul Mackerras 37714cf11afSPaul Mackerras /* Restore parameters */ 37814cf11afSPaul Mackerras mr r3,r31 37914cf11afSPaul Mackerras mr r4,r30 38014cf11afSPaul Mackerras mr r5,r29 38114cf11afSPaul Mackerras mr r6,r28 38214cf11afSPaul Mackerras mr r7,r27 38314cf11afSPaul Mackerras 38414cf11afSPaul Mackerras /* Do all of the interaction with OF client interface */ 385549e8152SPaul Mackerras mr r8,r26 38614cf11afSPaul Mackerras bl .prom_init 38728794d34SBenjamin Herrenschmidt#endif /* #CONFIG_PPC_OF_BOOT_TRAMPOLINE */ 38828794d34SBenjamin Herrenschmidt 38928794d34SBenjamin Herrenschmidt /* We never return. We also hit that trap if trying to boot 39028794d34SBenjamin Herrenschmidt * from OF while CONFIG_PPC_OF_BOOT_TRAMPOLINE isn't selected */ 39114cf11afSPaul Mackerras trap 39214cf11afSPaul Mackerras 39314cf11afSPaul Mackerras_STATIC(__after_prom_start) 394549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 395549e8152SPaul Mackerras /* process relocations for the final address of the kernel */ 396549e8152SPaul Mackerras lis r25,PAGE_OFFSET@highest /* compute virtual base of kernel */ 397549e8152SPaul Mackerras sldi r25,r25,32 3988b8b0cc1SMilton Miller lwz r7,__run_at_load-_stext(r26) 399928a3197SSonny Rao cmplwi cr0,r7,1 /* flagged to stay where we are ? */ 40054622f10SMohan Kumar M bne 1f 40154622f10SMohan Kumar M add r25,r25,r26 40254622f10SMohan Kumar M1: mr r3,r25 403549e8152SPaul Mackerras bl .relocate 404549e8152SPaul Mackerras#endif 40514cf11afSPaul Mackerras 40614cf11afSPaul Mackerras/* 407e31aa453SPaul Mackerras * We need to run with _stext at physical address PHYSICAL_START. 40814cf11afSPaul Mackerras * This will leave some code in the first 256B of 40914cf11afSPaul Mackerras * real memory, which are reserved for software use. 41014cf11afSPaul Mackerras * 41114cf11afSPaul Mackerras * Note: This process overwrites the OF exception vectors. 41214cf11afSPaul Mackerras */ 413549e8152SPaul Mackerras li r3,0 /* target addr */ 4142d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 4152d27cfd3SBenjamin Herrenschmidt tovirt(r3,r3) /* on booke, we already run at PAGE_OFFSET */ 4162d27cfd3SBenjamin Herrenschmidt#endif 417549e8152SPaul Mackerras mr. r4,r26 /* In some cases the loader may */ 418e31aa453SPaul Mackerras beq 9f /* have already put us at zero */ 41914cf11afSPaul Mackerras li r6,0x100 /* Start offset, the first 0x100 */ 42014cf11afSPaul Mackerras /* bytes were copied earlier. */ 4212d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 4222d27cfd3SBenjamin Herrenschmidt tovirt(r6,r6) /* on booke, we already run at PAGE_OFFSET */ 4232d27cfd3SBenjamin Herrenschmidt#endif 42414cf11afSPaul Mackerras 42554622f10SMohan Kumar M#ifdef CONFIG_CRASH_DUMP 42654622f10SMohan Kumar M/* 42754622f10SMohan Kumar M * Check if the kernel has to be running as relocatable kernel based on the 4288b8b0cc1SMilton Miller * variable __run_at_load, if it is set the kernel is treated as relocatable 42954622f10SMohan Kumar M * kernel, otherwise it will be moved to PHYSICAL_START 43054622f10SMohan Kumar M */ 4318b8b0cc1SMilton Miller lwz r7,__run_at_load-_stext(r26) 4328b8b0cc1SMilton Miller cmplwi cr0,r7,1 43354622f10SMohan Kumar M bne 3f 43454622f10SMohan Kumar M 43554622f10SMohan Kumar M li r5,__end_interrupts - _stext /* just copy interrupts */ 43654622f10SMohan Kumar M b 5f 43754622f10SMohan Kumar M3: 43854622f10SMohan Kumar M#endif 43954622f10SMohan Kumar M lis r5,(copy_to_here - _stext)@ha 44054622f10SMohan Kumar M addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */ 44154622f10SMohan Kumar M 44214cf11afSPaul Mackerras bl .copy_and_flush /* copy the first n bytes */ 44314cf11afSPaul Mackerras /* this includes the code being */ 44414cf11afSPaul Mackerras /* executed here. */ 445e31aa453SPaul Mackerras addis r8,r3,(4f - _stext)@ha /* Jump to the copy of this code */ 446e31aa453SPaul Mackerras addi r8,r8,(4f - _stext)@l /* that we just made */ 447e31aa453SPaul Mackerras mtctr r8 44814cf11afSPaul Mackerras bctr 44914cf11afSPaul Mackerras 45054622f10SMohan Kumar Mp_end: .llong _end - _stext 45154622f10SMohan Kumar M 452e31aa453SPaul Mackerras4: /* Now copy the rest of the kernel up to _end */ 453e31aa453SPaul Mackerras addis r5,r26,(p_end - _stext)@ha 454e31aa453SPaul Mackerras ld r5,(p_end - _stext)@l(r5) /* get _end */ 45554622f10SMohan Kumar M5: bl .copy_and_flush /* copy the rest */ 456e31aa453SPaul Mackerras 457e31aa453SPaul Mackerras9: b .start_here_multiplatform 458e31aa453SPaul Mackerras 45914cf11afSPaul Mackerras/* 46014cf11afSPaul Mackerras * Copy routine used to copy the kernel to start at physical address 0 46114cf11afSPaul Mackerras * and flush and invalidate the caches as needed. 46214cf11afSPaul Mackerras * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset 46314cf11afSPaul Mackerras * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5. 46414cf11afSPaul Mackerras * 46514cf11afSPaul Mackerras * Note: this routine *only* clobbers r0, r6 and lr 46614cf11afSPaul Mackerras */ 46714cf11afSPaul Mackerras_GLOBAL(copy_and_flush) 46814cf11afSPaul Mackerras addi r5,r5,-8 46914cf11afSPaul Mackerras addi r6,r6,-8 4705a2fe38dSOlof Johansson4: li r0,8 /* Use the smallest common */ 47114cf11afSPaul Mackerras /* denominator cache line */ 47214cf11afSPaul Mackerras /* size. This results in */ 47314cf11afSPaul Mackerras /* extra cache line flushes */ 47414cf11afSPaul Mackerras /* but operation is correct. */ 47514cf11afSPaul Mackerras /* Can't get cache line size */ 47614cf11afSPaul Mackerras /* from NACA as it is being */ 47714cf11afSPaul Mackerras /* moved too. */ 47814cf11afSPaul Mackerras 47914cf11afSPaul Mackerras mtctr r0 /* put # words/line in ctr */ 48014cf11afSPaul Mackerras3: addi r6,r6,8 /* copy a cache line */ 48114cf11afSPaul Mackerras ldx r0,r6,r4 48214cf11afSPaul Mackerras stdx r0,r6,r3 48314cf11afSPaul Mackerras bdnz 3b 48414cf11afSPaul Mackerras dcbst r6,r3 /* write it to memory */ 48514cf11afSPaul Mackerras sync 48614cf11afSPaul Mackerras icbi r6,r3 /* flush the icache line */ 48714cf11afSPaul Mackerras cmpld 0,r6,r5 48814cf11afSPaul Mackerras blt 4b 48914cf11afSPaul Mackerras sync 49014cf11afSPaul Mackerras addi r5,r5,8 49114cf11afSPaul Mackerras addi r6,r6,8 49214cf11afSPaul Mackerras blr 49314cf11afSPaul Mackerras 49414cf11afSPaul Mackerras.align 8 49514cf11afSPaul Mackerrascopy_to_here: 49614cf11afSPaul Mackerras 49714cf11afSPaul Mackerras#ifdef CONFIG_SMP 49814cf11afSPaul Mackerras#ifdef CONFIG_PPC_PMAC 49914cf11afSPaul Mackerras/* 50014cf11afSPaul Mackerras * On PowerMac, secondary processors starts from the reset vector, which 50114cf11afSPaul Mackerras * is temporarily turned into a call to one of the functions below. 50214cf11afSPaul Mackerras */ 50314cf11afSPaul Mackerras .section ".text"; 50414cf11afSPaul Mackerras .align 2 ; 50514cf11afSPaul Mackerras 50635499c01SPaul Mackerras .globl __secondary_start_pmac_0 50735499c01SPaul Mackerras__secondary_start_pmac_0: 50835499c01SPaul Mackerras /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */ 50935499c01SPaul Mackerras li r24,0 51035499c01SPaul Mackerras b 1f 51114cf11afSPaul Mackerras li r24,1 51235499c01SPaul Mackerras b 1f 51314cf11afSPaul Mackerras li r24,2 51435499c01SPaul Mackerras b 1f 51514cf11afSPaul Mackerras li r24,3 51635499c01SPaul Mackerras1: 51714cf11afSPaul Mackerras 51814cf11afSPaul Mackerras_GLOBAL(pmac_secondary_start) 51914cf11afSPaul Mackerras /* turn on 64-bit mode */ 52014cf11afSPaul Mackerras bl .enable_64b_mode 52114cf11afSPaul Mackerras 522c478b581SBenjamin Herrenschmidt li r0,0 523c478b581SBenjamin Herrenschmidt mfspr r3,SPRN_HID4 524c478b581SBenjamin Herrenschmidt rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */ 525c478b581SBenjamin Herrenschmidt sync 526c478b581SBenjamin Herrenschmidt mtspr SPRN_HID4,r3 527c478b581SBenjamin Herrenschmidt isync 528c478b581SBenjamin Herrenschmidt sync 529c478b581SBenjamin Herrenschmidt slbia 530c478b581SBenjamin Herrenschmidt 531e31aa453SPaul Mackerras /* get TOC pointer (real address) */ 532e31aa453SPaul Mackerras bl .relative_toc 533e31aa453SPaul Mackerras 53414cf11afSPaul Mackerras /* Copy some CPU settings from CPU 0 */ 535f39b7a55SOlof Johansson bl .__restore_cpu_ppc970 53614cf11afSPaul Mackerras 53714cf11afSPaul Mackerras /* pSeries do that early though I don't think we really need it */ 53814cf11afSPaul Mackerras mfmsr r3 53914cf11afSPaul Mackerras ori r3,r3,MSR_RI 54014cf11afSPaul Mackerras mtmsrd r3 /* RI on */ 54114cf11afSPaul Mackerras 54214cf11afSPaul Mackerras /* Set up a paca value for this processor. */ 5431426d5a3SMichael Ellerman LOAD_REG_ADDR(r4,paca) /* Load paca pointer */ 5441426d5a3SMichael Ellerman ld r4,0(r4) /* Get base vaddr of paca array */ 54514cf11afSPaul Mackerras mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */ 54614cf11afSPaul Mackerras add r13,r13,r4 /* for this processor. */ 5472dd60d79SBenjamin Herrenschmidt SET_PACA(r13) /* Save vaddr of paca in an SPRG*/ 54814cf11afSPaul Mackerras 54962cc67b9SBenjamin Herrenschmidt /* Mark interrupts soft and hard disabled (they might be enabled 55062cc67b9SBenjamin Herrenschmidt * in the PACA when doing hotplug) 55162cc67b9SBenjamin Herrenschmidt */ 55262cc67b9SBenjamin Herrenschmidt li r0,0 55362cc67b9SBenjamin Herrenschmidt stb r0,PACASOFTIRQEN(r13) 554*7230c564SBenjamin Herrenschmidt li r0,PACA_IRQ_HARD_DIS 555*7230c564SBenjamin Herrenschmidt stb r0,PACAIRQHAPPENED(r13) 55662cc67b9SBenjamin Herrenschmidt 55714cf11afSPaul Mackerras /* Create a temp kernel stack for use before relocation is on. */ 55814cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 55914cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 56014cf11afSPaul Mackerras 561c705677eSStephen Rothwell b __secondary_start 56214cf11afSPaul Mackerras 56314cf11afSPaul Mackerras#endif /* CONFIG_PPC_PMAC */ 56414cf11afSPaul Mackerras 56514cf11afSPaul Mackerras/* 56614cf11afSPaul Mackerras * This function is called after the master CPU has released the 56714cf11afSPaul Mackerras * secondary processors. The execution environment is relocation off. 56814cf11afSPaul Mackerras * The paca for this processor has the following fields initialized at 56914cf11afSPaul Mackerras * this point: 57014cf11afSPaul Mackerras * 1. Processor number 57114cf11afSPaul Mackerras * 2. Segment table pointer (virtual address) 57214cf11afSPaul Mackerras * On entry the following are set: 5734f8cf36fSBenjamin Herrenschmidt * r1 = stack pointer (real addr of temp stack) 57414cf11afSPaul Mackerras * r24 = cpu# (in Linux terms) 57514cf11afSPaul Mackerras * r13 = paca virtual address 576ee43eb78SBenjamin Herrenschmidt * SPRG_PACA = paca virtual address 57714cf11afSPaul Mackerras */ 5782d27cfd3SBenjamin Herrenschmidt .section ".text"; 5792d27cfd3SBenjamin Herrenschmidt .align 2 ; 5802d27cfd3SBenjamin Herrenschmidt 581fc68e869SStephen Rothwell .globl __secondary_start 582c705677eSStephen Rothwell__secondary_start: 583799d6046SPaul Mackerras /* Set thread priority to MEDIUM */ 584799d6046SPaul Mackerras HMT_MEDIUM 58514cf11afSPaul Mackerras 5864f8cf36fSBenjamin Herrenschmidt /* Initialize the kernel stack */ 587e58c3495SDavid Gibson LOAD_REG_ADDR(r3, current_set) 58814cf11afSPaul Mackerras sldi r28,r24,3 /* get current_set[cpu#] */ 58954a83404SMichael Neuling ldx r14,r3,r28 59054a83404SMichael Neuling addi r14,r14,THREAD_SIZE-STACK_FRAME_OVERHEAD 59154a83404SMichael Neuling std r14,PACAKSAVE(r13) 59214cf11afSPaul Mackerras 593f761622eSMatt Evans /* Do early setup for that CPU (stab, slb, hash table pointer) */ 594f761622eSMatt Evans bl .early_setup_secondary 595f761622eSMatt Evans 59654a83404SMichael Neuling /* 59754a83404SMichael Neuling * setup the new stack pointer, but *don't* use this until 59854a83404SMichael Neuling * translation is on. 59954a83404SMichael Neuling */ 60054a83404SMichael Neuling mr r1, r14 60154a83404SMichael Neuling 602799d6046SPaul Mackerras /* Clear backchain so we get nice backtraces */ 60314cf11afSPaul Mackerras li r7,0 60414cf11afSPaul Mackerras mtlr r7 60514cf11afSPaul Mackerras 606*7230c564SBenjamin Herrenschmidt /* Mark interrupts soft and hard disabled (they might be enabled 607*7230c564SBenjamin Herrenschmidt * in the PACA when doing hotplug) 608*7230c564SBenjamin Herrenschmidt */ 6094f8cf36fSBenjamin Herrenschmidt stb r7,PACASOFTIRQEN(r13) 610*7230c564SBenjamin Herrenschmidt li r0,PACA_IRQ_HARD_DIS 611*7230c564SBenjamin Herrenschmidt stb r0,PACAIRQHAPPENED(r13) 6124f8cf36fSBenjamin Herrenschmidt 61314cf11afSPaul Mackerras /* enable MMU and jump to start_secondary */ 614e58c3495SDavid Gibson LOAD_REG_ADDR(r3, .start_secondary_prolog) 615e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4, MSR_KERNEL) 616d04c56f7SPaul Mackerras 617b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r3 618b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r4 6192d27cfd3SBenjamin Herrenschmidt RFI 62014cf11afSPaul Mackerras b . /* prevent speculative execution */ 62114cf11afSPaul Mackerras 62214cf11afSPaul Mackerras/* 62314cf11afSPaul Mackerras * Running with relocation on at this point. All we want to do is 624e31aa453SPaul Mackerras * zero the stack back-chain pointer and get the TOC virtual address 625e31aa453SPaul Mackerras * before going into C code. 62614cf11afSPaul Mackerras */ 62714cf11afSPaul Mackerras_GLOBAL(start_secondary_prolog) 628e31aa453SPaul Mackerras ld r2,PACATOC(r13) 62914cf11afSPaul Mackerras li r3,0 63014cf11afSPaul Mackerras std r3,0(r1) /* Zero the stack frame pointer */ 63114cf11afSPaul Mackerras bl .start_secondary 632799d6046SPaul Mackerras b . 6338dbce53cSVaidyanathan Srinivasan/* 6348dbce53cSVaidyanathan Srinivasan * Reset stack pointer and call start_secondary 6358dbce53cSVaidyanathan Srinivasan * to continue with online operation when woken up 6368dbce53cSVaidyanathan Srinivasan * from cede in cpu offline. 6378dbce53cSVaidyanathan Srinivasan */ 6388dbce53cSVaidyanathan Srinivasan_GLOBAL(start_secondary_resume) 6398dbce53cSVaidyanathan Srinivasan ld r1,PACAKSAVE(r13) /* Reload kernel stack pointer */ 6408dbce53cSVaidyanathan Srinivasan li r3,0 6418dbce53cSVaidyanathan Srinivasan std r3,0(r1) /* Zero the stack frame pointer */ 6428dbce53cSVaidyanathan Srinivasan bl .start_secondary 6438dbce53cSVaidyanathan Srinivasan b . 64414cf11afSPaul Mackerras#endif 64514cf11afSPaul Mackerras 64614cf11afSPaul Mackerras/* 64714cf11afSPaul Mackerras * This subroutine clobbers r11 and r12 64814cf11afSPaul Mackerras */ 64914cf11afSPaul Mackerras_GLOBAL(enable_64b_mode) 65014cf11afSPaul Mackerras mfmsr r11 /* grab the current MSR */ 6512d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 6522d27cfd3SBenjamin Herrenschmidt oris r11,r11,0x8000 /* CM bit set, we'll set ICM later */ 6532d27cfd3SBenjamin Herrenschmidt mtmsr r11 6542d27cfd3SBenjamin Herrenschmidt#else /* CONFIG_PPC_BOOK3E */ 6559f0b0793SMichael Ellerman li r12,(MSR_64BIT | MSR_ISF)@highest 656e31aa453SPaul Mackerras sldi r12,r12,48 65714cf11afSPaul Mackerras or r11,r11,r12 65814cf11afSPaul Mackerras mtmsrd r11 65914cf11afSPaul Mackerras isync 6602d27cfd3SBenjamin Herrenschmidt#endif 66114cf11afSPaul Mackerras blr 66214cf11afSPaul Mackerras 66314cf11afSPaul Mackerras/* 664e31aa453SPaul Mackerras * This puts the TOC pointer into r2, offset by 0x8000 (as expected 665e31aa453SPaul Mackerras * by the toolchain). It computes the correct value for wherever we 666e31aa453SPaul Mackerras * are running at the moment, using position-independent code. 667e31aa453SPaul Mackerras */ 668e31aa453SPaul Mackerras_GLOBAL(relative_toc) 669e31aa453SPaul Mackerras mflr r0 670e31aa453SPaul Mackerras bcl 20,31,$+4 671e550592eSBenjamin Herrenschmidt0: mflr r11 672e550592eSBenjamin Herrenschmidt ld r2,(p_toc - 0b)(r11) 673e550592eSBenjamin Herrenschmidt add r2,r2,r11 674e31aa453SPaul Mackerras mtlr r0 675e31aa453SPaul Mackerras blr 676e31aa453SPaul Mackerras 677e31aa453SPaul Mackerrasp_toc: .llong __toc_start + 0x8000 - 0b 678e31aa453SPaul Mackerras 679e31aa453SPaul Mackerras/* 68014cf11afSPaul Mackerras * This is where the main kernel code starts. 68114cf11afSPaul Mackerras */ 682939e60f6SStephen Rothwell_INIT_STATIC(start_here_multiplatform) 683e31aa453SPaul Mackerras /* set up the TOC (real address) */ 684e31aa453SPaul Mackerras bl .relative_toc 68514cf11afSPaul Mackerras 68614cf11afSPaul Mackerras /* Clear out the BSS. It may have been done in prom_init, 68714cf11afSPaul Mackerras * already but that's irrelevant since prom_init will soon 68814cf11afSPaul Mackerras * be detached from the kernel completely. Besides, we need 68914cf11afSPaul Mackerras * to clear it now for kexec-style entry. 69014cf11afSPaul Mackerras */ 691e31aa453SPaul Mackerras LOAD_REG_ADDR(r11,__bss_stop) 692e31aa453SPaul Mackerras LOAD_REG_ADDR(r8,__bss_start) 69314cf11afSPaul Mackerras sub r11,r11,r8 /* bss size */ 69414cf11afSPaul Mackerras addi r11,r11,7 /* round up to an even double word */ 695e31aa453SPaul Mackerras srdi. r11,r11,3 /* shift right by 3 */ 69614cf11afSPaul Mackerras beq 4f 69714cf11afSPaul Mackerras addi r8,r8,-8 69814cf11afSPaul Mackerras li r0,0 69914cf11afSPaul Mackerras mtctr r11 /* zero this many doublewords */ 70014cf11afSPaul Mackerras3: stdu r0,8(r8) 70114cf11afSPaul Mackerras bdnz 3b 70214cf11afSPaul Mackerras4: 70314cf11afSPaul Mackerras 704daea1175SBenjamin Herrenschmidt#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL 705daea1175SBenjamin Herrenschmidt /* Setup OPAL entry */ 706daea1175SBenjamin Herrenschmidt std r28,0(r11); 707daea1175SBenjamin Herrenschmidt std r29,8(r11); 708daea1175SBenjamin Herrenschmidt#endif 709daea1175SBenjamin Herrenschmidt 7102d27cfd3SBenjamin Herrenschmidt#ifndef CONFIG_PPC_BOOK3E 71114cf11afSPaul Mackerras mfmsr r6 71214cf11afSPaul Mackerras ori r6,r6,MSR_RI 71314cf11afSPaul Mackerras mtmsrd r6 /* RI on */ 7142d27cfd3SBenjamin Herrenschmidt#endif 71514cf11afSPaul Mackerras 716549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 717549e8152SPaul Mackerras /* Save the physical address we're running at in kernstart_addr */ 718549e8152SPaul Mackerras LOAD_REG_ADDR(r4, kernstart_addr) 719549e8152SPaul Mackerras clrldi r0,r25,2 720549e8152SPaul Mackerras std r0,0(r4) 721549e8152SPaul Mackerras#endif 722549e8152SPaul Mackerras 723e31aa453SPaul Mackerras /* The following gets the stack set up with the regs */ 72414cf11afSPaul Mackerras /* pointing to the real addr of the kernel stack. This is */ 72514cf11afSPaul Mackerras /* all done to support the C function call below which sets */ 72614cf11afSPaul Mackerras /* up the htab. This is done because we have relocated the */ 72714cf11afSPaul Mackerras /* kernel but are still running in real mode. */ 72814cf11afSPaul Mackerras 729e31aa453SPaul Mackerras LOAD_REG_ADDR(r3,init_thread_union) 73014cf11afSPaul Mackerras 731e31aa453SPaul Mackerras /* set up a stack pointer */ 73214cf11afSPaul Mackerras addi r1,r3,THREAD_SIZE 73314cf11afSPaul Mackerras li r0,0 73414cf11afSPaul Mackerras stdu r0,-STACK_FRAME_OVERHEAD(r1) 73514cf11afSPaul Mackerras 73614cf11afSPaul Mackerras /* Do very early kernel initializations, including initial hash table, 73714cf11afSPaul Mackerras * stab and slb setup before we turn on relocation. */ 73814cf11afSPaul Mackerras 73914cf11afSPaul Mackerras /* Restore parameters passed from prom_init/kexec */ 74014cf11afSPaul Mackerras mr r3,r31 741ee43eb78SBenjamin Herrenschmidt bl .early_setup /* also sets r13 and SPRG_PACA */ 74214cf11afSPaul Mackerras 743e31aa453SPaul Mackerras LOAD_REG_ADDR(r3, .start_here_common) 744e31aa453SPaul Mackerras ld r4,PACAKMSR(r13) 745b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r3 746b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r4 7472d27cfd3SBenjamin Herrenschmidt RFI 74814cf11afSPaul Mackerras b . /* prevent speculative execution */ 74914cf11afSPaul Mackerras 75014cf11afSPaul Mackerras /* This is where all platforms converge execution */ 751fc68e869SStephen Rothwell_INIT_GLOBAL(start_here_common) 75214cf11afSPaul Mackerras /* relocation is on at this point */ 75314cf11afSPaul Mackerras std r1,PACAKSAVE(r13) 75414cf11afSPaul Mackerras 755e31aa453SPaul Mackerras /* Load the TOC (virtual address) */ 756e31aa453SPaul Mackerras ld r2,PACATOC(r13) 757e31aa453SPaul Mackerras 758*7230c564SBenjamin Herrenschmidt /* Do more system initializations in virtual mode */ 75914cf11afSPaul Mackerras bl .setup_system 76014cf11afSPaul Mackerras 761*7230c564SBenjamin Herrenschmidt /* Mark interrupts soft and hard disabled (they might be enabled 762*7230c564SBenjamin Herrenschmidt * in the PACA when doing hotplug) 763*7230c564SBenjamin Herrenschmidt */ 764*7230c564SBenjamin Herrenschmidt li r0,0 765*7230c564SBenjamin Herrenschmidt stb r0,PACASOFTIRQEN(r13) 766*7230c564SBenjamin Herrenschmidt li r0,PACA_IRQ_HARD_DIS 767*7230c564SBenjamin Herrenschmidt stb r0,PACAIRQHAPPENED(r13) 76814cf11afSPaul Mackerras 769*7230c564SBenjamin Herrenschmidt /* Generic kernel entry */ 77014cf11afSPaul Mackerras bl .start_kernel 77114cf11afSPaul Mackerras 772f1870f77SAnton Blanchard /* Not reached */ 773f1870f77SAnton Blanchard BUG_OPCODE 77414cf11afSPaul Mackerras 77514cf11afSPaul Mackerras/* 77614cf11afSPaul Mackerras * We put a few things here that have to be page-aligned. 77714cf11afSPaul Mackerras * This stuff goes at the beginning of the bss, which is page-aligned. 77814cf11afSPaul Mackerras */ 77914cf11afSPaul Mackerras .section ".bss" 78014cf11afSPaul Mackerras 78114cf11afSPaul Mackerras .align PAGE_SHIFT 78214cf11afSPaul Mackerras 78314cf11afSPaul Mackerras .globl empty_zero_page 78414cf11afSPaul Mackerrasempty_zero_page: 78514cf11afSPaul Mackerras .space PAGE_SIZE 78614cf11afSPaul Mackerras 78714cf11afSPaul Mackerras .globl swapper_pg_dir 78814cf11afSPaul Mackerrasswapper_pg_dir: 789ee7a76daSStephen Rothwell .space PGD_TABLE_SIZE 790