21 #include <linux/ptrace.h>
25 #include <asm/cacheflush.h>
31 #define KPROBE_HIT_ACTIVE 0x00000001
32 #define KPROBE_HIT_SS 0x00000002
34 static struct kprobe *cur_kprobe;
35 static unsigned long cur_kprobe_orig_pc;
36 static unsigned long cur_kprobe_next_pc;
37 static int cur_kprobe_ss_flags;
38 static unsigned long kprobe_status;
40 static unsigned long cur_kprobe_bp_addr;
46 #define SINGLESTEP_BRANCH 1
47 #define SINGLESTEP_PCREL 2
49 #define READ_BYTE(p, valp) \
50 do { *(u8 *)(valp) = *(u8 *)(p); } while (0)
52 #define READ_WORD16(p, valp) \
54 READ_BYTE((p), (valp)); \
55 READ_BYTE((u8 *)(p) + 1, (u8 *)(valp) + 1); \
58 #define READ_WORD32(p, valp) \
60 READ_BYTE((p), (valp)); \
61 READ_BYTE((u8 *)(p) + 1, (u8 *)(valp) + 1); \
62 READ_BYTE((u8 *)(p) + 2, (u8 *)(valp) + 2); \
63 READ_BYTE((u8 *)(p) + 3, (u8 *)(valp) + 3); \
67 static const u8 mn10300_insn_sizes[256] =
70 1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3, 1, 3, 3, 3,
71 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
72 2, 2, 2, 2, 3, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3,
73 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1,
74 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2,
75 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2,
76 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
77 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
78 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2,
79 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2,
80 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2,
81 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2,
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2,
83 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
84 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
85 0, 2, 2, 2, 2, 2, 2, 4, 0, 3, 0, 4, 0, 6, 7, 1
104 static const u16 cond_table[] = {
138 pc = (
u8 *) regs->
pc;
139 sp = (
u8 *) (regs + 1);
142 size = mn10300_insn_sizes[
opc];
150 if (cond_table[regs->
epsw & 0xf] & (1 << (opc & 0xf)))
174 next = (
u8 *)regs->
mdr;
191 if (opc >= 0xf0 && opc <= 0xf7) {
195 next = (
u8 *)regs->
a0;
198 next = (
u8 *)regs->
a1;
201 next = (
u8 *)regs->
a2;
204 next = (
u8 *)regs->
a3;
209 }
else if (opc == 0xfc) {
215 }
else if (opc == 0xfd) {
228 if (opc >= 0xe8 && opc <= 0xeb &&
229 (cond_table[regs->
epsw & 0xf] &
230 (1 << ((opc & 0xf) + 3)))
261 panic(
"Can't singlestep Lxx/SETLB\n");
265 return (
unsigned)
next;
277 pc = (
u8 *) regs->
pc;
278 sp = (
u8 *) (regs + 1);
305 regs->
mdr = (unsigned) next;
311 *(
unsigned *)sp = (
unsigned)
next;
317 if (opc >= 0xf0 && opc <= 0xf3) {
325 }
else if (opc >= 0xf4 && opc <= 0xf7) {
328 }
else if (opc == 0xfc) {
331 *(
unsigned *) sp = (
unsigned)
next;
332 }
else if (opc == 0xfd) {
335 *(
unsigned *)(sp + 4) = (unsigned) next;
355 panic(
"Can't singlestep Lxx/SETLB\n");
358 return (
unsigned)
next;
380 #ifndef CONFIG_MN10300_CACHE_SNOOP
395 #ifndef CONFIG_MN10300_CACHE_SNOOP
404 unsigned long nextpc;
406 cur_kprobe_orig_pc = regs->
pc;
408 regs->
pc = (
unsigned long) cur_kprobe_ss_buf;
410 nextpc = find_nextpc(regs, &cur_kprobe_ss_flags);
412 cur_kprobe_next_pc = cur_kprobe_orig_pc + (nextpc - regs->
pc);
414 cur_kprobe_next_pc = nextpc;
418 nextpc = singlestep_branch_setup(regs);
420 cur_kprobe_bp_addr = nextpc;
424 sizeof(cur_kprobe_ss_buf));
432 unsigned int *
addr = (
unsigned int *) regs->
pc;
438 if (kprobe_running()) {
443 disarm_kprobe(p, regs);
477 prepare_singlestep(p, regs);
497 if (cur_kprobe_ss_flags & SINGLESTEP_BRANCH) {
498 regs->
pc = cur_kprobe_orig_pc;
499 switch (p->
ainsn.insn[0]) {
501 *(
unsigned *) regs->
sp = regs->
mdr = regs->
pc + 5;
505 *(
unsigned *) regs->
sp = regs->
mdr = regs->
pc + 7;
508 if (p->
ainsn.insn[1] >= 0xf0 &&
509 p->
ainsn.insn[1] <= 0xf3) {
512 regs->
mdr = regs->
pc + 2;
513 *(
unsigned *) regs->
sp = regs->
mdr;
519 *(
unsigned *) regs->
sp = regs->
mdr = regs->
pc + 4;
524 *(
unsigned *) regs->
sp = regs->
mdr = regs->
pc + 6;
529 regs->
pc = cur_kprobe_next_pc;
530 cur_kprobe_bp_addr = 0;
535 if (!kprobe_running())
541 resume_execution(cur_kprobe, regs);
542 reset_current_kprobe();
556 resume_execution(cur_kprobe, regs);
557 reset_current_kprobe();
573 if (cur_kprobe_bp_addr != args->
regs->pc) {
577 if (post_kprobe_handler(args->
regs))
582 if (kprobe_running() &&
593 static struct pt_regs jprobe_saved_regs;
594 static struct pt_regs *jprobe_saved_regs_location;
601 jprobe_saved_regs_location =
regs;
608 memcpy(&jprobe_saved_stack, regs + 1,
sizeof(jprobe_saved_stack));
617 void *orig_sp = jprobe_saved_regs_location + 1;
620 asm volatile(
" mov %0,sp\n"
621 ".globl jprobe_return_bp_addr\n"
622 "jprobe_return_bp_addr:\n\t"
631 u8 *addr = (
u8 *) regs->
pc;
634 if (jprobe_saved_regs_location != regs) {
636 " Current regs (%p) does not match saved regs"
638 regs, jprobe_saved_regs_location);
646 memcpy(regs + 1, &jprobe_saved_stack,
647 sizeof(jprobe_saved_stack));