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

📄 usbwrap.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 4 页
字号:
; Set function as failure
	mov	al, USB_ATA_TIME_OUT_ERR
	jmp	SHORT UAMDR_Exit

UMADR_SetDevInfo:
; Set device info pointer in SI
	mov	si, ax

; If hot plug FDD/CDROM is enabled then pHCStrucPtr may be 0
	cmp	(DeviceInfo PTR [si]).pHCStrucPtr, 0
	je	UAMDR_InvokeFunction

; Check whether the control is with the BIOS
	push	bx
	push	si

	mov	si, (DeviceInfo PTR [si]).pHCStrucPtr

; Invoke host controller's check BIOS own status call
	mov	bx, (HCStruc PTR [si]).pHCDPointer
	call	(HCDHEADER PTR cs:[bx]).pHCDCheckControlStatus
	pop	si
	pop	bx
	jnz	UMADR_SetFuncFailure


UAMDR_InvokeFunction:
; Setup input registers from caller's inputs:
; ES:BX	UPR pointer
	retn		; Invokes the function (DO NOT USE RET!)

UAMDR_ReturnAddress:
; Return value in AX

IF	MKF_USB_MODE GE 2
	push	eax
; Save the time we left the USB SMI
	push	ds
	push	40h
	pop	ds
	mov	eax, dword ptr ds:[6Ch]		; EAX = Current Int1A Tick Counter
	pop	ds

; Store Current Int1A Tick Counter
	mov	dTimeLastInSMI, eax
	pop	eax
ENDIF

ENDIF ; MKF_USB_DEV_MASS

UAMDR_Exit:
	ret
USBAPI_MassDeviceRequest	ENDP


;----------------------------------------------------------------------------
;			USB API Procedures Starts
;----------------------------------------------------------------------------

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBAPI_CheckPresence
;
; Description:	This routine services the USB API function number 0.  It
;		reports the USB BIOS presence, its version number and
;		its current status information
;
; Input: 	ES:BX		Pointer to the URP structure
;
; Output: 	URP structure is updated with the following information
;		CkPresence.wBiosRev	USB BIOS revision (0210h means r2.10)
;		CkPresence.bBiosActive	0 - if USB BIOS is not running
;		CkPresence.bNumBootDev	Number of USB boot devices found
;		CkPresence.bNumHC	Number of host controller present
;		CkPresence.bNumPorts	Number of root hub ports
;		CkPresence.dUsbDataArea	Current USB data area
;
; Modified:	AL
;
; Referrals:	URP_STRUC, USBWrap_GetDeviceCount
;
; Notes:	DS is undefined if USB BIOS is un-initialized
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBAPI_CheckPresence	PROC NEAR SYSCALL PUBLIC

	push	eax
	push	cx
	push	di
	push	ds

; Initialize the return value
	xor	eax, eax
	mov	di, bx
	add	di, URP_STRUC.ApiData.CkPresence
	mov	cx, SIZE CK_PRESENCE
	rep	stosb

	mov	ax, (USB_BIOS_MAJOR_VERSION * 100h) + USB_BIOS_MINOR_VERSION
	mov	(URP_STRUC PTR es:[bx]).ApiData.CkPresence.wBiosRev, ax

	xor	ax, ax		; Get current segment
	call	USBGetDataSegment
	jz	UBCP_Exit

; DS - USB data segment
	cmp	UsbBiosActive, 0
	jz	UBCP_Exit

; Set USB BIOS as active
	mov	(URP_STRUC PTR es:[bx]).ApiData.CkPresence.bBiosActive, \
						USB_BIOS_ACTIVE

; Get active USB devices
; ES:BX	far pointer to URP structure
	call	USBWrap_GetDeviceCount

	mov	ax, ds
	movzx	eax, ax
	shl	eax, 4
	mov	(URP_STRUC PTR es:[bx]).ApiData.CkPresence.dUsbDataArea, eax

