-
-
Notifications
You must be signed in to change notification settings - Fork 417
/
run.sh
94 lines (84 loc) · 2.55 KB
/
run.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
#!/bin/bash
# This file is a part of Simple-XX/SimpleKernel
# (https://github.com/Simple-XX/SimpleKernel).
#
# run.sh for Simple-XX/SimpleKernel.
# 在虚拟机中运行内核
# shell 执行出错时终止运行
set -e
# 输出实际执行内容
#set -x
source ./tools/env.sh
export PATH="${GRUB_PATH}:$PATH"
# 重新编译
mkdir -p ./build_${ARCH}/
rm -rf ./build_${ARCH}/*
cd ./build_${ARCH}
cmake -DCMAKE_TOOLCHAIN_FILE=./cmake/${TOOLS} -DARCH=${ARCH} -DCMAKE_BUILD_TYPE=DEBUG ..
make
cd ../
# 如果是 i386/x86_64,需要判断是否符合 multiboot2 标准
if [ ${ARCH} == "i386" ] || [ ${ARCH} == "x86_64" ]; then
if ${GRUB_PATH}/grub-file --is-x86-multiboot2 ${kernel}; then
echo Multiboot2 Confirmed!
else
echo NOT Multiboot2!
exit
fi
fi
# 如果是 riscv 64,需要使用 opensbi
if [ ${ARCH} == "riscv64" ]; then
# OPENSBI 不存在则编译
if [ ! -f ${OPENSBI} ]; then
echo build opensbi.
cd ./tools/opensbi
mkdir -p build
export CROSS_COMPILE=${TOOLCHAIN_PREFIX}
export FW_JUMP=y
export FW_JUMP_ADDR=0x80200000
export PLATFORM_RISCV_XLEN=64
export PLATFORM=generic
make
cd ../..
echo build opensbi done.
fi
fi
# 检测路径是否合法,发生过 rm -rf -f /* 的惨剧
if [ "${iso_boot}" == "" ]; then
echo iso_boot path error.
else
mkdir -p ${iso_boot}
rm -rf -f ${iso_boot}/*
fi
# 初始化 gdb
if [ ${DEBUG} == 1 ]; then
cp ./tools/gdbinit ./.gdbinit
echo "" >> ./.gdbinit
echo "file "${kernel} >> ./.gdbinit
if [ ${ARCH} == "riscv64" ]; then
echo "add-symbol-file "${OPENSBI} >> ./.gdbinit
fi
echo "target remote localhost:1234" >> ./.gdbinit
GDB_OPT='-S -gdb tcp::1234'
echo "Run gdb-multiarch in another shell"
fi
# 设置 grub 相关数据
if [ ${ARCH} == "i386" ] || [ ${ARCH} == "x86_64" ]; then
mkdir -p ${iso_boot_grub}
cp ${kernel} ${iso_boot}
cp ./tools/grub.cfg ${iso_boot_grub}/
fi
# 运行虚拟机
if [ ${ARCH} == "i386" ] || [ ${ARCH} == "x86_64" ]; then
qemu-system-x86_64 -cdrom ${iso} -m 128M \
-monitor telnet::2333,server,nowait -serial stdio \
${GDB_OPT}
elif [ ${ARCH} == "aarch64" ]; then
qemu-system-aarch64 -machine virt -cpu cortex-a72 -kernel ${kernel} \
-monitor telnet::2333,server,nowait -serial stdio -nographic \
${GDB_OPT}
elif [ ${ARCH} == "riscv64" ]; then
qemu-system-riscv64 -machine virt -bios ${OPENSBI} -kernel ${kernel} \
-monitor telnet::2333,server,nowait -serial stdio -nographic \
${GDB_OPT}
fi