preliminaryDataProcessing.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * arch/arm/kernel/kprobes.h
  3. *
  4. * Copyright (C) 2011 Jon Medhurst <tixy@yxit.co.uk>.
  5. *
  6. * Some contents moved here from arch/arm/include/asm/kprobes.h which is
  7. * Copyright (C) 2006, 2007 Motorola Inc.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  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 GNU
  16. * General Public License for more details.
  17. */
  18. #ifndef _ARM_KERNEL_KPROBES_H
  19. #define _ARM_KERNEL_KPROBES_H
  20. /*
  21. * These undefined instructions must be unique and
  22. * reserved solely for kprobes' use.
  23. */
  24. #define KPROBE_ARM_BREAKPOINT_INSTRUCTION 0x07f001f8
  25. #define KPROBE_THUMB16_BREAKPOINT_INSTRUCTION 0xde18
  26. #define KPROBE_THUMB32_BREAKPOINT_INSTRUCTION 0xf7f0a018
  27. enum kprobe_insn {
  28. INSN_REJECTED,
  29. INSN_GOOD,
  30. INSN_GOOD_NO_SLOT
  31. };
  32. typedef enum kprobe_insn (kprobe_decode_insn_t)(kprobe_opcode_t,
  33. struct arch_specific_insn *);
  34. #ifdef CONFIG_THUMB2_KERNEL
  35. enum kprobe_insn thumb16_kprobe_decode_insn(kprobe_opcode_t,
  36. struct arch_specific_insn *);
  37. enum kprobe_insn thumb32_kprobe_decode_insn(kprobe_opcode_t,
  38. struct arch_specific_insn *);
  39. #else /* !CONFIG_THUMB2_KERNEL */
  40. enum kprobe_insn arm_kprobe_decode_insn(kprobe_opcode_t,
  41. struct arch_specific_insn *);
  42. #endif
  43. void __init arm_kprobe_decode_init(void);
  44. extern kprobe_check_cc * const kprobe_condition_checks[16];
  45. #if __LINUX_ARM_ARCH__ >= 7
  46. /* str_pc_offset is architecturally defined from ARMv7 onwards */
  47. #define str_pc_offset 8
  48. #define find_str_pc_offset()
  49. #else /* __LINUX_ARM_ARCH__ < 7 */
  50. /* We need a run-time check to determine str_pc_offset */
  51. extern int str_pc_offset;
  52. void __init find_str_pc_offset(void);
  53. #endif
  54. /*
  55. * Update ITSTATE after normal execution of an IT block instruction.
  56. *
  57. * The 8 IT state bits are split into two parts in CPSR:
  58. * ITSTATE<1:0> are in CPSR<26:25>
  59. * ITSTATE<7:2> are in CPSR<15:10>
  60. */
  61. static inline unsigned long it_advance(unsigned long cpsr)
  62. {
  63. if ((cpsr & 0x06000400) == 0) {
  64. /* ITSTATE<2:0> == 0 means end of IT block, so clear IT state */
  65. cpsr &= ~PSR_IT_MASK;
  66. } else {
  67. /* We need to shift left ITSTATE<4:0> */
  68. const unsigned long mask = 0x06001c00; /* Mask ITSTATE<4:0> */
  69. unsigned long it = cpsr & mask;
  70. it <<= 1;
  71. it |= it >> (27 - 10); /* Carry ITSTATE<2> to correct place */
  72. it &= mask;
  73. cpsr &= ~mask;
  74. cpsr |= it;
  75. }
  76. return cpsr;
  77. }
  78. static inline void __kprobes bx_write_pc(long pcv, struct pt_regs *regs)
  79. {
  80. long cpsr = regs->ARM_cpsr;
  81. if (pcv & 0x1) {
  82. cpsr |= PSR_T_BIT;
  83. pcv &= ~0x1;
  84. } else {
  85. cpsr &= ~PSR_T_BIT;
  86. pcv &= ~0x2; /* Avoid UNPREDICTABLE address allignment */
  87. }
  88. regs->ARM_cpsr = cpsr;
  89. regs->ARM_pc = pcv;
  90. }
  91. #if __LINUX_ARM_ARCH__ >= 6
  92. /* Kernels built for >= ARMv6 should never run on <= ARMv5 hardware, so... */
  93. #define load_write_pc_interworks true
  94. #define test_load_write_pc_interworking()
  95. #else /* __LINUX_ARM_ARCH__ < 6 */
  96. /* We need run-time testing to determine if load_write_pc() should interwork. */
  97. extern bool load_write_pc_interworks;
  98. void __init test_load_write_pc_interworking(void);
  99. #endif
  100. static inline void __kprobes load_write_pc(long pcv, struct pt_regs *regs)
  101. {
  102. if (load_write_pc_interworks)
  103. bx_write_pc(pcv, regs);
  104. else
  105. regs->ARM_pc = pcv;
  106. }