1/* 2 * PowerPC version 3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org) 4 * 5 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP 6 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu> 7 * Adapted for Power Macintosh by Paul Mackerras. 8 * Low-level exception handlers and MMU support 9 * rewritten by Paul Mackerras. 10 * Copyright (C) 1996 Paul Mackerras. 11 * 12 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and 13 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com 14 * 15 * This file contains the entry point for the 64-bit kernel along 16 * with some early initialization code common to all 64-bit powerpc 17 * variants. 18 * 19 * This program is free software; you can redistribute it and/or 20 * modify it under the terms of the GNU General Public License 21 * as published by the Free Software Foundation; either version 22 * 2 of the License, or (at your option) any later version. 23 */ 24 25#include <linux/threads.h> 26#include <asm/reg.h> 27#include <asm/page.h> 28#include <asm/mmu.h> 29#include <asm/ppc_asm.h> 30#include <asm/asm-offsets.h> 31#include <asm/bug.h> 32#include <asm/cputable.h> 33#include <asm/setup.h> 34#include <asm/hvcall.h> 35#include <asm/thread_info.h> 36#include <asm/firmware.h> 37#include <asm/page_64.h> 38#include <asm/irqflags.h> 39#include <asm/kvm_book3s_asm.h> 40#include <asm/ptrace.h> 41#include <asm/hw_irq.h> 42 43/* The physical memory is laid out such that the secondary processor 44 * spin code sits at 0x0000...0x00ff. On server, the vectors follow 45 * using the layout described in exceptions-64s.S 46 */ 47 48/* 49 * Entering into this code we make the following assumptions: 50 * 51 * For pSeries or server processors: 52 * 1. The MMU is off & open firmware is running in real mode. 53 * 2. The kernel is entered at __start 54 * -or- For OPAL entry: 55 * 1. The MMU is off, processor in HV mode, primary CPU enters at 0 56 * with device-tree in gpr3. We also get OPAL base in r8 and 57 * entry in r9 for debugging purposes 58 * 2. Secondary processors enter at 0x60 with PIR in gpr3 59 * 60 * For Book3E processors: 61 * 1. The MMU is on running in AS0 in a state defined in ePAPR 62 * 2. The kernel is entered at __start 63 */ 64 65 .text 66 .globl _stext 67_stext: 68_GLOBAL(__start) 69 /* NOP this out unconditionally */ 70BEGIN_FTR_SECTION 71 FIXUP_ENDIAN 72 b .__start_initialization_multiplatform 73END_FTR_SECTION(0, 1) 74 75 /* Catch branch to 0 in real mode */ 76 trap 77 78 /* Secondary processors spin on this value until it becomes nonzero. 79 * When it does it contains the real address of the descriptor 80 * of the function that the cpu should jump to to continue 81 * initialization. 82 */ 83 .balign 8 84 .globl __secondary_hold_spinloop 85__secondary_hold_spinloop: 86 .llong 0x0 87 88 /* Secondary processors write this value with their cpu # */ 89 /* after they enter the spin loop immediately below. */ 90 .globl __secondary_hold_acknowledge 91__secondary_hold_acknowledge: 92 .llong 0x0 93 94#ifdef CONFIG_RELOCATABLE 95 /* This flag is set to 1 by a loader if the kernel should run 96 * at the loaded address instead of the linked address. This 97 * is used by kexec-tools to keep the the kdump kernel in the 98 * crash_kernel region. The loader is responsible for 99 * observing the alignment requirement. 100 */ 101 /* Do not move this variable as kexec-tools knows about it. */ 102 . = 0x5c 103 .globl __run_at_load 104__run_at_load: 105 .long 0x72756e30 /* "run0" -- relocate to 0 by default */ 106#endif 107 108 . = 0x60 109/* 110 * The following code is used to hold secondary processors 111 * in a spin loop after they have entered the kernel, but 112 * before the bulk of the kernel has been relocated. This code 113 * is relocated to physical address 0x60 before prom_init is run. 114 * All of it must fit below the first exception vector at 0x100. 115 * Use .globl here not _GLOBAL because we want __secondary_hold 116 * to be the actual text address, not a descriptor. 117 */ 118 .globl __secondary_hold 119__secondary_hold: 120 FIXUP_ENDIAN 121#ifndef CONFIG_PPC_BOOK3E 122 mfmsr r24 123 ori r24,r24,MSR_RI 124 mtmsrd r24 /* RI on */ 125#endif 126 /* Grab our physical cpu number */ 127 mr r24,r3 128 /* stash r4 for book3e */ 129 mr r25,r4 130 131 /* Tell the master cpu we're here */ 132 /* Relocation is off & we are located at an address less */ 133 /* than 0x100, so only need to grab low order offset. */ 134 std r24,__secondary_hold_acknowledge-_stext(0) 135 sync 136 137 li r26,0 138#ifdef CONFIG_PPC_BOOK3E 139 tovirt(r26,r26) 140#endif 141 /* All secondary cpus wait here until told to start. */ 142100: ld r4,__secondary_hold_spinloop-_stext(r26) 143 cmpdi 0,r4,0 144 beq 100b 145 146#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC) 147#ifdef CONFIG_PPC_BOOK3E 148 tovirt(r4,r4) 149#endif 150 ld r4,0(r4) /* deref function descriptor */ 151 mtctr r4 152 mr r3,r24 153 /* 154 * it may be the case that other platforms have r4 right to 155 * begin with, this gives us some safety in case it is not 156 */ 157#ifdef CONFIG_PPC_BOOK3E 158 mr r4,r25 159#else 160 li r4,0 161#endif 162 /* Make sure that patched code is visible */ 163 isync 164 bctr 165#else 166 BUG_OPCODE 167#endif 168 169/* This value is used to mark exception frames on the stack. */ 170 .section ".toc","aw" 171exception_marker: 172 .tc ID_72656773_68657265[TC],0x7265677368657265 173 .text 174 175/* 176 * On server, we include the exception vectors code here as it 177 * relies on absolute addressing which is only possible within 178 * this compilation unit 179 */ 180#ifdef CONFIG_PPC_BOOK3S 181#include "exceptions-64s.S" 182#endif 183 184_GLOBAL(generic_secondary_thread_init) 185 mr r24,r3 186 187 /* turn on 64-bit mode */ 188 bl .enable_64b_mode 189 190 /* get a valid TOC pointer, wherever we're mapped at */ 191 bl .relative_toc 192 tovirt(r2,r2) 193 194#ifdef CONFIG_PPC_BOOK3E 195 /* Book3E initialization */ 196 mr r3,r24 197 bl .book3e_secondary_thread_init 198#endif 199 b generic_secondary_common_init 200 201/* 202 * On pSeries and most other platforms, secondary processors spin 203 * in the following code. 204 * At entry, r3 = this processor's number (physical cpu id) 205 * 206 * On Book3E, r4 = 1 to indicate that the initial TLB entry for 207 * this core already exists (setup via some other mechanism such 208 * as SCOM before entry). 209 */ 210_GLOBAL(generic_secondary_smp_init) 211 FIXUP_ENDIAN 212 mr r24,r3 213 mr r25,r4 214 215 /* turn on 64-bit mode */ 216 bl .enable_64b_mode 217 218 /* get a valid TOC pointer, wherever we're mapped at */ 219 bl .relative_toc 220 tovirt(r2,r2) 221 222#ifdef CONFIG_PPC_BOOK3E 223 /* Book3E initialization */ 224 mr r3,r24 225 mr r4,r25 226 bl .book3e_secondary_core_init 227#endif 228 229generic_secondary_common_init: 230 /* Set up a paca value for this processor. Since we have the 231 * physical cpu id in r24, we need to search the pacas to find 232 * which logical id maps to our physical one. 233 */ 234 LOAD_REG_ADDR(r13, paca) /* Load paca pointer */ 235 ld r13,0(r13) /* Get base vaddr of paca array */ 236#ifndef CONFIG_SMP 237 addi r13,r13,PACA_SIZE /* know r13 if used accidentally */ 238 b .kexec_wait /* wait for next kernel if !SMP */ 239#else 240 LOAD_REG_ADDR(r7, nr_cpu_ids) /* Load nr_cpu_ids address */ 241 lwz r7,0(r7) /* also the max paca allocated */ 242 li r5,0 /* logical cpu id */ 2431: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */ 244 cmpw r6,r24 /* Compare to our id */ 245 beq 2f 246 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */ 247 addi r5,r5,1 248 cmpw r5,r7 /* Check if more pacas exist */ 249 blt 1b 250 251 mr r3,r24 /* not found, copy phys to r3 */ 252 b .kexec_wait /* next kernel might do better */ 253 2542: SET_PACA(r13) 255#ifdef CONFIG_PPC_BOOK3E 256 addi r12,r13,PACA_EXTLB /* and TLB exc frame in another */ 257 mtspr SPRN_SPRG_TLB_EXFRAME,r12 258#endif 259 260 /* From now on, r24 is expected to be logical cpuid */ 261 mr r24,r5 262 263 /* See if we need to call a cpu state restore handler */ 264 LOAD_REG_ADDR(r23, cur_cpu_spec) 265 ld r23,0(r23) 266 ld r23,CPU_SPEC_RESTORE(r23) 267 cmpdi 0,r23,0 268 beq 3f 269 ld r23,0(r23) 270 mtctr r23 271 bctrl 272 2733: LOAD_REG_ADDR(r3, spinning_secondaries) /* Decrement spinning_secondaries */ 274 lwarx r4,0,r3 275 subi r4,r4,1 276 stwcx. r4,0,r3 277 bne 3b 278 isync 279 2804: HMT_LOW 281 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */ 282 /* start. */ 283 cmpwi 0,r23,0 284 beq 4b /* Loop until told to go */ 285 286 sync /* order paca.run and cur_cpu_spec */ 287 isync /* In case code patching happened */ 288 289 /* Create a temp kernel stack for use before relocation is on. */ 290 ld r1,PACAEMERGSP(r13) 291 subi r1,r1,STACK_FRAME_OVERHEAD 292 293 b __secondary_start 294#endif /* SMP */ 295 296/* 297 * Turn the MMU off. 298 * Assumes we're mapped EA == RA if the MMU is on. 299 */ 300#ifdef CONFIG_PPC_BOOK3S 301_STATIC(__mmu_off) 302 mfmsr r3 303 andi. r0,r3,MSR_IR|MSR_DR 304 beqlr 305 mflr r4 306 andc r3,r3,r0 307 mtspr SPRN_SRR0,r4 308 mtspr SPRN_SRR1,r3 309 sync 310 rfid 311 b . /* prevent speculative execution */ 312#endif 313 314 315/* 316 * Here is our main kernel entry point. We support currently 2 kind of entries 317 * depending on the value of r5. 318 * 319 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content 320 * in r3...r7 321 * 322 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the 323 * DT block, r4 is a physical pointer to the kernel itself 324 * 325 */ 326_GLOBAL(__start_initialization_multiplatform) 327 /* Make sure we are running in 64 bits mode */ 328 bl .enable_64b_mode 329 330 /* Get TOC pointer (current runtime address) */ 331 bl .relative_toc 332 333 /* find out where we are now */ 334 bcl 20,31,$+4 3350: mflr r26 /* r26 = runtime addr here */ 336 addis r26,r26,(_stext - 0b)@ha 337 addi r26,r26,(_stext - 0b)@l /* current runtime base addr */ 338 339 /* 340 * Are we booted from a PROM Of-type client-interface ? 341 */ 342 cmpldi cr0,r5,0 343 beq 1f 344 b .__boot_from_prom /* yes -> prom */ 3451: 346 /* Save parameters */ 347 mr r31,r3 348 mr r30,r4 349#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL 350 /* Save OPAL entry */ 351 mr r28,r8 352 mr r29,r9 353#endif 354 355#ifdef CONFIG_PPC_BOOK3E 356 bl .start_initialization_book3e 357 b .__after_prom_start 358#else 359 /* Setup some critical 970 SPRs before switching MMU off */ 360 mfspr r0,SPRN_PVR 361 srwi r0,r0,16 362 cmpwi r0,0x39 /* 970 */ 363 beq 1f 364 cmpwi r0,0x3c /* 970FX */ 365 beq 1f 366 cmpwi r0,0x44 /* 970MP */ 367 beq 1f 368 cmpwi r0,0x45 /* 970GX */ 369 bne 2f 3701: bl .__cpu_preinit_ppc970 3712: 372 373 /* Switch off MMU if not already off */ 374 bl .__mmu_off 375 b .__after_prom_start 376#endif /* CONFIG_PPC_BOOK3E */ 377 378_INIT_STATIC(__boot_from_prom) 379#ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE 380 /* Save parameters */ 381 mr r31,r3 382 mr r30,r4 383 mr r29,r5 384 mr r28,r6 385 mr r27,r7 386 387 /* 388 * Align the stack to 16-byte boundary 389 * Depending on the size and layout of the ELF sections in the initial 390 * boot binary, the stack pointer may be unaligned on PowerMac 391 */ 392 rldicr r1,r1,0,59 393 394#ifdef CONFIG_RELOCATABLE 395 /* Relocate code for where we are now */ 396 mr r3,r26 397 bl .relocate 398#endif 399 400 /* Restore parameters */ 401 mr r3,r31 402 mr r4,r30 403 mr r5,r29 404 mr r6,r28 405 mr r7,r27 406 407 /* Do all of the interaction with OF client interface */ 408 mr r8,r26 409 bl .prom_init 410#endif /* #CONFIG_PPC_OF_BOOT_TRAMPOLINE */ 411 412 /* We never return. We also hit that trap if trying to boot 413 * from OF while CONFIG_PPC_OF_BOOT_TRAMPOLINE isn't selected */ 414 trap 415 416_STATIC(__after_prom_start) 417#ifdef CONFIG_RELOCATABLE 418 /* process relocations for the final address of the kernel */ 419 lis r25,PAGE_OFFSET@highest /* compute virtual base of kernel */ 420 sldi r25,r25,32 421 lwz r7,__run_at_load-_stext(r26) 422 cmplwi cr0,r7,1 /* flagged to stay where we are ? */ 423 bne 1f 424 add r25,r25,r26 4251: mr r3,r25 426 bl .relocate 427#endif 428 429/* 430 * We need to run with _stext at physical address PHYSICAL_START. 431 * This will leave some code in the first 256B of 432 * real memory, which are reserved for software use. 433 * 434 * Note: This process overwrites the OF exception vectors. 435 */ 436 li r3,0 /* target addr */ 437#ifdef CONFIG_PPC_BOOK3E 438 tovirt(r3,r3) /* on booke, we already run at PAGE_OFFSET */ 439#endif 440 mr. r4,r26 /* In some cases the loader may */ 441 beq 9f /* have already put us at zero */ 442 li r6,0x100 /* Start offset, the first 0x100 */ 443 /* bytes were copied earlier. */ 444#ifdef CONFIG_PPC_BOOK3E 445 tovirt(r6,r6) /* on booke, we already run at PAGE_OFFSET */ 446#endif 447 448#ifdef CONFIG_RELOCATABLE 449/* 450 * Check if the kernel has to be running as relocatable kernel based on the 451 * variable __run_at_load, if it is set the kernel is treated as relocatable 452 * kernel, otherwise it will be moved to PHYSICAL_START 453 */ 454 lwz r7,__run_at_load-_stext(r26) 455 cmplwi cr0,r7,1 456 bne 3f 457 458 /* just copy interrupts */ 459 LOAD_REG_IMMEDIATE(r5, __end_interrupts - _stext) 460 b 5f 4613: 462#endif 463 lis r5,(copy_to_here - _stext)@ha 464 addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */ 465 466 bl .copy_and_flush /* copy the first n bytes */ 467 /* this includes the code being */ 468 /* executed here. */ 469 addis r8,r3,(4f - _stext)@ha /* Jump to the copy of this code */ 470 addi r8,r8,(4f - _stext)@l /* that we just made */ 471 mtctr r8 472 bctr 473 474.balign 8 475p_end: .llong _end - _stext 476 4774: /* Now copy the rest of the kernel up to _end */ 478 addis r5,r26,(p_end - _stext)@ha 479 ld r5,(p_end - _stext)@l(r5) /* get _end */ 4805: bl .copy_and_flush /* copy the rest */ 481 4829: b .start_here_multiplatform 483 484/* 485 * Copy routine used to copy the kernel to start at physical address 0 486 * and flush and invalidate the caches as needed. 487 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset 488 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5. 489 * 490 * Note: this routine *only* clobbers r0, r6 and lr 491 */ 492_GLOBAL(copy_and_flush) 493 addi r5,r5,-8 494 addi r6,r6,-8 4954: li r0,8 /* Use the smallest common */ 496 /* denominator cache line */ 497 /* size. This results in */ 498 /* extra cache line flushes */ 499 /* but operation is correct. */ 500 /* Can't get cache line size */ 501 /* from NACA as it is being */ 502 /* moved too. */ 503 504 mtctr r0 /* put # words/line in ctr */ 5053: addi r6,r6,8 /* copy a cache line */ 506 ldx r0,r6,r4 507 stdx r0,r6,r3 508 bdnz 3b 509 dcbst r6,r3 /* write it to memory */ 510 sync 511 icbi r6,r3 /* flush the icache line */ 512 cmpld 0,r6,r5 513 blt 4b 514 sync 515 addi r5,r5,8 516 addi r6,r6,8 517 isync 518 blr 519 520.align 8 521copy_to_here: 522 523#ifdef CONFIG_SMP 524#ifdef CONFIG_PPC_PMAC 525/* 526 * On PowerMac, secondary processors starts from the reset vector, which 527 * is temporarily turned into a call to one of the functions below. 528 */ 529 .section ".text"; 530 .align 2 ; 531 532 .globl __secondary_start_pmac_0 533__secondary_start_pmac_0: 534 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */ 535 li r24,0 536 b 1f 537 li r24,1 538 b 1f 539 li r24,2 540 b 1f 541 li r24,3 5421: 543 544_GLOBAL(pmac_secondary_start) 545 /* turn on 64-bit mode */ 546 bl .enable_64b_mode 547 548 li r0,0 549 mfspr r3,SPRN_HID4 550 rldimi r3,r0,40,23 /* clear bit 23 (rm_ci) */ 551 sync 552 mtspr SPRN_HID4,r3 553 isync 554 sync 555 slbia 556 557 /* get TOC pointer (real address) */ 558 bl .relative_toc 559 tovirt(r2,r2) 560 561 /* Copy some CPU settings from CPU 0 */ 562 bl .__restore_cpu_ppc970 563 564 /* pSeries do that early though I don't think we really need it */ 565 mfmsr r3 566 ori r3,r3,MSR_RI 567 mtmsrd r3 /* RI on */ 568 569 /* Set up a paca value for this processor. */ 570 LOAD_REG_ADDR(r4,paca) /* Load paca pointer */ 571 ld r4,0(r4) /* Get base vaddr of paca array */ 572 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */ 573 add r13,r13,r4 /* for this processor. */ 574 SET_PACA(r13) /* Save vaddr of paca in an SPRG*/ 575 576 /* Mark interrupts soft and hard disabled (they might be enabled 577 * in the PACA when doing hotplug) 578 */ 579 li r0,0 580 stb r0,PACASOFTIRQEN(r13) 581 li r0,PACA_IRQ_HARD_DIS 582 stb r0,PACAIRQHAPPENED(r13) 583 584 /* Create a temp kernel stack for use before relocation is on. */ 585 ld r1,PACAEMERGSP(r13) 586 subi r1,r1,STACK_FRAME_OVERHEAD 587 588 b __secondary_start 589 590#endif /* CONFIG_PPC_PMAC */ 591 592/* 593 * This function is called after the master CPU has released the 594 * secondary processors. The execution environment is relocation off. 595 * The paca for this processor has the following fields initialized at 596 * this point: 597 * 1. Processor number 598 * 2. Segment table pointer (virtual address) 599 * On entry the following are set: 600 * r1 = stack pointer (real addr of temp stack) 601 * r24 = cpu# (in Linux terms) 602 * r13 = paca virtual address 603 * SPRG_PACA = paca virtual address 604 */ 605 .section ".text"; 606 .align 2 ; 607 608 .globl __secondary_start 609__secondary_start: 610 /* Set thread priority to MEDIUM */ 611 HMT_MEDIUM 612 613 /* Initialize the kernel stack */ 614 LOAD_REG_ADDR(r3, current_set) 615 sldi r28,r24,3 /* get current_set[cpu#] */ 616 ldx r14,r3,r28 617 addi r14,r14,THREAD_SIZE-STACK_FRAME_OVERHEAD 618 std r14,PACAKSAVE(r13) 619 620 /* Do early setup for that CPU (stab, slb, hash table pointer) */ 621 bl .early_setup_secondary 622 623 /* 624 * setup the new stack pointer, but *don't* use this until 625 * translation is on. 626 */ 627 mr r1, r14 628 629 /* Clear backchain so we get nice backtraces */ 630 li r7,0 631 mtlr r7 632 633 /* Mark interrupts soft and hard disabled (they might be enabled 634 * in the PACA when doing hotplug) 635 */ 636 stb r7,PACASOFTIRQEN(r13) 637 li r0,PACA_IRQ_HARD_DIS 638 stb r0,PACAIRQHAPPENED(r13) 639 640 /* enable MMU and jump to start_secondary */ 641 LOAD_REG_ADDR(r3, .start_secondary_prolog) 642 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL) 643 644 mtspr SPRN_SRR0,r3 645 mtspr SPRN_SRR1,r4 646 RFI 647 b . /* prevent speculative execution */ 648 649/* 650 * Running with relocation on at this point. All we want to do is 651 * zero the stack back-chain pointer and get the TOC virtual address 652 * before going into C code. 653 */ 654_GLOBAL(start_secondary_prolog) 655 ld r2,PACATOC(r13) 656 li r3,0 657 std r3,0(r1) /* Zero the stack frame pointer */ 658 bl .start_secondary 659 b . 660/* 661 * Reset stack pointer and call start_secondary 662 * to continue with online operation when woken up 663 * from cede in cpu offline. 664 */ 665_GLOBAL(start_secondary_resume) 666 ld r1,PACAKSAVE(r13) /* Reload kernel stack pointer */ 667 li r3,0 668 std r3,0(r1) /* Zero the stack frame pointer */ 669 bl .start_secondary 670 b . 671#endif 672 673/* 674 * This subroutine clobbers r11 and r12 675 */ 676_GLOBAL(enable_64b_mode) 677 mfmsr r11 /* grab the current MSR */ 678#ifdef CONFIG_PPC_BOOK3E 679 oris r11,r11,0x8000 /* CM bit set, we'll set ICM later */ 680 mtmsr r11 681#else /* CONFIG_PPC_BOOK3E */ 682 li r12,(MSR_64BIT | MSR_ISF)@highest 683 sldi r12,r12,48 684 or r11,r11,r12 685 mtmsrd r11 686 isync 687#endif 688 blr 689 690/* 691 * This puts the TOC pointer into r2, offset by 0x8000 (as expected 692 * by the toolchain). It computes the correct value for wherever we 693 * are running at the moment, using position-independent code. 694 * 695 * Note: The compiler constructs pointers using offsets from the 696 * TOC in -mcmodel=medium mode. After we relocate to 0 but before 697 * the MMU is on we need our TOC to be a virtual address otherwise 698 * these pointers will be real addresses which may get stored and 699 * accessed later with the MMU on. We use tovirt() at the call 700 * sites to handle this. 701 */ 702_GLOBAL(relative_toc) 703 mflr r0 704 bcl 20,31,$+4 7050: mflr r11 706 ld r2,(p_toc - 0b)(r11) 707 add r2,r2,r11 708 mtlr r0 709 blr 710 711.balign 8 712p_toc: .llong __toc_start + 0x8000 - 0b 713 714/* 715 * This is where the main kernel code starts. 716 */ 717_INIT_STATIC(start_here_multiplatform) 718 /* set up the TOC */ 719 bl .relative_toc 720 tovirt(r2,r2) 721 722 /* Clear out the BSS. It may have been done in prom_init, 723 * already but that's irrelevant since prom_init will soon 724 * be detached from the kernel completely. Besides, we need 725 * to clear it now for kexec-style entry. 726 */ 727 LOAD_REG_ADDR(r11,__bss_stop) 728 LOAD_REG_ADDR(r8,__bss_start) 729 sub r11,r11,r8 /* bss size */ 730 addi r11,r11,7 /* round up to an even double word */ 731 srdi. r11,r11,3 /* shift right by 3 */ 732 beq 4f 733 addi r8,r8,-8 734 li r0,0 735 mtctr r11 /* zero this many doublewords */ 7363: stdu r0,8(r8) 737 bdnz 3b 7384: 739 740#ifdef CONFIG_PPC_EARLY_DEBUG_OPAL 741 /* Setup OPAL entry */ 742 LOAD_REG_ADDR(r11, opal) 743 std r28,0(r11); 744 std r29,8(r11); 745#endif 746 747#ifndef CONFIG_PPC_BOOK3E 748 mfmsr r6 749 ori r6,r6,MSR_RI 750 mtmsrd r6 /* RI on */ 751#endif 752 753#ifdef CONFIG_RELOCATABLE 754 /* Save the physical address we're running at in kernstart_addr */ 755 LOAD_REG_ADDR(r4, kernstart_addr) 756 clrldi r0,r25,2 757 std r0,0(r4) 758#endif 759 760 /* The following gets the stack set up with the regs */ 761 /* pointing to the real addr of the kernel stack. This is */ 762 /* all done to support the C function call below which sets */ 763 /* up the htab. This is done because we have relocated the */ 764 /* kernel but are still running in real mode. */ 765 766 LOAD_REG_ADDR(r3,init_thread_union) 767 768 /* set up a stack pointer */ 769 addi r1,r3,THREAD_SIZE 770 li r0,0 771 stdu r0,-STACK_FRAME_OVERHEAD(r1) 772 773 /* Do very early kernel initializations, including initial hash table, 774 * stab and slb setup before we turn on relocation. */ 775 776 /* Restore parameters passed from prom_init/kexec */ 777 mr r3,r31 778 bl .early_setup /* also sets r13 and SPRG_PACA */ 779 780 LOAD_REG_ADDR(r3, .start_here_common) 781 ld r4,PACAKMSR(r13) 782 mtspr SPRN_SRR0,r3 783 mtspr SPRN_SRR1,r4 784 RFI 785 b . /* prevent speculative execution */ 786 787 /* This is where all platforms converge execution */ 788_INIT_GLOBAL(start_here_common) 789 /* relocation is on at this point */ 790 std r1,PACAKSAVE(r13) 791 792 /* Load the TOC (virtual address) */ 793 ld r2,PACATOC(r13) 794 795 /* Do more system initializations in virtual mode */ 796 bl .setup_system 797 798 /* Mark interrupts soft and hard disabled (they might be enabled 799 * in the PACA when doing hotplug) 800 */ 801 li r0,0 802 stb r0,PACASOFTIRQEN(r13) 803 li r0,PACA_IRQ_HARD_DIS 804 stb r0,PACAIRQHAPPENED(r13) 805 806 /* Generic kernel entry */ 807 bl .start_kernel 808 809 /* Not reached */ 810 BUG_OPCODE 811 812/* 813 * We put a few things here that have to be page-aligned. 814 * This stuff goes at the beginning of the bss, which is page-aligned. 815 */ 816 .section ".bss" 817 818 .align PAGE_SHIFT 819 820 .globl empty_zero_page 821empty_zero_page: 822 .space PAGE_SIZE 823 824 .globl swapper_pg_dir 825swapper_pg_dir: 826 .space PGD_TABLE_SIZE 827