2 * linux/arch/m68k/mm/fault.c
4 * Copyright (C) 1995 Hamish Macdonald
7 #include <linux/mman.h>
9 #include <linux/kernel.h>
10 #include <linux/ptrace.h>
11 #include <linux/interrupt.h>
13 #include <asm/setup.h>
14 #include <asm/traps.h>
15 #include <asm/system.h>
16 #include <asm/uaccess.h>
17 #include <asm/pgalloc.h>
19 extern void die_if_kernel(char *, struct pt_regs
*, long);
20 extern const int frame_extra_sizes
[]; /* in m68k/kernel/signal.c */
23 * This routine handles page faults. It determines the problem, and
24 * then passes it off to one of the appropriate routines.
27 * bit 0 == 0 means no page found, 1 means protection fault
28 * bit 1 == 0 means read, 1 means write
30 * If this routine detects a bad access, it returns 1, otherwise it
33 asmlinkage
int do_page_fault(struct pt_regs
*regs
, unsigned long address
,
34 unsigned long error_code
)
36 struct mm_struct
*mm
= current
->mm
;
37 struct vm_area_struct
* vma
;
42 printk ("regs->sr=%#x, regs->pc=%#lx, address=%#lx, %ld, %p\n",
43 regs
->sr
, regs
->pc
, address
, error_code
,
48 * If we're in an interrupt or have no user
49 * context, we must not take the fault..
51 if (in_interrupt() || !mm
)
56 vma
= find_vma(mm
, address
);
59 if (vma
->vm_flags
& VM_IO
)
61 if (vma
->vm_start
<= address
)
63 if (!(vma
->vm_flags
& VM_GROWSDOWN
))
65 if (user_mode(regs
)) {
66 /* Accessing the stack below usp is always a bug. The
67 "+ 256" is there due to some instructions doing
68 pre-decrement on the stack and that doesn't show up
70 if (address
+ 256 < rdusp())
73 if (expand_stack(vma
, address
))
77 * Ok, we have a good vm_area for this memory access, so
82 switch (error_code
& 3) {
83 default: /* 3: write, present */
85 case 2: /* write, not present */
86 if (!(vma
->vm_flags
& VM_WRITE
))
90 case 1: /* read, present */
92 case 0: /* read, not present */
93 if (!(vma
->vm_flags
& (VM_READ
| VM_EXEC
)))
98 * If for any reason at all we couldn't handle the fault,
99 * make sure we exit gracefully rather than endlessly redo
102 fault
= handle_mm_fault(current
, vma
, address
, write
);
108 /* There seems to be a missing invalidate somewhere in do_no_page.
109 * Until I found it, this one cures the problem and makes
110 * 1.2 run on the 68040 (Martin Apel).
112 if (CPU_IS_040_OR_060
)
113 flush_tlb_page(vma
, address
);
118 * Something tried to access memory that isn't in our memory map..
119 * Fix it, but check if it's kernel or user first..
124 /* User mode accesses just cause a SIGSEGV */
125 if (user_mode(regs
)) {
127 info
.si_signo
= SIGSEGV
;
128 info
.si_code
= SEGV_MAPERR
;
129 info
.si_addr
= (void *)address
;
130 force_sig_info(SIGSEGV
, &info
, current
);
135 /* Are we prepared to handle this kernel fault? */
136 if ((fixup
= search_exception_table(regs
->pc
)) != 0) {
137 struct pt_regs
*tregs
;
138 /* Create a new four word stack frame, discarding the old
140 regs
->stkadj
= frame_extra_sizes
[regs
->format
];
141 tregs
= (struct pt_regs
*)((ulong
)regs
+ regs
->stkadj
);
142 tregs
->vector
= regs
->vector
;
145 tregs
->sr
= regs
->sr
;
150 * Oops. The kernel tried to access some bad page. We'll have to
151 * terminate things with extreme prejudice.
153 if ((unsigned long) address
< PAGE_SIZE
) {
154 printk(KERN_ALERT
"Unable to handle kernel NULL pointer dereference");
156 printk(KERN_ALERT
"Unable to handle kernel access");
157 printk(" at virtual address %08lx\n",address
);
158 die_if_kernel("Oops", regs
, error_code
);
162 * We ran out of memory, or some other thing happened to us that made
163 * us unable to handle the page fault gracefully.
167 printk("VM: killing process %s\n", current
->comm
);
176 * Send a sigbus, regardless of whether we were in kernel
179 force_sig(SIGBUS
, current
);
181 /* Kernel mode? Handle exceptions or die */
182 if (!user_mode(regs
))