diff options
-rw-r--r-- | devices/i8042.c | 38 | ||||
-rw-r--r-- | devices/keyboard.h | 2 | ||||
-rw-r--r-- | devices/mouse.c | 27 | ||||
-rw-r--r-- | devices/pckbd.c | 3 | ||||
-rw-r--r-- | devices/pic_8259.c | 4 | ||||
-rw-r--r-- | devices/ps2_controller.h | 3 | ||||
-rw-r--r-- | i686/isr.c | 3 | ||||
-rw-r--r-- | src/kernel.c | 2 |
8 files changed, 61 insertions, 21 deletions
diff --git a/devices/i8042.c b/devices/i8042.c index cf8c6ec..c612e6d 100644 --- a/devices/i8042.c +++ b/devices/i8042.c @@ -12,12 +12,16 @@ // w command register #define comm_port 0x64 #define comm_enable_first_ps2 0xae +#define comm_enable_second_ps2 0xa8 #define comm_read_ctrl_config 0x20 #define comm_write_ctrl_config 0x60 #define data_port 0x60 #define data_enable_scanning 0xf4 +// TODO: All output to port 0x60 or 0x64 must be preceded by waiting for bit 1 (value=2) of port 0x64 to become clear. +// TODO: Similarly, bytes cannot be read from port 0x60 until bit 0 (value=1) of port 0x64 is set. + void ps2_ctrl_init() { @@ -38,16 +42,46 @@ ps2_ctrl_init() // printf("8042: init keyboard\n"); outb(comm_enable_first_ps2, comm_port); + outb(comm_enable_second_ps2, comm_port); + + // resets the cpu + // outb(0xfe, 0x64); + + outb(0xf2, 0x60); + printf("i8042: id port1: "); + while ((inb(0x64) & 0x01) == 0) {} + for (int i = 0; i < 3; ++i) printf("%x ", inb(0x60)); + printf("\n"); + + outb(0xd4, 0x64); + outb(0xf2, 0x60); + printf("i8042: id port2: "); + while ((inb(0x64) & 0x01) == 0) {} + for (int i = 0; i < 3; ++i) printf("%x ", inb(0x60)); + printf("\n"); + outb(comm_read_ctrl_config, comm_port); - const uint8_t conf = (inb(data_port) | 1) & ~0x10; + uint8_t conf = (inb(data_port) | 1) & ~0x10; + conf |= 0x22; // mouse outb(comm_write_ctrl_config, comm_port); outb(conf, data_port); outb(data_enable_scanning, data_port); + + outb(0xd4, 0x64); + outb(0xf4, 0x60); } unsigned char -kbd_read_next() +ps2_read_port1() { return inb(data_port); } + +unsigned char +ps2_read_port2() +{ + + outb(0xd4, 0x64); + return inb(0x60); +} diff --git a/devices/keyboard.h b/devices/keyboard.h index 2375552..5f4fcc2 100644 --- a/devices/keyboard.h +++ b/devices/keyboard.h @@ -2,5 +2,3 @@ void ps2_keyboard_init(); void ps2_keyboard_irq_handler(); - -unsigned char kbd_read_next(); diff --git a/devices/mouse.c b/devices/mouse.c index 92f3f08..a950e8c 100644 --- a/devices/mouse.c +++ b/devices/mouse.c @@ -1,11 +1,9 @@ #include "mouse.h" +#include "ps2_controller.h" #include <stdint.h> #include <stdio.h> #include <sys/io.h> -// TODO: All output to port 0x60 or 0x64 must be preceded by waiting for bit 1 (value=2) of port 0x64 to become clear. -// TODO: Similarly, bytes cannot be read from port 0x60 until bit 0 (value=1) of port 0x64 is set. - void mouse_init() { @@ -14,17 +12,24 @@ mouse_init() // generate any ACK, from either the keyboard or mouse. // enable second ps/2 - // outb(0x64, 0xa8); + // outb(0xa8, 0x64); // outb(0x64, 0xd4); // outb(0x60, 0xf4); // printf("mouse_init: enable streaming(0xf4): %x\n", inb(0x60)); - /* - outb(0x64, 0xd4); - while (inb(0x64) & 0x1) - ; - outb(0x60, 0xf2); - printf("mouse_init: mouse_id(0xf2 %x): %x\n", inb(0x60), inb(0x60)); - */ + outb(0xd4, 0x64); + outb(0xeb, 0x60); // single packet + printf("mouse_init: single packet 0xeb\n"); + while ((inb(0x64) & 0x01) == 0) {} + for (int i = 0; i < 10; ++i) printf("%x ", inb(0x60)); + printf("\n"); +} + +void +mouse_packet() +{ + printf("mouse packet: "); + for (int i = 0; i < 4; ++i) printf("%x ", ps2_read_port2()); + printf("\n"); } diff --git a/devices/pckbd.c b/devices/pckbd.c index 916e8e6..c4fce5b 100644 --- a/devices/pckbd.c +++ b/devices/pckbd.c @@ -1,4 +1,5 @@ #include "keyboard.h" +#include "ps2_controller.h" #include "vga.h" #include <stdint.h> #include <stdio.h> @@ -23,7 +24,7 @@ ps2_keyboard_init() void ps2_keyboard_irq_handler() { - const uint8_t key = kbd_read_next(); + const uint8_t key = ps2_read_port1(); switch (key) { case 0x2a: // left shift down diff --git a/devices/pic_8259.c b/devices/pic_8259.c index d00f74a..75a2d0e 100644 --- a/devices/pic_8259.c +++ b/devices/pic_8259.c @@ -39,11 +39,11 @@ pic_enable() unsigned char mask1 = 0xff; mask1 &= ~(1 << 0); // irq0 timer mask1 &= ~(1 << 1); // irq1 keyboard - // mask1 &= ~(1 << 2); // irq1 cascade + mask1 &= ~(1 << 2); // irq1 cascade outb(mask1, PIC1 + DATA); unsigned char mask2 = 0xff; - // mask2 &= ~(1 << 4); // irq12 mouse + mask2 &= ~(1 << 4); // irq12 mouse outb(mask2, PIC2 + DATA); enable_interrupts(); diff --git a/devices/ps2_controller.h b/devices/ps2_controller.h index 9bed4f2..d2f7e80 100644 --- a/devices/ps2_controller.h +++ b/devices/ps2_controller.h @@ -1,4 +1,5 @@ #pragma once void ps2_ctrl_init(); -unsigned char ps2_ctrl_read(); +unsigned char ps2_read_port1(); +unsigned char ps2_read_port2(); @@ -41,9 +41,10 @@ irq0x01(__attribute__((unused)) struct interrupt_frame *frame) pic_clear(0x01); } +extern void mouse_packet(); __attribute__((interrupt)) void irq0x0c(__attribute__((unused)) struct interrupt_frame *frame) { - printf("irq 0x0c\n"); + mouse_packet(); pic_clear(0x0c); } diff --git a/src/kernel.c b/src/kernel.c index a9c54fe..2777f72 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -33,7 +33,7 @@ void kmain() { ps2_ctrl_init(); ps2_keyboard_init(); - // mouse_init(); + mouse_init(); pic_enable(); printf("interrupts enabled\n"); |