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