head_64.S 19.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*
 *  PowerPC version
 *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
 *
 *  Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
 *    Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
 *  Adapted for Power Macintosh by Paul Mackerras.
 *  Low-level exception handlers and MMU support
 *  rewritten by Paul Mackerras.
 *    Copyright (C) 1996 Paul Mackerras.
 *
 *  Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
 *    Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
 *
15 16 17
 *  This file contains the entry point for the 64-bit kernel along
 *  with some early initialization code common to all 64-bit powerpc
 *  variants.
18 19 20 21 22 23 24 25
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version
 *  2 of the License, or (at your option) any later version.
 */

#include <linux/threads.h>
26
#include <asm/reg.h>
27 28 29 30 31 32 33 34
#include <asm/page.h>
#include <asm/mmu.h>
#include <asm/ppc_asm.h>
#include <asm/asm-offsets.h>
#include <asm/bug.h>
#include <asm/cputable.h>
#include <asm/setup.h>
#include <asm/hvcall.h>
35
#include <asm/iseries/lpar_map.h>
36
#include <asm/thread_info.h>
37
#include <asm/firmware.h>
38
#include <asm/page_64.h>
39
#include <asm/irqflags.h>
40
#include <asm/kvm_book3s_asm.h>
41

42 43 44
/* The physical memory is layed out such that the secondary processor
 * spin code sits at 0x0000...0x00ff. On server, the vectors follow
 * using the layout described in exceptions-64s.S
45 46 47 48
 */

/*
 * Entering into this code we make the following assumptions:
49 50
 *
 *  For pSeries or server processors:
51 52 53 54 55 56
 *   1. The MMU is off & open firmware is running in real mode.
 *   2. The kernel is entered at __start
 *
 *  For iSeries:
 *   1. The MMU is on (as it always is for iSeries)
 *   2. The kernel is entered at system_reset_iSeries
57 58 59 60
 *
 *  For Book3E processors:
 *   1. The MMU is on running in AS0 in a state defined in ePAPR
 *   2. The kernel is entered at __start
61 62 63 64 65 66 67 68
 */

	.text
	.globl  _stext
_stext:
_GLOBAL(__start)
	/* NOP this out unconditionally */
BEGIN_FTR_SECTION
69
	b	.__start_initialization_multiplatform
70 71 72 73 74
END_FTR_SECTION(0, 1)

	/* Catch branch to 0 in real mode */
	trap

75 76 77 78 79
	/* Secondary processors spin on this value until it becomes nonzero.
	 * When it does it contains the real address of the descriptor
	 * of the function that the cpu should jump to to continue
	 * initialization.
	 */
80 81 82 83 84 85 86 87 88 89
	.globl  __secondary_hold_spinloop
__secondary_hold_spinloop:
	.llong	0x0

	/* Secondary processors write this value with their cpu # */
	/* after they enter the spin loop immediately below.	  */
	.globl	__secondary_hold_acknowledge
__secondary_hold_acknowledge:
	.llong	0x0

90 91 92 93 94 95 96 97 98
#ifdef CONFIG_PPC_ISERIES
	/*
	 * At offset 0x20, there is a pointer to iSeries LPAR data.
	 * This is required by the hypervisor
	 */
	. = 0x20
	.llong hvReleaseData-KERNELBASE
#endif /* CONFIG_PPC_ISERIES */

99 100 101 102 103 104 105 106 107 108 109 110 111 112
#ifdef CONFIG_CRASH_DUMP
	/* This flag is set to 1 by a loader if the kernel should run
	 * at the loaded address instead of the linked address.  This
	 * is used by kexec-tools to keep the the kdump kernel in the
	 * crash_kernel region.  The loader is responsible for
	 * observing the alignment requirement.
	 */
	/* Do not move this variable as kexec-tools knows about it. */
	. = 0x5c
	.globl	__run_at_load
__run_at_load:
	.long	0x72756e30	/* "run0" -- relocate to 0 by default */
#endif

113 114
	. = 0x60
