[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / lldb / scripts / lldb-test-qemu / run-qemu.sh
blob6dca03aab28e2b72be7f97ca8df9a4ccaaa2ee65
1 #!/bin/bash
3 print_usage() {
4 echo "Usage: $(basename $0) --arch [arm|arm64] [options]"
5 echo -e "Starts QEMU system mode emulation for the architecture.\n"
6 echo -e " --help\t\t\tDisplay this information."
7 echo -e " --arch {arm|arm64}\t\tSelects architecture QEMU system emulation."
8 echo -e " --sve\t\t\t\tEnables AArch64 SVE mode."
9 echo -e " --mte\t\t\t\tEnables AArch64 MTE mode."
10 echo -e " --sme\t\t\t\tEnables AArch64 SME mode."
11 echo -e " --rootfs {path}\t\tPath of root file system image."
12 echo -e " --qemu {path}\t\t\tPath of pre-installed qemu-system-* executable."
13 echo -e " --kernel {path}\t\tPath of Linux kernel prebuilt image.\n"
14 echo -e "By default this utility will use:"
15 echo -e " QEMU image built from source in qemu.git directory"
16 echo -e " Linux kernel image from linux.build/(arm or arm64) directory."
17 echo -e "Custom Linux kernel image or QEMU binary can be provided using commandline."
18 exit "$1"
21 invalid_arg() {
22 echo "ERROR: Unrecognized argument: $1" >&2
23 print_usage 1
26 run_qemu() {
27 QEMU_CORES=2
28 QEMU_MEMORY=1024
30 $QEMU_BIN \
31 -cpu $QEMU_CPU \
32 -m $QEMU_MEMORY \
33 -smp $QEMU_CORES \
34 -kernel $KERNEL_IMG \
35 -machine $QEMU_MACHINE \
36 -drive file=$ROOTFS_IMG,if=none,format=raw,id=hd0 \
37 -device virtio-blk-device,drive=hd0 \
38 -append "root=/dev/vda rw ip=dhcp mem=1024M raid=noautodetect \
39 crashkernel=128M rootwait console=ttyAMA0 devtmpfs.mount=0" \
40 -netdev type=tap,id=net0 \
41 -device virtio-net-device,netdev=net0 \
42 -nographic
45 # Parse options
46 while [[ $# -gt 0 ]]; do
47 case "${END_OF_OPT}${1}" in
48 --arch) ARCH=$2; shift;;
49 --rootfs) ROOTFS_IMG=$2; shift;;
50 --kernel) KERNEL_IMG=$2; shift;;
51 --qemu) QEMU_BIN=$2; shift;;
52 --sve) SVE=1;;
53 --mte) MTE=1;;
54 --sme) SME=1;;
55 --help) print_usage 0 ;;
56 *) invalid_arg "$1" ;;
57 esac
58 shift
59 done
61 if [ "$ARCH" == "arm64" ] && [ "$ARCH" == "arm" ]; then
62 echo "Invalid architecture: $ARCH"
63 print_usage 1
66 if [[ ! -f "$ROOTFS_IMG" ]]; then
67 echo "No root file system image image available for emulation."
68 exit
71 if [[ ! -f "$KERNEL_IMG" ]]; then
72 KERNEL_IMG_PATH=$(pwd)/linux.build/"$ARCH"/arch/"$ARCH"/boot/
74 if [[ ! -d "$KERNEL_IMG_PATH" ]]; then
75 echo "No Linux kernel image available for emulation."
76 exit
79 if [[ "$ARCH" == "arm" ]]; then
80 KERNEL_IMG=$KERNEL_IMG_PATH/zImage
81 elif [[ "$ARCH" == "arm64" ]]; then
82 KERNEL_IMG=$KERNEL_IMG_PATH/Image
86 if [[ ! -f "$QEMU_BIN" ]]; then
87 if [[ "$ARCH" == "arm" ]]; then
88 QEMU_BIN=$(pwd)/qemu.git/arm-softmmu/qemu-system-arm
89 elif [[ "$ARCH" == "arm64" ]]; then
90 QEMU_BIN=$(pwd)/qemu.git/aarch64-softmmu/qemu-system-aarch64
93 if [[ ! -f "$QEMU_BIN" ]]; then
94 echo "QEMU $ARCH system emulation executable not found."
95 exit
99 if [[ "$ARCH" == "arm" ]]; then
100 QEMU_MACHINE="virt,highmem=off"
101 QEMU_CPU="cortex-a15"
103 if [[ $SVE ]]; then
104 echo "warning: --sve is supported by AArch64 targets only"
106 if [[ $MTE ]]; then
107 echo "warning: --mte is supported by AArch64 targets only"
109 if [[ $SME ]]; then
110 echo "warning: --sme is supported by AArch64 targets only"
112 elif [[ "$ARCH" == "arm64" ]]; then
113 QEMU_MACHINE=virt
114 QEMU_SVE_MAX_VQ=4
115 QEMU_CPU="cortex-a53"
117 if [[ $SVE ]] || [[ $MTE ]] || [[ $SME ]]; then
118 QEMU_CPU="max"
121 if [[ $SVE ]] || [[ $SME ]]; then
122 QEMU_CPU="$QEMU_CPU,sve-max-vq=$QEMU_SVE_MAX_VQ"
124 if [[ $MTE ]]; then
125 QEMU_MACHINE="$QEMU_MACHINE,mte=on"
129 run_qemu