target-xtensa: introduce new target architecture
cover target-xtensa: introduce new target architecture
This series adds support for Tensilica Xtensa target.
Overall RFC -> PATCH changes:
- implement TB chaining;
- replace stray printfs with qemu_logs;
- consolidate big endianness support with corresponding little endianness counterparts;
- removed gdbstub patch from this series, will post a separate RFC for it;
- fix copyrights.
Makefile.target | 4 + arch_init.c | 2 + arch_init.h | 1 + configure | 12 +- cpu-exec.c | 10 + default-configs/xtensa-softmmu.mak | 1 + default-configs/xtensaeb-softmmu.mak | 1 + elf.h | 2 + hw/xtensa_pic.c | 121 ++ hw/xtensa_sample.c | 100 ++ qemu-options.hx | 4 +- target-xtensa/cpu.h | 328 ++++++ target-xtensa/exec.h | 50 + target-xtensa/helper.c | 227 ++++ target-xtensa/helpers.h | 24 + target-xtensa/machine.c | 38 + target-xtensa/op_helper.c | 346 ++++++ target-xtensa/translate.c | 2152 ++++++++++++++++++++++++++++++++++ xtensa-semi.c | 176 +++ 19 files changed, 3596 insertions(+), 3 deletions(-)
PATCH 1/26 target-xtensa: add target stubs
---
RFC -> PATCH changes:
- remove cpu_reset from cpu_xtensa_init;
--- Makefile.target | 2 + arch_init.c | 2 + arch_init.h | 1 + cpu-exec.c | 4 ++ elf.h | 2 + hw/xtensa_pic.c | 38 ++++++++++++++++++++ target-xtensa/cpu.h | 84 +++++++++++++++++++++++++++++++++++++++++++++ target-xtensa/exec.h | 50 ++++++++++++++++++++++++++ target-xtensa/helper.c | 73 +++++++++++++++++++++++++++++++++++++++ target-xtensa/machine.c | 38 ++++++++++++++++++++ target-xtensa/op_helper.c | 51 +++++++++++++++++++++++++++ target-xtensa/translate.c | 67 +++++++++++++++++++++++++++++++++++ 12 files changed, 412 insertions(+), 0 deletions(-) create mode 100644 hw/xtensa_pic.c create mode 100644 target-xtensa/cpu.h create mode 100644 target-xtensa/exec.h create mode 100644 target-xtensa/helper.c create mode 100644 target-xtensa/machine.c create mode 100644 target-xtensa/op_helper.c create mode 100644 target-xtensa/translate.c
Makefile.target +2 -0
@@ -378,6 +378,8 @@ obj-s390x-y = s390-virtio-bus.o s390-virtio.o obj-alpha-y = alpha_palcode.o +obj-xtensa-y += xtensa_pic.o + main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) monitor.o: hmp-commands.h qmp-commands.h
arch_init.c +2 -0
@@ -78,6 +78,8 @@ const char arch_config_name[] = CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".con#define QEMU_ARCH QEMU_ARCH_SH4#elif defined(TARGET_SPARC )#define QEMU_ARCH QEMU_ARCH_SPARC +#elif defined(TARGET_XTENSA ) +#define QEMU_ARCH QEMU_ARCH_XTENSA#endif const uint32_t arch_type =QEMU_ARCH ;
arch_init.h +1 -0
@@ -17,6 +17,7 @@ enum {QEMU_ARCH_S390X =512 ,QEMU_ARCH_SH4 =1024 ,QEMU_ARCH_SPARC =2048 , + QEMU_ARCH_XTENSA = 4096, };extern const uint32_t arch_type;
cpu-exec.c +4 -0
@@ -275,6 +275,7 @@ int cpu_exec(CPUState *env1)#elif defined(TARGET_SH4 )#elif defined(TARGET_CRIS )#elif defined(TARGET_S390X ) +#elif defined(TARGET_XTENSA )/* XXXXX */ #else #error unsupported target CPU
@@ -348,6 +349,8 @@ int cpu_exec(CPUState *env1)do_interrupt (0 );#elif defined(TARGET_S390X )do_interrupt (env); +#elif defined(TARGET_XTENSA ) +do_interrupt (env);#endif env->exception_index =-1 ;#endif
@@ -690,6 +693,7 @@ int cpu_exec(CPUState *env1)#elif defined(TARGET_ALPHA )#elif defined(TARGET_CRIS )#elif defined(TARGET_S390X ) +#elif defined(TARGET_XTENSA )/* XXXXX */ #else #error unsupported target CPU
elf.h +2 -0
@@ -125,6 +125,8 @@ typedef int64_t Elf64_Sxword;#define EM_MICROBLAZE 189#define EM_MICROBLAZE_OLD 0xBAAB +#define EM_XTENSA 94/* Tensilica Xtensa */ +/* This is the info that is needed to parse the dynamic section of the file */ #define DT_NULL 0#define DT_NEEDED 1
hw/xtensa_pic.c new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright (c) 2011, Max Filippov, Open Source and Linux Lab. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the Open Source and Linux Lab nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "hw.h" +#include "pc.h" + +/* Stub functions for hardware that doesn't exist. */ +void pic_info (Monitor *mon) +{ +} + +void irq_info (Monitor *mon) +{ +}
target-xtensa/cpu.h new file +84 -0
84 lines not on this page · raw message
target-xtensa/exec.h new file +50 -0
50 lines not on this page · raw message
target-xtensa/helper.c new file +73 -0
73 lines not on this page · raw message
target-xtensa/machine.c new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright (c) 2011, Max Filippov, Open Source and Linux Lab. +* All rights reserved. +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* * Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* * Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* * Neither the name of the Open Source and Linux Lab nor the +* names of its contributors may be used to endorse or promote products +* derived from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "hw/hw.h" +#include "hw/boards.h" + +void cpu_save (QEMUFile *f,void *opaque) +{ +} + +int cpu_load (QEMUFile *f,void *opaque,int version_id) +{ +return 0 ; +}
target-xtensa/op_helper.c new file +51 -0
51 lines not on this page · raw message
target-xtensa/translate.c new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 2/26 target-xtensa: add target to the configure script
In reply to Max Filippov--- configure | 12 +++++++++++- default-configs/xtensa-softmmu.mak | 1 + default-configs/xtensaeb-softmmu.mak | 1 + 3 files changed, 13 insertions(+), 1 deletions(-) create mode 100644 default-configs/xtensa-softmmu.mak create mode 100644 default-configs/xtensaeb-softmmu.mak
configure +11 -1
@@ -848,6 +848,8 @@ sh4-softmmu \ sh4eb-softmmu \ sparc-softmmu \ sparc64-softmmu \ +xtensa-softmmu \ +xtensaeb-softmmu \ " fi # the following are Linux specific
@@ -3099,7 +3101,7 @@ target_arch2=`echo $target | cut -d '-' -f 1` target_bigendian="no" case "$target_arch2" in - armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus) + armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb) target_bigendian=yes ;; esac
@@ -3294,6 +3296,10 @@ case "$target_arch2" in unicore32) target_phys_bits=32 ;; + xtensa|xtensaeb) + TARGET_ARCH=xtensa + target_phys_bits=32 + ;; *) echo "Unsupported target CPU" exit 1
@@ -3476,6 +3482,10 @@ for i in $ARCH $TARGET_BASE_ARCH ; do echo "CONFIG_SPARC_DIS=y" >> $config_target_mak echo "CONFIG_SPARC_DIS=y" >> $libdis_config_mak ;; + xtensa*) + echo "CONFIG_XTENSA_DIS=y" >> $config_target_mak + echo "CONFIG_XTENSA_DIS=y" >> $libdis_config_mak + ;; esac done
default-configs/xtensa-softmmu.mak new file +1 -0
@@ -0,0 +1 @@ +# Default configuration for Xtensa
default-configs/xtensaeb-softmmu.mak new file +1 -0
@@ -0,0 +1 @@ +# Default configuration for Xtensa
Signature · 1 line
1.7.3.4
PATCH 3/26 target-xtensa: implement disas_xtensa_insn
In reply to Max FilippovSet up disas_xtensa_insn switch structure, mark required options on high level groups. Implement arithmetic/bit logic/jump/call0.
Implement code generation loop with single step/breakpoint checking.
---
RFC -> PATCH changes:
- put gen_exit_tb into else clause in gen_jump;
--- target-xtensa/cpu.h | 65 +++++++ target-xtensa/helper.c | 27 +++- target-xtensa/helpers.h | 5 + target-xtensa/op_helper.c | 7 + target-xtensa/translate.c | 445 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 547 insertions(+), 2 deletions(-) create mode 100644 target-xtensa/helpers.h
target-xtensa/cpu.h +65 -0
@@ -45,7 +45,67 @@#define TARGET_VIRT_ADDR_SPACE_BITS 32#define TARGET_PAGE_BITS 12 +enum { +/* Additional instructions */ +XTENSA_OPTION_CODE_DENSITY , +XTENSA_OPTION_LOOP , +XTENSA_OPTION_EXTENDED_L32R , +XTENSA_OPTION_16_BIT_IMUL , +XTENSA_OPTION_32_BIT_IMUL , +XTENSA_OPTION_32_BIT_IDIV , +XTENSA_OPTION_MAC16 , +XTENSA_OPTION_MISC_OP , +XTENSA_OPTION_COPROCESSOR , +XTENSA_OPTION_BOOLEAN , +XTENSA_OPTION_FP_COPROCESSOR , +XTENSA_OPTION_MP_SYNCHRO , +XTENSA_OPTION_CONDITIONAL_STORE , + +/* Interrupts and exceptions */ +XTENSA_OPTION_EXCEPTION , +XTENSA_OPTION_RELOCATABLE_VECTOR , +XTENSA_OPTION_UNALIGNED_EXCEPTION , +XTENSA_OPTION_INTERRUPT , +XTENSA_OPTION_HIGH_PRIORITY_INTERRUPT , +XTENSA_OPTION_TIMER_INTERRUPT , + +/* Local memory */ +XTENSA_OPTION_ICACHE , +XTENSA_OPTION_ICACHE_TEST , +XTENSA_OPTION_ICACHE_INDEX_LOCK , +XTENSA_OPTION_DCACHE , +XTENSA_OPTION_DCACHE_TEST , +XTENSA_OPTION_DCACHE_INDEX_LOCK , +XTENSA_OPTION_IRAM , +XTENSA_OPTION_IROM , +XTENSA_OPTION_DRAM , +XTENSA_OPTION_DROM , +XTENSA_OPTION_XLMI , +XTENSA_OPTION_HW_ALIGNMENT , +XTENSA_OPTION_MEMORY_ECC_PARITY , + +/* Memory protection and translation */ +XTENSA_OPTION_REGION_PROTECTION , +XTENSA_OPTION_REGION_TRANSLATION , +XTENSA_OPTION_MMU , + +/* Other */ +XTENSA_OPTION_WINDOWED_REGISTER , +XTENSA_OPTION_PROCESSOR_INTERFACE , +XTENSA_OPTION_MISC_SR , +XTENSA_OPTION_THREAD_POINTER , +XTENSA_OPTION_PROCESSOR_ID , +XTENSA_OPTION_DEBUG , +XTENSA_OPTIN_TRACE_PORT , +}; + +typedef struct XtensaConfig { +const char *name; +uint64_t options; +}XtensaConfig ; + typedef struct CPUXtensaState { + const XtensaConfig *config; uint32_t regs[16]; uint32_t pc; uint32_t sregs[256];
@@ -66,6 +126,11 @@ void do_interrupt(CPUXtensaState *s);int cpu_xtensa_signal_handler (int host_signum,void *pinfo,void *puc);void xtensa_cpu_list (FILE *f,fprintf_function cpu_fprintf); +static inline int xtensa_option_enabled (const XtensaConfig *config,int opt) +{ +return (config->options & (((uint64_t )1 ) << (opt))) !=0 ; +} +static inline int cpu_mmu_index (CPUState *env) {return 0 ;
target-xtensa/helper.c +25 -2
@@ -39,12 +39,32 @@ void cpu_reset(CPUXtensaState *env) env->pc =0 ; } +static const XtensaConfig core_config[] = { + { + .name ="sample-xtensa-core" , + .options =-1 , + }, +}; +CPUXtensaState *cpu_xtensa_init (const char *cpu_model) {static int tcg_inited;CPUXtensaState *env; +const XtensaConfig *config =NULL ; +int i; + +for (i =0 ; i <ARRAY_SIZE (core_config); ++i) +if (strcmp (core_config[i].name, cpu_model) ==0 ) { + config = core_config + i; +break ; + } + +if (config ==NULL ) { +return NULL ; + } env =qemu_mallocz (sizeof (*env)); + env->config = config;cpu_exec_init (env);if (!tcg_inited) {
@@ -59,8 +79,11 @@ CPUXtensaState *cpu_xtensa_init(const char *cpu_model)void xtensa_cpu_list (FILE *f,fprintf_function cpu_fprintf) { -cpu_fprintf (f,"Available CPUs:\n" -" Xtensa core\n" ); +int i; +cpu_fprintf (f,"Available CPUs:\n" ); +for (i =0 ; i <ARRAY_SIZE (core_config); ++i) { +cpu_fprintf (f," %s\n" , core_config[i].name); + } }target_phys_addr_t cpu_get_phys_page_debug (CPUState *env,target_ulong addr)
target-xtensa/helpers.h new file +5 -0
@@ -0,0 +1,5 @@ +#include "def-helper.h" + +DEF_HELPER_1(exception, void, i32) + +#include "def-helper.h"
target-xtensa/op_helper.c +7 -0
@@ -26,6 +26,7 @@*/ #include "exec.h" +#include "helpers.h" #define MMUSUFFIX _mmu
@@ -49,3 +50,9 @@ void tlb_fill(target_ulong addr, int is_write, int mmu_idx, void *retaddr)PAGE_READ |PAGE_WRITE |PAGE_EXEC , mmu_idx, TARGET_PAGE_SIZE); } + +void HELPER (exception )(uint32_t excp) +{ + env->exception_index = excp; +cpu_loop_exit (); +}
target-xtensa/translate.c +445 -0
462 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 4/26 target-xtensa: implement narrow instructions
In reply to Max FilippovInstructions with op0 >= 8 are 2 bytes long, others are 3 bytes long.
--- target-xtensa/translate.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 54 insertions(+), 0 deletions(-)
target-xtensa/translate.c +54 -0
@@ -104,6 +104,11 @@ static void gen_jump_slot(DisasContext *dc, TCGv dest, int slot) dc->is_jmp =DISAS_UPDATE ; } +static void gen_jump (DisasContext *dc,TCGv dest) +{ +gen_jump_slot (dc, dest,-1 ); +} +static void gen_jumpi (DisasContext *dc,uint32_t dest,int slot) {TCGv_i32 tmp =tcg_const_i32 (dest);
@@ -375,22 +380,71 @@ static void disas_xtensa_insn(DisasContext *dc)case 7 :/*B*/ break ; +#define gen_narrow_load_store (type) do { \ + TCGv_i32 addr = tcg_temp_new_i32(); \ + tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \ + tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, 0); \ + tcg_temp_free(addr); \ + } while (0) +case 8 :/*L32I.Nn*/ +gen_narrow_load_store (ld32u);break ;case 9 :/*S32I.Nn*/ +gen_narrow_load_store (st32);break ; +#undef gen_narrow_load_storecase 10 :/*ADD.Nn*/ +tcg_gen_add_i32 (cpu_R[RRRN_R ], cpu_R[RRRN_S ], cpu_R[RRRN_T ]);break ;case 11 :/*ADDI.Nn*/ +tcg_gen_addi_i32 (cpu_R[RRRN_R ], cpu_R[RRRN_S ],RRRN_T ?RRRN_T :-1 );break ;case 12 :/*ST2n*/ +if (RRRN_T <8 ) {/*MOVI.Nn*/ +tcg_gen_movi_i32 (cpu_R[RRRN_S ], +RRRN_R | (RRRN_T <<4 ) | + ((RRRN_T &6 ) ==6 ?0xffffff80 :0 )); + }else {/*BEQZ.Nn*/ /*BNEZ.Nn*/ + }break ;case 13 :/*ST3n*/ +switch (RRRN_R ) { +case 0 :/*MOV.Nn*/ +tcg_gen_mov_i32 (cpu_R[RRRN_T ], cpu_R[RRRN_S ]); +break ; + +case 15 :/*S3*/ +switch (RRRN_T ) { +case 0 :/*RET.Nn*/ +gen_jump (dc, cpu_R[0 ]); +break ; + +case 1 :/*RETW.Nn*/ +break ; + +case 2 :/*BREAK.Nn*/ +break ; + +case 3 :/*NOP.Nn*/ +break ; + +case 6 :/*ILL.Nn*/ +break ; + +default :/*reserved*/ +break ; + } +break ; + +default :/*reserved*/ +break ; + }break ;default :/*reserved*/
Signature · 1 line
1.7.3.4
PATCH 5/26 target-xtensa: implement RT0 group
In reply to Max FilippovNEG and ABS are the only members of RT0 group.
--- target-xtensa/translate.c | 19 +++++++++++++++++++ 1 files changed, 19 insertions(+), 0 deletions(-)
target-xtensa/translate.c +19 -0
@@ -253,6 +253,25 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 6 :/*RT0*/ +switch (RRR_S ) { +case 0 :/*NEG*/ +tcg_gen_neg_i32 (cpu_R[RRR_R ], cpu_R[RRR_T ]); +break ; + +case 1 :/*ABS*/ + { +int label =gen_new_label (); +tcg_gen_mov_i32 (cpu_R[RRR_R ], cpu_R[RRR_T ]); +tcg_gen_brcondi_i32 ( +TCG_COND_GE , cpu_R[RRR_R ],0 , label); +tcg_gen_neg_i32 (cpu_R[RRR_R ], cpu_R[RRR_T ]); +gen_set_label (label); + } +break ; + +default :/*reserved*/ +break ; + }break ;case 7 :/*reserved*/
Signature · 1 line
1.7.3.4
PATCH 6/26 target-xtensa: add sample board
In reply to Max FilippovSample board and sample CPU core are used for debug and may be used for development of custom SoC emulators.
This board has two fixed size memory regions for DTCM and ITCM and variable length SRAM region.
--- Makefile.target | 1 + hw/xtensa_sample.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 0 deletions(-) create mode 100644 hw/xtensa_sample.c
Makefile.target +1 -0
@@ -379,6 +379,7 @@ obj-s390x-y = s390-virtio-bus.o s390-virtio.o obj-alpha-y = alpha_palcode.o obj-xtensa-y += xtensa_pic.o +obj-xtensa-y += xtensa_sample.o main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
hw/xtensa_sample.c new file +99 -0
99 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 7/26 target-xtensa: implement conditional jumps
In reply to Max Filippov- BZ (comparison to zero);
- BI0 (comparison to signed immediate);
- BI1 (comparison to unsigned immediate);
- B (two registers comparison, bit sets comparison);
- BEQZ.N/BNEZ.N (narrow comparison to zero).
---
RFC -> PATCH changes:
- extract common branching code into functions;
--- target-xtensa/translate.c | 164 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 164 insertions(+), 0 deletions(-)
target-xtensa/translate.c +164 -0
@@ -119,6 +119,25 @@ static void gen_jumpi(DisasContext *dc, uint32_t dest, int slot)tcg_temp_free (tmp); } +static void gen_brcond (DisasContext *dc,TCGCond cond, +TCGv_i32 t0,TCGv_i32 t1,uint32_t offset) +{ +int label =gen_new_label (); + +tcg_gen_brcond_i32 (cond, t0, t1, label); +gen_jumpi (dc, dc->next_pc,0 ); +gen_set_label (label); +gen_jumpi (dc, dc->pc + offset,1 ); +} + +static void gen_brcondi (DisasContext *dc,TCGCond cond, +TCGv_i32 t0,uint32_t t1,uint32_t offset) +{ +TCGv_i32 tmp =tcg_const_i32 (t1); +gen_brcond (dc, cond, t0, tmp, offset); +tcg_temp_free (tmp); +} +static void disas_xtensa_insn (DisasContext *dc) {#define HAS_OPTION (opt) do { \
@@ -200,6 +219,14 @@ static void disas_xtensa_insn(DisasContext *dc)uint8_t _b1 =ldub_code (dc->pc +1 );uint8_t _b2 =ldub_code (dc->pc +2 ); +static const uint32_t B4CONST [] = { +0xffffffff ,1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,10 ,12 ,16 ,32 ,64 ,128 ,256 + }; + +static const uint32_t B4CONSTU [] = { +32768 ,65536 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,10 ,12 ,16 ,32 ,64 ,128 ,256 + }; +if (_OP0 >=8 ) { dc->next_pc = dc->pc +2 ;HAS_OPTION (XTENSA_OPTION_CODE_DENSITY );
@@ -393,10 +420,143 @@ static void disas_xtensa_insn(DisasContext *dc)gen_jumpi (dc, dc->pc +4 +CALL_OFFSET_SE ,0 );break ; +case 1 :/*BZ*/ + { +static const TCGCond cond[] = { +TCG_COND_EQ ,/*BEQZ*/ +TCG_COND_NE ,/*BNEZ*/ +TCG_COND_LT ,/*BLTZ*/ +TCG_COND_GE ,/*BGEZ*/ + }; + +gen_brcondi (dc, cond[BRI12_M &3 ], cpu_R[BRI12_S ],0 , +4 +BRI12_IMM12_SE ); + } +break ; + +case 2 :/*BI0*/ + { +static const TCGCond cond[] = { +TCG_COND_EQ ,/*BEQI*/ +TCG_COND_NE ,/*BNEI*/ +TCG_COND_LT ,/*BLTI*/ +TCG_COND_GE ,/*BGEI*/ + }; + +gen_brcondi (dc, cond[BRI8_M &3 ], + cpu_R[BRI8_S ],B4CONST [BRI8_R ],4 +BRI8_IMM8_SE ); + } +break ; + +case 3 :/*BI1*/ +switch (BRI8_M ) { +case 0 :/*ENTRYw*/ +HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +break ; + +case 1 :/*B1*/ +switch (BRI8_R ) { +case 0 :/*BFp*/ +HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +break ; + +case 1 :/*BTp*/ +HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +break ; + +case 8 :/*LOOP*/ +break ; + +case 9 :/*LOOPNEZ*/ +break ; + +case 10 :/*LOOPGTZ*/ +break ; + +default :/*reserved*/ +break ; + + } +break ; + +case 2 :/*BLTUI*/ +case 3 :/*BGEUI*/ +gen_brcondi (dc,BRI8_M ==2 ?TCG_COND_LTU :TCG_COND_GEU , + cpu_R[BRI8_S ],B4CONSTU [BRI8_R ],4 +BRI8_IMM8_SE ); +break ; + } +break ; + }break ;case 7 :/*B*/ + { +TCGCond eq_ne = (RRI8_R &8 ) ?TCG_COND_NE :TCG_COND_EQ ; + +switch (RRI8_R &7 ) { +case 0 :/*BNONE*/ /*BANY*/ + { +TCGv_i32 tmp =tcg_temp_new_i32 (); +tcg_gen_and_i32 (tmp, cpu_R[RRI8_S ], cpu_R[RRI8_T ]); +gen_brcondi (dc, eq_ne, tmp,0 ,4 +RRI8_IMM8_SE ); +tcg_temp_free (tmp); + } +break ; + +case 1 :/*BEQ*/ /*BNE*/ +case 2 :/*BLT*/ /*BGE*/ +case 3 :/*BLTU*/ /*BGEU*/ + { +static const TCGCond cond[] = { + [1 ] =TCG_COND_EQ , + [2 ] =TCG_COND_LT , + [3 ] =TCG_COND_LTU , + [9 ] =TCG_COND_NE , + [10 ] =TCG_COND_GE , + [11 ] =TCG_COND_GEU , + }; +gen_brcond (dc, cond[RRI8_R ], cpu_R[RRI8_S ], cpu_R[RRI8_T ], +4 +RRI8_IMM8_SE ); + } +break ; + +case 4 :/*BALL*/ /*BNALL*/ + { +TCGv_i32 tmp =tcg_temp_new_i32 (); +tcg_gen_and_i32 (tmp, cpu_R[RRI8_S ], cpu_R[RRI8_T ]); +gen_brcond (dc, eq_ne, tmp, cpu_R[RRI8_T ], +4 +RRI8_IMM8_SE ); +tcg_temp_free (tmp); + } +break ; + +case 5 :/*BBC*/ /*BBS*/ + { +TCGv_i32 bit =tcg_const_i32 (1 ); +TCGv_i32 tmp =tcg_temp_new_i32 (); +tcg_gen_andi_i32 (tmp, cpu_R[RRI8_T ],0x1f ); +tcg_gen_shl_i32 (bit, bit, tmp); +tcg_gen_and_i32 (tmp, cpu_R[RRI8_S ], bit); +gen_brcondi (dc, eq_ne, tmp,0 ,4 +RRI8_IMM8_SE ); +tcg_temp_free (tmp); +tcg_temp_free (bit); + } +break ; + +case 6 :/*BBCI*/ /*BBSI*/ +case 7 : + { +TCGv_i32 tmp =tcg_temp_new_i32 (); +tcg_gen_andi_i32 (tmp, cpu_R[RRI8_S ], +1 << (((RRI8_R &1 ) <<4 ) |RRI8_T )); +gen_brcondi (dc, eq_ne, tmp,0 ,4 +RRI8_IMM8_SE ); +tcg_temp_free (tmp); + } +break ; + + } + }break ;#define gen_narrow_load_store (type) do { \
@@ -429,6 +589,10 @@ static void disas_xtensa_insn(DisasContext *dc)RRRN_R | (RRRN_T <<4 ) | ((RRRN_T & 6) == 6 ? 0xffffff80 : 0)); }else {/*BEQZ.Nn*/ /*BNEZ.Nn*/ +TCGCond eq_ne = (RRRN_T &4 ) ?TCG_COND_NE :TCG_COND_EQ ; + +gen_brcondi (dc, eq_ne, cpu_R[RRRN_S ],0 , +4 + (RRRN_R | ((RRRN_T &3 ) <<4 ))); }break ;
Signature · 1 line
1.7.3.4
PATCH 8/26 target-xtensa: implement JX/RET0/CALLX
In reply to Max FilippovGroup SNM0 (indirect jumps and calls).
--- target-xtensa/translate.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 43 insertions(+), 0 deletions(-)
target-xtensa/translate.c +43 -0
@@ -246,6 +246,49 @@ static void disas_xtensa_insn(DisasContext *dc)switch (RRR_R ) {case 0 :/*SNM0*/ +switch (CALLX_M ) { +case 0 :/*ILL*/ +break ; + +case 1 :/*reserved*/ +break ; + +case 2 :/*JR*/ +switch (CALLX_N ) { +case 0 :/*RET*/ +case 2 :/*JX*/ +gen_jump (dc, cpu_R[CALLX_S ]); +break ; + +case 1 :/*RETWw*/ +HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +break ; + +case 3 :/*reserved*/ +break ; + } +break ; + +case 3 :/*CALLX*/ +switch (CALLX_N ) { +case 0 :/*CALLX0*/ + { +TCGv_i32 tmp =tcg_temp_new_i32 (); +tcg_gen_mov_i32 (tmp, cpu_R[CALLX_S ]); +tcg_gen_movi_i32 (cpu_R[0 ], dc->next_pc); +gen_jump (dc, tmp); +tcg_temp_free (tmp); + } +break ; + +case 1 :/*CALLX4w*/ +case 2 :/*CALLX8w*/ +case 3 :/*CALLX12w*/ +HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +break ; + } +break ; + }break ;case 1 :/*MOVSPw*/
Signature · 1 line
1.7.3.4
PATCH 9/26 target-xtensa: add special and user registers
In reply to Max FilippovSpecial Registers hold the majority of the state added to the processor by the options. See ISA, 5.3 for details.
User Registers hold state added in support of designer's TIE and in some cases of options that Tensilica provides. See ISA, 5.4 for details.
Only registers mapped in sregnames or uregnames are considered valid.
--- target-xtensa/cpu.h | 7 ++++++ target-xtensa/translate.c | 47 +++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-)
target-xtensa/cpu.h +7 -0
@@ -99,6 +99,12 @@ enum { XTENSA_OPTIN_TRACE_PORT, }; +enum { +THREADPTR =231 , +FCR =232 , +FSR =233 , +}; + typedef struct XtensaConfig { const char *name; uint64_t options;
@@ -109,6 +115,7 @@ typedef struct CPUXtensaState {uint32_t regs[16 ];uint32_t pc;uint32_t sregs[256 ]; +uint32_t uregs[256 ]; CPU_COMMON } CPUXtensaState;
target-xtensa/translate.c +45 -2
69 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Re: [Qemu-devel] [PATCH 09/26] target-xtensa: add special and user registers
Quoted 10 lines · Max Filippov
target-xtensa/cpu.h +6
-0+enum { +THREADPTR =231 , +FCR =232 , +FSR =233 , +}; + typedef struct XtensaConfig { const char *name; uint64_t options;
target-xtensa/cpu.h typedef struct CPUXtensaState { · line 118
Quoted 4 lines
target-xtensa/cpu.h +1
-0@@ -109,6 +115,7 @@ typedef struct CPUXtensaState {uint32_t regs[16 ];uint32_t pc;uint32_t sregs[256 ]; +uint32_t uregs[256 ];
Is it really worthwhile allocating 2k worth of space in the CPUState when only several of the slots are actually used?
I would think that it might be better to have a function to map between number to offset/register. E.g.
int ur_offset(int ur)
{
switch (ur) {
case THREADPTR:
return offsetof(CPUState, ur_threadptr);
case FCR:
return offsetof(CPUState, ur_fcr);
case FSR:
return offsetof(CPUState, ur_fsr);
}
return -1;
}where the individual slots are allocated by hand in the CPUState. The fact that they'll be named in the struct will also make it easier to dump the value inside gdb and see what the individual values are.
r~
Re: [Qemu-devel] [PATCH 09/26] target-xtensa: add special and user registers
Quoted 34 lines
Quoted 10 lines
target-xtensa/cpu.h +6
-0+enum { +THREADPTR =231 , +FCR =232 , +FSR =233 , +}; + typedef struct XtensaConfig { const char *name; uint64_t options;target-xtensa/cpu.h typedef struct CPUXtensaState { · line 118
Quoted 4 lines
target-xtensa/cpu.h +1
-0@@ -109,6 +115,7 @@ typedef struct CPUXtensaState {uint32_t regs[16 ];uint32_t pc;uint32_t sregs[256 ]; +uint32_t uregs[256 ];Is it really worthwhile allocating 2k worth of space in the CPUState when only several of the slots are actually used?
I would think that it might be better to have a function to map between number to offset/register. E.g.
int
ur_offset(int ur){ switch (ur) { case THREADPTR: return offsetof(CPUState, ur_threadptr); case FCR: return offsetof(CPUState, ur_fcr); case FSR: return offsetof(CPUState, ur_fsr); } return -1; }
Quoted 4 lines
where the individual slots are allocated by hand in the CPUState. The fact that they'll be named in the struct will also make it easier to dump the value inside gdb and see what the individual values are.
User registers represent TIE states that may appear in custom xtensa configurations. I'd better change RUR and WUR so that they can access all user registers but warn on those not defined globally or in the CPUEnv::config. Is it OK?
Thanks.
-- Max
Re: [Qemu-devel] [PATCH 09/26] target-xtensa: add special and user registers
Quoted 4 lines · Max Filippov
User registers represent TIE states that may appear in custom xtensa configurations. I'd better change RUR and WUR so that they can access all user registers but warn on those not defined globally or in the
CPUEnv::config. Is it OK?
Well, it's ok if you change nothing. However, I wanted you to think about other ways that might make sense than simply allocating all of the registers.
r~
PATCH 10/26 target-xtensa: implement RST3 group
In reply to Max Filippov- access to Special Registers (wsr, rsr);
- access to User Registers (wur, rur);
- misc. operations option (value clamp, sign extension, min, max);
- conditional moves.
---
RFC -> PATCH changes:
- optimize SEXT from bits 7 and 15;
--- target-xtensa/translate.c | 161 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 161 insertions(+), 0 deletions(-)
target-xtensa/translate.c +161 -0
@@ -165,6 +165,40 @@ static void gen_brcondi(DisasContext *dc, TCGCond cond,tcg_temp_free (tmp); } +static void gen_rsr (DisasContext *dc,TCGv_i32 d,uint32_t sr) +{ +static void (*const rsr_handler[256 ])(DisasContext *dc, +TCGv_i32 d,uint32_t sr) = { + }; + +if (sregnames[sr]) { +if (rsr_handler[sr]) { + rsr_handler[sr](dc, d, sr); + }else { +tcg_gen_mov_i32 (d, cpu_SR[sr]); + } + }else { +qemu_log ("RSR %d not implemented, " , sr); + } +} + +static void gen_wsr (DisasContext *dc,uint32_t sr,TCGv_i32 s) +{ +static void (*const wsr_handler[256 ])(DisasContext *dc, +uint32_t sr,TCGv_i32 v) = { + }; + +if (sregnames[sr]) { +if (wsr_handler[sr]) { + wsr_handler[sr](dc, sr, s); + }else { +tcg_gen_mov_i32 (cpu_SR[sr], s); + } + }else { +qemu_log ("WSR %d not implemented, " , sr); + } +} +static void disas_xtensa_insn (DisasContext *dc) {#define HAS_OPTION (opt) do { \
@@ -413,6 +447,133 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 3 :/*RST3*/ +switch (_OP2) { +case 0 :/*RSR*/ +gen_rsr (dc, cpu_R[RRR_T ],RSR_SR ); +break ; + +case 1 :/*WSR*/ +gen_wsr (dc,RSR_SR , cpu_R[RRR_T ]); +break ; + +case 2 :/*SEXTu*/ +HAS_OPTION (XTENSA_OPTION_MISC_OP ); + { +int shift =24 -RRR_T ; + +if (shift ==24 ) { +tcg_gen_ext8s_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ]); + }else if (shift ==16 ) { +tcg_gen_ext16s_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ]); + }else { +TCGv_i32 tmp =tcg_temp_new_i32 (); +tcg_gen_shli_i32 (tmp, cpu_R[RRR_S ], shift); +tcg_gen_sari_i32 (cpu_R[RRR_R ], tmp, shift); +tcg_temp_free (tmp); + } + } +break ; + +case 3 :/*CLAMPSu*/ +HAS_OPTION (XTENSA_OPTION_MISC_OP ); + { +TCGv_i32 tmp1 =tcg_temp_new_i32 (); +TCGv_i32 tmp2 =tcg_temp_new_i32 (); +int label =gen_new_label (); + +tcg_gen_sari_i32 (tmp1, cpu_R[RRR_S ],24 -RRR_T ); +tcg_gen_xor_i32 (tmp2, tmp1, cpu_R[RRR_S ]); +tcg_gen_andi_i32 (tmp2, tmp2,0xffffffff << (RRR_T +7 )); +tcg_gen_mov_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ]); +tcg_gen_brcondi_i32 (TCG_COND_EQ , tmp2,0 , label); + +tcg_gen_sari_i32 (tmp1, cpu_R[RRR_S ],31 ); +tcg_gen_xori_i32 (cpu_R[RRR_R ], tmp1, +0xffffffff >> (25 -RRR_T )); + +gen_set_label (label); + +tcg_temp_free (tmp1); +tcg_temp_free (tmp2); + } +break ; + +case 4 :/*MINu*/ +case 5 :/*MAXu*/ +case 6 :/*MINUu*/ +case 7 :/*MAXUu*/ +HAS_OPTION (XTENSA_OPTION_MISC_OP ); + { +static const TCGCond cond[] = { +TCG_COND_LE , +TCG_COND_GE , +TCG_COND_LEU , +TCG_COND_GEU + }; +int label =gen_new_label (); + +if (RRR_R !=RRR_T ) { +tcg_gen_mov_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ]); +tcg_gen_brcond_i32 (cond[_OP2 -4 ], + cpu_R[RRR_S ], cpu_R[RRR_T ], label); +tcg_gen_mov_i32 (cpu_R[RRR_R ], cpu_R[RRR_T ]); + }else { +tcg_gen_brcond_i32 (cond[_OP2 -4 ], + cpu_R[RRR_T ], cpu_R[RRR_S ], label); +tcg_gen_mov_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ]); + } +gen_set_label (label); + } +break ; + +case 8 :/*MOVEQZ*/ +case 9 :/*MOVNEZ*/ +case 10 :/*MOVLTZ*/ +case 11 :/*MOVGEZ*/ + { +static const TCGCond cond[] = { +TCG_COND_NE , +TCG_COND_EQ , +TCG_COND_GE , +TCG_COND_LT + }; +int label =gen_new_label (); +tcg_gen_brcondi_i32 (cond[_OP2 -8 ], cpu_R[RRR_T ],0 , label); +tcg_gen_mov_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ]); +gen_set_label (label); + } +break ; + +case 12 :/*MOVFp*/ +HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +break ; + +case 13 :/*MOVTp*/ +HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +break ; + +case 14 :/*RUR*/ + { +int st = (RRR_S <<4 ) +RRR_T ; +if (uregnames[st]) { +tcg_gen_mov_i32 (cpu_R[RRR_R ], cpu_UR[st]); + }else { +qemu_log ("RUR %d not implemented, " , st); + } + } +break ; + +case 15 :/*WUR*/ + { +if (uregnames[RSR_SR ]) { +tcg_gen_mov_i32 (cpu_UR[RSR_SR ], cpu_R[RRR_T ]); + }else { +qemu_log ("WUR %d not implemented, " ,RSR_SR ); + } + } +break ; + + }break ;case 4 :/*EXTUI*/
Signature · 1 line
1.7.3.4
PATCH 11/26 target-xtensa: implement shifts (ST1 and RST1 groups)
In reply to Max Filippov- ST1: SAR (shift amount special register) manipulation, NSA(U);
- RST1: shifts, 16-bit multiplication.
---
RFC -> PATCH changes:
- make NSA/NSAU helpers;
- optimize shifts for 5 bit wide SAR;
--- target-xtensa/cpu.h | 4 + target-xtensa/helpers.h | 2 + target-xtensa/op_helper.c | 14 +++ target-xtensa/translate.c | 237 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 257 insertions(+), 0 deletions(-)
target-xtensa/cpu.h +4 -0
@@ -105,6 +105,10 @@ enum { FSR = 233, }; +enum { +SAR =3 , +}; + typedef struct XtensaConfig { const char *name; uint64_t options;
target-xtensa/helpers.h +2 -0
@@ -1,5 +1,7 @@#include "def-helper.h" DEF_HELPER_1(exception, void, i32) +DEF_HELPER_1(nsa, i32, i32) +DEF_HELPER_1(nsau, i32, i32)#include "def-helper.h"
target-xtensa/op_helper.c +14 -0
@@ -27,6 +27,7 @@#include "exec.h" #include "helpers.h" +#include "host-utils.h" #define MMUSUFFIX _mmu
@@ -56,3 +57,16 @@ void HELPER(exception)(uint32_t excp) env->exception_index = excp;cpu_loop_exit (); } + +uint32_t HELPER (nsa )(uint32_t v) +{ +if (v &0x80000000 ) { + v = ~v; + } +return v ?31 :clz32 (v) -1 ; +} + +uint32_t HELPER (nsau )(uint32_t v) +{ +return v ?clz32 (v) :32 ; +}
target-xtensa/translate.c +237 -0
295 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Re: [Qemu-devel] [PATCH 11/26] target-xtensa: implement shifts (ST1 and RST1 groups)
target-xtensa/op_helper.c void HELPER(exception)(uint32_t excp) · line 66
Quoted 6 lines · Max Filippov
target-xtensa/op_helper.c +6
-0+uint32_t HELPER (nsa )(uint32_t v) +{ +if (v &0x80000000 ) { + v = ~v; + } +return v ?31 :clz32 (v) -1 ;
Condition is reversed here.
r~
PATCH 12/26 target-xtensa: implement LSAI group
In reply to Max Filippov- base + offset load/store operations for 1/2/4 byte values;
- cache operations (not implemented);
- multiprocessor synchronization operations.
--- target-xtensa/cpu.h | 1 + target-xtensa/translate.c | 88 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 0 deletions(-)
target-xtensa/cpu.h +1 -0
@@ -107,6 +107,7 @@ enum {enum {SAR =3 , +SCOMPARE1 =12 , }; typedef struct XtensaConfig {
target-xtensa/translate.c +88 -0
101 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 13/26 target-xtensa: mark reserved and TBD opcodes
In reply to Max FilippovReserved opcodes must generate illegal instruction exception. Usually they signal emulation quality problems.
Not implemented opcodes are good to see.
--- target-xtensa/translate.c | 110 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 109 insertions(+), 1 deletions(-)
target-xtensa/translate.c +109 -1
@@ -258,6 +258,14 @@ static void disas_xtensa_insn(DisasContext *dc) } \ } while (0) +#define TBD () qemu_log("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__) +#define RESERVED () do { \ + qemu_log("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \ + dc->pc, _b0, _b1, _b2, __FILE__, __LINE__); \ + goto invalid_opcode; \ + } while (0) + +#ifdef TARGET_WORDS_BIGENDIAN #define _OP0 (((_b0) & 0xf0) >> 4)#define _OP1 (((_b2) & 0xf0) >> 4)
@@ -358,9 +366,11 @@ static void disas_xtensa_insn(DisasContext *dc)case 0 :/*SNM0*/ switch (CALLX_M ) {case 0 :/*ILL*/ +TBD ();break ;case 1 :/*reserved*/ +RESERVED ();break ;case 2 :/*JR*/
@@ -372,9 +382,11 @@ static void disas_xtensa_insn(DisasContext *dc)case 1 :/*RETWw*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ;case 3 :/*reserved*/ +RESERVED ();break ; }break ;
@@ -395,6 +407,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*CALLX8w*/ case 3 :/*CALLX12w*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ; }break ;
@@ -403,12 +416,59 @@ static void disas_xtensa_insn(DisasContext *dc)case 1 :/*MOVSPw*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ;case 2 :/*SYNC*/ +TBD (); +break ; + +case 3 :/*RFEIx*/ +TBD (); +break ; + +case 4 :/*BREAKx*/ +HAS_OPTION (XTENSA_OPTION_EXCEPTION ); +TBD (); +break ; + +case 5 :/*SYSCALLx*/ +HAS_OPTION (XTENSA_OPTION_EXCEPTION ); +TBD (); +break ; + +case 6 :/*RSILx*/ +HAS_OPTION (XTENSA_OPTION_INTERRUPT ); +TBD (); +break ; + +case 7 :/*WAITIx*/ +HAS_OPTION (XTENSA_OPTION_INTERRUPT ); +TBD (); +break ; + +case 8 :/*ANY4p*/ +HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +TBD (); +break ; + +case 9 :/*ALL4p*/ +HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +TBD ();break ; -case 3 : +case 10 :/*ANY8p*/ +HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +TBD (); +break ; + +case 11 :/*ALL8p*/ +HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +TBD (); +break ; + +default :/*reserved*/ +RESERVED ();break ; }
@@ -464,13 +524,16 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 6 :/*RER*/ +TBD ();break ;case 7 :/*WER*/ +TBD ();break ;case 8 :/*ROTWw*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ;case 14 :/*NSAu*/
@@ -484,11 +547,13 @@ static void disas_xtensa_insn(DisasContext *dc)break ;default :/*reserved*/ +RESERVED ();break ; }break ;case 5 :/*TLB*/ +TBD ();break ;case 6 :/*RT0*/
@@ -509,11 +574,13 @@ static void disas_xtensa_insn(DisasContext *dc)break ;default :/*reserved*/ +RESERVED ();break ; }break ;case 7 :/*reserved*/ +RESERVED ();break ;case 8 :/*ADD*/
@@ -573,6 +640,9 @@ static void disas_xtensa_insn(DisasContext *dc)gen_rsr (dc, cpu_R[RRR_T ],RSR_SR );gen_wsr (dc,RSR_SR , tmp);tcg_temp_free (tmp); +if (!sregnames[RSR_SR ]) { +TBD (); + } }break ;
@@ -662,21 +732,29 @@ static void disas_xtensa_insn(DisasContext *dc)break ;default :/*reserved*/ +RESERVED ();break ; }break ;case 2 :/*RST2*/ +TBD ();break ;case 3 :/*RST3*/ switch (_OP2) {case 0 :/*RSR*/ gen_rsr (dc, cpu_R[RRR_T ],RSR_SR ); +if (!sregnames[RSR_SR ]) { +TBD (); + }break ;case 1 :/*WSR*/ gen_wsr (dc,RSR_SR , cpu_R[RRR_T ]); +if (!sregnames[RSR_SR ]) { +TBD (); + }break ;case 2 :/*SEXTu*/
@@ -769,10 +847,12 @@ static void disas_xtensa_insn(DisasContext *dc)case 12 :/*MOVFp*/ HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +TBD ();break ;case 13 :/*MOVTp*/ HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +TBD ();break ;case 14 :/*RUR*/
@@ -782,6 +862,7 @@ static void disas_xtensa_insn(DisasContext *dc)tcg_gen_mov_i32 (cpu_R[RRR_R ], cpu_UR[st]); }else {qemu_log ("RUR %d not implemented, " , st); +TBD (); } }break ;
@@ -792,6 +873,7 @@ static void disas_xtensa_insn(DisasContext *dc)tcg_gen_mov_i32 (cpu_UR[RSR_SR ], cpu_R[RRR_T ]); }else {qemu_log ("WUR %d not implemented, " ,RSR_SR ); +TBD (); } }break ;
@@ -813,27 +895,34 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 6 :/*CUST0*/ +RESERVED ();break ;case 7 :/*CUST1*/ +RESERVED ();break ;case 8 :/*LSCXp*/ HAS_OPTION (XTENSA_OPTION_COPROCESSOR ); +TBD ();break ;case 9 :/*LSC4*/ +TBD ();break ;case 10 :/*FP0*/ HAS_OPTION (XTENSA_OPTION_FP_COPROCESSOR ); +TBD ();break ;case 11 :/*FP1*/ HAS_OPTION (XTENSA_OPTION_FP_COPROCESSOR ); +TBD ();break ;default :/*reserved*/ +RESERVED ();break ; }break ;
@@ -885,6 +974,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 7 :/*CACHEc*/ +TBD ();break ;case 9 :/*L16SI*/
@@ -936,6 +1026,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;default :/*reserved*/ +RESERVED ();break ; }break ;
@@ -943,10 +1034,12 @@ static void disas_xtensa_insn(DisasContext *dc)case 3 :/*LSCIp*/ HAS_OPTION (XTENSA_OPTION_COPROCESSOR ); +TBD ();break ;case 4 :/*MAC16d*/ HAS_OPTION (XTENSA_OPTION_MAC16 ); +TBD ();break ;case 5 :/*CALLN*/
@@ -960,6 +1053,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*CALL8w*/ case 3 :/*CALL12w*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ; }break ;
@@ -1002,28 +1096,35 @@ static void disas_xtensa_insn(DisasContext *dc)switch (BRI8_M ) {case 0 :/*ENTRYw*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ;case 1 :/*B1*/ switch (BRI8_R ) {case 0 :/*BFp*/ HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +TBD ();break ;case 1 :/*BTp*/ HAS_OPTION (XTENSA_OPTION_BOOLEAN ); +TBD ();break ;case 8 :/*LOOP*/ +TBD ();break ;case 9 :/*LOOPNEZ*/ +TBD ();break ;case 10 :/*LOOPGTZ*/ +TBD ();break ;default :/*reserved*/ +RESERVED ();break ; }
@@ -1159,28 +1260,35 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 1 :/*RETW.Nn*/ +HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ;case 2 :/*BREAK.Nn*/ +TBD ();break ;case 3 :/*NOP.Nn*/ break ;case 6 :/*ILL.Nn*/ +TBD ();break ;default :/*reserved*/ +RESERVED ();break ; }break ;default :/*reserved*/ +RESERVED ();break ; }break ;default :/*reserved*/ +RESERVED ();break ; }
Signature · 1 line
1.7.3.4
PATCH 14/26 target-xtensa: implement SYNC group
In reply to Max FilippovAll operations in this group are no-ops, because there are no delayed side effects.
--- target-xtensa/translate.c | 31 ++++++++++++++++++++++++++++++- 1 files changed, 30 insertions(+), 1 deletions(-)
target-xtensa/translate.c +30 -1
@@ -420,7 +420,36 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 2 :/*SYNC*/ -TBD (); +switch (RRR_T ) { +case 0 :/*ISYNC*/ +break ; + +case 1 :/*RSYNC*/ +break ; + +case 2 :/*ESYNC*/ +break ; + +case 3 :/*DSYNC*/ +break ; + +case 8 :/*EXCW*/ +HAS_OPTION (XTENSA_OPTION_EXCEPTION ); +break ; + +case 12 :/*MEMW*/ +break ; + +case 13 :/*EXTW*/ +break ; + +case 15 :/*NOP*/ +break ; + +default :/*reserved*/ +RESERVED (); +break ; + }break ;case 3 :/*RFEIx*/
Signature · 1 line
1.7.3.4
PATCH 15/26 target-xtensa: implement CACHE group
In reply to Max FilippovAll operations in this group are no-ops, because cache ought to be transparent to applications. However cache may be abused, then we'll need to actually implement these opcodes.
--- target-xtensa/translate.c | 95 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 94 insertions(+), 1 deletions(-)
target-xtensa/translate.c +94 -1
@@ -1003,7 +1003,100 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 7 :/*CACHEc*/ -TBD (); +if (RRI8_T <8 ) { +HAS_OPTION (XTENSA_OPTION_DCACHE ); + } + +switch (RRI8_T ) { +case 0 :/*DPFRc*/ +break ; + +case 1 :/*DPFWc*/ +break ; + +case 2 :/*DPFROc*/ +break ; + +case 3 :/*DPFWOc*/ +break ; + +case 4 :/*DHWBc*/ +break ; + +case 5 :/*DHWBIc*/ +break ; + +case 6 :/*DHIc*/ +break ; + +case 7 :/*DIIc*/ +break ; + +case 8 :/*DCEc*/ +switch (_OP1) { +case 0 :/*DPFLl*/ +HAS_OPTION (XTENSA_OPTION_DCACHE_INDEX_LOCK ); +break ; + +case 2 :/*DHUl*/ +HAS_OPTION (XTENSA_OPTION_DCACHE_INDEX_LOCK ); +break ; + +case 3 :/*DIUl*/ +HAS_OPTION (XTENSA_OPTION_DCACHE_INDEX_LOCK ); +break ; + +case 4 :/*DIWBc*/ +HAS_OPTION (XTENSA_OPTION_DCACHE ); +break ; + +case 5 :/*DIWBIc*/ +HAS_OPTION (XTENSA_OPTION_DCACHE ); +break ; + +default :/*reserved*/ +RESERVED (); +break ; + + } +break ; + +case 12 :/*IPFc*/ +HAS_OPTION (XTENSA_OPTION_ICACHE ); +break ; + +case 13 :/*ICEc*/ +switch (_OP1) { +case 0 :/*IPFLl*/ +HAS_OPTION (XTENSA_OPTION_ICACHE_INDEX_LOCK ); +break ; + +case 2 :/*IHUl*/ +HAS_OPTION (XTENSA_OPTION_ICACHE_INDEX_LOCK ); +break ; + +case 3 :/*IIUl*/ +HAS_OPTION (XTENSA_OPTION_ICACHE_INDEX_LOCK ); +break ; + +default :/*reserved*/ +RESERVED (); +break ; + } +break ; + +case 14 :/*IHIc*/ +HAS_OPTION (XTENSA_OPTION_ICACHE ); +break ; + +case 15 :/*IIIc*/ +HAS_OPTION (XTENSA_OPTION_ICACHE ); +break ; + +default :/*reserved*/ +RESERVED (); +break ; + }break ;case 9 :/*L16SI*/
Signature · 1 line
1.7.3.4
PATCH 16/26 target-xtensa: implement exceptions
In reply to Max Filippov- mark privileged opcodes with ring check;
- make debug exception on exception handler entry.
---
RFC -> PATCH changes:
- make privilege_check based on mem_index;
--- cpu-exec.c | 6 +++ target-xtensa/cpu.h | 103 +++++++++++++++++++++++++++++++++++++++++- target-xtensa/helper.c | 39 +++++++++++++++- target-xtensa/helpers.h | 2 + target-xtensa/op_helper.c | 29 ++++++++++++ target-xtensa/translate.c | 110 ++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 282 insertions(+), 7 deletions(-)
cpu-exec.c +6 -0
@@ -565,6 +565,12 @@ int cpu_exec(CPUState *env1)do_interrupt (env); next_tb = 0; } +#elif defined(TARGET_XTENSA) +if (interrupt_request &CPU_INTERRUPT_HARD ) { + env->exception_index =EXC_IRQ ; +do_interrupt (env); + next_tb =0 ; + }#endif /* Don't use the cached interrupt_request value, do_interrupt may have updated the EXITTB flag. */
target-xtensa/cpu.h +102 -1
128 lines not on this page · raw message
target-xtensa/helper.c +38 -1
@@ -36,13 +36,29 @@void cpu_reset (CPUXtensaState *env) { - env->pc =0 ; + env->exception_taken =0 ; + env->pc = env->config->exception_vector[EXC_RESET ]; + env->sregs[PS ] =0x1f ; }static const XtensaConfig core_config[] = { { .name ="sample-xtensa-core" , .options =-1 , + .ndepc =1 , + .excm_level =16 , + .exception_vector = { + [EXC_RESET ] =0x5fff8000 , + [EXC_WINDOW_OVERFLOW4 ] =0x5fff8400 , + [EXC_WINDOW_UNDERFLOW4 ] =0x5fff8440 , + [EXC_WINDOW_OVERFLOW8 ] =0x5fff8480 , + [EXC_WINDOW_UNDERFLOW8 ] =0x5fff84c0 , + [EXC_WINDOW_OVERFLOW12 ] =0x5fff8500 , + [EXC_WINDOW_UNDERFLOW12 ] =0x5fff8540 , + [EXC_KERNEL ] =0x5fff861c , + [EXC_USER ] =0x5fff863c , + [EXC_DOUBLE ] =0x5fff865c , + }, }, };
@@ -93,4 +109,25 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)void do_interrupt (CPUState *env) { +switch (env->exception_index) { +case EXC_WINDOW_OVERFLOW4 : +case EXC_WINDOW_UNDERFLOW4 : +case EXC_WINDOW_OVERFLOW8 : +case EXC_WINDOW_UNDERFLOW8 : +case EXC_WINDOW_OVERFLOW12 : +case EXC_WINDOW_UNDERFLOW12 : +case EXC_KERNEL : +case EXC_USER : +case EXC_DOUBLE : +if (env->config->exception_vector[env->exception_index]) { + env->pc = env->config->exception_vector[env->exception_index]; + env->exception_taken =1 ; + }else { +qemu_log ("%s(pc = %08x) bad exception_index: %d\n" , + __func__, env->pc, env->exception_index); + } +break ; + + } + env->interrupt_request |=CPU_INTERRUPT_EXITTB ; }
target-xtensa/helpers.h +2 -0
@@ -1,6 +1,8 @@#include "def-helper.h" DEF_HELPER_1(exception, void, i32) +DEF_HELPER_2(exception_cause, void, i32, i32) +DEF_HELPER_3(exception_cause_vaddr, void, i32, i32, i32) DEF_HELPER_1(nsa, i32, i32)DEF_HELPER_1 (nsau, i32, i32)
target-xtensa/op_helper.c +29 -0
@@ -58,6 +58,35 @@ void HELPER(exception)(uint32_t excp)cpu_loop_exit (); } +void HELPER (exception_cause )(uint32_t pc,uint32_t cause) +{ +uint32_t vector; + + env->pc = pc; +if (env->sregs[PS ] &PS_EXCM ) { +if (env->config->ndepc) { + env->sregs[DEPC ] = pc; + }else { + env->sregs[EPC1 ] = pc; + } + vector =EXC_DOUBLE ; + }else { + env->sregs[EPC1 ] = pc; + vector = (env->sregs[PS ] &PS_UM ) ?EXC_USER :EXC_KERNEL ; + } + + env->sregs[EXCCAUSE ] = cause; + env->sregs[PS ] |=PS_EXCM ; + +HELPER (exception)(vector); +} + +void HELPER (exception_cause_vaddr )(uint32_t pc,uint32_t cause,uint32_t vaddr) +{ + env->sregs[EXCVADDR ] = vaddr; +HELPER (exception_cause)(pc, cause); +} +uint32_t HELPER (nsa )(uint32_t v) {if (v &0x80000000 ) {
target-xtensa/translate.c +105 -5
186 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 17/26 target-xtensa: implement RST2 group (32 bit mul/div/rem)
In reply to Max Filippov--- target-xtensa/translate.c | 60 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 59 insertions(+), 1 deletions(-)
target-xtensa/translate.c +59 -1
@@ -854,7 +854,65 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 2 :/*RST2*/ -TBD (); +if (_OP2 >=12 ) { +HAS_OPTION (XTENSA_OPTION_32_BIT_IDIV ); +int label =gen_new_label (); +tcg_gen_brcondi_i32 (TCG_COND_NE , cpu_R[RRR_T ],0 , label); +gen_exception_cause (dc,INTEGER_DIVIDE_BY_ZERO_CAUSE ); +gen_set_label (label); + } + +switch (_OP2) { +case 8 :/*MULLi*/ +HAS_OPTION (XTENSA_OPTION_32_BIT_IMUL ); +tcg_gen_mul_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], cpu_R[RRR_T ]); +break ; + +case 10 :/*MULUHi*/ +case 11 :/*MULSHi*/ +HAS_OPTION (XTENSA_OPTION_32_BIT_IMUL ); + { +TCGv_i64 r =tcg_temp_new_i64 (); +TCGv_i64 s =tcg_temp_new_i64 (); +TCGv_i64 t =tcg_temp_new_i64 (); + +if (_OP2 ==10 ) { +tcg_gen_extu_i32_i64 (s, cpu_R[RRR_S ]); +tcg_gen_extu_i32_i64 (t, cpu_R[RRR_T ]); + }else { +tcg_gen_ext_i32_i64 (s, cpu_R[RRR_S ]); +tcg_gen_ext_i32_i64 (t, cpu_R[RRR_T ]); + } +tcg_gen_mul_i64 (r, s, t); +tcg_gen_shri_i64 (r, r,32 ); +tcg_gen_trunc_i64_i32 (cpu_R[RRR_R ], r); + +tcg_temp_free_i64 (r); +tcg_temp_free_i64 (s); +tcg_temp_free_i64 (t); + } +break ; + +case 12 :/*QUOUi*/ +tcg_gen_divu_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], cpu_R[RRR_T ]); +break ; + +case 13 :/*QUOSi*/ +tcg_gen_div_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], cpu_R[RRR_T ]); +break ; + +case 14 :/*REMUi*/ +tcg_gen_remu_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], cpu_R[RRR_T ]); +break ; + +case 15 :/*REMSi*/ +tcg_gen_rem_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], cpu_R[RRR_T ]); +break ; + +default :/*reserved*/ +RESERVED (); +break ; + }break ;case 3 :/*RST3*/
Signature · 1 line
1.7.3.4
PATCH 18/26 target-xtensa: implement windowed registers
In reply to Max FilippovSee ISA, 4.7.1 for details.
Physical registers and currently visible window are separate fields in CPUEnv. Only current window is accessible to TCG. On operations that change window base helpers copy current window to and from physical registers.
Window overflow check described in 4.7.1.3 is in separate patch.
--- target-xtensa/cpu.h | 8 ++ target-xtensa/helper.c | 1 + target-xtensa/helpers.h | 8 ++ target-xtensa/op_helper.c | 185 +++++++++++++++++++++++++++++++++++++++++++++ target-xtensa/translate.c | 146 +++++++++++++++++++++++++++++++++-- 5 files changed, 339 insertions(+), 9 deletions(-)
target-xtensa/cpu.h +8 -0
@@ -108,6 +108,8 @@ enum {enum {SAR =3 ,SCOMPARE1 =12 , +WINDOW_BASE =72 , +WINDOW_START =73 ,EPC1 =177 ,DEPC =192 ,EXCSAVE1 =209 ,
@@ -134,6 +136,8 @@ enum {#define PS_WOE 0x40000 +#define MAX_NAREG 64 +enum {/* Static vectors */ EXC_RESET ,
@@ -185,6 +189,7 @@ enum { typedef struct XtensaConfig { const char *name; uint64_t options; + unsigned nareg; int excm_level; int ndepc; uint32_t exception_vector[EXC_MAX];
@@ -196,6 +201,7 @@ typedef struct CPUXtensaState {uint32_t pc;uint32_t sregs[256 ];uint32_t uregs[256 ]; +uint32_t phys_regs[MAX_NAREG ];int exception_taken;
@@ -214,6 +220,8 @@ int cpu_xtensa_exec(CPUXtensaState *s);void do_interrupt (CPUXtensaState *s);int cpu_xtensa_signal_handler (int host_signum,void *pinfo,void *puc);void xtensa_cpu_list (FILE *f,fprintf_function cpu_fprintf); +void xtensa_sync_window_from_phys (CPUState *env); +void xtensa_sync_phys_from_window (CPUState *env);static inline int xtensa_option_enabled (const XtensaConfig *config,int opt) {
target-xtensa/helper.c +1 -0
@@ -45,6 +45,7 @@ static const XtensaConfig core_config[] = { { .name = "sample-xtensa-core", .options = -1, + .nareg = 64, .ndepc = 1, .excm_level = 16, .exception_vector = {
target-xtensa/helpers.h +8 -0
@@ -5,5 +5,13 @@ DEF_HELPER_2(exception_cause, void, i32, i32) DEF_HELPER_3(exception_cause_vaddr, void, i32, i32, i32) DEF_HELPER_1(nsa, i32, i32) DEF_HELPER_1(nsau, i32, i32) +DEF_HELPER_1(wsr_windowbase, void, i32) +DEF_HELPER_3(entry, void, i32, i32, i32) +DEF_HELPER_1(retw, i32, i32) +DEF_HELPER_1(rotw, void, i32) +DEF_HELPER_2(window_check, void, i32, i32) +DEF_HELPER_0(restore_owb, void) +DEF_HELPER_1(movsp, void, i32) +DEF_HELPER_0(dump_state, void)#include "def-helper.h"
target-xtensa/op_helper.c +185 -0
188 lines not on this page · raw message
target-xtensa/translate.c +137 -9
229 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH 19/26 target-xtensa: implement loop option
In reply to Max FilippovSee ISA, 4.3.2 for details.
Operations that change LEND SR value invalidate TBs at the old and at the new LEND. LEND value at TB compilation time is considered constant and loop instruction is generated based on this value.
Invalidation may be avoided for the TB at the old LEND address, since looping code verifies actual LEND value.
Invalidation may be avoided for the TB at the new LEND address if there's a way to associate LEND address with TB at compilation time and later verify that it doesn't change.
---
RFC -> PATCH changes:
- add XTENSA_TBFLAG_EXCM, use it in loop ending check;
--- target-xtensa/cpu.h | 8 +++++ target-xtensa/helpers.h | 1 + target-xtensa/op_helper.c | 11 +++++++ target-xtensa/translate.c | 65 +++++++++++++++++++++++++++++++++++++++----- 4 files changed, 77 insertions(+), 8 deletions(-)
target-xtensa/cpu.h +8 -0
@@ -106,6 +106,9 @@ enum { };enum { +LBEG =0 , +LEND =1 , +LCOUNT =2 ,SAR =3 ,SCOMPARE1 =12 ,WINDOW_BASE =72 ,
@@ -257,12 +260,17 @@ static inline int cpu_mmu_index(CPUState *env)return xtensa_get_cring (env) !=0 ; } +#define XTENSA_TBFLAG_EXCM 0x1 +static inline void cpu_get_tb_cpu_state (CPUState *env,target_ulong *pc,target_ulong *cs_base,int *flags) { *pc = env->pc; *cs_base =0 ; *flags =0 ; +if (env->sregs[PS ] &PS_EXCM ) { + *flags |=XTENSA_TBFLAG_EXCM ; + } }#include "cpu-all.h"
target-xtensa/helpers.h +1 -0
@@ -12,6 +12,7 @@ DEF_HELPER_1(rotw, void, i32) DEF_HELPER_2(window_check, void, i32, i32) DEF_HELPER_0(restore_owb, void) DEF_HELPER_1(movsp, void, i32) +DEF_HELPER_1(wsr_lend, void, i32) DEF_HELPER_0(dump_state, void)#include "def-helper.h"
target-xtensa/op_helper.c +11 -0
@@ -280,6 +280,17 @@ void HELPER(movsp)(uint32_t pc) } } +void HELPER (wsr_lend )(uint32_t v) +{ +if (env->sregs[LEND ] != v) { +tb_invalidate_phys_page_range ( + env->sregs[LEND ] -1 , env->sregs[LEND ],0 ); + env->sregs[LEND ] = v; +tb_invalidate_phys_page_range ( + env->sregs[LEND ] -1 , env->sregs[LEND ],0 ); + } +} +void HELPER (dump_state )(void ) {cpu_dump_state (env, stderr, fprintf,0 );
target-xtensa/translate.c +57 -8
122 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Re: [Qemu-devel] [PATCH 19/26] target-xtensa: implement loop option
target-xtensa/op_helper.c void HELPER(movsp)(uint32_t pc) · line 291
Quoted 7 lines · Max Filippov
target-xtensa/op_helper.c +7
-0+if (env->sregs[LEND ] != v) { +tb_invalidate_phys_page_range ( + env->sregs[LEND ] -1 , env->sregs[LEND ],0 ); + env->sregs[LEND ] = v; +tb_invalidate_phys_page_range ( + env->sregs[LEND ] -1 , env->sregs[LEND ],0 ); + }
Why are you invalidating twice?
target-xtensa/translate.c static void gen_callwi(DisasContext *dc, int callinc, uint32_t dest, int slot) · line 256
Quoted 13 lines
target-xtensa/translate.c +13
-0+static void gen_check_loop_end (DisasContext *dc,int slot) +{ +if (option_enabled (dc,XTENSA_OPTION_LOOP ) && + !(dc->tb->flags &XTENSA_TBFLAG_EXCM ) && + dc->next_pc == dc->lend) { +int label =gen_new_label (); + +tcg_gen_brcondi_i32 (TCG_COND_NE , cpu_SR[LEND ], dc->next_pc, label); +tcg_gen_brcondi_i32 (TCG_COND_EQ , cpu_SR[LCOUNT ],0 , label); +tcg_gen_subi_i32 (cpu_SR[LCOUNT ], cpu_SR[LCOUNT ],1 ); +gen_jump (dc, cpu_SR[LBEG ]); +gen_set_label (label); +gen_jumpi (dc, dc->next_pc, slot);
If you're going to pretend that LEND is a constant, you might as well pretend that LBEG is also a constant, so that you get to chain the TB's around the loop.
target-xtensa/translate.c static void gen_callwi(DisasContext *dc, int callinc, uint32_t dest, int slot) · line 263
Quoted 4 lines
target-xtensa/translate.c +4
-0+static void gen_jumpi_check_loop_end (DisasContext *dc,int slot) +{ +gen_check_loop_end (dc, slot); +gen_jumpi (dc, dc->next_pc, slot);
You're generating duplicate jumpi's here; that can probably be avoided fairly easily.
r~
Re: [Qemu-devel] [PATCH 19/26] target-xtensa: implement loop option
Quoted 9 lines
target-xtensa/op_helper.c void HELPER(movsp)(uint32_t pc) · line 291
Quoted 7 lines
target-xtensa/op_helper.c +7
-0+if (env->sregs[LEND ] != v) { +tb_invalidate_phys_page_range ( + env->sregs[LEND ] -1 , env->sregs[LEND ],0 ); + env->sregs[LEND ] = v; +tb_invalidate_phys_page_range ( + env->sregs[LEND ] -1 , env->sregs[LEND ],0 ); + }Why are you invalidating twice?
TB at the old LEND and at the new. Although it will work correctly without first invalidation.
Quoted 9 lines
Quoted 9 lines
target-xtensa/translate.c +9
-0+static void gen_check_loop_end (DisasContext *dc,int slot) +{ +if (option_enabled (dc,XTENSA_OPTION_LOOP ) && + !(dc->tb->flags &XTENSA_TBFLAG_EXCM ) && + dc->next_pc == dc->lend) { +int label =gen_new_label (); + +tcg_gen_brcondi_i32 (TCG_COND_NE , cpu_SR[LEND ], dc->next_pc, label); +tcg_gen_brcondi_i32 (TCG_COND_EQ , cpu_SR[LCOUNT ],0 , label);
Quoted 8 lines
target-xtensa/translate.c static void gen_callwi(DisasContext *dc, int callinc, uint32_t dest, int slot) · line 256
Quoted 4 lines
target-xtensa/translate.c +4
-0+tcg_gen_subi_i32 (cpu_SR[LCOUNT ], cpu_SR[LCOUNT ],1 ); +gen_jump (dc, cpu_SR[LBEG ]); +gen_set_label (label); +gen_jumpi (dc, dc->next_pc, slot);If you're going to pretend that LEND is a constant, you might as well pretend that LBEG is also a constant, so that you get to chain the TB's around the loop.
But there may be three exits from TB at the LEND if its last command is a branch: to the LBEG, to the branch target and to the next insn.
Thanks.
-- Max
Re: [Qemu-devel] [PATCH 19/26] target-xtensa: implement loop option
Quoted 30 lines
Quoted 9 lines
Quoted 7 lines
+ if (env->sregs[LEND] != v) {
+ tb_invalidate_phys_page_range(
+ env->sregs[LEND] - 1, env->sregs[LEND], 0);
+ env->sregs[LEND] = v;
+ tb_invalidate_phys_page_range(
+ env->sregs[LEND] - 1, env->sregs[LEND], 0);
+ }Why are you invalidating twice?
TB at the old LEND and at the new. Although it will work correctly without first invalidation.
Quoted 9 lines
Quoted 9 lines
target-xtensa/translate.c +9
-0+static void gen_check_loop_end (DisasContext *dc,int slot) +{ + if (option_enabled(dc, XTENSA_OPTION_LOOP) && + !(dc->tb->flags & XTENSA_TBFLAG_EXCM) && + dc->next_pc == dc->lend) { + int label = gen_new_label(); + + tcg_gen_brcondi_i32(TCG_COND_NE, cpu_SR[LEND], dc->next_pc, label); + tcg_gen_brcondi_i32(TCG_COND_EQ, cpu_SR[LCOUNT], 0, label);Quoted 8 lines
Quoted 4 lines
+ tcg_gen_subi_i32(cpu_SR[LCOUNT], cpu_SR[LCOUNT], 1);
+ gen_jump(dc, cpu_SR[LBEG]);
+ gen_set_label(label);
+ gen_jumpi(dc,dc->next_pc, slot);If you're going to pretend that LEND is a constant, you might as well pretend that LBEG is also a constant, so that you get to chain the TB's around the loop.
Quoted 1 line
But there may be three exits from TB at the LEND if its last command is a branch: to the LBEG, to the branch target and to the next insn.
Ok, I guess that I need to add gen_wsr_lbeg that invalidates TB at the current LEND, pretend that LBEG is constant and use given slot to jump to it. And also to get rid of tcg_gen_brcondi_i32(TCG_COND_NE, cpu_SR[LEND], dc->next_pc, label);
Signature · 2 lines
Thanks. -- Max
Re: [Qemu-devel] [PATCH 19/26] target-xtensa: implement loop option
Quoted 4 lines · Max Filippov
Quoted 4 lines
Quoted 3 lines
If you're going to pretend that LEND is a constant, you might as well pretend that LBEG is also a constant, so that you get to chain the TB's around the loop.
Quoted 8 lines
Quoted 3 lines
But there may be three exits from TB at the LEND if its last command is a branch: to the LBEG, to the branch target and to the next insn.
Ok, I guess that I need to add
gen_wsr_lbegthat invalidates TB at the current LEND, pretend that LBEG is constant and use given slot to jump to it. And also to get rid oftcg_gen_brcondi_i32(TCG_COND_NE, cpu_SR[LEND], dc->next_pc, label);
Yes.
Consider that the code is written to assume that the loop cycles, so the most likely exit at LEND is LBEG. If we choose to mirror that logic inside TCG, then of the 3 possible exits from the block one of them should be LBEG so that the most likely edge can get chained.
r~
PATCH 20/26 target-xtensa: implement extended L32R
In reply to Max FilippovSee ISA, 4.3.3 for details.
TB flag XTENSA_TBFLAG_LITBASE is used to track enable bit of LITBASE SR.
---
RFC -> PATCH changes:
- add XTENSA_TBFLAG_LITBASE, use it in L32R;
--- target-xtensa/cpu.h | 6 ++++++ target-xtensa/helper.c | 1 + target-xtensa/translate.c | 19 +++++++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-)
target-xtensa/cpu.h +6 -0
@@ -110,6 +110,7 @@ enum {LEND =1 ,LCOUNT =2 ,SAR =3 , +LITBASE =5 ,SCOMPARE1 =12 ,WINDOW_BASE =72 , WINDOW_START = 73,
@@ -261,6 +262,7 @@ static inline int cpu_mmu_index(CPUState *env) }#define XTENSA_TBFLAG_EXCM 0x1 +#define XTENSA_TBFLAG_LITBASE 0x2static inline void cpu_get_tb_cpu_state (CPUState *env,target_ulong *pc,target_ulong *cs_base,int *flags)
@@ -271,6 +273,10 @@ static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc,if (env->sregs[PS ] &PS_EXCM ) { *flags |=XTENSA_TBFLAG_EXCM ; } +if (xtensa_option_enabled (env->config,XTENSA_OPTION_EXTENDED_L32R ) && + (env->sregs[LITBASE ] &1 )) { + *flags |=XTENSA_TBFLAG_LITBASE ; + } }#include "cpu-all.h"
target-xtensa/helper.c +1 -0
@@ -38,6 +38,7 @@ void cpu_reset(CPUXtensaState *env) { env->exception_taken =0 ; env->pc = env->config->exception_vector[EXC_RESET ]; + env->sregs[LITBASE ] &= ~1 ; env->sregs[PS ] =0x1f ; }
target-xtensa/translate.c +15 -4
@@ -47,6 +47,7 @@ typedef struct DisasContext {uint32_t next_pc;int mem_idx;uint32_t lend; +uint32_t litbase;int is_jmp;int singlestep_enabled;
@@ -69,6 +70,7 @@ static const char * const sregnames[256] = { [LEND] = "LEND", [LCOUNT] = "LCOUNT", [SAR] = "SAR", + [LITBASE] = "LITBASE", [SCOMPARE1] = "SCOMPARE1", [WINDOW_BASE] = "WINDOW_BASE", [WINDOW_START] = "WINDOW_START",
@@ -314,6 +316,13 @@ static void gen_wsr_sar(DisasContext *dc, uint32_t sr, TCGv_i32 s) dc->sar_m32_5bit = false; } +static void gen_wsr_litbase (DisasContext *dc,uint32_t sr,TCGv_i32 s) +{ +tcg_gen_mov_i32 (cpu_SR[sr], s); +/* This can change tb->flags, so exit tb */ +gen_jumpi_check_loop_end (dc,-1 ); +} +static void gen_wsr_windowbase (DisasContext *dc,uint32_t sr,TCGv_i32 v) {gen_helper_wsr_windowbase (v);
@@ -325,6 +334,7 @@ static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) uint32_t sr, TCGv_i32 v) = { [LEND ] = gen_wsr_lend, [SAR ] = gen_wsr_sar, + [LITBASE ] = gen_wsr_litbase, [WINDOW_BASE ] = gen_wsr_windowbase, };
@@ -1250,10 +1260,10 @@ static void disas_xtensa_insn(DisasContext *dc)case 1 :/*L32R*/ {TCGv_i32 tmp =tcg_const_i32 ( - (0xfffc0000 | (RI16_IMM16 <<2 )) + - ((dc->pc +3 ) & ~3 )); - -/* no ext L32R */ + ((dc->tb->flags &XTENSA_TBFLAG_LITBASE ) ? + dc->litbase : + ((dc->pc +3 ) & ~3 )) + + (0xfffc0000 | (RI16_IMM16 <<2 )));tcg_gen_qemu_ld32u (cpu_R[RRR_T ], tmp,0 );tcg_temp_free (tmp);
@@ -1780,6 +1790,7 @@ static void gen_intermediate_code_internal( dc.pc = env->pc; dc.mem_idx =cpu_mmu_index (env); dc.lend = env->sregs[LEND ]; + dc.litbase = env->sregs[LITBASE ] &0xfffff000 ; dc.is_jmp =DISAS_NEXT ;reset_sar_tracker (&dc);
Signature · 1 line
1.7.3.4
Re: [Qemu-devel] [PATCH 20/26] target-xtensa: implement extended L32R
target-xtensa/translate.c static void gen_wsr_sar(DisasContext *dc, uint32_t sr, TCGv_i32 s) · line 324
Quoted 6 lines · Max Filippov
target-xtensa/translate.c +6
-0+static void gen_wsr_litbase (DisasContext *dc,uint32_t sr,TCGv_i32 s) +{ +tcg_gen_mov_i32 (cpu_SR[sr], s); +/* This can change tb->flags, so exit tb */ +gen_jumpi_check_loop_end (dc,-1 ); +}
Surely you have to flush all TB's when changing litbase?
target-xtensa/translate.c static void disas_xtensa_insn(DisasContext *dc) · line 1266
Quoted 4 lines
target-xtensa/translate.c +4
-0+ ((dc->tb->flags &XTENSA_TBFLAG_LITBASE ) ? + dc->litbase : + ((dc->pc +3 ) & ~3 )) + + (0xfffc0000 | (RI16_IMM16 << 2)));
Unless you actually read from env->sr[LITBASE] here, instead of building the value into the TB.
r~
Re: [Qemu-devel] [PATCH 20/26] target-xtensa: implement extended L32R
Quoted 9 lines
target-xtensa/translate.c static void gen_wsr_sar(DisasContext *dc, uint32_t sr, TCGv_i32 s) · line 324
Quoted 6 lines
target-xtensa/translate.c +6
-0+static void gen_wsr_litbase (DisasContext *dc,uint32_t sr,TCGv_i32 s) +{ +tcg_gen_mov_i32 (cpu_SR[sr], s); +/* This can change tb->flags, so exit tb */ +gen_jumpi_check_loop_end (dc,-1 ); +}Surely you have to flush all TB's when changing litbase?
Quoted 7 lines
target-xtensa/translate.c static void disas_xtensa_insn(DisasContext *dc) · line 1266
Quoted 4 lines
target-xtensa/translate.c +4
-0+ ((dc->tb->flags &XTENSA_TBFLAG_LITBASE ) ? + dc->litbase : + ((dc->pc +3 ) & ~3 )) + + (0xfffc0000 | (RI16_IMM16 << 2)));Unless you actually read from env->sr[LITBASE] here, instead of building the value into the TB.
You're right, I have to flush all TBs at gen_wsr_litbase for this code to always work correctly.
As far as I can see LITBASE usage pattern is that it is set up once in early initialization and is never changed after.
Thanks.
-- Max
Re: [Qemu-devel] [PATCH 20/26] target-xtensa: implement extended L32R
Quoted 2 lines · Max Filippov
As far as I can see LITBASE usage pattern is that it is set up once in early initialization and is never changed after.
That's probably true on a per-program basis. I.e. for semi-hosting or userland emulation, hard-coding litbase into the TB could make sense.
However, for full system emulation, with kernel and userland et al, I would expect that litbase would tend to be set per-application. At which point it would almost certainly be more efficient to read the value at runtime.
r~
PATCH 21/26 target-xtensa: implement unaligned exception option
In reply to Max FilippovSee ISA, 4.4.4 for details.
Correct (aligned as per ISA) address for unaligned access is generated in case this option is not enabled.
--- target-xtensa/translate.c | 33 +++++++++++++++++++++++++++++++-- 1 files changed, 31 insertions(+), 2 deletions(-)
target-xtensa/translate.c +31 -2
@@ -177,6 +177,16 @@ static void gen_exception_cause(DisasContext *dc, uint32_t cause)tcg_temp_free (_cause); } +static void gen_exception_cause_vaddr (DisasContext *dc,uint32_t cause, +TCGv_i32 vaddr) +{ +TCGv_i32 _pc =tcg_const_i32 (dc->pc); +TCGv_i32 _cause =tcg_const_i32 (cause); +gen_helper_exception_cause_vaddr (_pc, _cause, vaddr); +tcg_temp_free (_pc); +tcg_temp_free (_cause); +} +static void gen_check_privilege (DisasContext *dc) {if (dc->mem_idx) {
@@ -349,6 +359,20 @@ static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) } } +static void gen_load_store_alignment (DisasContext *dc,int shift,TCGv_i32 addr) +{ +TCGv_i32 tmp =tcg_temp_local_new_i32 (); +tcg_gen_mov_i32 (tmp, addr); +tcg_gen_andi_i32 (addr, addr, ~0 << shift); +if (option_enabled (dc,XTENSA_OPTION_UNALIGNED_EXCEPTION )) { +int label =gen_new_label (); +tcg_gen_brcond_i32 (TCG_COND_EQ , addr, tmp, label); +gen_exception_cause_vaddr (dc,LOAD_STORE_ALIGNMENT_CAUSE , tmp); +gen_set_label (label); + } +tcg_temp_free (tmp); +} +static void disas_xtensa_insn (DisasContext *dc) {#define HAS_OPTION (opt) do { \
@@ -1272,8 +1296,11 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*LSAI*/ #define gen_load_store (type, shift) do { \ - TCGv_i32 addr = tcg_temp_new_i32(); \ + TCGv_i32 addr = tcg_temp_local_new_i32(); \ tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \ + if (shift) { \ + gen_load_store_alignment(dc, shift, addr); \ + } \ tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, 0); \ tcg_temp_free(addr); \ } while (0)
@@ -1432,6 +1459,7 @@ static void disas_xtensa_insn(DisasContext *dc)tcg_gen_mov_i32 (tmp, cpu_R[RRI8_T ]);tcg_gen_addi_i32 (addr, cpu_R[RRI8_S ],RRI8_IMM8 <<2 ); +gen_load_store_alignment (dc,2 , addr);tcg_gen_qemu_ld32u (cpu_R[RRI8_T ], addr,0 );tcg_gen_brcond_i32 (TCG_COND_NE , tmp, cpu_SR[SCOMPARE1 ], label);
@@ -1657,8 +1685,9 @@ static void disas_xtensa_insn(DisasContext *dc)break ;#define gen_narrow_load_store (type) do { \ - TCGv_i32 addr = tcg_temp_new_i32(); \ + TCGv_i32 addr = tcg_temp_local_new_i32(); \ tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \ + gen_load_store_alignment(dc, 2, addr); \ tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, 0); \ tcg_temp_free(addr); \ } while (0)
Signature · 1 line
1.7.3.4
Re: [Qemu-devel] [PATCH 21/26] target-xtensa: implement unaligned exception option
Quoted 38 lines · Max Filippov
See ISA, 4.4.4 for details.
Correct (aligned as per ISA) address for unaligned access is generated in case this option is not enabled.
Signed-off-by Max Filippov <[email protected]>--- target-xtensa/translate.c | 33 +++++++++++++++++++++++++++++++-- 1 files changed, 31 insertions(+), 2 deletions(-)target-xtensa/translate.c +13
-0@@ -177,6 +177,16 @@ static void gen_exception_cause(DisasContext *dc, uint32_t cause)tcg_temp_free (_cause); } +static void gen_exception_cause_vaddr (DisasContext *dc,uint32_t cause, +TCGv_i32 vaddr) +{ +TCGv_i32 _pc =tcg_const_i32 (dc->pc); +TCGv_i32 _cause =tcg_const_i32 (cause); +gen_helper_exception_cause_vaddr (_pc, _cause, vaddr); +tcg_temp_free (_pc); +tcg_temp_free (_cause); +} +static void gen_check_privilege (DisasContext *dc) {if (dc->mem_idx) {@@ -349,6 +359,20 @@ static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) } } +static void gen_load_store_alignment (DisasContext *dc,int shift,TCGv_i32 addr) +{ +TCGv_i32 tmp =tcg_temp_local_new_i32 ();
target-xtensa/translate.c static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) · line 374
Quoted 10 lines
target-xtensa/translate.c +10
-0+tcg_gen_mov_i32 (tmp, addr); +tcg_gen_andi_i32 (addr, addr, ~0 << shift); +if (option_enabled (dc,XTENSA_OPTION_UNALIGNED_EXCEPTION )) { +int label =gen_new_label (); +tcg_gen_brcond_i32 (TCG_COND_EQ , addr, tmp, label); +gen_exception_cause_vaddr (dc,LOAD_STORE_ALIGNMENT_CAUSE , tmp); +gen_set_label (label); + } +tcg_temp_free (tmp); +}
This is not the correct method for this. Set ALIGNED_ONLY before defining the softmmu_templates. Define do_unaligned_access to raise the exception. See e.g. target-sparc/op_helper.c.
r~
Re: [Qemu-devel] [PATCH 21/26] target-xtensa: implement unaligned exception option
Quoted 9 lines
Quoted 9 lines
target-xtensa/translate.c +9
-0+static void gen_load_store_alignment (DisasContext *dc,int shift,TCGv_i32 addr) +{ +TCGv_i32 tmp =tcg_temp_local_new_i32 (); +tcg_gen_mov_i32 (tmp, addr); +tcg_gen_andi_i32 (addr, addr, ~0 << shift); +if (option_enabled (dc,XTENSA_OPTION_UNALIGNED_EXCEPTION )) { +int label =gen_new_label (); +tcg_gen_brcond_i32 (TCG_COND_EQ , addr, tmp, label); +gen_exception_cause_vaddr (dc,LOAD_STORE_ALIGNMENT_CAUSE , tmp);
Quoted 8 lines
target-xtensa/translate.c static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) · line 374
Quoted 4 lines
target-xtensa/translate.c +4
-0+gen_set_label (label); + } +tcg_temp_free (tmp); +}This is not the correct method for this. Set
ALIGNED_ONLYbefore defining thesoftmmu_templates. Definedo_unaligned_accessto raise the exception. See e.g.target-sparc/op_helper.c.
There are three alignment possibilities for xtensa: no unaligned exception, unaligned exception and hardware alignment.
In the first case unaligned access silently goes to aligned address. It looks like it cannot be done via do_unaligned_access, can it?
In the third case most unaligned accesses are handled transparently by the hardware. But e.g. unaligned access by multiprocessor synchronization instructions still cause alignment exception. Do I need to implement a different alignment checking mechanism for those unhandled cases?
Thanks.
-- Max
Re: [Qemu-devel] [PATCH 21/26] target-xtensa: implement unaligned exception option
Quoted 8 lines · Max Filippov
There are three alignment possibilities for xtensa: no unaligned exception, unaligned exception and hardware alignment. In the first case unaligned access silently goes to aligned address. It looks like it cannot be done via
do_unaligned_access, can it? In the third case most unaligned accesses are handled transparently by the hardware. But e.g. unaligned access by multiprocessor synchronization instructions still cause alignment exception. Do I need to implement a different alignment checking mechanism for those unhandled cases?
Case (1), silently going to an aligned address, should be handled inside the translator by masking the address before the load. See the ARM and Alpha targets for examples.
Case (2) and (3) are both handled by using ALIGNED_ONLY. All you need to do to handle (3) is *not* throw an exception from the do_unaligned_access function. See how the code is structured inside softmmu_template.h.
As for sync insns... You may need to handle it all out-of-line and check for alignment there.
r~
Re: [Qemu-devel] [PATCH 21/26] target-xtensa: implement unaligned exception option
Quoted 9 lines
Quoted 8 lines
There are three alignment possibilities for xtensa: no unaligned exception, unaligned exception and hardware alignment. In the first case unaligned access silently goes to aligned address. It looks like it cannot be done via
do_unaligned_access, can it? In the third case most unaligned accesses are handled transparently by the hardware. But e.g. unaligned access by multiprocessor synchronization instructions still cause alignment exception. Do I need to implement a different alignment checking mechanism for those unhandled cases?
Quoted 3 lines
Case (1), silently going to an aligned address, should be handled inside the translator by masking the address before the load. See the ARM and Alpha targets for examples.
This is what gen_load_store_alignment does.
Quoted 7 lines
Case (2) and (3) are both handled by using
ALIGNED_ONLY. All you need to do to handle (3) is *not* throw an exception from thedo_unaligned_accessfunction. See how the code is structured insidesoftmmu_template.h.As for sync insns... You may need to handle it all out-of-line and check for alignment there.
This is also done by gen_load_store_alignment.
Does it really worth copying part of this logic to do_unaligned_access just to use ALIGNED_ONLY framework?
Thanks.
-- Max
Re: [Qemu-devel] [PATCH 21/26] target-xtensa: implement unaligned exception option
Quoted 2 lines · Max Filippov
This is also done by
gen_load_store_alignment.
Does it really worth copying part of this logic todo_unaligned_accessjust to useALIGNED_ONLYframework?
Yes, because it is done out-of-line, as a part of the TLB load slow path.
r~
Re: [Qemu-devel] [PATCH 21/26] target-xtensa: implement unaligned exception option
Quoted 4 lines
Quoted 2 lines
This is also done by
gen_load_store_alignment.
Does it really worth copying part of this logic todo_unaligned_accessjust to useALIGNED_ONLYframework?Yes, because it is done out-of-line, as a part of the TLB load slow path.
I probably just don't get what you call 'out-of-line'. In fact do_unaligned_access will be called for every unaligned access, and alignment condition will be checked for every access. It just happens in other place. Does it have more chances to be optimized better than TCG code, or is it less TCG code itself that makes difference?
Thanks.
-- Max
Re: [Qemu-devel] [PATCH 21/26] target-xtensa: implement unaligned exception option
Quoted 5 lines · Max Filippov
I probably just don't get what you call 'out-of-line'. In fact
do_unaligned_accesswill be called for every unaligned access, and alignment condition will be checked for every access. It just happens in other place. Does it have more chances to be optimized better than TCG code, or is it less TCG code itself that makes difference?
Out of line meaning not inside TCG code at all.
The fast-path through a tcg_qemu_ld operation handles aligned memory accesses that hit the TLB. Unaligned accesses or TLB misses go to the slow path, in __ld[bwlq]_mmu. It is in these functions that we test for ALIGNED_ONLY, which enables the do_unaligned_access hook.
r~
PATCH 22/26 target-xtensa: implement SIMCALL
In reply to Max FilippovTensilica iss provides support for applications running in freestanding environment through SIMCALL command. It is used by Tensilica libc to access argc/argv, for file I/O, etc.
---
RFC -> PATCH changes:
- use -semihosting to implement SIMCALL;
- fix user memory manipulation code;
- fill in errno for failure cases;
- rename SYS_* to TARGET_SYS_*;
--- Makefile.target | 1 + qemu-options.hx | 4 +- target-xtensa/cpu.h | 1 + target-xtensa/helpers.h | 1 + target-xtensa/op_helper.c | 5 ++ target-xtensa/translate.c | 8 ++- xtensa-semi.c | 176 +++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 193 insertions(+), 3 deletions(-) create mode 100644 xtensa-semi.c
Makefile.target +1 -0
@@ -380,6 +380,7 @@ obj-alpha-y = alpha_palcode.o obj-xtensa-y += xtensa_pic.o obj-xtensa-y += xtensa_sample.o +obj-xtensa-y += xtensa-semi.o main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
qemu-options.hx +2 -2
@@ -2328,11 +2328,11 @@ STEXI Set OpenBIOS nvram @var{variable} to given @var{value} (PPC, SPARC only). ETEXI DEF("semihosting", 0, QEMU_OPTION_semihosting, - "-semihosting semihosting mode\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K) + "-semihosting semihosting mode\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA) STEXI @item -semihosting @findex -semihosting -Semihosting mode (ARM, M68K only). +Semihosting mode (ARM, M68K, Xtensa only). ETEXI DEF("old-param", 0, QEMU_OPTION_old_param, "-old-param old param mode\n", QEMU_ARCH_ARM)
target-xtensa/cpu.h +1 -0
@@ -226,6 +226,7 @@ int cpu_xtensa_signal_handler(int host_signum, void *pinfo, void *puc);void xtensa_cpu_list (FILE *f,fprintf_function cpu_fprintf);void xtensa_sync_window_from_phys (CPUState *env);void xtensa_sync_phys_from_window (CPUState *env); +void simcall (CPUState *env);static inline int xtensa_option_enabled (const XtensaConfig *config,int opt) {
target-xtensa/helpers.h +1 -0
@@ -13,6 +13,7 @@ DEF_HELPER_2(window_check, void, i32, i32) DEF_HELPER_0(restore_owb, void) DEF_HELPER_1(movsp, void, i32) DEF_HELPER_1(wsr_lend, void, i32) +DEF_HELPER_0(simcall, void) DEF_HELPER_0(dump_state, void)#include "def-helper.h"
target-xtensa/op_helper.c +5 -0
@@ -291,6 +291,11 @@ void HELPER(wsr_lend)(uint32_t v) } } +void HELPER (simcall )(void ) +{ +simcall (env); +} +void HELPER (dump_state )(void ) {cpu_dump_state (env, stderr, fprintf,0 );
target-xtensa/translate.c +7 -1
@@ -35,6 +35,7 @@#include "disas.h" #include "tcg-op.h" #include "qemu-log.h" +#include "sysemu.h" #include "helpers.h" #define GEN_HELPER 1
@@ -675,7 +676,12 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 1 :/*SIMCALL*/ -TBD (); +if (semihosting_enabled) { +gen_helper_simcall (); + }else { +qemu_log ("SIMCALL but semihosting is disabled\n" ); +gen_exception_cause (dc,ILLEGAL_INSTRUCTION_CAUSE ); + }break ;default :
xtensa-semi.c new file +176 -0
176 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Re: [Qemu-devel] [PATCH 22/26] target-xtensa: implement SIMCALL
Quoted 9 lines · Max Filippov
target-xtensa/helpers.h +1
-0+DEF_HELPER_0(simcall, void) DEF_HELPER_0(dump_state, void)#include "def-helper.h" target-xtensa/op_helper.c +0
-0
target-xtensa/op_helper.c void HELPER(wsr_lend)(uint32_t v) · line 298
Quoted 8 lines
target-xtensa/op_helper.c +5
-0@@ -291,6 +291,11 @@ void HELPER(wsr_lend)(uint32_t v) } } +void HELPER (simcall )(void ) +{ +simcall (env); +} +
You can explicitly pass env as an argument to the helper and avoid this wrapper function. See e.g. the ARM port and its many non-op_helper.c functions.
r~
PATCH 23/26 target-xtensa: implement interrupt option
In reply to Max FilippovSee ISA, 4.4.6 (interrupt option), 4.4.7 (high priority interrupt option) and 4.4.8 (timer interrupt option) for details.
---
RFC -> PATCH changes:
- halt CPU on waiti, use qemu timer to wake up on CCOMPARE match;
- advance CCOUNT on TB exit, on exception and on RSR.CCOUNT;
--- hw/xtensa_pic.c | 83 +++++++++++++++++++++++++++++++ target-xtensa/cpu.h | 39 ++++++++++++++ target-xtensa/exec.h | 2 +- target-xtensa/helper.c | 80 +++++++++++++++++++++++++++++- target-xtensa/helpers.h | 5 ++ target-xtensa/op_helper.c | 44 ++++++++++++++++ target-xtensa/translate.c | 121 ++++++++++++++++++++++++++++++++++++++++++--- 7 files changed, 365 insertions(+), 9 deletions(-)
hw/xtensa_pic.c +83 -0
@@ -27,6 +27,8 @@#include "hw.h" #include "pc.h" +#include "qemu-log.h" +#include "qemu-timer.h" /* Stub functions for hardware that doesn't exist. */ void pic_info (Monitor *mon)
@@ -36,3 +38,84 @@ void pic_info(Monitor *mon)void irq_info (Monitor *mon) { } + +void xtensa_advance_ccount (CPUState *env,uint32_t d) +{ +uint32_t old_ccount = env->sregs[CCOUNT ]; + + env->sregs[CCOUNT ] += d; + +if (xtensa_option_enabled (env->config,XTENSA_OPTION_TIMER_INTERRUPT )) { +int i; +for (i =0 ; i < env->config->nccompare; ++i) { +if (env->sregs[CCOMPARE + i] - old_ccount <= d) { + env->halted =0 ; +xtensa_timer_irq (env, i,1 ); + } + } + } +} + +void check_interrupts (CPUState *env) +{ +int minlevel =xtensa_get_cintlevel (env); +int level; + +for (level = env->config->nlevel; level > minlevel; --level) { +if (env->config->level_mask[level] & + env->sregs[INTSET ] & + env->sregs[INTENABLE ]) { +if (env->halted) { +xtensa_advance_ccount (env, +muldiv64 (qemu_get_clock_ns (vm_clock) - env->halt_clock, + env->config->clock_freq_khz,1000000 )); + } + env->pending_irq_level = level; +cpu_interrupt (env,CPU_INTERRUPT_HARD ); +return ; + } + } + env->pending_irq_level =0 ; +cpu_reset_interrupt (env,CPU_INTERRUPT_HARD ); +} + +static void xtensa_set_irq (void *opaque,int irq,int active) +{ +CPUState *env = opaque; + +if (irq >= env->config->ninterrupt) { +qemu_log ("%s: bad IRQ %d\n" , __func__, irq); + }else { +uint32_t irq_bit =1 << irq; + +if (active) { + env->sregs[INTSET ] |= irq_bit; + }else { + env->sregs[INTSET ] &= ~irq_bit; + } + +check_interrupts (env); + } +} + +void xtensa_timer_irq (CPUState *env,uint32_t id,uint32_t active) +{ +qemu_set_irq (env->irq_inputs[env->config->timerint[id]], active); +} + +static void xtensa_ccompare_cb (void *opaque) +{ +CPUState *env = opaque; +xtensa_advance_ccount (env, env->wake_ccount - env->sregs[CCOUNT ]); +} + +void xtensa_irq_init (CPUState *env) +{ + env->irq_inputs = (void **)qemu_allocate_irqs ( + xtensa_set_irq, env, env->config->ninterrupt); +if (xtensa_option_enabled (env->config,XTENSA_OPTION_TIMER_INTERRUPT ) && + env->config->nccompare >0 ) { + env->ccompare_timer = +qemu_new_timer_ns (vm_clock, &xtensa_ccompare_cb, env); + } +}
target-xtensa/cpu.h +39 -0
@@ -116,10 +116,16 @@ enum {WINDOW_START =73 ,EPC1 =177 ,DEPC =192 , +EPS2 =194 ,EXCSAVE1 =209 , +INTSET =226 , +INTCLEAR =227 , +INTENABLE =228 ,PS =230 ,EXCCAUSE =232 , +CCOUNT =234 ,EXCVADDR =238 , + CCOMPARE = 240, };#define PS_INTLEVEL 0xf
@@ -141,6 +147,10 @@ enum {#define PS_WOE 0x40000#define MAX_NAREG 64 +#define MAX_NINTERRUPT 32 +#define MAX_NLEVEL 6 +#define MAX_NNMI 1 +#define MAX_NCCOMPARE 3enum {/* Static vectors */
@@ -190,6 +200,16 @@ enum { COPROCESSOR0_DISABLED = 32, }; +typedef enum { +INTTYPE_LEVEL , +INTTYPE_EDGE , +INTTYPE_NMI , +INTTYPE_SOFTWARE , +INTTYPE_TIMER , +INTTYPE_DEBUG , +INTTYPE_WRITE_ERR , +}interrupt_type_t ; + typedef struct XtensaConfig { const char *name; uint64_t options;
@@ -197,6 +217,15 @@ typedef struct XtensaConfig {int excm_level;int ndepc;uint32_t exception_vector[EXC_MAX ]; +unsigned ninterrupt; +unsigned nlevel; +uint32_t interrupt_vector[MAX_NLEVEL +MAX_NNMI +1 ]; +uint32_t level[MAX_NINTERRUPT ]; +uint32_t level_mask[MAX_NLEVEL +MAX_NNMI +1 ]; +interrupt_type_t inttype[MAX_NINTERRUPT ]; +unsigned nccompare; +uint32_t timerint[MAX_NCCOMPARE ]; +uint32_t clock_freq_khz; } XtensaConfig; typedef struct CPUXtensaState {
@@ -207,6 +236,12 @@ typedef struct CPUXtensaState {uint32_t uregs[256 ];uint32_t phys_regs[MAX_NAREG ]; +int pending_irq_level;/* level of last raised IRQ */ +void **irq_inputs; +QEMUTimer *ccompare_timer; +uint32_t wake_ccount; +int64_t halt_clock; +int exception_taken;CPU_COMMON
@@ -222,6 +257,10 @@ CPUXtensaState *cpu_xtensa_init(const char *cpu_model);void xtensa_translate_init (void );int cpu_xtensa_exec (CPUXtensaState *s);void do_interrupt (CPUXtensaState *s); +void check_interrupts (CPUXtensaState *s); +void xtensa_irq_init (CPUState *env); +void xtensa_advance_ccount (CPUState *env,uint32_t d); +void xtensa_timer_irq (CPUState *env,uint32_t id,uint32_t active);int cpu_xtensa_signal_handler (int host_signum,void *pinfo,void *puc);void xtensa_cpu_list (FILE *f,fprintf_function cpu_fprintf);void xtensa_sync_window_from_phys (CPUState *env);
target-xtensa/exec.h +1 -1
@@ -35,7 +35,7 @@ register struct CPUXtensaState *env asm(AREG0);static inline int cpu_has_work (CPUState *env) { -return 1 ; +return env->pending_irq_level; }#if !defined(CONFIG_USER_ONLY )
target-xtensa/helper.c +79 -1
118 lines not on this page · raw message
target-xtensa/helpers.h +5 -0
@@ -16,4 +16,9 @@ DEF_HELPER_1(wsr_lend, void, i32) DEF_HELPER_0(simcall, void) DEF_HELPER_0(dump_state, void) +DEF_HELPER_0(check_interrupts, void) +DEF_HELPER_2(waiti, void, i32, i32) +DEF_HELPER_2(timer_irq, void, i32, i32) +DEF_HELPER_1(advance_ccount, void, i32) +#include "def-helper.h"
target-xtensa/op_helper.c +44 -0
47 lines not on this page · raw message
target-xtensa/translate.c +114 -7
267 lines not on this page · raw message
Signature · 1 line
1.7.3.4
Re: [Qemu-devel] [PATCH 23/26] target-xtensa: implement interrupt option
hw/xtensa_pic.c void pic_info(Monitor *mon) · line 53
Quoted 6 lines · Max Filippov
hw/xtensa_pic.c +6
-0+if (xtensa_option_enabled (env->config,XTENSA_OPTION_TIMER_INTERRUPT )) { +int i; +for (i =0 ; i < env->config->nccompare; ++i) { +if (env->sregs[CCOMPARE + i] - old_ccount <= d) { + env->halted =0 ; +xtensa_timer_irq (env, i,1 );
I don't think you should be writing to halted here; this is done by the code in cpu-exec.c, when noticing when cpu_has_work. Which will be true as a function of env->interrupt_request and the interrupt mask.
hw/xtensa_pic.c void pic_info(Monitor *mon) · line 72
Quoted 5 lines
hw/xtensa_pic.c +5
-0+if (env->halted) { +xtensa_advance_ccount (env, +muldiv64 (qemu_get_clock_ns (vm_clock) - env->halt_clock, + env->config->clock_freq_khz,1000000 )); + }
Why are you polling the vm_clock rather than setting up a timer?
hw/xtensa_pic.c void pic_info(Monitor *mon) · line 119
Quoted 2 lines
hw/xtensa_pic.c +2
-0+ env->ccompare_timer = +qemu_new_timer_ns (vm_clock, &xtensa_ccompare_cb, env);
... er, actually you are setting up a timer. So why aren't you using it?
target-xtensa/helper.c target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) · line 187
Quoted 10 lines
void
do_interrupt(CPUState *env){ switch (env->exception_index) {target-xtensa/helper.c +7
-0+case EXC_IRQ : +if (handle_interrupt (env)) { +break ; + } +/* not handled interrupt falls through, +* env->exception_index is updated +*/
Do you really want to fall through, rather than restart the switch?
target-xtensa/helper.c void do_interrupt(CPUState *env) · line 201
Quoted 5 lines
target-xtensa/helper.c +1
-0@@ -124,12 +198,16 @@ void do_interrupt(CPUState *env)if (env->config->exception_vector[env->exception_index]) { env->pc = env->config->exception_vector[env->exception_index]; env->exception_taken =1 ; + env->interrupt_request |=CPU_INTERRUPT_EXITTB ;
Huh? What are you trying to accomplish here?
EXITTB is supposed to be used when a device external to the cpu changes the memory mapping of the system. E.g. the x86 a20 line.
target-xtensa/helpers.h DEF_HELPER_1(wsr_lend, void, i32) · line 22
Quoted 4 lines
target-xtensa/helpers.h +4
-0+DEF_HELPER_0(check_interrupts, void) +DEF_HELPER_2(waiti, void, i32, i32) +DEF_HELPER_2(timer_irq, void, i32, i32) +DEF_HELPER_1 (advance_ccount, void, i32)
You shouldn't have to manage any of this from within the translator.
r~
Re: [Qemu-devel] [PATCH 23/26] target-xtensa: implement interrupt option
Quoted 10 lines
hw/xtensa_pic.c void pic_info(Monitor *mon) · line 53
Quoted 6 lines
hw/xtensa_pic.c +6
-0+if (xtensa_option_enabled (env->config,XTENSA_OPTION_TIMER_INTERRUPT )) { +int i; +for (i =0 ; i < env->config->nccompare; ++i) { +if (env->sregs[CCOMPARE + i] - old_ccount <= d) { + env->halted =0 ; +xtensa_timer_irq (env, i,1 );I don't think you should be writing to halted here; this is done by the code in
cpu-exec.c, when noticing whencpu_has_work. Which will be true as a function ofenv->interrupt_requestand the interrupt mask.
I do it here to distinguish interrupt caused by CCOMPARE match, for which I want exact CCOUNT value, from other interrupt sources, when CCOUNT may be advanced approximately.
Quoted 7 lines
hw/xtensa_pic.c void pic_info(Monitor *mon) · line 72
Quoted 5 lines
hw/xtensa_pic.c +5
-0+if (env->halted) { +xtensa_advance_ccount (env, +muldiv64 (qemu_get_clock_ns (vm_clock) - env->halt_clock, + env->config->clock_freq_khz,1000000 )); + }Why are you polling the
vm_clockrather than setting up a timer?
I'm not polling, I'm adjusting ccount according to vm_clock time passed since we were halted.
Quoted 4 lines
hw/xtensa_pic.c void pic_info(Monitor *mon) · line 119
Quoted 2 lines
hw/xtensa_pic.c +2
-0+ env->ccompare_timer = +qemu_new_timer_ns (vm_clock, &xtensa_ccompare_cb, env);... er, actually you are setting up a timer. So why aren't you using it?
I'm using it: it is wound up by HELPER(waiti) when there's no currently pending interrupts and xtensa_ccompare_cb calls xtensa_advance_ccount, which in turn calls xtensa_timer_irq.
Quoted 11 lines
target-xtensa/helper.c target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr) · line 187
Quoted 10 lines
void
do_interrupt(CPUState *env){ switch (env->exception_index) {target-xtensa/helper.c +7
-0+case EXC_IRQ : +if (handle_interrupt (env)) { +break ; + } +/* not handled interrupt falls through, +* env->exception_index is updated +*/
Quoted 1 line
Do you really want to fall through, rather than restart the switch?
Handle_interrupt will handle high-priority interrupt requests, leaving only level-1 interrupts, which it converts into EXC_USER or EXC_KERNEL. If only for the sake of readability...
Quoted 9 lines
target-xtensa/helper.c void do_interrupt(CPUState *env) · line 201
Quoted 5 lines
target-xtensa/helper.c +1
-0@@ -124,12 +198,16 @@ void do_interrupt(CPUState *env)if (env->config->exception_vector[env->exception_index]) { env->pc = env->config->exception_vector[env->exception_index]; env->exception_taken =1 ; + env->interrupt_request |=CPU_INTERRUPT_EXITTB ;Huh? What are you trying to accomplish here?
EXITTB is supposed to be used when a device external to the cpu changes the memory mapping of the system. E.g. the x86 a20 line.
I used it to have next_tb = 0 in cpu_exec, after return from do_interrupt, but now it is done unconditionally, so there's no need in CPU_INTERRUPT_EXITTB. By the way, do I understand it right that if I chain TBs than I need to periodically check for pending interrupts myself, otherwise e.g. "j $" will create uninterruptible infinite loop?
Quoted 6 lines
target-xtensa/helpers.h DEF_HELPER_1(wsr_lend, void, i32) · line 22
Quoted 4 lines
target-xtensa/helpers.h +4
-0+DEF_HELPER_0(check_interrupts, void) +DEF_HELPER_2(waiti, void, i32, i32) +DEF_HELPER_2(timer_irq, void, i32, i32) +DEF_HELPER_1 (advance_ccount, void, i32)You shouldn't have to manage any of this from within the translator.
Please explain.
Thanks.
-- Max
Re: [Qemu-devel] [PATCH 23/26] target-xtensa: implement interrupt option
Quoted 3 lines · Max Filippov
By the way, do I understand it right that if I chain TBs than I need to periodically check for pending interrupts myself, otherwise e.g. "j $" will create uninterruptible infinite loop?
No, it won't. It'll create a loop, but it'll be broken by the host signal handler. Notice no other target is checking for this.
Quoted 6 lines
Quoted 6 lines
target-xtensa/helpers.h DEF_HELPER_1(wsr_lend, void, i32) · line 22
Quoted 4 lines
target-xtensa/helpers.h +4
-0+DEF_HELPER_0(check_interrupts, void) +DEF_HELPER_2(waiti, void, i32, i32) +DEF_HELPER_2(timer_irq, void, i32, i32) +DEF_HELPER_1 (advance_ccount, void, i32)You shouldn't have to manage any of this from within the translator.
You should *never* have to check for interrupts, or advance cycle counters, from within the translated code. Interrupt processing, and thus timers, are handled in between TBs as necessary by generic code.
r~
Re: [Qemu-devel] [PATCH 23/26] target-xtensa: implement interrupt option
Quoted 14 lines
Quoted 3 lines
By the way, do I understand it right that if I chain TBs than I need to periodically check for pending interrupts myself, otherwise e.g. "j $" will create uninterruptible infinite loop?
No, it won't. It'll create a loop, but it'll be broken by the host signal handler. Notice no other target is checking for this.
Quoted 6 lines
Quoted 6 lines
target-xtensa/helpers.h DEF_HELPER_1(wsr_lend, void, i32) · line 22
Quoted 4 lines
target-xtensa/helpers.h +4
-0+DEF_HELPER_0(check_interrupts, void) +DEF_HELPER_2(waiti, void, i32, i32) +DEF_HELPER_2(timer_irq, void, i32, i32) +DEF_HELPER_1 (advance_ccount, void, i32)You shouldn't have to manage any of this from within the translator.
Quoted 3 lines
You should *never* have to check for interrupts, or advance cycle counters, from within the translated code. Interrupt processing, and thus timers, are handled in between TBs as necessary by generic code.
Well,
- cycles fed into advance_ccount may (and on real hardware actually do) depend on executed commands/pipeline/cache hits. Most of this stuff may be counted at the translation time;
- timer_irq is a helper that raises IRQ generated by CCOMPARE match;
- waiti is a helper for the instruction of the same name;
- check_interrupts converts IRQs on enabled interrupt sources into current irq level.
Thanks.
-- Max
Re: [Qemu-devel] [PATCH 23/26] target-xtensa: implement interrupt option
Quoted 3 lines · Max Filippov
- cycles fed into
advance_ccountmay (and on real hardware actually do) depend on executed commands/pipeline/cache hits. Most of this stuff may be counted at the translation time;
Since CCOUNT, as seen by any one thread of execution, on real hw depends on cache hits, interrupts, and other asynchronous stuff, then don't bother trying to account for it on a per-instruction basis. Just define a clock that runs at a given rate and be done. No need to advance it manually.
Quoted 1 line
-
timer_irqis a helper that raises IRQ generated by CCOMPARE match;
That's what the callback from qemu_new_timer_ns is for.
You've got N CCOMPARE registers, you can create N timers all of which are setup to raise the IRQ.
cpu_xtensa_init(...)
{
...
for (i = 0; i < N; ++i)
env->ccompare_timer[i] = qemu_new_timer(vm_clock, HZ, xtensa_ccompare_cb, env);
}void xtensa_ccompare_cb(CPUState *env)
{
/* Set something in the processor state. */
cpu_interrupt(env, CPU_INTERRUPT_HARD);
}void HELPER(wsr_ccompare)(int which, uint32_t match)
{
qemu_mod_timer(env->ccompare_timer[which], match);
}Quoted 1 line
- waiti is a helper for the instruction of the same name;
Sure, this one should exist for the translator. But it should do nothing except change PS.INTLEVEL, set env->halted, and do cpu_loop_exit. All of the actual waiting should be in the main QEMU loop.
Because it exits to the main loop, it should also end the TB.
Quoted 1 line
-
check_interruptsconverts IRQs on enabled interrupt sources into current irq level.
This is needed during do_interrupt, but should not be used by the translator itself.
You may find some of this easier if you utilize the IRQ cleanup patch series that was recently committed to HEAD. See CPU_INTERRUPT_TGT_EXT_[0-4] in cpu-all.h and its uses in the various targets.
r~
Re: [Qemu-devel] [PATCH 23/26] target-xtensa: implement interrupt option
Quoted 8 lines
Quoted 3 lines
- cycles fed into
advance_ccountmay (and on real hardware actually do) depend on executed commands/pipeline/cache hits. Most of this stuff may be counted at the translation time;Since CCOUNT, as seen by any one thread of execution, on real hw depends on cache hits, interrupts, and other asynchronous stuff, then don't bother trying to account for it on a per-instruction basis. Just define a clock that runs at a given rate and be done. No need to advance it manually.
It means no cycle-accurate emulation. This was one of my goals, maybe not closest one. Is it acceptable to have two simulation modes -- fast functional and slower cycle-accurate?
Quoted 2 lines
Quoted 1 line
-
check_interruptsconverts IRQs on enabled interrupt sources into current irq level.This is needed during
do_interrupt, but should not be used by the translator itself.
Not only during do_interrupt, but also in cpu_has_work.
Thanks.
-- Max
Re: [Qemu-devel] [PATCH 23/26] target-xtensa: implement interrupt option
Quoted 4 lines · Max Filippov
Quoted 4 lines
Quoted 3 lines
- cycles fed into
advance_ccountmay (and on real hardware actually do) depend on executed commands/pipeline/cache hits. Most of this stuff may be counted at the translation time;
Quoted 8 lines
Quoted 4 lines
Since CCOUNT, as seen by any one thread of execution, on real hw depends on cache hits, interrupts, and other asynchronous stuff, then don't bother trying to account for it on a per-instruction basis. Just define a clock that runs at a given rate and be done. No need to advance it manually.
It means no cycle-accurate emulation. This was one of my goals, maybe not closest one. Is it acceptable to have two simulation modes -- fast functional and slower cycle-accurate?
Huh. Given that you're not modeling the caches, I don't see how you could hope for true cycle accuracy. As for whether a mostly-cycle-accurate mode should be a goal... I'll have to defer to other QEMU maintainers.
r~
Re: [Qemu-devel] [PATCH 23/26] target-xtensa: implement interrupt option
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
- cycles fed into
advance_ccountmay (and on real hardware actually do) depend on executed commands/pipeline/cache hits. Most of this stuff may be counted at the translation time;Since CCOUNT, as seen by any one thread of execution, on real hw depends on cache hits, interrupts, and other asynchronous stuff, then don't bother trying to account for it on a per-instruction basis. Just define a clock that runs at a given rate and be done. No need to advance it manually.
Quoted 7 lines
Quoted 3 lines
It means no cycle-accurate emulation. This was one of my goals, maybe not closest one. Is it acceptable to have two simulation modes -- fast functional and slower cycle-accurate?
Huh. Given that you're not modeling the caches, I don't see how you could hope for true cycle accuracy. As for whether a mostly-cycle-accurate mode should be a goal... I'll have to defer to other QEMU maintainers.
I'm going to model them finally, as well as pipeline and TCM/external memory. Just need a stable basis to start with (:
Signature · 2 lines
Thanks. -- Max
PATCH 24/26 target-xtensa: implement accurate window check
In reply to Max FilippovSee ISA, 4.7.1.3 for details.
Window check is inserted before commands that push "used register watermark" beyond its current level. Used register watermark is reset on instructions that change WINDOW_BASE/WINDOW_START SRs.
--- target-xtensa/translate.c | 105 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 105 insertions(+), 0 deletions(-)
target-xtensa/translate.c +105 -0
@@ -58,6 +58,7 @@ typedef struct DisasContext {TCGv_i32 sar_m32;uint32_t ccount_delta; +unsigned used_window; } DisasContext;static TCGv_ptr cpu_env;
@@ -206,6 +207,11 @@ static void gen_check_interrupts(DisasContext *dc)gen_helper_check_interrupts (); } +static void reset_used_window (DisasContext *dc) +{ + dc->used_window =0 ; +} +static void gen_exception (DisasContext *dc,int excp) {TCGv_i32 tmp =tcg_const_i32 (excp);
@@ -392,11 +398,19 @@ static void gen_wsr_litbase(DisasContext *dc, uint32_t sr, TCGv_i32 s)static void gen_wsr_windowbase (DisasContext *dc,uint32_t sr,TCGv_i32 v) {gen_helper_wsr_windowbase (v); +reset_used_window (dc); +} + +static void gen_wsr_windowstart (DisasContext *dc,uint32_t sr,TCGv_i32 v) +{ +tcg_gen_mov_i32 (cpu_SR[sr], v); +reset_used_window (dc); }static void gen_wsr_ps (DisasContext *dc,uint32_t sr,TCGv_i32 v) {tcg_gen_mov_i32 (cpu_SR[sr], v); +reset_used_window (dc);gen_check_interrupts (dc);/* This can change tb->flags, so exit tb */ gen_jumpi_check_loop_end (dc,-1 );
@@ -421,6 +435,7 @@ static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) [SAR] = gen_wsr_sar, [LITBASE] = gen_wsr_litbase, [WINDOW_BASE] = gen_wsr_windowbase, + [WINDOW_START] = gen_wsr_windowstart, [PS] = gen_wsr_ps, [CCOMPARE] = gen_wsr_ccompare, [CCOMPARE + 1] = gen_wsr_ccompare,
@@ -462,6 +477,32 @@ static void gen_waiti(DisasContext *dc, uint32_t imm4)tcg_temp_free (intlevel); } +static void gen_window_check1 (DisasContext *dc,unsigned r1) +{ +if (option_enabled (dc,XTENSA_OPTION_WINDOWED_REGISTER ) && + r1 /4 > dc->used_window) { +TCGv_i32 pc =tcg_const_i32 (dc->pc); +TCGv_i32 w =tcg_const_i32 (r1 /4 ); + +gen_advance_ccount (dc); +gen_helper_window_check (pc, w); + +tcg_temp_free (w); +tcg_temp_free (pc); + } +} + +static void gen_window_check2 (DisasContext *dc,unsigned r1,unsigned r2) +{ +gen_window_check1 (dc, r1 > r2 ? r1 : r2); +} + +static void gen_window_check3 (DisasContext *dc,unsigned r1,unsigned r2, +unsigned r3) +{ +gen_window_check2 (dc, r1, r2 > r3 ? r2 : r3); +} +static void disas_xtensa_insn (DisasContext *dc) {#define HAS_OPTION (opt) do { \
@@ -591,6 +632,7 @@ static void disas_xtensa_insn(DisasContext *dc)switch (CALLX_N ) {case 0 :/*RET*/ case 2 :/*JX*/ +gen_window_check1 (dc,CALLX_S );gen_jump (dc, cpu_R[CALLX_S ]);break ;
@@ -612,6 +654,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 3 :/*CALLX*/ +gen_window_check2 (dc,CALLX_S ,CALLX_N <<2 );switch (CALLX_N ) {case 0 :/*CALLX0*/ {
@@ -642,6 +685,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 1 :/*MOVSPw*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +gen_window_check2 (dc,RRR_T ,RRR_S ); {TCGv_i32 pc =tcg_const_i32 (dc->pc);gen_advance_ccount (dc);
@@ -785,6 +829,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 6 :/*RSILx*/ HAS_OPTION (XTENSA_OPTION_INTERRUPT );gen_check_privilege (dc); +gen_window_check1 (dc,RRR_T );tcg_gen_mov_i32 (cpu_R[RRR_T ], cpu_SR[PS ]);tcg_gen_ori_i32 (cpu_SR[PS ], cpu_SR[PS ],RRR_S ); tcg_gen_andi_i32(cpu_SR[PS], cpu_SR[PS],
@@ -826,28 +871,34 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 1 :/*AND*/ +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T );tcg_gen_and_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], cpu_R[RRR_T ]);break ;case 2 :/*OR*/ +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T );tcg_gen_or_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], cpu_R[RRR_T ]);break ;case 3 :/*XOR*/ +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T );tcg_gen_xor_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], cpu_R[RRR_T ]);break ;case 4 :/*ST1*/ switch (RRR_R ) {case 0 :/*SSR*/ +gen_window_check1 (dc,RRR_S );gen_right_shift_sar (dc, cpu_R[RRR_S ]);break ;case 1 :/*SSL*/ +gen_window_check1 (dc,RRR_S );gen_left_shift_sar (dc, cpu_R[RRR_S ]);break ;case 2 :/*SSA8L*/ +gen_window_check1 (dc,RRR_S ); {TCGv_i32 tmp =tcg_temp_new_i32 ();tcg_gen_shli_i32 (tmp, cpu_R[RRR_S ],3 );
@@ -857,6 +908,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 3 :/*SSA8B*/ +gen_window_check1 (dc,RRR_S ); {TCGv_i32 tmp =tcg_temp_new_i32 ();tcg_gen_shli_i32 (tmp, cpu_R[RRR_S ],3 );
@@ -890,16 +942,19 @@ static void disas_xtensa_insn(DisasContext *dc) RRR_T | ((RRR_T & 8) ? 0xfffffff0 : 0));gen_helper_rotw (tmp);tcg_temp_free (tmp); +reset_used_window (dc); }break ;case 14 :/*NSAu*/ HAS_OPTION (XTENSA_OPTION_MISC_OP ); +gen_window_check2 (dc,RRR_S ,RRR_T );gen_helper_nsa (cpu_R[RRR_T ], cpu_R[RRR_S ]);break ;case 15 :/*NSAUu*/ HAS_OPTION (XTENSA_OPTION_MISC_OP ); +gen_window_check2 (dc,RRR_S ,RRR_T );gen_helper_nsau (cpu_R[RRR_T ], cpu_R[RRR_S ]);break ;
@@ -914,6 +969,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 6 :/*RT0*/ +gen_window_check2 (dc,RRR_R ,RRR_T );switch (RRR_S ) {case 0 :/*NEG*/ tcg_gen_neg_i32 (cpu_R[RRR_R ], cpu_R[RRR_T ]);
@@ -941,12 +997,14 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 8 :/*ADD*/ +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T );tcg_gen_add_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], cpu_R[RRR_T ]);break ;case 9 :/*ADD**/ case 10 :case 11 : +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T ); {TCGv_i32 tmp =tcg_temp_new_i32 ();tcg_gen_shli_i32 (tmp, cpu_R[RRR_S ], _OP2 -8 );
@@ -956,12 +1014,14 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 12 :/*SUB*/ +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T );tcg_gen_sub_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], cpu_R[RRR_T ]);break ;case 13 :/*SUB**/ case 14 :case 15 : +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T ); {TCGv_i32 tmp =tcg_temp_new_i32 ();tcg_gen_shli_i32 (tmp, cpu_R[RRR_S ], _OP2 -12 );
@@ -976,17 +1036,20 @@ static void disas_xtensa_insn(DisasContext *dc)switch (_OP2) {case 0 :/*SLLI*/ case 1 : +gen_window_check2 (dc,RRR_R ,RRR_S );tcg_gen_shli_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ],32 - (RRR_T | ((_OP2 &1 ) <<4 )));break ;case 2 :/*SRAI*/ case 3 : +gen_window_check2 (dc,RRR_R ,RRR_T );tcg_gen_sari_i32 (cpu_R[RRR_R ], cpu_R[RRR_T ],RRR_S | ((_OP2 &1 ) <<4 ));break ;case 4 :/*SRLI*/ +gen_window_check2 (dc,RRR_R ,RRR_T );tcg_gen_shri_i32 (cpu_R[RRR_R ], cpu_R[RRR_T ],RRR_S );break ;
@@ -996,6 +1059,7 @@ static void disas_xtensa_insn(DisasContext *dc)if (RSR_SR >=64 ) {gen_check_privilege (dc); } +gen_window_check1 (dc,RRR_T );tcg_gen_mov_i32 (tmp, cpu_R[RRR_T ]);gen_rsr (dc, cpu_R[RRR_T ],RSR_SR );gen_wsr (dc,RSR_SR , tmp);
@@ -1022,6 +1086,7 @@ static void disas_xtensa_insn(DisasContext *dc)#define gen_shift (cmd) gen_shift_reg(cmd, cpu_SR[SAR])case 8 :/*SRC*/ +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T ); {TCGv_i64 v =tcg_temp_new_i64 ();tcg_gen_concat_i32_i64 (v, cpu_R[RRR_T ], cpu_R[RRR_S ]);
@@ -1030,6 +1095,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 9 :/*SRL*/ +gen_window_check2 (dc,RRR_R ,RRR_T );if (dc->sar_5bit) {tcg_gen_shr_i32 (cpu_R[RRR_R ], cpu_R[RRR_T ], cpu_SR[SAR ]); }else {
@@ -1040,6 +1106,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 10 :/*SLL*/ +gen_window_check2 (dc,RRR_R ,RRR_S );if (dc->sar_m32_5bit) {tcg_gen_shl_i32 (cpu_R[RRR_R ], cpu_R[RRR_S ], dc->sar_m32); }else {
@@ -1054,6 +1121,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 11 :/*SRA*/ +gen_window_check2 (dc,RRR_R ,RRR_T );if (dc->sar_5bit) {tcg_gen_sar_i32 (cpu_R[RRR_R ], cpu_R[RRR_T ], cpu_SR[SAR ]); }else {
@@ -1067,6 +1135,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 12 :/*MUL16U*/ HAS_OPTION (XTENSA_OPTION_16_BIT_IMUL ); +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T ); {TCGv_i32 v1 =tcg_temp_new_i32 ();TCGv_i32 v2 =tcg_temp_new_i32 ();
@@ -1080,6 +1149,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 13 :/*MUL16S*/ HAS_OPTION (XTENSA_OPTION_16_BIT_IMUL ); +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T ); {TCGv_i32 v1 =tcg_temp_new_i32 ();TCGv_i32 v2 =tcg_temp_new_i32 ();
@@ -1098,6 +1168,8 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 2 :/*RST2*/ +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T ); +if (_OP2 >=12 ) {HAS_OPTION (XTENSA_OPTION_32_BIT_IDIV );int label =gen_new_label ();
@@ -1165,6 +1237,7 @@ static void disas_xtensa_insn(DisasContext *dc)if (RSR_SR >=64 ) {gen_check_privilege (dc); } +gen_window_check1 (dc,RRR_T );gen_rsr (dc, cpu_R[RRR_T ],RSR_SR );if (!sregnames[RSR_SR ]) {TBD ();
@@ -1175,6 +1248,7 @@ static void disas_xtensa_insn(DisasContext *dc)if (RSR_SR >=64 ) {gen_check_privilege (dc); } +gen_window_check1 (dc,RRR_T );gen_wsr (dc,RSR_SR , cpu_R[RRR_T ]);if (!sregnames[RSR_SR ]) {TBD ();
@@ -1183,6 +1257,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*SEXTu*/ HAS_OPTION (XTENSA_OPTION_MISC_OP ); +gen_window_check2 (dc,RRR_R ,RRR_S ); {int shift =24 -RRR_T ;
@@ -1201,6 +1276,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 3 :/*CLAMPSu*/ HAS_OPTION (XTENSA_OPTION_MISC_OP ); +gen_window_check2 (dc,RRR_R ,RRR_S ); {TCGv_i32 tmp1 =tcg_temp_new_i32 ();TCGv_i32 tmp2 =tcg_temp_new_i32 ();
@@ -1228,6 +1304,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 6 :/*MINUu*/ case 7 :/*MAXUu*/ HAS_OPTION (XTENSA_OPTION_MISC_OP ); +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T ); {static const TCGCond cond[] = {TCG_COND_LE ,
@@ -1255,6 +1332,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 9 :/*MOVNEZ*/ case 10 :/*MOVLTZ*/ case 11 :/*MOVGEZ*/ +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T ); {static const TCGCond cond[] = {TCG_COND_NE ,
@@ -1280,6 +1358,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 14 :/*RUR*/ +gen_window_check1 (dc,RRR_R ); {int st = (RRR_S <<4 ) +RRR_T ;if (uregnames[st]) {
@@ -1292,6 +1371,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 15 :/*WUR*/ +gen_window_check1 (dc,RRR_T ); {if (uregnames[RSR_SR ]) {tcg_gen_mov_i32 (cpu_UR[RSR_SR ], cpu_R[RRR_T ]);
@@ -1307,6 +1387,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 4 :/*EXTUI*/ case 5 : +gen_window_check2 (dc,RRR_R ,RRR_T ); {int shiftimm =RRR_S | (_OP1 <<4 );int maskimm = (1 << (_OP2 +1 )) -1 ;
@@ -1332,6 +1413,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 9 :/*LSC4*/ +gen_window_check2 (dc,RRR_S ,RRR_T );switch (_OP2) {case 0 :/*L32E*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER );
@@ -1382,6 +1464,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 1 :/*L32R*/ +gen_window_check1 (dc,RRR_T ); { TCGv_i32 tmp = tcg_const_i32( ((dc->tb->flags & XTENSA_TBFLAG_LITBASE) ?
@@ -1397,6 +1480,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*LSAI*/ #define gen_load_store (type, shift) do { \ TCGv_i32 addr = tcg_temp_local_new_i32(); \ + gen_window_check2(dc, RRI8_S, RRI8_T); \ tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \ if (shift) { \ gen_load_store_alignment(dc, shift, addr); \
@@ -1532,6 +1616,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 10 :/*MOVI*/ +gen_window_check1 (dc,RRI8_T );tcg_gen_movi_i32 (cpu_R[RRI8_T ],RRI8_IMM8 | (RRI8_S <<8 ) | ((RRI8_S &0x8 ) ?0xfffff000 :0 ));
@@ -1543,15 +1628,18 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 12 :/*ADDI*/ +gen_window_check2 (dc,RRI8_S ,RRI8_T );tcg_gen_addi_i32 (cpu_R[RRI8_T ], cpu_R[RRI8_S ],RRI8_IMM8_SE );break ;case 13 :/*ADDMI*/ +gen_window_check2 (dc,RRI8_S ,RRI8_T );tcg_gen_addi_i32 (cpu_R[RRI8_T ], cpu_R[RRI8_S ],RRI8_IMM8_SE <<8 );break ;case 14 :/*S32C1Iy*/ HAS_OPTION (XTENSA_OPTION_MP_SYNCHRO ); +gen_window_check2 (dc,RRI8_S ,RRI8_T ); {int label =gen_new_label ();TCGv_i32 tmp =tcg_temp_local_new_i32 ();
@@ -1604,6 +1692,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*CALL8w*/ case 3 :/*CALL12w*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +gen_window_check1 (dc,CALL_N <<2 );gen_callwi (dc,CALL_N , (dc->pc & ~3 ) + (CALL_OFFSET_SE <<2 ) +4 ,0 );break ;
@@ -1617,6 +1706,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 1 :/*BZ*/ +gen_window_check1 (dc,BRI12_S ); {static const TCGCond cond[] = {TCG_COND_EQ ,/*BEQZ*/
@@ -1631,6 +1721,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 2 :/*BI0*/ +gen_window_check1 (dc,BRI8_S ); {static const TCGCond cond[] = {TCG_COND_EQ ,/*BEQI*/
@@ -1657,6 +1748,7 @@ static void disas_xtensa_insn(DisasContext *dc)tcg_temp_free (imm);tcg_temp_free (s);tcg_temp_free (pc); +reset_used_window (dc); }break ;
@@ -1676,6 +1768,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 9 :/*LOOPNEZ*/ case 10 :/*LOOPGTZ*/ HAS_OPTION (XTENSA_OPTION_LOOP ); +gen_window_check1 (dc,RRI8_S ); {uint32_t lend = dc->pc +RRI8_IMM8 +4 ;TCGv_i32 tmp =tcg_const_i32 (lend);
@@ -1707,6 +1800,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*BLTUI*/ case 3 :/*BGEUI*/ +gen_window_check1 (dc,BRI8_S );gen_brcondi (dc,BRI8_M ==2 ?TCG_COND_LTU :TCG_COND_GEU , cpu_R[BRI8_S ],B4CONSTU [BRI8_R ],4 +BRI8_IMM8_SE );break ;
@@ -1722,6 +1816,7 @@ static void disas_xtensa_insn(DisasContext *dc)switch (RRI8_R &7 ) {case 0 :/*BNONE*/ /*BANY*/ +gen_window_check2 (dc,RRI8_S ,RRI8_T ); {TCGv_i32 tmp =tcg_temp_new_i32 ();tcg_gen_and_i32 (tmp, cpu_R[RRI8_S ], cpu_R[RRI8_T ]);
@@ -1733,6 +1828,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 1 :/*BEQ*/ /*BNE*/ case 2 :/*BLT*/ /*BGE*/ case 3 :/*BLTU*/ /*BGEU*/ +gen_window_check2 (dc,RRI8_S ,RRI8_T ); {static const TCGCond cond[] = { [1 ] =TCG_COND_EQ ,
@@ -1748,6 +1844,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 4 :/*BALL*/ /*BNALL*/ +gen_window_check2 (dc,RRI8_S ,RRI8_T ); {TCGv_i32 tmp =tcg_temp_new_i32 ();tcg_gen_and_i32 (tmp, cpu_R[RRI8_S ], cpu_R[RRI8_T ]);
@@ -1758,6 +1855,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 5 :/*BBC*/ /*BBS*/ +gen_window_check2 (dc,RRI8_S ,RRI8_T ); {TCGv_i32 bit =tcg_const_i32 (1 );TCGv_i32 tmp =tcg_temp_new_i32 ();
@@ -1772,6 +1870,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 6 :/*BBCI*/ /*BBSI*/ case 7 : +gen_window_check1 (dc,RRI8_S ); {TCGv_i32 tmp =tcg_temp_new_i32 (); tcg_gen_andi_i32(tmp, cpu_R[RRI8_S],
@@ -1787,6 +1886,7 @@ static void disas_xtensa_insn(DisasContext *dc)#define gen_narrow_load_store (type) do { \ TCGv_i32 addr = tcg_temp_local_new_i32(); \ + gen_window_check2(dc, RRRN_S, RRRN_T); \ tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \ gen_load_store_alignment(dc, 2, addr); \ tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, 0); \
@@ -1803,14 +1903,17 @@ static void disas_xtensa_insn(DisasContext *dc)#undef gen_narrow_load_storecase 10 :/*ADD.Nn*/ +gen_window_check3 (dc,RRRN_R ,RRRN_S ,RRRN_T );tcg_gen_add_i32 (cpu_R[RRRN_R ], cpu_R[RRRN_S ], cpu_R[RRRN_T ]);break ;case 11 :/*ADDI.Nn*/ +gen_window_check2 (dc,RRRN_R ,RRRN_S );tcg_gen_addi_i32 (cpu_R[RRRN_R ], cpu_R[RRRN_S ],RRRN_T ?RRRN_T :-1 );break ;case 12 :/*ST2n*/ +gen_window_check1 (dc,RRRN_S );if (RRRN_T <8 ) {/*MOVI.Nn*/ tcg_gen_movi_i32(cpu_R[RRRN_S], RRRN_R | (RRRN_T << 4) |
@@ -1826,6 +1929,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 13 :/*ST3n*/ switch (RRRN_R ) {case 0 :/*MOV.Nn*/ +gen_window_check2 (dc,RRRN_S ,RRRN_T );tcg_gen_mov_i32 (cpu_R[RRRN_T ], cpu_R[RRRN_S ]);break ;
@@ -1926,6 +2030,7 @@ static void gen_intermediate_code_internal( dc.ccount_delta =0 ;reset_sar_tracker (&dc); +reset_used_window (&dc);gen_icount_start ();
Signature · 1 line
1.7.3.4
Re: [Qemu-devel] [PATCH 24/26] target-xtensa: implement accurate window check
target-xtensa/translate.c static void gen_waiti(DisasContext *dc, uint32_t imm4) · line 492
Quoted 13 lines · Max Filippov
target-xtensa/translate.c +13
-0+static void gen_window_check1 (DisasContext *dc,unsigned r1) +{ +if (option_enabled (dc,XTENSA_OPTION_WINDOWED_REGISTER ) && + r1 /4 > dc->used_window) { +TCGv_i32 pc =tcg_const_i32 (dc->pc); +TCGv_i32 w =tcg_const_i32 (r1 /4 ); + +gen_advance_ccount (dc); +gen_helper_window_check (pc, w); + +tcg_temp_free (w); +tcg_temp_free (pc); + }
dc->used_window is never set to non-zero. I assume you meant to do that here?
r~
Re: [Qemu-devel] [PATCH 24/26] target-xtensa: implement accurate window check
Quoted 8 lines
Quoted 8 lines
target-xtensa/translate.c +8
-0+static void gen_window_check1 (DisasContext *dc,unsigned r1) +{ +if (option_enabled (dc,XTENSA_OPTION_WINDOWED_REGISTER ) && + r1 /4 > dc->used_window) { +TCGv_i32 pc =tcg_const_i32 (dc->pc); +TCGv_i32 w =tcg_const_i32 (r1 /4 ); + +gen_advance_ccount (dc);
Quoted 8 lines
target-xtensa/translate.c static void gen_waiti(DisasContext *dc, uint32_t imm4) · line 492
Quoted 5 lines
target-xtensa/translate.c +5
-0+gen_helper_window_check (pc, w); + +tcg_temp_free (w); +tcg_temp_free (pc); + }
dc->used_windowis never set to non-zero. I assume you meant to do that here?
Oops (. Thank you, indeed.
Thanks.
-- Max
PATCH 25/26 target-xtensa: implement CPENABLE and PRID SRs
In reply to Max Filippov--- hw/xtensa_sample.c | 1 + target-xtensa/cpu.h | 2 ++ target-xtensa/translate.c | 7 +++++++ 3 files changed, 10 insertions(+), 0 deletions(-)
hw/xtensa_sample.c +1 -0
@@ -45,6 +45,7 @@ static void xtensa_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } + env->sregs[PRID ] = n; } ram_offset =qemu_ram_alloc (NULL ,"xtensa.dram" ,0x10000 );
target-xtensa/cpu.h +2 -0
@@ -118,12 +118,14 @@ enum {DEPC =192 ,EPS2 =194 ,EXCSAVE1 =209 , +CPENABLE =224 ,INTSET =226 ,INTCLEAR =227 ,INTENABLE =228 ,PS =230 ,EXCCAUSE =232 ,CCOUNT =234 , +PRID =235 ,EXCVADDR =238 , CCOMPARE = 240, };
target-xtensa/translate.c +7 -0
@@ -99,12 +99,14 @@ static const char * const sregnames[256] = { [EXCSAVE1 + 4] = "EXCSAVE5", [EXCSAVE1 + 5] = "EXCSAVE6", [EXCSAVE1 + 6] = "EXCSAVE7", + [CPENABLE] = "CPENABLE", [INTSET] = "INTSET", [INTCLEAR] = "INTCLEAR", [INTENABLE] = "INTENABLE", [PS] = "PS", [EXCCAUSE] = "EXCCAUSE", [CCOUNT] = "CCOUNT", + [PRID] = "PRID", [EXCVADDR] = "EXCVADDR", [CCOMPARE] = "CCOMPARE0", [CCOMPARE + 1] = "CCOMPARE1",
@@ -416,6 +418,10 @@ static void gen_wsr_ps(DisasContext *dc, uint32_t sr, TCGv_i32 v)gen_jumpi_check_loop_end (dc,-1 ); } +static void gen_wsr_prid (DisasContext *dc,uint32_t sr,TCGv_i32 v) +{ +} +static void gen_wsr_ccompare (DisasContext *dc,uint32_t sr,TCGv_i32 v) {TCGv_i32 id =tcg_const_i32 (sr -CCOMPARE );
@@ -437,6 +443,7 @@ static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) [WINDOW_BASE] = gen_wsr_windowbase, [WINDOW_START] = gen_wsr_windowstart, [PS] = gen_wsr_ps, + [PRID] = gen_wsr_prid, [CCOMPARE] = gen_wsr_ccompare, [CCOMPARE + 1] = gen_wsr_ccompare, [CCOMPARE + 2] = gen_wsr_ccompare,
Signature · 1 line
1.7.3.4
PATCH 26/26 target-xtensa: implement relocatable vectors
In reply to Max FilippovSee ISA, 4.4.3 for details.
Vector addresses recorded in core configuration are absolute values that correspond to default VECBASE value.
--- target-xtensa/cpu.h | 2 ++ target-xtensa/helper.c | 18 ++++++++++++++++-- target-xtensa/translate.c | 1 + 3 files changed, 19 insertions(+), 2 deletions(-)
target-xtensa/cpu.h +2 -0
@@ -123,6 +123,7 @@ enum {INTCLEAR =227 ,INTENABLE =228 ,PS =230 , +VECBASE =231 ,EXCCAUSE =232 ,CCOUNT =234 , PRID = 235,
@@ -218,6 +219,7 @@ typedef struct XtensaConfig {unsigned nareg;int excm_level;int ndepc; +uint32_t vecbase;uint32_t exception_vector[EXC_MAX ];unsigned ninterrupt;unsigned nlevel;
target-xtensa/helper.c +16 -2
@@ -40,6 +40,7 @@ void cpu_reset(CPUXtensaState *env) env->pc = env->config->exception_vector[EXC_RESET ]; env->sregs[LITBASE ] &= ~1 ; env->sregs[PS ] =0x1f ; + env->sregs[VECBASE ] = env->config->vecbase; env->pending_irq_level =0 ; }
@@ -51,6 +52,7 @@ static const XtensaConfig core_config[] = { .nareg = 64, .ndepc = 1, .excm_level = 16, + .vecbase = 0x5fff8400, .exception_vector = { [EXC_RESET] = 0x5fff8000, [EXC_WINDOW_OVERFLOW4] = 0x5fff8400,
@@ -137,6 +139,16 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)return addr; } +static uint32_t relocated_vector (CPUState *env,uint32_t vector) +{ +if (xtensa_option_enabled (env->config, +XTENSA_OPTION_RELOCATABLE_VECTOR )) { +return vector - env->config->vecbase + env->sregs[VECBASE ]; + }else { +return vector; + } +} +static int handle_interrupt (CPUState *env) {int handled =1 ;
@@ -150,7 +162,8 @@ static int handle_interrupt(CPUState *env)if (level >1 ) { env->sregs[EPC1 + level -1 ] = env->pc; env->sregs[EPS2 + level -2 ] = env->sregs[PS ]; - env->pc = env->config->interrupt_vector[level]; + env->pc =relocated_vector (env, + env->config->interrupt_vector[level]); }else { handled =0 ; env->sregs[EXCCAUSE ] =LEVEL1_INTERRUPT_CAUSE ;
@@ -196,7 +209,8 @@ void do_interrupt(CPUState *env)case EXC_USER :case EXC_DOUBLE :if (env->config->exception_vector[env->exception_index]) { - env->pc = env->config->exception_vector[env->exception_index]; + env->pc =relocated_vector (env, + env->config->exception_vector[env->exception_index]); env->exception_taken =1 ; env->interrupt_request |=CPU_INTERRUPT_EXITTB ; }else {
target-xtensa/translate.c +1 -0
@@ -104,6 +104,7 @@ static const char * const sregnames[256] = { [INTCLEAR] = "INTCLEAR", [INTENABLE] = "INTENABLE", [PS] = "PS", + [VECBASE] = "VECBASE", [EXCCAUSE] = "EXCCAUSE", [CCOUNT] = "CCOUNT", [PRID] = "PRID",
Signature · 1 line
1.7.3.4