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.
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 "gen-icount.h"
81 static const char * const sregnames
[256] = {
87 [LITBASE
] = "LITBASE",
88 [SCOMPARE1
] = "SCOMPARE1",
95 [WINDOW_BASE
] = "WINDOW_BASE",
96 [WINDOW_START
] = "WINDOW_START",
97 [PTEVADDR
] = "PTEVADDR",
99 [ITLBCFG
] = "ITLBCFG",
100 [DTLBCFG
] = "DTLBCFG",
101 [IBREAKENABLE
] = "IBREAKENABLE",
102 [IBREAKA
] = "IBREAKA0",
103 [IBREAKA
+ 1] = "IBREAKA1",
104 [DBREAKA
] = "DBREAKA0",
105 [DBREAKA
+ 1] = "DBREAKA1",
106 [DBREAKC
] = "DBREAKC0",
107 [DBREAKC
+ 1] = "DBREAKC1",
122 [EXCSAVE1
] = "EXCSAVE1",
123 [EXCSAVE1
+ 1] = "EXCSAVE2",
124 [EXCSAVE1
+ 2] = "EXCSAVE3",
125 [EXCSAVE1
+ 3] = "EXCSAVE4",
126 [EXCSAVE1
+ 4] = "EXCSAVE5",
127 [EXCSAVE1
+ 5] = "EXCSAVE6",
128 [EXCSAVE1
+ 6] = "EXCSAVE7",
129 [CPENABLE
] = "CPENABLE",
131 [INTCLEAR
] = "INTCLEAR",
132 [INTENABLE
] = "INTENABLE",
134 [VECBASE
] = "VECBASE",
135 [EXCCAUSE
] = "EXCCAUSE",
136 [DEBUGCAUSE
] = "DEBUGCAUSE",
140 [ICOUNTLEVEL
] = "ICOUNTLEVEL",
141 [EXCVADDR
] = "EXCVADDR",
142 [CCOMPARE
] = "CCOMPARE0",
143 [CCOMPARE
+ 1] = "CCOMPARE1",
144 [CCOMPARE
+ 2] = "CCOMPARE2",
147 static const char * const uregnames
[256] = {
148 [THREADPTR
] = "THREADPTR",
153 void xtensa_translate_init(void)
155 static const char * const regnames
[] = {
156 "ar0", "ar1", "ar2", "ar3",
157 "ar4", "ar5", "ar6", "ar7",
158 "ar8", "ar9", "ar10", "ar11",
159 "ar12", "ar13", "ar14", "ar15",
161 static const char * const fregnames
[] = {
162 "f0", "f1", "f2", "f3",
163 "f4", "f5", "f6", "f7",
164 "f8", "f9", "f10", "f11",
165 "f12", "f13", "f14", "f15",
169 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
170 cpu_pc
= tcg_global_mem_new_i32(TCG_AREG0
,
171 offsetof(CPUXtensaState
, pc
), "pc");
173 for (i
= 0; i
< 16; i
++) {
174 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
175 offsetof(CPUXtensaState
, regs
[i
]),
179 for (i
= 0; i
< 16; i
++) {
180 cpu_FR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
181 offsetof(CPUXtensaState
, fregs
[i
]),
185 for (i
= 0; i
< 256; ++i
) {
187 cpu_SR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
188 offsetof(CPUXtensaState
, sregs
[i
]),
193 for (i
= 0; i
< 256; ++i
) {
195 cpu_UR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
196 offsetof(CPUXtensaState
, uregs
[i
]),
204 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
206 return xtensa_option_bits_enabled(dc
->config
, opt
);
209 static inline bool option_enabled(DisasContext
*dc
, int opt
)
211 return xtensa_option_enabled(dc
->config
, opt
);
214 static void init_litbase(DisasContext
*dc
)
216 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
217 dc
->litbase
= tcg_temp_local_new_i32();
218 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
222 static void reset_litbase(DisasContext
*dc
)
224 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
225 tcg_temp_free(dc
->litbase
);
229 static void init_sar_tracker(DisasContext
*dc
)
231 dc
->sar_5bit
= false;
232 dc
->sar_m32_5bit
= false;
233 dc
->sar_m32_allocated
= false;
236 static void reset_sar_tracker(DisasContext
*dc
)
238 if (dc
->sar_m32_allocated
) {
239 tcg_temp_free(dc
->sar_m32
);
243 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
245 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
246 if (dc
->sar_m32_5bit
) {
247 tcg_gen_discard_i32(dc
->sar_m32
);
250 dc
->sar_m32_5bit
= false;
253 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
255 TCGv_i32 tmp
= tcg_const_i32(32);
256 if (!dc
->sar_m32_allocated
) {
257 dc
->sar_m32
= tcg_temp_local_new_i32();
258 dc
->sar_m32_allocated
= true;
260 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
261 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
262 dc
->sar_5bit
= false;
263 dc
->sar_m32_5bit
= true;
267 static void gen_advance_ccount(DisasContext
*dc
)
269 if (dc
->ccount_delta
> 0) {
270 TCGv_i32 tmp
= tcg_const_i32(dc
->ccount_delta
);
271 dc
->ccount_delta
= 0;
272 gen_helper_advance_ccount(cpu_env
, tmp
);
277 static void reset_used_window(DisasContext
*dc
)
282 static void gen_exception(DisasContext
*dc
, int excp
)
284 TCGv_i32 tmp
= tcg_const_i32(excp
);
285 gen_advance_ccount(dc
);
286 gen_helper_exception(cpu_env
, tmp
);
290 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
292 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
293 TCGv_i32 tcause
= tcg_const_i32(cause
);
294 gen_advance_ccount(dc
);
295 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
297 tcg_temp_free(tcause
);
298 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
299 cause
== SYSCALL_CAUSE
) {
300 dc
->is_jmp
= DISAS_UPDATE
;
304 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
307 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
308 TCGv_i32 tcause
= tcg_const_i32(cause
);
309 gen_advance_ccount(dc
);
310 gen_helper_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
312 tcg_temp_free(tcause
);
315 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
317 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
318 TCGv_i32 tcause
= tcg_const_i32(cause
);
319 gen_advance_ccount(dc
);
320 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
322 tcg_temp_free(tcause
);
323 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
324 dc
->is_jmp
= DISAS_UPDATE
;
328 static void gen_check_privilege(DisasContext
*dc
)
331 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
332 dc
->is_jmp
= DISAS_UPDATE
;
336 static void gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
338 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
339 !(dc
->cpenable
& (1 << cp
))) {
340 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
341 dc
->is_jmp
= DISAS_UPDATE
;
345 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
347 tcg_gen_mov_i32(cpu_pc
, dest
);
348 gen_advance_ccount(dc
);
350 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
->next_icount
);
352 if (dc
->singlestep_enabled
) {
353 gen_exception(dc
, EXCP_DEBUG
);
356 tcg_gen_goto_tb(slot
);
357 tcg_gen_exit_tb((tcg_target_long
)dc
->tb
+ slot
);
362 dc
->is_jmp
= DISAS_UPDATE
;
365 static void gen_jump(DisasContext
*dc
, TCGv dest
)
367 gen_jump_slot(dc
, dest
, -1);
370 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
372 TCGv_i32 tmp
= tcg_const_i32(dest
);
373 if (((dc
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
376 gen_jump_slot(dc
, tmp
, slot
);
380 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
383 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
385 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
386 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
387 tcg_temp_free(tcallinc
);
388 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
389 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
390 gen_jump_slot(dc
, dest
, slot
);
393 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
395 gen_callw_slot(dc
, callinc
, dest
, -1);
398 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
400 TCGv_i32 tmp
= tcg_const_i32(dest
);
401 if (((dc
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
404 gen_callw_slot(dc
, callinc
, tmp
, slot
);
408 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
410 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
411 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
412 dc
->next_pc
== dc
->lend
) {
413 int label
= gen_new_label();
415 gen_advance_ccount(dc
);
416 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
417 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
418 gen_jumpi(dc
, dc
->lbeg
, slot
);
419 gen_set_label(label
);
420 gen_jumpi(dc
, dc
->next_pc
, -1);
426 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
428 if (!gen_check_loop_end(dc
, slot
)) {
429 gen_jumpi(dc
, dc
->next_pc
, slot
);
433 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
434 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
436 int label
= gen_new_label();
438 gen_advance_ccount(dc
);
439 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
440 gen_jumpi_check_loop_end(dc
, 0);
441 gen_set_label(label
);
442 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
445 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
446 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
448 TCGv_i32 tmp
= tcg_const_i32(t1
);
449 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
453 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
455 gen_advance_ccount(dc
);
456 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
459 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
461 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
462 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
463 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
466 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
468 static void (* const rsr_handler
[256])(DisasContext
*dc
,
469 TCGv_i32 d
, uint32_t sr
) = {
470 [CCOUNT
] = gen_rsr_ccount
,
471 [PTEVADDR
] = gen_rsr_ptevaddr
,
475 if (rsr_handler
[sr
]) {
476 rsr_handler
[sr
](dc
, d
, sr
);
478 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
481 qemu_log("RSR %d not implemented, ", sr
);
485 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
487 gen_helper_wsr_lbeg(cpu_env
, s
);
488 gen_jumpi_check_loop_end(dc
, 0);
491 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
493 gen_helper_wsr_lend(cpu_env
, s
);
494 gen_jumpi_check_loop_end(dc
, 0);
497 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
499 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
500 if (dc
->sar_m32_5bit
) {
501 tcg_gen_discard_i32(dc
->sar_m32
);
503 dc
->sar_5bit
= false;
504 dc
->sar_m32_5bit
= false;
507 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
509 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
512 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
514 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
515 /* This can change tb->flags, so exit tb */
516 gen_jumpi_check_loop_end(dc
, -1);
519 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
521 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
524 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
526 gen_helper_wsr_windowbase(cpu_env
, v
);
527 reset_used_window(dc
);
530 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
532 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
533 reset_used_window(dc
);
536 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
538 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
541 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
543 gen_helper_wsr_rasid(cpu_env
, v
);
544 /* This can change tb->flags, so exit tb */
545 gen_jumpi_check_loop_end(dc
, -1);
548 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
550 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
553 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
555 gen_helper_wsr_ibreakenable(cpu_env
, v
);
556 gen_jumpi_check_loop_end(dc
, 0);
559 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
561 unsigned id
= sr
- IBREAKA
;
563 if (id
< dc
->config
->nibreak
) {
564 TCGv_i32 tmp
= tcg_const_i32(id
);
565 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
567 gen_jumpi_check_loop_end(dc
, 0);
571 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
573 unsigned id
= sr
- DBREAKA
;
575 if (id
< dc
->config
->ndbreak
) {
576 TCGv_i32 tmp
= tcg_const_i32(id
);
577 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
582 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
584 unsigned id
= sr
- DBREAKC
;
586 if (id
< dc
->config
->ndbreak
) {
587 TCGv_i32 tmp
= tcg_const_i32(id
);
588 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
593 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
595 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
596 /* This can change tb->flags, so exit tb */
597 gen_jumpi_check_loop_end(dc
, -1);
600 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
602 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
603 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
604 gen_helper_check_interrupts(cpu_env
);
605 gen_jumpi_check_loop_end(dc
, 0);
608 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
610 TCGv_i32 tmp
= tcg_temp_new_i32();
612 tcg_gen_andi_i32(tmp
, v
,
613 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
614 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
615 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
616 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
618 gen_helper_check_interrupts(cpu_env
);
621 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
623 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
624 gen_helper_check_interrupts(cpu_env
);
625 gen_jumpi_check_loop_end(dc
, 0);
628 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
630 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
631 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
633 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
636 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
637 reset_used_window(dc
);
638 gen_helper_check_interrupts(cpu_env
);
639 /* This can change mmu index and tb->flags, so exit tb */
640 gen_jumpi_check_loop_end(dc
, -1);
643 static void gen_wsr_debugcause(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
647 static void gen_wsr_prid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
651 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
654 tcg_gen_mov_i32(dc
->next_icount
, v
);
656 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
660 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
662 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
663 /* This can change tb->flags, so exit tb */
664 gen_jumpi_check_loop_end(dc
, -1);
667 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
669 uint32_t id
= sr
- CCOMPARE
;
670 if (id
< dc
->config
->nccompare
) {
671 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
672 gen_advance_ccount(dc
);
673 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
674 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
675 gen_helper_check_interrupts(cpu_env
);
679 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
681 static void (* const wsr_handler
[256])(DisasContext
*dc
,
682 uint32_t sr
, TCGv_i32 v
) = {
683 [LBEG
] = gen_wsr_lbeg
,
684 [LEND
] = gen_wsr_lend
,
687 [LITBASE
] = gen_wsr_litbase
,
688 [ACCHI
] = gen_wsr_acchi
,
689 [WINDOW_BASE
] = gen_wsr_windowbase
,
690 [WINDOW_START
] = gen_wsr_windowstart
,
691 [PTEVADDR
] = gen_wsr_ptevaddr
,
692 [RASID
] = gen_wsr_rasid
,
693 [ITLBCFG
] = gen_wsr_tlbcfg
,
694 [DTLBCFG
] = gen_wsr_tlbcfg
,
695 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
696 [IBREAKA
] = gen_wsr_ibreaka
,
697 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
698 [DBREAKA
] = gen_wsr_dbreaka
,
699 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
700 [DBREAKC
] = gen_wsr_dbreakc
,
701 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
702 [CPENABLE
] = gen_wsr_cpenable
,
703 [INTSET
] = gen_wsr_intset
,
704 [INTCLEAR
] = gen_wsr_intclear
,
705 [INTENABLE
] = gen_wsr_intenable
,
707 [DEBUGCAUSE
] = gen_wsr_debugcause
,
708 [PRID
] = gen_wsr_prid
,
709 [ICOUNT
] = gen_wsr_icount
,
710 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
711 [CCOMPARE
] = gen_wsr_ccompare
,
712 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
713 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
717 if (wsr_handler
[sr
]) {
718 wsr_handler
[sr
](dc
, sr
, s
);
720 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
723 qemu_log("WSR %d not implemented, ", sr
);
727 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
731 gen_helper_wur_fcr(cpu_env
, s
);
735 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
739 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
744 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
745 TCGv_i32 addr
, bool no_hw_alignment
)
747 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
748 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
749 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
751 int label
= gen_new_label();
752 TCGv_i32 tmp
= tcg_temp_new_i32();
753 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
754 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
755 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
756 gen_set_label(label
);
761 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
763 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
764 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
765 gen_advance_ccount(dc
);
766 gen_helper_waiti(cpu_env
, pc
, intlevel
);
768 tcg_temp_free(intlevel
);
771 static void gen_window_check1(DisasContext
*dc
, unsigned r1
)
773 if (dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) {
776 if (option_enabled(dc
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
777 r1
/ 4 > dc
->used_window
) {
778 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
779 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
781 dc
->used_window
= r1
/ 4;
782 gen_advance_ccount(dc
);
783 gen_helper_window_check(cpu_env
, pc
, w
);
790 static void gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
792 gen_window_check1(dc
, r1
> r2
? r1
: r2
);
795 static void gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
798 gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
801 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
803 TCGv_i32 m
= tcg_temp_new_i32();
806 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
808 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
813 static void disas_xtensa_insn(DisasContext
*dc
)
815 #define HAS_OPTION_BITS(opt) do { \
816 if (!option_bits_enabled(dc, opt)) { \
817 qemu_log("Option is not enabled %s:%d\n", \
818 __FILE__, __LINE__); \
819 goto invalid_opcode; \
823 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
825 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
826 #define RESERVED() do { \
827 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
828 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
829 goto invalid_opcode; \
833 #ifdef TARGET_WORDS_BIGENDIAN
834 #define OP0 (((b0) & 0xf0) >> 4)
835 #define OP1 (((b2) & 0xf0) >> 4)
836 #define OP2 ((b2) & 0xf)
837 #define RRR_R ((b1) & 0xf)
838 #define RRR_S (((b1) & 0xf0) >> 4)
839 #define RRR_T ((b0) & 0xf)
841 #define OP0 (((b0) & 0xf))
842 #define OP1 (((b2) & 0xf))
843 #define OP2 (((b2) & 0xf0) >> 4)
844 #define RRR_R (((b1) & 0xf0) >> 4)
845 #define RRR_S (((b1) & 0xf))
846 #define RRR_T (((b0) & 0xf0) >> 4)
848 #define RRR_X ((RRR_R & 0x4) >> 2)
849 #define RRR_Y ((RRR_T & 0x4) >> 2)
850 #define RRR_W (RRR_R & 0x3)
859 #define RRI8_IMM8 (b2)
860 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
862 #ifdef TARGET_WORDS_BIGENDIAN
863 #define RI16_IMM16 (((b1) << 8) | (b2))
865 #define RI16_IMM16 (((b2) << 8) | (b1))
868 #ifdef TARGET_WORDS_BIGENDIAN
869 #define CALL_N (((b0) & 0xc) >> 2)
870 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
872 #define CALL_N (((b0) & 0x30) >> 4)
873 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
875 #define CALL_OFFSET_SE \
876 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
878 #define CALLX_N CALL_N
879 #ifdef TARGET_WORDS_BIGENDIAN
880 #define CALLX_M ((b0) & 0x3)
882 #define CALLX_M (((b0) & 0xc0) >> 6)
884 #define CALLX_S RRR_S
886 #define BRI12_M CALLX_M
887 #define BRI12_S RRR_S
888 #ifdef TARGET_WORDS_BIGENDIAN
889 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
891 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
893 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
895 #define BRI8_M BRI12_M
896 #define BRI8_R RRI8_R
897 #define BRI8_S RRI8_S
898 #define BRI8_IMM8 RRI8_IMM8
899 #define BRI8_IMM8_SE RRI8_IMM8_SE
903 uint8_t b0
= cpu_ldub_code(cpu_single_env
, dc
->pc
);
904 uint8_t b1
= cpu_ldub_code(cpu_single_env
, dc
->pc
+ 1);
907 static const uint32_t B4CONST
[] = {
908 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
911 static const uint32_t B4CONSTU
[] = {
912 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
916 dc
->next_pc
= dc
->pc
+ 2;
917 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
919 dc
->next_pc
= dc
->pc
+ 3;
920 b2
= cpu_ldub_code(cpu_single_env
, dc
->pc
+ 2);
929 if ((RRR_R
& 0xc) == 0x8) {
930 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
937 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
948 gen_window_check1(dc
, CALLX_S
);
949 gen_jump(dc
, cpu_R
[CALLX_S
]);
953 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
955 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
956 gen_advance_ccount(dc
);
957 gen_helper_retw(tmp
, cpu_env
, tmp
);
970 gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2);
974 TCGv_i32 tmp
= tcg_temp_new_i32();
975 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
976 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
985 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
987 TCGv_i32 tmp
= tcg_temp_new_i32();
989 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
990 gen_callw(dc
, CALLX_N
, tmp
);
1000 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1001 gen_window_check2(dc
, RRR_T
, RRR_S
);
1003 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1004 gen_advance_ccount(dc
);
1005 gen_helper_movsp(cpu_env
, pc
);
1006 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1026 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1038 default: /*reserved*/
1047 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1050 gen_check_privilege(dc
);
1051 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1052 gen_helper_check_interrupts(cpu_env
);
1053 gen_jump(dc
, cpu_SR
[EPC1
]);
1061 gen_check_privilege(dc
);
1062 gen_jump(dc
, cpu_SR
[
1063 dc
->config
->ndepc
? DEPC
: EPC1
]);
1068 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1069 gen_check_privilege(dc
);
1071 TCGv_i32 tmp
= tcg_const_i32(1);
1074 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1075 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1078 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1079 cpu_SR
[WINDOW_START
], tmp
);
1081 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1082 cpu_SR
[WINDOW_START
], tmp
);
1085 gen_helper_restore_owb(cpu_env
);
1086 gen_helper_check_interrupts(cpu_env
);
1087 gen_jump(dc
, cpu_SR
[EPC1
]);
1093 default: /*reserved*/
1100 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1101 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1102 gen_check_privilege(dc
);
1103 tcg_gen_mov_i32(cpu_SR
[PS
],
1104 cpu_SR
[EPS2
+ RRR_S
- 2]);
1105 gen_helper_check_interrupts(cpu_env
);
1106 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1108 qemu_log("RFI %d is illegal\n", RRR_S
);
1109 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1117 default: /*reserved*/
1125 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1127 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1131 case 5: /*SYSCALLx*/
1132 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1134 case 0: /*SYSCALLx*/
1135 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1139 if (semihosting_enabled
) {
1140 gen_check_privilege(dc
);
1141 gen_helper_simcall(cpu_env
);
1143 qemu_log("SIMCALL but semihosting is disabled\n");
1144 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1155 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1156 gen_check_privilege(dc
);
1157 gen_window_check1(dc
, RRR_T
);
1158 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1159 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1160 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1161 gen_helper_check_interrupts(cpu_env
);
1162 gen_jumpi_check_loop_end(dc
, 0);
1166 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1167 gen_check_privilege(dc
);
1168 gen_waiti(dc
, RRR_S
);
1175 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1177 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1178 TCGv_i32 mask
= tcg_const_i32(
1179 ((1 << shift
) - 1) << RRR_S
);
1180 TCGv_i32 tmp
= tcg_temp_new_i32();
1182 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1183 if (RRR_R
& 1) { /*ALL*/
1184 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1186 tcg_gen_add_i32(tmp
, tmp
, mask
);
1188 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1189 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1191 tcg_temp_free(mask
);
1196 default: /*reserved*/
1204 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1205 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1209 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1210 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1214 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1215 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1221 gen_window_check1(dc
, RRR_S
);
1222 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1226 gen_window_check1(dc
, RRR_S
);
1227 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1231 gen_window_check1(dc
, RRR_S
);
1233 TCGv_i32 tmp
= tcg_temp_new_i32();
1234 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1235 gen_right_shift_sar(dc
, tmp
);
1241 gen_window_check1(dc
, RRR_S
);
1243 TCGv_i32 tmp
= tcg_temp_new_i32();
1244 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1245 gen_left_shift_sar(dc
, tmp
);
1252 TCGv_i32 tmp
= tcg_const_i32(
1253 RRR_S
| ((RRR_T
& 1) << 4));
1254 gen_right_shift_sar(dc
, tmp
);
1268 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1269 gen_check_privilege(dc
);
1271 TCGv_i32 tmp
= tcg_const_i32(
1272 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1273 gen_helper_rotw(cpu_env
, tmp
);
1275 reset_used_window(dc
);
1280 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1281 gen_window_check2(dc
, RRR_S
, RRR_T
);
1282 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1286 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1287 gen_window_check2(dc
, RRR_S
, RRR_T
);
1288 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1291 default: /*reserved*/
1299 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1300 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1301 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1302 gen_check_privilege(dc
);
1303 gen_window_check2(dc
, RRR_S
, RRR_T
);
1305 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1307 switch (RRR_R
& 7) {
1308 case 3: /*RITLB0*/ /*RDTLB0*/
1309 gen_helper_rtlb0(cpu_R
[RRR_T
],
1310 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1313 case 4: /*IITLB*/ /*IDTLB*/
1314 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1315 /* This could change memory mapping, so exit tb */
1316 gen_jumpi_check_loop_end(dc
, -1);
1319 case 5: /*PITLB*/ /*PDTLB*/
1320 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1321 gen_helper_ptlb(cpu_R
[RRR_T
],
1322 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1325 case 6: /*WITLB*/ /*WDTLB*/
1327 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1328 /* This could change memory mapping, so exit tb */
1329 gen_jumpi_check_loop_end(dc
, -1);
1332 case 7: /*RITLB1*/ /*RDTLB1*/
1333 gen_helper_rtlb1(cpu_R
[RRR_T
],
1334 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1338 tcg_temp_free(dtlb
);
1342 tcg_temp_free(dtlb
);
1347 gen_window_check2(dc
, RRR_R
, RRR_T
);
1350 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1355 int label
= gen_new_label();
1356 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1357 tcg_gen_brcondi_i32(
1358 TCG_COND_GE
, cpu_R
[RRR_R
], 0, label
);
1359 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1360 gen_set_label(label
);
1364 default: /*reserved*/
1370 case 7: /*reserved*/
1375 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1376 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1382 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1384 TCGv_i32 tmp
= tcg_temp_new_i32();
1385 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1386 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1392 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1393 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1399 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1401 TCGv_i32 tmp
= tcg_temp_new_i32();
1402 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1403 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1414 gen_window_check2(dc
, RRR_R
, RRR_S
);
1415 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1416 32 - (RRR_T
| ((OP2
& 1) << 4)));
1421 gen_window_check2(dc
, RRR_R
, RRR_T
);
1422 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1423 RRR_S
| ((OP2
& 1) << 4));
1427 gen_window_check2(dc
, RRR_R
, RRR_T
);
1428 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1433 TCGv_i32 tmp
= tcg_temp_new_i32();
1435 gen_check_privilege(dc
);
1437 gen_window_check1(dc
, RRR_T
);
1438 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1439 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1440 gen_wsr(dc
, RSR_SR
, tmp
);
1442 if (!sregnames
[RSR_SR
]) {
1449 * Note: 64 bit ops are used here solely because SAR values
1452 #define gen_shift_reg(cmd, reg) do { \
1453 TCGv_i64 tmp = tcg_temp_new_i64(); \
1454 tcg_gen_extu_i32_i64(tmp, reg); \
1455 tcg_gen_##cmd##_i64(v, v, tmp); \
1456 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \
1457 tcg_temp_free_i64(v); \
1458 tcg_temp_free_i64(tmp); \
1461 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1464 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1466 TCGv_i64 v
= tcg_temp_new_i64();
1467 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1473 gen_window_check2(dc
, RRR_R
, RRR_T
);
1475 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1477 TCGv_i64 v
= tcg_temp_new_i64();
1478 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1484 gen_window_check2(dc
, RRR_R
, RRR_S
);
1485 if (dc
->sar_m32_5bit
) {
1486 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1488 TCGv_i64 v
= tcg_temp_new_i64();
1489 TCGv_i32 s
= tcg_const_i32(32);
1490 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1491 tcg_gen_andi_i32(s
, s
, 0x3f);
1492 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1493 gen_shift_reg(shl
, s
);
1499 gen_window_check2(dc
, RRR_R
, RRR_T
);
1501 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1503 TCGv_i64 v
= tcg_temp_new_i64();
1504 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1509 #undef gen_shift_reg
1512 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1513 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1515 TCGv_i32 v1
= tcg_temp_new_i32();
1516 TCGv_i32 v2
= tcg_temp_new_i32();
1517 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1518 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1519 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1526 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1527 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1529 TCGv_i32 v1
= tcg_temp_new_i32();
1530 TCGv_i32 v2
= tcg_temp_new_i32();
1531 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1532 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1533 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1539 default: /*reserved*/
1547 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1551 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1552 int label
= gen_new_label();
1553 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1554 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1555 gen_set_label(label
);
1559 #define BOOLEAN_LOGIC(fn, r, s, t) \
1561 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1562 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1563 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1565 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1566 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1567 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1568 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1569 tcg_temp_free(tmp1); \
1570 tcg_temp_free(tmp2); \
1574 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1578 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1582 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1586 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1590 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1593 #undef BOOLEAN_LOGIC
1596 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1597 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1602 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1604 TCGv_i64 r
= tcg_temp_new_i64();
1605 TCGv_i64 s
= tcg_temp_new_i64();
1606 TCGv_i64 t
= tcg_temp_new_i64();
1609 tcg_gen_extu_i32_i64(s
, cpu_R
[RRR_S
]);
1610 tcg_gen_extu_i32_i64(t
, cpu_R
[RRR_T
]);
1612 tcg_gen_ext_i32_i64(s
, cpu_R
[RRR_S
]);
1613 tcg_gen_ext_i32_i64(t
, cpu_R
[RRR_T
]);
1615 tcg_gen_mul_i64(r
, s
, t
);
1616 tcg_gen_shri_i64(r
, r
, 32);
1617 tcg_gen_trunc_i64_i32(cpu_R
[RRR_R
], r
);
1619 tcg_temp_free_i64(r
);
1620 tcg_temp_free_i64(s
);
1621 tcg_temp_free_i64(t
);
1626 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1632 int label1
= gen_new_label();
1633 int label2
= gen_new_label();
1635 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1637 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1639 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1640 OP2
== 13 ? 0x80000000 : 0);
1642 gen_set_label(label1
);
1644 tcg_gen_div_i32(cpu_R
[RRR_R
],
1645 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1647 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1648 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1650 gen_set_label(label2
);
1655 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1658 default: /*reserved*/
1668 gen_check_privilege(dc
);
1670 gen_window_check1(dc
, RRR_T
);
1671 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1672 if (!sregnames
[RSR_SR
]) {
1679 gen_check_privilege(dc
);
1681 gen_window_check1(dc
, RRR_T
);
1682 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1683 if (!sregnames
[RSR_SR
]) {
1689 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1690 gen_window_check2(dc
, RRR_R
, RRR_S
);
1692 int shift
= 24 - RRR_T
;
1695 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1696 } else if (shift
== 16) {
1697 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1699 TCGv_i32 tmp
= tcg_temp_new_i32();
1700 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1701 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1708 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1709 gen_window_check2(dc
, RRR_R
, RRR_S
);
1711 TCGv_i32 tmp1
= tcg_temp_new_i32();
1712 TCGv_i32 tmp2
= tcg_temp_new_i32();
1713 int label
= gen_new_label();
1715 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1716 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1717 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1718 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1719 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp2
, 0, label
);
1721 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1722 tcg_gen_xori_i32(cpu_R
[RRR_R
], tmp1
,
1723 0xffffffff >> (25 - RRR_T
));
1725 gen_set_label(label
);
1727 tcg_temp_free(tmp1
);
1728 tcg_temp_free(tmp2
);
1736 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1737 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1739 static const TCGCond cond
[] = {
1745 int label
= gen_new_label();
1747 if (RRR_R
!= RRR_T
) {
1748 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1749 tcg_gen_brcond_i32(cond
[OP2
- 4],
1750 cpu_R
[RRR_S
], cpu_R
[RRR_T
], label
);
1751 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1753 tcg_gen_brcond_i32(cond
[OP2
- 4],
1754 cpu_R
[RRR_T
], cpu_R
[RRR_S
], label
);
1755 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1757 gen_set_label(label
);
1765 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1767 static const TCGCond cond
[] = {
1773 int label
= gen_new_label();
1774 tcg_gen_brcondi_i32(cond
[OP2
- 8], cpu_R
[RRR_T
], 0, label
);
1775 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1776 gen_set_label(label
);
1782 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1783 gen_window_check2(dc
, RRR_R
, RRR_S
);
1785 int label
= gen_new_label();
1786 TCGv_i32 tmp
= tcg_temp_new_i32();
1788 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1789 tcg_gen_brcondi_i32(
1790 OP2
& 1 ? TCG_COND_EQ
: TCG_COND_NE
,
1792 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1793 gen_set_label(label
);
1799 gen_window_check1(dc
, RRR_R
);
1801 int st
= (RRR_S
<< 4) + RRR_T
;
1802 if (uregnames
[st
]) {
1803 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1805 qemu_log("RUR %d not implemented, ", st
);
1812 gen_window_check1(dc
, RRR_T
);
1813 if (uregnames
[RSR_SR
]) {
1814 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1816 qemu_log("WUR %d not implemented, ", RSR_SR
);
1826 gen_window_check2(dc
, RRR_R
, RRR_T
);
1828 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1829 int maskimm
= (1 << (OP2
+ 1)) - 1;
1831 TCGv_i32 tmp
= tcg_temp_new_i32();
1832 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1833 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1852 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1853 gen_window_check2(dc
, RRR_S
, RRR_T
);
1854 gen_check_cpenable(dc
, 0);
1856 TCGv_i32 addr
= tcg_temp_new_i32();
1857 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1858 gen_load_store_alignment(dc
, 2, addr
, false);
1860 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1862 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1865 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1867 tcg_temp_free(addr
);
1871 default: /*reserved*/
1878 gen_window_check2(dc
, RRR_S
, RRR_T
);
1881 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1882 gen_check_privilege(dc
);
1884 TCGv_i32 addr
= tcg_temp_new_i32();
1885 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1886 (0xffffffc0 | (RRR_R
<< 2)));
1887 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1888 tcg_temp_free(addr
);
1893 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1894 gen_check_privilege(dc
);
1896 TCGv_i32 addr
= tcg_temp_new_i32();
1897 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1898 (0xffffffc0 | (RRR_R
<< 2)));
1899 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1900 tcg_temp_free(addr
);
1911 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1914 gen_check_cpenable(dc
, 0);
1915 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
1916 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1920 gen_check_cpenable(dc
, 0);
1921 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
1922 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1926 gen_check_cpenable(dc
, 0);
1927 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
1928 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1932 gen_check_cpenable(dc
, 0);
1933 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
1934 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1938 gen_check_cpenable(dc
, 0);
1939 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
1940 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1943 case 8: /*ROUND.Sf*/
1944 case 9: /*TRUNC.Sf*/
1945 case 10: /*FLOOR.Sf*/
1946 case 11: /*CEIL.Sf*/
1947 case 14: /*UTRUNC.Sf*/
1948 gen_window_check1(dc
, RRR_R
);
1949 gen_check_cpenable(dc
, 0);
1951 static const unsigned rounding_mode_const
[] = {
1952 float_round_nearest_even
,
1953 float_round_to_zero
,
1956 [6] = float_round_to_zero
,
1958 TCGv_i32 rounding_mode
= tcg_const_i32(
1959 rounding_mode_const
[OP2
& 7]);
1960 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
1963 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
1964 rounding_mode
, scale
);
1966 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
1967 rounding_mode
, scale
);
1970 tcg_temp_free(rounding_mode
);
1971 tcg_temp_free(scale
);
1975 case 12: /*FLOAT.Sf*/
1976 case 13: /*UFLOAT.Sf*/
1977 gen_window_check1(dc
, RRR_S
);
1978 gen_check_cpenable(dc
, 0);
1980 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
1983 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
1984 cpu_R
[RRR_S
], scale
);
1986 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
1987 cpu_R
[RRR_S
], scale
);
1989 tcg_temp_free(scale
);
1996 gen_check_cpenable(dc
, 0);
1997 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2001 gen_check_cpenable(dc
, 0);
2002 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2006 gen_window_check1(dc
, RRR_R
);
2007 gen_check_cpenable(dc
, 0);
2008 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2012 gen_window_check1(dc
, RRR_S
);
2013 gen_check_cpenable(dc
, 0);
2014 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2018 gen_check_cpenable(dc
, 0);
2019 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2022 default: /*reserved*/
2028 default: /*reserved*/
2035 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2037 #define gen_compare(rel, br, a, b) \
2039 TCGv_i32 bit = tcg_const_i32(1 << br); \
2041 gen_check_cpenable(dc, 0); \
2042 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2043 tcg_temp_free(bit); \
2048 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2052 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2056 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2060 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2064 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2068 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2072 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2077 case 8: /*MOVEQZ.Sf*/
2078 case 9: /*MOVNEZ.Sf*/
2079 case 10: /*MOVLTZ.Sf*/
2080 case 11: /*MOVGEZ.Sf*/
2081 gen_window_check1(dc
, RRR_T
);
2082 gen_check_cpenable(dc
, 0);
2084 static const TCGCond cond
[] = {
2090 int label
= gen_new_label();
2091 tcg_gen_brcondi_i32(cond
[OP2
- 8], cpu_R
[RRR_T
], 0, label
);
2092 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2093 gen_set_label(label
);
2097 case 12: /*MOVF.Sf*/
2098 case 13: /*MOVT.Sf*/
2099 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2100 gen_check_cpenable(dc
, 0);
2102 int label
= gen_new_label();
2103 TCGv_i32 tmp
= tcg_temp_new_i32();
2105 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2106 tcg_gen_brcondi_i32(
2107 OP2
& 1 ? TCG_COND_EQ
: TCG_COND_NE
,
2109 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2110 gen_set_label(label
);
2115 default: /*reserved*/
2121 default: /*reserved*/
2128 gen_window_check1(dc
, RRR_T
);
2130 TCGv_i32 tmp
= tcg_const_i32(
2131 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2132 0 : ((dc
->pc
+ 3) & ~3)) +
2133 (0xfffc0000 | (RI16_IMM16
<< 2)));
2135 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2136 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2138 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2144 #define gen_load_store(type, shift) do { \
2145 TCGv_i32 addr = tcg_temp_new_i32(); \
2146 gen_window_check2(dc, RRI8_S, RRI8_T); \
2147 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2149 gen_load_store_alignment(dc, shift, addr, false); \
2151 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2152 tcg_temp_free(addr); \
2157 gen_load_store(ld8u
, 0);
2161 gen_load_store(ld16u
, 1);
2165 gen_load_store(ld32u
, 2);
2169 gen_load_store(st8
, 0);
2173 gen_load_store(st16
, 1);
2177 gen_load_store(st32
, 2);
2182 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2213 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2217 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2221 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2225 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2229 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2232 default: /*reserved*/
2240 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2246 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2250 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2254 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2257 default: /*reserved*/
2264 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2268 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2271 default: /*reserved*/
2278 gen_load_store(ld16s
, 1);
2280 #undef gen_load_store
2283 gen_window_check1(dc
, RRI8_T
);
2284 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2285 RRI8_IMM8
| (RRI8_S
<< 8) |
2286 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2289 #define gen_load_store_no_hw_align(type) do { \
2290 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2291 gen_window_check2(dc, RRI8_S, RRI8_T); \
2292 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2293 gen_load_store_alignment(dc, 2, addr, true); \
2294 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2295 tcg_temp_free(addr); \
2299 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2300 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2304 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2305 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2309 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2310 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
<< 8);
2313 case 14: /*S32C1Iy*/
2314 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2315 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2317 int label
= gen_new_label();
2318 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2319 TCGv_i32 addr
= tcg_temp_local_new_i32();
2321 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2322 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2323 gen_load_store_alignment(dc
, 2, addr
, true);
2324 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2325 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2326 cpu_SR
[SCOMPARE1
], label
);
2328 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2330 gen_set_label(label
);
2331 tcg_temp_free(addr
);
2337 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2338 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2340 #undef gen_load_store_no_hw_align
2342 default: /*reserved*/
2354 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2355 gen_window_check1(dc
, RRI8_S
);
2356 gen_check_cpenable(dc
, 0);
2358 TCGv_i32 addr
= tcg_temp_new_i32();
2359 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2360 gen_load_store_alignment(dc
, 2, addr
, false);
2362 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2364 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2367 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2369 tcg_temp_free(addr
);
2373 default: /*reserved*/
2380 HAS_OPTION(XTENSA_OPTION_MAC16
);
2389 bool is_m1_sr
= (OP2
& 0x3) == 2;
2390 bool is_m2_sr
= (OP2
& 0xc) == 0;
2391 uint32_t ld_offset
= 0;
2398 case 0: /*MACI?/MACC?*/
2400 ld_offset
= (OP2
& 1) ? -4 : 4;
2402 if (OP2
>= 8) { /*MACI/MACC*/
2403 if (OP1
== 0) { /*LDINC/LDDEC*/
2408 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2413 case 2: /*MACD?/MACA?*/
2414 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2420 if (op
!= MAC16_NONE
) {
2422 gen_window_check1(dc
, RRR_S
);
2425 gen_window_check1(dc
, RRR_T
);
2430 TCGv_i32 vaddr
= tcg_temp_new_i32();
2431 TCGv_i32 mem32
= tcg_temp_new_i32();
2434 gen_window_check1(dc
, RRR_S
);
2435 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2436 gen_load_store_alignment(dc
, 2, vaddr
, false);
2437 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2439 if (op
!= MAC16_NONE
) {
2440 TCGv_i32 m1
= gen_mac16_m(
2441 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2442 OP1
& 1, op
== MAC16_UMUL
);
2443 TCGv_i32 m2
= gen_mac16_m(
2444 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2445 OP1
& 2, op
== MAC16_UMUL
);
2447 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2448 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2449 if (op
== MAC16_UMUL
) {
2450 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2452 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2455 TCGv_i32 res
= tcg_temp_new_i32();
2456 TCGv_i64 res64
= tcg_temp_new_i64();
2457 TCGv_i64 tmp
= tcg_temp_new_i64();
2459 tcg_gen_mul_i32(res
, m1
, m2
);
2460 tcg_gen_ext_i32_i64(res64
, res
);
2461 tcg_gen_concat_i32_i64(tmp
,
2462 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
]);
2463 if (op
== MAC16_MULA
) {
2464 tcg_gen_add_i64(tmp
, tmp
, res64
);
2466 tcg_gen_sub_i64(tmp
, tmp
, res64
);
2468 tcg_gen_trunc_i64_i32(cpu_SR
[ACCLO
], tmp
);
2469 tcg_gen_shri_i64(tmp
, tmp
, 32);
2470 tcg_gen_trunc_i64_i32(cpu_SR
[ACCHI
], tmp
);
2471 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2474 tcg_temp_free_i64(res64
);
2475 tcg_temp_free_i64(tmp
);
2481 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2482 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2484 tcg_temp_free(vaddr
);
2485 tcg_temp_free(mem32
);
2493 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2494 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2500 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2501 gen_window_check1(dc
, CALL_N
<< 2);
2502 gen_callwi(dc
, CALL_N
,
2503 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2511 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2515 gen_window_check1(dc
, BRI12_S
);
2517 static const TCGCond cond
[] = {
2518 TCG_COND_EQ
, /*BEQZ*/
2519 TCG_COND_NE
, /*BNEZ*/
2520 TCG_COND_LT
, /*BLTZ*/
2521 TCG_COND_GE
, /*BGEZ*/
2524 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2525 4 + BRI12_IMM12_SE
);
2530 gen_window_check1(dc
, BRI8_S
);
2532 static const TCGCond cond
[] = {
2533 TCG_COND_EQ
, /*BEQI*/
2534 TCG_COND_NE
, /*BNEI*/
2535 TCG_COND_LT
, /*BLTI*/
2536 TCG_COND_GE
, /*BGEI*/
2539 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2540 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2547 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2549 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2550 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2551 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2552 gen_advance_ccount(dc
);
2553 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2557 reset_used_window(dc
);
2565 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2567 TCGv_i32 tmp
= tcg_temp_new_i32();
2568 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2570 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2571 tmp
, 0, 4 + RRI8_IMM8_SE
);
2578 case 10: /*LOOPGTZ*/
2579 HAS_OPTION(XTENSA_OPTION_LOOP
);
2580 gen_window_check1(dc
, RRI8_S
);
2582 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2583 TCGv_i32 tmp
= tcg_const_i32(lend
);
2585 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2586 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2587 gen_helper_wsr_lend(cpu_env
, tmp
);
2591 int label
= gen_new_label();
2592 tcg_gen_brcondi_i32(
2593 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2594 cpu_R
[RRI8_S
], 0, label
);
2595 gen_jumpi(dc
, lend
, 1);
2596 gen_set_label(label
);
2599 gen_jumpi(dc
, dc
->next_pc
, 0);
2603 default: /*reserved*/
2612 gen_window_check1(dc
, BRI8_S
);
2613 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2614 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2624 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2626 switch (RRI8_R
& 7) {
2627 case 0: /*BNONE*/ /*BANY*/
2628 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2630 TCGv_i32 tmp
= tcg_temp_new_i32();
2631 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2632 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2637 case 1: /*BEQ*/ /*BNE*/
2638 case 2: /*BLT*/ /*BGE*/
2639 case 3: /*BLTU*/ /*BGEU*/
2640 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2642 static const TCGCond cond
[] = {
2648 [11] = TCG_COND_GEU
,
2650 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2655 case 4: /*BALL*/ /*BNALL*/
2656 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2658 TCGv_i32 tmp
= tcg_temp_new_i32();
2659 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2660 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2666 case 5: /*BBC*/ /*BBS*/
2667 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2669 #ifdef TARGET_WORDS_BIGENDIAN
2670 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2672 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2674 TCGv_i32 tmp
= tcg_temp_new_i32();
2675 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2676 #ifdef TARGET_WORDS_BIGENDIAN
2677 tcg_gen_shr_i32(bit
, bit
, tmp
);
2679 tcg_gen_shl_i32(bit
, bit
, tmp
);
2681 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2682 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2688 case 6: /*BBCI*/ /*BBSI*/
2690 gen_window_check1(dc
, RRI8_S
);
2692 TCGv_i32 tmp
= tcg_temp_new_i32();
2693 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2694 #ifdef TARGET_WORDS_BIGENDIAN
2695 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2697 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2699 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2708 #define gen_narrow_load_store(type) do { \
2709 TCGv_i32 addr = tcg_temp_new_i32(); \
2710 gen_window_check2(dc, RRRN_S, RRRN_T); \
2711 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2712 gen_load_store_alignment(dc, 2, addr, false); \
2713 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2714 tcg_temp_free(addr); \
2718 gen_narrow_load_store(ld32u
);
2722 gen_narrow_load_store(st32
);
2724 #undef gen_narrow_load_store
2727 gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
);
2728 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2731 case 11: /*ADDI.Nn*/
2732 gen_window_check2(dc
, RRRN_R
, RRRN_S
);
2733 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], RRRN_T
? RRRN_T
: -1);
2737 gen_window_check1(dc
, RRRN_S
);
2738 if (RRRN_T
< 8) { /*MOVI.Nn*/
2739 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2740 RRRN_R
| (RRRN_T
<< 4) |
2741 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2742 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2743 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2745 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2746 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2753 gen_window_check2(dc
, RRRN_S
, RRRN_T
);
2754 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2760 gen_jump(dc
, cpu_R
[0]);
2764 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2766 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2767 gen_advance_ccount(dc
);
2768 gen_helper_retw(tmp
, cpu_env
, tmp
);
2774 case 2: /*BREAK.Nn*/
2775 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2777 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2785 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2788 default: /*reserved*/
2794 default: /*reserved*/
2800 default: /*reserved*/
2805 if (dc
->is_jmp
== DISAS_NEXT
) {
2806 gen_check_loop_end(dc
, 0);
2808 dc
->pc
= dc
->next_pc
;
2813 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2814 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2818 static void check_breakpoint(CPUXtensaState
*env
, DisasContext
*dc
)
2822 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2823 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2824 if (bp
->pc
== dc
->pc
) {
2825 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2826 gen_exception(dc
, EXCP_DEBUG
);
2827 dc
->is_jmp
= DISAS_UPDATE
;
2833 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
2837 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
2838 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
2839 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
2840 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
2846 static void gen_intermediate_code_internal(
2847 CPUXtensaState
*env
, TranslationBlock
*tb
, int search_pc
)
2852 uint16_t *gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
2853 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2854 uint32_t pc_start
= tb
->pc
;
2855 uint32_t next_page_start
=
2856 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2858 if (max_insns
== 0) {
2859 max_insns
= CF_COUNT_MASK
;
2862 dc
.config
= env
->config
;
2863 dc
.singlestep_enabled
= env
->singlestep_enabled
;
2866 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
2867 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
2868 dc
.lbeg
= env
->sregs
[LBEG
];
2869 dc
.lend
= env
->sregs
[LEND
];
2870 dc
.is_jmp
= DISAS_NEXT
;
2871 dc
.ccount_delta
= 0;
2872 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
2873 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
2874 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
2875 XTENSA_TBFLAG_CPENABLE_SHIFT
;
2878 init_sar_tracker(&dc
);
2879 reset_used_window(&dc
);
2881 dc
.next_icount
= tcg_temp_local_new_i32();
2886 if (env
->singlestep_enabled
&& env
->exception_taken
) {
2887 env
->exception_taken
= 0;
2888 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2889 gen_exception(&dc
, EXCP_DEBUG
);
2893 check_breakpoint(env
, &dc
);
2896 j
= gen_opc_ptr
- gen_opc_buf
;
2900 gen_opc_instr_start
[lj
++] = 0;
2903 gen_opc_pc
[lj
] = dc
.pc
;
2904 gen_opc_instr_start
[lj
] = 1;
2905 gen_opc_icount
[lj
] = insn_count
;
2908 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
2909 tcg_gen_debug_insn_start(dc
.pc
);
2914 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
2919 int label
= gen_new_label();
2921 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
2922 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
2923 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
2925 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
2927 gen_set_label(label
);
2931 gen_ibreak_check(env
, &dc
);
2934 disas_xtensa_insn(&dc
);
2937 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
2939 if (env
->singlestep_enabled
) {
2940 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2941 gen_exception(&dc
, EXCP_DEBUG
);
2944 } while (dc
.is_jmp
== DISAS_NEXT
&&
2945 insn_count
< max_insns
&&
2946 dc
.pc
< next_page_start
&&
2947 gen_opc_ptr
< gen_opc_end
);
2950 reset_sar_tracker(&dc
);
2952 tcg_temp_free(dc
.next_icount
);
2955 if (tb
->cflags
& CF_LAST_IO
) {
2959 if (dc
.is_jmp
== DISAS_NEXT
) {
2960 gen_jumpi(&dc
, dc
.pc
, 0);
2962 gen_icount_end(tb
, insn_count
);
2963 *gen_opc_ptr
= INDEX_op_end
;
2966 tb
->size
= dc
.pc
- pc_start
;
2967 tb
->icount
= insn_count
;
2971 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
2973 gen_intermediate_code_internal(env
, tb
, 0);
2976 void gen_intermediate_code_pc(CPUXtensaState
*env
, TranslationBlock
*tb
)
2978 gen_intermediate_code_internal(env
, tb
, 1);
2981 void cpu_dump_state(CPUXtensaState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
2986 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
2988 for (i
= j
= 0; i
< 256; ++i
) {
2990 cpu_fprintf(f
, "%s=%08x%c", sregnames
[i
], env
->sregs
[i
],
2991 (j
++ % 4) == 3 ? '\n' : ' ');
2995 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
2997 for (i
= j
= 0; i
< 256; ++i
) {
2999 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
], env
->uregs
[i
],
3000 (j
++ % 4) == 3 ? '\n' : ' ');
3004 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3006 for (i
= 0; i
< 16; ++i
) {
3007 cpu_fprintf(f
, "A%02d=%08x%c", i
, env
->regs
[i
],
3008 (i
% 4) == 3 ? '\n' : ' ');
3011 cpu_fprintf(f
, "\n");
3013 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3014 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3015 (i
% 4) == 3 ? '\n' : ' ');
3018 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3019 cpu_fprintf(f
, "\n");
3021 for (i
= 0; i
< 16; ++i
) {
3022 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3023 float32_val(env
->fregs
[i
]),
3024 *(float *)&env
->fregs
[i
], (i
% 2) == 1 ? '\n' : ' ');
3029 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
, int pc_pos
)
3031 env
->pc
= gen_opc_pc
[pc_pos
];