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

📄 usb.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 5 页
字号:
	TITLE	USB.ASM -- USB Generic Protocol Handler

;***************************************************************************;
;***************************************************************************;
;**                                                                       **;
;**           (C)Copyright 1985-2003, American Megatrends, Inc.           **;
;**                                                                       **;
;**                          All Rights Reserved.                         **;
;**                                                                       **;
;**                6145-F Northbelt Pkwy, Norcross, GA 30071              **;
;**                                                                       **;
;**                          Phone (770)-246-8600                         **;
;**                                                                       **;
;***************************************************************************;
;***************************************************************************;
;***************************************************************************;
; $Header: /BIOS/Corebin/800/Modules/USB2/Template/Core/USB.ASM 14    3/17/03 5:50p Sivagarn $
;
; $Revision: 14 $
;
; $Date: 3/17/03 5:50p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/USB.ASM $
; 
; 14    3/17/03 5:50p Sivagarn
;   - Byte flag 'bUSBInitFlag' is changed to double word 'dUSBInitFlag'
;   - Build error when 'USB_DEV_MASS' token is disabled is fixed by
; adding 
; 
; appropriate IF-ENDIF
;   - Bug in using previous devices incompatibility flag for the new
; device is fixed
; 
; 13    1/30/03 5:14p Sivagarn
; - Appropriate beep message is issued for unsupported USB device (like
; scanner) disabling sequence
; 
; 12    1/24/03 7:04p Sivagarn
;  - Support for HC data area in extended memory is added
; 
; 11    1/16/03 4:20p Sivagarn
; - Get next HCStruc routine adds one more condition to get valid HCStruc
; entry
; 
; 10    1/09/03 6:29p Sivagarn
; - Hand-over in progress flag is added.  This flag is enabled during
; shutting down of USB EHCI handler from OHCI handover call. When this
; flag is set further devices are not enumerated.  This fixes the bug in
; loading Windows XP when USB 2.0 MO drive is connected
; 
; 9     1/03/03 7:08p Sivagarn
; - 'bLastBulkCommandStatus' variable name changed to
; 'bLastCommandStatus' as it stores status of control transfer also
; - Internal stack is not used for SMI handler
; - Stack for USB INT13h handler is allocated in the USB data area
; 
; 8     12/17/02 12:50p Sivagarn
; - Changed copyright message year to 2003
; - Unwanted (commented) code is removed
; - Function header for "GetDeviceInfoFromDevAddr" is changed
; 
; 7     11/27/02 6:14p Sivagarn
;  - All the compatibility related code (between different versions of
; chipset template and core) are moved to USBMISC.ASM
;  - Three new eLinks are created to facilitate the addition of new
; controllers, addition of new USB device support and to extend the API
; provided by the USB
; 
; 6     11/06/02 11:56a Sivagarn
; - Building error caused by polling disable token is resolved
; 
; 5     10/29/02 6:41p Sivagarn
; - Support for port 60h/64h emulation is added
;   -  Setup option is read and stored in the local USB flag
; - Support for slow mass storage devices is added
;   - Control/bulk and interrupt transfer delay variable added
; - Mass storage error conditions are refined
;   - Added a new variable for tracking mass storage errors
; 
; 4     10/14/02 8:55p Sivagarn
;  * Code cleanup
;  * USB internal PCI access routines are changed to core access routines
;  * _BBLK_ flags are removed
;  * Dependence of MKF_ flags is reduced
;  * Bug fix for mass storage device reconnect is added
; 
; 3     9/19/02 9:02a Sivagarn
; Moved the disconnect device beep from the "USBDisconnectDevice" to the
; routine "USBCheckPortChange" to avoid unnecessary beeps during host
; controller stop call
;
; 2     9/18/02 12:01p Sivagarn
; - Corrected the register usage in the "USBIdentifyAndConfigureRoutine"
; for the DeviceInfo structure (This bug disables any device connected to
; the second USB host controller)
; - Changed the beep flag name from INIT_FLAG_BEEP_DISABLE to
; INIT_FLAG_BEEP_ENABLE
;
; 1     9/15/02 5:39p Sivagarn
; Initial AMIUSB 2.20 check-in
;
;***************************************************************************;

