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

📄 usb.asm

📁 AMI 主板的BIOS源码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
;*****************************************************************;
;*****************************************************************;
;**                                                             **;
;**      (C)Copyright 1985-1996, American Megatrends, Inc.      **;
;**                                                             **;
;**                     All Rights Reserved.                    **;
;**                                                             **;
;**           6145-F Northbelt Pkwy, Norcross, GA 30071         **;
;**                                                             **;
;**                     Phone (770)-246-8600                    **;
;**                                                             **;
;*****************************************************************;
;*****************************************************************;

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

	include makeflag.equ
	include usb.equ

	if MKF_USB_UHCI
	include uhci.equ
	endif

	if MKF_USB_OHCI
	include ohci.equ
	endif

	include usbdata.dat

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

	public	UsbApiHandler

	public	_UsbSetAddress
	public	_UsbGetDescriptor
	public	_UsbSetConfiguration

	public	UsbDataInit
	public	UsbHubPortChange

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

	extrn	_UsbHcInit		:near
	extrn	_UsbHcClose		:near
	extrn	UsbDeviceRequest	:near
	extrn	UsbEnableRootHubPort	:near
	extrn	UsbDisableRootHubPort	:near
	extrn	UsbGetRootHubPortStatus	:near
	extrn	_UsbActivatePolling	:near
	extrn	_UsbDeactivatePolling	:near
	extrn	UsbHcCheckActive	:near
  
	extrn 	ConnectDevice		:near
	extrn 	DisconnectDevice	:near
	extrn	ProcessKeyboardData	:near
	extrn	ProcessMouseData	:near
	extrn	InitUSBKbDataArea	:near

	extrn	pm_fixed_delay		:near

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


cgroup	group	_text
_text 	segment word public 'CODE'

	assume	cs:cgroup
	assume	ds:usbdgroup
	assume	es:usbdgroup
.386


;---------------------------------------;
; USB BIOS Version Number               ;
;---------------------------------------;
	public	usb_version
usb_version	label	byte
	db	'USB-'
;;;;	db	(USB_BIOS_MAJOR_VERSION SHR 04h) + 30h
	db	(USB_BIOS_MAJOR_VERSION AND 0Fh) + 30h
	db	'.'
	db	(USB_BIOS_MINOR_VERSION SHR 04h) + 30h
	db	(USB_BIOS_MINOR_VERSION AND 0Fh) + 30h
	db	' '
	db	00h

;---------------------------------------;
; USB BIOS API Function Table           ;
;---------------------------------------;
UsbApiTableStart:
	dw	UsbBiosCheckPresent	        ;USB BIOS API function 00h
	dw	UsbBiosInitialize		;USB BIOS API function 01h
	dw	_UsbHcClose			;USB BIOS API function 02h
	dw	UsbDeviceRequest		;USB BIOS API function 03h
	dw	UsbGetHubPortStatus		;USB BIOS API function 04h
	dw	UsbEnableHubPort		;USB BIOS API function 05h
	dw	UsbDisableHubPort		;USB BIOS API function 06h
	dw	UsbBiosReadApiDataBuffer	;USB BIOS API function 07h
	dw	UsbBiosWriteApiDataBuffer	;USB BIOS API function 08h
	dw	UsbBiosGetDeviceTableEntry	;USB BIOS API function 09h
	dw	UsbBiosSetDeviceTableEntry	;USB BIOS API function 0Ah
	dw	UsbBiosCheckDeviceTypePresent	;USB BIOS API function 0Bh
UsbApiTableEnd:


;---------------------------------------;
; UsbApiHandler                         ;
;---------------------------------------;--------------------------------------;
; This function handles calls to the USB BIOS API.  Each call is routed to the ;
; appropriate function based on the function number that was in the upper word ;
; of ESI when software SMI was generated.                                      ;
;                                                                              ;
; Input: cs:[cpu_gen_purpose_reg_entry + reg_esi]                              ;
;           Bit[31:16] = USB BIOS API function number                          ;
;           Bit[15:00] = 'SB' or 5342h                                         ;
;        cs:[cpu_gen_purpose_reg_entry + reg_ebx] = Function specific data     ;
;        cs:[cpu_gen_purpose_reg_entry + reg_ecx] = Function specific data     ;
;        cs:[cpu_gen_purpose_reg_entry + reg_edi] = Function specific data     ;
;        DS = ES = usbdseg (For functions 01h - 0Bh only, DS and ES are        ;
;                  undefined for function 00h)                                 ;
;                                                                              ;
; Output: cs:[cpu_gen_purpose_reg_entry + reg_ebx] = Function specific data    ;
;         cs:[cpu_gen_purpose_reg_entry + reg_ecx] = Function specific data    ;
;         cs:[cpu_gen_purpose_reg_entry + reg_edi] = Function specific data    ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
UsbApiHandler	proc near
	pushad

; Make sure function number is valid and then set BP to the offset
; of the function that is being called.

	mov	ebx, dword ptr cs:[cpu_gen_purpose_reg_entry + reg_esi]
	shr	ebx, 16			;BX = function number

	cmp	bx, (UsbApiTableEnd - UsbApiTableStart) / 2
	jb	UsbApiValidFunc		;Br if valid function number
UsbApiZero:
	stc				;Set carry to indicate error
	jmp	UsbApiCallAbort		;Return to caller

; If calling functions 02h - 0Ah, the USB BIOS must be running the USB HC.
; Generate an error if this condition is not met.

UsbApiValidFunc:
	cmp	bl, 2
	jb	UspApiOkToCall		;Br if calling function 00h or 01h

	call	UsbHcCheckActive	;Returns CL=00/01 for inactive/active
	or	cl, cl
	jz	UsbApiZero		;Br if BIOS not running USB HC

