coreBugZJ

此 blog 已弃。

引导并加载Loader,进入Loader执行



config.inc
 1%ifndef  __CONFIG_INC_INCLUDED__
 2%define  __CONFIG_INC_INCLUDED__
 3
 4
 5; 全局配置属性,针对汇编语言部分
 6
 7
 8; boot-loader-kernel 在引导盘中,内存中都连续分布
 9; 各自占用的扇区数量
10
11LOADER_SECTOR_NUM : equ 0x8
12KERNEL_SECTOR_NUM : equ 0x100
13
14
15%endif
16
17

boot/boot.s
 1%include "../config.inc"
 2%include "boot_const.inc"
 3
 4org 0x7c00
 5        jmp BOOT_BEGIN
 6
 7; 一些数据
 8        msg : db "Booting"
 9        msgL : equ $-msg
10
11BOOT_BEGIN : 
12
13; 设置默认显示方式
14        xor ah, ah
15        mov al, VIDEO_ID
16        int 0x10
17
18; 显示引导提示信息
19        mov ax, cs
20        mov es, ax
21        mov bp, msg
22        mov al, 1
23        mov cx, msgL
24        mov dh, 0xA
25        mov dl, 0x20
26        mov bh, 0
27        mov bl, 0x07
28        mov ah, 0x13
29        int 0x10
30
31; 读入 Loader 和 Kernel
32        xor ax, ax
33        mov es, ax
34        mov bx, LOADER_BEGIN
35        mov ah, 0x2
36        mov al, LOADER_SECTOR_NUM ; 暂无Kernel
37        mov cx, 0x0002
38        mov dx, 0x0000
39        int 0x13
40
41; 跳入 Loader
42        jmp LOADER_BEGIN
43
44; 确保填满一个引导扇区
45        times (0x200-2-($-$$))  db 0
46        db 0x55
47        db 0xAA
48
49LOADER_BEGIN : 
50
51

boot/boot_const.inc
 1%ifndef  __BOOT_CONST_INC_INCLUDED__
 2%define  __BOOT_CONST_INC_INCLUDED__
 3
 4
 5; 引导,加载,初始化的一些相关常数,针对汇编语言部分
 6
 7
 8%include "../config.inc"
 9
10
11; video
12MDA_ID : equ 0x07
13MDA_COL_NUM : equ  80
14MDA_ROW_NUM : equ  25
15MDA_BASE : equ  0xB0000
16MDA_BASE_SEG : equ 0xB000
17MDA_BASE_OFF : equ 0x0
18
19
20
21VIDEO_ID : equ  MDA_ID
22
23
24
25%endif
26
27

boot/loader.s
 1%include "../config.inc"
 2
 3
 4org 0x7C00+0x200
 5
 6        jmp LOADER_BEGIN
 7
 8; 一些数据
 9        msg : db "Loading"
10        msgL : equ $-msg
11
12LOADER_BEGIN : 
13
14; 显示加载提示信息
15        mov ax, cs
16        mov es, ax
17        mov bp, msg
18        mov al, 1
19        mov cx, msgL
20        mov dh, 0xB
21        mov dl, 0x20
22        mov bh, 0
23        mov bl, 0x07
24        mov ah, 0x13
25        int 0x10
26
27        jmp $
28        times (0x200-($-$$)) db 0
29; 准备进入保护模式
30
31; 进入保护模式
32

命令
1nasm -o boot.bin boot.s
2nasm -o loader.bin loader.s
3sudo dd if=boot.bin of=/dev/fd0 bs=512 count=1 conv=notrunc
4sudo dd if=loader.bin of=/dev/fd0 bs=512 count=1 conv=notrunc seek=1
5
6

posted on 2011-04-09 11:27 coreBugZJ 阅读(373) 评论(0)  编辑 收藏 引用 所属分类: AssembleOperatingSystem


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理