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

📄 usbkbd.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 5 页
字号:
	TITLE	USBKBD.ASM -- USB Keyboard Device Protocol Handler

;***************************************************************************;
;***************************************************************************;
;**                                                                       **;
;**           (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/USBKBD.ASM 8     3/25/03 5:30p Sivagarn $
;
; $Revision: 8 $
;
; $Date: 3/25/03 5:30p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBKBD.ASM $
; 
; 8     3/25/03 5:30p Sivagarn
; Routine "USBKBD_ConvertLinearToPhysical" is changed to
; "USBMisc_ConvertLinearToPhysical". Routine is moved to USBMISC.ASM
; file.
; 
; 7     3/17/03 5:52p Sivagarn
;   - Byte flag 'bUSBInitFlag' is changed to double word 'dUSBInitFlag'
;   - Bug in getting correct physical address from the CS:EIP, for the P4
; CPUs is 
; 
; corrected
;   - Bug in supporting 3D-mouse (Mouse with scroll wheel) in
; KBC_EMULATION mode (port 60h/64h trapping) is corrected
; 
; 6     02/12/03 5:45p Tonylo
; USB004 - Bug fixed for USB BarCode reader legacy support failed.
; 
; 5     11/20/02 5:52p Sivagarn
; - Port 60h/64h support for multiple CPUs is supported
; 
; 4     11/08/02 10:50a Sivagarn
; Code added and/or moved to have USB keyboard input support for the
; systems without keyboard controller
; 
; 3     10/29/02 6:46p Sivagarn
;  - Support for port 60h/64h emulation is added
;  - C-type calling convention is changed to assembly type calling
; convention to reduce code size
; 
; 2     10/14/02 9:00p Sivagarn
;  * Code cleanup
;  * Old boot block related code is removed
; 
; 1     9/15/02 5:39p Sivagarn
; Initial AMIUSB 2.20 check-in
; 
;***************************************************************************;


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

;----------------------------------------------------------------------------
;		Macro and equate files are included here
;----------------------------------------------------------------------------
	INCLUDE equates.equ
	INCLUDE	usbflag.equ
	INCLUDE	usb.equ
	INCLUDE usbkbd.equ
	INCLUDE mbiosequ.equ
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		External data definitions are defined here
;----------------------------------------------------------------------------
	EXTERN	bUSBDeviceList:BYTE

IF	MKF_USB_DEV_MOUSE
	EXTERN	pMouseInputBufferHeadPtr:WORD
	EXTERN	pMouseInputBufferTailPtr:WORD
	EXTERN	pMouseInputBufferStart:WORD
	EXTERN	bMouseStatusFlag:BYTE
ENDIF
	EXTERN	dUSBInitFlag:DWORD

IF	MKF_USB_KBC_EMULATION
	EXTERN	SMI_Dump_REGS:CPUDumpStruct
	EXTERN	rt_cmos_byte:BYTE
ENDIF
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		External function definitions are defined here
;----------------------------------------------------------------------------
USBActivateDevicePolling		PROTO NEAR SYSCALL
USBIssueControlTransferWithoutData	PROTO NEAR SYSCALL
USBIssueControlTransfer			PROTO NEAR SYSCALL

USBGetDeviceInfoFromDevAddr	PROTO NEAR SYSCALL

USBLogError			PROTO NEAR SYSCALL

IF	MKF_USB_DEV_MOUSE
USBMouse_GetFromMouseBuffer	PROTO NEAR C
USBMSSendMouseData		PROTO NEAR C
USBMSUpdateMouseInterface	PROTO NEAR C
ENDIF

IFE	MKF_KBC_SUPPORT
int_09				PROTO FAR SYSCALL
int_74				PROTO FAR SYSCALL

	EXTERN	USBAcquiredByOS:BYTE
ENDIF

IF	MKF_USB_KBC_EMULATION
USBMisc_ConvertLinearToPhysical	PROTO NEAR SYSCALL
ENDIF

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

;----------------------------------------------------------------------------
;		Public function definitions are defined here
;----------------------------------------------------------------------------
	PUBLIC	UKSKD_WriteKBData
	PUBLIC	pProcessBIOSKeys_FAR
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		Function prototype definitions are here
;----------------------------------------------------------------------------
USBKBDConnectKeyboard		PROTO NEAR SYSCALL
USBKBDFindUSBKBDeviceTableEntry	PROTO NEAR SYSCALL

USBKB_LEDOn			PROTO NEAR SYSCALL
USBKB_Scanner			PROTO NEAR SYSCALL
USBKB_UpdateLEDState		PROTO NEAR SYSCALL
USBKB_CheckForNumericKeyPadKey	PROTO NEAR SYSCALL
USBKB_CheckForExtendedKey	PROTO NEAR SYSCALL
USBKB_ConvertSet2CodeToSet1Code	PROTO NEAR SYSCALL
USBKB_ConvertScanCodeBetweenCodeSet PROTO NEAR SYSCALL
USBKB_GenerateScanCode		PROTO NEAR C bCodeGenFlag:BYTE,
					bKeyCode:BYTE, wWorkOffset:WORD
USBKB_GenerateType1MakeCode	PROTO NEAR C
USBKB_GenerateType2MakeCode	PROTO NEAR C
USBKB_GenerateType1BreakCode	PROTO NEAR C
USBKB_GenerateType2BreakCode	PROTO NEAR C
USBKB_DiscardCharacter		PROTO NEAR C pBuffer:NEAR

USBKBC_GetAndStoreCCB		PROTO NEAR SYSCALL
USBKBC_SendToCharacterBuffer	PROTO NEAR SYSCALL
USBKBC_CheckCharacterBufferFull	PROTO NEAR SYSCALL
USBKBC_SendKBCData		PROTO NEAR C
USBKBC_CheckAutoRepeat 		PROTO NEAR C

IF	MKF_KBC_SUPPORT
KBC_ReadDataByte			PROTO NEAR SYSCALL
KBC_WaitForInputBufferToBeFree		PROTO NEAR SYSCALL
ELSE
VIRKBC_GetCommandByte			PROTO NEAR SYSCALL
ENDIF
KBC_WriteCommandByte			PROTO NEAR SYSCALL
;----------------------------------------------------------------------------

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

;----------------------------------------------------------------------------
; Each entry points to the DeviceInfo structure of the USB KB device
pUSBKBDeviceTable		DW	MKF_HID_DEVICE_LIMIT DUP (?)

;----------------------------------------------------------------------------
; The following word flag stores data regarding USB keyboard
; controller operation. The bit status information is as follows:
;----------------------------------------------------------------------------
;   Bit Position		Description
;----------------------------------------------------------------------------
;	1,0		Represents current scan code set number (1, 2 or 3)
;	6-2		Typematic rate 0 = 30 char/sec, 31 = 2 char/sec
;	8,7		Typematic rate delay (00 - 250ms, 01 - 500ms,
;			10 - 750ms & 11 - 1000ms)
;	9		Auto repeat bit (1 - Enabled)
;	10		Keyboard controller password status (0 or 1-Enabled)
;	11		Keyboard scanner disabled (1) or enabled (0)
;	12		Keyboard trapping (port 60/64h) status (1-Enabled)
;	13		Make/break code generation (0-Make, 1-Break)
;	15,14		Keyboard/mouse data transmitting order
;			(00, 01 - Mouse data first, 10 - Keyboard data first)
;----------------------------------------------------------------------------
	PUBLIC wUSBKBC_StatusFlag
wUSBKBC_StatusFlag		DW	?
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
; The following byte flag stores data regarding USB keyboard
; controller operation. The bit status information is as follows:
;----------------------------------------------------------------------------
;   Bit Position		Description
;----------------------------------------------------------------------------
;	0		LED update is in progress
;	7-1		Reserved
;----------------------------------------------------------------------------
	PUBLIC bUSBKBC_ExtStatusFlag
bUSBKBC_ExtStatusFlag		DB	?
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
; The following byte flag stores data regarding USB keyboard LED
; status. The bit status information is as follows:
;----------------------------------------------------------------------------
;   Bit Position		Description
;----------------------------------------------------------------------------
;	7		Function key LED status
;	6		Scroll-lock key LED status
;	5		CAPS-lock key LED status
;	4		NUM-lock key LED status
;	3		Alternate (ALT) keypress status
;	2		Control (CTRL) keypress status
;	1		Left-shift keypress status
;	0		Right-shift keypress status
;----------------------------------------------------------------------------
bUSBKBShiftKeyStatus		DB	?	;  Keeps USB KBD LED state

;----------------------------------------------------------------------------
; The following byte flag stores data regarding USB keyboard LED
; status. The bit status information is as follows:
;----------------------------------------------------------------------------
;   Bit Position		Description
;----------------------------------------------------------------------------
;	7		Reserved (0-Always)
;	6		CAPS-lock key LED status
;	5		NUM-lock key LED status
;	4		Scroll-lock key LED status
;	3 		Free
;	2		Scroll-lock key LED status (If KB password is enabled)
;	1		CAPS-lock key LED status (If KB password is enabled)
;	0		NUM-lock key LED status  (If KB password is enabled)
;----------------------------------------------------------------------------
	PUBLIC	bNonUSBKBShiftKeyStatus
bNonUSBKBShiftKeyStatus		DB	?	; Keeps non-USB KBD LED state
;----------------------------------------------------------------------------
IF	MKF_USB_KBC_EMULATION
bLastPort60Value		BYTE	?
bRAMAddress			BYTE	?
pPort60Handler			WORD	?

aKBCPassword			BYTE	16 DUP (?)
aKBCPasswordEnd			LABEL	BYTE
wPasswordPtr			WORD	?
bOutputPortStatus		BYTE	?
bExternalKBData			BYTE	?
bKBMSCommandStatus		BYTE	?
	KBMS_0EDh_FLAG		EQU	1	; xxxx x001
	KBMS_0F0h_FLAG		EQU	1	; xxxx x010
	KBMS_0F3h_FLAG		EQU	1	; xxxx x011
	KBMS_0FBh_FLAG		EQU	1	; xxxx x100
	KBMS_0FCh_FLAG		EQU	1	; xxxx x101
	KBMS_0FDh_FLAG		EQU	1	; xxxx x110

; Dynamic scan code set 3 table. Size is 128 X 2 bits = 32 bytes, 8 dwords
pDynamicScanCodeSet3Table	DB	32 DUP (?)

; Temporary storage for the scan code set 3 scan code
bSet3ScanCode			DB	?

fDescriptorTable		DW	?
				DD	?

bCurrentTrapSMI			DB	?
ENDIF
;----------------------------------------------------------------------------
; Keyboard character buffer head and tail pointers
pKBCCharacterBufferHead		DW	?
pKBCCharacterBufferTail		DW	?

; Keyboard character buffer start and end addresses
		PUBLIC	pKBCCharacterBufferStart
;(USB004)>
;Enlarge character buffer for some HID devices might report a mount of 
;data shortly (like BarCode reader).
;X  pKBCCharacterBufferStart	DB	16 DUP (?)
pKBCCharacterBufferStart	DB	80 DUP (?)
;<(USB004)
pKBCCharacterBufferEnd		LABEL		WORD
;----------------------------------------------------------------------------

; Keyboard scan code buffer pointer
pKBCScanCodeBufferPtr		DW	?

; Keyboard scan code buffer start and end addresses
		PUBLIC	pKBCScanCodeBufferStart
pKBCScanCodeBufferStart		DB	16 DUP	(?)
pKBCScanCodeBufferEnd		LABEL	WORD

; Buffer to store keyboard shift key status bytes. This is correlated with
; scan code buffer to generate proper scan code sequence
		PUBLIC	pKBCShiftKeyStatusBufferStart
pKBCShiftKeyStatusBufferStart	DB	16 DUP (?)
pKBCShiftKeyStatusBufferEnd	LABEL	WORD

; Buffer to store keyboard device ID
	public	pKBCDeviceIDBufferStart
pKBCDeviceIDBufferStart		DB	16 DUP (?)
pKBCDeviceIDBufferEnd		LABEL	WORD
;----------------------------------------------------------------------------
; Keyboard expanded input buffer pointer (null-terminated)
pKBInputBuffer			DB	16 DUP (?)
;----------------------------------------------------------------------------
; Keyboard controller command byte (CCB)
	PUBLIC	bCCB
bCCB				BYTE	32 DUP (?)
CCB_KEYBOARD_DISABLED			EQU	BIT4
CCB_MOUSE_DISABLED			EQU	BIT5
CCB_TRANSLATE_SCAN_CODE_BIT_MASK	EQU	BIT6
;----------------------------------------------------------------------------
; Temporary location to store the HCStruc pointer
	PUBLIC	SavedHCStrucPtr
SavedHCStrucPtr			DW	?

; Temporary storage for the scan code set 2 scan code
bSet2ScanCode			DB	?

; Last USB key code processed
bLastUSBKeyCode			DB	?

; Current USB key code under processing
bCurrentUSBKeyCode		DB	?

; Device IDs for the keyboards generating break code
bBreakCodeDeviceID		DB	?

; Current USB keyboard device ID
bCurrentDeviceID		DB	?
;----------------------------------------------------------------------------
; Typematic repeat counter
wRepeatCounter			DW	?

; Typematic repeat rate
wRepeatRate			DW	?
;----------------------------------------------------------------------------
dKBReportData			DD	?

pProcessBIOSKeys_FAR		DD	?

		PUBLIC	USBKBC_DataEnd
USBKBC_DataEnd		LABEL		BYTE
USB_DSEG		ENDS
;----------------------------------------------------------------------------
;	C O D E   S E G M E N T
;----------------------------------------------------------------------------
USB_CSEG 	SEGMENT	WORD USE16 PUBLIC 'CODE'
	ASSUME	cs:USB_CSEG
	ASSUME	ds:USB_DSEG
.586p

	PUBLIC	_USBKBD_ASM_START
_USBKBD_ASM_START		LABEL		BYTE

	PUBLIC	USBKBDDeviceHeader
USBKBDDeviceHeader		LABEL		USB_DEV_HDR
	DB	BIOS_DEV_TYPE_KEYBOARD
	DW	OFFSET USBKBDInitialize			; Initialize
	DW	OFFSET USBKBDCheckForKeyboard		; Identify
	DW	OFFSET USBKBDConfigureKeyboard		; Configure
	DW	OFFSET USBKBDDisconnectKeyboard		; Disconnect

;----------------------------------------------------------------------------
; 		USB HID Related Static Tables
;----------------------------------------------------------------------------
	PUBLIC	_USBKBD_STAT_TABLE_START
_USBKBD_STAT_TABLE_START		LABEL		BYTE

;----------------------------------------------------------------------------
pStaticSet2ToSet1ScanCode	LABEL		BYTE
	DB	000h,0E5h,0F5h,006h,016h,026h,01Eh,03Dh	; 00h - 07h
	DB	0DCh,0DDh,0EDh,0FDh,00Eh,087h,0B6h,035h	; 08h - 0Fh
	DB	0D4h,03Eh,0AEh,07Ch,017h,07Fh,0EFh,02Dh	; 10h - 17h
	DB	0CCh,074h,09Eh,007h,00Fh,077h,0E7h,025h	; 18h - 1Fh
	DB	0C4h,08Eh,096h,0FEh,06Fh,0D7h,0DFh,01Dh	; 20h - 27h
	DB	0BCh,036h,086h,0F6h,05Fh,067h,0CFh,015h	; 28h - 2Fh
	DB	0B4h,076h,07Eh,0E6h,0EEh,057h,0C7h,00Dh	; 30h - 37h
	DB	0ACh,06Ch,06Eh,0DEh,04Fh,0BFh,0B7h,005h	; 38h - 3Fh
	DB	0A4h,066h,0D6h,047h,03Fh,0A7h,0AFh,0FCh	; 40h - 47h
	DB	09Ch,05Eh,056h,0CEh,0C6h,037h,09Fh,0F4h	; 48h - 4Fh
	DB	094h,064h,0BEh,05Ch,02Fh,097h,0ECh,08Ch	; 50h - 57h
	DB	02Eh,04Eh,01Fh,027h,054h,0A6h,0E4h,04Ch	; 58h - 5Fh
	DB	055h,04Dh,044h,03Ch,034h,02Ch,08Fh,024h	; 60h - 67h
	DB	01Ch,085h,014h,0A5h,0C5h,00Ch,004h,084h	; 68h - 6Fh
	DB	06Dh,065h,07Dh,09Dh,095h,0BDh,0F7h,0D5h	; 70h - 77h
	DB	045h,08Dh,075h,0ADh,046h,0B5h,0CDh,05Dh	; 78h - 7Fh
	DB	0FBh,0F3h,0EBh,0F5h,05Dh		; 80h - 84h
;----------------------------------------------------------------------------
	Public	pStaticKeyPadScan2Table
pStaticKeyPadScan2Table		LABEL		BYTE
	DB	END_KEY, LEFT_KEY, HOME_KEY, INSERT_KEY
	DB	DEL_KEY, DOWN_KEY, RIGHT_KEY, UP_KEY
	DB	PAGE_DOWN_KEY, PAGE_UP_KEY
pStaticKeyPadScan2TableEnd	LABEL		BYTE

;----------------------------------------------------------------------------
pStaticExtendedKeyScan2Table	LABEL		BYTE
	DB	RIGHT_ALT, RIGHT_CTRL, RIGHT_ENTER, LEFT_MS_KEY
	DB	RIGHT_MS_KEY, APP_MS_KEY
pStaticExtendedKeyScan2TableEnd	LABEL		BYTE

⌨️ 快捷键说明

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