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

📄 usbif.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	TITLE	USBIF.ASM -- USB POST Interface Module

;***************************************************************************;
;***************************************************************************;
;**                                                                       **;
;**           (C)Copyright 1985-2002, 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/USBIF.ASM 9     3/17/03 5:51p Sivagarn $
;
; $Revision: 9 $
;
; $Date: 3/17/03 5:51p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBIF.ASM $
; 
; 9     3/17/03 5:51p Sivagarn
;   - Byte flag 'bUSBInitFlag' is changed to double word 'dUSBInitFlag'
;   - A new runtime routine 'farUSBAPI_Stop'to stop the USB host
; controllers is 
; 
; added
; 
; 8     1/24/03 7:06p Sivagarn
; Support for HC data area in extended memory
;  - Code to allocate extended memory during USB start call is added
;  - Allocated extended memory is passed to the USB start call as a new
; parameter
; 
; 7     1/06/03 5:36p Sivagarn
; - Bug in installing DOS mouse driver for USB mouse if the USB mouse
; (without PS/2 mouse) is connected after checkpoint 38h is fixed.  Now
; USB mouse can be connected anytime during the POST
; 
; 6     11/27/02 6:19p Sivagarn
;  - Routine that displays USB device information is changed to support
; the updates made to CK_PRESENCE structure
;  - Code related to Security API are removed (now the security API
; belong to a separate USB module part)
; 
; 5     11/17/02 8:07p Sivagarn
; - Code to stop the USB host controllers, when legacy support option is
; set to Auto and no USB devices are present, is added
; 
; 4     11/08/02 10:51a Sivagarn
; The POST/runtime AMIBIOS8 variables related to keyboard/mouse is
; updated as per the presence of USB keyboard/mouse
; 
; 3     10/29/02 6:45p Sivagarn
; Support for port 60h/64h emulation is added
;   - rt_cmos_flag variable is updated with port 60h/64h emulation status
; 
; 2     10/14/02 8:59p Sivagarn
;  * Code cleanup
;  * Security device is not displayed in the POST
; 
; 1     9/15/02 5:39p Sivagarn
; Initial AMIUSB 2.20 check-in
; 
;***************************************************************************;

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

;----------------------------------------------------------------------------
;		Macro and equate files are included here
;----------------------------------------------------------------------------
	INCLUDE	equates.equ
	INCLUDE	usbflag.equ
	INCLUDE	usb.equ
	INCLUDE	mbiosequ.equ
	INCLUDE	sb.equ
	INCLUDE	pci.equ
	INCLUDE	ekdata.equ		; CORE EQUATE FILE

;----------------------------------------------------------------------------
; Chipset template compability flag
IFNDEF	MKF_ENABLE_EXT_MEMORY_DATA_AREA
MKF_ENABLE_EXT_MEMORY_DATA_AREA		EQU		0
ENDIF



;----------------------------------------------------------------------------
;		External data definitions are here
;----------------------------------------------------------------------------
	EXTERN	bUSBDeviceList:BYTE
	EXTERN	dUSBInitFlag:DWORD
	EXTERN	wErrorLogIndex:WORD
	EXTERN	aErrorLogBuffer:NEAR
IF	MKF_USB_DEV_KBD
	EXTERN	pProcessBIOSKeys_FAR:DWORD

ProcessBIOSKeys_FAR		PROTO	FAR
ENDIF

IFE	MKF_KBC_SUPPORT
IF	MKF_USB_DEV_MOUSE
	EXTERN	bMouseStatusFlag:BYTE
ENDIF
ENDIF

	EXTERN	_str$_usb_device:ABS
	EXTERN	_str$_usb_keyboard:ABS
	EXTERN	_str$_usb_keyboards:ABS
	EXTERN	_str$_usb_mouse:ABS
	EXTERN	_str$_usb_mice:ABS
	EXTERN	_str$_usb_hub:ABS
	EXTERN	_str$_usb_hubs:ABS
	EXTERN	_str$_usb_storage:ABS
	EXTERN	_str$_usb_storages:ABS
	EXTERN	_str$_usb_unknown:ABS
	EXTERN	_str$_usb_device_separator:ABS
	EXTERN	_str$_usb_legacy_disabled:ABS

	EXTERN	Q_USB_LEGACY_ENABLE:ABS
IF	MKF_USB_DEV_KBD AND MKF_USB_DEV_MOUSE
	EXTERN	Q_USB_LEGACY_MOUSE:ABS
ENDIF

	EXTERN	rt_cmos_byte:BYTE
	EXTERN	machine_config:WORD
	EXTERN	wActiveInputDevices:WORD