UBCP_Exit:
	pop	ds
	pop	di
	pop	cx
	pop	eax
	mov	al, USB_SUCCESS
	ret
USBAPI_CheckPresence	ENDP


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBAPI_Start
;
; Description:	This API routine configures the USB host controllers and
;		enumerate the devices
;
; Input: 	ES:BX			URP structure with input parameters
;		StartHc.wDataAreaFlag	Indicates which data area to use
;		StartHc.dExtDataArea	Address of the extended data area
;
; Output: 	StartHc.wDataAreaFlag	Returns current data area pointer
;		AX			USB_SUCCESS on success
;					USB_ERROR on error
;
; Modified:	EAX
;
; Referrals:	URP_STRUC, START_HC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBAPI_Start	PROC NEAR SYSCALL PUBLIC USES BX ESI DS ES


IFDEF _BBLK_
; Set the boot block data area if necessary
	mov	al, USB_CALLED_AT_BBLK
	call	USBPort_UpdateDataAreaTable
ELSE
; Set the data area for POST, if necessary
	mov	al, USB_CALLED_AT_INIT
	call	USBPort_UpdateDataAreaTable
ENDIF


; Call the USB start function
	mov	ax, (URP_STRUC PTR es:[bx]).ApiData.StartHc.wDataAreaFlag
	mov	esi, (URP_STRUC PTR es:[bx]).ApiData.StartHc.dExtDataArea
	call	USBStartHC
			
	mov	(URP_STRUC PTR es:[bx]).ApiData.StartHc.wDataAreaFlag, ax
	cmp	ax, 0FFFFh
	je	UAS_ErrorExit

	mov	ax, USB_SUCCESS
	jmp	SHORT UAS_Exit

UAS_ErrorExit:
	mov	ax, USB_ERROR
UAS_Exit:
	ret
USBAPI_Start	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBAPI_Stop
;
; Description:	This routine stops the USB host controllers
;
; Input: 	ES:BX	Pointer to the URP structure
;
; Output: 	AX	USB_SUCCESS on success
;			USB_ERROR on error (Like data area not found)
;
; Modified:	AX
;
; Referrals:	USBWrap_CallHCD, HCStruc, URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBAPI_Stop	PROC NEAR SYSCALL  USES BX DS


; Invoke each host controllers stop HC call
	mov	bx, HCDHEADER.pHCDStop
	call	USBCallAllHC

; Clear the data area signature
; Get and set the data segment address
	xor	ax, ax		; Get current segment
	call	USBGetDataSegment
	jnz	USBS_GoOn

	mov	al, USB_ERROR
	jmp	SHORT USBS_Exit

USBS_GoOn:
; DS - USB data segment
	xor	eax, eax
	mov	USBDataAreaSignature, eax	; Ax = 0
	mov	al, USB_SUCCESS

USBS_Exit:
	ret
USBAPI_Stop	ENDP


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBAPI_PowerManageUSB
;
; Description:	This routine suspends the USB host controllers
;
; Input: 	ES:BX	Pointer to the URP structure
;
; Output: 	AX
;
; Modified:	AX
;
; Referrals:	USBWrap_CallHCD, URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBAPI_PowerManageUSB	PROC NEAR SYSCALL PUBLIC USES BX DX SI DS

	mov	dl, (URP_STRUC PTR es:[bx]).bSubFunc

; Set DS properly
; Get and set the data segment address
	xor	ax, ax		; Get current segment
	call	USBGetDataSegment
	jz	UPMU_Exit
; DS - USB data segment

; Start from first HCStruc
	mov	si, 0FFFFh

UPMU_ProcessNextHCStruc:
; Get next HCStruc
	call	USBGetNextHCStruc	; SI - HCStruc
	clc
	je	UPMU_Exit

; SI - New HCStruc

; Invoke each host controller's suspend HC call
	mov	bx, (HCStruc PTR [si]).pHCDPointer
	mov	al, dl
