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

📄 ohci_bb.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 4 页
字号:
	mov	eax, DWORD PTR FS:[di+OHCI_INTERRUPT_STATUS]


; Check the interrupt status register for a one or more TDs completing.
; EAX = value from status register
	test	eax, WRITEBACK_DONEHEAD
	jz	OPI_InterruptProcessingDone
			; Br if no TDs have completed

; The memory dword at HCCADONEHEAD has been updated to contain the head
; pointer of the linked list of TDs that have completed.  Walk through
; this list processing TDs as we go.

OPI_CheckForMoreTds:

; Point data area to HC's common data area
	xor	ebx, ebx
	push	es
	push	USB_DATA
	pop	es
	xchg	ebx, (OHCIHCCA PTR ES:[di]).HCCADoneHead
	pop	es
			; EBX = abs addr of 1st completed TD
	or	ebx, ebx
	jz	OPI_InterruptProcessingDone
				; Br if no TDs in list

; Clear the WRITEBACK_DONEHEAD bit of the interrupt status register
; in the host controller

	; Write 1 to bit to clear it
	or	DWORD PTR FS:[di+OHCI_INTERRUPT_STATUS], WRITEBACK_DONEHEAD

OPI_ProcessNextTd:
	sub	ebx, dGlobalDataArea	; DI = offset of 1st completed TD
	and	bx, 0FFF0h		; Ignore any lower bits that may be set
; BX		TD pointer
; FS:EDI	Pointer to mem base address
; Check for NULL
	or	bx, bx
	jz	OPT_Done		; Null pointer

; Check whether TD is active
	cmp	(OHCI_TD PTR [bx]).ActiveFlag, TRUE
	jne	OPT_Done		; TD is not active

; Check whether call back function is present
	cmp	(OHCI_TD PTR [bx]).pCallback, 0
	jz	OPT_Done		; No callback associated

	push	di
	mov	di, bx
	call	(OHCI_TD PTR [bx]).pCallback
	pop	di

OPT_Done:
	mov	ebx, (OHCI_TD PTR [bx]).LinkPointer
	or	ebx, ebx
	jnz	OPI_ProcessNextTd	;Br if more TDs in list
	jmp	OPI_CheckForMoreTds	;Check if any TDs completed while processing

OPI_InterruptProcessingDone:


OPI_Exit:

	pop	edi
	pop	si
	pop	edx
	pop	ebx
	pop	eax
	pop	fs
	ret
OHCIBB_ProcessInterrupt		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_WaitForTransferComplete
;
; Description:	This function executes a device request command transaction
;
; Input:	DI	Pointer to the TD which has to be completed
;
; Output: 	None
;
; Modified:	None
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

OHCIBB_WaitForTransferComplete	PROC NEAR SYSCALL 
	push	bx
	push	cx

; Load the register with input parameters
	mov	bx, 60000d		; Check status change loop iteration

OWFTC_WaitForComplete:
	call	OHCIBB_ProcessInterrupt

	cmp	(OHCI_TD PTR [di]).ActiveFlag, FALSE
	je	OWFTC_Complete		; TD completed

	mov	cx, 7			; 75 microsec
	call	fixed_delay_far

	dec	bx			; Dec timeout counter
	jnz	OWFTC_WaitForComplete	; Br if not time to give up yet

	or	(OHCI_TD PTR [di]).ControlStatus, (GTD_DEVICE_NOT_RESPOND SHL 28)

OWFTC_Complete:
	pop	cx
	pop	bx
	ret
OHCIBB_WaitForTransferComplete	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_ControlTDCallback
;
; Description:	This function is called when the control transfer scheduled
;		is completed.
;
; Input: 	DI	Pointer to the TD that completed
;
; Output: 	Nothing
;
; Modified:	Nothing
;
; Referrals:	OHCI_TD
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

OHCIBB_ControlTDCallback	PROC NEAR SYSCALL USES EAX BX SI DI


; Check to see if the TD that just completed has any error bits set.  If
; any of the control TDs (Setup, Data, or Status) complete with an error, set
; ActiveFlag of the control status TD and copy the error information from the
; TD that just completed into the control status TD.
	mov	eax, (OHCI_TD PTR [di]).ControlStatus
	shr	eax, 28			; AL[3:0] = Completion status
	or	al, al
	jz	OCTCB_Done		; TD completed without an error

	shl	eax, 28			; EAX[31:28] = Completion status
	mov	bx, OFFSET GTDControlStatus
	cmp	di, bx
	je	OCTCB_Done
	mov	(OHCI_TD PTR [bx]).ControlStatus, eax
	mov	(OHCI_TD PTR [bx]).ActiveFlag, FALSE

; Make the TD that just completed inactive.  It may be the control setup TD,
; one of the control data TDs, or the control status TD.

OCTCB_Done:
	mov	(OHCI_TD PTR [di]).ActiveFlag, FALSE

	ret
OHCIBB_ControlTDCallback		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_GeneralTDCallback
;
; Description:	This function is called when bulk data or interrupt data TD
;		is completed. This routine just deactivates the TD.
;
; Input: 	DI	Pointer to the TD that completed
;
; Output: 	Nothing
;
; Modified:	Nothing
;
; Referrals:	OHCI_TD
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

