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
148
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;disk_load_16
;
[bits 16]
STR_ERROR:
db "Disk Read Error",0
STR_SPACE
db " ",0
STR_OK:
db "Kernel Loaded",0
bpbSectorsPerTrack:
dw 18
bpbHeadsPerCylinder:
dw 2
LBA:
dw 10 ; current lba
disk_load_16:
pusha
mov bx,0x1000 ;target es:bx
mov es,bx
mov bx,0
next_sectors:
pusha
mov bx, STR_SPACE
call print_string
;show es - target
mov bx,es
mov al,bh
call print_hex_byte
mov al,bl
call print_hex_byte
mov bx, STR_SPACE
call print_string
;load and show next LBA numer
mov ax,[LBA]
mov al,ah
call print_hex_byte
mov ax,[LBA]
call print_hex_byte
mov bx, STR_SPACE
call print_string
popa
mov ax,[LBA]
;calculate chs
call lba_to_chs
;show chs sector/ head / cylinder
mov al,cl
call print_hex_byte
mov al,dh
call print_hex_byte
mov al,ch
call print_hex_byte
call print_nextline
; and now READ it!
mov al,16 ;number of sectors to read
mov dl,[BOOT_DRIVE]
mov ah,0x02 ;BIOS read sector func
int 0x13 ;bios interrupt
jc disk_read_error
disk_read_error_continue:
mov bx,es
add bx,0x0200
cmp bx,0x9e00
je disk_load_finish
mov es,bx
mov bx,0
mov ax,[LBA]
add ax,16
mov [LBA],ax
jmp next_sectors
disk_read_error:
pusha
mov bx, STR_ERROR
call print_string
call print_nextline
popa
jmp disk_read_error_continue
disk_load_finish:
mov bx, STR_OK
call print_string
call print_nextline
popa
ret
;lba to chs translation:
; input : ax - lba
; output: cl - sector
; dh - head
; ch - cylinder / track
lba_to_chs:
xor dx, dx ; prepare dx:ax for operation
div WORD [bpbSectorsPerTrack] ; divide by sectors per track
inc dl ; add 1 (obsolute sector formula)
mov cl, dl
xor dx, dx ; prepare dx:ax for operation
div WORD [bpbHeadsPerCylinder] ; mod by number of heads (Absolue head formula)
mov dh,dl ; everything else was already done from the first formula
mov ch, al ; not much else to do :)
ret
|