3 * http://www.tensilica.com/products/literature-docs/documentation/xtensa-isa-databook.htm
5 * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * * Neither the name of the Open Source and Linux Lab nor the
16 * names of its contributors may be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "exec/exec-all.h"
35 #include "disas/disas.h"
38 #include "sysemu/sysemu.h"
44 typedef struct DisasContext
{
45 const XtensaConfig
*config
;
55 int singlestep_enabled
;
59 bool sar_m32_allocated
;
62 uint32_t ccount_delta
;
72 static TCGv_ptr cpu_env
;
73 static TCGv_i32 cpu_pc
;
74 static TCGv_i32 cpu_R
[16];
75 static TCGv_i32 cpu_FR
[16];
76 static TCGv_i32 cpu_SR
[256];
77 static TCGv_i32 cpu_UR
[256];
79 #include "exec/gen-icount.h"
81 typedef struct XtensaReg
{
93 #define XTENSA_REG_ACCESS(regname, opt, acc) { \
95 .opt_bits = XTENSA_OPTION_BIT(opt), \
99 #define XTENSA_REG(regname, opt) XTENSA_REG_ACCESS(regname, opt, SR_RWX)
101 #define XTENSA_REG_BITS(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
),
182 [MISC
] = XTENSA_REG("MISC0", XTENSA_OPTION_MISC_SR
),
183 [MISC
+ 1] = XTENSA_REG("MISC1", XTENSA_OPTION_MISC_SR
),
184 [MISC
+ 2] = XTENSA_REG("MISC2", XTENSA_OPTION_MISC_SR
),
185 [MISC
+ 3] = XTENSA_REG("MISC3", XTENSA_OPTION_MISC_SR
),
188 static const XtensaReg uregnames
[256] = {
189 [THREADPTR
] = XTENSA_REG("THREADPTR", XTENSA_OPTION_THREAD_POINTER
),
190 [FCR
] = XTENSA_REG("FCR", XTENSA_OPTION_FP_COPROCESSOR
),
191 [FSR
] = XTENSA_REG("FSR", XTENSA_OPTION_FP_COPROCESSOR
),
194 void xtensa_translate_init(void)
196 static const char * const regnames
[] = {
197 "ar0", "ar1", "ar2", "ar3",
198 "ar4", "ar5", "ar6", "ar7",
199 "ar8", "ar9", "ar10", "ar11",
200 "ar12", "ar13", "ar14", "ar15",
202 static const char * const fregnames
[] = {
203 "f0", "f1", "f2", "f3",
204 "f4", "f5", "f6", "f7",
205 "f8", "f9", "f10", "f11",
206 "f12", "f13", "f14", "f15",
210 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
211 cpu_pc
= tcg_global_mem_new_i32(TCG_AREG0
,
212 offsetof(CPUXtensaState
, pc
), "pc");
214 for (i
= 0; i
< 16; i
++) {
215 cpu_R
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
216 offsetof(CPUXtensaState
, regs
[i
]),
220 for (i
= 0; i
< 16; i
++) {
221 cpu_FR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
222 offsetof(CPUXtensaState
, fregs
[i
]),
226 for (i
= 0; i
< 256; ++i
) {
227 if (sregnames
[i
].name
) {
228 cpu_SR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
229 offsetof(CPUXtensaState
, sregs
[i
]),
234 for (i
= 0; i
< 256; ++i
) {
235 if (uregnames
[i
].name
) {
236 cpu_UR
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
237 offsetof(CPUXtensaState
, uregs
[i
]),
243 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
245 return xtensa_option_bits_enabled(dc
->config
, opt
);
248 static inline bool option_enabled(DisasContext
*dc
, int opt
)
250 return xtensa_option_enabled(dc
->config
, opt
);
253 static void init_litbase(DisasContext
*dc
)
255 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
256 dc
->litbase
= tcg_temp_local_new_i32();
257 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
261 static void reset_litbase(DisasContext
*dc
)
263 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
264 tcg_temp_free(dc
->litbase
);
268 static void init_sar_tracker(DisasContext
*dc
)
270 dc
->sar_5bit
= false;
271 dc
->sar_m32_5bit
= false;
272 dc
->sar_m32_allocated
= false;
275 static void reset_sar_tracker(DisasContext
*dc
)
277 if (dc
->sar_m32_allocated
) {
278 tcg_temp_free(dc
->sar_m32
);
282 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
284 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
285 if (dc
->sar_m32_5bit
) {
286 tcg_gen_discard_i32(dc
->sar_m32
);
289 dc
->sar_m32_5bit
= false;
292 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
294 TCGv_i32 tmp
= tcg_const_i32(32);
295 if (!dc
->sar_m32_allocated
) {
296 dc
->sar_m32
= tcg_temp_local_new_i32();
297 dc
->sar_m32_allocated
= true;
299 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
300 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
301 dc
->sar_5bit
= false;
302 dc
->sar_m32_5bit
= true;
306 static void gen_advance_ccount_cond(DisasContext
*dc
)
308 if (dc
->ccount_delta
> 0) {
309 TCGv_i32 tmp
= tcg_const_i32(dc
->ccount_delta
);
310 gen_helper_advance_ccount(cpu_env
, tmp
);
315 static void gen_advance_ccount(DisasContext
*dc
)
317 gen_advance_ccount_cond(dc
);
318 dc
->ccount_delta
= 0;
321 static void reset_used_window(DisasContext
*dc
)
326 static void gen_exception(DisasContext
*dc
, int excp
)
328 TCGv_i32 tmp
= tcg_const_i32(excp
);
329 gen_advance_ccount(dc
);
330 gen_helper_exception(cpu_env
, tmp
);
334 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
336 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
337 TCGv_i32 tcause
= tcg_const_i32(cause
);
338 gen_advance_ccount(dc
);
339 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
341 tcg_temp_free(tcause
);
342 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
343 cause
== SYSCALL_CAUSE
) {
344 dc
->is_jmp
= DISAS_UPDATE
;
348 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
351 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
352 TCGv_i32 tcause
= tcg_const_i32(cause
);
353 gen_advance_ccount(dc
);
354 gen_helper_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
356 tcg_temp_free(tcause
);
359 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
361 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
362 TCGv_i32 tcause
= tcg_const_i32(cause
);
363 gen_advance_ccount(dc
);
364 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
366 tcg_temp_free(tcause
);
367 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
368 dc
->is_jmp
= DISAS_UPDATE
;
372 static void gen_check_privilege(DisasContext
*dc
)
375 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
376 dc
->is_jmp
= DISAS_UPDATE
;
380 static void gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
382 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
383 !(dc
->cpenable
& (1 << cp
))) {
384 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
385 dc
->is_jmp
= DISAS_UPDATE
;
389 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
391 tcg_gen_mov_i32(cpu_pc
, dest
);
392 gen_advance_ccount(dc
);
394 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
->next_icount
);
396 if (dc
->singlestep_enabled
) {
397 gen_exception(dc
, EXCP_DEBUG
);
400 tcg_gen_goto_tb(slot
);
401 tcg_gen_exit_tb((uintptr_t)dc
->tb
+ slot
);
406 dc
->is_jmp
= DISAS_UPDATE
;
409 static void gen_jump(DisasContext
*dc
, TCGv dest
)
411 gen_jump_slot(dc
, dest
, -1);
414 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
416 TCGv_i32 tmp
= tcg_const_i32(dest
);
417 if (((dc
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
420 gen_jump_slot(dc
, tmp
, slot
);
424 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
427 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
429 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
430 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
431 tcg_temp_free(tcallinc
);
432 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
433 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
434 gen_jump_slot(dc
, dest
, slot
);
437 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
439 gen_callw_slot(dc
, callinc
, dest
, -1);
442 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
444 TCGv_i32 tmp
= tcg_const_i32(dest
);
445 if (((dc
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
448 gen_callw_slot(dc
, callinc
, tmp
, slot
);
452 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
454 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
455 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
456 dc
->next_pc
== dc
->lend
) {
457 int label
= gen_new_label();
459 gen_advance_ccount(dc
);
460 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
461 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
462 gen_jumpi(dc
, dc
->lbeg
, slot
);
463 gen_set_label(label
);
464 gen_jumpi(dc
, dc
->next_pc
, -1);
470 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
472 if (!gen_check_loop_end(dc
, slot
)) {
473 gen_jumpi(dc
, dc
->next_pc
, slot
);
477 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
478 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
480 int label
= gen_new_label();
482 gen_advance_ccount(dc
);
483 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
484 gen_jumpi_check_loop_end(dc
, 0);
485 gen_set_label(label
);
486 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
489 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
490 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
492 TCGv_i32 tmp
= tcg_const_i32(t1
);
493 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
497 static bool gen_check_sr(DisasContext
*dc
, uint32_t sr
, unsigned access
)
499 if (!xtensa_option_bits_enabled(dc
->config
, sregnames
[sr
].opt_bits
)) {
500 if (sregnames
[sr
].name
) {
501 qemu_log("SR %s is not configured\n", sregnames
[sr
].name
);
503 qemu_log("SR %d is not implemented\n", sr
);
505 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
507 } else if (!(sregnames
[sr
].access
& access
)) {
508 static const char * const access_text
[] = {
513 assert(access
< ARRAY_SIZE(access_text
) && access_text
[access
]);
514 qemu_log("SR %s is not available for %s\n", sregnames
[sr
].name
,
515 access_text
[access
]);
516 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
522 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
524 gen_advance_ccount(dc
);
525 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
528 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
530 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
531 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
532 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
535 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
537 static void (* const rsr_handler
[256])(DisasContext
*dc
,
538 TCGv_i32 d
, uint32_t sr
) = {
539 [CCOUNT
] = gen_rsr_ccount
,
540 [PTEVADDR
] = gen_rsr_ptevaddr
,
543 if (rsr_handler
[sr
]) {
544 rsr_handler
[sr
](dc
, d
, sr
);
546 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
550 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
552 gen_helper_wsr_lbeg(cpu_env
, s
);
553 gen_jumpi_check_loop_end(dc
, 0);
556 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
558 gen_helper_wsr_lend(cpu_env
, s
);
559 gen_jumpi_check_loop_end(dc
, 0);
562 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
564 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
565 if (dc
->sar_m32_5bit
) {
566 tcg_gen_discard_i32(dc
->sar_m32
);
568 dc
->sar_5bit
= false;
569 dc
->sar_m32_5bit
= false;
572 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
574 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
577 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
579 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
580 /* This can change tb->flags, so exit tb */
581 gen_jumpi_check_loop_end(dc
, -1);
584 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
586 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
589 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
591 gen_helper_wsr_windowbase(cpu_env
, v
);
592 reset_used_window(dc
);
595 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
597 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
598 reset_used_window(dc
);
601 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
603 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
606 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
608 gen_helper_wsr_rasid(cpu_env
, v
);
609 /* This can change tb->flags, so exit tb */
610 gen_jumpi_check_loop_end(dc
, -1);
613 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
615 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
618 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
620 gen_helper_wsr_ibreakenable(cpu_env
, v
);
621 gen_jumpi_check_loop_end(dc
, 0);
624 static void gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
626 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
629 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
631 unsigned id
= sr
- IBREAKA
;
633 if (id
< dc
->config
->nibreak
) {
634 TCGv_i32 tmp
= tcg_const_i32(id
);
635 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
637 gen_jumpi_check_loop_end(dc
, 0);
641 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
643 unsigned id
= sr
- DBREAKA
;
645 if (id
< dc
->config
->ndbreak
) {
646 TCGv_i32 tmp
= tcg_const_i32(id
);
647 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
652 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
654 unsigned id
= sr
- DBREAKC
;
656 if (id
< dc
->config
->ndbreak
) {
657 TCGv_i32 tmp
= tcg_const_i32(id
);
658 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
663 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
665 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
666 /* This can change tb->flags, so exit tb */
667 gen_jumpi_check_loop_end(dc
, -1);
670 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
672 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
673 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
674 gen_helper_check_interrupts(cpu_env
);
675 gen_jumpi_check_loop_end(dc
, 0);
678 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
680 TCGv_i32 tmp
= tcg_temp_new_i32();
682 tcg_gen_andi_i32(tmp
, v
,
683 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
684 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
685 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
686 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
688 gen_helper_check_interrupts(cpu_env
);
691 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
693 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
694 gen_helper_check_interrupts(cpu_env
);
695 gen_jumpi_check_loop_end(dc
, 0);
698 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
700 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
701 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
703 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
706 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
707 reset_used_window(dc
);
708 gen_helper_check_interrupts(cpu_env
);
709 /* This can change mmu index and tb->flags, so exit tb */
710 gen_jumpi_check_loop_end(dc
, -1);
713 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
716 tcg_gen_mov_i32(dc
->next_icount
, v
);
718 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
722 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
724 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
725 /* This can change tb->flags, so exit tb */
726 gen_jumpi_check_loop_end(dc
, -1);
729 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
731 uint32_t id
= sr
- CCOMPARE
;
732 if (id
< dc
->config
->nccompare
) {
733 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
734 gen_advance_ccount(dc
);
735 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
736 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
737 gen_helper_check_interrupts(cpu_env
);
741 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
743 static void (* const wsr_handler
[256])(DisasContext
*dc
,
744 uint32_t sr
, TCGv_i32 v
) = {
745 [LBEG
] = gen_wsr_lbeg
,
746 [LEND
] = gen_wsr_lend
,
749 [LITBASE
] = gen_wsr_litbase
,
750 [ACCHI
] = gen_wsr_acchi
,
751 [WINDOW_BASE
] = gen_wsr_windowbase
,
752 [WINDOW_START
] = gen_wsr_windowstart
,
753 [PTEVADDR
] = gen_wsr_ptevaddr
,
754 [RASID
] = gen_wsr_rasid
,
755 [ITLBCFG
] = gen_wsr_tlbcfg
,
756 [DTLBCFG
] = gen_wsr_tlbcfg
,
757 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
758 [ATOMCTL
] = gen_wsr_atomctl
,
759 [IBREAKA
] = gen_wsr_ibreaka
,
760 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
761 [DBREAKA
] = gen_wsr_dbreaka
,
762 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
763 [DBREAKC
] = gen_wsr_dbreakc
,
764 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
765 [CPENABLE
] = gen_wsr_cpenable
,
766 [INTSET
] = gen_wsr_intset
,
767 [INTCLEAR
] = gen_wsr_intclear
,
768 [INTENABLE
] = gen_wsr_intenable
,
770 [ICOUNT
] = gen_wsr_icount
,
771 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
772 [CCOMPARE
] = gen_wsr_ccompare
,
773 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
774 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
777 if (wsr_handler
[sr
]) {
778 wsr_handler
[sr
](dc
, sr
, s
);
780 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
784 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
788 gen_helper_wur_fcr(cpu_env
, s
);
792 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
796 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
801 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
802 TCGv_i32 addr
, bool no_hw_alignment
)
804 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
805 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
806 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
808 int label
= gen_new_label();
809 TCGv_i32 tmp
= tcg_temp_new_i32();
810 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
811 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
812 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
813 gen_set_label(label
);
818 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
820 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
821 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
822 gen_advance_ccount(dc
);
823 gen_helper_waiti(cpu_env
, pc
, intlevel
);
825 tcg_temp_free(intlevel
);
828 static void gen_window_check1(DisasContext
*dc
, unsigned r1
)
830 if (dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) {
833 if (option_enabled(dc
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
834 r1
/ 4 > dc
->used_window
) {
835 int label
= gen_new_label();
836 TCGv_i32 ws
= tcg_temp_new_i32();
838 dc
->used_window
= r1
/ 4;
839 tcg_gen_deposit_i32(ws
, cpu_SR
[WINDOW_START
], cpu_SR
[WINDOW_START
],
840 dc
->config
->nareg
/ 4, dc
->config
->nareg
/ 4);
841 tcg_gen_shr_i32(ws
, ws
, cpu_SR
[WINDOW_BASE
]);
842 tcg_gen_andi_i32(ws
, ws
, (2 << (r1
/ 4)) - 2);
843 tcg_gen_brcondi_i32(TCG_COND_EQ
, ws
, 0, label
);
845 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
846 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
848 gen_advance_ccount_cond(dc
);
849 gen_helper_window_check(cpu_env
, pc
, w
);
854 gen_set_label(label
);
859 static void gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
861 gen_window_check1(dc
, r1
> r2
? r1
: r2
);
864 static void gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
867 gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
870 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
872 TCGv_i32 m
= tcg_temp_new_i32();
875 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
877 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
882 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
884 #define HAS_OPTION_BITS(opt) do { \
885 if (!option_bits_enabled(dc, opt)) { \
886 qemu_log("Option is not enabled %s:%d\n", \
887 __FILE__, __LINE__); \
888 goto invalid_opcode; \
892 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
894 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
895 #define RESERVED() do { \
896 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
897 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
898 goto invalid_opcode; \
902 #ifdef TARGET_WORDS_BIGENDIAN
903 #define OP0 (((b0) & 0xf0) >> 4)
904 #define OP1 (((b2) & 0xf0) >> 4)
905 #define OP2 ((b2) & 0xf)
906 #define RRR_R ((b1) & 0xf)
907 #define RRR_S (((b1) & 0xf0) >> 4)
908 #define RRR_T ((b0) & 0xf)
910 #define OP0 (((b0) & 0xf))
911 #define OP1 (((b2) & 0xf))
912 #define OP2 (((b2) & 0xf0) >> 4)
913 #define RRR_R (((b1) & 0xf0) >> 4)
914 #define RRR_S (((b1) & 0xf))
915 #define RRR_T (((b0) & 0xf0) >> 4)
917 #define RRR_X ((RRR_R & 0x4) >> 2)
918 #define RRR_Y ((RRR_T & 0x4) >> 2)
919 #define RRR_W (RRR_R & 0x3)
928 #define RRI8_IMM8 (b2)
929 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
931 #ifdef TARGET_WORDS_BIGENDIAN
932 #define RI16_IMM16 (((b1) << 8) | (b2))
934 #define RI16_IMM16 (((b2) << 8) | (b1))
937 #ifdef TARGET_WORDS_BIGENDIAN
938 #define CALL_N (((b0) & 0xc) >> 2)
939 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
941 #define CALL_N (((b0) & 0x30) >> 4)
942 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
944 #define CALL_OFFSET_SE \
945 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
947 #define CALLX_N CALL_N
948 #ifdef TARGET_WORDS_BIGENDIAN
949 #define CALLX_M ((b0) & 0x3)
951 #define CALLX_M (((b0) & 0xc0) >> 6)
953 #define CALLX_S RRR_S
955 #define BRI12_M CALLX_M
956 #define BRI12_S RRR_S
957 #ifdef TARGET_WORDS_BIGENDIAN
958 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
960 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
962 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
964 #define BRI8_M BRI12_M
965 #define BRI8_R RRI8_R
966 #define BRI8_S RRI8_S
967 #define BRI8_IMM8 RRI8_IMM8
968 #define BRI8_IMM8_SE RRI8_IMM8_SE
972 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
973 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
976 static const uint32_t B4CONST
[] = {
977 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
980 static const uint32_t B4CONSTU
[] = {
981 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
985 dc
->next_pc
= dc
->pc
+ 2;
986 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
988 dc
->next_pc
= dc
->pc
+ 3;
989 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
998 if ((RRR_R
& 0xc) == 0x8) {
999 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1006 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1009 case 1: /*reserved*/
1017 gen_window_check1(dc
, CALLX_S
);
1018 gen_jump(dc
, cpu_R
[CALLX_S
]);
1022 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1024 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1025 gen_advance_ccount(dc
);
1026 gen_helper_retw(tmp
, cpu_env
, tmp
);
1032 case 3: /*reserved*/
1039 gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2);
1043 TCGv_i32 tmp
= tcg_temp_new_i32();
1044 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1045 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1053 case 3: /*CALLX12w*/
1054 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1056 TCGv_i32 tmp
= tcg_temp_new_i32();
1058 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1059 gen_callw(dc
, CALLX_N
, tmp
);
1069 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1070 gen_window_check2(dc
, RRR_T
, RRR_S
);
1072 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1073 gen_advance_ccount(dc
);
1074 gen_helper_movsp(cpu_env
, pc
);
1075 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1095 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1107 default: /*reserved*/
1116 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1119 gen_check_privilege(dc
);
1120 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1121 gen_helper_check_interrupts(cpu_env
);
1122 gen_jump(dc
, cpu_SR
[EPC1
]);
1130 gen_check_privilege(dc
);
1131 gen_jump(dc
, cpu_SR
[
1132 dc
->config
->ndepc
? DEPC
: EPC1
]);
1137 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1138 gen_check_privilege(dc
);
1140 TCGv_i32 tmp
= tcg_const_i32(1);
1143 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1144 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1147 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1148 cpu_SR
[WINDOW_START
], tmp
);
1150 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1151 cpu_SR
[WINDOW_START
], tmp
);
1154 gen_helper_restore_owb(cpu_env
);
1155 gen_helper_check_interrupts(cpu_env
);
1156 gen_jump(dc
, cpu_SR
[EPC1
]);
1162 default: /*reserved*/
1169 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1170 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1171 gen_check_privilege(dc
);
1172 tcg_gen_mov_i32(cpu_SR
[PS
],
1173 cpu_SR
[EPS2
+ RRR_S
- 2]);
1174 gen_helper_check_interrupts(cpu_env
);
1175 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1177 qemu_log("RFI %d is illegal\n", RRR_S
);
1178 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1186 default: /*reserved*/
1194 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1196 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1200 case 5: /*SYSCALLx*/
1201 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1203 case 0: /*SYSCALLx*/
1204 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1208 if (semihosting_enabled
) {
1209 gen_check_privilege(dc
);
1210 gen_helper_simcall(cpu_env
);
1212 qemu_log("SIMCALL but semihosting is disabled\n");
1213 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1224 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1225 gen_check_privilege(dc
);
1226 gen_window_check1(dc
, RRR_T
);
1227 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1228 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1229 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1230 gen_helper_check_interrupts(cpu_env
);
1231 gen_jumpi_check_loop_end(dc
, 0);
1235 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1236 gen_check_privilege(dc
);
1237 gen_waiti(dc
, RRR_S
);
1244 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1246 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1247 TCGv_i32 mask
= tcg_const_i32(
1248 ((1 << shift
) - 1) << RRR_S
);
1249 TCGv_i32 tmp
= tcg_temp_new_i32();
1251 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1252 if (RRR_R
& 1) { /*ALL*/
1253 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1255 tcg_gen_add_i32(tmp
, tmp
, mask
);
1257 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1258 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1260 tcg_temp_free(mask
);
1265 default: /*reserved*/
1273 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1274 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1278 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1279 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1283 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1284 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1290 gen_window_check1(dc
, RRR_S
);
1291 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1295 gen_window_check1(dc
, RRR_S
);
1296 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1300 gen_window_check1(dc
, RRR_S
);
1302 TCGv_i32 tmp
= tcg_temp_new_i32();
1303 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1304 gen_right_shift_sar(dc
, tmp
);
1310 gen_window_check1(dc
, RRR_S
);
1312 TCGv_i32 tmp
= tcg_temp_new_i32();
1313 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1314 gen_left_shift_sar(dc
, tmp
);
1321 TCGv_i32 tmp
= tcg_const_i32(
1322 RRR_S
| ((RRR_T
& 1) << 4));
1323 gen_right_shift_sar(dc
, tmp
);
1337 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1338 gen_check_privilege(dc
);
1340 TCGv_i32 tmp
= tcg_const_i32(
1341 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1342 gen_helper_rotw(cpu_env
, tmp
);
1344 reset_used_window(dc
);
1349 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1350 gen_window_check2(dc
, RRR_S
, RRR_T
);
1351 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1355 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1356 gen_window_check2(dc
, RRR_S
, RRR_T
);
1357 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1360 default: /*reserved*/
1368 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1369 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1370 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1371 gen_check_privilege(dc
);
1372 gen_window_check2(dc
, RRR_S
, RRR_T
);
1374 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1376 switch (RRR_R
& 7) {
1377 case 3: /*RITLB0*/ /*RDTLB0*/
1378 gen_helper_rtlb0(cpu_R
[RRR_T
],
1379 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1382 case 4: /*IITLB*/ /*IDTLB*/
1383 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1384 /* This could change memory mapping, so exit tb */
1385 gen_jumpi_check_loop_end(dc
, -1);
1388 case 5: /*PITLB*/ /*PDTLB*/
1389 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1390 gen_helper_ptlb(cpu_R
[RRR_T
],
1391 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1394 case 6: /*WITLB*/ /*WDTLB*/
1396 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1397 /* This could change memory mapping, so exit tb */
1398 gen_jumpi_check_loop_end(dc
, -1);
1401 case 7: /*RITLB1*/ /*RDTLB1*/
1402 gen_helper_rtlb1(cpu_R
[RRR_T
],
1403 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1407 tcg_temp_free(dtlb
);
1411 tcg_temp_free(dtlb
);
1416 gen_window_check2(dc
, RRR_R
, RRR_T
);
1419 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1424 TCGv_i32 zero
= tcg_const_i32(0);
1425 TCGv_i32 neg
= tcg_temp_new_i32();
1427 tcg_gen_neg_i32(neg
, cpu_R
[RRR_T
]);
1428 tcg_gen_movcond_i32(TCG_COND_GE
, cpu_R
[RRR_R
],
1429 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_T
], neg
);
1431 tcg_temp_free(zero
);
1435 default: /*reserved*/
1441 case 7: /*reserved*/
1446 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1447 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1453 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1455 TCGv_i32 tmp
= tcg_temp_new_i32();
1456 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1457 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1463 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1464 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1470 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1472 TCGv_i32 tmp
= tcg_temp_new_i32();
1473 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1474 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1485 gen_window_check2(dc
, RRR_R
, RRR_S
);
1486 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1487 32 - (RRR_T
| ((OP2
& 1) << 4)));
1492 gen_window_check2(dc
, RRR_R
, RRR_T
);
1493 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1494 RRR_S
| ((OP2
& 1) << 4));
1498 gen_window_check2(dc
, RRR_R
, RRR_T
);
1499 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1503 if (gen_check_sr(dc
, RSR_SR
, SR_X
)) {
1504 TCGv_i32 tmp
= tcg_temp_new_i32();
1507 gen_check_privilege(dc
);
1509 gen_window_check1(dc
, RRR_T
);
1510 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1511 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1512 gen_wsr(dc
, RSR_SR
, tmp
);
1518 * Note: 64 bit ops are used here solely because SAR values
1521 #define gen_shift_reg(cmd, reg) do { \
1522 TCGv_i64 tmp = tcg_temp_new_i64(); \
1523 tcg_gen_extu_i32_i64(tmp, reg); \
1524 tcg_gen_##cmd##_i64(v, v, tmp); \
1525 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \
1526 tcg_temp_free_i64(v); \
1527 tcg_temp_free_i64(tmp); \
1530 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1533 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1535 TCGv_i64 v
= tcg_temp_new_i64();
1536 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1542 gen_window_check2(dc
, RRR_R
, RRR_T
);
1544 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1546 TCGv_i64 v
= tcg_temp_new_i64();
1547 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1553 gen_window_check2(dc
, RRR_R
, RRR_S
);
1554 if (dc
->sar_m32_5bit
) {
1555 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1557 TCGv_i64 v
= tcg_temp_new_i64();
1558 TCGv_i32 s
= tcg_const_i32(32);
1559 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1560 tcg_gen_andi_i32(s
, s
, 0x3f);
1561 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1562 gen_shift_reg(shl
, s
);
1568 gen_window_check2(dc
, RRR_R
, RRR_T
);
1570 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1572 TCGv_i64 v
= tcg_temp_new_i64();
1573 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1578 #undef gen_shift_reg
1581 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1582 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1584 TCGv_i32 v1
= tcg_temp_new_i32();
1585 TCGv_i32 v2
= tcg_temp_new_i32();
1586 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1587 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1588 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1595 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1596 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1598 TCGv_i32 v1
= tcg_temp_new_i32();
1599 TCGv_i32 v2
= tcg_temp_new_i32();
1600 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1601 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1602 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1608 default: /*reserved*/
1616 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1620 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1621 int label
= gen_new_label();
1622 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1623 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1624 gen_set_label(label
);
1628 #define BOOLEAN_LOGIC(fn, r, s, t) \
1630 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1631 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1632 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1634 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1635 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1636 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1637 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1638 tcg_temp_free(tmp1); \
1639 tcg_temp_free(tmp2); \
1643 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1647 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1651 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1655 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1659 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1662 #undef BOOLEAN_LOGIC
1665 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1666 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1671 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1673 TCGv lo
= tcg_temp_new();
1676 tcg_gen_mulu2_i32(lo
, cpu_R
[RRR_R
],
1677 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1679 tcg_gen_muls2_i32(lo
, cpu_R
[RRR_R
],
1680 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1687 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1693 int label1
= gen_new_label();
1694 int label2
= gen_new_label();
1696 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1698 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1700 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1701 OP2
== 13 ? 0x80000000 : 0);
1703 gen_set_label(label1
);
1705 tcg_gen_div_i32(cpu_R
[RRR_R
],
1706 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1708 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1709 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1711 gen_set_label(label2
);
1716 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1719 default: /*reserved*/
1728 if (gen_check_sr(dc
, RSR_SR
, SR_R
)) {
1730 gen_check_privilege(dc
);
1732 gen_window_check1(dc
, RRR_T
);
1733 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1738 if (gen_check_sr(dc
, RSR_SR
, SR_W
)) {
1740 gen_check_privilege(dc
);
1742 gen_window_check1(dc
, RRR_T
);
1743 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1748 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1749 gen_window_check2(dc
, RRR_R
, RRR_S
);
1751 int shift
= 24 - RRR_T
;
1754 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1755 } else if (shift
== 16) {
1756 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1758 TCGv_i32 tmp
= tcg_temp_new_i32();
1759 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1760 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1767 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1768 gen_window_check2(dc
, RRR_R
, RRR_S
);
1770 TCGv_i32 tmp1
= tcg_temp_new_i32();
1771 TCGv_i32 tmp2
= tcg_temp_new_i32();
1772 TCGv_i32 zero
= tcg_const_i32(0);
1774 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1775 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1776 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1778 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1779 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1781 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1782 cpu_R
[RRR_S
], tmp1
);
1783 tcg_temp_free(tmp1
);
1784 tcg_temp_free(tmp2
);
1785 tcg_temp_free(zero
);
1793 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1794 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1796 static const TCGCond cond
[] = {
1802 tcg_gen_movcond_i32(cond
[OP2
- 4], cpu_R
[RRR_R
],
1803 cpu_R
[RRR_S
], cpu_R
[RRR_T
],
1804 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1812 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1814 static const TCGCond cond
[] = {
1820 TCGv_i32 zero
= tcg_const_i32(0);
1822 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1823 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1824 tcg_temp_free(zero
);
1830 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1831 gen_window_check2(dc
, RRR_R
, RRR_S
);
1833 TCGv_i32 zero
= tcg_const_i32(0);
1834 TCGv_i32 tmp
= tcg_temp_new_i32();
1836 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1837 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1838 cpu_R
[RRR_R
], tmp
, zero
,
1839 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1842 tcg_temp_free(zero
);
1847 gen_window_check1(dc
, RRR_R
);
1849 int st
= (RRR_S
<< 4) + RRR_T
;
1850 if (uregnames
[st
].name
) {
1851 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1853 qemu_log("RUR %d not implemented, ", st
);
1860 gen_window_check1(dc
, RRR_T
);
1861 if (uregnames
[RSR_SR
].name
) {
1862 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1864 qemu_log("WUR %d not implemented, ", RSR_SR
);
1874 gen_window_check2(dc
, RRR_R
, RRR_T
);
1876 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1877 int maskimm
= (1 << (OP2
+ 1)) - 1;
1879 TCGv_i32 tmp
= tcg_temp_new_i32();
1880 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1881 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1900 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1901 gen_window_check2(dc
, RRR_S
, RRR_T
);
1902 gen_check_cpenable(dc
, 0);
1904 TCGv_i32 addr
= tcg_temp_new_i32();
1905 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1906 gen_load_store_alignment(dc
, 2, addr
, false);
1908 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1910 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1913 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1915 tcg_temp_free(addr
);
1919 default: /*reserved*/
1926 gen_window_check2(dc
, RRR_S
, RRR_T
);
1929 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1930 gen_check_privilege(dc
);
1932 TCGv_i32 addr
= tcg_temp_new_i32();
1933 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1934 (0xffffffc0 | (RRR_R
<< 2)));
1935 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1936 tcg_temp_free(addr
);
1941 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1942 gen_check_privilege(dc
);
1944 TCGv_i32 addr
= tcg_temp_new_i32();
1945 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1946 (0xffffffc0 | (RRR_R
<< 2)));
1947 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1948 tcg_temp_free(addr
);
1959 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1962 gen_check_cpenable(dc
, 0);
1963 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
1964 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1968 gen_check_cpenable(dc
, 0);
1969 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
1970 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1974 gen_check_cpenable(dc
, 0);
1975 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
1976 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1980 gen_check_cpenable(dc
, 0);
1981 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
1982 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1986 gen_check_cpenable(dc
, 0);
1987 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
1988 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1991 case 8: /*ROUND.Sf*/
1992 case 9: /*TRUNC.Sf*/
1993 case 10: /*FLOOR.Sf*/
1994 case 11: /*CEIL.Sf*/
1995 case 14: /*UTRUNC.Sf*/
1996 gen_window_check1(dc
, RRR_R
);
1997 gen_check_cpenable(dc
, 0);
1999 static const unsigned rounding_mode_const
[] = {
2000 float_round_nearest_even
,
2001 float_round_to_zero
,
2004 [6] = float_round_to_zero
,
2006 TCGv_i32 rounding_mode
= tcg_const_i32(
2007 rounding_mode_const
[OP2
& 7]);
2008 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
2011 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2012 rounding_mode
, scale
);
2014 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2015 rounding_mode
, scale
);
2018 tcg_temp_free(rounding_mode
);
2019 tcg_temp_free(scale
);
2023 case 12: /*FLOAT.Sf*/
2024 case 13: /*UFLOAT.Sf*/
2025 gen_window_check1(dc
, RRR_S
);
2026 gen_check_cpenable(dc
, 0);
2028 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2031 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2032 cpu_R
[RRR_S
], scale
);
2034 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2035 cpu_R
[RRR_S
], scale
);
2037 tcg_temp_free(scale
);
2044 gen_check_cpenable(dc
, 0);
2045 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2049 gen_check_cpenable(dc
, 0);
2050 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2054 gen_window_check1(dc
, RRR_R
);
2055 gen_check_cpenable(dc
, 0);
2056 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2060 gen_window_check1(dc
, RRR_S
);
2061 gen_check_cpenable(dc
, 0);
2062 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2066 gen_check_cpenable(dc
, 0);
2067 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2070 default: /*reserved*/
2076 default: /*reserved*/
2083 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2085 #define gen_compare(rel, br, a, b) \
2087 TCGv_i32 bit = tcg_const_i32(1 << br); \
2089 gen_check_cpenable(dc, 0); \
2090 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2091 tcg_temp_free(bit); \
2096 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2100 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2104 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2108 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2112 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2116 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2120 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2125 case 8: /*MOVEQZ.Sf*/
2126 case 9: /*MOVNEZ.Sf*/
2127 case 10: /*MOVLTZ.Sf*/
2128 case 11: /*MOVGEZ.Sf*/
2129 gen_window_check1(dc
, RRR_T
);
2130 gen_check_cpenable(dc
, 0);
2132 static const TCGCond cond
[] = {
2138 TCGv_i32 zero
= tcg_const_i32(0);
2140 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2141 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2142 tcg_temp_free(zero
);
2146 case 12: /*MOVF.Sf*/
2147 case 13: /*MOVT.Sf*/
2148 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2149 gen_check_cpenable(dc
, 0);
2151 TCGv_i32 zero
= tcg_const_i32(0);
2152 TCGv_i32 tmp
= tcg_temp_new_i32();
2154 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2155 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2156 cpu_FR
[RRR_R
], tmp
, zero
,
2157 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2160 tcg_temp_free(zero
);
2164 default: /*reserved*/
2170 default: /*reserved*/
2177 gen_window_check1(dc
, RRR_T
);
2179 TCGv_i32 tmp
= tcg_const_i32(
2180 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2181 0 : ((dc
->pc
+ 3) & ~3)) +
2182 (0xfffc0000 | (RI16_IMM16
<< 2)));
2184 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2185 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2187 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2193 #define gen_load_store(type, shift) do { \
2194 TCGv_i32 addr = tcg_temp_new_i32(); \
2195 gen_window_check2(dc, RRI8_S, RRI8_T); \
2196 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2198 gen_load_store_alignment(dc, shift, addr, false); \
2200 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2201 tcg_temp_free(addr); \
2206 gen_load_store(ld8u
, 0);
2210 gen_load_store(ld16u
, 1);
2214 gen_load_store(ld32u
, 2);
2218 gen_load_store(st8
, 0);
2222 gen_load_store(st16
, 1);
2226 gen_load_store(st32
, 2);
2231 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2262 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2266 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2270 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2274 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2278 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2281 default: /*reserved*/
2289 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2295 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2299 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2303 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2306 default: /*reserved*/
2313 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2317 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2320 default: /*reserved*/
2327 gen_load_store(ld16s
, 1);
2329 #undef gen_load_store
2332 gen_window_check1(dc
, RRI8_T
);
2333 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2334 RRI8_IMM8
| (RRI8_S
<< 8) |
2335 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2338 #define gen_load_store_no_hw_align(type) do { \
2339 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2340 gen_window_check2(dc, RRI8_S, RRI8_T); \
2341 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2342 gen_load_store_alignment(dc, 2, addr, true); \
2343 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2344 tcg_temp_free(addr); \
2348 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2349 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2353 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2354 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2358 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2359 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
<< 8);
2362 case 14: /*S32C1Iy*/
2363 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2364 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2366 int label
= gen_new_label();
2367 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2368 TCGv_i32 addr
= tcg_temp_local_new_i32();
2371 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2372 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2373 gen_load_store_alignment(dc
, 2, addr
, true);
2375 gen_advance_ccount(dc
);
2376 tpc
= tcg_const_i32(dc
->pc
);
2377 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2378 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2379 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2380 cpu_SR
[SCOMPARE1
], label
);
2382 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2384 gen_set_label(label
);
2386 tcg_temp_free(addr
);
2392 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2393 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2395 #undef gen_load_store_no_hw_align
2397 default: /*reserved*/
2409 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2410 gen_window_check1(dc
, RRI8_S
);
2411 gen_check_cpenable(dc
, 0);
2413 TCGv_i32 addr
= tcg_temp_new_i32();
2414 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2415 gen_load_store_alignment(dc
, 2, addr
, false);
2417 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2419 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2422 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2424 tcg_temp_free(addr
);
2428 default: /*reserved*/
2435 HAS_OPTION(XTENSA_OPTION_MAC16
);
2444 bool is_m1_sr
= (OP2
& 0x3) == 2;
2445 bool is_m2_sr
= (OP2
& 0xc) == 0;
2446 uint32_t ld_offset
= 0;
2453 case 0: /*MACI?/MACC?*/
2455 ld_offset
= (OP2
& 1) ? -4 : 4;
2457 if (OP2
>= 8) { /*MACI/MACC*/
2458 if (OP1
== 0) { /*LDINC/LDDEC*/
2463 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2468 case 2: /*MACD?/MACA?*/
2469 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2475 if (op
!= MAC16_NONE
) {
2477 gen_window_check1(dc
, RRR_S
);
2480 gen_window_check1(dc
, RRR_T
);
2485 TCGv_i32 vaddr
= tcg_temp_new_i32();
2486 TCGv_i32 mem32
= tcg_temp_new_i32();
2489 gen_window_check1(dc
, RRR_S
);
2490 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2491 gen_load_store_alignment(dc
, 2, vaddr
, false);
2492 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2494 if (op
!= MAC16_NONE
) {
2495 TCGv_i32 m1
= gen_mac16_m(
2496 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2497 OP1
& 1, op
== MAC16_UMUL
);
2498 TCGv_i32 m2
= gen_mac16_m(
2499 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2500 OP1
& 2, op
== MAC16_UMUL
);
2502 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2503 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2504 if (op
== MAC16_UMUL
) {
2505 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2507 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2510 TCGv_i32 lo
= tcg_temp_new_i32();
2511 TCGv_i32 hi
= tcg_temp_new_i32();
2513 tcg_gen_mul_i32(lo
, m1
, m2
);
2514 tcg_gen_sari_i32(hi
, lo
, 31);
2515 if (op
== MAC16_MULA
) {
2516 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2517 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2520 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2521 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2524 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2526 tcg_temp_free_i32(lo
);
2527 tcg_temp_free_i32(hi
);
2533 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2534 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2536 tcg_temp_free(vaddr
);
2537 tcg_temp_free(mem32
);
2545 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2546 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2552 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2553 gen_window_check1(dc
, CALL_N
<< 2);
2554 gen_callwi(dc
, CALL_N
,
2555 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2563 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2567 gen_window_check1(dc
, BRI12_S
);
2569 static const TCGCond cond
[] = {
2570 TCG_COND_EQ
, /*BEQZ*/
2571 TCG_COND_NE
, /*BNEZ*/
2572 TCG_COND_LT
, /*BLTZ*/
2573 TCG_COND_GE
, /*BGEZ*/
2576 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2577 4 + BRI12_IMM12_SE
);
2582 gen_window_check1(dc
, BRI8_S
);
2584 static const TCGCond cond
[] = {
2585 TCG_COND_EQ
, /*BEQI*/
2586 TCG_COND_NE
, /*BNEI*/
2587 TCG_COND_LT
, /*BLTI*/
2588 TCG_COND_GE
, /*BGEI*/
2591 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2592 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2599 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2601 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2602 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2603 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2604 gen_advance_ccount(dc
);
2605 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2609 reset_used_window(dc
);
2617 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2619 TCGv_i32 tmp
= tcg_temp_new_i32();
2620 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2622 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2623 tmp
, 0, 4 + RRI8_IMM8_SE
);
2630 case 10: /*LOOPGTZ*/
2631 HAS_OPTION(XTENSA_OPTION_LOOP
);
2632 gen_window_check1(dc
, RRI8_S
);
2634 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2635 TCGv_i32 tmp
= tcg_const_i32(lend
);
2637 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2638 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2639 gen_helper_wsr_lend(cpu_env
, tmp
);
2643 int label
= gen_new_label();
2644 tcg_gen_brcondi_i32(
2645 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2646 cpu_R
[RRI8_S
], 0, label
);
2647 gen_jumpi(dc
, lend
, 1);
2648 gen_set_label(label
);
2651 gen_jumpi(dc
, dc
->next_pc
, 0);
2655 default: /*reserved*/
2664 gen_window_check1(dc
, BRI8_S
);
2665 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2666 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2676 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2678 switch (RRI8_R
& 7) {
2679 case 0: /*BNONE*/ /*BANY*/
2680 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2682 TCGv_i32 tmp
= tcg_temp_new_i32();
2683 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2684 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2689 case 1: /*BEQ*/ /*BNE*/
2690 case 2: /*BLT*/ /*BGE*/
2691 case 3: /*BLTU*/ /*BGEU*/
2692 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2694 static const TCGCond cond
[] = {
2700 [11] = TCG_COND_GEU
,
2702 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2707 case 4: /*BALL*/ /*BNALL*/
2708 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2710 TCGv_i32 tmp
= tcg_temp_new_i32();
2711 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2712 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2718 case 5: /*BBC*/ /*BBS*/
2719 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2721 #ifdef TARGET_WORDS_BIGENDIAN
2722 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2724 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2726 TCGv_i32 tmp
= tcg_temp_new_i32();
2727 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2728 #ifdef TARGET_WORDS_BIGENDIAN
2729 tcg_gen_shr_i32(bit
, bit
, tmp
);
2731 tcg_gen_shl_i32(bit
, bit
, tmp
);
2733 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2734 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2740 case 6: /*BBCI*/ /*BBSI*/
2742 gen_window_check1(dc
, RRI8_S
);
2744 TCGv_i32 tmp
= tcg_temp_new_i32();
2745 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2746 #ifdef TARGET_WORDS_BIGENDIAN
2747 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2749 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2751 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2760 #define gen_narrow_load_store(type) do { \
2761 TCGv_i32 addr = tcg_temp_new_i32(); \
2762 gen_window_check2(dc, RRRN_S, RRRN_T); \
2763 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2764 gen_load_store_alignment(dc, 2, addr, false); \
2765 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2766 tcg_temp_free(addr); \
2770 gen_narrow_load_store(ld32u
);
2774 gen_narrow_load_store(st32
);
2776 #undef gen_narrow_load_store
2779 gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
);
2780 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2783 case 11: /*ADDI.Nn*/
2784 gen_window_check2(dc
, RRRN_R
, RRRN_S
);
2785 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], RRRN_T
? RRRN_T
: -1);
2789 gen_window_check1(dc
, RRRN_S
);
2790 if (RRRN_T
< 8) { /*MOVI.Nn*/
2791 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2792 RRRN_R
| (RRRN_T
<< 4) |
2793 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2794 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2795 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2797 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2798 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2805 gen_window_check2(dc
, RRRN_S
, RRRN_T
);
2806 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2812 gen_jump(dc
, cpu_R
[0]);
2816 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2818 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2819 gen_advance_ccount(dc
);
2820 gen_helper_retw(tmp
, cpu_env
, tmp
);
2826 case 2: /*BREAK.Nn*/
2827 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2829 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2837 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2840 default: /*reserved*/
2846 default: /*reserved*/
2852 default: /*reserved*/
2857 if (dc
->is_jmp
== DISAS_NEXT
) {
2858 gen_check_loop_end(dc
, 0);
2860 dc
->pc
= dc
->next_pc
;
2865 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2866 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2870 static void check_breakpoint(CPUXtensaState
*env
, DisasContext
*dc
)
2874 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2875 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2876 if (bp
->pc
== dc
->pc
) {
2877 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2878 gen_exception(dc
, EXCP_DEBUG
);
2879 dc
->is_jmp
= DISAS_UPDATE
;
2885 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
2889 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
2890 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
2891 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
2892 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
2899 void gen_intermediate_code_internal(XtensaCPU
*cpu
,
2900 TranslationBlock
*tb
, bool search_pc
)
2902 CPUState
*cs
= CPU(cpu
);
2903 CPUXtensaState
*env
= &cpu
->env
;
2907 uint16_t *gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
2908 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2909 uint32_t pc_start
= tb
->pc
;
2910 uint32_t next_page_start
=
2911 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2913 if (max_insns
== 0) {
2914 max_insns
= CF_COUNT_MASK
;
2917 dc
.config
= env
->config
;
2918 dc
.singlestep_enabled
= cs
->singlestep_enabled
;
2921 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
2922 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
2923 dc
.lbeg
= env
->sregs
[LBEG
];
2924 dc
.lend
= env
->sregs
[LEND
];
2925 dc
.is_jmp
= DISAS_NEXT
;
2926 dc
.ccount_delta
= 0;
2927 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
2928 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
2929 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
2930 XTENSA_TBFLAG_CPENABLE_SHIFT
;
2933 init_sar_tracker(&dc
);
2934 reset_used_window(&dc
);
2936 dc
.next_icount
= tcg_temp_local_new_i32();
2941 if (tb
->flags
& XTENSA_TBFLAG_EXCEPTION
) {
2942 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2943 gen_exception(&dc
, EXCP_DEBUG
);
2947 check_breakpoint(env
, &dc
);
2950 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
2954 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2957 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
2958 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
2959 tcg_ctx
.gen_opc_icount
[lj
] = insn_count
;
2962 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
2963 tcg_gen_debug_insn_start(dc
.pc
);
2968 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
2973 int label
= gen_new_label();
2975 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
2976 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
2977 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
2979 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
2981 gen_set_label(label
);
2985 gen_ibreak_check(env
, &dc
);
2988 disas_xtensa_insn(env
, &dc
);
2991 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
2993 if (cs
->singlestep_enabled
) {
2994 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2995 gen_exception(&dc
, EXCP_DEBUG
);
2998 } while (dc
.is_jmp
== DISAS_NEXT
&&
2999 insn_count
< max_insns
&&
3000 dc
.pc
< next_page_start
&&
3001 tcg_ctx
.gen_opc_ptr
< gen_opc_end
);
3004 reset_sar_tracker(&dc
);
3006 tcg_temp_free(dc
.next_icount
);
3009 if (tb
->cflags
& CF_LAST_IO
) {
3013 if (dc
.is_jmp
== DISAS_NEXT
) {
3014 gen_jumpi(&dc
, dc
.pc
, 0);
3016 gen_tb_end(tb
, insn_count
);
3017 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
3020 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
3021 qemu_log("----------------\n");
3022 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
3023 log_target_disas(env
, pc_start
, dc
.pc
- pc_start
, 0);
3028 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3029 memset(tcg_ctx
.gen_opc_instr_start
+ lj
+ 1, 0,
3030 (j
- lj
) * sizeof(tcg_ctx
.gen_opc_instr_start
[0]));
3032 tb
->size
= dc
.pc
- pc_start
;
3033 tb
->icount
= insn_count
;
3037 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3039 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, false);
3042 void gen_intermediate_code_pc(CPUXtensaState
*env
, TranslationBlock
*tb
)
3044 gen_intermediate_code_internal(xtensa_env_get_cpu(env
), tb
, true);
3047 void xtensa_cpu_dump_state(CPUState
*cs
, FILE *f
,
3048 fprintf_function cpu_fprintf
, int flags
)
3050 XtensaCPU
*cpu
= XTENSA_CPU(cs
);
3051 CPUXtensaState
*env
= &cpu
->env
;
3054 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3056 for (i
= j
= 0; i
< 256; ++i
) {
3057 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3058 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3059 (j
++ % 4) == 3 ? '\n' : ' ');
3063 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3065 for (i
= j
= 0; i
< 256; ++i
) {
3066 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3067 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3068 (j
++ % 4) == 3 ? '\n' : ' ');
3072 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3074 for (i
= 0; i
< 16; ++i
) {
3075 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3076 (i
% 4) == 3 ? '\n' : ' ');
3079 cpu_fprintf(f
, "\n");
3081 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3082 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3083 (i
% 4) == 3 ? '\n' : ' ');
3086 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3087 cpu_fprintf(f
, "\n");
3089 for (i
= 0; i
< 16; ++i
) {
3090 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3091 float32_val(env
->fregs
[i
]),
3092 *(float *)&env
->fregs
[i
], (i
% 2) == 1 ? '\n' : ' ');
3097 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
, int pc_pos
)
3099 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];