OHCIBB_GeneralTDCallback	PROC	NEAR SYSCALL

; First deactivate the TD so this callback function will not get
; re-entered.
	mov	(OHCI_TD PTR [di]).ActiveFlag, FALSE

	ret
OHCIBB_GeneralTDCallback	ENDP

IF	MKF_USB_BB_DEV_KBD
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_KeyboardPollingCallback
;
; Description:	This function is called when the keyboard polling TD 
;		completes an interrupt transaction to its assigned device.
;		This routine should process any data in the TD's data buffer,
;		handle any errors, and then copy the TD's CSReloadValue
;		field into its control status field to put the TD back
;		into service.
;
; Input: 	DI	Pointer to the TD that completed
;
; Output: 	None
;
; Modified:	Nothing
;
; Referrals:	OHCI_ED, OHCI_TD
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

OHCIBB_KeyboardPollingCallback	PROC NEAR PUBLIC

	push	eax
	push	bx
	push	di
	push	fs


	mov	bx, di
; Set the TD's active flag to FALSE
	mov	(OHCI_TD PTR [bx]).ActiveFlag, FALSE

; Exit on error status
	test	(OHCI_TD PTR [bx]).ControlStatus, GTD_STATUS_FIELD
	jnz	OBKPC_Exit

; Set FS:DI to point to the memory base address of the HC
	call	OHCIBB_SetFS_DI

; Stop the periodic list processing
	and	DWORD PTR FS:[di+OHCI_CONTROL_REG], NOT PERIODIC_LIST_ENABLE

	push	di	; Save DI
	lea	ax, (OHCI_TD PTR [bx]).SetupData
	mov	di, ax
; Invoke the call back function
; DI	Pointer to the data buffer
	call	USBBB_ProcessKeyboardData
	pop	di	; Restore DI

; Start the periodic list processing
	or	DWORD PTR FS:[di+OHCI_CONTROL_REG], PERIODIC_LIST_ENABLE

; Reset the TD's control and buffer pointer fields to their original values.
	mov	eax, (OHCI_TD PTR [bx]).CSReloadValue
	mov	(OHCI_TD PTR [bx]).ControlStatus, eax

	lea	ax, (OHCI_TD PTR [bx]).SetupData; AX = ptr to TD's data buffer
	movzx	eax, ax				; Clear upper half of EAX
	add	eax, dGlobalDataArea		; EAX = abs addr of TD's data buffer
        mov     (OHCI_TD PTR [bx]).CurrentBufferPointer, eax

; Rebind the TD to its parent ED.
	mov	di, CurrentDevice.pPollEDPtr
	movzx	eax, bx			; EAX = offset of this TD
	add	eax, dGlobalDataArea	; EAX = addr of this TD
	and	(OHCI_ED PTR [di]).HeadPointer, ED_TOGGLE_CARRY
	or	(OHCI_ED PTR [di]).HeadPointer, eax

	mov 	(OHCI_TD PTR [bx]).ActiveFlag, TRUE

OBKPC_Exit:
	pop	fs
	pop	di
	pop	bx
	pop	eax
	ret
OHCIBB_KeyboardPollingCallback	ENDP
ENDIF	;; IF	MKF_USB_BB_DEV_KBD

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_ActivateKeyboardPolling
;
; Description:	This function activates the polling TD for the USB keyboard 
;
; Input: 	None
;
; Output: 	ZR	On error
;		NZ	On successfull completion
;
; Modified:	Nothing
;
; Referrals:	OHCI_TD, DeviceInfo
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

OHCIBB_ActivateKeyboardPolling		PROC NEAR SYSCALL PUBLIC USES BX SI EDI CX DX FS

IF	MKF_USB_BB_DEV_KBD
	mov	ax, OFFSET EDKeyboard
; Save the pointers in DeviceInfo structure
	push	ax
	mov	CurrentDevice.pPollEDPtr, ax
	add	ax, SIZE OHCI_ED
	mov	CurrentDevice.pPollTDPtr, ax
	pop	ax
	mov	di, ax
	add	ax, SIZE OHCI_ED
	mov	cx, ax

; Setup the polling ED
	movzx	eax, CurrentDevice.wEndp0MaxPacket
	shl	eax, 16			; EAX[26:16] = device's packet size
	movzx	ax, CurrentDevice.bEndpointSpeed
	; AL = 11/01/10 for HI/LO/FULL
	and	al, 1			; Mask off MSb
	shl	ax, 13			; AX[13] = full/low speed flag
	or	eax, ED_SKIP_TDQ OR ED_IN_PACKET OR  \
			(DEFAULT_PACKET_LENGTH  SHL 16)
					; Set PID=In, and MaxLen
	mov	(OHCI_ED PTR [di]).Control, eax

	movzx	eax, CurrentDevice.bEndPointNum
					; EAX[3:0] = Endpoint (0-F)
	shl	eax, 7			; EAX[10:7] = Endpoint (0-F)
	or	al, CurrentDevice.bDeviceAddress
					; EAX[6:0] = Device address (00-7F)
	or	(OHCI_ED PTR [di]).Control, eax