display_0d0a_FAR		PROTO	FAR SYSCALL
display_token_message_FAR	PROTO	FAR SYSCALL
fixed_delay_FAR			PROTO	FAR SYSCALL
write_tty_FAR			PROTO	FAR SYSCALL
ProgramPS2MouseIRQLevel_FAR   	PROTO	FAR SYSCALL
int_74				PROTO	FAR SYSCALL
check_cmos_data_far		PROTO	FAR SYSCALL
PostBIOSError_FAR		PROTO	FAR SYSCALL

;----------------------------------------------------------------------------
;		External function definitions are defined here
;----------------------------------------------------------------------------
IF	MKF_USB_MODE GE 2
farUSBRT_InvokeAPI		PROTO FAR SYSCALL
ENDIF
farUSBWrap_ApiHandler		PROTO FAR SYSCALL

farUSBPort_DisableUSBInChipset	PROTO FAR

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

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

;----------------------------------------------------------------------------
;		Function prototype definitions are here
;----------------------------------------------------------------------------

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

;----------------------------------------------------------------------------
;	D A T A   S E G M E N T
;----------------------------------------------------------------------------
USB_DSEG 	SEGMENT 	WORD PUBLIC 'DATA'
USB_DSEG 	ENDS

USB_DATA 		SEGMENT PARA PUBLIC 'DATA'
USB_DATA		ENDS

;----------------------------------------------------------------------------
;	P O S T     C O D E     S E G M E N T
;----------------------------------------------------------------------------
POST_CSEG	SEGMENT	PARA	PUBLIC	'CODE'
.586p
	ASSUME	CS:POST_CSEG
	ASSUME	DS:USB_DSEG
	ASSUME	GS:RUN_CSEG

wUSBDataAreaSegment		WORD		?


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	farInitUSBHC
;
; Description:	This function initializes the USB host controller and
;		enumerate the USB devices connected to the system
;
; Input: 	DS = 40h
;		ES = 0
;		FS = POST_DSEG
;		GS = RUN_CSEG
;
; Output: 	None
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

farInitUSBHC 		PROC FAR USES DS ES BX
	LOCAL	stURP:URP_STRUC, dUSBExtMemAllocated:DWORD


IF	MKF_ENABLE_EXT_MEMORY_DATA_AREA
	pushad
; Allocate extended memory
	EXTERN	AllocateExtMemForPOSTRuntime_FAR:FAR
	mov	ecx, USB_HC_EXT_MEM_SIZE

	push	ebp
	call	AllocateExtMemForPOSTRuntime_FAR
	pop	ebp
	mov	dUSBExtMemAllocated, esi
	popad
ELSE
	mov	dUSBExtMemAllocated, 0
ENDIF


; Fill URP with proper value
	lea	bx, stURP
	push	ss
	pop	es

	mov	(URP_STRUC PTR es:[bx]).bFuncNumber, USB_API_START
	mov	(URP_STRUC PTR es:[bx]).bSubFunc, 0
	mov	(URP_STRUC PTR es:[bx]).ApiData.StartHc.wDataAreaFlag, \
					USB_GET_RUNTIME_SEGMENT
	mov	eax, dUSBExtMemAllocated
	mov	(URP_STRUC PTR es:[bx]).ApiData.StartHc.dExtDataArea, eax
	INVOKE_USB_API_HANDLER

; Save the USB data area in a local variable
	mov	ax, (URP_STRUC PTR es:[bx]).ApiData.StartHc.wDataAreaFlag
	mov	CS:wUSBDataAreaSegment, ax

; Set DS to USB data area
	mov	ds, ax

; Save the DS in the local variable
IFE	MKF_KBC_SUPPORT
	push	ds
	pop	WORD PTR GS:bUBDataAreaPointer
ENDIF

IF	MKF_USB_DEV_KBD
; Update RUNTIME variable pProcessBIOSKeys_FAR (usbkbd.asm) with the far
; pointer POST_CSEG:ProcessBIOSKeys_FAR; after POST is completed this
; variable will be zeroed in farPrepareUSBForOS
	push	POST_CSEG
	push	OFFSET POST_CSEG:ProcessBIOSKeys_FAR
	pop	DWORD PTR ds:pProcessBIOSKeys_FAR
ENDIF

; Post the errors, if any
; Check number of log data present
	push	ax
	push	bx
	push	cx

	mov	cx, wErrorLogIndex

	or	cx, cx
	je	IUH_NoErrorToPost

	mov	bx, OFFSET aErrorLogBuffer

IUH_ProcessNextError:
	mov	ax, WORD PTR [bx]
	cmp	ax, USB_ERROR_CODE_START
	jb	IUH_CheckNextEntry

; Post the error
	call	PostBIOSError_FAR

IUH_CheckNextEntry:
	add	bx, ERROR_LOG_ENTRY_SIZE
	loop	IUH_ProcessNextError

