blob: d5505d6f2382bd00d298639595730000b9347021 [file] [log] [blame]
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -07001#ifndef _ASM_KPROBES_H
2#define _ASM_KPROBES_H
3/*
4 * Kernel Probes (KProbes)
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -07005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 *
20 * Copyright (C) IBM Corporation, 2002, 2004
21 * Copyright (C) Intel Corporation, 2005
22 *
23 * 2005-Apr Rusty Lynch <rusty.lynch@intel.com> and Anil S Keshavamurthy
24 * <anil.s.keshavamurthy@intel.com> adapted from i386
25 */
26#include <linux/types.h>
27#include <linux/ptrace.h>
Ananth N Mavinakayanahalli8a5c4dc2005-11-07 01:00:09 -080028#include <linux/percpu.h>
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -070029#include <asm/break.h>
30
bibo mao214ddde2006-09-26 11:20:37 -070031#define __ARCH_WANT_KPROBES_INSN_SLOT
Masami Hiramatsu34e1ceb2008-03-28 14:27:02 -070032#define MAX_INSN_SIZE 2 /* last half is for kprobe-booster */
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -070033#define BREAK_INST (long)(__IA64_BREAK_KPROBE << 6)
Masami Hiramatsu34e1ceb2008-03-28 14:27:02 -070034#define NOP_M_INST (long)(1<<27)
35#define BRL_INST(i1, i2) ((long)((0xcL << 37) | /* brl */ \
36 (0x1L << 12) | /* many */ \
37 (((i1) & 1) << 36) | ((i2) << 13))) /* imm */
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -070038
Anil S Keshavamurthy1674eaf2005-06-23 00:09:33 -070039typedef union cmp_inst {
40 struct {
41 unsigned long long qp : 6;
42 unsigned long long p1 : 6;
43 unsigned long long c : 1;
44 unsigned long long r2 : 7;
45 unsigned long long r3 : 7;
46 unsigned long long p2 : 6;
47 unsigned long long ta : 1;
48 unsigned long long x2 : 2;
49 unsigned long long tb : 1;
50 unsigned long long opcode : 4;
51 unsigned long long reserved : 23;
52 }f;
53 unsigned long long l;
54} cmp_inst_t;
55
Rusty Lynch8bc76772005-06-23 00:09:30 -070056struct kprobe;
57
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -070058typedef struct _bundle {
59 struct {
60 unsigned long long template : 5;
61 unsigned long long slot0 : 41;
62 unsigned long long slot1_p0 : 64-46;
63 } quad0;
64 struct {
65 unsigned long long slot1_p1 : 41 - (64-46);
66 unsigned long long slot2 : 41;
67 } quad1;
68} __attribute__((__aligned__(16))) bundle_t;
69
Ananth N Mavinakayanahalli8a5c4dc2005-11-07 01:00:09 -080070struct prev_kprobe {
71 struct kprobe *kp;
72 unsigned long status;
73};
74
Zhang Yanmind3ef1f52006-01-13 14:45:21 -080075#define MAX_PARAM_RSE_SIZE (0x60+0x60/0x3f)
Ananth N Mavinakayanahalli8a5c4dc2005-11-07 01:00:09 -080076/* per-cpu kprobe control block */
Anil S Keshavamurthycdc7dbd2007-05-11 09:38:40 -070077#define ARCH_PREV_KPROBE_SZ 2
Ananth N Mavinakayanahalli8a5c4dc2005-11-07 01:00:09 -080078struct kprobe_ctlblk {
79 unsigned long kprobe_status;
80 struct pt_regs jprobe_saved_regs;
Zhang Yanmind3ef1f52006-01-13 14:45:21 -080081 unsigned long jprobes_saved_stacked_regs[MAX_PARAM_RSE_SIZE];
82 unsigned long *bsp;
83 unsigned long cfm;
Anil S Keshavamurthycdc7dbd2007-05-11 09:38:40 -070084 atomic_t prev_kprobe_index;
85 struct prev_kprobe prev_kprobe[ARCH_PREV_KPROBE_SZ];
Ananth N Mavinakayanahalli8a5c4dc2005-11-07 01:00:09 -080086};
87
Masami Hiramatsuf438d912007-10-16 01:27:49 -070088#define kretprobe_blacklist_size 0
Rusty Lynch9508dbf2005-06-27 15:17:12 -070089
Anil S Keshavamurthycd2675b2005-06-23 00:09:29 -070090#define SLOT0_OPCODE_SHIFT (37)
91#define SLOT1_p1_OPCODE_SHIFT (37 - (64-46))
92#define SLOT2_OPCODE_SHIFT (37)
93
94#define INDIRECT_CALL_OPCODE (1)
95#define IP_RELATIVE_CALL_OPCODE (5)
96#define IP_RELATIVE_BRANCH_OPCODE (4)
97#define IP_RELATIVE_PREDICT_OPCODE (7)
98#define LONG_BRANCH_OPCODE (0xC)
99#define LONG_CALL_OPCODE (0xD)
bibo mao214ddde2006-09-26 11:20:37 -0700100#define flush_insn_slot(p) do { } while (0)
Anil S Keshavamurthycd2675b2005-06-23 00:09:29 -0700101
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -0700102typedef struct kprobe_opcode {
103 bundle_t bundle;
104} kprobe_opcode_t;
105
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -0700106/* Architecture specific copy of original instruction*/
107struct arch_specific_insn {
Anil S Keshavamurthycd2675b2005-06-23 00:09:29 -0700108 /* copy of the instruction to be emulated */
bibo mao214ddde2006-09-26 11:20:37 -0700109 kprobe_opcode_t *insn;
Anil S Keshavamurthycd2675b2005-06-23 00:09:29 -0700110 #define INST_FLAG_FIX_RELATIVE_IP_ADDR 1
111 #define INST_FLAG_FIX_BRANCH_REG 2
Keshavamurthy Anil Sdeac66a2005-09-06 15:19:35 -0700112 #define INST_FLAG_BREAK_INST 4
Masami Hiramatsu34e1ceb2008-03-28 14:27:02 -0700113 #define INST_FLAG_BOOSTABLE 8
Anil S Keshavamurthycd2675b2005-06-23 00:09:29 -0700114 unsigned long inst_flag;
115 unsigned short target_br_reg;
Tony Luck08ed38b2006-11-14 09:33:38 -0800116 unsigned short slot;
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -0700117};
118
Harvey Harrison45e18c22008-03-06 09:49:01 -0800119extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -0700120extern int kprobe_exceptions_notify(struct notifier_block *self,
121 unsigned long val, void *data);
Rusty Lynch9508dbf2005-06-27 15:17:12 -0700122
Zhang Yanmind3ef1f52006-01-13 14:45:21 -0800123extern void invalidate_stacked_regs(void);
124extern void flush_register_stack(void);
bibo mao214ddde2006-09-26 11:20:37 -0700125extern void arch_remove_kprobe(struct kprobe *p);
Rusty Lynch9508dbf2005-06-27 15:17:12 -0700126
Anil S Keshavamurthyfd7b2312005-06-23 00:09:28 -0700127#endif /* _ASM_KPROBES_H */