vserver 1.9.3
[linux-2.6.git] / arch / ppc / kernel / head_44x.S
1 /*
2  * arch/ppc/kernel/head_44x.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  *
27  * This program is free software; you can redistribute  it and/or modify it
28  * under  the terms of  the GNU General  Public License as published by the
29  * Free Software Foundation;  either version 2 of the  License, or (at your
30  * option) any later version.
31  */
32
33 #include <linux/config.h>
34 #include <asm/processor.h>
35 #include <asm/page.h>
36 #include <asm/mmu.h>
37 #include <asm/pgtable.h>
38 #include <asm/ibm4xx.h>
39 #include <asm/ibm44x.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
47 /* As with the other PowerPC ports, it is expected that when code
48  * execution begins here, the following registers contain valid, yet
49  * optional, information:
50  *
51  *   r3 - Board info structure pointer (DRAM, frequency, MAC address, etc.)
52  *   r4 - Starting address of the init RAM disk
53  *   r5 - Ending address of the init RAM disk
54  *   r6 - Start of kernel command line string (e.g. "mem=128")
55  *   r7 - End of kernel command line string
56  *
57  */
58         .text
59 _GLOBAL(_stext)
60 _GLOBAL(_start)
61         /*
62          * Reserve a word at a fixed location to store the address
63          * of abatron_pteptrs
64          */
65         nop
66 /*
67  * Save parameters we are passed
68  */
69         mr      r31,r3
70         mr      r30,r4
71         mr      r29,r5
72         mr      r28,r6
73         mr      r27,r7
74         li      r24,0           /* CPU number */
75
76 /*
77  * Set up the initial MMU state
78  *
79  * We are still executing code at the virtual address
80  * mappings set by the firmware for the base of RAM.
81  *
82  * We first invalidate all TLB entries but the one
83  * we are running from.  We then load the KERNELBASE
84  * mappings so we can begin to use kernel addresses
85  * natively and so the interrupt vector locations are
86  * permanently pinned (necessary since Book E
87  * implementations always have translation enabled).
88  *
89  * TODO: Use the known TLB entry we are running from to
90  *       determine which physical region we are located
91  *       in.  This can be used to determine where in RAM
92  *       (on a shared CPU system) or PCI memory space
93  *       (on a DRAMless system) we are located.
94  *       For now, we assume a perfect world which means
95  *       we are located at the base of DRAM (physical 0).
96  */
97
98 /*
99  * Search TLB for entry that we are currently using.
100  * Invalidate all entries but the one we are using.
101  */
102         /* Load our current PID->MMUCR TID and MSR IS->MMUCR STS */
103         mfspr   r3,SPRN_PID                     /* Get PID */
104         mfmsr   r4                              /* Get MSR */
105         andi.   r4,r4,MSR_IS@l                  /* TS=1? */
106         beq     wmmucr                          /* If not, leave STS=0 */
107         oris    r3,r3,PPC44x_MMUCR_STS@h        /* Set STS=1 */
108 wmmucr: mtspr   SPRN_MMUCR,r3                   /* Put MMUCR */
109         sync
110
111         bl      invstr                          /* Find our address */
112 invstr: mflr    r5                              /* Make it accessible */
113         tlbsx   r23,0,r5                        /* Find entry we are in */
114         li      r4,0                            /* Start at TLB entry 0 */
115         li      r3,0                            /* Set PAGEID inval value */
116 1:      cmpw    r23,r4                          /* Is this our entry? */
117         beq     skpinv                          /* If so, skip the inval */
118         tlbwe   r3,r4,PPC44x_TLB_PAGEID         /* If not, inval the entry */
119 skpinv: addi    r4,r4,1                         /* Increment */
120         cmpwi   r4,64                           /* Are we done? */
121         bne     1b                              /* If not, repeat */
122         isync                                   /* If so, context change */
123
124 /*
125  * Configure and load pinned entry into TLB slot 63.
126  */
127
128         lis     r3,KERNELBASE@h         /* Load the kernel virtual address */
129         ori     r3,r3,KERNELBASE@l
130
131         /* Kernel is at the base of RAM */
132         li r4, 0                        /* Load the kernel physical address */
133
134         /* Load the kernel PID = 0 */
135         li      r0,0
136         mtspr   SPRN_PID,r0
137         sync
138
139         /* Initialize MMUCR */
140         li      r5,0
141         mtspr   SPRN_MMUCR,r5
142         sync
143
144         /* pageid fields */
145         clrrwi  r3,r3,10                /* Mask off the effective page number */
146         ori     r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M
147
148         /* xlat fields */
149         clrrwi  r4,r4,10                /* Mask off the real page number */
150                                         /* ERPN is 0 for first 4GB page */
151
152         /* attrib fields */
153         /* Added guarded bit to protect against speculative loads/stores */
154         li      r5,0
155         ori     r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_SX | PPC44x_TLB_G)
156
157         li      r0,63                    /* TLB slot 63 */
158
159         tlbwe   r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */
160         tlbwe   r4,r0,PPC44x_TLB_XLAT   /* Load the translation fields */
161         tlbwe   r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */
162
163         /* Force context change */
164         mfmsr   r0
165         mtspr   SRR1, r0
166         lis     r0,3f@h
167         ori     r0,r0,3f@l
168         mtspr   SRR0,r0
169         sync
170         rfi
171
172         /* If necessary, invalidate original entry we used */
173 3:      cmpwi   r23,63
174         beq     4f
175         li      r6,0
176         tlbwe   r6,r23,PPC44x_TLB_PAGEID
177         isync
178
179 4:
180 #ifdef CONFIG_SERIAL_TEXT_DEBUG
181         /*
182          * Add temporary UART mapping for early debug.  This
183          * mapping must be identical to that used by the early
184          * bootloader code since the same asm/serial.h parameters
185          * are used for polled operation.
186          */
187         /* pageid fields */
188         lis     r3,0xe000       
189         ori     r3,r3,PPC44x_TLB_VALID | PPC44x_TLB_256M
190
191         /* xlat fields */
192         lis     r4,0x4000               /* RPN is 0x40000000 */
193         ori     r4,r4,0x0001            /* ERPN is 1 for second 4GB page */
194
195         /* attrib fields */
196         li      r5,0
197         ori     r5,r5,(PPC44x_TLB_SW | PPC44x_TLB_SR | PPC44x_TLB_I | PPC44x_TLB_G)
198
199         li      r0,1                    /* TLB slot 1 */
200
201         tlbwe   r3,r0,PPC44x_TLB_PAGEID /* Load the pageid fields */
202         tlbwe   r4,r0,PPC44x_TLB_XLAT   /* Load the translation fields */
203         tlbwe   r5,r0,PPC44x_TLB_ATTRIB /* Load the attrib/access fields */
204
205         /* Force context change */
206         isync
207 #endif /* CONFIG_SERIAL_TEXT_DEBUG */
208
209         /* Establish the interrupt vector offsets */
210         SET_IVOR(0,  CriticalInput);
211         SET_IVOR(1,  MachineCheck);
212         SET_IVOR(2,  DataStorage);
213         SET_IVOR(3,  InstructionStorage);
214         SET_IVOR(4,  ExternalInput);
215         SET_IVOR(5,  Alignment);
216         SET_IVOR(6,  Program);
217         SET_IVOR(7,  FloatingPointUnavailable);
218         SET_IVOR(8,  SystemCall);
219         SET_IVOR(9,  AuxillaryProcessorUnavailable);
220         SET_IVOR(10, Decrementer);
221         SET_IVOR(11, FixedIntervalTimer);
222         SET_IVOR(12, WatchdogTimer);
223         SET_IVOR(13, DataTLBError);
224         SET_IVOR(14, InstructionTLBError);
225         SET_IVOR(15, Debug);
226
227         /* Establish the interrupt vector base */
228         lis     r4,interrupt_base@h     /* IVPR only uses the high 16-bits */
229         mtspr   SPRN_IVPR,r4
230
231         /*
232          * This is where the main kernel code starts.
233          */
234
235         /* ptr to current */
236         lis     r2,init_task@h
237         ori     r2,r2,init_task@l
238
239         /* ptr to current thread */
240         addi    r4,r2,THREAD    /* init task's THREAD */
241         mtspr   SPRG3,r4
242
243         /* stack */
244         lis     r1,init_thread_union@h
245         ori     r1,r1,init_thread_union@l
246         li      r0,0
247         stwu    r0,THREAD_SIZE-STACK_FRAME_OVERHEAD(r1)
248
249         bl      early_init
250
251 /*
252  * Decide what sort of machine this is and initialize the MMU.
253  */
254         mr      r3,r31
255         mr      r4,r30
256         mr      r5,r29
257         mr      r6,r28
258         mr      r7,r27
259         bl      machine_init
260         bl      MMU_init
261
262         /* Setup PTE pointers for the Abatron bdiGDB */
263         lis     r6, swapper_pg_dir@h
264         ori     r6, r6, swapper_pg_dir@l
265         lis     r5, abatron_pteptrs@h
266         ori     r5, r5, abatron_pteptrs@l
267         lis     r4, KERNELBASE@h
268         ori     r4, r4, KERNELBASE@l
269         stw     r5, 0(r4)       /* Save abatron_pteptrs at a fixed location */
270         stw     r6, 0(r5)
271
272         /* Let's move on */
273         lis     r4,start_kernel@h
274         ori     r4,r4,start_kernel@l
275         lis     r3,MSR_KERNEL@h
276         ori     r3,r3,MSR_KERNEL@l
277         mtspr   SRR0,r4
278         mtspr   SRR1,r3
279         rfi                     /* change context and jump to start_kernel */
280
281 /*
282  * Interrupt vector entry code
283  *
284  * The Book E MMUs are always on so we don't need to handle
285  * interrupts in real mode as with previous PPC processors. In
286  * this case we handle interrupts in the kernel virtual address
287  * space.
288  *
289  * Interrupt vectors are dynamically placed relative to the
290  * interrupt prefix as determined by the address of interrupt_base.
291  * The interrupt vectors offsets are programmed using the labels
292  * for each interrupt vector entry.
293  *
294  * Interrupt vectors must be aligned on a 16 byte boundary.
295  * We align on a 32 byte cache line boundary for good measure.
296  */
297
298 interrupt_base:
299         /* Critical Input Interrupt */
300         CRITICAL_EXCEPTION(0x0100, CriticalInput, UnknownException)
301
302         /* Machine Check Interrupt */
303 #ifdef CONFIG_440A
304         MCHECK_EXCEPTION(0x0200, MachineCheck, MachineCheckException)
305 #else
306         CRITICAL_EXCEPTION(0x0200, MachineCheck, MachineCheckException)
307 #endif
308
309         /* Data Storage Interrupt */
310         START_EXCEPTION(DataStorage)
311         mtspr   SPRG0, r10              /* Save some working registers */
312         mtspr   SPRG1, r11
313         mtspr   SPRG4W, r12
314         mtspr   SPRG5W, r13
315         mfcr    r11
316         mtspr   SPRG7W, r11
317
318         /*
319          * Check if it was a store fault, if not then bail
320          * because a user tried to access a kernel or
321          * read-protected page.  Otherwise, get the
322          * offending address and handle it.
323          */
324         mfspr   r10, SPRN_ESR
325         andis.  r10, r10, ESR_ST@h
326         beq     2f
327
328         mfspr   r10, SPRN_DEAR          /* Get faulting address */
329
330         /* If we are faulting a kernel address, we have to use the
331          * kernel page tables.
332          */
333         andis.  r11, r10, 0x8000
334         beq     3f
335         lis     r11, swapper_pg_dir@h
336         ori     r11, r11, swapper_pg_dir@l
337
338         mfspr   r12,SPRN_MMUCR
339         rlwinm  r12,r12,0,0,23          /* Clear TID */
340
341         b       4f
342
343         /* Get the PGD for the current thread */
344 3:
345         mfspr   r11,SPRG3
346         lwz     r11,PGDIR(r11)
347
348         /* Load PID into MMUCR TID */
349         mfspr   r12,SPRN_MMUCR          /* Get MMUCR */
350         mfspr   r13,SPRN_PID            /* Get PID */
351         rlwimi  r12,r13,0,24,31         /* Set TID */
352
353 4:
354         mtspr   SPRN_MMUCR,r12
355
356         rlwinm  r12, r10, 13, 19, 29    /* Compute pgdir/pmd offset */
357         lwzx    r11, r12, r11           /* Get pgd/pmd entry */
358         rlwinm. r12, r11, 0, 0, 20      /* Extract pt base address */
359         beq     2f                      /* Bail if no table */
360
361         rlwimi  r12, r10, 23, 20, 28    /* Compute pte address */
362         lwz     r11, 4(r12)             /* Get pte entry */
363
364         andi.   r13, r11, _PAGE_RW      /* Is it writeable? */
365         beq     2f                      /* Bail if not */
366
367         /* Update 'changed'.
368         */
369         ori     r11, r11, _PAGE_DIRTY|_PAGE_ACCESSED|_PAGE_HWWRITE
370         stw     r11, 4(r12)             /* Update Linux page table */
371
372         li      r13, PPC44x_TLB_SR@l    /* Set SR */
373         rlwimi  r13, r11, 29, 29, 29    /* SX = _PAGE_HWEXEC */
374         rlwimi  r13, r11, 0, 30, 30     /* SW = _PAGE_RW */
375         rlwimi  r13, r11, 29, 28, 28    /* UR = _PAGE_USER */
376         rlwimi  r12, r11, 31, 26, 26    /* (_PAGE_USER>>1)->r12 */
377         rlwimi  r12, r11, 29, 30, 30    /* (_PAGE_USER>>3)->r12 */
378         and     r12, r12, r11           /* HWEXEC/RW & USER */
379         rlwimi  r13, r12, 0, 26, 26     /* UX = HWEXEC & USER */
380         rlwimi  r13, r12, 3, 27, 27     /* UW = RW & USER */
381
382         rlwimi  r11,r13,0,26,31         /* Insert static perms */
383
384         rlwinm  r11,r11,0,20,15         /* Clear U0-U3 */
385
386         /* find the TLB index that caused the fault.  It has to be here. */
387         tlbsx   r10, 0, r10
388
389         tlbwe   r11, r10, PPC44x_TLB_ATTRIB     /* Write ATTRIB */
390
391         /* Done...restore registers and get out of here.
392         */
393         mfspr   r11, SPRG7R
394         mtcr    r11
395         mfspr   r13, SPRG5R
396         mfspr   r12, SPRG4R
397
398         mfspr   r11, SPRG1
399         mfspr   r10, SPRG0
400         rfi                     /* Force context change */
401
402 2:
403         /*
404          * The bailout.  Restore registers to pre-exception conditions
405          * and call the heavyweights to help us out.
406          */
407         mfspr   r11, SPRG7R
408         mtcr    r11
409         mfspr   r13, SPRG5R
410         mfspr   r12, SPRG4R
411
412         mfspr   r11, SPRG1
413         mfspr   r10, SPRG0
414         b       data_access
415
416         /* Instruction Storage Interrupt */
417         START_EXCEPTION(InstructionStorage)
418         NORMAL_EXCEPTION_PROLOG
419         mr      r4,r12                  /* Pass SRR0 as arg2 */
420         li      r5,0                    /* Pass zero as arg3 */
421         EXC_XFER_EE_LITE(0x0400, handle_page_fault)
422
423         /* External Input Interrupt */
424         EXCEPTION(0x0500, ExternalInput, do_IRQ, EXC_XFER_LITE)
425
426         /* Alignment Interrupt */
427         START_EXCEPTION(Alignment)
428         NORMAL_EXCEPTION_PROLOG
429         mfspr   r4,SPRN_DEAR            /* Grab the DEAR and save it */
430         stw     r4,_DEAR(r11)
431         addi    r3,r1,STACK_FRAME_OVERHEAD
432         EXC_XFER_EE(0x0600, AlignmentException)
433
434         /* Program Interrupt */
435         START_EXCEPTION(Program)
436         NORMAL_EXCEPTION_PROLOG
437         mfspr   r4,SPRN_ESR             /* Grab the ESR and save it */
438         stw     r4,_ESR(r11)
439         addi    r3,r1,STACK_FRAME_OVERHEAD
440         EXC_XFER_STD(0x700, ProgramCheckException)
441
442         /* Floating Point Unavailable Interrupt */
443         EXCEPTION(0x2010, FloatingPointUnavailable, UnknownException, EXC_XFER_EE)
444
445         /* System Call Interrupt */
446         START_EXCEPTION(SystemCall)
447         NORMAL_EXCEPTION_PROLOG
448         EXC_XFER_EE_LITE(0x0c00, DoSyscall)
449
450         /* Auxillary Processor Unavailable Interrupt */
451         EXCEPTION(0x2020, AuxillaryProcessorUnavailable, UnknownException, EXC_XFER_EE)
452
453         /* Decrementer Interrupt */
454         START_EXCEPTION(Decrementer)
455         NORMAL_EXCEPTION_PROLOG
456         lis     r0,TSR_DIS@h            /* Setup the DEC interrupt mask */
457         mtspr   SPRN_TSR,r0             /* Clear the DEC interrupt */
458         addi    r3,r1,STACK_FRAME_OVERHEAD
459         EXC_XFER_LITE(0x1000, timer_interrupt)
460
461         /* Fixed Internal Timer Interrupt */
462         /* TODO: Add FIT support */
463         EXCEPTION(0x1010, FixedIntervalTimer, UnknownException, EXC_XFER_EE)
464
465         /* Watchdog Timer Interrupt */
466         /* TODO: Add watchdog support */
467         CRITICAL_EXCEPTION(0x1020, WatchdogTimer, UnknownException)
468
469         /* Data TLB Error Interrupt */
470         START_EXCEPTION(DataTLBError)
471         mtspr   SPRG0, r10              /* Save some working registers */
472         mtspr   SPRG1, r11
473         mtspr   SPRG4W, r12
474         mtspr   SPRG5W, r13
475         mfcr    r11
476         mtspr   SPRG7W, r11
477         mfspr   r10, SPRN_DEAR          /* Get faulting address */
478
479         /* If we are faulting a kernel address, we have to use the
480          * kernel page tables.
481          */
482         andis.  r11, r10, 0x8000
483         beq     3f
484         lis     r11, swapper_pg_dir@h
485         ori     r11, r11, swapper_pg_dir@l
486
487         mfspr   r12,SPRN_MMUCR
488         rlwinm  r12,r12,0,0,23          /* Clear TID */
489
490         b       4f
491
492         /* Get the PGD for the current thread */
493 3:
494         mfspr   r11,SPRG3
495         lwz     r11,PGDIR(r11)
496
497         /* Load PID into MMUCR TID */
498         mfspr   r12,SPRN_MMUCR
499         mfspr   r13,SPRN_PID            /* Get PID */
500         rlwimi  r12,r13,0,24,31         /* Set TID */
501
502 4:
503         mtspr   SPRN_MMUCR,r12
504
505         rlwinm  r12, r10, 13, 19, 29    /* Compute pgdir/pmd offset */
506         lwzx    r11, r12, r11           /* Get pgd/pmd entry */
507         rlwinm. r12, r11, 0, 0, 20      /* Extract pt base address */
508         beq     2f                      /* Bail if no table */
509
510         rlwimi  r12, r10, 23, 20, 28    /* Compute pte address */
511         lwz     r11, 4(r12)             /* Get pte entry */
512         andi.   r13, r11, _PAGE_PRESENT /* Is the page present? */
513         beq     2f                      /* Bail if not present */
514
515         ori     r11, r11, _PAGE_ACCESSED
516         stw     r11, 4(r12)
517
518          /* Jump to common tlb load */
519         b       finish_tlb_load
520
521 2:
522         /* The bailout.  Restore registers to pre-exception conditions
523          * and call the heavyweights to help us out.
524          */
525         mfspr   r11, SPRG7R
526         mtcr    r11
527         mfspr   r13, SPRG5R
528         mfspr   r12, SPRG4R
529         mfspr   r11, SPRG1
530         mfspr   r10, SPRG0
531         b       data_access
532
533         /* Instruction TLB Error Interrupt */
534         /*
535          * Nearly the same as above, except we get our
536          * information from different registers and bailout
537          * to a different point.
538          */
539         START_EXCEPTION(InstructionTLBError)
540         mtspr   SPRG0, r10              /* Save some working registers */
541         mtspr   SPRG1, r11
542         mtspr   SPRG4W, r12
543         mtspr   SPRG5W, r13
544         mfcr    r11
545         mtspr   SPRG7W, r11
546         mfspr   r10, SRR0               /* Get faulting address */
547
548         /* If we are faulting a kernel address, we have to use the
549          * kernel page tables.
550          */
551         andis.  r11, r10, 0x8000
552         beq     3f
553         lis     r11, swapper_pg_dir@h
554         ori     r11, r11, swapper_pg_dir@l
555
556         mfspr   r12,SPRN_MMUCR
557         rlwinm  r12,r12,0,0,23          /* Clear TID */
558
559         b       4f
560
561         /* Get the PGD for the current thread */
562 3:
563         mfspr   r11,SPRG3
564         lwz     r11,PGDIR(r11)
565
566         /* Load PID into MMUCR TID */
567         mfspr   r12,SPRN_MMUCR
568         mfspr   r13,SPRN_PID            /* Get PID */
569         rlwimi  r12,r13,0,24,31         /* Set TID */
570
571 4:
572         mtspr   SPRN_MMUCR,r12
573
574         rlwinm  r12, r10, 13, 19, 29    /* Compute pgdir/pmd offset */
575         lwzx    r11, r12, r11           /* Get pgd/pmd entry */
576         rlwinm. r12, r11, 0, 0, 20      /* Extract pt base address */
577         beq     2f                      /* Bail if no table */
578
579         rlwimi  r12, r10, 23, 20, 28    /* Compute pte address */
580         lwz     r11, 4(r12)             /* Get pte entry */
581         andi.   r13, r11, _PAGE_PRESENT /* Is the page present? */
582         beq     2f                      /* Bail if not present */
583
584         ori     r11, r11, _PAGE_ACCESSED
585         stw     r11, 4(r12)
586
587         /* Jump to common TLB load point */
588         b       finish_tlb_load
589
590 2:
591         /* The bailout.  Restore registers to pre-exception conditions
592          * and call the heavyweights to help us out.
593          */
594         mfspr   r11, SPRG7R
595         mtcr    r11
596         mfspr   r13, SPRG5R
597         mfspr   r12, SPRG4R
598         mfspr   r11, SPRG1
599         mfspr   r10, SPRG0
600         b       InstructionStorage
601
602 /* Check for a single step debug exception while in an exception
603  * handler before state has been saved.  This is to catch the case
604  * where an instruction that we are trying to single step causes
605  * an exception (eg ITLB/DTLB miss) and thus the first instruction of
606  * the exception handler generates a single step debug exception.
607  *
608  * If we get a debug trap on the first instruction of an exception handler,
609  * we reset the MSR_DE in the _exception handler's_ MSR (the debug trap is
610  * a critical exception, so we are using SPRN_CSRR1 to manipulate the MSR).
611  * The exception handler was handling a non-critical interrupt, so it will
612  * save (and later restore) the MSR via SPRN_SRR1, which will still have
613  * the MSR_DE bit set.
614  */
615         /* Debug Interrupt */
616         START_EXCEPTION(Debug)
617         CRITICAL_EXCEPTION_PROLOG
618
619         /*
620          * If this is a single step or branch-taken exception in an
621          * exception entry sequence, it was probably meant to apply to
622          * the code where the exception occurred (since exception entry
623          * doesn't turn off DE automatically).  We simulate the effect
624          * of turning off DE on entry to an exception handler by turning
625          * off DE in the CSRR1 value and clearing the debug status.
626          */
627         mfspr   r10,SPRN_DBSR           /* check single-step/branch taken */
628         andis.  r10,r10,(DBSR_IC|DBSR_BT)@h
629         beq+    1f
630         andi.   r0,r9,MSR_PR            /* check supervisor */
631         beq     2f                      /* branch if we need to fix it up... */
632
633         /* continue normal handling for a critical exception... */
634 1:      mfspr   r4,SPRN_DBSR
635         addi    r3,r1,STACK_FRAME_OVERHEAD
636         EXC_XFER_TEMPLATE(DebugException, 0x2002, \
637                 (MSR_KERNEL & ~(MSR_ME|MSR_DE|MSR_CE)), \
638                 NOCOPY, crit_transfer_to_handler, ret_from_crit_exc)
639
640         /* here it looks like we got an inappropriate debug exception. */
641 2:      rlwinm  r9,r9,0,~MSR_DE         /* clear DE in the CSRR1 value */
642         mtspr   SPRN_DBSR,r10           /* clear the IC/BT debug intr status */
643         /* restore state and get out */
644         lwz     r10,_CCR(r11)
645         lwz     r0,GPR0(r11)
646         lwz     r1,GPR1(r11)
647         mtcrf   0x80,r10
648         mtspr   CSRR0,r12
649         mtspr   CSRR1,r9
650         lwz     r9,GPR9(r11)
651
652         mtspr   SPRG2,r8;               /* SPRG2 only used in criticals */
653         lis     r8,crit_save@ha;
654         lwz     r10,crit_r10@l(r8)
655         lwz     r11,crit_r11@l(r8)
656         mfspr   r8,SPRG2
657
658         rfci
659         b       .
660
661 /*
662  * Local functions
663  */
664         /*
665          * Data TLB exceptions will bail out to this point
666          * if they can't resolve the lightweight TLB fault.
667          */
668 data_access:
669         NORMAL_EXCEPTION_PROLOG
670         mfspr   r5,SPRN_ESR             /* Grab the ESR, save it, pass arg3 */
671         stw     r5,_ESR(r11)
672         mfspr   r4,SPRN_DEAR            /* Grab the DEAR, save it, pass arg2 */
673         EXC_XFER_EE_LITE(0x0300, handle_page_fault)
674
675 /*
676
677  * Both the instruction and data TLB miss get to this
678  * point to load the TLB.
679  *      r10 - EA of fault
680  *      r11 - available to use
681  *      r12 - Pointer to the 64-bit PTE
682  *      r13 - available to use
683  *      MMUCR - loaded with proper value when we get here
684  *      Upon exit, we reload everything and RFI.
685  */
686 finish_tlb_load:
687         /*
688          * We set execute, because we don't have the granularity to
689          * properly set this at the page level (Linux problem).
690          * If shared is set, we cause a zero PID->TID load.
691          * Many of these bits are software only.  Bits we don't set
692          * here we (properly should) assume have the appropriate value.
693          */
694
695         /* Load the next available TLB index */
696         lis     r13, tlb_44x_index@ha
697         lwz     r13, tlb_44x_index@l(r13)
698         /* Load the TLB high watermark */
699         lis     r11, tlb_44x_hwater@ha
700         lwz     r11, tlb_44x_hwater@l(r11)
701
702         /* Increment, rollover, and store TLB index */
703         addi    r13, r13, 1
704         cmpw    0, r13, r11                     /* reserve entries */
705         ble     7f
706         li      r13, 0
707 7:
708         /* Store the next available TLB index */
709         lis     r11, tlb_44x_index@ha
710         stw     r13, tlb_44x_index@l(r11)
711
712         lwz     r11, 0(r12)                     /* Get MS word of PTE */
713         lwz     r12, 4(r12)                     /* Get LS word of PTE */
714         rlwimi  r11, r12, 0, 0 , 19             /* Insert RPN */
715         tlbwe   r11, r13, PPC44x_TLB_XLAT       /* Write XLAT */
716
717         /*
718          * Create PAGEID. This is the faulting address,
719          * page size, and valid flag.
720          */
721         li      r11, PPC44x_TLB_VALID | PPC44x_TLB_4K
722         rlwimi  r10, r11, 0, 20, 31             /* Insert valid and page size */
723         tlbwe   r10, r13, PPC44x_TLB_PAGEID     /* Write PAGEID */
724
725         li      r10, PPC44x_TLB_SR@l            /* Set SR */
726         rlwimi  r10, r12, 0, 30, 30             /* Set SW = _PAGE_RW */
727         rlwimi  r10, r12, 29, 29, 29            /* SX = _PAGE_HWEXEC */
728         rlwimi  r10, r12, 29, 28, 28            /* UR = _PAGE_USER */
729         rlwimi  r11, r12, 31, 26, 26            /* (_PAGE_USER>>1)->r12 */
730         and     r11, r12, r11                   /* HWEXEC & USER */
731         rlwimi  r10, r11, 0, 26, 26             /* UX = HWEXEC & USER */
732
733         rlwimi  r12, r10, 0, 26, 31             /* Insert static perms */
734         rlwinm  r12, r12, 0, 20, 15             /* Clear U0-U3 */
735         tlbwe   r12, r13, PPC44x_TLB_ATTRIB     /* Write ATTRIB */
736
737         /* Done...restore registers and get out of here.
738         */
739         mfspr   r11, SPRG7R
740         mtcr    r11
741         mfspr   r13, SPRG5R
742         mfspr   r12, SPRG4R
743         mfspr   r11, SPRG1
744         mfspr   r10, SPRG0
745         rfi                                     /* Force context change */
746
747 /*
748  * Global functions
749  */
750
751 /*
752  * extern void giveup_altivec(struct task_struct *prev)
753  *
754  * The 44x core does not have an AltiVec unit.
755  */
756 _GLOBAL(giveup_altivec)
757         blr
758
759 /*
760  * extern void giveup_fpu(struct task_struct *prev)
761  *
762  * The 44x core does not have an FPU.
763  */
764 _GLOBAL(giveup_fpu)
765         blr
766
767 /*
768  * extern void abort(void)
769  *
770  * At present, this routine just applies a system reset.
771  */
772 _GLOBAL(abort)
773         mfspr   r13,SPRN_DBCR0
774         oris    r13,r13,DBCR0_RST_SYSTEM@h
775         mtspr   SPRN_DBCR0,r13
776
777 _GLOBAL(set_context)
778
779 #ifdef CONFIG_BDI_SWITCH
780         /* Context switch the PTE pointer for the Abatron BDI2000.
781          * The PGDIR is the second parameter.
782          */
783         lis     r5, abatron_pteptrs@h
784         ori     r5, r5, abatron_pteptrs@l
785         stw     r4, 0x4(r5)
786 #endif
787         mtspr   SPRN_PID,r3
788         isync                   /* Force context change */
789         blr
790
791 /*
792  * We put a few things here that have to be page-aligned. This stuff
793  * goes at the beginning of the data segment, which is page-aligned.
794  */
795         .data
796 _GLOBAL(sdata)
797 _GLOBAL(empty_zero_page)
798         .space  4096
799
800 /*
801  * To support >32-bit physical addresses, we use an 8KB pgdir.
802  */
803 _GLOBAL(swapper_pg_dir)
804         .space  8192
805
806         .section .bss
807 /* Stack for handling critical exceptions from kernel mode */
808 critical_stack_bottom:
809         .space 4096
810 critical_stack_top:
811         .previous
812
813 /* Stack for handling machine check exceptions from kernel mode */
814 mcheck_stack_bottom:
815         .space 4096
816 mcheck_stack_top:
817         .previous
818
819 /*
820  * This area is used for temporarily saving registers during the
821  * critical and machine check exception prologs. It must always
822  * follow the page aligned allocations, so it starts on a page
823  * boundary, ensuring that all crit_save areas are in a single
824  * page.
825  */
826
827 /* crit_save */
828 _GLOBAL(crit_save)
829         .space  4
830 _GLOBAL(crit_r10)
831         .space  4
832 _GLOBAL(crit_r11)
833         .space  4
834 _GLOBAL(crit_sprg0)
835         .space  4
836 _GLOBAL(crit_sprg1)
837         .space  4
838 _GLOBAL(crit_sprg4)
839         .space  4
840 _GLOBAL(crit_sprg5)
841         .space  4
842 _GLOBAL(crit_sprg7)
843         .space  4
844 _GLOBAL(crit_pid)
845         .space  4
846 _GLOBAL(crit_srr0)
847         .space  4
848 _GLOBAL(crit_srr1)
849         .space  4
850
851 /* mcheck_save */
852 _GLOBAL(mcheck_save)
853         .space  4
854 _GLOBAL(mcheck_r10)
855         .space  4
856 _GLOBAL(mcheck_r11)
857         .space  4
858 _GLOBAL(mcheck_sprg0)
859         .space  4
860 _GLOBAL(mcheck_sprg1)
861         .space  4
862 _GLOBAL(mcheck_sprg4)
863         .space  4
864 _GLOBAL(mcheck_sprg5)
865         .space  4
866 _GLOBAL(mcheck_sprg7)
867         .space  4
868 _GLOBAL(mcheck_pid)
869         .space  4
870 _GLOBAL(mcheck_srr0)
871         .space  4
872 _GLOBAL(mcheck_srr1)
873         .space  4
874 _GLOBAL(mcheck_csrr0)
875         .space  4
876 _GLOBAL(mcheck_csrr1)
877         .space  4
878
879 /*
880  * This space gets a copy of optional info passed to us by the bootstrap
881  * which is used to pass parameters into the kernel like root=/dev/sda1, etc.
882  */
883 _GLOBAL(cmd_line)
884         .space  512
885
886 /*
887  * Room for two PTE pointers, usually the kernel and current user pointers
888  * to their respective root page table.
889  */
890 abatron_pteptrs:
891         .space  8
892
893