📄 syskbc.inc
字号:
ECHO -- Including: SYSKBC.INC
TITLE SYSKBC.INC -- Legacy keyboard controller(8042) access code
;***************************************************************************;
;***************************************************************************;
;** **;
;** (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/SYSKBC.INC 4 3/25/03 5:25p Sivagarn $
;
; $Revision: 4 $
;
; $Date: 3/25/03 5:25p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/SYSKBC.INC $
;
; 4 3/25/03 5:25p Sivagarn
; Updated procedure headers with correct register input values
;
; 3 11/08/02 10:50a Sivagarn
; Code added and/or moved to have USB keyboard input support for the
; systems without keyboard controller
;
; 2 10/29/02 7:00p Sivagarn
; - Support for port 60h/64h emulation is added
; - C-type calling convention is changed to assembly type calling
; convention to reduce code size
;
; 1 9/15/02 5:39p Sivagarn
; Initial AMIUSB 2.20 check-in
;
;***************************************************************************;
KBC_COMMAND_REG EQU 064h
KBC_SUBCOMMAND_REG EQU 060h
KBC_STATUS_REG EQU 064h
KBC_DATA_REG EQU 060h
BIT0 EQU 00000001y
BIT1 EQU 00000010y
BIT2 EQU 00000100y
BIT3 EQU 00001000y
BIT4 EQU 00010000y
BIT5 EQU 00100000y
BIT6 EQU 01000000y
BIT7 EQU 10000000y
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBKBC_GetAndStoreCCB
;
; Description: This routine will read the CCB from the keyboard controller
; and store it in a local variable
;
; Input: Nothing
;
; Output: Nothing
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBKBC_GetAndStoreCCB PROC NEAR SYSCALL PUBLIC
push ax
push bx
; Before sending CCB read command to KBC, check whether any data is pending
; to be read
in al, KBC_STATUS_REG
mov ah, al ; Save the KBC Status byte
test ah, BIT0 ; Check for output buffer full bit
jz UKGASC_NoData
; Data is pending. Read it in AL
in al, KBC_DATA_REG
mov bh, al
UKGASC_NoData:
; Read the CCB by using KBC command 20h
mov al, 020h
call KBC_ReadKeyboardControllerData
mov bCCB, al
; Check the saved KBC status register to see is there any valid data in AH
test ah, BIT0 ; Check for output buffer full bit
; Check condition is wrong. Sends random scan codes to KBC
;; jnz UKGASC_NoDataToSend
jz UKGASC_NoDataToSend
; Data has to be sent to the KBC. Check whether it is a KB or mouse data
test ah, BIT5 ; Check for mouse data
mov bl, 0D2h ; Assume it is KB data
jz UKGASC_DataForKB ; data for KB
mov bl, 0D3h ; Data is for mouse
UKGASC_DataForKB:
mov ax, bx
call KBC_WriteKeyboardControllerData ; AL,AH - CMD,DATA
UKGASC_NoDataToSend:
pop bx
pop ax
ret
USBKBC_GetAndStoreCCB ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: KBC_WaitForInputBufferToBeFree
;
; Description: This routine checks the input buffer free bit and waits till
; it is set by the keyboard controller
;
; Input: Nothing
;
; Output: ZR If the input buffer is free
; NZ If the input buffer is not free (Timed out)
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
KBC_WaitForInputBufferToBeFree PROC NEAR SYSCALL PUBLIC
push ax
push cx
mov cx, 16
KWFIBTBF_OuterLoop:
push cx
xor cx, cx
KWFIBTBF_CheckAgain:
in al, KBC_STATUS_REG
test al, BIT1 ; Check input buffer free bit (bit1)
loopnz KWFIBTBF_CheckAgain ; Full! Keep-on checking ..
pop cx
loopnz KWFIBTBF_OuterLoop
pop cx
pop ax
ret
KBC_WaitForInputBufferToBeFree ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: KBC_WaitForOutputBufferToBeFilled
;
; Description: This routine checks the output buffer full bit and waits till
; it is set by the keyboard controller
;
; Input: Nothing
;
; Output: ZR If output buffer is not filled (Timed out)
; NZ If output buffer is filled
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
KBC_WaitForOutputBufferToBeFilled PROC NEAR SYSCALL PUBLIC
push ax
push cx
mov cx, 16
KWFOBTBF_OuterLoop:
push cx
xor cx, cx
KWFOBTBF_CheckAgain:
in al, KBC_STATUS_REG
test al, BIT0 ; Check output buffer full bit (bit0)
loopz KWFOBTBF_CheckAgain ; Free! Keep-on checking ..
pop cx
loopz KWFOBTBF_OuterLoop
pop cx
pop ax
ret
KBC_WaitForOutputBufferToBeFilled ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: KBC_WriteCommandByte
;
; Description: This routine sends the command byte to the keyboard
; controller
;
; Input: AL Command byte
;
; Output: ZR If the input buffer is free
; NZ If the input buffer is not free (Timed out)
;
; Modified: Nothing
;
; Notes: This function does not return the value obtained for the
; command issued
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
KBC_WriteCommandByte PROC NEAR SYSCALL PUBLIC
push ax
; Wait for input buffer to be free
call KBC_WaitForInputBufferToBeFree
jnz kwcb_Exit
; Send the command byte
out KBC_COMMAND_REG, al
; Wait for input buffer to be free
call KBC_WaitForInputBufferToBeFree
kwcb_Exit:
pop ax
ret
KBC_WriteCommandByte ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: KBC_WriteSubCommandByte
;
; Description: This routine sends the sub-command byte to the keyboard
; controller
;
; Input: AL Sub-command byte
;
; Output: Nothing
;
; Modified: Nothing
;
; Notes: This function does not return the value obtained for the
; sub-command issued
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
KBC_WriteSubCommandByte PROC NEAR SYSCALL PUBLIC
push ax
; Send the sub-command byte
out KBC_SUBCOMMAND_REG, al
; Wait for input buffer to be free
call KBC_WaitForInputBufferToBeFree
pop ax
ret
KBC_WriteSubCommandByte ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: KBC_ReadDataByte
;
; Description: This routine till the keyboard controller sends a data byte
;
; Input: Nothing
;
; Output: ZR If there is no data
; NZ If there is data and AL has the data
; AL Data byte received from the KBC
;
; Modified: AL
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
KBC_ReadDataByte PROC NEAR SYSCALL PUBLIC
; Wait for the output buffer to be filled
call KBC_WaitForOutputBufferToBeFilled
jz krdb_Exit
; Read data from the keyboard
in al, KBC_DATA_REG
krdb_Exit:
ret
KBC_ReadDataByte ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: KBC_ReadKeyboardControllerData
;
; Description: This routine sends a command and receives the response byte
; for that command
;
; Input: AL Command to be sent
;
; Output: AL Data byte received from the keyboard controller
;
; Modified: AL
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
KBC_ReadKeyboardControllerData PROC NEAR SYSCALL
; Wait for input buffer to be free
call KBC_WaitForInputBufferToBeFree
jnz krkcd_Exit
; Send the command (AL)
call KBC_WriteCommandByte
jnz krkcd_Exit
; Get the KBC response
call KBC_ReadDataByte
krkcd_Exit:
ret
KBC_ReadKeyboardControllerData ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: KBC_WriteKeyboardControllerData
;
; Description: This routine writes a data byte to the keyboard controller
; by first sending a command byte first
;
; Input: AL Command to be sent
; AH Data to be written
;
; Output: Nothing
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
KBC_WriteKeyboardControllerData PROC NEAR SYSCALL PUBLIC
push ax
; Wait for input buffer to be free
call KBC_WaitForInputBufferToBeFree
jnz kwkcd_Exit
; Send the command
call KBC_WriteCommandByte
jnz kwkcd_Exit
; Write the data
mov al, ah
out KBC_DATA_REG, al
; Wait for input buffer to be free
call KBC_WaitForInputBufferToBeFree
kwkcd_Exit:
pop ax
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -