1 /* $Id: fault.c,v 1.9 1999/01/04 16:03:53 ralf Exp $
3 * This file is subject to the terms and conditions of the GNU General Public
4 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 1995, 1996, 1997, 1998 by Ralf Baechle
9 #include <linux/signal.h>
10 #include <linux/sched.h>
11 #include <linux/interrupt.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/string.h>
15 #include <linux/types.h>
16 #include <linux/ptrace.h>
17 #include <linux/mman.h>
19 #include <linux/smp.h>
20 #include <linux/smp_lock.h>
21 #include <linux/version.h>
23 #include <asm/hardirq.h>
24 #include <asm/pgtable.h>
25 #include <asm/mmu_context.h>
26 #include <asm/softirq.h>
27 #include <asm/system.h>
28 #include <asm/uaccess.h>
30 #define development_version (LINUX_VERSION_CODE & 0x100)
32 extern void die(char *, struct pt_regs
*, unsigned long write
);
34 unsigned long asid_cache
;
37 * Macro for exception fixup code to access integer registers.
39 #define dpf_reg(r) (regs->regs[r])
42 * This routine handles page faults. It determines the address,
43 * and the problem, and then passes it off to one of the appropriate
46 asmlinkage
void do_page_fault(struct pt_regs
*regs
, unsigned long write
,
47 unsigned long address
)
49 struct vm_area_struct
* vma
;
50 struct task_struct
*tsk
= current
;
51 struct mm_struct
*mm
= tsk
->mm
;
55 * If we're in an interrupt or have no user
56 * context, we must not take the fault..
58 if (in_interrupt() || !mm
)
61 printk("[%s:%d:%08lx:%ld:%08lx]\n", current
->comm
, current
->pid
,
62 address
, write
, regs
->cp0_epc
);
65 vma
= find_vma(mm
, address
);
68 if (vma
->vm_start
<= address
)
70 if (!(vma
->vm_flags
& VM_GROWSDOWN
))
72 if (expand_stack(vma
, address
))
75 * Ok, we have a good vm_area for this memory access, so
80 if (!(vma
->vm_flags
& VM_WRITE
))
83 if (!(vma
->vm_flags
& (VM_READ
| VM_EXEC
)))
88 * If for any reason at all we couldn't handle the fault,
89 * make sure we exit gracefully rather than endlessly redo
93 int fault
= handle_mm_fault(tsk
, vma
, address
, write
);
103 * Something tried to access memory that isn't in our memory map..
104 * Fix it, but check if it's kernel or user first..
109 if (user_mode(regs
)) {
110 tsk
->tss
.cp0_badvaddr
= address
;
111 tsk
->tss
.error_code
= write
;
113 printk("do_page_fault() #2: sending SIGSEGV to %s for illegal %s\n"
114 "%08lx (epc == %08lx, ra == %08lx)\n",
116 write
? "write access to" : "read access from",
118 (unsigned long) regs
->cp0_epc
,
119 (unsigned long) regs
->regs
[31]);
121 force_sig(SIGSEGV
, tsk
);
126 /* Are we prepared to handle this kernel fault? */
127 fixup
= search_exception_table(regs
->cp0_epc
);
131 tsk
->tss
.cp0_baduaddr
= address
;
132 new_epc
= fixup_exception(dpf_reg
, fixup
, regs
->cp0_epc
);
133 if (development_version
)
134 printk(KERN_DEBUG
"%s: Exception at [<%lx>] (%lx)\n",
135 tsk
->comm
, regs
->cp0_epc
, new_epc
);
136 regs
->cp0_epc
= new_epc
;
141 * Oops. The kernel tried to access some bad page. We'll have to
142 * terminate things with extreme prejudice.
144 printk(KERN_ALERT
"Unable to handle kernel paging request at virtual "
145 "address %08lx, epc == %08lx, ra == %08lx\n",
146 address
, regs
->cp0_epc
, regs
->regs
[31]);
147 die("Oops", regs
, write
);
151 * We ran out of memory, or some other thing happened to us that made
152 * us unable to handle the page fault gracefully.
156 printk("VM: killing process %s\n", tsk
->comm
);
165 * Send a sigbus, regardless of whether we were in kernel
167 * XXX Store details about fault for siginfo handling into tss.
169 force_sig(SIGBUS
, tsk
);
171 /* Kernel mode? Handle exceptions or die */
172 if (!user_mode(regs
))