-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_os.sh
More file actions
executable file
·80 lines (65 loc) · 1.99 KB
/
run_os.sh
File metadata and controls
executable file
·80 lines (65 loc) · 1.99 KB
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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="${SCRIPT_DIR}"
BUILD_DIR="${ROOT_DIR}/build"
KERNEL_ELF="${BUILD_DIR}/thunderos.elf"
FS_IMG="${BUILD_DIR}/fs.img"
QEMU_ACCEL_FLAGS_DEFAULT="-accel tcg,thread=multi"
find_qemu() {
if [[ -n "${QEMU_BIN:-}" ]]; then
if [[ -x "${QEMU_BIN}" ]]; then
printf '%s\n' "${QEMU_BIN}"
return 0
fi
echo "ERROR: QEMU_BIN is set but not executable: ${QEMU_BIN}" >&2
exit 1
fi
if command -v qemu-system-riscv64 >/dev/null 2>&1; then
printf '%s\n' "qemu-system-riscv64"
return 0
fi
if [[ -x /tmp/qemu-10.1.2/build/qemu-system-riscv64 ]]; then
printf '%s\n' "/tmp/qemu-10.1.2/build/qemu-system-riscv64"
return 0
fi
echo "ERROR: qemu-system-riscv64 not found. Install QEMU 10.1.2+ or set QEMU_BIN." >&2
exit 1
}
require_artifact() {
local path="$1"
local label="$2"
if [[ -f "${path}" ]]; then
return 0
fi
echo "ERROR: Missing ${label}: ${path}" >&2
echo "Build ThunderOS first with ./build_os.sh or make qemu." >&2
exit 1
}
main() {
local qemu_bin
local accel_flags
local extra_flags
qemu_bin="$(find_qemu)"
require_artifact "${KERNEL_ELF}" "kernel ELF"
require_artifact "${FS_IMG}" "filesystem image"
accel_flags="${QEMU_ACCEL_FLAGS:-${QEMU_ACCEL_FLAGS_DEFAULT}}"
extra_flags="${QEMU_EXTRA_FLAGS:-}"
echo "Starting ThunderOS with ${qemu_bin}"
echo " Kernel: ${KERNEL_ELF}"
echo " Disk: ${FS_IMG}"
echo " QEMU: ${accel_flags} ${extra_flags}"
exec "${qemu_bin}" \
-machine virt \
-m 128M \
-nographic \
-serial mon:stdio \
-bios none \
${accel_flags} \
-kernel "${KERNEL_ELF}" \
-global virtio-mmio.force-legacy=false \
${extra_flags} \
-drive file="${FS_IMG}",if=none,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0
}
main "$@"