/*
115 116
 * The following code is used to hold secondary processors
 * in a spin loop after they have entered the kernel, but
117 118 119
 * before the bulk of the kernel has been relocated.  This code
 * is relocated to physical address 0x60 before prom_init is run.
 * All of it must fit below the first exception vector at 0x100.
120 121
 * Use .globl here not _GLOBAL because we want __secondary_hold
 * to be the actual text address, not a descriptor.
122
 */
123 124
	.globl	__secondary_hold
__secondary_hold:
125
#ifndef CONFIG_PPC_BOOK3E
126 127 128
	mfmsr	r24
	ori	r24,r24,MSR_RI
	mtmsrd	r24			/* RI on */
129
#endif
130
	/* Grab our physical cpu number */
131 132 133 134 135
	mr	r24,r3

	/* Tell the master cpu we're here */
	/* Relocation is off & we are located at an address less */
	/* than 0x100, so only need to grab low order offset.    */
136
	std	r24,__secondary_hold_acknowledge-_stext(0)
137 138 139
	sync

	/* All secondary cpus wait here until told to start. */
140
100:	ld	r4,__secondary_hold_spinloop-_stext(0)
141 142
	cmpdi	0,r4,0
	beq	100b
143

144
#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
145
	ld	r4,0(r4)		/* deref function descriptor */
146
	mtctr	r4
147
	mr	r3,r24
148
	li	r4,0
149
	bctr
150 151 152 153 154 155 156 157 158 159 160
#else
	BUG_OPCODE
#endif

/* This value is used to mark exception frames on the stack. */
	.section ".toc","aw"
exception_marker:
	.tc	ID_72656773_68657265[TC],0x7265677368657265
	.text

/*
161 162 163
 * On server, we include the exception vectors code here as it
 * relies on absolute addressing which is only possible within
 * this compilation unit
164
 */
165 166
#ifdef CONFIG_PPC_BOOK3S
#include "exceptions-64s.S"
167
#endif
168

169 170 171
/* KVM trampoline code needs to be close to the interrupt handlers */

#ifdef CONFIG_KVM_BOOK3S_64_HANDLER
172
#include "../kvm/book3s_rmhandlers.S"
173 174
#endif

175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
_GLOBAL(generic_secondary_thread_init)
	mr	r24,r3

	/* turn on 64-bit mode */
	bl	.enable_64b_mode

	/* get a valid TOC pointer, wherever we're mapped at */
	bl	.relative_toc

#ifdef CONFIG_PPC_BOOK3E
	/* Book3E initialization */
	mr	r3,r24
	bl	.book3e_secondary_thread_init
#endif
	b	generic_secondary_common_init
190 191

/*
O
Olof Johansson 已提交
192 193
 * On pSeries and most other platforms, secondary processors spin
 * in the following code.
194
 * At entry, r3 = this processor's number (physical cpu id)
195 196 197 198
 *
 * On Book3E, r4 = 1 to indicate that the initial TLB entry for
 * this core already exists (setup via some other mechanism such
 * as SCOM before entry).
199
 */
O
Olof Johansson 已提交
200
_GLOBAL(generic_secondary_smp_init)
201
	mr	r24,r3
202 203
	mr	r25,r4

204 205 206
	/* turn on 64-bit mode */
	bl	.enable_64b_mode

207
	/* get a valid TOC pointer, wherever we're mapped at */
208 209
	bl	.relative_toc

210 211 212 213 214 215 216 217
#ifdef CONFIG_PPC_BOOK3E
	/* Book3E initialization */
	mr	r3,r24
	mr	r4,r25
	bl	.book3e_secondary_core_init
#endif

generic_secondary_common_init:
218 219 220 221
	/* Set up a paca value for this processor. Since we have the
	 * physical cpu id in r24, we need to search the pacas to find
	 * which logical id maps to our physical one.
	 */
222 223
	LOAD_REG_ADDR(r13, paca)	/* Load paca pointer		 */
	ld	r13,0(r13)		/* Get base vaddr of paca array	 */
224 225 226 227 228 229 230 231 232 233 234 235
	li	r5,0			/* logical cpu id                */
