xref: /linux/arch/mips/include/asm/kprobes.h (revision c1bf207d6ee1eb72e9c10365edbdc7c9ff7fb9b0)
1*c1bf207dSDavid Daney /*
2*c1bf207dSDavid Daney  *  Kernel Probes (KProbes)
3*c1bf207dSDavid Daney  *  include/asm-mips/kprobes.h
4*c1bf207dSDavid Daney  *
5*c1bf207dSDavid Daney  *  Copyright 2006 Sony Corp.
6*c1bf207dSDavid Daney  *  Copyright 2010 Cavium Networks
7*c1bf207dSDavid Daney  *
8*c1bf207dSDavid Daney  *  This program is free software; you can redistribute it and/or modify
9*c1bf207dSDavid Daney  *  it under the terms of the GNU General Public License as published by
10*c1bf207dSDavid Daney  *  the Free Software Foundation; version 2 of the License.
11*c1bf207dSDavid Daney  *
12*c1bf207dSDavid Daney  *  This program is distributed in the hope that it will be useful,
13*c1bf207dSDavid Daney  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14*c1bf207dSDavid Daney  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*c1bf207dSDavid Daney  *  GNU General Public License for more details.
16*c1bf207dSDavid Daney  *
17*c1bf207dSDavid Daney  *  You should have received a copy of the GNU General Public License
18*c1bf207dSDavid Daney  *  along with this program; if not, write to the Free Software
19*c1bf207dSDavid Daney  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20*c1bf207dSDavid Daney  */
21*c1bf207dSDavid Daney 
22*c1bf207dSDavid Daney #ifndef _ASM_KPROBES_H
23*c1bf207dSDavid Daney #define _ASM_KPROBES_H
24*c1bf207dSDavid Daney 
25*c1bf207dSDavid Daney #include <linux/ptrace.h>
26*c1bf207dSDavid Daney #include <linux/types.h>
27*c1bf207dSDavid Daney 
28*c1bf207dSDavid Daney #include <asm/cacheflush.h>
29*c1bf207dSDavid Daney #include <asm/kdebug.h>
30*c1bf207dSDavid Daney #include <asm/inst.h>
31*c1bf207dSDavid Daney 
32*c1bf207dSDavid Daney #define  __ARCH_WANT_KPROBES_INSN_SLOT
33*c1bf207dSDavid Daney 
34*c1bf207dSDavid Daney struct kprobe;
35*c1bf207dSDavid Daney struct pt_regs;
36*c1bf207dSDavid Daney 
37*c1bf207dSDavid Daney typedef union mips_instruction kprobe_opcode_t;
38*c1bf207dSDavid Daney 
39*c1bf207dSDavid Daney #define MAX_INSN_SIZE 2
40*c1bf207dSDavid Daney 
41*c1bf207dSDavid Daney #define flush_insn_slot(p)						\
42*c1bf207dSDavid Daney do {									\
43*c1bf207dSDavid Daney 	flush_icache_range((unsigned long)p->addr,			\
44*c1bf207dSDavid Daney 			   (unsigned long)p->addr +			\
45*c1bf207dSDavid Daney 			   (MAX_INSN_SIZE * sizeof(kprobe_opcode_t)));	\
46*c1bf207dSDavid Daney } while (0)
47*c1bf207dSDavid Daney 
48*c1bf207dSDavid Daney 
49*c1bf207dSDavid Daney #define kretprobe_blacklist_size 0
50*c1bf207dSDavid Daney 
51*c1bf207dSDavid Daney void arch_remove_kprobe(struct kprobe *p);
52*c1bf207dSDavid Daney 
53*c1bf207dSDavid Daney /* Architecture specific copy of original instruction*/
54*c1bf207dSDavid Daney struct arch_specific_insn {
55*c1bf207dSDavid Daney 	/* copy of the original instruction */
56*c1bf207dSDavid Daney 	kprobe_opcode_t *insn;
57*c1bf207dSDavid Daney };
58*c1bf207dSDavid Daney 
59*c1bf207dSDavid Daney struct prev_kprobe {
60*c1bf207dSDavid Daney 	struct kprobe *kp;
61*c1bf207dSDavid Daney 	unsigned long status;
62*c1bf207dSDavid Daney 	unsigned long old_SR;
63*c1bf207dSDavid Daney 	unsigned long saved_SR;
64*c1bf207dSDavid Daney 	unsigned long saved_epc;
65*c1bf207dSDavid Daney };
66*c1bf207dSDavid Daney 
67*c1bf207dSDavid Daney #define MAX_JPROBES_STACK_SIZE 128
68*c1bf207dSDavid Daney #define MAX_JPROBES_STACK_ADDR \
69*c1bf207dSDavid Daney 	(((unsigned long)current_thread_info()) + THREAD_SIZE - 32 - sizeof(struct pt_regs))
70*c1bf207dSDavid Daney 
71*c1bf207dSDavid Daney #define MIN_JPROBES_STACK_SIZE(ADDR)					\
72*c1bf207dSDavid Daney 	((((ADDR) + MAX_JPROBES_STACK_SIZE) > MAX_JPROBES_STACK_ADDR)	\
73*c1bf207dSDavid Daney 		? MAX_JPROBES_STACK_ADDR - (ADDR)			\
74*c1bf207dSDavid Daney 		: MAX_JPROBES_STACK_SIZE)
75*c1bf207dSDavid Daney 
76*c1bf207dSDavid Daney 
77*c1bf207dSDavid Daney /* per-cpu kprobe control block */
78*c1bf207dSDavid Daney struct kprobe_ctlblk {
79*c1bf207dSDavid Daney 	unsigned long kprobe_status;
80*c1bf207dSDavid Daney 	unsigned long kprobe_old_SR;
81*c1bf207dSDavid Daney 	unsigned long kprobe_saved_SR;
82*c1bf207dSDavid Daney 	unsigned long kprobe_saved_epc;
83*c1bf207dSDavid Daney 	unsigned long jprobe_saved_sp;
84*c1bf207dSDavid Daney 	struct pt_regs jprobe_saved_regs;
85*c1bf207dSDavid Daney 	u8 jprobes_stack[MAX_JPROBES_STACK_SIZE];
86*c1bf207dSDavid Daney 	struct prev_kprobe prev_kprobe;
87*c1bf207dSDavid Daney };
88*c1bf207dSDavid Daney 
89*c1bf207dSDavid Daney extern int kprobe_exceptions_notify(struct notifier_block *self,
90*c1bf207dSDavid Daney 				    unsigned long val, void *data);
91*c1bf207dSDavid Daney 
92*c1bf207dSDavid Daney #endif				/* _ASM_KPROBES_H */
93