-
Notifications
You must be signed in to change notification settings - Fork 0
/
vbr.S
141 lines (141 loc) · 3.99 KB
/
vbr.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#*******************************************************************************
# ___ publicplace
# ¦OUX¦ 16-bit assembly
# ¦/C+¦ OUX/C+ OS
# --- VBR boot loader
# entry
# ©overcq on ‟Gentoo Linux 17.1” “x86_64” 2021‒3‒11 T
#*******************************************************************************
.equiv Q_memory_S_vbr, 0x7c00
# “Q_memory_S_file_loader” musi być na wielokrotności 512.
.equiv Q_memory_S_file_loader, 0x7e00
#-------------------------------------------------------------------------------
.equiv Q_offset_S_file_loader_data, 224
.equiv Q_offset_S_second_mbr_part, 228
.equiv Q_offset_S_signature, 510
#-------------------------------------------------------------------------------
.equiv Q_vga_color_S_light_gray, 7
#===============================================================================
.org Q_memory_S_vbr
.code16
.text
cli
xor %ax, %ax
mov %ax, %ss
mov $Q_memory_S_vbr, %sp
push %ax
pop %ds
push %ax
pop %es
sti
mov %sp, %bp
ljmp $0, $0f
0: push %dx # Numer dysku, z którego ‘bootuje’.
mov $Q_print_S_logo, %si
push %bp
call Q_vga_I_print
pop %bp
cld
mov $Q_memory_S_vbr + Q_offset_S_file_loader_data, %si
lodsb
mov %al, -1(%bp) # head
lodsw
mov %ax, %cx # sector, cylinder
lodsb # Liczba sektorów do przeczytania.
test %al, %al
jz I_print_no_file_loader
push %cx
push %ax
mov $Q_print_S_booting_file, %si
push %bp
call Q_vga_I_print
pop %bp
mov $Q_memory_S_file_loader, %bx
1: mov -2(%bp), %dx
mov -4(%bp), %cx
mov $0x201, %ax
push %bp
push %bx
int $0x13
jc I_print_io_error
pop %bx
pop %bp
mov -4(%bp), %cl
and $~( ~0 << 6 ), %cl
inc %cl
testb $0x80, -2(%bp)
jnz 0f
cmp $19, %cl
jb 3f
mov $1, %cl
incb -1(%bp)
cmpb $2, -1(%bp)
jmp 2f
0: cmp $64, %cl
jb 3f
mov $1, %cl
incb -1(%bp)
cmpb $16, -1(%bp)
2: jb 3f
movb $0, -1(%bp)
addb $1, -3(%bp)
jnc 3f
addb $1 << 6, -4(%bp)
jc I_hlt
3: andb $~0 << 6, -4(%bp)
or %cl, -4(%bp)
pop %ax
dec %al
jz 0f
push %ax
add $512, %bx
jnc 1b
mov %es, %cx
add $1 << 12, %cx
mov %cx, %es
jmp 1b
0: add $3 * 2, %sp
pop %dx
mov $Q_memory_S_file_loader, %sp # Ustawienie większego stosu.
jmp Q_memory_S_file_loader
#-------------------------------------------------------------------------------
# jmp 0f
.org Q_memory_S_vbr + Q_offset_S_second_mbr_part
#-------------------------------------------------------------------------------
I_print_no_file_loader:
mov $Q_print_S_no_file_loader, %si
jmp 0f
I_print_io_error:
xor %ax, %ax
mov $Q_print_S_io_error, %si
mov %ax, %es
0: call Q_vga_I_print
I_hlt:
cli
0: hlt
jmp 0b
Q_vga_I_print:
0: cld
lodsb
test %al, %al
jz 0f
push %si
mov $0xe, %ah
mov $Q_vga_color_S_light_gray, %bx
int $0x10
pop %si
jmp 0b
0: ret
#===============================================================================
Q_print_S_logo:
.asciz "OUX/C+ OS boot loader. Volume Boot Record.\r\n"
Q_print_S_io_error:
.asciz "Disc I/O error."
Q_print_S_no_file_loader:
.asciz "No file loader."
Q_print_S_booting_file:
.asciz "Booting file...\r\n"
#===============================================================================
.org Q_memory_S_vbr + Q_offset_S_signature
.byte 0x55, 0xaa
#*******************************************************************************