1:	lhz	r6,PACAHWCPUID(r13)	/* Load HW procid from paca      */
	cmpw	r6,r24			/* Compare to our id             */
	beq	2f
	addi	r13,r13,PACA_SIZE	/* Loop to next PACA on miss     */
	addi	r5,r5,1
	cmpwi	r5,NR_CPUS
	blt	1b

	mr	r3,r24			/* not found, copy phys to r3	 */
	b	.kexec_wait		/* next kernel might do better	 */

236
2:	mtspr	SPRN_SPRG_PACA,r13	/* Save vaddr of paca in an SPRG */
237 238 239 240 241
#ifdef CONFIG_PPC_BOOK3E
	addi	r12,r13,PACA_EXTLB	/* and TLB exc frame in another  */
	mtspr	SPRN_SPRG_TLB_EXFRAME,r12
#endif

242 243 244 245 246 247
	/* From now on, r24 is expected to be logical cpuid */
	mr	r24,r5
3:	HMT_LOW
	lbz	r23,PACAPROCSTART(r13)	/* Test if this processor should */
					/* start.			 */

O
Olof Johansson 已提交
248 249 250 251 252 253
#ifndef CONFIG_SMP
	b	3b			/* Never go on non-SMP		 */
#else
	cmpwi	0,r23,0
	beq	3b			/* Loop until told to go	 */

254 255
	sync				/* order paca.run and cur_cpu_spec */

O
Olof Johansson 已提交
256
	/* See if we need to call a cpu state restore handler */
257
	LOAD_REG_ADDR(r23, cur_cpu_spec)
O
Olof Johansson 已提交
258 259 260 261 262 263 264 265 266
	ld	r23,0(r23)
	ld	r23,CPU_SPEC_RESTORE(r23)
	cmpdi	0,r23,0
	beq	4f
	ld	r23,0(r23)
	mtctr	r23
	bctrl

4:	/* Create a temp kernel stack for use before relocation is on.	*/
267 268 269
	ld	r1,PACAEMERGSP(r13)
	subi	r1,r1,STACK_FRAME_OVERHEAD

270
	b	__secondary_start
271 272
#endif

273 274 275 276
/*
 * Turn the MMU off.
 * Assumes we're mapped EA == RA if the MMU is on.
 */
277
#ifdef CONFIG_PPC_BOOK3S
278 279 280 281
_STATIC(__mmu_off)
	mfmsr	r3
	andi.	r0,r3,MSR_IR|MSR_DR
	beqlr
282
	mflr	r4
283 284 285 286 287 288
	andc	r3,r3,r0
	mtspr	SPRN_SRR0,r4
	mtspr	SPRN_SRR1,r3
	sync
	rfid
	b	.	/* prevent speculative execution */
289
#endif
290 291 292 293 294 295 296 297 298 299 300 301 302 303


/*
 * Here is our main kernel entry point. We support currently 2 kind of entries
 * depending on the value of r5.
 *
 *   r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
 *                 in r3...r7
 *   
 *   r5 == NULL -> kexec style entry. r3 is a physical pointer to the
 *                 DT block, r4 is a physical pointer to the kernel itself
 *
 */
_GLOBAL(__start_initialization_multiplatform)
304 305 306 307 308 309 310 311 312 313 314 315
	/* Make sure we are running in 64 bits mode */
	bl	.enable_64b_mode

	/* Get TOC pointer (current runtime address) */
	bl	.relative_toc

	/* find out where we are now */
	bcl	20,31,$+4
0:	mflr	r26			/* r26 = runtime addr here */
	addis	r26,r26,(_stext - 0b)@ha
	addi	r26,r26,(_stext - 0b)@l	/* current runtime base addr */

316 317 318 319
	/*
	 * Are we booted from a PROM Of-type client-interface ?
	 */
	cmpldi	cr0,r5,0
320 321 322
	beq	1f
	b	.__boot_from_prom		/* yes -> prom */
1:
323 324 325 326
	/* Save parameters */
	mr	r31,r3
	mr	r30,r4

327 328 329 330
#ifdef CONFIG_PPC_BOOK3E
	bl	.start_initialization_book3e
	b	.__after_prom_start
#else
331
	/* Setup some critical 970 SPRs before switching MMU off */