;----------------------------------------------------------------------------
; 		Global options are defined here
;----------------------------------------------------------------------------
OPTION	PROC:PRIVATE
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		Macro and equate files are included here
;----------------------------------------------------------------------------
	INCLUDE equates.equ
	INCLUDE	usbflag.equ
	INCLUDE	usb.equ
	INCLUDE	mbiosequ.equ
;----------------------------------------------------------------------------
; Chipset template compability flag
IFNDEF	MKF_ENABLE_EXT_MEMORY_DATA_AREA
MKF_ENABLE_EXT_MEMORY_DATA_AREA		EQU		0
ENDIF

;----------------------------------------------------------------------------
;		External data definitions are defined here
;----------------------------------------------------------------------------
DeviceDriverTable		PROTO	NEAR
USBCmosQuestionInitTable	PROTO	NEAR
USBCmosQuestionInitTableEnd	PROTO	NEAR
USBHCInfoTableStart		PROTO	NEAR
USBHCInfoTableEnd		PROTO	NEAR

	EXTERN	USBBadDeviceTable:NEAR
	EXTERN	USBBadDeviceTableEnd:NEAR
IF	MKF_USB_DEV_MASS
	EXTERN	wUSBGlobalDataSegment:WORD
ENDIF
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		External function definitions are defined here
;----------------------------------------------------------------------------
farUSBFindHCDriver		PROTO FAR SYSCALL	; eLink

check_cmos_data_FAR		PROTO FAR SYSCALL
read_pci_FAR			PROTO FAR SYSCALL
read_pci_dword_FAR		PROTO FAR SYSCALL

USBVerifyUSBClassCode		PROTO NEAR SYSCALL

USBHCInit			PROTO NEAR SYSCALL

IF	MKF_USB_DEV_HUB
USBHub_GetPortStatus		PROTO NEAR SYSCALL
USBHub_DisablePort		PROTO NEAR SYSCALL
USBHub_EnablePort		PROTO NEAR SYSCALL
ENDIF

IF	MKF_USB_DEV_MASS
USBMassGetFreeMassDeviceInfoStruc	PROTO NEAR SYSCALL
ENDIF

USBMem_Init 			PROTO NEAR SYSCALL
USBMem_Alloc			PROTO NEAR SYSCALL
				; AL - bNumBlocks
USBMem_Free			PROTO NEAR SYSCALL
				; AL - bNumBlocks, BX - wMemBlock
USBMisc_FixedDelay		PROTO NEAR SYSCALL
				; AX - wCount
USBMisc_SpeakerBeep		PROTO NEAR SYSCALL
				; BL - bFreq, CX - wDuration:WORD,

USBMiscFindIRQInService		PROTO NEAR SYSCALL
USBMiscFillDeviceDriverTable	PROTO NEAR SYSCALL

USBGetDataSegment		PROTO NEAR SYSCALL
USBGetHCAddress			PROTO NEAR SYSCALL

USBMiscFindHC			PROTO NEAR SYSCALL

IF	MKF_USB_MODE GE 2
farUSBRT_InvokeAPI		PROTO FAR SYSCALL
ELSE
farUSBWrap_ApiHandler		PROTO FAR SYSCALL
ENDIF

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

;----------------------------------------------------------------------------
;		Public function definitions are defined here
;----------------------------------------------------------------------------
	PUBLIC	USBAcquiredByOS
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		Function prototype definitions are here
;----------------------------------------------------------------------------
USB_ConfigureDevice	PROTO NEAR SYSCALL
USB_DetectNewDevice	PROTO NEAR SYSCALL
USBDisconnectDevice	PROTO NEAR SYSCALL
USBStopDevice		PROTO NEAR SYSCALL
USBDisableHubPort	PROTO NEAR SYSCALL
USBEnableHubPort	PROTO NEAR SYSCALL
USB_GetDescriptor	PROTO NEAR SYSCALL
;----------------------------------------------------------------------------

