Open main menu

Difference between revisions of "HOWTO-Debug-Endian-Issues"

Mention the Raspberry Pi being able to run big-endian NetBSD, just in case… untested
(Add subsections, mostly for readability)
(Mention the Raspberry Pi being able to run big-endian NetBSD, just in case… untested)
 
(16 intermediate revisions by the same user not shown)
Line 8: Line 8:
#* Examples include the [https://www.raptorcs.com/content/BK1B01/intro.html Raptor Blackbird™] workstation. It is a powerful system which can run up-to-date Linux/BSD distributions, both in little-endian and big-endian modes.
#* Examples include the [https://www.raptorcs.com/content/BK1B01/intro.html Raptor Blackbird™] workstation. It is a powerful system which can run up-to-date Linux/BSD distributions, both in little-endian and big-endian modes.
#* Unfortunately, it's a pricey niche system, and there's no guarantee that big-endian OS options will be maintained for long.
#* Unfortunately, it's a pricey niche system, and there's no guarantee that big-endian OS options will be maintained for long.
#* NetBSD also allows [https://mail-index.netbsd.org/port-arm/2020/12/03/msg007117.html running a Raspberry Pi in big-endian mode], but this isn't been tested for ScummVM development yet.
# Running a native, older big-endian development system:
# Running a native, older big-endian development system:
#* Examples include buying an older G4 or G5 Apple PowerPC system, or an older SPARC64 Sun station. They can often be bought second hand at very reasonable prices.
#* Examples include buying an older G4 or G5 Apple PowerPC system, or an older SPARC64 Sun station<ref>Some MIPS and ARM boards also exist, but their quality can vary a lot, and although the MIPS and ARM architectures are theoretically bi-endian, in practice these development boards often only run in little-endian mode, nowadays. They can be useful for strict-alignment testing, though (but <code>-fsanitize=alignment -DSCUMM_NEED_ALIGNMENT</code> in UBSan on your regular desktop will also catch a lot of these issues).</ref>. They can often be bought second hand at very reasonable prices.
#* However, running a modern development environment on them in getting harder (but not impossible), because the big-endian desktop ecosystem receives less and less maintenance, so things often tend to break. G5 systems (in particular) also require careful maintenance and can be very power-hungry.
#* However, running a modern development environment on them in getting harder (but not impossible), because the big-endian desktop ecosystem receives less and less maintenance, so things often tend to break. G5 systems (in particular) also require careful maintenance and can be very power-hungry.
#* (Some MIPS and ARM boards also exist, but their quality can vary a lot, and although the MIPS and ARM architectures are theoretically bi-endian, in practice these development boards often only run in little-endian mode, nowadays. They can be useful for strict-alignment testing, though.)
# '''Emulating a big-endian development system from your regular development machine''':
# '''Emulating a big-endian development system from your regular development machine''':
#* Any reasonably powerful desktop system should be able to emulate a big-endian architecture, thanks to [https://www.qemu.org QEMU].
#* Any reasonably powerful desktop system should be able to emulate a big-endian architecture, thanks to [https://www.qemu.org QEMU].
#* The main drawback is that this currently requires running some older/unmaintained Linux distributions, and, as of late 2022, audio and graphics acceleration support is missing. Since this is emulation (and not virtualization), there is also a noticeable (but usually tolerable) performance impact.
#* The main drawback is that this currently requires running some older/unmaintained Linux distributions, and, as of late 2022, graphics acceleration support is missing. Since this is emulation (and not virtualization), there is also a noticeable (but usually tolerable) performance impact.


This howto focuses on the last option, since it is the most accessible one, and it's still a way of fixing the majority of endianness issues we encounter.
This howto focuses on the last option, since it is the most accessible one, and it's still a way of fixing the majority of endianness issues we encounter.
Line 20: Line 20:
== Linux big-endian PowerPC emulation with QEMU ==
== Linux big-endian PowerPC emulation with QEMU ==


The current reference VM is a pre-configured Debian 8.11 PowerPC system. It has been modified to feature an updated C++11 toolchain (GCC 5.5.0).
The current reference VM is a pre-configured Debian 8.11 PowerPC system<ref>Modern versions of Debian are actually still built for big-endian PowerPC, but it's not a ''release'' architecture anymore, which means that it's only available through Debian ''unstable''. Debian unstable is harder to maintain than a stable release, and bugs/reliability issues often appear (e.g. Valgrind has been having PPC SDL compatibility problems for years, GRUB installation being much less reliable than the older Yaboot…), especially  on non-mainstream architectures. This is why we're sticking with a Debian 8 VM for now.</ref>. It has been modified to feature an updated C++11 toolchain (GCC 5.5.0).
 
The VM image is quite large, so ask the rest of the team for its URL.


Some important notes:
Some important notes:


