📄 usbi13.asm
字号:
; CX+ Low byte (CL+) number of sectors (512 bytes)
; to skip before reading actual data. High byte
; (CH+) number of sectors to skip after reading
; actual data
; EDX LBA number to read
; EDI Pointer to the read buffer (Seg:Off)
;
; Output: NC Successful
; AH 0
; CX Number of sectors read
; EDI Updated buffer pointer
; CY Error
; Ah <> 0
;
; Modified: AX, CX, EDI
;
; Referrals: USBCDDataArea, CDROM_API_HDR, URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBCDReadDevice PROC NEAR PUBLIC
LOCAL stURP:URP_STRUC
push bx
push ecx
push es
push ax
; Fill URP with proper values
lea bx, stURP
mov (URP_STRUC PTR ss:[bx]).bFuncNumber, \
USB_API_MASS_DEVICE_REQUEST
mov (URP_STRUC PTR ss:[bx]).bSubFunc, USB_MASSAPI_READ_DEVICE
mov al, (USBCDDataArea PTR FS:[si]).bUSBCDHandle
mov (URP_STRUC PTR ss:[bx]).ApiData.MassRead.bDevAddr, al
mov (URP_STRUC PTR ss:[bx]).ApiData.MassRead.dStartLBA, edx
mov (URP_STRUC PTR ss:[bx]).ApiData.MassRead.wNumBlks, cx
shr ecx, 16
movzx ax, cl
shl ax, 9 ; Multiply by 512
mov (URP_STRUC PTR ss:[bx]).ApiData.MassRead.wPreSkipSize, ax
movzx ax, ch
shl ax, 9 ; Multiply by 512
mov (URP_STRUC PTR ss:[bx]).ApiData.MassRead.wPostSkipSize, ax
mov (URP_STRUC PTR ss:[bx]).ApiData.MassRead.fpBufferPtr, edi
push ss
pop es
; ES:BX - Far URP pointer
INVOKE_USB_API_HANDLER
pop ax
mov ah, (URP_STRUC PTR es:[bx]).bRetValue
or ah, ah
jz UCRD_ExitSuccess
stc
jmp SHORT UCRD_Exit
UCRD_ExitSuccess:
clc
UCRD_Exit:
pop es
pop ecx
pop bx
ret
USBCDReadDevice ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
;
; Procedure: USBCDGetBootRecLBA
;
; Description: This routine is a part of USB CDROM API routines. This
; routine returns the boot record LBA number of the CDROM.
;
; Input: FS:SI Pointer to USBCDDataArea
; EDI Pointer to the read buffer (Seg:Off)
;
; Output: NC Successful
; EDX LBA of the boot record volume
; CY Error
;
; Modified: EDX
;
; Referrals: USBCDDataArea, CDROM_API_HDR, URP_STRUC, ATACDToc
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
CDATAPIGetTOCCommand LABEL BYTE
DB 043h, 000h, 000h, 000h, 000h, 000h
DB 000h, 000h, 00Ch, 040h, 000h, 000h
CDATAPIGetTOCCommandEnd LABEL BYTE
TOC_COMMAND_LENGTH EQU (CDATAPIGetTOCCommandEnd - CDATAPIGetTOCCommand)
USBCDGetBootRecLBA PROC NEAR PUBLIC
LOCAL stURP:URP_STRUC, aUSBCDToc:ATACDToc
push eax
push bx
push ecx
push es
; Fill URP with proper values
lea bx, stURP
mov (URP_STRUC PTR ss:[bx]).bFuncNumber, \
USB_API_MASS_DEVICE_REQUEST
mov (URP_STRUC PTR ss:[bx]).bSubFunc, USB_MASSAPI_CMD_PASS_THRU
mov al, (USBCDDataArea PTR FS:[si]).bUSBCDHandle
mov (URP_STRUC PTR ss:[bx]).ApiData.MassCmdPassThru.bDevAddr, al
; Set the command buffer pointer
push cs
push OFFSET CDATAPIGetTOCCommand
pop eax
mov (URP_STRUC PTR ss:[bx]).ApiData.MassCmdPassThru.fpCmdBuffer, eax
; Set the command length
mov (URP_STRUC PTR ss:[bx]).ApiData.MassCmdPassThru.wCmdLength, TOC_COMMAND_LENGTH
; Set the data buffer pointer
push ss
lea ax, aUSBCDToc
push ax
pop eax
mov (URP_STRUC PTR ss:[bx]).ApiData.MassCmdPassThru.fpDataBuffer, eax
; Set the data length
mov (URP_STRUC PTR ss:[bx]).ApiData.MassCmdPassThru.wDataLength, SIZE ATACDToc
; Set the transfer direction to IN
mov (URP_STRUC PTR ss:[bx]).ApiData.MassCmdPassThru.bXferDir, BIT7
push ss
pop es
; ES:BX - Far URP pointer
INVOKE_USB_API_HANDLER
mov edx, 011h ; Boot record LBA
; Check the sense code returned
mov eax, (URP_STRUC PTR ss:[bx]).ApiData.MassCmdPassThru.dSenseData
or eax, eax
jnz UCGBRL_Exit ; Assume boot record LBA as 011h
; Get the last sessions start LBA number from the data read
lea bx, aUSBCDToc
mov eax, (ATACDToC ptr SS:[bx]).dStartLBA
; Convert big-endian to small-endian
xchg al, ah
rol eax, 10h
xchg al, ah
add edx, eax
UCGBRL_Exit:
pop es
pop ecx
pop bx
pop eax
clc
ret
USBCDGetBootRecLBA ENDP
; USB data segment value (updated in POST and will not change)
PUBLIC wUSBGlobalDataSegment
wUSBGlobalDataSegment WORD ?
;---------------------------------------------------------------;
; USB_CALL_TABLE ;
;---------------------------------------------------------------;
UI13FDDCallTable LABEL PTRFUNCINT13
DW OFFSET UI13Func00 ; 00
DW OFFSET UI13FDDFunc01 ; 01
DW OFFSET UI13Func02 ; 02
DW OFFSET UI13Func03 ; 03
DW OFFSET UI13Func04 ; 04
DW OFFSET UI13FDDFunc05 ; 05
DW OFFSET UI13FuncInvalid ; 06
DW OFFSET UI13FuncInvalid ; 07
DW OFFSET UI13FDDFunc08 ; 08
DW OFFSET UI13FuncInvalid ; 09
DW OFFSET UI13FuncInvalid ; 0A
DW OFFSET UI13FuncInvalid ; 0B
DW OFFSET UI13FuncInvalid ; 0C
DW OFFSET UI13FuncInvalid ; 0D
DW OFFSET UI13FuncInvalid ; 0E
DW OFFSET UI13FuncInvalid ; 0F
DW OFFSET UI13FuncInvalid ; 10
DW OFFSET UI13FuncInvalid ; 11
DW OFFSET UI13FuncInvalid ; 12
DW OFFSET UI13FuncInvalid ; 13
DW OFFSET UI13FuncInvalid ; 14
DW OFFSET UI13FDDFunc15 ; 15
DW OFFSET UI13FDDFunc16 ; 16
DW OFFSET UI13FDDFunc17 ; 17
DW OFFSET UI13FDDFunc18 ; 18
DW OFFSET UI13FuncInvalid ; 19
DW OFFSET UI13FuncInvalid ; 1A
DW OFFSET UI13FuncInvalid ; 1B
DW OFFSET UI13FuncInvalid ; 1C
DW OFFSET UI13FuncInvalid ; 1D
DW OFFSET UI13FuncInvalid ; 1E
DW OFFSET UI13FuncInvalid ; 1F
DW OFFSET UI13FDDFunc20 ; 20
UI13FDDCallTableEnd LABEL WORD
UI13FDDExtendedCallTable LABEL PTRFUNCINT13
DW OFFSET UI13Func41 ; 41h
DW OFFSET UI13FuncInvalid ; 42h
DW OFFSET UI13FuncInvalid ; 43h
DW OFFSET UI13FuncInvalid ; 44h
DW OFFSET UI13FuncInvalid ; 45h
DW OFFSET UI13FuncInvalid ; 46h
DW OFFSET UI13FuncInvalid ; 47h
DW OFFSET UI13Func48 ; 48h
DW OFFSET UI13FDDFunc16 ; 49h
UI13FDDExtendedCallTableEnd LABEL WORD
UI13HDDCallTable LABEL PTRFUNCINT13
DW OFFSET UI13Func00 ; 00
DW OFFSET UI13HDDFunc01 ; 01
DW OFFSET UI13Func02 ; 02
DW OFFSET UI13Func03 ; 03
DW OFFSET UI13Func04 ; 04
DW OFFSET UI13FuncInvalid ; 05
DW OFFSET UI13FuncInvalid ; 06
DW OFFSET UI13FuncInvalid ; 07
DW OFFSET UI13HDDFunc08 ; 08
DW OFFSET UI13FuncInvalid ; 09
DW OFFSET UI13FuncInvalid ; 0A
DW OFFSET UI13FuncInvalid ; 0B
DW OFFSET UI13FuncInvalid ; 0C
DW OFFSET UI13FuncInvalid ; 0D
DW OFFSET UI13FuncInvalid ; 0E
DW OFFSET UI13FuncInvalid ; 0F
UI13HDDCallTableEnd LABEL WORD
UI13HDDExtendedCallTable LABEL PTRFUNCINT13
DW OFFSET UI13Func41 ; 41h
DW OFFSET UI13HDDFunc42 ; 42h
DW OFFSET UI13HDDFunc43 ; 43h
DW OFFSET UI13HDDFunc44 ; 44h
DW OFFSET UI13FuncInvalid ; 45h
DW OFFSET UI13FuncInvalid ; 46h
DW OFFSET UI13FuncInvalid ; 47h
DW OFFSET UI13Func48 ; 48h
UI13HDDExtendedCallTableEnd LABEL WORD
;----------------------------------------------------------------------------
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBINT13Handler
;
; Description: This function is the INT13h interface handler for the USB
; mass storage device
;
; Input: AH Function number
; DL Drive number
; DH Head number
; CH Low byte of the cylinder number
; CL[5-0] Start sector number
; CL[7-6] Bit 8 & 9 of the cylinder number
; AL Sector count
;
; Output: AH Operation status - return value
; CY On error
; NC On success
; CX, DX Return value for functions 8 & 15
;
; Modified: Only the registers which needs to return value are modified
; rest restored
;
; Referrals: USBLocalStore
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBINT13Handler PROC NEAR PUBLIC
cli
; Save FS
push fs
; Set DS to USB data segment
push WORD PTR CS:wUSBGlobalDataSegment
pop fs
; Save original stack
mov FS:UI13OldSS, ss
mov FS:UI13OldSP, sp
; Set new stack
push fs
pop ss
mov sp, OFFSET FS:UI13Stack
; Do not add/remove any push or pop at this point. If changes has to be done
; verify with the equates defined above.
push es
push ds
pushad
; Set the local storage area in the stack
sub sp, OFFSET USBLocalStore.dRegEDI
mov bp, sp
; Initialize the miscellanous information in the stack
mov si, bp
call USBI13SetMiscInfoInStack
;; or ax, ax
;; jnz UI13H_ErrorExit
; Load the INT13h function number (was AH) to DI
movzx di, BYTE PTR (USBLocalStore PTR [bp+1]).dRegEAX
; Check for HDD call
test BYTE PTR (USBLocalStore PTR [bp]).dRegEDX, 80h
jnz UI13_HDDInt13
; Floppy INT-13H Path
; Check for function number validity
cmp di, (OFFSET UI13FDDCallTableEnd - OFFSET UI13FDDCallTable) / 2
jb UI13_FDDCall
sub di, 41h
; Check for extended function call
cmp di, (OFFSET UI13FDDExtendedCallTableEnd - OFFSET UI13FDDExtendedCallTable) / 2
jae UI13_InvalidFunction
; Invoke the extended function
shl di, 1
; SI Stack frame pointer
call (FUNCINT13 PTR [di+UI13FDDExtendedCallTable])
or di, di
jnz UI13_FDDCommonExitPath
; Function 41h. Check return value
or ax, ax
jz UI13_FDDReturnInvalidFunction
jmp SHORT UI13_FDDSpecialFunction
UI13_FDDReturnInvalidFunction:
mov ah, 01h
jmp SHORT UI13_FDDCommonExitPath
UI13_InvalidFunction:
; Set to invalid function
mov di, 0Fh ; Force invalid func
UI13_FDDCall:
shl di, 1
; SI Stack frame pointer
call (FUNCINT13 PTR [di+UI13FDDCallTable])
UI13_FDDCommonExitPath:
shr di, 1
; Check and branch out if the function number is 15h
cmp di, 15h
je UI13_FDDSpecialFunction
; Check and branch out if the function number is 20h
cmp di, 20h
jne UI3_FDDNot20h
; For the function 20h the return value will be in AX and the return value is not
; having error code. This function will always return with carry flag cleared.
UI13_FDDSpecialFunction:
mov WORD PTR (USBLocalStore PTR [bp]).dRegEAX, ax ; Return code
add sp, OFFSET USBLocalStore.dRegEDI ; Release allocated stack space
clc
jmp SHORT UI13H_Exit
UI3_FDDNot20h:
push BDA_DSEG
pop ds
mov floppy_io_status, ah ; return current status in global location
jmp SHORT UI13H_ErrorExit
UI13_HDDInt13:
; Hard Disk INT-13h path
; Check for function number validity
cmp di, (OFFSET UI13HDDCallTableEnd - OFFSET UI13HDDCallTable) / 2
jb UI13_HDDCall
sub di, 41h
; Check for extended function call
cmp di, (OFFSET UI13HDDExtendedCallTableEnd - OFFSET UI13HDDExtendedCallTable) / 2
jae UI13_InvalidFunction
; Invoke the extended function
shl di, 1
; SI Stack frame pointer
call (FUNCINT13 PTR [di+UI13HDDExtendedCallTable])
or di, di
jnz UI13_HDDCommonExitPath
; Function 41h. Check return value
or ax, ax
jz UI13_HDDCommonExitPath
jmp SHORT UI13_FDDSpecialFunction
; Set to invalid function
mov di, 0Fh ; Force invalid func
UI13_HDDCall:
shl di, 1
; SI Stack frame pointer
INVOKE (FUNCINT13 PTR [di+UI13HDDCallTable])
UI13_HDDCommonExitPath:
push BDA_DSEG
pop ds
mov winch_status, ah ; return current status in global location
UI13H_ErrorExit:
mov BYTE PTR (USBLocalStore PTR [bp+1]).dRegEAX, ah ; return code
add sp, OFFSET USBLocalStore.dRegEDI ; release allocated stack space
cmp ah, 1
cmc ; NC/CY for ok/error
UI13H_Exit:
popad
pop ds
pop es
; Restore stack
mov ss, FS:UI13OldSS
mov sp, FS:UI13OldSP
; Restore FS
pop fs
sti
retf 2
USBINT13Handler ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBI13SetMiscInfoInStack
;
; Description: This function initializes miscellanous information
; in the stack
;
; Input: SI Stack frame pointer where the misc info has to be
; stored
;
; Output: AX 00 - Success, <> 0 error code
;
; Modified: AX
;
; Referrals: USBLocalStore, URP_STRUC
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBI13SetMiscInfoInStack PROC NEAR SYSCALL
LOCAL sURP:URP_STRUC
push bx
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -