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
]),
245 static inline bool option_bits_enabled(DisasContext
*dc
, uint64_t opt
)
247 return xtensa_option_bits_enabled(dc
->config
, opt
);
250 static inline bool option_enabled(DisasContext
*dc
, int opt
)
252 return xtensa_option_enabled(dc
->config
, opt
);
255 static void init_litbase(DisasContext
*dc
)
257 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
258 dc
->litbase
= tcg_temp_local_new_i32();
259 tcg_gen_andi_i32(dc
->litbase
, cpu_SR
[LITBASE
], 0xfffff000);
263 static void reset_litbase(DisasContext
*dc
)
265 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
266 tcg_temp_free(dc
->litbase
);
270 static void init_sar_tracker(DisasContext
*dc
)
272 dc
->sar_5bit
= false;
273 dc
->sar_m32_5bit
= false;
274 dc
->sar_m32_allocated
= false;
277 static void reset_sar_tracker(DisasContext
*dc
)
279 if (dc
->sar_m32_allocated
) {
280 tcg_temp_free(dc
->sar_m32
);
284 static void gen_right_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
286 tcg_gen_andi_i32(cpu_SR
[SAR
], sa
, 0x1f);
287 if (dc
->sar_m32_5bit
) {
288 tcg_gen_discard_i32(dc
->sar_m32
);
291 dc
->sar_m32_5bit
= false;
294 static void gen_left_shift_sar(DisasContext
*dc
, TCGv_i32 sa
)
296 TCGv_i32 tmp
= tcg_const_i32(32);
297 if (!dc
->sar_m32_allocated
) {
298 dc
->sar_m32
= tcg_temp_local_new_i32();
299 dc
->sar_m32_allocated
= true;
301 tcg_gen_andi_i32(dc
->sar_m32
, sa
, 0x1f);
302 tcg_gen_sub_i32(cpu_SR
[SAR
], tmp
, dc
->sar_m32
);
303 dc
->sar_5bit
= false;
304 dc
->sar_m32_5bit
= true;
308 static void gen_advance_ccount(DisasContext
*dc
)
310 if (dc
->ccount_delta
> 0) {
311 TCGv_i32 tmp
= tcg_const_i32(dc
->ccount_delta
);
312 dc
->ccount_delta
= 0;
313 gen_helper_advance_ccount(cpu_env
, tmp
);
318 static void reset_used_window(DisasContext
*dc
)
323 static void gen_exception(DisasContext
*dc
, int excp
)
325 TCGv_i32 tmp
= tcg_const_i32(excp
);
326 gen_advance_ccount(dc
);
327 gen_helper_exception(cpu_env
, tmp
);
331 static void gen_exception_cause(DisasContext
*dc
, uint32_t cause
)
333 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
334 TCGv_i32 tcause
= tcg_const_i32(cause
);
335 gen_advance_ccount(dc
);
336 gen_helper_exception_cause(cpu_env
, tpc
, tcause
);
338 tcg_temp_free(tcause
);
339 if (cause
== ILLEGAL_INSTRUCTION_CAUSE
||
340 cause
== SYSCALL_CAUSE
) {
341 dc
->is_jmp
= DISAS_UPDATE
;
345 static void gen_exception_cause_vaddr(DisasContext
*dc
, uint32_t cause
,
348 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
349 TCGv_i32 tcause
= tcg_const_i32(cause
);
350 gen_advance_ccount(dc
);
351 gen_helper_exception_cause_vaddr(cpu_env
, tpc
, tcause
, vaddr
);
353 tcg_temp_free(tcause
);
356 static void gen_debug_exception(DisasContext
*dc
, uint32_t cause
)
358 TCGv_i32 tpc
= tcg_const_i32(dc
->pc
);
359 TCGv_i32 tcause
= tcg_const_i32(cause
);
360 gen_advance_ccount(dc
);
361 gen_helper_debug_exception(cpu_env
, tpc
, tcause
);
363 tcg_temp_free(tcause
);
364 if (cause
& (DEBUGCAUSE_IB
| DEBUGCAUSE_BI
| DEBUGCAUSE_BN
)) {
365 dc
->is_jmp
= DISAS_UPDATE
;
369 static void gen_check_privilege(DisasContext
*dc
)
372 gen_exception_cause(dc
, PRIVILEGED_CAUSE
);
373 dc
->is_jmp
= DISAS_UPDATE
;
377 static void gen_check_cpenable(DisasContext
*dc
, unsigned cp
)
379 if (option_enabled(dc
, XTENSA_OPTION_COPROCESSOR
) &&
380 !(dc
->cpenable
& (1 << cp
))) {
381 gen_exception_cause(dc
, COPROCESSOR0_DISABLED
+ cp
);
382 dc
->is_jmp
= DISAS_UPDATE
;
386 static void gen_jump_slot(DisasContext
*dc
, TCGv dest
, int slot
)
388 tcg_gen_mov_i32(cpu_pc
, dest
);
389 gen_advance_ccount(dc
);
391 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
->next_icount
);
393 if (dc
->singlestep_enabled
) {
394 gen_exception(dc
, EXCP_DEBUG
);
397 tcg_gen_goto_tb(slot
);
398 tcg_gen_exit_tb((tcg_target_long
)dc
->tb
+ slot
);
403 dc
->is_jmp
= DISAS_UPDATE
;
406 static void gen_jump(DisasContext
*dc
, TCGv dest
)
408 gen_jump_slot(dc
, dest
, -1);
411 static void gen_jumpi(DisasContext
*dc
, uint32_t dest
, int slot
)
413 TCGv_i32 tmp
= tcg_const_i32(dest
);
414 if (((dc
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
417 gen_jump_slot(dc
, tmp
, slot
);
421 static void gen_callw_slot(DisasContext
*dc
, int callinc
, TCGv_i32 dest
,
424 TCGv_i32 tcallinc
= tcg_const_i32(callinc
);
426 tcg_gen_deposit_i32(cpu_SR
[PS
], cpu_SR
[PS
],
427 tcallinc
, PS_CALLINC_SHIFT
, PS_CALLINC_LEN
);
428 tcg_temp_free(tcallinc
);
429 tcg_gen_movi_i32(cpu_R
[callinc
<< 2],
430 (callinc
<< 30) | (dc
->next_pc
& 0x3fffffff));
431 gen_jump_slot(dc
, dest
, slot
);
434 static void gen_callw(DisasContext
*dc
, int callinc
, TCGv_i32 dest
)
436 gen_callw_slot(dc
, callinc
, dest
, -1);
439 static void gen_callwi(DisasContext
*dc
, int callinc
, uint32_t dest
, int slot
)
441 TCGv_i32 tmp
= tcg_const_i32(dest
);
442 if (((dc
->pc
^ dest
) & TARGET_PAGE_MASK
) != 0) {
445 gen_callw_slot(dc
, callinc
, tmp
, slot
);
449 static bool gen_check_loop_end(DisasContext
*dc
, int slot
)
451 if (option_enabled(dc
, XTENSA_OPTION_LOOP
) &&
452 !(dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) &&
453 dc
->next_pc
== dc
->lend
) {
454 int label
= gen_new_label();
456 gen_advance_ccount(dc
);
457 tcg_gen_brcondi_i32(TCG_COND_EQ
, cpu_SR
[LCOUNT
], 0, label
);
458 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_SR
[LCOUNT
], 1);
459 gen_jumpi(dc
, dc
->lbeg
, slot
);
460 gen_set_label(label
);
461 gen_jumpi(dc
, dc
->next_pc
, -1);
467 static void gen_jumpi_check_loop_end(DisasContext
*dc
, int slot
)
469 if (!gen_check_loop_end(dc
, slot
)) {
470 gen_jumpi(dc
, dc
->next_pc
, slot
);
474 static void gen_brcond(DisasContext
*dc
, TCGCond cond
,
475 TCGv_i32 t0
, TCGv_i32 t1
, uint32_t offset
)
477 int label
= gen_new_label();
479 gen_advance_ccount(dc
);
480 tcg_gen_brcond_i32(cond
, t0
, t1
, label
);
481 gen_jumpi_check_loop_end(dc
, 0);
482 gen_set_label(label
);
483 gen_jumpi(dc
, dc
->pc
+ offset
, 1);
486 static void gen_brcondi(DisasContext
*dc
, TCGCond cond
,
487 TCGv_i32 t0
, uint32_t t1
, uint32_t offset
)
489 TCGv_i32 tmp
= tcg_const_i32(t1
);
490 gen_brcond(dc
, cond
, t0
, tmp
, offset
);
494 static void gen_check_sr(DisasContext
*dc
, uint32_t sr
, unsigned access
)
496 if (!xtensa_option_bits_enabled(dc
->config
, sregnames
[sr
].opt_bits
)) {
497 if (sregnames
[sr
].name
) {
498 qemu_log("SR %s is not configured\n", sregnames
[sr
].name
);
500 qemu_log("SR %d is not implemented\n", sr
);
502 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
503 } else if (!(sregnames
[sr
].access
& access
)) {
504 static const char * const access_text
[] = {
509 assert(access
< ARRAY_SIZE(access_text
) && access_text
[access
]);
510 qemu_log("SR %s is not available for %s\n", sregnames
[sr
].name
,
511 access_text
[access
]);
512 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
516 static void gen_rsr_ccount(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
518 gen_advance_ccount(dc
);
519 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
522 static void gen_rsr_ptevaddr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
524 tcg_gen_shri_i32(d
, cpu_SR
[EXCVADDR
], 10);
525 tcg_gen_or_i32(d
, d
, cpu_SR
[sr
]);
526 tcg_gen_andi_i32(d
, d
, 0xfffffffc);
529 static void gen_rsr(DisasContext
*dc
, TCGv_i32 d
, uint32_t sr
)
531 static void (* const rsr_handler
[256])(DisasContext
*dc
,
532 TCGv_i32 d
, uint32_t sr
) = {
533 [CCOUNT
] = gen_rsr_ccount
,
534 [PTEVADDR
] = gen_rsr_ptevaddr
,
537 if (rsr_handler
[sr
]) {
538 rsr_handler
[sr
](dc
, d
, sr
);
540 tcg_gen_mov_i32(d
, cpu_SR
[sr
]);
544 static void gen_wsr_lbeg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
546 gen_helper_wsr_lbeg(cpu_env
, s
);
547 gen_jumpi_check_loop_end(dc
, 0);
550 static void gen_wsr_lend(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
552 gen_helper_wsr_lend(cpu_env
, s
);
553 gen_jumpi_check_loop_end(dc
, 0);
556 static void gen_wsr_sar(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
558 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0x3f);
559 if (dc
->sar_m32_5bit
) {
560 tcg_gen_discard_i32(dc
->sar_m32
);
562 dc
->sar_5bit
= false;
563 dc
->sar_m32_5bit
= false;
566 static void gen_wsr_br(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
568 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xffff);
571 static void gen_wsr_litbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
573 tcg_gen_andi_i32(cpu_SR
[sr
], s
, 0xfffff001);
574 /* This can change tb->flags, so exit tb */
575 gen_jumpi_check_loop_end(dc
, -1);
578 static void gen_wsr_acchi(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
580 tcg_gen_ext8s_i32(cpu_SR
[sr
], s
);
583 static void gen_wsr_windowbase(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
585 gen_helper_wsr_windowbase(cpu_env
, v
);
586 reset_used_window(dc
);
589 static void gen_wsr_windowstart(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
591 tcg_gen_andi_i32(cpu_SR
[sr
], v
, (1 << dc
->config
->nareg
/ 4) - 1);
592 reset_used_window(dc
);
595 static void gen_wsr_ptevaddr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
597 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xffc00000);
600 static void gen_wsr_rasid(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
602 gen_helper_wsr_rasid(cpu_env
, v
);
603 /* This can change tb->flags, so exit tb */
604 gen_jumpi_check_loop_end(dc
, -1);
607 static void gen_wsr_tlbcfg(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
609 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x01130000);
612 static void gen_wsr_ibreakenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
614 gen_helper_wsr_ibreakenable(cpu_env
, v
);
615 gen_jumpi_check_loop_end(dc
, 0);
618 static void gen_wsr_atomctl(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
620 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0x3f);
623 static void gen_wsr_ibreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
625 unsigned id
= sr
- IBREAKA
;
627 if (id
< dc
->config
->nibreak
) {
628 TCGv_i32 tmp
= tcg_const_i32(id
);
629 gen_helper_wsr_ibreaka(cpu_env
, tmp
, v
);
631 gen_jumpi_check_loop_end(dc
, 0);
635 static void gen_wsr_dbreaka(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
637 unsigned id
= sr
- DBREAKA
;
639 if (id
< dc
->config
->ndbreak
) {
640 TCGv_i32 tmp
= tcg_const_i32(id
);
641 gen_helper_wsr_dbreaka(cpu_env
, tmp
, v
);
646 static void gen_wsr_dbreakc(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
648 unsigned id
= sr
- DBREAKC
;
650 if (id
< dc
->config
->ndbreak
) {
651 TCGv_i32 tmp
= tcg_const_i32(id
);
652 gen_helper_wsr_dbreakc(cpu_env
, tmp
, v
);
657 static void gen_wsr_cpenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
659 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xff);
660 /* This can change tb->flags, so exit tb */
661 gen_jumpi_check_loop_end(dc
, -1);
664 static void gen_wsr_intset(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
666 tcg_gen_andi_i32(cpu_SR
[sr
], v
,
667 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
668 gen_helper_check_interrupts(cpu_env
);
669 gen_jumpi_check_loop_end(dc
, 0);
672 static void gen_wsr_intclear(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
674 TCGv_i32 tmp
= tcg_temp_new_i32();
676 tcg_gen_andi_i32(tmp
, v
,
677 dc
->config
->inttype_mask
[INTTYPE_EDGE
] |
678 dc
->config
->inttype_mask
[INTTYPE_NMI
] |
679 dc
->config
->inttype_mask
[INTTYPE_SOFTWARE
]);
680 tcg_gen_andc_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], tmp
);
682 gen_helper_check_interrupts(cpu_env
);
685 static void gen_wsr_intenable(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
687 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
688 gen_helper_check_interrupts(cpu_env
);
689 gen_jumpi_check_loop_end(dc
, 0);
692 static void gen_wsr_ps(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
694 uint32_t mask
= PS_WOE
| PS_CALLINC
| PS_OWB
|
695 PS_UM
| PS_EXCM
| PS_INTLEVEL
;
697 if (option_enabled(dc
, XTENSA_OPTION_MMU
)) {
700 tcg_gen_andi_i32(cpu_SR
[sr
], v
, mask
);
701 reset_used_window(dc
);
702 gen_helper_check_interrupts(cpu_env
);
703 /* This can change mmu index and tb->flags, so exit tb */
704 gen_jumpi_check_loop_end(dc
, -1);
707 static void gen_wsr_icount(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
710 tcg_gen_mov_i32(dc
->next_icount
, v
);
712 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
716 static void gen_wsr_icountlevel(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
718 tcg_gen_andi_i32(cpu_SR
[sr
], v
, 0xf);
719 /* This can change tb->flags, so exit tb */
720 gen_jumpi_check_loop_end(dc
, -1);
723 static void gen_wsr_ccompare(DisasContext
*dc
, uint32_t sr
, TCGv_i32 v
)
725 uint32_t id
= sr
- CCOMPARE
;
726 if (id
< dc
->config
->nccompare
) {
727 uint32_t int_bit
= 1 << dc
->config
->timerint
[id
];
728 gen_advance_ccount(dc
);
729 tcg_gen_mov_i32(cpu_SR
[sr
], v
);
730 tcg_gen_andi_i32(cpu_SR
[INTSET
], cpu_SR
[INTSET
], ~int_bit
);
731 gen_helper_check_interrupts(cpu_env
);
735 static void gen_wsr(DisasContext
*dc
, uint32_t sr
, TCGv_i32 s
)
737 static void (* const wsr_handler
[256])(DisasContext
*dc
,
738 uint32_t sr
, TCGv_i32 v
) = {
739 [LBEG
] = gen_wsr_lbeg
,
740 [LEND
] = gen_wsr_lend
,
743 [LITBASE
] = gen_wsr_litbase
,
744 [ACCHI
] = gen_wsr_acchi
,
745 [WINDOW_BASE
] = gen_wsr_windowbase
,
746 [WINDOW_START
] = gen_wsr_windowstart
,
747 [PTEVADDR
] = gen_wsr_ptevaddr
,
748 [RASID
] = gen_wsr_rasid
,
749 [ITLBCFG
] = gen_wsr_tlbcfg
,
750 [DTLBCFG
] = gen_wsr_tlbcfg
,
751 [IBREAKENABLE
] = gen_wsr_ibreakenable
,
752 [ATOMCTL
] = gen_wsr_atomctl
,
753 [IBREAKA
] = gen_wsr_ibreaka
,
754 [IBREAKA
+ 1] = gen_wsr_ibreaka
,
755 [DBREAKA
] = gen_wsr_dbreaka
,
756 [DBREAKA
+ 1] = gen_wsr_dbreaka
,
757 [DBREAKC
] = gen_wsr_dbreakc
,
758 [DBREAKC
+ 1] = gen_wsr_dbreakc
,
759 [CPENABLE
] = gen_wsr_cpenable
,
760 [INTSET
] = gen_wsr_intset
,
761 [INTCLEAR
] = gen_wsr_intclear
,
762 [INTENABLE
] = gen_wsr_intenable
,
764 [ICOUNT
] = gen_wsr_icount
,
765 [ICOUNTLEVEL
] = gen_wsr_icountlevel
,
766 [CCOMPARE
] = gen_wsr_ccompare
,
767 [CCOMPARE
+ 1] = gen_wsr_ccompare
,
768 [CCOMPARE
+ 2] = gen_wsr_ccompare
,
771 if (wsr_handler
[sr
]) {
772 wsr_handler
[sr
](dc
, sr
, s
);
774 tcg_gen_mov_i32(cpu_SR
[sr
], s
);
778 static void gen_wur(uint32_t ur
, TCGv_i32 s
)
782 gen_helper_wur_fcr(cpu_env
, s
);
786 tcg_gen_andi_i32(cpu_UR
[ur
], s
, 0xffffff80);
790 tcg_gen_mov_i32(cpu_UR
[ur
], s
);
795 static void gen_load_store_alignment(DisasContext
*dc
, int shift
,
796 TCGv_i32 addr
, bool no_hw_alignment
)
798 if (!option_enabled(dc
, XTENSA_OPTION_UNALIGNED_EXCEPTION
)) {
799 tcg_gen_andi_i32(addr
, addr
, ~0 << shift
);
800 } else if (option_enabled(dc
, XTENSA_OPTION_HW_ALIGNMENT
) &&
802 int label
= gen_new_label();
803 TCGv_i32 tmp
= tcg_temp_new_i32();
804 tcg_gen_andi_i32(tmp
, addr
, ~(~0 << shift
));
805 tcg_gen_brcondi_i32(TCG_COND_EQ
, tmp
, 0, label
);
806 gen_exception_cause_vaddr(dc
, LOAD_STORE_ALIGNMENT_CAUSE
, addr
);
807 gen_set_label(label
);
812 static void gen_waiti(DisasContext
*dc
, uint32_t imm4
)
814 TCGv_i32 pc
= tcg_const_i32(dc
->next_pc
);
815 TCGv_i32 intlevel
= tcg_const_i32(imm4
);
816 gen_advance_ccount(dc
);
817 gen_helper_waiti(cpu_env
, pc
, intlevel
);
819 tcg_temp_free(intlevel
);
822 static void gen_window_check1(DisasContext
*dc
, unsigned r1
)
824 if (dc
->tb
->flags
& XTENSA_TBFLAG_EXCM
) {
827 if (option_enabled(dc
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
828 r1
/ 4 > dc
->used_window
) {
829 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
830 TCGv_i32 w
= tcg_const_i32(r1
/ 4);
832 dc
->used_window
= r1
/ 4;
833 gen_advance_ccount(dc
);
834 gen_helper_window_check(cpu_env
, pc
, w
);
841 static void gen_window_check2(DisasContext
*dc
, unsigned r1
, unsigned r2
)
843 gen_window_check1(dc
, r1
> r2
? r1
: r2
);
846 static void gen_window_check3(DisasContext
*dc
, unsigned r1
, unsigned r2
,
849 gen_window_check2(dc
, r1
, r2
> r3
? r2
: r3
);
852 static TCGv_i32
gen_mac16_m(TCGv_i32 v
, bool hi
, bool is_unsigned
)
854 TCGv_i32 m
= tcg_temp_new_i32();
857 (is_unsigned
? tcg_gen_shri_i32
: tcg_gen_sari_i32
)(m
, v
, 16);
859 (is_unsigned
? tcg_gen_ext16u_i32
: tcg_gen_ext16s_i32
)(m
, v
);
864 static void disas_xtensa_insn(CPUXtensaState
*env
, DisasContext
*dc
)
866 #define HAS_OPTION_BITS(opt) do { \
867 if (!option_bits_enabled(dc, opt)) { \
868 qemu_log("Option is not enabled %s:%d\n", \
869 __FILE__, __LINE__); \
870 goto invalid_opcode; \
874 #define HAS_OPTION(opt) HAS_OPTION_BITS(XTENSA_OPTION_BIT(opt))
876 #define TBD() qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__)
877 #define RESERVED() do { \
878 qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \
879 dc->pc, b0, b1, b2, __FILE__, __LINE__); \
880 goto invalid_opcode; \
884 #ifdef TARGET_WORDS_BIGENDIAN
885 #define OP0 (((b0) & 0xf0) >> 4)
886 #define OP1 (((b2) & 0xf0) >> 4)
887 #define OP2 ((b2) & 0xf)
888 #define RRR_R ((b1) & 0xf)
889 #define RRR_S (((b1) & 0xf0) >> 4)
890 #define RRR_T ((b0) & 0xf)
892 #define OP0 (((b0) & 0xf))
893 #define OP1 (((b2) & 0xf))
894 #define OP2 (((b2) & 0xf0) >> 4)
895 #define RRR_R (((b1) & 0xf0) >> 4)
896 #define RRR_S (((b1) & 0xf))
897 #define RRR_T (((b0) & 0xf0) >> 4)
899 #define RRR_X ((RRR_R & 0x4) >> 2)
900 #define RRR_Y ((RRR_T & 0x4) >> 2)
901 #define RRR_W (RRR_R & 0x3)
910 #define RRI8_IMM8 (b2)
911 #define RRI8_IMM8_SE ((((b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8)
913 #ifdef TARGET_WORDS_BIGENDIAN
914 #define RI16_IMM16 (((b1) << 8) | (b2))
916 #define RI16_IMM16 (((b2) << 8) | (b1))
919 #ifdef TARGET_WORDS_BIGENDIAN
920 #define CALL_N (((b0) & 0xc) >> 2)
921 #define CALL_OFFSET ((((b0) & 0x3) << 16) | ((b1) << 8) | (b2))
923 #define CALL_N (((b0) & 0x30) >> 4)
924 #define CALL_OFFSET ((((b0) & 0xc0) >> 6) | ((b1) << 2) | ((b2) << 10))
926 #define CALL_OFFSET_SE \
927 (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)
929 #define CALLX_N CALL_N
930 #ifdef TARGET_WORDS_BIGENDIAN
931 #define CALLX_M ((b0) & 0x3)
933 #define CALLX_M (((b0) & 0xc0) >> 6)
935 #define CALLX_S RRR_S
937 #define BRI12_M CALLX_M
938 #define BRI12_S RRR_S
939 #ifdef TARGET_WORDS_BIGENDIAN
940 #define BRI12_IMM12 ((((b1) & 0xf) << 8) | (b2))
942 #define BRI12_IMM12 ((((b1) & 0xf0) >> 4) | ((b2) << 4))
944 #define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)
946 #define BRI8_M BRI12_M
947 #define BRI8_R RRI8_R
948 #define BRI8_S RRI8_S
949 #define BRI8_IMM8 RRI8_IMM8
950 #define BRI8_IMM8_SE RRI8_IMM8_SE
954 uint8_t b0
= cpu_ldub_code(env
, dc
->pc
);
955 uint8_t b1
= cpu_ldub_code(env
, dc
->pc
+ 1);
958 static const uint32_t B4CONST
[] = {
959 0xffffffff, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
962 static const uint32_t B4CONSTU
[] = {
963 32768, 65536, 2, 3, 4, 5, 6, 7, 8, 10, 12, 16, 32, 64, 128, 256
967 dc
->next_pc
= dc
->pc
+ 2;
968 HAS_OPTION(XTENSA_OPTION_CODE_DENSITY
);
970 dc
->next_pc
= dc
->pc
+ 3;
971 b2
= cpu_ldub_code(env
, dc
->pc
+ 2);
980 if ((RRR_R
& 0xc) == 0x8) {
981 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
988 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
999 gen_window_check1(dc
, CALLX_S
);
1000 gen_jump(dc
, cpu_R
[CALLX_S
]);
1004 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1006 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
1007 gen_advance_ccount(dc
);
1008 gen_helper_retw(tmp
, cpu_env
, tmp
);
1014 case 3: /*reserved*/
1021 gen_window_check2(dc
, CALLX_S
, CALLX_N
<< 2);
1025 TCGv_i32 tmp
= tcg_temp_new_i32();
1026 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1027 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
1035 case 3: /*CALLX12w*/
1036 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1038 TCGv_i32 tmp
= tcg_temp_new_i32();
1040 tcg_gen_mov_i32(tmp
, cpu_R
[CALLX_S
]);
1041 gen_callw(dc
, CALLX_N
, tmp
);
1051 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1052 gen_window_check2(dc
, RRR_T
, RRR_S
);
1054 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
1055 gen_advance_ccount(dc
);
1056 gen_helper_movsp(cpu_env
, pc
);
1057 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1077 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1089 default: /*reserved*/
1098 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1101 gen_check_privilege(dc
);
1102 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1103 gen_helper_check_interrupts(cpu_env
);
1104 gen_jump(dc
, cpu_SR
[EPC1
]);
1112 gen_check_privilege(dc
);
1113 gen_jump(dc
, cpu_SR
[
1114 dc
->config
->ndepc
? DEPC
: EPC1
]);
1119 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1120 gen_check_privilege(dc
);
1122 TCGv_i32 tmp
= tcg_const_i32(1);
1125 cpu_SR
[PS
], cpu_SR
[PS
], ~PS_EXCM
);
1126 tcg_gen_shl_i32(tmp
, tmp
, cpu_SR
[WINDOW_BASE
]);
1129 tcg_gen_andc_i32(cpu_SR
[WINDOW_START
],
1130 cpu_SR
[WINDOW_START
], tmp
);
1132 tcg_gen_or_i32(cpu_SR
[WINDOW_START
],
1133 cpu_SR
[WINDOW_START
], tmp
);
1136 gen_helper_restore_owb(cpu_env
);
1137 gen_helper_check_interrupts(cpu_env
);
1138 gen_jump(dc
, cpu_SR
[EPC1
]);
1144 default: /*reserved*/
1151 HAS_OPTION(XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
);
1152 if (RRR_S
>= 2 && RRR_S
<= dc
->config
->nlevel
) {
1153 gen_check_privilege(dc
);
1154 tcg_gen_mov_i32(cpu_SR
[PS
],
1155 cpu_SR
[EPS2
+ RRR_S
- 2]);
1156 gen_helper_check_interrupts(cpu_env
);
1157 gen_jump(dc
, cpu_SR
[EPC1
+ RRR_S
- 1]);
1159 qemu_log("RFI %d is illegal\n", RRR_S
);
1160 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1168 default: /*reserved*/
1176 HAS_OPTION(XTENSA_OPTION_DEBUG
);
1178 gen_debug_exception(dc
, DEBUGCAUSE_BI
);
1182 case 5: /*SYSCALLx*/
1183 HAS_OPTION(XTENSA_OPTION_EXCEPTION
);
1185 case 0: /*SYSCALLx*/
1186 gen_exception_cause(dc
, SYSCALL_CAUSE
);
1190 if (semihosting_enabled
) {
1191 gen_check_privilege(dc
);
1192 gen_helper_simcall(cpu_env
);
1194 qemu_log("SIMCALL but semihosting is disabled\n");
1195 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
1206 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1207 gen_check_privilege(dc
);
1208 gen_window_check1(dc
, RRR_T
);
1209 tcg_gen_mov_i32(cpu_R
[RRR_T
], cpu_SR
[PS
]);
1210 tcg_gen_andi_i32(cpu_SR
[PS
], cpu_SR
[PS
], ~PS_INTLEVEL
);
1211 tcg_gen_ori_i32(cpu_SR
[PS
], cpu_SR
[PS
], RRR_S
);
1212 gen_helper_check_interrupts(cpu_env
);
1213 gen_jumpi_check_loop_end(dc
, 0);
1217 HAS_OPTION(XTENSA_OPTION_INTERRUPT
);
1218 gen_check_privilege(dc
);
1219 gen_waiti(dc
, RRR_S
);
1226 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1228 const unsigned shift
= (RRR_R
& 2) ? 8 : 4;
1229 TCGv_i32 mask
= tcg_const_i32(
1230 ((1 << shift
) - 1) << RRR_S
);
1231 TCGv_i32 tmp
= tcg_temp_new_i32();
1233 tcg_gen_and_i32(tmp
, cpu_SR
[BR
], mask
);
1234 if (RRR_R
& 1) { /*ALL*/
1235 tcg_gen_addi_i32(tmp
, tmp
, 1 << RRR_S
);
1237 tcg_gen_add_i32(tmp
, tmp
, mask
);
1239 tcg_gen_shri_i32(tmp
, tmp
, RRR_S
+ shift
);
1240 tcg_gen_deposit_i32(cpu_SR
[BR
], cpu_SR
[BR
],
1242 tcg_temp_free(mask
);
1247 default: /*reserved*/
1255 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1256 tcg_gen_and_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1260 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1261 tcg_gen_or_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1265 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1266 tcg_gen_xor_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1272 gen_window_check1(dc
, RRR_S
);
1273 gen_right_shift_sar(dc
, cpu_R
[RRR_S
]);
1277 gen_window_check1(dc
, RRR_S
);
1278 gen_left_shift_sar(dc
, cpu_R
[RRR_S
]);
1282 gen_window_check1(dc
, RRR_S
);
1284 TCGv_i32 tmp
= tcg_temp_new_i32();
1285 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1286 gen_right_shift_sar(dc
, tmp
);
1292 gen_window_check1(dc
, RRR_S
);
1294 TCGv_i32 tmp
= tcg_temp_new_i32();
1295 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], 3);
1296 gen_left_shift_sar(dc
, tmp
);
1303 TCGv_i32 tmp
= tcg_const_i32(
1304 RRR_S
| ((RRR_T
& 1) << 4));
1305 gen_right_shift_sar(dc
, tmp
);
1319 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1320 gen_check_privilege(dc
);
1322 TCGv_i32 tmp
= tcg_const_i32(
1323 RRR_T
| ((RRR_T
& 8) ? 0xfffffff0 : 0));
1324 gen_helper_rotw(cpu_env
, tmp
);
1326 reset_used_window(dc
);
1331 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1332 gen_window_check2(dc
, RRR_S
, RRR_T
);
1333 gen_helper_nsa(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1337 HAS_OPTION(XTENSA_OPTION_MISC_OP_NSA
);
1338 gen_window_check2(dc
, RRR_S
, RRR_T
);
1339 gen_helper_nsau(cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1342 default: /*reserved*/
1350 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
1351 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_PROTECTION
) |
1352 XTENSA_OPTION_BIT(XTENSA_OPTION_REGION_TRANSLATION
));
1353 gen_check_privilege(dc
);
1354 gen_window_check2(dc
, RRR_S
, RRR_T
);
1356 TCGv_i32 dtlb
= tcg_const_i32((RRR_R
& 8) != 0);
1358 switch (RRR_R
& 7) {
1359 case 3: /*RITLB0*/ /*RDTLB0*/
1360 gen_helper_rtlb0(cpu_R
[RRR_T
],
1361 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1364 case 4: /*IITLB*/ /*IDTLB*/
1365 gen_helper_itlb(cpu_env
, cpu_R
[RRR_S
], dtlb
);
1366 /* This could change memory mapping, so exit tb */
1367 gen_jumpi_check_loop_end(dc
, -1);
1370 case 5: /*PITLB*/ /*PDTLB*/
1371 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
1372 gen_helper_ptlb(cpu_R
[RRR_T
],
1373 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1376 case 6: /*WITLB*/ /*WDTLB*/
1378 cpu_env
, cpu_R
[RRR_T
], cpu_R
[RRR_S
], dtlb
);
1379 /* This could change memory mapping, so exit tb */
1380 gen_jumpi_check_loop_end(dc
, -1);
1383 case 7: /*RITLB1*/ /*RDTLB1*/
1384 gen_helper_rtlb1(cpu_R
[RRR_T
],
1385 cpu_env
, cpu_R
[RRR_S
], dtlb
);
1389 tcg_temp_free(dtlb
);
1393 tcg_temp_free(dtlb
);
1398 gen_window_check2(dc
, RRR_R
, RRR_T
);
1401 tcg_gen_neg_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
]);
1406 TCGv_i32 zero
= tcg_const_i32(0);
1407 TCGv_i32 neg
= tcg_temp_new_i32();
1409 tcg_gen_neg_i32(neg
, cpu_R
[RRR_T
]);
1410 tcg_gen_movcond_i32(TCG_COND_GE
, cpu_R
[RRR_R
],
1411 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_T
], neg
);
1413 tcg_temp_free(zero
);
1417 default: /*reserved*/
1423 case 7: /*reserved*/
1428 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1429 tcg_gen_add_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1435 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1437 TCGv_i32 tmp
= tcg_temp_new_i32();
1438 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 8);
1439 tcg_gen_add_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1445 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1446 tcg_gen_sub_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1452 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1454 TCGv_i32 tmp
= tcg_temp_new_i32();
1455 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], OP2
- 12);
1456 tcg_gen_sub_i32(cpu_R
[RRR_R
], tmp
, cpu_R
[RRR_T
]);
1467 gen_window_check2(dc
, RRR_R
, RRR_S
);
1468 tcg_gen_shli_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
],
1469 32 - (RRR_T
| ((OP2
& 1) << 4)));
1474 gen_window_check2(dc
, RRR_R
, RRR_T
);
1475 tcg_gen_sari_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
],
1476 RRR_S
| ((OP2
& 1) << 4));
1480 gen_window_check2(dc
, RRR_R
, RRR_T
);
1481 tcg_gen_shri_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], RRR_S
);
1486 TCGv_i32 tmp
= tcg_temp_new_i32();
1487 gen_check_sr(dc
, RSR_SR
, SR_X
);
1489 gen_check_privilege(dc
);
1491 gen_window_check1(dc
, RRR_T
);
1492 tcg_gen_mov_i32(tmp
, cpu_R
[RRR_T
]);
1493 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1494 gen_wsr(dc
, RSR_SR
, tmp
);
1500 * Note: 64 bit ops are used here solely because SAR values
1503 #define gen_shift_reg(cmd, reg) do { \
1504 TCGv_i64 tmp = tcg_temp_new_i64(); \
1505 tcg_gen_extu_i32_i64(tmp, reg); \
1506 tcg_gen_##cmd##_i64(v, v, tmp); \
1507 tcg_gen_trunc_i64_i32(cpu_R[RRR_R], v); \
1508 tcg_temp_free_i64(v); \
1509 tcg_temp_free_i64(tmp); \
1512 #define gen_shift(cmd) gen_shift_reg(cmd, cpu_SR[SAR])
1515 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1517 TCGv_i64 v
= tcg_temp_new_i64();
1518 tcg_gen_concat_i32_i64(v
, cpu_R
[RRR_T
], cpu_R
[RRR_S
]);
1524 gen_window_check2(dc
, RRR_R
, RRR_T
);
1526 tcg_gen_shr_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1528 TCGv_i64 v
= tcg_temp_new_i64();
1529 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_T
]);
1535 gen_window_check2(dc
, RRR_R
, RRR_S
);
1536 if (dc
->sar_m32_5bit
) {
1537 tcg_gen_shl_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], dc
->sar_m32
);
1539 TCGv_i64 v
= tcg_temp_new_i64();
1540 TCGv_i32 s
= tcg_const_i32(32);
1541 tcg_gen_sub_i32(s
, s
, cpu_SR
[SAR
]);
1542 tcg_gen_andi_i32(s
, s
, 0x3f);
1543 tcg_gen_extu_i32_i64(v
, cpu_R
[RRR_S
]);
1544 gen_shift_reg(shl
, s
);
1550 gen_window_check2(dc
, RRR_R
, RRR_T
);
1552 tcg_gen_sar_i32(cpu_R
[RRR_R
], cpu_R
[RRR_T
], cpu_SR
[SAR
]);
1554 TCGv_i64 v
= tcg_temp_new_i64();
1555 tcg_gen_ext_i32_i64(v
, cpu_R
[RRR_T
]);
1560 #undef gen_shift_reg
1563 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1564 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1566 TCGv_i32 v1
= tcg_temp_new_i32();
1567 TCGv_i32 v2
= tcg_temp_new_i32();
1568 tcg_gen_ext16u_i32(v1
, cpu_R
[RRR_S
]);
1569 tcg_gen_ext16u_i32(v2
, cpu_R
[RRR_T
]);
1570 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1577 HAS_OPTION(XTENSA_OPTION_16_BIT_IMUL
);
1578 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1580 TCGv_i32 v1
= tcg_temp_new_i32();
1581 TCGv_i32 v2
= tcg_temp_new_i32();
1582 tcg_gen_ext16s_i32(v1
, cpu_R
[RRR_S
]);
1583 tcg_gen_ext16s_i32(v2
, cpu_R
[RRR_T
]);
1584 tcg_gen_mul_i32(cpu_R
[RRR_R
], v1
, v2
);
1590 default: /*reserved*/
1598 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1602 HAS_OPTION(XTENSA_OPTION_32_BIT_IDIV
);
1603 int label
= gen_new_label();
1604 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0, label
);
1605 gen_exception_cause(dc
, INTEGER_DIVIDE_BY_ZERO_CAUSE
);
1606 gen_set_label(label
);
1610 #define BOOLEAN_LOGIC(fn, r, s, t) \
1612 HAS_OPTION(XTENSA_OPTION_BOOLEAN); \
1613 TCGv_i32 tmp1 = tcg_temp_new_i32(); \
1614 TCGv_i32 tmp2 = tcg_temp_new_i32(); \
1616 tcg_gen_shri_i32(tmp1, cpu_SR[BR], s); \
1617 tcg_gen_shri_i32(tmp2, cpu_SR[BR], t); \
1618 tcg_gen_##fn##_i32(tmp1, tmp1, tmp2); \
1619 tcg_gen_deposit_i32(cpu_SR[BR], cpu_SR[BR], tmp1, r, 1); \
1620 tcg_temp_free(tmp1); \
1621 tcg_temp_free(tmp2); \
1625 BOOLEAN_LOGIC(and, RRR_R
, RRR_S
, RRR_T
);
1629 BOOLEAN_LOGIC(andc
, RRR_R
, RRR_S
, RRR_T
);
1633 BOOLEAN_LOGIC(or, RRR_R
, RRR_S
, RRR_T
);
1637 BOOLEAN_LOGIC(orc
, RRR_R
, RRR_S
, RRR_T
);
1641 BOOLEAN_LOGIC(xor, RRR_R
, RRR_S
, RRR_T
);
1644 #undef BOOLEAN_LOGIC
1647 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL
);
1648 tcg_gen_mul_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1653 HAS_OPTION(XTENSA_OPTION_32_BIT_IMUL_HIGH
);
1655 TCGv_i64 r
= tcg_temp_new_i64();
1656 TCGv_i64 s
= tcg_temp_new_i64();
1657 TCGv_i64 t
= tcg_temp_new_i64();
1660 tcg_gen_extu_i32_i64(s
, cpu_R
[RRR_S
]);
1661 tcg_gen_extu_i32_i64(t
, cpu_R
[RRR_T
]);
1663 tcg_gen_ext_i32_i64(s
, cpu_R
[RRR_S
]);
1664 tcg_gen_ext_i32_i64(t
, cpu_R
[RRR_T
]);
1666 tcg_gen_mul_i64(r
, s
, t
);
1667 tcg_gen_shri_i64(r
, r
, 32);
1668 tcg_gen_trunc_i64_i32(cpu_R
[RRR_R
], r
);
1670 tcg_temp_free_i64(r
);
1671 tcg_temp_free_i64(s
);
1672 tcg_temp_free_i64(t
);
1677 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1683 int label1
= gen_new_label();
1684 int label2
= gen_new_label();
1686 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1688 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1690 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1691 OP2
== 13 ? 0x80000000 : 0);
1693 gen_set_label(label1
);
1695 tcg_gen_div_i32(cpu_R
[RRR_R
],
1696 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1698 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1699 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1701 gen_set_label(label2
);
1706 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1709 default: /*reserved*/
1718 gen_check_sr(dc
, RSR_SR
, SR_R
);
1720 gen_check_privilege(dc
);
1722 gen_window_check1(dc
, RRR_T
);
1723 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1727 gen_check_sr(dc
, RSR_SR
, SR_W
);
1729 gen_check_privilege(dc
);
1731 gen_window_check1(dc
, RRR_T
);
1732 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1736 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1737 gen_window_check2(dc
, RRR_R
, RRR_S
);
1739 int shift
= 24 - RRR_T
;
1742 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1743 } else if (shift
== 16) {
1744 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1746 TCGv_i32 tmp
= tcg_temp_new_i32();
1747 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1748 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1755 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1756 gen_window_check2(dc
, RRR_R
, RRR_S
);
1758 TCGv_i32 tmp1
= tcg_temp_new_i32();
1759 TCGv_i32 tmp2
= tcg_temp_new_i32();
1760 TCGv_i32 zero
= tcg_const_i32(0);
1762 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1763 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1764 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1766 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1767 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1769 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1770 cpu_R
[RRR_S
], tmp1
);
1771 tcg_temp_free(tmp1
);
1772 tcg_temp_free(tmp2
);
1773 tcg_temp_free(zero
);
1781 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1782 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1784 static const TCGCond cond
[] = {
1790 tcg_gen_movcond_i32(cond
[OP2
- 4], cpu_R
[RRR_R
],
1791 cpu_R
[RRR_S
], cpu_R
[RRR_T
],
1792 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1800 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1802 static const TCGCond cond
[] = {
1808 TCGv_i32 zero
= tcg_const_i32(0);
1810 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1811 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1812 tcg_temp_free(zero
);
1818 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1819 gen_window_check2(dc
, RRR_R
, RRR_S
);
1821 TCGv_i32 zero
= tcg_const_i32(0);
1822 TCGv_i32 tmp
= tcg_temp_new_i32();
1824 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1825 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1826 cpu_R
[RRR_R
], tmp
, zero
,
1827 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1830 tcg_temp_free(zero
);
1835 gen_window_check1(dc
, RRR_R
);
1837 int st
= (RRR_S
<< 4) + RRR_T
;
1838 if (uregnames
[st
].name
) {
1839 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1841 qemu_log("RUR %d not implemented, ", st
);
1848 gen_window_check1(dc
, RRR_T
);
1849 if (uregnames
[RSR_SR
].name
) {
1850 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1852 qemu_log("WUR %d not implemented, ", RSR_SR
);
1862 gen_window_check2(dc
, RRR_R
, RRR_T
);
1864 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1865 int maskimm
= (1 << (OP2
+ 1)) - 1;
1867 TCGv_i32 tmp
= tcg_temp_new_i32();
1868 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1869 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1888 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1889 gen_window_check2(dc
, RRR_S
, RRR_T
);
1890 gen_check_cpenable(dc
, 0);
1892 TCGv_i32 addr
= tcg_temp_new_i32();
1893 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1894 gen_load_store_alignment(dc
, 2, addr
, false);
1896 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1898 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1901 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1903 tcg_temp_free(addr
);
1907 default: /*reserved*/
1914 gen_window_check2(dc
, RRR_S
, RRR_T
);
1917 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1918 gen_check_privilege(dc
);
1920 TCGv_i32 addr
= tcg_temp_new_i32();
1921 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1922 (0xffffffc0 | (RRR_R
<< 2)));
1923 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1924 tcg_temp_free(addr
);
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_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1936 tcg_temp_free(addr
);
1947 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1950 gen_check_cpenable(dc
, 0);
1951 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
1952 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1956 gen_check_cpenable(dc
, 0);
1957 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
1958 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1962 gen_check_cpenable(dc
, 0);
1963 gen_helper_mul_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_madd_s(cpu_FR
[RRR_R
], cpu_env
,
1970 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1974 gen_check_cpenable(dc
, 0);
1975 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
1976 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1979 case 8: /*ROUND.Sf*/
1980 case 9: /*TRUNC.Sf*/
1981 case 10: /*FLOOR.Sf*/
1982 case 11: /*CEIL.Sf*/
1983 case 14: /*UTRUNC.Sf*/
1984 gen_window_check1(dc
, RRR_R
);
1985 gen_check_cpenable(dc
, 0);
1987 static const unsigned rounding_mode_const
[] = {
1988 float_round_nearest_even
,
1989 float_round_to_zero
,
1992 [6] = float_round_to_zero
,
1994 TCGv_i32 rounding_mode
= tcg_const_i32(
1995 rounding_mode_const
[OP2
& 7]);
1996 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
1999 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2000 rounding_mode
, scale
);
2002 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
2003 rounding_mode
, scale
);
2006 tcg_temp_free(rounding_mode
);
2007 tcg_temp_free(scale
);
2011 case 12: /*FLOAT.Sf*/
2012 case 13: /*UFLOAT.Sf*/
2013 gen_window_check1(dc
, RRR_S
);
2014 gen_check_cpenable(dc
, 0);
2016 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2019 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2020 cpu_R
[RRR_S
], scale
);
2022 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2023 cpu_R
[RRR_S
], scale
);
2025 tcg_temp_free(scale
);
2032 gen_check_cpenable(dc
, 0);
2033 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2037 gen_check_cpenable(dc
, 0);
2038 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2042 gen_window_check1(dc
, RRR_R
);
2043 gen_check_cpenable(dc
, 0);
2044 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2048 gen_window_check1(dc
, RRR_S
);
2049 gen_check_cpenable(dc
, 0);
2050 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2054 gen_check_cpenable(dc
, 0);
2055 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2058 default: /*reserved*/
2064 default: /*reserved*/
2071 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2073 #define gen_compare(rel, br, a, b) \
2075 TCGv_i32 bit = tcg_const_i32(1 << br); \
2077 gen_check_cpenable(dc, 0); \
2078 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2079 tcg_temp_free(bit); \
2084 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2088 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2092 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2096 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2100 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2104 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2108 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2113 case 8: /*MOVEQZ.Sf*/
2114 case 9: /*MOVNEZ.Sf*/
2115 case 10: /*MOVLTZ.Sf*/
2116 case 11: /*MOVGEZ.Sf*/
2117 gen_window_check1(dc
, RRR_T
);
2118 gen_check_cpenable(dc
, 0);
2120 static const TCGCond cond
[] = {
2126 TCGv_i32 zero
= tcg_const_i32(0);
2128 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2129 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2130 tcg_temp_free(zero
);
2134 case 12: /*MOVF.Sf*/
2135 case 13: /*MOVT.Sf*/
2136 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2137 gen_check_cpenable(dc
, 0);
2139 TCGv_i32 zero
= tcg_const_i32(0);
2140 TCGv_i32 tmp
= tcg_temp_new_i32();
2142 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2143 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2144 cpu_FR
[RRR_R
], tmp
, zero
,
2145 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2148 tcg_temp_free(zero
);
2152 default: /*reserved*/
2158 default: /*reserved*/
2165 gen_window_check1(dc
, RRR_T
);
2167 TCGv_i32 tmp
= tcg_const_i32(
2168 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2169 0 : ((dc
->pc
+ 3) & ~3)) +
2170 (0xfffc0000 | (RI16_IMM16
<< 2)));
2172 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2173 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2175 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2181 #define gen_load_store(type, shift) do { \
2182 TCGv_i32 addr = tcg_temp_new_i32(); \
2183 gen_window_check2(dc, RRI8_S, RRI8_T); \
2184 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2186 gen_load_store_alignment(dc, shift, addr, false); \
2188 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2189 tcg_temp_free(addr); \
2194 gen_load_store(ld8u
, 0);
2198 gen_load_store(ld16u
, 1);
2202 gen_load_store(ld32u
, 2);
2206 gen_load_store(st8
, 0);
2210 gen_load_store(st16
, 1);
2214 gen_load_store(st32
, 2);
2219 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2250 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2254 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2258 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2262 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2266 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2269 default: /*reserved*/
2277 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2283 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2287 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2291 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2294 default: /*reserved*/
2301 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2305 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2308 default: /*reserved*/
2315 gen_load_store(ld16s
, 1);
2317 #undef gen_load_store
2320 gen_window_check1(dc
, RRI8_T
);
2321 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2322 RRI8_IMM8
| (RRI8_S
<< 8) |
2323 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2326 #define gen_load_store_no_hw_align(type) do { \
2327 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2328 gen_window_check2(dc, RRI8_S, RRI8_T); \
2329 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2330 gen_load_store_alignment(dc, 2, addr, true); \
2331 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2332 tcg_temp_free(addr); \
2336 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2337 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2341 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2342 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2346 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2347 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
<< 8);
2350 case 14: /*S32C1Iy*/
2351 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2352 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2354 int label
= gen_new_label();
2355 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2356 TCGv_i32 addr
= tcg_temp_local_new_i32();
2359 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2360 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2361 gen_load_store_alignment(dc
, 2, addr
, true);
2363 gen_advance_ccount(dc
);
2364 tpc
= tcg_const_i32(dc
->pc
);
2365 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2366 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2367 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2368 cpu_SR
[SCOMPARE1
], label
);
2370 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2372 gen_set_label(label
);
2374 tcg_temp_free(addr
);
2380 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2381 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2383 #undef gen_load_store_no_hw_align
2385 default: /*reserved*/
2397 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2398 gen_window_check1(dc
, RRI8_S
);
2399 gen_check_cpenable(dc
, 0);
2401 TCGv_i32 addr
= tcg_temp_new_i32();
2402 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2403 gen_load_store_alignment(dc
, 2, addr
, false);
2405 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2407 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2410 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2412 tcg_temp_free(addr
);
2416 default: /*reserved*/
2423 HAS_OPTION(XTENSA_OPTION_MAC16
);
2432 bool is_m1_sr
= (OP2
& 0x3) == 2;
2433 bool is_m2_sr
= (OP2
& 0xc) == 0;
2434 uint32_t ld_offset
= 0;
2441 case 0: /*MACI?/MACC?*/
2443 ld_offset
= (OP2
& 1) ? -4 : 4;
2445 if (OP2
>= 8) { /*MACI/MACC*/
2446 if (OP1
== 0) { /*LDINC/LDDEC*/
2451 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2456 case 2: /*MACD?/MACA?*/
2457 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2463 if (op
!= MAC16_NONE
) {
2465 gen_window_check1(dc
, RRR_S
);
2468 gen_window_check1(dc
, RRR_T
);
2473 TCGv_i32 vaddr
= tcg_temp_new_i32();
2474 TCGv_i32 mem32
= tcg_temp_new_i32();
2477 gen_window_check1(dc
, RRR_S
);
2478 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2479 gen_load_store_alignment(dc
, 2, vaddr
, false);
2480 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2482 if (op
!= MAC16_NONE
) {
2483 TCGv_i32 m1
= gen_mac16_m(
2484 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2485 OP1
& 1, op
== MAC16_UMUL
);
2486 TCGv_i32 m2
= gen_mac16_m(
2487 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2488 OP1
& 2, op
== MAC16_UMUL
);
2490 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2491 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2492 if (op
== MAC16_UMUL
) {
2493 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2495 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2498 TCGv_i32 res
= tcg_temp_new_i32();
2499 TCGv_i64 res64
= tcg_temp_new_i64();
2500 TCGv_i64 tmp
= tcg_temp_new_i64();
2502 tcg_gen_mul_i32(res
, m1
, m2
);
2503 tcg_gen_ext_i32_i64(res64
, res
);
2504 tcg_gen_concat_i32_i64(tmp
,
2505 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
]);
2506 if (op
== MAC16_MULA
) {
2507 tcg_gen_add_i64(tmp
, tmp
, res64
);
2509 tcg_gen_sub_i64(tmp
, tmp
, res64
);
2511 tcg_gen_trunc_i64_i32(cpu_SR
[ACCLO
], tmp
);
2512 tcg_gen_shri_i64(tmp
, tmp
, 32);
2513 tcg_gen_trunc_i64_i32(cpu_SR
[ACCHI
], tmp
);
2514 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2517 tcg_temp_free_i64(res64
);
2518 tcg_temp_free_i64(tmp
);
2524 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2525 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2527 tcg_temp_free(vaddr
);
2528 tcg_temp_free(mem32
);
2536 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2537 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2543 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2544 gen_window_check1(dc
, CALL_N
<< 2);
2545 gen_callwi(dc
, CALL_N
,
2546 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2554 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2558 gen_window_check1(dc
, BRI12_S
);
2560 static const TCGCond cond
[] = {
2561 TCG_COND_EQ
, /*BEQZ*/
2562 TCG_COND_NE
, /*BNEZ*/
2563 TCG_COND_LT
, /*BLTZ*/
2564 TCG_COND_GE
, /*BGEZ*/
2567 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2568 4 + BRI12_IMM12_SE
);
2573 gen_window_check1(dc
, BRI8_S
);
2575 static const TCGCond cond
[] = {
2576 TCG_COND_EQ
, /*BEQI*/
2577 TCG_COND_NE
, /*BNEI*/
2578 TCG_COND_LT
, /*BLTI*/
2579 TCG_COND_GE
, /*BGEI*/
2582 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2583 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2590 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2592 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2593 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2594 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2595 gen_advance_ccount(dc
);
2596 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2600 reset_used_window(dc
);
2608 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2610 TCGv_i32 tmp
= tcg_temp_new_i32();
2611 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2613 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2614 tmp
, 0, 4 + RRI8_IMM8_SE
);
2621 case 10: /*LOOPGTZ*/
2622 HAS_OPTION(XTENSA_OPTION_LOOP
);
2623 gen_window_check1(dc
, RRI8_S
);
2625 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2626 TCGv_i32 tmp
= tcg_const_i32(lend
);
2628 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2629 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2630 gen_helper_wsr_lend(cpu_env
, tmp
);
2634 int label
= gen_new_label();
2635 tcg_gen_brcondi_i32(
2636 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2637 cpu_R
[RRI8_S
], 0, label
);
2638 gen_jumpi(dc
, lend
, 1);
2639 gen_set_label(label
);
2642 gen_jumpi(dc
, dc
->next_pc
, 0);
2646 default: /*reserved*/
2655 gen_window_check1(dc
, BRI8_S
);
2656 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2657 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2667 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2669 switch (RRI8_R
& 7) {
2670 case 0: /*BNONE*/ /*BANY*/
2671 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2673 TCGv_i32 tmp
= tcg_temp_new_i32();
2674 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2675 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2680 case 1: /*BEQ*/ /*BNE*/
2681 case 2: /*BLT*/ /*BGE*/
2682 case 3: /*BLTU*/ /*BGEU*/
2683 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2685 static const TCGCond cond
[] = {
2691 [11] = TCG_COND_GEU
,
2693 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2698 case 4: /*BALL*/ /*BNALL*/
2699 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2701 TCGv_i32 tmp
= tcg_temp_new_i32();
2702 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2703 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2709 case 5: /*BBC*/ /*BBS*/
2710 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2712 #ifdef TARGET_WORDS_BIGENDIAN
2713 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2715 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2717 TCGv_i32 tmp
= tcg_temp_new_i32();
2718 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2719 #ifdef TARGET_WORDS_BIGENDIAN
2720 tcg_gen_shr_i32(bit
, bit
, tmp
);
2722 tcg_gen_shl_i32(bit
, bit
, tmp
);
2724 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2725 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2731 case 6: /*BBCI*/ /*BBSI*/
2733 gen_window_check1(dc
, RRI8_S
);
2735 TCGv_i32 tmp
= tcg_temp_new_i32();
2736 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2737 #ifdef TARGET_WORDS_BIGENDIAN
2738 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2740 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2742 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2751 #define gen_narrow_load_store(type) do { \
2752 TCGv_i32 addr = tcg_temp_new_i32(); \
2753 gen_window_check2(dc, RRRN_S, RRRN_T); \
2754 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2755 gen_load_store_alignment(dc, 2, addr, false); \
2756 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2757 tcg_temp_free(addr); \
2761 gen_narrow_load_store(ld32u
);
2765 gen_narrow_load_store(st32
);
2767 #undef gen_narrow_load_store
2770 gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
);
2771 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2774 case 11: /*ADDI.Nn*/
2775 gen_window_check2(dc
, RRRN_R
, RRRN_S
);
2776 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], RRRN_T
? RRRN_T
: -1);
2780 gen_window_check1(dc
, RRRN_S
);
2781 if (RRRN_T
< 8) { /*MOVI.Nn*/
2782 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2783 RRRN_R
| (RRRN_T
<< 4) |
2784 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2785 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2786 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2788 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2789 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2796 gen_window_check2(dc
, RRRN_S
, RRRN_T
);
2797 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2803 gen_jump(dc
, cpu_R
[0]);
2807 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2809 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2810 gen_advance_ccount(dc
);
2811 gen_helper_retw(tmp
, cpu_env
, tmp
);
2817 case 2: /*BREAK.Nn*/
2818 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2820 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2828 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2831 default: /*reserved*/
2837 default: /*reserved*/
2843 default: /*reserved*/
2848 if (dc
->is_jmp
== DISAS_NEXT
) {
2849 gen_check_loop_end(dc
, 0);
2851 dc
->pc
= dc
->next_pc
;
2856 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2857 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2861 static void check_breakpoint(CPUXtensaState
*env
, DisasContext
*dc
)
2865 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2866 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2867 if (bp
->pc
== dc
->pc
) {
2868 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2869 gen_exception(dc
, EXCP_DEBUG
);
2870 dc
->is_jmp
= DISAS_UPDATE
;
2876 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
2880 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
2881 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
2882 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
2883 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
2889 static void gen_intermediate_code_internal(
2890 CPUXtensaState
*env
, TranslationBlock
*tb
, int search_pc
)
2895 uint16_t *gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
2896 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2897 uint32_t pc_start
= tb
->pc
;
2898 uint32_t next_page_start
=
2899 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2901 if (max_insns
== 0) {
2902 max_insns
= CF_COUNT_MASK
;
2905 dc
.config
= env
->config
;
2906 dc
.singlestep_enabled
= env
->singlestep_enabled
;
2909 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
2910 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
2911 dc
.lbeg
= env
->sregs
[LBEG
];
2912 dc
.lend
= env
->sregs
[LEND
];
2913 dc
.is_jmp
= DISAS_NEXT
;
2914 dc
.ccount_delta
= 0;
2915 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
2916 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
2917 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
2918 XTENSA_TBFLAG_CPENABLE_SHIFT
;
2921 init_sar_tracker(&dc
);
2922 reset_used_window(&dc
);
2924 dc
.next_icount
= tcg_temp_local_new_i32();
2929 if (env
->singlestep_enabled
&& env
->exception_taken
) {
2930 env
->exception_taken
= 0;
2931 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2932 gen_exception(&dc
, EXCP_DEBUG
);
2936 check_breakpoint(env
, &dc
);
2939 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
2943 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2946 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
2947 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
2948 tcg_ctx
.gen_opc_icount
[lj
] = insn_count
;
2951 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
2952 tcg_gen_debug_insn_start(dc
.pc
);
2957 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
2962 int label
= gen_new_label();
2964 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
2965 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
2966 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
2968 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
2970 gen_set_label(label
);
2974 gen_ibreak_check(env
, &dc
);
2977 disas_xtensa_insn(env
, &dc
);
2980 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
2982 if (env
->singlestep_enabled
) {
2983 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2984 gen_exception(&dc
, EXCP_DEBUG
);
2987 } while (dc
.is_jmp
== DISAS_NEXT
&&
2988 insn_count
< max_insns
&&
2989 dc
.pc
< next_page_start
&&
2990 tcg_ctx
.gen_opc_ptr
< gen_opc_end
);
2993 reset_sar_tracker(&dc
);
2995 tcg_temp_free(dc
.next_icount
);
2998 if (tb
->cflags
& CF_LAST_IO
) {
3002 if (dc
.is_jmp
== DISAS_NEXT
) {
3003 gen_jumpi(&dc
, dc
.pc
, 0);
3005 gen_icount_end(tb
, insn_count
);
3006 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
3009 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
3010 memset(tcg_ctx
.gen_opc_instr_start
+ lj
+ 1, 0,
3011 (j
- lj
) * sizeof(tcg_ctx
.gen_opc_instr_start
[0]));
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
];