I'd read a lot of about 8042 microcontroller. This because I'm making my
own bootloader and I need understand on how to enable a20 gate. But,
before I try to enable the a20 gate, I'm trying something more simple,
IMHO, i.e., trying to turn on all led indicators.
But I have few questions:
Is the 8042 INSIDE the keyboard case?
When I make a comand to 60h, the command is received by 8042?
When I make a command to 64h, the command is received by motherboard onboard microcontroller?
reference: http://www.arl.wustl.edu/~lockwood/clas ... HEADING1-5
Also, the following code is my attempt to turn on leds in windows or
real mode (in my bootloader). It doesn't works. Can someone help me?
In the case of testing the code in my boot loader, I just include the
code via inc directive after my "Hello Word" message.
I already read other articles in the forum about enable keyboard leds and already try them, but without success.
note: I have a notebook. But I think that this does not change anything.
Code: Select all
; Turn on all leds of the keyboard.
ORG 0x100 ; Remove it in case of it is placed in bootloader.
turnOnLeds:
;This subroutine will turn on led indicators in the keyboard controller.
;Takes no arguments. Returns 0 in AX register on success, -1 on failure.
;Written for use in 16-bit code.
; Status Register
STATUS_PORT equ 0x64
KBD_OUT_BUF equ 0x60
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Symbolic constants definition
; Status Register Bits Names
SR_BIT0_OUTPUT_BUFFER equ 0 ; 0->has no data for system; 1->has data for system
SR_BIT1_INPUT_BUFFER equ 1 ; 0->has no data for 8042; 1-> has data for 8042
SR_BIT2_SYSTEM_FLAG equ 2 ; system flag (set to 0 after power on reset)
SR_BIT3_COMMAND_DATA equ 3 ; type of information in input register. 1->command; 0->data
SR_BIT4_ENABLED_DISABLED equ 4 ; 1->keyboard enabled; 2-> keyboard disabled (via switch)
SR_BIT5_TRANSMIT_TIMEOUT equ 5 ; 1->transmit timeout
SR_BIT6_RECEIVE_TIMEOUT equ 6 ; 1-> receive timeout
SR_BIT7_PARITY equ 7 ; 1-> even parity; 0->odd parity
; Keyboard Commands
KB_LED_CMD equ 0xED
; Keyboard Led Indicators
KB_CAPS_LOCK equ 001b
KB_NUM_LOCK equ 010b
KB_SCROLL_LOCK equ 101b
;KB_ALL_LEDS equ KB_CAPS_LOCK | KB_NUM_LOCK | KB_SCROLL_LOCK
KB_ALL_LEDS equ 111b
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
pusha ; Pushes the contents of the general-purpuse registers
; onto the stack following order: AX, CX, DX, BX, BP, SP
; (original value), BP, SI and DI. The value pushed for
; the SP register is its value before prior to pushing
; the first register.
cli ; Disable interrupts
; Wait for the keyboard controller to be ready for a command
xor ax,ax ; Clear ax
.commandWait1:
in al,STATUS_PORT ; Reads the 8042 status register
bt ax,SR_BIT1_INPUT_BUFFER ; Test if command buffer is full
jc .commandWait1 ; Input buffer is full. Try again.
mov al,KB_LED_CMD ; Tell 8042 we wanna change the LEDs
out KBD_OUT_BUF,al ; Send the command
.wait:
xor ax,ax
in al,STATUS_PORT
bt ax,SR_BIT1_INPUT_BUFFER ; Test if command came through
jc .wait
xor ax,ax
mov al,KB_ALL_LEDS ; Tell 8042 the option byte
out KBD_OUT_BUF,al ; Set all LED's to ON
sti ; Re-enable interrupts
popa ; Pops words from the stack into the general-purpose
; registers. The registers are loaded in the following
; order: DI, SI, BP, BX, DX, CX and AX. The value on
; the stack for the SP register is ignored. Instead,
; the SP register is incremented after each register
; is loaded.
ret
;------------------------------------------------------------;
; keyboard wait ;
; Wait for the keyboard controller to be ready for a command ;
;------------------------------------------------------------;
;.kbd_wait:
;jmp $+2
;in al,STATUS_PORT
;test al,1
;jz .ok
;jmp $+2
;in al,KBD_OUT_BUF
;jmp .kbd_wait
;.ok:
;test al,2
;jnz .kbd_wait
;ret
Best regards,
Marco Alves.