basic keyboard support

main
Clyne 3 months ago
parent 376d7ec265
commit ba5683581d
Signed by: clyne
GPG Key ID: 1B74EE6C49C96795

@ -2,9 +2,10 @@ CXXFLAGS := -m32 -ggdb -g3 -O0 -fno-pic -ffreestanding -fno-rtti -fno-exceptions
LDFLAGS := -m32 -static -T link.ld -ffreestanding -nostdlib LDFLAGS := -m32 -static -T link.ld -ffreestanding -nostdlib
CXXFILES := acpi.cpp \ CXXFILES := acpi.cpp \
boot.cpp \ boot.cpp \
gdt.cpp \ gdt.cpp \
idt.cpp \ idt.cpp \
keyboard.cpp \
memory.cpp \ memory.cpp \
multiboot.cpp \ multiboot.cpp \
pic.cpp \ pic.cpp \

@ -40,8 +40,11 @@ void interruptGeneralHandler(Registers regs)
} }
if (inum < callbacks.size()) { if (inum < callbacks.size()) {
if (auto cb = callbacks[inum]; cb) if (auto cb = callbacks[inum]; cb) {
cb(regs); asm volatile("cli");
cb(regs);
asm volatile("sti");
}
} }
} }

@ -1,10 +1,12 @@
#include "acpi.hpp" #include "acpi.hpp"
#include "gdt.hpp" #include "gdt.hpp"
#include "idt.hpp" #include "idt.hpp"
#include "keyboard.hpp"
#include "memory.hpp" #include "memory.hpp"
#include "multiboot.hpp" #include "multiboot.hpp"
#include "pic.hpp" #include "pic.hpp"
#include "pit.hpp" #include "pit.hpp"
#include "portio.hpp"
#include "tasking.hpp" #include "tasking.hpp"
#include "vgaterminal.hpp" #include "vgaterminal.hpp"
@ -33,39 +35,40 @@ void kernel_main(void)
pic_initialize(); pic_initialize();
idt_initialize(); idt_initialize();
pit_initialize(); pit_initialize();
keyboard_initialize();
asm volatile("sti"); asm volatile("sti");
tasking_initialize(); tasking_initialize();
term.write("Tasking enabled.\n"); term.write("Tasking enabled.\n");
tasking_spawn([] { //tasking_spawn([] {
for (;;) { // for (;;) {
do pit_delay_ms(1); // do pit_delay_ms(1);
while (termBusy); // while (termBusy);
termBusy = true; // termBusy = true;
term.write('B'); // term.write('B');
termBusy = false; // termBusy = false;
} // }
}, 256); //}, 256);
tasking_spawn([] { //tasking_spawn([] {
for (;;) { // for (;;) {
do pit_delay_ms(1); // do pit_delay_ms(1);
while (termBusy); // while (termBusy);
termBusy = true; // termBusy = true;
term.write('C'); // term.write('C');
termBusy = false; // termBusy = false;
} // }
}, 256); //}, 256);
for (;;) { for (;;) {
do pit_delay_ms(1); pit_delay_ms(100);
while (termBusy); //while (termBusy);
termBusy = true; //termBusy = true;
term.write('A'); //term.write('A');
termBusy = false; //termBusy = false;
} }
} }

@ -0,0 +1,65 @@
#include "idt.hpp"
#include "portio.hpp"
#include "vgaterminal.hpp"
#include <array>
#include <cstdint>
#define K_CONTROL_L -1
#define K_SHIFT_L -2
#define K_ALT_L -3
#define K_CAPS -4
#define K_NUM -5
#define K_SCROLL -6
#define K_SHIFT_R -7
#define K_ESCAPE -8
#define K_F1 -10
#define K_F2 -11
#define K_F3 -12
#define K_F4 -13
#define K_F5 -14
#define K_F6 -15
#define K_F7 -16
#define K_F8 -17
#define K_F9 -18
#define K_F10 -19
#define K_F11 -20
#define K_F12 -21
extern TextOutput& term;
static const std::array<char, 0x59> ScanCodeSet1 {{
0, K_ESCAPE,
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
'-', '=', '\b', '\t',
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '[', ']', '\n', K_CONTROL_L,
'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ';', '\'', '`', K_SHIFT_L, '\\',
'Z', 'X', 'C', 'V', 'B', 'N', 'M', ',', '.', '/',
K_SHIFT_R, '*', K_ALT_L, ' ', K_CAPS,
K_F1, K_F2, K_F3, K_F4, K_F5, K_F6, K_F7, K_F8, K_F9, K_F10,
K_NUM, K_SCROLL, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.',
0, 0, 0, // non-existant
K_F11, K_F12
}};
static constexpr bool isReleased(auto ch) {
return ch & 0x80;
}
static constexpr auto keycode(auto ch) {
return ch & 0x7F;
}
void keyboard_initialize()
{
idt_register_callback(33, [](auto& regs) {
const auto kc = inb(0x60);
if (!isReleased(kc)) {
const auto ch = ScanCodeSet1[keycode(kc)];
if (ch > 0)
term.write(ch);
}
});
}

@ -0,0 +1,7 @@
#ifndef KEYBOARD_HPP
#define KEYBOARD_HPP
void keyboard_initialize();
#endif // KEYBOARD_HPP

@ -8,7 +8,16 @@
void VGATerminal::write(char c) noexcept void VGATerminal::write(char c) noexcept
{ {
checkpos();
switch (c) { switch (c) {
case '\b':
if (offset % Width) {
--offset;
put(' ');
--offset;
}
break;
case '\n': case '\n':
offset += Width; offset += Width;
[[fallthrough]]; [[fallthrough]];
@ -16,11 +25,11 @@ void VGATerminal::write(char c) noexcept
offset -= offset % Width; offset -= offset % Width;
break; break;
default: default:
checkpos();
put(c); put(c);
updatecursor();
break; break;
} }
updatecursor();
} }
void VGATerminal::put(char c) noexcept void VGATerminal::put(char c) noexcept

Loading…
Cancel
Save