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
142
143
144
145
146
147
|
[BITS 16]
[ORG 7c00h]
init:
mov cx, 0xB800
mov gs, cx
start:
call clr_vga
mov si, HELLO
call write_str
call disk_read
mov si, VERIFY
call write_str
mov ax, 0x61
call cursor_next_line
call write_char_default_attr
mov ax, 0x62
call cursor_next_line
call write_char_default_attr
mov ax, 0x63
call cursor_next_line
call write_char_default_attr
call write_char_default_attr
call write_char_default_attr
call cursor_back_one
call cursor_backspace
jmp hang
read_err:
mov si, READ_ERR
call write_str
hang:
jmp hang
write_str:
push ax
push si
xor ax, ax
write_str_each_char:
mov al, byte [si]
cmp al, 0
je write_str_done
inc si
call write_char_default_attr
jmp write_str_each_char
write_str_done:
pop si
pop ax
ret
write_char_default_attr:
push bx
mov bl, 0x07
jmp write_char_inner
write_char:
push bx
write_char_inner:
push di
mov di, [CURSOR_LOC]
mov byte [gs:di], al
inc di
mov byte [gs:di], bl
inc di
mov [CURSOR_LOC], di
pop di
pop bx
ret
clr_vga:
mov di, 4000
clr_vga_loop:
dec di
mov byte [gs:di], 0x00
cmp di, 0
jne clr_vga_loop
mov word [CURSOR_LOC], 0
ret
disk_read:
; ax = disk number to read from
; reference: http://www.delorie.com/djgpp/doc/rbinter/id/14/7.html
mov dx, 0x80
or ax, dx
mov si, LBA_DISK_READ_PACKET
mov ah, 0x42
int 0x13
jc read_err
mov si, READ_SUCC
call write_str
ret
READ_ERR:
db 'Read failed: ', 0
READ_SUCC:
db 'Read didnt fail: ', 0
HELLO:
db 'Bootloader init: ', 0
CURSOR_LOC:
dw 0
; reference: http://www.delorie.com/djgpp/doc/rbinter/it/72/2.html
LBA_DISK_READ_PACKET:
db 0x10
db 0
dw 1 ; number of blocks to read, reset to # actually read when done
dw 0x7e00 ; read destination address
dw 0
dd 1 ; lba to read from
dd 0 ; for extended lba adresses (not really used here)
times 510-($-$$) db 0
db 0x55
db 0xAA
cursor_next_line:
mov di, [CURSOR_LOC]
add di, 160
mov [CURSOR_LOC], di
ret
cursor_prev_line:
mov di, [CURSOR_LOC]
sub di, 160
mov [CURSOR_LOC], di
ret
cursor_backspace:
push ax
call cursor_back_one
mov ax, 0x00
call write_char_default_attr
call cursor_back_one
pop ax
ret
cursor_back_one:
mov di, [CURSOR_LOC]
dec di
dec di
mov [CURSOR_LOC], di
ret
VERIFY:
db '[x] read next block: ', 0
times 1024-($-$$) db 0
|