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 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_ACCESS(regname, opt, acc) { \
107 #define XTENSA_REG_BITS(regname, opt) \
108 XTENSA_REG_BITS_ACCESS(regname, opt, SR_RWX)
110 static const XtensaReg sregnames
[256] = {
111 [LBEG
] = XTENSA_REG("LBEG", XTENSA_OPTION_LOOP
),
112 [LEND
] = XTENSA_REG("LEND", XTENSA_OPTION_LOOP
),
113 [LCOUNT
] = XTENSA_REG("LCOUNT", XTENSA_OPTION_LOOP
),
114 [SAR
] = XTENSA_REG_BITS("SAR", XTENSA_OPTION_ALL
),
115 [BR
] = XTENSA_REG("BR", XTENSA_OPTION_BOOLEAN
),
116 [LITBASE
] = XTENSA_REG("LITBASE", XTENSA_OPTION_EXTENDED_L32R
),
117 [SCOMPARE1
] = XTENSA_REG("SCOMPARE1", XTENSA_OPTION_CONDITIONAL_STORE
),
118 [ACCLO
] = XTENSA_REG("ACCLO", XTENSA_OPTION_MAC16
),
119 [ACCHI
] = XTENSA_REG("ACCHI", XTENSA_OPTION_MAC16
),
120 [MR
] = XTENSA_REG("MR0", XTENSA_OPTION_MAC16
),
121 [MR
+ 1] = XTENSA_REG("MR1", XTENSA_OPTION_MAC16
),
122 [MR
+ 2] = XTENSA_REG("MR2", XTENSA_OPTION_MAC16
),
123 [MR
+ 3] = XTENSA_REG("MR3", XTENSA_OPTION_MAC16
),
124 [WINDOW_BASE
] = XTENSA_REG("WINDOW_BASE", XTENSA_OPTION_WINDOWED_REGISTER
),
125 [WINDOW_START
] = XTENSA_REG("WINDOW_START",
126 XTENSA_OPTION_WINDOWED_REGISTER
),
127 [PTEVADDR
] = XTENSA_REG("PTEVADDR", XTENSA_OPTION_MMU
),
128 [RASID
] = XTENSA_REG("RASID", XTENSA_OPTION_MMU
),
129 [ITLBCFG
] = XTENSA_REG("ITLBCFG", XTENSA_OPTION_MMU
),
130 [DTLBCFG
] = XTENSA_REG("DTLBCFG", XTENSA_OPTION_MMU
),
131 [IBREAKENABLE
] = XTENSA_REG("IBREAKENABLE", XTENSA_OPTION_DEBUG
),
132 [CACHEATTR
] = XTENSA_REG("CACHEATTR", XTENSA_OPTION_CACHEATTR
),
133 [ATOMCTL
] = XTENSA_REG("ATOMCTL", XTENSA_OPTION_ATOMCTL
),
134 [IBREAKA
] = XTENSA_REG("IBREAKA0", XTENSA_OPTION_DEBUG
),
135 [IBREAKA
+ 1] = XTENSA_REG("IBREAKA1", XTENSA_OPTION_DEBUG
),
136 [DBREAKA
] = XTENSA_REG("DBREAKA0", XTENSA_OPTION_DEBUG
),
137 [DBREAKA
+ 1] = XTENSA_REG("DBREAKA1", XTENSA_OPTION_DEBUG
),
138 [DBREAKC
] = XTENSA_REG("DBREAKC0", XTENSA_OPTION_DEBUG
),
139 [DBREAKC
+ 1] = XTENSA_REG("DBREAKC1", XTENSA_OPTION_DEBUG
),
140 [CONFIGID0
] = XTENSA_REG_BITS_ACCESS("CONFIGID0", XTENSA_OPTION_ALL
, SR_R
),
141 [EPC1
] = XTENSA_REG("EPC1", XTENSA_OPTION_EXCEPTION
),
142 [EPC1
+ 1] = XTENSA_REG("EPC2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
143 [EPC1
+ 2] = XTENSA_REG("EPC3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
144 [EPC1
+ 3] = XTENSA_REG("EPC4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
145 [EPC1
+ 4] = XTENSA_REG("EPC5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
146 [EPC1
+ 5] = XTENSA_REG("EPC6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
147 [EPC1
+ 6] = XTENSA_REG("EPC7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
148 [DEPC
] = XTENSA_REG("DEPC", XTENSA_OPTION_EXCEPTION
),
149 [EPS2
] = XTENSA_REG("EPS2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
150 [EPS2
+ 1] = XTENSA_REG("EPS3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
151 [EPS2
+ 2] = XTENSA_REG("EPS4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
152 [EPS2
+ 3] = XTENSA_REG("EPS5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
153 [EPS2
+ 4] = XTENSA_REG("EPS6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
154 [EPS2
+ 5] = XTENSA_REG("EPS7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
155 [CONFIGID1
] = XTENSA_REG_BITS_ACCESS("CONFIGID1", XTENSA_OPTION_ALL
, SR_R
),
156 [EXCSAVE1
] = XTENSA_REG("EXCSAVE1", XTENSA_OPTION_EXCEPTION
),
157 [EXCSAVE1
+ 1] = XTENSA_REG("EXCSAVE2",
158 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
159 [EXCSAVE1
+ 2] = XTENSA_REG("EXCSAVE3",
160 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
161 [EXCSAVE1
+ 3] = XTENSA_REG("EXCSAVE4",
162 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
163 [EXCSAVE1
+ 4] = XTENSA_REG("EXCSAVE5",
164 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
165 [EXCSAVE1
+ 5] = XTENSA_REG("EXCSAVE6",
166 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
167 [EXCSAVE1
+ 6] = XTENSA_REG("EXCSAVE7",
168 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
169 [CPENABLE
] = XTENSA_REG("CPENABLE", XTENSA_OPTION_COPROCESSOR
),
170 [INTSET
] = XTENSA_REG_ACCESS("INTSET", XTENSA_OPTION_INTERRUPT
, SR_RW
),
171 [INTCLEAR
] = XTENSA_REG_ACCESS("INTCLEAR", XTENSA_OPTION_INTERRUPT
, SR_W
),
172 [INTENABLE
] = XTENSA_REG("INTENABLE", XTENSA_OPTION_INTERRUPT
),
173 [PS
] = XTENSA_REG_BITS("PS", XTENSA_OPTION_ALL
),
174 [VECBASE
] = XTENSA_REG("VECBASE", XTENSA_OPTION_RELOCATABLE_VECTOR
),
175 [EXCCAUSE
] = XTENSA_REG("EXCCAUSE", XTENSA_OPTION_EXCEPTION
),
176 [DEBUGCAUSE
] = XTENSA_REG_ACCESS("DEBUGCAUSE", XTENSA_OPTION_DEBUG
, SR_R
),
177 [CCOUNT
] = XTENSA_REG("CCOUNT", XTENSA_OPTION_TIMER_INTERRUPT
),
178 [PRID
] = XTENSA_REG_ACCESS("PRID", XTENSA_OPTION_PROCESSOR_ID
, SR_R
),
179 [ICOUNT
] = XTENSA_REG("ICOUNT", XTENSA_OPTION_DEBUG
),
180 [ICOUNTLEVEL
] = XTENSA_REG("ICOUNTLEVEL", XTENSA_OPTION_DEBUG
),
181 [EXCVADDR
] = XTENSA_REG("EXCVADDR", XTENSA_OPTION_EXCEPTION
),
182 [CCOMPARE
] = XTENSA_REG("CCOMPARE0", XTENSA_OPTION_TIMER_INTERRUPT
),
183 [CCOMPARE
+ 1] = XTENSA_REG("CCOMPARE1",
184 XTENSA_OPTION_TIMER_INTERRUPT
),
185 [CCOMPARE
+ 2] = XTENSA_REG("CCOMPARE2",
186 XTENSA_OPTION_TIMER_INTERRUPT
),
187 [MISC
] = XTENSA_REG("MISC0", XTENSA_OPTION_MISC_SR
),
188 [MISC
+ 1] = XTENSA_REG("MISC1", XTENSA_OPTION_MISC_SR
),
189 [MISC
+ 2] = XTENSA_REG("MISC2", XTENSA_OPTION_MISC_SR
),
190 [MISC
+ 3] = XTENSA_REG("MISC3", XTENSA_OPTION_MISC_SR
),
193 static const XtensaReg uregnames
[256] = {
194 [THREADPTR
] = XTENSA_REG("THREADPTR", XTENSA_OPTION_THREAD_POINTER
),
195 [FCR
] = XTENSA_REG("FCR", XTENSA_OPTION_FP_COPROCESSOR
),
196 [FSR
] = XTENSA_REG("FSR", XTENSA_OPTION_FP_COPROCESSOR
),
199 void xtensa_translate_init(void)
201 static const char * const regnames
[] = {
202 "ar0", "ar1", "ar2", "ar3",
203 "ar4", "ar5", "ar6", "ar7",
204 "ar8", "ar9", "ar10", "ar11",
205 "ar12", "ar13", "ar14", "ar15",
207 static const char * const fregnames
[] = {
208 "f0", "f1", "f2", "f3",
209 "f4", "f5", "f6", "f7",
210 "f8", "f9", "f10", "f11",
211 "f12", "f13", "f14", "f15",
215 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
216 cpu_pc
= tcg_global_mem_new_i32(TCG_AREG0
,
217 offsetof(CPUXtensaState
, pc
), "pc");
219 for (i
= 0; i
< 16; i
++) {
220 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
221 offsetof(CPUXtensaState
, regs
[i
]),
225 for (i
= 0; i
< 16; i
++) {
226 cpu_FR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
227 offsetof(CPUXtensaState
, fregs
[i
]),
231 for (i
= 0; i
< 256; ++i
) {
232 if (sregnames
[i
].name
) {
233 cpu_SR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
234 offsetof(CPUXtensaState
, sregs
[i
]),
239 for (i
= 0; i
< 256; ++i
) {
240 if (uregnames
[i
].name
) {
241 cpu_UR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
242 offsetof(CPUXtensaState
, uregs
[i
]),
248 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
250 return xtensa_option_bits_enabled(dc
->config
, opt
);
253 static inline bool option_enabled(DisasContext
*dc
, int opt
)
255 return xtensa_option_enabled(dc
->config
, opt
);
258 static void init_litbase(DisasContext
*dc
)
260 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
261 dc
->litbase
= tcg_temp_local_new_i32();
262 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
266 static void reset_litbase(DisasContext
*dc
)
268 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
269 tcg_temp_free(dc
->litbase
);
273 static void init_sar_tracker(DisasContext
*dc
)
275 dc
->sar_5bit
= false;
276 dc
->sar_m32_5bit
= false;
277 dc
->sar_m32_allocated
= false;
280 static void reset_sar_tracker(DisasContext
*dc
)
282 if (dc
->sar_m32_allocated
) {
283 tcg_temp_free(dc
->sar_m32
);
287 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
289 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
290 if (dc
->sar_m32_5bit
) {
291 tcg_gen_discard_i32(dc
->sar_m32
);
294 dc
->sar_m32_5bit
= false;
297 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
299 TCGv_i32 tmp
= tcg_const_i32(32);
300 if (!dc
->sar_m32_allocated
) {
301 dc
->sar_m32
= tcg_temp_local_new_i32();
302 dc
->sar_m32_allocated
= true;
304 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
305 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
306 dc
->sar_5bit
= false;
307 dc
->sar_m32_5bit
= true;
311 static void gen_advance_ccount_cond(DisasContext
*dc
)
313 if (dc
->ccount_delta
> 0) {
314 TCGv_i32 tmp
= tcg_const_i32(dc
->ccount_delta
);
315 gen_helper_advance_ccount(cpu_env
, tmp
);
320 static void gen_advance_ccount(DisasContext
*dc
)
322 gen_advance_ccount_cond(dc
);
323 dc
->ccount_delta
= 0;
326 static void reset_used_window(DisasContext
*dc
)
331 static void gen_exception(DisasContext
*dc
, int excp
)
333 TCGv_i32 tmp
= tcg_const_i32(excp
);
334 gen_advance_ccount(dc
);
335 gen_helper_exception(cpu_env
, tmp
);
339 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
341 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
342 TCGv_i32 tcause
= tcg_const_i32(cause
);
343 gen_advance_ccount(dc
);
344 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
346 tcg_temp_free(tcause
);
347 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
348 cause
== SYSCALL_CAUSE
) {
349 dc
->is_jmp
= DISAS_UPDATE
;
353 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
356 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
357 TCGv_i32 tcause
= tcg_const_i32(cause
);
358 gen_advance_ccount(dc
);
359 gen_helper_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
361 tcg_temp_free(tcause
);
364 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
366 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
367 TCGv_i32 tcause
= tcg_const_i32(cause
);
368 gen_advance_ccount(dc
);
369 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
371 tcg_temp_free(tcause
);
372 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
373 dc
->is_jmp
= DISAS_UPDATE
;
377 static void gen_check_privilege(DisasContext
*dc
)
380 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
381 dc
->is_jmp
= DISAS_UPDATE
;
385 static void gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
387 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
388 !(dc
->cpenable
& (1 << cp
))) {
389 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
390 dc
->is_jmp
= DISAS_UPDATE
;
394 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
396 tcg_gen_mov_i32(cpu_pc
, dest
);
397 gen_advance_ccount(dc
);
399 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
->next_icount
);
401 if (dc
->singlestep_enabled
) {
402 gen_exception(dc
, EXCP_DEBUG
);
405 tcg_gen_goto_tb(slot
);
406 tcg_gen_exit_tb((uintptr_t)dc
->tb
+ slot
);
411 dc
->is_jmp
= DISAS_UPDATE
;
414 static void gen_jump(DisasContext
*dc
, TCGv dest
)
416 gen_jump_slot(dc
, dest
, -1);
419 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
421 TCGv_i32 tmp
= tcg_const_i32(dest
);
422 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
425 gen_jump_slot(dc
, tmp
, slot
);
429 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
432 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
434 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
435 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
436 tcg_temp_free(tcallinc
);
437 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
438 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
439 gen_jump_slot(dc
, dest
, slot
);
442 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
444 gen_callw_slot(dc
, callinc
, dest
, -1);
447 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
449 TCGv_i32 tmp
= tcg_const_i32(dest
);
450 if (((dc
->tb
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
453 gen_callw_slot(dc
, callinc
, tmp
, slot
);
457 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
459 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
460 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
461 dc
->next_pc
== dc
->lend
) {
462 int label
= gen_new_label();
464 gen_advance_ccount(dc
);
465 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
466 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
467 gen_jumpi(dc
, dc
->lbeg
, slot
);
468 gen_set_label(label
);
469 gen_jumpi(dc
, dc
->next_pc
, -1);
475 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
477 if (!gen_check_loop_end(dc
, slot
)) {
478 gen_jumpi(dc
, dc
->next_pc
, slot
);
482 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
483 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
485 int label
= gen_new_label();
487 gen_advance_ccount(dc
);
488 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
489 gen_jumpi_check_loop_end(dc
, 0);
490 gen_set_label(label
);
491 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
494 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
495 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
497 TCGv_i32 tmp
= tcg_const_i32(t1
);
498 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
502 static bool gen_check_sr(DisasContext
*dc
, uint32_t sr
, unsigned access
)
504 if (!xtensa_option_bits_enabled(dc
->config
, sregnames
[sr
].opt_bits
)) {
505 if (sregnames
[sr
].name
) {
506 qemu_log("SR %s is not configured\n", sregnames
[sr
].name
);
508 qemu_log("SR %d is not implemented\n", sr
);
510 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
512 } else if (!(sregnames
[sr
].access
& access
)) {
513 static const char * const access_text
[] = {
518 assert(access
< ARRAY_SIZE(access_text
) && access_text
[access
]);
519 qemu_log("SR %s is not available for %s\n", sregnames
[sr
].name
,
520 access_text
[access
]);
521 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
527 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
529 gen_advance_ccount(dc
);
530 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
533 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
535 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
536 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
537 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
540 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
542 static void (* const rsr_handler
[256])(DisasContext
*dc
,
543 TCGv_i32 d
, uint32_t sr
) = {
544 [CCOUNT
] = gen_rsr_ccount
,
545 [PTEVADDR
] = gen_rsr_ptevaddr
,
548 if (rsr_handler
[sr
]) {
549 rsr_handler
[sr
](dc
, d
, sr
);
551 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
555 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
557 gen_helper_wsr_lbeg(cpu_env
, s
);
558 gen_jumpi_check_loop_end(dc
, 0);
561 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
563 gen_helper_wsr_lend(cpu_env
, s
);
564 gen_jumpi_check_loop_end(dc
, 0);
567 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
569 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
570 if (dc
->sar_m32_5bit
) {
571 tcg_gen_discard_i32(dc
->sar_m32
);
573 dc
->sar_5bit
= false;
574 dc
->sar_m32_5bit
= false;
577 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
579 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
582 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
584 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
585 /* This can change tb->flags, so exit tb */
586 gen_jumpi_check_loop_end(dc
, -1);
589 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
591 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
594 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
596 gen_helper_wsr_windowbase(cpu_env
, v
);
597 reset_used_window(dc
);
600 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
602 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
603 reset_used_window(dc
);
606 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
608 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
611 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
613 gen_helper_wsr_rasid(cpu_env
, v
);
614 /* This can change tb->flags, so exit tb */
615 gen_jumpi_check_loop_end(dc
, -1);
618 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
620 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
623 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
625 gen_helper_wsr_ibreakenable(cpu_env
, v
);
626 gen_jumpi_check_loop_end(dc
, 0);
629 static void gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
631 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
634 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
636 unsigned id
= sr
- IBREAKA
;
638 if (id
< dc
->config
->nibreak
) {
639 TCGv_i32 tmp
= tcg_const_i32(id
);
640 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
642 gen_jumpi_check_loop_end(dc
, 0);
646 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
648 unsigned id
= sr
- DBREAKA
;
650 if (id
< dc
->config
->ndbreak
) {
651 TCGv_i32 tmp
= tcg_const_i32(id
);
652 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
657 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
659 unsigned id
= sr
- DBREAKC
;
661 if (id
< dc
->config
->ndbreak
) {
662 TCGv_i32 tmp
= tcg_const_i32(id
);
663 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
668 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
670 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
671 /* This can change tb->flags, so exit tb */
672 gen_jumpi_check_loop_end(dc
, -1);
675 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
677 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
678 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
679 gen_helper_check_interrupts(cpu_env
);
680 gen_jumpi_check_loop_end(dc
, 0);
683 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
685 TCGv_i32 tmp
= tcg_temp_new_i32();
687 tcg_gen_andi_i32(tmp
, v
,
688 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
689 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
690 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
691 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
693 gen_helper_check_interrupts(cpu_env
);
696 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
698 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
699 gen_helper_check_interrupts(cpu_env
);
700 gen_jumpi_check_loop_end(dc
, 0);
703 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
705 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
706 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
708 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
711 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
712 reset_used_window(dc
);
713 gen_helper_check_interrupts(cpu_env
);
714 /* This can change mmu index and tb->flags, so exit tb */
715 gen_jumpi_check_loop_end(dc
, -1);
718 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
721 tcg_gen_mov_i32(dc
->next_icount
, v
);
723 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
727 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
729 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
730 /* This can change tb->flags, so exit tb */
731 gen_jumpi_check_loop_end(dc
, -1);
734 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
736 uint32_t id
= sr
- CCOMPARE
;
737 if (id
< dc
->config
->nccompare
) {
738 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
739 gen_advance_ccount(dc
);
740 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
741 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
742 gen_helper_check_interrupts(cpu_env
);
746 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
748 static void (* const wsr_handler
[256])(DisasContext
*dc
,
749 uint32_t sr
, TCGv_i32 v
) = {
750 [LBEG
] = gen_wsr_lbeg
,
751 [LEND
] = gen_wsr_lend
,
754 [LITBASE
] = gen_wsr_litbase
,
755 [ACCHI
] = gen_wsr_acchi
,
756 [WINDOW_BASE
] = gen_wsr_windowbase
,
757 [WINDOW_START
] = gen_wsr_windowstart
,
758 [PTEVADDR
] = gen_wsr_ptevaddr
,
759 [RASID
] = gen_wsr_rasid
,
760 [ITLBCFG
] = gen_wsr_tlbcfg
,
761 [DTLBCFG
] = gen_wsr_tlbcfg
,
762 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
763 [ATOMCTL
] = gen_wsr_atomctl
,
764 [IBREAKA
] = gen_wsr_ibreaka
,
765 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
766 [DBREAKA
] = gen_wsr_dbreaka
,
767 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
768 [DBREAKC
] = gen_wsr_dbreakc
,
769 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
770 [CPENABLE
] = gen_wsr_cpenable
,
771 [INTSET
] = gen_wsr_intset
,
772 [INTCLEAR
] = gen_wsr_intclear
,
773 [INTENABLE
] = gen_wsr_intenable
,
775 [ICOUNT
] = gen_wsr_icount
,
776 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
777 [CCOMPARE
] = gen_wsr_ccompare
,
778 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
779 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
782 if (wsr_handler
[sr
]) {
783 wsr_handler
[sr
](dc
, sr
, s
);
785 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
789 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
793 gen_helper_wur_fcr(cpu_env
, s
);
797 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
801 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
806 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
807 TCGv_i32 addr
, bool no_hw_alignment
)
809 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
810 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
811 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
813 int label
= gen_new_label();
814 TCGv_i32 tmp
= tcg_temp_new_i32();
815 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
816 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
817 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
818 gen_set_label(label
);
823 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
825 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
826 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
827 gen_advance_ccount(dc
);
828 gen_helper_waiti(cpu_env
, pc
, intlevel
);
830 tcg_temp_free(intlevel
);
833 static void gen_window_check1(DisasContext
*dc
, unsigned r1
)
835 if (dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) {
838 if (option_enabled(dc
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
839 r1
/ 4 > dc
->used_window
) {
840 int label
= gen_new_label();
841 TCGv_i32 ws
= tcg_temp_new_i32();
843 dc
->used_window
= r1
/ 4;
844 tcg_gen_deposit_i32(ws
, cpu_SR
[WINDOW_START
], cpu_SR
[WINDOW_START
],
845 dc
->config
->nareg
/ 4, dc
->config
->nareg
/ 4);
846 tcg_gen_shr_i32(ws
, ws
, cpu_SR
[WINDOW_BASE
]);
847 tcg_gen_andi_i32(ws
, ws
, (2 << (r1
/ 4)) - 2);
848 tcg_gen_brcondi_i32(TCG_COND_EQ
, ws
, 0, label
);
850 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
851 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
853 gen_advance_ccount_cond(dc
);
854 gen_helper_window_check(cpu_env
, pc
, w
);
859 gen_set_label(label
);
864 static void gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
866 gen_window_check1(dc
, r1
> r2
? r1
: r2
);
869 static void gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
872 gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
875 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
877 TCGv_i32 m
= tcg_temp_new_i32();
880 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
882 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
887 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
889 #define HAS_OPTION_BITS(opt) do { \
890 if (!option_bits_enabled(dc, opt)) { \
891 qemu_log("Option is not enabled %s:%d\n", \
892 __FILE__, __LINE__); \
893 goto invalid_opcode; \
897 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
899 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
900 #define RESERVED() do { \
901 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
902 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
903 goto invalid_opcode; \
907 #ifdef TARGET_WORDS_BIGENDIAN
908 #define OP0 (((b0) & 0xf0) >> 4)
909 #define OP1 (((b2) & 0xf0) >> 4)
910 #define OP2 ((b2) & 0xf)
911 #define RRR_R ((b1) & 0xf)
912 #define RRR_S (((b1) & 0xf0) >> 4)
913 #define RRR_T ((b0) & 0xf)
915 #define OP0 (((b0) & 0xf))
916 #define OP1 (((b2) & 0xf))
917 #define OP2 (((b2) & 0xf0) >> 4)
918 #define RRR_R (((b1) & 0xf0) >> 4)
919 #define RRR_S (((b1) & 0xf))
920 #define RRR_T (((b0) & 0xf0) >> 4)
922 #define RRR_X ((RRR_R & 0x4) >> 2)
923 #define RRR_Y ((RRR_T & 0x4) >> 2)
924 #define RRR_W (RRR_R & 0x3)
933 #ifdef TARGET_WORDS_BIGENDIAN
934 #define RRI4_IMM4 ((b2) & 0xf)
936 #define RRI4_IMM4 (((b2) & 0xf0) >> 4)
942 #define RRI8_IMM8 (b2)
943 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
945 #ifdef TARGET_WORDS_BIGENDIAN
946 #define RI16_IMM16 (((b1) << 8) | (b2))
948 #define RI16_IMM16 (((b2) << 8) | (b1))
951 #ifdef TARGET_WORDS_BIGENDIAN
952 #define CALL_N (((b0) & 0xc) >> 2)
953 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
955 #define CALL_N (((b0) & 0x30) >> 4)
956 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
958 #define CALL_OFFSET_SE \
959 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
961 #define CALLX_N CALL_N
962 #ifdef TARGET_WORDS_BIGENDIAN
963 #define CALLX_M ((b0) & 0x3)
965 #define CALLX_M (((b0) & 0xc0) >> 6)
967 #define CALLX_S RRR_S
969 #define BRI12_M CALLX_M
970 #define BRI12_S RRR_S
971 #ifdef TARGET_WORDS_BIGENDIAN
972 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
974 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
976 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
978 #define BRI8_M BRI12_M
979 #define BRI8_R RRI8_R
980 #define BRI8_S RRI8_S
981 #define BRI8_IMM8 RRI8_IMM8
982 #define BRI8_IMM8_SE RRI8_IMM8_SE
986 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
987 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
990 static const uint32_t B4CONST
[] = {
991 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
994 static const uint32_t B4CONSTU
[] = {
995 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
999 dc
->next_pc
= dc
->pc
+ 2;
1000 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
1002 dc
->next_pc
= dc
->pc
+ 3;
1003 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
1012 if ((RRR_R
& 0xc) == 0x8) {
1013 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1020 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1023 case 1: /*reserved*/
1031 gen_window_check1(dc
, CALLX_S
);
1032 gen_jump(dc
, cpu_R
[CALLX_S
]);
1036 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1038 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1039 gen_advance_ccount(dc
);
1040 gen_helper_retw(tmp
, cpu_env
, tmp
);
1046 case 3: /*reserved*/
1053 gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2);
1057 TCGv_i32 tmp
= tcg_temp_new_i32();
1058 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1059 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1067 case 3: /*CALLX12w*/
1068 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1070 TCGv_i32 tmp
= tcg_temp_new_i32();
1072 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1073 gen_callw(dc
, CALLX_N
, tmp
);
1083 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1084 gen_window_check2(dc
, RRR_T
, RRR_S
);
1086 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1087 gen_advance_ccount(dc
);
1088 gen_helper_movsp(cpu_env
, pc
);
1089 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1109 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1121 default: /*reserved*/
1130 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1133 gen_check_privilege(dc
);
1134 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1135 gen_helper_check_interrupts(cpu_env
);
1136 gen_jump(dc
, cpu_SR
[EPC1
]);
1144 gen_check_privilege(dc
);
1145 gen_jump(dc
, cpu_SR
[
1146 dc
->config
->ndepc
? DEPC
: EPC1
]);
1151 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1152 gen_check_privilege(dc
);
1154 TCGv_i32 tmp
= tcg_const_i32(1);
1157 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1158 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1161 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1162 cpu_SR
[WINDOW_START
], tmp
);
1164 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1165 cpu_SR
[WINDOW_START
], tmp
);
1168 gen_helper_restore_owb(cpu_env
);
1169 gen_helper_check_interrupts(cpu_env
);
1170 gen_jump(dc
, cpu_SR
[EPC1
]);
1176 default: /*reserved*/
1183 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1184 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1185 gen_check_privilege(dc
);
1186 tcg_gen_mov_i32(cpu_SR
[PS
],
1187 cpu_SR
[EPS2
+ RRR_S
- 2]);
1188 gen_helper_check_interrupts(cpu_env
);
1189 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1191 qemu_log("RFI %d is illegal\n", RRR_S
);
1192 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1200 default: /*reserved*/
1208 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1210 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1214 case 5: /*SYSCALLx*/
1215 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1217 case 0: /*SYSCALLx*/
1218 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1222 if (semihosting_enabled
) {
1223 gen_check_privilege(dc
);
1224 gen_helper_simcall(cpu_env
);
1226 qemu_log("SIMCALL but semihosting is disabled\n");
1227 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1238 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1239 gen_check_privilege(dc
);
1240 gen_window_check1(dc
, RRR_T
);
1241 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1242 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1243 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1244 gen_helper_check_interrupts(cpu_env
);
1245 gen_jumpi_check_loop_end(dc
, 0);
1249 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1250 gen_check_privilege(dc
);
1251 gen_waiti(dc
, RRR_S
);
1258 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1260 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1261 TCGv_i32 mask
= tcg_const_i32(
1262 ((1 << shift
) - 1) << RRR_S
);
1263 TCGv_i32 tmp
= tcg_temp_new_i32();
1265 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1266 if (RRR_R
& 1) { /*ALL*/
1267 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1269 tcg_gen_add_i32(tmp
, tmp
, mask
);
1271 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1272 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1274 tcg_temp_free(mask
);
1279 default: /*reserved*/
1287 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1288 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1292 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1293 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1297 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1298 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1304 gen_window_check1(dc
, RRR_S
);
1305 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1309 gen_window_check1(dc
, RRR_S
);
1310 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1314 gen_window_check1(dc
, RRR_S
);
1316 TCGv_i32 tmp
= tcg_temp_new_i32();
1317 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1318 gen_right_shift_sar(dc
, tmp
);
1324 gen_window_check1(dc
, RRR_S
);
1326 TCGv_i32 tmp
= tcg_temp_new_i32();
1327 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1328 gen_left_shift_sar(dc
, tmp
);
1335 TCGv_i32 tmp
= tcg_const_i32(
1336 RRR_S
| ((RRR_T
& 1) << 4));
1337 gen_right_shift_sar(dc
, tmp
);
1351 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1352 gen_check_privilege(dc
);
1354 TCGv_i32 tmp
= tcg_const_i32(
1355 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1356 gen_helper_rotw(cpu_env
, tmp
);
1358 reset_used_window(dc
);
1363 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1364 gen_window_check2(dc
, RRR_S
, RRR_T
);
1365 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1369 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1370 gen_window_check2(dc
, RRR_S
, RRR_T
);
1371 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1374 default: /*reserved*/
1382 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1383 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1384 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1385 gen_check_privilege(dc
);
1386 gen_window_check2(dc
, RRR_S
, RRR_T
);
1388 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1390 switch (RRR_R
& 7) {
1391 case 3: /*RITLB0*/ /*RDTLB0*/
1392 gen_helper_rtlb0(cpu_R
[RRR_T
],
1393 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1396 case 4: /*IITLB*/ /*IDTLB*/
1397 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1398 /* This could change memory mapping, so exit tb */
1399 gen_jumpi_check_loop_end(dc
, -1);
1402 case 5: /*PITLB*/ /*PDTLB*/
1403 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1404 gen_helper_ptlb(cpu_R
[RRR_T
],
1405 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1408 case 6: /*WITLB*/ /*WDTLB*/
1410 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1411 /* This could change memory mapping, so exit tb */
1412 gen_jumpi_check_loop_end(dc
, -1);
1415 case 7: /*RITLB1*/ /*RDTLB1*/
1416 gen_helper_rtlb1(cpu_R
[RRR_T
],
1417 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1421 tcg_temp_free(dtlb
);
1425 tcg_temp_free(dtlb
);
1430 gen_window_check2(dc
, RRR_R
, RRR_T
);
1433 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1438 TCGv_i32 zero
= tcg_const_i32(0);
1439 TCGv_i32 neg
= tcg_temp_new_i32();
1441 tcg_gen_neg_i32(neg
, cpu_R
[RRR_T
]);
1442 tcg_gen_movcond_i32(TCG_COND_GE
, cpu_R
[RRR_R
],
1443 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_T
], neg
);
1445 tcg_temp_free(zero
);
1449 default: /*reserved*/
1455 case 7: /*reserved*/
1460 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1461 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1467 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1469 TCGv_i32 tmp
= tcg_temp_new_i32();
1470 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1471 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1477 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1478 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1484 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1486 TCGv_i32 tmp
= tcg_temp_new_i32();
1487 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1488 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1499 gen_window_check2(dc
, RRR_R
, RRR_S
);
1500 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1501 32 - (RRR_T
| ((OP2
& 1) << 4)));
1506 gen_window_check2(dc
, RRR_R
, RRR_T
);
1507 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1508 RRR_S
| ((OP2
& 1) << 4));
1512 gen_window_check2(dc
, RRR_R
, RRR_T
);
1513 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1517 if (gen_check_sr(dc
, RSR_SR
, SR_X
)) {
1518 TCGv_i32 tmp
= tcg_temp_new_i32();
1521 gen_check_privilege(dc
);
1523 gen_window_check1(dc
, RRR_T
);
1524 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1525 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1526 gen_wsr(dc
, RSR_SR
, tmp
);
1532 * Note: 64 bit ops are used here solely because SAR values
1535 #define gen_shift_reg(cmd, reg) do { \
1536 TCGv_i64 tmp = tcg_temp_new_i64(); \
1537 tcg_gen_extu_i32_i64(tmp, reg); \
1538 tcg_gen_##cmd##_i64(v, v, tmp); \
1539 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \
1540 tcg_temp_free_i64(v); \
1541 tcg_temp_free_i64(tmp); \
1544 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1547 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1549 TCGv_i64 v
= tcg_temp_new_i64();
1550 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1556 gen_window_check2(dc
, RRR_R
, RRR_T
);
1558 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1560 TCGv_i64 v
= tcg_temp_new_i64();
1561 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1567 gen_window_check2(dc
, RRR_R
, RRR_S
);
1568 if (dc
->sar_m32_5bit
) {
1569 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1571 TCGv_i64 v
= tcg_temp_new_i64();
1572 TCGv_i32 s
= tcg_const_i32(32);
1573 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1574 tcg_gen_andi_i32(s
, s
, 0x3f);
1575 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1576 gen_shift_reg(shl
, s
);
1582 gen_window_check2(dc
, RRR_R
, RRR_T
);
1584 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1586 TCGv_i64 v
= tcg_temp_new_i64();
1587 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1592 #undef gen_shift_reg
1595 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1596 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1598 TCGv_i32 v1
= tcg_temp_new_i32();
1599 TCGv_i32 v2
= tcg_temp_new_i32();
1600 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1601 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1602 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1609 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1610 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1612 TCGv_i32 v1
= tcg_temp_new_i32();
1613 TCGv_i32 v2
= tcg_temp_new_i32();
1614 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1615 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1616 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1622 default: /*reserved*/
1630 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1634 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1635 int label
= gen_new_label();
1636 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1637 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1638 gen_set_label(label
);
1642 #define BOOLEAN_LOGIC(fn, r, s, t) \
1644 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1645 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1646 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1648 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1649 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1650 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1651 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1652 tcg_temp_free(tmp1); \
1653 tcg_temp_free(tmp2); \
1657 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1661 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1665 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1669 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1673 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1676 #undef BOOLEAN_LOGIC
1679 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1680 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1685 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1687 TCGv lo
= tcg_temp_new();
1690 tcg_gen_mulu2_i32(lo
, cpu_R
[RRR_R
],
1691 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1693 tcg_gen_muls2_i32(lo
, cpu_R
[RRR_R
],
1694 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1701 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1707 int label1
= gen_new_label();
1708 int label2
= gen_new_label();
1710 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1712 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1714 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1715 OP2
== 13 ? 0x80000000 : 0);
1717 gen_set_label(label1
);
1719 tcg_gen_div_i32(cpu_R
[RRR_R
],
1720 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1722 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1723 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1725 gen_set_label(label2
);
1730 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1733 default: /*reserved*/
1742 if (gen_check_sr(dc
, RSR_SR
, SR_R
)) {
1744 gen_check_privilege(dc
);
1746 gen_window_check1(dc
, RRR_T
);
1747 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1752 if (gen_check_sr(dc
, RSR_SR
, SR_W
)) {
1754 gen_check_privilege(dc
);
1756 gen_window_check1(dc
, RRR_T
);
1757 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1762 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1763 gen_window_check2(dc
, RRR_R
, RRR_S
);
1765 int shift
= 24 - RRR_T
;
1768 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1769 } else if (shift
== 16) {
1770 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1772 TCGv_i32 tmp
= tcg_temp_new_i32();
1773 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1774 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1781 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1782 gen_window_check2(dc
, RRR_R
, RRR_S
);
1784 TCGv_i32 tmp1
= tcg_temp_new_i32();
1785 TCGv_i32 tmp2
= tcg_temp_new_i32();
1786 TCGv_i32 zero
= tcg_const_i32(0);
1788 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1789 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1790 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1792 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1793 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1795 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1796 cpu_R
[RRR_S
], tmp1
);
1797 tcg_temp_free(tmp1
);
1798 tcg_temp_free(tmp2
);
1799 tcg_temp_free(zero
);
1807 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1808 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1810 static const TCGCond cond
[] = {
1816 tcg_gen_movcond_i32(cond
[OP2
- 4], cpu_R
[RRR_R
],
1817 cpu_R
[RRR_S
], cpu_R
[RRR_T
],
1818 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1826 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1828 static const TCGCond cond
[] = {
1834 TCGv_i32 zero
= tcg_const_i32(0);
1836 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1837 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1838 tcg_temp_free(zero
);
1844 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1845 gen_window_check2(dc
, RRR_R
, RRR_S
);
1847 TCGv_i32 zero
= tcg_const_i32(0);
1848 TCGv_i32 tmp
= tcg_temp_new_i32();
1850 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1851 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1852 cpu_R
[RRR_R
], tmp
, zero
,
1853 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1856 tcg_temp_free(zero
);
1861 gen_window_check1(dc
, RRR_R
);
1863 int st
= (RRR_S
<< 4) + RRR_T
;
1864 if (uregnames
[st
].name
) {
1865 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1867 qemu_log("RUR %d not implemented, ", st
);
1874 gen_window_check1(dc
, RRR_T
);
1875 if (uregnames
[RSR_SR
].name
) {
1876 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1878 qemu_log("WUR %d not implemented, ", RSR_SR
);
1888 gen_window_check2(dc
, RRR_R
, RRR_T
);
1890 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1891 int maskimm
= (1 << (OP2
+ 1)) - 1;
1893 TCGv_i32 tmp
= tcg_temp_new_i32();
1894 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1895 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1914 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1915 gen_window_check2(dc
, RRR_S
, RRR_T
);
1916 gen_check_cpenable(dc
, 0);
1918 TCGv_i32 addr
= tcg_temp_new_i32();
1919 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1920 gen_load_store_alignment(dc
, 2, addr
, false);
1922 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1924 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1927 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1929 tcg_temp_free(addr
);
1933 default: /*reserved*/
1940 gen_window_check2(dc
, RRR_S
, RRR_T
);
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_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1950 tcg_temp_free(addr
);
1955 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1956 gen_check_privilege(dc
);
1958 TCGv_i32 addr
= tcg_temp_new_i32();
1959 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1960 (0xffffffc0 | (RRR_R
<< 2)));
1961 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1962 tcg_temp_free(addr
);
1973 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1976 gen_check_cpenable(dc
, 0);
1977 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
1978 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1982 gen_check_cpenable(dc
, 0);
1983 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
1984 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1988 gen_check_cpenable(dc
, 0);
1989 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
1990 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1994 gen_check_cpenable(dc
, 0);
1995 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
1996 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2000 gen_check_cpenable(dc
, 0);
2001 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
2002 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
2005 case 8: /*ROUND.Sf*/
2006 case 9: /*TRUNC.Sf*/
2007 case 10: /*FLOOR.Sf*/
2008 case 11: /*CEIL.Sf*/
2009 case 14: /*UTRUNC.Sf*/
2010 gen_window_check1(dc
, RRR_R
);
2011 gen_check_cpenable(dc
, 0);
2013 static const unsigned rounding_mode_const
[] = {
2014 float_round_nearest_even
,
2015 float_round_to_zero
,
2018 [6] = float_round_to_zero
,
2020 TCGv_i32 rounding_mode
= tcg_const_i32(
2021 rounding_mode_const
[OP2
& 7]);
2022 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2025 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2026 rounding_mode
, scale
);
2028 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2029 rounding_mode
, scale
);
2032 tcg_temp_free(rounding_mode
);
2033 tcg_temp_free(scale
);
2037 case 12: /*FLOAT.Sf*/
2038 case 13: /*UFLOAT.Sf*/
2039 gen_window_check1(dc
, RRR_S
);
2040 gen_check_cpenable(dc
, 0);
2042 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2045 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2046 cpu_R
[RRR_S
], scale
);
2048 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2049 cpu_R
[RRR_S
], scale
);
2051 tcg_temp_free(scale
);
2058 gen_check_cpenable(dc
, 0);
2059 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2063 gen_check_cpenable(dc
, 0);
2064 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2068 gen_window_check1(dc
, RRR_R
);
2069 gen_check_cpenable(dc
, 0);
2070 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2074 gen_window_check1(dc
, RRR_S
);
2075 gen_check_cpenable(dc
, 0);
2076 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2080 gen_check_cpenable(dc
, 0);
2081 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2084 default: /*reserved*/
2090 default: /*reserved*/
2097 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2099 #define gen_compare(rel, br, a, b) \
2101 TCGv_i32 bit = tcg_const_i32(1 << br); \
2103 gen_check_cpenable(dc, 0); \
2104 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2105 tcg_temp_free(bit); \
2110 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2114 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2118 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2122 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2126 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2130 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2134 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2139 case 8: /*MOVEQZ.Sf*/
2140 case 9: /*MOVNEZ.Sf*/
2141 case 10: /*MOVLTZ.Sf*/
2142 case 11: /*MOVGEZ.Sf*/
2143 gen_window_check1(dc
, RRR_T
);
2144 gen_check_cpenable(dc
, 0);
2146 static const TCGCond cond
[] = {
2152 TCGv_i32 zero
= tcg_const_i32(0);
2154 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2155 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2156 tcg_temp_free(zero
);
2160 case 12: /*MOVF.Sf*/
2161 case 13: /*MOVT.Sf*/
2162 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2163 gen_check_cpenable(dc
, 0);
2165 TCGv_i32 zero
= tcg_const_i32(0);
2166 TCGv_i32 tmp
= tcg_temp_new_i32();
2168 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2169 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2170 cpu_FR
[RRR_R
], tmp
, zero
,
2171 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2174 tcg_temp_free(zero
);
2178 default: /*reserved*/
2184 default: /*reserved*/
2191 gen_window_check1(dc
, RRR_T
);
2193 TCGv_i32 tmp
= tcg_const_i32(
2194 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2195 0 : ((dc
->pc
+ 3) & ~3)) +
2196 (0xfffc0000 | (RI16_IMM16
<< 2)));
2198 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2199 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2201 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2207 #define gen_load_store(type, shift) do { \
2208 TCGv_i32 addr = tcg_temp_new_i32(); \
2209 gen_window_check2(dc, RRI8_S, RRI8_T); \
2210 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2212 gen_load_store_alignment(dc, shift, addr, false); \
2214 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2215 tcg_temp_free(addr); \
2220 gen_load_store(ld8u
, 0);
2224 gen_load_store(ld16u
, 1);
2228 gen_load_store(ld32u
, 2);
2232 gen_load_store(st8
, 0);
2236 gen_load_store(st16
, 1);
2240 gen_load_store(st32
, 2);
2243 #define gen_dcache_hit_test(w, shift) do { \
2244 TCGv_i32 addr = tcg_temp_new_i32(); \
2245 TCGv_i32 res = tcg_temp_new_i32(); \
2246 gen_window_check1(dc, RRI##w##_S); \
2247 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2248 RRI##w##_IMM##w << shift); \
2249 tcg_gen_qemu_ld8u(res, addr, dc->cring); \
2250 tcg_temp_free(addr); \
2251 tcg_temp_free(res); \
2254 #define gen_dcache_hit_test4() gen_dcache_hit_test(4, 4)
2255 #define gen_dcache_hit_test8() gen_dcache_hit_test(8, 2)
2259 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2264 gen_window_check1(dc
, RRI8_S
);
2268 gen_window_check1(dc
, RRI8_S
);
2272 gen_window_check1(dc
, RRI8_S
);
2276 gen_window_check1(dc
, RRI8_S
);
2280 gen_dcache_hit_test8();
2284 gen_dcache_hit_test8();
2288 gen_check_privilege(dc
);
2289 gen_dcache_hit_test8();
2293 gen_check_privilege(dc
);
2294 gen_window_check1(dc
, RRI8_S
);
2300 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2301 gen_check_privilege(dc
);
2302 gen_dcache_hit_test4();
2306 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2307 gen_check_privilege(dc
);
2308 gen_dcache_hit_test4();
2312 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2313 gen_check_privilege(dc
);
2314 gen_window_check1(dc
, RRI4_S
);
2318 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2319 gen_check_privilege(dc
);
2320 gen_window_check1(dc
, RRI4_S
);
2324 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2325 gen_check_privilege(dc
);
2326 gen_window_check1(dc
, RRI4_S
);
2329 default: /*reserved*/
2336 #undef gen_dcache_hit_test
2337 #undef gen_dcache_hit_test4
2338 #undef gen_dcache_hit_test8
2340 #define gen_icache_hit_test(w, shift) do { \
2341 TCGv_i32 addr = tcg_temp_new_i32(); \
2342 gen_window_check1(dc, RRI##w##_S); \
2343 tcg_gen_movi_i32(cpu_pc, dc->pc); \
2344 tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \
2345 RRI##w##_IMM##w << shift); \
2346 gen_helper_itlb_hit_test(cpu_env, addr); \
2347 tcg_temp_free(addr); \
2350 #define gen_icache_hit_test4() gen_icache_hit_test(4, 4)
2351 #define gen_icache_hit_test8() gen_icache_hit_test(8, 2)
2354 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2355 gen_window_check1(dc
, RRI8_S
);
2361 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2362 gen_check_privilege(dc
);
2363 gen_icache_hit_test4();
2367 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2368 gen_check_privilege(dc
);
2369 gen_icache_hit_test4();
2373 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2374 gen_check_privilege(dc
);
2375 gen_window_check1(dc
, RRI4_S
);
2378 default: /*reserved*/
2385 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2386 gen_icache_hit_test8();
2390 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2391 gen_check_privilege(dc
);
2392 gen_window_check1(dc
, RRI8_S
);
2395 default: /*reserved*/
2401 #undef gen_icache_hit_test
2402 #undef gen_icache_hit_test4
2403 #undef gen_icache_hit_test8
2406 gen_load_store(ld16s
, 1);
2408 #undef gen_load_store
2411 gen_window_check1(dc
, RRI8_T
);
2412 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2413 RRI8_IMM8
| (RRI8_S
<< 8) |
2414 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2417 #define gen_load_store_no_hw_align(type) do { \
2418 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2419 gen_window_check2(dc, RRI8_S, RRI8_T); \
2420 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2421 gen_load_store_alignment(dc, 2, addr, true); \
2422 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2423 tcg_temp_free(addr); \
2427 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2428 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2432 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2433 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2437 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2438 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
<< 8);
2441 case 14: /*S32C1Iy*/
2442 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2443 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2445 int label
= gen_new_label();
2446 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2447 TCGv_i32 addr
= tcg_temp_local_new_i32();
2450 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2451 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2452 gen_load_store_alignment(dc
, 2, addr
, true);
2454 gen_advance_ccount(dc
);
2455 tpc
= tcg_const_i32(dc
->pc
);
2456 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2457 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2458 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2459 cpu_SR
[SCOMPARE1
], label
);
2461 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2463 gen_set_label(label
);
2465 tcg_temp_free(addr
);
2471 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2472 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2474 #undef gen_load_store_no_hw_align
2476 default: /*reserved*/
2488 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2489 gen_window_check1(dc
, RRI8_S
);
2490 gen_check_cpenable(dc
, 0);
2492 TCGv_i32 addr
= tcg_temp_new_i32();
2493 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2494 gen_load_store_alignment(dc
, 2, addr
, false);
2496 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2498 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2501 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2503 tcg_temp_free(addr
);
2507 default: /*reserved*/
2514 HAS_OPTION(XTENSA_OPTION_MAC16
);
2523 bool is_m1_sr
= (OP2
& 0x3) == 2;
2524 bool is_m2_sr
= (OP2
& 0xc) == 0;
2525 uint32_t ld_offset
= 0;
2532 case 0: /*MACI?/MACC?*/
2534 ld_offset
= (OP2
& 1) ? -4 : 4;
2536 if (OP2
>= 8) { /*MACI/MACC*/
2537 if (OP1
== 0) { /*LDINC/LDDEC*/
2542 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2547 case 2: /*MACD?/MACA?*/
2548 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2554 if (op
!= MAC16_NONE
) {
2556 gen_window_check1(dc
, RRR_S
);
2559 gen_window_check1(dc
, RRR_T
);
2564 TCGv_i32 vaddr
= tcg_temp_new_i32();
2565 TCGv_i32 mem32
= tcg_temp_new_i32();
2568 gen_window_check1(dc
, RRR_S
);
2569 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2570 gen_load_store_alignment(dc
, 2, vaddr
, false);
2571 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2573 if (op
!= MAC16_NONE
) {
2574 TCGv_i32 m1
= gen_mac16_m(
2575 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2576 OP1
& 1, op
== MAC16_UMUL
);
2577 TCGv_i32 m2
= gen_mac16_m(
2578 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2579 OP1
& 2, op
== MAC16_UMUL
);
2581 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2582 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2583 if (op
== MAC16_UMUL
) {
2584 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2586 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2589 TCGv_i32 lo
= tcg_temp_new_i32();
2590 TCGv_i32 hi
= tcg_temp_new_i32();
2592 tcg_gen_mul_i32(lo
, m1
, m2
);
2593 tcg_gen_sari_i32(hi
, lo
, 31);
2594 if (op
== MAC16_MULA
) {
2595 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2596 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2599 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2600 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2603 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2605 tcg_temp_free_i32(lo
);
2606 tcg_temp_free_i32(hi
);
2612 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2613 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2615 tcg_temp_free(vaddr
);
2616 tcg_temp_free(mem32
);
2624 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2625 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2631 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2632 gen_window_check1(dc
, CALL_N
<< 2);
2633 gen_callwi(dc
, CALL_N
,
2634 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2642 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2646 gen_window_check1(dc
, BRI12_S
);
2648 static const TCGCond cond
[] = {
2649 TCG_COND_EQ
, /*BEQZ*/
2650 TCG_COND_NE
, /*BNEZ*/
2651 TCG_COND_LT
, /*BLTZ*/
2652 TCG_COND_GE
, /*BGEZ*/
2655 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2656 4 + BRI12_IMM12_SE
);
2661 gen_window_check1(dc
, BRI8_S
);
2663 static const TCGCond cond
[] = {
2664 TCG_COND_EQ
, /*BEQI*/
2665 TCG_COND_NE
, /*BNEI*/
2666 TCG_COND_LT
, /*BLTI*/
2667 TCG_COND_GE
, /*BGEI*/
2670 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2671 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2678 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2680 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2681 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2682 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2683 gen_advance_ccount(dc
);
2684 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2688 reset_used_window(dc
);
2696 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2698 TCGv_i32 tmp
= tcg_temp_new_i32();
2699 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2701 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2702 tmp
, 0, 4 + RRI8_IMM8_SE
);
2709 case 10: /*LOOPGTZ*/
2710 HAS_OPTION(XTENSA_OPTION_LOOP
);
2711 gen_window_check1(dc
, RRI8_S
);
2713 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2714 TCGv_i32 tmp
= tcg_const_i32(lend
);
2716 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2717 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2718 gen_helper_wsr_lend(cpu_env
, tmp
);
2722 int label
= gen_new_label();
2723 tcg_gen_brcondi_i32(
2724 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2725 cpu_R
[RRI8_S
], 0, label
);
2726 gen_jumpi(dc
, lend
, 1);
2727 gen_set_label(label
);
2730 gen_jumpi(dc
, dc
->next_pc
, 0);
2734 default: /*reserved*/
2743 gen_window_check1(dc
, BRI8_S
);
2744 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2745 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2755 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2757 switch (RRI8_R
& 7) {
2758 case 0: /*BNONE*/ /*BANY*/
2759 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2761 TCGv_i32 tmp
= tcg_temp_new_i32();
2762 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2763 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2768 case 1: /*BEQ*/ /*BNE*/
2769 case 2: /*BLT*/ /*BGE*/
2770 case 3: /*BLTU*/ /*BGEU*/
2771 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2773 static const TCGCond cond
[] = {
2779 [11] = TCG_COND_GEU
,
2781 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2786 case 4: /*BALL*/ /*BNALL*/
2787 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2789 TCGv_i32 tmp
= tcg_temp_new_i32();
2790 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2791 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2797 case 5: /*BBC*/ /*BBS*/
2798 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2800 #ifdef TARGET_WORDS_BIGENDIAN
2801 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2803 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2805 TCGv_i32 tmp
= tcg_temp_new_i32();
2806 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2807 #ifdef TARGET_WORDS_BIGENDIAN
2808 tcg_gen_shr_i32(bit
, bit
, tmp
);
2810 tcg_gen_shl_i32(bit
, bit
, tmp
);
2812 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2813 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2819 case 6: /*BBCI*/ /*BBSI*/
2821 gen_window_check1(dc
, RRI8_S
);
2823 TCGv_i32 tmp
= tcg_temp_new_i32();
2824 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2825 #ifdef TARGET_WORDS_BIGENDIAN
2826 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2828 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2830 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2839 #define gen_narrow_load_store(type) do { \
2840 TCGv_i32 addr = tcg_temp_new_i32(); \
2841 gen_window_check2(dc, RRRN_S, RRRN_T); \
2842 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2843 gen_load_store_alignment(dc, 2, addr, false); \
2844 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2845 tcg_temp_free(addr); \
2849 gen_narrow_load_store(ld32u
);
2853 gen_narrow_load_store(st32
);
2855 #undef gen_narrow_load_store
2858 gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
);
2859 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2862 case 11: /*ADDI.Nn*/
2863 gen_window_check2(dc
, RRRN_R
, RRRN_S
);
2864 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], RRRN_T
? RRRN_T
: -1);
2868 gen_window_check1(dc
, RRRN_S
);
2869 if (RRRN_T
< 8) { /*MOVI.Nn*/
2870 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2871 RRRN_R
| (RRRN_T
<< 4) |
2872 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2873 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2874 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2876 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2877 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2884 gen_window_check2(dc
, RRRN_S
, RRRN_T
);
2885 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2891 gen_jump(dc
, cpu_R
[0]);
2895 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2897 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2898 gen_advance_ccount(dc
);
2899 gen_helper_retw(tmp
, cpu_env
, tmp
);
2905 case 2: /*BREAK.Nn*/
2906 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2908 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2916 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2919 default: /*reserved*/
2925 default: /*reserved*/
2931 default: /*reserved*/
2936 if (dc
->is_jmp
== DISAS_NEXT
) {
2937 gen_check_loop_end(dc
, 0);
2939 dc
->pc
= dc
->next_pc
;
2944 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2945 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2949 static void check_breakpoint(CPUXtensaState
*env
, DisasContext
*dc
)
2951 CPUState
*cs
= CPU(xtensa_env_get_cpu(env
));
2954 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
2955 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
2956 if (bp
->pc
== dc
->pc
) {
2957 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2958 gen_exception(dc
, EXCP_DEBUG
);
2959 dc
->is_jmp
= DISAS_UPDATE
;
2965 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
2969 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
2970 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
2971 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
2972 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
2979 void gen_intermediate_code_internal(XtensaCPU
*cpu
,
2980 TranslationBlock
*tb
, bool search_pc
)
2982 CPUState
*cs
= CPU(cpu
);
2983 CPUXtensaState
*env
= &cpu
->env
;
2987 uint16_t *gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
2988 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2989 uint32_t pc_start
= tb
->pc
;
2990 uint32_t next_page_start
=
2991 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2993 if (max_insns
== 0) {
2994 max_insns
= CF_COUNT_MASK
;
2997 dc
.config
= env
->config
;
2998 dc
.singlestep_enabled
= cs
->singlestep_enabled
;
3001 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
3002 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
3003 dc
.lbeg
= env
->sregs
[LBEG
];
3004 dc
.lend
= env
->sregs
[LEND
];
3005 dc
.is_jmp
= DISAS_NEXT
;
3006 dc
.ccount_delta
= 0;
3007 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
3008 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
3009 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
3010 XTENSA_TBFLAG_CPENABLE_SHIFT
;
3013 init_sar_tracker(&dc
);
3014 reset_used_window(&dc
);
3016 dc
.next_icount
= tcg_temp_local_new_i32();
3021 if (tb
->flags
& XTENSA_TBFLAG_EXCEPTION
) {
3022 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3023 gen_exception(&dc
, EXCP_DEBUG
);
3027 check_breakpoint(env
, &dc
);
3030 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3034 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
3037 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
3038 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
3039 tcg_ctx
.gen_opc_icount
[lj
] = insn_count
;
3042 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
3043 tcg_gen_debug_insn_start(dc
.pc
);
3048 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
3053 int label
= gen_new_label();
3055 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
3056 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
3057 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
3059 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
3061 gen_set_label(label
);
3065 gen_ibreak_check(env
, &dc
);
3068 disas_xtensa_insn(env
, &dc
);
3071 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
3073 if (cs
->singlestep_enabled
) {
3074 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
3075 gen_exception(&dc
, EXCP_DEBUG
);
3078 } while (dc
.is_jmp
== DISAS_NEXT
&&
3079 insn_count
< max_insns
&&
3080 dc
.pc
< next_page_start
&&
3081 tcg_ctx
.gen_opc_ptr
< gen_opc_end
);
3084 reset_sar_tracker(&dc
);
3086 tcg_temp_free(dc
.next_icount
);
3089 if (tb
->cflags
& CF_LAST_IO
) {
3093 if (dc
.is_jmp
== DISAS_NEXT
) {
3094 gen_jumpi(&dc
, dc
.pc
, 0);
3096 gen_tb_end(tb
, insn_count
);
3097 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
3100 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3101 qemu_log("----------------\n");
3102 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3103 log_target_disas(env
, pc_start
, dc
.pc
- pc_start
, 0);
3108 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3109 memset(tcg_ctx
.gen_opc_instr_start
+ lj
+ 1, 0,
3110 (j
- lj
) * sizeof(tcg_ctx
.gen_opc_instr_start
[0]));
3112 tb
->size
= dc
.pc
- pc_start
;
3113 tb
->icount
= insn_count
;
3117 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3119 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, false);
3122 void gen_intermediate_code_pc(CPUXtensaState
*env
, TranslationBlock
*tb
)
3124 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, true);
3127 void xtensa_cpu_dump_state(CPUState
*cs
, FILE *f
,
3128 fprintf_function cpu_fprintf
, int flags
)
3130 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
3131 CPUXtensaState
*env
= &cpu
->env
;
3134 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3136 for (i
= j
= 0; i
< 256; ++i
) {
3137 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3138 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3139 (j
++ % 4) == 3 ? '\n' : ' ');
3143 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3145 for (i
= j
= 0; i
< 256; ++i
) {
3146 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3147 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3148 (j
++ % 4) == 3 ? '\n' : ' ');
3152 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3154 for (i
= 0; i
< 16; ++i
) {
3155 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3156 (i
% 4) == 3 ? '\n' : ' ');
3159 cpu_fprintf(f
, "\n");
3161 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3162 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3163 (i
% 4) == 3 ? '\n' : ' ');
3166 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3167 cpu_fprintf(f
, "\n");
3169 for (i
= 0; i
< 16; ++i
) {
3170 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3171 float32_val(env
->fregs
[i
]),
3172 *(float *)&env
->fregs
[i
], (i
% 2) == 1 ? '\n' : ' ');
3177 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
, int pc_pos
)
3179 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];