1 // SPDX-License-Identifier: GPL-2.0
3 * Common helper functions for kprobes and uprobes
5 * Copyright IBM Corp. 2014
8 #include <linux/errno.h>
9 #include <asm/kprobes.h>
12 int probe_is_prohibited_opcode(u16 *insn)
14 if (!is_known_insn((unsigned char *)insn))
16 switch (insn[0] >> 8) {
17 case 0x0c: /* bassm */
21 case 0xac: /* stnsm */
22 case 0xad: /* stosm */
25 switch (insn[0] & 0x0f) {
32 case 0xb25a: /* bsa */
33 case 0xb240: /* bakr */
34 case 0xb258: /* bsg */
37 case 0xb98d: /* epsw */
38 case 0xe560: /* tbegin */
39 case 0xe561: /* tbeginc */
40 case 0xb2f8: /* tend */
46 int probe_get_fixup_type(u16 *insn)
48 /* default fixup method */
49 int fixup = FIXUP_PSW_NORMAL;
51 switch (insn[0] >> 8) {
54 fixup = FIXUP_RETURN_REGISTER;
55 /* if r2 = 0, no branch will be taken */
56 if ((insn[0] & 0x0f) == 0)
57 fixup |= FIXUP_BRANCH_NOT_TAKEN;
61 fixup = FIXUP_BRANCH_NOT_TAKEN;
65 fixup = FIXUP_RETURN_REGISTER;
71 fixup = FIXUP_BRANCH_NOT_TAKEN;
74 fixup = FIXUP_NOT_REQUIRED;
76 case 0xb2: /* lpswe */
77 if ((insn[0] & 0xff) == 0xb2)
78 fixup = FIXUP_NOT_REQUIRED;
81 if ((insn[0] & 0x0f) == 0x05)
82 fixup |= FIXUP_RETURN_REGISTER;
85 if ((insn[0] & 0x0f) == 0x05) /* brasl */
86 fixup |= FIXUP_RETURN_REGISTER;
89 switch (insn[2] & 0xff) {
91 case 0x45: /* bxleg */
92 fixup = FIXUP_BRANCH_NOT_TAKEN;
97 if ((insn[2] & 0xff) == 0x46)
98 fixup = FIXUP_BRANCH_NOT_TAKEN;
101 switch (insn[2] & 0xff) {
102 case 0xe5: /* clgrb */
103 case 0xe6: /* cgrb */
105 case 0xf7: /* clrb */
106 case 0xfc: /* cgib */
107 case 0xfd: /* cglib */
109 case 0xff: /* clib */
110 fixup = FIXUP_BRANCH_NOT_TAKEN;
118 int probe_is_insn_relative_long(u16 *insn)
120 /* Check if we have a RIL-b or RIL-c format instruction which
121 * we need to modify in order to avoid instruction emulation. */
122 switch (insn[0] >> 8) {
124 if ((insn[0] & 0x0f) == 0x00) /* larl */
128 switch (insn[0] & 0x0f) {
129 case 0x02: /* llhrl */
130 case 0x04: /* lghrl */
131 case 0x05: /* lhrl */
132 case 0x06: /* llghrl */
133 case 0x07: /* sthrl */
134 case 0x08: /* lgrl */
135 case 0x0b: /* stgrl */
136 case 0x0c: /* lgfrl */
138 case 0x0e: /* llgfrl */
139 case 0x0f: /* strl */
144 switch (insn[0] & 0x0f) {
145 case 0x02: /* pfdrl */
146 case 0x04: /* cghrl */
147 case 0x05: /* chrl */
148 case 0x06: /* clghrl */
149 case 0x07: /* clhrl */
150 case 0x08: /* cgrl */
151 case 0x0a: /* clgrl */
152 case 0x0c: /* cgfrl */
154 case 0x0e: /* clgfrl */
155 case 0x0f: /* clrl */