-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_rust.sh
executable file
·124 lines (101 loc) · 3.31 KB
/
start_rust.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/bin/sh
usage() { echo "USAGE: sh $0 [OPTIONS]
OPTIONS:
-h display help
-b <resultfile> benchmark mode: write timestamp ID to the given file once qemu exits
-d debug mode: preserve qemu display
-e <path/to/binary> boot from the given Rust kernel binary
(default is rust-kernel/test_os/target/x86_64-test_os/release/bootimage-test_os.bin)
-i <path/to/image> original image file path
-m <memory> run qemu with the given memory amount as maximum (default 128M)
-o <outfilename> write start and end timestamps as well as any serial output to the given output file
-p <outdir> write output file to the given directory
-t <path/to/thumbnail> write thumbnail to the given file path
" 1>&2; exit 1; }
BENCHFILE=
BIN="rust-kernel/test_os/target/x86_64-test_os/release/bootimage-test_os.bin"
OUTFILE=
OUTDIR=
NODISP="-display none"
MEMORY=
IMAGE=
THUMBNAIL=
while getopts ":hb:de:i:m:o:p:t:" OPT; do
case "$OPT" in
h)
usage
;;
b)
BENCHFILE="$OPTARG"
;;
e)
BIN="$OPTARG"
;;
d)
NODISP=
;;
i)
IMAGE="$OPTARG"
;;
m)
MEMORY="-m $OPTARG"
;;
o)
OUTFILE="$OPTARG"
;;
p)
OUTDIR="$OPTARG"
;;
t)
THUMBNAIL="$OPTARG"
;;
*)
echo "ERROR: unknown option: $OPT"
usage
;;
esac
done
shift $((OPTIND - 1)) # isolate remaining args
[ -f "$BIN" ] || { echo "ERROR: binary does not exist: $BIN"; exit 1; }
[ -n "$IMAGE" ] || { echo "ERROR: missing required argument: -i <path/to/image>"; usage; }
[ -f "$IMAGE" ] || { echo "ERROR: image file does not exist: $IMAGE"; exit 1; }
TS="$(date +%s%N)" # get current time in nanoseconds -- good enough for unique timestamp
NAME="rust-$TS"
[ -n "$OUTFILE" ] || OUTFILE="$NAME.output"
[ -n "$THUMBNAIL" ] || THUMBNAIL="$NAME.png"
[ -n "$OUTDIR" ] && mkdir -p "$OUTDIR" || OUTDIR="."
OUTFILE="$OUTDIR/$OUTFILE"
THUMBNAIL="$OUTDIR/$THUMBNAIL"
NAMEDPIPE="/tmp/$NAME"
mkfifo "$NAMEDPIPE.in" "$NAMEDPIPE.out" # create I/O pipes
PIPE="-serial pipe:$NAMEDPIPE"
##### DEFINE FUNCTIONS FOR I/O #####
send_image () {
echo "beginbeginbeginbeginbeginbegin" > "$NAMEDPIPE.in"
# send a few bytes to trigger serial interrupts
# if qemu is not finished booting, at least one of these will need to be
# consumed by the kernel, which ensures the kernel reads all the png data
cat "$1" > "$NAMEDPIPE.in"
}
receive_image () {
cat "$NAMEDPIPE.out" > "$1"
}
##### SEND AND RECEIVE DATA FROM SERIAL PORT #####
send_image "$IMAGE" &
receive_image "$THUMBNAIL" &
##### BEGIN RUNNING QEMU #####
# 0xf4 is used to communicate exit codes to qemu
/usr/bin/time -o "$OUTFILE" --append --portability qemu-system-x86_64 \
-drive format=raw,file="$BIN" -smp 1 \
-snapshot \
-no-reboot \
-device isa-debug-exit,iobase=0xf4,iosize=0x04 \
$PIPE \
$MEMORY \
$NODISP
if [ $? -eq 33 ]; then
[ -n "$BENCHFILE" ] && echo "$TS" >> "$BENCHFILE"
else
echo "rust instance failed"
fi
rm "$NAMEDPIPE.in" "$NAMEDPIPE.out" # remove pipes