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 lo
= tcg_temp_new();
1658 tcg_gen_mulu2_i32(lo
, cpu_R
[RRR_R
],
1659 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1661 tcg_gen_muls2_i32(lo
, cpu_R
[RRR_R
],
1662 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1669 tcg_gen_divu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1675 int label1
= gen_new_label();
1676 int label2
= gen_new_label();
1678 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_S
], 0x80000000,
1680 tcg_gen_brcondi_i32(TCG_COND_NE
, cpu_R
[RRR_T
], 0xffffffff,
1682 tcg_gen_movi_i32(cpu_R
[RRR_R
],
1683 OP2
== 13 ? 0x80000000 : 0);
1685 gen_set_label(label1
);
1687 tcg_gen_div_i32(cpu_R
[RRR_R
],
1688 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1690 tcg_gen_rem_i32(cpu_R
[RRR_R
],
1691 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1693 gen_set_label(label2
);
1698 tcg_gen_remu_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1701 default: /*reserved*/
1710 gen_check_sr(dc
, RSR_SR
, SR_R
);
1712 gen_check_privilege(dc
);
1714 gen_window_check1(dc
, RRR_T
);
1715 gen_rsr(dc
, cpu_R
[RRR_T
], RSR_SR
);
1719 gen_check_sr(dc
, RSR_SR
, SR_W
);
1721 gen_check_privilege(dc
);
1723 gen_window_check1(dc
, RRR_T
);
1724 gen_wsr(dc
, RSR_SR
, cpu_R
[RRR_T
]);
1728 HAS_OPTION(XTENSA_OPTION_MISC_OP_SEXT
);
1729 gen_window_check2(dc
, RRR_R
, RRR_S
);
1731 int shift
= 24 - RRR_T
;
1734 tcg_gen_ext8s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1735 } else if (shift
== 16) {
1736 tcg_gen_ext16s_i32(cpu_R
[RRR_R
], cpu_R
[RRR_S
]);
1738 TCGv_i32 tmp
= tcg_temp_new_i32();
1739 tcg_gen_shli_i32(tmp
, cpu_R
[RRR_S
], shift
);
1740 tcg_gen_sari_i32(cpu_R
[RRR_R
], tmp
, shift
);
1747 HAS_OPTION(XTENSA_OPTION_MISC_OP_CLAMPS
);
1748 gen_window_check2(dc
, RRR_R
, RRR_S
);
1750 TCGv_i32 tmp1
= tcg_temp_new_i32();
1751 TCGv_i32 tmp2
= tcg_temp_new_i32();
1752 TCGv_i32 zero
= tcg_const_i32(0);
1754 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 24 - RRR_T
);
1755 tcg_gen_xor_i32(tmp2
, tmp1
, cpu_R
[RRR_S
]);
1756 tcg_gen_andi_i32(tmp2
, tmp2
, 0xffffffff << (RRR_T
+ 7));
1758 tcg_gen_sari_i32(tmp1
, cpu_R
[RRR_S
], 31);
1759 tcg_gen_xori_i32(tmp1
, tmp1
, 0xffffffff >> (25 - RRR_T
));
1761 tcg_gen_movcond_i32(TCG_COND_EQ
, cpu_R
[RRR_R
], tmp2
, zero
,
1762 cpu_R
[RRR_S
], tmp1
);
1763 tcg_temp_free(tmp1
);
1764 tcg_temp_free(tmp2
);
1765 tcg_temp_free(zero
);
1773 HAS_OPTION(XTENSA_OPTION_MISC_OP_MINMAX
);
1774 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1776 static const TCGCond cond
[] = {
1782 tcg_gen_movcond_i32(cond
[OP2
- 4], cpu_R
[RRR_R
],
1783 cpu_R
[RRR_S
], cpu_R
[RRR_T
],
1784 cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1792 gen_window_check3(dc
, RRR_R
, RRR_S
, RRR_T
);
1794 static const TCGCond cond
[] = {
1800 TCGv_i32 zero
= tcg_const_i32(0);
1802 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_R
[RRR_R
],
1803 cpu_R
[RRR_T
], zero
, cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1804 tcg_temp_free(zero
);
1810 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
1811 gen_window_check2(dc
, RRR_R
, RRR_S
);
1813 TCGv_i32 zero
= tcg_const_i32(0);
1814 TCGv_i32 tmp
= tcg_temp_new_i32();
1816 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
1817 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
1818 cpu_R
[RRR_R
], tmp
, zero
,
1819 cpu_R
[RRR_S
], cpu_R
[RRR_R
]);
1822 tcg_temp_free(zero
);
1827 gen_window_check1(dc
, RRR_R
);
1829 int st
= (RRR_S
<< 4) + RRR_T
;
1830 if (uregnames
[st
].name
) {
1831 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_UR
[st
]);
1833 qemu_log("RUR %d not implemented, ", st
);
1840 gen_window_check1(dc
, RRR_T
);
1841 if (uregnames
[RSR_SR
].name
) {
1842 gen_wur(RSR_SR
, cpu_R
[RRR_T
]);
1844 qemu_log("WUR %d not implemented, ", RSR_SR
);
1854 gen_window_check2(dc
, RRR_R
, RRR_T
);
1856 int shiftimm
= RRR_S
| ((OP1
& 1) << 4);
1857 int maskimm
= (1 << (OP2
+ 1)) - 1;
1859 TCGv_i32 tmp
= tcg_temp_new_i32();
1860 tcg_gen_shri_i32(tmp
, cpu_R
[RRR_T
], shiftimm
);
1861 tcg_gen_andi_i32(cpu_R
[RRR_R
], tmp
, maskimm
);
1880 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1881 gen_window_check2(dc
, RRR_S
, RRR_T
);
1882 gen_check_cpenable(dc
, 0);
1884 TCGv_i32 addr
= tcg_temp_new_i32();
1885 tcg_gen_add_i32(addr
, cpu_R
[RRR_S
], cpu_R
[RRR_T
]);
1886 gen_load_store_alignment(dc
, 2, addr
, false);
1888 tcg_gen_qemu_st32(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1890 tcg_gen_qemu_ld32u(cpu_FR
[RRR_R
], addr
, dc
->cring
);
1893 tcg_gen_mov_i32(cpu_R
[RRR_S
], addr
);
1895 tcg_temp_free(addr
);
1899 default: /*reserved*/
1906 gen_window_check2(dc
, RRR_S
, RRR_T
);
1909 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1910 gen_check_privilege(dc
);
1912 TCGv_i32 addr
= tcg_temp_new_i32();
1913 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1914 (0xffffffc0 | (RRR_R
<< 2)));
1915 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], addr
, dc
->ring
);
1916 tcg_temp_free(addr
);
1921 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
1922 gen_check_privilege(dc
);
1924 TCGv_i32 addr
= tcg_temp_new_i32();
1925 tcg_gen_addi_i32(addr
, cpu_R
[RRR_S
],
1926 (0xffffffc0 | (RRR_R
<< 2)));
1927 tcg_gen_qemu_st32(cpu_R
[RRR_T
], addr
, dc
->ring
);
1928 tcg_temp_free(addr
);
1939 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
1942 gen_check_cpenable(dc
, 0);
1943 gen_helper_add_s(cpu_FR
[RRR_R
], cpu_env
,
1944 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1948 gen_check_cpenable(dc
, 0);
1949 gen_helper_sub_s(cpu_FR
[RRR_R
], cpu_env
,
1950 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1954 gen_check_cpenable(dc
, 0);
1955 gen_helper_mul_s(cpu_FR
[RRR_R
], cpu_env
,
1956 cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1960 gen_check_cpenable(dc
, 0);
1961 gen_helper_madd_s(cpu_FR
[RRR_R
], cpu_env
,
1962 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1966 gen_check_cpenable(dc
, 0);
1967 gen_helper_msub_s(cpu_FR
[RRR_R
], cpu_env
,
1968 cpu_FR
[RRR_R
], cpu_FR
[RRR_S
], cpu_FR
[RRR_T
]);
1971 case 8: /*ROUND.Sf*/
1972 case 9: /*TRUNC.Sf*/
1973 case 10: /*FLOOR.Sf*/
1974 case 11: /*CEIL.Sf*/
1975 case 14: /*UTRUNC.Sf*/
1976 gen_window_check1(dc
, RRR_R
);
1977 gen_check_cpenable(dc
, 0);
1979 static const unsigned rounding_mode_const
[] = {
1980 float_round_nearest_even
,
1981 float_round_to_zero
,
1984 [6] = float_round_to_zero
,
1986 TCGv_i32 rounding_mode
= tcg_const_i32(
1987 rounding_mode_const
[OP2
& 7]);
1988 TCGv_i32 scale
= tcg_const_i32(RRR_T
);
1991 gen_helper_ftoui(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
1992 rounding_mode
, scale
);
1994 gen_helper_ftoi(cpu_R
[RRR_R
], cpu_FR
[RRR_S
],
1995 rounding_mode
, scale
);
1998 tcg_temp_free(rounding_mode
);
1999 tcg_temp_free(scale
);
2003 case 12: /*FLOAT.Sf*/
2004 case 13: /*UFLOAT.Sf*/
2005 gen_window_check1(dc
, RRR_S
);
2006 gen_check_cpenable(dc
, 0);
2008 TCGv_i32 scale
= tcg_const_i32(-RRR_T
);
2011 gen_helper_uitof(cpu_FR
[RRR_R
], cpu_env
,
2012 cpu_R
[RRR_S
], scale
);
2014 gen_helper_itof(cpu_FR
[RRR_R
], cpu_env
,
2015 cpu_R
[RRR_S
], scale
);
2017 tcg_temp_free(scale
);
2024 gen_check_cpenable(dc
, 0);
2025 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2029 gen_check_cpenable(dc
, 0);
2030 gen_helper_abs_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2034 gen_window_check1(dc
, RRR_R
);
2035 gen_check_cpenable(dc
, 0);
2036 tcg_gen_mov_i32(cpu_R
[RRR_R
], cpu_FR
[RRR_S
]);
2040 gen_window_check1(dc
, RRR_S
);
2041 gen_check_cpenable(dc
, 0);
2042 tcg_gen_mov_i32(cpu_FR
[RRR_R
], cpu_R
[RRR_S
]);
2046 gen_check_cpenable(dc
, 0);
2047 gen_helper_neg_s(cpu_FR
[RRR_R
], cpu_FR
[RRR_S
]);
2050 default: /*reserved*/
2056 default: /*reserved*/
2063 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2065 #define gen_compare(rel, br, a, b) \
2067 TCGv_i32 bit = tcg_const_i32(1 << br); \
2069 gen_check_cpenable(dc, 0); \
2070 gen_helper_##rel(cpu_env, bit, cpu_FR[a], cpu_FR[b]); \
2071 tcg_temp_free(bit); \
2076 gen_compare(un_s
, RRR_R
, RRR_S
, RRR_T
);
2080 gen_compare(oeq_s
, RRR_R
, RRR_S
, RRR_T
);
2084 gen_compare(ueq_s
, RRR_R
, RRR_S
, RRR_T
);
2088 gen_compare(olt_s
, RRR_R
, RRR_S
, RRR_T
);
2092 gen_compare(ult_s
, RRR_R
, RRR_S
, RRR_T
);
2096 gen_compare(ole_s
, RRR_R
, RRR_S
, RRR_T
);
2100 gen_compare(ule_s
, RRR_R
, RRR_S
, RRR_T
);
2105 case 8: /*MOVEQZ.Sf*/
2106 case 9: /*MOVNEZ.Sf*/
2107 case 10: /*MOVLTZ.Sf*/
2108 case 11: /*MOVGEZ.Sf*/
2109 gen_window_check1(dc
, RRR_T
);
2110 gen_check_cpenable(dc
, 0);
2112 static const TCGCond cond
[] = {
2118 TCGv_i32 zero
= tcg_const_i32(0);
2120 tcg_gen_movcond_i32(cond
[OP2
- 8], cpu_FR
[RRR_R
],
2121 cpu_R
[RRR_T
], zero
, cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2122 tcg_temp_free(zero
);
2126 case 12: /*MOVF.Sf*/
2127 case 13: /*MOVT.Sf*/
2128 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2129 gen_check_cpenable(dc
, 0);
2131 TCGv_i32 zero
= tcg_const_i32(0);
2132 TCGv_i32 tmp
= tcg_temp_new_i32();
2134 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRR_T
);
2135 tcg_gen_movcond_i32(OP2
& 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2136 cpu_FR
[RRR_R
], tmp
, zero
,
2137 cpu_FR
[RRR_S
], cpu_FR
[RRR_R
]);
2140 tcg_temp_free(zero
);
2144 default: /*reserved*/
2150 default: /*reserved*/
2157 gen_window_check1(dc
, RRR_T
);
2159 TCGv_i32 tmp
= tcg_const_i32(
2160 ((dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) ?
2161 0 : ((dc
->pc
+ 3) & ~3)) +
2162 (0xfffc0000 | (RI16_IMM16
<< 2)));
2164 if (dc
->tb
->flags
& XTENSA_TBFLAG_LITBASE
) {
2165 tcg_gen_add_i32(tmp
, tmp
, dc
->litbase
);
2167 tcg_gen_qemu_ld32u(cpu_R
[RRR_T
], tmp
, dc
->cring
);
2173 #define gen_load_store(type, shift) do { \
2174 TCGv_i32 addr = tcg_temp_new_i32(); \
2175 gen_window_check2(dc, RRI8_S, RRI8_T); \
2176 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \
2178 gen_load_store_alignment(dc, shift, addr, false); \
2180 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2181 tcg_temp_free(addr); \
2186 gen_load_store(ld8u
, 0);
2190 gen_load_store(ld16u
, 1);
2194 gen_load_store(ld32u
, 2);
2198 gen_load_store(st8
, 0);
2202 gen_load_store(st16
, 1);
2206 gen_load_store(st32
, 2);
2211 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2242 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2246 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2250 HAS_OPTION(XTENSA_OPTION_DCACHE_INDEX_LOCK
);
2254 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2258 HAS_OPTION(XTENSA_OPTION_DCACHE
);
2261 default: /*reserved*/
2269 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2275 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2279 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2283 HAS_OPTION(XTENSA_OPTION_ICACHE_INDEX_LOCK
);
2286 default: /*reserved*/
2293 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2297 HAS_OPTION(XTENSA_OPTION_ICACHE
);
2300 default: /*reserved*/
2307 gen_load_store(ld16s
, 1);
2309 #undef gen_load_store
2312 gen_window_check1(dc
, RRI8_T
);
2313 tcg_gen_movi_i32(cpu_R
[RRI8_T
],
2314 RRI8_IMM8
| (RRI8_S
<< 8) |
2315 ((RRI8_S
& 0x8) ? 0xfffff000 : 0));
2318 #define gen_load_store_no_hw_align(type) do { \
2319 TCGv_i32 addr = tcg_temp_local_new_i32(); \
2320 gen_window_check2(dc, RRI8_S, RRI8_T); \
2321 tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << 2); \
2322 gen_load_store_alignment(dc, 2, addr, true); \
2323 tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
2324 tcg_temp_free(addr); \
2328 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2329 gen_load_store_no_hw_align(ld32u
); /*TODO acquire?*/
2333 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2334 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
);
2338 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2339 tcg_gen_addi_i32(cpu_R
[RRI8_T
], cpu_R
[RRI8_S
], RRI8_IMM8_SE
<< 8);
2342 case 14: /*S32C1Iy*/
2343 HAS_OPTION(XTENSA_OPTION_CONDITIONAL_STORE
);
2344 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2346 int label
= gen_new_label();
2347 TCGv_i32 tmp
= tcg_temp_local_new_i32();
2348 TCGv_i32 addr
= tcg_temp_local_new_i32();
2351 tcg_gen_mov_i32(tmp
, cpu_R
[RRI8_T
]);
2352 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2353 gen_load_store_alignment(dc
, 2, addr
, true);
2355 gen_advance_ccount(dc
);
2356 tpc
= tcg_const_i32(dc
->pc
);
2357 gen_helper_check_atomctl(cpu_env
, tpc
, addr
);
2358 tcg_gen_qemu_ld32u(cpu_R
[RRI8_T
], addr
, dc
->cring
);
2359 tcg_gen_brcond_i32(TCG_COND_NE
, cpu_R
[RRI8_T
],
2360 cpu_SR
[SCOMPARE1
], label
);
2362 tcg_gen_qemu_st32(tmp
, addr
, dc
->cring
);
2364 gen_set_label(label
);
2366 tcg_temp_free(addr
);
2372 HAS_OPTION(XTENSA_OPTION_MP_SYNCHRO
);
2373 gen_load_store_no_hw_align(st32
); /*TODO release?*/
2375 #undef gen_load_store_no_hw_align
2377 default: /*reserved*/
2389 HAS_OPTION(XTENSA_OPTION_FP_COPROCESSOR
);
2390 gen_window_check1(dc
, RRI8_S
);
2391 gen_check_cpenable(dc
, 0);
2393 TCGv_i32 addr
= tcg_temp_new_i32();
2394 tcg_gen_addi_i32(addr
, cpu_R
[RRI8_S
], RRI8_IMM8
<< 2);
2395 gen_load_store_alignment(dc
, 2, addr
, false);
2397 tcg_gen_qemu_st32(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2399 tcg_gen_qemu_ld32u(cpu_FR
[RRI8_T
], addr
, dc
->cring
);
2402 tcg_gen_mov_i32(cpu_R
[RRI8_S
], addr
);
2404 tcg_temp_free(addr
);
2408 default: /*reserved*/
2415 HAS_OPTION(XTENSA_OPTION_MAC16
);
2424 bool is_m1_sr
= (OP2
& 0x3) == 2;
2425 bool is_m2_sr
= (OP2
& 0xc) == 0;
2426 uint32_t ld_offset
= 0;
2433 case 0: /*MACI?/MACC?*/
2435 ld_offset
= (OP2
& 1) ? -4 : 4;
2437 if (OP2
>= 8) { /*MACI/MACC*/
2438 if (OP1
== 0) { /*LDINC/LDDEC*/
2443 } else if (op
!= MAC16_MULA
) { /*MULA.*.*.LDINC/LDDEC*/
2448 case 2: /*MACD?/MACA?*/
2449 if (op
== MAC16_UMUL
&& OP2
!= 7) { /*UMUL only in MACAA*/
2455 if (op
!= MAC16_NONE
) {
2457 gen_window_check1(dc
, RRR_S
);
2460 gen_window_check1(dc
, RRR_T
);
2465 TCGv_i32 vaddr
= tcg_temp_new_i32();
2466 TCGv_i32 mem32
= tcg_temp_new_i32();
2469 gen_window_check1(dc
, RRR_S
);
2470 tcg_gen_addi_i32(vaddr
, cpu_R
[RRR_S
], ld_offset
);
2471 gen_load_store_alignment(dc
, 2, vaddr
, false);
2472 tcg_gen_qemu_ld32u(mem32
, vaddr
, dc
->cring
);
2474 if (op
!= MAC16_NONE
) {
2475 TCGv_i32 m1
= gen_mac16_m(
2476 is_m1_sr
? cpu_SR
[MR
+ RRR_X
] : cpu_R
[RRR_S
],
2477 OP1
& 1, op
== MAC16_UMUL
);
2478 TCGv_i32 m2
= gen_mac16_m(
2479 is_m2_sr
? cpu_SR
[MR
+ 2 + RRR_Y
] : cpu_R
[RRR_T
],
2480 OP1
& 2, op
== MAC16_UMUL
);
2482 if (op
== MAC16_MUL
|| op
== MAC16_UMUL
) {
2483 tcg_gen_mul_i32(cpu_SR
[ACCLO
], m1
, m2
);
2484 if (op
== MAC16_UMUL
) {
2485 tcg_gen_movi_i32(cpu_SR
[ACCHI
], 0);
2487 tcg_gen_sari_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCLO
], 31);
2490 TCGv_i32 lo
= tcg_temp_new_i32();
2491 TCGv_i32 hi
= tcg_temp_new_i32();
2493 tcg_gen_mul_i32(lo
, m1
, m2
);
2494 tcg_gen_sari_i32(hi
, lo
, 31);
2495 if (op
== MAC16_MULA
) {
2496 tcg_gen_add2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2497 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2500 tcg_gen_sub2_i32(cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2501 cpu_SR
[ACCLO
], cpu_SR
[ACCHI
],
2504 tcg_gen_ext8s_i32(cpu_SR
[ACCHI
], cpu_SR
[ACCHI
]);
2506 tcg_temp_free_i32(lo
);
2507 tcg_temp_free_i32(hi
);
2513 tcg_gen_mov_i32(cpu_R
[RRR_S
], vaddr
);
2514 tcg_gen_mov_i32(cpu_SR
[MR
+ RRR_W
], mem32
);
2516 tcg_temp_free(vaddr
);
2517 tcg_temp_free(mem32
);
2525 tcg_gen_movi_i32(cpu_R
[0], dc
->next_pc
);
2526 gen_jumpi(dc
, (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2532 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2533 gen_window_check1(dc
, CALL_N
<< 2);
2534 gen_callwi(dc
, CALL_N
,
2535 (dc
->pc
& ~3) + (CALL_OFFSET_SE
<< 2) + 4, 0);
2543 gen_jumpi(dc
, dc
->pc
+ 4 + CALL_OFFSET_SE
, 0);
2547 gen_window_check1(dc
, BRI12_S
);
2549 static const TCGCond cond
[] = {
2550 TCG_COND_EQ
, /*BEQZ*/
2551 TCG_COND_NE
, /*BNEZ*/
2552 TCG_COND_LT
, /*BLTZ*/
2553 TCG_COND_GE
, /*BGEZ*/
2556 gen_brcondi(dc
, cond
[BRI12_M
& 3], cpu_R
[BRI12_S
], 0,
2557 4 + BRI12_IMM12_SE
);
2562 gen_window_check1(dc
, BRI8_S
);
2564 static const TCGCond cond
[] = {
2565 TCG_COND_EQ
, /*BEQI*/
2566 TCG_COND_NE
, /*BNEI*/
2567 TCG_COND_LT
, /*BLTI*/
2568 TCG_COND_GE
, /*BGEI*/
2571 gen_brcondi(dc
, cond
[BRI8_M
& 3],
2572 cpu_R
[BRI8_S
], B4CONST
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2579 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2581 TCGv_i32 pc
= tcg_const_i32(dc
->pc
);
2582 TCGv_i32 s
= tcg_const_i32(BRI12_S
);
2583 TCGv_i32 imm
= tcg_const_i32(BRI12_IMM12
);
2584 gen_advance_ccount(dc
);
2585 gen_helper_entry(cpu_env
, pc
, s
, imm
);
2589 reset_used_window(dc
);
2597 HAS_OPTION(XTENSA_OPTION_BOOLEAN
);
2599 TCGv_i32 tmp
= tcg_temp_new_i32();
2600 tcg_gen_andi_i32(tmp
, cpu_SR
[BR
], 1 << RRI8_S
);
2602 BRI8_R
== 1 ? TCG_COND_NE
: TCG_COND_EQ
,
2603 tmp
, 0, 4 + RRI8_IMM8_SE
);
2610 case 10: /*LOOPGTZ*/
2611 HAS_OPTION(XTENSA_OPTION_LOOP
);
2612 gen_window_check1(dc
, RRI8_S
);
2614 uint32_t lend
= dc
->pc
+ RRI8_IMM8
+ 4;
2615 TCGv_i32 tmp
= tcg_const_i32(lend
);
2617 tcg_gen_subi_i32(cpu_SR
[LCOUNT
], cpu_R
[RRI8_S
], 1);
2618 tcg_gen_movi_i32(cpu_SR
[LBEG
], dc
->next_pc
);
2619 gen_helper_wsr_lend(cpu_env
, tmp
);
2623 int label
= gen_new_label();
2624 tcg_gen_brcondi_i32(
2625 BRI8_R
== 9 ? TCG_COND_NE
: TCG_COND_GT
,
2626 cpu_R
[RRI8_S
], 0, label
);
2627 gen_jumpi(dc
, lend
, 1);
2628 gen_set_label(label
);
2631 gen_jumpi(dc
, dc
->next_pc
, 0);
2635 default: /*reserved*/
2644 gen_window_check1(dc
, BRI8_S
);
2645 gen_brcondi(dc
, BRI8_M
== 2 ? TCG_COND_LTU
: TCG_COND_GEU
,
2646 cpu_R
[BRI8_S
], B4CONSTU
[BRI8_R
], 4 + BRI8_IMM8_SE
);
2656 TCGCond eq_ne
= (RRI8_R
& 8) ? TCG_COND_NE
: TCG_COND_EQ
;
2658 switch (RRI8_R
& 7) {
2659 case 0: /*BNONE*/ /*BANY*/
2660 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2662 TCGv_i32 tmp
= tcg_temp_new_i32();
2663 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2664 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2669 case 1: /*BEQ*/ /*BNE*/
2670 case 2: /*BLT*/ /*BGE*/
2671 case 3: /*BLTU*/ /*BGEU*/
2672 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2674 static const TCGCond cond
[] = {
2680 [11] = TCG_COND_GEU
,
2682 gen_brcond(dc
, cond
[RRI8_R
], cpu_R
[RRI8_S
], cpu_R
[RRI8_T
],
2687 case 4: /*BALL*/ /*BNALL*/
2688 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2690 TCGv_i32 tmp
= tcg_temp_new_i32();
2691 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], cpu_R
[RRI8_T
]);
2692 gen_brcond(dc
, eq_ne
, tmp
, cpu_R
[RRI8_T
],
2698 case 5: /*BBC*/ /*BBS*/
2699 gen_window_check2(dc
, RRI8_S
, RRI8_T
);
2701 #ifdef TARGET_WORDS_BIGENDIAN
2702 TCGv_i32 bit
= tcg_const_i32(0x80000000);
2704 TCGv_i32 bit
= tcg_const_i32(0x00000001);
2706 TCGv_i32 tmp
= tcg_temp_new_i32();
2707 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_T
], 0x1f);
2708 #ifdef TARGET_WORDS_BIGENDIAN
2709 tcg_gen_shr_i32(bit
, bit
, tmp
);
2711 tcg_gen_shl_i32(bit
, bit
, tmp
);
2713 tcg_gen_and_i32(tmp
, cpu_R
[RRI8_S
], bit
);
2714 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2720 case 6: /*BBCI*/ /*BBSI*/
2722 gen_window_check1(dc
, RRI8_S
);
2724 TCGv_i32 tmp
= tcg_temp_new_i32();
2725 tcg_gen_andi_i32(tmp
, cpu_R
[RRI8_S
],
2726 #ifdef TARGET_WORDS_BIGENDIAN
2727 0x80000000 >> (((RRI8_R
& 1) << 4) | RRI8_T
));
2729 0x00000001 << (((RRI8_R
& 1) << 4) | RRI8_T
));
2731 gen_brcondi(dc
, eq_ne
, tmp
, 0, 4 + RRI8_IMM8_SE
);
2740 #define gen_narrow_load_store(type) do { \
2741 TCGv_i32 addr = tcg_temp_new_i32(); \
2742 gen_window_check2(dc, RRRN_S, RRRN_T); \
2743 tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \
2744 gen_load_store_alignment(dc, 2, addr, false); \
2745 tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
2746 tcg_temp_free(addr); \
2750 gen_narrow_load_store(ld32u
);
2754 gen_narrow_load_store(st32
);
2756 #undef gen_narrow_load_store
2759 gen_window_check3(dc
, RRRN_R
, RRRN_S
, RRRN_T
);
2760 tcg_gen_add_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], cpu_R
[RRRN_T
]);
2763 case 11: /*ADDI.Nn*/
2764 gen_window_check2(dc
, RRRN_R
, RRRN_S
);
2765 tcg_gen_addi_i32(cpu_R
[RRRN_R
], cpu_R
[RRRN_S
], RRRN_T
? RRRN_T
: -1);
2769 gen_window_check1(dc
, RRRN_S
);
2770 if (RRRN_T
< 8) { /*MOVI.Nn*/
2771 tcg_gen_movi_i32(cpu_R
[RRRN_S
],
2772 RRRN_R
| (RRRN_T
<< 4) |
2773 ((RRRN_T
& 6) == 6 ? 0xffffff80 : 0));
2774 } else { /*BEQZ.Nn*/ /*BNEZ.Nn*/
2775 TCGCond eq_ne
= (RRRN_T
& 4) ? TCG_COND_NE
: TCG_COND_EQ
;
2777 gen_brcondi(dc
, eq_ne
, cpu_R
[RRRN_S
], 0,
2778 4 + (RRRN_R
| ((RRRN_T
& 3) << 4)));
2785 gen_window_check2(dc
, RRRN_S
, RRRN_T
);
2786 tcg_gen_mov_i32(cpu_R
[RRRN_T
], cpu_R
[RRRN_S
]);
2792 gen_jump(dc
, cpu_R
[0]);
2796 HAS_OPTION(XTENSA_OPTION_WINDOWED_REGISTER
);
2798 TCGv_i32 tmp
= tcg_const_i32(dc
->pc
);
2799 gen_advance_ccount(dc
);
2800 gen_helper_retw(tmp
, cpu_env
, tmp
);
2806 case 2: /*BREAK.Nn*/
2807 HAS_OPTION(XTENSA_OPTION_DEBUG
);
2809 gen_debug_exception(dc
, DEBUGCAUSE_BN
);
2817 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2820 default: /*reserved*/
2826 default: /*reserved*/
2832 default: /*reserved*/
2837 if (dc
->is_jmp
== DISAS_NEXT
) {
2838 gen_check_loop_end(dc
, 0);
2840 dc
->pc
= dc
->next_pc
;
2845 qemu_log("INVALID(pc = %08x)\n", dc
->pc
);
2846 gen_exception_cause(dc
, ILLEGAL_INSTRUCTION_CAUSE
);
2850 static void check_breakpoint(CPUXtensaState
*env
, DisasContext
*dc
)
2854 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
2855 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
2856 if (bp
->pc
== dc
->pc
) {
2857 tcg_gen_movi_i32(cpu_pc
, dc
->pc
);
2858 gen_exception(dc
, EXCP_DEBUG
);
2859 dc
->is_jmp
= DISAS_UPDATE
;
2865 static void gen_ibreak_check(CPUXtensaState
*env
, DisasContext
*dc
)
2869 for (i
= 0; i
< dc
->config
->nibreak
; ++i
) {
2870 if ((env
->sregs
[IBREAKENABLE
] & (1 << i
)) &&
2871 env
->sregs
[IBREAKA
+ i
] == dc
->pc
) {
2872 gen_debug_exception(dc
, DEBUGCAUSE_IB
);
2878 static void gen_intermediate_code_internal(
2879 CPUXtensaState
*env
, TranslationBlock
*tb
, int search_pc
)
2884 uint16_t *gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
2885 int max_insns
= tb
->cflags
& CF_COUNT_MASK
;
2886 uint32_t pc_start
= tb
->pc
;
2887 uint32_t next_page_start
=
2888 (pc_start
& TARGET_PAGE_MASK
) + TARGET_PAGE_SIZE
;
2890 if (max_insns
== 0) {
2891 max_insns
= CF_COUNT_MASK
;
2894 dc
.config
= env
->config
;
2895 dc
.singlestep_enabled
= env
->singlestep_enabled
;
2898 dc
.ring
= tb
->flags
& XTENSA_TBFLAG_RING_MASK
;
2899 dc
.cring
= (tb
->flags
& XTENSA_TBFLAG_EXCM
) ? 0 : dc
.ring
;
2900 dc
.lbeg
= env
->sregs
[LBEG
];
2901 dc
.lend
= env
->sregs
[LEND
];
2902 dc
.is_jmp
= DISAS_NEXT
;
2903 dc
.ccount_delta
= 0;
2904 dc
.debug
= tb
->flags
& XTENSA_TBFLAG_DEBUG
;
2905 dc
.icount
= tb
->flags
& XTENSA_TBFLAG_ICOUNT
;
2906 dc
.cpenable
= (tb
->flags
& XTENSA_TBFLAG_CPENABLE_MASK
) >>
2907 XTENSA_TBFLAG_CPENABLE_SHIFT
;
2910 init_sar_tracker(&dc
);
2911 reset_used_window(&dc
);
2913 dc
.next_icount
= tcg_temp_local_new_i32();
2918 if (env
->singlestep_enabled
&& env
->exception_taken
) {
2919 env
->exception_taken
= 0;
2920 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2921 gen_exception(&dc
, EXCP_DEBUG
);
2925 check_breakpoint(env
, &dc
);
2928 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
2932 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
2935 tcg_ctx
.gen_opc_pc
[lj
] = dc
.pc
;
2936 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
2937 tcg_ctx
.gen_opc_icount
[lj
] = insn_count
;
2940 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
2941 tcg_gen_debug_insn_start(dc
.pc
);
2946 if (insn_count
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
)) {
2951 int label
= gen_new_label();
2953 tcg_gen_addi_i32(dc
.next_icount
, cpu_SR
[ICOUNT
], 1);
2954 tcg_gen_brcondi_i32(TCG_COND_NE
, dc
.next_icount
, 0, label
);
2955 tcg_gen_mov_i32(dc
.next_icount
, cpu_SR
[ICOUNT
]);
2957 gen_debug_exception(&dc
, DEBUGCAUSE_IC
);
2959 gen_set_label(label
);
2963 gen_ibreak_check(env
, &dc
);
2966 disas_xtensa_insn(env
, &dc
);
2969 tcg_gen_mov_i32(cpu_SR
[ICOUNT
], dc
.next_icount
);
2971 if (env
->singlestep_enabled
) {
2972 tcg_gen_movi_i32(cpu_pc
, dc
.pc
);
2973 gen_exception(&dc
, EXCP_DEBUG
);
2976 } while (dc
.is_jmp
== DISAS_NEXT
&&
2977 insn_count
< max_insns
&&
2978 dc
.pc
< next_page_start
&&
2979 tcg_ctx
.gen_opc_ptr
< gen_opc_end
);
2982 reset_sar_tracker(&dc
);
2984 tcg_temp_free(dc
.next_icount
);
2987 if (tb
->cflags
& CF_LAST_IO
) {
2991 if (dc
.is_jmp
== DISAS_NEXT
) {
2992 gen_jumpi(&dc
, dc
.pc
, 0);
2994 gen_tb_end(tb
, insn_count
);
2995 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
2998 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
2999 memset(tcg_ctx
.gen_opc_instr_start
+ lj
+ 1, 0,
3000 (j
- lj
) * sizeof(tcg_ctx
.gen_opc_instr_start
[0]));
3002 tb
->size
= dc
.pc
- pc_start
;
3003 tb
->icount
= insn_count
;
3007 void gen_intermediate_code(CPUXtensaState
*env
, TranslationBlock
*tb
)
3009 gen_intermediate_code_internal(env
, tb
, 0);
3012 void gen_intermediate_code_pc(CPUXtensaState
*env
, TranslationBlock
*tb
)
3014 gen_intermediate_code_internal(env
, tb
, 1);
3017 void cpu_dump_state(CPUXtensaState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
3022 cpu_fprintf(f
, "PC=%08x\n\n", env
->pc
);
3024 for (i
= j
= 0; i
< 256; ++i
) {
3025 if (xtensa_option_bits_enabled(env
->config
, sregnames
[i
].opt_bits
)) {
3026 cpu_fprintf(f
, "%12s=%08x%c", sregnames
[i
].name
, env
->sregs
[i
],
3027 (j
++ % 4) == 3 ? '\n' : ' ');
3031 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3033 for (i
= j
= 0; i
< 256; ++i
) {
3034 if (xtensa_option_bits_enabled(env
->config
, uregnames
[i
].opt_bits
)) {
3035 cpu_fprintf(f
, "%s=%08x%c", uregnames
[i
].name
, env
->uregs
[i
],
3036 (j
++ % 4) == 3 ? '\n' : ' ');
3040 cpu_fprintf(f
, (j
% 4) == 0 ? "\n" : "\n\n");
3042 for (i
= 0; i
< 16; ++i
) {
3043 cpu_fprintf(f
, " A%02d=%08x%c", i
, env
->regs
[i
],
3044 (i
% 4) == 3 ? '\n' : ' ');
3047 cpu_fprintf(f
, "\n");
3049 for (i
= 0; i
< env
->config
->nareg
; ++i
) {
3050 cpu_fprintf(f
, "AR%02d=%08x%c", i
, env
->phys_regs
[i
],
3051 (i
% 4) == 3 ? '\n' : ' ');
3054 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_FP_COPROCESSOR
)) {
3055 cpu_fprintf(f
, "\n");
3057 for (i
= 0; i
< 16; ++i
) {
3058 cpu_fprintf(f
, "F%02d=%08x (%+10.8e)%c", i
,
3059 float32_val(env
->fregs
[i
]),
3060 *(float *)&env
->fregs
[i
], (i
% 2) == 1 ? '\n' : ' ');
3065 void restore_state_to_opc(CPUXtensaState
*env
, TranslationBlock
*tb
, int pc_pos
)
3067 env
->pc
= tcg_ctx
.gen_opc_pc
[pc_pos
];