O
Olof Johansson 已提交
332 333 334 335 336 337 338
	mfspr	r0,SPRN_PVR
	srwi	r0,r0,16
	cmpwi	r0,0x39		/* 970 */
	beq	1f
	cmpwi	r0,0x3c		/* 970FX */
	beq	1f
	cmpwi	r0,0x44		/* 970MP */
339 340
	beq	1f
	cmpwi	r0,0x45		/* 970GX */
O
Olof Johansson 已提交
341 342 343
	bne	2f
1:	bl	.__cpu_preinit_ppc970
2:
344

345
	/* Switch off MMU if not already off */
346 347
	bl	.__mmu_off
	b	.__after_prom_start
348
#endif /* CONFIG_PPC_BOOK3E */
349

350
_INIT_STATIC(__boot_from_prom)
351
#ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE
352 353 354 355 356 357 358
	/* Save parameters */
	mr	r31,r3
	mr	r30,r4
	mr	r29,r5
	mr	r28,r6
	mr	r27,r7

359 360 361
	/*
	 * Align the stack to 16-byte boundary
	 * Depending on the size and layout of the ELF sections in the initial
362
	 * boot binary, the stack pointer may be unaligned on PowerMac
363
	 */
364 365
	rldicr	r1,r1,0,59

366 367 368 369 370 371
#ifdef CONFIG_RELOCATABLE
	/* Relocate code for where we are now */
	mr	r3,r26
	bl	.relocate
#endif

372 373 374 375 376 377 378 379
	/* Restore parameters */
	mr	r3,r31
	mr	r4,r30
	mr	r5,r29
	mr	r6,r28
	mr	r7,r27

	/* Do all of the interaction with OF client interface */
380
	mr	r8,r26
381
	bl	.prom_init
382 383 384 385
#endif /* #CONFIG_PPC_OF_BOOT_TRAMPOLINE */

	/* We never return. We also hit that trap if trying to boot
	 * from OF while CONFIG_PPC_OF_BOOT_TRAMPOLINE isn't selected */
386 387 388
	trap

_STATIC(__after_prom_start)
389 390 391 392
#ifdef CONFIG_RELOCATABLE
	/* process relocations for the final address of the kernel */
	lis	r25,PAGE_OFFSET@highest	/* compute virtual base of kernel */
	sldi	r25,r25,32
393
#ifdef CONFIG_CRASH_DUMP
394 395
	lwz	r7,__run_at_load-_stext(r26)
	cmplwi	cr0,r7,1	/* kdump kernel ? - stay where we are */
396 397 398 399
	bne	1f
	add	r25,r25,r26
#endif
1:	mr	r3,r25
400 401
	bl	.relocate
#endif
402 403

/*
404
 * We need to run with _stext at physical address PHYSICAL_START.
405 406 407 408 409
 * This will leave some code in the first 256B of
 * real memory, which are reserved for software use.
 *
 * Note: This process overwrites the OF exception vectors.
 */
410
	li	r3,0			/* target addr */
411 412 413
#ifdef CONFIG_PPC_BOOK3E
	tovirt(r3,r3)			/* on booke, we already run at PAGE_OFFSET */
#endif
414
	mr.	r4,r26			/* In some cases the loader may  */
415
	beq	9f			/* have already put us at zero */
416 417
	li	r6,0x100		/* Start offset, the first 0x100 */
					/* bytes were copied earlier.	 */
418 419 420
#ifdef CONFIG_PPC_BOOK3E
	tovirt(r6,r6)			/* on booke, we already run at PAGE_OFFSET */
#endif
421

422 423 424
#ifdef CONFIG_CRASH_DUMP
/*
 * Check if the kernel has to be running as relocatable kernel based on the
425
 * variable __run_at_load, if it is set the kernel is treated as relocatable
426 427
 * kernel, otherwise it will be moved to PHYSICAL_START
 */
428 429
	lwz	r7,__run_at_load-_stext(r26)
	cmplwi	cr0,r7,1
430 431 432 433 434 435 436 437 438
	bne	3f

	li	r5,__end_interrupts - _stext	/* just copy interrupts */
	b	5f
3:
#endif
	lis	r5,(copy_to_here - _stext)@ha
	addi	r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */

