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.
31 #include "qemu-common.h"
33 #include "exec/cpu-defs.h"
34 #include "xtensa-isa.h"
38 /* Xtensa processors have a weak memory model */
39 #define TCG_GUEST_DEFAULT_MO (0)
41 #define CPUArchState struct CPUXtensaState
44 /* Additional instructions */
45 XTENSA_OPTION_CODE_DENSITY
,
47 XTENSA_OPTION_EXTENDED_L32R
,
48 XTENSA_OPTION_16_BIT_IMUL
,
49 XTENSA_OPTION_32_BIT_IMUL
,
50 XTENSA_OPTION_32_BIT_IMUL_HIGH
,
51 XTENSA_OPTION_32_BIT_IDIV
,
53 XTENSA_OPTION_MISC_OP_NSA
,
54 XTENSA_OPTION_MISC_OP_MINMAX
,
55 XTENSA_OPTION_MISC_OP_SEXT
,
56 XTENSA_OPTION_MISC_OP_CLAMPS
,
57 XTENSA_OPTION_COPROCESSOR
,
58 XTENSA_OPTION_BOOLEAN
,
59 XTENSA_OPTION_FP_COPROCESSOR
,
60 XTENSA_OPTION_MP_SYNCHRO
,
61 XTENSA_OPTION_CONDITIONAL_STORE
,
62 XTENSA_OPTION_ATOMCTL
,
63 XTENSA_OPTION_DEPBITS
,
65 /* Interrupts and exceptions */
66 XTENSA_OPTION_EXCEPTION
,
67 XTENSA_OPTION_RELOCATABLE_VECTOR
,
68 XTENSA_OPTION_UNALIGNED_EXCEPTION
,
69 XTENSA_OPTION_INTERRUPT
,
70 XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT
,
71 XTENSA_OPTION_TIMER_INTERRUPT
,
75 XTENSA_OPTION_ICACHE_TEST
,
76 XTENSA_OPTION_ICACHE_INDEX_LOCK
,
78 XTENSA_OPTION_DCACHE_TEST
,
79 XTENSA_OPTION_DCACHE_INDEX_LOCK
,
85 XTENSA_OPTION_HW_ALIGNMENT
,
86 XTENSA_OPTION_MEMORY_ECC_PARITY
,
88 /* Memory protection and translation */
89 XTENSA_OPTION_REGION_PROTECTION
,
90 XTENSA_OPTION_REGION_TRANSLATION
,
93 XTENSA_OPTION_CACHEATTR
,
96 XTENSA_OPTION_WINDOWED_REGISTER
,
97 XTENSA_OPTION_PROCESSOR_INTERFACE
,
98 XTENSA_OPTION_MISC_SR
,
99 XTENSA_OPTION_THREAD_POINTER
,
100 XTENSA_OPTION_PROCESSOR_ID
,
102 XTENSA_OPTION_TRACE_PORT
,
103 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
231 #define MAX_MPU_FOREGROUND_SEGMENTS 32
233 #define REGION_PAGE_MASK 0xe0000000
235 #define PAGE_CACHE_MASK 0x700
236 #define PAGE_CACHE_SHIFT 8
237 #define PAGE_CACHE_INVALID 0x000
238 #define PAGE_CACHE_BYPASS 0x100
239 #define PAGE_CACHE_WT 0x200
240 #define PAGE_CACHE_WB 0x400
241 #define PAGE_CACHE_ISOLATE 0x600
249 /* Dynamic vectors */
250 EXC_WINDOW_OVERFLOW4
,
251 EXC_WINDOW_UNDERFLOW4
,
252 EXC_WINDOW_OVERFLOW8
,
253 EXC_WINDOW_UNDERFLOW8
,
254 EXC_WINDOW_OVERFLOW12
,
255 EXC_WINDOW_UNDERFLOW12
,
265 ILLEGAL_INSTRUCTION_CAUSE
= 0,
267 INSTRUCTION_FETCH_ERROR_CAUSE
,
268 LOAD_STORE_ERROR_CAUSE
,
269 LEVEL1_INTERRUPT_CAUSE
,
271 INTEGER_DIVIDE_BY_ZERO_CAUSE
,
272 PC_VALUE_ERROR_CAUSE
,
274 LOAD_STORE_ALIGNMENT_CAUSE
,
275 EXTERNAL_REG_PRIVILEGE_CAUSE
,
276 EXCLUSIVE_ERROR_CAUSE
,
277 INSTR_PIF_DATA_ERROR_CAUSE
,
278 LOAD_STORE_PIF_DATA_ERROR_CAUSE
,
279 INSTR_PIF_ADDR_ERROR_CAUSE
,
280 LOAD_STORE_PIF_ADDR_ERROR_CAUSE
,
282 INST_TLB_MULTI_HIT_CAUSE
,
283 INST_FETCH_PRIVILEGE_CAUSE
,
284 INST_FETCH_PROHIBITED_CAUSE
= 20,
285 LOAD_STORE_TLB_MISS_CAUSE
= 24,
286 LOAD_STORE_TLB_MULTI_HIT_CAUSE
,
287 LOAD_STORE_PRIVILEGE_CAUSE
,
288 LOAD_PROHIBITED_CAUSE
= 28,
289 STORE_PROHIBITED_CAUSE
,
291 COPROCESSOR0_DISABLED
= 32,
309 struct CPUXtensaState
;
311 typedef struct xtensa_tlb_entry
{
319 typedef struct xtensa_tlb
{
321 const unsigned way_size
[10];
323 unsigned nrefillentries
;
326 typedef struct xtensa_mpu_entry
{
331 typedef struct XtensaGdbReg
{
339 typedef struct XtensaGdbRegmap
{
342 /* PC + a + ar + sr + ur */
343 XtensaGdbReg reg
[1 + 16 + 64 + 256 + 256];
346 typedef struct XtensaCcompareTimer
{
347 struct CPUXtensaState
*env
;
349 } XtensaCcompareTimer
;
351 typedef struct XtensaMemory
{
353 struct XtensaMemoryRegion
{
356 } location
[MAX_NMEMORY
];
359 typedef struct opcode_arg
{
366 typedef struct DisasContext DisasContext
;
367 typedef void (*XtensaOpcodeOp
)(DisasContext
*dc
, const OpcodeArg arg
[],
368 const uint32_t par
[]);
369 typedef bool (*XtensaOpcodeBoolTest
)(DisasContext
*dc
,
370 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 XtensaOpcodeBoolTest test_ill
;
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
;
428 struct XtensaConfig
{
431 XtensaGdbRegmap gdb_regmap
;
435 unsigned inst_fetch_width
;
436 unsigned max_insn_size
;
438 uint32_t exception_vector
[EXC_MAX
];
441 uint32_t interrupt_vector
[MAX_NLEVEL
+ MAX_NNMI
+ 1];
442 uint32_t level_mask
[MAX_NLEVEL
+ MAX_NNMI
+ 1];
443 uint32_t inttype_mask
[INTTYPE_MAX
];
446 interrupt_type inttype
;
447 } interrupt
[MAX_NINTERRUPT
];
449 uint32_t timerint
[MAX_NCCOMPARE
];
451 unsigned extint
[MAX_NINTERRUPT
];
453 unsigned debug_level
;
457 unsigned icache_ways
;
458 unsigned dcache_ways
;
459 unsigned dcache_line_bytes
;
460 uint32_t memctl_mask
;
462 XtensaMemory instrom
;
463 XtensaMemory instram
;
464 XtensaMemory datarom
;
465 XtensaMemory dataram
;
469 uint32_t configid
[2];
473 XtensaOpcodeOps
**opcode_ops
;
474 const XtensaOpcodeTranslators
**opcode_translators
;
475 xtensa_regfile a_regfile
;
478 uint32_t clock_freq_khz
;
484 unsigned n_mpu_fg_segments
;
485 unsigned n_mpu_bg_segments
;
486 const xtensa_mpu_entry
*mpu_bg
;
489 typedef struct XtensaConfigList
{
490 const XtensaConfig
*config
;
491 struct XtensaConfigList
*next
;
494 #ifdef HOST_WORDS_BIGENDIAN
506 typedef struct CPUXtensaState
{
507 const XtensaConfig
*config
;
512 uint32_t phys_regs
[MAX_NAREG
];
517 float_status fp_status
;
518 uint32_t windowbase_next
;
519 uint32_t exclusive_addr
;
520 uint32_t exclusive_val
;
522 #ifndef CONFIG_USER_ONLY
523 xtensa_tlb_entry itlb
[7][MAX_TLB_WAY_SIZE
];
524 xtensa_tlb_entry dtlb
[10][MAX_TLB_WAY_SIZE
];
525 xtensa_mpu_entry mpu_fg
[MAX_MPU_FOREGROUND_SEGMENTS
];
526 unsigned autorefill_idx
;
528 AddressSpace
*address_space_er
;
529 MemoryRegion
*system_er
;
530 int pending_irq_level
; /* level of last raised IRQ */
531 qemu_irq
*irq_inputs
;
532 qemu_irq ext_irq_inputs
[MAX_NINTERRUPT
];
533 qemu_irq runstall_irq
;
534 XtensaCcompareTimer ccompare
[MAX_NCCOMPARE
];
536 uint64_t ccount_time
;
537 uint32_t ccount_base
;
542 unsigned static_vectors
;
544 /* Watchpoints for DBREAK registers */
545 struct CPUWatchpoint
*cpu_watchpoint
[MAX_NDBREAK
];
552 * @env: #CPUXtensaState
564 static inline XtensaCPU
*xtensa_env_get_cpu(const CPUXtensaState
*env
)
566 return container_of(env
, XtensaCPU
, env
);
569 #define ENV_GET_CPU(e) CPU(xtensa_env_get_cpu(e))
571 #define ENV_OFFSET offsetof(XtensaCPU, env)
574 bool xtensa_cpu_tlb_fill(CPUState
*cs
, vaddr address
, int size
,
575 MMUAccessType access_type
, int mmu_idx
,
576 bool probe
, uintptr_t retaddr
);
577 void xtensa_cpu_do_interrupt(CPUState
*cpu
);
578 bool xtensa_cpu_exec_interrupt(CPUState
*cpu
, int interrupt_request
);
579 void xtensa_cpu_do_transaction_failed(CPUState
*cs
, hwaddr physaddr
, vaddr addr
,
580 unsigned size
, MMUAccessType access_type
,
581 int mmu_idx
, MemTxAttrs attrs
,
582 MemTxResult response
, uintptr_t retaddr
);
583 void xtensa_cpu_dump_state(CPUState
*cpu
, FILE *f
, int flags
);
584 hwaddr
xtensa_cpu_get_phys_page_debug(CPUState
*cpu
, vaddr addr
);
585 void xtensa_count_regs(const XtensaConfig
*config
,
586 unsigned *n_regs
, unsigned *n_core_regs
);
587 int xtensa_cpu_gdb_read_register(CPUState
*cpu
, uint8_t *buf
, int reg
);
588 int xtensa_cpu_gdb_write_register(CPUState
*cpu
, uint8_t *buf
, int reg
);
589 void xtensa_cpu_do_unaligned_access(CPUState
*cpu
, vaddr addr
,
590 MMUAccessType access_type
,
591 int mmu_idx
, uintptr_t retaddr
);
593 #define cpu_signal_handler cpu_xtensa_signal_handler
594 #define cpu_list xtensa_cpu_list
596 #define XTENSA_CPU_TYPE_SUFFIX "-" TYPE_XTENSA_CPU
597 #define XTENSA_CPU_TYPE_NAME(model) model XTENSA_CPU_TYPE_SUFFIX
598 #define CPU_RESOLVING_TYPE TYPE_XTENSA_CPU
600 #ifdef TARGET_WORDS_BIGENDIAN
601 #define XTENSA_DEFAULT_CPU_MODEL "fsf"
602 #define XTENSA_DEFAULT_CPU_NOMMU_MODEL "fsf"
604 #define XTENSA_DEFAULT_CPU_MODEL "dc232b"
605 #define XTENSA_DEFAULT_CPU_NOMMU_MODEL "de212"
607 #define XTENSA_DEFAULT_CPU_TYPE \
608 XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_MODEL)
609 #define XTENSA_DEFAULT_CPU_NOMMU_TYPE \
610 XTENSA_CPU_TYPE_NAME(XTENSA_DEFAULT_CPU_NOMMU_MODEL)
612 void xtensa_collect_sr_names(const XtensaConfig
*config
);
613 void xtensa_translate_init(void);
614 void **xtensa_get_regfile_by_name(const char *name
);
615 void xtensa_breakpoint_handler(CPUState
*cs
);
616 void xtensa_register_core(XtensaConfigList
*node
);
617 void xtensa_sim_open_console(Chardev
*chr
);
618 void check_interrupts(CPUXtensaState
*s
);
619 void xtensa_irq_init(CPUXtensaState
*env
);
620 qemu_irq
*xtensa_get_extints(CPUXtensaState
*env
);
621 qemu_irq
xtensa_get_runstall(CPUXtensaState
*env
);
622 int cpu_xtensa_signal_handler(int host_signum
, void *pinfo
, void *puc
);
623 void xtensa_cpu_list(void);
624 void xtensa_sync_window_from_phys(CPUXtensaState
*env
);
625 void xtensa_sync_phys_from_window(CPUXtensaState
*env
);
626 void xtensa_rotate_window(CPUXtensaState
*env
, uint32_t delta
);
627 void xtensa_restore_owb(CPUXtensaState
*env
);
628 void debug_exception_env(CPUXtensaState
*new_env
, uint32_t cause
);
630 static inline void xtensa_select_static_vectors(CPUXtensaState
*env
,
634 env
->static_vectors
= n
;
636 void xtensa_runstall(CPUXtensaState
*env
, bool runstall
);
638 #define XTENSA_OPTION_BIT(opt) (((uint64_t)1) << (opt))
639 #define XTENSA_OPTION_ALL (~(uint64_t)0)
641 static inline bool xtensa_option_bits_enabled(const XtensaConfig
*config
,
644 return (config
->options
& opt
) != 0;
647 static inline bool xtensa_option_enabled(const XtensaConfig
*config
, int opt
)
649 return xtensa_option_bits_enabled(config
, XTENSA_OPTION_BIT(opt
));
652 static inline int xtensa_get_cintlevel(const CPUXtensaState
*env
)
654 int level
= (env
->sregs
[PS
] & PS_INTLEVEL
) >> PS_INTLEVEL_SHIFT
;
655 if ((env
->sregs
[PS
] & PS_EXCM
) && env
->config
->excm_level
> level
) {
656 level
= env
->config
->excm_level
;
661 static inline int xtensa_get_ring(const CPUXtensaState
*env
)
663 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_MMU
)) {
664 return (env
->sregs
[PS
] & PS_RING
) >> PS_RING_SHIFT
;
670 static inline int xtensa_get_cring(const CPUXtensaState
*env
)
672 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_MMU
) &&
673 (env
->sregs
[PS
] & PS_EXCM
) == 0) {
674 return (env
->sregs
[PS
] & PS_RING
) >> PS_RING_SHIFT
;
680 #ifndef CONFIG_USER_ONLY
681 int xtensa_get_physical_addr(CPUXtensaState
*env
, bool update_tlb
,
682 uint32_t vaddr
, int is_write
, int mmu_idx
,
683 uint32_t *paddr
, uint32_t *page_size
, unsigned *access
);
684 void reset_mmu(CPUXtensaState
*env
);
685 void dump_mmu(CPUXtensaState
*env
);
687 static inline MemoryRegion
*xtensa_get_er_region(CPUXtensaState
*env
)
689 return env
->system_er
;
693 static inline uint32_t xtensa_replicate_windowstart(CPUXtensaState
*env
)
695 return env
->sregs
[WINDOW_START
] |
696 (env
->sregs
[WINDOW_START
] << env
->config
->nareg
/ 4);
699 /* MMU modes definitions */
700 #define MMU_MODE0_SUFFIX _ring0
701 #define MMU_MODE1_SUFFIX _ring1
702 #define MMU_MODE2_SUFFIX _ring2
703 #define MMU_MODE3_SUFFIX _ring3
704 #define MMU_USER_IDX 3
706 static inline int cpu_mmu_index(CPUXtensaState
*env
, bool ifetch
)
708 return xtensa_get_cring(env
);
711 #define XTENSA_TBFLAG_RING_MASK 0x3
712 #define XTENSA_TBFLAG_EXCM 0x4
713 #define XTENSA_TBFLAG_LITBASE 0x8
714 #define XTENSA_TBFLAG_DEBUG 0x10
715 #define XTENSA_TBFLAG_ICOUNT 0x20
716 #define XTENSA_TBFLAG_CPENABLE_MASK 0x3fc0
717 #define XTENSA_TBFLAG_CPENABLE_SHIFT 6
718 #define XTENSA_TBFLAG_EXCEPTION 0x4000
719 #define XTENSA_TBFLAG_WINDOW_MASK 0x18000
720 #define XTENSA_TBFLAG_WINDOW_SHIFT 15
721 #define XTENSA_TBFLAG_YIELD 0x20000
722 #define XTENSA_TBFLAG_CWOE 0x40000
723 #define XTENSA_TBFLAG_CALLINC_MASK 0x180000
724 #define XTENSA_TBFLAG_CALLINC_SHIFT 19
726 #define XTENSA_CSBASE_LEND_MASK 0x0000ffff
727 #define XTENSA_CSBASE_LEND_SHIFT 0
728 #define XTENSA_CSBASE_LBEG_OFF_MASK 0x00ff0000
729 #define XTENSA_CSBASE_LBEG_OFF_SHIFT 16
731 static inline void cpu_get_tb_cpu_state(CPUXtensaState
*env
, target_ulong
*pc
,
732 target_ulong
*cs_base
, uint32_t *flags
)
734 CPUState
*cs
= CPU(xtensa_env_get_cpu(env
));
739 *flags
|= xtensa_get_ring(env
);
740 if (env
->sregs
[PS
] & PS_EXCM
) {
741 *flags
|= XTENSA_TBFLAG_EXCM
;
742 } else if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_LOOP
)) {
743 target_ulong lend_dist
=
744 env
->sregs
[LEND
] - (env
->pc
& -(1u << TARGET_PAGE_BITS
));
747 * 0 in the csbase_lend field means that there may not be a loopback
748 * for any instruction that starts inside this page. Any other value
749 * means that an instruction that ends at this offset from the page
750 * start may loop back and will need loopback code to be generated.
752 * lend_dist is 0 when LEND points to the start of the page, but
753 * no instruction that starts inside this page may end at offset 0,
754 * so it's still correct.
756 * When an instruction ends at a page boundary it may only start in
757 * the previous page. lend_dist will be encoded as TARGET_PAGE_SIZE
758 * for the TB that contains this instruction.
760 if (lend_dist
< (1u << TARGET_PAGE_BITS
) + env
->config
->max_insn_size
) {
761 target_ulong lbeg_off
= env
->sregs
[LEND
] - env
->sregs
[LBEG
];
763 *cs_base
= lend_dist
;
764 if (lbeg_off
< 256) {
765 *cs_base
|= lbeg_off
<< XTENSA_CSBASE_LBEG_OFF_SHIFT
;
769 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_EXTENDED_L32R
) &&
770 (env
->sregs
[LITBASE
] & 1)) {
771 *flags
|= XTENSA_TBFLAG_LITBASE
;
773 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_DEBUG
)) {
774 if (xtensa_get_cintlevel(env
) < env
->config
->debug_level
) {
775 *flags
|= XTENSA_TBFLAG_DEBUG
;
777 if (xtensa_get_cintlevel(env
) < env
->sregs
[ICOUNTLEVEL
]) {
778 *flags
|= XTENSA_TBFLAG_ICOUNT
;
781 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_COPROCESSOR
)) {
782 *flags
|= env
->sregs
[CPENABLE
] << XTENSA_TBFLAG_CPENABLE_SHIFT
;
784 if (cs
->singlestep_enabled
&& env
->exception_taken
) {
785 *flags
|= XTENSA_TBFLAG_EXCEPTION
;
787 if (xtensa_option_enabled(env
->config
, XTENSA_OPTION_WINDOWED_REGISTER
) &&
788 (env
->sregs
[PS
] & (PS_WOE
| PS_EXCM
)) == PS_WOE
) {
789 uint32_t windowstart
= xtensa_replicate_windowstart(env
) >>
790 (env
->sregs
[WINDOW_BASE
] + 1);
791 uint32_t w
= ctz32(windowstart
| 0x8);
793 *flags
|= (w
<< XTENSA_TBFLAG_WINDOW_SHIFT
) | XTENSA_TBFLAG_CWOE
;
794 *flags
|= extract32(env
->sregs
[PS
], PS_CALLINC_SHIFT
,
795 PS_CALLINC_LEN
) << XTENSA_TBFLAG_CALLINC_SHIFT
;
797 *flags
|= 3 << XTENSA_TBFLAG_WINDOW_SHIFT
;
799 if (env
->yield_needed
) {
800 *flags
|= XTENSA_TBFLAG_YIELD
;
804 #include "exec/cpu-all.h"