3 Copyright 1999-2006 John Coffman.
6 Licensed under the terms contained in the file 'COPYING' in the
12 ; lba_read: read using LBA
15 ; AL actual count of blocks to transfer
16 ; DL device (0x00=A:, 0x80=C:, 0x81=D:) and LINEAR/LBA32 flags
17 ; ES:BX buffer pointer
21 ; No Error: carry clear
22 ; CX count of blocks read
25 ; AH error status if CF=1
29 lba_read: push si ;save some registers
33 xor ah,ah ;convert count to word
36 push cx ;gotta ask about 32-bit addressing
38 #ifndef JRC_FLAGS_IN_DH
39 mov dh,dl ;use BL for flag test
41 and dl,#DEV_MASK_asm ;remove spurious flags (0x8F)
44 jz no_lba ;linear will never use EDD calls
47 cmp al,#127 ;test for LINEAR transfer too big
48 ja no_lba ; for LBA mode (127 is max)
51 mov bx,#0x55AA ;magic number
52 mov ah,#0x41 ;function call
58 cmp bx,#0xAA55 ;magic return
60 test cl,#EDD_PACKET ;packet calls supported?
64 ; LBA mode is to be used
77 push dword #0 ; 0L is pushed
85 push #1 ;count always 1
87 push #16 ;size of parameter area ;#
88 ;actually pushes a word
89 mov si,sp ;DS:SI is param block pointer
92 pop ds ;DS:SI points at param block
95 mov ax,#0x4200 ;read function -- must be AX
96 ; as AL has meaning on WRITE
99 ;;; mov ax,#0x4200 ;read function
100 mov ah,#0x42 ;read only -- AL matters not
103 lea sp,word ptr (si+16) ;use lea so flags are not changed
116 lba_small: ;must get the disk geometry
117 #ifndef JRC_NOCOMPACT
130 mov ah,#8 ; DL is set to device
131 #ifndef JRC_NOCOMPACT
141 xchg cl,ch ;CX is max cylinder number
142 mov di,cx ;DI saves it
147 inc ax ;AX is number of heads (256 allowed)
149 ; compensate for Davide BIOS bug
150 dec cx ; 1..63 -> 0..62; 0->63
151 and cx,#0x003f ;CX is number of sectors
152 inc cx ; allow Sectors==0 to mean 64
155 xchg ax,si ;save in SI
160 jae lba_geom_error2 ;prevent division error
161 div si ;AX is cyl, DX is head/sect
163 ja lba_geom_error2 ;cyl is too big
168 div cl ;AH = sec-1, AL = head
169 #ifndef JRC_NOCOMPACT
170 sub cl,ah ;CX = max count possible
171 mov si,cx ;save in SI
174 add dl,ah ;form Cyl/Sec
180 #ifndef JRC_NOCOMPACT
181 pop ax ;restore the count
182 push ax ;keep in the stack
185 mov ax,si ;smaller is in AX
186 lba_cntltmax: push ax
190 mov ax,#0x201 ;read, count of 1
193 ; carry is set or clear
194 #ifndef JRC_NOCOMPACT
195 pop bx ;actual count read (was AX)
196 pop si ;count remaining
200 add cx,bx ;update lba address
201 adc di,#0 ;the # was omitted in rev 3
203 pop bx ;buffer address
204 add bh,al ;update ES:BX
205 add bh,al ;LILO has already checked for seg update
207 sub ax,si ;AX is remaining count after transfer
209 ; after the sub yields 0, the carry is clear
211 lba_read_exit1: jmp lba_read_exit
213 #ifndef JRC_NOCOMPACT
219 dsk_do_rw: or ah,#0 ; 0=read, 1=write, 2=read-only test
220 dsk_wrflag equ *-1 ; byte data area is the immediate
223 dsk_wrflag: .byte 0 ; 0=read, 1=write, 2=read-only test
232 dsk_wrflag: .byte 0 ; 0=read, 1=write, 2=read-only test
239 mov bp,#5 ;number of tries
243 dec bp ;does not affect the carry
245 xor ax,ax ;reset disk controllers
251 dsk_io_exit: mov bp,sp ;do not touch any flags
252 lea sp,(bp+16) ;an ADD would touch flags
253 pop bp ;do not touch any flags
261 mov ah,#0x40 ;seek failure error code
264 #ifndef JRC_NOCOMPACT
273 #ifndef JRC_NOCOMPACT
274 pop cx ;return count in CX