^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * arch/sparc/kernel/traps.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 1995, 2008 David S. Miller (davem@davemloft.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright 2000 Jakub Jelinek (jakub@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * I hate traps on the sparc, grrr...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sched/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/mm_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/kdebug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <asm/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <asm/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/traps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "entry.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) /* #define TRAP_DEBUG */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static void instruction_dump(unsigned long *pc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if((((unsigned long) pc) & 3))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) for(i = -3; i < 6; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) printk("%c%08lx%c",i?' ':'<',pc[i],i?' ':'>');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static int die_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* Amuse the user. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) printk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) " \\|/ ____ \\|/\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) " \"@'/ ,. \\`@\"\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) " /_| \\__/ |_\\\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) " \\__U_/\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) printk("%s(%d): %s [#%d]\n", current->comm, task_pid_nr(current), str, ++die_counter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) show_regs(regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) __SAVE; __SAVE; __SAVE; __SAVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) __SAVE; __SAVE; __SAVE; __SAVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) __RESTORE; __RESTORE; __RESTORE; __RESTORE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) __RESTORE; __RESTORE; __RESTORE; __RESTORE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct reg_window32 *rw = (struct reg_window32 *)regs->u_regs[UREG_FP];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* Stop the back trace when we hit userland or we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * find some badly aligned kernel stack. Set an upper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * bound in case our stack is trashed and we loop.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) while(rw &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) count++ < 30 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) (((unsigned long) rw) >= PAGE_OFFSET) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) !(((unsigned long) rw) & 0x7)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) printk("Caller[%08lx]: %pS\n", rw->ins[7],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) (void *) rw->ins[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) rw = (struct reg_window32 *)rw->ins[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) printk("Instruction DUMP:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) instruction_dump ((unsigned long *) regs->pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if(regs->psr & PSR_PS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) do_exit(SIGKILL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) do_exit(SIGSEGV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) void do_hw_interrupt(struct pt_regs *regs, unsigned long type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if(type < 0x80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) /* Sun OS's puke from bad traps, Linux survives! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) printk("Unimplemented Sparc TRAP, type = %02lx\n", type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) die_if_kernel("Whee... Hello Mr. Penguin", regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if(regs->psr & PSR_PS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) die_if_kernel("Kernel bad trap", regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) force_sig_fault(SIGILL, ILL_ILLTRP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) (void __user *)regs->pc, type - 0x80);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) void do_illegal_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) if(psr & PSR_PS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) die_if_kernel("Kernel illegal instruction", regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #ifdef TRAP_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) printk("Ill instr. at pc=%08lx instruction is %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) regs->pc, *(unsigned long *)regs->pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) send_sig_fault(SIGILL, ILL_ILLOPC, (void __user *)pc, 0, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) void do_priv_instruction(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if(psr & PSR_PS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) die_if_kernel("Penguin instruction from Penguin mode??!?!", regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) send_sig_fault(SIGILL, ILL_PRVOPC, (void __user *)pc, 0, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /* XXX User may want to be allowed to do this. XXX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) void do_memaccess_unaligned(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if(regs->psr & PSR_PS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) printk("KERNEL MNA at pc %08lx npc %08lx called by %08lx\n", pc, npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) regs->u_regs[UREG_RETPC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) die_if_kernel("BOGUS", regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* die_if_kernel("Kernel MNA access", regs); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) show_regs (regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) instruction_dump ((unsigned long *) regs->pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) printk ("do_MNA!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) send_sig_fault(SIGBUS, BUS_ADRALN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* FIXME: Should dig out mna address */ (void *)0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 0, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static unsigned long init_fsr = 0x0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static unsigned long init_fregs[32] __attribute__ ((aligned (8))) =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) { ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL, ~0UL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) void do_fpd_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) /* Sanity check... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if(psr & PSR_PS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) die_if_kernel("Kernel gets FloatingPenguinUnit disabled trap", regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) put_psr(get_psr() | PSR_EF); /* Allow FPU ops. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) regs->psr |= PSR_EF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if(last_task_used_math == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) if(last_task_used_math) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* Other processes fpu state, save away */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct task_struct *fptask = last_task_used_math;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) fpsave(&fptask->thread.float_regs[0], &fptask->thread.fsr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) &fptask->thread.fpqueue[0], &fptask->thread.fpqdepth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) last_task_used_math = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if(used_math()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) fpload(¤t->thread.float_regs[0], ¤t->thread.fsr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* Set initial sane state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) fpload(&init_fregs[0], &init_fsr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) set_used_math();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if(!used_math()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) fpload(&init_fregs[0], &init_fsr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) set_used_math();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) fpload(¤t->thread.float_regs[0], ¤t->thread.fsr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) set_thread_flag(TIF_USEDFPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) static unsigned long fake_regs[32] __attribute__ ((aligned (8)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) static unsigned long fake_fsr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static unsigned long fake_queue[32] __attribute__ ((aligned (8)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static unsigned long fake_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) void do_fpe_trap(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static int calls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned long fsr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct task_struct *fpt = last_task_used_math;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct task_struct *fpt = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) put_psr(get_psr() | PSR_EF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* If nobody owns the fpu right now, just clear the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * error into our fake static buffer and hope it don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * happen again. Thank you crashme...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if(!fpt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) if (!test_tsk_thread_flag(fpt, TIF_USEDFPU)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) fpsave(&fake_regs[0], &fake_fsr, &fake_queue[0], &fake_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) regs->psr &= ~PSR_EF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) fpsave(&fpt->thread.float_regs[0], &fpt->thread.fsr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) &fpt->thread.fpqueue[0], &fpt->thread.fpqdepth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #ifdef DEBUG_FPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) printk("Hmm, FP exception, fsr was %016lx\n", fpt->thread.fsr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) switch ((fpt->thread.fsr & 0x1c000)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* switch on the contents of the ftt [floating point trap type] field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #ifdef DEBUG_FPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) case (1 << 14):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) printk("IEEE_754_exception\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) case (2 << 14): /* unfinished_FPop (underflow & co) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) case (3 << 14): /* unimplemented_FPop (quad stuff, maybe sqrt) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ret = do_mathemu(regs, fpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #ifdef DEBUG_FPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) case (4 << 14):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) printk("sequence_error (OS bug...)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) case (5 << 14):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) printk("hardware_error (uhoh!)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) case (6 << 14):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) printk("invalid_fp_register (user error)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) #endif /* DEBUG_FPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) /* If we successfully emulated the FPop, we pretend the trap never happened :-> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) fpload(¤t->thread.float_regs[0], ¤t->thread.fsr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* nope, better SIGFPE the offending process... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) clear_tsk_thread_flag(fpt, TIF_USEDFPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if(psr & PSR_PS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* The first fsr store/load we tried trapped,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) * the second one will not (we hope).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) printk("WARNING: FPU exception from kernel mode. at pc=%08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) regs->pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) regs->pc = regs->npc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) regs->npc += 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) calls++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if(calls > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) die_if_kernel("Too many Penguin-FPU traps from kernel mode",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) fsr = fpt->thread.fsr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) code = FPE_FLTUNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if ((fsr & 0x1c000) == (1 << 14)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (fsr & 0x10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) code = FPE_FLTINV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) else if (fsr & 0x08)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) code = FPE_FLTOVF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) else if (fsr & 0x04)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) code = FPE_FLTUND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) else if (fsr & 0x02)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) code = FPE_FLTDIV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) else if (fsr & 0x01)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) code = FPE_FLTRES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) send_sig_fault(SIGFPE, code, (void __user *)pc, 0, fpt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) last_task_used_math = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) regs->psr &= ~PSR_EF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if(calls > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) calls=0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) void handle_tag_overflow(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) if(psr & PSR_PS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) die_if_kernel("Penguin overflow trap from kernel mode", regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) send_sig_fault(SIGEMT, EMT_TAGOVF, (void __user *)pc, 0, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) void handle_watchpoint(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) #ifdef TRAP_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) printk("Watchpoint detected at PC %08lx NPC %08lx PSR %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) pc, npc, psr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if(psr & PSR_PS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) panic("Tell me what a watchpoint trap is, and I'll then deal "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) "with such a beast...");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) void handle_reg_access(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) #ifdef TRAP_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) printk("Register Access Exception at PC %08lx NPC %08lx PSR %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) pc, npc, psr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) force_sig_fault(SIGBUS, BUS_OBJERR, (void __user *)pc, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) void handle_cp_disabled(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) send_sig_fault(SIGILL, ILL_COPROC, (void __user *)pc, 0, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) void handle_cp_exception(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) #ifdef TRAP_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) printk("Co-Processor Exception at PC %08lx NPC %08lx PSR %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) pc, npc, psr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) send_sig_fault(SIGILL, ILL_COPROC, (void __user *)pc, 0, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) void handle_hw_divzero(struct pt_regs *regs, unsigned long pc, unsigned long npc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) unsigned long psr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) send_sig_fault(SIGFPE, FPE_INTDIV, (void __user *)pc, 0, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) #ifdef CONFIG_DEBUG_BUGVERBOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) void do_BUG(const char *file, int line)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) // bust_spinlocks(1); XXX Not in our original BUG()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) printk("kernel BUG at %s:%d!\n", file, line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) EXPORT_SYMBOL(do_BUG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) /* Since we have our mappings set up, on multiprocessors we can spin them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * up here so that timer interrupts work during initialization.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) void trap_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) extern void thread_info_offsets_are_bolixed_pete(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* Force linker to barf if mismatched */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) if (TI_UWINMASK != offsetof(struct thread_info, uwinmask) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) TI_TASK != offsetof(struct thread_info, task) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) TI_FLAGS != offsetof(struct thread_info, flags) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) TI_CPU != offsetof(struct thread_info, cpu) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) TI_PREEMPT != offsetof(struct thread_info, preempt_count) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) TI_SOFTIRQ != offsetof(struct thread_info, softirq_count) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) TI_HARDIRQ != offsetof(struct thread_info, hardirq_count) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) TI_KSP != offsetof(struct thread_info, ksp) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) TI_KPC != offsetof(struct thread_info, kpc) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) TI_KPSR != offsetof(struct thread_info, kpsr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) TI_KWIM != offsetof(struct thread_info, kwim) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) TI_REG_WINDOW != offsetof(struct thread_info, reg_window) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) TI_RWIN_SPTRS != offsetof(struct thread_info, rwbuf_stkptrs) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) TI_W_SAVED != offsetof(struct thread_info, w_saved))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) thread_info_offsets_are_bolixed_pete();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /* Attach to the address space of init_task. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) mmgrab(&init_mm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) current->active_mm = &init_mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) /* NOTE: Other cpus have this done as they are started
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * up on SMP.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }