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.
31 #include "qemu/osdep.h"
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"
49 typedef struct DisasContext
{
50 const XtensaConfig
*config
;
60 int singlestep_enabled
;
64 bool sar_m32_allocated
;
67 uint32_t ccount_delta
;
77 static TCGv_env cpu_env
;
78 static TCGv_i32 cpu_pc
;
79 static TCGv_i32 cpu_R
[16];
80 static TCGv_i32 cpu_FR
[16];
81 static TCGv_i32 cpu_SR
[256];
82 static TCGv_i32 cpu_UR
[256];
84 #include "exec/gen-icount.h"
86 typedef struct XtensaReg
{
98 #define XTENSA_REG_ACCESS(regname, opt, acc) { \
100 .opt_bits = XTENSA_OPTION_BIT(opt), \
104 #define XTENSA_REG(regname, opt) XTENSA_REG_ACCESS(regname, opt, SR_RWX)
106 #define XTENSA_REG_BITS_ACCESS(regname, opt, acc) { \
112 #define XTENSA_REG_BITS(regname, opt) \
113 XTENSA_REG_BITS_ACCESS(regname, opt, SR_RWX)
115 static const XtensaReg sregnames
[256] = {
116 [LBEG
] = XTENSA_REG("LBEG", XTENSA_OPTION_LOOP
),
117 [LEND
] = XTENSA_REG("LEND", XTENSA_OPTION_LOOP
),
118 [LCOUNT
] = XTENSA_REG("LCOUNT", XTENSA_OPTION_LOOP
),
119 [SAR
] = XTENSA_REG_BITS("SAR", XTENSA_OPTION_ALL
),
120 [BR
] = XTENSA_REG("BR", XTENSA_OPTION_BOOLEAN
),
121 [LITBASE
] = XTENSA_REG("LITBASE", XTENSA_OPTION_EXTENDED_L32R
),
122 [SCOMPARE1
] = XTENSA_REG("SCOMPARE1", XTENSA_OPTION_CONDITIONAL_STORE
),
123 [ACCLO
] = XTENSA_REG("ACCLO", XTENSA_OPTION_MAC16
),
124 [ACCHI
] = XTENSA_REG("ACCHI", XTENSA_OPTION_MAC16
),
125 [MR
] = XTENSA_REG("MR0", XTENSA_OPTION_MAC16
),
126 [MR
+ 1] = XTENSA_REG("MR1", XTENSA_OPTION_MAC16
),
127 [MR
+ 2] = XTENSA_REG("MR2", XTENSA_OPTION_MAC16
),
128 [MR
+ 3] = XTENSA_REG("MR3", XTENSA_OPTION_MAC16
),
129 [WINDOW_BASE
] = XTENSA_REG("WINDOW_BASE", XTENSA_OPTION_WINDOWED_REGISTER
),
130 [WINDOW_START
] = XTENSA_REG("WINDOW_START",
131 XTENSA_OPTION_WINDOWED_REGISTER
),
132 [PTEVADDR
] = XTENSA_REG("PTEVADDR", XTENSA_OPTION_MMU
),
133 [RASID
] = XTENSA_REG("RASID", XTENSA_OPTION_MMU
),
134 [ITLBCFG
] = XTENSA_REG("ITLBCFG", XTENSA_OPTION_MMU
),
135 [DTLBCFG
] = XTENSA_REG("DTLBCFG", XTENSA_OPTION_MMU
),
136 [IBREAKENABLE
] = XTENSA_REG("IBREAKENABLE", XTENSA_OPTION_DEBUG
),
137 [CACHEATTR
] = XTENSA_REG("CACHEATTR", XTENSA_OPTION_CACHEATTR
),
138 [ATOMCTL
] = XTENSA_REG("ATOMCTL", XTENSA_OPTION_ATOMCTL
),
139 [IBREAKA
] = XTENSA_REG("IBREAKA0", XTENSA_OPTION_DEBUG
),
140 [IBREAKA
+ 1] = XTENSA_REG("IBREAKA1", XTENSA_OPTION_DEBUG
),
141 [DBREAKA
] = XTENSA_REG("DBREAKA0", XTENSA_OPTION_DEBUG
),
142 [DBREAKA
+ 1] = XTENSA_REG("DBREAKA1", XTENSA_OPTION_DEBUG
),
143 [DBREAKC
] = XTENSA_REG("DBREAKC0", XTENSA_OPTION_DEBUG
),
144 [DBREAKC
+ 1] = XTENSA_REG("DBREAKC1", XTENSA_OPTION_DEBUG
),
145 [CONFIGID0
] = XTENSA_REG_BITS_ACCESS("CONFIGID0", XTENSA_OPTION_ALL
, SR_R
),
146 [EPC1
] = XTENSA_REG("EPC1", XTENSA_OPTION_EXCEPTION
),
147 [EPC1
+ 1] = XTENSA_REG("EPC2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
148 [EPC1
+ 2] = XTENSA_REG("EPC3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
149 [EPC1
+ 3] = XTENSA_REG("EPC4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
150 [EPC1
+ 4] = XTENSA_REG("EPC5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
151 [EPC1
+ 5] = XTENSA_REG("EPC6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
152 [EPC1
+ 6] = XTENSA_REG("EPC7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
153 [DEPC
] = XTENSA_REG("DEPC", XTENSA_OPTION_EXCEPTION
),
154 [EPS2
] = XTENSA_REG("EPS2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
155 [EPS2
+ 1] = XTENSA_REG("EPS3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
156 [EPS2
+ 2] = XTENSA_REG("EPS4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
157 [EPS2
+ 3] = XTENSA_REG("EPS5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
158 [EPS2
+ 4] = XTENSA_REG("EPS6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
159 [EPS2
+ 5] = XTENSA_REG("EPS7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
160 [CONFIGID1
] = XTENSA_REG_BITS_ACCESS("CONFIGID1", XTENSA_OPTION_ALL
, SR_R
),
161 [EXCSAVE1
] = XTENSA_REG("EXCSAVE1", XTENSA_OPTION_EXCEPTION
),
162 [EXCSAVE1
+ 1] = XTENSA_REG("EXCSAVE2",
163 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
164 [EXCSAVE1
+ 2] = XTENSA_REG("EXCSAVE3",
165 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
166 [EXCSAVE1
+ 3] = XTENSA_REG("EXCSAVE4",
167 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
168 [EXCSAVE1
+ 4] = XTENSA_REG("EXCSAVE5",
169 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
170 [EXCSAVE1
+ 5] = XTENSA_REG("EXCSAVE6",
171 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
172 [EXCSAVE1
+ 6] = XTENSA_REG("EXCSAVE7",
173 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
174 [CPENABLE
] = XTENSA_REG("CPENABLE", XTENSA_OPTION_COPROCESSOR
),
175 [INTSET
] = XTENSA_REG_ACCESS("INTSET", XTENSA_OPTION_INTERRUPT
, SR_RW
),
176 [INTCLEAR
] = XTENSA_REG_ACCESS("INTCLEAR", XTENSA_OPTION_INTERRUPT
, SR_W
),
177 [INTENABLE
] = XTENSA_REG("INTENABLE", XTENSA_OPTION_INTERRUPT
),
178 [PS
] = XTENSA_REG_BITS("PS", XTENSA_OPTION_ALL
),
179 [VECBASE
] = XTENSA_REG("VECBASE", XTENSA_OPTION_RELOCATABLE_VECTOR
),
180 [EXCCAUSE
] = XTENSA_REG("EXCCAUSE", XTENSA_OPTION_EXCEPTION
),
181 [DEBUGCAUSE
] = XTENSA_REG_ACCESS("DEBUGCAUSE", XTENSA_OPTION_DEBUG
, SR_R
),
182 [CCOUNT
] = XTENSA_REG("CCOUNT", XTENSA_OPTION_TIMER_INTERRUPT
),
183 [PRID
] = XTENSA_REG_ACCESS("PRID", XTENSA_OPTION_PROCESSOR_ID
, SR_R
),
184 [ICOUNT
] = XTENSA_REG("ICOUNT", XTENSA_OPTION_DEBUG
),
185 [ICOUNTLEVEL
] = XTENSA_REG("ICOUNTLEVEL", XTENSA_OPTION_DEBUG
),
186 [EXCVADDR
] = XTENSA_REG("EXCVADDR", XTENSA_OPTION_EXCEPTION
),
187 [CCOMPARE
] = XTENSA_REG("CCOMPARE0", XTENSA_OPTION_TIMER_INTERRUPT
),
188 [CCOMPARE
+ 1] = XTENSA_REG("CCOMPARE1",
189 XTENSA_OPTION_TIMER_INTERRUPT
),
190 [CCOMPARE
+ 2] = XTENSA_REG("CCOMPARE2",
191 XTENSA_OPTION_TIMER_INTERRUPT
),
192 [MISC
] = XTENSA_REG("MISC0", XTENSA_OPTION_MISC_SR
),
193 [MISC
+ 1] = XTENSA_REG("MISC1", XTENSA_OPTION_MISC_SR
),
194 [MISC
+ 2] = XTENSA_REG("MISC2", XTENSA_OPTION_MISC_SR
),
195 [MISC
+ 3] = XTENSA_REG("MISC3", XTENSA_OPTION_MISC_SR
),
198 static const XtensaReg uregnames
[256] = {
199 [THREADPTR
] = XTENSA_REG("THREADPTR", XTENSA_OPTION_THREAD_POINTER
),
200 [FCR
] = XTENSA_REG("FCR", XTENSA_OPTION_FP_COPROCESSOR
),
201 [FSR
] = XTENSA_REG("FSR", XTENSA_OPTION_FP_COPROCESSOR
),
204 void xtensa_translate_init(void)
206 static const char * const regnames
[] = {
207 "ar0", "ar1", "ar2", "ar3",
208 "ar4", "ar5", "ar6", "ar7",
209 "ar8", "ar9", "ar10", "ar11",
210 "ar12", "ar13", "ar14", "ar15",
212 static const char * const fregnames
[] = {
213 "f0", "f1", "f2", "f3",
214 "f4", "f5", "f6", "f7",
215 "f8", "f9", "f10", "f11",
216 "f12", "f13", "f14", "f15",
220 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
221 cpu_pc
= tcg_global_mem_new_i32(cpu_env
,
222 offsetof(CPUXtensaState
, pc
), "pc");
224 for (i
= 0; i
< 16; i
++) {
225 cpu_R
[i
] = tcg_global_mem_new_i32(cpu_env
,
226 offsetof(CPUXtensaState
, regs
[i
]),
230 for (i
= 0; i
< 16; i
++) {
231 cpu_FR
[i
] = tcg_global_mem_new_i32(cpu_env
,
232 offsetof(CPUXtensaState
, fregs
[i
].f32
[FP_F32_LOW
]),
236 for (i
= 0; i
< 256; ++i
) {
237 if (sregnames
[i
].name
) {
238 cpu_SR
[i
] = tcg_global_mem_new_i32(cpu_env
,
239 offsetof(CPUXtensaState
, sregs
[i
]),
244 for (i
= 0; i
< 256; ++i
) {
245 if (uregnames
[i
].name
) {
246 cpu_UR
[i
] = tcg_global_mem_new_i32(cpu_env
,
247 offsetof(CPUXtensaState
, uregs
[i
]),
253 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
255 return xtensa_option_bits_enabled(dc
->config
, opt
);
258 static inline bool option_enabled(DisasContext
*dc
, int opt
)
260 return xtensa_option_enabled(dc
->config
, opt
);
263 static void init_litbase(DisasContext
*dc
)
265 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
266 dc
->litbase
= tcg_temp_local_new_i32();
267 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
271 static void reset_litbase(DisasContext
*dc
)
273 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
274 tcg_temp_free(dc
->litbase
);
278 static void init_sar_tracker(DisasContext
*dc
)
280 dc
->sar_5bit
= false;
281 dc
->sar_m32_5bit
= false;
282 dc
->sar_m32_allocated
= false;
285 static void reset_sar_tracker(DisasContext
*dc
)
287 if (dc
->sar_m32_allocated
) {
288 tcg_temp_free(dc
->sar_m32
);
292 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
294 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
295 if (dc
->sar_m32_5bit
) {
296 tcg_gen_discard_i32(dc
->sar_m32
);
299 dc
->sar_m32_5bit
= false;
302 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
304 TCGv_i32 tmp
= tcg_const_i32(32);
305 if (!dc
->sar_m32_allocated
) {
306 dc
->sar_m32
= tcg_temp_local_new_i32();
307 dc
->sar_m32_allocated
= true;
309 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
310 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
311 dc
->sar_5bit
= false;
312 dc
->sar_m32_5bit
= true;
316 static void gen_advance_ccount(DisasContext
*dc
)
318 if (dc
->ccount_delta
> 0) {
319 TCGv_i32 tmp
= tcg_const_i32(dc
->ccount_delta
);
320 gen_helper_advance_ccount(cpu_env
, tmp
);
323 dc
->ccount_delta
= 0;
326 static void gen_exception(DisasContext
*dc
, int excp
)
328 TCGv_i32 tmp
= tcg_const_i32(excp
);
329 gen_advance_ccount(dc
);
330 gen_helper_exception(cpu_env
, tmp
);
334 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
336 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
337 TCGv_i32 tcause
= tcg_const_i32(cause
);
338 gen_advance_ccount(dc
);
339 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
341 tcg_temp_free(tcause
);
342 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
343 cause
== SYSCALL_CAUSE
) {
344 dc
->is_jmp
= DISAS_UPDATE
;
348 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
351 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
352 TCGv_i32 tcause
= tcg_const_i32(cause
);
353 gen_advance_ccount(dc
);
354 gen_helper_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
356 tcg_temp_free(tcause
);
359 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
361 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
362 TCGv_i32 tcause
= tcg_const_i32(cause
);
363 gen_advance_ccount(dc
);
364 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
366 tcg_temp_free(tcause
);
367 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
368 dc
->is_jmp
= DISAS_UPDATE
;
372 static bool gen_check_privilege(DisasContext
*dc
)
375 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
376 dc
->is_jmp
= DISAS_UPDATE
;
382 static bool gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
384 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
385 !(dc
->cpenable
& (1 << cp
))) {
386 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
387 dc
->is_jmp
= DISAS_UPDATE
;
393 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
395 tcg_gen_mov_i32(cpu_pc
, dest
);
396 gen_advance_ccount(dc
);
398 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
->next_icount
);
400 if (dc
->singlestep_enabled
) {
401 gen_exception(dc
, EXCP_DEBUG
);
404 tcg_gen_goto_tb(slot
);
405 tcg_gen_exit_tb((uintptr_t)dc
->tb
+ slot
);
410 dc
->is_jmp
= DISAS_UPDATE
;
413 static void gen_jump(DisasContext
*dc
, TCGv dest
)
415 gen_jump_slot(dc
, dest
, -1);
418 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
420 TCGv_i32 tmp
= tcg_const_i32(dest
);
421 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
424 gen_jump_slot(dc
, tmp
, slot
);
428 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
431 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
433 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
434 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
435 tcg_temp_free(tcallinc
);
436 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
437 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
438 gen_jump_slot(dc
, dest
, slot
);
441 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
443 gen_callw_slot(dc
, callinc
, dest
, -1);
446 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
448 TCGv_i32 tmp
= tcg_const_i32(dest
);
449 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
452 gen_callw_slot(dc
, callinc
, tmp
, slot
);
456 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
458 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
459 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
460 dc
->next_pc
== dc
->lend
) {
461 TCGLabel
*label
= gen_new_label();
463 gen_advance_ccount(dc
);
464 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
465 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
466 gen_jumpi(dc
, dc
->lbeg
, slot
);
467 gen_set_label(label
);
468 gen_jumpi(dc
, dc
->next_pc
, -1);
474 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
476 if (!gen_check_loop_end(dc
, slot
)) {
477 gen_jumpi(dc
, dc
->next_pc
, slot
);
481 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
482 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
484 TCGLabel
*label
= gen_new_label();
486 gen_advance_ccount(dc
);
487 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
488 gen_jumpi_check_loop_end(dc
, 0);
489 gen_set_label(label
);
490 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
493 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
494 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
496 TCGv_i32 tmp
= tcg_const_i32(t1
);
497 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
501 static bool gen_check_sr(DisasContext
*dc
, uint32_t sr
, unsigned access
)
503 if (!xtensa_option_bits_enabled(dc
->config
, sregnames
[sr
].opt_bits
)) {
504 if (sregnames
[sr
].name
) {
505 qemu_log_mask(LOG_GUEST_ERROR
, "SR %s is not configured\n", sregnames
[sr
].name
);
507 qemu_log_mask(LOG_UNIMP
, "SR %d is not implemented\n", sr
);
509 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
511 } else if (!(sregnames
[sr
].access
& access
)) {
512 static const char * const access_text
[] = {
517 assert(access
< ARRAY_SIZE(access_text
) && access_text
[access
]);
518 qemu_log_mask(LOG_GUEST_ERROR
, "SR %s is not available for %s\n", sregnames
[sr
].name
,
519 access_text
[access
]);
520 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
526 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
528 gen_advance_ccount(dc
);
529 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
532 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
534 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
535 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
536 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
539 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
541 static void (* const rsr_handler
[256])(DisasContext
*dc
,
542 TCGv_i32 d
, uint32_t sr
) = {
543 [CCOUNT
] = gen_rsr_ccount
,
544 [PTEVADDR
] = gen_rsr_ptevaddr
,
547 if (rsr_handler
[sr
]) {
548 rsr_handler
[sr
](dc
, d
, sr
);
550 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
554 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
556 gen_helper_wsr_lbeg(cpu_env
, s
);
557 gen_jumpi_check_loop_end(dc
, 0);
560 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
562 gen_helper_wsr_lend(cpu_env
, s
);
563 gen_jumpi_check_loop_end(dc
, 0);
566 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
568 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
569 if (dc
->sar_m32_5bit
) {
570 tcg_gen_discard_i32(dc
->sar_m32
);
572 dc
->sar_5bit
= false;
573 dc
->sar_m32_5bit
= false;
576 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
578 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
581 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
583 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
584 /* This can change tb->flags, so exit tb */
585 gen_jumpi_check_loop_end(dc
, -1);
588 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
590 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
593 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
595 gen_helper_wsr_windowbase(cpu_env
, v
);
596 /* This can change tb->flags, so exit tb */
597 gen_jumpi_check_loop_end(dc
, -1);
600 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
602 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
603 /* This can change tb->flags, so exit tb */
604 gen_jumpi_check_loop_end(dc
, -1);
607 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
609 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
612 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
614 gen_helper_wsr_rasid(cpu_env
, v
);
615 /* This can change tb->flags, so exit tb */
616 gen_jumpi_check_loop_end(dc
, -1);
619 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
621 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
624 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
626 gen_helper_wsr_ibreakenable(cpu_env
, v
);
627 gen_jumpi_check_loop_end(dc
, 0);
630 static void gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
632 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
635 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
637 unsigned id
= sr
- IBREAKA
;
639 if (id
< dc
->config
->nibreak
) {
640 TCGv_i32 tmp
= tcg_const_i32(id
);
641 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
643 gen_jumpi_check_loop_end(dc
, 0);
647 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
649 unsigned id
= sr
- DBREAKA
;
651 if (id
< dc
->config
->ndbreak
) {
652 TCGv_i32 tmp
= tcg_const_i32(id
);
653 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
658 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
660 unsigned id
= sr
- DBREAKC
;
662 if (id
< dc
->config
->ndbreak
) {
663 TCGv_i32 tmp
= tcg_const_i32(id
);
664 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
669 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
671 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
672 /* This can change tb->flags, so exit tb */
673 gen_jumpi_check_loop_end(dc
, -1);
676 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
678 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
679 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
680 gen_helper_check_interrupts(cpu_env
);
681 gen_jumpi_check_loop_end(dc
, 0);
684 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
686 TCGv_i32 tmp
= tcg_temp_new_i32();
688 tcg_gen_andi_i32(tmp
, v
,
689 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
690 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
691 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
692 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
694 gen_helper_check_interrupts(cpu_env
);
697 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
699 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
700 gen_helper_check_interrupts(cpu_env
);
701 gen_jumpi_check_loop_end(dc
, 0);
704 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
706 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
707 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
709 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
712 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
713 gen_helper_check_interrupts(cpu_env
);
714 /* This can change mmu index and tb->flags, so exit tb */
715 gen_jumpi_check_loop_end(dc
, -1);
718 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
721 tcg_gen_mov_i32(dc
->next_icount
, v
);
723 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
727 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
729 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
730 /* This can change tb->flags, so exit tb */
731 gen_jumpi_check_loop_end(dc
, -1);
734 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
736 uint32_t id
= sr
- CCOMPARE
;
737 if (id
< dc
->config
->nccompare
) {
738 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
739 gen_advance_ccount(dc
);
740 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
741 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
742 gen_helper_check_interrupts(cpu_env
);
746 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
748 static void (* const wsr_handler
[256])(DisasContext
*dc
,
749 uint32_t sr
, TCGv_i32 v
) = {
750 [LBEG
] = gen_wsr_lbeg
,
751 [LEND
] = gen_wsr_lend
,
754 [LITBASE
] = gen_wsr_litbase
,
755 [ACCHI
] = gen_wsr_acchi
,
756 [WINDOW_BASE
] = gen_wsr_windowbase
,
757 [WINDOW_START
] = gen_wsr_windowstart
,
758 [PTEVADDR
] = gen_wsr_ptevaddr
,
759 [RASID
] = gen_wsr_rasid
,
760 [ITLBCFG
] = gen_wsr_tlbcfg
,
761 [DTLBCFG
] = gen_wsr_tlbcfg
,
762 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
763 [ATOMCTL
] = gen_wsr_atomctl
,
764 [IBREAKA
] = gen_wsr_ibreaka
,
765 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
766 [DBREAKA
] = gen_wsr_dbreaka
,
767 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
768 [DBREAKC
] = gen_wsr_dbreakc
,
769 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
770 [CPENABLE
] = gen_wsr_cpenable
,
771 [INTSET
] = gen_wsr_intset
,
772 [INTCLEAR
] = gen_wsr_intclear
,
773 [INTENABLE
] = gen_wsr_intenable
,
775 [ICOUNT
] = gen_wsr_icount
,
776 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
777 [CCOMPARE
] = gen_wsr_ccompare
,
778 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
779 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
782 if (wsr_handler
[sr
]) {
783 wsr_handler
[sr
](dc
, sr
, s
);
785 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
789 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
793 gen_helper_wur_fcr(cpu_env
, s
);
797 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
801 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
806 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
807 TCGv_i32 addr
, bool no_hw_alignment
)
809 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
810 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
811 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
813 TCGLabel
*label
= gen_new_label();
814 TCGv_i32 tmp
= tcg_temp_new_i32();
815 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
816 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
817 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
818 gen_set_label(label
);
823 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
825 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
826 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
827 gen_advance_ccount(dc
);
828 gen_helper_waiti(cpu_env
, pc
, intlevel
);
830 tcg_temp_free(intlevel
);
833 static bool gen_window_check1(DisasContext
*dc
, unsigned r1
)
835 if (r1
/ 4 > dc
->window
) {
836 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
837 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
839 gen_advance_ccount(dc
);
840 gen_helper_window_check(cpu_env
, pc
, w
);
841 dc
->is_jmp
= DISAS_UPDATE
;
847 static bool gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
849 return gen_window_check1(dc
, r1
> r2
? r1
: r2
);
852 static bool gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
855 return gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
858 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
860 TCGv_i32 m
= tcg_temp_new_i32();
863 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
865 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
870 static inline unsigned xtensa_op0_insn_len(unsigned op0
)
872 return op0
>= 8 ? 2 : 3;
875 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
877 #define HAS_OPTION_BITS(opt) do { \
878 if (!option_bits_enabled(dc, opt)) { \
879 qemu_log_mask(LOG_GUEST_ERROR, "Option is not enabled %s:%d\n", \
880 __FILE__, __LINE__); \
881 goto invalid_opcode; \
885 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
887 #define TBD() qemu_log_mask(LOG_UNIMP, "TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
888 #define RESERVED() do { \
889 qemu_log_mask(LOG_GUEST_ERROR, "RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
890 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
891 goto invalid_opcode; \
895 #ifdef TARGET_WORDS_BIGENDIAN
896 #define OP0 (((b0) & 0xf0) >> 4)
897 #define OP1 (((b2) & 0xf0) >> 4)
898 #define OP2 ((b2) & 0xf)
899 #define RRR_R ((b1) & 0xf)
900 #define RRR_S (((b1) & 0xf0) >> 4)
901 #define RRR_T ((b0) & 0xf)
903 #define OP0 (((b0) & 0xf))
904 #define OP1 (((b2) & 0xf))
905 #define OP2 (((b2) & 0xf0) >> 4)
906 #define RRR_R (((b1) & 0xf0) >> 4)
907 #define RRR_S (((b1) & 0xf))
908 #define RRR_T (((b0) & 0xf0) >> 4)
910 #define RRR_X ((RRR_R & 0x4) >> 2)
911 #define RRR_Y ((RRR_T & 0x4) >> 2)
912 #define RRR_W (RRR_R & 0x3)
921 #ifdef TARGET_WORDS_BIGENDIAN
922 #define RRI4_IMM4 ((b2) & 0xf)
924 #define RRI4_IMM4 (((b2) & 0xf0) >> 4)
930 #define RRI8_IMM8 (b2)
931 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
933 #ifdef TARGET_WORDS_BIGENDIAN
934 #define RI16_IMM16 (((b1) << 8) | (b2))
936 #define RI16_IMM16 (((b2) << 8) | (b1))
939 #ifdef TARGET_WORDS_BIGENDIAN
940 #define CALL_N (((b0) & 0xc) >> 2)
941 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
943 #define CALL_N (((b0) & 0x30) >> 4)
944 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
946 #define CALL_OFFSET_SE \
947 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
949 #define CALLX_N CALL_N
950 #ifdef TARGET_WORDS_BIGENDIAN
951 #define CALLX_M ((b0) & 0x3)
953 #define CALLX_M (((b0) & 0xc0) >> 6)
955 #define CALLX_S RRR_S
957 #define BRI12_M CALLX_M
958 #define BRI12_S RRR_S
959 #ifdef TARGET_WORDS_BIGENDIAN
960 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
962 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
964 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
966 #define BRI8_M BRI12_M
967 #define BRI8_R RRI8_R
968 #define BRI8_S RRI8_S
969 #define BRI8_IMM8 RRI8_IMM8
970 #define BRI8_IMM8_SE RRI8_IMM8_SE
974 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
975 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
977 unsigned len
= xtensa_op0_insn_len(OP0
);
979 static const uint32_t B4CONST
[] = {
980 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
983 static const uint32_t B4CONSTU
[] = {
984 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
989 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
993 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
999 dc
->next_pc
= dc
->pc
+ len
;
1007 if ((RRR_R
& 0xc) == 0x8) {
1008 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1015 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1018 case 1: /*reserved*/
1026 if (gen_window_check1(dc
, CALLX_S
)) {
1027 gen_jump(dc
, cpu_R
[CALLX_S
]);
1032 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1034 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1035 gen_advance_ccount(dc
);
1036 gen_helper_retw(tmp
, cpu_env
, tmp
);
1042 case 3: /*reserved*/
1049 if (!gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2)) {
1055 TCGv_i32 tmp
= tcg_temp_new_i32();
1056 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1057 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1065 case 3: /*CALLX12w*/
1066 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1068 TCGv_i32 tmp
= tcg_temp_new_i32();
1070 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1071 gen_callw(dc
, CALLX_N
, tmp
);
1081 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1082 if (gen_window_check2(dc
, RRR_T
, RRR_S
)) {
1083 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1084 gen_advance_ccount(dc
);
1085 gen_helper_movsp(cpu_env
, pc
);
1086 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1106 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1118 default: /*reserved*/
1127 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1130 if (gen_check_privilege(dc
)) {
1131 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1132 gen_helper_check_interrupts(cpu_env
);
1133 gen_jump(dc
, cpu_SR
[EPC1
]);
1142 if (gen_check_privilege(dc
)) {
1143 gen_jump(dc
, cpu_SR
[
1144 dc
->config
->ndepc
? DEPC
: EPC1
]);
1150 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1151 if (gen_check_privilege(dc
)) {
1152 TCGv_i32 tmp
= tcg_const_i32(1);
1155 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1156 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1159 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1160 cpu_SR
[WINDOW_START
], tmp
);
1162 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1163 cpu_SR
[WINDOW_START
], tmp
);
1166 gen_helper_restore_owb(cpu_env
);
1167 gen_helper_check_interrupts(cpu_env
);
1168 gen_jump(dc
, cpu_SR
[EPC1
]);
1174 default: /*reserved*/
1181 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1182 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1183 if (gen_check_privilege(dc
)) {
1184 tcg_gen_mov_i32(cpu_SR
[PS
],
1185 cpu_SR
[EPS2
+ RRR_S
- 2]);
1186 gen_helper_check_interrupts(cpu_env
);
1187 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1190 qemu_log_mask(LOG_GUEST_ERROR
, "RFI %d is illegal\n", RRR_S
);
1191 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1199 default: /*reserved*/
1207 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1209 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1213 case 5: /*SYSCALLx*/
1214 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1216 case 0: /*SYSCALLx*/
1217 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1221 if (semihosting_enabled()) {
1222 if (gen_check_privilege(dc
)) {
1223 gen_helper_simcall(cpu_env
);
1226 qemu_log_mask(LOG_GUEST_ERROR
, "SIMCALL but semihosting is disabled\n");
1227 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1238 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1239 if (gen_check_privilege(dc
) &&
1240 gen_window_check1(dc
, RRR_T
)) {
1241 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1242 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1243 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1244 gen_helper_check_interrupts(cpu_env
);
1245 gen_jumpi_check_loop_end(dc
, 0);
1250 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1251 if (gen_check_privilege(dc
)) {
1252 gen_waiti(dc
, RRR_S
);
1260 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1262 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1263 TCGv_i32 mask
= tcg_const_i32(
1264 ((1 << shift
) - 1) << RRR_S
);
1265 TCGv_i32 tmp
= tcg_temp_new_i32();
1267 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1268 if (RRR_R
& 1) { /*ALL*/
1269 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1271 tcg_gen_add_i32(tmp
, tmp
, mask
);
1273 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1274 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1276 tcg_temp_free(mask
);
1281 default: /*reserved*/
1289 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1290 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1295 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1296 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1301 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1302 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1309 if (gen_window_check1(dc
, RRR_S
)) {
1310 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1315 if (gen_window_check1(dc
, RRR_S
)) {
1316 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1321 if (gen_window_check1(dc
, RRR_S
)) {
1322 TCGv_i32 tmp
= tcg_temp_new_i32();
1323 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1324 gen_right_shift_sar(dc
, tmp
);
1330 if (gen_window_check1(dc
, RRR_S
)) {
1331 TCGv_i32 tmp
= tcg_temp_new_i32();
1332 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1333 gen_left_shift_sar(dc
, tmp
);
1340 TCGv_i32 tmp
= tcg_const_i32(
1341 RRR_S
| ((RRR_T
& 1) << 4));
1342 gen_right_shift_sar(dc
, tmp
);
1356 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1357 if (gen_check_privilege(dc
)) {
1358 TCGv_i32 tmp
= tcg_const_i32(
1359 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1360 gen_helper_rotw(cpu_env
, tmp
);
1362 /* This can change tb->flags, so exit tb */
1363 gen_jumpi_check_loop_end(dc
, -1);
1368 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1369 if (gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1370 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1375 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1376 if (gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1377 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1381 default: /*reserved*/
1389 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1390 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1391 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1392 if (gen_check_privilege(dc
) &&
1393 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1394 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1396 switch (RRR_R
& 7) {
1397 case 3: /*RITLB0*/ /*RDTLB0*/
1398 gen_helper_rtlb0(cpu_R
[RRR_T
],
1399 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1402 case 4: /*IITLB*/ /*IDTLB*/
1403 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1404 /* This could change memory mapping, so exit tb */
1405 gen_jumpi_check_loop_end(dc
, -1);
1408 case 5: /*PITLB*/ /*PDTLB*/
1409 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1410 gen_helper_ptlb(cpu_R
[RRR_T
],
1411 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1414 case 6: /*WITLB*/ /*WDTLB*/
1416 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1417 /* This could change memory mapping, so exit tb */
1418 gen_jumpi_check_loop_end(dc
, -1);
1421 case 7: /*RITLB1*/ /*RDTLB1*/
1422 gen_helper_rtlb1(cpu_R
[RRR_T
],
1423 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1427 tcg_temp_free(dtlb
);
1431 tcg_temp_free(dtlb
);
1436 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1441 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1446 TCGv_i32 zero
= tcg_const_i32(0);
1447 TCGv_i32 neg
= tcg_temp_new_i32();
1449 tcg_gen_neg_i32(neg
, cpu_R
[RRR_T
]);
1450 tcg_gen_movcond_i32(TCG_COND_GE
, cpu_R
[RRR_R
],
1451 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_T
], neg
);
1453 tcg_temp_free(zero
);
1457 default: /*reserved*/
1463 case 7: /*reserved*/
1468 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1469 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1476 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1477 TCGv_i32 tmp
= tcg_temp_new_i32();
1478 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1479 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1485 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1486 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1493 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1494 TCGv_i32 tmp
= tcg_temp_new_i32();
1495 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1496 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1507 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1508 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1509 32 - (RRR_T
| ((OP2
& 1) << 4)));
1515 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1516 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1517 RRR_S
| ((OP2
& 1) << 4));
1522 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1523 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1528 if (gen_check_sr(dc
, RSR_SR
, SR_X
) &&
1529 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1530 gen_window_check1(dc
, RRR_T
)) {
1531 TCGv_i32 tmp
= tcg_temp_new_i32();
1533 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1534 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1535 gen_wsr(dc
, RSR_SR
, tmp
);
1541 * Note: 64 bit ops are used here solely because SAR values
1544 #define gen_shift_reg(cmd, reg) do { \
1545 TCGv_i64 tmp = tcg_temp_new_i64(); \
1546 tcg_gen_extu_i32_i64(tmp, reg); \
1547 tcg_gen_##cmd##_i64(v, v, tmp); \
1548 tcg_gen_extrl_i64_i32(cpu_R[RRR_R], v); \
1549 tcg_temp_free_i64(v); \
1550 tcg_temp_free_i64(tmp); \
1553 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1556 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1557 TCGv_i64 v
= tcg_temp_new_i64();
1558 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1564 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1568 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1570 TCGv_i64 v
= tcg_temp_new_i64();
1571 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1577 if (!gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1580 if (dc
->sar_m32_5bit
) {
1581 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1583 TCGv_i64 v
= tcg_temp_new_i64();
1584 TCGv_i32 s
= tcg_const_i32(32);
1585 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1586 tcg_gen_andi_i32(s
, s
, 0x3f);
1587 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1588 gen_shift_reg(shl
, s
);
1594 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1598 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1600 TCGv_i64 v
= tcg_temp_new_i64();
1601 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1606 #undef gen_shift_reg
1609 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1610 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1611 TCGv_i32 v1
= tcg_temp_new_i32();
1612 TCGv_i32 v2
= tcg_temp_new_i32();
1613 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1614 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1615 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1622 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1623 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1624 TCGv_i32 v1
= tcg_temp_new_i32();
1625 TCGv_i32 v2
= tcg_temp_new_i32();
1626 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1627 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1628 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1634 default: /*reserved*/
1641 if (OP2
>= 8 && !gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1646 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1647 TCGLabel
*label
= gen_new_label();
1648 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1649 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1650 gen_set_label(label
);
1654 #define BOOLEAN_LOGIC(fn, r, s, t) \
1656 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1657 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1658 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1660 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1661 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1662 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1663 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1664 tcg_temp_free(tmp1); \
1665 tcg_temp_free(tmp2); \
1669 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1673 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1677 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1681 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1685 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1688 #undef BOOLEAN_LOGIC
1691 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1692 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1697 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1699 TCGv lo
= tcg_temp_new();
1702 tcg_gen_mulu2_i32(lo
, cpu_R
[RRR_R
],
1703 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1705 tcg_gen_muls2_i32(lo
, cpu_R
[RRR_R
],
1706 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1713 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1719 TCGLabel
*label1
= gen_new_label();
1720 TCGLabel
*label2
= gen_new_label();
1722 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1724 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1726 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1727 OP2
== 13 ? 0x80000000 : 0);
1729 gen_set_label(label1
);
1731 tcg_gen_div_i32(cpu_R
[RRR_R
],
1732 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1734 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1735 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1737 gen_set_label(label2
);
1742 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1745 default: /*reserved*/
1754 if (gen_check_sr(dc
, RSR_SR
, SR_R
) &&
1755 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1756 gen_window_check1(dc
, RRR_T
)) {
1757 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1762 if (gen_check_sr(dc
, RSR_SR
, SR_W
) &&
1763 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1764 gen_window_check1(dc
, RRR_T
)) {
1765 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1770 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1771 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1772 int shift
= 24 - RRR_T
;
1775 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1776 } else if (shift
== 16) {
1777 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1779 TCGv_i32 tmp
= tcg_temp_new_i32();
1780 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1781 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1788 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1789 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1790 TCGv_i32 tmp1
= tcg_temp_new_i32();
1791 TCGv_i32 tmp2
= tcg_temp_new_i32();
1792 TCGv_i32 zero
= tcg_const_i32(0);
1794 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1795 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1796 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1798 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1799 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1801 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1802 cpu_R
[RRR_S
], tmp1
);
1803 tcg_temp_free(tmp1
);
1804 tcg_temp_free(tmp2
);
1805 tcg_temp_free(zero
);
1813 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1814 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1815 static const TCGCond cond
[] = {
1821 tcg_gen_movcond_i32(cond
[OP2
- 4], cpu_R
[RRR_R
],
1822 cpu_R
[RRR_S
], cpu_R
[RRR_T
],
1823 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1831 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1832 static const TCGCond cond
[] = {
1838 TCGv_i32 zero
= tcg_const_i32(0);
1840 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1841 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1842 tcg_temp_free(zero
);
1848 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1849 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1850 TCGv_i32 zero
= tcg_const_i32(0);
1851 TCGv_i32 tmp
= tcg_temp_new_i32();
1853 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1854 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1855 cpu_R
[RRR_R
], tmp
, zero
,
1856 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1859 tcg_temp_free(zero
);
1864 if (gen_window_check1(dc
, RRR_R
)) {
1865 int st
= (RRR_S
<< 4) + RRR_T
;
1866 if (uregnames
[st
].name
) {
1867 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1869 qemu_log_mask(LOG_UNIMP
, "RUR %d not implemented, ", st
);
1876 if (gen_window_check1(dc
, RRR_T
)) {
1877 if (uregnames
[RSR_SR
].name
) {
1878 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1880 qemu_log_mask(LOG_UNIMP
, "WUR %d not implemented, ", RSR_SR
);
1891 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1892 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1893 int maskimm
= (1 << (OP2
+ 1)) - 1;
1895 TCGv_i32 tmp
= tcg_temp_new_i32();
1896 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1897 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1916 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1917 if (gen_window_check2(dc
, RRR_S
, RRR_T
) &&
1918 gen_check_cpenable(dc
, 0)) {
1919 TCGv_i32 addr
= tcg_temp_new_i32();
1920 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1921 gen_load_store_alignment(dc
, 2, addr
, false);
1923 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1925 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1928 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1930 tcg_temp_free(addr
);
1934 default: /*reserved*/
1941 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1946 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1947 if (gen_check_privilege(dc
) &&
1948 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1949 TCGv_i32 addr
= tcg_temp_new_i32();
1950 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1951 (0xffffffc0 | (RRR_R
<< 2)));
1952 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1953 tcg_temp_free(addr
);
1958 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1959 if (gen_check_privilege(dc
) &&
1960 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1961 TCGv_i32 addr
= tcg_temp_new_i32();
1962 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1963 (0xffffffc0 | (RRR_R
<< 2)));
1964 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1965 tcg_temp_free(addr
);
1970 if (gen_window_check2(dc
, RRI4_S
, RRI4_T
)) {
1971 TCGv_i32 addr
= tcg_temp_new_i32();
1973 tcg_gen_addi_i32(addr
, cpu_R
[RRI4_S
], RRI4_IMM4
<< 2);
1974 gen_load_store_alignment(dc
, 2, addr
, false);
1975 tcg_gen_qemu_st32(cpu_R
[RRI4_T
], addr
, dc
->cring
);
1976 tcg_temp_free(addr
);
1988 if (option_enabled(dc
, XTENSA_OPTION_DEPBITS
)) {
1989 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1992 tcg_gen_deposit_i32(cpu_R
[RRR_T
], cpu_R
[RRR_T
], cpu_R
[RRR_S
],
1997 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2000 if (gen_check_cpenable(dc
, 0)) {
2001 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
2002 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2007 if (gen_check_cpenable(dc
, 0)) {
2008 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
2009 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2014 if (gen_check_cpenable(dc
, 0)) {
2015 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
2016 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2021 if (gen_check_cpenable(dc
, 0)) {
2022 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
2023 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2029 if (gen_check_cpenable(dc
, 0)) {
2030 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
2031 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2036 case 8: /*ROUND.Sf*/
2037 case 9: /*TRUNC.Sf*/
2038 case 10: /*FLOOR.Sf*/
2039 case 11: /*CEIL.Sf*/
2040 case 14: /*UTRUNC.Sf*/
2041 if (gen_window_check1(dc
, RRR_R
) &&
2042 gen_check_cpenable(dc
, 0)) {
2043 static const unsigned rounding_mode_const
[] = {
2044 float_round_nearest_even
,
2045 float_round_to_zero
,
2048 [6] = float_round_to_zero
,
2050 TCGv_i32 rounding_mode
= tcg_const_i32(
2051 rounding_mode_const
[OP2
& 7]);
2052 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2055 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2056 rounding_mode
, scale
);
2058 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2059 rounding_mode
, scale
);
2062 tcg_temp_free(rounding_mode
);
2063 tcg_temp_free(scale
);
2067 case 12: /*FLOAT.Sf*/
2068 case 13: /*UFLOAT.Sf*/
2069 if (gen_window_check1(dc
, RRR_S
) &&
2070 gen_check_cpenable(dc
, 0)) {
2071 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2074 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2075 cpu_R
[RRR_S
], scale
);
2077 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2078 cpu_R
[RRR_S
], scale
);
2080 tcg_temp_free(scale
);
2087 if (gen_check_cpenable(dc
, 0)) {
2088 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2093 if (gen_check_cpenable(dc
, 0)) {
2094 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2099 if (gen_window_check1(dc
, RRR_R
) &&
2100 gen_check_cpenable(dc
, 0)) {
2101 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2106 if (gen_window_check1(dc
, RRR_S
) &&
2107 gen_check_cpenable(dc
, 0)) {
2108 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2113 if (gen_check_cpenable(dc
, 0)) {
2114 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2118 default: /*reserved*/
2124 default: /*reserved*/
2132 if (option_enabled(dc
, XTENSA_OPTION_DEPBITS
)) {
2133 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
2136 tcg_gen_deposit_i32(cpu_R
[RRR_T
], cpu_R
[RRR_T
], cpu_R
[RRR_S
],
2137 OP2
+ 16, RRR_R
+ 1);
2141 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2143 #define gen_compare(rel, br, a, b) \
2145 if (gen_check_cpenable(dc, 0)) { \
2146 TCGv_i32 bit = tcg_const_i32(1 << br); \
2148 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2149 tcg_temp_free(bit); \
2155 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2159 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2163 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2167 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2171 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2175 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2179 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2184 case 8: /*MOVEQZ.Sf*/
2185 case 9: /*MOVNEZ.Sf*/
2186 case 10: /*MOVLTZ.Sf*/
2187 case 11: /*MOVGEZ.Sf*/
2188 if (gen_window_check1(dc
, RRR_T
) &&
2189 gen_check_cpenable(dc
, 0)) {
2190 static const TCGCond cond
[] = {
2196 TCGv_i32 zero
= tcg_const_i32(0);
2198 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2199 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2200 tcg_temp_free(zero
);
2204 case 12: /*MOVF.Sf*/
2205 case 13: /*MOVT.Sf*/
2206 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2207 if (gen_check_cpenable(dc
, 0)) {
2208 TCGv_i32 zero
= tcg_const_i32(0);
2209 TCGv_i32 tmp
= tcg_temp_new_i32();
2211 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2212 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2213 cpu_FR
[RRR_R
], tmp
, zero
,
2214 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2217 tcg_temp_free(zero
);
2221 default: /*reserved*/
2227 default: /*reserved*/
2234 if (gen_window_check1(dc
, RRR_T
)) {
2235 TCGv_i32 tmp
= tcg_const_i32(
2236 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2237 0 : ((dc
->pc
+ 3) & ~3)) +
2238 (0xfffc0000 | (RI16_IMM16
<< 2)));
2240 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2241 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2243 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2249 #define gen_load_store(type, shift) do { \
2250 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2251 TCGv_i32 addr = tcg_temp_new_i32(); \
2253 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2255 gen_load_store_alignment(dc, shift, addr, false); \
2257 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2258 tcg_temp_free(addr); \
2264 gen_load_store(ld8u
, 0);
2268 gen_load_store(ld16u
, 1);
2272 gen_load_store(ld32u
, 2);
2276 gen_load_store(st8
, 0);
2280 gen_load_store(st16
, 1);
2284 gen_load_store(st32
, 2);
2287 #define gen_dcache_hit_test(w, shift) do { \
2288 if (gen_window_check1(dc, RRI##w##_S)) { \
2289 TCGv_i32 addr = tcg_temp_new_i32(); \
2290 TCGv_i32 res = tcg_temp_new_i32(); \
2291 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2292 RRI##w##_IMM##w << shift); \
2293 tcg_gen_qemu_ld8u(res, addr, dc->cring); \
2294 tcg_temp_free(addr); \
2295 tcg_temp_free(res); \
2299 #define gen_dcache_hit_test4() gen_dcache_hit_test(4, 4)
2300 #define gen_dcache_hit_test8() gen_dcache_hit_test(8, 2)
2304 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2309 gen_window_check1(dc
, RRI8_S
);
2313 gen_window_check1(dc
, RRI8_S
);
2317 gen_window_check1(dc
, RRI8_S
);
2321 gen_window_check1(dc
, RRI8_S
);
2325 gen_dcache_hit_test8();
2329 gen_dcache_hit_test8();
2333 if (gen_check_privilege(dc
)) {
2334 gen_dcache_hit_test8();
2339 if (gen_check_privilege(dc
)) {
2340 gen_window_check1(dc
, RRI8_S
);
2347 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2348 if (gen_check_privilege(dc
)) {
2349 gen_dcache_hit_test4();
2354 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2355 if (gen_check_privilege(dc
)) {
2356 gen_dcache_hit_test4();
2361 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2362 if (gen_check_privilege(dc
)) {
2363 gen_window_check1(dc
, RRI4_S
);
2368 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2369 if (gen_check_privilege(dc
)) {
2370 gen_window_check1(dc
, RRI4_S
);
2375 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2376 if (gen_check_privilege(dc
)) {
2377 gen_window_check1(dc
, RRI4_S
);
2381 default: /*reserved*/
2388 #undef gen_dcache_hit_test
2389 #undef gen_dcache_hit_test4
2390 #undef gen_dcache_hit_test8
2392 #define gen_icache_hit_test(w, shift) do { \
2393 if (gen_window_check1(dc, RRI##w##_S)) { \
2394 TCGv_i32 addr = tcg_temp_new_i32(); \
2395 tcg_gen_movi_i32(cpu_pc, dc->pc); \
2396 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2397 RRI##w##_IMM##w << shift); \
2398 gen_helper_itlb_hit_test(cpu_env, addr); \
2399 tcg_temp_free(addr); \
2403 #define gen_icache_hit_test4() gen_icache_hit_test(4, 4)
2404 #define gen_icache_hit_test8() gen_icache_hit_test(8, 2)
2407 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2408 gen_window_check1(dc
, RRI8_S
);
2414 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2415 if (gen_check_privilege(dc
)) {
2416 gen_icache_hit_test4();
2421 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2422 if (gen_check_privilege(dc
)) {
2423 gen_icache_hit_test4();
2428 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2429 if (gen_check_privilege(dc
)) {
2430 gen_window_check1(dc
, RRI4_S
);
2434 default: /*reserved*/
2441 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2442 gen_icache_hit_test8();
2446 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2447 if (gen_check_privilege(dc
)) {
2448 gen_window_check1(dc
, RRI8_S
);
2452 default: /*reserved*/
2458 #undef gen_icache_hit_test
2459 #undef gen_icache_hit_test4
2460 #undef gen_icache_hit_test8
2463 gen_load_store(ld16s
, 1);
2465 #undef gen_load_store
2468 if (gen_window_check1(dc
, RRI8_T
)) {
2469 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2470 RRI8_IMM8
| (RRI8_S
<< 8) |
2471 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2475 #define gen_load_store_no_hw_align(type) do { \
2476 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2477 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2478 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2479 gen_load_store_alignment(dc, 2, addr, true); \
2480 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2481 tcg_temp_free(addr); \
2486 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2487 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2491 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2492 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2497 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2498 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
],
2503 case 14: /*S32C1Iy*/
2504 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2505 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2506 TCGLabel
*label
= gen_new_label();
2507 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2508 TCGv_i32 addr
= tcg_temp_local_new_i32();
2511 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2512 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2513 gen_load_store_alignment(dc
, 2, addr
, true);
2515 gen_advance_ccount(dc
);
2516 tpc
= tcg_const_i32(dc
->pc
);
2517 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2518 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2519 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2520 cpu_SR
[SCOMPARE1
], label
);
2522 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2524 gen_set_label(label
);
2526 tcg_temp_free(addr
);
2532 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2533 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2535 #undef gen_load_store_no_hw_align
2537 default: /*reserved*/
2549 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2550 if (gen_window_check1(dc
, RRI8_S
) &&
2551 gen_check_cpenable(dc
, 0)) {
2552 TCGv_i32 addr
= tcg_temp_new_i32();
2553 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2554 gen_load_store_alignment(dc
, 2, addr
, false);
2556 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2558 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2561 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2563 tcg_temp_free(addr
);
2567 default: /*reserved*/
2574 HAS_OPTION(XTENSA_OPTION_MAC16
);
2583 bool is_m1_sr
= (OP2
& 0x3) == 2;
2584 bool is_m2_sr
= (OP2
& 0xc) == 0;
2585 uint32_t ld_offset
= 0;
2592 case 0: /*MACI?/MACC?*/
2594 ld_offset
= (OP2
& 1) ? -4 : 4;
2596 if (OP2
>= 8) { /*MACI/MACC*/
2597 if (OP1
== 0) { /*LDINC/LDDEC*/
2602 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2607 case 2: /*MACD?/MACA?*/
2608 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2614 if (op
!= MAC16_NONE
) {
2615 if (!is_m1_sr
&& !gen_window_check1(dc
, RRR_S
)) {
2618 if (!is_m2_sr
&& !gen_window_check1(dc
, RRR_T
)) {
2623 if (ld_offset
&& !gen_window_check1(dc
, RRR_S
)) {
2628 TCGv_i32 vaddr
= tcg_temp_new_i32();
2629 TCGv_i32 mem32
= tcg_temp_new_i32();
2632 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2633 gen_load_store_alignment(dc
, 2, vaddr
, false);
2634 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2636 if (op
!= MAC16_NONE
) {
2637 TCGv_i32 m1
= gen_mac16_m(
2638 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2639 OP1
& 1, op
== MAC16_UMUL
);
2640 TCGv_i32 m2
= gen_mac16_m(
2641 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2642 OP1
& 2, op
== MAC16_UMUL
);
2644 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2645 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2646 if (op
== MAC16_UMUL
) {
2647 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2649 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2652 TCGv_i32 lo
= tcg_temp_new_i32();
2653 TCGv_i32 hi
= tcg_temp_new_i32();
2655 tcg_gen_mul_i32(lo
, m1
, m2
);
2656 tcg_gen_sari_i32(hi
, lo
, 31);
2657 if (op
== MAC16_MULA
) {
2658 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2659 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2662 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2663 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2666 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2668 tcg_temp_free_i32(lo
);
2669 tcg_temp_free_i32(hi
);
2675 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2676 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2678 tcg_temp_free(vaddr
);
2679 tcg_temp_free(mem32
);
2687 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2688 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2694 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2695 if (gen_window_check1(dc
, CALL_N
<< 2)) {
2696 gen_callwi(dc
, CALL_N
,
2697 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2706 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2710 if (gen_window_check1(dc
, BRI12_S
)) {
2711 static const TCGCond cond
[] = {
2712 TCG_COND_EQ
, /*BEQZ*/
2713 TCG_COND_NE
, /*BNEZ*/
2714 TCG_COND_LT
, /*BLTZ*/
2715 TCG_COND_GE
, /*BGEZ*/
2718 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2719 4 + BRI12_IMM12_SE
);
2724 if (gen_window_check1(dc
, BRI8_S
)) {
2725 static const TCGCond cond
[] = {
2726 TCG_COND_EQ
, /*BEQI*/
2727 TCG_COND_NE
, /*BNEI*/
2728 TCG_COND_LT
, /*BLTI*/
2729 TCG_COND_GE
, /*BGEI*/
2732 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2733 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2740 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2742 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2743 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2744 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2745 gen_advance_ccount(dc
);
2746 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2750 /* This can change tb->flags, so exit tb */
2751 gen_jumpi_check_loop_end(dc
, -1);
2759 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2761 TCGv_i32 tmp
= tcg_temp_new_i32();
2762 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2764 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2765 tmp
, 0, 4 + RRI8_IMM8_SE
);
2772 case 10: /*LOOPGTZ*/
2773 HAS_OPTION(XTENSA_OPTION_LOOP
);
2774 if (gen_window_check1(dc
, RRI8_S
)) {
2775 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2776 TCGv_i32 tmp
= tcg_const_i32(lend
);
2778 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2779 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2780 gen_helper_wsr_lend(cpu_env
, tmp
);
2784 TCGLabel
*label
= gen_new_label();
2785 tcg_gen_brcondi_i32(
2786 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2787 cpu_R
[RRI8_S
], 0, label
);
2788 gen_jumpi(dc
, lend
, 1);
2789 gen_set_label(label
);
2792 gen_jumpi(dc
, dc
->next_pc
, 0);
2796 default: /*reserved*/
2805 if (gen_window_check1(dc
, BRI8_S
)) {
2806 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2807 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
],
2819 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2821 switch (RRI8_R
& 7) {
2822 case 0: /*BNONE*/ /*BANY*/
2823 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2824 TCGv_i32 tmp
= tcg_temp_new_i32();
2825 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2826 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2831 case 1: /*BEQ*/ /*BNE*/
2832 case 2: /*BLT*/ /*BGE*/
2833 case 3: /*BLTU*/ /*BGEU*/
2834 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2835 static const TCGCond cond
[] = {
2841 [11] = TCG_COND_GEU
,
2843 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2848 case 4: /*BALL*/ /*BNALL*/
2849 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2850 TCGv_i32 tmp
= tcg_temp_new_i32();
2851 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2852 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2858 case 5: /*BBC*/ /*BBS*/
2859 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2860 #ifdef TARGET_WORDS_BIGENDIAN
2861 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2863 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2865 TCGv_i32 tmp
= tcg_temp_new_i32();
2866 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2867 #ifdef TARGET_WORDS_BIGENDIAN
2868 tcg_gen_shr_i32(bit
, bit
, tmp
);
2870 tcg_gen_shl_i32(bit
, bit
, tmp
);
2872 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2873 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2879 case 6: /*BBCI*/ /*BBSI*/
2881 if (gen_window_check1(dc
, RRI8_S
)) {
2882 TCGv_i32 tmp
= tcg_temp_new_i32();
2883 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2884 #ifdef TARGET_WORDS_BIGENDIAN
2885 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2887 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2889 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2898 #define gen_narrow_load_store(type) do { \
2899 if (gen_window_check2(dc, RRRN_S, RRRN_T)) { \
2900 TCGv_i32 addr = tcg_temp_new_i32(); \
2901 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2902 gen_load_store_alignment(dc, 2, addr, false); \
2903 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2904 tcg_temp_free(addr); \
2909 gen_narrow_load_store(ld32u
);
2913 gen_narrow_load_store(st32
);
2915 #undef gen_narrow_load_store
2918 if (gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
)) {
2919 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2923 case 11: /*ADDI.Nn*/
2924 if (gen_window_check2(dc
, RRRN_R
, RRRN_S
)) {
2925 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
],
2926 RRRN_T
? RRRN_T
: -1);
2931 if (!gen_window_check1(dc
, RRRN_S
)) {
2934 if (RRRN_T
< 8) { /*MOVI.Nn*/
2935 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2936 RRRN_R
| (RRRN_T
<< 4) |
2937 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2938 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2939 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2941 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2942 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2949 if (gen_window_check2(dc
, RRRN_S
, RRRN_T
)) {
2950 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2957 gen_jump(dc
, cpu_R
[0]);
2961 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2963 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2964 gen_advance_ccount(dc
);
2965 gen_helper_retw(tmp
, cpu_env
, tmp
);
2971 case 2: /*BREAK.Nn*/
2972 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2974 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2982 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2985 default: /*reserved*/
2991 default: /*reserved*/
2997 default: /*reserved*/
3002 if (dc
->is_jmp
== DISAS_NEXT
) {
3003 gen_check_loop_end(dc
, 0);
3005 dc
->pc
= dc
->next_pc
;
3010 qemu_log_mask(LOG_GUEST_ERROR
, "INVALID(pc = %08x)\n", dc
->pc
);
3011 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
3015 static inline unsigned xtensa_insn_len(CPUXtensaState
*env
, DisasContext
*dc
)
3017 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
3018 return xtensa_op0_insn_len(OP0
);
3021 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
3025 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
3026 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
3027 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
3028 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
3034 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3036 XtensaCPU
*cpu
= xtensa_env_get_cpu(env
);
3037 CPUState
*cs
= CPU(cpu
);
3040 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3041 uint32_t pc_start
= tb
->pc
;
3042 uint32_t next_page_start
=
3043 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3045 if (max_insns
== 0) {
3046 max_insns
= CF_COUNT_MASK
;
3048 if (max_insns
> TCG_MAX_INSNS
) {
3049 max_insns
= TCG_MAX_INSNS
;
3052 dc
.config
= env
->config
;
3053 dc
.singlestep_enabled
= cs
->singlestep_enabled
;
3056 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
3057 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
3058 dc
.lbeg
= env
->sregs
[LBEG
];
3059 dc
.lend
= env
->sregs
[LEND
];
3060 dc
.is_jmp
= DISAS_NEXT
;
3061 dc
.ccount_delta
= 0;
3062 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
3063 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
3064 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
3065 XTENSA_TBFLAG_CPENABLE_SHIFT
;
3066 dc
.window
= ((tb
->flags
& XTENSA_TBFLAG_WINDOW_MASK
) >>
3067 XTENSA_TBFLAG_WINDOW_SHIFT
);
3070 init_sar_tracker(&dc
);
3072 dc
.next_icount
= tcg_temp_local_new_i32();
3077 if (tb
->flags
& XTENSA_TBFLAG_EXCEPTION
) {
3078 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3079 gen_exception(&dc
, EXCP_DEBUG
);
3083 tcg_gen_insn_start(dc
.pc
);
3088 if (unlikely(cpu_breakpoint_test(cs
, dc
.pc
, BP_ANY
))) {
3089 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3090 gen_exception(&dc
, EXCP_DEBUG
);
3091 dc
.is_jmp
= DISAS_UPDATE
;
3092 /* The address covered by the breakpoint must be included in
3093 [tb->pc, tb->pc + tb->size) in order to for it to be
3094 properly cleared -- thus we increment the PC here so that
3095 the logic setting tb->size below does the right thing. */
3100 if (insn_count
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3105 TCGLabel
*label
= gen_new_label();
3107 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
3108 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
3109 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
3111 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
3113 gen_set_label(label
);
3117 gen_ibreak_check(env
, &dc
);
3120 disas_xtensa_insn(env
, &dc
);
3122 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
3124 if (cs
->singlestep_enabled
) {
3125 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3126 gen_exception(&dc
, EXCP_DEBUG
);
3129 } while (dc
.is_jmp
== DISAS_NEXT
&&
3130 insn_count
< max_insns
&&
3131 dc
.pc
< next_page_start
&&
3132 dc
.pc
+ xtensa_insn_len(env
, &dc
) <= next_page_start
&&
3133 !tcg_op_buf_full());
3136 reset_sar_tracker(&dc
);
3138 tcg_temp_free(dc
.next_icount
);
3141 if (tb
->cflags
& CF_LAST_IO
) {
3145 if (dc
.is_jmp
== DISAS_NEXT
) {
3146 gen_jumpi(&dc
, dc
.pc
, 0);
3148 gen_tb_end(tb
, insn_count
);
3151 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3152 qemu_log("----------------\n");
3153 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3154 log_target_disas(cs
, pc_start
, dc
.pc
- pc_start
, 0);
3158 tb
->size
= dc
.pc
- pc_start
;
3159 tb
->icount
= insn_count
;
3162 void xtensa_cpu_dump_state(CPUState
*cs
, FILE *f
,
3163 fprintf_function cpu_fprintf
, int flags
)
3165 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
3166 CPUXtensaState
*env
= &cpu
->env
;
3169 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3171 for (i
= j
= 0; i
< 256; ++i
) {
3172 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3173 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3174 (j
++ % 4) == 3 ? '\n' : ' ');
3178 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3180 for (i
= j
= 0; i
< 256; ++i
) {
3181 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3182 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3183 (j
++ % 4) == 3 ? '\n' : ' ');
3187 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3189 for (i
= 0; i
< 16; ++i
) {
3190 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3191 (i
% 4) == 3 ? '\n' : ' ');
3194 cpu_fprintf(f
, "\n");
3196 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3197 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3198 (i
% 4) == 3 ? '\n' : ' ');
3201 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3202 cpu_fprintf(f
, "\n");
3204 for (i
= 0; i
< 16; ++i
) {
3205 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3206 float32_val(env
->fregs
[i
].f32
[FP_F32_LOW
]),
3207 *(float *)(env
->fregs
[i
].f32
+ FP_F32_LOW
),
3208 (i
% 2) == 1 ? '\n' : ' ');
3213 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
,