target-xtensa: add target stubs
RFC 2/28 target-xtensa: add target to the configure script
In reply to Max Filippov--- configure | 9 +++++++++ default-configs/xtensa-softmmu.mak | 1 + 2 files changed, 10 insertions(+), 0 deletions(-) create mode 100644 default-configs/xtensa-softmmu.mak
configure +9 -0
@@ -1028,6 +1028,7 @@ sh4-softmmu \ sh4eb-softmmu \ sparc-softmmu \ sparc64-softmmu \ +xtensa-softmmu \ " fi # the following are Linux specific
@@ -3210,6 +3211,10 @@ case "$target_arch2" in unicore32) target_phys_bits=32 ;; + xtensa) + TARGET_ARCH=xtensa + target_phys_bits=32 + ;; *) echo "Unsupported target CPU" exit 1
@@ -3385,6 +3390,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
Signature · 1 line
1.7.3.4
RFC 1/28 target-xtensa: add target stubs
--- Makefile.target | 2 + arch_init.c | 2 + arch_init.h | 1 + cpu-exec.c | 10 +++++ elf.h | 2 + hw/xtensa_pic.c | 11 ++++++ target-xtensa/cpu.h | 84 +++++++++++++++++++++++++++++++++++++++++++++ target-xtensa/exec.h | 55 +++++++++++++++++++++++++++++ target-xtensa/helper.c | 74 +++++++++++++++++++++++++++++++++++++++ target-xtensa/machine.c | 38 ++++++++++++++++++++ target-xtensa/op_helper.c | 51 +++++++++++++++++++++++++++ target-xtensa/translate.c | 67 +++++++++++++++++++++++++++++++++++ 12 files changed, 397 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
@@ -366,6 +366,8 @@ obj-s390x-y = s390-virtio-bus.o s390-virtio.o obj-alpha-y = alpha_palcode.o +obj-xtensa-y += xtensa_pic.o + main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS) monitor.o: hmp-commands.h qmp-commands.h
arch_init.c +2 -0
@@ -78,6 +78,8 @@ const char arch_config_name[] = CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".con#define QEMU_ARCH QEMU_ARCH_SH4#elif defined(TARGET_SPARC )#define QEMU_ARCH QEMU_ARCH_SPARC +#elif defined(TARGET_XTENSA ) +#define QEMU_ARCH QEMU_ARCH_XTENSA#endif const uint32_t arch_type =QEMU_ARCH ;
arch_init.h +1 -0
@@ -17,6 +17,7 @@ enum {QEMU_ARCH_S390X =512 ,QEMU_ARCH_SH4 =1024 ,QEMU_ARCH_SPARC =2048 , + QEMU_ARCH_XTENSA = 4096, };extern const uint32_t arch_type;
cpu-exec.c +10 -0
@@ -275,6 +275,7 @@ int cpu_exec(CPUState *env1)#elif defined(TARGET_SH4 )#elif defined(TARGET_CRIS )#elif defined(TARGET_S390X ) +#elif defined(TARGET_XTENSA )/* XXXXX */ #else #error unsupported target CPU
@@ -348,6 +349,8 @@ int cpu_exec(CPUState *env1)do_interrupt (0 );#elif defined(TARGET_S390X )do_interrupt (env); +#elif defined(TARGET_XTENSA ) +do_interrupt (env);#endif env->exception_index =-1 ;#endif
@@ -568,6 +571,12 @@ int cpu_exec(CPUState *env1)do_interrupt (env); next_tb = 0; } +#elif defined(TARGET_XTENSA) +if (interrupt_request &CPU_INTERRUPT_HARD ) { + env->exception_index =EXC_IRQ ; +do_interrupt (env); + next_tb =0 ; + }#endif /* Don't use the cached interupt_request value, do_interrupt may have updated the EXITTB flag. */
@@ -696,6 +705,7 @@ int cpu_exec(CPUState *env1)#elif defined(TARGET_ALPHA )#elif defined(TARGET_CRIS )#elif defined(TARGET_S390X ) +#elif defined(TARGET_XTENSA )/* XXXXX */ #else #error unsupported target CPU
elf.h +2 -0
@@ -125,6 +125,8 @@ typedef int64_t Elf64_Sxword;#define EM_MICROBLAZE 189#define EM_MICROBLAZE_OLD 0xBAAB +#define EM_XTENSA 94/* Tensilica Xtensa */ +/* This is the info that is needed to parse the dynamic section of the file */ #define DT_NULL 0#define DT_NEEDED 1
hw/xtensa_pic.c new file +11 -0
@@ -0,0 +1,11 @@ +#include "hw.h" +#include "pc.h" + +/* Stub functions for hardware that doesn't exist. */ +void pic_info (Monitor *mon) +{ +} + +void irq_info (Monitor *mon) +{ +}
target-xtensa/cpu.h new file +84 -0
84 lines not on this page · raw message
target-xtensa/exec.h new file +55 -0
55 lines not on this page · raw message
target-xtensa/helper.c new file +74 -0
74 lines not on this page · raw message
target-xtensa/machine.c new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright (c) 2011, Max Filippov, Motorola Solutions, Inc. +* 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 Motorola Solutions 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
RFC 3/28 target-xtensa: implement disas_xtensa_insn
Set 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 | 60 +++++++ target-xtensa/helper.c | 27 +++- target-xtensa/helpers.h | 5 + target-xtensa/op_helper.c | 7 + target-xtensa/translate.c | 374 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 471 insertions(+), 2 deletions(-) create mode 100644 target-xtensa/helpers.h
target-xtensa/cpu.h +60 -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];
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) {
@@ -60,8 +80,11 @@ CPUXtensaState *cpu_xtensa_init(const char *cpu_model)void xtensa_cpu_list (FILE *f,fprintf_function cpu_fprintf) { -cpu_fprintf (f,"Available CPUs:\n" -" Xtensa core\n" ); +int i; +cpu_fprintf (f,"Available CPUs:\n" ); +for (i =0 ; i <ARRAY_SIZE (core_config); ++i) { +cpu_fprintf (f," %s\n" , core_config[i].name); + } }target_phys_addr_t cpu_get_phys_page_debug (CPUState *env,target_ulong addr)
target-xtensa/helpers.h new file +5 -0
@@ -0,0 +1,5 @@ +#include "def-helper.h" + +DEF_HELPER_1(exception, void, i32) + +#include "def-helper.h"
target-xtensa/op_helper.c +7 -0
@@ -26,6 +26,7 @@*/ #include "exec.h" +#include "helpers.h" #define MMUSUFFIX _mmu
@@ -49,3 +50,9 @@ void tlb_fill(target_ulong addr, int is_write, int mmu_idx, void *retaddr)PAGE_READ |PAGE_WRITE |PAGE_EXEC , mmu_idx, TARGET_PAGE_SIZE); } + +void HELPER (exception )(uint32_t excp) +{ + env->exception_index = excp; +cpu_loop_exit (); +}
target-xtensa/translate.c +374 -0
391 lines not on this page · raw message
Signature · 1 line
1.7.3.4
RFC 4/28 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 | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 57 insertions(+), 0 deletions(-)
target-xtensa/translate.c +57 -0
@@ -301,22 +301,79 @@ 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*/ +int label =gen_new_label (); +int inv =RRRN_T &4 ; + +tcg_gen_brcondi_i32 (inv ?TCG_COND_EQ :TCG_COND_NE , + cpu_R[RRRN_S ],0 , label); +gen_jumpi (dc, dc->pc +4 + (RRRN_R | ((RRRN_T &3 ) <<4 ))); +gen_set_label (label); +gen_jumpi (dc, dc->pc +2 ); + }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
RFC 5/28 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
@@ -174,6 +174,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
RFC 6/28 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 | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 0 deletions(-) create mode 100644 hw/xtensa_sample.c
Makefile.target +1 -0
@@ -367,6 +367,7 @@ obj-s390x-y = s390-virtio-bus.o s390-virtio.o obj-alpha-y = alpha_palcode.o obj-xtensa-y += xtensa_pic.o +obj-xtensa-y += xtensa_sample.o main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
hw/xtensa_sample.c new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
1.7.3.4
RFC 7/28 target-xtensa: add gdb support
In reply to Max Filippov--- configure | 1 + default-configs/xtensa-softmmu.mak | 1 + gdb-xml/xtensa-core.xml | 24 ++++++++++++++++++++++ gdbstub.c | 39 ++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 0 deletions(-) create mode 100644 gdb-xml/xtensa-core.xml
configure +1 -0
@@ -3213,6 +3213,7 @@ case "$target_arch2" in ;; xtensa) TARGET_ARCH=xtensa + gdb_xml_files="xtensa-core.xml" target_phys_bits=32 ;; *)
default-configs/xtensa-softmmu.mak +1 -0
@@ -1 +1,2 @@ # Default configuration for Xtensa +CONFIG_GDBSTUB_XML=y
gdb-xml/xtensa-core.xml new file +24 -0
@@ -0,0 +1,24 @@ +<?xml version="1.0"?> +<!DOCTYPE feature SYSTEM "gdb-target.dtd"> +<feature name="org.gnu.gdb.xtensa.core"> + <reg name="pc" bitsize="32" type="code_ptr"/> + <reg name="a0" bitsize="32"/> + <reg name="a1" bitsize="32"/> + <reg name="a2" bitsize="32"/> + <reg name="a3" bitsize="32"/> + <reg name="a4" bitsize="32"/> + <reg name="a5" bitsize="32"/> + <reg name="a6" bitsize="32"/> + <reg name="a7" bitsize="32"/> + <reg name="a8" bitsize="32"/> + <reg name="a9" bitsize="32"/> + <reg name="a10" bitsize="32"/> + <reg name="a11" bitsize="32"/> + <reg name="a12" bitsize="32"/> + <reg name="a13" bitsize="32"/> + <reg name="a14" bitsize="32"/> + <reg name="a15" bitsize="32"/> + + <reg name="windowbase" bitsize="32" regnum="38"/> + <reg name="ps" bitsize="32" regnum="42"/> +</feature>
gdbstub.c +39 -0
@@ -1541,6 +1541,43 @@ static int cpu_gdb_write_register(CPUState *env, uint8_t *mem_buf, int n) }return 4 ; } +#elif defined(TARGET_XTENSA) + +#define GDB_CORE_XML "xtensa-core.xml" +#define NUM_CORE_REGS (45) + +static int cpu_gdb_read_register (CPUState *env,uint8_t *mem_buf,int n) +{ +if (n <0 || n >=NUM_CORE_REGS ) { +return 0 ; + } +if (n ==0 ) { +GET_REG32 (env->pc); + }else if (n <17 ) { +GET_REG32 (env->regs[n -1 ]); + }else { +GET_REG32 (env->sregs[n -17 ]); + } +} + +static int cpu_gdb_write_register (CPUState *env,uint8_t *mem_buf,int n) +{ +uint32_t tmp; + +if (n <0 || n >=NUM_CORE_REGS ) { +return 0 ; + } + tmp =ldl_p (mem_buf); + +if (n ==0 ) { + env->pc = tmp; + }else if (n <17 ) { + env->regs[n -1 ] = tmp; + }else { + env->sregs[n -17 ] = tmp; + } +return 4 ; +}#else #define NUM_CORE_REGS 0
@@ -1818,6 +1855,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 }
Signature · 1 line
1.7.3.4
RFC 8/28 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).
--- target-xtensa/translate.c | 188 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 188 insertions(+), 0 deletions(-)
target-xtensa/translate.c +188 -0
@@ -118,16 +118,41 @@ static void disas_xtensa_insn(DisasContext *dc)#define RRRN_S RRR_S#define RRRN_T RRR_T +#define RRI8_R RRR_R +#define RRI8_S RRR_S +#define RRI8_T RRR_T +#define RRI8_IMM8 (_b2) +#define RRI8_IMM8_SE ((((_b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8) +#define RI16_IMM16 (((_b1) << 8) | (_b2))#define CALL_N (((_b0) & 0xc) >> 2)#define CALL_OFFSET ((((_b0) & 0x3) << 16) | ((_b1) << 8) | (_b2))#define CALL_OFFSET_SE (((_b0 & 0x2) ? 0xfffc0000 : 0) | CALL_OFFSET) +#define BRI12_M ((_b0) & 0x3) +#define BRI12_S RRR_S +#define BRI12_IMM12 ((((_b1) & 0xf) << 8) | (_b2)) +#define BRI12_IMM12_SE ((((_b1) & 0x8) ? 0xfffff000 : 0) | BRI12_IMM12) + +#define BRI8_M BRI12_M +#define BRI8_R RRI8_R +#define BRI8_S RRI8_S +#define BRI8_IMM8 RRI8_IMM8 +#define BRI8_IMM8_SE RRI8_IMM8_SE +uint8_t _b0 =ldub_code (dc->pc);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 + }; +switch (_OP0) {case 0 :/*QRST*/ switch (_OP1) {
@@ -314,10 +339,173 @@ static void disas_xtensa_insn(DisasContext *dc)gen_jumpi (dc, dc->pc +4 +CALL_OFFSET_SE );break ; +case 1 :/*BZ*/ + { +int label =gen_new_label (); +int inv =BRI12_M &1 ; + +switch (BRI12_M &2 ) { +case 0 :/*BEQZ*/ +tcg_gen_brcondi_i32 (inv ?TCG_COND_EQ :TCG_COND_NE , + cpu_R[BRI12_S ],0 , label); +break ; + +case 2 :/*BLTZ*/ +tcg_gen_brcondi_i32 (inv ?TCG_COND_LT :TCG_COND_GE , + cpu_R[BRI12_S ],0 , label); +break ; + } +gen_jumpi (dc, dc->pc +4 +BRI12_IMM12_SE ); +gen_set_label (label); +gen_jumpi (dc, dc->pc +3 ); + } +break ; + +case 2 :/*BI0*/ + { +int label =gen_new_label (); +int inv =BRI8_M &1 ; + +switch (BRI8_M &2 ) { +case 0 :/*BEQI*/ +tcg_gen_brcondi_i32 (inv ?TCG_COND_EQ :TCG_COND_NE , + cpu_R[BRI8_S ],B4CONST [BRI8_R ], label); +break ; + +case 2 :/*BLTI*/ +tcg_gen_brcondi_i32 (inv ?TCG_COND_LT :TCG_COND_GE , + cpu_R[BRI8_S ],B4CONST [BRI8_R ], label); +break ; + } +gen_jumpi (dc, dc->pc +4 +BRI8_IMM8_SE ); +gen_set_label (label); +gen_jumpi (dc, dc->pc +3 ); + } +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*/ + { +int label =gen_new_label (); +int inv =BRI8_M &1 ; + +tcg_gen_brcondi_i32 (inv ?TCG_COND_LTU :TCG_COND_GEU , + cpu_R[BRI8_S ],B4CONSTU [BRI8_R ], label); + +gen_jumpi (dc, dc->pc +4 +BRI8_IMM8_SE ); +gen_set_label (label); +gen_jumpi (dc, dc->pc +3 ); + } +break ; + } +break ; + }break ;case 7 :/*B*/ + { +int label =gen_new_label (); +int inv =RRI8_R &8 ; + +switch (RRI8_R &7 ) { +case 0 :/*BNONE*/ + { +TCGv_i32 tmp =tcg_temp_new_i32 (); +tcg_gen_and_i32 (tmp, cpu_R[RRI8_S ], cpu_R[RRI8_T ]); +tcg_gen_brcondi_i32 (inv ?TCG_COND_EQ :TCG_COND_NE , + tmp,0 , label); +tcg_temp_free (tmp); + } +break ; + +case 1 :/*BEQ*/ +tcg_gen_brcond_i32 (inv ?TCG_COND_EQ :TCG_COND_NE , + cpu_R[RRI8_S ], cpu_R[RRI8_T ], label); +break ; + +case 2 :/*BLT*/ +tcg_gen_brcond_i32 (inv ?TCG_COND_LT :TCG_COND_GE , + cpu_R[RRI8_S ], cpu_R[RRI8_T ], label); +break ; + +case 3 :/*BLTU*/ +tcg_gen_brcond_i32 (inv ?TCG_COND_LTU :TCG_COND_GEU , + cpu_R[RRI8_S ], cpu_R[RRI8_T ], label); +break ; + +case 4 :/*BALL*/ + { +TCGv_i32 tmp =tcg_temp_new_i32 (); +tcg_gen_and_i32 (tmp, cpu_R[RRI8_S ], cpu_R[RRI8_T ]); +tcg_gen_brcond_i32 (inv ?TCG_COND_EQ :TCG_COND_NE , + tmp, cpu_R[RRI8_T ], label); +tcg_temp_free (tmp); + } +break ; + +case 5 :/*BBC*/ + { +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); +tcg_gen_brcondi_i32 (inv ?TCG_COND_EQ :TCG_COND_NE , + tmp,0 , label); +tcg_temp_free (tmp); +tcg_temp_free (bit); + } +break ; + +case 6 :/*BBCI*/ +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 )); +tcg_gen_brcondi_i32 (inv ?TCG_COND_EQ :TCG_COND_NE , + tmp,0 , label); +tcg_temp_free (tmp); + } +break ; + + } +gen_jumpi (dc, dc->pc +4 +RRI8_IMM8_SE ); +gen_set_label (label); +gen_jumpi (dc, dc->pc +3 ); + }break ;#define gen_narrow_load_store (type) do { \
Signature · 1 line
1.7.3.4
RFC 9/28 target-xtensa: implement JX/RET0/CALLX
In reply to Max FilippovGroup SNM0 (indirect jumps and calls).
--- target-xtensa/translate.c | 49 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 48 insertions(+), 1 deletions(-)
target-xtensa/translate.c +48 -1
@@ -130,7 +130,11 @@ static void disas_xtensa_insn(DisasContext *dc)#define CALL_OFFSET ((((_b0) & 0x3) << 16) | ((_b1) << 8) | (_b2))#define CALL_OFFSET_SE (((_b0 & 0x2) ? 0xfffc0000 : 0) | CALL_OFFSET) -#define BRI12_M ((_b0) & 0x3) +#define CALLX_N CALL_N +#define CALLX_M ((_b0) & 0x3) +#define CALLX_S RRR_S + +#define BRI12_M CALLX_M#define BRI12_S RRR_S#define BRI12_IMM12 ((((_b1) & 0xf) << 8) | (_b2))#define BRI12_IMM12_SE ((((_b1) & 0x8) ? 0xfffff000 : 0) | BRI12_IMM12)
@@ -165,6 +169,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->pc +3 ); +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
RFC 10/28 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
RFC 11/28 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 | 147 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 147 insertions(+), 0 deletions(-)
target-xtensa/translate.c +147 -0
@@ -102,6 +102,32 @@ void xtensa_translate_init(void) } } +static void gen_rsr (TCGv_i32 d,int sr) +{ +if (sregnames[sr]) { +tcg_gen_mov_i32 (d, cpu_SR[sr]); + }else { +printf ("SR %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 { +printf ("SR %d not implemented, " , sr); + } +} +static void gen_exception (int excp) {TCGv_i32 tmp =tcg_const_i32 (excp);
@@ -172,6 +198,8 @@ static void disas_xtensa_insn(DisasContext *dc)#define BRI8_IMM8 RRI8_IMM8#define BRI8_IMM8_SE RRI8_IMM8_SE +#define RSR_SR (_b1) +uint8_t _b0 =ldub_code (dc->pc);uint8_t _b1 =ldub_code (dc->pc +1 );uint8_t _b2 =ldub_code (dc->pc +2 );
@@ -336,6 +364,125 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 3 :/*RST3*/ +switch (_OP2) { +case 0 :/*RSR*/ +gen_rsr (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 ); + { +TCGv_i32 tmp =tcg_temp_new_i32 (); +tcg_gen_shli_i32 (tmp, cpu_R[RRR_S ],24 -RRR_T ); +tcg_gen_sari_i32 (cpu_R[RRR_R ], tmp,24 -RRR_T ); +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 { +printf ("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 { +printf ("wur %d not implemented, " ,RSR_SR ); + } + } +break ; + + }break ;case 4 :/*EXTUI*/
Signature · 1 line
1.7.3.4
RFC 12/28 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.
--- target-xtensa/cpu.h | 4 + target-xtensa/translate.c | 210 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 214 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/translate.c +210 -0
234 lines not on this page · raw message
Signature · 1 line
1.7.3.4
RFC 13/28 target-xtensa: implement LSAI group
In reply to Max Filippov- base + offset load/store operations for 1/2/4 byte values;
- cache operations (not implemented);
- multiprocessor synchronization operations.
--- target-xtensa/cpu.h | 1 + target-xtensa/translate.c | 88 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 0 deletions(-)
target-xtensa/cpu.h +1 -0
@@ -107,6 +107,7 @@ enum {enum {SAR =3 , +SCOMPARE1 =12 , }; typedef struct XtensaConfig {
target-xtensa/translate.c +88 -0
101 lines not on this page · raw message
Signature · 1 line
1.7.3.4
RFC 14/28 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 | 111 ++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 110 insertions(+), 1 deletions(-)
target-xtensa/translate.c +110 -1
@@ -162,6 +162,14 @@ static void disas_xtensa_insn(DisasContext *dc) } \ } while (0) +#define TBD () printf("TBD(pc = %08x): %s:%d\n", dc->pc, __FILE__, __LINE__) +#define RESERVED () do { \ + printf("RESERVED(pc = %08x, %02x%02x%02x): %s:%d\n", \ + dc->pc, _b0, _b1, _b2, __FILE__, __LINE__); \ + goto invalid_opcode; \ + } while (0) + +#define _OP0 (((_b0) & 0xf0) >> 4)#define _OP1 (((_b2) & 0xf0) >> 4)#define _OP2 ((_b2) & 0xf)
@@ -228,9 +236,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*/
@@ -242,9 +252,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 ;
@@ -265,6 +277,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*CALLX8w*/ case 3 :/*CALLX12w*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ; }break ;
@@ -273,12 +286,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 ; }
@@ -339,17 +399,21 @@ 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*/ HAS_OPTION (XTENSA_OPTION_MISC_OP ); +TBD ();break ;case 15 :/*NSAUu*/
@@ -390,11 +454,13 @@ static void disas_xtensa_insn(DisasContext *dc)break ;default :/*reserved*/ +RESERVED ();break ; }break ;case 5 :/*TLB*/ +TBD ();break ;case 6 :/*RT0*/
@@ -415,11 +481,13 @@ static void disas_xtensa_insn(DisasContext *dc)break ;default :/*reserved*/ +RESERVED ();break ; }break ;case 7 :/*reserved*/ +RESERVED ();break ;case 8 :/*ADD*/
@@ -479,6 +547,9 @@ static void disas_xtensa_insn(DisasContext *dc)gen_rsr (cpu_R[RRR_T ],RSR_SR );gen_wsr (dc,RSR_SR , tmp);tcg_temp_free (tmp); +if (!sregnames[RSR_SR ]) { +TBD (); + } }break ;
@@ -558,21 +629,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 (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*/
@@ -657,10 +736,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*/
@@ -670,6 +751,7 @@ static void disas_xtensa_insn(DisasContext *dc)tcg_gen_mov_i32 (cpu_R[RRR_R ], cpu_UR[st]); }else {printf ("rur %d not implemented, " , st); +TBD (); } }break ;
@@ -680,6 +762,7 @@ static void disas_xtensa_insn(DisasContext *dc)tcg_gen_mov_i32 (cpu_UR[RSR_SR ], cpu_R[RRR_T ]); }else {printf ("wur %d not implemented, " ,RSR_SR ); +TBD (); } }break ;
@@ -701,27 +784,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 ;
@@ -773,6 +863,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 7 :/*CACHEc*/ +TBD ();break ;case 9 :/*L16SI*/
@@ -824,6 +915,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;default :/*reserved*/ +RESERVED ();break ; }break ;
@@ -831,10 +923,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*/
@@ -848,6 +942,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*CALL8w*/ case 3 :/*CALL12w*/ HAS_OPTION (XTENSA_OPTION_WINDOWED_REGISTER ); +TBD ();break ; }break ;
@@ -906,28 +1001,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 ; }
@@ -1081,28 +1183,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
RFC 15/28 target-xtensa: big endian support
In reply to Max FilippovBig endian opcode decoding is slightly different.
--- configure | 7 ++++--- hw/xtensa_sample.c | 6 +++++- target-xtensa/translate.c | 31 +++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 6 deletions(-)
configure +4 -3
@@ -1029,6 +1029,7 @@ sh4eb-softmmu \ sparc-softmmu \ sparc64-softmmu \ xtensa-softmmu \ +xtensaeb-softmmu \ " fi # the following are Linux specific
@@ -3016,7 +3017,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
@@ -3211,7 +3212,7 @@ case "$target_arch2" in unicore32) target_phys_bits=32 ;; - xtensa) + xtensa|xtensaeb) TARGET_ARCH=xtensa gdb_xml_files="xtensa-core.xml" target_phys_bits=32
@@ -3391,7 +3392,7 @@ 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) + xtensa*) echo "CONFIG_XTENSA_DIS=y" >> $config_target_mak echo "CONFIG_XTENSA_DIS=y" >> $libdis_config_mak ;;
hw/xtensa_sample.c +5 -1
@@ -32,9 +32,13 @@ static void xtensa_init(ram_addr_t ram_size,if (kernel_filename) {uint64_t elf_entry;uint64_t elf_lowaddr; - +#ifdef TARGET_WORDS_BIGENDIAN +int success =load_elf (kernel_filename,NULL ,NULL , &elf_entry, + &elf_lowaddr,NULL ,1 ,ELF_MACHINE ,0 ); +#else int success =load_elf (kernel_filename,NULL ,NULL , &elf_entry, &elf_lowaddr,NULL ,0 ,ELF_MACHINE ,0 ); +#endif if (success >0 ) { env->pc = elf_entry; }
target-xtensa/translate.c +29 -2
@@ -170,12 +170,21 @@ static void disas_xtensa_insn(DisasContext *dc) } while (0) +#ifdef TARGET_WORDS_BIGENDIAN #define _OP0 (((_b0) & 0xf0) >> 4)#define _OP1 (((_b2) & 0xf0) >> 4)#define _OP2 ((_b2) & 0xf)#define RRR_R ((_b1) & 0xf)#define RRR_S (((_b1) & 0xf0) >> 4)#define RRR_T ((_b0) & 0xf) +#else +#define _OP0 (((_b0) & 0xf)) +#define _OP1 (((_b2) & 0xf)) +#define _OP2 (((_b2) & 0xf0) >> 4) +#define RRR_R (((_b1) & 0xf0) >> 4) +#define RRR_S (((_b1) & 0xf)) +#define RRR_T (((_b0) & 0xf0) >> 4) +#endif #define RRRN_R RRR_R#define RRRN_S RRR_S
@@ -187,20 +196,38 @@ static void disas_xtensa_insn(DisasContext *dc)#define RRI8_IMM8 (_b2)#define RRI8_IMM8_SE ((((_b2) & 0x80) ? 0xffffff00 : 0) | RRI8_IMM8) +#ifdef TARGET_WORDS_BIGENDIAN #define RI16_IMM16 (((_b1) << 8) | (_b2)) +#else +#define RI16_IMM16 (((_b2) << 8) | (_b1)) +#endif +#ifdef TARGET_WORDS_BIGENDIAN #define CALL_N (((_b0) & 0xc) >> 2)#define CALL_OFFSET ((((_b0) & 0x3) << 16) | ((_b1) << 8) | (_b2)) -#define CALL_OFFSET_SE (((_b0 & 0x2) ? 0xfffc0000 : 0) | CALL_OFFSET) +#else +#define CALL_N (((_b0) & 0x30) >> 4) +#define CALL_OFFSET ((((_b0) & 0xc0) >> 6) | ((_b1) << 2) | ((_b2) << 10)) +#endif +#define CALL_OFFSET_SE \ + (((CALL_OFFSET & 0x20000) ? 0xfffc0000 : 0) | CALL_OFFSET)#define CALLX_N CALL_N +#ifdef TARGET_WORDS_BIGENDIAN #define CALLX_M ((_b0) & 0x3) +#else +#define CALLX_M (((_b0) & 0xc0) >> 6) +#endif #define CALLX_S RRR_S#define BRI12_M CALLX_M#define BRI12_S RRR_S +#ifdef TARGET_WORDS_BIGENDIAN #define BRI12_IMM12 ((((_b1) & 0xf) << 8) | (_b2)) -#define BRI12_IMM12_SE ((((_b1) & 0x8) ? 0xfffff000 : 0) | BRI12_IMM12) +#else +#define BRI12_IMM12 ((((_b1) & 0xf0) >> 4) | ((_b2) << 4)) +#endif +#define BRI12_IMM12_SE (((BRI12_IMM12 & 0x800) ? 0xfffff000 : 0) | BRI12_IMM12)#define BRI8_M BRI12_M#define BRI8_R RRI8_R
Signature · 1 line
1.7.3.4
RFC 16/28 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
@@ -317,7 +317,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
RFC 17/28 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
@@ -919,7 +919,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
RFC 18/28 target-xtensa: implement exceptions
In reply to Max Filippov- mark privileged opcodes with ring check;
- make debug exception on exception handler entry.
--- target-xtensa/cpu.h | 91 +++++++++++++++++++++++++++++++++ target-xtensa/helper.c | 39 ++++++++++++++- target-xtensa/helpers.h | 2 + target-xtensa/op_helper.c | 29 +++++++++++ target-xtensa/translate.c | 124 +++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 279 insertions(+), 6 deletions(-)
target-xtensa/cpu.h +91 -0
@@ -108,11 +108,86 @@ enum {enum {SAR =3 ,SCOMPARE1 =12 , +EPC1 =177 , +DEPC =192 , +EXCSAVE1 =209 , +PS =230 , +EXCCAUSE =232 , +EXCVADDR =238 , +}; + +#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 + +enum { +/* Static vectors */ +EXC_RESET , +EXC_MEMORY_ERROR , + +/* Dynamic vectors */ +EXC_WINDOW_OVERFLOW4 , +EXC_WINDOW_UNDERFLOW4 , +EXC_WINDOW_OVERFLOW8 , +EXC_WINDOW_UNDERFLOW8 , +EXC_WINDOW_OVERFLOW12 , +EXC_WINDOW_UNDERFLOW12 , +EXC_IRQ , +EXC_KERNEL , +EXC_USER , +EXC_DOUBLE , +EXC_MAX +}; + +enum { +ILLEGAL_INSTRUCTION_CAUSE =0 , +SYSCALL_CAUSE , +INSTRUCTION_FETCH_ERROR_CAUSE , +LOAD_STORE_ERROR_CAUSE , +LEVEL1_INTERRUPT_CAUSE , +ALLOCA_CAUSE , +INTEGER_DIVIE_BY_ZERO_CAUSE , +PRIVILEGED_CAUSE =8 , +LOAD_STORE_ALIGNMENT_CAUSE , + +INSTR_PIF_DATA_ERROR_CAUSE =12 , +LOAD_STORE_PIF_DATA_ERROR_CAUSE , +INSTR_PIF_ADDR_ERROR_CAUSE , +LOAD_STORE_PIF_ADDR_ERROR_CAUSE , + +INST_TLB_MISS_CAUSE , +INST_TLB_MULTI_HIT_CAUSE , +INST_FETCH_PRIVILEGE_CAUSE , +INST_FETCH_PROHIBITED_CAUSE =20 , +LOAD_STORE_TLB_MISS_CAUSE =24 , +LOAD_STORE_TLB_MULTI_HIT_CAUSE , +LOAD_STORE_PRIVILEGE_CAUSE , +LOAD_PROHIBITED_CAUSE =28 , +STORE_PROHIBITED_CAUSE , + +COPROCESSOR0_DISABLED =32 , };typedef struct XtensaConfig {const char *name;uint64_t options; +int excm_level; +int ndepc; +uint32_t exception_vector[EXC_MAX ]; }XtensaConfig ; typedef struct CPUXtensaState {
@@ -122,6 +197,8 @@ typedef struct CPUXtensaState {uint32_t sregs[256 ];uint32_t uregs[256 ]; +int exception_taken; + CPU_COMMON } CPUXtensaState;
@@ -151,6 +228,20 @@ static inline void cpu_get_tb_cpu_state(CPUState *env, target_ulong *pc, *flags = 0; } +static inline int xtensa_option_enabled (const XtensaConfig *config,int opt) +{ +return (config->options & (((uint64_t )1 ) << (opt))) !=0 ; +} + +static inline int xtensa_get_cintlevel (CPUState *env) +{ +int level = (env->sregs[PS ] &PS_INTLEVEL ) >>PS_INTLEVEL_SHIFT ; +if ((env->sregs[PS ] &PS_EXCM ) && env->config->excm_level > level) { + level = env->config->excm_level; + } +return level; +} +#include "cpu-all.h" #endif
target-xtensa/helper.c +38 -1
@@ -36,13 +36,29 @@void cpu_reset (CPUXtensaState *env) { - env->pc =0 ; + env->exception_taken =0 ; + env->pc = env->config->exception_vector[EXC_RESET ]; + env->sregs[PS ] =0x1f ; }static const XtensaConfig core_config[] = { { .name ="sample-xtensa-core" , .options =-1 , + .ndepc =1 , + .excm_level =16 , + .exception_vector = { + [EXC_RESET ] =0x5fff8000 , + [EXC_WINDOW_OVERFLOW4 ] =0x5fff8400 , + [EXC_WINDOW_UNDERFLOW4 ] =0x5fff8440 , + [EXC_WINDOW_OVERFLOW8 ] =0x5fff8480 , + [EXC_WINDOW_UNDERFLOW8 ] =0x5fff84c0 , + [EXC_WINDOW_OVERFLOW12 ] =0x5fff8500 , + [EXC_WINDOW_UNDERFLOW12 ] =0x5fff8540 , + [EXC_KERNEL ] =0x5fff861c , + [EXC_USER ] =0x5fff863c , + [EXC_DOUBLE ] =0x5fff865c , + }, }, };
@@ -94,4 +110,25 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)void do_interrupt (CPUState *env) { +switch (env->exception_index) { +case EXC_WINDOW_OVERFLOW4 : +case EXC_WINDOW_UNDERFLOW4 : +case EXC_WINDOW_OVERFLOW8 : +case EXC_WINDOW_UNDERFLOW8 : +case EXC_WINDOW_OVERFLOW12 : +case EXC_WINDOW_UNDERFLOW12 : +case EXC_KERNEL : +case EXC_USER : +case EXC_DOUBLE : +if (env->config->exception_vector[env->exception_index]) { + env->pc = env->config->exception_vector[env->exception_index]; + env->exception_taken =1 ; + }else { +printf ("%s(pc = %08x) bad exception_index: %d\n" , + __func__, env->pc, env->exception_index); + } +break ; + + } + env->interrupt_request |=CPU_INTERRUPT_EXITTB ; }
target-xtensa/helpers.h +2 -0
@@ -1,5 +1,7 @@#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)#include "def-helper.h"
target-xtensa/op_helper.c +29 -0
@@ -56,3 +56,32 @@ void HELPER(exception)(uint32_t excp) env->exception_index = excp;cpu_loop_exit (); } + +void HELPER (exception_cause )(uint32_t pc,uint32_t cause) +{ +uint32_t vector; + + env->pc = pc; +if (env->sregs[PS ] &PS_EXCM ) { +if (env->config->ndepc) { + env->sregs[DEPC ] = pc; + }else { + env->sregs[EPC1 ] = pc; + } + vector =EXC_DOUBLE ; + }else { + env->sregs[EPC1 ] = pc; + vector = (env->sregs[PS ] &PS_UM ) ?EXC_USER :EXC_KERNEL ; + } + + env->sregs[EXCCAUSE ] = cause; + env->sregs[PS ] |=PS_EXCM ; + +HELPER (exception)(vector); +} + +void HELPER (exception_cause_vaddr )(uint32_t pc,uint32_t cause,uint32_t vaddr) +{ + env->sregs[EXCVADDR ] = vaddr; +HELPER (exception_cause)(pc, cause); +}
target-xtensa/translate.c +119 -5
194 lines not on this page · raw message
Signature · 1 line
1.7.3.4
RFC 19/28 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
@@ -793,7 +793,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_DIVIE_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
RFC 20/28 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 | 6 ++ target-xtensa/helper.c | 1 + target-xtensa/helpers.h | 8 ++ target-xtensa/op_helper.c | 172 +++++++++++++++++++++++++++++++++++++++++++++ target-xtensa/translate.c | 134 ++++++++++++++++++++++++++++++++--- 5 files changed, 312 insertions(+), 9 deletions(-)
target-xtensa/cpu.h +6 -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;
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
@@ -3,5 +3,13 @@ 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(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 +172 -0
175 lines not on this page · raw message
target-xtensa/translate.c +125 -9
216 lines not on this page · raw message
Signature · 1 line
1.7.3.4
RFC 21/28 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.
--- target-xtensa/cpu.h | 3 ++ target-xtensa/helpers.h | 1 + target-xtensa/op_helper.c | 11 ++++++ target-xtensa/translate.c | 80 +++++++++++++++++++++++++++++++++++++------- 4 files changed, 82 insertions(+), 13 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 +1 -0
@@ -10,6 +10,7 @@ DEF_HELPER_1(rotw, void, i32) DEF_HELPER_2(window_check, void, i32, i32) DEF_HELPER_0(restore_owb, void) DEF_HELPER_1(movsp, void, i32) +DEF_HELPER_1(wsr_lend, void, i32) DEF_HELPER_0(dump_state, void)#include "def-helper.h"
target-xtensa/op_helper.c +11 -0
@@ -253,6 +253,17 @@ void HELPER(movsp)(uint32_t pc) } } +void HELPER (wsr_lend )(uint32_t v) +{ +if (env->sregs[LEND ] != v) { +tb_invalidate_phys_page_range ( + env->sregs[LEND ] -1 , env->sregs[LEND ],0 ); + env->sregs[LEND ] = v; +tb_invalidate_phys_page_range ( + env->sregs[LEND ] -1 , env->sregs[LEND ],0 ); + } +} +void HELPER (dump_state )(void ) {cpu_dump_state (env, stderr, fprintf,0 );
target-xtensa/translate.c +67 -13
163 lines not on this page · raw message
Signature · 1 line
1.7.3.4
RFC 22/28 target-xtensa: implement extended L32R
In reply to Max FilippovSee ISA, 4.3.3 for details.
Enable bit of LITBASE may be stored separately for further speedup.
--- target-xtensa/cpu.h | 1 + target-xtensa/helper.c | 1 + target-xtensa/translate.c | 18 ++++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-)
target-xtensa/cpu.h +1 -0
@@ -110,6 +110,7 @@ enum {LEND =1 ,LCOUNT =2 ,SAR =3 , +LITBASE =5 ,SCOMPARE1 =12 ,WINDOW_BASE =72 , WINDOW_START = 73,
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 +16 -2
@@ -62,6 +62,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",
@@ -1168,12 +1169,25 @@ static void disas_xtensa_insn(DisasContext *dc)case 1 :/*L32R*/ { -TCGv_i32 tmp =tcg_const_i32 ( +TCGv_i32 tmp =tcg_temp_local_new_i32 (); + +tcg_gen_movi_i32 (tmp, (0xfffc0000 | (RI16_IMM16 <<2 )) + ((dc->pc +3 ) & ~3 )); -/* no ext L32R */ +if (option_enabled (dc,XTENSA_OPTION_EXTENDED_L32R )) { +TCGv_i32 tmp1 =tcg_temp_new_i32 (); +int label =gen_new_label (); + +tcg_gen_andi_i32 (tmp1, cpu_SR[LITBASE ],1 ); +tcg_gen_brcondi_i32 (TCG_COND_EQ , tmp1,0 , label); +tcg_gen_andi_i32 (tmp1, cpu_SR[LITBASE ],0xfffff000 ); +tcg_gen_addi_i32 (tmp, tmp1, (0xfffc0000 | (RI16_IMM16 <<2 ))); +gen_set_label (label); +tcg_temp_free (tmp1); + } +/* much simplified, no MMU */ tcg_gen_qemu_ld32u (cpu_R[RRR_T ], tmp,0 );tcg_temp_free (tmp); }
Signature · 1 line
1.7.3.4
RFC 23/28 target-xtensa: implement unaligned exception option
In reply to Max FilippovSee ISA, 4.4.4 for details.
Correct (aligned as per ISA) address for unaligned access is generated in case this option is not enabled.
--- target-xtensa/translate.c | 33 +++++++++++++++++++++++++++++++-- 1 files changed, 31 insertions(+), 2 deletions(-)
target-xtensa/translate.c +31 -2
@@ -176,6 +176,16 @@ static void gen_exception_cause(DisasContext *dc, uint32_t cause)tcg_temp_free (_cause); } +static void gen_exception_cause_vaddr (DisasContext *dc,uint32_t cause, +TCGv_i32 vaddr) +{ +TCGv_i32 _pc =tcg_const_i32 (dc->pc); +TCGv_i32 _cause =tcg_const_i32 (cause); +gen_helper_exception_cause_vaddr (_pc, _cause, vaddr); +tcg_temp_free (_pc); +tcg_temp_free (_cause); +} +static void gen_check_privilege (DisasContext *dc) {if (option_enabled (dc,XTENSA_OPTION_MMU )) {
@@ -249,6 +259,20 @@ static void gen_jumpi_check_loop_end(DisasContext *dc, uint32_t dest)gen_jumpi (dc, dest); } +static void gen_load_store_alignment (DisasContext *dc,int shift,TCGv_i32 addr) +{ +TCGv_i32 tmp =tcg_temp_local_new_i32 (); +tcg_gen_mov_i32 (tmp, addr); +tcg_gen_andi_i32 (addr, addr, ~0 << shift); +if (option_enabled (dc,XTENSA_OPTION_UNALIGNED_EXCEPTION )) { +int label =gen_new_label (); +tcg_gen_brcond_i32 (TCG_COND_EQ , addr, tmp, label); +gen_exception_cause_vaddr (dc,LOAD_STORE_ALIGNMENT_CAUSE , tmp); +gen_set_label (label); + } +tcg_temp_free (tmp); +} +static void disas_xtensa_insn (DisasContext *dc) {#define HAS_OPTION (opt) do { \
@@ -1195,8 +1219,11 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*LSAI*/ #define gen_load_store (type, shift) do { \ - TCGv_i32 addr = tcg_temp_new_i32(); \ + TCGv_i32 addr = tcg_temp_local_new_i32(); \ tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \ + if (shift) { \ + gen_load_store_alignment(dc, shift, addr); \ + } \ tcg_gen_qemu_##type(cpu_R[RRI8_T], addr, 0); \ tcg_temp_free(addr); \ } while (0)
@@ -1355,6 +1382,7 @@ static void disas_xtensa_insn(DisasContext *dc)tcg_gen_mov_i32 (tmp, cpu_R[RRI8_T ]);tcg_gen_addi_i32 (addr, cpu_R[RRI8_S ],RRI8_IMM8 <<2 ); +gen_load_store_alignment (dc,2 , addr);tcg_gen_qemu_ld32u (cpu_R[RRI8_T ], addr,0 );tcg_gen_brcond_i32 (TCG_COND_NE , tmp, cpu_SR[SCOMPARE1 ], label);
@@ -1614,8 +1642,9 @@ static void disas_xtensa_insn(DisasContext *dc)break ;#define gen_narrow_load_store (type) do { \ - TCGv_i32 addr = tcg_temp_new_i32(); \ + TCGv_i32 addr = tcg_temp_local_new_i32(); \ tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \ + gen_load_store_alignment(dc, 2, addr); \ tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, 0); \ tcg_temp_free(addr); \ } while (0)
Signature · 1 line
1.7.3.4
RFC 24/28 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.
--- target-xtensa/helpers.h | 1 + target-xtensa/op_helper.c | 7 ++ target-xtensa/simcall.c | 157 +++++++++++++++++++++++++++++++++++++++++++++ target-xtensa/translate.c | 2 +- 4 files changed, 166 insertions(+), 1 deletions(-) create mode 100644 target-xtensa/simcall.c
target-xtensa/helpers.h +1 -0
@@ -11,6 +11,7 @@ DEF_HELPER_2(window_check, void, i32, i32) DEF_HELPER_0(restore_owb, void) DEF_HELPER_1(movsp, void, i32) DEF_HELPER_1(wsr_lend, void, i32) +DEF_HELPER_0(simcall, void) DEF_HELPER_0(dump_state, void)#include "def-helper.h"
target-xtensa/op_helper.c +7 -0
@@ -264,6 +264,13 @@ void HELPER(wsr_lend)(uint32_t v) } } +#include "simcall.c" + +void HELPER (simcall )(void ) +{ +simcall (env->regs); +} +void HELPER (dump_state )(void ) {cpu_dump_state (env, stderr, fprintf,0 );
target-xtensa/simcall.c new file +157 -0
157 lines not on this page · raw message
target-xtensa/translate.c +1 -1
@@ -566,7 +566,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 1 :/*SIMCALL*/ -TBD (); +gen_helper_simcall ();break ;default :
Signature · 1 line
1.7.3.4
RFC 25/28 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.7 (timer interrupt option) for details.
CCOUNT SR is incremented before every command and timer interrupt checking is inserted before every command. It may be done on TB boundary for optimization.
WAITI doesn't go to sleep, but just sets PS.INTLEVEL. Timer may be used to avoid busy looping.
--- hw/xtensa_pic.c | 43 ++++++++++++++++++++ target-xtensa/cpu.h | 33 +++++++++++++++ target-xtensa/helper.c | 79 +++++++++++++++++++++++++++++++++++- target-xtensa/helpers.h | 4 ++ target-xtensa/op_helper.c | 18 ++++++++ target-xtensa/translate.c | 98 ++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 272 insertions(+), 3 deletions(-)
hw/xtensa_pic.c +43 -0
@@ -9,3 +9,46 @@ void pic_info(Monitor *mon)void irq_info (Monitor *mon) { } + +void check_interrupts (CPUState *env) +{ +int minlevel =xtensa_get_cintlevel (env); +int level; + +for (level = env->config->nlevel; level > minlevel; --level) { +if (env->config->level_mask[level] & + env->sregs[INTSET ] & + env->sregs[INTENABLE ]) { + 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) { +printf ("%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_irq_init (CPUState *env) +{ + env->irq_inputs = (void **)qemu_allocate_irqs ( + xtensa_set_irq, env, env->config->ninterrupt); +}
target-xtensa/cpu.h +33 -0
@@ -116,10 +116,16 @@ enum {WINDOW_START =73 ,EPC1 =177 ,DEPC =192 , +EPS2 =194 ,EXCSAVE1 =209 , +INTSET =226 , +INTCLEAR =227 , +INTENABLE =228 ,PS =230 ,EXCCAUSE =232 , +CCOUNT =234 ,EXCVADDR =238 , + CCOMPARE = 240, };#define PS_INTLEVEL 0xf
@@ -141,6 +147,10 @@ enum {#define PS_WOE 0x40000#define MAX_NAREG 64 +#define MAX_NINTERRUPT 32 +#define MAX_NLEVEL 6 +#define MAX_NNMI 1 +#define MAX_NCCOMPARE 3enum {/* Static vectors */
@@ -190,6 +200,16 @@ enum { COPROCESSOR0_DISABLED = 32, }; +typedef enum { +INTTYPE_LEVEL , +INTTYPE_EDGE , +INTTYPE_NMI , +INTTYPE_SOFTWARE , +INTTYPE_TIMER , +INTTYPE_DEBUG , +INTTYPE_WRITE_ERR , +}interrupt_type_t ; + typedef struct XtensaConfig { const char *name; uint64_t options;
@@ -197,6 +217,14 @@ typedef struct XtensaConfig {int excm_level;int ndepc;uint32_t exception_vector[EXC_MAX ]; +unsigned ninterrupt; +unsigned nlevel; +uint32_t interrupt_vector[MAX_NLEVEL +MAX_NNMI +1 ]; +uint32_t level[MAX_NINTERRUPT ]; +uint32_t level_mask[MAX_NLEVEL +MAX_NNMI +1 ]; +interrupt_type_t inttype[MAX_NINTERRUPT ]; +unsigned nccompare; +uint32_t timerint[MAX_NCCOMPARE ]; } XtensaConfig; typedef struct CPUXtensaState {
@@ -207,6 +235,9 @@ typedef struct CPUXtensaState {uint32_t uregs[256 ];uint32_t phys_regs[MAX_NAREG ]; +int pending_irq_level;/* level of last raised IRQ */ +void **irq_inputs; +int exception_taken;CPU_COMMON
@@ -222,6 +253,8 @@ CPUXtensaState *cpu_xtensa_init(const char *cpu_model);void xtensa_translate_init (void );int cpu_xtensa_exec (CPUXtensaState *s);void do_interrupt (CPUXtensaState *s); +void check_interrupts (CPUXtensaState *s); +void xtensa_irq_init (CPUState *env);int cpu_xtensa_signal_handler (int host_signum,void *pinfo,void *puc);void xtensa_cpu_list (FILE *f,fprintf_function cpu_fprintf);
target-xtensa/helper.c +78 -1
117 lines not on this page · raw message
target-xtensa/helpers.h +4 -0
@@ -14,4 +14,8 @@ DEF_HELPER_1(wsr_lend, void, i32) DEF_HELPER_0(simcall, void) DEF_HELPER_0(dump_state, void) +DEF_HELPER_0(check_interrupts, void) +DEF_HELPER_2(waiti, void, i32, i32) +DEF_HELPER_2(timer_irq, void, i32, i32) +#include "def-helper.h"
target-xtensa/op_helper.c +18 -0
@@ -27,6 +27,7 @@#include "exec.h" #include "helpers.h" +#include "hw/irq.h" #define MMUSUFFIX _mmu
@@ -275,3 +276,20 @@ void HELPER(dump_state)(void) {cpu_dump_state (env, stderr, fprintf,0 ); } + +void HELPER (check_interrupts )(void ) +{ +check_interrupts (env); +} + +void HELPER (waiti )(uint32_t pc,uint32_t intlevel) +{ + env->sregs[PS ] = (env->sregs[PS ] & ~PS_INTLEVEL ) | + (intlevel <<PS_INTLEVEL_SHIFT ); +check_interrupts (env); +} + +void HELPER (timer_irq )(uint32_t id,uint32_t active) +{ +qemu_set_irq (env->irq_inputs[env->config->timerint[id]], active); +}
target-xtensa/translate.c +96 -2
167 lines not on this page · raw message
Signature · 1 line
1.7.3.4
RFC 26/28 target-xtensa: implement accurate window check
In reply to Max FilippovSee ISA, 4.7.1.3 for details.
Window check is inserted before commands that push "used register watermark" beyond its current level. Used register watermark is reset on instructions that change WINDOW_BASE/WINDOW_START SRs.
--- target-xtensa/translate.c | 105 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 105 insertions(+), 0 deletions(-)
target-xtensa/translate.c +105 -0
@@ -47,6 +47,7 @@ typedef struct DisasContext {uint32_t lend;int is_jmp;int singlestep_enabled; +unsigned used_window; } DisasContext;static TCGv_ptr cpu_env;
@@ -153,6 +154,11 @@ static void gen_check_interrupts(DisasContext *dc)gen_helper_check_interrupts (); } +static void reset_used_window (DisasContext *dc) +{ + dc->used_window =0 ; +} +static void gen_rsr (TCGv_i32 d,int sr) {if (sregnames[sr]) {
@@ -170,11 +176,19 @@ static void gen_wsr_lend(DisasContext *dc, uint32_t sr, TCGv_i32 v)static void gen_wsr_windowbase (DisasContext *dc,uint32_t sr,TCGv_i32 v) {gen_helper_wsr_windowbase (v); +reset_used_window (dc); +} + +static void gen_wsr_windowstart (DisasContext *dc,uint32_t sr,TCGv_i32 v) +{ +tcg_gen_mov_i32 (cpu_SR[sr], v); +reset_used_window (dc); }static void gen_wsr_ps (DisasContext *dc,uint32_t sr,TCGv_i32 v) {tcg_gen_mov_i32 (cpu_SR[sr], v); +reset_used_window (dc);gen_check_interrupts (dc); }
@@ -194,6 +208,7 @@ static void gen_wsr(DisasContext *dc, uint32_t sr, TCGv_i32 s) uint32_t sr, TCGv_i32 v) = { [LEND ] = gen_wsr_lend, [WINDOW_BASE ] = gen_wsr_windowbase, + [WINDOW_START ] = gen_wsr_windowstart, [PS ] = gen_wsr_ps, [CCOMPARE ] = gen_wsr_ccompare, [CCOMPARE +1 ] = gen_wsr_ccompare,
@@ -333,6 +348,31 @@ static void gen_waiti(DisasContext *dc, uint32_t imm4)tcg_temp_free (intlevel); } +static void gen_window_check1 (DisasContext *dc,unsigned r1) +{ +if (option_enabled (dc,XTENSA_OPTION_WINDOWED_REGISTER ) && + r1 /4 > dc->used_window) { +TCGv_i32 pc =tcg_const_i32 (dc->pc); +TCGv_i32 w =tcg_const_i32 (r1 /4 ); + +gen_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 { \
@@ -453,6 +493,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 ;
@@ -473,6 +514,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*/ {
@@ -503,6 +545,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_helper_movsp (pc);
@@ -640,6 +683,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 6 :/*RSILx*/ HAS_OPTION (XTENSA_OPTION_INTERRUPT );gen_check_privilege (dc); +gen_window_check1 (dc,RRR_T );tcg_gen_mov_i32 (cpu_R[RRR_T ], cpu_SR[PS ]);tcg_gen_ori_i32 (cpu_SR[PS ], cpu_SR[PS ],RRR_S ); tcg_gen_andi_i32(cpu_SR[PS], cpu_SR[PS],
@@ -681,24 +725,29 @@ 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 );tcg_gen_andi_i32 (cpu_SR[SAR ], cpu_R[RRR_S ],0x1f );break ;case 1 :/*SSL*/ +gen_window_check1 (dc,RRR_S ); {TCGv_i32 base =tcg_const_i32 (32 );TCGv_i32 tmp =tcg_temp_new_i32 ();
@@ -710,6 +759,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 2 :/*SSA8L*/ +gen_window_check1 (dc,RRR_S ); {TCGv_i32 tmp =tcg_temp_new_i32 ();tcg_gen_andi_i32 (tmp, cpu_R[RRR_S ],0x3 );
@@ -719,6 +769,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 3 :/*SSA8B*/ +gen_window_check1 (dc,RRR_S ); {TCGv_i32 base =tcg_const_i32 (32 );TCGv_i32 tmp =tcg_temp_new_i32 ();
@@ -750,6 +801,7 @@ 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 ;
@@ -760,6 +812,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 15 :/*NSAUu*/ HAS_OPTION (XTENSA_OPTION_MISC_OP ); +gen_window_check2 (dc,RRR_S ,RRR_T ); {#define gen_bit_bisect (w) do { \ int label = gen_new_label(); \
@@ -806,6 +859,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 ]);
@@ -833,12 +887,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 );
@@ -848,12 +904,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 );
@@ -868,17 +926,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 ;
@@ -888,6 +949,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 (cpu_R[RRR_T ],RSR_SR );gen_wsr (dc,RSR_SR , tmp);
@@ -913,6 +975,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 8 :/*SRC*/ {TCGv_i64 v =tcg_temp_new_i64 (); +gen_window_check3 (dc,RRR_R ,RRR_S ,RRR_T );tcg_gen_concat_i32_i64 (v, cpu_R[RRR_T ], cpu_R[RRR_S ]);gen_shift (shr); }
@@ -921,6 +984,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 9 :/*SRL*/ {TCGv_i64 v =tcg_temp_new_i64 (); +gen_window_check2 (dc,RRR_R ,RRR_T );tcg_gen_extu_i32_i64 (v, cpu_R[RRR_T ]);gen_shift (shr); }
@@ -930,6 +994,7 @@ static void disas_xtensa_insn(DisasContext *dc) {TCGv_i64 v =tcg_temp_new_i64 ();TCGv_i32 s =tcg_const_i32 (32 ); +gen_window_check2 (dc,RRR_R ,RRR_S );tcg_gen_sub_i32 (s, s, cpu_SR[SAR ]);tcg_gen_extu_i32_i64 (v, cpu_R[RRR_S ]);gen_shift_reg (shl, s);
@@ -940,6 +1005,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 11 :/*SRA*/ {TCGv_i64 v =tcg_temp_new_i64 (); +gen_window_check2 (dc,RRR_R ,RRR_T );tcg_gen_ext_i32_i64 (v, cpu_R[RRR_T ]);gen_shift (sar); }
@@ -949,6 +1015,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 ();
@@ -962,6 +1029,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 ();
@@ -980,6 +1048,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 ();
@@ -1047,6 +1117,7 @@ static void disas_xtensa_insn(DisasContext *dc)if (RSR_SR >=64 ) {gen_check_privilege (dc); } +gen_window_check1 (dc,RRR_T );gen_rsr (cpu_R[RRR_T ],RSR_SR );if (!sregnames[RSR_SR ]) {TBD ();
@@ -1057,6 +1128,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 ();
@@ -1065,6 +1137,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 ); {TCGv_i32 tmp =tcg_temp_new_i32 ();tcg_gen_shli_i32 (tmp, cpu_R[RRR_S ],24 -RRR_T );
@@ -1075,6 +1148,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 ();
@@ -1102,6 +1176,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 ,
@@ -1129,6 +1204,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 ,
@@ -1154,6 +1230,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]) {
@@ -1166,6 +1243,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 ]);
@@ -1181,6 +1259,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 ;
@@ -1206,6 +1285,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 );
@@ -1256,6 +1336,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 1 :/*L32R*/ +gen_window_check1 (dc,RRR_T ); {TCGv_i32 tmp =tcg_temp_local_new_i32 ();
@@ -1284,6 +1365,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*LSAI*/ #define gen_load_store (type, shift) do { \ TCGv_i32 addr = tcg_temp_local_new_i32(); \ + gen_window_check2(dc, RRI8_S, RRI8_T); \ tcg_gen_addi_i32(addr, cpu_R[RRI8_S], RRI8_IMM8 << shift); \ if (shift) { \ gen_load_store_alignment(dc, shift, addr); \
@@ -1419,6 +1501,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 10 :/*MOVI*/ +gen_window_check1 (dc,RRI8_T );tcg_gen_movi_i32 (cpu_R[RRI8_T ],RRI8_IMM8 | (RRI8_S <<8 ) | ((RRI8_S &0x8 ) ?0xfffff000 :0 ));
@@ -1430,15 +1513,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 ();
@@ -1491,6 +1577,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 ); {TCGv_i32 tmp =tcg_const_i32 ( (dc->pc & ~3 ) + (CALL_OFFSET_SE <<2 ) +4 );
@@ -1508,6 +1595,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 1 :/*BZ*/ +gen_window_check1 (dc,BRI12_S ); {int label =gen_new_label ();int inv =BRI12_M &1 ;
@@ -1530,6 +1618,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 2 :/*BI0*/ +gen_window_check1 (dc,BRI8_S ); {int label =gen_new_label ();int inv =BRI8_M &1 ;
@@ -1563,6 +1652,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 ;
@@ -1582,6 +1672,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);
@@ -1613,6 +1704,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 2 :/*BLTUI*/ case 3 :/*BGEUI*/ +gen_window_check1 (dc,BRI8_S ); {int label =gen_new_label ();int inv =BRI8_M &1 ;
@@ -1638,6 +1730,7 @@ static void disas_xtensa_insn(DisasContext *dc)switch (RRI8_R &7 ) {case 0 :/*BNONE*/ +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 ]);
@@ -1648,21 +1741,25 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 1 :/*BEQ*/ +gen_window_check2 (dc,RRI8_S ,RRI8_T );tcg_gen_brcond_i32 (inv ?TCG_COND_EQ :TCG_COND_NE , cpu_R[RRI8_S ], cpu_R[RRI8_T ], label);break ;case 2 :/*BLT*/ +gen_window_check2 (dc,RRI8_S ,RRI8_T );tcg_gen_brcond_i32 (inv ?TCG_COND_LT :TCG_COND_GE , cpu_R[RRI8_S ], cpu_R[RRI8_T ], label);break ;case 3 :/*BLTU*/ +gen_window_check2 (dc,RRI8_S ,RRI8_T );tcg_gen_brcond_i32 (inv ?TCG_COND_LTU :TCG_COND_GEU , cpu_R[RRI8_S ], cpu_R[RRI8_T ], label);break ;case 4 :/*BALL*/ +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 ]);
@@ -1673,6 +1770,7 @@ static void disas_xtensa_insn(DisasContext *dc)break ;case 5 :/*BBC*/ +gen_window_check2 (dc,RRI8_S ,RRI8_T ); {TCGv_i32 bit =tcg_const_i32 (1 );TCGv_i32 tmp =tcg_temp_new_i32 ();
@@ -1688,6 +1786,7 @@ static void disas_xtensa_insn(DisasContext *dc)case 6 :/*BBCI*/ case 7 : +gen_window_check1 (dc,RRI8_S ); {TCGv_i32 tmp =tcg_temp_new_i32 (); tcg_gen_andi_i32(tmp, cpu_R[RRI8_S],
@@ -1707,6 +1806,7 @@ static void disas_xtensa_insn(DisasContext *dc)#define gen_narrow_load_store (type) do { \ TCGv_i32 addr = tcg_temp_local_new_i32(); \ + gen_window_check2(dc, RRRN_S, RRRN_T); \ tcg_gen_addi_i32(addr, cpu_R[RRRN_S], RRRN_R << 2); \ gen_load_store_alignment(dc, 2, addr); \ tcg_gen_qemu_##type(cpu_R[RRRN_T], addr, 0); \
@@ -1723,14 +1823,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) |
@@ -1750,6 +1853,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 ;
@@ -1868,6 +1972,7 @@ static void gen_intermediate_code_internal( dc.pc = env->pc; dc.lend = env->sregs[LEND ]; dc.is_jmp =DISAS_NEXT ; +reset_used_window (&dc);gen_icount_start ();
Signature · 1 line
1.7.3.4
RFC 27/28 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
@@ -18,6 +18,7 @@ static void xtensa_init(ram_addr_t ram_size,fprintf (stderr,"Unable to find CPU definition\n" );exit (1 ); } + env->sregs[PRID ] = n; } ram_offset =qemu_ram_alloc (NULL ,"xtensa.dram" ,0x10000 );
target-xtensa/cpu.h +2 -0
@@ -118,12 +118,14 @@ enum {DEPC =192 ,EPS2 =194 ,EXCSAVE1 =209 , +CPENABLE =224 ,INTSET =226 ,INTCLEAR =227 ,INTENABLE =228 ,PS =230 ,EXCCAUSE =232 ,CCOUNT =234 , +PRID =235 ,EXCVADDR =238 , CCOMPARE = 240, };
target-xtensa/translate.c +7 -0
@@ -88,12 +88,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",
@@ -192,6 +194,10 @@ static void gen_wsr_ps(DisasContext *dc, uint32_t sr, TCGv_i32 v)gen_check_interrupts (dc); } +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 );
@@ -210,6 +216,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
RFC 28/28 target-xtensa: implement relocatable vectors
In reply to Max FilippovSee ISA, 4.4.3 for details.
Vector addresses recorded in core configuration are absolute values that correspond to default VECBASE value.
--- target-xtensa/cpu.h | 2 ++ target-xtensa/helper.c | 18 ++++++++++++++++-- target-xtensa/translate.c | 1 + 3 files changed, 19 insertions(+), 2 deletions(-)
target-xtensa/cpu.h +2 -0
@@ -123,6 +123,7 @@ enum {INTCLEAR =227 ,INTENABLE =228 ,PS =230 , +VECBASE =231 ,EXCCAUSE =232 ,CCOUNT =234 , PRID = 235,
@@ -218,6 +219,7 @@ typedef struct XtensaConfig {unsigned nareg;int excm_level;int ndepc; +uint32_t vecbase;uint32_t exception_vector[EXC_MAX ];unsigned ninterrupt;unsigned nlevel;
target-xtensa/helper.c +16 -2
@@ -40,6 +40,7 @@ void cpu_reset(CPUXtensaState *env) env->pc = env->config->exception_vector[EXC_RESET ]; env->sregs[LITBASE ] &= ~1 ; env->sregs[PS ] =0x1f ; + env->sregs[VECBASE ] = env->config->vecbase; env->pending_irq_level =0 ; }
@@ -51,6 +52,7 @@ static const XtensaConfig core_config[] = { .nareg = 64, .ndepc = 1, .excm_level = 16, + .vecbase = 0x5fff8400, .exception_vector = { [EXC_RESET] = 0x5fff8000, [EXC_WINDOW_OVERFLOW4] = 0x5fff8400,
@@ -137,6 +139,16 @@ target_phys_addr_t cpu_get_phys_page_debug(CPUState *env, target_ulong addr)return addr; } +static uint32_t relocated_vector (CPUState *env,uint32_t vector) +{ +if (xtensa_option_enabled (env->config, +XTENSA_OPTION_RELOCATABLE_VECTOR )) { +return vector - env->config->vecbase + env->sregs[VECBASE ]; + }else { +return vector; + } +} +static int handle_interrupt (CPUState *env) {int handled =1 ;
@@ -150,7 +162,8 @@ static int handle_interrupt(CPUState *env)if (level >1 ) { env->sregs[EPC1 + level -1 ] = env->pc; env->sregs[EPS2 + level -2 ] = env->sregs[PS ]; - env->pc = env->config->interrupt_vector[level]; + env->pc =relocated_vector (env, + env->config->interrupt_vector[level]); }else { handled =0 ; env->sregs[EXCCAUSE ] =LEVEL1_INTERRUPT_CAUSE ;
@@ -196,7 +209,8 @@ void do_interrupt(CPUState *env)case EXC_USER :case EXC_DOUBLE :if (env->config->exception_vector[env->exception_index]) { - env->pc = env->config->exception_vector[env->exception_index]; + env->pc =relocated_vector (env, + env->config->exception_vector[env->exception_index]); env->exception_taken =1 ; env->interrupt_request |=CPU_INTERRUPT_EXITTB ; }else {
target-xtensa/translate.c +1 -0
@@ -93,6 +93,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
Quoted 6 lines
+#elif
defined(TARGET_XTENSA)
+ if (interrupt_request&CPU_INTERRUPT_HARD) {
+ env->exception_index =EXC_IRQ;
+ do_interrupt(env);
+ next_tb = 0;
+ }
Looks like I've moved this hunk here from 'target-xtensa: implement exceptions' by mistake ): It will not compile until then.
Thanks.
-- Max
Re: [Qemu-devel] [RFC 03/28] target-xtensa: implement disas_xtensa_insn
In reply to Max Filippovtarget-xtensa/translate.c line 92
Quoted 8 lines · Max Filippov
target-xtensa/translate.c +8
-0+static void gen_jump (DisasContext *dc,TCGv dest) +{ +tcg_gen_mov_i32 (cpu_pc, dest); +if (dc->singlestep_enabled) { +gen_exception (EXCP_DEBUG ); + } +tcg_gen_exit_tb (0 ); + dc->is_jmp =DISAS_UPDATE ;
You're generating useless instructions here. The exception is a noreturn function. It performs a longjmp to back out of the cpu loop.
Thus the exit_tb should be in an else here.
target-xtensa/translate.c line 335
Quoted 2 lines
target-xtensa/translate.c +2
-0+invalid_opcode: +printf ("INVALID(pc = %08x): %s:%d\n" , dc->pc, __FILE__, __LINE__);
Don't printf. Use the logging functions properly.
r~
Re: [Qemu-devel] [RFC 08/28] target-xtensa: implement conditional jumps
In reply to Max FilippovQuoted 7 lines · Max Filippov
target-xtensa/translate.c +7
-0+int label =gen_new_label (); +int inv =BRI12_M &1 ; + +switch (BRI12_M &2 ) { +case 0 :/*BEQZ*/ +tcg_gen_brcondi_i32 (inv ?TCG_COND_EQ :TCG_COND_NE , + cpu_R[BRI12_S ],0 , label);
target-xtensa/translate.c static void disas_xtensa_insn(DisasContext *dc) · line 360
Quoted 10 lines
target-xtensa/translate.c +10
-0+break ; + +case 2 :/*BLTZ*/ +tcg_gen_brcondi_i32 (inv ?TCG_COND_LT :TCG_COND_GE , + cpu_R[BRI12_S ],0 , label); +break ; + } +gen_jumpi (dc, dc->pc +4 +BRI12_IMM12_SE ); +gen_set_label (label); +gen_jumpi (dc, dc->pc +3 );
It seems to me that this code could be cleaned up by extracting the branching and jumpi'ing into a function. There's a lot of repetition here.
Also, once you do get around to using chained TB's, there'll be only one place to have to update to get that to happen.
r~
Re: [Qemu-devel] [RFC 11/28] target-xtensa: implement RST3 group
In reply to Max Filippovtarget-xtensa/translate.c static void disas_xtensa_insn(DisasContext *dc) · line 382
Quoted 7 lines · Max Filippov
target-xtensa/translate.c +7
-0+case 2 :/*SEXTu*/ +HAS_OPTION (XTENSA_OPTION_MISC_OP ); + { +TCGv_i32 tmp =tcg_temp_new_i32 (); +tcg_gen_shli_i32 (tmp, cpu_R[RRR_S ],24 -RRR_T ); +tcg_gen_sari_i32 (cpu_R[RRR_R ], tmp,24 -RRR_T ); +tcg_temp_free (tmp);
It's probably worth special-casing extensions from bit 7 and 15 as normal 8 and 16-bit sign-extensions. Those are likely to be 99% of all extension operations actually performed.
r~
Re: [Qemu-devel] [RFC 12/28] target-xtensa: implement shifts (ST1 and RST1 groups)
In reply to Max FilippovQuoted 23 lines · Max Filippov
target-xtensa/translate.c +23
-0+HAS_OPTION (XTENSA_OPTION_MISC_OP ); + { +#define gen_bit_bisect (w) do { \ + int label = gen_new_label(); \ + tcg_gen_brcondi_i32(TCG_COND_LTU, tmp, 1 << (w), label); \ + tcg_gen_shri_i32(tmp, tmp, (w)); \ + tcg_gen_subi_i32(res, res, (w)); \ + gen_set_label(label); \ + } while (0) + +int label =gen_new_label (); +TCGv_i32 res =tcg_temp_local_new_i32 (); + +tcg_gen_movi_i32 (res,32 ); +tcg_gen_brcondi_i32 ( +TCG_COND_EQ , cpu_R[RRR_S ],0 , label); + { +TCGv_i32 tmp =tcg_temp_local_new_i32 (); +tcg_gen_mov_i32 (tmp, cpu_R[RRR_S ]); +tcg_gen_movi_i32 (res,31 ); + +gen_bit_bisect (16 ); +gen_bit_bisect (8 );
target-xtensa/translate.c static void disas_xtensa_insn(DisasContext *dc) · line 387
Quoted 10 lines
target-xtensa/translate.c +10
-0+gen_bit_bisect (4 ); +gen_bit_bisect (2 ); +gen_bit_bisect (1 ); + +tcg_temp_free (tmp); + } +gen_set_label (label); +tcg_gen_mov_i32 (cpu_R[RRR_T ], res); +tcg_temp_free (res); +#undef gen_bit_bisect
This instruction is probably right at the edge of the size restrictions on the number of ops allowed to be emitted per guest insn. It probably makes more sense to move this to an out-of-line helper function.
Also note that this is implementable more efficiently on hosts that have a count-leading-zeros function:
uint32_t HELPER(nsau)(uint32_t val)
{
return val ? clz32(val) : 32;
}uint32_t HELPER(nsa)(int32_t val)
{
if (val < 0) {
val = ~val;
}
if (val == 0) {
return 31;
}
return clz32(val) - 1;
}Quoted 15 lines
target-xtensa/translate.c +15
-0+case 9 :/*SRL*/ + { +TCGv_i64 v =tcg_temp_new_i64 (); +tcg_gen_extu_i32_i64 (v, cpu_R[RRR_T ]); +gen_shift (shr); + } +break ; + +case 10 :/*SLL*/ + { +TCGv_i64 v =tcg_temp_new_i64 (); +TCGv_i32 s =tcg_const_i32 (32 ); +tcg_gen_sub_i32 (s, s, cpu_SR[SAR ]); +tcg_gen_extu_i32_i64 (v, cpu_R[RRR_S ]); +gen_shift_reg (shl, s);
target-xtensa/translate.c static void disas_xtensa_insn(DisasContext *dc) · line 528
Quoted 10 lines
target-xtensa/translate.c +10
-0+tcg_temp_free (s); + } +break ; + +case 11 :/*SRA*/ + { +TCGv_i64 v =tcg_temp_new_i64 (); +tcg_gen_ext_i32_i64 (v, cpu_R[RRR_T ]); +gen_shift (sar); + }
Are you implementing some of these as 64-bit shifts simply to get a shift count of 32 correct? While I admit that it's probably the most efficient mechanism when the host is 64-bit, it's somewhat less than clear. You could stand to add some commentary here about your choice.
As a future enhancement, it might be worthwhile to track any known contents of SAR within the TB (see how other ports put information about the state of the flags register in the DisassContext). If you have a known value in the SAR, you can emit the proper 32-bit shift directly.
r~
Re: [Qemu-devel] [RFC 18/28] target-xtensa: implement exceptions
In reply to Max FilippovQuoted 7 lines · Max Filippov
target-xtensa/translate.c +7
-0+static void gen_check_privilege (DisasContext *dc) +{ +if (option_enabled (dc,XTENSA_OPTION_MMU )) { +TCGv_i32 tmp =tcg_temp_new_i32 (); +int label =gen_new_label (); + +tcg_gen_andi_i32 (tmp, cpu_SR[PS ],PS_EXCM );
target-xtensa/translate.c static void gen_exception(int excp) · line 176
Quoted 10 lines
target-xtensa/translate.c +10
-0+tcg_gen_brcondi_i32 (TCG_COND_EQ , tmp,PS_EXCM , label); +tcg_gen_andi_i32 (tmp, cpu_SR[PS ],PS_RING ); +tcg_gen_brcondi_i32 (TCG_COND_GEU , tmp,0 , label); + +gen_exception_cause (dc,PRIVILEGED_CAUSE ); + +gen_set_label (label); +tcg_temp_free (tmp); + } +}
This is a case where you almost certainly want to check this condition inside QEMU and translate the opcode differently.
See cpu_get_tb_cpu_state, which sets bits in *flags. These flags can then be checked in tb->flags while translating. At which point you'd avoid all the conditionalization on the value in PS here in check_privilege and merely issue the exception_cause.
The ARM port is a good example for testing these sorts of bits.
r~
Re: [Qemu-devel] [RFC 12/28] target-xtensa: implement shifts (ST1 and RST1 groups)
In reply to Richard HendersonQuoted 46 lines
Quoted 23 lines
+ HAS_OPTION(XTENSA_OPTION_MISC_OP);
+ {target-xtensa/translate.c +21
-0+#define gen_bit_bisect (w) do { \ + int label = gen_new_label(); \ + tcg_gen_brcondi_i32(TCG_COND_LTU, tmp, 1 << (w), label); \ + tcg_gen_shri_i32(tmp, tmp, (w)); \ + tcg_gen_subi_i32(res, res, (w)); \ + gen_set_label(label); \ + } while (0) + + int label = gen_new_label(); + TCGv_i32 res = tcg_temp_local_new_i32(); + + tcg_gen_movi_i32(res, 32); + tcg_gen_brcondi_i32( + TCG_COND_EQ, cpu_R[RRR_S], 0, label); + { + TCGv_i32 tmp = tcg_temp_local_new_i32(); + tcg_gen_mov_i32(tmp, cpu_R[RRR_S]); + tcg_gen_movi_i32(res, 31); + + gen_bit_bisect(16); + gen_bit_bisect(8);target-xtensa/translate.c static void disas_xtensa_insn(DisasContext *dc) · line 387
Quoted 10 lines
target-xtensa/translate.c +10
-0+ gen_bit_bisect(4); + gen_bit_bisect(2); + gen_bit_bisect(1); + + tcg_temp_free(tmp); + } + gen_set_label(label); + tcg_gen_mov_i32(cpu_R[RRR_T], res); + tcg_temp_free(res); +#undef gen_bit_bisectThis instruction is probably right at the edge of the size restrictions on the number of ops allowed to be emitted per guest insn. It probably makes more sense to move this to an out-of-line helper function.
Also note that this is implementable more efficiently on hosts that have a count-leading-zeros function:
uint32_tHELPER(nsau)(uint32_t val)
{
return val ? clz32(val) : 32;
}
Quoted 10 lines
uint32_tHELPER(nsa)(int32_t val)
{
if (val < 0) {
val = ~val;
}
if (val == 0) {
return 31;
}
return clz32(val) - 1;
}
Thanks for the hint, this way it looks much better.
Quoted 23 lines
Quoted 23 lines
+ case 9: /*SRL*/
+ {
+ TCGv_i64 v =tcg_temp_new_i64();
+ tcg_gen_extu_i32_i64(v, cpu_R[RRR_T]);
+ gen_shift(shr);
+ }
+ break;target-xtensa/translate.c +16
-0+ + case 10: /*SLL*/ + { + TCGv_i64 v = tcg_temp_new_i64(); + TCGv_i32 s = tcg_const_i32(32); + tcg_gen_sub_i32(s, s, cpu_SR[SAR]); + tcg_gen_extu_i32_i64(v, cpu_R[RRR_S]); + gen_shift_reg(shl, s); + tcg_temp_free(s); + } + break; + + case 11: /*SRA*/ + { + TCGv_i64 v = tcg_temp_new_i64(); + tcg_gen_ext_i32_i64(v, cpu_R[RRR_T]);
Quoted 8 lines
Quoted 2 lines
+ gen_shift(sar);
+ }Are you implementing some of these as 64-bit shifts simply to get a shift count of 32 correct? While I admit that it's probably the most efficient mechanism when the host is 64-bit, it's somewhat less than clear. You could stand to add some commentary here about your choice.
Yes, possibility of indirect 32 bit shift was the only reason for that. Will document that.
Quoted 5 lines
As a future enhancement, it might be worthwhile to track any known contents of SAR within the TB (see how other ports put information about the state of the flags register in the DisassContext). If you have a known value in the SAR, you can emit the proper 32-bit shift directly.
To track immediate values written to SAR? You mean that there may be some performance difference of fixed size shift vs indirect shift and TCG is able to tell them apart?
Thanks.
-- Max
Re: [Qemu-devel] [RFC 18/28] target-xtensa: implement exceptions
In reply to Richard HendersonQuoted 10 lines · Richard Henderson
This is a case where you almost certainly want to check this condition inside QEMU and translate the opcode differently.
See
cpu_get_tb_cpu_state, which sets bits in *flags. These flags can then be checked intb->flagswhile translating. At which point you'd avoid all the conditionalization on the value in PS here incheck_privilegeand merely issue theexception_cause.The ARM port is a good example for testing these sorts of bits.
Actually, while the tb flags are useful, privileged instructions are usually checked by testing mmu_index, since we already have to generate different code for the TB based on which TLB entry we need to access.
r~
Re: [Qemu-devel] [RFC 12/28] target-xtensa: implement shifts (ST1 and RST1 groups)
In reply to Max FilippovQuoted 3 lines · Max Filippov
To track immediate values written to SAR? You mean that there may be some performance difference of fixed size shift vs indirect shift and TCG is able to tell them apart?
Well, not really fixed vs indirect, but if you know that the value in the SAR register is in the right range, you can avoid using a 64-bit shift.
For instance,
SSL ar2 SLL ar0, ar1
could be implemented with
tcg_gen_sll_i32(ar0, ar1, ar2);
assuming we have enough context.
Let us decompose the SAR register into two parts, storing both the true value, and 32-value.
struct DisasContext {
// Current Stuff
// ...
// When valid, holds 32-SAR.
TCGv sar_m32;
bool sar_m32_alloc;
bool sar_m32_valid;
bool sar_5bit;
};At the beginning of the TB:
TCGV_UNUSED_I32(dc->sar_m32); dc->sar_m32_alloc = false; dc->sar_m32_valid = false; dc->sar_5bit = false;
static void gen_set_sra_m32(DisasContext *dc, TCGv val)
{
if (!dc->sar_m32_alloc) {
dc->sar_m32_alloc = true;
dc->sar_m32 = tcg_temp_local_new_i32();
}
dc->sar_m32_valid = true;
/* Clear 5 bit because the SAR value could be 32. */
dc->sar_5bit = false;
tcg_gen_movi_i32(cpu_SR[SAR], 32);
tcg_gen_sub_i32(cpu_SR[SAR], cpu_SR[SAR], val);
tcg_gen_mov_i32(dc->sar_m32, val);
}static void gen_set_sra(DisasContext *dc, TCGv val, bool is_5bit)
{
if (dc->sar_m32_alloc && dc->sar_m32_valid) {
tcg_gen_discard_i32(dc->sar_m32);
}
dc->sar_m32_valid = false;
dc->sar_5bit = is_5bit;
tcg_gen_mov_i32(cpu_SR[SAR], val);
} /* SSL */
tcg_gen_andi_i32(tmp, cpu_R[AS], 31);
gen_set_sra_m32(dc, tmp);
break;
/* SRL */
tcg_gen_andi_i32(tmp, cpu_R[AS], 31);
gen_set_sra(dc, tmp, true);
break;
/* WSR.SAR */
tcg_gen_andi_i32(tmp, cpu_R[AS], 63);
gen_set_sra(dc, tmp, false);
break;
/* SSAI */
tcg_gen_movi_i32(tmp, constant);
gen_gen_sra(dc, tmp, true);
break;
/* SLL */
if (dc->sar_m32_valid) {
tcg_gen_sll_i32(cpu_R[AR], cpu_R[AS], dc->sar_m32);
} else {
/* your existing 64-bit shift emulation. */
}
break;
/* SRL */
if (dc->sar_5bit) {
tcg_gen_srl_i32(cpu_R[AR], cpu_R[AS], cpu_SR[SAR]);
} else {
/* your existing 64-bit shift emulation. */
}A couple of points: The use of the local temp avoids problems with intervening insns that might generate branch opcodes. For the simplest cases, as with the case at the start of the message, we ought to be able to propagate the values into the TCG shift insn directly.
Does that make sense?
r~
Re: [Qemu-devel] [RFC 20/28] target-xtensa: implement windowed registers
In reply to Max FilippovQuoted 6 lines · Max Filippov
See 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.
I'm not sure how the register windows work, but maybe you could use the same trick used for Sparc. There is a pool of registers (env->regbase[]), a register window pointer (env->regwptr, cpu_regwptr) tracks which are the currently accessible ones. The advantage is to avoid copying (not entirely for Sparc due to the window overlap).
Re: [Qemu-devel] [RFC 19/28] target-xtensa: implement RST2 group (32 bit mul/div/rem)
In reply to Max FilippovQuoted 12 lines · Max Filippov
Signed-off-by Max Filippov <[email protected]>---
target-xtensa/translate.c | 60 ++++++++++++++++++++++++++++++++++++++++++++-1 files changed, 59 insertions(+), 1 deletions(-)target-xtensa/translate.c +0
-0@@ -793,7 +793,65 @@ static void disas_xtensa_insn(DisasContext *dc) break;
Quoted 7 lines
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_DIVIE_BY_ZERO_CAUSE);
DIVIE?
Re: [Qemu-devel] [RFC 24/28] target-xtensa: implement SIMCALL
In reply to Max FilippovQuoted 30 lines · Max Filippov
Tensilica 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.
Signed-off-by Max Filippov <[email protected]>---
target-xtensa/helpers.h | 1 +
target-xtensa/op_helper.c | 7 ++
target-xtensa/simcall.c | 157 +++++++++++++++++++++++++++++++++++++++++++++target-xtensa/translate.c| 2 +-4 files changed, 166 insertions(+), 1 deletions(-)create mode 100644
target-xtensa/simcall.ctarget-xtensa/helpers.h +1
-0@@ -11,6 +11,7 @@ DEF_HELPER_2(window_check, void, i32, i32) DEF_HELPER_0(restore_owb, void) DEF_HELPER_1(movsp, void, i32) DEF_HELPER_1(wsr_lend, void, i32) +DEF_HELPER_0(simcall, void) DEF_HELPER_0(dump_state, void) #include "def-helper.h"target-xtensa/op_helper.c +0
-0
target-xtensa/op_helper.c void HELPER(wsr_lend)(uint32_t v) · line 271
Quoted 8 lines
target-xtensa/op_helper.c +5
-0@@ -264,6 +264,13 @@ void HELPER(wsr_lend)(uint32_t v) } } +#include "simcall.c" + +void HELPER (simcall )(void ) +{ + simcall(env->regs);
Maybe this should be enabled only with -semihosting parameter, like ARM and m68k. Consider for example what could happen if this would be issued from userland when used with an OS.
Quoted 45 lines
target-xtensa/op_helper.c +2
-0+} + void HELPER(dump_state)(void) { cpu_dump_state(env, stderr, fprintf, 0);target-xtensa/simcall.c new file +34
-0@@ -0,0 +1,157 @@ +/* +* Copyright (c) 2011, Max Filippov, Motorola Solutions, Inc. +* 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 Motorola Solutions 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 <assert.h> +#include <errno.h> +#include <unistd.h> +#include <string.h> +#include <stddef.h> + +enum {
target-xtensa/simcall.c line 44
Quoted 10 lines
target-xtensa/simcall.c new file +10
-0+ SYS_exit = 1, + SYS_read = 3, + SYS_write = 4, + SYS_open = 5, + SYS_close = 6, + + SYS_argc = 1000, + SYS_argv_sz = 1001, + SYS_argv = 1002, + SYS_memset = 1004,
I think these names may easily conflict with system defines, please use for example TARGET_SYS_exit etc.
Quoted 88 lines
target-xtensa/simcall.c new file +88
-0+}; + +static void simcall (uint32_t regs[16 ]) +{ + switch (regs[2]) { + case SYS_exit: + printf("exit(%d)\n", regs[3]); + exit(regs[3]); + break; + + case SYS_read: + { + target_phys_addr_t len = regs[5]; + void *buf = cpu_physical_memory_map(regs[4], &len, 1); + + if (buf) { + regs[2] = read(regs[3], buf, len); + regs[3] = errno; + cpu_physical_memory_unmap(buf, len, 1, len); + } else { + regs[2] = -1; + regs[3] = 0; + } + } + break; + + case SYS_write: + { + target_phys_addr_t len = regs[5]; + void *buf = cpu_physical_memory_map(regs[4], &len, 0); + + if (buf) { + regs[2] = write(regs[3], buf, len); + regs[3] = errno; + cpu_physical_memory_unmap(buf, len, 0, len); + } else { + regs[2] = -1; + regs[3] = 0; + } + } + break; + + case SYS_open: + { + target_phys_addr_t len = 1024; + void *buf = cpu_physical_memory_map(regs[3], &len, 0); + + if (buf && strnlen((char *)buf, len) < len) { + regs[2] = open((char *)buf, regs[4], regs[5]); + regs[3] = errno; + } else { + regs[2] = -1; + regs[3] = 0; + } + } + break; + + case SYS_close: + if (regs[3] < 3) { + regs[2] = regs[3] = 0; + } else { + regs[2] = close(regs[3]); + regs[3] = errno; + } + break; + + case SYS_argc: + regs[2] = 1; + regs[3] = 0; + break; + + case SYS_argv_sz: + regs[2] = 128; + regs[3] = 0; + break; + + case SYS_argv: + { + struct Argv { + uint32_t argptr[2]; + char text[120]; + } argv = { + {0, 0}, + "test" + }; + + argv.argptr[0] = regs[3] + offsetof(struct Argv, text); + cpu_memory_rw_debug(
target-xtensa/simcall.c line 142
Quoted 10 lines
target-xtensa/simcall.c new file +10
-0+ env, regs[3], (uint8_t *)&argv, sizeof(argv), 1); + } + break; + + case SYS_memset: + { + target_phys_addr_t len = regs[5]; + void *buf = cpu_physical_memory_map(regs[3], &len, 1); + + assert(len == regs[5]);
The guest can probably trigger this assertion, which would not be safe.
Quoted 335 lines · Max Filippov
Signed-off-by Max Filippov <[email protected]>---
Makefile.target | 2 +
arch_init.c | 2 +
arch_init.h | 1 +
cpu-exec.c | 10 +++++
elf.h | 2 +
hw/xtensa_pic.c | 11 ++++++
target-xtensa/cpu.h | 84 +++++++++++++++++++++++++++++++++++++++++++++target-xtensa/exec.h| 55 +++++++++++++++++++++++++++++target-xtensa/helper.c| 74 +++++++++++++++++++++++++++++++++++++++target-xtensa/machine.c| 38 ++++++++++++++++++++target-xtensa/op_helper.c| 51 +++++++++++++++++++++++++++target-xtensa/translate.c| 67 +++++++++++++++++++++++++++++++++++12 files changed, 397 insertions(+), 0 deletions(-)create mode 100644
hw/xtensa_pic.c
create mode 100644target-xtensa/cpu.h
create mode 100644target-xtensa/exec.h
create mode 100644target-xtensa/helper.c
create mode 100644target-xtensa/machine.c
create mode 100644target-xtensa/op_helper.c
create mode 100644target-xtensa/translate.cMakefile.target +0
-0@@ -366,6 +366,8 @@ obj-s390x-y = s390-virtio-bus.o s390-virtio.oobj-alpha-y = alpha_palcode.o
Makefile.target +2
-0+obj-xtensa-y += xtensa_pic.o +main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
monitor.o:
hmp-commands.hqmp-commands.harch_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 +9
-0@@ -275,6 +275,7 @@ int cpu_exec(CPUState *env1) #elif defined(TARGET_SH4) #elif defined(TARGET_CRIS) #elif defined(TARGET_S390X) +#elif defined(TARGET_XTENSA ) /* XXXXX */ #else #error unsupported target CPU@@ -348,6 +349,8 @@ int cpu_exec(CPUState *env1) do_interrupt(0); #elif defined(TARGET_S390X) do_interrupt(env); +#elif defined(TARGET_XTENSA ) + do_interrupt(env); #endif env->exception_index = -1; #endif@@ -568,6 +571,12 @@ int cpu_exec(CPUState *env1) do_interrupt(env); next_tb = 0; } +#elif defined(TARGET_XTENSA ) + if (interrupt_request & CPU_INTERRUPT_HARD) { + env->exception_index = EXC_IRQ; + do_interrupt(env); + next_tb = 0; + } #endif /* Don't use the cached interupt_request value,
do_interruptmay have updated the EXITTB flag. */cpu-exec.c +1
-0@@ -696,6 +705,7 @@ int cpu_exec(CPUState *env1) #elif defined(TARGET_ALPHA) #elif defined(TARGET_CRIS) #elif defined(TARGET_S390X) +#elif defined(TARGET_XTENSA ) /* XXXXX */ #else #error unsupported target CPUelf.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 1hw/xtensa_pic.c new file +11
-0@@ -0,0 +1,11 @@ +#include "hw.h" +#include "pc.h" + +/* Stub functions for hardware that doesn't exist. */ +void pic_info (Monitor *mon) +{ +} + +void irq_info (Monitor *mon) +{ +}target-xtensa/cpu.h new file +84
-0@@ -0,0 +1,84 @@ +/* +* Copyright (c) 2011, Max Filippov, Motorola Solutions, Inc. +* 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 Motorola Solutions 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. +*/ + +#ifndef CPU_XTENSA_H +#define CPU_XTENSA_H + +#define TARGET_LONG_BITS 32 +#define ELF_MACHINE EM_XTENSA + +#define CPUState struct CPUXtensaState + +#include "config.h" +#include "qemu-common.h" +#include "cpu-defs.h" + +#define TARGET_HAS_ICE 1 + +#define NB_MMU_MODES 2 + +#define TARGET_PHYS_ADDR_SPACE_BITS 32 +#define TARGET_VIRT_ADDR_SPACE_BITS 32 +#define TARGET_PAGE_BITS 12 + +typedef struct CPUXtensaState { + uint32_t regs[16]; + uint32_t pc; + uint32_t sregs[256]; + + CPU_COMMON +}CPUXtensaState ; + +#define cpu_init cpu_xtensa_init +#define cpu_exec cpu_xtensa_exec +#define cpu_gen_code cpu_xtensa_gen_code +#define cpu_signal_handler cpu_xtensa_signal_handler +#define cpu_list xtensa_cpu_list + +CPUXtensaState *cpu_xtensa_init (const char *cpu_model); +void xtensa_translate_init (void ); +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); + +static inline int cpu_mmu_index (CPUState *env) +{ + return 0; +} + +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; +} + +#include "cpu-all.h" + +#endif target-xtensa/exec.h new file +55
-0@@ -0,0 +1,55 @@ +/* +* Copyright (c) 2011, Max Filippov, Motorola Solutions, Inc. +* 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 Motorola Solutions 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" +#include "exec-all.h" + +static inline int cpu_has_work (CPUState *env) +{ + return 1; +} + +static inline int cpu_halted (CPUState *env) +{ + return 0; +} + +#if !defined(CONFIG_USER_ONLY ) +#include "softmmu_exec.h" +#endif + +void raise_exception (int ); + +static inline void cpu_pc_from_tb (CPUState *env,TranslationBlock *tb) +{ + env->pc = tb->pc; +}target-xtensa/helper.c new file +45
-0@@ -0,0 +1,74 @@ +/* +* Copyright (c) 2011, Max Filippov, Motorola Solutions, Inc. +* 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 Motorola Solutions 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 "cpu.h" +#include "exec-all.h" +#include "gdbstub.h" +#include "qemu-common.h" +#include "host-utils.h" +#if !defined(CONFIG_USER_ONLY ) +#include "hw/loader.h" +#endif + +void cpu_reset (CPUXtensaState *env) +{ + env->pc = 0; +} + +CPUXtensaState *cpu_xtensa_init (const char *cpu_model) +{ + static int tcg_inited; + CPUXtensaState *env;
target-xtensa/helper.c line 55
Quoted 10 lines
target-xtensa/helper.c new file +10
-0+ + env = qemu_mallocz(sizeof(*env)); + cpu_exec_init(env); + + if (!tcg_inited) { + tcg_inited = 1; + xtensa_translate_init(); + } + + cpu_reset(env);
CPU init should not call reset anymore, this is done elsewhere nowadays.
Re: [Qemu-devel] [RFC 20/28] target-xtensa: implement windowed registers
In reply to Richard HendersonQuoted 16 lines · Richard Henderson
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Max Filippov
See 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.
Quoted 6 lines
I'm not sure how the register windows work, but maybe you could use the same trick used for Sparc. There is a pool of registers (env->regbase[]), a register window pointer (
env->regwptr,cpu_regwptr) tracks which are the currently accessible ones. The advantage is to avoid copying (not entirely for Sparc due to the window overlap).
Quoted 2 lines
Sparc loses out on some TCG optimizations because of that, although to be fair the most effective of these are still in Aurlien's trees.
Interesting. Which optimizations? What trees? How would you implement the register windows then?
Re: [Qemu-devel] [RFC 20/28] target-xtensa: implement windowed registers
In reply to Blue SwirlQuoted 8 lines · Blue Swirl
Quoted 6 lines · Max Filippov
See 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.
Quoted 6 lines
I'm not sure how the register windows work, but maybe you could use the same trick used for Sparc. There is a pool of registers (env->regbase[]), a register window pointer (
env->regwptr,cpu_regwptr) tracks which are the currently accessible ones. The advantage is to avoid copying (not entirely for Sparc due to the window overlap).
Sparc loses out on some TCG optimizations because of that, although to be fair the most effective of these are still in Aurlien's trees.
That said, I still would not recommend a new port to follow suit.
r~
Re: [Qemu-devel] [RFC 20/28] target-xtensa: implement windowed registers
In reply to Blue SwirlQuoted 5 lines · Blue Swirl
Quoted 2 lines
Sparc loses out on some TCG optimizations because of that, although to be fair the most effective of these are still in Aurlien's trees.
Interesting. Which optimizations? What trees? How would you implement the register windows then?
Constant propagation for one. This one in particular would allow the tcg backend to see full constants, rather than seeing the constant being built up from risc instructions.
git://git.aurel32.net/qemu.git tcg-optimizations
I have previously built on this to streamline the code generated for target load/store operations. We currently always force the address into a register and do the arithmetic on that. If we have the full constant for the address, we can push the parts of that constant into the TLB load etc.
git://repo.or.cz/qemu/rth.git tcg-const-addr-1
As for how to implement the register windows...
I'm not 100% sure. The easiest way is indeed to copy values to and fro a consolidated register file, as Max is doing here. I've also experimented briefly with extending TCG to handle "indirect" registers. Where the register values are consistent as far as the TCG optimizers are concerned, but when it comes time to expand the code, we perform the indirect read, just as you currently expand by hand ahead of time. I never got either solution totally working for sparc.
r~
Re: [Qemu-devel] [RFC 24/28] target-xtensa: implement SIMCALL
In reply to Blue SwirlQuoted 10 lines · Blue Swirl
Quoted 9 lines · Max Filippov
Tensilica 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.
Signed-off-by Max Filippov <[email protected]>---
target-xtensa/helpers.h | 1 +
target-xtensa/op_helper.c | 7 ++
target-xtensa/simcall.c | 157 +++++++++++++++++++++++++++++++++++++++++++++
The existing simcall/semihosting implementations are in arm-semi.c and m68k-semi.c in the top level directory. I think xtensa should do the same (unless somebody wants to propose moving arm and m68k instead...)
Quoted 7 lines
target-xtensa/op_helper.c void HELPER(wsr_lend)(uint32_t v) · line 271
Quoted 3 lines
target-xtensa/op_helper.c +3
-0+void HELPER (simcall )(void ) +{ + simcall(env->regs);Maybe this should be enabled only with -semihosting parameter, like ARM and m68k. Consider for example what could happen if this would be issued from userland when used with an OS.
+1 for consistency with arm/m68k. This applies more generally:
for example if there's any chance there might be a linux-user implementation for xtensa then you want to use the softmmu-semi.h helpers so the memory access will work in both setups.
m68k and ARM also both funnel semihosting through the interrupt/ exception mechanisms; I haven't figured out if there's a good reason for that that would make it worth copying in xtensa :-)
Quoted 4 lines
Quoted 1 line
+ SYS_exit = 1,
I think these names may easily conflict with system defines, please use for example
TARGET_SYS_exitetc.
Renaming's safe, but as it happens arm-semi.c has been using SYS_EXIT &c with no problems, so I don't think it's a big deal either way.
-- PMM
Re: [Qemu-devel] [RFC 19/28] target-xtensa: implement RST2 group (32 bit mul/div/rem)
In reply to Blue SwirlQuoted 9 lines
Quoted 7 lines
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_DIVIE_BY_ZERO_CAUSE);DIVIE?
Oops (: Looks like I overuse ^n.
Thanks.
-- Max
Re: [Qemu-devel] [RFC 12/28] target-xtensa: implement shifts (ST1 and RST1 groups)
In reply to Richard HendersonQuoted 105 lines
Quoted 3 lines
To track immediate values written to SAR? You mean that there may be some performance difference of fixed size shift vs indirect shift and TCG is able to tell them apart?
Well, not really fixed vs indirect, but if you know that the value in the SAR register is in the right range, you can avoid using a 64-bit shift.
For instance,
SSL ar2
SLL ar0, ar1could be implemented with
tcg_gen_sll_i32(ar0, ar1, ar2);
assuming we have enough context.
Let us decompose the SAR register into two parts, storing both the true value, and 32-value.
struct DisasContext {
// Current Stuff
// ...// When valid, holds 32-SAR.
TCGvsar_m32;
boolsar_m32_alloc;
boolsar_m32_valid;
boolsar_5bit;
};At the beginning of the TB:
TCGV_UNUSED_I32(dc->sar_m32);
dc->sar_m32_alloc = false;
dc->sar_m32_valid = false;
dc->sar_5bit = false;static void
gen_set_sra_m32(DisasContext *dc, TCGv val){
if (!dc->sar_m32_alloc) {
dc->sar_m32_alloc = true;
dc->sar_m32 =tcg_temp_local_new_i32(); }
dc->sar_m32_valid = true;/* Clear 5 bit because the SAR value could be 32. */
dc->sar_5bit= false;tcg_gen_movi_i32(cpu_SR[SAR], 32);
tcg_gen_sub_i32(cpu_SR[SAR], cpu_SR[SAR], val);tcg_gen_mov_i32(dc->sar_m32, val);
}static void
gen_set_sra(DisasContext *dc, TCGv val, bool is_5bit){
if (dc->sar_m32_alloc&&dc->sar_m32_valid) {tcg_gen_discard_i32(dc->sar_m32);
}
dc->sar_m32_valid = false;
dc->sar_5bit =is_5bit;tcg_gen_mov_i32(cpu_SR[SAR], val);
}/* SSL */
tcg_gen_andi_i32(tmp, cpu_R[AS], 31);
gen_set_sra_m32(dc, tmp);
break;/* SRL */
tcg_gen_andi_i32(tmp, cpu_R[AS], 31);
gen_set_sra(dc, tmp, true);
break;/* WSR.SAR */
tcg_gen_andi_i32(tmp, cpu_R[AS], 63);
gen_set_sra(dc, tmp, false);
break;/* SSAI */
tcg_gen_movi_i32(tmp, constant);
gen_gen_sra(dc, tmp, true);
break;/* SLL */
if (dc->sar_m32_valid) {tcg_gen_sll_i32(cpu_R[AR], cpu_R[AS], dc->sar_m32); } else {
/* your existing 64-bit shift emulation. */ }
break;/* SRL */
if (dc->sar_5bit) {tcg_gen_srl_i32(cpu_R[AR], cpu_R[AS], cpu_SR[SAR]); } else {
/* your existing 64-bit shift emulation. */ }
Quoted 7 lines
A couple of points: The use of the local temp avoids problems with intervening insns that might generate branch opcodes. For the simplest cases, as with the case at the start of the message, we ought to be able to propagate the values into the TCG shift insn directly.
Does that make sense?
Yes it does. Thanks for the good explanation.
I tried to keep it all as simple as possible to have a working prototype qickly. Now that it works optimizations should be no problem.
Thanks.
-- Max
Re: [Qemu-devel] [RFC 18/28] target-xtensa: implement exceptions
In reply to Richard HendersonQuoted 9 lines
Quoted 9 lines
This is a case where you almost certainly want to check this condition inside QEMU and translate the opcode differently.
See
cpu_get_tb_cpu_state, which sets bits in *flags. These flags can then be checked intb->flagswhile translating. At which point you'd avoid all the conditionalization on the value in PS here incheck_privilegeand merely issue theexception_cause.
Quoted 6 lines
Quoted 1 line
The ARM port is a good example for testing these sorts of bits.
Actually, while the tb flags are useful, privileged instructions are usually checked by testing
mmu_index, since we already have to generate different code for the TB based on which TLB entry we need to access.
Richard,
do I understand it right that if I use tb->flags or mem_index to make decisions during translation, then I must issue exit_tb on instructions that can change state they reflect?
Thanks.
-- Max
Re: [Qemu-devel] [RFC 18/28] target-xtensa: implement exceptions
Quoted 3 lines · Max Filippov
do I understand it right that if I use
tb->flagsormem_indexto make decisions during translation, then I must issueexit_tbon instructions that can change state they reflect?
Yes.
Quite often it's some sort of branch instruction anyway, such as return-from-interrupt changing from kernel mode back to user mode. However, there are some non-branch instructions that may require the TB to end, such as TLB flushes.
r~