hc
2024-09-20 a36159eec6ca17402b0e146b86efaf76568dc353
kernel/arch/nds32/kernel/traps.c
....@@ -12,6 +12,7 @@
1212
1313 #include <asm/proc-fns.h>
1414 #include <asm/unistd.h>
15
+#include <asm/fpu.h>
1516
1617 #include <linux/ptrace.h>
1718 #include <nds32_intrinsic.h>
....@@ -96,18 +97,19 @@
9697 }
9798
9899 #define LOOP_TIMES (100)
99
-static void __dump(struct task_struct *tsk, unsigned long *base_reg)
100
+static void __dump(struct task_struct *tsk, unsigned long *base_reg,
101
+ const char *loglvl)
100102 {
101103 unsigned long ret_addr;
102104 int cnt = LOOP_TIMES, graph = 0;
103
- pr_emerg("Call Trace:\n");
105
+ printk("%sCall Trace:\n", loglvl);
104106 if (!IS_ENABLED(CONFIG_FRAME_POINTER)) {
105107 while (!kstack_end(base_reg)) {
106108 ret_addr = *base_reg++;
107109 if (__kernel_text_address(ret_addr)) {
108110 ret_addr = ftrace_graph_ret_addr(
109111 tsk, &graph, ret_addr, NULL);
110
- print_ip_sym(ret_addr);
112
+ print_ip_sym(loglvl, ret_addr);
111113 }
112114 if (--cnt < 0)
113115 break;
....@@ -123,17 +125,17 @@
123125
124126 ret_addr = ftrace_graph_ret_addr(
125127 tsk, &graph, ret_addr, NULL);
126
- print_ip_sym(ret_addr);
128
+ print_ip_sym(loglvl, ret_addr);
127129 }
128130 if (--cnt < 0)
129131 break;
130132 base_reg = (unsigned long *)next_fp;
131133 }
132134 }
133
- pr_emerg("\n");
135
+ printk("%s\n", loglvl);
134136 }
135137
136
-void show_stack(struct task_struct *tsk, unsigned long *sp)
138
+void show_stack(struct task_struct *tsk, unsigned long *sp, const char *loglvl)
137139 {
138140 unsigned long *base_reg;
139141
....@@ -150,7 +152,7 @@
150152 else
151153 __asm__ __volatile__("\tori\t%0, $fp, #0\n":"=r"(base_reg));
152154 }
153
- __dump(tsk, base_reg);
155
+ __dump(tsk, base_reg, loglvl);
154156 barrier();
155157 }
156158
....@@ -183,7 +185,7 @@
183185
184186 bust_spinlocks(0);
185187 spin_unlock_irq(&die_lock);
186
- do_exit(SIGSEGV);
188
+ make_task_dead(SIGSEGV);
187189 }
188190
189191 EXPORT_SYMBOL(die);
....@@ -204,7 +206,7 @@
204206 }
205207
206208 force_sig_fault(SIGILL, ILL_ILLTRP,
207
- (void __user *)instruction_pointer(regs) - 4, current);
209
+ (void __user *)instruction_pointer(regs) - 4);
208210 die_if_kernel("Oops - bad syscall", regs, n);
209211 return regs->uregs[0];
210212 }
....@@ -254,14 +256,15 @@
254256 cpu_cache_wbinval_page(base, true);
255257 }
256258
257
-void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
258
- int error_code, int si_code)
259
+static void send_sigtrap(struct pt_regs *regs, int error_code, int si_code)
259260 {
261
+ struct task_struct *tsk = current;
262
+
260263 tsk->thread.trap_no = ENTRY_DEBUG_RELATED;
261264 tsk->thread.error_code = error_code;
262265
263266 force_sig_fault(SIGTRAP, si_code,
264
- (void __user *)instruction_pointer(regs), tsk);
267
+ (void __user *)instruction_pointer(regs));
265268 }
266269
267270 void do_debug_trap(unsigned long entry, unsigned long addr,
....@@ -273,7 +276,7 @@
273276
274277 if (user_mode(regs)) {
275278 /* trap_signal */
276
- send_sigtrap(current, regs, 0, TRAP_BRKPT);
279
+ send_sigtrap(regs, 0, TRAP_BRKPT);
277280 } else {
278281 /* kernel_trap */
279282 if (!fixup_exception(regs))
....@@ -286,8 +289,8 @@
286289 pr_emerg("unhandled_interruption\n");
287290 show_regs(regs);
288291 if (!user_mode(regs))
289
- do_exit(SIGKILL);
290
- force_sig(SIGKILL, current);
292
+ make_task_dead(SIGKILL);
293
+ force_sig(SIGKILL);
291294 }
292295
293296 void unhandled_exceptions(unsigned long entry, unsigned long addr,
....@@ -297,8 +300,8 @@
297300 addr, type);
298301 show_regs(regs);
299302 if (!user_mode(regs))
300
- do_exit(SIGKILL);
301
- force_sig(SIGKILL, current);
303
+ make_task_dead(SIGKILL);
304
+ force_sig(SIGKILL);
302305 }
303306
304307 extern int do_page_fault(unsigned long entry, unsigned long addr,
....@@ -324,8 +327,8 @@
324327 pr_emerg("Reserved Instruction\n");
325328 show_regs(regs);
326329 if (!user_mode(regs))
327
- do_exit(SIGILL);
328
- force_sig(SIGILL, current);
330
+ make_task_dead(SIGILL);
331
+ force_sig(SIGILL);
329332 }
330333
331334 #ifdef CONFIG_ALIGNMENT_TRAP
....@@ -357,6 +360,21 @@
357360 } else if (type == ETYPE_RESERVED_INSTRUCTION) {
358361 /* Reserved instruction */
359362 do_revinsn(regs);
363
+ } else if (type == ETYPE_COPROCESSOR) {
364
+ /* Coprocessor */
365
+#if IS_ENABLED(CONFIG_FPU)
366
+ unsigned int fucop_exist = __nds32__mfsr(NDS32_SR_FUCOP_EXIST);
367
+ unsigned int cpid = ((itype & ITYPE_mskCPID) >> ITYPE_offCPID);
368
+
369
+ if ((cpid == FPU_CPID) &&
370
+ (fucop_exist & FUCOP_EXIST_mskCP0ISFPU)) {
371
+ unsigned int subtype = (itype & ITYPE_mskSTYPE);
372
+
373
+ if (true == do_fpu_exception(subtype, regs))
374
+ return;
375
+ }
376
+#endif
377
+ unhandled_exceptions(entry, addr, type, regs);
360378 } else if (type == ETYPE_TRAP && swid == SWID_RAISE_INTERRUPT_LEVEL) {
361379 /* trap, used on v3 EDM target debugging workaround */
362380 /*