blob: 817718809ac73697bf82e20e693ef056c587f0b4 (
plain)
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
125
126
127
128
129
130
|
#!/bin/bash
USAGE="Usage: $0 [OPTION]...
-h --help Display this help dialog.
-c --check Enable memcheck leak detection. Requires -d gdb.
-d --debug <arg> Run with debugging support. 'gdb' will start gdb
and 'qemu' will start the qemu monitor.
-n --new-disk Use a fresh copy of the hard disk image.
"
# XXX hardcoding these temporarily -- should be read from the makefiles
KERN_DIR=kernel
ISO_IMAGE=weenix.iso
SYMBOLS=kernel.bin
GDB_COMM_INIT=commands.gdb
GDB_PREINIT=preinit.gdb
GDB_INIT=init.gdb
GDB_MEMCHECK=memcheck.gdb
GDBCOMM=gdb-commands
cd $(dirname $0)
dbgmode="run"
newdisk=
memcheck=
while (( "$#" )); do
case "$1" in
-h|--help) echo "$USAGE" >&2 ; exit 0 ;;
-c|--check) memcheck=1 ; shift ;;
-n|--new-disk) newdisk=1 ; shift ;;
-d|--debug) dbgmode="$2" ; shift 2 ;;
--) shift ;;
*) echo "Argument error." >&2 ; exit 2 ;;
esac
done
QEMU=qemu-system-x86_64
#if ! which $QEMU; then
#echo "Unable to find qemu." >&2
#exit 2
#fi
# QEMU=qemu/build/x86_64-softmmu/qemu-system-x86_64
QEMU_FLAGS="-k en-us -boot order=dca -device isa-debug-exit "
QEMU_FLAGS+="-drive format=raw,file=disk0.img "
QEMU_FLAGS+="-smp 4 -vga std -machine q35 "
#QEMU_FLAGS+="-chardev null,id=char0 "
#QEMU_FLAGS+="-device pci-serial,chardev=char0,id=d1 "
MEMCHECK_INIT=
if [[ -n "$memcheck" ]]
then
case $dbgmode in
gdb)
MEMCHECK_INIT="-x $GDB_MEMCHECK"
;;
*)
echo "memcheck is only supported with -d gdb" >&2
exit 2
;;
esac
fi
if [[ -n "$newdisk" || ! ( -f disk0.img ) ]]; then
cp -f user/disk0.img disk0.img
fi
MEMORY=1024
case $dbgmode in
run)
$QEMU $QEMU_FLAGS -m "$MEMORY" -cdrom "$KERN_DIR/$ISO_IMAGE" -serial stdio
;;
gdb)
# We recommend using GDB 8.1 or higher
# This path is used by default to ensure department machine compatibility
GDB=gdb
GDB_PORT=1234
GDB_TERM=xterm
if ! which $GDB; then
echo "Unable to find gdb." >&2
exit 2
fi
GDB_FLAGS="-x $GDB_PREINIT -s $KERN_DIR/$SYMBOLS -x $GDB_COMM_INIT $MEMCHECK_INIT -x $GDB_INIT"
rm -f "$GDB_COMM_INIT"
cat "$KERN_DIR/$GDBCOMM" | grep -E ".(gdb|py)$" | while read file
do
echo "source $file" >> "$GDB_COMM_INIT"
done
#$QEMU $QEMU_FLAGS -m "$MEMORY" -cdrom "$KERN_DIR/$ISO_IMAGE" -s -S -daemonize &
xterm -e $QEMU $QEMU_FLAGS -m "$MEMORY" -cdrom "$KERN_DIR/$ISO_IMAGE" -serial stdio -s -S &
$GDB $GDB_FLAGS
;;
gdb-only)
# We recommend using GDB 8.1 or higher
# This path is used by default to ensure department machine compatibility
GDB=gdb
GDB_PORT=1234
GDB_TERM=xterm
if ! which $GDB; then
echo "Unable to find gdb." >&2
exit 2
fi
GDB_FLAGS="-x $GDB_PREINIT -s $KERN_DIR/$SYMBOLS -x $GDB_COMM_INIT $MEMCHECK_INIT -x $GDB_INIT"
rm -f "$GDB_COMM_INIT"
cat "$KERN_DIR/$GDBCOMM" | grep -E ".(gdb|py)$" | while read file
do
echo "source $file" >> "$GDB_COMM_INIT"
done
$QEMU $QEMU_FLAGS -m "$MEMORY" -cdrom "$KERN_DIR/$ISO_IMAGE" -s -S -daemonize &
$GDB $GDB_FLAGS
;;
qemu)
$QEMU $QEMU_FLAGS -m "$MEMORY" -cdrom "$KERN_DIR/$ISO_IMAGE" -monitor stdio
;;
*)
echo "'$dbgmode' is an unknown debug mode." >&2
echo "Valid modes: gdb" >&2
echo "$USAGE" >&2
exit 1
;;
esac
|