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
;
66 static TCGv_ptr cpu_env
;
67 static TCGv_i32 cpu_pc
;
68 static TCGv_i32 cpu_R
[16];
69 static TCGv_i32 cpu_SR
[256];
70 static TCGv_i32 cpu_UR
[256];
72 #include "gen-icount.h"
74 static const char * const sregnames
[256] = {
80 [LITBASE
] = "LITBASE",
81 [SCOMPARE1
] = "SCOMPARE1",
88 [WINDOW_BASE
] = "WINDOW_BASE",
89 [WINDOW_START
] = "WINDOW_START",
90 [PTEVADDR
] = "PTEVADDR",
92 [ITLBCFG
] = "ITLBCFG",
93 [DTLBCFG
] = "DTLBCFG",
108 [EXCSAVE1
] = "EXCSAVE1",
109 [EXCSAVE1
+ 1] = "EXCSAVE2",
110 [EXCSAVE1
+ 2] = "EXCSAVE3",
111 [EXCSAVE1
+ 3] = "EXCSAVE4",
112 [EXCSAVE1
+ 4] = "EXCSAVE5",
113 [EXCSAVE1
+ 5] = "EXCSAVE6",
114 [EXCSAVE1
+ 6] = "EXCSAVE7",
115 [CPENABLE
] = "CPENABLE",
117 [INTCLEAR
] = "INTCLEAR",
118 [INTENABLE
] = "INTENABLE",
120 [VECBASE
] = "VECBASE",
121 [EXCCAUSE
] = "EXCCAUSE",
124 [EXCVADDR
] = "EXCVADDR",
125 [CCOMPARE
] = "CCOMPARE0",
126 [CCOMPARE
+ 1] = "CCOMPARE1",
127 [CCOMPARE
+ 2] = "CCOMPARE2",
130 static const char * const uregnames
[256] = {
131 [THREADPTR
] = "THREADPTR",
136 void xtensa_translate_init(void)
138 static const char * const regnames
[] = {
139 "ar0", "ar1", "ar2", "ar3",
140 "ar4", "ar5", "ar6", "ar7",
141 "ar8", "ar9", "ar10", "ar11",
142 "ar12", "ar13", "ar14", "ar15",
146 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
147 cpu_pc
= tcg_global_mem_new_i32(TCG_AREG0
,
148 offsetof(CPUState
, pc
), "pc");
150 for (i
= 0; i
< 16; i
++) {
151 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
152 offsetof(CPUState
, regs
[i
]),
156 for (i
= 0; i
< 256; ++i
) {
158 cpu_SR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
159 offsetof(CPUState
, sregs
[i
]),
164 for (i
= 0; i
< 256; ++i
) {
166 cpu_UR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
167 offsetof(CPUState
, uregs
[i
]),
175 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
177 return xtensa_option_bits_enabled(dc
->config
, opt
);
180 static inline bool option_enabled(DisasContext
*dc
, int opt
)
182 return xtensa_option_enabled(dc
->config
, opt
);
185 static void init_litbase(DisasContext
*dc
)
187 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
188 dc
->litbase
= tcg_temp_local_new_i32();
189 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
193 static void reset_litbase(DisasContext
*dc
)
195 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
196 tcg_temp_free(dc
->litbase
);
200 static void init_sar_tracker(DisasContext
*dc
)
202 dc
->sar_5bit
= false;
203 dc
->sar_m32_5bit
= false;
204 dc
->sar_m32_allocated
= false;
207 static void reset_sar_tracker(DisasContext
*dc
)
209 if (dc
->sar_m32_allocated
) {
210 tcg_temp_free(dc
->sar_m32
);
214 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
216 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
217 if (dc
->sar_m32_5bit
) {
218 tcg_gen_discard_i32(dc
->sar_m32
);
221 dc
->sar_m32_5bit
= false;
224 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
226 TCGv_i32 tmp
= tcg_const_i32(32);
227 if (!dc
->sar_m32_allocated
) {
228 dc
->sar_m32
= tcg_temp_local_new_i32();
229 dc
->sar_m32_allocated
= true;
231 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
232 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
233 dc
->sar_5bit
= false;
234 dc
->sar_m32_5bit
= true;
238 static void gen_advance_ccount(DisasContext
*dc
)
240 if (dc
->ccount_delta
> 0) {
241 TCGv_i32 tmp
= tcg_const_i32(dc
->ccount_delta
);
242 dc
->ccount_delta
= 0;
243 gen_helper_advance_ccount(tmp
);
248 static void reset_used_window(DisasContext
*dc
)
253 static void gen_exception(DisasContext
*dc
, int excp
)
255 TCGv_i32 tmp
= tcg_const_i32(excp
);
256 gen_advance_ccount(dc
);
257 gen_helper_exception(tmp
);
261 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
263 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
264 TCGv_i32 tcause
= tcg_const_i32(cause
);
265 gen_advance_ccount(dc
);
266 gen_helper_exception_cause(tpc
, tcause
);
268 tcg_temp_free(tcause
);
271 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
274 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
275 TCGv_i32 tcause
= tcg_const_i32(cause
);
276 gen_advance_ccount(dc
);
277 gen_helper_exception_cause_vaddr(tpc
, tcause
, vaddr
);
279 tcg_temp_free(tcause
);
282 static void gen_check_privilege(DisasContext
*dc
)
285 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
289 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
291 tcg_gen_mov_i32(cpu_pc
, dest
);
292 if (dc
->singlestep_enabled
) {
293 gen_exception(dc
, EXCP_DEBUG
);
295 gen_advance_ccount(dc
);
297 tcg_gen_goto_tb(slot
);
298 tcg_gen_exit_tb((tcg_target_long
)dc
->tb
+ slot
);
303 dc
->is_jmp
= DISAS_UPDATE
;
306 static void gen_jump(DisasContext
*dc
, TCGv dest
)
308 gen_jump_slot(dc
, dest
, -1);
311 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
313 TCGv_i32 tmp
= tcg_const_i32(dest
);
314 if (((dc
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
317 gen_jump_slot(dc
, tmp
, slot
);
321 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
324 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
326 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
327 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
328 tcg_temp_free(tcallinc
);
329 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
330 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
331 gen_jump_slot(dc
, dest
, slot
);
334 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
336 gen_callw_slot(dc
, callinc
, dest
, -1);
339 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
341 TCGv_i32 tmp
= tcg_const_i32(dest
);
342 if (((dc
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
345 gen_callw_slot(dc
, callinc
, tmp
, slot
);
349 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
351 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
352 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
353 dc
->next_pc
== dc
->lend
) {
354 int label
= gen_new_label();
356 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
357 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
358 gen_jumpi(dc
, dc
->lbeg
, slot
);
359 gen_set_label(label
);
360 gen_jumpi(dc
, dc
->next_pc
, -1);
366 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
368 if (!gen_check_loop_end(dc
, slot
)) {
369 gen_jumpi(dc
, dc
->next_pc
, slot
);
373 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
374 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
376 int label
= gen_new_label();
378 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
379 gen_jumpi_check_loop_end(dc
, 0);
380 gen_set_label(label
);
381 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
384 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
385 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
387 TCGv_i32 tmp
= tcg_const_i32(t1
);
388 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
392 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
394 gen_advance_ccount(dc
);
395 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
398 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
400 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
401 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
402 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
405 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
407 static void (* const rsr_handler
[256])(DisasContext
*dc
,
408 TCGv_i32 d
, uint32_t sr
) = {
409 [CCOUNT
] = gen_rsr_ccount
,
410 [PTEVADDR
] = gen_rsr_ptevaddr
,
414 if (rsr_handler
[sr
]) {
415 rsr_handler
[sr
](dc
, d
, sr
);
417 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
420 qemu_log("RSR %d not implemented, ", sr
);
424 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
426 gen_helper_wsr_lbeg(s
);
429 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
431 gen_helper_wsr_lend(s
);
434 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
436 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
437 if (dc
->sar_m32_5bit
) {
438 tcg_gen_discard_i32(dc
->sar_m32
);
440 dc
->sar_5bit
= false;
441 dc
->sar_m32_5bit
= false;
444 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
446 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
449 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
451 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
452 /* This can change tb->flags, so exit tb */
453 gen_jumpi_check_loop_end(dc
, -1);
456 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
458 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
461 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
463 gen_helper_wsr_windowbase(v
);
464 reset_used_window(dc
);
467 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
469 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
470 reset_used_window(dc
);
473 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
475 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
478 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
480 gen_helper_wsr_rasid(v
);
481 /* This can change tb->flags, so exit tb */
482 gen_jumpi_check_loop_end(dc
, -1);
485 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
487 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
490 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
492 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
493 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
494 gen_helper_check_interrupts(cpu_env
);
495 gen_jumpi_check_loop_end(dc
, 0);
498 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
500 TCGv_i32 tmp
= tcg_temp_new_i32();
502 tcg_gen_andi_i32(tmp
, v
,
503 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
504 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
505 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
506 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
508 gen_helper_check_interrupts(cpu_env
);
511 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
513 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
514 gen_helper_check_interrupts(cpu_env
);
515 gen_jumpi_check_loop_end(dc
, 0);
518 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
520 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
521 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
523 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
526 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
527 reset_used_window(dc
);
528 gen_helper_check_interrupts(cpu_env
);
529 /* This can change mmu index and tb->flags, so exit tb */
530 gen_jumpi_check_loop_end(dc
, -1);
533 static void gen_wsr_prid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
537 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
539 uint32_t id
= sr
- CCOMPARE
;
540 if (id
< dc
->config
->nccompare
) {
541 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
542 gen_advance_ccount(dc
);
543 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
544 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
545 gen_helper_check_interrupts(cpu_env
);
549 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
551 static void (* const wsr_handler
[256])(DisasContext
*dc
,
552 uint32_t sr
, TCGv_i32 v
) = {
553 [LBEG
] = gen_wsr_lbeg
,
554 [LEND
] = gen_wsr_lend
,
557 [LITBASE
] = gen_wsr_litbase
,
558 [ACCHI
] = gen_wsr_acchi
,
559 [WINDOW_BASE
] = gen_wsr_windowbase
,
560 [WINDOW_START
] = gen_wsr_windowstart
,
561 [PTEVADDR
] = gen_wsr_ptevaddr
,
562 [RASID
] = gen_wsr_rasid
,
563 [ITLBCFG
] = gen_wsr_tlbcfg
,
564 [DTLBCFG
] = gen_wsr_tlbcfg
,
565 [INTSET
] = gen_wsr_intset
,
566 [INTCLEAR
] = gen_wsr_intclear
,
567 [INTENABLE
] = gen_wsr_intenable
,
569 [PRID
] = gen_wsr_prid
,
570 [CCOMPARE
] = gen_wsr_ccompare
,
571 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
572 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
576 if (wsr_handler
[sr
]) {
577 wsr_handler
[sr
](dc
, sr
, s
);
579 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
582 qemu_log("WSR %d not implemented, ", sr
);
586 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
587 TCGv_i32 addr
, bool no_hw_alignment
)
589 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
590 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
591 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
593 int label
= gen_new_label();
594 TCGv_i32 tmp
= tcg_temp_new_i32();
595 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
596 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
597 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
598 gen_set_label(label
);
603 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
605 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
606 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
607 gen_advance_ccount(dc
);
608 gen_helper_waiti(pc
, intlevel
);
610 tcg_temp_free(intlevel
);
613 static void gen_window_check1(DisasContext
*dc
, unsigned r1
)
615 if (dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) {
618 if (option_enabled(dc
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
619 r1
/ 4 > dc
->used_window
) {
620 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
621 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
623 dc
->used_window
= r1
/ 4;
624 gen_advance_ccount(dc
);
625 gen_helper_window_check(pc
, w
);
632 static void gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
634 gen_window_check1(dc
, r1
> r2
? r1
: r2
);
637 static void gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
640 gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
643 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
645 TCGv_i32 m
= tcg_temp_new_i32();
648 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
650 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
655 static void disas_xtensa_insn(DisasContext
*dc
)
657 #define HAS_OPTION_BITS(opt) do { \
658 if (!option_bits_enabled(dc, opt)) { \
659 qemu_log("Option is not enabled %s:%d\n", \
660 __FILE__, __LINE__); \
661 goto invalid_opcode; \
665 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
667 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
668 #define RESERVED() do { \
669 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
670 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
671 goto invalid_opcode; \
675 #ifdef TARGET_WORDS_BIGENDIAN
676 #define OP0 (((b0) & 0xf0) >> 4)
677 #define OP1 (((b2) & 0xf0) >> 4)
678 #define OP2 ((b2) & 0xf)
679 #define RRR_R ((b1) & 0xf)
680 #define RRR_S (((b1) & 0xf0) >> 4)
681 #define RRR_T ((b0) & 0xf)
683 #define OP0 (((b0) & 0xf))
684 #define OP1 (((b2) & 0xf))
685 #define OP2 (((b2) & 0xf0) >> 4)
686 #define RRR_R (((b1) & 0xf0) >> 4)
687 #define RRR_S (((b1) & 0xf))
688 #define RRR_T (((b0) & 0xf0) >> 4)
690 #define RRR_X ((RRR_R & 0x4) >> 2)
691 #define RRR_Y ((RRR_T & 0x4) >> 2)
692 #define RRR_W (RRR_R & 0x3)
701 #define RRI8_IMM8 (b2)
702 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
704 #ifdef TARGET_WORDS_BIGENDIAN
705 #define RI16_IMM16 (((b1) << 8) | (b2))
707 #define RI16_IMM16 (((b2) << 8) | (b1))
710 #ifdef TARGET_WORDS_BIGENDIAN
711 #define CALL_N (((b0) & 0xc) >> 2)
712 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
714 #define CALL_N (((b0) & 0x30) >> 4)
715 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
717 #define CALL_OFFSET_SE \
718 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
720 #define CALLX_N CALL_N
721 #ifdef TARGET_WORDS_BIGENDIAN
722 #define CALLX_M ((b0) & 0x3)
724 #define CALLX_M (((b0) & 0xc0) >> 6)
726 #define CALLX_S RRR_S
728 #define BRI12_M CALLX_M
729 #define BRI12_S RRR_S
730 #ifdef TARGET_WORDS_BIGENDIAN
731 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
733 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
735 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
737 #define BRI8_M BRI12_M
738 #define BRI8_R RRI8_R
739 #define BRI8_S RRI8_S
740 #define BRI8_IMM8 RRI8_IMM8
741 #define BRI8_IMM8_SE RRI8_IMM8_SE
745 uint8_t b0
= ldub_code(dc
->pc
);
746 uint8_t b1
= ldub_code(dc
->pc
+ 1);
747 uint8_t b2
= ldub_code(dc
->pc
+ 2);
749 static const uint32_t B4CONST
[] = {
750 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
753 static const uint32_t B4CONSTU
[] = {
754 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
758 dc
->next_pc
= dc
->pc
+ 2;
759 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
761 dc
->next_pc
= dc
->pc
+ 3;
770 if ((RRR_R
& 0xc) == 0x8) {
771 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
778 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
789 gen_window_check1(dc
, CALLX_S
);
790 gen_jump(dc
, cpu_R
[CALLX_S
]);
794 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
796 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
797 gen_advance_ccount(dc
);
798 gen_helper_retw(tmp
, tmp
);
811 gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2);
815 TCGv_i32 tmp
= tcg_temp_new_i32();
816 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
817 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
826 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
828 TCGv_i32 tmp
= tcg_temp_new_i32();
830 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
831 gen_callw(dc
, CALLX_N
, tmp
);
841 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
842 gen_window_check2(dc
, RRR_T
, RRR_S
);
844 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
845 gen_advance_ccount(dc
);
846 gen_helper_movsp(pc
);
847 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
867 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
879 default: /*reserved*/
888 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
891 gen_check_privilege(dc
);
892 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
893 gen_helper_check_interrupts(cpu_env
);
894 gen_jump(dc
, cpu_SR
[EPC1
]);
902 gen_check_privilege(dc
);
904 dc
->config
->ndepc
? DEPC
: EPC1
]);
909 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
910 gen_check_privilege(dc
);
912 TCGv_i32 tmp
= tcg_const_i32(1);
915 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
916 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
919 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
920 cpu_SR
[WINDOW_START
], tmp
);
922 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
923 cpu_SR
[WINDOW_START
], tmp
);
926 gen_helper_restore_owb();
927 gen_helper_check_interrupts(cpu_env
);
928 gen_jump(dc
, cpu_SR
[EPC1
]);
934 default: /*reserved*/
941 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
942 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
943 gen_check_privilege(dc
);
944 tcg_gen_mov_i32(cpu_SR
[PS
],
945 cpu_SR
[EPS2
+ RRR_S
- 2]);
946 gen_helper_check_interrupts(cpu_env
);
947 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
949 qemu_log("RFI %d is illegal\n", RRR_S
);
950 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
958 default: /*reserved*/
966 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
971 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
974 gen_exception_cause(dc
, SYSCALL_CAUSE
);
978 if (semihosting_enabled
) {
979 gen_check_privilege(dc
);
980 gen_helper_simcall(cpu_env
);
982 qemu_log("SIMCALL but semihosting is disabled\n");
983 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
994 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
995 gen_check_privilege(dc
);
996 gen_window_check1(dc
, RRR_T
);
997 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
998 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
999 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1000 gen_helper_check_interrupts(cpu_env
);
1001 gen_jumpi_check_loop_end(dc
, 0);
1005 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1006 gen_check_privilege(dc
);
1007 gen_waiti(dc
, RRR_S
);
1014 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1016 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1017 TCGv_i32 mask
= tcg_const_i32(
1018 ((1 << shift
) - 1) << RRR_S
);
1019 TCGv_i32 tmp
= tcg_temp_new_i32();
1021 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1022 if (RRR_R
& 1) { /*ALL*/
1023 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1025 tcg_gen_add_i32(tmp
, tmp
, mask
);
1027 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1028 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1030 tcg_temp_free(mask
);
1035 default: /*reserved*/
1043 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1044 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1048 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1049 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1053 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1054 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1060 gen_window_check1(dc
, RRR_S
);
1061 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1065 gen_window_check1(dc
, RRR_S
);
1066 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1070 gen_window_check1(dc
, RRR_S
);
1072 TCGv_i32 tmp
= tcg_temp_new_i32();
1073 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1074 gen_right_shift_sar(dc
, tmp
);
1080 gen_window_check1(dc
, RRR_S
);
1082 TCGv_i32 tmp
= tcg_temp_new_i32();
1083 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1084 gen_left_shift_sar(dc
, tmp
);
1091 TCGv_i32 tmp
= tcg_const_i32(
1092 RRR_S
| ((RRR_T
& 1) << 4));
1093 gen_right_shift_sar(dc
, tmp
);
1107 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1108 gen_check_privilege(dc
);
1110 TCGv_i32 tmp
= tcg_const_i32(
1111 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1112 gen_helper_rotw(tmp
);
1114 reset_used_window(dc
);
1119 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1120 gen_window_check2(dc
, RRR_S
, RRR_T
);
1121 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1125 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1126 gen_window_check2(dc
, RRR_S
, RRR_T
);
1127 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1130 default: /*reserved*/
1138 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1139 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1140 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1141 gen_check_privilege(dc
);
1142 gen_window_check2(dc
, RRR_S
, RRR_T
);
1144 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1146 switch (RRR_R
& 7) {
1147 case 3: /*RITLB0*/ /*RDTLB0*/
1148 gen_helper_rtlb0(cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1151 case 4: /*IITLB*/ /*IDTLB*/
1152 gen_helper_itlb(cpu_R
[RRR_S
], dtlb
);
1153 /* This could change memory mapping, so exit tb */
1154 gen_jumpi_check_loop_end(dc
, -1);
1157 case 5: /*PITLB*/ /*PDTLB*/
1158 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1159 gen_helper_ptlb(cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1162 case 6: /*WITLB*/ /*WDTLB*/
1163 gen_helper_wtlb(cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1164 /* This could change memory mapping, so exit tb */
1165 gen_jumpi_check_loop_end(dc
, -1);
1168 case 7: /*RITLB1*/ /*RDTLB1*/
1169 gen_helper_rtlb1(cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1173 tcg_temp_free(dtlb
);
1177 tcg_temp_free(dtlb
);
1182 gen_window_check2(dc
, RRR_R
, RRR_T
);
1185 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1190 int label
= gen_new_label();
1191 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1192 tcg_gen_brcondi_i32(
1193 TCG_COND_GE
, cpu_R
[RRR_R
], 0, label
);
1194 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1195 gen_set_label(label
);
1199 default: /*reserved*/
1205 case 7: /*reserved*/
1210 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1211 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1217 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1219 TCGv_i32 tmp
= tcg_temp_new_i32();
1220 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1221 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1227 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1228 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1234 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1236 TCGv_i32 tmp
= tcg_temp_new_i32();
1237 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1238 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1249 gen_window_check2(dc
, RRR_R
, RRR_S
);
1250 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1251 32 - (RRR_T
| ((OP2
& 1) << 4)));
1256 gen_window_check2(dc
, RRR_R
, RRR_T
);
1257 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1258 RRR_S
| ((OP2
& 1) << 4));
1262 gen_window_check2(dc
, RRR_R
, RRR_T
);
1263 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1268 TCGv_i32 tmp
= tcg_temp_new_i32();
1270 gen_check_privilege(dc
);
1272 gen_window_check1(dc
, RRR_T
);
1273 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1274 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1275 gen_wsr(dc
, RSR_SR
, tmp
);
1277 if (!sregnames
[RSR_SR
]) {
1284 * Note: 64 bit ops are used here solely because SAR values
1287 #define gen_shift_reg(cmd, reg) do { \
1288 TCGv_i64 tmp = tcg_temp_new_i64(); \
1289 tcg_gen_extu_i32_i64(tmp, reg); \
1290 tcg_gen_##cmd##_i64(v, v, tmp); \
1291 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \
1292 tcg_temp_free_i64(v); \
1293 tcg_temp_free_i64(tmp); \
1296 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1299 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1301 TCGv_i64 v
= tcg_temp_new_i64();
1302 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1308 gen_window_check2(dc
, RRR_R
, RRR_T
);
1310 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1312 TCGv_i64 v
= tcg_temp_new_i64();
1313 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1319 gen_window_check2(dc
, RRR_R
, RRR_S
);
1320 if (dc
->sar_m32_5bit
) {
1321 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1323 TCGv_i64 v
= tcg_temp_new_i64();
1324 TCGv_i32 s
= tcg_const_i32(32);
1325 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1326 tcg_gen_andi_i32(s
, s
, 0x3f);
1327 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1328 gen_shift_reg(shl
, s
);
1334 gen_window_check2(dc
, RRR_R
, RRR_T
);
1336 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1338 TCGv_i64 v
= tcg_temp_new_i64();
1339 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1344 #undef gen_shift_reg
1347 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1348 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1350 TCGv_i32 v1
= tcg_temp_new_i32();
1351 TCGv_i32 v2
= tcg_temp_new_i32();
1352 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1353 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1354 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1361 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1362 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1364 TCGv_i32 v1
= tcg_temp_new_i32();
1365 TCGv_i32 v2
= tcg_temp_new_i32();
1366 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1367 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1368 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1374 default: /*reserved*/
1382 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1386 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1387 int label
= gen_new_label();
1388 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1389 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1390 gen_set_label(label
);
1394 #define BOOLEAN_LOGIC(fn, r, s, t) \
1396 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1397 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1398 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1400 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1401 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1402 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1403 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1404 tcg_temp_free(tmp1); \
1405 tcg_temp_free(tmp2); \
1409 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1413 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1417 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1421 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1425 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1428 #undef BOOLEAN_LOGIC
1431 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1432 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1437 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1439 TCGv_i64 r
= tcg_temp_new_i64();
1440 TCGv_i64 s
= tcg_temp_new_i64();
1441 TCGv_i64 t
= tcg_temp_new_i64();
1444 tcg_gen_extu_i32_i64(s
, cpu_R
[RRR_S
]);
1445 tcg_gen_extu_i32_i64(t
, cpu_R
[RRR_T
]);
1447 tcg_gen_ext_i32_i64(s
, cpu_R
[RRR_S
]);
1448 tcg_gen_ext_i32_i64(t
, cpu_R
[RRR_T
]);
1450 tcg_gen_mul_i64(r
, s
, t
);
1451 tcg_gen_shri_i64(r
, r
, 32);
1452 tcg_gen_trunc_i64_i32(cpu_R
[RRR_R
], r
);
1454 tcg_temp_free_i64(r
);
1455 tcg_temp_free_i64(s
);
1456 tcg_temp_free_i64(t
);
1461 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1467 int label1
= gen_new_label();
1468 int label2
= gen_new_label();
1470 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1472 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1474 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1475 OP2
== 13 ? 0x80000000 : 0);
1477 gen_set_label(label1
);
1479 tcg_gen_div_i32(cpu_R
[RRR_R
],
1480 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1482 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1483 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1485 gen_set_label(label2
);
1490 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1493 default: /*reserved*/
1503 gen_check_privilege(dc
);
1505 gen_window_check1(dc
, RRR_T
);
1506 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1507 if (!sregnames
[RSR_SR
]) {
1514 gen_check_privilege(dc
);
1516 gen_window_check1(dc
, RRR_T
);
1517 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1518 if (!sregnames
[RSR_SR
]) {
1524 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1525 gen_window_check2(dc
, RRR_R
, RRR_S
);
1527 int shift
= 24 - RRR_T
;
1530 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1531 } else if (shift
== 16) {
1532 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1534 TCGv_i32 tmp
= tcg_temp_new_i32();
1535 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1536 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1543 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1544 gen_window_check2(dc
, RRR_R
, RRR_S
);
1546 TCGv_i32 tmp1
= tcg_temp_new_i32();
1547 TCGv_i32 tmp2
= tcg_temp_new_i32();
1548 int label
= gen_new_label();
1550 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1551 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1552 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1553 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1554 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp2
, 0, label
);
1556 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1557 tcg_gen_xori_i32(cpu_R
[RRR_R
], tmp1
,
1558 0xffffffff >> (25 - RRR_T
));
1560 gen_set_label(label
);
1562 tcg_temp_free(tmp1
);
1563 tcg_temp_free(tmp2
);
1571 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1572 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1574 static const TCGCond cond
[] = {
1580 int label
= gen_new_label();
1582 if (RRR_R
!= RRR_T
) {
1583 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1584 tcg_gen_brcond_i32(cond
[OP2
- 4],
1585 cpu_R
[RRR_S
], cpu_R
[RRR_T
], label
);
1586 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1588 tcg_gen_brcond_i32(cond
[OP2
- 4],
1589 cpu_R
[RRR_T
], cpu_R
[RRR_S
], label
);
1590 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1592 gen_set_label(label
);
1600 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1602 static const TCGCond cond
[] = {
1608 int label
= gen_new_label();
1609 tcg_gen_brcondi_i32(cond
[OP2
- 8], cpu_R
[RRR_T
], 0, label
);
1610 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1611 gen_set_label(label
);
1617 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1618 gen_window_check2(dc
, RRR_R
, RRR_S
);
1620 int label
= gen_new_label();
1621 TCGv_i32 tmp
= tcg_temp_new_i32();
1623 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1624 tcg_gen_brcondi_i32(
1625 OP2
& 1 ? TCG_COND_EQ
: TCG_COND_NE
,
1627 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1628 gen_set_label(label
);
1634 gen_window_check1(dc
, RRR_R
);
1636 int st
= (RRR_S
<< 4) + RRR_T
;
1637 if (uregnames
[st
]) {
1638 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1640 qemu_log("RUR %d not implemented, ", st
);
1647 gen_window_check1(dc
, RRR_T
);
1649 if (uregnames
[RSR_SR
]) {
1650 tcg_gen_mov_i32(cpu_UR
[RSR_SR
], cpu_R
[RRR_T
]);
1652 qemu_log("WUR %d not implemented, ", RSR_SR
);
1663 gen_window_check2(dc
, RRR_R
, RRR_T
);
1665 int shiftimm
= RRR_S
| (OP1
<< 4);
1666 int maskimm
= (1 << (OP2
+ 1)) - 1;
1668 TCGv_i32 tmp
= tcg_temp_new_i32();
1669 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1670 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1684 HAS_OPTION(XTENSA_OPTION_COPROCESSOR
);
1689 gen_window_check2(dc
, RRR_S
, RRR_T
);
1692 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1693 gen_check_privilege(dc
);
1695 TCGv_i32 addr
= tcg_temp_new_i32();
1696 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1697 (0xffffffc0 | (RRR_R
<< 2)));
1698 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1699 tcg_temp_free(addr
);
1704 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1705 gen_check_privilege(dc
);
1707 TCGv_i32 addr
= tcg_temp_new_i32();
1708 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1709 (0xffffffc0 | (RRR_R
<< 2)));
1710 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1711 tcg_temp_free(addr
);
1722 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1727 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1731 default: /*reserved*/
1738 gen_window_check1(dc
, RRR_T
);
1740 TCGv_i32 tmp
= tcg_const_i32(
1741 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
1742 0 : ((dc
->pc
+ 3) & ~3)) +
1743 (0xfffc0000 | (RI16_IMM16
<< 2)));
1745 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
1746 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
1748 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
1754 #define gen_load_store(type, shift) do { \
1755 TCGv_i32 addr = tcg_temp_new_i32(); \
1756 gen_window_check2(dc, RRI8_S, RRI8_T); \
1757 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
1759 gen_load_store_alignment(dc, shift, addr, false); \
1761 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
1762 tcg_temp_free(addr); \
1767 gen_load_store(ld8u
, 0);
1771 gen_load_store(ld16u
, 1);
1775 gen_load_store(ld32u
, 2);
1779 gen_load_store(st8
, 0);
1783 gen_load_store(st16
, 1);
1787 gen_load_store(st32
, 2);
1792 HAS_OPTION(XTENSA_OPTION_DCACHE
);
1823 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
1827 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
1831 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
1835 HAS_OPTION(XTENSA_OPTION_DCACHE
);
1839 HAS_OPTION(XTENSA_OPTION_DCACHE
);
1842 default: /*reserved*/
1850 HAS_OPTION(XTENSA_OPTION_ICACHE
);
1856 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
1860 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
1864 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
1867 default: /*reserved*/
1874 HAS_OPTION(XTENSA_OPTION_ICACHE
);
1878 HAS_OPTION(XTENSA_OPTION_ICACHE
);
1881 default: /*reserved*/
1888 gen_load_store(ld16s
, 1);
1890 #undef gen_load_store
1893 gen_window_check1(dc
, RRI8_T
);
1894 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
1895 RRI8_IMM8
| (RRI8_S
<< 8) |
1896 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
1899 #define gen_load_store_no_hw_align(type) do { \
1900 TCGv_i32 addr = tcg_temp_local_new_i32(); \
1901 gen_window_check2(dc, RRI8_S, RRI8_T); \
1902 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
1903 gen_load_store_alignment(dc, 2, addr, true); \
1904 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
1905 tcg_temp_free(addr); \
1909 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
1910 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
1914 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
1915 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
1919 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
1920 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
<< 8);
1923 case 14: /*S32C1Iy*/
1924 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
1925 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
1927 int label
= gen_new_label();
1928 TCGv_i32 tmp
= tcg_temp_local_new_i32();
1929 TCGv_i32 addr
= tcg_temp_local_new_i32();
1931 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
1932 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
1933 gen_load_store_alignment(dc
, 2, addr
, true);
1934 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
1935 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
1936 cpu_SR
[SCOMPARE1
], label
);
1938 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
1940 gen_set_label(label
);
1941 tcg_temp_free(addr
);
1947 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
1948 gen_load_store_no_hw_align(st32
); /*TODO release?*/
1950 #undef gen_load_store_no_hw_align
1952 default: /*reserved*/
1959 HAS_OPTION(XTENSA_OPTION_COPROCESSOR
);
1964 HAS_OPTION(XTENSA_OPTION_MAC16
);
1973 bool is_m1_sr
= (OP2
& 0x3) == 2;
1974 bool is_m2_sr
= (OP2
& 0xc) == 0;
1975 uint32_t ld_offset
= 0;
1982 case 0: /*MACI?/MACC?*/
1984 ld_offset
= (OP2
& 1) ? -4 : 4;
1986 if (OP2
>= 8) { /*MACI/MACC*/
1987 if (OP1
== 0) { /*LDINC/LDDEC*/
1992 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
1997 case 2: /*MACD?/MACA?*/
1998 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2004 if (op
!= MAC16_NONE
) {
2006 gen_window_check1(dc
, RRR_S
);
2009 gen_window_check1(dc
, RRR_T
);
2014 TCGv_i32 vaddr
= tcg_temp_new_i32();
2015 TCGv_i32 mem32
= tcg_temp_new_i32();
2018 gen_window_check1(dc
, RRR_S
);
2019 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2020 gen_load_store_alignment(dc
, 2, vaddr
, false);
2021 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2023 if (op
!= MAC16_NONE
) {
2024 TCGv_i32 m1
= gen_mac16_m(
2025 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2026 OP1
& 1, op
== MAC16_UMUL
);
2027 TCGv_i32 m2
= gen_mac16_m(
2028 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2029 OP1
& 2, op
== MAC16_UMUL
);
2031 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2032 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2033 if (op
== MAC16_UMUL
) {
2034 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2036 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2039 TCGv_i32 res
= tcg_temp_new_i32();
2040 TCGv_i64 res64
= tcg_temp_new_i64();
2041 TCGv_i64 tmp
= tcg_temp_new_i64();
2043 tcg_gen_mul_i32(res
, m1
, m2
);
2044 tcg_gen_ext_i32_i64(res64
, res
);
2045 tcg_gen_concat_i32_i64(tmp
,
2046 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
]);
2047 if (op
== MAC16_MULA
) {
2048 tcg_gen_add_i64(tmp
, tmp
, res64
);
2050 tcg_gen_sub_i64(tmp
, tmp
, res64
);
2052 tcg_gen_trunc_i64_i32(cpu_SR
[ACCLO
], tmp
);
2053 tcg_gen_shri_i64(tmp
, tmp
, 32);
2054 tcg_gen_trunc_i64_i32(cpu_SR
[ACCHI
], tmp
);
2055 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2058 tcg_temp_free_i64(res64
);
2059 tcg_temp_free_i64(tmp
);
2065 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2066 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2068 tcg_temp_free(vaddr
);
2069 tcg_temp_free(mem32
);
2077 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2078 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2084 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2085 gen_window_check1(dc
, CALL_N
<< 2);
2086 gen_callwi(dc
, CALL_N
,
2087 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2095 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2099 gen_window_check1(dc
, BRI12_S
);
2101 static const TCGCond cond
[] = {
2102 TCG_COND_EQ
, /*BEQZ*/
2103 TCG_COND_NE
, /*BNEZ*/
2104 TCG_COND_LT
, /*BLTZ*/
2105 TCG_COND_GE
, /*BGEZ*/
2108 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2109 4 + BRI12_IMM12_SE
);
2114 gen_window_check1(dc
, BRI8_S
);
2116 static const TCGCond cond
[] = {
2117 TCG_COND_EQ
, /*BEQI*/
2118 TCG_COND_NE
, /*BNEI*/
2119 TCG_COND_LT
, /*BLTI*/
2120 TCG_COND_GE
, /*BGEI*/
2123 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2124 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2131 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2133 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2134 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2135 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2136 gen_advance_ccount(dc
);
2137 gen_helper_entry(pc
, s
, imm
);
2141 reset_used_window(dc
);
2149 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2151 TCGv_i32 tmp
= tcg_temp_new_i32();
2152 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2154 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2155 tmp
, 0, 4 + RRI8_IMM8_SE
);
2162 case 10: /*LOOPGTZ*/
2163 HAS_OPTION(XTENSA_OPTION_LOOP
);
2164 gen_window_check1(dc
, RRI8_S
);
2166 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2167 TCGv_i32 tmp
= tcg_const_i32(lend
);
2169 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2170 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2171 gen_wsr_lend(dc
, LEND
, tmp
);
2175 int label
= gen_new_label();
2176 tcg_gen_brcondi_i32(
2177 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2178 cpu_R
[RRI8_S
], 0, label
);
2179 gen_jumpi(dc
, lend
, 1);
2180 gen_set_label(label
);
2183 gen_jumpi(dc
, dc
->next_pc
, 0);
2187 default: /*reserved*/
2196 gen_window_check1(dc
, BRI8_S
);
2197 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2198 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2208 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2210 switch (RRI8_R
& 7) {
2211 case 0: /*BNONE*/ /*BANY*/
2212 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2214 TCGv_i32 tmp
= tcg_temp_new_i32();
2215 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2216 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2221 case 1: /*BEQ*/ /*BNE*/
2222 case 2: /*BLT*/ /*BGE*/
2223 case 3: /*BLTU*/ /*BGEU*/
2224 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2226 static const TCGCond cond
[] = {
2232 [11] = TCG_COND_GEU
,
2234 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2239 case 4: /*BALL*/ /*BNALL*/
2240 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2242 TCGv_i32 tmp
= tcg_temp_new_i32();
2243 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2244 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2250 case 5: /*BBC*/ /*BBS*/
2251 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2253 TCGv_i32 bit
= tcg_const_i32(1);
2254 TCGv_i32 tmp
= tcg_temp_new_i32();
2255 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2256 tcg_gen_shl_i32(bit
, bit
, tmp
);
2257 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2258 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2264 case 6: /*BBCI*/ /*BBSI*/
2266 gen_window_check1(dc
, RRI8_S
);
2268 TCGv_i32 tmp
= tcg_temp_new_i32();
2269 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2270 1 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2271 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2280 #define gen_narrow_load_store(type) do { \
2281 TCGv_i32 addr = tcg_temp_new_i32(); \
2282 gen_window_check2(dc, RRRN_S, RRRN_T); \
2283 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2284 gen_load_store_alignment(dc, 2, addr, false); \
2285 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2286 tcg_temp_free(addr); \
2290 gen_narrow_load_store(ld32u
);
2294 gen_narrow_load_store(st32
);
2296 #undef gen_narrow_load_store
2299 gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
);
2300 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2303 case 11: /*ADDI.Nn*/
2304 gen_window_check2(dc
, RRRN_R
, RRRN_S
);
2305 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], RRRN_T
? RRRN_T
: -1);
2309 gen_window_check1(dc
, RRRN_S
);
2310 if (RRRN_T
< 8) { /*MOVI.Nn*/
2311 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2312 RRRN_R
| (RRRN_T
<< 4) |
2313 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2314 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2315 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2317 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2318 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2325 gen_window_check2(dc
, RRRN_S
, RRRN_T
);
2326 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2332 gen_jump(dc
, cpu_R
[0]);
2336 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2338 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2339 gen_advance_ccount(dc
);
2340 gen_helper_retw(tmp
, tmp
);
2346 case 2: /*BREAK.Nn*/
2354 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2357 default: /*reserved*/
2363 default: /*reserved*/
2369 default: /*reserved*/
2374 gen_check_loop_end(dc
, 0);
2375 dc
->pc
= dc
->next_pc
;
2380 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2381 dc
->pc
= dc
->next_pc
;
2385 static void check_breakpoint(CPUState
*env
, DisasContext
*dc
)
2389 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2390 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2391 if (bp
->pc
== dc
->pc
) {
2392 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2393 gen_exception(dc
, EXCP_DEBUG
);
2394 dc
->is_jmp
= DISAS_UPDATE
;
2400 static void gen_intermediate_code_internal(
2401 CPUState
*env
, TranslationBlock
*tb
, int search_pc
)
2406 uint16_t *gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
2407 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2408 uint32_t pc_start
= tb
->pc
;
2409 uint32_t next_page_start
=
2410 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2412 if (max_insns
== 0) {
2413 max_insns
= CF_COUNT_MASK
;
2416 dc
.config
= env
->config
;
2417 dc
.singlestep_enabled
= env
->singlestep_enabled
;
2420 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
2421 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
2422 dc
.lbeg
= env
->sregs
[LBEG
];
2423 dc
.lend
= env
->sregs
[LEND
];
2424 dc
.is_jmp
= DISAS_NEXT
;
2425 dc
.ccount_delta
= 0;
2428 init_sar_tracker(&dc
);
2429 reset_used_window(&dc
);
2433 if (env
->singlestep_enabled
&& env
->exception_taken
) {
2434 env
->exception_taken
= 0;
2435 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2436 gen_exception(&dc
, EXCP_DEBUG
);
2440 check_breakpoint(env
, &dc
);
2443 j
= gen_opc_ptr
- gen_opc_buf
;
2447 gen_opc_instr_start
[lj
++] = 0;
2450 gen_opc_pc
[lj
] = dc
.pc
;
2451 gen_opc_instr_start
[lj
] = 1;
2452 gen_opc_icount
[lj
] = insn_count
;
2455 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
))) {
2456 tcg_gen_debug_insn_start(dc
.pc
);
2461 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
2465 disas_xtensa_insn(&dc
);
2467 if (env
->singlestep_enabled
) {
2468 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2469 gen_exception(&dc
, EXCP_DEBUG
);
2472 } while (dc
.is_jmp
== DISAS_NEXT
&&
2473 insn_count
< max_insns
&&
2474 dc
.pc
< next_page_start
&&
2475 gen_opc_ptr
< gen_opc_end
);
2478 reset_sar_tracker(&dc
);
2480 if (tb
->cflags
& CF_LAST_IO
) {
2484 if (dc
.is_jmp
== DISAS_NEXT
) {
2485 gen_jumpi(&dc
, dc
.pc
, 0);
2487 gen_icount_end(tb
, insn_count
);
2488 *gen_opc_ptr
= INDEX_op_end
;
2491 tb
->size
= dc
.pc
- pc_start
;
2492 tb
->icount
= insn_count
;
2496 void gen_intermediate_code(CPUState
*env
, TranslationBlock
*tb
)
2498 gen_intermediate_code_internal(env
, tb
, 0);
2501 void gen_intermediate_code_pc(CPUState
*env
, TranslationBlock
*tb
)
2503 gen_intermediate_code_internal(env
, tb
, 1);
2506 void cpu_dump_state(CPUState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
2511 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
2513 for (i
= j
= 0; i
< 256; ++i
) {
2515 cpu_fprintf(f
, "%s=%08x%c", sregnames
[i
], env
->sregs
[i
],
2516 (j
++ % 4) == 3 ? '\n' : ' ');
2520 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
2522 for (i
= j
= 0; i
< 256; ++i
) {
2524 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
], env
->uregs
[i
],
2525 (j
++ % 4) == 3 ? '\n' : ' ');
2529 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
2531 for (i
= 0; i
< 16; ++i
) {
2532 cpu_fprintf(f
, "A%02d=%08x%c", i
, env
->regs
[i
],
2533 (i
% 4) == 3 ? '\n' : ' ');
2536 cpu_fprintf(f
, "\n");
2538 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
2539 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
2540 (i
% 4) == 3 ? '\n' : ' ');
2544 void restore_state_to_opc(CPUState
*env
, TranslationBlock
*tb
, int pc_pos
)
2546 env
->pc
= gen_opc_pc
[pc_pos
];