439 440 441
	bl	.copy_and_flush		/* copy the first n bytes	 */
					/* this includes the code being	 */
					/* executed here.		 */
442 443 444
	addis	r8,r3,(4f - _stext)@ha	/* Jump to the copy of this code */
	addi	r8,r8,(4f - _stext)@l	/* that we just made */
	mtctr	r8
445 446
	bctr

447 448
p_end:	.llong	_end - _stext

449 450 451
4:	/* Now copy the rest of the kernel up to _end */
	addis	r5,r26,(p_end - _stext)@ha
	ld	r5,(p_end - _stext)@l(r5)	/* get _end */
452
5:	bl	.copy_and_flush		/* copy the rest */
453 454 455

9:	b	.start_here_multiplatform

456 457 458 459 460 461 462 463 464 465 466
/*
 * Copy routine used to copy the kernel to start at physical address 0
 * and flush and invalidate the caches as needed.
 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
 *
 * Note: this routine *only* clobbers r0, r6 and lr
 */
_GLOBAL(copy_and_flush)
	addi	r5,r5,-8
	addi	r6,r6,-8
467
4:	li	r0,8			/* Use the smallest common	*/
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
					/* denominator cache line	*/
					/* size.  This results in	*/
					/* extra cache line flushes	*/
					/* but operation is correct.	*/
					/* Can't get cache line size	*/
					/* from NACA as it is being	*/
					/* moved too.			*/

	mtctr	r0			/* put # words/line in ctr	*/
3:	addi	r6,r6,8			/* copy a cache line		*/
	ldx	r0,r6,r4
	stdx	r0,r6,r3
	bdnz	3b
	dcbst	r6,r3			/* write it to memory		*/
	sync
	icbi	r6,r3			/* flush the icache line	*/
	cmpld	0,r6,r5
	blt	4b
	sync
	addi	r5,r5,8
	addi	r6,r6,8
	blr

.align 8
copy_to_here:

#ifdef CONFIG_SMP
#ifdef CONFIG_PPC_PMAC
/*
 * On PowerMac, secondary processors starts from the reset vector, which
 * is temporarily turned into a call to one of the functions below.
 */
	.section ".text";
	.align 2 ;

503 504 505 506 507 508 509 510 511 512 513
	.globl	__secondary_start_pmac_0
__secondary_start_pmac_0:
	/* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
	li	r24,0
	b	1f
	li	r24,1
	b	1f
	li	r24,2
	b	1f
	li	r24,3
1:
514 515 516 517 518
	
_GLOBAL(pmac_secondary_start)
	/* turn on 64-bit mode */
	bl	.enable_64b_mode

519 520 521 522 523 524 525 526 527
	li	r0,0
	mfspr	r3,SPRN_HID4
	rldimi	r3,r0,40,23	/* clear bit 23 (rm_ci) */
	sync
	mtspr	SPRN_HID4,r3
	isync
	sync
	slbia

528 529 530
	/* get TOC pointer (real address) */
	bl	.relative_toc

531
	/* Copy some CPU settings from CPU 0 */
O
Olof Johansson 已提交
532
	bl	.__restore_cpu_ppc970
533 534 535 536 537 538 539

	/* pSeries do that early though I don't think we really need it */
	mfmsr	r3
	ori	r3,r3,MSR_RI
	mtmsrd	r3			/* RI on */

	/* Set up a paca value for this processor. */
540 541
	LOAD_REG_ADDR(r4,paca)		/* Load paca pointer		*/
	ld	r4,0(r4)		/* Get base vaddr of paca array	*/
542
	mulli	r13,r24,PACA_SIZE	/* Calculate vaddr of right paca */
543
	add	r13,r13,r4		/* for this processor.		*/
544
	mtspr	SPRN_SPRG_PACA,r13	/* Save vaddr of paca in an SPRG*/
545 546 547 548 549

	/* Create a temp kernel stack for use before relocation is on.	*/
	ld	r1,PACAEMERGSP(r13)
	subi	r1,r1,STACK_FRAME_OVERHEAD

550
	b	__secondary_start
551 552 553 554 555 556 557 558 559 560 561

#endif /* CONFIG_PPC_PMAC */

