3 ; Copyright 1999-2006 John Coffman
4 ; Copyright 2009-2011 Joachim Wiedorn
7 ; Licensed under the terms contained in the file 'COPYING'
8 ; in the source directory.
13 ; lba_read: read using LBA
16 ; AL actual count of blocks to transfer
17 ; DL device (0x00=A:, 0x80=C:, 0x81=D:) and LINEAR/LBA32 flags
18 ; ES:BX buffer pointer
22 ; No Error: carry clear
23 ; CX count of blocks read
26 ; AH error status if CF=1
30 lba_read: push si ;save some registers
34 xor ah,ah ;convert count to word
37 push cx ;gotta ask about 32-bit addressing
39 #ifndef JRC_FLAGS_IN_DH
40 mov dh,dl ;use BL for flag test
42 and dl,#DEV_MASK_asm ;remove spurious flags (0x8F)
45 jz no_lba ;linear will never use EDD calls
48 cmp al,#127 ;test for LINEAR transfer too big
49 ja no_lba ; for LBA mode (127 is max)
52 mov bx,#0x55AA ;magic number
53 mov ah,#0x41 ;function call
59 cmp bx,#0xAA55 ;magic return
61 test cl,#EDD_PACKET ;packet calls supported?
65 ; LBA mode is to be used
78 push dword #0 ; 0L is pushed
86 push #1 ;count always 1
88 push #16 ;size of parameter area ;#
89 ;actually pushes a word
90 mov si,sp ;DS:SI is param block pointer
93 pop ds ;DS:SI points at param block
96 mov ax,#0x4200 ;read function -- must be AX
97 ; as AL has meaning on WRITE
100 ;;; mov ax,#0x4200 ;read function
101 mov ah,#0x42 ;read only -- AL matters not
104 lea sp,word ptr (si+16) ;use lea so flags are not changed
117 lba_small: ;must get the disk geometry
118 #ifndef JRC_NOCOMPACT
131 mov ah,#8 ; DL is set to device
132 #ifndef JRC_NOCOMPACT
142 xchg cl,ch ;CX is max cylinder number
143 mov di,cx ;DI saves it
148 inc ax ;AX is number of heads (256 allowed)
150 ; compensate for Davide BIOS bug
151 dec cx ; 1..63 -> 0..62; 0->63
152 and cx,#0x003f ;CX is number of sectors
153 inc cx ; allow Sectors==0 to mean 64
156 xchg ax,si ;save in SI
161 jae lba_geom_error2 ;prevent division error
162 div si ;AX is cyl, DX is head/sect
164 ja lba_geom_error2 ;cyl is too big
169 div cl ;AH = sec-1, AL = head
170 #ifndef JRC_NOCOMPACT
171 sub cl,ah ;CX = max count possible
172 mov si,cx ;save in SI
175 add dl,ah ;form Cyl/Sec
181 #ifndef JRC_NOCOMPACT
182 pop ax ;restore the count
183 push ax ;keep in the stack
186 mov ax,si ;smaller is in AX
187 lba_cntltmax: push ax
191 mov ax,#0x201 ;read, count of 1
194 ; carry is set or clear
195 #ifndef JRC_NOCOMPACT
196 pop bx ;actual count read (was AX)
197 pop si ;count remaining
201 add cx,bx ;update lba address
202 adc di,#0 ;the # was omitted in rev 3
204 pop bx ;buffer address
205 add bh,al ;update ES:BX
206 add bh,al ;LILO has already checked for seg update
208 sub ax,si ;AX is remaining count after transfer
210 ; after the sub yields 0, the carry is clear
212 lba_read_exit1: jmp lba_read_exit
214 #ifndef JRC_NOCOMPACT
220 dsk_do_rw: or ah,#0 ; 0=read, 1=write, 2=read-only test
221 dsk_wrflag equ *-1 ; byte data area is the immediate
224 dsk_wrflag: .byte 0 ; 0=read, 1=write, 2=read-only test
233 dsk_wrflag: .byte 0 ; 0=read, 1=write, 2=read-only test
240 mov bp,#5 ;number of tries
244 dec bp ;does not affect the carry
246 xor ax,ax ;reset disk controllers
252 dsk_io_exit: mov bp,sp ;do not touch any flags
253 lea sp,(bp+16) ;an ADD would touch flags
254 pop bp ;do not touch any flags
262 mov ah,#0x40 ;seek failure error code
265 #ifndef JRC_NOCOMPACT
274 #ifndef JRC_NOCOMPACT
275 pop cx ;return count in CX