blob: 6cdfd44d8efe6eeb5371c75fee7392b3515aa04f [file] [log] [blame]
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10002 * PowerPC version
3 * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
4 *
5 * Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
6 * Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
7 * Adapted for Power Macintosh by Paul Mackerras.
8 * Low-level exception handlers and MMU support
9 * rewritten by Paul Mackerras.
10 * Copyright (C) 1996 Paul Mackerras.
11 *
12 * Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
13 * Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
14 *
15 * This file contains the low-level support and setup for the
16 * PowerPC-64 platform, including trap and interrupt dispatch.
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 */
23
Paul Mackerras14cf11a2005-09-26 16:04:21 +100024#include <linux/threads.h>
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100025#include <asm/reg.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100026#include <asm/page.h>
27#include <asm/mmu.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100028#include <asm/ppc_asm.h>
29#include <asm/asm-offsets.h>
30#include <asm/bug.h>
31#include <asm/cputable.h>
32#include <asm/setup.h>
33#include <asm/hvcall.h>
Kelly Dalyc43a55f2005-11-02 15:02:47 +110034#include <asm/iseries/lpar_map.h>
David Gibson6cb7bfe2005-10-21 15:45:50 +100035#include <asm/thread_info.h>
Stephen Rothwell3f639ee2006-09-25 18:19:00 +100036#include <asm/firmware.h>
Stephen Rothwell16a15a32007-08-20 14:58:36 +100037#include <asm/page_64.h>
Stephen Rothwellf9ff0f32007-08-22 13:46:44 +100038#include <asm/exception.h>
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +100039#include <asm/irqflags.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100040
41/*
42 * We layout physical memory as follows:
43 * 0x0000 - 0x00ff : Secondary processor spin code
44 * 0x0100 - 0x2fff : pSeries Interrupt prologs
45 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
46 * 0x6000 - 0x6fff : Initial (CPU0) segment table
47 * 0x7000 - 0x7fff : FWNMI data area
48 * 0x8000 - : Early init and support code
49 */
50
51/*
52 * SPRG Usage
53 *
54 * Register Definition
55 *
56 * SPRG0 reserved for hypervisor
57 * SPRG1 temp - used to save gpr
58 * SPRG2 temp - used to save gpr
59 * SPRG3 virt addr of paca
60 */
61
62/*
63 * Entering into this code we make the following assumptions:
64 * For pSeries:
65 * 1. The MMU is off & open firmware is running in real mode.
66 * 2. The kernel is entered at __start
67 *
68 * For iSeries:
69 * 1. The MMU is on (as it always is for iSeries)
70 * 2. The kernel is entered at system_reset_iSeries
71 */
72
73 .text
74 .globl _stext
75_stext:
Paul Mackerras14cf11a2005-09-26 16:04:21 +100076_GLOBAL(__start)
77 /* NOP this out unconditionally */
78BEGIN_FTR_SECTION
Paul Mackerrasb85a0462005-10-06 10:59:19 +100079 b .__start_initialization_multiplatform
Paul Mackerras14cf11a2005-09-26 16:04:21 +100080END_FTR_SECTION(0, 1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100081
82 /* Catch branch to 0 in real mode */
83 trap
84
Paul Mackerras1f6a93e2008-08-30 11:40:24 +100085 /* Secondary processors spin on this value until it becomes nonzero.
86 * When it does it contains the real address of the descriptor
87 * of the function that the cpu should jump to to continue
88 * initialization.
89 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100090 .globl __secondary_hold_spinloop
91__secondary_hold_spinloop:
92 .llong 0x0
93
94 /* Secondary processors write this value with their cpu # */
95 /* after they enter the spin loop immediately below. */
96 .globl __secondary_hold_acknowledge
97__secondary_hold_acknowledge:
98 .llong 0x0
99
Michael Ellerman1dce0e32006-06-23 18:15:37 +1000100#ifdef CONFIG_PPC_ISERIES
101 /*
102 * At offset 0x20, there is a pointer to iSeries LPAR data.
103 * This is required by the hypervisor
104 */
105 . = 0x20
106 .llong hvReleaseData-KERNELBASE
107#endif /* CONFIG_PPC_ISERIES */
108
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000109 . = 0x60
110/*
Geoff Levand75423b72007-06-16 08:06:23 +1000111 * The following code is used to hold secondary processors
112 * in a spin loop after they have entered the kernel, but
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000113 * before the bulk of the kernel has been relocated. This code
114 * is relocated to physical address 0x60 before prom_init is run.
115 * All of it must fit below the first exception vector at 0x100.
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000116 * Use .globl here not _GLOBAL because we want __secondary_hold
117 * to be the actual text address, not a descriptor.
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000118 */
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000119 .globl __secondary_hold
120__secondary_hold:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000121 mfmsr r24
122 ori r24,r24,MSR_RI
123 mtmsrd r24 /* RI on */
124
Anton Blanchardf1870f72006-02-13 18:11:13 +1100125 /* Grab our physical cpu number */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000126 mr r24,r3
127
128 /* Tell the master cpu we're here */
129 /* Relocation is off & we are located at an address less */
130 /* than 0x100, so only need to grab low order offset. */
Paul Mackerrase31aa452008-08-30 11:41:12 +1000131 std r24,__secondary_hold_acknowledge-_stext(0)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000132 sync
133
134 /* All secondary cpus wait here until told to start. */
Paul Mackerrase31aa452008-08-30 11:41:12 +1000135100: ld r4,__secondary_hold_spinloop-_stext(0)
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000136 cmpdi 0,r4,0
137 beq 100b
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000138
Anton Blanchardf1870f72006-02-13 18:11:13 +1100139#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000140 ld r4,0(r4) /* deref function descriptor */
Michael Ellerman758438a2005-12-05 15:49:00 -0600141 mtctr r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000142 mr r3,r24
Michael Ellerman758438a2005-12-05 15:49:00 -0600143 bctr
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000144#else
145 BUG_OPCODE
146#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000147
148/* This value is used to mark exception frames on the stack. */
149 .section ".toc","aw"
150exception_marker:
151 .tc ID_72656773_68657265[TC],0x7265677368657265
152 .text
153
154/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000155 * This is the start of the interrupt handlers for pSeries
156 * This code runs with relocation off.
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000157 * Code from here to __end_interrupts gets copied down to real
158 * address 0x100 when we are running a relocatable kernel.
159 * Therefore any relative branches in this section must only
160 * branch to labels in this section.
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000161 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000162 . = 0x100
163 .globl __start_interrupts
164__start_interrupts:
165
166 STD_EXCEPTION_PSERIES(0x100, system_reset)
167
168 . = 0x200
169_machine_check_pSeries:
170 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000171 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000172 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
173
174 . = 0x300
175 .globl data_access_pSeries
176data_access_pSeries:
177 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000178 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000179BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000180 mtspr SPRN_SPRG2,r12
181 mfspr r13,SPRN_DAR
182 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000183 srdi r13,r13,60
184 rlwimi r13,r12,16,0x20
185 mfcr r12
186 cmpwi r13,0x2c
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100187 beq do_stab_bolted_pSeries
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000188 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000189 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000190END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
191 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
192
193 . = 0x380
194 .globl data_access_slb_pSeries
195data_access_slb_pSeries:
196 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000197 mtspr SPRN_SPRG1,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000198 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100199 std r3,PACA_EXSLB+EX_R3(r13)
200 mfspr r3,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000201 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100202 mfcr r9
203#ifdef __DISABLED__
204 /* Keep that around for when we re-implement dynamic VSIDs */
205 cmpdi r3,0
206 bge slb_miss_user_pseries
207#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000208 std r10,PACA_EXSLB+EX_R10(r13)
209 std r11,PACA_EXSLB+EX_R11(r13)
210 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100211 mfspr r10,SPRN_SPRG1
212 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000213 mfspr r12,SPRN_SRR1 /* and SRR1 */
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000214#ifndef CONFIG_RELOCATABLE
215 b .slb_miss_realmode
216#else
217 /*
218 * We can't just use a direct branch to .slb_miss_realmode
219 * because the distance from here to there depends on where
220 * the kernel ends up being put.
221 */
222 mfctr r11
223 ld r10,PACAKBASE(r13)
224 LOAD_HANDLER(r10, .slb_miss_realmode)
225 mtctr r10
226 bctr
227#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000228
229 STD_EXCEPTION_PSERIES(0x400, instruction_access)
230
231 . = 0x480
232 .globl instruction_access_slb_pSeries
233instruction_access_slb_pSeries:
234 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000235 mtspr SPRN_SPRG1,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000236 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100237 std r3,PACA_EXSLB+EX_R3(r13)
238 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000239 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100240 mfcr r9
241#ifdef __DISABLED__
242 /* Keep that around for when we re-implement dynamic VSIDs */
243 cmpdi r3,0
244 bge slb_miss_user_pseries
245#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000246 std r10,PACA_EXSLB+EX_R10(r13)
247 std r11,PACA_EXSLB+EX_R11(r13)
248 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100249 mfspr r10,SPRN_SPRG1
250 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000251 mfspr r12,SPRN_SRR1 /* and SRR1 */
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000252#ifndef CONFIG_RELOCATABLE
253 b .slb_miss_realmode
254#else
255 mfctr r11
256 ld r10,PACAKBASE(r13)
257 LOAD_HANDLER(r10, .slb_miss_realmode)
258 mtctr r10
259 bctr
260#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000261
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000262 MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000263 STD_EXCEPTION_PSERIES(0x600, alignment)
264 STD_EXCEPTION_PSERIES(0x700, program_check)
265 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000266 MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000267 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
268 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
269
270 . = 0xc00
271 .globl system_call_pSeries
272system_call_pSeries:
273 HMT_MEDIUM
Paul Mackerras745a14c2008-04-28 13:52:31 +1000274BEGIN_FTR_SECTION
275 cmpdi r0,0x1ebe
276 beq- 1f
277END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000278 mr r9,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000279 mfspr r13,SPRN_SPRG3
280 mfspr r11,SPRN_SRR0
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000281 ld r12,PACAKBASE(r13)
282 ld r10,PACAKMSR(r13)
283 LOAD_HANDLER(r12, system_call_entry)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000284 mtspr SPRN_SRR0,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000285 mfspr r12,SPRN_SRR1
286 mtspr SPRN_SRR1,r10
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000287 rfid
288 b . /* prevent speculative execution */
289
Paul Mackerras745a14c2008-04-28 13:52:31 +1000290/* Fast LE/BE switch system call */
2911: mfspr r12,SPRN_SRR1
292 xori r12,r12,MSR_LE
293 mtspr SPRN_SRR1,r12
294 rfid /* return to userspace */
295 b .
296
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000297 STD_EXCEPTION_PSERIES(0xd00, single_step)
298 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
299
300 /* We need to deal with the Altivec unavailable exception
301 * here which is at 0xf20, thus in the middle of the
302 * prolog code of the PerformanceMonitor one. A little
303 * trickery is thus necessary
304 */
305 . = 0xf00
306 b performance_monitor_pSeries
307
Michael Neuling10e34392008-06-25 14:07:18 +1000308 . = 0xf20
309 b altivec_unavailable_pSeries
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000310
Michael Neulingce48b212008-06-25 14:07:18 +1000311 . = 0xf40
312 b vsx_unavailable_pSeries
313
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200314#ifdef CONFIG_CBE_RAS
315 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
316#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000317 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200318#ifdef CONFIG_CBE_RAS
319 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
320#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000321 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200322#ifdef CONFIG_CBE_RAS
323 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
324#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000325
326 . = 0x3000
327
328/*** pSeries interrupt support ***/
329
330 /* moved from 0xf00 */
Livio Soares449d8462007-02-07 12:51:36 +1100331 STD_EXCEPTION_PSERIES(., performance_monitor)
Michael Neuling10e34392008-06-25 14:07:18 +1000332 STD_EXCEPTION_PSERIES(., altivec_unavailable)
Michael Neulingce48b212008-06-25 14:07:18 +1000333 STD_EXCEPTION_PSERIES(., vsx_unavailable)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000334
335/*
336 * An interrupt came in while soft-disabled; clear EE in SRR1,
337 * clear paca->hard_enabled and return.
338 */
339masked_interrupt:
340 stb r10,PACAHARDIRQEN(r13)
341 mtcrf 0x80,r9
342 ld r9,PACA_EXGEN+EX_R9(r13)
343 mfspr r10,SPRN_SRR1
344 rldicl r10,r10,48,1 /* clear MSR_EE */
345 rotldi r10,r10,16
346 mtspr SPRN_SRR1,r10
347 ld r10,PACA_EXGEN+EX_R10(r13)
348 mfspr r13,SPRN_SPRG1
349 rfid
350 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000351
352 .align 7
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100353do_stab_bolted_pSeries:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000354 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000355 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000356 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
357
Paul Mackerras9a955162008-08-30 11:39:26 +1000358#ifdef CONFIG_PPC_PSERIES
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000359/*
Paul Mackerras9a955162008-08-30 11:39:26 +1000360 * Vectors for the FWNMI option. Share common code.
361 */
362 .globl system_reset_fwnmi
363 .align 7
364system_reset_fwnmi:
365 HMT_MEDIUM
366 mtspr SPRN_SPRG1,r13 /* save r13 */
367 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
368
369 .globl machine_check_fwnmi
370 .align 7
371machine_check_fwnmi:
372 HMT_MEDIUM
373 mtspr SPRN_SPRG1,r13 /* save r13 */
374 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
375
376#endif /* CONFIG_PPC_PSERIES */
377
378#ifdef __DISABLED__
379/*
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100380 * This is used for when the SLB miss handler has to go virtual,
381 * which doesn't happen for now anymore but will once we re-implement
382 * dynamic VSIDs for shared page tables
383 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100384slb_miss_user_pseries:
385 std r10,PACA_EXGEN+EX_R10(r13)
386 std r11,PACA_EXGEN+EX_R11(r13)
387 std r12,PACA_EXGEN+EX_R12(r13)
388 mfspr r10,SPRG1
389 ld r11,PACA_EXSLB+EX_R9(r13)
390 ld r12,PACA_EXSLB+EX_R3(r13)
391 std r10,PACA_EXGEN+EX_R13(r13)
392 std r11,PACA_EXGEN+EX_R9(r13)
393 std r12,PACA_EXGEN+EX_R3(r13)
394 clrrdi r12,r13,32
395 mfmsr r10
396 mfspr r11,SRR0 /* save SRR0 */
397 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
398 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
399 mtspr SRR0,r12
400 mfspr r12,SRR1 /* and SRR1 */
401 mtspr SRR1,r10
402 rfid
403 b . /* prevent spec. execution */
404#endif /* __DISABLED__ */
405
Paul Mackerras9a955162008-08-30 11:39:26 +1000406 .align 7
407 .globl __end_interrupts
408__end_interrupts:
409
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100410/*
Paul Mackerras9a955162008-08-30 11:39:26 +1000411 * Code from here down to __end_handlers is invoked from the
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000412 * exception prologs above. Because the prologs assemble the
413 * addresses of these handlers using the LOAD_HANDLER macro,
414 * which uses an addi instruction, these handlers must be in
415 * the first 32k of the kernel image.
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000416 */
Stephen Rothwell9e4859e2007-09-18 17:25:12 +1000417
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000418/*** Common interrupt handlers ***/
419
420 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
421
422 /*
423 * Machine check is different because we use a different
424 * save area: PACA_EXMC instead of PACA_EXGEN.
425 */
426 .align 7
427 .globl machine_check_common
428machine_check_common:
429 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000430 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000431 DISABLE_INTS
432 bl .save_nvgprs
433 addi r3,r1,STACK_FRAME_OVERHEAD
434 bl .machine_check_exception
435 b .ret_from_except
436
437 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
438 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
439 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
440 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
441 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000442 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000443 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
444#ifdef CONFIG_ALTIVEC
445 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
446#else
447 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
448#endif
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200449#ifdef CONFIG_CBE_RAS
450 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
451 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
452 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
453#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000454
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000455 .align 7
456system_call_entry:
457 b system_call_common
458
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000459/*
460 * Here we have detected that the kernel stack pointer is bad.
461 * R9 contains the saved CR, r13 points to the paca,
462 * r10 contains the (bad) kernel stack pointer,
463 * r11 and r12 contain the saved SRR0 and SRR1.
464 * We switch to using an emergency stack, save the registers there,
465 * and call kernel_bad_stack(), which panics.
466 */
467bad_stack:
468 ld r1,PACAEMERGSP(r13)
469 subi r1,r1,64+INT_FRAME_SIZE
470 std r9,_CCR(r1)
471 std r10,GPR1(r1)
472 std r11,_NIP(r1)
473 std r12,_MSR(r1)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000474 mfspr r11,SPRN_DAR
475 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000476 std r11,_DAR(r1)
477 std r12,_DSISR(r1)
478 mflr r10
479 mfctr r11
480 mfxer r12
481 std r10,_LINK(r1)
482 std r11,_CTR(r1)
483 std r12,_XER(r1)
484 SAVE_GPR(0,r1)
485 SAVE_GPR(2,r1)
486 SAVE_4GPRS(3,r1)
487 SAVE_2GPRS(7,r1)
488 SAVE_10GPRS(12,r1)
489 SAVE_10GPRS(22,r1)
Olof Johansson68730402007-04-24 01:11:55 +1000490 lhz r12,PACA_TRAP_SAVE(r13)
491 std r12,_TRAP(r1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000492 addi r11,r1,INT_FRAME_SIZE
493 std r11,0(r1)
494 li r12,0
495 std r12,0(r11)
496 ld r2,PACATOC(r13)
4971: addi r3,r1,STACK_FRAME_OVERHEAD
498 bl .kernel_bad_stack
499 b 1b
500
501/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000502 * Here r13 points to the paca, r9 contains the saved CR,
503 * SRR0 and SRR1 are saved in r11 and r12,
504 * r9 - r13 are saved in paca->exgen.
505 */
506 .align 7
507 .globl data_access_common
508data_access_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000509 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000510 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000511 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000512 stw r10,PACA_EXGEN+EX_DSISR(r13)
513 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
514 ld r3,PACA_EXGEN+EX_DAR(r13)
515 lwz r4,PACA_EXGEN+EX_DSISR(r13)
516 li r5,0x300
517 b .do_hash_page /* Try to handle as hpte fault */
518
519 .align 7
520 .globl instruction_access_common
521instruction_access_common:
522 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
523 ld r3,_NIP(r1)
524 andis. r4,r12,0x5820
525 li r5,0x400
526 b .do_hash_page /* Try to handle as hpte fault */
527
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100528/*
529 * Here is the common SLB miss user that is used when going to virtual
530 * mode for SLB misses, that is currently not used
531 */
532#ifdef __DISABLED__
533 .align 7
534 .globl slb_miss_user_common
535slb_miss_user_common:
536 mflr r10
537 std r3,PACA_EXGEN+EX_DAR(r13)
538 stw r9,PACA_EXGEN+EX_CCR(r13)
539 std r10,PACA_EXGEN+EX_LR(r13)
540 std r11,PACA_EXGEN+EX_SRR0(r13)
541 bl .slb_allocate_user
542
543 ld r10,PACA_EXGEN+EX_LR(r13)
544 ld r3,PACA_EXGEN+EX_R3(r13)
545 lwz r9,PACA_EXGEN+EX_CCR(r13)
546 ld r11,PACA_EXGEN+EX_SRR0(r13)
547 mtlr r10
548 beq- slb_miss_fault
549
550 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
551 beq- unrecov_user_slb
552 mfmsr r10
553
554.machine push
555.machine "power4"
556 mtcrf 0x80,r9
557.machine pop
558
559 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
560 mtmsrd r10,1
561
562 mtspr SRR0,r11
563 mtspr SRR1,r12
564
565 ld r9,PACA_EXGEN+EX_R9(r13)
566 ld r10,PACA_EXGEN+EX_R10(r13)
567 ld r11,PACA_EXGEN+EX_R11(r13)
568 ld r12,PACA_EXGEN+EX_R12(r13)
569 ld r13,PACA_EXGEN+EX_R13(r13)
570 rfid
571 b .
572
573slb_miss_fault:
574 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
575 ld r4,PACA_EXGEN+EX_DAR(r13)
576 li r5,0
577 std r4,_DAR(r1)
578 std r5,_DSISR(r1)
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100579 b handle_page_fault
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100580
581unrecov_user_slb:
582 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
583 DISABLE_INTS
584 bl .save_nvgprs
5851: addi r3,r1,STACK_FRAME_OVERHEAD
586 bl .unrecoverable_exception
587 b 1b
588
589#endif /* __DISABLED__ */
590
591
592/*
593 * r13 points to the PACA, r9 contains the saved CR,
594 * r12 contain the saved SRR1, SRR0 is still ready for return
595 * r3 has the faulting address
596 * r9 - r13 are saved in paca->exslb.
597 * r3 is saved in paca->slb_r3
598 * We assume we aren't going to take any exceptions during this procedure.
599 */
600_GLOBAL(slb_miss_realmode)
601 mflr r10
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000602#ifdef CONFIG_RELOCATABLE
603 mtctr r11
604#endif
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100605
606 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
607 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
608
609 bl .slb_allocate_realmode
610
611 /* All done -- return from exception. */
612
613 ld r10,PACA_EXSLB+EX_LR(r13)
614 ld r3,PACA_EXSLB+EX_R3(r13)
615 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
616#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000617BEGIN_FW_FTR_SECTION
David Gibson3356bb92006-01-13 10:26:42 +1100618 ld r11,PACALPPACAPTR(r13)
619 ld r11,LPPACASRR0(r11) /* get SRR0 value */
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000620END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100621#endif /* CONFIG_PPC_ISERIES */
622
623 mtlr r10
624
625 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
Paul Mackerras320787c2008-04-14 13:59:02 +1000626 beq- 2f
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100627
628.machine push
629.machine "power4"
630 mtcrf 0x80,r9
631 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
632.machine pop
633
634#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000635BEGIN_FW_FTR_SECTION
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100636 mtspr SPRN_SRR0,r11
637 mtspr SPRN_SRR1,r12
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000638END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100639#endif /* CONFIG_PPC_ISERIES */
640 ld r9,PACA_EXSLB+EX_R9(r13)
641 ld r10,PACA_EXSLB+EX_R10(r13)
642 ld r11,PACA_EXSLB+EX_R11(r13)
643 ld r12,PACA_EXSLB+EX_R12(r13)
644 ld r13,PACA_EXSLB+EX_R13(r13)
645 rfid
646 b . /* prevent speculative execution */
647
Paul Mackerras320787c2008-04-14 13:59:02 +10006482:
649#ifdef CONFIG_PPC_ISERIES
650BEGIN_FW_FTR_SECTION
651 b unrecov_slb
652END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
653#endif /* CONFIG_PPC_ISERIES */
654 mfspr r11,SPRN_SRR0
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000655 ld r10,PACAKBASE(r13)
Paul Mackerras320787c2008-04-14 13:59:02 +1000656 LOAD_HANDLER(r10,unrecov_slb)
657 mtspr SPRN_SRR0,r10
Paul Mackerras1f6a93e2008-08-30 11:40:24 +1000658 ld r10,PACAKMSR(r13)
Paul Mackerras320787c2008-04-14 13:59:02 +1000659 mtspr SPRN_SRR1,r10
660 rfid
661 b .
662
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100663unrecov_slb:
664 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
665 DISABLE_INTS
666 bl .save_nvgprs
6671: addi r3,r1,STACK_FRAME_OVERHEAD
668 bl .unrecoverable_exception
669 b 1b
670
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000671 .align 7
672 .globl hardware_interrupt_common
673 .globl hardware_interrupt_entry
674hardware_interrupt_common:
675 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000676 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000677hardware_interrupt_entry:
678 DISABLE_INTS
Olof Johanssona4165612007-09-05 12:42:30 +1000679BEGIN_FTR_SECTION
Anton Blanchardcb2c9b22006-02-13 14:48:35 +1100680 bl .ppc64_runlatch_on
Olof Johanssona4165612007-09-05 12:42:30 +1000681END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000682 addi r3,r1,STACK_FRAME_OVERHEAD
683 bl .do_IRQ
684 b .ret_from_except_lite
685
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000686#ifdef CONFIG_PPC_970_NAP
687power4_fixup_nap:
688 andc r9,r9,r10
689 std r9,TI_LOCAL_FLAGS(r11)
690 ld r10,_LINK(r1) /* make idle task do the */
691 std r10,_NIP(r1) /* equivalent of a blr */
692 blr
693#endif
694
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000695 .align 7
696 .globl alignment_common
697alignment_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000698 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000699 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000700 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000701 stw r10,PACA_EXGEN+EX_DSISR(r13)
702 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
703 ld r3,PACA_EXGEN+EX_DAR(r13)
704 lwz r4,PACA_EXGEN+EX_DSISR(r13)
705 std r3,_DAR(r1)
706 std r4,_DSISR(r1)
707 bl .save_nvgprs
708 addi r3,r1,STACK_FRAME_OVERHEAD
709 ENABLE_INTS
710 bl .alignment_exception
711 b .ret_from_except
712
713 .align 7
714 .globl program_check_common
715program_check_common:
716 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
717 bl .save_nvgprs
718 addi r3,r1,STACK_FRAME_OVERHEAD
719 ENABLE_INTS
720 bl .program_check_exception
721 b .ret_from_except
722
723 .align 7
724 .globl fp_unavailable_common
725fp_unavailable_common:
726 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100727 bne 1f /* if from user, just load it up */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000728 bl .save_nvgprs
729 addi r3,r1,STACK_FRAME_OVERHEAD
730 ENABLE_INTS
731 bl .kernel_fp_unavailable_exception
732 BUG_OPCODE
Michael Neuling6f3d8e62008-06-25 14:07:18 +10007331: bl .load_up_fpu
734 b fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000735
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000736 .align 7
737 .globl altivec_unavailable_common
738altivec_unavailable_common:
739 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
740#ifdef CONFIG_ALTIVEC
741BEGIN_FTR_SECTION
Michael Neuling6f3d8e62008-06-25 14:07:18 +1000742 beq 1f
743 bl .load_up_altivec
744 b fast_exception_return
7451:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000746END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
747#endif
748 bl .save_nvgprs
749 addi r3,r1,STACK_FRAME_OVERHEAD
750 ENABLE_INTS
751 bl .altivec_unavailable_exception
752 b .ret_from_except
753
Paul Mackerras9a955162008-08-30 11:39:26 +1000754 .align 7
755 .globl vsx_unavailable_common
756vsx_unavailable_common:
757 EXCEPTION_PROLOG_COMMON(0xf40, PACA_EXGEN)
758#ifdef CONFIG_VSX
759BEGIN_FTR_SECTION
760 bne .load_up_vsx
7611:
762END_FTR_SECTION_IFSET(CPU_FTR_VSX)
763#endif
764 bl .save_nvgprs
765 addi r3,r1,STACK_FRAME_OVERHEAD
766 ENABLE_INTS
767 bl .vsx_unavailable_exception
768 b .ret_from_except
769
770 .align 7
771 .globl __end_handlers
772__end_handlers:
773
774/*
775 * Return from an exception with minimal checks.
776 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
777 * If interrupts have been enabled, or anything has been
778 * done that might have changed the scheduling status of
779 * any task or sent any task a signal, you should use
780 * ret_from_except or ret_from_except_lite instead of this.
781 */
782fast_exc_return_irq: /* restores irq state too */
783 ld r3,SOFTE(r1)
784 TRACE_AND_RESTORE_IRQ(r3);
785 ld r12,_MSR(r1)
786 rldicl r4,r12,49,63 /* get MSR_EE to LSB */
787 stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
788 b 1f
789
790 .globl fast_exception_return
791fast_exception_return:
792 ld r12,_MSR(r1)
7931: ld r11,_NIP(r1)
794 andi. r3,r12,MSR_RI /* check if RI is set */
795 beq- unrecov_fer
796
797#ifdef CONFIG_VIRT_CPU_ACCOUNTING
798 andi. r3,r12,MSR_PR
799 beq 2f
800 ACCOUNT_CPU_USER_EXIT(r3, r4)
8012:
802#endif
803
804 ld r3,_CCR(r1)
805 ld r4,_LINK(r1)
806 ld r5,_CTR(r1)
807 ld r6,_XER(r1)
808 mtcr r3
809 mtlr r4
810 mtctr r5
811 mtxer r6
812 REST_GPR(0, r1)
813 REST_8GPRS(2, r1)
814
815 mfmsr r10
816 rldicl r10,r10,48,1 /* clear EE */
817 rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
818 mtmsrd r10,1
819
820 mtspr SPRN_SRR1,r12
821 mtspr SPRN_SRR0,r11
822 REST_4GPRS(10, r1)
823 ld r1,GPR1(r1)
824 rfid
825 b . /* prevent speculative execution */
826
827unrecov_fer:
828 bl .save_nvgprs
8291: addi r3,r1,STACK_FRAME_OVERHEAD
830 bl .unrecoverable_exception
831 b 1b
832
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000833#ifdef CONFIG_ALTIVEC
834/*
835 * load_up_altivec(unused, unused, tsk)
836 * Disable VMX for the task which had it previously,
837 * and save its vector registers in its thread_struct.
838 * Enables the VMX for use in the kernel on return.
839 * On SMP we know the VMX is free, since we give it up every
840 * switch (ie, no lazy save of the vector registers).
841 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
842 */
843_STATIC(load_up_altivec)
844 mfmsr r5 /* grab the current MSR */
845 oris r5,r5,MSR_VEC@h
846 mtmsrd r5 /* enable use of VMX now */
847 isync
848
849/*
850 * For SMP, we don't do lazy VMX switching because it just gets too
851 * horrendously complex, especially when a task switches from one CPU
852 * to another. Instead we call giveup_altvec in switch_to.
853 * VRSAVE isn't dealt with here, that is done in the normal context
854 * switch code. Note that we could rely on vrsave value to eventually
855 * avoid saving all of the VREGs here...
856 */
857#ifndef CONFIG_SMP
858 ld r3,last_task_used_altivec@got(r2)
859 ld r4,0(r3)
860 cmpdi 0,r4,0
861 beq 1f
862 /* Save VMX state to last_task_used_altivec's THREAD struct */
863 addi r4,r4,THREAD
864 SAVE_32VRS(0,r5,r4)
865 mfvscr vr0
866 li r10,THREAD_VSCR
867 stvx vr0,r10,r4
868 /* Disable VMX for last_task_used_altivec */
869 ld r5,PT_REGS(r4)
870 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
871 lis r6,MSR_VEC@h
872 andc r4,r4,r6
873 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
8741:
875#endif /* CONFIG_SMP */
876 /* Hack: if we get an altivec unavailable trap with VRSAVE
877 * set to all zeros, we assume this is a broken application
878 * that fails to set it properly, and thus we switch it to
879 * all 1's
880 */
881 mfspr r4,SPRN_VRSAVE
882 cmpdi 0,r4,0
883 bne+ 1f
884 li r4,-1
885 mtspr SPRN_VRSAVE,r4
8861:
887 /* enable use of VMX after return */
888 ld r4,PACACURRENT(r13)
889 addi r5,r4,THREAD /* Get THREAD */
890 oris r12,r12,MSR_VEC@h
891 std r12,_MSR(r1)
892 li r4,1
893 li r10,THREAD_VSCR
894 stw r4,THREAD_USED_VR(r5)
895 lvx vr0,r10,r5
896 mtvscr vr0
897 REST_32VRS(0,r4,r5)
898#ifndef CONFIG_SMP
899 /* Update last_task_used_math to 'current' */
900 subi r4,r5,THREAD /* Back to 'current' */
901 std r4,0(r3)
902#endif /* CONFIG_SMP */
903 /* restore registers and return */
Michael Neuling6f3d8e62008-06-25 14:07:18 +1000904 blr
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000905#endif /* CONFIG_ALTIVEC */
906
Michael Neulingce48b212008-06-25 14:07:18 +1000907#ifdef CONFIG_VSX
908/*
909 * load_up_vsx(unused, unused, tsk)
910 * Disable VSX for the task which had it previously,
911 * and save its vector registers in its thread_struct.
912 * Reuse the fp and vsx saves, but first check to see if they have
913 * been saved already.
914 * On entry: r13 == 'current' && last_task_used_vsx != 'current'
915 */
916_STATIC(load_up_vsx)
917/* Load FP and VSX registers if they haven't been done yet */
918 andi. r5,r12,MSR_FP
919 beql+ load_up_fpu /* skip if already loaded */
920 andis. r5,r12,MSR_VEC@h
921 beql+ load_up_altivec /* skip if already loaded */
922
923#ifndef CONFIG_SMP
924 ld r3,last_task_used_vsx@got(r2)
925 ld r4,0(r3)
926 cmpdi 0,r4,0
927 beq 1f
928 /* Disable VSX for last_task_used_vsx */
929 addi r4,r4,THREAD
930 ld r5,PT_REGS(r4)
931 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
932 lis r6,MSR_VSX@h
933 andc r6,r4,r6
934 std r6,_MSR-STACK_FRAME_OVERHEAD(r5)
9351:
936#endif /* CONFIG_SMP */
937 ld r4,PACACURRENT(r13)
938 addi r4,r4,THREAD /* Get THREAD */
939 li r6,1
940 stw r6,THREAD_USED_VSR(r4) /* ... also set thread used vsr */
941 /* enable use of VSX after return */
942 oris r12,r12,MSR_VSX@h
943 std r12,_MSR(r1)
944#ifndef CONFIG_SMP
945 /* Update last_task_used_math to 'current' */
946 ld r4,PACACURRENT(r13)
947 std r4,0(r3)
948#endif /* CONFIG_SMP */
949 b fast_exception_return
950#endif /* CONFIG_VSX */
951
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000952/*
953 * Hash table stuff
954 */
955 .align 7
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000956_STATIC(do_hash_page)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000957 std r3,_DAR(r1)
958 std r4,_DSISR(r1)
959
960 andis. r0,r4,0xa450 /* weird error? */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100961 bne- handle_page_fault /* if not, try to insert a HPTE */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000962BEGIN_FTR_SECTION
963 andis. r0,r4,0x0020 /* Is it a segment table fault? */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100964 bne- do_ste_alloc /* If so handle it */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000965END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
966
967 /*
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000968 * On iSeries, we soft-disable interrupts here, then
969 * hard-enable interrupts so that the hash_page code can spin on
970 * the hash_table_lock without problems on a shared processor.
971 */
972 DISABLE_INTS
973
974 /*
975 * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
976 * and will clobber volatile registers when irq tracing is enabled
977 * so we need to reload them. It may be possible to be smarter here
978 * and move the irq tracing elsewhere but let's keep it simple for
979 * now
980 */
981#ifdef CONFIG_TRACE_IRQFLAGS
982 ld r3,_DAR(r1)
983 ld r4,_DSISR(r1)
984 ld r5,_TRAP(r1)
985 ld r12,_MSR(r1)
986 clrrdi r5,r5,4
987#endif /* CONFIG_TRACE_IRQFLAGS */
988 /*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000989 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
990 * accessing a userspace segment (even from the kernel). We assume
991 * kernel addresses always have the high bit set.
992 */
993 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
994 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
995 orc r0,r12,r0 /* MSR_PR | ~high_bit */
996 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
997 ori r4,r4,1 /* add _PAGE_PRESENT */
998 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
999
1000 /*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001001 * r3 contains the faulting address
1002 * r4 contains the required access permissions
1003 * r5 contains the trap number
1004 *
1005 * at return r3 = 0 for success
1006 */
1007 bl .hash_page /* build HPTE if possible */
1008 cmpdi r3,0 /* see if hash_page succeeded */
1009
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001010BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001011 /*
1012 * If we had interrupts soft-enabled at the point where the
1013 * DSI/ISI occurred, and an interrupt came in during hash_page,
1014 * handle it now.
1015 * We jump to ret_from_except_lite rather than fast_exception_return
1016 * because ret_from_except_lite will check for and handle pending
1017 * interrupts if necessary.
1018 */
Paul Mackerras3ccfc652006-11-02 09:44:37 +11001019 beq 13f
Paul Mackerrasb0a779d2006-10-18 10:11:22 +10001020END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +10001021
Paul Mackerrasb0a779d2006-10-18 10:11:22 +10001022BEGIN_FW_FTR_SECTION
1023 /*
1024 * Here we have interrupts hard-disabled, so it is sufficient
1025 * to restore paca->{soft,hard}_enable and get out.
1026 */
1027 beq fast_exc_return_irq /* Return from exception on success */
1028END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1029
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001030 /* For a hash failure, we don't bother re-enabling interrupts */
1031 ble- 12f
1032
1033 /*
1034 * hash_page couldn't handle it, set soft interrupt enable back
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +10001035 * to what it was before the trap. Note that .raw_local_irq_restore
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001036 * handles any interrupts pending at this point.
1037 */
1038 ld r3,SOFTE(r1)
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +10001039 TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
1040 bl .raw_local_irq_restore
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001041 b 11f
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001042
1043/* Here we have a page fault that hash_page can't handle. */
Paul Mackerras3ccfc652006-11-02 09:44:37 +11001044handle_page_fault:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001045 ENABLE_INTS
104611: ld r4,_DAR(r1)
1047 ld r5,_DSISR(r1)
1048 addi r3,r1,STACK_FRAME_OVERHEAD
1049 bl .do_page_fault
1050 cmpdi r3,0
Paul Mackerras3ccfc652006-11-02 09:44:37 +11001051 beq+ 13f
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001052 bl .save_nvgprs
1053 mr r5,r3
1054 addi r3,r1,STACK_FRAME_OVERHEAD
1055 lwz r4,_DAR(r1)
1056 bl .bad_page_fault
1057 b .ret_from_except
1058
Paul Mackerras79acbb32006-12-04 15:59:07 +1100105913: b .ret_from_except_lite
1060
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001061/* We have a page fault that hash_page could handle but HV refused
1062 * the PTE insertion
1063 */
106412: bl .save_nvgprs
Paul Mackerrasfa282372008-01-24 08:35:13 +11001065 mr r5,r3
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001066 addi r3,r1,STACK_FRAME_OVERHEAD
Benjamin Herrenschmidta792e752007-11-07 17:17:02 +11001067 ld r4,_DAR(r1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001068 bl .low_hash_fault
1069 b .ret_from_except
1070
1071 /* here we have a segment miss */
Paul Mackerras3ccfc652006-11-02 09:44:37 +11001072do_ste_alloc:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001073 bl .ste_allocate /* try to insert stab entry */
1074 cmpdi r3,0
Paul Mackerras3ccfc652006-11-02 09:44:37 +11001075 bne- handle_page_fault
1076 b fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001077
1078/*
1079 * r13 points to the PACA, r9 contains the saved CR,
1080 * r11 and r12 contain the saved SRR0 and SRR1.
1081 * r9 - r13 are saved in paca->exslb.
1082 * We assume we aren't going to take any exceptions during this procedure.
1083 * We assume (DAR >> 60) == 0xc.
1084 */
1085 .align 7
1086_GLOBAL(do_stab_bolted)
1087 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1088 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1089
1090 /* Hash to the primary group */
1091 ld r10,PACASTABVIRT(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001092 mfspr r11,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001093 srdi r11,r11,28
1094 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1095
1096 /* Calculate VSID */
1097 /* This is a kernel address, so protovsid = ESID */
Paul Mackerras1189be62007-10-11 20:37:10 +10001098 ASM_VSID_SCRAMBLE(r11, r9, 256M)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001099 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1100
1101 /* Search the primary group for a free entry */
11021: ld r11,0(r10) /* Test valid bit of the current ste */
1103 andi. r11,r11,0x80
1104 beq 2f
1105 addi r10,r10,16
1106 andi. r11,r10,0x70
1107 bne 1b
1108
1109 /* Stick for only searching the primary group for now. */
1110 /* At least for now, we use a very simple random castout scheme */
1111 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1112 mftb r11
1113 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1114 ori r11,r11,0x10
1115
1116 /* r10 currently points to an ste one past the group of interest */
1117 /* make it point to the randomly selected entry */
1118 subi r10,r10,128
1119 or r10,r10,r11 /* r10 is the entry to invalidate */
1120
1121 isync /* mark the entry invalid */
1122 ld r11,0(r10)
1123 rldicl r11,r11,56,1 /* clear the valid bit */
1124 rotldi r11,r11,8
1125 std r11,0(r10)
1126 sync
1127
1128 clrrdi r11,r11,28 /* Get the esid part of the ste */
1129 slbie r11
1130
11312: std r9,8(r10) /* Store the vsid part of the ste */
1132 eieio
1133
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001134 mfspr r11,SPRN_DAR /* Get the new esid */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001135 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1136 ori r11,r11,0x90 /* Turn on valid and kp */
1137 std r11,0(r10) /* Put new entry back into the stab */
1138
1139 sync
1140
1141 /* All done -- return from exception. */
1142 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1143 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1144
1145 andi. r10,r12,MSR_RI
1146 beq- unrecov_slb
1147
1148 mtcrf 0x80,r9 /* restore CR */
1149
1150 mfmsr r10
1151 clrrdi r10,r10,2
1152 mtmsrd r10,1
1153
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001154 mtspr SPRN_SRR0,r11
1155 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001156 ld r9,PACA_EXSLB+EX_R9(r13)
1157 ld r10,PACA_EXSLB+EX_R10(r13)
1158 ld r11,PACA_EXSLB+EX_R11(r13)
1159 ld r12,PACA_EXSLB+EX_R12(r13)
1160 ld r13,PACA_EXSLB+EX_R13(r13)
1161 rfid
1162 b . /* prevent speculative execution */
1163
1164/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001165 * Space for CPU0's segment table.
1166 *
1167 * On iSeries, the hypervisor must fill in at least one entry before
Stephen Rothwell16a15a32007-08-20 14:58:36 +10001168 * we get control (with relocate on). The address is given to the hv
1169 * as a page number (see xLparMap below), so this must be at a
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001170 * fixed address (the linker can't compute (u64)&initial_stab >>
1171 * PAGE_SHIFT).
1172 */
Michael Ellerman758438a2005-12-05 15:49:00 -06001173 . = STAB0_OFFSET /* 0x6000 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001174 .globl initial_stab
1175initial_stab:
1176 .space 4096
1177
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001178#ifdef CONFIG_PPC_PSERIES
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001179/*
1180 * Data area reserved for FWNMI option.
1181 * This address (0x7000) is fixed by the RPA.
1182 */
1183 .= 0x7000
1184 .globl fwnmi_data_area
1185fwnmi_data_area:
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001186#endif /* CONFIG_PPC_PSERIES */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001187
1188 /* iSeries does not use the FWNMI stuff, so it is safe to put
1189 * this here, even if we later allow kernels that will boot on
1190 * both pSeries and iSeries */
1191#ifdef CONFIG_PPC_ISERIES
1192 . = LPARMAP_PHYS
Stephen Rothwell16a15a32007-08-20 14:58:36 +10001193 .globl xLparMap
1194xLparMap:
1195 .quad HvEsidsToMap /* xNumberEsids */
1196 .quad HvRangesToMap /* xNumberRanges */
1197 .quad STAB0_PAGE /* xSegmentTableOffs */
1198 .zero 40 /* xRsvd */
1199 /* xEsids (HvEsidsToMap entries of 2 quads) */
1200 .quad PAGE_OFFSET_ESID /* xKernelEsid */
1201 .quad PAGE_OFFSET_VSID /* xKernelVsid */
1202 .quad VMALLOC_START_ESID /* xKernelEsid */
1203 .quad VMALLOC_START_VSID /* xKernelVsid */
1204 /* xRanges (HvRangesToMap entries of 3 quads) */
1205 .quad HvPagesToMap /* xPages */
1206 .quad 0 /* xOffset */
1207 .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
1208
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001209#endif /* CONFIG_PPC_ISERIES */
1210
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001211#ifdef CONFIG_PPC_PSERIES
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001212 . = 0x8000
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001213#endif /* CONFIG_PPC_PSERIES */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001214
1215/*
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001216 * On pSeries and most other platforms, secondary processors spin
1217 * in the following code.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001218 * At entry, r3 = this processor's number (physical cpu id)
1219 */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001220_GLOBAL(generic_secondary_smp_init)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001221 mr r24,r3
1222
1223 /* turn on 64-bit mode */
1224 bl .enable_64b_mode
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001225
Paul Mackerrase31aa452008-08-30 11:41:12 +10001226 /* get the TOC pointer (real address) */
1227 bl .relative_toc
1228
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001229 /* Set up a paca value for this processor. Since we have the
1230 * physical cpu id in r24, we need to search the pacas to find
1231 * which logical id maps to our physical one.
1232 */
Paul Mackerrase31aa452008-08-30 11:41:12 +10001233 LOAD_REG_ADDR(r13, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001234 li r5,0 /* logical cpu id */
12351: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1236 cmpw r6,r24 /* Compare to our id */
1237 beq 2f
1238 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1239 addi r5,r5,1
1240 cmpwi r5,NR_CPUS
1241 blt 1b
1242
1243 mr r3,r24 /* not found, copy phys to r3 */
1244 b .kexec_wait /* next kernel might do better */
1245
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100012462: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001247 /* From now on, r24 is expected to be logical cpuid */
1248 mr r24,r5
12493: HMT_LOW
1250 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1251 /* start. */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001252
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001253#ifndef CONFIG_SMP
1254 b 3b /* Never go on non-SMP */
1255#else
1256 cmpwi 0,r23,0
1257 beq 3b /* Loop until told to go */
1258
Sonny Raob6f6b982008-07-12 09:00:26 +10001259 sync /* order paca.run and cur_cpu_spec */
1260
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001261 /* See if we need to call a cpu state restore handler */
Paul Mackerrase31aa452008-08-30 11:41:12 +10001262 LOAD_REG_ADDR(r23, cur_cpu_spec)
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001263 ld r23,0(r23)
1264 ld r23,CPU_SPEC_RESTORE(r23)
1265 cmpdi 0,r23,0
1266 beq 4f
1267 ld r23,0(r23)
1268 mtctr r23
1269 bctrl
1270
12714: /* Create a temp kernel stack for use before relocation is on. */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001272 ld r1,PACAEMERGSP(r13)
1273 subi r1,r1,STACK_FRAME_OVERHEAD
1274
Stephen Rothwellc7056772006-11-27 14:59:50 +11001275 b __secondary_start
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001276#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001277
Paul Mackerrase31aa452008-08-30 11:41:12 +10001278/*
1279 * Turn the MMU off.
1280 * Assumes we're mapped EA == RA if the MMU is on.
1281 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001282_STATIC(__mmu_off)
1283 mfmsr r3
1284 andi. r0,r3,MSR_IR|MSR_DR
1285 beqlr
Paul Mackerrase31aa452008-08-30 11:41:12 +10001286 mflr r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001287 andc r3,r3,r0
1288 mtspr SPRN_SRR0,r4
1289 mtspr SPRN_SRR1,r3
1290 sync
1291 rfid
1292 b . /* prevent speculative execution */
1293
1294
1295/*
1296 * Here is our main kernel entry point. We support currently 2 kind of entries
1297 * depending on the value of r5.
1298 *
1299 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1300 * in r3...r7
1301 *
1302 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1303 * DT block, r4 is a physical pointer to the kernel itself
1304 *
1305 */
1306_GLOBAL(__start_initialization_multiplatform)
Paul Mackerrase31aa452008-08-30 11:41:12 +10001307 /* Make sure we are running in 64 bits mode */
1308 bl .enable_64b_mode
1309
1310 /* Get TOC pointer (current runtime address) */
1311 bl .relative_toc
1312
1313 /* find out where we are now */
1314 bcl 20,31,$+4
13150: mflr r26 /* r26 = runtime addr here */
1316 addis r26,r26,(_stext - 0b)@ha
1317 addi r26,r26,(_stext - 0b)@l /* current runtime base addr */
1318
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001319 /*
1320 * Are we booted from a PROM Of-type client-interface ?
1321 */
1322 cmpldi cr0,r5,0
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001323 beq 1f
1324 b .__boot_from_prom /* yes -> prom */
13251:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001326 /* Save parameters */
1327 mr r31,r3
1328 mr r30,r4
1329
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001330 /* Setup some critical 970 SPRs before switching MMU off */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001331 mfspr r0,SPRN_PVR
1332 srwi r0,r0,16
1333 cmpwi r0,0x39 /* 970 */
1334 beq 1f
1335 cmpwi r0,0x3c /* 970FX */
1336 beq 1f
1337 cmpwi r0,0x44 /* 970MP */
Olof Johansson190a24f2006-10-25 17:32:40 -05001338 beq 1f
1339 cmpwi r0,0x45 /* 970GX */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001340 bne 2f
13411: bl .__cpu_preinit_ppc970
13422:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001343
Paul Mackerrase31aa452008-08-30 11:41:12 +10001344 /* Switch off MMU if not already off */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001345 bl .__mmu_off
1346 b .__after_prom_start
1347
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001348_INIT_STATIC(__boot_from_prom)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001349 /* Save parameters */
1350 mr r31,r3
1351 mr r30,r4
1352 mr r29,r5
1353 mr r28,r6
1354 mr r27,r7
1355
Olaf Hering60888572006-03-23 21:50:59 +01001356 /*
1357 * Align the stack to 16-byte boundary
1358 * Depending on the size and layout of the ELF sections in the initial
Paul Mackerrase31aa452008-08-30 11:41:12 +10001359 * boot binary, the stack pointer may be unaligned on PowerMac
Olaf Hering60888572006-03-23 21:50:59 +01001360 */
Linus Torvaldsc05b4772006-03-04 15:00:45 -08001361 rldicr r1,r1,0,59
1362
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001363 /* Restore parameters */
1364 mr r3,r31
1365 mr r4,r30
1366 mr r5,r29
1367 mr r6,r28
1368 mr r7,r27
1369
1370 /* Do all of the interaction with OF client interface */
1371 bl .prom_init
1372 /* We never return */
1373 trap
1374
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001375_STATIC(__after_prom_start)
1376
1377/*
Paul Mackerrase31aa452008-08-30 11:41:12 +10001378 * We need to run with _stext at physical address PHYSICAL_START.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001379 * This will leave some code in the first 256B of
1380 * real memory, which are reserved for software use.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001381 *
1382 * Note: This process overwrites the OF exception vectors.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001383 */
David Gibsone58c3492006-01-13 14:56:25 +11001384 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
Paul Mackerrase31aa452008-08-30 11:41:12 +10001385 cmpd r3,r26 /* In some cases the loader may */
1386 beq 9f /* have already put us at zero */
1387 mr r4,r26 /* source address */
1388 lis r5,(copy_to_here - _stext)@ha
1389 addi r5,r5,(copy_to_here - _stext)@l /* # bytes of memory to copy */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001390 li r6,0x100 /* Start offset, the first 0x100 */
1391 /* bytes were copied earlier. */
1392
1393 bl .copy_and_flush /* copy the first n bytes */
1394 /* this includes the code being */
1395 /* executed here. */
Paul Mackerrase31aa452008-08-30 11:41:12 +10001396 addis r8,r3,(4f - _stext)@ha /* Jump to the copy of this code */
1397 addi r8,r8,(4f - _stext)@l /* that we just made */
1398 mtctr r8
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001399 bctr
1400
Paul Mackerrase31aa452008-08-30 11:41:12 +100014014: /* Now copy the rest of the kernel up to _end */
1402 addis r5,r26,(p_end - _stext)@ha
1403 ld r5,(p_end - _stext)@l(r5) /* get _end */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001404 bl .copy_and_flush /* copy the rest */
Paul Mackerrase31aa452008-08-30 11:41:12 +10001405
14069: b .start_here_multiplatform
1407
1408p_end: .llong _end - _stext
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001409
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001410/*
1411 * Copy routine used to copy the kernel to start at physical address 0
1412 * and flush and invalidate the caches as needed.
1413 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1414 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1415 *
1416 * Note: this routine *only* clobbers r0, r6 and lr
1417 */
1418_GLOBAL(copy_and_flush)
1419 addi r5,r5,-8
1420 addi r6,r6,-8
Olof Johansson5a2fe382006-09-06 14:34:41 -050014214: li r0,8 /* Use the smallest common */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001422 /* denominator cache line */
1423 /* size. This results in */
1424 /* extra cache line flushes */
1425 /* but operation is correct. */
1426 /* Can't get cache line size */
1427 /* from NACA as it is being */
1428 /* moved too. */
1429
1430 mtctr r0 /* put # words/line in ctr */
14313: addi r6,r6,8 /* copy a cache line */
1432 ldx r0,r6,r4
1433 stdx r0,r6,r3
1434 bdnz 3b
1435 dcbst r6,r3 /* write it to memory */
1436 sync
1437 icbi r6,r3 /* flush the icache line */
1438 cmpld 0,r6,r5
1439 blt 4b
1440 sync
1441 addi r5,r5,8
1442 addi r6,r6,8
1443 blr
1444
1445.align 8
1446copy_to_here:
1447
1448#ifdef CONFIG_SMP
1449#ifdef CONFIG_PPC_PMAC
1450/*
1451 * On PowerMac, secondary processors starts from the reset vector, which
1452 * is temporarily turned into a call to one of the functions below.
1453 */
1454 .section ".text";
1455 .align 2 ;
1456
Paul Mackerras35499c02005-10-22 16:02:39 +10001457 .globl __secondary_start_pmac_0
1458__secondary_start_pmac_0:
1459 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1460 li r24,0
1461 b 1f
1462 li r24,1
1463 b 1f
1464 li r24,2
1465 b 1f
1466 li r24,3
14671:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001468
1469_GLOBAL(pmac_secondary_start)
1470 /* turn on 64-bit mode */
1471 bl .enable_64b_mode
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001472
Paul Mackerrase31aa452008-08-30 11:41:12 +10001473 /* get TOC pointer (real address) */
1474 bl .relative_toc
1475
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001476 /* Copy some CPU settings from CPU 0 */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001477 bl .__restore_cpu_ppc970
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001478
1479 /* pSeries do that early though I don't think we really need it */
1480 mfmsr r3
1481 ori r3,r3,MSR_RI
1482 mtmsrd r3 /* RI on */
1483
1484 /* Set up a paca value for this processor. */
Paul Mackerrase31aa452008-08-30 11:41:12 +10001485 LOAD_REG_ADDR(r4,paca) /* Get base vaddr of paca array */
1486 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001487 add r13,r13,r4 /* for this processor. */
Paul Mackerrase31aa452008-08-30 11:41:12 +10001488 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001489
1490 /* Create a temp kernel stack for use before relocation is on. */
1491 ld r1,PACAEMERGSP(r13)
1492 subi r1,r1,STACK_FRAME_OVERHEAD
1493
Stephen Rothwellc7056772006-11-27 14:59:50 +11001494 b __secondary_start
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001495
1496#endif /* CONFIG_PPC_PMAC */
1497
1498/*
1499 * This function is called after the master CPU has released the
1500 * secondary processors. The execution environment is relocation off.
1501 * The paca for this processor has the following fields initialized at
1502 * this point:
1503 * 1. Processor number
1504 * 2. Segment table pointer (virtual address)
1505 * On entry the following are set:
1506 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1507 * r24 = cpu# (in Linux terms)
1508 * r13 = paca virtual address
1509 * SPRG3 = paca virtual address
1510 */
Stephen Rothwellfc68e862007-08-22 13:44:58 +10001511 .globl __secondary_start
Stephen Rothwellc7056772006-11-27 14:59:50 +11001512__secondary_start:
Paul Mackerras799d6042005-11-10 13:37:51 +11001513 /* Set thread priority to MEDIUM */
1514 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001515
Paul Mackerras799d6042005-11-10 13:37:51 +11001516 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1517 bl .early_setup_secondary
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001518
1519 /* Initialize the kernel stack. Just a repeat for iSeries. */
David Gibsone58c3492006-01-13 14:56:25 +11001520 LOAD_REG_ADDR(r3, current_set)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001521 sldi r28,r24,3 /* get current_set[cpu#] */
1522 ldx r1,r3,r28
1523 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1524 std r1,PACAKSAVE(r13)
1525
Paul Mackerras799d6042005-11-10 13:37:51 +11001526 /* Clear backchain so we get nice backtraces */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001527 li r7,0
1528 mtlr r7
1529
1530 /* enable MMU and jump to start_secondary */
David Gibsone58c3492006-01-13 14:56:25 +11001531 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1532 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001533#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001534BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001535 ori r4,r4,MSR_EE
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001536 li r8,1
1537 stb r8,PACAHARDIRQEN(r13)
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001538END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001539#endif
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001540BEGIN_FW_FTR_SECTION
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001541 stb r7,PACAHARDIRQEN(r13)
1542END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001543 stb r7,PACASOFTIRQEN(r13)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001544
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001545 mtspr SPRN_SRR0,r3
1546 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001547 rfid
1548 b . /* prevent speculative execution */
1549
1550/*
1551 * Running with relocation on at this point. All we want to do is
Paul Mackerrase31aa452008-08-30 11:41:12 +10001552 * zero the stack back-chain pointer and get the TOC virtual address
1553 * before going into C code.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001554 */
1555_GLOBAL(start_secondary_prolog)
Paul Mackerrase31aa452008-08-30 11:41:12 +10001556 ld r2,PACATOC(r13)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001557 li r3,0
1558 std r3,0(r1) /* Zero the stack frame pointer */
1559 bl .start_secondary
Paul Mackerras799d6042005-11-10 13:37:51 +11001560 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001561#endif
1562
1563/*
1564 * This subroutine clobbers r11 and r12
1565 */
1566_GLOBAL(enable_64b_mode)
1567 mfmsr r11 /* grab the current MSR */
Paul Mackerrase31aa452008-08-30 11:41:12 +10001568 li r12,(MSR_SF | MSR_ISF)@highest
1569 sldi r12,r12,48
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001570 or r11,r11,r12
1571 mtmsrd r11
1572 isync
1573 blr
1574
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001575/*
Paul Mackerrase31aa452008-08-30 11:41:12 +10001576 * This puts the TOC pointer into r2, offset by 0x8000 (as expected
1577 * by the toolchain). It computes the correct value for wherever we
1578 * are running at the moment, using position-independent code.
1579 */
1580_GLOBAL(relative_toc)
1581 mflr r0
1582 bcl 20,31,$+4
15830: mflr r9
1584 ld r2,(p_toc - 0b)(r9)
1585 add r2,r2,r9
1586 mtlr r0
1587 blr
1588
1589p_toc: .llong __toc_start + 0x8000 - 0b
1590
1591/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001592 * This is where the main kernel code starts.
1593 */
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001594_INIT_STATIC(start_here_multiplatform)
Paul Mackerrase31aa452008-08-30 11:41:12 +10001595 /* set up the TOC (real address) */
1596 bl .relative_toc
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001597
1598 /* Clear out the BSS. It may have been done in prom_init,
1599 * already but that's irrelevant since prom_init will soon
1600 * be detached from the kernel completely. Besides, we need
1601 * to clear it now for kexec-style entry.
1602 */
Paul Mackerrase31aa452008-08-30 11:41:12 +10001603 LOAD_REG_ADDR(r11,__bss_stop)
1604 LOAD_REG_ADDR(r8,__bss_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001605 sub r11,r11,r8 /* bss size */
1606 addi r11,r11,7 /* round up to an even double word */
Paul Mackerrase31aa452008-08-30 11:41:12 +10001607 srdi. r11,r11,3 /* shift right by 3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001608 beq 4f
1609 addi r8,r8,-8
1610 li r0,0
1611 mtctr r11 /* zero this many doublewords */
16123: stdu r0,8(r8)
1613 bdnz 3b
16144:
1615
1616 mfmsr r6
1617 ori r6,r6,MSR_RI
1618 mtmsrd r6 /* RI on */
1619
Paul Mackerrase31aa452008-08-30 11:41:12 +10001620 /* The following gets the stack set up with the regs */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001621 /* pointing to the real addr of the kernel stack. This is */
1622 /* all done to support the C function call below which sets */
1623 /* up the htab. This is done because we have relocated the */
1624 /* kernel but are still running in real mode. */
1625
Paul Mackerrase31aa452008-08-30 11:41:12 +10001626 LOAD_REG_ADDR(r3,init_thread_union)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001627
Paul Mackerrase31aa452008-08-30 11:41:12 +10001628 /* set up a stack pointer */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001629 addi r1,r3,THREAD_SIZE
1630 li r0,0
1631 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1632
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001633 /* Do very early kernel initializations, including initial hash table,
1634 * stab and slb setup before we turn on relocation. */
1635
1636 /* Restore parameters passed from prom_init/kexec */
1637 mr r3,r31
Paul Mackerrase31aa452008-08-30 11:41:12 +10001638 bl .early_setup /* also sets r13 and SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001639
Paul Mackerrase31aa452008-08-30 11:41:12 +10001640 LOAD_REG_ADDR(r3, .start_here_common)
1641 ld r4,PACAKMSR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001642 mtspr SPRN_SRR0,r3
1643 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001644 rfid
1645 b . /* prevent speculative execution */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001646
1647 /* This is where all platforms converge execution */
Stephen Rothwellfc68e862007-08-22 13:44:58 +10001648_INIT_GLOBAL(start_here_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001649 /* relocation is on at this point */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001650 std r1,PACAKSAVE(r13)
1651
Paul Mackerrase31aa452008-08-30 11:41:12 +10001652 /* Load the TOC (virtual address) */
1653 ld r2,PACATOC(r13)
1654
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001655 bl .setup_system
1656
1657 /* Load up the kernel context */
16585:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001659 li r5,0
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001660 stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
1661#ifdef CONFIG_PPC_ISERIES
1662BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001663 mfmsr r5
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001664 ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001665 mtmsrd r5
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001666 li r5,1
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001667END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001668#endif
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001669 stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001670
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001671 bl .start_kernel
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001672
Anton Blanchardf1870f72006-02-13 18:11:13 +11001673 /* Not reached */
1674 BUG_OPCODE
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001675
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001676/*
1677 * We put a few things here that have to be page-aligned.
1678 * This stuff goes at the beginning of the bss, which is page-aligned.
1679 */
1680 .section ".bss"
1681
1682 .align PAGE_SHIFT
1683
1684 .globl empty_zero_page
1685empty_zero_page:
1686 .space PAGE_SIZE
1687
1688 .globl swapper_pg_dir
1689swapper_pg_dir:
Stephen Rothwellee7a76d2007-09-18 17:22:59 +10001690 .space PGD_TABLE_SIZE