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

📄 usbbb.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 4 页
字号:
	TITLE	USBBB.ASM -- USB Boot Block Routines

;***************************************************************************;
;***************************************************************************;
;**                                                                       **;
;**           (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/USBBB.ASM 2     11/17/02 8:11p Sivagarn $
;
; $Revision: 2 $
;
; $Date: 11/17/02 8:11p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBBB.ASM $
; 
; 2     11/17/02 8:11p Sivagarn
; - Code to include/exclude code for USB keyboard support in the boot
; block is added based on the flag "USB_BB_DEV_KBD"
; - USB host controllers are stopped if there is no devices are connected
; to it.  If not stopped the host controllers block the initialization of
; second host controller
; 
; 1     10/14/02 8:40p Sivagarn
;  * USB boot block related files are added
; 
;***************************************************************************;

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

;----------------------------------------------------------------------------
;		Macro and equate files are included here
;----------------------------------------------------------------------------
	INCLUDE equates.equ
	INCLUDE	usb.equ
	INCLUDE	mbiosequ.equ
	INCLUDE	mbiosmac.mac
;----------------------------------------------------------------------------
;;; Build flag adjustments
IFNDEF	MKF_USB_BB_DEV_KBD
MKF_USB_BB_DEV_KBD	EQU	0
ENDIF	;; IFNDEF	MKF_USB_BB_DEV_KBD


;----------------------------------------------------------------------------
;		External data definitions are defined here
;----------------------------------------------------------------------------
	EXTERN	USBHCPCIInfoTableStart:NEAR
	EXTERN	USBHCPCIInfoTableEnd:NEAR
	EXTERN	USB_DSEG_DATA_END:NEAR
	EXTERN	USBBadDeviceTable:NEAR
	EXTERN	USBBadDeviceTableEnd:NEAR
	EXTERN	boot_block_flag:BYTE
	EXTERN	stMassDeviceInfo:MassDeviceInfo
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		External function definitions are defined here
;----------------------------------------------------------------------------
read_pci_far		PROTO FAR SYSCALL
write_pci_far		PROTO FAR SYSCALL
read_pci_dword_far	PROTO FAR SYSCALL
write_pci_dword_far	PROTO FAR SYSCALL
fixed_delay_far		PROTO FAR SYSCALL
;----------------------------------------------------------------------------

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

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

;----------------------------------------------------------------------------
; RUN_CSEG  S E G M E N T  STARTS
;----------------------------------------------------------------------------
RUN_CSEG SEGMENT BYTE COMMON 'CODE'

RUN_CSEG ENDS

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

	PUBLIC	_USBBB_ASM_START
_USBBB_ASM_START	LABEL		BYTE

;<AMI_THDR_START>
;----------------------------------------------------------------------------
; Name:		BBHCDriverTable - Boot block Host Controller Driver Table
;
; Type:		Driver Header Table
;
; Description:	This is the table of header addresses used in boot block
;
;----------------------------------------------------------------------------
;<AMI_THDR_END>

BBHCDriverTable		LABEL		WORD
IF	MKF_USB_BB_UHCI
	EXTERN	UHCIBB_HCHeader:BBHCDHEADER
	DW	OFFSET UHCIBB_HCHeader
ENDIF
IF	MKF_USB_BB_OHCI
	EXTERN	OHCIBB_HCHeader:BBHCDHEADER
	DW	OFFSET OHCIBB_HCHeader
ENDIF
IF	MKF_USB_BB_EHCI
	EXTERN	EHCIBB_HCHeader:BBHCDHEADER
	DW	OFFSET EHCIBB_HCHeader
ENDIF
	DW	0

; Global variable defined in the code segment
		PUBLIC	bCurrentDeviceType
bCurrentDeviceType	BYTE		?

		PUBLIC	pDeviceInitializer
pDeviceInitializer	WORD		?

IF	MKF_USB_BB_DEV_KBD
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	farEnableUSBKeyboard
;
; Description:	This eProcedure will enable the first USB keyboard found and
;		schedule the polling for the keyboard
;
; Input: 	None
;
; Output: 	None
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

farEnableUSBKeyboard		PROC FAR PUBLIC

	push	ax
	push	cx
	push	ds
	push	es

; Set current device type that we are looking as keyboard
	mov	CS:bCurrentDeviceType, BIOS_DEV_TYPE_KEYBOARD
	mov	ax, OFFSET USBBB_ConfigureKeyboard
	mov	CS:pDeviceInitializer, ax
	call	USBBB_EnumerateUSBDevice	; Changes DS, ES
	jz	fEUK_Exit

	sti		; Allow interrupts
; Keyboard found and connected
; Delay for n*100 milli seconds
	mov	cx, 5		; n
fEUK_KBDDelay:
	push	cx
	mov	cx, (100 * 1000)/15	; 100 ms
	call	fixed_delay_far
	pop	cx
	loop	fEUK_KBDDelay

fEUK_Exit:
	pop	es
	pop	ds
	pop	cx
	pop	ax
	ret
farEnableUSBKeyboard		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	farShutdownUSBHostController
;
; Description:	This eProcedure will disable the USB host controller that
;		is running
;
; Input: 	None
;
; Output: 	None
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

farShutdownUSBHostController	PROC FAR PUBLIC
	push	ax
	push	bx
	push	ds

; Set the data segment
	push	USB_DSEG
	pop	ds
; DS - Data segment

	mov	bx, CurrentHC.pHCDPointer
	or	bx, bx
	jz	fUBDK_Exit
; Issue the HCD stop HC call
	call	(BBHCDHEADER PTR CS:[bx]).pHCDStopHC


; Get the IRQ number
	mov	al, MKF_USB_BB_IRQ

	add	al, 8			;IRQ 0/1/../7 -> INT 8/9/../F
	cmp	al, 10h
	jb	InitVector		;Br if IRQ 0..7
	add	al, 70h - 10h 		;Add offset of second 8259's vectors
InitVector:

	movzx	bx, al			;BX = HC's interrupt vector
	shl	bx, 2			;BX = addr of interrupt vector to hook

	mov	eax, dNextISR
	push	ds
	push	0			;Set DS = 0
	pop	ds
	xchg	DWORD PTR [bx], eax	;Hook interrupt
	pop	ds


fUBDK_Exit:
	pop	ds
	pop	bx
	pop	ax
	ret
farShutdownUSBHostController	ENDP
ENDIF	;; IF		MKF_USB_BB_DEV_KBD


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBBB_EnumerateUSBDevice
;
; Description:	This function looks for the device type specified in the
;		variable CS:bCurrentDeviceType and configures it
;
; Input: 	None
;
; Output: 	ZR	If no such device found
;		NZ	If device found
;
; Modified:	DS, ES
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBBB_EnumerateUSBDevice	PROC NEAR PUBLIC

	pushad

; Set the data segment
	push	USB_DSEG
	pop	ds
; DS - Data segment

; Initialize the memory for global data
	push	ds
	pop	es
	xor	di, di			; Start at offset 0
	mov	cx, OFFSET USB_DSEG_DATA_END
	shr	cx, 2			; Divide by 4
	xor	eax, eax

	rep	stosd			; Clear entire USB data area

; Form global data area address
	mov	ax, ds
	shl	eax, 4			; EAX is already zero
	mov	dGlobalDataArea, eax

	xor	dx, dx
; DL	0 Indicating EHCI initialization is not done
	mov	si, OFFSET USBHCPCIInfoTableStart

UBCUD_CheckNextHC:
	cmp	si, OFFSET USBHCPCIInfoTableEnd
	jae	UBCUD_CheckHCInitDone

; Check whether EHCI HC intialization is already done
	or	dl, dl
	jnz	UBCUD_EHCIInitDone

; Look for EHCI HC
	cmp	(HC_INFO_STRUC PTR CS:[si]).bHCType, USB_EHCI
	jne	UBCUD_PrepareForNextEntry	; It is a non-EHCI controller

; EHCI HC found. Hand over the HC ports to classic HCs

; Save the HC info struc pointer
	mov	pHCInfoStrucPtr, si

; Enable the HC by programming appropriate registers
	mov	ebx, MKF_USB_BB_MEM_BASE
	mov	ah, USB_MEM_BASE_ADDRESS
	call	USBBB_EnableHC

	push	fs
	push	di
; Set FS:DI to point to the memory base address of the HC
; EBX	Memory base address
	shr	ebx, 4
	mov	fs, bx
	xor	di, di	

; Get the operational register offset
	xor	ax, ax
	mov	al, BYTE PTR FS:[di]
	add	di, ax

; Clear the "Configure Flag" in CONFIGFLAG register (ofset OpBase+40h)
	and	BYTE PTR FS:[di+40h], NOT BIT0
	pop	di
	pop	fs
	jmp	SHORT UBCUD_PrepareForNextEntry

UBCUD_EHCIInitDone:
; Look for non-EHCI controllers
	cmp	(HC_INFO_STRUC PTR CS:[si]).bHCType, USB_EHCI
	je	UBCUD_PrepareForNextEntry

UBCUD_InitHC:
; Update the HC information in the local variables

; Save the HC info struc pointer
	mov	pHCInfoStrucPtr, si

; Save the bus, device function number of the HC
	mov	ax, (HC_INFO_STRUC PTR CS:[si]).wBusDevFuncNumber
	mov	CurrentHC.wBusDevFuncNum, ax

; Save the HC type
	mov	al, (HC_INFO_STRUC PTR CS:[si]).bHCType
	mov	CurrentHC.bHCType, al

; Find the appropriate HC driver and store its pointer
	call	USBBB_FindHCDriver
	jz	UBCUD_PrepareForNextEntry

; Issue the HC initialize call (returns number of ports present in the HC)
	mov	bx, CurrentHC.pHCDPointer
	call	(BBHCDHEADER PTR CS:[bx]).pHCDInitializeHC
	jz	UBCUD_PrepareForNextEntry	; Failed - Try next HC

; CL	Number of ports in the HC
; Set that no hub was found
	mov	bCurrentHubDeviceEntry, 0FFh

; Set the current device address as 0
	mov	bCurrentDeviceAddress, 0

; Check the hub port for device presence
	push	si
	mov	si, OFFSET CurrentDevice
	call	USBBB_EnumerateHubPorts
	pop	si
	jz	UBCUD_NoDeviceFound
	jmp	UBCUD_Exit		; Zero flag cleared

UBCUD_NoDeviceFound:
; Stop the HC
	mov	bx, CurrentHC.pHCDPointer
	call	(BBHCDHEADER PTR CS:[bx]).pHCDStopHC

; No keyboard found. Nullfy the HCD pointer
	mov	CurrentHC.pHCDPointer, 0

UBCUD_PrepareForNextEntry:
	add	si, SIZE HC_INFO_STRUC
	jmp	UBCUD_CheckNextHC

UBCUD_CheckHCInitDone:
; End of the table reached. Check we really initialized all the HC or 
; we just initialize the EHCI controllers.
	or	dl, dl
	jnz	UBCUD_ErrorExit

; We initialized only the EHCI HC. Now set the appropriate flags and 
; start from the first entry in the table but initialize non-EHCI
; host controllers

; EHCI init done. Now do the init for other HCs
	dec	dl
	mov	si, OFFSET USBHCPCIInfoTableStart
	jmp	UBCUD_CheckNextHC

UBCUD_ErrorExit:
; Set zero flag
	cmp	sp, sp

UBCUD_Exit:
	popad
	ret

USBBB_EnumerateUSBDevice	ENDP


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBBB_EnumerateHubPorts
;
; Description:	This function power-up each port in the USB (root)hub and 
;		check for device presence
;
; Input: 	CL	Number of ports to enumerate
;		SI	Pointer to the device information structure
;
; Output: 	ZR	On error (no matching device found)
;		NZ	On success (matching device found and configured)
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBBB_EnumerateHubPorts		PROC NEAR PUBLIC
	pusha

; Check the root hub ports to see if a device is connected.  If so, then
; call UsbHubPortChange to handle the attachment of a new device.
	mov	ch, cl			; Save CL in CH
	xor	cl, cl			; CL will count through port numbers

UBEHP_CheckNextPort:
	inc	cl
	cmp	cl, ch
	ja	UBEHP_Done

; Power up the port
	call	USBBB_EnableHubPort
	jz	UBEHP_DisableHubPort

; Device present. Port status in AX
	test	ax, USB_PORT_STAT_DEV_CONNECTED
	jz	UBEHP_CheckNextPort		; No device connected

; Device connected. Store the device speed
	and	al, USB_PORT_STAT_DEV_SPEED_MASK
	shr	al, USB_PORT_STAT_DEV_SPEED_MASK_SHIFT
;;	mov	(DeviceInfo PTR [si]).bEndpointSpeed, al
	mov	CurrentDevice.bEndpointSpeed, al

; Set the device information variables
	mov	CurrentDevice.bDeviceAddress, 0
	mov	CurrentDevice.wEndp0MaxPacket, 40h

; Check whether the call is for hub or root hub
	cmp	bCurrentHubDeviceEntry, 0FFh
	jne	UBEHP_NotRootHub
	mov	bCurrentHCPortNumber, cl
UBEHP_NotRootHub:

; Get device type
	call	USBBB_GetDeviceType
; DL	Device type
	jnz	UBEHP_CheckForHub

UBEHP_DisableHubPort:
; Disable the hub port
	call	USBBB_DisableHubPort	; Error code ignored
; Check the next port
	jmp	UBEHP_CheckNextPort


UBEHP_CheckForHub:
; Check for hub
	cmp	dl, BIOS_DEV_TYPE_HUB
	jne	UBEHP_CheckForCurrentDeviceType

; Initialize the hub 

; Check for free hub device entry
	mov	al, bCurrentHubDeviceEntry
	inc	al
	cmp	al, MKF_HUB_DEVICE_LIMIT
	ja	UBEHP_DisableHubPort	; No free entry found

; Configure the device by setting address & configuration
	call	USBBB_ConfigureUSBDevice
	jz	UBEHP_DisableHubPort

; Get hub descriptor
	call	USBBB_GetHubDescriptor
; DS:DI	Hub descriptor
	jz	UBEHP_DeviceInitFailed

⌨️ 快捷键说明

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