* Security support updates have been discontinued for Debian 8 in late 2018. Older cryptographic ciphers and certificates (such as in TLS or SSH) in the base system may also cause various issues. For this reason, this VM should only be run ''on a local, trusted environment''.
* Security support updates have been discontinued for Debian 8 in late 2018. Older cryptographic ciphers and certificates (such as in TLS or SSH) in the base system may also cause various issues. For this reason, this VM should only be run ''on a local, trusted environment''.
* Modern versions of Debian are actually still built for big-endian PowerPC, but it's not a ''release'' architecture anymore, which means that it's only available through Debian ''unstable''. Debian unstable is harder to maintain than a stable release, and bugs/reliability issues often appear, especially  on non-mainstream architectures. This is why we're sticking with a Debian 8 VM for now.
* 3D games will have a slow framerate, since QEMU only provides a limited, unaccelerated framebuffer for PPC<ref>Using the <code>-device ati-vga</code> QEMU option may bring an improvement at some point, but it's experimental and currently broken, especially with the old Debian 8 kernel.</ref>.
* '''3D games and audio content will be hard to debug''' on this environment, since QEMU only provides a limited, unaccelerated framebuffer, and no sound card support yet. Make sure that the ScummVM component you want to debug/test won't be impacted by this.
* '''The bigger your host CPU clock rate, the better''': a 4 GHz CPU will bring some improvement over a 3 GHz CPU, which is itself much better than a 2 GHz CPU, and so on<ref>For reference, a full build of ScummVM with only the SCUMM engine takes around 26 minutes in QEMU on an Intel i7 or an Apple M1, while the same build on a native PowerPC G4 7447A takes 13 minutes (all single-threaded).</ref>. Note that QEMU emulation is mostly single-threaded, so having many CPU cores isn't really useful for this.
* The bigger your CPU clock rate, the better: a 4 GHz CPU will bring noticeable improvement over a 3 GHz CPU, which is itself much better than a 2 GHz CPU, and so on. Note that QEMU emulation is mostly single-threaded, so having many CPU cores isn't really useful for this.


=== Starting the VM ===
=== Starting the VM ===
The VM image is quite large, so ask the rest of the team for its URL.


Once you've downloaded and extracted the VM archive, you'll need to install QEMU for your system with your usual package manager (Windows builds are available [https://qemu.weilnetz.de/w64/ here]).
Once you've downloaded and extracted the VM archive, you'll need to install QEMU for your system with your usual package manager (Windows builds are available [https://qemu.weilnetz.de/w64/ here]).
Line 47: Line 46:
-m 2048 ^
-m 2048 ^
-g 1024x750x32 ^
-g 1024x750x32 ^
-device ES1370 ^
-no-reboot ^
-no-reboot ^
-boot c ^
-boot c ^
Line 63: Line 63:
-m 2048 \
-m 2048 \
-g 1024x750x32 \
-g 1024x750x32 \
-device ES1370 \
-no-reboot \
-no-reboot \
-boot c \
-boot c \
Line 94: Line 95:
==== Build dependencies ====
==== Build dependencies ====


For development purposes, you may want to install the following set of tools, if you use them:
For development purposes, you may want to install the following set of tools, if they are useful for your use case (note that Valgrind is quite large, though):


<syntaxhighlight lang="shell">
<syntaxhighlight lang="shell">
Line 102: Line 103:
Compilers, GNU Make, GDB, Git and SDL development files are already installed in this image. The APT package manager is also pre-configured to use the older [https://www.debian.org/distrib/archive.en.html Debian 8 archive] files. Some Debian 8 GPG keys have expired since then, though, so APT will print some security warnings.
Compilers, GNU Make, GDB, Git and SDL development files are already installed in this image. The APT package manager is also pre-configured to use the older [https://www.debian.org/distrib/archive.en.html Debian 8 archive] files. Some Debian 8 GPG keys have expired since then, though, so APT will print some security warnings.


==== Running the <code>./configure</code> script ====
==== Building ====


Cloning the repository and compiling ScummVM is done through the [[Compiling_ScummVM/GCC|usual means]], with some important points:
Cloning the repository and compiling ScummVM is done through the [[Compiling_ScummVM/GCC|usual means]], with some important points:


* Everything is going to be slower than your usual environment; building ScummVM through <code>qemu-system-ppc</code> with only the SCUMM engine and no optimizations takes around 20 minutes with a 4.2 GHz Intel i7, for example.
* Everything is going to be slower than your usual environment.
* Since QEMU emulation is single-threaded, there is no point is running <code>make</code> with any <code>-j</code> flag for parallel compilation.
* Since QEMU emulation is single-threaded, there is no point is running <code>make</code> with any <code>-j</code> flag for parallel compilation.
* It is highly suggested to only enable the engines and features that you need for your test, e.g. <code>./configure --disable-detection-full --disable-all-engines --enable-engine=tinsel --disable-lua --disable-tinygl --disable-cloud --disable-hq-scalers --disable-optimizations --enable-debug</code> will save you a lot of time if you're only interested in testing the Tinsel engine.
* It is highly suggested to only enable the engines and features that you need for your test, e.g. <code>./configure --disable-detection-full --disable-all-engines --enable-engine=tinsel --disable-lua --disable-tinygl --disable-cloud --disable-hq-scalers --disable-optimizations --enable-debug</code> will save you a lot of time if you're only interested in testing the Tinsel engine.
Line 117: Line 118:


=== Various options for a more convenient setup ===
=== Various options for a more convenient setup ===
==== Unmuting audio ====
If you can't hear any sound, make sure that your QEMU run script has the <code>-device ES1370</code> option.
It's also possible that the emulated audio card is muted inside the Linux VM, for some reason. To fix this, start the Applications > Multimedia > Audio Mixer program and check that no main output is muted (you can also run the <code>alsamixer</code> program in the Terminal and type <code>M</code> and then <code>Esc</code> to unmute the main output).


==== Modern IDE integration ====
==== Modern IDE integration ====
Line 148: Line 155:


However, there are a few architectures which QEMU does not support, notably [https://en.wikipedia.org/wiki/SuperH SH]. However, there is another general purpose CPU/machine emulator called [http://gxemul.sourceforge.net/ GXemul] which does support this and some other more esoteric platforms. This is less supported than QEMU, but this procedure should be possible with some modifications. Any notes on this would be gratefully received by the team.
However, there are a few architectures which QEMU does not support, notably [https://en.wikipedia.org/wiki/SuperH SH]. However, there is another general purpose CPU/machine emulator called [http://gxemul.sourceforge.net/ GXemul] which does support this and some other more esoteric platforms. This is less supported than QEMU, but this procedure should be possible with some modifications. Any notes on this would be gratefully received by the team.
== Notes ==
<references />
151

edits