]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - arch/avr32/kernel/traps.c
sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[mirror_ubuntu-jammy-kernel.git] / arch / avr32 / kernel / traps.c
CommitLineData
5f97f7f9
HS
1/*
2 * Copyright (C) 2004-2006 Atmel Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
623b0355
HS
8
9#include <linux/bug.h>
ba84be23 10#include <linux/hardirq.h>
5f97f7f9 11#include <linux/init.h>
5f97f7f9 12#include <linux/kallsyms.h>
e7ba176b 13#include <linux/kdebug.h>
9a2950fe
PG
14#include <linux/extable.h>
15#include <linux/module.h> /* print_modules */
5f97f7f9 16#include <linux/notifier.h>
3f07c014 17#include <linux/sched/signal.h>
623b0355 18#include <linux/uaccess.h>
5f97f7f9 19
5f97f7f9 20#include <asm/addrspace.h>
5f97f7f9 21#include <asm/mmu_context.h>
623b0355
HS
22#include <asm/ocd.h>
23#include <asm/sysreg.h>
24#include <asm/traps.h>
5f97f7f9 25
5f97f7f9
HS
26static DEFINE_SPINLOCK(die_lock);
27
9402c95f 28void die(const char *str, struct pt_regs *regs, long err)
5f97f7f9 29{
5f97f7f9
HS
30 static int die_counter;
31
32 console_verbose();
33 spin_lock_irq(&die_lock);
34 bust_spinlocks(1);
35
ad361c98 36 printk(KERN_ALERT "Oops: %s, sig: %ld [#%d]\n",
623b0355 37 str, err, ++die_counter);
ad361c98
JP
38
39 printk(KERN_EMERG);
40
623b0355 41#ifdef CONFIG_PREEMPT
ad361c98 42 printk(KERN_CONT "PREEMPT ");
623b0355
HS
43#endif
44#ifdef CONFIG_FRAME_POINTER
ad361c98 45 printk(KERN_CONT "FRAME_POINTER ");
623b0355
HS
46#endif
47 if (current_cpu_data.features & AVR32_FEATURE_OCD) {
8dfe8f29 48 unsigned long did = ocd_read(DID);
ad361c98 49 printk(KERN_CONT "chip: 0x%03lx:0x%04lx rev %lu\n",
623b0355
HS
50 (did >> 1) & 0x7ff,
51 (did >> 12) & 0x7fff,
52 (did >> 28) & 0xf);
53 } else {
ad361c98 54 printk(KERN_CONT "cpu: arch %u r%u / core %u r%u\n",
623b0355
HS
55 current_cpu_data.arch_type,
56 current_cpu_data.arch_revision,
57 current_cpu_data.cpu_type,
58 current_cpu_data.cpu_revision);
5f97f7f9
HS
59 }
60
623b0355
HS
61 print_modules();
62 show_regs_log_lvl(regs, KERN_EMERG);
63 show_stack_log_lvl(current, regs->sp, regs, KERN_EMERG);
5f97f7f9 64 bust_spinlocks(0);
373d4d09 65 add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
5f97f7f9 66 spin_unlock_irq(&die_lock);
623b0355
HS
67
68 if (in_interrupt())
69 panic("Fatal exception in interrupt");
70
71 if (panic_on_oops)
72 panic("Fatal exception");
73
74 do_exit(err);
5f97f7f9
HS
75}
76
623b0355
HS
77void _exception(long signr, struct pt_regs *regs, int code,
78 unsigned long addr)
5f97f7f9 79{
623b0355
HS
80 siginfo_t info;
81
bb6e6470
HS
82 if (!user_mode(regs)) {
83 const struct exception_table_entry *fixup;
84
85 /* Are we prepared to handle this kernel fault? */
86 fixup = search_exception_tables(regs->pc);
87 if (fixup) {
88 regs->pc = fixup->fixup;
89 return;
90 }
623b0355 91 die("Unhandled exception in kernel mode", regs, signr);
bb6e6470 92 }
623b0355
HS
93
94 memset(&info, 0, sizeof(info));
95 info.si_signo = signr;
96 info.si_code = code;
97 info.si_addr = (void __user *)addr;
98 force_sig_info(signr, &info, current);
623b0355 99}
5f97f7f9 100
623b0355
HS
101asmlinkage void do_nmi(unsigned long ecr, struct pt_regs *regs)
102{
e7ba176b
HS
103 int ret;
104
105 nmi_enter();
106
107 ret = notify_die(DIE_NMI, "NMI", regs, 0, ecr, SIGINT);
108 switch (ret) {
109 case NOTIFY_OK:
110 case NOTIFY_STOP:
3d431a74 111 break;
e7ba176b
HS
112 case NOTIFY_BAD:
113 die("Fatal Non-Maskable Interrupt", regs, SIGINT);
114 default:
3d431a74
MS
115 printk(KERN_ALERT "Got NMI, but nobody cared. Disabling...\n");
116 nmi_disable();
e7ba176b
HS
117 break;
118 }
3d431a74 119 nmi_exit();
5f97f7f9
HS
120}
121
122asmlinkage void do_critical_exception(unsigned long ecr, struct pt_regs *regs)
123{
623b0355 124 die("Critical exception", regs, SIGKILL);
5f97f7f9
HS
125}
126
127asmlinkage void do_address_exception(unsigned long ecr, struct pt_regs *regs)
128{
623b0355 129 _exception(SIGBUS, regs, BUS_ADRALN, regs->pc);
5f97f7f9
HS
130}
131
132/* This way of handling undefined instructions is stolen from ARM */
133static LIST_HEAD(undef_hook);
e89b064a 134static DEFINE_SPINLOCK(undef_lock);
5f97f7f9
HS
135
136void register_undef_hook(struct undef_hook *hook)
137{
138 spin_lock_irq(&undef_lock);
139 list_add(&hook->node, &undef_hook);
140 spin_unlock_irq(&undef_lock);
141}
142
143void unregister_undef_hook(struct undef_hook *hook)
144{
145 spin_lock_irq(&undef_lock);
146 list_del(&hook->node);
147 spin_unlock_irq(&undef_lock);
148}
149
150static int do_cop_absent(u32 insn)
151{
152 int cop_nr;
153 u32 cpucr;
623b0355
HS
154
155 if ((insn & 0xfdf00000) == 0xf1900000)
5f97f7f9
HS
156 /* LDC0 */
157 cop_nr = 0;
158 else
159 cop_nr = (insn >> 13) & 0x7;
160
161 /* Try enabling the coprocessor */
162 cpucr = sysreg_read(CPUCR);
163 cpucr |= (1 << (24 + cop_nr));
164 sysreg_write(CPUCR, cpucr);
165
166 cpucr = sysreg_read(CPUCR);
623b0355
HS
167 if (!(cpucr & (1 << (24 + cop_nr))))
168 return -ENODEV;
5f97f7f9
HS
169
170 return 0;
171}
172
957ecd7d 173#ifdef CONFIG_BUG
623b0355 174int is_valid_bugaddr(unsigned long pc)
5f97f7f9 175{
623b0355
HS
176 unsigned short opcode;
177
178 if (pc < PAGE_OFFSET)
179 return 0;
180 if (probe_kernel_address((u16 *)pc, opcode))
181 return 0;
5f97f7f9 182
623b0355 183 return opcode == AVR32_BUG_OPCODE;
5f97f7f9 184}
957ecd7d 185#endif
5f97f7f9
HS
186
187asmlinkage void do_illegal_opcode(unsigned long ecr, struct pt_regs *regs)
188{
189 u32 insn;
190 struct undef_hook *hook;
5f97f7f9 191 void __user *pc;
623b0355 192 long code;
5f97f7f9 193
957ecd7d 194#ifdef CONFIG_BUG
623b0355
HS
195 if (!user_mode(regs) && (ecr == ECR_ILLEGAL_OPCODE)) {
196 enum bug_trap_type type;
197
608e2619 198 type = report_bug(regs->pc, regs);
623b0355
HS
199 switch (type) {
200 case BUG_TRAP_TYPE_NONE:
201 break;
202 case BUG_TRAP_TYPE_WARN:
203 regs->pc += 2;
204 return;
205 case BUG_TRAP_TYPE_BUG:
206 die("Kernel BUG", regs, SIGKILL);
207 }
208 }
957ecd7d 209#endif
5f97f7f9
HS
210
211 local_irq_enable();
212
623b0355
HS
213 if (user_mode(regs)) {
214 pc = (void __user *)instruction_pointer(regs);
215 if (get_user(insn, (u32 __user *)pc))
216 goto invalid_area;
5f97f7f9 217
623b0355 218 if (ecr == ECR_COPROC_ABSENT && !do_cop_absent(insn))
5f97f7f9 219 return;
5f97f7f9 220
623b0355
HS
221 spin_lock_irq(&undef_lock);
222 list_for_each_entry(hook, &undef_hook, node) {
223 if ((insn & hook->insn_mask) == hook->insn_val) {
224 if (hook->fn(regs, insn) == 0) {
225 spin_unlock_irq(&undef_lock);
226 return;
227 }
5f97f7f9
HS
228 }
229 }
623b0355 230 spin_unlock_irq(&undef_lock);
5f97f7f9 231 }
5f97f7f9 232
5f97f7f9 233 switch (ecr) {
5f97f7f9 234 case ECR_PRIVILEGE_VIOLATION:
623b0355 235 code = ILL_PRVOPC;
5f97f7f9
HS
236 break;
237 case ECR_COPROC_ABSENT:
623b0355 238 code = ILL_COPROC;
5f97f7f9
HS
239 break;
240 default:
623b0355
HS
241 code = ILL_ILLOPC;
242 break;
5f97f7f9
HS
243 }
244
623b0355 245 _exception(SIGILL, regs, code, regs->pc);
5f97f7f9
HS
246 return;
247
623b0355
HS
248invalid_area:
249 _exception(SIGSEGV, regs, SEGV_MAPERR, regs->pc);
5f97f7f9
HS
250}
251
252asmlinkage void do_fpe(unsigned long ecr, struct pt_regs *regs)
253{
623b0355
HS
254 /* We have no FPU yet */
255 _exception(SIGILL, regs, ILL_COPROC, regs->pc);
5f97f7f9
HS
256}
257
258
259void __init trap_init(void)
260{
261
262}