-
Notifications
You must be signed in to change notification settings - Fork 1
/
qemu.sh
executable file
·72 lines (61 loc) · 1.59 KB
/
qemu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/bash
set -e
script="$0"
function usage() {
echo "Usage: $script [options] executable" >&2
echo "Options:" >&2
echo " -d: launch a debugger" >&2
echo " -n: disable graphical output" >&2
echo " -q: pass an option through to qemu" >&2
exit 1
}
function exists() {
command -v "$1" > /dev/null
}
declare -a options
declare -a binaries
file=
debug=0
nox=0
while [ ! -z "$1" ]; do
while getopts "dnq:" o; do
case "$o" in
d)
debug=1
;;
n)
nox=1
;;
q)
shift
options+=("$OPTARG")
;;
esac
done
shift $((OPTIND-1))
[ -z "$1" ] || { [ -z "$file" ] && file=$1 || binaries+=("$1"); } || usage
OPTIND=2
done
[ -z "$file" ] && usage
image="$file.img"
./mkimage.sh -i "$file" -o "$image" "${binaries[@]}"
options+=(-drive "format=raw,media=disk,index=0,file=$image" -serial mon:stdio -L "$(dirname "$script")/qemu_roms")
if [ $nox -eq 1 ]; then
options+=(-nographic)
fi
if [ $debug -eq 1 ]; then
let port=$RANDOM+1024
options+=(-S -gdb tcp::$port)
if exists rust-lldb; then
debugger=(rust-lldb $file -o "gdb-remote $port")
elif exists lldb; then
debugger=(lldb $file -o "gdb-remote $port")
elif exists gdb; then
debugger=(gdb $file -ex "target remote localhost:$port")
else
echo "error: could not find lldb or gdb" >&2
exit 1
fi
setsid qemu-system-i386 "${options[@]}" & "${debugger[@]}"
fi
qemu-system-i386 "${options[@]}"