From 51e5a0ffb87c44a18be9d6cd7e0de50dcaad97bf Mon Sep 17 00:00:00 2001 From: fslongjin Date: Mon, 17 Jan 2022 14:15:26 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20=E5=88=9B=E5=BB=BA=E4=BA=86loader.asm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bootloader/boot.asm | 8 +++++--- bootloader/loader.asm | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 bootloader/loader.asm diff --git a/bootloader/boot.asm b/bootloader/boot.asm index 32c765d3..f3c62d9b 100644 --- a/bootloader/boot.asm +++ b/bootloader/boot.asm @@ -48,7 +48,7 @@ Label_Start: mov bx, 0x0700 ;设置白色字体,不闪烁,字体正常亮度,黑色背景 mov cx, 0 mov dx, 0184fh - int 10h + int 0x10 ;设置屏幕光标位置为左上角(0,0)的位置 mov ax, 0x0200 @@ -60,7 +60,7 @@ Label_Start: mov ax, 0x1301 ;设置显示字符串,显示后,光标移到字符串末端 mov bx, 0x000a ;设置黑色背景,白色字体,高亮度,不闪烁 mov dx, 0x0000 ;设置游标行列号均为0 - mov cx, 24 ;设置字符串长度为20 + mov cx, 24 ;设置字符串长度为24 push ax mov ax, ds @@ -186,7 +186,9 @@ Label_Go_On_Loading_File: jmp Label_Go_On_Loading_File Label_File_Loaded: - jmp $ + ; 跳转到loader + ; 这个指令结束后,目标段会复制到CS寄存器中 + jmp BaseOfLoader:OffsetOfLoader ; 从软盘读取一个扇区 diff --git a/bootloader/loader.asm b/bootloader/loader.asm new file mode 100644 index 00000000..d18e62ed --- /dev/null +++ b/bootloader/loader.asm @@ -0,0 +1,33 @@ +; |==================| +; | 这是loader程序 | +; |==================| +; Created by longjin, 2022/01/17 + +; 由于实模式下,物理地址为CS<<4+IP,而从boot的定义中直到,loader的CS为0x1000, 因此loader首地址为0x10000 +org 0x10000 + mov ax, cs + mov ds, ax ; 初始化数据段寄存器 + mov es, ax ; 初始化附加段寄存器 + mov ax, 0x00 + mov ss, ax ;初始化堆栈段寄存器 + mov sp, 0x7c00 + + ;在屏幕上显示 start Loader + mov ax, 0x1301 + mov bx, 0x000f + mov dx, 0x0100 ;在第2行显示 + mov cx, 23 ;设置消息长度 + push ax + + mov ax, ds + mov es, ax + pop ax + mov bp, Message_Start_Loader + int 0x10 + + jmp $ + + +; 要显示的消息文本 +Message_Start_Loader: db "[DragonOS] Start Loader" +len_Message_Start_Loader: db 23