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
149
150
151
152
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
;disk_load_16
;
[bits 16]
DISK_LOAD:
db "D",0
DISK_LOAD_ERROR
db "E",0
Head:
db 0
Track:
db 0
Sector:
db 1
LBA:
dw 0 ;; starts at zero!
Sectors:
dw 80
Heads:
dw 2
;disk_load routune (load dh sectors from drive dl to es:bx)
;lba mode has 52 sectors hardcoded!
disk_load_16:
pusha
;;; ; check if LBA is supported
;;; pusha
;;; mov ah,0x41
;;; mov bx,0x55aa
;;; int 0x13
;;; jnc disk_load_lba
;;; popa
disk_load_next:
call ESBX
; load using CHS
;; mov al,80 ;read dh sectors (amount)
;; mov cx,[LBA]
;; cmp cx,0
;; jne disk_read_normal
;; mov al,79 ;read dh sectors (amount)
;; disk_read_normal
mov al,1
mov cl,[Sector] ;sector
mov ch,[Track] ;cyl
mov dl,[BOOT_DRIVE]
mov dh,[Head] ;head
mov ah,0x02 ;BIOS read sector func
int 0x13 ;bios interrupt
jnc disk_read_ok ;ready becaue of error :(
mov bx, DISK_LOAD_ERROR
call print_string
jmp $
disk_read_ok:
mov ax,[LBA]
cmp ax,880
je disk_load_ready
mov bx, DISK_LOAD
call print_string
add ax,1 ;conver LBA to CHS
mov [LBA],ax
call LBACHS
jmp disk_load_next
disk_load_ready:
jmp $
popa
ret
ESBX:
xor dx,dx
xor dx,dx
mov ax,[LBA]
mov bx,0x200
mul bx
mov bx,ax
add dx,1
shl dx,12
mov es,dx
ret
; load using LBA
;;;disk_load_lba:
;;;
;;; popa
;;;
;;; xor ah,ah
;;; mov ah,0x42
;;; lea si,[lba_adr]
;;; int 0x13
;;; jc skip_print
;;; mov bx, DISK_LOAD
;;; call print_string
;;; skip_print:
;;;
;;; popa
;;; ret
;;;
LBACHS:
xor dx, dx ; prepare dx:ax for operation
div WORD [Sectors] ; divide by sectors per track
inc dl ; add 1 (obsolute sector formula)
mov BYTE [Sector], dl
xor dx, dx ; prepare dx:ax for operation
div WORD [Heads] ; mod by number of heads (Absolue head formula)
mov BYTE [Head], dl ; everything else was already done from the first formula
mov BYTE [Track], al ; not much else to do :)
ret
lba_adr:
dw 0x10 ; size of packet ( 16 byte)
dw 53 ; number of sectors to read
dw 0x0000 ; target addr. offset
dw 0x1000 ; target addr. sector
dd 1 ; first sector to read
dd 0 ;
|