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> 35c43a55ffSKelly Daly#include <asm/iseries/lpar_map.h> 366cb7bfebSDavid Gibson#include <asm/thread_info.h> 373f639ee8SStephen Rothwell#include <asm/firmware.h> 3816a15a30SStephen Rothwell#include <asm/page_64.h> 39945feb17SBenjamin Herrenschmidt#include <asm/irqflags.h> 4014cf11afSPaul Mackerras 410ebc4cdaSBenjamin Herrenschmidt/* The physical memory is layed out such that the secondary processor 420ebc4cdaSBenjamin Herrenschmidt * spin code sits at 0x0000...0x00ff. On server, the vectors follow 430ebc4cdaSBenjamin Herrenschmidt * using the layout described in exceptions-64s.S 4414cf11afSPaul Mackerras */ 4514cf11afSPaul Mackerras 4614cf11afSPaul Mackerras/* 4714cf11afSPaul Mackerras * Entering into this code we make the following assumptions: 480ebc4cdaSBenjamin Herrenschmidt * 490ebc4cdaSBenjamin Herrenschmidt * For pSeries or server processors: 5014cf11afSPaul Mackerras * 1. The MMU is off & open firmware is running in real mode. 5114cf11afSPaul Mackerras * 2. The kernel is entered at __start 5214cf11afSPaul Mackerras * 5314cf11afSPaul Mackerras * For iSeries: 5414cf11afSPaul Mackerras * 1. The MMU is on (as it always is for iSeries) 5514cf11afSPaul Mackerras * 2. The kernel is entered at system_reset_iSeries 560ebc4cdaSBenjamin Herrenschmidt * 570ebc4cdaSBenjamin Herrenschmidt * For Book3E processors: 580ebc4cdaSBenjamin Herrenschmidt * 1. The MMU is on running in AS0 in a state defined in ePAPR 590ebc4cdaSBenjamin Herrenschmidt * 2. The kernel is entered at __start 6014cf11afSPaul Mackerras */ 6114cf11afSPaul Mackerras 6214cf11afSPaul Mackerras .text 6314cf11afSPaul Mackerras .globl _stext 6414cf11afSPaul Mackerras_stext: 6514cf11afSPaul Mackerras_GLOBAL(__start) 6614cf11afSPaul Mackerras /* NOP this out unconditionally */ 6714cf11afSPaul MackerrasBEGIN_FTR_SECTION 6814cf11afSPaul Mackerras b .__start_initialization_multiplatform 6914cf11afSPaul MackerrasEND_FTR_SECTION(0, 1) 7014cf11afSPaul Mackerras 7114cf11afSPaul Mackerras /* Catch branch to 0 in real mode */ 7214cf11afSPaul Mackerras trap 7314cf11afSPaul Mackerras 741f6a93e4SPaul Mackerras /* Secondary processors spin on this value until it becomes nonzero. 751f6a93e4SPaul Mackerras * When it does it contains the real address of the descriptor 761f6a93e4SPaul Mackerras * of the function that the cpu should jump to to continue 771f6a93e4SPaul Mackerras * initialization. 781f6a93e4SPaul Mackerras */ 7914cf11afSPaul Mackerras .globl __secondary_hold_spinloop 8014cf11afSPaul Mackerras__secondary_hold_spinloop: 8114cf11afSPaul Mackerras .llong 0x0 8214cf11afSPaul Mackerras 8314cf11afSPaul Mackerras /* Secondary processors write this value with their cpu # */ 8414cf11afSPaul Mackerras /* after they enter the spin loop immediately below. */ 8514cf11afSPaul Mackerras .globl __secondary_hold_acknowledge 8614cf11afSPaul Mackerras__secondary_hold_acknowledge: 8714cf11afSPaul Mackerras .llong 0x0 8814cf11afSPaul Mackerras 891dce0e30SMichael Ellerman#ifdef CONFIG_PPC_ISERIES 901dce0e30SMichael Ellerman /* 911dce0e30SMichael Ellerman * At offset 0x20, there is a pointer to iSeries LPAR data. 921dce0e30SMichael Ellerman * This is required by the hypervisor 931dce0e30SMichael Ellerman */ 941dce0e30SMichael Ellerman . = 0x20 951dce0e30SMichael Ellerman .llong hvReleaseData-KERNELBASE 961dce0e30SMichael Ellerman#endif /* CONFIG_PPC_ISERIES */ 971dce0e30SMichael Ellerman 988b8b0cc1SMilton Miller#ifdef CONFIG_CRASH_DUMP 998b8b0cc1SMilton Miller /* This flag is set to 1 by a loader if the kernel should run 1008b8b0cc1SMilton Miller * at the loaded address instead of the linked address. This 1018b8b0cc1SMilton Miller * is used by kexec-tools to keep the the kdump kernel in the 1028b8b0cc1SMilton Miller * crash_kernel region. The loader is responsible for 1038b8b0cc1SMilton Miller * observing the alignment requirement. 1048b8b0cc1SMilton Miller */ 1058b8b0cc1SMilton Miller /* Do not move this variable as kexec-tools knows about it. */ 1068b8b0cc1SMilton Miller . = 0x5c 1078b8b0cc1SMilton Miller .globl __run_at_load 1088b8b0cc1SMilton Miller__run_at_load: 1098b8b0cc1SMilton Miller .long 0x72756e30 /* "run0" -- relocate to 0 by default */ 1108b8b0cc1SMilton Miller#endif 1118b8b0cc1SMilton Miller 11214cf11afSPaul Mackerras . = 0x60 11314cf11afSPaul Mackerras/* 11475423b7bSGeoff Levand * The following code is used to hold secondary processors 11575423b7bSGeoff Levand * in a spin loop after they have entered the kernel, but 11614cf11afSPaul Mackerras * before the bulk of the kernel has been relocated. This code 11714cf11afSPaul Mackerras * is relocated to physical address 0x60 before prom_init is run. 11814cf11afSPaul Mackerras * All of it must fit below the first exception vector at 0x100. 1191f6a93e4SPaul Mackerras * Use .globl here not _GLOBAL because we want __secondary_hold 1201f6a93e4SPaul Mackerras * to be the actual text address, not a descriptor. 12114cf11afSPaul Mackerras */ 1221f6a93e4SPaul Mackerras .globl __secondary_hold 1231f6a93e4SPaul Mackerras__secondary_hold: 12414cf11afSPaul Mackerras mfmsr r24 12514cf11afSPaul Mackerras ori r24,r24,MSR_RI 12614cf11afSPaul Mackerras mtmsrd r24 /* RI on */ 12714cf11afSPaul Mackerras 128f1870f77SAnton Blanchard /* Grab our physical cpu number */ 12914cf11afSPaul Mackerras mr r24,r3 13014cf11afSPaul Mackerras 13114cf11afSPaul Mackerras /* Tell the master cpu we're here */ 13214cf11afSPaul Mackerras /* Relocation is off & we are located at an address less */ 13314cf11afSPaul Mackerras /* than 0x100, so only need to grab low order offset. */ 134e31aa453SPaul Mackerras std r24,__secondary_hold_acknowledge-_stext(0) 13514cf11afSPaul Mackerras sync 13614cf11afSPaul Mackerras 13714cf11afSPaul Mackerras /* All secondary cpus wait here until told to start. */ 138e31aa453SPaul Mackerras100: ld r4,__secondary_hold_spinloop-_stext(0) 1391f6a93e4SPaul Mackerras cmpdi 0,r4,0 1401f6a93e4SPaul Mackerras beq 100b 14114cf11afSPaul Mackerras 142f1870f77SAnton Blanchard#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC) 1431f6a93e4SPaul Mackerras ld r4,0(r4) /* deref function descriptor */ 144758438a7SMichael Ellerman mtctr r4 14514cf11afSPaul Mackerras mr r3,r24 146758438a7SMichael Ellerman bctr 14714cf11afSPaul Mackerras#else 14814cf11afSPaul Mackerras BUG_OPCODE 14914cf11afSPaul Mackerras#endif 15014cf11afSPaul Mackerras 15114cf11afSPaul Mackerras/* This value is used to mark exception frames on the stack. */ 15214cf11afSPaul Mackerras .section ".toc","aw" 15314cf11afSPaul Mackerrasexception_marker: 15414cf11afSPaul Mackerras .tc ID_72656773_68657265[TC],0x7265677368657265 15514cf11afSPaul Mackerras .text 15614cf11afSPaul Mackerras 15714cf11afSPaul Mackerras/* 1580ebc4cdaSBenjamin Herrenschmidt * On server, we include the exception vectors code here as it 1590ebc4cdaSBenjamin Herrenschmidt * relies on absolute addressing which is only possible within 1600ebc4cdaSBenjamin Herrenschmidt * this compilation unit 16114cf11afSPaul Mackerras */ 1620ebc4cdaSBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3S 1630ebc4cdaSBenjamin Herrenschmidt#include "exceptions-64s.S" 1641f6a93e4SPaul Mackerras#endif 16514cf11afSPaul Mackerras 16614cf11afSPaul Mackerras 16714cf11afSPaul Mackerras/* 168f39b7a55SOlof Johansson * On pSeries and most other platforms, secondary processors spin 169f39b7a55SOlof Johansson * in the following code. 17014cf11afSPaul Mackerras * At entry, r3 = this processor's number (physical cpu id) 17114cf11afSPaul Mackerras */ 172f39b7a55SOlof Johansson_GLOBAL(generic_secondary_smp_init) 17314cf11afSPaul Mackerras mr r24,r3 17414cf11afSPaul Mackerras 17514cf11afSPaul Mackerras /* turn on 64-bit mode */ 17614cf11afSPaul Mackerras bl .enable_64b_mode 17714cf11afSPaul Mackerras 178e31aa453SPaul Mackerras /* get the TOC pointer (real address) */ 179e31aa453SPaul Mackerras bl .relative_toc 180e31aa453SPaul Mackerras 18114cf11afSPaul Mackerras /* Set up a paca value for this processor. Since we have the 18214cf11afSPaul Mackerras * physical cpu id in r24, we need to search the pacas to find 18314cf11afSPaul Mackerras * which logical id maps to our physical one. 18414cf11afSPaul Mackerras */ 185e31aa453SPaul Mackerras LOAD_REG_ADDR(r13, paca) /* Get base vaddr of paca array */ 18614cf11afSPaul Mackerras li r5,0 /* logical cpu id */ 18714cf11afSPaul Mackerras1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */ 18814cf11afSPaul Mackerras cmpw r6,r24 /* Compare to our id */ 18914cf11afSPaul Mackerras beq 2f 19014cf11afSPaul Mackerras addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */ 19114cf11afSPaul Mackerras addi r5,r5,1 19214cf11afSPaul Mackerras cmpwi r5,NR_CPUS 19314cf11afSPaul Mackerras blt 1b 19414cf11afSPaul Mackerras 19514cf11afSPaul Mackerras mr r3,r24 /* not found, copy phys to r3 */ 19614cf11afSPaul Mackerras b .kexec_wait /* next kernel might do better */ 19714cf11afSPaul Mackerras 198*ee43eb78SBenjamin Herrenschmidt2: mtspr SPRN_SPRG_PACA,r13 /* Save vaddr of paca in an SPRG */ 19914cf11afSPaul Mackerras /* From now on, r24 is expected to be logical cpuid */ 20014cf11afSPaul Mackerras mr r24,r5 20114cf11afSPaul Mackerras3: HMT_LOW 20214cf11afSPaul Mackerras lbz r23,PACAPROCSTART(r13) /* Test if this processor should */ 20314cf11afSPaul Mackerras /* start. */ 20414cf11afSPaul Mackerras 205f39b7a55SOlof Johansson#ifndef CONFIG_SMP 206f39b7a55SOlof Johansson b 3b /* Never go on non-SMP */ 207f39b7a55SOlof Johansson#else 208f39b7a55SOlof Johansson cmpwi 0,r23,0 209f39b7a55SOlof Johansson beq 3b /* Loop until told to go */ 210f39b7a55SOlof Johansson 211b6f6b98aSSonny Rao sync /* order paca.run and cur_cpu_spec */ 212b6f6b98aSSonny Rao 213f39b7a55SOlof Johansson /* See if we need to call a cpu state restore handler */ 214e31aa453SPaul Mackerras LOAD_REG_ADDR(r23, cur_cpu_spec) 215f39b7a55SOlof Johansson ld r23,0(r23) 216f39b7a55SOlof Johansson ld r23,CPU_SPEC_RESTORE(r23) 217f39b7a55SOlof Johansson cmpdi 0,r23,0 218f39b7a55SOlof Johansson beq 4f 219f39b7a55SOlof Johansson ld r23,0(r23) 220f39b7a55SOlof Johansson mtctr r23 221f39b7a55SOlof Johansson bctrl 222f39b7a55SOlof Johansson 223f39b7a55SOlof Johansson4: /* Create a temp kernel stack for use before relocation is on. */ 22414cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 22514cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 22614cf11afSPaul Mackerras 227c705677eSStephen Rothwell b __secondary_start 22814cf11afSPaul Mackerras#endif 22914cf11afSPaul Mackerras 230e31aa453SPaul Mackerras/* 231e31aa453SPaul Mackerras * Turn the MMU off. 232e31aa453SPaul Mackerras * Assumes we're mapped EA == RA if the MMU is on. 233e31aa453SPaul Mackerras */ 23414cf11afSPaul Mackerras_STATIC(__mmu_off) 23514cf11afSPaul Mackerras mfmsr r3 23614cf11afSPaul Mackerras andi. r0,r3,MSR_IR|MSR_DR 23714cf11afSPaul Mackerras beqlr 238e31aa453SPaul Mackerras mflr r4 23914cf11afSPaul Mackerras andc r3,r3,r0 24014cf11afSPaul Mackerras mtspr SPRN_SRR0,r4 24114cf11afSPaul Mackerras mtspr SPRN_SRR1,r3 24214cf11afSPaul Mackerras sync 24314cf11afSPaul Mackerras rfid 24414cf11afSPaul Mackerras b . /* prevent speculative execution */ 24514cf11afSPaul Mackerras 24614cf11afSPaul Mackerras 24714cf11afSPaul Mackerras/* 24814cf11afSPaul Mackerras * Here is our main kernel entry point. We support currently 2 kind of entries 24914cf11afSPaul Mackerras * depending on the value of r5. 25014cf11afSPaul Mackerras * 25114cf11afSPaul Mackerras * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content 25214cf11afSPaul Mackerras * in r3...r7 25314cf11afSPaul Mackerras * 25414cf11afSPaul Mackerras * r5 == NULL -> kexec style entry. r3 is a physical pointer to the 25514cf11afSPaul Mackerras * DT block, r4 is a physical pointer to the kernel itself 25614cf11afSPaul Mackerras * 25714cf11afSPaul Mackerras */ 25814cf11afSPaul Mackerras_GLOBAL(__start_initialization_multiplatform) 259e31aa453SPaul Mackerras /* Make sure we are running in 64 bits mode */ 260e31aa453SPaul Mackerras bl .enable_64b_mode 261e31aa453SPaul Mackerras 262e31aa453SPaul Mackerras /* Get TOC pointer (current runtime address) */ 263e31aa453SPaul Mackerras bl .relative_toc 264e31aa453SPaul Mackerras 265e31aa453SPaul Mackerras /* find out where we are now */ 266e31aa453SPaul Mackerras bcl 20,31,$+4 267e31aa453SPaul Mackerras0: mflr r26 /* r26 = runtime addr here */ 268e31aa453SPaul Mackerras addis r26,r26,(_stext - 0b)@ha 269e31aa453SPaul Mackerras addi r26,r26,(_stext - 0b)@l /* current runtime base addr */ 270e31aa453SPaul Mackerras 27114cf11afSPaul Mackerras /* 27214cf11afSPaul Mackerras * Are we booted from a PROM Of-type client-interface ? 27314cf11afSPaul Mackerras */ 27414cf11afSPaul Mackerras cmpldi cr0,r5,0 275939e60f6SStephen Rothwell beq 1f 276939e60f6SStephen Rothwell b .__boot_from_prom /* yes -> prom */ 277939e60f6SStephen Rothwell1: 27814cf11afSPaul Mackerras /* Save parameters */ 27914cf11afSPaul Mackerras mr r31,r3 28014cf11afSPaul Mackerras mr r30,r4 28114cf11afSPaul Mackerras 28214cf11afSPaul Mackerras /* Setup some critical 970 SPRs before switching MMU off */ 283f39b7a55SOlof Johansson mfspr r0,SPRN_PVR 284f39b7a55SOlof Johansson srwi r0,r0,16 285f39b7a55SOlof Johansson cmpwi r0,0x39 /* 970 */ 286f39b7a55SOlof Johansson beq 1f 287f39b7a55SOlof Johansson cmpwi r0,0x3c /* 970FX */ 288f39b7a55SOlof Johansson beq 1f 289f39b7a55SOlof Johansson cmpwi r0,0x44 /* 970MP */ 290190a24f5SOlof Johansson beq 1f 291190a24f5SOlof Johansson cmpwi r0,0x45 /* 970GX */ 292f39b7a55SOlof Johansson bne 2f 293f39b7a55SOlof Johansson1: bl .__cpu_preinit_ppc970 294f39b7a55SOlof Johansson2: 29514cf11afSPaul Mackerras 296e31aa453SPaul Mackerras /* Switch off MMU if not already off */ 29714cf11afSPaul Mackerras bl .__mmu_off 29814cf11afSPaul Mackerras b .__after_prom_start 29914cf11afSPaul Mackerras 300939e60f6SStephen Rothwell_INIT_STATIC(__boot_from_prom) 30128794d34SBenjamin Herrenschmidt#ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE 30214cf11afSPaul Mackerras /* Save parameters */ 30314cf11afSPaul Mackerras mr r31,r3 30414cf11afSPaul Mackerras mr r30,r4 30514cf11afSPaul Mackerras mr r29,r5 30614cf11afSPaul Mackerras mr r28,r6 30714cf11afSPaul Mackerras mr r27,r7 30814cf11afSPaul Mackerras 3096088857bSOlaf Hering /* 3106088857bSOlaf Hering * Align the stack to 16-byte boundary 3116088857bSOlaf Hering * Depending on the size and layout of the ELF sections in the initial 312e31aa453SPaul Mackerras * boot binary, the stack pointer may be unaligned on PowerMac 3136088857bSOlaf Hering */ 314c05b4770SLinus Torvalds rldicr r1,r1,0,59 315c05b4770SLinus Torvalds 316549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 317549e8152SPaul Mackerras /* Relocate code for where we are now */ 318549e8152SPaul Mackerras mr r3,r26 319549e8152SPaul Mackerras bl .relocate 320549e8152SPaul Mackerras#endif 321549e8152SPaul Mackerras 32214cf11afSPaul Mackerras /* Restore parameters */ 32314cf11afSPaul Mackerras mr r3,r31 32414cf11afSPaul Mackerras mr r4,r30 32514cf11afSPaul Mackerras mr r5,r29 32614cf11afSPaul Mackerras mr r6,r28 32714cf11afSPaul Mackerras mr r7,r27 32814cf11afSPaul Mackerras 32914cf11afSPaul Mackerras /* Do all of the interaction with OF client interface */ 330549e8152SPaul Mackerras mr r8,r26 33114cf11afSPaul Mackerras bl .prom_init 33228794d34SBenjamin Herrenschmidt#endif /* #CONFIG_PPC_OF_BOOT_TRAMPOLINE */ 33328794d34SBenjamin Herrenschmidt 33428794d34SBenjamin Herrenschmidt /* We never return. We also hit that trap if trying to boot 33528794d34SBenjamin Herrenschmidt * from OF while CONFIG_PPC_OF_BOOT_TRAMPOLINE isn't selected */ 33614cf11afSPaul Mackerras trap 33714cf11afSPaul Mackerras 33814cf11afSPaul Mackerras_STATIC(__after_prom_start) 339549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 340549e8152SPaul Mackerras /* process relocations for the final address of the kernel */ 341549e8152SPaul Mackerras lis r25,PAGE_OFFSET@highest /* compute virtual base of kernel */ 342549e8152SPaul Mackerras sldi r25,r25,32 34354622f10SMohan Kumar M#ifdef CONFIG_CRASH_DUMP 3448b8b0cc1SMilton Miller lwz r7,__run_at_load-_stext(r26) 3458b8b0cc1SMilton Miller cmplwi cr0,r7,1 /* kdump kernel ? - stay where we are */ 34654622f10SMohan Kumar M bne 1f 34754622f10SMohan Kumar M add r25,r25,r26 34854622f10SMohan Kumar M#endif 34954622f10SMohan Kumar M1: mr r3,r25 350549e8152SPaul Mackerras bl .relocate 351549e8152SPaul Mackerras#endif 35214cf11afSPaul Mackerras 35314cf11afSPaul Mackerras/* 354e31aa453SPaul Mackerras * We need to run with _stext at physical address PHYSICAL_START. 35514cf11afSPaul Mackerras * This will leave some code in the first 256B of 35614cf11afSPaul Mackerras * real memory, which are reserved for software use. 35714cf11afSPaul Mackerras * 35814cf11afSPaul Mackerras * Note: This process overwrites the OF exception vectors. 35914cf11afSPaul Mackerras */ 360549e8152SPaul Mackerras li r3,0 /* target addr */ 361549e8152SPaul Mackerras mr. r4,r26 /* In some cases the loader may */ 362e31aa453SPaul Mackerras beq 9f /* have already put us at zero */ 36314cf11afSPaul Mackerras li r6,0x100 /* Start offset, the first 0x100 */ 36414cf11afSPaul Mackerras /* bytes were copied earlier. */ 36514cf11afSPaul Mackerras 36654622f10SMohan Kumar M#ifdef CONFIG_CRASH_DUMP 36754622f10SMohan Kumar M/* 36854622f10SMohan Kumar M * Check if the kernel has to be running as relocatable kernel based on the 3698b8b0cc1SMilton Miller * variable __run_at_load, if it is set the kernel is treated as relocatable 37054622f10SMohan Kumar M * kernel, otherwise it will be moved to PHYSICAL_START 37154622f10SMohan Kumar M */ 3728b8b0cc1SMilton Miller lwz r7,__run_at_load-_stext(r26) 3738b8b0cc1SMilton Miller cmplwi cr0,r7,1 37454622f10SMohan Kumar M bne 3f 37554622f10SMohan Kumar M 37654622f10SMohan Kumar M li r5,__end_interrupts - _stext /* just copy interrupts */ 37754622f10SMohan Kumar M b 5f 37854622f10SMohan Kumar M3: 37954622f10SMohan Kumar M#endif 38054622f10SMohan Kumar M lis r5,(copy_to_here - _stext)@ha 38154622f10SMohan Kumar M addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */ 38254622f10SMohan Kumar M 38314cf11afSPaul Mackerras bl .copy_and_flush /* copy the first n bytes */ 38414cf11afSPaul Mackerras /* this includes the code being */ 38514cf11afSPaul Mackerras /* executed here. */ 386e31aa453SPaul Mackerras addis r8,r3,(4f - _stext)@ha /* Jump to the copy of this code */ 387e31aa453SPaul Mackerras addi r8,r8,(4f - _stext)@l /* that we just made */ 388e31aa453SPaul Mackerras mtctr r8 38914cf11afSPaul Mackerras bctr 39014cf11afSPaul Mackerras 39154622f10SMohan Kumar Mp_end: .llong _end - _stext 39254622f10SMohan Kumar M 393e31aa453SPaul Mackerras4: /* Now copy the rest of the kernel up to _end */ 394e31aa453SPaul Mackerras addis r5,r26,(p_end - _stext)@ha 395e31aa453SPaul Mackerras ld r5,(p_end - _stext)@l(r5) /* get _end */ 39654622f10SMohan Kumar M5: bl .copy_and_flush /* copy the rest */ 397e31aa453SPaul Mackerras 398e31aa453SPaul Mackerras9: b .start_here_multiplatform 399e31aa453SPaul Mackerras 40014cf11afSPaul Mackerras/* 40114cf11afSPaul Mackerras * Copy routine used to copy the kernel to start at physical address 0 40214cf11afSPaul Mackerras * and flush and invalidate the caches as needed. 40314cf11afSPaul Mackerras * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset 40414cf11afSPaul Mackerras * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5. 40514cf11afSPaul Mackerras * 40614cf11afSPaul Mackerras * Note: this routine *only* clobbers r0, r6 and lr 40714cf11afSPaul Mackerras */ 40814cf11afSPaul Mackerras_GLOBAL(copy_and_flush) 40914cf11afSPaul Mackerras addi r5,r5,-8 41014cf11afSPaul Mackerras addi r6,r6,-8 4115a2fe38dSOlof Johansson4: li r0,8 /* Use the smallest common */ 41214cf11afSPaul Mackerras /* denominator cache line */ 41314cf11afSPaul Mackerras /* size. This results in */ 41414cf11afSPaul Mackerras /* extra cache line flushes */ 41514cf11afSPaul Mackerras /* but operation is correct. */ 41614cf11afSPaul Mackerras /* Can't get cache line size */ 41714cf11afSPaul Mackerras /* from NACA as it is being */ 41814cf11afSPaul Mackerras /* moved too. */ 41914cf11afSPaul Mackerras 42014cf11afSPaul Mackerras mtctr r0 /* put # words/line in ctr */ 42114cf11afSPaul Mackerras3: addi r6,r6,8 /* copy a cache line */ 42214cf11afSPaul Mackerras ldx r0,r6,r4 42314cf11afSPaul Mackerras stdx r0,r6,r3 42414cf11afSPaul Mackerras bdnz 3b 42514cf11afSPaul Mackerras dcbst r6,r3 /* write it to memory */ 42614cf11afSPaul Mackerras sync 42714cf11afSPaul Mackerras icbi r6,r3 /* flush the icache line */ 42814cf11afSPaul Mackerras cmpld 0,r6,r5 42914cf11afSPaul Mackerras blt 4b 43014cf11afSPaul Mackerras sync 43114cf11afSPaul Mackerras addi r5,r5,8 43214cf11afSPaul Mackerras addi r6,r6,8 43314cf11afSPaul Mackerras blr 43414cf11afSPaul Mackerras 43514cf11afSPaul Mackerras.align 8 43614cf11afSPaul Mackerrascopy_to_here: 43714cf11afSPaul Mackerras 43814cf11afSPaul Mackerras#ifdef CONFIG_SMP 43914cf11afSPaul Mackerras#ifdef CONFIG_PPC_PMAC 44014cf11afSPaul Mackerras/* 44114cf11afSPaul Mackerras * On PowerMac, secondary processors starts from the reset vector, which 44214cf11afSPaul Mackerras * is temporarily turned into a call to one of the functions below. 44314cf11afSPaul Mackerras */ 44414cf11afSPaul Mackerras .section ".text"; 44514cf11afSPaul Mackerras .align 2 ; 44614cf11afSPaul Mackerras 44735499c01SPaul Mackerras .globl __secondary_start_pmac_0 44835499c01SPaul Mackerras__secondary_start_pmac_0: 44935499c01SPaul Mackerras /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */ 45035499c01SPaul Mackerras li r24,0 45135499c01SPaul Mackerras b 1f 45214cf11afSPaul Mackerras li r24,1 45335499c01SPaul Mackerras b 1f 45414cf11afSPaul Mackerras li r24,2 45535499c01SPaul Mackerras b 1f 45614cf11afSPaul Mackerras li r24,3 45735499c01SPaul Mackerras1: 45814cf11afSPaul Mackerras 45914cf11afSPaul Mackerras_GLOBAL(pmac_secondary_start) 46014cf11afSPaul Mackerras /* turn on 64-bit mode */ 46114cf11afSPaul Mackerras bl .enable_64b_mode 46214cf11afSPaul Mackerras 463c478b581SBenjamin Herrenschmidt li r0,0 464c478b581SBenjamin Herrenschmidt mfspr r3,SPRN_HID4 465c478b581SBenjamin Herrenschmidt rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */ 466c478b581SBenjamin Herrenschmidt sync 467c478b581SBenjamin Herrenschmidt mtspr SPRN_HID4,r3 468c478b581SBenjamin Herrenschmidt isync 469c478b581SBenjamin Herrenschmidt sync 470c478b581SBenjamin Herrenschmidt slbia 471c478b581SBenjamin Herrenschmidt 472e31aa453SPaul Mackerras /* get TOC pointer (real address) */ 473e31aa453SPaul Mackerras bl .relative_toc 474e31aa453SPaul Mackerras 47514cf11afSPaul Mackerras /* Copy some CPU settings from CPU 0 */ 476f39b7a55SOlof Johansson bl .__restore_cpu_ppc970 47714cf11afSPaul Mackerras 47814cf11afSPaul Mackerras /* pSeries do that early though I don't think we really need it */ 47914cf11afSPaul Mackerras mfmsr r3 48014cf11afSPaul Mackerras ori r3,r3,MSR_RI 48114cf11afSPaul Mackerras mtmsrd r3 /* RI on */ 48214cf11afSPaul Mackerras 48314cf11afSPaul Mackerras /* Set up a paca value for this processor. */ 484e31aa453SPaul Mackerras LOAD_REG_ADDR(r4,paca) /* Get base vaddr of paca array */ 48514cf11afSPaul Mackerras mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */ 48614cf11afSPaul Mackerras add r13,r13,r4 /* for this processor. */ 487*ee43eb78SBenjamin Herrenschmidt mtspr SPRN_SPRG_PACA,r13 /* Save vaddr of paca in an SPRG*/ 48814cf11afSPaul Mackerras 48914cf11afSPaul Mackerras /* Create a temp kernel stack for use before relocation is on. */ 49014cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 49114cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 49214cf11afSPaul Mackerras 493c705677eSStephen Rothwell b __secondary_start 49414cf11afSPaul Mackerras 49514cf11afSPaul Mackerras#endif /* CONFIG_PPC_PMAC */ 49614cf11afSPaul Mackerras 49714cf11afSPaul Mackerras/* 49814cf11afSPaul Mackerras * This function is called after the master CPU has released the 49914cf11afSPaul Mackerras * secondary processors. The execution environment is relocation off. 50014cf11afSPaul Mackerras * The paca for this processor has the following fields initialized at 50114cf11afSPaul Mackerras * this point: 50214cf11afSPaul Mackerras * 1. Processor number 50314cf11afSPaul Mackerras * 2. Segment table pointer (virtual address) 50414cf11afSPaul Mackerras * On entry the following are set: 50514cf11afSPaul Mackerras * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries 50614cf11afSPaul Mackerras * r24 = cpu# (in Linux terms) 50714cf11afSPaul Mackerras * r13 = paca virtual address 508*ee43eb78SBenjamin Herrenschmidt * SPRG_PACA = paca virtual address 50914cf11afSPaul Mackerras */ 510fc68e869SStephen Rothwell .globl __secondary_start 511c705677eSStephen Rothwell__secondary_start: 512799d6046SPaul Mackerras /* Set thread priority to MEDIUM */ 513799d6046SPaul Mackerras HMT_MEDIUM 51414cf11afSPaul Mackerras 515799d6046SPaul Mackerras /* Do early setup for that CPU (stab, slb, hash table pointer) */ 516799d6046SPaul Mackerras bl .early_setup_secondary 51714cf11afSPaul Mackerras 51814cf11afSPaul Mackerras /* Initialize the kernel stack. Just a repeat for iSeries. */ 519e58c3495SDavid Gibson LOAD_REG_ADDR(r3, current_set) 52014cf11afSPaul Mackerras sldi r28,r24,3 /* get current_set[cpu#] */ 52114cf11afSPaul Mackerras ldx r1,r3,r28 52214cf11afSPaul Mackerras addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD 52314cf11afSPaul Mackerras std r1,PACAKSAVE(r13) 52414cf11afSPaul Mackerras 525799d6046SPaul Mackerras /* Clear backchain so we get nice backtraces */ 52614cf11afSPaul Mackerras li r7,0 52714cf11afSPaul Mackerras mtlr r7 52814cf11afSPaul Mackerras 52914cf11afSPaul Mackerras /* enable MMU and jump to start_secondary */ 530e58c3495SDavid Gibson LOAD_REG_ADDR(r3, .start_secondary_prolog) 531e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4, MSR_KERNEL) 532d04c56f7SPaul Mackerras#ifdef CONFIG_PPC_ISERIES 5333f639ee8SStephen RothwellBEGIN_FW_FTR_SECTION 53414cf11afSPaul Mackerras ori r4,r4,MSR_EE 535ff3da2e0SBenjamin Herrenschmidt li r8,1 536ff3da2e0SBenjamin Herrenschmidt stb r8,PACAHARDIRQEN(r13) 5373f639ee8SStephen RothwellEND_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) 53814cf11afSPaul Mackerras#endif 539d04c56f7SPaul MackerrasBEGIN_FW_FTR_SECTION 540d04c56f7SPaul Mackerras stb r7,PACAHARDIRQEN(r13) 541d04c56f7SPaul MackerrasEND_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES) 542ff3da2e0SBenjamin Herrenschmidt stb r7,PACASOFTIRQEN(r13) 543d04c56f7SPaul Mackerras 544b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r3 545b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r4 54614cf11afSPaul Mackerras rfid 54714cf11afSPaul Mackerras b . /* prevent speculative execution */ 54814cf11afSPaul Mackerras 54914cf11afSPaul Mackerras/* 55014cf11afSPaul Mackerras * Running with relocation on at this point. All we want to do is 551e31aa453SPaul Mackerras * zero the stack back-chain pointer and get the TOC virtual address 552e31aa453SPaul Mackerras * before going into C code. 55314cf11afSPaul Mackerras */ 55414cf11afSPaul Mackerras_GLOBAL(start_secondary_prolog) 555e31aa453SPaul Mackerras ld r2,PACATOC(r13) 55614cf11afSPaul Mackerras li r3,0 55714cf11afSPaul Mackerras std r3,0(r1) /* Zero the stack frame pointer */ 55814cf11afSPaul Mackerras bl .start_secondary 559799d6046SPaul Mackerras b . 56014cf11afSPaul Mackerras#endif 56114cf11afSPaul Mackerras 56214cf11afSPaul Mackerras/* 56314cf11afSPaul Mackerras * This subroutine clobbers r11 and r12 56414cf11afSPaul Mackerras */ 56514cf11afSPaul Mackerras_GLOBAL(enable_64b_mode) 56614cf11afSPaul Mackerras mfmsr r11 /* grab the current MSR */ 567e31aa453SPaul Mackerras li r12,(MSR_SF | MSR_ISF)@highest 568e31aa453SPaul Mackerras sldi r12,r12,48 56914cf11afSPaul Mackerras or r11,r11,r12 57014cf11afSPaul Mackerras mtmsrd r11 57114cf11afSPaul Mackerras isync 57214cf11afSPaul Mackerras blr 57314cf11afSPaul Mackerras 57414cf11afSPaul Mackerras/* 575e31aa453SPaul Mackerras * This puts the TOC pointer into r2, offset by 0x8000 (as expected 576e31aa453SPaul Mackerras * by the toolchain). It computes the correct value for wherever we 577e31aa453SPaul Mackerras * are running at the moment, using position-independent code. 578e31aa453SPaul Mackerras */ 579e31aa453SPaul Mackerras_GLOBAL(relative_toc) 580e31aa453SPaul Mackerras mflr r0 581e31aa453SPaul Mackerras bcl 20,31,$+4 582e31aa453SPaul Mackerras0: mflr r9 583e31aa453SPaul Mackerras ld r2,(p_toc - 0b)(r9) 584e31aa453SPaul Mackerras add r2,r2,r9 585e31aa453SPaul Mackerras mtlr r0 586e31aa453SPaul Mackerras blr 587e31aa453SPaul Mackerras 588e31aa453SPaul Mackerrasp_toc: .llong __toc_start + 0x8000 - 0b 589e31aa453SPaul Mackerras 590e31aa453SPaul Mackerras/* 59114cf11afSPaul Mackerras * This is where the main kernel code starts. 59214cf11afSPaul Mackerras */ 593939e60f6SStephen Rothwell_INIT_STATIC(start_here_multiplatform) 594e31aa453SPaul Mackerras /* set up the TOC (real address) */ 595e31aa453SPaul Mackerras bl .relative_toc 59614cf11afSPaul Mackerras 59714cf11afSPaul Mackerras /* Clear out the BSS. It may have been done in prom_init, 59814cf11afSPaul Mackerras * already but that's irrelevant since prom_init will soon 59914cf11afSPaul Mackerras * be detached from the kernel completely. Besides, we need 60014cf11afSPaul Mackerras * to clear it now for kexec-style entry. 60114cf11afSPaul Mackerras */ 602e31aa453SPaul Mackerras LOAD_REG_ADDR(r11,__bss_stop) 603e31aa453SPaul Mackerras LOAD_REG_ADDR(r8,__bss_start) 60414cf11afSPaul Mackerras sub r11,r11,r8 /* bss size */ 60514cf11afSPaul Mackerras addi r11,r11,7 /* round up to an even double word */ 606e31aa453SPaul Mackerras srdi. r11,r11,3 /* shift right by 3 */ 60714cf11afSPaul Mackerras beq 4f 60814cf11afSPaul Mackerras addi r8,r8,-8 60914cf11afSPaul Mackerras li r0,0 61014cf11afSPaul Mackerras mtctr r11 /* zero this many doublewords */ 61114cf11afSPaul Mackerras3: stdu r0,8(r8) 61214cf11afSPaul Mackerras bdnz 3b 61314cf11afSPaul Mackerras4: 61414cf11afSPaul Mackerras 61514cf11afSPaul Mackerras mfmsr r6 61614cf11afSPaul Mackerras ori r6,r6,MSR_RI 61714cf11afSPaul Mackerras mtmsrd r6 /* RI on */ 61814cf11afSPaul Mackerras 619549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 620549e8152SPaul Mackerras /* Save the physical address we're running at in kernstart_addr */ 621549e8152SPaul Mackerras LOAD_REG_ADDR(r4, kernstart_addr) 622549e8152SPaul Mackerras clrldi r0,r25,2 623549e8152SPaul Mackerras std r0,0(r4) 624549e8152SPaul Mackerras#endif 625549e8152SPaul Mackerras 626e31aa453SPaul Mackerras /* The following gets the stack set up with the regs */ 62714cf11afSPaul Mackerras /* pointing to the real addr of the kernel stack. This is */ 62814cf11afSPaul Mackerras /* all done to support the C function call below which sets */ 62914cf11afSPaul Mackerras /* up the htab. This is done because we have relocated the */ 63014cf11afSPaul Mackerras /* kernel but are still running in real mode. */ 63114cf11afSPaul Mackerras 632e31aa453SPaul Mackerras LOAD_REG_ADDR(r3,init_thread_union) 63314cf11afSPaul Mackerras 634e31aa453SPaul Mackerras /* set up a stack pointer */ 63514cf11afSPaul Mackerras addi r1,r3,THREAD_SIZE 63614cf11afSPaul Mackerras li r0,0 63714cf11afSPaul Mackerras stdu r0,-STACK_FRAME_OVERHEAD(r1) 63814cf11afSPaul Mackerras 63914cf11afSPaul Mackerras /* Do very early kernel initializations, including initial hash table, 64014cf11afSPaul Mackerras * stab and slb setup before we turn on relocation. */ 64114cf11afSPaul Mackerras 64214cf11afSPaul Mackerras /* Restore parameters passed from prom_init/kexec */ 64314cf11afSPaul Mackerras mr r3,r31 644*ee43eb78SBenjamin Herrenschmidt bl .early_setup /* also sets r13 and SPRG_PACA */ 64514cf11afSPaul Mackerras 646e31aa453SPaul Mackerras LOAD_REG_ADDR(r3, .start_here_common) 647e31aa453SPaul Mackerras ld r4,PACAKMSR(r13) 648b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r3 649b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r4 65014cf11afSPaul Mackerras rfid 65114cf11afSPaul Mackerras b . /* prevent speculative execution */ 65214cf11afSPaul Mackerras 65314cf11afSPaul Mackerras /* This is where all platforms converge execution */ 654fc68e869SStephen Rothwell_INIT_GLOBAL(start_here_common) 65514cf11afSPaul Mackerras /* relocation is on at this point */ 65614cf11afSPaul Mackerras std r1,PACAKSAVE(r13) 65714cf11afSPaul Mackerras 658e31aa453SPaul Mackerras /* Load the TOC (virtual address) */ 659e31aa453SPaul Mackerras ld r2,PACATOC(r13) 660e31aa453SPaul Mackerras 66114cf11afSPaul Mackerras bl .setup_system 66214cf11afSPaul Mackerras 66314cf11afSPaul Mackerras /* Load up the kernel context */ 66414cf11afSPaul Mackerras5: 66514cf11afSPaul Mackerras li r5,0 666d04c56f7SPaul Mackerras stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */ 667d04c56f7SPaul Mackerras#ifdef CONFIG_PPC_ISERIES 668d04c56f7SPaul MackerrasBEGIN_FW_FTR_SECTION 66914cf11afSPaul Mackerras mfmsr r5 670ff3da2e0SBenjamin Herrenschmidt ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/ 67114cf11afSPaul Mackerras mtmsrd r5 672ff3da2e0SBenjamin Herrenschmidt li r5,1 6733f639ee8SStephen RothwellEND_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES) 67414cf11afSPaul Mackerras#endif 675ff3da2e0SBenjamin Herrenschmidt stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */ 67614cf11afSPaul Mackerras 67714cf11afSPaul Mackerras bl .start_kernel 67814cf11afSPaul Mackerras 679f1870f77SAnton Blanchard /* Not reached */ 680f1870f77SAnton Blanchard BUG_OPCODE 68114cf11afSPaul Mackerras 68214cf11afSPaul Mackerras/* 68314cf11afSPaul Mackerras * We put a few things here that have to be page-aligned. 68414cf11afSPaul Mackerras * This stuff goes at the beginning of the bss, which is page-aligned. 68514cf11afSPaul Mackerras */ 68614cf11afSPaul Mackerras .section ".bss" 68714cf11afSPaul Mackerras 68814cf11afSPaul Mackerras .align PAGE_SHIFT 68914cf11afSPaul Mackerras 69014cf11afSPaul Mackerras .globl empty_zero_page 69114cf11afSPaul Mackerrasempty_zero_page: 69214cf11afSPaul Mackerras .space PAGE_SIZE 69314cf11afSPaul Mackerras 69414cf11afSPaul Mackerras .globl swapper_pg_dir 69514cf11afSPaul Mackerrasswapper_pg_dir: 696ee7a76daSStephen Rothwell .space PGD_TABLE_SIZE 697