blob: fe6122bfd073130df41217531da526dafb0b9ed2 [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>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100039
Paul Mackerras14cf11a2005-09-26 16:04:21 +100040#define DO_SOFT_DISABLE
Paul Mackerras14cf11a2005-09-26 16:04:21 +100041
42/*
43 * We layout physical memory as follows:
44 * 0x0000 - 0x00ff : Secondary processor spin code
45 * 0x0100 - 0x2fff : pSeries Interrupt prologs
46 * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
47 * 0x6000 - 0x6fff : Initial (CPU0) segment table
48 * 0x7000 - 0x7fff : FWNMI data area
49 * 0x8000 - : Early init and support code
50 */
51
52/*
53 * SPRG Usage
54 *
55 * Register Definition
56 *
57 * SPRG0 reserved for hypervisor
58 * SPRG1 temp - used to save gpr
59 * SPRG2 temp - used to save gpr
60 * SPRG3 virt addr of paca
61 */
62
63/*
64 * Entering into this code we make the following assumptions:
65 * For pSeries:
66 * 1. The MMU is off & open firmware is running in real mode.
67 * 2. The kernel is entered at __start
68 *
69 * For iSeries:
70 * 1. The MMU is on (as it always is for iSeries)
71 * 2. The kernel is entered at system_reset_iSeries
72 */
73
74 .text
75 .globl _stext
76_stext:
Paul Mackerras14cf11a2005-09-26 16:04:21 +100077_GLOBAL(__start)
78 /* NOP this out unconditionally */
79BEGIN_FTR_SECTION
Paul Mackerrasb85a0462005-10-06 10:59:19 +100080 b .__start_initialization_multiplatform
Paul Mackerras14cf11a2005-09-26 16:04:21 +100081END_FTR_SECTION(0, 1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +100082
83 /* Catch branch to 0 in real mode */
84 trap
85
Paul Mackerras14cf11a2005-09-26 16:04:21 +100086 /* Secondary processors spin on this value until it goes to 1. */
87 .globl __secondary_hold_spinloop
88__secondary_hold_spinloop:
89 .llong 0x0
90
91 /* Secondary processors write this value with their cpu # */
92 /* after they enter the spin loop immediately below. */
93 .globl __secondary_hold_acknowledge
94__secondary_hold_acknowledge:
95 .llong 0x0
96
Michael Ellerman1dce0e32006-06-23 18:15:37 +100097#ifdef CONFIG_PPC_ISERIES
98 /*
99 * At offset 0x20, there is a pointer to iSeries LPAR data.
100 * This is required by the hypervisor
101 */
102 . = 0x20
103 .llong hvReleaseData-KERNELBASE
104#endif /* CONFIG_PPC_ISERIES */
105
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000106 . = 0x60
107/*
Geoff Levand75423b72007-06-16 08:06:23 +1000108 * The following code is used to hold secondary processors
109 * in a spin loop after they have entered the kernel, but
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000110 * before the bulk of the kernel has been relocated. This code
111 * is relocated to physical address 0x60 before prom_init is run.
112 * All of it must fit below the first exception vector at 0x100.
113 */
114_GLOBAL(__secondary_hold)
115 mfmsr r24
116 ori r24,r24,MSR_RI
117 mtmsrd r24 /* RI on */
118
Anton Blanchardf1870f72006-02-13 18:11:13 +1100119 /* Grab our physical cpu number */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000120 mr r24,r3
121
122 /* Tell the master cpu we're here */
123 /* Relocation is off & we are located at an address less */
124 /* than 0x100, so only need to grab low order offset. */
125 std r24,__secondary_hold_acknowledge@l(0)
126 sync
127
128 /* All secondary cpus wait here until told to start. */
129100: ld r4,__secondary_hold_spinloop@l(0)
130 cmpdi 0,r4,1
131 bne 100b
132
Anton Blanchardf1870f72006-02-13 18:11:13 +1100133#if defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
Olof Johanssonf39b7a52006-08-11 00:07:08 -0500134 LOAD_REG_IMMEDIATE(r4, .generic_secondary_smp_init)
Michael Ellerman758438a2005-12-05 15:49:00 -0600135 mtctr r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000136 mr r3,r24
Michael Ellerman758438a2005-12-05 15:49:00 -0600137 bctr
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000138#else
139 BUG_OPCODE
140#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000141
142/* This value is used to mark exception frames on the stack. */
143 .section ".toc","aw"
144exception_marker:
145 .tc ID_72656773_68657265[TC],0x7265677368657265
146 .text
147
148/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000149 * This is the start of the interrupt handlers for pSeries
150 * This code runs with relocation off.
151 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000152 . = 0x100
153 .globl __start_interrupts
154__start_interrupts:
155
156 STD_EXCEPTION_PSERIES(0x100, system_reset)
157
158 . = 0x200
159_machine_check_pSeries:
160 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000161 mtspr SPRN_SPRG1,r13 /* save r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000162 EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
163
164 . = 0x300
165 .globl data_access_pSeries
166data_access_pSeries:
167 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000168 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000169BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000170 mtspr SPRN_SPRG2,r12
171 mfspr r13,SPRN_DAR
172 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000173 srdi r13,r13,60
174 rlwimi r13,r12,16,0x20
175 mfcr r12
176 cmpwi r13,0x2c
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100177 beq do_stab_bolted_pSeries
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000178 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000179 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000180END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
181 EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
182
183 . = 0x380
184 .globl data_access_slb_pSeries
185data_access_slb_pSeries:
186 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000187 mtspr SPRN_SPRG1,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000188 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100189 std r3,PACA_EXSLB+EX_R3(r13)
190 mfspr r3,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000191 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100192 mfcr r9
193#ifdef __DISABLED__
194 /* Keep that around for when we re-implement dynamic VSIDs */
195 cmpdi r3,0
196 bge slb_miss_user_pseries
197#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000198 std r10,PACA_EXSLB+EX_R10(r13)
199 std r11,PACA_EXSLB+EX_R11(r13)
200 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100201 mfspr r10,SPRN_SPRG1
202 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000203 mfspr r12,SPRN_SRR1 /* and SRR1 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100204 b .slb_miss_realmode /* Rel. branch works in real mode */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000205
206 STD_EXCEPTION_PSERIES(0x400, instruction_access)
207
208 . = 0x480
209 .globl instruction_access_slb_pSeries
210instruction_access_slb_pSeries:
211 HMT_MEDIUM
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000212 mtspr SPRN_SPRG1,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000213 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100214 std r3,PACA_EXSLB+EX_R3(r13)
215 mfspr r3,SPRN_SRR0 /* SRR0 is faulting address */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000216 std r9,PACA_EXSLB+EX_R9(r13) /* save r9 - r12 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100217 mfcr r9
218#ifdef __DISABLED__
219 /* Keep that around for when we re-implement dynamic VSIDs */
220 cmpdi r3,0
221 bge slb_miss_user_pseries
222#endif /* __DISABLED__ */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000223 std r10,PACA_EXSLB+EX_R10(r13)
224 std r11,PACA_EXSLB+EX_R11(r13)
225 std r12,PACA_EXSLB+EX_R12(r13)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100226 mfspr r10,SPRN_SPRG1
227 std r10,PACA_EXSLB+EX_R13(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000228 mfspr r12,SPRN_SRR1 /* and SRR1 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100229 b .slb_miss_realmode /* Rel. branch works in real mode */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000230
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000231 MASKABLE_EXCEPTION_PSERIES(0x500, hardware_interrupt)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000232 STD_EXCEPTION_PSERIES(0x600, alignment)
233 STD_EXCEPTION_PSERIES(0x700, program_check)
234 STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000235 MASKABLE_EXCEPTION_PSERIES(0x900, decrementer)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000236 STD_EXCEPTION_PSERIES(0xa00, trap_0a)
237 STD_EXCEPTION_PSERIES(0xb00, trap_0b)
238
239 . = 0xc00
240 .globl system_call_pSeries
241system_call_pSeries:
242 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000243 mr r9,r13
244 mfmsr r10
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000245 mfspr r13,SPRN_SPRG3
246 mfspr r11,SPRN_SRR0
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000247 clrrdi r12,r13,32
248 oris r12,r12,system_call_common@h
249 ori r12,r12,system_call_common@l
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000250 mtspr SPRN_SRR0,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000251 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000252 mfspr r12,SPRN_SRR1
253 mtspr SPRN_SRR1,r10
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000254 rfid
255 b . /* prevent speculative execution */
256
257 STD_EXCEPTION_PSERIES(0xd00, single_step)
258 STD_EXCEPTION_PSERIES(0xe00, trap_0e)
259
260 /* We need to deal with the Altivec unavailable exception
261 * here which is at 0xf20, thus in the middle of the
262 * prolog code of the PerformanceMonitor one. A little
263 * trickery is thus necessary
264 */
265 . = 0xf00
266 b performance_monitor_pSeries
267
268 STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
269
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200270#ifdef CONFIG_CBE_RAS
271 HSTD_EXCEPTION_PSERIES(0x1200, cbe_system_error)
272#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000273 STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200274#ifdef CONFIG_CBE_RAS
275 HSTD_EXCEPTION_PSERIES(0x1600, cbe_maintenance)
276#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000277 STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200278#ifdef CONFIG_CBE_RAS
279 HSTD_EXCEPTION_PSERIES(0x1800, cbe_thermal)
280#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000281
282 . = 0x3000
283
284/*** pSeries interrupt support ***/
285
286 /* moved from 0xf00 */
Livio Soares449d8462007-02-07 12:51:36 +1100287 STD_EXCEPTION_PSERIES(., performance_monitor)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000288
289/*
290 * An interrupt came in while soft-disabled; clear EE in SRR1,
291 * clear paca->hard_enabled and return.
292 */
293masked_interrupt:
294 stb r10,PACAHARDIRQEN(r13)
295 mtcrf 0x80,r9
296 ld r9,PACA_EXGEN+EX_R9(r13)
297 mfspr r10,SPRN_SRR1
298 rldicl r10,r10,48,1 /* clear MSR_EE */
299 rotldi r10,r10,16
300 mtspr SPRN_SRR1,r10
301 ld r10,PACA_EXGEN+EX_R10(r13)
302 mfspr r13,SPRN_SPRG1
303 rfid
304 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000305
306 .align 7
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100307do_stab_bolted_pSeries:
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000308 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000309 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000310 EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
311
312/*
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100313 * We have some room here we use that to put
314 * the peries slb miss user trampoline code so it's reasonably
315 * away from slb_miss_user_common to avoid problems with rfid
316 *
317 * This is used for when the SLB miss handler has to go virtual,
318 * which doesn't happen for now anymore but will once we re-implement
319 * dynamic VSIDs for shared page tables
320 */
321#ifdef __DISABLED__
322slb_miss_user_pseries:
323 std r10,PACA_EXGEN+EX_R10(r13)
324 std r11,PACA_EXGEN+EX_R11(r13)
325 std r12,PACA_EXGEN+EX_R12(r13)
326 mfspr r10,SPRG1
327 ld r11,PACA_EXSLB+EX_R9(r13)
328 ld r12,PACA_EXSLB+EX_R3(r13)
329 std r10,PACA_EXGEN+EX_R13(r13)
330 std r11,PACA_EXGEN+EX_R9(r13)
331 std r12,PACA_EXGEN+EX_R3(r13)
332 clrrdi r12,r13,32
333 mfmsr r10
334 mfspr r11,SRR0 /* save SRR0 */
335 ori r12,r12,slb_miss_user_common@l /* virt addr of handler */
336 ori r10,r10,MSR_IR|MSR_DR|MSR_RI
337 mtspr SRR0,r12
338 mfspr r12,SRR1 /* and SRR1 */
339 mtspr SRR1,r10
340 rfid
341 b . /* prevent spec. execution */
342#endif /* __DISABLED__ */
343
344/*
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
361#ifdef CONFIG_PPC_ISERIES
362/*** ISeries-LPAR interrupt handlers ***/
363
364 STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
365
366 .globl data_access_iSeries
367data_access_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000368 mtspr SPRN_SPRG1,r13
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000369BEGIN_FTR_SECTION
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000370 mtspr SPRN_SPRG2,r12
371 mfspr r13,SPRN_DAR
372 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000373 srdi r13,r13,60
374 rlwimi r13,r12,16,0x20
375 mfcr r12
376 cmpwi r13,0x2c
377 beq .do_stab_bolted_iSeries
378 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000379 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000380END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
381 EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
382 EXCEPTION_PROLOG_ISERIES_2
383 b data_access_common
384
385.do_stab_bolted_iSeries:
386 mtcrf 0x80,r12
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000387 mfspr r12,SPRN_SPRG2
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000388 EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
389 EXCEPTION_PROLOG_ISERIES_2
390 b .do_stab_bolted
391
392 .globl data_access_slb_iSeries
393data_access_slb_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000394 mtspr SPRN_SPRG1,r13 /* save r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100395 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000396 std r3,PACA_EXSLB+EX_R3(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000397 mfspr r3,SPRN_DAR
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100398 std r9,PACA_EXSLB+EX_R9(r13)
399 mfcr r9
400#ifdef __DISABLED__
401 cmpdi r3,0
402 bge slb_miss_user_iseries
403#endif
404 std r10,PACA_EXSLB+EX_R10(r13)
405 std r11,PACA_EXSLB+EX_R11(r13)
406 std r12,PACA_EXSLB+EX_R12(r13)
407 mfspr r10,SPRN_SPRG1
408 std r10,PACA_EXSLB+EX_R13(r13)
David Gibson3356bb92006-01-13 10:26:42 +1100409 ld r12,PACALPPACAPTR(r13)
410 ld r12,LPPACASRR1(r12)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100411 b .slb_miss_realmode
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000412
413 STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
414
415 .globl instruction_access_slb_iSeries
416instruction_access_slb_iSeries:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000417 mtspr SPRN_SPRG1,r13 /* save r13 */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100418 mfspr r13,SPRN_SPRG3 /* get paca address into r13 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000419 std r3,PACA_EXSLB+EX_R3(r13)
David Gibson3356bb92006-01-13 10:26:42 +1100420 ld r3,PACALPPACAPTR(r13)
421 ld r3,LPPACASRR0(r3) /* get SRR0 value */
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100422 std r9,PACA_EXSLB+EX_R9(r13)
423 mfcr r9
424#ifdef __DISABLED__
425 cmpdi r3,0
426 bge .slb_miss_user_iseries
427#endif
428 std r10,PACA_EXSLB+EX_R10(r13)
429 std r11,PACA_EXSLB+EX_R11(r13)
430 std r12,PACA_EXSLB+EX_R12(r13)
431 mfspr r10,SPRN_SPRG1
432 std r10,PACA_EXSLB+EX_R13(r13)
David Gibson3356bb92006-01-13 10:26:42 +1100433 ld r12,PACALPPACAPTR(r13)
434 ld r12,LPPACASRR1(r12)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100435 b .slb_miss_realmode
436
437#ifdef __DISABLED__
438slb_miss_user_iseries:
439 std r10,PACA_EXGEN+EX_R10(r13)
440 std r11,PACA_EXGEN+EX_R11(r13)
441 std r12,PACA_EXGEN+EX_R12(r13)
442 mfspr r10,SPRG1
443 ld r11,PACA_EXSLB+EX_R9(r13)
444 ld r12,PACA_EXSLB+EX_R3(r13)
445 std r10,PACA_EXGEN+EX_R13(r13)
446 std r11,PACA_EXGEN+EX_R9(r13)
447 std r12,PACA_EXGEN+EX_R3(r13)
448 EXCEPTION_PROLOG_ISERIES_2
449 b slb_miss_user_common
450#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000451
452 MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
453 STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
454 STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
455 STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
456 MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
457 STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
458 STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
459
460 .globl system_call_iSeries
461system_call_iSeries:
462 mr r9,r13
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000463 mfspr r13,SPRN_SPRG3
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000464 EXCEPTION_PROLOG_ISERIES_2
465 b system_call_common
466
467 STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
468 STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
469 STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
470
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000471decrementer_iSeries_masked:
Michael Ellermanf9b40452006-02-07 13:26:14 +1100472 /* We may not have a valid TOC pointer in here. */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000473 li r11,1
David Gibson3356bb92006-01-13 10:26:42 +1100474 ld r12,PACALPPACAPTR(r13)
475 stb r11,LPPACADECRINT(r12)
Michael Ellermanf9b40452006-02-07 13:26:14 +1100476 LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
477 lwz r12,0(r12)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000478 mtspr SPRN_DEC,r12
479 /* fall through */
480
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000481hardware_interrupt_iSeries_masked:
482 mtcrf 0x80,r9 /* Restore regs */
David Gibson3356bb92006-01-13 10:26:42 +1100483 ld r12,PACALPPACAPTR(r13)
484 ld r11,LPPACASRR0(r12)
485 ld r12,LPPACASRR1(r12)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000486 mtspr SPRN_SRR0,r11
487 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000488 ld r9,PACA_EXGEN+EX_R9(r13)
489 ld r10,PACA_EXGEN+EX_R10(r13)
490 ld r11,PACA_EXGEN+EX_R11(r13)
491 ld r12,PACA_EXGEN+EX_R12(r13)
492 ld r13,PACA_EXGEN+EX_R13(r13)
493 rfid
494 b . /* prevent speculative execution */
495#endif /* CONFIG_PPC_ISERIES */
496
497/*** Common interrupt handlers ***/
498
499 STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
500
501 /*
502 * Machine check is different because we use a different
503 * save area: PACA_EXMC instead of PACA_EXGEN.
504 */
505 .align 7
506 .globl machine_check_common
507machine_check_common:
508 EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000509 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000510 DISABLE_INTS
511 bl .save_nvgprs
512 addi r3,r1,STACK_FRAME_OVERHEAD
513 bl .machine_check_exception
514 b .ret_from_except
515
516 STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
517 STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
518 STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
519 STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
520 STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000521 STD_EXCEPTION_COMMON_IDLE(0xf00, performance_monitor, .performance_monitor_exception)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000522 STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
523#ifdef CONFIG_ALTIVEC
524 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
525#else
526 STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
527#endif
Benjamin Herrenschmidtacf7d762006-06-19 20:33:16 +0200528#ifdef CONFIG_CBE_RAS
529 STD_EXCEPTION_COMMON(0x1200, cbe_system_error, .cbe_system_error_exception)
530 STD_EXCEPTION_COMMON(0x1600, cbe_maintenance, .cbe_maintenance_exception)
531 STD_EXCEPTION_COMMON(0x1800, cbe_thermal, .cbe_thermal_exception)
532#endif /* CONFIG_CBE_RAS */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000533
534/*
535 * Here we have detected that the kernel stack pointer is bad.
536 * R9 contains the saved CR, r13 points to the paca,
537 * r10 contains the (bad) kernel stack pointer,
538 * r11 and r12 contain the saved SRR0 and SRR1.
539 * We switch to using an emergency stack, save the registers there,
540 * and call kernel_bad_stack(), which panics.
541 */
542bad_stack:
543 ld r1,PACAEMERGSP(r13)
544 subi r1,r1,64+INT_FRAME_SIZE
545 std r9,_CCR(r1)
546 std r10,GPR1(r1)
547 std r11,_NIP(r1)
548 std r12,_MSR(r1)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000549 mfspr r11,SPRN_DAR
550 mfspr r12,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000551 std r11,_DAR(r1)
552 std r12,_DSISR(r1)
553 mflr r10
554 mfctr r11
555 mfxer r12
556 std r10,_LINK(r1)
557 std r11,_CTR(r1)
558 std r12,_XER(r1)
559 SAVE_GPR(0,r1)
560 SAVE_GPR(2,r1)
561 SAVE_4GPRS(3,r1)
562 SAVE_2GPRS(7,r1)
563 SAVE_10GPRS(12,r1)
564 SAVE_10GPRS(22,r1)
Olof Johansson68730402007-04-24 01:11:55 +1000565 lhz r12,PACA_TRAP_SAVE(r13)
566 std r12,_TRAP(r1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000567 addi r11,r1,INT_FRAME_SIZE
568 std r11,0(r1)
569 li r12,0
570 std r12,0(r11)
571 ld r2,PACATOC(r13)
5721: addi r3,r1,STACK_FRAME_OVERHEAD
573 bl .kernel_bad_stack
574 b 1b
575
576/*
577 * Return from an exception with minimal checks.
578 * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
579 * If interrupts have been enabled, or anything has been
580 * done that might have changed the scheduling status of
581 * any task or sent any task a signal, you should use
582 * ret_from_except or ret_from_except_lite instead of this.
583 */
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000584fast_exc_return_irq: /* restores irq state too */
585 ld r3,SOFTE(r1)
586 ld r12,_MSR(r1)
587 stb r3,PACASOFTIRQEN(r13) /* restore paca->soft_enabled */
588 rldicl r4,r12,49,63 /* get MSR_EE to LSB */
589 stb r4,PACAHARDIRQEN(r13) /* restore paca->hard_enabled */
590 b 1f
591
Paul Mackerras40ef8cb2005-10-10 22:50:37 +1000592 .globl fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000593fast_exception_return:
594 ld r12,_MSR(r1)
Paul Mackerrasb0a779d2006-10-18 10:11:22 +10005951: ld r11,_NIP(r1)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000596 andi. r3,r12,MSR_RI /* check if RI is set */
597 beq- unrecov_fer
Paul Mackerrasc6622f62006-02-24 10:06:59 +1100598
599#ifdef CONFIG_VIRT_CPU_ACCOUNTING
600 andi. r3,r12,MSR_PR
601 beq 2f
602 ACCOUNT_CPU_USER_EXIT(r3, r4)
6032:
604#endif
605
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000606 ld r3,_CCR(r1)
607 ld r4,_LINK(r1)
608 ld r5,_CTR(r1)
609 ld r6,_XER(r1)
610 mtcr r3
611 mtlr r4
612 mtctr r5
613 mtxer r6
614 REST_GPR(0, r1)
615 REST_8GPRS(2, r1)
616
617 mfmsr r10
Paul Mackerrasd04c56f2006-10-04 16:47:49 +1000618 rldicl r10,r10,48,1 /* clear EE */
619 rldicr r10,r10,16,61 /* clear RI (LE is 0 already) */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000620 mtmsrd r10,1
621
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000622 mtspr SPRN_SRR1,r12
623 mtspr SPRN_SRR0,r11
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000624 REST_4GPRS(10, r1)
625 ld r1,GPR1(r1)
626 rfid
627 b . /* prevent speculative execution */
628
629unrecov_fer:
630 bl .save_nvgprs
6311: addi r3,r1,STACK_FRAME_OVERHEAD
632 bl .unrecoverable_exception
633 b 1b
634
635/*
636 * Here r13 points to the paca, r9 contains the saved CR,
637 * SRR0 and SRR1 are saved in r11 and r12,
638 * r9 - r13 are saved in paca->exgen.
639 */
640 .align 7
641 .globl data_access_common
642data_access_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000643 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000644 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000645 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000646 stw r10,PACA_EXGEN+EX_DSISR(r13)
647 EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
648 ld r3,PACA_EXGEN+EX_DAR(r13)
649 lwz r4,PACA_EXGEN+EX_DSISR(r13)
650 li r5,0x300
651 b .do_hash_page /* Try to handle as hpte fault */
652
653 .align 7
654 .globl instruction_access_common
655instruction_access_common:
656 EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
657 ld r3,_NIP(r1)
658 andis. r4,r12,0x5820
659 li r5,0x400
660 b .do_hash_page /* Try to handle as hpte fault */
661
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100662/*
663 * Here is the common SLB miss user that is used when going to virtual
664 * mode for SLB misses, that is currently not used
665 */
666#ifdef __DISABLED__
667 .align 7
668 .globl slb_miss_user_common
669slb_miss_user_common:
670 mflr r10
671 std r3,PACA_EXGEN+EX_DAR(r13)
672 stw r9,PACA_EXGEN+EX_CCR(r13)
673 std r10,PACA_EXGEN+EX_LR(r13)
674 std r11,PACA_EXGEN+EX_SRR0(r13)
675 bl .slb_allocate_user
676
677 ld r10,PACA_EXGEN+EX_LR(r13)
678 ld r3,PACA_EXGEN+EX_R3(r13)
679 lwz r9,PACA_EXGEN+EX_CCR(r13)
680 ld r11,PACA_EXGEN+EX_SRR0(r13)
681 mtlr r10
682 beq- slb_miss_fault
683
684 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
685 beq- unrecov_user_slb
686 mfmsr r10
687
688.machine push
689.machine "power4"
690 mtcrf 0x80,r9
691.machine pop
692
693 clrrdi r10,r10,2 /* clear RI before setting SRR0/1 */
694 mtmsrd r10,1
695
696 mtspr SRR0,r11
697 mtspr SRR1,r12
698
699 ld r9,PACA_EXGEN+EX_R9(r13)
700 ld r10,PACA_EXGEN+EX_R10(r13)
701 ld r11,PACA_EXGEN+EX_R11(r13)
702 ld r12,PACA_EXGEN+EX_R12(r13)
703 ld r13,PACA_EXGEN+EX_R13(r13)
704 rfid
705 b .
706
707slb_miss_fault:
708 EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
709 ld r4,PACA_EXGEN+EX_DAR(r13)
710 li r5,0
711 std r4,_DAR(r1)
712 std r5,_DSISR(r1)
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100713 b handle_page_fault
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100714
715unrecov_user_slb:
716 EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
717 DISABLE_INTS
718 bl .save_nvgprs
7191: addi r3,r1,STACK_FRAME_OVERHEAD
720 bl .unrecoverable_exception
721 b 1b
722
723#endif /* __DISABLED__ */
724
725
726/*
727 * r13 points to the PACA, r9 contains the saved CR,
728 * r12 contain the saved SRR1, SRR0 is still ready for return
729 * r3 has the faulting address
730 * r9 - r13 are saved in paca->exslb.
731 * r3 is saved in paca->slb_r3
732 * We assume we aren't going to take any exceptions during this procedure.
733 */
734_GLOBAL(slb_miss_realmode)
735 mflr r10
736
737 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
738 std r10,PACA_EXSLB+EX_LR(r13) /* save LR */
739
740 bl .slb_allocate_realmode
741
742 /* All done -- return from exception. */
743
744 ld r10,PACA_EXSLB+EX_LR(r13)
745 ld r3,PACA_EXSLB+EX_R3(r13)
746 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
747#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000748BEGIN_FW_FTR_SECTION
David Gibson3356bb92006-01-13 10:26:42 +1100749 ld r11,PACALPPACAPTR(r13)
750 ld r11,LPPACASRR0(r11) /* get SRR0 value */
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000751END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100752#endif /* CONFIG_PPC_ISERIES */
753
754 mtlr r10
755
756 andi. r10,r12,MSR_RI /* check for unrecoverable exception */
757 beq- unrecov_slb
758
759.machine push
760.machine "power4"
761 mtcrf 0x80,r9
762 mtcrf 0x01,r9 /* slb_allocate uses cr0 and cr7 */
763.machine pop
764
765#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000766BEGIN_FW_FTR_SECTION
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100767 mtspr SPRN_SRR0,r11
768 mtspr SPRN_SRR1,r12
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000769END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Benjamin Herrenschmidt3c726f82005-11-07 11:06:55 +1100770#endif /* CONFIG_PPC_ISERIES */
771 ld r9,PACA_EXSLB+EX_R9(r13)
772 ld r10,PACA_EXSLB+EX_R10(r13)
773 ld r11,PACA_EXSLB+EX_R11(r13)
774 ld r12,PACA_EXSLB+EX_R12(r13)
775 ld r13,PACA_EXSLB+EX_R13(r13)
776 rfid
777 b . /* prevent speculative execution */
778
779unrecov_slb:
780 EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
781 DISABLE_INTS
782 bl .save_nvgprs
7831: addi r3,r1,STACK_FRAME_OVERHEAD
784 bl .unrecoverable_exception
785 b 1b
786
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000787 .align 7
788 .globl hardware_interrupt_common
789 .globl hardware_interrupt_entry
790hardware_interrupt_common:
791 EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000792 FINISH_NAP
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000793hardware_interrupt_entry:
794 DISABLE_INTS
Anton Blanchardcb2c9b22006-02-13 14:48:35 +1100795 bl .ppc64_runlatch_on
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000796 addi r3,r1,STACK_FRAME_OVERHEAD
797 bl .do_IRQ
798 b .ret_from_except_lite
799
Paul Mackerrasf39224a2006-04-18 21:49:11 +1000800#ifdef CONFIG_PPC_970_NAP
801power4_fixup_nap:
802 andc r9,r9,r10
803 std r9,TI_LOCAL_FLAGS(r11)
804 ld r10,_LINK(r1) /* make idle task do the */
805 std r10,_NIP(r1) /* equivalent of a blr */
806 blr
807#endif
808
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000809 .align 7
810 .globl alignment_common
811alignment_common:
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000812 mfspr r10,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000813 std r10,PACA_EXGEN+EX_DAR(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +1000814 mfspr r10,SPRN_DSISR
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000815 stw r10,PACA_EXGEN+EX_DSISR(r13)
816 EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
817 ld r3,PACA_EXGEN+EX_DAR(r13)
818 lwz r4,PACA_EXGEN+EX_DSISR(r13)
819 std r3,_DAR(r1)
820 std r4,_DSISR(r1)
821 bl .save_nvgprs
822 addi r3,r1,STACK_FRAME_OVERHEAD
823 ENABLE_INTS
824 bl .alignment_exception
825 b .ret_from_except
826
827 .align 7
828 .globl program_check_common
829program_check_common:
830 EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
831 bl .save_nvgprs
832 addi r3,r1,STACK_FRAME_OVERHEAD
833 ENABLE_INTS
834 bl .program_check_exception
835 b .ret_from_except
836
837 .align 7
838 .globl fp_unavailable_common
839fp_unavailable_common:
840 EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100841 bne 1f /* if from user, just load it up */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000842 bl .save_nvgprs
843 addi r3,r1,STACK_FRAME_OVERHEAD
844 ENABLE_INTS
845 bl .kernel_fp_unavailable_exception
846 BUG_OPCODE
Paul Mackerras3ccfc652006-11-02 09:44:37 +11008471: b .load_up_fpu
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000848
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000849 .align 7
850 .globl altivec_unavailable_common
851altivec_unavailable_common:
852 EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
853#ifdef CONFIG_ALTIVEC
854BEGIN_FTR_SECTION
855 bne .load_up_altivec /* if from user, just load it up */
856END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
857#endif
858 bl .save_nvgprs
859 addi r3,r1,STACK_FRAME_OVERHEAD
860 ENABLE_INTS
861 bl .altivec_unavailable_exception
862 b .ret_from_except
863
864#ifdef CONFIG_ALTIVEC
865/*
866 * load_up_altivec(unused, unused, tsk)
867 * Disable VMX for the task which had it previously,
868 * and save its vector registers in its thread_struct.
869 * Enables the VMX for use in the kernel on return.
870 * On SMP we know the VMX is free, since we give it up every
871 * switch (ie, no lazy save of the vector registers).
872 * On entry: r13 == 'current' && last_task_used_altivec != 'current'
873 */
874_STATIC(load_up_altivec)
875 mfmsr r5 /* grab the current MSR */
876 oris r5,r5,MSR_VEC@h
877 mtmsrd r5 /* enable use of VMX now */
878 isync
879
880/*
881 * For SMP, we don't do lazy VMX switching because it just gets too
882 * horrendously complex, especially when a task switches from one CPU
883 * to another. Instead we call giveup_altvec in switch_to.
884 * VRSAVE isn't dealt with here, that is done in the normal context
885 * switch code. Note that we could rely on vrsave value to eventually
886 * avoid saving all of the VREGs here...
887 */
888#ifndef CONFIG_SMP
889 ld r3,last_task_used_altivec@got(r2)
890 ld r4,0(r3)
891 cmpdi 0,r4,0
892 beq 1f
893 /* Save VMX state to last_task_used_altivec's THREAD struct */
894 addi r4,r4,THREAD
895 SAVE_32VRS(0,r5,r4)
896 mfvscr vr0
897 li r10,THREAD_VSCR
898 stvx vr0,r10,r4
899 /* Disable VMX for last_task_used_altivec */
900 ld r5,PT_REGS(r4)
901 ld r4,_MSR-STACK_FRAME_OVERHEAD(r5)
902 lis r6,MSR_VEC@h
903 andc r4,r4,r6
904 std r4,_MSR-STACK_FRAME_OVERHEAD(r5)
9051:
906#endif /* CONFIG_SMP */
907 /* Hack: if we get an altivec unavailable trap with VRSAVE
908 * set to all zeros, we assume this is a broken application
909 * that fails to set it properly, and thus we switch it to
910 * all 1's
911 */
912 mfspr r4,SPRN_VRSAVE
913 cmpdi 0,r4,0
914 bne+ 1f
915 li r4,-1
916 mtspr SPRN_VRSAVE,r4
9171:
918 /* enable use of VMX after return */
919 ld r4,PACACURRENT(r13)
920 addi r5,r4,THREAD /* Get THREAD */
921 oris r12,r12,MSR_VEC@h
922 std r12,_MSR(r1)
923 li r4,1
924 li r10,THREAD_VSCR
925 stw r4,THREAD_USED_VR(r5)
926 lvx vr0,r10,r5
927 mtvscr vr0
928 REST_32VRS(0,r4,r5)
929#ifndef CONFIG_SMP
930 /* Update last_task_used_math to 'current' */
931 subi r4,r5,THREAD /* Back to 'current' */
932 std r4,0(r3)
933#endif /* CONFIG_SMP */
934 /* restore registers and return */
935 b fast_exception_return
936#endif /* CONFIG_ALTIVEC */
937
938/*
939 * Hash table stuff
940 */
941 .align 7
942_GLOBAL(do_hash_page)
943 std r3,_DAR(r1)
944 std r4,_DSISR(r1)
945
946 andis. r0,r4,0xa450 /* weird error? */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100947 bne- handle_page_fault /* if not, try to insert a HPTE */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000948BEGIN_FTR_SECTION
949 andis. r0,r4,0x0020 /* Is it a segment table fault? */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100950 bne- do_ste_alloc /* If so handle it */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000951END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
952
953 /*
954 * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
955 * accessing a userspace segment (even from the kernel). We assume
956 * kernel addresses always have the high bit set.
957 */
958 rlwinm r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
959 rotldi r0,r3,15 /* Move high bit into MSR_PR posn */
960 orc r0,r12,r0 /* MSR_PR | ~high_bit */
961 rlwimi r4,r0,32-13,30,30 /* becomes _PAGE_USER access bit */
962 ori r4,r4,1 /* add _PAGE_PRESENT */
963 rlwimi r4,r5,22+2,31-2,31-2 /* Set _PAGE_EXEC if trap is 0x400 */
964
965 /*
966 * On iSeries, we soft-disable interrupts here, then
967 * hard-enable interrupts so that the hash_page code can spin on
968 * the hash_table_lock without problems on a shared processor.
969 */
970 DISABLE_INTS
971
972 /*
973 * r3 contains the faulting address
974 * r4 contains the required access permissions
975 * r5 contains the trap number
976 *
977 * at return r3 = 0 for success
978 */
979 bl .hash_page /* build HPTE if possible */
980 cmpdi r3,0 /* see if hash_page succeeded */
981
982#ifdef DO_SOFT_DISABLE
Stephen Rothwell3f639ee2006-09-25 18:19:00 +1000983BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000984 /*
985 * If we had interrupts soft-enabled at the point where the
986 * DSI/ISI occurred, and an interrupt came in during hash_page,
987 * handle it now.
988 * We jump to ret_from_except_lite rather than fast_exception_return
989 * because ret_from_except_lite will check for and handle pending
990 * interrupts if necessary.
991 */
Paul Mackerras3ccfc652006-11-02 09:44:37 +1100992 beq 13f
Paul Mackerrasb0a779d2006-10-18 10:11:22 +1000993END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
994#endif
995BEGIN_FW_FTR_SECTION
996 /*
997 * Here we have interrupts hard-disabled, so it is sufficient
998 * to restore paca->{soft,hard}_enable and get out.
999 */
1000 beq fast_exc_return_irq /* Return from exception on success */
1001END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1002
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001003 /* For a hash failure, we don't bother re-enabling interrupts */
1004 ble- 12f
1005
1006 /*
1007 * hash_page couldn't handle it, set soft interrupt enable back
1008 * to what it was before the trap. Note that .local_irq_restore
1009 * handles any interrupts pending at this point.
1010 */
1011 ld r3,SOFTE(r1)
1012 bl .local_irq_restore
1013 b 11f
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001014
1015/* Here we have a page fault that hash_page can't handle. */
Paul Mackerras3ccfc652006-11-02 09:44:37 +11001016handle_page_fault:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001017 ENABLE_INTS
101811: ld r4,_DAR(r1)
1019 ld r5,_DSISR(r1)
1020 addi r3,r1,STACK_FRAME_OVERHEAD
1021 bl .do_page_fault
1022 cmpdi r3,0
Paul Mackerras3ccfc652006-11-02 09:44:37 +11001023 beq+ 13f
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001024 bl .save_nvgprs
1025 mr r5,r3
1026 addi r3,r1,STACK_FRAME_OVERHEAD
1027 lwz r4,_DAR(r1)
1028 bl .bad_page_fault
1029 b .ret_from_except
1030
Paul Mackerras79acbb32006-12-04 15:59:07 +1100103113: b .ret_from_except_lite
1032
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001033/* We have a page fault that hash_page could handle but HV refused
1034 * the PTE insertion
1035 */
103612: bl .save_nvgprs
1037 addi r3,r1,STACK_FRAME_OVERHEAD
1038 lwz r4,_DAR(r1)
1039 bl .low_hash_fault
1040 b .ret_from_except
1041
1042 /* here we have a segment miss */
Paul Mackerras3ccfc652006-11-02 09:44:37 +11001043do_ste_alloc:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001044 bl .ste_allocate /* try to insert stab entry */
1045 cmpdi r3,0
Paul Mackerras3ccfc652006-11-02 09:44:37 +11001046 bne- handle_page_fault
1047 b fast_exception_return
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001048
1049/*
1050 * r13 points to the PACA, r9 contains the saved CR,
1051 * r11 and r12 contain the saved SRR0 and SRR1.
1052 * r9 - r13 are saved in paca->exslb.
1053 * We assume we aren't going to take any exceptions during this procedure.
1054 * We assume (DAR >> 60) == 0xc.
1055 */
1056 .align 7
1057_GLOBAL(do_stab_bolted)
1058 stw r9,PACA_EXSLB+EX_CCR(r13) /* save CR in exc. frame */
1059 std r11,PACA_EXSLB+EX_SRR0(r13) /* save SRR0 in exc. frame */
1060
1061 /* Hash to the primary group */
1062 ld r10,PACASTABVIRT(r13)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001063 mfspr r11,SPRN_DAR
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001064 srdi r11,r11,28
1065 rldimi r10,r11,7,52 /* r10 = first ste of the group */
1066
1067 /* Calculate VSID */
1068 /* This is a kernel address, so protovsid = ESID */
1069 ASM_VSID_SCRAMBLE(r11, r9)
1070 rldic r9,r11,12,16 /* r9 = vsid << 12 */
1071
1072 /* Search the primary group for a free entry */
10731: ld r11,0(r10) /* Test valid bit of the current ste */
1074 andi. r11,r11,0x80
1075 beq 2f
1076 addi r10,r10,16
1077 andi. r11,r10,0x70
1078 bne 1b
1079
1080 /* Stick for only searching the primary group for now. */
1081 /* At least for now, we use a very simple random castout scheme */
1082 /* Use the TB as a random number ; OR in 1 to avoid entry 0 */
1083 mftb r11
1084 rldic r11,r11,4,57 /* r11 = (r11 << 4) & 0x70 */
1085 ori r11,r11,0x10
1086
1087 /* r10 currently points to an ste one past the group of interest */
1088 /* make it point to the randomly selected entry */
1089 subi r10,r10,128
1090 or r10,r10,r11 /* r10 is the entry to invalidate */
1091
1092 isync /* mark the entry invalid */
1093 ld r11,0(r10)
1094 rldicl r11,r11,56,1 /* clear the valid bit */
1095 rotldi r11,r11,8
1096 std r11,0(r10)
1097 sync
1098
1099 clrrdi r11,r11,28 /* Get the esid part of the ste */
1100 slbie r11
1101
11022: std r9,8(r10) /* Store the vsid part of the ste */
1103 eieio
1104
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001105 mfspr r11,SPRN_DAR /* Get the new esid */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001106 clrrdi r11,r11,28 /* Permits a full 32b of ESID */
1107 ori r11,r11,0x90 /* Turn on valid and kp */
1108 std r11,0(r10) /* Put new entry back into the stab */
1109
1110 sync
1111
1112 /* All done -- return from exception. */
1113 lwz r9,PACA_EXSLB+EX_CCR(r13) /* get saved CR */
1114 ld r11,PACA_EXSLB+EX_SRR0(r13) /* get saved SRR0 */
1115
1116 andi. r10,r12,MSR_RI
1117 beq- unrecov_slb
1118
1119 mtcrf 0x80,r9 /* restore CR */
1120
1121 mfmsr r10
1122 clrrdi r10,r10,2
1123 mtmsrd r10,1
1124
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001125 mtspr SPRN_SRR0,r11
1126 mtspr SPRN_SRR1,r12
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001127 ld r9,PACA_EXSLB+EX_R9(r13)
1128 ld r10,PACA_EXSLB+EX_R10(r13)
1129 ld r11,PACA_EXSLB+EX_R11(r13)
1130 ld r12,PACA_EXSLB+EX_R12(r13)
1131 ld r13,PACA_EXSLB+EX_R13(r13)
1132 rfid
1133 b . /* prevent speculative execution */
1134
1135/*
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001136 * Space for CPU0's segment table.
1137 *
1138 * On iSeries, the hypervisor must fill in at least one entry before
Stephen Rothwell16a15a32007-08-20 14:58:36 +10001139 * we get control (with relocate on). The address is given to the hv
1140 * as a page number (see xLparMap below), so this must be at a
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001141 * fixed address (the linker can't compute (u64)&initial_stab >>
1142 * PAGE_SHIFT).
1143 */
Michael Ellerman758438a2005-12-05 15:49:00 -06001144 . = STAB0_OFFSET /* 0x6000 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001145 .globl initial_stab
1146initial_stab:
1147 .space 4096
1148
1149/*
1150 * Data area reserved for FWNMI option.
1151 * This address (0x7000) is fixed by the RPA.
1152 */
1153 .= 0x7000
1154 .globl fwnmi_data_area
1155fwnmi_data_area:
1156
1157 /* iSeries does not use the FWNMI stuff, so it is safe to put
1158 * this here, even if we later allow kernels that will boot on
1159 * both pSeries and iSeries */
1160#ifdef CONFIG_PPC_ISERIES
1161 . = LPARMAP_PHYS
Stephen Rothwell16a15a32007-08-20 14:58:36 +10001162 .globl xLparMap
1163xLparMap:
1164 .quad HvEsidsToMap /* xNumberEsids */
1165 .quad HvRangesToMap /* xNumberRanges */
1166 .quad STAB0_PAGE /* xSegmentTableOffs */
1167 .zero 40 /* xRsvd */
1168 /* xEsids (HvEsidsToMap entries of 2 quads) */
1169 .quad PAGE_OFFSET_ESID /* xKernelEsid */
1170 .quad PAGE_OFFSET_VSID /* xKernelVsid */
1171 .quad VMALLOC_START_ESID /* xKernelEsid */
1172 .quad VMALLOC_START_VSID /* xKernelVsid */
1173 /* xRanges (HvRangesToMap entries of 3 quads) */
1174 .quad HvPagesToMap /* xPages */
1175 .quad 0 /* xOffset */
1176 .quad PAGE_OFFSET_VSID << (SID_SHIFT - HW_PAGE_SHIFT) /* xVPN */
1177
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001178#endif /* CONFIG_PPC_ISERIES */
1179
1180 . = 0x8000
1181
1182/*
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001183 * On pSeries and most other platforms, secondary processors spin
1184 * in the following code.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001185 * At entry, r3 = this processor's number (physical cpu id)
1186 */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001187_GLOBAL(generic_secondary_smp_init)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001188 mr r24,r3
1189
1190 /* turn on 64-bit mode */
1191 bl .enable_64b_mode
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001192
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001193 /* Set up a paca value for this processor. Since we have the
1194 * physical cpu id in r24, we need to search the pacas to find
1195 * which logical id maps to our physical one.
1196 */
David Gibsone58c3492006-01-13 14:56:25 +11001197 LOAD_REG_IMMEDIATE(r13, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001198 li r5,0 /* logical cpu id */
11991: lhz r6,PACAHWCPUID(r13) /* Load HW procid from paca */
1200 cmpw r6,r24 /* Compare to our id */
1201 beq 2f
1202 addi r13,r13,PACA_SIZE /* Loop to next PACA on miss */
1203 addi r5,r5,1
1204 cmpwi r5,NR_CPUS
1205 blt 1b
1206
1207 mr r3,r24 /* not found, copy phys to r3 */
1208 b .kexec_wait /* next kernel might do better */
1209
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +100012102: mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001211 /* From now on, r24 is expected to be logical cpuid */
1212 mr r24,r5
12133: HMT_LOW
1214 lbz r23,PACAPROCSTART(r13) /* Test if this processor should */
1215 /* start. */
1216 sync
1217
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001218#ifndef CONFIG_SMP
1219 b 3b /* Never go on non-SMP */
1220#else
1221 cmpwi 0,r23,0
1222 beq 3b /* Loop until told to go */
1223
1224 /* See if we need to call a cpu state restore handler */
1225 LOAD_REG_IMMEDIATE(r23, cur_cpu_spec)
1226 ld r23,0(r23)
1227 ld r23,CPU_SPEC_RESTORE(r23)
1228 cmpdi 0,r23,0
1229 beq 4f
1230 ld r23,0(r23)
1231 mtctr r23
1232 bctrl
1233
12344: /* Create a temp kernel stack for use before relocation is on. */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001235 ld r1,PACAEMERGSP(r13)
1236 subi r1,r1,STACK_FRAME_OVERHEAD
1237
Stephen Rothwellc7056772006-11-27 14:59:50 +11001238 b __secondary_start
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001239#endif
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001240
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001241_STATIC(__mmu_off)
1242 mfmsr r3
1243 andi. r0,r3,MSR_IR|MSR_DR
1244 beqlr
1245 andc r3,r3,r0
1246 mtspr SPRN_SRR0,r4
1247 mtspr SPRN_SRR1,r3
1248 sync
1249 rfid
1250 b . /* prevent speculative execution */
1251
1252
1253/*
1254 * Here is our main kernel entry point. We support currently 2 kind of entries
1255 * depending on the value of r5.
1256 *
1257 * r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1258 * in r3...r7
1259 *
1260 * r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1261 * DT block, r4 is a physical pointer to the kernel itself
1262 *
1263 */
1264_GLOBAL(__start_initialization_multiplatform)
1265 /*
1266 * Are we booted from a PROM Of-type client-interface ?
1267 */
1268 cmpldi cr0,r5,0
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001269 beq 1f
1270 b .__boot_from_prom /* yes -> prom */
12711:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001272 /* Save parameters */
1273 mr r31,r3
1274 mr r30,r4
1275
1276 /* Make sure we are running in 64 bits mode */
1277 bl .enable_64b_mode
1278
1279 /* Setup some critical 970 SPRs before switching MMU off */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001280 mfspr r0,SPRN_PVR
1281 srwi r0,r0,16
1282 cmpwi r0,0x39 /* 970 */
1283 beq 1f
1284 cmpwi r0,0x3c /* 970FX */
1285 beq 1f
1286 cmpwi r0,0x44 /* 970MP */
Olof Johansson190a24f2006-10-25 17:32:40 -05001287 beq 1f
1288 cmpwi r0,0x45 /* 970GX */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001289 bne 2f
12901: bl .__cpu_preinit_ppc970
12912:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001292
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001293 /* Switch off MMU if not already */
David Gibsone58c3492006-01-13 14:56:25 +11001294 LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001295 add r4,r4,r30
1296 bl .__mmu_off
1297 b .__after_prom_start
1298
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001299_INIT_STATIC(__boot_from_prom)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001300 /* Save parameters */
1301 mr r31,r3
1302 mr r30,r4
1303 mr r29,r5
1304 mr r28,r6
1305 mr r27,r7
1306
Olaf Hering60888572006-03-23 21:50:59 +01001307 /*
1308 * Align the stack to 16-byte boundary
1309 * Depending on the size and layout of the ELF sections in the initial
1310 * boot binary, the stack pointer will be unalignet on PowerMac
1311 */
Linus Torvaldsc05b4772006-03-04 15:00:45 -08001312 rldicr r1,r1,0,59
1313
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001314 /* Make sure we are running in 64 bits mode */
1315 bl .enable_64b_mode
1316
1317 /* put a relocation offset into r3 */
1318 bl .reloc_offset
1319
David Gibsone58c3492006-01-13 14:56:25 +11001320 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001321 addi r2,r2,0x4000
1322 addi r2,r2,0x4000
1323
1324 /* Relocate the TOC from a virt addr to a real addr */
Paul Mackerras5a408322005-10-10 22:41:25 +10001325 add r2,r2,r3
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001326
1327 /* Restore parameters */
1328 mr r3,r31
1329 mr r4,r30
1330 mr r5,r29
1331 mr r6,r28
1332 mr r7,r27
1333
1334 /* Do all of the interaction with OF client interface */
1335 bl .prom_init
1336 /* We never return */
1337 trap
1338
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001339_STATIC(__after_prom_start)
1340
1341/*
Michael Ellerman758438a2005-12-05 15:49:00 -06001342 * We need to run with __start at physical address PHYSICAL_START.
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001343 * This will leave some code in the first 256B of
1344 * real memory, which are reserved for software use.
1345 * The remainder of the first page is loaded with the fixed
1346 * interrupt vectors. The next two pages are filled with
1347 * unknown exception placeholders.
1348 *
1349 * Note: This process overwrites the OF exception vectors.
1350 * r26 == relocation offset
1351 * r27 == KERNELBASE
1352 */
1353 bl .reloc_offset
1354 mr r26,r3
David Gibsone58c3492006-01-13 14:56:25 +11001355 LOAD_REG_IMMEDIATE(r27, KERNELBASE)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001356
David Gibsone58c3492006-01-13 14:56:25 +11001357 LOAD_REG_IMMEDIATE(r3, PHYSICAL_START) /* target addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001358
1359 // XXX FIXME: Use phys returned by OF (r30)
Paul Mackerras5a408322005-10-10 22:41:25 +10001360 add r4,r27,r26 /* source addr */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001361 /* current address of _start */
1362 /* i.e. where we are running */
1363 /* the source addr */
1364
Jimi Xenidisd0b79c52006-06-26 04:56:58 -04001365 cmpdi r4,0 /* In some cases the loader may */
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001366 bne 1f
1367 b .start_here_multiplatform /* have already put us at zero */
Jimi Xenidisd0b79c52006-06-26 04:56:58 -04001368 /* so we can skip the copy. */
Stephen Rothwell939e60f62007-07-31 16:44:13 +100013691: LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001370 sub r5,r5,r27
1371
1372 li r6,0x100 /* Start offset, the first 0x100 */
1373 /* bytes were copied earlier. */
1374
1375 bl .copy_and_flush /* copy the first n bytes */
1376 /* this includes the code being */
1377 /* executed here. */
1378
David Gibsone58c3492006-01-13 14:56:25 +11001379 LOAD_REG_IMMEDIATE(r0, 4f) /* Jump to the copy of this code */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001380 mtctr r0 /* that we just made/relocated */
1381 bctr
1382
David Gibsone58c3492006-01-13 14:56:25 +110013834: LOAD_REG_IMMEDIATE(r5,klimit)
Paul Mackerras5a408322005-10-10 22:41:25 +10001384 add r5,r5,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001385 ld r5,0(r5) /* get the value of klimit */
1386 sub r5,r5,r27
1387 bl .copy_and_flush /* copy the rest */
1388 b .start_here_multiplatform
1389
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001390/*
1391 * Copy routine used to copy the kernel to start at physical address 0
1392 * and flush and invalidate the caches as needed.
1393 * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1394 * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1395 *
1396 * Note: this routine *only* clobbers r0, r6 and lr
1397 */
1398_GLOBAL(copy_and_flush)
1399 addi r5,r5,-8
1400 addi r6,r6,-8
Olof Johansson5a2fe382006-09-06 14:34:41 -050014014: li r0,8 /* Use the smallest common */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001402 /* denominator cache line */
1403 /* size. This results in */
1404 /* extra cache line flushes */
1405 /* but operation is correct. */
1406 /* Can't get cache line size */
1407 /* from NACA as it is being */
1408 /* moved too. */
1409
1410 mtctr r0 /* put # words/line in ctr */
14113: addi r6,r6,8 /* copy a cache line */
1412 ldx r0,r6,r4
1413 stdx r0,r6,r3
1414 bdnz 3b
1415 dcbst r6,r3 /* write it to memory */
1416 sync
1417 icbi r6,r3 /* flush the icache line */
1418 cmpld 0,r6,r5
1419 blt 4b
1420 sync
1421 addi r5,r5,8
1422 addi r6,r6,8
1423 blr
1424
1425.align 8
1426copy_to_here:
1427
1428#ifdef CONFIG_SMP
1429#ifdef CONFIG_PPC_PMAC
1430/*
1431 * On PowerMac, secondary processors starts from the reset vector, which
1432 * is temporarily turned into a call to one of the functions below.
1433 */
1434 .section ".text";
1435 .align 2 ;
1436
Paul Mackerras35499c02005-10-22 16:02:39 +10001437 .globl __secondary_start_pmac_0
1438__secondary_start_pmac_0:
1439 /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1440 li r24,0
1441 b 1f
1442 li r24,1
1443 b 1f
1444 li r24,2
1445 b 1f
1446 li r24,3
14471:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001448
1449_GLOBAL(pmac_secondary_start)
1450 /* turn on 64-bit mode */
1451 bl .enable_64b_mode
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001452
1453 /* Copy some CPU settings from CPU 0 */
Olof Johanssonf39b7a52006-08-11 00:07:08 -05001454 bl .__restore_cpu_ppc970
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001455
1456 /* pSeries do that early though I don't think we really need it */
1457 mfmsr r3
1458 ori r3,r3,MSR_RI
1459 mtmsrd r3 /* RI on */
1460
1461 /* Set up a paca value for this processor. */
David Gibsone58c3492006-01-13 14:56:25 +11001462 LOAD_REG_IMMEDIATE(r4, paca) /* Get base vaddr of paca array */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001463 mulli r13,r24,PACA_SIZE /* Calculate vaddr of right paca */
1464 add r13,r13,r4 /* for this processor. */
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001465 mtspr SPRN_SPRG3,r13 /* Save vaddr of paca in SPRG3 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001466
1467 /* Create a temp kernel stack for use before relocation is on. */
1468 ld r1,PACAEMERGSP(r13)
1469 subi r1,r1,STACK_FRAME_OVERHEAD
1470
Stephen Rothwellc7056772006-11-27 14:59:50 +11001471 b __secondary_start
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001472
1473#endif /* CONFIG_PPC_PMAC */
1474
1475/*
1476 * This function is called after the master CPU has released the
1477 * secondary processors. The execution environment is relocation off.
1478 * The paca for this processor has the following fields initialized at
1479 * this point:
1480 * 1. Processor number
1481 * 2. Segment table pointer (virtual address)
1482 * On entry the following are set:
1483 * r1 = stack pointer. vaddr for iSeries, raddr (temp stack) for pSeries
1484 * r24 = cpu# (in Linux terms)
1485 * r13 = paca virtual address
1486 * SPRG3 = paca virtual address
1487 */
Stephen Rothwellfc68e862007-08-22 13:44:58 +10001488 .globl __secondary_start
Stephen Rothwellc7056772006-11-27 14:59:50 +11001489__secondary_start:
Paul Mackerras799d6042005-11-10 13:37:51 +11001490 /* Set thread priority to MEDIUM */
1491 HMT_MEDIUM
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001492
Paul Mackerras799d6042005-11-10 13:37:51 +11001493 /* Load TOC */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001494 ld r2,PACATOC(r13)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001495
Paul Mackerras799d6042005-11-10 13:37:51 +11001496 /* Do early setup for that CPU (stab, slb, hash table pointer) */
1497 bl .early_setup_secondary
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001498
1499 /* Initialize the kernel stack. Just a repeat for iSeries. */
David Gibsone58c3492006-01-13 14:56:25 +11001500 LOAD_REG_ADDR(r3, current_set)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001501 sldi r28,r24,3 /* get current_set[cpu#] */
1502 ldx r1,r3,r28
1503 addi r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1504 std r1,PACAKSAVE(r13)
1505
Paul Mackerras799d6042005-11-10 13:37:51 +11001506 /* Clear backchain so we get nice backtraces */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001507 li r7,0
1508 mtlr r7
1509
1510 /* enable MMU and jump to start_secondary */
David Gibsone58c3492006-01-13 14:56:25 +11001511 LOAD_REG_ADDR(r3, .start_secondary_prolog)
1512 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001513#ifdef CONFIG_PPC_ISERIES
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001514BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001515 ori r4,r4,MSR_EE
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001516END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001517#endif
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001518BEGIN_FW_FTR_SECTION
1519 stb r7,PACASOFTIRQEN(r13)
1520 stb r7,PACAHARDIRQEN(r13)
1521END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
1522
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001523 mtspr SPRN_SRR0,r3
1524 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001525 rfid
1526 b . /* prevent speculative execution */
1527
1528/*
1529 * Running with relocation on at this point. All we want to do is
1530 * zero the stack back-chain pointer before going into C code.
1531 */
1532_GLOBAL(start_secondary_prolog)
1533 li r3,0
1534 std r3,0(r1) /* Zero the stack frame pointer */
1535 bl .start_secondary
Paul Mackerras799d6042005-11-10 13:37:51 +11001536 b .
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001537#endif
1538
1539/*
1540 * This subroutine clobbers r11 and r12
1541 */
1542_GLOBAL(enable_64b_mode)
1543 mfmsr r11 /* grab the current MSR */
1544 li r12,1
1545 rldicr r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1546 or r11,r11,r12
1547 li r12,1
1548 rldicr r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1549 or r11,r11,r12
1550 mtmsrd r11
1551 isync
1552 blr
1553
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001554/*
1555 * This is where the main kernel code starts.
1556 */
Stephen Rothwell939e60f62007-07-31 16:44:13 +10001557_INIT_STATIC(start_here_multiplatform)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001558 /* get a new offset, now that the kernel has moved. */
1559 bl .reloc_offset
1560 mr r26,r3
1561
1562 /* Clear out the BSS. It may have been done in prom_init,
1563 * already but that's irrelevant since prom_init will soon
1564 * be detached from the kernel completely. Besides, we need
1565 * to clear it now for kexec-style entry.
1566 */
David Gibsone58c3492006-01-13 14:56:25 +11001567 LOAD_REG_IMMEDIATE(r11,__bss_stop)
1568 LOAD_REG_IMMEDIATE(r8,__bss_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001569 sub r11,r11,r8 /* bss size */
1570 addi r11,r11,7 /* round up to an even double word */
1571 rldicl. r11,r11,61,3 /* shift right by 3 */
1572 beq 4f
1573 addi r8,r8,-8
1574 li r0,0
1575 mtctr r11 /* zero this many doublewords */
15763: stdu r0,8(r8)
1577 bdnz 3b
15784:
1579
1580 mfmsr r6
1581 ori r6,r6,MSR_RI
1582 mtmsrd r6 /* RI on */
1583
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001584 /* The following gets the stack and TOC set up with the regs */
1585 /* pointing to the real addr of the kernel stack. This is */
1586 /* all done to support the C function call below which sets */
1587 /* up the htab. This is done because we have relocated the */
1588 /* kernel but are still running in real mode. */
1589
David Gibsone58c3492006-01-13 14:56:25 +11001590 LOAD_REG_IMMEDIATE(r3,init_thread_union)
Paul Mackerras5a408322005-10-10 22:41:25 +10001591 add r3,r3,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001592
1593 /* set up a stack pointer (physical address) */
1594 addi r1,r3,THREAD_SIZE
1595 li r0,0
1596 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1597
1598 /* set up the TOC (physical address) */
David Gibsone58c3492006-01-13 14:56:25 +11001599 LOAD_REG_IMMEDIATE(r2,__toc_start)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001600 addi r2,r2,0x4000
1601 addi r2,r2,0x4000
Paul Mackerras5a408322005-10-10 22:41:25 +10001602 add r2,r2,r26
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001603
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001604 /* Do very early kernel initializations, including initial hash table,
1605 * stab and slb setup before we turn on relocation. */
1606
1607 /* Restore parameters passed from prom_init/kexec */
1608 mr r3,r31
1609 bl .early_setup
1610
David Gibsone58c3492006-01-13 14:56:25 +11001611 LOAD_REG_IMMEDIATE(r3, .start_here_common)
1612 LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
Paul Mackerrasb5bbeb22005-10-10 14:01:07 +10001613 mtspr SPRN_SRR0,r3
1614 mtspr SPRN_SRR1,r4
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001615 rfid
1616 b . /* prevent speculative execution */
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001617
1618 /* This is where all platforms converge execution */
Stephen Rothwellfc68e862007-08-22 13:44:58 +10001619_INIT_GLOBAL(start_here_common)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001620 /* relocation is on at this point */
1621
1622 /* The following code sets up the SP and TOC now that we are */
1623 /* running with translation enabled. */
1624
David Gibsone58c3492006-01-13 14:56:25 +11001625 LOAD_REG_IMMEDIATE(r3,init_thread_union)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001626
1627 /* set up the stack */
1628 addi r1,r3,THREAD_SIZE
1629 li r0,0
1630 stdu r0,-STACK_FRAME_OVERHEAD(r1)
1631
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001632 /* ptr to current */
David Gibsone58c3492006-01-13 14:56:25 +11001633 LOAD_REG_IMMEDIATE(r4, init_task)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001634 std r4,PACACURRENT(r13)
1635
1636 /* Load the TOC */
1637 ld r2,PACATOC(r13)
1638 std r1,PACAKSAVE(r13)
1639
1640 bl .setup_system
1641
1642 /* Load up the kernel context */
16435:
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001644 li r5,0
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001645 stb r5,PACASOFTIRQEN(r13) /* Soft Disabled */
1646#ifdef CONFIG_PPC_ISERIES
1647BEGIN_FW_FTR_SECTION
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001648 mfmsr r5
1649 ori r5,r5,MSR_EE /* Hard Enabled */
1650 mtmsrd r5
Stephen Rothwell3f639ee2006-09-25 18:19:00 +10001651END_FW_FTR_SECTION_IFSET(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001652#endif
Paul Mackerrasd04c56f2006-10-04 16:47:49 +10001653BEGIN_FW_FTR_SECTION
1654 stb r5,PACAHARDIRQEN(r13)
1655END_FW_FTR_SECTION_IFCLR(FW_FEATURE_ISERIES)
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001656
1657 bl .start_kernel
1658
Anton Blanchardf1870f72006-02-13 18:11:13 +11001659 /* Not reached */
1660 BUG_OPCODE
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001661
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001662/*
1663 * We put a few things here that have to be page-aligned.
1664 * This stuff goes at the beginning of the bss, which is page-aligned.
1665 */
1666 .section ".bss"
1667
1668 .align PAGE_SHIFT
1669
1670 .globl empty_zero_page
1671empty_zero_page:
1672 .space PAGE_SIZE
1673
1674 .globl swapper_pg_dir
1675swapper_pg_dir:
1676 .space PAGE_SIZE
1677
1678/*
1679 * This space gets a copy of optional info passed to us by the bootstrap
1680 * Used to pass parameters into the kernel like root=/dev/sda1, etc.
1681 */
1682 .globl cmd_line
1683cmd_line:
1684 .space COMMAND_LINE_SIZE