]>
Commit | Line | Data |
---|---|---|
9a5071ab PM |
1 | /* |
2 | * ARM translation: M-profile NOCP special-case instructions | |
3 | * | |
4 | * Copyright (c) 2020 Linaro, Ltd. | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser General Public | |
8 | * License as published by the Free Software Foundation; either | |
9 | * version 2.1 of the License, or (at your option) any later version. | |
10 | * | |
11 | * This library is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include "qemu/osdep.h" | |
21 | #include "tcg/tcg-op.h" | |
22 | #include "translate.h" | |
23 | #include "translate-a32.h" | |
24 | ||
25 | #include "decode-m-nocp.c.inc" | |
26 | ||
27 | /* | |
28 | * Decode VLLDM and VLSTM are nonstandard because: | |
29 | * * if there is no FPU then these insns must NOP in | |
30 | * Secure state and UNDEF in Nonsecure state | |
31 | * * if there is an FPU then these insns do not have | |
32 | * the usual behaviour that vfp_access_check() provides of | |
33 | * being controlled by CPACR/NSACR enable bits or the | |
34 | * lazy-stacking logic. | |
35 | */ | |
36 | static bool trans_VLLDM_VLSTM(DisasContext *s, arg_VLLDM_VLSTM *a) | |
37 | { | |
38 | TCGv_i32 fptr; | |
39 | ||
40 | if (!arm_dc_feature(s, ARM_FEATURE_M) || | |
41 | !arm_dc_feature(s, ARM_FEATURE_V8)) { | |
42 | return false; | |
43 | } | |
44 | ||
45 | if (a->op) { | |
46 | /* | |
47 | * T2 encoding ({D0-D31} reglist): v8.1M and up. We choose not | |
48 | * to take the IMPDEF option to make memory accesses to the stack | |
49 | * slots that correspond to the D16-D31 registers (discarding | |
50 | * read data and writing UNKNOWN values), so for us the T2 | |
51 | * encoding behaves identically to the T1 encoding. | |
52 | */ | |
53 | if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) { | |
54 | return false; | |
55 | } | |
56 | } else { | |
57 | /* | |
58 | * T1 encoding ({D0-D15} reglist); undef if we have 32 Dregs. | |
59 | * This is currently architecturally impossible, but we add the | |
60 | * check to stay in line with the pseudocode. Note that we must | |
61 | * emit code for the UNDEF so it takes precedence over the NOCP. | |
62 | */ | |
63 | if (dc_isar_feature(aa32_simd_r32, s)) { | |
64 | unallocated_encoding(s); | |
65 | return true; | |
66 | } | |
67 | } | |
68 | ||
69 | /* | |
70 | * If not secure, UNDEF. We must emit code for this | |
71 | * rather than returning false so that this takes | |
72 | * precedence over the m-nocp.decode NOCP fallback. | |
73 | */ | |
74 | if (!s->v8m_secure) { | |
75 | unallocated_encoding(s); | |
76 | return true; | |
77 | } | |
5138bd01 PM |
78 | |
79 | s->eci_handled = true; | |
80 | ||
9a5071ab PM |
81 | /* If no fpu, NOP. */ |
82 | if (!dc_isar_feature(aa32_vfp, s)) { | |
5138bd01 | 83 | clear_eci_state(s); |
9a5071ab PM |
84 | return true; |
85 | } | |
86 | ||
87 | fptr = load_reg(s, a->rn); | |
88 | if (a->l) { | |
89 | gen_helper_v7m_vlldm(cpu_env, fptr); | |
90 | } else { | |
91 | gen_helper_v7m_vlstm(cpu_env, fptr); | |
92 | } | |
93 | tcg_temp_free_i32(fptr); | |
94 | ||
5138bd01 PM |
95 | clear_eci_state(s); |
96 | ||
9a5071ab PM |
97 | /* End the TB, because we have updated FP control bits */ |
98 | s->base.is_jmp = DISAS_UPDATE_EXIT; | |
99 | return true; | |
100 | } | |
101 | ||
102 | static bool trans_VSCCLRM(DisasContext *s, arg_VSCCLRM *a) | |
103 | { | |
104 | int btmreg, topreg; | |
105 | TCGv_i64 zero; | |
106 | TCGv_i32 aspen, sfpa; | |
107 | ||
108 | if (!dc_isar_feature(aa32_m_sec_state, s)) { | |
109 | /* Before v8.1M, fall through in decode to NOCP check */ | |
110 | return false; | |
111 | } | |
112 | ||
113 | /* Explicitly UNDEF because this takes precedence over NOCP */ | |
114 | if (!arm_dc_feature(s, ARM_FEATURE_M_MAIN) || !s->v8m_secure) { | |
115 | unallocated_encoding(s); | |
116 | return true; | |
117 | } | |
118 | ||
5138bd01 PM |
119 | s->eci_handled = true; |
120 | ||
9a5071ab PM |
121 | if (!dc_isar_feature(aa32_vfp_simd, s)) { |
122 | /* NOP if we have neither FP nor MVE */ | |
5138bd01 | 123 | clear_eci_state(s); |
9a5071ab PM |
124 | return true; |
125 | } | |
126 | ||
127 | /* | |
128 | * If FPCCR.ASPEN != 0 && CONTROL_S.SFPA == 0 then there is no | |
129 | * active floating point context so we must NOP (without doing | |
130 | * any lazy state preservation or the NOCP check). | |
131 | */ | |
132 | aspen = load_cpu_field(v7m.fpccr[M_REG_S]); | |
133 | sfpa = load_cpu_field(v7m.control[M_REG_S]); | |
134 | tcg_gen_andi_i32(aspen, aspen, R_V7M_FPCCR_ASPEN_MASK); | |
135 | tcg_gen_xori_i32(aspen, aspen, R_V7M_FPCCR_ASPEN_MASK); | |
136 | tcg_gen_andi_i32(sfpa, sfpa, R_V7M_CONTROL_SFPA_MASK); | |
137 | tcg_gen_or_i32(sfpa, sfpa, aspen); | |
138 | arm_gen_condlabel(s); | |
139 | tcg_gen_brcondi_i32(TCG_COND_EQ, sfpa, 0, s->condlabel); | |
140 | ||
141 | if (s->fp_excp_el != 0) { | |
142 | gen_exception_insn(s, s->pc_curr, EXCP_NOCP, | |
143 | syn_uncategorized(), s->fp_excp_el); | |
144 | return true; | |
145 | } | |
146 | ||
147 | topreg = a->vd + a->imm - 1; | |
148 | btmreg = a->vd; | |
149 | ||
150 | /* Convert to Sreg numbers if the insn specified in Dregs */ | |
151 | if (a->size == 3) { | |
152 | topreg = topreg * 2 + 1; | |
153 | btmreg *= 2; | |
154 | } | |
155 | ||
156 | if (topreg > 63 || (topreg > 31 && !(topreg & 1))) { | |
157 | /* UNPREDICTABLE: we choose to undef */ | |
158 | unallocated_encoding(s); | |
159 | return true; | |
160 | } | |
161 | ||
162 | /* Silently ignore requests to clear D16-D31 if they don't exist */ | |
163 | if (topreg > 31 && !dc_isar_feature(aa32_simd_r32, s)) { | |
164 | topreg = 31; | |
165 | } | |
166 | ||
167 | if (!vfp_access_check(s)) { | |
168 | return true; | |
169 | } | |
170 | ||
171 | /* Zero the Sregs from btmreg to topreg inclusive. */ | |
172 | zero = tcg_const_i64(0); | |
173 | if (btmreg & 1) { | |
174 | write_neon_element64(zero, btmreg >> 1, 1, MO_32); | |
175 | btmreg++; | |
176 | } | |
177 | for (; btmreg + 1 <= topreg; btmreg += 2) { | |
178 | write_neon_element64(zero, btmreg >> 1, 0, MO_64); | |
179 | } | |
180 | if (btmreg == topreg) { | |
181 | write_neon_element64(zero, btmreg >> 1, 0, MO_32); | |
182 | btmreg++; | |
183 | } | |
184 | assert(btmreg == topreg + 1); | |
375256a8 PM |
185 | if (dc_isar_feature(aa32_mve, s)) { |
186 | TCGv_i32 z32 = tcg_const_i32(0); | |
187 | store_cpu_field(z32, v7m.vpr); | |
188 | } | |
5138bd01 PM |
189 | |
190 | clear_eci_state(s); | |
9a5071ab PM |
191 | return true; |
192 | } | |
193 | ||
194 | static bool trans_NOCP(DisasContext *s, arg_nocp *a) | |
195 | { | |
196 | /* | |
197 | * Handle M-profile early check for disabled coprocessor: | |
198 | * all we need to do here is emit the NOCP exception if | |
199 | * the coprocessor is disabled. Otherwise we return false | |
200 | * and the real VFP/etc decode will handle the insn. | |
201 | */ | |
202 | assert(arm_dc_feature(s, ARM_FEATURE_M)); | |
203 | ||
204 | if (a->cp == 11) { | |
205 | a->cp = 10; | |
206 | } | |
207 | if (arm_dc_feature(s, ARM_FEATURE_V8_1M) && | |
208 | (a->cp == 8 || a->cp == 9 || a->cp == 14 || a->cp == 15)) { | |
209 | /* in v8.1M cp 8, 9, 14, 15 also are governed by the cp10 enable */ | |
210 | a->cp = 10; | |
211 | } | |
212 | ||
213 | if (a->cp != 10) { | |
214 | gen_exception_insn(s, s->pc_curr, EXCP_NOCP, | |
215 | syn_uncategorized(), default_exception_el(s)); | |
216 | return true; | |
217 | } | |
218 | ||
219 | if (s->fp_excp_el != 0) { | |
220 | gen_exception_insn(s, s->pc_curr, EXCP_NOCP, | |
221 | syn_uncategorized(), s->fp_excp_el); | |
222 | return true; | |
223 | } | |
224 | ||
225 | return false; | |
226 | } | |
227 | ||
228 | static bool trans_NOCP_8_1(DisasContext *s, arg_nocp *a) | |
229 | { | |
230 | /* This range needs a coprocessor check for v8.1M and later only */ | |
231 | if (!arm_dc_feature(s, ARM_FEATURE_V8_1M)) { | |
232 | return false; | |
233 | } | |
234 | return trans_NOCP(s, a); | |
235 | } |