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("SR %s is not configured\n", sregnames
[sr
].name
);
506 qemu_log("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("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("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("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
887 #define RESERVED() do { \
888 qemu_log("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("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("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_trunc_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("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("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 TCGv_i32 addr
= tcg_temp_new_i32();
1948 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1949 (0xffffffc0 | (RRR_R
<< 2)));
1950 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1951 tcg_temp_free(addr
);
1956 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1957 if (gen_check_privilege(dc
)) {
1958 TCGv_i32 addr
= tcg_temp_new_i32();
1959 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1960 (0xffffffc0 | (RRR_R
<< 2)));
1961 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1962 tcg_temp_free(addr
);
1973 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1976 if (gen_check_cpenable(dc
, 0)) {
1977 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
1978 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1983 if (gen_check_cpenable(dc
, 0)) {
1984 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
1985 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1990 if (gen_check_cpenable(dc
, 0)) {
1991 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
1992 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1997 if (gen_check_cpenable(dc
, 0)) {
1998 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
1999 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2005 if (gen_check_cpenable(dc
, 0)) {
2006 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
2007 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2012 case 8: /*ROUND.Sf*/
2013 case 9: /*TRUNC.Sf*/
2014 case 10: /*FLOOR.Sf*/
2015 case 11: /*CEIL.Sf*/
2016 case 14: /*UTRUNC.Sf*/
2017 if (gen_window_check1(dc
, RRR_R
) &&
2018 gen_check_cpenable(dc
, 0)) {
2019 static const unsigned rounding_mode_const
[] = {
2020 float_round_nearest_even
,
2021 float_round_to_zero
,
2024 [6] = float_round_to_zero
,
2026 TCGv_i32 rounding_mode
= tcg_const_i32(
2027 rounding_mode_const
[OP2
& 7]);
2028 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2031 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2032 rounding_mode
, scale
);
2034 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2035 rounding_mode
, scale
);
2038 tcg_temp_free(rounding_mode
);
2039 tcg_temp_free(scale
);
2043 case 12: /*FLOAT.Sf*/
2044 case 13: /*UFLOAT.Sf*/
2045 if (gen_window_check1(dc
, RRR_S
) &&
2046 gen_check_cpenable(dc
, 0)) {
2047 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2050 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2051 cpu_R
[RRR_S
], scale
);
2053 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2054 cpu_R
[RRR_S
], scale
);
2056 tcg_temp_free(scale
);
2063 if (gen_check_cpenable(dc
, 0)) {
2064 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2069 if (gen_check_cpenable(dc
, 0)) {
2070 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2075 if (gen_window_check1(dc
, RRR_R
) &&
2076 gen_check_cpenable(dc
, 0)) {
2077 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2082 if (gen_window_check1(dc
, RRR_S
) &&
2083 gen_check_cpenable(dc
, 0)) {
2084 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2089 if (gen_check_cpenable(dc
, 0)) {
2090 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2094 default: /*reserved*/
2100 default: /*reserved*/
2107 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2109 #define gen_compare(rel, br, a, b) \
2111 if (gen_check_cpenable(dc, 0)) { \
2112 TCGv_i32 bit = tcg_const_i32(1 << br); \
2114 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2115 tcg_temp_free(bit); \
2121 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2125 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2129 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2133 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2137 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2141 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2145 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2150 case 8: /*MOVEQZ.Sf*/
2151 case 9: /*MOVNEZ.Sf*/
2152 case 10: /*MOVLTZ.Sf*/
2153 case 11: /*MOVGEZ.Sf*/
2154 if (gen_window_check1(dc
, RRR_T
) &&
2155 gen_check_cpenable(dc
, 0)) {
2156 static const TCGCond cond
[] = {
2162 TCGv_i32 zero
= tcg_const_i32(0);
2164 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2165 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2166 tcg_temp_free(zero
);
2170 case 12: /*MOVF.Sf*/
2171 case 13: /*MOVT.Sf*/
2172 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2173 if (gen_check_cpenable(dc
, 0)) {
2174 TCGv_i32 zero
= tcg_const_i32(0);
2175 TCGv_i32 tmp
= tcg_temp_new_i32();
2177 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2178 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2179 cpu_FR
[RRR_R
], tmp
, zero
,
2180 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2183 tcg_temp_free(zero
);
2187 default: /*reserved*/
2193 default: /*reserved*/
2200 if (gen_window_check1(dc
, RRR_T
)) {
2201 TCGv_i32 tmp
= tcg_const_i32(
2202 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2203 0 : ((dc
->pc
+ 3) & ~3)) +
2204 (0xfffc0000 | (RI16_IMM16
<< 2)));
2206 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2207 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2209 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2215 #define gen_load_store(type, shift) do { \
2216 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2217 TCGv_i32 addr = tcg_temp_new_i32(); \
2219 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2221 gen_load_store_alignment(dc, shift, addr, false); \
2223 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2224 tcg_temp_free(addr); \
2230 gen_load_store(ld8u
, 0);
2234 gen_load_store(ld16u
, 1);
2238 gen_load_store(ld32u
, 2);
2242 gen_load_store(st8
, 0);
2246 gen_load_store(st16
, 1);
2250 gen_load_store(st32
, 2);
2253 #define gen_dcache_hit_test(w, shift) do { \
2254 if (gen_window_check1(dc, RRI##w##_S)) { \
2255 TCGv_i32 addr = tcg_temp_new_i32(); \
2256 TCGv_i32 res = tcg_temp_new_i32(); \
2257 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2258 RRI##w##_IMM##w << shift); \
2259 tcg_gen_qemu_ld8u(res, addr, dc->cring); \
2260 tcg_temp_free(addr); \
2261 tcg_temp_free(res); \
2265 #define gen_dcache_hit_test4() gen_dcache_hit_test(4, 4)
2266 #define gen_dcache_hit_test8() gen_dcache_hit_test(8, 2)
2270 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2275 gen_window_check1(dc
, RRI8_S
);
2279 gen_window_check1(dc
, RRI8_S
);
2283 gen_window_check1(dc
, RRI8_S
);
2287 gen_window_check1(dc
, RRI8_S
);
2291 gen_dcache_hit_test8();
2295 gen_dcache_hit_test8();
2299 if (gen_check_privilege(dc
)) {
2300 gen_dcache_hit_test8();
2305 if (gen_check_privilege(dc
)) {
2306 gen_window_check1(dc
, RRI8_S
);
2313 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2314 if (gen_check_privilege(dc
)) {
2315 gen_dcache_hit_test4();
2320 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2321 if (gen_check_privilege(dc
)) {
2322 gen_dcache_hit_test4();
2327 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2328 if (gen_check_privilege(dc
)) {
2329 gen_window_check1(dc
, RRI4_S
);
2334 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2335 if (gen_check_privilege(dc
)) {
2336 gen_window_check1(dc
, RRI4_S
);
2341 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2342 if (gen_check_privilege(dc
)) {
2343 gen_window_check1(dc
, RRI4_S
);
2347 default: /*reserved*/
2354 #undef gen_dcache_hit_test
2355 #undef gen_dcache_hit_test4
2356 #undef gen_dcache_hit_test8
2358 #define gen_icache_hit_test(w, shift) do { \
2359 if (gen_window_check1(dc, RRI##w##_S)) { \
2360 TCGv_i32 addr = tcg_temp_new_i32(); \
2361 tcg_gen_movi_i32(cpu_pc, dc->pc); \
2362 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2363 RRI##w##_IMM##w << shift); \
2364 gen_helper_itlb_hit_test(cpu_env, addr); \
2365 tcg_temp_free(addr); \
2369 #define gen_icache_hit_test4() gen_icache_hit_test(4, 4)
2370 #define gen_icache_hit_test8() gen_icache_hit_test(8, 2)
2373 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2374 gen_window_check1(dc
, RRI8_S
);
2380 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2381 if (gen_check_privilege(dc
)) {
2382 gen_icache_hit_test4();
2387 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2388 if (gen_check_privilege(dc
)) {
2389 gen_icache_hit_test4();
2394 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2395 if (gen_check_privilege(dc
)) {
2396 gen_window_check1(dc
, RRI4_S
);
2400 default: /*reserved*/
2407 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2408 gen_icache_hit_test8();
2412 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2413 if (gen_check_privilege(dc
)) {
2414 gen_window_check1(dc
, RRI8_S
);
2418 default: /*reserved*/
2424 #undef gen_icache_hit_test
2425 #undef gen_icache_hit_test4
2426 #undef gen_icache_hit_test8
2429 gen_load_store(ld16s
, 1);
2431 #undef gen_load_store
2434 if (gen_window_check1(dc
, RRI8_T
)) {
2435 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2436 RRI8_IMM8
| (RRI8_S
<< 8) |
2437 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2441 #define gen_load_store_no_hw_align(type) do { \
2442 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2443 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2444 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2445 gen_load_store_alignment(dc, 2, addr, true); \
2446 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2447 tcg_temp_free(addr); \
2452 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2453 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2457 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2458 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2463 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2464 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
],
2469 case 14: /*S32C1Iy*/
2470 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2471 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2472 TCGLabel
*label
= gen_new_label();
2473 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2474 TCGv_i32 addr
= tcg_temp_local_new_i32();
2477 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2478 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2479 gen_load_store_alignment(dc
, 2, addr
, true);
2481 gen_advance_ccount(dc
);
2482 tpc
= tcg_const_i32(dc
->pc
);
2483 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2484 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2485 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2486 cpu_SR
[SCOMPARE1
], label
);
2488 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2490 gen_set_label(label
);
2492 tcg_temp_free(addr
);
2498 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2499 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2501 #undef gen_load_store_no_hw_align
2503 default: /*reserved*/
2515 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2516 if (gen_window_check1(dc
, RRI8_S
) &&
2517 gen_check_cpenable(dc
, 0)) {
2518 TCGv_i32 addr
= tcg_temp_new_i32();
2519 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2520 gen_load_store_alignment(dc
, 2, addr
, false);
2522 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2524 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2527 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2529 tcg_temp_free(addr
);
2533 default: /*reserved*/
2540 HAS_OPTION(XTENSA_OPTION_MAC16
);
2549 bool is_m1_sr
= (OP2
& 0x3) == 2;
2550 bool is_m2_sr
= (OP2
& 0xc) == 0;
2551 uint32_t ld_offset
= 0;
2558 case 0: /*MACI?/MACC?*/
2560 ld_offset
= (OP2
& 1) ? -4 : 4;
2562 if (OP2
>= 8) { /*MACI/MACC*/
2563 if (OP1
== 0) { /*LDINC/LDDEC*/
2568 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2573 case 2: /*MACD?/MACA?*/
2574 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2580 if (op
!= MAC16_NONE
) {
2581 if (!is_m1_sr
&& !gen_window_check1(dc
, RRR_S
)) {
2584 if (!is_m2_sr
&& !gen_window_check1(dc
, RRR_T
)) {
2589 if (ld_offset
&& !gen_window_check1(dc
, RRR_S
)) {
2594 TCGv_i32 vaddr
= tcg_temp_new_i32();
2595 TCGv_i32 mem32
= tcg_temp_new_i32();
2598 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2599 gen_load_store_alignment(dc
, 2, vaddr
, false);
2600 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2602 if (op
!= MAC16_NONE
) {
2603 TCGv_i32 m1
= gen_mac16_m(
2604 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2605 OP1
& 1, op
== MAC16_UMUL
);
2606 TCGv_i32 m2
= gen_mac16_m(
2607 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2608 OP1
& 2, op
== MAC16_UMUL
);
2610 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2611 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2612 if (op
== MAC16_UMUL
) {
2613 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2615 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2618 TCGv_i32 lo
= tcg_temp_new_i32();
2619 TCGv_i32 hi
= tcg_temp_new_i32();
2621 tcg_gen_mul_i32(lo
, m1
, m2
);
2622 tcg_gen_sari_i32(hi
, lo
, 31);
2623 if (op
== MAC16_MULA
) {
2624 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2625 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2628 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2629 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2632 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2634 tcg_temp_free_i32(lo
);
2635 tcg_temp_free_i32(hi
);
2641 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2642 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2644 tcg_temp_free(vaddr
);
2645 tcg_temp_free(mem32
);
2653 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2654 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2660 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2661 if (gen_window_check1(dc
, CALL_N
<< 2)) {
2662 gen_callwi(dc
, CALL_N
,
2663 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2672 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2676 if (gen_window_check1(dc
, BRI12_S
)) {
2677 static const TCGCond cond
[] = {
2678 TCG_COND_EQ
, /*BEQZ*/
2679 TCG_COND_NE
, /*BNEZ*/
2680 TCG_COND_LT
, /*BLTZ*/
2681 TCG_COND_GE
, /*BGEZ*/
2684 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2685 4 + BRI12_IMM12_SE
);
2690 if (gen_window_check1(dc
, BRI8_S
)) {
2691 static const TCGCond cond
[] = {
2692 TCG_COND_EQ
, /*BEQI*/
2693 TCG_COND_NE
, /*BNEI*/
2694 TCG_COND_LT
, /*BLTI*/
2695 TCG_COND_GE
, /*BGEI*/
2698 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2699 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2706 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2708 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2709 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2710 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2711 gen_advance_ccount(dc
);
2712 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2716 /* This can change tb->flags, so exit tb */
2717 gen_jumpi_check_loop_end(dc
, -1);
2725 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2727 TCGv_i32 tmp
= tcg_temp_new_i32();
2728 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2730 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2731 tmp
, 0, 4 + RRI8_IMM8_SE
);
2738 case 10: /*LOOPGTZ*/
2739 HAS_OPTION(XTENSA_OPTION_LOOP
);
2740 if (gen_window_check1(dc
, RRI8_S
)) {
2741 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2742 TCGv_i32 tmp
= tcg_const_i32(lend
);
2744 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2745 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2746 gen_helper_wsr_lend(cpu_env
, tmp
);
2750 TCGLabel
*label
= gen_new_label();
2751 tcg_gen_brcondi_i32(
2752 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2753 cpu_R
[RRI8_S
], 0, label
);
2754 gen_jumpi(dc
, lend
, 1);
2755 gen_set_label(label
);
2758 gen_jumpi(dc
, dc
->next_pc
, 0);
2762 default: /*reserved*/
2771 if (gen_window_check1(dc
, BRI8_S
)) {
2772 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2773 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
],
2785 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2787 switch (RRI8_R
& 7) {
2788 case 0: /*BNONE*/ /*BANY*/
2789 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2790 TCGv_i32 tmp
= tcg_temp_new_i32();
2791 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2792 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2797 case 1: /*BEQ*/ /*BNE*/
2798 case 2: /*BLT*/ /*BGE*/
2799 case 3: /*BLTU*/ /*BGEU*/
2800 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2801 static const TCGCond cond
[] = {
2807 [11] = TCG_COND_GEU
,
2809 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2814 case 4: /*BALL*/ /*BNALL*/
2815 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2816 TCGv_i32 tmp
= tcg_temp_new_i32();
2817 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2818 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2824 case 5: /*BBC*/ /*BBS*/
2825 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2826 #ifdef TARGET_WORDS_BIGENDIAN
2827 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2829 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2831 TCGv_i32 tmp
= tcg_temp_new_i32();
2832 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2833 #ifdef TARGET_WORDS_BIGENDIAN
2834 tcg_gen_shr_i32(bit
, bit
, tmp
);
2836 tcg_gen_shl_i32(bit
, bit
, tmp
);
2838 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2839 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2845 case 6: /*BBCI*/ /*BBSI*/
2847 if (gen_window_check1(dc
, RRI8_S
)) {
2848 TCGv_i32 tmp
= tcg_temp_new_i32();
2849 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2850 #ifdef TARGET_WORDS_BIGENDIAN
2851 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2853 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2855 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2864 #define gen_narrow_load_store(type) do { \
2865 if (gen_window_check2(dc, RRRN_S, RRRN_T)) { \
2866 TCGv_i32 addr = tcg_temp_new_i32(); \
2867 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2868 gen_load_store_alignment(dc, 2, addr, false); \
2869 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2870 tcg_temp_free(addr); \
2875 gen_narrow_load_store(ld32u
);
2879 gen_narrow_load_store(st32
);
2881 #undef gen_narrow_load_store
2884 if (gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
)) {
2885 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2889 case 11: /*ADDI.Nn*/
2890 if (gen_window_check2(dc
, RRRN_R
, RRRN_S
)) {
2891 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
],
2892 RRRN_T
? RRRN_T
: -1);
2897 if (!gen_window_check1(dc
, RRRN_S
)) {
2900 if (RRRN_T
< 8) { /*MOVI.Nn*/
2901 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2902 RRRN_R
| (RRRN_T
<< 4) |
2903 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2904 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2905 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2907 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2908 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2915 if (gen_window_check2(dc
, RRRN_S
, RRRN_T
)) {
2916 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2923 gen_jump(dc
, cpu_R
[0]);
2927 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2929 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2930 gen_advance_ccount(dc
);
2931 gen_helper_retw(tmp
, cpu_env
, tmp
);
2937 case 2: /*BREAK.Nn*/
2938 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2940 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2948 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2951 default: /*reserved*/
2957 default: /*reserved*/
2963 default: /*reserved*/
2968 if (dc
->is_jmp
== DISAS_NEXT
) {
2969 gen_check_loop_end(dc
, 0);
2971 dc
->pc
= dc
->next_pc
;
2976 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2977 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2981 static inline unsigned xtensa_insn_len(CPUXtensaState
*env
, DisasContext
*dc
)
2983 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
2984 return xtensa_op0_insn_len(OP0
);
2987 static void check_breakpoint(CPUXtensaState
*env
, DisasContext
*dc
)
2989 CPUState
*cs
= CPU(xtensa_env_get_cpu(env
));
2992 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
2993 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
2994 if (bp
->pc
== dc
->pc
) {
2995 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2996 gen_exception(dc
, EXCP_DEBUG
);
2997 dc
->is_jmp
= DISAS_UPDATE
;
3003 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
3007 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
3008 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
3009 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
3010 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
3017 void gen_intermediate_code_internal(XtensaCPU
*cpu
,
3018 TranslationBlock
*tb
, bool search_pc
)
3020 CPUState
*cs
= CPU(cpu
);
3021 CPUXtensaState
*env
= &cpu
->env
;
3025 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3026 uint32_t pc_start
= tb
->pc
;
3027 uint32_t next_page_start
=
3028 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3030 if (max_insns
== 0) {
3031 max_insns
= CF_COUNT_MASK
;
3034 dc
.config
= env
->config
;
3035 dc
.singlestep_enabled
= cs
->singlestep_enabled
;
3038 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
3039 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
3040 dc
.lbeg
= env
->sregs
[LBEG
];
3041 dc
.lend
= env
->sregs
[LEND
];
3042 dc
.is_jmp
= DISAS_NEXT
;
3043 dc
.ccount_delta
= 0;
3044 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
3045 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
3046 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
3047 XTENSA_TBFLAG_CPENABLE_SHIFT
;
3048 dc
.window
= ((tb
->flags
& XTENSA_TBFLAG_WINDOW_MASK
) >>
3049 XTENSA_TBFLAG_WINDOW_SHIFT
);
3052 init_sar_tracker(&dc
);
3054 dc
.next_icount
= tcg_temp_local_new_i32();
3059 if (tb
->flags
& XTENSA_TBFLAG_EXCEPTION
) {
3060 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3061 gen_exception(&dc
, EXCP_DEBUG
);
3065 check_breakpoint(env
, &dc
);
3068 j
= tcg_op_buf_count();
3072 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3075 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
3076 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
3077 tcg_ctx
.gen_opc_icount
[lj
] = insn_count
;
3080 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
3081 tcg_gen_debug_insn_start(dc
.pc
);
3086 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3091 TCGLabel
*label
= gen_new_label();
3093 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
3094 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
3095 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
3097 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
3099 gen_set_label(label
);
3103 gen_ibreak_check(env
, &dc
);
3106 disas_xtensa_insn(env
, &dc
);
3109 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
3111 if (cs
->singlestep_enabled
) {
3112 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3113 gen_exception(&dc
, EXCP_DEBUG
);
3116 } while (dc
.is_jmp
== DISAS_NEXT
&&
3117 insn_count
< max_insns
&&
3118 dc
.pc
< next_page_start
&&
3119 dc
.pc
+ xtensa_insn_len(env
, &dc
) <= next_page_start
&&
3120 !tcg_op_buf_full());
3123 reset_sar_tracker(&dc
);
3125 tcg_temp_free(dc
.next_icount
);
3128 if (tb
->cflags
& CF_LAST_IO
) {
3132 if (dc
.is_jmp
== DISAS_NEXT
) {
3133 gen_jumpi(&dc
, dc
.pc
, 0);
3135 gen_tb_end(tb
, insn_count
);
3138 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3139 qemu_log("----------------\n");
3140 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3141 log_target_disas(cs
, pc_start
, dc
.pc
- pc_start
, 0);
3146 j
= tcg_op_buf_count();
3147 memset(tcg_ctx
.gen_opc_instr_start
+ lj
+ 1, 0,
3148 (j
- lj
) * sizeof(tcg_ctx
.gen_opc_instr_start
[0]));
3150 tb
->size
= dc
.pc
- pc_start
;
3151 tb
->icount
= insn_count
;
3155 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3157 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, false);
3160 void gen_intermediate_code_pc(CPUXtensaState
*env
, TranslationBlock
*tb
)
3162 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, true);
3165 void xtensa_cpu_dump_state(CPUState
*cs
, FILE *f
,
3166 fprintf_function cpu_fprintf
, int flags
)
3168 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
3169 CPUXtensaState
*env
= &cpu
->env
;
3172 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3174 for (i
= j
= 0; i
< 256; ++i
) {
3175 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3176 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3177 (j
++ % 4) == 3 ? '\n' : ' ');
3181 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3183 for (i
= j
= 0; i
< 256; ++i
) {
3184 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3185 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3186 (j
++ % 4) == 3 ? '\n' : ' ');
3190 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3192 for (i
= 0; i
< 16; ++i
) {
3193 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3194 (i
% 4) == 3 ? '\n' : ' ');
3197 cpu_fprintf(f
, "\n");
3199 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3200 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3201 (i
% 4) == 3 ? '\n' : ' ');
3204 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3205 cpu_fprintf(f
, "\n");
3207 for (i
= 0; i
< 16; ++i
) {
3208 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3209 float32_val(env
->fregs
[i
].f32
[FP_F32_LOW
]),
3210 *(float *)(env
->fregs
[i
].f32
+ FP_F32_LOW
),
3211 (i
% 2) == 1 ? '\n' : ' ');
3216 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
, int pc_pos
)
3218 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];