aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-03-03 11:43:43 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-03-03 11:43:43 +0200
commit02a703e8dca690780d6e00198274a2139e89f01a (patch)
tree0688710e65f0a8e81719b739393935399ef1022e
parentAdd keyboard driver (diff)
downloadkernel.cpp-02a703e8dca690780d6e00198274a2139e89f01a.tar.xz
Add some comments to keyboard driver
-rw-r--r--drivers/keyboard.cc27
-rw-r--r--drivers/keyboard.h10
-rw-r--r--drivers/ports.h3
-rw-r--r--src/makefile3
-rw-r--r--toolchain.makefile3
5 files changed, 33 insertions, 13 deletions
diff --git a/drivers/keyboard.cc b/drivers/keyboard.cc
index 268ce2b..09fd4e9 100644
--- a/drivers/keyboard.cc
+++ b/drivers/keyboard.cc
@@ -1,15 +1,28 @@
#include "keyboard.h"
#include <stdlib.h>
+/*
+ * https://wiki.osdev.org/%228042%22_PS/2_Controller
+ * https://wiki.osdev.org/PS/2_Keyboard
+ */
+
+constexpr uint8_t comm_enable_first_ps2 = 0xae;
+constexpr uint8_t comm_read_ctrl_config = 0x20;
+constexpr uint8_t comm_write_ctrl_config = 0x60;
+
+constexpr uint8_t dat_enable_scanning = 0xf4;
+
Keyboard::Keyboard() : InterruptHandler(0x01) {
// eat all previous keystrikes
- while (commandport.read() & 0x1) dataport.read();
- commandport.write(0xae); // ???
- commandport.write(0x20); // get state ???
- auto status = (dataport.read() | 1) & ~0x10;
- commandport.write(0x60); // set state ???
- dataport.write(status); // ???
- dataport.write(0xf4); // ???
+ while (commstatport.read() & 0x1) {
+ [[maybe_unused]] auto _c = dataport.read();
+ }
+ commstatport.write(comm_enable_first_ps2);
+ commstatport.write(comm_read_ctrl_config);
+ const uint8_t conf = (dataport.read() | 1) & ~0x10;
+ commstatport.write(comm_write_ctrl_config);
+ dataport.write(conf);
+ dataport.write(dat_enable_scanning);
}
void Keyboard::trigger() {
diff --git a/drivers/keyboard.h b/drivers/keyboard.h
index a14c2c0..cac0cb0 100644
--- a/drivers/keyboard.h
+++ b/drivers/keyboard.h
@@ -3,6 +3,7 @@
#include "idt.h"
#include "ports.h"
+/* PS/2 Keyboard */
class Keyboard : public InterruptHandler {
public:
Keyboard();
@@ -10,6 +11,11 @@ public:
void trigger() override;
private:
- keyboard_comm_t commandport;
- keyboard_data_t dataport;
+ /* 8042 PS/2 Controller Ports */
+ typedef Port<0x60, uint8_t> data_port_t; // rw data port
+ typedef Port<0x64, uint8_t> comm_port_t; // r status register
+ // w command register
+
+ data_port_t dataport;
+ comm_port_t commstatport;
};
diff --git a/drivers/ports.h b/drivers/ports.h
index 2d26e65..393fd4d 100644
--- a/drivers/ports.h
+++ b/drivers/ports.h
@@ -58,6 +58,3 @@ typedef Port<0x2e8, uint8_t> com4_port_t;
typedef Port<0x20, uint8_t> pic1_t;
typedef Port<0xa0, uint8_t> pic2_t;
-/* PS/2 keyboard */
-typedef Port<0x60, uint8_t> keyboard_data_t;
-typedef Port<0x64, uint8_t> keyboard_comm_t;
diff --git a/src/makefile b/src/makefile
index dda24af..8db63d6 100644
--- a/src/makefile
+++ b/src/makefile
@@ -14,7 +14,8 @@ src/cpu/irq.h: $(OBJ_DIR)/src/cpu/exceptions.o $(OBJ_DIR)/src/cpu/interrupts.o
@echo " GEN $@"
@echo '#pragma once' > $@
@echo 'extern "C" {' >> $@
- @for x in $^; do nm $$x -g | sed -nr 's/[0-9a-f]{8} T (.+)/void \1();/p'; done >> $@
+ @echo '/* interrupt map */' >> $@
+ @for x in $^; do $(NM) $$x -g | $(SED) -nr 's/[0-9a-f]{8} T (.+)/void \1();/p'; done >> $@
@echo '}' >> $@
autogen := $(autogen) src/cpu/irq.h
diff --git a/toolchain.makefile b/toolchain.makefile
index 7a64904..0631904 100644
--- a/toolchain.makefile
+++ b/toolchain.makefile
@@ -1,6 +1,9 @@
# Toolchain
TARGET := i686-elf
+NM := llvm-nm
+SED := sed
+
AS := clang
AS_FLAGS :=