This source file includes following definitions.
- kvm_condition_valid32
- kvm_adjust_itstate
- kvm_skip_instr32
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/kvm_host.h>
14 #include <asm/kvm_emulate.h>
15 #include <asm/kvm_hyp.h>
16
17
18
19
20
21
22
23
24
25 static const unsigned short cc_map[16] = {
26 0xF0F0,
27 0x0F0F,
28 0xCCCC,
29 0x3333,
30 0xFF00,
31 0x00FF,
32 0xAAAA,
33 0x5555,
34 0x0C0C,
35 0xF3F3,
36 0xAA55,
37 0x55AA,
38 0x0A05,
39 0xF5FA,
40 0xFFFF,
41 0
42 };
43
44
45
46
47 bool __hyp_text kvm_condition_valid32(const struct kvm_vcpu *vcpu)
48 {
49 unsigned long cpsr;
50 u32 cpsr_cond;
51 int cond;
52
53
54 if (kvm_vcpu_get_hsr(vcpu) >> 30)
55 return true;
56
57
58 cond = kvm_vcpu_get_condition(vcpu);
59 if (cond == 0xE)
60 return true;
61
62 cpsr = *vcpu_cpsr(vcpu);
63
64 if (cond < 0) {
65
66 unsigned long it;
67
68 it = ((cpsr >> 8) & 0xFC) | ((cpsr >> 25) & 0x3);
69
70
71 if (it == 0)
72 return true;
73
74
75 cond = (it >> 4);
76 }
77
78 cpsr_cond = cpsr >> 28;
79
80 if (!((cc_map[cond] >> cpsr_cond) & 1))
81 return false;
82
83 return true;
84 }
85
86
87
88
89
90
91
92
93
94
95
96 static void __hyp_text kvm_adjust_itstate(struct kvm_vcpu *vcpu)
97 {
98 unsigned long itbits, cond;
99 unsigned long cpsr = *vcpu_cpsr(vcpu);
100 bool is_arm = !(cpsr & PSR_AA32_T_BIT);
101
102 if (is_arm || !(cpsr & PSR_AA32_IT_MASK))
103 return;
104
105 cond = (cpsr & 0xe000) >> 13;
106 itbits = (cpsr & 0x1c00) >> (10 - 2);
107 itbits |= (cpsr & (0x3 << 25)) >> 25;
108
109
110 if ((itbits & 0x7) == 0)
111 itbits = cond = 0;
112 else
113 itbits = (itbits << 1) & 0x1f;
114
115 cpsr &= ~PSR_AA32_IT_MASK;
116 cpsr |= cond << 13;
117 cpsr |= (itbits & 0x1c) << (10 - 2);
118 cpsr |= (itbits & 0x3) << 25;
119 *vcpu_cpsr(vcpu) = cpsr;
120 }
121
122
123
124
125
126 void __hyp_text kvm_skip_instr32(struct kvm_vcpu *vcpu, bool is_wide_instr)
127 {
128 u32 pc = *vcpu_pc(vcpu);
129 bool is_thumb;
130
131 is_thumb = !!(*vcpu_cpsr(vcpu) & PSR_AA32_T_BIT);
132 if (is_thumb && !is_wide_instr)
133 pc += 2;
134 else
135 pc += 4;
136
137 *vcpu_pc(vcpu) = pc;
138
139 kvm_adjust_itstate(vcpu);
140 }