schellingb / dosbox-pure

DOSBox Pure is a new fork of DOSBox built for RetroArch/Libretro aiming for simplicity and ease of use.
GNU General Public License v2.0
731 stars 61 forks source link

Segmentation fault on RPi5 with cpu_core=auto #488

Open jonian opened 3 months ago

jonian commented 3 months ago

Hi, when running dosbox-pure on an RPi5 device with dosbox_pure_cpu_core=auto, I get a segmentation fault error. Switching to cpu_core=normal fixes the issue.

My guess is that with the option set to auto, the core uses dynamic recompiler which is not supported on aarch64 (?).

schellingb commented 3 months ago

hmmm.. aarch64 is supported on Android though... maybe it's a build configuration issue? I only have a RPi4 and I have not seen that, but now I'm not sure I tested in 32-bit or 64-bit mode.

I have received reports of eerily similar issues on Nintendo Switch. What's funny about Switch though is that it is possible to run Android on Switch and then the aarch64 Android core runs perfectly.

jonian commented 3 months ago

Thanks for the reply! I used the lakka scripts to build the core using docker, the armv7 builds using the same method work without issues. If you want me to test some builds I will be happy to do it.

The flags used to compile the core:

CFLAGS    : -march=armv8-a+crc -mabi=lp64 -Wno-psabi -mtune=cortex-a72 -mno-outline-atomics -Wall -pipe 
CXXFLAGS  : -march=armv8-a+crc -mabi=lp64 -Wno-psabi -mtune=cortex-a72 -mno-outline-atomics -Wall -pipe  
LDFLAGS   : -Wl,--as-needed 

If you would like to compile the core using my scripts:

git clone https://github.com/jonian/game.retroarch.git
cd game.retroarch

CORE=dosbox_pure ARCH=arm64 DEVICE=RPi5 sh libretro/build.sh
jonian commented 3 months ago

@schellingb after some searching, this might be an issue only on RPi5 due to this bug https://github.com/raspberrypi/bookworm-feedback/issues/107, similar to:

flyinghead/flycast#1288 realnc/dosbox-core#57

jonian commented 3 months ago

I can confirm that it works without issues if compiled with the flag:

-DPAGESIZE=16384
schellingb commented 1 month ago

Thanks for looking into this and finding a fix! Would there be a problem to set this on all aarch64 devices? My first instinct is to change our Makefile from

    PROCCPU := $(shell cat /proc/cpuinfo))
    ifneq ($(and $(filter ARMv7,$(PROCCPU)),$(filter neon,$(PROCCPU))),)
      CPUFLAGS := -marm -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard -ffast-math

to

    UNAMEM := $(shell uname -m))
    ifeq ($(UNAMEM),aarch64)
      CPUFLAGS := -DPAGESIZE=16384
    else ifeq ($(UNAMEM), armv7l)
      CPUFLAGS := -marm -mcpu=cortex-a72 -mfpu=neon-fp-armv8 -mfloat-abi=hard -ffast-math

I only have a RPI4 but I have it running on a 64bit OS so I can try that on there and see if there's any issues.

jonian commented 1 month ago

I don't think that it is needed for every aarch64 device. Even on rpi5 it works with the 4k page size if you set kernel=kernel8.img in config.txt. Maybe the best approach is to check for the page size at build time using:

shell getconf PAGESIZE

This is how it was fixed in flycast and dosbox-core.

https://github.com/flyinghead/flycast/commit/0f6a92caad25ed65d6b558bb965793ae02c39be1 https://github.com/realnc/dosbox-core/pull/58/commits/1e6a675a9e56aa2399c64d3f70be2519b7c1548b