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

📄 usbwrap.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 4 页
字号:
; Call the USB move data area function
	mov	ax, (URP_STRUC PTR es:[bx]).ApiData.StartHc.wDataAreaFlag
	call	USBMoveDataArea

	mov	(URP_STRUC PTR es:[bx]).ApiData.StartHc.wDataAreaFlag, ax
	cmp	ax, 0FFFFh
	je	UMDA_ErrorExit

	mov	al, USB_SUCCESS
	jmp	SHORT UMDA_Exit

UMDA_ErrorExit:
EndComment ~
	mov	al, USB_ERROR
UMDA_Exit:
	ret
USBAPI_MoveDataArea	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBAPI_GetDeviceInfo
;
; Description:	This routine returns the information regarding
;		a USB device like keyboard, mouse, floppy drive etc
;
; Input: 	ES:BX			URP structure with input parameters
;		GetDevInfo.bDevNumber	Device number (1-based) whose
;					information is requested
;
; Output: 	URP structure is updated with the following information
;		GetDevInfo.bHCNumber	HC number in which the device
;					is found
;		GetDevInfo.bDevType	Type of the device
;		AL	
;			USB_SUCCESS 		on successfull completion
;			USB_PARAMETER_ERROR 	if bDevNumber is invalid
;			USB_ERROR		on error
;
; Modified:	AX
;
; Referrals:	URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBAPI_GetDeviceInfo	PROC NEAR SYSCALL  USES BX DX SI DS

; Initialize the return values
	xor	ax, ax
	mov	(URP_STRUC PTR es:[bx]).ApiData.GetDevInfo.bHCNumber, al
	mov	(URP_STRUC PTR es:[bx]).ApiData.GetDevInfo.bDevType, al

	mov	dx, USB_ERROR

; Check for parameter validity
	mov	al, (URP_STRUC PTR es:[bx]).ApiData.GetDevInfo.bDevNumber
	or	al, al
	jz	UWGDI_Exit

; Get and set the data segment address
	xor	ax, ax		; Get current segment
	call	USBGetDataSegment
	jz	UWGDI_Exit

; DS - USB data segment

	mov	dx, USB_PARAMETER_ERROR
; Get the device information structure for the 'n'th device
	mov	al, (URP_STRUC PTR es:[bx]).ApiData.GetDevInfo.bDevNumber
	call	USBWrap_GetnthDeviceInfoStructure

	or	ax, ax
	jz	UWGDI_Exit

	mov	si, ax

; Return value
	mov	al, (DeviceInfo PTR [si]).bDeviceType
	mov	(URP_STRUC PTR es:[bx]).ApiData.GetDevInfo.bDevType, al

	mov	si, (DeviceInfo PTR [si]).pHCStrucPtr
	mov	al, (HCStruc PTR [si]).bHCNumber
	mov	(URP_STRUC PTR es:[bx]).ApiData.GetDevInfo.bHCNumber, al
	mov	dx, USB_PARAMETER_ERROR

UWGDI_Exit:
	mov	ax, dx
	ret
USBAPI_GetDeviceInfo	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBAPI_CheckDevicePresence
;
; Description:	This routine checks whether a particular type of USB device
;		is installed in the system or not.
;
; Input: 	ES:BX			URP structure with input parameters
;		ChkDevPrsnc.bDevType	Device type to found
;
; Output: 	AX	will be one of the following value
;		USB_SUCCESS 		if device type present
;		USB_PARAMETER_ERROR 	if device type not present
;		USB_ERROR		on error
;
; Modified:	AX
;
; Referrals:	URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBAPI_CheckDevicePresence	PROC NEAR SYSCALL USES DS

; Get and set the data segment address
	xor	ax, ax		; Get current segment
	call	USBGetDataSegment
	jz	UWCDP_Exit

; DS - USB data segment

; Get device type to found
	mov	al, (URP_STRUC PTR es:[bx]).ApiData.ChkDevPrsnc.bDevType
	call	USBGetDeviceInfoStruc
	or	ax, ax
	jz	UWCDP_EntryNotFound

