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 #ifndef CONFIG_USER_ONLY
422 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
426 gen_jump_slot(dc
, tmp
, slot
);
430 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
433 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
435 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
436 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
437 tcg_temp_free(tcallinc
);
438 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
439 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
440 gen_jump_slot(dc
, dest
, slot
);
443 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
445 gen_callw_slot(dc
, callinc
, dest
, -1);
448 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
450 TCGv_i32 tmp
= tcg_const_i32(dest
);
451 #ifndef CONFIG_USER_ONLY
452 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
456 gen_callw_slot(dc
, callinc
, tmp
, slot
);
460 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
462 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
463 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
464 dc
->next_pc
== dc
->lend
) {
465 TCGLabel
*label
= gen_new_label();
467 gen_advance_ccount(dc
);
468 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
469 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
470 gen_jumpi(dc
, dc
->lbeg
, slot
);
471 gen_set_label(label
);
472 gen_jumpi(dc
, dc
->next_pc
, -1);
478 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
480 if (!gen_check_loop_end(dc
, slot
)) {
481 gen_jumpi(dc
, dc
->next_pc
, slot
);
485 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
486 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
488 TCGLabel
*label
= gen_new_label();
490 gen_advance_ccount(dc
);
491 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
492 gen_jumpi_check_loop_end(dc
, 0);
493 gen_set_label(label
);
494 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
497 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
498 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
500 TCGv_i32 tmp
= tcg_const_i32(t1
);
501 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
505 static bool gen_check_sr(DisasContext
*dc
, uint32_t sr
, unsigned access
)
507 if (!xtensa_option_bits_enabled(dc
->config
, sregnames
[sr
].opt_bits
)) {
508 if (sregnames
[sr
].name
) {
509 qemu_log_mask(LOG_GUEST_ERROR
, "SR %s is not configured\n", sregnames
[sr
].name
);
511 qemu_log_mask(LOG_UNIMP
, "SR %d is not implemented\n", sr
);
513 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
515 } else if (!(sregnames
[sr
].access
& access
)) {
516 static const char * const access_text
[] = {
521 assert(access
< ARRAY_SIZE(access_text
) && access_text
[access
]);
522 qemu_log_mask(LOG_GUEST_ERROR
, "SR %s is not available for %s\n", sregnames
[sr
].name
,
523 access_text
[access
]);
524 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
530 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
532 gen_advance_ccount(dc
);
533 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
536 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
538 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
539 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
540 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
543 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
545 static void (* const rsr_handler
[256])(DisasContext
*dc
,
546 TCGv_i32 d
, uint32_t sr
) = {
547 [CCOUNT
] = gen_rsr_ccount
,
548 [PTEVADDR
] = gen_rsr_ptevaddr
,
551 if (rsr_handler
[sr
]) {
552 rsr_handler
[sr
](dc
, d
, sr
);
554 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
558 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
560 gen_helper_wsr_lbeg(cpu_env
, s
);
561 gen_jumpi_check_loop_end(dc
, 0);
564 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
566 gen_helper_wsr_lend(cpu_env
, s
);
567 gen_jumpi_check_loop_end(dc
, 0);
570 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
572 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
573 if (dc
->sar_m32_5bit
) {
574 tcg_gen_discard_i32(dc
->sar_m32
);
576 dc
->sar_5bit
= false;
577 dc
->sar_m32_5bit
= false;
580 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
582 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
585 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
587 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
588 /* This can change tb->flags, so exit tb */
589 gen_jumpi_check_loop_end(dc
, -1);
592 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
594 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
597 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
599 gen_helper_wsr_windowbase(cpu_env
, v
);
600 /* This can change tb->flags, so exit tb */
601 gen_jumpi_check_loop_end(dc
, -1);
604 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
606 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
607 /* This can change tb->flags, so exit tb */
608 gen_jumpi_check_loop_end(dc
, -1);
611 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
613 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
616 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
618 gen_helper_wsr_rasid(cpu_env
, v
);
619 /* This can change tb->flags, so exit tb */
620 gen_jumpi_check_loop_end(dc
, -1);
623 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
625 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
628 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
630 gen_helper_wsr_ibreakenable(cpu_env
, v
);
631 gen_jumpi_check_loop_end(dc
, 0);
634 static void gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
636 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
639 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
641 unsigned id
= sr
- IBREAKA
;
643 if (id
< dc
->config
->nibreak
) {
644 TCGv_i32 tmp
= tcg_const_i32(id
);
645 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
647 gen_jumpi_check_loop_end(dc
, 0);
651 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
653 unsigned id
= sr
- DBREAKA
;
655 if (id
< dc
->config
->ndbreak
) {
656 TCGv_i32 tmp
= tcg_const_i32(id
);
657 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
662 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
664 unsigned id
= sr
- DBREAKC
;
666 if (id
< dc
->config
->ndbreak
) {
667 TCGv_i32 tmp
= tcg_const_i32(id
);
668 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
673 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
675 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
676 /* This can change tb->flags, so exit tb */
677 gen_jumpi_check_loop_end(dc
, -1);
680 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
682 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
683 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
684 gen_helper_check_interrupts(cpu_env
);
685 gen_jumpi_check_loop_end(dc
, 0);
688 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
690 TCGv_i32 tmp
= tcg_temp_new_i32();
692 tcg_gen_andi_i32(tmp
, v
,
693 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
694 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
695 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
696 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
698 gen_helper_check_interrupts(cpu_env
);
701 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
703 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
704 gen_helper_check_interrupts(cpu_env
);
705 gen_jumpi_check_loop_end(dc
, 0);
708 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
710 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
711 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
713 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
716 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
717 gen_helper_check_interrupts(cpu_env
);
718 /* This can change mmu index and tb->flags, so exit tb */
719 gen_jumpi_check_loop_end(dc
, -1);
722 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
725 tcg_gen_mov_i32(dc
->next_icount
, v
);
727 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
731 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
733 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
734 /* This can change tb->flags, so exit tb */
735 gen_jumpi_check_loop_end(dc
, -1);
738 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
740 uint32_t id
= sr
- CCOMPARE
;
741 if (id
< dc
->config
->nccompare
) {
742 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
743 gen_advance_ccount(dc
);
744 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
745 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
746 gen_helper_check_interrupts(cpu_env
);
750 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
752 static void (* const wsr_handler
[256])(DisasContext
*dc
,
753 uint32_t sr
, TCGv_i32 v
) = {
754 [LBEG
] = gen_wsr_lbeg
,
755 [LEND
] = gen_wsr_lend
,
758 [LITBASE
] = gen_wsr_litbase
,
759 [ACCHI
] = gen_wsr_acchi
,
760 [WINDOW_BASE
] = gen_wsr_windowbase
,
761 [WINDOW_START
] = gen_wsr_windowstart
,
762 [PTEVADDR
] = gen_wsr_ptevaddr
,
763 [RASID
] = gen_wsr_rasid
,
764 [ITLBCFG
] = gen_wsr_tlbcfg
,
765 [DTLBCFG
] = gen_wsr_tlbcfg
,
766 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
767 [ATOMCTL
] = gen_wsr_atomctl
,
768 [IBREAKA
] = gen_wsr_ibreaka
,
769 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
770 [DBREAKA
] = gen_wsr_dbreaka
,
771 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
772 [DBREAKC
] = gen_wsr_dbreakc
,
773 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
774 [CPENABLE
] = gen_wsr_cpenable
,
775 [INTSET
] = gen_wsr_intset
,
776 [INTCLEAR
] = gen_wsr_intclear
,
777 [INTENABLE
] = gen_wsr_intenable
,
779 [ICOUNT
] = gen_wsr_icount
,
780 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
781 [CCOMPARE
] = gen_wsr_ccompare
,
782 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
783 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
786 if (wsr_handler
[sr
]) {
787 wsr_handler
[sr
](dc
, sr
, s
);
789 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
793 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
797 gen_helper_wur_fcr(cpu_env
, s
);
801 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
805 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
810 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
811 TCGv_i32 addr
, bool no_hw_alignment
)
813 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
814 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
815 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
817 TCGLabel
*label
= gen_new_label();
818 TCGv_i32 tmp
= tcg_temp_new_i32();
819 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
820 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
821 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
822 gen_set_label(label
);
827 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
829 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
830 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
831 gen_advance_ccount(dc
);
832 gen_helper_waiti(cpu_env
, pc
, intlevel
);
834 tcg_temp_free(intlevel
);
837 static bool gen_window_check1(DisasContext
*dc
, unsigned r1
)
839 if (r1
/ 4 > dc
->window
) {
840 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
841 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
843 gen_advance_ccount(dc
);
844 gen_helper_window_check(cpu_env
, pc
, w
);
845 dc
->is_jmp
= DISAS_UPDATE
;
851 static bool gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
853 return gen_window_check1(dc
, r1
> r2
? r1
: r2
);
856 static bool gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
859 return gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
862 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
864 TCGv_i32 m
= tcg_temp_new_i32();
867 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
869 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
874 static inline unsigned xtensa_op0_insn_len(unsigned op0
)
876 return op0
>= 8 ? 2 : 3;
879 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
881 #define HAS_OPTION_BITS(opt) do { \
882 if (!option_bits_enabled(dc, opt)) { \
883 qemu_log_mask(LOG_GUEST_ERROR, "Option is not enabled %s:%d\n", \
884 __FILE__, __LINE__); \
885 goto invalid_opcode; \
889 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
891 #define TBD() qemu_log_mask(LOG_UNIMP, "TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
892 #define RESERVED() do { \
893 qemu_log_mask(LOG_GUEST_ERROR, "RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
894 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
895 goto invalid_opcode; \
899 #ifdef TARGET_WORDS_BIGENDIAN
900 #define OP0 (((b0) & 0xf0) >> 4)
901 #define OP1 (((b2) & 0xf0) >> 4)
902 #define OP2 ((b2) & 0xf)
903 #define RRR_R ((b1) & 0xf)
904 #define RRR_S (((b1) & 0xf0) >> 4)
905 #define RRR_T ((b0) & 0xf)
907 #define OP0 (((b0) & 0xf))
908 #define OP1 (((b2) & 0xf))
909 #define OP2 (((b2) & 0xf0) >> 4)
910 #define RRR_R (((b1) & 0xf0) >> 4)
911 #define RRR_S (((b1) & 0xf))
912 #define RRR_T (((b0) & 0xf0) >> 4)
914 #define RRR_X ((RRR_R & 0x4) >> 2)
915 #define RRR_Y ((RRR_T & 0x4) >> 2)
916 #define RRR_W (RRR_R & 0x3)
925 #ifdef TARGET_WORDS_BIGENDIAN
926 #define RRI4_IMM4 ((b2) & 0xf)
928 #define RRI4_IMM4 (((b2) & 0xf0) >> 4)
934 #define RRI8_IMM8 (b2)
935 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
937 #ifdef TARGET_WORDS_BIGENDIAN
938 #define RI16_IMM16 (((b1) << 8) | (b2))
940 #define RI16_IMM16 (((b2) << 8) | (b1))
943 #ifdef TARGET_WORDS_BIGENDIAN
944 #define CALL_N (((b0) & 0xc) >> 2)
945 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
947 #define CALL_N (((b0) & 0x30) >> 4)
948 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
950 #define CALL_OFFSET_SE \
951 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
953 #define CALLX_N CALL_N
954 #ifdef TARGET_WORDS_BIGENDIAN
955 #define CALLX_M ((b0) & 0x3)
957 #define CALLX_M (((b0) & 0xc0) >> 6)
959 #define CALLX_S RRR_S
961 #define BRI12_M CALLX_M
962 #define BRI12_S RRR_S
963 #ifdef TARGET_WORDS_BIGENDIAN
964 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
966 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
968 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
970 #define BRI8_M BRI12_M
971 #define BRI8_R RRI8_R
972 #define BRI8_S RRI8_S
973 #define BRI8_IMM8 RRI8_IMM8
974 #define BRI8_IMM8_SE RRI8_IMM8_SE
978 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
979 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
981 unsigned len
= xtensa_op0_insn_len(OP0
);
983 static const uint32_t B4CONST
[] = {
984 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
987 static const uint32_t B4CONSTU
[] = {
988 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
993 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
997 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
1003 dc
->next_pc
= dc
->pc
+ len
;
1011 if ((RRR_R
& 0xc) == 0x8) {
1012 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1019 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1022 case 1: /*reserved*/
1030 if (gen_window_check1(dc
, CALLX_S
)) {
1031 gen_jump(dc
, cpu_R
[CALLX_S
]);
1036 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1038 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1039 gen_advance_ccount(dc
);
1040 gen_helper_retw(tmp
, cpu_env
, tmp
);
1046 case 3: /*reserved*/
1053 if (!gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2)) {
1059 TCGv_i32 tmp
= tcg_temp_new_i32();
1060 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1061 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1069 case 3: /*CALLX12w*/
1070 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1072 TCGv_i32 tmp
= tcg_temp_new_i32();
1074 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1075 gen_callw(dc
, CALLX_N
, tmp
);
1085 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1086 if (gen_window_check2(dc
, RRR_T
, RRR_S
)) {
1087 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1088 gen_advance_ccount(dc
);
1089 gen_helper_movsp(cpu_env
, pc
);
1090 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1110 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1122 default: /*reserved*/
1131 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1134 if (gen_check_privilege(dc
)) {
1135 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1136 gen_helper_check_interrupts(cpu_env
);
1137 gen_jump(dc
, cpu_SR
[EPC1
]);
1146 if (gen_check_privilege(dc
)) {
1147 gen_jump(dc
, cpu_SR
[
1148 dc
->config
->ndepc
? DEPC
: EPC1
]);
1154 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1155 if (gen_check_privilege(dc
)) {
1156 TCGv_i32 tmp
= tcg_const_i32(1);
1159 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1160 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1163 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1164 cpu_SR
[WINDOW_START
], tmp
);
1166 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1167 cpu_SR
[WINDOW_START
], tmp
);
1170 gen_helper_restore_owb(cpu_env
);
1171 gen_helper_check_interrupts(cpu_env
);
1172 gen_jump(dc
, cpu_SR
[EPC1
]);
1178 default: /*reserved*/
1185 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1186 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1187 if (gen_check_privilege(dc
)) {
1188 tcg_gen_mov_i32(cpu_SR
[PS
],
1189 cpu_SR
[EPS2
+ RRR_S
- 2]);
1190 gen_helper_check_interrupts(cpu_env
);
1191 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1194 qemu_log_mask(LOG_GUEST_ERROR
, "RFI %d is illegal\n", RRR_S
);
1195 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1203 default: /*reserved*/
1211 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1213 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1217 case 5: /*SYSCALLx*/
1218 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1220 case 0: /*SYSCALLx*/
1221 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1225 if (semihosting_enabled()) {
1226 if (gen_check_privilege(dc
)) {
1227 gen_helper_simcall(cpu_env
);
1230 qemu_log_mask(LOG_GUEST_ERROR
, "SIMCALL but semihosting is disabled\n");
1231 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1242 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1243 if (gen_check_privilege(dc
) &&
1244 gen_window_check1(dc
, RRR_T
)) {
1245 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1246 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1247 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1248 gen_helper_check_interrupts(cpu_env
);
1249 gen_jumpi_check_loop_end(dc
, 0);
1254 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1255 if (gen_check_privilege(dc
)) {
1256 gen_waiti(dc
, RRR_S
);
1264 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1266 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1267 TCGv_i32 mask
= tcg_const_i32(
1268 ((1 << shift
) - 1) << RRR_S
);
1269 TCGv_i32 tmp
= tcg_temp_new_i32();
1271 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1272 if (RRR_R
& 1) { /*ALL*/
1273 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1275 tcg_gen_add_i32(tmp
, tmp
, mask
);
1277 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1278 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1280 tcg_temp_free(mask
);
1285 default: /*reserved*/
1293 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1294 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1299 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1300 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1305 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1306 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1313 if (gen_window_check1(dc
, RRR_S
)) {
1314 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1319 if (gen_window_check1(dc
, RRR_S
)) {
1320 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1325 if (gen_window_check1(dc
, RRR_S
)) {
1326 TCGv_i32 tmp
= tcg_temp_new_i32();
1327 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1328 gen_right_shift_sar(dc
, tmp
);
1334 if (gen_window_check1(dc
, RRR_S
)) {
1335 TCGv_i32 tmp
= tcg_temp_new_i32();
1336 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1337 gen_left_shift_sar(dc
, tmp
);
1344 TCGv_i32 tmp
= tcg_const_i32(
1345 RRR_S
| ((RRR_T
& 1) << 4));
1346 gen_right_shift_sar(dc
, tmp
);
1360 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1361 if (gen_check_privilege(dc
)) {
1362 TCGv_i32 tmp
= tcg_const_i32(
1363 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1364 gen_helper_rotw(cpu_env
, tmp
);
1366 /* This can change tb->flags, so exit tb */
1367 gen_jumpi_check_loop_end(dc
, -1);
1372 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1373 if (gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1374 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1379 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1380 if (gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1381 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1385 default: /*reserved*/
1393 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1394 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1395 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1396 if (gen_check_privilege(dc
) &&
1397 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1398 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1400 switch (RRR_R
& 7) {
1401 case 3: /*RITLB0*/ /*RDTLB0*/
1402 gen_helper_rtlb0(cpu_R
[RRR_T
],
1403 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1406 case 4: /*IITLB*/ /*IDTLB*/
1407 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1408 /* This could change memory mapping, so exit tb */
1409 gen_jumpi_check_loop_end(dc
, -1);
1412 case 5: /*PITLB*/ /*PDTLB*/
1413 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1414 gen_helper_ptlb(cpu_R
[RRR_T
],
1415 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1418 case 6: /*WITLB*/ /*WDTLB*/
1420 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1421 /* This could change memory mapping, so exit tb */
1422 gen_jumpi_check_loop_end(dc
, -1);
1425 case 7: /*RITLB1*/ /*RDTLB1*/
1426 gen_helper_rtlb1(cpu_R
[RRR_T
],
1427 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1431 tcg_temp_free(dtlb
);
1435 tcg_temp_free(dtlb
);
1440 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1445 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1450 TCGv_i32 zero
= tcg_const_i32(0);
1451 TCGv_i32 neg
= tcg_temp_new_i32();
1453 tcg_gen_neg_i32(neg
, cpu_R
[RRR_T
]);
1454 tcg_gen_movcond_i32(TCG_COND_GE
, cpu_R
[RRR_R
],
1455 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_T
], neg
);
1457 tcg_temp_free(zero
);
1461 default: /*reserved*/
1467 case 7: /*reserved*/
1472 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1473 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1480 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1481 TCGv_i32 tmp
= tcg_temp_new_i32();
1482 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1483 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1489 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1490 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1497 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1498 TCGv_i32 tmp
= tcg_temp_new_i32();
1499 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1500 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1511 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1512 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1513 32 - (RRR_T
| ((OP2
& 1) << 4)));
1519 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1520 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1521 RRR_S
| ((OP2
& 1) << 4));
1526 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1527 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1532 if (gen_check_sr(dc
, RSR_SR
, SR_X
) &&
1533 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1534 gen_window_check1(dc
, RRR_T
)) {
1535 TCGv_i32 tmp
= tcg_temp_new_i32();
1537 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1538 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1539 gen_wsr(dc
, RSR_SR
, tmp
);
1545 * Note: 64 bit ops are used here solely because SAR values
1548 #define gen_shift_reg(cmd, reg) do { \
1549 TCGv_i64 tmp = tcg_temp_new_i64(); \
1550 tcg_gen_extu_i32_i64(tmp, reg); \
1551 tcg_gen_##cmd##_i64(v, v, tmp); \
1552 tcg_gen_extrl_i64_i32(cpu_R[RRR_R], v); \
1553 tcg_temp_free_i64(v); \
1554 tcg_temp_free_i64(tmp); \
1557 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1560 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1561 TCGv_i64 v
= tcg_temp_new_i64();
1562 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1568 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1572 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1574 TCGv_i64 v
= tcg_temp_new_i64();
1575 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1581 if (!gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1584 if (dc
->sar_m32_5bit
) {
1585 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1587 TCGv_i64 v
= tcg_temp_new_i64();
1588 TCGv_i32 s
= tcg_const_i32(32);
1589 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1590 tcg_gen_andi_i32(s
, s
, 0x3f);
1591 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1592 gen_shift_reg(shl
, s
);
1598 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1602 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1604 TCGv_i64 v
= tcg_temp_new_i64();
1605 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1610 #undef gen_shift_reg
1613 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1614 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1615 TCGv_i32 v1
= tcg_temp_new_i32();
1616 TCGv_i32 v2
= tcg_temp_new_i32();
1617 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1618 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1619 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1626 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1627 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1628 TCGv_i32 v1
= tcg_temp_new_i32();
1629 TCGv_i32 v2
= tcg_temp_new_i32();
1630 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1631 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1632 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1638 default: /*reserved*/
1645 if (OP2
>= 8 && !gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1650 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1651 TCGLabel
*label
= gen_new_label();
1652 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1653 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1654 gen_set_label(label
);
1658 #define BOOLEAN_LOGIC(fn, r, s, t) \
1660 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1661 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1662 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1664 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1665 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1666 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1667 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1668 tcg_temp_free(tmp1); \
1669 tcg_temp_free(tmp2); \
1673 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1677 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1681 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1685 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1689 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1692 #undef BOOLEAN_LOGIC
1695 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1696 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1701 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1703 TCGv lo
= tcg_temp_new();
1706 tcg_gen_mulu2_i32(lo
, cpu_R
[RRR_R
],
1707 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1709 tcg_gen_muls2_i32(lo
, cpu_R
[RRR_R
],
1710 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1717 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1723 TCGLabel
*label1
= gen_new_label();
1724 TCGLabel
*label2
= gen_new_label();
1726 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1728 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1730 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1731 OP2
== 13 ? 0x80000000 : 0);
1733 gen_set_label(label1
);
1735 tcg_gen_div_i32(cpu_R
[RRR_R
],
1736 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1738 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1739 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1741 gen_set_label(label2
);
1746 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1749 default: /*reserved*/
1758 if (gen_check_sr(dc
, RSR_SR
, SR_R
) &&
1759 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1760 gen_window_check1(dc
, RRR_T
)) {
1761 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1766 if (gen_check_sr(dc
, RSR_SR
, SR_W
) &&
1767 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1768 gen_window_check1(dc
, RRR_T
)) {
1769 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1774 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1775 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1776 int shift
= 24 - RRR_T
;
1779 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1780 } else if (shift
== 16) {
1781 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1783 TCGv_i32 tmp
= tcg_temp_new_i32();
1784 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1785 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1792 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1793 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1794 TCGv_i32 tmp1
= tcg_temp_new_i32();
1795 TCGv_i32 tmp2
= tcg_temp_new_i32();
1796 TCGv_i32 zero
= tcg_const_i32(0);
1798 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1799 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1800 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1802 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1803 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1805 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1806 cpu_R
[RRR_S
], tmp1
);
1807 tcg_temp_free(tmp1
);
1808 tcg_temp_free(tmp2
);
1809 tcg_temp_free(zero
);
1817 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1818 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1819 static const TCGCond cond
[] = {
1825 tcg_gen_movcond_i32(cond
[OP2
- 4], cpu_R
[RRR_R
],
1826 cpu_R
[RRR_S
], cpu_R
[RRR_T
],
1827 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1835 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1836 static const TCGCond cond
[] = {
1842 TCGv_i32 zero
= tcg_const_i32(0);
1844 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1845 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1846 tcg_temp_free(zero
);
1852 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1853 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1854 TCGv_i32 zero
= tcg_const_i32(0);
1855 TCGv_i32 tmp
= tcg_temp_new_i32();
1857 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1858 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1859 cpu_R
[RRR_R
], tmp
, zero
,
1860 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1863 tcg_temp_free(zero
);
1868 if (gen_window_check1(dc
, RRR_R
)) {
1869 int st
= (RRR_S
<< 4) + RRR_T
;
1870 if (uregnames
[st
].name
) {
1871 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1873 qemu_log_mask(LOG_UNIMP
, "RUR %d not implemented, ", st
);
1880 if (gen_window_check1(dc
, RRR_T
)) {
1881 if (uregnames
[RSR_SR
].name
) {
1882 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1884 qemu_log_mask(LOG_UNIMP
, "WUR %d not implemented, ", RSR_SR
);
1895 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1896 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1897 int maskimm
= (1 << (OP2
+ 1)) - 1;
1899 TCGv_i32 tmp
= tcg_temp_new_i32();
1900 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1901 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1920 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1921 if (gen_window_check2(dc
, RRR_S
, RRR_T
) &&
1922 gen_check_cpenable(dc
, 0)) {
1923 TCGv_i32 addr
= tcg_temp_new_i32();
1924 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1925 gen_load_store_alignment(dc
, 2, addr
, false);
1927 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1929 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1932 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1934 tcg_temp_free(addr
);
1938 default: /*reserved*/
1945 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1950 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1951 if (gen_check_privilege(dc
) &&
1952 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1953 TCGv_i32 addr
= tcg_temp_new_i32();
1954 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1955 (0xffffffc0 | (RRR_R
<< 2)));
1956 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1957 tcg_temp_free(addr
);
1962 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1963 if (gen_check_privilege(dc
) &&
1964 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1965 TCGv_i32 addr
= tcg_temp_new_i32();
1966 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1967 (0xffffffc0 | (RRR_R
<< 2)));
1968 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1969 tcg_temp_free(addr
);
1974 if (gen_window_check2(dc
, RRI4_S
, RRI4_T
)) {
1975 TCGv_i32 addr
= tcg_temp_new_i32();
1977 tcg_gen_addi_i32(addr
, cpu_R
[RRI4_S
], RRI4_IMM4
<< 2);
1978 gen_load_store_alignment(dc
, 2, addr
, false);
1979 tcg_gen_qemu_st32(cpu_R
[RRI4_T
], addr
, dc
->cring
);
1980 tcg_temp_free(addr
);
1992 if (option_enabled(dc
, XTENSA_OPTION_DEPBITS
)) {
1993 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1996 tcg_gen_deposit_i32(cpu_R
[RRR_T
], cpu_R
[RRR_T
], cpu_R
[RRR_S
],
2001 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2004 if (gen_check_cpenable(dc
, 0)) {
2005 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
2006 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2011 if (gen_check_cpenable(dc
, 0)) {
2012 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
2013 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2018 if (gen_check_cpenable(dc
, 0)) {
2019 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
2020 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2025 if (gen_check_cpenable(dc
, 0)) {
2026 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
2027 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2033 if (gen_check_cpenable(dc
, 0)) {
2034 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
2035 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2040 case 8: /*ROUND.Sf*/
2041 case 9: /*TRUNC.Sf*/
2042 case 10: /*FLOOR.Sf*/
2043 case 11: /*CEIL.Sf*/
2044 case 14: /*UTRUNC.Sf*/
2045 if (gen_window_check1(dc
, RRR_R
) &&
2046 gen_check_cpenable(dc
, 0)) {
2047 static const unsigned rounding_mode_const
[] = {
2048 float_round_nearest_even
,
2049 float_round_to_zero
,
2052 [6] = float_round_to_zero
,
2054 TCGv_i32 rounding_mode
= tcg_const_i32(
2055 rounding_mode_const
[OP2
& 7]);
2056 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2059 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2060 rounding_mode
, scale
);
2062 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2063 rounding_mode
, scale
);
2066 tcg_temp_free(rounding_mode
);
2067 tcg_temp_free(scale
);
2071 case 12: /*FLOAT.Sf*/
2072 case 13: /*UFLOAT.Sf*/
2073 if (gen_window_check1(dc
, RRR_S
) &&
2074 gen_check_cpenable(dc
, 0)) {
2075 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2078 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2079 cpu_R
[RRR_S
], scale
);
2081 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2082 cpu_R
[RRR_S
], scale
);
2084 tcg_temp_free(scale
);
2091 if (gen_check_cpenable(dc
, 0)) {
2092 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2097 if (gen_check_cpenable(dc
, 0)) {
2098 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2103 if (gen_window_check1(dc
, RRR_R
) &&
2104 gen_check_cpenable(dc
, 0)) {
2105 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2110 if (gen_window_check1(dc
, RRR_S
) &&
2111 gen_check_cpenable(dc
, 0)) {
2112 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2117 if (gen_check_cpenable(dc
, 0)) {
2118 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2122 default: /*reserved*/
2128 default: /*reserved*/
2136 if (option_enabled(dc
, XTENSA_OPTION_DEPBITS
)) {
2137 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
2140 tcg_gen_deposit_i32(cpu_R
[RRR_T
], cpu_R
[RRR_T
], cpu_R
[RRR_S
],
2141 OP2
+ 16, RRR_R
+ 1);
2145 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2147 #define gen_compare(rel, br, a, b) \
2149 if (gen_check_cpenable(dc, 0)) { \
2150 TCGv_i32 bit = tcg_const_i32(1 << br); \
2152 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2153 tcg_temp_free(bit); \
2159 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2163 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2167 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2171 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2175 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2179 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2183 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2188 case 8: /*MOVEQZ.Sf*/
2189 case 9: /*MOVNEZ.Sf*/
2190 case 10: /*MOVLTZ.Sf*/
2191 case 11: /*MOVGEZ.Sf*/
2192 if (gen_window_check1(dc
, RRR_T
) &&
2193 gen_check_cpenable(dc
, 0)) {
2194 static const TCGCond cond
[] = {
2200 TCGv_i32 zero
= tcg_const_i32(0);
2202 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2203 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2204 tcg_temp_free(zero
);
2208 case 12: /*MOVF.Sf*/
2209 case 13: /*MOVT.Sf*/
2210 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2211 if (gen_check_cpenable(dc
, 0)) {
2212 TCGv_i32 zero
= tcg_const_i32(0);
2213 TCGv_i32 tmp
= tcg_temp_new_i32();
2215 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2216 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2217 cpu_FR
[RRR_R
], tmp
, zero
,
2218 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2221 tcg_temp_free(zero
);
2225 default: /*reserved*/
2231 default: /*reserved*/
2238 if (gen_window_check1(dc
, RRR_T
)) {
2239 TCGv_i32 tmp
= tcg_const_i32(
2240 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2241 0 : ((dc
->pc
+ 3) & ~3)) +
2242 (0xfffc0000 | (RI16_IMM16
<< 2)));
2244 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2245 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2247 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2253 #define gen_load_store(type, shift) do { \
2254 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2255 TCGv_i32 addr = tcg_temp_new_i32(); \
2257 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2259 gen_load_store_alignment(dc, shift, addr, false); \
2261 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2262 tcg_temp_free(addr); \
2268 gen_load_store(ld8u
, 0);
2272 gen_load_store(ld16u
, 1);
2276 gen_load_store(ld32u
, 2);
2280 gen_load_store(st8
, 0);
2284 gen_load_store(st16
, 1);
2288 gen_load_store(st32
, 2);
2291 #define gen_dcache_hit_test(w, shift) do { \
2292 if (gen_window_check1(dc, RRI##w##_S)) { \
2293 TCGv_i32 addr = tcg_temp_new_i32(); \
2294 TCGv_i32 res = tcg_temp_new_i32(); \
2295 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2296 RRI##w##_IMM##w << shift); \
2297 tcg_gen_qemu_ld8u(res, addr, dc->cring); \
2298 tcg_temp_free(addr); \
2299 tcg_temp_free(res); \
2303 #define gen_dcache_hit_test4() gen_dcache_hit_test(4, 4)
2304 #define gen_dcache_hit_test8() gen_dcache_hit_test(8, 2)
2308 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2313 gen_window_check1(dc
, RRI8_S
);
2317 gen_window_check1(dc
, RRI8_S
);
2321 gen_window_check1(dc
, RRI8_S
);
2325 gen_window_check1(dc
, RRI8_S
);
2329 gen_dcache_hit_test8();
2333 gen_dcache_hit_test8();
2337 if (gen_check_privilege(dc
)) {
2338 gen_dcache_hit_test8();
2343 if (gen_check_privilege(dc
)) {
2344 gen_window_check1(dc
, RRI8_S
);
2351 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2352 if (gen_check_privilege(dc
)) {
2353 gen_dcache_hit_test4();
2358 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2359 if (gen_check_privilege(dc
)) {
2360 gen_dcache_hit_test4();
2365 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2366 if (gen_check_privilege(dc
)) {
2367 gen_window_check1(dc
, RRI4_S
);
2372 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2373 if (gen_check_privilege(dc
)) {
2374 gen_window_check1(dc
, RRI4_S
);
2379 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2380 if (gen_check_privilege(dc
)) {
2381 gen_window_check1(dc
, RRI4_S
);
2385 default: /*reserved*/
2392 #undef gen_dcache_hit_test
2393 #undef gen_dcache_hit_test4
2394 #undef gen_dcache_hit_test8
2396 #define gen_icache_hit_test(w, shift) do { \
2397 if (gen_window_check1(dc, RRI##w##_S)) { \
2398 TCGv_i32 addr = tcg_temp_new_i32(); \
2399 tcg_gen_movi_i32(cpu_pc, dc->pc); \
2400 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2401 RRI##w##_IMM##w << shift); \
2402 gen_helper_itlb_hit_test(cpu_env, addr); \
2403 tcg_temp_free(addr); \
2407 #define gen_icache_hit_test4() gen_icache_hit_test(4, 4)
2408 #define gen_icache_hit_test8() gen_icache_hit_test(8, 2)
2411 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2412 gen_window_check1(dc
, RRI8_S
);
2418 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2419 if (gen_check_privilege(dc
)) {
2420 gen_icache_hit_test4();
2425 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2426 if (gen_check_privilege(dc
)) {
2427 gen_icache_hit_test4();
2432 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2433 if (gen_check_privilege(dc
)) {
2434 gen_window_check1(dc
, RRI4_S
);
2438 default: /*reserved*/
2445 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2446 gen_icache_hit_test8();
2450 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2451 if (gen_check_privilege(dc
)) {
2452 gen_window_check1(dc
, RRI8_S
);
2456 default: /*reserved*/
2462 #undef gen_icache_hit_test
2463 #undef gen_icache_hit_test4
2464 #undef gen_icache_hit_test8
2467 gen_load_store(ld16s
, 1);
2469 #undef gen_load_store
2472 if (gen_window_check1(dc
, RRI8_T
)) {
2473 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2474 RRI8_IMM8
| (RRI8_S
<< 8) |
2475 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2479 #define gen_load_store_no_hw_align(type) do { \
2480 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2481 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2482 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2483 gen_load_store_alignment(dc, 2, addr, true); \
2484 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2485 tcg_temp_free(addr); \
2490 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2491 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2495 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2496 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2501 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2502 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
],
2507 case 14: /*S32C1Iy*/
2508 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2509 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2510 TCGLabel
*label
= gen_new_label();
2511 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2512 TCGv_i32 addr
= tcg_temp_local_new_i32();
2515 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2516 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2517 gen_load_store_alignment(dc
, 2, addr
, true);
2519 gen_advance_ccount(dc
);
2520 tpc
= tcg_const_i32(dc
->pc
);
2521 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2522 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2523 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2524 cpu_SR
[SCOMPARE1
], label
);
2526 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2528 gen_set_label(label
);
2530 tcg_temp_free(addr
);
2536 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2537 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2539 #undef gen_load_store_no_hw_align
2541 default: /*reserved*/
2553 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2554 if (gen_window_check1(dc
, RRI8_S
) &&
2555 gen_check_cpenable(dc
, 0)) {
2556 TCGv_i32 addr
= tcg_temp_new_i32();
2557 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2558 gen_load_store_alignment(dc
, 2, addr
, false);
2560 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2562 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2565 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2567 tcg_temp_free(addr
);
2571 default: /*reserved*/
2578 HAS_OPTION(XTENSA_OPTION_MAC16
);
2587 bool is_m1_sr
= (OP2
& 0x3) == 2;
2588 bool is_m2_sr
= (OP2
& 0xc) == 0;
2589 uint32_t ld_offset
= 0;
2596 case 0: /*MACI?/MACC?*/
2598 ld_offset
= (OP2
& 1) ? -4 : 4;
2600 if (OP2
>= 8) { /*MACI/MACC*/
2601 if (OP1
== 0) { /*LDINC/LDDEC*/
2606 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2611 case 2: /*MACD?/MACA?*/
2612 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2618 if (op
!= MAC16_NONE
) {
2619 if (!is_m1_sr
&& !gen_window_check1(dc
, RRR_S
)) {
2622 if (!is_m2_sr
&& !gen_window_check1(dc
, RRR_T
)) {
2627 if (ld_offset
&& !gen_window_check1(dc
, RRR_S
)) {
2632 TCGv_i32 vaddr
= tcg_temp_new_i32();
2633 TCGv_i32 mem32
= tcg_temp_new_i32();
2636 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2637 gen_load_store_alignment(dc
, 2, vaddr
, false);
2638 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2640 if (op
!= MAC16_NONE
) {
2641 TCGv_i32 m1
= gen_mac16_m(
2642 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2643 OP1
& 1, op
== MAC16_UMUL
);
2644 TCGv_i32 m2
= gen_mac16_m(
2645 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2646 OP1
& 2, op
== MAC16_UMUL
);
2648 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2649 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2650 if (op
== MAC16_UMUL
) {
2651 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2653 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2656 TCGv_i32 lo
= tcg_temp_new_i32();
2657 TCGv_i32 hi
= tcg_temp_new_i32();
2659 tcg_gen_mul_i32(lo
, m1
, m2
);
2660 tcg_gen_sari_i32(hi
, lo
, 31);
2661 if (op
== MAC16_MULA
) {
2662 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2663 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2666 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2667 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2670 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2672 tcg_temp_free_i32(lo
);
2673 tcg_temp_free_i32(hi
);
2679 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2680 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2682 tcg_temp_free(vaddr
);
2683 tcg_temp_free(mem32
);
2691 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2692 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2698 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2699 if (gen_window_check1(dc
, CALL_N
<< 2)) {
2700 gen_callwi(dc
, CALL_N
,
2701 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2710 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2714 if (gen_window_check1(dc
, BRI12_S
)) {
2715 static const TCGCond cond
[] = {
2716 TCG_COND_EQ
, /*BEQZ*/
2717 TCG_COND_NE
, /*BNEZ*/
2718 TCG_COND_LT
, /*BLTZ*/
2719 TCG_COND_GE
, /*BGEZ*/
2722 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2723 4 + BRI12_IMM12_SE
);
2728 if (gen_window_check1(dc
, BRI8_S
)) {
2729 static const TCGCond cond
[] = {
2730 TCG_COND_EQ
, /*BEQI*/
2731 TCG_COND_NE
, /*BNEI*/
2732 TCG_COND_LT
, /*BLTI*/
2733 TCG_COND_GE
, /*BGEI*/
2736 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2737 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2744 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2746 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2747 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2748 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2749 gen_advance_ccount(dc
);
2750 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2754 /* This can change tb->flags, so exit tb */
2755 gen_jumpi_check_loop_end(dc
, -1);
2763 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2765 TCGv_i32 tmp
= tcg_temp_new_i32();
2766 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2768 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2769 tmp
, 0, 4 + RRI8_IMM8_SE
);
2776 case 10: /*LOOPGTZ*/
2777 HAS_OPTION(XTENSA_OPTION_LOOP
);
2778 if (gen_window_check1(dc
, RRI8_S
)) {
2779 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2780 TCGv_i32 tmp
= tcg_const_i32(lend
);
2782 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2783 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2784 gen_helper_wsr_lend(cpu_env
, tmp
);
2788 TCGLabel
*label
= gen_new_label();
2789 tcg_gen_brcondi_i32(
2790 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2791 cpu_R
[RRI8_S
], 0, label
);
2792 gen_jumpi(dc
, lend
, 1);
2793 gen_set_label(label
);
2796 gen_jumpi(dc
, dc
->next_pc
, 0);
2800 default: /*reserved*/
2809 if (gen_window_check1(dc
, BRI8_S
)) {
2810 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2811 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
],
2823 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2825 switch (RRI8_R
& 7) {
2826 case 0: /*BNONE*/ /*BANY*/
2827 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2828 TCGv_i32 tmp
= tcg_temp_new_i32();
2829 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2830 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2835 case 1: /*BEQ*/ /*BNE*/
2836 case 2: /*BLT*/ /*BGE*/
2837 case 3: /*BLTU*/ /*BGEU*/
2838 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2839 static const TCGCond cond
[] = {
2845 [11] = TCG_COND_GEU
,
2847 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2852 case 4: /*BALL*/ /*BNALL*/
2853 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2854 TCGv_i32 tmp
= tcg_temp_new_i32();
2855 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2856 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2862 case 5: /*BBC*/ /*BBS*/
2863 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2864 #ifdef TARGET_WORDS_BIGENDIAN
2865 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2867 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2869 TCGv_i32 tmp
= tcg_temp_new_i32();
2870 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2871 #ifdef TARGET_WORDS_BIGENDIAN
2872 tcg_gen_shr_i32(bit
, bit
, tmp
);
2874 tcg_gen_shl_i32(bit
, bit
, tmp
);
2876 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2877 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2883 case 6: /*BBCI*/ /*BBSI*/
2885 if (gen_window_check1(dc
, RRI8_S
)) {
2886 TCGv_i32 tmp
= tcg_temp_new_i32();
2887 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2888 #ifdef TARGET_WORDS_BIGENDIAN
2889 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2891 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2893 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2902 #define gen_narrow_load_store(type) do { \
2903 if (gen_window_check2(dc, RRRN_S, RRRN_T)) { \
2904 TCGv_i32 addr = tcg_temp_new_i32(); \
2905 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2906 gen_load_store_alignment(dc, 2, addr, false); \
2907 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2908 tcg_temp_free(addr); \
2913 gen_narrow_load_store(ld32u
);
2917 gen_narrow_load_store(st32
);
2919 #undef gen_narrow_load_store
2922 if (gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
)) {
2923 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2927 case 11: /*ADDI.Nn*/
2928 if (gen_window_check2(dc
, RRRN_R
, RRRN_S
)) {
2929 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
],
2930 RRRN_T
? RRRN_T
: -1);
2935 if (!gen_window_check1(dc
, RRRN_S
)) {
2938 if (RRRN_T
< 8) { /*MOVI.Nn*/
2939 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2940 RRRN_R
| (RRRN_T
<< 4) |
2941 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2942 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2943 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2945 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2946 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2953 if (gen_window_check2(dc
, RRRN_S
, RRRN_T
)) {
2954 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2961 gen_jump(dc
, cpu_R
[0]);
2965 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2967 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2968 gen_advance_ccount(dc
);
2969 gen_helper_retw(tmp
, cpu_env
, tmp
);
2975 case 2: /*BREAK.Nn*/
2976 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2978 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2986 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2989 default: /*reserved*/
2995 default: /*reserved*/
3001 default: /*reserved*/
3006 if (dc
->is_jmp
== DISAS_NEXT
) {
3007 gen_check_loop_end(dc
, 0);
3009 dc
->pc
= dc
->next_pc
;
3014 qemu_log_mask(LOG_GUEST_ERROR
, "INVALID(pc = %08x)\n", dc
->pc
);
3015 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
3019 static inline unsigned xtensa_insn_len(CPUXtensaState
*env
, DisasContext
*dc
)
3021 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
3022 return xtensa_op0_insn_len(OP0
);
3025 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
3029 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
3030 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
3031 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
3032 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
3038 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3040 XtensaCPU
*cpu
= xtensa_env_get_cpu(env
);
3041 CPUState
*cs
= CPU(cpu
);
3044 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3045 uint32_t pc_start
= tb
->pc
;
3046 uint32_t next_page_start
=
3047 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3049 if (max_insns
== 0) {
3050 max_insns
= CF_COUNT_MASK
;
3052 if (max_insns
> TCG_MAX_INSNS
) {
3053 max_insns
= TCG_MAX_INSNS
;
3056 dc
.config
= env
->config
;
3057 dc
.singlestep_enabled
= cs
->singlestep_enabled
;
3060 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
3061 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
3062 dc
.lbeg
= env
->sregs
[LBEG
];
3063 dc
.lend
= env
->sregs
[LEND
];
3064 dc
.is_jmp
= DISAS_NEXT
;
3065 dc
.ccount_delta
= 0;
3066 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
3067 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
3068 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
3069 XTENSA_TBFLAG_CPENABLE_SHIFT
;
3070 dc
.window
= ((tb
->flags
& XTENSA_TBFLAG_WINDOW_MASK
) >>
3071 XTENSA_TBFLAG_WINDOW_SHIFT
);
3074 init_sar_tracker(&dc
);
3076 dc
.next_icount
= tcg_temp_local_new_i32();
3081 if (tb
->flags
& XTENSA_TBFLAG_EXCEPTION
) {
3082 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3083 gen_exception(&dc
, EXCP_DEBUG
);
3087 tcg_gen_insn_start(dc
.pc
);
3092 if (unlikely(cpu_breakpoint_test(cs
, dc
.pc
, BP_ANY
))) {
3093 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3094 gen_exception(&dc
, EXCP_DEBUG
);
3095 dc
.is_jmp
= DISAS_UPDATE
;
3096 /* The address covered by the breakpoint must be included in
3097 [tb->pc, tb->pc + tb->size) in order to for it to be
3098 properly cleared -- thus we increment the PC here so that
3099 the logic setting tb->size below does the right thing. */
3104 if (insn_count
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3109 TCGLabel
*label
= gen_new_label();
3111 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
3112 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
3113 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
3115 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
3117 gen_set_label(label
);
3121 gen_ibreak_check(env
, &dc
);
3124 disas_xtensa_insn(env
, &dc
);
3126 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
3128 if (cs
->singlestep_enabled
) {
3129 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3130 gen_exception(&dc
, EXCP_DEBUG
);
3133 } while (dc
.is_jmp
== DISAS_NEXT
&&
3134 insn_count
< max_insns
&&
3135 dc
.pc
< next_page_start
&&
3136 dc
.pc
+ xtensa_insn_len(env
, &dc
) <= next_page_start
&&
3137 !tcg_op_buf_full());
3140 reset_sar_tracker(&dc
);
3142 tcg_temp_free(dc
.next_icount
);
3145 if (tb
->cflags
& CF_LAST_IO
) {
3149 if (dc
.is_jmp
== DISAS_NEXT
) {
3150 gen_jumpi(&dc
, dc
.pc
, 0);
3152 gen_tb_end(tb
, insn_count
);
3155 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3156 qemu_log("----------------\n");
3157 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3158 log_target_disas(cs
, pc_start
, dc
.pc
- pc_start
, 0);
3162 tb
->size
= dc
.pc
- pc_start
;
3163 tb
->icount
= insn_count
;
3166 void xtensa_cpu_dump_state(CPUState
*cs
, FILE *f
,
3167 fprintf_function cpu_fprintf
, int flags
)
3169 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
3170 CPUXtensaState
*env
= &cpu
->env
;
3173 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3175 for (i
= j
= 0; i
< 256; ++i
) {
3176 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3177 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3178 (j
++ % 4) == 3 ? '\n' : ' ');
3182 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3184 for (i
= j
= 0; i
< 256; ++i
) {
3185 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3186 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3187 (j
++ % 4) == 3 ? '\n' : ' ');
3191 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3193 for (i
= 0; i
< 16; ++i
) {
3194 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3195 (i
% 4) == 3 ? '\n' : ' ');
3198 cpu_fprintf(f
, "\n");
3200 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3201 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3202 (i
% 4) == 3 ? '\n' : ' ');
3205 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3206 cpu_fprintf(f
, "\n");
3208 for (i
= 0; i
< 16; ++i
) {
3209 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3210 float32_val(env
->fregs
[i
].f32
[FP_F32_LOW
]),
3211 *(float *)(env
->fregs
[i
].f32
+ FP_F32_LOW
),
3212 (i
% 2) == 1 ? '\n' : ' ');
3217 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
,