; AL	Power management subfunction
	call	(HCDHEADER PTR cs:[bx]).pHCDPowerManagement

	jmp	SHORT UPMU_ProcessNextHCStruc

UPMU_Exit:
	ret

USBAPI_PowerManageUSB	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBAPI_PrepareForOS
;
; Description:	This routine updates data structures to reflect that
;		POST is completed
;
; Input: 	ES:BX	Pointer to the URP structure
;
; Output: 	AX	USB_SUCCESS
;
; Modified:	AX
;
; Referrals:	USBWrap_CallHCD, URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBAPI_PrepareForOS	PROC NEAR SYSCALL PUBLIC USES DS

; Set DS properly
; Get and set the data segment address
	xor	ax, ax		; Get current segment
	call	USBGetDataSegment
	jz	UPFO_Exit

; DS - USB data segment

; Set the USB acquired by OS flag
	mov	USBAcquiredByOS, TRUE

; Enable the port 60h/64h trapping SMI
IF	(MKF_USB_MODE EQ 2) AND (MKF_USB_KBC_EMULATION)
; Start from first HCStruc
	mov	si, 0FFFFh

UPFO_ProcessNextHCStruc:
; Get next HCStruc
	call	USBGetNextHCStruc	; SI - HCStruc
	clc
	je	UPFO_Exit

; SI - New HCStruc
; Check for UHCI host controllers
	cmp	(HCStruc PTR [si]).bHCType, USB_UHCI
	jne	UPFO_ProcessNextHCStruc

; Invoke each host controller's enable trapping call
	mov	bx, (HCStruc PTR [si]).pHCDPointer
	call	(HCDHEADER PTR cs:[bx]).pHCDEnableTrapping

	jmp	SHORT UPFO_ProcessNextHCStruc
ENDIF

UPFO_Exit:
	mov	ax, USB_SUCCESS
	ret

USBAPI_PrepareForOS	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBAPI_DisableInterrupts
;
; Description:	This routine stops the USB host controllers interrupts
;
; Input: 	ES:BX	Pointer to the URP structure
;
; Output: 	AL	USB_SUCCESS on success
;			USB_ERROR on error (Like data area not found)
;
; Modified:	AX
;
; Referrals:	URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBAPI_DisableInterrupts	PROC NEAR SYSCALL

; Invoke each host controllers stop HC call
	push	bx
	mov	bx, HCDHEADER.pHCDDisableInterrupts
USBAPI_CommonCallAllHC::
	call	USBCallAllHC

	mov	al, USB_SUCCESS
	pop	bx

	ret
USBAPI_DisableInterrupts	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBAPI_EnableInterrupts
;
; Description:	This routine re-enable the USB host controller interrupts
;
; Input: 	ES:BX	Pointer to the URP structure
;
; Output: 	AL	USB_SUCCESS on success
;			USB_ERROR on error (Like data area not found)
;
; Modified:	AX
;
; Referrals:	URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBAPI_EnableInterrupts		PROC NEAR SYSCALL

; Invoke each host controllers start HC call
	push	bx
	mov	bx, HCDHEADER.pHCDEnableInterrupts
	jmp	SHORT USBAPI_CommonCallAllHC

USBAPI_EnableInterrupts		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBAPI_MoveDataArea
;
; Description:	This routine stops the USB host controllers and moves
;		the data area used by host controllers to a new area.
;		The host controller is started from the new place.
;
; Input: 	ES:BX		URP structure with input parameters
;		StartHc.wDataAreaFlag	Indicates which data area to use
;
; Output: 	AL	USB_SUCCESS
;
; Modified:	AX
;
; Referrals:	URP_STRUC, START_HC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBAPI_MoveDataArea	PROC NEAR SYSCALL

; ES:BX	fpURPPointer

Comment ~
; Update data area table, if necessary
	mov	al, USB_CALLED_AT_MOVE
	call	USBPort_UpdateDataAreaTable

⌨️ 快捷键说明

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