blob: 973c3eb1243ab9be42e54b728d0a987866aa360b [file] [log] [blame]
Jon Medhurst24371702011-04-19 17:56:58 +01001/*
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
11#include <linux/kernel.h>
12#include <linux/kprobes.h>
13
14#include "kprobes.h"
15
Jon Medhursteaf4f33f2011-04-20 19:29:52 +010016
17/*
18 * True if current instruction is in an IT block.
19 */
20#define in_it_block(cpsr) ((cpsr & 0x06000c00) != 0x00000000)
21
22/*
23 * Return the condition code to check for the currently executing instruction.
24 * This is in ITSTATE<7:4> which is in CPSR<15:12> but is only valid if
25 * in_it_block returns true.
26 */
27#define current_cond(cpsr) ((cpsr >> 12) & 0xf)
28
29static unsigned long __kprobes thumb_check_cc(unsigned long cpsr)
30{
31 if (unlikely(in_it_block(cpsr)))
32 return kprobe_condition_checks[current_cond(cpsr)](cpsr);
33 return true;
34}
35
Jon Medhurstc6a7d972011-06-09 12:11:27 +010036static void __kprobes thumb16_singlestep(struct kprobe *p, struct pt_regs *regs)
37{
38 regs->ARM_pc += 2;
39 p->ainsn.insn_handler(p, regs);
40 regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
41}
42
43static void __kprobes thumb32_singlestep(struct kprobe *p, struct pt_regs *regs)
44{
45 regs->ARM_pc += 4;
46 p->ainsn.insn_handler(p, regs);
47 regs->ARM_cpsr = it_advance(regs->ARM_cpsr);
48}
49
Jon Medhurst24371702011-04-19 17:56:58 +010050enum kprobe_insn __kprobes
51thumb16_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
52{
Jon Medhurstc6a7d972011-06-09 12:11:27 +010053 asi->insn_singlestep = thumb16_singlestep;
Jon Medhursteaf4f33f2011-04-20 19:29:52 +010054 asi->insn_check_cc = thumb_check_cc;
Jon Medhurst24371702011-04-19 17:56:58 +010055 return INSN_REJECTED;
56}
57
58enum kprobe_insn __kprobes
59thumb32_kprobe_decode_insn(kprobe_opcode_t insn, struct arch_specific_insn *asi)
60{
Jon Medhurstc6a7d972011-06-09 12:11:27 +010061 asi->insn_singlestep = thumb32_singlestep;
Jon Medhursteaf4f33f2011-04-20 19:29:52 +010062 asi->insn_check_cc = thumb_check_cc;
Jon Medhurst24371702011-04-19 17:56:58 +010063 return INSN_REJECTED;
64}