keyboard!!!! :D
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
kernel/lib/IO.o
Normal file
BIN
kernel/lib/IO.o
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
17
kernel/src/IO.cpp
Normal file
17
kernel/src/IO.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include "IO.h"
|
||||||
|
|
||||||
|
void outb(uint16_t port, uint8_t value){
|
||||||
|
asm volatile ("outb %0, %1" : : "a"(value), "Nd"(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t inb(uint16_t port){
|
||||||
|
uint8_t returnVal;
|
||||||
|
asm volatile ("inb %1, %0"
|
||||||
|
: "=a"(returnVal)
|
||||||
|
: "Nd"(port));
|
||||||
|
return returnVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
void io_wait(){
|
||||||
|
asm volatile ("outb %%al, $0x80" : : "a"(0));
|
||||||
|
}
|
||||||
6
kernel/src/IO.h
Normal file
6
kernel/src/IO.h
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void outb(uint16_t port, uint8_t value);
|
||||||
|
uint8_t inb(uint16_t port);
|
||||||
|
void io_wait();
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "interrupts.h"
|
#include "interrupts.h"
|
||||||
#include "../panic.h"
|
#include "../panic.h"
|
||||||
|
#include "../IO.h"
|
||||||
|
|
||||||
__attribute__((interrupt)) void PageFault_Handler(struct interrupt_frame* frame) {
|
__attribute__((interrupt)) void PageFault_Handler(struct interrupt_frame* frame) {
|
||||||
Panic("Page Fault");
|
Panic("Page Fault");
|
||||||
@@ -14,4 +15,59 @@ __attribute__((interrupt)) void DoubleFault_Handler(struct interrupt_frame* fram
|
|||||||
__attribute__((interrupt)) void GPFault_Handler(struct interrupt_frame* frame) {
|
__attribute__((interrupt)) void GPFault_Handler(struct interrupt_frame* frame) {
|
||||||
Panic("General Protection Fault");
|
Panic("General Protection Fault");
|
||||||
while (true);
|
while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__((interrupt)) void KeyboardInterrupt_Handler(struct interrupt_frame* frame) {
|
||||||
|
GlobalRenderer->Print("A");
|
||||||
|
|
||||||
|
uint8_t scancode = inb(0x60);
|
||||||
|
|
||||||
|
PIC_EndMaster();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PIC_EndMaster() {
|
||||||
|
outb(PIC1_COMMAND, PIC_EOI);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PIC_EndSlave() {
|
||||||
|
outb(PIC2_COMMAND, PIC_EOI);
|
||||||
|
outb(PIC1_COMMAND, PIC_EOI);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemapPIC() {
|
||||||
|
uint8_t a1, a2;
|
||||||
|
|
||||||
|
a1 = inb(PIC1_DATA);
|
||||||
|
io_wait();
|
||||||
|
a2 = inb(PIC2_DATA);
|
||||||
|
io_wait();
|
||||||
|
|
||||||
|
// init master
|
||||||
|
outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4);
|
||||||
|
io_wait();
|
||||||
|
// init slave
|
||||||
|
outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
|
||||||
|
io_wait();
|
||||||
|
|
||||||
|
outb(PIC1_DATA, 0x20);
|
||||||
|
io_wait();
|
||||||
|
outb(PIC2_DATA, 0x28);
|
||||||
|
io_wait();
|
||||||
|
|
||||||
|
// tell the pic chips how they correspond to eachother so they can chat
|
||||||
|
outb(PIC1_DATA, 4);
|
||||||
|
io_wait();
|
||||||
|
outb(PIC2_DATA, 2);
|
||||||
|
io_wait();
|
||||||
|
|
||||||
|
outb(PIC1_DATA, ICW4_8086);
|
||||||
|
io_wait();
|
||||||
|
outb(PIC2_DATA, ICW4_8086);
|
||||||
|
io_wait();
|
||||||
|
|
||||||
|
// restore bitmasks we saved earlier
|
||||||
|
outb(PIC1_DATA, a1);
|
||||||
|
io_wait();
|
||||||
|
outb(PIC2_DATA, a2);
|
||||||
|
io_wait();
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../BasicRenderer.h"
|
#include "../BasicRenderer.h"
|
||||||
|
|
||||||
struct interrupt_frame;
|
#define PIC1_COMMAND 0x20
|
||||||
|
#define PIC1_DATA 0x21
|
||||||
|
#define PIC2_COMMAND 0xA0
|
||||||
|
#define PIC2_DATA 0xA1
|
||||||
|
#define PIC_EOI 0x20
|
||||||
|
|
||||||
|
#define ICW1_INIT 0x10
|
||||||
|
#define ICW1_ICW4 0x01
|
||||||
|
#define ICW4_8086 0x01
|
||||||
|
|
||||||
|
struct interrupt_frame;
|
||||||
__attribute__((interrupt)) void PageFault_Handler(struct interrupt_frame* frame);
|
__attribute__((interrupt)) void PageFault_Handler(struct interrupt_frame* frame);
|
||||||
__attribute__((interrupt)) void DoubleFault_Handler(struct interrupt_frame* frame);
|
__attribute__((interrupt)) void DoubleFault_Handler(struct interrupt_frame* frame);
|
||||||
__attribute__((interrupt)) void GPFault_Handler(struct interrupt_frame* frame);
|
__attribute__((interrupt)) void GPFault_Handler(struct interrupt_frame* frame);
|
||||||
|
|
||||||
|
__attribute__((interrupt)) void KeyboardInterrupt_Handler(struct interrupt_frame* frame);
|
||||||
|
|
||||||
|
void RemapPIC();
|
||||||
|
void PIC_EndMaster();
|
||||||
|
void PIC_EndSlave();
|
||||||
@@ -8,8 +8,6 @@ extern "C" void _start(BootInfo* bootInfo) {
|
|||||||
GlobalRenderer->Print("Kernel initialized successfully!");
|
GlobalRenderer->Print("Kernel initialized successfully!");
|
||||||
GlobalRenderer->Next();
|
GlobalRenderer->Next();
|
||||||
|
|
||||||
asm("int $0x0e");
|
|
||||||
|
|
||||||
// make sure we never return from our OS
|
// make sure we never return from our OS
|
||||||
while (true);
|
while (true);
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ extern "C" void __stack_chk_fail(void) {
|
|||||||
#include "gdt/gdt.h"
|
#include "gdt/gdt.h"
|
||||||
#include "interrupts/IDT.h"
|
#include "interrupts/IDT.h"
|
||||||
#include "interrupts/interrupts.h"
|
#include "interrupts/interrupts.h"
|
||||||
|
#include "IO.h"
|
||||||
|
|
||||||
KernelInfo kernelInfo;
|
KernelInfo kernelInfo;
|
||||||
PageTableManager pageTableManager = NULL;
|
PageTableManager pageTableManager = NULL;
|
||||||
@@ -64,8 +65,20 @@ void PrepareInterrupts() {
|
|||||||
int_GPFault->type_attr = IDT_TA_InterruptGate;
|
int_GPFault->type_attr = IDT_TA_InterruptGate;
|
||||||
int_GPFault->selector = 0x08; // kernel code segment
|
int_GPFault->selector = 0x08; // kernel code segment
|
||||||
|
|
||||||
|
IDTDescEntry* int_Keyboard = (IDTDescEntry*)(idtr.Offset + 0x21 * sizeof(IDTDescEntry));
|
||||||
|
int_Keyboard->SetOffset((uint64_t)KeyboardInterrupt_Handler);
|
||||||
|
int_Keyboard->type_attr = IDT_TA_InterruptGate;
|
||||||
|
int_Keyboard->selector = 0x08; // kernel code segment
|
||||||
|
|
||||||
// load idt
|
// load idt
|
||||||
asm("lidt %0" : : "m" (idtr));
|
asm("lidt %0" : : "m" (idtr));
|
||||||
|
|
||||||
|
// remap pic so we can get hardware interrupts
|
||||||
|
RemapPIC();
|
||||||
|
outb(PIC1_DATA, 0b11111101); // unmask 2nd interrupt
|
||||||
|
outb(PIC2_DATA, 0b11111111);
|
||||||
|
|
||||||
|
asm ("sti");
|
||||||
}
|
}
|
||||||
|
|
||||||
BasicRenderer r = BasicRenderer(NULL, NULL);
|
BasicRenderer r = BasicRenderer(NULL, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user