2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
7 * Copyright (C) 1995, 1996, 1997, 1998 by Ralf Baechle
8 * Copyright 1999 SuSE GmbH (Philipp Rumpf, prumpf@tux.org)
9 * Copyright 1999 Hewlett Packard Co.
14 #include <linux/ptrace.h>
15 #include <linux/sched.h>
16 #include <linux/interrupt.h>
17 #include <linux/module.h>
19 #include <asm/uaccess.h>
20 #include <asm/traps.h>
22 #define PRINT_USER_FAULTS /* (turn this on if you want user faults to be */
23 /* dumped to the console via printk) */
26 /* Various important other fields */
27 #define bit22set(x) (x & 0x00000200)
28 #define bits23_25set(x) (x & 0x000001c0)
29 #define isGraphicsFlushRead(x) ((x & 0xfc003fdf) == 0x04001a80)
30 /* extended opcode is 0x6a */
32 #define BITSSET 0x1c0 /* for identifying LDCW */
35 DEFINE_PER_CPU(struct exception_data
, exception_data
);
38 * parisc_acctyp(unsigned int inst) --
39 * Given a PA-RISC memory access instruction, determine if the
40 * the instruction would perform a memory read or memory write
43 * This function assumes that the given instruction is a memory access
44 * instruction (i.e. you should really only call it if you know that
45 * the instruction has generated some sort of a memory access fault).
48 * VM_READ if read operation
49 * VM_WRITE if write operation
50 * VM_EXEC if execute operation
53 parisc_acctyp(unsigned long code
, unsigned int inst
)
55 if (code
== 6 || code
== 16)
58 switch (inst
& 0xf0000000) {
59 case 0x40000000: /* load */
60 case 0x50000000: /* new load */
63 case 0x60000000: /* store */
64 case 0x70000000: /* new store */
67 case 0x20000000: /* coproc */
68 case 0x30000000: /* coproc2 */
72 case 0x0: /* indexed/memory management */
75 * Check for the 'Graphics Flush Read' instruction.
76 * It resembles an FDC instruction, except for bits
77 * 20 and 21. Any combination other than zero will
78 * utilize the block mover functionality on some
79 * older PA-RISC platforms. The case where a block
80 * move is performed from VM to graphics IO space
81 * should be treated as a READ.
83 * The significance of bits 20,21 in the FDC
86 * 00 Flush data cache (normal instruction behavior)
87 * 01 Graphics flush write (IO space -> VM)
88 * 10 Graphics flush read (VM -> IO space)
89 * 11 Graphics flush read/write (VM <-> IO space)
91 if (isGraphicsFlushRead(inst
))
96 * Check for LDCWX and LDCWS (semaphore instructions).
97 * If bits 23 through 25 are all 1's it is one of
98 * the above two instructions and is a write.
100 * Note: With the limited bits we are looking at,
101 * this will also catch PROBEW and PROBEWI. However,
102 * these should never get in here because they don't
103 * generate exceptions of the type:
104 * Data TLB miss fault/data page fault
105 * Data memory protection trap
107 if (bits23_25set(inst
) == BITSSET
)
110 return VM_READ
; /* Default */
112 return VM_READ
; /* Default */
117 #undef isGraphicsFlushRead
122 int fixup_exception(struct pt_regs
*regs
)
124 const struct exception_table_entry
*fix
;
126 fix
= search_exception_tables(regs
->iaoq
[0]);
128 struct exception_data
*d
;
129 d
= &__get_cpu_var(exception_data
);
130 d
->fault_ip
= regs
->iaoq
[0];
131 d
->fault_space
= regs
->isr
;
132 d
->fault_addr
= regs
->ior
;
134 regs
->iaoq
[0] = ((fix
->fixup
) & ~3);
136 * NOTE: In some cases the faulting instruction
137 * may be in the delay slot of a branch. We
138 * don't want to take the branch, so we don't
139 * increment iaoq[1], instead we set it to be
140 * iaoq[0]+4, and clear the B bit in the PSW
142 regs
->iaoq
[1] = regs
->iaoq
[0] + 4;
143 regs
->gr
[0] &= ~PSW_B
; /* IPSW in gr[0] */
151 void do_page_fault(struct pt_regs
*regs
, unsigned long code
,
152 unsigned long address
)
154 struct vm_area_struct
*vma
, *prev_vma
;
155 struct task_struct
*tsk
= current
;
156 struct mm_struct
*mm
= tsk
->mm
;
157 unsigned long acc_type
;
160 if (in_atomic() || !mm
)
163 down_read(&mm
->mmap_sem
);
164 vma
= find_vma_prev(mm
, address
, &prev_vma
);
165 if (!vma
|| address
< vma
->vm_start
)
166 goto check_expansion
;
168 * Ok, we have a good vm_area for this memory access. We still need to
169 * check the access permissions.
174 acc_type
= parisc_acctyp(code
,regs
->iir
);
176 if ((vma
->vm_flags
& acc_type
) != acc_type
)
180 * If for any reason at all we couldn't handle the fault, make
181 * sure we exit gracefully rather than endlessly redo the
185 fault
= handle_mm_fault(mm
, vma
, address
, (acc_type
& VM_WRITE
) ? FAULT_FLAG_WRITE
: 0);
186 if (unlikely(fault
& VM_FAULT_ERROR
)) {
188 * We hit a shared mapping outside of the file, or some
189 * other thing happened to us that made us unable to
190 * handle the page fault gracefully.
192 if (fault
& VM_FAULT_OOM
)
194 else if (fault
& VM_FAULT_SIGBUS
)
198 if (fault
& VM_FAULT_MAJOR
)
202 up_read(&mm
->mmap_sem
);
207 if (vma
&& (expand_stack(vma
, address
) == 0))
211 * Something tried to access memory that isn't in our memory map..
214 up_read(&mm
->mmap_sem
);
216 if (user_mode(regs
)) {
219 #ifdef PRINT_USER_FAULTS
220 printk(KERN_DEBUG
"\n");
221 printk(KERN_DEBUG
"do_page_fault() pid=%d command='%s' type=%lu address=0x%08lx\n",
222 task_pid_nr(tsk
), tsk
->comm
, code
, address
);
224 printk(KERN_DEBUG
"vm_start = 0x%08lx, vm_end = 0x%08lx\n",
225 vma
->vm_start
, vma
->vm_end
);
229 si
.si_signo
= SIGSEGV
;
231 si
.si_code
= SEGV_MAPERR
;
232 si
.si_addr
= (void __user
*) address
;
233 force_sig_info(SIGSEGV
, &si
, current
);
239 if (!user_mode(regs
) && fixup_exception(regs
)) {
243 parisc_terminate("Bad Address (null pointer deref?)", regs
, code
, address
);
246 up_read(&mm
->mmap_sem
);
247 if (!user_mode(regs
))
249 pagefault_out_of_memory();