Merge git://git.kernel.org/pub/scm/linux/kernel/git/paulus/powerpc-merge
[sfrench/cifs-2.6.git] / arch / powerpc / kernel / head_64.S
1 /*
2  *  arch/ppc64/kernel/head.S
3  *
4  *  PowerPC version
5  *    Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
6  *
7  *  Rewritten by Cort Dougan (cort@cs.nmt.edu) for PReP
8  *    Copyright (C) 1996 Cort Dougan <cort@cs.nmt.edu>
9  *  Adapted for Power Macintosh by Paul Mackerras.
10  *  Low-level exception handlers and MMU support
11  *  rewritten by Paul Mackerras.
12  *    Copyright (C) 1996 Paul Mackerras.
13  *
14  *  Adapted for 64bit PowerPC by Dave Engebretsen, Peter Bergner, and
15  *    Mike Corrigan {engebret|bergner|mikejc}@us.ibm.com
16  *
17  *  This file contains the low-level support and setup for the
18  *  PowerPC-64 platform, including trap and interrupt dispatch.
19  *
20  *  This program is free software; you can redistribute it and/or
21  *  modify it under the terms of the GNU General Public License
22  *  as published by the Free Software Foundation; either version
23  *  2 of the License, or (at your option) any later version.
24  */
25
26 #include <linux/config.h>
27 #include <linux/threads.h>
28 #include <asm/reg.h>
29 #include <asm/page.h>
30 #include <asm/mmu.h>
31 #include <asm/ppc_asm.h>
32 #include <asm/asm-offsets.h>
33 #include <asm/bug.h>
34 #include <asm/cputable.h>
35 #include <asm/setup.h>
36 #include <asm/hvcall.h>
37 #include <asm/iseries/lpar_map.h>
38 #include <asm/thread_info.h>
39
40 #ifdef CONFIG_PPC_ISERIES
41 #define DO_SOFT_DISABLE
42 #endif
43
44 /*
45  * We layout physical memory as follows:
46  * 0x0000 - 0x00ff : Secondary processor spin code
47  * 0x0100 - 0x2fff : pSeries Interrupt prologs
48  * 0x3000 - 0x5fff : interrupt support, iSeries and common interrupt prologs
49  * 0x6000 - 0x6fff : Initial (CPU0) segment table
50  * 0x7000 - 0x7fff : FWNMI data area
51  * 0x8000 -        : Early init and support code
52  */
53
54 /*
55  *   SPRG Usage
56  *
57  *   Register   Definition
58  *
59  *   SPRG0      reserved for hypervisor
60  *   SPRG1      temp - used to save gpr
61  *   SPRG2      temp - used to save gpr
62  *   SPRG3      virt addr of paca
63  */
64
65 /*
66  * Entering into this code we make the following assumptions:
67  *  For pSeries:
68  *   1. The MMU is off & open firmware is running in real mode.
69  *   2. The kernel is entered at __start
70  *
71  *  For iSeries:
72  *   1. The MMU is on (as it always is for iSeries)
73  *   2. The kernel is entered at system_reset_iSeries
74  */
75
76         .text
77         .globl  _stext
78 _stext:
79 #ifdef CONFIG_PPC_MULTIPLATFORM
80 _GLOBAL(__start)
81         /* NOP this out unconditionally */
82 BEGIN_FTR_SECTION
83         b       .__start_initialization_multiplatform
84 END_FTR_SECTION(0, 1)
85 #endif /* CONFIG_PPC_MULTIPLATFORM */
86
87         /* Catch branch to 0 in real mode */
88         trap
89
90 #ifdef CONFIG_PPC_ISERIES
91         /*
92          * At offset 0x20, there is a pointer to iSeries LPAR data.
93          * This is required by the hypervisor
94          */
95         . = 0x20
96         .llong hvReleaseData-KERNELBASE
97
98         /*
99          * At offset 0x28 and 0x30 are offsets to the mschunks_map
100          * array (used by the iSeries LPAR debugger to do translation
101          * between physical addresses and absolute addresses) and
102          * to the pidhash table (also used by the debugger)
103          */
104         .llong mschunks_map-KERNELBASE
105         .llong 0        /* pidhash-KERNELBASE SFRXXX */
106
107         /* Offset 0x38 - Pointer to start of embedded System.map */
108         .globl  embedded_sysmap_start
109 embedded_sysmap_start:
110         .llong  0
111         /* Offset 0x40 - Pointer to end of embedded System.map */
112         .globl  embedded_sysmap_end
113 embedded_sysmap_end:
114         .llong  0
115
116 #endif /* CONFIG_PPC_ISERIES */
117
118         /* Secondary processors spin on this value until it goes to 1. */
119         .globl  __secondary_hold_spinloop
120 __secondary_hold_spinloop:
121         .llong  0x0
122
123         /* Secondary processors write this value with their cpu # */
124         /* after they enter the spin loop immediately below.      */
125         .globl  __secondary_hold_acknowledge
126 __secondary_hold_acknowledge:
127         .llong  0x0
128
129         . = 0x60
130 /*
131  * The following code is used on pSeries to hold secondary processors
132  * in a spin loop after they have been freed from OpenFirmware, but
133  * before the bulk of the kernel has been relocated.  This code
134  * is relocated to physical address 0x60 before prom_init is run.
135  * All of it must fit below the first exception vector at 0x100.
136  */
137 _GLOBAL(__secondary_hold)
138         mfmsr   r24
139         ori     r24,r24,MSR_RI
140         mtmsrd  r24                     /* RI on */
141
142         /* Grab our linux cpu number */
143         mr      r24,r3
144
145         /* Tell the master cpu we're here */
146         /* Relocation is off & we are located at an address less */
147         /* than 0x100, so only need to grab low order offset.    */
148         std     r24,__secondary_hold_acknowledge@l(0)
149         sync
150
151         /* All secondary cpus wait here until told to start. */
152 100:    ld      r4,__secondary_hold_spinloop@l(0)
153         cmpdi   0,r4,1
154         bne     100b
155
156 #ifdef CONFIG_HMT
157         SET_REG_IMMEDIATE(r4, .hmt_init)
158         mtctr   r4
159         bctr
160 #elif defined(CONFIG_SMP) || defined(CONFIG_KEXEC)
161         LOAD_REG_IMMEDIATE(r4, .pSeries_secondary_smp_init)
162         mtctr   r4
163         mr      r3,r24
164         bctr
165 #else
166         BUG_OPCODE
167 #endif
168
169 /* This value is used to mark exception frames on the stack. */
170         .section ".toc","aw"
171 exception_marker:
172         .tc     ID_72656773_68657265[TC],0x7265677368657265
173         .text
174
175 /*
176  * The following macros define the code that appears as
177  * the prologue to each of the exception handlers.  They
178  * are split into two parts to allow a single kernel binary
179  * to be used for pSeries and iSeries.
180  * LOL.  One day... - paulus
181  */
182
183 /*
184  * We make as much of the exception code common between native
185  * exception handlers (including pSeries LPAR) and iSeries LPAR
186  * implementations as possible.
187  */
188
189 /*
190  * This is the start of the interrupt handlers for pSeries
191  * This code runs with relocation off.
192  */
193 #define EX_R9           0
194 #define EX_R10          8
195 #define EX_R11          16
196 #define EX_R12          24
197 #define EX_R13          32
198 #define EX_SRR0         40
199 #define EX_DAR          48
200 #define EX_DSISR        56
201 #define EX_CCR          60
202 #define EX_R3           64
203 #define EX_LR           72
204
205 /*
206  * We're short on space and time in the exception prolog, so we can't
207  * use the normal SET_REG_IMMEDIATE macro. Normally we just need the
208  * low halfword of the address, but for Kdump we need the whole low
209  * word.
210  */
211 #ifdef CONFIG_CRASH_DUMP
212 #define LOAD_HANDLER(reg, label)                                        \
213         oris    reg,reg,(label)@h;      /* virt addr of handler ... */  \
214         ori     reg,reg,(label)@l;      /* .. and the rest */
215 #else
216 #define LOAD_HANDLER(reg, label)                                        \
217         ori     reg,reg,(label)@l;      /* virt addr of handler ... */
218 #endif
219
220 #define EXCEPTION_PROLOG_PSERIES(area, label)                           \
221         mfspr   r13,SPRN_SPRG3;         /* get paca address into r13 */ \
222         std     r9,area+EX_R9(r13);     /* save r9 - r12 */             \
223         std     r10,area+EX_R10(r13);                                   \
224         std     r11,area+EX_R11(r13);                                   \
225         std     r12,area+EX_R12(r13);                                   \
226         mfspr   r9,SPRN_SPRG1;                                          \
227         std     r9,area+EX_R13(r13);                                    \
228         mfcr    r9;                                                     \
229         clrrdi  r12,r13,32;             /* get high part of &label */   \
230         mfmsr   r10;                                                    \
231         mfspr   r11,SPRN_SRR0;          /* save SRR0 */                 \
232         LOAD_HANDLER(r12,label)                                         \
233         ori     r10,r10,MSR_IR|MSR_DR|MSR_RI;                           \
234         mtspr   SPRN_SRR0,r12;                                          \
235         mfspr   r12,SPRN_SRR1;          /* and SRR1 */                  \
236         mtspr   SPRN_SRR1,r10;                                          \
237         rfid;                                                           \
238         b       .       /* prevent speculative execution */
239
240 /*
241  * This is the start of the interrupt handlers for iSeries
242  * This code runs with relocation on.
243  */
244 #define EXCEPTION_PROLOG_ISERIES_1(area)                                \
245         mfspr   r13,SPRN_SPRG3;         /* get paca address into r13 */ \
246         std     r9,area+EX_R9(r13);     /* save r9 - r12 */             \
247         std     r10,area+EX_R10(r13);                                   \
248         std     r11,area+EX_R11(r13);                                   \
249         std     r12,area+EX_R12(r13);                                   \
250         mfspr   r9,SPRN_SPRG1;                                          \
251         std     r9,area+EX_R13(r13);                                    \
252         mfcr    r9
253
254 #define EXCEPTION_PROLOG_ISERIES_2                                      \
255         mfmsr   r10;                                                    \
256         ld      r12,PACALPPACAPTR(r13);                                 \
257         ld      r11,LPPACASRR0(r12);                                    \
258         ld      r12,LPPACASRR1(r12);                                    \
259         ori     r10,r10,MSR_RI;                                         \
260         mtmsrd  r10,1
261
262 /*
263  * The common exception prolog is used for all except a few exceptions
264  * such as a segment miss on a kernel address.  We have to be prepared
265  * to take another exception from the point where we first touch the
266  * kernel stack onwards.
267  *
268  * On entry r13 points to the paca, r9-r13 are saved in the paca,
269  * r9 contains the saved CR, r11 and r12 contain the saved SRR0 and
270  * SRR1, and relocation is on.
271  */
272 #define EXCEPTION_PROLOG_COMMON(n, area)                                   \
273         andi.   r10,r12,MSR_PR;         /* See if coming from user      */ \
274         mr      r10,r1;                 /* Save r1                      */ \
275         subi    r1,r1,INT_FRAME_SIZE;   /* alloc frame on kernel stack  */ \
276         beq-    1f;                                                        \
277         ld      r1,PACAKSAVE(r13);      /* kernel stack to use          */ \
278 1:      cmpdi   cr1,r1,0;               /* check if r1 is in userspace  */ \
279         bge-    cr1,bad_stack;          /* abort if it is               */ \
280         std     r9,_CCR(r1);            /* save CR in stackframe        */ \
281         std     r11,_NIP(r1);           /* save SRR0 in stackframe      */ \
282         std     r12,_MSR(r1);           /* save SRR1 in stackframe      */ \
283         std     r10,0(r1);              /* make stack chain pointer     */ \
284         std     r0,GPR0(r1);            /* save r0 in stackframe        */ \
285         std     r10,GPR1(r1);           /* save r1 in stackframe        */ \
286         std     r2,GPR2(r1);            /* save r2 in stackframe        */ \
287         SAVE_4GPRS(3, r1);              /* save r3 - r6 in stackframe   */ \
288         SAVE_2GPRS(7, r1);              /* save r7, r8 in stackframe    */ \
289         ld      r9,area+EX_R9(r13);     /* move r9, r10 to stackframe   */ \
290         ld      r10,area+EX_R10(r13);                                      \
291         std     r9,GPR9(r1);                                               \
292         std     r10,GPR10(r1);                                             \
293         ld      r9,area+EX_R11(r13);    /* move r11 - r13 to stackframe */ \
294         ld      r10,area+EX_R12(r13);                                      \
295         ld      r11,area+EX_R13(r13);                                      \
296         std     r9,GPR11(r1);                                              \
297         std     r10,GPR12(r1);                                             \
298         std     r11,GPR13(r1);                                             \
299         ld      r2,PACATOC(r13);        /* get kernel TOC into r2       */ \
300         mflr    r9;                     /* save LR in stackframe        */ \
301         std     r9,_LINK(r1);                                              \
302         mfctr   r10;                    /* save CTR in stackframe       */ \
303         std     r10,_CTR(r1);                                              \
304         mfspr   r11,SPRN_XER;           /* save XER in stackframe       */ \
305         std     r11,_XER(r1);                                              \
306         li      r9,(n)+1;                                                  \
307         std     r9,_TRAP(r1);           /* set trap number              */ \
308         li      r10,0;                                                     \
309         ld      r11,exception_marker@toc(r2);                              \
310         std     r10,RESULT(r1);         /* clear regs->result           */ \
311         std     r11,STACK_FRAME_OVERHEAD-16(r1); /* mark the frame      */
312
313 /*
314  * Exception vectors.
315  */
316 #define STD_EXCEPTION_PSERIES(n, label)                 \
317         . = n;                                          \
318         .globl label##_pSeries;                         \
319 label##_pSeries:                                        \
320         HMT_MEDIUM;                                     \
321         mtspr   SPRN_SPRG1,r13;         /* save r13 */  \
322         RUNLATCH_ON(r13);                               \
323         EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, label##_common)
324
325 #define STD_EXCEPTION_ISERIES(n, label, area)           \
326         .globl label##_iSeries;                         \
327 label##_iSeries:                                        \
328         HMT_MEDIUM;                                     \
329         mtspr   SPRN_SPRG1,r13;         /* save r13 */  \
330         RUNLATCH_ON(r13);                               \
331         EXCEPTION_PROLOG_ISERIES_1(area);               \
332         EXCEPTION_PROLOG_ISERIES_2;                     \
333         b       label##_common
334
335 #define MASKABLE_EXCEPTION_ISERIES(n, label)                            \
336         .globl label##_iSeries;                                         \
337 label##_iSeries:                                                        \
338         HMT_MEDIUM;                                                     \
339         mtspr   SPRN_SPRG1,r13;         /* save r13 */                  \
340         RUNLATCH_ON(r13);                                               \
341         EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN);                         \
342         lbz     r10,PACAPROCENABLED(r13);                               \
343         cmpwi   0,r10,0;                                                \
344         beq-    label##_iSeries_masked;                                 \
345         EXCEPTION_PROLOG_ISERIES_2;                                     \
346         b       label##_common;                                         \
347
348 #ifdef DO_SOFT_DISABLE
349 #define DISABLE_INTS                            \
350         lbz     r10,PACAPROCENABLED(r13);       \
351         li      r11,0;                          \
352         std     r10,SOFTE(r1);                  \
353         mfmsr   r10;                            \
354         stb     r11,PACAPROCENABLED(r13);       \
355         ori     r10,r10,MSR_EE;                 \
356         mtmsrd  r10,1
357
358 #define ENABLE_INTS                             \
359         lbz     r10,PACAPROCENABLED(r13);       \
360         mfmsr   r11;                            \
361         std     r10,SOFTE(r1);                  \
362         ori     r11,r11,MSR_EE;                 \
363         mtmsrd  r11,1
364
365 #else   /* hard enable/disable interrupts */
366 #define DISABLE_INTS
367
368 #define ENABLE_INTS                             \
369         ld      r12,_MSR(r1);                   \
370         mfmsr   r11;                            \
371         rlwimi  r11,r12,0,MSR_EE;               \
372         mtmsrd  r11,1
373
374 #endif
375
376 #define STD_EXCEPTION_COMMON(trap, label, hdlr)         \
377         .align  7;                                      \
378         .globl label##_common;                          \
379 label##_common:                                         \
380         EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN);      \
381         DISABLE_INTS;                                   \
382         bl      .save_nvgprs;                           \
383         addi    r3,r1,STACK_FRAME_OVERHEAD;             \
384         bl      hdlr;                                   \
385         b       .ret_from_except
386
387 #define STD_EXCEPTION_COMMON_LITE(trap, label, hdlr)    \
388         .align  7;                                      \
389         .globl label##_common;                          \
390 label##_common:                                         \
391         EXCEPTION_PROLOG_COMMON(trap, PACA_EXGEN);      \
392         DISABLE_INTS;                                   \
393         addi    r3,r1,STACK_FRAME_OVERHEAD;             \
394         bl      hdlr;                                   \
395         b       .ret_from_except_lite
396
397 /*
398  * Start of pSeries system interrupt routines
399  */
400         . = 0x100
401         .globl __start_interrupts
402 __start_interrupts:
403
404         STD_EXCEPTION_PSERIES(0x100, system_reset)
405
406         . = 0x200
407 _machine_check_pSeries:
408         HMT_MEDIUM
409         mtspr   SPRN_SPRG1,r13          /* save r13 */
410         RUNLATCH_ON(r13)
411         EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
412
413         . = 0x300
414         .globl data_access_pSeries
415 data_access_pSeries:
416         HMT_MEDIUM
417         mtspr   SPRN_SPRG1,r13
418 BEGIN_FTR_SECTION
419         mtspr   SPRN_SPRG2,r12
420         mfspr   r13,SPRN_DAR
421         mfspr   r12,SPRN_DSISR
422         srdi    r13,r13,60
423         rlwimi  r13,r12,16,0x20
424         mfcr    r12
425         cmpwi   r13,0x2c
426         beq     .do_stab_bolted_pSeries
427         mtcrf   0x80,r12
428         mfspr   r12,SPRN_SPRG2
429 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
430         EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, data_access_common)
431
432         . = 0x380
433         .globl data_access_slb_pSeries
434 data_access_slb_pSeries:
435         HMT_MEDIUM
436         mtspr   SPRN_SPRG1,r13
437         RUNLATCH_ON(r13)
438         mfspr   r13,SPRN_SPRG3          /* get paca address into r13 */
439         std     r3,PACA_EXSLB+EX_R3(r13)
440         mfspr   r3,SPRN_DAR
441         std     r9,PACA_EXSLB+EX_R9(r13)        /* save r9 - r12 */
442         mfcr    r9
443 #ifdef __DISABLED__
444         /* Keep that around for when we re-implement dynamic VSIDs */
445         cmpdi   r3,0
446         bge     slb_miss_user_pseries
447 #endif /* __DISABLED__ */
448         std     r10,PACA_EXSLB+EX_R10(r13)
449         std     r11,PACA_EXSLB+EX_R11(r13)
450         std     r12,PACA_EXSLB+EX_R12(r13)
451         mfspr   r10,SPRN_SPRG1
452         std     r10,PACA_EXSLB+EX_R13(r13)
453         mfspr   r12,SPRN_SRR1           /* and SRR1 */
454         b       .slb_miss_realmode      /* Rel. branch works in real mode */
455
456         STD_EXCEPTION_PSERIES(0x400, instruction_access)
457
458         . = 0x480
459         .globl instruction_access_slb_pSeries
460 instruction_access_slb_pSeries:
461         HMT_MEDIUM
462         mtspr   SPRN_SPRG1,r13
463         RUNLATCH_ON(r13)
464         mfspr   r13,SPRN_SPRG3          /* get paca address into r13 */
465         std     r3,PACA_EXSLB+EX_R3(r13)
466         mfspr   r3,SPRN_SRR0            /* SRR0 is faulting address */
467         std     r9,PACA_EXSLB+EX_R9(r13)        /* save r9 - r12 */
468         mfcr    r9
469 #ifdef __DISABLED__
470         /* Keep that around for when we re-implement dynamic VSIDs */
471         cmpdi   r3,0
472         bge     slb_miss_user_pseries
473 #endif /* __DISABLED__ */
474         std     r10,PACA_EXSLB+EX_R10(r13)
475         std     r11,PACA_EXSLB+EX_R11(r13)
476         std     r12,PACA_EXSLB+EX_R12(r13)
477         mfspr   r10,SPRN_SPRG1
478         std     r10,PACA_EXSLB+EX_R13(r13)
479         mfspr   r12,SPRN_SRR1           /* and SRR1 */
480         b       .slb_miss_realmode      /* Rel. branch works in real mode */
481
482         STD_EXCEPTION_PSERIES(0x500, hardware_interrupt)
483         STD_EXCEPTION_PSERIES(0x600, alignment)
484         STD_EXCEPTION_PSERIES(0x700, program_check)
485         STD_EXCEPTION_PSERIES(0x800, fp_unavailable)
486         STD_EXCEPTION_PSERIES(0x900, decrementer)
487         STD_EXCEPTION_PSERIES(0xa00, trap_0a)
488         STD_EXCEPTION_PSERIES(0xb00, trap_0b)
489
490         . = 0xc00
491         .globl  system_call_pSeries
492 system_call_pSeries:
493         HMT_MEDIUM
494         RUNLATCH_ON(r9)
495         mr      r9,r13
496         mfmsr   r10
497         mfspr   r13,SPRN_SPRG3
498         mfspr   r11,SPRN_SRR0
499         clrrdi  r12,r13,32
500         oris    r12,r12,system_call_common@h
501         ori     r12,r12,system_call_common@l
502         mtspr   SPRN_SRR0,r12
503         ori     r10,r10,MSR_IR|MSR_DR|MSR_RI
504         mfspr   r12,SPRN_SRR1
505         mtspr   SPRN_SRR1,r10
506         rfid
507         b       .       /* prevent speculative execution */
508
509         STD_EXCEPTION_PSERIES(0xd00, single_step)
510         STD_EXCEPTION_PSERIES(0xe00, trap_0e)
511
512         /* We need to deal with the Altivec unavailable exception
513          * here which is at 0xf20, thus in the middle of the
514          * prolog code of the PerformanceMonitor one. A little
515          * trickery is thus necessary
516          */
517         . = 0xf00
518         b       performance_monitor_pSeries
519
520         STD_EXCEPTION_PSERIES(0xf20, altivec_unavailable)
521
522         STD_EXCEPTION_PSERIES(0x1300, instruction_breakpoint)
523         STD_EXCEPTION_PSERIES(0x1700, altivec_assist)
524
525         . = 0x3000
526
527 /*** pSeries interrupt support ***/
528
529         /* moved from 0xf00 */
530         STD_EXCEPTION_PSERIES(., performance_monitor)
531
532         .align  7
533 _GLOBAL(do_stab_bolted_pSeries)
534         mtcrf   0x80,r12
535         mfspr   r12,SPRN_SPRG2
536         EXCEPTION_PROLOG_PSERIES(PACA_EXSLB, .do_stab_bolted)
537
538 /*
539  * We have some room here  we use that to put
540  * the peries slb miss user trampoline code so it's reasonably
541  * away from slb_miss_user_common to avoid problems with rfid
542  *
543  * This is used for when the SLB miss handler has to go virtual,
544  * which doesn't happen for now anymore but will once we re-implement
545  * dynamic VSIDs for shared page tables
546  */
547 #ifdef __DISABLED__
548 slb_miss_user_pseries:
549         std     r10,PACA_EXGEN+EX_R10(r13)
550         std     r11,PACA_EXGEN+EX_R11(r13)
551         std     r12,PACA_EXGEN+EX_R12(r13)
552         mfspr   r10,SPRG1
553         ld      r11,PACA_EXSLB+EX_R9(r13)
554         ld      r12,PACA_EXSLB+EX_R3(r13)
555         std     r10,PACA_EXGEN+EX_R13(r13)
556         std     r11,PACA_EXGEN+EX_R9(r13)
557         std     r12,PACA_EXGEN+EX_R3(r13)
558         clrrdi  r12,r13,32
559         mfmsr   r10
560         mfspr   r11,SRR0                        /* save SRR0 */
561         ori     r12,r12,slb_miss_user_common@l  /* virt addr of handler */
562         ori     r10,r10,MSR_IR|MSR_DR|MSR_RI
563         mtspr   SRR0,r12
564         mfspr   r12,SRR1                        /* and SRR1 */
565         mtspr   SRR1,r10
566         rfid
567         b       .                               /* prevent spec. execution */
568 #endif /* __DISABLED__ */
569
570 /*
571  * Vectors for the FWNMI option.  Share common code.
572  */
573         .globl system_reset_fwnmi
574       .align 7
575 system_reset_fwnmi:
576         HMT_MEDIUM
577         mtspr   SPRN_SPRG1,r13          /* save r13 */
578         RUNLATCH_ON(r13)
579         EXCEPTION_PROLOG_PSERIES(PACA_EXGEN, system_reset_common)
580
581         .globl machine_check_fwnmi
582       .align 7
583 machine_check_fwnmi:
584         HMT_MEDIUM
585         mtspr   SPRN_SPRG1,r13          /* save r13 */
586         RUNLATCH_ON(r13)
587         EXCEPTION_PROLOG_PSERIES(PACA_EXMC, machine_check_common)
588
589 #ifdef CONFIG_PPC_ISERIES
590 /***  ISeries-LPAR interrupt handlers ***/
591
592         STD_EXCEPTION_ISERIES(0x200, machine_check, PACA_EXMC)
593
594         .globl data_access_iSeries
595 data_access_iSeries:
596         mtspr   SPRN_SPRG1,r13
597 BEGIN_FTR_SECTION
598         mtspr   SPRN_SPRG2,r12
599         mfspr   r13,SPRN_DAR
600         mfspr   r12,SPRN_DSISR
601         srdi    r13,r13,60
602         rlwimi  r13,r12,16,0x20
603         mfcr    r12
604         cmpwi   r13,0x2c
605         beq     .do_stab_bolted_iSeries
606         mtcrf   0x80,r12
607         mfspr   r12,SPRN_SPRG2
608 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
609         EXCEPTION_PROLOG_ISERIES_1(PACA_EXGEN)
610         EXCEPTION_PROLOG_ISERIES_2
611         b       data_access_common
612
613 .do_stab_bolted_iSeries:
614         mtcrf   0x80,r12
615         mfspr   r12,SPRN_SPRG2
616         EXCEPTION_PROLOG_ISERIES_1(PACA_EXSLB)
617         EXCEPTION_PROLOG_ISERIES_2
618         b       .do_stab_bolted
619
620         .globl  data_access_slb_iSeries
621 data_access_slb_iSeries:
622         mtspr   SPRN_SPRG1,r13          /* save r13 */
623         mfspr   r13,SPRN_SPRG3          /* get paca address into r13 */
624         std     r3,PACA_EXSLB+EX_R3(r13)
625         mfspr   r3,SPRN_DAR
626         std     r9,PACA_EXSLB+EX_R9(r13)
627         mfcr    r9
628 #ifdef __DISABLED__
629         cmpdi   r3,0
630         bge     slb_miss_user_iseries
631 #endif
632         std     r10,PACA_EXSLB+EX_R10(r13)
633         std     r11,PACA_EXSLB+EX_R11(r13)
634         std     r12,PACA_EXSLB+EX_R12(r13)
635         mfspr   r10,SPRN_SPRG1
636         std     r10,PACA_EXSLB+EX_R13(r13)
637         ld      r12,PACALPPACAPTR(r13)
638         ld      r12,LPPACASRR1(r12)
639         b       .slb_miss_realmode
640
641         STD_EXCEPTION_ISERIES(0x400, instruction_access, PACA_EXGEN)
642
643         .globl  instruction_access_slb_iSeries
644 instruction_access_slb_iSeries:
645         mtspr   SPRN_SPRG1,r13          /* save r13 */
646         mfspr   r13,SPRN_SPRG3          /* get paca address into r13 */
647         std     r3,PACA_EXSLB+EX_R3(r13)
648         ld      r3,PACALPPACAPTR(r13)
649         ld      r3,LPPACASRR0(r3)       /* get SRR0 value */
650         std     r9,PACA_EXSLB+EX_R9(r13)
651         mfcr    r9
652 #ifdef __DISABLED__
653         cmpdi   r3,0
654         bge     .slb_miss_user_iseries
655 #endif
656         std     r10,PACA_EXSLB+EX_R10(r13)
657         std     r11,PACA_EXSLB+EX_R11(r13)
658         std     r12,PACA_EXSLB+EX_R12(r13)
659         mfspr   r10,SPRN_SPRG1
660         std     r10,PACA_EXSLB+EX_R13(r13)
661         ld      r12,PACALPPACAPTR(r13)
662         ld      r12,LPPACASRR1(r12)
663         b       .slb_miss_realmode
664
665 #ifdef __DISABLED__
666 slb_miss_user_iseries:
667         std     r10,PACA_EXGEN+EX_R10(r13)
668         std     r11,PACA_EXGEN+EX_R11(r13)
669         std     r12,PACA_EXGEN+EX_R12(r13)
670         mfspr   r10,SPRG1
671         ld      r11,PACA_EXSLB+EX_R9(r13)
672         ld      r12,PACA_EXSLB+EX_R3(r13)
673         std     r10,PACA_EXGEN+EX_R13(r13)
674         std     r11,PACA_EXGEN+EX_R9(r13)
675         std     r12,PACA_EXGEN+EX_R3(r13)
676         EXCEPTION_PROLOG_ISERIES_2
677         b       slb_miss_user_common
678 #endif
679
680         MASKABLE_EXCEPTION_ISERIES(0x500, hardware_interrupt)
681         STD_EXCEPTION_ISERIES(0x600, alignment, PACA_EXGEN)
682         STD_EXCEPTION_ISERIES(0x700, program_check, PACA_EXGEN)
683         STD_EXCEPTION_ISERIES(0x800, fp_unavailable, PACA_EXGEN)
684         MASKABLE_EXCEPTION_ISERIES(0x900, decrementer)
685         STD_EXCEPTION_ISERIES(0xa00, trap_0a, PACA_EXGEN)
686         STD_EXCEPTION_ISERIES(0xb00, trap_0b, PACA_EXGEN)
687
688         .globl  system_call_iSeries
689 system_call_iSeries:
690         mr      r9,r13
691         mfspr   r13,SPRN_SPRG3
692         EXCEPTION_PROLOG_ISERIES_2
693         b       system_call_common
694
695         STD_EXCEPTION_ISERIES( 0xd00, single_step, PACA_EXGEN)
696         STD_EXCEPTION_ISERIES( 0xe00, trap_0e, PACA_EXGEN)
697         STD_EXCEPTION_ISERIES( 0xf00, performance_monitor, PACA_EXGEN)
698
699         .globl system_reset_iSeries
700 system_reset_iSeries:
701         mfspr   r13,SPRN_SPRG3          /* Get paca address */
702         mfmsr   r24
703         ori     r24,r24,MSR_RI
704         mtmsrd  r24                     /* RI on */
705         lhz     r24,PACAPACAINDEX(r13)  /* Get processor # */
706         cmpwi   0,r24,0                 /* Are we processor 0? */
707         beq     .__start_initialization_iSeries /* Start up the first processor */
708         mfspr   r4,SPRN_CTRLF
709         li      r5,CTRL_RUNLATCH        /* Turn off the run light */
710         andc    r4,r4,r5
711         mtspr   SPRN_CTRLT,r4
712
713 1:
714         HMT_LOW
715 #ifdef CONFIG_SMP
716         lbz     r23,PACAPROCSTART(r13)  /* Test if this processor
717                                          * should start */
718         sync
719         LOAD_REG_IMMEDIATE(r3,current_set)
720         sldi    r28,r24,3               /* get current_set[cpu#] */
721         ldx     r3,r3,r28
722         addi    r1,r3,THREAD_SIZE
723         subi    r1,r1,STACK_FRAME_OVERHEAD
724
725         cmpwi   0,r23,0
726         beq     iSeries_secondary_smp_loop      /* Loop until told to go */
727         bne     .__secondary_start              /* Loop until told to go */
728 iSeries_secondary_smp_loop:
729         /* Let the Hypervisor know we are alive */
730         /* 8002 is a call to HvCallCfg::getLps, a harmless Hypervisor function */
731         lis     r3,0x8002
732         rldicr  r3,r3,32,15             /* r0 = (r3 << 32) & 0xffff000000000000 */
733 #else /* CONFIG_SMP */
734         /* Yield the processor.  This is required for non-SMP kernels
735                 which are running on multi-threaded machines. */
736         lis     r3,0x8000
737         rldicr  r3,r3,32,15             /* r3 = (r3 << 32) & 0xffff000000000000 */
738         addi    r3,r3,18                /* r3 = 0x8000000000000012 which is "yield" */
739         li      r4,0                    /* "yield timed" */
740         li      r5,-1                   /* "yield forever" */
741 #endif /* CONFIG_SMP */
742         li      r0,-1                   /* r0=-1 indicates a Hypervisor call */
743         sc                              /* Invoke the hypervisor via a system call */
744         mfspr   r13,SPRN_SPRG3          /* Put r13 back ???? */
745         b       1b                      /* If SMP not configured, secondaries
746                                          * loop forever */
747
748         .globl decrementer_iSeries_masked
749 decrementer_iSeries_masked:
750         /* We may not have a valid TOC pointer in here. */
751         li      r11,1
752         ld      r12,PACALPPACAPTR(r13)
753         stb     r11,LPPACADECRINT(r12)
754         LOAD_REG_IMMEDIATE(r12, tb_ticks_per_jiffy)
755         lwz     r12,0(r12)
756         mtspr   SPRN_DEC,r12
757         /* fall through */
758
759         .globl hardware_interrupt_iSeries_masked
760 hardware_interrupt_iSeries_masked:
761         mtcrf   0x80,r9         /* Restore regs */
762         ld      r12,PACALPPACAPTR(r13)
763         ld      r11,LPPACASRR0(r12)
764         ld      r12,LPPACASRR1(r12)
765         mtspr   SPRN_SRR0,r11
766         mtspr   SPRN_SRR1,r12
767         ld      r9,PACA_EXGEN+EX_R9(r13)
768         ld      r10,PACA_EXGEN+EX_R10(r13)
769         ld      r11,PACA_EXGEN+EX_R11(r13)
770         ld      r12,PACA_EXGEN+EX_R12(r13)
771         ld      r13,PACA_EXGEN+EX_R13(r13)
772         rfid
773         b       .       /* prevent speculative execution */
774 #endif /* CONFIG_PPC_ISERIES */
775
776 /*** Common interrupt handlers ***/
777
778         STD_EXCEPTION_COMMON(0x100, system_reset, .system_reset_exception)
779
780         /*
781          * Machine check is different because we use a different
782          * save area: PACA_EXMC instead of PACA_EXGEN.
783          */
784         .align  7
785         .globl machine_check_common
786 machine_check_common:
787         EXCEPTION_PROLOG_COMMON(0x200, PACA_EXMC)
788         DISABLE_INTS
789         bl      .save_nvgprs
790         addi    r3,r1,STACK_FRAME_OVERHEAD
791         bl      .machine_check_exception
792         b       .ret_from_except
793
794         STD_EXCEPTION_COMMON_LITE(0x900, decrementer, .timer_interrupt)
795         STD_EXCEPTION_COMMON(0xa00, trap_0a, .unknown_exception)
796         STD_EXCEPTION_COMMON(0xb00, trap_0b, .unknown_exception)
797         STD_EXCEPTION_COMMON(0xd00, single_step, .single_step_exception)
798         STD_EXCEPTION_COMMON(0xe00, trap_0e, .unknown_exception)
799         STD_EXCEPTION_COMMON(0xf00, performance_monitor, .performance_monitor_exception)
800         STD_EXCEPTION_COMMON(0x1300, instruction_breakpoint, .instruction_breakpoint_exception)
801 #ifdef CONFIG_ALTIVEC
802         STD_EXCEPTION_COMMON(0x1700, altivec_assist, .altivec_assist_exception)
803 #else
804         STD_EXCEPTION_COMMON(0x1700, altivec_assist, .unknown_exception)
805 #endif
806
807 /*
808  * Here we have detected that the kernel stack pointer is bad.
809  * R9 contains the saved CR, r13 points to the paca,
810  * r10 contains the (bad) kernel stack pointer,
811  * r11 and r12 contain the saved SRR0 and SRR1.
812  * We switch to using an emergency stack, save the registers there,
813  * and call kernel_bad_stack(), which panics.
814  */
815 bad_stack:
816         ld      r1,PACAEMERGSP(r13)
817         subi    r1,r1,64+INT_FRAME_SIZE
818         std     r9,_CCR(r1)
819         std     r10,GPR1(r1)
820         std     r11,_NIP(r1)
821         std     r12,_MSR(r1)
822         mfspr   r11,SPRN_DAR
823         mfspr   r12,SPRN_DSISR
824         std     r11,_DAR(r1)
825         std     r12,_DSISR(r1)
826         mflr    r10
827         mfctr   r11
828         mfxer   r12
829         std     r10,_LINK(r1)
830         std     r11,_CTR(r1)
831         std     r12,_XER(r1)
832         SAVE_GPR(0,r1)
833         SAVE_GPR(2,r1)
834         SAVE_4GPRS(3,r1)
835         SAVE_2GPRS(7,r1)
836         SAVE_10GPRS(12,r1)
837         SAVE_10GPRS(22,r1)
838         addi    r11,r1,INT_FRAME_SIZE
839         std     r11,0(r1)
840         li      r12,0
841         std     r12,0(r11)
842         ld      r2,PACATOC(r13)
843 1:      addi    r3,r1,STACK_FRAME_OVERHEAD
844         bl      .kernel_bad_stack
845         b       1b
846
847 /*
848  * Return from an exception with minimal checks.
849  * The caller is assumed to have done EXCEPTION_PROLOG_COMMON.
850  * If interrupts have been enabled, or anything has been
851  * done that might have changed the scheduling status of
852  * any task or sent any task a signal, you should use
853  * ret_from_except or ret_from_except_lite instead of this.
854  */
855         .globl  fast_exception_return
856 fast_exception_return:
857         ld      r12,_MSR(r1)
858         ld      r11,_NIP(r1)
859         andi.   r3,r12,MSR_RI           /* check if RI is set */
860         beq-    unrecov_fer
861         ld      r3,_CCR(r1)
862         ld      r4,_LINK(r1)
863         ld      r5,_CTR(r1)
864         ld      r6,_XER(r1)
865         mtcr    r3
866         mtlr    r4
867         mtctr   r5
868         mtxer   r6
869         REST_GPR(0, r1)
870         REST_8GPRS(2, r1)
871
872         mfmsr   r10
873         clrrdi  r10,r10,2               /* clear RI (LE is 0 already) */
874         mtmsrd  r10,1
875
876         mtspr   SPRN_SRR1,r12
877         mtspr   SPRN_SRR0,r11
878         REST_4GPRS(10, r1)
879         ld      r1,GPR1(r1)
880         rfid
881         b       .       /* prevent speculative execution */
882
883 unrecov_fer:
884         bl      .save_nvgprs
885 1:      addi    r3,r1,STACK_FRAME_OVERHEAD
886         bl      .unrecoverable_exception
887         b       1b
888
889 /*
890  * Here r13 points to the paca, r9 contains the saved CR,
891  * SRR0 and SRR1 are saved in r11 and r12,
892  * r9 - r13 are saved in paca->exgen.
893  */
894         .align  7
895         .globl data_access_common
896 data_access_common:
897         RUNLATCH_ON(r10)                /* It wont fit in the 0x300 handler */
898         mfspr   r10,SPRN_DAR
899         std     r10,PACA_EXGEN+EX_DAR(r13)
900         mfspr   r10,SPRN_DSISR
901         stw     r10,PACA_EXGEN+EX_DSISR(r13)
902         EXCEPTION_PROLOG_COMMON(0x300, PACA_EXGEN)
903         ld      r3,PACA_EXGEN+EX_DAR(r13)
904         lwz     r4,PACA_EXGEN+EX_DSISR(r13)
905         li      r5,0x300
906         b       .do_hash_page           /* Try to handle as hpte fault */
907
908         .align  7
909         .globl instruction_access_common
910 instruction_access_common:
911         EXCEPTION_PROLOG_COMMON(0x400, PACA_EXGEN)
912         ld      r3,_NIP(r1)
913         andis.  r4,r12,0x5820
914         li      r5,0x400
915         b       .do_hash_page           /* Try to handle as hpte fault */
916
917 /*
918  * Here is the common SLB miss user that is used when going to virtual
919  * mode for SLB misses, that is currently not used
920  */
921 #ifdef __DISABLED__
922         .align  7
923         .globl  slb_miss_user_common
924 slb_miss_user_common:
925         mflr    r10
926         std     r3,PACA_EXGEN+EX_DAR(r13)
927         stw     r9,PACA_EXGEN+EX_CCR(r13)
928         std     r10,PACA_EXGEN+EX_LR(r13)
929         std     r11,PACA_EXGEN+EX_SRR0(r13)
930         bl      .slb_allocate_user
931
932         ld      r10,PACA_EXGEN+EX_LR(r13)
933         ld      r3,PACA_EXGEN+EX_R3(r13)
934         lwz     r9,PACA_EXGEN+EX_CCR(r13)
935         ld      r11,PACA_EXGEN+EX_SRR0(r13)
936         mtlr    r10
937         beq-    slb_miss_fault
938
939         andi.   r10,r12,MSR_RI          /* check for unrecoverable exception */
940         beq-    unrecov_user_slb
941         mfmsr   r10
942
943 .machine push
944 .machine "power4"
945         mtcrf   0x80,r9
946 .machine pop
947
948         clrrdi  r10,r10,2               /* clear RI before setting SRR0/1 */
949         mtmsrd  r10,1
950
951         mtspr   SRR0,r11
952         mtspr   SRR1,r12
953
954         ld      r9,PACA_EXGEN+EX_R9(r13)
955         ld      r10,PACA_EXGEN+EX_R10(r13)
956         ld      r11,PACA_EXGEN+EX_R11(r13)
957         ld      r12,PACA_EXGEN+EX_R12(r13)
958         ld      r13,PACA_EXGEN+EX_R13(r13)
959         rfid
960         b       .
961
962 slb_miss_fault:
963         EXCEPTION_PROLOG_COMMON(0x380, PACA_EXGEN)
964         ld      r4,PACA_EXGEN+EX_DAR(r13)
965         li      r5,0
966         std     r4,_DAR(r1)
967         std     r5,_DSISR(r1)
968         b       .handle_page_fault
969
970 unrecov_user_slb:
971         EXCEPTION_PROLOG_COMMON(0x4200, PACA_EXGEN)
972         DISABLE_INTS
973         bl      .save_nvgprs
974 1:      addi    r3,r1,STACK_FRAME_OVERHEAD
975         bl      .unrecoverable_exception
976         b       1b
977
978 #endif /* __DISABLED__ */
979
980
981 /*
982  * r13 points to the PACA, r9 contains the saved CR,
983  * r12 contain the saved SRR1, SRR0 is still ready for return
984  * r3 has the faulting address
985  * r9 - r13 are saved in paca->exslb.
986  * r3 is saved in paca->slb_r3
987  * We assume we aren't going to take any exceptions during this procedure.
988  */
989 _GLOBAL(slb_miss_realmode)
990         mflr    r10
991
992         stw     r9,PACA_EXSLB+EX_CCR(r13)       /* save CR in exc. frame */
993         std     r10,PACA_EXSLB+EX_LR(r13)       /* save LR */
994
995         bl      .slb_allocate_realmode
996
997         /* All done -- return from exception. */
998
999         ld      r10,PACA_EXSLB+EX_LR(r13)
1000         ld      r3,PACA_EXSLB+EX_R3(r13)
1001         lwz     r9,PACA_EXSLB+EX_CCR(r13)       /* get saved CR */
1002 #ifdef CONFIG_PPC_ISERIES
1003         ld      r11,PACALPPACAPTR(r13)
1004         ld      r11,LPPACASRR0(r11)             /* get SRR0 value */
1005 #endif /* CONFIG_PPC_ISERIES */
1006
1007         mtlr    r10
1008
1009         andi.   r10,r12,MSR_RI  /* check for unrecoverable exception */
1010         beq-    unrecov_slb
1011
1012 .machine        push
1013 .machine        "power4"
1014         mtcrf   0x80,r9
1015         mtcrf   0x01,r9         /* slb_allocate uses cr0 and cr7 */
1016 .machine        pop
1017
1018 #ifdef CONFIG_PPC_ISERIES
1019         mtspr   SPRN_SRR0,r11
1020         mtspr   SPRN_SRR1,r12
1021 #endif /* CONFIG_PPC_ISERIES */
1022         ld      r9,PACA_EXSLB+EX_R9(r13)
1023         ld      r10,PACA_EXSLB+EX_R10(r13)
1024         ld      r11,PACA_EXSLB+EX_R11(r13)
1025         ld      r12,PACA_EXSLB+EX_R12(r13)
1026         ld      r13,PACA_EXSLB+EX_R13(r13)
1027         rfid
1028         b       .       /* prevent speculative execution */
1029
1030 unrecov_slb:
1031         EXCEPTION_PROLOG_COMMON(0x4100, PACA_EXSLB)
1032         DISABLE_INTS
1033         bl      .save_nvgprs
1034 1:      addi    r3,r1,STACK_FRAME_OVERHEAD
1035         bl      .unrecoverable_exception
1036         b       1b
1037
1038         .align  7
1039         .globl hardware_interrupt_common
1040         .globl hardware_interrupt_entry
1041 hardware_interrupt_common:
1042         EXCEPTION_PROLOG_COMMON(0x500, PACA_EXGEN)
1043 hardware_interrupt_entry:
1044         DISABLE_INTS
1045         addi    r3,r1,STACK_FRAME_OVERHEAD
1046         bl      .do_IRQ
1047         b       .ret_from_except_lite
1048
1049         .align  7
1050         .globl alignment_common
1051 alignment_common:
1052         mfspr   r10,SPRN_DAR
1053         std     r10,PACA_EXGEN+EX_DAR(r13)
1054         mfspr   r10,SPRN_DSISR
1055         stw     r10,PACA_EXGEN+EX_DSISR(r13)
1056         EXCEPTION_PROLOG_COMMON(0x600, PACA_EXGEN)
1057         ld      r3,PACA_EXGEN+EX_DAR(r13)
1058         lwz     r4,PACA_EXGEN+EX_DSISR(r13)
1059         std     r3,_DAR(r1)
1060         std     r4,_DSISR(r1)
1061         bl      .save_nvgprs
1062         addi    r3,r1,STACK_FRAME_OVERHEAD
1063         ENABLE_INTS
1064         bl      .alignment_exception
1065         b       .ret_from_except
1066
1067         .align  7
1068         .globl program_check_common
1069 program_check_common:
1070         EXCEPTION_PROLOG_COMMON(0x700, PACA_EXGEN)
1071         bl      .save_nvgprs
1072         addi    r3,r1,STACK_FRAME_OVERHEAD
1073         ENABLE_INTS
1074         bl      .program_check_exception
1075         b       .ret_from_except
1076
1077         .align  7
1078         .globl fp_unavailable_common
1079 fp_unavailable_common:
1080         EXCEPTION_PROLOG_COMMON(0x800, PACA_EXGEN)
1081         bne     .load_up_fpu            /* if from user, just load it up */
1082         bl      .save_nvgprs
1083         addi    r3,r1,STACK_FRAME_OVERHEAD
1084         ENABLE_INTS
1085         bl      .kernel_fp_unavailable_exception
1086         BUG_OPCODE
1087
1088         .align  7
1089         .globl altivec_unavailable_common
1090 altivec_unavailable_common:
1091         EXCEPTION_PROLOG_COMMON(0xf20, PACA_EXGEN)
1092 #ifdef CONFIG_ALTIVEC
1093 BEGIN_FTR_SECTION
1094         bne     .load_up_altivec        /* if from user, just load it up */
1095 END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC)
1096 #endif
1097         bl      .save_nvgprs
1098         addi    r3,r1,STACK_FRAME_OVERHEAD
1099         ENABLE_INTS
1100         bl      .altivec_unavailable_exception
1101         b       .ret_from_except
1102
1103 #ifdef CONFIG_ALTIVEC
1104 /*
1105  * load_up_altivec(unused, unused, tsk)
1106  * Disable VMX for the task which had it previously,
1107  * and save its vector registers in its thread_struct.
1108  * Enables the VMX for use in the kernel on return.
1109  * On SMP we know the VMX is free, since we give it up every
1110  * switch (ie, no lazy save of the vector registers).
1111  * On entry: r13 == 'current' && last_task_used_altivec != 'current'
1112  */
1113 _STATIC(load_up_altivec)
1114         mfmsr   r5                      /* grab the current MSR */
1115         oris    r5,r5,MSR_VEC@h
1116         mtmsrd  r5                      /* enable use of VMX now */
1117         isync
1118
1119 /*
1120  * For SMP, we don't do lazy VMX switching because it just gets too
1121  * horrendously complex, especially when a task switches from one CPU
1122  * to another.  Instead we call giveup_altvec in switch_to.
1123  * VRSAVE isn't dealt with here, that is done in the normal context
1124  * switch code. Note that we could rely on vrsave value to eventually
1125  * avoid saving all of the VREGs here...
1126  */
1127 #ifndef CONFIG_SMP
1128         ld      r3,last_task_used_altivec@got(r2)
1129         ld      r4,0(r3)
1130         cmpdi   0,r4,0
1131         beq     1f
1132         /* Save VMX state to last_task_used_altivec's THREAD struct */
1133         addi    r4,r4,THREAD
1134         SAVE_32VRS(0,r5,r4)
1135         mfvscr  vr0
1136         li      r10,THREAD_VSCR
1137         stvx    vr0,r10,r4
1138         /* Disable VMX for last_task_used_altivec */
1139         ld      r5,PT_REGS(r4)
1140         ld      r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1141         lis     r6,MSR_VEC@h
1142         andc    r4,r4,r6
1143         std     r4,_MSR-STACK_FRAME_OVERHEAD(r5)
1144 1:
1145 #endif /* CONFIG_SMP */
1146         /* Hack: if we get an altivec unavailable trap with VRSAVE
1147          * set to all zeros, we assume this is a broken application
1148          * that fails to set it properly, and thus we switch it to
1149          * all 1's
1150          */
1151         mfspr   r4,SPRN_VRSAVE
1152         cmpdi   0,r4,0
1153         bne+    1f
1154         li      r4,-1
1155         mtspr   SPRN_VRSAVE,r4
1156 1:
1157         /* enable use of VMX after return */
1158         ld      r4,PACACURRENT(r13)
1159         addi    r5,r4,THREAD            /* Get THREAD */
1160         oris    r12,r12,MSR_VEC@h
1161         std     r12,_MSR(r1)
1162         li      r4,1
1163         li      r10,THREAD_VSCR
1164         stw     r4,THREAD_USED_VR(r5)
1165         lvx     vr0,r10,r5
1166         mtvscr  vr0
1167         REST_32VRS(0,r4,r5)
1168 #ifndef CONFIG_SMP
1169         /* Update last_task_used_math to 'current' */
1170         subi    r4,r5,THREAD            /* Back to 'current' */
1171         std     r4,0(r3)
1172 #endif /* CONFIG_SMP */
1173         /* restore registers and return */
1174         b       fast_exception_return
1175 #endif /* CONFIG_ALTIVEC */
1176
1177 /*
1178  * Hash table stuff
1179  */
1180         .align  7
1181 _GLOBAL(do_hash_page)
1182         std     r3,_DAR(r1)
1183         std     r4,_DSISR(r1)
1184
1185         andis.  r0,r4,0xa450            /* weird error? */
1186         bne-    .handle_page_fault      /* if not, try to insert a HPTE */
1187 BEGIN_FTR_SECTION
1188         andis.  r0,r4,0x0020            /* Is it a segment table fault? */
1189         bne-    .do_ste_alloc           /* If so handle it */
1190 END_FTR_SECTION_IFCLR(CPU_FTR_SLB)
1191
1192         /*
1193          * We need to set the _PAGE_USER bit if MSR_PR is set or if we are
1194          * accessing a userspace segment (even from the kernel). We assume
1195          * kernel addresses always have the high bit set.
1196          */
1197         rlwinm  r4,r4,32-25+9,31-9,31-9 /* DSISR_STORE -> _PAGE_RW */
1198         rotldi  r0,r3,15                /* Move high bit into MSR_PR posn */
1199         orc     r0,r12,r0               /* MSR_PR | ~high_bit */
1200         rlwimi  r4,r0,32-13,30,30       /* becomes _PAGE_USER access bit */
1201         ori     r4,r4,1                 /* add _PAGE_PRESENT */
1202         rlwimi  r4,r5,22+2,31-2,31-2    /* Set _PAGE_EXEC if trap is 0x400 */
1203
1204         /*
1205          * On iSeries, we soft-disable interrupts here, then
1206          * hard-enable interrupts so that the hash_page code can spin on
1207          * the hash_table_lock without problems on a shared processor.
1208          */
1209         DISABLE_INTS
1210
1211         /*
1212          * r3 contains the faulting address
1213          * r4 contains the required access permissions
1214          * r5 contains the trap number
1215          *
1216          * at return r3 = 0 for success
1217          */
1218         bl      .hash_page              /* build HPTE if possible */
1219         cmpdi   r3,0                    /* see if hash_page succeeded */
1220
1221 #ifdef DO_SOFT_DISABLE
1222         /*
1223          * If we had interrupts soft-enabled at the point where the
1224          * DSI/ISI occurred, and an interrupt came in during hash_page,
1225          * handle it now.
1226          * We jump to ret_from_except_lite rather than fast_exception_return
1227          * because ret_from_except_lite will check for and handle pending
1228          * interrupts if necessary.
1229          */
1230         beq     .ret_from_except_lite
1231         /* For a hash failure, we don't bother re-enabling interrupts */
1232         ble-    12f
1233
1234         /*
1235          * hash_page couldn't handle it, set soft interrupt enable back
1236          * to what it was before the trap.  Note that .local_irq_restore
1237          * handles any interrupts pending at this point.
1238          */
1239         ld      r3,SOFTE(r1)
1240         bl      .local_irq_restore
1241         b       11f
1242 #else
1243         beq     fast_exception_return   /* Return from exception on success */
1244         ble-    12f                     /* Failure return from hash_page */
1245
1246         /* fall through */
1247 #endif
1248
1249 /* Here we have a page fault that hash_page can't handle. */
1250 _GLOBAL(handle_page_fault)
1251         ENABLE_INTS
1252 11:     ld      r4,_DAR(r1)
1253         ld      r5,_DSISR(r1)
1254         addi    r3,r1,STACK_FRAME_OVERHEAD
1255         bl      .do_page_fault
1256         cmpdi   r3,0
1257         beq+    .ret_from_except_lite
1258         bl      .save_nvgprs
1259         mr      r5,r3
1260         addi    r3,r1,STACK_FRAME_OVERHEAD
1261         lwz     r4,_DAR(r1)
1262         bl      .bad_page_fault
1263         b       .ret_from_except
1264
1265 /* We have a page fault that hash_page could handle but HV refused
1266  * the PTE insertion
1267  */
1268 12:     bl      .save_nvgprs
1269         addi    r3,r1,STACK_FRAME_OVERHEAD
1270         lwz     r4,_DAR(r1)
1271         bl      .low_hash_fault
1272         b       .ret_from_except
1273
1274         /* here we have a segment miss */
1275 _GLOBAL(do_ste_alloc)
1276         bl      .ste_allocate           /* try to insert stab entry */
1277         cmpdi   r3,0
1278         beq+    fast_exception_return
1279         b       .handle_page_fault
1280
1281 /*
1282  * r13 points to the PACA, r9 contains the saved CR,
1283  * r11 and r12 contain the saved SRR0 and SRR1.
1284  * r9 - r13 are saved in paca->exslb.
1285  * We assume we aren't going to take any exceptions during this procedure.
1286  * We assume (DAR >> 60) == 0xc.
1287  */
1288         .align  7
1289 _GLOBAL(do_stab_bolted)
1290         stw     r9,PACA_EXSLB+EX_CCR(r13)       /* save CR in exc. frame */
1291         std     r11,PACA_EXSLB+EX_SRR0(r13)     /* save SRR0 in exc. frame */
1292
1293         /* Hash to the primary group */
1294         ld      r10,PACASTABVIRT(r13)
1295         mfspr   r11,SPRN_DAR
1296         srdi    r11,r11,28
1297         rldimi  r10,r11,7,52    /* r10 = first ste of the group */
1298
1299         /* Calculate VSID */
1300         /* This is a kernel address, so protovsid = ESID */
1301         ASM_VSID_SCRAMBLE(r11, r9)
1302         rldic   r9,r11,12,16    /* r9 = vsid << 12 */
1303
1304         /* Search the primary group for a free entry */
1305 1:      ld      r11,0(r10)      /* Test valid bit of the current ste    */
1306         andi.   r11,r11,0x80
1307         beq     2f
1308         addi    r10,r10,16
1309         andi.   r11,r10,0x70
1310         bne     1b
1311
1312         /* Stick for only searching the primary group for now.          */
1313         /* At least for now, we use a very simple random castout scheme */
1314         /* Use the TB as a random number ;  OR in 1 to avoid entry 0    */
1315         mftb    r11
1316         rldic   r11,r11,4,57    /* r11 = (r11 << 4) & 0x70 */
1317         ori     r11,r11,0x10
1318
1319         /* r10 currently points to an ste one past the group of interest */
1320         /* make it point to the randomly selected entry                 */
1321         subi    r10,r10,128
1322         or      r10,r10,r11     /* r10 is the entry to invalidate       */
1323
1324         isync                   /* mark the entry invalid               */
1325         ld      r11,0(r10)
1326         rldicl  r11,r11,56,1    /* clear the valid bit */
1327         rotldi  r11,r11,8
1328         std     r11,0(r10)
1329         sync
1330
1331         clrrdi  r11,r11,28      /* Get the esid part of the ste         */
1332         slbie   r11
1333
1334 2:      std     r9,8(r10)       /* Store the vsid part of the ste       */
1335         eieio
1336
1337         mfspr   r11,SPRN_DAR            /* Get the new esid                     */
1338         clrrdi  r11,r11,28      /* Permits a full 32b of ESID           */
1339         ori     r11,r11,0x90    /* Turn on valid and kp                 */
1340         std     r11,0(r10)      /* Put new entry back into the stab     */
1341
1342         sync
1343
1344         /* All done -- return from exception. */
1345         lwz     r9,PACA_EXSLB+EX_CCR(r13)       /* get saved CR */
1346         ld      r11,PACA_EXSLB+EX_SRR0(r13)     /* get saved SRR0 */
1347
1348         andi.   r10,r12,MSR_RI
1349         beq-    unrecov_slb
1350
1351         mtcrf   0x80,r9                 /* restore CR */
1352
1353         mfmsr   r10
1354         clrrdi  r10,r10,2
1355         mtmsrd  r10,1
1356
1357         mtspr   SPRN_SRR0,r11
1358         mtspr   SPRN_SRR1,r12
1359         ld      r9,PACA_EXSLB+EX_R9(r13)
1360         ld      r10,PACA_EXSLB+EX_R10(r13)
1361         ld      r11,PACA_EXSLB+EX_R11(r13)
1362         ld      r12,PACA_EXSLB+EX_R12(r13)
1363         ld      r13,PACA_EXSLB+EX_R13(r13)
1364         rfid
1365         b       .       /* prevent speculative execution */
1366
1367 /*
1368  * Space for CPU0's segment table.
1369  *
1370  * On iSeries, the hypervisor must fill in at least one entry before
1371  * we get control (with relocate on).  The address is give to the hv
1372  * as a page number (see xLparMap in lpardata.c), so this must be at a
1373  * fixed address (the linker can't compute (u64)&initial_stab >>
1374  * PAGE_SHIFT).
1375  */
1376         . = STAB0_OFFSET        /* 0x6000 */
1377         .globl initial_stab
1378 initial_stab:
1379         .space  4096
1380
1381 /*
1382  * Data area reserved for FWNMI option.
1383  * This address (0x7000) is fixed by the RPA.
1384  */
1385         .= 0x7000
1386         .globl fwnmi_data_area
1387 fwnmi_data_area:
1388
1389         /* iSeries does not use the FWNMI stuff, so it is safe to put
1390          * this here, even if we later allow kernels that will boot on
1391          * both pSeries and iSeries */
1392 #ifdef CONFIG_PPC_ISERIES
1393         . = LPARMAP_PHYS
1394 #include "lparmap.s"
1395 /*
1396  * This ".text" is here for old compilers that generate a trailing
1397  * .note section when compiling .c files to .s
1398  */
1399         .text
1400 #endif /* CONFIG_PPC_ISERIES */
1401
1402         . = 0x8000
1403
1404 /*
1405  * On pSeries, secondary processors spin in the following code.
1406  * At entry, r3 = this processor's number (physical cpu id)
1407  */
1408 _GLOBAL(pSeries_secondary_smp_init)
1409         mr      r24,r3
1410         
1411         /* turn on 64-bit mode */
1412         bl      .enable_64b_mode
1413         isync
1414
1415         /* Copy some CPU settings from CPU 0 */
1416         bl      .__restore_cpu_setup
1417
1418         /* Set up a paca value for this processor. Since we have the
1419          * physical cpu id in r24, we need to search the pacas to find
1420          * which logical id maps to our physical one.
1421          */
1422         LOAD_REG_IMMEDIATE(r13, paca)   /* Get base vaddr of paca array  */
1423         li      r5,0                    /* logical cpu id                */
1424 1:      lhz     r6,PACAHWCPUID(r13)     /* Load HW procid from paca      */
1425         cmpw    r6,r24                  /* Compare to our id             */
1426         beq     2f
1427         addi    r13,r13,PACA_SIZE       /* Loop to next PACA on miss     */
1428         addi    r5,r5,1
1429         cmpwi   r5,NR_CPUS
1430         blt     1b
1431
1432         mr      r3,r24                  /* not found, copy phys to r3    */
1433         b       .kexec_wait             /* next kernel might do better   */
1434
1435 2:      mtspr   SPRN_SPRG3,r13          /* Save vaddr of paca in SPRG3   */
1436         /* From now on, r24 is expected to be logical cpuid */
1437         mr      r24,r5
1438 3:      HMT_LOW
1439         lbz     r23,PACAPROCSTART(r13)  /* Test if this processor should */
1440                                         /* start.                        */
1441         sync
1442
1443         /* Create a temp kernel stack for use before relocation is on.  */
1444         ld      r1,PACAEMERGSP(r13)
1445         subi    r1,r1,STACK_FRAME_OVERHEAD
1446
1447         cmpwi   0,r23,0
1448 #ifdef CONFIG_SMP
1449         bne     .__secondary_start
1450 #endif
1451         b       3b                      /* Loop until told to go         */
1452
1453 #ifdef CONFIG_PPC_ISERIES
1454 _STATIC(__start_initialization_iSeries)
1455         /* Clear out the BSS */
1456         LOAD_REG_IMMEDIATE(r11,__bss_stop)
1457         LOAD_REG_IMMEDIATE(r8,__bss_start)
1458         sub     r11,r11,r8              /* bss size                     */
1459         addi    r11,r11,7               /* round up to an even double word */
1460         rldicl. r11,r11,61,3            /* shift right by 3             */
1461         beq     4f
1462         addi    r8,r8,-8
1463         li      r0,0
1464         mtctr   r11                     /* zero this many doublewords   */
1465 3:      stdu    r0,8(r8)
1466         bdnz    3b
1467 4:
1468         LOAD_REG_IMMEDIATE(r1,init_thread_union)
1469         addi    r1,r1,THREAD_SIZE
1470         li      r0,0
1471         stdu    r0,-STACK_FRAME_OVERHEAD(r1)
1472
1473         LOAD_REG_IMMEDIATE(r3,cpu_specs)
1474         LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1475         li      r5,0
1476         bl      .identify_cpu
1477
1478         LOAD_REG_IMMEDIATE(r2,__toc_start)
1479         addi    r2,r2,0x4000
1480         addi    r2,r2,0x4000
1481
1482         bl      .iSeries_early_setup
1483         bl      .early_setup
1484
1485         /* relocation is on at this point */
1486
1487         b       .start_here_common
1488 #endif /* CONFIG_PPC_ISERIES */
1489
1490 #ifdef CONFIG_PPC_MULTIPLATFORM
1491
1492 _STATIC(__mmu_off)
1493         mfmsr   r3
1494         andi.   r0,r3,MSR_IR|MSR_DR
1495         beqlr
1496         andc    r3,r3,r0
1497         mtspr   SPRN_SRR0,r4
1498         mtspr   SPRN_SRR1,r3
1499         sync
1500         rfid
1501         b       .       /* prevent speculative execution */
1502
1503
1504 /*
1505  * Here is our main kernel entry point. We support currently 2 kind of entries
1506  * depending on the value of r5.
1507  *
1508  *   r5 != NULL -> OF entry, we go to prom_init, "legacy" parameter content
1509  *                 in r3...r7
1510  *   
1511  *   r5 == NULL -> kexec style entry. r3 is a physical pointer to the
1512  *                 DT block, r4 is a physical pointer to the kernel itself
1513  *
1514  */
1515 _GLOBAL(__start_initialization_multiplatform)
1516 #ifdef CONFIG_PPC_MULTIPLATFORM
1517         /*
1518          * Are we booted from a PROM Of-type client-interface ?
1519          */
1520         cmpldi  cr0,r5,0
1521         bne     .__boot_from_prom               /* yes -> prom */
1522 #endif
1523
1524         /* Save parameters */
1525         mr      r31,r3
1526         mr      r30,r4
1527
1528         /* Make sure we are running in 64 bits mode */
1529         bl      .enable_64b_mode
1530
1531         /* Setup some critical 970 SPRs before switching MMU off */
1532         bl      .__970_cpu_preinit
1533
1534         /* cpu # */
1535         li      r24,0
1536
1537         /* Switch off MMU if not already */
1538         LOAD_REG_IMMEDIATE(r4, .__after_prom_start - KERNELBASE)
1539         add     r4,r4,r30
1540         bl      .__mmu_off
1541         b       .__after_prom_start
1542
1543 #ifdef CONFIG_PPC_MULTIPLATFORM
1544 _STATIC(__boot_from_prom)
1545         /* Save parameters */
1546         mr      r31,r3
1547         mr      r30,r4
1548         mr      r29,r5
1549         mr      r28,r6
1550         mr      r27,r7
1551
1552         /* Make sure we are running in 64 bits mode */
1553         bl      .enable_64b_mode
1554
1555         /* put a relocation offset into r3 */
1556         bl      .reloc_offset
1557
1558         LOAD_REG_IMMEDIATE(r2,__toc_start)
1559         addi    r2,r2,0x4000
1560         addi    r2,r2,0x4000
1561
1562         /* Relocate the TOC from a virt addr to a real addr */
1563         add     r2,r2,r3
1564
1565         /* Restore parameters */
1566         mr      r3,r31
1567         mr      r4,r30
1568         mr      r5,r29
1569         mr      r6,r28
1570         mr      r7,r27
1571
1572         /* Do all of the interaction with OF client interface */
1573         bl      .prom_init
1574         /* We never return */
1575         trap
1576 #endif
1577
1578 /*
1579  * At this point, r3 contains the physical address we are running at,
1580  * returned by prom_init()
1581  */
1582 _STATIC(__after_prom_start)
1583
1584 /*
1585  * We need to run with __start at physical address PHYSICAL_START.
1586  * This will leave some code in the first 256B of
1587  * real memory, which are reserved for software use.
1588  * The remainder of the first page is loaded with the fixed
1589  * interrupt vectors.  The next two pages are filled with
1590  * unknown exception placeholders.
1591  *
1592  * Note: This process overwrites the OF exception vectors.
1593  *      r26 == relocation offset
1594  *      r27 == KERNELBASE
1595  */
1596         bl      .reloc_offset
1597         mr      r26,r3
1598         LOAD_REG_IMMEDIATE(r27, KERNELBASE)
1599
1600         LOAD_REG_IMMEDIATE(r3, PHYSICAL_START)  /* target addr */
1601
1602         // XXX FIXME: Use phys returned by OF (r30)
1603         add     r4,r27,r26              /* source addr                   */
1604                                         /* current address of _start     */
1605                                         /*   i.e. where we are running   */
1606                                         /*      the source addr          */
1607
1608         LOAD_REG_IMMEDIATE(r5,copy_to_here) /* # bytes of memory to copy */
1609         sub     r5,r5,r27
1610
1611         li      r6,0x100                /* Start offset, the first 0x100 */
1612                                         /* bytes were copied earlier.    */
1613
1614         bl      .copy_and_flush         /* copy the first n bytes        */
1615                                         /* this includes the code being  */
1616                                         /* executed here.                */
1617
1618         LOAD_REG_IMMEDIATE(r0, 4f)      /* Jump to the copy of this code */
1619         mtctr   r0                      /* that we just made/relocated   */
1620         bctr
1621
1622 4:      LOAD_REG_IMMEDIATE(r5,klimit)
1623         add     r5,r5,r26
1624         ld      r5,0(r5)                /* get the value of klimit */
1625         sub     r5,r5,r27
1626         bl      .copy_and_flush         /* copy the rest */
1627         b       .start_here_multiplatform
1628
1629 #endif /* CONFIG_PPC_MULTIPLATFORM */
1630
1631 /*
1632  * Copy routine used to copy the kernel to start at physical address 0
1633  * and flush and invalidate the caches as needed.
1634  * r3 = dest addr, r4 = source addr, r5 = copy limit, r6 = start offset
1635  * on exit, r3, r4, r5 are unchanged, r6 is updated to be >= r5.
1636  *
1637  * Note: this routine *only* clobbers r0, r6 and lr
1638  */
1639 _GLOBAL(copy_and_flush)
1640         addi    r5,r5,-8
1641         addi    r6,r6,-8
1642 4:      li      r0,16                   /* Use the least common         */
1643                                         /* denominator cache line       */
1644                                         /* size.  This results in       */
1645                                         /* extra cache line flushes     */
1646                                         /* but operation is correct.    */
1647                                         /* Can't get cache line size    */
1648                                         /* from NACA as it is being     */
1649                                         /* moved too.                   */
1650
1651         mtctr   r0                      /* put # words/line in ctr      */
1652 3:      addi    r6,r6,8                 /* copy a cache line            */
1653         ldx     r0,r6,r4
1654         stdx    r0,r6,r3
1655         bdnz    3b
1656         dcbst   r6,r3                   /* write it to memory           */
1657         sync
1658         icbi    r6,r3                   /* flush the icache line        */
1659         cmpld   0,r6,r5
1660         blt     4b
1661         sync
1662         addi    r5,r5,8
1663         addi    r6,r6,8
1664         blr
1665
1666 .align 8
1667 copy_to_here:
1668
1669 #ifdef CONFIG_SMP
1670 #ifdef CONFIG_PPC_PMAC
1671 /*
1672  * On PowerMac, secondary processors starts from the reset vector, which
1673  * is temporarily turned into a call to one of the functions below.
1674  */
1675         .section ".text";
1676         .align 2 ;
1677
1678         .globl  __secondary_start_pmac_0
1679 __secondary_start_pmac_0:
1680         /* NB the entries for cpus 0, 1, 2 must each occupy 8 bytes. */
1681         li      r24,0
1682         b       1f
1683         li      r24,1
1684         b       1f
1685         li      r24,2
1686         b       1f
1687         li      r24,3
1688 1:
1689         
1690 _GLOBAL(pmac_secondary_start)
1691         /* turn on 64-bit mode */
1692         bl      .enable_64b_mode
1693         isync
1694
1695         /* Copy some CPU settings from CPU 0 */
1696         bl      .__restore_cpu_setup
1697
1698         /* pSeries do that early though I don't think we really need it */
1699         mfmsr   r3
1700         ori     r3,r3,MSR_RI
1701         mtmsrd  r3                      /* RI on */
1702
1703         /* Set up a paca value for this processor. */
1704         LOAD_REG_IMMEDIATE(r4, paca)    /* Get base vaddr of paca array */
1705         mulli   r13,r24,PACA_SIZE        /* Calculate vaddr of right paca */
1706         add     r13,r13,r4              /* for this processor.          */
1707         mtspr   SPRN_SPRG3,r13           /* Save vaddr of paca in SPRG3 */
1708
1709         /* Create a temp kernel stack for use before relocation is on.  */
1710         ld      r1,PACAEMERGSP(r13)
1711         subi    r1,r1,STACK_FRAME_OVERHEAD
1712
1713         b       .__secondary_start
1714
1715 #endif /* CONFIG_PPC_PMAC */
1716
1717 /*
1718  * This function is called after the master CPU has released the
1719  * secondary processors.  The execution environment is relocation off.
1720  * The paca for this processor has the following fields initialized at
1721  * this point:
1722  *   1. Processor number
1723  *   2. Segment table pointer (virtual address)
1724  * On entry the following are set:
1725  *   r1 = stack pointer.  vaddr for iSeries, raddr (temp stack) for pSeries
1726  *   r24   = cpu# (in Linux terms)
1727  *   r13   = paca virtual address
1728  *   SPRG3 = paca virtual address
1729  */
1730 _GLOBAL(__secondary_start)
1731         /* Set thread priority to MEDIUM */
1732         HMT_MEDIUM
1733
1734         /* Load TOC */
1735         ld      r2,PACATOC(r13)
1736
1737         /* Do early setup for that CPU (stab, slb, hash table pointer) */
1738         bl      .early_setup_secondary
1739
1740         /* Initialize the kernel stack.  Just a repeat for iSeries.      */
1741         LOAD_REG_ADDR(r3, current_set)
1742         sldi    r28,r24,3               /* get current_set[cpu#]         */
1743         ldx     r1,r3,r28
1744         addi    r1,r1,THREAD_SIZE-STACK_FRAME_OVERHEAD
1745         std     r1,PACAKSAVE(r13)
1746
1747         /* Clear backchain so we get nice backtraces */
1748         li      r7,0
1749         mtlr    r7
1750
1751         /* enable MMU and jump to start_secondary */
1752         LOAD_REG_ADDR(r3, .start_secondary_prolog)
1753         LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1754 #ifdef DO_SOFT_DISABLE
1755         ori     r4,r4,MSR_EE
1756 #endif
1757         mtspr   SPRN_SRR0,r3
1758         mtspr   SPRN_SRR1,r4
1759         rfid
1760         b       .       /* prevent speculative execution */
1761
1762 /* 
1763  * Running with relocation on at this point.  All we want to do is
1764  * zero the stack back-chain pointer before going into C code.
1765  */
1766 _GLOBAL(start_secondary_prolog)
1767         li      r3,0
1768         std     r3,0(r1)                /* Zero the stack frame pointer */
1769         bl      .start_secondary
1770         b       .
1771 #endif
1772
1773 /*
1774  * This subroutine clobbers r11 and r12
1775  */
1776 _GLOBAL(enable_64b_mode)
1777         mfmsr   r11                     /* grab the current MSR */
1778         li      r12,1
1779         rldicr  r12,r12,MSR_SF_LG,(63-MSR_SF_LG)
1780         or      r11,r11,r12
1781         li      r12,1
1782         rldicr  r12,r12,MSR_ISF_LG,(63-MSR_ISF_LG)
1783         or      r11,r11,r12
1784         mtmsrd  r11
1785         isync
1786         blr
1787
1788 #ifdef CONFIG_PPC_MULTIPLATFORM
1789 /*
1790  * This is where the main kernel code starts.
1791  */
1792 _STATIC(start_here_multiplatform)
1793         /* get a new offset, now that the kernel has moved. */
1794         bl      .reloc_offset
1795         mr      r26,r3
1796
1797         /* Clear out the BSS. It may have been done in prom_init,
1798          * already but that's irrelevant since prom_init will soon
1799          * be detached from the kernel completely. Besides, we need
1800          * to clear it now for kexec-style entry.
1801          */
1802         LOAD_REG_IMMEDIATE(r11,__bss_stop)
1803         LOAD_REG_IMMEDIATE(r8,__bss_start)
1804         sub     r11,r11,r8              /* bss size                     */
1805         addi    r11,r11,7               /* round up to an even double word */
1806         rldicl. r11,r11,61,3            /* shift right by 3             */
1807         beq     4f
1808         addi    r8,r8,-8
1809         li      r0,0
1810         mtctr   r11                     /* zero this many doublewords   */
1811 3:      stdu    r0,8(r8)
1812         bdnz    3b
1813 4:
1814
1815         mfmsr   r6
1816         ori     r6,r6,MSR_RI
1817         mtmsrd  r6                      /* RI on */
1818
1819 #ifdef CONFIG_HMT
1820         /* Start up the second thread on cpu 0 */
1821         mfspr   r3,SPRN_PVR
1822         srwi    r3,r3,16
1823         cmpwi   r3,0x34                 /* Pulsar  */
1824         beq     90f
1825         cmpwi   r3,0x36                 /* Icestar */
1826         beq     90f
1827         cmpwi   r3,0x37                 /* SStar   */
1828         beq     90f
1829         b       91f                     /* HMT not supported */
1830 90:     li      r3,0
1831         bl      .hmt_start_secondary
1832 91:
1833 #endif
1834
1835         /* The following gets the stack and TOC set up with the regs */
1836         /* pointing to the real addr of the kernel stack.  This is   */
1837         /* all done to support the C function call below which sets  */
1838         /* up the htab.  This is done because we have relocated the  */
1839         /* kernel but are still running in real mode. */
1840
1841         LOAD_REG_IMMEDIATE(r3,init_thread_union)
1842         add     r3,r3,r26
1843
1844         /* set up a stack pointer (physical address) */
1845         addi    r1,r3,THREAD_SIZE
1846         li      r0,0
1847         stdu    r0,-STACK_FRAME_OVERHEAD(r1)
1848
1849         /* set up the TOC (physical address) */
1850         LOAD_REG_IMMEDIATE(r2,__toc_start)
1851         addi    r2,r2,0x4000
1852         addi    r2,r2,0x4000
1853         add     r2,r2,r26
1854
1855         LOAD_REG_IMMEDIATE(r3, cpu_specs)
1856         add     r3,r3,r26
1857         LOAD_REG_IMMEDIATE(r4,cur_cpu_spec)
1858         add     r4,r4,r26
1859         mr      r5,r26
1860         bl      .identify_cpu
1861
1862         /* Save some low level config HIDs of CPU0 to be copied to
1863          * other CPUs later on, or used for suspend/resume
1864          */
1865         bl      .__save_cpu_setup
1866         sync
1867
1868         /* Setup a valid physical PACA pointer in SPRG3 for early_setup
1869          * note that boot_cpuid can always be 0 nowadays since there is
1870          * nowhere it can be initialized differently before we reach this
1871          * code
1872          */
1873         LOAD_REG_IMMEDIATE(r27, boot_cpuid)
1874         add     r27,r27,r26
1875         lwz     r27,0(r27)
1876
1877         LOAD_REG_IMMEDIATE(r24, paca)   /* Get base vaddr of paca array  */
1878         mulli   r13,r27,PACA_SIZE       /* Calculate vaddr of right paca */
1879         add     r13,r13,r24             /* for this processor.           */
1880         add     r13,r13,r26             /* convert to physical addr      */
1881         mtspr   SPRN_SPRG3,r13
1882         
1883         /* Do very early kernel initializations, including initial hash table,
1884          * stab and slb setup before we turn on relocation.     */
1885
1886         /* Restore parameters passed from prom_init/kexec */
1887         mr      r3,r31
1888         bl      .early_setup
1889
1890         LOAD_REG_IMMEDIATE(r3, .start_here_common)
1891         LOAD_REG_IMMEDIATE(r4, MSR_KERNEL)
1892         mtspr   SPRN_SRR0,r3
1893         mtspr   SPRN_SRR1,r4
1894         rfid
1895         b       .       /* prevent speculative execution */
1896 #endif /* CONFIG_PPC_MULTIPLATFORM */
1897         
1898         /* This is where all platforms converge execution */
1899 _STATIC(start_here_common)
1900         /* relocation is on at this point */
1901
1902         /* The following code sets up the SP and TOC now that we are */
1903         /* running with translation enabled. */
1904
1905         LOAD_REG_IMMEDIATE(r3,init_thread_union)
1906
1907         /* set up the stack */
1908         addi    r1,r3,THREAD_SIZE
1909         li      r0,0
1910         stdu    r0,-STACK_FRAME_OVERHEAD(r1)
1911
1912         /* Apply the CPUs-specific fixups (nop out sections not relevant
1913          * to this CPU
1914          */
1915         li      r3,0
1916         bl      .do_cpu_ftr_fixups
1917
1918         LOAD_REG_IMMEDIATE(r26, boot_cpuid)
1919         lwz     r26,0(r26)
1920
1921         LOAD_REG_IMMEDIATE(r24, paca)   /* Get base vaddr of paca array  */
1922         mulli   r13,r26,PACA_SIZE       /* Calculate vaddr of right paca */
1923         add     r13,r13,r24             /* for this processor.           */
1924         mtspr   SPRN_SPRG3,r13
1925
1926         /* ptr to current */
1927         LOAD_REG_IMMEDIATE(r4, init_task)
1928         std     r4,PACACURRENT(r13)
1929
1930         /* Load the TOC */
1931         ld      r2,PACATOC(r13)
1932         std     r1,PACAKSAVE(r13)
1933
1934         bl      .setup_system
1935
1936         /* Load up the kernel context */
1937 5:
1938 #ifdef DO_SOFT_DISABLE
1939         li      r5,0
1940         stb     r5,PACAPROCENABLED(r13) /* Soft Disabled */
1941         mfmsr   r5
1942         ori     r5,r5,MSR_EE            /* Hard Enabled */
1943         mtmsrd  r5
1944 #endif
1945
1946         bl .start_kernel
1947
1948 _GLOBAL(hmt_init)
1949 #ifdef CONFIG_HMT
1950         LOAD_REG_IMMEDIATE(r5, hmt_thread_data)
1951         mfspr   r7,SPRN_PVR
1952         srwi    r7,r7,16
1953         cmpwi   r7,0x34                 /* Pulsar  */
1954         beq     90f
1955         cmpwi   r7,0x36                 /* Icestar */
1956         beq     91f
1957         cmpwi   r7,0x37                 /* SStar   */
1958         beq     91f
1959         b       101f
1960 90:     mfspr   r6,SPRN_PIR
1961         andi.   r6,r6,0x1f
1962         b       92f
1963 91:     mfspr   r6,SPRN_PIR
1964         andi.   r6,r6,0x3ff
1965 92:     sldi    r4,r24,3
1966         stwx    r6,r5,r4
1967         bl      .hmt_start_secondary
1968         b       101f
1969
1970 __hmt_secondary_hold:
1971         LOAD_REG_IMMEDIATE(r5, hmt_thread_data)
1972         clrldi  r5,r5,4
1973         li      r7,0
1974         mfspr   r6,SPRN_PIR
1975         mfspr   r8,SPRN_PVR
1976         srwi    r8,r8,16
1977         cmpwi   r8,0x34
1978         bne     93f
1979         andi.   r6,r6,0x1f
1980         b       103f
1981 93:     andi.   r6,r6,0x3f
1982
1983 103:    lwzx    r8,r5,r7
1984         cmpw    r8,r6
1985         beq     104f
1986         addi    r7,r7,8
1987         b       103b
1988
1989 104:    addi    r7,r7,4
1990         lwzx    r9,r5,r7
1991         mr      r24,r9
1992 101:
1993 #endif
1994         mr      r3,r24
1995         b       .pSeries_secondary_smp_init
1996
1997 #ifdef CONFIG_HMT
1998 _GLOBAL(hmt_start_secondary)
1999         LOAD_REG_IMMEDIATE(r4,__hmt_secondary_hold)
2000         clrldi  r4,r4,4
2001         mtspr   SPRN_NIADORM, r4
2002         mfspr   r4, SPRN_MSRDORM
2003         li      r5, -65
2004         and     r4, r4, r5
2005         mtspr   SPRN_MSRDORM, r4
2006         lis     r4,0xffef
2007         ori     r4,r4,0x7403
2008         mtspr   SPRN_TSC, r4
2009         li      r4,0x1f4
2010         mtspr   SPRN_TST, r4
2011         mfspr   r4, SPRN_HID0
2012         ori     r4, r4, 0x1
2013         mtspr   SPRN_HID0, r4
2014         mfspr   r4, SPRN_CTRLF
2015         oris    r4, r4, 0x40
2016         mtspr   SPRN_CTRLT, r4
2017         blr
2018 #endif
2019
2020 /*
2021  * We put a few things here that have to be page-aligned.
2022  * This stuff goes at the beginning of the bss, which is page-aligned.
2023  */
2024         .section ".bss"
2025
2026         .align  PAGE_SHIFT
2027
2028         .globl  empty_zero_page
2029 empty_zero_page:
2030         .space  PAGE_SIZE
2031
2032         .globl  swapper_pg_dir
2033 swapper_pg_dir:
2034         .space  PAGE_SIZE
2035
2036 /*
2037  * This space gets a copy of optional info passed to us by the bootstrap
2038  * Used to pass parameters into the kernel like root=/dev/sda1, etc.
2039  */
2040         .globl  cmd_line
2041 cmd_line:
2042         .space  COMMAND_LINE_SIZE