target-microblaze: Drop unused cpu_mb_close() prototype
[qemu/opensuse.git] / target-xtensa / translate.c
blob7029ac481455d3de188bf591b06918552d4c21a2
1 /*
2 * Xtensa ISA:
3 * http://www.tensilica.com/products/literature-docs/documentation/xtensa-isa-databook.htm
5 * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab.
6 * All rights reserved.
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.
31 #include <stdio.h>
33 #include "cpu.h"
34 #include "exec/exec-all.h"
35 #include "disas/disas.h"
36 #include "tcg-op.h"
37 #include "qemu/log.h"
38 #include "sysemu/sysemu.h"
40 #include "helper.h"
41 #define GEN_HELPER 1
42 #include "helper.h"
44 typedef struct DisasContext {
45 const XtensaConfig *config;
46 TranslationBlock *tb;
47 uint32_t pc;
48 uint32_t next_pc;
49 int cring;
50 int ring;
51 uint32_t lbeg;
52 uint32_t lend;
53 TCGv_i32 litbase;
54 int is_jmp;
55 int singlestep_enabled;
57 bool sar_5bit;
58 bool sar_m32_5bit;
59 bool sar_m32_allocated;
60 TCGv_i32 sar_m32;
62 uint32_t ccount_delta;
63 unsigned used_window;
65 bool debug;
66 bool icount;
67 TCGv_i32 next_icount;
69 unsigned cpenable;
70 } DisasContext;
72 static TCGv_ptr cpu_env;
73 static TCGv_i32 cpu_pc;
74 static TCGv_i32 cpu_R[16];
75 static TCGv_i32 cpu_FR[16];
76 static TCGv_i32 cpu_SR[256];
77 static TCGv_i32 cpu_UR[256];
79 #include "exec/gen-icount.h"
81 typedef struct XtensaReg {
82 const char *name;
83 uint64_t opt_bits;
84 enum {
85 SR_R = 1,
86 SR_W = 2,
87 SR_X = 4,
88 SR_RW = 3,
89 SR_RWX = 7,
90 } access;
91 } XtensaReg;
93 #define XTENSA_REG_ACCESS(regname, opt, acc) { \
94 .name = (regname), \
95 .opt_bits = XTENSA_OPTION_BIT(opt), \
96 .access = (acc), \
99 #define XTENSA_REG(regname, opt) XTENSA_REG_ACCESS(regname, opt, SR_RWX)
101 #define XTENSA_REG_BITS(regname, opt) { \
102 .name = (regname), \
103 .opt_bits = (opt), \
104 .access = SR_RWX, \
107 static const XtensaReg sregnames[256] = {
108 [LBEG] = XTENSA_REG("LBEG", XTENSA_OPTION_LOOP),
109 [LEND] = XTENSA_REG("LEND", XTENSA_OPTION_LOOP),
110 [LCOUNT] = XTENSA_REG("LCOUNT", XTENSA_OPTION_LOOP),
111 [SAR] = XTENSA_REG_BITS("SAR", XTENSA_OPTION_ALL),
112 [BR] = XTENSA_REG("BR", XTENSA_OPTION_BOOLEAN),
113 [LITBASE] = XTENSA_REG("LITBASE", XTENSA_OPTION_EXTENDED_L32R),
114 [SCOMPARE1] = XTENSA_REG("SCOMPARE1", XTENSA_OPTION_CONDITIONAL_STORE),
115 [ACCLO] = XTENSA_REG("ACCLO", XTENSA_OPTION_MAC16),
116 [ACCHI] = XTENSA_REG("ACCHI", XTENSA_OPTION_MAC16),
117 [MR] = XTENSA_REG("MR0", XTENSA_OPTION_MAC16),
118 [MR + 1] = XTENSA_REG("MR1", XTENSA_OPTION_MAC16),
119 [MR + 2] = XTENSA_REG("MR2", XTENSA_OPTION_MAC16),
120 [MR + 3] = XTENSA_REG("MR3", XTENSA_OPTION_MAC16),
121 [WINDOW_BASE] = XTENSA_REG("WINDOW_BASE", XTENSA_OPTION_WINDOWED_REGISTER),
122 [WINDOW_START] = XTENSA_REG("WINDOW_START",
123 XTENSA_OPTION_WINDOWED_REGISTER),
124 [PTEVADDR] = XTENSA_REG("PTEVADDR", XTENSA_OPTION_MMU),
125 [RASID] = XTENSA_REG("RASID", XTENSA_OPTION_MMU),
126 [ITLBCFG] = XTENSA_REG("ITLBCFG", XTENSA_OPTION_MMU),
127 [DTLBCFG] = XTENSA_REG("DTLBCFG", XTENSA_OPTION_MMU),
128 [IBREAKENABLE] = XTENSA_REG("IBREAKENABLE", XTENSA_OPTION_DEBUG),
129 [CACHEATTR] = XTENSA_REG("CACHEATTR", XTENSA_OPTION_CACHEATTR),
130 [ATOMCTL] = XTENSA_REG("ATOMCTL", XTENSA_OPTION_ATOMCTL),
131 [IBREAKA] = XTENSA_REG("IBREAKA0", XTENSA_OPTION_DEBUG),
132 [IBREAKA + 1] = XTENSA_REG("IBREAKA1", XTENSA_OPTION_DEBUG),
133 [DBREAKA] = XTENSA_REG("DBREAKA0", XTENSA_OPTION_DEBUG),
134 [DBREAKA + 1] = XTENSA_REG("DBREAKA1", XTENSA_OPTION_DEBUG),
135 [DBREAKC] = XTENSA_REG("DBREAKC0", XTENSA_OPTION_DEBUG),
136 [DBREAKC + 1] = XTENSA_REG("DBREAKC1", XTENSA_OPTION_DEBUG),
137 [EPC1] = XTENSA_REG("EPC1", XTENSA_OPTION_EXCEPTION),
138 [EPC1 + 1] = XTENSA_REG("EPC2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
139 [EPC1 + 2] = XTENSA_REG("EPC3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
140 [EPC1 + 3] = XTENSA_REG("EPC4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
141 [EPC1 + 4] = XTENSA_REG("EPC5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
142 [EPC1 + 5] = XTENSA_REG("EPC6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
143 [EPC1 + 6] = XTENSA_REG("EPC7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
144 [DEPC] = XTENSA_REG("DEPC", XTENSA_OPTION_EXCEPTION),
145 [EPS2] = XTENSA_REG("EPS2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
146 [EPS2 + 1] = XTENSA_REG("EPS3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
147 [EPS2 + 2] = XTENSA_REG("EPS4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
148 [EPS2 + 3] = XTENSA_REG("EPS5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
149 [EPS2 + 4] = XTENSA_REG("EPS6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
150 [EPS2 + 5] = XTENSA_REG("EPS7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
151 [EXCSAVE1] = XTENSA_REG("EXCSAVE1", XTENSA_OPTION_EXCEPTION),
152 [EXCSAVE1 + 1] = XTENSA_REG("EXCSAVE2",
153 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
154 [EXCSAVE1 + 2] = XTENSA_REG("EXCSAVE3",
155 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
156 [EXCSAVE1 + 3] = XTENSA_REG("EXCSAVE4",
157 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
158 [EXCSAVE1 + 4] = XTENSA_REG("EXCSAVE5",
159 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
160 [EXCSAVE1 + 5] = XTENSA_REG("EXCSAVE6",
161 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
162 [EXCSAVE1 + 6] = XTENSA_REG("EXCSAVE7",
163 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT),
164 [CPENABLE] = XTENSA_REG("CPENABLE", XTENSA_OPTION_COPROCESSOR),
165 [INTSET] = XTENSA_REG_ACCESS("INTSET", XTENSA_OPTION_INTERRUPT, SR_RW),
166 [INTCLEAR] = XTENSA_REG_ACCESS("INTCLEAR", XTENSA_OPTION_INTERRUPT, SR_W),
167 [INTENABLE] = XTENSA_REG("INTENABLE", XTENSA_OPTION_INTERRUPT),
168 [PS] = XTENSA_REG_BITS("PS", XTENSA_OPTION_ALL),
169 [VECBASE] = XTENSA_REG("VECBASE", XTENSA_OPTION_RELOCATABLE_VECTOR),
170 [EXCCAUSE] = XTENSA_REG("EXCCAUSE", XTENSA_OPTION_EXCEPTION),
171 [DEBUGCAUSE] = XTENSA_REG_ACCESS("DEBUGCAUSE", XTENSA_OPTION_DEBUG, SR_R),
172 [CCOUNT] = XTENSA_REG("CCOUNT", XTENSA_OPTION_TIMER_INTERRUPT),
173 [PRID] = XTENSA_REG_ACCESS("PRID", XTENSA_OPTION_PROCESSOR_ID, SR_R),
174 [ICOUNT] = XTENSA_REG("ICOUNT", XTENSA_OPTION_DEBUG),
175 [ICOUNTLEVEL] = XTENSA_REG("ICOUNTLEVEL", XTENSA_OPTION_DEBUG),
176 [EXCVADDR] = XTENSA_REG("EXCVADDR", XTENSA_OPTION_EXCEPTION),
177 [CCOMPARE] = XTENSA_REG("CCOMPARE0", XTENSA_OPTION_TIMER_INTERRUPT),
178 [CCOMPARE + 1] = XTENSA_REG("CCOMPARE1",
179 XTENSA_OPTION_TIMER_INTERRUPT),
180 [CCOMPARE + 2] = XTENSA_REG("CCOMPARE2",
181 XTENSA_OPTION_TIMER_INTERRUPT),
182 [MISC] = XTENSA_REG("MISC0", XTENSA_OPTION_MISC_SR),
183 [MISC + 1] = XTENSA_REG("MISC1", XTENSA_OPTION_MISC_SR),
184 [MISC + 2] = XTENSA_REG("MISC2", XTENSA_OPTION_MISC_SR),
185 [MISC + 3] = XTENSA_REG("MISC3", XTENSA_OPTION_MISC_SR),
188 static const XtensaReg uregnames[256] = {
189 [THREADPTR] = XTENSA_REG("THREADPTR", XTENSA_OPTION_THREAD_POINTER),
190 [FCR] = XTENSA_REG("FCR", XTENSA_OPTION_FP_COPROCESSOR),
191 [FSR] = XTENSA_REG("FSR", XTENSA_OPTION_FP_COPROCESSOR),
194 void xtensa_translate_init(void)
196 static const char * const regnames[] = {
197 "ar0", "ar1", "ar2", "ar3",
198 "ar4", "ar5", "ar6", "ar7",
199 "ar8", "ar9", "ar10", "ar11",
200 "ar12", "ar13", "ar14", "ar15",
202 static const char * const fregnames[] = {
203 "f0", "f1", "f2", "f3",
204 "f4", "f5", "f6", "f7",
205 "f8", "f9", "f10", "f11",
206 "f12", "f13", "f14", "f15",
208 int i;
210 cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env");
211 cpu_pc = tcg_global_mem_new_i32(TCG_AREG0,
212 offsetof(CPUXtensaState, pc), "pc");
214 for (i = 0; i < 16; i++) {
215 cpu_R[i] = tcg_global_mem_new_i32(TCG_AREG0,
216 offsetof(CPUXtensaState, regs[i]),
217 regnames[i]);
220 for (i = 0; i < 16; i++) {
221 cpu_FR[i] = tcg_global_mem_new_i32(TCG_AREG0,
222 offsetof(CPUXtensaState, fregs[i]),
223 fregnames[i]);
226 for (i = 0; i < 256; ++i) {
227 if (sregnames[i].name) {
228 cpu_SR[i] = tcg_global_mem_new_i32(TCG_AREG0,
229 offsetof(CPUXtensaState, sregs[i]),
230 sregnames[i].name);
234 for (i = 0; i < 256; ++i) {
235 if (uregnames[i].name) {
236 cpu_UR[i] = tcg_global_mem_new_i32(TCG_AREG0,
237 offsetof(CPUXtensaState, uregs[i]),
238 uregnames[i].name);
241 #define GEN_HELPER 2
242 #include "helper.h"
245 static inline bool option_bits_enabled(DisasContext *dc, uint64_t opt)
247 return xtensa_option_bits_enabled(dc->config, opt);
250 static inline bool option_enabled(DisasContext *dc, int opt)
252 return xtensa_option_enabled(dc->config, opt);
255 static void init_litbase(DisasContext *dc)
257 if (dc->tb->flags & XTENSA_TBFLAG_LITBASE) {
258 dc->litbase = tcg_temp_local_new_i32();
259 tcg_gen_andi_i32(dc->litbase, cpu_SR[LITBASE], 0xfffff000);
263 static void reset_litbase(DisasContext *dc)
265 if (dc->tb->flags & XTENSA_TBFLAG_LITBASE) {
266 tcg_temp_free(dc->litbase);
270 static void init_sar_tracker(DisasContext *dc)
272 dc->sar_5bit = false;
273 dc->sar_m32_5bit = false;
274 dc->sar_m32_allocated = false;
277 static void reset_sar_tracker(DisasContext *dc)
279 if (dc->sar_m32_allocated) {
280 tcg_temp_free(dc->sar_m32);
284 static void gen_right_shift_sar(DisasContext *dc, TCGv_i32 sa)
286 tcg_gen_andi_i32(cpu_SR[SAR], sa, 0x1f);
287 if (dc->sar_m32_5bit) {
288 tcg_gen_discard_i32(dc->sar_m32);
290 dc->sar_5bit = true;
291 dc->sar_m32_5bit = false;
294 static void gen_left_shift_sar(DisasContext *dc, TCGv_i32 sa)
296 TCGv_i32 tmp = tcg_const_i32(32);
297 if (!dc->sar_m32_allocated) {
298 dc->sar_m32 = tcg_temp_local_new_i32();
299 dc->sar_m32_allocated = true;
301 tcg_gen_andi_i32(dc->sar_m32, sa, 0x1f);
302 tcg_gen_sub_i32(cpu_SR[SAR], tmp, dc->sar_m32);
303 dc->sar_5bit = false;
304 dc->sar_m32_5bit = true;
305 tcg_temp_free(tmp);
308 static void gen_advance_ccount(DisasContext *dc)
310 if (dc->ccount_delta > 0) {
311 TCGv_i32 tmp = tcg_const_i32(dc->ccount_delta);
312 dc->ccount_delta = 0;
313 gen_helper_advance_ccount(cpu_env, tmp);
314 tcg_temp_free(tmp);
318 static void reset_used_window(DisasContext *dc)
320 dc->used_window = 0;
323 static void gen_exception(DisasContext *dc, int excp)
325 TCGv_i32 tmp = tcg_const_i32(excp);
326 gen_advance_ccount(dc);
327 gen_helper_exception(cpu_env, tmp);
328 tcg_temp_free(tmp);
331 static void gen_exception_cause(DisasContext *dc, uint32_t cause)
333 TCGv_i32 tpc = tcg_const_i32(dc->pc);
334 TCGv_i32 tcause = tcg_const_i32(cause);
335 gen_advance_ccount(dc);
336 gen_helper_exception_cause(cpu_env, tpc, tcause);
337 tcg_temp_free(tpc);
338 tcg_temp_free(tcause);
339 if (cause == ILLEGAL_INSTRUCTION_CAUSE ||
340 cause == SYSCALL_CAUSE) {
341 dc->is_jmp = DISAS_UPDATE;
345 static void gen_exception_cause_vaddr(DisasContext *dc, uint32_t cause,
346 TCGv_i32 vaddr)
348 TCGv_i32 tpc = tcg_const_i32(dc->pc);
349 TCGv_i32 tcause = tcg_const_i32(cause);
350 gen_advance_ccount(dc);
351 gen_helper_exception_cause_vaddr(cpu_env, tpc, tcause, vaddr);
352 tcg_temp_free(tpc);
353 tcg_temp_free(tcause);
356 static void gen_debug_exception(DisasContext *dc, uint32_t cause)
358 TCGv_i32 tpc = tcg_const_i32(dc->pc);
359 TCGv_i32 tcause = tcg_const_i32(cause);
360 gen_advance_ccount(dc);
361 gen_helper_debug_exception(cpu_env, tpc, tcause);
362 tcg_temp_free(tpc);
363 tcg_temp_free(tcause);
364 if (cause & (DEBUGCAUSE_IB | DEBUGCAUSE_BI | DEBUGCAUSE_BN)) {
365 dc->is_jmp = DISAS_UPDATE;
369 static void gen_check_privilege(DisasContext *dc)
371 if (dc->cring) {
372 gen_exception_cause(dc, PRIVILEGED_CAUSE);
373 dc->is_jmp = DISAS_UPDATE;
377 static void gen_check_cpenable(DisasContext *dc, unsigned cp)
379 if (option_enabled(dc, XTENSA_OPTION_COPROCESSOR) &&
380 !(dc->cpenable & (1 << cp))) {
381 gen_exception_cause(dc, COPROCESSOR0_DISABLED + cp);
382 dc->is_jmp = DISAS_UPDATE;
386 static void gen_jump_slot(DisasContext *dc, TCGv dest, int slot)
388 tcg_gen_mov_i32(cpu_pc, dest);
389 gen_advance_ccount(dc);
390 if (dc->icount) {
391 tcg_gen_mov_i32(cpu_SR[ICOUNT], dc->next_icount);
393 if (dc->singlestep_enabled) {
394 gen_exception(dc, EXCP_DEBUG);
395 } else {
396 if (slot >= 0) {
397 tcg_gen_goto_tb(slot);
398 tcg_gen_exit_tb((tcg_target_long)dc->tb + slot);
399 } else {
400 tcg_gen_exit_tb(0);
403 dc->is_jmp = DISAS_UPDATE;
406 static void gen_jump(DisasContext *dc, TCGv dest)
408 gen_jump_slot(dc, dest, -1);
411 static void gen_jumpi(DisasContext *dc, uint32_t dest, int slot)
413 TCGv_i32 tmp = tcg_const_i32(dest);
414 if (((dc->pc ^ dest) & TARGET_PAGE_MASK) != 0) {
415 slot = -1;
417 gen_jump_slot(dc, tmp, slot);
418 tcg_temp_free(tmp);
421 static void gen_callw_slot(DisasContext *dc, int callinc, TCGv_i32 dest,
422 int slot)
424 TCGv_i32 tcallinc = tcg_const_i32(callinc);
426 tcg_gen_deposit_i32(cpu_SR[PS], cpu_SR[PS],
427 tcallinc, PS_CALLINC_SHIFT, PS_CALLINC_LEN);
428 tcg_temp_free(tcallinc);
429 tcg_gen_movi_i32(cpu_R[callinc << 2],
430 (callinc << 30) | (dc->next_pc & 0x3fffffff));
431 gen_jump_slot(dc, dest, slot);
434 static void gen_callw(DisasContext *dc, int callinc, TCGv_i32 dest)
436 gen_callw_slot(dc, callinc, dest, -1);
439 static void gen_callwi(DisasContext *dc, int callinc, uint32_t dest, int slot)
441 TCGv_i32 tmp = tcg_const_i32(dest);
442 if (((dc->pc ^ dest) & TARGET_PAGE_MASK) != 0) {
443 slot = -1;
445 gen_callw_slot(dc, callinc, tmp, slot);
446 tcg_temp_free(tmp);
449 static bool gen_check_loop_end(DisasContext *dc, int slot)
451 if (option_enabled(dc, XTENSA_OPTION_LOOP) &&
452 !(dc->tb->flags & XTENSA_TBFLAG_EXCM) &&
453 dc->next_pc == dc->lend) {
454 int label = gen_new_label();
456 gen_advance_ccount(dc);
457 tcg_gen_brcondi_i32(TCG_COND_EQ, cpu_SR[LCOUNT], 0, label);
458 tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_SR[LCOUNT], 1);
459 gen_jumpi(dc, dc->lbeg, slot);
460 gen_set_label(label);
461 gen_jumpi(dc, dc->next_pc, -1);
462 return true;
464 return false;
467 static void gen_jumpi_check_loop_end(DisasContext *dc, int slot)
469 if (!gen_check_loop_end(dc, slot)) {
470 gen_jumpi(dc, dc->next_pc, slot);
474 static void gen_brcond(DisasContext *dc, TCGCond cond,
475 TCGv_i32 t0, TCGv_i32 t1, uint32_t offset)
477 int label = gen_new_label();
479 gen_advance_ccount(dc);
480 tcg_gen_brcond_i32(cond, t0, t1, label);
481 gen_jumpi_check_loop_end(dc, 0);
482 gen_set_label(label);
483 gen_jumpi(dc, dc->pc + offset, 1);
486 static void gen_brcondi(DisasContext *dc, TCGCond cond,
487 TCGv_i32 t0, uint32_t t1, uint32_t offset)
489 TCGv_i32 tmp = tcg_const_i32(t1);
490 gen_brcond(dc, cond, t0, tmp, offset);
491 tcg_temp_free(tmp);
494 static void gen_check_sr(DisasContext *dc, uint32_t sr, unsigned access)
496 if (!xtensa_option_bits_enabled(dc->config, sregnames[sr].opt_bits)) {
497 if (sregnames[sr].name) {
498 qemu_log("SR %s is not configured\n", sregnames[sr].name);
499 } else {
500 qemu_log("SR %d is not implemented\n", sr);
502 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
503 } else if (!(sregnames[sr].access & access)) {
504 static const char * const access_text[] = {
505 [SR_R] = "rsr",
506 [SR_W] = "wsr",
507 [SR_X] = "xsr",
509 assert(access < ARRAY_SIZE(access_text) && access_text[access]);
510 qemu_log("SR %s is not available for %s\n", sregnames[sr].name,
511 access_text[access]);
512 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
516 static void gen_rsr_ccount(DisasContext *dc, TCGv_i32 d, uint32_t sr)
518 gen_advance_ccount(dc);
519 tcg_gen_mov_i32(d, cpu_SR[sr]);
522 static void gen_rsr_ptevaddr(DisasContext *dc, TCGv_i32 d, uint32_t sr)
524 tcg_gen_shri_i32(d, cpu_SR[EXCVADDR], 10);
525 tcg_gen_or_i32(d, d, cpu_SR[sr]);
526 tcg_gen_andi_i32(d, d, 0xfffffffc);
529 static void gen_rsr(DisasContext *dc, TCGv_i32 d, uint32_t sr)
531 static void (* const rsr_handler[256])(DisasContext *dc,
532 TCGv_i32 d, uint32_t sr) = {
533 [CCOUNT] = gen_rsr_ccount,
534 [PTEVADDR] = gen_rsr_ptevaddr,
537 if (rsr_handler[sr]) {
538 rsr_handler[sr](dc, d, sr);
539 } else {
540 tcg_gen_mov_i32(d, cpu_SR[sr]);
544 static void gen_wsr_lbeg(DisasContext *dc, uint32_t sr, TCGv_i32 s)
546 gen_helper_wsr_lbeg(cpu_env, s);
547 gen_jumpi_check_loop_end(dc, 0);
550 static void gen_wsr_lend(DisasContext *dc, uint32_t sr, TCGv_i32 s)
552 gen_helper_wsr_lend(cpu_env, s);
553 gen_jumpi_check_loop_end(dc, 0);
556 static void gen_wsr_sar(DisasContext *dc, uint32_t sr, TCGv_i32 s)
558 tcg_gen_andi_i32(cpu_SR[sr], s, 0x3f);
559 if (dc->sar_m32_5bit) {
560 tcg_gen_discard_i32(dc->sar_m32);
562 dc->sar_5bit = false;
563 dc->sar_m32_5bit = false;
566 static void gen_wsr_br(DisasContext *dc, uint32_t sr, TCGv_i32 s)
568 tcg_gen_andi_i32(cpu_SR[sr], s, 0xffff);
571 static void gen_wsr_litbase(DisasContext *dc, uint32_t sr, TCGv_i32 s)
573 tcg_gen_andi_i32(cpu_SR[sr], s, 0xfffff001);
574 /* This can change tb->flags, so exit tb */
575 gen_jumpi_check_loop_end(dc, -1);
578 static void gen_wsr_acchi(DisasContext *dc, uint32_t sr, TCGv_i32 s)
580 tcg_gen_ext8s_i32(cpu_SR[sr], s);
583 static void gen_wsr_windowbase(DisasContext *dc, uint32_t sr, TCGv_i32 v)
585 gen_helper_wsr_windowbase(cpu_env, v);
586 reset_used_window(dc);
589 static void gen_wsr_windowstart(DisasContext *dc, uint32_t sr, TCGv_i32 v)
591 tcg_gen_andi_i32(cpu_SR[sr], v, (1 << dc->config->nareg / 4) - 1);
592 reset_used_window(dc);
595 static void gen_wsr_ptevaddr(DisasContext *dc, uint32_t sr, TCGv_i32 v)
597 tcg_gen_andi_i32(cpu_SR[sr], v, 0xffc00000);
600 static void gen_wsr_rasid(DisasContext *dc, uint32_t sr, TCGv_i32 v)
602 gen_helper_wsr_rasid(cpu_env, v);
603 /* This can change tb->flags, so exit tb */
604 gen_jumpi_check_loop_end(dc, -1);
607 static void gen_wsr_tlbcfg(DisasContext *dc, uint32_t sr, TCGv_i32 v)
609 tcg_gen_andi_i32(cpu_SR[sr], v, 0x01130000);
612 static void gen_wsr_ibreakenable(DisasContext *dc, uint32_t sr, TCGv_i32 v)
614 gen_helper_wsr_ibreakenable(cpu_env, v);
615 gen_jumpi_check_loop_end(dc, 0);
618 static void gen_wsr_atomctl(DisasContext *dc, uint32_t sr, TCGv_i32 v)
620 tcg_gen_andi_i32(cpu_SR[sr], v, 0x3f);
623 static void gen_wsr_ibreaka(DisasContext *dc, uint32_t sr, TCGv_i32 v)
625 unsigned id = sr - IBREAKA;
627 if (id < dc->config->nibreak) {
628 TCGv_i32 tmp = tcg_const_i32(id);
629 gen_helper_wsr_ibreaka(cpu_env, tmp, v);
630 tcg_temp_free(tmp);
631 gen_jumpi_check_loop_end(dc, 0);
635 static void gen_wsr_dbreaka(DisasContext *dc, uint32_t sr, TCGv_i32 v)
637 unsigned id = sr - DBREAKA;
639 if (id < dc->config->ndbreak) {
640 TCGv_i32 tmp = tcg_const_i32(id);
641 gen_helper_wsr_dbreaka(cpu_env, tmp, v);
642 tcg_temp_free(tmp);
646 static void gen_wsr_dbreakc(DisasContext *dc, uint32_t sr, TCGv_i32 v)
648 unsigned id = sr - DBREAKC;
650 if (id < dc->config->ndbreak) {
651 TCGv_i32 tmp = tcg_const_i32(id);
652 gen_helper_wsr_dbreakc(cpu_env, tmp, v);
653 tcg_temp_free(tmp);
657 static void gen_wsr_cpenable(DisasContext *dc, uint32_t sr, TCGv_i32 v)
659 tcg_gen_andi_i32(cpu_SR[sr], v, 0xff);
660 /* This can change tb->flags, so exit tb */
661 gen_jumpi_check_loop_end(dc, -1);
664 static void gen_wsr_intset(DisasContext *dc, uint32_t sr, TCGv_i32 v)
666 tcg_gen_andi_i32(cpu_SR[sr], v,
667 dc->config->inttype_mask[INTTYPE_SOFTWARE]);
668 gen_helper_check_interrupts(cpu_env);
669 gen_jumpi_check_loop_end(dc, 0);
672 static void gen_wsr_intclear(DisasContext *dc, uint32_t sr, TCGv_i32 v)
674 TCGv_i32 tmp = tcg_temp_new_i32();
676 tcg_gen_andi_i32(tmp, v,
677 dc->config->inttype_mask[INTTYPE_EDGE] |
678 dc->config->inttype_mask[INTTYPE_NMI] |
679 dc->config->inttype_mask[INTTYPE_SOFTWARE]);
680 tcg_gen_andc_i32(cpu_SR[INTSET], cpu_SR[INTSET], tmp);
681 tcg_temp_free(tmp);
682 gen_helper_check_interrupts(cpu_env);
685 static void gen_wsr_intenable(DisasContext *dc, uint32_t sr, TCGv_i32 v)
687 tcg_gen_mov_i32(cpu_SR[sr], v);
688 gen_helper_check_interrupts(cpu_env);
689 gen_jumpi_check_loop_end(dc, 0);
692 static void gen_wsr_ps(DisasContext *dc, uint32_t sr, TCGv_i32 v)
694 uint32_t mask = PS_WOE | PS_CALLINC | PS_OWB |
695 PS_UM | PS_EXCM | PS_INTLEVEL;
697 if (option_enabled(dc, XTENSA_OPTION_MMU)) {
698 mask |= PS_RING;
700 tcg_gen_andi_i32(cpu_SR[sr], v, mask);
701 reset_used_window(dc);
702 gen_helper_check_interrupts(cpu_env);
703 /* This can change mmu index and tb->flags, so exit tb */
704 gen_jumpi_check_loop_end(dc, -1);
707 static void gen_wsr_icount(DisasContext *dc, uint32_t sr, TCGv_i32 v)
709 if (dc->icount) {
710 tcg_gen_mov_i32(dc->next_icount, v);
711 } else {
712 tcg_gen_mov_i32(cpu_SR[sr], v);
716 static void gen_wsr_icountlevel(DisasContext *dc, uint32_t sr, TCGv_i32 v)
718 tcg_gen_andi_i32(cpu_SR[sr], v, 0xf);
719 /* This can change tb->flags, so exit tb */
720 gen_jumpi_check_loop_end(dc, -1);
723 static void gen_wsr_ccompare(DisasContext *dc, uint32_t sr, TCGv_i32 v)
725 uint32_t id = sr - CCOMPARE;
726 if (id < dc->config->nccompare) {
727 uint32_t int_bit = 1 << dc->config->timerint[id];
728 gen_advance_ccount(dc);
729 tcg_gen_mov_i32(cpu_SR[sr], v);
730 tcg_gen_andi_i32(cpu_SR[INTSET], cpu_SR[INTSET], ~int_bit);
731 gen_helper_check_interrupts(cpu_env);
735 static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s)
737 static void (* const wsr_handler[256])(DisasContext *dc,
738 uint32_t sr, TCGv_i32 v) = {
739 [LBEG] = gen_wsr_lbeg,
740 [LEND] = gen_wsr_lend,
741 [SAR] = gen_wsr_sar,
742 [BR] = gen_wsr_br,
743 [LITBASE] = gen_wsr_litbase,
744 [ACCHI] = gen_wsr_acchi,
745 [WINDOW_BASE] = gen_wsr_windowbase,
746 [WINDOW_START] = gen_wsr_windowstart,
747 [PTEVADDR] = gen_wsr_ptevaddr,
748 [RASID] = gen_wsr_rasid,
749 [ITLBCFG] = gen_wsr_tlbcfg,
750 [DTLBCFG] = gen_wsr_tlbcfg,
751 [IBREAKENABLE] = gen_wsr_ibreakenable,
752 [ATOMCTL] = gen_wsr_atomctl,
753 [IBREAKA] = gen_wsr_ibreaka,
754 [IBREAKA + 1] = gen_wsr_ibreaka,
755 [DBREAKA] = gen_wsr_dbreaka,
756 [DBREAKA + 1] = gen_wsr_dbreaka,
757 [DBREAKC] = gen_wsr_dbreakc,
758 [DBREAKC + 1] = gen_wsr_dbreakc,
759 [CPENABLE] = gen_wsr_cpenable,
760 [INTSET] = gen_wsr_intset,
761 [INTCLEAR] = gen_wsr_intclear,
762 [INTENABLE] = gen_wsr_intenable,
763 [PS] = gen_wsr_ps,
764 [ICOUNT] = gen_wsr_icount,
765 [ICOUNTLEVEL] = gen_wsr_icountlevel,
766 [CCOMPARE] = gen_wsr_ccompare,
767 [CCOMPARE + 1] = gen_wsr_ccompare,
768 [CCOMPARE + 2] = gen_wsr_ccompare,
771 if (wsr_handler[sr]) {
772 wsr_handler[sr](dc, sr, s);
773 } else {
774 tcg_gen_mov_i32(cpu_SR[sr], s);
778 static void gen_wur(uint32_t ur, TCGv_i32 s)
780 switch (ur) {
781 case FCR:
782 gen_helper_wur_fcr(cpu_env, s);
783 break;
785 case FSR:
786 tcg_gen_andi_i32(cpu_UR[ur], s, 0xffffff80);
787 break;
789 default:
790 tcg_gen_mov_i32(cpu_UR[ur], s);
791 break;
795 static void gen_load_store_alignment(DisasContext *dc, int shift,
796 TCGv_i32 addr, bool no_hw_alignment)
798 if (!option_enabled(dc, XTENSA_OPTION_UNALIGNED_EXCEPTION)) {
799 tcg_gen_andi_i32(addr, addr, ~0 << shift);
800 } else if (option_enabled(dc, XTENSA_OPTION_HW_ALIGNMENT) &&
801 no_hw_alignment) {
802 int label = gen_new_label();
803 TCGv_i32 tmp = tcg_temp_new_i32();
804 tcg_gen_andi_i32(tmp, addr, ~(~0 << shift));
805 tcg_gen_brcondi_i32(TCG_COND_EQ, tmp, 0, label);
806 gen_exception_cause_vaddr(dc, LOAD_STORE_ALIGNMENT_CAUSE, addr);
807 gen_set_label(label);
808 tcg_temp_free(tmp);
812 static void gen_waiti(DisasContext *dc, uint32_t imm4)
814 TCGv_i32 pc = tcg_const_i32(dc->next_pc);
815 TCGv_i32 intlevel = tcg_const_i32(imm4);
816 gen_advance_ccount(dc);
817 gen_helper_waiti(cpu_env, pc, intlevel);
818 tcg_temp_free(pc);
819 tcg_temp_free(intlevel);
822 static void gen_window_check1(DisasContext *dc, unsigned r1)
824 if (dc->tb->flags & XTENSA_TBFLAG_EXCM) {
825 return;
827 if (option_enabled(dc, XTENSA_OPTION_WINDOWED_REGISTER) &&
828 r1 / 4 > dc->used_window) {
829 TCGv_i32 pc = tcg_const_i32(dc->pc);
830 TCGv_i32 w = tcg_const_i32(r1 / 4);
832 dc->used_window = r1 / 4;
833 gen_advance_ccount(dc);
834 gen_helper_window_check(cpu_env, pc, w);
836 tcg_temp_free(w);
837 tcg_temp_free(pc);
841 static void gen_window_check2(DisasContext *dc, unsigned r1, unsigned r2)
843 gen_window_check1(dc, r1 > r2 ? r1 : r2);
846 static void gen_window_check3(DisasContext *dc, unsigned r1, unsigned r2,
847 unsigned r3)
849 gen_window_check2(dc, r1, r2 > r3 ? r2 : r3);
852 static TCGv_i32 gen_mac16_m(TCGv_i32 v, bool hi, bool is_unsigned)
854 TCGv_i32 m = tcg_temp_new_i32();
856 if (hi) {
857 (is_unsigned ? tcg_gen_shri_i32 : tcg_gen_sari_i32)(m, v, 16);
858 } else {
859 (is_unsigned ? tcg_gen_ext16u_i32 : tcg_gen_ext16s_i32)(m, v);
861 return m;
864 static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)
866 #define HAS_OPTION_BITS(opt) do { \
867 if (!option_bits_enabled(dc, opt)) { \
868 qemu_log("Option is not enabled %s:%d\n", \
869 __FILE__, __LINE__); \
870 goto invalid_opcode; \
872 } while (0)
874 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
876 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
877 #define RESERVED() do { \
878 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
879 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
880 goto invalid_opcode; \
881 } while (0)
884 #ifdef TARGET_WORDS_BIGENDIAN
885 #define OP0 (((b0) & 0xf0) >> 4)
886 #define OP1 (((b2) & 0xf0) >> 4)
887 #define OP2 ((b2) & 0xf)
888 #define RRR_R ((b1) & 0xf)
889 #define RRR_S (((b1) & 0xf0) >> 4)
890 #define RRR_T ((b0) & 0xf)
891 #else
892 #define OP0 (((b0) & 0xf))
893 #define OP1 (((b2) & 0xf))
894 #define OP2 (((b2) & 0xf0) >> 4)
895 #define RRR_R (((b1) & 0xf0) >> 4)
896 #define RRR_S (((b1) & 0xf))
897 #define RRR_T (((b0) & 0xf0) >> 4)
898 #endif
899 #define RRR_X ((RRR_R & 0x4) >> 2)
900 #define RRR_Y ((RRR_T & 0x4) >> 2)
901 #define RRR_W (RRR_R & 0x3)
903 #define RRRN_R RRR_R
904 #define RRRN_S RRR_S
905 #define RRRN_T RRR_T
907 #define RRI8_R RRR_R
908 #define RRI8_S RRR_S
909 #define RRI8_T RRR_T
910 #define RRI8_IMM8 (b2)
911 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
913 #ifdef TARGET_WORDS_BIGENDIAN
914 #define RI16_IMM16 (((b1) << 8) | (b2))
915 #else
916 #define RI16_IMM16 (((b2) << 8) | (b1))
917 #endif
919 #ifdef TARGET_WORDS_BIGENDIAN
920 #define CALL_N (((b0) & 0xc) >> 2)
921 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
922 #else
923 #define CALL_N (((b0) & 0x30) >> 4)
924 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
925 #endif
926 #define CALL_OFFSET_SE \
927 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
929 #define CALLX_N CALL_N
930 #ifdef TARGET_WORDS_BIGENDIAN
931 #define CALLX_M ((b0) & 0x3)
932 #else
933 #define CALLX_M (((b0) & 0xc0) >> 6)
934 #endif
935 #define CALLX_S RRR_S
937 #define BRI12_M CALLX_M
938 #define BRI12_S RRR_S
939 #ifdef TARGET_WORDS_BIGENDIAN
940 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
941 #else
942 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
943 #endif
944 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
946 #define BRI8_M BRI12_M
947 #define BRI8_R RRI8_R
948 #define BRI8_S RRI8_S
949 #define BRI8_IMM8 RRI8_IMM8
950 #define BRI8_IMM8_SE RRI8_IMM8_SE
952 #define RSR_SR (b1)
954 uint8_t b0 = cpu_ldub_code(env, dc->pc);
955 uint8_t b1 = cpu_ldub_code(env, dc->pc + 1);
956 uint8_t b2 = 0;
958 static const uint32_t B4CONST[] = {
959 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
962 static const uint32_t B4CONSTU[] = {
963 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
966 if (OP0 >= 8) {
967 dc->next_pc = dc->pc + 2;
968 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY);
969 } else {
970 dc->next_pc = dc->pc + 3;
971 b2 = cpu_ldub_code(env, dc->pc + 2);
974 switch (OP0) {
975 case 0: /*QRST*/
976 switch (OP1) {
977 case 0: /*RST0*/
978 switch (OP2) {
979 case 0: /*ST0*/
980 if ((RRR_R & 0xc) == 0x8) {
981 HAS_OPTION(XTENSA_OPTION_BOOLEAN);
984 switch (RRR_R) {
985 case 0: /*SNM0*/
986 switch (CALLX_M) {
987 case 0: /*ILL*/
988 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
989 break;
991 case 1: /*reserved*/
992 RESERVED();
993 break;
995 case 2: /*JR*/
996 switch (CALLX_N) {
997 case 0: /*RET*/
998 case 2: /*JX*/
999 gen_window_check1(dc, CALLX_S);
1000 gen_jump(dc, cpu_R[CALLX_S]);
1001 break;
1003 case 1: /*RETWw*/
1004 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1006 TCGv_i32 tmp = tcg_const_i32(dc->pc);
1007 gen_advance_ccount(dc);
1008 gen_helper_retw(tmp, cpu_env, tmp);
1009 gen_jump(dc, tmp);
1010 tcg_temp_free(tmp);
1012 break;
1014 case 3: /*reserved*/
1015 RESERVED();
1016 break;
1018 break;
1020 case 3: /*CALLX*/
1021 gen_window_check2(dc, CALLX_S, CALLX_N << 2);
1022 switch (CALLX_N) {
1023 case 0: /*CALLX0*/
1025 TCGv_i32 tmp = tcg_temp_new_i32();
1026 tcg_gen_mov_i32(tmp, cpu_R[CALLX_S]);
1027 tcg_gen_movi_i32(cpu_R[0], dc->next_pc);
1028 gen_jump(dc, tmp);
1029 tcg_temp_free(tmp);
1031 break;
1033 case 1: /*CALLX4w*/
1034 case 2: /*CALLX8w*/
1035 case 3: /*CALLX12w*/
1036 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1038 TCGv_i32 tmp = tcg_temp_new_i32();
1040 tcg_gen_mov_i32(tmp, cpu_R[CALLX_S]);
1041 gen_callw(dc, CALLX_N, tmp);
1042 tcg_temp_free(tmp);
1044 break;
1046 break;
1048 break;
1050 case 1: /*MOVSPw*/
1051 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1052 gen_window_check2(dc, RRR_T, RRR_S);
1054 TCGv_i32 pc = tcg_const_i32(dc->pc);
1055 gen_advance_ccount(dc);
1056 gen_helper_movsp(cpu_env, pc);
1057 tcg_gen_mov_i32(cpu_R[RRR_T], cpu_R[RRR_S]);
1058 tcg_temp_free(pc);
1060 break;
1062 case 2: /*SYNC*/
1063 switch (RRR_T) {
1064 case 0: /*ISYNC*/
1065 break;
1067 case 1: /*RSYNC*/
1068 break;
1070 case 2: /*ESYNC*/
1071 break;
1073 case 3: /*DSYNC*/
1074 break;
1076 case 8: /*EXCW*/
1077 HAS_OPTION(XTENSA_OPTION_EXCEPTION);
1078 break;
1080 case 12: /*MEMW*/
1081 break;
1083 case 13: /*EXTW*/
1084 break;
1086 case 15: /*NOP*/
1087 break;
1089 default: /*reserved*/
1090 RESERVED();
1091 break;
1093 break;
1095 case 3: /*RFEIx*/
1096 switch (RRR_T) {
1097 case 0: /*RFETx*/
1098 HAS_OPTION(XTENSA_OPTION_EXCEPTION);
1099 switch (RRR_S) {
1100 case 0: /*RFEx*/
1101 gen_check_privilege(dc);
1102 tcg_gen_andi_i32(cpu_SR[PS], cpu_SR[PS], ~PS_EXCM);
1103 gen_helper_check_interrupts(cpu_env);
1104 gen_jump(dc, cpu_SR[EPC1]);
1105 break;
1107 case 1: /*RFUEx*/
1108 RESERVED();
1109 break;
1111 case 2: /*RFDEx*/
1112 gen_check_privilege(dc);
1113 gen_jump(dc, cpu_SR[
1114 dc->config->ndepc ? DEPC : EPC1]);
1115 break;
1117 case 4: /*RFWOw*/
1118 case 5: /*RFWUw*/
1119 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1120 gen_check_privilege(dc);
1122 TCGv_i32 tmp = tcg_const_i32(1);
1124 tcg_gen_andi_i32(
1125 cpu_SR[PS], cpu_SR[PS], ~PS_EXCM);
1126 tcg_gen_shl_i32(tmp, tmp, cpu_SR[WINDOW_BASE]);
1128 if (RRR_S == 4) {
1129 tcg_gen_andc_i32(cpu_SR[WINDOW_START],
1130 cpu_SR[WINDOW_START], tmp);
1131 } else {
1132 tcg_gen_or_i32(cpu_SR[WINDOW_START],
1133 cpu_SR[WINDOW_START], tmp);
1136 gen_helper_restore_owb(cpu_env);
1137 gen_helper_check_interrupts(cpu_env);
1138 gen_jump(dc, cpu_SR[EPC1]);
1140 tcg_temp_free(tmp);
1142 break;
1144 default: /*reserved*/
1145 RESERVED();
1146 break;
1148 break;
1150 case 1: /*RFIx*/
1151 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT);
1152 if (RRR_S >= 2 && RRR_S <= dc->config->nlevel) {
1153 gen_check_privilege(dc);
1154 tcg_gen_mov_i32(cpu_SR[PS],
1155 cpu_SR[EPS2 + RRR_S - 2]);
1156 gen_helper_check_interrupts(cpu_env);
1157 gen_jump(dc, cpu_SR[EPC1 + RRR_S - 1]);
1158 } else {
1159 qemu_log("RFI %d is illegal\n", RRR_S);
1160 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
1162 break;
1164 case 2: /*RFME*/
1165 TBD();
1166 break;
1168 default: /*reserved*/
1169 RESERVED();
1170 break;
1173 break;
1175 case 4: /*BREAKx*/
1176 HAS_OPTION(XTENSA_OPTION_DEBUG);
1177 if (dc->debug) {
1178 gen_debug_exception(dc, DEBUGCAUSE_BI);
1180 break;
1182 case 5: /*SYSCALLx*/
1183 HAS_OPTION(XTENSA_OPTION_EXCEPTION);
1184 switch (RRR_S) {
1185 case 0: /*SYSCALLx*/
1186 gen_exception_cause(dc, SYSCALL_CAUSE);
1187 break;
1189 case 1: /*SIMCALL*/
1190 if (semihosting_enabled) {
1191 gen_check_privilege(dc);
1192 gen_helper_simcall(cpu_env);
1193 } else {
1194 qemu_log("SIMCALL but semihosting is disabled\n");
1195 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
1197 break;
1199 default:
1200 RESERVED();
1201 break;
1203 break;
1205 case 6: /*RSILx*/
1206 HAS_OPTION(XTENSA_OPTION_INTERRUPT);
1207 gen_check_privilege(dc);
1208 gen_window_check1(dc, RRR_T);
1209 tcg_gen_mov_i32(cpu_R[RRR_T], cpu_SR[PS]);
1210 tcg_gen_andi_i32(cpu_SR[PS], cpu_SR[PS], ~PS_INTLEVEL);
1211 tcg_gen_ori_i32(cpu_SR[PS], cpu_SR[PS], RRR_S);
1212 gen_helper_check_interrupts(cpu_env);
1213 gen_jumpi_check_loop_end(dc, 0);
1214 break;
1216 case 7: /*WAITIx*/
1217 HAS_OPTION(XTENSA_OPTION_INTERRUPT);
1218 gen_check_privilege(dc);
1219 gen_waiti(dc, RRR_S);
1220 break;
1222 case 8: /*ANY4p*/
1223 case 9: /*ALL4p*/
1224 case 10: /*ANY8p*/
1225 case 11: /*ALL8p*/
1226 HAS_OPTION(XTENSA_OPTION_BOOLEAN);
1228 const unsigned shift = (RRR_R & 2) ? 8 : 4;
1229 TCGv_i32 mask = tcg_const_i32(
1230 ((1 << shift) - 1) << RRR_S);
1231 TCGv_i32 tmp = tcg_temp_new_i32();
1233 tcg_gen_and_i32(tmp, cpu_SR[BR], mask);
1234 if (RRR_R & 1) { /*ALL*/
1235 tcg_gen_addi_i32(tmp, tmp, 1 << RRR_S);
1236 } else { /*ANY*/
1237 tcg_gen_add_i32(tmp, tmp, mask);
1239 tcg_gen_shri_i32(tmp, tmp, RRR_S + shift);
1240 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR],
1241 tmp, RRR_T, 1);
1242 tcg_temp_free(mask);
1243 tcg_temp_free(tmp);
1245 break;
1247 default: /*reserved*/
1248 RESERVED();
1249 break;
1252 break;
1254 case 1: /*AND*/
1255 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1256 tcg_gen_and_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1257 break;
1259 case 2: /*OR*/
1260 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1261 tcg_gen_or_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1262 break;
1264 case 3: /*XOR*/
1265 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1266 tcg_gen_xor_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1267 break;
1269 case 4: /*ST1*/
1270 switch (RRR_R) {
1271 case 0: /*SSR*/
1272 gen_window_check1(dc, RRR_S);
1273 gen_right_shift_sar(dc, cpu_R[RRR_S]);
1274 break;
1276 case 1: /*SSL*/
1277 gen_window_check1(dc, RRR_S);
1278 gen_left_shift_sar(dc, cpu_R[RRR_S]);
1279 break;
1281 case 2: /*SSA8L*/
1282 gen_window_check1(dc, RRR_S);
1284 TCGv_i32 tmp = tcg_temp_new_i32();
1285 tcg_gen_shli_i32(tmp, cpu_R[RRR_S], 3);
1286 gen_right_shift_sar(dc, tmp);
1287 tcg_temp_free(tmp);
1289 break;
1291 case 3: /*SSA8B*/
1292 gen_window_check1(dc, RRR_S);
1294 TCGv_i32 tmp = tcg_temp_new_i32();
1295 tcg_gen_shli_i32(tmp, cpu_R[RRR_S], 3);
1296 gen_left_shift_sar(dc, tmp);
1297 tcg_temp_free(tmp);
1299 break;
1301 case 4: /*SSAI*/
1303 TCGv_i32 tmp = tcg_const_i32(
1304 RRR_S | ((RRR_T & 1) << 4));
1305 gen_right_shift_sar(dc, tmp);
1306 tcg_temp_free(tmp);
1308 break;
1310 case 6: /*RER*/
1311 TBD();
1312 break;
1314 case 7: /*WER*/
1315 TBD();
1316 break;
1318 case 8: /*ROTWw*/
1319 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1320 gen_check_privilege(dc);
1322 TCGv_i32 tmp = tcg_const_i32(
1323 RRR_T | ((RRR_T & 8) ? 0xfffffff0 : 0));
1324 gen_helper_rotw(cpu_env, tmp);
1325 tcg_temp_free(tmp);
1326 reset_used_window(dc);
1328 break;
1330 case 14: /*NSAu*/
1331 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA);
1332 gen_window_check2(dc, RRR_S, RRR_T);
1333 gen_helper_nsa(cpu_R[RRR_T], cpu_R[RRR_S]);
1334 break;
1336 case 15: /*NSAUu*/
1337 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA);
1338 gen_window_check2(dc, RRR_S, RRR_T);
1339 gen_helper_nsau(cpu_R[RRR_T], cpu_R[RRR_S]);
1340 break;
1342 default: /*reserved*/
1343 RESERVED();
1344 break;
1346 break;
1348 case 5: /*TLB*/
1349 HAS_OPTION_BITS(
1350 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU) |
1351 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION) |
1352 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION));
1353 gen_check_privilege(dc);
1354 gen_window_check2(dc, RRR_S, RRR_T);
1356 TCGv_i32 dtlb = tcg_const_i32((RRR_R & 8) != 0);
1358 switch (RRR_R & 7) {
1359 case 3: /*RITLB0*/ /*RDTLB0*/
1360 gen_helper_rtlb0(cpu_R[RRR_T],
1361 cpu_env, cpu_R[RRR_S], dtlb);
1362 break;
1364 case 4: /*IITLB*/ /*IDTLB*/
1365 gen_helper_itlb(cpu_env, cpu_R[RRR_S], dtlb);
1366 /* This could change memory mapping, so exit tb */
1367 gen_jumpi_check_loop_end(dc, -1);
1368 break;
1370 case 5: /*PITLB*/ /*PDTLB*/
1371 tcg_gen_movi_i32(cpu_pc, dc->pc);
1372 gen_helper_ptlb(cpu_R[RRR_T],
1373 cpu_env, cpu_R[RRR_S], dtlb);
1374 break;
1376 case 6: /*WITLB*/ /*WDTLB*/
1377 gen_helper_wtlb(
1378 cpu_env, cpu_R[RRR_T], cpu_R[RRR_S], dtlb);
1379 /* This could change memory mapping, so exit tb */
1380 gen_jumpi_check_loop_end(dc, -1);
1381 break;
1383 case 7: /*RITLB1*/ /*RDTLB1*/
1384 gen_helper_rtlb1(cpu_R[RRR_T],
1385 cpu_env, cpu_R[RRR_S], dtlb);
1386 break;
1388 default:
1389 tcg_temp_free(dtlb);
1390 RESERVED();
1391 break;
1393 tcg_temp_free(dtlb);
1395 break;
1397 case 6: /*RT0*/
1398 gen_window_check2(dc, RRR_R, RRR_T);
1399 switch (RRR_S) {
1400 case 0: /*NEG*/
1401 tcg_gen_neg_i32(cpu_R[RRR_R], cpu_R[RRR_T]);
1402 break;
1404 case 1: /*ABS*/
1406 TCGv_i32 zero = tcg_const_i32(0);
1407 TCGv_i32 neg = tcg_temp_new_i32();
1409 tcg_gen_neg_i32(neg, cpu_R[RRR_T]);
1410 tcg_gen_movcond_i32(TCG_COND_GE, cpu_R[RRR_R],
1411 cpu_R[RRR_T], zero, cpu_R[RRR_T], neg);
1412 tcg_temp_free(neg);
1413 tcg_temp_free(zero);
1415 break;
1417 default: /*reserved*/
1418 RESERVED();
1419 break;
1421 break;
1423 case 7: /*reserved*/
1424 RESERVED();
1425 break;
1427 case 8: /*ADD*/
1428 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1429 tcg_gen_add_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1430 break;
1432 case 9: /*ADD**/
1433 case 10:
1434 case 11:
1435 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1437 TCGv_i32 tmp = tcg_temp_new_i32();
1438 tcg_gen_shli_i32(tmp, cpu_R[RRR_S], OP2 - 8);
1439 tcg_gen_add_i32(cpu_R[RRR_R], tmp, cpu_R[RRR_T]);
1440 tcg_temp_free(tmp);
1442 break;
1444 case 12: /*SUB*/
1445 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1446 tcg_gen_sub_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1447 break;
1449 case 13: /*SUB**/
1450 case 14:
1451 case 15:
1452 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1454 TCGv_i32 tmp = tcg_temp_new_i32();
1455 tcg_gen_shli_i32(tmp, cpu_R[RRR_S], OP2 - 12);
1456 tcg_gen_sub_i32(cpu_R[RRR_R], tmp, cpu_R[RRR_T]);
1457 tcg_temp_free(tmp);
1459 break;
1461 break;
1463 case 1: /*RST1*/
1464 switch (OP2) {
1465 case 0: /*SLLI*/
1466 case 1:
1467 gen_window_check2(dc, RRR_R, RRR_S);
1468 tcg_gen_shli_i32(cpu_R[RRR_R], cpu_R[RRR_S],
1469 32 - (RRR_T | ((OP2 & 1) << 4)));
1470 break;
1472 case 2: /*SRAI*/
1473 case 3:
1474 gen_window_check2(dc, RRR_R, RRR_T);
1475 tcg_gen_sari_i32(cpu_R[RRR_R], cpu_R[RRR_T],
1476 RRR_S | ((OP2 & 1) << 4));
1477 break;
1479 case 4: /*SRLI*/
1480 gen_window_check2(dc, RRR_R, RRR_T);
1481 tcg_gen_shri_i32(cpu_R[RRR_R], cpu_R[RRR_T], RRR_S);
1482 break;
1484 case 6: /*XSR*/
1486 TCGv_i32 tmp = tcg_temp_new_i32();
1487 gen_check_sr(dc, RSR_SR, SR_X);
1488 if (RSR_SR >= 64) {
1489 gen_check_privilege(dc);
1491 gen_window_check1(dc, RRR_T);
1492 tcg_gen_mov_i32(tmp, cpu_R[RRR_T]);
1493 gen_rsr(dc, cpu_R[RRR_T], RSR_SR);
1494 gen_wsr(dc, RSR_SR, tmp);
1495 tcg_temp_free(tmp);
1497 break;
1500 * Note: 64 bit ops are used here solely because SAR values
1501 * have range 0..63
1503 #define gen_shift_reg(cmd, reg) do { \
1504 TCGv_i64 tmp = tcg_temp_new_i64(); \
1505 tcg_gen_extu_i32_i64(tmp, reg); \
1506 tcg_gen_##cmd##_i64(v, v, tmp); \
1507 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \
1508 tcg_temp_free_i64(v); \
1509 tcg_temp_free_i64(tmp); \
1510 } while (0)
1512 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1514 case 8: /*SRC*/
1515 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1517 TCGv_i64 v = tcg_temp_new_i64();
1518 tcg_gen_concat_i32_i64(v, cpu_R[RRR_T], cpu_R[RRR_S]);
1519 gen_shift(shr);
1521 break;
1523 case 9: /*SRL*/
1524 gen_window_check2(dc, RRR_R, RRR_T);
1525 if (dc->sar_5bit) {
1526 tcg_gen_shr_i32(cpu_R[RRR_R], cpu_R[RRR_T], cpu_SR[SAR]);
1527 } else {
1528 TCGv_i64 v = tcg_temp_new_i64();
1529 tcg_gen_extu_i32_i64(v, cpu_R[RRR_T]);
1530 gen_shift(shr);
1532 break;
1534 case 10: /*SLL*/
1535 gen_window_check2(dc, RRR_R, RRR_S);
1536 if (dc->sar_m32_5bit) {
1537 tcg_gen_shl_i32(cpu_R[RRR_R], cpu_R[RRR_S], dc->sar_m32);
1538 } else {
1539 TCGv_i64 v = tcg_temp_new_i64();
1540 TCGv_i32 s = tcg_const_i32(32);
1541 tcg_gen_sub_i32(s, s, cpu_SR[SAR]);
1542 tcg_gen_andi_i32(s, s, 0x3f);
1543 tcg_gen_extu_i32_i64(v, cpu_R[RRR_S]);
1544 gen_shift_reg(shl, s);
1545 tcg_temp_free(s);
1547 break;
1549 case 11: /*SRA*/
1550 gen_window_check2(dc, RRR_R, RRR_T);
1551 if (dc->sar_5bit) {
1552 tcg_gen_sar_i32(cpu_R[RRR_R], cpu_R[RRR_T], cpu_SR[SAR]);
1553 } else {
1554 TCGv_i64 v = tcg_temp_new_i64();
1555 tcg_gen_ext_i32_i64(v, cpu_R[RRR_T]);
1556 gen_shift(sar);
1558 break;
1559 #undef gen_shift
1560 #undef gen_shift_reg
1562 case 12: /*MUL16U*/
1563 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL);
1564 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1566 TCGv_i32 v1 = tcg_temp_new_i32();
1567 TCGv_i32 v2 = tcg_temp_new_i32();
1568 tcg_gen_ext16u_i32(v1, cpu_R[RRR_S]);
1569 tcg_gen_ext16u_i32(v2, cpu_R[RRR_T]);
1570 tcg_gen_mul_i32(cpu_R[RRR_R], v1, v2);
1571 tcg_temp_free(v2);
1572 tcg_temp_free(v1);
1574 break;
1576 case 13: /*MUL16S*/
1577 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL);
1578 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1580 TCGv_i32 v1 = tcg_temp_new_i32();
1581 TCGv_i32 v2 = tcg_temp_new_i32();
1582 tcg_gen_ext16s_i32(v1, cpu_R[RRR_S]);
1583 tcg_gen_ext16s_i32(v2, cpu_R[RRR_T]);
1584 tcg_gen_mul_i32(cpu_R[RRR_R], v1, v2);
1585 tcg_temp_free(v2);
1586 tcg_temp_free(v1);
1588 break;
1590 default: /*reserved*/
1591 RESERVED();
1592 break;
1594 break;
1596 case 2: /*RST2*/
1597 if (OP2 >= 8) {
1598 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1601 if (OP2 >= 12) {
1602 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV);
1603 int label = gen_new_label();
1604 tcg_gen_brcondi_i32(TCG_COND_NE, cpu_R[RRR_T], 0, label);
1605 gen_exception_cause(dc, INTEGER_DIVIDE_BY_ZERO_CAUSE);
1606 gen_set_label(label);
1609 switch (OP2) {
1610 #define BOOLEAN_LOGIC(fn, r, s, t) \
1611 do { \
1612 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1613 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1614 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1616 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1617 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1618 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1619 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1620 tcg_temp_free(tmp1); \
1621 tcg_temp_free(tmp2); \
1622 } while (0)
1624 case 0: /*ANDBp*/
1625 BOOLEAN_LOGIC(and, RRR_R, RRR_S, RRR_T);
1626 break;
1628 case 1: /*ANDBCp*/
1629 BOOLEAN_LOGIC(andc, RRR_R, RRR_S, RRR_T);
1630 break;
1632 case 2: /*ORBp*/
1633 BOOLEAN_LOGIC(or, RRR_R, RRR_S, RRR_T);
1634 break;
1636 case 3: /*ORBCp*/
1637 BOOLEAN_LOGIC(orc, RRR_R, RRR_S, RRR_T);
1638 break;
1640 case 4: /*XORBp*/
1641 BOOLEAN_LOGIC(xor, RRR_R, RRR_S, RRR_T);
1642 break;
1644 #undef BOOLEAN_LOGIC
1646 case 8: /*MULLi*/
1647 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL);
1648 tcg_gen_mul_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1649 break;
1651 case 10: /*MULUHi*/
1652 case 11: /*MULSHi*/
1653 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH);
1655 TCGv_i64 r = tcg_temp_new_i64();
1656 TCGv_i64 s = tcg_temp_new_i64();
1657 TCGv_i64 t = tcg_temp_new_i64();
1659 if (OP2 == 10) {
1660 tcg_gen_extu_i32_i64(s, cpu_R[RRR_S]);
1661 tcg_gen_extu_i32_i64(t, cpu_R[RRR_T]);
1662 } else {
1663 tcg_gen_ext_i32_i64(s, cpu_R[RRR_S]);
1664 tcg_gen_ext_i32_i64(t, cpu_R[RRR_T]);
1666 tcg_gen_mul_i64(r, s, t);
1667 tcg_gen_shri_i64(r, r, 32);
1668 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], r);
1670 tcg_temp_free_i64(r);
1671 tcg_temp_free_i64(s);
1672 tcg_temp_free_i64(t);
1674 break;
1676 case 12: /*QUOUi*/
1677 tcg_gen_divu_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1678 break;
1680 case 13: /*QUOSi*/
1681 case 15: /*REMSi*/
1683 int label1 = gen_new_label();
1684 int label2 = gen_new_label();
1686 tcg_gen_brcondi_i32(TCG_COND_NE, cpu_R[RRR_S], 0x80000000,
1687 label1);
1688 tcg_gen_brcondi_i32(TCG_COND_NE, cpu_R[RRR_T], 0xffffffff,
1689 label1);
1690 tcg_gen_movi_i32(cpu_R[RRR_R],
1691 OP2 == 13 ? 0x80000000 : 0);
1692 tcg_gen_br(label2);
1693 gen_set_label(label1);
1694 if (OP2 == 13) {
1695 tcg_gen_div_i32(cpu_R[RRR_R],
1696 cpu_R[RRR_S], cpu_R[RRR_T]);
1697 } else {
1698 tcg_gen_rem_i32(cpu_R[RRR_R],
1699 cpu_R[RRR_S], cpu_R[RRR_T]);
1701 gen_set_label(label2);
1703 break;
1705 case 14: /*REMUi*/
1706 tcg_gen_remu_i32(cpu_R[RRR_R], cpu_R[RRR_S], cpu_R[RRR_T]);
1707 break;
1709 default: /*reserved*/
1710 RESERVED();
1711 break;
1713 break;
1715 case 3: /*RST3*/
1716 switch (OP2) {
1717 case 0: /*RSR*/
1718 gen_check_sr(dc, RSR_SR, SR_R);
1719 if (RSR_SR >= 64) {
1720 gen_check_privilege(dc);
1722 gen_window_check1(dc, RRR_T);
1723 gen_rsr(dc, cpu_R[RRR_T], RSR_SR);
1724 break;
1726 case 1: /*WSR*/
1727 gen_check_sr(dc, RSR_SR, SR_W);
1728 if (RSR_SR >= 64) {
1729 gen_check_privilege(dc);
1731 gen_window_check1(dc, RRR_T);
1732 gen_wsr(dc, RSR_SR, cpu_R[RRR_T]);
1733 break;
1735 case 2: /*SEXTu*/
1736 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT);
1737 gen_window_check2(dc, RRR_R, RRR_S);
1739 int shift = 24 - RRR_T;
1741 if (shift == 24) {
1742 tcg_gen_ext8s_i32(cpu_R[RRR_R], cpu_R[RRR_S]);
1743 } else if (shift == 16) {
1744 tcg_gen_ext16s_i32(cpu_R[RRR_R], cpu_R[RRR_S]);
1745 } else {
1746 TCGv_i32 tmp = tcg_temp_new_i32();
1747 tcg_gen_shli_i32(tmp, cpu_R[RRR_S], shift);
1748 tcg_gen_sari_i32(cpu_R[RRR_R], tmp, shift);
1749 tcg_temp_free(tmp);
1752 break;
1754 case 3: /*CLAMPSu*/
1755 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS);
1756 gen_window_check2(dc, RRR_R, RRR_S);
1758 TCGv_i32 tmp1 = tcg_temp_new_i32();
1759 TCGv_i32 tmp2 = tcg_temp_new_i32();
1760 TCGv_i32 zero = tcg_const_i32(0);
1762 tcg_gen_sari_i32(tmp1, cpu_R[RRR_S], 24 - RRR_T);
1763 tcg_gen_xor_i32(tmp2, tmp1, cpu_R[RRR_S]);
1764 tcg_gen_andi_i32(tmp2, tmp2, 0xffffffff << (RRR_T + 7));
1766 tcg_gen_sari_i32(tmp1, cpu_R[RRR_S], 31);
1767 tcg_gen_xori_i32(tmp1, tmp1, 0xffffffff >> (25 - RRR_T));
1769 tcg_gen_movcond_i32(TCG_COND_EQ, cpu_R[RRR_R], tmp2, zero,
1770 cpu_R[RRR_S], tmp1);
1771 tcg_temp_free(tmp1);
1772 tcg_temp_free(tmp2);
1773 tcg_temp_free(zero);
1775 break;
1777 case 4: /*MINu*/
1778 case 5: /*MAXu*/
1779 case 6: /*MINUu*/
1780 case 7: /*MAXUu*/
1781 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX);
1782 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1784 static const TCGCond cond[] = {
1785 TCG_COND_LE,
1786 TCG_COND_GE,
1787 TCG_COND_LEU,
1788 TCG_COND_GEU
1790 tcg_gen_movcond_i32(cond[OP2 - 4], cpu_R[RRR_R],
1791 cpu_R[RRR_S], cpu_R[RRR_T],
1792 cpu_R[RRR_S], cpu_R[RRR_T]);
1794 break;
1796 case 8: /*MOVEQZ*/
1797 case 9: /*MOVNEZ*/
1798 case 10: /*MOVLTZ*/
1799 case 11: /*MOVGEZ*/
1800 gen_window_check3(dc, RRR_R, RRR_S, RRR_T);
1802 static const TCGCond cond[] = {
1803 TCG_COND_EQ,
1804 TCG_COND_NE,
1805 TCG_COND_LT,
1806 TCG_COND_GE,
1808 TCGv_i32 zero = tcg_const_i32(0);
1810 tcg_gen_movcond_i32(cond[OP2 - 8], cpu_R[RRR_R],
1811 cpu_R[RRR_T], zero, cpu_R[RRR_S], cpu_R[RRR_R]);
1812 tcg_temp_free(zero);
1814 break;
1816 case 12: /*MOVFp*/
1817 case 13: /*MOVTp*/
1818 HAS_OPTION(XTENSA_OPTION_BOOLEAN);
1819 gen_window_check2(dc, RRR_R, RRR_S);
1821 TCGv_i32 zero = tcg_const_i32(0);
1822 TCGv_i32 tmp = tcg_temp_new_i32();
1824 tcg_gen_andi_i32(tmp, cpu_SR[BR], 1 << RRR_T);
1825 tcg_gen_movcond_i32(OP2 & 1 ? TCG_COND_NE : TCG_COND_EQ,
1826 cpu_R[RRR_R], tmp, zero,
1827 cpu_R[RRR_S], cpu_R[RRR_R]);
1829 tcg_temp_free(tmp);
1830 tcg_temp_free(zero);
1832 break;
1834 case 14: /*RUR*/
1835 gen_window_check1(dc, RRR_R);
1837 int st = (RRR_S << 4) + RRR_T;
1838 if (uregnames[st].name) {
1839 tcg_gen_mov_i32(cpu_R[RRR_R], cpu_UR[st]);
1840 } else {
1841 qemu_log("RUR %d not implemented, ", st);
1842 TBD();
1845 break;
1847 case 15: /*WUR*/
1848 gen_window_check1(dc, RRR_T);
1849 if (uregnames[RSR_SR].name) {
1850 gen_wur(RSR_SR, cpu_R[RRR_T]);
1851 } else {
1852 qemu_log("WUR %d not implemented, ", RSR_SR);
1853 TBD();
1855 break;
1858 break;
1860 case 4: /*EXTUI*/
1861 case 5:
1862 gen_window_check2(dc, RRR_R, RRR_T);
1864 int shiftimm = RRR_S | ((OP1 & 1) << 4);
1865 int maskimm = (1 << (OP2 + 1)) - 1;
1867 TCGv_i32 tmp = tcg_temp_new_i32();
1868 tcg_gen_shri_i32(tmp, cpu_R[RRR_T], shiftimm);
1869 tcg_gen_andi_i32(cpu_R[RRR_R], tmp, maskimm);
1870 tcg_temp_free(tmp);
1872 break;
1874 case 6: /*CUST0*/
1875 RESERVED();
1876 break;
1878 case 7: /*CUST1*/
1879 RESERVED();
1880 break;
1882 case 8: /*LSCXp*/
1883 switch (OP2) {
1884 case 0: /*LSXf*/
1885 case 1: /*LSXUf*/
1886 case 4: /*SSXf*/
1887 case 5: /*SSXUf*/
1888 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR);
1889 gen_window_check2(dc, RRR_S, RRR_T);
1890 gen_check_cpenable(dc, 0);
1892 TCGv_i32 addr = tcg_temp_new_i32();
1893 tcg_gen_add_i32(addr, cpu_R[RRR_S], cpu_R[RRR_T]);
1894 gen_load_store_alignment(dc, 2, addr, false);
1895 if (OP2 & 0x4) {
1896 tcg_gen_qemu_st32(cpu_FR[RRR_R], addr, dc->cring);
1897 } else {
1898 tcg_gen_qemu_ld32u(cpu_FR[RRR_R], addr, dc->cring);
1900 if (OP2 & 0x1) {
1901 tcg_gen_mov_i32(cpu_R[RRR_S], addr);
1903 tcg_temp_free(addr);
1905 break;
1907 default: /*reserved*/
1908 RESERVED();
1909 break;
1911 break;
1913 case 9: /*LSC4*/
1914 gen_window_check2(dc, RRR_S, RRR_T);
1915 switch (OP2) {
1916 case 0: /*L32E*/
1917 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1918 gen_check_privilege(dc);
1920 TCGv_i32 addr = tcg_temp_new_i32();
1921 tcg_gen_addi_i32(addr, cpu_R[RRR_S],
1922 (0xffffffc0 | (RRR_R << 2)));
1923 tcg_gen_qemu_ld32u(cpu_R[RRR_T], addr, dc->ring);
1924 tcg_temp_free(addr);
1926 break;
1928 case 4: /*S32E*/
1929 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
1930 gen_check_privilege(dc);
1932 TCGv_i32 addr = tcg_temp_new_i32();
1933 tcg_gen_addi_i32(addr, cpu_R[RRR_S],
1934 (0xffffffc0 | (RRR_R << 2)));
1935 tcg_gen_qemu_st32(cpu_R[RRR_T], addr, dc->ring);
1936 tcg_temp_free(addr);
1938 break;
1940 default:
1941 RESERVED();
1942 break;
1944 break;
1946 case 10: /*FP0*/
1947 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR);
1948 switch (OP2) {
1949 case 0: /*ADD.Sf*/
1950 gen_check_cpenable(dc, 0);
1951 gen_helper_add_s(cpu_FR[RRR_R], cpu_env,
1952 cpu_FR[RRR_S], cpu_FR[RRR_T]);
1953 break;
1955 case 1: /*SUB.Sf*/
1956 gen_check_cpenable(dc, 0);
1957 gen_helper_sub_s(cpu_FR[RRR_R], cpu_env,
1958 cpu_FR[RRR_S], cpu_FR[RRR_T]);
1959 break;
1961 case 2: /*MUL.Sf*/
1962 gen_check_cpenable(dc, 0);
1963 gen_helper_mul_s(cpu_FR[RRR_R], cpu_env,
1964 cpu_FR[RRR_S], cpu_FR[RRR_T]);
1965 break;
1967 case 4: /*MADD.Sf*/
1968 gen_check_cpenable(dc, 0);
1969 gen_helper_madd_s(cpu_FR[RRR_R], cpu_env,
1970 cpu_FR[RRR_R], cpu_FR[RRR_S], cpu_FR[RRR_T]);
1971 break;
1973 case 5: /*MSUB.Sf*/
1974 gen_check_cpenable(dc, 0);
1975 gen_helper_msub_s(cpu_FR[RRR_R], cpu_env,
1976 cpu_FR[RRR_R], cpu_FR[RRR_S], cpu_FR[RRR_T]);
1977 break;
1979 case 8: /*ROUND.Sf*/
1980 case 9: /*TRUNC.Sf*/
1981 case 10: /*FLOOR.Sf*/
1982 case 11: /*CEIL.Sf*/
1983 case 14: /*UTRUNC.Sf*/
1984 gen_window_check1(dc, RRR_R);
1985 gen_check_cpenable(dc, 0);
1987 static const unsigned rounding_mode_const[] = {
1988 float_round_nearest_even,
1989 float_round_to_zero,
1990 float_round_down,
1991 float_round_up,
1992 [6] = float_round_to_zero,
1994 TCGv_i32 rounding_mode = tcg_const_i32(
1995 rounding_mode_const[OP2 & 7]);
1996 TCGv_i32 scale = tcg_const_i32(RRR_T);
1998 if (OP2 == 14) {
1999 gen_helper_ftoui(cpu_R[RRR_R], cpu_FR[RRR_S],
2000 rounding_mode, scale);
2001 } else {
2002 gen_helper_ftoi(cpu_R[RRR_R], cpu_FR[RRR_S],
2003 rounding_mode, scale);
2006 tcg_temp_free(rounding_mode);
2007 tcg_temp_free(scale);
2009 break;
2011 case 12: /*FLOAT.Sf*/
2012 case 13: /*UFLOAT.Sf*/
2013 gen_window_check1(dc, RRR_S);
2014 gen_check_cpenable(dc, 0);
2016 TCGv_i32 scale = tcg_const_i32(-RRR_T);
2018 if (OP2 == 13) {
2019 gen_helper_uitof(cpu_FR[RRR_R], cpu_env,
2020 cpu_R[RRR_S], scale);
2021 } else {
2022 gen_helper_itof(cpu_FR[RRR_R], cpu_env,
2023 cpu_R[RRR_S], scale);
2025 tcg_temp_free(scale);
2027 break;
2029 case 15: /*FP1OP*/
2030 switch (RRR_T) {
2031 case 0: /*MOV.Sf*/
2032 gen_check_cpenable(dc, 0);
2033 tcg_gen_mov_i32(cpu_FR[RRR_R], cpu_FR[RRR_S]);
2034 break;
2036 case 1: /*ABS.Sf*/
2037 gen_check_cpenable(dc, 0);
2038 gen_helper_abs_s(cpu_FR[RRR_R], cpu_FR[RRR_S]);
2039 break;
2041 case 4: /*RFRf*/
2042 gen_window_check1(dc, RRR_R);
2043 gen_check_cpenable(dc, 0);
2044 tcg_gen_mov_i32(cpu_R[RRR_R], cpu_FR[RRR_S]);
2045 break;
2047 case 5: /*WFRf*/
2048 gen_window_check1(dc, RRR_S);
2049 gen_check_cpenable(dc, 0);
2050 tcg_gen_mov_i32(cpu_FR[RRR_R], cpu_R[RRR_S]);
2051 break;
2053 case 6: /*NEG.Sf*/
2054 gen_check_cpenable(dc, 0);
2055 gen_helper_neg_s(cpu_FR[RRR_R], cpu_FR[RRR_S]);
2056 break;
2058 default: /*reserved*/
2059 RESERVED();
2060 break;
2062 break;
2064 default: /*reserved*/
2065 RESERVED();
2066 break;
2068 break;
2070 case 11: /*FP1*/
2071 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR);
2073 #define gen_compare(rel, br, a, b) \
2074 do { \
2075 TCGv_i32 bit = tcg_const_i32(1 << br); \
2077 gen_check_cpenable(dc, 0); \
2078 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2079 tcg_temp_free(bit); \
2080 } while (0)
2082 switch (OP2) {
2083 case 1: /*UN.Sf*/
2084 gen_compare(un_s, RRR_R, RRR_S, RRR_T);
2085 break;
2087 case 2: /*OEQ.Sf*/
2088 gen_compare(oeq_s, RRR_R, RRR_S, RRR_T);
2089 break;
2091 case 3: /*UEQ.Sf*/
2092 gen_compare(ueq_s, RRR_R, RRR_S, RRR_T);
2093 break;
2095 case 4: /*OLT.Sf*/
2096 gen_compare(olt_s, RRR_R, RRR_S, RRR_T);
2097 break;
2099 case 5: /*ULT.Sf*/
2100 gen_compare(ult_s, RRR_R, RRR_S, RRR_T);
2101 break;
2103 case 6: /*OLE.Sf*/
2104 gen_compare(ole_s, RRR_R, RRR_S, RRR_T);
2105 break;
2107 case 7: /*ULE.Sf*/
2108 gen_compare(ule_s, RRR_R, RRR_S, RRR_T);
2109 break;
2111 #undef gen_compare
2113 case 8: /*MOVEQZ.Sf*/
2114 case 9: /*MOVNEZ.Sf*/
2115 case 10: /*MOVLTZ.Sf*/
2116 case 11: /*MOVGEZ.Sf*/
2117 gen_window_check1(dc, RRR_T);
2118 gen_check_cpenable(dc, 0);
2120 static const TCGCond cond[] = {
2121 TCG_COND_EQ,
2122 TCG_COND_NE,
2123 TCG_COND_LT,
2124 TCG_COND_GE,
2126 TCGv_i32 zero = tcg_const_i32(0);
2128 tcg_gen_movcond_i32(cond[OP2 - 8], cpu_FR[RRR_R],
2129 cpu_R[RRR_T], zero, cpu_FR[RRR_S], cpu_FR[RRR_R]);
2130 tcg_temp_free(zero);
2132 break;
2134 case 12: /*MOVF.Sf*/
2135 case 13: /*MOVT.Sf*/
2136 HAS_OPTION(XTENSA_OPTION_BOOLEAN);
2137 gen_check_cpenable(dc, 0);
2139 TCGv_i32 zero = tcg_const_i32(0);
2140 TCGv_i32 tmp = tcg_temp_new_i32();
2142 tcg_gen_andi_i32(tmp, cpu_SR[BR], 1 << RRR_T);
2143 tcg_gen_movcond_i32(OP2 & 1 ? TCG_COND_NE : TCG_COND_EQ,
2144 cpu_FR[RRR_R], tmp, zero,
2145 cpu_FR[RRR_S], cpu_FR[RRR_R]);
2147 tcg_temp_free(tmp);
2148 tcg_temp_free(zero);
2150 break;
2152 default: /*reserved*/
2153 RESERVED();
2154 break;
2156 break;
2158 default: /*reserved*/
2159 RESERVED();
2160 break;
2162 break;
2164 case 1: /*L32R*/
2165 gen_window_check1(dc, RRR_T);
2167 TCGv_i32 tmp = tcg_const_i32(
2168 ((dc->tb->flags & XTENSA_TBFLAG_LITBASE) ?
2169 0 : ((dc->pc + 3) & ~3)) +
2170 (0xfffc0000 | (RI16_IMM16 << 2)));
2172 if (dc->tb->flags & XTENSA_TBFLAG_LITBASE) {
2173 tcg_gen_add_i32(tmp, tmp, dc->litbase);
2175 tcg_gen_qemu_ld32u(cpu_R[RRR_T], tmp, dc->cring);
2176 tcg_temp_free(tmp);
2178 break;
2180 case 2: /*LSAI*/
2181 #define gen_load_store(type, shift) do { \
2182 TCGv_i32 addr = tcg_temp_new_i32(); \
2183 gen_window_check2(dc, RRI8_S, RRI8_T); \
2184 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2185 if (shift) { \
2186 gen_load_store_alignment(dc, shift, addr, false); \
2188 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2189 tcg_temp_free(addr); \
2190 } while (0)
2192 switch (RRI8_R) {
2193 case 0: /*L8UI*/
2194 gen_load_store(ld8u, 0);
2195 break;
2197 case 1: /*L16UI*/
2198 gen_load_store(ld16u, 1);
2199 break;
2201 case 2: /*L32I*/
2202 gen_load_store(ld32u, 2);
2203 break;
2205 case 4: /*S8I*/
2206 gen_load_store(st8, 0);
2207 break;
2209 case 5: /*S16I*/
2210 gen_load_store(st16, 1);
2211 break;
2213 case 6: /*S32I*/
2214 gen_load_store(st32, 2);
2215 break;
2217 case 7: /*CACHEc*/
2218 if (RRI8_T < 8) {
2219 HAS_OPTION(XTENSA_OPTION_DCACHE);
2222 switch (RRI8_T) {
2223 case 0: /*DPFRc*/
2224 break;
2226 case 1: /*DPFWc*/
2227 break;
2229 case 2: /*DPFROc*/
2230 break;
2232 case 3: /*DPFWOc*/
2233 break;
2235 case 4: /*DHWBc*/
2236 break;
2238 case 5: /*DHWBIc*/
2239 break;
2241 case 6: /*DHIc*/
2242 break;
2244 case 7: /*DIIc*/
2245 break;
2247 case 8: /*DCEc*/
2248 switch (OP1) {
2249 case 0: /*DPFLl*/
2250 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK);
2251 break;
2253 case 2: /*DHUl*/
2254 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK);
2255 break;
2257 case 3: /*DIUl*/
2258 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK);
2259 break;
2261 case 4: /*DIWBc*/
2262 HAS_OPTION(XTENSA_OPTION_DCACHE);
2263 break;
2265 case 5: /*DIWBIc*/
2266 HAS_OPTION(XTENSA_OPTION_DCACHE);
2267 break;
2269 default: /*reserved*/
2270 RESERVED();
2271 break;
2274 break;
2276 case 12: /*IPFc*/
2277 HAS_OPTION(XTENSA_OPTION_ICACHE);
2278 break;
2280 case 13: /*ICEc*/
2281 switch (OP1) {
2282 case 0: /*IPFLl*/
2283 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK);
2284 break;
2286 case 2: /*IHUl*/
2287 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK);
2288 break;
2290 case 3: /*IIUl*/
2291 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK);
2292 break;
2294 default: /*reserved*/
2295 RESERVED();
2296 break;
2298 break;
2300 case 14: /*IHIc*/
2301 HAS_OPTION(XTENSA_OPTION_ICACHE);
2302 break;
2304 case 15: /*IIIc*/
2305 HAS_OPTION(XTENSA_OPTION_ICACHE);
2306 break;
2308 default: /*reserved*/
2309 RESERVED();
2310 break;
2312 break;
2314 case 9: /*L16SI*/
2315 gen_load_store(ld16s, 1);
2316 break;
2317 #undef gen_load_store
2319 case 10: /*MOVI*/
2320 gen_window_check1(dc, RRI8_T);
2321 tcg_gen_movi_i32(cpu_R[RRI8_T],
2322 RRI8_IMM8 | (RRI8_S << 8) |
2323 ((RRI8_S & 0x8) ? 0xfffff000 : 0));
2324 break;
2326 #define gen_load_store_no_hw_align(type) do { \
2327 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2328 gen_window_check2(dc, RRI8_S, RRI8_T); \
2329 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2330 gen_load_store_alignment(dc, 2, addr, true); \
2331 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2332 tcg_temp_free(addr); \
2333 } while (0)
2335 case 11: /*L32AIy*/
2336 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO);
2337 gen_load_store_no_hw_align(ld32u); /*TODO acquire?*/
2338 break;
2340 case 12: /*ADDI*/
2341 gen_window_check2(dc, RRI8_S, RRI8_T);
2342 tcg_gen_addi_i32(cpu_R[RRI8_T], cpu_R[RRI8_S], RRI8_IMM8_SE);
2343 break;
2345 case 13: /*ADDMI*/
2346 gen_window_check2(dc, RRI8_S, RRI8_T);
2347 tcg_gen_addi_i32(cpu_R[RRI8_T], cpu_R[RRI8_S], RRI8_IMM8_SE << 8);
2348 break;
2350 case 14: /*S32C1Iy*/
2351 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE);
2352 gen_window_check2(dc, RRI8_S, RRI8_T);
2354 int label = gen_new_label();
2355 TCGv_i32 tmp = tcg_temp_local_new_i32();
2356 TCGv_i32 addr = tcg_temp_local_new_i32();
2357 TCGv_i32 tpc;
2359 tcg_gen_mov_i32(tmp, cpu_R[RRI8_T]);
2360 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2);
2361 gen_load_store_alignment(dc, 2, addr, true);
2363 gen_advance_ccount(dc);
2364 tpc = tcg_const_i32(dc->pc);
2365 gen_helper_check_atomctl(cpu_env, tpc, addr);
2366 tcg_gen_qemu_ld32u(cpu_R[RRI8_T], addr, dc->cring);
2367 tcg_gen_brcond_i32(TCG_COND_NE, cpu_R[RRI8_T],
2368 cpu_SR[SCOMPARE1], label);
2370 tcg_gen_qemu_st32(tmp, addr, dc->cring);
2372 gen_set_label(label);
2373 tcg_temp_free(tpc);
2374 tcg_temp_free(addr);
2375 tcg_temp_free(tmp);
2377 break;
2379 case 15: /*S32RIy*/
2380 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO);
2381 gen_load_store_no_hw_align(st32); /*TODO release?*/
2382 break;
2383 #undef gen_load_store_no_hw_align
2385 default: /*reserved*/
2386 RESERVED();
2387 break;
2389 break;
2391 case 3: /*LSCIp*/
2392 switch (RRI8_R) {
2393 case 0: /*LSIf*/
2394 case 4: /*SSIf*/
2395 case 8: /*LSIUf*/
2396 case 12: /*SSIUf*/
2397 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR);
2398 gen_window_check1(dc, RRI8_S);
2399 gen_check_cpenable(dc, 0);
2401 TCGv_i32 addr = tcg_temp_new_i32();
2402 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2);
2403 gen_load_store_alignment(dc, 2, addr, false);
2404 if (RRI8_R & 0x4) {
2405 tcg_gen_qemu_st32(cpu_FR[RRI8_T], addr, dc->cring);
2406 } else {
2407 tcg_gen_qemu_ld32u(cpu_FR[RRI8_T], addr, dc->cring);
2409 if (RRI8_R & 0x8) {
2410 tcg_gen_mov_i32(cpu_R[RRI8_S], addr);
2412 tcg_temp_free(addr);
2414 break;
2416 default: /*reserved*/
2417 RESERVED();
2418 break;
2420 break;
2422 case 4: /*MAC16d*/
2423 HAS_OPTION(XTENSA_OPTION_MAC16);
2425 enum {
2426 MAC16_UMUL = 0x0,
2427 MAC16_MUL = 0x4,
2428 MAC16_MULA = 0x8,
2429 MAC16_MULS = 0xc,
2430 MAC16_NONE = 0xf,
2431 } op = OP1 & 0xc;
2432 bool is_m1_sr = (OP2 & 0x3) == 2;
2433 bool is_m2_sr = (OP2 & 0xc) == 0;
2434 uint32_t ld_offset = 0;
2436 if (OP2 > 9) {
2437 RESERVED();
2440 switch (OP2 & 2) {
2441 case 0: /*MACI?/MACC?*/
2442 is_m1_sr = true;
2443 ld_offset = (OP2 & 1) ? -4 : 4;
2445 if (OP2 >= 8) { /*MACI/MACC*/
2446 if (OP1 == 0) { /*LDINC/LDDEC*/
2447 op = MAC16_NONE;
2448 } else {
2449 RESERVED();
2451 } else if (op != MAC16_MULA) { /*MULA.*.*.LDINC/LDDEC*/
2452 RESERVED();
2454 break;
2456 case 2: /*MACD?/MACA?*/
2457 if (op == MAC16_UMUL && OP2 != 7) { /*UMUL only in MACAA*/
2458 RESERVED();
2460 break;
2463 if (op != MAC16_NONE) {
2464 if (!is_m1_sr) {
2465 gen_window_check1(dc, RRR_S);
2467 if (!is_m2_sr) {
2468 gen_window_check1(dc, RRR_T);
2473 TCGv_i32 vaddr = tcg_temp_new_i32();
2474 TCGv_i32 mem32 = tcg_temp_new_i32();
2476 if (ld_offset) {
2477 gen_window_check1(dc, RRR_S);
2478 tcg_gen_addi_i32(vaddr, cpu_R[RRR_S], ld_offset);
2479 gen_load_store_alignment(dc, 2, vaddr, false);
2480 tcg_gen_qemu_ld32u(mem32, vaddr, dc->cring);
2482 if (op != MAC16_NONE) {
2483 TCGv_i32 m1 = gen_mac16_m(
2484 is_m1_sr ? cpu_SR[MR + RRR_X] : cpu_R[RRR_S],
2485 OP1 & 1, op == MAC16_UMUL);
2486 TCGv_i32 m2 = gen_mac16_m(
2487 is_m2_sr ? cpu_SR[MR + 2 + RRR_Y] : cpu_R[RRR_T],
2488 OP1 & 2, op == MAC16_UMUL);
2490 if (op == MAC16_MUL || op == MAC16_UMUL) {
2491 tcg_gen_mul_i32(cpu_SR[ACCLO], m1, m2);
2492 if (op == MAC16_UMUL) {
2493 tcg_gen_movi_i32(cpu_SR[ACCHI], 0);
2494 } else {
2495 tcg_gen_sari_i32(cpu_SR[ACCHI], cpu_SR[ACCLO], 31);
2497 } else {
2498 TCGv_i32 res = tcg_temp_new_i32();
2499 TCGv_i64 res64 = tcg_temp_new_i64();
2500 TCGv_i64 tmp = tcg_temp_new_i64();
2502 tcg_gen_mul_i32(res, m1, m2);
2503 tcg_gen_ext_i32_i64(res64, res);
2504 tcg_gen_concat_i32_i64(tmp,
2505 cpu_SR[ACCLO], cpu_SR[ACCHI]);
2506 if (op == MAC16_MULA) {
2507 tcg_gen_add_i64(tmp, tmp, res64);
2508 } else {
2509 tcg_gen_sub_i64(tmp, tmp, res64);
2511 tcg_gen_trunc_i64_i32(cpu_SR[ACCLO], tmp);
2512 tcg_gen_shri_i64(tmp, tmp, 32);
2513 tcg_gen_trunc_i64_i32(cpu_SR[ACCHI], tmp);
2514 tcg_gen_ext8s_i32(cpu_SR[ACCHI], cpu_SR[ACCHI]);
2516 tcg_temp_free(res);
2517 tcg_temp_free_i64(res64);
2518 tcg_temp_free_i64(tmp);
2520 tcg_temp_free(m1);
2521 tcg_temp_free(m2);
2523 if (ld_offset) {
2524 tcg_gen_mov_i32(cpu_R[RRR_S], vaddr);
2525 tcg_gen_mov_i32(cpu_SR[MR + RRR_W], mem32);
2527 tcg_temp_free(vaddr);
2528 tcg_temp_free(mem32);
2531 break;
2533 case 5: /*CALLN*/
2534 switch (CALL_N) {
2535 case 0: /*CALL0*/
2536 tcg_gen_movi_i32(cpu_R[0], dc->next_pc);
2537 gen_jumpi(dc, (dc->pc & ~3) + (CALL_OFFSET_SE << 2) + 4, 0);
2538 break;
2540 case 1: /*CALL4w*/
2541 case 2: /*CALL8w*/
2542 case 3: /*CALL12w*/
2543 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
2544 gen_window_check1(dc, CALL_N << 2);
2545 gen_callwi(dc, CALL_N,
2546 (dc->pc & ~3) + (CALL_OFFSET_SE << 2) + 4, 0);
2547 break;
2549 break;
2551 case 6: /*SI*/
2552 switch (CALL_N) {
2553 case 0: /*J*/
2554 gen_jumpi(dc, dc->pc + 4 + CALL_OFFSET_SE, 0);
2555 break;
2557 case 1: /*BZ*/
2558 gen_window_check1(dc, BRI12_S);
2560 static const TCGCond cond[] = {
2561 TCG_COND_EQ, /*BEQZ*/
2562 TCG_COND_NE, /*BNEZ*/
2563 TCG_COND_LT, /*BLTZ*/
2564 TCG_COND_GE, /*BGEZ*/
2567 gen_brcondi(dc, cond[BRI12_M & 3], cpu_R[BRI12_S], 0,
2568 4 + BRI12_IMM12_SE);
2570 break;
2572 case 2: /*BI0*/
2573 gen_window_check1(dc, BRI8_S);
2575 static const TCGCond cond[] = {
2576 TCG_COND_EQ, /*BEQI*/
2577 TCG_COND_NE, /*BNEI*/
2578 TCG_COND_LT, /*BLTI*/
2579 TCG_COND_GE, /*BGEI*/
2582 gen_brcondi(dc, cond[BRI8_M & 3],
2583 cpu_R[BRI8_S], B4CONST[BRI8_R], 4 + BRI8_IMM8_SE);
2585 break;
2587 case 3: /*BI1*/
2588 switch (BRI8_M) {
2589 case 0: /*ENTRYw*/
2590 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
2592 TCGv_i32 pc = tcg_const_i32(dc->pc);
2593 TCGv_i32 s = tcg_const_i32(BRI12_S);
2594 TCGv_i32 imm = tcg_const_i32(BRI12_IMM12);
2595 gen_advance_ccount(dc);
2596 gen_helper_entry(cpu_env, pc, s, imm);
2597 tcg_temp_free(imm);
2598 tcg_temp_free(s);
2599 tcg_temp_free(pc);
2600 reset_used_window(dc);
2602 break;
2604 case 1: /*B1*/
2605 switch (BRI8_R) {
2606 case 0: /*BFp*/
2607 case 1: /*BTp*/
2608 HAS_OPTION(XTENSA_OPTION_BOOLEAN);
2610 TCGv_i32 tmp = tcg_temp_new_i32();
2611 tcg_gen_andi_i32(tmp, cpu_SR[BR], 1 << RRI8_S);
2612 gen_brcondi(dc,
2613 BRI8_R == 1 ? TCG_COND_NE : TCG_COND_EQ,
2614 tmp, 0, 4 + RRI8_IMM8_SE);
2615 tcg_temp_free(tmp);
2617 break;
2619 case 8: /*LOOP*/
2620 case 9: /*LOOPNEZ*/
2621 case 10: /*LOOPGTZ*/
2622 HAS_OPTION(XTENSA_OPTION_LOOP);
2623 gen_window_check1(dc, RRI8_S);
2625 uint32_t lend = dc->pc + RRI8_IMM8 + 4;
2626 TCGv_i32 tmp = tcg_const_i32(lend);
2628 tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_R[RRI8_S], 1);
2629 tcg_gen_movi_i32(cpu_SR[LBEG], dc->next_pc);
2630 gen_helper_wsr_lend(cpu_env, tmp);
2631 tcg_temp_free(tmp);
2633 if (BRI8_R > 8) {
2634 int label = gen_new_label();
2635 tcg_gen_brcondi_i32(
2636 BRI8_R == 9 ? TCG_COND_NE : TCG_COND_GT,
2637 cpu_R[RRI8_S], 0, label);
2638 gen_jumpi(dc, lend, 1);
2639 gen_set_label(label);
2642 gen_jumpi(dc, dc->next_pc, 0);
2644 break;
2646 default: /*reserved*/
2647 RESERVED();
2648 break;
2651 break;
2653 case 2: /*BLTUI*/
2654 case 3: /*BGEUI*/
2655 gen_window_check1(dc, BRI8_S);
2656 gen_brcondi(dc, BRI8_M == 2 ? TCG_COND_LTU : TCG_COND_GEU,
2657 cpu_R[BRI8_S], B4CONSTU[BRI8_R], 4 + BRI8_IMM8_SE);
2658 break;
2660 break;
2663 break;
2665 case 7: /*B*/
2667 TCGCond eq_ne = (RRI8_R & 8) ? TCG_COND_NE : TCG_COND_EQ;
2669 switch (RRI8_R & 7) {
2670 case 0: /*BNONE*/ /*BANY*/
2671 gen_window_check2(dc, RRI8_S, RRI8_T);
2673 TCGv_i32 tmp = tcg_temp_new_i32();
2674 tcg_gen_and_i32(tmp, cpu_R[RRI8_S], cpu_R[RRI8_T]);
2675 gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE);
2676 tcg_temp_free(tmp);
2678 break;
2680 case 1: /*BEQ*/ /*BNE*/
2681 case 2: /*BLT*/ /*BGE*/
2682 case 3: /*BLTU*/ /*BGEU*/
2683 gen_window_check2(dc, RRI8_S, RRI8_T);
2685 static const TCGCond cond[] = {
2686 [1] = TCG_COND_EQ,
2687 [2] = TCG_COND_LT,
2688 [3] = TCG_COND_LTU,
2689 [9] = TCG_COND_NE,
2690 [10] = TCG_COND_GE,
2691 [11] = TCG_COND_GEU,
2693 gen_brcond(dc, cond[RRI8_R], cpu_R[RRI8_S], cpu_R[RRI8_T],
2694 4 + RRI8_IMM8_SE);
2696 break;
2698 case 4: /*BALL*/ /*BNALL*/
2699 gen_window_check2(dc, RRI8_S, RRI8_T);
2701 TCGv_i32 tmp = tcg_temp_new_i32();
2702 tcg_gen_and_i32(tmp, cpu_R[RRI8_S], cpu_R[RRI8_T]);
2703 gen_brcond(dc, eq_ne, tmp, cpu_R[RRI8_T],
2704 4 + RRI8_IMM8_SE);
2705 tcg_temp_free(tmp);
2707 break;
2709 case 5: /*BBC*/ /*BBS*/
2710 gen_window_check2(dc, RRI8_S, RRI8_T);
2712 #ifdef TARGET_WORDS_BIGENDIAN
2713 TCGv_i32 bit = tcg_const_i32(0x80000000);
2714 #else
2715 TCGv_i32 bit = tcg_const_i32(0x00000001);
2716 #endif
2717 TCGv_i32 tmp = tcg_temp_new_i32();
2718 tcg_gen_andi_i32(tmp, cpu_R[RRI8_T], 0x1f);
2719 #ifdef TARGET_WORDS_BIGENDIAN
2720 tcg_gen_shr_i32(bit, bit, tmp);
2721 #else
2722 tcg_gen_shl_i32(bit, bit, tmp);
2723 #endif
2724 tcg_gen_and_i32(tmp, cpu_R[RRI8_S], bit);
2725 gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE);
2726 tcg_temp_free(tmp);
2727 tcg_temp_free(bit);
2729 break;
2731 case 6: /*BBCI*/ /*BBSI*/
2732 case 7:
2733 gen_window_check1(dc, RRI8_S);
2735 TCGv_i32 tmp = tcg_temp_new_i32();
2736 tcg_gen_andi_i32(tmp, cpu_R[RRI8_S],
2737 #ifdef TARGET_WORDS_BIGENDIAN
2738 0x80000000 >> (((RRI8_R & 1) << 4) | RRI8_T));
2739 #else
2740 0x00000001 << (((RRI8_R & 1) << 4) | RRI8_T));
2741 #endif
2742 gen_brcondi(dc, eq_ne, tmp, 0, 4 + RRI8_IMM8_SE);
2743 tcg_temp_free(tmp);
2745 break;
2749 break;
2751 #define gen_narrow_load_store(type) do { \
2752 TCGv_i32 addr = tcg_temp_new_i32(); \
2753 gen_window_check2(dc, RRRN_S, RRRN_T); \
2754 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2755 gen_load_store_alignment(dc, 2, addr, false); \
2756 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2757 tcg_temp_free(addr); \
2758 } while (0)
2760 case 8: /*L32I.Nn*/
2761 gen_narrow_load_store(ld32u);
2762 break;
2764 case 9: /*S32I.Nn*/
2765 gen_narrow_load_store(st32);
2766 break;
2767 #undef gen_narrow_load_store
2769 case 10: /*ADD.Nn*/
2770 gen_window_check3(dc, RRRN_R, RRRN_S, RRRN_T);
2771 tcg_gen_add_i32(cpu_R[RRRN_R], cpu_R[RRRN_S], cpu_R[RRRN_T]);
2772 break;
2774 case 11: /*ADDI.Nn*/
2775 gen_window_check2(dc, RRRN_R, RRRN_S);
2776 tcg_gen_addi_i32(cpu_R[RRRN_R], cpu_R[RRRN_S], RRRN_T ? RRRN_T : -1);
2777 break;
2779 case 12: /*ST2n*/
2780 gen_window_check1(dc, RRRN_S);
2781 if (RRRN_T < 8) { /*MOVI.Nn*/
2782 tcg_gen_movi_i32(cpu_R[RRRN_S],
2783 RRRN_R | (RRRN_T << 4) |
2784 ((RRRN_T & 6) == 6 ? 0xffffff80 : 0));
2785 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2786 TCGCond eq_ne = (RRRN_T & 4) ? TCG_COND_NE : TCG_COND_EQ;
2788 gen_brcondi(dc, eq_ne, cpu_R[RRRN_S], 0,
2789 4 + (RRRN_R | ((RRRN_T & 3) << 4)));
2791 break;
2793 case 13: /*ST3n*/
2794 switch (RRRN_R) {
2795 case 0: /*MOV.Nn*/
2796 gen_window_check2(dc, RRRN_S, RRRN_T);
2797 tcg_gen_mov_i32(cpu_R[RRRN_T], cpu_R[RRRN_S]);
2798 break;
2800 case 15: /*S3*/
2801 switch (RRRN_T) {
2802 case 0: /*RET.Nn*/
2803 gen_jump(dc, cpu_R[0]);
2804 break;
2806 case 1: /*RETW.Nn*/
2807 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER);
2809 TCGv_i32 tmp = tcg_const_i32(dc->pc);
2810 gen_advance_ccount(dc);
2811 gen_helper_retw(tmp, cpu_env, tmp);
2812 gen_jump(dc, tmp);
2813 tcg_temp_free(tmp);
2815 break;
2817 case 2: /*BREAK.Nn*/
2818 HAS_OPTION(XTENSA_OPTION_DEBUG);
2819 if (dc->debug) {
2820 gen_debug_exception(dc, DEBUGCAUSE_BN);
2822 break;
2824 case 3: /*NOP.Nn*/
2825 break;
2827 case 6: /*ILL.Nn*/
2828 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
2829 break;
2831 default: /*reserved*/
2832 RESERVED();
2833 break;
2835 break;
2837 default: /*reserved*/
2838 RESERVED();
2839 break;
2841 break;
2843 default: /*reserved*/
2844 RESERVED();
2845 break;
2848 if (dc->is_jmp == DISAS_NEXT) {
2849 gen_check_loop_end(dc, 0);
2851 dc->pc = dc->next_pc;
2853 return;
2855 invalid_opcode:
2856 qemu_log("INVALID(pc = %08x)\n", dc->pc);
2857 gen_exception_cause(dc, ILLEGAL_INSTRUCTION_CAUSE);
2858 #undef HAS_OPTION
2861 static void check_breakpoint(CPUXtensaState *env, DisasContext *dc)
2863 CPUBreakpoint *bp;
2865 if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) {
2866 QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
2867 if (bp->pc == dc->pc) {
2868 tcg_gen_movi_i32(cpu_pc, dc->pc);
2869 gen_exception(dc, EXCP_DEBUG);
2870 dc->is_jmp = DISAS_UPDATE;
2876 static void gen_ibreak_check(CPUXtensaState *env, DisasContext *dc)
2878 unsigned i;
2880 for (i = 0; i < dc->config->nibreak; ++i) {
2881 if ((env->sregs[IBREAKENABLE] & (1 << i)) &&
2882 env->sregs[IBREAKA + i] == dc->pc) {
2883 gen_debug_exception(dc, DEBUGCAUSE_IB);
2884 break;
2889 static void gen_intermediate_code_internal(
2890 CPUXtensaState *env, TranslationBlock *tb, int search_pc)
2892 DisasContext dc;
2893 int insn_count = 0;
2894 int j, lj = -1;
2895 uint16_t *gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE;
2896 int max_insns = tb->cflags & CF_COUNT_MASK;
2897 uint32_t pc_start = tb->pc;
2898 uint32_t next_page_start =
2899 (pc_start & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
2901 if (max_insns == 0) {
2902 max_insns = CF_COUNT_MASK;
2905 dc.config = env->config;
2906 dc.singlestep_enabled = env->singlestep_enabled;
2907 dc.tb = tb;
2908 dc.pc = pc_start;
2909 dc.ring = tb->flags & XTENSA_TBFLAG_RING_MASK;
2910 dc.cring = (tb->flags & XTENSA_TBFLAG_EXCM) ? 0 : dc.ring;
2911 dc.lbeg = env->sregs[LBEG];
2912 dc.lend = env->sregs[LEND];
2913 dc.is_jmp = DISAS_NEXT;
2914 dc.ccount_delta = 0;
2915 dc.debug = tb->flags & XTENSA_TBFLAG_DEBUG;
2916 dc.icount = tb->flags & XTENSA_TBFLAG_ICOUNT;
2917 dc.cpenable = (tb->flags & XTENSA_TBFLAG_CPENABLE_MASK) >>
2918 XTENSA_TBFLAG_CPENABLE_SHIFT;
2920 init_litbase(&dc);
2921 init_sar_tracker(&dc);
2922 reset_used_window(&dc);
2923 if (dc.icount) {
2924 dc.next_icount = tcg_temp_local_new_i32();
2927 gen_icount_start();
2929 if (env->singlestep_enabled && env->exception_taken) {
2930 env->exception_taken = 0;
2931 tcg_gen_movi_i32(cpu_pc, dc.pc);
2932 gen_exception(&dc, EXCP_DEBUG);
2935 do {
2936 check_breakpoint(env, &dc);
2938 if (search_pc) {
2939 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
2940 if (lj < j) {
2941 lj++;
2942 while (lj < j) {
2943 tcg_ctx.gen_opc_instr_start[lj++] = 0;
2946 tcg_ctx.gen_opc_pc[lj] = dc.pc;
2947 tcg_ctx.gen_opc_instr_start[lj] = 1;
2948 tcg_ctx.gen_opc_icount[lj] = insn_count;
2951 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) {
2952 tcg_gen_debug_insn_start(dc.pc);
2955 ++dc.ccount_delta;
2957 if (insn_count + 1 == max_insns && (tb->cflags & CF_LAST_IO)) {
2958 gen_io_start();
2961 if (dc.icount) {
2962 int label = gen_new_label();
2964 tcg_gen_addi_i32(dc.next_icount, cpu_SR[ICOUNT], 1);
2965 tcg_gen_brcondi_i32(TCG_COND_NE, dc.next_icount, 0, label);
2966 tcg_gen_mov_i32(dc.next_icount, cpu_SR[ICOUNT]);
2967 if (dc.debug) {
2968 gen_debug_exception(&dc, DEBUGCAUSE_IC);
2970 gen_set_label(label);
2973 if (dc.debug) {
2974 gen_ibreak_check(env, &dc);
2977 disas_xtensa_insn(env, &dc);
2978 ++insn_count;
2979 if (dc.icount) {
2980 tcg_gen_mov_i32(cpu_SR[ICOUNT], dc.next_icount);
2982 if (env->singlestep_enabled) {
2983 tcg_gen_movi_i32(cpu_pc, dc.pc);
2984 gen_exception(&dc, EXCP_DEBUG);
2985 break;
2987 } while (dc.is_jmp == DISAS_NEXT &&
2988 insn_count < max_insns &&
2989 dc.pc < next_page_start &&
2990 tcg_ctx.gen_opc_ptr < gen_opc_end);
2992 reset_litbase(&dc);
2993 reset_sar_tracker(&dc);
2994 if (dc.icount) {
2995 tcg_temp_free(dc.next_icount);
2998 if (tb->cflags & CF_LAST_IO) {
2999 gen_io_end();
3002 if (dc.is_jmp == DISAS_NEXT) {
3003 gen_jumpi(&dc, dc.pc, 0);
3005 gen_icount_end(tb, insn_count);
3006 *tcg_ctx.gen_opc_ptr = INDEX_op_end;
3008 if (search_pc) {
3009 j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf;
3010 memset(tcg_ctx.gen_opc_instr_start + lj + 1, 0,
3011 (j - lj) * sizeof(tcg_ctx.gen_opc_instr_start[0]));
3012 } else {
3013 tb->size = dc.pc - pc_start;
3014 tb->icount = insn_count;
3018 void gen_intermediate_code(CPUXtensaState *env, TranslationBlock *tb)
3020 gen_intermediate_code_internal(env, tb, 0);
3023 void gen_intermediate_code_pc(CPUXtensaState *env, TranslationBlock *tb)
3025 gen_intermediate_code_internal(env, tb, 1);
3028 void cpu_dump_state(CPUXtensaState *env, FILE *f, fprintf_function cpu_fprintf,
3029 int flags)
3031 int i, j;
3033 cpu_fprintf(f, "PC=%08x\n\n", env->pc);
3035 for (i = j = 0; i < 256; ++i) {
3036 if (xtensa_option_bits_enabled(env->config, sregnames[i].opt_bits)) {
3037 cpu_fprintf(f, "%12s=%08x%c", sregnames[i].name, env->sregs[i],
3038 (j++ % 4) == 3 ? '\n' : ' ');
3042 cpu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n");
3044 for (i = j = 0; i < 256; ++i) {
3045 if (xtensa_option_bits_enabled(env->config, uregnames[i].opt_bits)) {
3046 cpu_fprintf(f, "%s=%08x%c", uregnames[i].name, env->uregs[i],
3047 (j++ % 4) == 3 ? '\n' : ' ');
3051 cpu_fprintf(f, (j % 4) == 0 ? "\n" : "\n\n");
3053 for (i = 0; i < 16; ++i) {
3054 cpu_fprintf(f, " A%02d=%08x%c", i, env->regs[i],
3055 (i % 4) == 3 ? '\n' : ' ');
3058 cpu_fprintf(f, "\n");
3060 for (i = 0; i < env->config->nareg; ++i) {
3061 cpu_fprintf(f, "AR%02d=%08x%c", i, env->phys_regs[i],
3062 (i % 4) == 3 ? '\n' : ' ');
3065 if (xtensa_option_enabled(env->config, XTENSA_OPTION_FP_COPROCESSOR)) {
3066 cpu_fprintf(f, "\n");
3068 for (i = 0; i < 16; ++i) {
3069 cpu_fprintf(f, "F%02d=%08x (%+10.8e)%c", i,
3070 float32_val(env->fregs[i]),
3071 *(float *)&env->fregs[i], (i % 2) == 1 ? '\n' : ' ');
3076 void restore_state_to_opc(CPUXtensaState *env, TranslationBlock *tb, int pc_pos)
3078 env->pc = tcg_ctx.gen_opc_pc[pc_pos];