3 * http://www.tensilica.com/products/literature-docs/documentation/xtensa-isa-databook.htm
5 * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of the Open Source and Linux Lab nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "exec/exec-all.h"
35 #include "disas/disas.h"
38 #include "sysemu/sysemu.h"
39 #include "exec/cpu_ldst.h"
40 #include "exec/semihost.h"
42 #include "exec/helper-proto.h"
43 #include "exec/helper-gen.h"
45 #include "trace-tcg.h"
48 typedef struct DisasContext
{
49 const XtensaConfig
*config
;
59 int singlestep_enabled
;
63 bool sar_m32_allocated
;
66 uint32_t ccount_delta
;
76 static TCGv_ptr cpu_env
;
77 static TCGv_i32 cpu_pc
;
78 static TCGv_i32 cpu_R
[16];
79 static TCGv_i32 cpu_FR
[16];
80 static TCGv_i32 cpu_SR
[256];
81 static TCGv_i32 cpu_UR
[256];
83 #include "exec/gen-icount.h"
85 typedef struct XtensaReg
{
97 #define XTENSA_REG_ACCESS(regname, opt, acc) { \
99 .opt_bits = XTENSA_OPTION_BIT(opt), \
103 #define XTENSA_REG(regname, opt) XTENSA_REG_ACCESS(regname, opt, SR_RWX)
105 #define XTENSA_REG_BITS_ACCESS(regname, opt, acc) { \
111 #define XTENSA_REG_BITS(regname, opt) \
112 XTENSA_REG_BITS_ACCESS(regname, opt, SR_RWX)
114 static const XtensaReg sregnames
[256] = {
115 [LBEG
] = XTENSA_REG("LBEG", XTENSA_OPTION_LOOP
),
116 [LEND
] = XTENSA_REG("LEND", XTENSA_OPTION_LOOP
),
117 [LCOUNT
] = XTENSA_REG("LCOUNT", XTENSA_OPTION_LOOP
),
118 [SAR
] = XTENSA_REG_BITS("SAR", XTENSA_OPTION_ALL
),
119 [BR
] = XTENSA_REG("BR", XTENSA_OPTION_BOOLEAN
),
120 [LITBASE
] = XTENSA_REG("LITBASE", XTENSA_OPTION_EXTENDED_L32R
),
121 [SCOMPARE1
] = XTENSA_REG("SCOMPARE1", XTENSA_OPTION_CONDITIONAL_STORE
),
122 [ACCLO
] = XTENSA_REG("ACCLO", XTENSA_OPTION_MAC16
),
123 [ACCHI
] = XTENSA_REG("ACCHI", XTENSA_OPTION_MAC16
),
124 [MR
] = XTENSA_REG("MR0", XTENSA_OPTION_MAC16
),
125 [MR
+ 1] = XTENSA_REG("MR1", XTENSA_OPTION_MAC16
),
126 [MR
+ 2] = XTENSA_REG("MR2", XTENSA_OPTION_MAC16
),
127 [MR
+ 3] = XTENSA_REG("MR3", XTENSA_OPTION_MAC16
),
128 [WINDOW_BASE
] = XTENSA_REG("WINDOW_BASE", XTENSA_OPTION_WINDOWED_REGISTER
),
129 [WINDOW_START
] = XTENSA_REG("WINDOW_START",
130 XTENSA_OPTION_WINDOWED_REGISTER
),
131 [PTEVADDR
] = XTENSA_REG("PTEVADDR", XTENSA_OPTION_MMU
),
132 [RASID
] = XTENSA_REG("RASID", XTENSA_OPTION_MMU
),
133 [ITLBCFG
] = XTENSA_REG("ITLBCFG", XTENSA_OPTION_MMU
),
134 [DTLBCFG
] = XTENSA_REG("DTLBCFG", XTENSA_OPTION_MMU
),
135 [IBREAKENABLE
] = XTENSA_REG("IBREAKENABLE", XTENSA_OPTION_DEBUG
),
136 [CACHEATTR
] = XTENSA_REG("CACHEATTR", XTENSA_OPTION_CACHEATTR
),
137 [ATOMCTL
] = XTENSA_REG("ATOMCTL", XTENSA_OPTION_ATOMCTL
),
138 [IBREAKA
] = XTENSA_REG("IBREAKA0", XTENSA_OPTION_DEBUG
),
139 [IBREAKA
+ 1] = XTENSA_REG("IBREAKA1", XTENSA_OPTION_DEBUG
),
140 [DBREAKA
] = XTENSA_REG("DBREAKA0", XTENSA_OPTION_DEBUG
),
141 [DBREAKA
+ 1] = XTENSA_REG("DBREAKA1", XTENSA_OPTION_DEBUG
),
142 [DBREAKC
] = XTENSA_REG("DBREAKC0", XTENSA_OPTION_DEBUG
),
143 [DBREAKC
+ 1] = XTENSA_REG("DBREAKC1", XTENSA_OPTION_DEBUG
),
144 [CONFIGID0
] = XTENSA_REG_BITS_ACCESS("CONFIGID0", XTENSA_OPTION_ALL
, SR_R
),
145 [EPC1
] = XTENSA_REG("EPC1", XTENSA_OPTION_EXCEPTION
),
146 [EPC1
+ 1] = XTENSA_REG("EPC2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
147 [EPC1
+ 2] = XTENSA_REG("EPC3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
148 [EPC1
+ 3] = XTENSA_REG("EPC4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
149 [EPC1
+ 4] = XTENSA_REG("EPC5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
150 [EPC1
+ 5] = XTENSA_REG("EPC6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
151 [EPC1
+ 6] = XTENSA_REG("EPC7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
152 [DEPC
] = XTENSA_REG("DEPC", XTENSA_OPTION_EXCEPTION
),
153 [EPS2
] = XTENSA_REG("EPS2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
154 [EPS2
+ 1] = XTENSA_REG("EPS3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
155 [EPS2
+ 2] = XTENSA_REG("EPS4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
156 [EPS2
+ 3] = XTENSA_REG("EPS5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
157 [EPS2
+ 4] = XTENSA_REG("EPS6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
158 [EPS2
+ 5] = XTENSA_REG("EPS7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
159 [CONFIGID1
] = XTENSA_REG_BITS_ACCESS("CONFIGID1", XTENSA_OPTION_ALL
, SR_R
),
160 [EXCSAVE1
] = XTENSA_REG("EXCSAVE1", XTENSA_OPTION_EXCEPTION
),
161 [EXCSAVE1
+ 1] = XTENSA_REG("EXCSAVE2",
162 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
163 [EXCSAVE1
+ 2] = XTENSA_REG("EXCSAVE3",
164 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
165 [EXCSAVE1
+ 3] = XTENSA_REG("EXCSAVE4",
166 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
167 [EXCSAVE1
+ 4] = XTENSA_REG("EXCSAVE5",
168 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
169 [EXCSAVE1
+ 5] = XTENSA_REG("EXCSAVE6",
170 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
171 [EXCSAVE1
+ 6] = XTENSA_REG("EXCSAVE7",
172 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
173 [CPENABLE
] = XTENSA_REG("CPENABLE", XTENSA_OPTION_COPROCESSOR
),
174 [INTSET
] = XTENSA_REG_ACCESS("INTSET", XTENSA_OPTION_INTERRUPT
, SR_RW
),
175 [INTCLEAR
] = XTENSA_REG_ACCESS("INTCLEAR", XTENSA_OPTION_INTERRUPT
, SR_W
),
176 [INTENABLE
] = XTENSA_REG("INTENABLE", XTENSA_OPTION_INTERRUPT
),
177 [PS
] = XTENSA_REG_BITS("PS", XTENSA_OPTION_ALL
),
178 [VECBASE
] = XTENSA_REG("VECBASE", XTENSA_OPTION_RELOCATABLE_VECTOR
),
179 [EXCCAUSE
] = XTENSA_REG("EXCCAUSE", XTENSA_OPTION_EXCEPTION
),
180 [DEBUGCAUSE
] = XTENSA_REG_ACCESS("DEBUGCAUSE", XTENSA_OPTION_DEBUG
, SR_R
),
181 [CCOUNT
] = XTENSA_REG("CCOUNT", XTENSA_OPTION_TIMER_INTERRUPT
),
182 [PRID
] = XTENSA_REG_ACCESS("PRID", XTENSA_OPTION_PROCESSOR_ID
, SR_R
),
183 [ICOUNT
] = XTENSA_REG("ICOUNT", XTENSA_OPTION_DEBUG
),
184 [ICOUNTLEVEL
] = XTENSA_REG("ICOUNTLEVEL", XTENSA_OPTION_DEBUG
),
185 [EXCVADDR
] = XTENSA_REG("EXCVADDR", XTENSA_OPTION_EXCEPTION
),
186 [CCOMPARE
] = XTENSA_REG("CCOMPARE0", XTENSA_OPTION_TIMER_INTERRUPT
),
187 [CCOMPARE
+ 1] = XTENSA_REG("CCOMPARE1",
188 XTENSA_OPTION_TIMER_INTERRUPT
),
189 [CCOMPARE
+ 2] = XTENSA_REG("CCOMPARE2",
190 XTENSA_OPTION_TIMER_INTERRUPT
),
191 [MISC
] = XTENSA_REG("MISC0", XTENSA_OPTION_MISC_SR
),
192 [MISC
+ 1] = XTENSA_REG("MISC1", XTENSA_OPTION_MISC_SR
),
193 [MISC
+ 2] = XTENSA_REG("MISC2", XTENSA_OPTION_MISC_SR
),
194 [MISC
+ 3] = XTENSA_REG("MISC3", XTENSA_OPTION_MISC_SR
),
197 static const XtensaReg uregnames
[256] = {
198 [THREADPTR
] = XTENSA_REG("THREADPTR", XTENSA_OPTION_THREAD_POINTER
),
199 [FCR
] = XTENSA_REG("FCR", XTENSA_OPTION_FP_COPROCESSOR
),
200 [FSR
] = XTENSA_REG("FSR", XTENSA_OPTION_FP_COPROCESSOR
),
203 void xtensa_translate_init(void)
205 static const char * const regnames
[] = {
206 "ar0", "ar1", "ar2", "ar3",
207 "ar4", "ar5", "ar6", "ar7",
208 "ar8", "ar9", "ar10", "ar11",
209 "ar12", "ar13", "ar14", "ar15",
211 static const char * const fregnames
[] = {
212 "f0", "f1", "f2", "f3",
213 "f4", "f5", "f6", "f7",
214 "f8", "f9", "f10", "f11",
215 "f12", "f13", "f14", "f15",
219 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
220 cpu_pc
= tcg_global_mem_new_i32(TCG_AREG0
,
221 offsetof(CPUXtensaState
, pc
), "pc");
223 for (i
= 0; i
< 16; i
++) {
224 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
225 offsetof(CPUXtensaState
, regs
[i
]),
229 for (i
= 0; i
< 16; i
++) {
230 cpu_FR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
231 offsetof(CPUXtensaState
, fregs
[i
].f32
[FP_F32_LOW
]),
235 for (i
= 0; i
< 256; ++i
) {
236 if (sregnames
[i
].name
) {
237 cpu_SR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
238 offsetof(CPUXtensaState
, sregs
[i
]),
243 for (i
= 0; i
< 256; ++i
) {
244 if (uregnames
[i
].name
) {
245 cpu_UR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
246 offsetof(CPUXtensaState
, uregs
[i
]),
252 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
254 return xtensa_option_bits_enabled(dc
->config
, opt
);
257 static inline bool option_enabled(DisasContext
*dc
, int opt
)
259 return xtensa_option_enabled(dc
->config
, opt
);
262 static void init_litbase(DisasContext
*dc
)
264 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
265 dc
->litbase
= tcg_temp_local_new_i32();
266 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
270 static void reset_litbase(DisasContext
*dc
)
272 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
273 tcg_temp_free(dc
->litbase
);
277 static void init_sar_tracker(DisasContext
*dc
)
279 dc
->sar_5bit
= false;
280 dc
->sar_m32_5bit
= false;
281 dc
->sar_m32_allocated
= false;
284 static void reset_sar_tracker(DisasContext
*dc
)
286 if (dc
->sar_m32_allocated
) {
287 tcg_temp_free(dc
->sar_m32
);
291 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
293 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
294 if (dc
->sar_m32_5bit
) {
295 tcg_gen_discard_i32(dc
->sar_m32
);
298 dc
->sar_m32_5bit
= false;
301 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
303 TCGv_i32 tmp
= tcg_const_i32(32);
304 if (!dc
->sar_m32_allocated
) {
305 dc
->sar_m32
= tcg_temp_local_new_i32();
306 dc
->sar_m32_allocated
= true;
308 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
309 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
310 dc
->sar_5bit
= false;
311 dc
->sar_m32_5bit
= true;
315 static void gen_advance_ccount(DisasContext
*dc
)
317 if (dc
->ccount_delta
> 0) {
318 TCGv_i32 tmp
= tcg_const_i32(dc
->ccount_delta
);
319 gen_helper_advance_ccount(cpu_env
, tmp
);
322 dc
->ccount_delta
= 0;
325 static void gen_exception(DisasContext
*dc
, int excp
)
327 TCGv_i32 tmp
= tcg_const_i32(excp
);
328 gen_advance_ccount(dc
);
329 gen_helper_exception(cpu_env
, tmp
);
333 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
335 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
336 TCGv_i32 tcause
= tcg_const_i32(cause
);
337 gen_advance_ccount(dc
);
338 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
340 tcg_temp_free(tcause
);
341 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
342 cause
== SYSCALL_CAUSE
) {
343 dc
->is_jmp
= DISAS_UPDATE
;
347 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
350 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
351 TCGv_i32 tcause
= tcg_const_i32(cause
);
352 gen_advance_ccount(dc
);
353 gen_helper_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
355 tcg_temp_free(tcause
);
358 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
360 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
361 TCGv_i32 tcause
= tcg_const_i32(cause
);
362 gen_advance_ccount(dc
);
363 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
365 tcg_temp_free(tcause
);
366 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
367 dc
->is_jmp
= DISAS_UPDATE
;
371 static bool gen_check_privilege(DisasContext
*dc
)
374 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
375 dc
->is_jmp
= DISAS_UPDATE
;
381 static bool gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
383 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
384 !(dc
->cpenable
& (1 << cp
))) {
385 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
386 dc
->is_jmp
= DISAS_UPDATE
;
392 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
394 tcg_gen_mov_i32(cpu_pc
, dest
);
395 gen_advance_ccount(dc
);
397 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
->next_icount
);
399 if (dc
->singlestep_enabled
) {
400 gen_exception(dc
, EXCP_DEBUG
);
403 tcg_gen_goto_tb(slot
);
404 tcg_gen_exit_tb((uintptr_t)dc
->tb
+ slot
);
409 dc
->is_jmp
= DISAS_UPDATE
;
412 static void gen_jump(DisasContext
*dc
, TCGv dest
)
414 gen_jump_slot(dc
, dest
, -1);
417 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
419 TCGv_i32 tmp
= tcg_const_i32(dest
);
420 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
423 gen_jump_slot(dc
, tmp
, slot
);
427 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
430 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
432 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
433 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
434 tcg_temp_free(tcallinc
);
435 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
436 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
437 gen_jump_slot(dc
, dest
, slot
);
440 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
442 gen_callw_slot(dc
, callinc
, dest
, -1);
445 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
447 TCGv_i32 tmp
= tcg_const_i32(dest
);
448 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
451 gen_callw_slot(dc
, callinc
, tmp
, slot
);
455 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
457 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
458 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
459 dc
->next_pc
== dc
->lend
) {
460 TCGLabel
*label
= gen_new_label();
462 gen_advance_ccount(dc
);
463 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
464 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
465 gen_jumpi(dc
, dc
->lbeg
, slot
);
466 gen_set_label(label
);
467 gen_jumpi(dc
, dc
->next_pc
, -1);
473 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
475 if (!gen_check_loop_end(dc
, slot
)) {
476 gen_jumpi(dc
, dc
->next_pc
, slot
);
480 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
481 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
483 TCGLabel
*label
= gen_new_label();
485 gen_advance_ccount(dc
);
486 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
487 gen_jumpi_check_loop_end(dc
, 0);
488 gen_set_label(label
);
489 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
492 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
493 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
495 TCGv_i32 tmp
= tcg_const_i32(t1
);
496 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
500 static bool gen_check_sr(DisasContext
*dc
, uint32_t sr
, unsigned access
)
502 if (!xtensa_option_bits_enabled(dc
->config
, sregnames
[sr
].opt_bits
)) {
503 if (sregnames
[sr
].name
) {
504 qemu_log_mask(LOG_GUEST_ERROR
, "SR %s is not configured\n", sregnames
[sr
].name
);
506 qemu_log_mask(LOG_UNIMP
, "SR %d is not implemented\n", sr
);
508 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
510 } else if (!(sregnames
[sr
].access
& access
)) {
511 static const char * const access_text
[] = {
516 assert(access
< ARRAY_SIZE(access_text
) && access_text
[access
]);
517 qemu_log_mask(LOG_GUEST_ERROR
, "SR %s is not available for %s\n", sregnames
[sr
].name
,
518 access_text
[access
]);
519 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
525 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
527 gen_advance_ccount(dc
);
528 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
531 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
533 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
534 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
535 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
538 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
540 static void (* const rsr_handler
[256])(DisasContext
*dc
,
541 TCGv_i32 d
, uint32_t sr
) = {
542 [CCOUNT
] = gen_rsr_ccount
,
543 [PTEVADDR
] = gen_rsr_ptevaddr
,
546 if (rsr_handler
[sr
]) {
547 rsr_handler
[sr
](dc
, d
, sr
);
549 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
553 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
555 gen_helper_wsr_lbeg(cpu_env
, s
);
556 gen_jumpi_check_loop_end(dc
, 0);
559 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
561 gen_helper_wsr_lend(cpu_env
, s
);
562 gen_jumpi_check_loop_end(dc
, 0);
565 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
567 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
568 if (dc
->sar_m32_5bit
) {
569 tcg_gen_discard_i32(dc
->sar_m32
);
571 dc
->sar_5bit
= false;
572 dc
->sar_m32_5bit
= false;
575 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
577 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
580 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
582 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
583 /* This can change tb->flags, so exit tb */
584 gen_jumpi_check_loop_end(dc
, -1);
587 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
589 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
592 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
594 gen_helper_wsr_windowbase(cpu_env
, v
);
595 /* This can change tb->flags, so exit tb */
596 gen_jumpi_check_loop_end(dc
, -1);
599 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
601 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
602 /* This can change tb->flags, so exit tb */
603 gen_jumpi_check_loop_end(dc
, -1);
606 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
608 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
611 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
613 gen_helper_wsr_rasid(cpu_env
, v
);
614 /* This can change tb->flags, so exit tb */
615 gen_jumpi_check_loop_end(dc
, -1);
618 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
620 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
623 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
625 gen_helper_wsr_ibreakenable(cpu_env
, v
);
626 gen_jumpi_check_loop_end(dc
, 0);
629 static void gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
631 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
634 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
636 unsigned id
= sr
- IBREAKA
;
638 if (id
< dc
->config
->nibreak
) {
639 TCGv_i32 tmp
= tcg_const_i32(id
);
640 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
642 gen_jumpi_check_loop_end(dc
, 0);
646 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
648 unsigned id
= sr
- DBREAKA
;
650 if (id
< dc
->config
->ndbreak
) {
651 TCGv_i32 tmp
= tcg_const_i32(id
);
652 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
657 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
659 unsigned id
= sr
- DBREAKC
;
661 if (id
< dc
->config
->ndbreak
) {
662 TCGv_i32 tmp
= tcg_const_i32(id
);
663 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
668 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
670 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
671 /* This can change tb->flags, so exit tb */
672 gen_jumpi_check_loop_end(dc
, -1);
675 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
677 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
678 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
679 gen_helper_check_interrupts(cpu_env
);
680 gen_jumpi_check_loop_end(dc
, 0);
683 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
685 TCGv_i32 tmp
= tcg_temp_new_i32();
687 tcg_gen_andi_i32(tmp
, v
,
688 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
689 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
690 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
691 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
693 gen_helper_check_interrupts(cpu_env
);
696 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
698 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
699 gen_helper_check_interrupts(cpu_env
);
700 gen_jumpi_check_loop_end(dc
, 0);
703 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
705 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
706 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
708 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
711 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
712 gen_helper_check_interrupts(cpu_env
);
713 /* This can change mmu index and tb->flags, so exit tb */
714 gen_jumpi_check_loop_end(dc
, -1);
717 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
720 tcg_gen_mov_i32(dc
->next_icount
, v
);
722 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
726 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
728 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
729 /* This can change tb->flags, so exit tb */
730 gen_jumpi_check_loop_end(dc
, -1);
733 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
735 uint32_t id
= sr
- CCOMPARE
;
736 if (id
< dc
->config
->nccompare
) {
737 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
738 gen_advance_ccount(dc
);
739 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
740 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
741 gen_helper_check_interrupts(cpu_env
);
745 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
747 static void (* const wsr_handler
[256])(DisasContext
*dc
,
748 uint32_t sr
, TCGv_i32 v
) = {
749 [LBEG
] = gen_wsr_lbeg
,
750 [LEND
] = gen_wsr_lend
,
753 [LITBASE
] = gen_wsr_litbase
,
754 [ACCHI
] = gen_wsr_acchi
,
755 [WINDOW_BASE
] = gen_wsr_windowbase
,
756 [WINDOW_START
] = gen_wsr_windowstart
,
757 [PTEVADDR
] = gen_wsr_ptevaddr
,
758 [RASID
] = gen_wsr_rasid
,
759 [ITLBCFG
] = gen_wsr_tlbcfg
,
760 [DTLBCFG
] = gen_wsr_tlbcfg
,
761 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
762 [ATOMCTL
] = gen_wsr_atomctl
,
763 [IBREAKA
] = gen_wsr_ibreaka
,
764 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
765 [DBREAKA
] = gen_wsr_dbreaka
,
766 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
767 [DBREAKC
] = gen_wsr_dbreakc
,
768 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
769 [CPENABLE
] = gen_wsr_cpenable
,
770 [INTSET
] = gen_wsr_intset
,
771 [INTCLEAR
] = gen_wsr_intclear
,
772 [INTENABLE
] = gen_wsr_intenable
,
774 [ICOUNT
] = gen_wsr_icount
,
775 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
776 [CCOMPARE
] = gen_wsr_ccompare
,
777 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
778 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
781 if (wsr_handler
[sr
]) {
782 wsr_handler
[sr
](dc
, sr
, s
);
784 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
788 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
792 gen_helper_wur_fcr(cpu_env
, s
);
796 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
800 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
805 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
806 TCGv_i32 addr
, bool no_hw_alignment
)
808 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
809 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
810 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
812 TCGLabel
*label
= gen_new_label();
813 TCGv_i32 tmp
= tcg_temp_new_i32();
814 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
815 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
816 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
817 gen_set_label(label
);
822 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
824 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
825 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
826 gen_advance_ccount(dc
);
827 gen_helper_waiti(cpu_env
, pc
, intlevel
);
829 tcg_temp_free(intlevel
);
832 static bool gen_window_check1(DisasContext
*dc
, unsigned r1
)
834 if (r1
/ 4 > dc
->window
) {
835 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
836 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
838 gen_advance_ccount(dc
);
839 gen_helper_window_check(cpu_env
, pc
, w
);
840 dc
->is_jmp
= DISAS_UPDATE
;
846 static bool gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
848 return gen_window_check1(dc
, r1
> r2
? r1
: r2
);
851 static bool gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
854 return gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
857 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
859 TCGv_i32 m
= tcg_temp_new_i32();
862 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
864 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
869 static inline unsigned xtensa_op0_insn_len(unsigned op0
)
871 return op0
>= 8 ? 2 : 3;
874 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
876 #define HAS_OPTION_BITS(opt) do { \
877 if (!option_bits_enabled(dc, opt)) { \
878 qemu_log_mask(LOG_GUEST_ERROR, "Option is not enabled %s:%d\n", \
879 __FILE__, __LINE__); \
880 goto invalid_opcode; \
884 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
886 #define TBD() qemu_log_mask(LOG_UNIMP, "TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
887 #define RESERVED() do { \
888 qemu_log_mask(LOG_GUEST_ERROR, "RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
889 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
890 goto invalid_opcode; \
894 #ifdef TARGET_WORDS_BIGENDIAN
895 #define OP0 (((b0) & 0xf0) >> 4)
896 #define OP1 (((b2) & 0xf0) >> 4)
897 #define OP2 ((b2) & 0xf)
898 #define RRR_R ((b1) & 0xf)
899 #define RRR_S (((b1) & 0xf0) >> 4)
900 #define RRR_T ((b0) & 0xf)
902 #define OP0 (((b0) & 0xf))
903 #define OP1 (((b2) & 0xf))
904 #define OP2 (((b2) & 0xf0) >> 4)
905 #define RRR_R (((b1) & 0xf0) >> 4)
906 #define RRR_S (((b1) & 0xf))
907 #define RRR_T (((b0) & 0xf0) >> 4)
909 #define RRR_X ((RRR_R & 0x4) >> 2)
910 #define RRR_Y ((RRR_T & 0x4) >> 2)
911 #define RRR_W (RRR_R & 0x3)
920 #ifdef TARGET_WORDS_BIGENDIAN
921 #define RRI4_IMM4 ((b2) & 0xf)
923 #define RRI4_IMM4 (((b2) & 0xf0) >> 4)
929 #define RRI8_IMM8 (b2)
930 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
932 #ifdef TARGET_WORDS_BIGENDIAN
933 #define RI16_IMM16 (((b1) << 8) | (b2))
935 #define RI16_IMM16 (((b2) << 8) | (b1))
938 #ifdef TARGET_WORDS_BIGENDIAN
939 #define CALL_N (((b0) & 0xc) >> 2)
940 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
942 #define CALL_N (((b0) & 0x30) >> 4)
943 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
945 #define CALL_OFFSET_SE \
946 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
948 #define CALLX_N CALL_N
949 #ifdef TARGET_WORDS_BIGENDIAN
950 #define CALLX_M ((b0) & 0x3)
952 #define CALLX_M (((b0) & 0xc0) >> 6)
954 #define CALLX_S RRR_S
956 #define BRI12_M CALLX_M
957 #define BRI12_S RRR_S
958 #ifdef TARGET_WORDS_BIGENDIAN
959 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
961 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
963 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
965 #define BRI8_M BRI12_M
966 #define BRI8_R RRI8_R
967 #define BRI8_S RRI8_S
968 #define BRI8_IMM8 RRI8_IMM8
969 #define BRI8_IMM8_SE RRI8_IMM8_SE
973 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
974 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
976 unsigned len
= xtensa_op0_insn_len(OP0
);
978 static const uint32_t B4CONST
[] = {
979 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
982 static const uint32_t B4CONSTU
[] = {
983 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
988 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
992 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
998 dc
->next_pc
= dc
->pc
+ len
;
1006 if ((RRR_R
& 0xc) == 0x8) {
1007 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1014 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1017 case 1: /*reserved*/
1025 if (gen_window_check1(dc
, CALLX_S
)) {
1026 gen_jump(dc
, cpu_R
[CALLX_S
]);
1031 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1033 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1034 gen_advance_ccount(dc
);
1035 gen_helper_retw(tmp
, cpu_env
, tmp
);
1041 case 3: /*reserved*/
1048 if (!gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2)) {
1054 TCGv_i32 tmp
= tcg_temp_new_i32();
1055 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1056 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1064 case 3: /*CALLX12w*/
1065 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1067 TCGv_i32 tmp
= tcg_temp_new_i32();
1069 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1070 gen_callw(dc
, CALLX_N
, tmp
);
1080 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1081 if (gen_window_check2(dc
, RRR_T
, RRR_S
)) {
1082 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1083 gen_advance_ccount(dc
);
1084 gen_helper_movsp(cpu_env
, pc
);
1085 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1105 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1117 default: /*reserved*/
1126 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1129 if (gen_check_privilege(dc
)) {
1130 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1131 gen_helper_check_interrupts(cpu_env
);
1132 gen_jump(dc
, cpu_SR
[EPC1
]);
1141 if (gen_check_privilege(dc
)) {
1142 gen_jump(dc
, cpu_SR
[
1143 dc
->config
->ndepc
? DEPC
: EPC1
]);
1149 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1150 if (gen_check_privilege(dc
)) {
1151 TCGv_i32 tmp
= tcg_const_i32(1);
1154 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1155 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1158 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1159 cpu_SR
[WINDOW_START
], tmp
);
1161 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1162 cpu_SR
[WINDOW_START
], tmp
);
1165 gen_helper_restore_owb(cpu_env
);
1166 gen_helper_check_interrupts(cpu_env
);
1167 gen_jump(dc
, cpu_SR
[EPC1
]);
1173 default: /*reserved*/
1180 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1181 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1182 if (gen_check_privilege(dc
)) {
1183 tcg_gen_mov_i32(cpu_SR
[PS
],
1184 cpu_SR
[EPS2
+ RRR_S
- 2]);
1185 gen_helper_check_interrupts(cpu_env
);
1186 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1189 qemu_log_mask(LOG_GUEST_ERROR
, "RFI %d is illegal\n", RRR_S
);
1190 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1198 default: /*reserved*/
1206 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1208 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1212 case 5: /*SYSCALLx*/
1213 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1215 case 0: /*SYSCALLx*/
1216 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1220 if (semihosting_enabled()) {
1221 if (gen_check_privilege(dc
)) {
1222 gen_helper_simcall(cpu_env
);
1225 qemu_log_mask(LOG_GUEST_ERROR
, "SIMCALL but semihosting is disabled\n");
1226 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1237 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1238 if (gen_check_privilege(dc
) &&
1239 gen_window_check1(dc
, RRR_T
)) {
1240 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1241 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1242 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1243 gen_helper_check_interrupts(cpu_env
);
1244 gen_jumpi_check_loop_end(dc
, 0);
1249 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1250 if (gen_check_privilege(dc
)) {
1251 gen_waiti(dc
, RRR_S
);
1259 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1261 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1262 TCGv_i32 mask
= tcg_const_i32(
1263 ((1 << shift
) - 1) << RRR_S
);
1264 TCGv_i32 tmp
= tcg_temp_new_i32();
1266 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1267 if (RRR_R
& 1) { /*ALL*/
1268 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1270 tcg_gen_add_i32(tmp
, tmp
, mask
);
1272 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1273 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1275 tcg_temp_free(mask
);
1280 default: /*reserved*/
1288 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1289 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1294 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1295 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1300 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1301 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1308 if (gen_window_check1(dc
, RRR_S
)) {
1309 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1314 if (gen_window_check1(dc
, RRR_S
)) {
1315 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1320 if (gen_window_check1(dc
, RRR_S
)) {
1321 TCGv_i32 tmp
= tcg_temp_new_i32();
1322 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1323 gen_right_shift_sar(dc
, tmp
);
1329 if (gen_window_check1(dc
, RRR_S
)) {
1330 TCGv_i32 tmp
= tcg_temp_new_i32();
1331 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1332 gen_left_shift_sar(dc
, tmp
);
1339 TCGv_i32 tmp
= tcg_const_i32(
1340 RRR_S
| ((RRR_T
& 1) << 4));
1341 gen_right_shift_sar(dc
, tmp
);
1355 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1356 if (gen_check_privilege(dc
)) {
1357 TCGv_i32 tmp
= tcg_const_i32(
1358 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1359 gen_helper_rotw(cpu_env
, tmp
);
1361 /* This can change tb->flags, so exit tb */
1362 gen_jumpi_check_loop_end(dc
, -1);
1367 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1368 if (gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1369 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1374 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1375 if (gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1376 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1380 default: /*reserved*/
1388 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1389 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1390 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1391 if (gen_check_privilege(dc
) &&
1392 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1393 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1395 switch (RRR_R
& 7) {
1396 case 3: /*RITLB0*/ /*RDTLB0*/
1397 gen_helper_rtlb0(cpu_R
[RRR_T
],
1398 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1401 case 4: /*IITLB*/ /*IDTLB*/
1402 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1403 /* This could change memory mapping, so exit tb */
1404 gen_jumpi_check_loop_end(dc
, -1);
1407 case 5: /*PITLB*/ /*PDTLB*/
1408 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1409 gen_helper_ptlb(cpu_R
[RRR_T
],
1410 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1413 case 6: /*WITLB*/ /*WDTLB*/
1415 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1416 /* This could change memory mapping, so exit tb */
1417 gen_jumpi_check_loop_end(dc
, -1);
1420 case 7: /*RITLB1*/ /*RDTLB1*/
1421 gen_helper_rtlb1(cpu_R
[RRR_T
],
1422 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1426 tcg_temp_free(dtlb
);
1430 tcg_temp_free(dtlb
);
1435 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1440 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1445 TCGv_i32 zero
= tcg_const_i32(0);
1446 TCGv_i32 neg
= tcg_temp_new_i32();
1448 tcg_gen_neg_i32(neg
, cpu_R
[RRR_T
]);
1449 tcg_gen_movcond_i32(TCG_COND_GE
, cpu_R
[RRR_R
],
1450 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_T
], neg
);
1452 tcg_temp_free(zero
);
1456 default: /*reserved*/
1462 case 7: /*reserved*/
1467 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1468 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1475 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1476 TCGv_i32 tmp
= tcg_temp_new_i32();
1477 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1478 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1484 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1485 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1492 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1493 TCGv_i32 tmp
= tcg_temp_new_i32();
1494 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1495 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1506 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1507 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1508 32 - (RRR_T
| ((OP2
& 1) << 4)));
1514 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1515 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1516 RRR_S
| ((OP2
& 1) << 4));
1521 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1522 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1527 if (gen_check_sr(dc
, RSR_SR
, SR_X
) &&
1528 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1529 gen_window_check1(dc
, RRR_T
)) {
1530 TCGv_i32 tmp
= tcg_temp_new_i32();
1532 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1533 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1534 gen_wsr(dc
, RSR_SR
, tmp
);
1540 * Note: 64 bit ops are used here solely because SAR values
1543 #define gen_shift_reg(cmd, reg) do { \
1544 TCGv_i64 tmp = tcg_temp_new_i64(); \
1545 tcg_gen_extu_i32_i64(tmp, reg); \
1546 tcg_gen_##cmd##_i64(v, v, tmp); \
1547 tcg_gen_extrl_i64_i32(cpu_R[RRR_R], v); \
1548 tcg_temp_free_i64(v); \
1549 tcg_temp_free_i64(tmp); \
1552 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1555 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1556 TCGv_i64 v
= tcg_temp_new_i64();
1557 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1563 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1567 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1569 TCGv_i64 v
= tcg_temp_new_i64();
1570 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1576 if (!gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1579 if (dc
->sar_m32_5bit
) {
1580 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1582 TCGv_i64 v
= tcg_temp_new_i64();
1583 TCGv_i32 s
= tcg_const_i32(32);
1584 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1585 tcg_gen_andi_i32(s
, s
, 0x3f);
1586 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1587 gen_shift_reg(shl
, s
);
1593 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1597 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1599 TCGv_i64 v
= tcg_temp_new_i64();
1600 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1605 #undef gen_shift_reg
1608 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1609 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1610 TCGv_i32 v1
= tcg_temp_new_i32();
1611 TCGv_i32 v2
= tcg_temp_new_i32();
1612 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1613 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1614 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1621 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1622 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1623 TCGv_i32 v1
= tcg_temp_new_i32();
1624 TCGv_i32 v2
= tcg_temp_new_i32();
1625 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1626 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1627 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1633 default: /*reserved*/
1640 if (OP2
>= 8 && !gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1645 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1646 TCGLabel
*label
= gen_new_label();
1647 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1648 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1649 gen_set_label(label
);
1653 #define BOOLEAN_LOGIC(fn, r, s, t) \
1655 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1656 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1657 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1659 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1660 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1661 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1662 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1663 tcg_temp_free(tmp1); \
1664 tcg_temp_free(tmp2); \
1668 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1672 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1676 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1680 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1684 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1687 #undef BOOLEAN_LOGIC
1690 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1691 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1696 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1698 TCGv lo
= tcg_temp_new();
1701 tcg_gen_mulu2_i32(lo
, cpu_R
[RRR_R
],
1702 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1704 tcg_gen_muls2_i32(lo
, cpu_R
[RRR_R
],
1705 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1712 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1718 TCGLabel
*label1
= gen_new_label();
1719 TCGLabel
*label2
= gen_new_label();
1721 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1723 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1725 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1726 OP2
== 13 ? 0x80000000 : 0);
1728 gen_set_label(label1
);
1730 tcg_gen_div_i32(cpu_R
[RRR_R
],
1731 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1733 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1734 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1736 gen_set_label(label2
);
1741 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1744 default: /*reserved*/
1753 if (gen_check_sr(dc
, RSR_SR
, SR_R
) &&
1754 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1755 gen_window_check1(dc
, RRR_T
)) {
1756 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1761 if (gen_check_sr(dc
, RSR_SR
, SR_W
) &&
1762 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1763 gen_window_check1(dc
, RRR_T
)) {
1764 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1769 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1770 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1771 int shift
= 24 - RRR_T
;
1774 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1775 } else if (shift
== 16) {
1776 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1778 TCGv_i32 tmp
= tcg_temp_new_i32();
1779 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1780 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1787 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1788 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1789 TCGv_i32 tmp1
= tcg_temp_new_i32();
1790 TCGv_i32 tmp2
= tcg_temp_new_i32();
1791 TCGv_i32 zero
= tcg_const_i32(0);
1793 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1794 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1795 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1797 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1798 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1800 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1801 cpu_R
[RRR_S
], tmp1
);
1802 tcg_temp_free(tmp1
);
1803 tcg_temp_free(tmp2
);
1804 tcg_temp_free(zero
);
1812 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1813 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1814 static const TCGCond cond
[] = {
1820 tcg_gen_movcond_i32(cond
[OP2
- 4], cpu_R
[RRR_R
],
1821 cpu_R
[RRR_S
], cpu_R
[RRR_T
],
1822 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1830 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1831 static const TCGCond cond
[] = {
1837 TCGv_i32 zero
= tcg_const_i32(0);
1839 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1840 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1841 tcg_temp_free(zero
);
1847 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1848 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1849 TCGv_i32 zero
= tcg_const_i32(0);
1850 TCGv_i32 tmp
= tcg_temp_new_i32();
1852 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1853 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1854 cpu_R
[RRR_R
], tmp
, zero
,
1855 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1858 tcg_temp_free(zero
);
1863 if (gen_window_check1(dc
, RRR_R
)) {
1864 int st
= (RRR_S
<< 4) + RRR_T
;
1865 if (uregnames
[st
].name
) {
1866 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1868 qemu_log_mask(LOG_UNIMP
, "RUR %d not implemented, ", st
);
1875 if (gen_window_check1(dc
, RRR_T
)) {
1876 if (uregnames
[RSR_SR
].name
) {
1877 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1879 qemu_log_mask(LOG_UNIMP
, "WUR %d not implemented, ", RSR_SR
);
1890 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1891 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1892 int maskimm
= (1 << (OP2
+ 1)) - 1;
1894 TCGv_i32 tmp
= tcg_temp_new_i32();
1895 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1896 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1915 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1916 if (gen_window_check2(dc
, RRR_S
, RRR_T
) &&
1917 gen_check_cpenable(dc
, 0)) {
1918 TCGv_i32 addr
= tcg_temp_new_i32();
1919 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1920 gen_load_store_alignment(dc
, 2, addr
, false);
1922 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1924 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1927 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1929 tcg_temp_free(addr
);
1933 default: /*reserved*/
1940 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1945 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1946 if (gen_check_privilege(dc
) &&
1947 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1948 TCGv_i32 addr
= tcg_temp_new_i32();
1949 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1950 (0xffffffc0 | (RRR_R
<< 2)));
1951 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1952 tcg_temp_free(addr
);
1957 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1958 if (gen_check_privilege(dc
) &&
1959 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1960 TCGv_i32 addr
= tcg_temp_new_i32();
1961 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1962 (0xffffffc0 | (RRR_R
<< 2)));
1963 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1964 tcg_temp_free(addr
);
1969 if (gen_window_check2(dc
, RRI4_S
, RRI4_T
)) {
1970 TCGv_i32 addr
= tcg_temp_new_i32();
1972 tcg_gen_addi_i32(addr
, cpu_R
[RRI4_S
], RRI4_IMM4
<< 2);
1973 gen_load_store_alignment(dc
, 2, addr
, false);
1974 tcg_gen_qemu_st32(cpu_R
[RRI4_T
], addr
, dc
->cring
);
1975 tcg_temp_free(addr
);
1987 if (option_enabled(dc
, XTENSA_OPTION_DEPBITS
)) {
1988 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1991 tcg_gen_deposit_i32(cpu_R
[RRR_T
], cpu_R
[RRR_T
], cpu_R
[RRR_S
],
1996 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1999 if (gen_check_cpenable(dc
, 0)) {
2000 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
2001 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2006 if (gen_check_cpenable(dc
, 0)) {
2007 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
2008 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2013 if (gen_check_cpenable(dc
, 0)) {
2014 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
2015 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2020 if (gen_check_cpenable(dc
, 0)) {
2021 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
2022 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2028 if (gen_check_cpenable(dc
, 0)) {
2029 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
2030 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2035 case 8: /*ROUND.Sf*/
2036 case 9: /*TRUNC.Sf*/
2037 case 10: /*FLOOR.Sf*/
2038 case 11: /*CEIL.Sf*/
2039 case 14: /*UTRUNC.Sf*/
2040 if (gen_window_check1(dc
, RRR_R
) &&
2041 gen_check_cpenable(dc
, 0)) {
2042 static const unsigned rounding_mode_const
[] = {
2043 float_round_nearest_even
,
2044 float_round_to_zero
,
2047 [6] = float_round_to_zero
,
2049 TCGv_i32 rounding_mode
= tcg_const_i32(
2050 rounding_mode_const
[OP2
& 7]);
2051 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2054 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2055 rounding_mode
, scale
);
2057 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2058 rounding_mode
, scale
);
2061 tcg_temp_free(rounding_mode
);
2062 tcg_temp_free(scale
);
2066 case 12: /*FLOAT.Sf*/
2067 case 13: /*UFLOAT.Sf*/
2068 if (gen_window_check1(dc
, RRR_S
) &&
2069 gen_check_cpenable(dc
, 0)) {
2070 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2073 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2074 cpu_R
[RRR_S
], scale
);
2076 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2077 cpu_R
[RRR_S
], scale
);
2079 tcg_temp_free(scale
);
2086 if (gen_check_cpenable(dc
, 0)) {
2087 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2092 if (gen_check_cpenable(dc
, 0)) {
2093 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2098 if (gen_window_check1(dc
, RRR_R
) &&
2099 gen_check_cpenable(dc
, 0)) {
2100 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2105 if (gen_window_check1(dc
, RRR_S
) &&
2106 gen_check_cpenable(dc
, 0)) {
2107 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2112 if (gen_check_cpenable(dc
, 0)) {
2113 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2117 default: /*reserved*/
2123 default: /*reserved*/
2131 if (option_enabled(dc
, XTENSA_OPTION_DEPBITS
)) {
2132 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
2135 tcg_gen_deposit_i32(cpu_R
[RRR_T
], cpu_R
[RRR_T
], cpu_R
[RRR_S
],
2136 OP2
+ 16, RRR_R
+ 1);
2140 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2142 #define gen_compare(rel, br, a, b) \
2144 if (gen_check_cpenable(dc, 0)) { \
2145 TCGv_i32 bit = tcg_const_i32(1 << br); \
2147 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2148 tcg_temp_free(bit); \
2154 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2158 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2162 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2166 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2170 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2174 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2178 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2183 case 8: /*MOVEQZ.Sf*/
2184 case 9: /*MOVNEZ.Sf*/
2185 case 10: /*MOVLTZ.Sf*/
2186 case 11: /*MOVGEZ.Sf*/
2187 if (gen_window_check1(dc
, RRR_T
) &&
2188 gen_check_cpenable(dc
, 0)) {
2189 static const TCGCond cond
[] = {
2195 TCGv_i32 zero
= tcg_const_i32(0);
2197 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2198 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2199 tcg_temp_free(zero
);
2203 case 12: /*MOVF.Sf*/
2204 case 13: /*MOVT.Sf*/
2205 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2206 if (gen_check_cpenable(dc
, 0)) {
2207 TCGv_i32 zero
= tcg_const_i32(0);
2208 TCGv_i32 tmp
= tcg_temp_new_i32();
2210 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2211 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2212 cpu_FR
[RRR_R
], tmp
, zero
,
2213 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2216 tcg_temp_free(zero
);
2220 default: /*reserved*/
2226 default: /*reserved*/
2233 if (gen_window_check1(dc
, RRR_T
)) {
2234 TCGv_i32 tmp
= tcg_const_i32(
2235 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2236 0 : ((dc
->pc
+ 3) & ~3)) +
2237 (0xfffc0000 | (RI16_IMM16
<< 2)));
2239 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2240 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2242 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2248 #define gen_load_store(type, shift) do { \
2249 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2250 TCGv_i32 addr = tcg_temp_new_i32(); \
2252 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2254 gen_load_store_alignment(dc, shift, addr, false); \
2256 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2257 tcg_temp_free(addr); \
2263 gen_load_store(ld8u
, 0);
2267 gen_load_store(ld16u
, 1);
2271 gen_load_store(ld32u
, 2);
2275 gen_load_store(st8
, 0);
2279 gen_load_store(st16
, 1);
2283 gen_load_store(st32
, 2);
2286 #define gen_dcache_hit_test(w, shift) do { \
2287 if (gen_window_check1(dc, RRI##w##_S)) { \
2288 TCGv_i32 addr = tcg_temp_new_i32(); \
2289 TCGv_i32 res = tcg_temp_new_i32(); \
2290 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2291 RRI##w##_IMM##w << shift); \
2292 tcg_gen_qemu_ld8u(res, addr, dc->cring); \
2293 tcg_temp_free(addr); \
2294 tcg_temp_free(res); \
2298 #define gen_dcache_hit_test4() gen_dcache_hit_test(4, 4)
2299 #define gen_dcache_hit_test8() gen_dcache_hit_test(8, 2)
2303 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2308 gen_window_check1(dc
, RRI8_S
);
2312 gen_window_check1(dc
, RRI8_S
);
2316 gen_window_check1(dc
, RRI8_S
);
2320 gen_window_check1(dc
, RRI8_S
);
2324 gen_dcache_hit_test8();
2328 gen_dcache_hit_test8();
2332 if (gen_check_privilege(dc
)) {
2333 gen_dcache_hit_test8();
2338 if (gen_check_privilege(dc
)) {
2339 gen_window_check1(dc
, RRI8_S
);
2346 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2347 if (gen_check_privilege(dc
)) {
2348 gen_dcache_hit_test4();
2353 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2354 if (gen_check_privilege(dc
)) {
2355 gen_dcache_hit_test4();
2360 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2361 if (gen_check_privilege(dc
)) {
2362 gen_window_check1(dc
, RRI4_S
);
2367 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2368 if (gen_check_privilege(dc
)) {
2369 gen_window_check1(dc
, RRI4_S
);
2374 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2375 if (gen_check_privilege(dc
)) {
2376 gen_window_check1(dc
, RRI4_S
);
2380 default: /*reserved*/
2387 #undef gen_dcache_hit_test
2388 #undef gen_dcache_hit_test4
2389 #undef gen_dcache_hit_test8
2391 #define gen_icache_hit_test(w, shift) do { \
2392 if (gen_window_check1(dc, RRI##w##_S)) { \
2393 TCGv_i32 addr = tcg_temp_new_i32(); \
2394 tcg_gen_movi_i32(cpu_pc, dc->pc); \
2395 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2396 RRI##w##_IMM##w << shift); \
2397 gen_helper_itlb_hit_test(cpu_env, addr); \
2398 tcg_temp_free(addr); \
2402 #define gen_icache_hit_test4() gen_icache_hit_test(4, 4)
2403 #define gen_icache_hit_test8() gen_icache_hit_test(8, 2)
2406 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2407 gen_window_check1(dc
, RRI8_S
);
2413 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2414 if (gen_check_privilege(dc
)) {
2415 gen_icache_hit_test4();
2420 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2421 if (gen_check_privilege(dc
)) {
2422 gen_icache_hit_test4();
2427 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2428 if (gen_check_privilege(dc
)) {
2429 gen_window_check1(dc
, RRI4_S
);
2433 default: /*reserved*/
2440 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2441 gen_icache_hit_test8();
2445 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2446 if (gen_check_privilege(dc
)) {
2447 gen_window_check1(dc
, RRI8_S
);
2451 default: /*reserved*/
2457 #undef gen_icache_hit_test
2458 #undef gen_icache_hit_test4
2459 #undef gen_icache_hit_test8
2462 gen_load_store(ld16s
, 1);
2464 #undef gen_load_store
2467 if (gen_window_check1(dc
, RRI8_T
)) {
2468 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2469 RRI8_IMM8
| (RRI8_S
<< 8) |
2470 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2474 #define gen_load_store_no_hw_align(type) do { \
2475 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2476 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2477 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2478 gen_load_store_alignment(dc, 2, addr, true); \
2479 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2480 tcg_temp_free(addr); \
2485 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2486 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2490 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2491 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2496 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2497 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
],
2502 case 14: /*S32C1Iy*/
2503 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2504 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2505 TCGLabel
*label
= gen_new_label();
2506 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2507 TCGv_i32 addr
= tcg_temp_local_new_i32();
2510 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2511 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2512 gen_load_store_alignment(dc
, 2, addr
, true);
2514 gen_advance_ccount(dc
);
2515 tpc
= tcg_const_i32(dc
->pc
);
2516 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2517 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2518 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2519 cpu_SR
[SCOMPARE1
], label
);
2521 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2523 gen_set_label(label
);
2525 tcg_temp_free(addr
);
2531 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2532 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2534 #undef gen_load_store_no_hw_align
2536 default: /*reserved*/
2548 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2549 if (gen_window_check1(dc
, RRI8_S
) &&
2550 gen_check_cpenable(dc
, 0)) {
2551 TCGv_i32 addr
= tcg_temp_new_i32();
2552 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2553 gen_load_store_alignment(dc
, 2, addr
, false);
2555 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2557 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2560 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2562 tcg_temp_free(addr
);
2566 default: /*reserved*/
2573 HAS_OPTION(XTENSA_OPTION_MAC16
);
2582 bool is_m1_sr
= (OP2
& 0x3) == 2;
2583 bool is_m2_sr
= (OP2
& 0xc) == 0;
2584 uint32_t ld_offset
= 0;
2591 case 0: /*MACI?/MACC?*/
2593 ld_offset
= (OP2
& 1) ? -4 : 4;
2595 if (OP2
>= 8) { /*MACI/MACC*/
2596 if (OP1
== 0) { /*LDINC/LDDEC*/
2601 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2606 case 2: /*MACD?/MACA?*/
2607 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2613 if (op
!= MAC16_NONE
) {
2614 if (!is_m1_sr
&& !gen_window_check1(dc
, RRR_S
)) {
2617 if (!is_m2_sr
&& !gen_window_check1(dc
, RRR_T
)) {
2622 if (ld_offset
&& !gen_window_check1(dc
, RRR_S
)) {
2627 TCGv_i32 vaddr
= tcg_temp_new_i32();
2628 TCGv_i32 mem32
= tcg_temp_new_i32();
2631 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2632 gen_load_store_alignment(dc
, 2, vaddr
, false);
2633 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2635 if (op
!= MAC16_NONE
) {
2636 TCGv_i32 m1
= gen_mac16_m(
2637 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2638 OP1
& 1, op
== MAC16_UMUL
);
2639 TCGv_i32 m2
= gen_mac16_m(
2640 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2641 OP1
& 2, op
== MAC16_UMUL
);
2643 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2644 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2645 if (op
== MAC16_UMUL
) {
2646 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2648 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2651 TCGv_i32 lo
= tcg_temp_new_i32();
2652 TCGv_i32 hi
= tcg_temp_new_i32();
2654 tcg_gen_mul_i32(lo
, m1
, m2
);
2655 tcg_gen_sari_i32(hi
, lo
, 31);
2656 if (op
== MAC16_MULA
) {
2657 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2658 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2661 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2662 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2665 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2667 tcg_temp_free_i32(lo
);
2668 tcg_temp_free_i32(hi
);
2674 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2675 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2677 tcg_temp_free(vaddr
);
2678 tcg_temp_free(mem32
);
2686 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2687 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2693 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2694 if (gen_window_check1(dc
, CALL_N
<< 2)) {
2695 gen_callwi(dc
, CALL_N
,
2696 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2705 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2709 if (gen_window_check1(dc
, BRI12_S
)) {
2710 static const TCGCond cond
[] = {
2711 TCG_COND_EQ
, /*BEQZ*/
2712 TCG_COND_NE
, /*BNEZ*/
2713 TCG_COND_LT
, /*BLTZ*/
2714 TCG_COND_GE
, /*BGEZ*/
2717 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2718 4 + BRI12_IMM12_SE
);
2723 if (gen_window_check1(dc
, BRI8_S
)) {
2724 static const TCGCond cond
[] = {
2725 TCG_COND_EQ
, /*BEQI*/
2726 TCG_COND_NE
, /*BNEI*/
2727 TCG_COND_LT
, /*BLTI*/
2728 TCG_COND_GE
, /*BGEI*/
2731 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2732 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2739 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2741 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2742 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2743 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2744 gen_advance_ccount(dc
);
2745 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2749 /* This can change tb->flags, so exit tb */
2750 gen_jumpi_check_loop_end(dc
, -1);
2758 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2760 TCGv_i32 tmp
= tcg_temp_new_i32();
2761 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2763 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2764 tmp
, 0, 4 + RRI8_IMM8_SE
);
2771 case 10: /*LOOPGTZ*/
2772 HAS_OPTION(XTENSA_OPTION_LOOP
);
2773 if (gen_window_check1(dc
, RRI8_S
)) {
2774 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2775 TCGv_i32 tmp
= tcg_const_i32(lend
);
2777 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2778 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2779 gen_helper_wsr_lend(cpu_env
, tmp
);
2783 TCGLabel
*label
= gen_new_label();
2784 tcg_gen_brcondi_i32(
2785 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2786 cpu_R
[RRI8_S
], 0, label
);
2787 gen_jumpi(dc
, lend
, 1);
2788 gen_set_label(label
);
2791 gen_jumpi(dc
, dc
->next_pc
, 0);
2795 default: /*reserved*/
2804 if (gen_window_check1(dc
, BRI8_S
)) {
2805 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2806 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
],
2818 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2820 switch (RRI8_R
& 7) {
2821 case 0: /*BNONE*/ /*BANY*/
2822 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2823 TCGv_i32 tmp
= tcg_temp_new_i32();
2824 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2825 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2830 case 1: /*BEQ*/ /*BNE*/
2831 case 2: /*BLT*/ /*BGE*/
2832 case 3: /*BLTU*/ /*BGEU*/
2833 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2834 static const TCGCond cond
[] = {
2840 [11] = TCG_COND_GEU
,
2842 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2847 case 4: /*BALL*/ /*BNALL*/
2848 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2849 TCGv_i32 tmp
= tcg_temp_new_i32();
2850 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2851 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2857 case 5: /*BBC*/ /*BBS*/
2858 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2859 #ifdef TARGET_WORDS_BIGENDIAN
2860 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2862 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2864 TCGv_i32 tmp
= tcg_temp_new_i32();
2865 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2866 #ifdef TARGET_WORDS_BIGENDIAN
2867 tcg_gen_shr_i32(bit
, bit
, tmp
);
2869 tcg_gen_shl_i32(bit
, bit
, tmp
);
2871 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2872 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2878 case 6: /*BBCI*/ /*BBSI*/
2880 if (gen_window_check1(dc
, RRI8_S
)) {
2881 TCGv_i32 tmp
= tcg_temp_new_i32();
2882 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2883 #ifdef TARGET_WORDS_BIGENDIAN
2884 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2886 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2888 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2897 #define gen_narrow_load_store(type) do { \
2898 if (gen_window_check2(dc, RRRN_S, RRRN_T)) { \
2899 TCGv_i32 addr = tcg_temp_new_i32(); \
2900 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2901 gen_load_store_alignment(dc, 2, addr, false); \
2902 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2903 tcg_temp_free(addr); \
2908 gen_narrow_load_store(ld32u
);
2912 gen_narrow_load_store(st32
);
2914 #undef gen_narrow_load_store
2917 if (gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
)) {
2918 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2922 case 11: /*ADDI.Nn*/
2923 if (gen_window_check2(dc
, RRRN_R
, RRRN_S
)) {
2924 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
],
2925 RRRN_T
? RRRN_T
: -1);
2930 if (!gen_window_check1(dc
, RRRN_S
)) {
2933 if (RRRN_T
< 8) { /*MOVI.Nn*/
2934 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2935 RRRN_R
| (RRRN_T
<< 4) |
2936 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2937 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2938 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2940 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2941 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2948 if (gen_window_check2(dc
, RRRN_S
, RRRN_T
)) {
2949 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2956 gen_jump(dc
, cpu_R
[0]);
2960 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2962 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2963 gen_advance_ccount(dc
);
2964 gen_helper_retw(tmp
, cpu_env
, tmp
);
2970 case 2: /*BREAK.Nn*/
2971 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2973 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2981 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2984 default: /*reserved*/
2990 default: /*reserved*/
2996 default: /*reserved*/
3001 if (dc
->is_jmp
== DISAS_NEXT
) {
3002 gen_check_loop_end(dc
, 0);
3004 dc
->pc
= dc
->next_pc
;
3009 qemu_log_mask(LOG_GUEST_ERROR
, "INVALID(pc = %08x)\n", dc
->pc
);
3010 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
3014 static inline unsigned xtensa_insn_len(CPUXtensaState
*env
, DisasContext
*dc
)
3016 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
3017 return xtensa_op0_insn_len(OP0
);
3020 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
3024 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
3025 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
3026 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
3027 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
3033 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3035 XtensaCPU
*cpu
= xtensa_env_get_cpu(env
);
3036 CPUState
*cs
= CPU(cpu
);
3039 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3040 uint32_t pc_start
= tb
->pc
;
3041 uint32_t next_page_start
=
3042 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3044 if (max_insns
== 0) {
3045 max_insns
= CF_COUNT_MASK
;
3047 if (max_insns
> TCG_MAX_INSNS
) {
3048 max_insns
= TCG_MAX_INSNS
;
3051 dc
.config
= env
->config
;
3052 dc
.singlestep_enabled
= cs
->singlestep_enabled
;
3055 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
3056 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
3057 dc
.lbeg
= env
->sregs
[LBEG
];
3058 dc
.lend
= env
->sregs
[LEND
];
3059 dc
.is_jmp
= DISAS_NEXT
;
3060 dc
.ccount_delta
= 0;
3061 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
3062 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
3063 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
3064 XTENSA_TBFLAG_CPENABLE_SHIFT
;
3065 dc
.window
= ((tb
->flags
& XTENSA_TBFLAG_WINDOW_MASK
) >>
3066 XTENSA_TBFLAG_WINDOW_SHIFT
);
3069 init_sar_tracker(&dc
);
3071 dc
.next_icount
= tcg_temp_local_new_i32();
3076 if (tb
->flags
& XTENSA_TBFLAG_EXCEPTION
) {
3077 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3078 gen_exception(&dc
, EXCP_DEBUG
);
3082 tcg_gen_insn_start(dc
.pc
);
3087 if (unlikely(cpu_breakpoint_test(cs
, dc
.pc
, BP_ANY
))) {
3088 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3089 gen_exception(&dc
, EXCP_DEBUG
);
3090 dc
.is_jmp
= DISAS_UPDATE
;
3091 /* The address covered by the breakpoint must be included in
3092 [tb->pc, tb->pc + tb->size) in order to for it to be
3093 properly cleared -- thus we increment the PC here so that
3094 the logic setting tb->size below does the right thing. */
3099 if (insn_count
== max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3104 TCGLabel
*label
= gen_new_label();
3106 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
3107 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
3108 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
3110 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
3112 gen_set_label(label
);
3116 gen_ibreak_check(env
, &dc
);
3119 disas_xtensa_insn(env
, &dc
);
3121 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
3123 if (cs
->singlestep_enabled
) {
3124 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3125 gen_exception(&dc
, EXCP_DEBUG
);
3128 } while (dc
.is_jmp
== DISAS_NEXT
&&
3129 insn_count
< max_insns
&&
3130 dc
.pc
< next_page_start
&&
3131 dc
.pc
+ xtensa_insn_len(env
, &dc
) <= next_page_start
&&
3132 !tcg_op_buf_full());
3135 reset_sar_tracker(&dc
);
3137 tcg_temp_free(dc
.next_icount
);
3140 if (tb
->cflags
& CF_LAST_IO
) {
3144 if (dc
.is_jmp
== DISAS_NEXT
) {
3145 gen_jumpi(&dc
, dc
.pc
, 0);
3147 gen_tb_end(tb
, insn_count
);
3150 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3151 qemu_log("----------------\n");
3152 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3153 log_target_disas(cs
, pc_start
, dc
.pc
- pc_start
, 0);
3157 tb
->size
= dc
.pc
- pc_start
;
3158 tb
->icount
= insn_count
;
3161 void xtensa_cpu_dump_state(CPUState
*cs
, FILE *f
,
3162 fprintf_function cpu_fprintf
, int flags
)
3164 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
3165 CPUXtensaState
*env
= &cpu
->env
;
3168 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3170 for (i
= j
= 0; i
< 256; ++i
) {
3171 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3172 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3173 (j
++ % 4) == 3 ? '\n' : ' ');
3177 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3179 for (i
= j
= 0; i
< 256; ++i
) {
3180 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3181 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3182 (j
++ % 4) == 3 ? '\n' : ' ');
3186 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3188 for (i
= 0; i
< 16; ++i
) {
3189 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3190 (i
% 4) == 3 ? '\n' : ' ');
3193 cpu_fprintf(f
, "\n");
3195 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3196 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3197 (i
% 4) == 3 ? '\n' : ' ');
3200 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3201 cpu_fprintf(f
, "\n");
3203 for (i
= 0; i
< 16; ++i
) {
3204 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3205 float32_val(env
->fregs
[i
].f32
[FP_F32_LOW
]),
3206 *(float *)(env
->fregs
[i
].f32
+ FP_F32_LOW
),
3207 (i
% 2) == 1 ? '\n' : ' ');
3212 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
,