IF	MKF_USB_MODE EQ 3
;----------------------------------------------------------------------------
;	R U N T I M E    C O D E     S E G M E N T
;----------------------------------------------------------------------------
RUN_CSEG	SEGMENT	WORD	PUBLIC	'CODE'
RUN_CSEG	ENDS
ENDIF

;----------------------------------------------------------------------------
;	C O D E   S E G M E N T
;----------------------------------------------------------------------------
USB_CSEG	SEGMENT	WORD	USE16 	PUBLIC 'CODE'
	ASSUME	cs:USB_CSEG
	ASSUME	ds:USB_DSEG
.586p

	PUBLIC	_USB_ASM_START
_USB_ASM_START		LABEL		BYTE

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBLogError
;
; Description:	This routine logs the USB error in the data area. This
;		logged errors will be displayed during the POST.
;
; Input: 	AX	Error code to log
;
; Output: 	None
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBLogError		PROC	NEAR SYSCALL PUBLIC
	push	bx
	push	si

	mov	si, OFFSET aErrorLogBuffer
	mov	bx, wErrorLogIndex

; Check for end of the buffer
	cmp	wErrorLogIndex, (ERROR_LOG_BUFFER_SIZE / ERROR_LOG_ENTRY_SIZE)
	jae	ULE_Exit

; Still have space to log errors
	shl	bx, 1
	mov	WORD PTR [si+bx], ax
	inc	wErrorLogIndex

ULE_Exit:
	pop	si
	pop	bx
	ret
USBLogError		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBGetFreeHCStruc
;
; Description:	This routine looks for a free HCStruc structure 
;
; Input: 	None
;
; Output: 	SI	0 On error
;		SI	Pointer to the HCStruc - on success
;
; Modified:	SI
;
; Referrals:	HCStruc
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBGetHCStruc		PROC	NEAR SYSCALL
	push	ax
	push	cx

	mov	si, OFFSET HCTable
	mov	cx, MKF_USB_MAX_HC
	xor	ax, ax

UGHD_TryNextHC:
	cmp	(HCStruc PTR [si]).bHCType, al
	jne	UGHD_PrepareForLoop
	cmp	(HCStruc PTR [si]).wBusDevFuncNum, ax
	jne	UGHD_PrepareForLoop

; Structure found
	jmp	short UGHD_Exit

UGHD_PrepareForLoop:
	add	si, SIZE HCStruc
	loop	UGHD_TryNextHC
	xor	si, si

UGHD_Exit:
	or	si, si
	pop	cx
	pop	ax
	ret
USBGetHCStruc		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBGetDataSegment
;
; Description:	This routine returns the segment value of the USB data
;		area depending on the input parameter
;
; Input: 	AX			Description
;		USB_GET_CURRENT_SEGMENT	Return current segment address
;		USB_GET_RUNTIME_SEGMENT	Return runtimesegment address
;
; Output: 	DS	Segment address = 0 if segment not defined yet
;
; Modified:	DS
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBDataSegmentTable	LABEL WORD
	PUBLIC	USBRuntimeDataSegment
USBRuntimeDataSegment	DW	MKF_USB_DATA_SEGMENT
USBDataSegmentTableEnd		LABEL	WORD

USBGetDataSegment	PROC NEAR SYSCALL PUBLIC 

	push	ax
	push	bx
	push	cx
	push	si

	mov	cx, ds		; Save DS

; Check whether to return current data segment
	or	ax, ax
	jz	UGDS_ProceedNormally		; Return current segment

; Calculate offset into USBDataSegmentTable
	not	ax
	shl	ax, 1				; Multiply by 2
	add	ax, OFFSET cs:USBDataSegmentTable

