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

📄 usbhub.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 2 页
字号:
; wIndex = Port number, wValue = 0, fpBuffer = DS:DI and wlength = 4
	call	USBIssueControlTransfer		; Retries
	; ZR - on error, NZ on success

	pushf
	mov	ax, WORD PTR dTempHubPortStatus	; AX[Bit0]=Connect status,
						; AX[BIT9]=Speed
	popf
	pop	di
	ret
USBHubGetPortStatusFromDevice		ENDP


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBHub_GetPortStatus
;
; Description:	This routine returns the hub port status
;
; Input: 	DH	USB device address of the hub whose status
;			has changed
;			bit 7	: 1 - Root hub, 0 for other hubs
;			bit 6-0	: Device address of the hub
;		DL	Port number
;		SI	HCStruc of the host controller
;
; Output: 	AL	Port status flags (Refer USB_PORT_STAT_XX equates)
;
; Modified:	AX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBHub_GetPortStatus	PROC NEAR SYSCALL PUBLIC USES BX CX DX SI DI

	LOCAL	bStatus:BYTE, wTemp:WORD

; Get DeviceInfo pointer in AX
	xchg	dh, dl
	call	USBGetDeviceInfoFromDevAddr	; DL - Device address
	xchg	dh, dl
	mov	bx, ax

; Reset the hub port
; SI - HCStruc pointer
; DX - Hub address and port number
	call	USBHub_EnablePort

; Perform control transfer with device request as HUB_RQ_GET_PORT_STATUS,
; wIndex = Port number, wValue = 0, fpBuffer = DS:DI and wlength = 4
	call	USBHubGetPortStatusFromDevice
	jz	UHGPS_Exit		; Br if error during command

; AX	Status returned from the hub
	mov	bStatus, 0

; Check the device present status in the hub
	test	ax, HUB_PORT_STATUS_DEVICE_PRESENT
	jz	UHGPS_CheckSpeed

; Device present set appropriate flag
	or	bStatus, USB_PORT_STAT_DEV_CONNECTED

UHGPS_CheckSpeed:

; Assume it as low speed device
	or	bStatus, USB_PORT_STAT_DEV_LOWSPEED

; Check the device speed status
	test	ax, HUB_PORT_STATUS_LOW_SPEED
	jnz	UHGPS_CheckStatusChange		; Yes.It is a low speed dev.

; It is either a full speed of high speed device

; Assume it as a high speed device
	and	bStatus, NOT USB_PORT_STAT_DEV_SPEED_MASK
	or	bStatus, USB_PORT_STAT_DEV_HISPEED

; Check the device speed status
	test	ax, HUB_PORT_STATUS_HIGH_SPEED
	jnz	UHGPS_CheckStatusChange		; Yes.It is a high speed dev.

; No. It is a full speed device
	and	bStatus, NOT USB_PORT_STAT_DEV_SPEED_MASK
	or	bStatus, USB_PORT_STAT_DEV_FULLSPEED

UHGPS_CheckStatusChange:

; Check for connect status change
	test	BYTE PTR dTempHubPortStatus+2, HUB_PORT_STATUS_CHANGE_CONNECT
	jz	UHGPS_BitStatusDone

; Set bit to indicate the device connect status change
	or	bStatus, USB_PORT_STAT_DEV_CONNECT_CHANGED

UHGPS_BitStatusDone:

; Clear any status change bits that are set (connect change, enable change,
; suspend change, over-current change, reset change).

; Perform control transfer with device request as HUB_RQ_GET_PORT_STATUS,
; wIndex = Port number, wValue = 0, fpBuffer = DS:DI and wlength = 4
	mov	cx, HUB_FEATURE_PORT_CONNECT_CHANGE
	mov	ax, WORD PTR dTempHubPortStatus+2	; AX = Status change bits
	and	ax, (HUB_PORT_STATUS_CHANGE_CONNECT OR \
			HUB_PORT_STATUS_CHANGE_ENABLE OR \
			HUB_PORT_STATUS_CHANGE_SUSPEND OR \
			HUB_PORT_STATUS_CHANGE_OVERCURRENT OR \
			HUB_PORT_STATUS_CHANGE_RESET)
	mov	wTemp, ax

UHGPS_StatusClearNext:

; Set wIndex in EBX+
	movzx	ax, dl
	push	ax
	push	bx
	pop	ebx

	mov	ax, cx
	sub	ax, 16			; Starts from 16
	bt	wTemp, ax		; CF = wTemp bit ax
	jnc	UHGPS_CheckNextFeature

