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

📄 syskbc.inc

📁 dos下的USB源码(包括UHCI
💻 INC
📖 第 1 页 / 共 2 页
字号:
KBC_WriteKeyboardControllerData	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	KBC_UpdateLEDState
;
; Description:	This routine updates the LED state in the PS/2 keyboard
;
; Input: 	AL	LED state data
;
; Output: 	Nothing
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

KBC_UpdateLEDState	PROC NEAR SYSCALL PUBLIC
	push	ax
	push	bx

; Wait for input buffer to be free
	call	KBC_WaitForInputBufferToBeFree
	jnz	SKULS_Exit

; Save AL in BL
	mov	bl, al

; one of these commands must work
;;;;	mov	al,0d1h		; write output port command
;;;;	mov	al,0d4h		; write to aux port command
;;;;	mov	al,60h		; write command byte command
; Send command to KBC
	mov	al, MKF_USB_SEND_COMMAND_TO_KBC
	call	KBC_WriteCommandByte
	jnz	SKULS_Exit

	in	al, KBC_STATUS_REG

; Save the status for future use
	mov	ah, al

	test	al, BIT0		; Check for output buffer full bit
	jz	SKULS_NoData

; Data is pending. Read it in AL
	in	al, KBC_DATA_REG
	mov	bh, al

SKULS_NoData:

	push	ax

	mov	al, 0AEh
	call	KBC_WriteCommandByte		; Send command to KBC

	mov	al, 0EDh			; LED-ON command
	call	KBC_WriteSubCommandByte
	call	KBC_ReadDataByte

	mov	al, bl
	call	KBC_WriteSubCommandByte		; Send LED status data
	call	KBC_ReadDataByte
	pop	ax

; Status byte in AH

	test	ah, BIT0
	jz	SKULS_Exit		; No data pending. Exit !

	test	ah, BIT5		; Check for KB data
	mov	bl, 0D2h		; KB data
	jz	SKULS_Cont

	mov	bl, 0D3h		; Mouse data
SKULS_Cont:
	mov	ax, bx
	call	KBC_WriteKeyboardControllerData		; AL,AH - CMD,DATA

SKULS_Exit:
	pop	bx
	pop	ax
	ret
KBC_UpdateLEDState	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	KBC_SendkeyboardData
;
; Description:	This routine sends the data to the keyboard through the
;		keyboard controller
;
; Input: 	AL	Data to be sent
;
; Output: 	Nothing
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

KBC_SendKeyboardData	PROC NEAR SYSCALL PUBLIC
	push	ax

	mov	ah, 0D2h
	xchg	ah, al
	call	KBC_WriteKeyboardControllerData		; AL,AH - CMD,DATA

	pop	ax
	ret
KBC_SendKeyboardData	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	KBC_SendMouseData
;
; Description:	This routine sends the data to the mouse through the
;		keyboard controller
;
; Input: 	AL	Data to be sent
;
; Output: 	Nothing
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

KBC_SendMouseData	PROC NEAR SYSCALL PUBLIC
	push	ax

	mov	ah, 0D3h
	xchg	ah, al
	call	KBC_WriteKeyboardControllerData		; AL,AH - CMD,DATA

	pop	ax
	ret
KBC_SendMouseData	ENDP

IF	MKF_USB_KBC_EMULATION
	PUBLIC	_SYSKBC_6064_TRAPPING_START
_SYSKBC_6064_TRAPPING_START	LABEL		BYTE

USBKBC_TrapHandlerTable		LABEL	WORD
	WORD	OFFSET SYSKBC_HandleReadPort60
	WORD	OFFSET SYSKBC_HandleWritePort60
	WORD	OFFSET SYSKBC_HandleReadPort64
	WORD	OFFSET KBC_HandleWritePort64

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	SYSKBC_HandleReadPort60
;
; Description:	This routine will handle the trapping caused by port 60h
;		read operation
;
; Input: 	SI	HCStruc structure pointer
;
; Output: 	AL	BIT0	(Trap that is serviced)
;
; Modified:	AX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

SYSKBC_HandleReadPort60		PROC NEAR PUBLIC

; Check whether password feature is enabled
	test	wUSBKBC_StatusFlag, KBC_PASSWORD_FLAG_BIT_MASK
	jz	skhrp60_PasswordDisabled

	in	al, KBC_STATUS_REG
	test	al, BIT5	; Check for mouse data
	in	al, KBC_DATA_REG
	jnz	skhrp60_MouseData

	call	USBKBC_VerifyPassword
; Return acknowledgement
	mov	bLastPort60Value, 0FAh
	jmp	SHORT skhrp60_Exit

skhrp60_MouseData:
IF	MKF_USB_DEV_MOUSE
	test	bMouseStatusFlag, MOUSE_DATA_READY_BIT_MASK
	jnz	skhrp60_USBMouseData
ENDIF
	mov	al, 00h		; Data from PS/2 mouse
skhrp60_USBMouseData:
IF	MKF_USB_DEV_MOUSE
; Reset mouse data flag
	and	bMouseStatusFlag, NOT MOUSE_DATA_READY_BIT_MASK
ENDIF
	mov	bLastPort60Value, al
	jmp	SHORT skhrp60_Exit

skhrp60_PasswordDisabled:
	in	al, KBC_DATA_REG	; Read from port 60h

; Save the 60h value
	mov	bLastPort60Value, al

	call	USBKBD_ReturnAL		; Return AL for the appropriate CPU

skhrp60_Exit:

	mov	al, BIT0
	ret
SYSKBC_HandleReadPort60		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	SYSKBC_HandleWritePort60
;
; Description:	This routine will handle the trapping caused by port 60h
;		write operation
;
; Input: 	SI	HCStruc structure pointer
;
; Output: 	AL	BIT1	(Trap that is serviced)
;
; Modified:	AX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

SYSKBC_HandleWritePort60		PROC NEAR PUBLIC

; Indicate that port 60h/64h emulation is in progress
	or	wUSBKBC_StatusFlag, KBC_PORT6064_TRAP_BIT_MASK

; Get the value that was output to the port 60h
	call	USBKBD_GetAL

; Check for port 60h handler routine
	cmp	pPort60Handler, 0
	jz	shw60_Handle60

; Dispatch to the correct routine
	jmp	pPort60Handler

shw60_Handle60:
	push	bx

; Enable keyboard interface
	and	bCCB, NOT CCB_KEYBOARD_DISABLED

; Save the port 60h value
	mov	bx, ax

; Send the data to 8042
	call	KBC_WriteSubCommandByte

; Get the status
	in	al, KBC_STATUS_REG
	mov	ah, al		; Save the status

; Check for data presence
	test	al, BIT0
	jz	shw60_NoData

; Read the data
	in	al, KBC_DATA_REG

shw60_NoData:
	xchg	al, ah

	push	ax		; Save the data & status
	call	KBC_ReadDataByte
	jnz	shw60_ValidData
	mov	al, 0FEh	; Time out

shw60_ValidData:
; Save the data received
	mov	bExternalKBData, al

; Restore port 60h command value
	mov	ax, bx

; Dispatch to corresponding routine
	push	ax
	sub	al, 0EDh
	mov	bx, OFFSET CS:KBC_Write60CommandTable
	jnc	shw60_Proceed		; Commands 0EDh to 0FFh

	mov	al, bKBMSCommandStatus
	and	al, 07h
; Non-zero means command followed by data

	mov	bx, OFFSET CS:KBC_Write60CommandDataTable
shw60_Proceed:
; Clear the command flag
	and	bKBMSCommandStatus, NOT (BIT0+BIT1+BIT2)

	movzx	ax, al
	shl	ax, 1
	add	bx, ax
	pop	ax

	call	WORD PTR CS:[bx]

; Restore data & status
	pop	ax
	test	al, BIT0
	jz	shw60_Exit

	test	al, BIT5
	mov	al, 0D2h		; Keyboard data
	jz	shw60_SendData
	mov	al, 0D3h		; Mouse data
shw60_SendData:
	call	KBC_WriteKeyboardControllerData		; AL,AH - CMD,DATA

shw60_Exit:
	pop	bx
	mov	al, BIT1
	ret
SYSKBC_HandleWritePort60		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	SYSKBC_HandleReadPort64
;
; Description:	This routine will handle the trapping caused by port 64h
;		read operation
;
; Input: 	SI	HCStruc structure pointer
;
; Output: 	AL	BIT2	(Trap that is serviced)
;
; Modified:	AL
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

SYSKBC_HandleReadPort64		PROC NEAR PUBLIC

	in	al, KBC_COMMAND_REG	; Read from port 64h

	call	USBKBD_ReturnAL		; Return AL for the appropriate CPU

	mov	al, BIT2
	ret
SYSKBC_HandleReadPort64		ENDP



;----------------------------------------------------------------------------
	PUBLIC	_SYSKBC_6064_TRAPPING_END
_SYSKBC_6064_TRAPPING_END	LABEL		BYTE
ENDIF	; MKF_USB_KBC_EMULATION

;***************************************************************************;
;***************************************************************************;
;**                                                                       **;
;**           (C)Copyright 1985-2002, American Megatrends, Inc.           **;
;**                                                                       **;
;**                          All Rights Reserved.                         **;
;**                                                                       **;
;**                6145-F Northbelt Pkwy, Norcross, GA 30071              **;
;**                                                                       **;
;**                          Phone (770)-246-8600                         **;
;**                                                                       **;
;***************************************************************************;
;***************************************************************************;

⌨️ 快捷键说明

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