diff --git a/Makefile b/Makefile index c4276fd..0ac57b4 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive if=none,id=stick,format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci -device usb-mouse -device usb-storage,drive=stick -device usb-kbd +EMUFLAGS = -m 1G -drive if=none,id=stick,format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci -device usb-storage,drive=stick BUILD_FOLDER = build diff --git a/Makefile b/Makefile index c4276fd..0ac57b4 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive if=none,id=stick,format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci -device usb-mouse -device usb-storage,drive=stick -device usb-kbd +EMUFLAGS = -m 1G -drive if=none,id=stick,format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci -device usb-storage,drive=stick BUILD_FOLDER = build diff --git a/src/userland/ps2/main.c b/src/userland/ps2/main.c index bd97a92..54465e3 100644 --- a/src/userland/ps2/main.c +++ b/src/userland/ps2/main.c @@ -1,6 +1,41 @@ #include +#include + +typedef union { + uint8_t byte; + struct { + uint8_t outputBufferStatus:1; + uint8_t inputBufferStatus: 1; + uint8_t sytemFlag: 1; + uint8_t commandData: 1; + uint8_t unused: 2; + uint8_t timeoutError: 1; + uint8_t parityError: 1; + } __attribute__((packed)) data; + } Status; + +Status readStatus() { + Status result = {.byte = ioIn(0x64, 1)}; + return result; +} + +void waitForRead() { + uint32_t timeout = 100000; + while (!readStatus().data.outputBufferStatus) { + if (--timeout == 0) { + printf("PS/2 read timeout\n"); + return; + } + } +} + +uint8_t read(uint8_t device) { + waitForRead(); + return ioIn(0x60, 1); +} int32_t main() { - loadFromInitrd("ps2kb"); - return 0; + createFunction("read", (void *)read); + loadFromInitrd("ps2kb"); + return 0; } diff --git a/Makefile b/Makefile index c4276fd..0ac57b4 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive if=none,id=stick,format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci -device usb-mouse -device usb-storage,drive=stick -device usb-kbd +EMUFLAGS = -m 1G -drive if=none,id=stick,format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci -device usb-storage,drive=stick BUILD_FOLDER = build diff --git a/src/userland/ps2/main.c b/src/userland/ps2/main.c index bd97a92..54465e3 100644 --- a/src/userland/ps2/main.c +++ b/src/userland/ps2/main.c @@ -1,6 +1,41 @@ #include +#include + +typedef union { + uint8_t byte; + struct { + uint8_t outputBufferStatus:1; + uint8_t inputBufferStatus: 1; + uint8_t sytemFlag: 1; + uint8_t commandData: 1; + uint8_t unused: 2; + uint8_t timeoutError: 1; + uint8_t parityError: 1; + } __attribute__((packed)) data; + } Status; + +Status readStatus() { + Status result = {.byte = ioIn(0x64, 1)}; + return result; +} + +void waitForRead() { + uint32_t timeout = 100000; + while (!readStatus().data.outputBufferStatus) { + if (--timeout == 0) { + printf("PS/2 read timeout\n"); + return; + } + } +} + +uint8_t read(uint8_t device) { + waitForRead(); + return ioIn(0x60, 1); +} int32_t main() { - loadFromInitrd("ps2kb"); - return 0; + createFunction("read", (void *)read); + loadFromInitrd("ps2kb"); + return 0; } diff --git a/src/userland/ps2kb/main.c b/src/userland/ps2kb/main.c index d14cc99..f97f4e1 100644 --- a/src/userland/ps2kb/main.c +++ b/src/userland/ps2kb/main.c @@ -22,25 +22,14 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -uint8_t getScancode() { - int_fast16_t scancode = -1; - for (uint16_t i = 0; i < 1000; i++) { - if ((ioIn(0x64, 1) & 1) == 0) { - continue; - } - scancode = ioIn(0x60, 1); - break; - } - return scancode; -} - REQUEST(keyDown, "keyboard", "keyDown"); REQUEST(keyUp, "keyboard", "keyUp"); +REQUEST(read, "ps2", "read"); void onKey() { - uint8_t scancode = getScancode(); + uint8_t scancode = read(0, 0); if (scancode == 0xE0) { - scancode = getScancode(); + scancode = read(0, 0); if (scancode & 0x80) { return; }