; Set request type & wValue
	mov	eax, (HUB_RQ_CLEAR_PORT_FEATURE SHL 16)
	mov	ax, cx

; Invoke the control transfer function in the HCD
; BX - pDevInfo
	call	USBIssueControlTransferWithoutData	; Retries
	; ZR - on error, NZ on success

uHGPS_CheckNextFeature:
	inc	cx
	cmp	cx, HUB_FEATURE_PORT_RESET_CHANGE
	jbe	UHGPS_StatusClearNext	;Br if not past last feature/status bit

	mov	al, bStatus
UHGPS_Exit:
	ret
USBHub_GetPortStatus	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBHub_EnablePort
;
; Description:	This routine enables the hub port
;
; Input: 	DH	USB device address of the hub whose status
;			has changed
;			bit 7	: 1 - Root hub, 0 for other hubs
;			bit 6-0	: Device address of the hub
;		DL	Port number
;		SI	HCStruc of the host controller
;
; Output: 	ZR	On error
;		NZ	On success
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBHub_EnablePort	PROC NEAR SYSCALL PUBLIC USES EBX CX SI DI

; Delay for 100ms allowing power to settle.
	mov	ax, ((100 * 1000) / 15)	; 100ms delay
	call	USBMisc_FixedDelay

; Check whether it is for root hub or for USB hub
	test	dh, BIT7
	jz	UHEP_EnableStdHub	; Br if not enabling port on root hub

; Call appropriate controller to enable the root hub status
	mov	al, dl
; SI	HCStruc pointer
; Move pointer parameter to register
	mov	bx, (HCStruc PTR [si]).pHCDPointer
	call	(HCDHEADER PTR cs:[bx]).pHCDEnableRootHub
	jmp	UHEP_Done

UHEP_EnableStdHub:

; Get DeviceInfo pointer in AX
	xchg	dh, dl
	call	USBGetDeviceInfoFromDevAddr	; DL - Device address
	xchg	dh, dl
	mov	bx, ax

; Reset the device attached to the hub by setting the hub/port's reset feature.

; Perform control transfer with device request as HUB_RQ_SET_PORT_FEATURE,
; wIndex = Port number, wValue = HUB_FEATURE_PORT_RESET,
; fpBuffer = 0 and wlength = 0

; Set wIndex in EBX+
	movzx	ax, dl
	push	ax
	push	bx
	pop	ebx

; Set request type & wValue
	mov	eax, (HUB_RQ_SET_PORT_FEATURE SHL 16) + HUB_FEATURE_PORT_RESET

; Invoke the control transfer function in the HCD
; BX - pDevInfo
	call	USBIssueControlTransferWithoutData	; Retries
	; ZR - on error, NZ on success
	jz	UHEP_Done	; Br if error during command

; Wait for the hub to complete its port reset sequence by sending a GetPortStatus
; command to the hub.

	mov	cx, 10		; Time out after 10 iterations
UHEP_WaitReset:
	mov	ax, ((100 * 1000) / 15)	; 100ms delay
	call	USBMisc_FixedDelay

	dec	cx			; Decrement time out counter

	stc				; Set CF in case this jz jumps
	jz	SHORT UHEP_Done		; Branch if timeout waiting
					; for reset completed

; Perform control transfer with device request as HUB_RQ_GET_PORT_STATUS,
; wIndex = Port number, wValue = 0, fpBuffer = DS:DI and wlength = 4
	call	USBHubGetPortStatusFromDevice
	jz	UHEP_Done		; Branch if error during command

	test	dTempHubPortStatus, HUB_PORT_STATUS_RESET
	jnz	UHEP_WaitReset		; Branch if hub has not completed
					; reset yet

UHEP_ResetDone:

; Acknowledge the reset by clearing the port's reset change feature.

; Perform control transfer with device request as HUB_RQ_CLEAR_PORT_FEATURE,
; wIndex = Port number, wValue = HUB_FEATURE_PORT_RESET_CHANGE,
; fpBuffer = 0 and wlength = 0
; Set wIndex in EBX+
	movzx	ax, dl
	push	ax
	push	bx
	pop	ebx

; Set request type & wValue
	mov	eax, (HUB_RQ_CLEAR_PORT_FEATURE SHL 16) + HUB_FEATURE_PORT_RESET_CHANGE
; Invoke the control transfer function in the HCD
; BX - pDevInfo
	call	USBIssueControlTransferWithoutData	; Retries
	; ZR - on error, NZ on success
	jz	UHEP_Done		;Br if error during command

; Delay for the required time after reseting a USB device.
	mov	ax, ((100 * 1000) / 15)	; 100ms delay
	call	USBMisc_FixedDelay

