This code sends the first byte to the keyboard, and then (without waiting for the keyboard controller to send that byte to the keyboard or receive the keyboard's response) sends an undocumented command to the keyboard controller. This code does not appear to match your ps2_keyboard_install function.
For the rest of your code, I'll assume PS2_KB_CMD is 0x64 and PS2_KB_DATA is 0x60.
Code: Select all
while(inb(PS2_KB_CMD) & 0x1)
inb(PS2_KB_DATA);
If there is a fault with the keyboard controller, this may become an infinite loop.
Code: Select all
outb(PS2_KB_CMD,0xAA);
if(inb(PS2_KB_DATA) != 0x55)
{
Keyboard controller command 0xAA may take a long time to execute, and it may completely reset the keyboard controller to its power-on defaults. You must wait for the keyboard controller to respond, and you may also need to reconfigure it (e.g. to disable translation and set the "system flag").
Code: Select all
outb(PS2_KB_CMD,0xAB);
if(inb(PS2_KB_DATA) != 0x00)
{
Again, you need to wait for the keyboard controller to respond.
Seriously. Old keyboard controllers are slow. You have to wait.
This reboots the computer, assuming the keyboard controller is ready to accept this command.
This is not a documented keyboard command. The keyboard may misbehave after you send this.
Code: Select all
outb(PS2_KB_CMD,0x20);
uint8_t cfg = (inb(PS2_KB_DATA) | 1) & ~0x10;
// Set config
outb(PS2_KB_CMD,0x60);
outb(PS2_KB_DATA,cfg);
You can probably guess what I'm going to say here: not enough waiting. Also, it's a race condition, since you're enabling IRQ1 before you install an IRQ1 handler.
It looks like you might be confusing the keyboard controller with the keyboard. Both can accept and respond to commands, but sending commands to the keyboard is different from sending commands to the keyboard controller. You should finish initializing your keyboard controller, installing the IRQ handler(s), and enabling the IRQ(s) before you enable the keyboard port and start initializing the keyboard.