]>
Commit | Line | Data |
---|---|---|
2328826b MF |
1 | /* |
2 | * Xtensa ISA: | |
3 | * http://www.tensilica.com/products/literature-docs/documentation/xtensa-isa-databook.htm | |
4 | * | |
5 | * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab. | |
6 | * All rights reserved. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions are met: | |
10 | * * Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | |
12 | * * Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * * Neither the name of the Open Source and Linux Lab nor the | |
16 | * names of its contributors may be used to endorse or promote products | |
17 | * derived from this software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | |
23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
26 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 | */ | |
30 | ||
31 | #include <stdio.h> | |
32 | ||
33 | #include "cpu.h" | |
022c62cb | 34 | #include "exec/exec-all.h" |
76cad711 | 35 | #include "disas/disas.h" |
2328826b | 36 | #include "tcg-op.h" |
1de7afc9 | 37 | #include "qemu/log.h" |
9c17d615 | 38 | #include "sysemu/sysemu.h" |
2328826b | 39 | |
16c1deae | 40 | #include "helper.h" |
dedc5eae | 41 | #define GEN_HELPER 1 |
16c1deae | 42 | #include "helper.h" |
dedc5eae MF |
43 | |
44 | typedef struct DisasContext { | |
45 | const XtensaConfig *config; | |
46 | TranslationBlock *tb; | |
47 | uint32_t pc; | |
48 | uint32_t next_pc; | |
f0a548b9 MF |
49 | int cring; |
50 | int ring; | |
797d780b MF |
51 | uint32_t lbeg; |
52 | uint32_t lend; | |
6ad6dbf7 | 53 | TCGv_i32 litbase; |
dedc5eae MF |
54 | int is_jmp; |
55 | int singlestep_enabled; | |
3580ecad MF |
56 | |
57 | bool sar_5bit; | |
58 | bool sar_m32_5bit; | |
59 | bool sar_m32_allocated; | |
60 | TCGv_i32 sar_m32; | |
b994e91b MF |
61 | |
62 | uint32_t ccount_delta; | |
772177c1 | 63 | unsigned used_window; |
e61dc8f7 MF |
64 | |
65 | bool debug; | |
35b5c044 MF |
66 | bool icount; |
67 | TCGv_i32 next_icount; | |
ef04a846 MF |
68 | |
69 | unsigned cpenable; | |
dedc5eae MF |
70 | } DisasContext; |
71 | ||
72 | static TCGv_ptr cpu_env; | |
73 | static TCGv_i32 cpu_pc; | |
74 | static TCGv_i32 cpu_R[16]; | |
dd519cbe | 75 | static TCGv_i32 cpu_FR[16]; |
2af3da91 MF |
76 | static TCGv_i32 cpu_SR[256]; |
77 | static TCGv_i32 cpu_UR[256]; | |
dedc5eae | 78 | |
022c62cb | 79 | #include "exec/gen-icount.h" |
2328826b | 80 | |
fe0bd475 MF |
81 | typedef struct XtensaReg { |
82 | const char *name; | |
83 | uint64_t opt_bits; | |
53593e90 MF |
84 | enum { |
85 | SR_R = 1, | |
86 | SR_W = 2, | |
87 | SR_X = 4, | |
88 | SR_RW = 3, | |
89 | SR_RWX = 7, | |
90 | } access; | |
fe0bd475 MF |
91 | } XtensaReg; |
92 | ||
53593e90 | 93 | #define XTENSA_REG_ACCESS(regname, opt, acc) { \ |
fe0bd475 MF |
94 | .name = (regname), \ |
95 | .opt_bits = XTENSA_OPTION_BIT(opt), \ | |
53593e90 | 96 | .access = (acc), \ |
fe0bd475 MF |
97 | } |
98 | ||
53593e90 MF |
99 | #define XTENSA_REG(regname, opt) XTENSA_REG_ACCESS(regname, opt, SR_RWX) |
100 | ||
604e1f9c | 101 | #define XTENSA_REG_BITS_ACCESS(regname, opt, acc) { \ |
fe0bd475 MF |
102 | .name = (regname), \ |
103 | .opt_bits = (opt), \ | |
604e1f9c | 104 | .access = (acc), \ |
fe0bd475 MF |
105 | } |
106 | ||
604e1f9c MF |
107 | #define XTENSA_REG_BITS(regname, opt) \ |
108 | XTENSA_REG_BITS_ACCESS(regname, opt, SR_RWX) | |
109 | ||
fe0bd475 MF |
110 | static const XtensaReg sregnames[256] = { |
111 | [LBEG] = XTENSA_REG("LBEG", XTENSA_OPTION_LOOP), | |
112 | [LEND] = XTENSA_REG("LEND", XTENSA_OPTION_LOOP), | |
113 | [LCOUNT] = XTENSA_REG("LCOUNT", XTENSA_OPTION_LOOP), | |
114 | [SAR] = XTENSA_REG_BITS("SAR", XTENSA_OPTION_ALL), | |
115 | [BR] = XTENSA_REG("BR", XTENSA_OPTION_BOOLEAN), | |
116 | [LITBASE] = XTENSA_REG("LITBASE", XTENSA_OPTION_EXTENDED_L32R), | |
117 | [SCOMPARE1] = XTENSA_REG("SCOMPARE1", XTENSA_OPTION_CONDITIONAL_STORE), | |
118 | [ACCLO] = XTENSA_REG("ACCLO", XTENSA_OPTION_MAC16), | |
119 | [ACCHI] = XTENSA_REG("ACCHI", XTENSA_OPTION_MAC16), | |
120 | [MR] = XTENSA_REG("MR0", XTENSA_OPTION_MAC16), | |
121 | [MR + 1] = XTENSA_REG("MR1", XTENSA_OPTION_MAC16), | |
122 | [MR + 2] = XTENSA_REG("MR2", XTENSA_OPTION_MAC16), | |
123 | [MR + 3] = XTENSA_REG("MR3", XTENSA_OPTION_MAC16), | |
124 | [WINDOW_BASE] = XTENSA_REG("WINDOW_BASE", XTENSA_OPTION_WINDOWED_REGISTER), | |
125 | [WINDOW_START] = XTENSA_REG("WINDOW_START", | |
126 | XTENSA_OPTION_WINDOWED_REGISTER), | |
127 | [PTEVADDR] = XTENSA_REG("PTEVADDR", XTENSA_OPTION_MMU), | |
128 | [RASID] = XTENSA_REG("RASID", XTENSA_OPTION_MMU), | |
129 | [ITLBCFG] = XTENSA_REG("ITLBCFG", XTENSA_OPTION_MMU), | |
130 | [DTLBCFG] = XTENSA_REG("DTLBCFG", XTENSA_OPTION_MMU), | |
131 | [IBREAKENABLE] = XTENSA_REG("IBREAKENABLE", XTENSA_OPTION_DEBUG), | |
132 | [CACHEATTR] = XTENSA_REG("CACHEATTR", XTENSA_OPTION_CACHEATTR), | |
133 | [ATOMCTL] = XTENSA_REG("ATOMCTL", XTENSA_OPTION_ATOMCTL), | |
134 | [IBREAKA] = XTENSA_REG("IBREAKA0", XTENSA_OPTION_DEBUG), | |
135 | [IBREAKA + 1] = XTENSA_REG("IBREAKA1", XTENSA_OPTION_DEBUG), | |
136 | [DBREAKA] = XTENSA_REG("DBREAKA0", XTENSA_OPTION_DEBUG), | |
137 | [DBREAKA + 1] = XTENSA_REG("DBREAKA1", XTENSA_OPTION_DEBUG), | |
138 | [DBREAKC] = XTENSA_REG("DBREAKC0", XTENSA_OPTION_DEBUG), | |
139 | [DBREAKC + 1] = XTENSA_REG("DBREAKC1", XTENSA_OPTION_DEBUG), | |
604e1f9c | 140 | [CONFIGID0] = XTENSA_REG_BITS_ACCESS("CONFIGID0", XTENSA_OPTION_ALL, SR_R), |
fe0bd475 MF |
141 | [EPC1] = XTENSA_REG("EPC1", XTENSA_OPTION_EXCEPTION), |
142 | [EPC1 + 1] = XTENSA_REG("EPC2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
143 | [EPC1 + 2] = XTENSA_REG("EPC3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
144 | [EPC1 + 3] = XTENSA_REG("EPC4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
145 | [EPC1 + 4] = XTENSA_REG("EPC5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
146 | [EPC1 + 5] = XTENSA_REG("EPC6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
147 | [EPC1 + 6] = XTENSA_REG("EPC7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
148 | [DEPC] = XTENSA_REG("DEPC", XTENSA_OPTION_EXCEPTION), | |
149 | [EPS2] = XTENSA_REG("EPS2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
150 | [EPS2 + 1] = XTENSA_REG("EPS3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
151 | [EPS2 + 2] = XTENSA_REG("EPS4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
152 | [EPS2 + 3] = XTENSA_REG("EPS5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
153 | [EPS2 + 4] = XTENSA_REG("EPS6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
154 | [EPS2 + 5] = XTENSA_REG("EPS7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
604e1f9c | 155 | [CONFIGID1] = XTENSA_REG_BITS_ACCESS("CONFIGID1", XTENSA_OPTION_ALL, SR_R), |
fe0bd475 MF |
156 | [EXCSAVE1] = XTENSA_REG("EXCSAVE1", XTENSA_OPTION_EXCEPTION), |
157 | [EXCSAVE1 + 1] = XTENSA_REG("EXCSAVE2", | |
158 | XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
159 | [EXCSAVE1 + 2] = XTENSA_REG("EXCSAVE3", | |
160 | XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
161 | [EXCSAVE1 + 3] = XTENSA_REG("EXCSAVE4", | |
162 | XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
163 | [EXCSAVE1 + 4] = XTENSA_REG("EXCSAVE5", | |
164 | XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
165 | [EXCSAVE1 + 5] = XTENSA_REG("EXCSAVE6", | |
166 | XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
167 | [EXCSAVE1 + 6] = XTENSA_REG("EXCSAVE7", | |
168 | XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT), | |
169 | [CPENABLE] = XTENSA_REG("CPENABLE", XTENSA_OPTION_COPROCESSOR), | |
53593e90 MF |
170 | [INTSET] = XTENSA_REG_ACCESS("INTSET", XTENSA_OPTION_INTERRUPT, SR_RW), |
171 | [INTCLEAR] = XTENSA_REG_ACCESS("INTCLEAR", XTENSA_OPTION_INTERRUPT, SR_W), | |
fe0bd475 MF |
172 | [INTENABLE] = XTENSA_REG("INTENABLE", XTENSA_OPTION_INTERRUPT), |
173 | [PS] = XTENSA_REG_BITS("PS", XTENSA_OPTION_ALL), | |
174 | [VECBASE] = XTENSA_REG("VECBASE", XTENSA_OPTION_RELOCATABLE_VECTOR), | |
175 | [EXCCAUSE] = XTENSA_REG("EXCCAUSE", XTENSA_OPTION_EXCEPTION), | |
53593e90 | 176 | [DEBUGCAUSE] = XTENSA_REG_ACCESS("DEBUGCAUSE", XTENSA_OPTION_DEBUG, SR_R), |
fe0bd475 | 177 | [CCOUNT] = XTENSA_REG("CCOUNT", XTENSA_OPTION_TIMER_INTERRUPT), |
53593e90 | 178 | [PRID] = XTENSA_REG_ACCESS("PRID", XTENSA_OPTION_PROCESSOR_ID, SR_R), |
fe0bd475 MF |
179 | [ICOUNT] = XTENSA_REG("ICOUNT", XTENSA_OPTION_DEBUG), |
180 | [ICOUNTLEVEL] = XTENSA_REG("ICOUNTLEVEL", XTENSA_OPTION_DEBUG), | |
181 | [EXCVADDR] = XTENSA_REG("EXCVADDR", XTENSA_OPTION_EXCEPTION), | |
182 | [CCOMPARE] = XTENSA_REG("CCOMPARE0", XTENSA_OPTION_TIMER_INTERRUPT), | |
183 | [CCOMPARE + 1] = XTENSA_REG("CCOMPARE1", | |
184 | XTENSA_OPTION_TIMER_INTERRUPT), | |
185 | [CCOMPARE + 2] = XTENSA_REG("CCOMPARE2", | |
186 | XTENSA_OPTION_TIMER_INTERRUPT), | |
b7909d81 MF |
187 | [MISC] = XTENSA_REG("MISC0", XTENSA_OPTION_MISC_SR), |
188 | [MISC + 1] = XTENSA_REG("MISC1", XTENSA_OPTION_MISC_SR), | |
189 | [MISC + 2] = XTENSA_REG("MISC2", XTENSA_OPTION_MISC_SR), | |
190 | [MISC + 3] = XTENSA_REG("MISC3", XTENSA_OPTION_MISC_SR), | |
2af3da91 MF |
191 | }; |
192 | ||
fe0bd475 MF |
193 | static const XtensaReg uregnames[256] = { |
194 | [THREADPTR] = XTENSA_REG("THREADPTR", XTENSA_OPTION_THREAD_POINTER), | |
195 | [FCR] = XTENSA_REG("FCR", XTENSA_OPTION_FP_COPROCESSOR), | |
196 | [FSR] = XTENSA_REG("FSR", XTENSA_OPTION_FP_COPROCESSOR), | |
2af3da91 MF |
197 | }; |
198 | ||
2328826b MF |
199 | void xtensa_translate_init(void) |
200 | { | |
dedc5eae MF |
201 | static const char * const regnames[] = { |
202 | "ar0", "ar1", "ar2", "ar3", | |
203 | "ar4", "ar5", "ar6", "ar7", | |
204 | "ar8", "ar9", "ar10", "ar11", | |
205 | "ar12", "ar13", "ar14", "ar15", | |
206 | }; | |
dd519cbe MF |
207 | static const char * const fregnames[] = { |
208 | "f0", "f1", "f2", "f3", | |
209 | "f4", "f5", "f6", "f7", | |
210 | "f8", "f9", "f10", "f11", | |
211 | "f12", "f13", "f14", "f15", | |
212 | }; | |
dedc5eae MF |
213 | int i; |
214 | ||
215 | cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env"); | |
216 | cpu_pc = tcg_global_mem_new_i32(TCG_AREG0, | |
97129ac8 | 217 | offsetof(CPUXtensaState, pc), "pc"); |
dedc5eae MF |
218 | |
219 | for (i = 0; i < 16; i++) { | |
220 | cpu_R[i] = tcg_global_mem_new_i32(TCG_AREG0, | |
97129ac8 | 221 | offsetof(CPUXtensaState, regs[i]), |
dedc5eae MF |
222 | regnames[i]); |
223 | } | |
2af3da91 | 224 | |
dd519cbe MF |
225 | for (i = 0; i < 16; i++) { |
226 | cpu_FR[i] = tcg_global_mem_new_i32(TCG_AREG0, | |
227 | offsetof(CPUXtensaState, fregs[i]), | |
228 | fregnames[i]); | |
229 | } | |
230 | ||
2af3da91 | 231 | for (i = 0; i < 256; ++i) { |
fe0bd475 | 232 | if (sregnames[i].name) { |
2af3da91 | 233 | cpu_SR[i] = tcg_global_mem_new_i32(TCG_AREG0, |
97129ac8 | 234 | offsetof(CPUXtensaState, sregs[i]), |
fe0bd475 | 235 | sregnames[i].name); |
2af3da91 MF |
236 | } |
237 | } | |
238 | ||
239 | for (i = 0; i < 256; ++i) { | |
fe0bd475 | 240 | if (uregnames[i].name) { |
2af3da91 | 241 | cpu_UR[i] = tcg_global_mem_new_i32(TCG_AREG0, |
97129ac8 | 242 | offsetof(CPUXtensaState, uregs[i]), |
fe0bd475 | 243 | uregnames[i].name); |
2af3da91 MF |
244 | } |
245 | } | |
dedc5eae MF |
246 | } |
247 | ||
b67ea0cd MF |
248 | static inline bool option_bits_enabled(DisasContext *dc, uint64_t opt) |
249 | { | |
250 | return xtensa_option_bits_enabled(dc->config, opt); | |
251 | } | |
252 | ||
dedc5eae MF |
253 | static inline bool option_enabled(DisasContext *dc, int opt) |
254 | { | |
255 | return xtensa_option_enabled(dc->config, opt); | |
256 | } | |
257 | ||
6ad6dbf7 MF |
258 | static void init_litbase(DisasContext *dc) |
259 | { | |
260 | if (dc->tb->flags & XTENSA_TBFLAG_LITBASE) { | |
261 | dc->litbase = tcg_temp_local_new_i32(); | |
262 | tcg_gen_andi_i32(dc->litbase, cpu_SR[LITBASE], 0xfffff000); | |
263 | } | |
264 | } | |
265 | ||
266 | static void reset_litbase(DisasContext *dc) | |
267 | { | |
268 | if (dc->tb->flags & XTENSA_TBFLAG_LITBASE) { | |
269 | tcg_temp_free(dc->litbase); | |
270 | } | |
271 | } | |
272 | ||
3580ecad MF |
273 | static void init_sar_tracker(DisasContext *dc) |
274 | { | |
275 | dc->sar_5bit = false; | |
276 | dc->sar_m32_5bit = false; | |
277 | dc->sar_m32_allocated = false; | |
278 | } | |
279 | ||
280 | static void reset_sar_tracker(DisasContext *dc) | |
281 | { | |
282 | if (dc->sar_m32_allocated) { | |
283 | tcg_temp_free(dc->sar_m32); | |
284 | } | |
285 | } | |
286 | ||
287 | static void gen_right_shift_sar(DisasContext *dc, TCGv_i32 sa) | |
288 | { | |
289 | tcg_gen_andi_i32(cpu_SR[SAR], sa, 0x1f); | |
290 | if (dc->sar_m32_5bit) { | |
291 | tcg_gen_discard_i32(dc->sar_m32); | |
292 | } | |
293 | dc->sar_5bit = true; | |
294 | dc->sar_m32_5bit = false; | |
295 | } | |
296 | ||
297 | static void gen_left_shift_sar(DisasContext *dc, TCGv_i32 sa) | |
298 | { | |
299 | TCGv_i32 tmp = tcg_const_i32(32); | |
300 | if (!dc->sar_m32_allocated) { | |
301 | dc->sar_m32 = tcg_temp_local_new_i32(); | |
302 | dc->sar_m32_allocated = true; | |
303 | } | |
304 | tcg_gen_andi_i32(dc->sar_m32, sa, 0x1f); | |
305 | tcg_gen_sub_i32(cpu_SR[SAR], tmp, dc->sar_m32); | |
306 | dc->sar_5bit = false; | |
307 | dc->sar_m32_5bit = true; | |
308 | tcg_temp_free(tmp); | |
309 | } | |
310 | ||
908c67fc | 311 | static void gen_advance_ccount_cond(DisasContext *dc) |
b994e91b MF |
312 | { |
313 | if (dc->ccount_delta > 0) { | |
314 | TCGv_i32 tmp = tcg_const_i32(dc->ccount_delta); | |
f492b82d | 315 | gen_helper_advance_ccount(cpu_env, tmp); |
b994e91b MF |
316 | tcg_temp_free(tmp); |
317 | } | |
318 | } | |
319 | ||
908c67fc MF |
320 | static void gen_advance_ccount(DisasContext *dc) |
321 | { | |
322 | gen_advance_ccount_cond(dc); | |
323 | dc->ccount_delta = 0; | |
324 | } | |
325 | ||
772177c1 MF |
326 | static void reset_used_window(DisasContext *dc) |
327 | { | |
328 | dc->used_window = 0; | |
329 | } | |
330 | ||
b994e91b | 331 | static void gen_exception(DisasContext *dc, int excp) |
dedc5eae MF |
332 | { |
333 | TCGv_i32 tmp = tcg_const_i32(excp); | |
b994e91b | 334 | gen_advance_ccount(dc); |
f492b82d | 335 | gen_helper_exception(cpu_env, tmp); |
dedc5eae MF |
336 | tcg_temp_free(tmp); |
337 | } | |
338 | ||
40643d7c MF |
339 | static void gen_exception_cause(DisasContext *dc, uint32_t cause) |
340 | { | |
341 | TCGv_i32 tpc = tcg_const_i32(dc->pc); | |
342 | TCGv_i32 tcause = tcg_const_i32(cause); | |
b994e91b | 343 | gen_advance_ccount(dc); |
f492b82d | 344 | gen_helper_exception_cause(cpu_env, tpc, tcause); |
40643d7c MF |
345 | tcg_temp_free(tpc); |
346 | tcg_temp_free(tcause); | |
6b814719 MF |
347 | if (cause == ILLEGAL_INSTRUCTION_CAUSE || |
348 | cause == SYSCALL_CAUSE) { | |
349 | dc->is_jmp = DISAS_UPDATE; | |
350 | } | |
40643d7c MF |
351 | } |
352 | ||
5b4e481b MF |
353 | static void gen_exception_cause_vaddr(DisasContext *dc, uint32_t cause, |
354 | TCGv_i32 vaddr) | |
355 | { | |
356 | TCGv_i32 tpc = tcg_const_i32(dc->pc); | |
357 | TCGv_i32 tcause = tcg_const_i32(cause); | |
b994e91b | 358 | gen_advance_ccount(dc); |
f492b82d | 359 | gen_helper_exception_cause_vaddr(cpu_env, tpc, tcause, vaddr); |
5b4e481b MF |
360 | tcg_temp_free(tpc); |
361 | tcg_temp_free(tcause); | |
362 | } | |
363 | ||
e61dc8f7 MF |
364 | static void gen_debug_exception(DisasContext *dc, uint32_t cause) |
365 | { | |
366 | TCGv_i32 tpc = tcg_const_i32(dc->pc); | |
367 | TCGv_i32 tcause = tcg_const_i32(cause); | |
368 | gen_advance_ccount(dc); | |
f492b82d | 369 | gen_helper_debug_exception(cpu_env, tpc, tcause); |
e61dc8f7 MF |
370 | tcg_temp_free(tpc); |
371 | tcg_temp_free(tcause); | |
372 | if (cause & (DEBUGCAUSE_IB | DEBUGCAUSE_BI | DEBUGCAUSE_BN)) { | |
373 | dc->is_jmp = DISAS_UPDATE; | |
374 | } | |
375 | } | |
376 | ||
40643d7c MF |
377 | static void gen_check_privilege(DisasContext *dc) |
378 | { | |
379 | if (dc->cring) { | |
380 | gen_exception_cause(dc, PRIVILEGED_CAUSE); | |
6b814719 | 381 | dc->is_jmp = DISAS_UPDATE; |
40643d7c MF |
382 | } |
383 | } | |
384 | ||
ef04a846 MF |
385 | static void gen_check_cpenable(DisasContext *dc, unsigned cp) |
386 | { | |
387 | if (option_enabled(dc, XTENSA_OPTION_COPROCESSOR) && | |
388 | !(dc->cpenable & (1 << cp))) { | |
389 | gen_exception_cause(dc, COPROCESSOR0_DISABLED + cp); | |
390 | dc->is_jmp = DISAS_UPDATE; | |
391 | } | |
392 | } | |
393 | ||
dedc5eae MF |
394 | static void gen_jump_slot(DisasContext *dc, TCGv dest, int slot) |
395 | { | |
396 | tcg_gen_mov_i32(cpu_pc, dest); | |
35b5c044 MF |
397 | gen_advance_ccount(dc); |
398 | if (dc->icount) { | |
399 | tcg_gen_mov_i32(cpu_SR[ICOUNT], dc->next_icount); | |
400 | } | |
dedc5eae | 401 | if (dc->singlestep_enabled) { |
b994e91b | 402 | gen_exception(dc, EXCP_DEBUG); |
dedc5eae MF |
403 | } else { |
404 | if (slot >= 0) { | |
405 | tcg_gen_goto_tb(slot); | |
8cfd0495 | 406 | tcg_gen_exit_tb((uintptr_t)dc->tb + slot); |
dedc5eae MF |
407 | } else { |
408 | tcg_gen_exit_tb(0); | |
409 | } | |
410 | } | |
411 | dc->is_jmp = DISAS_UPDATE; | |
412 | } | |
413 | ||
67882fd1 MF |
414 | static void gen_jump(DisasContext *dc, TCGv dest) |
415 | { | |
416 | gen_jump_slot(dc, dest, -1); | |
417 | } | |
418 | ||
dedc5eae MF |
419 | static void gen_jumpi(DisasContext *dc, uint32_t dest, int slot) |
420 | { | |
421 | TCGv_i32 tmp = tcg_const_i32(dest); | |
422 | if (((dc->pc ^ dest) & TARGET_PAGE_MASK) != 0) { | |
423 | slot = -1; | |
424 | } | |
425 | gen_jump_slot(dc, tmp, slot); | |
426 | tcg_temp_free(tmp); | |
427 | } | |
428 | ||
553e44f9 MF |
429 | static void gen_callw_slot(DisasContext *dc, int callinc, TCGv_i32 dest, |
430 | int slot) | |
431 | { | |
432 | TCGv_i32 tcallinc = tcg_const_i32(callinc); | |
433 | ||
434 | tcg_gen_deposit_i32(cpu_SR[PS], cpu_SR[PS], | |
435 | tcallinc, PS_CALLINC_SHIFT, PS_CALLINC_LEN); | |
436 | tcg_temp_free(tcallinc); | |
437 | tcg_gen_movi_i32(cpu_R[callinc << 2], | |
438 | (callinc << 30) | (dc->next_pc & 0x3fffffff)); | |
439 | gen_jump_slot(dc, dest, slot); | |
440 | } | |
441 | ||
442 | static void gen_callw(DisasContext *dc, int callinc, TCGv_i32 dest) | |
443 | { | |
444 | gen_callw_slot(dc, callinc, dest, -1); | |
445 | } | |
446 | ||
447 | static void gen_callwi(DisasContext *dc, int callinc, uint32_t dest, int slot) | |
448 | { | |
449 | TCGv_i32 tmp = tcg_const_i32(dest); | |
450 | if (((dc->pc ^ dest) & TARGET_PAGE_MASK) != 0) { | |
451 | slot = -1; | |
452 | } | |
453 | gen_callw_slot(dc, callinc, tmp, slot); | |
454 | tcg_temp_free(tmp); | |
455 | } | |
456 | ||
797d780b MF |
457 | static bool gen_check_loop_end(DisasContext *dc, int slot) |
458 | { | |
459 | if (option_enabled(dc, XTENSA_OPTION_LOOP) && | |
460 | !(dc->tb->flags & XTENSA_TBFLAG_EXCM) && | |
461 | dc->next_pc == dc->lend) { | |
462 | int label = gen_new_label(); | |
463 | ||
d865f307 | 464 | gen_advance_ccount(dc); |
797d780b MF |
465 | tcg_gen_brcondi_i32(TCG_COND_EQ, cpu_SR[LCOUNT], 0, label); |
466 | tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_SR[LCOUNT], 1); | |
467 | gen_jumpi(dc, dc->lbeg, slot); | |
468 | gen_set_label(label); | |
469 | gen_jumpi(dc, dc->next_pc, -1); | |
470 | return true; | |
471 | } | |
472 | return false; | |
473 | } | |
474 | ||
475 | static void gen_jumpi_check_loop_end(DisasContext *dc, int slot) | |
476 | { | |
477 | if (!gen_check_loop_end(dc, slot)) { | |
478 | gen_jumpi(dc, dc->next_pc, slot); | |
479 | } | |
480 | } | |
481 | ||
bd57fb91 MF |
482 | static void gen_brcond(DisasContext *dc, TCGCond cond, |
483 | TCGv_i32 t0, TCGv_i32 t1, uint32_t offset) | |
484 | { | |
485 | int label = gen_new_label(); | |
486 | ||
d865f307 | 487 | gen_advance_ccount(dc); |
bd57fb91 | 488 | tcg_gen_brcond_i32(cond, t0, t1, label); |
797d780b | 489 | gen_jumpi_check_loop_end(dc, 0); |
bd57fb91 MF |
490 | gen_set_label(label); |
491 | gen_jumpi(dc, dc->pc + offset, 1); | |
492 | } | |
493 | ||
494 | static void gen_brcondi(DisasContext *dc, TCGCond cond, | |
495 | TCGv_i32 t0, uint32_t t1, uint32_t offset) | |
496 | { | |
497 | TCGv_i32 tmp = tcg_const_i32(t1); | |
498 | gen_brcond(dc, cond, t0, tmp, offset); | |
499 | tcg_temp_free(tmp); | |
500 | } | |
501 | ||
0857a06e | 502 | static bool gen_check_sr(DisasContext *dc, uint32_t sr, unsigned access) |
fe0bd475 MF |
503 | { |
504 | if (!xtensa_option_bits_enabled(dc->config, sregnames[sr].opt_bits)) { | |
505 | if (sregnames[sr].name) { | |
506 | qemu_log("SR %s is not configured\n", sregnames[sr].name); | |
507 | } else { | |
508 | qemu_log("SR %d is not implemented\n", sr); | |
509 | } | |
510 | gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE); | |
0857a06e | 511 | return false; |
53593e90 MF |
512 | } else if (!(sregnames[sr].access & access)) { |
513 | static const char * const access_text[] = { | |
514 | [SR_R] = "rsr", | |
515 | [SR_W] = "wsr", | |
516 | [SR_X] = "xsr", | |
517 | }; | |
518 | assert(access < ARRAY_SIZE(access_text) && access_text[access]); | |
519 | qemu_log("SR %s is not available for %s\n", sregnames[sr].name, | |
520 | access_text[access]); | |
521 | gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE); | |
0857a06e | 522 | return false; |
fe0bd475 | 523 | } |
0857a06e | 524 | return true; |
fe0bd475 MF |
525 | } |
526 | ||
b994e91b MF |
527 | static void gen_rsr_ccount(DisasContext *dc, TCGv_i32 d, uint32_t sr) |
528 | { | |
529 | gen_advance_ccount(dc); | |
530 | tcg_gen_mov_i32(d, cpu_SR[sr]); | |
531 | } | |
532 | ||
b67ea0cd MF |
533 | static void gen_rsr_ptevaddr(DisasContext *dc, TCGv_i32 d, uint32_t sr) |
534 | { | |
535 | tcg_gen_shri_i32(d, cpu_SR[EXCVADDR], 10); | |
536 | tcg_gen_or_i32(d, d, cpu_SR[sr]); | |
537 | tcg_gen_andi_i32(d, d, 0xfffffffc); | |
538 | } | |
539 | ||
b8132eff MF |
540 | static void gen_rsr(DisasContext *dc, TCGv_i32 d, uint32_t sr) |
541 | { | |
542 | static void (* const rsr_handler[256])(DisasContext *dc, | |
543 | TCGv_i32 d, uint32_t sr) = { | |
b994e91b | 544 | [CCOUNT] = gen_rsr_ccount, |
b67ea0cd | 545 | [PTEVADDR] = gen_rsr_ptevaddr, |
b8132eff MF |
546 | }; |
547 | ||
fe0bd475 MF |
548 | if (rsr_handler[sr]) { |
549 | rsr_handler[sr](dc, d, sr); | |
b8132eff | 550 | } else { |
fe0bd475 | 551 | tcg_gen_mov_i32(d, cpu_SR[sr]); |
b8132eff MF |
552 | } |
553 | } | |
554 | ||
797d780b MF |
555 | static void gen_wsr_lbeg(DisasContext *dc, uint32_t sr, TCGv_i32 s) |
556 | { | |
f492b82d | 557 | gen_helper_wsr_lbeg(cpu_env, s); |
3d0be8a5 | 558 | gen_jumpi_check_loop_end(dc, 0); |
797d780b MF |
559 | } |
560 | ||
561 | static void gen_wsr_lend(DisasContext *dc, uint32_t sr, TCGv_i32 s) | |
562 | { | |
f492b82d | 563 | gen_helper_wsr_lend(cpu_env, s); |
3d0be8a5 | 564 | gen_jumpi_check_loop_end(dc, 0); |
797d780b MF |
565 | } |
566 | ||
3580ecad MF |
567 | static void gen_wsr_sar(DisasContext *dc, uint32_t sr, TCGv_i32 s) |
568 | { | |
569 | tcg_gen_andi_i32(cpu_SR[sr], s, 0x3f); | |
570 | if (dc->sar_m32_5bit) { | |
571 | tcg_gen_discard_i32(dc->sar_m32); | |
572 | } | |
573 | dc->sar_5bit = false; | |
574 | dc->sar_m32_5bit = false; | |
575 | } | |
576 | ||
4dd85b6b MF |
577 | static void gen_wsr_br(DisasContext *dc, uint32_t sr, TCGv_i32 s) |
578 | { | |
579 | tcg_gen_andi_i32(cpu_SR[sr], s, 0xffff); | |
580 | } | |
581 | ||
6ad6dbf7 MF |
582 | static void gen_wsr_litbase(DisasContext *dc, uint32_t sr, TCGv_i32 s) |
583 | { | |
584 | tcg_gen_andi_i32(cpu_SR[sr], s, 0xfffff001); | |
585 | /* This can change tb->flags, so exit tb */ | |
586 | gen_jumpi_check_loop_end(dc, -1); | |
587 | } | |
588 | ||
6825b6c3 MF |
589 | static void gen_wsr_acchi(DisasContext *dc, uint32_t sr, TCGv_i32 s) |
590 | { | |
591 | tcg_gen_ext8s_i32(cpu_SR[sr], s); | |
592 | } | |
593 | ||
553e44f9 MF |
594 | static void gen_wsr_windowbase(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
595 | { | |
f492b82d | 596 | gen_helper_wsr_windowbase(cpu_env, v); |
772177c1 MF |
597 | reset_used_window(dc); |
598 | } | |
599 | ||
600 | static void gen_wsr_windowstart(DisasContext *dc, uint32_t sr, TCGv_i32 v) | |
601 | { | |
53a72dfd | 602 | tcg_gen_andi_i32(cpu_SR[sr], v, (1 << dc->config->nareg / 4) - 1); |
772177c1 | 603 | reset_used_window(dc); |
553e44f9 MF |
604 | } |
605 | ||
b67ea0cd MF |
606 | static void gen_wsr_ptevaddr(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
607 | { | |
608 | tcg_gen_andi_i32(cpu_SR[sr], v, 0xffc00000); | |
609 | } | |
610 | ||
611 | static void gen_wsr_rasid(DisasContext *dc, uint32_t sr, TCGv_i32 v) | |
612 | { | |
f492b82d | 613 | gen_helper_wsr_rasid(cpu_env, v); |
b67ea0cd MF |
614 | /* This can change tb->flags, so exit tb */ |
615 | gen_jumpi_check_loop_end(dc, -1); | |
616 | } | |
617 | ||
618 | static void gen_wsr_tlbcfg(DisasContext *dc, uint32_t sr, TCGv_i32 v) | |
619 | { | |
620 | tcg_gen_andi_i32(cpu_SR[sr], v, 0x01130000); | |
621 | } | |
622 | ||
e61dc8f7 MF |
623 | static void gen_wsr_ibreakenable(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
624 | { | |
f492b82d | 625 | gen_helper_wsr_ibreakenable(cpu_env, v); |
e61dc8f7 MF |
626 | gen_jumpi_check_loop_end(dc, 0); |
627 | } | |
628 | ||
fcc803d1 MF |
629 | static void gen_wsr_atomctl(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
630 | { | |
631 | tcg_gen_andi_i32(cpu_SR[sr], v, 0x3f); | |
632 | } | |
633 | ||
e61dc8f7 MF |
634 | static void gen_wsr_ibreaka(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
635 | { | |
636 | unsigned id = sr - IBREAKA; | |
637 | ||
638 | if (id < dc->config->nibreak) { | |
639 | TCGv_i32 tmp = tcg_const_i32(id); | |
f492b82d | 640 | gen_helper_wsr_ibreaka(cpu_env, tmp, v); |
e61dc8f7 MF |
641 | tcg_temp_free(tmp); |
642 | gen_jumpi_check_loop_end(dc, 0); | |
643 | } | |
644 | } | |
645 | ||
f14c4b5f MF |
646 | static void gen_wsr_dbreaka(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
647 | { | |
648 | unsigned id = sr - DBREAKA; | |
649 | ||
650 | if (id < dc->config->ndbreak) { | |
651 | TCGv_i32 tmp = tcg_const_i32(id); | |
f492b82d | 652 | gen_helper_wsr_dbreaka(cpu_env, tmp, v); |
f14c4b5f MF |
653 | tcg_temp_free(tmp); |
654 | } | |
655 | } | |
656 | ||
657 | static void gen_wsr_dbreakc(DisasContext *dc, uint32_t sr, TCGv_i32 v) | |
658 | { | |
659 | unsigned id = sr - DBREAKC; | |
660 | ||
661 | if (id < dc->config->ndbreak) { | |
662 | TCGv_i32 tmp = tcg_const_i32(id); | |
f492b82d | 663 | gen_helper_wsr_dbreakc(cpu_env, tmp, v); |
f14c4b5f MF |
664 | tcg_temp_free(tmp); |
665 | } | |
666 | } | |
667 | ||
ef04a846 MF |
668 | static void gen_wsr_cpenable(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
669 | { | |
670 | tcg_gen_andi_i32(cpu_SR[sr], v, 0xff); | |
671 | /* This can change tb->flags, so exit tb */ | |
672 | gen_jumpi_check_loop_end(dc, -1); | |
673 | } | |
674 | ||
b994e91b MF |
675 | static void gen_wsr_intset(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
676 | { | |
677 | tcg_gen_andi_i32(cpu_SR[sr], v, | |
678 | dc->config->inttype_mask[INTTYPE_SOFTWARE]); | |
679 | gen_helper_check_interrupts(cpu_env); | |
680 | gen_jumpi_check_loop_end(dc, 0); | |
681 | } | |
682 | ||
683 | static void gen_wsr_intclear(DisasContext *dc, uint32_t sr, TCGv_i32 v) | |
684 | { | |
685 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
686 | ||
687 | tcg_gen_andi_i32(tmp, v, | |
688 | dc->config->inttype_mask[INTTYPE_EDGE] | | |
689 | dc->config->inttype_mask[INTTYPE_NMI] | | |
690 | dc->config->inttype_mask[INTTYPE_SOFTWARE]); | |
691 | tcg_gen_andc_i32(cpu_SR[INTSET], cpu_SR[INTSET], tmp); | |
692 | tcg_temp_free(tmp); | |
693 | gen_helper_check_interrupts(cpu_env); | |
694 | } | |
695 | ||
696 | static void gen_wsr_intenable(DisasContext *dc, uint32_t sr, TCGv_i32 v) | |
697 | { | |
698 | tcg_gen_mov_i32(cpu_SR[sr], v); | |
699 | gen_helper_check_interrupts(cpu_env); | |
700 | gen_jumpi_check_loop_end(dc, 0); | |
701 | } | |
702 | ||
f0a548b9 MF |
703 | static void gen_wsr_ps(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
704 | { | |
705 | uint32_t mask = PS_WOE | PS_CALLINC | PS_OWB | | |
706 | PS_UM | PS_EXCM | PS_INTLEVEL; | |
707 | ||
708 | if (option_enabled(dc, XTENSA_OPTION_MMU)) { | |
709 | mask |= PS_RING; | |
710 | } | |
711 | tcg_gen_andi_i32(cpu_SR[sr], v, mask); | |
772177c1 | 712 | reset_used_window(dc); |
b994e91b MF |
713 | gen_helper_check_interrupts(cpu_env); |
714 | /* This can change mmu index and tb->flags, so exit tb */ | |
797d780b | 715 | gen_jumpi_check_loop_end(dc, -1); |
f0a548b9 MF |
716 | } |
717 | ||
35b5c044 MF |
718 | static void gen_wsr_icount(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
719 | { | |
720 | if (dc->icount) { | |
721 | tcg_gen_mov_i32(dc->next_icount, v); | |
722 | } else { | |
723 | tcg_gen_mov_i32(cpu_SR[sr], v); | |
724 | } | |
725 | } | |
726 | ||
727 | static void gen_wsr_icountlevel(DisasContext *dc, uint32_t sr, TCGv_i32 v) | |
728 | { | |
729 | tcg_gen_andi_i32(cpu_SR[sr], v, 0xf); | |
730 | /* This can change tb->flags, so exit tb */ | |
731 | gen_jumpi_check_loop_end(dc, -1); | |
732 | } | |
733 | ||
b994e91b MF |
734 | static void gen_wsr_ccompare(DisasContext *dc, uint32_t sr, TCGv_i32 v) |
735 | { | |
736 | uint32_t id = sr - CCOMPARE; | |
737 | if (id < dc->config->nccompare) { | |
738 | uint32_t int_bit = 1 << dc->config->timerint[id]; | |
739 | gen_advance_ccount(dc); | |
740 | tcg_gen_mov_i32(cpu_SR[sr], v); | |
741 | tcg_gen_andi_i32(cpu_SR[INTSET], cpu_SR[INTSET], ~int_bit); | |
742 | gen_helper_check_interrupts(cpu_env); | |
743 | } | |
744 | } | |
745 | ||
b8132eff MF |
746 | static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) |
747 | { | |
748 | static void (* const wsr_handler[256])(DisasContext *dc, | |
749 | uint32_t sr, TCGv_i32 v) = { | |
797d780b MF |
750 | [LBEG] = gen_wsr_lbeg, |
751 | [LEND] = gen_wsr_lend, | |
3580ecad | 752 | [SAR] = gen_wsr_sar, |
4dd85b6b | 753 | [BR] = gen_wsr_br, |
6ad6dbf7 | 754 | [LITBASE] = gen_wsr_litbase, |
6825b6c3 | 755 | [ACCHI] = gen_wsr_acchi, |
553e44f9 | 756 | [WINDOW_BASE] = gen_wsr_windowbase, |
772177c1 | 757 | [WINDOW_START] = gen_wsr_windowstart, |
b67ea0cd MF |
758 | [PTEVADDR] = gen_wsr_ptevaddr, |
759 | [RASID] = gen_wsr_rasid, | |
760 | [ITLBCFG] = gen_wsr_tlbcfg, | |
761 | [DTLBCFG] = gen_wsr_tlbcfg, | |
e61dc8f7 | 762 | [IBREAKENABLE] = gen_wsr_ibreakenable, |
fcc803d1 | 763 | [ATOMCTL] = gen_wsr_atomctl, |
e61dc8f7 MF |
764 | [IBREAKA] = gen_wsr_ibreaka, |
765 | [IBREAKA + 1] = gen_wsr_ibreaka, | |
f14c4b5f MF |
766 | [DBREAKA] = gen_wsr_dbreaka, |
767 | [DBREAKA + 1] = gen_wsr_dbreaka, | |
768 | [DBREAKC] = gen_wsr_dbreakc, | |
769 | [DBREAKC + 1] = gen_wsr_dbreakc, | |
ef04a846 | 770 | [CPENABLE] = gen_wsr_cpenable, |
b994e91b MF |
771 | [INTSET] = gen_wsr_intset, |
772 | [INTCLEAR] = gen_wsr_intclear, | |
773 | [INTENABLE] = gen_wsr_intenable, | |
f0a548b9 | 774 | [PS] = gen_wsr_ps, |
35b5c044 MF |
775 | [ICOUNT] = gen_wsr_icount, |
776 | [ICOUNTLEVEL] = gen_wsr_icountlevel, | |
b994e91b MF |
777 | [CCOMPARE] = gen_wsr_ccompare, |
778 | [CCOMPARE + 1] = gen_wsr_ccompare, | |
779 | [CCOMPARE + 2] = gen_wsr_ccompare, | |
b8132eff MF |
780 | }; |
781 | ||
fe0bd475 MF |
782 | if (wsr_handler[sr]) { |
783 | wsr_handler[sr](dc, sr, s); | |
b8132eff | 784 | } else { |
fe0bd475 | 785 | tcg_gen_mov_i32(cpu_SR[sr], s); |
b8132eff MF |
786 | } |
787 | } | |
788 | ||
dd519cbe MF |
789 | static void gen_wur(uint32_t ur, TCGv_i32 s) |
790 | { | |
791 | switch (ur) { | |
792 | case FCR: | |
793 | gen_helper_wur_fcr(cpu_env, s); | |
794 | break; | |
795 | ||
796 | case FSR: | |
797 | tcg_gen_andi_i32(cpu_UR[ur], s, 0xffffff80); | |
798 | break; | |
799 | ||
800 | default: | |
801 | tcg_gen_mov_i32(cpu_UR[ur], s); | |
802 | break; | |
803 | } | |
804 | } | |
805 | ||
5b4e481b MF |
806 | static void gen_load_store_alignment(DisasContext *dc, int shift, |
807 | TCGv_i32 addr, bool no_hw_alignment) | |
808 | { | |
809 | if (!option_enabled(dc, XTENSA_OPTION_UNALIGNED_EXCEPTION)) { | |
810 | tcg_gen_andi_i32(addr, addr, ~0 << shift); | |
811 | } else if (option_enabled(dc, XTENSA_OPTION_HW_ALIGNMENT) && | |
812 | no_hw_alignment) { | |
813 | int label = gen_new_label(); | |
814 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
815 | tcg_gen_andi_i32(tmp, addr, ~(~0 << shift)); | |
816 | tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label); | |
817 | gen_exception_cause_vaddr(dc, LOAD_STORE_ALIGNMENT_CAUSE, addr); | |
818 | gen_set_label(label); | |
819 | tcg_temp_free(tmp); | |
820 | } | |
821 | } | |
822 | ||
b994e91b MF |
823 | static void gen_waiti(DisasContext *dc, uint32_t imm4) |
824 | { | |
825 | TCGv_i32 pc = tcg_const_i32(dc->next_pc); | |
826 | TCGv_i32 intlevel = tcg_const_i32(imm4); | |
827 | gen_advance_ccount(dc); | |
f492b82d | 828 | gen_helper_waiti(cpu_env, pc, intlevel); |
b994e91b MF |
829 | tcg_temp_free(pc); |
830 | tcg_temp_free(intlevel); | |
831 | } | |
832 | ||
772177c1 MF |
833 | static void gen_window_check1(DisasContext *dc, unsigned r1) |
834 | { | |
835 | if (dc->tb->flags & XTENSA_TBFLAG_EXCM) { | |
836 | return; | |
837 | } | |
838 | if (option_enabled(dc, XTENSA_OPTION_WINDOWED_REGISTER) && | |
839 | r1 / 4 > dc->used_window) { | |
908c67fc MF |
840 | int label = gen_new_label(); |
841 | TCGv_i32 ws = tcg_temp_new_i32(); | |
772177c1 MF |
842 | |
843 | dc->used_window = r1 / 4; | |
908c67fc MF |
844 | tcg_gen_deposit_i32(ws, cpu_SR[WINDOW_START], cpu_SR[WINDOW_START], |
845 | dc->config->nareg / 4, dc->config->nareg / 4); | |
846 | tcg_gen_shr_i32(ws, ws, cpu_SR[WINDOW_BASE]); | |
847 | tcg_gen_andi_i32(ws, ws, (2 << (r1 / 4)) - 2); | |
848 | tcg_gen_brcondi_i32(TCG_COND_EQ, ws, 0, label); | |
849 | { | |
850 | TCGv_i32 pc = tcg_const_i32(dc->pc); | |
851 | TCGv_i32 w = tcg_const_i32(r1 / 4); | |
852 | ||
853 | gen_advance_ccount_cond(dc); | |
854 | gen_helper_window_check(cpu_env, pc, w); | |
855 | ||
856 | tcg_temp_free(w); | |
857 | tcg_temp_free(pc); | |
858 | } | |
859 | gen_set_label(label); | |
860 | tcg_temp_free(ws); | |
772177c1 MF |
861 | } |
862 | } | |
863 | ||
864 | static void gen_window_check2(DisasContext *dc, unsigned r1, unsigned r2) | |
865 | { | |
866 | gen_window_check1(dc, r1 > r2 ? r1 : r2); | |
867 | } | |
868 | ||
869 | static void gen_window_check3(DisasContext *dc, unsigned r1, unsigned r2, | |
870 | unsigned r3) | |
871 | { | |
872 | gen_window_check2(dc, r1, r2 > r3 ? r2 : r3); | |
873 | } | |
874 | ||
6825b6c3 MF |
875 | static TCGv_i32 gen_mac16_m(TCGv_i32 v, bool hi, bool is_unsigned) |
876 | { | |
877 | TCGv_i32 m = tcg_temp_new_i32(); | |
878 | ||
879 | if (hi) { | |
880 | (is_unsigned ? tcg_gen_shri_i32 : tcg_gen_sari_i32)(m, v, 16); | |
881 | } else { | |
882 | (is_unsigned ? tcg_gen_ext16u_i32 : tcg_gen_ext16s_i32)(m, v); | |
883 | } | |
884 | return m; | |
885 | } | |
886 | ||
0c4fabea | 887 | static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) |
dedc5eae | 888 | { |
b67ea0cd MF |
889 | #define HAS_OPTION_BITS(opt) do { \ |
890 | if (!option_bits_enabled(dc, opt)) { \ | |
891 | qemu_log("Option is not enabled %s:%d\n", \ | |
892 | __FILE__, __LINE__); \ | |
dedc5eae MF |
893 | goto invalid_opcode; \ |
894 | } \ | |
895 | } while (0) | |
896 | ||
b67ea0cd MF |
897 | #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt)) |
898 | ||
91a5bb76 MF |
899 | #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__) |
900 | #define RESERVED() do { \ | |
901 | qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \ | |
902 | dc->pc, b0, b1, b2, __FILE__, __LINE__); \ | |
903 | goto invalid_opcode; \ | |
904 | } while (0) | |
905 | ||
906 | ||
dedc5eae MF |
907 | #ifdef TARGET_WORDS_BIGENDIAN |
908 | #define OP0 (((b0) & 0xf0) >> 4) | |
909 | #define OP1 (((b2) & 0xf0) >> 4) | |
910 | #define OP2 ((b2) & 0xf) | |
911 | #define RRR_R ((b1) & 0xf) | |
912 | #define RRR_S (((b1) & 0xf0) >> 4) | |
913 | #define RRR_T ((b0) & 0xf) | |
914 | #else | |
915 | #define OP0 (((b0) & 0xf)) | |
916 | #define OP1 (((b2) & 0xf)) | |
917 | #define OP2 (((b2) & 0xf0) >> 4) | |
918 | #define RRR_R (((b1) & 0xf0) >> 4) | |
919 | #define RRR_S (((b1) & 0xf)) | |
920 | #define RRR_T (((b0) & 0xf0) >> 4) | |
921 | #endif | |
6825b6c3 MF |
922 | #define RRR_X ((RRR_R & 0x4) >> 2) |
923 | #define RRR_Y ((RRR_T & 0x4) >> 2) | |
924 | #define RRR_W (RRR_R & 0x3) | |
dedc5eae MF |
925 | |
926 | #define RRRN_R RRR_R | |
927 | #define RRRN_S RRR_S | |
928 | #define RRRN_T RRR_T | |
929 | ||
65026682 MF |
930 | #define RRI4_R RRR_R |
931 | #define RRI4_S RRR_S | |
932 | #define RRI4_T RRR_T | |
933 | #ifdef TARGET_WORDS_BIGENDIAN | |
934 | #define RRI4_IMM4 ((b2) & 0xf) | |
935 | #else | |
936 | #define RRI4_IMM4 (((b2) & 0xf0) >> 4) | |
937 | #endif | |
938 | ||
dedc5eae MF |
939 | #define RRI8_R RRR_R |
940 | #define RRI8_S RRR_S | |
941 | #define RRI8_T RRR_T | |
942 | #define RRI8_IMM8 (b2) | |
943 | #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8) | |
944 | ||
945 | #ifdef TARGET_WORDS_BIGENDIAN | |
946 | #define RI16_IMM16 (((b1) << 8) | (b2)) | |
947 | #else | |
948 | #define RI16_IMM16 (((b2) << 8) | (b1)) | |
949 | #endif | |
950 | ||
951 | #ifdef TARGET_WORDS_BIGENDIAN | |
952 | #define CALL_N (((b0) & 0xc) >> 2) | |
953 | #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2)) | |
954 | #else | |
955 | #define CALL_N (((b0) & 0x30) >> 4) | |
956 | #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10)) | |
957 | #endif | |
958 | #define CALL_OFFSET_SE \ | |
959 | (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET) | |
960 | ||
961 | #define CALLX_N CALL_N | |
962 | #ifdef TARGET_WORDS_BIGENDIAN | |
963 | #define CALLX_M ((b0) & 0x3) | |
964 | #else | |
965 | #define CALLX_M (((b0) & 0xc0) >> 6) | |
966 | #endif | |
967 | #define CALLX_S RRR_S | |
968 | ||
969 | #define BRI12_M CALLX_M | |
970 | #define BRI12_S RRR_S | |
971 | #ifdef TARGET_WORDS_BIGENDIAN | |
972 | #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2)) | |
973 | #else | |
974 | #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4)) | |
975 | #endif | |
976 | #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12) | |
977 | ||
978 | #define BRI8_M BRI12_M | |
979 | #define BRI8_R RRI8_R | |
980 | #define BRI8_S RRI8_S | |
981 | #define BRI8_IMM8 RRI8_IMM8 | |
982 | #define BRI8_IMM8_SE RRI8_IMM8_SE | |
983 | ||
984 | #define RSR_SR (b1) | |
985 | ||
0c4fabea BS |
986 | uint8_t b0 = cpu_ldub_code(env, dc->pc); |
987 | uint8_t b1 = cpu_ldub_code(env, dc->pc + 1); | |
a044ec2a | 988 | uint8_t b2 = 0; |
dedc5eae | 989 | |
bd57fb91 MF |
990 | static const uint32_t B4CONST[] = { |
991 | 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256 | |
992 | }; | |
993 | ||
994 | static const uint32_t B4CONSTU[] = { | |
995 | 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256 | |
996 | }; | |
997 | ||
dedc5eae MF |
998 | if (OP0 >= 8) { |
999 | dc->next_pc = dc->pc + 2; | |
1000 | HAS_OPTION(XTENSA_OPTION_CODE_DENSITY); | |
1001 | } else { | |
1002 | dc->next_pc = dc->pc + 3; | |
0c4fabea | 1003 | b2 = cpu_ldub_code(env, dc->pc + 2); |
dedc5eae MF |
1004 | } |
1005 | ||
1006 | switch (OP0) { | |
1007 | case 0: /*QRST*/ | |
1008 | switch (OP1) { | |
1009 | case 0: /*RST0*/ | |
1010 | switch (OP2) { | |
1011 | case 0: /*ST0*/ | |
1012 | if ((RRR_R & 0xc) == 0x8) { | |
1013 | HAS_OPTION(XTENSA_OPTION_BOOLEAN); | |
1014 | } | |
1015 | ||
1016 | switch (RRR_R) { | |
1017 | case 0: /*SNM0*/ | |
5da4a6a8 MF |
1018 | switch (CALLX_M) { |
1019 | case 0: /*ILL*/ | |
40643d7c | 1020 | gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE); |
5da4a6a8 MF |
1021 | break; |
1022 | ||
1023 | case 1: /*reserved*/ | |
91a5bb76 | 1024 | RESERVED(); |
5da4a6a8 MF |
1025 | break; |
1026 | ||
1027 | case 2: /*JR*/ | |
1028 | switch (CALLX_N) { | |
1029 | case 0: /*RET*/ | |
1030 | case 2: /*JX*/ | |
772177c1 | 1031 | gen_window_check1(dc, CALLX_S); |
5da4a6a8 MF |
1032 | gen_jump(dc, cpu_R[CALLX_S]); |
1033 | break; | |
1034 | ||
1035 | case 1: /*RETWw*/ | |
1036 | HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); | |
553e44f9 MF |
1037 | { |
1038 | TCGv_i32 tmp = tcg_const_i32(dc->pc); | |
b994e91b | 1039 | gen_advance_ccount(dc); |
f492b82d | 1040 | gen_helper_retw(tmp, cpu_env, tmp); |
553e44f9 MF |
1041 | gen_jump(dc, tmp); |
1042 | tcg_temp_free(tmp); | |
1043 | } | |
5da4a6a8 MF |
1044 | break; |
1045 | ||
1046 | case 3: /*reserved*/ | |
91a5bb76 | 1047 | RESERVED(); |
5da4a6a8 MF |
1048 | break; |
1049 | } | |
1050 | break; | |
1051 | ||
1052 | case 3: /*CALLX*/ | |
772177c1 | 1053 | gen_window_check2(dc, CALLX_S, CALLX_N << 2); |
5da4a6a8 MF |
1054 | switch (CALLX_N) { |
1055 | case 0: /*CALLX0*/ | |
1056 | { | |
1057 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
1058 | tcg_gen_mov_i32(tmp, cpu_R[CALLX_S]); | |
1059 | tcg_gen_movi_i32(cpu_R[0], dc->next_pc); | |
1060 | gen_jump(dc, tmp); | |
1061 | tcg_temp_free(tmp); | |
1062 | } | |
1063 | break; | |
1064 | ||
1065 | case 1: /*CALLX4w*/ | |
1066 | case 2: /*CALLX8w*/ | |
1067 | case 3: /*CALLX12w*/ | |
1068 | HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); | |
553e44f9 MF |
1069 | { |
1070 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
1071 | ||
1072 | tcg_gen_mov_i32(tmp, cpu_R[CALLX_S]); | |
1073 | gen_callw(dc, CALLX_N, tmp); | |
1074 | tcg_temp_free(tmp); | |
1075 | } | |
5da4a6a8 MF |
1076 | break; |
1077 | } | |
1078 | break; | |
1079 | } | |
dedc5eae MF |
1080 | break; |
1081 | ||
1082 | case 1: /*MOVSPw*/ | |
1083 | HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); | |
772177c1 | 1084 | gen_window_check2(dc, RRR_T, RRR_S); |
553e44f9 MF |
1085 | { |
1086 | TCGv_i32 pc = tcg_const_i32(dc->pc); | |
b994e91b | 1087 | gen_advance_ccount(dc); |
f492b82d | 1088 | gen_helper_movsp(cpu_env, pc); |
553e44f9 MF |
1089 | tcg_gen_mov_i32(cpu_R[RRR_T], cpu_R[RRR_S]); |
1090 | tcg_temp_free(pc); | |
1091 | } | |
dedc5eae MF |
1092 | break; |
1093 | ||
1094 | case 2: /*SYNC*/ | |
28067b22 MF |
1095 | switch (RRR_T) { |
1096 | case 0: /*ISYNC*/ | |
1097 | break; | |
1098 | ||
1099 | case 1: /*RSYNC*/ | |
1100 | break; | |
1101 | ||
1102 | case 2: /*ESYNC*/ | |
1103 | break; | |
1104 | ||
1105 | case 3: /*DSYNC*/ | |
1106 | break; | |
1107 | ||
1108 | case 8: /*EXCW*/ | |
1109 | HAS_OPTION(XTENSA_OPTION_EXCEPTION); | |
1110 | break; | |
1111 | ||
1112 | case 12: /*MEMW*/ | |
1113 | break; | |
1114 | ||
1115 | case 13: /*EXTW*/ | |
1116 | break; | |
1117 | ||
1118 | case 15: /*NOP*/ | |
1119 | break; | |
1120 | ||
1121 | default: /*reserved*/ | |
1122 | RESERVED(); | |
1123 | break; | |
1124 | } | |
91a5bb76 MF |
1125 | break; |
1126 | ||
1127 | case 3: /*RFEIx*/ | |
40643d7c MF |
1128 | switch (RRR_T) { |
1129 | case 0: /*RFETx*/ | |
1130 | HAS_OPTION(XTENSA_OPTION_EXCEPTION); | |
1131 | switch (RRR_S) { | |
1132 | case 0: /*RFEx*/ | |
1133 | gen_check_privilege(dc); | |
1134 | tcg_gen_andi_i32(cpu_SR[PS], cpu_SR[PS], ~PS_EXCM); | |
b994e91b | 1135 | gen_helper_check_interrupts(cpu_env); |
40643d7c MF |
1136 | gen_jump(dc, cpu_SR[EPC1]); |
1137 | break; | |
1138 | ||
1139 | case 1: /*RFUEx*/ | |
1140 | RESERVED(); | |
1141 | break; | |
1142 | ||
1143 | case 2: /*RFDEx*/ | |
1144 | gen_check_privilege(dc); | |
1145 | gen_jump(dc, cpu_SR[ | |
1146 | dc->config->ndepc ? DEPC : EPC1]); | |
1147 | break; | |
1148 | ||
1149 | case 4: /*RFWOw*/ | |
1150 | case 5: /*RFWUw*/ | |
1151 | HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); | |
553e44f9 MF |
1152 | gen_check_privilege(dc); |
1153 | { | |
1154 | TCGv_i32 tmp = tcg_const_i32(1); | |
1155 | ||
1156 | tcg_gen_andi_i32( | |
1157 | cpu_SR[PS], cpu_SR[PS], ~PS_EXCM); | |
1158 | tcg_gen_shl_i32(tmp, tmp, cpu_SR[WINDOW_BASE]); | |
1159 | ||
1160 | if (RRR_S == 4) { | |
1161 | tcg_gen_andc_i32(cpu_SR[WINDOW_START], | |
1162 | cpu_SR[WINDOW_START], tmp); | |
1163 | } else { | |
1164 | tcg_gen_or_i32(cpu_SR[WINDOW_START], | |
1165 | cpu_SR[WINDOW_START], tmp); | |
1166 | } | |
1167 | ||
f492b82d | 1168 | gen_helper_restore_owb(cpu_env); |
b994e91b | 1169 | gen_helper_check_interrupts(cpu_env); |
553e44f9 MF |
1170 | gen_jump(dc, cpu_SR[EPC1]); |
1171 | ||
1172 | tcg_temp_free(tmp); | |
1173 | } | |
40643d7c MF |
1174 | break; |
1175 | ||
1176 | default: /*reserved*/ | |
1177 | RESERVED(); | |
1178 | break; | |
1179 | } | |
1180 | break; | |
1181 | ||
1182 | case 1: /*RFIx*/ | |
1183 | HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT); | |
b994e91b MF |
1184 | if (RRR_S >= 2 && RRR_S <= dc->config->nlevel) { |
1185 | gen_check_privilege(dc); | |
1186 | tcg_gen_mov_i32(cpu_SR[PS], | |
1187 | cpu_SR[EPS2 + RRR_S - 2]); | |
1188 | gen_helper_check_interrupts(cpu_env); | |
1189 | gen_jump(dc, cpu_SR[EPC1 + RRR_S - 1]); | |
1190 | } else { | |
1191 | qemu_log("RFI %d is illegal\n", RRR_S); | |
1192 | gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE); | |
1193 | } | |
40643d7c MF |
1194 | break; |
1195 | ||
1196 | case 2: /*RFME*/ | |
1197 | TBD(); | |
1198 | break; | |
1199 | ||
1200 | default: /*reserved*/ | |
1201 | RESERVED(); | |
1202 | break; | |
1203 | ||
1204 | } | |
91a5bb76 MF |
1205 | break; |
1206 | ||
1207 | case 4: /*BREAKx*/ | |
e61dc8f7 MF |
1208 | HAS_OPTION(XTENSA_OPTION_DEBUG); |
1209 | if (dc->debug) { | |
1210 | gen_debug_exception(dc, DEBUGCAUSE_BI); | |
1211 | } | |
91a5bb76 MF |
1212 | break; |
1213 | ||
1214 | case 5: /*SYSCALLx*/ | |
1215 | HAS_OPTION(XTENSA_OPTION_EXCEPTION); | |
40643d7c MF |
1216 | switch (RRR_S) { |
1217 | case 0: /*SYSCALLx*/ | |
1218 | gen_exception_cause(dc, SYSCALL_CAUSE); | |
1219 | break; | |
1220 | ||
1221 | case 1: /*SIMCALL*/ | |
1ddeaa5d MF |
1222 | if (semihosting_enabled) { |
1223 | gen_check_privilege(dc); | |
1224 | gen_helper_simcall(cpu_env); | |
1225 | } else { | |
1226 | qemu_log("SIMCALL but semihosting is disabled\n"); | |
1227 | gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE); | |
1228 | } | |
40643d7c MF |
1229 | break; |
1230 | ||
1231 | default: | |
1232 | RESERVED(); | |
1233 | break; | |
1234 | } | |
91a5bb76 MF |
1235 | break; |
1236 | ||
1237 | case 6: /*RSILx*/ | |
1238 | HAS_OPTION(XTENSA_OPTION_INTERRUPT); | |
40643d7c | 1239 | gen_check_privilege(dc); |
772177c1 | 1240 | gen_window_check1(dc, RRR_T); |
40643d7c | 1241 | tcg_gen_mov_i32(cpu_R[RRR_T], cpu_SR[PS]); |
b994e91b | 1242 | tcg_gen_andi_i32(cpu_SR[PS], cpu_SR[PS], ~PS_INTLEVEL); |
40643d7c | 1243 | tcg_gen_ori_i32(cpu_SR[PS], cpu_SR[PS], RRR_S); |
b994e91b MF |
1244 | gen_helper_check_interrupts(cpu_env); |
1245 | gen_jumpi_check_loop_end(dc, 0); | |
91a5bb76 MF |
1246 | break; |
1247 | ||
1248 | case 7: /*WAITIx*/ | |
1249 | HAS_OPTION(XTENSA_OPTION_INTERRUPT); | |
b994e91b MF |
1250 | gen_check_privilege(dc); |
1251 | gen_waiti(dc, RRR_S); | |
91a5bb76 MF |
1252 | break; |
1253 | ||
1254 | case 8: /*ANY4p*/ | |
91a5bb76 | 1255 | case 9: /*ALL4p*/ |
91a5bb76 | 1256 | case 10: /*ANY8p*/ |
91a5bb76 MF |
1257 | case 11: /*ALL8p*/ |
1258 | HAS_OPTION(XTENSA_OPTION_BOOLEAN); | |
4dd85b6b MF |
1259 | { |
1260 | const unsigned shift = (RRR_R & 2) ? 8 : 4; | |
1261 | TCGv_i32 mask = tcg_const_i32( | |
1262 | ((1 << shift) - 1) << RRR_S); | |
1263 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
1264 | ||
1265 | tcg_gen_and_i32(tmp, cpu_SR[BR], mask); | |
1266 | if (RRR_R & 1) { /*ALL*/ | |
1267 | tcg_gen_addi_i32(tmp, tmp, 1 << RRR_S); | |
1268 | } else { /*ANY*/ | |
1269 | tcg_gen_add_i32(tmp, tmp, mask); | |
1270 | } | |
1271 | tcg_gen_shri_i32(tmp, tmp, RRR_S + shift); | |
1272 | tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], | |
1273 | tmp, RRR_T, 1); | |
1274 | tcg_temp_free(mask); | |
1275 | tcg_temp_free(tmp); | |
1276 | } | |
91a5bb76 MF |
1277 | break; |
1278 | ||
1279 | default: /*reserved*/ | |
1280 | RESERVED(); | |
dedc5eae MF |
1281 | break; |
1282 | ||
1283 | } | |
1284 | break; | |
1285 | ||
1286 | case 1: /*AND*/ | |
772177c1 | 1287 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
dedc5eae MF |
1288 | tcg_gen_and_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); |
1289 | break; | |
1290 | ||
1291 | case 2: /*OR*/ | |
772177c1 | 1292 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
dedc5eae MF |
1293 | tcg_gen_or_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); |
1294 | break; | |
1295 | ||
1296 | case 3: /*XOR*/ | |
772177c1 | 1297 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
dedc5eae MF |
1298 | tcg_gen_xor_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); |
1299 | break; | |
1300 | ||
1301 | case 4: /*ST1*/ | |
3580ecad MF |
1302 | switch (RRR_R) { |
1303 | case 0: /*SSR*/ | |
772177c1 | 1304 | gen_window_check1(dc, RRR_S); |
3580ecad MF |
1305 | gen_right_shift_sar(dc, cpu_R[RRR_S]); |
1306 | break; | |
1307 | ||
1308 | case 1: /*SSL*/ | |
772177c1 | 1309 | gen_window_check1(dc, RRR_S); |
3580ecad MF |
1310 | gen_left_shift_sar(dc, cpu_R[RRR_S]); |
1311 | break; | |
1312 | ||
1313 | case 2: /*SSA8L*/ | |
772177c1 | 1314 | gen_window_check1(dc, RRR_S); |
3580ecad MF |
1315 | { |
1316 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
1317 | tcg_gen_shli_i32(tmp, cpu_R[RRR_S], 3); | |
1318 | gen_right_shift_sar(dc, tmp); | |
1319 | tcg_temp_free(tmp); | |
1320 | } | |
1321 | break; | |
1322 | ||
1323 | case 3: /*SSA8B*/ | |
772177c1 | 1324 | gen_window_check1(dc, RRR_S); |
3580ecad MF |
1325 | { |
1326 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
1327 | tcg_gen_shli_i32(tmp, cpu_R[RRR_S], 3); | |
1328 | gen_left_shift_sar(dc, tmp); | |
1329 | tcg_temp_free(tmp); | |
1330 | } | |
1331 | break; | |
1332 | ||
1333 | case 4: /*SSAI*/ | |
1334 | { | |
1335 | TCGv_i32 tmp = tcg_const_i32( | |
1336 | RRR_S | ((RRR_T & 1) << 4)); | |
1337 | gen_right_shift_sar(dc, tmp); | |
1338 | tcg_temp_free(tmp); | |
1339 | } | |
1340 | break; | |
1341 | ||
1342 | case 6: /*RER*/ | |
91a5bb76 | 1343 | TBD(); |
3580ecad MF |
1344 | break; |
1345 | ||
1346 | case 7: /*WER*/ | |
91a5bb76 | 1347 | TBD(); |
3580ecad MF |
1348 | break; |
1349 | ||
1350 | case 8: /*ROTWw*/ | |
1351 | HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); | |
553e44f9 MF |
1352 | gen_check_privilege(dc); |
1353 | { | |
1354 | TCGv_i32 tmp = tcg_const_i32( | |
1355 | RRR_T | ((RRR_T & 8) ? 0xfffffff0 : 0)); | |
f492b82d | 1356 | gen_helper_rotw(cpu_env, tmp); |
553e44f9 | 1357 | tcg_temp_free(tmp); |
772177c1 | 1358 | reset_used_window(dc); |
553e44f9 | 1359 | } |
3580ecad MF |
1360 | break; |
1361 | ||
1362 | case 14: /*NSAu*/ | |
7f65f4b0 | 1363 | HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA); |
772177c1 | 1364 | gen_window_check2(dc, RRR_S, RRR_T); |
3580ecad MF |
1365 | gen_helper_nsa(cpu_R[RRR_T], cpu_R[RRR_S]); |
1366 | break; | |
1367 | ||
1368 | case 15: /*NSAUu*/ | |
7f65f4b0 | 1369 | HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA); |
772177c1 | 1370 | gen_window_check2(dc, RRR_S, RRR_T); |
3580ecad MF |
1371 | gen_helper_nsau(cpu_R[RRR_T], cpu_R[RRR_S]); |
1372 | break; | |
1373 | ||
1374 | default: /*reserved*/ | |
91a5bb76 | 1375 | RESERVED(); |
3580ecad MF |
1376 | break; |
1377 | } | |
dedc5eae MF |
1378 | break; |
1379 | ||
1380 | case 5: /*TLB*/ | |
b67ea0cd MF |
1381 | HAS_OPTION_BITS( |
1382 | XTENSA_OPTION_BIT(XTENSA_OPTION_MMU) | | |
1383 | XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION) | | |
1384 | XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION)); | |
1385 | gen_check_privilege(dc); | |
1386 | gen_window_check2(dc, RRR_S, RRR_T); | |
1387 | { | |
1388 | TCGv_i32 dtlb = tcg_const_i32((RRR_R & 8) != 0); | |
1389 | ||
1390 | switch (RRR_R & 7) { | |
1391 | case 3: /*RITLB0*/ /*RDTLB0*/ | |
f492b82d MF |
1392 | gen_helper_rtlb0(cpu_R[RRR_T], |
1393 | cpu_env, cpu_R[RRR_S], dtlb); | |
b67ea0cd MF |
1394 | break; |
1395 | ||
1396 | case 4: /*IITLB*/ /*IDTLB*/ | |
f492b82d | 1397 | gen_helper_itlb(cpu_env, cpu_R[RRR_S], dtlb); |
b67ea0cd MF |
1398 | /* This could change memory mapping, so exit tb */ |
1399 | gen_jumpi_check_loop_end(dc, -1); | |
1400 | break; | |
1401 | ||
1402 | case 5: /*PITLB*/ /*PDTLB*/ | |
1403 | tcg_gen_movi_i32(cpu_pc, dc->pc); | |
f492b82d MF |
1404 | gen_helper_ptlb(cpu_R[RRR_T], |
1405 | cpu_env, cpu_R[RRR_S], dtlb); | |
b67ea0cd MF |
1406 | break; |
1407 | ||
1408 | case 6: /*WITLB*/ /*WDTLB*/ | |
f492b82d MF |
1409 | gen_helper_wtlb( |
1410 | cpu_env, cpu_R[RRR_T], cpu_R[RRR_S], dtlb); | |
b67ea0cd MF |
1411 | /* This could change memory mapping, so exit tb */ |
1412 | gen_jumpi_check_loop_end(dc, -1); | |
1413 | break; | |
1414 | ||
1415 | case 7: /*RITLB1*/ /*RDTLB1*/ | |
f492b82d MF |
1416 | gen_helper_rtlb1(cpu_R[RRR_T], |
1417 | cpu_env, cpu_R[RRR_S], dtlb); | |
b67ea0cd MF |
1418 | break; |
1419 | ||
1420 | default: | |
1421 | tcg_temp_free(dtlb); | |
1422 | RESERVED(); | |
1423 | break; | |
1424 | } | |
1425 | tcg_temp_free(dtlb); | |
1426 | } | |
dedc5eae MF |
1427 | break; |
1428 | ||
1429 | case 6: /*RT0*/ | |
772177c1 | 1430 | gen_window_check2(dc, RRR_R, RRR_T); |
f331fe5e MF |
1431 | switch (RRR_S) { |
1432 | case 0: /*NEG*/ | |
1433 | tcg_gen_neg_i32(cpu_R[RRR_R], cpu_R[RRR_T]); | |
1434 | break; | |
1435 | ||
1436 | case 1: /*ABS*/ | |
1437 | { | |
f877d09e MF |
1438 | TCGv_i32 zero = tcg_const_i32(0); |
1439 | TCGv_i32 neg = tcg_temp_new_i32(); | |
1440 | ||
1441 | tcg_gen_neg_i32(neg, cpu_R[RRR_T]); | |
1442 | tcg_gen_movcond_i32(TCG_COND_GE, cpu_R[RRR_R], | |
1443 | cpu_R[RRR_T], zero, cpu_R[RRR_T], neg); | |
1444 | tcg_temp_free(neg); | |
1445 | tcg_temp_free(zero); | |
f331fe5e MF |
1446 | } |
1447 | break; | |
1448 | ||
1449 | default: /*reserved*/ | |
91a5bb76 | 1450 | RESERVED(); |
f331fe5e MF |
1451 | break; |
1452 | } | |
dedc5eae MF |
1453 | break; |
1454 | ||
1455 | case 7: /*reserved*/ | |
91a5bb76 | 1456 | RESERVED(); |
dedc5eae MF |
1457 | break; |
1458 | ||
1459 | case 8: /*ADD*/ | |
772177c1 | 1460 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
dedc5eae MF |
1461 | tcg_gen_add_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); |
1462 | break; | |
1463 | ||
1464 | case 9: /*ADD**/ | |
1465 | case 10: | |
1466 | case 11: | |
772177c1 | 1467 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
dedc5eae MF |
1468 | { |
1469 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
1470 | tcg_gen_shli_i32(tmp, cpu_R[RRR_S], OP2 - 8); | |
1471 | tcg_gen_add_i32(cpu_R[RRR_R], tmp, cpu_R[RRR_T]); | |
1472 | tcg_temp_free(tmp); | |
1473 | } | |
1474 | break; | |
1475 | ||
1476 | case 12: /*SUB*/ | |
772177c1 | 1477 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
dedc5eae MF |
1478 | tcg_gen_sub_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); |
1479 | break; | |
1480 | ||
1481 | case 13: /*SUB**/ | |
1482 | case 14: | |
1483 | case 15: | |
772177c1 | 1484 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
dedc5eae MF |
1485 | { |
1486 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
1487 | tcg_gen_shli_i32(tmp, cpu_R[RRR_S], OP2 - 12); | |
1488 | tcg_gen_sub_i32(cpu_R[RRR_R], tmp, cpu_R[RRR_T]); | |
1489 | tcg_temp_free(tmp); | |
1490 | } | |
1491 | break; | |
1492 | } | |
1493 | break; | |
1494 | ||
1495 | case 1: /*RST1*/ | |
3580ecad MF |
1496 | switch (OP2) { |
1497 | case 0: /*SLLI*/ | |
1498 | case 1: | |
772177c1 | 1499 | gen_window_check2(dc, RRR_R, RRR_S); |
3580ecad MF |
1500 | tcg_gen_shli_i32(cpu_R[RRR_R], cpu_R[RRR_S], |
1501 | 32 - (RRR_T | ((OP2 & 1) << 4))); | |
1502 | break; | |
1503 | ||
1504 | case 2: /*SRAI*/ | |
1505 | case 3: | |
772177c1 | 1506 | gen_window_check2(dc, RRR_R, RRR_T); |
3580ecad MF |
1507 | tcg_gen_sari_i32(cpu_R[RRR_R], cpu_R[RRR_T], |
1508 | RRR_S | ((OP2 & 1) << 4)); | |
1509 | break; | |
1510 | ||
1511 | case 4: /*SRLI*/ | |
772177c1 | 1512 | gen_window_check2(dc, RRR_R, RRR_T); |
3580ecad MF |
1513 | tcg_gen_shri_i32(cpu_R[RRR_R], cpu_R[RRR_T], RRR_S); |
1514 | break; | |
1515 | ||
1516 | case 6: /*XSR*/ | |
0857a06e | 1517 | if (gen_check_sr(dc, RSR_SR, SR_X)) { |
3580ecad | 1518 | TCGv_i32 tmp = tcg_temp_new_i32(); |
0857a06e | 1519 | |
40643d7c MF |
1520 | if (RSR_SR >= 64) { |
1521 | gen_check_privilege(dc); | |
1522 | } | |
772177c1 | 1523 | gen_window_check1(dc, RRR_T); |
3580ecad MF |
1524 | tcg_gen_mov_i32(tmp, cpu_R[RRR_T]); |
1525 | gen_rsr(dc, cpu_R[RRR_T], RSR_SR); | |
1526 | gen_wsr(dc, RSR_SR, tmp); | |
1527 | tcg_temp_free(tmp); | |
1528 | } | |
1529 | break; | |
1530 | ||
1531 | /* | |
1532 | * Note: 64 bit ops are used here solely because SAR values | |
1533 | * have range 0..63 | |
1534 | */ | |
1535 | #define gen_shift_reg(cmd, reg) do { \ | |
1536 | TCGv_i64 tmp = tcg_temp_new_i64(); \ | |
1537 | tcg_gen_extu_i32_i64(tmp, reg); \ | |
1538 | tcg_gen_##cmd##_i64(v, v, tmp); \ | |
1539 | tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \ | |
1540 | tcg_temp_free_i64(v); \ | |
1541 | tcg_temp_free_i64(tmp); \ | |
1542 | } while (0) | |
1543 | ||
1544 | #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR]) | |
1545 | ||
1546 | case 8: /*SRC*/ | |
772177c1 | 1547 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
3580ecad MF |
1548 | { |
1549 | TCGv_i64 v = tcg_temp_new_i64(); | |
1550 | tcg_gen_concat_i32_i64(v, cpu_R[RRR_T], cpu_R[RRR_S]); | |
1551 | gen_shift(shr); | |
1552 | } | |
1553 | break; | |
1554 | ||
1555 | case 9: /*SRL*/ | |
772177c1 | 1556 | gen_window_check2(dc, RRR_R, RRR_T); |
3580ecad MF |
1557 | if (dc->sar_5bit) { |
1558 | tcg_gen_shr_i32(cpu_R[RRR_R], cpu_R[RRR_T], cpu_SR[SAR]); | |
1559 | } else { | |
1560 | TCGv_i64 v = tcg_temp_new_i64(); | |
1561 | tcg_gen_extu_i32_i64(v, cpu_R[RRR_T]); | |
1562 | gen_shift(shr); | |
1563 | } | |
1564 | break; | |
1565 | ||
1566 | case 10: /*SLL*/ | |
772177c1 | 1567 | gen_window_check2(dc, RRR_R, RRR_S); |
3580ecad MF |
1568 | if (dc->sar_m32_5bit) { |
1569 | tcg_gen_shl_i32(cpu_R[RRR_R], cpu_R[RRR_S], dc->sar_m32); | |
1570 | } else { | |
1571 | TCGv_i64 v = tcg_temp_new_i64(); | |
1572 | TCGv_i32 s = tcg_const_i32(32); | |
1573 | tcg_gen_sub_i32(s, s, cpu_SR[SAR]); | |
1574 | tcg_gen_andi_i32(s, s, 0x3f); | |
1575 | tcg_gen_extu_i32_i64(v, cpu_R[RRR_S]); | |
1576 | gen_shift_reg(shl, s); | |
1577 | tcg_temp_free(s); | |
1578 | } | |
1579 | break; | |
1580 | ||
1581 | case 11: /*SRA*/ | |
772177c1 | 1582 | gen_window_check2(dc, RRR_R, RRR_T); |
3580ecad MF |
1583 | if (dc->sar_5bit) { |
1584 | tcg_gen_sar_i32(cpu_R[RRR_R], cpu_R[RRR_T], cpu_SR[SAR]); | |
1585 | } else { | |
1586 | TCGv_i64 v = tcg_temp_new_i64(); | |
1587 | tcg_gen_ext_i32_i64(v, cpu_R[RRR_T]); | |
1588 | gen_shift(sar); | |
1589 | } | |
1590 | break; | |
1591 | #undef gen_shift | |
1592 | #undef gen_shift_reg | |
1593 | ||
1594 | case 12: /*MUL16U*/ | |
1595 | HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL); | |
772177c1 | 1596 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
3580ecad MF |
1597 | { |
1598 | TCGv_i32 v1 = tcg_temp_new_i32(); | |
1599 | TCGv_i32 v2 = tcg_temp_new_i32(); | |
1600 | tcg_gen_ext16u_i32(v1, cpu_R[RRR_S]); | |
1601 | tcg_gen_ext16u_i32(v2, cpu_R[RRR_T]); | |
1602 | tcg_gen_mul_i32(cpu_R[RRR_R], v1, v2); | |
1603 | tcg_temp_free(v2); | |
1604 | tcg_temp_free(v1); | |
1605 | } | |
1606 | break; | |
1607 | ||
1608 | case 13: /*MUL16S*/ | |
1609 | HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL); | |
772177c1 | 1610 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
3580ecad MF |
1611 | { |
1612 | TCGv_i32 v1 = tcg_temp_new_i32(); | |
1613 | TCGv_i32 v2 = tcg_temp_new_i32(); | |
1614 | tcg_gen_ext16s_i32(v1, cpu_R[RRR_S]); | |
1615 | tcg_gen_ext16s_i32(v2, cpu_R[RRR_T]); | |
1616 | tcg_gen_mul_i32(cpu_R[RRR_R], v1, v2); | |
1617 | tcg_temp_free(v2); | |
1618 | tcg_temp_free(v1); | |
1619 | } | |
1620 | break; | |
1621 | ||
1622 | default: /*reserved*/ | |
91a5bb76 | 1623 | RESERVED(); |
3580ecad MF |
1624 | break; |
1625 | } | |
dedc5eae MF |
1626 | break; |
1627 | ||
1628 | case 2: /*RST2*/ | |
4dd85b6b MF |
1629 | if (OP2 >= 8) { |
1630 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); | |
1631 | } | |
772177c1 | 1632 | |
f76ebf55 MF |
1633 | if (OP2 >= 12) { |
1634 | HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV); | |
1635 | int label = gen_new_label(); | |
1636 | tcg_gen_brcondi_i32(TCG_COND_NE, cpu_R[RRR_T], 0, label); | |
1637 | gen_exception_cause(dc, INTEGER_DIVIDE_BY_ZERO_CAUSE); | |
1638 | gen_set_label(label); | |
1639 | } | |
1640 | ||
1641 | switch (OP2) { | |
4dd85b6b MF |
1642 | #define BOOLEAN_LOGIC(fn, r, s, t) \ |
1643 | do { \ | |
1644 | HAS_OPTION(XTENSA_OPTION_BOOLEAN); \ | |
1645 | TCGv_i32 tmp1 = tcg_temp_new_i32(); \ | |
1646 | TCGv_i32 tmp2 = tcg_temp_new_i32(); \ | |
1647 | \ | |
1648 | tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \ | |
1649 | tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \ | |
1650 | tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \ | |
1651 | tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \ | |
1652 | tcg_temp_free(tmp1); \ | |
1653 | tcg_temp_free(tmp2); \ | |
1654 | } while (0) | |
1655 | ||
1656 | case 0: /*ANDBp*/ | |
1657 | BOOLEAN_LOGIC(and, RRR_R, RRR_S, RRR_T); | |
1658 | break; | |
1659 | ||
1660 | case 1: /*ANDBCp*/ | |
1661 | BOOLEAN_LOGIC(andc, RRR_R, RRR_S, RRR_T); | |
1662 | break; | |
1663 | ||
1664 | case 2: /*ORBp*/ | |
1665 | BOOLEAN_LOGIC(or, RRR_R, RRR_S, RRR_T); | |
1666 | break; | |
1667 | ||
1668 | case 3: /*ORBCp*/ | |
1669 | BOOLEAN_LOGIC(orc, RRR_R, RRR_S, RRR_T); | |
1670 | break; | |
1671 | ||
1672 | case 4: /*XORBp*/ | |
1673 | BOOLEAN_LOGIC(xor, RRR_R, RRR_S, RRR_T); | |
1674 | break; | |
1675 | ||
1676 | #undef BOOLEAN_LOGIC | |
1677 | ||
f76ebf55 MF |
1678 | case 8: /*MULLi*/ |
1679 | HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL); | |
1680 | tcg_gen_mul_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); | |
1681 | break; | |
1682 | ||
1683 | case 10: /*MULUHi*/ | |
1684 | case 11: /*MULSHi*/ | |
7f65f4b0 | 1685 | HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH); |
f76ebf55 | 1686 | { |
c9cda20b | 1687 | TCGv lo = tcg_temp_new(); |
f76ebf55 MF |
1688 | |
1689 | if (OP2 == 10) { | |
c9cda20b RH |
1690 | tcg_gen_mulu2_i32(lo, cpu_R[RRR_R], |
1691 | cpu_R[RRR_S], cpu_R[RRR_T]); | |
f76ebf55 | 1692 | } else { |
c9cda20b RH |
1693 | tcg_gen_muls2_i32(lo, cpu_R[RRR_R], |
1694 | cpu_R[RRR_S], cpu_R[RRR_T]); | |
f76ebf55 | 1695 | } |
c9cda20b | 1696 | tcg_temp_free(lo); |
f76ebf55 MF |
1697 | } |
1698 | break; | |
1699 | ||
1700 | case 12: /*QUOUi*/ | |
1701 | tcg_gen_divu_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); | |
1702 | break; | |
1703 | ||
1704 | case 13: /*QUOSi*/ | |
1705 | case 15: /*REMSi*/ | |
1706 | { | |
1707 | int label1 = gen_new_label(); | |
1708 | int label2 = gen_new_label(); | |
1709 | ||
1710 | tcg_gen_brcondi_i32(TCG_COND_NE, cpu_R[RRR_S], 0x80000000, | |
1711 | label1); | |
1712 | tcg_gen_brcondi_i32(TCG_COND_NE, cpu_R[RRR_T], 0xffffffff, | |
1713 | label1); | |
1714 | tcg_gen_movi_i32(cpu_R[RRR_R], | |
1715 | OP2 == 13 ? 0x80000000 : 0); | |
1716 | tcg_gen_br(label2); | |
1717 | gen_set_label(label1); | |
1718 | if (OP2 == 13) { | |
1719 | tcg_gen_div_i32(cpu_R[RRR_R], | |
1720 | cpu_R[RRR_S], cpu_R[RRR_T]); | |
1721 | } else { | |
1722 | tcg_gen_rem_i32(cpu_R[RRR_R], | |
1723 | cpu_R[RRR_S], cpu_R[RRR_T]); | |
1724 | } | |
1725 | gen_set_label(label2); | |
1726 | } | |
1727 | break; | |
1728 | ||
1729 | case 14: /*REMUi*/ | |
1730 | tcg_gen_remu_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]); | |
1731 | break; | |
1732 | ||
1733 | default: /*reserved*/ | |
1734 | RESERVED(); | |
1735 | break; | |
1736 | } | |
dedc5eae MF |
1737 | break; |
1738 | ||
1739 | case 3: /*RST3*/ | |
b8132eff MF |
1740 | switch (OP2) { |
1741 | case 0: /*RSR*/ | |
0857a06e MF |
1742 | if (gen_check_sr(dc, RSR_SR, SR_R)) { |
1743 | if (RSR_SR >= 64) { | |
1744 | gen_check_privilege(dc); | |
1745 | } | |
1746 | gen_window_check1(dc, RRR_T); | |
1747 | gen_rsr(dc, cpu_R[RRR_T], RSR_SR); | |
40643d7c | 1748 | } |
b8132eff MF |
1749 | break; |
1750 | ||
1751 | case 1: /*WSR*/ | |
0857a06e MF |
1752 | if (gen_check_sr(dc, RSR_SR, SR_W)) { |
1753 | if (RSR_SR >= 64) { | |
1754 | gen_check_privilege(dc); | |
1755 | } | |
1756 | gen_window_check1(dc, RRR_T); | |
1757 | gen_wsr(dc, RSR_SR, cpu_R[RRR_T]); | |
40643d7c | 1758 | } |
b8132eff MF |
1759 | break; |
1760 | ||
1761 | case 2: /*SEXTu*/ | |
7f65f4b0 | 1762 | HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT); |
772177c1 | 1763 | gen_window_check2(dc, RRR_R, RRR_S); |
b8132eff MF |
1764 | { |
1765 | int shift = 24 - RRR_T; | |
1766 | ||
1767 | if (shift == 24) { | |
1768 | tcg_gen_ext8s_i32(cpu_R[RRR_R], cpu_R[RRR_S]); | |
1769 | } else if (shift == 16) { | |
1770 | tcg_gen_ext16s_i32(cpu_R[RRR_R], cpu_R[RRR_S]); | |
1771 | } else { | |
1772 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
1773 | tcg_gen_shli_i32(tmp, cpu_R[RRR_S], shift); | |
1774 | tcg_gen_sari_i32(cpu_R[RRR_R], tmp, shift); | |
1775 | tcg_temp_free(tmp); | |
1776 | } | |
1777 | } | |
1778 | break; | |
1779 | ||
1780 | case 3: /*CLAMPSu*/ | |
7f65f4b0 | 1781 | HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS); |
772177c1 | 1782 | gen_window_check2(dc, RRR_R, RRR_S); |
b8132eff MF |
1783 | { |
1784 | TCGv_i32 tmp1 = tcg_temp_new_i32(); | |
1785 | TCGv_i32 tmp2 = tcg_temp_new_i32(); | |
f877d09e | 1786 | TCGv_i32 zero = tcg_const_i32(0); |
b8132eff MF |
1787 | |
1788 | tcg_gen_sari_i32(tmp1, cpu_R[RRR_S], 24 - RRR_T); | |
1789 | tcg_gen_xor_i32(tmp2, tmp1, cpu_R[RRR_S]); | |
1790 | tcg_gen_andi_i32(tmp2, tmp2, 0xffffffff << (RRR_T + 7)); | |
b8132eff MF |
1791 | |
1792 | tcg_gen_sari_i32(tmp1, cpu_R[RRR_S], 31); | |
f877d09e | 1793 | tcg_gen_xori_i32(tmp1, tmp1, 0xffffffff >> (25 - RRR_T)); |
b8132eff | 1794 | |
f877d09e MF |
1795 | tcg_gen_movcond_i32(TCG_COND_EQ, cpu_R[RRR_R], tmp2, zero, |
1796 | cpu_R[RRR_S], tmp1); | |
b8132eff MF |
1797 | tcg_temp_free(tmp1); |
1798 | tcg_temp_free(tmp2); | |
f877d09e | 1799 | tcg_temp_free(zero); |
b8132eff MF |
1800 | } |
1801 | break; | |
1802 | ||
1803 | case 4: /*MINu*/ | |
1804 | case 5: /*MAXu*/ | |
1805 | case 6: /*MINUu*/ | |
1806 | case 7: /*MAXUu*/ | |
7f65f4b0 | 1807 | HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX); |
772177c1 | 1808 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
b8132eff MF |
1809 | { |
1810 | static const TCGCond cond[] = { | |
1811 | TCG_COND_LE, | |
1812 | TCG_COND_GE, | |
1813 | TCG_COND_LEU, | |
1814 | TCG_COND_GEU | |
1815 | }; | |
f877d09e MF |
1816 | tcg_gen_movcond_i32(cond[OP2 - 4], cpu_R[RRR_R], |
1817 | cpu_R[RRR_S], cpu_R[RRR_T], | |
1818 | cpu_R[RRR_S], cpu_R[RRR_T]); | |
b8132eff MF |
1819 | } |
1820 | break; | |
1821 | ||
1822 | case 8: /*MOVEQZ*/ | |
1823 | case 9: /*MOVNEZ*/ | |
1824 | case 10: /*MOVLTZ*/ | |
1825 | case 11: /*MOVGEZ*/ | |
772177c1 | 1826 | gen_window_check3(dc, RRR_R, RRR_S, RRR_T); |
b8132eff MF |
1827 | { |
1828 | static const TCGCond cond[] = { | |
b8132eff | 1829 | TCG_COND_EQ, |
f877d09e MF |
1830 | TCG_COND_NE, |
1831 | TCG_COND_LT, | |
b8132eff | 1832 | TCG_COND_GE, |
b8132eff | 1833 | }; |
f877d09e MF |
1834 | TCGv_i32 zero = tcg_const_i32(0); |
1835 | ||
1836 | tcg_gen_movcond_i32(cond[OP2 - 8], cpu_R[RRR_R], | |
1837 | cpu_R[RRR_T], zero, cpu_R[RRR_S], cpu_R[RRR_R]); | |
1838 | tcg_temp_free(zero); | |
b8132eff MF |
1839 | } |
1840 | break; | |
1841 | ||
1842 | case 12: /*MOVFp*/ | |
b8132eff MF |
1843 | case 13: /*MOVTp*/ |
1844 | HAS_OPTION(XTENSA_OPTION_BOOLEAN); | |
4dd85b6b MF |
1845 | gen_window_check2(dc, RRR_R, RRR_S); |
1846 | { | |
f877d09e | 1847 | TCGv_i32 zero = tcg_const_i32(0); |
4dd85b6b MF |
1848 | TCGv_i32 tmp = tcg_temp_new_i32(); |
1849 | ||
1850 | tcg_gen_andi_i32(tmp, cpu_SR[BR], 1 << RRR_T); | |
f877d09e MF |
1851 | tcg_gen_movcond_i32(OP2 & 1 ? TCG_COND_NE : TCG_COND_EQ, |
1852 | cpu_R[RRR_R], tmp, zero, | |
1853 | cpu_R[RRR_S], cpu_R[RRR_R]); | |
1854 | ||
4dd85b6b | 1855 | tcg_temp_free(tmp); |
f877d09e | 1856 | tcg_temp_free(zero); |
4dd85b6b | 1857 | } |
b8132eff MF |
1858 | break; |
1859 | ||
1860 | case 14: /*RUR*/ | |
772177c1 | 1861 | gen_window_check1(dc, RRR_R); |
b8132eff MF |
1862 | { |
1863 | int st = (RRR_S << 4) + RRR_T; | |
fe0bd475 | 1864 | if (uregnames[st].name) { |
b8132eff MF |
1865 | tcg_gen_mov_i32(cpu_R[RRR_R], cpu_UR[st]); |
1866 | } else { | |
1867 | qemu_log("RUR %d not implemented, ", st); | |
91a5bb76 | 1868 | TBD(); |
b8132eff MF |
1869 | } |
1870 | } | |
1871 | break; | |
1872 | ||
1873 | case 15: /*WUR*/ | |
772177c1 | 1874 | gen_window_check1(dc, RRR_T); |
fe0bd475 | 1875 | if (uregnames[RSR_SR].name) { |
dd519cbe MF |
1876 | gen_wur(RSR_SR, cpu_R[RRR_T]); |
1877 | } else { | |
1878 | qemu_log("WUR %d not implemented, ", RSR_SR); | |
1879 | TBD(); | |
b8132eff MF |
1880 | } |
1881 | break; | |
1882 | ||
1883 | } | |
dedc5eae MF |
1884 | break; |
1885 | ||
1886 | case 4: /*EXTUI*/ | |
1887 | case 5: | |
772177c1 | 1888 | gen_window_check2(dc, RRR_R, RRR_T); |
3580ecad | 1889 | { |
f9cb5045 | 1890 | int shiftimm = RRR_S | ((OP1 & 1) << 4); |
3580ecad MF |
1891 | int maskimm = (1 << (OP2 + 1)) - 1; |
1892 | ||
1893 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
f783cb22 AJ |
1894 | tcg_gen_shri_i32(tmp, cpu_R[RRR_T], shiftimm); |
1895 | tcg_gen_andi_i32(cpu_R[RRR_R], tmp, maskimm); | |
3580ecad MF |
1896 | tcg_temp_free(tmp); |
1897 | } | |
dedc5eae MF |
1898 | break; |
1899 | ||
1900 | case 6: /*CUST0*/ | |
91a5bb76 | 1901 | RESERVED(); |
dedc5eae MF |
1902 | break; |
1903 | ||
1904 | case 7: /*CUST1*/ | |
91a5bb76 | 1905 | RESERVED(); |
dedc5eae MF |
1906 | break; |
1907 | ||
1908 | case 8: /*LSCXp*/ | |
9ed7ae12 MF |
1909 | switch (OP2) { |
1910 | case 0: /*LSXf*/ | |
1911 | case 1: /*LSXUf*/ | |
1912 | case 4: /*SSXf*/ | |
1913 | case 5: /*SSXUf*/ | |
1914 | HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR); | |
1915 | gen_window_check2(dc, RRR_S, RRR_T); | |
ef04a846 | 1916 | gen_check_cpenable(dc, 0); |
9ed7ae12 MF |
1917 | { |
1918 | TCGv_i32 addr = tcg_temp_new_i32(); | |
1919 | tcg_gen_add_i32(addr, cpu_R[RRR_S], cpu_R[RRR_T]); | |
1920 | gen_load_store_alignment(dc, 2, addr, false); | |
1921 | if (OP2 & 0x4) { | |
1922 | tcg_gen_qemu_st32(cpu_FR[RRR_R], addr, dc->cring); | |
1923 | } else { | |
1924 | tcg_gen_qemu_ld32u(cpu_FR[RRR_R], addr, dc->cring); | |
1925 | } | |
1926 | if (OP2 & 0x1) { | |
1927 | tcg_gen_mov_i32(cpu_R[RRR_S], addr); | |
1928 | } | |
1929 | tcg_temp_free(addr); | |
1930 | } | |
1931 | break; | |
1932 | ||
1933 | default: /*reserved*/ | |
1934 | RESERVED(); | |
1935 | break; | |
1936 | } | |
dedc5eae MF |
1937 | break; |
1938 | ||
1939 | case 9: /*LSC4*/ | |
772177c1 | 1940 | gen_window_check2(dc, RRR_S, RRR_T); |
553e44f9 MF |
1941 | switch (OP2) { |
1942 | case 0: /*L32E*/ | |
1943 | HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); | |
1944 | gen_check_privilege(dc); | |
1945 | { | |
1946 | TCGv_i32 addr = tcg_temp_new_i32(); | |
1947 | tcg_gen_addi_i32(addr, cpu_R[RRR_S], | |
1948 | (0xffffffc0 | (RRR_R << 2))); | |
1949 | tcg_gen_qemu_ld32u(cpu_R[RRR_T], addr, dc->ring); | |
1950 | tcg_temp_free(addr); | |
1951 | } | |
1952 | break; | |
1953 | ||
1954 | case 4: /*S32E*/ | |
1955 | HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); | |
1956 | gen_check_privilege(dc); | |
1957 | { | |
1958 | TCGv_i32 addr = tcg_temp_new_i32(); | |
1959 | tcg_gen_addi_i32(addr, cpu_R[RRR_S], | |
1960 | (0xffffffc0 | (RRR_R << 2))); | |
1961 | tcg_gen_qemu_st32(cpu_R[RRR_T], addr, dc->ring); | |
1962 | tcg_temp_free(addr); | |
1963 | } | |
1964 | break; | |
1965 | ||
1966 | default: | |
1967 | RESERVED(); | |
1968 | break; | |
1969 | } | |
dedc5eae MF |
1970 | break; |
1971 | ||
1972 | case 10: /*FP0*/ | |
1973 | HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR); | |
0b6df838 MF |
1974 | switch (OP2) { |
1975 | case 0: /*ADD.Sf*/ | |
ef04a846 | 1976 | gen_check_cpenable(dc, 0); |
0b6df838 MF |
1977 | gen_helper_add_s(cpu_FR[RRR_R], cpu_env, |
1978 | cpu_FR[RRR_S], cpu_FR[RRR_T]); | |
1979 | break; | |
1980 | ||
1981 | case 1: /*SUB.Sf*/ | |
ef04a846 | 1982 | gen_check_cpenable(dc, 0); |
0b6df838 MF |
1983 | gen_helper_sub_s(cpu_FR[RRR_R], cpu_env, |
1984 | cpu_FR[RRR_S], cpu_FR[RRR_T]); | |
1985 | break; | |
1986 | ||
1987 | case 2: /*MUL.Sf*/ | |
ef04a846 | 1988 | gen_check_cpenable(dc, 0); |
0b6df838 MF |
1989 | gen_helper_mul_s(cpu_FR[RRR_R], cpu_env, |
1990 | cpu_FR[RRR_S], cpu_FR[RRR_T]); | |
1991 | break; | |
1992 | ||
1993 | case 4: /*MADD.Sf*/ | |
ef04a846 | 1994 | gen_check_cpenable(dc, 0); |
0b6df838 MF |
1995 | gen_helper_madd_s(cpu_FR[RRR_R], cpu_env, |
1996 | cpu_FR[RRR_R], cpu_FR[RRR_S], cpu_FR[RRR_T]); | |
1997 | break; | |
1998 | ||
1999 | case 5: /*MSUB.Sf*/ | |
ef04a846 | 2000 | gen_check_cpenable(dc, 0); |
0b6df838 MF |
2001 | gen_helper_msub_s(cpu_FR[RRR_R], cpu_env, |
2002 | cpu_FR[RRR_R], cpu_FR[RRR_S], cpu_FR[RRR_T]); | |
2003 | break; | |
2004 | ||
b7ee8c6a MF |
2005 | case 8: /*ROUND.Sf*/ |
2006 | case 9: /*TRUNC.Sf*/ | |
2007 | case 10: /*FLOOR.Sf*/ | |
2008 | case 11: /*CEIL.Sf*/ | |
2009 | case 14: /*UTRUNC.Sf*/ | |
2010 | gen_window_check1(dc, RRR_R); | |
ef04a846 | 2011 | gen_check_cpenable(dc, 0); |
b7ee8c6a MF |
2012 | { |
2013 | static const unsigned rounding_mode_const[] = { | |
2014 | float_round_nearest_even, | |
2015 | float_round_to_zero, | |
2016 | float_round_down, | |
2017 | float_round_up, | |
2018 | [6] = float_round_to_zero, | |
2019 | }; | |
2020 | TCGv_i32 rounding_mode = tcg_const_i32( | |
2021 | rounding_mode_const[OP2 & 7]); | |
2022 | TCGv_i32 scale = tcg_const_i32(RRR_T); | |
2023 | ||
2024 | if (OP2 == 14) { | |
2025 | gen_helper_ftoui(cpu_R[RRR_R], cpu_FR[RRR_S], | |
2026 | rounding_mode, scale); | |
2027 | } else { | |
2028 | gen_helper_ftoi(cpu_R[RRR_R], cpu_FR[RRR_S], | |
2029 | rounding_mode, scale); | |
2030 | } | |
2031 | ||
2032 | tcg_temp_free(rounding_mode); | |
2033 | tcg_temp_free(scale); | |
2034 | } | |
2035 | break; | |
2036 | ||
2037 | case 12: /*FLOAT.Sf*/ | |
2038 | case 13: /*UFLOAT.Sf*/ | |
2039 | gen_window_check1(dc, RRR_S); | |
ef04a846 | 2040 | gen_check_cpenable(dc, 0); |
b7ee8c6a MF |
2041 | { |
2042 | TCGv_i32 scale = tcg_const_i32(-RRR_T); | |
2043 | ||
2044 | if (OP2 == 13) { | |
2045 | gen_helper_uitof(cpu_FR[RRR_R], cpu_env, | |
2046 | cpu_R[RRR_S], scale); | |
2047 | } else { | |
2048 | gen_helper_itof(cpu_FR[RRR_R], cpu_env, | |
2049 | cpu_R[RRR_S], scale); | |
2050 | } | |
2051 | tcg_temp_free(scale); | |
2052 | } | |
2053 | break; | |
2054 | ||
0b6df838 MF |
2055 | case 15: /*FP1OP*/ |
2056 | switch (RRR_T) { | |
2057 | case 0: /*MOV.Sf*/ | |
ef04a846 | 2058 | gen_check_cpenable(dc, 0); |
0b6df838 MF |
2059 | tcg_gen_mov_i32(cpu_FR[RRR_R], cpu_FR[RRR_S]); |
2060 | break; | |
2061 | ||
2062 | case 1: /*ABS.Sf*/ | |
ef04a846 | 2063 | gen_check_cpenable(dc, 0); |
0b6df838 MF |
2064 | gen_helper_abs_s(cpu_FR[RRR_R], cpu_FR[RRR_S]); |
2065 | break; | |
2066 | ||
2067 | case 4: /*RFRf*/ | |
2068 | gen_window_check1(dc, RRR_R); | |
ef04a846 | 2069 | gen_check_cpenable(dc, 0); |
0b6df838 MF |
2070 | tcg_gen_mov_i32(cpu_R[RRR_R], cpu_FR[RRR_S]); |
2071 | break; | |
2072 | ||
2073 | case 5: /*WFRf*/ | |
2074 | gen_window_check1(dc, RRR_S); | |
ef04a846 | 2075 | gen_check_cpenable(dc, 0); |
0b6df838 MF |
2076 | tcg_gen_mov_i32(cpu_FR[RRR_R], cpu_R[RRR_S]); |
2077 | break; | |
2078 | ||
2079 | case 6: /*NEG.Sf*/ | |
ef04a846 | 2080 | gen_check_cpenable(dc, 0); |
0b6df838 MF |
2081 | gen_helper_neg_s(cpu_FR[RRR_R], cpu_FR[RRR_S]); |
2082 | break; | |
2083 | ||
2084 | default: /*reserved*/ | |
2085 | RESERVED(); | |
2086 | break; | |
2087 | } | |
2088 | break; | |
2089 | ||
2090 | default: /*reserved*/ | |
2091 | RESERVED(); | |
2092 | break; | |
2093 | } | |
dedc5eae MF |
2094 | break; |
2095 | ||
2096 | case 11: /*FP1*/ | |
2097 | HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR); | |
4e273869 MF |
2098 | |
2099 | #define gen_compare(rel, br, a, b) \ | |
2100 | do { \ | |
2101 | TCGv_i32 bit = tcg_const_i32(1 << br); \ | |
2102 | \ | |
ef04a846 | 2103 | gen_check_cpenable(dc, 0); \ |
4e273869 MF |
2104 | gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \ |
2105 | tcg_temp_free(bit); \ | |
2106 | } while (0) | |
2107 | ||
2108 | switch (OP2) { | |
2109 | case 1: /*UN.Sf*/ | |
2110 | gen_compare(un_s, RRR_R, RRR_S, RRR_T); | |
2111 | break; | |
2112 | ||
2113 | case 2: /*OEQ.Sf*/ | |
2114 | gen_compare(oeq_s, RRR_R, RRR_S, RRR_T); | |
2115 | break; | |
2116 | ||
2117 | case 3: /*UEQ.Sf*/ | |
2118 | gen_compare(ueq_s, RRR_R, RRR_S, RRR_T); | |
2119 | break; | |
2120 | ||
2121 | case 4: /*OLT.Sf*/ | |
2122 | gen_compare(olt_s, RRR_R, RRR_S, RRR_T); | |
2123 | break; | |
2124 | ||
2125 | case 5: /*ULT.Sf*/ | |
2126 | gen_compare(ult_s, RRR_R, RRR_S, RRR_T); | |
2127 | break; | |
2128 | ||
2129 | case 6: /*OLE.Sf*/ | |
2130 | gen_compare(ole_s, RRR_R, RRR_S, RRR_T); | |
2131 | break; | |
2132 | ||
2133 | case 7: /*ULE.Sf*/ | |
2134 | gen_compare(ule_s, RRR_R, RRR_S, RRR_T); | |
2135 | break; | |
2136 | ||
2137 | #undef gen_compare | |
2138 | ||
2139 | case 8: /*MOVEQZ.Sf*/ | |
2140 | case 9: /*MOVNEZ.Sf*/ | |
2141 | case 10: /*MOVLTZ.Sf*/ | |
2142 | case 11: /*MOVGEZ.Sf*/ | |
2143 | gen_window_check1(dc, RRR_T); | |
ef04a846 | 2144 | gen_check_cpenable(dc, 0); |
4e273869 MF |
2145 | { |
2146 | static const TCGCond cond[] = { | |
4e273869 | 2147 | TCG_COND_EQ, |
f877d09e MF |
2148 | TCG_COND_NE, |
2149 | TCG_COND_LT, | |
4e273869 | 2150 | TCG_COND_GE, |
4e273869 | 2151 | }; |
f877d09e MF |
2152 | TCGv_i32 zero = tcg_const_i32(0); |
2153 | ||
2154 | tcg_gen_movcond_i32(cond[OP2 - 8], cpu_FR[RRR_R], | |
2155 | cpu_R[RRR_T], zero, cpu_FR[RRR_S], cpu_FR[RRR_R]); | |
2156 | tcg_temp_free(zero); | |
4e273869 MF |
2157 | } |
2158 | break; | |
2159 | ||
2160 | case 12: /*MOVF.Sf*/ | |
2161 | case 13: /*MOVT.Sf*/ | |
2162 | HAS_OPTION(XTENSA_OPTION_BOOLEAN); | |
ef04a846 | 2163 | gen_check_cpenable(dc, 0); |
4e273869 | 2164 | { |
f877d09e | 2165 | TCGv_i32 zero = tcg_const_i32(0); |
4e273869 MF |
2166 | TCGv_i32 tmp = tcg_temp_new_i32(); |
2167 | ||
2168 | tcg_gen_andi_i32(tmp, cpu_SR[BR], 1 << RRR_T); | |
f877d09e MF |
2169 | tcg_gen_movcond_i32(OP2 & 1 ? TCG_COND_NE : TCG_COND_EQ, |
2170 | cpu_FR[RRR_R], tmp, zero, | |
2171 | cpu_FR[RRR_S], cpu_FR[RRR_R]); | |
2172 | ||
4e273869 | 2173 | tcg_temp_free(tmp); |
f877d09e | 2174 | tcg_temp_free(zero); |
4e273869 MF |
2175 | } |
2176 | break; | |
2177 | ||
2178 | default: /*reserved*/ | |
2179 | RESERVED(); | |
2180 | break; | |
2181 | } | |
dedc5eae MF |
2182 | break; |
2183 | ||
2184 | default: /*reserved*/ | |
91a5bb76 | 2185 | RESERVED(); |
dedc5eae MF |
2186 | break; |
2187 | } | |
2188 | break; | |
2189 | ||
2190 | case 1: /*L32R*/ | |
772177c1 | 2191 | gen_window_check1(dc, RRR_T); |
dedc5eae MF |
2192 | { |
2193 | TCGv_i32 tmp = tcg_const_i32( | |
6ad6dbf7 MF |
2194 | ((dc->tb->flags & XTENSA_TBFLAG_LITBASE) ? |
2195 | 0 : ((dc->pc + 3) & ~3)) + | |
2196 | (0xfffc0000 | (RI16_IMM16 << 2))); | |
dedc5eae | 2197 | |
6ad6dbf7 MF |
2198 | if (dc->tb->flags & XTENSA_TBFLAG_LITBASE) { |
2199 | tcg_gen_add_i32(tmp, tmp, dc->litbase); | |
2200 | } | |
f0a548b9 | 2201 | tcg_gen_qemu_ld32u(cpu_R[RRR_T], tmp, dc->cring); |
dedc5eae MF |
2202 | tcg_temp_free(tmp); |
2203 | } | |
2204 | break; | |
2205 | ||
2206 | case 2: /*LSAI*/ | |
809377aa MF |
2207 | #define gen_load_store(type, shift) do { \ |
2208 | TCGv_i32 addr = tcg_temp_new_i32(); \ | |
772177c1 | 2209 | gen_window_check2(dc, RRI8_S, RRI8_T); \ |
809377aa | 2210 | tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \ |
5b4e481b MF |
2211 | if (shift) { \ |
2212 | gen_load_store_alignment(dc, shift, addr, false); \ | |
2213 | } \ | |
f0a548b9 | 2214 | tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \ |
809377aa MF |
2215 | tcg_temp_free(addr); \ |
2216 | } while (0) | |
2217 | ||
2218 | switch (RRI8_R) { | |
2219 | case 0: /*L8UI*/ | |
2220 | gen_load_store(ld8u, 0); | |
2221 | break; | |
2222 | ||
2223 | case 1: /*L16UI*/ | |
2224 | gen_load_store(ld16u, 1); | |
2225 | break; | |
2226 | ||
2227 | case 2: /*L32I*/ | |
2228 | gen_load_store(ld32u, 2); | |
2229 | break; | |
2230 | ||
2231 | case 4: /*S8I*/ | |
2232 | gen_load_store(st8, 0); | |
2233 | break; | |
2234 | ||
2235 | case 5: /*S16I*/ | |
2236 | gen_load_store(st16, 1); | |
2237 | break; | |
2238 | ||
2239 | case 6: /*S32I*/ | |
2240 | gen_load_store(st32, 2); | |
2241 | break; | |
2242 | ||
7c842590 MF |
2243 | #define gen_dcache_hit_test(w, shift) do { \ |
2244 | TCGv_i32 addr = tcg_temp_new_i32(); \ | |
2245 | TCGv_i32 res = tcg_temp_new_i32(); \ | |
2246 | gen_window_check1(dc, RRI##w##_S); \ | |
2247 | tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \ | |
2248 | RRI##w##_IMM##w << shift); \ | |
2249 | tcg_gen_qemu_ld8u(res, addr, dc->cring); \ | |
2250 | tcg_temp_free(addr); \ | |
2251 | tcg_temp_free(res); \ | |
2252 | } while (0) | |
2253 | ||
2254 | #define gen_dcache_hit_test4() gen_dcache_hit_test(4, 4) | |
2255 | #define gen_dcache_hit_test8() gen_dcache_hit_test(8, 2) | |
2256 | ||
809377aa | 2257 | case 7: /*CACHEc*/ |
8ffc2d0d MF |
2258 | if (RRI8_T < 8) { |
2259 | HAS_OPTION(XTENSA_OPTION_DCACHE); | |
2260 | } | |
2261 | ||
2262 | switch (RRI8_T) { | |
2263 | case 0: /*DPFRc*/ | |
7c842590 | 2264 | gen_window_check1(dc, RRI8_S); |
8ffc2d0d MF |
2265 | break; |
2266 | ||
2267 | case 1: /*DPFWc*/ | |
7c842590 | 2268 | gen_window_check1(dc, RRI8_S); |
8ffc2d0d MF |
2269 | break; |
2270 | ||
2271 | case 2: /*DPFROc*/ | |
7c842590 | 2272 | gen_window_check1(dc, RRI8_S); |
8ffc2d0d MF |
2273 | break; |
2274 | ||
2275 | case 3: /*DPFWOc*/ | |
7c842590 | 2276 | gen_window_check1(dc, RRI8_S); |
8ffc2d0d MF |
2277 | break; |
2278 | ||
2279 | case 4: /*DHWBc*/ | |
7c842590 | 2280 | gen_dcache_hit_test8(); |
8ffc2d0d MF |
2281 | break; |
2282 | ||
2283 | case 5: /*DHWBIc*/ | |
7c842590 | 2284 | gen_dcache_hit_test8(); |
8ffc2d0d MF |
2285 | break; |
2286 | ||
2287 | case 6: /*DHIc*/ | |
7c842590 MF |
2288 | gen_check_privilege(dc); |
2289 | gen_dcache_hit_test8(); | |
8ffc2d0d MF |
2290 | break; |
2291 | ||
2292 | case 7: /*DIIc*/ | |
7c842590 MF |
2293 | gen_check_privilege(dc); |
2294 | gen_window_check1(dc, RRI8_S); | |
8ffc2d0d MF |
2295 | break; |
2296 | ||
2297 | case 8: /*DCEc*/ | |
2298 | switch (OP1) { | |
2299 | case 0: /*DPFLl*/ | |
2300 | HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK); | |
7c842590 MF |
2301 | gen_check_privilege(dc); |
2302 | gen_dcache_hit_test4(); | |
8ffc2d0d MF |
2303 | break; |
2304 | ||
2305 | case 2: /*DHUl*/ | |
2306 | HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK); | |
7c842590 MF |
2307 | gen_check_privilege(dc); |
2308 | gen_dcache_hit_test4(); | |
8ffc2d0d MF |
2309 | break; |
2310 | ||
2311 | case 3: /*DIUl*/ | |
2312 | HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK); | |
7c842590 MF |
2313 | gen_check_privilege(dc); |
2314 | gen_window_check1(dc, RRI4_S); | |
8ffc2d0d MF |
2315 | break; |
2316 | ||
2317 | case 4: /*DIWBc*/ | |
2318 | HAS_OPTION(XTENSA_OPTION_DCACHE); | |
7c842590 MF |
2319 | gen_check_privilege(dc); |
2320 | gen_window_check1(dc, RRI4_S); | |
8ffc2d0d MF |
2321 | break; |
2322 | ||
2323 | case 5: /*DIWBIc*/ | |
2324 | HAS_OPTION(XTENSA_OPTION_DCACHE); | |
7c842590 MF |
2325 | gen_check_privilege(dc); |
2326 | gen_window_check1(dc, RRI4_S); | |
8ffc2d0d MF |
2327 | break; |
2328 | ||
2329 | default: /*reserved*/ | |
2330 | RESERVED(); | |
2331 | break; | |
2332 | ||
2333 | } | |
2334 | break; | |
2335 | ||
7c842590 MF |
2336 | #undef gen_dcache_hit_test |
2337 | #undef gen_dcache_hit_test4 | |
2338 | #undef gen_dcache_hit_test8 | |
2339 | ||
e848dd42 MF |
2340 | #define gen_icache_hit_test(w, shift) do { \ |
2341 | TCGv_i32 addr = tcg_temp_new_i32(); \ | |
2342 | gen_window_check1(dc, RRI##w##_S); \ | |
2343 | tcg_gen_movi_i32(cpu_pc, dc->pc); \ | |
2344 | tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \ | |
2345 | RRI##w##_IMM##w << shift); \ | |
2346 | gen_helper_itlb_hit_test(cpu_env, addr); \ | |
2347 | tcg_temp_free(addr); \ | |
2348 | } while (0) | |
2349 | ||
2350 | #define gen_icache_hit_test4() gen_icache_hit_test(4, 4) | |
2351 | #define gen_icache_hit_test8() gen_icache_hit_test(8, 2) | |
2352 | ||
8ffc2d0d MF |
2353 | case 12: /*IPFc*/ |
2354 | HAS_OPTION(XTENSA_OPTION_ICACHE); | |
e848dd42 | 2355 | gen_window_check1(dc, RRI8_S); |
8ffc2d0d MF |
2356 | break; |
2357 | ||
2358 | case 13: /*ICEc*/ | |
2359 | switch (OP1) { | |
2360 | case 0: /*IPFLl*/ | |
2361 | HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK); | |
e848dd42 MF |
2362 | gen_check_privilege(dc); |
2363 | gen_icache_hit_test4(); | |
8ffc2d0d MF |
2364 | break; |
2365 | ||
2366 | case 2: /*IHUl*/ | |
2367 | HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK); | |
e848dd42 MF |
2368 | gen_check_privilege(dc); |
2369 | gen_icache_hit_test4(); | |
8ffc2d0d MF |
2370 | break; |
2371 | ||
2372 | case 3: /*IIUl*/ | |
2373 | HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK); | |
e848dd42 MF |
2374 | gen_check_privilege(dc); |
2375 | gen_window_check1(dc, RRI4_S); | |
8ffc2d0d MF |
2376 | break; |
2377 | ||
2378 | default: /*reserved*/ | |
2379 | RESERVED(); | |
2380 | break; | |
2381 | } | |
2382 | break; | |
2383 | ||
2384 | case 14: /*IHIc*/ | |
2385 | HAS_OPTION(XTENSA_OPTION_ICACHE); | |
e848dd42 | 2386 | gen_icache_hit_test8(); |
8ffc2d0d MF |
2387 | break; |
2388 | ||
2389 | case 15: /*IIIc*/ | |
2390 | HAS_OPTION(XTENSA_OPTION_ICACHE); | |
e848dd42 MF |
2391 | gen_check_privilege(dc); |
2392 | gen_window_check1(dc, RRI8_S); | |
8ffc2d0d MF |
2393 | break; |
2394 | ||
2395 | default: /*reserved*/ | |
2396 | RESERVED(); | |
2397 | break; | |
2398 | } | |
809377aa MF |
2399 | break; |
2400 | ||
e848dd42 MF |
2401 | #undef gen_icache_hit_test |
2402 | #undef gen_icache_hit_test4 | |
2403 | #undef gen_icache_hit_test8 | |
2404 | ||
809377aa MF |
2405 | case 9: /*L16SI*/ |
2406 | gen_load_store(ld16s, 1); | |
2407 | break; | |
5b4e481b | 2408 | #undef gen_load_store |
809377aa MF |
2409 | |
2410 | case 10: /*MOVI*/ | |
772177c1 | 2411 | gen_window_check1(dc, RRI8_T); |
809377aa MF |
2412 | tcg_gen_movi_i32(cpu_R[RRI8_T], |
2413 | RRI8_IMM8 | (RRI8_S << 8) | | |
2414 | ((RRI8_S & 0x8) ? 0xfffff000 : 0)); | |
2415 | break; | |
2416 | ||
5b4e481b MF |
2417 | #define gen_load_store_no_hw_align(type) do { \ |
2418 | TCGv_i32 addr = tcg_temp_local_new_i32(); \ | |
772177c1 | 2419 | gen_window_check2(dc, RRI8_S, RRI8_T); \ |
5b4e481b MF |
2420 | tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \ |
2421 | gen_load_store_alignment(dc, 2, addr, true); \ | |
2422 | tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \ | |
2423 | tcg_temp_free(addr); \ | |
2424 | } while (0) | |
2425 | ||
809377aa MF |
2426 | case 11: /*L32AIy*/ |
2427 | HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO); | |
5b4e481b | 2428 | gen_load_store_no_hw_align(ld32u); /*TODO acquire?*/ |
809377aa MF |
2429 | break; |
2430 | ||
2431 | case 12: /*ADDI*/ | |
772177c1 | 2432 | gen_window_check2(dc, RRI8_S, RRI8_T); |
809377aa MF |
2433 | tcg_gen_addi_i32(cpu_R[RRI8_T], cpu_R[RRI8_S], RRI8_IMM8_SE); |
2434 | break; | |
2435 | ||
2436 | case 13: /*ADDMI*/ | |
772177c1 | 2437 | gen_window_check2(dc, RRI8_S, RRI8_T); |
809377aa MF |
2438 | tcg_gen_addi_i32(cpu_R[RRI8_T], cpu_R[RRI8_S], RRI8_IMM8_SE << 8); |
2439 | break; | |
2440 | ||
2441 | case 14: /*S32C1Iy*/ | |
7f65f4b0 | 2442 | HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE); |
772177c1 | 2443 | gen_window_check2(dc, RRI8_S, RRI8_T); |
809377aa MF |
2444 | { |
2445 | int label = gen_new_label(); | |
2446 | TCGv_i32 tmp = tcg_temp_local_new_i32(); | |
2447 | TCGv_i32 addr = tcg_temp_local_new_i32(); | |
fcc803d1 | 2448 | TCGv_i32 tpc; |
809377aa MF |
2449 | |
2450 | tcg_gen_mov_i32(tmp, cpu_R[RRI8_T]); | |
2451 | tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); | |
5b4e481b | 2452 | gen_load_store_alignment(dc, 2, addr, true); |
fcc803d1 MF |
2453 | |
2454 | gen_advance_ccount(dc); | |
2455 | tpc = tcg_const_i32(dc->pc); | |
2456 | gen_helper_check_atomctl(cpu_env, tpc, addr); | |
f0a548b9 | 2457 | tcg_gen_qemu_ld32u(cpu_R[RRI8_T], addr, dc->cring); |
809377aa MF |
2458 | tcg_gen_brcond_i32(TCG_COND_NE, cpu_R[RRI8_T], |
2459 | cpu_SR[SCOMPARE1], label); | |
2460 | ||
f0a548b9 | 2461 | tcg_gen_qemu_st32(tmp, addr, dc->cring); |
809377aa MF |
2462 | |
2463 | gen_set_label(label); | |
fcc803d1 | 2464 | tcg_temp_free(tpc); |
809377aa MF |
2465 | tcg_temp_free(addr); |
2466 | tcg_temp_free(tmp); | |
2467 | } | |
2468 | break; | |
2469 | ||
2470 | case 15: /*S32RIy*/ | |
2471 | HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO); | |
5b4e481b | 2472 | gen_load_store_no_hw_align(st32); /*TODO release?*/ |
809377aa | 2473 | break; |
5b4e481b | 2474 | #undef gen_load_store_no_hw_align |
809377aa MF |
2475 | |
2476 | default: /*reserved*/ | |
91a5bb76 | 2477 | RESERVED(); |
809377aa MF |
2478 | break; |
2479 | } | |
dedc5eae MF |
2480 | break; |
2481 | ||
2482 | case 3: /*LSCIp*/ | |
9ed7ae12 MF |
2483 | switch (RRI8_R) { |
2484 | case 0: /*LSIf*/ | |
2485 | case 4: /*SSIf*/ | |
2486 | case 8: /*LSIUf*/ | |
2487 | case 12: /*SSIUf*/ | |
2488 | HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR); | |
2489 | gen_window_check1(dc, RRI8_S); | |
ef04a846 | 2490 | gen_check_cpenable(dc, 0); |
9ed7ae12 MF |
2491 | { |
2492 | TCGv_i32 addr = tcg_temp_new_i32(); | |
2493 | tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); | |
2494 | gen_load_store_alignment(dc, 2, addr, false); | |
2495 | if (RRI8_R & 0x4) { | |
2496 | tcg_gen_qemu_st32(cpu_FR[RRI8_T], addr, dc->cring); | |
2497 | } else { | |
2498 | tcg_gen_qemu_ld32u(cpu_FR[RRI8_T], addr, dc->cring); | |
2499 | } | |
2500 | if (RRI8_R & 0x8) { | |
2501 | tcg_gen_mov_i32(cpu_R[RRI8_S], addr); | |
2502 | } | |
2503 | tcg_temp_free(addr); | |
2504 | } | |
2505 | break; | |
2506 | ||
2507 | default: /*reserved*/ | |
2508 | RESERVED(); | |
2509 | break; | |
2510 | } | |
dedc5eae MF |
2511 | break; |
2512 | ||
2513 | case 4: /*MAC16d*/ | |
2514 | HAS_OPTION(XTENSA_OPTION_MAC16); | |
6825b6c3 MF |
2515 | { |
2516 | enum { | |
2517 | MAC16_UMUL = 0x0, | |
2518 | MAC16_MUL = 0x4, | |
2519 | MAC16_MULA = 0x8, | |
2520 | MAC16_MULS = 0xc, | |
2521 | MAC16_NONE = 0xf, | |
2522 | } op = OP1 & 0xc; | |
2523 | bool is_m1_sr = (OP2 & 0x3) == 2; | |
2524 | bool is_m2_sr = (OP2 & 0xc) == 0; | |
2525 | uint32_t ld_offset = 0; | |
2526 | ||
2527 | if (OP2 > 9) { | |
2528 | RESERVED(); | |
2529 | } | |
2530 | ||
2531 | switch (OP2 & 2) { | |
2532 | case 0: /*MACI?/MACC?*/ | |
2533 | is_m1_sr = true; | |
2534 | ld_offset = (OP2 & 1) ? -4 : 4; | |
2535 | ||
2536 | if (OP2 >= 8) { /*MACI/MACC*/ | |
2537 | if (OP1 == 0) { /*LDINC/LDDEC*/ | |
2538 | op = MAC16_NONE; | |
2539 | } else { | |
2540 | RESERVED(); | |
2541 | } | |
2542 | } else if (op != MAC16_MULA) { /*MULA.*.*.LDINC/LDDEC*/ | |
2543 | RESERVED(); | |
2544 | } | |
2545 | break; | |
2546 | ||
2547 | case 2: /*MACD?/MACA?*/ | |
2548 | if (op == MAC16_UMUL && OP2 != 7) { /*UMUL only in MACAA*/ | |
2549 | RESERVED(); | |
2550 | } | |
2551 | break; | |
2552 | } | |
2553 | ||
2554 | if (op != MAC16_NONE) { | |
2555 | if (!is_m1_sr) { | |
2556 | gen_window_check1(dc, RRR_S); | |
2557 | } | |
2558 | if (!is_m2_sr) { | |
2559 | gen_window_check1(dc, RRR_T); | |
2560 | } | |
2561 | } | |
2562 | ||
2563 | { | |
2564 | TCGv_i32 vaddr = tcg_temp_new_i32(); | |
2565 | TCGv_i32 mem32 = tcg_temp_new_i32(); | |
2566 | ||
2567 | if (ld_offset) { | |
2568 | gen_window_check1(dc, RRR_S); | |
2569 | tcg_gen_addi_i32(vaddr, cpu_R[RRR_S], ld_offset); | |
2570 | gen_load_store_alignment(dc, 2, vaddr, false); | |
2571 | tcg_gen_qemu_ld32u(mem32, vaddr, dc->cring); | |
2572 | } | |
2573 | if (op != MAC16_NONE) { | |
2574 | TCGv_i32 m1 = gen_mac16_m( | |
2575 | is_m1_sr ? cpu_SR[MR + RRR_X] : cpu_R[RRR_S], | |
2576 | OP1 & 1, op == MAC16_UMUL); | |
2577 | TCGv_i32 m2 = gen_mac16_m( | |
2578 | is_m2_sr ? cpu_SR[MR + 2 + RRR_Y] : cpu_R[RRR_T], | |
2579 | OP1 & 2, op == MAC16_UMUL); | |
2580 | ||
2581 | if (op == MAC16_MUL || op == MAC16_UMUL) { | |
2582 | tcg_gen_mul_i32(cpu_SR[ACCLO], m1, m2); | |
2583 | if (op == MAC16_UMUL) { | |
2584 | tcg_gen_movi_i32(cpu_SR[ACCHI], 0); | |
2585 | } else { | |
2586 | tcg_gen_sari_i32(cpu_SR[ACCHI], cpu_SR[ACCLO], 31); | |
2587 | } | |
2588 | } else { | |
d2123a07 RH |
2589 | TCGv_i32 lo = tcg_temp_new_i32(); |
2590 | TCGv_i32 hi = tcg_temp_new_i32(); | |
2591 | ||
2592 | tcg_gen_mul_i32(lo, m1, m2); | |
2593 | tcg_gen_sari_i32(hi, lo, 31); | |
6825b6c3 | 2594 | if (op == MAC16_MULA) { |
d2123a07 RH |
2595 | tcg_gen_add2_i32(cpu_SR[ACCLO], cpu_SR[ACCHI], |
2596 | cpu_SR[ACCLO], cpu_SR[ACCHI], | |
2597 | lo, hi); | |
6825b6c3 | 2598 | } else { |
d2123a07 RH |
2599 | tcg_gen_sub2_i32(cpu_SR[ACCLO], cpu_SR[ACCHI], |
2600 | cpu_SR[ACCLO], cpu_SR[ACCHI], | |
2601 | lo, hi); | |
6825b6c3 | 2602 | } |
6825b6c3 MF |
2603 | tcg_gen_ext8s_i32(cpu_SR[ACCHI], cpu_SR[ACCHI]); |
2604 | ||
d2123a07 RH |
2605 | tcg_temp_free_i32(lo); |
2606 | tcg_temp_free_i32(hi); | |
6825b6c3 MF |
2607 | } |
2608 | tcg_temp_free(m1); | |
2609 | tcg_temp_free(m2); | |
2610 | } | |
2611 | if (ld_offset) { | |
2612 | tcg_gen_mov_i32(cpu_R[RRR_S], vaddr); | |
2613 | tcg_gen_mov_i32(cpu_SR[MR + RRR_W], mem32); | |
2614 | } | |
2615 | tcg_temp_free(vaddr); | |
2616 | tcg_temp_free(mem32); | |
2617 | } | |
2618 | } | |
dedc5eae MF |
2619 | break; |
2620 | ||
2621 | case 5: /*CALLN*/ | |
2622 | switch (CALL_N) { | |
2623 | case 0: /*CALL0*/ | |
2624 | tcg_gen_movi_i32(cpu_R[0], dc->next_pc); | |
2625 | gen_jumpi(dc, (dc->pc & ~3) + (CALL_OFFSET_SE << 2) + 4, 0); | |
2626 | break; | |
2627 | ||
2628 | case 1: /*CALL4w*/ | |
2629 | case 2: /*CALL8w*/ | |
2630 | case 3: /*CALL12w*/ | |
2631 | HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); | |
772177c1 | 2632 | gen_window_check1(dc, CALL_N << 2); |
553e44f9 MF |
2633 | gen_callwi(dc, CALL_N, |
2634 | (dc->pc & ~3) + (CALL_OFFSET_SE << 2) + 4, 0); | |
dedc5eae MF |
2635 | break; |
2636 | } | |
2637 | break; | |
2638 | ||
2639 | case 6: /*SI*/ | |
2640 | switch (CALL_N) { | |
2641 | case 0: /*J*/ | |
2642 | gen_jumpi(dc, dc->pc + 4 + CALL_OFFSET_SE, 0); | |
2643 | break; | |
2644 | ||
bd57fb91 | 2645 | case 1: /*BZ*/ |
772177c1 | 2646 | gen_window_check1(dc, BRI12_S); |
bd57fb91 MF |
2647 | { |
2648 | static const TCGCond cond[] = { | |
2649 | TCG_COND_EQ, /*BEQZ*/ | |
2650 | TCG_COND_NE, /*BNEZ*/ | |
2651 | TCG_COND_LT, /*BLTZ*/ | |
2652 | TCG_COND_GE, /*BGEZ*/ | |
2653 | }; | |
2654 | ||
2655 | gen_brcondi(dc, cond[BRI12_M & 3], cpu_R[BRI12_S], 0, | |
2656 | 4 + BRI12_IMM12_SE); | |
2657 | } | |
2658 | break; | |
2659 | ||
2660 | case 2: /*BI0*/ | |
772177c1 | 2661 | gen_window_check1(dc, BRI8_S); |
bd57fb91 MF |
2662 | { |
2663 | static const TCGCond cond[] = { | |
2664 | TCG_COND_EQ, /*BEQI*/ | |
2665 | TCG_COND_NE, /*BNEI*/ | |
2666 | TCG_COND_LT, /*BLTI*/ | |
2667 | TCG_COND_GE, /*BGEI*/ | |
2668 | }; | |
2669 | ||
2670 | gen_brcondi(dc, cond[BRI8_M & 3], | |
2671 | cpu_R[BRI8_S], B4CONST[BRI8_R], 4 + BRI8_IMM8_SE); | |
2672 | } | |
2673 | break; | |
2674 | ||
2675 | case 3: /*BI1*/ | |
2676 | switch (BRI8_M) { | |
2677 | case 0: /*ENTRYw*/ | |
2678 | HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); | |
553e44f9 MF |
2679 | { |
2680 | TCGv_i32 pc = tcg_const_i32(dc->pc); | |
2681 | TCGv_i32 s = tcg_const_i32(BRI12_S); | |
2682 | TCGv_i32 imm = tcg_const_i32(BRI12_IMM12); | |
b994e91b | 2683 | gen_advance_ccount(dc); |
f492b82d | 2684 | gen_helper_entry(cpu_env, pc, s, imm); |
553e44f9 MF |
2685 | tcg_temp_free(imm); |
2686 | tcg_temp_free(s); | |
2687 | tcg_temp_free(pc); | |
772177c1 | 2688 | reset_used_window(dc); |
553e44f9 | 2689 | } |
bd57fb91 MF |
2690 | break; |
2691 | ||
2692 | case 1: /*B1*/ | |
2693 | switch (BRI8_R) { | |
2694 | case 0: /*BFp*/ | |
bd57fb91 MF |
2695 | case 1: /*BTp*/ |
2696 | HAS_OPTION(XTENSA_OPTION_BOOLEAN); | |
4dd85b6b MF |
2697 | { |
2698 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
2699 | tcg_gen_andi_i32(tmp, cpu_SR[BR], 1 << RRI8_S); | |
2700 | gen_brcondi(dc, | |
2701 | BRI8_R == 1 ? TCG_COND_NE : TCG_COND_EQ, | |
2702 | tmp, 0, 4 + RRI8_IMM8_SE); | |
2703 | tcg_temp_free(tmp); | |
2704 | } | |
bd57fb91 MF |
2705 | break; |
2706 | ||
2707 | case 8: /*LOOP*/ | |
bd57fb91 | 2708 | case 9: /*LOOPNEZ*/ |
bd57fb91 | 2709 | case 10: /*LOOPGTZ*/ |
797d780b | 2710 | HAS_OPTION(XTENSA_OPTION_LOOP); |
772177c1 | 2711 | gen_window_check1(dc, RRI8_S); |
797d780b MF |
2712 | { |
2713 | uint32_t lend = dc->pc + RRI8_IMM8 + 4; | |
2714 | TCGv_i32 tmp = tcg_const_i32(lend); | |
2715 | ||
2716 | tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_R[RRI8_S], 1); | |
2717 | tcg_gen_movi_i32(cpu_SR[LBEG], dc->next_pc); | |
f492b82d | 2718 | gen_helper_wsr_lend(cpu_env, tmp); |
797d780b MF |
2719 | tcg_temp_free(tmp); |
2720 | ||
2721 | if (BRI8_R > 8) { | |
2722 | int label = gen_new_label(); | |
2723 | tcg_gen_brcondi_i32( | |
2724 | BRI8_R == 9 ? TCG_COND_NE : TCG_COND_GT, | |
2725 | cpu_R[RRI8_S], 0, label); | |
2726 | gen_jumpi(dc, lend, 1); | |
2727 | gen_set_label(label); | |
2728 | } | |
2729 | ||
2730 | gen_jumpi(dc, dc->next_pc, 0); | |
2731 | } | |
bd57fb91 MF |
2732 | break; |
2733 | ||
2734 | default: /*reserved*/ | |
91a5bb76 | 2735 | RESERVED(); |
bd57fb91 MF |
2736 | break; |
2737 | ||
2738 | } | |
2739 | break; | |
2740 | ||
2741 | case 2: /*BLTUI*/ | |
2742 | case 3: /*BGEUI*/ | |
772177c1 | 2743 | gen_window_check1(dc, BRI8_S); |
bd57fb91 MF |
2744 | gen_brcondi(dc, BRI8_M == 2 ? TCG_COND_LTU : TCG_COND_GEU, |
2745 | cpu_R[BRI8_S], B4CONSTU[BRI8_R], 4 + BRI8_IMM8_SE); | |
2746 | break; | |
2747 | } | |
2748 | break; | |
2749 | ||
dedc5eae MF |
2750 | } |
2751 | break; | |
2752 | ||
2753 | case 7: /*B*/ | |
bd57fb91 MF |
2754 | { |
2755 | TCGCond eq_ne = (RRI8_R & 8) ? TCG_COND_NE : TCG_COND_EQ; | |
2756 | ||
2757 | switch (RRI8_R & 7) { | |
2758 | case 0: /*BNONE*/ /*BANY*/ | |
772177c1 | 2759 | gen_window_check2(dc, RRI8_S, RRI8_T); |
bd57fb91 MF |
2760 | { |
2761 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
2762 | tcg_gen_and_i32(tmp, cpu_R[RRI8_S], cpu_R[RRI8_T]); | |
2763 | gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE); | |
2764 | tcg_temp_free(tmp); | |
2765 | } | |
2766 | break; | |
2767 | ||
2768 | case 1: /*BEQ*/ /*BNE*/ | |
2769 | case 2: /*BLT*/ /*BGE*/ | |
2770 | case 3: /*BLTU*/ /*BGEU*/ | |
772177c1 | 2771 | gen_window_check2(dc, RRI8_S, RRI8_T); |
bd57fb91 MF |
2772 | { |
2773 | static const TCGCond cond[] = { | |
2774 | [1] = TCG_COND_EQ, | |
2775 | [2] = TCG_COND_LT, | |
2776 | [3] = TCG_COND_LTU, | |
2777 | [9] = TCG_COND_NE, | |
2778 | [10] = TCG_COND_GE, | |
2779 | [11] = TCG_COND_GEU, | |
2780 | }; | |
2781 | gen_brcond(dc, cond[RRI8_R], cpu_R[RRI8_S], cpu_R[RRI8_T], | |
2782 | 4 + RRI8_IMM8_SE); | |
2783 | } | |
2784 | break; | |
2785 | ||
2786 | case 4: /*BALL*/ /*BNALL*/ | |
772177c1 | 2787 | gen_window_check2(dc, RRI8_S, RRI8_T); |
bd57fb91 MF |
2788 | { |
2789 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
2790 | tcg_gen_and_i32(tmp, cpu_R[RRI8_S], cpu_R[RRI8_T]); | |
2791 | gen_brcond(dc, eq_ne, tmp, cpu_R[RRI8_T], | |
2792 | 4 + RRI8_IMM8_SE); | |
2793 | tcg_temp_free(tmp); | |
2794 | } | |
2795 | break; | |
2796 | ||
2797 | case 5: /*BBC*/ /*BBS*/ | |
772177c1 | 2798 | gen_window_check2(dc, RRI8_S, RRI8_T); |
bd57fb91 | 2799 | { |
7ff7563f MF |
2800 | #ifdef TARGET_WORDS_BIGENDIAN |
2801 | TCGv_i32 bit = tcg_const_i32(0x80000000); | |
2802 | #else | |
2803 | TCGv_i32 bit = tcg_const_i32(0x00000001); | |
2804 | #endif | |
bd57fb91 MF |
2805 | TCGv_i32 tmp = tcg_temp_new_i32(); |
2806 | tcg_gen_andi_i32(tmp, cpu_R[RRI8_T], 0x1f); | |
7ff7563f MF |
2807 | #ifdef TARGET_WORDS_BIGENDIAN |
2808 | tcg_gen_shr_i32(bit, bit, tmp); | |
2809 | #else | |
bd57fb91 | 2810 | tcg_gen_shl_i32(bit, bit, tmp); |
7ff7563f | 2811 | #endif |
bd57fb91 MF |
2812 | tcg_gen_and_i32(tmp, cpu_R[RRI8_S], bit); |
2813 | gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE); | |
2814 | tcg_temp_free(tmp); | |
2815 | tcg_temp_free(bit); | |
2816 | } | |
2817 | break; | |
2818 | ||
2819 | case 6: /*BBCI*/ /*BBSI*/ | |
2820 | case 7: | |
772177c1 | 2821 | gen_window_check1(dc, RRI8_S); |
bd57fb91 MF |
2822 | { |
2823 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
2824 | tcg_gen_andi_i32(tmp, cpu_R[RRI8_S], | |
7ff7563f MF |
2825 | #ifdef TARGET_WORDS_BIGENDIAN |
2826 | 0x80000000 >> (((RRI8_R & 1) << 4) | RRI8_T)); | |
2827 | #else | |
2828 | 0x00000001 << (((RRI8_R & 1) << 4) | RRI8_T)); | |
2829 | #endif | |
bd57fb91 MF |
2830 | gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE); |
2831 | tcg_temp_free(tmp); | |
2832 | } | |
2833 | break; | |
2834 | ||
2835 | } | |
2836 | } | |
dedc5eae MF |
2837 | break; |
2838 | ||
67882fd1 MF |
2839 | #define gen_narrow_load_store(type) do { \ |
2840 | TCGv_i32 addr = tcg_temp_new_i32(); \ | |
772177c1 | 2841 | gen_window_check2(dc, RRRN_S, RRRN_T); \ |
67882fd1 | 2842 | tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \ |
5b4e481b | 2843 | gen_load_store_alignment(dc, 2, addr, false); \ |
f0a548b9 | 2844 | tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \ |
67882fd1 MF |
2845 | tcg_temp_free(addr); \ |
2846 | } while (0) | |
2847 | ||
dedc5eae | 2848 | case 8: /*L32I.Nn*/ |
67882fd1 | 2849 | gen_narrow_load_store(ld32u); |
dedc5eae MF |
2850 | break; |
2851 | ||
2852 | case 9: /*S32I.Nn*/ | |
67882fd1 | 2853 | gen_narrow_load_store(st32); |
dedc5eae | 2854 | break; |
67882fd1 | 2855 | #undef gen_narrow_load_store |
dedc5eae MF |
2856 | |
2857 | case 10: /*ADD.Nn*/ | |
772177c1 | 2858 | gen_window_check3(dc, RRRN_R, RRRN_S, RRRN_T); |
67882fd1 | 2859 | tcg_gen_add_i32(cpu_R[RRRN_R], cpu_R[RRRN_S], cpu_R[RRRN_T]); |
dedc5eae MF |
2860 | break; |
2861 | ||
2862 | case 11: /*ADDI.Nn*/ | |
772177c1 | 2863 | gen_window_check2(dc, RRRN_R, RRRN_S); |
67882fd1 | 2864 | tcg_gen_addi_i32(cpu_R[RRRN_R], cpu_R[RRRN_S], RRRN_T ? RRRN_T : -1); |
dedc5eae MF |
2865 | break; |
2866 | ||
2867 | case 12: /*ST2n*/ | |
772177c1 | 2868 | gen_window_check1(dc, RRRN_S); |
67882fd1 MF |
2869 | if (RRRN_T < 8) { /*MOVI.Nn*/ |
2870 | tcg_gen_movi_i32(cpu_R[RRRN_S], | |
2871 | RRRN_R | (RRRN_T << 4) | | |
2872 | ((RRRN_T & 6) == 6 ? 0xffffff80 : 0)); | |
2873 | } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/ | |
bd57fb91 MF |
2874 | TCGCond eq_ne = (RRRN_T & 4) ? TCG_COND_NE : TCG_COND_EQ; |
2875 | ||
2876 | gen_brcondi(dc, eq_ne, cpu_R[RRRN_S], 0, | |
2877 | 4 + (RRRN_R | ((RRRN_T & 3) << 4))); | |
67882fd1 | 2878 | } |
dedc5eae MF |
2879 | break; |
2880 | ||
2881 | case 13: /*ST3n*/ | |
67882fd1 MF |
2882 | switch (RRRN_R) { |
2883 | case 0: /*MOV.Nn*/ | |
772177c1 | 2884 | gen_window_check2(dc, RRRN_S, RRRN_T); |
67882fd1 MF |
2885 | tcg_gen_mov_i32(cpu_R[RRRN_T], cpu_R[RRRN_S]); |
2886 | break; | |
2887 | ||
2888 | case 15: /*S3*/ | |
2889 | switch (RRRN_T) { | |
2890 | case 0: /*RET.Nn*/ | |
2891 | gen_jump(dc, cpu_R[0]); | |
2892 | break; | |
2893 | ||
2894 | case 1: /*RETW.Nn*/ | |
91a5bb76 | 2895 | HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER); |
553e44f9 MF |
2896 | { |
2897 | TCGv_i32 tmp = tcg_const_i32(dc->pc); | |
b994e91b | 2898 | gen_advance_ccount(dc); |
f492b82d | 2899 | gen_helper_retw(tmp, cpu_env, tmp); |
553e44f9 MF |
2900 | gen_jump(dc, tmp); |
2901 | tcg_temp_free(tmp); | |
2902 | } | |
67882fd1 MF |
2903 | break; |
2904 | ||
2905 | case 2: /*BREAK.Nn*/ | |
e61dc8f7 MF |
2906 | HAS_OPTION(XTENSA_OPTION_DEBUG); |
2907 | if (dc->debug) { | |
2908 | gen_debug_exception(dc, DEBUGCAUSE_BN); | |
2909 | } | |
67882fd1 MF |
2910 | break; |
2911 | ||
2912 | case 3: /*NOP.Nn*/ | |
2913 | break; | |
2914 | ||
2915 | case 6: /*ILL.Nn*/ | |
40643d7c | 2916 | gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE); |
67882fd1 MF |
2917 | break; |
2918 | ||
2919 | default: /*reserved*/ | |
91a5bb76 | 2920 | RESERVED(); |
67882fd1 MF |
2921 | break; |
2922 | } | |
2923 | break; | |
2924 | ||
2925 | default: /*reserved*/ | |
91a5bb76 | 2926 | RESERVED(); |
67882fd1 MF |
2927 | break; |
2928 | } | |
dedc5eae MF |
2929 | break; |
2930 | ||
2931 | default: /*reserved*/ | |
91a5bb76 | 2932 | RESERVED(); |
dedc5eae MF |
2933 | break; |
2934 | } | |
2935 | ||
c26032b2 MF |
2936 | if (dc->is_jmp == DISAS_NEXT) { |
2937 | gen_check_loop_end(dc, 0); | |
2938 | } | |
dedc5eae | 2939 | dc->pc = dc->next_pc; |
797d780b | 2940 | |
dedc5eae MF |
2941 | return; |
2942 | ||
2943 | invalid_opcode: | |
2944 | qemu_log("INVALID(pc = %08x)\n", dc->pc); | |
6b814719 | 2945 | gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE); |
dedc5eae MF |
2946 | #undef HAS_OPTION |
2947 | } | |
2948 | ||
97129ac8 | 2949 | static void check_breakpoint(CPUXtensaState *env, DisasContext *dc) |
dedc5eae MF |
2950 | { |
2951 | CPUBreakpoint *bp; | |
2952 | ||
2953 | if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) { | |
2954 | QTAILQ_FOREACH(bp, &env->breakpoints, entry) { | |
2955 | if (bp->pc == dc->pc) { | |
2956 | tcg_gen_movi_i32(cpu_pc, dc->pc); | |
b994e91b | 2957 | gen_exception(dc, EXCP_DEBUG); |
dedc5eae MF |
2958 | dc->is_jmp = DISAS_UPDATE; |
2959 | } | |
2960 | } | |
2961 | } | |
2962 | } | |
2963 | ||
97129ac8 | 2964 | static void gen_ibreak_check(CPUXtensaState *env, DisasContext *dc) |
e61dc8f7 MF |
2965 | { |
2966 | unsigned i; | |
2967 | ||
2968 | for (i = 0; i < dc->config->nibreak; ++i) { | |
2969 | if ((env->sregs[IBREAKENABLE] & (1 << i)) && | |
2970 | env->sregs[IBREAKA + i] == dc->pc) { | |
2971 | gen_debug_exception(dc, DEBUGCAUSE_IB); | |
2972 | break; | |
2973 | } | |
2974 | } | |
2975 | } | |
2976 | ||
ae06d498 | 2977 | static inline |
90b85b77 AF |
2978 | void gen_intermediate_code_internal(XtensaCPU *cpu, |
2979 | TranslationBlock *tb, bool search_pc) | |
dedc5eae | 2980 | { |
ed2803da | 2981 | CPUState *cs = CPU(cpu); |
90b85b77 | 2982 | CPUXtensaState *env = &cpu->env; |
dedc5eae MF |
2983 | DisasContext dc; |
2984 | int insn_count = 0; | |
2985 | int j, lj = -1; | |
92414b31 | 2986 | uint16_t *gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE; |
dedc5eae MF |
2987 | int max_insns = tb->cflags & CF_COUNT_MASK; |
2988 | uint32_t pc_start = tb->pc; | |
2989 | uint32_t next_page_start = | |
2990 | (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE; | |
2991 | ||
2992 | if (max_insns == 0) { | |
2993 | max_insns = CF_COUNT_MASK; | |
2994 | } | |
2995 | ||
2996 | dc.config = env->config; | |
ed2803da | 2997 | dc.singlestep_enabled = cs->singlestep_enabled; |
dedc5eae MF |
2998 | dc.tb = tb; |
2999 | dc.pc = pc_start; | |
f0a548b9 MF |
3000 | dc.ring = tb->flags & XTENSA_TBFLAG_RING_MASK; |
3001 | dc.cring = (tb->flags & XTENSA_TBFLAG_EXCM) ? 0 : dc.ring; | |
797d780b MF |
3002 | dc.lbeg = env->sregs[LBEG]; |
3003 | dc.lend = env->sregs[LEND]; | |
dedc5eae | 3004 | dc.is_jmp = DISAS_NEXT; |
b994e91b | 3005 | dc.ccount_delta = 0; |
e61dc8f7 | 3006 | dc.debug = tb->flags & XTENSA_TBFLAG_DEBUG; |
35b5c044 | 3007 | dc.icount = tb->flags & XTENSA_TBFLAG_ICOUNT; |
ef04a846 MF |
3008 | dc.cpenable = (tb->flags & XTENSA_TBFLAG_CPENABLE_MASK) >> |
3009 | XTENSA_TBFLAG_CPENABLE_SHIFT; | |
dedc5eae | 3010 | |
6ad6dbf7 | 3011 | init_litbase(&dc); |
3580ecad | 3012 | init_sar_tracker(&dc); |
772177c1 | 3013 | reset_used_window(&dc); |
35b5c044 MF |
3014 | if (dc.icount) { |
3015 | dc.next_icount = tcg_temp_local_new_i32(); | |
3016 | } | |
3580ecad | 3017 | |
806f352d | 3018 | gen_tb_start(); |
dedc5eae | 3019 | |
a00817cc | 3020 | if (tb->flags & XTENSA_TBFLAG_EXCEPTION) { |
40643d7c | 3021 | tcg_gen_movi_i32(cpu_pc, dc.pc); |
b994e91b | 3022 | gen_exception(&dc, EXCP_DEBUG); |
40643d7c MF |
3023 | } |
3024 | ||
dedc5eae MF |
3025 | do { |
3026 | check_breakpoint(env, &dc); | |
3027 | ||
3028 | if (search_pc) { | |
92414b31 | 3029 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
dedc5eae MF |
3030 | if (lj < j) { |
3031 | lj++; | |
3032 | while (lj < j) { | |
ab1103de | 3033 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
dedc5eae MF |
3034 | } |
3035 | } | |
25983cad | 3036 | tcg_ctx.gen_opc_pc[lj] = dc.pc; |
ab1103de | 3037 | tcg_ctx.gen_opc_instr_start[lj] = 1; |
c9c99c22 | 3038 | tcg_ctx.gen_opc_icount[lj] = insn_count; |
dedc5eae MF |
3039 | } |
3040 | ||
fdefe51c | 3041 | if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) { |
dedc5eae MF |
3042 | tcg_gen_debug_insn_start(dc.pc); |
3043 | } | |
3044 | ||
b994e91b MF |
3045 | ++dc.ccount_delta; |
3046 | ||
3047 | if (insn_count + 1 == max_insns && (tb->cflags & CF_LAST_IO)) { | |
3048 | gen_io_start(); | |
3049 | } | |
3050 | ||
35b5c044 MF |
3051 | if (dc.icount) { |
3052 | int label = gen_new_label(); | |
3053 | ||
3054 | tcg_gen_addi_i32(dc.next_icount, cpu_SR[ICOUNT], 1); | |
3055 | tcg_gen_brcondi_i32(TCG_COND_NE, dc.next_icount, 0, label); | |
3056 | tcg_gen_mov_i32(dc.next_icount, cpu_SR[ICOUNT]); | |
3057 | if (dc.debug) { | |
3058 | gen_debug_exception(&dc, DEBUGCAUSE_IC); | |
3059 | } | |
3060 | gen_set_label(label); | |
3061 | } | |
3062 | ||
e61dc8f7 MF |
3063 | if (dc.debug) { |
3064 | gen_ibreak_check(env, &dc); | |
3065 | } | |
3066 | ||
0c4fabea | 3067 | disas_xtensa_insn(env, &dc); |
dedc5eae | 3068 | ++insn_count; |
35b5c044 MF |
3069 | if (dc.icount) { |
3070 | tcg_gen_mov_i32(cpu_SR[ICOUNT], dc.next_icount); | |
3071 | } | |
ed2803da | 3072 | if (cs->singlestep_enabled) { |
dedc5eae | 3073 | tcg_gen_movi_i32(cpu_pc, dc.pc); |
b994e91b | 3074 | gen_exception(&dc, EXCP_DEBUG); |
dedc5eae MF |
3075 | break; |
3076 | } | |
3077 | } while (dc.is_jmp == DISAS_NEXT && | |
3078 | insn_count < max_insns && | |
3079 | dc.pc < next_page_start && | |
efd7f486 | 3080 | tcg_ctx.gen_opc_ptr < gen_opc_end); |
dedc5eae | 3081 | |
6ad6dbf7 | 3082 | reset_litbase(&dc); |
3580ecad | 3083 | reset_sar_tracker(&dc); |
35b5c044 MF |
3084 | if (dc.icount) { |
3085 | tcg_temp_free(dc.next_icount); | |
3086 | } | |
3580ecad | 3087 | |
b994e91b MF |
3088 | if (tb->cflags & CF_LAST_IO) { |
3089 | gen_io_end(); | |
3090 | } | |
3091 | ||
dedc5eae MF |
3092 | if (dc.is_jmp == DISAS_NEXT) { |
3093 | gen_jumpi(&dc, dc.pc, 0); | |
3094 | } | |
806f352d | 3095 | gen_tb_end(tb, insn_count); |
efd7f486 | 3096 | *tcg_ctx.gen_opc_ptr = INDEX_op_end; |
dedc5eae | 3097 | |
ca529f8e MF |
3098 | #ifdef DEBUG_DISAS |
3099 | if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { | |
3100 | qemu_log("----------------\n"); | |
3101 | qemu_log("IN: %s\n", lookup_symbol(pc_start)); | |
3102 | log_target_disas(env, pc_start, dc.pc - pc_start, 0); | |
3103 | qemu_log("\n"); | |
3104 | } | |
3105 | #endif | |
36f25d25 MF |
3106 | if (search_pc) { |
3107 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; | |
3108 | memset(tcg_ctx.gen_opc_instr_start + lj + 1, 0, | |
3109 | (j - lj) * sizeof(tcg_ctx.gen_opc_instr_start[0])); | |
3110 | } else { | |
dedc5eae MF |
3111 | tb->size = dc.pc - pc_start; |
3112 | tb->icount = insn_count; | |
3113 | } | |
2328826b MF |
3114 | } |
3115 | ||
97129ac8 | 3116 | void gen_intermediate_code(CPUXtensaState *env, TranslationBlock *tb) |
2328826b | 3117 | { |
90b85b77 | 3118 | gen_intermediate_code_internal(xtensa_env_get_cpu(env), tb, false); |
2328826b MF |
3119 | } |
3120 | ||
97129ac8 | 3121 | void gen_intermediate_code_pc(CPUXtensaState *env, TranslationBlock *tb) |
2328826b | 3122 | { |
90b85b77 | 3123 | gen_intermediate_code_internal(xtensa_env_get_cpu(env), tb, true); |
2328826b MF |
3124 | } |
3125 | ||
878096ee AF |
3126 | void xtensa_cpu_dump_state(CPUState *cs, FILE *f, |
3127 | fprintf_function cpu_fprintf, int flags) | |
2328826b | 3128 | { |
878096ee AF |
3129 | XtensaCPU *cpu = XTENSA_CPU(cs); |
3130 | CPUXtensaState *env = &cpu->env; | |
2af3da91 MF |
3131 | int i, j; |
3132 | ||
3133 | cpu_fprintf(f, "PC=%08x\n\n", env->pc); | |
3134 | ||
3135 | for (i = j = 0; i < 256; ++i) { | |
fe0bd475 MF |
3136 | if (xtensa_option_bits_enabled(env->config, sregnames[i].opt_bits)) { |
3137 | cpu_fprintf(f, "%12s=%08x%c", sregnames[i].name, env->sregs[i], | |
2af3da91 MF |
3138 | (j++ % 4) == 3 ? '\n' : ' '); |
3139 | } | |
3140 | } | |
3141 | ||
3142 | cpu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n"); | |
3143 | ||
3144 | for (i = j = 0; i < 256; ++i) { | |
fe0bd475 MF |
3145 | if (xtensa_option_bits_enabled(env->config, uregnames[i].opt_bits)) { |
3146 | cpu_fprintf(f, "%s=%08x%c", uregnames[i].name, env->uregs[i], | |
2af3da91 MF |
3147 | (j++ % 4) == 3 ? '\n' : ' '); |
3148 | } | |
3149 | } | |
2328826b | 3150 | |
2af3da91 | 3151 | cpu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n"); |
2328826b MF |
3152 | |
3153 | for (i = 0; i < 16; ++i) { | |
fe0bd475 | 3154 | cpu_fprintf(f, " A%02d=%08x%c", i, env->regs[i], |
2328826b MF |
3155 | (i % 4) == 3 ? '\n' : ' '); |
3156 | } | |
553e44f9 MF |
3157 | |
3158 | cpu_fprintf(f, "\n"); | |
3159 | ||
3160 | for (i = 0; i < env->config->nareg; ++i) { | |
3161 | cpu_fprintf(f, "AR%02d=%08x%c", i, env->phys_regs[i], | |
3162 | (i % 4) == 3 ? '\n' : ' '); | |
3163 | } | |
dd519cbe MF |
3164 | |
3165 | if (xtensa_option_enabled(env->config, XTENSA_OPTION_FP_COPROCESSOR)) { | |
3166 | cpu_fprintf(f, "\n"); | |
3167 | ||
3168 | for (i = 0; i < 16; ++i) { | |
3169 | cpu_fprintf(f, "F%02d=%08x (%+10.8e)%c", i, | |
3170 | float32_val(env->fregs[i]), | |
3171 | *(float *)&env->fregs[i], (i % 2) == 1 ? '\n' : ' '); | |
3172 | } | |
3173 | } | |
2328826b MF |
3174 | } |
3175 | ||
97129ac8 | 3176 | void restore_state_to_opc(CPUXtensaState *env, TranslationBlock *tb, int pc_pos) |
2328826b | 3177 | { |
25983cad | 3178 | env->pc = tcg_ctx.gen_opc_pc[pc_pos]; |
2328826b | 3179 | } |