From c7cc246652da3785ee84e1e3262af8b7ad4c5af9 Mon Sep 17 00:00:00 2001 From: fslongjin Date: Mon, 17 Jan 2022 14:15:50 +0800 Subject: [PATCH] =?UTF-8?q?:wrench:=20=E5=AE=8C=E5=96=84=E4=BA=86=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E8=84=9A=E6=9C=AC=EF=BC=8C=E5=8A=A0=E5=85=A5=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=A3=80=E6=9F=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootloader/CMakeLists.txt | 5 ++-- run_in_qemu.sh | 62 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/bootloader/CMakeLists.txt b/bootloader/CMakeLists.txt index fb012ece..f5b77372 100644 --- a/bootloader/CMakeLists.txt +++ b/bootloader/CMakeLists.txt @@ -5,5 +5,6 @@ set(CMAKE_ASM_NASM_LINK_EXECUTABLE "nasm -o " enable_language(ASM_NASM) #修改输出的路径 -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) -add_executable(boot.bin boot.asm) \ No newline at end of file +set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin/bootloader) +add_executable(boot.bin boot.asm) +add_executable(loader.bin loader.asm) \ No newline at end of file diff --git a/run_in_qemu.sh b/run_in_qemu.sh index 4dee2793..4ad1f858 100644 --- a/run_in_qemu.sh +++ b/run_in_qemu.sh @@ -1,3 +1,61 @@ +# ==============检查文件是否齐全================ +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/boot.bin of=bin/boot.img bs=512 count=1 conv=notrunc -qemu-system-x86_64 -s -S -m 2048 -fda bin/boot.img \ No newline at end of file +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到tmp/boot + mkdir tmp/boot + sudo 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 + sudo cp bin/bootloader/loader.bin tmp/boot + sync + sudo umount tmp/boot + else + echo "挂载 boot.img 失败!" + fi + + + +# 运行结束后删除tmp文件夹 +sudo 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 + qemu-system-x86_64 -s -S -m 2048 -fda bin/boot.img +else + echo "不满足运行条件" +fi \ No newline at end of file