1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
4 #include <linux/sched.h>
5 #include <linux/signal.h>
6 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/user.h>
10 #include <linux/string.h>
11 #include <linux/linkage.h>
12 #include <linux/init.h>
13 #include <linux/ptrace.h>
14 #include <linux/kallsyms.h>
15 #include <linux/rtc.h>
16 #include <linux/uaccess.h>
18 #include <asm/setup.h>
19 #include <asm/traps.h>
20 #include <asm/pgalloc.h>
21 #include <asm/siginfo.h>
23 #include <asm/mmu_context.h>
25 #ifdef CONFIG_CPU_HAS_FPU
29 /* Defined in entry.S */
30 asmlinkage
void csky_trap(void);
32 asmlinkage
void csky_systemcall(void);
33 asmlinkage
void csky_cmpxchg(void);
34 asmlinkage
void csky_get_tls(void);
35 asmlinkage
void csky_irq(void);
37 asmlinkage
void csky_tlbinvalidl(void);
38 asmlinkage
void csky_tlbinvalids(void);
39 asmlinkage
void csky_tlbmodified(void);
41 /* Defined in head.S */
42 asmlinkage
void _start_smp_secondary(void);
44 void __init
pre_trap_init(void)
48 mtcr("vbr", vec_base
);
50 for (i
= 1; i
< 128; i
++)
51 VEC_INIT(i
, csky_trap
);
54 void __init
trap_init(void)
56 VEC_INIT(VEC_AUTOVEC
, csky_irq
);
58 /* setup trap0 trap2 trap3 */
59 VEC_INIT(VEC_TRAP0
, csky_systemcall
);
60 VEC_INIT(VEC_TRAP2
, csky_cmpxchg
);
61 VEC_INIT(VEC_TRAP3
, csky_get_tls
);
63 /* setup MMU TLB exception */
64 VEC_INIT(VEC_TLBINVALIDL
, csky_tlbinvalidl
);
65 VEC_INIT(VEC_TLBINVALIDS
, csky_tlbinvalids
);
66 VEC_INIT(VEC_TLBMODIFIED
, csky_tlbmodified
);
68 #ifdef CONFIG_CPU_HAS_FPU
73 mtcr("cr<28, 0>", virt_to_phys(vec_base
));
75 VEC_INIT(VEC_RESET
, (void *)virt_to_phys(_start_smp_secondary
));
79 void die_if_kernel(char *str
, struct pt_regs
*regs
, int nr
)
85 pr_err("%s: %08x\n", str
, nr
);
87 add_taint(TAINT_DIE
, LOCKDEP_NOW_UNRELIABLE
);
91 void buserr(struct pt_regs
*regs
)
93 #ifdef CONFIG_CPU_CK810
94 static unsigned long prev_pc
;
96 if ((regs
->pc
== prev_pc
) && prev_pc
!= 0) {
104 die_if_kernel("Kernel mode BUS error", regs
, 0);
106 pr_err("User mode Bus Error\n");
109 force_sig_fault(SIGSEGV
, 0, (void __user
*)regs
->pc
);
112 #define USR_BKPT 0x1464
113 asmlinkage
void trap_c(struct pt_regs
*regs
)
116 unsigned long vector
;
119 vector
= (mfcr("psr") >> 16) & 0xff;
123 die_if_kernel("Kernel mode ZERO DIV", regs
, vector
);
128 info
.si_code
= TRAP_TRACE
;
132 die_if_kernel("Kernel mode ILLEGAL", regs
, vector
);
133 #ifndef CONFIG_CPU_NO_USER_BKPT
134 if (*(uint16_t *)instruction_pointer(regs
) != USR_BKPT
)
140 /* gdbserver breakpoint */
142 /* jtagserver breakpoint */
144 die_if_kernel("Kernel mode BKPT", regs
, vector
);
145 info
.si_code
= TRAP_BRKPT
;
150 #ifdef CONFIG_CPU_NEED_SOFTALIGN
152 return csky_alignment(regs
);
154 #ifdef CONFIG_CPU_HAS_FPU
156 die_if_kernel("Kernel mode FPE", regs
, vector
);
157 return fpu_fpe(regs
);
159 die_if_kernel("Kernel mode PRIV", regs
, vector
);
160 if (fpu_libc_helper(regs
))
167 send_sig(sig
, current
, 0);