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"
44 typedef struct DisasContext
{
45 const XtensaConfig
*config
;
55 int singlestep_enabled
;
59 bool sar_m32_allocated
;
62 uint32_t ccount_delta
;
72 static TCGv_ptr cpu_env
;
73 static TCGv_i32 cpu_pc
;
74 static TCGv_i32 cpu_R
[16];
75 static TCGv_i32 cpu_FR
[16];
76 static TCGv_i32 cpu_SR
[256];
77 static TCGv_i32 cpu_UR
[256];
79 #include "exec/gen-icount.h"
81 typedef struct XtensaReg
{
93 #define XTENSA_REG_ACCESS(regname, opt, acc) { \
95 .opt_bits = XTENSA_OPTION_BIT(opt), \
99 #define XTENSA_REG(regname, opt) XTENSA_REG_ACCESS(regname, opt, SR_RWX)
101 #define XTENSA_REG_BITS(regname, opt) { \
107 static const XtensaReg sregnames
[256] = {
108 [LBEG
] = XTENSA_REG("LBEG", XTENSA_OPTION_LOOP
),
109 [LEND
] = XTENSA_REG("LEND", XTENSA_OPTION_LOOP
),
110 [LCOUNT
] = XTENSA_REG("LCOUNT", XTENSA_OPTION_LOOP
),
111 [SAR
] = XTENSA_REG_BITS("SAR", XTENSA_OPTION_ALL
),
112 [BR
] = XTENSA_REG("BR", XTENSA_OPTION_BOOLEAN
),
113 [LITBASE
] = XTENSA_REG("LITBASE", XTENSA_OPTION_EXTENDED_L32R
),
114 [SCOMPARE1
] = XTENSA_REG("SCOMPARE1", XTENSA_OPTION_CONDITIONAL_STORE
),
115 [ACCLO
] = XTENSA_REG("ACCLO", XTENSA_OPTION_MAC16
),
116 [ACCHI
] = XTENSA_REG("ACCHI", XTENSA_OPTION_MAC16
),
117 [MR
] = XTENSA_REG("MR0", XTENSA_OPTION_MAC16
),
118 [MR
+ 1] = XTENSA_REG("MR1", XTENSA_OPTION_MAC16
),
119 [MR
+ 2] = XTENSA_REG("MR2", XTENSA_OPTION_MAC16
),
120 [MR
+ 3] = XTENSA_REG("MR3", XTENSA_OPTION_MAC16
),
121 [WINDOW_BASE
] = XTENSA_REG("WINDOW_BASE", XTENSA_OPTION_WINDOWED_REGISTER
),
122 [WINDOW_START
] = XTENSA_REG("WINDOW_START",
123 XTENSA_OPTION_WINDOWED_REGISTER
),
124 [PTEVADDR
] = XTENSA_REG("PTEVADDR", XTENSA_OPTION_MMU
),
125 [RASID
] = XTENSA_REG("RASID", XTENSA_OPTION_MMU
),
126 [ITLBCFG
] = XTENSA_REG("ITLBCFG", XTENSA_OPTION_MMU
),
127 [DTLBCFG
] = XTENSA_REG("DTLBCFG", XTENSA_OPTION_MMU
),
128 [IBREAKENABLE
] = XTENSA_REG("IBREAKENABLE", XTENSA_OPTION_DEBUG
),
129 [CACHEATTR
] = XTENSA_REG("CACHEATTR", XTENSA_OPTION_CACHEATTR
),
130 [ATOMCTL
] = XTENSA_REG("ATOMCTL", XTENSA_OPTION_ATOMCTL
),
131 [IBREAKA
] = XTENSA_REG("IBREAKA0", XTENSA_OPTION_DEBUG
),
132 [IBREAKA
+ 1] = XTENSA_REG("IBREAKA1", XTENSA_OPTION_DEBUG
),
133 [DBREAKA
] = XTENSA_REG("DBREAKA0", XTENSA_OPTION_DEBUG
),
134 [DBREAKA
+ 1] = XTENSA_REG("DBREAKA1", XTENSA_OPTION_DEBUG
),
135 [DBREAKC
] = XTENSA_REG("DBREAKC0", XTENSA_OPTION_DEBUG
),
136 [DBREAKC
+ 1] = XTENSA_REG("DBREAKC1", XTENSA_OPTION_DEBUG
),
137 [EPC1
] = XTENSA_REG("EPC1", XTENSA_OPTION_EXCEPTION
),
138 [EPC1
+ 1] = XTENSA_REG("EPC2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
139 [EPC1
+ 2] = XTENSA_REG("EPC3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
140 [EPC1
+ 3] = XTENSA_REG("EPC4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
141 [EPC1
+ 4] = XTENSA_REG("EPC5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
142 [EPC1
+ 5] = XTENSA_REG("EPC6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
143 [EPC1
+ 6] = XTENSA_REG("EPC7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
144 [DEPC
] = XTENSA_REG("DEPC", XTENSA_OPTION_EXCEPTION
),
145 [EPS2
] = XTENSA_REG("EPS2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
146 [EPS2
+ 1] = XTENSA_REG("EPS3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
147 [EPS2
+ 2] = XTENSA_REG("EPS4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
148 [EPS2
+ 3] = XTENSA_REG("EPS5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
149 [EPS2
+ 4] = XTENSA_REG("EPS6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
150 [EPS2
+ 5] = XTENSA_REG("EPS7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
151 [EXCSAVE1
] = XTENSA_REG("EXCSAVE1", XTENSA_OPTION_EXCEPTION
),
152 [EXCSAVE1
+ 1] = XTENSA_REG("EXCSAVE2",
153 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
154 [EXCSAVE1
+ 2] = XTENSA_REG("EXCSAVE3",
155 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
156 [EXCSAVE1
+ 3] = XTENSA_REG("EXCSAVE4",
157 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
158 [EXCSAVE1
+ 4] = XTENSA_REG("EXCSAVE5",
159 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
160 [EXCSAVE1
+ 5] = XTENSA_REG("EXCSAVE6",
161 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
162 [EXCSAVE1
+ 6] = XTENSA_REG("EXCSAVE7",
163 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
164 [CPENABLE
] = XTENSA_REG("CPENABLE", XTENSA_OPTION_COPROCESSOR
),
165 [INTSET
] = XTENSA_REG_ACCESS("INTSET", XTENSA_OPTION_INTERRUPT
, SR_RW
),
166 [INTCLEAR
] = XTENSA_REG_ACCESS("INTCLEAR", XTENSA_OPTION_INTERRUPT
, SR_W
),
167 [INTENABLE
] = XTENSA_REG("INTENABLE", XTENSA_OPTION_INTERRUPT
),
168 [PS
] = XTENSA_REG_BITS("PS", XTENSA_OPTION_ALL
),
169 [VECBASE
] = XTENSA_REG("VECBASE", XTENSA_OPTION_RELOCATABLE_VECTOR
),
170 [EXCCAUSE
] = XTENSA_REG("EXCCAUSE", XTENSA_OPTION_EXCEPTION
),
171 [DEBUGCAUSE
] = XTENSA_REG_ACCESS("DEBUGCAUSE", XTENSA_OPTION_DEBUG
, SR_R
),
172 [CCOUNT
] = XTENSA_REG("CCOUNT", XTENSA_OPTION_TIMER_INTERRUPT
),
173 [PRID
] = XTENSA_REG_ACCESS("PRID", XTENSA_OPTION_PROCESSOR_ID
, SR_R
),
174 [ICOUNT
] = XTENSA_REG("ICOUNT", XTENSA_OPTION_DEBUG
),
175 [ICOUNTLEVEL
] = XTENSA_REG("ICOUNTLEVEL", XTENSA_OPTION_DEBUG
),
176 [EXCVADDR
] = XTENSA_REG("EXCVADDR", XTENSA_OPTION_EXCEPTION
),
177 [CCOMPARE
] = XTENSA_REG("CCOMPARE0", XTENSA_OPTION_TIMER_INTERRUPT
),
178 [CCOMPARE
+ 1] = XTENSA_REG("CCOMPARE1",
179 XTENSA_OPTION_TIMER_INTERRUPT
),
180 [CCOMPARE
+ 2] = XTENSA_REG("CCOMPARE2",
181 XTENSA_OPTION_TIMER_INTERRUPT
),
182 [MISC
] = XTENSA_REG("MISC0", XTENSA_OPTION_MISC_SR
),
183 [MISC
+ 1] = XTENSA_REG("MISC1", XTENSA_OPTION_MISC_SR
),
184 [MISC
+ 2] = XTENSA_REG("MISC2", XTENSA_OPTION_MISC_SR
),
185 [MISC
+ 3] = XTENSA_REG("MISC3", XTENSA_OPTION_MISC_SR
),
188 static const XtensaReg uregnames
[256] = {
189 [THREADPTR
] = XTENSA_REG("THREADPTR", XTENSA_OPTION_THREAD_POINTER
),
190 [FCR
] = XTENSA_REG("FCR", XTENSA_OPTION_FP_COPROCESSOR
),
191 [FSR
] = XTENSA_REG("FSR", XTENSA_OPTION_FP_COPROCESSOR
),
194 void xtensa_translate_init(void)
196 static const char * const regnames
[] = {
197 "ar0", "ar1", "ar2", "ar3",
198 "ar4", "ar5", "ar6", "ar7",
199 "ar8", "ar9", "ar10", "ar11",
200 "ar12", "ar13", "ar14", "ar15",
202 static const char * const fregnames
[] = {
203 "f0", "f1", "f2", "f3",
204 "f4", "f5", "f6", "f7",
205 "f8", "f9", "f10", "f11",
206 "f12", "f13", "f14", "f15",
210 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
211 cpu_pc
= tcg_global_mem_new_i32(TCG_AREG0
,
212 offsetof(CPUXtensaState
, pc
), "pc");
214 for (i
= 0; i
< 16; i
++) {
215 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
216 offsetof(CPUXtensaState
, regs
[i
]),
220 for (i
= 0; i
< 16; i
++) {
221 cpu_FR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
222 offsetof(CPUXtensaState
, fregs
[i
]),
226 for (i
= 0; i
< 256; ++i
) {
227 if (sregnames
[i
].name
) {
228 cpu_SR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
229 offsetof(CPUXtensaState
, sregs
[i
]),
234 for (i
= 0; i
< 256; ++i
) {
235 if (uregnames
[i
].name
) {
236 cpu_UR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
237 offsetof(CPUXtensaState
, uregs
[i
]),
245 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
247 return xtensa_option_bits_enabled(dc
->config
, opt
);
250 static inline bool option_enabled(DisasContext
*dc
, int opt
)
252 return xtensa_option_enabled(dc
->config
, opt
);
255 static void init_litbase(DisasContext
*dc
)
257 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
258 dc
->litbase
= tcg_temp_local_new_i32();
259 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
263 static void reset_litbase(DisasContext
*dc
)
265 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
266 tcg_temp_free(dc
->litbase
);
270 static void init_sar_tracker(DisasContext
*dc
)
272 dc
->sar_5bit
= false;
273 dc
->sar_m32_5bit
= false;
274 dc
->sar_m32_allocated
= false;
277 static void reset_sar_tracker(DisasContext
*dc
)
279 if (dc
->sar_m32_allocated
) {
280 tcg_temp_free(dc
->sar_m32
);
284 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
286 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
287 if (dc
->sar_m32_5bit
) {
288 tcg_gen_discard_i32(dc
->sar_m32
);
291 dc
->sar_m32_5bit
= false;
294 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
296 TCGv_i32 tmp
= tcg_const_i32(32);
297 if (!dc
->sar_m32_allocated
) {
298 dc
->sar_m32
= tcg_temp_local_new_i32();
299 dc
->sar_m32_allocated
= true;
301 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
302 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
303 dc
->sar_5bit
= false;
304 dc
->sar_m32_5bit
= true;
308 static void gen_advance_ccount_cond(DisasContext
*dc
)
310 if (dc
->ccount_delta
> 0) {
311 TCGv_i32 tmp
= tcg_const_i32(dc
->ccount_delta
);
312 gen_helper_advance_ccount(cpu_env
, tmp
);
317 static void gen_advance_ccount(DisasContext
*dc
)
319 gen_advance_ccount_cond(dc
);
320 dc
->ccount_delta
= 0;
323 static void reset_used_window(DisasContext
*dc
)
328 static void gen_exception(DisasContext
*dc
, int excp
)
330 TCGv_i32 tmp
= tcg_const_i32(excp
);
331 gen_advance_ccount(dc
);
332 gen_helper_exception(cpu_env
, tmp
);
336 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
338 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
339 TCGv_i32 tcause
= tcg_const_i32(cause
);
340 gen_advance_ccount(dc
);
341 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
343 tcg_temp_free(tcause
);
344 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
345 cause
== SYSCALL_CAUSE
) {
346 dc
->is_jmp
= DISAS_UPDATE
;
350 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
353 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
354 TCGv_i32 tcause
= tcg_const_i32(cause
);
355 gen_advance_ccount(dc
);
356 gen_helper_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
358 tcg_temp_free(tcause
);
361 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
363 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
364 TCGv_i32 tcause
= tcg_const_i32(cause
);
365 gen_advance_ccount(dc
);
366 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
368 tcg_temp_free(tcause
);
369 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
370 dc
->is_jmp
= DISAS_UPDATE
;
374 static void gen_check_privilege(DisasContext
*dc
)
377 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
378 dc
->is_jmp
= DISAS_UPDATE
;
382 static void gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
384 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
385 !(dc
->cpenable
& (1 << cp
))) {
386 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
387 dc
->is_jmp
= DISAS_UPDATE
;
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((tcg_target_long
)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
->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
->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 int 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 int 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 reset_used_window(dc
);
597 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
599 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
600 reset_used_window(dc
);
603 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
605 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
608 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
610 gen_helper_wsr_rasid(cpu_env
, v
);
611 /* This can change tb->flags, so exit tb */
612 gen_jumpi_check_loop_end(dc
, -1);
615 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
617 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
620 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
622 gen_helper_wsr_ibreakenable(cpu_env
, v
);
623 gen_jumpi_check_loop_end(dc
, 0);
626 static void gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
628 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
631 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
633 unsigned id
= sr
- IBREAKA
;
635 if (id
< dc
->config
->nibreak
) {
636 TCGv_i32 tmp
= tcg_const_i32(id
);
637 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
639 gen_jumpi_check_loop_end(dc
, 0);
643 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
645 unsigned id
= sr
- DBREAKA
;
647 if (id
< dc
->config
->ndbreak
) {
648 TCGv_i32 tmp
= tcg_const_i32(id
);
649 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
654 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
656 unsigned id
= sr
- DBREAKC
;
658 if (id
< dc
->config
->ndbreak
) {
659 TCGv_i32 tmp
= tcg_const_i32(id
);
660 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
665 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
667 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
668 /* This can change tb->flags, so exit tb */
669 gen_jumpi_check_loop_end(dc
, -1);
672 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
674 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
675 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
676 gen_helper_check_interrupts(cpu_env
);
677 gen_jumpi_check_loop_end(dc
, 0);
680 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
682 TCGv_i32 tmp
= tcg_temp_new_i32();
684 tcg_gen_andi_i32(tmp
, v
,
685 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
686 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
687 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
688 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
690 gen_helper_check_interrupts(cpu_env
);
693 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
695 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
696 gen_helper_check_interrupts(cpu_env
);
697 gen_jumpi_check_loop_end(dc
, 0);
700 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
702 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
703 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
705 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
708 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
709 reset_used_window(dc
);
710 gen_helper_check_interrupts(cpu_env
);
711 /* This can change mmu index and tb->flags, so exit tb */
712 gen_jumpi_check_loop_end(dc
, -1);
715 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
718 tcg_gen_mov_i32(dc
->next_icount
, v
);
720 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
724 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
726 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
727 /* This can change tb->flags, so exit tb */
728 gen_jumpi_check_loop_end(dc
, -1);
731 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
733 uint32_t id
= sr
- CCOMPARE
;
734 if (id
< dc
->config
->nccompare
) {
735 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
736 gen_advance_ccount(dc
);
737 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
738 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
739 gen_helper_check_interrupts(cpu_env
);
743 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
745 static void (* const wsr_handler
[256])(DisasContext
*dc
,
746 uint32_t sr
, TCGv_i32 v
) = {
747 [LBEG
] = gen_wsr_lbeg
,
748 [LEND
] = gen_wsr_lend
,
751 [LITBASE
] = gen_wsr_litbase
,
752 [ACCHI
] = gen_wsr_acchi
,
753 [WINDOW_BASE
] = gen_wsr_windowbase
,
754 [WINDOW_START
] = gen_wsr_windowstart
,
755 [PTEVADDR
] = gen_wsr_ptevaddr
,
756 [RASID
] = gen_wsr_rasid
,
757 [ITLBCFG
] = gen_wsr_tlbcfg
,
758 [DTLBCFG
] = gen_wsr_tlbcfg
,
759 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
760 [ATOMCTL
] = gen_wsr_atomctl
,
761 [IBREAKA
] = gen_wsr_ibreaka
,
762 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
763 [DBREAKA
] = gen_wsr_dbreaka
,
764 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
765 [DBREAKC
] = gen_wsr_dbreakc
,
766 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
767 [CPENABLE
] = gen_wsr_cpenable
,
768 [INTSET
] = gen_wsr_intset
,
769 [INTCLEAR
] = gen_wsr_intclear
,
770 [INTENABLE
] = gen_wsr_intenable
,
772 [ICOUNT
] = gen_wsr_icount
,
773 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
774 [CCOMPARE
] = gen_wsr_ccompare
,
775 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
776 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
779 if (wsr_handler
[sr
]) {
780 wsr_handler
[sr
](dc
, sr
, s
);
782 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
786 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
790 gen_helper_wur_fcr(cpu_env
, s
);
794 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
798 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
803 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
804 TCGv_i32 addr
, bool no_hw_alignment
)
806 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
807 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
808 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
810 int label
= gen_new_label();
811 TCGv_i32 tmp
= tcg_temp_new_i32();
812 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
813 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
814 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
815 gen_set_label(label
);
820 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
822 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
823 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
824 gen_advance_ccount(dc
);
825 gen_helper_waiti(cpu_env
, pc
, intlevel
);
827 tcg_temp_free(intlevel
);
830 static void gen_window_check1(DisasContext
*dc
, unsigned r1
)
832 if (dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) {
835 if (option_enabled(dc
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
836 r1
/ 4 > dc
->used_window
) {
837 int label
= gen_new_label();
838 TCGv_i32 ws
= tcg_temp_new_i32();
840 dc
->used_window
= r1
/ 4;
841 tcg_gen_deposit_i32(ws
, cpu_SR
[WINDOW_START
], cpu_SR
[WINDOW_START
],
842 dc
->config
->nareg
/ 4, dc
->config
->nareg
/ 4);
843 tcg_gen_shr_i32(ws
, ws
, cpu_SR
[WINDOW_BASE
]);
844 tcg_gen_andi_i32(ws
, ws
, (2 << (r1
/ 4)) - 2);
845 tcg_gen_brcondi_i32(TCG_COND_EQ
, ws
, 0, label
);
847 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
848 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
850 gen_advance_ccount_cond(dc
);
851 gen_helper_window_check(cpu_env
, pc
, w
);
856 gen_set_label(label
);
861 static void gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
863 gen_window_check1(dc
, r1
> r2
? r1
: r2
);
866 static void gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
869 gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
872 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
874 TCGv_i32 m
= tcg_temp_new_i32();
877 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
879 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
884 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
886 #define HAS_OPTION_BITS(opt) do { \
887 if (!option_bits_enabled(dc, opt)) { \
888 qemu_log("Option is not enabled %s:%d\n", \
889 __FILE__, __LINE__); \
890 goto invalid_opcode; \
894 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
896 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
897 #define RESERVED() do { \
898 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
899 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
900 goto invalid_opcode; \
904 #ifdef TARGET_WORDS_BIGENDIAN
905 #define OP0 (((b0) & 0xf0) >> 4)
906 #define OP1 (((b2) & 0xf0) >> 4)
907 #define OP2 ((b2) & 0xf)
908 #define RRR_R ((b1) & 0xf)
909 #define RRR_S (((b1) & 0xf0) >> 4)
910 #define RRR_T ((b0) & 0xf)
912 #define OP0 (((b0) & 0xf))
913 #define OP1 (((b2) & 0xf))
914 #define OP2 (((b2) & 0xf0) >> 4)
915 #define RRR_R (((b1) & 0xf0) >> 4)
916 #define RRR_S (((b1) & 0xf))
917 #define RRR_T (((b0) & 0xf0) >> 4)
919 #define RRR_X ((RRR_R & 0x4) >> 2)
920 #define RRR_Y ((RRR_T & 0x4) >> 2)
921 #define RRR_W (RRR_R & 0x3)
930 #define RRI8_IMM8 (b2)
931 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
933 #ifdef TARGET_WORDS_BIGENDIAN
934 #define RI16_IMM16 (((b1) << 8) | (b2))
936 #define RI16_IMM16 (((b2) << 8) | (b1))
939 #ifdef TARGET_WORDS_BIGENDIAN
940 #define CALL_N (((b0) & 0xc) >> 2)
941 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
943 #define CALL_N (((b0) & 0x30) >> 4)
944 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
946 #define CALL_OFFSET_SE \
947 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
949 #define CALLX_N CALL_N
950 #ifdef TARGET_WORDS_BIGENDIAN
951 #define CALLX_M ((b0) & 0x3)
953 #define CALLX_M (((b0) & 0xc0) >> 6)
955 #define CALLX_S RRR_S
957 #define BRI12_M CALLX_M
958 #define BRI12_S RRR_S
959 #ifdef TARGET_WORDS_BIGENDIAN
960 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
962 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
964 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
966 #define BRI8_M BRI12_M
967 #define BRI8_R RRI8_R
968 #define BRI8_S RRI8_S
969 #define BRI8_IMM8 RRI8_IMM8
970 #define BRI8_IMM8_SE RRI8_IMM8_SE
974 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
975 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
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
987 dc
->next_pc
= dc
->pc
+ 2;
988 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
990 dc
->next_pc
= dc
->pc
+ 3;
991 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
1000 if ((RRR_R
& 0xc) == 0x8) {
1001 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1008 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1011 case 1: /*reserved*/
1019 gen_window_check1(dc
, CALLX_S
);
1020 gen_jump(dc
, cpu_R
[CALLX_S
]);
1024 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1026 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1027 gen_advance_ccount(dc
);
1028 gen_helper_retw(tmp
, cpu_env
, tmp
);
1034 case 3: /*reserved*/
1041 gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2);
1045 TCGv_i32 tmp
= tcg_temp_new_i32();
1046 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1047 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1055 case 3: /*CALLX12w*/
1056 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1058 TCGv_i32 tmp
= tcg_temp_new_i32();
1060 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1061 gen_callw(dc
, CALLX_N
, tmp
);
1071 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1072 gen_window_check2(dc
, RRR_T
, RRR_S
);
1074 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1075 gen_advance_ccount(dc
);
1076 gen_helper_movsp(cpu_env
, pc
);
1077 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1097 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1109 default: /*reserved*/
1118 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1121 gen_check_privilege(dc
);
1122 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1123 gen_helper_check_interrupts(cpu_env
);
1124 gen_jump(dc
, cpu_SR
[EPC1
]);
1132 gen_check_privilege(dc
);
1133 gen_jump(dc
, cpu_SR
[
1134 dc
->config
->ndepc
? DEPC
: EPC1
]);
1139 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1140 gen_check_privilege(dc
);
1142 TCGv_i32 tmp
= tcg_const_i32(1);
1145 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1146 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1149 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1150 cpu_SR
[WINDOW_START
], tmp
);
1152 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1153 cpu_SR
[WINDOW_START
], tmp
);
1156 gen_helper_restore_owb(cpu_env
);
1157 gen_helper_check_interrupts(cpu_env
);
1158 gen_jump(dc
, cpu_SR
[EPC1
]);
1164 default: /*reserved*/
1171 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1172 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1173 gen_check_privilege(dc
);
1174 tcg_gen_mov_i32(cpu_SR
[PS
],
1175 cpu_SR
[EPS2
+ RRR_S
- 2]);
1176 gen_helper_check_interrupts(cpu_env
);
1177 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1179 qemu_log("RFI %d is illegal\n", RRR_S
);
1180 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1188 default: /*reserved*/
1196 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1198 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1202 case 5: /*SYSCALLx*/
1203 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1205 case 0: /*SYSCALLx*/
1206 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1210 if (semihosting_enabled
) {
1211 gen_check_privilege(dc
);
1212 gen_helper_simcall(cpu_env
);
1214 qemu_log("SIMCALL but semihosting is disabled\n");
1215 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1226 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1227 gen_check_privilege(dc
);
1228 gen_window_check1(dc
, RRR_T
);
1229 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1230 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1231 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1232 gen_helper_check_interrupts(cpu_env
);
1233 gen_jumpi_check_loop_end(dc
, 0);
1237 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1238 gen_check_privilege(dc
);
1239 gen_waiti(dc
, RRR_S
);
1246 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1248 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1249 TCGv_i32 mask
= tcg_const_i32(
1250 ((1 << shift
) - 1) << RRR_S
);
1251 TCGv_i32 tmp
= tcg_temp_new_i32();
1253 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1254 if (RRR_R
& 1) { /*ALL*/
1255 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1257 tcg_gen_add_i32(tmp
, tmp
, mask
);
1259 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1260 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1262 tcg_temp_free(mask
);
1267 default: /*reserved*/
1275 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1276 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1280 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1281 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1285 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1286 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1292 gen_window_check1(dc
, RRR_S
);
1293 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1297 gen_window_check1(dc
, RRR_S
);
1298 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1302 gen_window_check1(dc
, RRR_S
);
1304 TCGv_i32 tmp
= tcg_temp_new_i32();
1305 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1306 gen_right_shift_sar(dc
, tmp
);
1312 gen_window_check1(dc
, RRR_S
);
1314 TCGv_i32 tmp
= tcg_temp_new_i32();
1315 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1316 gen_left_shift_sar(dc
, tmp
);
1323 TCGv_i32 tmp
= tcg_const_i32(
1324 RRR_S
| ((RRR_T
& 1) << 4));
1325 gen_right_shift_sar(dc
, tmp
);
1339 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1340 gen_check_privilege(dc
);
1342 TCGv_i32 tmp
= tcg_const_i32(
1343 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1344 gen_helper_rotw(cpu_env
, tmp
);
1346 reset_used_window(dc
);
1351 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1352 gen_window_check2(dc
, RRR_S
, RRR_T
);
1353 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1357 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1358 gen_window_check2(dc
, RRR_S
, RRR_T
);
1359 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1362 default: /*reserved*/
1370 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1371 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1372 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1373 gen_check_privilege(dc
);
1374 gen_window_check2(dc
, RRR_S
, RRR_T
);
1376 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1378 switch (RRR_R
& 7) {
1379 case 3: /*RITLB0*/ /*RDTLB0*/
1380 gen_helper_rtlb0(cpu_R
[RRR_T
],
1381 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1384 case 4: /*IITLB*/ /*IDTLB*/
1385 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1386 /* This could change memory mapping, so exit tb */
1387 gen_jumpi_check_loop_end(dc
, -1);
1390 case 5: /*PITLB*/ /*PDTLB*/
1391 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1392 gen_helper_ptlb(cpu_R
[RRR_T
],
1393 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1396 case 6: /*WITLB*/ /*WDTLB*/
1398 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1399 /* This could change memory mapping, so exit tb */
1400 gen_jumpi_check_loop_end(dc
, -1);
1403 case 7: /*RITLB1*/ /*RDTLB1*/
1404 gen_helper_rtlb1(cpu_R
[RRR_T
],
1405 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1409 tcg_temp_free(dtlb
);
1413 tcg_temp_free(dtlb
);
1418 gen_window_check2(dc
, RRR_R
, RRR_T
);
1421 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1426 TCGv_i32 zero
= tcg_const_i32(0);
1427 TCGv_i32 neg
= tcg_temp_new_i32();
1429 tcg_gen_neg_i32(neg
, cpu_R
[RRR_T
]);
1430 tcg_gen_movcond_i32(TCG_COND_GE
, cpu_R
[RRR_R
],
1431 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_T
], neg
);
1433 tcg_temp_free(zero
);
1437 default: /*reserved*/
1443 case 7: /*reserved*/
1448 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1449 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1455 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1457 TCGv_i32 tmp
= tcg_temp_new_i32();
1458 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1459 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1465 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1466 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1472 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1474 TCGv_i32 tmp
= tcg_temp_new_i32();
1475 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1476 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1487 gen_window_check2(dc
, RRR_R
, RRR_S
);
1488 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1489 32 - (RRR_T
| ((OP2
& 1) << 4)));
1494 gen_window_check2(dc
, RRR_R
, RRR_T
);
1495 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1496 RRR_S
| ((OP2
& 1) << 4));
1500 gen_window_check2(dc
, RRR_R
, RRR_T
);
1501 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1505 if (gen_check_sr(dc
, RSR_SR
, SR_X
)) {
1506 TCGv_i32 tmp
= tcg_temp_new_i32();
1509 gen_check_privilege(dc
);
1511 gen_window_check1(dc
, RRR_T
);
1512 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1513 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1514 gen_wsr(dc
, RSR_SR
, tmp
);
1520 * Note: 64 bit ops are used here solely because SAR values
1523 #define gen_shift_reg(cmd, reg) do { \
1524 TCGv_i64 tmp = tcg_temp_new_i64(); \
1525 tcg_gen_extu_i32_i64(tmp, reg); \
1526 tcg_gen_##cmd##_i64(v, v, tmp); \
1527 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \
1528 tcg_temp_free_i64(v); \
1529 tcg_temp_free_i64(tmp); \
1532 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1535 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1537 TCGv_i64 v
= tcg_temp_new_i64();
1538 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1544 gen_window_check2(dc
, RRR_R
, RRR_T
);
1546 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1548 TCGv_i64 v
= tcg_temp_new_i64();
1549 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1555 gen_window_check2(dc
, RRR_R
, RRR_S
);
1556 if (dc
->sar_m32_5bit
) {
1557 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1559 TCGv_i64 v
= tcg_temp_new_i64();
1560 TCGv_i32 s
= tcg_const_i32(32);
1561 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1562 tcg_gen_andi_i32(s
, s
, 0x3f);
1563 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1564 gen_shift_reg(shl
, s
);
1570 gen_window_check2(dc
, RRR_R
, RRR_T
);
1572 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1574 TCGv_i64 v
= tcg_temp_new_i64();
1575 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1580 #undef gen_shift_reg
1583 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1584 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1586 TCGv_i32 v1
= tcg_temp_new_i32();
1587 TCGv_i32 v2
= tcg_temp_new_i32();
1588 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1589 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1590 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1597 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1598 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1600 TCGv_i32 v1
= tcg_temp_new_i32();
1601 TCGv_i32 v2
= tcg_temp_new_i32();
1602 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1603 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1604 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1610 default: /*reserved*/
1618 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1622 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1623 int label
= gen_new_label();
1624 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1625 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1626 gen_set_label(label
);
1630 #define BOOLEAN_LOGIC(fn, r, s, t) \
1632 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1633 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1634 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1636 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1637 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1638 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1639 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1640 tcg_temp_free(tmp1); \
1641 tcg_temp_free(tmp2); \
1645 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1649 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1653 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1657 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1661 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1664 #undef BOOLEAN_LOGIC
1667 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1668 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1673 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1675 TCGv lo
= tcg_temp_new();
1678 tcg_gen_mulu2_i32(lo
, cpu_R
[RRR_R
],
1679 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1681 tcg_gen_muls2_i32(lo
, cpu_R
[RRR_R
],
1682 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1689 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1695 int label1
= gen_new_label();
1696 int label2
= gen_new_label();
1698 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1700 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1702 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1703 OP2
== 13 ? 0x80000000 : 0);
1705 gen_set_label(label1
);
1707 tcg_gen_div_i32(cpu_R
[RRR_R
],
1708 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1710 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1711 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1713 gen_set_label(label2
);
1718 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1721 default: /*reserved*/
1730 if (gen_check_sr(dc
, RSR_SR
, SR_R
)) {
1732 gen_check_privilege(dc
);
1734 gen_window_check1(dc
, RRR_T
);
1735 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1740 if (gen_check_sr(dc
, RSR_SR
, SR_W
)) {
1742 gen_check_privilege(dc
);
1744 gen_window_check1(dc
, RRR_T
);
1745 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1750 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1751 gen_window_check2(dc
, RRR_R
, RRR_S
);
1753 int shift
= 24 - RRR_T
;
1756 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1757 } else if (shift
== 16) {
1758 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1760 TCGv_i32 tmp
= tcg_temp_new_i32();
1761 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1762 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1769 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1770 gen_window_check2(dc
, RRR_R
, RRR_S
);
1772 TCGv_i32 tmp1
= tcg_temp_new_i32();
1773 TCGv_i32 tmp2
= tcg_temp_new_i32();
1774 TCGv_i32 zero
= tcg_const_i32(0);
1776 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1777 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1778 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1780 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1781 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1783 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1784 cpu_R
[RRR_S
], tmp1
);
1785 tcg_temp_free(tmp1
);
1786 tcg_temp_free(tmp2
);
1787 tcg_temp_free(zero
);
1795 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1796 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1798 static const TCGCond cond
[] = {
1804 tcg_gen_movcond_i32(cond
[OP2
- 4], cpu_R
[RRR_R
],
1805 cpu_R
[RRR_S
], cpu_R
[RRR_T
],
1806 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1814 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1816 static const TCGCond cond
[] = {
1822 TCGv_i32 zero
= tcg_const_i32(0);
1824 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1825 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1826 tcg_temp_free(zero
);
1832 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1833 gen_window_check2(dc
, RRR_R
, RRR_S
);
1835 TCGv_i32 zero
= tcg_const_i32(0);
1836 TCGv_i32 tmp
= tcg_temp_new_i32();
1838 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1839 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1840 cpu_R
[RRR_R
], tmp
, zero
,
1841 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1844 tcg_temp_free(zero
);
1849 gen_window_check1(dc
, RRR_R
);
1851 int st
= (RRR_S
<< 4) + RRR_T
;
1852 if (uregnames
[st
].name
) {
1853 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1855 qemu_log("RUR %d not implemented, ", st
);
1862 gen_window_check1(dc
, RRR_T
);
1863 if (uregnames
[RSR_SR
].name
) {
1864 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1866 qemu_log("WUR %d not implemented, ", RSR_SR
);
1876 gen_window_check2(dc
, RRR_R
, RRR_T
);
1878 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1879 int maskimm
= (1 << (OP2
+ 1)) - 1;
1881 TCGv_i32 tmp
= tcg_temp_new_i32();
1882 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1883 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1902 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1903 gen_window_check2(dc
, RRR_S
, RRR_T
);
1904 gen_check_cpenable(dc
, 0);
1906 TCGv_i32 addr
= tcg_temp_new_i32();
1907 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1908 gen_load_store_alignment(dc
, 2, addr
, false);
1910 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1912 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1915 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1917 tcg_temp_free(addr
);
1921 default: /*reserved*/
1928 gen_window_check2(dc
, RRR_S
, RRR_T
);
1931 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1932 gen_check_privilege(dc
);
1934 TCGv_i32 addr
= tcg_temp_new_i32();
1935 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1936 (0xffffffc0 | (RRR_R
<< 2)));
1937 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1938 tcg_temp_free(addr
);
1943 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1944 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_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1950 tcg_temp_free(addr
);
1961 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1964 gen_check_cpenable(dc
, 0);
1965 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
1966 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1970 gen_check_cpenable(dc
, 0);
1971 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
1972 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1976 gen_check_cpenable(dc
, 0);
1977 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
1978 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1982 gen_check_cpenable(dc
, 0);
1983 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
1984 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1988 gen_check_cpenable(dc
, 0);
1989 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
1990 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1993 case 8: /*ROUND.Sf*/
1994 case 9: /*TRUNC.Sf*/
1995 case 10: /*FLOOR.Sf*/
1996 case 11: /*CEIL.Sf*/
1997 case 14: /*UTRUNC.Sf*/
1998 gen_window_check1(dc
, RRR_R
);
1999 gen_check_cpenable(dc
, 0);
2001 static const unsigned rounding_mode_const
[] = {
2002 float_round_nearest_even
,
2003 float_round_to_zero
,
2006 [6] = float_round_to_zero
,
2008 TCGv_i32 rounding_mode
= tcg_const_i32(
2009 rounding_mode_const
[OP2
& 7]);
2010 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2013 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2014 rounding_mode
, scale
);
2016 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2017 rounding_mode
, scale
);
2020 tcg_temp_free(rounding_mode
);
2021 tcg_temp_free(scale
);
2025 case 12: /*FLOAT.Sf*/
2026 case 13: /*UFLOAT.Sf*/
2027 gen_window_check1(dc
, RRR_S
);
2028 gen_check_cpenable(dc
, 0);
2030 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2033 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2034 cpu_R
[RRR_S
], scale
);
2036 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2037 cpu_R
[RRR_S
], scale
);
2039 tcg_temp_free(scale
);
2046 gen_check_cpenable(dc
, 0);
2047 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2051 gen_check_cpenable(dc
, 0);
2052 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2056 gen_window_check1(dc
, RRR_R
);
2057 gen_check_cpenable(dc
, 0);
2058 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2062 gen_window_check1(dc
, RRR_S
);
2063 gen_check_cpenable(dc
, 0);
2064 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2068 gen_check_cpenable(dc
, 0);
2069 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2072 default: /*reserved*/
2078 default: /*reserved*/
2085 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2087 #define gen_compare(rel, br, a, b) \
2089 TCGv_i32 bit = tcg_const_i32(1 << br); \
2091 gen_check_cpenable(dc, 0); \
2092 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2093 tcg_temp_free(bit); \
2098 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2102 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2106 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2110 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2114 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2118 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2122 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2127 case 8: /*MOVEQZ.Sf*/
2128 case 9: /*MOVNEZ.Sf*/
2129 case 10: /*MOVLTZ.Sf*/
2130 case 11: /*MOVGEZ.Sf*/
2131 gen_window_check1(dc
, RRR_T
);
2132 gen_check_cpenable(dc
, 0);
2134 static const TCGCond cond
[] = {
2140 TCGv_i32 zero
= tcg_const_i32(0);
2142 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2143 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2144 tcg_temp_free(zero
);
2148 case 12: /*MOVF.Sf*/
2149 case 13: /*MOVT.Sf*/
2150 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2151 gen_check_cpenable(dc
, 0);
2153 TCGv_i32 zero
= tcg_const_i32(0);
2154 TCGv_i32 tmp
= tcg_temp_new_i32();
2156 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2157 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2158 cpu_FR
[RRR_R
], tmp
, zero
,
2159 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2162 tcg_temp_free(zero
);
2166 default: /*reserved*/
2172 default: /*reserved*/
2179 gen_window_check1(dc
, RRR_T
);
2181 TCGv_i32 tmp
= tcg_const_i32(
2182 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2183 0 : ((dc
->pc
+ 3) & ~3)) +
2184 (0xfffc0000 | (RI16_IMM16
<< 2)));
2186 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2187 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2189 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2195 #define gen_load_store(type, shift) do { \
2196 TCGv_i32 addr = tcg_temp_new_i32(); \
2197 gen_window_check2(dc, RRI8_S, RRI8_T); \
2198 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2200 gen_load_store_alignment(dc, shift, addr, false); \
2202 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2203 tcg_temp_free(addr); \
2208 gen_load_store(ld8u
, 0);
2212 gen_load_store(ld16u
, 1);
2216 gen_load_store(ld32u
, 2);
2220 gen_load_store(st8
, 0);
2224 gen_load_store(st16
, 1);
2228 gen_load_store(st32
, 2);
2233 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2264 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2268 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2272 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2276 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2280 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2283 default: /*reserved*/
2291 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2297 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2301 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2305 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2308 default: /*reserved*/
2315 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2319 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2322 default: /*reserved*/
2329 gen_load_store(ld16s
, 1);
2331 #undef gen_load_store
2334 gen_window_check1(dc
, RRI8_T
);
2335 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2336 RRI8_IMM8
| (RRI8_S
<< 8) |
2337 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2340 #define gen_load_store_no_hw_align(type) do { \
2341 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2342 gen_window_check2(dc, RRI8_S, RRI8_T); \
2343 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2344 gen_load_store_alignment(dc, 2, addr, true); \
2345 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2346 tcg_temp_free(addr); \
2350 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2351 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2355 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2356 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2360 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2361 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
<< 8);
2364 case 14: /*S32C1Iy*/
2365 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2366 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2368 int label
= gen_new_label();
2369 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2370 TCGv_i32 addr
= tcg_temp_local_new_i32();
2373 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2374 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2375 gen_load_store_alignment(dc
, 2, addr
, true);
2377 gen_advance_ccount(dc
);
2378 tpc
= tcg_const_i32(dc
->pc
);
2379 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2380 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2381 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2382 cpu_SR
[SCOMPARE1
], label
);
2384 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2386 gen_set_label(label
);
2388 tcg_temp_free(addr
);
2394 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2395 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2397 #undef gen_load_store_no_hw_align
2399 default: /*reserved*/
2411 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2412 gen_window_check1(dc
, RRI8_S
);
2413 gen_check_cpenable(dc
, 0);
2415 TCGv_i32 addr
= tcg_temp_new_i32();
2416 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2417 gen_load_store_alignment(dc
, 2, addr
, false);
2419 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2421 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2424 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2426 tcg_temp_free(addr
);
2430 default: /*reserved*/
2437 HAS_OPTION(XTENSA_OPTION_MAC16
);
2446 bool is_m1_sr
= (OP2
& 0x3) == 2;
2447 bool is_m2_sr
= (OP2
& 0xc) == 0;
2448 uint32_t ld_offset
= 0;
2455 case 0: /*MACI?/MACC?*/
2457 ld_offset
= (OP2
& 1) ? -4 : 4;
2459 if (OP2
>= 8) { /*MACI/MACC*/
2460 if (OP1
== 0) { /*LDINC/LDDEC*/
2465 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2470 case 2: /*MACD?/MACA?*/
2471 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2477 if (op
!= MAC16_NONE
) {
2479 gen_window_check1(dc
, RRR_S
);
2482 gen_window_check1(dc
, RRR_T
);
2487 TCGv_i32 vaddr
= tcg_temp_new_i32();
2488 TCGv_i32 mem32
= tcg_temp_new_i32();
2491 gen_window_check1(dc
, RRR_S
);
2492 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2493 gen_load_store_alignment(dc
, 2, vaddr
, false);
2494 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2496 if (op
!= MAC16_NONE
) {
2497 TCGv_i32 m1
= gen_mac16_m(
2498 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2499 OP1
& 1, op
== MAC16_UMUL
);
2500 TCGv_i32 m2
= gen_mac16_m(
2501 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2502 OP1
& 2, op
== MAC16_UMUL
);
2504 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2505 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2506 if (op
== MAC16_UMUL
) {
2507 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2509 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2512 TCGv_i32 lo
= tcg_temp_new_i32();
2513 TCGv_i32 hi
= tcg_temp_new_i32();
2515 tcg_gen_mul_i32(lo
, m1
, m2
);
2516 tcg_gen_sari_i32(hi
, lo
, 31);
2517 if (op
== MAC16_MULA
) {
2518 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2519 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2522 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2523 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2526 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2528 tcg_temp_free_i32(lo
);
2529 tcg_temp_free_i32(hi
);
2535 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2536 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2538 tcg_temp_free(vaddr
);
2539 tcg_temp_free(mem32
);
2547 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2548 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2554 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2555 gen_window_check1(dc
, CALL_N
<< 2);
2556 gen_callwi(dc
, CALL_N
,
2557 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2565 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2569 gen_window_check1(dc
, BRI12_S
);
2571 static const TCGCond cond
[] = {
2572 TCG_COND_EQ
, /*BEQZ*/
2573 TCG_COND_NE
, /*BNEZ*/
2574 TCG_COND_LT
, /*BLTZ*/
2575 TCG_COND_GE
, /*BGEZ*/
2578 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2579 4 + BRI12_IMM12_SE
);
2584 gen_window_check1(dc
, BRI8_S
);
2586 static const TCGCond cond
[] = {
2587 TCG_COND_EQ
, /*BEQI*/
2588 TCG_COND_NE
, /*BNEI*/
2589 TCG_COND_LT
, /*BLTI*/
2590 TCG_COND_GE
, /*BGEI*/
2593 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2594 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2601 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2603 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2604 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2605 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2606 gen_advance_ccount(dc
);
2607 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2611 reset_used_window(dc
);
2619 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2621 TCGv_i32 tmp
= tcg_temp_new_i32();
2622 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2624 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2625 tmp
, 0, 4 + RRI8_IMM8_SE
);
2632 case 10: /*LOOPGTZ*/
2633 HAS_OPTION(XTENSA_OPTION_LOOP
);
2634 gen_window_check1(dc
, RRI8_S
);
2636 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2637 TCGv_i32 tmp
= tcg_const_i32(lend
);
2639 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2640 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2641 gen_helper_wsr_lend(cpu_env
, tmp
);
2645 int label
= gen_new_label();
2646 tcg_gen_brcondi_i32(
2647 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2648 cpu_R
[RRI8_S
], 0, label
);
2649 gen_jumpi(dc
, lend
, 1);
2650 gen_set_label(label
);
2653 gen_jumpi(dc
, dc
->next_pc
, 0);
2657 default: /*reserved*/
2666 gen_window_check1(dc
, BRI8_S
);
2667 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2668 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2678 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2680 switch (RRI8_R
& 7) {
2681 case 0: /*BNONE*/ /*BANY*/
2682 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2684 TCGv_i32 tmp
= tcg_temp_new_i32();
2685 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2686 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2691 case 1: /*BEQ*/ /*BNE*/
2692 case 2: /*BLT*/ /*BGE*/
2693 case 3: /*BLTU*/ /*BGEU*/
2694 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2696 static const TCGCond cond
[] = {
2702 [11] = TCG_COND_GEU
,
2704 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2709 case 4: /*BALL*/ /*BNALL*/
2710 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2712 TCGv_i32 tmp
= tcg_temp_new_i32();
2713 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2714 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2720 case 5: /*BBC*/ /*BBS*/
2721 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2723 #ifdef TARGET_WORDS_BIGENDIAN
2724 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2726 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2728 TCGv_i32 tmp
= tcg_temp_new_i32();
2729 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2730 #ifdef TARGET_WORDS_BIGENDIAN
2731 tcg_gen_shr_i32(bit
, bit
, tmp
);
2733 tcg_gen_shl_i32(bit
, bit
, tmp
);
2735 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2736 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2742 case 6: /*BBCI*/ /*BBSI*/
2744 gen_window_check1(dc
, RRI8_S
);
2746 TCGv_i32 tmp
= tcg_temp_new_i32();
2747 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2748 #ifdef TARGET_WORDS_BIGENDIAN
2749 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2751 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2753 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2762 #define gen_narrow_load_store(type) do { \
2763 TCGv_i32 addr = tcg_temp_new_i32(); \
2764 gen_window_check2(dc, RRRN_S, RRRN_T); \
2765 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2766 gen_load_store_alignment(dc, 2, addr, false); \
2767 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2768 tcg_temp_free(addr); \
2772 gen_narrow_load_store(ld32u
);
2776 gen_narrow_load_store(st32
);
2778 #undef gen_narrow_load_store
2781 gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
);
2782 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2785 case 11: /*ADDI.Nn*/
2786 gen_window_check2(dc
, RRRN_R
, RRRN_S
);
2787 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], RRRN_T
? RRRN_T
: -1);
2791 gen_window_check1(dc
, RRRN_S
);
2792 if (RRRN_T
< 8) { /*MOVI.Nn*/
2793 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2794 RRRN_R
| (RRRN_T
<< 4) |
2795 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2796 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2797 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2799 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2800 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2807 gen_window_check2(dc
, RRRN_S
, RRRN_T
);
2808 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2814 gen_jump(dc
, cpu_R
[0]);
2818 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2820 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2821 gen_advance_ccount(dc
);
2822 gen_helper_retw(tmp
, cpu_env
, tmp
);
2828 case 2: /*BREAK.Nn*/
2829 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2831 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2839 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2842 default: /*reserved*/
2848 default: /*reserved*/
2854 default: /*reserved*/
2859 if (dc
->is_jmp
== DISAS_NEXT
) {
2860 gen_check_loop_end(dc
, 0);
2862 dc
->pc
= dc
->next_pc
;
2867 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2868 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2872 static void check_breakpoint(CPUXtensaState
*env
, DisasContext
*dc
)
2876 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2877 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2878 if (bp
->pc
== dc
->pc
) {
2879 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2880 gen_exception(dc
, EXCP_DEBUG
);
2881 dc
->is_jmp
= DISAS_UPDATE
;
2887 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
2891 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
2892 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
2893 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
2894 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
2901 void gen_intermediate_code_internal(XtensaCPU
*cpu
,
2902 TranslationBlock
*tb
, bool search_pc
)
2904 CPUState
*cs
= CPU(cpu
);
2905 CPUXtensaState
*env
= &cpu
->env
;
2909 uint16_t *gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
2910 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2911 uint32_t pc_start
= tb
->pc
;
2912 uint32_t next_page_start
=
2913 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2915 if (max_insns
== 0) {
2916 max_insns
= CF_COUNT_MASK
;
2919 dc
.config
= env
->config
;
2920 dc
.singlestep_enabled
= cs
->singlestep_enabled
;
2923 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
2924 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
2925 dc
.lbeg
= env
->sregs
[LBEG
];
2926 dc
.lend
= env
->sregs
[LEND
];
2927 dc
.is_jmp
= DISAS_NEXT
;
2928 dc
.ccount_delta
= 0;
2929 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
2930 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
2931 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
2932 XTENSA_TBFLAG_CPENABLE_SHIFT
;
2935 init_sar_tracker(&dc
);
2936 reset_used_window(&dc
);
2938 dc
.next_icount
= tcg_temp_local_new_i32();
2943 if (tb
->flags
& XTENSA_TBFLAG_EXCEPTION
) {
2944 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2945 gen_exception(&dc
, EXCP_DEBUG
);
2949 check_breakpoint(env
, &dc
);
2952 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
2956 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2959 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
2960 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
2961 tcg_ctx
.gen_opc_icount
[lj
] = insn_count
;
2964 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
2965 tcg_gen_debug_insn_start(dc
.pc
);
2970 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
2975 int label
= gen_new_label();
2977 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
2978 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
2979 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
2981 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
2983 gen_set_label(label
);
2987 gen_ibreak_check(env
, &dc
);
2990 disas_xtensa_insn(env
, &dc
);
2993 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
2995 if (cs
->singlestep_enabled
) {
2996 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2997 gen_exception(&dc
, EXCP_DEBUG
);
3000 } while (dc
.is_jmp
== DISAS_NEXT
&&
3001 insn_count
< max_insns
&&
3002 dc
.pc
< next_page_start
&&
3003 tcg_ctx
.gen_opc_ptr
< gen_opc_end
);
3006 reset_sar_tracker(&dc
);
3008 tcg_temp_free(dc
.next_icount
);
3011 if (tb
->cflags
& CF_LAST_IO
) {
3015 if (dc
.is_jmp
== DISAS_NEXT
) {
3016 gen_jumpi(&dc
, dc
.pc
, 0);
3018 gen_tb_end(tb
, insn_count
);
3019 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
3022 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3023 memset(tcg_ctx
.gen_opc_instr_start
+ lj
+ 1, 0,
3024 (j
- lj
) * sizeof(tcg_ctx
.gen_opc_instr_start
[0]));
3026 tb
->size
= dc
.pc
- pc_start
;
3027 tb
->icount
= insn_count
;
3031 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3033 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, false);
3036 void gen_intermediate_code_pc(CPUXtensaState
*env
, TranslationBlock
*tb
)
3038 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, true);
3041 void xtensa_cpu_dump_state(CPUState
*cs
, FILE *f
,
3042 fprintf_function cpu_fprintf
, int flags
)
3044 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
3045 CPUXtensaState
*env
= &cpu
->env
;
3048 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3050 for (i
= j
= 0; i
< 256; ++i
) {
3051 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3052 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3053 (j
++ % 4) == 3 ? '\n' : ' ');
3057 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3059 for (i
= j
= 0; i
< 256; ++i
) {
3060 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3061 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3062 (j
++ % 4) == 3 ? '\n' : ' ');
3066 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3068 for (i
= 0; i
< 16; ++i
) {
3069 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3070 (i
% 4) == 3 ? '\n' : ' ');
3073 cpu_fprintf(f
, "\n");
3075 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3076 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3077 (i
% 4) == 3 ? '\n' : ' ');
3080 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3081 cpu_fprintf(f
, "\n");
3083 for (i
= 0; i
< 16; ++i
) {
3084 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3085 float32_val(env
->fregs
[i
]),
3086 *(float *)&env
->fregs
[i
], (i
% 2) == 1 ? '\n' : ' ');
3091 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
, int pc_pos
)
3093 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];