1
2
3
4
5
6
7#include <linux/sched.h>
8#include <linux/kernel.h>
9#include <linux/mm.h>
10#include <asm/io.h>
11
12#define __EXTERN_INLINE inline
13#include <asm/mmu_context.h>
14#include <asm/tlbflush.h>
15#undef __EXTERN_INLINE
16
17#include <linux/signal.h>
18#include <linux/errno.h>
19#include <linux/string.h>
20#include <linux/types.h>
21#include <linux/ptrace.h>
22#include <linux/mman.h>
23#include <linux/smp.h>
24#include <linux/interrupt.h>
25#include <linux/module.h>
26
27#include <asm/system.h>
28#include <asm/uaccess.h>
29
30extern void die_if_kernel(char *,struct pt_regs *,long, unsigned long *);
31
32
33
34
35
36
37#ifndef CONFIG_SMP
38unsigned long last_asn = ASN_FIRST_VERSION;
39#endif
40
41void
42__load_new_mm_context(struct mm_struct *next_mm)
43{
44 unsigned long mmc;
45 struct pcb_struct *pcb;
46
47 mmc = __get_new_mm_context(next_mm, smp_processor_id());
48 next_mm->context[smp_processor_id()] = mmc;
49
50 pcb = ¤t_thread_info()->pcb;
51 pcb->asn = mmc & HARDWARE_ASN_MASK;
52 pcb->ptbr = ((unsigned long) next_mm->pgd - IDENT_ADDR) >> PAGE_SHIFT;
53
54 __reload_thread(pcb);
55}
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80#define dpf_reg(r) \
81 (((unsigned long *)regs)[(r) <= 8 ? (r) : (r) <= 15 ? (r)-16 : \
82 (r) <= 18 ? (r)+8 : (r)-10])
83
84asmlinkage void
85do_page_fault(unsigned long address, unsigned long mmcsr,
86 long cause, struct pt_regs *regs)
87{
88 struct vm_area_struct * vma;
89 struct mm_struct *mm = current->mm;
90 const struct exception_table_entry *fixup;
91 int fault, si_code = SEGV_MAPERR;
92 siginfo_t info;
93
94
95
96
97 if (cause == 0) {
98 unsigned int insn;
99 __get_user(insn, (unsigned int __user *)regs->pc);
100 if ((insn >> 21 & 0x1f) == 0x1f &&
101
102 (1ul << (insn >> 26) & 0x30f00001400ul)) {
103 regs->pc += 4;
104 return;
105 }
106 }
107
108
109
110 if (!mm || in_atomic())
111 goto no_context;
112
113#ifdef CONFIG_ALPHA_LARGE_VMALLOC
114 if (address >= TASK_SIZE)
115 goto vmalloc_fault;
116#endif
117
118 down_read(&mm->mmap_sem);
119 vma = find_vma(mm, address);
120 if (!vma)
121 goto bad_area;
122 if (vma->vm_start <= address)
123 goto good_area;
124 if (!(vma->vm_flags & VM_GROWSDOWN))
125 goto bad_area;
126 if (expand_stack(vma, address))
127 goto bad_area;
128
129
130
131 good_area:
132 si_code = SEGV_ACCERR;
133 if (cause < 0) {
134 if (!(vma->vm_flags & VM_EXEC))
135 goto bad_area;
136 } else if (!cause) {
137
138 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
139 goto bad_area;
140 } else {
141 if (!(vma->vm_flags & VM_WRITE))
142 goto bad_area;
143 }
144
145
146
147
148 fault = handle_mm_fault(mm, vma, address, cause > 0 ? FAULT_FLAG_WRITE : 0);
149 up_read(&mm->mmap_sem);
150 if (unlikely(fault & VM_FAULT_ERROR)) {
151 if (fault & VM_FAULT_OOM)
152 goto out_of_memory;
153 else if (fault & VM_FAULT_SIGBUS)
154 goto do_sigbus;
155 BUG();
156 }
157 if (fault & VM_FAULT_MAJOR)
158 current->maj_flt++;
159 else
160 current->min_flt++;
161 return;
162
163
164
165 bad_area:
166 up_read(&mm->mmap_sem);
167
168 if (user_mode(regs))
169 goto do_sigsegv;
170
171 no_context:
172
173 if ((fixup = search_exception_tables(regs->pc)) != 0) {
174 unsigned long newpc;
175 newpc = fixup_exception(dpf_reg, fixup, regs->pc);
176 regs->pc = newpc;
177 return;
178 }
179
180
181
182 printk(KERN_ALERT "Unable to handle kernel paging request at "
183 "virtual address %016lx\n", address);
184 die_if_kernel("Oops", regs, cause, (unsigned long*)regs - 16);
185 do_exit(SIGKILL);
186
187
188
189 out_of_memory:
190 if (!user_mode(regs))
191 goto no_context;
192 pagefault_out_of_memory();
193 return;
194
195 do_sigbus:
196
197
198 info.si_signo = SIGBUS;
199 info.si_errno = 0;
200 info.si_code = BUS_ADRERR;
201 info.si_addr = (void __user *) address;
202 force_sig_info(SIGBUS, &info, current);
203 if (!user_mode(regs))
204 goto no_context;
205 return;
206
207 do_sigsegv:
208 info.si_signo = SIGSEGV;
209 info.si_errno = 0;
210 info.si_code = si_code;
211 info.si_addr = (void __user *) address;
212 force_sig_info(SIGSEGV, &info, current);
213 return;
214
215#ifdef CONFIG_ALPHA_LARGE_VMALLOC
216 vmalloc_fault:
217 if (user_mode(regs))
218 goto do_sigsegv;
219 else {
220
221
222 long index = pgd_index(address);
223 pgd_t *pgd, *pgd_k;
224
225 pgd = current->active_mm->pgd + index;
226 pgd_k = swapper_pg_dir + index;
227 if (!pgd_present(*pgd) && pgd_present(*pgd_k)) {
228 pgd_val(*pgd) = pgd_val(*pgd_k);
229 return;
230 }
231 goto no_context;
232 }
233#endif
234}
235