Keyboard\Mouse Micro-controller Commands and other uses
The 8042 Micro-Controller not only controls Mouse/Keyboard but also provides set of functions to enable A20 Gate,Rebooting,Halting,Speaker,etc.Here are few examples of using the micro-controller features for other purposes.
A_20 GATE
The A20 gate is the physical representation of the 21st bit of any memory access.To get memory access more than 1MB we need to enable this A20 Gate.This can be done using the keyboard controller, system port, or using the BIOS.
Through the Keyboard Controller
Command's
0xDD Enable A20 Address Line
0xDF Disable A20 Address Line
Using the keyboard to enable A20:
EnableA20_KB:
cli ;Disables interrupts
push ax ;Saves AX
mov al, 0xdd ;Look at the command list
out 0x64, al ;Command Register
pop ax ;Restore's AX
sti ;Enables interrupts
ret
Halting or Rebooting System:
The keyboard microcontroller can also be used for rebooting or halting the system.
int system_restart()
{
keyboard_wait();
outportb(0x64,0xD1);
keyboard_wait();
outportb(0x60,0xFE);
return 0;
}
Micro-controller Functions:
0x20 Read command byte
0x60 Write command byte
0xAA Self Test
0xAB Interface Test
0xAD Disable Keyboard
0xAE Enable Keyboard
0xC0 Read Input Port
0xD0 Read Output Port
0xD1 Write Output Port
0xE0 Read Test Inputs
0xFE System Reset
0xA7 Disable Mouse Port
0xA8 Enable Mouse Port
0xA9 Test Mouse Port
0xD4 Write To Mouse Non Standard Commands
0x00-0x1F Read Controller RAM
0x20-0x3F Read Controller RAM
0x40-0x5F Write Controller RAM
0x60-0x7F Write Controller RAM
0x90-0x93 Synaptics Multiplexer Prefix
0x90-0x9F Write port 13-Port 10
0xA0 Read Copyright
0xA1 Read Firmware Version
0xA2 Change Speed 0xA3Change Speed
0xA4 Check if password is installed
0xA5 Load Password
0xA6 Check Password
0xAC Disagnostic Dump
0xAF Read Keyboard Version
0xB0-0xB5 Reset Controller Line
0xB8-0xBD Set Controller Line
0xC1 Continuous input port poll, low
0xC2 Continuous input port poll, high
0xC8 Unblock Controller lines P22 and P23
0xC9 Block Controller lines P22 and P23
0xCA Read Controller Mode
0xCB Write Controller Mode
0xD2 Write Output Buffer
0xD3 Write Mouse Output Buffer
0xDD Disable A20 address line
0xDF Enable A20 address line
0xF0-0xFF Pulse output bit
Using (0xAA)Keyboard Self Test function provided by the micro-controller:
unsigned int keyboard_test ()
{
unsigned char testcheck = inportb(0x60);
unsigned char data = inportb(0x64);
unsigned int temp = 1;
keyboard_wait();
outportb(0x64,0xAA);
while (1) if (data & 1) break;
if(testcheck == 0x55)
{
temp = 0;
}
return temp;
}
A_20 GATE
The A20 gate is the physical representation of the 21st bit of any memory access.To get memory access more than 1MB we need to enable this A20 Gate.This can be done using the keyboard controller, system port, or using the BIOS.
Through the Keyboard Controller
Command's
0xDD Enable A20 Address Line
0xDF Disable A20 Address Line
Using the keyboard to enable A20:
EnableA20_KB:
cli ;Disables interrupts
push ax ;Saves AX
mov al, 0xdd ;Look at the command list
out 0x64, al ;Command Register
pop ax ;Restore's AX
sti ;Enables interrupts
ret
Halting or Rebooting System:
The keyboard microcontroller can also be used for rebooting or halting the system.
int system_restart()
{
keyboard_wait();
outportb(0x64,0xD1);
keyboard_wait();
outportb(0x60,0xFE);
return 0;
}
Micro-controller Functions:
0x20 Read command byte
0x60 Write command byte
0xAA Self Test
0xAB Interface Test
0xAD Disable Keyboard
0xAE Enable Keyboard
0xC0 Read Input Port
0xD0 Read Output Port
0xD1 Write Output Port
0xE0 Read Test Inputs
0xFE System Reset
0xA7 Disable Mouse Port
0xA8 Enable Mouse Port
0xA9 Test Mouse Port
0xD4 Write To Mouse Non Standard Commands
0x00-0x1F Read Controller RAM
0x20-0x3F Read Controller RAM
0x40-0x5F Write Controller RAM
0x60-0x7F Write Controller RAM
0x90-0x93 Synaptics Multiplexer Prefix
0x90-0x9F Write port 13-Port 10
0xA0 Read Copyright
0xA1 Read Firmware Version
0xA2 Change Speed 0xA3Change Speed
0xA4 Check if password is installed
0xA5 Load Password
0xA6 Check Password
0xAC Disagnostic Dump
0xAF Read Keyboard Version
0xB0-0xB5 Reset Controller Line
0xB8-0xBD Set Controller Line
0xC1 Continuous input port poll, low
0xC2 Continuous input port poll, high
0xC8 Unblock Controller lines P22 and P23
0xC9 Block Controller lines P22 and P23
0xCA Read Controller Mode
0xCB Write Controller Mode
0xD2 Write Output Buffer
0xD3 Write Mouse Output Buffer
0xDD Disable A20 address line
0xDF Enable A20 address line
0xF0-0xFF Pulse output bit
Using (0xAA)Keyboard Self Test function provided by the micro-controller:
unsigned int keyboard_test ()
{
unsigned char testcheck = inportb(0x60);
unsigned char data = inportb(0x64);
unsigned int temp = 1;
keyboard_wait();
outportb(0x64,0xAA);
while (1) if (data & 1) break;
if(testcheck == 0x55)
{
temp = 0;
}
return temp;
}