xref: /openbmc/linux/arch/powerpc/kernel/head_44x.S (revision 3d37ef41)
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Kernel execution entry point code.
4 *
5 *    Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org>
6 *      Initial PowerPC version.
7 *    Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu>
8 *      Rewritten for PReP
9 *    Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au>
10 *      Low-level exception handers, MMU support, and rewrite.
11 *    Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
12 *      PowerPC 8xx modifications.
13 *    Copyright (c) 1998-1999 TiVo, Inc.
14 *      PowerPC 403GCX modifications.
15 *    Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
16 *      PowerPC 403GCX/405GP modifications.
17 *    Copyright 2000 MontaVista Software Inc.
18 *	PPC405 modifications
19 *      PowerPC 403GCX/405GP modifications.
20 * 	Author: MontaVista Software, Inc.
21 *         	frank_rowand@mvista.com or source@mvista.com
22 * 	   	debbie_chu@mvista.com
23 *    Copyright 2002-2005 MontaVista Software, Inc.
24 *      PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org>
25 */
26
27#include <linux/init.h>
28#include <linux/pgtable.h>
29#include <asm/processor.h>
30#include <asm/page.h>
31#include <asm/mmu.h>
32#include <asm/cputable.h>
33#include <asm/thread_info.h>
34#include <asm/ppc_asm.h>
35#include <asm/asm-offsets.h>
36#include <asm/ptrace.h>
37#include <asm/synch.h>
38#include <asm/export.h>
39#include <asm/code-patching-asm.h>
40#include "head_booke.h"
41
42
43/* As with the other PowerPC ports, it is expected that when code
44 * execution begins here, the following registers contain valid, yet
45 * optional, information:
46 *
47 *   r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
48 *   r4 - Starting address of the init RAM disk
49 *   r5 - Ending address of the init RAM disk
50 *   r6 - Start of kernel command line string (e.g. "mem=128")
51 *   r7 - End of kernel command line string
52 *
53 */
54	__HEAD
55_ENTRY(_stext);
56_ENTRY(_start);
57	/*
58	 * Reserve a word at a fixed location to store the address
59	 * of abatron_pteptrs
60	 */
61	nop
62	mr	r31,r3		/* save device tree ptr */
63	li	r24,0		/* CPU number */
64
65#ifdef CONFIG_RELOCATABLE
66/*
67 * Relocate ourselves to the current runtime address.
68 * This is called only by the Boot CPU.
69 * "relocate" is called with our current runtime virutal
70 * address.
71 * r21 will be loaded with the physical runtime address of _stext
72 */
73	bl	0f				/* Get our runtime address */
740:	mflr	r21				/* Make it accessible */
75	addis	r21,r21,(_stext - 0b)@ha
76	addi	r21,r21,(_stext - 0b)@l 	/* Get our current runtime base */
77
78	/*
79	 * We have the runtime (virutal) address of our base.
80	 * We calculate our shift of offset from a 256M page.
81	 * We could map the 256M page we belong to at PAGE_OFFSET and
82	 * get going from there.
83	 */
84	lis	r4,KERNELBASE@h
85	ori	r4,r4,KERNELBASE@l
86	rlwinm	r6,r21,0,4,31			/* r6 = PHYS_START % 256M */
87	rlwinm	r5,r4,0,4,31			/* r5 = KERNELBASE % 256M */
88	subf	r3,r5,r6			/* r3 = r6 - r5 */
89	add	r3,r4,r3			/* Required Virutal Address */
90
91	bl	relocate
92#endif
93
94	bl	init_cpu_state
95
96	/*
97	 * This is where the main kernel code starts.
98	 */
99
100	/* ptr to current */
101	lis	r2,init_task@h
102	ori	r2,r2,init_task@l
103
104	/* ptr to current thread */
105	addi	r4,r2,THREAD	/* init task's THREAD */
106	mtspr	SPRN_SPRG_THREAD,r4
107
108	/* stack */
109	lis	r1,init_thread_union@h
110	ori	r1,r1,init_thread_union@l
111	li	r0,0
112	stwu	r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
113
114	bl	early_init
115
116#ifdef CONFIG_RELOCATABLE
117	/*
118	 * Relocatable kernel support based on processing of dynamic
119	 * relocation entries.
120	 *
121	 * r25 will contain RPN/ERPN for the start address of memory
122	 * r21 will contain the current offset of _stext
123	 */
124	lis	r3,kernstart_addr@ha
125	la	r3,kernstart_addr@l(r3)
126
127	/*
128	 * Compute the kernstart_addr.
129	 * kernstart_addr => (r6,r8)
130	 * kernstart_addr & ~0xfffffff => (r6,r7)
131	 */
132	rlwinm	r6,r25,0,28,31	/* ERPN. Bits 32-35 of Address */
133	rlwinm	r7,r25,0,0,3	/* RPN - assuming 256 MB page size */
134	rlwinm	r8,r21,0,4,31	/* r8 = (_stext & 0xfffffff) */
135	or	r8,r7,r8	/* Compute the lower 32bit of kernstart_addr */
136
137	/* Store kernstart_addr */
138	stw	r6,0(r3)	/* higher 32bit */
139	stw	r8,4(r3)	/* lower 32bit  */
140
141	/*
142	 * Compute the virt_phys_offset :
143	 * virt_phys_offset = stext.run - kernstart_addr
144	 *
145	 * stext.run = (KERNELBASE & ~0xfffffff) + (kernstart_addr & 0xfffffff)
146	 * When we relocate, we have :
147	 *
148	 *	(kernstart_addr & 0xfffffff) = (stext.run & 0xfffffff)
149	 *
150	 * hence:
151	 *  virt_phys_offset = (KERNELBASE & ~0xfffffff) - (kernstart_addr & ~0xfffffff)
152	 *
153	 */
154
155	/* KERNELBASE&~0xfffffff => (r4,r5) */
156	li	r4, 0		/* higer 32bit */
157	lis	r5,KERNELBASE@h
158	rlwinm	r5,r5,0,0,3	/* Align to 256M, lower 32bit */
159
160	/*
161	 * 64bit subtraction.
162	 */
163	subfc	r5,r7,r5
164	subfe	r4,r6,r4
165
166	/* Store virt_phys_offset */
167	lis	r3,virt_phys_offset@ha
168	la	r3,virt_phys_offset@l(r3)
169
170	stw	r4,0(r3)
171	stw	r5,4(r3)
172
173#elif defined(CONFIG_DYNAMIC_MEMSTART)
174	/*
175	 * Mapping based, page aligned dynamic kernel loading.
176	 *
177	 * r25 will contain RPN/ERPN for the start address of memory
178	 *
179	 * Add the difference between KERNELBASE and PAGE_OFFSET to the
180	 * start of physical memory to get kernstart_addr.
181	 */
182	lis	r3,kernstart_addr@ha
183	la	r3,kernstart_addr@l(r3)
184
185	lis	r4,KERNELBASE@h
186	ori	r4,r4,KERNELBASE@l
187	lis	r5,PAGE_OFFSET@h
188	ori	r5,r5,PAGE_OFFSET@l
189	subf	r4,r5,r4
190
191	rlwinm	r6,r25,0,28,31	/* ERPN */
192	rlwinm	r7,r25,0,0,3	/* RPN - assuming 256 MB page size */
193	add	r7,r7,r4
194
195	stw	r6,0(r3)
196	stw	r7,4(r3)
197#endif
198
199/*
200 * Decide what sort of machine this is and initialize the MMU.
201 */
202#ifdef CONFIG_KASAN
203	bl	kasan_early_init
204#endif
205	li	r3,0
206	mr	r4,r31
207	bl	machine_init
208	bl	MMU_init
209
210	/* Setup PTE pointers for the Abatron bdiGDB */
211	lis	r6, swapper_pg_dir@h
212	ori	r6, r6, swapper_pg_dir@l
213	lis	r5, abatron_pteptrs@h
214	ori	r5, r5, abatron_pteptrs@l
215	lis	r4, KERNELBASE@h
216	ori	r4, r4, KERNELBASE@l
217	stw	r5, 0(r4)	/* Save abatron_pteptrs at a fixed location */
218	stw	r6, 0(r5)
219
220	/* Clear the Machine Check Syndrome Register */
221	li	r0,0
222	mtspr	SPRN_MCSR,r0
223
224	/* Let's move on */
225	lis	r4,start_kernel@h
226	ori	r4,r4,start_kernel@l
227	lis	r3,MSR_KERNEL@h
228	ori	r3,r3,MSR_KERNEL@l
229	mtspr	SPRN_SRR0,r4
230	mtspr	SPRN_SRR1,r3
231	rfi			/* change context and jump to start_kernel */
232
233/*
234 * Interrupt vector entry code
235 *
236 * The Book E MMUs are always on so we don't need to handle
237 * interrupts in real mode as with previous PPC processors. In
238 * this case we handle interrupts in the kernel virtual address
239 * space.
240 *
241 * Interrupt vectors are dynamically placed relative to the
242 * interrupt prefix as determined by the address of interrupt_base.
243 * The interrupt vectors offsets are programmed using the labels
244 * for each interrupt vector entry.
245 *
246 * Interrupt vectors must be aligned on a 16 byte boundary.
247 * We align on a 32 byte cache line boundary for good measure.
248 */
249
250interrupt_base:
251	/* Critical Input Interrupt */
252	CRITICAL_EXCEPTION(0x0100, CRITICAL, CriticalInput, unknown_exception)
253
254	/* Machine Check Interrupt */
255	CRITICAL_EXCEPTION(0x0200, MACHINE_CHECK, MachineCheck, \
256			   machine_check_exception)
257	MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception)
258
259	/* Data Storage Interrupt */
260	DATA_STORAGE_EXCEPTION
261
262		/* Instruction Storage Interrupt */
263	INSTRUCTION_STORAGE_EXCEPTION
264
265	/* External Input Interrupt */
266	EXCEPTION(0x0500, BOOKE_INTERRUPT_EXTERNAL, ExternalInput, do_IRQ)
267
268	/* Alignment Interrupt */
269	ALIGNMENT_EXCEPTION
270
271	/* Program Interrupt */
272	PROGRAM_EXCEPTION
273
274	/* Floating Point Unavailable Interrupt */
275#ifdef CONFIG_PPC_FPU
276	FP_UNAVAILABLE_EXCEPTION
277#else
278	EXCEPTION(0x2010, BOOKE_INTERRUPT_FP_UNAVAIL, \
279		  FloatingPointUnavailable, unknown_exception)
280#endif
281	/* System Call Interrupt */
282	START_EXCEPTION(SystemCall)
283	SYSCALL_ENTRY   0xc00 BOOKE_INTERRUPT_SYSCALL
284
285	/* Auxiliary Processor Unavailable Interrupt */
286	EXCEPTION(0x2020, BOOKE_INTERRUPT_AP_UNAVAIL, \
287		  AuxillaryProcessorUnavailable, unknown_exception)
288
289	/* Decrementer Interrupt */
290	DECREMENTER_EXCEPTION
291
292	/* Fixed Internal Timer Interrupt */
293	/* TODO: Add FIT support */
294	EXCEPTION(0x1010, BOOKE_INTERRUPT_FIT, FixedIntervalTimer, unknown_exception)
295
296	/* Watchdog Timer Interrupt */
297	/* TODO: Add watchdog support */
298#ifdef CONFIG_BOOKE_WDT
299	CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, WatchdogException)
300#else
301	CRITICAL_EXCEPTION(0x1020, WATCHDOG, WatchdogTimer, unknown_exception)
302#endif
303
304	/* Data TLB Error Interrupt */
305	START_EXCEPTION(DataTLBError44x)
306	mtspr	SPRN_SPRG_WSCRATCH0, r10		/* Save some working registers */
307	mtspr	SPRN_SPRG_WSCRATCH1, r11
308	mtspr	SPRN_SPRG_WSCRATCH2, r12
309	mtspr	SPRN_SPRG_WSCRATCH3, r13
310	mfcr	r11
311	mtspr	SPRN_SPRG_WSCRATCH4, r11
312	mfspr	r10, SPRN_DEAR		/* Get faulting address */
313
314	/* If we are faulting a kernel address, we have to use the
315	 * kernel page tables.
316	 */
317	lis	r11, PAGE_OFFSET@h
318	cmplw	r10, r11
319	blt+	3f
320	lis	r11, swapper_pg_dir@h
321	ori	r11, r11, swapper_pg_dir@l
322
323	mfspr	r12,SPRN_MMUCR
324	rlwinm	r12,r12,0,0,23		/* Clear TID */
325
326	b	4f
327
328	/* Get the PGD for the current thread */
3293:
330	mfspr	r11,SPRN_SPRG_THREAD
331	lwz	r11,PGDIR(r11)
332
333	/* Load PID into MMUCR TID */
334	mfspr	r12,SPRN_MMUCR
335	mfspr   r13,SPRN_PID		/* Get PID */
336	rlwimi	r12,r13,0,24,31		/* Set TID */
337
3384:
339	mtspr	SPRN_MMUCR,r12
340
341	/* Mask of required permission bits. Note that while we
342	 * do copy ESR:ST to _PAGE_RW position as trying to write
343	 * to an RO page is pretty common, we don't do it with
344	 * _PAGE_DIRTY. We could do it, but it's a fairly rare
345	 * event so I'd rather take the overhead when it happens
346	 * rather than adding an instruction here. We should measure
347	 * whether the whole thing is worth it in the first place
348	 * as we could avoid loading SPRN_ESR completely in the first
349	 * place...
350	 *
351	 * TODO: Is it worth doing that mfspr & rlwimi in the first
352	 *       place or can we save a couple of instructions here ?
353	 */
354	mfspr	r12,SPRN_ESR
355	li	r13,_PAGE_PRESENT|_PAGE_ACCESSED
356	rlwimi	r13,r12,10,30,30
357
358	/* Load the PTE */
359	/* Compute pgdir/pmd offset */
360	rlwinm  r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
361	lwzx	r11, r12, r11		/* Get pgd/pmd entry */
362	rlwinm.	r12, r11, 0, 0, 20	/* Extract pt base address */
363	beq	2f			/* Bail if no table */
364
365	/* Compute pte address */
366	rlwimi  r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
367	lwz	r11, 0(r12)		/* Get high word of pte entry */
368	lwz	r12, 4(r12)		/* Get low word of pte entry */
369
370	lis	r10,tlb_44x_index@ha
371
372	andc.	r13,r13,r12		/* Check permission */
373
374	/* Load the next available TLB index */
375	lwz	r13,tlb_44x_index@l(r10)
376
377	bne	2f			/* Bail if permission mismatch */
378
379	/* Increment, rollover, and store TLB index */
380	addi	r13,r13,1
381
382	patch_site 0f, patch__tlb_44x_hwater_D
383	/* Compare with watermark (instruction gets patched) */
3840:	cmpwi	0,r13,1			/* reserve entries */
385	ble	5f
386	li	r13,0
3875:
388	/* Store the next available TLB index */
389	stw	r13,tlb_44x_index@l(r10)
390
391	/* Re-load the faulting address */
392	mfspr	r10,SPRN_DEAR
393
394	 /* Jump to common tlb load */
395	b	finish_tlb_load_44x
396
3972:
398	/* The bailout.  Restore registers to pre-exception conditions
399	 * and call the heavyweights to help us out.
400	 */
401	mfspr	r11, SPRN_SPRG_RSCRATCH4
402	mtcr	r11
403	mfspr	r13, SPRN_SPRG_RSCRATCH3
404	mfspr	r12, SPRN_SPRG_RSCRATCH2
405	mfspr	r11, SPRN_SPRG_RSCRATCH1
406	mfspr	r10, SPRN_SPRG_RSCRATCH0
407	b	DataStorage
408
409	/* Instruction TLB Error Interrupt */
410	/*
411	 * Nearly the same as above, except we get our
412	 * information from different registers and bailout
413	 * to a different point.
414	 */
415	START_EXCEPTION(InstructionTLBError44x)
416	mtspr	SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
417	mtspr	SPRN_SPRG_WSCRATCH1, r11
418	mtspr	SPRN_SPRG_WSCRATCH2, r12
419	mtspr	SPRN_SPRG_WSCRATCH3, r13
420	mfcr	r11
421	mtspr	SPRN_SPRG_WSCRATCH4, r11
422	mfspr	r10, SPRN_SRR0		/* Get faulting address */
423
424	/* If we are faulting a kernel address, we have to use the
425	 * kernel page tables.
426	 */
427	lis	r11, PAGE_OFFSET@h
428	cmplw	r10, r11
429	blt+	3f
430	lis	r11, swapper_pg_dir@h
431	ori	r11, r11, swapper_pg_dir@l
432
433	mfspr	r12,SPRN_MMUCR
434	rlwinm	r12,r12,0,0,23		/* Clear TID */
435
436	b	4f
437
438	/* Get the PGD for the current thread */
4393:
440	mfspr	r11,SPRN_SPRG_THREAD
441	lwz	r11,PGDIR(r11)
442
443	/* Load PID into MMUCR TID */
444	mfspr	r12,SPRN_MMUCR
445	mfspr   r13,SPRN_PID		/* Get PID */
446	rlwimi	r12,r13,0,24,31		/* Set TID */
447
4484:
449	mtspr	SPRN_MMUCR,r12
450
451	/* Make up the required permissions */
452	li	r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
453
454	/* Compute pgdir/pmd offset */
455	rlwinm 	r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
456	lwzx	r11, r12, r11		/* Get pgd/pmd entry */
457	rlwinm.	r12, r11, 0, 0, 20	/* Extract pt base address */
458	beq	2f			/* Bail if no table */
459
460	/* Compute pte address */
461	rlwimi	r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
462	lwz	r11, 0(r12)		/* Get high word of pte entry */
463	lwz	r12, 4(r12)		/* Get low word of pte entry */
464
465	lis	r10,tlb_44x_index@ha
466
467	andc.	r13,r13,r12		/* Check permission */
468
469	/* Load the next available TLB index */
470	lwz	r13,tlb_44x_index@l(r10)
471
472	bne	2f			/* Bail if permission mismatch */
473
474	/* Increment, rollover, and store TLB index */
475	addi	r13,r13,1
476
477	patch_site 0f, patch__tlb_44x_hwater_I
478	/* Compare with watermark (instruction gets patched) */
4790:	cmpwi	0,r13,1			/* reserve entries */
480	ble	5f
481	li	r13,0
4825:
483	/* Store the next available TLB index */
484	stw	r13,tlb_44x_index@l(r10)
485
486	/* Re-load the faulting address */
487	mfspr	r10,SPRN_SRR0
488
489	/* Jump to common TLB load point */
490	b	finish_tlb_load_44x
491
4922:
493	/* The bailout.  Restore registers to pre-exception conditions
494	 * and call the heavyweights to help us out.
495	 */
496	mfspr	r11, SPRN_SPRG_RSCRATCH4
497	mtcr	r11
498	mfspr	r13, SPRN_SPRG_RSCRATCH3
499	mfspr	r12, SPRN_SPRG_RSCRATCH2
500	mfspr	r11, SPRN_SPRG_RSCRATCH1
501	mfspr	r10, SPRN_SPRG_RSCRATCH0
502	b	InstructionStorage
503
504/*
505 * Both the instruction and data TLB miss get to this
506 * point to load the TLB.
507 * 	r10 - EA of fault
508 * 	r11 - PTE high word value
509 *	r12 - PTE low word value
510 *	r13 - TLB index
511 *	MMUCR - loaded with proper value when we get here
512 *	Upon exit, we reload everything and RFI.
513 */
514finish_tlb_load_44x:
515	/* Combine RPN & ERPN an write WS 0 */
516	rlwimi	r11,r12,0,0,31-PAGE_SHIFT
517	tlbwe	r11,r13,PPC44x_TLB_XLAT
518
519	/*
520	 * Create WS1. This is the faulting address (EPN),
521	 * page size, and valid flag.
522	 */
523	li	r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE
524	/* Insert valid and page size */
525	rlwimi	r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31
526	tlbwe	r10,r13,PPC44x_TLB_PAGEID	/* Write PAGEID */
527
528	/* And WS 2 */
529	li	r10,0xf85			/* Mask to apply from PTE */
530	rlwimi	r10,r12,29,30,30		/* DIRTY -> SW position */
531	and	r11,r12,r10			/* Mask PTE bits to keep */
532	andi.	r10,r12,_PAGE_USER		/* User page ? */
533	beq	1f				/* nope, leave U bits empty */
534	rlwimi	r11,r11,3,26,28			/* yes, copy S bits to U */
5351:	tlbwe	r11,r13,PPC44x_TLB_ATTRIB	/* Write ATTRIB */
536
537	/* Done...restore registers and get out of here.
538	*/
539	mfspr	r11, SPRN_SPRG_RSCRATCH4
540	mtcr	r11
541	mfspr	r13, SPRN_SPRG_RSCRATCH3
542	mfspr	r12, SPRN_SPRG_RSCRATCH2
543	mfspr	r11, SPRN_SPRG_RSCRATCH1
544	mfspr	r10, SPRN_SPRG_RSCRATCH0
545	rfi					/* Force context change */
546
547/* TLB error interrupts for 476
548 */
549#ifdef CONFIG_PPC_47x
550	START_EXCEPTION(DataTLBError47x)
551	mtspr	SPRN_SPRG_WSCRATCH0,r10	/* Save some working registers */
552	mtspr	SPRN_SPRG_WSCRATCH1,r11
553	mtspr	SPRN_SPRG_WSCRATCH2,r12
554	mtspr	SPRN_SPRG_WSCRATCH3,r13
555	mfcr	r11
556	mtspr	SPRN_SPRG_WSCRATCH4,r11
557	mfspr	r10,SPRN_DEAR		/* Get faulting address */
558
559	/* If we are faulting a kernel address, we have to use the
560	 * kernel page tables.
561	 */
562	lis	r11,PAGE_OFFSET@h
563	cmplw	cr0,r10,r11
564	blt+	3f
565	lis	r11,swapper_pg_dir@h
566	ori	r11,r11, swapper_pg_dir@l
567	li	r12,0			/* MMUCR = 0 */
568	b	4f
569
570	/* Get the PGD for the current thread and setup MMUCR */
5713:	mfspr	r11,SPRN_SPRG3
572	lwz	r11,PGDIR(r11)
573	mfspr   r12,SPRN_PID		/* Get PID */
5744:	mtspr	SPRN_MMUCR,r12		/* Set MMUCR */
575
576	/* Mask of required permission bits. Note that while we
577	 * do copy ESR:ST to _PAGE_RW position as trying to write
578	 * to an RO page is pretty common, we don't do it with
579	 * _PAGE_DIRTY. We could do it, but it's a fairly rare
580	 * event so I'd rather take the overhead when it happens
581	 * rather than adding an instruction here. We should measure
582	 * whether the whole thing is worth it in the first place
583	 * as we could avoid loading SPRN_ESR completely in the first
584	 * place...
585	 *
586	 * TODO: Is it worth doing that mfspr & rlwimi in the first
587	 *       place or can we save a couple of instructions here ?
588	 */
589	mfspr	r12,SPRN_ESR
590	li	r13,_PAGE_PRESENT|_PAGE_ACCESSED
591	rlwimi	r13,r12,10,30,30
592
593	/* Load the PTE */
594	/* Compute pgdir/pmd offset */
595	rlwinm  r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
596	lwzx	r11,r12,r11		/* Get pgd/pmd entry */
597
598	/* Word 0 is EPN,V,TS,DSIZ */
599	li	r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
600	rlwimi	r10,r12,0,32-PAGE_SHIFT,31	/* Insert valid and page size*/
601	li	r12,0
602	tlbwe	r10,r12,0
603
604	/* XXX can we do better ? Need to make sure tlbwe has established
605	 * latch V bit in MMUCR0 before the PTE is loaded further down */
606#ifdef CONFIG_SMP
607	isync
608#endif
609
610	rlwinm.	r12,r11,0,0,20		/* Extract pt base address */
611	/* Compute pte address */
612	rlwimi  r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
613	beq	2f			/* Bail if no table */
614	lwz	r11,0(r12)		/* Get high word of pte entry */
615
616	/* XXX can we do better ? maybe insert a known 0 bit from r11 into the
617	 * bottom of r12 to create a data dependency... We can also use r10
618	 * as destination nowadays
619	 */
620#ifdef CONFIG_SMP
621	lwsync
622#endif
623	lwz	r12,4(r12)		/* Get low word of pte entry */
624
625	andc.	r13,r13,r12		/* Check permission */
626
627	 /* Jump to common tlb load */
628	beq	finish_tlb_load_47x
629
6302:	/* The bailout.  Restore registers to pre-exception conditions
631	 * and call the heavyweights to help us out.
632	 */
633	mfspr	r11,SPRN_SPRG_RSCRATCH4
634	mtcr	r11
635	mfspr	r13,SPRN_SPRG_RSCRATCH3
636	mfspr	r12,SPRN_SPRG_RSCRATCH2
637	mfspr	r11,SPRN_SPRG_RSCRATCH1
638	mfspr	r10,SPRN_SPRG_RSCRATCH0
639	b	DataStorage
640
641	/* Instruction TLB Error Interrupt */
642	/*
643	 * Nearly the same as above, except we get our
644	 * information from different registers and bailout
645	 * to a different point.
646	 */
647	START_EXCEPTION(InstructionTLBError47x)
648	mtspr	SPRN_SPRG_WSCRATCH0,r10	/* Save some working registers */
649	mtspr	SPRN_SPRG_WSCRATCH1,r11
650	mtspr	SPRN_SPRG_WSCRATCH2,r12
651	mtspr	SPRN_SPRG_WSCRATCH3,r13
652	mfcr	r11
653	mtspr	SPRN_SPRG_WSCRATCH4,r11
654	mfspr	r10,SPRN_SRR0		/* Get faulting address */
655
656	/* If we are faulting a kernel address, we have to use the
657	 * kernel page tables.
658	 */
659	lis	r11,PAGE_OFFSET@h
660	cmplw	cr0,r10,r11
661	blt+	3f
662	lis	r11,swapper_pg_dir@h
663	ori	r11,r11, swapper_pg_dir@l
664	li	r12,0			/* MMUCR = 0 */
665	b	4f
666
667	/* Get the PGD for the current thread and setup MMUCR */
6683:	mfspr	r11,SPRN_SPRG_THREAD
669	lwz	r11,PGDIR(r11)
670	mfspr   r12,SPRN_PID		/* Get PID */
6714:	mtspr	SPRN_MMUCR,r12		/* Set MMUCR */
672
673	/* Make up the required permissions */
674	li	r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
675
676	/* Load PTE */
677	/* Compute pgdir/pmd offset */
678	rlwinm  r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
679	lwzx	r11,r12,r11		/* Get pgd/pmd entry */
680
681	/* Word 0 is EPN,V,TS,DSIZ */
682	li	r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
683	rlwimi	r10,r12,0,32-PAGE_SHIFT,31	/* Insert valid and page size*/
684	li	r12,0
685	tlbwe	r10,r12,0
686
687	/* XXX can we do better ? Need to make sure tlbwe has established
688	 * latch V bit in MMUCR0 before the PTE is loaded further down */
689#ifdef CONFIG_SMP
690	isync
691#endif
692
693	rlwinm.	r12,r11,0,0,20		/* Extract pt base address */
694	/* Compute pte address */
695	rlwimi  r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
696	beq	2f			/* Bail if no table */
697
698	lwz	r11,0(r12)		/* Get high word of pte entry */
699	/* XXX can we do better ? maybe insert a known 0 bit from r11 into the
700	 * bottom of r12 to create a data dependency... We can also use r10
701	 * as destination nowadays
702	 */
703#ifdef CONFIG_SMP
704	lwsync
705#endif
706	lwz	r12,4(r12)		/* Get low word of pte entry */
707
708	andc.	r13,r13,r12		/* Check permission */
709
710	/* Jump to common TLB load point */
711	beq	finish_tlb_load_47x
712
7132:	/* The bailout.  Restore registers to pre-exception conditions
714	 * and call the heavyweights to help us out.
715	 */
716	mfspr	r11, SPRN_SPRG_RSCRATCH4
717	mtcr	r11
718	mfspr	r13, SPRN_SPRG_RSCRATCH3
719	mfspr	r12, SPRN_SPRG_RSCRATCH2
720	mfspr	r11, SPRN_SPRG_RSCRATCH1
721	mfspr	r10, SPRN_SPRG_RSCRATCH0
722	b	InstructionStorage
723
724/*
725 * Both the instruction and data TLB miss get to this
726 * point to load the TLB.
727 * 	r10 - free to use
728 * 	r11 - PTE high word value
729 *	r12 - PTE low word value
730 *      r13 - free to use
731 *	MMUCR - loaded with proper value when we get here
732 *	Upon exit, we reload everything and RFI.
733 */
734finish_tlb_load_47x:
735	/* Combine RPN & ERPN an write WS 1 */
736	rlwimi	r11,r12,0,0,31-PAGE_SHIFT
737	tlbwe	r11,r13,1
738
739	/* And make up word 2 */
740	li	r10,0xf85			/* Mask to apply from PTE */
741	rlwimi	r10,r12,29,30,30		/* DIRTY -> SW position */
742	and	r11,r12,r10			/* Mask PTE bits to keep */
743	andi.	r10,r12,_PAGE_USER		/* User page ? */
744	beq	1f				/* nope, leave U bits empty */
745	rlwimi	r11,r11,3,26,28			/* yes, copy S bits to U */
7461:	tlbwe	r11,r13,2
747
748	/* Done...restore registers and get out of here.
749	*/
750	mfspr	r11, SPRN_SPRG_RSCRATCH4
751	mtcr	r11
752	mfspr	r13, SPRN_SPRG_RSCRATCH3
753	mfspr	r12, SPRN_SPRG_RSCRATCH2
754	mfspr	r11, SPRN_SPRG_RSCRATCH1
755	mfspr	r10, SPRN_SPRG_RSCRATCH0
756	rfi
757
758#endif /* CONFIG_PPC_47x */
759
760	/* Debug Interrupt */
761	/*
762	 * This statement needs to exist at the end of the IVPR
763	 * definition just in case you end up taking a debug
764	 * exception within another exception.
765	 */
766	DEBUG_CRIT_EXCEPTION
767
768interrupt_end:
769
770/*
771 * Global functions
772 */
773
774/*
775 * Adjust the machine check IVOR on 440A cores
776 */
777_GLOBAL(__fixup_440A_mcheck)
778	li	r3,MachineCheckA@l
779	mtspr	SPRN_IVOR1,r3
780	sync
781	blr
782
783_GLOBAL(set_context)
784
785#ifdef CONFIG_BDI_SWITCH
786	/* Context switch the PTE pointer for the Abatron BDI2000.
787	 * The PGDIR is the second parameter.
788	 */
789	lis	r5, abatron_pteptrs@h
790	ori	r5, r5, abatron_pteptrs@l
791	stw	r4, 0x4(r5)
792#endif
793	mtspr	SPRN_PID,r3
794	isync			/* Force context change */
795	blr
796
797/*
798 * Init CPU state. This is called at boot time or for secondary CPUs
799 * to setup initial TLB entries, setup IVORs, etc...
800 *
801 */
802_GLOBAL(init_cpu_state)
803	mflr	r22
804#ifdef CONFIG_PPC_47x
805	/* We use the PVR to differentiate 44x cores from 476 */
806	mfspr	r3,SPRN_PVR
807	srwi	r3,r3,16
808	cmplwi	cr0,r3,PVR_476FPE@h
809	beq	head_start_47x
810	cmplwi	cr0,r3,PVR_476@h
811	beq	head_start_47x
812	cmplwi	cr0,r3,PVR_476_ISS@h
813	beq	head_start_47x
814#endif /* CONFIG_PPC_47x */
815
816/*
817 * In case the firmware didn't do it, we apply some workarounds
818 * that are good for all 440 core variants here
819 */
820	mfspr	r3,SPRN_CCR0
821	rlwinm	r3,r3,0,0,27	/* disable icache prefetch */
822	isync
823	mtspr	SPRN_CCR0,r3
824	isync
825	sync
826
827/*
828 * Set up the initial MMU state for 44x
829 *
830 * We are still executing code at the virtual address
831 * mappings set by the firmware for the base of RAM.
832 *
833 * We first invalidate all TLB entries but the one
834 * we are running from.  We then load the KERNELBASE
835 * mappings so we can begin to use kernel addresses
836 * natively and so the interrupt vector locations are
837 * permanently pinned (necessary since Book E
838 * implementations always have translation enabled).
839 *
840 * TODO: Use the known TLB entry we are running from to
841 *	 determine which physical region we are located
842 *	 in.  This can be used to determine where in RAM
843 *	 (on a shared CPU system) or PCI memory space
844 *	 (on a DRAMless system) we are located.
845 *       For now, we assume a perfect world which means
846 *	 we are located at the base of DRAM (physical 0).
847 */
848
849/*
850 * Search TLB for entry that we are currently using.
851 * Invalidate all entries but the one we are using.
852 */
853	/* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
854	mfspr	r3,SPRN_PID			/* Get PID */
855	mfmsr	r4				/* Get MSR */
856	andi.	r4,r4,MSR_IS@l			/* TS=1? */
857	beq	wmmucr				/* If not, leave STS=0 */
858	oris	r3,r3,PPC44x_MMUCR_STS@h	/* Set STS=1 */
859wmmucr:	mtspr	SPRN_MMUCR,r3			/* Put MMUCR */
860	sync
861
862	bl	invstr				/* Find our address */
863invstr:	mflr	r5				/* Make it accessible */
864	tlbsx	r23,0,r5			/* Find entry we are in */
865	li	r4,0				/* Start at TLB entry 0 */
866	li	r3,0				/* Set PAGEID inval value */
8671:	cmpw	r23,r4				/* Is this our entry? */
868	beq	skpinv				/* If so, skip the inval */
869	tlbwe	r3,r4,PPC44x_TLB_PAGEID		/* If not, inval the entry */
870skpinv:	addi	r4,r4,1				/* Increment */
871	cmpwi	r4,64				/* Are we done? */
872	bne	1b				/* If not, repeat */
873	isync					/* If so, context change */
874
875/*
876 * Configure and load pinned entry into TLB slot 63.
877 */
878#ifdef CONFIG_NONSTATIC_KERNEL
879	/*
880	 * In case of a NONSTATIC_KERNEL we reuse the TLB XLAT
881	 * entries of the initial mapping set by the boot loader.
882	 * The XLAT entry is stored in r25
883	 */
884
885	/* Read the XLAT entry for our current mapping */
886	tlbre	r25,r23,PPC44x_TLB_XLAT
887
888	lis	r3,KERNELBASE@h
889	ori	r3,r3,KERNELBASE@l
890
891	/* Use our current RPN entry */
892	mr	r4,r25
893#else
894
895	lis	r3,PAGE_OFFSET@h
896	ori	r3,r3,PAGE_OFFSET@l
897
898	/* Kernel is at the base of RAM */
899	li r4, 0			/* Load the kernel physical address */
900#endif
901
902	/* Load the kernel PID = 0 */
903	li	r0,0
904	mtspr	SPRN_PID,r0
905	sync
906
907	/* Initialize MMUCR */
908	li	r5,0
909	mtspr	SPRN_MMUCR,r5
910	sync
911
912	/* pageid fields */
913	clrrwi	r3,r3,10		/* Mask off the effective page number */
914	ori	r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M
915
916	/* xlat fields */
917	clrrwi	r4,r4,10		/* Mask off the real page number */
918					/* ERPN is 0 for first 4GB page */
919
920	/* attrib fields */
921	/* Added guarded bit to protect against speculative loads/stores */
922	li	r5,0
923	ori	r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G)
924
925        li      r0,63                    /* TLB slot 63 */
926
927	tlbwe	r3,r0,PPC44x_TLB_PAGEID	/* Load the pageid fields */
928	tlbwe	r4,r0,PPC44x_TLB_XLAT	/* Load the translation fields */
929	tlbwe	r5,r0,PPC44x_TLB_ATTRIB	/* Load the attrib/access fields */
930
931	/* Force context change */
932	mfmsr	r0
933	mtspr	SPRN_SRR1, r0
934	lis	r0,3f@h
935	ori	r0,r0,3f@l
936	mtspr	SPRN_SRR0,r0
937	sync
938	rfi
939
940	/* If necessary, invalidate original entry we used */
9413:	cmpwi	r23,63
942	beq	4f
943	li	r6,0
944	tlbwe   r6,r23,PPC44x_TLB_PAGEID
945	isync
946
9474:
948#ifdef CONFIG_PPC_EARLY_DEBUG_44x
949	/* Add UART mapping for early debug. */
950
951	/* pageid fields */
952	lis	r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
953	ori	r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K
954
955	/* xlat fields */
956	lis	r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
957	ori	r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
958
959	/* attrib fields */
960	li	r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G)
961        li      r0,62                    /* TLB slot 0 */
962
963	tlbwe	r3,r0,PPC44x_TLB_PAGEID
964	tlbwe	r4,r0,PPC44x_TLB_XLAT
965	tlbwe	r5,r0,PPC44x_TLB_ATTRIB
966
967	/* Force context change */
968	isync
969#endif /* CONFIG_PPC_EARLY_DEBUG_44x */
970
971	/* Establish the interrupt vector offsets */
972	SET_IVOR(0,  CriticalInput);
973	SET_IVOR(1,  MachineCheck);
974	SET_IVOR(2,  DataStorage);
975	SET_IVOR(3,  InstructionStorage);
976	SET_IVOR(4,  ExternalInput);
977	SET_IVOR(5,  Alignment);
978	SET_IVOR(6,  Program);
979	SET_IVOR(7,  FloatingPointUnavailable);
980	SET_IVOR(8,  SystemCall);
981	SET_IVOR(9,  AuxillaryProcessorUnavailable);
982	SET_IVOR(10, Decrementer);
983	SET_IVOR(11, FixedIntervalTimer);
984	SET_IVOR(12, WatchdogTimer);
985	SET_IVOR(13, DataTLBError44x);
986	SET_IVOR(14, InstructionTLBError44x);
987	SET_IVOR(15, DebugCrit);
988
989	b	head_start_common
990
991
992#ifdef CONFIG_PPC_47x
993
994#ifdef CONFIG_SMP
995
996/* Entry point for secondary 47x processors */
997_GLOBAL(start_secondary_47x)
998        mr      r24,r3          /* CPU number */
999
1000	bl	init_cpu_state
1001
1002	/* Now we need to bolt the rest of kernel memory which
1003	 * is done in C code. We must be careful because our task
1004	 * struct or our stack can (and will probably) be out
1005	 * of reach of the initial 256M TLB entry, so we use a
1006	 * small temporary stack in .bss for that. This works
1007	 * because only one CPU at a time can be in this code
1008	 */
1009	lis	r1,temp_boot_stack@h
1010	ori	r1,r1,temp_boot_stack@l
1011	addi	r1,r1,1024-STACK_FRAME_OVERHEAD
1012	li	r0,0
1013	stw	r0,0(r1)
1014	bl	mmu_init_secondary
1015
1016	/* Now we can get our task struct and real stack pointer */
1017
1018	/* Get current's stack and current */
1019	lis	r2,secondary_current@ha
1020	lwz	r2,secondary_current@l(r2)
1021	lwz	r1,TASK_STACK(r2)
1022
1023	/* Current stack pointer */
1024	addi	r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1025	li	r0,0
1026	stw	r0,0(r1)
1027
1028	/* Kernel stack for exception entry in SPRG3 */
1029	addi	r4,r2,THREAD	/* init task's THREAD */
1030	mtspr	SPRN_SPRG3,r4
1031
1032	b	start_secondary
1033
1034#endif /* CONFIG_SMP */
1035
1036/*
1037 * Set up the initial MMU state for 44x
1038 *
1039 * We are still executing code at the virtual address
1040 * mappings set by the firmware for the base of RAM.
1041 */
1042
1043head_start_47x:
1044	/* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
1045	mfspr	r3,SPRN_PID			/* Get PID */
1046	mfmsr	r4				/* Get MSR */
1047	andi.	r4,r4,MSR_IS@l			/* TS=1? */
1048	beq	1f				/* If not, leave STS=0 */
1049	oris	r3,r3,PPC47x_MMUCR_STS@h	/* Set STS=1 */
10501:	mtspr	SPRN_MMUCR,r3			/* Put MMUCR */
1051	sync
1052
1053	/* Find the entry we are running from */
1054	bl	1f
10551:	mflr	r23
1056	tlbsx	r23,0,r23
1057	tlbre	r24,r23,0
1058	tlbre	r25,r23,1
1059	tlbre	r26,r23,2
1060
1061/*
1062 * Cleanup time
1063 */
1064
1065	/* Initialize MMUCR */
1066	li	r5,0
1067	mtspr	SPRN_MMUCR,r5
1068	sync
1069
1070clear_all_utlb_entries:
1071
1072	#; Set initial values.
1073
1074	addis		r3,0,0x8000
1075	addi		r4,0,0
1076	addi		r5,0,0
1077	b		clear_utlb_entry
1078
1079	#; Align the loop to speed things up.
1080
1081	.align		6
1082
1083clear_utlb_entry:
1084
1085	tlbwe		r4,r3,0
1086	tlbwe		r5,r3,1
1087	tlbwe		r5,r3,2
1088	addis		r3,r3,0x2000
1089	cmpwi		r3,0
1090	bne		clear_utlb_entry
1091	addis		r3,0,0x8000
1092	addis		r4,r4,0x100
1093	cmpwi		r4,0
1094	bne		clear_utlb_entry
1095
1096	#; Restore original entry.
1097
1098	oris	r23,r23,0x8000  /* specify the way */
1099	tlbwe		r24,r23,0
1100	tlbwe		r25,r23,1
1101	tlbwe		r26,r23,2
1102
1103/*
1104 * Configure and load pinned entry into TLB for the kernel core
1105 */
1106
1107	lis	r3,PAGE_OFFSET@h
1108	ori	r3,r3,PAGE_OFFSET@l
1109
1110	/* Load the kernel PID = 0 */
1111	li	r0,0
1112	mtspr	SPRN_PID,r0
1113	sync
1114
1115	/* Word 0 */
1116	clrrwi	r3,r3,12		/* Mask off the effective page number */
1117	ori	r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_256M
1118
1119	/* Word 1 - use r25.  RPN is the same as the original entry */
1120
1121	/* Word 2 */
1122	li	r5,0
1123	ori	r5,r5,PPC47x_TLB2_S_RWX
1124#ifdef CONFIG_SMP
1125	ori	r5,r5,PPC47x_TLB2_M
1126#endif
1127
1128	/* We write to way 0 and bolted 0 */
1129	lis	r0,0x8800
1130	tlbwe	r3,r0,0
1131	tlbwe	r25,r0,1
1132	tlbwe	r5,r0,2
1133
1134/*
1135 * Configure SSPCR, ISPCR and USPCR for now to search everything, we can fix
1136 * them up later
1137 */
1138	LOAD_REG_IMMEDIATE(r3, 0x9abcdef0)
1139	mtspr	SPRN_SSPCR,r3
1140	mtspr	SPRN_USPCR,r3
1141	LOAD_REG_IMMEDIATE(r3, 0x12345670)
1142	mtspr	SPRN_ISPCR,r3
1143
1144	/* Force context change */
1145	mfmsr	r0
1146	mtspr	SPRN_SRR1, r0
1147	lis	r0,3f@h
1148	ori	r0,r0,3f@l
1149	mtspr	SPRN_SRR0,r0
1150	sync
1151	rfi
1152
1153	/* Invalidate original entry we used */
11543:
1155	rlwinm	r24,r24,0,21,19 /* clear the "valid" bit */
1156	tlbwe	r24,r23,0
1157	addi	r24,0,0
1158	tlbwe	r24,r23,1
1159	tlbwe	r24,r23,2
1160	isync                   /* Clear out the shadow TLB entries */
1161
1162#ifdef CONFIG_PPC_EARLY_DEBUG_44x
1163	/* Add UART mapping for early debug. */
1164
1165	/* Word 0 */
1166	lis	r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
1167	ori	r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_TS | PPC47x_TLB0_1M
1168
1169	/* Word 1 */
1170	lis	r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
1171	ori	r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
1172
1173	/* Word 2 */
1174	li	r5,(PPC47x_TLB2_S_RW | PPC47x_TLB2_IMG)
1175
1176	/* Bolted in way 0, bolt slot 5, we -hope- we don't hit the same
1177	 * congruence class as the kernel, we need to make sure of it at
1178	 * some point
1179	 */
1180        lis	r0,0x8d00
1181	tlbwe	r3,r0,0
1182	tlbwe	r4,r0,1
1183	tlbwe	r5,r0,2
1184
1185	/* Force context change */
1186	isync
1187#endif /* CONFIG_PPC_EARLY_DEBUG_44x */
1188
1189	/* Establish the interrupt vector offsets */
1190	SET_IVOR(0,  CriticalInput);
1191	SET_IVOR(1,  MachineCheckA);
1192	SET_IVOR(2,  DataStorage);
1193	SET_IVOR(3,  InstructionStorage);
1194	SET_IVOR(4,  ExternalInput);
1195	SET_IVOR(5,  Alignment);
1196	SET_IVOR(6,  Program);
1197	SET_IVOR(7,  FloatingPointUnavailable);
1198	SET_IVOR(8,  SystemCall);
1199	SET_IVOR(9,  AuxillaryProcessorUnavailable);
1200	SET_IVOR(10, Decrementer);
1201	SET_IVOR(11, FixedIntervalTimer);
1202	SET_IVOR(12, WatchdogTimer);
1203	SET_IVOR(13, DataTLBError47x);
1204	SET_IVOR(14, InstructionTLBError47x);
1205	SET_IVOR(15, DebugCrit);
1206
1207	/* We configure icbi to invalidate 128 bytes at a time since the
1208	 * current 32-bit kernel code isn't too happy with icache != dcache
1209	 * block size. We also disable the BTAC as this can cause errors
1210	 * in some circumstances (see IBM Erratum 47).
1211	 */
1212	mfspr	r3,SPRN_CCR0
1213	oris	r3,r3,0x0020
1214	ori	r3,r3,0x0040
1215	mtspr	SPRN_CCR0,r3
1216	isync
1217
1218#endif /* CONFIG_PPC_47x */
1219
1220/*
1221 * Here we are back to code that is common between 44x and 47x
1222 *
1223 * We proceed to further kernel initialization and return to the
1224 * main kernel entry
1225 */
1226head_start_common:
1227	/* Establish the interrupt vector base */
1228	lis	r4,interrupt_base@h	/* IVPR only uses the high 16-bits */
1229	mtspr	SPRN_IVPR,r4
1230
1231	/*
1232	 * If the kernel was loaded at a non-zero 256 MB page, we need to
1233	 * mask off the most significant 4 bits to get the relative address
1234	 * from the start of physical memory
1235	 */
1236	rlwinm	r22,r22,0,4,31
1237	addis	r22,r22,PAGE_OFFSET@h
1238	mtlr	r22
1239	isync
1240	blr
1241
1242/*
1243 * We put a few things here that have to be page-aligned. This stuff
1244 * goes at the beginning of the data segment, which is page-aligned.
1245 */
1246	.data
1247	.align	PAGE_SHIFT
1248	.globl	sdata
1249sdata:
1250	.globl	empty_zero_page
1251empty_zero_page:
1252	.space	PAGE_SIZE
1253EXPORT_SYMBOL(empty_zero_page)
1254
1255/*
1256 * To support >32-bit physical addresses, we use an 8KB pgdir.
1257 */
1258	.globl	swapper_pg_dir
1259swapper_pg_dir:
1260	.space	PGD_TABLE_SIZE
1261
1262/*
1263 * Room for two PTE pointers, usually the kernel and current user pointers
1264 * to their respective root page table.
1265 */
1266abatron_pteptrs:
1267	.space	8
1268
1269#ifdef CONFIG_SMP
1270	.align	12
1271temp_boot_stack:
1272	.space	1024
1273#endif /* CONFIG_SMP */
1274