; Device type found
	mov	ax, USB_SUCCESS
	jmp	SHORT UWCDP_Exit


UWCDP_EntryNotFound:
; Indicate device not present
	mov	ax, USB_PARAMETER_ERROR

UWCDP_Exit:
	ret
USBAPI_CheckDevicePresence	ENDP


IF MKF_USB_DEV_MASS

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMassAPIGetDeviceInformation
;
; 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
;		    bDevAddr	USB device address of the device
;
; Output: 	AX		Return value
;		fpURPPointer	Pointer to the URP structure
;			dSenseData	Sense data of the last command
;			bDevType	Device type byte (HDD, CD, Removable)
;			bEmuType	Emulation type used
;			fpDevId		Far pointer to the device ID
;
; Modified:	AX
;
; Referrals:	URP_STRUC
;
; Notes:	Initially the bDevAddr should be set to 0 as input. This
;		function returns the information regarding the first mass
;		storage device (if no device found it returns bDevAddr as
;		0FFh) and also updates bDevAddr to the device address of
;		the current mass storage device. If no other mass storage
;		device is found then the routine sets the bit7 to 1
;		indicating current information is valid but no more mass
;		device found in the system. The caller can get the next
;		device info if bDevAddr is not 0FFh and bit7 is not set
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMassAPIGetDeviceInformation	PROC NEAR SYSCALL PUBLIC USES BX

; Load the registers with input parameters
	add	bx, URP_STRUC.ApiData.MassGetDevInfo
	call	USBMassGetDeviceInfo
; Return value in AX
; Return the error code properly

	ret
USBMassAPIGetDeviceInformation	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMassAPIGetDeviceGeometry
;
; Description:	This function is part of the USB BIOS MASS API. This function
;		returns the geometry of the mass storage device
;
; Input: 	ES:BX		Pointer to the URP structure
;		SI		Pointer to device info structure
;
; Output: 	AX		Return value
;		fpURPPointer	Pointer to the URP structure
;			dSenseData	Sense data of the last command
;			bNumHeads	Number of heads
;			wNumCylinders	Number of cylinders
;			bNumSectors	Number of sectors
;			bLBANumHeads	Number of heads (for INT13h func 48h)
;			wLBANumCyls	Number of cylinders (for INT13h func 48h)
;			bLBANumSectors	Number of sectors (for INT13h func 48h)
;			wBytesPerSector	Number of bytes per sector
;			bMediaType	Media type
;			dLastLBA	Last addressable LBA
;
; Modified:	AX
;
; Referrals:	URP_STRUC, MASS_GET_DEV_GEO, DeviceInfo, MassDeviceInfo
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMassAPIGetDeviceGeometry	PROC NEAR SYSCALL PUBLIC

	push	bx
	push	dx
	push	di

; Load the registers with input parameters
	add	bx, URP_STRUC.ApiData.MassGetDevGeo

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


; Get & update geometry information
	cmp	(MassDeviceInfo PTR [di]).wBlockSize, 0
	je	UMAGDG_GetDevData

	cmp	(MassDeviceInfo PTR [di]).wBlockSize, 0FFFFh
	jne	UMAGDG_Done

UMAGDG_GetDevData:

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

