-
Notifications
You must be signed in to change notification settings - Fork 0
Building QEMU
Install all necessary prerequisites which are necessary for building QEMU: https://wiki.qemu.org/Hosts/Linux. Then prepare sources and a build directory:
git clone https://github.com/foss-for-synopsys-dwc-arc-processors/qemu
mkdir -p qemu/build
cd qemu/build
Configure QEMU (use your own --prefix
value):
../configure --target-list=arc-softmmu,arc64-softmmu,arc-linux-user,arc64-linux-user \
--enable-debug --enable-debug-tcg --prefix=/tools/qemu
Build an install:
make
make install
Configure your environment:
export QEMU_HOME="/tools/qemu"
export PATH="${QEMU_HOME}/bin:$PATH"
(From https://github.com/foss-for-synopsys-dwc-arc-processors/qemu/wiki/Building-QEMU-for-ARC, https://github.com/foss-for-synopsys-dwc-arc-processors/qemu/wiki/QEMU-and-Zephyr, https://github.com/foss-for-synopsys-dwc-arc-processors/qemu/wiki/QEMU-traces, https://github.com/foss-for-synopsys-dwc-arc-processors/qemu/wiki/Tips-and-Tricks-for-Troubleshooting)
ℹ️ Refer to the official documentation for details.
sudo pacman -S git cmake ninja gperf ccache dfu-util dtc wget \
python-pip python-setuptools python-wheel xz file make
sudo dnf group install "Development Tools" "C Development Tools and Libraries"
dnf install git cmake ninja-build gperf ccache dfu-util dtc wget \
python3-pip xz file glibc-devel.i686 libstdc++-devel.i686
sudo apt-get install --no-install-recommends git cmake ninja-build gperf \
ccache dfu-util device-tree-compiler wget \
python3-pip python3-setuptools python3-wheel \
xz-utils file make gcc gcc-multilib
sudo xbps-install git cmake ninja gperf ccache dfu-util dtc wget \
python3-pip python3-setuptools python3-wheel xz \
file make
Clone the repo into your source folder with git clone https://github.com/foss-for-synopsys-dwc-arc-processors/qemu.git
In a separate build folder, configure QEMU. A common configuration follows:
./configure --target-list=arc-softmmu,arc64-softmmu,arc-linux-user,arc64-linux-user \ # QEMU ARC targets
--prefix=/PATH/TO/INSTALL/QEMU \ # where you want it installed
--enable-debug \ # for developers
--enable-debug-tcg \ # for developers
--enable-trace-backends=simple \ # for developers
--disable-plugins \ # for developers
--skip-meson \ # Do not run meson on every build
--disable-werror \ # in case QEMU emits unexpected warnings
--disable-pie \ # needed for older GCCs (like CentOS 7)
--enable-trace-backends=simple # for the tracing backends mentioned further ahead
To enable TCG testing, the arc-elf32-gcc
and arc64-elf-gcc
compilers must be available during configuration, and the following two arguments added to the command above
--cross-cc-arc=arc-elf32-gcc --cross-cc-arc64=arc64-elf-gcc
make
make install
QEMU provides several tools to debug both itself and the binary being executed.
QEMU has a GDBstub with which it allows an external GDB instance to connect directly to the running executable. See more information about this in here.
If you require full system emulation, the GLibC tests show how to launch these and debug the running executable without having to the debug the whole kernel.
Sometimes it is useful to get more information from the simulator than the one GDB has access to. There are a few ways to obtain more information.
To enable logging, it is necessary to provide the enabled log levels with the -d
flag. Some of the more relevant ones are:
in_asm show target assembly code for each compiled TB
nochain do not chain compiled TBs so that "exec" and "cpu" show complete traces
exec show trace before each executed TB (lots of logs)
cpu show CPU registers before entering a TB (lots of logs)
fpu include FPU registers in the 'cpu' logging
int show interrupts/exceptions in short format
mmu log MMU-related activities
unimp log unimplemented functionality
To get a complete listing, run qemu-system-arc -d help
Use -D <logfile>
to dump the logs into a file instead of stdout.
QEMU provides a tracing infrastructure which may help in debugging or analyzing what happens within a simulation cycle. At this moment, there are two tracers added into ARC backend, one for MMU operations, and the other for exceptions:
# mmu.c
mmu_command(uint32_t address, const char *command, uint32_t pd0, uint32_t pd1) "[MMU] at 0x%08x, CMD=%s, PD0=0x%08x, PD1=0x%08x"
# helper.c
excp_info(uint32_t address, const char *name) "[IRQ] at 0x08, Exception=%s"
To run this tracing:
- Build with the
--enable-trace-backends=simple
configure parameter: - Create a file with the events you want to trace. For example:
$ cat > events.trc << 'EOF'
mmu_command
excp_info
EOF
- Run the virtual machine to produce a trace file:
qemu-system-arc --trace events=events.trc ... # your normal QEMU invocation
- Pretty-print the binary trace file:
$QEMU_SRC/scripts/simpletrace.py $QEMU_SRC/target/arc/trace-events trace-* # Override * with QEMU <pid>
Testing using QEMU as the simulator can be done in multiple ways. The currently configured testsuits are:
In general, the most transparent way is by using usermode emulation with binfmt for seamless execution. This is what is used in some of the GLibC tests mentioned above.
TCG is the internal language that powers QEMU.
There are some assembly tests that validate the basic function of several instructions in QEMU.
To run these, make sure that the compilers specified in '--cross-cc-arc' and '--cross-cc-arc64' are available during build time and when running the commands below:
make clean-tcg
make build-tcg
make check-tcg