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> 436becef7eSchenhui zhao#include <asm/cputhreads.h> 44*7a25d912SScott Wood#include <asm/ppc-opcode.h> 4514cf11afSPaul Mackerras 4625985edcSLucas De Marchi/* The physical memory is laid out such that the secondary processor 470ebc4cdaSBenjamin Herrenschmidt * spin code sits at 0x0000...0x00ff. On server, the vectors follow 480ebc4cdaSBenjamin Herrenschmidt * using the layout described in exceptions-64s.S 4914cf11afSPaul Mackerras */ 5014cf11afSPaul Mackerras 5114cf11afSPaul Mackerras/* 5214cf11afSPaul Mackerras * Entering into this code we make the following assumptions: 530ebc4cdaSBenjamin Herrenschmidt * 540ebc4cdaSBenjamin Herrenschmidt * For pSeries or server processors: 5514cf11afSPaul Mackerras * 1. The MMU is off & open firmware is running in real mode. 5614cf11afSPaul Mackerras * 2. The kernel is entered at __start 5727f44888SBenjamin Herrenschmidt * -or- For OPAL entry: 5827f44888SBenjamin Herrenschmidt * 1. The MMU is off, processor in HV mode, primary CPU enters at 0 59daea1175SBenjamin Herrenschmidt * with device-tree in gpr3. We also get OPAL base in r8 and 60daea1175SBenjamin Herrenschmidt * entry in r9 for debugging purposes 6127f44888SBenjamin Herrenschmidt * 2. Secondary processors enter at 0x60 with PIR in gpr3 6214cf11afSPaul Mackerras * 630ebc4cdaSBenjamin Herrenschmidt * For Book3E processors: 640ebc4cdaSBenjamin Herrenschmidt * 1. The MMU is on running in AS0 in a state defined in ePAPR 650ebc4cdaSBenjamin Herrenschmidt * 2. The kernel is entered at __start 6614cf11afSPaul Mackerras */ 6714cf11afSPaul Mackerras 6814cf11afSPaul Mackerras .text 6914cf11afSPaul Mackerras .globl _stext 7014cf11afSPaul Mackerras_stext: 7114cf11afSPaul Mackerras_GLOBAL(__start) 7214cf11afSPaul Mackerras /* NOP this out unconditionally */ 7314cf11afSPaul MackerrasBEGIN_FTR_SECTION 745c0484e2SBenjamin Herrenschmidt FIXUP_ENDIAN 75b1576fecSAnton Blanchard b __start_initialization_multiplatform 7614cf11afSPaul MackerrasEND_FTR_SECTION(0, 1) 7714cf11afSPaul Mackerras 7814cf11afSPaul Mackerras /* Catch branch to 0 in real mode */ 7914cf11afSPaul Mackerras trap 8014cf11afSPaul Mackerras 812751b628SAnton Blanchard /* Secondary processors spin on this value until it becomes non-zero. 822751b628SAnton Blanchard * When non-zero, it contains the real address of the function the cpu 832751b628SAnton Blanchard * should jump to. 841f6a93e4SPaul Mackerras */ 857d4151b5SOlof Johansson .balign 8 8614cf11afSPaul Mackerras .globl __secondary_hold_spinloop 8714cf11afSPaul Mackerras__secondary_hold_spinloop: 8814cf11afSPaul Mackerras .llong 0x0 8914cf11afSPaul Mackerras 9014cf11afSPaul Mackerras /* Secondary processors write this value with their cpu # */ 9114cf11afSPaul Mackerras /* after they enter the spin loop immediately below. */ 9214cf11afSPaul Mackerras .globl __secondary_hold_acknowledge 9314cf11afSPaul Mackerras__secondary_hold_acknowledge: 9414cf11afSPaul Mackerras .llong 0x0 9514cf11afSPaul Mackerras 96928a3197SSonny Rao#ifdef CONFIG_RELOCATABLE 978b8b0cc1SMilton Miller /* This flag is set to 1 by a loader if the kernel should run 988b8b0cc1SMilton Miller * at the loaded address instead of the linked address. This 998b8b0cc1SMilton Miller * is used by kexec-tools to keep the the kdump kernel in the 1008b8b0cc1SMilton Miller * crash_kernel region. The loader is responsible for 1018b8b0cc1SMilton Miller * observing the alignment requirement. 1028b8b0cc1SMilton Miller */ 1038b8b0cc1SMilton Miller /* Do not move this variable as kexec-tools knows about it. */ 1048b8b0cc1SMilton Miller . = 0x5c 1058b8b0cc1SMilton Miller .globl __run_at_load 1068b8b0cc1SMilton Miller__run_at_load: 1078b8b0cc1SMilton Miller .long 0x72756e30 /* "run0" -- relocate to 0 by default */ 1088b8b0cc1SMilton Miller#endif 1098b8b0cc1SMilton Miller 11014cf11afSPaul Mackerras . = 0x60 11114cf11afSPaul Mackerras/* 11275423b7bSGeoff Levand * The following code is used to hold secondary processors 11375423b7bSGeoff Levand * in a spin loop after they have entered the kernel, but 11414cf11afSPaul Mackerras * before the bulk of the kernel has been relocated. This code 11514cf11afSPaul Mackerras * is relocated to physical address 0x60 before prom_init is run. 11614cf11afSPaul Mackerras * All of it must fit below the first exception vector at 0x100. 1171f6a93e4SPaul Mackerras * Use .globl here not _GLOBAL because we want __secondary_hold 1181f6a93e4SPaul Mackerras * to be the actual text address, not a descriptor. 11914cf11afSPaul Mackerras */ 1201f6a93e4SPaul Mackerras .globl __secondary_hold 1211f6a93e4SPaul Mackerras__secondary_hold: 1225c0484e2SBenjamin Herrenschmidt FIXUP_ENDIAN 1232d27cfd3SBenjamin Herrenschmidt#ifndef CONFIG_PPC_BOOK3E 12414cf11afSPaul Mackerras mfmsr r24 12514cf11afSPaul Mackerras ori r24,r24,MSR_RI 12614cf11afSPaul Mackerras mtmsrd r24 /* RI on */ 1272d27cfd3SBenjamin Herrenschmidt#endif 128f1870f77SAnton Blanchard /* Grab our physical cpu number */ 12914cf11afSPaul Mackerras mr r24,r3 13096f013feSJimi Xenidis /* stash r4 for book3e */ 13196f013feSJimi Xenidis mr r25,r4 13214cf11afSPaul Mackerras 13314cf11afSPaul Mackerras /* Tell the master cpu we're here */ 13414cf11afSPaul Mackerras /* Relocation is off & we are located at an address less */ 13514cf11afSPaul Mackerras /* than 0x100, so only need to grab low order offset. */ 136e31aa453SPaul Mackerras std r24,__secondary_hold_acknowledge-_stext(0) 13714cf11afSPaul Mackerras sync 13814cf11afSPaul Mackerras 13996f013feSJimi Xenidis li r26,0 14096f013feSJimi Xenidis#ifdef CONFIG_PPC_BOOK3E 14196f013feSJimi Xenidis tovirt(r26,r26) 14296f013feSJimi Xenidis#endif 14314cf11afSPaul Mackerras /* All secondary cpus wait here until told to start. */ 144cc7efbf9SAnton Blanchard100: ld r12,__secondary_hold_spinloop-_stext(r26) 145cc7efbf9SAnton Blanchard cmpdi 0,r12,0 1461f6a93e4SPaul Mackerras beq 100b 14714cf11afSPaul Mackerras 148f1870f77SAnton Blanchard#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC) 14996f013feSJimi Xenidis#ifdef CONFIG_PPC_BOOK3E 150cc7efbf9SAnton Blanchard tovirt(r12,r12) 15196f013feSJimi Xenidis#endif 152cc7efbf9SAnton Blanchard mtctr r12 15314cf11afSPaul Mackerras mr r3,r24 15496f013feSJimi Xenidis /* 15596f013feSJimi Xenidis * it may be the case that other platforms have r4 right to 15696f013feSJimi Xenidis * begin with, this gives us some safety in case it is not 15796f013feSJimi Xenidis */ 15896f013feSJimi Xenidis#ifdef CONFIG_PPC_BOOK3E 15996f013feSJimi Xenidis mr r4,r25 16096f013feSJimi Xenidis#else 1612d27cfd3SBenjamin Herrenschmidt li r4,0 16296f013feSJimi Xenidis#endif 163dd797738SBenjamin Herrenschmidt /* Make sure that patched code is visible */ 164dd797738SBenjamin Herrenschmidt isync 165758438a7SMichael Ellerman bctr 16614cf11afSPaul Mackerras#else 16714cf11afSPaul Mackerras BUG_OPCODE 16814cf11afSPaul Mackerras#endif 16914cf11afSPaul Mackerras 17014cf11afSPaul Mackerras/* This value is used to mark exception frames on the stack. */ 17114cf11afSPaul Mackerras .section ".toc","aw" 17214cf11afSPaul Mackerrasexception_marker: 17314cf11afSPaul Mackerras .tc ID_72656773_68657265[TC],0x7265677368657265 17414cf11afSPaul Mackerras .text 17514cf11afSPaul Mackerras 17614cf11afSPaul Mackerras/* 1770ebc4cdaSBenjamin Herrenschmidt * On server, we include the exception vectors code here as it 1780ebc4cdaSBenjamin Herrenschmidt * relies on absolute addressing which is only possible within 1790ebc4cdaSBenjamin Herrenschmidt * this compilation unit 18014cf11afSPaul Mackerras */ 1810ebc4cdaSBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3S 1820ebc4cdaSBenjamin Herrenschmidt#include "exceptions-64s.S" 1831f6a93e4SPaul Mackerras#endif 18414cf11afSPaul Mackerras 185e16c8765SAndy Fleming#ifdef CONFIG_PPC_BOOK3E 186d17799f9Schenhui zhao/* 1876becef7eSchenhui zhao * The booting_thread_hwid holds the thread id we want to boot in cpu 1886becef7eSchenhui zhao * hotplug case. It is set by cpu hotplug code, and is invalid by default. 1896becef7eSchenhui zhao * The thread id is the same as the initial value of SPRN_PIR[THREAD_ID] 1906becef7eSchenhui zhao * bit field. 1916becef7eSchenhui zhao */ 1926becef7eSchenhui zhao .globl booting_thread_hwid 1936becef7eSchenhui zhaobooting_thread_hwid: 1946becef7eSchenhui zhao .long INVALID_THREAD_HWID 1956becef7eSchenhui zhao .align 3 1966becef7eSchenhui zhao/* 1976becef7eSchenhui zhao * start a thread in the same core 1986becef7eSchenhui zhao * input parameters: 1996becef7eSchenhui zhao * r3 = the thread physical id 2006becef7eSchenhui zhao * r4 = the entry point where thread starts 2016becef7eSchenhui zhao */ 2026becef7eSchenhui zhao_GLOBAL(book3e_start_thread) 2036becef7eSchenhui zhao LOAD_REG_IMMEDIATE(r5, MSR_KERNEL) 2046becef7eSchenhui zhao cmpi 0, r3, 0 2056becef7eSchenhui zhao beq 10f 2066becef7eSchenhui zhao cmpi 0, r3, 1 2076becef7eSchenhui zhao beq 11f 2086becef7eSchenhui zhao /* If the thread id is invalid, just exit. */ 2096becef7eSchenhui zhao b 13f 2106becef7eSchenhui zhao10: 211*7a25d912SScott Wood MTTMR(TMRN_IMSR0, 5) 212*7a25d912SScott Wood MTTMR(TMRN_INIA0, 4) 2136becef7eSchenhui zhao b 12f 2146becef7eSchenhui zhao11: 215*7a25d912SScott Wood MTTMR(TMRN_IMSR1, 5) 216*7a25d912SScott Wood MTTMR(TMRN_INIA1, 4) 2176becef7eSchenhui zhao12: 2186becef7eSchenhui zhao isync 2196becef7eSchenhui zhao li r6, 1 2206becef7eSchenhui zhao sld r6, r6, r3 2216becef7eSchenhui zhao mtspr SPRN_TENS, r6 2226becef7eSchenhui zhao13: 2236becef7eSchenhui zhao blr 2246becef7eSchenhui zhao 2256becef7eSchenhui zhao/* 226d17799f9Schenhui zhao * stop a thread in the same core 227d17799f9Schenhui zhao * input parameter: 228d17799f9Schenhui zhao * r3 = the thread physical id 229d17799f9Schenhui zhao */ 230d17799f9Schenhui zhao_GLOBAL(book3e_stop_thread) 231d17799f9Schenhui zhao cmpi 0, r3, 0 232d17799f9Schenhui zhao beq 10f 233d17799f9Schenhui zhao cmpi 0, r3, 1 234d17799f9Schenhui zhao beq 10f 235d17799f9Schenhui zhao /* If the thread id is invalid, just exit. */ 236d17799f9Schenhui zhao b 13f 237d17799f9Schenhui zhao10: 238d17799f9Schenhui zhao li r4, 1 239d17799f9Schenhui zhao sld r4, r4, r3 240d17799f9Schenhui zhao mtspr SPRN_TENC, r4 241d17799f9Schenhui zhao13: 242d17799f9Schenhui zhao blr 243d17799f9Schenhui zhao 244e16c8765SAndy Fleming_GLOBAL(fsl_secondary_thread_init) 245f34b3e19SScott Wood mfspr r4,SPRN_BUCSR 246f34b3e19SScott Wood 247e16c8765SAndy Fleming /* Enable branch prediction */ 248e16c8765SAndy Fleming lis r3,BUCSR_INIT@h 249e16c8765SAndy Fleming ori r3,r3,BUCSR_INIT@l 250e16c8765SAndy Fleming mtspr SPRN_BUCSR,r3 251e16c8765SAndy Fleming isync 252e16c8765SAndy Fleming 253e16c8765SAndy Fleming /* 254e16c8765SAndy Fleming * Fix PIR to match the linear numbering in the device tree. 255e16c8765SAndy Fleming * 256e16c8765SAndy Fleming * On e6500, the reset value of PIR uses the low three bits for 257e16c8765SAndy Fleming * the thread within a core, and the upper bits for the core 258e16c8765SAndy Fleming * number. There are two threads per core, so shift everything 259e16c8765SAndy Fleming * but the low bit right by two bits so that the cpu numbering is 260e16c8765SAndy Fleming * continuous. 261f34b3e19SScott Wood * 262f34b3e19SScott Wood * If the old value of BUCSR is non-zero, this thread has run 263f34b3e19SScott Wood * before. Thus, we assume we are coming from kexec or a similar 264f34b3e19SScott Wood * scenario, and PIR is already set to the correct value. This 265f34b3e19SScott Wood * is a bit of a hack, but there are limited opportunities for 266f34b3e19SScott Wood * getting information into the thread and the alternatives 267f34b3e19SScott Wood * seemed like they'd be overkill. We can't tell just by looking 268f34b3e19SScott Wood * at the old PIR value which state it's in, since the same value 269f34b3e19SScott Wood * could be valid for one thread out of reset and for a different 270f34b3e19SScott Wood * thread in Linux. 271e16c8765SAndy Fleming */ 272f34b3e19SScott Wood 273e16c8765SAndy Fleming mfspr r3, SPRN_PIR 274f34b3e19SScott Wood cmpwi r4,0 275f34b3e19SScott Wood bne 1f 276e16c8765SAndy Fleming rlwimi r3, r3, 30, 2, 30 277e16c8765SAndy Fleming mtspr SPRN_PIR, r3 278f34b3e19SScott Wood1: 279e16c8765SAndy Fleming#endif 280e16c8765SAndy Fleming 2812d27cfd3SBenjamin Herrenschmidt_GLOBAL(generic_secondary_thread_init) 28214cf11afSPaul Mackerras mr r24,r3 28314cf11afSPaul Mackerras 28414cf11afSPaul Mackerras /* turn on 64-bit mode */ 285b1576fecSAnton Blanchard bl enable_64b_mode 28614cf11afSPaul Mackerras 2872d27cfd3SBenjamin Herrenschmidt /* get a valid TOC pointer, wherever we're mapped at */ 288b1576fecSAnton Blanchard bl relative_toc 2891fbe9cf2SAnton Blanchard tovirt(r2,r2) 290e31aa453SPaul Mackerras 2912d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 2922d27cfd3SBenjamin Herrenschmidt /* Book3E initialization */ 2932d27cfd3SBenjamin Herrenschmidt mr r3,r24 294b1576fecSAnton Blanchard bl book3e_secondary_thread_init 2952d27cfd3SBenjamin Herrenschmidt#endif 2962d27cfd3SBenjamin Herrenschmidt b generic_secondary_common_init 2972d27cfd3SBenjamin Herrenschmidt 2982d27cfd3SBenjamin Herrenschmidt/* 2992d27cfd3SBenjamin Herrenschmidt * On pSeries and most other platforms, secondary processors spin 3002d27cfd3SBenjamin Herrenschmidt * in the following code. 3012d27cfd3SBenjamin Herrenschmidt * At entry, r3 = this processor's number (physical cpu id) 3022d27cfd3SBenjamin Herrenschmidt * 3032d27cfd3SBenjamin Herrenschmidt * On Book3E, r4 = 1 to indicate that the initial TLB entry for 3042d27cfd3SBenjamin Herrenschmidt * this core already exists (setup via some other mechanism such 3052d27cfd3SBenjamin Herrenschmidt * as SCOM before entry). 3062d27cfd3SBenjamin Herrenschmidt */ 3072d27cfd3SBenjamin Herrenschmidt_GLOBAL(generic_secondary_smp_init) 3085c0484e2SBenjamin Herrenschmidt FIXUP_ENDIAN 3092d27cfd3SBenjamin Herrenschmidt mr r24,r3 3102d27cfd3SBenjamin Herrenschmidt mr r25,r4 3112d27cfd3SBenjamin Herrenschmidt 3122d27cfd3SBenjamin Herrenschmidt /* turn on 64-bit mode */ 313b1576fecSAnton Blanchard bl enable_64b_mode 3142d27cfd3SBenjamin Herrenschmidt 3152d27cfd3SBenjamin Herrenschmidt /* get a valid TOC pointer, wherever we're mapped at */ 316b1576fecSAnton Blanchard bl relative_toc 3171fbe9cf2SAnton Blanchard tovirt(r2,r2) 3182d27cfd3SBenjamin Herrenschmidt 3192d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 3202d27cfd3SBenjamin Herrenschmidt /* Book3E initialization */ 3212d27cfd3SBenjamin Herrenschmidt mr r3,r24 3222d27cfd3SBenjamin Herrenschmidt mr r4,r25 323b1576fecSAnton Blanchard bl book3e_secondary_core_init 3246becef7eSchenhui zhao 3256becef7eSchenhui zhao/* 3266becef7eSchenhui zhao * After common core init has finished, check if the current thread is the 3276becef7eSchenhui zhao * one we wanted to boot. If not, start the specified thread and stop the 3286becef7eSchenhui zhao * current thread. 3296becef7eSchenhui zhao */ 3306becef7eSchenhui zhao LOAD_REG_ADDR(r4, booting_thread_hwid) 3316becef7eSchenhui zhao lwz r3, 0(r4) 3326becef7eSchenhui zhao li r5, INVALID_THREAD_HWID 3336becef7eSchenhui zhao cmpw r3, r5 3346becef7eSchenhui zhao beq 20f 3356becef7eSchenhui zhao 3366becef7eSchenhui zhao /* 3376becef7eSchenhui zhao * The value of booting_thread_hwid has been stored in r3, 3386becef7eSchenhui zhao * so make it invalid. 3396becef7eSchenhui zhao */ 3406becef7eSchenhui zhao stw r5, 0(r4) 3416becef7eSchenhui zhao 3426becef7eSchenhui zhao /* 3436becef7eSchenhui zhao * Get the current thread id and check if it is the one we wanted. 3446becef7eSchenhui zhao * If not, start the one specified in booting_thread_hwid and stop 3456becef7eSchenhui zhao * the current thread. 3466becef7eSchenhui zhao */ 3476becef7eSchenhui zhao mfspr r8, SPRN_TIR 3486becef7eSchenhui zhao cmpw r3, r8 3496becef7eSchenhui zhao beq 20f 3506becef7eSchenhui zhao 3516becef7eSchenhui zhao /* start the specified thread */ 3526becef7eSchenhui zhao LOAD_REG_ADDR(r5, fsl_secondary_thread_init) 3536becef7eSchenhui zhao ld r4, 0(r5) 3546becef7eSchenhui zhao bl book3e_start_thread 3556becef7eSchenhui zhao 3566becef7eSchenhui zhao /* stop the current thread */ 3576becef7eSchenhui zhao mr r3, r8 3586becef7eSchenhui zhao bl book3e_stop_thread 3596becef7eSchenhui zhao10: 3606becef7eSchenhui zhao b 10b 3616becef7eSchenhui zhao20: 3622d27cfd3SBenjamin Herrenschmidt#endif 3632d27cfd3SBenjamin Herrenschmidt 3642d27cfd3SBenjamin Herrenschmidtgeneric_secondary_common_init: 36514cf11afSPaul Mackerras /* Set up a paca value for this processor. Since we have the 36614cf11afSPaul Mackerras * physical cpu id in r24, we need to search the pacas to find 36714cf11afSPaul Mackerras * which logical id maps to our physical one. 36814cf11afSPaul Mackerras */ 3691426d5a3SMichael Ellerman LOAD_REG_ADDR(r13, paca) /* Load paca pointer */ 3701426d5a3SMichael Ellerman ld r13,0(r13) /* Get base vaddr of paca array */ 371768d18adSMilton Miller#ifndef CONFIG_SMP 372768d18adSMilton Miller addi r13,r13,PACA_SIZE /* know r13 if used accidentally */ 373b1576fecSAnton Blanchard b kexec_wait /* wait for next kernel if !SMP */ 374768d18adSMilton Miller#else 375768d18adSMilton Miller LOAD_REG_ADDR(r7, nr_cpu_ids) /* Load nr_cpu_ids address */ 376768d18adSMilton Miller lwz r7,0(r7) /* also the max paca allocated */ 37714cf11afSPaul Mackerras li r5,0 /* logical cpu id */ 37814cf11afSPaul Mackerras1: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */ 37914cf11afSPaul Mackerras cmpw r6,r24 /* Compare to our id */ 38014cf11afSPaul Mackerras beq 2f 38114cf11afSPaul Mackerras addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */ 38214cf11afSPaul Mackerras addi r5,r5,1 383768d18adSMilton Miller cmpw r5,r7 /* Check if more pacas exist */ 38414cf11afSPaul Mackerras blt 1b 38514cf11afSPaul Mackerras 38614cf11afSPaul Mackerras mr r3,r24 /* not found, copy phys to r3 */ 387b1576fecSAnton Blanchard b kexec_wait /* next kernel might do better */ 38814cf11afSPaul Mackerras 3892dd60d79SBenjamin Herrenschmidt2: SET_PACA(r13) 3902d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 3912d27cfd3SBenjamin Herrenschmidt addi r12,r13,PACA_EXTLB /* and TLB exc frame in another */ 3922d27cfd3SBenjamin Herrenschmidt mtspr SPRN_SPRG_TLB_EXFRAME,r12 3932d27cfd3SBenjamin Herrenschmidt#endif 3942d27cfd3SBenjamin Herrenschmidt 39514cf11afSPaul Mackerras /* From now on, r24 is expected to be logical cpuid */ 39614cf11afSPaul Mackerras mr r24,r5 397b6f6b98aSSonny Rao 398f39b7a55SOlof Johansson /* See if we need to call a cpu state restore handler */ 399e31aa453SPaul Mackerras LOAD_REG_ADDR(r23, cur_cpu_spec) 400f39b7a55SOlof Johansson ld r23,0(r23) 4012751b628SAnton Blanchard ld r12,CPU_SPEC_RESTORE(r23) 4022751b628SAnton Blanchard cmpdi 0,r12,0 4039d07bc84SBenjamin Herrenschmidt beq 3f 4042751b628SAnton Blanchard#if !defined(_CALL_ELF) || _CALL_ELF != 2 4052751b628SAnton Blanchard ld r12,0(r12) 4062751b628SAnton Blanchard#endif 407cc7efbf9SAnton Blanchard mtctr r12 408f39b7a55SOlof Johansson bctrl 409f39b7a55SOlof Johansson 4107ac87abbSMatt Evans3: LOAD_REG_ADDR(r3, spinning_secondaries) /* Decrement spinning_secondaries */ 4119d07bc84SBenjamin Herrenschmidt lwarx r4,0,r3 4129d07bc84SBenjamin Herrenschmidt subi r4,r4,1 4139d07bc84SBenjamin Herrenschmidt stwcx. r4,0,r3 4149d07bc84SBenjamin Herrenschmidt bne 3b 4159d07bc84SBenjamin Herrenschmidt isync 4169d07bc84SBenjamin Herrenschmidt 4179d07bc84SBenjamin Herrenschmidt4: HMT_LOW 418ad0693eeSBenjamin Herrenschmidt lbz r23,PACAPROCSTART(r13) /* Test if this processor should */ 419ad0693eeSBenjamin Herrenschmidt /* start. */ 420ad0693eeSBenjamin Herrenschmidt cmpwi 0,r23,0 4219d07bc84SBenjamin Herrenschmidt beq 4b /* Loop until told to go */ 422ad0693eeSBenjamin Herrenschmidt 423ad0693eeSBenjamin Herrenschmidt sync /* order paca.run and cur_cpu_spec */ 4249d07bc84SBenjamin Herrenschmidt isync /* In case code patching happened */ 425ad0693eeSBenjamin Herrenschmidt 4269d07bc84SBenjamin Herrenschmidt /* Create a temp kernel stack for use before relocation is on. */ 42714cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 42814cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 42914cf11afSPaul Mackerras 430c705677eSStephen Rothwell b __secondary_start 431768d18adSMilton Miller#endif /* SMP */ 43214cf11afSPaul Mackerras 433e31aa453SPaul Mackerras/* 434e31aa453SPaul Mackerras * Turn the MMU off. 435e31aa453SPaul Mackerras * Assumes we're mapped EA == RA if the MMU is on. 436e31aa453SPaul Mackerras */ 4372d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3S 4386a3bab90SAnton Blanchard__mmu_off: 43914cf11afSPaul Mackerras mfmsr r3 44014cf11afSPaul Mackerras andi. r0,r3,MSR_IR|MSR_DR 44114cf11afSPaul Mackerras beqlr 442e31aa453SPaul Mackerras mflr r4 44314cf11afSPaul Mackerras andc r3,r3,r0 44414cf11afSPaul Mackerras mtspr SPRN_SRR0,r4 44514cf11afSPaul Mackerras mtspr SPRN_SRR1,r3 44614cf11afSPaul Mackerras sync 44714cf11afSPaul Mackerras rfid 44814cf11afSPaul Mackerras b . /* prevent speculative execution */ 4492d27cfd3SBenjamin Herrenschmidt#endif 45014cf11afSPaul Mackerras 45114cf11afSPaul Mackerras 45214cf11afSPaul Mackerras/* 45314cf11afSPaul Mackerras * Here is our main kernel entry point. We support currently 2 kind of entries 45414cf11afSPaul Mackerras * depending on the value of r5. 45514cf11afSPaul Mackerras * 45614cf11afSPaul Mackerras * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content 45714cf11afSPaul Mackerras * in r3...r7 45814cf11afSPaul Mackerras * 45914cf11afSPaul Mackerras * r5 == NULL -> kexec style entry. r3 is a physical pointer to the 46014cf11afSPaul Mackerras * DT block, r4 is a physical pointer to the kernel itself 46114cf11afSPaul Mackerras * 46214cf11afSPaul Mackerras */ 4636a3bab90SAnton Blanchard__start_initialization_multiplatform: 464e31aa453SPaul Mackerras /* Make sure we are running in 64 bits mode */ 465b1576fecSAnton Blanchard bl enable_64b_mode 466e31aa453SPaul Mackerras 467e31aa453SPaul Mackerras /* Get TOC pointer (current runtime address) */ 468b1576fecSAnton Blanchard bl relative_toc 469e31aa453SPaul Mackerras 470e31aa453SPaul Mackerras /* find out where we are now */ 471e31aa453SPaul Mackerras bcl 20,31,$+4 472e31aa453SPaul Mackerras0: mflr r26 /* r26 = runtime addr here */ 473e31aa453SPaul Mackerras addis r26,r26,(_stext - 0b)@ha 474e31aa453SPaul Mackerras addi r26,r26,(_stext - 0b)@l /* current runtime base addr */ 475e31aa453SPaul Mackerras 47614cf11afSPaul Mackerras /* 47714cf11afSPaul Mackerras * Are we booted from a PROM Of-type client-interface ? 47814cf11afSPaul Mackerras */ 47914cf11afSPaul Mackerras cmpldi cr0,r5,0 480939e60f6SStephen Rothwell beq 1f 481b1576fecSAnton Blanchard b __boot_from_prom /* yes -> prom */ 482939e60f6SStephen Rothwell1: 48314cf11afSPaul Mackerras /* Save parameters */ 48414cf11afSPaul Mackerras mr r31,r3 48514cf11afSPaul Mackerras mr r30,r4 486daea1175SBenjamin Herrenschmidt#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL 487daea1175SBenjamin Herrenschmidt /* Save OPAL entry */ 488daea1175SBenjamin Herrenschmidt mr r28,r8 489daea1175SBenjamin Herrenschmidt mr r29,r9 490daea1175SBenjamin Herrenschmidt#endif 49114cf11afSPaul Mackerras 4922d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 493b1576fecSAnton Blanchard bl start_initialization_book3e 494b1576fecSAnton Blanchard b __after_prom_start 4952d27cfd3SBenjamin Herrenschmidt#else 49614cf11afSPaul Mackerras /* Setup some critical 970 SPRs before switching MMU off */ 497f39b7a55SOlof Johansson mfspr r0,SPRN_PVR 498f39b7a55SOlof Johansson srwi r0,r0,16 499f39b7a55SOlof Johansson cmpwi r0,0x39 /* 970 */ 500f39b7a55SOlof Johansson beq 1f 501f39b7a55SOlof Johansson cmpwi r0,0x3c /* 970FX */ 502f39b7a55SOlof Johansson beq 1f 503f39b7a55SOlof Johansson cmpwi r0,0x44 /* 970MP */ 504190a24f5SOlof Johansson beq 1f 505190a24f5SOlof Johansson cmpwi r0,0x45 /* 970GX */ 506f39b7a55SOlof Johansson bne 2f 507b1576fecSAnton Blanchard1: bl __cpu_preinit_ppc970 508f39b7a55SOlof Johansson2: 50914cf11afSPaul Mackerras 510e31aa453SPaul Mackerras /* Switch off MMU if not already off */ 511b1576fecSAnton Blanchard bl __mmu_off 512b1576fecSAnton Blanchard b __after_prom_start 5132d27cfd3SBenjamin Herrenschmidt#endif /* CONFIG_PPC_BOOK3E */ 51414cf11afSPaul Mackerras 5156a3bab90SAnton Blanchard__boot_from_prom: 51628794d34SBenjamin Herrenschmidt#ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE 51714cf11afSPaul Mackerras /* Save parameters */ 51814cf11afSPaul Mackerras mr r31,r3 51914cf11afSPaul Mackerras mr r30,r4 52014cf11afSPaul Mackerras mr r29,r5 52114cf11afSPaul Mackerras mr r28,r6 52214cf11afSPaul Mackerras mr r27,r7 52314cf11afSPaul Mackerras 5246088857bSOlaf Hering /* 5256088857bSOlaf Hering * Align the stack to 16-byte boundary 5266088857bSOlaf Hering * Depending on the size and layout of the ELF sections in the initial 527e31aa453SPaul Mackerras * boot binary, the stack pointer may be unaligned on PowerMac 5286088857bSOlaf Hering */ 529c05b4770SLinus Torvalds rldicr r1,r1,0,59 530c05b4770SLinus Torvalds 531549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 532549e8152SPaul Mackerras /* Relocate code for where we are now */ 533549e8152SPaul Mackerras mr r3,r26 534b1576fecSAnton Blanchard bl relocate 535549e8152SPaul Mackerras#endif 536549e8152SPaul Mackerras 53714cf11afSPaul Mackerras /* Restore parameters */ 53814cf11afSPaul Mackerras mr r3,r31 53914cf11afSPaul Mackerras mr r4,r30 54014cf11afSPaul Mackerras mr r5,r29 54114cf11afSPaul Mackerras mr r6,r28 54214cf11afSPaul Mackerras mr r7,r27 54314cf11afSPaul Mackerras 54414cf11afSPaul Mackerras /* Do all of the interaction with OF client interface */ 545549e8152SPaul Mackerras mr r8,r26 546b1576fecSAnton Blanchard bl prom_init 54728794d34SBenjamin Herrenschmidt#endif /* #CONFIG_PPC_OF_BOOT_TRAMPOLINE */ 54828794d34SBenjamin Herrenschmidt 54928794d34SBenjamin Herrenschmidt /* We never return. We also hit that trap if trying to boot 55028794d34SBenjamin Herrenschmidt * from OF while CONFIG_PPC_OF_BOOT_TRAMPOLINE isn't selected */ 55114cf11afSPaul Mackerras trap 55214cf11afSPaul Mackerras 5536a3bab90SAnton Blanchard__after_prom_start: 554549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 555549e8152SPaul Mackerras /* process relocations for the final address of the kernel */ 556549e8152SPaul Mackerras lis r25,PAGE_OFFSET@highest /* compute virtual base of kernel */ 557549e8152SPaul Mackerras sldi r25,r25,32 5581cb6e064STiejun Chen#if defined(CONFIG_PPC_BOOK3E) 5591cb6e064STiejun Chen tovirt(r26,r26) /* on booke, we already run at PAGE_OFFSET */ 5601cb6e064STiejun Chen#endif 5618b8b0cc1SMilton Miller lwz r7,__run_at_load-_stext(r26) 5621cb6e064STiejun Chen#if defined(CONFIG_PPC_BOOK3E) 5631cb6e064STiejun Chen tophys(r26,r26) 5641cb6e064STiejun Chen#endif 565928a3197SSonny Rao cmplwi cr0,r7,1 /* flagged to stay where we are ? */ 56654622f10SMohan Kumar M bne 1f 56754622f10SMohan Kumar M add r25,r25,r26 56854622f10SMohan Kumar M1: mr r3,r25 569b1576fecSAnton Blanchard bl relocate 5701cb6e064STiejun Chen#if defined(CONFIG_PPC_BOOK3E) 5711cb6e064STiejun Chen /* IVPR needs to be set after relocation. */ 5721cb6e064STiejun Chen bl init_core_book3e 5731cb6e064STiejun Chen#endif 574549e8152SPaul Mackerras#endif 57514cf11afSPaul Mackerras 57614cf11afSPaul Mackerras/* 577e31aa453SPaul Mackerras * We need to run with _stext at physical address PHYSICAL_START. 57814cf11afSPaul Mackerras * This will leave some code in the first 256B of 57914cf11afSPaul Mackerras * real memory, which are reserved for software use. 58014cf11afSPaul Mackerras * 58114cf11afSPaul Mackerras * Note: This process overwrites the OF exception vectors. 58214cf11afSPaul Mackerras */ 583549e8152SPaul Mackerras li r3,0 /* target addr */ 5842d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 5852d27cfd3SBenjamin Herrenschmidt tovirt(r3,r3) /* on booke, we already run at PAGE_OFFSET */ 5862d27cfd3SBenjamin Herrenschmidt#endif 587549e8152SPaul Mackerras mr. r4,r26 /* In some cases the loader may */ 588835c031cSTiejun Chen#if defined(CONFIG_PPC_BOOK3E) 589835c031cSTiejun Chen tovirt(r4,r4) 590835c031cSTiejun Chen#endif 591e31aa453SPaul Mackerras beq 9f /* have already put us at zero */ 59214cf11afSPaul Mackerras li r6,0x100 /* Start offset, the first 0x100 */ 59314cf11afSPaul Mackerras /* bytes were copied earlier. */ 59414cf11afSPaul Mackerras 59511ee7e99SAnton Blanchard#ifdef CONFIG_RELOCATABLE 59654622f10SMohan Kumar M/* 59754622f10SMohan Kumar M * Check if the kernel has to be running as relocatable kernel based on the 5988b8b0cc1SMilton Miller * variable __run_at_load, if it is set the kernel is treated as relocatable 59954622f10SMohan Kumar M * kernel, otherwise it will be moved to PHYSICAL_START 60054622f10SMohan Kumar M */ 6011cb6e064STiejun Chen#if defined(CONFIG_PPC_BOOK3E) 6021cb6e064STiejun Chen tovirt(r26,r26) /* on booke, we already run at PAGE_OFFSET */ 6031cb6e064STiejun Chen#endif 6048b8b0cc1SMilton Miller lwz r7,__run_at_load-_stext(r26) 6058b8b0cc1SMilton Miller cmplwi cr0,r7,1 60654622f10SMohan Kumar M bne 3f 60754622f10SMohan Kumar M 6081cb6e064STiejun Chen#ifdef CONFIG_PPC_BOOK3E 6091cb6e064STiejun Chen LOAD_REG_ADDR(r5, __end_interrupts) 6101cb6e064STiejun Chen LOAD_REG_ADDR(r11, _stext) 6111cb6e064STiejun Chen sub r5,r5,r11 6121cb6e064STiejun Chen#else 613c1fb6816SMichael Neuling /* just copy interrupts */ 614c1fb6816SMichael Neuling LOAD_REG_IMMEDIATE(r5, __end_interrupts - _stext) 6151cb6e064STiejun Chen#endif 61654622f10SMohan Kumar M b 5f 61754622f10SMohan Kumar M3: 61854622f10SMohan Kumar M#endif 61954622f10SMohan Kumar M lis r5,(copy_to_here - _stext)@ha 62054622f10SMohan Kumar M addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */ 62154622f10SMohan Kumar M 622b1576fecSAnton Blanchard bl copy_and_flush /* copy the first n bytes */ 62314cf11afSPaul Mackerras /* this includes the code being */ 62414cf11afSPaul Mackerras /* executed here. */ 625e31aa453SPaul Mackerras addis r8,r3,(4f - _stext)@ha /* Jump to the copy of this code */ 626cc7efbf9SAnton Blanchard addi r12,r8,(4f - _stext)@l /* that we just made */ 627cc7efbf9SAnton Blanchard mtctr r12 62814cf11afSPaul Mackerras bctr 62914cf11afSPaul Mackerras 630286e4f90SAnton Blanchard.balign 8 63154622f10SMohan Kumar Mp_end: .llong _end - _stext 63254622f10SMohan Kumar M 633e31aa453SPaul Mackerras4: /* Now copy the rest of the kernel up to _end */ 634e31aa453SPaul Mackerras addis r5,r26,(p_end - _stext)@ha 635e31aa453SPaul Mackerras ld r5,(p_end - _stext)@l(r5) /* get _end */ 636b1576fecSAnton Blanchard5: bl copy_and_flush /* copy the rest */ 637e31aa453SPaul Mackerras 638b1576fecSAnton Blanchard9: b start_here_multiplatform 639e31aa453SPaul Mackerras 64014cf11afSPaul Mackerras/* 64114cf11afSPaul Mackerras * Copy routine used to copy the kernel to start at physical address 0 64214cf11afSPaul Mackerras * and flush and invalidate the caches as needed. 64314cf11afSPaul Mackerras * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset 64414cf11afSPaul Mackerras * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5. 64514cf11afSPaul Mackerras * 64614cf11afSPaul Mackerras * Note: this routine *only* clobbers r0, r6 and lr 64714cf11afSPaul Mackerras */ 64814cf11afSPaul Mackerras_GLOBAL(copy_and_flush) 64914cf11afSPaul Mackerras addi r5,r5,-8 65014cf11afSPaul Mackerras addi r6,r6,-8 6515a2fe38dSOlof Johansson4: li r0,8 /* Use the smallest common */ 65214cf11afSPaul Mackerras /* denominator cache line */ 65314cf11afSPaul Mackerras /* size. This results in */ 65414cf11afSPaul Mackerras /* extra cache line flushes */ 65514cf11afSPaul Mackerras /* but operation is correct. */ 65614cf11afSPaul Mackerras /* Can't get cache line size */ 65714cf11afSPaul Mackerras /* from NACA as it is being */ 65814cf11afSPaul Mackerras /* moved too. */ 65914cf11afSPaul Mackerras 66014cf11afSPaul Mackerras mtctr r0 /* put # words/line in ctr */ 66114cf11afSPaul Mackerras3: addi r6,r6,8 /* copy a cache line */ 66214cf11afSPaul Mackerras ldx r0,r6,r4 66314cf11afSPaul Mackerras stdx r0,r6,r3 66414cf11afSPaul Mackerras bdnz 3b 66514cf11afSPaul Mackerras dcbst r6,r3 /* write it to memory */ 66614cf11afSPaul Mackerras sync 66714cf11afSPaul Mackerras icbi r6,r3 /* flush the icache line */ 66814cf11afSPaul Mackerras cmpld 0,r6,r5 66914cf11afSPaul Mackerras blt 4b 67014cf11afSPaul Mackerras sync 67114cf11afSPaul Mackerras addi r5,r5,8 67214cf11afSPaul Mackerras addi r6,r6,8 67329ce3c50SMichael Neuling isync 67414cf11afSPaul Mackerras blr 67514cf11afSPaul Mackerras 67614cf11afSPaul Mackerras.align 8 67714cf11afSPaul Mackerrascopy_to_here: 67814cf11afSPaul Mackerras 67914cf11afSPaul Mackerras#ifdef CONFIG_SMP 68014cf11afSPaul Mackerras#ifdef CONFIG_PPC_PMAC 68114cf11afSPaul Mackerras/* 68214cf11afSPaul Mackerras * On PowerMac, secondary processors starts from the reset vector, which 68314cf11afSPaul Mackerras * is temporarily turned into a call to one of the functions below. 68414cf11afSPaul Mackerras */ 68514cf11afSPaul Mackerras .section ".text"; 68614cf11afSPaul Mackerras .align 2 ; 68714cf11afSPaul Mackerras 68835499c01SPaul Mackerras .globl __secondary_start_pmac_0 68935499c01SPaul Mackerras__secondary_start_pmac_0: 69035499c01SPaul Mackerras /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */ 69135499c01SPaul Mackerras li r24,0 69235499c01SPaul Mackerras b 1f 69314cf11afSPaul Mackerras li r24,1 69435499c01SPaul Mackerras b 1f 69514cf11afSPaul Mackerras li r24,2 69635499c01SPaul Mackerras b 1f 69714cf11afSPaul Mackerras li r24,3 69835499c01SPaul Mackerras1: 69914cf11afSPaul Mackerras 70014cf11afSPaul Mackerras_GLOBAL(pmac_secondary_start) 70114cf11afSPaul Mackerras /* turn on 64-bit mode */ 702b1576fecSAnton Blanchard bl enable_64b_mode 70314cf11afSPaul Mackerras 704c478b581SBenjamin Herrenschmidt li r0,0 705c478b581SBenjamin Herrenschmidt mfspr r3,SPRN_HID4 706c478b581SBenjamin Herrenschmidt rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */ 707c478b581SBenjamin Herrenschmidt sync 708c478b581SBenjamin Herrenschmidt mtspr SPRN_HID4,r3 709c478b581SBenjamin Herrenschmidt isync 710c478b581SBenjamin Herrenschmidt sync 711c478b581SBenjamin Herrenschmidt slbia 712c478b581SBenjamin Herrenschmidt 713e31aa453SPaul Mackerras /* get TOC pointer (real address) */ 714b1576fecSAnton Blanchard bl relative_toc 7151fbe9cf2SAnton Blanchard tovirt(r2,r2) 716e31aa453SPaul Mackerras 71714cf11afSPaul Mackerras /* Copy some CPU settings from CPU 0 */ 718b1576fecSAnton Blanchard bl __restore_cpu_ppc970 71914cf11afSPaul Mackerras 72014cf11afSPaul Mackerras /* pSeries do that early though I don't think we really need it */ 72114cf11afSPaul Mackerras mfmsr r3 72214cf11afSPaul Mackerras ori r3,r3,MSR_RI 72314cf11afSPaul Mackerras mtmsrd r3 /* RI on */ 72414cf11afSPaul Mackerras 72514cf11afSPaul Mackerras /* Set up a paca value for this processor. */ 7261426d5a3SMichael Ellerman LOAD_REG_ADDR(r4,paca) /* Load paca pointer */ 7271426d5a3SMichael Ellerman ld r4,0(r4) /* Get base vaddr of paca array */ 72814cf11afSPaul Mackerras mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */ 72914cf11afSPaul Mackerras add r13,r13,r4 /* for this processor. */ 7302dd60d79SBenjamin Herrenschmidt SET_PACA(r13) /* Save vaddr of paca in an SPRG*/ 73114cf11afSPaul Mackerras 73262cc67b9SBenjamin Herrenschmidt /* Mark interrupts soft and hard disabled (they might be enabled 73362cc67b9SBenjamin Herrenschmidt * in the PACA when doing hotplug) 73462cc67b9SBenjamin Herrenschmidt */ 73562cc67b9SBenjamin Herrenschmidt li r0,0 73662cc67b9SBenjamin Herrenschmidt stb r0,PACASOFTIRQEN(r13) 7377230c564SBenjamin Herrenschmidt li r0,PACA_IRQ_HARD_DIS 7387230c564SBenjamin Herrenschmidt stb r0,PACAIRQHAPPENED(r13) 73962cc67b9SBenjamin Herrenschmidt 74014cf11afSPaul Mackerras /* Create a temp kernel stack for use before relocation is on. */ 74114cf11afSPaul Mackerras ld r1,PACAEMERGSP(r13) 74214cf11afSPaul Mackerras subi r1,r1,STACK_FRAME_OVERHEAD 74314cf11afSPaul Mackerras 744c705677eSStephen Rothwell b __secondary_start 74514cf11afSPaul Mackerras 74614cf11afSPaul Mackerras#endif /* CONFIG_PPC_PMAC */ 74714cf11afSPaul Mackerras 74814cf11afSPaul Mackerras/* 74914cf11afSPaul Mackerras * This function is called after the master CPU has released the 75014cf11afSPaul Mackerras * secondary processors. The execution environment is relocation off. 75114cf11afSPaul Mackerras * The paca for this processor has the following fields initialized at 75214cf11afSPaul Mackerras * this point: 75314cf11afSPaul Mackerras * 1. Processor number 75414cf11afSPaul Mackerras * 2. Segment table pointer (virtual address) 75514cf11afSPaul Mackerras * On entry the following are set: 7564f8cf36fSBenjamin Herrenschmidt * r1 = stack pointer (real addr of temp stack) 75714cf11afSPaul Mackerras * r24 = cpu# (in Linux terms) 75814cf11afSPaul Mackerras * r13 = paca virtual address 759ee43eb78SBenjamin Herrenschmidt * SPRG_PACA = paca virtual address 76014cf11afSPaul Mackerras */ 7612d27cfd3SBenjamin Herrenschmidt .section ".text"; 7622d27cfd3SBenjamin Herrenschmidt .align 2 ; 7632d27cfd3SBenjamin Herrenschmidt 764fc68e869SStephen Rothwell .globl __secondary_start 765c705677eSStephen Rothwell__secondary_start: 766799d6046SPaul Mackerras /* Set thread priority to MEDIUM */ 767799d6046SPaul Mackerras HMT_MEDIUM 76814cf11afSPaul Mackerras 7694f8cf36fSBenjamin Herrenschmidt /* Initialize the kernel stack */ 770e58c3495SDavid Gibson LOAD_REG_ADDR(r3, current_set) 77114cf11afSPaul Mackerras sldi r28,r24,3 /* get current_set[cpu#] */ 77254a83404SMichael Neuling ldx r14,r3,r28 77354a83404SMichael Neuling addi r14,r14,THREAD_SIZE-STACK_FRAME_OVERHEAD 77454a83404SMichael Neuling std r14,PACAKSAVE(r13) 77514cf11afSPaul Mackerras 776376af594SMichael Ellerman /* Do early setup for that CPU (SLB and hash table pointer) */ 777b1576fecSAnton Blanchard bl early_setup_secondary 778f761622eSMatt Evans 77954a83404SMichael Neuling /* 78054a83404SMichael Neuling * setup the new stack pointer, but *don't* use this until 78154a83404SMichael Neuling * translation is on. 78254a83404SMichael Neuling */ 78354a83404SMichael Neuling mr r1, r14 78454a83404SMichael Neuling 785799d6046SPaul Mackerras /* Clear backchain so we get nice backtraces */ 78614cf11afSPaul Mackerras li r7,0 78714cf11afSPaul Mackerras mtlr r7 78814cf11afSPaul Mackerras 7897230c564SBenjamin Herrenschmidt /* Mark interrupts soft and hard disabled (they might be enabled 7907230c564SBenjamin Herrenschmidt * in the PACA when doing hotplug) 7917230c564SBenjamin Herrenschmidt */ 7924f8cf36fSBenjamin Herrenschmidt stb r7,PACASOFTIRQEN(r13) 7937230c564SBenjamin Herrenschmidt li r0,PACA_IRQ_HARD_DIS 7947230c564SBenjamin Herrenschmidt stb r0,PACAIRQHAPPENED(r13) 7954f8cf36fSBenjamin Herrenschmidt 79614cf11afSPaul Mackerras /* enable MMU and jump to start_secondary */ 797ad0289e4SAnton Blanchard LOAD_REG_ADDR(r3, start_secondary_prolog) 798e58c3495SDavid Gibson LOAD_REG_IMMEDIATE(r4, MSR_KERNEL) 799d04c56f7SPaul Mackerras 800b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r3 801b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r4 8022d27cfd3SBenjamin Herrenschmidt RFI 80314cf11afSPaul Mackerras b . /* prevent speculative execution */ 80414cf11afSPaul Mackerras 80514cf11afSPaul Mackerras/* 80614cf11afSPaul Mackerras * Running with relocation on at this point. All we want to do is 807e31aa453SPaul Mackerras * zero the stack back-chain pointer and get the TOC virtual address 808e31aa453SPaul Mackerras * before going into C code. 80914cf11afSPaul Mackerras */ 810ad0289e4SAnton Blanchardstart_secondary_prolog: 811e31aa453SPaul Mackerras ld r2,PACATOC(r13) 81214cf11afSPaul Mackerras li r3,0 81314cf11afSPaul Mackerras std r3,0(r1) /* Zero the stack frame pointer */ 814b1576fecSAnton Blanchard bl start_secondary 815799d6046SPaul Mackerras b . 8168dbce53cSVaidyanathan Srinivasan/* 8178dbce53cSVaidyanathan Srinivasan * Reset stack pointer and call start_secondary 8188dbce53cSVaidyanathan Srinivasan * to continue with online operation when woken up 8198dbce53cSVaidyanathan Srinivasan * from cede in cpu offline. 8208dbce53cSVaidyanathan Srinivasan */ 8218dbce53cSVaidyanathan Srinivasan_GLOBAL(start_secondary_resume) 8228dbce53cSVaidyanathan Srinivasan ld r1,PACAKSAVE(r13) /* Reload kernel stack pointer */ 8238dbce53cSVaidyanathan Srinivasan li r3,0 8248dbce53cSVaidyanathan Srinivasan std r3,0(r1) /* Zero the stack frame pointer */ 825b1576fecSAnton Blanchard bl start_secondary 8268dbce53cSVaidyanathan Srinivasan b . 82714cf11afSPaul Mackerras#endif 82814cf11afSPaul Mackerras 82914cf11afSPaul Mackerras/* 83014cf11afSPaul Mackerras * This subroutine clobbers r11 and r12 83114cf11afSPaul Mackerras */ 8326a3bab90SAnton Blanchardenable_64b_mode: 83314cf11afSPaul Mackerras mfmsr r11 /* grab the current MSR */ 8342d27cfd3SBenjamin Herrenschmidt#ifdef CONFIG_PPC_BOOK3E 8352d27cfd3SBenjamin Herrenschmidt oris r11,r11,0x8000 /* CM bit set, we'll set ICM later */ 8362d27cfd3SBenjamin Herrenschmidt mtmsr r11 8372d27cfd3SBenjamin Herrenschmidt#else /* CONFIG_PPC_BOOK3E */ 8389f0b0793SMichael Ellerman li r12,(MSR_64BIT | MSR_ISF)@highest 839e31aa453SPaul Mackerras sldi r12,r12,48 84014cf11afSPaul Mackerras or r11,r11,r12 84114cf11afSPaul Mackerras mtmsrd r11 84214cf11afSPaul Mackerras isync 8432d27cfd3SBenjamin Herrenschmidt#endif 84414cf11afSPaul Mackerras blr 84514cf11afSPaul Mackerras 84614cf11afSPaul Mackerras/* 847e31aa453SPaul Mackerras * This puts the TOC pointer into r2, offset by 0x8000 (as expected 848e31aa453SPaul Mackerras * by the toolchain). It computes the correct value for wherever we 849e31aa453SPaul Mackerras * are running at the moment, using position-independent code. 8501fbe9cf2SAnton Blanchard * 8511fbe9cf2SAnton Blanchard * Note: The compiler constructs pointers using offsets from the 8521fbe9cf2SAnton Blanchard * TOC in -mcmodel=medium mode. After we relocate to 0 but before 8531fbe9cf2SAnton Blanchard * the MMU is on we need our TOC to be a virtual address otherwise 8541fbe9cf2SAnton Blanchard * these pointers will be real addresses which may get stored and 8551fbe9cf2SAnton Blanchard * accessed later with the MMU on. We use tovirt() at the call 8561fbe9cf2SAnton Blanchard * sites to handle this. 857e31aa453SPaul Mackerras */ 858e31aa453SPaul Mackerras_GLOBAL(relative_toc) 859e31aa453SPaul Mackerras mflr r0 860e31aa453SPaul Mackerras bcl 20,31,$+4 861e550592eSBenjamin Herrenschmidt0: mflr r11 862e550592eSBenjamin Herrenschmidt ld r2,(p_toc - 0b)(r11) 863e550592eSBenjamin Herrenschmidt add r2,r2,r11 864e31aa453SPaul Mackerras mtlr r0 865e31aa453SPaul Mackerras blr 866e31aa453SPaul Mackerras 8675b63fee1SAnton Blanchard.balign 8 868e31aa453SPaul Mackerrasp_toc: .llong __toc_start + 0x8000 - 0b 869e31aa453SPaul Mackerras 870e31aa453SPaul Mackerras/* 87114cf11afSPaul Mackerras * This is where the main kernel code starts. 87214cf11afSPaul Mackerras */ 8736a3bab90SAnton Blanchardstart_here_multiplatform: 8741fbe9cf2SAnton Blanchard /* set up the TOC */ 875b1576fecSAnton Blanchard bl relative_toc 8761fbe9cf2SAnton Blanchard tovirt(r2,r2) 87714cf11afSPaul Mackerras 87814cf11afSPaul Mackerras /* Clear out the BSS. It may have been done in prom_init, 87914cf11afSPaul Mackerras * already but that's irrelevant since prom_init will soon 88014cf11afSPaul Mackerras * be detached from the kernel completely. Besides, we need 88114cf11afSPaul Mackerras * to clear it now for kexec-style entry. 88214cf11afSPaul Mackerras */ 883e31aa453SPaul Mackerras LOAD_REG_ADDR(r11,__bss_stop) 884e31aa453SPaul Mackerras LOAD_REG_ADDR(r8,__bss_start) 88514cf11afSPaul Mackerras sub r11,r11,r8 /* bss size */ 88614cf11afSPaul Mackerras addi r11,r11,7 /* round up to an even double word */ 887e31aa453SPaul Mackerras srdi. r11,r11,3 /* shift right by 3 */ 88814cf11afSPaul Mackerras beq 4f 88914cf11afSPaul Mackerras addi r8,r8,-8 89014cf11afSPaul Mackerras li r0,0 89114cf11afSPaul Mackerras mtctr r11 /* zero this many doublewords */ 89214cf11afSPaul Mackerras3: stdu r0,8(r8) 89314cf11afSPaul Mackerras bdnz 3b 89414cf11afSPaul Mackerras4: 89514cf11afSPaul Mackerras 896daea1175SBenjamin Herrenschmidt#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL 897daea1175SBenjamin Herrenschmidt /* Setup OPAL entry */ 898ab7f961aSBenjamin Herrenschmidt LOAD_REG_ADDR(r11, opal) 899daea1175SBenjamin Herrenschmidt std r28,0(r11); 900daea1175SBenjamin Herrenschmidt std r29,8(r11); 901daea1175SBenjamin Herrenschmidt#endif 902daea1175SBenjamin Herrenschmidt 9032d27cfd3SBenjamin Herrenschmidt#ifndef CONFIG_PPC_BOOK3E 90414cf11afSPaul Mackerras mfmsr r6 90514cf11afSPaul Mackerras ori r6,r6,MSR_RI 90614cf11afSPaul Mackerras mtmsrd r6 /* RI on */ 9072d27cfd3SBenjamin Herrenschmidt#endif 90814cf11afSPaul Mackerras 909549e8152SPaul Mackerras#ifdef CONFIG_RELOCATABLE 910549e8152SPaul Mackerras /* Save the physical address we're running at in kernstart_addr */ 911549e8152SPaul Mackerras LOAD_REG_ADDR(r4, kernstart_addr) 912549e8152SPaul Mackerras clrldi r0,r25,2 913549e8152SPaul Mackerras std r0,0(r4) 914549e8152SPaul Mackerras#endif 915549e8152SPaul Mackerras 916e31aa453SPaul Mackerras /* The following gets the stack set up with the regs */ 91714cf11afSPaul Mackerras /* pointing to the real addr of the kernel stack. This is */ 91814cf11afSPaul Mackerras /* all done to support the C function call below which sets */ 91914cf11afSPaul Mackerras /* up the htab. This is done because we have relocated the */ 92014cf11afSPaul Mackerras /* kernel but are still running in real mode. */ 92114cf11afSPaul Mackerras 922e31aa453SPaul Mackerras LOAD_REG_ADDR(r3,init_thread_union) 92314cf11afSPaul Mackerras 924e31aa453SPaul Mackerras /* set up a stack pointer */ 92514cf11afSPaul Mackerras addi r1,r3,THREAD_SIZE 92614cf11afSPaul Mackerras li r0,0 92714cf11afSPaul Mackerras stdu r0,-STACK_FRAME_OVERHEAD(r1) 92814cf11afSPaul Mackerras 929376af594SMichael Ellerman /* 930376af594SMichael Ellerman * Do very early kernel initializations, including initial hash table 931376af594SMichael Ellerman * and SLB setup before we turn on relocation. 932376af594SMichael Ellerman */ 93314cf11afSPaul Mackerras 93414cf11afSPaul Mackerras /* Restore parameters passed from prom_init/kexec */ 93514cf11afSPaul Mackerras mr r3,r31 936b1576fecSAnton Blanchard bl early_setup /* also sets r13 and SPRG_PACA */ 93714cf11afSPaul Mackerras 938ad0289e4SAnton Blanchard LOAD_REG_ADDR(r3, start_here_common) 939e31aa453SPaul Mackerras ld r4,PACAKMSR(r13) 940b5bbeb23SPaul Mackerras mtspr SPRN_SRR0,r3 941b5bbeb23SPaul Mackerras mtspr SPRN_SRR1,r4 9422d27cfd3SBenjamin Herrenschmidt RFI 94314cf11afSPaul Mackerras b . /* prevent speculative execution */ 94414cf11afSPaul Mackerras 94514cf11afSPaul Mackerras /* This is where all platforms converge execution */ 946ad0289e4SAnton Blanchard 947ad0289e4SAnton Blanchardstart_here_common: 94814cf11afSPaul Mackerras /* relocation is on at this point */ 94914cf11afSPaul Mackerras std r1,PACAKSAVE(r13) 95014cf11afSPaul Mackerras 951e31aa453SPaul Mackerras /* Load the TOC (virtual address) */ 952e31aa453SPaul Mackerras ld r2,PACATOC(r13) 953e31aa453SPaul Mackerras 9547230c564SBenjamin Herrenschmidt /* Do more system initializations in virtual mode */ 955b1576fecSAnton Blanchard bl setup_system 95614cf11afSPaul Mackerras 9577230c564SBenjamin Herrenschmidt /* Mark interrupts soft and hard disabled (they might be enabled 9587230c564SBenjamin Herrenschmidt * in the PACA when doing hotplug) 9597230c564SBenjamin Herrenschmidt */ 9607230c564SBenjamin Herrenschmidt li r0,0 9617230c564SBenjamin Herrenschmidt stb r0,PACASOFTIRQEN(r13) 9627230c564SBenjamin Herrenschmidt li r0,PACA_IRQ_HARD_DIS 9637230c564SBenjamin Herrenschmidt stb r0,PACAIRQHAPPENED(r13) 96414cf11afSPaul Mackerras 9657230c564SBenjamin Herrenschmidt /* Generic kernel entry */ 966b1576fecSAnton Blanchard bl start_kernel 96714cf11afSPaul Mackerras 968f1870f77SAnton Blanchard /* Not reached */ 969f1870f77SAnton Blanchard BUG_OPCODE 97014cf11afSPaul Mackerras 97114cf11afSPaul Mackerras/* 97214cf11afSPaul Mackerras * We put a few things here that have to be page-aligned. 97314cf11afSPaul Mackerras * This stuff goes at the beginning of the bss, which is page-aligned. 97414cf11afSPaul Mackerras */ 97514cf11afSPaul Mackerras .section ".bss" 97614cf11afSPaul Mackerras 97714cf11afSPaul Mackerras .align PAGE_SHIFT 97814cf11afSPaul Mackerras 97914cf11afSPaul Mackerras .globl empty_zero_page 98014cf11afSPaul Mackerrasempty_zero_page: 98114cf11afSPaul Mackerras .space PAGE_SIZE 98214cf11afSPaul Mackerras 98314cf11afSPaul Mackerras .globl swapper_pg_dir 98414cf11afSPaul Mackerrasswapper_pg_dir: 985ee7a76daSStephen Rothwell .space PGD_TABLE_SIZE 986