blob: 215973a2c8d5971fd8431505d1c58b62a4bd5bf7 [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 Mackerras14cf11a2005-09-26 16:04:21 +100085 /* Secondary processors spin on this value until it goes to 1. */
86 .globl __secondary_hold_spinloop
87__secondary_hold_spinloop:
88 .llong 0x0
89
90 /* Secondary processors write this value with their cpu # */
91 /* after they enter the spin loop immediately below. */
92 .globl __secondary_hold_acknowledge
93__secondary_hold_acknowledge:
94 .llong 0x0
95
Michael Ellerman1dce0e302006-06-23 18:15:37 +100096#ifdef CONFIG_PPC_ISERIES
97 /*
98 * At offset 0x20, there is a pointer to iSeries LPAR data.
99 * This is required by the hypervisor
100 */
101 . = 0x20
102 .llong hvReleaseData-KERNELBASE
103#endif /* CONFIG_PPC_ISERIES */
104
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000105 . = 0x60
106/*
Geoff Levand75423b72007-06-16 08:06:23 +1000107 * The following code is used to hold secondary processors
108 * in a spin loop after they have entered the kernel, but
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000109 * before the bulk of the kernel has been relocated. This code
110 * is relocated to physical address 0x60 before prom_init is run.
111 * All of it must fit below the first exception vector at 0x100.
112 */
113_GLOBAL(__secondary_hold)
114 mfmsr r24
115 ori r24,r24,MSR_RI
116 mtmsrd r24 /* RI on */
117
Anton Blanchardf1870f72006-02-13 18:11:13 +1100118 /* Grab our physical cpu number */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000119 mr r24,r3
120
121 /* Tell the master cpu we're here */
122 /* Relocation is off & we are located at an address less */
123 /* than 0x100, so only need to grab low order offset. */
124 std r24,__secondary_hold_acknowledge@l(0)
125 sync
126
127 /* All secondary cpus wait here until told to start. */
128100: ld r4,__secondary_hold_spinloop@l(0)
129 cmpdi 0,r4,1
130 bne 100b
131
Anton Blanchardf1870f72006-02-13 18:11:13 +1100132#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
Olof Johanssonf39b7a52006-08-11 00:07:08 -0500133 LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
Michael Ellerman758438a2005-12-05 15:49:00 -0600134 mtctr r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000135 mr r3,r24
Michael Ellerman758438a2005-12-05 15:49:00 -0600136 bctr
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000137#else
138 BUG_OPCODE
139#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000140
141/* This value is used to mark exception frames on the stack. */
142 .section ".toc","aw"
143exception_marker:
144 .tc ID_72656773_68657265[TC],0x7265677368657265
145 .text
146
147/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000148 * This is the start of the interrupt handlers for pSeries
149 * This code runs with relocation off.
150 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000151 . = 0x100
152 .globl __start_interrupts
153__start_interrupts:
154
155 STD_EXCEPTION_PSERIES(0x100, system_reset)
156
157 . = 0x200
158_machine_check_pSeries:
159 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000160 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000161 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
162
163 . = 0x300
164 .globl data_access_pSeries
165data_access_pSeries:
166 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000167 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000168BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000169 mtspr SPRN_SPRG2,r12
170 mfspr r13,SPRN_DAR
171 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000172 srdi r13,r13,60
173 rlwimi r13,r12,16,0x20
174 mfcr r12
175 cmpwi r13,0x2c
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100176 beq do_stab_bolted_pSeries
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000177 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000178 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000179END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
180 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
181
182 . = 0x380
183 .globl data_access_slb_pSeries
184data_access_slb_pSeries:
185 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000186 mtspr SPRN_SPRG1,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000187 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100188 std r3,PACA_EXSLB+EX_R3(r13)
189 mfspr r3,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000190 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100191 mfcr r9
192#ifdef __DISABLED__
193 /* Keep that around for when we re-implement dynamic VSIDs */
194 cmpdi r3,0
195 bge slb_miss_user_pseries
196#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000197 std r10,PACA_EXSLB+EX_R10(r13)
198 std r11,PACA_EXSLB+EX_R11(r13)
199 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100200 mfspr r10,SPRN_SPRG1
201 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000202 mfspr r12,SPRN_SRR1 /* and SRR1 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100203 b .slb_miss_realmode /* Rel. branch works in real mode */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000204
205 STD_EXCEPTION_PSERIES(0x400, instruction_access)
206
207 . = 0x480
208 .globl instruction_access_slb_pSeries
209instruction_access_slb_pSeries:
210 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000211 mtspr SPRN_SPRG1,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000212 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100213 std r3,PACA_EXSLB+EX_R3(r13)
214 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000215 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100216 mfcr r9
217#ifdef __DISABLED__
218 /* Keep that around for when we re-implement dynamic VSIDs */
219 cmpdi r3,0
220 bge slb_miss_user_pseries
221#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000222 std r10,PACA_EXSLB+EX_R10(r13)
223 std r11,PACA_EXSLB+EX_R11(r13)
224 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100225 mfspr r10,SPRN_SPRG1
226 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000227 mfspr r12,SPRN_SRR1 /* and SRR1 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100228 b .slb_miss_realmode /* Rel. branch works in real mode */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000229
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000230 MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000231 STD_EXCEPTION_PSERIES(0x600, alignment)
232 STD_EXCEPTION_PSERIES(0x700, program_check)
233 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000234 MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000235 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
236 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
237
238 . = 0xc00
239 .globl system_call_pSeries
240system_call_pSeries:
241 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000242 mr r9,r13
243 mfmsr r10
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000244 mfspr r13,SPRN_SPRG3
245 mfspr r11,SPRN_SRR0
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000246 clrrdi r12,r13,32
247 oris r12,r12,system_call_common@h
248 ori r12,r12,system_call_common@l
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000249 mtspr SPRN_SRR0,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000250 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000251 mfspr r12,SPRN_SRR1
252 mtspr SPRN_SRR1,r10
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000253 rfid
254 b . /* prevent speculative execution */
255
256 STD_EXCEPTION_PSERIES(0xd00, single_step)
257 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
258
259 /* We need to deal with the Altivec unavailable exception
260 * here which is at 0xf20, thus in the middle of the
261 * prolog code of the PerformanceMonitor one. A little
262 * trickery is thus necessary
263 */
264 . = 0xf00
265 b performance_monitor_pSeries
266
267 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
268
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200269#ifdef CONFIG_CBE_RAS
270 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
271#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000272 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200273#ifdef CONFIG_CBE_RAS
274 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
275#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000276 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200277#ifdef CONFIG_CBE_RAS
278 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
279#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000280
281 . = 0x3000
282
283/*** pSeries interrupt support ***/
284
285 /* moved from 0xf00 */
Livio Soares449d8462007-02-07 12:51:36 +1100286 STD_EXCEPTION_PSERIES(., performance_monitor)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000287
288/*
289 * An interrupt came in while soft-disabled; clear EE in SRR1,
290 * clear paca->hard_enabled and return.
291 */
292masked_interrupt:
293 stb r10,PACAHARDIRQEN(r13)
294 mtcrf 0x80,r9
295 ld r9,PACA_EXGEN+EX_R9(r13)
296 mfspr r10,SPRN_SRR1
297 rldicl r10,r10,48,1 /* clear MSR_EE */
298 rotldi r10,r10,16
299 mtspr SPRN_SRR1,r10
300 ld r10,PACA_EXGEN+EX_R10(r13)
301 mfspr r13,SPRN_SPRG1
302 rfid
303 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000304
305 .align 7
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100306do_stab_bolted_pSeries:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000307 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000308 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000309 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
310
311/*
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100312 * We have some room here we use that to put
313 * the peries slb miss user trampoline code so it's reasonably
314 * away from slb_miss_user_common to avoid problems with rfid
315 *
316 * This is used for when the SLB miss handler has to go virtual,
317 * which doesn't happen for now anymore but will once we re-implement
318 * dynamic VSIDs for shared page tables
319 */
320#ifdef __DISABLED__
321slb_miss_user_pseries:
322 std r10,PACA_EXGEN+EX_R10(r13)
323 std r11,PACA_EXGEN+EX_R11(r13)
324 std r12,PACA_EXGEN+EX_R12(r13)
325 mfspr r10,SPRG1
326 ld r11,PACA_EXSLB+EX_R9(r13)
327 ld r12,PACA_EXSLB+EX_R3(r13)
328 std r10,PACA_EXGEN+EX_R13(r13)
329 std r11,PACA_EXGEN+EX_R9(r13)
330 std r12,PACA_EXGEN+EX_R3(r13)
331 clrrdi r12,r13,32
332 mfmsr r10
333 mfspr r11,SRR0 /* save SRR0 */
334 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
335 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
336 mtspr SRR0,r12
337 mfspr r12,SRR1 /* and SRR1 */
338 mtspr SRR1,r10
339 rfid
340 b . /* prevent spec. execution */
341#endif /* __DISABLED__ */
342
Stephen Rothwell9e4859e2007-09-18 17:25:12 +1000343#ifdef CONFIG_PPC_PSERIES
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100344/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000345 * Vectors for the FWNMI option. Share common code.
346 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000347 .globl system_reset_fwnmi
Michael Ellerman8c4f1f22005-12-04 18:39:33 +1100348 .align 7
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000349system_reset_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000350 HMT_MEDIUM
351 mtspr SPRN_SPRG1,r13 /* save r13 */
Olaf Hering9fc0a922006-07-19 10:34:05 +0200352 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000353
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000354 .globl machine_check_fwnmi
Michael Ellerman8c4f1f22005-12-04 18:39:33 +1100355 .align 7
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000356machine_check_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000357 HMT_MEDIUM
358 mtspr SPRN_SPRG1,r13 /* save r13 */
Olaf Hering9fc0a922006-07-19 10:34:05 +0200359 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000360
Stephen Rothwell9e4859e2007-09-18 17:25:12 +1000361#endif /* CONFIG_PPC_PSERIES */
362
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000363/*** Common interrupt handlers ***/
364
365 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
366
367 /*
368 * Machine check is different because we use a different
369 * save area: PACA_EXMC instead of PACA_EXGEN.
370 */
371 .align 7
372 .globl machine_check_common
373machine_check_common:
374 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000375 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000376 DISABLE_INTS
377 bl .save_nvgprs
378 addi r3,r1,STACK_FRAME_OVERHEAD
379 bl .machine_check_exception
380 b .ret_from_except
381
382 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
383 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
384 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
385 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
386 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000387 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000388 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
389#ifdef CONFIG_ALTIVEC
390 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
391#else
392 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
393#endif
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200394#ifdef CONFIG_CBE_RAS
395 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
396 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
397 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
398#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000399
400/*
401 * Here we have detected that the kernel stack pointer is bad.
402 * R9 contains the saved CR, r13 points to the paca,
403 * r10 contains the (bad) kernel stack pointer,
404 * r11 and r12 contain the saved SRR0 and SRR1.
405 * We switch to using an emergency stack, save the registers there,
406 * and call kernel_bad_stack(), which panics.
407 */
408bad_stack:
409 ld r1,PACAEMERGSP(r13)
410 subi r1,r1,64+INT_FRAME_SIZE
411 std r9,_CCR(r1)
412 std r10,GPR1(r1)
413 std r11,_NIP(r1)
414 std r12,_MSR(r1)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000415 mfspr r11,SPRN_DAR
416 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000417 std r11,_DAR(r1)
418 std r12,_DSISR(r1)
419 mflr r10
420 mfctr r11
421 mfxer r12
422 std r10,_LINK(r1)
423 std r11,_CTR(r1)
424 std r12,_XER(r1)
425 SAVE_GPR(0,r1)
426 SAVE_GPR(2,r1)
427 SAVE_4GPRS(3,r1)
428 SAVE_2GPRS(7,r1)
429 SAVE_10GPRS(12,r1)
430 SAVE_10GPRS(22,r1)
Olof Johansson68730402007-04-24 01:11:55 +1000431 lhz r12,PACA_TRAP_SAVE(r13)
432 std r12,_TRAP(r1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000433 addi r11,r1,INT_FRAME_SIZE
434 std r11,0(r1)
435 li r12,0
436 std r12,0(r11)
437 ld r2,PACATOC(r13)
4381: addi r3,r1,STACK_FRAME_OVERHEAD
439 bl .kernel_bad_stack
440 b 1b
441
442/*
443 * Return from an exception with minimal checks.
444 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
445 * If interrupts have been enabled, or anything has been
446 * done that might have changed the scheduling status of
447 * any task or sent any task a signal, you should use
448 * ret_from_except or ret_from_except_lite instead of this.
449 */
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000450fast_exc_return_irq: /* restores irq state too */
451 ld r3,SOFTE(r1)
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000452 TRACE_AND_RESTORE_IRQ(r3);
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000453 ld r12,_MSR(r1)
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000454 rldicl r4,r12,49,63 /* get MSR_EE to LSB */
455 stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
456 b 1f
457
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000458 .globl fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000459fast_exception_return:
460 ld r12,_MSR(r1)
Paul Mackerrasb0a779d2006-10-18 10:11:22 +10004611: ld r11,_NIP(r1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000462 andi. r3,r12,MSR_RI /* check if RI is set */
463 beq- unrecov_fer
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100464
465#ifdef CONFIG_VIRT_CPU_ACCOUNTING
466 andi. r3,r12,MSR_PR
467 beq 2f
468 ACCOUNT_CPU_USER_EXIT(r3, r4)
4692:
470#endif
471
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000472 ld r3,_CCR(r1)
473 ld r4,_LINK(r1)
474 ld r5,_CTR(r1)
475 ld r6,_XER(r1)
476 mtcr r3
477 mtlr r4
478 mtctr r5
479 mtxer r6
480 REST_GPR(0, r1)
481 REST_8GPRS(2, r1)
482
483 mfmsr r10
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000484 rldicl r10,r10,48,1 /* clear EE */
485 rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000486 mtmsrd r10,1
487
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000488 mtspr SPRN_SRR1,r12
489 mtspr SPRN_SRR0,r11
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000490 REST_4GPRS(10, r1)
491 ld r1,GPR1(r1)
492 rfid
493 b . /* prevent speculative execution */
494
495unrecov_fer:
496 bl .save_nvgprs
4971: addi r3,r1,STACK_FRAME_OVERHEAD
498 bl .unrecoverable_exception
499 b 1b
500
501/*
502 * 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
602
603 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
604 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
605
606 bl .slb_allocate_realmode
607
608 /* All done -- return from exception. */
609
610 ld r10,PACA_EXSLB+EX_LR(r13)
611 ld r3,PACA_EXSLB+EX_R3(r13)
612 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
613#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000614BEGIN_FW_FTR_SECTION
David Gibson3356bb92006-01-13 10:26:42 +1100615 ld r11,PACALPPACAPTR(r13)
616 ld r11,LPPACASRR0(r11) /* get SRR0 value */
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000617END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100618#endif /* CONFIG_PPC_ISERIES */
619
620 mtlr r10
621
622 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
Paul Mackerras320787c2008-04-14 13:59:02 +1000623 beq- 2f
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100624
625.machine push
626.machine "power4"
627 mtcrf 0x80,r9
628 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
629.machine pop
630
631#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000632BEGIN_FW_FTR_SECTION
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100633 mtspr SPRN_SRR0,r11
634 mtspr SPRN_SRR1,r12
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000635END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100636#endif /* CONFIG_PPC_ISERIES */
637 ld r9,PACA_EXSLB+EX_R9(r13)
638 ld r10,PACA_EXSLB+EX_R10(r13)
639 ld r11,PACA_EXSLB+EX_R11(r13)
640 ld r12,PACA_EXSLB+EX_R12(r13)
641 ld r13,PACA_EXSLB+EX_R13(r13)
642 rfid
643 b . /* prevent speculative execution */
644
Paul Mackerras320787c2008-04-14 13:59:02 +10006452:
646#ifdef CONFIG_PPC_ISERIES
647BEGIN_FW_FTR_SECTION
648 b unrecov_slb
649END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
650#endif /* CONFIG_PPC_ISERIES */
651 mfspr r11,SPRN_SRR0
652 clrrdi r10,r13,32
653 LOAD_HANDLER(r10,unrecov_slb)
654 mtspr SPRN_SRR0,r10
655 mfmsr r10
656 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
657 mtspr SPRN_SRR1,r10
658 rfid
659 b .
660
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100661unrecov_slb:
662 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
663 DISABLE_INTS
664 bl .save_nvgprs
6651: addi r3,r1,STACK_FRAME_OVERHEAD
666 bl .unrecoverable_exception
667 b 1b
668
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000669 .align 7
670 .globl hardware_interrupt_common
671 .globl hardware_interrupt_entry
672hardware_interrupt_common:
673 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000674 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000675hardware_interrupt_entry:
676 DISABLE_INTS
Olof Johanssona4165612007-09-05 12:42:30 +1000677BEGIN_FTR_SECTION
Anton Blanchardcb2c9b22006-02-13 14:48:35 +1100678 bl .ppc64_runlatch_on
Olof Johanssona4165612007-09-05 12:42:30 +1000679END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000680 addi r3,r1,STACK_FRAME_OVERHEAD
681 bl .do_IRQ
682 b .ret_from_except_lite
683
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000684#ifdef CONFIG_PPC_970_NAP
685power4_fixup_nap:
686 andc r9,r9,r10
687 std r9,TI_LOCAL_FLAGS(r11)
688 ld r10,_LINK(r1) /* make idle task do the */
689 std r10,_NIP(r1) /* equivalent of a blr */
690 blr
691#endif
692
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000693 .align 7
694 .globl alignment_common
695alignment_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000696 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000697 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000698 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000699 stw r10,PACA_EXGEN+EX_DSISR(r13)
700 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
701 ld r3,PACA_EXGEN+EX_DAR(r13)
702 lwz r4,PACA_EXGEN+EX_DSISR(r13)
703 std r3,_DAR(r1)
704 std r4,_DSISR(r1)
705 bl .save_nvgprs
706 addi r3,r1,STACK_FRAME_OVERHEAD
707 ENABLE_INTS
708 bl .alignment_exception
709 b .ret_from_except
710
711 .align 7
712 .globl program_check_common
713program_check_common:
714 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
715 bl .save_nvgprs
716 addi r3,r1,STACK_FRAME_OVERHEAD
717 ENABLE_INTS
718 bl .program_check_exception
719 b .ret_from_except
720
721 .align 7
722 .globl fp_unavailable_common
723fp_unavailable_common:
724 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100725 bne 1f /* if from user, just load it up */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000726 bl .save_nvgprs
727 addi r3,r1,STACK_FRAME_OVERHEAD
728 ENABLE_INTS
729 bl .kernel_fp_unavailable_exception
730 BUG_OPCODE
Paul Mackerras3ccfc652006-11-02 09:44:37 +11007311: b .load_up_fpu
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000732
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000733 .align 7
734 .globl altivec_unavailable_common
735altivec_unavailable_common:
736 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
737#ifdef CONFIG_ALTIVEC
738BEGIN_FTR_SECTION
739 bne .load_up_altivec /* if from user, just load it up */
740END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
741#endif
742 bl .save_nvgprs
743 addi r3,r1,STACK_FRAME_OVERHEAD
744 ENABLE_INTS
745 bl .altivec_unavailable_exception
746 b .ret_from_except
747
748#ifdef CONFIG_ALTIVEC
749/*
750 * load_up_altivec(unused, unused, tsk)
751 * Disable VMX for the task which had it previously,
752 * and save its vector registers in its thread_struct.
753 * Enables the VMX for use in the kernel on return.
754 * On SMP we know the VMX is free, since we give it up every
755 * switch (ie, no lazy save of the vector registers).
756 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
757 */
758_STATIC(load_up_altivec)
759 mfmsr r5 /* grab the current MSR */
760 oris r5,r5,MSR_VEC@h
761 mtmsrd r5 /* enable use of VMX now */
762 isync
763
764/*
765 * For SMP, we don't do lazy VMX switching because it just gets too
766 * horrendously complex, especially when a task switches from one CPU
767 * to another. Instead we call giveup_altvec in switch_to.
768 * VRSAVE isn't dealt with here, that is done in the normal context
769 * switch code. Note that we could rely on vrsave value to eventually
770 * avoid saving all of the VREGs here...
771 */
772#ifndef CONFIG_SMP
773 ld r3,last_task_used_altivec@got(r2)
774 ld r4,0(r3)
775 cmpdi 0,r4,0
776 beq 1f
777 /* Save VMX state to last_task_used_altivec's THREAD struct */
778 addi r4,r4,THREAD
779 SAVE_32VRS(0,r5,r4)
780 mfvscr vr0
781 li r10,THREAD_VSCR
782 stvx vr0,r10,r4
783 /* Disable VMX for last_task_used_altivec */
784 ld r5,PT_REGS(r4)
785 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
786 lis r6,MSR_VEC@h
787 andc r4,r4,r6
788 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
7891:
790#endif /* CONFIG_SMP */
791 /* Hack: if we get an altivec unavailable trap with VRSAVE
792 * set to all zeros, we assume this is a broken application
793 * that fails to set it properly, and thus we switch it to
794 * all 1's
795 */
796 mfspr r4,SPRN_VRSAVE
797 cmpdi 0,r4,0
798 bne+ 1f
799 li r4,-1
800 mtspr SPRN_VRSAVE,r4
8011:
802 /* enable use of VMX after return */
803 ld r4,PACACURRENT(r13)
804 addi r5,r4,THREAD /* Get THREAD */
805 oris r12,r12,MSR_VEC@h
806 std r12,_MSR(r1)
807 li r4,1
808 li r10,THREAD_VSCR
809 stw r4,THREAD_USED_VR(r5)
810 lvx vr0,r10,r5
811 mtvscr vr0
812 REST_32VRS(0,r4,r5)
813#ifndef CONFIG_SMP
814 /* Update last_task_used_math to 'current' */
815 subi r4,r5,THREAD /* Back to 'current' */
816 std r4,0(r3)
817#endif /* CONFIG_SMP */
818 /* restore registers and return */
819 b fast_exception_return
820#endif /* CONFIG_ALTIVEC */
821
822/*
823 * Hash table stuff
824 */
825 .align 7
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000826_STATIC(do_hash_page)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000827 std r3,_DAR(r1)
828 std r4,_DSISR(r1)
829
830 andis. r0,r4,0xa450 /* weird error? */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100831 bne- handle_page_fault /* if not, try to insert a HPTE */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000832BEGIN_FTR_SECTION
833 andis. r0,r4,0x0020 /* Is it a segment table fault? */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100834 bne- do_ste_alloc /* If so handle it */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000835END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
836
837 /*
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000838 * On iSeries, we soft-disable interrupts here, then
839 * hard-enable interrupts so that the hash_page code can spin on
840 * the hash_table_lock without problems on a shared processor.
841 */
842 DISABLE_INTS
843
844 /*
845 * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
846 * and will clobber volatile registers when irq tracing is enabled
847 * so we need to reload them. It may be possible to be smarter here
848 * and move the irq tracing elsewhere but let's keep it simple for
849 * now
850 */
851#ifdef CONFIG_TRACE_IRQFLAGS
852 ld r3,_DAR(r1)
853 ld r4,_DSISR(r1)
854 ld r5,_TRAP(r1)
855 ld r12,_MSR(r1)
856 clrrdi r5,r5,4
857#endif /* CONFIG_TRACE_IRQFLAGS */
858 /*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000859 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
860 * accessing a userspace segment (even from the kernel). We assume
861 * kernel addresses always have the high bit set.
862 */
863 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
864 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
865 orc r0,r12,r0 /* MSR_PR | ~high_bit */
866 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
867 ori r4,r4,1 /* add _PAGE_PRESENT */
868 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
869
870 /*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000871 * r3 contains the faulting address
872 * r4 contains the required access permissions
873 * r5 contains the trap number
874 *
875 * at return r3 = 0 for success
876 */
877 bl .hash_page /* build HPTE if possible */
878 cmpdi r3,0 /* see if hash_page succeeded */
879
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000880BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000881 /*
882 * If we had interrupts soft-enabled at the point where the
883 * DSI/ISI occurred, and an interrupt came in during hash_page,
884 * handle it now.
885 * We jump to ret_from_except_lite rather than fast_exception_return
886 * because ret_from_except_lite will check for and handle pending
887 * interrupts if necessary.
888 */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100889 beq 13f
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000890END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000891
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000892BEGIN_FW_FTR_SECTION
893 /*
894 * Here we have interrupts hard-disabled, so it is sufficient
895 * to restore paca->{soft,hard}_enable and get out.
896 */
897 beq fast_exc_return_irq /* Return from exception on success */
898END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
899
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000900 /* For a hash failure, we don't bother re-enabling interrupts */
901 ble- 12f
902
903 /*
904 * hash_page couldn't handle it, set soft interrupt enable back
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000905 * to what it was before the trap. Note that .raw_local_irq_restore
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000906 * handles any interrupts pending at this point.
907 */
908 ld r3,SOFTE(r1)
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000909 TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
910 bl .raw_local_irq_restore
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000911 b 11f
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000912
913/* Here we have a page fault that hash_page can't handle. */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100914handle_page_fault:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000915 ENABLE_INTS
91611: ld r4,_DAR(r1)
917 ld r5,_DSISR(r1)
918 addi r3,r1,STACK_FRAME_OVERHEAD
919 bl .do_page_fault
920 cmpdi r3,0
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100921 beq+ 13f
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000922 bl .save_nvgprs
923 mr r5,r3
924 addi r3,r1,STACK_FRAME_OVERHEAD
925 lwz r4,_DAR(r1)
926 bl .bad_page_fault
927 b .ret_from_except
928
Paul Mackerras79acbb32006-12-04 15:59:07 +110092913: b .ret_from_except_lite
930
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000931/* We have a page fault that hash_page could handle but HV refused
932 * the PTE insertion
933 */
93412: bl .save_nvgprs
Paul Mackerrasfa282372008-01-24 08:35:13 +1100935 mr r5,r3
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000936 addi r3,r1,STACK_FRAME_OVERHEAD
Benjamin Herrenschmidta792e752007-11-07 17:17:02 +1100937 ld r4,_DAR(r1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000938 bl .low_hash_fault
939 b .ret_from_except
940
941 /* here we have a segment miss */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100942do_ste_alloc:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000943 bl .ste_allocate /* try to insert stab entry */
944 cmpdi r3,0
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100945 bne- handle_page_fault
946 b fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000947
948/*
949 * r13 points to the PACA, r9 contains the saved CR,
950 * r11 and r12 contain the saved SRR0 and SRR1.
951 * r9 - r13 are saved in paca->exslb.
952 * We assume we aren't going to take any exceptions during this procedure.
953 * We assume (DAR >> 60) == 0xc.
954 */
955 .align 7
956_GLOBAL(do_stab_bolted)
957 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
958 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
959
960 /* Hash to the primary group */
961 ld r10,PACASTABVIRT(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000962 mfspr r11,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000963 srdi r11,r11,28
964 rldimi r10,r11,7,52 /* r10 = first ste of the group */
965
966 /* Calculate VSID */
967 /* This is a kernel address, so protovsid = ESID */
Paul Mackerras1189be62007-10-11 20:37:10 +1000968 ASM_VSID_SCRAMBLE(r11, r9, 256M)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000969 rldic r9,r11,12,16 /* r9 = vsid << 12 */
970
971 /* Search the primary group for a free entry */
9721: ld r11,0(r10) /* Test valid bit of the current ste */
973 andi. r11,r11,0x80
974 beq 2f
975 addi r10,r10,16
976 andi. r11,r10,0x70
977 bne 1b
978
979 /* Stick for only searching the primary group for now. */
980 /* At least for now, we use a very simple random castout scheme */
981 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
982 mftb r11
983 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
984 ori r11,r11,0x10
985
986 /* r10 currently points to an ste one past the group of interest */
987 /* make it point to the randomly selected entry */
988 subi r10,r10,128
989 or r10,r10,r11 /* r10 is the entry to invalidate */
990
991 isync /* mark the entry invalid */
992 ld r11,0(r10)
993 rldicl r11,r11,56,1 /* clear the valid bit */
994 rotldi r11,r11,8
995 std r11,0(r10)
996 sync
997
998 clrrdi r11,r11,28 /* Get the esid part of the ste */
999 slbie r11
1000
10012: std r9,8(r10) /* Store the vsid part of the ste */
1002 eieio
1003
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001004 mfspr r11,SPRN_DAR /* Get the new esid */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001005 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1006 ori r11,r11,0x90 /* Turn on valid and kp */
1007 std r11,0(r10) /* Put new entry back into the stab */
1008
1009 sync
1010
1011 /* All done -- return from exception. */
1012 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1013 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1014
1015 andi. r10,r12,MSR_RI
1016 beq- unrecov_slb
1017
1018 mtcrf 0x80,r9 /* restore CR */
1019
1020 mfmsr r10
1021 clrrdi r10,r10,2
1022 mtmsrd r10,1
1023
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001024 mtspr SPRN_SRR0,r11
1025 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001026 ld r9,PACA_EXSLB+EX_R9(r13)
1027 ld r10,PACA_EXSLB+EX_R10(r13)
1028 ld r11,PACA_EXSLB+EX_R11(r13)
1029 ld r12,PACA_EXSLB+EX_R12(r13)
1030 ld r13,PACA_EXSLB+EX_R13(r13)
1031 rfid
1032 b . /* prevent speculative execution */
1033
1034/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001035 * Space for CPU0's segment table.
1036 *
1037 * On iSeries, the hypervisor must fill in at least one entry before
Stephen Rothwell16a15a32007-08-20 14:58:36 +10001038 * we get control (with relocate on). The address is given to the hv
1039 * as a page number (see xLparMap below), so this must be at a
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001040 * fixed address (the linker can't compute (u64)&initial_stab >>
1041 * PAGE_SHIFT).
1042 */
Michael Ellerman758438a2005-12-05 15:49:00 -06001043 . = STAB0_OFFSET /* 0x6000 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001044 .globl initial_stab
1045initial_stab:
1046 .space 4096
1047
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001048#ifdef CONFIG_PPC_PSERIES
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001049/*
1050 * Data area reserved for FWNMI option.
1051 * This address (0x7000) is fixed by the RPA.
1052 */
1053 .= 0x7000
1054 .globl fwnmi_data_area
1055fwnmi_data_area:
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001056#endif /* CONFIG_PPC_PSERIES */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001057
1058 /* iSeries does not use the FWNMI stuff, so it is safe to put
1059 * this here, even if we later allow kernels that will boot on
1060 * both pSeries and iSeries */
1061#ifdef CONFIG_PPC_ISERIES
1062 . = LPARMAP_PHYS
Stephen Rothwell16a15a32007-08-20 14:58:36 +10001063 .globl xLparMap
1064xLparMap:
1065 .quad HvEsidsToMap /* xNumberEsids */
1066 .quad HvRangesToMap /* xNumberRanges */
1067 .quad STAB0_PAGE /* xSegmentTableOffs */
1068 .zero 40 /* xRsvd */
1069 /* xEsids (HvEsidsToMap entries of 2 quads) */
1070 .quad PAGE_OFFSET_ESID /* xKernelEsid */
1071 .quad PAGE_OFFSET_VSID /* xKernelVsid */
1072 .quad VMALLOC_START_ESID /* xKernelEsid */
1073 .quad VMALLOC_START_VSID /* xKernelVsid */
1074 /* xRanges (HvRangesToMap entries of 3 quads) */
1075 .quad HvPagesToMap /* xPages */
1076 .quad 0 /* xOffset */
1077 .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
1078
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001079#endif /* CONFIG_PPC_ISERIES */
1080
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001081#ifdef CONFIG_PPC_PSERIES
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001082 . = 0x8000
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001083#endif /* CONFIG_PPC_PSERIES */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001084
1085/*
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001086 * On pSeries and most other platforms, secondary processors spin
1087 * in the following code.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001088 * At entry, r3 = this processor's number (physical cpu id)
1089 */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001090_GLOBAL(generic_secondary_smp_init)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001091 mr r24,r3
1092
1093 /* turn on 64-bit mode */
1094 bl .enable_64b_mode
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001095
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001096 /* Set up a paca value for this processor. Since we have the
1097 * physical cpu id in r24, we need to search the pacas to find
1098 * which logical id maps to our physical one.
1099 */
David Gibsone58c3492006-01-13 14:56:25 +11001100 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001101 li r5,0 /* logical cpu id */
11021: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1103 cmpw r6,r24 /* Compare to our id */
1104 beq 2f
1105 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1106 addi r5,r5,1
1107 cmpwi r5,NR_CPUS
1108 blt 1b
1109
1110 mr r3,r24 /* not found, copy phys to r3 */
1111 b .kexec_wait /* next kernel might do better */
1112
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100011132: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001114 /* From now on, r24 is expected to be logical cpuid */
1115 mr r24,r5
11163: HMT_LOW
1117 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1118 /* start. */
1119 sync
1120
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001121#ifndef CONFIG_SMP
1122 b 3b /* Never go on non-SMP */
1123#else
1124 cmpwi 0,r23,0
1125 beq 3b /* Loop until told to go */
1126
1127 /* See if we need to call a cpu state restore handler */
1128 LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
1129 ld r23,0(r23)
1130 ld r23,CPU_SPEC_RESTORE(r23)
1131 cmpdi 0,r23,0
1132 beq 4f
1133 ld r23,0(r23)
1134 mtctr r23
1135 bctrl
1136
11374: /* Create a temp kernel stack for use before relocation is on. */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001138 ld r1,PACAEMERGSP(r13)
1139 subi r1,r1,STACK_FRAME_OVERHEAD
1140
Stephen Rothwellc7056772006-11-27 14:59:50 +11001141 b __secondary_start
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001142#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001143
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001144_STATIC(__mmu_off)
1145 mfmsr r3
1146 andi. r0,r3,MSR_IR|MSR_DR
1147 beqlr
1148 andc r3,r3,r0
1149 mtspr SPRN_SRR0,r4
1150 mtspr SPRN_SRR1,r3
1151 sync
1152 rfid
1153 b . /* prevent speculative execution */
1154
1155
1156/*
1157 * Here is our main kernel entry point. We support currently 2 kind of entries
1158 * depending on the value of r5.
1159 *
1160 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1161 * in r3...r7
1162 *
1163 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1164 * DT block, r4 is a physical pointer to the kernel itself
1165 *
1166 */
1167_GLOBAL(__start_initialization_multiplatform)
1168 /*
1169 * Are we booted from a PROM Of-type client-interface ?
1170 */
1171 cmpldi cr0,r5,0
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001172 beq 1f
1173 b .__boot_from_prom /* yes -> prom */
11741:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001175 /* Save parameters */
1176 mr r31,r3
1177 mr r30,r4
1178
1179 /* Make sure we are running in 64 bits mode */
1180 bl .enable_64b_mode
1181
1182 /* Setup some critical 970 SPRs before switching MMU off */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001183 mfspr r0,SPRN_PVR
1184 srwi r0,r0,16
1185 cmpwi r0,0x39 /* 970 */
1186 beq 1f
1187 cmpwi r0,0x3c /* 970FX */
1188 beq 1f
1189 cmpwi r0,0x44 /* 970MP */
Olof Johansson190a24f2006-10-25 17:32:40 -05001190 beq 1f
1191 cmpwi r0,0x45 /* 970GX */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001192 bne 2f
11931: bl .__cpu_preinit_ppc970
11942:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001195
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001196 /* Switch off MMU if not already */
David Gibsone58c3492006-01-13 14:56:25 +11001197 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001198 add r4,r4,r30
1199 bl .__mmu_off
1200 b .__after_prom_start
1201
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001202_INIT_STATIC(__boot_from_prom)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001203 /* Save parameters */
1204 mr r31,r3
1205 mr r30,r4
1206 mr r29,r5
1207 mr r28,r6
1208 mr r27,r7
1209
Olaf Hering60888572006-03-23 21:50:59 +01001210 /*
1211 * Align the stack to 16-byte boundary
1212 * Depending on the size and layout of the ELF sections in the initial
1213 * boot binary, the stack pointer will be unalignet on PowerMac
1214 */
Linus Torvaldsc05b4772006-03-04 15:00:45 -08001215 rldicr r1,r1,0,59
1216
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001217 /* Make sure we are running in 64 bits mode */
1218 bl .enable_64b_mode
1219
1220 /* put a relocation offset into r3 */
1221 bl .reloc_offset
1222
David Gibsone58c3492006-01-13 14:56:25 +11001223 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001224 addi r2,r2,0x4000
1225 addi r2,r2,0x4000
1226
1227 /* Relocate the TOC from a virt addr to a real addr */
Paul Mackerras5a408322005-10-10 22:41:25 +10001228 add r2,r2,r3
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001229
1230 /* Restore parameters */
1231 mr r3,r31
1232 mr r4,r30
1233 mr r5,r29
1234 mr r6,r28
1235 mr r7,r27
1236
1237 /* Do all of the interaction with OF client interface */
1238 bl .prom_init
1239 /* We never return */
1240 trap
1241
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001242_STATIC(__after_prom_start)
1243
1244/*
Michael Ellerman758438a2005-12-05 15:49:00 -06001245 * We need to run with __start at physical address PHYSICAL_START.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001246 * This will leave some code in the first 256B of
1247 * real memory, which are reserved for software use.
1248 * The remainder of the first page is loaded with the fixed
1249 * interrupt vectors. The next two pages are filled with
1250 * unknown exception placeholders.
1251 *
1252 * Note: This process overwrites the OF exception vectors.
1253 * r26 == relocation offset
1254 * r27 == KERNELBASE
1255 */
1256 bl .reloc_offset
1257 mr r26,r3
David Gibsone58c3492006-01-13 14:56:25 +11001258 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001259
David Gibsone58c3492006-01-13 14:56:25 +11001260 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001261
1262 // XXX FIXME: Use phys returned by OF (r30)
Paul Mackerras5a408322005-10-10 22:41:25 +10001263 add r4,r27,r26 /* source addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001264 /* current address of _start */
1265 /* i.e. where we are running */
1266 /* the source addr */
1267
Jimi Xenidisd0b79c52006-06-26 04:56:58 -04001268 cmpdi r4,0 /* In some cases the loader may */
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001269 bne 1f
1270 b .start_here_multiplatform /* have already put us at zero */
Jimi Xenidisd0b79c52006-06-26 04:56:58 -04001271 /* so we can skip the copy. */
Stephen Rothwell939e60f62007-07-31 16:44:13 +100012721: LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001273 sub r5,r5,r27
1274
1275 li r6,0x100 /* Start offset, the first 0x100 */
1276 /* bytes were copied earlier. */
1277
1278 bl .copy_and_flush /* copy the first n bytes */
1279 /* this includes the code being */
1280 /* executed here. */
1281
David Gibsone58c3492006-01-13 14:56:25 +11001282 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001283 mtctr r0 /* that we just made/relocated */
1284 bctr
1285
David Gibsone58c3492006-01-13 14:56:25 +110012864: LOAD_REG_IMMEDIATE(r5,klimit)
Paul Mackerras5a408322005-10-10 22:41:25 +10001287 add r5,r5,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001288 ld r5,0(r5) /* get the value of klimit */
1289 sub r5,r5,r27
1290 bl .copy_and_flush /* copy the rest */
1291 b .start_here_multiplatform
1292
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001293/*
1294 * Copy routine used to copy the kernel to start at physical address 0
1295 * and flush and invalidate the caches as needed.
1296 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1297 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1298 *
1299 * Note: this routine *only* clobbers r0, r6 and lr
1300 */
1301_GLOBAL(copy_and_flush)
1302 addi r5,r5,-8
1303 addi r6,r6,-8
Olof Johansson5a2fe382006-09-06 14:34:41 -050013044: li r0,8 /* Use the smallest common */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001305 /* denominator cache line */
1306 /* size. This results in */
1307 /* extra cache line flushes */
1308 /* but operation is correct. */
1309 /* Can't get cache line size */
1310 /* from NACA as it is being */
1311 /* moved too. */
1312
1313 mtctr r0 /* put # words/line in ctr */
13143: addi r6,r6,8 /* copy a cache line */
1315 ldx r0,r6,r4
1316 stdx r0,r6,r3
1317 bdnz 3b
1318 dcbst r6,r3 /* write it to memory */
1319 sync
1320 icbi r6,r3 /* flush the icache line */
1321 cmpld 0,r6,r5
1322 blt 4b
1323 sync
1324 addi r5,r5,8
1325 addi r6,r6,8
1326 blr
1327
1328.align 8
1329copy_to_here:
1330
1331#ifdef CONFIG_SMP
1332#ifdef CONFIG_PPC_PMAC
1333/*
1334 * On PowerMac, secondary processors starts from the reset vector, which
1335 * is temporarily turned into a call to one of the functions below.
1336 */
1337 .section ".text";
1338 .align 2 ;
1339
Paul Mackerras35499c02005-10-22 16:02:39 +10001340 .globl __secondary_start_pmac_0
1341__secondary_start_pmac_0:
1342 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1343 li r24,0
1344 b 1f
1345 li r24,1
1346 b 1f
1347 li r24,2
1348 b 1f
1349 li r24,3
13501:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001351
1352_GLOBAL(pmac_secondary_start)
1353 /* turn on 64-bit mode */
1354 bl .enable_64b_mode
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001355
1356 /* Copy some CPU settings from CPU 0 */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001357 bl .__restore_cpu_ppc970
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001358
1359 /* pSeries do that early though I don't think we really need it */
1360 mfmsr r3
1361 ori r3,r3,MSR_RI
1362 mtmsrd r3 /* RI on */
1363
1364 /* Set up a paca value for this processor. */
David Gibsone58c3492006-01-13 14:56:25 +11001365 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001366 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1367 add r13,r13,r4 /* for this processor. */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001368 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001369
1370 /* Create a temp kernel stack for use before relocation is on. */
1371 ld r1,PACAEMERGSP(r13)
1372 subi r1,r1,STACK_FRAME_OVERHEAD
1373
Stephen Rothwellc7056772006-11-27 14:59:50 +11001374 b __secondary_start
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001375
1376#endif /* CONFIG_PPC_PMAC */
1377
1378/*
1379 * This function is called after the master CPU has released the
1380 * secondary processors. The execution environment is relocation off.
1381 * The paca for this processor has the following fields initialized at
1382 * this point:
1383 * 1. Processor number
1384 * 2. Segment table pointer (virtual address)
1385 * On entry the following are set:
1386 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1387 * r24 = cpu# (in Linux terms)
1388 * r13 = paca virtual address
1389 * SPRG3 = paca virtual address
1390 */
Stephen Rothwellfc68e862007-08-22 13:44:58 +10001391 .globl __secondary_start
Stephen Rothwellc7056772006-11-27 14:59:50 +11001392__secondary_start:
Paul Mackerras799d6042005-11-10 13:37:51 +11001393 /* Set thread priority to MEDIUM */
1394 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001395
Paul Mackerras799d6042005-11-10 13:37:51 +11001396 /* Load TOC */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001397 ld r2,PACATOC(r13)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001398
Paul Mackerras799d6042005-11-10 13:37:51 +11001399 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1400 bl .early_setup_secondary
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001401
1402 /* Initialize the kernel stack. Just a repeat for iSeries. */
David Gibsone58c3492006-01-13 14:56:25 +11001403 LOAD_REG_ADDR(r3, current_set)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001404 sldi r28,r24,3 /* get current_set[cpu#] */
1405 ldx r1,r3,r28
1406 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1407 std r1,PACAKSAVE(r13)
1408
Paul Mackerras799d6042005-11-10 13:37:51 +11001409 /* Clear backchain so we get nice backtraces */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001410 li r7,0
1411 mtlr r7
1412
1413 /* enable MMU and jump to start_secondary */
David Gibsone58c3492006-01-13 14:56:25 +11001414 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1415 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001416#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001417BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001418 ori r4,r4,MSR_EE
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001419 li r8,1
1420 stb r8,PACAHARDIRQEN(r13)
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001421END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001422#endif
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001423BEGIN_FW_FTR_SECTION
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001424 stb r7,PACAHARDIRQEN(r13)
1425END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001426 stb r7,PACASOFTIRQEN(r13)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001427
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001428 mtspr SPRN_SRR0,r3
1429 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001430 rfid
1431 b . /* prevent speculative execution */
1432
1433/*
1434 * Running with relocation on at this point. All we want to do is
1435 * zero the stack back-chain pointer before going into C code.
1436 */
1437_GLOBAL(start_secondary_prolog)
1438 li r3,0
1439 std r3,0(r1) /* Zero the stack frame pointer */
1440 bl .start_secondary
Paul Mackerras799d6042005-11-10 13:37:51 +11001441 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001442#endif
1443
1444/*
1445 * This subroutine clobbers r11 and r12
1446 */
1447_GLOBAL(enable_64b_mode)
1448 mfmsr r11 /* grab the current MSR */
1449 li r12,1
1450 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1451 or r11,r11,r12
1452 li r12,1
1453 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1454 or r11,r11,r12
1455 mtmsrd r11
1456 isync
1457 blr
1458
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001459/*
1460 * This is where the main kernel code starts.
1461 */
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001462_INIT_STATIC(start_here_multiplatform)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001463 /* get a new offset, now that the kernel has moved. */
1464 bl .reloc_offset
1465 mr r26,r3
1466
1467 /* Clear out the BSS. It may have been done in prom_init,
1468 * already but that's irrelevant since prom_init will soon
1469 * be detached from the kernel completely. Besides, we need
1470 * to clear it now for kexec-style entry.
1471 */
David Gibsone58c3492006-01-13 14:56:25 +11001472 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1473 LOAD_REG_IMMEDIATE(r8,__bss_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001474 sub r11,r11,r8 /* bss size */
1475 addi r11,r11,7 /* round up to an even double word */
1476 rldicl. r11,r11,61,3 /* shift right by 3 */
1477 beq 4f
1478 addi r8,r8,-8
1479 li r0,0
1480 mtctr r11 /* zero this many doublewords */
14813: stdu r0,8(r8)
1482 bdnz 3b
14834:
1484
1485 mfmsr r6
1486 ori r6,r6,MSR_RI
1487 mtmsrd r6 /* RI on */
1488
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001489 /* The following gets the stack and TOC set up with the regs */
1490 /* pointing to the real addr of the kernel stack. This is */
1491 /* all done to support the C function call below which sets */
1492 /* up the htab. This is done because we have relocated the */
1493 /* kernel but are still running in real mode. */
1494
David Gibsone58c3492006-01-13 14:56:25 +11001495 LOAD_REG_IMMEDIATE(r3,init_thread_union)
Paul Mackerras5a408322005-10-10 22:41:25 +10001496 add r3,r3,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001497
1498 /* set up a stack pointer (physical address) */
1499 addi r1,r3,THREAD_SIZE
1500 li r0,0
1501 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1502
1503 /* set up the TOC (physical address) */
David Gibsone58c3492006-01-13 14:56:25 +11001504 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001505 addi r2,r2,0x4000
1506 addi r2,r2,0x4000
Paul Mackerras5a408322005-10-10 22:41:25 +10001507 add r2,r2,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001508
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +10001509 /* Set initial ptr to current */
1510 LOAD_REG_IMMEDIATE(r4, init_task)
1511 std r4,PACACURRENT(r13)
1512
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001513 /* Do very early kernel initializations, including initial hash table,
1514 * stab and slb setup before we turn on relocation. */
1515
1516 /* Restore parameters passed from prom_init/kexec */
1517 mr r3,r31
1518 bl .early_setup
1519
David Gibsone58c3492006-01-13 14:56:25 +11001520 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1521 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001522 mtspr SPRN_SRR0,r3
1523 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001524 rfid
1525 b . /* prevent speculative execution */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001526
1527 /* This is where all platforms converge execution */
Stephen Rothwellfc68e862007-08-22 13:44:58 +10001528_INIT_GLOBAL(start_here_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001529 /* relocation is on at this point */
1530
1531 /* The following code sets up the SP and TOC now that we are */
1532 /* running with translation enabled. */
1533
David Gibsone58c3492006-01-13 14:56:25 +11001534 LOAD_REG_IMMEDIATE(r3,init_thread_union)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001535
1536 /* set up the stack */
1537 addi r1,r3,THREAD_SIZE
1538 li r0,0
1539 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1540
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001541 /* Load the TOC */
1542 ld r2,PACATOC(r13)
1543 std r1,PACAKSAVE(r13)
1544
1545 bl .setup_system
1546
1547 /* Load up the kernel context */
15485:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001549 li r5,0
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001550 stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
1551#ifdef CONFIG_PPC_ISERIES
1552BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001553 mfmsr r5
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001554 ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001555 mtmsrd r5
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001556 li r5,1
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001557END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001558#endif
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001559 stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001560
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001561 bl .start_kernel
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001562
Anton Blanchardf1870f72006-02-13 18:11:13 +11001563 /* Not reached */
1564 BUG_OPCODE
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001565
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001566/*
1567 * We put a few things here that have to be page-aligned.
1568 * This stuff goes at the beginning of the bss, which is page-aligned.
1569 */
1570 .section ".bss"
1571
1572 .align PAGE_SHIFT
1573
1574 .globl empty_zero_page
1575empty_zero_page:
1576 .space PAGE_SIZE
1577
1578 .globl swapper_pg_dir
1579swapper_pg_dir:
Stephen Rothwellee7a76d2007-09-18 17:22:59 +10001580 .space PGD_TABLE_SIZE