/*
 * This function is called after the master CPU has released the
 * secondary processors.  The execution environment is relocation off.
 * The paca for this processor has the following fields initialized at
 * this point:
 *   1. Processor number
 *   2. Segment table pointer (virtual address)
 * On entry the following are set:
562 563 564 565
 *   r1	       = stack pointer.  vaddr for iSeries, raddr (temp stack) for pSeries
 *   r24       = cpu# (in Linux terms)
 *   r13       = paca virtual address
 *   SPRG_PACA = paca virtual address
566
 */
567 568 569
	.section ".text";
	.align 2 ;

570
	.globl	__secondary_start
571
__secondary_start:
572 573
	/* Set thread priority to MEDIUM */
	HMT_MEDIUM
574 575

	/* Initialize the kernel stack.  Just a repeat for iSeries.	 */
576
	LOAD_REG_ADDR(r3, current_set)
577 578 579 580 581
	sldi	r28,r24,3		/* get current_set[cpu#]	 */
	ldx	r1,r3,r28
	addi	r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
	std	r1,PACAKSAVE(r13)

582 583 584
	/* Do early setup for that CPU (stab, slb, hash table pointer) */
	bl	.early_setup_secondary

585
	/* Clear backchain so we get nice backtraces */
586 587 588 589
	li	r7,0
	mtlr	r7

	/* enable MMU and jump to start_secondary */
590 591
	LOAD_REG_ADDR(r3, .start_secondary_prolog)
	LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
592
#ifdef CONFIG_PPC_ISERIES
593
BEGIN_FW_FTR_SECTION
594
	ori	r4,r4,MSR_EE
595 596
	li	r8,1
	stb	r8,PACAHARDIRQEN(r13)
597
END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
598
#endif
599 600 601
BEGIN_FW_FTR_SECTION
	stb	r7,PACAHARDIRQEN(r13)
END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
602
	stb	r7,PACASOFTIRQEN(r13)
603

604 605
	mtspr	SPRN_SRR0,r3
	mtspr	SPRN_SRR1,r4
606
	RFI
607 608 609 610
	b	.	/* prevent speculative execution */

/* 
 * Running with relocation on at this point.  All we want to do is
611 612
 * zero the stack back-chain pointer and get the TOC virtual address
 * before going into C code.
613 614
 */
_GLOBAL(start_secondary_prolog)
615
	ld	r2,PACATOC(r13)
616 617 618
	li	r3,0
	std	r3,0(r1)		/* Zero the stack frame pointer	*/
	bl	.start_secondary
619
	b	.
620 621 622 623 624 625 626 627 628 629 630
/*
 * Reset stack pointer and call start_secondary
 * to continue with online operation when woken up
 * from cede in cpu offline.
 */
_GLOBAL(start_secondary_resume)
	ld	r1,PACAKSAVE(r13)	/* Reload kernel stack pointer */
	li	r3,0
	std	r3,0(r1)		/* Zero the stack frame pointer	*/
	bl	.start_secondary
	b	.
631 632 633 634 635 636 637
#endif

/*
 * This subroutine clobbers r11 and r12
 */
_GLOBAL(enable_64b_mode)
	mfmsr	r11			/* grab the current MSR */
638 639 640 641
#ifdef CONFIG_PPC_BOOK3E
	oris	r11,r11,0x8000		/* CM bit set, we'll set ICM later */
	mtmsr	r11
#else /* CONFIG_PPC_BOOK3E */
642 643
	li	r12,(MSR_SF | MSR_ISF)@highest
	sldi	r12,r12,48
644 645 646
	or	r11,r11,r12
	mtmsrd	r11
	isync
647
#endif
648 649
	blr

650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665
/*
 * This puts the TOC pointer into r2, offset by 0x8000 (as expected
 * by the toolchain).  It computes the correct value for wherever we
 * are running at the moment, using position-independent code.
 */
_GLOBAL(relative_toc)
	mflr	r0
	bcl	20,31,$+4
0:	mflr	r9
	ld	r2,(p_toc - 0b)(r9)
	add	r2,r2,r9
	mtlr	r0
	blr

