-
Notifications
You must be signed in to change notification settings - Fork 0
/
emul
executable file
·96 lines (79 loc) · 2.12 KB
/
emul
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
#!/usr/bin/env bash
if [[ -z ${TOOLCHAIN+x} ]]; then
echo TOOLCHAIN is not set. Please source activate
exit 1
fi
function print_help() {
cat << EOF
emul [-gvdh]
Runs emulator
-g
Run with graphics window
Can also be invoked by setting EMULGFX
-v
Run in vnc mode
Can also be invoked by setting EMULVNC
Open a listening client to port 5909 to connect
-d
DON'T run gdb debugger
Can also be invoked by setting EMULNDEBUG
-h
Display help message
EOF
}
function main() {
EMULGFX="${EMULGFX+x}"
EMULVNC="${EMULVNC+x}"
EMULNDEBUG="${EMULNDEBUG+x}"
local monitorwin=""
while getopts "gvdh" OPTION; do
case ${OPTION} in
g)
readonly EMULGFX=1
;;
v)
readonly EMULVNC=1
;;
d)
readonly EMULNDEBUG=1
;;
h)
print_help
exit 0
;;
esac
done
[[ $1 = "--" ]] && shift
EMULPARAM=("$@")
make all || exit 1
util/build_iso.sh || exit 1
echo > serial.log
emulator="qemu-system-x86_64 -hda image.img -cdrom mittos64.iso -boot order=d -serial file:serial.log -smp 4 ${EMULPARAM[@]}"
debugger=$(which x86_64-elf-linux-gdb)
if [[ (-n ${EMULVNC}) ]]; then
# A bug in qemu means the reverse port does not work as written in the man pages
# :X,reverse will open a reverse connection on DISPLAY X, not PORT X
# i.e. PORT 5900+X
emulator="${emulator} -vnc :9,reverse"
fi
if [[ (-n ${EMULVNC}) || (-n ${EMULGFX}) ]]; then
emulator="${emulator} -monitor stdio"
fi
if [[ (-z ${EMULNDEBUG}) ]]; then
emulator="${emulator} -s -S"
fi
if [[ (-z ${EMULVNC}) && (-z ${EMULGFX}) && (-n "${TMUX+x}") ]]; then
emulator="${emulator} -curses"
fi
if [[ -n "${TMUX}" ]]; then
emulwindow=`tmux new-window -P -n "osdevemul" "${emulator} 2>qemu-error.log; tmux kill-window -t osdevemul"`
if [[ -z ${EMULNDEBUG} ]]; then
debugpane=`tmux split-window -P -h -t ${emulwindow} "sleep 1; ${debugger}"`
fi
serialpane=`tmux split-window -P -v -t ${emulwindow} "tail -f serial.log | util/colorize.sh"`
tmux select-pane -l
else
${emulator}
fi
}
main "${@}"