3 * http://www.tensilica.com/products/literature-docs/documentation/xtensa-isa-databook.htm
5 * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab.
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.
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.
34 #include "exec/exec-all.h"
35 #include "disas/disas.h"
38 #include "sysemu/sysemu.h"
39 #include "exec/cpu_ldst.h"
40 #include "exec/semihost.h"
42 #include "exec/helper-proto.h"
43 #include "exec/helper-gen.h"
45 #include "trace-tcg.h"
48 typedef struct DisasContext {
49 const XtensaConfig *config;
59 int singlestep_enabled;
63 bool sar_m32_allocated;
66 uint32_t ccount_delta;
76 static TCGv_ptr cpu_env;
77 static TCGv_i32 cpu_pc;
78 static TCGv_i32 cpu_R[16];
79 static TCGv_i32 cpu_FR[16];
80 static TCGv_i32 cpu_SR[256];
81 static TCGv_i32 cpu_UR[256];
83 #include "exec/gen-icount.h"
85 typedef struct XtensaReg {
97 #define XTENSA_REG_ACCESS(regname, opt, acc) { \
99 .opt_bits = XTENSA_OPTION_BIT(opt), \
103 #define XTENSA_REG(regname, opt) XTENSA_REG_ACCESS(regname, opt, SR_RWX)
105 #define XTENSA_REG_BITS_ACCESS(regname, opt, acc) { \
111 #define XTENSA_REG_BITS(regname, opt) \
112 XTENSA_REG_BITS_ACCESS(regname, opt, SR_RWX)
114 static const XtensaReg sregnames[256] = {
115 [LBEG] = XTENSA_REG("LBEG", XTENSA_OPTION_LOOP),
116 [LEND] = XTENSA_REG("LEND", XTENSA_OPTION_LOOP),
117 [LCOUNT] = XTENSA_REG("LCOUNT", XTENSA_OPTION_LOOP),
118 [SAR] = XTENSA_REG_BITS("SAR", XTENSA_OPTION_ALL),
119 [BR] = XTENSA_REG("BR", XTENSA_OPTION_BOOLEAN),
120 [LITBASE] = XTENSA_REG("LITBASE", XTENSA_OPTION_EXTENDED_L32R),
121 [SCOMPARE1] = XTENSA_REG("SCOMPARE1", XTENSA_OPTION_CONDITIONAL_STORE),
122 [ACCLO] = XTENSA_REG("ACCLO", XTENSA_OPTION_MAC16),
123 [ACCHI] = XTENSA_REG("ACCHI", XTENSA_OPTION_MAC16),
124 [MR] = XTENSA_REG("MR0", XTENSA_OPTION_MAC16),
125 [MR + 1] = XTENSA_REG("MR1", XTENSA_OPTION_MAC16),
126 [MR + 2] = XTENSA_REG("MR2", XTENSA_OPTION_MAC16),
127 [MR + 3] = XTENSA_REG("MR3", XTENSA_OPTION_MAC16),
128 [WINDOW_BASE] = XTENSA_REG("WINDOW_BASE", XTENSA_OPTION_WINDOWED_REGISTER),
129 [WINDOW_START] = XTENSA_REG("WINDOW_START",
130 XTENSA_OPTION_WINDOWED_REGISTER),
131 [PTEVADDR] = XTENSA_REG("PTEVADDR", XTENSA_OPTION_MMU),
132 [RASID] = XTENSA_REG("RASID", XTENSA_OPTION_MMU),
133 [ITLBCFG] = XTENSA_REG("ITLBCFG", XTENSA_OPTION_MMU),
134 [DTLBCFG] = XTENSA_REG("DTLBCFG", XTENSA_OPTION_MMU),
135 [IBREAKENABLE] = XTENSA_REG("IBREAKENABLE", XTENSA_OPTION_DEBUG),
136 [CACHEATTR] = XTENSA_REG("CACHEATTR", XTENSA_OPTION_CACHEATTR),
137 [ATOMCTL] = XTENSA_REG("ATOMCTL", XTENSA_OPTION_ATOMCTL),
138 [IBREAKA] = XTENSA_REG("IBREAKA0", XTENSA_OPTION_DEBUG),
139 [IBREAKA + 1] = XTENSA_REG("IBREAKA1", XTENSA_OPTION_DEBUG),
140 [DBREAKA] = XTENSA_REG("DBREAKA0", XTENSA_OPTION_DEBUG),
141 [DBREAKA + 1] = XTENSA_REG("DBREAKA1", XTENSA_OPTION_DEBUG),
142 [DBREAKC] = XTENSA_REG("DBREAKC0", XTENSA_OPTION_DEBUG),
143 [DBREAKC + 1] = XTENSA_REG("DBREAKC1", XTENSA_OPTION_DEBUG),
144 [CONFIGID0] = XTENSA_REG_BITS_ACCESS("CONFIGID0", XTENSA_OPTION_ALL, SR_R),
145 [EPC1] = XTENSA_REG("EPC1", XTENSA_OPTION_EXCEPTION),
146 [EPC1 + 1] = XTENSA_REG("EPC2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
147 [EPC1 + 2] = XTENSA_REG("EPC3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
148 [EPC1 + 3] = XTENSA_REG("EPC4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
149 [EPC1 + 4] = XTENSA_REG("EPC5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
150 [EPC1 + 5] = XTENSA_REG("EPC6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
151 [EPC1 + 6] = XTENSA_REG("EPC7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
152 [DEPC] = XTENSA_REG("DEPC", XTENSA_OPTION_EXCEPTION),
153 [EPS2] = XTENSA_REG("EPS2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
154 [EPS2 + 1] = XTENSA_REG("EPS3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
155 [EPS2 + 2] = XTENSA_REG("EPS4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
156 [EPS2 + 3] = XTENSA_REG("EPS5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
157 [EPS2 + 4] = XTENSA_REG("EPS6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
158 [EPS2 + 5] = XTENSA_REG("EPS7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
159 [CONFIGID1] = XTENSA_REG_BITS_ACCESS("CONFIGID1", XTENSA_OPTION_ALL, SR_R),
160 [EXCSAVE1] = XTENSA_REG("EXCSAVE1", XTENSA_OPTION_EXCEPTION),
161 [EXCSAVE1 + 1] = XTENSA_REG("EXCSAVE2",
162 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
163 [EXCSAVE1 + 2] = XTENSA_REG("EXCSAVE3",
164 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
165 [EXCSAVE1 + 3] = XTENSA_REG("EXCSAVE4",
166 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
167 [EXCSAVE1 + 4] = XTENSA_REG("EXCSAVE5",
168 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
169 [EXCSAVE1 + 5] = XTENSA_REG("EXCSAVE6",
170 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
171 [EXCSAVE1 + 6] = XTENSA_REG("EXCSAVE7",
172 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
173 [CPENABLE] = XTENSA_REG("CPENABLE", XTENSA_OPTION_COPROCESSOR),
174 [INTSET] = XTENSA_REG_ACCESS("INTSET", XTENSA_OPTION_INTERRUPT, SR_RW),
175 [INTCLEAR] = XTENSA_REG_ACCESS("INTCLEAR", XTENSA_OPTION_INTERRUPT, SR_W),
176 [INTENABLE] = XTENSA_REG("INTENABLE", XTENSA_OPTION_INTERRUPT),
177 [PS] = XTENSA_REG_BITS("PS", XTENSA_OPTION_ALL),
178 [VECBASE] = XTENSA_REG("VECBASE", XTENSA_OPTION_RELOCATABLE_VECTOR),
179 [EXCCAUSE] = XTENSA_REG("EXCCAUSE", XTENSA_OPTION_EXCEPTION),
180 [DEBUGCAUSE] = XTENSA_REG_ACCESS("DEBUGCAUSE", XTENSA_OPTION_DEBUG, SR_R),
181 [CCOUNT] = XTENSA_REG("CCOUNT", XTENSA_OPTION_TIMER_INTERRUPT),
182 [PRID] = XTENSA_REG_ACCESS("PRID", XTENSA_OPTION_PROCESSOR_ID, SR_R),
183 [ICOUNT] = XTENSA_REG("ICOUNT", XTENSA_OPTION_DEBUG),
184 [ICOUNTLEVEL] = XTENSA_REG("ICOUNTLEVEL", XTENSA_OPTION_DEBUG),
185 [EXCVADDR] = XTENSA_REG("EXCVADDR", XTENSA_OPTION_EXCEPTION),
186 [CCOMPARE] = XTENSA_REG("CCOMPARE0", XTENSA_OPTION_TIMER_INTERRUPT),
187 [CCOMPARE + 1] = XTENSA_REG("CCOMPARE1",
188 XTENSA_OPTION_TIMER_INTERRUPT),
189 [CCOMPARE + 2] = XTENSA_REG("CCOMPARE2",
190 XTENSA_OPTION_TIMER_INTERRUPT),
191 [MISC] = XTENSA_REG("MISC0", XTENSA_OPTION_MISC_SR),
192 [MISC + 1] = XTENSA_REG("MISC1", XTENSA_OPTION_MISC_SR),
193 [MISC + 2] = XTENSA_REG("MISC2", XTENSA_OPTION_MISC_SR),
194 [MISC + 3] = XTENSA_REG("MISC3", XTENSA_OPTION_MISC_SR),
197 static const XtensaReg uregnames[256] = {
198 [THREADPTR] = XTENSA_REG("THREADPTR", XTENSA_OPTION_THREAD_POINTER),
199 [FCR] = XTENSA_REG("FCR", XTENSA_OPTION_FP_COPROCESSOR),
200 [FSR] = XTENSA_REG("FSR", XTENSA_OPTION_FP_COPROCESSOR),
203 void xtensa_translate_init(void)
205 static const char * const regnames[] = {
206 "ar0", "ar1", "ar2", "ar3",
207 "ar4", "ar5", "ar6", "ar7",
208 "ar8", "ar9", "ar10", "ar11",
209 "ar12", "ar13", "ar14", "ar15",
211 static const char * const fregnames[] = {
212 "f0", "f1", "f2", "f3",
213 "f4", "f5", "f6", "f7",
214 "f8", "f9", "f10", "f11",
215 "f12", "f13", "f14", "f15",
219 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
220 cpu_pc = tcg_global_mem_new_i32(TCG_AREG0,
221 offsetof(CPUXtensaState, pc), "pc");
223 for (i = 0; i < 16; i++) {
224 cpu_R[i] = tcg_global_mem_new_i32(TCG_AREG0,
225 offsetof(CPUXtensaState, regs[i]),
229 for (i = 0; i < 16; i++) {
230 cpu_FR[i] = tcg_global_mem_new_i32(TCG_AREG0,
231 offsetof(CPUXtensaState, fregs[i].f32[FP_F32_LOW]),
235 for (i = 0; i < 256; ++i) {
236 if (sregnames[i].name) {
237 cpu_SR[i] = tcg_global_mem_new_i32(TCG_AREG0,
238 offsetof(CPUXtensaState, sregs[i]),
243 for (i = 0; i < 256; ++i) {
244 if (uregnames[i].name) {
245 cpu_UR[i] = tcg_global_mem_new_i32(TCG_AREG0,
246 offsetof(CPUXtensaState, uregs[i]),
252 static inline bool option_bits_enabled(DisasContext *dc, uint64_t opt)
254 return xtensa_option_bits_enabled(dc->config, opt);
257 static inline bool option_enabled(DisasContext *dc, int opt)
259 return xtensa_option_enabled(dc->config, opt);
262 static void init_litbase(DisasContext *dc)
264 if (dc->tb->flags & XTENSA_TBFLAG_LITBASE) {
265 dc->litbase = tcg_temp_local_new_i32();
266 tcg_gen_andi_i32(dc->litbase, cpu_SR[LITBASE], 0xfffff000);
270 static void reset_litbase(DisasContext *dc)
272 if (dc->tb->flags & XTENSA_TBFLAG_LITBASE) {
273 tcg_temp_free(dc->litbase);
277 static void init_sar_tracker(DisasContext *dc)
279 dc->sar_5bit = false;
280 dc->sar_m32_5bit = false;
281 dc->sar_m32_allocated = false;
284 static void reset_sar_tracker(DisasContext *dc)
286 if (dc->sar_m32_allocated) {
287 tcg_temp_free(dc->sar_m32);
291 static void gen_right_shift_sar(DisasContext *dc, TCGv_i32 sa)
293 tcg_gen_andi_i32(cpu_SR[SAR], sa, 0x1f);
294 if (dc->sar_m32_5bit) {
295 tcg_gen_discard_i32(dc->sar_m32);
298 dc->sar_m32_5bit = false;
301 static void gen_left_shift_sar(DisasContext *dc, TCGv_i32 sa)
303 TCGv_i32 tmp = tcg_const_i32(32);
304 if (!dc->sar_m32_allocated) {
305 dc->sar_m32 = tcg_temp_local_new_i32();
306 dc->sar_m32_allocated = true;
308 tcg_gen_andi_i32(dc->sar_m32, sa, 0x1f);
309 tcg_gen_sub_i32(cpu_SR[SAR], tmp, dc->sar_m32);
310 dc->sar_5bit = false;
311 dc->sar_m32_5bit = true;
315 static void gen_advance_ccount(DisasContext *dc)
317 if (dc->ccount_delta > 0) {
318 TCGv_i32 tmp = tcg_const_i32(dc->ccount_delta);
319 gen_helper_advance_ccount(cpu_env, tmp);
322 dc->ccount_delta = 0;
325 static void gen_exception(DisasContext *dc, int excp)
327 TCGv_i32 tmp = tcg_const_i32(excp);
328 gen_advance_ccount(dc);
329 gen_helper_exception(cpu_env, tmp);
333 static void gen_exception_cause(DisasContext *dc, uint32_t cause)
335 TCGv_i32 tpc = tcg_const_i32(dc->pc);
336 TCGv_i32 tcause = tcg_const_i32(cause);
337 gen_advance_ccount(dc);
338 gen_helper_exception_cause(cpu_env, tpc, tcause);
340 tcg_temp_free(tcause);
341 if (cause == ILLEGAL_INSTRUCTION_CAUSE ||
342 cause == SYSCALL_CAUSE) {
343 dc->is_jmp = DISAS_UPDATE;
347 static void gen_exception_cause_vaddr(DisasContext *dc, uint32_t cause,
350 TCGv_i32 tpc = tcg_const_i32(dc->pc);
351 TCGv_i32 tcause = tcg_const_i32(cause);
352 gen_advance_ccount(dc);
353 gen_helper_exception_cause_vaddr(cpu_env, tpc, tcause, vaddr);
355 tcg_temp_free(tcause);
358 static void gen_debug_exception(DisasContext *dc, uint32_t cause)
360 TCGv_i32 tpc = tcg_const_i32(dc->pc);
361 TCGv_i32 tcause = tcg_const_i32(cause);
362 gen_advance_ccount(dc);
363 gen_helper_debug_exception(cpu_env, tpc, tcause);
365 tcg_temp_free(tcause);
366 if (cause & (DEBUGCAUSE_IB | DEBUGCAUSE_BI | DEBUGCAUSE_BN)) {
367 dc->is_jmp = DISAS_UPDATE;
371 static bool gen_check_privilege(DisasContext *dc)
374 gen_exception_cause(dc, PRIVILEGED_CAUSE);
375 dc->is_jmp = DISAS_UPDATE;
381 static bool gen_check_cpenable(DisasContext *dc, unsigned cp)
383 if (option_enabled(dc, XTENSA_OPTION_COPROCESSOR) &&
384 !(dc->cpenable & (1 << cp))) {
385 gen_exception_cause(dc, COPROCESSOR0_DISABLED + cp);
386 dc->is_jmp = DISAS_UPDATE;
392 static void gen_jump_slot(DisasContext *dc, TCGv dest, int slot)
394 tcg_gen_mov_i32(cpu_pc, dest);
395 gen_advance_ccount(dc);
397 tcg_gen_mov_i32(cpu_SR[ICOUNT], dc->next_icount);
399 if (dc->singlestep_enabled) {
400 gen_exception(dc, EXCP_DEBUG);
403 tcg_gen_goto_tb(slot);
404 tcg_gen_exit_tb((uintptr_t)dc->tb + slot);
409 dc->is_jmp = DISAS_UPDATE;
412 static void gen_jump(DisasContext *dc, TCGv dest)
414 gen_jump_slot(dc, dest, -1);
417 static void gen_jumpi(DisasContext *dc, uint32_t dest, int slot)
419 TCGv_i32 tmp = tcg_const_i32(dest);
420 if (((dc->tb->pc ^ dest) & TARGET_PAGE_MASK) != 0) {
423 gen_jump_slot(dc, tmp, slot);
427 static void gen_callw_slot(DisasContext *dc, int callinc, TCGv_i32 dest,
430 TCGv_i32 tcallinc = tcg_const_i32(callinc);
432 tcg_gen_deposit_i32(cpu_SR[PS], cpu_SR[PS],
433 tcallinc, PS_CALLINC_SHIFT, PS_CALLINC_LEN);
434 tcg_temp_free(tcallinc);
435 tcg_gen_movi_i32(cpu_R[callinc << 2],
436 (callinc << 30) | (dc->next_pc & 0x3fffffff));
437 gen_jump_slot(dc, dest, slot);
440 static void gen_callw(DisasContext *dc, int callinc, TCGv_i32 dest)
442 gen_callw_slot(dc, callinc, dest, -1);
445 static void gen_callwi(DisasContext *dc, int callinc, uint32_t dest, int slot)
447 TCGv_i32 tmp = tcg_const_i32(dest);
448 if (((dc->tb->pc ^ dest) & TARGET_PAGE_MASK) != 0) {
451 gen_callw_slot(dc, callinc, tmp, slot);
455 static bool gen_check_loop_end(DisasContext *dc, int slot)
457 if (option_enabled(dc, XTENSA_OPTION_LOOP) &&
458 !(dc->tb->flags & XTENSA_TBFLAG_EXCM) &&
459 dc->next_pc == dc->lend) {
460 TCGLabel *label = gen_new_label();
462 gen_advance_ccount(dc);
463 tcg_gen_brcondi_i32(TCG_COND_EQ, cpu_SR[LCOUNT], 0, label);
464 tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_SR[LCOUNT], 1);
465 gen_jumpi(dc, dc->lbeg, slot);
466 gen_set_label(label);
467 gen_jumpi(dc, dc->next_pc, -1);
473 static void gen_jumpi_check_loop_end(DisasContext *dc, int slot)
475 if (!gen_check_loop_end(dc, slot)) {
476 gen_jumpi(dc, dc->next_pc, slot);
480 static void gen_brcond(DisasContext *dc, TCGCond cond,
481 TCGv_i32 t0, TCGv_i32 t1, uint32_t offset)
483 TCGLabel *label = gen_new_label();
485 gen_advance_ccount(dc);
486 tcg_gen_brcond_i32(cond, t0, t1, label);
487 gen_jumpi_check_loop_end(dc, 0);
488 gen_set_label(label);
489 gen_jumpi(dc, dc->pc + offset, 1);
492 static void gen_brcondi(DisasContext *dc, TCGCond cond,
493 TCGv_i32 t0, uint32_t t1, uint32_t offset)
495 TCGv_i32 tmp = tcg_const_i32(t1);
496 gen_brcond(dc, cond, t0, tmp, offset);
500 static bool gen_check_sr(DisasContext *dc, uint32_t sr, unsigned access)
502 if (!xtensa_option_bits_enabled(dc->config, sregnames[sr].opt_bits)) {
503 if (sregnames[sr].name) {
504 qemu_log("SR %s is not configured\n", sregnames[sr].name);
506 qemu_log("SR %d is not implemented\n", sr);
508 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
510 } else if (!(sregnames[sr].access & access)) {
511 static const char * const access_text[] = {
516 assert(access < ARRAY_SIZE(access_text) && access_text[access]);
517 qemu_log("SR %s is not available for %s\n", sregnames[sr].name,
518 access_text[access]);
519 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
525 static void gen_rsr_ccount(DisasContext *dc, TCGv_i32 d, uint32_t sr)
527 gen_advance_ccount(dc);
528 tcg_gen_mov_i32(d, cpu_SR[sr]);
531 static void gen_rsr_ptevaddr(DisasContext *dc, TCGv_i32 d, uint32_t sr)
533 tcg_gen_shri_i32(d, cpu_SR[EXCVADDR], 10);
534 tcg_gen_or_i32(d, d, cpu_SR[sr]);
535 tcg_gen_andi_i32(d, d, 0xfffffffc);
538 static void gen_rsr(DisasContext *dc, TCGv_i32 d, uint32_t sr)
540 static void (* const rsr_handler[256])(DisasContext *dc,
541 TCGv_i32 d, uint32_t sr) = {
542 [CCOUNT] = gen_rsr_ccount,
543 [PTEVADDR] = gen_rsr_ptevaddr,
546 if (rsr_handler[sr]) {
547 rsr_handler[sr](dc, d, sr);
549 tcg_gen_mov_i32(d, cpu_SR[sr]);
553 static void gen_wsr_lbeg(DisasContext *dc, uint32_t sr, TCGv_i32 s)
555 gen_helper_wsr_lbeg(cpu_env, s);
556 gen_jumpi_check_loop_end(dc, 0);
559 static void gen_wsr_lend(DisasContext *dc, uint32_t sr, TCGv_i32 s)
561 gen_helper_wsr_lend(cpu_env, s);
562 gen_jumpi_check_loop_end(dc, 0);
565 static void gen_wsr_sar(DisasContext *dc, uint32_t sr, TCGv_i32 s)
567 tcg_gen_andi_i32(cpu_SR[sr], s, 0x3f);
568 if (dc->sar_m32_5bit) {
569 tcg_gen_discard_i32(dc->sar_m32);
571 dc->sar_5bit = false;
572 dc->sar_m32_5bit = false;
575 static void gen_wsr_br(DisasContext *dc, uint32_t sr, TCGv_i32 s)
577 tcg_gen_andi_i32(cpu_SR[sr], s, 0xffff);
580 static void gen_wsr_litbase(DisasContext *dc, uint32_t sr, TCGv_i32 s)
582 tcg_gen_andi_i32(cpu_SR[sr], s, 0xfffff001);
583 /* This can change tb->flags, so exit tb */
584 gen_jumpi_check_loop_end(dc, -1);
587 static void gen_wsr_acchi(DisasContext *dc, uint32_t sr, TCGv_i32 s)
589 tcg_gen_ext8s_i32(cpu_SR[sr], s);
592 static void gen_wsr_windowbase(DisasContext *dc, uint32_t sr, TCGv_i32 v)
594 gen_helper_wsr_windowbase(cpu_env, v);
595 /* This can change tb->flags, so exit tb */
596 gen_jumpi_check_loop_end(dc, -1);
599 static void gen_wsr_windowstart(DisasContext *dc, uint32_t sr, TCGv_i32 v)
601 tcg_gen_andi_i32(cpu_SR[sr], v, (1 << dc->config->nareg / 4) - 1);
602 /* This can change tb->flags, so exit tb */
603 gen_jumpi_check_loop_end(dc, -1);
606 static void gen_wsr_ptevaddr(DisasContext *dc, uint32_t sr, TCGv_i32 v)
608 tcg_gen_andi_i32(cpu_SR[sr], v, 0xffc00000);
611 static void gen_wsr_rasid(DisasContext *dc, uint32_t sr, TCGv_i32 v)
613 gen_helper_wsr_rasid(cpu_env, v);
614 /* This can change tb->flags, so exit tb */
615 gen_jumpi_check_loop_end(dc, -1);
618 static void gen_wsr_tlbcfg(DisasContext *dc, uint32_t sr, TCGv_i32 v)
620 tcg_gen_andi_i32(cpu_SR[sr], v, 0x01130000);
623 static void gen_wsr_ibreakenable(DisasContext *dc, uint32_t sr, TCGv_i32 v)
625 gen_helper_wsr_ibreakenable(cpu_env, v);
626 gen_jumpi_check_loop_end(dc, 0);
629 static void gen_wsr_atomctl(DisasContext *dc, uint32_t sr, TCGv_i32 v)
631 tcg_gen_andi_i32(cpu_SR[sr], v, 0x3f);
634 static void gen_wsr_ibreaka(DisasContext *dc, uint32_t sr, TCGv_i32 v)
636 unsigned id = sr - IBREAKA;
638 if (id < dc->config->nibreak) {
639 TCGv_i32 tmp = tcg_const_i32(id);
640 gen_helper_wsr_ibreaka(cpu_env, tmp, v);
642 gen_jumpi_check_loop_end(dc, 0);
646 static void gen_wsr_dbreaka(DisasContext *dc, uint32_t sr, TCGv_i32 v)
648 unsigned id = sr - DBREAKA;
650 if (id < dc->config->ndbreak) {
651 TCGv_i32 tmp = tcg_const_i32(id);
652 gen_helper_wsr_dbreaka(cpu_env, tmp, v);
657 static void gen_wsr_dbreakc(DisasContext *dc, uint32_t sr, TCGv_i32 v)
659 unsigned id = sr - DBREAKC;
661 if (id < dc->config->ndbreak) {
662 TCGv_i32 tmp = tcg_const_i32(id);
663 gen_helper_wsr_dbreakc(cpu_env, tmp, v);
668 static void gen_wsr_cpenable(DisasContext *dc, uint32_t sr, TCGv_i32 v)
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);
675 static void gen_wsr_intset(DisasContext *dc, uint32_t sr, TCGv_i32 v)
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);
683 static void gen_wsr_intclear(DisasContext *dc, uint32_t sr, TCGv_i32 v)
685 TCGv_i32 tmp = tcg_temp_new_i32();
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);
693 gen_helper_check_interrupts(cpu_env);
696 static void gen_wsr_intenable(DisasContext *dc, uint32_t sr, TCGv_i32 v)
698 tcg_gen_mov_i32(cpu_SR[sr], v);
699 gen_helper_check_interrupts(cpu_env);
700 gen_jumpi_check_loop_end(dc, 0);
703 static void gen_wsr_ps(DisasContext *dc, uint32_t sr, TCGv_i32 v)
705 uint32_t mask = PS_WOE | PS_CALLINC | PS_OWB |
706 PS_UM | PS_EXCM | PS_INTLEVEL;
708 if (option_enabled(dc, XTENSA_OPTION_MMU)) {
711 tcg_gen_andi_i32(cpu_SR[sr], v, mask);
712 gen_helper_check_interrupts(cpu_env);
713 /* This can change mmu index and tb->flags, so exit tb */
714 gen_jumpi_check_loop_end(dc, -1);
717 static void gen_wsr_icount(DisasContext *dc, uint32_t sr, TCGv_i32 v)
720 tcg_gen_mov_i32(dc->next_icount, v);
722 tcg_gen_mov_i32(cpu_SR[sr], v);
726 static void gen_wsr_icountlevel(DisasContext *dc, uint32_t sr, TCGv_i32 v)
728 tcg_gen_andi_i32(cpu_SR[sr], v, 0xf);
729 /* This can change tb->flags, so exit tb */
730 gen_jumpi_check_loop_end(dc, -1);
733 static void gen_wsr_ccompare(DisasContext *dc, uint32_t sr, TCGv_i32 v)
735 uint32_t id = sr - CCOMPARE;
736 if (id < dc->config->nccompare) {
737 uint32_t int_bit = 1 << dc->config->timerint[id];
738 gen_advance_ccount(dc);
739 tcg_gen_mov_i32(cpu_SR[sr], v);
740 tcg_gen_andi_i32(cpu_SR[INTSET], cpu_SR[INTSET], ~int_bit);
741 gen_helper_check_interrupts(cpu_env);
745 static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s)
747 static void (* const wsr_handler[256])(DisasContext *dc,
748 uint32_t sr, TCGv_i32 v) = {
749 [LBEG] = gen_wsr_lbeg,
750 [LEND] = gen_wsr_lend,
753 [LITBASE] = gen_wsr_litbase,
754 [ACCHI] = gen_wsr_acchi,
755 [WINDOW_BASE] = gen_wsr_windowbase,
756 [WINDOW_START] = gen_wsr_windowstart,
757 [PTEVADDR] = gen_wsr_ptevaddr,
758 [RASID] = gen_wsr_rasid,
759 [ITLBCFG] = gen_wsr_tlbcfg,
760 [DTLBCFG] = gen_wsr_tlbcfg,
761 [IBREAKENABLE] = gen_wsr_ibreakenable,
762 [ATOMCTL] = gen_wsr_atomctl,
763 [IBREAKA] = gen_wsr_ibreaka,
764 [IBREAKA + 1] = gen_wsr_ibreaka,
765 [DBREAKA] = gen_wsr_dbreaka,
766 [DBREAKA + 1] = gen_wsr_dbreaka,
767 [DBREAKC] = gen_wsr_dbreakc,
768 [DBREAKC + 1] = gen_wsr_dbreakc,
769 [CPENABLE] = gen_wsr_cpenable,
770 [INTSET] = gen_wsr_intset,
771 [INTCLEAR] = gen_wsr_intclear,
772 [INTENABLE] = gen_wsr_intenable,
774 [ICOUNT] = gen_wsr_icount,
775 [ICOUNTLEVEL] = gen_wsr_icountlevel,
776 [CCOMPARE] = gen_wsr_ccompare,
777 [CCOMPARE + 1] = gen_wsr_ccompare,
778 [CCOMPARE + 2] = gen_wsr_ccompare,
781 if (wsr_handler[sr]) {
782 wsr_handler[sr](dc, sr, s);
784 tcg_gen_mov_i32(cpu_SR[sr], s);
788 static void gen_wur(uint32_t ur, TCGv_i32 s)
792 gen_helper_wur_fcr(cpu_env, s);
796 tcg_gen_andi_i32(cpu_UR[ur], s, 0xffffff80);
800 tcg_gen_mov_i32(cpu_UR[ur], s);
805 static void gen_load_store_alignment(DisasContext *dc, int shift,
806 TCGv_i32 addr, bool no_hw_alignment)
808 if (!option_enabled(dc, XTENSA_OPTION_UNALIGNED_EXCEPTION)) {
809 tcg_gen_andi_i32(addr, addr, ~0 << shift);
810 } else if (option_enabled(dc, XTENSA_OPTION_HW_ALIGNMENT) &&
812 TCGLabel *label = gen_new_label();
813 TCGv_i32 tmp = tcg_temp_new_i32();
814 tcg_gen_andi_i32(tmp, addr, ~(~0 << shift));
815 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
816 gen_exception_cause_vaddr(dc, LOAD_STORE_ALIGNMENT_CAUSE, addr);
817 gen_set_label(label);
822 static void gen_waiti(DisasContext *dc, uint32_t imm4)
824 TCGv_i32 pc = tcg_const_i32(dc->next_pc);
825 TCGv_i32 intlevel = tcg_const_i32(imm4);
826 gen_advance_ccount(dc);
827 gen_helper_waiti(cpu_env, pc, intlevel);
829 tcg_temp_free(intlevel);
832 static bool gen_window_check1(DisasContext *dc, unsigned r1)
834 if (r1 / 4 > dc->window) {
835 TCGv_i32 pc = tcg_const_i32(dc->pc);
836 TCGv_i32 w = tcg_const_i32(r1 / 4);
838 gen_advance_ccount(dc);
839 gen_helper_window_check(cpu_env, pc, w);
840 dc->is_jmp = DISAS_UPDATE;
846 static bool gen_window_check2(DisasContext *dc, unsigned r1, unsigned r2)
848 return gen_window_check1(dc, r1 > r2 ? r1 : r2);
851 static bool gen_window_check3(DisasContext *dc, unsigned r1, unsigned r2,
854 return gen_window_check2(dc, r1, r2 > r3 ? r2 : r3);
857 static TCGv_i32 gen_mac16_m(TCGv_i32 v, bool hi, bool is_unsigned)
859 TCGv_i32 m = tcg_temp_new_i32();
862 (is_unsigned ? tcg_gen_shri_i32 : tcg_gen_sari_i32)(m, v, 16);
864 (is_unsigned ? tcg_gen_ext16u_i32 : tcg_gen_ext16s_i32)(m, v);
869 static inline unsigned xtensa_op0_insn_len(unsigned op0)
871 return op0 >= 8 ? 2 : 3;
874 static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)
876 #define HAS_OPTION_BITS(opt) do { \
877 if (!option_bits_enabled(dc, opt)) { \
878 qemu_log("Option is not enabled %s:%d\n", \
879 __FILE__, __LINE__); \
880 goto invalid_opcode; \
884 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
886 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
887 #define RESERVED() do { \
888 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
889 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
890 goto invalid_opcode; \
894 #ifdef TARGET_WORDS_BIGENDIAN
895 #define OP0 (((b0) & 0xf0) >> 4)
896 #define OP1 (((b2) & 0xf0) >> 4)
897 #define OP2 ((b2) & 0xf)
898 #define RRR_R ((b1) & 0xf)
899 #define RRR_S (((b1) & 0xf0) >> 4)
900 #define RRR_T ((b0) & 0xf)
902 #define OP0 (((b0) & 0xf))
903 #define OP1 (((b2) & 0xf))
904 #define OP2 (((b2) & 0xf0) >> 4)
905 #define RRR_R (((b1) & 0xf0) >> 4)
906 #define RRR_S (((b1) & 0xf))
907 #define RRR_T (((b0) & 0xf0) >> 4)
909 #define RRR_X ((RRR_R & 0x4) >> 2)
910 #define RRR_Y ((RRR_T & 0x4) >> 2)
911 #define RRR_W (RRR_R & 0x3)
920 #ifdef TARGET_WORDS_BIGENDIAN
921 #define RRI4_IMM4 ((b2) & 0xf)
923 #define RRI4_IMM4 (((b2) & 0xf0) >> 4)
929 #define RRI8_IMM8 (b2)
930 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
932 #ifdef TARGET_WORDS_BIGENDIAN
933 #define RI16_IMM16 (((b1) << 8) | (b2))
935 #define RI16_IMM16 (((b2) << 8) | (b1))
938 #ifdef TARGET_WORDS_BIGENDIAN
939 #define CALL_N (((b0) & 0xc) >> 2)
940 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
942 #define CALL_N (((b0) & 0x30) >> 4)
943 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
945 #define CALL_OFFSET_SE \
946 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
948 #define CALLX_N CALL_N
949 #ifdef TARGET_WORDS_BIGENDIAN
950 #define CALLX_M ((b0) & 0x3)
952 #define CALLX_M (((b0) & 0xc0) >> 6)
954 #define CALLX_S RRR_S
956 #define BRI12_M CALLX_M
957 #define BRI12_S RRR_S
958 #ifdef TARGET_WORDS_BIGENDIAN
959 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
961 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
963 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
965 #define BRI8_M BRI12_M
966 #define BRI8_R RRI8_R
967 #define BRI8_S RRI8_S
968 #define BRI8_IMM8 RRI8_IMM8
969 #define BRI8_IMM8_SE RRI8_IMM8_SE
973 uint8_t b0 = cpu_ldub_code(env, dc->pc);
974 uint8_t b1 = cpu_ldub_code(env, dc->pc + 1);
976 unsigned len = xtensa_op0_insn_len(OP0);
978 static const uint32_t B4CONST[] = {
979 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
982 static const uint32_t B4CONSTU[] = {
983 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
988 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY);
992 b2 = cpu_ldub_code(env, dc->pc + 2);
998 dc->next_pc = dc->pc + len;
1006 if ((RRR_R & 0xc) == 0x8) {
1007 HAS_OPTION(XTENSA_OPTION_BOOLEAN);
1014 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
1017 case 1: /*reserved*/
1025 if (gen_window_check1(dc, CALLX_S)) {
1026 gen_jump(dc, cpu_R[CALLX_S]);
1031 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1033 TCGv_i32 tmp = tcg_const_i32(dc->pc);
1034 gen_advance_ccount(dc);
1035 gen_helper_retw(tmp, cpu_env, tmp);
1041 case 3: /*reserved*/
1048 if (!gen_window_check2(dc, CALLX_S, CALLX_N << 2)) {
1054 TCGv_i32 tmp = tcg_temp_new_i32();
1055 tcg_gen_mov_i32(tmp, cpu_R[CALLX_S]);
1056 tcg_gen_movi_i32(cpu_R[0], dc->next_pc);
1064 case 3: /*CALLX12w*/
1065 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1067 TCGv_i32 tmp = tcg_temp_new_i32();
1069 tcg_gen_mov_i32(tmp, cpu_R[CALLX_S]);
1070 gen_callw(dc, CALLX_N, tmp);
1080 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1081 if (gen_window_check2(dc, RRR_T, RRR_S)) {
1082 TCGv_i32 pc = tcg_const_i32(dc->pc);
1083 gen_advance_ccount(dc);
1084 gen_helper_movsp(cpu_env, pc);
1085 tcg_gen_mov_i32(cpu_R[RRR_T], cpu_R[RRR_S]);
1105 HAS_OPTION(XTENSA_OPTION_EXCEPTION);
1117 default: /*reserved*/
1126 HAS_OPTION(XTENSA_OPTION_EXCEPTION);
1129 if (gen_check_privilege(dc)) {
1130 tcg_gen_andi_i32(cpu_SR[PS], cpu_SR[PS], ~PS_EXCM);
1131 gen_helper_check_interrupts(cpu_env);
1132 gen_jump(dc, cpu_SR[EPC1]);
1141 if (gen_check_privilege(dc)) {
1142 gen_jump(dc, cpu_SR[
1143 dc->config->ndepc ? DEPC : EPC1]);
1149 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1150 if (gen_check_privilege(dc)) {
1151 TCGv_i32 tmp = tcg_const_i32(1);
1154 cpu_SR[PS], cpu_SR[PS], ~PS_EXCM);
1155 tcg_gen_shl_i32(tmp, tmp, cpu_SR[WINDOW_BASE]);
1158 tcg_gen_andc_i32(cpu_SR[WINDOW_START],
1159 cpu_SR[WINDOW_START], tmp);
1161 tcg_gen_or_i32(cpu_SR[WINDOW_START],
1162 cpu_SR[WINDOW_START], tmp);
1165 gen_helper_restore_owb(cpu_env);
1166 gen_helper_check_interrupts(cpu_env);
1167 gen_jump(dc, cpu_SR[EPC1]);
1173 default: /*reserved*/
1180 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT);
1181 if (RRR_S >= 2 && RRR_S <= dc->config->nlevel) {
1182 if (gen_check_privilege(dc)) {
1183 tcg_gen_mov_i32(cpu_SR[PS],
1184 cpu_SR[EPS2 + RRR_S - 2]);
1185 gen_helper_check_interrupts(cpu_env);
1186 gen_jump(dc, cpu_SR[EPC1 + RRR_S - 1]);
1189 qemu_log("RFI %d is illegal\n", RRR_S);
1190 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
1198 default: /*reserved*/
1206 HAS_OPTION(XTENSA_OPTION_DEBUG);
1208 gen_debug_exception(dc, DEBUGCAUSE_BI);
1212 case 5: /*SYSCALLx*/
1213 HAS_OPTION(XTENSA_OPTION_EXCEPTION);
1215 case 0: /*SYSCALLx*/
1216 gen_exception_cause(dc, SYSCALL_CAUSE);
1220 if (semihosting_enabled()) {
1221 if (gen_check_privilege(dc)) {
1222 gen_helper_simcall(cpu_env);
1225 qemu_log("SIMCALL but semihosting is disabled\n");
1226 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
1237 HAS_OPTION(XTENSA_OPTION_INTERRUPT);
1238 if (gen_check_privilege(dc) &&
1239 gen_window_check1(dc, RRR_T)) {
1240 tcg_gen_mov_i32(cpu_R[RRR_T], cpu_SR[PS]);
1241 tcg_gen_andi_i32(cpu_SR[PS], cpu_SR[PS], ~PS_INTLEVEL);
1242 tcg_gen_ori_i32(cpu_SR[PS], cpu_SR[PS], RRR_S);
1243 gen_helper_check_interrupts(cpu_env);
1244 gen_jumpi_check_loop_end(dc, 0);
1249 HAS_OPTION(XTENSA_OPTION_INTERRUPT);
1250 if (gen_check_privilege(dc)) {
1251 gen_waiti(dc, RRR_S);
1259 HAS_OPTION(XTENSA_OPTION_BOOLEAN);
1261 const unsigned shift = (RRR_R & 2) ? 8 : 4;
1262 TCGv_i32 mask = tcg_const_i32(
1263 ((1 << shift) - 1) << RRR_S);
1264 TCGv_i32 tmp = tcg_temp_new_i32();
1266 tcg_gen_and_i32(tmp, cpu_SR[BR], mask);
1267 if (RRR_R & 1) { /*ALL*/
1268 tcg_gen_addi_i32(tmp, tmp, 1 << RRR_S);
1270 tcg_gen_add_i32(tmp, tmp, mask);
1272 tcg_gen_shri_i32(tmp, tmp, RRR_S + shift);
1273 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR],
1275 tcg_temp_free(mask);
1280 default: /*reserved*/
1288 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1289 tcg_gen_and_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1294 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1295 tcg_gen_or_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1300 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1301 tcg_gen_xor_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1308 if (gen_window_check1(dc, RRR_S)) {
1309 gen_right_shift_sar(dc, cpu_R[RRR_S]);
1314 if (gen_window_check1(dc, RRR_S)) {
1315 gen_left_shift_sar(dc, cpu_R[RRR_S]);
1320 if (gen_window_check1(dc, RRR_S)) {
1321 TCGv_i32 tmp = tcg_temp_new_i32();
1322 tcg_gen_shli_i32(tmp, cpu_R[RRR_S], 3);
1323 gen_right_shift_sar(dc, tmp);
1329 if (gen_window_check1(dc, RRR_S)) {
1330 TCGv_i32 tmp = tcg_temp_new_i32();
1331 tcg_gen_shli_i32(tmp, cpu_R[RRR_S], 3);
1332 gen_left_shift_sar(dc, tmp);
1339 TCGv_i32 tmp = tcg_const_i32(
1340 RRR_S | ((RRR_T & 1) << 4));
1341 gen_right_shift_sar(dc, tmp);
1355 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1356 if (gen_check_privilege(dc)) {
1357 TCGv_i32 tmp = tcg_const_i32(
1358 RRR_T | ((RRR_T & 8) ? 0xfffffff0 : 0));
1359 gen_helper_rotw(cpu_env, tmp);
1361 /* This can change tb->flags, so exit tb */
1362 gen_jumpi_check_loop_end(dc, -1);
1367 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA);
1368 if (gen_window_check2(dc, RRR_S, RRR_T)) {
1369 gen_helper_nsa(cpu_R[RRR_T], cpu_R[RRR_S]);
1374 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA);
1375 if (gen_window_check2(dc, RRR_S, RRR_T)) {
1376 gen_helper_nsau(cpu_R[RRR_T], cpu_R[RRR_S]);
1380 default: /*reserved*/
1388 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU) |
1389 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION) |
1390 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION));
1391 if (gen_check_privilege(dc) &&
1392 gen_window_check2(dc, RRR_S, RRR_T)) {
1393 TCGv_i32 dtlb = tcg_const_i32((RRR_R & 8) != 0);
1395 switch (RRR_R & 7) {
1396 case 3: /*RITLB0*/ /*RDTLB0*/
1397 gen_helper_rtlb0(cpu_R[RRR_T],
1398 cpu_env, cpu_R[RRR_S], dtlb);
1401 case 4: /*IITLB*/ /*IDTLB*/
1402 gen_helper_itlb(cpu_env, cpu_R[RRR_S], dtlb);
1403 /* This could change memory mapping, so exit tb */
1404 gen_jumpi_check_loop_end(dc, -1);
1407 case 5: /*PITLB*/ /*PDTLB*/
1408 tcg_gen_movi_i32(cpu_pc, dc->pc);
1409 gen_helper_ptlb(cpu_R[RRR_T],
1410 cpu_env, cpu_R[RRR_S], dtlb);
1413 case 6: /*WITLB*/ /*WDTLB*/
1415 cpu_env, cpu_R[RRR_T], cpu_R[RRR_S], dtlb);
1416 /* This could change memory mapping, so exit tb */
1417 gen_jumpi_check_loop_end(dc, -1);
1420 case 7: /*RITLB1*/ /*RDTLB1*/
1421 gen_helper_rtlb1(cpu_R[RRR_T],
1422 cpu_env, cpu_R[RRR_S], dtlb);
1426 tcg_temp_free(dtlb);
1430 tcg_temp_free(dtlb);
1435 if (!gen_window_check2(dc, RRR_R, RRR_T)) {
1440 tcg_gen_neg_i32(cpu_R[RRR_R], cpu_R[RRR_T]);
1445 TCGv_i32 zero = tcg_const_i32(0);
1446 TCGv_i32 neg = tcg_temp_new_i32();
1448 tcg_gen_neg_i32(neg, cpu_R[RRR_T]);
1449 tcg_gen_movcond_i32(TCG_COND_GE, cpu_R[RRR_R],
1450 cpu_R[RRR_T], zero, cpu_R[RRR_T], neg);
1452 tcg_temp_free(zero);
1456 default: /*reserved*/
1462 case 7: /*reserved*/
1467 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1468 tcg_gen_add_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1475 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1476 TCGv_i32 tmp = tcg_temp_new_i32();
1477 tcg_gen_shli_i32(tmp, cpu_R[RRR_S], OP2 - 8);
1478 tcg_gen_add_i32(cpu_R[RRR_R], tmp, cpu_R[RRR_T]);
1484 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1485 tcg_gen_sub_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1492 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1493 TCGv_i32 tmp = tcg_temp_new_i32();
1494 tcg_gen_shli_i32(tmp, cpu_R[RRR_S], OP2 - 12);
1495 tcg_gen_sub_i32(cpu_R[RRR_R], tmp, cpu_R[RRR_T]);
1506 if (gen_window_check2(dc, RRR_R, RRR_S)) {
1507 tcg_gen_shli_i32(cpu_R[RRR_R], cpu_R[RRR_S],
1508 32 - (RRR_T | ((OP2 & 1) << 4)));
1514 if (gen_window_check2(dc, RRR_R, RRR_T)) {
1515 tcg_gen_sari_i32(cpu_R[RRR_R], cpu_R[RRR_T],
1516 RRR_S | ((OP2 & 1) << 4));
1521 if (gen_window_check2(dc, RRR_R, RRR_T)) {
1522 tcg_gen_shri_i32(cpu_R[RRR_R], cpu_R[RRR_T], RRR_S);
1527 if (gen_check_sr(dc, RSR_SR, SR_X) &&
1528 (RSR_SR < 64 || gen_check_privilege(dc)) &&
1529 gen_window_check1(dc, RRR_T)) {
1530 TCGv_i32 tmp = tcg_temp_new_i32();
1532 tcg_gen_mov_i32(tmp, cpu_R[RRR_T]);
1533 gen_rsr(dc, cpu_R[RRR_T], RSR_SR);
1534 gen_wsr(dc, RSR_SR, tmp);
1540 * Note: 64 bit ops are used here solely because SAR values
1543 #define gen_shift_reg(cmd, reg) do { \
1544 TCGv_i64 tmp = tcg_temp_new_i64(); \
1545 tcg_gen_extu_i32_i64(tmp, reg); \
1546 tcg_gen_##cmd##_i64(v, v, tmp); \
1547 tcg_gen_extrl_i64_i32(cpu_R[RRR_R], v); \
1548 tcg_temp_free_i64(v); \
1549 tcg_temp_free_i64(tmp); \
1552 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1555 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1556 TCGv_i64 v = tcg_temp_new_i64();
1557 tcg_gen_concat_i32_i64(v, cpu_R[RRR_T], cpu_R[RRR_S]);
1563 if (!gen_window_check2(dc, RRR_R, RRR_T)) {
1567 tcg_gen_shr_i32(cpu_R[RRR_R], cpu_R[RRR_T], cpu_SR[SAR]);
1569 TCGv_i64 v = tcg_temp_new_i64();
1570 tcg_gen_extu_i32_i64(v, cpu_R[RRR_T]);
1576 if (!gen_window_check2(dc, RRR_R, RRR_S)) {
1579 if (dc->sar_m32_5bit) {
1580 tcg_gen_shl_i32(cpu_R[RRR_R], cpu_R[RRR_S], dc->sar_m32);
1582 TCGv_i64 v = tcg_temp_new_i64();
1583 TCGv_i32 s = tcg_const_i32(32);
1584 tcg_gen_sub_i32(s, s, cpu_SR[SAR]);
1585 tcg_gen_andi_i32(s, s, 0x3f);
1586 tcg_gen_extu_i32_i64(v, cpu_R[RRR_S]);
1587 gen_shift_reg(shl, s);
1593 if (!gen_window_check2(dc, RRR_R, RRR_T)) {
1597 tcg_gen_sar_i32(cpu_R[RRR_R], cpu_R[RRR_T], cpu_SR[SAR]);
1599 TCGv_i64 v = tcg_temp_new_i64();
1600 tcg_gen_ext_i32_i64(v, cpu_R[RRR_T]);
1605 #undef gen_shift_reg
1608 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL);
1609 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1610 TCGv_i32 v1 = tcg_temp_new_i32();
1611 TCGv_i32 v2 = tcg_temp_new_i32();
1612 tcg_gen_ext16u_i32(v1, cpu_R[RRR_S]);
1613 tcg_gen_ext16u_i32(v2, cpu_R[RRR_T]);
1614 tcg_gen_mul_i32(cpu_R[RRR_R], v1, v2);
1621 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL);
1622 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1623 TCGv_i32 v1 = tcg_temp_new_i32();
1624 TCGv_i32 v2 = tcg_temp_new_i32();
1625 tcg_gen_ext16s_i32(v1, cpu_R[RRR_S]);
1626 tcg_gen_ext16s_i32(v2, cpu_R[RRR_T]);
1627 tcg_gen_mul_i32(cpu_R[RRR_R], v1, v2);
1633 default: /*reserved*/
1640 if (OP2 >= 8 && !gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1645 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV);
1646 TCGLabel *label = gen_new_label();
1647 tcg_gen_brcondi_i32(TCG_COND_NE, cpu_R[RRR_T], 0, label);
1648 gen_exception_cause(dc, INTEGER_DIVIDE_BY_ZERO_CAUSE);
1649 gen_set_label(label);
1653 #define BOOLEAN_LOGIC(fn, r, s, t) \
1655 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1656 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1657 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1659 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1660 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1661 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1662 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1663 tcg_temp_free(tmp1); \
1664 tcg_temp_free(tmp2); \
1668 BOOLEAN_LOGIC(and, RRR_R, RRR_S, RRR_T);
1672 BOOLEAN_LOGIC(andc, RRR_R, RRR_S, RRR_T);
1676 BOOLEAN_LOGIC(or, RRR_R, RRR_S, RRR_T);
1680 BOOLEAN_LOGIC(orc, RRR_R, RRR_S, RRR_T);
1684 BOOLEAN_LOGIC(xor, RRR_R, RRR_S, RRR_T);
1687 #undef BOOLEAN_LOGIC
1690 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL);
1691 tcg_gen_mul_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1696 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH);
1698 TCGv lo = tcg_temp_new();
1701 tcg_gen_mulu2_i32(lo, cpu_R[RRR_R],
1702 cpu_R[RRR_S], cpu_R[RRR_T]);
1704 tcg_gen_muls2_i32(lo, cpu_R[RRR_R],
1705 cpu_R[RRR_S], cpu_R[RRR_T]);
1712 tcg_gen_divu_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1718 TCGLabel *label1 = gen_new_label();
1719 TCGLabel *label2 = gen_new_label();
1721 tcg_gen_brcondi_i32(TCG_COND_NE, cpu_R[RRR_S], 0x80000000,
1723 tcg_gen_brcondi_i32(TCG_COND_NE, cpu_R[RRR_T], 0xffffffff,
1725 tcg_gen_movi_i32(cpu_R[RRR_R],
1726 OP2 == 13 ? 0x80000000 : 0);
1728 gen_set_label(label1);
1730 tcg_gen_div_i32(cpu_R[RRR_R],
1731 cpu_R[RRR_S], cpu_R[RRR_T]);
1733 tcg_gen_rem_i32(cpu_R[RRR_R],
1734 cpu_R[RRR_S], cpu_R[RRR_T]);
1736 gen_set_label(label2);
1741 tcg_gen_remu_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1744 default: /*reserved*/
1753 if (gen_check_sr(dc, RSR_SR, SR_R) &&
1754 (RSR_SR < 64 || gen_check_privilege(dc)) &&
1755 gen_window_check1(dc, RRR_T)) {
1756 gen_rsr(dc, cpu_R[RRR_T], RSR_SR);
1761 if (gen_check_sr(dc, RSR_SR, SR_W) &&
1762 (RSR_SR < 64 || gen_check_privilege(dc)) &&
1763 gen_window_check1(dc, RRR_T)) {
1764 gen_wsr(dc, RSR_SR, cpu_R[RRR_T]);
1769 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT);
1770 if (gen_window_check2(dc, RRR_R, RRR_S)) {
1771 int shift = 24 - RRR_T;
1774 tcg_gen_ext8s_i32(cpu_R[RRR_R], cpu_R[RRR_S]);
1775 } else if (shift == 16) {
1776 tcg_gen_ext16s_i32(cpu_R[RRR_R], cpu_R[RRR_S]);
1778 TCGv_i32 tmp = tcg_temp_new_i32();
1779 tcg_gen_shli_i32(tmp, cpu_R[RRR_S], shift);
1780 tcg_gen_sari_i32(cpu_R[RRR_R], tmp, shift);
1787 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS);
1788 if (gen_window_check2(dc, RRR_R, RRR_S)) {
1789 TCGv_i32 tmp1 = tcg_temp_new_i32();
1790 TCGv_i32 tmp2 = tcg_temp_new_i32();
1791 TCGv_i32 zero = tcg_const_i32(0);
1793 tcg_gen_sari_i32(tmp1, cpu_R[RRR_S], 24 - RRR_T);
1794 tcg_gen_xor_i32(tmp2, tmp1, cpu_R[RRR_S]);
1795 tcg_gen_andi_i32(tmp2, tmp2, 0xffffffff << (RRR_T + 7));
1797 tcg_gen_sari_i32(tmp1, cpu_R[RRR_S], 31);
1798 tcg_gen_xori_i32(tmp1, tmp1, 0xffffffff >> (25 - RRR_T));
1800 tcg_gen_movcond_i32(TCG_COND_EQ, cpu_R[RRR_R], tmp2, zero,
1801 cpu_R[RRR_S], tmp1);
1802 tcg_temp_free(tmp1);
1803 tcg_temp_free(tmp2);
1804 tcg_temp_free(zero);
1812 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX);
1813 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1814 static const TCGCond cond[] = {
1820 tcg_gen_movcond_i32(cond[OP2 - 4], cpu_R[RRR_R],
1821 cpu_R[RRR_S], cpu_R[RRR_T],
1822 cpu_R[RRR_S], cpu_R[RRR_T]);
1830 if (gen_window_check3(dc, RRR_R, RRR_S, RRR_T)) {
1831 static const TCGCond cond[] = {
1837 TCGv_i32 zero = tcg_const_i32(0);
1839 tcg_gen_movcond_i32(cond[OP2 - 8], cpu_R[RRR_R],
1840 cpu_R[RRR_T], zero, cpu_R[RRR_S], cpu_R[RRR_R]);
1841 tcg_temp_free(zero);
1847 HAS_OPTION(XTENSA_OPTION_BOOLEAN);
1848 if (gen_window_check2(dc, RRR_R, RRR_S)) {
1849 TCGv_i32 zero = tcg_const_i32(0);
1850 TCGv_i32 tmp = tcg_temp_new_i32();
1852 tcg_gen_andi_i32(tmp, cpu_SR[BR], 1 << RRR_T);
1853 tcg_gen_movcond_i32(OP2 & 1 ? TCG_COND_NE : TCG_COND_EQ,
1854 cpu_R[RRR_R], tmp, zero,
1855 cpu_R[RRR_S], cpu_R[RRR_R]);
1858 tcg_temp_free(zero);
1863 if (gen_window_check1(dc, RRR_R)) {
1864 int st = (RRR_S << 4) + RRR_T;
1865 if (uregnames[st].name) {
1866 tcg_gen_mov_i32(cpu_R[RRR_R], cpu_UR[st]);
1868 qemu_log("RUR %d not implemented, ", st);
1875 if (gen_window_check1(dc, RRR_T)) {
1876 if (uregnames[RSR_SR].name) {
1877 gen_wur(RSR_SR, cpu_R[RRR_T]);
1879 qemu_log("WUR %d not implemented, ", RSR_SR);
1890 if (gen_window_check2(dc, RRR_R, RRR_T)) {
1891 int shiftimm = RRR_S | ((OP1 & 1) << 4);
1892 int maskimm = (1 << (OP2 + 1)) - 1;
1894 TCGv_i32 tmp = tcg_temp_new_i32();
1895 tcg_gen_shri_i32(tmp, cpu_R[RRR_T], shiftimm);
1896 tcg_gen_andi_i32(cpu_R[RRR_R], tmp, maskimm);
1915 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR);
1916 if (gen_window_check2(dc, RRR_S, RRR_T) &&
1917 gen_check_cpenable(dc, 0)) {
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);
1922 tcg_gen_qemu_st32(cpu_FR[RRR_R], addr, dc->cring);
1924 tcg_gen_qemu_ld32u(cpu_FR[RRR_R], addr, dc->cring);
1927 tcg_gen_mov_i32(cpu_R[RRR_S], addr);
1929 tcg_temp_free(addr);
1933 default: /*reserved*/
1940 if (!gen_window_check2(dc, RRR_S, RRR_T)) {
1945 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1946 if (gen_check_privilege(dc) &&
1947 gen_window_check2(dc, RRR_S, RRR_T)) {
1948 TCGv_i32 addr = tcg_temp_new_i32();
1949 tcg_gen_addi_i32(addr, cpu_R[RRR_S],
1950 (0xffffffc0 | (RRR_R << 2)));
1951 tcg_gen_qemu_ld32u(cpu_R[RRR_T], addr, dc->ring);
1952 tcg_temp_free(addr);
1957 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1958 if (gen_check_privilege(dc) &&
1959 gen_window_check2(dc, RRR_S, RRR_T)) {
1960 TCGv_i32 addr = tcg_temp_new_i32();
1961 tcg_gen_addi_i32(addr, cpu_R[RRR_S],
1962 (0xffffffc0 | (RRR_R << 2)));
1963 tcg_gen_qemu_st32(cpu_R[RRR_T], addr, dc->ring);
1964 tcg_temp_free(addr);
1975 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR);
1978 if (gen_check_cpenable(dc, 0)) {
1979 gen_helper_add_s(cpu_FR[RRR_R], cpu_env,
1980 cpu_FR[RRR_S], cpu_FR[RRR_T]);
1985 if (gen_check_cpenable(dc, 0)) {
1986 gen_helper_sub_s(cpu_FR[RRR_R], cpu_env,
1987 cpu_FR[RRR_S], cpu_FR[RRR_T]);
1992 if (gen_check_cpenable(dc, 0)) {
1993 gen_helper_mul_s(cpu_FR[RRR_R], cpu_env,
1994 cpu_FR[RRR_S], cpu_FR[RRR_T]);
1999 if (gen_check_cpenable(dc, 0)) {
2000 gen_helper_madd_s(cpu_FR[RRR_R], cpu_env,
2001 cpu_FR[RRR_R], cpu_FR[RRR_S],
2007 if (gen_check_cpenable(dc, 0)) {
2008 gen_helper_msub_s(cpu_FR[RRR_R], cpu_env,
2009 cpu_FR[RRR_R], cpu_FR[RRR_S],
2014 case 8: /*ROUND.Sf*/
2015 case 9: /*TRUNC.Sf*/
2016 case 10: /*FLOOR.Sf*/
2017 case 11: /*CEIL.Sf*/
2018 case 14: /*UTRUNC.Sf*/
2019 if (gen_window_check1(dc, RRR_R) &&
2020 gen_check_cpenable(dc, 0)) {
2021 static const unsigned rounding_mode_const[] = {
2022 float_round_nearest_even,
2023 float_round_to_zero,
2026 [6] = float_round_to_zero,
2028 TCGv_i32 rounding_mode = tcg_const_i32(
2029 rounding_mode_const[OP2 & 7]);
2030 TCGv_i32 scale = tcg_const_i32(RRR_T);
2033 gen_helper_ftoui(cpu_R[RRR_R], cpu_FR[RRR_S],
2034 rounding_mode, scale);
2036 gen_helper_ftoi(cpu_R[RRR_R], cpu_FR[RRR_S],
2037 rounding_mode, scale);
2040 tcg_temp_free(rounding_mode);
2041 tcg_temp_free(scale);
2045 case 12: /*FLOAT.Sf*/
2046 case 13: /*UFLOAT.Sf*/
2047 if (gen_window_check1(dc, RRR_S) &&
2048 gen_check_cpenable(dc, 0)) {
2049 TCGv_i32 scale = tcg_const_i32(-RRR_T);
2052 gen_helper_uitof(cpu_FR[RRR_R], cpu_env,
2053 cpu_R[RRR_S], scale);
2055 gen_helper_itof(cpu_FR[RRR_R], cpu_env,
2056 cpu_R[RRR_S], scale);
2058 tcg_temp_free(scale);
2065 if (gen_check_cpenable(dc, 0)) {
2066 tcg_gen_mov_i32(cpu_FR[RRR_R], cpu_FR[RRR_S]);
2071 if (gen_check_cpenable(dc, 0)) {
2072 gen_helper_abs_s(cpu_FR[RRR_R], cpu_FR[RRR_S]);
2077 if (gen_window_check1(dc, RRR_R) &&
2078 gen_check_cpenable(dc, 0)) {
2079 tcg_gen_mov_i32(cpu_R[RRR_R], cpu_FR[RRR_S]);
2084 if (gen_window_check1(dc, RRR_S) &&
2085 gen_check_cpenable(dc, 0)) {
2086 tcg_gen_mov_i32(cpu_FR[RRR_R], cpu_R[RRR_S]);
2091 if (gen_check_cpenable(dc, 0)) {
2092 gen_helper_neg_s(cpu_FR[RRR_R], cpu_FR[RRR_S]);
2096 default: /*reserved*/
2102 default: /*reserved*/
2109 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR);
2111 #define gen_compare(rel, br, a, b) \
2113 if (gen_check_cpenable(dc, 0)) { \
2114 TCGv_i32 bit = tcg_const_i32(1 << br); \
2116 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2117 tcg_temp_free(bit); \
2123 gen_compare(un_s, RRR_R, RRR_S, RRR_T);
2127 gen_compare(oeq_s, RRR_R, RRR_S, RRR_T);
2131 gen_compare(ueq_s, RRR_R, RRR_S, RRR_T);
2135 gen_compare(olt_s, RRR_R, RRR_S, RRR_T);
2139 gen_compare(ult_s, RRR_R, RRR_S, RRR_T);
2143 gen_compare(ole_s, RRR_R, RRR_S, RRR_T);
2147 gen_compare(ule_s, RRR_R, RRR_S, RRR_T);
2152 case 8: /*MOVEQZ.Sf*/
2153 case 9: /*MOVNEZ.Sf*/
2154 case 10: /*MOVLTZ.Sf*/
2155 case 11: /*MOVGEZ.Sf*/
2156 if (gen_window_check1(dc, RRR_T) &&
2157 gen_check_cpenable(dc, 0)) {
2158 static const TCGCond cond[] = {
2164 TCGv_i32 zero = tcg_const_i32(0);
2166 tcg_gen_movcond_i32(cond[OP2 - 8], cpu_FR[RRR_R],
2167 cpu_R[RRR_T], zero, cpu_FR[RRR_S], cpu_FR[RRR_R]);
2168 tcg_temp_free(zero);
2172 case 12: /*MOVF.Sf*/
2173 case 13: /*MOVT.Sf*/
2174 HAS_OPTION(XTENSA_OPTION_BOOLEAN);
2175 if (gen_check_cpenable(dc, 0)) {
2176 TCGv_i32 zero = tcg_const_i32(0);
2177 TCGv_i32 tmp = tcg_temp_new_i32();
2179 tcg_gen_andi_i32(tmp, cpu_SR[BR], 1 << RRR_T);
2180 tcg_gen_movcond_i32(OP2 & 1 ? TCG_COND_NE : TCG_COND_EQ,
2181 cpu_FR[RRR_R], tmp, zero,
2182 cpu_FR[RRR_S], cpu_FR[RRR_R]);
2185 tcg_temp_free(zero);
2189 default: /*reserved*/
2195 default: /*reserved*/
2202 if (gen_window_check1(dc, RRR_T)) {
2203 TCGv_i32 tmp = tcg_const_i32(
2204 ((dc->tb->flags & XTENSA_TBFLAG_LITBASE) ?
2205 0 : ((dc->pc + 3) & ~3)) +
2206 (0xfffc0000 | (RI16_IMM16 << 2)));
2208 if (dc->tb->flags & XTENSA_TBFLAG_LITBASE) {
2209 tcg_gen_add_i32(tmp, tmp, dc->litbase);
2211 tcg_gen_qemu_ld32u(cpu_R[RRR_T], tmp, dc->cring);
2217 #define gen_load_store(type, shift) do { \
2218 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2219 TCGv_i32 addr = tcg_temp_new_i32(); \
2221 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2223 gen_load_store_alignment(dc, shift, addr, false); \
2225 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2226 tcg_temp_free(addr); \
2232 gen_load_store(ld8u, 0);
2236 gen_load_store(ld16u, 1);
2240 gen_load_store(ld32u, 2);
2244 gen_load_store(st8, 0);
2248 gen_load_store(st16, 1);
2252 gen_load_store(st32, 2);
2255 #define gen_dcache_hit_test(w, shift) do { \
2256 if (gen_window_check1(dc, RRI##w##_S)) { \
2257 TCGv_i32 addr = tcg_temp_new_i32(); \
2258 TCGv_i32 res = tcg_temp_new_i32(); \
2259 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2260 RRI##w##_IMM##w << shift); \
2261 tcg_gen_qemu_ld8u(res, addr, dc->cring); \
2262 tcg_temp_free(addr); \
2263 tcg_temp_free(res); \
2267 #define gen_dcache_hit_test4() gen_dcache_hit_test(4, 4)
2268 #define gen_dcache_hit_test8() gen_dcache_hit_test(8, 2)
2272 HAS_OPTION(XTENSA_OPTION_DCACHE);
2277 gen_window_check1(dc, RRI8_S);
2281 gen_window_check1(dc, RRI8_S);
2285 gen_window_check1(dc, RRI8_S);
2289 gen_window_check1(dc, RRI8_S);
2293 gen_dcache_hit_test8();
2297 gen_dcache_hit_test8();
2301 if (gen_check_privilege(dc)) {
2302 gen_dcache_hit_test8();
2307 if (gen_check_privilege(dc)) {
2308 gen_window_check1(dc, RRI8_S);
2315 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK);
2316 if (gen_check_privilege(dc)) {
2317 gen_dcache_hit_test4();
2322 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK);
2323 if (gen_check_privilege(dc)) {
2324 gen_dcache_hit_test4();
2329 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK);
2330 if (gen_check_privilege(dc)) {
2331 gen_window_check1(dc, RRI4_S);
2336 HAS_OPTION(XTENSA_OPTION_DCACHE);
2337 if (gen_check_privilege(dc)) {
2338 gen_window_check1(dc, RRI4_S);
2343 HAS_OPTION(XTENSA_OPTION_DCACHE);
2344 if (gen_check_privilege(dc)) {
2345 gen_window_check1(dc, RRI4_S);
2349 default: /*reserved*/
2356 #undef gen_dcache_hit_test
2357 #undef gen_dcache_hit_test4
2358 #undef gen_dcache_hit_test8
2360 #define gen_icache_hit_test(w, shift) do { \
2361 if (gen_window_check1(dc, RRI##w##_S)) { \
2362 TCGv_i32 addr = tcg_temp_new_i32(); \
2363 tcg_gen_movi_i32(cpu_pc, dc->pc); \
2364 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2365 RRI##w##_IMM##w << shift); \
2366 gen_helper_itlb_hit_test(cpu_env, addr); \
2367 tcg_temp_free(addr); \
2371 #define gen_icache_hit_test4() gen_icache_hit_test(4, 4)
2372 #define gen_icache_hit_test8() gen_icache_hit_test(8, 2)
2375 HAS_OPTION(XTENSA_OPTION_ICACHE);
2376 gen_window_check1(dc, RRI8_S);
2382 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK);
2383 if (gen_check_privilege(dc)) {
2384 gen_icache_hit_test4();
2389 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK);
2390 if (gen_check_privilege(dc)) {
2391 gen_icache_hit_test4();
2396 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK);
2397 if (gen_check_privilege(dc)) {
2398 gen_window_check1(dc, RRI4_S);
2402 default: /*reserved*/
2409 HAS_OPTION(XTENSA_OPTION_ICACHE);
2410 gen_icache_hit_test8();
2414 HAS_OPTION(XTENSA_OPTION_ICACHE);
2415 if (gen_check_privilege(dc)) {
2416 gen_window_check1(dc, RRI8_S);
2420 default: /*reserved*/
2426 #undef gen_icache_hit_test
2427 #undef gen_icache_hit_test4
2428 #undef gen_icache_hit_test8
2431 gen_load_store(ld16s, 1);
2433 #undef gen_load_store
2436 if (gen_window_check1(dc, RRI8_T)) {
2437 tcg_gen_movi_i32(cpu_R[RRI8_T],
2438 RRI8_IMM8 | (RRI8_S << 8) |
2439 ((RRI8_S & 0x8) ? 0xfffff000 : 0));
2443 #define gen_load_store_no_hw_align(type) do { \
2444 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2445 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2446 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2447 gen_load_store_alignment(dc, 2, addr, true); \
2448 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2449 tcg_temp_free(addr); \
2454 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO);
2455 gen_load_store_no_hw_align(ld32u); /*TODO acquire?*/
2459 if (gen_window_check2(dc, RRI8_S, RRI8_T)) {
2460 tcg_gen_addi_i32(cpu_R[RRI8_T], cpu_R[RRI8_S], RRI8_IMM8_SE);
2465 if (gen_window_check2(dc, RRI8_S, RRI8_T)) {
2466 tcg_gen_addi_i32(cpu_R[RRI8_T], cpu_R[RRI8_S],
2471 case 14: /*S32C1Iy*/
2472 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE);
2473 if (gen_window_check2(dc, RRI8_S, RRI8_T)) {
2474 TCGLabel *label = gen_new_label();
2475 TCGv_i32 tmp = tcg_temp_local_new_i32();
2476 TCGv_i32 addr = tcg_temp_local_new_i32();
2479 tcg_gen_mov_i32(tmp, cpu_R[RRI8_T]);
2480 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2);
2481 gen_load_store_alignment(dc, 2, addr, true);
2483 gen_advance_ccount(dc);
2484 tpc = tcg_const_i32(dc->pc);
2485 gen_helper_check_atomctl(cpu_env, tpc, addr);
2486 tcg_gen_qemu_ld32u(cpu_R[RRI8_T], addr, dc->cring);
2487 tcg_gen_brcond_i32(TCG_COND_NE, cpu_R[RRI8_T],
2488 cpu_SR[SCOMPARE1], label);
2490 tcg_gen_qemu_st32(tmp, addr, dc->cring);
2492 gen_set_label(label);
2494 tcg_temp_free(addr);
2500 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO);
2501 gen_load_store_no_hw_align(st32); /*TODO release?*/
2503 #undef gen_load_store_no_hw_align
2505 default: /*reserved*/
2517 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR);
2518 if (gen_window_check1(dc, RRI8_S) &&
2519 gen_check_cpenable(dc, 0)) {
2520 TCGv_i32 addr = tcg_temp_new_i32();
2521 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2);
2522 gen_load_store_alignment(dc, 2, addr, false);
2524 tcg_gen_qemu_st32(cpu_FR[RRI8_T], addr, dc->cring);
2526 tcg_gen_qemu_ld32u(cpu_FR[RRI8_T], addr, dc->cring);
2529 tcg_gen_mov_i32(cpu_R[RRI8_S], addr);
2531 tcg_temp_free(addr);
2535 default: /*reserved*/
2542 HAS_OPTION(XTENSA_OPTION_MAC16);
2551 bool is_m1_sr = (OP2 & 0x3) == 2;
2552 bool is_m2_sr = (OP2 & 0xc) == 0;
2553 uint32_t ld_offset = 0;
2560 case 0: /*MACI?/MACC?*/
2562 ld_offset = (OP2 & 1) ? -4 : 4;
2564 if (OP2 >= 8) { /*MACI/MACC*/
2565 if (OP1 == 0) { /*LDINC/LDDEC*/
2570 } else if (op != MAC16_MULA) { /*MULA.*.*.LDINC/LDDEC*/
2575 case 2: /*MACD?/MACA?*/
2576 if (op == MAC16_UMUL && OP2 != 7) { /*UMUL only in MACAA*/
2582 if (op != MAC16_NONE) {
2583 if (!is_m1_sr && !gen_window_check1(dc, RRR_S)) {
2586 if (!is_m2_sr && !gen_window_check1(dc, RRR_T)) {
2591 if (ld_offset && !gen_window_check1(dc, RRR_S)) {
2596 TCGv_i32 vaddr = tcg_temp_new_i32();
2597 TCGv_i32 mem32 = tcg_temp_new_i32();
2600 tcg_gen_addi_i32(vaddr, cpu_R[RRR_S], ld_offset);
2601 gen_load_store_alignment(dc, 2, vaddr, false);
2602 tcg_gen_qemu_ld32u(mem32, vaddr, dc->cring);
2604 if (op != MAC16_NONE) {
2605 TCGv_i32 m1 = gen_mac16_m(
2606 is_m1_sr ? cpu_SR[MR + RRR_X] : cpu_R[RRR_S],
2607 OP1 & 1, op == MAC16_UMUL);
2608 TCGv_i32 m2 = gen_mac16_m(
2609 is_m2_sr ? cpu_SR[MR + 2 + RRR_Y] : cpu_R[RRR_T],
2610 OP1 & 2, op == MAC16_UMUL);
2612 if (op == MAC16_MUL || op == MAC16_UMUL) {
2613 tcg_gen_mul_i32(cpu_SR[ACCLO], m1, m2);
2614 if (op == MAC16_UMUL) {
2615 tcg_gen_movi_i32(cpu_SR[ACCHI], 0);
2617 tcg_gen_sari_i32(cpu_SR[ACCHI], cpu_SR[ACCLO], 31);
2620 TCGv_i32 lo = tcg_temp_new_i32();
2621 TCGv_i32 hi = tcg_temp_new_i32();
2623 tcg_gen_mul_i32(lo, m1, m2);
2624 tcg_gen_sari_i32(hi, lo, 31);
2625 if (op == MAC16_MULA) {
2626 tcg_gen_add2_i32(cpu_SR[ACCLO], cpu_SR[ACCHI],
2627 cpu_SR[ACCLO], cpu_SR[ACCHI],
2630 tcg_gen_sub2_i32(cpu_SR[ACCLO], cpu_SR[ACCHI],
2631 cpu_SR[ACCLO], cpu_SR[ACCHI],
2634 tcg_gen_ext8s_i32(cpu_SR[ACCHI], cpu_SR[ACCHI]);
2636 tcg_temp_free_i32(lo);
2637 tcg_temp_free_i32(hi);
2643 tcg_gen_mov_i32(cpu_R[RRR_S], vaddr);
2644 tcg_gen_mov_i32(cpu_SR[MR + RRR_W], mem32);
2646 tcg_temp_free(vaddr);
2647 tcg_temp_free(mem32);
2655 tcg_gen_movi_i32(cpu_R[0], dc->next_pc);
2656 gen_jumpi(dc, (dc->pc & ~3) + (CALL_OFFSET_SE << 2) + 4, 0);
2662 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
2663 if (gen_window_check1(dc, CALL_N << 2)) {
2664 gen_callwi(dc, CALL_N,
2665 (dc->pc & ~3) + (CALL_OFFSET_SE << 2) + 4, 0);
2674 gen_jumpi(dc, dc->pc + 4 + CALL_OFFSET_SE, 0);
2678 if (gen_window_check1(dc, BRI12_S)) {
2679 static const TCGCond cond[] = {
2680 TCG_COND_EQ, /*BEQZ*/
2681 TCG_COND_NE, /*BNEZ*/
2682 TCG_COND_LT, /*BLTZ*/
2683 TCG_COND_GE, /*BGEZ*/
2686 gen_brcondi(dc, cond[BRI12_M & 3], cpu_R[BRI12_S], 0,
2687 4 + BRI12_IMM12_SE);
2692 if (gen_window_check1(dc, BRI8_S)) {
2693 static const TCGCond cond[] = {
2694 TCG_COND_EQ, /*BEQI*/
2695 TCG_COND_NE, /*BNEI*/
2696 TCG_COND_LT, /*BLTI*/
2697 TCG_COND_GE, /*BGEI*/
2700 gen_brcondi(dc, cond[BRI8_M & 3],
2701 cpu_R[BRI8_S], B4CONST[BRI8_R], 4 + BRI8_IMM8_SE);
2708 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
2710 TCGv_i32 pc = tcg_const_i32(dc->pc);
2711 TCGv_i32 s = tcg_const_i32(BRI12_S);
2712 TCGv_i32 imm = tcg_const_i32(BRI12_IMM12);
2713 gen_advance_ccount(dc);
2714 gen_helper_entry(cpu_env, pc, s, imm);
2718 /* This can change tb->flags, so exit tb */
2719 gen_jumpi_check_loop_end(dc, -1);
2727 HAS_OPTION(XTENSA_OPTION_BOOLEAN);
2729 TCGv_i32 tmp = tcg_temp_new_i32();
2730 tcg_gen_andi_i32(tmp, cpu_SR[BR], 1 << RRI8_S);
2732 BRI8_R == 1 ? TCG_COND_NE : TCG_COND_EQ,
2733 tmp, 0, 4 + RRI8_IMM8_SE);
2740 case 10: /*LOOPGTZ*/
2741 HAS_OPTION(XTENSA_OPTION_LOOP);
2742 if (gen_window_check1(dc, RRI8_S)) {
2743 uint32_t lend = dc->pc + RRI8_IMM8 + 4;
2744 TCGv_i32 tmp = tcg_const_i32(lend);
2746 tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_R[RRI8_S], 1);
2747 tcg_gen_movi_i32(cpu_SR[LBEG], dc->next_pc);
2748 gen_helper_wsr_lend(cpu_env, tmp);
2752 TCGLabel *label = gen_new_label();
2753 tcg_gen_brcondi_i32(
2754 BRI8_R == 9 ? TCG_COND_NE : TCG_COND_GT,
2755 cpu_R[RRI8_S], 0, label);
2756 gen_jumpi(dc, lend, 1);
2757 gen_set_label(label);
2760 gen_jumpi(dc, dc->next_pc, 0);
2764 default: /*reserved*/
2773 if (gen_window_check1(dc, BRI8_S)) {
2774 gen_brcondi(dc, BRI8_M == 2 ? TCG_COND_LTU : TCG_COND_GEU,
2775 cpu_R[BRI8_S], B4CONSTU[BRI8_R],
2787 TCGCond eq_ne = (RRI8_R & 8) ? TCG_COND_NE : TCG_COND_EQ;
2789 switch (RRI8_R & 7) {
2790 case 0: /*BNONE*/ /*BANY*/
2791 if (gen_window_check2(dc, RRI8_S, RRI8_T)) {
2792 TCGv_i32 tmp = tcg_temp_new_i32();
2793 tcg_gen_and_i32(tmp, cpu_R[RRI8_S], cpu_R[RRI8_T]);
2794 gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE);
2799 case 1: /*BEQ*/ /*BNE*/
2800 case 2: /*BLT*/ /*BGE*/
2801 case 3: /*BLTU*/ /*BGEU*/
2802 if (gen_window_check2(dc, RRI8_S, RRI8_T)) {
2803 static const TCGCond cond[] = {
2809 [11] = TCG_COND_GEU,
2811 gen_brcond(dc, cond[RRI8_R], cpu_R[RRI8_S], cpu_R[RRI8_T],
2816 case 4: /*BALL*/ /*BNALL*/
2817 if (gen_window_check2(dc, RRI8_S, RRI8_T)) {
2818 TCGv_i32 tmp = tcg_temp_new_i32();
2819 tcg_gen_and_i32(tmp, cpu_R[RRI8_S], cpu_R[RRI8_T]);
2820 gen_brcond(dc, eq_ne, tmp, cpu_R[RRI8_T],
2826 case 5: /*BBC*/ /*BBS*/
2827 if (gen_window_check2(dc, RRI8_S, RRI8_T)) {
2828 #ifdef TARGET_WORDS_BIGENDIAN
2829 TCGv_i32 bit = tcg_const_i32(0x80000000);
2831 TCGv_i32 bit = tcg_const_i32(0x00000001);
2833 TCGv_i32 tmp = tcg_temp_new_i32();
2834 tcg_gen_andi_i32(tmp, cpu_R[RRI8_T], 0x1f);
2835 #ifdef TARGET_WORDS_BIGENDIAN
2836 tcg_gen_shr_i32(bit, bit, tmp);
2838 tcg_gen_shl_i32(bit, bit, tmp);
2840 tcg_gen_and_i32(tmp, cpu_R[RRI8_S], bit);
2841 gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE);
2847 case 6: /*BBCI*/ /*BBSI*/
2849 if (gen_window_check1(dc, RRI8_S)) {
2850 TCGv_i32 tmp = tcg_temp_new_i32();
2851 tcg_gen_andi_i32(tmp, cpu_R[RRI8_S],
2852 #ifdef TARGET_WORDS_BIGENDIAN
2853 0x80000000 >> (((RRI8_R & 1) << 4) | RRI8_T));
2855 0x00000001 << (((RRI8_R & 1) << 4) | RRI8_T));
2857 gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE);
2866 #define gen_narrow_load_store(type) do { \
2867 if (gen_window_check2(dc, RRRN_S, RRRN_T)) { \
2868 TCGv_i32 addr = tcg_temp_new_i32(); \
2869 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2870 gen_load_store_alignment(dc, 2, addr, false); \
2871 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2872 tcg_temp_free(addr); \
2877 gen_narrow_load_store(ld32u);
2881 gen_narrow_load_store(st32);
2883 #undef gen_narrow_load_store
2886 if (gen_window_check3(dc, RRRN_R, RRRN_S, RRRN_T)) {
2887 tcg_gen_add_i32(cpu_R[RRRN_R], cpu_R[RRRN_S], cpu_R[RRRN_T]);
2891 case 11: /*ADDI.Nn*/
2892 if (gen_window_check2(dc, RRRN_R, RRRN_S)) {
2893 tcg_gen_addi_i32(cpu_R[RRRN_R], cpu_R[RRRN_S],
2894 RRRN_T ? RRRN_T : -1);
2899 if (!gen_window_check1(dc, RRRN_S)) {
2902 if (RRRN_T < 8) { /*MOVI.Nn*/
2903 tcg_gen_movi_i32(cpu_R[RRRN_S],
2904 RRRN_R | (RRRN_T << 4) |
2905 ((RRRN_T & 6) == 6 ? 0xffffff80 : 0));
2906 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2907 TCGCond eq_ne = (RRRN_T & 4) ? TCG_COND_NE : TCG_COND_EQ;
2909 gen_brcondi(dc, eq_ne, cpu_R[RRRN_S], 0,
2910 4 + (RRRN_R | ((RRRN_T & 3) << 4)));
2917 if (gen_window_check2(dc, RRRN_S, RRRN_T)) {
2918 tcg_gen_mov_i32(cpu_R[RRRN_T], cpu_R[RRRN_S]);
2925 gen_jump(dc, cpu_R[0]);
2929 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
2931 TCGv_i32 tmp = tcg_const_i32(dc->pc);
2932 gen_advance_ccount(dc);
2933 gen_helper_retw(tmp, cpu_env, tmp);
2939 case 2: /*BREAK.Nn*/
2940 HAS_OPTION(XTENSA_OPTION_DEBUG);
2942 gen_debug_exception(dc, DEBUGCAUSE_BN);
2950 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
2953 default: /*reserved*/
2959 default: /*reserved*/
2965 default: /*reserved*/
2970 if (dc->is_jmp == DISAS_NEXT) {
2971 gen_check_loop_end(dc, 0);
2973 dc->pc = dc->next_pc;
2978 qemu_log("INVALID(pc = %08x)\n", dc->pc);
2979 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
2983 static inline unsigned xtensa_insn_len(CPUXtensaState *env, DisasContext *dc)
2985 uint8_t b0 = cpu_ldub_code(env, dc->pc);
2986 return xtensa_op0_insn_len(OP0);
2989 static void gen_ibreak_check(CPUXtensaState *env, DisasContext *dc)
2993 for (i = 0; i < dc->config->nibreak; ++i) {
2994 if ((env->sregs[IBREAKENABLE] & (1 << i)) &&
2995 env->sregs[IBREAKA + i] == dc->pc) {
2996 gen_debug_exception(dc, DEBUGCAUSE_IB);
3002 void gen_intermediate_code(CPUXtensaState *env, TranslationBlock *tb)
3004 XtensaCPU *cpu = xtensa_env_get_cpu(env);
3005 CPUState *cs = CPU(cpu);
3008 int max_insns = tb->cflags & CF_COUNT_MASK;
3009 uint32_t pc_start = tb->pc;
3010 uint32_t next_page_start =
3011 (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
3013 if (max_insns == 0) {
3014 max_insns = CF_COUNT_MASK;
3016 if (max_insns > TCG_MAX_INSNS) {
3017 max_insns = TCG_MAX_INSNS;
3020 dc.config = env->config;
3021 dc.singlestep_enabled = cs->singlestep_enabled;
3024 dc.ring = tb->flags & XTENSA_TBFLAG_RING_MASK;
3025 dc.cring = (tb->flags & XTENSA_TBFLAG_EXCM) ? 0 : dc.ring;
3026 dc.lbeg = env->sregs[LBEG];
3027 dc.lend = env->sregs[LEND];
3028 dc.is_jmp = DISAS_NEXT;
3029 dc.ccount_delta = 0;
3030 dc.debug = tb->flags & XTENSA_TBFLAG_DEBUG;
3031 dc.icount = tb->flags & XTENSA_TBFLAG_ICOUNT;
3032 dc.cpenable = (tb->flags & XTENSA_TBFLAG_CPENABLE_MASK) >>
3033 XTENSA_TBFLAG_CPENABLE_SHIFT;
3034 dc.window = ((tb->flags & XTENSA_TBFLAG_WINDOW_MASK) >>
3035 XTENSA_TBFLAG_WINDOW_SHIFT);
3038 init_sar_tracker(&dc);
3040 dc.next_icount = tcg_temp_local_new_i32();
3045 if (tb->flags & XTENSA_TBFLAG_EXCEPTION) {
3046 tcg_gen_movi_i32(cpu_pc, dc.pc);
3047 gen_exception(&dc, EXCP_DEBUG);
3051 tcg_gen_insn_start(dc.pc);
3056 if (unlikely(cpu_breakpoint_test(cs, dc.pc, BP_ANY))) {
3057 tcg_gen_movi_i32(cpu_pc, dc.pc);
3058 gen_exception(&dc, EXCP_DEBUG);
3059 dc.is_jmp = DISAS_UPDATE;
3063 if (insn_count == max_insns && (tb->cflags & CF_LAST_IO)) {
3068 TCGLabel *label = gen_new_label();
3070 tcg_gen_addi_i32(dc.next_icount, cpu_SR[ICOUNT], 1);
3071 tcg_gen_brcondi_i32(TCG_COND_NE, dc.next_icount, 0, label);
3072 tcg_gen_mov_i32(dc.next_icount, cpu_SR[ICOUNT]);
3074 gen_debug_exception(&dc, DEBUGCAUSE_IC);
3076 gen_set_label(label);
3080 gen_ibreak_check(env, &dc);
3083 disas_xtensa_insn(env, &dc);
3085 tcg_gen_mov_i32(cpu_SR[ICOUNT], dc.next_icount);
3087 if (cs->singlestep_enabled) {
3088 tcg_gen_movi_i32(cpu_pc, dc.pc);
3089 gen_exception(&dc, EXCP_DEBUG);
3092 } while (dc.is_jmp == DISAS_NEXT &&
3093 insn_count < max_insns &&
3094 dc.pc < next_page_start &&
3095 dc.pc + xtensa_insn_len(env, &dc) <= next_page_start &&
3096 !tcg_op_buf_full());
3099 reset_sar_tracker(&dc);
3101 tcg_temp_free(dc.next_icount);
3104 if (tb->cflags & CF_LAST_IO) {
3108 if (dc.is_jmp == DISAS_NEXT) {
3109 gen_jumpi(&dc, dc.pc, 0);
3111 gen_tb_end(tb, insn_count);
3114 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
3115 qemu_log("----------------\n");
3116 qemu_log("IN: %s\n", lookup_symbol(pc_start));
3117 log_target_disas(cs, pc_start, dc.pc - pc_start, 0);
3121 tb->size = dc.pc - pc_start;
3122 tb->icount = insn_count;
3125 void xtensa_cpu_dump_state(CPUState *cs, FILE *f,
3126 fprintf_function cpu_fprintf, int flags)
3128 XtensaCPU *cpu = XTENSA_CPU(cs);
3129 CPUXtensaState *env = &cpu->env;
3132 cpu_fprintf(f, "PC=%08x\n\n", env->pc);
3134 for (i = j = 0; i < 256; ++i) {
3135 if (xtensa_option_bits_enabled(env->config, sregnames[i].opt_bits)) {
3136 cpu_fprintf(f, "%12s=%08x%c", sregnames[i].name, env->sregs[i],
3137 (j++ % 4) == 3 ? '\n' : ' ');
3141 cpu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n");
3143 for (i = j = 0; i < 256; ++i) {
3144 if (xtensa_option_bits_enabled(env->config, uregnames[i].opt_bits)) {
3145 cpu_fprintf(f, "%s=%08x%c", uregnames[i].name, env->uregs[i],
3146 (j++ % 4) == 3 ? '\n' : ' ');
3150 cpu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n");
3152 for (i = 0; i < 16; ++i) {
3153 cpu_fprintf(f, " A%02d=%08x%c", i, env->regs[i],
3154 (i % 4) == 3 ? '\n' : ' ');
3157 cpu_fprintf(f, "\n");
3159 for (i = 0; i < env->config->nareg; ++i) {
3160 cpu_fprintf(f, "AR%02d=%08x%c", i, env->phys_regs[i],
3161 (i % 4) == 3 ? '\n' : ' ');
3164 if (xtensa_option_enabled(env->config, XTENSA_OPTION_FP_COPROCESSOR)) {
3165 cpu_fprintf(f, "\n");
3167 for (i = 0; i < 16; ++i) {
3168 cpu_fprintf(f, "F%02d=%08x (%+10.8e)%c", i,
3169 float32_val(env->fregs[i].f32[FP_F32_LOW]),
3170 *(float *)(env->fregs[i].f32 + FP_F32_LOW),
3171 (i % 2) == 1 ? '\n' : ' ');
3176 void restore_state_to_opc(CPUXtensaState *env, TranslationBlock *tb,