Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/kernel/kprobes-decode.c |
| 3 | * |
| 4 | * Copyright (C) 2006, 2007 Motorola Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | /* |
| 17 | * We do not have hardware single-stepping on ARM, This |
| 18 | * effort is further complicated by the ARM not having a |
| 19 | * "next PC" register. Instructions that change the PC |
| 20 | * can't be safely single-stepped in a MP environment, so |
| 21 | * we have a lot of work to do: |
| 22 | * |
| 23 | * In the prepare phase: |
| 24 | * *) If it is an instruction that does anything |
| 25 | * with the CPU mode, we reject it for a kprobe. |
| 26 | * (This is out of laziness rather than need. The |
| 27 | * instructions could be simulated.) |
| 28 | * |
| 29 | * *) Otherwise, decode the instruction rewriting its |
| 30 | * registers to take fixed, ordered registers and |
| 31 | * setting a handler for it to run the instruction. |
| 32 | * |
| 33 | * In the execution phase by an instruction's handler: |
| 34 | * |
| 35 | * *) If the PC is written to by the instruction, the |
| 36 | * instruction must be fully simulated in software. |
| 37 | * If it is a conditional instruction, the handler |
| 38 | * will use insn[0] to copy its condition code to |
| 39 | * set r0 to 1 and insn[1] to "mov pc, lr" to return. |
| 40 | * |
| 41 | * *) Otherwise, a modified form of the instruction is |
| 42 | * directly executed. Its handler calls the |
| 43 | * instruction in insn[0]. In insn[1] is a |
| 44 | * "mov pc, lr" to return. |
| 45 | * |
| 46 | * Before calling, load up the reordered registers |
| 47 | * from the original instruction's registers. If one |
| 48 | * of the original input registers is the PC, compute |
| 49 | * and adjust the appropriate input register. |
| 50 | * |
| 51 | * After call completes, copy the output registers to |
| 52 | * the original instruction's original registers. |
| 53 | * |
| 54 | * We don't use a real breakpoint instruction since that |
| 55 | * would have us in the kernel go from SVC mode to SVC |
| 56 | * mode losing the link register. Instead we use an |
| 57 | * undefined instruction. To simplify processing, the |
| 58 | * undefined instruction used for kprobes must be reserved |
| 59 | * exclusively for kprobes use. |
| 60 | * |
| 61 | * TODO: ifdef out some instruction decoding based on architecture. |
| 62 | */ |
| 63 | |
| 64 | #include <linux/kernel.h> |
| 65 | #include <linux/kprobes.h> |
| 66 | |
| 67 | #define sign_extend(x, signbit) ((x) | (0 - ((x) & (1 << (signbit))))) |
| 68 | |
| 69 | #define branch_displacement(insn) sign_extend(((insn) & 0xffffff) << 2, 25) |
| 70 | |
| 71 | #define PSR_fs (PSR_f|PSR_s) |
| 72 | |
| 73 | #define KPROBE_RETURN_INSTRUCTION 0xe1a0f00e /* mov pc, lr */ |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 74 | |
| 75 | typedef long (insn_0arg_fn_t)(void); |
| 76 | typedef long (insn_1arg_fn_t)(long); |
| 77 | typedef long (insn_2arg_fn_t)(long, long); |
| 78 | typedef long (insn_3arg_fn_t)(long, long, long); |
| 79 | typedef long (insn_4arg_fn_t)(long, long, long, long); |
| 80 | typedef long long (insn_llret_0arg_fn_t)(void); |
| 81 | typedef long long (insn_llret_3arg_fn_t)(long, long, long); |
| 82 | typedef long long (insn_llret_4arg_fn_t)(long, long, long, long); |
| 83 | |
| 84 | union reg_pair { |
| 85 | long long dr; |
| 86 | #ifdef __LITTLE_ENDIAN |
| 87 | struct { long r0, r1; }; |
| 88 | #else |
| 89 | struct { long r1, r0; }; |
| 90 | #endif |
| 91 | }; |
| 92 | |
| 93 | /* |
| 94 | * For STR and STM instructions, an ARM core may choose to use either |
| 95 | * a +8 or a +12 displacement from the current instruction's address. |
| 96 | * Whichever value is chosen for a given core, it must be the same for |
| 97 | * both instructions and may not change. This function measures it. |
| 98 | */ |
| 99 | |
| 100 | static int str_pc_offset; |
| 101 | |
| 102 | static void __init find_str_pc_offset(void) |
| 103 | { |
| 104 | int addr, scratch, ret; |
| 105 | |
| 106 | __asm__ ( |
| 107 | "sub %[ret], pc, #4 \n\t" |
| 108 | "str pc, %[addr] \n\t" |
| 109 | "ldr %[scr], %[addr] \n\t" |
| 110 | "sub %[ret], %[scr], %[ret] \n\t" |
| 111 | : [ret] "=r" (ret), [scr] "=r" (scratch), [addr] "+m" (addr)); |
| 112 | |
| 113 | str_pc_offset = ret; |
| 114 | } |
| 115 | |
| 116 | /* |
| 117 | * The insnslot_?arg_r[w]flags() functions below are to keep the |
| 118 | * msr -> *fn -> mrs instruction sequences indivisible so that |
| 119 | * the state of the CPSR flags aren't inadvertently modified |
| 120 | * just before or just after the call. |
| 121 | */ |
| 122 | |
| 123 | static inline long __kprobes |
| 124 | insnslot_0arg_rflags(long cpsr, insn_0arg_fn_t *fn) |
| 125 | { |
| 126 | register long ret asm("r0"); |
| 127 | |
| 128 | __asm__ __volatile__ ( |
| 129 | "msr cpsr_fs, %[cpsr] \n\t" |
| 130 | "mov lr, pc \n\t" |
| 131 | "mov pc, %[fn] \n\t" |
| 132 | : "=r" (ret) |
| 133 | : [cpsr] "r" (cpsr), [fn] "r" (fn) |
| 134 | : "lr", "cc" |
| 135 | ); |
| 136 | return ret; |
| 137 | } |
| 138 | |
| 139 | static inline long long __kprobes |
| 140 | insnslot_llret_0arg_rflags(long cpsr, insn_llret_0arg_fn_t *fn) |
| 141 | { |
| 142 | register long ret0 asm("r0"); |
| 143 | register long ret1 asm("r1"); |
| 144 | union reg_pair fnr; |
| 145 | |
| 146 | __asm__ __volatile__ ( |
| 147 | "msr cpsr_fs, %[cpsr] \n\t" |
| 148 | "mov lr, pc \n\t" |
| 149 | "mov pc, %[fn] \n\t" |
| 150 | : "=r" (ret0), "=r" (ret1) |
| 151 | : [cpsr] "r" (cpsr), [fn] "r" (fn) |
| 152 | : "lr", "cc" |
| 153 | ); |
| 154 | fnr.r0 = ret0; |
| 155 | fnr.r1 = ret1; |
| 156 | return fnr.dr; |
| 157 | } |
| 158 | |
| 159 | static inline long __kprobes |
| 160 | insnslot_1arg_rflags(long r0, long cpsr, insn_1arg_fn_t *fn) |
| 161 | { |
| 162 | register long rr0 asm("r0") = r0; |
| 163 | register long ret asm("r0"); |
| 164 | |
| 165 | __asm__ __volatile__ ( |
| 166 | "msr cpsr_fs, %[cpsr] \n\t" |
| 167 | "mov lr, pc \n\t" |
| 168 | "mov pc, %[fn] \n\t" |
| 169 | : "=r" (ret) |
| 170 | : "0" (rr0), [cpsr] "r" (cpsr), [fn] "r" (fn) |
| 171 | : "lr", "cc" |
| 172 | ); |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | static inline long __kprobes |
| 177 | insnslot_2arg_rflags(long r0, long r1, long cpsr, insn_2arg_fn_t *fn) |
| 178 | { |
| 179 | register long rr0 asm("r0") = r0; |
| 180 | register long rr1 asm("r1") = r1; |
| 181 | register long ret asm("r0"); |
| 182 | |
| 183 | __asm__ __volatile__ ( |
| 184 | "msr cpsr_fs, %[cpsr] \n\t" |
| 185 | "mov lr, pc \n\t" |
| 186 | "mov pc, %[fn] \n\t" |
| 187 | : "=r" (ret) |
| 188 | : "0" (rr0), "r" (rr1), |
| 189 | [cpsr] "r" (cpsr), [fn] "r" (fn) |
| 190 | : "lr", "cc" |
| 191 | ); |
| 192 | return ret; |
| 193 | } |
| 194 | |
| 195 | static inline long __kprobes |
| 196 | insnslot_3arg_rflags(long r0, long r1, long r2, long cpsr, insn_3arg_fn_t *fn) |
| 197 | { |
| 198 | register long rr0 asm("r0") = r0; |
| 199 | register long rr1 asm("r1") = r1; |
| 200 | register long rr2 asm("r2") = r2; |
| 201 | register long ret asm("r0"); |
| 202 | |
| 203 | __asm__ __volatile__ ( |
| 204 | "msr cpsr_fs, %[cpsr] \n\t" |
| 205 | "mov lr, pc \n\t" |
| 206 | "mov pc, %[fn] \n\t" |
| 207 | : "=r" (ret) |
| 208 | : "0" (rr0), "r" (rr1), "r" (rr2), |
| 209 | [cpsr] "r" (cpsr), [fn] "r" (fn) |
| 210 | : "lr", "cc" |
| 211 | ); |
| 212 | return ret; |
| 213 | } |
| 214 | |
| 215 | static inline long long __kprobes |
| 216 | insnslot_llret_3arg_rflags(long r0, long r1, long r2, long cpsr, |
| 217 | insn_llret_3arg_fn_t *fn) |
| 218 | { |
| 219 | register long rr0 asm("r0") = r0; |
| 220 | register long rr1 asm("r1") = r1; |
| 221 | register long rr2 asm("r2") = r2; |
| 222 | register long ret0 asm("r0"); |
| 223 | register long ret1 asm("r1"); |
| 224 | union reg_pair fnr; |
| 225 | |
| 226 | __asm__ __volatile__ ( |
| 227 | "msr cpsr_fs, %[cpsr] \n\t" |
| 228 | "mov lr, pc \n\t" |
| 229 | "mov pc, %[fn] \n\t" |
| 230 | : "=r" (ret0), "=r" (ret1) |
| 231 | : "0" (rr0), "r" (rr1), "r" (rr2), |
| 232 | [cpsr] "r" (cpsr), [fn] "r" (fn) |
| 233 | : "lr", "cc" |
| 234 | ); |
| 235 | fnr.r0 = ret0; |
| 236 | fnr.r1 = ret1; |
| 237 | return fnr.dr; |
| 238 | } |
| 239 | |
| 240 | static inline long __kprobes |
| 241 | insnslot_4arg_rflags(long r0, long r1, long r2, long r3, long cpsr, |
| 242 | insn_4arg_fn_t *fn) |
| 243 | { |
| 244 | register long rr0 asm("r0") = r0; |
| 245 | register long rr1 asm("r1") = r1; |
| 246 | register long rr2 asm("r2") = r2; |
| 247 | register long rr3 asm("r3") = r3; |
| 248 | register long ret asm("r0"); |
| 249 | |
| 250 | __asm__ __volatile__ ( |
| 251 | "msr cpsr_fs, %[cpsr] \n\t" |
| 252 | "mov lr, pc \n\t" |
| 253 | "mov pc, %[fn] \n\t" |
| 254 | : "=r" (ret) |
| 255 | : "0" (rr0), "r" (rr1), "r" (rr2), "r" (rr3), |
| 256 | [cpsr] "r" (cpsr), [fn] "r" (fn) |
| 257 | : "lr", "cc" |
| 258 | ); |
| 259 | return ret; |
| 260 | } |
| 261 | |
| 262 | static inline long __kprobes |
| 263 | insnslot_1arg_rwflags(long r0, long *cpsr, insn_1arg_fn_t *fn) |
| 264 | { |
| 265 | register long rr0 asm("r0") = r0; |
| 266 | register long ret asm("r0"); |
| 267 | long oldcpsr = *cpsr; |
| 268 | long newcpsr; |
| 269 | |
| 270 | __asm__ __volatile__ ( |
| 271 | "msr cpsr_fs, %[oldcpsr] \n\t" |
| 272 | "mov lr, pc \n\t" |
| 273 | "mov pc, %[fn] \n\t" |
| 274 | "mrs %[newcpsr], cpsr \n\t" |
| 275 | : "=r" (ret), [newcpsr] "=r" (newcpsr) |
| 276 | : "0" (rr0), [oldcpsr] "r" (oldcpsr), [fn] "r" (fn) |
| 277 | : "lr", "cc" |
| 278 | ); |
| 279 | *cpsr = (oldcpsr & ~PSR_fs) | (newcpsr & PSR_fs); |
| 280 | return ret; |
| 281 | } |
| 282 | |
| 283 | static inline long __kprobes |
| 284 | insnslot_2arg_rwflags(long r0, long r1, long *cpsr, insn_2arg_fn_t *fn) |
| 285 | { |
| 286 | register long rr0 asm("r0") = r0; |
| 287 | register long rr1 asm("r1") = r1; |
| 288 | register long ret asm("r0"); |
| 289 | long oldcpsr = *cpsr; |
| 290 | long newcpsr; |
| 291 | |
| 292 | __asm__ __volatile__ ( |
| 293 | "msr cpsr_fs, %[oldcpsr] \n\t" |
| 294 | "mov lr, pc \n\t" |
| 295 | "mov pc, %[fn] \n\t" |
| 296 | "mrs %[newcpsr], cpsr \n\t" |
| 297 | : "=r" (ret), [newcpsr] "=r" (newcpsr) |
| 298 | : "0" (rr0), "r" (rr1), [oldcpsr] "r" (oldcpsr), [fn] "r" (fn) |
| 299 | : "lr", "cc" |
| 300 | ); |
| 301 | *cpsr = (oldcpsr & ~PSR_fs) | (newcpsr & PSR_fs); |
| 302 | return ret; |
| 303 | } |
| 304 | |
| 305 | static inline long __kprobes |
| 306 | insnslot_3arg_rwflags(long r0, long r1, long r2, long *cpsr, |
| 307 | insn_3arg_fn_t *fn) |
| 308 | { |
| 309 | register long rr0 asm("r0") = r0; |
| 310 | register long rr1 asm("r1") = r1; |
| 311 | register long rr2 asm("r2") = r2; |
| 312 | register long ret asm("r0"); |
| 313 | long oldcpsr = *cpsr; |
| 314 | long newcpsr; |
| 315 | |
| 316 | __asm__ __volatile__ ( |
| 317 | "msr cpsr_fs, %[oldcpsr] \n\t" |
| 318 | "mov lr, pc \n\t" |
| 319 | "mov pc, %[fn] \n\t" |
| 320 | "mrs %[newcpsr], cpsr \n\t" |
| 321 | : "=r" (ret), [newcpsr] "=r" (newcpsr) |
| 322 | : "0" (rr0), "r" (rr1), "r" (rr2), |
| 323 | [oldcpsr] "r" (oldcpsr), [fn] "r" (fn) |
| 324 | : "lr", "cc" |
| 325 | ); |
| 326 | *cpsr = (oldcpsr & ~PSR_fs) | (newcpsr & PSR_fs); |
| 327 | return ret; |
| 328 | } |
| 329 | |
| 330 | static inline long __kprobes |
| 331 | insnslot_4arg_rwflags(long r0, long r1, long r2, long r3, long *cpsr, |
| 332 | insn_4arg_fn_t *fn) |
| 333 | { |
| 334 | register long rr0 asm("r0") = r0; |
| 335 | register long rr1 asm("r1") = r1; |
| 336 | register long rr2 asm("r2") = r2; |
| 337 | register long rr3 asm("r3") = r3; |
| 338 | register long ret asm("r0"); |
| 339 | long oldcpsr = *cpsr; |
| 340 | long newcpsr; |
| 341 | |
| 342 | __asm__ __volatile__ ( |
| 343 | "msr cpsr_fs, %[oldcpsr] \n\t" |
| 344 | "mov lr, pc \n\t" |
| 345 | "mov pc, %[fn] \n\t" |
| 346 | "mrs %[newcpsr], cpsr \n\t" |
| 347 | : "=r" (ret), [newcpsr] "=r" (newcpsr) |
| 348 | : "0" (rr0), "r" (rr1), "r" (rr2), "r" (rr3), |
| 349 | [oldcpsr] "r" (oldcpsr), [fn] "r" (fn) |
| 350 | : "lr", "cc" |
| 351 | ); |
| 352 | *cpsr = (oldcpsr & ~PSR_fs) | (newcpsr & PSR_fs); |
| 353 | return ret; |
| 354 | } |
| 355 | |
| 356 | static inline long long __kprobes |
| 357 | insnslot_llret_4arg_rwflags(long r0, long r1, long r2, long r3, long *cpsr, |
| 358 | insn_llret_4arg_fn_t *fn) |
| 359 | { |
| 360 | register long rr0 asm("r0") = r0; |
| 361 | register long rr1 asm("r1") = r1; |
| 362 | register long rr2 asm("r2") = r2; |
| 363 | register long rr3 asm("r3") = r3; |
| 364 | register long ret0 asm("r0"); |
| 365 | register long ret1 asm("r1"); |
| 366 | long oldcpsr = *cpsr; |
| 367 | long newcpsr; |
| 368 | union reg_pair fnr; |
| 369 | |
| 370 | __asm__ __volatile__ ( |
| 371 | "msr cpsr_fs, %[oldcpsr] \n\t" |
| 372 | "mov lr, pc \n\t" |
| 373 | "mov pc, %[fn] \n\t" |
| 374 | "mrs %[newcpsr], cpsr \n\t" |
| 375 | : "=r" (ret0), "=r" (ret1), [newcpsr] "=r" (newcpsr) |
| 376 | : "0" (rr0), "r" (rr1), "r" (rr2), "r" (rr3), |
| 377 | [oldcpsr] "r" (oldcpsr), [fn] "r" (fn) |
| 378 | : "lr", "cc" |
| 379 | ); |
| 380 | *cpsr = (oldcpsr & ~PSR_fs) | (newcpsr & PSR_fs); |
| 381 | fnr.r0 = ret0; |
| 382 | fnr.r1 = ret1; |
| 383 | return fnr.dr; |
| 384 | } |
| 385 | |
| 386 | /* |
| 387 | * To avoid the complications of mimicing single-stepping on a |
| 388 | * processor without a Next-PC or a single-step mode, and to |
| 389 | * avoid having to deal with the side-effects of boosting, we |
| 390 | * simulate or emulate (almost) all ARM instructions. |
| 391 | * |
| 392 | * "Simulation" is where the instruction's behavior is duplicated in |
| 393 | * C code. "Emulation" is where the original instruction is rewritten |
| 394 | * and executed, often by altering its registers. |
| 395 | * |
| 396 | * By having all behavior of the kprobe'd instruction completed before |
| 397 | * returning from the kprobe_handler(), all locks (scheduler and |
| 398 | * interrupt) can safely be released. There is no need for secondary |
| 399 | * breakpoints, no race with MP or preemptable kernels, nor having to |
| 400 | * clean up resources counts at a later time impacting overall system |
| 401 | * performance. By rewriting the instruction, only the minimum registers |
| 402 | * need to be loaded and saved back optimizing performance. |
| 403 | * |
| 404 | * Calling the insnslot_*_rwflags version of a function doesn't hurt |
| 405 | * anything even when the CPSR flags aren't updated by the |
| 406 | * instruction. It's just a little slower in return for saving |
| 407 | * a little space by not having a duplicate function that doesn't |
| 408 | * update the flags. (The same optimization can be said for |
| 409 | * instructions that do or don't perform register writeback) |
| 410 | * Also, instructions can either read the flags, only write the |
| 411 | * flags, or read and write the flags. To save combinations |
| 412 | * rather than for sheer performance, flag functions just assume |
| 413 | * read and write of flags. |
| 414 | */ |
| 415 | |
| 416 | static void __kprobes simulate_bbl(struct kprobe *p, struct pt_regs *regs) |
| 417 | { |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 418 | kprobe_opcode_t insn = p->opcode; |
| 419 | long iaddr = (long)p->addr; |
| 420 | int disp = branch_displacement(insn); |
| 421 | |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 422 | if (insn & (1 << 24)) |
| 423 | regs->ARM_lr = iaddr + 4; |
| 424 | |
| 425 | regs->ARM_pc = iaddr + 8 + disp; |
| 426 | } |
| 427 | |
| 428 | static void __kprobes simulate_blx1(struct kprobe *p, struct pt_regs *regs) |
| 429 | { |
| 430 | kprobe_opcode_t insn = p->opcode; |
| 431 | long iaddr = (long)p->addr; |
| 432 | int disp = branch_displacement(insn); |
| 433 | |
| 434 | regs->ARM_lr = iaddr + 4; |
| 435 | regs->ARM_pc = iaddr + 8 + disp + ((insn >> 23) & 0x2); |
| 436 | regs->ARM_cpsr |= PSR_T_BIT; |
| 437 | } |
| 438 | |
| 439 | static void __kprobes simulate_blx2bx(struct kprobe *p, struct pt_regs *regs) |
| 440 | { |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 441 | kprobe_opcode_t insn = p->opcode; |
| 442 | int rm = insn & 0xf; |
| 443 | long rmv = regs->uregs[rm]; |
| 444 | |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 445 | if (insn & (1 << 5)) |
| 446 | regs->ARM_lr = (long)p->addr + 4; |
| 447 | |
| 448 | regs->ARM_pc = rmv & ~0x1; |
| 449 | regs->ARM_cpsr &= ~PSR_T_BIT; |
| 450 | if (rmv & 0x1) |
| 451 | regs->ARM_cpsr |= PSR_T_BIT; |
| 452 | } |
| 453 | |
| 454 | static void __kprobes simulate_ldm1stm1(struct kprobe *p, struct pt_regs *regs) |
| 455 | { |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 456 | kprobe_opcode_t insn = p->opcode; |
| 457 | int rn = (insn >> 16) & 0xf; |
| 458 | int lbit = insn & (1 << 20); |
| 459 | int wbit = insn & (1 << 21); |
| 460 | int ubit = insn & (1 << 23); |
| 461 | int pbit = insn & (1 << 24); |
| 462 | long *addr = (long *)regs->uregs[rn]; |
| 463 | int reg_bit_vector; |
| 464 | int reg_count; |
| 465 | |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 466 | reg_count = 0; |
| 467 | reg_bit_vector = insn & 0xffff; |
| 468 | while (reg_bit_vector) { |
| 469 | reg_bit_vector &= (reg_bit_vector - 1); |
| 470 | ++reg_count; |
| 471 | } |
| 472 | |
| 473 | if (!ubit) |
| 474 | addr -= reg_count; |
Nicolas Pitre | 2d4b6c9 | 2008-08-21 23:22:49 +0100 | [diff] [blame] | 475 | addr += (!pbit == !ubit); |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 476 | |
| 477 | reg_bit_vector = insn & 0xffff; |
| 478 | while (reg_bit_vector) { |
| 479 | int reg = __ffs(reg_bit_vector); |
| 480 | reg_bit_vector &= (reg_bit_vector - 1); |
| 481 | if (lbit) |
| 482 | regs->uregs[reg] = *addr++; |
| 483 | else |
| 484 | *addr++ = regs->uregs[reg]; |
| 485 | } |
| 486 | |
| 487 | if (wbit) { |
| 488 | if (!ubit) |
| 489 | addr -= reg_count; |
Nicolas Pitre | 2d4b6c9 | 2008-08-21 23:22:49 +0100 | [diff] [blame] | 490 | addr -= (!pbit == !ubit); |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 491 | regs->uregs[rn] = (long)addr; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | static void __kprobes simulate_stm1_pc(struct kprobe *p, struct pt_regs *regs) |
| 496 | { |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 497 | regs->ARM_pc = (long)p->addr + str_pc_offset; |
| 498 | simulate_ldm1stm1(p, regs); |
| 499 | regs->ARM_pc = (long)p->addr + 4; |
| 500 | } |
| 501 | |
| 502 | static void __kprobes simulate_mov_ipsp(struct kprobe *p, struct pt_regs *regs) |
| 503 | { |
| 504 | regs->uregs[12] = regs->uregs[13]; |
| 505 | } |
| 506 | |
| 507 | static void __kprobes emulate_ldcstc(struct kprobe *p, struct pt_regs *regs) |
| 508 | { |
| 509 | insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0]; |
| 510 | kprobe_opcode_t insn = p->opcode; |
| 511 | int rn = (insn >> 16) & 0xf; |
| 512 | long rnv = regs->uregs[rn]; |
| 513 | |
| 514 | /* Save Rn in case of writeback. */ |
| 515 | regs->uregs[rn] = insnslot_1arg_rflags(rnv, regs->ARM_cpsr, i_fn); |
| 516 | } |
| 517 | |
| 518 | static void __kprobes emulate_ldrd(struct kprobe *p, struct pt_regs *regs) |
| 519 | { |
| 520 | insn_2arg_fn_t *i_fn = (insn_2arg_fn_t *)&p->ainsn.insn[0]; |
| 521 | kprobe_opcode_t insn = p->opcode; |
Viktor Rosendahl | cf3cc1a | 2011-03-28 18:56:05 +0300 | [diff] [blame] | 522 | long ppc = (long)p->addr + 8; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 523 | int rd = (insn >> 12) & 0xf; |
| 524 | int rn = (insn >> 16) & 0xf; |
| 525 | int rm = insn & 0xf; /* rm may be invalid, don't care. */ |
Viktor Rosendahl | cf3cc1a | 2011-03-28 18:56:05 +0300 | [diff] [blame] | 526 | long rmv = (rm == 15) ? ppc : regs->uregs[rm]; |
| 527 | long rnv = (rn == 15) ? ppc : regs->uregs[rn]; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 528 | |
| 529 | /* Not following the C calling convention here, so need asm(). */ |
| 530 | __asm__ __volatile__ ( |
| 531 | "ldr r0, %[rn] \n\t" |
| 532 | "ldr r1, %[rm] \n\t" |
| 533 | "msr cpsr_fs, %[cpsr]\n\t" |
| 534 | "mov lr, pc \n\t" |
| 535 | "mov pc, %[i_fn] \n\t" |
| 536 | "str r0, %[rn] \n\t" /* in case of writeback */ |
| 537 | "str r2, %[rd0] \n\t" |
| 538 | "str r3, %[rd1] \n\t" |
Viktor Rosendahl | cf3cc1a | 2011-03-28 18:56:05 +0300 | [diff] [blame] | 539 | : [rn] "+m" (rnv), |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 540 | [rd0] "=m" (regs->uregs[rd]), |
| 541 | [rd1] "=m" (regs->uregs[rd+1]) |
Viktor Rosendahl | cf3cc1a | 2011-03-28 18:56:05 +0300 | [diff] [blame] | 542 | : [rm] "m" (rmv), |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 543 | [cpsr] "r" (regs->ARM_cpsr), |
| 544 | [i_fn] "r" (i_fn) |
| 545 | : "r0", "r1", "r2", "r3", "lr", "cc" |
| 546 | ); |
Viktor Rosendahl | cf3cc1a | 2011-03-28 18:56:05 +0300 | [diff] [blame] | 547 | if (rn != 15) |
| 548 | regs->uregs[rn] = rnv; /* Save Rn in case of writeback. */ |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static void __kprobes emulate_strd(struct kprobe *p, struct pt_regs *regs) |
| 552 | { |
| 553 | insn_4arg_fn_t *i_fn = (insn_4arg_fn_t *)&p->ainsn.insn[0]; |
| 554 | kprobe_opcode_t insn = p->opcode; |
Viktor Rosendahl | cf3cc1a | 2011-03-28 18:56:05 +0300 | [diff] [blame] | 555 | long ppc = (long)p->addr + 8; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 556 | int rd = (insn >> 12) & 0xf; |
| 557 | int rn = (insn >> 16) & 0xf; |
| 558 | int rm = insn & 0xf; |
Viktor Rosendahl | cf3cc1a | 2011-03-28 18:56:05 +0300 | [diff] [blame] | 559 | long rnv = (rn == 15) ? ppc : regs->uregs[rn]; |
| 560 | /* rm/rmv may be invalid, don't care. */ |
| 561 | long rmv = (rm == 15) ? ppc : regs->uregs[rm]; |
| 562 | long rnv_wb; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 563 | |
Viktor Rosendahl | cf3cc1a | 2011-03-28 18:56:05 +0300 | [diff] [blame] | 564 | rnv_wb = insnslot_4arg_rflags(rnv, rmv, regs->uregs[rd], |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 565 | regs->uregs[rd+1], |
| 566 | regs->ARM_cpsr, i_fn); |
Viktor Rosendahl | cf3cc1a | 2011-03-28 18:56:05 +0300 | [diff] [blame] | 567 | if (rn != 15) |
| 568 | regs->uregs[rn] = rnv_wb; /* Save Rn in case of writeback. */ |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | static void __kprobes emulate_ldr(struct kprobe *p, struct pt_regs *regs) |
| 572 | { |
| 573 | insn_llret_3arg_fn_t *i_fn = (insn_llret_3arg_fn_t *)&p->ainsn.insn[0]; |
| 574 | kprobe_opcode_t insn = p->opcode; |
Nicolas Pitre | 0ebe25f | 2010-07-14 05:21:22 +0100 | [diff] [blame] | 575 | long ppc = (long)p->addr + 8; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 576 | union reg_pair fnr; |
| 577 | int rd = (insn >> 12) & 0xf; |
| 578 | int rn = (insn >> 16) & 0xf; |
| 579 | int rm = insn & 0xf; |
| 580 | long rdv; |
Nicolas Pitre | 0ebe25f | 2010-07-14 05:21:22 +0100 | [diff] [blame] | 581 | long rnv = (rn == 15) ? ppc : regs->uregs[rn]; |
| 582 | long rmv = (rm == 15) ? ppc : regs->uregs[rm]; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 583 | long cpsr = regs->ARM_cpsr; |
| 584 | |
| 585 | fnr.dr = insnslot_llret_3arg_rflags(rnv, 0, rmv, cpsr, i_fn); |
Viktor Rosendahl | 0652f06 | 2011-03-26 18:11:01 +0100 | [diff] [blame] | 586 | if (rn != 15) |
| 587 | regs->uregs[rn] = fnr.r0; /* Save Rn in case of writeback. */ |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 588 | rdv = fnr.r1; |
| 589 | |
| 590 | if (rd == 15) { |
| 591 | #if __LINUX_ARM_ARCH__ >= 5 |
| 592 | cpsr &= ~PSR_T_BIT; |
| 593 | if (rdv & 0x1) |
| 594 | cpsr |= PSR_T_BIT; |
| 595 | regs->ARM_cpsr = cpsr; |
| 596 | rdv &= ~0x1; |
| 597 | #else |
| 598 | rdv &= ~0x2; |
| 599 | #endif |
| 600 | } |
| 601 | regs->uregs[rd] = rdv; |
| 602 | } |
| 603 | |
| 604 | static void __kprobes emulate_str(struct kprobe *p, struct pt_regs *regs) |
| 605 | { |
| 606 | insn_3arg_fn_t *i_fn = (insn_3arg_fn_t *)&p->ainsn.insn[0]; |
| 607 | kprobe_opcode_t insn = p->opcode; |
| 608 | long iaddr = (long)p->addr; |
| 609 | int rd = (insn >> 12) & 0xf; |
| 610 | int rn = (insn >> 16) & 0xf; |
| 611 | int rm = insn & 0xf; |
| 612 | long rdv = (rd == 15) ? iaddr + str_pc_offset : regs->uregs[rd]; |
| 613 | long rnv = (rn == 15) ? iaddr + 8 : regs->uregs[rn]; |
| 614 | long rmv = regs->uregs[rm]; /* rm/rmv may be invalid, don't care. */ |
Viktor Rosendahl | 0652f06 | 2011-03-26 18:11:01 +0100 | [diff] [blame] | 615 | long rnv_wb; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 616 | |
Viktor Rosendahl | 0652f06 | 2011-03-26 18:11:01 +0100 | [diff] [blame] | 617 | rnv_wb = insnslot_3arg_rflags(rnv, rdv, rmv, regs->ARM_cpsr, i_fn); |
| 618 | if (rn != 15) |
| 619 | regs->uregs[rn] = rnv_wb; /* Save Rn in case of writeback. */ |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | static void __kprobes emulate_mrrc(struct kprobe *p, struct pt_regs *regs) |
| 623 | { |
| 624 | insn_llret_0arg_fn_t *i_fn = (insn_llret_0arg_fn_t *)&p->ainsn.insn[0]; |
| 625 | kprobe_opcode_t insn = p->opcode; |
| 626 | union reg_pair fnr; |
| 627 | int rd = (insn >> 12) & 0xf; |
| 628 | int rn = (insn >> 16) & 0xf; |
| 629 | |
| 630 | fnr.dr = insnslot_llret_0arg_rflags(regs->ARM_cpsr, i_fn); |
| 631 | regs->uregs[rn] = fnr.r0; |
| 632 | regs->uregs[rd] = fnr.r1; |
| 633 | } |
| 634 | |
| 635 | static void __kprobes emulate_mcrr(struct kprobe *p, struct pt_regs *regs) |
| 636 | { |
| 637 | insn_2arg_fn_t *i_fn = (insn_2arg_fn_t *)&p->ainsn.insn[0]; |
| 638 | kprobe_opcode_t insn = p->opcode; |
| 639 | int rd = (insn >> 12) & 0xf; |
| 640 | int rn = (insn >> 16) & 0xf; |
| 641 | long rnv = regs->uregs[rn]; |
| 642 | long rdv = regs->uregs[rd]; |
| 643 | |
| 644 | insnslot_2arg_rflags(rnv, rdv, regs->ARM_cpsr, i_fn); |
| 645 | } |
| 646 | |
| 647 | static void __kprobes emulate_sat(struct kprobe *p, struct pt_regs *regs) |
| 648 | { |
| 649 | insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0]; |
| 650 | kprobe_opcode_t insn = p->opcode; |
| 651 | int rd = (insn >> 12) & 0xf; |
| 652 | int rm = insn & 0xf; |
| 653 | long rmv = regs->uregs[rm]; |
| 654 | |
| 655 | /* Writes Q flag */ |
| 656 | regs->uregs[rd] = insnslot_1arg_rwflags(rmv, ®s->ARM_cpsr, i_fn); |
| 657 | } |
| 658 | |
| 659 | static void __kprobes emulate_sel(struct kprobe *p, struct pt_regs *regs) |
| 660 | { |
| 661 | insn_2arg_fn_t *i_fn = (insn_2arg_fn_t *)&p->ainsn.insn[0]; |
| 662 | kprobe_opcode_t insn = p->opcode; |
| 663 | int rd = (insn >> 12) & 0xf; |
| 664 | int rn = (insn >> 16) & 0xf; |
| 665 | int rm = insn & 0xf; |
| 666 | long rnv = regs->uregs[rn]; |
| 667 | long rmv = regs->uregs[rm]; |
| 668 | |
| 669 | /* Reads GE bits */ |
| 670 | regs->uregs[rd] = insnslot_2arg_rflags(rnv, rmv, regs->ARM_cpsr, i_fn); |
| 671 | } |
| 672 | |
| 673 | static void __kprobes emulate_none(struct kprobe *p, struct pt_regs *regs) |
| 674 | { |
| 675 | insn_0arg_fn_t *i_fn = (insn_0arg_fn_t *)&p->ainsn.insn[0]; |
| 676 | |
| 677 | insnslot_0arg_rflags(regs->ARM_cpsr, i_fn); |
| 678 | } |
| 679 | |
| 680 | static void __kprobes emulate_rd12(struct kprobe *p, struct pt_regs *regs) |
| 681 | { |
| 682 | insn_0arg_fn_t *i_fn = (insn_0arg_fn_t *)&p->ainsn.insn[0]; |
| 683 | kprobe_opcode_t insn = p->opcode; |
| 684 | int rd = (insn >> 12) & 0xf; |
| 685 | |
| 686 | regs->uregs[rd] = insnslot_0arg_rflags(regs->ARM_cpsr, i_fn); |
| 687 | } |
| 688 | |
| 689 | static void __kprobes emulate_ird12(struct kprobe *p, struct pt_regs *regs) |
| 690 | { |
| 691 | insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0]; |
| 692 | kprobe_opcode_t insn = p->opcode; |
| 693 | int ird = (insn >> 12) & 0xf; |
| 694 | |
| 695 | insnslot_1arg_rflags(regs->uregs[ird], regs->ARM_cpsr, i_fn); |
| 696 | } |
| 697 | |
| 698 | static void __kprobes emulate_rn16(struct kprobe *p, struct pt_regs *regs) |
| 699 | { |
| 700 | insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0]; |
| 701 | kprobe_opcode_t insn = p->opcode; |
| 702 | int rn = (insn >> 16) & 0xf; |
| 703 | long rnv = regs->uregs[rn]; |
| 704 | |
| 705 | insnslot_1arg_rflags(rnv, regs->ARM_cpsr, i_fn); |
| 706 | } |
| 707 | |
| 708 | static void __kprobes emulate_rd12rm0(struct kprobe *p, struct pt_regs *regs) |
| 709 | { |
| 710 | insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0]; |
| 711 | kprobe_opcode_t insn = p->opcode; |
| 712 | int rd = (insn >> 12) & 0xf; |
| 713 | int rm = insn & 0xf; |
| 714 | long rmv = regs->uregs[rm]; |
| 715 | |
| 716 | regs->uregs[rd] = insnslot_1arg_rflags(rmv, regs->ARM_cpsr, i_fn); |
| 717 | } |
| 718 | |
| 719 | static void __kprobes |
| 720 | emulate_rd12rn16rm0_rwflags(struct kprobe *p, struct pt_regs *regs) |
| 721 | { |
| 722 | insn_2arg_fn_t *i_fn = (insn_2arg_fn_t *)&p->ainsn.insn[0]; |
| 723 | kprobe_opcode_t insn = p->opcode; |
| 724 | int rd = (insn >> 12) & 0xf; |
| 725 | int rn = (insn >> 16) & 0xf; |
| 726 | int rm = insn & 0xf; |
| 727 | long rnv = regs->uregs[rn]; |
| 728 | long rmv = regs->uregs[rm]; |
| 729 | |
| 730 | regs->uregs[rd] = |
| 731 | insnslot_2arg_rwflags(rnv, rmv, ®s->ARM_cpsr, i_fn); |
| 732 | } |
| 733 | |
| 734 | static void __kprobes |
| 735 | emulate_rd16rn12rs8rm0_rwflags(struct kprobe *p, struct pt_regs *regs) |
| 736 | { |
| 737 | insn_3arg_fn_t *i_fn = (insn_3arg_fn_t *)&p->ainsn.insn[0]; |
| 738 | kprobe_opcode_t insn = p->opcode; |
| 739 | int rd = (insn >> 16) & 0xf; |
| 740 | int rn = (insn >> 12) & 0xf; |
| 741 | int rs = (insn >> 8) & 0xf; |
| 742 | int rm = insn & 0xf; |
| 743 | long rnv = regs->uregs[rn]; |
| 744 | long rsv = regs->uregs[rs]; |
| 745 | long rmv = regs->uregs[rm]; |
| 746 | |
| 747 | regs->uregs[rd] = |
| 748 | insnslot_3arg_rwflags(rnv, rsv, rmv, ®s->ARM_cpsr, i_fn); |
| 749 | } |
| 750 | |
| 751 | static void __kprobes |
| 752 | emulate_rd16rs8rm0_rwflags(struct kprobe *p, struct pt_regs *regs) |
| 753 | { |
| 754 | insn_2arg_fn_t *i_fn = (insn_2arg_fn_t *)&p->ainsn.insn[0]; |
| 755 | kprobe_opcode_t insn = p->opcode; |
| 756 | int rd = (insn >> 16) & 0xf; |
| 757 | int rs = (insn >> 8) & 0xf; |
| 758 | int rm = insn & 0xf; |
| 759 | long rsv = regs->uregs[rs]; |
| 760 | long rmv = regs->uregs[rm]; |
| 761 | |
| 762 | regs->uregs[rd] = |
| 763 | insnslot_2arg_rwflags(rsv, rmv, ®s->ARM_cpsr, i_fn); |
| 764 | } |
| 765 | |
| 766 | static void __kprobes |
| 767 | emulate_rdhi16rdlo12rs8rm0_rwflags(struct kprobe *p, struct pt_regs *regs) |
| 768 | { |
| 769 | insn_llret_4arg_fn_t *i_fn = (insn_llret_4arg_fn_t *)&p->ainsn.insn[0]; |
| 770 | kprobe_opcode_t insn = p->opcode; |
| 771 | union reg_pair fnr; |
| 772 | int rdhi = (insn >> 16) & 0xf; |
| 773 | int rdlo = (insn >> 12) & 0xf; |
| 774 | int rs = (insn >> 8) & 0xf; |
| 775 | int rm = insn & 0xf; |
| 776 | long rsv = regs->uregs[rs]; |
| 777 | long rmv = regs->uregs[rm]; |
| 778 | |
| 779 | fnr.dr = insnslot_llret_4arg_rwflags(regs->uregs[rdhi], |
| 780 | regs->uregs[rdlo], rsv, rmv, |
| 781 | ®s->ARM_cpsr, i_fn); |
| 782 | regs->uregs[rdhi] = fnr.r0; |
| 783 | regs->uregs[rdlo] = fnr.r1; |
| 784 | } |
| 785 | |
| 786 | static void __kprobes |
| 787 | emulate_alu_imm_rflags(struct kprobe *p, struct pt_regs *regs) |
| 788 | { |
| 789 | insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0]; |
| 790 | kprobe_opcode_t insn = p->opcode; |
| 791 | int rd = (insn >> 12) & 0xf; |
| 792 | int rn = (insn >> 16) & 0xf; |
| 793 | long rnv = (rn == 15) ? (long)p->addr + 8 : regs->uregs[rn]; |
| 794 | |
| 795 | regs->uregs[rd] = insnslot_1arg_rflags(rnv, regs->ARM_cpsr, i_fn); |
| 796 | } |
| 797 | |
| 798 | static void __kprobes |
| 799 | emulate_alu_imm_rwflags(struct kprobe *p, struct pt_regs *regs) |
| 800 | { |
| 801 | insn_1arg_fn_t *i_fn = (insn_1arg_fn_t *)&p->ainsn.insn[0]; |
| 802 | kprobe_opcode_t insn = p->opcode; |
| 803 | int rd = (insn >> 12) & 0xf; |
| 804 | int rn = (insn >> 16) & 0xf; |
| 805 | long rnv = (rn == 15) ? (long)p->addr + 8 : regs->uregs[rn]; |
| 806 | |
| 807 | regs->uregs[rd] = insnslot_1arg_rwflags(rnv, ®s->ARM_cpsr, i_fn); |
| 808 | } |
| 809 | |
| 810 | static void __kprobes |
| 811 | emulate_alu_rflags(struct kprobe *p, struct pt_regs *regs) |
| 812 | { |
| 813 | insn_3arg_fn_t *i_fn = (insn_3arg_fn_t *)&p->ainsn.insn[0]; |
| 814 | kprobe_opcode_t insn = p->opcode; |
| 815 | long ppc = (long)p->addr + 8; |
| 816 | int rd = (insn >> 12) & 0xf; |
| 817 | int rn = (insn >> 16) & 0xf; /* rn/rnv/rs/rsv may be */ |
| 818 | int rs = (insn >> 8) & 0xf; /* invalid, don't care. */ |
| 819 | int rm = insn & 0xf; |
| 820 | long rnv = (rn == 15) ? ppc : regs->uregs[rn]; |
| 821 | long rmv = (rm == 15) ? ppc : regs->uregs[rm]; |
| 822 | long rsv = regs->uregs[rs]; |
| 823 | |
| 824 | regs->uregs[rd] = |
| 825 | insnslot_3arg_rflags(rnv, rmv, rsv, regs->ARM_cpsr, i_fn); |
| 826 | } |
| 827 | |
| 828 | static void __kprobes |
| 829 | emulate_alu_rwflags(struct kprobe *p, struct pt_regs *regs) |
| 830 | { |
| 831 | insn_3arg_fn_t *i_fn = (insn_3arg_fn_t *)&p->ainsn.insn[0]; |
| 832 | kprobe_opcode_t insn = p->opcode; |
| 833 | long ppc = (long)p->addr + 8; |
| 834 | int rd = (insn >> 12) & 0xf; |
| 835 | int rn = (insn >> 16) & 0xf; /* rn/rnv/rs/rsv may be */ |
| 836 | int rs = (insn >> 8) & 0xf; /* invalid, don't care. */ |
| 837 | int rm = insn & 0xf; |
| 838 | long rnv = (rn == 15) ? ppc : regs->uregs[rn]; |
| 839 | long rmv = (rm == 15) ? ppc : regs->uregs[rm]; |
| 840 | long rsv = regs->uregs[rs]; |
| 841 | |
| 842 | regs->uregs[rd] = |
| 843 | insnslot_3arg_rwflags(rnv, rmv, rsv, ®s->ARM_cpsr, i_fn); |
| 844 | } |
| 845 | |
| 846 | static enum kprobe_insn __kprobes |
| 847 | prep_emulate_ldr_str(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 848 | { |
| 849 | int ibit = (insn & (1 << 26)) ? 25 : 22; |
| 850 | |
| 851 | insn &= 0xfff00fff; |
| 852 | insn |= 0x00001000; /* Rn = r0, Rd = r1 */ |
| 853 | if (insn & (1 << ibit)) { |
| 854 | insn &= ~0xf; |
| 855 | insn |= 2; /* Rm = r2 */ |
| 856 | } |
| 857 | asi->insn[0] = insn; |
| 858 | asi->insn_handler = (insn & (1 << 20)) ? emulate_ldr : emulate_str; |
| 859 | return INSN_GOOD; |
| 860 | } |
| 861 | |
| 862 | static enum kprobe_insn __kprobes |
| 863 | prep_emulate_rd12rm0(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 864 | { |
| 865 | insn &= 0xffff0ff0; /* Rd = r0, Rm = r0 */ |
| 866 | asi->insn[0] = insn; |
| 867 | asi->insn_handler = emulate_rd12rm0; |
| 868 | return INSN_GOOD; |
| 869 | } |
| 870 | |
| 871 | static enum kprobe_insn __kprobes |
| 872 | prep_emulate_rd12(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 873 | { |
| 874 | insn &= 0xffff0fff; /* Rd = r0 */ |
| 875 | asi->insn[0] = insn; |
| 876 | asi->insn_handler = emulate_rd12; |
| 877 | return INSN_GOOD; |
| 878 | } |
| 879 | |
| 880 | static enum kprobe_insn __kprobes |
| 881 | prep_emulate_rd12rn16rm0_wflags(kprobe_opcode_t insn, |
| 882 | struct arch_specific_insn *asi) |
| 883 | { |
| 884 | insn &= 0xfff00ff0; /* Rd = r0, Rn = r0 */ |
| 885 | insn |= 0x00000001; /* Rm = r1 */ |
| 886 | asi->insn[0] = insn; |
| 887 | asi->insn_handler = emulate_rd12rn16rm0_rwflags; |
| 888 | return INSN_GOOD; |
| 889 | } |
| 890 | |
| 891 | static enum kprobe_insn __kprobes |
| 892 | prep_emulate_rd16rs8rm0_wflags(kprobe_opcode_t insn, |
| 893 | struct arch_specific_insn *asi) |
| 894 | { |
| 895 | insn &= 0xfff0f0f0; /* Rd = r0, Rs = r0 */ |
| 896 | insn |= 0x00000001; /* Rm = r1 */ |
| 897 | asi->insn[0] = insn; |
| 898 | asi->insn_handler = emulate_rd16rs8rm0_rwflags; |
| 899 | return INSN_GOOD; |
| 900 | } |
| 901 | |
| 902 | static enum kprobe_insn __kprobes |
| 903 | prep_emulate_rd16rn12rs8rm0_wflags(kprobe_opcode_t insn, |
| 904 | struct arch_specific_insn *asi) |
| 905 | { |
| 906 | insn &= 0xfff000f0; /* Rd = r0, Rn = r0 */ |
| 907 | insn |= 0x00000102; /* Rs = r1, Rm = r2 */ |
| 908 | asi->insn[0] = insn; |
| 909 | asi->insn_handler = emulate_rd16rn12rs8rm0_rwflags; |
| 910 | return INSN_GOOD; |
| 911 | } |
| 912 | |
| 913 | static enum kprobe_insn __kprobes |
| 914 | prep_emulate_rdhi16rdlo12rs8rm0_wflags(kprobe_opcode_t insn, |
| 915 | struct arch_specific_insn *asi) |
| 916 | { |
| 917 | insn &= 0xfff000f0; /* RdHi = r0, RdLo = r1 */ |
| 918 | insn |= 0x00001203; /* Rs = r2, Rm = r3 */ |
| 919 | asi->insn[0] = insn; |
| 920 | asi->insn_handler = emulate_rdhi16rdlo12rs8rm0_rwflags; |
| 921 | return INSN_GOOD; |
| 922 | } |
| 923 | |
| 924 | /* |
| 925 | * For the instruction masking and comparisons in all the "space_*" |
| 926 | * functions below, Do _not_ rearrange the order of tests unless |
| 927 | * you're very, very sure of what you are doing. For the sake of |
| 928 | * efficiency, the masks for some tests sometimes assume other test |
| 929 | * have been done prior to them so the number of patterns to test |
| 930 | * for an instruction set can be as broad as possible to reduce the |
| 931 | * number of tests needed. |
| 932 | */ |
| 933 | |
| 934 | static enum kprobe_insn __kprobes |
| 935 | space_1111(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 936 | { |
| 937 | /* CPS mmod == 1 : 1111 0001 0000 xx10 xxxx xxxx xx0x xxxx */ |
| 938 | /* RFE : 1111 100x x0x1 xxxx xxxx 1010 xxxx xxxx */ |
| 939 | /* SRS : 1111 100x x1x0 1101 xxxx 0101 xxxx xxxx */ |
| 940 | if ((insn & 0xfff30020) == 0xf1020000 || |
| 941 | (insn & 0xfe500f00) == 0xf8100a00 || |
| 942 | (insn & 0xfe5f0f00) == 0xf84d0500) |
| 943 | return INSN_REJECTED; |
| 944 | |
| 945 | /* PLD : 1111 01x1 x101 xxxx xxxx xxxx xxxx xxxx : */ |
| 946 | if ((insn & 0xfd700000) == 0xf4500000) { |
| 947 | insn &= 0xfff0ffff; /* Rn = r0 */ |
| 948 | asi->insn[0] = insn; |
| 949 | asi->insn_handler = emulate_rn16; |
| 950 | return INSN_GOOD; |
| 951 | } |
| 952 | |
| 953 | /* BLX(1) : 1111 101x xxxx xxxx xxxx xxxx xxxx xxxx : */ |
| 954 | if ((insn & 0xfe000000) == 0xfa000000) { |
| 955 | asi->insn_handler = simulate_blx1; |
| 956 | return INSN_GOOD_NO_SLOT; |
| 957 | } |
| 958 | |
| 959 | /* SETEND : 1111 0001 0000 0001 xxxx xxxx 0000 xxxx */ |
| 960 | /* CDP2 : 1111 1110 xxxx xxxx xxxx xxxx xxx0 xxxx */ |
| 961 | if ((insn & 0xffff00f0) == 0xf1010000 || |
| 962 | (insn & 0xff000010) == 0xfe000000) { |
| 963 | asi->insn[0] = insn; |
| 964 | asi->insn_handler = emulate_none; |
| 965 | return INSN_GOOD; |
| 966 | } |
| 967 | |
| 968 | /* MCRR2 : 1111 1100 0100 xxxx xxxx xxxx xxxx xxxx : (Rd != Rn) */ |
| 969 | /* MRRC2 : 1111 1100 0101 xxxx xxxx xxxx xxxx xxxx : (Rd != Rn) */ |
| 970 | if ((insn & 0xffe00000) == 0xfc400000) { |
| 971 | insn &= 0xfff00fff; /* Rn = r0 */ |
| 972 | insn |= 0x00001000; /* Rd = r1 */ |
| 973 | asi->insn[0] = insn; |
| 974 | asi->insn_handler = |
| 975 | (insn & (1 << 20)) ? emulate_mrrc : emulate_mcrr; |
| 976 | return INSN_GOOD; |
| 977 | } |
| 978 | |
| 979 | /* LDC2 : 1111 110x xxx1 xxxx xxxx xxxx xxxx xxxx */ |
| 980 | /* STC2 : 1111 110x xxx0 xxxx xxxx xxxx xxxx xxxx */ |
| 981 | if ((insn & 0xfe000000) == 0xfc000000) { |
| 982 | insn &= 0xfff0ffff; /* Rn = r0 */ |
| 983 | asi->insn[0] = insn; |
| 984 | asi->insn_handler = emulate_ldcstc; |
| 985 | return INSN_GOOD; |
| 986 | } |
| 987 | |
| 988 | /* MCR2 : 1111 1110 xxx0 xxxx xxxx xxxx xxx1 xxxx */ |
| 989 | /* MRC2 : 1111 1110 xxx1 xxxx xxxx xxxx xxx1 xxxx */ |
| 990 | insn &= 0xffff0fff; /* Rd = r0 */ |
| 991 | asi->insn[0] = insn; |
| 992 | asi->insn_handler = (insn & (1 << 20)) ? emulate_rd12 : emulate_ird12; |
| 993 | return INSN_GOOD; |
| 994 | } |
| 995 | |
| 996 | static enum kprobe_insn __kprobes |
| 997 | space_cccc_000x(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 998 | { |
| 999 | /* cccc 0001 0xx0 xxxx xxxx xxxx xxxx xxx0 xxxx */ |
| 1000 | if ((insn & 0x0f900010) == 0x01000000) { |
| 1001 | |
| 1002 | /* BXJ : cccc 0001 0010 xxxx xxxx xxxx 0010 xxxx */ |
| 1003 | /* MSR : cccc 0001 0x10 xxxx xxxx xxxx 0000 xxxx */ |
| 1004 | if ((insn & 0x0ff000f0) == 0x01200020 || |
| 1005 | (insn & 0x0fb000f0) == 0x01200000) |
| 1006 | return INSN_REJECTED; |
| 1007 | |
| 1008 | /* MRS : cccc 0001 0x00 xxxx xxxx xxxx 0000 xxxx */ |
| 1009 | if ((insn & 0x0fb00010) == 0x01000000) |
| 1010 | return prep_emulate_rd12(insn, asi); |
| 1011 | |
| 1012 | /* SMLALxy : cccc 0001 0100 xxxx xxxx xxxx 1xx0 xxxx */ |
| 1013 | if ((insn & 0x0ff00090) == 0x01400080) |
| 1014 | return prep_emulate_rdhi16rdlo12rs8rm0_wflags(insn, asi); |
| 1015 | |
| 1016 | /* SMULWy : cccc 0001 0010 xxxx xxxx xxxx 1x10 xxxx */ |
| 1017 | /* SMULxy : cccc 0001 0110 xxxx xxxx xxxx 1xx0 xxxx */ |
| 1018 | if ((insn & 0x0ff000b0) == 0x012000a0 || |
| 1019 | (insn & 0x0ff00090) == 0x01600080) |
| 1020 | return prep_emulate_rd16rs8rm0_wflags(insn, asi); |
| 1021 | |
| 1022 | /* SMLAxy : cccc 0001 0000 xxxx xxxx xxxx 1xx0 xxxx : Q */ |
| 1023 | /* SMLAWy : cccc 0001 0010 xxxx xxxx xxxx 0x00 xxxx : Q */ |
| 1024 | return prep_emulate_rd16rn12rs8rm0_wflags(insn, asi); |
| 1025 | |
| 1026 | } |
| 1027 | |
| 1028 | /* cccc 0001 0xx0 xxxx xxxx xxxx xxxx 0xx1 xxxx */ |
| 1029 | else if ((insn & 0x0f900090) == 0x01000010) { |
| 1030 | |
| 1031 | /* BKPT : 1110 0001 0010 xxxx xxxx xxxx 0111 xxxx */ |
| 1032 | if ((insn & 0xfff000f0) == 0xe1200070) |
| 1033 | return INSN_REJECTED; |
| 1034 | |
| 1035 | /* BLX(2) : cccc 0001 0010 xxxx xxxx xxxx 0011 xxxx */ |
| 1036 | /* BX : cccc 0001 0010 xxxx xxxx xxxx 0001 xxxx */ |
| 1037 | if ((insn & 0x0ff000d0) == 0x01200010) { |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1038 | asi->insn_handler = simulate_blx2bx; |
Jon Medhurst | a539f5d | 2011-04-06 11:17:10 +0100 | [diff] [blame^] | 1039 | return INSN_GOOD_NO_SLOT; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
| 1042 | /* CLZ : cccc 0001 0110 xxxx xxxx xxxx 0001 xxxx */ |
| 1043 | if ((insn & 0x0ff000f0) == 0x01600010) |
| 1044 | return prep_emulate_rd12rm0(insn, asi); |
| 1045 | |
| 1046 | /* QADD : cccc 0001 0000 xxxx xxxx xxxx 0101 xxxx :Q */ |
| 1047 | /* QSUB : cccc 0001 0010 xxxx xxxx xxxx 0101 xxxx :Q */ |
| 1048 | /* QDADD : cccc 0001 0100 xxxx xxxx xxxx 0101 xxxx :Q */ |
| 1049 | /* QDSUB : cccc 0001 0110 xxxx xxxx xxxx 0101 xxxx :Q */ |
| 1050 | return prep_emulate_rd12rn16rm0_wflags(insn, asi); |
| 1051 | } |
| 1052 | |
| 1053 | /* cccc 0000 xxxx xxxx xxxx xxxx xxxx 1001 xxxx */ |
| 1054 | else if ((insn & 0x0f000090) == 0x00000090) { |
| 1055 | |
| 1056 | /* MUL : cccc 0000 0000 xxxx xxxx xxxx 1001 xxxx : */ |
| 1057 | /* MULS : cccc 0000 0001 xxxx xxxx xxxx 1001 xxxx :cc */ |
| 1058 | /* MLA : cccc 0000 0010 xxxx xxxx xxxx 1001 xxxx : */ |
| 1059 | /* MLAS : cccc 0000 0011 xxxx xxxx xxxx 1001 xxxx :cc */ |
| 1060 | /* UMAAL : cccc 0000 0100 xxxx xxxx xxxx 1001 xxxx : */ |
| 1061 | /* UMULL : cccc 0000 1000 xxxx xxxx xxxx 1001 xxxx : */ |
| 1062 | /* UMULLS : cccc 0000 1001 xxxx xxxx xxxx 1001 xxxx :cc */ |
| 1063 | /* UMLAL : cccc 0000 1010 xxxx xxxx xxxx 1001 xxxx : */ |
| 1064 | /* UMLALS : cccc 0000 1011 xxxx xxxx xxxx 1001 xxxx :cc */ |
| 1065 | /* SMULL : cccc 0000 1100 xxxx xxxx xxxx 1001 xxxx : */ |
| 1066 | /* SMULLS : cccc 0000 1101 xxxx xxxx xxxx 1001 xxxx :cc */ |
| 1067 | /* SMLAL : cccc 0000 1110 xxxx xxxx xxxx 1001 xxxx : */ |
| 1068 | /* SMLALS : cccc 0000 1111 xxxx xxxx xxxx 1001 xxxx :cc */ |
| 1069 | if ((insn & 0x0fe000f0) == 0x00000090) { |
| 1070 | return prep_emulate_rd16rs8rm0_wflags(insn, asi); |
| 1071 | } else if ((insn & 0x0fe000f0) == 0x00200090) { |
| 1072 | return prep_emulate_rd16rn12rs8rm0_wflags(insn, asi); |
| 1073 | } else { |
| 1074 | return prep_emulate_rdhi16rdlo12rs8rm0_wflags(insn, asi); |
| 1075 | } |
| 1076 | } |
| 1077 | |
| 1078 | /* cccc 000x xxxx xxxx xxxx xxxx xxxx 1xx1 xxxx */ |
| 1079 | else if ((insn & 0x0e000090) == 0x00000090) { |
| 1080 | |
| 1081 | /* SWP : cccc 0001 0000 xxxx xxxx xxxx 1001 xxxx */ |
| 1082 | /* SWPB : cccc 0001 0100 xxxx xxxx xxxx 1001 xxxx */ |
| 1083 | /* LDRD : cccc 000x xxx0 xxxx xxxx xxxx 1101 xxxx */ |
| 1084 | /* STRD : cccc 000x xxx0 xxxx xxxx xxxx 1111 xxxx */ |
| 1085 | /* STREX : cccc 0001 1000 xxxx xxxx xxxx 1001 xxxx */ |
| 1086 | /* LDREX : cccc 0001 1001 xxxx xxxx xxxx 1001 xxxx */ |
| 1087 | /* LDRH : cccc 000x xxx1 xxxx xxxx xxxx 1011 xxxx */ |
| 1088 | /* STRH : cccc 000x xxx0 xxxx xxxx xxxx 1011 xxxx */ |
| 1089 | /* LDRSB : cccc 000x xxx1 xxxx xxxx xxxx 1101 xxxx */ |
| 1090 | /* LDRSH : cccc 000x xxx1 xxxx xxxx xxxx 1111 xxxx */ |
| 1091 | if ((insn & 0x0fb000f0) == 0x01000090) { |
| 1092 | /* SWP/SWPB */ |
| 1093 | return prep_emulate_rd12rn16rm0_wflags(insn, asi); |
| 1094 | } else if ((insn & 0x0e1000d0) == 0x00000d0) { |
| 1095 | /* STRD/LDRD */ |
| 1096 | insn &= 0xfff00fff; |
| 1097 | insn |= 0x00002000; /* Rn = r0, Rd = r2 */ |
| 1098 | if (insn & (1 << 22)) { |
| 1099 | /* I bit */ |
| 1100 | insn &= ~0xf; |
| 1101 | insn |= 1; /* Rm = r1 */ |
| 1102 | } |
| 1103 | asi->insn[0] = insn; |
| 1104 | asi->insn_handler = |
| 1105 | (insn & (1 << 5)) ? emulate_strd : emulate_ldrd; |
| 1106 | return INSN_GOOD; |
| 1107 | } |
| 1108 | |
| 1109 | return prep_emulate_ldr_str(insn, asi); |
| 1110 | } |
| 1111 | |
| 1112 | /* cccc 000x xxxx xxxx xxxx xxxx xxxx xxxx xxxx */ |
| 1113 | |
| 1114 | /* |
| 1115 | * ALU op with S bit and Rd == 15 : |
| 1116 | * cccc 000x xxx1 xxxx 1111 xxxx xxxx xxxx |
| 1117 | */ |
| 1118 | if ((insn & 0x0e10f000) == 0x0010f000) |
| 1119 | return INSN_REJECTED; |
| 1120 | |
| 1121 | /* |
| 1122 | * "mov ip, sp" is the most common kprobe'd instruction by far. |
| 1123 | * Check and optimize for it explicitly. |
| 1124 | */ |
| 1125 | if (insn == 0xe1a0c00d) { |
| 1126 | asi->insn_handler = simulate_mov_ipsp; |
| 1127 | return INSN_GOOD_NO_SLOT; |
| 1128 | } |
| 1129 | |
| 1130 | /* |
| 1131 | * Data processing: Immediate-shift / Register-shift |
| 1132 | * ALU op : cccc 000x xxxx xxxx xxxx xxxx xxxx xxxx |
| 1133 | * CPY : cccc 0001 1010 xxxx xxxx 0000 0000 xxxx |
| 1134 | * MOV : cccc 0001 101x xxxx xxxx xxxx xxxx xxxx |
| 1135 | * *S (bit 20) updates condition codes |
| 1136 | * ADC/SBC/RSC reads the C flag |
| 1137 | */ |
| 1138 | insn &= 0xfff00ff0; /* Rn = r0, Rd = r0 */ |
| 1139 | insn |= 0x00000001; /* Rm = r1 */ |
| 1140 | if (insn & 0x010) { |
| 1141 | insn &= 0xfffff0ff; /* register shift */ |
| 1142 | insn |= 0x00000200; /* Rs = r2 */ |
| 1143 | } |
| 1144 | asi->insn[0] = insn; |
| 1145 | asi->insn_handler = (insn & (1 << 20)) ? /* S-bit */ |
| 1146 | emulate_alu_rwflags : emulate_alu_rflags; |
| 1147 | return INSN_GOOD; |
| 1148 | } |
| 1149 | |
| 1150 | static enum kprobe_insn __kprobes |
| 1151 | space_cccc_001x(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 1152 | { |
| 1153 | /* |
| 1154 | * MSR : cccc 0011 0x10 xxxx xxxx xxxx xxxx xxxx |
Will Deacon | ccdf2e1 | 2010-09-27 18:12:12 +0100 | [diff] [blame] | 1155 | * Undef : cccc 0011 0100 xxxx xxxx xxxx xxxx xxxx |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1156 | * ALU op with S bit and Rd == 15 : |
| 1157 | * cccc 001x xxx1 xxxx 1111 xxxx xxxx xxxx |
| 1158 | */ |
Will Deacon | ccdf2e1 | 2010-09-27 18:12:12 +0100 | [diff] [blame] | 1159 | if ((insn & 0x0fb00000) == 0x03200000 || /* MSR */ |
| 1160 | (insn & 0x0ff00000) == 0x03400000 || /* Undef */ |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1161 | (insn & 0x0e10f000) == 0x0210f000) /* ALU s-bit, R15 */ |
| 1162 | return INSN_REJECTED; |
| 1163 | |
| 1164 | /* |
| 1165 | * Data processing: 32-bit Immediate |
| 1166 | * ALU op : cccc 001x xxxx xxxx xxxx xxxx xxxx xxxx |
| 1167 | * MOV : cccc 0011 101x xxxx xxxx xxxx xxxx xxxx |
| 1168 | * *S (bit 20) updates condition codes |
| 1169 | * ADC/SBC/RSC reads the C flag |
| 1170 | */ |
Will Deacon | ccdf2e1 | 2010-09-27 18:12:12 +0100 | [diff] [blame] | 1171 | insn &= 0xffff0fff; /* Rd = r0 */ |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1172 | asi->insn[0] = insn; |
| 1173 | asi->insn_handler = (insn & (1 << 20)) ? /* S-bit */ |
| 1174 | emulate_alu_imm_rwflags : emulate_alu_imm_rflags; |
| 1175 | return INSN_GOOD; |
| 1176 | } |
| 1177 | |
| 1178 | static enum kprobe_insn __kprobes |
| 1179 | space_cccc_0110__1(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 1180 | { |
| 1181 | /* SEL : cccc 0110 1000 xxxx xxxx xxxx 1011 xxxx GE: !!! */ |
| 1182 | if ((insn & 0x0ff000f0) == 0x068000b0) { |
| 1183 | insn &= 0xfff00ff0; /* Rd = r0, Rn = r0 */ |
| 1184 | insn |= 0x00000001; /* Rm = r1 */ |
| 1185 | asi->insn[0] = insn; |
| 1186 | asi->insn_handler = emulate_sel; |
| 1187 | return INSN_GOOD; |
| 1188 | } |
| 1189 | |
| 1190 | /* SSAT : cccc 0110 101x xxxx xxxx xxxx xx01 xxxx :Q */ |
| 1191 | /* USAT : cccc 0110 111x xxxx xxxx xxxx xx01 xxxx :Q */ |
| 1192 | /* SSAT16 : cccc 0110 1010 xxxx xxxx xxxx 0011 xxxx :Q */ |
| 1193 | /* USAT16 : cccc 0110 1110 xxxx xxxx xxxx 0011 xxxx :Q */ |
| 1194 | if ((insn & 0x0fa00030) == 0x06a00010 || |
| 1195 | (insn & 0x0fb000f0) == 0x06a00030) { |
| 1196 | insn &= 0xffff0ff0; /* Rd = r0, Rm = r0 */ |
| 1197 | asi->insn[0] = insn; |
| 1198 | asi->insn_handler = emulate_sat; |
| 1199 | return INSN_GOOD; |
| 1200 | } |
| 1201 | |
| 1202 | /* REV : cccc 0110 1011 xxxx xxxx xxxx 0011 xxxx */ |
| 1203 | /* REV16 : cccc 0110 1011 xxxx xxxx xxxx 1011 xxxx */ |
| 1204 | /* REVSH : cccc 0110 1111 xxxx xxxx xxxx 1011 xxxx */ |
| 1205 | if ((insn & 0x0ff00070) == 0x06b00030 || |
| 1206 | (insn & 0x0ff000f0) == 0x06f000b0) |
| 1207 | return prep_emulate_rd12rm0(insn, asi); |
| 1208 | |
| 1209 | /* SADD16 : cccc 0110 0001 xxxx xxxx xxxx 0001 xxxx :GE */ |
| 1210 | /* SADDSUBX : cccc 0110 0001 xxxx xxxx xxxx 0011 xxxx :GE */ |
| 1211 | /* SSUBADDX : cccc 0110 0001 xxxx xxxx xxxx 0101 xxxx :GE */ |
| 1212 | /* SSUB16 : cccc 0110 0001 xxxx xxxx xxxx 0111 xxxx :GE */ |
| 1213 | /* SADD8 : cccc 0110 0001 xxxx xxxx xxxx 1001 xxxx :GE */ |
| 1214 | /* SSUB8 : cccc 0110 0001 xxxx xxxx xxxx 1111 xxxx :GE */ |
| 1215 | /* QADD16 : cccc 0110 0010 xxxx xxxx xxxx 0001 xxxx : */ |
| 1216 | /* QADDSUBX : cccc 0110 0010 xxxx xxxx xxxx 0011 xxxx : */ |
| 1217 | /* QSUBADDX : cccc 0110 0010 xxxx xxxx xxxx 0101 xxxx : */ |
| 1218 | /* QSUB16 : cccc 0110 0010 xxxx xxxx xxxx 0111 xxxx : */ |
| 1219 | /* QADD8 : cccc 0110 0010 xxxx xxxx xxxx 1001 xxxx : */ |
| 1220 | /* QSUB8 : cccc 0110 0010 xxxx xxxx xxxx 1111 xxxx : */ |
| 1221 | /* SHADD16 : cccc 0110 0011 xxxx xxxx xxxx 0001 xxxx : */ |
| 1222 | /* SHADDSUBX : cccc 0110 0011 xxxx xxxx xxxx 0011 xxxx : */ |
| 1223 | /* SHSUBADDX : cccc 0110 0011 xxxx xxxx xxxx 0101 xxxx : */ |
| 1224 | /* SHSUB16 : cccc 0110 0011 xxxx xxxx xxxx 0111 xxxx : */ |
| 1225 | /* SHADD8 : cccc 0110 0011 xxxx xxxx xxxx 1001 xxxx : */ |
| 1226 | /* SHSUB8 : cccc 0110 0011 xxxx xxxx xxxx 1111 xxxx : */ |
| 1227 | /* UADD16 : cccc 0110 0101 xxxx xxxx xxxx 0001 xxxx :GE */ |
| 1228 | /* UADDSUBX : cccc 0110 0101 xxxx xxxx xxxx 0011 xxxx :GE */ |
| 1229 | /* USUBADDX : cccc 0110 0101 xxxx xxxx xxxx 0101 xxxx :GE */ |
| 1230 | /* USUB16 : cccc 0110 0101 xxxx xxxx xxxx 0111 xxxx :GE */ |
| 1231 | /* UADD8 : cccc 0110 0101 xxxx xxxx xxxx 1001 xxxx :GE */ |
| 1232 | /* USUB8 : cccc 0110 0101 xxxx xxxx xxxx 1111 xxxx :GE */ |
| 1233 | /* UQADD16 : cccc 0110 0110 xxxx xxxx xxxx 0001 xxxx : */ |
| 1234 | /* UQADDSUBX : cccc 0110 0110 xxxx xxxx xxxx 0011 xxxx : */ |
| 1235 | /* UQSUBADDX : cccc 0110 0110 xxxx xxxx xxxx 0101 xxxx : */ |
| 1236 | /* UQSUB16 : cccc 0110 0110 xxxx xxxx xxxx 0111 xxxx : */ |
| 1237 | /* UQADD8 : cccc 0110 0110 xxxx xxxx xxxx 1001 xxxx : */ |
| 1238 | /* UQSUB8 : cccc 0110 0110 xxxx xxxx xxxx 1111 xxxx : */ |
| 1239 | /* UHADD16 : cccc 0110 0111 xxxx xxxx xxxx 0001 xxxx : */ |
| 1240 | /* UHADDSUBX : cccc 0110 0111 xxxx xxxx xxxx 0011 xxxx : */ |
| 1241 | /* UHSUBADDX : cccc 0110 0111 xxxx xxxx xxxx 0101 xxxx : */ |
| 1242 | /* UHSUB16 : cccc 0110 0111 xxxx xxxx xxxx 0111 xxxx : */ |
| 1243 | /* UHADD8 : cccc 0110 0111 xxxx xxxx xxxx 1001 xxxx : */ |
| 1244 | /* UHSUB8 : cccc 0110 0111 xxxx xxxx xxxx 1111 xxxx : */ |
| 1245 | /* PKHBT : cccc 0110 1000 xxxx xxxx xxxx x001 xxxx : */ |
| 1246 | /* PKHTB : cccc 0110 1000 xxxx xxxx xxxx x101 xxxx : */ |
| 1247 | /* SXTAB16 : cccc 0110 1000 xxxx xxxx xxxx 0111 xxxx : */ |
| 1248 | /* SXTB : cccc 0110 1010 xxxx xxxx xxxx 0111 xxxx : */ |
| 1249 | /* SXTAB : cccc 0110 1010 xxxx xxxx xxxx 0111 xxxx : */ |
| 1250 | /* SXTAH : cccc 0110 1011 xxxx xxxx xxxx 0111 xxxx : */ |
| 1251 | /* UXTAB16 : cccc 0110 1100 xxxx xxxx xxxx 0111 xxxx : */ |
| 1252 | /* UXTAB : cccc 0110 1110 xxxx xxxx xxxx 0111 xxxx : */ |
| 1253 | /* UXTAH : cccc 0110 1111 xxxx xxxx xxxx 0111 xxxx : */ |
| 1254 | return prep_emulate_rd12rn16rm0_wflags(insn, asi); |
| 1255 | } |
| 1256 | |
| 1257 | static enum kprobe_insn __kprobes |
| 1258 | space_cccc_0111__1(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 1259 | { |
| 1260 | /* Undef : cccc 0111 1111 xxxx xxxx xxxx 1111 xxxx */ |
| 1261 | if ((insn & 0x0ff000f0) == 0x03f000f0) |
| 1262 | return INSN_REJECTED; |
| 1263 | |
| 1264 | /* USADA8 : cccc 0111 1000 xxxx xxxx xxxx 0001 xxxx */ |
| 1265 | /* USAD8 : cccc 0111 1000 xxxx 1111 xxxx 0001 xxxx */ |
| 1266 | if ((insn & 0x0ff000f0) == 0x07800010) |
| 1267 | return prep_emulate_rd16rn12rs8rm0_wflags(insn, asi); |
| 1268 | |
| 1269 | /* SMLALD : cccc 0111 0100 xxxx xxxx xxxx 00x1 xxxx */ |
| 1270 | /* SMLSLD : cccc 0111 0100 xxxx xxxx xxxx 01x1 xxxx */ |
| 1271 | if ((insn & 0x0ff00090) == 0x07400010) |
| 1272 | return prep_emulate_rdhi16rdlo12rs8rm0_wflags(insn, asi); |
| 1273 | |
| 1274 | /* SMLAD : cccc 0111 0000 xxxx xxxx xxxx 00x1 xxxx :Q */ |
| 1275 | /* SMLSD : cccc 0111 0000 xxxx xxxx xxxx 01x1 xxxx :Q */ |
| 1276 | /* SMMLA : cccc 0111 0101 xxxx xxxx xxxx 00x1 xxxx : */ |
| 1277 | /* SMMLS : cccc 0111 0101 xxxx xxxx xxxx 11x1 xxxx : */ |
| 1278 | if ((insn & 0x0ff00090) == 0x07000010 || |
| 1279 | (insn & 0x0ff000d0) == 0x07500010 || |
| 1280 | (insn & 0x0ff000d0) == 0x075000d0) |
| 1281 | return prep_emulate_rd16rn12rs8rm0_wflags(insn, asi); |
| 1282 | |
| 1283 | /* SMUSD : cccc 0111 0000 xxxx xxxx xxxx 01x1 xxxx : */ |
| 1284 | /* SMUAD : cccc 0111 0000 xxxx 1111 xxxx 00x1 xxxx :Q */ |
| 1285 | /* SMMUL : cccc 0111 0101 xxxx 1111 xxxx 00x1 xxxx : */ |
| 1286 | return prep_emulate_rd16rs8rm0_wflags(insn, asi); |
| 1287 | } |
| 1288 | |
| 1289 | static enum kprobe_insn __kprobes |
| 1290 | space_cccc_01xx(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 1291 | { |
| 1292 | /* LDR : cccc 01xx x0x1 xxxx xxxx xxxx xxxx xxxx */ |
| 1293 | /* LDRB : cccc 01xx x1x1 xxxx xxxx xxxx xxxx xxxx */ |
| 1294 | /* LDRBT : cccc 01x0 x111 xxxx xxxx xxxx xxxx xxxx */ |
| 1295 | /* LDRT : cccc 01x0 x011 xxxx xxxx xxxx xxxx xxxx */ |
| 1296 | /* STR : cccc 01xx x0x0 xxxx xxxx xxxx xxxx xxxx */ |
| 1297 | /* STRB : cccc 01xx x1x0 xxxx xxxx xxxx xxxx xxxx */ |
| 1298 | /* STRBT : cccc 01x0 x110 xxxx xxxx xxxx xxxx xxxx */ |
| 1299 | /* STRT : cccc 01x0 x010 xxxx xxxx xxxx xxxx xxxx */ |
| 1300 | return prep_emulate_ldr_str(insn, asi); |
| 1301 | } |
| 1302 | |
| 1303 | static enum kprobe_insn __kprobes |
| 1304 | space_cccc_100x(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 1305 | { |
| 1306 | /* LDM(2) : cccc 100x x101 xxxx 0xxx xxxx xxxx xxxx */ |
| 1307 | /* LDM(3) : cccc 100x x1x1 xxxx 1xxx xxxx xxxx xxxx */ |
| 1308 | if ((insn & 0x0e708000) == 0x85000000 || |
| 1309 | (insn & 0x0e508000) == 0x85010000) |
| 1310 | return INSN_REJECTED; |
| 1311 | |
| 1312 | /* LDM(1) : cccc 100x x0x1 xxxx xxxx xxxx xxxx xxxx */ |
| 1313 | /* STM(1) : cccc 100x x0x0 xxxx xxxx xxxx xxxx xxxx */ |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1314 | asi->insn_handler = ((insn & 0x108000) == 0x008000) ? /* STM & R15 */ |
| 1315 | simulate_stm1_pc : simulate_ldm1stm1; |
Jon Medhurst | a539f5d | 2011-04-06 11:17:10 +0100 | [diff] [blame^] | 1316 | return INSN_GOOD_NO_SLOT; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | static enum kprobe_insn __kprobes |
| 1320 | space_cccc_101x(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 1321 | { |
| 1322 | /* B : cccc 1010 xxxx xxxx xxxx xxxx xxxx xxxx */ |
| 1323 | /* BL : cccc 1011 xxxx xxxx xxxx xxxx xxxx xxxx */ |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1324 | asi->insn_handler = simulate_bbl; |
Jon Medhurst | a539f5d | 2011-04-06 11:17:10 +0100 | [diff] [blame^] | 1325 | return INSN_GOOD_NO_SLOT; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
| 1328 | static enum kprobe_insn __kprobes |
| 1329 | space_cccc_1100_010x(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 1330 | { |
| 1331 | /* MCRR : cccc 1100 0100 xxxx xxxx xxxx xxxx xxxx : (Rd!=Rn) */ |
| 1332 | /* MRRC : cccc 1100 0101 xxxx xxxx xxxx xxxx xxxx : (Rd!=Rn) */ |
| 1333 | insn &= 0xfff00fff; |
| 1334 | insn |= 0x00001000; /* Rn = r0, Rd = r1 */ |
| 1335 | asi->insn[0] = insn; |
| 1336 | asi->insn_handler = (insn & (1 << 20)) ? emulate_mrrc : emulate_mcrr; |
| 1337 | return INSN_GOOD; |
| 1338 | } |
| 1339 | |
| 1340 | static enum kprobe_insn __kprobes |
| 1341 | space_cccc_110x(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 1342 | { |
| 1343 | /* LDC : cccc 110x xxx1 xxxx xxxx xxxx xxxx xxxx */ |
| 1344 | /* STC : cccc 110x xxx0 xxxx xxxx xxxx xxxx xxxx */ |
| 1345 | insn &= 0xfff0ffff; /* Rn = r0 */ |
| 1346 | asi->insn[0] = insn; |
| 1347 | asi->insn_handler = emulate_ldcstc; |
| 1348 | return INSN_GOOD; |
| 1349 | } |
| 1350 | |
| 1351 | static enum kprobe_insn __kprobes |
| 1352 | space_cccc_111x(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 1353 | { |
| 1354 | /* BKPT : 1110 0001 0010 xxxx xxxx xxxx 0111 xxxx */ |
| 1355 | /* SWI : cccc 1111 xxxx xxxx xxxx xxxx xxxx xxxx */ |
| 1356 | if ((insn & 0xfff000f0) == 0xe1200070 || |
| 1357 | (insn & 0x0f000000) == 0x0f000000) |
| 1358 | return INSN_REJECTED; |
| 1359 | |
| 1360 | /* CDP : cccc 1110 xxxx xxxx xxxx xxxx xxx0 xxxx */ |
| 1361 | if ((insn & 0x0f000010) == 0x0e000000) { |
| 1362 | asi->insn[0] = insn; |
| 1363 | asi->insn_handler = emulate_none; |
| 1364 | return INSN_GOOD; |
| 1365 | } |
| 1366 | |
| 1367 | /* MCR : cccc 1110 xxx0 xxxx xxxx xxxx xxx1 xxxx */ |
| 1368 | /* MRC : cccc 1110 xxx1 xxxx xxxx xxxx xxx1 xxxx */ |
| 1369 | insn &= 0xffff0fff; /* Rd = r0 */ |
| 1370 | asi->insn[0] = insn; |
| 1371 | asi->insn_handler = (insn & (1 << 20)) ? emulate_rd12 : emulate_ird12; |
| 1372 | return INSN_GOOD; |
| 1373 | } |
| 1374 | |
Jon Medhurst | 073090c | 2011-04-06 11:17:09 +0100 | [diff] [blame] | 1375 | static unsigned long __kprobes __check_eq(unsigned long cpsr) |
| 1376 | { |
| 1377 | return cpsr & PSR_Z_BIT; |
| 1378 | } |
| 1379 | |
| 1380 | static unsigned long __kprobes __check_ne(unsigned long cpsr) |
| 1381 | { |
| 1382 | return (~cpsr) & PSR_Z_BIT; |
| 1383 | } |
| 1384 | |
| 1385 | static unsigned long __kprobes __check_cs(unsigned long cpsr) |
| 1386 | { |
| 1387 | return cpsr & PSR_C_BIT; |
| 1388 | } |
| 1389 | |
| 1390 | static unsigned long __kprobes __check_cc(unsigned long cpsr) |
| 1391 | { |
| 1392 | return (~cpsr) & PSR_C_BIT; |
| 1393 | } |
| 1394 | |
| 1395 | static unsigned long __kprobes __check_mi(unsigned long cpsr) |
| 1396 | { |
| 1397 | return cpsr & PSR_N_BIT; |
| 1398 | } |
| 1399 | |
| 1400 | static unsigned long __kprobes __check_pl(unsigned long cpsr) |
| 1401 | { |
| 1402 | return (~cpsr) & PSR_N_BIT; |
| 1403 | } |
| 1404 | |
| 1405 | static unsigned long __kprobes __check_vs(unsigned long cpsr) |
| 1406 | { |
| 1407 | return cpsr & PSR_V_BIT; |
| 1408 | } |
| 1409 | |
| 1410 | static unsigned long __kprobes __check_vc(unsigned long cpsr) |
| 1411 | { |
| 1412 | return (~cpsr) & PSR_V_BIT; |
| 1413 | } |
| 1414 | |
| 1415 | static unsigned long __kprobes __check_hi(unsigned long cpsr) |
| 1416 | { |
| 1417 | cpsr &= ~(cpsr >> 1); /* PSR_C_BIT &= ~PSR_Z_BIT */ |
| 1418 | return cpsr & PSR_C_BIT; |
| 1419 | } |
| 1420 | |
| 1421 | static unsigned long __kprobes __check_ls(unsigned long cpsr) |
| 1422 | { |
| 1423 | cpsr &= ~(cpsr >> 1); /* PSR_C_BIT &= ~PSR_Z_BIT */ |
| 1424 | return (~cpsr) & PSR_C_BIT; |
| 1425 | } |
| 1426 | |
| 1427 | static unsigned long __kprobes __check_ge(unsigned long cpsr) |
| 1428 | { |
| 1429 | cpsr ^= (cpsr << 3); /* PSR_N_BIT ^= PSR_V_BIT */ |
| 1430 | return (~cpsr) & PSR_N_BIT; |
| 1431 | } |
| 1432 | |
| 1433 | static unsigned long __kprobes __check_lt(unsigned long cpsr) |
| 1434 | { |
| 1435 | cpsr ^= (cpsr << 3); /* PSR_N_BIT ^= PSR_V_BIT */ |
| 1436 | return cpsr & PSR_N_BIT; |
| 1437 | } |
| 1438 | |
| 1439 | static unsigned long __kprobes __check_gt(unsigned long cpsr) |
| 1440 | { |
| 1441 | unsigned long temp = cpsr ^ (cpsr << 3); /* PSR_N_BIT ^= PSR_V_BIT */ |
| 1442 | temp |= (cpsr << 1); /* PSR_N_BIT |= PSR_Z_BIT */ |
| 1443 | return (~temp) & PSR_N_BIT; |
| 1444 | } |
| 1445 | |
| 1446 | static unsigned long __kprobes __check_le(unsigned long cpsr) |
| 1447 | { |
| 1448 | unsigned long temp = cpsr ^ (cpsr << 3); /* PSR_N_BIT ^= PSR_V_BIT */ |
| 1449 | temp |= (cpsr << 1); /* PSR_N_BIT |= PSR_Z_BIT */ |
| 1450 | return temp & PSR_N_BIT; |
| 1451 | } |
| 1452 | |
| 1453 | static unsigned long __kprobes __check_al(unsigned long cpsr) |
| 1454 | { |
| 1455 | return true; |
| 1456 | } |
| 1457 | |
| 1458 | static kprobe_check_cc * const condition_checks[16] = { |
| 1459 | &__check_eq, &__check_ne, &__check_cs, &__check_cc, |
| 1460 | &__check_mi, &__check_pl, &__check_vs, &__check_vc, |
| 1461 | &__check_hi, &__check_ls, &__check_ge, &__check_lt, |
| 1462 | &__check_gt, &__check_le, &__check_al, &__check_al |
| 1463 | }; |
| 1464 | |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1465 | /* Return: |
| 1466 | * INSN_REJECTED If instruction is one not allowed to kprobe, |
| 1467 | * INSN_GOOD If instruction is supported and uses instruction slot, |
| 1468 | * INSN_GOOD_NO_SLOT If instruction is supported but doesn't use its slot. |
| 1469 | * |
| 1470 | * For instructions we don't want to kprobe (INSN_REJECTED return result): |
| 1471 | * These are generally ones that modify the processor state making |
| 1472 | * them "hard" to simulate such as switches processor modes or |
| 1473 | * make accesses in alternate modes. Any of these could be simulated |
| 1474 | * if the work was put into it, but low return considering they |
| 1475 | * should also be very rare. |
| 1476 | */ |
| 1477 | enum kprobe_insn __kprobes |
| 1478 | arm_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi) |
| 1479 | { |
Jon Medhurst | 073090c | 2011-04-06 11:17:09 +0100 | [diff] [blame] | 1480 | asi->insn_check_cc = condition_checks[insn>>28]; |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1481 | asi->insn[1] = KPROBE_RETURN_INSTRUCTION; |
| 1482 | |
| 1483 | if ((insn & 0xf0000000) == 0xf0000000) { |
| 1484 | |
| 1485 | return space_1111(insn, asi); |
| 1486 | |
| 1487 | } else if ((insn & 0x0e000000) == 0x00000000) { |
| 1488 | |
| 1489 | return space_cccc_000x(insn, asi); |
| 1490 | |
| 1491 | } else if ((insn & 0x0e000000) == 0x02000000) { |
| 1492 | |
| 1493 | return space_cccc_001x(insn, asi); |
| 1494 | |
| 1495 | } else if ((insn & 0x0f000010) == 0x06000010) { |
| 1496 | |
| 1497 | return space_cccc_0110__1(insn, asi); |
| 1498 | |
| 1499 | } else if ((insn & 0x0f000010) == 0x07000010) { |
| 1500 | |
| 1501 | return space_cccc_0111__1(insn, asi); |
| 1502 | |
| 1503 | } else if ((insn & 0x0c000000) == 0x04000000) { |
| 1504 | |
| 1505 | return space_cccc_01xx(insn, asi); |
| 1506 | |
| 1507 | } else if ((insn & 0x0e000000) == 0x08000000) { |
| 1508 | |
| 1509 | return space_cccc_100x(insn, asi); |
| 1510 | |
| 1511 | } else if ((insn & 0x0e000000) == 0x0a000000) { |
| 1512 | |
| 1513 | return space_cccc_101x(insn, asi); |
| 1514 | |
| 1515 | } else if ((insn & 0x0fe00000) == 0x0c400000) { |
| 1516 | |
| 1517 | return space_cccc_1100_010x(insn, asi); |
| 1518 | |
Nicolas Pitre | 5a5af73 | 2011-02-21 04:37:20 +0100 | [diff] [blame] | 1519 | } else if ((insn & 0x0e000000) == 0x0c000000) { |
Quentin Barnes | 35aa1df | 2007-06-11 22:20:10 +0000 | [diff] [blame] | 1520 | |
| 1521 | return space_cccc_110x(insn, asi); |
| 1522 | |
| 1523 | } |
| 1524 | |
| 1525 | return space_cccc_111x(insn, asi); |
| 1526 | } |
| 1527 | |
| 1528 | void __init arm_kprobe_decode_init(void) |
| 1529 | { |
| 1530 | find_str_pc_offset(); |
| 1531 | } |
| 1532 | |
| 1533 | |
| 1534 | /* |
| 1535 | * All ARM instructions listed below. |
| 1536 | * |
| 1537 | * Instructions and their general purpose registers are given. |
| 1538 | * If a particular register may not use R15, it is prefixed with a "!". |
| 1539 | * If marked with a "*" means the value returned by reading R15 |
| 1540 | * is implementation defined. |
| 1541 | * |
| 1542 | * ADC/ADD/AND/BIC/CMN/CMP/EOR/MOV/MVN/ORR/RSB/RSC/SBC/SUB/TEQ |
| 1543 | * TST: Rd, Rn, Rm, !Rs |
| 1544 | * BX: Rm |
| 1545 | * BLX(2): !Rm |
| 1546 | * BX: Rm (R15 legal, but discouraged) |
| 1547 | * BXJ: !Rm, |
| 1548 | * CLZ: !Rd, !Rm |
| 1549 | * CPY: Rd, Rm |
| 1550 | * LDC/2,STC/2 immediate offset & unindex: Rn |
| 1551 | * LDC/2,STC/2 immediate pre/post-indexed: !Rn |
| 1552 | * LDM(1/3): !Rn, register_list |
| 1553 | * LDM(2): !Rn, !register_list |
| 1554 | * LDR,STR,PLD immediate offset: Rd, Rn |
| 1555 | * LDR,STR,PLD register offset: Rd, Rn, !Rm |
| 1556 | * LDR,STR,PLD scaled register offset: Rd, !Rn, !Rm |
| 1557 | * LDR,STR immediate pre/post-indexed: Rd, !Rn |
| 1558 | * LDR,STR register pre/post-indexed: Rd, !Rn, !Rm |
| 1559 | * LDR,STR scaled register pre/post-indexed: Rd, !Rn, !Rm |
| 1560 | * LDRB,STRB immediate offset: !Rd, Rn |
| 1561 | * LDRB,STRB register offset: !Rd, Rn, !Rm |
| 1562 | * LDRB,STRB scaled register offset: !Rd, !Rn, !Rm |
| 1563 | * LDRB,STRB immediate pre/post-indexed: !Rd, !Rn |
| 1564 | * LDRB,STRB register pre/post-indexed: !Rd, !Rn, !Rm |
| 1565 | * LDRB,STRB scaled register pre/post-indexed: !Rd, !Rn, !Rm |
| 1566 | * LDRT,LDRBT,STRBT immediate pre/post-indexed: !Rd, !Rn |
| 1567 | * LDRT,LDRBT,STRBT register pre/post-indexed: !Rd, !Rn, !Rm |
| 1568 | * LDRT,LDRBT,STRBT scaled register pre/post-indexed: !Rd, !Rn, !Rm |
| 1569 | * LDRH/SH/SB/D,STRH/SH/SB/D immediate offset: !Rd, Rn |
| 1570 | * LDRH/SH/SB/D,STRH/SH/SB/D register offset: !Rd, Rn, !Rm |
| 1571 | * LDRH/SH/SB/D,STRH/SH/SB/D immediate pre/post-indexed: !Rd, !Rn |
| 1572 | * LDRH/SH/SB/D,STRH/SH/SB/D register pre/post-indexed: !Rd, !Rn, !Rm |
| 1573 | * LDREX: !Rd, !Rn |
| 1574 | * MCR/2: !Rd |
| 1575 | * MCRR/2,MRRC/2: !Rd, !Rn |
| 1576 | * MLA: !Rd, !Rn, !Rm, !Rs |
| 1577 | * MOV: Rd |
| 1578 | * MRC/2: !Rd (if Rd==15, only changes cond codes, not the register) |
| 1579 | * MRS,MSR: !Rd |
| 1580 | * MUL: !Rd, !Rm, !Rs |
| 1581 | * PKH{BT,TB}: !Rd, !Rn, !Rm |
| 1582 | * QDADD,[U]QADD/16/8/SUBX: !Rd, !Rm, !Rn |
| 1583 | * QDSUB,[U]QSUB/16/8/ADDX: !Rd, !Rm, !Rn |
| 1584 | * REV/16/SH: !Rd, !Rm |
| 1585 | * RFE: !Rn |
| 1586 | * {S,U}[H]ADD{16,8,SUBX},{S,U}[H]SUB{16,8,ADDX}: !Rd, !Rn, !Rm |
| 1587 | * SEL: !Rd, !Rn, !Rm |
| 1588 | * SMLA<x><y>,SMLA{D,W<y>},SMLSD,SMML{A,S}: !Rd, !Rn, !Rm, !Rs |
| 1589 | * SMLAL<x><y>,SMLA{D,LD},SMLSLD,SMMULL,SMULW<y>: !RdHi, !RdLo, !Rm, !Rs |
| 1590 | * SMMUL,SMUAD,SMUL<x><y>,SMUSD: !Rd, !Rm, !Rs |
| 1591 | * SSAT/16: !Rd, !Rm |
| 1592 | * STM(1/2): !Rn, register_list* (R15 in reg list not recommended) |
| 1593 | * STRT immediate pre/post-indexed: Rd*, !Rn |
| 1594 | * STRT register pre/post-indexed: Rd*, !Rn, !Rm |
| 1595 | * STRT scaled register pre/post-indexed: Rd*, !Rn, !Rm |
| 1596 | * STREX: !Rd, !Rn, !Rm |
| 1597 | * SWP/B: !Rd, !Rn, !Rm |
| 1598 | * {S,U}XTA{B,B16,H}: !Rd, !Rn, !Rm |
| 1599 | * {S,U}XT{B,B16,H}: !Rd, !Rm |
| 1600 | * UM{AA,LA,UL}L: !RdHi, !RdLo, !Rm, !Rs |
| 1601 | * USA{D8,A8,T,T16}: !Rd, !Rm, !Rs |
| 1602 | * |
| 1603 | * May transfer control by writing R15 (possible mode changes or alternate |
| 1604 | * mode accesses marked by "*"): |
| 1605 | * ALU op (* with s-bit), B, BL, BKPT, BLX(1/2), BX, BXJ, CPS*, CPY, |
| 1606 | * LDM(1), LDM(2/3)*, LDR, MOV, RFE*, SWI* |
| 1607 | * |
| 1608 | * Instructions that do not take general registers, nor transfer control: |
| 1609 | * CDP/2, SETEND, SRS* |
| 1610 | */ |