Redesign KProbe module (separating core and arch parts).
[kernel/swap-modules.git] / kprobe / arch / asm-mips / dbi_kprobes.h
1 #ifndef _SRC_ASM_MIPS_KPROBES_H
2 #define _SRC_ASM_MIPS_KPROBES_H
3
4 /*
5  *  Dynamic Binary Instrumentation Module based on KProbes
6  *  modules/kprobe/arch/asm-mips/dbi_kprobes.h
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  * Copyright (C) Samsung Electronics, 2006-2010
23  *
24  * 2006-2007    Ekaterina Gorelkina <e.gorelkina@samsung.com>: initial implementation for ARM/MIPS
25  * 2008-2009    Alexey Gerenkov <a.gerenkov@samsung.com> User-Space
26  *              Probes initial implementation; Support x86/ARM/MIPS for both user-space and kernel space.
27  * 2010         Ekaterina Gorelkina <e.gorelkina@samsung.com>: redesign module for separating core and arch parts 
28  *
29  */
30
31 #include "arch/dbi_kprobes.h"
32 #include "dbi_kprobe_deps.h"
33
34 typedef unsigned long kprobe_opcode_t;
35
36 #define BREAKPOINT_INSTRUCTION         0x0000000d
37
38 #ifndef KPROBES_RET_PROBE_TRAMP
39 #define UNDEF_INSTRUCTION              0x0000004d
40 #endif 
41
42 #define MAX_INSN_SIZE                  1
43
44 # define UPROBES_TRAMP_LEN             3
45 # define UPROBES_TRAMP_INSN_IDX        0
46 # define UPROBES_TRAMP_SS_BREAK_IDX    1
47 # define UPROBES_TRAMP_RET_BREAK_IDX   2
48 # define KPROBES_TRAMP_LEN             UPROBES_TRAMP_LEN
49 # define KPROBES_TRAMP_INSN_IDX        UPROBES_TRAMP_INSN_IDX
50 # define KPROBES_TRAMP_SS_BREAK_IDX    UPROBES_TRAMP_SS_BREAK_IDX
51 # define KPROBES_TRAMP_RET_BREAK_IDX   UPROBES_TRAMP_RET_BREAK_IDX
52
53 #define REG_HI_INDEX                   0
54 #define REG_LO_INDEX                   1
55 #define NOTIFIER_CALL_CHAIN_INDEX      0
56
57
58 #define MIPS_INSN_OPCODE_MASK   0xFC000000
59 #define MIPS_INSN_RS_MASK       0x03E00000
60 #define MIPS_INSN_RT_MASK       0x001F0000
61 //#define MIPS_INSN_UN_MASK     0x0000FFC0
62 #define MIPS_INSN_FUNC_MASK     0x0000003F
63 #define MIPS_INSN_OPCODE(insn)  (insn & MIPS_INSN_OPCODE_MASK)
64 #define MIPS_INSN_RS(insn)      (insn & MIPS_INSN_RS_MASK)
65 #define MIPS_INSN_RT(insn)      (insn & MIPS_INSN_RT_MASK)
66 #define MIPS_INSN_FUNC(insn)    (insn & MIPS_INSN_FUNC_MASK)
67 // opcodes 31..26
68 #define MIPS_BEQ_OPCODE         0x10000000
69 #define MIPS_BNE_OPCODE         0x14000000
70 #define MIPS_BLEZ_OPCODE        0x18000000
71 #define MIPS_BGTZ_OPCODE        0x1C000000
72 #define MIPS_BEQL_OPCODE        0x50000000
73 #define MIPS_BNEL_OPCODE        0x54000000
74 #define MIPS_BLEZL_OPCODE       0x58000000
75 #define MIPS_BGTZL_OPCODE       0x5C000000
76 #define MIPS_REGIMM_OPCODE      0x04000000
77 #define MIPS_SPECIAL_OPCODE     0x00000000
78 #define MIPS_COP1_OPCODE        0x44000000
79 #define MIPS_COP2_OPCODE        0x48000000
80 #define MIPS_J_OPCODE           0x08000000
81 #define MIPS_JAL_OPCODE         0x0C000000
82 #define MIPS_JALX_OPCODE        0x74000000
83 // rs 25..21
84 #define MIPS_BC_RS              0x01000000
85 // rt 20..16
86 #define MIPS_BLTZ_RT            0x00000000
87 #define MIPS_BGEZ_RT            0x00010000
88 #define MIPS_BLTZL_RT           0x00020000
89 #define MIPS_BGEZL_RT           0x00030000
90 #define MIPS_BLTZAL_RT          0x00100000
91 #define MIPS_BGEZAL_RT          0x00110000
92 #define MIPS_BLTZALL_RT         0x00120000
93 #define MIPS_BGEZALL_RT         0x00130000
94 // unnamed 15..6
95 // function 5..0
96 #define MIPS_JR_FUNC            0x00000008
97 #define MIPS_JALR_FUNC          0x00000009
98 #define MIPS_BREAK_FUNC         0x0000000D
99 #define MIPS_SYSCALL_FUNC       0x0000000C
100
101 DECLARE_MOD_CB_DEP(flush_icache_range, \
102                 void, unsigned long __user start, unsigned long __user end);
103 DECLARE_MOD_CB_DEP(flush_icache_page, \
104                 void, struct vm_area_struct * vma, struct page * page);
105 DECLARE_MOD_CB_DEP(flush_cache_page, \
106                 void, struct vm_area_struct * vma, unsigned long page);
107
108 unsigned int arr_traps_template[] = {  0x3c010000,   // lui  a1       [0]
109         0x24210000,   // addiu a1, a1  [1]
110         0x00200008,   // jr a1         [2]
111         0x00000000,   // nop
112         0xffffffff    // end
113 }
114
115 /* per-cpu kprobe control block */
116 struct kprobe_ctlblk {
117         unsigned long kprobe_status;
118         struct prev_kprobe prev_kprobe;
119 };
120
121 /* Architecture specific copy of original instruction */
122 struct arch_specific_insn {
123         /* copy of the original instruction */
124         kprobe_opcode_t *insn;
125         /*
126          * If this flag is not 0, this kprobe can be boost when its
127          * post_handler and break_handler is not set.
128          */
129         int boostable;
130 };
131
132 typedef kprobe_opcode_t (*entry_point_t) (unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long);
133
134
135 void gen_insn_execbuf_holder (void);
136
137 void patch_suspended_task_ret_addr(struct task_struct *p, struct kretprobe *rp);
138
139 static struct kprobe trampoline_p =
140 {
141         .addr = (kprobe_opcode_t *) & kretprobe_trampoline,
142         .pre_handler = trampoline_probe_handler
143 };
144
145 #endif /*  _SRC_ASM_MIPS_KPROBES_H */