2 * Copyright (c) 2011, Max Filippov, Open Source and Linux Lab.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the Open Source and Linux Lab nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #define TARGET_LONG_BITS 32
34 /* Xtensa processors have a weak memory model */
35 #define TCG_GUEST_DEFAULT_MO (0)
37 #define CPUArchState struct CPUXtensaState
39 #include "qemu-common.h"
41 #include "exec/cpu-defs.h"
42 #include "xtensa-isa.h"
44 #define NB_MMU_MODES 4
46 #define TARGET_PHYS_ADDR_SPACE_BITS 32
47 #ifdef CONFIG_USER_ONLY
48 #define TARGET_VIRT_ADDR_SPACE_BITS 30
50 #define TARGET_VIRT_ADDR_SPACE_BITS 32
52 #define TARGET_PAGE_BITS 12
55 /* Additional instructions */
56 XTENSA_OPTION_CODE_DENSITY
,
58 XTENSA_OPTION_EXTENDED_L32R
,
59 XTENSA_OPTION_16_BIT_IMUL
,
60 XTENSA_OPTION_32_BIT_IMUL
,
61 XTENSA_OPTION_32_BIT_IMUL_HIGH
,
62 XTENSA_OPTION_32_BIT_IDIV
,
64 XTENSA_OPTION_MISC_OP_NSA
,
65 XTENSA_OPTION_MISC_OP_MINMAX
,
66 XTENSA_OPTION_MISC_OP_SEXT
,
67 XTENSA_OPTION_MISC_OP_CLAMPS
,
68 XTENSA_OPTION_COPROCESSOR
,
69 XTENSA_OPTION_BOOLEAN
,
70 XTENSA_OPTION_FP_COPROCESSOR
,
71 XTENSA_OPTION_MP_SYNCHRO
,
72 XTENSA_OPTION_CONDITIONAL_STORE
,
73 XTENSA_OPTION_ATOMCTL
,
74 XTENSA_OPTION_DEPBITS
,
76 /* Interrupts and exceptions */
77 XTENSA_OPTION_EXCEPTION
,
78 XTENSA_OPTION_RELOCATABLE_VECTOR
,
79 XTENSA_OPTION_UNALIGNED_EXCEPTION
,
80 XTENSA_OPTION_INTERRUPT
,
81 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
,
82 XTENSA_OPTION_TIMER_INTERRUPT
,
86 XTENSA_OPTION_ICACHE_TEST
,
87 XTENSA_OPTION_ICACHE_INDEX_LOCK
,
89 XTENSA_OPTION_DCACHE_TEST
,
90 XTENSA_OPTION_DCACHE_INDEX_LOCK
,
96 XTENSA_OPTION_HW_ALIGNMENT
,
97 XTENSA_OPTION_MEMORY_ECC_PARITY
,
99 /* Memory protection and translation */
100 XTENSA_OPTION_REGION_PROTECTION
,
101 XTENSA_OPTION_REGION_TRANSLATION
,
103 XTENSA_OPTION_CACHEATTR
,
106 XTENSA_OPTION_WINDOWED_REGISTER
,
107 XTENSA_OPTION_PROCESSOR_INTERFACE
,
108 XTENSA_OPTION_MISC_SR
,
109 XTENSA_OPTION_THREAD_POINTER
,
110 XTENSA_OPTION_PROCESSOR_ID
,
112 XTENSA_OPTION_TRACE_PORT
,
113 XTENSA_OPTION_EXTERN_REGS
,
173 #define PS_INTLEVEL 0xf
174 #define PS_INTLEVEL_SHIFT 0
180 #define PS_RING_SHIFT 6
183 #define PS_OWB_SHIFT 8
186 #define PS_CALLINC 0x30000
187 #define PS_CALLINC_SHIFT 16
188 #define PS_CALLINC_LEN 2
190 #define PS_WOE 0x40000
192 #define DEBUGCAUSE_IC 0x1
193 #define DEBUGCAUSE_IB 0x2
194 #define DEBUGCAUSE_DB 0x4
195 #define DEBUGCAUSE_BI 0x8
196 #define DEBUGCAUSE_BN 0x10
197 #define DEBUGCAUSE_DI 0x20
198 #define DEBUGCAUSE_DBNUM 0xf00
199 #define DEBUGCAUSE_DBNUM_SHIFT 8
201 #define DBREAKC_SB 0x80000000
202 #define DBREAKC_LB 0x40000000
203 #define DBREAKC_SB_LB (DBREAKC_SB | DBREAKC_LB)
204 #define DBREAKC_MASK 0x3f
206 #define MEMCTL_INIT 0x00800000
207 #define MEMCTL_IUSEWAYS_SHIFT 18
208 #define MEMCTL_IUSEWAYS_LEN 5
209 #define MEMCTL_IUSEWAYS_MASK 0x007c0000
210 #define MEMCTL_DALLOCWAYS_SHIFT 13
211 #define MEMCTL_DALLOCWAYS_LEN 5
212 #define MEMCTL_DALLOCWAYS_MASK 0x0003e000
213 #define MEMCTL_DUSEWAYS_SHIFT 8
214 #define MEMCTL_DUSEWAYS_LEN 5
215 #define MEMCTL_DUSEWAYS_MASK 0x00001f00
216 #define MEMCTL_ISNP 0x4
217 #define MEMCTL_DSNP 0x2
218 #define MEMCTL_IL0EN 0x1
220 #define MAX_INSN_LENGTH 64
221 #define MAX_INSN_SLOTS 32
222 #define MAX_OPCODE_ARGS 16
224 #define MAX_NINTERRUPT 32
227 #define MAX_NCCOMPARE 3
228 #define MAX_TLB_WAY_SIZE 8
229 #define MAX_NDBREAK 2
230 #define MAX_NMEMORY 4
232 #define REGION_PAGE_MASK 0xe0000000
234 #define PAGE_CACHE_MASK 0x700
235 #define PAGE_CACHE_SHIFT 8
236 #define PAGE_CACHE_INVALID 0x000
237 #define PAGE_CACHE_BYPASS 0x100
238 #define PAGE_CACHE_WT 0x200
239 #define PAGE_CACHE_WB 0x400
240 #define PAGE_CACHE_ISOLATE 0x600
248 /* Dynamic vectors */
249 EXC_WINDOW_OVERFLOW4
,
250 EXC_WINDOW_UNDERFLOW4
,
251 EXC_WINDOW_OVERFLOW8
,
252 EXC_WINDOW_UNDERFLOW8
,
253 EXC_WINDOW_OVERFLOW12
,
254 EXC_WINDOW_UNDERFLOW12
,
264 ILLEGAL_INSTRUCTION_CAUSE
= 0,
266 INSTRUCTION_FETCH_ERROR_CAUSE
,
267 LOAD_STORE_ERROR_CAUSE
,
268 LEVEL1_INTERRUPT_CAUSE
,
270 INTEGER_DIVIDE_BY_ZERO_CAUSE
,
271 PRIVILEGED_CAUSE
= 8,
272 LOAD_STORE_ALIGNMENT_CAUSE
,
274 INSTR_PIF_DATA_ERROR_CAUSE
= 12,
275 LOAD_STORE_PIF_DATA_ERROR_CAUSE
,
276 INSTR_PIF_ADDR_ERROR_CAUSE
,
277 LOAD_STORE_PIF_ADDR_ERROR_CAUSE
,
280 INST_TLB_MULTI_HIT_CAUSE
,
281 INST_FETCH_PRIVILEGE_CAUSE
,
282 INST_FETCH_PROHIBITED_CAUSE
= 20,
283 LOAD_STORE_TLB_MISS_CAUSE
= 24,
284 LOAD_STORE_TLB_MULTI_HIT_CAUSE
,
285 LOAD_STORE_PRIVILEGE_CAUSE
,
286 LOAD_PROHIBITED_CAUSE
= 28,
287 STORE_PROHIBITED_CAUSE
,
289 COPROCESSOR0_DISABLED
= 32,
304 struct CPUXtensaState
;
306 typedef struct xtensa_tlb_entry
{
314 typedef struct xtensa_tlb
{
316 const unsigned way_size
[10];
318 unsigned nrefillentries
;
321 typedef struct XtensaGdbReg
{
329 typedef struct XtensaGdbRegmap
{
332 /* PC + a + ar + sr + ur */
333 XtensaGdbReg reg
[1 + 16 + 64 + 256 + 256];
336 typedef struct XtensaCcompareTimer
{
337 struct CPUXtensaState
*env
;
339 } XtensaCcompareTimer
;
341 typedef struct XtensaMemory
{
343 struct XtensaMemoryRegion
{
346 } location
[MAX_NMEMORY
];
349 typedef struct opcode_arg
{
356 typedef struct DisasContext DisasContext
;
357 typedef void (*XtensaOpcodeOp
)(DisasContext
*dc
, const OpcodeArg arg
[],
358 const uint32_t par
[]);
359 typedef bool (*XtensaOpcodeBoolTest
)(DisasContext
*dc
,
360 const OpcodeArg arg
[],
361 const uint32_t par
[]);
362 typedef uint32_t (*XtensaOpcodeUintTest
)(DisasContext
*dc
,
363 const OpcodeArg arg
[],
364 const uint32_t par
[]);
368 XTENSA_OP_PRIVILEGED
= 0x2,
369 XTENSA_OP_SYSCALL
= 0x4,
370 XTENSA_OP_DEBUG_BREAK
= 0x8,
372 XTENSA_OP_OVERFLOW
= 0x10,
373 XTENSA_OP_UNDERFLOW
= 0x20,
374 XTENSA_OP_ALLOCA
= 0x40,
375 XTENSA_OP_COPROCESSOR
= 0x80,
377 XTENSA_OP_DIVIDE_BY_ZERO
= 0x100,
379 /* Postprocessing flags */
380 XTENSA_OP_CHECK_INTERRUPTS
= 0x200,
381 XTENSA_OP_EXIT_TB_M1
= 0x400,
382 XTENSA_OP_EXIT_TB_0
= 0x800,
383 XTENSA_OP_SYNC_REGISTER_WINDOW
= 0x1000,
385 XTENSA_OP_POSTPROCESS
=
386 XTENSA_OP_CHECK_INTERRUPTS
|
387 XTENSA_OP_EXIT_TB_M1
|
388 XTENSA_OP_EXIT_TB_0
|
389 XTENSA_OP_SYNC_REGISTER_WINDOW
,
391 XTENSA_OP_NAME_ARRAY
= 0x8000,
393 XTENSA_OP_CONTROL_FLOW
= 0x10000,
394 XTENSA_OP_STORE
= 0x20000,
395 XTENSA_OP_LOAD
= 0x40000,
396 XTENSA_OP_LOAD_STORE
=
397 XTENSA_OP_LOAD
| XTENSA_OP_STORE
,
400 typedef struct XtensaOpcodeOps
{
402 XtensaOpcodeOp translate
;
403 XtensaOpcodeBoolTest test_ill
;
404 XtensaOpcodeUintTest test_overflow
;
407 uint32_t coprocessor
;
410 typedef struct XtensaOpcodeTranslators
{
411 unsigned num_opcodes
;
412 const XtensaOpcodeOps
*opcode
;
413 } XtensaOpcodeTranslators
;
415 extern const XtensaOpcodeTranslators xtensa_core_opcodes
;
416 extern const XtensaOpcodeTranslators xtensa_fpu2000_opcodes
;
418 struct XtensaConfig
{
421 XtensaGdbRegmap gdb_regmap
;
425 unsigned inst_fetch_width
;
426 unsigned max_insn_size
;
428 uint32_t exception_vector
[EXC_MAX
];
431 uint32_t interrupt_vector
[MAX_NLEVEL
+ MAX_NNMI
+ 1];
432 uint32_t level_mask
[MAX_NLEVEL
+ MAX_NNMI
+ 1];
433 uint32_t inttype_mask
[INTTYPE_MAX
];
436 interrupt_type inttype
;
437 } interrupt
[MAX_NINTERRUPT
];
439 uint32_t timerint
[MAX_NCCOMPARE
];
441 unsigned extint
[MAX_NINTERRUPT
];
443 unsigned debug_level
;
447 unsigned icache_ways
;
448 unsigned dcache_ways
;
449 uint32_t memctl_mask
;
451 XtensaMemory instrom
;
452 XtensaMemory instram
;
453 XtensaMemory datarom
;
454 XtensaMemory dataram
;
458 uint32_t configid
[2];
462 XtensaOpcodeOps
**opcode_ops
;
463 const XtensaOpcodeTranslators
**opcode_translators
;
464 xtensa_regfile a_regfile
;
467 uint32_t clock_freq_khz
;
473 typedef struct XtensaConfigList
{
474 const XtensaConfig
*config
;
475 struct XtensaConfigList
*next
;
478 #ifdef HOST_WORDS_BIGENDIAN
490 typedef struct CPUXtensaState
{
491 const XtensaConfig
*config
;
496 uint32_t phys_regs
[MAX_NAREG
];
501 float_status fp_status
;
502 uint32_t windowbase_next
;
504 #ifndef CONFIG_USER_ONLY
505 xtensa_tlb_entry itlb
[7][MAX_TLB_WAY_SIZE
];
506 xtensa_tlb_entry dtlb
[10][MAX_TLB_WAY_SIZE
];
507 unsigned autorefill_idx
;
509 AddressSpace
*address_space_er
;
510 MemoryRegion
*system_er
;
511 int pending_irq_level
; /* level of last raised IRQ */
512 qemu_irq
*irq_inputs
;
513 qemu_irq ext_irq_inputs
[MAX_NINTERRUPT
];
514 qemu_irq runstall_irq
;
515 XtensaCcompareTimer ccompare
[MAX_NCCOMPARE
];
517 uint64_t ccount_time
;
518 uint32_t ccount_base
;
523 unsigned static_vectors
;
525 /* Watchpoints for DBREAK registers */
526 struct CPUWatchpoint
*cpu_watchpoint
[MAX_NDBREAK
];
533 * @env: #CPUXtensaState
545 static inline XtensaCPU
*xtensa_env_get_cpu(const CPUXtensaState
*env
)
547 return container_of(env
, XtensaCPU
, env
);
550 #define ENV_GET_CPU(e) CPU(xtensa_env_get_cpu(e))
552 #define ENV_OFFSET offsetof(XtensaCPU, env)
555 int xtensa_cpu_handle_mmu_fault(CPUState
*cs
, vaddr address
, int rw
, int size
,
557 void xtensa_cpu_do_interrupt(CPUState
*cpu
);
558 bool xtensa_cpu_exec_interrupt(CPUState
*cpu
, int interrupt_request
);
559 void xtensa_cpu_do_transaction_failed(CPUState
*cs
, hwaddr physaddr
, vaddr addr
,
560 unsigned size
, MMUAccessType access_type
,
561 int mmu_idx
, MemTxAttrs attrs
,
562 MemTxResult response
, uintptr_t retaddr
);
563 void xtensa_cpu_dump_state(CPUState
*cpu
, FILE *f
,
564 fprintf_function cpu_fprintf
, int flags
);
565 hwaddr
xtensa_cpu_get_phys_page_debug(CPUState
*cpu
, vaddr addr
);
566 void xtensa_count_regs(const XtensaConfig
*config
,
567 unsigned *n_regs
, unsigned *n_core_regs
);
568 int xtensa_cpu_gdb_read_register(CPUState
*cpu
, uint8_t *buf
, int reg
);
569 int xtensa_cpu_gdb_write_register(CPUState
*cpu
, uint8_t *buf
, int reg
);
570 void xtensa_cpu_do_unaligned_access(CPUState
*cpu
, vaddr addr
,
571 MMUAccessType access_type
,
572 int mmu_idx
, uintptr_t retaddr
);
574 #define cpu_signal_handler cpu_xtensa_signal_handler
575 #define cpu_list xtensa_cpu_list
577 #define XTENSA_CPU_TYPE_SUFFIX "-" TYPE_XTENSA_CPU
578 #define XTENSA_CPU_TYPE_NAME(model) model XTENSA_CPU_TYPE_SUFFIX
579 #define CPU_RESOLVING_TYPE TYPE_XTENSA_CPU
581 #ifdef TARGET_WORDS_BIGENDIAN
582 #define XTENSA_DEFAULT_CPU_MODEL "fsf"
583 #define XTENSA_DEFAULT_CPU_NOMMU_MODEL "fsf"
585 #define XTENSA_DEFAULT_CPU_MODEL "dc232b"
586 #define XTENSA_DEFAULT_CPU_NOMMU_MODEL "de212"
588 #define XTENSA_DEFAULT_CPU_TYPE \
589 XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)
590 #define XTENSA_DEFAULT_CPU_NOMMU_TYPE \
591 XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_NOMMU_MODEL)
593 void xtensa_translate_init(void);
594 void **xtensa_get_regfile_by_name(const char *name
);
595 void xtensa_breakpoint_handler(CPUState
*cs
);
596 void xtensa_register_core(XtensaConfigList
*node
);
597 void xtensa_sim_open_console(Chardev
*chr
);
598 void check_interrupts(CPUXtensaState
*s
);
599 void xtensa_irq_init(CPUXtensaState
*env
);
600 qemu_irq
*xtensa_get_extints(CPUXtensaState
*env
);
601 qemu_irq
xtensa_get_runstall(CPUXtensaState
*env
);
602 int cpu_xtensa_signal_handler(int host_signum
, void *pinfo
, void *puc
);
603 void xtensa_cpu_list(FILE *f
, fprintf_function cpu_fprintf
);
604 void xtensa_sync_window_from_phys(CPUXtensaState
*env
);
605 void xtensa_sync_phys_from_window(CPUXtensaState
*env
);
606 void xtensa_rotate_window(CPUXtensaState
*env
, uint32_t delta
);
607 void xtensa_restore_owb(CPUXtensaState
*env
);
608 void debug_exception_env(CPUXtensaState
*new_env
, uint32_t cause
);
610 static inline void xtensa_select_static_vectors(CPUXtensaState
*env
,
614 env
->static_vectors
= n
;
616 void xtensa_runstall(CPUXtensaState
*env
, bool runstall
);
618 #define XTENSA_OPTION_BIT(opt) (((uint64_t)1) << (opt))
619 #define XTENSA_OPTION_ALL (~(uint64_t)0)
621 static inline bool xtensa_option_bits_enabled(const XtensaConfig
*config
,
624 return (config
->options
& opt
) != 0;
627 static inline bool xtensa_option_enabled(const XtensaConfig
*config
, int opt
)
629 return xtensa_option_bits_enabled(config
, XTENSA_OPTION_BIT(opt
));
632 static inline int xtensa_get_cintlevel(const CPUXtensaState
*env
)
634 int level
= (env
->sregs
[PS
] & PS_INTLEVEL
) >> PS_INTLEVEL_SHIFT
;
635 if ((env
->sregs
[PS
] & PS_EXCM
) && env
->config
->excm_level
> level
) {
636 level
= env
->config
->excm_level
;
641 static inline int xtensa_get_ring(const CPUXtensaState
*env
)
643 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_MMU
)) {
644 return (env
->sregs
[PS
] & PS_RING
) >> PS_RING_SHIFT
;
650 static inline int xtensa_get_cring(const CPUXtensaState
*env
)
652 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_MMU
) &&
653 (env
->sregs
[PS
] & PS_EXCM
) == 0) {
654 return (env
->sregs
[PS
] & PS_RING
) >> PS_RING_SHIFT
;
660 #ifndef CONFIG_USER_ONLY
661 uint32_t xtensa_tlb_get_addr_mask(const CPUXtensaState
*env
,
662 bool dtlb
, uint32_t way
);
663 void split_tlb_entry_spec_way(const CPUXtensaState
*env
, uint32_t v
, bool dtlb
,
664 uint32_t *vpn
, uint32_t wi
, uint32_t *ei
);
665 int xtensa_tlb_lookup(const CPUXtensaState
*env
, uint32_t addr
, bool dtlb
,
666 uint32_t *pwi
, uint32_t *pei
, uint8_t *pring
);
667 void xtensa_tlb_set_entry_mmu(const CPUXtensaState
*env
,
668 xtensa_tlb_entry
*entry
, bool dtlb
,
669 unsigned wi
, unsigned ei
, uint32_t vpn
, uint32_t pte
);
670 void xtensa_tlb_set_entry(CPUXtensaState
*env
, bool dtlb
,
671 unsigned wi
, unsigned ei
, uint32_t vpn
, uint32_t pte
);
672 int xtensa_get_physical_addr(CPUXtensaState
*env
, bool update_tlb
,
673 uint32_t vaddr
, int is_write
, int mmu_idx
,
674 uint32_t *paddr
, uint32_t *page_size
, unsigned *access
);
675 void reset_mmu(CPUXtensaState
*env
);
676 void dump_mmu(FILE *f
, fprintf_function cpu_fprintf
, CPUXtensaState
*env
);
678 static inline MemoryRegion
*xtensa_get_er_region(CPUXtensaState
*env
)
680 return env
->system_er
;
683 static inline xtensa_tlb_entry
*xtensa_tlb_get_entry(CPUXtensaState
*env
,
684 bool dtlb
, unsigned wi
, unsigned ei
)
692 static inline uint32_t xtensa_replicate_windowstart(CPUXtensaState
*env
)
694 return env
->sregs
[WINDOW_START
] |
695 (env
->sregs
[WINDOW_START
] << env
->config
->nareg
/ 4);
698 /* MMU modes definitions */
699 #define MMU_MODE0_SUFFIX _ring0
700 #define MMU_MODE1_SUFFIX _ring1
701 #define MMU_MODE2_SUFFIX _ring2
702 #define MMU_MODE3_SUFFIX _ring3
703 #define MMU_USER_IDX 3
705 static inline int cpu_mmu_index(CPUXtensaState
*env
, bool ifetch
)
707 return xtensa_get_cring(env
);
710 #define XTENSA_TBFLAG_RING_MASK 0x3
711 #define XTENSA_TBFLAG_EXCM 0x4
712 #define XTENSA_TBFLAG_LITBASE 0x8
713 #define XTENSA_TBFLAG_DEBUG 0x10
714 #define XTENSA_TBFLAG_ICOUNT 0x20
715 #define XTENSA_TBFLAG_CPENABLE_MASK 0x3fc0
716 #define XTENSA_TBFLAG_CPENABLE_SHIFT 6
717 #define XTENSA_TBFLAG_EXCEPTION 0x4000
718 #define XTENSA_TBFLAG_WINDOW_MASK 0x18000
719 #define XTENSA_TBFLAG_WINDOW_SHIFT 15
720 #define XTENSA_TBFLAG_YIELD 0x20000
721 #define XTENSA_TBFLAG_CWOE 0x40000
722 #define XTENSA_TBFLAG_CALLINC_MASK 0x180000
723 #define XTENSA_TBFLAG_CALLINC_SHIFT 19
725 #define XTENSA_CSBASE_LEND_MASK 0x0000ffff
726 #define XTENSA_CSBASE_LEND_SHIFT 0
727 #define XTENSA_CSBASE_LBEG_OFF_MASK 0x00ff0000
728 #define XTENSA_CSBASE_LBEG_OFF_SHIFT 16
730 static inline void cpu_get_tb_cpu_state(CPUXtensaState
*env
, target_ulong
*pc
,
731 target_ulong
*cs_base
, uint32_t *flags
)
733 CPUState
*cs
= CPU(xtensa_env_get_cpu(env
));
738 *flags
|= xtensa_get_ring(env
);
739 if (env
->sregs
[PS
] & PS_EXCM
) {
740 *flags
|= XTENSA_TBFLAG_EXCM
;
741 } else if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_LOOP
)) {
742 target_ulong lend_dist
=
743 env
->sregs
[LEND
] - (env
->pc
& -(1u << TARGET_PAGE_BITS
));
746 * 0 in the csbase_lend field means that there may not be a loopback
747 * for any instruction that starts inside this page. Any other value
748 * means that an instruction that ends at this offset from the page
749 * start may loop back and will need loopback code to be generated.
751 * lend_dist is 0 when LEND points to the start of the page, but
752 * no instruction that starts inside this page may end at offset 0,
753 * so it's still correct.
755 * When an instruction ends at a page boundary it may only start in
756 * the previous page. lend_dist will be encoded as TARGET_PAGE_SIZE
757 * for the TB that contains this instruction.
759 if (lend_dist
< (1u << TARGET_PAGE_BITS
) + env
->config
->max_insn_size
) {
760 target_ulong lbeg_off
= env
->sregs
[LEND
] - env
->sregs
[LBEG
];
762 *cs_base
= lend_dist
;
763 if (lbeg_off
< 256) {
764 *cs_base
|= lbeg_off
<< XTENSA_CSBASE_LBEG_OFF_SHIFT
;
768 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_EXTENDED_L32R
) &&
769 (env
->sregs
[LITBASE
] & 1)) {
770 *flags
|= XTENSA_TBFLAG_LITBASE
;
772 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_DEBUG
)) {
773 if (xtensa_get_cintlevel(env
) < env
->config
->debug_level
) {
774 *flags
|= XTENSA_TBFLAG_DEBUG
;
776 if (xtensa_get_cintlevel(env
) < env
->sregs
[ICOUNTLEVEL
]) {
777 *flags
|= XTENSA_TBFLAG_ICOUNT
;
780 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_COPROCESSOR
)) {
781 *flags
|= env
->sregs
[CPENABLE
] << XTENSA_TBFLAG_CPENABLE_SHIFT
;
783 if (cs
->singlestep_enabled
&& env
->exception_taken
) {
784 *flags
|= XTENSA_TBFLAG_EXCEPTION
;
786 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
787 (env
->sregs
[PS
] & (PS_WOE
| PS_EXCM
)) == PS_WOE
) {
788 uint32_t windowstart
= xtensa_replicate_windowstart(env
) >>
789 (env
->sregs
[WINDOW_BASE
] + 1);
790 uint32_t w
= ctz32(windowstart
| 0x8);
792 *flags
|= (w
<< XTENSA_TBFLAG_WINDOW_SHIFT
) | XTENSA_TBFLAG_CWOE
;
793 *flags
|= extract32(env
->sregs
[PS
], PS_CALLINC_SHIFT
,
794 PS_CALLINC_LEN
) << XTENSA_TBFLAG_CALLINC_SHIFT
;
796 *flags
|= 3 << XTENSA_TBFLAG_WINDOW_SHIFT
;
798 if (env
->yield_needed
) {
799 *flags
|= XTENSA_TBFLAG_YIELD
;
803 #include "exec/cpu-all.h"