-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrunfoo
executable file
·62 lines (58 loc) · 1.81 KB
/
runfoo
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
#!/bin/bash
die() { echo "$*"; exit 1; }
QEMU_BIN=${QEMU_BIN:-qemu-system-i386}
DISPLAY_OPTS=${DISPLAY_OPTS:--nographic}
DISABLE_KVM=${DISABLE_KVM:-}
[ "${1}" ] || die "Usage: $0 PROG [ARG...]"
case ${FOO_MODE:-qemu} in
qemu)
(
sleep 0.1
tries=0
while ! exec 3<> /dev/tcp/localhost/21118; do
sleep 0.5
tries=$(( tries + 1 ))
[ "${tries}" -gt 10 ] && die "Could not connect to qemu"
done
while read -u 3 -r cmd arg1; do
case ${cmd} in
read:)
if [ -r "${arg1}" ]; then
echo "fdata: $(stat --printf="%s" ${arg1})" >&3
cat >&3 ${arg1}
else
echo "error: Could not read file ${arg1}" >&3
fi
;;
size:)
if [ -r "${arg1}" ]; then
echo "fdata: $(stat --printf="%s" ${arg1})" >&3
else
echo "error: Could not stat file ${arg1}" >&3
fi
;;
*)
echo >&2 "Unknown socket command: $cmd"
;;
esac
done
) &
bin=$1; shift
opts="${DISPLAY_OPTS}"
[ "${DISABLE_KVM}" ] || opts="${opts} --enable-kvm"
[ "${GDB}" ] && opts="${opts} -s -S"
set -x
${QEMU_BIN} \
${opts} \
-monitor none \
-serial stdio \
-serial tcp:localhost:21118,server \
-device isa-debug-exit,iobase=0xf4,iosize=0x04 \
-kernel ${bin} \
${@:+-append "${*}"}
exit $(( $? / 2 ))
;;
*)
$1 "${@}"
;;
esac