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"
41 #include "exec/helper-proto.h"
42 #include "exec/helper-gen.h"
44 #include "trace-tcg.h"
47 typedef struct DisasContext
{
48 const XtensaConfig
*config
;
58 int singlestep_enabled
;
62 bool sar_m32_allocated
;
65 uint32_t ccount_delta
;
75 static TCGv_ptr cpu_env
;
76 static TCGv_i32 cpu_pc
;
77 static TCGv_i32 cpu_R
[16];
78 static TCGv_i32 cpu_FR
[16];
79 static TCGv_i32 cpu_SR
[256];
80 static TCGv_i32 cpu_UR
[256];
82 #include "exec/gen-icount.h"
84 typedef struct XtensaReg
{
96 #define XTENSA_REG_ACCESS(regname, opt, acc) { \
98 .opt_bits = XTENSA_OPTION_BIT(opt), \
102 #define XTENSA_REG(regname, opt) XTENSA_REG_ACCESS(regname, opt, SR_RWX)
104 #define XTENSA_REG_BITS_ACCESS(regname, opt, acc) { \
110 #define XTENSA_REG_BITS(regname, opt) \
111 XTENSA_REG_BITS_ACCESS(regname, opt, SR_RWX)
113 static const XtensaReg sregnames
[256] = {
114 [LBEG
] = XTENSA_REG("LBEG", XTENSA_OPTION_LOOP
),
115 [LEND
] = XTENSA_REG("LEND", XTENSA_OPTION_LOOP
),
116 [LCOUNT
] = XTENSA_REG("LCOUNT", XTENSA_OPTION_LOOP
),
117 [SAR
] = XTENSA_REG_BITS("SAR", XTENSA_OPTION_ALL
),
118 [BR
] = XTENSA_REG("BR", XTENSA_OPTION_BOOLEAN
),
119 [LITBASE
] = XTENSA_REG("LITBASE", XTENSA_OPTION_EXTENDED_L32R
),
120 [SCOMPARE1
] = XTENSA_REG("SCOMPARE1", XTENSA_OPTION_CONDITIONAL_STORE
),
121 [ACCLO
] = XTENSA_REG("ACCLO", XTENSA_OPTION_MAC16
),
122 [ACCHI
] = XTENSA_REG("ACCHI", XTENSA_OPTION_MAC16
),
123 [MR
] = XTENSA_REG("MR0", XTENSA_OPTION_MAC16
),
124 [MR
+ 1] = XTENSA_REG("MR1", XTENSA_OPTION_MAC16
),
125 [MR
+ 2] = XTENSA_REG("MR2", XTENSA_OPTION_MAC16
),
126 [MR
+ 3] = XTENSA_REG("MR3", XTENSA_OPTION_MAC16
),
127 [WINDOW_BASE
] = XTENSA_REG("WINDOW_BASE", XTENSA_OPTION_WINDOWED_REGISTER
),
128 [WINDOW_START
] = XTENSA_REG("WINDOW_START",
129 XTENSA_OPTION_WINDOWED_REGISTER
),
130 [PTEVADDR
] = XTENSA_REG("PTEVADDR", XTENSA_OPTION_MMU
),
131 [RASID
] = XTENSA_REG("RASID", XTENSA_OPTION_MMU
),
132 [ITLBCFG
] = XTENSA_REG("ITLBCFG", XTENSA_OPTION_MMU
),
133 [DTLBCFG
] = XTENSA_REG("DTLBCFG", XTENSA_OPTION_MMU
),
134 [IBREAKENABLE
] = XTENSA_REG("IBREAKENABLE", XTENSA_OPTION_DEBUG
),
135 [CACHEATTR
] = XTENSA_REG("CACHEATTR", XTENSA_OPTION_CACHEATTR
),
136 [ATOMCTL
] = XTENSA_REG("ATOMCTL", XTENSA_OPTION_ATOMCTL
),
137 [IBREAKA
] = XTENSA_REG("IBREAKA0", XTENSA_OPTION_DEBUG
),
138 [IBREAKA
+ 1] = XTENSA_REG("IBREAKA1", XTENSA_OPTION_DEBUG
),
139 [DBREAKA
] = XTENSA_REG("DBREAKA0", XTENSA_OPTION_DEBUG
),
140 [DBREAKA
+ 1] = XTENSA_REG("DBREAKA1", XTENSA_OPTION_DEBUG
),
141 [DBREAKC
] = XTENSA_REG("DBREAKC0", XTENSA_OPTION_DEBUG
),
142 [DBREAKC
+ 1] = XTENSA_REG("DBREAKC1", XTENSA_OPTION_DEBUG
),
143 [CONFIGID0
] = XTENSA_REG_BITS_ACCESS("CONFIGID0", XTENSA_OPTION_ALL
, SR_R
),
144 [EPC1
] = XTENSA_REG("EPC1", XTENSA_OPTION_EXCEPTION
),
145 [EPC1
+ 1] = XTENSA_REG("EPC2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
146 [EPC1
+ 2] = XTENSA_REG("EPC3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
147 [EPC1
+ 3] = XTENSA_REG("EPC4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
148 [EPC1
+ 4] = XTENSA_REG("EPC5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
149 [EPC1
+ 5] = XTENSA_REG("EPC6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
150 [EPC1
+ 6] = XTENSA_REG("EPC7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
151 [DEPC
] = XTENSA_REG("DEPC", XTENSA_OPTION_EXCEPTION
),
152 [EPS2
] = XTENSA_REG("EPS2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
153 [EPS2
+ 1] = XTENSA_REG("EPS3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
154 [EPS2
+ 2] = XTENSA_REG("EPS4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
155 [EPS2
+ 3] = XTENSA_REG("EPS5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
156 [EPS2
+ 4] = XTENSA_REG("EPS6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
157 [EPS2
+ 5] = XTENSA_REG("EPS7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
158 [CONFIGID1
] = XTENSA_REG_BITS_ACCESS("CONFIGID1", XTENSA_OPTION_ALL
, SR_R
),
159 [EXCSAVE1
] = XTENSA_REG("EXCSAVE1", XTENSA_OPTION_EXCEPTION
),
160 [EXCSAVE1
+ 1] = XTENSA_REG("EXCSAVE2",
161 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
162 [EXCSAVE1
+ 2] = XTENSA_REG("EXCSAVE3",
163 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
164 [EXCSAVE1
+ 3] = XTENSA_REG("EXCSAVE4",
165 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
166 [EXCSAVE1
+ 4] = XTENSA_REG("EXCSAVE5",
167 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
168 [EXCSAVE1
+ 5] = XTENSA_REG("EXCSAVE6",
169 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
170 [EXCSAVE1
+ 6] = XTENSA_REG("EXCSAVE7",
171 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
172 [CPENABLE
] = XTENSA_REG("CPENABLE", XTENSA_OPTION_COPROCESSOR
),
173 [INTSET
] = XTENSA_REG_ACCESS("INTSET", XTENSA_OPTION_INTERRUPT
, SR_RW
),
174 [INTCLEAR
] = XTENSA_REG_ACCESS("INTCLEAR", XTENSA_OPTION_INTERRUPT
, SR_W
),
175 [INTENABLE
] = XTENSA_REG("INTENABLE", XTENSA_OPTION_INTERRUPT
),
176 [PS
] = XTENSA_REG_BITS("PS", XTENSA_OPTION_ALL
),
177 [VECBASE
] = XTENSA_REG("VECBASE", XTENSA_OPTION_RELOCATABLE_VECTOR
),
178 [EXCCAUSE
] = XTENSA_REG("EXCCAUSE", XTENSA_OPTION_EXCEPTION
),
179 [DEBUGCAUSE
] = XTENSA_REG_ACCESS("DEBUGCAUSE", XTENSA_OPTION_DEBUG
, SR_R
),
180 [CCOUNT
] = XTENSA_REG("CCOUNT", XTENSA_OPTION_TIMER_INTERRUPT
),
181 [PRID
] = XTENSA_REG_ACCESS("PRID", XTENSA_OPTION_PROCESSOR_ID
, SR_R
),
182 [ICOUNT
] = XTENSA_REG("ICOUNT", XTENSA_OPTION_DEBUG
),
183 [ICOUNTLEVEL
] = XTENSA_REG("ICOUNTLEVEL", XTENSA_OPTION_DEBUG
),
184 [EXCVADDR
] = XTENSA_REG("EXCVADDR", XTENSA_OPTION_EXCEPTION
),
185 [CCOMPARE
] = XTENSA_REG("CCOMPARE0", XTENSA_OPTION_TIMER_INTERRUPT
),
186 [CCOMPARE
+ 1] = XTENSA_REG("CCOMPARE1",
187 XTENSA_OPTION_TIMER_INTERRUPT
),
188 [CCOMPARE
+ 2] = XTENSA_REG("CCOMPARE2",
189 XTENSA_OPTION_TIMER_INTERRUPT
),
190 [MISC
] = XTENSA_REG("MISC0", XTENSA_OPTION_MISC_SR
),
191 [MISC
+ 1] = XTENSA_REG("MISC1", XTENSA_OPTION_MISC_SR
),
192 [MISC
+ 2] = XTENSA_REG("MISC2", XTENSA_OPTION_MISC_SR
),
193 [MISC
+ 3] = XTENSA_REG("MISC3", XTENSA_OPTION_MISC_SR
),
196 static const XtensaReg uregnames
[256] = {
197 [THREADPTR
] = XTENSA_REG("THREADPTR", XTENSA_OPTION_THREAD_POINTER
),
198 [FCR
] = XTENSA_REG("FCR", XTENSA_OPTION_FP_COPROCESSOR
),
199 [FSR
] = XTENSA_REG("FSR", XTENSA_OPTION_FP_COPROCESSOR
),
202 void xtensa_translate_init(void)
204 static const char * const regnames
[] = {
205 "ar0", "ar1", "ar2", "ar3",
206 "ar4", "ar5", "ar6", "ar7",
207 "ar8", "ar9", "ar10", "ar11",
208 "ar12", "ar13", "ar14", "ar15",
210 static const char * const fregnames
[] = {
211 "f0", "f1", "f2", "f3",
212 "f4", "f5", "f6", "f7",
213 "f8", "f9", "f10", "f11",
214 "f12", "f13", "f14", "f15",
218 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
219 cpu_pc
= tcg_global_mem_new_i32(TCG_AREG0
,
220 offsetof(CPUXtensaState
, pc
), "pc");
222 for (i
= 0; i
< 16; i
++) {
223 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
224 offsetof(CPUXtensaState
, regs
[i
]),
228 for (i
= 0; i
< 16; i
++) {
229 cpu_FR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
230 offsetof(CPUXtensaState
, fregs
[i
]),
234 for (i
= 0; i
< 256; ++i
) {
235 if (sregnames
[i
].name
) {
236 cpu_SR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
237 offsetof(CPUXtensaState
, sregs
[i
]),
242 for (i
= 0; i
< 256; ++i
) {
243 if (uregnames
[i
].name
) {
244 cpu_UR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
245 offsetof(CPUXtensaState
, uregs
[i
]),
251 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
253 return xtensa_option_bits_enabled(dc
->config
, opt
);
256 static inline bool option_enabled(DisasContext
*dc
, int opt
)
258 return xtensa_option_enabled(dc
->config
, opt
);
261 static void init_litbase(DisasContext
*dc
)
263 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
264 dc
->litbase
= tcg_temp_local_new_i32();
265 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
269 static void reset_litbase(DisasContext
*dc
)
271 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
272 tcg_temp_free(dc
->litbase
);
276 static void init_sar_tracker(DisasContext
*dc
)
278 dc
->sar_5bit
= false;
279 dc
->sar_m32_5bit
= false;
280 dc
->sar_m32_allocated
= false;
283 static void reset_sar_tracker(DisasContext
*dc
)
285 if (dc
->sar_m32_allocated
) {
286 tcg_temp_free(dc
->sar_m32
);
290 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
292 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
293 if (dc
->sar_m32_5bit
) {
294 tcg_gen_discard_i32(dc
->sar_m32
);
297 dc
->sar_m32_5bit
= false;
300 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
302 TCGv_i32 tmp
= tcg_const_i32(32);
303 if (!dc
->sar_m32_allocated
) {
304 dc
->sar_m32
= tcg_temp_local_new_i32();
305 dc
->sar_m32_allocated
= true;
307 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
308 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
309 dc
->sar_5bit
= false;
310 dc
->sar_m32_5bit
= true;
314 static void gen_advance_ccount(DisasContext
*dc
)
316 if (dc
->ccount_delta
> 0) {
317 TCGv_i32 tmp
= tcg_const_i32(dc
->ccount_delta
);
318 gen_helper_advance_ccount(cpu_env
, tmp
);
321 dc
->ccount_delta
= 0;
324 static void gen_exception(DisasContext
*dc
, int excp
)
326 TCGv_i32 tmp
= tcg_const_i32(excp
);
327 gen_advance_ccount(dc
);
328 gen_helper_exception(cpu_env
, tmp
);
332 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
334 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
335 TCGv_i32 tcause
= tcg_const_i32(cause
);
336 gen_advance_ccount(dc
);
337 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
339 tcg_temp_free(tcause
);
340 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
341 cause
== SYSCALL_CAUSE
) {
342 dc
->is_jmp
= DISAS_UPDATE
;
346 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
349 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
350 TCGv_i32 tcause
= tcg_const_i32(cause
);
351 gen_advance_ccount(dc
);
352 gen_helper_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
354 tcg_temp_free(tcause
);
357 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
359 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
360 TCGv_i32 tcause
= tcg_const_i32(cause
);
361 gen_advance_ccount(dc
);
362 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
364 tcg_temp_free(tcause
);
365 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
366 dc
->is_jmp
= DISAS_UPDATE
;
370 static bool gen_check_privilege(DisasContext
*dc
)
373 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
374 dc
->is_jmp
= DISAS_UPDATE
;
380 static bool gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
382 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
383 !(dc
->cpenable
& (1 << cp
))) {
384 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
385 dc
->is_jmp
= DISAS_UPDATE
;
391 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
393 tcg_gen_mov_i32(cpu_pc
, dest
);
394 gen_advance_ccount(dc
);
396 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
->next_icount
);
398 if (dc
->singlestep_enabled
) {
399 gen_exception(dc
, EXCP_DEBUG
);
402 tcg_gen_goto_tb(slot
);
403 tcg_gen_exit_tb((uintptr_t)dc
->tb
+ slot
);
408 dc
->is_jmp
= DISAS_UPDATE
;
411 static void gen_jump(DisasContext
*dc
, TCGv dest
)
413 gen_jump_slot(dc
, dest
, -1);
416 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
418 TCGv_i32 tmp
= tcg_const_i32(dest
);
419 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
422 gen_jump_slot(dc
, tmp
, slot
);
426 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
429 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
431 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
432 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
433 tcg_temp_free(tcallinc
);
434 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
435 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
436 gen_jump_slot(dc
, dest
, slot
);
439 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
441 gen_callw_slot(dc
, callinc
, dest
, -1);
444 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
446 TCGv_i32 tmp
= tcg_const_i32(dest
);
447 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
450 gen_callw_slot(dc
, callinc
, tmp
, slot
);
454 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
456 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
457 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
458 dc
->next_pc
== dc
->lend
) {
459 TCGLabel
*label
= gen_new_label();
461 gen_advance_ccount(dc
);
462 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
463 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
464 gen_jumpi(dc
, dc
->lbeg
, slot
);
465 gen_set_label(label
);
466 gen_jumpi(dc
, dc
->next_pc
, -1);
472 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
474 if (!gen_check_loop_end(dc
, slot
)) {
475 gen_jumpi(dc
, dc
->next_pc
, slot
);
479 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
480 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
482 TCGLabel
*label
= gen_new_label();
484 gen_advance_ccount(dc
);
485 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
486 gen_jumpi_check_loop_end(dc
, 0);
487 gen_set_label(label
);
488 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
491 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
492 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
494 TCGv_i32 tmp
= tcg_const_i32(t1
);
495 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
499 static bool gen_check_sr(DisasContext
*dc
, uint32_t sr
, unsigned access
)
501 if (!xtensa_option_bits_enabled(dc
->config
, sregnames
[sr
].opt_bits
)) {
502 if (sregnames
[sr
].name
) {
503 qemu_log("SR %s is not configured\n", sregnames
[sr
].name
);
505 qemu_log("SR %d is not implemented\n", sr
);
507 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
509 } else if (!(sregnames
[sr
].access
& access
)) {
510 static const char * const access_text
[] = {
515 assert(access
< ARRAY_SIZE(access_text
) && access_text
[access
]);
516 qemu_log("SR %s is not available for %s\n", sregnames
[sr
].name
,
517 access_text
[access
]);
518 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
524 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
526 gen_advance_ccount(dc
);
527 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
530 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
532 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
533 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
534 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
537 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
539 static void (* const rsr_handler
[256])(DisasContext
*dc
,
540 TCGv_i32 d
, uint32_t sr
) = {
541 [CCOUNT
] = gen_rsr_ccount
,
542 [PTEVADDR
] = gen_rsr_ptevaddr
,
545 if (rsr_handler
[sr
]) {
546 rsr_handler
[sr
](dc
, d
, sr
);
548 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
552 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
554 gen_helper_wsr_lbeg(cpu_env
, s
);
555 gen_jumpi_check_loop_end(dc
, 0);
558 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
560 gen_helper_wsr_lend(cpu_env
, s
);
561 gen_jumpi_check_loop_end(dc
, 0);
564 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
566 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
567 if (dc
->sar_m32_5bit
) {
568 tcg_gen_discard_i32(dc
->sar_m32
);
570 dc
->sar_5bit
= false;
571 dc
->sar_m32_5bit
= false;
574 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
576 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
579 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
581 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
582 /* This can change tb->flags, so exit tb */
583 gen_jumpi_check_loop_end(dc
, -1);
586 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
588 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
591 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
593 gen_helper_wsr_windowbase(cpu_env
, v
);
594 /* This can change tb->flags, so exit tb */
595 gen_jumpi_check_loop_end(dc
, -1);
598 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
600 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
601 /* This can change tb->flags, so exit tb */
602 gen_jumpi_check_loop_end(dc
, -1);
605 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
607 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
610 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
612 gen_helper_wsr_rasid(cpu_env
, v
);
613 /* This can change tb->flags, so exit tb */
614 gen_jumpi_check_loop_end(dc
, -1);
617 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
619 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
622 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
624 gen_helper_wsr_ibreakenable(cpu_env
, v
);
625 gen_jumpi_check_loop_end(dc
, 0);
628 static void gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
630 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
633 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
635 unsigned id
= sr
- IBREAKA
;
637 if (id
< dc
->config
->nibreak
) {
638 TCGv_i32 tmp
= tcg_const_i32(id
);
639 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
641 gen_jumpi_check_loop_end(dc
, 0);
645 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
647 unsigned id
= sr
- DBREAKA
;
649 if (id
< dc
->config
->ndbreak
) {
650 TCGv_i32 tmp
= tcg_const_i32(id
);
651 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
656 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
658 unsigned id
= sr
- DBREAKC
;
660 if (id
< dc
->config
->ndbreak
) {
661 TCGv_i32 tmp
= tcg_const_i32(id
);
662 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
667 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
669 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
670 /* This can change tb->flags, so exit tb */
671 gen_jumpi_check_loop_end(dc
, -1);
674 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
676 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
677 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
678 gen_helper_check_interrupts(cpu_env
);
679 gen_jumpi_check_loop_end(dc
, 0);
682 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
684 TCGv_i32 tmp
= tcg_temp_new_i32();
686 tcg_gen_andi_i32(tmp
, v
,
687 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
688 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
689 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
690 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
692 gen_helper_check_interrupts(cpu_env
);
695 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
697 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
698 gen_helper_check_interrupts(cpu_env
);
699 gen_jumpi_check_loop_end(dc
, 0);
702 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
704 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
705 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
707 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
710 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
711 gen_helper_check_interrupts(cpu_env
);
712 /* This can change mmu index and tb->flags, so exit tb */
713 gen_jumpi_check_loop_end(dc
, -1);
716 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
719 tcg_gen_mov_i32(dc
->next_icount
, v
);
721 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
725 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
727 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
728 /* This can change tb->flags, so exit tb */
729 gen_jumpi_check_loop_end(dc
, -1);
732 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
734 uint32_t id
= sr
- CCOMPARE
;
735 if (id
< dc
->config
->nccompare
) {
736 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
737 gen_advance_ccount(dc
);
738 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
739 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
740 gen_helper_check_interrupts(cpu_env
);
744 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
746 static void (* const wsr_handler
[256])(DisasContext
*dc
,
747 uint32_t sr
, TCGv_i32 v
) = {
748 [LBEG
] = gen_wsr_lbeg
,
749 [LEND
] = gen_wsr_lend
,
752 [LITBASE
] = gen_wsr_litbase
,
753 [ACCHI
] = gen_wsr_acchi
,
754 [WINDOW_BASE
] = gen_wsr_windowbase
,
755 [WINDOW_START
] = gen_wsr_windowstart
,
756 [PTEVADDR
] = gen_wsr_ptevaddr
,
757 [RASID
] = gen_wsr_rasid
,
758 [ITLBCFG
] = gen_wsr_tlbcfg
,
759 [DTLBCFG
] = gen_wsr_tlbcfg
,
760 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
761 [ATOMCTL
] = gen_wsr_atomctl
,
762 [IBREAKA
] = gen_wsr_ibreaka
,
763 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
764 [DBREAKA
] = gen_wsr_dbreaka
,
765 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
766 [DBREAKC
] = gen_wsr_dbreakc
,
767 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
768 [CPENABLE
] = gen_wsr_cpenable
,
769 [INTSET
] = gen_wsr_intset
,
770 [INTCLEAR
] = gen_wsr_intclear
,
771 [INTENABLE
] = gen_wsr_intenable
,
773 [ICOUNT
] = gen_wsr_icount
,
774 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
775 [CCOMPARE
] = gen_wsr_ccompare
,
776 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
777 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
780 if (wsr_handler
[sr
]) {
781 wsr_handler
[sr
](dc
, sr
, s
);
783 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
787 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
791 gen_helper_wur_fcr(cpu_env
, s
);
795 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
799 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
804 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
805 TCGv_i32 addr
, bool no_hw_alignment
)
807 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
808 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
809 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
811 TCGLabel
*label
= gen_new_label();
812 TCGv_i32 tmp
= tcg_temp_new_i32();
813 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
814 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
815 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
816 gen_set_label(label
);
821 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
823 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
824 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
825 gen_advance_ccount(dc
);
826 gen_helper_waiti(cpu_env
, pc
, intlevel
);
828 tcg_temp_free(intlevel
);
831 static bool gen_window_check1(DisasContext
*dc
, unsigned r1
)
833 if (r1
/ 4 > dc
->window
) {
834 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
835 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
837 gen_advance_ccount(dc
);
838 gen_helper_window_check(cpu_env
, pc
, w
);
839 dc
->is_jmp
= DISAS_UPDATE
;
845 static bool gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
847 return gen_window_check1(dc
, r1
> r2
? r1
: r2
);
850 static bool gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
853 return gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
856 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
858 TCGv_i32 m
= tcg_temp_new_i32();
861 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
863 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
868 static inline unsigned xtensa_op0_insn_len(unsigned op0
)
870 return op0
>= 8 ? 2 : 3;
873 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
875 #define HAS_OPTION_BITS(opt) do { \
876 if (!option_bits_enabled(dc, opt)) { \
877 qemu_log("Option is not enabled %s:%d\n", \
878 __FILE__, __LINE__); \
879 goto invalid_opcode; \
883 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
885 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
886 #define RESERVED() do { \
887 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
888 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
889 goto invalid_opcode; \
893 #ifdef TARGET_WORDS_BIGENDIAN
894 #define OP0 (((b0) & 0xf0) >> 4)
895 #define OP1 (((b2) & 0xf0) >> 4)
896 #define OP2 ((b2) & 0xf)
897 #define RRR_R ((b1) & 0xf)
898 #define RRR_S (((b1) & 0xf0) >> 4)
899 #define RRR_T ((b0) & 0xf)
901 #define OP0 (((b0) & 0xf))
902 #define OP1 (((b2) & 0xf))
903 #define OP2 (((b2) & 0xf0) >> 4)
904 #define RRR_R (((b1) & 0xf0) >> 4)
905 #define RRR_S (((b1) & 0xf))
906 #define RRR_T (((b0) & 0xf0) >> 4)
908 #define RRR_X ((RRR_R & 0x4) >> 2)
909 #define RRR_Y ((RRR_T & 0x4) >> 2)
910 #define RRR_W (RRR_R & 0x3)
919 #ifdef TARGET_WORDS_BIGENDIAN
920 #define RRI4_IMM4 ((b2) & 0xf)
922 #define RRI4_IMM4 (((b2) & 0xf0) >> 4)
928 #define RRI8_IMM8 (b2)
929 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
931 #ifdef TARGET_WORDS_BIGENDIAN
932 #define RI16_IMM16 (((b1) << 8) | (b2))
934 #define RI16_IMM16 (((b2) << 8) | (b1))
937 #ifdef TARGET_WORDS_BIGENDIAN
938 #define CALL_N (((b0) & 0xc) >> 2)
939 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
941 #define CALL_N (((b0) & 0x30) >> 4)
942 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
944 #define CALL_OFFSET_SE \
945 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
947 #define CALLX_N CALL_N
948 #ifdef TARGET_WORDS_BIGENDIAN
949 #define CALLX_M ((b0) & 0x3)
951 #define CALLX_M (((b0) & 0xc0) >> 6)
953 #define CALLX_S RRR_S
955 #define BRI12_M CALLX_M
956 #define BRI12_S RRR_S
957 #ifdef TARGET_WORDS_BIGENDIAN
958 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
960 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
962 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
964 #define BRI8_M BRI12_M
965 #define BRI8_R RRI8_R
966 #define BRI8_S RRI8_S
967 #define BRI8_IMM8 RRI8_IMM8
968 #define BRI8_IMM8_SE RRI8_IMM8_SE
972 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
973 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
975 unsigned len
= xtensa_op0_insn_len(OP0
);
977 static const uint32_t B4CONST
[] = {
978 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
981 static const uint32_t B4CONSTU
[] = {
982 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
987 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
991 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
997 dc
->next_pc
= dc
->pc
+ len
;
1005 if ((RRR_R
& 0xc) == 0x8) {
1006 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1013 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1016 case 1: /*reserved*/
1024 if (gen_window_check1(dc
, CALLX_S
)) {
1025 gen_jump(dc
, cpu_R
[CALLX_S
]);
1030 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1032 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1033 gen_advance_ccount(dc
);
1034 gen_helper_retw(tmp
, cpu_env
, tmp
);
1040 case 3: /*reserved*/
1047 if (!gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2)) {
1053 TCGv_i32 tmp
= tcg_temp_new_i32();
1054 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1055 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1063 case 3: /*CALLX12w*/
1064 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1066 TCGv_i32 tmp
= tcg_temp_new_i32();
1068 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1069 gen_callw(dc
, CALLX_N
, tmp
);
1079 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1080 if (gen_window_check2(dc
, RRR_T
, RRR_S
)) {
1081 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1082 gen_advance_ccount(dc
);
1083 gen_helper_movsp(cpu_env
, pc
);
1084 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1104 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1116 default: /*reserved*/
1125 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1128 if (gen_check_privilege(dc
)) {
1129 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1130 gen_helper_check_interrupts(cpu_env
);
1131 gen_jump(dc
, cpu_SR
[EPC1
]);
1140 if (gen_check_privilege(dc
)) {
1141 gen_jump(dc
, cpu_SR
[
1142 dc
->config
->ndepc
? DEPC
: EPC1
]);
1148 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1149 if (gen_check_privilege(dc
)) {
1150 TCGv_i32 tmp
= tcg_const_i32(1);
1153 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1154 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1157 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1158 cpu_SR
[WINDOW_START
], tmp
);
1160 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1161 cpu_SR
[WINDOW_START
], tmp
);
1164 gen_helper_restore_owb(cpu_env
);
1165 gen_helper_check_interrupts(cpu_env
);
1166 gen_jump(dc
, cpu_SR
[EPC1
]);
1172 default: /*reserved*/
1179 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1180 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1181 if (gen_check_privilege(dc
)) {
1182 tcg_gen_mov_i32(cpu_SR
[PS
],
1183 cpu_SR
[EPS2
+ RRR_S
- 2]);
1184 gen_helper_check_interrupts(cpu_env
);
1185 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1188 qemu_log("RFI %d is illegal\n", RRR_S
);
1189 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1197 default: /*reserved*/
1205 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1207 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1211 case 5: /*SYSCALLx*/
1212 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1214 case 0: /*SYSCALLx*/
1215 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1219 if (semihosting_enabled
) {
1220 if (gen_check_privilege(dc
)) {
1221 gen_helper_simcall(cpu_env
);
1224 qemu_log("SIMCALL but semihosting is disabled\n");
1225 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1236 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1237 if (gen_check_privilege(dc
) &&
1238 gen_window_check1(dc
, RRR_T
)) {
1239 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1240 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1241 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1242 gen_helper_check_interrupts(cpu_env
);
1243 gen_jumpi_check_loop_end(dc
, 0);
1248 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1249 if (gen_check_privilege(dc
)) {
1250 gen_waiti(dc
, RRR_S
);
1258 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1260 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1261 TCGv_i32 mask
= tcg_const_i32(
1262 ((1 << shift
) - 1) << RRR_S
);
1263 TCGv_i32 tmp
= tcg_temp_new_i32();
1265 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1266 if (RRR_R
& 1) { /*ALL*/
1267 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1269 tcg_gen_add_i32(tmp
, tmp
, mask
);
1271 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1272 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1274 tcg_temp_free(mask
);
1279 default: /*reserved*/
1287 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1288 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1293 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1294 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1299 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1300 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1307 if (gen_window_check1(dc
, RRR_S
)) {
1308 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1313 if (gen_window_check1(dc
, RRR_S
)) {
1314 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1319 if (gen_window_check1(dc
, RRR_S
)) {
1320 TCGv_i32 tmp
= tcg_temp_new_i32();
1321 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1322 gen_right_shift_sar(dc
, tmp
);
1328 if (gen_window_check1(dc
, RRR_S
)) {
1329 TCGv_i32 tmp
= tcg_temp_new_i32();
1330 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1331 gen_left_shift_sar(dc
, tmp
);
1338 TCGv_i32 tmp
= tcg_const_i32(
1339 RRR_S
| ((RRR_T
& 1) << 4));
1340 gen_right_shift_sar(dc
, tmp
);
1354 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1355 if (gen_check_privilege(dc
)) {
1356 TCGv_i32 tmp
= tcg_const_i32(
1357 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1358 gen_helper_rotw(cpu_env
, tmp
);
1360 /* This can change tb->flags, so exit tb */
1361 gen_jumpi_check_loop_end(dc
, -1);
1366 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1367 if (gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1368 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1373 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1374 if (gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1375 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1379 default: /*reserved*/
1387 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1388 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1389 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1390 if (gen_check_privilege(dc
) &&
1391 gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1392 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1394 switch (RRR_R
& 7) {
1395 case 3: /*RITLB0*/ /*RDTLB0*/
1396 gen_helper_rtlb0(cpu_R
[RRR_T
],
1397 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1400 case 4: /*IITLB*/ /*IDTLB*/
1401 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1402 /* This could change memory mapping, so exit tb */
1403 gen_jumpi_check_loop_end(dc
, -1);
1406 case 5: /*PITLB*/ /*PDTLB*/
1407 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1408 gen_helper_ptlb(cpu_R
[RRR_T
],
1409 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1412 case 6: /*WITLB*/ /*WDTLB*/
1414 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1415 /* This could change memory mapping, so exit tb */
1416 gen_jumpi_check_loop_end(dc
, -1);
1419 case 7: /*RITLB1*/ /*RDTLB1*/
1420 gen_helper_rtlb1(cpu_R
[RRR_T
],
1421 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1425 tcg_temp_free(dtlb
);
1429 tcg_temp_free(dtlb
);
1434 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1439 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1444 TCGv_i32 zero
= tcg_const_i32(0);
1445 TCGv_i32 neg
= tcg_temp_new_i32();
1447 tcg_gen_neg_i32(neg
, cpu_R
[RRR_T
]);
1448 tcg_gen_movcond_i32(TCG_COND_GE
, cpu_R
[RRR_R
],
1449 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_T
], neg
);
1451 tcg_temp_free(zero
);
1455 default: /*reserved*/
1461 case 7: /*reserved*/
1466 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1467 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1474 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1475 TCGv_i32 tmp
= tcg_temp_new_i32();
1476 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1477 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1483 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1484 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1491 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1492 TCGv_i32 tmp
= tcg_temp_new_i32();
1493 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1494 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1505 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1506 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1507 32 - (RRR_T
| ((OP2
& 1) << 4)));
1513 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1514 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1515 RRR_S
| ((OP2
& 1) << 4));
1520 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1521 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1526 if (gen_check_sr(dc
, RSR_SR
, SR_X
) &&
1527 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1528 gen_window_check1(dc
, RRR_T
)) {
1529 TCGv_i32 tmp
= tcg_temp_new_i32();
1531 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1532 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1533 gen_wsr(dc
, RSR_SR
, tmp
);
1539 * Note: 64 bit ops are used here solely because SAR values
1542 #define gen_shift_reg(cmd, reg) do { \
1543 TCGv_i64 tmp = tcg_temp_new_i64(); \
1544 tcg_gen_extu_i32_i64(tmp, reg); \
1545 tcg_gen_##cmd##_i64(v, v, tmp); \
1546 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \
1547 tcg_temp_free_i64(v); \
1548 tcg_temp_free_i64(tmp); \
1551 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1554 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1555 TCGv_i64 v
= tcg_temp_new_i64();
1556 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1562 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1566 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1568 TCGv_i64 v
= tcg_temp_new_i64();
1569 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1575 if (!gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1578 if (dc
->sar_m32_5bit
) {
1579 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1581 TCGv_i64 v
= tcg_temp_new_i64();
1582 TCGv_i32 s
= tcg_const_i32(32);
1583 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1584 tcg_gen_andi_i32(s
, s
, 0x3f);
1585 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1586 gen_shift_reg(shl
, s
);
1592 if (!gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1596 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1598 TCGv_i64 v
= tcg_temp_new_i64();
1599 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1604 #undef gen_shift_reg
1607 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1608 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1609 TCGv_i32 v1
= tcg_temp_new_i32();
1610 TCGv_i32 v2
= tcg_temp_new_i32();
1611 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1612 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1613 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1620 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1621 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1622 TCGv_i32 v1
= tcg_temp_new_i32();
1623 TCGv_i32 v2
= tcg_temp_new_i32();
1624 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1625 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1626 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1632 default: /*reserved*/
1639 if (OP2
>= 8 && !gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1644 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1645 TCGLabel
*label
= gen_new_label();
1646 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1647 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1648 gen_set_label(label
);
1652 #define BOOLEAN_LOGIC(fn, r, s, t) \
1654 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1655 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1656 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1658 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1659 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1660 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1661 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1662 tcg_temp_free(tmp1); \
1663 tcg_temp_free(tmp2); \
1667 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1671 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1675 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1679 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1683 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1686 #undef BOOLEAN_LOGIC
1689 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1690 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1695 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1697 TCGv lo
= tcg_temp_new();
1700 tcg_gen_mulu2_i32(lo
, cpu_R
[RRR_R
],
1701 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1703 tcg_gen_muls2_i32(lo
, cpu_R
[RRR_R
],
1704 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1711 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1717 TCGLabel
*label1
= gen_new_label();
1718 TCGLabel
*label2
= gen_new_label();
1720 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1722 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1724 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1725 OP2
== 13 ? 0x80000000 : 0);
1727 gen_set_label(label1
);
1729 tcg_gen_div_i32(cpu_R
[RRR_R
],
1730 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1732 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1733 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1735 gen_set_label(label2
);
1740 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1743 default: /*reserved*/
1752 if (gen_check_sr(dc
, RSR_SR
, SR_R
) &&
1753 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1754 gen_window_check1(dc
, RRR_T
)) {
1755 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1760 if (gen_check_sr(dc
, RSR_SR
, SR_W
) &&
1761 (RSR_SR
< 64 || gen_check_privilege(dc
)) &&
1762 gen_window_check1(dc
, RRR_T
)) {
1763 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1768 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1769 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1770 int shift
= 24 - RRR_T
;
1773 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1774 } else if (shift
== 16) {
1775 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1777 TCGv_i32 tmp
= tcg_temp_new_i32();
1778 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1779 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1786 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1787 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1788 TCGv_i32 tmp1
= tcg_temp_new_i32();
1789 TCGv_i32 tmp2
= tcg_temp_new_i32();
1790 TCGv_i32 zero
= tcg_const_i32(0);
1792 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1793 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1794 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1796 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1797 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1799 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1800 cpu_R
[RRR_S
], tmp1
);
1801 tcg_temp_free(tmp1
);
1802 tcg_temp_free(tmp2
);
1803 tcg_temp_free(zero
);
1811 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1812 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1813 static const TCGCond cond
[] = {
1819 tcg_gen_movcond_i32(cond
[OP2
- 4], cpu_R
[RRR_R
],
1820 cpu_R
[RRR_S
], cpu_R
[RRR_T
],
1821 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1829 if (gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
)) {
1830 static const TCGCond cond
[] = {
1836 TCGv_i32 zero
= tcg_const_i32(0);
1838 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1839 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1840 tcg_temp_free(zero
);
1846 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1847 if (gen_window_check2(dc
, RRR_R
, RRR_S
)) {
1848 TCGv_i32 zero
= tcg_const_i32(0);
1849 TCGv_i32 tmp
= tcg_temp_new_i32();
1851 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1852 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1853 cpu_R
[RRR_R
], tmp
, zero
,
1854 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1857 tcg_temp_free(zero
);
1862 if (gen_window_check1(dc
, RRR_R
)) {
1863 int st
= (RRR_S
<< 4) + RRR_T
;
1864 if (uregnames
[st
].name
) {
1865 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1867 qemu_log("RUR %d not implemented, ", st
);
1874 if (gen_window_check1(dc
, RRR_T
)) {
1875 if (uregnames
[RSR_SR
].name
) {
1876 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1878 qemu_log("WUR %d not implemented, ", RSR_SR
);
1889 if (gen_window_check2(dc
, RRR_R
, RRR_T
)) {
1890 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1891 int maskimm
= (1 << (OP2
+ 1)) - 1;
1893 TCGv_i32 tmp
= tcg_temp_new_i32();
1894 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1895 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1914 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1915 if (gen_window_check2(dc
, RRR_S
, RRR_T
) &&
1916 gen_check_cpenable(dc
, 0)) {
1917 TCGv_i32 addr
= tcg_temp_new_i32();
1918 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1919 gen_load_store_alignment(dc
, 2, addr
, false);
1921 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1923 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1926 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1928 tcg_temp_free(addr
);
1932 default: /*reserved*/
1939 if (!gen_window_check2(dc
, RRR_S
, RRR_T
)) {
1944 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1945 if (gen_check_privilege(dc
)) {
1946 TCGv_i32 addr
= tcg_temp_new_i32();
1947 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1948 (0xffffffc0 | (RRR_R
<< 2)));
1949 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1950 tcg_temp_free(addr
);
1955 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1956 if (gen_check_privilege(dc
)) {
1957 TCGv_i32 addr
= tcg_temp_new_i32();
1958 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1959 (0xffffffc0 | (RRR_R
<< 2)));
1960 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1961 tcg_temp_free(addr
);
1972 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1975 if (gen_check_cpenable(dc
, 0)) {
1976 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
1977 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1982 if (gen_check_cpenable(dc
, 0)) {
1983 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
1984 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1989 if (gen_check_cpenable(dc
, 0)) {
1990 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
1991 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1996 if (gen_check_cpenable(dc
, 0)) {
1997 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
1998 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2004 if (gen_check_cpenable(dc
, 0)) {
2005 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
2006 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
],
2011 case 8: /*ROUND.Sf*/
2012 case 9: /*TRUNC.Sf*/
2013 case 10: /*FLOOR.Sf*/
2014 case 11: /*CEIL.Sf*/
2015 case 14: /*UTRUNC.Sf*/
2016 if (gen_window_check1(dc
, RRR_R
) &&
2017 gen_check_cpenable(dc
, 0)) {
2018 static const unsigned rounding_mode_const
[] = {
2019 float_round_nearest_even
,
2020 float_round_to_zero
,
2023 [6] = float_round_to_zero
,
2025 TCGv_i32 rounding_mode
= tcg_const_i32(
2026 rounding_mode_const
[OP2
& 7]);
2027 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2030 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2031 rounding_mode
, scale
);
2033 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2034 rounding_mode
, scale
);
2037 tcg_temp_free(rounding_mode
);
2038 tcg_temp_free(scale
);
2042 case 12: /*FLOAT.Sf*/
2043 case 13: /*UFLOAT.Sf*/
2044 if (gen_window_check1(dc
, RRR_S
) &&
2045 gen_check_cpenable(dc
, 0)) {
2046 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2049 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2050 cpu_R
[RRR_S
], scale
);
2052 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2053 cpu_R
[RRR_S
], scale
);
2055 tcg_temp_free(scale
);
2062 if (gen_check_cpenable(dc
, 0)) {
2063 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2068 if (gen_check_cpenable(dc
, 0)) {
2069 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2074 if (gen_window_check1(dc
, RRR_R
) &&
2075 gen_check_cpenable(dc
, 0)) {
2076 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2081 if (gen_window_check1(dc
, RRR_S
) &&
2082 gen_check_cpenable(dc
, 0)) {
2083 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2088 if (gen_check_cpenable(dc
, 0)) {
2089 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2093 default: /*reserved*/
2099 default: /*reserved*/
2106 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2108 #define gen_compare(rel, br, a, b) \
2110 if (gen_check_cpenable(dc, 0)) { \
2111 TCGv_i32 bit = tcg_const_i32(1 << br); \
2113 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2114 tcg_temp_free(bit); \
2120 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2124 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2128 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2132 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2136 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2140 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2144 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2149 case 8: /*MOVEQZ.Sf*/
2150 case 9: /*MOVNEZ.Sf*/
2151 case 10: /*MOVLTZ.Sf*/
2152 case 11: /*MOVGEZ.Sf*/
2153 if (gen_window_check1(dc
, RRR_T
) &&
2154 gen_check_cpenable(dc
, 0)) {
2155 static const TCGCond cond
[] = {
2161 TCGv_i32 zero
= tcg_const_i32(0);
2163 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2164 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2165 tcg_temp_free(zero
);
2169 case 12: /*MOVF.Sf*/
2170 case 13: /*MOVT.Sf*/
2171 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2172 if (gen_check_cpenable(dc
, 0)) {
2173 TCGv_i32 zero
= tcg_const_i32(0);
2174 TCGv_i32 tmp
= tcg_temp_new_i32();
2176 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2177 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2178 cpu_FR
[RRR_R
], tmp
, zero
,
2179 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2182 tcg_temp_free(zero
);
2186 default: /*reserved*/
2192 default: /*reserved*/
2199 if (gen_window_check1(dc
, RRR_T
)) {
2200 TCGv_i32 tmp
= tcg_const_i32(
2201 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2202 0 : ((dc
->pc
+ 3) & ~3)) +
2203 (0xfffc0000 | (RI16_IMM16
<< 2)));
2205 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2206 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2208 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2214 #define gen_load_store(type, shift) do { \
2215 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2216 TCGv_i32 addr = tcg_temp_new_i32(); \
2218 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2220 gen_load_store_alignment(dc, shift, addr, false); \
2222 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2223 tcg_temp_free(addr); \
2229 gen_load_store(ld8u
, 0);
2233 gen_load_store(ld16u
, 1);
2237 gen_load_store(ld32u
, 2);
2241 gen_load_store(st8
, 0);
2245 gen_load_store(st16
, 1);
2249 gen_load_store(st32
, 2);
2252 #define gen_dcache_hit_test(w, shift) do { \
2253 if (gen_window_check1(dc, RRI##w##_S)) { \
2254 TCGv_i32 addr = tcg_temp_new_i32(); \
2255 TCGv_i32 res = tcg_temp_new_i32(); \
2256 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2257 RRI##w##_IMM##w << shift); \
2258 tcg_gen_qemu_ld8u(res, addr, dc->cring); \
2259 tcg_temp_free(addr); \
2260 tcg_temp_free(res); \
2264 #define gen_dcache_hit_test4() gen_dcache_hit_test(4, 4)
2265 #define gen_dcache_hit_test8() gen_dcache_hit_test(8, 2)
2269 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2274 gen_window_check1(dc
, RRI8_S
);
2278 gen_window_check1(dc
, RRI8_S
);
2282 gen_window_check1(dc
, RRI8_S
);
2286 gen_window_check1(dc
, RRI8_S
);
2290 gen_dcache_hit_test8();
2294 gen_dcache_hit_test8();
2298 if (gen_check_privilege(dc
)) {
2299 gen_dcache_hit_test8();
2304 if (gen_check_privilege(dc
)) {
2305 gen_window_check1(dc
, RRI8_S
);
2312 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2313 if (gen_check_privilege(dc
)) {
2314 gen_dcache_hit_test4();
2319 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2320 if (gen_check_privilege(dc
)) {
2321 gen_dcache_hit_test4();
2326 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2327 if (gen_check_privilege(dc
)) {
2328 gen_window_check1(dc
, RRI4_S
);
2333 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2334 if (gen_check_privilege(dc
)) {
2335 gen_window_check1(dc
, RRI4_S
);
2340 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2341 if (gen_check_privilege(dc
)) {
2342 gen_window_check1(dc
, RRI4_S
);
2346 default: /*reserved*/
2353 #undef gen_dcache_hit_test
2354 #undef gen_dcache_hit_test4
2355 #undef gen_dcache_hit_test8
2357 #define gen_icache_hit_test(w, shift) do { \
2358 if (gen_window_check1(dc, RRI##w##_S)) { \
2359 TCGv_i32 addr = tcg_temp_new_i32(); \
2360 tcg_gen_movi_i32(cpu_pc, dc->pc); \
2361 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2362 RRI##w##_IMM##w << shift); \
2363 gen_helper_itlb_hit_test(cpu_env, addr); \
2364 tcg_temp_free(addr); \
2368 #define gen_icache_hit_test4() gen_icache_hit_test(4, 4)
2369 #define gen_icache_hit_test8() gen_icache_hit_test(8, 2)
2372 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2373 gen_window_check1(dc
, RRI8_S
);
2379 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2380 if (gen_check_privilege(dc
)) {
2381 gen_icache_hit_test4();
2386 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2387 if (gen_check_privilege(dc
)) {
2388 gen_icache_hit_test4();
2393 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2394 if (gen_check_privilege(dc
)) {
2395 gen_window_check1(dc
, RRI4_S
);
2399 default: /*reserved*/
2406 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2407 gen_icache_hit_test8();
2411 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2412 if (gen_check_privilege(dc
)) {
2413 gen_window_check1(dc
, RRI8_S
);
2417 default: /*reserved*/
2423 #undef gen_icache_hit_test
2424 #undef gen_icache_hit_test4
2425 #undef gen_icache_hit_test8
2428 gen_load_store(ld16s
, 1);
2430 #undef gen_load_store
2433 if (gen_window_check1(dc
, RRI8_T
)) {
2434 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2435 RRI8_IMM8
| (RRI8_S
<< 8) |
2436 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2440 #define gen_load_store_no_hw_align(type) do { \
2441 if (gen_window_check2(dc, RRI8_S, RRI8_T)) { \
2442 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2443 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2444 gen_load_store_alignment(dc, 2, addr, true); \
2445 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2446 tcg_temp_free(addr); \
2451 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2452 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2456 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2457 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2462 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2463 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
],
2468 case 14: /*S32C1Iy*/
2469 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2470 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2471 TCGLabel
*label
= gen_new_label();
2472 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2473 TCGv_i32 addr
= tcg_temp_local_new_i32();
2476 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2477 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2478 gen_load_store_alignment(dc
, 2, addr
, true);
2480 gen_advance_ccount(dc
);
2481 tpc
= tcg_const_i32(dc
->pc
);
2482 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2483 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2484 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2485 cpu_SR
[SCOMPARE1
], label
);
2487 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2489 gen_set_label(label
);
2491 tcg_temp_free(addr
);
2497 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2498 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2500 #undef gen_load_store_no_hw_align
2502 default: /*reserved*/
2514 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2515 if (gen_window_check1(dc
, RRI8_S
) &&
2516 gen_check_cpenable(dc
, 0)) {
2517 TCGv_i32 addr
= tcg_temp_new_i32();
2518 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2519 gen_load_store_alignment(dc
, 2, addr
, false);
2521 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2523 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2526 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2528 tcg_temp_free(addr
);
2532 default: /*reserved*/
2539 HAS_OPTION(XTENSA_OPTION_MAC16
);
2548 bool is_m1_sr
= (OP2
& 0x3) == 2;
2549 bool is_m2_sr
= (OP2
& 0xc) == 0;
2550 uint32_t ld_offset
= 0;
2557 case 0: /*MACI?/MACC?*/
2559 ld_offset
= (OP2
& 1) ? -4 : 4;
2561 if (OP2
>= 8) { /*MACI/MACC*/
2562 if (OP1
== 0) { /*LDINC/LDDEC*/
2567 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2572 case 2: /*MACD?/MACA?*/
2573 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2579 if (op
!= MAC16_NONE
) {
2580 if (!is_m1_sr
&& !gen_window_check1(dc
, RRR_S
)) {
2583 if (!is_m2_sr
&& !gen_window_check1(dc
, RRR_T
)) {
2588 if (ld_offset
&& !gen_window_check1(dc
, RRR_S
)) {
2593 TCGv_i32 vaddr
= tcg_temp_new_i32();
2594 TCGv_i32 mem32
= tcg_temp_new_i32();
2597 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2598 gen_load_store_alignment(dc
, 2, vaddr
, false);
2599 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2601 if (op
!= MAC16_NONE
) {
2602 TCGv_i32 m1
= gen_mac16_m(
2603 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2604 OP1
& 1, op
== MAC16_UMUL
);
2605 TCGv_i32 m2
= gen_mac16_m(
2606 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2607 OP1
& 2, op
== MAC16_UMUL
);
2609 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2610 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2611 if (op
== MAC16_UMUL
) {
2612 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2614 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2617 TCGv_i32 lo
= tcg_temp_new_i32();
2618 TCGv_i32 hi
= tcg_temp_new_i32();
2620 tcg_gen_mul_i32(lo
, m1
, m2
);
2621 tcg_gen_sari_i32(hi
, lo
, 31);
2622 if (op
== MAC16_MULA
) {
2623 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2624 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2627 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2628 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2631 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2633 tcg_temp_free_i32(lo
);
2634 tcg_temp_free_i32(hi
);
2640 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2641 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2643 tcg_temp_free(vaddr
);
2644 tcg_temp_free(mem32
);
2652 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2653 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2659 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2660 if (gen_window_check1(dc
, CALL_N
<< 2)) {
2661 gen_callwi(dc
, CALL_N
,
2662 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2671 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2675 if (gen_window_check1(dc
, BRI12_S
)) {
2676 static const TCGCond cond
[] = {
2677 TCG_COND_EQ
, /*BEQZ*/
2678 TCG_COND_NE
, /*BNEZ*/
2679 TCG_COND_LT
, /*BLTZ*/
2680 TCG_COND_GE
, /*BGEZ*/
2683 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2684 4 + BRI12_IMM12_SE
);
2689 if (gen_window_check1(dc
, BRI8_S
)) {
2690 static const TCGCond cond
[] = {
2691 TCG_COND_EQ
, /*BEQI*/
2692 TCG_COND_NE
, /*BNEI*/
2693 TCG_COND_LT
, /*BLTI*/
2694 TCG_COND_GE
, /*BGEI*/
2697 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2698 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2705 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2707 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2708 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2709 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2710 gen_advance_ccount(dc
);
2711 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2715 /* This can change tb->flags, so exit tb */
2716 gen_jumpi_check_loop_end(dc
, -1);
2724 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2726 TCGv_i32 tmp
= tcg_temp_new_i32();
2727 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2729 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2730 tmp
, 0, 4 + RRI8_IMM8_SE
);
2737 case 10: /*LOOPGTZ*/
2738 HAS_OPTION(XTENSA_OPTION_LOOP
);
2739 if (gen_window_check1(dc
, RRI8_S
)) {
2740 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2741 TCGv_i32 tmp
= tcg_const_i32(lend
);
2743 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2744 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2745 gen_helper_wsr_lend(cpu_env
, tmp
);
2749 TCGLabel
*label
= gen_new_label();
2750 tcg_gen_brcondi_i32(
2751 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2752 cpu_R
[RRI8_S
], 0, label
);
2753 gen_jumpi(dc
, lend
, 1);
2754 gen_set_label(label
);
2757 gen_jumpi(dc
, dc
->next_pc
, 0);
2761 default: /*reserved*/
2770 if (gen_window_check1(dc
, BRI8_S
)) {
2771 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2772 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
],
2784 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2786 switch (RRI8_R
& 7) {
2787 case 0: /*BNONE*/ /*BANY*/
2788 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2789 TCGv_i32 tmp
= tcg_temp_new_i32();
2790 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2791 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2796 case 1: /*BEQ*/ /*BNE*/
2797 case 2: /*BLT*/ /*BGE*/
2798 case 3: /*BLTU*/ /*BGEU*/
2799 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2800 static const TCGCond cond
[] = {
2806 [11] = TCG_COND_GEU
,
2808 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2813 case 4: /*BALL*/ /*BNALL*/
2814 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2815 TCGv_i32 tmp
= tcg_temp_new_i32();
2816 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2817 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2823 case 5: /*BBC*/ /*BBS*/
2824 if (gen_window_check2(dc
, RRI8_S
, RRI8_T
)) {
2825 #ifdef TARGET_WORDS_BIGENDIAN
2826 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2828 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2830 TCGv_i32 tmp
= tcg_temp_new_i32();
2831 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2832 #ifdef TARGET_WORDS_BIGENDIAN
2833 tcg_gen_shr_i32(bit
, bit
, tmp
);
2835 tcg_gen_shl_i32(bit
, bit
, tmp
);
2837 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2838 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2844 case 6: /*BBCI*/ /*BBSI*/
2846 if (gen_window_check1(dc
, RRI8_S
)) {
2847 TCGv_i32 tmp
= tcg_temp_new_i32();
2848 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2849 #ifdef TARGET_WORDS_BIGENDIAN
2850 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2852 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2854 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2863 #define gen_narrow_load_store(type) do { \
2864 if (gen_window_check2(dc, RRRN_S, RRRN_T)) { \
2865 TCGv_i32 addr = tcg_temp_new_i32(); \
2866 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2867 gen_load_store_alignment(dc, 2, addr, false); \
2868 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2869 tcg_temp_free(addr); \
2874 gen_narrow_load_store(ld32u
);
2878 gen_narrow_load_store(st32
);
2880 #undef gen_narrow_load_store
2883 if (gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
)) {
2884 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2888 case 11: /*ADDI.Nn*/
2889 if (gen_window_check2(dc
, RRRN_R
, RRRN_S
)) {
2890 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
],
2891 RRRN_T
? RRRN_T
: -1);
2896 if (!gen_window_check1(dc
, RRRN_S
)) {
2899 if (RRRN_T
< 8) { /*MOVI.Nn*/
2900 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2901 RRRN_R
| (RRRN_T
<< 4) |
2902 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2903 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2904 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2906 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2907 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2914 if (gen_window_check2(dc
, RRRN_S
, RRRN_T
)) {
2915 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2922 gen_jump(dc
, cpu_R
[0]);
2926 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2928 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2929 gen_advance_ccount(dc
);
2930 gen_helper_retw(tmp
, cpu_env
, tmp
);
2936 case 2: /*BREAK.Nn*/
2937 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2939 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2947 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2950 default: /*reserved*/
2956 default: /*reserved*/
2962 default: /*reserved*/
2967 if (dc
->is_jmp
== DISAS_NEXT
) {
2968 gen_check_loop_end(dc
, 0);
2970 dc
->pc
= dc
->next_pc
;
2975 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2976 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2980 static inline unsigned xtensa_insn_len(CPUXtensaState
*env
, DisasContext
*dc
)
2982 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
2983 return xtensa_op0_insn_len(OP0
);
2986 static void check_breakpoint(CPUXtensaState
*env
, DisasContext
*dc
)
2988 CPUState
*cs
= CPU(xtensa_env_get_cpu(env
));
2991 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
2992 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
2993 if (bp
->pc
== dc
->pc
) {
2994 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2995 gen_exception(dc
, EXCP_DEBUG
);
2996 dc
->is_jmp
= DISAS_UPDATE
;
3002 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
3006 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
3007 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
3008 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
3009 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
3016 void gen_intermediate_code_internal(XtensaCPU
*cpu
,
3017 TranslationBlock
*tb
, bool search_pc
)
3019 CPUState
*cs
= CPU(cpu
);
3020 CPUXtensaState
*env
= &cpu
->env
;
3024 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
3025 uint32_t pc_start
= tb
->pc
;
3026 uint32_t next_page_start
=
3027 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
3029 if (max_insns
== 0) {
3030 max_insns
= CF_COUNT_MASK
;
3033 dc
.config
= env
->config
;
3034 dc
.singlestep_enabled
= cs
->singlestep_enabled
;
3037 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
3038 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
3039 dc
.lbeg
= env
->sregs
[LBEG
];
3040 dc
.lend
= env
->sregs
[LEND
];
3041 dc
.is_jmp
= DISAS_NEXT
;
3042 dc
.ccount_delta
= 0;
3043 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
3044 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
3045 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
3046 XTENSA_TBFLAG_CPENABLE_SHIFT
;
3047 dc
.window
= ((tb
->flags
& XTENSA_TBFLAG_WINDOW_MASK
) >>
3048 XTENSA_TBFLAG_WINDOW_SHIFT
);
3051 init_sar_tracker(&dc
);
3053 dc
.next_icount
= tcg_temp_local_new_i32();
3058 if (tb
->flags
& XTENSA_TBFLAG_EXCEPTION
) {
3059 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3060 gen_exception(&dc
, EXCP_DEBUG
);
3064 check_breakpoint(env
, &dc
);
3067 j
= tcg_op_buf_count();
3071 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3074 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
3075 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
3076 tcg_ctx
.gen_opc_icount
[lj
] = insn_count
;
3079 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
3080 tcg_gen_debug_insn_start(dc
.pc
);
3085 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3090 TCGLabel
*label
= gen_new_label();
3092 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
3093 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
3094 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
3096 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
3098 gen_set_label(label
);
3102 gen_ibreak_check(env
, &dc
);
3105 disas_xtensa_insn(env
, &dc
);
3108 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
3110 if (cs
->singlestep_enabled
) {
3111 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3112 gen_exception(&dc
, EXCP_DEBUG
);
3115 } while (dc
.is_jmp
== DISAS_NEXT
&&
3116 insn_count
< max_insns
&&
3117 dc
.pc
< next_page_start
&&
3118 dc
.pc
+ xtensa_insn_len(env
, &dc
) <= next_page_start
&&
3119 !tcg_op_buf_full());
3122 reset_sar_tracker(&dc
);
3124 tcg_temp_free(dc
.next_icount
);
3127 if (tb
->cflags
& CF_LAST_IO
) {
3131 if (dc
.is_jmp
== DISAS_NEXT
) {
3132 gen_jumpi(&dc
, dc
.pc
, 0);
3134 gen_tb_end(tb
, insn_count
);
3137 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3138 qemu_log("----------------\n");
3139 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3140 log_target_disas(env
, pc_start
, dc
.pc
- pc_start
, 0);
3145 j
= tcg_op_buf_count();
3146 memset(tcg_ctx
.gen_opc_instr_start
+ lj
+ 1, 0,
3147 (j
- lj
) * sizeof(tcg_ctx
.gen_opc_instr_start
[0]));
3149 tb
->size
= dc
.pc
- pc_start
;
3150 tb
->icount
= insn_count
;
3154 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3156 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, false);
3159 void gen_intermediate_code_pc(CPUXtensaState
*env
, TranslationBlock
*tb
)
3161 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, true);
3164 void xtensa_cpu_dump_state(CPUState
*cs
, FILE *f
,
3165 fprintf_function cpu_fprintf
, int flags
)
3167 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
3168 CPUXtensaState
*env
= &cpu
->env
;
3171 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3173 for (i
= j
= 0; i
< 256; ++i
) {
3174 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3175 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3176 (j
++ % 4) == 3 ? '\n' : ' ');
3180 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3182 for (i
= j
= 0; i
< 256; ++i
) {
3183 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3184 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3185 (j
++ % 4) == 3 ? '\n' : ' ');
3189 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3191 for (i
= 0; i
< 16; ++i
) {
3192 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3193 (i
% 4) == 3 ? '\n' : ' ');
3196 cpu_fprintf(f
, "\n");
3198 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3199 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3200 (i
% 4) == 3 ? '\n' : ' ');
3203 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3204 cpu_fprintf(f
, "\n");
3206 for (i
= 0; i
< 16; ++i
) {
3207 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3208 float32_val(env
->fregs
[i
]),
3209 *(float *)&env
->fregs
[i
], (i
% 2) == 1 ? '\n' : ' ');
3214 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
, int pc_pos
)
3216 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];