UMAGDG_Done:


	mov	ax, (MassDeviceInfo PTR [di]).wBlockSize
	mov	(MASS_GET_DEV_GEO PTR ES:[bx]).wBytesPerSector, ax

	mov	al, (MassDeviceInfo PTR [di]).bHeads
	mov	(MASS_GET_DEV_GEO PTR ES:[bx]).bLBANumHeads, al

	mov	al, (MassDeviceInfo PTR [di]).bSectors
	mov	(MASS_GET_DEV_GEO PTR ES:[bx]).bLBANumSectors, al

	mov	ax, (MassDeviceInfo PTR [di]).wCylinders
	mov	(MASS_GET_DEV_GEO PTR ES:[bx]).wLBANumCyls, ax

	mov	al, (MassDeviceInfo PTR [di]).bNonLBAHeads
	mov	(MASS_GET_DEV_GEO PTR ES:[bx]).bNumHeads, al

	mov	al, (MassDeviceInfo PTR [di]).bNonLBASectors
	mov	(MASS_GET_DEV_GEO PTR ES:[bx]).bNumSectors, al

	mov	ax, (MassDeviceInfo PTR [di]).wNonLBACylinders
	mov	(MASS_GET_DEV_GEO PTR ES:[bx]).wNumCylinders, ax

	mov	al, (MassDeviceInfo PTR [di]).bMediaType
	mov	(MASS_GET_DEV_GEO PTR ES:[bx]).bMediaType, al

	mov	eax, (MassDeviceInfo PTR [di]).dMaxLBA
	mov	(MASS_GET_DEV_GEO PTR ES:[bx]).dLastLBA, eax

; Set function as success
	mov	ax, USB_SUCCESS

; Return value in AX
	pop	di
	pop	dx
	pop	bx
	ret
USBMassAPIGetDeviceGeometry	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMassAPIResetDevice
;
; 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 pointer
;
; Output: 	AX	Return value
;
; Modified:	AX
;
; Referrals:	URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMassAPIResetDevice		PROC NEAR SYSCALL PUBLIC USES EDX SI

; SI - DeviceInfo pointer
	call	USBMassStartUnitCommand		; EDX - Sense code
	jnz	UMARD_SuccessExit

; EDX - Sense code
	call	USBWrapGetATAErrorCode
	movzx	dx, al
	mov	(URP_STRUC PTR es:[bx]).bRetValue, al

; Set the bRetValue with appropriate error code
	jmp	SHORT UMARD_Exit

UMARD_SuccessExit:
; Set function as success
	mov	dx, USB_SUCCESS

UMARD_Exit:
	mov	ax, dx
; Return value in AX
	ret
USBMassAPIResetDevice		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMassAPIReadDevice
;
; 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 read
;			wPreSkipSize	Number of bytes to skip before
;			wPostSkipSize	Number of bytes to skip after
;			fpBufferPtr	Far buffer pointer
;
; Output: 	ES:BX	Pointer to the URP structure
;			bRetValue	Return value
;			dSenseData	Sense data of the last command
;		AX	Return code (0 - Failure, <>0 - Size read)
;
; Modified:	AX
;
; Referrals:	URP_STRUC, DeviceInfo
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMassAPIReadDevice		PROC NEAR SYSCALL PUBLIC

	mov	al, COMMON_READ_10_OPCODE

USBMassAPICommonRWV::

	push	cx
	push	dx
	push	si

; Save AL - Command code
	mov	dl, al

; Issue the appropriate command
	push	bx
	add	bx, URP_STRUC.ApiData.MassRead
; SI	DeviceInfo pointer
; ES:BX	Mass read/write/verify data
; dl	Command code
	call	USBMassRWVCommand
	or	ax, ax
	pop	bx
	jnz	UMRD_SuccessExit

	mov	edx, (URP_STRUC PTR es:[bx]).ApiData.MassRead.dSenseData
	call	USBWrapGetATAErrorCode
	movzx	cx, al
; Set the bRetValue with appropriate error code
	jmp	SHORT UMRD_Exit

UMRD_SuccessExit:
; Set function as success
	mov	cx, USB_SUCCESS

UMRD_Exit:
; Return value in AX
	mov	ax, cx
	pop	si
	pop	dx
	pop	cx
	ret
USBMassAPIReadDevice		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMassAPIWriteDevice
;
; 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:	Nothing
;
; Referrals:	URP_STRUC, DeviceInfo
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMassAPIWriteDevice		PROC NEAR SYSCALL PUBLIC
	mov	al, COMMON_WRITE_10_OPCODE
	jmp	SHORT USBMassAPICommonRWV

USBMassAPIWriteDevice		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------

⌨️ 快捷键说明

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