Here are the source files:
_____________________kernel.c________________________
Code: Select all
#include "kernel.h"
void _start(void)
{
term = New_TerminalB8000();
T_Clear(term);
idt_init();
int a = 5;
int b = 0;
T_Print(term, "%d", a/b);
for(;;);
}
Code: Select all
#pragma once
#include "common.h"
#include "int_handlers.h"
#include "terminal.h"
#include "kernel.h"
struct IDTEntry
{
uint16_t offset_0_15; // offset bits 0..15
uint16_t selector; // a code segment selector in GDT or LDT
uint8_t zero; // unused, set to 0
uint8_t flags; // type and attributes, see below
uint16_t offset_16_31; // offset bits 16..31
}__attribute__((packed));
struct IDTR
{
uint16_t limit;
uint32_t base;
}__attribute__((packed));
typedef struct IDTEntry IDTEntry;
typedef struct IDTR IDTR;
void idt_init();
Code: Select all
#include "idt.h"
#define SETIDTDESCR(d, offset) { \
d.offset_0_15 = ((uint32_t)offset & 0xffff); \
d.selector = 0x8; \
d.zero = 0; \
d.flags = 0x8E; \
d.offset_16_31 = (((uint32_t)offset >> 16) & 0xffff); \
}
IDTEntry IDT[256];
void idt_init()
{
for(int i=0; i<=32; i++)
SETIDTDESCR(IDT[i], interrupt_handler);
IDTR ptr = {
(uint16_t)((256 * 8 ) - 1),
(uint32_t)&IDT
};
__asm("lidt [0]" : : "m"(ptr));
}
Code: Select all
#pragma once
#include "common.h"
#include "kernel.h"
void interrupt_handler();
Code: Select all
#include "int_handlers.h"
void interrupt_handler()
{
T_Print(term, "Interrupt");
for(;;);
}