@samitouri / QOSamiQemu / commits / 13eb268182

target/hexagon: raise SIGBUS on unaligned data access in sysemu

hexagon-softmmu had no enforcement of alignment for scalar loads and stores: the MO_ALIGN flag added by the previous two commits triggers TLB_INVALID_MASK/alignment faults in cputlb.c, but Hexagon's TCGCPUOps did not implement do_unaligned_access, so the fault was never delivered to the guest. Add hexagon_cpu_do_unaligned_access(), which raises HEX_CAUSE_MISALIGNED_LOAD/_STORE via the existing HEX_EVENT_PRECISE path, mirroring raise_tlbmiss_exception()/raise_perm_exception(). Reviewed-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com> Reviewed-by: Matheus Tavares Bernardino <matheus.bernardino@oss.qualcomm.com> Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>

Brian Cain committed Jul 13, 2026 at 18:09 UTC 13eb268182476414c4604302404a08ee09b8572e
1 file changed +25
target/hexagon/cpu.c
+25
@@ -637,6 +637,18 @@ static void raise_perm_exception(CPUState *cs, uint32_t VA, int slot,
637 cs->exception_index = excp;
638 }
639
640 +static void raise_misaligned_exception(CPUState *cs, uint32_t VA, int slot,
641 + MMUAccessType access_type)
642 +{
643 + CPUHexagonState *env = cpu_env(cs);
644 + int32_t excp = (access_type == MMU_DATA_STORE) ?
645 + HEX_CAUSE_MISALIGNED_STORE : HEX_CAUSE_MISALIGNED_LOAD;
646 +
647 + set_badva_regs(env, VA, slot, access_type);
648 + cs->exception_index = HEX_EVENT_PRECISE;
649 + env->cause_code = excp;
650 +}
651 +
652 static const char *access_type_names[] = { "MMU_DATA_LOAD ", "MMU_DATA_STORE",
653 "MMU_INST_FETCH" };
654
@@ -715,6 +727,18 @@ static vaddr hexagon_pointer_wrap(CPUState *cs, int mmu_idx,
727 return result;
728 }
729
730 +static G_NORETURN
731 +void hexagon_cpu_do_unaligned_access(CPUState *cs, vaddr addr,
732 + MMUAccessType access_type, int mmu_idx,
733 + uintptr_t retaddr)
734 +{
735 + CPUHexagonState *env = cpu_env(cs);
736 +
737 + raise_misaligned_exception(cs, addr, 0, access_type);
738 + do_raise_exception(env, cs->exception_index, env->gpr[HEX_REG_PC],
739 + retaddr);
740 +}
741 +
742 #endif
743
744 static const TCGCPUOps hexagon_tcg_ops = {
@@ -732,6 +756,7 @@ static const TCGCPUOps hexagon_tcg_ops = {
756 .pointer_wrap = hexagon_pointer_wrap,
757 .cpu_exec_reset = cpu_reset,
758 .tlb_fill = hexagon_tlb_fill,
759 + .do_unaligned_access = hexagon_cpu_do_unaligned_access,
760 .cpu_exec_halt = hexagon_cpu_has_work,
761 .do_interrupt = hexagon_cpu_do_interrupt,
762 #endif /* !CONFIG_USER_ONLY */