From eb37e8a20c9f94f8fa7d3d0011fbd3bbf7651d4e Mon Sep 17 00:00:00 2001 From: fslongjin Date: Sat, 15 Jan 2022 12:49:18 +0800 Subject: [PATCH] =?UTF-8?q?:tada:=20=E5=88=9B=E5=BB=BA=E4=BA=86boot?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ .idea/.gitignore | 8 ++++++ CMakeLists.txt | 6 +++++ bootloader/CMakeLists.txt | 9 +++++++ bootloader/boot.asm | 57 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 CMakeLists.txt create mode 100644 bootloader/CMakeLists.txt create mode 100644 bootloader/boot.asm diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..27aa8727 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/cmake-build-debug/ +/bin/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..fbaf0cd1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.20) +project(dragonOS C) + +set(CMAKE_C_STANDARD 11) +add_subdirectory(bootloader) + diff --git a/bootloader/CMakeLists.txt b/bootloader/CMakeLists.txt new file mode 100644 index 00000000..fb012ece --- /dev/null +++ b/bootloader/CMakeLists.txt @@ -0,0 +1,9 @@ +set(CMAKE_ASM_NASM_SOURCE_FILE_EXTENSIONS nasm asm S) +set(CMAKE_ASM_NASM_OBJECT_FORMAT bin) +set(CMAKE_ASM_NASM_FLAGS "-e") +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 diff --git a/bootloader/boot.asm b/bootloader/boot.asm new file mode 100644 index 00000000..97b55440 --- /dev/null +++ b/bootloader/boot.asm @@ -0,0 +1,57 @@ +;将程序开始位置设置为0x7c00处,并给BaseOfStack赋值为0x7c00 + org 0x7c00 + +BaseOfStack equ 0x7c00 + +Label_Start: + ;初始化寄存器 + mov ax, cs + mov ds, ax + mov es, ax + mov ss, ax + mov sp, BaseOfStack + + ;清屏 + mov ax, 0x0600 ;AL=0时,清屏,BX、CX、DX不起作用 + mov bx, 0x0700 ;设置白色字体,不闪烁,字体正常亮度,黑色背景 + mov cx, 0 + mov dx, 0184fh + int 10h + + ;设置屏幕光标位置为左上角(0,0)的位置 + mov ax, 0x0200 + mov bx, 0x0000 + mov dx, 0x0000 + int 10h + + ;在屏幕上显示Start Booting + mov ax, 0x1301 ;设置显示字符串,显示后,光标移到字符串末端 + mov bx, 0x000f ;设置黑色背景,白色字体,高亮度,不闪烁 + mov dx, 0x0000 ;设置游标行列号均为0 + mov cx, 10 ;设置字符串长度为10 + + ;为什么这里不能直接把ds赋值给es? + push ax + mov ax, ds + mov es, ax + pop ax + mov bp, StartBootMessage + int 10h + + ;软盘驱动器复位 + xor ah, ah + xor dl, dl + int 13h + + jmp $ + +StartBootMessage: db "Start Boot" + +;填满整个扇区的512字节 + times 510 - ( $ - $$ ) db 0 + dw 0xaa55 ;===确保以0x55 0xaa为结尾 + + + + +