target-xtensa: add basic checks to cache opcodes
cover target-xtensa: add basic checks to cache opcodes
Hello,
this series adds basic checks (privilege level, address validity, windowed register validation) to all cache opcodes. This improves emulation quality and allows to debug cache-related issues that happen on real hardware.
Max Filippov (6):
target-xtensa: add RRRI4 opcode format fields
target-xtensa: add basic checks to dcache opcodes
target-xtensa: add basic checks to icache opcodes
target-xtensa: add overridable test_init macro
target-xtensa: allow using core configuration in tests
target-xtensa: add basic tests for cache opcodes
target-xtensa/helper.h | 1 + target-xtensa/op_helper.c | 5 ++ target-xtensa/translate.c | 74 +++++++++++++++++++++++++++++ tests/tcg/xtensa/Makefile | 12 +++-- tests/tcg/xtensa/macros.inc | 6 +++ tests/tcg/xtensa/test_b.S | 2 +- tests/tcg/xtensa/test_bi.S | 2 +- tests/tcg/xtensa/test_boolean.S | 2 +- tests/tcg/xtensa/test_break.S | 2 +- tests/tcg/xtensa/test_bz.S | 2 +- tests/tcg/xtensa/test_cache.S | 97 +++++++++++++++++++++++++++++++++++++++ tests/tcg/xtensa/test_clamps.S | 2 +- tests/tcg/xtensa/test_extui.S | 2 +- tests/tcg/xtensa/test_fail.S | 2 +- tests/tcg/xtensa/test_interrupt.S | 2 +- tests/tcg/xtensa/test_loop.S | 2 +- tests/tcg/xtensa/test_mac16.S | 2 +- tests/tcg/xtensa/test_max.S | 2 +- tests/tcg/xtensa/test_min.S | 2 +- tests/tcg/xtensa/test_mmu.S | 6 +-- tests/tcg/xtensa/test_mul16.S | 2 +- tests/tcg/xtensa/test_mul32.S | 2 +- tests/tcg/xtensa/test_nsa.S | 2 +- tests/tcg/xtensa/test_pipeline.S | 2 +- tests/tcg/xtensa/test_quo.S | 2 +- tests/tcg/xtensa/test_rem.S | 2 +- tests/tcg/xtensa/test_rst0.S | 2 +- tests/tcg/xtensa/test_s32c1i.S | 2 +- tests/tcg/xtensa/test_sar.S | 2 +- tests/tcg/xtensa/test_sext.S | 2 +- tests/tcg/xtensa/test_shift.S | 2 +- tests/tcg/xtensa/test_sr.S | 2 +- tests/tcg/xtensa/test_timer.S | 2 +- tests/tcg/xtensa/test_windowed.S | 2 +- 34 files changed, 221 insertions(+), 34 deletions(-) create mode 100644 tests/tcg/xtensa/test_cache.S
Signature · 1 line
1.8.1.4
PATCH 1/6 target-xtensa: add RRRI4 opcode format fields
This encoding is used by cache instructions.
--- target-xtensa/translate.c | 9 +++++++++ 1 file changed, 9 insertions(+)
target-xtensa/translate.c +9 -0
@@ -922,6 +922,15 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)#define RRRN_S RRR_S#define RRRN_T RRR_T +#define RRI4_R RRR_R +#define RRI4_S RRR_S +#define RRI4_T RRR_T +#ifdef TARGET_WORDS_BIGENDIAN +#define RRI4_IMM4 ((b2) & 0xf) +#else +#define RRI4_IMM4 (((b2) & 0xf0) >> 4) +#endif +#define RRI8_R RRR_R#define RRI8_S RRR_S#define RRI8_T RRR_T
Signature · 1 line
1.8.1.4
PATCH 2/6 target-xtensa: add basic checks to dcache opcodes
In reply to Max FilippovCheck privilege level for privileged instructions (DHI, DHU, DII, DIU, DIWB, DIWBI, DPFL are privileged), memory accessibility for instructions that reference memory (all DH* and DPFL) and windowed register validity for all data cache instructions.
--- target-xtensa/translate.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
target-xtensa/translate.c +38 -0
@@ -2239,6 +2239,20 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)gen_load_store (st32,2 );break ; +#define gen_dcache_hit_test (w, shift) do { \ + TCGv_i32 addr = tcg_temp_new_i32(); \ + TCGv_i32 res = tcg_temp_new_i32(); \ + gen_window_check1(dc, RRI##w##_S); \ + tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \ + RRI##w##_IMM##w << shift); \ + tcg_gen_qemu_ld8u(res, addr, dc->cring); \ + tcg_temp_free(addr); \ + tcg_temp_free(res); \ + } while (0) + +#define gen_dcache_hit_test4 () gen_dcache_hit_test(4, 4) +#define gen_dcache_hit_test8 () gen_dcache_hit_test(8, 2) +case 7 :/*CACHEc*/ if (RRI8_T <8 ) {HAS_OPTION (XTENSA_OPTION_DCACHE );
@@ -2246,49 +2260,69 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)switch (RRI8_T ) {case 0 :/*DPFRc*/ +gen_window_check1 (dc,RRI8_S );break ;case 1 :/*DPFWc*/ +gen_window_check1 (dc,RRI8_S );break ;case 2 :/*DPFROc*/ +gen_window_check1 (dc,RRI8_S );break ;case 3 :/*DPFWOc*/ +gen_window_check1 (dc,RRI8_S );break ;case 4 :/*DHWBc*/ +gen_dcache_hit_test8 ();break ;case 5 :/*DHWBIc*/ +gen_dcache_hit_test8 ();break ;case 6 :/*DHIc*/ +gen_check_privilege (dc); +gen_dcache_hit_test8 ();break ;case 7 :/*DIIc*/ +gen_check_privilege (dc); +gen_window_check1 (dc,RRI8_S );break ;case 8 :/*DCEc*/ switch (OP1 ) {case 0 :/*DPFLl*/ HAS_OPTION (XTENSA_OPTION_DCACHE_INDEX_LOCK ); +gen_check_privilege (dc); +gen_dcache_hit_test4 ();break ;case 2 :/*DHUl*/ HAS_OPTION (XTENSA_OPTION_DCACHE_INDEX_LOCK ); +gen_check_privilege (dc); +gen_dcache_hit_test4 ();break ;case 3 :/*DIUl*/ HAS_OPTION (XTENSA_OPTION_DCACHE_INDEX_LOCK ); +gen_check_privilege (dc); +gen_window_check1 (dc,RRI4_S );break ;case 4 :/*DIWBc*/ HAS_OPTION (XTENSA_OPTION_DCACHE ); +gen_check_privilege (dc); +gen_window_check1 (dc,RRI4_S );break ;case 5 :/*DIWBIc*/ HAS_OPTION (XTENSA_OPTION_DCACHE ); +gen_check_privilege (dc); +gen_window_check1 (dc,RRI4_S );break ;default :/*reserved*/
@@ -2298,6 +2332,10 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) }break ; +#undef gen_dcache_hit_test +#undef gen_dcache_hit_test4 +#undef gen_dcache_hit_test8 +case 12 :/*IPFc*/ HAS_OPTION (XTENSA_OPTION_ICACHE );break ;
Signature · 1 line
1.8.1.4
PATCH 3/6 target-xtensa: add basic checks to icache opcodes
In reply to Max FilippovCheck privilege level for privileged instructions (IHU, III, IIU and IPFL are privileged), memory accessibility for instructions that reference memory (IH* and IPFL) and windowed register validity for all instruction cache instructions.
--- target-xtensa/helper.h | 1 + target-xtensa/op_helper.c | 5 +++++ target-xtensa/translate.c | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+)
target-xtensa/helper.h +1 -0
@@ -25,6 +25,7 @@ DEF_HELPER_2(advance_ccount, void, env, i32) DEF_HELPER_1(check_interrupts, void, env) DEF_HELPER_3(check_atomctl, void, env, i32, i32) +DEF_HELPER_2(itlb_hit_test, void, env, i32) DEF_HELPER_2(wsr_rasid, void, env, i32) DEF_HELPER_FLAGS_3(rtlb0, TCG_CALL_NO_RWG_SE, i32, env, i32, i32)DEF_HELPER_FLAGS_3 (rtlb1,TCG_CALL_NO_RWG_SE , i32, env, i32, i32)
target-xtensa/op_helper.c +5 -0
@@ -414,6 +414,11 @@ void HELPER(check_interrupts)(CPUXtensaState *env)check_interrupts (env); } +void HELPER (itlb_hit_test )(CPUXtensaState *env,uint32_t vaddr) +{ +get_page_addr_code (env, vaddr); +} +/*! * Check vaddr accessibility/cache attributes and raise an exception if * specified by the ATOMCTL SR.
target-xtensa/translate.c +27 -0
@@ -2336,22 +2336,42 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)#undef gen_dcache_hit_test4#undef gen_dcache_hit_test8 +#define gen_icache_hit_test (w, shift) do { \ + TCGv_i32 addr = tcg_temp_new_i32(); \ + gen_window_check1(dc, RRI##w##_S); \ + tcg_gen_movi_i32(cpu_pc, dc->pc); \ + tcg_gen_addi_i32(addr, cpu_R[RRI##w##_S], \ + RRI##w##_IMM##w << shift); \ + gen_helper_itlb_hit_test(cpu_env, addr); \ + tcg_temp_free(addr); \ + } while (0) + +#define gen_icache_hit_test4 () gen_icache_hit_test(4, 4) +#define gen_icache_hit_test8 () gen_icache_hit_test(8, 2) +case 12 :/*IPFc*/ HAS_OPTION (XTENSA_OPTION_ICACHE ); +gen_window_check1 (dc,RRI8_S );break ;case 13 :/*ICEc*/ switch (OP1 ) {case 0 :/*IPFLl*/ HAS_OPTION (XTENSA_OPTION_ICACHE_INDEX_LOCK ); +gen_check_privilege (dc); +gen_icache_hit_test4 ();break ;case 2 :/*IHUl*/ HAS_OPTION (XTENSA_OPTION_ICACHE_INDEX_LOCK ); +gen_check_privilege (dc); +gen_icache_hit_test4 ();break ;case 3 :/*IIUl*/ HAS_OPTION (XTENSA_OPTION_ICACHE_INDEX_LOCK ); +gen_check_privilege (dc); +gen_window_check1 (dc,RRI4_S );break ;default :/*reserved*/
@@ -2362,10 +2382,13 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc)case 14 :/*IHIc*/ HAS_OPTION (XTENSA_OPTION_ICACHE ); +gen_icache_hit_test8 ();break ;case 15 :/*IIIc*/ HAS_OPTION (XTENSA_OPTION_ICACHE ); +gen_check_privilege (dc); +gen_window_check1 (dc,RRI8_S );break ;default :/*reserved*/
@@ -2374,6 +2397,10 @@ static void disas_xtensa_insn(CPUXtensaState *env, DisasContext *dc) }break ; +#undef gen_icache_hit_test +#undef gen_icache_hit_test4 +#undef gen_icache_hit_test8 +case 9 :/*L16SI*/ gen_load_store (ld16s,1 );break ;
Signature · 1 line
1.8.1.4
PATCH 4/6 target-xtensa: add overridable test_init macro
In reply to Max FilippovSome test suites, like MMU, need per-test initialization. Don't make them redefine test macro, add test_init for that purpose.
--- tests/tcg/xtensa/macros.inc | 4 ++++ tests/tcg/xtensa/test_mmu.S | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-)
tests/tcg/xtensa/macros.inc +4 -0
@@ -43,8 +43,12 @@ main: simcall .endm +.macro test_init +.endm + .macro test name //print test_\name + test_init test_\name: .global test_\name .endm
tests/tcg/xtensa/test_mmu.S +2 -2
@@ -2,9 +2,9 @@ test_suite mmu -.purgem test +.purgem test_init -.macro test name +.macro test_init movi a2, 0x00000004 idtlb a2 movi a2, 0x00100004
Signature · 1 line
1.8.1.4
PATCH 5/6 target-xtensa: allow using core configuration in tests
In reply to Max FilippovAdd path to the core configuration directory to test build command and replace .include asm directive with #include to enable preprocessing.
--- tests/tcg/xtensa/Makefile | 11 +++++++---- tests/tcg/xtensa/macros.inc | 2 ++ tests/tcg/xtensa/test_b.S | 2 +- tests/tcg/xtensa/test_bi.S | 2 +- tests/tcg/xtensa/test_boolean.S | 2 +- tests/tcg/xtensa/test_break.S | 2 +- tests/tcg/xtensa/test_bz.S | 2 +- tests/tcg/xtensa/test_clamps.S | 2 +- tests/tcg/xtensa/test_extui.S | 2 +- tests/tcg/xtensa/test_fail.S | 2 +- tests/tcg/xtensa/test_interrupt.S | 2 +- tests/tcg/xtensa/test_loop.S | 2 +- tests/tcg/xtensa/test_mac16.S | 2 +- tests/tcg/xtensa/test_max.S | 2 +- tests/tcg/xtensa/test_min.S | 2 +- tests/tcg/xtensa/test_mmu.S | 2 +- tests/tcg/xtensa/test_mul16.S | 2 +- tests/tcg/xtensa/test_mul32.S | 2 +- tests/tcg/xtensa/test_nsa.S | 2 +- tests/tcg/xtensa/test_pipeline.S | 2 +- tests/tcg/xtensa/test_quo.S | 2 +- tests/tcg/xtensa/test_rem.S | 2 +- tests/tcg/xtensa/test_rst0.S | 2 +- tests/tcg/xtensa/test_s32c1i.S | 2 +- tests/tcg/xtensa/test_sar.S | 2 +- tests/tcg/xtensa/test_sext.S | 2 +- tests/tcg/xtensa/test_shift.S | 2 +- tests/tcg/xtensa/test_sr.S | 2 +- tests/tcg/xtensa/test_timer.S | 2 +- tests/tcg/xtensa/test_windowed.S | 2 +- 30 files changed, 37 insertions(+), 32 deletions(-)
tests/tcg/xtensa/Makefile +7 -4
@@ -1,10 +1,11 @@ -include ../../../config-host.mak -CROSS=xtensa-dc232b-elf- +CORE=dc232b +CROSS=xtensa-$(CORE)-elf- ifndef XT SIM = ../../../xtensa-softmmu/qemu-system-xtensa -SIMFLAGS = -M sim -cpu dc232b -nographic -semihosting $(EXTFLAGS) -kernel +SIMFLAGS = -M sim -cpu $(CORE) -nographic -semihosting $(EXTFLAGS) -kernel SIMDEBUG = -s -S else SIM = xt-run
@@ -17,6 +18,8 @@ AS = $(CROSS)gcc -x assembler-with-cpp LD = $(CROSS)ld XTENSA_SRC_PATH = $(SRC_PATH)/tests/tcg/xtensa +INCLUDE_DIRS = $(XTENSA_SRC_PATH) $(SRC_PATH)/target-xtensa/core-$(CORE) +XTENSA_INC = $(addprefix -I,$(INCLUDE_DIRS)) LDFLAGS = -T$(XTENSA_SRC_PATH)/linker.ld
@@ -56,10 +59,10 @@ TESTCASES += test_windowed.tst all: build %.o: $(XTENSA_SRC_PATH)/%.c - $(CC) -I$(XTENSA_SRC_PATH) $(CFLAGS) -c $< -o $@ + $(CC) $(XTENSA_INC) $(CFLAGS) -c $< -o $@ %.o: $(XTENSA_SRC_PATH)/%.S - $(AS) -Wa,-I,$(XTENSA_SRC_PATH) $(ASFLAGS) -c $< -o $@ + $(CC) $(XTENSA_INC) $(ASFLAGS) -c $< -o $@ %.tst: %.o $(XTENSA_SRC_PATH)/macros.inc $(CRT) Makefile $(LD) $(LDFLAGS) $(NOSTDFLAGS) $(CRT) $< -o $@
tests/tcg/xtensa/macros.inc +2 -0
@@ -1,3 +1,5 @@ +#include "core-isa.h" + .macro test_suite name .data status: .word result
tests/tcg/xtensa/test_b.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite b
tests/tcg/xtensa/test_bi.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite bi
tests/tcg/xtensa/test_boolean.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite boolean
tests/tcg/xtensa/test_break.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" #define debug_level 6 #define debug_vector level6
tests/tcg/xtensa/test_bz.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite bz
tests/tcg/xtensa/test_clamps.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite clamps
tests/tcg/xtensa/test_extui.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite extui
tests/tcg/xtensa/test_fail.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite fail
tests/tcg/xtensa/test_interrupt.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite interrupt
tests/tcg/xtensa/test_loop.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite loop
tests/tcg/xtensa/test_mac16.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite mac16
tests/tcg/xtensa/test_max.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite max
tests/tcg/xtensa/test_min.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite min
tests/tcg/xtensa/test_mmu.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite mmu
tests/tcg/xtensa/test_mul16.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite mul16
tests/tcg/xtensa/test_mul32.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite mul32
tests/tcg/xtensa/test_nsa.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite nsa
tests/tcg/xtensa/test_pipeline.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" .purgem test .macro test name
tests/tcg/xtensa/test_quo.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite quo
tests/tcg/xtensa/test_rem.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite rem
tests/tcg/xtensa/test_rst0.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite rst0
tests/tcg/xtensa/test_s32c1i.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite s32c1i
tests/tcg/xtensa/test_sar.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite sar
tests/tcg/xtensa/test_sext.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite sext
tests/tcg/xtensa/test_shift.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite shift
tests/tcg/xtensa/test_sr.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite sr
tests/tcg/xtensa/test_timer.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite timer
tests/tcg/xtensa/test_windowed.S +1 -1
@@ -1,4 +1,4 @@ -.include "macros.inc" +#include "macros.inc" test_suite windowed
Signature · 1 line
1.8.1.4
PATCH 6/6 target-xtensa: add basic tests for cache opcodes
In reply to Max FilippovTest that non-locking prefetch operations don't cause exceptions on missing TLB and that other 'hit' cache operations do.
--- tests/tcg/xtensa/Makefile | 1 + tests/tcg/xtensa/test_cache.S | 97 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 tests/tcg/xtensa/test_cache.S
tests/tcg/xtensa/Makefile +1 -0
@@ -30,6 +30,7 @@ TESTCASES += test_bi.tst #TESTCASES += test_boolean.tst TESTCASES += test_break.tst TESTCASES += test_bz.tst +TESTCASES += test_cache.tst TESTCASES += test_clamps.tst TESTCASES += test_extui.tst TESTCASES += test_fail.tst
tests/tcg/xtensa/test_cache.S new file +97 -0
97 lines not on this page · raw message
Signature · 1 line
1.8.1.4