target/hexagon: fix packet execution and fault handling
v2 cover target/hexagon: fix packet execution and fault handling
This series is intended for QEMU 11.2.
Changes in v2:
Removed v1 patches 1 (C4 predicate reads) and 7 (packet lookahead). Brian is carrying them here:
https://patchew.org/QEMU/[email protected]/
Apply those fixes before running the full packet regression suite.
Patches 3, 7, 9-12: Use TCG instead of added runtime helpers to reduce memory-check overhead.
Marco Liebel (13):
target/hexagon: allow writes to V85 USR coprocessor fields target/hexagon: suppress LR writes from a losing call target/hexagon: reject HMX operands outside VTCM target/hexagon: commit coprocessor results before context changes target/hexagon: distinguish packet-page instruction TLB misses target/hexagon: report the faulting memory slot target/hexagon: retain both scalar packet fault addresses target/hexagon: preserve inactive BADVA registers target/hexagon: probe scalar packet memory in slot priority order target/hexagon: prioritize packet alignment in the fault path target/hexagon: validate both stores before packet commit target/hexagon: probe VMEMU upper transactions before lower ones tests/functional/hexagon: add packet regression tests
hw/hexagon/hex-subsys.c | 4 ++ include/hw/hexagon/hexagon.h | 2 + target/hexagon/cpu.c | 76 +++++++++++++++++++-- target/hexagon/cpu.h | 12 ++++ target/hexagon/gen_tcg_func_table.py | 6 ++ target/hexagon/gen_tcg_funcs.py | 38 +++++++++++ target/hexagon/genptr.c | 55 ++++++++++++++- target/hexagon/genptr.h | 4 ++ target/hexagon/helper.h | 5 +- target/hexagon/hex_common.py | 22 ++++++ target/hexagon/internal.h | 5 ++ target/hexagon/op_helper.c | 72 ++++++++++++++++++-- target/hexagon/reg_fields_def.h.inc | 2 + target/hexagon/translate.c | 85 +++++++++++++++++++++--- target/hexagon/translate.h | 11 ++- tests/functional/hexagon/meson.build | 2 + tests/functional/hexagon/test_packets.py | 47 +++++++++++++ tests/tcg/hexagon/meson.build | 2 + tests/tcg/hexagon/packet_user.c | 61 +++++++++++++++++ 19 files changed, 485 insertions(+), 26 deletions(-) create mode 100644 tests/functional/hexagon/test_packets.py create mode 100644 tests/tcg/hexagon/packet_user.c
Signature · 1 line
2.43.0
PATCH v2 1/13 target/hexagon: allow writes to V85 USR coprocessor fields
NPC and FPCOPROC are writable on V85. Remove them from the immutable mask for that revision, without changing older CPU models.
--- target/hexagon/genptr.c | 6 +++++ target/hexagon/reg_fields_def.h.inc | 2 ++ tests/tcg/hexagon/meson.build | 2 ++ tests/tcg/hexagon/packet_user.c | 35 +++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 tests/tcg/hexagon/packet_user.c
target/hexagon/genptr.c +6 -0
@@ -562,6 +562,12 @@ static inline void gen_write_ctrl_reg(DisasContext *ctx, int reg_num,/* USR.FPSAT is reserved before v79 */ reg_mask &= ~fGET_REG_FIELD_MASK (USR_FPSAT ); } +if (reg_num ==HEX_REG_USR && + ctx->hex_def->hex_version >=HEX_VER_V85 ) { +/* V85 permits writes to NPC and FPCOPROC. */ + reg_mask &= ~(fGET_REG_FIELD_MASK (USR_NPC ) | +fGET_REG_FIELD_MASK (USR_FPCOPROC )); + }gen_masked_reg_write (val, hex_gpr[reg_num], reg_mask);tcg_gen_mov_tl (get_result_gpr (ctx, reg_num), val);if (reg_num ==HEX_REG_QEMU_PKT_CNT ) {
target/hexagon/reg_fields_def.h.inc +2 -0
@@ -29,10 +29,12 @@ DEF_REG_FIELD(USR_FPDBZF, 2, 1) DEF_REG_FIELD(USR_FPOVFF, 3, 1) DEF_REG_FIELD(USR_FPUNFF, 4, 1) DEF_REG_FIELD(USR_FPINPF, 5, 1) +DEF_REG_FIELD(USR_NPC, 6, 1) DEF_REG_FIELD(USR_LPCFG, 8, 2) DEF_REG_FIELD(USR_FPDAZ, 17, 1) +DEF_REG_FIELD(USR_FPCOPROC, 20, 2) DEF_REG_FIELD(USR_FPRND, 22, 2) DEF_REG_FIELD(USR_FPSAT, 24, 1)
tests/tcg/hexagon/meson.build +2 -0
@@ -96,6 +96,8 @@ tests += { 'misc.c': {'cflags': [cflags, '-mv71', '-O2']}, 'multiple-writes.c': {'cflags': [cflags, '-mhvx']}, 'overflow.c': {'cflags': cflags, 'exe_name': 'hex-overflow'}, + 'packet_user.c': {'cflags': [cflags, '-O2'], + 'qemu_args': ['-cpu', 'v85']}, 'preg_alias.c': {'cflags': cflags}, 'dual_stores.c': {'cflags': cflags}, 'framekey.c': {'cflags': cflags},
tests/tcg/hexagon/packet_user.c new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. +* SPDX-License-Identifier: BSD-3-Clause-Clear +*/ + +#include <stdio.h> +#include <stdint.h> + +static int err; + +#include "hex_test.h" + +static void test_usr_mask (void ) +{ +unsigned old, value; + + asmvolatile ( +"%[old] = usr\n" +"r0 = #-1\n" +"usr = r0\n" +"%[value] = usr\n" +"usr = %[old]\n" + : [old]"=&r" (old), [value]"=&r" (value) + : :"r0" + ); +/* V85 USR writable bits. */ +check32 (value,0x3fffff7f ); +} + +int main (void ) +{ +test_usr_mask (); +puts (err ?"FAIL" :"PASS" ); +return err !=0 ; +}
Signature · 1 line
2.43.0
PATCH v2 2/13 target/hexagon: suppress LR writes from a losing call
In reply to Marco LiebelA call after a taken branch must not update LR. Guard direct and indirect calls with the packet branch state, and preserve LR when a multi-branch packet uses deferred register commit.
--- target/hexagon/genptr.c | 14 +++++++++++--- target/hexagon/translate.c | 4 ++++ tests/tcg/hexagon/packet_user.c | 26 ++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-)
target/hexagon/genptr.c +11 -3
@@ -1058,27 +1058,35 @@ static void gen_jumpr(DisasContext *ctx, TCGv new_pc)static void gen_call (DisasContext *ctx,int pc_off) {TCGv lr =get_result_gpr (ctx,HEX_REG_LR ); +TCGLabel *skip =gen_new_label (); +if (ctx->pkt.pkt_has_multi_cof) { +tcg_gen_brcondi_tl (TCG_COND_NE , ctx->branch_taken,0 , skip); + }tcg_gen_movi_tl (lr, ctx->next_PC);gen_write_new_pc_pcrel (ctx, pc_off,TCG_COND_ALWAYS ,NULL ); +gen_set_label (skip); }static void gen_callr (DisasContext *ctx,TCGv new_pc) {TCGv lr =get_result_gpr (ctx,HEX_REG_LR ); +TCGLabel *skip =gen_new_label (); new_pc =gen_unalias_gpr_src (new_pc, lr); +if (ctx->pkt.pkt_has_multi_cof) { +tcg_gen_brcondi_tl (TCG_COND_NE , ctx->branch_taken,0 , skip); + }tcg_gen_movi_tl (lr, ctx->next_PC);gen_write_new_pc_addr (ctx, new_pc,TCG_COND_ALWAYS ,NULL ); +gen_set_label (skip); }static void gen_cond_call (DisasContext *ctx,TCGv pred,TCGCond cond,int pc_off) { -TCGv lr =get_result_gpr (ctx,HEX_REG_LR );TCGLabel *skip =gen_new_label (); -gen_write_new_pc_pcrel (ctx, pc_off, cond, pred);tcg_gen_brcondi_tl (cond, pred,1 , skip); -tcg_gen_movi_tl (lr, ctx->next_PC); +gen_call (ctx, pc_off);gen_set_label (skip); }
target/hexagon/translate.c +4 -0
@@ -495,6 +495,10 @@ static void mark_implicit_reg_write(DisasContext *ctx, int attrib, int rnum)if (GET_ATTRIB (opcode, attrib)) {bool is_predicated =GET_ATTRIB (opcode,A_CONDEXEC ); +if (rnum ==HEX_REG_LR && ctx->pkt.pkt_has_multi_cof) { + is_predicated = true; + } +/* LC0/LC1 is conditionally written by endloop instructions */ if ((rnum == HEX_REG_LC0 || rnum == HEX_REG_LC1) && (opcode == J2_endloop0 ||
tests/tcg/hexagon/packet_user.c +26 -0
@@ -27,9 +27,35 @@ static void test_usr_mask(void)check32 (value,0x3fffff7f ); } +static void test_call_priority (void ) +{ +unsigned lr; + + asmvolatile ( +"r12 = r31\n" +"r31 = ##0x12345678\n" +"r0 = #0\n" +"p0 = cmp.eq(r0,r0)\n" +"{\n" +" if (p0) jump 1f\n" +" call 2f\n" +"}\n" +"2:\n" +"r31 = #0\n" +"1:\n" +"%[lr] = r31\n" +"r31 = r12\n" + : [lr]"=&r" (lr) + : :"r0" ,"r12" ,"r31" ,"p0" + ); +/* Losing call preserves LR. */ +check32 (lr,0x12345678 ); +} +int main (void ) {test_usr_mask (); +test_call_priority ();puts (err ?"FAIL" :"PASS" );return err !=0 ; }
Signature · 1 line
2.43.0
PATCH v2 3/13 target/hexagon: reject HMX operands outside VTCM
In reply to Marco LiebelCheck activation and weight addresses against the machine VTCM range before executing packet instructions. An invalid operand raises the precise coprocessor VMEM address error and prevents packet commit. HMX arithmetic remains unimplemented.
--- hw/hexagon/hex-subsys.c | 4 ++++ include/hw/hexagon/hexagon.h | 2 ++ target/hexagon/cpu.c | 2 ++ target/hexagon/cpu.h | 2 ++ target/hexagon/translate.c | 26 ++++++++++++++++++++++++++ target/hexagon/translate.h | 4 ++++ 6 files changed, 40 insertions(+)
hw/hexagon/hex-subsys.c +4 -0
@@ -181,6 +181,8 @@ void hex_subsys_create(HexagonCommonMachineState *hms,sizeof (m_cfg->cfgtable), m_cfg->cfgbase, &address_space_memory); + hms->vtcm_base = (uint64_t )m_cfg->cfgtable.vtcm_base <<16 ; + hms->vtcm_size = (uint64_t )m_cfg->cfgtable.vtcm_size_kb <<10 ;if (m_cfg->cfgtable.vtcm_size_kb >0 ) { memory_region_init_ram(&hms->vtcm, NULL, "vtcm.ram", m_cfg->cfgtable.vtcm_size_kb * 1024,
@@ -204,6 +206,8 @@ void hex_subsys_add_cpu(HexagonCommonMachineState *hms, DeviceState *cpu)Object *hmx;object_property_add_child (OBJECT (hms->cluster),"cpu[*]" ,OBJECT (cpu)); +qdev_prop_set_uint64 (cpu,"vtcm-base" , hms->vtcm_base); +qdev_prop_set_uint64 (cpu,"vtcm-size" , hms->vtcm_size);object_property_set_link (OBJECT (cpu),"global-regs" ,OBJECT (hms->glob_regs), &error_fatal); object_property_set_link(OBJECT(cpu), "tlb", OBJECT(hms->tlb),
include/hw/hexagon/hexagon.h +2 -0
@@ -187,6 +187,8 @@ struct HexagonCommonMachineState {MemoryRegion cfgtable_rom;uint32_t cfgtable_data[HEXAGON_CFGSPACE_ENTRIES ];MemoryRegion vtcm; +uint64_t vtcm_base; +uint64_t vtcm_size;DeviceState *cluster;DeviceState *l2vic;DeviceState *qtimer;
target/hexagon/cpu.c +2 -0
@@ -69,6 +69,8 @@ static const Property hexagon_cpu_properties[] = {DEFINE_PROP_LINK ("tlb" , HexagonCPU, tlb,TYPE_HEXAGON_TLB , HexagonTLBState *),DEFINE_PROP_UINT32 ("exec-start-addr" , HexagonCPU, boot_addr,0xffffffff ), +DEFINE_PROP_UINT64 ("vtcm-base" , HexagonCPU, vtcm_base,0 ), +DEFINE_PROP_UINT64 ("vtcm-size" , HexagonCPU, vtcm_size,0 ),DEFINE_PROP_LINK ("l2vic" , HexagonCPU, l2vic, TYPE_HEX_L2VIC_INTERFACE, HexL2VicInterface *), DEFINE_PROP_LINK("global-regs", HexagonCPU, globalregs,
target/hexagon/cpu.h +2 -0
@@ -248,6 +248,8 @@ struct ArchCPU {HexagonHMXContextState *hmx_ctx;HexagonTLBState *tlb;uint32_t boot_addr; +uint64_t vtcm_base; +uint64_t vtcm_size;HexagonGlobalRegState *globalregs;uint32_t htid;HexL2VicInterface *l2vic;
target/hexagon/translate.c +26 -0
@@ -149,6 +149,20 @@ void gen_precise_exception(int cause, uint32_t PC) tcg_constant_i32(PC)); } +#ifndef CONFIG_USER_ONLY +static void gen_hmx_check_address (DisasContext *ctx,TCGv_i32 address) +{ +TCGv_i64 offset =tcg_temp_new_i64 (); +TCGLabel *valid =gen_new_label (); + +tcg_gen_extu_i32_i64 (offset, address); +tcg_gen_subi_i64 (offset, offset, ctx->vtcm_base); +tcg_gen_brcondi_i64 (TCG_COND_LTU , offset, ctx->vtcm_size, valid); +gen_precise_exception (HEX_CAUSE_COPROC_LDST , ctx->pkt.pc); +gen_set_label (valid); +} +#endif +static void gen_exec_counters (DisasContext *ctx) { tcg_gen_addi_tl(hex_gpr[HEX_REG_QEMU_PKT_CNT],
@@ -946,6 +960,16 @@ static void gen_start_packet(DisasContext *ctx)gen_precise_exception (HEX_CAUSE_NO_COPROC2_ENABLE , ctx->pkt.pc); ctx->hmx_check_emitted = true; } +if (ctx->pkt.pkt_has_hmx) { +for (i =0 ; i < ctx->pkt.num_insns; i++) { +Insn *insn = &ctx->pkt.insn[i]; +if (GET_ATTRIB (insn->opcode,A_HMX ) && + (GET_ATTRIB (insn->opcode,A_PAIR_1OF2 ) || +GET_ATTRIB (insn->opcode,A_PAIR_2OF2 ))) { +gen_hmx_check_address (ctx, hex_gpr[insn->regno[0 ]]); + } + } + }#endif }
@@ -1583,6 +1607,8 @@ static void hexagon_tr_init_disas_context(DisasContextBase *dcbase, ctx->hlx_coproc_enabled = hex_cpu->hlx !=NULL && hex_cpu->hlx->contexts_bitmap !=0 ; ctx->hlx_check_emitted = false; + ctx->vtcm_base = hex_cpu->vtcm_base; + ctx->vtcm_size = hex_cpu->vtcm_size;#endif ctx->branch_cond =TCG_COND_NEVER ; ctx->is_tight_loop =FIELD_EX32 (hex_flags,TB_FLAGS ,IS_TIGHT_LOOP );
target/hexagon/translate.h +4 -0
@@ -114,6 +114,10 @@ typedef struct DisasContext {DECLARE_BITMAP (lregs_updated_tmp,NUM_LREGS );bool hmx_coproc_enabled;bool hmx_check_emitted; +#ifndef CONFIG_USER_ONLY +uint64_t vtcm_base; +uint64_t vtcm_size; +#endif } DisasContext;bool is_gather_store_insn (DisasContext *ctx);
Signature · 1 line
2.43.0
PATCH v2 4/13 target/hexagon: commit coprocessor results before context changes
In reply to Marco LiebelA CCR write can detach the HLX context. Commit packet results to the old context before applying system register writes, so clearing XE3 does not abort the emulator.
--- target/hexagon/translate.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
target/hexagon/translate.c +4 -1
@@ -1482,7 +1482,6 @@ static void gen_commit_packet(DisasContext *ctx)gen_reg_writes (ctx);#ifndef CONFIG_USER_ONLY gen_greg_writes (ctx); -gen_sreg_writes (ctx);#endif gen_pred_writes (ctx);if (ctx->pkt.pkt_has_hvx) {
@@ -1494,6 +1493,10 @@ static void gen_commit_packet(DisasContext *ctx)if (ctx->pkt.pkt_has_hmx) {gen_commit_hmx (ctx); } +#ifndef CONFIG_USER_ONLY +/* Context changes must follow writes to the packet's old context. */ +gen_sreg_writes (ctx); +#endif update_exec_counters (ctx);if (ctx->pkt.vhist_insn !=NULL ) {
Signature · 1 line
2.43.0
PATCH v2 5/13 target/hexagon: distinguish packet-page instruction TLB misses
In reply to Marco LiebelA page-aligned fault address does not imply a straddling packet. Compare its page with the packet PC page to select cause 0x60 or 0x61.
--- target/hexagon/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/hexagon/cpu.c +2 -1
@@ -786,7 +786,8 @@ static void raise_tlbmiss_exception(CPUState *cs, uint32_t VA, int slot,switch (access_type) {case MMU_INST_FETCH : cs->exception_index =HEX_EVENT_TLB_MISS_X ; -if ((VA & ~TARGET_PAGE_MASK ) ==0 ) { +if ((VA &TARGET_PAGE_MASK ) != + (env->gpr[HEX_REG_PC ] &TARGET_PAGE_MASK )) { env->cause_code =HEX_CAUSE_TLBMISSX_CAUSE_NEXTPAGE ; }else { env->cause_code =HEX_CAUSE_TLBMISSX_CAUSE_NORMAL ;
Signature · 1 line
2.43.0
PATCH v2 6/13 target/hexagon: report the faulting memory slot
In reply to Marco LiebelTrack the slot during memory execution and store probes. Use it for TLB and alignment faults so a slot 1 fault selects BADVA1 and BVS.
--- target/hexagon/cpu.c | 4 ++-- target/hexagon/cpu.h | 2 ++ target/hexagon/op_helper.c | 6 ++++++ target/hexagon/translate.c | 18 ++++++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-)
target/hexagon/cpu.c +2 -2
@@ -836,7 +836,7 @@ static bool hexagon_tlb_fill(CPUState *cs, vaddr address, int size, uintptr_t retaddr) {CPUHexagonState *env =cpu_env (cs); -int slot =0 ; +int slot = access_type ==MMU_INST_FETCH ?0 : env->mem_slot;hwaddr phys;int prot =0 ;uint64_t page_size =0 ;
@@ -918,7 +918,7 @@ void hexagon_cpu_do_unaligned_access(CPUState *cs, vaddr addr, {CPUHexagonState *env =cpu_env (cs); -raise_misaligned_exception (cs, addr,0 , access_type); +raise_misaligned_exception (cs, addr, env->mem_slot, access_type);do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], retaddr); }
target/hexagon/cpu.h +2 -0
@@ -165,6 +165,8 @@ typedef struct CPUArchState {#ifndef CONFIG_USER_ONLY /* Some system registers are per thread and some are global. */ uint32_t t_sreg[NUM_SREGS ]; +/* Slot of the memory operation currently being executed or probed. */ +uint32_t mem_slot;uint32_t greg[NUM_GREGS ];
target/hexagon/op_helper.c +6 -0
@@ -441,6 +441,9 @@ static void probe_store(CPUHexagonState *env, int slot, int mmu_idx, bool is_predicated, uintptr_t retaddr) {if (!is_predicated || !(env->slot_cancelled & (1 << slot))) { +#ifndef CONFIG_USER_ONLY + env->mem_slot = slot; +#endif uint32_t width = env->mem_log_stores[slot].width;target_ulong va = env->mem_log_stores[slot].va;probe_write (env, va, width, mmu_idx, retaddr);
@@ -455,6 +458,9 @@ void HELPER(probe_noshuf_load)(CPUHexagonState *env, target_ulong va, int size, int mmu_idx) {uintptr_t retaddr =GETPC (); +#ifndef CONFIG_USER_ONLY + env->mem_slot =0 ; +#endif probe_read (env, va, size, mmu_idx, retaddr); }
target/hexagon/translate.c +18 -0
@@ -1019,6 +1019,13 @@ static void gen_insn(DisasContext *ctx) {uint16_t opcode = ctx->insn->opcode; +#ifndef CONFIG_USER_ONLY +if (GET_ATTRIB (opcode,A_LOAD ) ||GET_ATTRIB (opcode,A_STORE )) { +tcg_gen_st_i32 (tcg_constant_i32 (ctx->insn->slot), tcg_env, + offsetof(CPUHexagonState , mem_slot)); + } +#endif +if (GET_ATTRIB (opcode,A_RELEASE ) ||GET_ATTRIB (opcode,A_CVI_SCATTER_RELEASE )) {tcg_gen_mb (TCG_MO_ALL |TCG_BAR_STRL );
@@ -1175,6 +1182,10 @@ void process_store(DisasContext *ctx, int slot_num) } {TCGv address =tcg_temp_new (); +#ifndef CONFIG_USER_ONLY +tcg_gen_st_i32 (tcg_constant_i32 (slot_num), tcg_env, + offsetof(CPUHexagonState , mem_slot)); +#endif tcg_gen_mov_tl (address, hex_store_addr[slot_num]);/*
@@ -1221,6 +1232,13 @@ void process_store(DisasContext *ctx, int slot_num)if (is_predicated) {gen_set_label (label_end); } +#ifndef CONFIG_USER_ONLY +/* An early mem_noshuf store is followed by the slot 0 load. */ +if (ctx->pre_commit) { +tcg_gen_st_i32 (tcg_constant_i32 (ctx->insn->slot), tcg_env, + offsetof(CPUHexagonState , mem_slot)); + } +#endif }static void process_store_log (DisasContext *ctx)
Signature · 1 line
2.43.0
PATCH v2 7/13 target/hexagon: retain both scalar packet fault addresses
In reply to Marco LiebelGenerate address-only code from scalar memory semantics. Record both active slots before memory execution, without loads, stores, or pointer updates. Use the recorded addresses and validity bits on a data fault.
--- target/hexagon/cpu.c | 16 ++++++++++++ target/hexagon/cpu.h | 2 ++ target/hexagon/gen_tcg_func_table.py | 6 +++++ target/hexagon/gen_tcg_funcs.py | 38 ++++++++++++++++++++++++++++ target/hexagon/genptr.c | 17 +++++++++++++ target/hexagon/genptr.h | 4 +++ target/hexagon/hex_common.py | 22 ++++++++++++++++ target/hexagon/translate.c | 16 ++++++++++++ target/hexagon/translate.h | 1 + 9 files changed, 122 insertions(+)
target/hexagon/cpu.c +16 -0
@@ -759,6 +759,22 @@ static void set_badva_regs(CPUHexagonState *env, uint32_t VA, int slot, { env->t_sreg[HEX_SREG_BADVA ] =VA ; +if (access_type !=MMU_INST_FETCH && env->mem_access_valid) { +uint32_t valid = env->mem_access_valid | (1U << slot); +for (int i =0 ; i <2 ; i++) { +if (valid & (1U << i)) { + env->t_sreg[HEX_SREG_BADVA0 + i] = + i == slot ?VA : env->mem_access_va[i]; + }else { + env->t_sreg[HEX_SREG_BADVA0 + i] =INVALID_BADVA ; + } + } +SET_SSR_FIELD (env,SSR_V0 , valid &1 ); +SET_SSR_FIELD (env,SSR_V1 , (valid >>1 ) &1 ); +SET_SSR_FIELD (env,SSR_BVS , slot); +return ; + } +if (access_type ==MMU_INST_FETCH || slot ==0 ) { env->t_sreg[HEX_SREG_BADVA0 ] =VA ; env->t_sreg[HEX_SREG_BADVA1 ] =INVALID_BADVA ;
target/hexagon/cpu.h +2 -0
@@ -167,6 +167,8 @@ typedef struct CPUArchState {uint32_t t_sreg[NUM_SREGS ];/* Slot of the memory operation currently being executed or probed. */ uint32_t mem_slot; +uint32_t mem_access_valid; +uint32_t mem_access_va[2 ];uint32_t greg[NUM_GREGS ];
target/hexagon/gen_tcg_func_table.py +6 -0
@@ -22,6 +22,12 @@ def main(): f.write(f" [{tag}] = generate_{tag},\n") f.write("};\n\n") + f.write("#ifndef CONFIG_USER_ONLY\n") + f.write("const SemanticInsn opcode_address[XX_LAST_OPCODE] = {\n") + for tag in hex_common.tags: + if not hex_common.tag_ignore(tag) and hex_common.packet_memory_info(tag): + f.write(f" [{tag}] = address_{tag},\n") + f.write("};\n#endif\n\n") f.write("#endif /* HEXAGON_FUNC_TABLE_H */\n")
target/hexagon/gen_tcg_funcs.py +38 -0
@@ -154,11 +154,49 @@ def gen_tcg_func(f, tag, regs, imms): f.write("}\n\n") +def gen_memory_address(f, tag, regs, imms): + info = hex_common.packet_memory_info(tag) + if info is None: + return + ea, pred, width = info + for reg in ("SP", "FP", "GP", "LR"): + ea = ea.replace(f"fREAD_{reg}()", f"hex_gpr[HEX_REG_{reg}]") + f.write("#ifndef CONFIG_USER_ONLY\n") + f.write(f"static void address_{tag}(DisasContext *ctx)\n{{\n") + f.write(" Insn *insn G_GNUC_UNUSED = ctx->insn;\n") + f.write(" TCGv EA = tcg_temp_new();\n") + for i, (regtype, regid) in enumerate(regs): + name = f"{regtype}{regid}V" + if regtype == "R" and re.search(rf"\b{name}\b", ea): + f.write(f" TCGv {name} = hex_gpr[insn->regno[{i}]];\n") + for immlett, bits, shift in imms: + name = hex_common.imm_name(immlett) + if re.search(rf"\b{name}\b", ea): + i = 1 if immlett.isupper() else 0 + f.write(f" int {name} = insn->immed[{i}];\n") + if pred: + name = pred.group(3) + i = next(i for i, (t, r) in enumerate(regs) + if f"{t}{r}" == name[:-1]) + source = "ctx->new_pred_value" if pred.group(1) == "NEW" else "hex_pred" + f.write(" TCGv LSB = tcg_temp_new();\n") + f.write(" TCGLabel *skip = gen_new_label();\n") + f.write(f" tcg_gen_andi_tl(LSB, {source}[insn->regno[{i}]], 1);\n") + cond = "NE" if pred.group(2) else "EQ" + f.write(f" tcg_gen_brcondi_tl(TCG_COND_{cond}, LSB, 0, skip);\n") + f.write(f" {ea};\n") + f.write(" gen_log_mem_address(ctx, EA);\n") + if pred: + f.write(" gen_set_label(skip);\n") + f.write("}\n#endif\n\n") + + def gen_def_tcg_func(f, tag, tagregs, tagimms): regs = tagregs[tag] imms = tagimms[tag] gen_tcg_func(f, tag, regs, imms) + gen_memory_address(f, tag, regs, imms) def main():
target/hexagon/genptr.c +17 -0
@@ -1722,6 +1722,23 @@ static void vec_to_qvec(size_t size, TCGv_ptr dstbase, intptr_t dstoff, } } +#ifndef CONFIG_USER_ONLY +void gen_log_mem_address (DisasContext *ctx,TCGv va) +{ +unsigned slot = ctx->insn->slot; +TCGv valid =tcg_temp_new (); + +tcg_debug_assert (slot <2 ); +tcg_gen_st_i32 (va, tcg_env, + offsetof(CPUHexagonState, mem_access_va[slot])); +tcg_gen_ld_i32 (valid, tcg_env, + offsetof(CPUHexagonState , mem_access_valid)); +tcg_gen_ori_i32 (valid, valid,1U << slot); +tcg_gen_st_i32 (valid, tcg_env, + offsetof(CPUHexagonState , mem_access_valid)); +} +#endif +void probe_noshuf_load (TCGv va,int s,int mi) {TCGv size =tcg_constant_tl (s);
target/hexagon/genptr.h +4 -0
@@ -23,6 +23,10 @@#include "translate.h" extern const SemanticInsn opcode_genptr[]; +#ifndef CONFIG_USER_ONLY +extern const SemanticInsn opcode_address[]; +void gen_log_mem_address (DisasContext *ctx,TCGv va); +#endif void gen_store32 (TCGv vaddr,TCGv src,uint32_t width,uint32_t slot);void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src,uint32_t slot);
target/hexagon/hex_common.py +22 -0
@@ -299,6 +299,28 @@ def need_pkt_has_multi_cof(tag): return False +def packet_memory_info(tag): + """Return a side-effect-free scalar address expression, if available.""" + attrs = attribdict[tag] + if not ("A_LOAD" in attrs or "A_STORE" in attrs): + return None + if any(a in attrs for a in ("A_CVI", "A_HVX", "A_HLX", "A_HMX")): + return None + sem = semdict[tag] + ea = re.search(r"fEA_(?:RI|RRs|IRs|IMM|REG|BREVR)\([^;]+\)", sem) + if not ea: + return None + # A locked store is conditional on the reservation, not a predicate. + if "fSTORE_LOCKED" in sem: + return None + width = next((n for n in (1, 2, 4, 8) + if f"A_MEMSIZE_{n}B" in attrs), None) + if width is None: + return None + pred = re.search(r"fLSB(OLD|NEW)(NOT)?\((P\w+)\)", sem) + return ea.group(0), pred, width + + def need_pkt_need_commit(tag): return 'A_IMPLICIT_WRITES_USR' in attribdict[tag]
target/hexagon/translate.c +16 -0
@@ -814,6 +814,7 @@ static void gen_start_packet(DisasContext *ctx)* gen phase, so clear it again. */ bitmap_zero (ctx->pregs_written,NUM_PREGS ); + ctx->mem_addresses_generated = false;#ifndef CONFIG_USER_ONLY for (i =0 ; i <HEX_SREG_GLB_START ; i++) { ctx->t_sreg_new_value[i] =NULL ;
@@ -1021,6 +1022,21 @@ static void gen_insn(DisasContext *ctx)#ifndef CONFIG_USER_ONLY if (GET_ATTRIB (opcode,A_LOAD ) ||GET_ATTRIB (opcode,A_STORE )) { +if (!ctx->mem_addresses_generated) { +Insn *saved = ctx->insn; + +tcg_gen_st_i32 (tcg_constant_i32 (0 ), tcg_env, + offsetof(CPUHexagonState , mem_access_valid)); +for (int i =0 ; i < ctx->pkt.num_insns; i++) { +Insn *in = &ctx->pkt.insn[i]; +if (opcode_address[in->opcode]) { + ctx->insn = in; + opcode_address[in->opcode](ctx); + } + } + ctx->insn = saved; + ctx->mem_addresses_generated = true; + }tcg_gen_st_i32 (tcg_constant_i32 (ctx->insn->slot), tcg_env, offsetof(CPUHexagonState , mem_slot)); }
target/hexagon/translate.h +1 -0
@@ -88,6 +88,7 @@ typedef struct DisasContext {DECLARE_BITMAP (insn_qregs_read,NUM_QREGS );bool pre_commit;bool need_commit; +bool mem_addresses_generated;TCGCond branch_cond;target_ulong branch_dest;bool is_tight_loop;
Signature · 1 line
2.43.0
PATCH v2 8/13 target/hexagon: preserve inactive BADVA registers
In reply to Marco LiebelClear the validity bit without overwriting the inactive slot address. Fault handlers can retain BADVA values across exceptions.
--- target/hexagon/cpu.c | 6 ------ 1 file changed, 6 deletions(-)
target/hexagon/cpu.c +0 -6
@@ -752,8 +752,6 @@ static bool hexagon_cpu_translate_for_debug(CPUState *cs, vaddr addr, } -#define INVALID_BADVA 0xbadabada -static void set_badva_regs (CPUHexagonState *env,uint32_t VA ,int slot,MMUAccessType access_type) {
@@ -765,8 +763,6 @@ static void set_badva_regs(CPUHexagonState *env, uint32_t VA, int slot,if (valid & (1U << i)) { env->t_sreg[HEX_SREG_BADVA0 + i] = i == slot ?VA : env->mem_access_va[i]; - }else { - env->t_sreg[HEX_SREG_BADVA0 + i] =INVALID_BADVA ; } }SET_SSR_FIELD (env,SSR_V0 , valid &1 );
@@ -777,12 +773,10 @@ static void set_badva_regs(CPUHexagonState *env, uint32_t VA, int slot,if (access_type ==MMU_INST_FETCH || slot ==0 ) { env->t_sreg[HEX_SREG_BADVA0 ] =VA ; - env->t_sreg[HEX_SREG_BADVA1 ] =INVALID_BADVA ;SET_SSR_FIELD (env,SSR_V0 ,1 );SET_SSR_FIELD (env,SSR_V1 ,0 );SET_SSR_FIELD (env,SSR_BVS ,0 ); }else if (slot ==1 ) { - env->t_sreg[HEX_SREG_BADVA0 ] =INVALID_BADVA ; env->t_sreg[HEX_SREG_BADVA1 ] =VA ;SET_SSR_FIELD (env,SSR_V0 ,0 );SET_SSR_FIELD (env,SSR_V1 ,1 );
Signature · 1 line
2.43.0
PATCH v2 9/13 target/hexagon: probe scalar packet memory in slot priority order
In reply to Marco LiebelProbe slot 1 before slot 0 without committing either access. A slot 1 store miss must win over a slot 0 load miss in a mem_noshuf packet.
--- target/hexagon/op_helper.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
target/hexagon/op_helper.c +10 -0
@@ -459,6 +459,12 @@ void HELPER(probe_noshuf_load)(CPUHexagonState *env, target_ulong va, {uintptr_t retaddr =GETPC ();#ifndef CONFIG_USER_ONLY +/* The slot 1 store fault must precede the slot 0 load fault. */ +if (env->mem_access_valid & (1U <<1 )) { + env->mem_slot =1 ; +probe_write (env, env->mem_access_va[1 ], + env->mem_log_stores[1 ].width, mmu_idx, retaddr); + } env->mem_slot =0 ;#endif probe_read (env, va, size, mmu_idx, retaddr);
@@ -555,6 +561,10 @@ static void check_noshuf(CPUHexagonState *env, bool pkt_has_scalar_store_s1, {if (slot ==0 && pkt_has_scalar_store_s1 && ((env->slot_cancelled & (1 <<1 )) ==0 )) { +#ifndef CONFIG_USER_ONLY +probe_store (env,1 ,MMU_USER_IDX , false, ra); + env->mem_slot =0 ; +#endif probe_read (env, vaddr, size,MMU_USER_IDX , ra);commit_store (env,1 , ra); }
Signature · 1 line
2.43.0
PATCH v2 10/13 target/hexagon: prioritize packet alignment in the fault path
In reply to Marco LiebelUse MO_ALIGN for normal scalar memory accesses. On a memory fault, check the recorded active addresses for alignment before reporting a translation fault. Give slot 1 priority when both accesses are unaligned.
Keep constant access widths and types in insn_start unwind metadata so the precedence checks add no runtime metadata stores or packet-wide TCG alignment checks. Retain per-access checks in commit probes to prevent partial stores.
--- target/hexagon/cpu.c | 47 +++++++++++++++++++++++++++++++++ target/hexagon/cpu.h | 6 +++++ target/hexagon/gen_tcg_funcs.py | 2 +- target/hexagon/genptr.c | 10 ++++++- target/hexagon/genptr.h | 2 +- target/hexagon/internal.h | 5 ++++ target/hexagon/op_helper.c | 2 ++ target/hexagon/translate.c | 1 + target/hexagon/translate.h | 1 + 9 files changed, 73 insertions(+), 3 deletions(-)
target/hexagon/cpu.c +47 -0
@@ -30,6 +30,7 @@#include "tcg/tcg.h" #include "exec/gdbstub.h" #include "accel/tcg/cpu-ops.h" +#include "accel/tcg/cpu-loop.h" #include "cpu_helper.h" #include "hex_mmu.h"
@@ -835,6 +836,45 @@ static void raise_misaligned_exception(CPUState *cs, uint32_t VA, int slot, env->cause_code = excp; } +static void check_packet_alignment (CPUHexagonState *env,uintptr_t retaddr) +{ +CPUState *cs =env_cpu (env); +uint64_t data[INSN_START_WORDS ]; + +if (!env->mem_access_valid || !retaddr || + !cpu_unwind_state_data (cs, retaddr, data)) { +return ; + } + +/* Alignment wins over translation faults; slot 1 wins over slot 0. */ +for (int slot =1 ; slot >=0 ; slot--) { +unsigned info = data[1 ] >> (slot *HEX_SCALAR_MEM_ACCESS_BITS ); +unsigned width = info &HEX_SCALAR_MEM_SIZE_MASK ; +uint32_t va = env->mem_access_va[slot]; + +if ((env->mem_access_valid & (1U << slot)) && width && + (va & (width -1 ))) { +raise_misaligned_exception (cs, va, slot, + info &HEX_SCALAR_MEM_STORE ? +MMU_DATA_STORE :MMU_DATA_LOAD ); +do_raise_exception (env, cs->exception_index, data[0 ], retaddr); + } + } +} + +void hexagon_check_alignment (CPUHexagonState *env,uint32_t va, +unsigned size,int slot, +MMUAccessType access_type,uintptr_t retaddr) +{ +if (va & (size -1 )) { +CPUState *cs =env_cpu (env); +check_packet_alignment (env, retaddr); +raise_misaligned_exception (cs, va, slot, access_type); +do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], + retaddr); + } +} +static const char *access_type_names[] = {"MMU_DATA_LOAD " ,"MMU_DATA_STORE" ,"MMU_INST_FETCH" };
@@ -870,6 +910,9 @@ static bool hexagon_tlb_fill(CPUState *cs, vaddr address, int size,if (probe) {return false; } +if (access_type !=MMU_INST_FETCH ) { +check_packet_alignment (env, retaddr); + }raise_perm_exception (cs, address, slot, access_type, excp);do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], retaddr);
@@ -877,6 +920,9 @@ static bool hexagon_tlb_fill(CPUState *cs, vaddr address, int size,if (probe) {return false; } +if (access_type !=MMU_INST_FETCH ) { +check_packet_alignment (env, retaddr); + }raise_tlbmiss_exception (cs, address, slot, access_type);do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], retaddr); }
@@ -928,6 +974,7 @@ void hexagon_cpu_do_unaligned_access(CPUState *cs, vaddr addr, {CPUHexagonState *env =cpu_env (cs); +check_packet_alignment (env, retaddr);raise_misaligned_exception (cs, addr, env->mem_slot, access_type);do_raise_exception (env, cs->exception_index, env->gpr[HEX_REG_PC ], retaddr);
target/hexagon/cpu.h +6 -0
@@ -231,6 +231,12 @@ typedef struct CPUArchState {HmxState *hmx_state; } CPUHexagonState; +#ifndef CONFIG_USER_ONLY +void hexagon_check_alignment (CPUHexagonState *env,uint32_t va, +unsigned size,int slot, +MMUAccessType access_type,uintptr_t retaddr); +#endif + typedef struct HexagonCPUClass { CPUClass parent_class;
target/hexagon/gen_tcg_funcs.py +1 -1
@@ -185,7 +185,7 @@ def gen_memory_address(f, tag, regs, imms): cond = "NE" if pred.group(2) else "EQ" f.write(f" tcg_gen_brcondi_tl(TCG_COND_{cond}, LSB, 0, skip);\n") f.write(f" {ea};\n") - f.write(" gen_log_mem_address(ctx, EA);\n") + f.write(f" gen_log_mem_address(ctx, EA, {width});\n") if pred: f.write(" gen_set_label(skip);\n") f.write("}\n#endif\n\n")
target/hexagon/genptr.c +9 -1
@@ -24,6 +24,7 @@#include "tcg/tcg-op-gvec.h" #include "exec/helper-gen.h" #include "insn.h" +#include "attribs.h" #include "opcodes.h" #include "sys_macros.h" #include "translate.h"
@@ -1723,12 +1724,18 @@ static void vec_to_qvec(size_t size, TCGv_ptr dstbase, intptr_t dstoff, }#ifndef CONFIG_USER_ONLY -void gen_log_mem_address (DisasContext *ctx,TCGv va) +void gen_log_mem_address (DisasContext *ctx,TCGv va,unsigned width) {unsigned slot = ctx->insn->slot; +unsigned info = width;TCGv valid =tcg_temp_new ();tcg_debug_assert (slot <2 ); +if (GET_ATTRIB (ctx->insn->opcode,A_STORE )) { + info |=HEX_SCALAR_MEM_STORE ; + } + ctx->scalar_mem_info |= info << (slot *HEX_SCALAR_MEM_ACCESS_BITS ); +tcg_set_insn_start_param (ctx->base.insn_start,1 , ctx->scalar_mem_info);tcg_gen_st_i32 (va, tcg_env, offsetof(CPUHexagonState, mem_access_va[slot])); tcg_gen_ld_i32(valid, tcg_env,
@@ -1737,6 +1744,7 @@ void gen_log_mem_address(DisasContext *ctx, TCGv va)tcg_gen_st_i32 (valid, tcg_env, offsetof(CPUHexagonState, mem_access_valid)); } +#endif void probe_noshuf_load (TCGv va,int s,int mi)
target/hexagon/genptr.h +1 -1
@@ -25,7 +25,7 @@extern const SemanticInsn opcode_genptr[];#ifndef CONFIG_USER_ONLY extern const SemanticInsn opcode_address[]; -void gen_log_mem_address (DisasContext *ctx,TCGv va); +void gen_log_mem_address (DisasContext *ctx,TCGv va,unsigned width);#endif void gen_store32 (TCGv vaddr,TCGv src,uint32_t width,uint32_t slot);
target/hexagon/internal.h +5 -0
@@ -20,6 +20,11 @@#include "target/hexagon/cpu.h" +/* Per-slot scalar access fields in the second insn_start unwind word. */ +#define HEX_SCALAR_MEM_ACCESS_BITS 5 +#define HEX_SCALAR_MEM_SIZE_MASK 0xf +#define HEX_SCALAR_MEM_STORE (1U << 4) +int hexagon_gdb_read_register (CPUState *cpu,GByteArray *buf,int reg);int hexagon_gdb_write_register (CPUState *cpu,uint8_t *buf,int reg);int hexagon_hvx_gdb_read_register (CPUState *env,GByteArray *mem_buf,int n);
target/hexagon/op_helper.c +2 -0
@@ -466,6 +466,7 @@ void HELPER(probe_noshuf_load)(CPUHexagonState *env, target_ulong va, env->mem_log_stores[1].width, mmu_idx, retaddr); } env->mem_slot =0 ; +hexagon_check_alignment (env, va, size,0 ,MMU_DATA_LOAD , retaddr);#endif probe_read (env, va, size, mmu_idx, retaddr); }
@@ -564,6 +565,7 @@ static void check_noshuf(CPUHexagonState *env, bool pkt_has_scalar_store_s1,#ifndef CONFIG_USER_ONLY probe_store (env,1 ,MMU_USER_IDX , false, ra); env->mem_slot =0 ; +hexagon_check_alignment (env, vaddr, size,0 ,MMU_DATA_LOAD , ra);#endif probe_read (env, vaddr, size,MMU_USER_IDX , ra);commit_store (env,1 , ra);
target/hexagon/translate.c +1 -0
@@ -816,6 +816,7 @@ static void gen_start_packet(DisasContext *ctx)bitmap_zero (ctx->pregs_written,NUM_PREGS ); ctx->mem_addresses_generated = false;#ifndef CONFIG_USER_ONLY + ctx->scalar_mem_info =0 ;for (i =0 ; i <HEX_SREG_GLB_START ; i++) { ctx->t_sreg_new_value[i] =NULL ; }
target/hexagon/translate.h +1 -0
@@ -46,6 +46,7 @@ typedef struct DisasContext {bool implicit_usr_write;#ifndef CONFIG_USER_ONLY uint32_t cpu_mode; +uint32_t scalar_mem_info;bool ss_active;int greg_log[GREG_WRITES_MAX ];int greg_log_idx;
Signature · 1 line
2.43.0
PATCH v2 11/13 target/hexagon: validate both stores before packet commit
In reply to Marco LiebelCheck alignment in store probes and validate both logged stores before committing either one. This also covers stores without generated address preflight code.
--- target/hexagon/helper.h | 2 +- target/hexagon/op_helper.c | 16 +++++++++++----- target/hexagon/translate.c | 15 ++++++++------- target/hexagon/translate.h | 5 +++-- 4 files changed, 23 insertions(+), 15 deletions(-)
target/hexagon/helper.h +1 -1
@@ -143,7 +143,7 @@ DEF_HELPER_2(vwhist128m, void, env, s32) DEF_HELPER_2(vwhist128qm, void, env, s32) DEF_HELPER_4(probe_noshuf_load, void, env, i32, int, int) -DEF_HELPER_2(probe_pkt_scalar_store_s0, void, env, int) +DEF_HELPER_2(probe_pkt_scalar_stores, void, env, int) DEF_HELPER_2(probe_hvx_stores, void, env, int)DEF_HELPER_2 (probe_pkt_scalar_hvx_stores, void, env, int)
target/hexagon/op_helper.c +11 -5
@@ -446,6 +446,9 @@ static void probe_store(CPUHexagonState *env, int slot, int mmu_idx,#endif uint32_t width = env->mem_log_stores[slot].width;target_ulong va = env->mem_log_stores[slot].va; +#ifndef CONFIG_USER_ONLY +hexagon_check_alignment (env, va, width, slot,MMU_DATA_STORE , retaddr); +#endif probe_write (env, va, width, mmu_idx, retaddr); } }
@@ -472,13 +475,16 @@ void HELPER(probe_noshuf_load)(CPUHexagonState *env, target_ulong va, }/* Called during packet commit when there are two scalar stores */ -void HELPER (probe_pkt_scalar_store_s0 )(CPUHexagonState *env,int args) +void HELPER (probe_pkt_scalar_stores )(CPUHexagonState *env,int args) { -int mmu_idx =FIELD_EX32 (args,PROBE_PKT_SCALAR_STORE_S0 ,MMU_IDX ); -bool is_predicated = -FIELD_EX32 (args,PROBE_PKT_SCALAR_STORE_S0 ,IS_PREDICATED ); +int mmu_idx =FIELD_EX32 (args,PROBE_PKT_SCALAR_STORES ,MMU_IDX ); +bool pred[2 ] = { +FIELD_EX32 (args,PROBE_PKT_SCALAR_STORES ,S0_IS_PREDICATED ), +FIELD_EX32 (args,PROBE_PKT_SCALAR_STORES ,S1_IS_PREDICATED ), + };uintptr_t ra =GETPC (); -probe_store (env,0 , mmu_idx, is_predicated, ra); +probe_store (env,1 , mmu_idx, pred[1 ], ra); +probe_store (env,0 , mmu_idx, pred[0 ], ra); } static void probe_hvx_stores(CPUHexagonState *env, int mmu_idx,
target/hexagon/translate.c +8 -7
@@ -1486,19 +1486,20 @@ static void gen_commit_packet(DisasContext *ctx) tcg_constant_tl(mask)); } }else if (has_store_s0 && has_store_s1) { -/* -* process_store_log will execute the slot 1 store first, -* so we only have to probe the store in slot 0 -*/ +/* Validate both stores, including alignment, before commit. */ int args =0 ; args = -FIELD_DP32 (args,PROBE_PKT_SCALAR_STORE_S0 ,MMU_IDX , ctx->mem_idx); +FIELD_DP32 (args,PROBE_PKT_SCALAR_STORES ,MMU_IDX , ctx->mem_idx);if (slot_is_predicated (&ctx->pkt,0 )) { args = -FIELD_DP32 (args,PROBE_PKT_SCALAR_STORE_S0 ,IS_PREDICATED ,1 ); +FIELD_DP32 (args,PROBE_PKT_SCALAR_STORES ,S0_IS_PREDICATED ,1 ); + } +if (slot_is_predicated (&ctx->pkt,1 )) { + args =FIELD_DP32 (args,PROBE_PKT_SCALAR_STORES , +S1_IS_PREDICATED ,1 ); }TCGv args_tcgv =tcg_constant_tl (args); -gen_helper_probe_pkt_scalar_store_s0 (tcg_env, args_tcgv); +gen_helper_probe_pkt_scalar_stores (tcg_env, args_tcgv); }if (ctx->hex_def->hex_version >=HEX_VER_V83 ) {
target/hexagon/translate.h +3 -2
@@ -442,8 +442,9 @@ void hex_gen_exception_end_tb(DisasContext *ctx, int cause);void process_store (DisasContext *ctx,int slot_num); -FIELD(PROBE_PKT_SCALAR_STORE_S0, MMU_IDX, 0, 2) -FIELD(PROBE_PKT_SCALAR_STORE_S0, IS_PREDICATED, 2, 1) +FIELD(PROBE_PKT_SCALAR_STORES, MMU_IDX, 0, 2) +FIELD(PROBE_PKT_SCALAR_STORES, S0_IS_PREDICATED, 2, 1) +FIELD(PROBE_PKT_SCALAR_STORES, S1_IS_PREDICATED, 3, 1) FIELD(PROBE_PKT_SCALAR_HVX_STORES, HAS_ST0, 0, 1)FIELD (PROBE_PKT_SCALAR_HVX_STORES ,HAS_ST1 ,1 ,1 )
Signature · 1 line
2.43.0
PATCH v2 12/13 target/hexagon: probe VMEMU upper transactions before lower ones
In reply to Marco LiebelRecord both unaligned VMEMU addresses and probe the upper transaction first. Report the architectural address, not the page boundary found by a split TLB access. Preserve both validity bits on load and store faults.
--- target/hexagon/cpu.c | 4 +++- target/hexagon/genptr.c | 10 ++++++++++ target/hexagon/helper.h | 3 +++ target/hexagon/op_helper.c | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-)
target/hexagon/cpu.c +3 -1
@@ -763,9 +763,11 @@ static void set_badva_regs(CPUHexagonState *env, uint32_t VA, int slot,for (int i =0 ; i <2 ; i++) {if (valid & (1U << i)) { env->t_sreg[HEX_SREG_BADVA0 + i] = - i == slot ?VA : env->mem_access_va[i]; + (env->mem_access_valid & (1U << i)) ? + env->mem_access_va[i] :VA ; } } + env->t_sreg[HEX_SREG_BADVA ] = env->t_sreg[HEX_SREG_BADVA0 + slot];SET_SSR_FIELD (env,SSR_V0 , valid &1 );SET_SSR_FIELD (env,SSR_V1 , (valid >>1 ) &1 );SET_SSR_FIELD (env,SSR_BVS , slot);
target/hexagon/genptr.c +10 -0
@@ -1635,6 +1635,11 @@ static void gen_vreg_load(DisasContext *ctx, TCGv_ptr dstbase, intptr_t dstoff, TCGv src, bool aligned) { TCGv_i64 tmp = tcg_temp_new_i64(); +#ifndef CONFIG_USER_ONLY +gen_helper_probe_hvx_mem (tcg_env, src,tcg_constant_i32 (ctx->insn->slot), +tcg_constant_i32 (aligned),tcg_constant_i32 (0 ), +tcg_constant_i32 (ctx->mem_idx)); +#endif if (aligned) {tcg_gen_andi_tl (src, src, ~((int32_t )VECTOR_SIZE_BYTE -1 )); }
@@ -1657,6 +1662,11 @@ static void gen_vreg_store(DisasContext *ctx, TCGv EA, TCGv_ptr srcbase,return ; } +#ifndef CONFIG_USER_ONLY +gen_helper_probe_hvx_mem (tcg_env,EA ,tcg_constant_i32 (slot), +tcg_constant_i32 (aligned),tcg_constant_i32 (1 ), +tcg_constant_i32 (ctx->mem_idx)); +#endif tcg_gen_movi_tl (hex_vstore_pending[slot],1 );if (aligned) { tcg_gen_andi_tl(hex_vstore_addr[slot], EA,
target/hexagon/helper.h +3 -0
@@ -22,6 +22,9 @@ DEF_HELPER_FLAGS_3(raise_exception, TCG_CALL_NO_RETURN, noreturn, env, i32, i32) DEF_HELPER_2(commit_store, void, env, int) DEF_HELPER_3(gather_store, void, env, i32, int) DEF_HELPER_1(commit_hvx_stores, void, env) +#ifndef CONFIG_USER_ONLY +DEF_HELPER_6(probe_hvx_mem, void, env, i32, i32, i32, i32, i32) +#endif DEF_HELPER_FLAGS_4(fcircadd, TCG_CALL_NO_RWG_SE, s32, s32, s32, s32, s32) DEF_HELPER_FLAGS_1(fbrev, TCG_CALL_NO_RWG_SE, i32, i32)DEF_HELPER_4 (sfrecipa, i64, env, f32, f32, i32)
target/hexagon/op_helper.c +38 -0
@@ -54,6 +54,41 @@#include "hexswi.h" #endif +#ifndef CONFIG_USER_ONLY +static void log_mem_address (CPUHexagonState *env,uint32_t va,uint32_t slot) +{ +assert (slot <2 ); + env->mem_access_valid |=1U << slot; + env->mem_access_va[slot] = va; +} + +void HELPER (probe_hvx_mem )(CPUHexagonState *env,uint32_t va,uint32_t slot, +uint32_t aligned,uint32_t store,uint32_t mmu_idx) +{ +uintptr_t ra =GETPC (); +uint32_t base = va & ~(VECTOR_SIZE_BYTE -1 ); + +if (aligned) { +log_mem_address (env, base, slot); + }else { +/* VMEMU uses both slots; BADVA records the unaligned addresses. */ +log_mem_address (env, va,0 ); +log_mem_address (env, va +VECTOR_SIZE_BYTE ,1 ); + } +int first = aligned ? slot :1 ; +int last = aligned ? slot :0 ; +for (int s = first; s >= last; s--) { +uint32_t address = base + (aligned ?0 : s *VECTOR_SIZE_BYTE ); + env->mem_slot = s; +if (store) { +probe_write (env, address,VECTOR_SIZE_BYTE , mmu_idx, ra); + }else { +probe_read (env, address,VECTOR_SIZE_BYTE , mmu_idx, ra); + } + } +} +#endif +#ifdef CONFIG_USER_ONLY /* * User mode has no qtimer device backing TIMERLO/TIMERHI, so derive the
@@ -493,6 +528,9 @@ static void probe_hvx_stores(CPUHexagonState *env, int mmu_idx,/* Normal (possibly masked) vector store */ for (int i =0 ; i <VSTORES_MAX ; i++) {if (env->vstore_pending[i]) { +#ifndef CONFIG_USER_ONLY + env->mem_slot = i; +#endif target_ulong va = env->vstore[i].va;int size = env->vstore[i].size;for (int j =0 ; j < size; j++) {
Signature · 1 line
2.43.0
PATCH v2 13/13 tests/functional/hexagon: add packet regression tests
In reply to Marco LiebelRun the standalone packet binary from qemu-hexagon-testing v0.3.5 and check all 11 system case results and the final summary. Use the existing standalone archive layout with a checksum-verified release archive. Stop QEMU after the runtime prints the results.
--- tests/functional/hexagon/meson.build | 2 + tests/functional/hexagon/test_packets.py | 47 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/functional/hexagon/test_packets.py
tests/functional/hexagon/meson.build +2 -0
@@ -6,6 +6,7 @@ tests_hexagon_system_thorough = [ 'systests', 'hlx', 'minivm', + 'packets', ] test_hexagon_timeouts = {
@@ -13,4 +14,5 @@ test_hexagon_timeouts = { 'qcom_dsp_firmware': 240, 'systests': 180, 'hlx': 180, + 'packets': 180, }
tests/functional/hexagon/test_packets.py new file +47 -0
47 lines not on this page · raw message
Signature · 1 line
2.43.0