📄 usbwrap.asm
字号:
TITLE USBWRAP.ASM -- USB Wrapper Source File
;***************************************************************************;
;***************************************************************************;
;** **;
;** (C)Copyright 1985-2003, American Megatrends, Inc. **;
;** **;
;** All Rights Reserved. **;
;** **;
;** 6145-F Northbelt Pkwy, Norcross, GA 30071 **;
;** **;
;** Phone (770)-246-8600 **;
;** **;
;***************************************************************************;
;***************************************************************************;
;***************************************************************************;
; $Header: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBWRAP.ASM 10 3/17/03 5:56p Sivagarn $
;
; $Revision: 10 $
;
; $Date: 3/17/03 5:56p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBWRAP.ASM $
;
; 10 3/17/03 5:56p Sivagarn
; - Byte flag 'bUSBInitFlag' is changed to double word 'dUSBInitFlag'
; - HCStruc pointer is validated before using it, in mass API
; dispatcher
; - USB_MASS_DEVICE_REGISTERED flag is set during assign drive number
; processing
;
; 9 1/27/03 8:49p Sivagarn
; - Code to return from INT13h handler if the HC is not-owned by the
; BIOS is added. This fixes the OS hangs, when OS tries to access USB
; drives using INT13h after it takes control of the USB HC
;
; 8 1/24/03 7:07p Sivagarn
; BugFix
; - Bug in returning correct max LBA was fixed
; - BIOS hang when 4-in-1 flash reader is connected is fixed (Invalid
; read format
; capacity command was identified as valid command)
;
; 7 12/17/02 3:34p Sivagarn
; - Changed copyright message year to 2003
; - 'USBMassAPIGetDeviceGeometry' routine is modified to obtain correct
; CHS value if the geometry is unknown
; - 'USBWrapGetATAErrorCode' routine checks for mode sense code 0 and
; returns successfull completion
; - Bug in using wrong register in the routine 'USBWrapGetATAErrorCode'
; is fixed
;
; 6 11/27/02 6:23p Sivagarn
; - Support for the extended API eLink is added
; - Security related API calls are removed (now they add themselves
; using the new extended API eLink)
; - Change in the CK_PRESENCE data structure is taken care by updating
; code in the routines in CheckPresence API call path
; - Code cleanup
;
; 5 11/17/02 8:09p Sivagarn
; - Bug in displaying wrong, multiple USB mass storage devices during the
; POST, when the USB data area is corrupted or not initialized properly,
; is fixed
;
; 4 10/29/02 6:56p Sivagarn
; Code to enable port 60h/64h trapping is added
;
; 3 10/14/02 9:03p Sivagarn
; * Code cleanup and header update
;
; 2 9/23/02 4:53p Sivagarn
; Bug in USB_MODE 3 is corrected (F000h segment is corrupted because of
; wrong code fall through)
;
; 1 9/15/02 5:39p Sivagarn
; Initial AMIUSB 2.20 check-in
;
;***************************************************************************;
;----------------------------------------------------------------------------
; Global options are defined here
;----------------------------------------------------------------------------
OPTION PROC:PRIVATE
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Macro and equate files are included here
;----------------------------------------------------------------------------
INCLUDE equates.equ
INCLUDE usbflag.equ
INCLUDE usb.equ
INCLUDE mbiosequ.equ
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; External function definitions are defined here
;----------------------------------------------------------------------------
USBGetNextHCStruc PROTO NEAR SYSCALL ; HCStruc in SI
USBCallAllHC PROTO NEAR SYSCALL ; wAPIOffset in BX
USBStartHC PROTO NEAR SYSCALL
farUSBExtAPIHandler PROTO FAR SYSCALL ; eLINK
;;USBMoveDataArea PROTO SYSCALL
IF MKF_USB_DEV_MASS
USBMassGetDeviceInfo PROTO NEAR SYSCALL
USBMassCmdPassThru PROTO NEAR SYSCALL
USBMassCheckDeviceReady PROTO NEAR SYSCALL
USBMassRWVCommand PROTO NEAR SYSCALL
USBMassStartUnitCommand PROTO NEAR SYSCALL
USBMassUpdateDeviceGeometry PROTO NEAR SYSCALL
USBMassReadCapacityCommand PROTO NEAR SYSCALL
USBMassGetFormatType PROTO NEAR SYSCALL
ENDIF ; MKF_USB_DEV_MASS
USBGetDataSegment PROTO NEAR SYSCALL
USBGetDeviceInfoStruc PROTO NEAR SYSCALL
USBPort_UpdateDataAreaTable PROTO NEAR SYSCALL
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Public function definitions are defined here
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Function prototype definitions are here
;----------------------------------------------------------------------------
USBWrap_FindHCDriver PROTO NEAR C bHCType:BYTE
USBWrapGetATAErrorCode PROTO NEAR SYSCALL
USBWrap_GetDeviceCount PROTO NEAR SYSCALL
USBWrap_GetHCStruc PROTO NEAR C bHCType:BYTE, wHCAddress:WORD
USBWrap_GetnthDeviceInfoStruc PROTO NEAR SYSCALL
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; External data definitions are here
;----------------------------------------------------------------------------
HCTable PROTO NEAR
EXTERN DeviceInfoTable:NEAR
EXTERN DeviceInfoTableEnd:NEAR
EXTERN USBDataAreaSignature:DWORD
EXTERN USBBiosActive:BYTE
EXTERN USBAcquiredByOS:BYTE
EXTERN dUSBInitFlag:DWORD
IF MKF_USB_MODE GE 2
EXTERN dTimeLastInSMI:DWORD
ENDIF
;----------------------------------------------------------------------------
; D A T A S E G M E N T
;----------------------------------------------------------------------------
USB_DSEG SEGMENT PARA PUBLIC 'DATA'
USB_DSEG ENDS
;----------------------------------------------------------------------------
; C O D E S E G M E N T
;----------------------------------------------------------------------------
USB_CSEG SEGMENT WORD USE16 PUBLIC 'CODE'
ASSUME cs:USB_CSEG
ASSUME ds:USB_DSEG
.586p
PUBLIC _USBWRAP_ASM_START
_USBWRAP_ASM_START LABEL BYTE
;<AMI_THDR_START>
;----------------------------------------------------------------------------
; Name: UsbApiTable - USB API Function Dispatch Table
;
; Type: Function Dispatch Table
;
; Description: This is the table of functions used by USB API
;
; Notes: This functions are invoked via software SMI
;
;----------------------------------------------------------------------------
;<AMI_THDR_END>
UsbApiTable_Start LABEL WORD
WORD OFFSET USBAPI_CheckPresence ; API 00h
WORD OFFSET USBAPI_Start ; API 20h
WORD OFFSET USBAPI_Stop ; API 21h
WORD OFFSET USBAPI_DisableInterrupts ; API 22h
WORD OFFSET USBAPI_EnableInterrupts ; API 23h
WORD OFFSET USBAPI_MoveDataArea ; API 24h
WORD OFFSET USBAPI_GetDeviceInfo ; API 25h
WORD OFFSET USBAPI_CheckDevicePresence ; API 26h
WORD OFFSET USBAPI_MassDeviceRequest ; API 27h
WORD OFFSET USBAPI_PowerManageUSB ; API 28h
WORD OFFSET USBAPI_PrepareForOS ; API 29h
UsbApiTable_End:
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: farUSBWrap_ApiHandler
;
; Description: This function dispatches the USB Request Packets (URP) to
; the appropriate functions.
;
; Input: ES:BX Pointer to the URP structure
;
; Output: bRetValue Zero on successfull completion
; Non-zero on error
;
; Modified: Nothing
;
; Referrals: UsbApiTable, URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
farUSBWrap_ApiHandler PROC FAR SYSCALL PUBLIC
IF MKF_USB_MODE EQ 3
EXTERN farUSBSMIHandler:FAR
push ax
push es
pop ax
cmp ax, 0FFFFh
pop ax
jne fUWAH_Continue
call farUSBSMIHandler
ret
fUWAH_Continue:
ENDIF
push ax
push bx
push si
push es
; Get the function number in AL
movzx ax, (URP_STRUC PTR es:[bx]).bFuncNumber
; Make sure function number is valid and then set AX to the offset
; of the function that is being called.
or al, al
je UAH_Cont0
; Function number is not zero check for valid USB 2.0 API function
cmp al, USB_NEW_API_START_FUNC
jb UAH_InvalidFunc
sub al, (USB_NEW_API_START_FUNC - 1)
UAH_Cont0:
cmp al, (UsbApiTable_End - UsbApiTable_Start) / 2
jb UAH_ValidFunc ; Br if valid function number
add al, (USB_NEW_API_START_FUNC - 1)
; Check for extended API function
cmp al, USB_EXT_API_START_FUNC
jb UAH_InvalidFunc
cmp al, USB_EXT_API_END_FUNC
ja UAH_InvalidFunc
; Invoke the extended API eLink with URP_Struc in the ES:BX and
; with AL = function number
call farUSBExtAPIHandler ; eLink
; Returns AL with the return code
jmp SHORT UAH_CallAbort
UAH_InvalidFunc:
; Invalid function number. Set the error code
mov al, USBAPI_INVALID_FUNCTION
jmp UAH_CallAbort ; Return to caller
; If calling functions 02h - 0Ah, the USB BIOS must be running the USB HC.
; Generate an error if this condition is not met.
UAH_ValidFunc:
shl ax, 1 ; AX = function number * 2
mov si, ax
mov al, 0FFh ; Failure
; Check the validity of the function
cmp WORD PTR CS:[si + UsbApiTable_Start], 0
je UAH_CallAbort ; Null pointer
; Setup input registers from caller's inputs
; ES:BX far pointer to URP structure
call NEAR PTR CS:[si + UsbApiTable_Start] ; AX - Return value
;; INVOKE API_FUNC_PTR PTR cs:[si + UsbApiTable_Start], fpURPPointer
UAH_CallAbort:
mov (URP_STRUC PTR es:[bx]).bRetValue, al
pop es
pop si
pop bx
pop ax
ret
farUSBWrap_ApiHandler ENDP
IF MKF_USB_DEV_MASS
;<AMI_THDR_START>
;----------------------------------------------------------------------------
; Name: USBMassAPITable - USB Mass Storage API Function Dispatch Table
;
; Type: Function Dispatch Table
;
; Description: This is the table of functions used by USB Mass Storage API
;
; Notes:
;
;----------------------------------------------------------------------------
;<AMI_THDR_END>
USBMassAPITable_Start:
DW USBMassAPIGetDeviceInformation ; USB Mass API Sub-Func 00h
DW USBMassAPIGetDeviceGeometry ; USB Mass API Sub-Func 01h
DW USBMassAPIResetDevice ; USB Mass API Sub-Func 02h
DW USBMassAPIReadDevice ; USB Mass API Sub-Func 03h
DW USBMassAPIWriteDevice ; USB Mass API Sub-Func 04h
DW USBMassAPIVerifyDevice ; USB Mass API Sub-Func 05h
DW USBMassAPIFormatDevice ; USB Mass API Sub-Func 06h
DW USBMassAPICommandPassThru ; USB Mass API Sub-Func 07h
DW USBMassAPIAssignDriveNumber ; USB BIOS API function 08h
USBMassAPITable_End:
ENDIF ; MKF_USB_DEV_MASS
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBAPI_MassDeviceRequest
;
; Description: This routine services the USB API function number 27h. It
; handles all the mass storage related calls from the higher
; layer. Different sub-functions are invoked depending on
; the sub-function number
;
; Input: ES:BX Pointer to the URP structure
; fpURPPointer.bSubFunc Subfunction number
; 00 Get Device Information
; 01 Get Device Parameter
; 02 Reset Device
; 03 Read Device
; 04 Write Device
; 05 Verify Device
; 06 Format Device
; 07 Command Pass Through
; 08 Assign drive number
;
; Output: URP structure is updated with the relevant information
; AX Return value
;
; Modified: EAX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBAPI_MassDeviceRequest PROC NEAR SYSCALL PUBLIC USES DS ES BX SI
IF MKF_USB_DEV_MASS
; Get the sub-function number
mov al, (URP_STRUC PTR es:[bx]).bSubFunc
; Make sure function number is valid and then set BP to the offset
; of the function that is being called
cmp al, (USBMassAPITable_End - USBMassAPITable_Start) / 2
jb UAMDR_ValidFunction
mov al, USBAPI_INVALID_FUNCTION
jmp SHORT UAMDR_Exit
UAMDR_ValidFunction:
; Valid function number
shl ax, 1 ; AX = Function number * 2
mov si, ax
; Set the data segment
xor ax, ax ; Get current segment
call USBGetDataSegment
mov ax, USB_ERROR
jnz UAMDR_DispatchFunction
; Error in getting data segment
; Check for first mass storage function
or si, si
jnz UAMDR_Exit
; Return 0FFh in the device address field
mov (URP_STRUC PTR ES:[bx]).ApiData.MassGetDevInfo.bDevAddr, 0FFh
jmp SHORT UAMDR_Exit
UAMDR_DispatchFunction:
; DS - USB data segment
add si, OFFSET USBMassAPITable_Start
; Push the return address
push OFFSET UAMDR_ReturnAddress
push WORD PTR CS:[si]
; For sub-function number 0, no need to get device info structure
cmp si, OFFSET USBMassAPITable_Start
jz UAMDR_InvokeFunction
; Get the DeviceInfo pointer from the device info structure number
push bx
mov al, (URP_STRUC PTR es:[bx]).ApiData.MassReset.bDevAddr
mov bl, SIZE DeviceInfo
mul bl
add ax, OFFSET DeviceInfoTable
mov bx, ax
; Check whether the entry is valid
test (DeviceInfo PTR [bx]).bFlag, DEV_INFO_VALID_STRUC
jz UMADR_NotValid ; Entry not valid
; Check whether device is connected to it
test (DeviceInfo PTR [bx]).bFlag, DEV_INFO_DEV_PRESENT
jnz UMADR_AXValid ; Entry valid!
UMADR_NotValid:
xor ax, ax
UMADR_AXValid:
pop bx
or ax, ax
jnz UMADR_SetDevInfo
UMADR_SetFuncFailure:
; Adjust stack (it has two words)
pop ax
pop ax
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -