引導并加載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
11
LOADER_SECTOR_NUM : equ 0x8
12
KERNEL_SECTOR_NUM : equ 0x100
13
14
15
%endif
16
17
%ifndef __CONFIG_INC_INCLUDED__2
%define __CONFIG_INC_INCLUDED__3

4

5
; 全局配置屬性,針對匯編語言部分6

7

8
; boot-loader-kernel 在引導盤中,內存中都連續分布9
; 各自占用的扇區數量10

11
LOADER_SECTOR_NUM : equ 0x812
KERNEL_SECTOR_NUM : equ 0x10013

14

15
%endif16

17

boot/boot.s
1
%include "../config.inc"
2
%include "boot_const.inc"
3
4
org 0x7c00
5
jmp BOOT_BEGIN
6
7
; 一些數據
8
msg : db "Booting
"
9
msgL : equ $-msg
10
11
BOOT_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
49
LOADER_BEGIN :
50
51
%include "../config.inc"2
%include "boot_const.inc"3

4
org 0x7c005
jmp BOOT_BEGIN6

7
; 一些數據8
msg : db "Booting
"9
msgL : equ $-msg10

11
BOOT_BEGIN : 12

13
; 設置默認顯示方式14
xor ah, ah15
mov al, VIDEO_ID16
int 0x1017

18
; 顯示引導提示信息19
mov ax, cs20
mov es, ax21
mov bp, msg22
mov al, 123
mov cx, msgL24
mov dh, 0xA25
mov dl, 0x2026
mov bh, 027
mov bl, 0x0728
mov ah, 0x1329
int 0x1030

31
; 讀入 Loader 和 Kernel32
xor ax, ax33
mov es, ax34
mov bx, LOADER_BEGIN35
mov ah, 0x236
mov al, LOADER_SECTOR_NUM ; 暫無Kernel37
mov cx, 0x000238
mov dx, 0x000039
int 0x1340

41
; 跳入 Loader42
jmp LOADER_BEGIN43

44
; 確保填滿一個引導扇區45
times (0x200-2-($-$$)) db 046
db 0x5547
db 0xAA48

49
LOADER_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
12
MDA_ID : equ 0x07
13
MDA_COL_NUM : equ 80
14
MDA_ROW_NUM : equ 25
15
MDA_BASE : equ 0xB0000
16
MDA_BASE_SEG : equ 0xB000
17
MDA_BASE_OFF : equ 0x0
18
19
20
21
VIDEO_ID : equ MDA_ID
22
23
24
25
%endif
26
27
%ifndef __BOOT_CONST_INC_INCLUDED__2
%define __BOOT_CONST_INC_INCLUDED__3

4

5
; 引導,加載,初始化的一些相關常數,針對匯編語言部分6

7

8
%include "../config.inc"9

10

11
; video12
MDA_ID : equ 0x0713
MDA_COL_NUM : equ 8014
MDA_ROW_NUM : equ 2515
MDA_BASE : equ 0xB000016
MDA_BASE_SEG : equ 0xB00017
MDA_BASE_OFF : equ 0x018

19

20

21
VIDEO_ID : equ MDA_ID22

23

24

25
%endif26

27

boot/loader.s
1
%include "../config.inc"
2
3
4
org 0x7C00+0x200
5
6
jmp LOADER_BEGIN
7
8
; 一些數據
9
msg : db "Loading
"
10
msgL : equ $-msg
11
12
LOADER_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
%include "../config.inc"2

3

4
org 0x7C00+0x2005

6
jmp LOADER_BEGIN7

8
; 一些數據9
msg : db "Loading
"10
msgL : equ $-msg11

12
LOADER_BEGIN : 13

14
; 顯示加載提示信息15
mov ax, cs16
mov es, ax17
mov bp, msg18
mov al, 119
mov cx, msgL20
mov dh, 0xB21
mov dl, 0x2022
mov bh, 023
mov bl, 0x0724
mov ah, 0x1325
int 0x1026

27
jmp $28
times (0x200-($-$$)) db 029
; 準備進入保護模式30

31
; 進入保護模式32

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

6

posted on 2011-04-09 11:27 coreBugZJ 閱讀(413) 評論(0) 編輯 收藏 引用 所屬分類: Assemble 、OperatingSystem