; Link polling TD to the polling ED
	movzx	eax, cx				; Polling TD
	add	eax, dGlobalDataArea
	mov	(OHCI_ED PTR [di]).HeadPointer, eax

	mov	eax, OHCI_TERMINATE
	mov	(OHCI_ED PTR [di]).TailPointer, eax
	mov	(OHCI_ED PTR [di]).LinkPointer, eax

; Fill in various fields for the polling TD
; The ControlStatus field will be set so
;   Buffer Rounding = 1,
;   Direction PID = GTD_IN_PACKET,
;   Delay Interrupt = GTD_IntD,
;   Data Toggle = GTD_DATA0_TOGGLE,
;   Error Count = GTD_NO_ERRORS,
;   Condition Code = GTD_NOT_ACCESSED
; The CurrentBufferPointer field will point to the TD's SetupData buffer
;   which was before initialized to contain a DeviceRequest struc.
; The BufferEnd field will point to the last byte of the TD's SetupData
;   buffer.
; The LinkPointer field will point to OHCI_TERMINATE
; The ActiveFlag field will be set to TRUE.

	push	di
	mov	di, cx
	mov	eax,  GTD_BUFFER_ROUNDING OR GTD_IN_PACKET OR \
		GTD_NO_ERRORS OR GTD_IntD OR (GTD_NOT_ACCESSED shl 28)
	mov	(OHCI_TD PTR [di]).ControlStatus, eax
	mov	(OHCI_TD PTR [di]).CSReloadValue, eax

	lea	ax, (OHCI_TD PTR [di]).SetupData
					; AX = ptr to TD's data buffer
	movzx	eax, ax 		; Clear upper half of EAX
	add	eax, dGlobalDataArea	; EAX = abs addr of TD's 8 byte data buffer
	mov	(OHCI_TD PTR [di]).CurrentBufferPointer, eax

	add	eax, (SIZE (OHCI_TD PTR [di]).SetupData) - 1
	mov	(OHCI_TD PTR [di]).BufferEnd, eax
	mov	(OHCI_TD PTR [di]).LinkPointer, OHCI_TERMINATE
	mov	(OHCI_TD PTR [di]).pCallback, OFFSET CS:OHCIBB_KeyboardPollingCallback
	mov	(OHCI_TD PTR [di]).ActiveFlag, TRUE

	pop	di

; Capture the HC IRQ to point to the common IRQ handler
	call	USBBB_CaptureHCInterrupt


; Enable the polling ED for processing
	and	(OHCI_ED PTR [di]).Control, NOT ED_SKIP_TDQ

; Set FS:DI to point to the memory base address of the HC
	call	OHCIBB_SetFS_DI

; Enable SOF, WDH, RHSC interrupts
	mov	DWORD PTR FS:[di+OHCI_INTERRUPT_ENABLE], MASTER_INTERRUPT_ENABLE OR WRITEBACK_DONEHEAD_ENABLE

; Start the host controller for periodic list and control list.
	or	DWORD PTR FS:[di+OHCI_CONTROL_REG], PERIODIC_LIST_ENABLE

ENDIF	;; IF	MKF_USB_BB_DEV_KBD
	or	sp, sp		; Clear the zero flag
	ret
OHCIBB_ActivateKeyboardPolling		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_DeactivateKeyboardPolling
;
; Description:	This function de-activates the polling TD for the USB keyboard
;
; Input: 	None
;
; Output: 	ZR	On error
;		NZ	On successfull completion
;
; Modified:	Nothing
;
; Referrals:	OHCI_TD, DeviceInfo
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

OHCIBB_DeactivateKeyboardPolling	PROC NEAR SYSCALL PUBLIC USES SI BX EDI

IF	MKF_USB_BB_DEV_KBD
; Skip the processing of this ED
	mov	bx, CurrentDevice.pPollEDPtr
	or	bx, bx
	jz	ODP_Exit
	or 	(OHCI_ED PTR [bx]).Control, ED_SKIP_TDQ

; Get a pointer to the device's TD from the poll TD pointer
	mov	bx, (DeviceInfo PTR [di]).pPollTDPtr

; Set the TD to inactive and prevent the HC from processing it.
	mov	(OHCI_TD PTR [bx]).ControlStatus, 0
	mov	(OHCI_TD PTR [bx]).CSReloadValue, 0
	mov	(OHCI_TD PTR [bx]).ActiveFlag, FALSE

	mov	CurrentDevice.pPollTDPtr, 0
	mov	CurrentDevice.pPollEDPtr, 0

ODP_Exit:
ENDIF	;; IF	MKF_USB_BB_DEV_KBD
	or	sp, sp			; Clear the sero flag
	ret

OHCIBB_DeactivateKeyboardPolling	ENDP

	PUBLIC	_OHCI_BB_ASM_END
_OHCI_BB_ASM_END		LABEL		BYTE


USB_CSEG	ENDS

	END
;*****************************************************************;
;*****************************************************************;
;**                                                             **;
;**      (C)Copyright 1985-2002, 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 + -