blob: 64433731d9958cc148d0458f8fdf3d1d33fbd65e [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 Ellerman1dce0e32006-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 Mackerras745a14c2008-04-28 13:52:31 +1000242BEGIN_FTR_SECTION
243 cmpdi r0,0x1ebe
244 beq- 1f
245END_FTR_SECTION_IFSET(CPU_FTR_REAL_LE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000246 mr r9,r13
247 mfmsr r10
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000248 mfspr r13,SPRN_SPRG3
249 mfspr r11,SPRN_SRR0
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000250 clrrdi r12,r13,32
251 oris r12,r12,system_call_common@h
252 ori r12,r12,system_call_common@l
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000253 mtspr SPRN_SRR0,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000254 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000255 mfspr r12,SPRN_SRR1
256 mtspr SPRN_SRR1,r10
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000257 rfid
258 b . /* prevent speculative execution */
259
Paul Mackerras745a14c2008-04-28 13:52:31 +1000260/* Fast LE/BE switch system call */
2611: mfspr r12,SPRN_SRR1
262 xori r12,r12,MSR_LE
263 mtspr SPRN_SRR1,r12
264 rfid /* return to userspace */
265 b .
266
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000267 STD_EXCEPTION_PSERIES(0xd00, single_step)
268 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
269
270 /* We need to deal with the Altivec unavailable exception
271 * here which is at 0xf20, thus in the middle of the
272 * prolog code of the PerformanceMonitor one. A little
273 * trickery is thus necessary
274 */
275 . = 0xf00
276 b performance_monitor_pSeries
277
Michael Neuling10e34392008-06-25 14:07:18 +1000278 . = 0xf20
279 b altivec_unavailable_pSeries
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000280
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200281#ifdef CONFIG_CBE_RAS
282 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
283#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000284 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200285#ifdef CONFIG_CBE_RAS
286 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
287#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000288 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200289#ifdef CONFIG_CBE_RAS
290 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
291#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000292
293 . = 0x3000
294
295/*** pSeries interrupt support ***/
296
297 /* moved from 0xf00 */
Livio Soares449d8462007-02-07 12:51:36 +1100298 STD_EXCEPTION_PSERIES(., performance_monitor)
Michael Neuling10e34392008-06-25 14:07:18 +1000299 STD_EXCEPTION_PSERIES(., altivec_unavailable)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000300
301/*
302 * An interrupt came in while soft-disabled; clear EE in SRR1,
303 * clear paca->hard_enabled and return.
304 */
305masked_interrupt:
306 stb r10,PACAHARDIRQEN(r13)
307 mtcrf 0x80,r9
308 ld r9,PACA_EXGEN+EX_R9(r13)
309 mfspr r10,SPRN_SRR1
310 rldicl r10,r10,48,1 /* clear MSR_EE */
311 rotldi r10,r10,16
312 mtspr SPRN_SRR1,r10
313 ld r10,PACA_EXGEN+EX_R10(r13)
314 mfspr r13,SPRN_SPRG1
315 rfid
316 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000317
318 .align 7
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100319do_stab_bolted_pSeries:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000320 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000321 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000322 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
323
324/*
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100325 * We have some room here we use that to put
326 * the peries slb miss user trampoline code so it's reasonably
327 * away from slb_miss_user_common to avoid problems with rfid
328 *
329 * This is used for when the SLB miss handler has to go virtual,
330 * which doesn't happen for now anymore but will once we re-implement
331 * dynamic VSIDs for shared page tables
332 */
333#ifdef __DISABLED__
334slb_miss_user_pseries:
335 std r10,PACA_EXGEN+EX_R10(r13)
336 std r11,PACA_EXGEN+EX_R11(r13)
337 std r12,PACA_EXGEN+EX_R12(r13)
338 mfspr r10,SPRG1
339 ld r11,PACA_EXSLB+EX_R9(r13)
340 ld r12,PACA_EXSLB+EX_R3(r13)
341 std r10,PACA_EXGEN+EX_R13(r13)
342 std r11,PACA_EXGEN+EX_R9(r13)
343 std r12,PACA_EXGEN+EX_R3(r13)
344 clrrdi r12,r13,32
345 mfmsr r10
346 mfspr r11,SRR0 /* save SRR0 */
347 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
348 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
349 mtspr SRR0,r12
350 mfspr r12,SRR1 /* and SRR1 */
351 mtspr SRR1,r10
352 rfid
353 b . /* prevent spec. execution */
354#endif /* __DISABLED__ */
355
Stephen Rothwell9e4859e2007-09-18 17:25:12 +1000356#ifdef CONFIG_PPC_PSERIES
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100357/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000358 * Vectors for the FWNMI option. Share common code.
359 */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000360 .globl system_reset_fwnmi
Michael Ellerman8c4f1f22005-12-04 18:39:33 +1100361 .align 7
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000362system_reset_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000363 HMT_MEDIUM
364 mtspr SPRN_SPRG1,r13 /* save r13 */
Olaf Hering9fc0a922006-07-19 10:34:05 +0200365 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXGEN, system_reset_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000366
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000367 .globl machine_check_fwnmi
Michael Ellerman8c4f1f22005-12-04 18:39:33 +1100368 .align 7
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000369machine_check_fwnmi:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000370 HMT_MEDIUM
371 mtspr SPRN_SPRG1,r13 /* save r13 */
Olaf Hering9fc0a922006-07-19 10:34:05 +0200372 EXCEPTION_PROLOG_PSERIES_FORCE_64BIT(PACA_EXMC, machine_check_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000373
Stephen Rothwell9e4859e2007-09-18 17:25:12 +1000374#endif /* CONFIG_PPC_PSERIES */
375
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000376/*** Common interrupt handlers ***/
377
378 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
379
380 /*
381 * Machine check is different because we use a different
382 * save area: PACA_EXMC instead of PACA_EXGEN.
383 */
384 .align 7
385 .globl machine_check_common
386machine_check_common:
387 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000388 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000389 DISABLE_INTS
390 bl .save_nvgprs
391 addi r3,r1,STACK_FRAME_OVERHEAD
392 bl .machine_check_exception
393 b .ret_from_except
394
395 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
396 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
397 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
398 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
399 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000400 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000401 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
402#ifdef CONFIG_ALTIVEC
403 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
404#else
405 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
406#endif
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200407#ifdef CONFIG_CBE_RAS
408 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
409 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
410 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
411#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000412
413/*
414 * Here we have detected that the kernel stack pointer is bad.
415 * R9 contains the saved CR, r13 points to the paca,
416 * r10 contains the (bad) kernel stack pointer,
417 * r11 and r12 contain the saved SRR0 and SRR1.
418 * We switch to using an emergency stack, save the registers there,
419 * and call kernel_bad_stack(), which panics.
420 */
421bad_stack:
422 ld r1,PACAEMERGSP(r13)
423 subi r1,r1,64+INT_FRAME_SIZE
424 std r9,_CCR(r1)
425 std r10,GPR1(r1)
426 std r11,_NIP(r1)
427 std r12,_MSR(r1)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000428 mfspr r11,SPRN_DAR
429 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000430 std r11,_DAR(r1)
431 std r12,_DSISR(r1)
432 mflr r10
433 mfctr r11
434 mfxer r12
435 std r10,_LINK(r1)
436 std r11,_CTR(r1)
437 std r12,_XER(r1)
438 SAVE_GPR(0,r1)
439 SAVE_GPR(2,r1)
440 SAVE_4GPRS(3,r1)
441 SAVE_2GPRS(7,r1)
442 SAVE_10GPRS(12,r1)
443 SAVE_10GPRS(22,r1)
Olof Johansson68730402007-04-24 01:11:55 +1000444 lhz r12,PACA_TRAP_SAVE(r13)
445 std r12,_TRAP(r1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000446 addi r11,r1,INT_FRAME_SIZE
447 std r11,0(r1)
448 li r12,0
449 std r12,0(r11)
450 ld r2,PACATOC(r13)
4511: addi r3,r1,STACK_FRAME_OVERHEAD
452 bl .kernel_bad_stack
453 b 1b
454
455/*
456 * Return from an exception with minimal checks.
457 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
458 * If interrupts have been enabled, or anything has been
459 * done that might have changed the scheduling status of
460 * any task or sent any task a signal, you should use
461 * ret_from_except or ret_from_except_lite instead of this.
462 */
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000463fast_exc_return_irq: /* restores irq state too */
464 ld r3,SOFTE(r1)
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000465 TRACE_AND_RESTORE_IRQ(r3);
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000466 ld r12,_MSR(r1)
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000467 rldicl r4,r12,49,63 /* get MSR_EE to LSB */
468 stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
469 b 1f
470
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000471 .globl fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000472fast_exception_return:
473 ld r12,_MSR(r1)
Paul Mackerrasb0a779d2006-10-18 10:11:22 +10004741: ld r11,_NIP(r1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000475 andi. r3,r12,MSR_RI /* check if RI is set */
476 beq- unrecov_fer
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100477
478#ifdef CONFIG_VIRT_CPU_ACCOUNTING
479 andi. r3,r12,MSR_PR
480 beq 2f
481 ACCOUNT_CPU_USER_EXIT(r3, r4)
4822:
483#endif
484
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000485 ld r3,_CCR(r1)
486 ld r4,_LINK(r1)
487 ld r5,_CTR(r1)
488 ld r6,_XER(r1)
489 mtcr r3
490 mtlr r4
491 mtctr r5
492 mtxer r6
493 REST_GPR(0, r1)
494 REST_8GPRS(2, r1)
495
496 mfmsr r10
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000497 rldicl r10,r10,48,1 /* clear EE */
498 rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000499 mtmsrd r10,1
500
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000501 mtspr SPRN_SRR1,r12
502 mtspr SPRN_SRR0,r11
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000503 REST_4GPRS(10, r1)
504 ld r1,GPR1(r1)
505 rfid
506 b . /* prevent speculative execution */
507
508unrecov_fer:
509 bl .save_nvgprs
5101: addi r3,r1,STACK_FRAME_OVERHEAD
511 bl .unrecoverable_exception
512 b 1b
513
514/*
515 * Here r13 points to the paca, r9 contains the saved CR,
516 * SRR0 and SRR1 are saved in r11 and r12,
517 * r9 - r13 are saved in paca->exgen.
518 */
519 .align 7
520 .globl data_access_common
521data_access_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000522 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000523 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000524 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000525 stw r10,PACA_EXGEN+EX_DSISR(r13)
526 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
527 ld r3,PACA_EXGEN+EX_DAR(r13)
528 lwz r4,PACA_EXGEN+EX_DSISR(r13)
529 li r5,0x300
530 b .do_hash_page /* Try to handle as hpte fault */
531
532 .align 7
533 .globl instruction_access_common
534instruction_access_common:
535 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
536 ld r3,_NIP(r1)
537 andis. r4,r12,0x5820
538 li r5,0x400
539 b .do_hash_page /* Try to handle as hpte fault */
540
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100541/*
542 * Here is the common SLB miss user that is used when going to virtual
543 * mode for SLB misses, that is currently not used
544 */
545#ifdef __DISABLED__
546 .align 7
547 .globl slb_miss_user_common
548slb_miss_user_common:
549 mflr r10
550 std r3,PACA_EXGEN+EX_DAR(r13)
551 stw r9,PACA_EXGEN+EX_CCR(r13)
552 std r10,PACA_EXGEN+EX_LR(r13)
553 std r11,PACA_EXGEN+EX_SRR0(r13)
554 bl .slb_allocate_user
555
556 ld r10,PACA_EXGEN+EX_LR(r13)
557 ld r3,PACA_EXGEN+EX_R3(r13)
558 lwz r9,PACA_EXGEN+EX_CCR(r13)
559 ld r11,PACA_EXGEN+EX_SRR0(r13)
560 mtlr r10
561 beq- slb_miss_fault
562
563 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
564 beq- unrecov_user_slb
565 mfmsr r10
566
567.machine push
568.machine "power4"
569 mtcrf 0x80,r9
570.machine pop
571
572 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
573 mtmsrd r10,1
574
575 mtspr SRR0,r11
576 mtspr SRR1,r12
577
578 ld r9,PACA_EXGEN+EX_R9(r13)
579 ld r10,PACA_EXGEN+EX_R10(r13)
580 ld r11,PACA_EXGEN+EX_R11(r13)
581 ld r12,PACA_EXGEN+EX_R12(r13)
582 ld r13,PACA_EXGEN+EX_R13(r13)
583 rfid
584 b .
585
586slb_miss_fault:
587 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
588 ld r4,PACA_EXGEN+EX_DAR(r13)
589 li r5,0
590 std r4,_DAR(r1)
591 std r5,_DSISR(r1)
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100592 b handle_page_fault
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100593
594unrecov_user_slb:
595 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
596 DISABLE_INTS
597 bl .save_nvgprs
5981: addi r3,r1,STACK_FRAME_OVERHEAD
599 bl .unrecoverable_exception
600 b 1b
601
602#endif /* __DISABLED__ */
603
604
605/*
606 * r13 points to the PACA, r9 contains the saved CR,
607 * r12 contain the saved SRR1, SRR0 is still ready for return
608 * r3 has the faulting address
609 * r9 - r13 are saved in paca->exslb.
610 * r3 is saved in paca->slb_r3
611 * We assume we aren't going to take any exceptions during this procedure.
612 */
613_GLOBAL(slb_miss_realmode)
614 mflr r10
615
616 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
617 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
618
619 bl .slb_allocate_realmode
620
621 /* All done -- return from exception. */
622
623 ld r10,PACA_EXSLB+EX_LR(r13)
624 ld r3,PACA_EXSLB+EX_R3(r13)
625 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
626#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000627BEGIN_FW_FTR_SECTION
David Gibson3356bb92006-01-13 10:26:42 +1100628 ld r11,PACALPPACAPTR(r13)
629 ld r11,LPPACASRR0(r11) /* get SRR0 value */
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000630END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100631#endif /* CONFIG_PPC_ISERIES */
632
633 mtlr r10
634
635 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
Paul Mackerras320787c2008-04-14 13:59:02 +1000636 beq- 2f
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100637
638.machine push
639.machine "power4"
640 mtcrf 0x80,r9
641 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
642.machine pop
643
644#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000645BEGIN_FW_FTR_SECTION
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100646 mtspr SPRN_SRR0,r11
647 mtspr SPRN_SRR1,r12
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000648END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100649#endif /* CONFIG_PPC_ISERIES */
650 ld r9,PACA_EXSLB+EX_R9(r13)
651 ld r10,PACA_EXSLB+EX_R10(r13)
652 ld r11,PACA_EXSLB+EX_R11(r13)
653 ld r12,PACA_EXSLB+EX_R12(r13)
654 ld r13,PACA_EXSLB+EX_R13(r13)
655 rfid
656 b . /* prevent speculative execution */
657
Paul Mackerras320787c2008-04-14 13:59:02 +10006582:
659#ifdef CONFIG_PPC_ISERIES
660BEGIN_FW_FTR_SECTION
661 b unrecov_slb
662END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
663#endif /* CONFIG_PPC_ISERIES */
664 mfspr r11,SPRN_SRR0
665 clrrdi r10,r13,32
666 LOAD_HANDLER(r10,unrecov_slb)
667 mtspr SPRN_SRR0,r10
668 mfmsr r10
669 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
670 mtspr SPRN_SRR1,r10
671 rfid
672 b .
673
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100674unrecov_slb:
675 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
676 DISABLE_INTS
677 bl .save_nvgprs
6781: addi r3,r1,STACK_FRAME_OVERHEAD
679 bl .unrecoverable_exception
680 b 1b
681
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000682 .align 7
683 .globl hardware_interrupt_common
684 .globl hardware_interrupt_entry
685hardware_interrupt_common:
686 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000687 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000688hardware_interrupt_entry:
689 DISABLE_INTS
Olof Johanssona4165612007-09-05 12:42:30 +1000690BEGIN_FTR_SECTION
Anton Blanchardcb2c9b22006-02-13 14:48:35 +1100691 bl .ppc64_runlatch_on
Olof Johanssona4165612007-09-05 12:42:30 +1000692END_FTR_SECTION_IFSET(CPU_FTR_CTRL)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000693 addi r3,r1,STACK_FRAME_OVERHEAD
694 bl .do_IRQ
695 b .ret_from_except_lite
696
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000697#ifdef CONFIG_PPC_970_NAP
698power4_fixup_nap:
699 andc r9,r9,r10
700 std r9,TI_LOCAL_FLAGS(r11)
701 ld r10,_LINK(r1) /* make idle task do the */
702 std r10,_NIP(r1) /* equivalent of a blr */
703 blr
704#endif
705
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000706 .align 7
707 .globl alignment_common
708alignment_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000709 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000710 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000711 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000712 stw r10,PACA_EXGEN+EX_DSISR(r13)
713 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
714 ld r3,PACA_EXGEN+EX_DAR(r13)
715 lwz r4,PACA_EXGEN+EX_DSISR(r13)
716 std r3,_DAR(r1)
717 std r4,_DSISR(r1)
718 bl .save_nvgprs
719 addi r3,r1,STACK_FRAME_OVERHEAD
720 ENABLE_INTS
721 bl .alignment_exception
722 b .ret_from_except
723
724 .align 7
725 .globl program_check_common
726program_check_common:
727 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
728 bl .save_nvgprs
729 addi r3,r1,STACK_FRAME_OVERHEAD
730 ENABLE_INTS
731 bl .program_check_exception
732 b .ret_from_except
733
734 .align 7
735 .globl fp_unavailable_common
736fp_unavailable_common:
737 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100738 bne 1f /* if from user, just load it up */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000739 bl .save_nvgprs
740 addi r3,r1,STACK_FRAME_OVERHEAD
741 ENABLE_INTS
742 bl .kernel_fp_unavailable_exception
743 BUG_OPCODE
Michael Neuling6f3d8e62008-06-25 14:07:18 +10007441: bl .load_up_fpu
745 b fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000746
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000747 .align 7
748 .globl altivec_unavailable_common
749altivec_unavailable_common:
750 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
751#ifdef CONFIG_ALTIVEC
752BEGIN_FTR_SECTION
Michael Neuling6f3d8e62008-06-25 14:07:18 +1000753 beq 1f
754 bl .load_up_altivec
755 b fast_exception_return
7561:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000757END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
758#endif
759 bl .save_nvgprs
760 addi r3,r1,STACK_FRAME_OVERHEAD
761 ENABLE_INTS
762 bl .altivec_unavailable_exception
763 b .ret_from_except
764
765#ifdef CONFIG_ALTIVEC
766/*
767 * load_up_altivec(unused, unused, tsk)
768 * Disable VMX for the task which had it previously,
769 * and save its vector registers in its thread_struct.
770 * Enables the VMX for use in the kernel on return.
771 * On SMP we know the VMX is free, since we give it up every
772 * switch (ie, no lazy save of the vector registers).
773 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
774 */
775_STATIC(load_up_altivec)
776 mfmsr r5 /* grab the current MSR */
777 oris r5,r5,MSR_VEC@h
778 mtmsrd r5 /* enable use of VMX now */
779 isync
780
781/*
782 * For SMP, we don't do lazy VMX switching because it just gets too
783 * horrendously complex, especially when a task switches from one CPU
784 * to another. Instead we call giveup_altvec in switch_to.
785 * VRSAVE isn't dealt with here, that is done in the normal context
786 * switch code. Note that we could rely on vrsave value to eventually
787 * avoid saving all of the VREGs here...
788 */
789#ifndef CONFIG_SMP
790 ld r3,last_task_used_altivec@got(r2)
791 ld r4,0(r3)
792 cmpdi 0,r4,0
793 beq 1f
794 /* Save VMX state to last_task_used_altivec's THREAD struct */
795 addi r4,r4,THREAD
796 SAVE_32VRS(0,r5,r4)
797 mfvscr vr0
798 li r10,THREAD_VSCR
799 stvx vr0,r10,r4
800 /* Disable VMX for last_task_used_altivec */
801 ld r5,PT_REGS(r4)
802 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
803 lis r6,MSR_VEC@h
804 andc r4,r4,r6
805 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
8061:
807#endif /* CONFIG_SMP */
808 /* Hack: if we get an altivec unavailable trap with VRSAVE
809 * set to all zeros, we assume this is a broken application
810 * that fails to set it properly, and thus we switch it to
811 * all 1's
812 */
813 mfspr r4,SPRN_VRSAVE
814 cmpdi 0,r4,0
815 bne+ 1f
816 li r4,-1
817 mtspr SPRN_VRSAVE,r4
8181:
819 /* enable use of VMX after return */
820 ld r4,PACACURRENT(r13)
821 addi r5,r4,THREAD /* Get THREAD */
822 oris r12,r12,MSR_VEC@h
823 std r12,_MSR(r1)
824 li r4,1
825 li r10,THREAD_VSCR
826 stw r4,THREAD_USED_VR(r5)
827 lvx vr0,r10,r5
828 mtvscr vr0
829 REST_32VRS(0,r4,r5)
830#ifndef CONFIG_SMP
831 /* Update last_task_used_math to 'current' */
832 subi r4,r5,THREAD /* Back to 'current' */
833 std r4,0(r3)
834#endif /* CONFIG_SMP */
835 /* restore registers and return */
Michael Neuling6f3d8e62008-06-25 14:07:18 +1000836 blr
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000837#endif /* CONFIG_ALTIVEC */
838
839/*
840 * Hash table stuff
841 */
842 .align 7
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000843_STATIC(do_hash_page)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000844 std r3,_DAR(r1)
845 std r4,_DSISR(r1)
846
847 andis. r0,r4,0xa450 /* weird error? */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100848 bne- handle_page_fault /* if not, try to insert a HPTE */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000849BEGIN_FTR_SECTION
850 andis. r0,r4,0x0020 /* Is it a segment table fault? */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100851 bne- do_ste_alloc /* If so handle it */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000852END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
853
854 /*
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000855 * On iSeries, we soft-disable interrupts here, then
856 * hard-enable interrupts so that the hash_page code can spin on
857 * the hash_table_lock without problems on a shared processor.
858 */
859 DISABLE_INTS
860
861 /*
862 * Currently, trace_hardirqs_off() will be called by DISABLE_INTS
863 * and will clobber volatile registers when irq tracing is enabled
864 * so we need to reload them. It may be possible to be smarter here
865 * and move the irq tracing elsewhere but let's keep it simple for
866 * now
867 */
868#ifdef CONFIG_TRACE_IRQFLAGS
869 ld r3,_DAR(r1)
870 ld r4,_DSISR(r1)
871 ld r5,_TRAP(r1)
872 ld r12,_MSR(r1)
873 clrrdi r5,r5,4
874#endif /* CONFIG_TRACE_IRQFLAGS */
875 /*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000876 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
877 * accessing a userspace segment (even from the kernel). We assume
878 * kernel addresses always have the high bit set.
879 */
880 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
881 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
882 orc r0,r12,r0 /* MSR_PR | ~high_bit */
883 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
884 ori r4,r4,1 /* add _PAGE_PRESENT */
885 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
886
887 /*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000888 * r3 contains the faulting address
889 * r4 contains the required access permissions
890 * r5 contains the trap number
891 *
892 * at return r3 = 0 for success
893 */
894 bl .hash_page /* build HPTE if possible */
895 cmpdi r3,0 /* see if hash_page succeeded */
896
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000897BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000898 /*
899 * If we had interrupts soft-enabled at the point where the
900 * DSI/ISI occurred, and an interrupt came in during hash_page,
901 * handle it now.
902 * We jump to ret_from_except_lite rather than fast_exception_return
903 * because ret_from_except_lite will check for and handle pending
904 * interrupts if necessary.
905 */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100906 beq 13f
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000907END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000908
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000909BEGIN_FW_FTR_SECTION
910 /*
911 * Here we have interrupts hard-disabled, so it is sufficient
912 * to restore paca->{soft,hard}_enable and get out.
913 */
914 beq fast_exc_return_irq /* Return from exception on success */
915END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
916
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000917 /* For a hash failure, we don't bother re-enabling interrupts */
918 ble- 12f
919
920 /*
921 * hash_page couldn't handle it, set soft interrupt enable back
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000922 * to what it was before the trap. Note that .raw_local_irq_restore
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000923 * handles any interrupts pending at this point.
924 */
925 ld r3,SOFTE(r1)
Benjamin Herrenschmidt945feb12008-04-17 14:35:01 +1000926 TRACE_AND_RESTORE_IRQ_PARTIAL(r3, 11f)
927 bl .raw_local_irq_restore
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000928 b 11f
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000929
930/* Here we have a page fault that hash_page can't handle. */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100931handle_page_fault:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000932 ENABLE_INTS
93311: ld r4,_DAR(r1)
934 ld r5,_DSISR(r1)
935 addi r3,r1,STACK_FRAME_OVERHEAD
936 bl .do_page_fault
937 cmpdi r3,0
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100938 beq+ 13f
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000939 bl .save_nvgprs
940 mr r5,r3
941 addi r3,r1,STACK_FRAME_OVERHEAD
942 lwz r4,_DAR(r1)
943 bl .bad_page_fault
944 b .ret_from_except
945
Paul Mackerras79acbb32006-12-04 15:59:07 +110094613: b .ret_from_except_lite
947
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000948/* We have a page fault that hash_page could handle but HV refused
949 * the PTE insertion
950 */
95112: bl .save_nvgprs
Paul Mackerrasfa282372008-01-24 08:35:13 +1100952 mr r5,r3
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000953 addi r3,r1,STACK_FRAME_OVERHEAD
Benjamin Herrenschmidta792e752007-11-07 17:17:02 +1100954 ld r4,_DAR(r1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000955 bl .low_hash_fault
956 b .ret_from_except
957
958 /* here we have a segment miss */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100959do_ste_alloc:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000960 bl .ste_allocate /* try to insert stab entry */
961 cmpdi r3,0
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100962 bne- handle_page_fault
963 b fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000964
965/*
966 * r13 points to the PACA, r9 contains the saved CR,
967 * r11 and r12 contain the saved SRR0 and SRR1.
968 * r9 - r13 are saved in paca->exslb.
969 * We assume we aren't going to take any exceptions during this procedure.
970 * We assume (DAR >> 60) == 0xc.
971 */
972 .align 7
973_GLOBAL(do_stab_bolted)
974 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
975 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
976
977 /* Hash to the primary group */
978 ld r10,PACASTABVIRT(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000979 mfspr r11,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000980 srdi r11,r11,28
981 rldimi r10,r11,7,52 /* r10 = first ste of the group */
982
983 /* Calculate VSID */
984 /* This is a kernel address, so protovsid = ESID */
Paul Mackerras1189be62007-10-11 20:37:10 +1000985 ASM_VSID_SCRAMBLE(r11, r9, 256M)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000986 rldic r9,r11,12,16 /* r9 = vsid << 12 */
987
988 /* Search the primary group for a free entry */
9891: ld r11,0(r10) /* Test valid bit of the current ste */
990 andi. r11,r11,0x80
991 beq 2f
992 addi r10,r10,16
993 andi. r11,r10,0x70
994 bne 1b
995
996 /* Stick for only searching the primary group for now. */
997 /* At least for now, we use a very simple random castout scheme */
998 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
999 mftb r11
1000 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1001 ori r11,r11,0x10
1002
1003 /* r10 currently points to an ste one past the group of interest */
1004 /* make it point to the randomly selected entry */
1005 subi r10,r10,128
1006 or r10,r10,r11 /* r10 is the entry to invalidate */
1007
1008 isync /* mark the entry invalid */
1009 ld r11,0(r10)
1010 rldicl r11,r11,56,1 /* clear the valid bit */
1011 rotldi r11,r11,8
1012 std r11,0(r10)
1013 sync
1014
1015 clrrdi r11,r11,28 /* Get the esid part of the ste */
1016 slbie r11
1017
10182: std r9,8(r10) /* Store the vsid part of the ste */
1019 eieio
1020
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001021 mfspr r11,SPRN_DAR /* Get the new esid */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001022 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1023 ori r11,r11,0x90 /* Turn on valid and kp */
1024 std r11,0(r10) /* Put new entry back into the stab */
1025
1026 sync
1027
1028 /* All done -- return from exception. */
1029 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1030 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1031
1032 andi. r10,r12,MSR_RI
1033 beq- unrecov_slb
1034
1035 mtcrf 0x80,r9 /* restore CR */
1036
1037 mfmsr r10
1038 clrrdi r10,r10,2
1039 mtmsrd r10,1
1040
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001041 mtspr SPRN_SRR0,r11
1042 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001043 ld r9,PACA_EXSLB+EX_R9(r13)
1044 ld r10,PACA_EXSLB+EX_R10(r13)
1045 ld r11,PACA_EXSLB+EX_R11(r13)
1046 ld r12,PACA_EXSLB+EX_R12(r13)
1047 ld r13,PACA_EXSLB+EX_R13(r13)
1048 rfid
1049 b . /* prevent speculative execution */
1050
1051/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001052 * Space for CPU0's segment table.
1053 *
1054 * On iSeries, the hypervisor must fill in at least one entry before
Stephen Rothwell16a15a32007-08-20 14:58:36 +10001055 * we get control (with relocate on). The address is given to the hv
1056 * as a page number (see xLparMap below), so this must be at a
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001057 * fixed address (the linker can't compute (u64)&initial_stab >>
1058 * PAGE_SHIFT).
1059 */
Michael Ellerman758438a2005-12-05 15:49:00 -06001060 . = STAB0_OFFSET /* 0x6000 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001061 .globl initial_stab
1062initial_stab:
1063 .space 4096
1064
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001065#ifdef CONFIG_PPC_PSERIES
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001066/*
1067 * Data area reserved for FWNMI option.
1068 * This address (0x7000) is fixed by the RPA.
1069 */
1070 .= 0x7000
1071 .globl fwnmi_data_area
1072fwnmi_data_area:
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001073#endif /* CONFIG_PPC_PSERIES */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001074
1075 /* iSeries does not use the FWNMI stuff, so it is safe to put
1076 * this here, even if we later allow kernels that will boot on
1077 * both pSeries and iSeries */
1078#ifdef CONFIG_PPC_ISERIES
1079 . = LPARMAP_PHYS
Stephen Rothwell16a15a32007-08-20 14:58:36 +10001080 .globl xLparMap
1081xLparMap:
1082 .quad HvEsidsToMap /* xNumberEsids */
1083 .quad HvRangesToMap /* xNumberRanges */
1084 .quad STAB0_PAGE /* xSegmentTableOffs */
1085 .zero 40 /* xRsvd */
1086 /* xEsids (HvEsidsToMap entries of 2 quads) */
1087 .quad PAGE_OFFSET_ESID /* xKernelEsid */
1088 .quad PAGE_OFFSET_VSID /* xKernelVsid */
1089 .quad VMALLOC_START_ESID /* xKernelEsid */
1090 .quad VMALLOC_START_VSID /* xKernelVsid */
1091 /* xRanges (HvRangesToMap entries of 3 quads) */
1092 .quad HvPagesToMap /* xPages */
1093 .quad 0 /* xOffset */
1094 .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
1095
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001096#endif /* CONFIG_PPC_ISERIES */
1097
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001098#ifdef CONFIG_PPC_PSERIES
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001099 . = 0x8000
Stephen Rothwell9e4859e2007-09-18 17:25:12 +10001100#endif /* CONFIG_PPC_PSERIES */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001101
1102/*
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001103 * On pSeries and most other platforms, secondary processors spin
1104 * in the following code.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001105 * At entry, r3 = this processor's number (physical cpu id)
1106 */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001107_GLOBAL(generic_secondary_smp_init)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001108 mr r24,r3
1109
1110 /* turn on 64-bit mode */
1111 bl .enable_64b_mode
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001112
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001113 /* Set up a paca value for this processor. Since we have the
1114 * physical cpu id in r24, we need to search the pacas to find
1115 * which logical id maps to our physical one.
1116 */
David Gibsone58c3492006-01-13 14:56:25 +11001117 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001118 li r5,0 /* logical cpu id */
11191: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1120 cmpw r6,r24 /* Compare to our id */
1121 beq 2f
1122 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1123 addi r5,r5,1
1124 cmpwi r5,NR_CPUS
1125 blt 1b
1126
1127 mr r3,r24 /* not found, copy phys to r3 */
1128 b .kexec_wait /* next kernel might do better */
1129
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100011302: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001131 /* From now on, r24 is expected to be logical cpuid */
1132 mr r24,r5
11333: HMT_LOW
1134 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1135 /* start. */
1136 sync
1137
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001138#ifndef CONFIG_SMP
1139 b 3b /* Never go on non-SMP */
1140#else
1141 cmpwi 0,r23,0
1142 beq 3b /* Loop until told to go */
1143
1144 /* See if we need to call a cpu state restore handler */
1145 LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
1146 ld r23,0(r23)
1147 ld r23,CPU_SPEC_RESTORE(r23)
1148 cmpdi 0,r23,0
1149 beq 4f
1150 ld r23,0(r23)
1151 mtctr r23
1152 bctrl
1153
11544: /* Create a temp kernel stack for use before relocation is on. */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001155 ld r1,PACAEMERGSP(r13)
1156 subi r1,r1,STACK_FRAME_OVERHEAD
1157
Stephen Rothwellc7056772006-11-27 14:59:50 +11001158 b __secondary_start
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001159#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001160
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001161_STATIC(__mmu_off)
1162 mfmsr r3
1163 andi. r0,r3,MSR_IR|MSR_DR
1164 beqlr
1165 andc r3,r3,r0
1166 mtspr SPRN_SRR0,r4
1167 mtspr SPRN_SRR1,r3
1168 sync
1169 rfid
1170 b . /* prevent speculative execution */
1171
1172
1173/*
1174 * Here is our main kernel entry point. We support currently 2 kind of entries
1175 * depending on the value of r5.
1176 *
1177 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1178 * in r3...r7
1179 *
1180 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1181 * DT block, r4 is a physical pointer to the kernel itself
1182 *
1183 */
1184_GLOBAL(__start_initialization_multiplatform)
1185 /*
1186 * Are we booted from a PROM Of-type client-interface ?
1187 */
1188 cmpldi cr0,r5,0
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001189 beq 1f
1190 b .__boot_from_prom /* yes -> prom */
11911:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001192 /* Save parameters */
1193 mr r31,r3
1194 mr r30,r4
1195
1196 /* Make sure we are running in 64 bits mode */
1197 bl .enable_64b_mode
1198
1199 /* Setup some critical 970 SPRs before switching MMU off */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001200 mfspr r0,SPRN_PVR
1201 srwi r0,r0,16
1202 cmpwi r0,0x39 /* 970 */
1203 beq 1f
1204 cmpwi r0,0x3c /* 970FX */
1205 beq 1f
1206 cmpwi r0,0x44 /* 970MP */
Olof Johansson190a24f2006-10-25 17:32:40 -05001207 beq 1f
1208 cmpwi r0,0x45 /* 970GX */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001209 bne 2f
12101: bl .__cpu_preinit_ppc970
12112:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001212
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001213 /* Switch off MMU if not already */
David Gibsone58c3492006-01-13 14:56:25 +11001214 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001215 add r4,r4,r30
1216 bl .__mmu_off
1217 b .__after_prom_start
1218
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001219_INIT_STATIC(__boot_from_prom)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001220 /* Save parameters */
1221 mr r31,r3
1222 mr r30,r4
1223 mr r29,r5
1224 mr r28,r6
1225 mr r27,r7
1226
Olaf Hering60888572006-03-23 21:50:59 +01001227 /*
1228 * Align the stack to 16-byte boundary
1229 * Depending on the size and layout of the ELF sections in the initial
1230 * boot binary, the stack pointer will be unalignet on PowerMac
1231 */
Linus Torvaldsc05b4772006-03-04 15:00:45 -08001232 rldicr r1,r1,0,59
1233
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001234 /* Make sure we are running in 64 bits mode */
1235 bl .enable_64b_mode
1236
1237 /* put a relocation offset into r3 */
1238 bl .reloc_offset
1239
David Gibsone58c3492006-01-13 14:56:25 +11001240 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001241 addi r2,r2,0x4000
1242 addi r2,r2,0x4000
1243
1244 /* Relocate the TOC from a virt addr to a real addr */
Paul Mackerras5a408322005-10-10 22:41:25 +10001245 add r2,r2,r3
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001246
1247 /* Restore parameters */
1248 mr r3,r31
1249 mr r4,r30
1250 mr r5,r29
1251 mr r6,r28
1252 mr r7,r27
1253
1254 /* Do all of the interaction with OF client interface */
1255 bl .prom_init
1256 /* We never return */
1257 trap
1258
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001259_STATIC(__after_prom_start)
1260
1261/*
Michael Ellerman758438a2005-12-05 15:49:00 -06001262 * We need to run with __start at physical address PHYSICAL_START.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001263 * This will leave some code in the first 256B of
1264 * real memory, which are reserved for software use.
1265 * The remainder of the first page is loaded with the fixed
1266 * interrupt vectors. The next two pages are filled with
1267 * unknown exception placeholders.
1268 *
1269 * Note: This process overwrites the OF exception vectors.
1270 * r26 == relocation offset
1271 * r27 == KERNELBASE
1272 */
1273 bl .reloc_offset
1274 mr r26,r3
David Gibsone58c3492006-01-13 14:56:25 +11001275 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001276
David Gibsone58c3492006-01-13 14:56:25 +11001277 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001278
1279 // XXX FIXME: Use phys returned by OF (r30)
Paul Mackerras5a408322005-10-10 22:41:25 +10001280 add r4,r27,r26 /* source addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001281 /* current address of _start */
1282 /* i.e. where we are running */
1283 /* the source addr */
1284
Jimi Xenidisd0b79c52006-06-26 04:56:58 -04001285 cmpdi r4,0 /* In some cases the loader may */
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001286 bne 1f
1287 b .start_here_multiplatform /* have already put us at zero */
Jimi Xenidisd0b79c52006-06-26 04:56:58 -04001288 /* so we can skip the copy. */
Stephen Rothwell939e60f62007-07-31 16:44:13 +100012891: LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001290 sub r5,r5,r27
1291
1292 li r6,0x100 /* Start offset, the first 0x100 */
1293 /* bytes were copied earlier. */
1294
1295 bl .copy_and_flush /* copy the first n bytes */
1296 /* this includes the code being */
1297 /* executed here. */
1298
David Gibsone58c3492006-01-13 14:56:25 +11001299 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001300 mtctr r0 /* that we just made/relocated */
1301 bctr
1302
David Gibsone58c3492006-01-13 14:56:25 +110013034: LOAD_REG_IMMEDIATE(r5,klimit)
Paul Mackerras5a408322005-10-10 22:41:25 +10001304 add r5,r5,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001305 ld r5,0(r5) /* get the value of klimit */
1306 sub r5,r5,r27
1307 bl .copy_and_flush /* copy the rest */
1308 b .start_here_multiplatform
1309
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001310/*
1311 * Copy routine used to copy the kernel to start at physical address 0
1312 * and flush and invalidate the caches as needed.
1313 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1314 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1315 *
1316 * Note: this routine *only* clobbers r0, r6 and lr
1317 */
1318_GLOBAL(copy_and_flush)
1319 addi r5,r5,-8
1320 addi r6,r6,-8
Olof Johansson5a2fe382006-09-06 14:34:41 -050013214: li r0,8 /* Use the smallest common */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001322 /* denominator cache line */
1323 /* size. This results in */
1324 /* extra cache line flushes */
1325 /* but operation is correct. */
1326 /* Can't get cache line size */
1327 /* from NACA as it is being */
1328 /* moved too. */
1329
1330 mtctr r0 /* put # words/line in ctr */
13313: addi r6,r6,8 /* copy a cache line */
1332 ldx r0,r6,r4
1333 stdx r0,r6,r3
1334 bdnz 3b
1335 dcbst r6,r3 /* write it to memory */
1336 sync
1337 icbi r6,r3 /* flush the icache line */
1338 cmpld 0,r6,r5
1339 blt 4b
1340 sync
1341 addi r5,r5,8
1342 addi r6,r6,8
1343 blr
1344
1345.align 8
1346copy_to_here:
1347
1348#ifdef CONFIG_SMP
1349#ifdef CONFIG_PPC_PMAC
1350/*
1351 * On PowerMac, secondary processors starts from the reset vector, which
1352 * is temporarily turned into a call to one of the functions below.
1353 */
1354 .section ".text";
1355 .align 2 ;
1356
Paul Mackerras35499c02005-10-22 16:02:39 +10001357 .globl __secondary_start_pmac_0
1358__secondary_start_pmac_0:
1359 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1360 li r24,0
1361 b 1f
1362 li r24,1
1363 b 1f
1364 li r24,2
1365 b 1f
1366 li r24,3
13671:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001368
1369_GLOBAL(pmac_secondary_start)
1370 /* turn on 64-bit mode */
1371 bl .enable_64b_mode
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001372
1373 /* Copy some CPU settings from CPU 0 */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001374 bl .__restore_cpu_ppc970
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001375
1376 /* pSeries do that early though I don't think we really need it */
1377 mfmsr r3
1378 ori r3,r3,MSR_RI
1379 mtmsrd r3 /* RI on */
1380
1381 /* Set up a paca value for this processor. */
David Gibsone58c3492006-01-13 14:56:25 +11001382 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001383 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1384 add r13,r13,r4 /* for this processor. */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001385 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001386
1387 /* Create a temp kernel stack for use before relocation is on. */
1388 ld r1,PACAEMERGSP(r13)
1389 subi r1,r1,STACK_FRAME_OVERHEAD
1390
Stephen Rothwellc7056772006-11-27 14:59:50 +11001391 b __secondary_start
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001392
1393#endif /* CONFIG_PPC_PMAC */
1394
1395/*
1396 * This function is called after the master CPU has released the
1397 * secondary processors. The execution environment is relocation off.
1398 * The paca for this processor has the following fields initialized at
1399 * this point:
1400 * 1. Processor number
1401 * 2. Segment table pointer (virtual address)
1402 * On entry the following are set:
1403 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1404 * r24 = cpu# (in Linux terms)
1405 * r13 = paca virtual address
1406 * SPRG3 = paca virtual address
1407 */
Stephen Rothwellfc68e862007-08-22 13:44:58 +10001408 .globl __secondary_start
Stephen Rothwellc7056772006-11-27 14:59:50 +11001409__secondary_start:
Paul Mackerras799d6042005-11-10 13:37:51 +11001410 /* Set thread priority to MEDIUM */
1411 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001412
Paul Mackerras799d6042005-11-10 13:37:51 +11001413 /* Load TOC */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001414 ld r2,PACATOC(r13)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001415
Paul Mackerras799d6042005-11-10 13:37:51 +11001416 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1417 bl .early_setup_secondary
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001418
1419 /* Initialize the kernel stack. Just a repeat for iSeries. */
David Gibsone58c3492006-01-13 14:56:25 +11001420 LOAD_REG_ADDR(r3, current_set)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001421 sldi r28,r24,3 /* get current_set[cpu#] */
1422 ldx r1,r3,r28
1423 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1424 std r1,PACAKSAVE(r13)
1425
Paul Mackerras799d6042005-11-10 13:37:51 +11001426 /* Clear backchain so we get nice backtraces */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001427 li r7,0
1428 mtlr r7
1429
1430 /* enable MMU and jump to start_secondary */
David Gibsone58c3492006-01-13 14:56:25 +11001431 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1432 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001433#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001434BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001435 ori r4,r4,MSR_EE
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001436 li r8,1
1437 stb r8,PACAHARDIRQEN(r13)
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001438END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001439#endif
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001440BEGIN_FW_FTR_SECTION
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001441 stb r7,PACAHARDIRQEN(r13)
1442END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001443 stb r7,PACASOFTIRQEN(r13)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001444
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001445 mtspr SPRN_SRR0,r3
1446 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001447 rfid
1448 b . /* prevent speculative execution */
1449
1450/*
1451 * Running with relocation on at this point. All we want to do is
1452 * zero the stack back-chain pointer before going into C code.
1453 */
1454_GLOBAL(start_secondary_prolog)
1455 li r3,0
1456 std r3,0(r1) /* Zero the stack frame pointer */
1457 bl .start_secondary
Paul Mackerras799d6042005-11-10 13:37:51 +11001458 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001459#endif
1460
1461/*
1462 * This subroutine clobbers r11 and r12
1463 */
1464_GLOBAL(enable_64b_mode)
1465 mfmsr r11 /* grab the current MSR */
1466 li r12,1
1467 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1468 or r11,r11,r12
1469 li r12,1
1470 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1471 or r11,r11,r12
1472 mtmsrd r11
1473 isync
1474 blr
1475
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001476/*
1477 * This is where the main kernel code starts.
1478 */
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001479_INIT_STATIC(start_here_multiplatform)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001480 /* get a new offset, now that the kernel has moved. */
1481 bl .reloc_offset
1482 mr r26,r3
1483
1484 /* Clear out the BSS. It may have been done in prom_init,
1485 * already but that's irrelevant since prom_init will soon
1486 * be detached from the kernel completely. Besides, we need
1487 * to clear it now for kexec-style entry.
1488 */
David Gibsone58c3492006-01-13 14:56:25 +11001489 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1490 LOAD_REG_IMMEDIATE(r8,__bss_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001491 sub r11,r11,r8 /* bss size */
1492 addi r11,r11,7 /* round up to an even double word */
1493 rldicl. r11,r11,61,3 /* shift right by 3 */
1494 beq 4f
1495 addi r8,r8,-8
1496 li r0,0
1497 mtctr r11 /* zero this many doublewords */
14983: stdu r0,8(r8)
1499 bdnz 3b
15004:
1501
1502 mfmsr r6
1503 ori r6,r6,MSR_RI
1504 mtmsrd r6 /* RI on */
1505
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001506 /* The following gets the stack and TOC set up with the regs */
1507 /* pointing to the real addr of the kernel stack. This is */
1508 /* all done to support the C function call below which sets */
1509 /* up the htab. This is done because we have relocated the */
1510 /* kernel but are still running in real mode. */
1511
David Gibsone58c3492006-01-13 14:56:25 +11001512 LOAD_REG_IMMEDIATE(r3,init_thread_union)
Paul Mackerras5a408322005-10-10 22:41:25 +10001513 add r3,r3,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001514
1515 /* set up a stack pointer (physical address) */
1516 addi r1,r3,THREAD_SIZE
1517 li r0,0
1518 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1519
1520 /* set up the TOC (physical address) */
David Gibsone58c3492006-01-13 14:56:25 +11001521 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001522 addi r2,r2,0x4000
1523 addi r2,r2,0x4000
Paul Mackerras5a408322005-10-10 22:41:25 +10001524 add r2,r2,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001525
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001526 /* Do very early kernel initializations, including initial hash table,
1527 * stab and slb setup before we turn on relocation. */
1528
1529 /* Restore parameters passed from prom_init/kexec */
1530 mr r3,r31
1531 bl .early_setup
1532
David Gibsone58c3492006-01-13 14:56:25 +11001533 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1534 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001535 mtspr SPRN_SRR0,r3
1536 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001537 rfid
1538 b . /* prevent speculative execution */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001539
1540 /* This is where all platforms converge execution */
Stephen Rothwellfc68e862007-08-22 13:44:58 +10001541_INIT_GLOBAL(start_here_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001542 /* relocation is on at this point */
1543
1544 /* The following code sets up the SP and TOC now that we are */
1545 /* running with translation enabled. */
1546
David Gibsone58c3492006-01-13 14:56:25 +11001547 LOAD_REG_IMMEDIATE(r3,init_thread_union)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001548
1549 /* set up the stack */
1550 addi r1,r3,THREAD_SIZE
1551 li r0,0
1552 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1553
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001554 /* Load the TOC */
1555 ld r2,PACATOC(r13)
1556 std r1,PACAKSAVE(r13)
1557
1558 bl .setup_system
1559
1560 /* Load up the kernel context */
15615:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001562 li r5,0
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001563 stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
1564#ifdef CONFIG_PPC_ISERIES
1565BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001566 mfmsr r5
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001567 ori r5,r5,MSR_EE /* Hard Enabled on iSeries*/
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001568 mtmsrd r5
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001569 li r5,1
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001570END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001571#endif
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001572 stb r5,PACAHARDIRQEN(r13) /* Hard Disabled on others */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001573
Benjamin Herrenschmidtff3da2e2008-04-02 15:58:40 +11001574 bl .start_kernel
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001575
Anton Blanchardf1870f72006-02-13 18:11:13 +11001576 /* Not reached */
1577 BUG_OPCODE
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001578
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001579/*
1580 * We put a few things here that have to be page-aligned.
1581 * This stuff goes at the beginning of the bss, which is page-aligned.
1582 */
1583 .section ".bss"
1584
1585 .align PAGE_SHIFT
1586
1587 .globl empty_zero_page
1588empty_zero_page:
1589 .space PAGE_SIZE
1590
1591 .globl swapper_pg_dir
1592swapper_pg_dir:
Stephen Rothwellee7a76d2007-09-18 17:22:59 +10001593 .space PGD_TABLE_SIZE