⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbwrap.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 4 页
字号:
; Procedure:	USBMassAPIVerifyDevice
;
; Description:	This function is part of the USB BIOS MASS API. This function
;		returns the device information of the mass storage device
;
; Input: 	ES:BX		Pointer to the URP structure
;		SI	DeviceInfo structure
;			bDevAddr	USB device address of the device
;			dStartLBA	Starting LBA address
;			wNumBlks	Number of blocks to write
;			wPreSkipSize	Number of bytes to skip before
;			wPostSkipSize	Number of bytes to skip after
;			fpBufferPtr	Far buffer pointer
;
; Output: 	fpURPPointer	Pointer to the URP structure
;			bRetValue	Return value
;			dSenseData	Sense data of the last command
;		AX	Return value
;
; Modified:	AX
;
; Referrals:	URP_STRUC, DeviceInfo
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMassAPIVerifyDevice		PROC NEAR SYSCALL PUBLIC

	mov	al, COMMON_VERIFY_OPCODE
	jmp	SHORT USBMassAPICommonRWV

USBMassAPIVerifyDevice		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMassAPIFormatDevice
;
; Description:	This function is part of the USB BIOS MASS API. This function
;		returns the device information of the mass storage device
;
; Input: 	ES:BX	Pointer to the URP structure
;		SI	DeviceInfo structure
;
; Output: 	AX	Return value
;
; Modified:	AX
;
; Referrals:	URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMassAPIFormatDevice		PROC NEAR SYSCALL PUBLIC 

	mov	ax, USB_SUCCESS
	ret
USBMassAPIFormatDevice		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMassAPICommandPassThru
;
; Description:	This function is part of the USB BIOS MASS API. This 
;		function can be used to pass raw command/data sequence to
;		the USB mass storage device
;
; Input: 	ES:BX	Pointer to the URP structure
;		SI	DeviceInfo structure
;
; Output: 	AX	Return value
;
; Modified:	AX
;
; Referrals:	URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMassAPICommandPassThru	PROC NEAR SYSCALL PUBLIC USES BX

; Load the registers with input parameters
	add	bx, URP_STRUC.ApiData.MassCmdPassThru
	call	USBMassCmdPassThru
; Return code in AX
	ret
USBMassAPICommandPassThru	ENDP

;<AMI_PHDR_START>
;-----------------------------------------------------------------------------
; Procedure:	USBMassAPIAssignDriveNumber
;
; Description:	This function is part of the USB BIOS MASS API. This function
;		assigns the logical drdevice information of the mass storage device
;
; Input: 	ES:BX	Pointer to the URP structure
;			bDevAddr	USB device address of the device
;			bLogDevNum	Logical Drive Number to assign to the device
;		SI	DeviceInfo structure
;
; Output: 	AX	Return code (0 - Failure, 0FFFFh - Success)
;
; Destroys: 	AX
;
; Referrals:	URP_STRUC
;
;------------------------------------------------------------------------------;
;<AMI_PHDR_END>

USBMassAPIAssignDriveNumber PROC NEAR SYSCALL PUBLIC USES DX BX DI SI ES

	mov	dx, USB_ERROR

; Get mass info pointer
	mov	di, (DeviceInfo PTR [si]).pMassInfoPtr

; Set the device as registered
	or	(DeviceInfo PTR [si]).bFlag, DEV_INFO_MASS_DEV_REGD

; Update device drive number
	mov	al, (URP_STRUC PTR es:[bx]).ApiData.MassAssignNum.bLogDevNum
	mov	(MassDeviceInfo PTR [di]).bDriveNumber, al

	mov	dx, USB_SUCCESS			; No errors expected after this point

	cmp	(MassDeviceInfo PTR [di]).wBlockSize, 0
	je	UMADN_GetDevData

	cmp	(MassDeviceInfo PTR [di]).wBlockSize, 0FFFFh
	jne	UMADN_Exit
UMADN_GetDevData:

; Get & update geometry information
	call	USBMassCheckDeviceReady		; SI - DeviceInfo

UMADN_Exit:

; Fill CHS information
	mov	al, (MassDeviceInfo PTR [di]).bHeads
	mov	(URP_STRUC PTR es:[bx]).ApiData.MassAssignNum.bHeads, al

	mov	al, (MassDeviceInfo PTR [di]).bSectors
	mov	(URP_STRUC PTR es:[bx]).ApiData.MassAssignNum.bSectors, al

	mov	ax, (MassDeviceInfo PTR [di]).wCylinders
	mov	(URP_STRUC PTR es:[bx]).ApiData.MassAssignNum.wCylinders, ax

	mov	ax, (MassDeviceInfo PTR [di]).wBlockSize
	mov	(URP_STRUC PTR es:[bx]).ApiData.MassAssignNum.wBlockSize, ax

	mov	al, (DeviceInfo PTR [si]).bLUN
	mov	(URP_STRUC PTR es:[bx]).ApiData.MassAssignNum.bLUN, al

; Set speed as full speed
	xor	ax, ax
	mov	al, (DeviceInfo PTR [si]).bEndPointSpeed
	or	al, al
	jnz	UMADN_SpeedSet
	inc	ah
UMADN_SpeedSet:
	mov	(URP_STRUC PTR es:[bx]).ApiData.MassAssignNum.bSpeed, ah

; Set the mass storage devices registered flag
	or	dUSBInitFlag, USB_MASS_DEVICES_REGISTERED
	ret
USBMassAPIAssignDriveNumber ENDP

ENDIF ; MKF_USB_DEV_MASS

;----------------------------------------------------------------------------
;			USB API Procedures Ends
;----------------------------------------------------------------------------

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBWrapGetATAError
;
; Description:	This routine converts the sense data information into
;		ATAPI error code
;
; Input: 	EDX	Sense data obtained from the device
;
; Output: 	AL - ATAPI error code
;
; Modified:	AL
;
; Referrals:
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBWrapGetATAErrorCode		PROC NEAR SYSCALL PUBLIC USES DX CX

	mov	al, 0
; Check for Sense code 0
	or	edx, edx
	jz	UMGAEC_Exit

	mov	cl, dl
	shr	edx, 8
	xchg	dh, dl

; CL - Sense Code
; DL - Additional Sense Code (ASC)
; DH - Additional Sense Code Qualifier (ASCQ)

; Check for drive not ready error
	mov	al, USB_ATA_DRIVE_NOT_READY_ERR
	cmp	dh, 028h
	je	UMGAEC_Exit

; Check for write protected data
	mov	al, USB_ATA_WRITE_PROTECT_ERR
	cmp	cl, 007h
	je	UMGAEC_Exit

; Check for timed out error
	mov	al, USB_ATA_TIME_OUT_ERR
	cmp	dx, 8080h
	je	UMGAEC_Exit

; Check for ECC error corrected state
	mov	al, USB_ATA_DATA_CORRECTED_ERR
	cmp	dh, 18h
	je	UMGAEC_Exit

; Check for address mark not found error
	mov	al, USB_ATA_MARK_NOT_FOUND_ERR
	cmp	dx, 600h
	je	UMGAEC_Exit

; Check for media not found error
;;	mov	al, USB_ATA_NO_MEDIA_ERR
	mov	al, USB_ATA_TIME_OUT_ERR
	cmp	dx, 03A00h
	je	UMGAEC_Exit

; Check for any read error
	mov	al, USB_ATA_READ_ERR
	cmp	dx, 1100h
	je	UMGAEC_Exit

; Check for ECC error
	mov	al, USB_ATA_UNCORRECTABLE_ERR
	cmp	dx, 1106h
	je	UMGAEC_Exit

; Check for bad sector
	mov	al, USB_ATA_BAD_SECTOR_ERR
	cmp	dh, 30h
	je	UMGAEC_Exit

; Set to general failure error
	mov	al, USB_ATA_GENERAL_FAILURE

; Check for parameter failed error
	cmp	dh, 20h
	jb	UMGAEC_Exit
	cmp	dh, 26h
	ja	UMGAEC_Exit

	mov	al, USB_ATA_PARAMETER_FAILED
UMGAEC_Exit:

	ret
USBWrapGetATAErrorCode		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBWrap_GetnthDeviceInfoStructure
;
; Description:	This routine finds the 'n'th device's DeviceInfo entry.
;
; Input: 	AL	Device number (1-based)
;
; Output: 	AX	DeviceInfo structure if found else 0
;
; Modified:	AX
;
; Referrals:
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBWrap_GetnthDeviceInfoStructure	PROC	NEAR SYSCALL USES BX CX