p_toc:	.llong	__toc_start + 0x8000 - 0b

666 667 668
/*
 * This is where the main kernel code starts.
 */
669
_INIT_STATIC(start_here_multiplatform)
670 671
	/* set up the TOC (real address) */
	bl	.relative_toc
672 673 674 675 676 677

	/* Clear out the BSS. It may have been done in prom_init,
	 * already but that's irrelevant since prom_init will soon
	 * be detached from the kernel completely. Besides, we need
	 * to clear it now for kexec-style entry.
	 */
678 679
	LOAD_REG_ADDR(r11,__bss_stop)
	LOAD_REG_ADDR(r8,__bss_start)
680 681
	sub	r11,r11,r8		/* bss size			*/
	addi	r11,r11,7		/* round up to an even double word */
682
	srdi.	r11,r11,3		/* shift right by 3		*/
683 684 685 686 687 688 689 690
	beq	4f
	addi	r8,r8,-8
	li	r0,0
	mtctr	r11			/* zero this many doublewords	*/
3:	stdu	r0,8(r8)
	bdnz	3b
4:

691
#ifndef CONFIG_PPC_BOOK3E
692 693 694
	mfmsr	r6
	ori	r6,r6,MSR_RI
	mtmsrd	r6			/* RI on */
695
#endif
696

697 698 699 700 701 702 703
#ifdef CONFIG_RELOCATABLE
	/* Save the physical address we're running at in kernstart_addr */
	LOAD_REG_ADDR(r4, kernstart_addr)
	clrldi	r0,r25,2
	std	r0,0(r4)
#endif

704
	/* The following gets the stack set up with the regs */
705 706 707 708 709
	/* pointing to the real addr of the kernel stack.  This is   */
	/* all done to support the C function call below which sets  */
	/* up the htab.  This is done because we have relocated the  */
	/* kernel but are still running in real mode. */

710
	LOAD_REG_ADDR(r3,init_thread_union)
711

712
	/* set up a stack pointer */
713 714 715 716 717 718 719 720 721
	addi	r1,r3,THREAD_SIZE
	li	r0,0
	stdu	r0,-STACK_FRAME_OVERHEAD(r1)

	/* Do very early kernel initializations, including initial hash table,
	 * stab and slb setup before we turn on relocation.	*/

	/* Restore parameters passed from prom_init/kexec */
	mr	r3,r31
722
	bl	.early_setup		/* also sets r13 and SPRG_PACA */
723

724 725
	LOAD_REG_ADDR(r3, .start_here_common)
	ld	r4,PACAKMSR(r13)
726 727
	mtspr	SPRN_SRR0,r3
	mtspr	SPRN_SRR1,r4
728
	RFI
729 730 731
	b	.	/* prevent speculative execution */
	
	/* This is where all platforms converge execution */
732
_INIT_GLOBAL(start_here_common)
733
	/* relocation is on at this point */
734
	std	r1,PACAKSAVE(r13)
735

736
	/* Load the TOC (virtual address) */
737 738 739 740 741 742 743
	ld	r2,PACATOC(r13)

	bl	.setup_system

	/* Load up the kernel context */
5:
	li	r5,0
744 745 746
	stb	r5,PACASOFTIRQEN(r13)	/* Soft Disabled */
#ifdef CONFIG_PPC_ISERIES
BEGIN_FW_FTR_SECTION
747
	mfmsr	r5
748
	ori	r5,r5,MSR_EE		/* Hard Enabled on iSeries*/
749
	mtmsrd	r5
750
	li	r5,1
751
END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
752
#endif
753
	stb	r5,PACAHARDIRQEN(r13)	/* Hard Disabled on others */
754

755
	bl	.start_kernel
756

757 758
	/* Not reached */
	BUG_OPCODE
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773

/*
 * We put a few things here that have to be page-aligned.
 * This stuff goes at the beginning of the bss, which is page-aligned.
 */
	.section ".bss"

	.align	PAGE_SHIFT

	.globl	empty_zero_page
empty_zero_page:
	.space	PAGE_SIZE

	.globl	swapper_pg_dir
swapper_pg_dir:
774
	.space	PGD_TABLE_SIZE