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
;
76 static TCGv_env cpu_env
;
77 static TCGv_i32 cpu_pc
;
78 static TCGv_i32 cpu_R
[16];
79 static TCGv_i32 cpu_FR
[16];
80 static TCGv_i32 cpu_SR
[256];
81 static TCGv_i32 cpu_UR
[256];
83 #include "exec/gen-icount.h"
85 typedef struct XtensaReg
{
97 #define XTENSA_REG_ACCESS(regname, opt, acc) { \
99 .opt_bits = XTENSA_OPTION_BIT(opt), \
103 #define XTENSA_REG(regname, opt) XTENSA_REG_ACCESS(regname, opt, SR_RWX)
105 #define XTENSA_REG_BITS_ACCESS(regname, opt, acc) { \
111 #define XTENSA_REG_BITS(regname, opt) \
112 XTENSA_REG_BITS_ACCESS(regname, opt, SR_RWX)
114 static const XtensaReg sregnames
[256] = {
115 [LBEG
] = XTENSA_REG("LBEG", XTENSA_OPTION_LOOP
),
116 [LEND
] = XTENSA_REG("LEND", XTENSA_OPTION_LOOP
),
117 [LCOUNT
] = XTENSA_REG("LCOUNT", XTENSA_OPTION_LOOP
),
118 [SAR
] = XTENSA_REG_BITS("SAR", XTENSA_OPTION_ALL
),
119 [BR
] = XTENSA_REG("BR", XTENSA_OPTION_BOOLEAN
),
120 [LITBASE
] = XTENSA_REG("LITBASE", XTENSA_OPTION_EXTENDED_L32R
),
121 [SCOMPARE1
] = XTENSA_REG("SCOMPARE1", XTENSA_OPTION_CONDITIONAL_STORE
),
122 [ACCLO
] = XTENSA_REG("ACCLO", XTENSA_OPTION_MAC16
),
123 [ACCHI
] = XTENSA_REG("ACCHI", XTENSA_OPTION_MAC16
),
124 [MR
] = XTENSA_REG("MR0", XTENSA_OPTION_MAC16
),
125 [MR
+ 1] = XTENSA_REG("MR1", XTENSA_OPTION_MAC16
),
126 [MR
+ 2] = XTENSA_REG("MR2", XTENSA_OPTION_MAC16
),
127 [MR
+ 3] = XTENSA_REG("MR3", XTENSA_OPTION_MAC16
),
128 [WINDOW_BASE
] = XTENSA_REG("WINDOW_BASE", XTENSA_OPTION_WINDOWED_REGISTER
),
129 [WINDOW_START
] = XTENSA_REG("WINDOW_START",
130 XTENSA_OPTION_WINDOWED_REGISTER
),
131 [PTEVADDR
] = XTENSA_REG("PTEVADDR", XTENSA_OPTION_MMU
),
132 [RASID
] = XTENSA_REG("RASID", XTENSA_OPTION_MMU
),
133 [ITLBCFG
] = XTENSA_REG("ITLBCFG", XTENSA_OPTION_MMU
),
134 [DTLBCFG
] = XTENSA_REG("DTLBCFG", XTENSA_OPTION_MMU
),
135 [IBREAKENABLE
] = XTENSA_REG("IBREAKENABLE", XTENSA_OPTION_DEBUG
),
136 [MEMCTL
] = XTENSA_REG_BITS("MEMCTL", XTENSA_OPTION_ALL
),
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 tcg_ctx
.tcg_env
= cpu_env
;
222 cpu_pc
= tcg_global_mem_new_i32(cpu_env
,
223 offsetof(CPUXtensaState
, pc
), "pc");
225 for (i
= 0; i
< 16; i
++) {
226 cpu_R
[i
] = tcg_global_mem_new_i32(cpu_env
,
227 offsetof(CPUXtensaState
, regs
[i
]),
231 for (i
= 0; i
< 16; i
++) {
232 cpu_FR
[i
] = tcg_global_mem_new_i32(cpu_env
,
233 offsetof(CPUXtensaState
, fregs
[i
].f32
[FP_F32_LOW
]),
237 for (i
= 0; i
< 256; ++i
) {
238 if (sregnames
[i
].name
) {
239 cpu_SR
[i
] = tcg_global_mem_new_i32(cpu_env
,
240 offsetof(CPUXtensaState
, sregs
[i
]),
245 for (i
= 0; i
< 256; ++i
) {
246 if (uregnames
[i
].name
) {
247 cpu_UR
[i
] = tcg_global_mem_new_i32(cpu_env
,
248 offsetof(CPUXtensaState
, uregs
[i
]),
254 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
256 return xtensa_option_bits_enabled(dc
->config
, opt
);
259 static inline bool option_enabled(DisasContext
*dc
, int opt
)
261 return xtensa_option_enabled(dc
->config
, opt
);
264 static void init_litbase(DisasContext
*dc
)
266 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
267 dc
->litbase
= tcg_temp_local_new_i32();
268 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
272 static void reset_litbase(DisasContext
*dc
)
274 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
275 tcg_temp_free(dc
->litbase
);
279 static void init_sar_tracker(DisasContext
*dc
)
281 dc
->sar_5bit
= false;
282 dc
->sar_m32_5bit
= false;
283 dc
->sar_m32_allocated
= false;
286 static void reset_sar_tracker(DisasContext
*dc
)
288 if (dc
->sar_m32_allocated
) {
289 tcg_temp_free(dc
->sar_m32
);
293 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
295 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
296 if (dc
->sar_m32_5bit
) {
297 tcg_gen_discard_i32(dc
->sar_m32
);
300 dc
->sar_m32_5bit
= false;
303 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
305 TCGv_i32 tmp
= tcg_const_i32(32);
306 if (!dc
->sar_m32_allocated
) {
307 dc
->sar_m32
= tcg_temp_local_new_i32();
308 dc
->sar_m32_allocated
= true;
310 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
311 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
312 dc
->sar_5bit
= false;
313 dc
->sar_m32_5bit
= true;
317 static void gen_exception(DisasContext
*dc
, int excp
)
319 TCGv_i32 tmp
= tcg_const_i32(excp
);
320 gen_helper_exception(cpu_env
, tmp
);
324 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
326 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
327 TCGv_i32 tcause
= tcg_const_i32(cause
);
328 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
330 tcg_temp_free(tcause
);
331 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
332 cause
== SYSCALL_CAUSE
) {
333 dc
->is_jmp
= DISAS_UPDATE
;
337 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
340 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
341 TCGv_i32 tcause
= tcg_const_i32(cause
);
342 gen_helper_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
344 tcg_temp_free(tcause
);
347 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
349 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
350 TCGv_i32 tcause
= tcg_const_i32(cause
);
351 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
353 tcg_temp_free(tcause
);
354 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
355 dc
->is_jmp
= DISAS_UPDATE
;
359 static bool gen_check_privilege(DisasContext
*dc
)
362 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
363 dc
->is_jmp
= DISAS_UPDATE
;
369 static bool gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
371 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
372 !(dc
->cpenable
& (1 << cp
))) {
373 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
374 dc
->is_jmp
= DISAS_UPDATE
;
380 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
382 tcg_gen_mov_i32(cpu_pc
, dest
);
384 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
->next_icount
);
386 if (dc
->singlestep_enabled
) {
387 gen_exception(dc
, EXCP_DEBUG
);
390 tcg_gen_goto_tb(slot
);
391 tcg_gen_exit_tb((uintptr_t)dc
->tb
+ slot
);
396 dc
->is_jmp
= DISAS_UPDATE
;
399 static void gen_jump(DisasContext
*dc
, TCGv dest
)
401 gen_jump_slot(dc
, dest
, -1);
404 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
406 TCGv_i32 tmp
= tcg_const_i32(dest
);
407 #ifndef CONFIG_USER_ONLY
408 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
412 gen_jump_slot(dc
, tmp
, slot
);
416 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
419 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
421 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
422 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
423 tcg_temp_free(tcallinc
);
424 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
425 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
426 gen_jump_slot(dc
, dest
, slot
);
429 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
431 gen_callw_slot(dc
, callinc
, dest
, -1);
434 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
436 TCGv_i32 tmp
= tcg_const_i32(dest
);
437 #ifndef CONFIG_USER_ONLY
438 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
442 gen_callw_slot(dc
, callinc
, tmp
, slot
);
446 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
448 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
449 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
450 dc
->next_pc
== dc
->lend
) {
451 TCGLabel
*label
= gen_new_label();
453 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
454 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
455 gen_jumpi(dc
, dc
->lbeg
, slot
);
456 gen_set_label(label
);
457 gen_jumpi(dc
, dc
->next_pc
, -1);
463 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
465 if (!gen_check_loop_end(dc
, slot
)) {
466 gen_jumpi(dc
, dc
->next_pc
, slot
);
470 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
471 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
473 TCGLabel
*label
= gen_new_label();
475 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
476 gen_jumpi_check_loop_end(dc
, 0);
477 gen_set_label(label
);
478 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
481 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
482 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
484 TCGv_i32 tmp
= tcg_const_i32(t1
);
485 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
489 static bool gen_check_sr(DisasContext
*dc
, uint32_t sr
, unsigned access
)
491 if (!xtensa_option_bits_enabled(dc
->config
, sregnames
[sr
].opt_bits
)) {
492 if (sregnames
[sr
].name
) {
493 qemu_log_mask(LOG_GUEST_ERROR
, "SR %s is not configured\n", sregnames
[sr
].name
);
495 qemu_log_mask(LOG_UNIMP
, "SR %d is not implemented\n", sr
);
497 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
499 } else if (!(sregnames
[sr
].access
& access
)) {
500 static const char * const access_text
[] = {
505 assert(access
< ARRAY_SIZE(access_text
) && access_text
[access
]);
506 qemu_log_mask(LOG_GUEST_ERROR
, "SR %s is not available for %s\n", sregnames
[sr
].name
,
507 access_text
[access
]);
508 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
514 static bool gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
516 if (dc
->tb
->cflags
& CF_USE_ICOUNT
) {
519 gen_helper_update_ccount(cpu_env
);
520 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
521 if (dc
->tb
->cflags
& CF_USE_ICOUNT
) {
528 static bool gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
530 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
531 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
532 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
536 static bool gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
538 static bool (* const rsr_handler
[256])(DisasContext
*dc
,
539 TCGv_i32 d
, uint32_t sr
) = {
540 [CCOUNT
] = gen_rsr_ccount
,
541 [INTSET
] = gen_rsr_ccount
,
542 [PTEVADDR
] = gen_rsr_ptevaddr
,
545 if (rsr_handler
[sr
]) {
546 return rsr_handler
[sr
](dc
, d
, sr
);
548 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
553 static bool gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
555 gen_helper_wsr_lbeg(cpu_env
, s
);
556 gen_jumpi_check_loop_end(dc
, 0);
560 static bool 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);
567 static bool gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
569 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
570 if (dc
->sar_m32_5bit
) {
571 tcg_gen_discard_i32(dc
->sar_m32
);
573 dc
->sar_5bit
= false;
574 dc
->sar_m32_5bit
= false;
578 static bool gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
580 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
584 static bool gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
586 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
587 /* This can change tb->flags, so exit tb */
588 gen_jumpi_check_loop_end(dc
, -1);
592 static bool gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
594 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
598 static bool gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
600 gen_helper_wsr_windowbase(cpu_env
, v
);
601 /* This can change tb->flags, so exit tb */
602 gen_jumpi_check_loop_end(dc
, -1);
606 static bool gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
608 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
609 /* This can change tb->flags, so exit tb */
610 gen_jumpi_check_loop_end(dc
, -1);
614 static bool gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
616 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
620 static bool gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
622 gen_helper_wsr_rasid(cpu_env
, v
);
623 /* This can change tb->flags, so exit tb */
624 gen_jumpi_check_loop_end(dc
, -1);
628 static bool gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
630 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
634 static bool gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
636 gen_helper_wsr_ibreakenable(cpu_env
, v
);
637 gen_jumpi_check_loop_end(dc
, 0);
641 static bool gen_wsr_memctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
643 gen_helper_wsr_memctl(cpu_env
, v
);
647 static bool gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
649 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
653 static bool gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
655 unsigned id
= sr
- IBREAKA
;
657 if (id
< dc
->config
->nibreak
) {
658 TCGv_i32 tmp
= tcg_const_i32(id
);
659 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
661 gen_jumpi_check_loop_end(dc
, 0);
667 static bool gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
669 unsigned id
= sr
- DBREAKA
;
671 if (id
< dc
->config
->ndbreak
) {
672 TCGv_i32 tmp
= tcg_const_i32(id
);
673 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
679 static bool gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
681 unsigned id
= sr
- DBREAKC
;
683 if (id
< dc
->config
->ndbreak
) {
684 TCGv_i32 tmp
= tcg_const_i32(id
);
685 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
691 static bool gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
693 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
694 /* This can change tb->flags, so exit tb */
695 gen_jumpi_check_loop_end(dc
, -1);
699 static void gen_check_interrupts(DisasContext
*dc
)
701 if (dc
->tb
->cflags
& CF_USE_ICOUNT
) {
704 gen_helper_check_interrupts(cpu_env
);
705 if (dc
->tb
->cflags
& CF_USE_ICOUNT
) {
710 static bool gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
712 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
713 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
714 gen_check_interrupts(dc
);
715 gen_jumpi_check_loop_end(dc
, 0);
719 static bool gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
721 TCGv_i32 tmp
= tcg_temp_new_i32();
723 tcg_gen_andi_i32(tmp
, v
,
724 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
725 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
726 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
727 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
729 gen_check_interrupts(dc
);
730 gen_jumpi_check_loop_end(dc
, 0);
734 static bool gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
736 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
737 gen_check_interrupts(dc
);
738 gen_jumpi_check_loop_end(dc
, 0);
742 static bool gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
744 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
745 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
747 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
750 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
751 gen_check_interrupts(dc
);
752 /* This can change mmu index and tb->flags, so exit tb */
753 gen_jumpi_check_loop_end(dc
, -1);
757 static bool gen_wsr_ccount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
759 if (dc
->tb
->cflags
& CF_USE_ICOUNT
) {
762 gen_helper_wsr_ccount(cpu_env
, v
);
763 if (dc
->tb
->cflags
& CF_USE_ICOUNT
) {
765 gen_jumpi_check_loop_end(dc
, 0);
771 static bool gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
774 tcg_gen_mov_i32(dc
->next_icount
, v
);
776 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
781 static bool gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
783 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
784 /* This can change tb->flags, so exit tb */
785 gen_jumpi_check_loop_end(dc
, -1);
789 static bool gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
791 uint32_t id
= sr
- CCOMPARE
;
794 if (id
< dc
->config
->nccompare
) {
795 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
796 TCGv_i32 tmp
= tcg_const_i32(id
);
798 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
799 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
800 if (dc
->tb
->cflags
& CF_USE_ICOUNT
) {
803 gen_helper_update_ccompare(cpu_env
, tmp
);
804 if (dc
->tb
->cflags
& CF_USE_ICOUNT
) {
806 gen_jumpi_check_loop_end(dc
, 0);
814 static bool gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
816 static bool (* const wsr_handler
[256])(DisasContext
*dc
,
817 uint32_t sr
, TCGv_i32 v
) = {
818 [LBEG
] = gen_wsr_lbeg
,
819 [LEND
] = gen_wsr_lend
,
822 [LITBASE
] = gen_wsr_litbase
,
823 [ACCHI
] = gen_wsr_acchi
,
824 [WINDOW_BASE
] = gen_wsr_windowbase
,
825 [WINDOW_START
] = gen_wsr_windowstart
,
826 [PTEVADDR
] = gen_wsr_ptevaddr
,
827 [RASID
] = gen_wsr_rasid
,
828 [ITLBCFG
] = gen_wsr_tlbcfg
,
829 [DTLBCFG
] = gen_wsr_tlbcfg
,
830 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
831 [MEMCTL
] = gen_wsr_memctl
,
832 [ATOMCTL
] = gen_wsr_atomctl
,
833 [IBREAKA
] = gen_wsr_ibreaka
,
834 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
835 [DBREAKA
] = gen_wsr_dbreaka
,
836 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
837 [DBREAKC
] = gen_wsr_dbreakc
,
838 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
839 [CPENABLE
] = gen_wsr_cpenable
,
840 [INTSET
] = gen_wsr_intset
,
841 [INTCLEAR
] = gen_wsr_intclear
,
842 [INTENABLE
] = gen_wsr_intenable
,
844 [CCOUNT
] = gen_wsr_ccount
,
845 [ICOUNT
] = gen_wsr_icount
,
846 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
847 [CCOMPARE
] = gen_wsr_ccompare
,
848 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
849 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
852 if (wsr_handler
[sr
]) {
853 return wsr_handler
[sr
](dc
, sr
, s
);
855 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
860 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
864 gen_helper_wur_fcr(cpu_env
, s
);
868 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
872 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
877 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
878 TCGv_i32 addr
, bool no_hw_alignment
)
880 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
881 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
882 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
884 TCGLabel
*label
= gen_new_label();
885 TCGv_i32 tmp
= tcg_temp_new_i32();
886 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
887 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
888 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
889 gen_set_label(label
);
894 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
896 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
897 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
899 if (dc
->tb
->cflags
& CF_USE_ICOUNT
) {
902 gen_helper_waiti(cpu_env
, pc
, intlevel
);
903 if (dc
->tb
->cflags
& CF_USE_ICOUNT
) {
907 tcg_temp_free(intlevel
);
908 gen_jumpi_check_loop_end(dc
, 0);
911 static bool gen_window_check1(DisasContext
*dc
, unsigned r1
)
913 if (r1
/ 4 > dc
->window
) {
914 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
915 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
917 gen_helper_window_check(cpu_env
, pc
, w
);
918 dc
->is_jmp
= DISAS_UPDATE
;
924 static bool gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
926 return gen_window_check1(dc
, r1
> r2
? r1
: r2
);
929 static bool gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
932 return gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
935 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
937 TCGv_i32 m
= tcg_temp_new_i32();
940 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
942 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
947 static inline unsigned xtensa_op0_insn_len(unsigned op0
)
949 return op0
>= 8 ? 2 : 3;
952 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
954 #define HAS_OPTION_BITS(opt) do { \
955 if (!option_bits_enabled(dc, opt)) { \
956 qemu_log_mask(LOG_GUEST_ERROR, "Option is not enabled %s:%d\n", \
957 __FILE__, __LINE__); \
958 goto invalid_opcode; \
962 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
964 #define TBD() qemu_log_mask(LOG_UNIMP, "TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
965 #define RESERVED() do { \
966 qemu_log_mask(LOG_GUEST_ERROR, "RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
967 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
968 goto invalid_opcode; \
972 #ifdef TARGET_WORDS_BIGENDIAN
973 #define OP0 (((b0) & 0xf0) >> 4)
974 #define OP1 (((b2) & 0xf0) >> 4)
975 #define OP2 ((b2) & 0xf)
976 #define RRR_R ((b1) & 0xf)
977 #define RRR_S (((b1) & 0xf0) >> 4)
978 #define RRR_T ((b0) & 0xf)
980 #define OP0 (((b0) & 0xf))
981 #define OP1 (((b2) & 0xf))
982 #define OP2 (((b2) & 0xf0) >> 4)
983 #define RRR_R (((b1) & 0xf0) >> 4)
984 #define RRR_S (((b1) & 0xf))
985 #define RRR_T (((b0) & 0xf0) >> 4)
987 #define RRR_X ((RRR_R & 0x4) >> 2)
988 #define RRR_Y ((RRR_T & 0x4) >> 2)
989 #define RRR_W (RRR_R & 0x3)
998 #ifdef TARGET_WORDS_BIGENDIAN
999 #define RRI4_IMM4 ((b2) & 0xf)
1001 #define RRI4_IMM4 (((b2) & 0xf0) >> 4)
1004 #define RRI8_R RRR_R
1005 #define RRI8_S RRR_S
1006 #define RRI8_T RRR_T
1007 #define RRI8_IMM8 (b2)
1008 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
1010 #ifdef TARGET_WORDS_BIGENDIAN
1011 #define RI16_IMM16 (((b1) << 8) | (b2))
1013 #define RI16_IMM16 (((b2) << 8) | (b1))
1016 #ifdef TARGET_WORDS_BIGENDIAN
1017 #define CALL_N (((b0) & 0xc) >> 2)
1018 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
1020 #define CALL_N (((b0) & 0x30) >> 4)
1021 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
1023 #define CALL_OFFSET_SE \
1024 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
1026 #define CALLX_N CALL_N
1027 #ifdef TARGET_WORDS_BIGENDIAN
1028 #define CALLX_M ((b0) & 0x3)
1030 #define CALLX_M (((b0) & 0xc0) >> 6)
1032 #define CALLX_S RRR_S
1034 #define BRI12_M CALLX_M
1035 #define BRI12_S RRR_S
1036 #ifdef TARGET_WORDS_BIGENDIAN
1037 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
1039 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
1041 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
1043 #define BRI8_M BRI12_M
1044 #define BRI8_R RRI8_R
1045 #define BRI8_S RRI8_S
1046 #define BRI8_IMM8 RRI8_IMM8
1047 #define BRI8_IMM8_SE RRI8_IMM8_SE
1051 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
1052 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
1054 unsigned len
= xtensa_op0_insn_len(OP0
);
1056 static const uint32_t B4CONST
[] = {
1057 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
1060 static const uint32_t B4CONSTU
[] = {
1061 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
1066 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
1070 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
1076 dc
->next_pc
= dc
->pc
+ len
;
1084 if ((RRR_R
& 0xc) == 0x8) {
1085 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1092 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1095 case 1: /*reserved*/
1103 if (gen_window_check1(dc
, CALLX_S
)) {
1104 gen_jump(dc
, cpu_R
[CALLX_S
]);
1109 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1111 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1112 gen_helper_retw(tmp
, cpu_env
, tmp
);
1118 case 3: /*reserved*/
1125 if (!gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2)) {
1131 TCGv_i32 tmp
= tcg_temp_new_i32();
1132 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1133 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1141 case 3: /*CALLX12w*/
1142 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1144 TCGv_i32 tmp
= tcg_temp_new_i32();
1146 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1147 gen_callw(dc
, CALLX_N
, tmp
);
1157 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1158 if (gen_window_check2(dc
, RRR_T
, RRR_S
)) {
1159 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1160 gen_helper_movsp(cpu_env
, pc
);
1161 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1181 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1193 default: /*reserved*/
1202 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1205 if (gen_check_privilege(dc
)) {
1206 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1207 gen_check_interrupts(dc
);
1208 gen_jump(dc
, cpu_SR
[EPC1
]);
1217 if (gen_check_privilege(dc
)) {
1218 gen_jump(dc
, cpu_SR
[
1219 dc
->config
->ndepc
? DEPC
: EPC1
]);
1225 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1226 if (gen_check_privilege(dc
)) {
1227 TCGv_i32 tmp
= tcg_const_i32(1);
1230 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1231 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1234 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1235 cpu_SR
[WINDOW_START
], tmp
);
1237 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1238 cpu_SR
[WINDOW_START
], tmp
);
1241 gen_helper_restore_owb(cpu_env
);
1242 gen_check_interrupts(dc
);
1243 gen_jump(dc
, cpu_SR
[EPC1
]);
1249 default: /*reserved*/
1256 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1257 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1258 if (gen_check_privilege(dc
)) {
1259 tcg_gen_mov_i32(cpu_SR
[PS
],
1260 cpu_SR
[EPS2
+ RRR_S
- 2]);
1261 gen_check_interrupts(dc
);
1262 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1265 qemu_log_mask(LOG_GUEST_ERROR
, "RFI %d is illegal\n", RRR_S
);
1266 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1274 default: /*reserved*/
1282 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1284 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1288 case 5: /*SYSCALLx*/
1289 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1291 case 0: /*SYSCALLx*/
1292 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1296 if (semihosting_enabled()) {
1297 if (gen_check_privilege(dc
)) {
1298 gen_helper_simcall(cpu_env
);
1301 qemu_log_mask(LOG_GUEST_ERROR
, "SIMCALL but semihosting is disabled\n");
1302 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1313 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1314 if (gen_check_privilege(dc
) &&
1315 gen_window_check1(dc
, RRR_T
)) {
1316 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1317 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1318 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1319 gen_check_interrupts(dc
);
1320 gen_jumpi_check_loop_end(dc
, 0);
1325 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1326 if (gen_check_privilege(dc
)) {
1327 gen_waiti(dc
, RRR_S
);
1335 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1337 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1338 TCGv_i32 mask
= tcg_const_i32(
1339 ((1 << shift
) - 1) << RRR_S
);
1340 TCGv_i32 tmp
= tcg_temp_new_i32();
1342 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1343 if (RRR_R
& 1) { /*ALL*/
1344 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1346 tcg_gen_add_i32(tmp
, tmp
, mask
);
1348 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1349 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1351 tcg_temp_free(mask
);
1356 default: /*reserved*/
1364 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1365 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1370 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1371 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1376 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1377 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1384 if (gen_window_check1(dc
, RRR_S
)) {
1385 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1390 if (gen_window_check1(dc
, RRR_S
)) {
1391 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1396 if (gen_window_check1(dc
, RRR_S
)) {
1397 TCGv_i32 tmp
= tcg_temp_new_i32();
1398 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1399 gen_right_shift_sar(dc
, tmp
);
1405 if (gen_window_check1(dc
, RRR_S
)) {
1406 TCGv_i32 tmp
= tcg_temp_new_i32();
1407 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1408 gen_left_shift_sar(dc
, tmp
);
1415 TCGv_i32 tmp
= tcg_const_i32(
1416 RRR_S
| ((RRR_T
& 1) << 4));
1417 gen_right_shift_sar(dc
, tmp
);
1423 HAS_OPTION(XTENSA_OPTION_EXTERN_REGS
);
1424 if (gen_check_privilege(dc
) &&
1425 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1426 gen_helper_rer(cpu_R
[RRR_T
], cpu_env
, cpu_R
[RRR_S
]);
1431 HAS_OPTION(XTENSA_OPTION_EXTERN_REGS
);
1432 if (gen_check_privilege(dc
) &&
1433 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1434 gen_helper_wer(cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1439 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1440 if (gen_check_privilege(dc
)) {
1441 TCGv_i32 tmp
= tcg_const_i32(
1442 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1443 gen_helper_rotw(cpu_env
, tmp
);
1445 /* This can change tb->flags, so exit tb */
1446 gen_jumpi_check_loop_end(dc
, -1);
1451 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1452 if (gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1453 tcg_gen_clrsb_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1458 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1459 if (gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1460 tcg_gen_clzi_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
], 32);
1464 default: /*reserved*/
1472 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1473 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1474 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1475 if (gen_check_privilege(dc
) &&
1476 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1477 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1479 switch (RRR_R
& 7) {
1480 case 3: /*RITLB0*/ /*RDTLB0*/
1481 gen_helper_rtlb0(cpu_R
[RRR_T
],
1482 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1485 case 4: /*IITLB*/ /*IDTLB*/
1486 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1487 /* This could change memory mapping, so exit tb */
1488 gen_jumpi_check_loop_end(dc
, -1);
1491 case 5: /*PITLB*/ /*PDTLB*/
1492 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1493 gen_helper_ptlb(cpu_R
[RRR_T
],
1494 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1497 case 6: /*WITLB*/ /*WDTLB*/
1499 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1500 /* This could change memory mapping, so exit tb */
1501 gen_jumpi_check_loop_end(dc
, -1);
1504 case 7: /*RITLB1*/ /*RDTLB1*/
1505 gen_helper_rtlb1(cpu_R
[RRR_T
],
1506 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1510 tcg_temp_free(dtlb
);
1514 tcg_temp_free(dtlb
);
1519 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1524 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1529 TCGv_i32 zero
= tcg_const_i32(0);
1530 TCGv_i32 neg
= tcg_temp_new_i32();
1532 tcg_gen_neg_i32(neg
, cpu_R
[RRR_T
]);
1533 tcg_gen_movcond_i32(TCG_COND_GE
, cpu_R
[RRR_R
],
1534 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_T
], neg
);
1536 tcg_temp_free(zero
);
1540 default: /*reserved*/
1546 case 7: /*reserved*/
1551 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1552 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1559 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1560 TCGv_i32 tmp
= tcg_temp_new_i32();
1561 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1562 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1568 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1569 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1576 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1577 TCGv_i32 tmp
= tcg_temp_new_i32();
1578 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1579 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1590 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1591 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1592 32 - (RRR_T
| ((OP2
& 1) << 4)));
1598 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1599 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1600 RRR_S
| ((OP2
& 1) << 4));
1605 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1606 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1611 if (gen_check_sr(dc
, RSR_SR
, SR_X
) &&
1612 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1613 gen_window_check1(dc
, RRR_T
)) {
1614 TCGv_i32 tmp
= tcg_temp_new_i32();
1615 bool rsr_end
, wsr_end
;
1617 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1618 rsr_end
= gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1619 wsr_end
= gen_wsr(dc
, RSR_SR
, tmp
);
1621 if (rsr_end
&& !wsr_end
) {
1622 gen_jumpi_check_loop_end(dc
, 0);
1628 * Note: 64 bit ops are used here solely because SAR values
1631 #define gen_shift_reg(cmd, reg) do { \
1632 TCGv_i64 tmp = tcg_temp_new_i64(); \
1633 tcg_gen_extu_i32_i64(tmp, reg); \
1634 tcg_gen_##cmd##_i64(v, v, tmp); \
1635 tcg_gen_extrl_i64_i32(cpu_R[RRR_R], v); \
1636 tcg_temp_free_i64(v); \
1637 tcg_temp_free_i64(tmp); \
1640 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1643 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1644 TCGv_i64 v
= tcg_temp_new_i64();
1645 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1651 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1655 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1657 TCGv_i64 v
= tcg_temp_new_i64();
1658 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1664 if (!gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1667 if (dc
->sar_m32_5bit
) {
1668 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1670 TCGv_i64 v
= tcg_temp_new_i64();
1671 TCGv_i32 s
= tcg_const_i32(32);
1672 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1673 tcg_gen_andi_i32(s
, s
, 0x3f);
1674 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1675 gen_shift_reg(shl
, s
);
1681 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1685 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1687 TCGv_i64 v
= tcg_temp_new_i64();
1688 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1693 #undef gen_shift_reg
1696 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1697 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1698 TCGv_i32 v1
= tcg_temp_new_i32();
1699 TCGv_i32 v2
= tcg_temp_new_i32();
1700 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1701 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1702 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1709 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1710 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1711 TCGv_i32 v1
= tcg_temp_new_i32();
1712 TCGv_i32 v2
= tcg_temp_new_i32();
1713 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1714 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1715 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1721 default: /*reserved*/
1728 if (OP2
>= 8 && !gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1733 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1734 TCGLabel
*label
= gen_new_label();
1735 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1736 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1737 gen_set_label(label
);
1741 #define BOOLEAN_LOGIC(fn, r, s, t) \
1743 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1744 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1745 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1747 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1748 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1749 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1750 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1751 tcg_temp_free(tmp1); \
1752 tcg_temp_free(tmp2); \
1756 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1760 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1764 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1768 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1772 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1775 #undef BOOLEAN_LOGIC
1778 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1779 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1784 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1786 TCGv lo
= tcg_temp_new();
1789 tcg_gen_mulu2_i32(lo
, cpu_R
[RRR_R
],
1790 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1792 tcg_gen_muls2_i32(lo
, cpu_R
[RRR_R
],
1793 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1800 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1806 TCGLabel
*label1
= gen_new_label();
1807 TCGLabel
*label2
= gen_new_label();
1809 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1811 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1813 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1814 OP2
== 13 ? 0x80000000 : 0);
1816 gen_set_label(label1
);
1818 tcg_gen_div_i32(cpu_R
[RRR_R
],
1819 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1821 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1822 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1824 gen_set_label(label2
);
1829 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1832 default: /*reserved*/
1841 if (gen_check_sr(dc
, RSR_SR
, SR_R
) &&
1842 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1843 gen_window_check1(dc
, RRR_T
)) {
1844 if (gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
)) {
1845 gen_jumpi_check_loop_end(dc
, 0);
1851 if (gen_check_sr(dc
, RSR_SR
, SR_W
) &&
1852 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1853 gen_window_check1(dc
, RRR_T
)) {
1854 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1859 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1860 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1861 int shift
= 24 - RRR_T
;
1864 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1865 } else if (shift
== 16) {
1866 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1868 TCGv_i32 tmp
= tcg_temp_new_i32();
1869 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1870 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1877 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1878 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1879 TCGv_i32 tmp1
= tcg_temp_new_i32();
1880 TCGv_i32 tmp2
= tcg_temp_new_i32();
1881 TCGv_i32 zero
= tcg_const_i32(0);
1883 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1884 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1885 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1887 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1888 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1890 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1891 cpu_R
[RRR_S
], tmp1
);
1892 tcg_temp_free(tmp1
);
1893 tcg_temp_free(tmp2
);
1894 tcg_temp_free(zero
);
1902 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1903 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1904 static const TCGCond cond
[] = {
1910 tcg_gen_movcond_i32(cond
[OP2
- 4], cpu_R
[RRR_R
],
1911 cpu_R
[RRR_S
], cpu_R
[RRR_T
],
1912 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1920 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1921 static const TCGCond cond
[] = {
1927 TCGv_i32 zero
= tcg_const_i32(0);
1929 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1930 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1931 tcg_temp_free(zero
);
1937 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1938 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1939 TCGv_i32 zero
= tcg_const_i32(0);
1940 TCGv_i32 tmp
= tcg_temp_new_i32();
1942 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1943 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1944 cpu_R
[RRR_R
], tmp
, zero
,
1945 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1948 tcg_temp_free(zero
);
1953 if (gen_window_check1(dc
, RRR_R
)) {
1954 int st
= (RRR_S
<< 4) + RRR_T
;
1955 if (uregnames
[st
].name
) {
1956 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1958 qemu_log_mask(LOG_UNIMP
, "RUR %d not implemented, ", st
);
1965 if (gen_window_check1(dc
, RRR_T
)) {
1966 if (uregnames
[RSR_SR
].name
) {
1967 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1969 qemu_log_mask(LOG_UNIMP
, "WUR %d not implemented, ", RSR_SR
);
1980 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1981 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1982 int maskimm
= (1 << (OP2
+ 1)) - 1;
1984 TCGv_i32 tmp
= tcg_temp_new_i32();
1985 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1986 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
2005 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2006 if (gen_window_check2(dc
, RRR_S
, RRR_T
) &&
2007 gen_check_cpenable(dc
, 0)) {
2008 TCGv_i32 addr
= tcg_temp_new_i32();
2009 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
2010 gen_load_store_alignment(dc
, 2, addr
, false);
2012 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
2014 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
2017 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
2019 tcg_temp_free(addr
);
2023 default: /*reserved*/
2030 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
2035 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2036 if (gen_check_privilege(dc
) &&
2037 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
2038 TCGv_i32 addr
= tcg_temp_new_i32();
2039 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
2040 (0xffffffc0 | (RRR_R
<< 2)));
2041 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
2042 tcg_temp_free(addr
);
2047 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2048 if (gen_check_privilege(dc
) &&
2049 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
2050 TCGv_i32 addr
= tcg_temp_new_i32();
2051 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
2052 (0xffffffc0 | (RRR_R
<< 2)));
2053 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
2054 tcg_temp_free(addr
);
2059 if (gen_window_check2(dc
, RRI4_S
, RRI4_T
)) {
2060 TCGv_i32 addr
= tcg_temp_new_i32();
2062 tcg_gen_addi_i32(addr
, cpu_R
[RRI4_S
], RRI4_IMM4
<< 2);
2063 gen_load_store_alignment(dc
, 2, addr
, false);
2064 tcg_gen_qemu_st32(cpu_R
[RRI4_T
], addr
, dc
->cring
);
2065 tcg_temp_free(addr
);
2077 if (option_enabled(dc
, XTENSA_OPTION_DEPBITS
)) {
2078 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
2081 tcg_gen_deposit_i32(cpu_R
[RRR_T
], cpu_R
[RRR_T
], cpu_R
[RRR_S
],
2086 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2089 if (gen_check_cpenable(dc
, 0)) {
2090 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
2091 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2096 if (gen_check_cpenable(dc
, 0)) {
2097 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
2098 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2103 if (gen_check_cpenable(dc
, 0)) {
2104 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
2105 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2110 if (gen_check_cpenable(dc
, 0)) {
2111 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
2112 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2118 if (gen_check_cpenable(dc
, 0)) {
2119 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
2120 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2125 case 8: /*ROUND.Sf*/
2126 case 9: /*TRUNC.Sf*/
2127 case 10: /*FLOOR.Sf*/
2128 case 11: /*CEIL.Sf*/
2129 case 14: /*UTRUNC.Sf*/
2130 if (gen_window_check1(dc
, RRR_R
) &&
2131 gen_check_cpenable(dc
, 0)) {
2132 static const unsigned rounding_mode_const
[] = {
2133 float_round_nearest_even
,
2134 float_round_to_zero
,
2137 [6] = float_round_to_zero
,
2139 TCGv_i32 rounding_mode
= tcg_const_i32(
2140 rounding_mode_const
[OP2
& 7]);
2141 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2144 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2145 rounding_mode
, scale
);
2147 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2148 rounding_mode
, scale
);
2151 tcg_temp_free(rounding_mode
);
2152 tcg_temp_free(scale
);
2156 case 12: /*FLOAT.Sf*/
2157 case 13: /*UFLOAT.Sf*/
2158 if (gen_window_check1(dc
, RRR_S
) &&
2159 gen_check_cpenable(dc
, 0)) {
2160 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2163 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2164 cpu_R
[RRR_S
], scale
);
2166 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2167 cpu_R
[RRR_S
], scale
);
2169 tcg_temp_free(scale
);
2176 if (gen_check_cpenable(dc
, 0)) {
2177 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2182 if (gen_check_cpenable(dc
, 0)) {
2183 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2188 if (gen_window_check1(dc
, RRR_R
) &&
2189 gen_check_cpenable(dc
, 0)) {
2190 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2195 if (gen_window_check1(dc
, RRR_S
) &&
2196 gen_check_cpenable(dc
, 0)) {
2197 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2202 if (gen_check_cpenable(dc
, 0)) {
2203 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2207 default: /*reserved*/
2213 default: /*reserved*/
2221 if (option_enabled(dc
, XTENSA_OPTION_DEPBITS
)) {
2222 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
2225 tcg_gen_deposit_i32(cpu_R
[RRR_T
], cpu_R
[RRR_T
], cpu_R
[RRR_S
],
2226 OP2
+ 16, RRR_R
+ 1);
2230 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2232 #define gen_compare(rel, br, a, b) \
2234 if (gen_check_cpenable(dc, 0)) { \
2235 TCGv_i32 bit = tcg_const_i32(1 << br); \
2237 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2238 tcg_temp_free(bit); \
2244 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2248 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2252 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2256 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2260 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2264 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2268 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2273 case 8: /*MOVEQZ.Sf*/
2274 case 9: /*MOVNEZ.Sf*/
2275 case 10: /*MOVLTZ.Sf*/
2276 case 11: /*MOVGEZ.Sf*/
2277 if (gen_window_check1(dc
, RRR_T
) &&
2278 gen_check_cpenable(dc
, 0)) {
2279 static const TCGCond cond
[] = {
2285 TCGv_i32 zero
= tcg_const_i32(0);
2287 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2288 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2289 tcg_temp_free(zero
);
2293 case 12: /*MOVF.Sf*/
2294 case 13: /*MOVT.Sf*/
2295 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2296 if (gen_check_cpenable(dc
, 0)) {
2297 TCGv_i32 zero
= tcg_const_i32(0);
2298 TCGv_i32 tmp
= tcg_temp_new_i32();
2300 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2301 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2302 cpu_FR
[RRR_R
], tmp
, zero
,
2303 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2306 tcg_temp_free(zero
);
2310 default: /*reserved*/
2316 default: /*reserved*/
2323 if (gen_window_check1(dc
, RRR_T
)) {
2324 TCGv_i32 tmp
= tcg_const_i32(
2325 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2326 0 : ((dc
->pc
+ 3) & ~3)) +
2327 (0xfffc0000 | (RI16_IMM16
<< 2)));
2329 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2330 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2332 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2338 #define gen_load_store(type, shift) do { \
2339 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2340 TCGv_i32 addr = tcg_temp_new_i32(); \
2342 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2344 gen_load_store_alignment(dc, shift, addr, false); \
2346 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2347 tcg_temp_free(addr); \
2353 gen_load_store(ld8u
, 0);
2357 gen_load_store(ld16u
, 1);
2361 gen_load_store(ld32u
, 2);
2365 gen_load_store(st8
, 0);
2369 gen_load_store(st16
, 1);
2373 gen_load_store(st32
, 2);
2376 #define gen_dcache_hit_test(w, shift) do { \
2377 if (gen_window_check1(dc, RRI##w##_S)) { \
2378 TCGv_i32 addr = tcg_temp_new_i32(); \
2379 TCGv_i32 res = tcg_temp_new_i32(); \
2380 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2381 RRI##w##_IMM##w << shift); \
2382 tcg_gen_qemu_ld8u(res, addr, dc->cring); \
2383 tcg_temp_free(addr); \
2384 tcg_temp_free(res); \
2388 #define gen_dcache_hit_test4() gen_dcache_hit_test(4, 4)
2389 #define gen_dcache_hit_test8() gen_dcache_hit_test(8, 2)
2393 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2398 gen_window_check1(dc
, RRI8_S
);
2402 gen_window_check1(dc
, RRI8_S
);
2406 gen_window_check1(dc
, RRI8_S
);
2410 gen_window_check1(dc
, RRI8_S
);
2414 gen_dcache_hit_test8();
2418 gen_dcache_hit_test8();
2422 if (gen_check_privilege(dc
)) {
2423 gen_dcache_hit_test8();
2428 if (gen_check_privilege(dc
)) {
2429 gen_window_check1(dc
, RRI8_S
);
2436 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2437 if (gen_check_privilege(dc
)) {
2438 gen_dcache_hit_test4();
2443 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2444 if (gen_check_privilege(dc
)) {
2445 gen_dcache_hit_test4();
2450 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2451 if (gen_check_privilege(dc
)) {
2452 gen_window_check1(dc
, RRI4_S
);
2457 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2458 if (gen_check_privilege(dc
)) {
2459 gen_window_check1(dc
, RRI4_S
);
2464 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2465 if (gen_check_privilege(dc
)) {
2466 gen_window_check1(dc
, RRI4_S
);
2470 default: /*reserved*/
2477 #undef gen_dcache_hit_test
2478 #undef gen_dcache_hit_test4
2479 #undef gen_dcache_hit_test8
2481 #define gen_icache_hit_test(w, shift) do { \
2482 if (gen_window_check1(dc, RRI##w##_S)) { \
2483 TCGv_i32 addr = tcg_temp_new_i32(); \
2484 tcg_gen_movi_i32(cpu_pc, dc->pc); \
2485 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2486 RRI##w##_IMM##w << shift); \
2487 gen_helper_itlb_hit_test(cpu_env, addr); \
2488 tcg_temp_free(addr); \
2492 #define gen_icache_hit_test4() gen_icache_hit_test(4, 4)
2493 #define gen_icache_hit_test8() gen_icache_hit_test(8, 2)
2496 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2497 gen_window_check1(dc
, RRI8_S
);
2503 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2504 if (gen_check_privilege(dc
)) {
2505 gen_icache_hit_test4();
2510 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2511 if (gen_check_privilege(dc
)) {
2512 gen_icache_hit_test4();
2517 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2518 if (gen_check_privilege(dc
)) {
2519 gen_window_check1(dc
, RRI4_S
);
2523 default: /*reserved*/
2530 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2531 gen_icache_hit_test8();
2535 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2536 if (gen_check_privilege(dc
)) {
2537 gen_window_check1(dc
, RRI8_S
);
2541 default: /*reserved*/
2547 #undef gen_icache_hit_test
2548 #undef gen_icache_hit_test4
2549 #undef gen_icache_hit_test8
2552 gen_load_store(ld16s
, 1);
2554 #undef gen_load_store
2557 if (gen_window_check1(dc
, RRI8_T
)) {
2558 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2559 RRI8_IMM8
| (RRI8_S
<< 8) |
2560 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2564 #define gen_load_store_no_hw_align(type) do { \
2565 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2566 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2567 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2568 gen_load_store_alignment(dc, 2, addr, true); \
2569 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2570 tcg_temp_free(addr); \
2575 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2576 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2580 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2581 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2586 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2587 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
],
2592 case 14: /*S32C1Iy*/
2593 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2594 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2595 TCGLabel
*label
= gen_new_label();
2596 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2597 TCGv_i32 addr
= tcg_temp_local_new_i32();
2600 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2601 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2602 gen_load_store_alignment(dc
, 2, addr
, true);
2604 tpc
= tcg_const_i32(dc
->pc
);
2605 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2606 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2607 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2608 cpu_SR
[SCOMPARE1
], label
);
2610 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2612 gen_set_label(label
);
2614 tcg_temp_free(addr
);
2620 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2621 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2623 #undef gen_load_store_no_hw_align
2625 default: /*reserved*/
2637 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2638 if (gen_window_check1(dc
, RRI8_S
) &&
2639 gen_check_cpenable(dc
, 0)) {
2640 TCGv_i32 addr
= tcg_temp_new_i32();
2641 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2642 gen_load_store_alignment(dc
, 2, addr
, false);
2644 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2646 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2649 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2651 tcg_temp_free(addr
);
2655 default: /*reserved*/
2662 HAS_OPTION(XTENSA_OPTION_MAC16
);
2671 bool is_m1_sr
= (OP2
& 0x3) == 2;
2672 bool is_m2_sr
= (OP2
& 0xc) == 0;
2673 uint32_t ld_offset
= 0;
2680 case 0: /*MACI?/MACC?*/
2682 ld_offset
= (OP2
& 1) ? -4 : 4;
2684 if (OP2
>= 8) { /*MACI/MACC*/
2685 if (OP1
== 0) { /*LDINC/LDDEC*/
2690 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2695 case 2: /*MACD?/MACA?*/
2696 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2702 if (op
!= MAC16_NONE
) {
2703 if (!is_m1_sr
&& !gen_window_check1(dc
, RRR_S
)) {
2706 if (!is_m2_sr
&& !gen_window_check1(dc
, RRR_T
)) {
2711 if (ld_offset
&& !gen_window_check1(dc
, RRR_S
)) {
2716 TCGv_i32 vaddr
= tcg_temp_new_i32();
2717 TCGv_i32 mem32
= tcg_temp_new_i32();
2720 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2721 gen_load_store_alignment(dc
, 2, vaddr
, false);
2722 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2724 if (op
!= MAC16_NONE
) {
2725 TCGv_i32 m1
= gen_mac16_m(
2726 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2727 OP1
& 1, op
== MAC16_UMUL
);
2728 TCGv_i32 m2
= gen_mac16_m(
2729 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2730 OP1
& 2, op
== MAC16_UMUL
);
2732 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2733 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2734 if (op
== MAC16_UMUL
) {
2735 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2737 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2740 TCGv_i32 lo
= tcg_temp_new_i32();
2741 TCGv_i32 hi
= tcg_temp_new_i32();
2743 tcg_gen_mul_i32(lo
, m1
, m2
);
2744 tcg_gen_sari_i32(hi
, lo
, 31);
2745 if (op
== MAC16_MULA
) {
2746 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2747 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2750 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2751 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2754 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2756 tcg_temp_free_i32(lo
);
2757 tcg_temp_free_i32(hi
);
2763 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2764 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2766 tcg_temp_free(vaddr
);
2767 tcg_temp_free(mem32
);
2775 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2776 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2782 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2783 if (gen_window_check1(dc
, CALL_N
<< 2)) {
2784 gen_callwi(dc
, CALL_N
,
2785 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2794 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2798 if (gen_window_check1(dc
, BRI12_S
)) {
2799 static const TCGCond cond
[] = {
2800 TCG_COND_EQ
, /*BEQZ*/
2801 TCG_COND_NE
, /*BNEZ*/
2802 TCG_COND_LT
, /*BLTZ*/
2803 TCG_COND_GE
, /*BGEZ*/
2806 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2807 4 + BRI12_IMM12_SE
);
2812 if (gen_window_check1(dc
, BRI8_S
)) {
2813 static const TCGCond cond
[] = {
2814 TCG_COND_EQ
, /*BEQI*/
2815 TCG_COND_NE
, /*BNEI*/
2816 TCG_COND_LT
, /*BLTI*/
2817 TCG_COND_GE
, /*BGEI*/
2820 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2821 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2828 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2830 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2831 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2832 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2833 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2837 /* This can change tb->flags, so exit tb */
2838 gen_jumpi_check_loop_end(dc
, -1);
2846 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2848 TCGv_i32 tmp
= tcg_temp_new_i32();
2849 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2851 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2852 tmp
, 0, 4 + RRI8_IMM8_SE
);
2859 case 10: /*LOOPGTZ*/
2860 HAS_OPTION(XTENSA_OPTION_LOOP
);
2861 if (gen_window_check1(dc
, RRI8_S
)) {
2862 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2863 TCGv_i32 tmp
= tcg_const_i32(lend
);
2865 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2866 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2867 gen_helper_wsr_lend(cpu_env
, tmp
);
2871 TCGLabel
*label
= gen_new_label();
2872 tcg_gen_brcondi_i32(
2873 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2874 cpu_R
[RRI8_S
], 0, label
);
2875 gen_jumpi(dc
, lend
, 1);
2876 gen_set_label(label
);
2879 gen_jumpi(dc
, dc
->next_pc
, 0);
2883 default: /*reserved*/
2892 if (gen_window_check1(dc
, BRI8_S
)) {
2893 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2894 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
],
2906 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2908 switch (RRI8_R
& 7) {
2909 case 0: /*BNONE*/ /*BANY*/
2910 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2911 TCGv_i32 tmp
= tcg_temp_new_i32();
2912 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2913 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2918 case 1: /*BEQ*/ /*BNE*/
2919 case 2: /*BLT*/ /*BGE*/
2920 case 3: /*BLTU*/ /*BGEU*/
2921 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2922 static const TCGCond cond
[] = {
2928 [11] = TCG_COND_GEU
,
2930 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2935 case 4: /*BALL*/ /*BNALL*/
2936 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2937 TCGv_i32 tmp
= tcg_temp_new_i32();
2938 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2939 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2945 case 5: /*BBC*/ /*BBS*/
2946 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2947 #ifdef TARGET_WORDS_BIGENDIAN
2948 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2950 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2952 TCGv_i32 tmp
= tcg_temp_new_i32();
2953 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2954 #ifdef TARGET_WORDS_BIGENDIAN
2955 tcg_gen_shr_i32(bit
, bit
, tmp
);
2957 tcg_gen_shl_i32(bit
, bit
, tmp
);
2959 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2960 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2966 case 6: /*BBCI*/ /*BBSI*/
2968 if (gen_window_check1(dc
, RRI8_S
)) {
2969 TCGv_i32 tmp
= tcg_temp_new_i32();
2970 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2971 #ifdef TARGET_WORDS_BIGENDIAN
2972 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2974 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2976 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2985 #define gen_narrow_load_store(type) do { \
2986 if (gen_window_check2(dc, RRRN_S, RRRN_T)) { \
2987 TCGv_i32 addr = tcg_temp_new_i32(); \
2988 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2989 gen_load_store_alignment(dc, 2, addr, false); \
2990 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2991 tcg_temp_free(addr); \
2996 gen_narrow_load_store(ld32u
);
3000 gen_narrow_load_store(st32
);
3002 #undef gen_narrow_load_store
3005 if (gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
)) {
3006 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
3010 case 11: /*ADDI.Nn*/
3011 if (gen_window_check2(dc
, RRRN_R
, RRRN_S
)) {
3012 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
],
3013 RRRN_T
? RRRN_T
: -1);
3018 if (!gen_window_check1(dc
, RRRN_S
)) {
3021 if (RRRN_T
< 8) { /*MOVI.Nn*/
3022 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
3023 RRRN_R
| (RRRN_T
<< 4) |
3024 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
3025 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
3026 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
3028 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
3029 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
3036 if (gen_window_check2(dc
, RRRN_S
, RRRN_T
)) {
3037 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
3044 gen_jump(dc
, cpu_R
[0]);
3048 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
3050 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
3051 gen_helper_retw(tmp
, cpu_env
, tmp
);
3057 case 2: /*BREAK.Nn*/
3058 HAS_OPTION(XTENSA_OPTION_DEBUG
);
3060 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
3068 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
3071 default: /*reserved*/
3077 default: /*reserved*/
3083 default: /*reserved*/
3088 if (dc
->is_jmp
== DISAS_NEXT
) {
3089 gen_check_loop_end(dc
, 0);
3091 dc
->pc
= dc
->next_pc
;
3096 qemu_log_mask(LOG_GUEST_ERROR
, "INVALID(pc = %08x)\n", dc
->pc
);
3097 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
3101 static inline unsigned xtensa_insn_len(CPUXtensaState
*env
, DisasContext
*dc
)
3103 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
3104 return xtensa_op0_insn_len(OP0
);
3107 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
3111 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
3112 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
3113 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
3114 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
3120 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3122 XtensaCPU
*cpu
= xtensa_env_get_cpu(env
);
3123 CPUState
*cs
= CPU(cpu
);
3126 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3127 uint32_t pc_start
= tb
->pc
;
3128 uint32_t next_page_start
=
3129 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3131 if (max_insns
== 0) {
3132 max_insns
= CF_COUNT_MASK
;
3134 if (max_insns
> TCG_MAX_INSNS
) {
3135 max_insns
= TCG_MAX_INSNS
;
3138 dc
.config
= env
->config
;
3139 dc
.singlestep_enabled
= cs
->singlestep_enabled
;
3142 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
3143 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
3144 dc
.lbeg
= env
->sregs
[LBEG
];
3145 dc
.lend
= env
->sregs
[LEND
];
3146 dc
.is_jmp
= DISAS_NEXT
;
3147 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
3148 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
3149 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
3150 XTENSA_TBFLAG_CPENABLE_SHIFT
;
3151 dc
.window
= ((tb
->flags
& XTENSA_TBFLAG_WINDOW_MASK
) >>
3152 XTENSA_TBFLAG_WINDOW_SHIFT
);
3155 init_sar_tracker(&dc
);
3157 dc
.next_icount
= tcg_temp_local_new_i32();
3162 if ((tb
->cflags
& CF_USE_ICOUNT
) &&
3163 (tb
->flags
& XTENSA_TBFLAG_YIELD
)) {
3164 tcg_gen_insn_start(dc
.pc
);
3166 gen_exception(&dc
, EXCP_YIELD
);
3167 dc
.is_jmp
= DISAS_UPDATE
;
3170 if (tb
->flags
& XTENSA_TBFLAG_EXCEPTION
) {
3171 tcg_gen_insn_start(dc
.pc
);
3173 gen_exception(&dc
, EXCP_DEBUG
);
3174 dc
.is_jmp
= DISAS_UPDATE
;
3179 tcg_gen_insn_start(dc
.pc
);
3182 if (unlikely(cpu_breakpoint_test(cs
, dc
.pc
, BP_ANY
))) {
3183 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3184 gen_exception(&dc
, EXCP_DEBUG
);
3185 dc
.is_jmp
= DISAS_UPDATE
;
3186 /* The address covered by the breakpoint must be included in
3187 [tb->pc, tb->pc + tb->size) in order to for it to be
3188 properly cleared -- thus we increment the PC here so that
3189 the logic setting tb->size below does the right thing. */
3194 if (insn_count
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3199 TCGLabel
*label
= gen_new_label();
3201 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
3202 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
3203 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
3205 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
3207 gen_set_label(label
);
3211 gen_ibreak_check(env
, &dc
);
3214 disas_xtensa_insn(env
, &dc
);
3216 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
3218 if (cs
->singlestep_enabled
) {
3219 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3220 gen_exception(&dc
, EXCP_DEBUG
);
3223 } while (dc
.is_jmp
== DISAS_NEXT
&&
3224 insn_count
< max_insns
&&
3225 dc
.pc
< next_page_start
&&
3226 dc
.pc
+ xtensa_insn_len(env
, &dc
) <= next_page_start
&&
3227 !tcg_op_buf_full());
3230 reset_sar_tracker(&dc
);
3232 tcg_temp_free(dc
.next_icount
);
3235 if (tb
->cflags
& CF_LAST_IO
) {
3239 if (dc
.is_jmp
== DISAS_NEXT
) {
3240 gen_jumpi(&dc
, dc
.pc
, 0);
3242 gen_tb_end(tb
, insn_count
);
3245 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)
3246 && qemu_log_in_addr_range(pc_start
)) {
3248 qemu_log("----------------\n");
3249 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3250 log_target_disas(cs
, pc_start
, dc
.pc
- pc_start
, 0);
3255 tb
->size
= dc
.pc
- pc_start
;
3256 tb
->icount
= insn_count
;
3259 void xtensa_cpu_dump_state(CPUState
*cs
, FILE *f
,
3260 fprintf_function cpu_fprintf
, int flags
)
3262 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
3263 CPUXtensaState
*env
= &cpu
->env
;
3266 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3268 for (i
= j
= 0; i
< 256; ++i
) {
3269 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3270 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3271 (j
++ % 4) == 3 ? '\n' : ' ');
3275 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3277 for (i
= j
= 0; i
< 256; ++i
) {
3278 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3279 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3280 (j
++ % 4) == 3 ? '\n' : ' ');
3284 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3286 for (i
= 0; i
< 16; ++i
) {
3287 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3288 (i
% 4) == 3 ? '\n' : ' ');
3291 cpu_fprintf(f
, "\n");
3293 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3294 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3295 (i
% 4) == 3 ? '\n' : ' ');
3298 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3299 cpu_fprintf(f
, "\n");
3301 for (i
= 0; i
< 16; ++i
) {
3302 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3303 float32_val(env
->fregs
[i
].f32
[FP_F32_LOW
]),
3304 *(float *)(env
->fregs
[i
].f32
+ FP_F32_LOW
),
3305 (i
% 2) == 1 ? '\n' : ' ');
3310 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
,