📄 usbi13.asm
字号:
push es
; Load pointer to the sURP in ES:BX
lea bx, sURP
push ss
pop es
; Get the USB device address (Stack DL has the drive number)
mov al, BYTE PTR (USBLocalStore PTR SS:[si]).dRegEDX
; For HDD emulated device bit7 is set. Reset it.
and al, NOT BIT7
; Save the USB device address
mov (USBLocalStore PTR SS:[si]).bUSBAddress, al
mov (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.bDevAddr, al
mov (URP_STRUC PTR ES:[bx]).bFuncNumber, \
USB_API_MASS_DEVICE_REQUEST
mov (URP_STRUC PTR ES:[bx]).bSubFunc, \
USB_MASSAPI_GET_DEVICE_GEOMETRY
INVOKE_USB_API_HANDLER
mov ah, (URP_STRUC PTR ES:[bx]).bRetValue
or ah, ah
jnz UISMIIS_Exit
; Check the block size. If it is 0 or FFFFh then return media not present error
mov ah, USB_ATA_TIME_OUT_ERR
cmp (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.wBytesPerSector, 0
je UISMIIS_Exit
cmp (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.wBytesPerSector, 0FFFFh
je UISMIIS_Exit
; Update local stack variables with device geometry info
; Update number of heads
mov al, (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.bNumHeads
mov (USBLocalStore PTR SS:[si]).bNumHeads, al
mov al, (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.bLBANumHeads
mov (USBLocalStore PTR SS:[si]).bLBANumHeads, al
; Update number of cylinders
mov ax, (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.wNumCylinders
mov (USBLocalStore PTR SS:[si]).wNumCyls, ax
mov ax, (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.wLBANumCyls
mov (USBLocalStore PTR SS:[si]).wLBANumCyls, ax
; Update number of sectos/track
mov al, (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.bNumSectors
mov (USBLocalStore PTR SS:[si]).bNumSecs, al
mov al, (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.bLBANumSectors
mov (USBLocalStore PTR SS:[si]).bLBANumSecs, al
; Update block size or sector size (in bytes)
mov ax, (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.wBytesPerSector
mov (USBLocalStore PTR SS:[si]).wSecSize, ax
; Media type from flexible disk information page (read thro' ModeSense)
mov al, (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.bMediaType
mov (USBLocalStore PTR SS:[si]).bMediaType, al
; Last LBA value returned from ReadCapacity command
mov eax, (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.dLastLBA
mov (USBLocalStore PTR SS:[si]).dLastLBA, eax
;;; Media change status
;; mov al, (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevGeo.bMediaChange
;; mov (USBLocalStore PTR SS:[si]).bMediaChange, al
xor ax, ax
UISMIIS_Exit:
pop es
pop bx
ret
USBI13SetMiscInfoInStack ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UI13Func00
;
; Description: This function is the generic Int13h drive reset call
;
; Input: SI Pointer to stack frame
;
; Output: AX 0 on success
; <> 0 on error
;
; Modified: AX
;
; Referrals: USBLocalStore, URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UI13Func00 PROC NEAR SYSCALL
LOCAL sURP:URP_STRUC
push bx
push es
mov al, (USBLocalStore PTR SS:[si]).bUSBAddress
lea bx, sURP
push ss
pop es
mov (URP_STRUC PTR ES:[bx]).ApiData.MassReset.bDevAddr, al
mov (URP_STRUC PTR ES:[bx]).bFuncNumber, \
USB_API_MASS_DEVICE_REQUEST
mov (URP_STRUC PTR ES:[bx]).bSubFunc, \
USB_MASSAPI_RESET_DEVICE
INVOKE_USB_API_HANDLER
mov ah, (URP_STRUC PTR ES:[bx]).bRetValue
pop es
pop bx
ret
UI13Func00 ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UI13FDDFunc01
;
; Description: This function is the get status call for the floppy drive
;
; Input: SI Pointer to stack frame
;
; Output: AH Last floppy status
;
; Modified: AH
;
; Referrals: USBLocalStore, URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UI13FDDFunc01 PROC NEAR SYSCALL
push ds
push BDA_DSEG
pop ds
mov ah, floppy_io_status ; AH = status of previous operation
pop ds
ret
UI13FDDFunc01 ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UI13HDDFunc01
;
; Description: This function is the get status call for the harddisk drives
;
; Input: SI Pointer to stack frame
;
; Output: AH Last floppy status
;
; Modified: AH
;
; Referrals: USBLocalStore, URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UI13HDDFunc01 PROC NEAR SYSCALL
push ds
push BDA_DSEG
pop ds
mov ah, winch_status ; AH = status of previous operation
pop ds
ret
UI13HDDFunc01 endp
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBINT13CommonRWVHandler
;
; Description: This function is the common read/write/verify function
;
; Input: SI Pointer to stack frame where all the register values
; are saved:
; AL Number of sectors to read
; CH Low 8bits of 10bit cylinder number (0 based)
; CL Bit 7-6 : High 2 bits of 10bit cylinder num
; CL Bit 5-0 : Starting sector number (1 based)
; DH Head number (0 based)
; ES:BX Pointer to the read buffer
; DL Command byte (Read, write or verify)
; CX Routine used to prepare URP structure
;
; Output: AX 0 on success
; <> 0 on error
;
; Modified: AX
;
; Referrals: USBLocalStore, URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBINT13CommonRWVHandler PROC NEAR SYSCALL
LOCAL sURP:URP_STRUC
push bx
push es
; Load pointer to the sURP in ES:BX
lea bx, sURP
push ss
pop es
; Initialize unnecessary URP fields to zero
xor eax, eax
mov (URP_STRUC PTR ES:[bx]).ApiData.MassRead.wPreSkipSize, ax
mov (URP_STRUC PTR ES:[bx]).ApiData.MassRead.wPostSkipSize, ax
; Update device address in URP
mov al, (USBLocalStore PTR SS:[si]).bUSBAddress
mov (URP_STRUC PTR ES:[bx]).ApiData.MassRead.bDevAddr, al
call cx
mov (URP_STRUC PTR ES:[bx]).bFuncNumber, \
USB_API_MASS_DEVICE_REQUEST
mov (URP_STRUC PTR ES:[bx]).bSubFunc, dl ; Sub-function number
INVOKE_USB_API_HANDLER
mov ah, (URP_STRUC PTR ES:[bx]).bRetValue
or ah, ah
jnz UIF2_Exit ; Error
;; AX Number of bytes read
;; xor dx, dx ; DX:AX = #of bytes read
;;; SS:SI = Stack frame pointer
;;; DX:AX = #of bytes read
;; div (USBLocalStore PTR SS:[si]).wSecSize
;; ; AX = #of sectors read
;; mov BYTE PTR (USBLocalStore PTR SS:[si]).dRegEAX, al
; Return #of sectors read
UIF2_Exit:
mov ah, (URP_STRUC PTR ES:[bx]).bRetValue
pop es
pop bx
ret
USBINT13CommonRWVHandler ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UI13FormURP
;
; Description: This function converts the cylinder/head/sector addressing
; into LBA address
;
; Input: SI Pointer to stack frame where all the register values
; are saved:
; AX Number of sectors to read
; CH Low 8bits of 10bit cylinder number (0 based)
; CL Bit 7-6 : High 2 bits of 10bit cylinder num
; CL Bit 5-0 : Starting sector number (1 based)
; DH Head number (0 based)
; ES:BX Pointer to the read buffer
; ES:BX Pointer to URP where the above information are filled
;
; Output: AX Return code (Ax = 0 Success, AH = Error code)
;
; Modified: EAX
;
; Referrals: USBLocalStore, URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UI13FormURP PROC NEAR SYSCALL
LOCAL bStartSector:BYTE, wCylinderNum:WORD
push ebx
push ecx
push dx
push si
push di
push es
; Load the ES:DI with fpURP
mov di, bx
; Convert the CHS to LBA
; Find the start sector number and cylinder number
mov al, BYTE PTR (USBLocalStore PTR SS:[si]).dRegECX
and al, 3Fh ; AX - Start sector number
mov bStartSector, al
; Get Cylinder number
mov ax, WORD PTR (USBLocalStore PTR SS:[si]).dRegECX
shr al, 06h
xchg al, ah ; AX - Cylinder number
mov wCylinderNum, ax
mov al, (USBLocalStore PTR SS:[si]).bNumSecs ; Sectors/track
mul (USBLocalStore PTR SS:[si]).bNumHeads ; Num. Heads
; AX - Number of heads * sectors per track
mul wCylinderNum
; DX:AX - Start sector of cylinder
push dx
push ax
pop ebx ; EBX = start sector of cylinder
movzx eax, bStartSector ; 1 based
dec eax ; 0 based
add ebx, eax
; Get head number * number of sectors / track
mov al, (USBLocalStore PTR SS:[si]).bNumSecs ; Sectors/track
mul BYTE PTR (USBLocalStore PTR SS:[si+1]).dRegEDX ; Head number
movzx eax, ax
add eax, ebx ; Start LBA
mov (URP_STRUC PTR ES:[di]).ApiData.MassRead.dStartLBA, eax
movzx ax, BYTE PTR (USBLocalStore PTR SS:[si]).dRegEAX
; AX - Block count
mov (URP_STRUC PTR ES:[di]).ApiData.MassRead.wNumBlks, ax
; Load number of sectors to read in AL
mov al, BYTE PTR (USBLocalStore PTR SS:[si]).dRegEAX
; Load sector size in CX (in bytes)
mov cx, (USBLocalStore PTR SS:[si]).wSecSize
; AL Number of sectors to read/write/verify
; CX Sector size in bytes
push ax
movzx eax, WORD PTR (USBLocalStore PTR SS:[si]).dRegEBX
mov bx, ax
shr ax, 4
add ax, (USBLocalStore PTR SS:[si]).wRegES
shl eax, 16
; Modify BX to make only lowest nibble significant
and bx, 000Fh
mov ax, bx ; EAX - Normalized address
mov (URP_STRUC PTR ES:[di]).ApiData.MassRead.fpBufferPtr, eax
xor ax, ax
mov dx, 1
sub ax, bx ; Max # of bytes that can be xferred
sbb dx, 0
div cx ; Divide by sector size
mov cx, bx ; ES:CX = normalized address
mov dl, al ; Max # of sectors that can be xferred
pop ax ; Get back user requested sector count
cmp dl, al ; if requested count is more than the limit
;; DO NOT USE XOR it will affect the flags
mov ah, 00h ; AH = 00, ok
jae UIFU_Exit ; Exit
mov ah, 09h ; Data extends too long error
UIFU_Exit:
pop es
pop di
pop si
pop dx
pop ecx
pop ebx
ret
UI13FormURP ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UI13Func02
;
; Description: This function is the generic drive read call
;
; Input: SI Pointer to stack frame where all the register values
; are saved:
; AL Number of sectors to read
; CH Low 8bits of 10bit cylinder number (0 based)
; CL Bit 7-6 : High 2 bits of 10bit cylinder num
; CL Bit 5-0 : Starting sector number (1 based)
; DH Head number (0 based)
; ES:BX Pointer to the read buffer
; AX Return code returned from USBI13SetMiscInfoInStack routine
;
; Output: AX 0 on success
; <> 0 on error
;
; Modified: AX
;
; Referrals: USBLocalStore, URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UI13Func02 PROC NEAR SYSCALL
; Check the error code returned by set misc info in stack routine
or ax, ax
jnz u1f2_Exit
push cx
push dx
mov dl, USB_MASSAPI_READ_DEVICE
mov cx, OFFSET UI13FormURP
call USBINT13CommonRWVHandler
pop dx
pop cx
u1f2_Exit:
ret
UI13Func02 ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UI13Func03
;
; Description: This function is the generic drive write call
;
; Input: SI Pointer to stack frame where all the register values
; are saved:
; AL Number of sectors to write
; CH Low 8bits of 10bit cylinder number (0 based)
; CL Bit 7-6 : High 2 bits of 10bit cylinder num
; CL Bit 5-0 : Starting sector number (1 based)
; DH Head number (0 based)
; ES:BX Pointer to the write buffer
; AX Return code returned from USBI13SetMiscInfoInStack routine
;
; Output: AX 0 on success
; <> 0 on error
;
; Modified: AX
;
; Referrals: USBLocalStore, URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UI13Func03 PROC NEAR SYSCALL
; Check the error code returned by set misc info in stack routine
or ax, ax
jnz u1f3_Exit
push cx
push dx
mov dl, USB_MASSAPI_WRITE_DEVICE
mov cx, OFFSET UI13FormURP
call USBINT13CommonRWVHandler
pop dx
pop cx
u1f3_Exit:
ret
UI13Func03 ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UI13Func04
;
; Description: This function is the floppy drive verify call
;
; Input: SI Pointer to stack frame where all the register values
; are saved:
; AL Number of sectors to verify
; CH Low 8bits of 10bit cylinder number (0 based)
; CL Bit 7-6 : High 2 bits of 10bit cylinder num
; CL Bit 5-0 : Starting sector number (1 based)
; DH Head number (0 based)
; ES:BX Pointer to the verify buffer
; AX Return code returned from USBI13SetMiscInfoInStack routine
;
; Output: AX 0 on success
; <> 0 on error
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -