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_cond(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
);
323 static void gen_advance_ccount(DisasContext
*dc
)
325 gen_advance_ccount_cond(dc
);
326 dc
->ccount_delta
= 0;
329 static void reset_used_window(DisasContext
*dc
)
334 static void gen_exception(DisasContext
*dc
, int excp
)
336 TCGv_i32 tmp
= tcg_const_i32(excp
);
337 gen_advance_ccount(dc
);
338 gen_helper_exception(cpu_env
, tmp
);
342 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
344 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
345 TCGv_i32 tcause
= tcg_const_i32(cause
);
346 gen_advance_ccount(dc
);
347 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
349 tcg_temp_free(tcause
);
350 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
351 cause
== SYSCALL_CAUSE
) {
352 dc
->is_jmp
= DISAS_UPDATE
;
356 static void gen_exception_cause_vaddr(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_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
364 tcg_temp_free(tcause
);
367 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
369 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
370 TCGv_i32 tcause
= tcg_const_i32(cause
);
371 gen_advance_ccount(dc
);
372 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
374 tcg_temp_free(tcause
);
375 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
376 dc
->is_jmp
= DISAS_UPDATE
;
380 static void gen_check_privilege(DisasContext
*dc
)
383 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
384 dc
->is_jmp
= DISAS_UPDATE
;
388 static void gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
390 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
391 !(dc
->cpenable
& (1 << cp
))) {
392 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
393 dc
->is_jmp
= DISAS_UPDATE
;
397 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
399 tcg_gen_mov_i32(cpu_pc
, dest
);
400 gen_advance_ccount(dc
);
402 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
->next_icount
);
404 if (dc
->singlestep_enabled
) {
405 gen_exception(dc
, EXCP_DEBUG
);
408 tcg_gen_goto_tb(slot
);
409 tcg_gen_exit_tb((uintptr_t)dc
->tb
+ slot
);
414 dc
->is_jmp
= DISAS_UPDATE
;
417 static void gen_jump(DisasContext
*dc
, TCGv dest
)
419 gen_jump_slot(dc
, dest
, -1);
422 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
424 TCGv_i32 tmp
= tcg_const_i32(dest
);
425 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
428 gen_jump_slot(dc
, tmp
, slot
);
432 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
435 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
437 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
438 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
439 tcg_temp_free(tcallinc
);
440 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
441 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
442 gen_jump_slot(dc
, dest
, slot
);
445 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
447 gen_callw_slot(dc
, callinc
, dest
, -1);
450 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
452 TCGv_i32 tmp
= tcg_const_i32(dest
);
453 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
456 gen_callw_slot(dc
, callinc
, tmp
, slot
);
460 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
462 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
463 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
464 dc
->next_pc
== dc
->lend
) {
465 int label
= gen_new_label();
467 gen_advance_ccount(dc
);
468 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
469 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
470 gen_jumpi(dc
, dc
->lbeg
, slot
);
471 gen_set_label(label
);
472 gen_jumpi(dc
, dc
->next_pc
, -1);
478 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
480 if (!gen_check_loop_end(dc
, slot
)) {
481 gen_jumpi(dc
, dc
->next_pc
, slot
);
485 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
486 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
488 int label
= gen_new_label();
490 gen_advance_ccount(dc
);
491 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
492 gen_jumpi_check_loop_end(dc
, 0);
493 gen_set_label(label
);
494 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
497 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
498 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
500 TCGv_i32 tmp
= tcg_const_i32(t1
);
501 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
505 static bool gen_check_sr(DisasContext
*dc
, uint32_t sr
, unsigned access
)
507 if (!xtensa_option_bits_enabled(dc
->config
, sregnames
[sr
].opt_bits
)) {
508 if (sregnames
[sr
].name
) {
509 qemu_log("SR %s is not configured\n", sregnames
[sr
].name
);
511 qemu_log("SR %d is not implemented\n", sr
);
513 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
515 } else if (!(sregnames
[sr
].access
& access
)) {
516 static const char * const access_text
[] = {
521 assert(access
< ARRAY_SIZE(access_text
) && access_text
[access
]);
522 qemu_log("SR %s is not available for %s\n", sregnames
[sr
].name
,
523 access_text
[access
]);
524 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
530 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
532 gen_advance_ccount(dc
);
533 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
536 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
538 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
539 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
540 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
543 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
545 static void (* const rsr_handler
[256])(DisasContext
*dc
,
546 TCGv_i32 d
, uint32_t sr
) = {
547 [CCOUNT
] = gen_rsr_ccount
,
548 [PTEVADDR
] = gen_rsr_ptevaddr
,
551 if (rsr_handler
[sr
]) {
552 rsr_handler
[sr
](dc
, d
, sr
);
554 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
558 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
560 gen_helper_wsr_lbeg(cpu_env
, s
);
561 gen_jumpi_check_loop_end(dc
, 0);
564 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
566 gen_helper_wsr_lend(cpu_env
, s
);
567 gen_jumpi_check_loop_end(dc
, 0);
570 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
572 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
573 if (dc
->sar_m32_5bit
) {
574 tcg_gen_discard_i32(dc
->sar_m32
);
576 dc
->sar_5bit
= false;
577 dc
->sar_m32_5bit
= false;
580 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
582 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
585 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
587 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
588 /* This can change tb->flags, so exit tb */
589 gen_jumpi_check_loop_end(dc
, -1);
592 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
594 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
597 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
599 gen_helper_wsr_windowbase(cpu_env
, v
);
600 reset_used_window(dc
);
603 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
605 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
606 reset_used_window(dc
);
609 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
611 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
614 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
616 gen_helper_wsr_rasid(cpu_env
, v
);
617 /* This can change tb->flags, so exit tb */
618 gen_jumpi_check_loop_end(dc
, -1);
621 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
623 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
626 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
628 gen_helper_wsr_ibreakenable(cpu_env
, v
);
629 gen_jumpi_check_loop_end(dc
, 0);
632 static void gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
634 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
637 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
639 unsigned id
= sr
- IBREAKA
;
641 if (id
< dc
->config
->nibreak
) {
642 TCGv_i32 tmp
= tcg_const_i32(id
);
643 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
645 gen_jumpi_check_loop_end(dc
, 0);
649 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
651 unsigned id
= sr
- DBREAKA
;
653 if (id
< dc
->config
->ndbreak
) {
654 TCGv_i32 tmp
= tcg_const_i32(id
);
655 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
660 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
662 unsigned id
= sr
- DBREAKC
;
664 if (id
< dc
->config
->ndbreak
) {
665 TCGv_i32 tmp
= tcg_const_i32(id
);
666 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
671 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
673 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
674 /* This can change tb->flags, so exit tb */
675 gen_jumpi_check_loop_end(dc
, -1);
678 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
680 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
681 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
682 gen_helper_check_interrupts(cpu_env
);
683 gen_jumpi_check_loop_end(dc
, 0);
686 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
688 TCGv_i32 tmp
= tcg_temp_new_i32();
690 tcg_gen_andi_i32(tmp
, v
,
691 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
692 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
693 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
694 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
696 gen_helper_check_interrupts(cpu_env
);
699 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
701 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
702 gen_helper_check_interrupts(cpu_env
);
703 gen_jumpi_check_loop_end(dc
, 0);
706 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
708 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
709 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
711 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
714 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
715 reset_used_window(dc
);
716 gen_helper_check_interrupts(cpu_env
);
717 /* This can change mmu index and tb->flags, so exit tb */
718 gen_jumpi_check_loop_end(dc
, -1);
721 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
724 tcg_gen_mov_i32(dc
->next_icount
, v
);
726 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
730 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
732 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
733 /* This can change tb->flags, so exit tb */
734 gen_jumpi_check_loop_end(dc
, -1);
737 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
739 uint32_t id
= sr
- CCOMPARE
;
740 if (id
< dc
->config
->nccompare
) {
741 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
742 gen_advance_ccount(dc
);
743 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
744 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
745 gen_helper_check_interrupts(cpu_env
);
749 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
751 static void (* const wsr_handler
[256])(DisasContext
*dc
,
752 uint32_t sr
, TCGv_i32 v
) = {
753 [LBEG
] = gen_wsr_lbeg
,
754 [LEND
] = gen_wsr_lend
,
757 [LITBASE
] = gen_wsr_litbase
,
758 [ACCHI
] = gen_wsr_acchi
,
759 [WINDOW_BASE
] = gen_wsr_windowbase
,
760 [WINDOW_START
] = gen_wsr_windowstart
,
761 [PTEVADDR
] = gen_wsr_ptevaddr
,
762 [RASID
] = gen_wsr_rasid
,
763 [ITLBCFG
] = gen_wsr_tlbcfg
,
764 [DTLBCFG
] = gen_wsr_tlbcfg
,
765 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
766 [ATOMCTL
] = gen_wsr_atomctl
,
767 [IBREAKA
] = gen_wsr_ibreaka
,
768 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
769 [DBREAKA
] = gen_wsr_dbreaka
,
770 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
771 [DBREAKC
] = gen_wsr_dbreakc
,
772 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
773 [CPENABLE
] = gen_wsr_cpenable
,
774 [INTSET
] = gen_wsr_intset
,
775 [INTCLEAR
] = gen_wsr_intclear
,
776 [INTENABLE
] = gen_wsr_intenable
,
778 [ICOUNT
] = gen_wsr_icount
,
779 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
780 [CCOMPARE
] = gen_wsr_ccompare
,
781 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
782 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
785 if (wsr_handler
[sr
]) {
786 wsr_handler
[sr
](dc
, sr
, s
);
788 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
792 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
796 gen_helper_wur_fcr(cpu_env
, s
);
800 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
804 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
809 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
810 TCGv_i32 addr
, bool no_hw_alignment
)
812 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
813 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
814 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
816 int label
= gen_new_label();
817 TCGv_i32 tmp
= tcg_temp_new_i32();
818 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
819 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
820 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
821 gen_set_label(label
);
826 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
828 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
829 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
830 gen_advance_ccount(dc
);
831 gen_helper_waiti(cpu_env
, pc
, intlevel
);
833 tcg_temp_free(intlevel
);
836 static void gen_window_check1(DisasContext
*dc
, unsigned r1
)
838 if (dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) {
841 if (option_enabled(dc
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
842 r1
/ 4 > dc
->used_window
) {
843 int label
= gen_new_label();
844 TCGv_i32 ws
= tcg_temp_new_i32();
846 dc
->used_window
= r1
/ 4;
847 tcg_gen_deposit_i32(ws
, cpu_SR
[WINDOW_START
], cpu_SR
[WINDOW_START
],
848 dc
->config
->nareg
/ 4, dc
->config
->nareg
/ 4);
849 tcg_gen_shr_i32(ws
, ws
, cpu_SR
[WINDOW_BASE
]);
850 tcg_gen_andi_i32(ws
, ws
, (2 << (r1
/ 4)) - 2);
851 tcg_gen_brcondi_i32(TCG_COND_EQ
, ws
, 0, label
);
853 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
854 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
856 gen_advance_ccount_cond(dc
);
857 gen_helper_window_check(cpu_env
, pc
, w
);
862 gen_set_label(label
);
867 static void gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
869 gen_window_check1(dc
, r1
> r2
? r1
: r2
);
872 static void gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
875 gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
878 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
880 TCGv_i32 m
= tcg_temp_new_i32();
883 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
885 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
890 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
892 #define HAS_OPTION_BITS(opt) do { \
893 if (!option_bits_enabled(dc, opt)) { \
894 qemu_log("Option is not enabled %s:%d\n", \
895 __FILE__, __LINE__); \
896 goto invalid_opcode; \
900 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
902 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
903 #define RESERVED() do { \
904 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
905 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
906 goto invalid_opcode; \
910 #ifdef TARGET_WORDS_BIGENDIAN
911 #define OP0 (((b0) & 0xf0) >> 4)
912 #define OP1 (((b2) & 0xf0) >> 4)
913 #define OP2 ((b2) & 0xf)
914 #define RRR_R ((b1) & 0xf)
915 #define RRR_S (((b1) & 0xf0) >> 4)
916 #define RRR_T ((b0) & 0xf)
918 #define OP0 (((b0) & 0xf))
919 #define OP1 (((b2) & 0xf))
920 #define OP2 (((b2) & 0xf0) >> 4)
921 #define RRR_R (((b1) & 0xf0) >> 4)
922 #define RRR_S (((b1) & 0xf))
923 #define RRR_T (((b0) & 0xf0) >> 4)
925 #define RRR_X ((RRR_R & 0x4) >> 2)
926 #define RRR_Y ((RRR_T & 0x4) >> 2)
927 #define RRR_W (RRR_R & 0x3)
936 #ifdef TARGET_WORDS_BIGENDIAN
937 #define RRI4_IMM4 ((b2) & 0xf)
939 #define RRI4_IMM4 (((b2) & 0xf0) >> 4)
945 #define RRI8_IMM8 (b2)
946 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
948 #ifdef TARGET_WORDS_BIGENDIAN
949 #define RI16_IMM16 (((b1) << 8) | (b2))
951 #define RI16_IMM16 (((b2) << 8) | (b1))
954 #ifdef TARGET_WORDS_BIGENDIAN
955 #define CALL_N (((b0) & 0xc) >> 2)
956 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
958 #define CALL_N (((b0) & 0x30) >> 4)
959 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
961 #define CALL_OFFSET_SE \
962 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
964 #define CALLX_N CALL_N
965 #ifdef TARGET_WORDS_BIGENDIAN
966 #define CALLX_M ((b0) & 0x3)
968 #define CALLX_M (((b0) & 0xc0) >> 6)
970 #define CALLX_S RRR_S
972 #define BRI12_M CALLX_M
973 #define BRI12_S RRR_S
974 #ifdef TARGET_WORDS_BIGENDIAN
975 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
977 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
979 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
981 #define BRI8_M BRI12_M
982 #define BRI8_R RRI8_R
983 #define BRI8_S RRI8_S
984 #define BRI8_IMM8 RRI8_IMM8
985 #define BRI8_IMM8_SE RRI8_IMM8_SE
989 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
990 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
993 static const uint32_t B4CONST
[] = {
994 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
997 static const uint32_t B4CONSTU
[] = {
998 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
1002 dc
->next_pc
= dc
->pc
+ 2;
1003 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
1005 dc
->next_pc
= dc
->pc
+ 3;
1006 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
1015 if ((RRR_R
& 0xc) == 0x8) {
1016 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1023 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1026 case 1: /*reserved*/
1034 gen_window_check1(dc
, CALLX_S
);
1035 gen_jump(dc
, cpu_R
[CALLX_S
]);
1039 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1041 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1042 gen_advance_ccount(dc
);
1043 gen_helper_retw(tmp
, cpu_env
, tmp
);
1049 case 3: /*reserved*/
1056 gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2);
1060 TCGv_i32 tmp
= tcg_temp_new_i32();
1061 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1062 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1070 case 3: /*CALLX12w*/
1071 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1073 TCGv_i32 tmp
= tcg_temp_new_i32();
1075 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1076 gen_callw(dc
, CALLX_N
, tmp
);
1086 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1087 gen_window_check2(dc
, RRR_T
, RRR_S
);
1089 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1090 gen_advance_ccount(dc
);
1091 gen_helper_movsp(cpu_env
, pc
);
1092 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1112 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1124 default: /*reserved*/
1133 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1136 gen_check_privilege(dc
);
1137 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1138 gen_helper_check_interrupts(cpu_env
);
1139 gen_jump(dc
, cpu_SR
[EPC1
]);
1147 gen_check_privilege(dc
);
1148 gen_jump(dc
, cpu_SR
[
1149 dc
->config
->ndepc
? DEPC
: EPC1
]);
1154 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1155 gen_check_privilege(dc
);
1157 TCGv_i32 tmp
= tcg_const_i32(1);
1160 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1161 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1164 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1165 cpu_SR
[WINDOW_START
], tmp
);
1167 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1168 cpu_SR
[WINDOW_START
], tmp
);
1171 gen_helper_restore_owb(cpu_env
);
1172 gen_helper_check_interrupts(cpu_env
);
1173 gen_jump(dc
, cpu_SR
[EPC1
]);
1179 default: /*reserved*/
1186 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1187 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1188 gen_check_privilege(dc
);
1189 tcg_gen_mov_i32(cpu_SR
[PS
],
1190 cpu_SR
[EPS2
+ RRR_S
- 2]);
1191 gen_helper_check_interrupts(cpu_env
);
1192 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1194 qemu_log("RFI %d is illegal\n", RRR_S
);
1195 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1203 default: /*reserved*/
1211 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1213 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1217 case 5: /*SYSCALLx*/
1218 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1220 case 0: /*SYSCALLx*/
1221 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1225 if (semihosting_enabled
) {
1226 gen_check_privilege(dc
);
1227 gen_helper_simcall(cpu_env
);
1229 qemu_log("SIMCALL but semihosting is disabled\n");
1230 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1241 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1242 gen_check_privilege(dc
);
1243 gen_window_check1(dc
, RRR_T
);
1244 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1245 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1246 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1247 gen_helper_check_interrupts(cpu_env
);
1248 gen_jumpi_check_loop_end(dc
, 0);
1252 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1253 gen_check_privilege(dc
);
1254 gen_waiti(dc
, RRR_S
);
1261 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1263 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1264 TCGv_i32 mask
= tcg_const_i32(
1265 ((1 << shift
) - 1) << RRR_S
);
1266 TCGv_i32 tmp
= tcg_temp_new_i32();
1268 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1269 if (RRR_R
& 1) { /*ALL*/
1270 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1272 tcg_gen_add_i32(tmp
, tmp
, mask
);
1274 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1275 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1277 tcg_temp_free(mask
);
1282 default: /*reserved*/
1290 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1291 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1295 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1296 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1300 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1301 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1307 gen_window_check1(dc
, RRR_S
);
1308 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1312 gen_window_check1(dc
, RRR_S
);
1313 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1317 gen_window_check1(dc
, RRR_S
);
1319 TCGv_i32 tmp
= tcg_temp_new_i32();
1320 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1321 gen_right_shift_sar(dc
, tmp
);
1327 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 gen_check_privilege(dc
);
1357 TCGv_i32 tmp
= tcg_const_i32(
1358 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1359 gen_helper_rotw(cpu_env
, tmp
);
1361 reset_used_window(dc
);
1366 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1367 gen_window_check2(dc
, RRR_S
, RRR_T
);
1368 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1372 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1373 gen_window_check2(dc
, RRR_S
, RRR_T
);
1374 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1377 default: /*reserved*/
1385 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1386 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1387 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1388 gen_check_privilege(dc
);
1389 gen_window_check2(dc
, RRR_S
, RRR_T
);
1391 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1393 switch (RRR_R
& 7) {
1394 case 3: /*RITLB0*/ /*RDTLB0*/
1395 gen_helper_rtlb0(cpu_R
[RRR_T
],
1396 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1399 case 4: /*IITLB*/ /*IDTLB*/
1400 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1401 /* This could change memory mapping, so exit tb */
1402 gen_jumpi_check_loop_end(dc
, -1);
1405 case 5: /*PITLB*/ /*PDTLB*/
1406 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1407 gen_helper_ptlb(cpu_R
[RRR_T
],
1408 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1411 case 6: /*WITLB*/ /*WDTLB*/
1413 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1414 /* This could change memory mapping, so exit tb */
1415 gen_jumpi_check_loop_end(dc
, -1);
1418 case 7: /*RITLB1*/ /*RDTLB1*/
1419 gen_helper_rtlb1(cpu_R
[RRR_T
],
1420 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1424 tcg_temp_free(dtlb
);
1428 tcg_temp_free(dtlb
);
1433 gen_window_check2(dc
, RRR_R
, RRR_T
);
1436 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1441 TCGv_i32 zero
= tcg_const_i32(0);
1442 TCGv_i32 neg
= tcg_temp_new_i32();
1444 tcg_gen_neg_i32(neg
, cpu_R
[RRR_T
]);
1445 tcg_gen_movcond_i32(TCG_COND_GE
, cpu_R
[RRR_R
],
1446 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_T
], neg
);
1448 tcg_temp_free(zero
);
1452 default: /*reserved*/
1458 case 7: /*reserved*/
1463 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1464 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1470 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1472 TCGv_i32 tmp
= tcg_temp_new_i32();
1473 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1474 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1480 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1481 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1487 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1489 TCGv_i32 tmp
= tcg_temp_new_i32();
1490 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1491 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1502 gen_window_check2(dc
, RRR_R
, RRR_S
);
1503 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1504 32 - (RRR_T
| ((OP2
& 1) << 4)));
1509 gen_window_check2(dc
, RRR_R
, RRR_T
);
1510 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1511 RRR_S
| ((OP2
& 1) << 4));
1515 gen_window_check2(dc
, RRR_R
, RRR_T
);
1516 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1520 if (gen_check_sr(dc
, RSR_SR
, SR_X
)) {
1521 TCGv_i32 tmp
= tcg_temp_new_i32();
1524 gen_check_privilege(dc
);
1526 gen_window_check1(dc
, RRR_T
);
1527 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1528 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1529 gen_wsr(dc
, RSR_SR
, tmp
);
1535 * Note: 64 bit ops are used here solely because SAR values
1538 #define gen_shift_reg(cmd, reg) do { \
1539 TCGv_i64 tmp = tcg_temp_new_i64(); \
1540 tcg_gen_extu_i32_i64(tmp, reg); \
1541 tcg_gen_##cmd##_i64(v, v, tmp); \
1542 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \
1543 tcg_temp_free_i64(v); \
1544 tcg_temp_free_i64(tmp); \
1547 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1550 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1552 TCGv_i64 v
= tcg_temp_new_i64();
1553 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1559 gen_window_check2(dc
, RRR_R
, RRR_T
);
1561 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1563 TCGv_i64 v
= tcg_temp_new_i64();
1564 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1570 gen_window_check2(dc
, RRR_R
, RRR_S
);
1571 if (dc
->sar_m32_5bit
) {
1572 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1574 TCGv_i64 v
= tcg_temp_new_i64();
1575 TCGv_i32 s
= tcg_const_i32(32);
1576 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1577 tcg_gen_andi_i32(s
, s
, 0x3f);
1578 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1579 gen_shift_reg(shl
, s
);
1585 gen_window_check2(dc
, RRR_R
, RRR_T
);
1587 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1589 TCGv_i64 v
= tcg_temp_new_i64();
1590 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1595 #undef gen_shift_reg
1598 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1599 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1601 TCGv_i32 v1
= tcg_temp_new_i32();
1602 TCGv_i32 v2
= tcg_temp_new_i32();
1603 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1604 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1605 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1612 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1613 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1615 TCGv_i32 v1
= tcg_temp_new_i32();
1616 TCGv_i32 v2
= tcg_temp_new_i32();
1617 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1618 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1619 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1625 default: /*reserved*/
1633 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1637 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1638 int label
= gen_new_label();
1639 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1640 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1641 gen_set_label(label
);
1645 #define BOOLEAN_LOGIC(fn, r, s, t) \
1647 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1648 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1649 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1651 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1652 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1653 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1654 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1655 tcg_temp_free(tmp1); \
1656 tcg_temp_free(tmp2); \
1660 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1664 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1668 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1672 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1676 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1679 #undef BOOLEAN_LOGIC
1682 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1683 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1688 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1690 TCGv lo
= tcg_temp_new();
1693 tcg_gen_mulu2_i32(lo
, cpu_R
[RRR_R
],
1694 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1696 tcg_gen_muls2_i32(lo
, cpu_R
[RRR_R
],
1697 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1704 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1710 int label1
= gen_new_label();
1711 int label2
= gen_new_label();
1713 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1715 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1717 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1718 OP2
== 13 ? 0x80000000 : 0);
1720 gen_set_label(label1
);
1722 tcg_gen_div_i32(cpu_R
[RRR_R
],
1723 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1725 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1726 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1728 gen_set_label(label2
);
1733 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1736 default: /*reserved*/
1745 if (gen_check_sr(dc
, RSR_SR
, SR_R
)) {
1747 gen_check_privilege(dc
);
1749 gen_window_check1(dc
, RRR_T
);
1750 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1755 if (gen_check_sr(dc
, RSR_SR
, SR_W
)) {
1757 gen_check_privilege(dc
);
1759 gen_window_check1(dc
, RRR_T
);
1760 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1765 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1766 gen_window_check2(dc
, RRR_R
, RRR_S
);
1768 int shift
= 24 - RRR_T
;
1771 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1772 } else if (shift
== 16) {
1773 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1775 TCGv_i32 tmp
= tcg_temp_new_i32();
1776 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1777 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1784 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1785 gen_window_check2(dc
, RRR_R
, RRR_S
);
1787 TCGv_i32 tmp1
= tcg_temp_new_i32();
1788 TCGv_i32 tmp2
= tcg_temp_new_i32();
1789 TCGv_i32 zero
= tcg_const_i32(0);
1791 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1792 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1793 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1795 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1796 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1798 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1799 cpu_R
[RRR_S
], tmp1
);
1800 tcg_temp_free(tmp1
);
1801 tcg_temp_free(tmp2
);
1802 tcg_temp_free(zero
);
1810 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1811 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 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1831 static const TCGCond cond
[] = {
1837 TCGv_i32 zero
= tcg_const_i32(0);
1839 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1840 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1841 tcg_temp_free(zero
);
1847 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1848 gen_window_check2(dc
, RRR_R
, RRR_S
);
1850 TCGv_i32 zero
= tcg_const_i32(0);
1851 TCGv_i32 tmp
= tcg_temp_new_i32();
1853 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1854 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1855 cpu_R
[RRR_R
], tmp
, zero
,
1856 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1859 tcg_temp_free(zero
);
1864 gen_window_check1(dc
, RRR_R
);
1866 int st
= (RRR_S
<< 4) + RRR_T
;
1867 if (uregnames
[st
].name
) {
1868 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1870 qemu_log("RUR %d not implemented, ", st
);
1877 gen_window_check1(dc
, RRR_T
);
1878 if (uregnames
[RSR_SR
].name
) {
1879 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1881 qemu_log("WUR %d not implemented, ", RSR_SR
);
1891 gen_window_check2(dc
, RRR_R
, RRR_T
);
1893 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1894 int maskimm
= (1 << (OP2
+ 1)) - 1;
1896 TCGv_i32 tmp
= tcg_temp_new_i32();
1897 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1898 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1917 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1918 gen_window_check2(dc
, RRR_S
, RRR_T
);
1919 gen_check_cpenable(dc
, 0);
1921 TCGv_i32 addr
= tcg_temp_new_i32();
1922 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1923 gen_load_store_alignment(dc
, 2, addr
, false);
1925 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1927 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1930 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1932 tcg_temp_free(addr
);
1936 default: /*reserved*/
1943 gen_window_check2(dc
, RRR_S
, RRR_T
);
1946 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1947 gen_check_privilege(dc
);
1949 TCGv_i32 addr
= tcg_temp_new_i32();
1950 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1951 (0xffffffc0 | (RRR_R
<< 2)));
1952 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1953 tcg_temp_free(addr
);
1958 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1959 gen_check_privilege(dc
);
1961 TCGv_i32 addr
= tcg_temp_new_i32();
1962 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1963 (0xffffffc0 | (RRR_R
<< 2)));
1964 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1965 tcg_temp_free(addr
);
1976 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1979 gen_check_cpenable(dc
, 0);
1980 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
1981 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1985 gen_check_cpenable(dc
, 0);
1986 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
1987 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1991 gen_check_cpenable(dc
, 0);
1992 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
1993 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1997 gen_check_cpenable(dc
, 0);
1998 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
1999 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2003 gen_check_cpenable(dc
, 0);
2004 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
2005 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2008 case 8: /*ROUND.Sf*/
2009 case 9: /*TRUNC.Sf*/
2010 case 10: /*FLOOR.Sf*/
2011 case 11: /*CEIL.Sf*/
2012 case 14: /*UTRUNC.Sf*/
2013 gen_window_check1(dc
, RRR_R
);
2014 gen_check_cpenable(dc
, 0);
2016 static const unsigned rounding_mode_const
[] = {
2017 float_round_nearest_even
,
2018 float_round_to_zero
,
2021 [6] = float_round_to_zero
,
2023 TCGv_i32 rounding_mode
= tcg_const_i32(
2024 rounding_mode_const
[OP2
& 7]);
2025 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2028 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2029 rounding_mode
, scale
);
2031 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2032 rounding_mode
, scale
);
2035 tcg_temp_free(rounding_mode
);
2036 tcg_temp_free(scale
);
2040 case 12: /*FLOAT.Sf*/
2041 case 13: /*UFLOAT.Sf*/
2042 gen_window_check1(dc
, RRR_S
);
2043 gen_check_cpenable(dc
, 0);
2045 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2048 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2049 cpu_R
[RRR_S
], scale
);
2051 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2052 cpu_R
[RRR_S
], scale
);
2054 tcg_temp_free(scale
);
2061 gen_check_cpenable(dc
, 0);
2062 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2066 gen_check_cpenable(dc
, 0);
2067 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2071 gen_window_check1(dc
, RRR_R
);
2072 gen_check_cpenable(dc
, 0);
2073 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2077 gen_window_check1(dc
, RRR_S
);
2078 gen_check_cpenable(dc
, 0);
2079 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2083 gen_check_cpenable(dc
, 0);
2084 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2087 default: /*reserved*/
2093 default: /*reserved*/
2100 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2102 #define gen_compare(rel, br, a, b) \
2104 TCGv_i32 bit = tcg_const_i32(1 << br); \
2106 gen_check_cpenable(dc, 0); \
2107 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2108 tcg_temp_free(bit); \
2113 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2117 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2121 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2125 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2129 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2133 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2137 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2142 case 8: /*MOVEQZ.Sf*/
2143 case 9: /*MOVNEZ.Sf*/
2144 case 10: /*MOVLTZ.Sf*/
2145 case 11: /*MOVGEZ.Sf*/
2146 gen_window_check1(dc
, RRR_T
);
2147 gen_check_cpenable(dc
, 0);
2149 static const TCGCond cond
[] = {
2155 TCGv_i32 zero
= tcg_const_i32(0);
2157 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2158 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2159 tcg_temp_free(zero
);
2163 case 12: /*MOVF.Sf*/
2164 case 13: /*MOVT.Sf*/
2165 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2166 gen_check_cpenable(dc
, 0);
2168 TCGv_i32 zero
= tcg_const_i32(0);
2169 TCGv_i32 tmp
= tcg_temp_new_i32();
2171 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2172 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2173 cpu_FR
[RRR_R
], tmp
, zero
,
2174 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2177 tcg_temp_free(zero
);
2181 default: /*reserved*/
2187 default: /*reserved*/
2194 gen_window_check1(dc
, RRR_T
);
2196 TCGv_i32 tmp
= tcg_const_i32(
2197 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2198 0 : ((dc
->pc
+ 3) & ~3)) +
2199 (0xfffc0000 | (RI16_IMM16
<< 2)));
2201 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2202 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2204 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2210 #define gen_load_store(type, shift) do { \
2211 TCGv_i32 addr = tcg_temp_new_i32(); \
2212 gen_window_check2(dc, RRI8_S, RRI8_T); \
2213 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2215 gen_load_store_alignment(dc, shift, addr, false); \
2217 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2218 tcg_temp_free(addr); \
2223 gen_load_store(ld8u
, 0);
2227 gen_load_store(ld16u
, 1);
2231 gen_load_store(ld32u
, 2);
2235 gen_load_store(st8
, 0);
2239 gen_load_store(st16
, 1);
2243 gen_load_store(st32
, 2);
2246 #define gen_dcache_hit_test(w, shift) do { \
2247 TCGv_i32 addr = tcg_temp_new_i32(); \
2248 TCGv_i32 res = tcg_temp_new_i32(); \
2249 gen_window_check1(dc, RRI##w##_S); \
2250 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2251 RRI##w##_IMM##w << shift); \
2252 tcg_gen_qemu_ld8u(res, addr, dc->cring); \
2253 tcg_temp_free(addr); \
2254 tcg_temp_free(res); \
2257 #define gen_dcache_hit_test4() gen_dcache_hit_test(4, 4)
2258 #define gen_dcache_hit_test8() gen_dcache_hit_test(8, 2)
2262 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2267 gen_window_check1(dc
, RRI8_S
);
2271 gen_window_check1(dc
, RRI8_S
);
2275 gen_window_check1(dc
, RRI8_S
);
2279 gen_window_check1(dc
, RRI8_S
);
2283 gen_dcache_hit_test8();
2287 gen_dcache_hit_test8();
2291 gen_check_privilege(dc
);
2292 gen_dcache_hit_test8();
2296 gen_check_privilege(dc
);
2297 gen_window_check1(dc
, RRI8_S
);
2303 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2304 gen_check_privilege(dc
);
2305 gen_dcache_hit_test4();
2309 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2310 gen_check_privilege(dc
);
2311 gen_dcache_hit_test4();
2315 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2316 gen_check_privilege(dc
);
2317 gen_window_check1(dc
, RRI4_S
);
2321 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2322 gen_check_privilege(dc
);
2323 gen_window_check1(dc
, RRI4_S
);
2327 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2328 gen_check_privilege(dc
);
2329 gen_window_check1(dc
, RRI4_S
);
2332 default: /*reserved*/
2339 #undef gen_dcache_hit_test
2340 #undef gen_dcache_hit_test4
2341 #undef gen_dcache_hit_test8
2343 #define gen_icache_hit_test(w, shift) do { \
2344 TCGv_i32 addr = tcg_temp_new_i32(); \
2345 gen_window_check1(dc, RRI##w##_S); \
2346 tcg_gen_movi_i32(cpu_pc, dc->pc); \
2347 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2348 RRI##w##_IMM##w << shift); \
2349 gen_helper_itlb_hit_test(cpu_env, addr); \
2350 tcg_temp_free(addr); \
2353 #define gen_icache_hit_test4() gen_icache_hit_test(4, 4)
2354 #define gen_icache_hit_test8() gen_icache_hit_test(8, 2)
2357 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2358 gen_window_check1(dc
, RRI8_S
);
2364 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2365 gen_check_privilege(dc
);
2366 gen_icache_hit_test4();
2370 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2371 gen_check_privilege(dc
);
2372 gen_icache_hit_test4();
2376 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2377 gen_check_privilege(dc
);
2378 gen_window_check1(dc
, RRI4_S
);
2381 default: /*reserved*/
2388 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2389 gen_icache_hit_test8();
2393 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2394 gen_check_privilege(dc
);
2395 gen_window_check1(dc
, RRI8_S
);
2398 default: /*reserved*/
2404 #undef gen_icache_hit_test
2405 #undef gen_icache_hit_test4
2406 #undef gen_icache_hit_test8
2409 gen_load_store(ld16s
, 1);
2411 #undef gen_load_store
2414 gen_window_check1(dc
, RRI8_T
);
2415 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2416 RRI8_IMM8
| (RRI8_S
<< 8) |
2417 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2420 #define gen_load_store_no_hw_align(type) do { \
2421 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2422 gen_window_check2(dc, RRI8_S, RRI8_T); \
2423 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2424 gen_load_store_alignment(dc, 2, addr, true); \
2425 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2426 tcg_temp_free(addr); \
2430 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2431 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2435 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2436 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2440 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2441 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
<< 8);
2444 case 14: /*S32C1Iy*/
2445 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2446 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2448 int label
= gen_new_label();
2449 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2450 TCGv_i32 addr
= tcg_temp_local_new_i32();
2453 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2454 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2455 gen_load_store_alignment(dc
, 2, addr
, true);
2457 gen_advance_ccount(dc
);
2458 tpc
= tcg_const_i32(dc
->pc
);
2459 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2460 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2461 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2462 cpu_SR
[SCOMPARE1
], label
);
2464 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2466 gen_set_label(label
);
2468 tcg_temp_free(addr
);
2474 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2475 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2477 #undef gen_load_store_no_hw_align
2479 default: /*reserved*/
2491 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2492 gen_window_check1(dc
, RRI8_S
);
2493 gen_check_cpenable(dc
, 0);
2495 TCGv_i32 addr
= tcg_temp_new_i32();
2496 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2497 gen_load_store_alignment(dc
, 2, addr
, false);
2499 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2501 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2504 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2506 tcg_temp_free(addr
);
2510 default: /*reserved*/
2517 HAS_OPTION(XTENSA_OPTION_MAC16
);
2526 bool is_m1_sr
= (OP2
& 0x3) == 2;
2527 bool is_m2_sr
= (OP2
& 0xc) == 0;
2528 uint32_t ld_offset
= 0;
2535 case 0: /*MACI?/MACC?*/
2537 ld_offset
= (OP2
& 1) ? -4 : 4;
2539 if (OP2
>= 8) { /*MACI/MACC*/
2540 if (OP1
== 0) { /*LDINC/LDDEC*/
2545 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2550 case 2: /*MACD?/MACA?*/
2551 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2557 if (op
!= MAC16_NONE
) {
2559 gen_window_check1(dc
, RRR_S
);
2562 gen_window_check1(dc
, RRR_T
);
2567 TCGv_i32 vaddr
= tcg_temp_new_i32();
2568 TCGv_i32 mem32
= tcg_temp_new_i32();
2571 gen_window_check1(dc
, RRR_S
);
2572 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2573 gen_load_store_alignment(dc
, 2, vaddr
, false);
2574 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2576 if (op
!= MAC16_NONE
) {
2577 TCGv_i32 m1
= gen_mac16_m(
2578 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2579 OP1
& 1, op
== MAC16_UMUL
);
2580 TCGv_i32 m2
= gen_mac16_m(
2581 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2582 OP1
& 2, op
== MAC16_UMUL
);
2584 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2585 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2586 if (op
== MAC16_UMUL
) {
2587 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2589 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2592 TCGv_i32 lo
= tcg_temp_new_i32();
2593 TCGv_i32 hi
= tcg_temp_new_i32();
2595 tcg_gen_mul_i32(lo
, m1
, m2
);
2596 tcg_gen_sari_i32(hi
, lo
, 31);
2597 if (op
== MAC16_MULA
) {
2598 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2599 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2602 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2603 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2606 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2608 tcg_temp_free_i32(lo
);
2609 tcg_temp_free_i32(hi
);
2615 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2616 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2618 tcg_temp_free(vaddr
);
2619 tcg_temp_free(mem32
);
2627 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2628 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2634 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2635 gen_window_check1(dc
, CALL_N
<< 2);
2636 gen_callwi(dc
, CALL_N
,
2637 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2645 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2649 gen_window_check1(dc
, BRI12_S
);
2651 static const TCGCond cond
[] = {
2652 TCG_COND_EQ
, /*BEQZ*/
2653 TCG_COND_NE
, /*BNEZ*/
2654 TCG_COND_LT
, /*BLTZ*/
2655 TCG_COND_GE
, /*BGEZ*/
2658 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2659 4 + BRI12_IMM12_SE
);
2664 gen_window_check1(dc
, BRI8_S
);
2666 static const TCGCond cond
[] = {
2667 TCG_COND_EQ
, /*BEQI*/
2668 TCG_COND_NE
, /*BNEI*/
2669 TCG_COND_LT
, /*BLTI*/
2670 TCG_COND_GE
, /*BGEI*/
2673 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2674 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2681 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2683 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2684 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2685 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2686 gen_advance_ccount(dc
);
2687 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2691 reset_used_window(dc
);
2699 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2701 TCGv_i32 tmp
= tcg_temp_new_i32();
2702 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2704 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2705 tmp
, 0, 4 + RRI8_IMM8_SE
);
2712 case 10: /*LOOPGTZ*/
2713 HAS_OPTION(XTENSA_OPTION_LOOP
);
2714 gen_window_check1(dc
, RRI8_S
);
2716 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2717 TCGv_i32 tmp
= tcg_const_i32(lend
);
2719 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2720 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2721 gen_helper_wsr_lend(cpu_env
, tmp
);
2725 int label
= gen_new_label();
2726 tcg_gen_brcondi_i32(
2727 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2728 cpu_R
[RRI8_S
], 0, label
);
2729 gen_jumpi(dc
, lend
, 1);
2730 gen_set_label(label
);
2733 gen_jumpi(dc
, dc
->next_pc
, 0);
2737 default: /*reserved*/
2746 gen_window_check1(dc
, BRI8_S
);
2747 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2748 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2758 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2760 switch (RRI8_R
& 7) {
2761 case 0: /*BNONE*/ /*BANY*/
2762 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2764 TCGv_i32 tmp
= tcg_temp_new_i32();
2765 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2766 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2771 case 1: /*BEQ*/ /*BNE*/
2772 case 2: /*BLT*/ /*BGE*/
2773 case 3: /*BLTU*/ /*BGEU*/
2774 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2776 static const TCGCond cond
[] = {
2782 [11] = TCG_COND_GEU
,
2784 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2789 case 4: /*BALL*/ /*BNALL*/
2790 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2792 TCGv_i32 tmp
= tcg_temp_new_i32();
2793 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2794 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2800 case 5: /*BBC*/ /*BBS*/
2801 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2803 #ifdef TARGET_WORDS_BIGENDIAN
2804 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2806 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2808 TCGv_i32 tmp
= tcg_temp_new_i32();
2809 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2810 #ifdef TARGET_WORDS_BIGENDIAN
2811 tcg_gen_shr_i32(bit
, bit
, tmp
);
2813 tcg_gen_shl_i32(bit
, bit
, tmp
);
2815 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2816 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2822 case 6: /*BBCI*/ /*BBSI*/
2824 gen_window_check1(dc
, RRI8_S
);
2826 TCGv_i32 tmp
= tcg_temp_new_i32();
2827 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2828 #ifdef TARGET_WORDS_BIGENDIAN
2829 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2831 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2833 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2842 #define gen_narrow_load_store(type) do { \
2843 TCGv_i32 addr = tcg_temp_new_i32(); \
2844 gen_window_check2(dc, RRRN_S, RRRN_T); \
2845 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2846 gen_load_store_alignment(dc, 2, addr, false); \
2847 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2848 tcg_temp_free(addr); \
2852 gen_narrow_load_store(ld32u
);
2856 gen_narrow_load_store(st32
);
2858 #undef gen_narrow_load_store
2861 gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
);
2862 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2865 case 11: /*ADDI.Nn*/
2866 gen_window_check2(dc
, RRRN_R
, RRRN_S
);
2867 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], RRRN_T
? RRRN_T
: -1);
2871 gen_window_check1(dc
, RRRN_S
);
2872 if (RRRN_T
< 8) { /*MOVI.Nn*/
2873 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2874 RRRN_R
| (RRRN_T
<< 4) |
2875 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2876 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2877 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2879 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2880 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2887 gen_window_check2(dc
, RRRN_S
, RRRN_T
);
2888 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2894 gen_jump(dc
, cpu_R
[0]);
2898 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2900 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2901 gen_advance_ccount(dc
);
2902 gen_helper_retw(tmp
, cpu_env
, tmp
);
2908 case 2: /*BREAK.Nn*/
2909 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2911 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2919 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2922 default: /*reserved*/
2928 default: /*reserved*/
2934 default: /*reserved*/
2939 if (dc
->is_jmp
== DISAS_NEXT
) {
2940 gen_check_loop_end(dc
, 0);
2942 dc
->pc
= dc
->next_pc
;
2947 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2948 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2952 static void check_breakpoint(CPUXtensaState
*env
, DisasContext
*dc
)
2954 CPUState
*cs
= CPU(xtensa_env_get_cpu(env
));
2957 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
2958 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
2959 if (bp
->pc
== dc
->pc
) {
2960 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2961 gen_exception(dc
, EXCP_DEBUG
);
2962 dc
->is_jmp
= DISAS_UPDATE
;
2968 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
2972 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
2973 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
2974 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
2975 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
2982 void gen_intermediate_code_internal(XtensaCPU
*cpu
,
2983 TranslationBlock
*tb
, bool search_pc
)
2985 CPUState
*cs
= CPU(cpu
);
2986 CPUXtensaState
*env
= &cpu
->env
;
2990 uint16_t *gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
2991 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2992 uint32_t pc_start
= tb
->pc
;
2993 uint32_t next_page_start
=
2994 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2996 if (max_insns
== 0) {
2997 max_insns
= CF_COUNT_MASK
;
3000 dc
.config
= env
->config
;
3001 dc
.singlestep_enabled
= cs
->singlestep_enabled
;
3004 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
3005 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
3006 dc
.lbeg
= env
->sregs
[LBEG
];
3007 dc
.lend
= env
->sregs
[LEND
];
3008 dc
.is_jmp
= DISAS_NEXT
;
3009 dc
.ccount_delta
= 0;
3010 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
3011 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
3012 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
3013 XTENSA_TBFLAG_CPENABLE_SHIFT
;
3016 init_sar_tracker(&dc
);
3017 reset_used_window(&dc
);
3019 dc
.next_icount
= tcg_temp_local_new_i32();
3024 if (tb
->flags
& XTENSA_TBFLAG_EXCEPTION
) {
3025 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3026 gen_exception(&dc
, EXCP_DEBUG
);
3030 check_breakpoint(env
, &dc
);
3033 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3037 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3040 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
3041 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
3042 tcg_ctx
.gen_opc_icount
[lj
] = insn_count
;
3045 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
3046 tcg_gen_debug_insn_start(dc
.pc
);
3051 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3056 int label
= gen_new_label();
3058 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
3059 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
3060 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
3062 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
3064 gen_set_label(label
);
3068 gen_ibreak_check(env
, &dc
);
3071 disas_xtensa_insn(env
, &dc
);
3074 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
3076 if (cs
->singlestep_enabled
) {
3077 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3078 gen_exception(&dc
, EXCP_DEBUG
);
3081 } while (dc
.is_jmp
== DISAS_NEXT
&&
3082 insn_count
< max_insns
&&
3083 dc
.pc
< next_page_start
&&
3084 tcg_ctx
.gen_opc_ptr
< gen_opc_end
);
3087 reset_sar_tracker(&dc
);
3089 tcg_temp_free(dc
.next_icount
);
3092 if (tb
->cflags
& CF_LAST_IO
) {
3096 if (dc
.is_jmp
== DISAS_NEXT
) {
3097 gen_jumpi(&dc
, dc
.pc
, 0);
3099 gen_tb_end(tb
, insn_count
);
3100 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
3103 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3104 qemu_log("----------------\n");
3105 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3106 log_target_disas(env
, pc_start
, dc
.pc
- pc_start
, 0);
3111 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3112 memset(tcg_ctx
.gen_opc_instr_start
+ lj
+ 1, 0,
3113 (j
- lj
) * sizeof(tcg_ctx
.gen_opc_instr_start
[0]));
3115 tb
->size
= dc
.pc
- pc_start
;
3116 tb
->icount
= insn_count
;
3120 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3122 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, false);
3125 void gen_intermediate_code_pc(CPUXtensaState
*env
, TranslationBlock
*tb
)
3127 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, true);
3130 void xtensa_cpu_dump_state(CPUState
*cs
, FILE *f
,
3131 fprintf_function cpu_fprintf
, int flags
)
3133 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
3134 CPUXtensaState
*env
= &cpu
->env
;
3137 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3139 for (i
= j
= 0; i
< 256; ++i
) {
3140 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3141 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3142 (j
++ % 4) == 3 ? '\n' : ' ');
3146 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3148 for (i
= j
= 0; i
< 256; ++i
) {
3149 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3150 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3151 (j
++ % 4) == 3 ? '\n' : ' ');
3155 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3157 for (i
= 0; i
< 16; ++i
) {
3158 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3159 (i
% 4) == 3 ? '\n' : ' ');
3162 cpu_fprintf(f
, "\n");
3164 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3165 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3166 (i
% 4) == 3 ? '\n' : ' ');
3169 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3170 cpu_fprintf(f
, "\n");
3172 for (i
= 0; i
< 16; ++i
) {
3173 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3174 float32_val(env
->fregs
[i
]),
3175 *(float *)&env
->fregs
[i
], (i
% 2) == 1 ? '\n' : ' ');
3180 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
, int pc_pos
)
3182 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];