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
|
[BITS 16]
[ORG 7c00h]
init:
mov cx, 0xB800
mov gs, cx
start:
call clr_vga
mov si, HELLO
call write_str
call disk_read
call verify_read
mov si, READ_NERR
call write_str
jmp word [0x7dfc]
jmp hang
read_err:
mov si, READ_ERR
call write_str
hang:
jmp hang
verify_read:
mov bx, word [0x7dfc]
mov al, 0x66
cmp al, byte [bx]
jne read_err
mov al, 0x55
cmp al, byte [bx+1]
jne read_err
mov al, 0x66
cmp al, byte [bx+2]
jne read_err
mov al, 0x89
cmp al, byte [bx+3]
jne read_err
ret
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
ret
READ_ERR:
db 'Read failed: ', 0
READ_NERR:
db 'No err reading, continuing: ', 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 32 ; number of blocks to read, reset to # actually read when done
dw 0x7dfc ; read destination address
dw 0x0000
dd 1 ; lba to read from
dd 0 ; for extended lba adresses (not really used here)
; times 510-($-$$) db 0
; db 0x55
; db 0xAA
|