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

📄 usbmbb.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 5 页
字号:

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBM_BOTGetMaxLUN
;
; Description:	This function gets the maximum logical unit number(LUN)
;		supported by the device.  It is zero based value.
;
; Input: 	None
;
; Output: 	AX	Max LUN supported
;
; Modified:	AX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBM_BOTGetMaxLUN		PROC NEAR SYSCALL PUBLIC
	push	si

; Get the interface number in ax
	movzx	ax, CurrentDevice.bInterfaceNum
	mov	CurrentDevice.CntrlXfer.wIndex, ax

; Set SI to the current devices device info structure
	mov	si, OFFSET CurrentDevice

; Set up receive buffer
	mov	wMassTempData, 0		; Indicate max LUN to 0
	push	ds
	push	OFFSET wMassTempData
	pop	eax
	mov	CurrentDevice.CntrlXfer.fpBuffer, eax

; Set data length
	mov	CurrentDevice.CntrlXfer.wLength, 1

; Set request type
	mov	CurrentDevice.CntrlXfer.wRequest, ADSC_IN_REQUEST_TYPE + (BOT_GET_MAX_LUN_REQUEST_CODE SHL 8)
	xor	ax, ax
	mov	CurrentDevice.CntrlXfer.wValue, ax

; Perform control transfer with device request as ADSC_IN_REQUEST_TYPE
; wIndex = Port number, wValue = 0, fpBuffer = DS:DI and wlength = 4
	push	bx
	mov	bx, CurrentHC.pHCDPointer
; Issue the HCD control transfer call
	call	(BBHCDHEADER PTR CS:[bx]).pHCDControlTransfer
	pop	bx
	; ZR - on error, NZ on success


; Return value in AX
	mov	al, BYTE PTR wMassTempData

	pop	si
	ret
USBM_BOTGetMaxLUN		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBM_IssueCBITransaction
;
; Description:	This function performs a mass storage transaction using CBI
;		or CB protocol.
;
; Input: 	stMassXactStruc
;		  pCmdBuffer	Pointer to command buffer
;		  bCmdSize	Size of command block
;		  bXferDir	Transfer direction
;		  fpBuffer	Data buffer far pointer
;		  dwLength	Amount of data to be transferred
;		  wPreSkip	Number of bytes to skip before data
;		  wPostSkip	Number of bytes to skip after data
;
; Output: 	ZR	On error
;		NZ	On successfull completion
;			EAX	Amount of data actually transferred
;
; Modified:	EAX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBM_IssueCBITransaction	PROC NEAR SYSCALL PUBLIC

	push	ecx

; Total data transferred
	xor	ecx, ecx

; Send the command control transfer
	call	USBM_SendCBICommand
	jz	UMICT_Exit

; Check whether to transmit/receive any data
	cmp	stMassXactStruc.dwLength, 0
	je	UMICT_CheckStatus

; Transfer the bulk data
	call	USBM_ProcessBulkData
; EAX actual data size
	mov	ecx, eax

	or	ecx, ecx
	jne	UMICT_CheckStatus

; Check for stall condition
	cmp	bLastBulkCommandStalled, TRUE
	jne	UMICT_CheckStatus

	mov	al, stMassXactStruc.bXferDir
; Clear the stall condition of bulk endpoints
	call	USBM_ClearBulkEndpointStall
	jmp	SHORT UMICT_Exit

UMICT_CheckStatus:
; Bypass interrupt transaction if it is CB protocol
	cmp	stMassDeviceInfo.bProtocol, PROTOCOL_CBI_NO_INT
	je	UMICT_Success
	call	USBM_GetCBIStatus

UMICT_Success:
	or	sp, sp
UMICT_Exit:
	mov	eax, ecx
	pop	ecx
	ret
USBM_IssueCBITransaction	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBM_SendCBICommand
;
; Description:	This function sends the CBI command sequence using
;		control transfer
;
; Input: 	stMassXactStruc
;		  pCmdBuffer	Pointer to the command buffer
;		  bCmdSize	Size of command block
;
; Output: 	NZ	On successfull completion
;		ZR	On error
;
; Modified:	None
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBM_SendCBICommand	PROC NEAR SYSCALL

	push	eax
	push	ebx
	push	si

	xor	eax, eax
	mov	CurrentDevice.CntrlXfer.wValue, ax

; Get the interface number in dx
	movzx	ax, CurrentDevice.bInterfaceNum
	mov	CurrentDevice.CntrlXfer.wIndex, ax