; Check end condition
	cmp	ax, OFFSET cs:USBDataSegmentTableEnd
	jae	UGDS_ReturnNull

	mov	bx, ax
	mov	ax, WORD PTR cs:[bx]
IFE	MKF_ENABLE_EXT_MEMORY_DATA_AREA
	add	ax, USB_HC_DATA_AREA_SIZE_PARA
ENDIF
	mov	ds, ax
	jmp	SHORT UGDS_Success

UGDS_ProceedNormally:

; Find current data segmnet
	mov	si, OFFSET CS:USBDataSegmentTable

UGDS_CheckNextAddress:
	mov	ax, WORD PTR cs:[si]
IFE	MKF_ENABLE_EXT_MEMORY_DATA_AREA
	add	ax, USB_HC_DATA_AREA_SIZE_PARA
ENDIF
	mov	ds, ax
	xor	bx, bx
	cmp	DWORD PTR [bx], '$UDA'			; Signature
	je	UGDS_Success

	add	si, 2
	cmp	si, OFFSET cs:USBDataSegmentTableEnd
	jb	UGDS_CheckNextAddress

UGDS_ReturnNull:
; Restore DS
	mov	ds, cx
	cmp	sp, sp		; Set ZR flag (error)
	jmp	SHORT UGDS_Exit

UGDS_Success:
	or	sp, sp		; Clear ZR flag

UGDS_Exit:
	pop	si
	pop	cx
	pop	bx
	pop	ax
	ret
USBGetDataSegment	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBGetNextHCStruc
;
; Description:	This routine returns the next HCStruc pointer. If the input
;		is 0FFFFh then it will return the first HCStruc pointer. At
;		the end it will return 0FFFFh to indicate end of structure.
;
; Input: 	SI	Current HCStruc pointer
;
; Output: 	NZ	On success
;			SI - New HCStruc
;		ZR	Error
;
; Modified:	SI
;
; Referrals:	HCStruc
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBGetNextHCStruc		PROC NEAR SYSCALL PUBLIC

	push	ax
	push	cx

; Move the parameter from the stack to register
	mov	ax, si

; Start from the first structure
	mov	si, OFFSET HCTable

; Check for start value
	cmp	ax, 0FFFFh
	je	UWGNHS_Okay		; Start with first structure

; Find the next structure offset
	mov	si, ax
	add	si, SIZE HCStruc

UWGNHS_Okay:

; Calculate the structure number
	mov	ax, si
	sub	ax, OFFSET HCTable
	mov	cl, SIZE HCStruc
	div	cl

	mov	cx, MKF_USB_MAX_HC
	sub	cx, ax			; Loop count

	xor	ax, ax
	dec	ax

; Check for valid structure
	or	cx, cx
	jbe	UWCNHS_Exit

UWCNHS_TryNextHC:
	cmp	(HCStruc PTR [si]).bHCType, 0
	jz	UWCNHS_PrepareForLoop
	cmp	(HCStruc PTR [si]).bNumPorts, 0
	jz	UWCNHS_PrepareForLoop
	cmp	(HCStruc PTR [si]).wBusDevFuncNum, 0
	jz	UWCNHS_PrepareForLoop

; Structure found
	or	sp, sp		; Clear zero flag
	jmp	SHORT UWCNHS_Exit

UWCNHS_PrepareForLoop:
	loop	UWCNHS_TryNextHC
	cmp	sp, sp		; Set zero flag

UWCNHS_Exit:

	pop	cx
	pop	ax
	ret
USBGetNextHCStruc		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBCallAllHC
;
; Description:	This routine invokes all HCs API function provided by
;		the offset wAPIOffset
;
; Input: 	BX	Near offset into HCDHeader table for the
;			API function to be invoked
;
; Output: 	AX	USB_SUCCESS/USB_ERROR
;
; Modified:	AX
;
; Referrals:	HCStruc
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBCallAllHC		PROC NEAR SYSCALL PUBLIC  USES BX DX SI DS

⌨️ 快捷键说明

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