Files
my-kern/launch-qemu.sh
2022-09-01 20:45:40 +02:00

69 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
ARGS=""
KERNEL="-kernel cmake-build-debug/my-kernel.bin"
NOHUP=0
function print_help() {
cat <<EOF
Usage: $0 [OPTION]...
Options:
-h, --help Print help info
-d, --debug Start qemu with halted cpu and GDB port 1234 open. Also print guest errors and interrupts
-i [disk], --ide [disk] Use [disk] as a hda on an IDE bus
-n, --nohup Run QEMU using nohup and output to /dev/null
-m, --max-cpu Run qemu with -m max
--net Launch the kernel using TFTP. (Requires GRUB to be set up)
EOF
}
while [[ "$#" -gt 0 ]]; do
key=$1
case $key in
-d | --debug)
ARGS="${ARGS} -S -s -d guest_errors,int"
shift
;;
--net)
cp cmake-build-debug/my-kernel.bin netdir/my-kernel.bin
KERNEL="-netdev user,id=n0,tftp=netdir,bootfile=/boot/grub/i386-pc/core.0 -device e1000,netdev=n0,bootindex=1"
shift
;;
-i | --ide)
ARGS="${ARGS} -hda $2"
shift 2
;;
-s | --sata)
ARGS="${ARGS} -drive id=disk1,file=$2,if=none -device ahci,id=ahci -device ide-drive,drive=disk1,bus=ahci.0"
shift 2
;;
--virtio)
ARGS="$ARGS -drive id=disk1,file=$2,if=virtio"
shift 2
;;
-m | --max-cpu)
ARGS="${ARGS} -cpu max"
shift
;;
-n | --nophup)
NOHUP=1
shift
;;
-h | --help)
print_help
exit
;;
esac
done
echo "Launching with args ${ARGS} ${KERNEL}"
if [ "$NOHUP" -gt 0 ]; then
# shellcheck disable=SC2086
nohup qemu-system-i386 ${ARGS} ${KERNEL} >/dev/null &
disown
else
# shellcheck disable=SC2086
qemu-system-i386 ${ARGS} ${KERNEL}
fi