; Set DS for the far pointer
	push	ds
	pop	ax
	shl	eax, 4
	movzx	ebx, stMassXactStruc.pCmdBuffer
	add	eax, ebx
	mov	CurrentDevice.CntrlXfer.fpBuffer, eax

; Set data length
	movzx	ax, stMassXactStruc.bCmdSize
	mov	CurrentDevice.CntrlXfer.wLength, ax

; Set request type
	mov	CurrentDevice.CntrlXfer.wRequest, ADSC_OUT_REQUEST_TYPE

	mov	si, OFFSET CurrentDevice

; Perform control transfer with device request as ADSC_OUT_REQUEST_TYPE,
; wIndex = 0, wValue = 0, fpBuffer = command buffer and wlength = CmdBuf length
	mov	bx, CurrentHC.pHCDPointer
; Issue the HCD control transfer call
	call	(BBHCDHEADER PTR CS:[bx]).pHCDControlTransfer
	; ZR - on error, NZ on success

UMSCC_Exit:
; ZR - on error, NZ on success
	pop	si
	pop	ebx
	pop	eax
	ret
USBM_SendCBICommand	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBM_GetCBIStatus
;
; Description:	This function gets the status of the mass transaction
;		through an interrupt transfer
;
; Input: 	None
;
; Output: 	None
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBM_GetCBIStatus	PROC NEAR SYSCALL
	push	bx
	push	cx
	push	dx

; Get the data area for the interrupt transfer
	mov	dx, OFFSET wMassTempData
	mov	cx, 2
; Invoke the interrupt transfer function in the HCD
	mov	bx, CurrentHC.pHCDPointer
	call	(BBHCDHEADER PTR CS:[bx]).pHCDInterruptTransfer

;;; Return value
;;	mov	ax, wMassTempData

	pop	dx
	pop	cx
	pop	bx
	ret
USBM_GetCBIStatus	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBM_IssueBulkTransfer
;
; Description:	This function executes a bulk transaction on the USB. The
;		transfer may be either DATA_IN or DATA_OUT packets containing
;		data sent from the host to the device or vice-versa. This
;		function wil not return until the request either completes
;		successfully or completes with error (due to time out, etc.)
;		Size of data can be upto 64K
;
; Input:	DL	Transfer direction
;			Bit 7	: Data direction
;				    0 Host sending data to device
;				    1 Device sending data to host
;			Bit 6-0 : Reserved
;		ES:DI	Buffer containing data to be sent to the device or
;			buffer to be used to receive data. Value in
;			Segment:Offset format
;		ECX	dwLength request parameter, number of bytes of data
;			to be transferred in or out of the host controller
;
; Output: 	ZR	On error
;		NZ	On success
;			EAX	Amount of data transferred
;
; Modified:	EAX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBM_IssueBulkTransfer		PROC NEAR PUBLIC

	push	ebx
	push	ecx
	push	esi
	push	edi

; Load registers with input variables
	xor	ebx, ebx

; Initialize local variables
	mov	esi, ecx

; Convert the address
	mov	ax, es
	movzx	eax, ax
	shl	eax, 4
	movzx	edi, di
	add	edi, eax

UBT_NextTransfer:
; Send/receive maximum MAX_UHCI_BULK_DATA_SIZE data only
	cmp	ecx, CurrentHC.dMaxBulkDataSize
	jbe	UBT_SizeOkay
	mov	cx, WORD PTR CurrentHC.dMaxBulkDataSize
UBT_SizeOkay:

; EDI	Far pointer to the buffer
; CX	Size of data to be transferred
; DL	Transfer direction
	push	bx
	mov	bx, CurrentHC.pHCDPointer
	mov	ax, (BBHCDHEADER PTR CS:[bx]).pHCDBulkTransfer
	pop	bx
	call	ax
	jz	UBT_Exit

	movzx	eax, ax
; Adjust total amount of data transferred
	add	ebx, eax

; Check whether the size requested is same as the size transferred
	cmp	ax, cx
	jb	UBT_ShortPacket		; Tranfer completed

; Adjust loop variables
; Adjust amount of data to be transferred
	sub	esi, eax
; Adjust the buffer pointer
	add	edi, eax

	mov	ecx, esi
	or	ecx, ecx
	jnz	UBT_NextTransfer

UBT_ShortPacket:
	or	sp, sp		; Indicate as success