; Clear ZR flag
	or	sp, sp
UHEP_Done:
	ret
USBHub_EnablePort	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBHub_DisablePort
;
; Description:	This routine disables the hub port
;
; Input: 	DH	USB device address of the hub whose status
;			has changed
;			bit 7	: 1 - Root hub, 0 for other hubs
;			bit 6-0	: Device address of the hub
;		DL	Port number
;		SI	HCStruc of the host controller
;
; Output: 	ZR	On error
;		NZ	On success
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBHub_DisablePort	PROC NEAR SYSCALL PUBLIC USES EBX SI DI

; Get DeviceInfo pointer in AX
	xchg	dh, dl
	call	USBGetDeviceInfoFromDevAddr	; DL - Device address
	xchg	dh, dl
	mov	bx, ax

; Disable the hub/port by clearing its Enable feature

; Perform control transfer with device request as HUB_RQ_CLEAR_PORT_FEATURE,
; wIndex = Port number, wValue = HUB_FEATURE_PORT_ENABLE,
; fpBuffer = 0 and wlength = 0

; Set wIndex in EBX+
	movzx	ax, dl
	push	ax
	push	bx
	pop	ebx

; Set request type & wValue
	mov	eax, (HUB_RQ_CLEAR_PORT_FEATURE SHL 16) OR HUB_FEATURE_PORT_ENABLE

; Invoke the control transfer function in the HCD
; BX - pDevInfo
	call	USBIssueControlTransferWithoutData	; Retries
; ZR - on error, NZ on success

Comment ~
; Set wIndex in EBX+
	movzx	ax, dl
	push	ax
	push	bx
	pop	ebx

; Set request type & wValue
	mov	eax, (HUB_RQ_CLEAR_PORT_FEATURE SHL 16) OR HUB_FEATURE_PORT_ENABLE

; Invoke the control transfer function in the HCD
; BX - pDevInfo
	call	USBIssueControlTransferWithoutData	; Retries
	; ZR - on error, NZ on success
; Return value in AX
EndComment ~

UHDP_DisablePortDone:
	ret
USBHub_DisablePort	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBHub_ProcessHubData
;
; Description:	This routine is called with USB hub status change
;		report data
;
; Input: 	SI	Pointer to HCStruc
;		BX	Pointer to device information structure
;		DI	Pointer to the data buffer
;
; Output: 	Nothing
;
; Modified:	Nothing
;
; Notes:	The status change data is an array of bit flags:
;			Bit		Description
;		----------------------------------------------------------
;			0	Indicate connect change status for all ports
;			1	Indicate connect change status for port 1
;			2	Indicate connect change status for port 2
;			...		..............
;			n	Indicate connect change status for port n
;		-----------------------------------------------------------
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBHub_ProcessHubData	PROC NEAR SYSCALL PUBLIC USES EAX BX DX SI DI

; Check for enum flag and avoid hub port enumeration if needed
	cmp	bEnumFlag, TRUE
	je	UHPHD_Exit

IFDEF	USB_HUB_REVERSE_PORT_SCAN_ORDER
	mov	dl, (DeviceInfo PTR [bx]).bHubNumPorts
ELSE
	mov	dl, 1		; Ports on the hub (1-N)
ENDIF

UHPHD_NextPort:

	movzx	ax, dl			; AX = port number on hub to check
	bt	WORD PTR [di], ax
	jnc	UHPHD_SkipPort		; Br if no change on port AX

	mov	dh, (DeviceInfo PTR [bx]).bDeviceAddress

	mov	bEnumFlag, TRUE		; Set enumeration flag so that another device
					; will not get enabled

; Handle hub port connect/disconnect change
; DH - Hub number
; DL - Port number
; SI - HCStruc pointer
	call	USBCheckPortChange

	mov	bEnumFlag, FALSE	; Reset enumeration flag so that other devices
					; can be enumerated

UHPHD_SkipPort:
IFDEF	USB_HUB_REVERSE_PORT_SCAN_ORDER
	dec	dl
	jnz	UHPHD_NextPort
ELSE
	inc	dl
	cmp	dl, (DeviceInfo PTR [bx]).bHubNumPorts
	jbe	UHPHD_NextPort		;Br if more ports on hub to check
ENDIF

UHPHD_Exit:

	ret

USBHub_ProcessHubData	ENDP

	PUBLIC	_USBHUB_ASM_END
_USBHUB_ASM_END		LABEL		BYTE

;----------------------------------------------------------------------------
;			END OF ROUTINES
;----------------------------------------------------------------------------

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 + -