diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.asm | 9 | ||||
-rw-r--r-- | src/idt/idt.c | 36 | ||||
-rw-r--r-- | src/idt/idt.h | 6 | ||||
-rw-r--r-- | src/kernel.c | 4 | ||||
-rw-r--r-- | src/memory/memory.c | 16 | ||||
-rw-r--r-- | src/memory/memory.h | 6 |
6 files changed, 76 insertions, 1 deletions
diff --git a/src/boot.asm b/src/boot.asm index fda8b0c..b45d64b 100644 --- a/src/boot.asm +++ b/src/boot.asm @@ -34,6 +34,7 @@ stublet: call kernel_main jmp $ +; GDT flush function global gdt_flush extern gp gdt_flush: @@ -48,8 +49,14 @@ gdt_flush: flush2: ret ; Returns to C code -; TODO: ISR +; IDT loader +global idt_load +extern idtp +idt_load: + lidt [idtp] + ret +; Store the stack SECTION .bss resb 8192 ; Reserve 8KiB _sys_stack:
\ No newline at end of file diff --git a/src/idt/idt.c b/src/idt/idt.c new file mode 100644 index 0000000..3c0c246 --- /dev/null +++ b/src/idt/idt.c @@ -0,0 +1,36 @@ +#include "../memory/memory.h" + +/* Defines an IDT entry */ +struct idt_entry { + unsigned short base_lo; + unsigned short sel; // Kernel segment + unsigned char always0; // Always 0 + unsigned char flags; + unsigned short base_hi; +} __attribute__((packed)); + +struct idt_ptr { + unsigned short limit; + unsigned int base; +} __attribute__((packed)); + +// Initialize IDT with 256 entries +struct idt_entry idt[256]; +struct idt_ptr idtp; + +// Defined in boot.asm +extern void idt_load(); + +// Install IDT +void idt_install() { + // Set IDT pointer and limit + idtp.limit = (sizeof(struct idt_entry) * 256) - 1; + idtp.base = &idt; + + // Clear IDT by setting memory cells to 0 + memory_set(&idt, 0, sizeof(struct idt_entry) * 256); + + // TODO: Add method to add ISRs to IDT + + idt_load(); +} diff --git a/src/idt/idt.h b/src/idt/idt.h new file mode 100644 index 0000000..6a68e86 --- /dev/null +++ b/src/idt/idt.h @@ -0,0 +1,6 @@ +#ifndef MELVIX_IDT_H +#define MELVIX_IDT_H + +void idt_install(); + +#endif diff --git a/src/kernel.c b/src/kernel.c index e8ee10e..8e2f534 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -1,6 +1,10 @@ #include "graphics/vga.h" +#include "gdt/gdt.h" +#include "idt/idt.h" void kernel_main(void) { + gdt_install(); + idt_install(); terminal_initialize(); terminal_write_string("Melvix loaded successfully!\nTest"); }
\ No newline at end of file diff --git a/src/memory/memory.c b/src/memory/memory.c new file mode 100644 index 0000000..3524787 --- /dev/null +++ b/src/memory/memory.c @@ -0,0 +1,16 @@ +#include "../graphics/vga.h" + +unsigned char *memory_copy(unsigned char *dest, const unsigned char *src, int count) { + // TODO: Add memory copy function +} + +unsigned char *memory_set(unsigned char *dest, unsigned char val, int count) { + unsigned char *p = dest; + while (count > 0) { + if (!*p) break; + *p = val; + p++; + count--; + } + return dest; +} diff --git a/src/memory/memory.h b/src/memory/memory.h new file mode 100644 index 0000000..9e2374d --- /dev/null +++ b/src/memory/memory.h @@ -0,0 +1,6 @@ +#ifndef MELVIX_MEMORY_H +#define MELVIX_MEMORY_H + +unsigned char *memory_set(unsigned char *dest, unsigned char val, int count); + +#endif |