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 #include "qemu/cpu-float.h"
33 #include "exec/cpu-defs.h"
35 #include "xtensa-isa.h"
37 /* Xtensa processors have a weak memory model */
38 #define TCG_GUEST_DEFAULT_MO (0)
41 /* Additional instructions */
42 XTENSA_OPTION_CODE_DENSITY
,
44 XTENSA_OPTION_EXTENDED_L32R
,
45 XTENSA_OPTION_16_BIT_IMUL
,
46 XTENSA_OPTION_32_BIT_IMUL
,
47 XTENSA_OPTION_32_BIT_IMUL_HIGH
,
48 XTENSA_OPTION_32_BIT_IDIV
,
50 XTENSA_OPTION_MISC_OP_NSA
,
51 XTENSA_OPTION_MISC_OP_MINMAX
,
52 XTENSA_OPTION_MISC_OP_SEXT
,
53 XTENSA_OPTION_MISC_OP_CLAMPS
,
54 XTENSA_OPTION_COPROCESSOR
,
55 XTENSA_OPTION_BOOLEAN
,
56 XTENSA_OPTION_FP_COPROCESSOR
,
57 XTENSA_OPTION_DFP_COPROCESSOR
,
58 XTENSA_OPTION_DFPU_SINGLE_ONLY
,
59 XTENSA_OPTION_MP_SYNCHRO
,
60 XTENSA_OPTION_CONDITIONAL_STORE
,
61 XTENSA_OPTION_ATOMCTL
,
62 XTENSA_OPTION_DEPBITS
,
64 /* Interrupts and exceptions */
65 XTENSA_OPTION_EXCEPTION
,
66 XTENSA_OPTION_RELOCATABLE_VECTOR
,
67 XTENSA_OPTION_UNALIGNED_EXCEPTION
,
68 XTENSA_OPTION_INTERRUPT
,
69 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
,
70 XTENSA_OPTION_TIMER_INTERRUPT
,
74 XTENSA_OPTION_ICACHE_TEST
,
75 XTENSA_OPTION_ICACHE_INDEX_LOCK
,
77 XTENSA_OPTION_DCACHE_TEST
,
78 XTENSA_OPTION_DCACHE_INDEX_LOCK
,
84 XTENSA_OPTION_HW_ALIGNMENT
,
85 XTENSA_OPTION_MEMORY_ECC_PARITY
,
87 /* Memory protection and translation */
88 XTENSA_OPTION_REGION_PROTECTION
,
89 XTENSA_OPTION_REGION_TRANSLATION
,
92 XTENSA_OPTION_CACHEATTR
,
95 XTENSA_OPTION_WINDOWED_REGISTER
,
96 XTENSA_OPTION_PROCESSOR_INTERFACE
,
97 XTENSA_OPTION_MISC_SR
,
98 XTENSA_OPTION_THREAD_POINTER
,
99 XTENSA_OPTION_PROCESSOR_ID
,
101 XTENSA_OPTION_TRACE_PORT
,
102 XTENSA_OPTION_EXTERN_REGS
,
172 #define PS_INTLEVEL 0xf
173 #define PS_INTLEVEL_SHIFT 0
179 #define PS_RING_SHIFT 6
182 #define PS_OWB_SHIFT 8
185 #define PS_CALLINC 0x30000
186 #define PS_CALLINC_SHIFT 16
187 #define PS_CALLINC_LEN 2
189 #define PS_WOE 0x40000
191 #define DEBUGCAUSE_IC 0x1
192 #define DEBUGCAUSE_IB 0x2
193 #define DEBUGCAUSE_DB 0x4
194 #define DEBUGCAUSE_BI 0x8
195 #define DEBUGCAUSE_BN 0x10
196 #define DEBUGCAUSE_DI 0x20
197 #define DEBUGCAUSE_DBNUM 0xf00
198 #define DEBUGCAUSE_DBNUM_SHIFT 8
200 #define DBREAKC_SB 0x80000000
201 #define DBREAKC_LB 0x40000000
202 #define DBREAKC_SB_LB (DBREAKC_SB | DBREAKC_LB)
203 #define DBREAKC_MASK 0x3f
205 #define MEMCTL_INIT 0x00800000
206 #define MEMCTL_IUSEWAYS_SHIFT 18
207 #define MEMCTL_IUSEWAYS_LEN 5
208 #define MEMCTL_IUSEWAYS_MASK 0x007c0000
209 #define MEMCTL_DALLOCWAYS_SHIFT 13
210 #define MEMCTL_DALLOCWAYS_LEN 5
211 #define MEMCTL_DALLOCWAYS_MASK 0x0003e000
212 #define MEMCTL_DUSEWAYS_SHIFT 8
213 #define MEMCTL_DUSEWAYS_LEN 5
214 #define MEMCTL_DUSEWAYS_MASK 0x00001f00
215 #define MEMCTL_ISNP 0x4
216 #define MEMCTL_DSNP 0x2
217 #define MEMCTL_IL0EN 0x1
219 #define MAX_INSN_LENGTH 64
220 #define MAX_INSNBUF_LENGTH \
221 ((MAX_INSN_LENGTH + sizeof(xtensa_insnbuf_word) - 1) / \
222 sizeof(xtensa_insnbuf_word))
223 #define MAX_INSN_SLOTS 32
224 #define MAX_OPCODE_ARGS 16
226 #define MAX_NINTERRUPT 32
229 #define MAX_NCCOMPARE 3
230 #define MAX_TLB_WAY_SIZE 8
231 #define MAX_NDBREAK 2
232 #define MAX_NMEMORY 4
233 #define MAX_MPU_FOREGROUND_SEGMENTS 32
235 #define REGION_PAGE_MASK 0xe0000000
237 #define PAGE_CACHE_MASK 0x700
238 #define PAGE_CACHE_SHIFT 8
239 #define PAGE_CACHE_INVALID 0x000
240 #define PAGE_CACHE_BYPASS 0x100
241 #define PAGE_CACHE_WT 0x200
242 #define PAGE_CACHE_WB 0x400
243 #define PAGE_CACHE_ISOLATE 0x600
251 /* Dynamic vectors */
252 EXC_WINDOW_OVERFLOW4
,
253 EXC_WINDOW_UNDERFLOW4
,
254 EXC_WINDOW_OVERFLOW8
,
255 EXC_WINDOW_UNDERFLOW8
,
256 EXC_WINDOW_OVERFLOW12
,
257 EXC_WINDOW_UNDERFLOW12
,
267 ILLEGAL_INSTRUCTION_CAUSE
= 0,
269 INSTRUCTION_FETCH_ERROR_CAUSE
,
270 LOAD_STORE_ERROR_CAUSE
,
271 LEVEL1_INTERRUPT_CAUSE
,
273 INTEGER_DIVIDE_BY_ZERO_CAUSE
,
274 PC_VALUE_ERROR_CAUSE
,
276 LOAD_STORE_ALIGNMENT_CAUSE
,
277 EXTERNAL_REG_PRIVILEGE_CAUSE
,
278 EXCLUSIVE_ERROR_CAUSE
,
279 INSTR_PIF_DATA_ERROR_CAUSE
,
280 LOAD_STORE_PIF_DATA_ERROR_CAUSE
,
281 INSTR_PIF_ADDR_ERROR_CAUSE
,
282 LOAD_STORE_PIF_ADDR_ERROR_CAUSE
,
284 INST_TLB_MULTI_HIT_CAUSE
,
285 INST_FETCH_PRIVILEGE_CAUSE
,
286 INST_FETCH_PROHIBITED_CAUSE
= 20,
287 LOAD_STORE_TLB_MISS_CAUSE
= 24,
288 LOAD_STORE_TLB_MULTI_HIT_CAUSE
,
289 LOAD_STORE_PRIVILEGE_CAUSE
,
290 LOAD_PROHIBITED_CAUSE
= 28,
291 STORE_PROHIBITED_CAUSE
,
293 COPROCESSOR0_DISABLED
= 32,
311 typedef struct CPUArchState CPUXtensaState
;
313 typedef struct xtensa_tlb_entry
{
321 typedef struct xtensa_tlb
{
323 const unsigned way_size
[10];
325 unsigned nrefillentries
;
328 typedef struct xtensa_mpu_entry
{
333 typedef struct XtensaGdbReg
{
341 typedef struct XtensaGdbRegmap
{
344 /* PC + a + ar + sr + ur */
345 XtensaGdbReg reg
[1 + 16 + 64 + 256 + 256];
348 typedef struct XtensaCcompareTimer
{
351 } XtensaCcompareTimer
;
353 typedef struct XtensaMemory
{
355 struct XtensaMemoryRegion
{
358 } location
[MAX_NMEMORY
];
361 typedef struct opcode_arg
{
369 typedef struct DisasContext DisasContext
;
370 typedef void (*XtensaOpcodeOp
)(DisasContext
*dc
, const OpcodeArg arg
[],
371 const uint32_t par
[]);
372 typedef uint32_t (*XtensaOpcodeUintTest
)(DisasContext
*dc
,
373 const OpcodeArg arg
[],
374 const uint32_t par
[]);
378 XTENSA_OP_PRIVILEGED
= 0x2,
379 XTENSA_OP_SYSCALL
= 0x4,
380 XTENSA_OP_DEBUG_BREAK
= 0x8,
382 XTENSA_OP_OVERFLOW
= 0x10,
383 XTENSA_OP_UNDERFLOW
= 0x20,
384 XTENSA_OP_ALLOCA
= 0x40,
385 XTENSA_OP_COPROCESSOR
= 0x80,
387 XTENSA_OP_DIVIDE_BY_ZERO
= 0x100,
389 /* Postprocessing flags */
390 XTENSA_OP_CHECK_INTERRUPTS
= 0x200,
391 XTENSA_OP_EXIT_TB_M1
= 0x400,
392 XTENSA_OP_EXIT_TB_0
= 0x800,
393 XTENSA_OP_SYNC_REGISTER_WINDOW
= 0x1000,
395 XTENSA_OP_POSTPROCESS
=
396 XTENSA_OP_CHECK_INTERRUPTS
|
397 XTENSA_OP_EXIT_TB_M1
|
398 XTENSA_OP_EXIT_TB_0
|
399 XTENSA_OP_SYNC_REGISTER_WINDOW
,
401 XTENSA_OP_NAME_ARRAY
= 0x8000,
403 XTENSA_OP_CONTROL_FLOW
= 0x10000,
404 XTENSA_OP_STORE
= 0x20000,
405 XTENSA_OP_LOAD
= 0x40000,
406 XTENSA_OP_LOAD_STORE
=
407 XTENSA_OP_LOAD
| XTENSA_OP_STORE
,
410 typedef struct XtensaOpcodeOps
{
412 XtensaOpcodeOp translate
;
413 XtensaOpcodeUintTest test_exceptions
;
414 XtensaOpcodeUintTest test_overflow
;
417 uint32_t coprocessor
;
420 typedef struct XtensaOpcodeTranslators
{
421 unsigned num_opcodes
;
422 const XtensaOpcodeOps
*opcode
;
423 } XtensaOpcodeTranslators
;
425 extern const XtensaOpcodeTranslators xtensa_core_opcodes
;
426 extern const XtensaOpcodeTranslators xtensa_fpu2000_opcodes
;
427 extern const XtensaOpcodeTranslators xtensa_fpu_opcodes
;
429 struct XtensaConfig
{
432 XtensaGdbRegmap gdb_regmap
;
436 unsigned inst_fetch_width
;
437 unsigned max_insn_size
;
439 uint32_t exception_vector
[EXC_MAX
];
443 uint32_t interrupt_vector
[MAX_NLEVEL
+ MAX_NNMI
+ 1];
444 uint32_t level_mask
[MAX_NLEVEL
+ MAX_NNMI
+ 1];
445 uint32_t inttype_mask
[INTTYPE_MAX
];
448 interrupt_type inttype
;
449 } interrupt
[MAX_NINTERRUPT
];
451 uint32_t timerint
[MAX_NCCOMPARE
];
453 unsigned extint
[MAX_NINTERRUPT
];
455 unsigned debug_level
;
459 unsigned icache_ways
;
460 unsigned dcache_ways
;
461 unsigned dcache_line_bytes
;
462 uint32_t memctl_mask
;
464 XtensaMemory instrom
;
465 XtensaMemory instram
;
466 XtensaMemory datarom
;
467 XtensaMemory dataram
;
472 uint32_t configid
[2];
476 XtensaOpcodeOps
**opcode_ops
;
477 const XtensaOpcodeTranslators
**opcode_translators
;
478 xtensa_regfile a_regfile
;
481 uint32_t clock_freq_khz
;
487 unsigned n_mpu_fg_segments
;
488 unsigned n_mpu_bg_segments
;
489 const xtensa_mpu_entry
*mpu_bg
;
494 typedef struct XtensaConfigList
{
495 const XtensaConfig
*config
;
496 struct XtensaConfigList
*next
;
511 struct CPUArchState
{
512 const XtensaConfig
*config
;
517 uint32_t phys_regs
[MAX_NAREG
];
522 float_status fp_status
;
523 uint32_t windowbase_next
;
524 uint32_t exclusive_addr
;
525 uint32_t exclusive_val
;
527 #ifndef CONFIG_USER_ONLY
528 xtensa_tlb_entry itlb
[7][MAX_TLB_WAY_SIZE
];
529 xtensa_tlb_entry dtlb
[10][MAX_TLB_WAY_SIZE
];
530 xtensa_mpu_entry mpu_fg
[MAX_MPU_FOREGROUND_SEGMENTS
];
531 unsigned autorefill_idx
;
533 AddressSpace
*address_space_er
;
534 MemoryRegion
*system_er
;
535 int pending_irq_level
; /* level of last raised IRQ */
536 qemu_irq
*irq_inputs
;
537 qemu_irq ext_irq_inputs
[MAX_NINTERRUPT
];
538 qemu_irq runstall_irq
;
539 XtensaCcompareTimer ccompare
[MAX_NCCOMPARE
];
541 uint64_t ccount_time
;
542 uint32_t ccount_base
;
546 unsigned static_vectors
;
548 /* Watchpoints for DBREAK registers */
549 struct CPUWatchpoint
*cpu_watchpoint
[MAX_NDBREAK
];
554 * @env: #CPUXtensaState
564 CPUNegativeOffsetState neg
;
569 #ifndef CONFIG_USER_ONLY
570 bool xtensa_cpu_tlb_fill(CPUState
*cs
, vaddr address
, int size
,
571 MMUAccessType access_type
, int mmu_idx
,
572 bool probe
, uintptr_t retaddr
);
573 void xtensa_cpu_do_interrupt(CPUState
*cpu
);
574 bool xtensa_cpu_exec_interrupt(CPUState
*cpu
, int interrupt_request
);
575 void xtensa_cpu_do_transaction_failed(CPUState
*cs
, hwaddr physaddr
, vaddr addr
,
576 unsigned size
, MMUAccessType access_type
,
577 int mmu_idx
, MemTxAttrs attrs
,
578 MemTxResult response
, uintptr_t retaddr
);
579 hwaddr
xtensa_cpu_get_phys_page_debug(CPUState
*cpu
, vaddr addr
);
581 void xtensa_cpu_dump_state(CPUState
*cpu
, FILE *f
, int flags
);
582 void xtensa_count_regs(const XtensaConfig
*config
,
583 unsigned *n_regs
, unsigned *n_core_regs
);
584 int xtensa_cpu_gdb_read_register(CPUState
*cpu
, GByteArray
*buf
, int reg
);
585 int xtensa_cpu_gdb_write_register(CPUState
*cpu
, uint8_t *buf
, int reg
);
586 G_NORETURN
void xtensa_cpu_do_unaligned_access(CPUState
*cpu
, vaddr addr
,
587 MMUAccessType access_type
, int mmu_idx
,
590 #define cpu_list xtensa_cpu_list
592 #define XTENSA_CPU_TYPE_SUFFIX "-" TYPE_XTENSA_CPU
593 #define XTENSA_CPU_TYPE_NAME(model) model XTENSA_CPU_TYPE_SUFFIX
594 #define CPU_RESOLVING_TYPE TYPE_XTENSA_CPU
596 #if TARGET_BIG_ENDIAN
597 #define XTENSA_DEFAULT_CPU_MODEL "fsf"
598 #define XTENSA_DEFAULT_CPU_NOMMU_MODEL "fsf"
600 #define XTENSA_DEFAULT_CPU_MODEL "dc232b"
601 #define XTENSA_DEFAULT_CPU_NOMMU_MODEL "de212"
603 #define XTENSA_DEFAULT_CPU_TYPE \
604 XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)
605 #define XTENSA_DEFAULT_CPU_NOMMU_TYPE \
606 XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_NOMMU_MODEL)
608 void xtensa_collect_sr_names(const XtensaConfig
*config
);
609 void xtensa_translate_init(void);
610 void **xtensa_get_regfile_by_name(const char *name
, int entries
, int bits
);
611 void xtensa_breakpoint_handler(CPUState
*cs
);
612 void xtensa_register_core(XtensaConfigList
*node
);
613 void xtensa_sim_open_console(Chardev
*chr
);
614 void check_interrupts(CPUXtensaState
*s
);
615 void xtensa_irq_init(CPUXtensaState
*env
);
616 qemu_irq
*xtensa_get_extints(CPUXtensaState
*env
);
617 qemu_irq
xtensa_get_runstall(CPUXtensaState
*env
);
618 void xtensa_cpu_list(void);
619 void xtensa_sync_window_from_phys(CPUXtensaState
*env
);
620 void xtensa_sync_phys_from_window(CPUXtensaState
*env
);
621 void xtensa_rotate_window(CPUXtensaState
*env
, uint32_t delta
);
622 void xtensa_restore_owb(CPUXtensaState
*env
);
623 void debug_exception_env(CPUXtensaState
*new_env
, uint32_t cause
);
625 static inline void xtensa_select_static_vectors(CPUXtensaState
*env
,
629 env
->static_vectors
= n
;
631 void xtensa_runstall(CPUXtensaState
*env
, bool runstall
);
633 #define XTENSA_OPTION_BIT(opt) (((uint64_t)1) << (opt))
634 #define XTENSA_OPTION_ALL (~(uint64_t)0)
636 static inline bool xtensa_option_bits_enabled(const XtensaConfig
*config
,
639 return (config
->options
& opt
) != 0;
642 static inline bool xtensa_option_enabled(const XtensaConfig
*config
, int opt
)
644 return xtensa_option_bits_enabled(config
, XTENSA_OPTION_BIT(opt
));
647 static inline int xtensa_get_cintlevel(const CPUXtensaState
*env
)
649 int level
= (env
->sregs
[PS
] & PS_INTLEVEL
) >> PS_INTLEVEL_SHIFT
;
650 if ((env
->sregs
[PS
] & PS_EXCM
) && env
->config
->excm_level
> level
) {
651 level
= env
->config
->excm_level
;
656 static inline int xtensa_get_ring(const CPUXtensaState
*env
)
658 if (xtensa_option_bits_enabled(env
->config
,
659 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
660 XTENSA_OPTION_BIT(XTENSA_OPTION_MPU
))) {
661 return (env
->sregs
[PS
] & PS_RING
) >> PS_RING_SHIFT
;
667 static inline int xtensa_get_cring(const CPUXtensaState
*env
)
669 if (xtensa_option_bits_enabled(env
->config
,
670 XTENSA_OPTION_BIT(XTENSA_OPTION_MMU
) |
671 XTENSA_OPTION_BIT(XTENSA_OPTION_MPU
)) &&
672 (env
->sregs
[PS
] & PS_EXCM
) == 0) {
673 return (env
->sregs
[PS
] & PS_RING
) >> PS_RING_SHIFT
;
679 #ifndef CONFIG_USER_ONLY
680 int xtensa_get_physical_addr(CPUXtensaState
*env
, bool update_tlb
,
681 uint32_t vaddr
, int is_write
, int mmu_idx
,
682 uint32_t *paddr
, uint32_t *page_size
, unsigned *access
);
683 void reset_mmu(CPUXtensaState
*env
);
684 void dump_mmu(CPUXtensaState
*env
);
686 static inline MemoryRegion
*xtensa_get_er_region(CPUXtensaState
*env
)
688 return env
->system_er
;
691 void xtensa_set_abi_call0(void);
692 bool xtensa_abi_call0(void);
695 static inline uint32_t xtensa_replicate_windowstart(CPUXtensaState
*env
)
697 return env
->sregs
[WINDOW_START
] |
698 (env
->sregs
[WINDOW_START
] << env
->config
->nareg
/ 4);
701 /* MMU modes definitions */
702 #define MMU_USER_IDX 3
704 static inline int cpu_mmu_index(CPUXtensaState
*env
, bool ifetch
)
706 return xtensa_get_cring(env
);
709 #define XTENSA_TBFLAG_RING_MASK 0x3
710 #define XTENSA_TBFLAG_EXCM 0x4
711 #define XTENSA_TBFLAG_LITBASE 0x8
712 #define XTENSA_TBFLAG_DEBUG 0x10
713 #define XTENSA_TBFLAG_ICOUNT 0x20
714 #define XTENSA_TBFLAG_CPENABLE_MASK 0x3fc0
715 #define XTENSA_TBFLAG_CPENABLE_SHIFT 6
716 #define XTENSA_TBFLAG_WINDOW_MASK 0x18000
717 #define XTENSA_TBFLAG_WINDOW_SHIFT 15
718 #define XTENSA_TBFLAG_YIELD 0x20000
719 #define XTENSA_TBFLAG_CWOE 0x40000
720 #define XTENSA_TBFLAG_CALLINC_MASK 0x180000
721 #define XTENSA_TBFLAG_CALLINC_SHIFT 19
723 #define XTENSA_CSBASE_LEND_MASK 0x0000ffff
724 #define XTENSA_CSBASE_LEND_SHIFT 0
725 #define XTENSA_CSBASE_LBEG_OFF_MASK 0x00ff0000
726 #define XTENSA_CSBASE_LBEG_OFF_SHIFT 16
728 #include "exec/cpu-all.h"
730 static inline void cpu_get_tb_cpu_state(CPUXtensaState
*env
, target_ulong
*pc
,
731 target_ulong
*cs_base
, uint32_t *flags
)
736 *flags
|= xtensa_get_ring(env
);
737 if (env
->sregs
[PS
] & PS_EXCM
) {
738 *flags
|= XTENSA_TBFLAG_EXCM
;
739 } else if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_LOOP
)) {
740 target_ulong lend_dist
=
741 env
->sregs
[LEND
] - (env
->pc
& -(1u << TARGET_PAGE_BITS
));
744 * 0 in the csbase_lend field means that there may not be a loopback
745 * for any instruction that starts inside this page. Any other value
746 * means that an instruction that ends at this offset from the page
747 * start may loop back and will need loopback code to be generated.
749 * lend_dist is 0 when LEND points to the start of the page, but
750 * no instruction that starts inside this page may end at offset 0,
751 * so it's still correct.
753 * When an instruction ends at a page boundary it may only start in
754 * the previous page. lend_dist will be encoded as TARGET_PAGE_SIZE
755 * for the TB that contains this instruction.
757 if (lend_dist
< (1u << TARGET_PAGE_BITS
) + env
->config
->max_insn_size
) {
758 target_ulong lbeg_off
= env
->sregs
[LEND
] - env
->sregs
[LBEG
];
760 *cs_base
= lend_dist
;
761 if (lbeg_off
< 256) {
762 *cs_base
|= lbeg_off
<< XTENSA_CSBASE_LBEG_OFF_SHIFT
;
766 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_EXTENDED_L32R
) &&
767 (env
->sregs
[LITBASE
] & 1)) {
768 *flags
|= XTENSA_TBFLAG_LITBASE
;
770 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_DEBUG
)) {
771 if (xtensa_get_cintlevel(env
) < env
->config
->debug_level
) {
772 *flags
|= XTENSA_TBFLAG_DEBUG
;
774 if (xtensa_get_cintlevel(env
) < env
->sregs
[ICOUNTLEVEL
]) {
775 *flags
|= XTENSA_TBFLAG_ICOUNT
;
778 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_COPROCESSOR
)) {
779 *flags
|= env
->sregs
[CPENABLE
] << XTENSA_TBFLAG_CPENABLE_SHIFT
;
781 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
782 (env
->sregs
[PS
] & (PS_WOE
| PS_EXCM
)) == PS_WOE
) {
783 uint32_t windowstart
= xtensa_replicate_windowstart(env
) >>
784 (env
->sregs
[WINDOW_BASE
] + 1);
785 uint32_t w
= ctz32(windowstart
| 0x8);
787 *flags
|= (w
<< XTENSA_TBFLAG_WINDOW_SHIFT
) | XTENSA_TBFLAG_CWOE
;
788 *flags
|= extract32(env
->sregs
[PS
], PS_CALLINC_SHIFT
,
789 PS_CALLINC_LEN
) << XTENSA_TBFLAG_CALLINC_SHIFT
;
791 *flags
|= 3 << XTENSA_TBFLAG_WINDOW_SHIFT
;
793 if (env
->yield_needed
) {
794 *flags
|= XTENSA_TBFLAG_YIELD
;
798 XtensaCPU
*xtensa_cpu_create_with_clock(const char *cpu_type
,