dosbox-pure icon indicating copy to clipboard operation
dosbox-pure copied to clipboard

Segmentation fault on RPi5 with cpu_core=auto

Open jonian opened this issue 1 year ago • 6 comments

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 (?).

jonian avatar Mar 25 '24 12:03 jonian

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.

schellingb avatar Mar 25 '24 13:03 schellingb

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 avatar Mar 25 '24 13:03 jonian

@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 avatar Mar 26 '24 12:03 jonian

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

-DPAGESIZE=16384

jonian avatar Mar 26 '24 13:03 jonian

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.

schellingb avatar May 16 '24 05:05 schellingb

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

jonian avatar May 16 '24 09:05 jonian

Could you try DOOM on a Pi5? Does it work?

toniosj avatar Dec 19 '24 12:12 toniosj

The person who opened this issue said

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

So I'm inclined to believe them. As described, the error only happens with cpu_core=auto and not with cpu_core=normal. It very likely also happens on cpu_core=dynamic. Games like DOOM (and most games made after 1994 or so) run in so called "protected mode", with cpu_core=auto that means the emulation on startup runs on the "normal cpu core" and when switching into protected mode it switches to "dynamic cpu core". That's what the "auto" part in the cpu_core setting does. So if this fixes auto in general, this very likely fixes DOOM.

I myself only have a Pi4 so I can't test it. If you have one, you could test it, compiling the core should be as easy as

git clone --single-branch --branch main --depth 1 https://github.com/schellingb/dosbox-pure
make -C dosbox-pure -j4

Then you should have the compiled core as the file dosbox-pure/dosbox_pure_libretro.so. The core has zero dependencies, so all that is required are the g++ and make packages to be installed i.e. do sudo apt-get install g++ make beforehand if you don't have them.

schellingb avatar Dec 19 '24 14:12 schellingb

@toniosj haven't tried doom, I have only tried doom ultimate and it works without issues. You can use my RPi5 build from here.

jonian avatar Dec 19 '24 20:12 jonian

@toniosj Can you test the newest version 1.0-preview1 available from the RetroArch online core downloader?

schellingb avatar Dec 29 '24 17:12 schellingb

@toniosj haven't tried doom, I have only tried doom ultimate and it works without issues. You can use my RPi5 build from here.

@jonian Could you share your RPi5 build again? Thanks!

toniosj avatar Feb 17 '25 19:02 toniosj

@toniosj RPI5 build https://github.com/jonian/game.retroarch/actions/runs/12470792330

jonian avatar Feb 21 '25 09:02 jonian