🔧 更改为使用bochs虚拟机(qemu暂时没法正常显示画面)

This commit is contained in:
fslongjin
2022-01-21 22:04:24 +08:00
parent f479f32102
commit 3d37bf9c3a
5 changed files with 119 additions and 6 deletions

79
run_in_bochs.sh Normal file
View File

@ -0,0 +1,79 @@
# ======检查是否以sudo运行=================
uid=`id -u`
if [ ! $uid == "0" ];then
echo "请以sudo权限运行"
exit
fi
# 第一个参数如果是--notbuild 那就不构建,直接运行
if [ ! "$1" == "--nobuild" ]; then
echo "开始构建..."
make all
make clean
fi
# ==============检查文件是否齐全================
if [ ! -x "bin/bootloader/boot.bin" ]; then
echo "bin/bootloader/boot.bin 不存在!"
exit
fi
if [ ! -x "bin/bootloader/loader.bin" ]; then
echo "bin/bootloader/loader.bin 不存在!"
exit
fi
if [ ! -x "bin/boot.img" ]; then
echo "bin/boot.img 不存在!"
exit
fi
# ===============文件检查完毕===================
# =========将引导程序写入boot.img=============
dd if=bin/bootloader/boot.bin of=bin/boot.img bs=512 count=1 conv=notrunc
# =========创建临时文件夹==================
# 判断临时文件夹是否存在,若不存在则创建新的
if [ ! -d "tmp/" ]; then
mkdir tmp/
echo "创建了tmp文件夹"
fi
# ==============挂载boot.img=============
mkdir tmp/boot
mount bin/boot.img tmp/boot -t vfat -o loop
# 检查是否挂载成功
if mountpoint -q tmp/boot
then
echo "成功挂载 boot.img 到 tmp/boot"
# ========把loader.bin复制到boot.img==========
cp bin/bootloader/loader.bin tmp/boot
# ========把内核程序复制到boot.img======
cp bin/kernel/kernel.bin tmp/boot
sync
# 卸载磁盘
umount tmp/boot
else
echo "挂载 boot.img 失败!"
fi
# 运行结束后删除tmp文件夹
rm -rf tmp
# 进行启动前检查
flag_can_run=0
if [ -d "tmp/" ]; then
flag_can_run=0
echo "tmp文件夹未删除"
else
flag_can_run=1
fi
if [ $flag_can_run -eq 1 ]; then
bochs -f ./bochsrc -q
else
echo "不满足运行条件"
fi