; Search through the DeviceInfo table to find the first device
	mov	bx, OFFSET DeviceInfoTable
	add	bx, SIZE DeviceInfo
	dec	al
	mov	cx, MAX_DEVICES

UGDIS_Loop:
; Check whether the entry is valid
	test	(DeviceInfo PTR [bx]).bFlag, DEV_INFO_VALID_STRUC
	jz	UGDIS_Cont		; Entry not valid check next

; Check whether device is connected to it
	test	(DeviceInfo PTR [bx]).bFlag, DEV_INFO_DEV_PRESENT
	jz	UGDIS_Cont		; Entry not valid check next

; Entry present. Check whether this is the entry we want.
	or	al, al
	jz	UGDIS_Exit		; Our entry found

; This is not the entry. Reduce the device number and check next device
	dec	al
UGDIS_Cont:
	add	bx, SIZE DeviceInfo
	loop	UGDIS_Loop

; Couldn't find the specified device number. Return error
	xor	bx, bx

UGDIS_Exit:
	mov	ax, bx			; return value
	ret
USBWrap_GetnthDeviceInfoStructure	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBWrap_GetDeviceCount
;
; Description:	This routine searches through the device entry table
;		and returns number of active USB devices configured
;		by the BIOS.
;
; Input: 	ES:BX	Far pointer to the URP
;
; Output: 	Following fields in the URP are modified
;		CkPresence.bNumBootDev	Number of USB boot devices found
;
; Modified:	Nothing
;
; Referrals:	URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBWrap_GetDeviceCount	PROC NEAR SYSCALL PUBLIC
	push	ax
	push	cx
	push	si
	push	di

	mov	si, OFFSET DeviceInfoTable
	add	si, SIZE DeviceInfo	; Skip zeroth entry
	mov	cx, MAX_DEVICES
	xor	ax, ax

; Set DI to the start of device specific count
	mov	di, bx
	dec	di
	add	di, URP_STRUC.ApiData.CkPresence.bNumKeyboards

UGDC_CheckNext:
	test	(DeviceInfo PTR [si]).bFlag, DEV_INFO_VALID_STRUC
	jz	UGDC_CheckForNextIteration

; Check whether device is connected to it
	test	(DeviceInfo PTR [si]).bFlag, DEV_INFO_DEV_PRESENT
	jz	UGDC_CheckForNextIteration

; Do not count devices greater than storage
	cmp	(DeviceInfo PTR [si]).bDeviceType, BIOS_DEV_TYPE_STORAGE
	ja	UGDC_CheckForNextIteration

; Valid entry found. Increment the count
	inc	ax

; Find the type and update the type specific count
	push	ax
	push	si
	push	di

	movzx	ax, (DeviceInfo PTR [si]).bDeviceType
	add	di, ax
	inc	BYTE PTR ES:[di]

; If the device type is storage update the emulation type count
	cmp	al, BIOS_DEV_TYPE_STORAGE
	jne	UGDC_NotStorage

; Get the emulation type
	mov	si, (DeviceInfo PTR [si]).pMassInfoPtr
	movzx	ax, (MassDeviceInfo PTR [si]).bDevType
	or	ax, ax
	jz	UGDC_NotStorage
	add	di, ax
	inc	BYTE PTR ES:[di]
UGDC_NotStorage:
	pop	di
	pop	si
	pop	ax

UGDC_CheckForNextIteration:
	add	si, SIZE DeviceInfo
	loop	UGDC_CheckNext

	mov	(URP_STRUC PTR es:[bx]).ApiData.CkPresence.bNumBootDev, al

	pop	di
	pop	si
	pop	cx
	pop	ax
	ret
USBWrap_GetDeviceCount	ENDP
 ; IFNDEF _BBLK_


	PUBLIC	_USBWRAP_ASM_END
_USBWRAP_ASM_END		LABEL		BYTE

;----------------------------------------------------------------------------

USB_CSEG	ENDS
;----------------------------------------------------------------------------

	END

;***************************************************************************;
;***************************************************************************;
;**                                                                       **;
;**           (C)Copyright 1985-2003, American Megatrends, Inc.           **;
;**                                                                       **;
;**                          All Rights Reserved.                         **;
;**                                                                       **;
;**                6145-F Northbelt Pkwy, Norcross, GA 30071              **;
;**                                                                       **;
;**                          Phone (770)-246-8600                         **;
;**                                                                       **;
;***************************************************************************;
;***************************************************************************;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -