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 typedef struct XtensaReg
{
93 #define XTENSA_REG_ACCESS(regname, opt, acc) { \
95 .opt_bits = XTENSA_OPTION_BIT(opt), \
99 #define XTENSA_REG(regname, opt) XTENSA_REG_ACCESS(regname, opt, SR_RWX)
101 #define XTENSA_REG_BITS(regname, opt) { \
107 static const XtensaReg sregnames
[256] = {
108 [LBEG
] = XTENSA_REG("LBEG", XTENSA_OPTION_LOOP
),
109 [LEND
] = XTENSA_REG("LEND", XTENSA_OPTION_LOOP
),
110 [LCOUNT
] = XTENSA_REG("LCOUNT", XTENSA_OPTION_LOOP
),
111 [SAR
] = XTENSA_REG_BITS("SAR", XTENSA_OPTION_ALL
),
112 [BR
] = XTENSA_REG("BR", XTENSA_OPTION_BOOLEAN
),
113 [LITBASE
] = XTENSA_REG("LITBASE", XTENSA_OPTION_EXTENDED_L32R
),
114 [SCOMPARE1
] = XTENSA_REG("SCOMPARE1", XTENSA_OPTION_CONDITIONAL_STORE
),
115 [ACCLO
] = XTENSA_REG("ACCLO", XTENSA_OPTION_MAC16
),
116 [ACCHI
] = XTENSA_REG("ACCHI", XTENSA_OPTION_MAC16
),
117 [MR
] = XTENSA_REG("MR0", XTENSA_OPTION_MAC16
),
118 [MR
+ 1] = XTENSA_REG("MR1", XTENSA_OPTION_MAC16
),
119 [MR
+ 2] = XTENSA_REG("MR2", XTENSA_OPTION_MAC16
),
120 [MR
+ 3] = XTENSA_REG("MR3", XTENSA_OPTION_MAC16
),
121 [WINDOW_BASE
] = XTENSA_REG("WINDOW_BASE", XTENSA_OPTION_WINDOWED_REGISTER
),
122 [WINDOW_START
] = XTENSA_REG("WINDOW_START",
123 XTENSA_OPTION_WINDOWED_REGISTER
),
124 [PTEVADDR
] = XTENSA_REG("PTEVADDR", XTENSA_OPTION_MMU
),
125 [RASID
] = XTENSA_REG("RASID", XTENSA_OPTION_MMU
),
126 [ITLBCFG
] = XTENSA_REG("ITLBCFG", XTENSA_OPTION_MMU
),
127 [DTLBCFG
] = XTENSA_REG("DTLBCFG", XTENSA_OPTION_MMU
),
128 [IBREAKENABLE
] = XTENSA_REG("IBREAKENABLE", XTENSA_OPTION_DEBUG
),
129 [CACHEATTR
] = XTENSA_REG("CACHEATTR", XTENSA_OPTION_CACHEATTR
),
130 [ATOMCTL
] = XTENSA_REG("ATOMCTL", XTENSA_OPTION_ATOMCTL
),
131 [IBREAKA
] = XTENSA_REG("IBREAKA0", XTENSA_OPTION_DEBUG
),
132 [IBREAKA
+ 1] = XTENSA_REG("IBREAKA1", XTENSA_OPTION_DEBUG
),
133 [DBREAKA
] = XTENSA_REG("DBREAKA0", XTENSA_OPTION_DEBUG
),
134 [DBREAKA
+ 1] = XTENSA_REG("DBREAKA1", XTENSA_OPTION_DEBUG
),
135 [DBREAKC
] = XTENSA_REG("DBREAKC0", XTENSA_OPTION_DEBUG
),
136 [DBREAKC
+ 1] = XTENSA_REG("DBREAKC1", XTENSA_OPTION_DEBUG
),
137 [EPC1
] = XTENSA_REG("EPC1", XTENSA_OPTION_EXCEPTION
),
138 [EPC1
+ 1] = XTENSA_REG("EPC2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
139 [EPC1
+ 2] = XTENSA_REG("EPC3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
140 [EPC1
+ 3] = XTENSA_REG("EPC4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
141 [EPC1
+ 4] = XTENSA_REG("EPC5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
142 [EPC1
+ 5] = XTENSA_REG("EPC6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
143 [EPC1
+ 6] = XTENSA_REG("EPC7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
144 [DEPC
] = XTENSA_REG("DEPC", XTENSA_OPTION_EXCEPTION
),
145 [EPS2
] = XTENSA_REG("EPS2", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
146 [EPS2
+ 1] = XTENSA_REG("EPS3", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
147 [EPS2
+ 2] = XTENSA_REG("EPS4", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
148 [EPS2
+ 3] = XTENSA_REG("EPS5", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
149 [EPS2
+ 4] = XTENSA_REG("EPS6", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
150 [EPS2
+ 5] = XTENSA_REG("EPS7", XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
151 [EXCSAVE1
] = XTENSA_REG("EXCSAVE1", XTENSA_OPTION_EXCEPTION
),
152 [EXCSAVE1
+ 1] = XTENSA_REG("EXCSAVE2",
153 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
154 [EXCSAVE1
+ 2] = XTENSA_REG("EXCSAVE3",
155 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
156 [EXCSAVE1
+ 3] = XTENSA_REG("EXCSAVE4",
157 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
158 [EXCSAVE1
+ 4] = XTENSA_REG("EXCSAVE5",
159 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
160 [EXCSAVE1
+ 5] = XTENSA_REG("EXCSAVE6",
161 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
162 [EXCSAVE1
+ 6] = XTENSA_REG("EXCSAVE7",
163 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
),
164 [CPENABLE
] = XTENSA_REG("CPENABLE", XTENSA_OPTION_COPROCESSOR
),
165 [INTSET
] = XTENSA_REG_ACCESS("INTSET", XTENSA_OPTION_INTERRUPT
, SR_RW
),
166 [INTCLEAR
] = XTENSA_REG_ACCESS("INTCLEAR", XTENSA_OPTION_INTERRUPT
, SR_W
),
167 [INTENABLE
] = XTENSA_REG("INTENABLE", XTENSA_OPTION_INTERRUPT
),
168 [PS
] = XTENSA_REG_BITS("PS", XTENSA_OPTION_ALL
),
169 [VECBASE
] = XTENSA_REG("VECBASE", XTENSA_OPTION_RELOCATABLE_VECTOR
),
170 [EXCCAUSE
] = XTENSA_REG("EXCCAUSE", XTENSA_OPTION_EXCEPTION
),
171 [DEBUGCAUSE
] = XTENSA_REG_ACCESS("DEBUGCAUSE", XTENSA_OPTION_DEBUG
, SR_R
),
172 [CCOUNT
] = XTENSA_REG("CCOUNT", XTENSA_OPTION_TIMER_INTERRUPT
),
173 [PRID
] = XTENSA_REG_ACCESS("PRID", XTENSA_OPTION_PROCESSOR_ID
, SR_R
),
174 [ICOUNT
] = XTENSA_REG("ICOUNT", XTENSA_OPTION_DEBUG
),
175 [ICOUNTLEVEL
] = XTENSA_REG("ICOUNTLEVEL", XTENSA_OPTION_DEBUG
),
176 [EXCVADDR
] = XTENSA_REG("EXCVADDR", XTENSA_OPTION_EXCEPTION
),
177 [CCOMPARE
] = XTENSA_REG("CCOMPARE0", XTENSA_OPTION_TIMER_INTERRUPT
),
178 [CCOMPARE
+ 1] = XTENSA_REG("CCOMPARE1",
179 XTENSA_OPTION_TIMER_INTERRUPT
),
180 [CCOMPARE
+ 2] = XTENSA_REG("CCOMPARE2",
181 XTENSA_OPTION_TIMER_INTERRUPT
),
184 static const XtensaReg uregnames
[256] = {
185 [THREADPTR
] = XTENSA_REG("THREADPTR", XTENSA_OPTION_THREAD_POINTER
),
186 [FCR
] = XTENSA_REG("FCR", XTENSA_OPTION_FP_COPROCESSOR
),
187 [FSR
] = XTENSA_REG("FSR", XTENSA_OPTION_FP_COPROCESSOR
),
190 void xtensa_translate_init(void)
192 static const char * const regnames
[] = {
193 "ar0", "ar1", "ar2", "ar3",
194 "ar4", "ar5", "ar6", "ar7",
195 "ar8", "ar9", "ar10", "ar11",
196 "ar12", "ar13", "ar14", "ar15",
198 static const char * const fregnames
[] = {
199 "f0", "f1", "f2", "f3",
200 "f4", "f5", "f6", "f7",
201 "f8", "f9", "f10", "f11",
202 "f12", "f13", "f14", "f15",
206 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
207 cpu_pc
= tcg_global_mem_new_i32(TCG_AREG0
,
208 offsetof(CPUXtensaState
, pc
), "pc");
210 for (i
= 0; i
< 16; i
++) {
211 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
212 offsetof(CPUXtensaState
, regs
[i
]),
216 for (i
= 0; i
< 16; i
++) {
217 cpu_FR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
218 offsetof(CPUXtensaState
, fregs
[i
]),
222 for (i
= 0; i
< 256; ++i
) {
223 if (sregnames
[i
].name
) {
224 cpu_SR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
225 offsetof(CPUXtensaState
, sregs
[i
]),
230 for (i
= 0; i
< 256; ++i
) {
231 if (uregnames
[i
].name
) {
232 cpu_UR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
233 offsetof(CPUXtensaState
, uregs
[i
]),
241 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
243 return xtensa_option_bits_enabled(dc
->config
, opt
);
246 static inline bool option_enabled(DisasContext
*dc
, int opt
)
248 return xtensa_option_enabled(dc
->config
, opt
);
251 static void init_litbase(DisasContext
*dc
)
253 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
254 dc
->litbase
= tcg_temp_local_new_i32();
255 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
259 static void reset_litbase(DisasContext
*dc
)
261 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
262 tcg_temp_free(dc
->litbase
);
266 static void init_sar_tracker(DisasContext
*dc
)
268 dc
->sar_5bit
= false;
269 dc
->sar_m32_5bit
= false;
270 dc
->sar_m32_allocated
= false;
273 static void reset_sar_tracker(DisasContext
*dc
)
275 if (dc
->sar_m32_allocated
) {
276 tcg_temp_free(dc
->sar_m32
);
280 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
282 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
283 if (dc
->sar_m32_5bit
) {
284 tcg_gen_discard_i32(dc
->sar_m32
);
287 dc
->sar_m32_5bit
= false;
290 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
292 TCGv_i32 tmp
= tcg_const_i32(32);
293 if (!dc
->sar_m32_allocated
) {
294 dc
->sar_m32
= tcg_temp_local_new_i32();
295 dc
->sar_m32_allocated
= true;
297 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
298 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
299 dc
->sar_5bit
= false;
300 dc
->sar_m32_5bit
= true;
304 static void gen_advance_ccount(DisasContext
*dc
)
306 if (dc
->ccount_delta
> 0) {
307 TCGv_i32 tmp
= tcg_const_i32(dc
->ccount_delta
);
308 dc
->ccount_delta
= 0;
309 gen_helper_advance_ccount(cpu_env
, tmp
);
314 static void reset_used_window(DisasContext
*dc
)
319 static void gen_exception(DisasContext
*dc
, int excp
)
321 TCGv_i32 tmp
= tcg_const_i32(excp
);
322 gen_advance_ccount(dc
);
323 gen_helper_exception(cpu_env
, tmp
);
327 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
329 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
330 TCGv_i32 tcause
= tcg_const_i32(cause
);
331 gen_advance_ccount(dc
);
332 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
334 tcg_temp_free(tcause
);
335 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
336 cause
== SYSCALL_CAUSE
) {
337 dc
->is_jmp
= DISAS_UPDATE
;
341 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
344 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
345 TCGv_i32 tcause
= tcg_const_i32(cause
);
346 gen_advance_ccount(dc
);
347 gen_helper_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
349 tcg_temp_free(tcause
);
352 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
354 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
355 TCGv_i32 tcause
= tcg_const_i32(cause
);
356 gen_advance_ccount(dc
);
357 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
359 tcg_temp_free(tcause
);
360 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
361 dc
->is_jmp
= DISAS_UPDATE
;
365 static void gen_check_privilege(DisasContext
*dc
)
368 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
369 dc
->is_jmp
= DISAS_UPDATE
;
373 static void gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
375 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
376 !(dc
->cpenable
& (1 << cp
))) {
377 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
378 dc
->is_jmp
= DISAS_UPDATE
;
382 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
384 tcg_gen_mov_i32(cpu_pc
, dest
);
385 gen_advance_ccount(dc
);
387 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
->next_icount
);
389 if (dc
->singlestep_enabled
) {
390 gen_exception(dc
, EXCP_DEBUG
);
393 tcg_gen_goto_tb(slot
);
394 tcg_gen_exit_tb((tcg_target_long
)dc
->tb
+ slot
);
399 dc
->is_jmp
= DISAS_UPDATE
;
402 static void gen_jump(DisasContext
*dc
, TCGv dest
)
404 gen_jump_slot(dc
, dest
, -1);
407 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
409 TCGv_i32 tmp
= tcg_const_i32(dest
);
410 if (((dc
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
413 gen_jump_slot(dc
, tmp
, slot
);
417 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
420 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
422 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
423 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
424 tcg_temp_free(tcallinc
);
425 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
426 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
427 gen_jump_slot(dc
, dest
, slot
);
430 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
432 gen_callw_slot(dc
, callinc
, dest
, -1);
435 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
437 TCGv_i32 tmp
= tcg_const_i32(dest
);
438 if (((dc
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
441 gen_callw_slot(dc
, callinc
, tmp
, slot
);
445 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
447 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
448 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
449 dc
->next_pc
== dc
->lend
) {
450 int label
= gen_new_label();
452 gen_advance_ccount(dc
);
453 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
454 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
455 gen_jumpi(dc
, dc
->lbeg
, slot
);
456 gen_set_label(label
);
457 gen_jumpi(dc
, dc
->next_pc
, -1);
463 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
465 if (!gen_check_loop_end(dc
, slot
)) {
466 gen_jumpi(dc
, dc
->next_pc
, slot
);
470 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
471 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
473 int label
= gen_new_label();
475 gen_advance_ccount(dc
);
476 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
477 gen_jumpi_check_loop_end(dc
, 0);
478 gen_set_label(label
);
479 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
482 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
483 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
485 TCGv_i32 tmp
= tcg_const_i32(t1
);
486 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
490 static void gen_check_sr(DisasContext
*dc
, uint32_t sr
, unsigned access
)
492 if (!xtensa_option_bits_enabled(dc
->config
, sregnames
[sr
].opt_bits
)) {
493 if (sregnames
[sr
].name
) {
494 qemu_log("SR %s is not configured\n", sregnames
[sr
].name
);
496 qemu_log("SR %d is not implemented\n", sr
);
498 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
499 } else if (!(sregnames
[sr
].access
& access
)) {
500 static const char * const access_text
[] = {
505 assert(access
< ARRAY_SIZE(access_text
) && access_text
[access
]);
506 qemu_log("SR %s is not available for %s\n", sregnames
[sr
].name
,
507 access_text
[access
]);
508 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
512 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
514 gen_advance_ccount(dc
);
515 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
518 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
520 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
521 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
522 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
525 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
527 static void (* const rsr_handler
[256])(DisasContext
*dc
,
528 TCGv_i32 d
, uint32_t sr
) = {
529 [CCOUNT
] = gen_rsr_ccount
,
530 [PTEVADDR
] = gen_rsr_ptevaddr
,
533 if (rsr_handler
[sr
]) {
534 rsr_handler
[sr
](dc
, d
, sr
);
536 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
540 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
542 gen_helper_wsr_lbeg(cpu_env
, s
);
543 gen_jumpi_check_loop_end(dc
, 0);
546 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
548 gen_helper_wsr_lend(cpu_env
, s
);
549 gen_jumpi_check_loop_end(dc
, 0);
552 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
554 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
555 if (dc
->sar_m32_5bit
) {
556 tcg_gen_discard_i32(dc
->sar_m32
);
558 dc
->sar_5bit
= false;
559 dc
->sar_m32_5bit
= false;
562 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
564 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
567 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
569 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
570 /* This can change tb->flags, so exit tb */
571 gen_jumpi_check_loop_end(dc
, -1);
574 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
576 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
579 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
581 gen_helper_wsr_windowbase(cpu_env
, v
);
582 reset_used_window(dc
);
585 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
587 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
588 reset_used_window(dc
);
591 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
593 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
596 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
598 gen_helper_wsr_rasid(cpu_env
, v
);
599 /* This can change tb->flags, so exit tb */
600 gen_jumpi_check_loop_end(dc
, -1);
603 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
605 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
608 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
610 gen_helper_wsr_ibreakenable(cpu_env
, v
);
611 gen_jumpi_check_loop_end(dc
, 0);
614 static void gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
616 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
619 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
621 unsigned id
= sr
- IBREAKA
;
623 if (id
< dc
->config
->nibreak
) {
624 TCGv_i32 tmp
= tcg_const_i32(id
);
625 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
627 gen_jumpi_check_loop_end(dc
, 0);
631 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
633 unsigned id
= sr
- DBREAKA
;
635 if (id
< dc
->config
->ndbreak
) {
636 TCGv_i32 tmp
= tcg_const_i32(id
);
637 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
642 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
644 unsigned id
= sr
- DBREAKC
;
646 if (id
< dc
->config
->ndbreak
) {
647 TCGv_i32 tmp
= tcg_const_i32(id
);
648 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
653 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
655 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
656 /* This can change tb->flags, so exit tb */
657 gen_jumpi_check_loop_end(dc
, -1);
660 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
662 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
663 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
664 gen_helper_check_interrupts(cpu_env
);
665 gen_jumpi_check_loop_end(dc
, 0);
668 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
670 TCGv_i32 tmp
= tcg_temp_new_i32();
672 tcg_gen_andi_i32(tmp
, v
,
673 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
674 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
675 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
676 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
678 gen_helper_check_interrupts(cpu_env
);
681 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
683 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
684 gen_helper_check_interrupts(cpu_env
);
685 gen_jumpi_check_loop_end(dc
, 0);
688 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
690 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
691 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
693 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
696 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
697 reset_used_window(dc
);
698 gen_helper_check_interrupts(cpu_env
);
699 /* This can change mmu index and tb->flags, so exit tb */
700 gen_jumpi_check_loop_end(dc
, -1);
703 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
706 tcg_gen_mov_i32(dc
->next_icount
, v
);
708 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
712 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
714 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
715 /* This can change tb->flags, so exit tb */
716 gen_jumpi_check_loop_end(dc
, -1);
719 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
721 uint32_t id
= sr
- CCOMPARE
;
722 if (id
< dc
->config
->nccompare
) {
723 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
724 gen_advance_ccount(dc
);
725 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
726 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
727 gen_helper_check_interrupts(cpu_env
);
731 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
733 static void (* const wsr_handler
[256])(DisasContext
*dc
,
734 uint32_t sr
, TCGv_i32 v
) = {
735 [LBEG
] = gen_wsr_lbeg
,
736 [LEND
] = gen_wsr_lend
,
739 [LITBASE
] = gen_wsr_litbase
,
740 [ACCHI
] = gen_wsr_acchi
,
741 [WINDOW_BASE
] = gen_wsr_windowbase
,
742 [WINDOW_START
] = gen_wsr_windowstart
,
743 [PTEVADDR
] = gen_wsr_ptevaddr
,
744 [RASID
] = gen_wsr_rasid
,
745 [ITLBCFG
] = gen_wsr_tlbcfg
,
746 [DTLBCFG
] = gen_wsr_tlbcfg
,
747 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
748 [ATOMCTL
] = gen_wsr_atomctl
,
749 [IBREAKA
] = gen_wsr_ibreaka
,
750 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
751 [DBREAKA
] = gen_wsr_dbreaka
,
752 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
753 [DBREAKC
] = gen_wsr_dbreakc
,
754 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
755 [CPENABLE
] = gen_wsr_cpenable
,
756 [INTSET
] = gen_wsr_intset
,
757 [INTCLEAR
] = gen_wsr_intclear
,
758 [INTENABLE
] = gen_wsr_intenable
,
760 [ICOUNT
] = gen_wsr_icount
,
761 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
762 [CCOMPARE
] = gen_wsr_ccompare
,
763 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
764 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
767 if (wsr_handler
[sr
]) {
768 wsr_handler
[sr
](dc
, sr
, s
);
770 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
774 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
778 gen_helper_wur_fcr(cpu_env
, s
);
782 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
786 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
791 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
792 TCGv_i32 addr
, bool no_hw_alignment
)
794 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
795 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
796 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
798 int label
= gen_new_label();
799 TCGv_i32 tmp
= tcg_temp_new_i32();
800 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
801 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
802 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
803 gen_set_label(label
);
808 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
810 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
811 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
812 gen_advance_ccount(dc
);
813 gen_helper_waiti(cpu_env
, pc
, intlevel
);
815 tcg_temp_free(intlevel
);
818 static void gen_window_check1(DisasContext
*dc
, unsigned r1
)
820 if (dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) {
823 if (option_enabled(dc
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
824 r1
/ 4 > dc
->used_window
) {
825 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
826 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
828 dc
->used_window
= r1
/ 4;
829 gen_advance_ccount(dc
);
830 gen_helper_window_check(cpu_env
, pc
, w
);
837 static void gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
839 gen_window_check1(dc
, r1
> r2
? r1
: r2
);
842 static void gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
845 gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
848 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
850 TCGv_i32 m
= tcg_temp_new_i32();
853 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
855 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
860 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
862 #define HAS_OPTION_BITS(opt) do { \
863 if (!option_bits_enabled(dc, opt)) { \
864 qemu_log("Option is not enabled %s:%d\n", \
865 __FILE__, __LINE__); \
866 goto invalid_opcode; \
870 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
872 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
873 #define RESERVED() do { \
874 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
875 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
876 goto invalid_opcode; \
880 #ifdef TARGET_WORDS_BIGENDIAN
881 #define OP0 (((b0) & 0xf0) >> 4)
882 #define OP1 (((b2) & 0xf0) >> 4)
883 #define OP2 ((b2) & 0xf)
884 #define RRR_R ((b1) & 0xf)
885 #define RRR_S (((b1) & 0xf0) >> 4)
886 #define RRR_T ((b0) & 0xf)
888 #define OP0 (((b0) & 0xf))
889 #define OP1 (((b2) & 0xf))
890 #define OP2 (((b2) & 0xf0) >> 4)
891 #define RRR_R (((b1) & 0xf0) >> 4)
892 #define RRR_S (((b1) & 0xf))
893 #define RRR_T (((b0) & 0xf0) >> 4)
895 #define RRR_X ((RRR_R & 0x4) >> 2)
896 #define RRR_Y ((RRR_T & 0x4) >> 2)
897 #define RRR_W (RRR_R & 0x3)
906 #define RRI8_IMM8 (b2)
907 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
909 #ifdef TARGET_WORDS_BIGENDIAN
910 #define RI16_IMM16 (((b1) << 8) | (b2))
912 #define RI16_IMM16 (((b2) << 8) | (b1))
915 #ifdef TARGET_WORDS_BIGENDIAN
916 #define CALL_N (((b0) & 0xc) >> 2)
917 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
919 #define CALL_N (((b0) & 0x30) >> 4)
920 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
922 #define CALL_OFFSET_SE \
923 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
925 #define CALLX_N CALL_N
926 #ifdef TARGET_WORDS_BIGENDIAN
927 #define CALLX_M ((b0) & 0x3)
929 #define CALLX_M (((b0) & 0xc0) >> 6)
931 #define CALLX_S RRR_S
933 #define BRI12_M CALLX_M
934 #define BRI12_S RRR_S
935 #ifdef TARGET_WORDS_BIGENDIAN
936 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
938 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
940 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
942 #define BRI8_M BRI12_M
943 #define BRI8_R RRI8_R
944 #define BRI8_S RRI8_S
945 #define BRI8_IMM8 RRI8_IMM8
946 #define BRI8_IMM8_SE RRI8_IMM8_SE
950 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
951 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
954 static const uint32_t B4CONST
[] = {
955 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
958 static const uint32_t B4CONSTU
[] = {
959 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
963 dc
->next_pc
= dc
->pc
+ 2;
964 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
966 dc
->next_pc
= dc
->pc
+ 3;
967 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
976 if ((RRR_R
& 0xc) == 0x8) {
977 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
984 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
995 gen_window_check1(dc
, CALLX_S
);
996 gen_jump(dc
, cpu_R
[CALLX_S
]);
1000 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1002 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1003 gen_advance_ccount(dc
);
1004 gen_helper_retw(tmp
, cpu_env
, tmp
);
1010 case 3: /*reserved*/
1017 gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2);
1021 TCGv_i32 tmp
= tcg_temp_new_i32();
1022 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1023 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1031 case 3: /*CALLX12w*/
1032 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1034 TCGv_i32 tmp
= tcg_temp_new_i32();
1036 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1037 gen_callw(dc
, CALLX_N
, tmp
);
1047 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1048 gen_window_check2(dc
, RRR_T
, RRR_S
);
1050 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1051 gen_advance_ccount(dc
);
1052 gen_helper_movsp(cpu_env
, pc
);
1053 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1073 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1085 default: /*reserved*/
1094 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1097 gen_check_privilege(dc
);
1098 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1099 gen_helper_check_interrupts(cpu_env
);
1100 gen_jump(dc
, cpu_SR
[EPC1
]);
1108 gen_check_privilege(dc
);
1109 gen_jump(dc
, cpu_SR
[
1110 dc
->config
->ndepc
? DEPC
: EPC1
]);
1115 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1116 gen_check_privilege(dc
);
1118 TCGv_i32 tmp
= tcg_const_i32(1);
1121 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1122 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1125 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1126 cpu_SR
[WINDOW_START
], tmp
);
1128 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1129 cpu_SR
[WINDOW_START
], tmp
);
1132 gen_helper_restore_owb(cpu_env
);
1133 gen_helper_check_interrupts(cpu_env
);
1134 gen_jump(dc
, cpu_SR
[EPC1
]);
1140 default: /*reserved*/
1147 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1148 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1149 gen_check_privilege(dc
);
1150 tcg_gen_mov_i32(cpu_SR
[PS
],
1151 cpu_SR
[EPS2
+ RRR_S
- 2]);
1152 gen_helper_check_interrupts(cpu_env
);
1153 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1155 qemu_log("RFI %d is illegal\n", RRR_S
);
1156 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1164 default: /*reserved*/
1172 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1174 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1178 case 5: /*SYSCALLx*/
1179 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1181 case 0: /*SYSCALLx*/
1182 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1186 if (semihosting_enabled
) {
1187 gen_check_privilege(dc
);
1188 gen_helper_simcall(cpu_env
);
1190 qemu_log("SIMCALL but semihosting is disabled\n");
1191 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1202 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1203 gen_check_privilege(dc
);
1204 gen_window_check1(dc
, RRR_T
);
1205 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1206 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1207 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1208 gen_helper_check_interrupts(cpu_env
);
1209 gen_jumpi_check_loop_end(dc
, 0);
1213 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1214 gen_check_privilege(dc
);
1215 gen_waiti(dc
, RRR_S
);
1222 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1224 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1225 TCGv_i32 mask
= tcg_const_i32(
1226 ((1 << shift
) - 1) << RRR_S
);
1227 TCGv_i32 tmp
= tcg_temp_new_i32();
1229 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1230 if (RRR_R
& 1) { /*ALL*/
1231 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1233 tcg_gen_add_i32(tmp
, tmp
, mask
);
1235 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1236 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1238 tcg_temp_free(mask
);
1243 default: /*reserved*/
1251 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1252 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1256 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1257 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1261 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1262 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1268 gen_window_check1(dc
, RRR_S
);
1269 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1273 gen_window_check1(dc
, RRR_S
);
1274 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1278 gen_window_check1(dc
, RRR_S
);
1280 TCGv_i32 tmp
= tcg_temp_new_i32();
1281 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1282 gen_right_shift_sar(dc
, tmp
);
1288 gen_window_check1(dc
, RRR_S
);
1290 TCGv_i32 tmp
= tcg_temp_new_i32();
1291 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1292 gen_left_shift_sar(dc
, tmp
);
1299 TCGv_i32 tmp
= tcg_const_i32(
1300 RRR_S
| ((RRR_T
& 1) << 4));
1301 gen_right_shift_sar(dc
, tmp
);
1315 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1316 gen_check_privilege(dc
);
1318 TCGv_i32 tmp
= tcg_const_i32(
1319 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1320 gen_helper_rotw(cpu_env
, tmp
);
1322 reset_used_window(dc
);
1327 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1328 gen_window_check2(dc
, RRR_S
, RRR_T
);
1329 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1333 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1334 gen_window_check2(dc
, RRR_S
, RRR_T
);
1335 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1338 default: /*reserved*/
1346 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1347 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1348 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1349 gen_check_privilege(dc
);
1350 gen_window_check2(dc
, RRR_S
, RRR_T
);
1352 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1354 switch (RRR_R
& 7) {
1355 case 3: /*RITLB0*/ /*RDTLB0*/
1356 gen_helper_rtlb0(cpu_R
[RRR_T
],
1357 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1360 case 4: /*IITLB*/ /*IDTLB*/
1361 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1362 /* This could change memory mapping, so exit tb */
1363 gen_jumpi_check_loop_end(dc
, -1);
1366 case 5: /*PITLB*/ /*PDTLB*/
1367 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1368 gen_helper_ptlb(cpu_R
[RRR_T
],
1369 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1372 case 6: /*WITLB*/ /*WDTLB*/
1374 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1375 /* This could change memory mapping, so exit tb */
1376 gen_jumpi_check_loop_end(dc
, -1);
1379 case 7: /*RITLB1*/ /*RDTLB1*/
1380 gen_helper_rtlb1(cpu_R
[RRR_T
],
1381 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1385 tcg_temp_free(dtlb
);
1389 tcg_temp_free(dtlb
);
1394 gen_window_check2(dc
, RRR_R
, RRR_T
);
1397 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1402 int label
= gen_new_label();
1403 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1404 tcg_gen_brcondi_i32(
1405 TCG_COND_GE
, cpu_R
[RRR_R
], 0, label
);
1406 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1407 gen_set_label(label
);
1411 default: /*reserved*/
1417 case 7: /*reserved*/
1422 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1423 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1429 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1431 TCGv_i32 tmp
= tcg_temp_new_i32();
1432 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1433 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1439 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1440 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1446 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1448 TCGv_i32 tmp
= tcg_temp_new_i32();
1449 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1450 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1461 gen_window_check2(dc
, RRR_R
, RRR_S
);
1462 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1463 32 - (RRR_T
| ((OP2
& 1) << 4)));
1468 gen_window_check2(dc
, RRR_R
, RRR_T
);
1469 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1470 RRR_S
| ((OP2
& 1) << 4));
1474 gen_window_check2(dc
, RRR_R
, RRR_T
);
1475 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1480 TCGv_i32 tmp
= tcg_temp_new_i32();
1481 gen_check_sr(dc
, RSR_SR
, SR_X
);
1483 gen_check_privilege(dc
);
1485 gen_window_check1(dc
, RRR_T
);
1486 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1487 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1488 gen_wsr(dc
, RSR_SR
, tmp
);
1494 * Note: 64 bit ops are used here solely because SAR values
1497 #define gen_shift_reg(cmd, reg) do { \
1498 TCGv_i64 tmp = tcg_temp_new_i64(); \
1499 tcg_gen_extu_i32_i64(tmp, reg); \
1500 tcg_gen_##cmd##_i64(v, v, tmp); \
1501 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \
1502 tcg_temp_free_i64(v); \
1503 tcg_temp_free_i64(tmp); \
1506 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1509 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1511 TCGv_i64 v
= tcg_temp_new_i64();
1512 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1518 gen_window_check2(dc
, RRR_R
, RRR_T
);
1520 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1522 TCGv_i64 v
= tcg_temp_new_i64();
1523 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1529 gen_window_check2(dc
, RRR_R
, RRR_S
);
1530 if (dc
->sar_m32_5bit
) {
1531 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1533 TCGv_i64 v
= tcg_temp_new_i64();
1534 TCGv_i32 s
= tcg_const_i32(32);
1535 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1536 tcg_gen_andi_i32(s
, s
, 0x3f);
1537 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1538 gen_shift_reg(shl
, s
);
1544 gen_window_check2(dc
, RRR_R
, RRR_T
);
1546 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1548 TCGv_i64 v
= tcg_temp_new_i64();
1549 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1554 #undef gen_shift_reg
1557 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1558 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1560 TCGv_i32 v1
= tcg_temp_new_i32();
1561 TCGv_i32 v2
= tcg_temp_new_i32();
1562 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1563 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1564 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1571 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1572 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1574 TCGv_i32 v1
= tcg_temp_new_i32();
1575 TCGv_i32 v2
= tcg_temp_new_i32();
1576 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1577 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1578 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1584 default: /*reserved*/
1592 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1596 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1597 int label
= gen_new_label();
1598 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1599 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1600 gen_set_label(label
);
1604 #define BOOLEAN_LOGIC(fn, r, s, t) \
1606 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1607 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1608 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1610 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1611 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1612 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1613 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1614 tcg_temp_free(tmp1); \
1615 tcg_temp_free(tmp2); \
1619 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1623 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1627 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1631 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1635 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1638 #undef BOOLEAN_LOGIC
1641 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1642 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1647 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1649 TCGv_i64 r
= tcg_temp_new_i64();
1650 TCGv_i64 s
= tcg_temp_new_i64();
1651 TCGv_i64 t
= tcg_temp_new_i64();
1654 tcg_gen_extu_i32_i64(s
, cpu_R
[RRR_S
]);
1655 tcg_gen_extu_i32_i64(t
, cpu_R
[RRR_T
]);
1657 tcg_gen_ext_i32_i64(s
, cpu_R
[RRR_S
]);
1658 tcg_gen_ext_i32_i64(t
, cpu_R
[RRR_T
]);
1660 tcg_gen_mul_i64(r
, s
, t
);
1661 tcg_gen_shri_i64(r
, r
, 32);
1662 tcg_gen_trunc_i64_i32(cpu_R
[RRR_R
], r
);
1664 tcg_temp_free_i64(r
);
1665 tcg_temp_free_i64(s
);
1666 tcg_temp_free_i64(t
);
1671 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1677 int label1
= gen_new_label();
1678 int label2
= gen_new_label();
1680 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1682 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1684 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1685 OP2
== 13 ? 0x80000000 : 0);
1687 gen_set_label(label1
);
1689 tcg_gen_div_i32(cpu_R
[RRR_R
],
1690 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1692 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1693 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1695 gen_set_label(label2
);
1700 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1703 default: /*reserved*/
1712 gen_check_sr(dc
, RSR_SR
, SR_R
);
1714 gen_check_privilege(dc
);
1716 gen_window_check1(dc
, RRR_T
);
1717 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1721 gen_check_sr(dc
, RSR_SR
, SR_W
);
1723 gen_check_privilege(dc
);
1725 gen_window_check1(dc
, RRR_T
);
1726 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1730 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1731 gen_window_check2(dc
, RRR_R
, RRR_S
);
1733 int shift
= 24 - RRR_T
;
1736 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1737 } else if (shift
== 16) {
1738 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1740 TCGv_i32 tmp
= tcg_temp_new_i32();
1741 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1742 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1749 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1750 gen_window_check2(dc
, RRR_R
, RRR_S
);
1752 TCGv_i32 tmp1
= tcg_temp_new_i32();
1753 TCGv_i32 tmp2
= tcg_temp_new_i32();
1754 int label
= gen_new_label();
1756 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1757 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1758 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1759 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1760 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp2
, 0, label
);
1762 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1763 tcg_gen_xori_i32(cpu_R
[RRR_R
], tmp1
,
1764 0xffffffff >> (25 - RRR_T
));
1766 gen_set_label(label
);
1768 tcg_temp_free(tmp1
);
1769 tcg_temp_free(tmp2
);
1777 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1778 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1780 static const TCGCond cond
[] = {
1786 int label
= gen_new_label();
1788 if (RRR_R
!= RRR_T
) {
1789 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1790 tcg_gen_brcond_i32(cond
[OP2
- 4],
1791 cpu_R
[RRR_S
], cpu_R
[RRR_T
], label
);
1792 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1794 tcg_gen_brcond_i32(cond
[OP2
- 4],
1795 cpu_R
[RRR_T
], cpu_R
[RRR_S
], label
);
1796 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1798 gen_set_label(label
);
1806 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1808 static const TCGCond cond
[] = {
1814 int label
= gen_new_label();
1815 tcg_gen_brcondi_i32(cond
[OP2
- 8], cpu_R
[RRR_T
], 0, label
);
1816 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1817 gen_set_label(label
);
1823 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1824 gen_window_check2(dc
, RRR_R
, RRR_S
);
1826 int label
= gen_new_label();
1827 TCGv_i32 tmp
= tcg_temp_new_i32();
1829 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1830 tcg_gen_brcondi_i32(
1831 OP2
& 1 ? TCG_COND_EQ
: TCG_COND_NE
,
1833 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1834 gen_set_label(label
);
1840 gen_window_check1(dc
, RRR_R
);
1842 int st
= (RRR_S
<< 4) + RRR_T
;
1843 if (uregnames
[st
].name
) {
1844 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1846 qemu_log("RUR %d not implemented, ", st
);
1853 gen_window_check1(dc
, RRR_T
);
1854 if (uregnames
[RSR_SR
].name
) {
1855 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1857 qemu_log("WUR %d not implemented, ", RSR_SR
);
1867 gen_window_check2(dc
, RRR_R
, RRR_T
);
1869 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1870 int maskimm
= (1 << (OP2
+ 1)) - 1;
1872 TCGv_i32 tmp
= tcg_temp_new_i32();
1873 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1874 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1893 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1894 gen_window_check2(dc
, RRR_S
, RRR_T
);
1895 gen_check_cpenable(dc
, 0);
1897 TCGv_i32 addr
= tcg_temp_new_i32();
1898 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1899 gen_load_store_alignment(dc
, 2, addr
, false);
1901 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1903 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1906 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1908 tcg_temp_free(addr
);
1912 default: /*reserved*/
1919 gen_window_check2(dc
, RRR_S
, RRR_T
);
1922 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1923 gen_check_privilege(dc
);
1925 TCGv_i32 addr
= tcg_temp_new_i32();
1926 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1927 (0xffffffc0 | (RRR_R
<< 2)));
1928 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1929 tcg_temp_free(addr
);
1934 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1935 gen_check_privilege(dc
);
1937 TCGv_i32 addr
= tcg_temp_new_i32();
1938 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1939 (0xffffffc0 | (RRR_R
<< 2)));
1940 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1941 tcg_temp_free(addr
);
1952 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1955 gen_check_cpenable(dc
, 0);
1956 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
1957 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1961 gen_check_cpenable(dc
, 0);
1962 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
1963 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1967 gen_check_cpenable(dc
, 0);
1968 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
1969 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1973 gen_check_cpenable(dc
, 0);
1974 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
1975 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1979 gen_check_cpenable(dc
, 0);
1980 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
1981 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1984 case 8: /*ROUND.Sf*/
1985 case 9: /*TRUNC.Sf*/
1986 case 10: /*FLOOR.Sf*/
1987 case 11: /*CEIL.Sf*/
1988 case 14: /*UTRUNC.Sf*/
1989 gen_window_check1(dc
, RRR_R
);
1990 gen_check_cpenable(dc
, 0);
1992 static const unsigned rounding_mode_const
[] = {
1993 float_round_nearest_even
,
1994 float_round_to_zero
,
1997 [6] = float_round_to_zero
,
1999 TCGv_i32 rounding_mode
= tcg_const_i32(
2000 rounding_mode_const
[OP2
& 7]);
2001 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2004 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2005 rounding_mode
, scale
);
2007 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2008 rounding_mode
, scale
);
2011 tcg_temp_free(rounding_mode
);
2012 tcg_temp_free(scale
);
2016 case 12: /*FLOAT.Sf*/
2017 case 13: /*UFLOAT.Sf*/
2018 gen_window_check1(dc
, RRR_S
);
2019 gen_check_cpenable(dc
, 0);
2021 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2024 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2025 cpu_R
[RRR_S
], scale
);
2027 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2028 cpu_R
[RRR_S
], scale
);
2030 tcg_temp_free(scale
);
2037 gen_check_cpenable(dc
, 0);
2038 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2042 gen_check_cpenable(dc
, 0);
2043 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2047 gen_window_check1(dc
, RRR_R
);
2048 gen_check_cpenable(dc
, 0);
2049 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2053 gen_window_check1(dc
, RRR_S
);
2054 gen_check_cpenable(dc
, 0);
2055 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2059 gen_check_cpenable(dc
, 0);
2060 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2063 default: /*reserved*/
2069 default: /*reserved*/
2076 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2078 #define gen_compare(rel, br, a, b) \
2080 TCGv_i32 bit = tcg_const_i32(1 << br); \
2082 gen_check_cpenable(dc, 0); \
2083 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2084 tcg_temp_free(bit); \
2089 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2093 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2097 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2101 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2105 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2109 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2113 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2118 case 8: /*MOVEQZ.Sf*/
2119 case 9: /*MOVNEZ.Sf*/
2120 case 10: /*MOVLTZ.Sf*/
2121 case 11: /*MOVGEZ.Sf*/
2122 gen_window_check1(dc
, RRR_T
);
2123 gen_check_cpenable(dc
, 0);
2125 static const TCGCond cond
[] = {
2131 int label
= gen_new_label();
2132 tcg_gen_brcondi_i32(cond
[OP2
- 8], cpu_R
[RRR_T
], 0, label
);
2133 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2134 gen_set_label(label
);
2138 case 12: /*MOVF.Sf*/
2139 case 13: /*MOVT.Sf*/
2140 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2141 gen_check_cpenable(dc
, 0);
2143 int label
= gen_new_label();
2144 TCGv_i32 tmp
= tcg_temp_new_i32();
2146 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2147 tcg_gen_brcondi_i32(
2148 OP2
& 1 ? TCG_COND_EQ
: TCG_COND_NE
,
2150 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2151 gen_set_label(label
);
2156 default: /*reserved*/
2162 default: /*reserved*/
2169 gen_window_check1(dc
, RRR_T
);
2171 TCGv_i32 tmp
= tcg_const_i32(
2172 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2173 0 : ((dc
->pc
+ 3) & ~3)) +
2174 (0xfffc0000 | (RI16_IMM16
<< 2)));
2176 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2177 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2179 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2185 #define gen_load_store(type, shift) do { \
2186 TCGv_i32 addr = tcg_temp_new_i32(); \
2187 gen_window_check2(dc, RRI8_S, RRI8_T); \
2188 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2190 gen_load_store_alignment(dc, shift, addr, false); \
2192 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2193 tcg_temp_free(addr); \
2198 gen_load_store(ld8u
, 0);
2202 gen_load_store(ld16u
, 1);
2206 gen_load_store(ld32u
, 2);
2210 gen_load_store(st8
, 0);
2214 gen_load_store(st16
, 1);
2218 gen_load_store(st32
, 2);
2223 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2254 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2258 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2262 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2266 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2270 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2273 default: /*reserved*/
2281 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2287 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2291 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2295 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2298 default: /*reserved*/
2305 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2309 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2312 default: /*reserved*/
2319 gen_load_store(ld16s
, 1);
2321 #undef gen_load_store
2324 gen_window_check1(dc
, RRI8_T
);
2325 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2326 RRI8_IMM8
| (RRI8_S
<< 8) |
2327 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2330 #define gen_load_store_no_hw_align(type) do { \
2331 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2332 gen_window_check2(dc, RRI8_S, RRI8_T); \
2333 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2334 gen_load_store_alignment(dc, 2, addr, true); \
2335 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2336 tcg_temp_free(addr); \
2340 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2341 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2345 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2346 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2350 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2351 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
<< 8);
2354 case 14: /*S32C1Iy*/
2355 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2356 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2358 int label
= gen_new_label();
2359 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2360 TCGv_i32 addr
= tcg_temp_local_new_i32();
2363 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2364 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2365 gen_load_store_alignment(dc
, 2, addr
, true);
2367 gen_advance_ccount(dc
);
2368 tpc
= tcg_const_i32(dc
->pc
);
2369 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2370 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2371 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2372 cpu_SR
[SCOMPARE1
], label
);
2374 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2376 gen_set_label(label
);
2378 tcg_temp_free(addr
);
2384 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2385 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2387 #undef gen_load_store_no_hw_align
2389 default: /*reserved*/
2401 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2402 gen_window_check1(dc
, RRI8_S
);
2403 gen_check_cpenable(dc
, 0);
2405 TCGv_i32 addr
= tcg_temp_new_i32();
2406 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2407 gen_load_store_alignment(dc
, 2, addr
, false);
2409 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2411 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2414 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2416 tcg_temp_free(addr
);
2420 default: /*reserved*/
2427 HAS_OPTION(XTENSA_OPTION_MAC16
);
2436 bool is_m1_sr
= (OP2
& 0x3) == 2;
2437 bool is_m2_sr
= (OP2
& 0xc) == 0;
2438 uint32_t ld_offset
= 0;
2445 case 0: /*MACI?/MACC?*/
2447 ld_offset
= (OP2
& 1) ? -4 : 4;
2449 if (OP2
>= 8) { /*MACI/MACC*/
2450 if (OP1
== 0) { /*LDINC/LDDEC*/
2455 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2460 case 2: /*MACD?/MACA?*/
2461 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2467 if (op
!= MAC16_NONE
) {
2469 gen_window_check1(dc
, RRR_S
);
2472 gen_window_check1(dc
, RRR_T
);
2477 TCGv_i32 vaddr
= tcg_temp_new_i32();
2478 TCGv_i32 mem32
= tcg_temp_new_i32();
2481 gen_window_check1(dc
, RRR_S
);
2482 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2483 gen_load_store_alignment(dc
, 2, vaddr
, false);
2484 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2486 if (op
!= MAC16_NONE
) {
2487 TCGv_i32 m1
= gen_mac16_m(
2488 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2489 OP1
& 1, op
== MAC16_UMUL
);
2490 TCGv_i32 m2
= gen_mac16_m(
2491 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2492 OP1
& 2, op
== MAC16_UMUL
);
2494 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2495 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2496 if (op
== MAC16_UMUL
) {
2497 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2499 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2502 TCGv_i32 res
= tcg_temp_new_i32();
2503 TCGv_i64 res64
= tcg_temp_new_i64();
2504 TCGv_i64 tmp
= tcg_temp_new_i64();
2506 tcg_gen_mul_i32(res
, m1
, m2
);
2507 tcg_gen_ext_i32_i64(res64
, res
);
2508 tcg_gen_concat_i32_i64(tmp
,
2509 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
]);
2510 if (op
== MAC16_MULA
) {
2511 tcg_gen_add_i64(tmp
, tmp
, res64
);
2513 tcg_gen_sub_i64(tmp
, tmp
, res64
);
2515 tcg_gen_trunc_i64_i32(cpu_SR
[ACCLO
], tmp
);
2516 tcg_gen_shri_i64(tmp
, tmp
, 32);
2517 tcg_gen_trunc_i64_i32(cpu_SR
[ACCHI
], tmp
);
2518 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2521 tcg_temp_free_i64(res64
);
2522 tcg_temp_free_i64(tmp
);
2528 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2529 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2531 tcg_temp_free(vaddr
);
2532 tcg_temp_free(mem32
);
2540 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2541 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2547 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2548 gen_window_check1(dc
, CALL_N
<< 2);
2549 gen_callwi(dc
, CALL_N
,
2550 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2558 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2562 gen_window_check1(dc
, BRI12_S
);
2564 static const TCGCond cond
[] = {
2565 TCG_COND_EQ
, /*BEQZ*/
2566 TCG_COND_NE
, /*BNEZ*/
2567 TCG_COND_LT
, /*BLTZ*/
2568 TCG_COND_GE
, /*BGEZ*/
2571 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2572 4 + BRI12_IMM12_SE
);
2577 gen_window_check1(dc
, BRI8_S
);
2579 static const TCGCond cond
[] = {
2580 TCG_COND_EQ
, /*BEQI*/
2581 TCG_COND_NE
, /*BNEI*/
2582 TCG_COND_LT
, /*BLTI*/
2583 TCG_COND_GE
, /*BGEI*/
2586 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2587 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2594 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2596 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2597 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2598 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2599 gen_advance_ccount(dc
);
2600 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2604 reset_used_window(dc
);
2612 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2614 TCGv_i32 tmp
= tcg_temp_new_i32();
2615 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2617 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2618 tmp
, 0, 4 + RRI8_IMM8_SE
);
2625 case 10: /*LOOPGTZ*/
2626 HAS_OPTION(XTENSA_OPTION_LOOP
);
2627 gen_window_check1(dc
, RRI8_S
);
2629 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2630 TCGv_i32 tmp
= tcg_const_i32(lend
);
2632 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2633 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2634 gen_helper_wsr_lend(cpu_env
, tmp
);
2638 int label
= gen_new_label();
2639 tcg_gen_brcondi_i32(
2640 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2641 cpu_R
[RRI8_S
], 0, label
);
2642 gen_jumpi(dc
, lend
, 1);
2643 gen_set_label(label
);
2646 gen_jumpi(dc
, dc
->next_pc
, 0);
2650 default: /*reserved*/
2659 gen_window_check1(dc
, BRI8_S
);
2660 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2661 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2671 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2673 switch (RRI8_R
& 7) {
2674 case 0: /*BNONE*/ /*BANY*/
2675 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2677 TCGv_i32 tmp
= tcg_temp_new_i32();
2678 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2679 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2684 case 1: /*BEQ*/ /*BNE*/
2685 case 2: /*BLT*/ /*BGE*/
2686 case 3: /*BLTU*/ /*BGEU*/
2687 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2689 static const TCGCond cond
[] = {
2695 [11] = TCG_COND_GEU
,
2697 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2702 case 4: /*BALL*/ /*BNALL*/
2703 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2705 TCGv_i32 tmp
= tcg_temp_new_i32();
2706 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2707 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2713 case 5: /*BBC*/ /*BBS*/
2714 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2716 #ifdef TARGET_WORDS_BIGENDIAN
2717 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2719 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2721 TCGv_i32 tmp
= tcg_temp_new_i32();
2722 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2723 #ifdef TARGET_WORDS_BIGENDIAN
2724 tcg_gen_shr_i32(bit
, bit
, tmp
);
2726 tcg_gen_shl_i32(bit
, bit
, tmp
);
2728 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2729 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2735 case 6: /*BBCI*/ /*BBSI*/
2737 gen_window_check1(dc
, RRI8_S
);
2739 TCGv_i32 tmp
= tcg_temp_new_i32();
2740 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2741 #ifdef TARGET_WORDS_BIGENDIAN
2742 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2744 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2746 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2755 #define gen_narrow_load_store(type) do { \
2756 TCGv_i32 addr = tcg_temp_new_i32(); \
2757 gen_window_check2(dc, RRRN_S, RRRN_T); \
2758 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2759 gen_load_store_alignment(dc, 2, addr, false); \
2760 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2761 tcg_temp_free(addr); \
2765 gen_narrow_load_store(ld32u
);
2769 gen_narrow_load_store(st32
);
2771 #undef gen_narrow_load_store
2774 gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
);
2775 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2778 case 11: /*ADDI.Nn*/
2779 gen_window_check2(dc
, RRRN_R
, RRRN_S
);
2780 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], RRRN_T
? RRRN_T
: -1);
2784 gen_window_check1(dc
, RRRN_S
);
2785 if (RRRN_T
< 8) { /*MOVI.Nn*/
2786 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2787 RRRN_R
| (RRRN_T
<< 4) |
2788 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2789 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2790 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2792 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2793 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2800 gen_window_check2(dc
, RRRN_S
, RRRN_T
);
2801 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2807 gen_jump(dc
, cpu_R
[0]);
2811 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2813 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2814 gen_advance_ccount(dc
);
2815 gen_helper_retw(tmp
, cpu_env
, tmp
);
2821 case 2: /*BREAK.Nn*/
2822 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2824 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2832 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2835 default: /*reserved*/
2841 default: /*reserved*/
2847 default: /*reserved*/
2852 if (dc
->is_jmp
== DISAS_NEXT
) {
2853 gen_check_loop_end(dc
, 0);
2855 dc
->pc
= dc
->next_pc
;
2860 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2861 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2865 static void check_breakpoint(CPUXtensaState
*env
, DisasContext
*dc
)
2869 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2870 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2871 if (bp
->pc
== dc
->pc
) {
2872 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2873 gen_exception(dc
, EXCP_DEBUG
);
2874 dc
->is_jmp
= DISAS_UPDATE
;
2880 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
2884 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
2885 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
2886 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
2887 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
2893 static void gen_intermediate_code_internal(
2894 CPUXtensaState
*env
, TranslationBlock
*tb
, int search_pc
)
2899 uint16_t *gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
2900 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2901 uint32_t pc_start
= tb
->pc
;
2902 uint32_t next_page_start
=
2903 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2905 if (max_insns
== 0) {
2906 max_insns
= CF_COUNT_MASK
;
2909 dc
.config
= env
->config
;
2910 dc
.singlestep_enabled
= env
->singlestep_enabled
;
2913 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
2914 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
2915 dc
.lbeg
= env
->sregs
[LBEG
];
2916 dc
.lend
= env
->sregs
[LEND
];
2917 dc
.is_jmp
= DISAS_NEXT
;
2918 dc
.ccount_delta
= 0;
2919 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
2920 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
2921 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
2922 XTENSA_TBFLAG_CPENABLE_SHIFT
;
2925 init_sar_tracker(&dc
);
2926 reset_used_window(&dc
);
2928 dc
.next_icount
= tcg_temp_local_new_i32();
2933 if (env
->singlestep_enabled
&& env
->exception_taken
) {
2934 env
->exception_taken
= 0;
2935 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2936 gen_exception(&dc
, EXCP_DEBUG
);
2940 check_breakpoint(env
, &dc
);
2943 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
2947 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2950 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
2951 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
2952 tcg_ctx
.gen_opc_icount
[lj
] = insn_count
;
2955 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
2956 tcg_gen_debug_insn_start(dc
.pc
);
2961 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
2966 int label
= gen_new_label();
2968 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
2969 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
2970 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
2972 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
2974 gen_set_label(label
);
2978 gen_ibreak_check(env
, &dc
);
2981 disas_xtensa_insn(env
, &dc
);
2984 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
2986 if (env
->singlestep_enabled
) {
2987 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2988 gen_exception(&dc
, EXCP_DEBUG
);
2991 } while (dc
.is_jmp
== DISAS_NEXT
&&
2992 insn_count
< max_insns
&&
2993 dc
.pc
< next_page_start
&&
2994 tcg_ctx
.gen_opc_ptr
< gen_opc_end
);
2997 reset_sar_tracker(&dc
);
2999 tcg_temp_free(dc
.next_icount
);
3002 if (tb
->cflags
& CF_LAST_IO
) {
3006 if (dc
.is_jmp
== DISAS_NEXT
) {
3007 gen_jumpi(&dc
, dc
.pc
, 0);
3009 gen_icount_end(tb
, insn_count
);
3010 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
3013 tb
->size
= dc
.pc
- pc_start
;
3014 tb
->icount
= insn_count
;
3018 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3020 gen_intermediate_code_internal(env
, tb
, 0);
3023 void gen_intermediate_code_pc(CPUXtensaState
*env
, TranslationBlock
*tb
)
3025 gen_intermediate_code_internal(env
, tb
, 1);
3028 void cpu_dump_state(CPUXtensaState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
3033 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3035 for (i
= j
= 0; i
< 256; ++i
) {
3036 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3037 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3038 (j
++ % 4) == 3 ? '\n' : ' ');
3042 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3044 for (i
= j
= 0; i
< 256; ++i
) {
3045 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3046 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3047 (j
++ % 4) == 3 ? '\n' : ' ');
3051 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3053 for (i
= 0; i
< 16; ++i
) {
3054 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3055 (i
% 4) == 3 ? '\n' : ' ');
3058 cpu_fprintf(f
, "\n");
3060 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3061 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3062 (i
% 4) == 3 ? '\n' : ' ');
3065 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3066 cpu_fprintf(f
, "\n");
3068 for (i
= 0; i
< 16; ++i
) {
3069 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3070 float32_val(env
->fregs
[i
]),
3071 *(float *)&env
->fregs
[i
], (i
% 2) == 1 ? '\n' : ' ');
3076 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
, int pc_pos
)
3078 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];