-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmbr.s
106 lines (83 loc) · 1.78 KB
/
mbr.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
; 主引导程序
;-----------------------------------------------
%include "boot.inc"
SECTION MBR vstart=0x7c00
mov ax, cs
mov ds, ax
mov es, ax
mov ss, ax
mov fs, ax
mov sp, 0x7c00
mov ax, 0xb800
mov gs, ax
; 清屏
;---------------------------------------------------
mov ax, 0600h
mov bx, 0700h
mov cx, 0
mov dx, 184fh
int 10h
; 显示"MBR"
mov byte [gs:0x00], '1'
mov byte [gs:0x01], 0xA4
mov byte [gs:0x02], ' '
mov byte [gs:0x03], 0xA4
mov byte [gs:0x04], 'M'
mov byte [gs:0x05], 0xA4
mov byte [gs:0x06], 'B'
mov byte [gs:0x07], 0xA4
mov byte [gs:0x08], 'R'
mov byte [gs:0x09], 0xA4
mov eax, LOADER_START_SECTOR
mov bx, LOADER_BASE_ADDR
; 读取4个扇区
mov cx, 4
call rd_disk_m_16
jmp LOADER_BASE_ADDR + 0x300
;-----------------------------------------------------------
; 读取磁盘的n个扇区,用于加载loader
; eax保存从硬盘读取到的数据的保存地址,ebx为起始扇区,cx为读取的扇区数
rd_disk_m_16:
;-----------------------------------------------------------
mov esi, eax
mov di, cx
mov dx, 0x1f2
mov al, cl
out dx, al
mov eax, esi
mov dx, 0x1f3
out dx, al
mov cl, 8
shr eax, cl
mov dx, 0x1f4
out dx, al
shr eax, cl
mov dx, 0x1f5
out dx, al
shr eax, cl
and al, 0x0f
or al, 0xe0
mov dx, 0x1f6
out dx, al
mov dx, 0x1f7
mov al, 0x20
out dx, al
.not_ready:
nop
in al, dx
and al, 0x88
cmp al, 0x08
jnz .not_ready
mov ax, di
mov dx, 256
mul dx
mov cx, ax
mov dx, 0x1f0
.go_on_read:
in ax, dx
mov [bx], ax
add bx, 2
loop .go_on_read
ret
times 510-($-$$) db 0
db 0x55, 0xaa