aboutsummaryrefslogtreecommitdiff
path: root/arch/arm64/kernel/probes-condn-check.c
blob: e68aa0c86b94d277dd344e0d221e5edbceb4c031 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * arch/arm64/kernel/probes-condn-check.c
 *
 * Copyright (C) 2013 Linaro Limited
 *
 * Copied from: arch/arm/kernel/kprobes-common.c
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * Description:
 *
 *  AArch64 and AArch32 shares same conditional(CNZV) flags encoding.
 *  This file implements conditional check helpers compatible with
 *  both AArch64 and AArch32 modes. Uprobes on v8 can handle both 32-bit
 *  & 64-bit user-space instructions, so we abstract the common functions
 *  in this file. While AArch64 and AArch32 specific instruction handling
 *  are implemented in separate files, this file contains common bits.
 */
#include <linux/kernel.h>
#include <linux/module.h>
#include <asm/probes.h>

static unsigned long __kprobes __check_eq(unsigned long pstate)
{
	return pstate & PSR_Z_BIT;
}

static unsigned long __kprobes __check_ne(unsigned long pstate)
{
	return (~pstate) & PSR_Z_BIT;
}

static unsigned long __kprobes __check_cs(unsigned long pstate)
{
	return pstate & PSR_C_BIT;
}

static unsigned long __kprobes __check_cc(unsigned long pstate)
{
	return (~pstate) & PSR_C_BIT;
}

static unsigned long __kprobes __check_mi(unsigned long pstate)
{
	return pstate & PSR_N_BIT;
}

static unsigned long __kprobes __check_pl(unsigned long pstate)
{
	return (~pstate) & PSR_N_BIT;
}

static unsigned long __kprobes __check_vs(unsigned long pstate)
{
	return pstate & PSR_V_BIT;
}

static unsigned long __kprobes __check_vc(unsigned long pstate)
{
	return (~pstate) & PSR_V_BIT;
}

static unsigned long __kprobes __check_hi(unsigned long pstate)
{
	pstate &= ~(pstate >> 1);	/* PSR_C_BIT &= ~PSR_Z_BIT */
	return pstate & PSR_C_BIT;
}

static unsigned long __kprobes __check_ls(unsigned long pstate)
{
	pstate &= ~(pstate >> 1);	/* PSR_C_BIT &= ~PSR_Z_BIT */
	return (~pstate) & PSR_C_BIT;
}

static unsigned long __kprobes __check_ge(unsigned long pstate)
{
	pstate ^= (pstate << 3);	/* PSR_N_BIT ^= PSR_V_BIT */
	return (~pstate) & PSR_N_BIT;
}

static unsigned long __kprobes __check_lt(unsigned long pstate)
{
	pstate ^= (pstate << 3);	/* PSR_N_BIT ^= PSR_V_BIT */
	return pstate & PSR_N_BIT;
}

static unsigned long __kprobes __check_gt(unsigned long pstate)
{
	/*PSR_N_BIT ^= PSR_V_BIT */
	unsigned long temp = pstate ^ (pstate << 3);

	temp |= (pstate << 1);	/*PSR_N_BIT |= PSR_Z_BIT */
	return (~temp) & PSR_N_BIT;
}

static unsigned long __kprobes __check_le(unsigned long pstate)
{
	/*PSR_N_BIT ^= PSR_V_BIT */
	unsigned long temp = pstate ^ (pstate << 3);

	temp |= (pstate << 1);	/*PSR_N_BIT |= PSR_Z_BIT */
	return temp & PSR_N_BIT;
}

static unsigned long __kprobes __check_al(unsigned long pstate)
{
	return true;
}

kprobes_pstate_check_t * const kprobe_condition_checks[16] = {
	&__check_eq, &__check_ne, &__check_cs, &__check_cc,
	&__check_mi, &__check_pl, &__check_vs, &__check_vc,
	&__check_hi, &__check_ls, &__check_ge, &__check_lt,
	&__check_gt, &__check_le, &__check_al, &__check_al
};