vserver 1.9.5.x5
[linux-2.6.git] / arch / ppc / kernel / head_e500.S
1 /*
2  * arch/ppc/kernel/head_e500.S
3  *
4  * Kernel execution entry point code.
5  *
6  *    Copyright (c) 1995-1996 Gary Thomas <gdt@linuxppc.org>
7  *      Initial PowerPC version.
8  *    Copyright (c) 1996 Cort Dougan <cort@cs.nmt.edu>
9  *      Rewritten for PReP
10  *    Copyright (c) 1996 Paul Mackerras <paulus@cs.anu.edu.au>
11  *      Low-level exception handers, MMU support, and rewrite.
12  *    Copyright (c) 1997 Dan Malek <dmalek@jlc.net>
13  *      PowerPC 8xx modifications.
14  *    Copyright (c) 1998-1999 TiVo, Inc.
15  *      PowerPC 403GCX modifications.
16  *    Copyright (c) 1999 Grant Erickson <grant@lcse.umn.edu>
17  *      PowerPC 403GCX/405GP modifications.
18  *    Copyright 2000 MontaVista Software Inc.
19  *      PPC405 modifications
20  *      PowerPC 403GCX/405GP modifications.
21  *      Author: MontaVista Software, Inc.
22  *              frank_rowand@mvista.com or source@mvista.com
23  *              debbie_chu@mvista.com
24  *    Copyright 2002-2004 MontaVista Software, Inc.
25  *      PowerPC 44x support, Matt Porter <mporter@kernel.crashing.org>
26  *    Copyright 2004 Freescale Semiconductor, Inc
27  *      PowerPC e500 modifications, Kumar Gala <kumar.gala@freescale.com>
28  *
29  * This program is free software; you can redistribute  it and/or modify it
30  * under  the terms of  the GNU General  Public License as published by the
31  * Free Software Foundation;  either version 2 of the  License, or (at your
32  * option) any later version.
33  */
34
35 #include <linux/config.h>
36 #include <asm/processor.h>
37 #include <asm/page.h>
38 #include <asm/mmu.h>
39 #include <asm/pgtable.h>
40 #include <asm/cputable.h>
41 #include <asm/thread_info.h>
42 #include <asm/ppc_asm.h>
43 #include <asm/offsets.h>
44 #include "head_booke.h"
45
46 /* As with the other PowerPC ports, it is expected that when code
47  * execution begins here, the following registers contain valid, yet
48  * optional, information:
49  *
50  *   r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
51  *   r4 - Starting address of the init RAM disk
52  *   r5 - Ending address of the init RAM disk
53  *   r6 - Start of kernel command line string (e.g. "mem=128")
54  *   r7 - End of kernel command line string
55  *
56  */
57         .text
58 _GLOBAL(_stext)
59 _GLOBAL(_start)
60         /*
61          * Reserve a word at a fixed location to store the address
62          * of abatron_pteptrs
63          */
64         nop
65 /*
66  * Save parameters we are passed
67  */
68         mr      r31,r3
69         mr      r30,r4
70         mr      r29,r5
71         mr      r28,r6
72         mr      r27,r7
73         li      r24,0           /* CPU number */
74
75 /* We try to not make any assumptions about how the boot loader
76  * setup or used the TLBs.  We invalidate all mappings from the
77  * boot loader and load a single entry in TLB1[0] to map the
78  * first 16M of kernel memory.  Any boot info passed from the
79  * bootloader needs to live in this first 16M.
80  *
81  * Requirement on bootloader:
82  *  - The page we're executing in needs to reside in TLB1 and
83  *    have IPROT=1.  If not an invalidate broadcast could
84  *    evict the entry we're currently executing in.
85  *
86  *  r3 = Index of TLB1 were executing in
87  *  r4 = Current MSR[IS]
88  *  r5 = Index of TLB1 temp mapping
89  *
90  * Later in mapin_ram we will correctly map lowmem, and resize TLB1[0]
91  * if needed
92  */
93
94 /* 1. Find the index of the entry we're executing in */
95         bl      invstr                          /* Find our address */
96 invstr: mflr    r6                              /* Make it accessible */
97         mfmsr   r7
98         rlwinm  r4,r7,27,31,31                  /* extract MSR[IS] */
99         mfspr   r7, SPRN_PID0
100         slwi    r7,r7,16
101         or      r7,r7,r4
102         mtspr   SPRN_MAS6,r7
103         tlbsx   0,r6                            /* search MSR[IS], SPID=PID0 */
104         mfspr   r7,SPRN_MAS1
105         andis.  r7,r7,MAS1_VALID@h
106         bne     match_TLB
107         mfspr   r7,SPRN_PID1
108         slwi    r7,r7,16
109         or      r7,r7,r4
110         mtspr   SPRN_MAS6,r7
111         tlbsx   0,r6                            /* search MSR[IS], SPID=PID1 */
112         mfspr   r7,SPRN_MAS1
113         andis.  r7,r7,MAS1_VALID@h
114         bne     match_TLB
115         mfspr   r7, SPRN_PID2
116         slwi    r7,r7,16
117         or      r7,r7,r4
118         mtspr   SPRN_MAS6,r7
119         tlbsx   0,r6                            /* Fall through, we had to match */
120 match_TLB:
121         mfspr   r7,SPRN_MAS0
122         rlwinm  r3,r7,16,20,31                  /* Extract MAS0(Entry) */
123
124         mfspr   r7,SPRN_MAS1                    /* Insure IPROT set */
125         oris    r7,r7,MAS1_IPROT@h
126         mtspr   SPRN_MAS1,r7
127         tlbwe
128
129 /* 2. Invalidate all entries except the entry we're executing in */
130         mfspr   r9,SPRN_TLB1CFG
131         andi.   r9,r9,0xfff
132         li      r6,0                            /* Set Entry counter to 0 */
133 1:      lis     r7,0x1000                       /* Set MAS0(TLBSEL) = 1 */
134         rlwimi  r7,r6,16,4,15                   /* Setup MAS0 = TLBSEL | ESEL(r6) */
135         mtspr   SPRN_MAS0,r7
136         tlbre
137         mfspr   r7,SPRN_MAS1
138         rlwinm  r7,r7,0,2,31                    /* Clear MAS1 Valid and IPROT */
139         cmpw    r3,r6
140         beq     skpinv                          /* Dont update the current execution TLB */
141         mtspr   SPRN_MAS1,r7
142         tlbwe
143         isync
144 skpinv: addi    r6,r6,1                         /* Increment */
145         cmpw    r6,r9                           /* Are we done? */
146         bne     1b                              /* If not, repeat */
147
148         /* Invalidate TLB0 */
149         li      r6,0x04
150         tlbivax 0,r6
151 #ifdef CONFIG_SMP
152         tlbsync
153 #endif
154         /* Invalidate TLB1 */
155         li      r6,0x0c
156         tlbivax 0,r6
157 #ifdef CONFIG_SMP
158         tlbsync
159 #endif
160         msync
161
162 /* 3. Setup a temp mapping and jump to it */
163         andi.   r5, r3, 0x1     /* Find an entry not used and is non-zero */
164         addi    r5, r5, 0x1
165         lis     r7,0x1000       /* Set MAS0(TLBSEL) = 1 */
166         rlwimi  r7,r3,16,4,15   /* Setup MAS0 = TLBSEL | ESEL(r3) */
167         mtspr   SPRN_MAS0,r7
168         tlbre
169
170         /* Just modify the entry ID and EPN for the temp mapping */
171         lis     r7,0x1000       /* Set MAS0(TLBSEL) = 1 */
172         rlwimi  r7,r5,16,4,15   /* Setup MAS0 = TLBSEL | ESEL(r5) */
173         mtspr   SPRN_MAS0,r7
174         xori    r6,r4,1         /* Setup TMP mapping in the other Address space */
175         slwi    r6,r6,12
176         oris    r6,r6,(MAS1_VALID|MAS1_IPROT)@h
177         ori     r6,r6,(MAS1_TSIZE(BOOKE_PAGESZ_4K))@l
178         mtspr   SPRN_MAS1,r6
179         mfspr   r6,SPRN_MAS2
180         li      r7,0            /* temp EPN = 0 */
181         rlwimi  r7,r6,0,20,31
182         mtspr   SPRN_MAS2,r7
183         tlbwe
184
185         xori    r6,r4,1
186         slwi    r6,r6,5         /* setup new context with other address space */
187         bl      1f              /* Find our address */
188 1:      mflr    r9
189         rlwimi  r7,r9,0,20,31
190         addi    r7,r7,24
191         mtspr   SRR0,r7
192         mtspr   SRR1,r6
193         rfi
194
195 /* 4. Clear out PIDs & Search info */
196         li      r6,0
197         mtspr   SPRN_PID0,r6
198         mtspr   SPRN_PID1,r6
199         mtspr   SPRN_PID2,r6
200         mtspr   SPRN_MAS6,r6
201
202 /* 5. Invalidate mapping we started in */
203         lis     r7,0x1000       /* Set MAS0(TLBSEL) = 1 */
204         rlwimi  r7,r3,16,4,15   /* Setup MAS0 = TLBSEL | ESEL(r3) */
205         mtspr   SPRN_MAS0,r7
206         tlbre
207         li      r6,0
208         mtspr   SPRN_MAS1,r6
209         tlbwe
210         /* Invalidate TLB1 */
211         li      r9,0x0c
212         tlbivax 0,r9
213 #ifdef CONFIG_SMP
214         tlbsync
215 #endif
216         msync
217
218 /* 6. Setup KERNELBASE mapping in TLB1[0] */
219         lis     r6,0x1000               /* Set MAS0(TLBSEL) = TLB1(1), ESEL = 0 */
220         mtspr   SPRN_MAS0,r6
221         lis     r6,(MAS1_VALID|MAS1_IPROT)@h
222         ori     r6,r6,(MAS1_TSIZE(BOOKE_PAGESZ_16M))@l
223         mtspr   SPRN_MAS1,r6
224         li      r7,0
225         lis     r6,KERNELBASE@h
226         ori     r6,r6,KERNELBASE@l
227         rlwimi  r6,r7,0,20,31
228         mtspr   SPRN_MAS2,r6
229         li      r7,(MAS3_SX|MAS3_SW|MAS3_SR)
230         mtspr   SPRN_MAS3,r7
231         tlbwe
232
233 /* 7. Jump to KERNELBASE mapping */
234         li      r7,0
235         bl      1f                      /* Find our address */
236 1:      mflr    r9
237         rlwimi  r6,r9,0,20,31
238         addi    r6,r6,24
239         mtspr   SRR0,r6
240         mtspr   SRR1,r7
241         rfi                             /* start execution out of TLB1[0] entry */
242
243 /* 8. Clear out the temp mapping */
244         lis     r7,0x1000       /* Set MAS0(TLBSEL) = 1 */
245         rlwimi  r7,r5,16,4,15   /* Setup MAS0 = TLBSEL | ESEL(r5) */
246         mtspr   SPRN_MAS0,r7
247         tlbre
248         mtspr   SPRN_MAS1,r8
249         tlbwe
250         /* Invalidate TLB1 */
251         li      r9,0x0c
252         tlbivax 0,r9
253 #ifdef CONFIG_SMP
254         tlbsync
255 #endif
256         msync
257
258         /* Establish the interrupt vector offsets */
259         SET_IVOR(0,  CriticalInput);
260         SET_IVOR(1,  MachineCheck);
261         SET_IVOR(2,  DataStorage);
262         SET_IVOR(3,  InstructionStorage);
263         SET_IVOR(4,  ExternalInput);
264         SET_IVOR(5,  Alignment);
265         SET_IVOR(6,  Program);
266         SET_IVOR(7,  FloatingPointUnavailable);
267         SET_IVOR(8,  SystemCall);
268         SET_IVOR(9,  AuxillaryProcessorUnavailable);
269         SET_IVOR(10, Decrementer);
270         SET_IVOR(11, FixedIntervalTimer);
271         SET_IVOR(12, WatchdogTimer);
272         SET_IVOR(13, DataTLBError);
273         SET_IVOR(14, InstructionTLBError);
274         SET_IVOR(15, Debug);
275         SET_IVOR(32, SPEUnavailable);
276         SET_IVOR(33, SPEFloatingPointData);
277         SET_IVOR(34, SPEFloatingPointRound);
278         SET_IVOR(35, PerformanceMonitor);
279
280         /* Establish the interrupt vector base */
281         lis     r4,interrupt_base@h     /* IVPR only uses the high 16-bits */
282         mtspr   SPRN_IVPR,r4
283
284         /* Setup the defaults for TLB entries */
285         li      r2,(MAS4_TSIZED(BOOKE_PAGESZ_4K))@l
286         mtspr   SPRN_MAS4, r2
287
288 #if 0
289         /* Enable DOZE */
290         mfspr   r2,SPRN_HID0
291         oris    r2,r2,HID0_DOZE@h
292         mtspr   SPRN_HID0, r2
293 #endif
294
295         /*
296          * This is where the main kernel code starts.
297          */
298
299         /* ptr to current */
300         lis     r2,init_task@h
301         ori     r2,r2,init_task@l
302
303         /* ptr to current thread */
304         addi    r4,r2,THREAD    /* init task's THREAD */
305         mtspr   SPRG3,r4
306
307         /* stack */
308         lis     r1,init_thread_union@h
309         ori     r1,r1,init_thread_union@l
310         li      r0,0
311         stwu    r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
312
313         bl      early_init
314
315         mfspr   r3,SPRN_TLB1CFG
316         andi.   r3,r3,0xfff
317         lis     r4,num_tlbcam_entries@ha
318         stw     r3,num_tlbcam_entries@l(r4)
319 /*
320  * Decide what sort of machine this is and initialize the MMU.
321  */
322         mr      r3,r31
323         mr      r4,r30
324         mr      r5,r29
325         mr      r6,r28
326         mr      r7,r27
327         bl      machine_init
328         bl      MMU_init
329
330         /* Setup PTE pointers for the Abatron bdiGDB */
331         lis     r6, swapper_pg_dir@h
332         ori     r6, r6, swapper_pg_dir@l
333         lis     r5, abatron_pteptrs@h
334         ori     r5, r5, abatron_pteptrs@l
335         lis     r4, KERNELBASE@h
336         ori     r4, r4, KERNELBASE@l
337         stw     r5, 0(r4)       /* Save abatron_pteptrs at a fixed location */
338         stw     r6, 0(r5)
339
340         /* Let's move on */
341         lis     r4,start_kernel@h
342         ori     r4,r4,start_kernel@l
343         lis     r3,MSR_KERNEL@h
344         ori     r3,r3,MSR_KERNEL@l
345         mtspr   SRR0,r4
346         mtspr   SRR1,r3
347         rfi                     /* change context and jump to start_kernel */
348
349 /*
350  * Interrupt vector entry code
351  *
352  * The Book E MMUs are always on so we don't need to handle
353  * interrupts in real mode as with previous PPC processors. In
354  * this case we handle interrupts in the kernel virtual address
355  * space.
356  *
357  * Interrupt vectors are dynamically placed relative to the
358  * interrupt prefix as determined by the address of interrupt_base.
359  * The interrupt vectors offsets are programmed using the labels
360  * for each interrupt vector entry.
361  *
362  * Interrupt vectors must be aligned on a 16 byte boundary.
363  * We align on a 32 byte cache line boundary for good measure.
364  */
365
366 interrupt_base:
367         /* Critical Input Interrupt */
368         CRITICAL_EXCEPTION(0x0100, CriticalInput, UnknownException)
369
370         /* Machine Check Interrupt */
371         MCHECK_EXCEPTION(0x0200, MachineCheck, MachineCheckException)
372
373         /* Data Storage Interrupt */
374         START_EXCEPTION(DataStorage)
375         mtspr   SPRG0, r10              /* Save some working registers */
376         mtspr   SPRG1, r11
377         mtspr   SPRG4W, r12
378         mtspr   SPRG5W, r13
379         mfcr    r11
380         mtspr   SPRG7W, r11
381
382         /*
383          * Check if it was a store fault, if not then bail
384          * because a user tried to access a kernel or
385          * read-protected page.  Otherwise, get the
386          * offending address and handle it.
387          */
388         mfspr   r10, SPRN_ESR
389         andis.  r10, r10, ESR_ST@h
390         beq     2f
391
392         mfspr   r10, SPRN_DEAR          /* Get faulting address */
393
394         /* If we are faulting a kernel address, we have to use the
395          * kernel page tables.
396          */
397         lis     r11, TASK_SIZE@h
398         ori     r11, r11, TASK_SIZE@l
399         cmplw   0, r10, r11
400         bge     2f
401
402         /* Get the PGD for the current thread */
403 3:
404         mfspr   r11,SPRG3
405         lwz     r11,PGDIR(r11)
406 4:
407         rlwimi  r11, r10, 12, 20, 29    /* Create L1 (pgdir/pmd) address */
408         lwz     r11, 0(r11)             /* Get L1 entry */
409         rlwinm. r12, r11, 0, 0, 19      /* Extract L2 (pte) base address */
410         beq     2f                      /* Bail if no table */
411
412         rlwimi  r12, r10, 22, 20, 29    /* Compute PTE address */
413         lwz     r11, 0(r12)             /* Get Linux PTE */
414
415         /* Are _PAGE_USER & _PAGE_RW set & _PAGE_HWWRITE not? */
416         andi.   r13, r11, _PAGE_RW|_PAGE_USER|_PAGE_HWWRITE
417         cmpwi   0, r13, _PAGE_RW|_PAGE_USER
418         bne     2f                      /* Bail if not */
419
420         /* Update 'changed'. */
421         ori     r11, r11, _PAGE_DIRTY|_PAGE_ACCESSED|_PAGE_HWWRITE
422         stw     r11, 0(r12)             /* Update Linux page table */
423
424         /* MAS2 not updated as the entry does exist in the tlb, this
425            fault taken to detect state transition (eg: COW -> DIRTY)
426          */
427         lis     r12, MAS3_RPN@h
428         ori     r12, r12, _PAGE_HWEXEC | MAS3_RPN@l
429         and     r11, r11, r12
430         rlwimi  r11, r11, 31, 27, 27    /* SX <- _PAGE_HWEXEC */
431         ori     r11, r11, (MAS3_UW|MAS3_SW|MAS3_UR|MAS3_SR)@l /* set static perms */
432
433         /* update search PID in MAS6, AS = 0 */
434         mfspr   r12, SPRN_PID0
435         slwi    r12, r12, 16
436         mtspr   SPRN_MAS6, r12
437
438         /* find the TLB index that caused the fault.  It has to be here. */
439         tlbsx   0, r10
440
441         mtspr   SPRN_MAS3,r11
442         tlbwe
443
444         /* Done...restore registers and get out of here.  */
445         mfspr   r11, SPRG7R
446         mtcr    r11
447         mfspr   r13, SPRG5R
448         mfspr   r12, SPRG4R
449         mfspr   r11, SPRG1
450         mfspr   r10, SPRG0
451         rfi                     /* Force context change */
452
453 2:
454         /*
455          * The bailout.  Restore registers to pre-exception conditions
456          * and call the heavyweights to help us out.
457          */
458         mfspr   r11, SPRG7R
459         mtcr    r11
460         mfspr   r13, SPRG5R
461         mfspr   r12, SPRG4R
462         mfspr   r11, SPRG1
463         mfspr   r10, SPRG0
464         b       data_access
465
466         /* Instruction Storage Interrupt */
467         INSTRUCTION_STORAGE_EXCEPTION
468
469         /* External Input Interrupt */
470         EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE)
471
472         /* Alignment Interrupt */
473         ALIGNMENT_EXCEPTION
474
475         /* Program Interrupt */
476         PROGRAM_EXCEPTION
477
478         /* Floating Point Unavailable Interrupt */
479         EXCEPTION(0x0800, FloatingPointUnavailable, UnknownException, EXC_XFER_EE)
480
481         /* System Call Interrupt */
482         START_EXCEPTION(SystemCall)
483         NORMAL_EXCEPTION_PROLOG
484         EXC_XFER_EE_LITE(0x0c00, DoSyscall)
485
486         /* Auxillary Processor Unavailable Interrupt */
487         EXCEPTION(0x2900, AuxillaryProcessorUnavailable, UnknownException, EXC_XFER_EE)
488
489         /* Decrementer Interrupt */
490         DECREMENTER_EXCEPTION
491
492         /* Fixed Internal Timer Interrupt */
493         /* TODO: Add FIT support */
494         EXCEPTION(0x3100, FixedIntervalTimer, UnknownException, EXC_XFER_EE)
495
496         /* Watchdog Timer Interrupt */
497         /* TODO: Add watchdog support */
498         CRITICAL_EXCEPTION(0x3200, WatchdogTimer, UnknownException)
499
500         /* Data TLB Error Interrupt */
501         START_EXCEPTION(DataTLBError)
502         mtspr   SPRG0, r10              /* Save some working registers */
503         mtspr   SPRG1, r11
504         mtspr   SPRG4W, r12
505         mtspr   SPRG5W, r13
506         mfcr    r11
507         mtspr   SPRG7W, r11
508         mfspr   r10, SPRN_DEAR          /* Get faulting address */
509
510         /* If we are faulting a kernel address, we have to use the
511          * kernel page tables.
512          */
513         lis     r11, TASK_SIZE@h
514         ori     r11, r11, TASK_SIZE@l
515         cmplw   5, r10, r11
516         blt     5, 3f
517         lis     r11, swapper_pg_dir@h
518         ori     r11, r11, swapper_pg_dir@l
519
520         mfspr   r12,SPRN_MAS1           /* Set TID to 0 */
521         rlwinm  r12,r12,0,16,1
522         mtspr   SPRN_MAS1,r12
523
524         b       4f
525
526         /* Get the PGD for the current thread */
527 3:
528         mfspr   r11,SPRG3
529         lwz     r11,PGDIR(r11)
530
531 4:
532         rlwimi  r11, r10, 12, 20, 29    /* Create L1 (pgdir/pmd) address */
533         lwz     r11, 0(r11)             /* Get L1 entry */
534         rlwinm. r12, r11, 0, 0, 19      /* Extract L2 (pte) base address */
535         beq     2f                      /* Bail if no table */
536
537         rlwimi  r12, r10, 22, 20, 29    /* Compute PTE address */
538         lwz     r11, 0(r12)             /* Get Linux PTE */
539         andi.   r13, r11, _PAGE_PRESENT
540         beq     2f
541
542         ori     r11, r11, _PAGE_ACCESSED
543         stw     r11, 0(r12)
544
545          /* Jump to common tlb load */
546         b       finish_tlb_load
547 2:
548         /* The bailout.  Restore registers to pre-exception conditions
549          * and call the heavyweights to help us out.
550          */
551         mfspr   r11, SPRG7R
552         mtcr    r11
553         mfspr   r13, SPRG5R
554         mfspr   r12, SPRG4R
555         mfspr   r11, SPRG1
556         mfspr   r10, SPRG0
557         b       data_access
558
559         /* Instruction TLB Error Interrupt */
560         /*
561          * Nearly the same as above, except we get our
562          * information from different registers and bailout
563          * to a different point.
564          */
565         START_EXCEPTION(InstructionTLBError)
566         mtspr   SPRG0, r10              /* Save some working registers */
567         mtspr   SPRG1, r11
568         mtspr   SPRG4W, r12
569         mtspr   SPRG5W, r13
570         mfcr    r11
571         mtspr   SPRG7W, r11
572         mfspr   r10, SRR0               /* Get faulting address */
573
574         /* If we are faulting a kernel address, we have to use the
575          * kernel page tables.
576          */
577         lis     r11, TASK_SIZE@h
578         ori     r11, r11, TASK_SIZE@l
579         cmplw   5, r10, r11
580         blt     5, 3f
581         lis     r11, swapper_pg_dir@h
582         ori     r11, r11, swapper_pg_dir@l
583
584         mfspr   r12,SPRN_MAS1           /* Set TID to 0 */
585         rlwinm  r12,r12,0,16,1
586         mtspr   SPRN_MAS1,r12
587
588         b       4f
589
590         /* Get the PGD for the current thread */
591 3:
592         mfspr   r11,SPRG3
593         lwz     r11,PGDIR(r11)
594
595 4:
596         rlwimi  r11, r10, 12, 20, 29    /* Create L1 (pgdir/pmd) address */
597         lwz     r11, 0(r11)             /* Get L1 entry */
598         rlwinm. r12, r11, 0, 0, 19      /* Extract L2 (pte) base address */
599         beq     2f                      /* Bail if no table */
600
601         rlwimi  r12, r10, 22, 20, 29    /* Compute PTE address */
602         lwz     r11, 0(r12)             /* Get Linux PTE */
603         andi.   r13, r11, _PAGE_PRESENT
604         beq     2f
605
606         ori     r11, r11, _PAGE_ACCESSED
607         stw     r11, 0(r12)
608
609         /* Jump to common TLB load point */
610         b       finish_tlb_load
611
612 2:
613         /* The bailout.  Restore registers to pre-exception conditions
614          * and call the heavyweights to help us out.
615          */
616         mfspr   r11, SPRG7R
617         mtcr    r11
618         mfspr   r13, SPRG5R
619         mfspr   r12, SPRG4R
620         mfspr   r11, SPRG1
621         mfspr   r10, SPRG0
622         b       InstructionStorage
623
624 #ifdef CONFIG_SPE
625         /* SPE Unavailable */
626         START_EXCEPTION(SPEUnavailable)
627         NORMAL_EXCEPTION_PROLOG
628         bne     load_up_spe
629         addi    r3,r1,STACK_FRAME_OVERHEAD
630         EXC_XFER_EE_LITE(0x2010, KernelSPE)
631 #else
632         EXCEPTION(0x2020, SPEUnavailable, UnknownException, EXC_XFER_EE)
633 #endif /* CONFIG_SPE */
634
635         /* SPE Floating Point Data */
636 #ifdef CONFIG_SPE
637         EXCEPTION(0x2030, SPEFloatingPointData, SPEFloatingPointException, EXC_XFER_EE);
638 #else
639         EXCEPTION(0x2040, SPEFloatingPointData, UnknownException, EXC_XFER_EE)
640 #endif /* CONFIG_SPE */
641
642         /* SPE Floating Point Round */
643         EXCEPTION(0x2050, SPEFloatingPointRound, UnknownException, EXC_XFER_EE)
644
645         /* Performance Monitor */
646         EXCEPTION(0x2060, PerformanceMonitor, PerformanceMonitorException, EXC_XFER_STD)
647
648
649         /* Debug Interrupt */
650         DEBUG_EXCEPTION
651
652 /*
653  * Local functions
654  */
655         /*
656          * Data TLB exceptions will bail out to this point
657          * if they can't resolve the lightweight TLB fault.
658          */
659 data_access:
660         NORMAL_EXCEPTION_PROLOG
661         mfspr   r5,SPRN_ESR             /* Grab the ESR, save it, pass arg3 */
662         stw     r5,_ESR(r11)
663         mfspr   r4,SPRN_DEAR            /* Grab the DEAR, save it, pass arg2 */
664         andis.  r10,r5,(ESR_ILK|ESR_DLK)@h
665         bne     1f
666         EXC_XFER_EE_LITE(0x0300, handle_page_fault)
667 1:
668         addi    r3,r1,STACK_FRAME_OVERHEAD
669         EXC_XFER_EE_LITE(0x0300, CacheLockingException)
670
671 /*
672
673  * Both the instruction and data TLB miss get to this
674  * point to load the TLB.
675  *      r10 - EA of fault
676  *      r11 - TLB (info from Linux PTE)
677  *      r12, r13 - available to use
678  *      CR5 - results of addr < TASK_SIZE
679  *      MAS0, MAS1 - loaded with proper value when we get here
680  *      MAS2, MAS3 - will need additional info from Linux PTE
681  *      Upon exit, we reload everything and RFI.
682  */
683 finish_tlb_load:
684         /*
685          * We set execute, because we don't have the granularity to
686          * properly set this at the page level (Linux problem).
687          * Many of these bits are software only.  Bits we don't set
688          * here we (properly should) assume have the appropriate value.
689          */
690
691         mfspr   r12, SPRN_MAS2
692         rlwimi  r12, r11, 26, 27, 31    /* extract WIMGE from pte */
693         mtspr   SPRN_MAS2, r12
694
695         bge     5, 1f
696
697         /* addr > TASK_SIZE */
698         li      r10, (MAS3_UX | MAS3_UW | MAS3_UR)
699         andi.   r13, r11, (_PAGE_USER | _PAGE_HWWRITE | _PAGE_HWEXEC)
700         andi.   r12, r11, _PAGE_USER    /* Test for _PAGE_USER */
701         iseleq  r12, 0, r10
702         and     r10, r12, r13
703         srwi    r12, r10, 1
704         or      r12, r12, r10   /* Copy user perms into supervisor */
705         b       2f
706
707         /* addr <= TASK_SIZE */
708 1:      rlwinm  r12, r11, 31, 29, 29    /* Extract _PAGE_HWWRITE into SW */
709         ori     r12, r12, (MAS3_SX | MAS3_SR)
710
711 2:      rlwimi  r11, r12, 0, 20, 31     /* Extract RPN from PTE and merge with perms */
712         mtspr   SPRN_MAS3, r11
713         tlbwe
714
715         /* Done...restore registers and get out of here.  */
716         mfspr   r11, SPRG7R
717         mtcr    r11
718         mfspr   r13, SPRG5R
719         mfspr   r12, SPRG4R
720         mfspr   r11, SPRG1
721         mfspr   r10, SPRG0
722         rfi                                     /* Force context change */
723
724 #ifdef CONFIG_SPE
725 /* Note that the SPE support is closely modeled after the AltiVec
726  * support.  Changes to one are likely to be applicable to the
727  * other!  */
728 load_up_spe:
729 /*
730  * Disable SPE for the task which had SPE previously,
731  * and save its SPE registers in its thread_struct.
732  * Enables SPE for use in the kernel on return.
733  * On SMP we know the SPE units are free, since we give it up every
734  * switch.  -- Kumar
735  */
736         mfmsr   r5
737         oris    r5,r5,MSR_SPE@h
738         mtmsr   r5                      /* enable use of SPE now */
739         isync
740 /*
741  * For SMP, we don't do lazy SPE switching because it just gets too
742  * horrendously complex, especially when a task switches from one CPU
743  * to another.  Instead we call giveup_spe in switch_to.
744  */
745 #ifndef CONFIG_SMP
746         lis     r3,last_task_used_spe@ha
747         lwz     r4,last_task_used_spe@l(r3)
748         cmpi    0,r4,0
749         beq     1f
750         addi    r4,r4,THREAD    /* want THREAD of last_task_used_spe */
751         SAVE_32EVR(0,r10,r4)
752         evxor   evr10, evr10, evr10     /* clear out evr10 */
753         evmwumiaa evr10, evr10, evr10   /* evr10 <- ACC = 0 * 0 + ACC */
754         li      r5,THREAD_ACC
755         evstddx evr10, r4, r5           /* save off accumulator */
756         lwz     r5,PT_REGS(r4)
757         lwz     r4,_MSR-STACK_FRAME_OVERHEAD(r5)
758         lis     r10,MSR_SPE@h
759         andc    r4,r4,r10       /* disable SPE for previous task */
760         stw     r4,_MSR-STACK_FRAME_OVERHEAD(r5)
761 1:
762 #endif /* CONFIG_SMP */
763         /* enable use of SPE after return */
764         oris    r9,r9,MSR_SPE@h
765         mfspr   r5,SPRG3                /* current task's THREAD (phys) */
766         li      r4,1
767         li      r10,THREAD_ACC
768         stw     r4,THREAD_USED_SPE(r5)
769         evlddx  evr4,r10,r5
770         evmra   evr4,evr4
771         REST_32EVR(0,r10,r5)
772 #ifndef CONFIG_SMP
773         subi    r4,r5,THREAD
774         stw     r4,last_task_used_spe@l(r3)
775 #endif /* CONFIG_SMP */
776         /* restore registers and return */
777 2:      REST_4GPRS(3, r11)
778         lwz     r10,_CCR(r11)
779         REST_GPR(1, r11)
780         mtcr    r10
781         lwz     r10,_LINK(r11)
782         mtlr    r10
783         REST_GPR(10, r11)
784         mtspr   SRR1,r9
785         mtspr   SRR0,r12
786         REST_GPR(9, r11)
787         REST_GPR(12, r11)
788         lwz     r11,GPR11(r11)
789         SYNC
790         rfi
791
792
793
794 /*
795  * SPE unavailable trap from kernel - print a message, but let
796  * the task use SPE in the kernel until it returns to user mode.
797  */
798 KernelSPE:
799         lwz     r3,_MSR(r1)
800         oris    r3,r3,MSR_SPE@h
801         stw     r3,_MSR(r1)     /* enable use of SPE after return */
802         lis     r3,87f@h
803         ori     r3,r3,87f@l
804         mr      r4,r2           /* current */
805         lwz     r5,_NIP(r1)
806         bl      printk
807         b       ret_from_except
808 87:     .string "SPE used in kernel  (task=%p, pc=%x)  \n"
809         .align  4,0
810
811 #endif /* CONFIG_SPE */
812
813 /*
814  * Global functions
815  */
816
817 /*
818  * extern void loadcam_entry(unsigned int index)
819  *
820  * Load TLBCAM[index] entry in to the L2 CAM MMU
821  */
822 _GLOBAL(loadcam_entry)
823         lis     r4,TLBCAM@ha
824         addi    r4,r4,TLBCAM@l
825         mulli   r5,r3,20
826         add     r3,r5,r4
827         lwz     r4,0(r3)
828         mtspr   SPRN_MAS0,r4
829         lwz     r4,4(r3)
830         mtspr   SPRN_MAS1,r4
831         lwz     r4,8(r3)
832         mtspr   SPRN_MAS2,r4
833         lwz     r4,12(r3)
834         mtspr   SPRN_MAS3,r4
835         tlbwe
836         isync
837         blr
838
839 /*
840  * extern void giveup_altivec(struct task_struct *prev)
841  *
842  * The e500 core does not have an AltiVec unit.
843  */
844 _GLOBAL(giveup_altivec)
845         blr
846
847 #ifdef CONFIG_SPE
848 /*
849  * extern void giveup_spe(struct task_struct *prev)
850  *
851  */
852 _GLOBAL(giveup_spe)
853         mfmsr   r5
854         oris    r5,r5,MSR_SPE@h
855         SYNC
856         mtmsr   r5                      /* enable use of SPE now */
857         isync
858         cmpi    0,r3,0
859         beqlr-                          /* if no previous owner, done */
860         addi    r3,r3,THREAD            /* want THREAD of task */
861         lwz     r5,PT_REGS(r3)
862         cmpi    0,r5,0
863         SAVE_32EVR(0, r4, r3)
864         evxor   evr6, evr6, evr6        /* clear out evr6 */
865         evmwumiaa evr6, evr6, evr6      /* evr6 <- ACC = 0 * 0 + ACC */
866         li      r4,THREAD_ACC
867         evstddx evr6, r4, r3            /* save off accumulator */
868         mfspr   r6,SPRN_SPEFSCR
869         stw     r6,THREAD_SPEFSCR(r3)   /* save spefscr register value */
870         beq     1f
871         lwz     r4,_MSR-STACK_FRAME_OVERHEAD(r5)
872         lis     r3,MSR_SPE@h
873         andc    r4,r4,r3                /* disable SPE for previous task */
874         stw     r4,_MSR-STACK_FRAME_OVERHEAD(r5)
875 1:
876 #ifndef CONFIG_SMP
877         li      r5,0
878         lis     r4,last_task_used_spe@ha
879         stw     r5,last_task_used_spe@l(r4)
880 #endif /* CONFIG_SMP */
881         blr
882 #endif /* CONFIG_SPE */
883
884 /*
885  * extern void giveup_fpu(struct task_struct *prev)
886  *
887  * The e500 core does not have an FPU.
888  */
889 _GLOBAL(giveup_fpu)
890         blr
891
892 /*
893  * extern void abort(void)
894  *
895  * At present, this routine just applies a system reset.
896  */
897 _GLOBAL(abort)
898         li      r13,0
899         mtspr   SPRN_DBCR0,r13          /* disable all debug events */
900         mfmsr   r13
901         ori     r13,r13,MSR_DE@l        /* Enable Debug Events */
902         mtmsr   r13
903         mfspr   r13,SPRN_DBCR0
904         lis     r13,(DBCR0_IDM|DBCR0_RST_CHIP)@h
905         mtspr   SPRN_DBCR0,r13
906
907 _GLOBAL(set_context)
908
909 #ifdef CONFIG_BDI_SWITCH
910         /* Context switch the PTE pointer for the Abatron BDI2000.
911          * The PGDIR is the second parameter.
912          */
913         lis     r5, abatron_pteptrs@h
914         ori     r5, r5, abatron_pteptrs@l
915         stw     r4, 0x4(r5)
916 #endif
917         mtspr   SPRN_PID,r3
918         isync                   /* Force context change */
919         blr
920
921 /*
922  * We put a few things here that have to be page-aligned. This stuff
923  * goes at the beginning of the data segment, which is page-aligned.
924  */
925         .data
926 _GLOBAL(sdata)
927 _GLOBAL(empty_zero_page)
928         .space  4096
929 _GLOBAL(swapper_pg_dir)
930         .space  4096
931
932         .section .bss
933 /* Stack for handling critical exceptions from kernel mode */
934 critical_stack_bottom:
935         .space 4096
936 critical_stack_top:
937         .previous
938
939 /* Stack for handling machine check exceptions from kernel mode */
940 mcheck_stack_bottom:
941         .space 4096
942 mcheck_stack_top:
943         .previous
944
945 /*
946  * This area is used for temporarily saving registers during the
947  * critical and machine check exception prologs. It must always
948  * follow the page aligned allocations, so it starts on a page
949  * boundary, ensuring that all crit_save areas are in a single
950  * page.
951  */
952
953 /* crit_save */
954 _GLOBAL(crit_save)
955         .space  4
956 _GLOBAL(crit_r10)
957         .space  4
958 _GLOBAL(crit_r11)
959         .space  4
960 _GLOBAL(crit_sprg0)
961         .space  4
962 _GLOBAL(crit_sprg1)
963         .space  4
964 _GLOBAL(crit_sprg4)
965         .space  4
966 _GLOBAL(crit_sprg5)
967         .space  4
968 _GLOBAL(crit_sprg7)
969         .space  4
970 _GLOBAL(crit_pid)
971         .space  4
972 _GLOBAL(crit_srr0)
973         .space  4
974 _GLOBAL(crit_srr1)
975         .space  4
976
977 /* mcheck_save */
978 _GLOBAL(mcheck_save)
979         .space  4
980 _GLOBAL(mcheck_r10)
981         .space  4
982 _GLOBAL(mcheck_r11)
983         .space  4
984 _GLOBAL(mcheck_sprg0)
985         .space  4
986 _GLOBAL(mcheck_sprg1)
987         .space  4
988 _GLOBAL(mcheck_sprg4)
989         .space  4
990 _GLOBAL(mcheck_sprg5)
991         .space  4
992 _GLOBAL(mcheck_sprg7)
993         .space  4
994 _GLOBAL(mcheck_pid)
995         .space  4
996 _GLOBAL(mcheck_srr0)
997         .space  4
998 _GLOBAL(mcheck_srr1)
999         .space  4
1000 _GLOBAL(mcheck_csrr0)
1001         .space  4
1002 _GLOBAL(mcheck_csrr1)
1003         .space  4
1004
1005 /*
1006  * This space gets a copy of optional info passed to us by the bootstrap
1007  * which is used to pass parameters into the kernel like root=/dev/sda1, etc.
1008  */
1009 _GLOBAL(cmd_line)
1010         .space  512
1011
1012 /*
1013  * Room for two PTE pointers, usually the kernel and current user pointers
1014  * to their respective root page table.
1015  */
1016 abatron_pteptrs:
1017         .space  8
1018
1019