Kernel: Add keyboard
This commit is contained in:
parent
f214f7d15e
commit
01725789fd
|
@ -5,8 +5,9 @@
|
|||
#include "serial.h"
|
||||
#include "gdt.c"
|
||||
#include "interrupts.c"
|
||||
#include "timer.c"
|
||||
#include "paging.h"
|
||||
//#include "timer.c"
|
||||
#include "keyboard.c"
|
||||
//#include "paging.h"
|
||||
|
||||
void kernel_early_main(void) {
|
||||
gdt_init();
|
||||
|
@ -14,9 +15,10 @@ void kernel_early_main(void) {
|
|||
serial_printf("gdt initialized!\n");
|
||||
idt_init();
|
||||
serial_printf("idt initialized!\n");
|
||||
init_timer(50); // Initialise timer to 50Hz
|
||||
//init_timer(50); // Initialise timer to 50Hz
|
||||
serial_printf("timer initialized!\n");
|
||||
init_paging();
|
||||
serial_printf("paging initialized!\n");
|
||||
//init_paging();
|
||||
//serial_printf("paging initialized!\n");
|
||||
terminal_initialize();
|
||||
init_keyboard();
|
||||
}
|
||||
|
|
|
@ -64,18 +64,6 @@ void idt_init() {
|
|||
|
||||
memset(idt_entries, 0, sizeof(idt_entry_t)*256);
|
||||
|
||||
// Remap the irq table.
|
||||
outb(0x20, 0x11);
|
||||
outb(0xA0, 0x11);
|
||||
outb(0x21, 0x20);
|
||||
outb(0xA1, 0x28);
|
||||
outb(0x21, 0x04);
|
||||
outb(0xA1, 0x02);
|
||||
outb(0x21, 0x01);
|
||||
outb(0xA1, 0x01);
|
||||
outb(0x21, 0x0);
|
||||
outb(0xA1, 0x0);
|
||||
|
||||
extern isr_t isr0;
|
||||
extern isr_t isr1;
|
||||
extern isr_t isr2;
|
||||
|
@ -159,6 +147,21 @@ void idt_init() {
|
|||
idt_set_gate(30, (uint32_t)&isr30, 0x08, 0x8E);
|
||||
idt_set_gate(31, (uint32_t)&isr31, 0x08, 0x8E);
|
||||
|
||||
extern void idt_flush(uint32_t);
|
||||
idt_flush((uint32_t)&idt_ptr);
|
||||
|
||||
// Remap the irq table.
|
||||
outb(0x20, 0x11);
|
||||
outb(0xA0, 0x11);
|
||||
outb(0x21, 0x20);
|
||||
outb(0xA1, 0x28);
|
||||
outb(0x21, 0x04);
|
||||
outb(0xA1, 0x02);
|
||||
outb(0x21, 0x01);
|
||||
outb(0xA1, 0x01);
|
||||
outb(0x21, 0x0);
|
||||
outb(0xA1, 0x0);
|
||||
|
||||
idt_set_gate(32, (uint32_t)&irq0, 0x08, 0x8E);
|
||||
idt_set_gate(33, (uint32_t)&irq1, 0x08, 0x8E);
|
||||
idt_set_gate(34, (uint32_t)&irq2, 0x08, 0x8E);
|
||||
|
@ -176,8 +179,6 @@ void idt_init() {
|
|||
idt_set_gate(46, (uint32_t)&irq14, 0x08, 0x8E);
|
||||
idt_set_gate(47, (uint32_t)&irq15, 0x08, 0x8E);
|
||||
|
||||
extern void idt_flush(uint32_t);
|
||||
idt_flush((uint32_t)&idt_ptr);
|
||||
}
|
||||
|
||||
void isr_handler(registers_t regs)
|
||||
|
|
|
@ -9,6 +9,9 @@ void kernel_main(void) {
|
|||
char * test_string = "test";
|
||||
serial_printf("This is string from variable: %s\n", test_string);
|
||||
|
||||
asm volatile ("int $0x3");
|
||||
printf("Test finished success!\n");
|
||||
asm volatile("sti");
|
||||
for(;;) {
|
||||
asm("hlt");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
unsigned char kbdus[128] =
|
||||
{
|
||||
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
|
||||
'9', '0', '-', '=', '\b', /* Backspace */
|
||||
'\t', /* Tab */
|
||||
'q', 'w', 'e', 'r', /* 19 */
|
||||
't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', /* Enter key */
|
||||
0, /* 29 - Control */
|
||||
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* 39 */
|
||||
'\'', '`', 0, /* Left shift */
|
||||
'\\', 'z', 'x', 'c', 'v', 'b', 'n', /* 49 */
|
||||
'm', ',', '.', '/', 0, /* Right shift */
|
||||
'*',
|
||||
0, /* Alt */
|
||||
' ', /* Space bar */
|
||||
0, /* Caps lock */
|
||||
0, /* 59 - F1 key ... > */
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, /* < ... F10 */
|
||||
0, /* 69 - Num lock*/
|
||||
0, /* Scroll Lock */
|
||||
0, /* Home key */
|
||||
0, /* Up Arrow */
|
||||
0, /* Page Up */
|
||||
'-',
|
||||
0, /* Left Arrow */
|
||||
0,
|
||||
0, /* Right Arrow */
|
||||
'+',
|
||||
0, /* 79 - End key*/
|
||||
0, /* Down Arrow */
|
||||
0, /* Page Down */
|
||||
0, /* Insert Key */
|
||||
0, /* Delete Key */
|
||||
0, 0, 0,
|
||||
0, /* F11 Key */
|
||||
0, /* F12 Key */
|
||||
0, /* All other keys are undefined */
|
||||
};
|
||||
|
||||
/* Handles the keyboard interrupt */
|
||||
static void keyboard_handler(struct regs *r)
|
||||
{
|
||||
unsigned char scancode = inb(0x60);
|
||||
|
||||
if (scancode & 0x80)
|
||||
{
|
||||
// Shift, alt, ctrl keys
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("%c", kbdus[scancode]);
|
||||
}
|
||||
}
|
||||
void init_keyboard()
|
||||
{
|
||||
register_interrupt_handler(IRQ1, &keyboard_handler);
|
||||
}
|
Loading…
Reference in New Issue