kprobes-thumb.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * arch/arm/kernel/kprobes-thumb.c
  3. *
  4. * Copyright (C) 2011 Jon Medhurst <tixy@yxit.co.uk>.
  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. #include <linux/kernel.h>
  11. #include <linux/kprobes.h>
  12. #include "kprobes.h"
  13. /*
  14. * True if current instruction is in an IT block.
  15. */
  16. #define in_it_block(cpsr) ((cpsr & 0x06000c00) != 0x00000000)
  17. /*
  18. * Return the condition code to check for the currently executing instruction.
  19. * This is in ITSTATE<7:4> which is in CPSR<15:12> but is only valid if
  20. * in_it_block returns true.
  21. */
  22. #define current_cond(cpsr) ((cpsr >> 12) & 0xf)
  23. static unsigned long __kprobes thumb_check_cc(unsigned long cpsr)
  24. {
  25. if (unlikely(in_it_block(cpsr)))
  26. return kprobe_condition_checks[current_cond(cpsr)](cpsr);
  27. return true;
  28. }
  29. static void __kprobes thumb16_singlestep(struct kprobe *p, struct pt_regs *regs)
  30. {
  31. regs->ARM_pc += 2;
  32. p->ainsn.insn_handler(p, regs);
  33. regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
  34. }
  35. static void __kprobes thumb32_singlestep(struct kprobe *p, struct pt_regs *regs)
  36. {
  37. regs->ARM_pc += 4;
  38. p->ainsn.insn_handler(p, regs);
  39. regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
  40. }
  41. enum kprobe_insn __kprobes
  42. thumb16_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  43. {
  44. asi->insn_singlestep = thumb16_singlestep;
  45. asi->insn_check_cc = thumb_check_cc;
  46. return INSN_REJECTED;
  47. }
  48. enum kprobe_insn __kprobes
  49. thumb32_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
  50. {
  51. asi->insn_singlestep = thumb32_singlestep;
  52. asi->insn_check_cc = thumb_check_cc;
  53. return INSN_REJECTED;
  54. }