GP Fault handler
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "io/serial/serial.h"
|
||||
#include "io/kbd/ps2.h"
|
||||
#include <kernel.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct interrupt_descriptor idt[256];
|
||||
struct idtr idt_reg;
|
||||
@@ -85,6 +86,32 @@ static void page_fault_handler(struct cpu_status_t* ctx)
|
||||
panic(ctx);
|
||||
}
|
||||
|
||||
static void gp_fault_handler(struct cpu_status_t* ctx)
|
||||
{
|
||||
DEBUG("\x1b[38;5;231mGeneral Protection Fault at rip=0x%p, err=%u (%s)\x1b[0m",
|
||||
ctx->iret_rip,
|
||||
ctx->error_code,
|
||||
(ctx->error_code == 0) ? "NOT_SEGMENT_RELATED" : "SEGMENT_RELATED");
|
||||
|
||||
// Segment-related
|
||||
if (ctx->error_code != 0)
|
||||
{
|
||||
bool is_external = CHECK_BIT(ctx->error_code, 0);
|
||||
// is it IDT, GDT, LDT?
|
||||
uint8_t table = ctx->error_code & 0x6; // 0b110 (isolate table)
|
||||
uint16_t index = ctx->error_code & 0xFFF8; // 13*1 1111111111111 + 000 = 1111111111111000
|
||||
|
||||
char* table_names[4] = {"GDT", "IDT", "LDT", "IDT"};
|
||||
|
||||
DEBUG("\x1b[38;5;231m%s in %s index %u\x1b[0m",
|
||||
is_external ? "EXTERNAL" : "INTERNAL",
|
||||
table_names[table],
|
||||
index);
|
||||
}
|
||||
|
||||
panic(ctx);
|
||||
}
|
||||
|
||||
struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context)
|
||||
{
|
||||
switch(context->vector_number)
|
||||
@@ -129,7 +156,7 @@ struct cpu_status_t* interrupt_dispatch(struct cpu_status_t* context)
|
||||
DEBUG("Stack-Segment Fault!");
|
||||
break;
|
||||
case 13:
|
||||
DEBUG("General Protection Fault!");
|
||||
gp_fault_handler(context);
|
||||
break;
|
||||
case 14:
|
||||
// Better debugging for page faults...
|
||||
|
||||
@@ -46,7 +46,7 @@ int term_init()
|
||||
{
|
||||
fb = boot_ctx.fb->address;
|
||||
framebuffer = boot_ctx.fb;
|
||||
DEBUG("terminal initialized");
|
||||
DEBUG("terminal initialized, fb=0x%p (width=%u height=%u pitch=%u bpp=%u)", fb, framebuffer->width, framebuffer->height, framebuffer->pitch, framebuffer->bpp);
|
||||
return 0;
|
||||
}
|
||||
return -ENOMEM;
|
||||
@@ -102,7 +102,12 @@ void term_scroll()
|
||||
const size_t screen_rows = framebuffer->height;
|
||||
|
||||
// Move framebuffer up by one text row
|
||||
memmove(fb, fb + row_height * row_bytes, (screen_rows - row_height) * row_bytes);
|
||||
//memmove(fb, fb + row_height * row_bytes, (screen_rows - row_height) * row_bytes);
|
||||
|
||||
for (size_t i = 0; i < (screen_rows - row_height) * row_bytes; i++)
|
||||
{
|
||||
fb[i] = fb[i + row_height * row_bytes];
|
||||
}
|
||||
|
||||
// Clear last text row
|
||||
size_t clear_start = (screen_rows - row_height) * row_bytes;
|
||||
|
||||
Reference in New Issue
Block a user