interrupts!!!! :D
This commit is contained in:
Binary file not shown.
@@ -26,6 +26,11 @@ DIRS = $(wildcard $(SRCDIR)/*)
|
||||
|
||||
kernel: $(OBJS) link
|
||||
|
||||
$(OBJDIR)/interrupts/interrupts.o: $(SRCDIR)/interrupts/interrupts.cpp
|
||||
@ echo !==== COMPILING $^
|
||||
@ mkdir -p $(@D)
|
||||
$(CC) -mno-red-zone -mgeneral-regs-only -ffreestanding -c $^ -o $@
|
||||
|
||||
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
|
||||
@ echo !==== COMPILING $^
|
||||
@ mkdir -p $(@D)
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
kernel/lib/interrupts/IDT.o
Normal file
BIN
kernel/lib/interrupts/IDT.o
Normal file
Binary file not shown.
BIN
kernel/lib/interrupts/interrupts.o
Normal file
BIN
kernel/lib/interrupts/interrupts.o
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,7 @@
|
||||
#include "BasicRenderer.h"
|
||||
|
||||
BasicRenderer* GlobalRenderer;
|
||||
|
||||
BasicRenderer::BasicRenderer(Framebuffer* framebuffer, PSF1_FONT* psf1_Font) {
|
||||
targetFramebuffer = framebuffer;
|
||||
PSF1_Font = psf1_Font;
|
||||
|
||||
@@ -12,4 +12,6 @@ class BasicRenderer {
|
||||
unsigned int Colour;
|
||||
void Print(const char* str);
|
||||
void PutChar(char chr, unsigned int xOff, unsigned int yOff);
|
||||
};
|
||||
};
|
||||
|
||||
extern BasicRenderer* GlobalRenderer;
|
||||
15
kernel/src/interrupts/IDT.cpp
Normal file
15
kernel/src/interrupts/IDT.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "IDT.h"
|
||||
|
||||
void IDTDescEntry::SetOffset(uint64_t offset) {
|
||||
offset0 = (uint16_t)(offset & 0x000000000000ffff); // lower 16 bits -> offset0
|
||||
offset1 = (uint16_t)((offset & 0x00000000ffff0000) >> 16); // upper 16 bits -> offset1
|
||||
offset2 = (uint32_t)((offset & 0xffffffff00000000) >> 32); // upper 32 bits -> offset2
|
||||
}
|
||||
|
||||
uint64_t IDTDescEntry::GetOffset() {
|
||||
uint64_t offset = 0;
|
||||
offset |= (uint64_t)offset0;
|
||||
offset |= (uint64_t)offset1 << 16;
|
||||
offset |= (uint64_t)offset2 << 32;
|
||||
return offset;
|
||||
}
|
||||
24
kernel/src/interrupts/IDT.h
Normal file
24
kernel/src/interrupts/IDT.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
#define IDT_TA_InterruptGate 0b10001110
|
||||
#define IDT_TA_CallGate 0b10001100
|
||||
#define IDT_TA_TrapGate 0b10001111
|
||||
|
||||
struct IDTDescEntry {
|
||||
uint16_t offset0; // lower 16 bits of offset
|
||||
uint16_t selector; // segment selector
|
||||
uint8_t ist; // interrupt stack table offset
|
||||
uint8_t type_attr; // interrupt gate, trap gate, etc...
|
||||
uint16_t offset1; // upper 16 bits of offset
|
||||
uint32_t offset2; // upper 32 bits of offset
|
||||
uint32_t ignore; // unused
|
||||
|
||||
void SetOffset(uint64_t offset);
|
||||
uint64_t GetOffset();
|
||||
};
|
||||
|
||||
struct IDTR {
|
||||
uint16_t Limit;
|
||||
uint64_t Offset;
|
||||
}__attribute__((packed));
|
||||
6
kernel/src/interrupts/interrupts.cpp
Normal file
6
kernel/src/interrupts/interrupts.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include "interrupts.h"
|
||||
|
||||
__attribute__((interrupt)) void PageFault_Handler(struct interrupt_frame* frame) {
|
||||
GlobalRenderer->Print("Page fault caught!");
|
||||
while (true);
|
||||
}
|
||||
6
kernel/src/interrupts/interrupts.h
Normal file
6
kernel/src/interrupts/interrupts.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
#include "../BasicRenderer.h"
|
||||
|
||||
struct interrupt_frame;
|
||||
|
||||
__attribute__((interrupt)) void PageFault_Handler(struct interrupt_frame* frame);
|
||||
@@ -2,12 +2,11 @@
|
||||
|
||||
extern "C" void _start(BootInfo* bootInfo) {
|
||||
KernelInfo kernelInfo = InitializeKernel(bootInfo);
|
||||
BasicRenderer newRenderer = BasicRenderer(bootInfo->framebuffer, bootInfo->psf1_Font);
|
||||
PageTableManager* pageTableManager = kernelInfo.pageTableManager;
|
||||
|
||||
newRenderer.Print("Kernel initialized successfully! (we didn't crash lol)");
|
||||
newRenderer.cursorPosition = {0, newRenderer.cursorPosition.y + 18};
|
||||
|
||||
GlobalRenderer->Print("Kernel initialized successfully!");
|
||||
GlobalRenderer->cursorPosition = {0, GlobalRenderer->cursorPosition.y + 18};
|
||||
|
||||
// make sure we never return from our OS
|
||||
while (true);
|
||||
}
|
||||
@@ -6,6 +6,8 @@ extern "C" void __stack_chk_fail(void) {
|
||||
|
||||
#include "kernelUtil.h"
|
||||
#include "gdt/gdt.h"
|
||||
#include "interrupts/IDT.h"
|
||||
#include "interrupts/interrupts.h"
|
||||
|
||||
KernelInfo kernelInfo;
|
||||
PageTableManager pageTableManager = NULL;
|
||||
@@ -41,8 +43,25 @@ void PrepareMemory(BootInfo* bootInfo){
|
||||
kernelInfo.pageTableManager = &pageTableManager;
|
||||
}
|
||||
|
||||
IDTR idtr;
|
||||
void PrepareInterrupts() {
|
||||
idtr.Limit = 0x0FFF;
|
||||
idtr.Offset = (uint64_t)GlobalAllocator.RequestPage();
|
||||
memset((void*)idtr.Offset, 0, 0x1000);
|
||||
|
||||
IDTDescEntry* int_PageFault = (IDTDescEntry*)(idtr.Offset + 0xE * sizeof(IDTDescEntry));
|
||||
int_PageFault->SetOffset((uint64_t)PageFault_Handler);
|
||||
int_PageFault->type_attr = IDT_TA_InterruptGate;
|
||||
int_PageFault->selector = 0x08; // kernel code segment
|
||||
|
||||
// load idt
|
||||
asm("lidt %0" : : "m" (idtr));
|
||||
}
|
||||
|
||||
BasicRenderer r = BasicRenderer(NULL, NULL);
|
||||
KernelInfo InitializeKernel(BootInfo* bootInfo){
|
||||
r = BasicRenderer(bootInfo->framebuffer, bootInfo->psf1_Font);
|
||||
GlobalRenderer = &r;
|
||||
|
||||
GDTDescriptor gdtDescriptor;
|
||||
gdtDescriptor.Size = sizeof(GDT) - 1;
|
||||
@@ -53,5 +72,7 @@ KernelInfo InitializeKernel(BootInfo* bootInfo){
|
||||
|
||||
memset(bootInfo->framebuffer->BaseAddress, 0, bootInfo->framebuffer->BufferSize);
|
||||
|
||||
PrepareInterrupts();
|
||||
|
||||
return kernelInfo;
|
||||
}
|
||||
Reference in New Issue
Block a user