2 * linux/arch/frv/mm/fault.c
4 * Copyright (C) 2003 Red Hat, Inc. All Rights Reserved.
5 * - Written by David Howells (dhowells@redhat.com)
6 * - Derived from arch/m68knommu/mm/fault.c
7 * - Copyright (C) 1998 D. Jeff Dionne <jeff@lineo.ca>,
8 * - Copyright (C) 2000 Lineo, Inc. (www.lineo.com)
12 * linux/arch/m68k/mm/fault.c
14 * Copyright (C) 1995 Hamish Macdonald
17 #include <linux/mman.h>
19 #include <linux/kernel.h>
20 #include <linux/ptrace.h>
21 #include <linux/hardirq.h>
23 #include <asm/system.h>
24 #include <asm/pgtable.h>
25 #include <asm/uaccess.h>
26 #include <asm/gdb-stub.h>
28 /*****************************************************************************/
30 * This routine handles page faults. It determines the problem, and
31 * then passes it off to one of the appropriate routines.
33 asmlinkage
void do_page_fault(int datammu
, unsigned long esr0
, unsigned long ear0
)
35 struct vm_area_struct
*vma
;
37 unsigned long _pme
, lrai
, lrad
, fixup
;
49 * We fault-in kernel-space virtual memory on-demand. The
50 * 'reference' page table is init_mm.pgd.
52 * NOTE! We MUST NOT take any locks for this case. We may
53 * be in an interrupt or a critical region, and should
54 * only copy the information from the master page table,
57 * This verifies that the fault happens in kernel space
58 * and that the fault was a page not present (invalid) error
60 if (!user_mode(__frame
) && (esr0
& ESR0_ATXC
) == ESR0_ATXC_AMRTLB_MISS
) {
61 if (ear0
>= VMALLOC_START
&& ear0
< VMALLOC_END
)
62 goto kernel_pte_fault
;
63 if (ear0
>= PKMAP_BASE
&& ear0
< PKMAP_END
)
64 goto kernel_pte_fault
;
67 info
.si_code
= SEGV_MAPERR
;
70 * If we're in an interrupt or have no user
71 * context, we must not take the fault..
73 if (in_atomic() || !mm
)
76 down_read(&mm
->mmap_sem
);
78 vma
= find_vma(mm
, ear0
);
81 if (vma
->vm_start
<= ear0
)
83 if (!(vma
->vm_flags
& VM_GROWSDOWN
))
86 if (user_mode(__frame
)) {
88 * accessing the stack below %esp is always a bug.
89 * The "+ 32" is there due to some instructions (like
90 * pusha) doing post-decrement on the stack and that
91 * doesn't show up until later..
93 if ((ear0
& PAGE_MASK
) + 2 * PAGE_SIZE
< __frame
->sp
) {
98 if (expand_stack(vma
, ear0
))
102 * Ok, we have a good vm_area for this memory access, so
106 info
.si_code
= SEGV_ACCERR
;
108 switch (esr0
& ESR0_ATXC
) {
110 /* handle write to write protected page */
111 case ESR0_ATXC_WP_EXCEP
:
112 #ifdef TEST_VERIFY_AREA
113 if (!(user_mode(__frame
)))
114 printk("WP fault at %08lx\n", __frame
->pc
);
116 if (!(vma
->vm_flags
& VM_WRITE
))
121 /* handle read from protected page */
122 case ESR0_ATXC_PRIV_EXCEP
:
125 /* handle read, write or exec on absent page
126 * - can't support write without permitting read
127 * - don't support execute without permitting read and vice-versa
129 case ESR0_ATXC_AMRTLB_MISS
:
130 if (!(vma
->vm_flags
& (VM_READ
| VM_WRITE
| VM_EXEC
)))
136 * If for any reason at all we couldn't handle the fault,
137 * make sure we exit gracefully rather than endlessly redo
140 fault
= handle_mm_fault(mm
, vma
, ear0
, write
? FAULT_FLAG_WRITE
: 0);
141 if (unlikely(fault
& VM_FAULT_ERROR
)) {
142 if (fault
& VM_FAULT_OOM
)
144 else if (fault
& VM_FAULT_SIGBUS
)
148 if (fault
& VM_FAULT_MAJOR
)
153 up_read(&mm
->mmap_sem
);
157 * Something tried to access memory that isn't in our memory map..
158 * Fix it, but check if it's kernel or user first..
161 up_read(&mm
->mmap_sem
);
163 /* User mode accesses just cause a SIGSEGV */
164 if (user_mode(__frame
)) {
165 info
.si_signo
= SIGSEGV
;
167 /* info.si_code has been set above */
168 info
.si_addr
= (void *) ear0
;
169 force_sig_info(SIGSEGV
, &info
, current
);
174 /* are we prepared to handle this kernel fault? */
175 if ((fixup
= search_exception_table(__frame
->pc
)) != 0) {
181 * Oops. The kernel tried to access some bad page. We'll have to
182 * terminate things with extreme prejudice.
187 if (ear0
< PAGE_SIZE
)
188 printk(KERN_ALERT
"Unable to handle kernel NULL pointer dereference");
190 printk(KERN_ALERT
"Unable to handle kernel paging request");
191 printk(" at virtual addr %08lx\n", ear0
);
192 printk(" PC : %08lx\n", __frame
->pc
);
193 printk(" EXC : esr0=%08lx ear0=%08lx\n", esr0
, ear0
);
195 asm("lrai %1,%0,#1,#0,#0" : "=&r"(lrai
) : "r"(ear0
));
196 asm("lrad %1,%0,#1,#0,#0" : "=&r"(lrad
) : "r"(ear0
));
198 printk(KERN_ALERT
" LRAI: %08lx\n", lrai
);
199 printk(KERN_ALERT
" LRAD: %08lx\n", lrad
);
201 __break_hijack_kernel_event();
203 pge
= pgd_offset(current
->mm
, ear0
);
204 pue
= pud_offset(pge
, ear0
);
205 _pme
= pue
->pue
[0].ste
[0];
207 printk(KERN_ALERT
" PGE : %8p { PME %08lx }\n", pge
, _pme
);
209 if (_pme
& xAMPRx_V
) {
210 unsigned long dampr
, damlr
, val
;
212 asm volatile("movsg dampr2,%0 ! movgs %2,dampr2 ! movsg damlr2,%1"
213 : "=&r"(dampr
), "=r"(damlr
)
214 : "r" (_pme
| xAMPRx_L
|xAMPRx_SS_16Kb
|xAMPRx_S
|xAMPRx_C
|xAMPRx_V
)
217 pte
= (pte_t
*) damlr
+ __pte_index(ear0
);
220 asm volatile("movgs %0,dampr2" :: "r" (dampr
));
222 printk(KERN_ALERT
" PTE : %8p { %08lx }\n", pte
, val
);
225 die_if_kernel("Oops\n");
229 * We ran out of memory, or some other thing happened to us that made
230 * us unable to handle the page fault gracefully.
233 up_read(&mm
->mmap_sem
);
234 if (!user_mode(__frame
))
236 pagefault_out_of_memory();
240 up_read(&mm
->mmap_sem
);
243 * Send a sigbus, regardless of whether we were in kernel
246 info
.si_signo
= SIGBUS
;
248 info
.si_code
= BUS_ADRERR
;
249 info
.si_addr
= (void *) ear0
;
250 force_sig_info(SIGBUS
, &info
, current
);
252 /* Kernel mode? Handle exceptions or die */
253 if (!user_mode(__frame
))
258 * The fault was caused by a kernel PTE (such as installed by vmalloc or kmap)
263 * Synchronize this task's top level page-table
264 * with the 'reference' page table.
266 * Do _not_ use "tsk" here. We might be inside
267 * an interrupt in the middle of a task switch..
269 int index
= pgd_index(ear0
);
275 pgd
= (pgd_t
*) __get_TTBR();
276 pgd
= (pgd_t
*)__va(pgd
) + index
;
277 pgd_k
= ((pgd_t
*)(init_mm
.pgd
)) + index
;
279 if (!pgd_present(*pgd_k
))
281 //set_pgd(pgd, *pgd_k); /////// gcc ICE's on this line
283 pud_k
= pud_offset(pgd_k
, ear0
);
284 if (!pud_present(*pud_k
))
287 pmd_k
= pmd_offset(pud_k
, ear0
);
288 if (!pmd_present(*pmd_k
))
291 pud
= pud_offset(pgd
, ear0
);
292 pmd
= pmd_offset(pud
, ear0
);
293 set_pmd(pmd
, *pmd_k
);
295 pte_k
= pte_offset_kernel(pmd_k
, ear0
);
296 if (!pte_present(*pte_k
))
300 } /* end do_page_fault() */