UspApiOkToCall:
	shl	bx, 1			;BX = function number * 2
	add	bx, orgbase
	mov	bp, word ptr cs:[bx + UsbApiTableStart]
	or	bp, bp
	jz	UsbApiZero		;Br if table entry is zero

; Setup input registers from caller's inputs:
;    AX = upper word of EBX
;    BX = BX
;    CX = CX
;    DX = upper word of ECX
;    SI = DI
;    DI = offset ApiDataBuffer

	mov	ebx, dword ptr cs:[cpu_gen_purpose_reg_entry + reg_ebx]
	mov	ecx, dword ptr cs:[cpu_gen_purpose_reg_entry + reg_ecx]
	mov	esi, dword ptr cs:[cpu_gen_purpose_reg_entry + reg_edi]
	mov	eax, ebx		;Get AX from upper half of EBX
	shr	eax, 16
	mov	edx, ecx		;Get DX from upper half of ECX
	shr	edx, 16
	mov	di, offset ApiDataBuffer

	and	byte ptr cs:[cpu_gen_purpose_reg_entry + reg_eflags], 0FEh ;CLC
	add	bp, orgbase
	call	bp			;Call the requested function
UsbApiCallAbort:
	jnc	@f			;Br if CF is clear
	or	byte ptr cs:[cpu_gen_purpose_reg_entry + reg_eflags], 01h ;STC
@@:

; Save any outputs back into registers for return to caller (reverse of
; translation done above).

	mov	dword ptr cs:[cpu_gen_purpose_reg_entry + reg_ebx], ebx
	mov	dword ptr cs:[cpu_gen_purpose_reg_entry + reg_ecx], ecx
	mov	dword ptr cs:[cpu_gen_purpose_reg_entry + reg_edi], esi

	popad
	ret
UsbApiHandler	endp


;---------------------------------------;
; UsbBiosCheckPresent                   ;
;---------------------------------------;--------------------------------------;
; This function is part of the USB BIOS API.  It reports that the USB BIOS     ;
; is present as well as version and status information.                        ;
;                                                                              ;
; Input: Nothing (even DS and ES are undefined)                                ;
;                                                                              ;
; Output: BX = Revision level of USB BIOS (0210h means v2.10)                  ;
;         CH = Number of entries in the DeviceTable array                      ;
;         CL = Flags                                                           ;
;                Bit[7:4] = Reserved                                           ;
;                Bit[3:1] = Number of ports on root hub of host controller     ;
;                Bit[0]   = 1 if USB BIOS is running host controller           ;
;                           0 if USB BIOS is not running host controller       ;
;         ESI = Current USB data area                                          ;
;         CF = Clear (USB BIOS is present)                                     ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
UsbBiosCheckPresent	proc near
	call	UsbHcCheckActive	;Returns CL = flags
	mov	bx, (USB_BIOS_MAJOR_VERSION * 100h) + USB_BIOS_MINOR_VERSION
	mov	ch, MAX_DEVICES + 1

	xor	esi, esi		;Clear upper half of ESI
	test	cl, 1
	jz	@f			;Br if USB BIOS is not active
	mov	si, ds			;DS valid if HC has been inited
	shl	esi, 4			;Convert seg to abs addr
@@:
	clc
	ret
UsbBiosCheckPresent	endp


;---------------------------------------;
; UsbBiosInitialize                     ;
;---------------------------------------;--------------------------------------;
; This function initializes the USB host controller and optionally causes      ;
; the USB to be enumerated.                                                    ;
;                                                                              ;
; Input: DS  = ES = usbdseg                                                    ;
;        EBX = 32-bit absolute address of USB BIOS data area (usbdseg)         ;
;        CL  = USB BIOS initialization flags                                   ;
;              Bit 2-0: 000 = Auto enum                                        ;
;                       001 = KB on port 1                                     ;
;                       ...   ...                                              ;
;                       111 = KB on port 7                                     ;
;              Bit 3: If set, do not enum the USB                              ;
;              Bit 4: If set, do not beep on new devices                       ;
;              Bit 7-5: Reserved                                               ;
;                                                                              ;
; Output: CF = Clear if initialization was successful, set otherwise           ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
UsbBiosInitialize	proc near
; Clear the 8k data area to be used by USB.

	pusha
	xor	di, di			;Start at offset 0
	mov	cx, 1000h		;Clear 4k words
	xor	ax, ax
	rep	stosw			;Clear 8k data area
	popa

	mov	InitializationFlags, cl	;Save initialization flags

	call	_UsbHcInit		;Init the host controller

	ret
UsbBiosInitialize	endp


;---------------------------------------;
; UsbBiosReadApiDataBuffer              ;
;---------------------------------------;--------------------------------------;
; This function allows USB BIOS API callers to read 8 bytes of data from the   ;
; ApiDataBuffer starting at a given offset.                                    ;
;                                                                              ;
; Input: SI = Offset within buffer to read                                     ;
;        DS:DI = Segment:Offset ApiDataBuffer                                  ;
;                                                                              ;
; Output: EBX = Data bytes 0 - 3 read from ApiDataBuffer                       ;
;         ECX = Data bytes 4 - 7 read from ApiDataBuffer                       ;
;         CF = Clear (USB BIOS is present)                                     ;
;                                                                              ;
; Destroys: Nothing                                                            ;
;------------------------------------------------------------------------------;
UsbBiosReadApiDataBuffer	proc near
	push	si

	xor	ebx, ebx		;Setup default return values

⌨️ 快捷键说明

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