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> 26c141611fSPaul Gortmaker#include <linux/init.h> 27b5bbeb23SPaul Mackerras#include <asm/reg.h> 2814cf11afSPaul Mackerras#include <asm/page.h> 2914cf11afSPaul Mackerras#include <asm/mmu.h> 3014cf11afSPaul Mackerras#include <asm/ppc_asm.h> 3114cf11afSPaul Mackerras#include <asm/asm-offsets.h> 3214cf11afSPaul Mackerras#include <asm/bug.h> 3314cf11afSPaul Mackerras#include <asm/cputable.h> 3414cf11afSPaul Mackerras#include <asm/setup.h> 3514cf11afSPaul Mackerras#include <asm/hvcall.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> 402191d657SAlexander Graf#include <asm/kvm_book3s_asm.h> 4146f52210SStephen Rothwell#include <asm/ptrace.h> 427230c564SBenjamin Herrenschmidt#include <asm/hw_irq.h> 4314cf11afSPaul Mackerras 4425985edcSLucas De Marchi/* The physical memory is laid out such that the secondary processor 450ebc4cdaSBenjamin Herrenschmidt * spin code sits at 0x0000...0x00ff. On server, the vectors follow 460ebc4cdaSBenjamin Herrenschmidt * using the layout described in exceptions-64s.S 4714cf11afSPaul Mackerras */ 4814cf11afSPaul Mackerras 4914cf11afSPaul Mackerras/* 5014cf11afSPaul Mackerras * Entering into this code we make the following assumptions: 510ebc4cdaSBenjamin Herrenschmidt * 520ebc4cdaSBenjamin Herrenschmidt * For pSeries or server processors: 5314cf11afSPaul Mackerras * 1. The MMU is off & open firmware is running in real mode. 5414cf11afSPaul Mackerras * 2. The kernel is entered at __start 5527f44888SBenjamin Herrenschmidt * -or- For OPAL entry: 5627f44888SBenjamin Herrenschmidt * 1. The MMU is off, processor in HV mode, primary CPU enters at 0 57daea1175SBenjamin Herrenschmidt * with device-tree in gpr3. We also get OPAL base in r8 and 58daea1175SBenjamin Herrenschmidt * entry in r9 for debugging purposes 5927f44888SBenjamin Herrenschmidt * 2. Secondary processors enter at 0x60 with PIR in gpr3 6014cf11afSPaul Mackerras * 610ebc4cdaSBenjamin Herrenschmidt * For Book3E processors: 620ebc4cdaSBenjamin Herrenschmidt * 1. The MMU is on running in AS0 in a state defined in ePAPR 630ebc4cdaSBenjamin Herrenschmidt * 2. The kernel is entered at __start 6414cf11afSPaul Mackerras */ 6514cf11afSPaul Mackerras 6614cf11afSPaul Mackerras .text 6714cf11afSPaul Mackerras .globl _stext 6814cf11afSPaul Mackerras_stext: 6914cf11afSPaul Mackerras_GLOBAL(__start) 7014cf11afSPaul Mackerras /* NOP this out unconditionally */ 7114cf11afSPaul MackerrasBEGIN_FTR_SECTION 725c0484e2SBenjamin Herrenschmidt FIXUP_ENDIAN 73b1576fecSAnton Blanchard b __start_initialization_multiplatform 7414cf11afSPaul MackerrasEND_FTR_SECTION(0, 1) 7514cf11afSPaul Mackerras 7614cf11afSPaul Mackerras /* Catch branch to 0 in real mode */ 7714cf11afSPaul Mackerras trap 7814cf11afSPaul Mackerras 792751b628SAnton Blanchard /* Secondary processors spin on this value until it becomes non-zero. 802751b628SAnton Blanchard * When non-zero, it contains the real address of the function the cpu 812751b628SAnton Blanchard * should jump to. 821f6a93e4SPaul Mackerras */ 837d4151b5SOlof Johansson .balign 8 8414cf11afSPaul Mackerras .globl __secondary_hold_spinloop 8514cf11afSPaul Mackerras__secondary_hold_spinloop: 8614cf11afSPaul Mackerras .llong 0x0 8714cf11afSPaul Mackerras 8814cf11afSPaul Mackerras /* Secondary processors write this value with their cpu # */ 8914cf11afSPaul Mackerras /* after they enter the spin loop immediately below. */ 9014cf11afSPaul Mackerras .globl __secondary_hold_acknowledge 9114cf11afSPaul Mackerras__secondary_hold_acknowledge: 9214cf11afSPaul Mackerras .llong 0x0 9314cf11afSPaul Mackerras 94928a3197SSonny Rao#ifdef CONFIG_RELOCATABLE 958b8b0cc1SMilton Miller /* This flag is set to 1 by a loader if the kernel should run 968b8b0cc1SMilton Miller * at the loaded address instead of the linked address. This 978b8b0cc1SMilton Miller * is used by kexec-tools to keep the the kdump kernel in the 988b8b0cc1SMilton Miller * crash_kernel region. The loader is responsible for 998b8b0cc1SMilton Miller * observing the alignment requirement. 1008b8b0cc1SMilton Miller */ 1018b8b0cc1SMilton Miller /* Do not move this variable as kexec-tools knows about it. */ 1028b8b0cc1SMilton Miller . = 0x5c 1038b8b0cc1SMilton Miller .globl __run_at_load 1048b8b0cc1SMilton Miller__run_at_load: 1058b8b0cc1SMilton Miller .long 0x72756e30 /* "run0" -- relocate to 0 by default */ 1068b8b0cc1SMilton Miller#endif 1078b8b0cc1SMilton Miller 10814cf11afSPaul Mackerras . = 0x60 10914cf11afSPaul Mackerras/* 11075423b7bSGeoff Levand * The following code is used to hold secondary processors 11175423b7bSGeoff Levand * in a spin loop after they have entered the kernel, but 11214cf11afSPaul Mackerras * before the bulk of the kernel has been relocated. This code 11314cf11afSPaul Mackerras * is relocated to physical address 0x60 before prom_init is run. 11414cf11afSPaul Mackerras * All of it must fit below the first exception vector at 0x100. 1151f6a93e4SPaul Mackerras * Use .globl here not _GLOBAL because we want __secondary_hold 1161f6a93e4SPaul Mackerras * to be the actual text address, not a descriptor. 11714cf11afSPaul Mackerras */ 1181f6a93e4SPaul Mackerras .globl __secondary_hold 1191f6a93e4SPaul Mackerras__secondary_hold: 1205c0484e2SBenjamin Herrenschmidt FIXUP_ENDIAN 1212d27cfd3SBenjamin Herrenschmidt#ifndef CONFIG_PPC_BOOK3E 12214cf11afSPaul Mackerras mfmsr r24 12314cf11afSPaul Mackerras ori r24,r24,MSR_RI 12414cf11afSPaul Mackerras mtmsrd r24 /* RI on */ 1252d27cfd3SBenjamin Herrenschmidt#endif 126f1870f77SAnton Blanchard /* Grab our physical cpu number */ 12714cf11afSPaul Mackerras mr r24,r3 12896f013feSJimi Xenidis /* stash r4 for book3e */ 12996f013feSJimi Xenidis mr r25,r4 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 13796f013feSJimi Xenidis li r26,0 13896f013feSJimi Xenidis#ifdef CONFIG_PPC_BOOK3E 13996f013feSJimi Xenidis tovirt(r26,r26) 14096f013feSJimi Xenidis#endif 14114cf11afSPaul Mackerras /* All secondary cpus wait here until told to start. */ 142cc7efbf9SAnton Blanchard100: ld r12,__secondary_hold_spinloop-_stext(r26) 143cc7efbf9SAnton Blanchard cmpdi 0,r12,0 1441f6a93e4SPaul Mackerras beq 100b 14514cf11afSPaul Mackerras 146f1870f77SAnton Blanchard#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC) 14796f013feSJimi Xenidis#ifdef CONFIG_PPC_BOOK3E 148cc7efbf9SAnton Blanchard tovirt(r12,r12) 14996f013feSJimi Xenidis#endif 150cc7efbf9SAnton Blanchard mtctr r12 15114cf11afSPaul Mackerras mr r3,r24 15296f013feSJimi Xenidis /* 15396f013feSJimi Xenidis * it may be the case that other platforms have r4 right to 15496f013feSJimi Xenidis * begin with, this gives us some safety in case it is not 15596f013feSJimi Xenidis */ 15696f013feSJimi Xenidis#ifdef CONFIG_PPC_BOOK3E 15796f013feSJimi Xenidis mr r4,r25 15896f013feSJimi Xenidis#else 1592d27cfd3SBenjamin Herrenschmidt li r4,0 16096f013feSJimi Xenidis#endif 161dd797738SBenjamin Herrenschmidt /* Make sure that patched code is visible */ 162dd797738SBenjamin Herrenschmidt isync 163758438a7SMichael Ellerman bctr 16414cf11afSPaul Mackerras#else 16514cf11afSPaul Mackerras BUG_OPCODE 16614cf11afSPaul Mackerras#endif 16714cf11afSPaul Mackerras 16814cf11afSPaul Mackerras/* This value is used to mark exception frames on the stack. */ 16914cf11afSPaul Mackerras .section ".toc","aw" 17014cf11afSPaul Mackerrasexception_marker: 17114cf11afSPaul Mackerras .tc ID_72656773_68657265[TC],0x7265677368657265 17214cf11afSPaul Mackerras .text 17314cf11afSPaul Mackerras 17414cf11afSPaul Mackerras/* 1750ebc4cdaSBenjamin Herrenschmidt * On server, we include the exception vectors code here as it 1760ebc4cdaSBenjamin Herrenschmidt * relies on absolute addressing which is only possible within 1770ebc4cdaSBenjamin Herrenschmidt * this compilation unit 17814cf11afSPaul Mackerras */ 1790ebc4cdaSBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3S 1800ebc4cdaSBenjamin Herrenschmidt#include "exceptions-64s.S" 1811f6a93e4SPaul Mackerras#endif 18214cf11afSPaul Mackerras 1832d27cfd3SBenjamin Herrenschmidt_GLOBAL(generic_secondary_thread_init) 18414cf11afSPaul Mackerras mr r24,r3 18514cf11afSPaul Mackerras 18614cf11afSPaul Mackerras /* turn on 64-bit mode */ 187b1576fecSAnton Blanchard bl enable_64b_mode 18814cf11afSPaul Mackerras 1892d27cfd3SBenjamin Herrenschmidt /* get a valid TOC pointer, wherever we're mapped at */ 190b1576fecSAnton Blanchard bl relative_toc 1911fbe9cf2SAnton Blanchard tovirt(r2,r2) 192e31aa453SPaul Mackerras 1932d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 1942d27cfd3SBenjamin Herrenschmidt /* Book3E initialization */ 1952d27cfd3SBenjamin Herrenschmidt mr r3,r24 196b1576fecSAnton Blanchard bl book3e_secondary_thread_init 1972d27cfd3SBenjamin Herrenschmidt#endif 1982d27cfd3SBenjamin Herrenschmidt b generic_secondary_common_init 1992d27cfd3SBenjamin Herrenschmidt 2002d27cfd3SBenjamin Herrenschmidt/* 2012d27cfd3SBenjamin Herrenschmidt * On pSeries and most other platforms, secondary processors spin 2022d27cfd3SBenjamin Herrenschmidt * in the following code. 2032d27cfd3SBenjamin Herrenschmidt * At entry, r3 = this processor's number (physical cpu id) 2042d27cfd3SBenjamin Herrenschmidt * 2052d27cfd3SBenjamin Herrenschmidt * On Book3E, r4 = 1 to indicate that the initial TLB entry for 2062d27cfd3SBenjamin Herrenschmidt * this core already exists (setup via some other mechanism such 2072d27cfd3SBenjamin Herrenschmidt * as SCOM before entry). 2082d27cfd3SBenjamin Herrenschmidt */ 2092d27cfd3SBenjamin Herrenschmidt_GLOBAL(generic_secondary_smp_init) 2105c0484e2SBenjamin Herrenschmidt FIXUP_ENDIAN 2112d27cfd3SBenjamin Herrenschmidt mr r24,r3 2122d27cfd3SBenjamin Herrenschmidt mr r25,r4 2132d27cfd3SBenjamin Herrenschmidt 2142d27cfd3SBenjamin Herrenschmidt /* turn on 64-bit mode */ 215b1576fecSAnton Blanchard bl enable_64b_mode 2162d27cfd3SBenjamin Herrenschmidt 2172d27cfd3SBenjamin Herrenschmidt /* get a valid TOC pointer, wherever we're mapped at */ 218b1576fecSAnton Blanchard bl relative_toc 2191fbe9cf2SAnton Blanchard tovirt(r2,r2) 2202d27cfd3SBenjamin Herrenschmidt 2212d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 2222d27cfd3SBenjamin Herrenschmidt /* Book3E initialization */ 2232d27cfd3SBenjamin Herrenschmidt mr r3,r24 2242d27cfd3SBenjamin Herrenschmidt mr r4,r25 225b1576fecSAnton Blanchard bl book3e_secondary_core_init 2262d27cfd3SBenjamin Herrenschmidt#endif 2272d27cfd3SBenjamin Herrenschmidt 2282d27cfd3SBenjamin Herrenschmidtgeneric_secondary_common_init: 22914cf11afSPaul Mackerras /* Set up a paca value for this processor. Since we have the 23014cf11afSPaul Mackerras * physical cpu id in r24, we need to search the pacas to find 23114cf11afSPaul Mackerras * which logical id maps to our physical one. 23214cf11afSPaul Mackerras */ 2331426d5a3SMichael Ellerman LOAD_REG_ADDR(r13, paca) /* Load paca pointer */ 2341426d5a3SMichael Ellerman ld r13,0(r13) /* Get base vaddr of paca array */ 235768d18adSMilton Miller#ifndef CONFIG_SMP 236768d18adSMilton Miller addi r13,r13,PACA_SIZE /* know r13 if used accidentally */ 237b1576fecSAnton Blanchard b kexec_wait /* wait for next kernel if !SMP */ 238768d18adSMilton Miller#else 239768d18adSMilton Miller LOAD_REG_ADDR(r7, nr_cpu_ids) /* Load nr_cpu_ids address */ 240768d18adSMilton Miller lwz r7,0(r7) /* also the max paca allocated */ 24114cf11afSPaul Mackerras li r5,0 /* logical cpu id */ 24214cf11afSPaul Mackerras1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */ 24314cf11afSPaul Mackerras cmpw r6,r24 /* Compare to our id */ 24414cf11afSPaul Mackerras beq 2f 24514cf11afSPaul Mackerras addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */ 24614cf11afSPaul Mackerras addi r5,r5,1 247768d18adSMilton Miller cmpw r5,r7 /* Check if more pacas exist */ 24814cf11afSPaul Mackerras blt 1b 24914cf11afSPaul Mackerras 25014cf11afSPaul Mackerras mr r3,r24 /* not found, copy phys to r3 */ 251b1576fecSAnton Blanchard b kexec_wait /* next kernel might do better */ 25214cf11afSPaul Mackerras 2532dd60d79SBenjamin Herrenschmidt2: SET_PACA(r13) 2542d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 2552d27cfd3SBenjamin Herrenschmidt addi r12,r13,PACA_EXTLB /* and TLB exc frame in another */ 2562d27cfd3SBenjamin Herrenschmidt mtspr SPRN_SPRG_TLB_EXFRAME,r12 2572d27cfd3SBenjamin Herrenschmidt#endif 2582d27cfd3SBenjamin Herrenschmidt 25914cf11afSPaul Mackerras /* From now on, r24 is expected to be logical cpuid */ 26014cf11afSPaul Mackerras mr r24,r5 261b6f6b98aSSonny Rao 262f39b7a55SOlof Johansson /* See if we need to call a cpu state restore handler */ 263e31aa453SPaul Mackerras LOAD_REG_ADDR(r23, cur_cpu_spec) 264f39b7a55SOlof Johansson ld r23,0(r23) 2652751b628SAnton Blanchard ld r12,CPU_SPEC_RESTORE(r23) 2662751b628SAnton Blanchard cmpdi 0,r12,0 2679d07bc84SBenjamin Herrenschmidt beq 3f 2682751b628SAnton Blanchard#if !defined(_CALL_ELF) || _CALL_ELF != 2 2692751b628SAnton Blanchard ld r12,0(r12) 2702751b628SAnton Blanchard#endif 271cc7efbf9SAnton Blanchard mtctr r12 272f39b7a55SOlof Johansson bctrl 273f39b7a55SOlof Johansson 2747ac87abbSMatt Evans3: LOAD_REG_ADDR(r3, spinning_secondaries) /* Decrement spinning_secondaries */ 2759d07bc84SBenjamin Herrenschmidt lwarx r4,0,r3 2769d07bc84SBenjamin Herrenschmidt subi r4,r4,1 2779d07bc84SBenjamin Herrenschmidt stwcx. r4,0,r3 2789d07bc84SBenjamin Herrenschmidt bne 3b 2799d07bc84SBenjamin Herrenschmidt isync 2809d07bc84SBenjamin Herrenschmidt 2819d07bc84SBenjamin Herrenschmidt4: HMT_LOW 282ad0693eeSBenjamin Herrenschmidt lbz r23,PACAPROCSTART(r13) /* Test if this processor should */ 283ad0693eeSBenjamin Herrenschmidt /* start. */ 284ad0693eeSBenjamin Herrenschmidt cmpwi 0,r23,0 2859d07bc84SBenjamin Herrenschmidt beq 4b /* Loop until told to go */ 286ad0693eeSBenjamin Herrenschmidt 287ad0693eeSBenjamin Herrenschmidt sync /* order paca.run and cur_cpu_spec */ 2889d07bc84SBenjamin Herrenschmidt isync /* In case code patching happened */ 289ad0693eeSBenjamin Herrenschmidt 2909d07bc84SBenjamin Herrenschmidt /* Create a temp kernel stack for use before relocation is on. */ 29114cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 29214cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 29314cf11afSPaul Mackerras 294c705677eSStephen Rothwell b __secondary_start 295768d18adSMilton Miller#endif /* SMP */ 29614cf11afSPaul Mackerras 297e31aa453SPaul Mackerras/* 298e31aa453SPaul Mackerras * Turn the MMU off. 299e31aa453SPaul Mackerras * Assumes we're mapped EA == RA if the MMU is on. 300e31aa453SPaul Mackerras */ 3012d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3S 3026a3bab90SAnton Blanchard__mmu_off: 30314cf11afSPaul Mackerras mfmsr r3 30414cf11afSPaul Mackerras andi. r0,r3,MSR_IR|MSR_DR 30514cf11afSPaul Mackerras beqlr 306e31aa453SPaul Mackerras mflr r4 30714cf11afSPaul Mackerras andc r3,r3,r0 30814cf11afSPaul Mackerras mtspr SPRN_SRR0,r4 30914cf11afSPaul Mackerras mtspr SPRN_SRR1,r3 31014cf11afSPaul Mackerras sync 31114cf11afSPaul Mackerras rfid 31214cf11afSPaul Mackerras b . /* prevent speculative execution */ 3132d27cfd3SBenjamin Herrenschmidt#endif 31414cf11afSPaul Mackerras 31514cf11afSPaul Mackerras 31614cf11afSPaul Mackerras/* 31714cf11afSPaul Mackerras * Here is our main kernel entry point. We support currently 2 kind of entries 31814cf11afSPaul Mackerras * depending on the value of r5. 31914cf11afSPaul Mackerras * 32014cf11afSPaul Mackerras * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content 32114cf11afSPaul Mackerras * in r3...r7 32214cf11afSPaul Mackerras * 32314cf11afSPaul Mackerras * r5 == NULL -> kexec style entry. r3 is a physical pointer to the 32414cf11afSPaul Mackerras * DT block, r4 is a physical pointer to the kernel itself 32514cf11afSPaul Mackerras * 32614cf11afSPaul Mackerras */ 3276a3bab90SAnton Blanchard__start_initialization_multiplatform: 328e31aa453SPaul Mackerras /* Make sure we are running in 64 bits mode */ 329b1576fecSAnton Blanchard bl enable_64b_mode 330e31aa453SPaul Mackerras 331e31aa453SPaul Mackerras /* Get TOC pointer (current runtime address) */ 332b1576fecSAnton Blanchard bl relative_toc 333e31aa453SPaul Mackerras 334e31aa453SPaul Mackerras /* find out where we are now */ 335e31aa453SPaul Mackerras bcl 20,31,$+4 336e31aa453SPaul Mackerras0: mflr r26 /* r26 = runtime addr here */ 337e31aa453SPaul Mackerras addis r26,r26,(_stext - 0b)@ha 338e31aa453SPaul Mackerras addi r26,r26,(_stext - 0b)@l /* current runtime base addr */ 339e31aa453SPaul Mackerras 34014cf11afSPaul Mackerras /* 34114cf11afSPaul Mackerras * Are we booted from a PROM Of-type client-interface ? 34214cf11afSPaul Mackerras */ 34314cf11afSPaul Mackerras cmpldi cr0,r5,0 344939e60f6SStephen Rothwell beq 1f 345b1576fecSAnton Blanchard b __boot_from_prom /* yes -> prom */ 346939e60f6SStephen Rothwell1: 34714cf11afSPaul Mackerras /* Save parameters */ 34814cf11afSPaul Mackerras mr r31,r3 34914cf11afSPaul Mackerras mr r30,r4 350daea1175SBenjamin Herrenschmidt#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL 351daea1175SBenjamin Herrenschmidt /* Save OPAL entry */ 352daea1175SBenjamin Herrenschmidt mr r28,r8 353daea1175SBenjamin Herrenschmidt mr r29,r9 354daea1175SBenjamin Herrenschmidt#endif 35514cf11afSPaul Mackerras 3562d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 357b1576fecSAnton Blanchard bl start_initialization_book3e 358b1576fecSAnton Blanchard b __after_prom_start 3592d27cfd3SBenjamin Herrenschmidt#else 36014cf11afSPaul Mackerras /* Setup some critical 970 SPRs before switching MMU off */ 361f39b7a55SOlof Johansson mfspr r0,SPRN_PVR 362f39b7a55SOlof Johansson srwi r0,r0,16 363f39b7a55SOlof Johansson cmpwi r0,0x39 /* 970 */ 364f39b7a55SOlof Johansson beq 1f 365f39b7a55SOlof Johansson cmpwi r0,0x3c /* 970FX */ 366f39b7a55SOlof Johansson beq 1f 367f39b7a55SOlof Johansson cmpwi r0,0x44 /* 970MP */ 368190a24f5SOlof Johansson beq 1f 369190a24f5SOlof Johansson cmpwi r0,0x45 /* 970GX */ 370f39b7a55SOlof Johansson bne 2f 371b1576fecSAnton Blanchard1: bl __cpu_preinit_ppc970 372f39b7a55SOlof Johansson2: 37314cf11afSPaul Mackerras 374e31aa453SPaul Mackerras /* Switch off MMU if not already off */ 375b1576fecSAnton Blanchard bl __mmu_off 376b1576fecSAnton Blanchard b __after_prom_start 3772d27cfd3SBenjamin Herrenschmidt#endif /* CONFIG_PPC_BOOK3E */ 37814cf11afSPaul Mackerras 3796a3bab90SAnton Blanchard__boot_from_prom: 38028794d34SBenjamin Herrenschmidt#ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE 38114cf11afSPaul Mackerras /* Save parameters */ 38214cf11afSPaul Mackerras mr r31,r3 38314cf11afSPaul Mackerras mr r30,r4 38414cf11afSPaul Mackerras mr r29,r5 38514cf11afSPaul Mackerras mr r28,r6 38614cf11afSPaul Mackerras mr r27,r7 38714cf11afSPaul Mackerras 3886088857bSOlaf Hering /* 3896088857bSOlaf Hering * Align the stack to 16-byte boundary 3906088857bSOlaf Hering * Depending on the size and layout of the ELF sections in the initial 391e31aa453SPaul Mackerras * boot binary, the stack pointer may be unaligned on PowerMac 3926088857bSOlaf Hering */ 393c05b4770SLinus Torvalds rldicr r1,r1,0,59 394c05b4770SLinus Torvalds 395549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 396549e8152SPaul Mackerras /* Relocate code for where we are now */ 397549e8152SPaul Mackerras mr r3,r26 398b1576fecSAnton Blanchard bl relocate 399549e8152SPaul Mackerras#endif 400549e8152SPaul Mackerras 40114cf11afSPaul Mackerras /* Restore parameters */ 40214cf11afSPaul Mackerras mr r3,r31 40314cf11afSPaul Mackerras mr r4,r30 40414cf11afSPaul Mackerras mr r5,r29 40514cf11afSPaul Mackerras mr r6,r28 40614cf11afSPaul Mackerras mr r7,r27 40714cf11afSPaul Mackerras 40814cf11afSPaul Mackerras /* Do all of the interaction with OF client interface */ 409549e8152SPaul Mackerras mr r8,r26 410b1576fecSAnton Blanchard bl prom_init 41128794d34SBenjamin Herrenschmidt#endif /* #CONFIG_PPC_OF_BOOT_TRAMPOLINE */ 41228794d34SBenjamin Herrenschmidt 41328794d34SBenjamin Herrenschmidt /* We never return. We also hit that trap if trying to boot 41428794d34SBenjamin Herrenschmidt * from OF while CONFIG_PPC_OF_BOOT_TRAMPOLINE isn't selected */ 41514cf11afSPaul Mackerras trap 41614cf11afSPaul Mackerras 4176a3bab90SAnton Blanchard__after_prom_start: 418549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 419549e8152SPaul Mackerras /* process relocations for the final address of the kernel */ 420549e8152SPaul Mackerras lis r25,PAGE_OFFSET@highest /* compute virtual base of kernel */ 421549e8152SPaul Mackerras sldi r25,r25,32 4228b8b0cc1SMilton Miller lwz r7,__run_at_load-_stext(r26) 423928a3197SSonny Rao cmplwi cr0,r7,1 /* flagged to stay where we are ? */ 42454622f10SMohan Kumar M bne 1f 42554622f10SMohan Kumar M add r25,r25,r26 42654622f10SMohan Kumar M1: mr r3,r25 427b1576fecSAnton Blanchard bl relocate 428549e8152SPaul Mackerras#endif 42914cf11afSPaul Mackerras 43014cf11afSPaul Mackerras/* 431e31aa453SPaul Mackerras * We need to run with _stext at physical address PHYSICAL_START. 43214cf11afSPaul Mackerras * This will leave some code in the first 256B of 43314cf11afSPaul Mackerras * real memory, which are reserved for software use. 43414cf11afSPaul Mackerras * 43514cf11afSPaul Mackerras * Note: This process overwrites the OF exception vectors. 43614cf11afSPaul Mackerras */ 437549e8152SPaul Mackerras li r3,0 /* target addr */ 4382d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 4392d27cfd3SBenjamin Herrenschmidt tovirt(r3,r3) /* on booke, we already run at PAGE_OFFSET */ 4402d27cfd3SBenjamin Herrenschmidt#endif 441549e8152SPaul Mackerras mr. r4,r26 /* In some cases the loader may */ 442e31aa453SPaul Mackerras beq 9f /* have already put us at zero */ 44314cf11afSPaul Mackerras li r6,0x100 /* Start offset, the first 0x100 */ 44414cf11afSPaul Mackerras /* bytes were copied earlier. */ 4452d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 4462d27cfd3SBenjamin Herrenschmidt tovirt(r6,r6) /* on booke, we already run at PAGE_OFFSET */ 4472d27cfd3SBenjamin Herrenschmidt#endif 44814cf11afSPaul Mackerras 44911ee7e99SAnton Blanchard#ifdef CONFIG_RELOCATABLE 45054622f10SMohan Kumar M/* 45154622f10SMohan Kumar M * Check if the kernel has to be running as relocatable kernel based on the 4528b8b0cc1SMilton Miller * variable __run_at_load, if it is set the kernel is treated as relocatable 45354622f10SMohan Kumar M * kernel, otherwise it will be moved to PHYSICAL_START 45454622f10SMohan Kumar M */ 4558b8b0cc1SMilton Miller lwz r7,__run_at_load-_stext(r26) 4568b8b0cc1SMilton Miller cmplwi cr0,r7,1 45754622f10SMohan Kumar M bne 3f 45854622f10SMohan Kumar M 459c1fb6816SMichael Neuling /* just copy interrupts */ 460c1fb6816SMichael Neuling LOAD_REG_IMMEDIATE(r5, __end_interrupts - _stext) 46154622f10SMohan Kumar M b 5f 46254622f10SMohan Kumar M3: 46354622f10SMohan Kumar M#endif 46454622f10SMohan Kumar M lis r5,(copy_to_here - _stext)@ha 46554622f10SMohan Kumar M addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */ 46654622f10SMohan Kumar M 467b1576fecSAnton Blanchard bl copy_and_flush /* copy the first n bytes */ 46814cf11afSPaul Mackerras /* this includes the code being */ 46914cf11afSPaul Mackerras /* executed here. */ 470e31aa453SPaul Mackerras addis r8,r3,(4f - _stext)@ha /* Jump to the copy of this code */ 471cc7efbf9SAnton Blanchard addi r12,r8,(4f - _stext)@l /* that we just made */ 472cc7efbf9SAnton Blanchard mtctr r12 47314cf11afSPaul Mackerras bctr 47414cf11afSPaul Mackerras 475286e4f90SAnton Blanchard.balign 8 47654622f10SMohan Kumar Mp_end: .llong _end - _stext 47754622f10SMohan Kumar M 478e31aa453SPaul Mackerras4: /* Now copy the rest of the kernel up to _end */ 479e31aa453SPaul Mackerras addis r5,r26,(p_end - _stext)@ha 480e31aa453SPaul Mackerras ld r5,(p_end - _stext)@l(r5) /* get _end */ 481b1576fecSAnton Blanchard5: bl copy_and_flush /* copy the rest */ 482e31aa453SPaul Mackerras 483b1576fecSAnton Blanchard9: b start_here_multiplatform 484e31aa453SPaul Mackerras 48514cf11afSPaul Mackerras/* 48614cf11afSPaul Mackerras * Copy routine used to copy the kernel to start at physical address 0 48714cf11afSPaul Mackerras * and flush and invalidate the caches as needed. 48814cf11afSPaul Mackerras * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset 48914cf11afSPaul Mackerras * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5. 49014cf11afSPaul Mackerras * 49114cf11afSPaul Mackerras * Note: this routine *only* clobbers r0, r6 and lr 49214cf11afSPaul Mackerras */ 49314cf11afSPaul Mackerras_GLOBAL(copy_and_flush) 49414cf11afSPaul Mackerras addi r5,r5,-8 49514cf11afSPaul Mackerras addi r6,r6,-8 4965a2fe38dSOlof Johansson4: li r0,8 /* Use the smallest common */ 49714cf11afSPaul Mackerras /* denominator cache line */ 49814cf11afSPaul Mackerras /* size. This results in */ 49914cf11afSPaul Mackerras /* extra cache line flushes */ 50014cf11afSPaul Mackerras /* but operation is correct. */ 50114cf11afSPaul Mackerras /* Can't get cache line size */ 50214cf11afSPaul Mackerras /* from NACA as it is being */ 50314cf11afSPaul Mackerras /* moved too. */ 50414cf11afSPaul Mackerras 50514cf11afSPaul Mackerras mtctr r0 /* put # words/line in ctr */ 50614cf11afSPaul Mackerras3: addi r6,r6,8 /* copy a cache line */ 50714cf11afSPaul Mackerras ldx r0,r6,r4 50814cf11afSPaul Mackerras stdx r0,r6,r3 50914cf11afSPaul Mackerras bdnz 3b 51014cf11afSPaul Mackerras dcbst r6,r3 /* write it to memory */ 51114cf11afSPaul Mackerras sync 51214cf11afSPaul Mackerras icbi r6,r3 /* flush the icache line */ 51314cf11afSPaul Mackerras cmpld 0,r6,r5 51414cf11afSPaul Mackerras blt 4b 51514cf11afSPaul Mackerras sync 51614cf11afSPaul Mackerras addi r5,r5,8 51714cf11afSPaul Mackerras addi r6,r6,8 51829ce3c50SMichael Neuling isync 51914cf11afSPaul Mackerras blr 52014cf11afSPaul Mackerras 52114cf11afSPaul Mackerras.align 8 52214cf11afSPaul Mackerrascopy_to_here: 52314cf11afSPaul Mackerras 52414cf11afSPaul Mackerras#ifdef CONFIG_SMP 52514cf11afSPaul Mackerras#ifdef CONFIG_PPC_PMAC 52614cf11afSPaul Mackerras/* 52714cf11afSPaul Mackerras * On PowerMac, secondary processors starts from the reset vector, which 52814cf11afSPaul Mackerras * is temporarily turned into a call to one of the functions below. 52914cf11afSPaul Mackerras */ 53014cf11afSPaul Mackerras .section ".text"; 53114cf11afSPaul Mackerras .align 2 ; 53214cf11afSPaul Mackerras 53335499c01SPaul Mackerras .globl __secondary_start_pmac_0 53435499c01SPaul Mackerras__secondary_start_pmac_0: 53535499c01SPaul Mackerras /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */ 53635499c01SPaul Mackerras li r24,0 53735499c01SPaul Mackerras b 1f 53814cf11afSPaul Mackerras li r24,1 53935499c01SPaul Mackerras b 1f 54014cf11afSPaul Mackerras li r24,2 54135499c01SPaul Mackerras b 1f 54214cf11afSPaul Mackerras li r24,3 54335499c01SPaul Mackerras1: 54414cf11afSPaul Mackerras 54514cf11afSPaul Mackerras_GLOBAL(pmac_secondary_start) 54614cf11afSPaul Mackerras /* turn on 64-bit mode */ 547b1576fecSAnton Blanchard bl enable_64b_mode 54814cf11afSPaul Mackerras 549c478b581SBenjamin Herrenschmidt li r0,0 550c478b581SBenjamin Herrenschmidt mfspr r3,SPRN_HID4 551c478b581SBenjamin Herrenschmidt rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */ 552c478b581SBenjamin Herrenschmidt sync 553c478b581SBenjamin Herrenschmidt mtspr SPRN_HID4,r3 554c478b581SBenjamin Herrenschmidt isync 555c478b581SBenjamin Herrenschmidt sync 556c478b581SBenjamin Herrenschmidt slbia 557c478b581SBenjamin Herrenschmidt 558e31aa453SPaul Mackerras /* get TOC pointer (real address) */ 559b1576fecSAnton Blanchard bl relative_toc 5601fbe9cf2SAnton Blanchard tovirt(r2,r2) 561e31aa453SPaul Mackerras 56214cf11afSPaul Mackerras /* Copy some CPU settings from CPU 0 */ 563b1576fecSAnton Blanchard bl __restore_cpu_ppc970 56414cf11afSPaul Mackerras 56514cf11afSPaul Mackerras /* pSeries do that early though I don't think we really need it */ 56614cf11afSPaul Mackerras mfmsr r3 56714cf11afSPaul Mackerras ori r3,r3,MSR_RI 56814cf11afSPaul Mackerras mtmsrd r3 /* RI on */ 56914cf11afSPaul Mackerras 57014cf11afSPaul Mackerras /* Set up a paca value for this processor. */ 5711426d5a3SMichael Ellerman LOAD_REG_ADDR(r4,paca) /* Load paca pointer */ 5721426d5a3SMichael Ellerman ld r4,0(r4) /* Get base vaddr of paca array */ 57314cf11afSPaul Mackerras mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */ 57414cf11afSPaul Mackerras add r13,r13,r4 /* for this processor. */ 5752dd60d79SBenjamin Herrenschmidt SET_PACA(r13) /* Save vaddr of paca in an SPRG*/ 57614cf11afSPaul Mackerras 57762cc67b9SBenjamin Herrenschmidt /* Mark interrupts soft and hard disabled (they might be enabled 57862cc67b9SBenjamin Herrenschmidt * in the PACA when doing hotplug) 57962cc67b9SBenjamin Herrenschmidt */ 58062cc67b9SBenjamin Herrenschmidt li r0,0 58162cc67b9SBenjamin Herrenschmidt stb r0,PACASOFTIRQEN(r13) 5827230c564SBenjamin Herrenschmidt li r0,PACA_IRQ_HARD_DIS 5837230c564SBenjamin Herrenschmidt stb r0,PACAIRQHAPPENED(r13) 58462cc67b9SBenjamin Herrenschmidt 58514cf11afSPaul Mackerras /* Create a temp kernel stack for use before relocation is on. */ 58614cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 58714cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 58814cf11afSPaul Mackerras 589c705677eSStephen Rothwell b __secondary_start 59014cf11afSPaul Mackerras 59114cf11afSPaul Mackerras#endif /* CONFIG_PPC_PMAC */ 59214cf11afSPaul Mackerras 59314cf11afSPaul Mackerras/* 59414cf11afSPaul Mackerras * This function is called after the master CPU has released the 59514cf11afSPaul Mackerras * secondary processors. The execution environment is relocation off. 59614cf11afSPaul Mackerras * The paca for this processor has the following fields initialized at 59714cf11afSPaul Mackerras * this point: 59814cf11afSPaul Mackerras * 1. Processor number 59914cf11afSPaul Mackerras * 2. Segment table pointer (virtual address) 60014cf11afSPaul Mackerras * On entry the following are set: 6014f8cf36fSBenjamin Herrenschmidt * r1 = stack pointer (real addr of temp stack) 60214cf11afSPaul Mackerras * r24 = cpu# (in Linux terms) 60314cf11afSPaul Mackerras * r13 = paca virtual address 604ee43eb78SBenjamin Herrenschmidt * SPRG_PACA = paca virtual address 60514cf11afSPaul Mackerras */ 6062d27cfd3SBenjamin Herrenschmidt .section ".text"; 6072d27cfd3SBenjamin Herrenschmidt .align 2 ; 6082d27cfd3SBenjamin Herrenschmidt 609fc68e869SStephen Rothwell .globl __secondary_start 610c705677eSStephen Rothwell__secondary_start: 611799d6046SPaul Mackerras /* Set thread priority to MEDIUM */ 612799d6046SPaul Mackerras HMT_MEDIUM 61314cf11afSPaul Mackerras 6144f8cf36fSBenjamin Herrenschmidt /* Initialize the kernel stack */ 615e58c3495SDavid Gibson LOAD_REG_ADDR(r3, current_set) 61614cf11afSPaul Mackerras sldi r28,r24,3 /* get current_set[cpu#] */ 61754a83404SMichael Neuling ldx r14,r3,r28 61854a83404SMichael Neuling addi r14,r14,THREAD_SIZE-STACK_FRAME_OVERHEAD 61954a83404SMichael Neuling std r14,PACAKSAVE(r13) 62014cf11afSPaul Mackerras 621*376af594SMichael Ellerman /* Do early setup for that CPU (SLB and hash table pointer) */ 622b1576fecSAnton Blanchard bl early_setup_secondary 623f761622eSMatt Evans 62454a83404SMichael Neuling /* 62554a83404SMichael Neuling * setup the new stack pointer, but *don't* use this until 62654a83404SMichael Neuling * translation is on. 62754a83404SMichael Neuling */ 62854a83404SMichael Neuling mr r1, r14 62954a83404SMichael Neuling 630799d6046SPaul Mackerras /* Clear backchain so we get nice backtraces */ 63114cf11afSPaul Mackerras li r7,0 63214cf11afSPaul Mackerras mtlr r7 63314cf11afSPaul Mackerras 6347230c564SBenjamin Herrenschmidt /* Mark interrupts soft and hard disabled (they might be enabled 6357230c564SBenjamin Herrenschmidt * in the PACA when doing hotplug) 6367230c564SBenjamin Herrenschmidt */ 6374f8cf36fSBenjamin Herrenschmidt stb r7,PACASOFTIRQEN(r13) 6387230c564SBenjamin Herrenschmidt li r0,PACA_IRQ_HARD_DIS 6397230c564SBenjamin Herrenschmidt stb r0,PACAIRQHAPPENED(r13) 6404f8cf36fSBenjamin Herrenschmidt 64114cf11afSPaul Mackerras /* enable MMU and jump to start_secondary */ 642ad0289e4SAnton Blanchard LOAD_REG_ADDR(r3, start_secondary_prolog) 643e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4, MSR_KERNEL) 644d04c56f7SPaul Mackerras 645b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r3 646b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r4 6472d27cfd3SBenjamin Herrenschmidt RFI 64814cf11afSPaul Mackerras b . /* prevent speculative execution */ 64914cf11afSPaul Mackerras 65014cf11afSPaul Mackerras/* 65114cf11afSPaul Mackerras * Running with relocation on at this point. All we want to do is 652e31aa453SPaul Mackerras * zero the stack back-chain pointer and get the TOC virtual address 653e31aa453SPaul Mackerras * before going into C code. 65414cf11afSPaul Mackerras */ 655ad0289e4SAnton Blanchardstart_secondary_prolog: 656e31aa453SPaul Mackerras ld r2,PACATOC(r13) 65714cf11afSPaul Mackerras li r3,0 65814cf11afSPaul Mackerras std r3,0(r1) /* Zero the stack frame pointer */ 659b1576fecSAnton Blanchard bl start_secondary 660799d6046SPaul Mackerras b . 6618dbce53cSVaidyanathan Srinivasan/* 6628dbce53cSVaidyanathan Srinivasan * Reset stack pointer and call start_secondary 6638dbce53cSVaidyanathan Srinivasan * to continue with online operation when woken up 6648dbce53cSVaidyanathan Srinivasan * from cede in cpu offline. 6658dbce53cSVaidyanathan Srinivasan */ 6668dbce53cSVaidyanathan Srinivasan_GLOBAL(start_secondary_resume) 6678dbce53cSVaidyanathan Srinivasan ld r1,PACAKSAVE(r13) /* Reload kernel stack pointer */ 6688dbce53cSVaidyanathan Srinivasan li r3,0 6698dbce53cSVaidyanathan Srinivasan std r3,0(r1) /* Zero the stack frame pointer */ 670b1576fecSAnton Blanchard bl start_secondary 6718dbce53cSVaidyanathan Srinivasan b . 67214cf11afSPaul Mackerras#endif 67314cf11afSPaul Mackerras 67414cf11afSPaul Mackerras/* 67514cf11afSPaul Mackerras * This subroutine clobbers r11 and r12 67614cf11afSPaul Mackerras */ 6776a3bab90SAnton Blanchardenable_64b_mode: 67814cf11afSPaul Mackerras mfmsr r11 /* grab the current MSR */ 6792d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 6802d27cfd3SBenjamin Herrenschmidt oris r11,r11,0x8000 /* CM bit set, we'll set ICM later */ 6812d27cfd3SBenjamin Herrenschmidt mtmsr r11 6822d27cfd3SBenjamin Herrenschmidt#else /* CONFIG_PPC_BOOK3E */ 6839f0b0793SMichael Ellerman li r12,(MSR_64BIT | MSR_ISF)@highest 684e31aa453SPaul Mackerras sldi r12,r12,48 68514cf11afSPaul Mackerras or r11,r11,r12 68614cf11afSPaul Mackerras mtmsrd r11 68714cf11afSPaul Mackerras isync 6882d27cfd3SBenjamin Herrenschmidt#endif 68914cf11afSPaul Mackerras blr 69014cf11afSPaul Mackerras 69114cf11afSPaul Mackerras/* 692e31aa453SPaul Mackerras * This puts the TOC pointer into r2, offset by 0x8000 (as expected 693e31aa453SPaul Mackerras * by the toolchain). It computes the correct value for wherever we 694e31aa453SPaul Mackerras * are running at the moment, using position-independent code. 6951fbe9cf2SAnton Blanchard * 6961fbe9cf2SAnton Blanchard * Note: The compiler constructs pointers using offsets from the 6971fbe9cf2SAnton Blanchard * TOC in -mcmodel=medium mode. After we relocate to 0 but before 6981fbe9cf2SAnton Blanchard * the MMU is on we need our TOC to be a virtual address otherwise 6991fbe9cf2SAnton Blanchard * these pointers will be real addresses which may get stored and 7001fbe9cf2SAnton Blanchard * accessed later with the MMU on. We use tovirt() at the call 7011fbe9cf2SAnton Blanchard * sites to handle this. 702e31aa453SPaul Mackerras */ 703e31aa453SPaul Mackerras_GLOBAL(relative_toc) 704e31aa453SPaul Mackerras mflr r0 705e31aa453SPaul Mackerras bcl 20,31,$+4 706e550592eSBenjamin Herrenschmidt0: mflr r11 707e550592eSBenjamin Herrenschmidt ld r2,(p_toc - 0b)(r11) 708e550592eSBenjamin Herrenschmidt add r2,r2,r11 709e31aa453SPaul Mackerras mtlr r0 710e31aa453SPaul Mackerras blr 711e31aa453SPaul Mackerras 7125b63fee1SAnton Blanchard.balign 8 713e31aa453SPaul Mackerrasp_toc: .llong __toc_start + 0x8000 - 0b 714e31aa453SPaul Mackerras 715e31aa453SPaul Mackerras/* 71614cf11afSPaul Mackerras * This is where the main kernel code starts. 71714cf11afSPaul Mackerras */ 7186a3bab90SAnton Blanchardstart_here_multiplatform: 7191fbe9cf2SAnton Blanchard /* set up the TOC */ 720b1576fecSAnton Blanchard bl relative_toc 7211fbe9cf2SAnton Blanchard tovirt(r2,r2) 72214cf11afSPaul Mackerras 72314cf11afSPaul Mackerras /* Clear out the BSS. It may have been done in prom_init, 72414cf11afSPaul Mackerras * already but that's irrelevant since prom_init will soon 72514cf11afSPaul Mackerras * be detached from the kernel completely. Besides, we need 72614cf11afSPaul Mackerras * to clear it now for kexec-style entry. 72714cf11afSPaul Mackerras */ 728e31aa453SPaul Mackerras LOAD_REG_ADDR(r11,__bss_stop) 729e31aa453SPaul Mackerras LOAD_REG_ADDR(r8,__bss_start) 73014cf11afSPaul Mackerras sub r11,r11,r8 /* bss size */ 73114cf11afSPaul Mackerras addi r11,r11,7 /* round up to an even double word */ 732e31aa453SPaul Mackerras srdi. r11,r11,3 /* shift right by 3 */ 73314cf11afSPaul Mackerras beq 4f 73414cf11afSPaul Mackerras addi r8,r8,-8 73514cf11afSPaul Mackerras li r0,0 73614cf11afSPaul Mackerras mtctr r11 /* zero this many doublewords */ 73714cf11afSPaul Mackerras3: stdu r0,8(r8) 73814cf11afSPaul Mackerras bdnz 3b 73914cf11afSPaul Mackerras4: 74014cf11afSPaul Mackerras 741daea1175SBenjamin Herrenschmidt#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL 742daea1175SBenjamin Herrenschmidt /* Setup OPAL entry */ 743ab7f961aSBenjamin Herrenschmidt LOAD_REG_ADDR(r11, opal) 744daea1175SBenjamin Herrenschmidt std r28,0(r11); 745daea1175SBenjamin Herrenschmidt std r29,8(r11); 746daea1175SBenjamin Herrenschmidt#endif 747daea1175SBenjamin Herrenschmidt 7482d27cfd3SBenjamin Herrenschmidt#ifndef CONFIG_PPC_BOOK3E 74914cf11afSPaul Mackerras mfmsr r6 75014cf11afSPaul Mackerras ori r6,r6,MSR_RI 75114cf11afSPaul Mackerras mtmsrd r6 /* RI on */ 7522d27cfd3SBenjamin Herrenschmidt#endif 75314cf11afSPaul Mackerras 754549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 755549e8152SPaul Mackerras /* Save the physical address we're running at in kernstart_addr */ 756549e8152SPaul Mackerras LOAD_REG_ADDR(r4, kernstart_addr) 757549e8152SPaul Mackerras clrldi r0,r25,2 758549e8152SPaul Mackerras std r0,0(r4) 759549e8152SPaul Mackerras#endif 760549e8152SPaul Mackerras 761e31aa453SPaul Mackerras /* The following gets the stack set up with the regs */ 76214cf11afSPaul Mackerras /* pointing to the real addr of the kernel stack. This is */ 76314cf11afSPaul Mackerras /* all done to support the C function call below which sets */ 76414cf11afSPaul Mackerras /* up the htab. This is done because we have relocated the */ 76514cf11afSPaul Mackerras /* kernel but are still running in real mode. */ 76614cf11afSPaul Mackerras 767e31aa453SPaul Mackerras LOAD_REG_ADDR(r3,init_thread_union) 76814cf11afSPaul Mackerras 769e31aa453SPaul Mackerras /* set up a stack pointer */ 77014cf11afSPaul Mackerras addi r1,r3,THREAD_SIZE 77114cf11afSPaul Mackerras li r0,0 77214cf11afSPaul Mackerras stdu r0,-STACK_FRAME_OVERHEAD(r1) 77314cf11afSPaul Mackerras 774*376af594SMichael Ellerman /* 775*376af594SMichael Ellerman * Do very early kernel initializations, including initial hash table 776*376af594SMichael Ellerman * and SLB setup before we turn on relocation. 777*376af594SMichael Ellerman */ 77814cf11afSPaul Mackerras 77914cf11afSPaul Mackerras /* Restore parameters passed from prom_init/kexec */ 78014cf11afSPaul Mackerras mr r3,r31 781b1576fecSAnton Blanchard bl early_setup /* also sets r13 and SPRG_PACA */ 78214cf11afSPaul Mackerras 783ad0289e4SAnton Blanchard LOAD_REG_ADDR(r3, start_here_common) 784e31aa453SPaul Mackerras ld r4,PACAKMSR(r13) 785b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r3 786b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r4 7872d27cfd3SBenjamin Herrenschmidt RFI 78814cf11afSPaul Mackerras b . /* prevent speculative execution */ 78914cf11afSPaul Mackerras 79014cf11afSPaul Mackerras /* This is where all platforms converge execution */ 791ad0289e4SAnton Blanchard 792ad0289e4SAnton Blanchardstart_here_common: 79314cf11afSPaul Mackerras /* relocation is on at this point */ 79414cf11afSPaul Mackerras std r1,PACAKSAVE(r13) 79514cf11afSPaul Mackerras 796e31aa453SPaul Mackerras /* Load the TOC (virtual address) */ 797e31aa453SPaul Mackerras ld r2,PACATOC(r13) 798e31aa453SPaul Mackerras 7997230c564SBenjamin Herrenschmidt /* Do more system initializations in virtual mode */ 800b1576fecSAnton Blanchard bl setup_system 80114cf11afSPaul Mackerras 8027230c564SBenjamin Herrenschmidt /* Mark interrupts soft and hard disabled (they might be enabled 8037230c564SBenjamin Herrenschmidt * in the PACA when doing hotplug) 8047230c564SBenjamin Herrenschmidt */ 8057230c564SBenjamin Herrenschmidt li r0,0 8067230c564SBenjamin Herrenschmidt stb r0,PACASOFTIRQEN(r13) 8077230c564SBenjamin Herrenschmidt li r0,PACA_IRQ_HARD_DIS 8087230c564SBenjamin Herrenschmidt stb r0,PACAIRQHAPPENED(r13) 80914cf11afSPaul Mackerras 8107230c564SBenjamin Herrenschmidt /* Generic kernel entry */ 811b1576fecSAnton Blanchard bl start_kernel 81214cf11afSPaul Mackerras 813f1870f77SAnton Blanchard /* Not reached */ 814f1870f77SAnton Blanchard BUG_OPCODE 81514cf11afSPaul Mackerras 81614cf11afSPaul Mackerras/* 81714cf11afSPaul Mackerras * We put a few things here that have to be page-aligned. 81814cf11afSPaul Mackerras * This stuff goes at the beginning of the bss, which is page-aligned. 81914cf11afSPaul Mackerras */ 82014cf11afSPaul Mackerras .section ".bss" 82114cf11afSPaul Mackerras 82214cf11afSPaul Mackerras .align PAGE_SHIFT 82314cf11afSPaul Mackerras 82414cf11afSPaul Mackerras .globl empty_zero_page 82514cf11afSPaul Mackerrasempty_zero_page: 82614cf11afSPaul Mackerras .space PAGE_SIZE 82714cf11afSPaul Mackerras 82814cf11afSPaul Mackerras .globl swapper_pg_dir 82914cf11afSPaul Mackerrasswapper_pg_dir: 830ee7a76daSStephen Rothwell .space PGD_TABLE_SIZE 831