IUH_NoErrorToPost:
	pop	cx
	pop	bx
	pop	ax

; Check whether USB keyboard is present
	test	bUSBDeviceList, USB_TYPE_KEYBOARD
	jz	IUH_KBDone

	or	fs:wActiveInputDevices, USB_KBD_DEVICE_BIT

IUH_KBDone:

; Check whether USB mouse is present
	test	bUSBDeviceList, USB_TYPE_MOUSE
	jz	IUH_MouseDone

IF	MKF_USB_KBC_EMULATION
	test	dUSBInitFlag, USB_PORT_TRAPPING_BIT
	jz	IUH_SkipFlagUpdate

; Port 60h/64h emulation is enabled. Set appropriate bit in the rt_cmos_byte
	or	gs:rt_cmos_byte, rt_cmos_6064_bit

IUH_SkipFlagUpdate:
ENDIF


IUH_MouseDone:

	ret
farInitUSBHC		ENDP

;------------------------------------------------------------------------------;
USBDeviceStringTable		LABEL	WORD
	WORD	_str$_usb_keyboard
	WORD	_str$_usb_keyboards
	WORD	_str$_usb_mouse
	WORD	_str$_usb_mice
	WORD	_str$_usb_hub
	WORD	_str$_usb_hubs
	WORD	_str$_usb_storage
	WORD	_str$_usb_storages
USBDeviceStringTableEnd		LABEL	WORD
;------------------------------------------------------------------------------;


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	farDisplayUSBDevices
;
; Description:	This function displays information about USB devices
;		connected right now in the system
;
; Input: 	None
;
; Output: 	None
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

farDisplayUSBDevices		PROC	FAR
	LOCAL	stURP:URP_STRUC, bQ_USBLegacyEnable:BYTE

	pushad

; Check for USB legacy support.
	mov	ax, Q_USB_LEGACY_ENABLE
	call	check_cmos_data_far
	mov	bQ_USBLegacyEnable, al
	or	al, al
	jnz	fDUD_GoOn

; Legacy disabled. Display legacy disabled message and exit.
	mov	bx, _str$_usb_legacy_disabled
	call	display_token_message_FAR
	call	display_0d0a_FAR
	jmp	DUD_Exit

fDUD_GoOn:
; Check for USB BIOS presence
	push	es

; Fill URP with proper value
	lea	di, stURP
	push	ss
	pop	es

	mov	(URP_STRUC PTR es:[di]).bFuncNumber, USB_API_CHECK_PRESENCE
	push	bx
	mov	bx, di
	INVOKE_USB_API_HANDLER
	pop	bx

	cmp	(URP_STRUC PTR es:[di]).ApiData.CkPresence.bBiosActive, USB_BIOS_ACTIVE
	jne	DUD_DisplayDeviceDone	; USB BIOS is not running

	cmp	(URP_STRUC PTR es:[di]).ApiData.CkPresence.bNumBootDev, 0
	jnz	fDUD_USBDevicesFound

; Check for "Auto"
	cmp	bQ_USBLegacyEnable, 2
	jnz	DUD_DisplayDeviceDone	; Not "Auto"

	mov	(URP_STRUC PTR es:[di]).bFuncNumber, USB_API_STOP
	mov	(URP_STRUC PTR es:[di]).bSubFunc, 0
	push	bx
	mov	bx, di
	INVOKE_USB_API_HANDLER
	pop	bx

	jmp	DUD_DisplayDeviceDone	; USB is disabled...

fDUD_USBDevicesFound:
	mov	bx, _str$_usb_device
	call	display_token_message_FAR	; "USB Device(s):" displayed

;----------------------------------------------------------------------------
; URP_STRUC.ApiData.CkPresence now contains the following:
;	bNumKeyboards	- Number of HID Boot keyboards
;	bNumMice	- Number of HID Boot mice
;	bNumHubs	- Number of Downstream hubs
;	bNumStorage	- Number of Mass storage devices
;----------------------------------------------------------------------------
	mov	si, OFFSET CS:USBDeviceStringTable
	add	di, URP_STRUC.ApiData.CkPresence.bNumKeyboards
	xor	bp, bp

DUD_DisplayDeviceLoop:
	cmp	si, offset OFFSET CS:USBDeviceStringTableEnd
	jae	DUD_DisplayDeviceDone

	mov	al, BYTE PTR ES:[di]
	or	al, al
	jz	DUD_DisplayNextDeviceType

	or	bp, bp			; First iteration?
	jz	DUD_SeparatorIsDone	; Yes - no commas required
	mov	bx, _str$_usb_device_separator
	call	display_token_message_FAR	; Display separator
DUD_SeparatorIsDone:
	dec	bp

	mov	bx, cs:[si]		; String for singular item

⌨️ 快捷键说明

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