Commit | Line | Data |
---|---|---|
0ab4c02d JM |
1 | /* |
2 | * arch/arm/kernel/kprobes-common.c | |
3 | * | |
4 | * Copyright (C) 2011 Jon Medhurst <tixy@yxit.co.uk>. | |
5 | * | |
6c8df330 JM |
6 | * Some contents moved here from arch/arm/include/asm/kprobes-arm.c which is |
7 | * Copyright (C) 2006, 2007 Motorola Inc. | |
8 | * | |
0ab4c02d JM |
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 | ||
14 | #include <linux/kernel.h> | |
15 | #include <linux/kprobes.h> | |
16 | ||
17 | #include "kprobes.h" | |
18 | ||
19 | ||
6c8df330 JM |
20 | /* |
21 | * For STR and STM instructions, an ARM core may choose to use either | |
22 | * a +8 or a +12 displacement from the current instruction's address. | |
23 | * Whichever value is chosen for a given core, it must be the same for | |
24 | * both instructions and may not change. This function measures it. | |
25 | */ | |
26 | ||
27 | int str_pc_offset; | |
28 | ||
29 | void __init find_str_pc_offset(void) | |
30 | { | |
31 | int addr, scratch, ret; | |
32 | ||
33 | __asm__ ( | |
34 | "sub %[ret], pc, #4 \n\t" | |
35 | "str pc, %[addr] \n\t" | |
36 | "ldr %[scr], %[addr] \n\t" | |
37 | "sub %[ret], %[scr], %[ret] \n\t" | |
38 | : [ret] "=r" (ret), [scr] "=r" (scratch), [addr] "+m" (addr)); | |
39 | ||
40 | str_pc_offset = ret; | |
41 | } | |
42 | ||
43 | ||
44 | void __init arm_kprobe_decode_init(void) | |
45 | { | |
46 | find_str_pc_offset(); | |
47 | } | |
48 | ||
49 | ||
0ab4c02d JM |
50 | static unsigned long __kprobes __check_eq(unsigned long cpsr) |
51 | { | |
52 | return cpsr & PSR_Z_BIT; | |
53 | } | |
54 | ||
55 | static unsigned long __kprobes __check_ne(unsigned long cpsr) | |
56 | { | |
57 | return (~cpsr) & PSR_Z_BIT; | |
58 | } | |
59 | ||
60 | static unsigned long __kprobes __check_cs(unsigned long cpsr) | |
61 | { | |
62 | return cpsr & PSR_C_BIT; | |
63 | } | |
64 | ||
65 | static unsigned long __kprobes __check_cc(unsigned long cpsr) | |
66 | { | |
67 | return (~cpsr) & PSR_C_BIT; | |
68 | } | |
69 | ||
70 | static unsigned long __kprobes __check_mi(unsigned long cpsr) | |
71 | { | |
72 | return cpsr & PSR_N_BIT; | |
73 | } | |
74 | ||
75 | static unsigned long __kprobes __check_pl(unsigned long cpsr) | |
76 | { | |
77 | return (~cpsr) & PSR_N_BIT; | |
78 | } | |
79 | ||
80 | static unsigned long __kprobes __check_vs(unsigned long cpsr) | |
81 | { | |
82 | return cpsr & PSR_V_BIT; | |
83 | } | |
84 | ||
85 | static unsigned long __kprobes __check_vc(unsigned long cpsr) | |
86 | { | |
87 | return (~cpsr) & PSR_V_BIT; | |
88 | } | |
89 | ||
90 | static unsigned long __kprobes __check_hi(unsigned long cpsr) | |
91 | { | |
92 | cpsr &= ~(cpsr >> 1); /* PSR_C_BIT &= ~PSR_Z_BIT */ | |
93 | return cpsr & PSR_C_BIT; | |
94 | } | |
95 | ||
96 | static unsigned long __kprobes __check_ls(unsigned long cpsr) | |
97 | { | |
98 | cpsr &= ~(cpsr >> 1); /* PSR_C_BIT &= ~PSR_Z_BIT */ | |
99 | return (~cpsr) & PSR_C_BIT; | |
100 | } | |
101 | ||
102 | static unsigned long __kprobes __check_ge(unsigned long cpsr) | |
103 | { | |
104 | cpsr ^= (cpsr << 3); /* PSR_N_BIT ^= PSR_V_BIT */ | |
105 | return (~cpsr) & PSR_N_BIT; | |
106 | } | |
107 | ||
108 | static unsigned long __kprobes __check_lt(unsigned long cpsr) | |
109 | { | |
110 | cpsr ^= (cpsr << 3); /* PSR_N_BIT ^= PSR_V_BIT */ | |
111 | return cpsr & PSR_N_BIT; | |
112 | } | |
113 | ||
114 | static unsigned long __kprobes __check_gt(unsigned long cpsr) | |
115 | { | |
116 | unsigned long temp = cpsr ^ (cpsr << 3); /* PSR_N_BIT ^= PSR_V_BIT */ | |
117 | temp |= (cpsr << 1); /* PSR_N_BIT |= PSR_Z_BIT */ | |
118 | return (~temp) & PSR_N_BIT; | |
119 | } | |
120 | ||
121 | static unsigned long __kprobes __check_le(unsigned long cpsr) | |
122 | { | |
123 | unsigned long temp = cpsr ^ (cpsr << 3); /* PSR_N_BIT ^= PSR_V_BIT */ | |
124 | temp |= (cpsr << 1); /* PSR_N_BIT |= PSR_Z_BIT */ | |
125 | return temp & PSR_N_BIT; | |
126 | } | |
127 | ||
128 | static unsigned long __kprobes __check_al(unsigned long cpsr) | |
129 | { | |
130 | return true; | |
131 | } | |
132 | ||
133 | kprobe_check_cc * const kprobe_condition_checks[16] = { | |
134 | &__check_eq, &__check_ne, &__check_cs, &__check_cc, | |
135 | &__check_mi, &__check_pl, &__check_vs, &__check_vc, | |
136 | &__check_hi, &__check_ls, &__check_ge, &__check_lt, | |
137 | &__check_gt, &__check_le, &__check_al, &__check_al | |
138 | }; |