checkers-thumb.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * arch/arm/probes/kprobes/checkers-thumb.c
  3. *
  4. * Copyright (C) 2014 Huawei 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. #include <linux/kernel.h>
  16. #include "../decode.h"
  17. #include "../decode-thumb.h"
  18. #include "checkers.h"
  19. static enum probes_insn __kprobes t32_check_stack(probes_opcode_t insn,
  20. struct arch_probes_insn *asi,
  21. const struct decode_header *h)
  22. {
  23. /*
  24. * PROBES_T32_LDMSTM, PROBES_T32_LDRDSTRD and PROBES_T32_LDRSTR
  25. * may get here. Simply mark all normal insns as STACK_USE_NONE.
  26. */
  27. static const union decode_item table[] = {
  28. /*
  29. * First, filter out all ldr insns to make our life easier.
  30. * Following load insns may come here:
  31. * LDM, LDRD, LDR.
  32. * In T32 encoding, bit 20 is enough for distinguishing
  33. * load and store. All load insns have this bit set, when
  34. * all store insns have this bit clear.
  35. */
  36. DECODE_CUSTOM (0x00100000, 0x00100000, STACK_USE_NONE),
  37. /*
  38. * Mark all 'STR{,B,H}, Rt, [Rn, Rm]' as STACK_USE_UNKNOWN
  39. * if Rn or Rm is SP. T32 doesn't encode STRD.
  40. */
  41. /* xx | Rn | Rt | | Rm |*/
  42. /* STR (register) 1111 1000 0100 xxxx xxxx 0000 00xx xxxx */
  43. /* STRB (register) 1111 1000 0000 xxxx xxxx 0000 00xx xxxx */
  44. /* STRH (register) 1111 1000 0010 xxxx xxxx 0000 00xx xxxx */
  45. /* INVALID INSN 1111 1000 0110 xxxx xxxx 0000 00xx xxxx */
  46. /* By Introducing INVALID INSN, bit 21 and 22 can be ignored. */
  47. DECODE_OR (0xff9f0fc0, 0xf80d0000),
  48. DECODE_CUSTOM (0xff900fcf, 0xf800000d, STACK_USE_UNKNOWN),
  49. /* xx | Rn | Rt | PUW| imm8 |*/
  50. /* STR (imm 8) 1111 1000 0100 1101 xxxx 110x xxxx xxxx */
  51. /* STRB (imm 8) 1111 1000 0000 1101 xxxx 110x xxxx xxxx */
  52. /* STRH (imm 8) 1111 1000 0010 1101 xxxx 110x xxxx xxxx */
  53. /* INVALID INSN 1111 1000 0110 1101 xxxx 110x xxxx xxxx */
  54. /* Only consider U == 0 and P == 1: strx rx, [sp, #-<imm>] */
  55. DECODE_CUSTOM (0xff9f0e00, 0xf80d0c00, STACK_USE_FIXED_0XX),
  56. /* For STR{,B,H} (imm 12), offset is always positive, so ignore them. */
  57. /* P U W | Rn | Rt | Rt2| imm8 |*/
  58. /* STRD (immediate) 1110 1001 01x0 1101 xxxx xxxx xxxx xxxx */
  59. /*
  60. * Only consider U == 0 and P == 1.
  61. * Also note that STRD in T32 encoding is special:
  62. * imm = ZeroExtend(imm8:'00', 32)
  63. */
  64. DECODE_CUSTOM (0xffdf0000, 0xe94d0000, STACK_USE_T32STRD),
  65. /* | Rn | */
  66. /* STMDB 1110 1001 00x0 1101 xxxx xxxx xxxx xxxx */
  67. DECODE_CUSTOM (0xffdf0000, 0xe90d0000, STACK_USE_STMDX),
  68. /* fall through */
  69. DECODE_CUSTOM (0, 0, STACK_USE_NONE),
  70. DECODE_END
  71. };
  72. return probes_decode_insn(insn, asi, table, false, false, stack_check_actions, NULL);
  73. }
  74. const struct decode_checker t32_stack_checker[NUM_PROBES_T32_ACTIONS] = {
  75. [PROBES_T32_LDMSTM] = {.checker = t32_check_stack},
  76. [PROBES_T32_LDRDSTRD] = {.checker = t32_check_stack},
  77. [PROBES_T32_LDRSTR] = {.checker = t32_check_stack},
  78. };
  79. /*
  80. * See following comments. This insn must be 'push'.
  81. */
  82. static enum probes_insn __kprobes t16_check_stack(probes_opcode_t insn,
  83. struct arch_probes_insn *asi,
  84. const struct decode_header *h)
  85. {
  86. unsigned int reglist = insn & 0x1ff;
  87. asi->stack_space = hweight32(reglist) * 4;
  88. return INSN_GOOD;
  89. }
  90. /*
  91. * T16 encoding is simple: only the 'push' insn can need extra stack space.
  92. * Other insns, like str, can only use r0-r7 as Rn.
  93. */
  94. const struct decode_checker t16_stack_checker[NUM_PROBES_T16_ACTIONS] = {
  95. [PROBES_T16_PUSH] = {.checker = t16_check_stack},
  96. };