UBT_Exit:
	mov	eax, ebx

	pop	edi
	pop	esi
	pop	ecx
	pop	ebx
	ret
USBM_IssueBulkTransfer	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMBB_GetBulkEndPointInfo
;
; Description:	This function is used to return the bulk endpoint
;		information like endpoint number, max packet size and
;		data sync values for USB security device and mass storage
;		device.  This is used by UHCI & OHCI based HCs
;                                                                              ;
; Input: 	DL	For identifying bulk-in or bulk-out
;
; Output: 	AX	Max bulk data packet value
;		BL	Endpoint number (Bulk IN/OUT)
;		BH	Data sync value
;
; Modified:	AX, BX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMBB_GetBulkEndPointInfo	PROC NEAR SYSCALL PUBLIC

	push	cx

; Get maximum packet size from device info structure
	mov	cx, CurrentDevice.wBulkInMaxPkt
	mov	bl, CurrentDevice.bBulkInEndpoint
	mov	bh, USB_BULK_IN_DATA_SYNC_SHIFT

	test	dl, BIT7
	jnz	UMGBEI_MaxPktSzFound

; It is an OUT transaction get appropriate size
	mov	cx, CurrentDevice.wBulkOutMaxPkt
	mov	bl, CurrentDevice.bBulkOutEndpoint
	mov	bh, USB_BULK_OUT_DATA_SYNC_SHIFT

UMGBEI_MaxPktSzFound:

	movzx	ax, CurrentDevice.bDataSync

	push	bx
	push	cx
	movzx	bx, bh
	xor	cl, cl
	bt	ax, bx
	jnc	UMGBEI_ToggleBitObtained
	inc	cl
UMGBEI_ToggleBitObtained:
	pop	ax		; Max Packet
	pop	bx

	mov	bh, cl		; Data sync value
	pop	cx
	ret
USBMBB_GetBulkEndPointInfo	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBMBB_UpdateBulkDataSync
;
; Description:	This function is used to update the bulk data sync value
;		for the USB security sensor and mass storage device
;                                                                              ;
; Input: 	DL	Transfer direction
;		CL	Data toggle value to be updated
;
; Output: 	Nothing
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBMBB_UpdateBulkDataSync	PROC NEAR SYSCALL PUBLIC

	push	ax
	push	cx
	push	dx

	mov	ch, cl
; Update the data toggle value into the structure
	mov	dh, USB_BULK_IN_DATA_SYNC_SHIFT
	test	dl, BIT7
	jnz	UMUBDS_InPacket
; It is an OUT transaction get appropriate size
	mov	dh, USB_BULK_OUT_DATA_SYNC_SHIFT
UMUBDS_InPacket:


; Reset toggle bit
	mov	al, 1
	xchg	dh, cl
	shl	al, cl
	not	al
	and	CurrentDevice.bDataSync, al

; Set toggle bit appropriately
	mov	al, ch
	shl	al, cl
	or	CurrentDevice.bDataSync, al
	xchg	dh, cl

	pop	dx
	pop	cx
	pop	ax
	ret
USBMBB_UpdateBulkDataSync	ENDP


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBM_ConsumeBulkData
;
; Description:	This function reads unwanted amount of data specified in
;		the size
;
; Input: 	CX	Amount of data to be consumed
;		DL	Transfer direction
;
; Output: 	ZR	On error
;		NZ	On successfull completion
;
; Modified:	None
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBM_ConsumeBulkData	PROC NEAR SYSCALL

	push	eax
	push	bx
	push	ecx
	push	di

; Need to process only maximum amount of data that ControlBuffer can
; handle, i.e. MAX_CONTROL_DATA_SIZE

UMCBT_NextDataTransport:
	mov	bx, cx
	cmp	bx, MAX_CONTROL_DATA_SIZE
	jb	UMCBT_SizeOkay
	mov	bx, MAX_CONTROL_DATA_SIZE
UMCBT_SizeOkay:

; Set ES:DI to consume buffer
	mov	di, OFFSET ControlDataBuffer
	push	cx
; Consume buffer size
	movzx	ecx, bx
; ES:DI	Pointer to the data buffer
; ECX	Size of data to be tranferred
; DL	Transaction direction
	call	USBM_IssueBulkTransfer
	pop	cx
	jz	UMCBT_Exit

; EAX = Size. Comparing AX should be sufficient
	cmp	ax, bx

⌨️ 快捷键说明

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