target-xtensa: new target architecture
v2 cover target-xtensa: new target architecture
This series adds support for Tensilica Xtensa target. Port status: Linux for DC232B works in the qemu.
Not implemented xtensa options: MAC16, floating point coprocessor, boolean option, cache option, debug option.
v1 -> v2 changes:
- extract PS register and access control into separate patch;
- implement all memory protection options;
- GDB support.
Max Filippov (31):
target-xtensa: add target stubs
target-xtensa: add target to the configure script
target-xtensa: implement disas_xtensa_insn
target-xtensa: implement narrow instructions
target-xtensa: implement RT0 group
target-xtensa: add sample board
target-xtensa: implement conditional jumps
target-xtensa: implement JX/RET0/CALLX
target-xtensa: add special and user registers
target-xtensa: implement RST3 group
target-xtensa: implement shifts (ST1 and RST1 groups)
target-xtensa: implement LSAI group
target-xtensa: mark reserved and TBD opcodes
target-xtensa: implement SYNC group
target-xtensa: implement CACHE group
target-xtensa: add PS register and access control
target-xtensa: implement exceptions
target-xtensa: implement RST2 group (32 bit mul/div/rem)
target-xtensa: implement windowed registers
target-xtensa: implement loop option
target-xtensa: implement extended L32R
target-xtensa: implement unaligned exception option
target-xtensa: implement SIMCALL
target-xtensa: implement interrupt option
target-xtensa: implement accurate window check
target-xtensa: implement CPENABLE and PRID SRs
target-xtensa: implement relocatable vectors
target-xtensa: add gdb support
target-xtensa: implement memory protection options
target-xtensa: add dc232b core and board
MAINTAINERS: add xtensa maintainer
MAINTAINERS | 13 + Makefile.target | 5 + arch_init.c | 2 + arch_init.h | 1 + configure | 12 +- cpu-exec.c | 8 + default-configs/xtensa-softmmu.mak | 1 + default-configs/xtensaeb-softmmu.mak | 1 + elf.h | 2 + gdbstub.c | 96 + hw/xtensa_dc232b.c | 112 ++ hw/xtensa_pic.c | 126 ++ hw/xtensa_sample.c | 106 ++ qemu-options.hx | 4 +- target-xtensa/cpu.h | 422 +++++ target-xtensa/exec.h | 39 + target-xtensa/gdb-config-dc232b.c | 261 +++ target-xtensa/gdb-config-sample-xtensa-core.c | 375 ++++ target-xtensa/helper.c | 745 ++++++++ target-xtensa/helpers.h | 31 + target-xtensa/machine.c | 38 + target-xtensa/op_helper.c | 662 +++++++ target-xtensa/translate.c | 2288 +++++++++++++++++++++++++ xtensa-semi.c | 223 +++ 24 files changed, 5570 insertions(+), 3 deletions(-) create mode 100644 default-configs/xtensa-softmmu.mak create mode 100644 default-configs/xtensaeb-softmmu.mak create mode 100644 hw/xtensa_dc232b.c create mode 100644 hw/xtensa_pic.c create mode 100644 hw/xtensa_sample.c create mode 100644 target-xtensa/cpu.h create mode 100644 target-xtensa/exec.h create mode 100644 target-xtensa/gdb-config-dc232b.c create mode 100644 target-xtensa/gdb-config-sample-xtensa-core.c create mode 100644 target-xtensa/helper.c create mode 100644 target-xtensa/helpers.h create mode 100644 target-xtensa/machine.c create mode 100644 target-xtensa/op_helper.c create mode 100644 target-xtensa/translate.c create mode 100644 xtensa-semi.c
Signature · 1 line
1.7.3.4
PATCH v2 1/31 target-xtensa: add target stubs
--- Makefile.target | 2 + arch_init.c | 2 + arch_init.h | 1 + cpu-exec.c | 2 + elf.h | 2 + hw/xtensa_pic.c | 38 ++++++++++++++++++ target-xtensa/cpu.h | 95 +++++++++++++++++++++++++++++++++++++++++++++ target-xtensa/exec.h | 39 ++++++++++++++++++ target-xtensa/helper.c | 73 ++++++++++++++++++++++++++++++++++ target-xtensa/machine.c | 38 ++++++++++++++++++ target-xtensa/op_helper.c | 51 ++++++++++++++++++++++++ target-xtensa/translate.c | 67 +++++++++++++++++++++++++++++++ 12 files changed, 410 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
@@ -372,6 +372,8 @@ obj-s390x-y = s390-virtio-bus.o s390-virtio.o obj-alpha-y = i8259.o mc146818rtc.o obj-alpha-y += vga.o cirrus_vga.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 +2 -0
@@ -222,6 +222,7 @@ int cpu_exec(CPUState *env)#elif defined(TARGET_SH4 )#elif defined(TARGET_CRIS )#elif defined(TARGET_S390X ) +#elif defined(TARGET_XTENSA )/* XXXXX */ #else #error unsupported target CPU
@@ -616,6 +617,7 @@ int cpu_exec(CPUState *env)#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 +95 -0
95 lines not on this page · raw message
target-xtensa/exec.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* 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 "config.h" +#include "dyngen-exec.h" + +register struct CPUXtensaState *env asm(AREG0); + +#include "cpu.h" + +#if !defined(CONFIG_USER_ONLY ) +#include "softmmu_exec.h" +#endif + +void raise_exception (int );
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 v2 2/31 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
@@ -856,6 +856,8 @@ sh4eb-softmmu \ sparc-softmmu \ sparc64-softmmu \ s390x-softmmu \ +xtensa-softmmu \ +xtensaeb-softmmu \ " fi # the following are Linux specific
@@ -3055,7 +3057,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
@@ -3250,6 +3252,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
@@ -3423,6 +3429,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 v2 3/31 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.
--- target-xtensa/cpu.h | 67 +++++++ target-xtensa/helper.c | 27 +++- target-xtensa/helpers.h | 5 + target-xtensa/op_helper.c | 7 + target-xtensa/translate.c | 452 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 556 insertions(+), 2 deletions(-) create mode 100644 target-xtensa/helpers.h
target-xtensa/cpu.h +67 -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,13 @@ 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); +#define XTENSA_OPTION_BIT (opt) (((uint64_t)1) << (opt)) + +static inline bool xtensa_option_enabled (const XtensaConfig *config,int opt) +{ +return (config->options &XTENSA_OPTION_BIT (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 (env); +}
target-xtensa/translate.c +452 -0
469 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 4/31 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
@@ -106,6 +106,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);
@@ -377,22 +382,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 v2 5/31 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
@@ -255,6 +255,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 v2 6/31 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 | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 0 deletions(-) create mode 100644 hw/xtensa_sample.c
Makefile.target +1 -0
@@ -373,6 +373,7 @@ obj-alpha-y = i8259.o mc146818rtc.o obj-alpha-y += vga.o cirrus_vga.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 +105 -0
105 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 7/31 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).
--- target-xtensa/translate.c | 164 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 164 insertions(+), 0 deletions(-)
target-xtensa/translate.c +164 -0
@@ -121,6 +121,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 { \
@@ -202,6 +221,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 );
@@ -395,10 +422,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 { \
@@ -431,6 +591,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 v2 8/31 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
@@ -248,6 +248,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 v2 9/31 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
PATCH v2 10/31 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.
--- target-xtensa/translate.c | 161 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 161 insertions(+), 0 deletions(-)
target-xtensa/translate.c +161 -0
@@ -167,6 +167,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 { \
@@ -415,6 +449,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 v2 11/31 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.
---
v1 -> v2 changes:
- fix nsa helper implementation;
--- target-xtensa/cpu.h | 4 + target-xtensa/helpers.h | 2 + target-xtensa/op_helper.c | 14 +++ target-xtensa/translate.c | 242 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 262 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 (env); } + +uint32_t HELPER (nsa )(uint32_t v) +{ +if (v &0x80000000 ) { + v = ~v; + } +return v ?clz32 (v) -1 :31 ; +} + +uint32_t HELPER (nsau )(uint32_t v) +{ +return v ?clz32 (v) :32 ; +}
target-xtensa/translate.c +242 -0
300 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 12/31 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 | 89 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 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 +89 -0
102 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 13/31 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
@@ -267,6 +267,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)
@@ -367,9 +375,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*/
@@ -381,9 +391,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 ;
@@ -404,6 +416,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*CALLX8w*/ case 3 :/*CALLX12w*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ; }break ;
@@ -412,12 +425,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 ; }
@@ -473,13 +533,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*/
@@ -493,11 +556,13 @@ static void disas_xtensa_insn(DisasContext *dc)break ;default :/*reserved*/ +RESERVED ();break ; }break ;case 5 :/*TLB*/ +TBD ();break ;case 6 :/*RT0*/
@@ -518,11 +583,13 @@ static void disas_xtensa_insn(DisasContext *dc)break ;default :/*reserved*/ +RESERVED ();break ; }break ;case 7 :/*reserved*/ +RESERVED ();break ;case 8 :/*ADD*/
@@ -582,6 +649,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 ;
@@ -671,21 +741,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*/
@@ -778,10 +856,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*/
@@ -791,6 +871,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 ;
@@ -801,6 +882,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 ;
@@ -822,27 +904,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 ;
@@ -894,6 +983,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 7 :/*CACHEc*/ +TBD ();break ;case 9 :/*L16SI*/
@@ -946,6 +1036,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;default :/*reserved*/ +RESERVED ();break ; }break ;
@@ -953,10 +1044,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*/
@@ -970,6 +1063,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*CALL8w*/ case 3 :/*CALL12w*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ; }break ;
@@ -1012,28 +1106,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 ; }
@@ -1169,28 +1270,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 v2 14/31 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
@@ -429,7 +429,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 v2 15/31 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
@@ -1012,7 +1012,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 v2 16/31 target-xtensa: add PS register and access control
In reply to Max Filippov--- target-xtensa/cpu.h | 53 ++++++++++++++++++++++++++++++++++++++++++++- target-xtensa/helper.c | 1 + target-xtensa/translate.c | 29 ++++++++++++++++++++---- 3 files changed, 77 insertions(+), 6 deletions(-)
target-xtensa/cpu.h +52 -1
@@ -108,8 +108,27 @@ enum {enum {SAR =3 ,SCOMPARE1 =12 , +PS =230 , }; +#define PS_INTLEVEL 0xf +#define PS_INTLEVEL_SHIFT 0 + +#define PS_EXCM 0x10 +#define PS_UM 0x20 + +#define PS_RING 0xc0 +#define PS_RING_SHIFT 6 + +#define PS_OWB 0xf00 +#define PS_OWB_SHIFT 8 + +#define PS_CALLINC 0x30000 +#define PS_CALLINC_SHIFT 16 +#define PS_CALLINC_LEN 2 + +#define PS_WOE 0x40000 + typedef struct XtensaConfig { const char *name; uint64_t options;
@@ -145,17 +164,49 @@ static inline bool xtensa_option_enabled(const XtensaConfig *config, int opt)return (config->options &XTENSA_OPTION_BIT (opt)) !=0 ; } +static inline int xtensa_get_ring (const CPUState *env) +{ +if (xtensa_option_enabled (env->config,XTENSA_OPTION_MMU )) { +return (env->sregs[PS ] &PS_RING ) >>PS_RING_SHIFT ; + }else { +return 0 ; + } +} + +static inline int xtensa_get_cring (const CPUState *env) +{ +if (xtensa_option_enabled (env->config,XTENSA_OPTION_MMU ) && + (env->sregs[PS ] &PS_EXCM ) ==0 ) { +return (env->sregs[PS ] &PS_RING ) >>PS_RING_SHIFT ; + }else { +return 0 ; + } +} + +/* MMU modes definitions */ +#define MMU_MODE0_SUFFIX _ring0 +#define MMU_MODE1_SUFFIX _ring1 +#define MMU_MODE2_SUFFIX _ring2 +#define MMU_MODE3_SUFFIX _ring3 +static inline int cpu_mmu_index (CPUState *env) { -return 0 ; +return xtensa_get_cring (env); } +#define XTENSA_TBFLAG_RING_MASK 0x3 +#define XTENSA_TBFLAG_EXCM 0x4 +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 ; + *flags |=xtensa_get_ring (env); +if (env->sregs[PS ] &PS_EXCM ) { + *flags |=XTENSA_TBFLAG_EXCM ; + } }#include "cpu-all.h"
target-xtensa/helper.c +1 -0
@@ -37,6 +37,7 @@void cpu_reset (CPUXtensaState *env) { env->pc =0 ; + env->sregs[PS ] =0x1f ; }static const XtensaConfig core_config[] = {
target-xtensa/translate.c +24 -5
@@ -45,6 +45,8 @@ typedef struct DisasContext {TranslationBlock *tb;uint32_t pc;uint32_t next_pc; +int cring; +int ring;int is_jmp;int singlestep_enabled;
@@ -65,6 +67,7 @@ static TCGv_i32 cpu_UR[256];static const char *const sregnames[256 ] = { [SAR ] ="SAR" , [SCOMPARE1 ] ="SCOMPARE1" , + [PS ] ="PS" , };static const char *const uregnames[256 ] = {
@@ -239,11 +242,25 @@ static void gen_wsr_sar(DisasContext *dc, uint32_t sr, TCGv_i32 s) dc->sar_m32_5bit = false; } +static void gen_wsr_ps (DisasContext *dc,uint32_t sr,TCGv_i32 v) +{ +uint32_t mask =PS_WOE |PS_CALLINC |PS_OWB | +PS_UM |PS_EXCM |PS_INTLEVEL ; + +if (option_enabled (dc,XTENSA_OPTION_MMU )) { + mask |=PS_RING ; + } +tcg_gen_andi_i32 (cpu_SR[sr], v, mask); +/* This can change mmu index, so exit tb */ +gen_jumpi (dc, dc->next_pc,-1 ); +} +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) = { [SAR ] = gen_wsr_sar, + [PS ] = gen_wsr_ps, };if (sregnames[sr]) {
@@ -973,7 +990,7 @@ static void disas_xtensa_insn(DisasContext *dc)/* no ext L32R */ -tcg_gen_qemu_ld32u (cpu_R[RRR_T ], tmp,0 ); +tcg_gen_qemu_ld32u (cpu_R[RRR_T ], tmp, dc->cring);tcg_temp_free (tmp); }break ;
@@ -982,7 +999,7 @@ static void disas_xtensa_insn(DisasContext *dc)#define gen_load_store (type, shift) do { \ TCGv_i32 addr = tcg_temp_new_i32(); \ tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \ - tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, 0); \ + tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \ tcg_temp_free(addr); \ } while (0)
@@ -1140,11 +1157,11 @@ 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 ); -tcg_gen_qemu_ld32u (cpu_R[RRI8_T ], addr,0 ); +tcg_gen_qemu_ld32u (cpu_R[RRI8_T ], addr, dc->cring);tcg_gen_brcond_i32 (TCG_COND_NE , cpu_R[RRI8_T ], cpu_SR[SCOMPARE1 ], label); -tcg_gen_qemu_st32 (tmp, addr,0 ); +tcg_gen_qemu_st32 (tmp, addr, dc->cring);gen_set_label (label);tcg_temp_free (addr);
@@ -1345,7 +1362,7 @@ static void disas_xtensa_insn(DisasContext *dc)#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_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \ tcg_temp_free(addr); \ } while (0)
@@ -1468,6 +1485,8 @@ static void gen_intermediate_code_internal( dc.singlestep_enabled = env->singlestep_enabled; dc.tb = tb; dc.pc = pc_start; + dc.ring = tb->flags &XTENSA_TBFLAG_RING_MASK ; + dc.cring = (tb->flags &XTENSA_TBFLAG_EXCM ) ?0 : dc.ring; dc.is_jmp =DISAS_NEXT ;init_sar_tracker (&dc);
Signature · 1 line
1.7.3.4
PATCH v2 17/31 target-xtensa: implement exceptions
In reply to Max Filippov- mark privileged opcodes with ring check;
- make debug exception on exception handler entry.
--- cpu-exec.c | 6 +++ target-xtensa/cpu.h | 67 ++++++++++++++++++++++++++++ target-xtensa/helper.c | 37 +++++++++++++++- target-xtensa/helpers.h | 2 + target-xtensa/op_helper.c | 29 ++++++++++++ target-xtensa/translate.c | 107 ++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 242 insertions(+), 6 deletions(-)
cpu-exec.c +6 -0
@@ -488,6 +488,12 @@ int cpu_exec(CPUState *env)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 +67 -0
95 lines not on this page · raw message
target-xtensa/helper.c +36 -1
@@ -36,7 +36,8 @@void cpu_reset (CPUXtensaState *env) { - env->pc =0 ; + env->exception_taken =0 ; + env->pc = env->config->exception_vector[EXC_RESET ]; env->sregs[PS ] =0x1f ; }
@@ -44,6 +45,20 @@ 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, + }, }, };
@@ -94,4 +109,24 @@ 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 ; + + } }
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 (env); } +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 +102 -5
172 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 18/31 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
@@ -878,7 +878,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 v2 19/31 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 | 144 +++++++++++++++++++++++++++++++++-- 5 files changed, 337 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);#define XTENSA_OPTION_BIT (opt) (((uint64_t)1) << (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 +135 -9
228 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 20/31 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.
---
v1 -> v2 changes:
- chain TBs around the loop;
- avoid extra jump generation in the gen_jumpi_check_loop_end;
--- target-xtensa/cpu.h | 3 ++ target-xtensa/helpers.h | 2 + target-xtensa/op_helper.c | 20 ++++++++++++ target-xtensa/translate.c | 77 +++++++++++++++++++++++++++++++++++++++----- 4 files changed, 93 insertions(+), 9 deletions(-)
target-xtensa/cpu.h +3 -0
@@ -106,6 +106,9 @@ enum { };enum { +LBEG =0 , +LEND =1 , +LCOUNT =2 ,SAR =3 ,SCOMPARE1 =12 ,WINDOW_BASE =72 ,
target-xtensa/helpers.h +2 -0
@@ -12,6 +12,8 @@ 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_lbeg, void, i32) +DEF_HELPER_1(wsr_lend, void, i32) DEF_HELPER_0(dump_state, void)#include "def-helper.h"
target-xtensa/op_helper.c +20 -0
@@ -280,6 +280,26 @@ void HELPER(movsp)(uint32_t pc) } } +void HELPER (wsr_lbeg )(uint32_t v) +{ +if (env->sregs[LBEG ] != v) { +tb_invalidate_phys_page_range ( + env->sregs[LEND ] -1 , env->sregs[LEND ],0 ); + env->sregs[LBEG ] = v; + } +} + +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 +68 -9
140 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 21/31 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.
---
v1 -> v2 changes:
- do not encode LITBASE value into TB;
--- target-xtensa/cpu.h | 6 ++++++ target-xtensa/helper.c | 1 + target-xtensa/translate.c | 37 +++++++++++++++++++++++++++++++++---- 3 files changed, 40 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,
@@ -274,6 +275,7 @@ static inline int cpu_mmu_index(CPUState *env)#define XTENSA_TBFLAG_RING_MASK 0x3#define XTENSA_TBFLAG_EXCM 0x4 +#define XTENSA_TBFLAG_LITBASE 0x8static inline void cpu_get_tb_cpu_state (CPUState *env,target_ulong *pc,target_ulong *cs_base,int *flags)
@@ -285,6 +287,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 +33 -4
@@ -49,6 +49,7 @@ typedef struct DisasContext {int ring;uint32_t lbeg;uint32_t lend; +TCGv_i32 litbase;int is_jmp;int singlestep_enabled;
@@ -71,6 +72,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",
@@ -132,6 +134,21 @@ static inline bool option_enabled(DisasContext *dc, int opt)return xtensa_option_enabled (dc->config, opt); } +static void init_litbase (DisasContext *dc) +{ +if (dc->tb->flags &XTENSA_TBFLAG_LITBASE ) { + dc->litbase =tcg_temp_local_new_i32 (); +tcg_gen_andi_i32 (dc->litbase, cpu_SR[LITBASE ],0xfffff000 ); + } +} + +static void reset_litbase (DisasContext *dc) +{ +if (dc->tb->flags &XTENSA_TBFLAG_LITBASE ) { +tcg_temp_free (dc->litbase); + } +} +static void init_sar_tracker (DisasContext *dc) { dc->sar_5bit = false;
@@ -332,6 +349,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);
@@ -357,6 +381,7 @@ static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) [LBEG] = gen_wsr_lbeg, [LEND] = gen_wsr_lend, [SAR] = gen_wsr_sar, + [LITBASE] = gen_wsr_litbase, [WINDOW_BASE] = gen_wsr_windowbase, [PS] = gen_wsr_ps, };
@@ -1281,11 +1306,13 @@ 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 ) ? +0 : ((dc->pc +3 ) & ~3 )) + + (0xfffc0000 | (RI16_IMM16 <<2 ))); +if (dc->tb->flags &XTENSA_TBFLAG_LITBASE ) { +tcg_gen_add_i32 (tmp, tmp, dc->litbase); + }tcg_gen_qemu_ld32u (cpu_R[RRR_T ], tmp, dc->cring);tcg_temp_free (tmp); }
@@ -1817,6 +1844,7 @@ static void gen_intermediate_code_internal( dc.lend = env->sregs[LEND ]; dc.is_jmp =DISAS_NEXT ; +init_litbase (&dc);init_sar_tracker (&dc);gen_icount_start ();
@@ -1859,6 +1887,7 @@ static void gen_intermediate_code_internal( dc.pc < next_page_start && gen_opc_ptr < gen_opc_end); +reset_litbase (&dc);reset_sar_tracker (&dc);if (dc.is_jmp ==DISAS_NEXT ) {
Signature · 1 line
1.7.3.4
PATCH v2 22/31 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.
---
v1 -> v2 changes:
- use ALIGNED_ONLY to handle unaligned memory access;
--- target-xtensa/helper.c | 4 ++- target-xtensa/op_helper.c | 26 ++++++++++++++++++++++++ target-xtensa/translate.c | 47 ++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 73 insertions(+), 4 deletions(-)
target-xtensa/helper.c +3 -1
@@ -45,7 +45,9 @@ void cpu_reset(CPUXtensaState *env)static const XtensaConfig core_config[] = { { .name ="sample-xtensa-core" , - .options =-1 , + .options =-1 ^ + (XTENSA_OPTION_BIT (XTENSA_OPTION_HW_ALIGNMENT ) | +XTENSA_OPTION_BIT (XTENSA_OPTION_MMU )), .nareg =64 , .ndepc =1 , .excm_level =16 ,
target-xtensa/op_helper.c +26 -0
@@ -29,6 +29,10 @@#include "helpers.h" #include "host-utils.h" +static void do_unaligned_access (target_ulong addr,int is_write,int is_user, +void *retaddr); + +#define ALIGNED_ONLY #define MMUSUFFIX _mmu#define SHIFT 0
@@ -43,6 +47,28 @@#define SHIFT 3#include "softmmu_template.h" +static void do_restore_state (void *pc_ptr) +{ +TranslationBlock *tb; +uint32_t pc = (uint32_t )(intptr_t )pc_ptr; + + tb =tb_find_pc (pc); +if (tb) { +cpu_restore_state (tb, env, pc); + } +} + +static void do_unaligned_access (target_ulong addr,int is_write,int is_user, +void *retaddr) +{ +if (xtensa_option_enabled (env->config,XTENSA_OPTION_UNALIGNED_EXCEPTION ) && + !xtensa_option_enabled (env->config,XTENSA_OPTION_HW_ALIGNMENT )) { +do_restore_state (retaddr); +HELPER (exception_cause_vaddr)( + env->pc,LOAD_STORE_ALIGNMENT_CAUSE , addr); + } +} +void tlb_fill (target_ulong addr,int is_write,int mmu_idx,void *retaddr) { tlb_set_page(cpu_single_env,
target-xtensa/translate.c +44 -3
104 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 23/31 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.
Note that simcalls that accept buffer addresses expect virtual addresses.
--- Makefile.target | 1 + qemu-options.hx | 4 +- target-xtensa/helpers.h | 1 + target-xtensa/translate.c | 9 ++- xtensa-semi.c | 223 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 235 insertions(+), 3 deletions(-) create mode 100644 xtensa-semi.c
Makefile.target +1 -0
@@ -374,6 +374,7 @@ obj-alpha-y += vga.o cirrus_vga.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
@@ -2375,11 +2375,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/helpers.h +1 -0
@@ -14,6 +14,7 @@ DEF_HELPER_0(restore_owb, void) DEF_HELPER_1(movsp, void, i32) DEF_HELPER_1(wsr_lbeg, void, i32) DEF_HELPER_1(wsr_lend, void, i32) +DEF_HELPER_1(simcall, void, env) DEF_HELPER_0(dump_state, void)#include "def-helper.h"
target-xtensa/translate.c +8 -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
@@ -726,7 +727,13 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 1 :/*SIMCALL*/ -TBD (); +if (semihosting_enabled) { +gen_check_privilege (dc); +gen_helper_simcall (cpu_env); + }else { +qemu_log ("SIMCALL but semihosting is disabled\n" ); +gen_exception_cause (dc,ILLEGAL_INSTRUCTION_CAUSE ); + }break ;default :
xtensa-semi.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 24/31 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.
---
v1 -> v2 changes:
- don't reset env->halted in xtensa_advance_ccount;
- clean up cases in the do_interrupt switch;
--- hw/xtensa_pic.c | 88 ++++++++++++++++++++++++++++++++++++ target-xtensa/cpu.h | 43 +++++++++++++++++- target-xtensa/helper.c | 79 ++++++++++++++++++++++++++++++++ target-xtensa/helpers.h | 4 ++ target-xtensa/op_helper.c | 41 +++++++++++++++++ target-xtensa/translate.c | 109 ++++++++++++++++++++++++++++++++++++++++---- 6 files changed, 353 insertions(+), 11 deletions(-)
hw/xtensa_pic.c +88 -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,89 @@ 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) { +xtensa_timer_irq (env, i,1 ); + } + } + } +} + +void check_interrupts (CPUState *env) +{ +int minlevel =xtensa_get_cintlevel (env); +int level; + +/* If the CPU is halted advance CCOUNT according to the vm_clock time +* elapsed since the moment when it was advanced last time. +*/ +if (env->halted) { +int64_t now =qemu_get_clock_ns (vm_clock); + +xtensa_advance_ccount (env, +muldiv64 (now - env->halt_clock, + env->config->clock_freq_khz,1000000 )); + env->halt_clock = now; + } +for (level = env->config->nlevel; level > minlevel; --level) { +if (env->config->level_mask[level] & + env->sregs[INTSET ] & + env->sregs[INTENABLE ]) { + 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 +42 -1
89 lines not on this page · raw message
target-xtensa/helper.c +79 -0
110 lines not on this page · raw message
target-xtensa/helpers.h +4 -0
@@ -17,4 +17,8 @@ DEF_HELPER_1(wsr_lend, void, i32) DEF_HELPER_1(simcall, void, env) DEF_HELPER_0(dump_state, 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 +41 -0
44 lines not on this page · raw message
target-xtensa/translate.c +99 -10
259 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 25/31 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.
---
v1 -> v2 changes:
- dc->used_window is updated as necessary in the gen_window_check1;
--- target-xtensa/translate.c | 110 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 110 insertions(+), 0 deletions(-)
target-xtensa/translate.c +110 -0
@@ -60,6 +60,7 @@ typedef struct DisasContext {TCGv_i32 sar_m32;uint32_t ccount_delta; +unsigned used_window; } DisasContext;static TCGv_ptr cpu_env;
@@ -225,6 +226,11 @@ static void gen_advance_ccount(DisasContext *dc) } } +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);
@@ -418,6 +424,13 @@ 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)
@@ -429,6 +442,7 @@ static void gen_wsr_ps(DisasContext *dc, uint32_t sr, TCGv_i32 v) mask |=PS_RING ; }tcg_gen_andi_i32 (cpu_SR[sr], v, mask); +reset_used_window (dc);/* This can change mmu index and tb->flags, so exit tb */ gen_jumpi_check_loop_end (dc,-1 ); }
@@ -453,6 +467,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,
@@ -497,6 +512,36 @@ static void gen_waiti(DisasContext *dc, uint32_t imm4)tcg_temp_free (intlevel); } +static void gen_window_check1 (DisasContext *dc,unsigned r1) +{ +if (dc->tb->flags &XTENSA_TBFLAG_EXCM ) { +return ; + } +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 ); + + dc->used_window = 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 { \
@@ -626,6 +671,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 ;
@@ -647,6 +693,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*/ {
@@ -677,6 +724,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);
@@ -821,6 +869,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_andi_i32 (cpu_SR[PS ], cpu_SR[PS ], ~PS_INTLEVEL );tcg_gen_ori_i32 (cpu_SR[PS ], cpu_SR[PS ],RRR_S );
@@ -860,28 +909,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 );
@@ -891,6 +946,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 );
@@ -924,16 +980,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 ;
@@ -948,6 +1007,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 ]);
@@ -975,12 +1035,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 );
@@ -990,12 +1052,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 );
@@ -1010,17 +1074,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 ;
@@ -1030,6 +1097,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);
@@ -1056,6 +1124,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 ]);
@@ -1064,6 +1133,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 {
@@ -1074,6 +1144,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 {
@@ -1088,6 +1159,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 {
@@ -1101,6 +1173,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 ();
@@ -1114,6 +1187,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 ();
@@ -1132,6 +1206,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 ();
@@ -1199,6 +1275,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 ();
@@ -1209,6 +1286,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 ();
@@ -1217,6 +1295,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 ;
@@ -1235,6 +1314,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 ();
@@ -1262,6 +1342,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 ,
@@ -1289,6 +1370,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 ,
@@ -1314,6 +1396,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]) {
@@ -1326,6 +1409,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 ]);
@@ -1341,6 +1425,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 ;
@@ -1366,6 +1451,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 );
@@ -1414,6 +1500,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) ?
@@ -1431,6 +1518,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*LSAI*/ #define gen_load_store (type, shift) do { \ TCGv_i32 addr = tcg_temp_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, false); \
@@ -1567,6 +1655,7 @@ static void disas_xtensa_insn(DisasContext *dc)#undef gen_load_storecase 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 ));
@@ -1574,6 +1663,7 @@ static void disas_xtensa_insn(DisasContext *dc)#define gen_load_store_no_hw_align (type) 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 << 2); \ gen_load_store_alignment(dc, 2, addr, true); \ tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, dc->cring); \
@@ -1586,15 +1676,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 ();
@@ -1648,6 +1741,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 ;
@@ -1661,6 +1755,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*/
@@ -1675,6 +1770,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*/
@@ -1701,6 +1797,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 ;
@@ -1720,6 +1817,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);
@@ -1751,6 +1849,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 ;
@@ -1766,6 +1865,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 ]);
@@ -1777,6 +1877,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 ,
@@ -1792,6 +1893,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 ]);
@@ -1802,6 +1904,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 ();
@@ -1816,6 +1919,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],
@@ -1831,6 +1935,7 @@ static void disas_xtensa_insn(DisasContext *dc)#define gen_narrow_load_store (type) do { \ TCGv_i32 addr = tcg_temp_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, false); \ tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, dc->cring); \
@@ -1847,14 +1952,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) |
@@ -1870,6 +1978,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 ;
@@ -1973,6 +2082,7 @@ static void gen_intermediate_code_internal(init_litbase (&dc);init_sar_tracker (&dc); +reset_used_window (&dc);gen_icount_start ();
Signature · 1 line
1.7.3.4
PATCH v2 26/31 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
@@ -51,6 +51,7 @@ static void xtensa_init(ram_addr_t ram_size,exit (1 ); }qemu_register_reset (xtensa_sample_reset, env); + 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
@@ -101,12 +101,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",
@@ -447,6 +449,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 );
@@ -469,6 +475,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 v2 27/31 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 ; }
@@ -53,6 +54,7 @@ static const XtensaConfig core_config[] = { .nareg = 64, .ndepc = 1, .excm_level = 16, + .vecbase = 0x5fff8400, .exception_vector = { [EXC_RESET] = 0x5fff8000, [EXC_WINDOW_OVERFLOW4] = 0x5fff8400,
@@ -139,6 +141,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; + } +} +/*! * Handle penging IRQ. * For the high priority interrupt jump to the corresponding interrupt vector.
@@ -158,7 +170,8 @@ static bool 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 = false; env->sregs[EXCCAUSE ] =LEVEL1_INTERRUPT_CAUSE ;
@@ -199,7 +212,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 ; }else { qemu_log("%s(pc = %08x) bad exception_index: %d\n",
target-xtensa/translate.c +1 -0
@@ -106,6 +106,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
PATCH v2 28/31 target-xtensa: add gdb support
In reply to Max FilippovSpecific xtensa processor overlay for GDB contains register map in the gdb/xtensa-config.c. This description is used by the GDB to e.g. parse 'g' response packets and it may be reused in the qemu's gdbstub (only XTREG definitions for non-pseudoregisters are needed).
Currently mainline GDB does not support operations with privileged SRs (see http://sourceware.org/ml/gdb/2011-07/msg00075.html). This support may be enabled, see NUM_CORE_REGS comment in the gdbstub.c
--- gdbstub.c | 96 +++++++ target-xtensa/cpu.h | 14 + target-xtensa/gdb-config-sample-xtensa-core.c | 375 +++++++++++++++++++++++++ target-xtensa/helper.c | 11 + 4 files changed, 496 insertions(+), 0 deletions(-) create mode 100644 target-xtensa/gdb-config-sample-xtensa-core.c
gdbstub.c +96 -0
@@ -1541,6 +1541,94 @@ static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) }return 4 ; } +#elif defined(TARGET_XTENSA) + +/* Use num_core_regs to see only non-privileged registers in an unmodified gdb. +* Use num_regs to see all registers. gdb modification is required for that: +* reset bit 0 in the 'flags' field of the registers definitions in the +* gdb/xtensa-config.c inside gdb source tree or inside gdb overlay. +*/ +#define NUM_CORE_REGS (env->config->gdb_regmap.num_regs) +#define num_g_regs NUM_CORE_REGS + +static int cpu_gdb_read_register (CPUState *env,uint8_t *mem_buf,int n) +{ +const XtensaGdbReg *reg = env->config->gdb_regmap.reg + n; + +if (n <0 || n >= env->config->gdb_regmap.num_regs) { +return 0 ; + } + +switch (reg->type) { +case 9 :/*pc*/ +GET_REG32 (env->pc); +break ; + +case 1 :/*ar*/ +xtensa_sync_phys_from_window (env); +GET_REG32 (env->phys_regs[(reg->targno &0xff ) % env->config->nareg]); +break ; + +case 2 :/*SR*/ +GET_REG32 (env->sregs[reg->targno &0xff ]); +break ; + +case 3 :/*UR*/ +GET_REG32 (env->uregs[reg->targno &0xff ]); +break ; + +case 8 :/*a*/ +GET_REG32 (env->regs[reg->targno &0x0f ]); +break ; + +default : +qemu_log ("%s from reg %d of unsupported type %d\n" , + __func__, n, reg->type); +return 0 ; + } +} + +static int cpu_gdb_write_register (CPUState *env,uint8_t *mem_buf,int n) +{ +uint32_t tmp; +const XtensaGdbReg *reg = env->config->gdb_regmap.reg + n; + +if (n <0 || n >= env->config->gdb_regmap.num_regs) { +return 0 ; + } + + tmp =ldl_p (mem_buf); + +switch (reg->type) { +case 9 :/*pc*/ + env->pc = tmp; +break ; + +case 1 :/*ar*/ + env->phys_regs[(reg->targno &0xff ) % env->config->nareg] = tmp; +xtensa_sync_window_from_phys (env); +break ; + +case 2 :/*SR*/ + env->sregs[reg->targno &0xff ] = tmp; +break ; + +case 3 :/*UR*/ + env->uregs[reg->targno &0xff ] = tmp; +break ; + +case 8 :/*a*/ + env->regs[reg->targno &0x0f ] = tmp; +break ; + +default : +qemu_log ("%s to reg %d of unsupported type %d\n" , + __func__, n, reg->type); +return 0 ; + } + +return 4 ; +}#else #define NUM_CORE_REGS 0
@@ -1557,7 +1645,9 @@ static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n)#endif +#if !defined(TARGET_XTENSA )static int num_g_regs =NUM_CORE_REGS ; +#endif #ifdef GDB_CORE_XML /* Encode data using the encoding for 'x' packets. */
@@ -1654,6 +1744,7 @@ static int gdb_write_register(CPUState *env, uint8_t *mem_buf, int reg)return 0 ; } +#if !defined(TARGET_XTENSA )/* Register a supplemental set of CPU registers. If g_pos is nonzero it specifies the first register number and these registers are included in a standard "g" packet. Direction is relative to gdb, i.e. get_reg is
@@ -1693,6 +1784,7 @@ void gdb_register_coprocessor(CPUState * env, } } } +#endif #ifndef CONFIG_USER_ONLY static const int xlat_gdb_type[] = {
@@ -1818,6 +1910,8 @@ static void gdb_set_cpu_pc(GDBState *s, target_ulong pc) s->c_cpu->psw.addr = pc;#elif defined (TARGET_LM32 ) s->c_cpu->pc = pc; +#elif defined(TARGET_XTENSA ) + s->c_cpu->pc = pc;#endif }
@@ -1988,6 +2082,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)break ;case 'g' :cpu_synchronize_state (s->g_cpu); + env = s->g_cpu; len =0 ;for (addr =0 ; addr < num_g_regs; addr++) { reg_size =gdb_read_register (s->g_cpu, mem_buf + len, addr);
@@ -1998,6 +2093,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf)break ;case 'G' :cpu_synchronize_state (s->g_cpu); + env = s->g_cpu; registers = mem_buf; len =strlen (p) /2 ;hextomem ((uint8_t *)registers, p, len);
target-xtensa/cpu.h +14 -0
@@ -213,9 +213,23 @@ typedef enum {INTTYPE_WRITE_ERR , } interrupt_type_t; +typedef struct XtensaGdbReg { +int targno; +int type; +int group; +}XtensaGdbReg ; + +typedef struct XtensaGdbRegmap { +int num_regs; +int num_core_regs; +/* PC + a + ar + sr + ur */ +XtensaGdbReg reg[1 +16 +64 +256 +256 ]; +}XtensaGdbRegmap ; + typedef struct XtensaConfig { const char *name; uint64_t options; + XtensaGdbRegmap gdb_regmap; unsigned nareg; int excm_level; int ndepc;
target-xtensa/gdb-config-sample-xtensa-core.c new file +375 -0
375 lines not on this page · raw message
target-xtensa/helper.c +11 -0
@@ -34,6 +34,10 @@#include "hw/loader.h" #endif +#define XTREG (idx, ofs, bi, sz, al, _targno, flags, cp, typ, _group, name, \ + a1, a2, a3, a4, a5, a6) \ + { .targno = (_targno), .type = (typ), .group = (_group) }, +void cpu_reset (CPUXtensaState *env) { env->exception_taken =0 ;
@@ -51,6 +55,13 @@ static const XtensaConfig core_config[] = { .options = -1 ^ (XTENSA_OPTION_BIT(XTENSA_OPTION_HW_ALIGNMENT) | XTENSA_OPTION_BIT(XTENSA_OPTION_MMU)), + .gdb_regmap = { + .num_regs = 176, + .num_core_regs = 117, + .reg = { +#include "gdb-config-sample-xtensa-core.c" + } + }, .nareg = 64, .ndepc = 1, .excm_level = 16,
Signature · 1 line
1.7.3.4
PATCH v2 29/31 target-xtensa: implement memory protection options
In reply to Max Filippov- TLB opcode group;
- region protection option (ISA, 4.6.3);
- region translation option (ISA, 4.6.4);
- MMU option (ISA, 4.6.5).
Cache control attribute bits are not used by this implementation.
--- target-xtensa/cpu.h | 56 ++++++++- target-xtensa/helper.c | 340 ++++++++++++++++++++++++++++++++++++++++++++- target-xtensa/helpers.h | 7 + target-xtensa/op_helper.c | 301 +++++++++++++++++++++++++++++++++++++++- target-xtensa/translate.c | 91 ++++++++++++- 5 files changed, 782 insertions(+), 13 deletions(-)
target-xtensa/cpu.h +55 -1
@@ -114,6 +114,10 @@ enum {SCOMPARE1 =12 ,WINDOW_BASE =72 ,WINDOW_START =73 , +PTEVADDR =83 , +RASID =90 , +ITLBCFG =91 , +DTLBCFG =92 ,EPC1 =177 ,DEPC =192 , EPS2 = 194,
@@ -154,6 +158,9 @@ enum {#define MAX_NLEVEL 6#define MAX_NNMI 1#define MAX_NCCOMPARE 3 +#define MAX_TLB_WAY_SIZE 8 + +#define REGION_PAGE_MASK 0xe0000000enum {/* Static vectors */
@@ -213,6 +220,21 @@ typedef enum {INTTYPE_WRITE_ERR , } interrupt_type_t; +typedef struct xtensa_tlb_entry { +uint32_t vaddr; +uint32_t paddr; +uint8_t asid; +uint8_t attr; +bool variable; +}xtensa_tlb_entry_t ; + +typedef struct xtensa_tlb { +unsigned nways; +const unsigned way_size[10 ]; +bool varway56; +unsigned nrefillentries; +}xtensa_tlb_t ; + typedef struct XtensaGdbReg { int targno; int type;
@@ -246,6 +268,9 @@ typedef struct XtensaConfig {unsigned nccompare;uint32_t timerint[MAX_NCCOMPARE ];uint32_t clock_freq_khz; + +xtensa_tlb_t itlb; +xtensa_tlb_t dtlb; } XtensaConfig; typedef struct CPUXtensaState {
@@ -256,6 +281,10 @@ typedef struct CPUXtensaState {uint32_t uregs[256 ];uint32_t phys_regs[MAX_NAREG ]; +xtensa_tlb_entry_t itlb[7 ][MAX_TLB_WAY_SIZE ]; +xtensa_tlb_entry_t dtlb[10 ][MAX_TLB_WAY_SIZE ]; +unsigned autorefill_idx; +int pending_irq_level;/* level of last raised IRQ */ void **irq_inputs;QEMUTimer *ccompare_timer;
@@ -285,12 +314,29 @@ 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); +uint32_t xtensa_tlb_get_addr_mask (const CPUState *env,bool dtlb,uint32_t way); +void split_tlb_entry_spec_way (const CPUState *env,uint32_t v,bool dtlb, +uint32_t *vpn,uint32_t wi,uint32_t *ei); +int xtensa_tlb_lookup (const CPUState *env,uint32_t addr,bool dtlb, +uint32_t *_wi,uint32_t *_ei,uint8_t *_ring); +void xtensa_tlb_set_entry (CPUState *env,bool dtlb, +unsigned wi,unsigned ei,uint32_t vpn,uint32_t pte); +int xtensa_get_physical_addr (CPUState *env, +uint32_t vaddr,int is_write,int mmu_idx, +uint32_t *paddr,uint32_t *page_size,unsigned *access); +#define XTENSA_OPTION_BIT (opt) (((uint64_t)1) << (opt)) +static inline bool xtensa_option_bits_enabled (const XtensaConfig *config, +uint64_t opt) +{ +return (config->options & opt) !=0 ; +} +static inline bool xtensa_option_enabled (const XtensaConfig *config,int opt) { -return (config->options &XTENSA_OPTION_BIT (opt)) !=0 ; +return xtensa_option_bits_enabled (config,XTENSA_OPTION_BIT (opt)); }static inline int xtensa_get_cintlevel (const CPUState *env)
@@ -321,6 +367,14 @@ static inline int xtensa_get_cring(const CPUState *env) } } +static inline xtensa_tlb_entry_t *xtensa_tlb_get_entry (CPUState *env, +bool dtlb,unsigned wi,unsigned ei) +{ +return dtlb ? + env->dtlb[wi] + ei : + env->itlb[wi] + ei; +} +/* MMU modes definitions */ #define MMU_MODE0_SUFFIX _ring0#define MMU_MODE1_SUFFIX _ring1
target-xtensa/helper.c +339 -1
361 lines not on this page · raw message
target-xtensa/helpers.h +7 -0
@@ -21,4 +21,11 @@ DEF_HELPER_2(waiti, void, i32, i32) DEF_HELPER_2(timer_irq, void, i32, i32) DEF_HELPER_1(advance_ccount, void, i32) +DEF_HELPER_1(wsr_rasid, void, i32) +DEF_HELPER_2(rtlb0, i32, i32, i32) +DEF_HELPER_2(rtlb1, i32, i32, i32) +DEF_HELPER_2(itlb, void, i32, i32) +DEF_HELPER_2(ptlb, i32, i32, i32) +DEF_HELPER_3(wtlb, void, i32, i32, i32) +#include "def-helper.h"
target-xtensa/op_helper.c +295 -6
311 lines not on this page · raw message
target-xtensa/translate.c +86 -5
142 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 30/31 target-xtensa: add dc232b core and board
In reply to Max FilippovThis is Diamond 232L Standard Core Rev.B (LE).
--- Makefile.target | 1 + hw/xtensa_dc232b.c | 112 ++++++++++++++++ target-xtensa/gdb-config-dc232b.c | 261 +++++++++++++++++++++++++++++++++++++ target-xtensa/helper.c | 167 +++++++++++++++++++++++ 4 files changed, 541 insertions(+), 0 deletions(-) create mode 100644 hw/xtensa_dc232b.c create mode 100644 target-xtensa/gdb-config-dc232b.c
Makefile.target +1 -0
@@ -374,6 +374,7 @@ obj-alpha-y += vga.o cirrus_vga.o obj-xtensa-y += xtensa_pic.o obj-xtensa-y += xtensa_sample.o +obj-xtensa-y += xtensa_dc232b.o obj-xtensa-y += xtensa-semi.o main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
hw/xtensa_dc232b.c new file +112 -0
112 lines not on this page · raw message
target-xtensa/gdb-config-dc232b.c new file +261 -0
261 lines not on this page · raw message
target-xtensa/helper.c +167 -0
173 lines not on this page · raw message
Signature · 1 line
1.7.3.4
PATCH v2 31/31 MAINTAINERS: add xtensa maintainer
In reply to Max FilippovAdd myself as target-xtensa and DC232B maintainer.
--- MAINTAINERS | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
MAINTAINERS +13 -0
@@ -115,6 +115,12 @@ M: [email protected] S: Odd Fixes F: target-i386/ +Xtensa +M: Max Filippov <[email protected]> +W: http://kkv.spb.su/doku.php?id=etc:users:jcmvbkbc:qemu-target-xtensa +S: Maintained +F: target-xtensa/ + Guest CPU Cores (KVM): ----------------------
@@ -325,6 +331,13 @@ M: Anthony Liguori <[email protected]> S: Supported F: hw/pc.[ch] hw/pc_piix.c +Xtensa Machines +--------------- +DC232B +M: Max Filippov <[email protected]> +S: Maintained +F: hw/xtensa_dc232b.c + Devices ------- IDE
Signature · 1 line
1.7.3.4
Quoted 34 lines · Max Filippov
This series adds support for Tensilica Xtensa target. Port status: Linux for DC232B works in the qemu.
Not implemented xtensa options: MAC16, floating point coprocessor, boolean option, cache option, debug option.v1 -> v2 changes:
- extract PS register and access control into separate patch;
- implement all memory protection options;
- GDB support.Max Filippov (31):
target-xtensa: add target stubs
target-xtensa: add target to the configure script
target-xtensa: implementdisas_xtensa_insn
target-xtensa: implement narrow instructions
target-xtensa: implement RT0 group
target-xtensa: add sample board
target-xtensa: implement conditional jumps
target-xtensa: implement JX/RET0/CALLX
target-xtensa: add special and user registers
target-xtensa: implement RST3 group
target-xtensa: implement shifts (ST1 and RST1 groups)
target-xtensa: implement LSAI group
target-xtensa: mark reserved and TBD opcodes
target-xtensa: implement SYNC group
target-xtensa: implement CACHE group
target-xtensa: add PS register and access control
target-xtensa: implement exceptions
target-xtensa: implement RST2 group (32 bit mul/div/rem)
target-xtensa: implement windowed registers
target-xtensa: implement loop option
target-xtensa: implement extended L32R
target-xtensa: implement unaligned exception option
target-xtensa: implement SIMCALL
Quoted 8 lines
target-xtensa: implement interrupt option
target-xtensa: implement accurate window check
target-xtensa: implement CPENABLE and PRID SRs
target-xtensa: implement relocatable vectors
target-xtensa: add gdb support
target-xtensa: implement memory protection options
target-xtensa: add dc232b core and board
MAINTAINERS: add xtensa maintainer
All parts:
I guess everything except the last couple of patches I'd already commented on in the last go-round.
There's of course the conflict with the new Memory API that'll need to be resolved, but those are trivial changes.
r~