NEMU icon indicating copy to clipboard operation
NEMU copied to clipboard

NEMU could not trap at misaligned memory access when running standalone

Open cebarobot opened this issue 1 year ago • 1 comments

When NEMU is running as shared library, it could detect misaligned memory access and trap into address misaligned, which is good.

But when NEMU is running standalone, it is no longer able to detect misaligned memory access:

  • Using By host CPU (AC_HOST): NEMU would crash and report "BUS ERROR (core dumped)"
  • Using By software emulation (AC_SOFT): Nothing would happen.

Check macro AC_SOFT, we could find isa_misalign_data_addr_check(). This function shows up at three place:

  • isa_mmu_check(): This function seems to be called rarely and only at AMO or ifetch.
  • vaddr_read_internal(): isa_misalign_data_addr_check() is only called when enable CONFIG_SHARE and it works well when NEMU is using as ref.
  • vaddr_write(): isa_misalign_data_addr_check() is only called when enable CONFIG_SHARE and it works well when NEMU is using as ref.

In Summary, there is no misalign check at normal loads and stores when NEMU is running standalone.

I have tried to remove #ifdef CONFIG_SHARE of isa_misalign_data_addr_check() in vaddr_read_internal() and vaddr_write(). It worked well if PERF_OPT is off, but crashed if PERF_OPT is on.

cebarobot avatar Apr 11 '24 06:04 cebarobot

This problem is still here. When I run NEMU with SPIKE, NEMU won't trap at a misaligned addr access.

cebarobot avatar May 31 '24 08:05 cebarobot