blob: d7a1debda10b6471359d76965ab3451ea8a4cd32 [file] [log] [blame]
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10002 * Kernel execution entry point code.
3 *
4 * Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org>
5 * Initial PowerPC version.
6 * Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu>
7 * Rewritten for PReP
8 * Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au>
9 * Low-level exception handers, MMU support, and rewrite.
10 * Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
11 * PowerPC 8xx modifications.
12 * Copyright (c) 1998-1999 TiVo, Inc.
13 * PowerPC 403GCX modifications.
14 * Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
15 * PowerPC 403GCX/405GP modifications.
16 * Copyright 2000 MontaVista Software Inc.
17 * PPC405 modifications
18 * PowerPC 403GCX/405GP modifications.
19 * Author: MontaVista Software, Inc.
20 * frank_rowand@mvista.com or source@mvista.com
21 * debbie_chu@mvista.com
22 * Copyright 2002-2005 MontaVista Software, Inc.
23 * PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org>
24 *
25 * This program is free software; you can redistribute it and/or modify it
26 * under the terms of the GNU General Public License as published by the
27 * Free Software Foundation; either version 2 of the License, or (at your
28 * option) any later version.
29 */
30
Tim Abbotte7039842009-04-25 22:11:05 -040031#include <linux/init.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100032#include <asm/processor.h>
33#include <asm/page.h>
34#include <asm/mmu.h>
35#include <asm/pgtable.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100036#include <asm/cputable.h>
37#include <asm/thread_info.h>
38#include <asm/ppc_asm.h>
39#include <asm/asm-offsets.h>
Stephen Rothwell46f52212010-11-18 15:06:17 +000040#include <asm/ptrace.h>
Dave Kleikampe7f75ad2010-03-05 10:43:12 +000041#include <asm/synch.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100042#include "head_booke.h"
43
44
45/* As with the other PowerPC ports, it is expected that when code
46 * execution begins here, the following registers contain valid, yet
47 * optional, information:
48 *
49 * r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
50 * r4 - Starting address of the init RAM disk
51 * r5 - Ending address of the init RAM disk
52 * r6 - Start of kernel command line string (e.g. "mem=128")
53 * r7 - End of kernel command line string
54 *
55 */
Tim Abbotte7039842009-04-25 22:11:05 -040056 __HEAD
Kumar Gala748a7682007-09-13 15:42:35 -050057_ENTRY(_stext);
58_ENTRY(_start);
Paul Mackerras14cf11a2005-09-26 16:04:21 +100059 /*
60 * Reserve a word at a fixed location to store the address
61 * of abatron_pteptrs
62 */
63 nop
Scott Wood6dece0e2011-07-25 11:29:33 +000064 mr r31,r3 /* save device tree ptr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100065 li r24,0 /* CPU number */
66
Dave Kleikamp795033c2010-03-05 10:43:07 +000067 bl init_cpu_state
Paul Mackerras14cf11a2005-09-26 16:04:21 +100068
Paul Mackerras14cf11a2005-09-26 16:04:21 +100069 /*
70 * This is where the main kernel code starts.
71 */
72
73 /* ptr to current */
74 lis r2,init_task@h
75 ori r2,r2,init_task@l
76
77 /* ptr to current thread */
78 addi r4,r2,THREAD /* init task's THREAD */
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +000079 mtspr SPRN_SPRG_THREAD,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +100080
81 /* stack */
82 lis r1,init_thread_union@h
83 ori r1,r1,init_thread_union@l
84 li r0,0
85 stwu r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
86
87 bl early_init
88
Suzuki Poulose0f890c82011-12-14 22:57:15 +000089#ifdef CONFIG_DYNAMIC_MEMSTART
Dave Kleikamp96615342011-07-04 18:36:57 +000090 /*
Suzuki Poulose0f890c82011-12-14 22:57:15 +000091 * Mapping based, page aligned dynamic kernel loading.
92 *
Dave Kleikamp96615342011-07-04 18:36:57 +000093 * r25 will contain RPN/ERPN for the start address of memory
94 *
95 * Add the difference between KERNELBASE and PAGE_OFFSET to the
96 * start of physical memory to get kernstart_addr.
97 */
98 lis r3,kernstart_addr@ha
99 la r3,kernstart_addr@l(r3)
100
101 lis r4,KERNELBASE@h
102 ori r4,r4,KERNELBASE@l
103 lis r5,PAGE_OFFSET@h
104 ori r5,r5,PAGE_OFFSET@l
105 subf r4,r5,r4
106
107 rlwinm r6,r25,0,28,31 /* ERPN */
108 rlwinm r7,r25,0,0,3 /* RPN - assuming 256 MB page size */
109 add r7,r7,r4
110
111 stw r6,0(r3)
112 stw r7,4(r3)
113#endif
114
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000115/*
116 * Decide what sort of machine this is and initialize the MMU.
117 */
Scott Wood6dece0e2011-07-25 11:29:33 +0000118 li r3,0
119 mr r4,r31
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000120 bl machine_init
121 bl MMU_init
122
123 /* Setup PTE pointers for the Abatron bdiGDB */
124 lis r6, swapper_pg_dir@h
125 ori r6, r6, swapper_pg_dir@l
126 lis r5, abatron_pteptrs@h
127 ori r5, r5, abatron_pteptrs@l
128 lis r4, KERNELBASE@h
129 ori r4, r4, KERNELBASE@l
130 stw r5, 0(r4) /* Save abatron_pteptrs at a fixed location */
131 stw r6, 0(r5)
132
Dave Kleikamp029b8f62010-08-18 06:44:23 +0000133 /* Clear the Machine Check Syndrome Register */
134 li r0,0
135 mtspr SPRN_MCSR,r0
136
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000137 /* Let's move on */
138 lis r4,start_kernel@h
139 ori r4,r4,start_kernel@l
140 lis r3,MSR_KERNEL@h
141 ori r3,r3,MSR_KERNEL@l
142 mtspr SPRN_SRR0,r4
143 mtspr SPRN_SRR1,r3
144 rfi /* change context and jump to start_kernel */
145
146/*
147 * Interrupt vector entry code
148 *
149 * The Book E MMUs are always on so we don't need to handle
150 * interrupts in real mode as with previous PPC processors. In
151 * this case we handle interrupts in the kernel virtual address
152 * space.
153 *
154 * Interrupt vectors are dynamically placed relative to the
155 * interrupt prefix as determined by the address of interrupt_base.
156 * The interrupt vectors offsets are programmed using the labels
157 * for each interrupt vector entry.
158 *
159 * Interrupt vectors must be aligned on a 16 byte boundary.
160 * We align on a 32 byte cache line boundary for good measure.
161 */
162
163interrupt_base:
164 /* Critical Input Interrupt */
Stephen Rothwelldc1c1ca2005-10-01 18:43:42 +1000165 CRITICAL_EXCEPTION(0x0100, CriticalInput, unknown_exception)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000166
167 /* Machine Check Interrupt */
Stephen Rothwelldc1c1ca2005-10-01 18:43:42 +1000168 CRITICAL_EXCEPTION(0x0200, MachineCheck, machine_check_exception)
Benjamin Herrenschmidt47c0bd12007-12-21 15:39:21 +1100169 MCHECK_EXCEPTION(0x0210, MachineCheckA, machine_check_exception)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000170
171 /* Data Storage Interrupt */
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000172 DATA_STORAGE_EXCEPTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000173
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000174 /* Instruction Storage Interrupt */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000175 INSTRUCTION_STORAGE_EXCEPTION
176
177 /* External Input Interrupt */
178 EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE)
179
180 /* Alignment Interrupt */
181 ALIGNMENT_EXCEPTION
182
183 /* Program Interrupt */
184 PROGRAM_EXCEPTION
185
186 /* Floating Point Unavailable Interrupt */
187#ifdef CONFIG_PPC_FPU
188 FP_UNAVAILABLE_EXCEPTION
189#else
Stephen Rothwelldc1c1ca2005-10-01 18:43:42 +1000190 EXCEPTION(0x2010, FloatingPointUnavailable, unknown_exception, EXC_XFER_EE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000191#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000192 /* System Call Interrupt */
193 START_EXCEPTION(SystemCall)
194 NORMAL_EXCEPTION_PROLOG
195 EXC_XFER_EE_LITE(0x0c00, DoSyscall)
196
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300197 /* Auxiliary Processor Unavailable Interrupt */
Stephen Rothwelldc1c1ca2005-10-01 18:43:42 +1000198 EXCEPTION(0x2020, AuxillaryProcessorUnavailable, unknown_exception, EXC_XFER_EE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000199
200 /* Decrementer Interrupt */
201 DECREMENTER_EXCEPTION
202
203 /* Fixed Internal Timer Interrupt */
204 /* TODO: Add FIT support */
Stephen Rothwelldc1c1ca2005-10-01 18:43:42 +1000205 EXCEPTION(0x1010, FixedIntervalTimer, unknown_exception, EXC_XFER_EE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000206
207 /* Watchdog Timer Interrupt */
208 /* TODO: Add watchdog support */
209#ifdef CONFIG_BOOKE_WDT
210 CRITICAL_EXCEPTION(0x1020, WatchdogTimer, WatchdogException)
211#else
Stephen Rothwelldc1c1ca2005-10-01 18:43:42 +1000212 CRITICAL_EXCEPTION(0x1020, WatchdogTimer, unknown_exception)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000213#endif
214
215 /* Data TLB Error Interrupt */
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000216 START_EXCEPTION(DataTLBError44x)
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000217 mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
218 mtspr SPRN_SPRG_WSCRATCH1, r11
219 mtspr SPRN_SPRG_WSCRATCH2, r12
220 mtspr SPRN_SPRG_WSCRATCH3, r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000221 mfcr r11
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000222 mtspr SPRN_SPRG_WSCRATCH4, r11
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000223 mfspr r10, SPRN_DEAR /* Get faulting address */
224
225 /* If we are faulting a kernel address, we have to use the
226 * kernel page tables.
227 */
Kumar Gala8a13c4f2007-10-11 13:36:52 -0500228 lis r11, PAGE_OFFSET@h
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000229 cmplw r10, r11
230 blt+ 3f
231 lis r11, swapper_pg_dir@h
232 ori r11, r11, swapper_pg_dir@l
233
234 mfspr r12,SPRN_MMUCR
235 rlwinm r12,r12,0,0,23 /* Clear TID */
236
237 b 4f
238
239 /* Get the PGD for the current thread */
2403:
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000241 mfspr r11,SPRN_SPRG_THREAD
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000242 lwz r11,PGDIR(r11)
243
244 /* Load PID into MMUCR TID */
245 mfspr r12,SPRN_MMUCR
246 mfspr r13,SPRN_PID /* Get PID */
247 rlwimi r12,r13,0,24,31 /* Set TID */
248
2494:
250 mtspr SPRN_MMUCR,r12
251
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000252 /* Mask of required permission bits. Note that while we
253 * do copy ESR:ST to _PAGE_RW position as trying to write
254 * to an RO page is pretty common, we don't do it with
255 * _PAGE_DIRTY. We could do it, but it's a fairly rare
256 * event so I'd rather take the overhead when it happens
257 * rather than adding an instruction here. We should measure
258 * whether the whole thing is worth it in the first place
259 * as we could avoid loading SPRN_ESR completely in the first
260 * place...
261 *
262 * TODO: Is it worth doing that mfspr & rlwimi in the first
263 * place or can we save a couple of instructions here ?
264 */
265 mfspr r12,SPRN_ESR
266 li r13,_PAGE_PRESENT|_PAGE_ACCESSED
267 rlwimi r13,r12,10,30,30
268
269 /* Load the PTE */
Ilya Yanokca9153a2008-12-11 04:55:41 +0300270 /* Compute pgdir/pmd offset */
271 rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000272 lwzx r11, r12, r11 /* Get pgd/pmd entry */
273 rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */
274 beq 2f /* Bail if no table */
275
Ilya Yanokca9153a2008-12-11 04:55:41 +0300276 /* Compute pte address */
277 rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000278 lwz r11, 0(r12) /* Get high word of pte entry */
279 lwz r12, 4(r12) /* Get low word of pte entry */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000280
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000281 lis r10,tlb_44x_index@ha
282
283 andc. r13,r13,r12 /* Check permission */
284
285 /* Load the next available TLB index */
286 lwz r13,tlb_44x_index@l(r10)
287
288 bne 2f /* Bail if permission mismach */
289
290 /* Increment, rollover, and store TLB index */
291 addi r13,r13,1
292
293 /* Compare with watermark (instruction gets patched) */
294 .globl tlb_44x_patch_hwater_D
295tlb_44x_patch_hwater_D:
296 cmpwi 0,r13,1 /* reserve entries */
297 ble 5f
298 li r13,0
2995:
300 /* Store the next available TLB index */
301 stw r13,tlb_44x_index@l(r10)
302
303 /* Re-load the faulting address */
304 mfspr r10,SPRN_DEAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000305
306 /* Jump to common tlb load */
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000307 b finish_tlb_load_44x
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000308
3092:
310 /* The bailout. Restore registers to pre-exception conditions
311 * and call the heavyweights to help us out.
312 */
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000313 mfspr r11, SPRN_SPRG_RSCRATCH4
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000314 mtcr r11
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000315 mfspr r13, SPRN_SPRG_RSCRATCH3
316 mfspr r12, SPRN_SPRG_RSCRATCH2
317 mfspr r11, SPRN_SPRG_RSCRATCH1
318 mfspr r10, SPRN_SPRG_RSCRATCH0
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000319 b DataStorage
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000320
321 /* Instruction TLB Error Interrupt */
322 /*
323 * Nearly the same as above, except we get our
324 * information from different registers and bailout
325 * to a different point.
326 */
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000327 START_EXCEPTION(InstructionTLBError44x)
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000328 mtspr SPRN_SPRG_WSCRATCH0, r10 /* Save some working registers */
329 mtspr SPRN_SPRG_WSCRATCH1, r11
330 mtspr SPRN_SPRG_WSCRATCH2, r12
331 mtspr SPRN_SPRG_WSCRATCH3, r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000332 mfcr r11
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000333 mtspr SPRN_SPRG_WSCRATCH4, r11
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000334 mfspr r10, SPRN_SRR0 /* Get faulting address */
335
336 /* If we are faulting a kernel address, we have to use the
337 * kernel page tables.
338 */
Kumar Gala8a13c4f2007-10-11 13:36:52 -0500339 lis r11, PAGE_OFFSET@h
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000340 cmplw r10, r11
341 blt+ 3f
342 lis r11, swapper_pg_dir@h
343 ori r11, r11, swapper_pg_dir@l
344
345 mfspr r12,SPRN_MMUCR
346 rlwinm r12,r12,0,0,23 /* Clear TID */
347
348 b 4f
349
350 /* Get the PGD for the current thread */
3513:
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000352 mfspr r11,SPRN_SPRG_THREAD
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000353 lwz r11,PGDIR(r11)
354
355 /* Load PID into MMUCR TID */
356 mfspr r12,SPRN_MMUCR
357 mfspr r13,SPRN_PID /* Get PID */
358 rlwimi r12,r13,0,24,31 /* Set TID */
359
3604:
361 mtspr SPRN_MMUCR,r12
362
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000363 /* Make up the required permissions */
Benjamin Herrenschmidtea3cc332009-08-18 19:00:34 +0000364 li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000365
Ilya Yanokca9153a2008-12-11 04:55:41 +0300366 /* Compute pgdir/pmd offset */
367 rlwinm r12, r10, PPC44x_PGD_OFF_SHIFT, PPC44x_PGD_OFF_MASK_BIT, 29
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000368 lwzx r11, r12, r11 /* Get pgd/pmd entry */
369 rlwinm. r12, r11, 0, 0, 20 /* Extract pt base address */
370 beq 2f /* Bail if no table */
371
Ilya Yanokca9153a2008-12-11 04:55:41 +0300372 /* Compute pte address */
373 rlwimi r12, r10, PPC44x_PTE_ADD_SHIFT, PPC44x_PTE_ADD_MASK_BIT, 28
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000374 lwz r11, 0(r12) /* Get high word of pte entry */
375 lwz r12, 4(r12) /* Get low word of pte entry */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000376
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000377 lis r10,tlb_44x_index@ha
378
379 andc. r13,r13,r12 /* Check permission */
380
381 /* Load the next available TLB index */
382 lwz r13,tlb_44x_index@l(r10)
383
384 bne 2f /* Bail if permission mismach */
385
386 /* Increment, rollover, and store TLB index */
387 addi r13,r13,1
388
389 /* Compare with watermark (instruction gets patched) */
390 .globl tlb_44x_patch_hwater_I
391tlb_44x_patch_hwater_I:
392 cmpwi 0,r13,1 /* reserve entries */
393 ble 5f
394 li r13,0
3955:
396 /* Store the next available TLB index */
397 stw r13,tlb_44x_index@l(r10)
398
399 /* Re-load the faulting address */
400 mfspr r10,SPRN_SRR0
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000401
402 /* Jump to common TLB load point */
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000403 b finish_tlb_load_44x
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000404
4052:
406 /* The bailout. Restore registers to pre-exception conditions
407 * and call the heavyweights to help us out.
408 */
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000409 mfspr r11, SPRN_SPRG_RSCRATCH4
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000410 mtcr r11
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000411 mfspr r13, SPRN_SPRG_RSCRATCH3
412 mfspr r12, SPRN_SPRG_RSCRATCH2
413 mfspr r11, SPRN_SPRG_RSCRATCH1
414 mfspr r10, SPRN_SPRG_RSCRATCH0
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000415 b InstructionStorage
416
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000417/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000418 * Both the instruction and data TLB miss get to this
419 * point to load the TLB.
420 * r10 - EA of fault
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000421 * r11 - PTE high word value
422 * r12 - PTE low word value
423 * r13 - TLB index
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000424 * MMUCR - loaded with proper value when we get here
425 * Upon exit, we reload everything and RFI.
426 */
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000427finish_tlb_load_44x:
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000428 /* Combine RPN & ERPN an write WS 0 */
Ilya Yanokca9153a2008-12-11 04:55:41 +0300429 rlwimi r11,r12,0,0,31-PAGE_SHIFT
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000430 tlbwe r11,r13,PPC44x_TLB_XLAT
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000431
432 /*
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000433 * Create WS1. This is the faulting address (EPN),
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000434 * page size, and valid flag.
435 */
Ilya Yanokca9153a2008-12-11 04:55:41 +0300436 li r11,PPC44x_TLB_VALID | PPC44x_TLBE_SIZE
437 /* Insert valid and page size */
438 rlwimi r10,r11,0,PPC44x_PTE_ADD_MASK_BIT,31
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000439 tlbwe r10,r13,PPC44x_TLB_PAGEID /* Write PAGEID */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000440
Benjamin Herrenschmidt1bc54c02008-07-08 15:54:40 +1000441 /* And WS 2 */
442 li r10,0xf85 /* Mask to apply from PTE */
443 rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */
444 and r11,r12,r10 /* Mask PTE bits to keep */
445 andi. r10,r12,_PAGE_USER /* User page ? */
446 beq 1f /* nope, leave U bits empty */
447 rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */
4481: tlbwe r11,r13,PPC44x_TLB_ATTRIB /* Write ATTRIB */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000449
450 /* Done...restore registers and get out of here.
451 */
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000452 mfspr r11, SPRN_SPRG_RSCRATCH4
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000453 mtcr r11
Benjamin Herrenschmidtee43eb72009-07-14 20:52:54 +0000454 mfspr r13, SPRN_SPRG_RSCRATCH3
455 mfspr r12, SPRN_SPRG_RSCRATCH2
456 mfspr r11, SPRN_SPRG_RSCRATCH1
457 mfspr r10, SPRN_SPRG_RSCRATCH0
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000458 rfi /* Force context change */
459
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000460/* TLB error interrupts for 476
461 */
462#ifdef CONFIG_PPC_47x
463 START_EXCEPTION(DataTLBError47x)
464 mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */
465 mtspr SPRN_SPRG_WSCRATCH1,r11
466 mtspr SPRN_SPRG_WSCRATCH2,r12
467 mtspr SPRN_SPRG_WSCRATCH3,r13
468 mfcr r11
469 mtspr SPRN_SPRG_WSCRATCH4,r11
470 mfspr r10,SPRN_DEAR /* Get faulting address */
471
472 /* If we are faulting a kernel address, we have to use the
473 * kernel page tables.
474 */
475 lis r11,PAGE_OFFSET@h
476 cmplw cr0,r10,r11
477 blt+ 3f
478 lis r11,swapper_pg_dir@h
479 ori r11,r11, swapper_pg_dir@l
480 li r12,0 /* MMUCR = 0 */
481 b 4f
482
483 /* Get the PGD for the current thread and setup MMUCR */
4843: mfspr r11,SPRN_SPRG3
485 lwz r11,PGDIR(r11)
486 mfspr r12,SPRN_PID /* Get PID */
4874: mtspr SPRN_MMUCR,r12 /* Set MMUCR */
488
489 /* Mask of required permission bits. Note that while we
490 * do copy ESR:ST to _PAGE_RW position as trying to write
491 * to an RO page is pretty common, we don't do it with
492 * _PAGE_DIRTY. We could do it, but it's a fairly rare
493 * event so I'd rather take the overhead when it happens
494 * rather than adding an instruction here. We should measure
495 * whether the whole thing is worth it in the first place
496 * as we could avoid loading SPRN_ESR completely in the first
497 * place...
498 *
499 * TODO: Is it worth doing that mfspr & rlwimi in the first
500 * place or can we save a couple of instructions here ?
501 */
502 mfspr r12,SPRN_ESR
503 li r13,_PAGE_PRESENT|_PAGE_ACCESSED
504 rlwimi r13,r12,10,30,30
505
506 /* Load the PTE */
507 /* Compute pgdir/pmd offset */
508 rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
509 lwzx r11,r12,r11 /* Get pgd/pmd entry */
510
511 /* Word 0 is EPN,V,TS,DSIZ */
512 li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
513 rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/
514 li r12,0
515 tlbwe r10,r12,0
516
517 /* XXX can we do better ? Need to make sure tlbwe has established
518 * latch V bit in MMUCR0 before the PTE is loaded further down */
519#ifdef CONFIG_SMP
520 isync
521#endif
522
523 rlwinm. r12,r11,0,0,20 /* Extract pt base address */
524 /* Compute pte address */
525 rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
526 beq 2f /* Bail if no table */
527 lwz r11,0(r12) /* Get high word of pte entry */
528
529 /* XXX can we do better ? maybe insert a known 0 bit from r11 into the
530 * bottom of r12 to create a data dependency... We can also use r10
531 * as destination nowadays
532 */
533#ifdef CONFIG_SMP
534 lwsync
535#endif
536 lwz r12,4(r12) /* Get low word of pte entry */
537
538 andc. r13,r13,r12 /* Check permission */
539
540 /* Jump to common tlb load */
541 beq finish_tlb_load_47x
542
5432: /* The bailout. Restore registers to pre-exception conditions
544 * and call the heavyweights to help us out.
545 */
546 mfspr r11,SPRN_SPRG_RSCRATCH4
547 mtcr r11
548 mfspr r13,SPRN_SPRG_RSCRATCH3
549 mfspr r12,SPRN_SPRG_RSCRATCH2
550 mfspr r11,SPRN_SPRG_RSCRATCH1
551 mfspr r10,SPRN_SPRG_RSCRATCH0
552 b DataStorage
553
554 /* Instruction TLB Error Interrupt */
555 /*
556 * Nearly the same as above, except we get our
557 * information from different registers and bailout
558 * to a different point.
559 */
560 START_EXCEPTION(InstructionTLBError47x)
561 mtspr SPRN_SPRG_WSCRATCH0,r10 /* Save some working registers */
562 mtspr SPRN_SPRG_WSCRATCH1,r11
563 mtspr SPRN_SPRG_WSCRATCH2,r12
564 mtspr SPRN_SPRG_WSCRATCH3,r13
565 mfcr r11
566 mtspr SPRN_SPRG_WSCRATCH4,r11
567 mfspr r10,SPRN_SRR0 /* Get faulting address */
568
569 /* If we are faulting a kernel address, we have to use the
570 * kernel page tables.
571 */
572 lis r11,PAGE_OFFSET@h
573 cmplw cr0,r10,r11
574 blt+ 3f
575 lis r11,swapper_pg_dir@h
576 ori r11,r11, swapper_pg_dir@l
577 li r12,0 /* MMUCR = 0 */
578 b 4f
579
580 /* Get the PGD for the current thread and setup MMUCR */
5813: mfspr r11,SPRN_SPRG_THREAD
582 lwz r11,PGDIR(r11)
583 mfspr r12,SPRN_PID /* Get PID */
5844: mtspr SPRN_MMUCR,r12 /* Set MMUCR */
585
586 /* Make up the required permissions */
587 li r13,_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_EXEC
588
589 /* Load PTE */
590 /* Compute pgdir/pmd offset */
591 rlwinm r12,r10,PPC44x_PGD_OFF_SHIFT,PPC44x_PGD_OFF_MASK_BIT,29
592 lwzx r11,r12,r11 /* Get pgd/pmd entry */
593
594 /* Word 0 is EPN,V,TS,DSIZ */
595 li r12,PPC47x_TLB0_VALID | PPC47x_TLBE_SIZE
596 rlwimi r10,r12,0,32-PAGE_SHIFT,31 /* Insert valid and page size*/
597 li r12,0
598 tlbwe r10,r12,0
599
600 /* XXX can we do better ? Need to make sure tlbwe has established
601 * latch V bit in MMUCR0 before the PTE is loaded further down */
602#ifdef CONFIG_SMP
603 isync
604#endif
605
606 rlwinm. r12,r11,0,0,20 /* Extract pt base address */
607 /* Compute pte address */
608 rlwimi r12,r10,PPC44x_PTE_ADD_SHIFT,PPC44x_PTE_ADD_MASK_BIT,28
609 beq 2f /* Bail if no table */
610
611 lwz r11,0(r12) /* Get high word of pte entry */
612 /* XXX can we do better ? maybe insert a known 0 bit from r11 into the
613 * bottom of r12 to create a data dependency... We can also use r10
614 * as destination nowadays
615 */
616#ifdef CONFIG_SMP
617 lwsync
618#endif
619 lwz r12,4(r12) /* Get low word of pte entry */
620
621 andc. r13,r13,r12 /* Check permission */
622
623 /* Jump to common TLB load point */
624 beq finish_tlb_load_47x
625
6262: /* The bailout. Restore registers to pre-exception conditions
627 * and call the heavyweights to help us out.
628 */
629 mfspr r11, SPRN_SPRG_RSCRATCH4
630 mtcr r11
631 mfspr r13, SPRN_SPRG_RSCRATCH3
632 mfspr r12, SPRN_SPRG_RSCRATCH2
633 mfspr r11, SPRN_SPRG_RSCRATCH1
634 mfspr r10, SPRN_SPRG_RSCRATCH0
635 b InstructionStorage
636
637/*
638 * Both the instruction and data TLB miss get to this
639 * point to load the TLB.
640 * r10 - free to use
641 * r11 - PTE high word value
642 * r12 - PTE low word value
643 * r13 - free to use
644 * MMUCR - loaded with proper value when we get here
645 * Upon exit, we reload everything and RFI.
646 */
647finish_tlb_load_47x:
648 /* Combine RPN & ERPN an write WS 1 */
649 rlwimi r11,r12,0,0,31-PAGE_SHIFT
650 tlbwe r11,r13,1
651
652 /* And make up word 2 */
653 li r10,0xf85 /* Mask to apply from PTE */
654 rlwimi r10,r12,29,30,30 /* DIRTY -> SW position */
655 and r11,r12,r10 /* Mask PTE bits to keep */
656 andi. r10,r12,_PAGE_USER /* User page ? */
657 beq 1f /* nope, leave U bits empty */
658 rlwimi r11,r11,3,26,28 /* yes, copy S bits to U */
6591: tlbwe r11,r13,2
660
661 /* Done...restore registers and get out of here.
662 */
663 mfspr r11, SPRN_SPRG_RSCRATCH4
664 mtcr r11
665 mfspr r13, SPRN_SPRG_RSCRATCH3
666 mfspr r12, SPRN_SPRG_RSCRATCH2
667 mfspr r11, SPRN_SPRG_RSCRATCH1
668 mfspr r10, SPRN_SPRG_RSCRATCH0
669 rfi
670
671#endif /* CONFIG_PPC_47x */
672
673 /* Debug Interrupt */
674 /*
675 * This statement needs to exist at the end of the IVPR
676 * definition just in case you end up taking a debug
677 * exception within another exception.
678 */
679 DEBUG_CRIT_EXCEPTION
680
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000681/*
682 * Global functions
683 */
684
685/*
Benjamin Herrenschmidt47c0bd12007-12-21 15:39:21 +1100686 * Adjust the machine check IVOR on 440A cores
687 */
688_GLOBAL(__fixup_440A_mcheck)
689 li r3,MachineCheckA@l
690 mtspr SPRN_IVOR1,r3
691 sync
692 blr
693
694/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000695 * extern void giveup_altivec(struct task_struct *prev)
696 *
697 * The 44x core does not have an AltiVec unit.
698 */
699_GLOBAL(giveup_altivec)
700 blr
701
702/*
703 * extern void giveup_fpu(struct task_struct *prev)
704 *
705 * The 44x core does not have an FPU.
706 */
707#ifndef CONFIG_PPC_FPU
708_GLOBAL(giveup_fpu)
709 blr
710#endif
711
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000712_GLOBAL(set_context)
713
714#ifdef CONFIG_BDI_SWITCH
715 /* Context switch the PTE pointer for the Abatron BDI2000.
716 * The PGDIR is the second parameter.
717 */
718 lis r5, abatron_pteptrs@h
719 ori r5, r5, abatron_pteptrs@l
720 stw r4, 0x4(r5)
721#endif
722 mtspr SPRN_PID,r3
723 isync /* Force context change */
724 blr
725
726/*
Dave Kleikamp795033c2010-03-05 10:43:07 +0000727 * Init CPU state. This is called at boot time or for secondary CPUs
728 * to setup initial TLB entries, setup IVORs, etc...
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000729 *
Dave Kleikamp795033c2010-03-05 10:43:07 +0000730 */
731_GLOBAL(init_cpu_state)
732 mflr r22
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000733#ifdef CONFIG_PPC_47x
734 /* We use the PVR to differenciate 44x cores from 476 */
735 mfspr r3,SPRN_PVR
736 srwi r3,r3,16
Tony Breedsdf777bd2011-11-30 21:39:23 +0000737 cmplwi cr0,r3,PVR_476FPE@h
738 beq head_start_47x
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000739 cmplwi cr0,r3,PVR_476@h
740 beq head_start_47x
Torez Smithb4e8c8d2010-03-05 10:45:54 +0000741 cmplwi cr0,r3,PVR_476_ISS@h
742 beq head_start_47x
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000743#endif /* CONFIG_PPC_47x */
744
Dave Kleikamp795033c2010-03-05 10:43:07 +0000745/*
746 * In case the firmware didn't do it, we apply some workarounds
747 * that are good for all 440 core variants here
748 */
749 mfspr r3,SPRN_CCR0
750 rlwinm r3,r3,0,0,27 /* disable icache prefetch */
751 isync
752 mtspr SPRN_CCR0,r3
753 isync
754 sync
755
756/*
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000757 * Set up the initial MMU state for 44x
Dave Kleikamp795033c2010-03-05 10:43:07 +0000758 *
759 * We are still executing code at the virtual address
760 * mappings set by the firmware for the base of RAM.
761 *
762 * We first invalidate all TLB entries but the one
763 * we are running from. We then load the KERNELBASE
764 * mappings so we can begin to use kernel addresses
765 * natively and so the interrupt vector locations are
766 * permanently pinned (necessary since Book E
767 * implementations always have translation enabled).
768 *
769 * TODO: Use the known TLB entry we are running from to
770 * determine which physical region we are located
771 * in. This can be used to determine where in RAM
772 * (on a shared CPU system) or PCI memory space
773 * (on a DRAMless system) we are located.
774 * For now, we assume a perfect world which means
775 * we are located at the base of DRAM (physical 0).
776 */
777
778/*
779 * Search TLB for entry that we are currently using.
780 * Invalidate all entries but the one we are using.
781 */
782 /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
783 mfspr r3,SPRN_PID /* Get PID */
784 mfmsr r4 /* Get MSR */
785 andi. r4,r4,MSR_IS@l /* TS=1? */
786 beq wmmucr /* If not, leave STS=0 */
787 oris r3,r3,PPC44x_MMUCR_STS@h /* Set STS=1 */
788wmmucr: mtspr SPRN_MMUCR,r3 /* Put MMUCR */
789 sync
790
791 bl invstr /* Find our address */
792invstr: mflr r5 /* Make it accessible */
793 tlbsx r23,0,r5 /* Find entry we are in */
794 li r4,0 /* Start at TLB entry 0 */
795 li r3,0 /* Set PAGEID inval value */
7961: cmpw r23,r4 /* Is this our entry? */
797 beq skpinv /* If so, skip the inval */
798 tlbwe r3,r4,PPC44x_TLB_PAGEID /* If not, inval the entry */
799skpinv: addi r4,r4,1 /* Increment */
800 cmpwi r4,64 /* Are we done? */
801 bne 1b /* If not, repeat */
802 isync /* If so, context change */
803
804/*
805 * Configure and load pinned entry into TLB slot 63.
806 */
807
808 lis r3,PAGE_OFFSET@h
809 ori r3,r3,PAGE_OFFSET@l
810
811 /* Kernel is at the base of RAM */
812 li r4, 0 /* Load the kernel physical address */
813
814 /* Load the kernel PID = 0 */
815 li r0,0
816 mtspr SPRN_PID,r0
817 sync
818
819 /* Initialize MMUCR */
820 li r5,0
821 mtspr SPRN_MMUCR,r5
822 sync
823
824 /* pageid fields */
825 clrrwi r3,r3,10 /* Mask off the effective page number */
826 ori r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M
827
828 /* xlat fields */
829 clrrwi r4,r4,10 /* Mask off the real page number */
830 /* ERPN is 0 for first 4GB page */
831
832 /* attrib fields */
833 /* Added guarded bit to protect against speculative loads/stores */
834 li r5,0
835 ori r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G)
836
837 li r0,63 /* TLB slot 63 */
838
839 tlbwe r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */
840 tlbwe r4,r0,PPC44x_TLB_XLAT /* Load the translation fields */
841 tlbwe r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */
842
843 /* Force context change */
844 mfmsr r0
845 mtspr SPRN_SRR1, r0
846 lis r0,3f@h
847 ori r0,r0,3f@l
848 mtspr SPRN_SRR0,r0
849 sync
850 rfi
851
852 /* If necessary, invalidate original entry we used */
8533: cmpwi r23,63
854 beq 4f
855 li r6,0
856 tlbwe r6,r23,PPC44x_TLB_PAGEID
857 isync
858
8594:
860#ifdef CONFIG_PPC_EARLY_DEBUG_44x
861 /* Add UART mapping for early debug. */
862
863 /* pageid fields */
864 lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
865 ori r3,r3,PPC44x_TLB_VALID|PPC44x_TLB_TS|PPC44x_TLB_64K
866
867 /* xlat fields */
868 lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
869 ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
870
871 /* attrib fields */
872 li r5,(PPC44x_TLB_SW|PPC44x_TLB_SR|PPC44x_TLB_I|PPC44x_TLB_G)
873 li r0,62 /* TLB slot 0 */
874
875 tlbwe r3,r0,PPC44x_TLB_PAGEID
876 tlbwe r4,r0,PPC44x_TLB_XLAT
877 tlbwe r5,r0,PPC44x_TLB_ATTRIB
878
879 /* Force context change */
880 isync
881#endif /* CONFIG_PPC_EARLY_DEBUG_44x */
882
883 /* Establish the interrupt vector offsets */
884 SET_IVOR(0, CriticalInput);
885 SET_IVOR(1, MachineCheck);
886 SET_IVOR(2, DataStorage);
887 SET_IVOR(3, InstructionStorage);
888 SET_IVOR(4, ExternalInput);
889 SET_IVOR(5, Alignment);
890 SET_IVOR(6, Program);
891 SET_IVOR(7, FloatingPointUnavailable);
892 SET_IVOR(8, SystemCall);
893 SET_IVOR(9, AuxillaryProcessorUnavailable);
894 SET_IVOR(10, Decrementer);
895 SET_IVOR(11, FixedIntervalTimer);
896 SET_IVOR(12, WatchdogTimer);
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000897 SET_IVOR(13, DataTLBError44x);
898 SET_IVOR(14, InstructionTLBError44x);
Dave Kleikamp795033c2010-03-05 10:43:07 +0000899 SET_IVOR(15, DebugCrit);
900
Dave Kleikampe7f75ad2010-03-05 10:43:12 +0000901 b head_start_common
902
903
904#ifdef CONFIG_PPC_47x
905
906#ifdef CONFIG_SMP
907
908/* Entry point for secondary 47x processors */
909_GLOBAL(start_secondary_47x)
910 mr r24,r3 /* CPU number */
911
912 bl init_cpu_state
913
914 /* Now we need to bolt the rest of kernel memory which
915 * is done in C code. We must be careful because our task
916 * struct or our stack can (and will probably) be out
917 * of reach of the initial 256M TLB entry, so we use a
918 * small temporary stack in .bss for that. This works
919 * because only one CPU at a time can be in this code
920 */
921 lis r1,temp_boot_stack@h
922 ori r1,r1,temp_boot_stack@l
923 addi r1,r1,1024-STACK_FRAME_OVERHEAD
924 li r0,0
925 stw r0,0(r1)
926 bl mmu_init_secondary
927
928 /* Now we can get our task struct and real stack pointer */
929
930 /* Get current_thread_info and current */
931 lis r1,secondary_ti@ha
932 lwz r1,secondary_ti@l(r1)
933 lwz r2,TI_TASK(r1)
934
935 /* Current stack pointer */
936 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
937 li r0,0
938 stw r0,0(r1)
939
940 /* Kernel stack for exception entry in SPRG3 */
941 addi r4,r2,THREAD /* init task's THREAD */
942 mtspr SPRN_SPRG3,r4
943
944 b start_secondary
945
946#endif /* CONFIG_SMP */
947
948/*
949 * Set up the initial MMU state for 44x
950 *
951 * We are still executing code at the virtual address
952 * mappings set by the firmware for the base of RAM.
953 */
954
955head_start_47x:
956 /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
957 mfspr r3,SPRN_PID /* Get PID */
958 mfmsr r4 /* Get MSR */
959 andi. r4,r4,MSR_IS@l /* TS=1? */
960 beq 1f /* If not, leave STS=0 */
961 oris r3,r3,PPC47x_MMUCR_STS@h /* Set STS=1 */
9621: mtspr SPRN_MMUCR,r3 /* Put MMUCR */
963 sync
964
965 /* Find the entry we are running from */
966 bl 1f
9671: mflr r23
968 tlbsx r23,0,r23
969 tlbre r24,r23,0
970 tlbre r25,r23,1
971 tlbre r26,r23,2
972
973/*
974 * Cleanup time
975 */
976
977 /* Initialize MMUCR */
978 li r5,0
979 mtspr SPRN_MMUCR,r5
980 sync
981
982clear_all_utlb_entries:
983
984 #; Set initial values.
985
986 addis r3,0,0x8000
987 addi r4,0,0
988 addi r5,0,0
989 b clear_utlb_entry
990
991 #; Align the loop to speed things up.
992
993 .align 6
994
995clear_utlb_entry:
996
997 tlbwe r4,r3,0
998 tlbwe r5,r3,1
999 tlbwe r5,r3,2
1000 addis r3,r3,0x2000
1001 cmpwi r3,0
1002 bne clear_utlb_entry
1003 addis r3,0,0x8000
1004 addis r4,r4,0x100
1005 cmpwi r4,0
1006 bne clear_utlb_entry
1007
1008 #; Restore original entry.
1009
1010 oris r23,r23,0x8000 /* specify the way */
1011 tlbwe r24,r23,0
1012 tlbwe r25,r23,1
1013 tlbwe r26,r23,2
1014
1015/*
1016 * Configure and load pinned entry into TLB for the kernel core
1017 */
1018
1019 lis r3,PAGE_OFFSET@h
1020 ori r3,r3,PAGE_OFFSET@l
1021
Dave Kleikampe7f75ad2010-03-05 10:43:12 +00001022 /* Load the kernel PID = 0 */
1023 li r0,0
1024 mtspr SPRN_PID,r0
1025 sync
1026
1027 /* Word 0 */
1028 clrrwi r3,r3,12 /* Mask off the effective page number */
1029 ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_256M
1030
Dave Kleikamp96615342011-07-04 18:36:57 +00001031 /* Word 1 - use r25. RPN is the same as the original entry */
1032
Dave Kleikampe7f75ad2010-03-05 10:43:12 +00001033 /* Word 2 */
1034 li r5,0
1035 ori r5,r5,PPC47x_TLB2_S_RWX
1036#ifdef CONFIG_SMP
1037 ori r5,r5,PPC47x_TLB2_M
1038#endif
1039
1040 /* We write to way 0 and bolted 0 */
1041 lis r0,0x8800
1042 tlbwe r3,r0,0
Dave Kleikamp96615342011-07-04 18:36:57 +00001043 tlbwe r25,r0,1
Dave Kleikampe7f75ad2010-03-05 10:43:12 +00001044 tlbwe r5,r0,2
1045
1046/*
1047 * Configure SSPCR, ISPCR and USPCR for now to search everything, we can fix
1048 * them up later
1049 */
1050 LOAD_REG_IMMEDIATE(r3, 0x9abcdef0)
1051 mtspr SPRN_SSPCR,r3
1052 mtspr SPRN_USPCR,r3
1053 LOAD_REG_IMMEDIATE(r3, 0x12345670)
1054 mtspr SPRN_ISPCR,r3
1055
1056 /* Force context change */
1057 mfmsr r0
1058 mtspr SPRN_SRR1, r0
1059 lis r0,3f@h
1060 ori r0,r0,3f@l
1061 mtspr SPRN_SRR0,r0
1062 sync
1063 rfi
1064
1065 /* Invalidate original entry we used */
10663:
1067 rlwinm r24,r24,0,21,19 /* clear the "valid" bit */
1068 tlbwe r24,r23,0
1069 addi r24,0,0
1070 tlbwe r24,r23,1
1071 tlbwe r24,r23,2
1072 isync /* Clear out the shadow TLB entries */
1073
1074#ifdef CONFIG_PPC_EARLY_DEBUG_44x
1075 /* Add UART mapping for early debug. */
1076
1077 /* Word 0 */
1078 lis r3,PPC44x_EARLY_DEBUG_VIRTADDR@h
1079 ori r3,r3,PPC47x_TLB0_VALID | PPC47x_TLB0_TS | PPC47x_TLB0_1M
1080
1081 /* Word 1 */
1082 lis r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSLOW@h
1083 ori r4,r4,CONFIG_PPC_EARLY_DEBUG_44x_PHYSHIGH
1084
1085 /* Word 2 */
1086 li r5,(PPC47x_TLB2_S_RW | PPC47x_TLB2_IMG)
1087
1088 /* Bolted in way 0, bolt slot 5, we -hope- we don't hit the same
1089 * congruence class as the kernel, we need to make sure of it at
1090 * some point
1091 */
1092 lis r0,0x8d00
1093 tlbwe r3,r0,0
1094 tlbwe r4,r0,1
1095 tlbwe r5,r0,2
1096
1097 /* Force context change */
1098 isync
1099#endif /* CONFIG_PPC_EARLY_DEBUG_44x */
1100
1101 /* Establish the interrupt vector offsets */
1102 SET_IVOR(0, CriticalInput);
1103 SET_IVOR(1, MachineCheckA);
1104 SET_IVOR(2, DataStorage);
1105 SET_IVOR(3, InstructionStorage);
1106 SET_IVOR(4, ExternalInput);
1107 SET_IVOR(5, Alignment);
1108 SET_IVOR(6, Program);
1109 SET_IVOR(7, FloatingPointUnavailable);
1110 SET_IVOR(8, SystemCall);
1111 SET_IVOR(9, AuxillaryProcessorUnavailable);
1112 SET_IVOR(10, Decrementer);
1113 SET_IVOR(11, FixedIntervalTimer);
1114 SET_IVOR(12, WatchdogTimer);
1115 SET_IVOR(13, DataTLBError47x);
1116 SET_IVOR(14, InstructionTLBError47x);
1117 SET_IVOR(15, DebugCrit);
1118
1119 /* We configure icbi to invalidate 128 bytes at a time since the
1120 * current 32-bit kernel code isn't too happy with icache != dcache
1121 * block size
1122 */
1123 mfspr r3,SPRN_CCR0
1124 oris r3,r3,0x0020
1125 mtspr SPRN_CCR0,r3
1126 isync
1127
1128#endif /* CONFIG_PPC_47x */
1129
1130/*
1131 * Here we are back to code that is common between 44x and 47x
1132 *
1133 * We proceed to further kernel initialization and return to the
1134 * main kernel entry
1135 */
1136head_start_common:
Dave Kleikamp795033c2010-03-05 10:43:07 +00001137 /* Establish the interrupt vector base */
1138 lis r4,interrupt_base@h /* IVPR only uses the high 16-bits */
1139 mtspr SPRN_IVPR,r4
1140
Dave Kleikamp96615342011-07-04 18:36:57 +00001141 /*
1142 * If the kernel was loaded at a non-zero 256 MB page, we need to
1143 * mask off the most significant 4 bits to get the relative address
1144 * from the start of physical memory
1145 */
1146 rlwinm r22,r22,0,4,31
1147 addis r22,r22,PAGE_OFFSET@h
Dave Kleikamp795033c2010-03-05 10:43:07 +00001148 mtlr r22
Dave Kleikampe7f75ad2010-03-05 10:43:12 +00001149 isync
Dave Kleikamp795033c2010-03-05 10:43:07 +00001150 blr
1151
1152/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001153 * We put a few things here that have to be page-aligned. This stuff
1154 * goes at the beginning of the data segment, which is page-aligned.
1155 */
1156 .data
Ilya Yanokca9153a2008-12-11 04:55:41 +03001157 .align PAGE_SHIFT
Kumar Galaea703ce2005-10-11 23:54:00 -05001158 .globl sdata
1159sdata:
1160 .globl empty_zero_page
1161empty_zero_page:
Ilya Yanokca9153a2008-12-11 04:55:41 +03001162 .space PAGE_SIZE
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001163
1164/*
1165 * To support >32-bit physical addresses, we use an 8KB pgdir.
1166 */
Kumar Galaea703ce2005-10-11 23:54:00 -05001167 .globl swapper_pg_dir
1168swapper_pg_dir:
Kumar Galabee86f12007-12-06 13:11:04 -06001169 .space PGD_TABLE_SIZE
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001170
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001171/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001172 * Room for two PTE pointers, usually the kernel and current user pointers
1173 * to their respective root page table.
1174 */
1175abatron_pteptrs:
1176 .space 8
Dave Kleikampe7f75ad2010-03-05 10:43:12 +00001177
1178#ifdef CONFIG_SMP
1179 .align 12
1180temp_boot_stack:
1181 .space 1024
1182#endif /* CONFIG_SMP */