diff --git a/idt.c b/idt.c new file mode 100644 index 0000000..02f13fe --- /dev/null +++ b/idt.c @@ -0,0 +1,42 @@ +#include "idt.h" +#include "system.h" + +struct idt_entry +{ + unsigned short base_lo; + unsigned short sel; + unsigned char always0; + unsigned char flags; + unsigned short base_hi; +} __attribute__((packed)); + +struct idt_ptr +{ + unsigned short limit; + unsigned int base; +} __attribute__((packed)); + +struct idt_entry idt[256]; +struct idt_ptr idtp; + +extern void idt_load(); + +void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags) +{ + idt[num].base_lo = (base & 0xFFFF); + idt[num].base_hi = (base >> 16) & 0xFFFF; + + idt[num].sel = sel; + idt[num].always0 = 0; + idt[num].flags = flags; +} + +void idt_install() +{ + idtp.limit = (sizeof (struct idt_entry)*256) - 1; + idtp.base = (unsigned int)&idt; + + memset(&idt, 0, sizeof(struct idt_entry)*256); + + idt_load(); +} diff --git a/idt.h b/idt.h new file mode 100644 index 0000000..2d28f8f --- /dev/null +++ b/idt.h @@ -0,0 +1,8 @@ +#ifndef IDT_H +#define IDT_H + +void idt_set_gate(unsigned char num, unsigned long base, unsigned short sel, unsigned char flags); + +void idt_install(); + +#endif diff --git a/iso/boot/kernel.elf b/iso/boot/kernel.elf index 4fafbb5..37b9308 100755 Binary files a/iso/boot/kernel.elf and b/iso/boot/kernel.elf differ diff --git a/kernel.elf b/kernel.elf index 4fafbb5..37b9308 100755 Binary files a/kernel.elf and b/kernel.elf differ diff --git a/kmain.c b/kmain.c index b15b916..a9712ba 100644 --- a/kmain.c +++ b/kmain.c @@ -1,11 +1,13 @@ #include "stdio.h" #include "serial.h" #include "gdt.h" +#include "idt.h" int kmain(int retvalue) { gdt_install(); + idt_install(); // serial testing diff --git a/loader.s b/loader.s index bdf1dd1..25aa675 100644 --- a/loader.s +++ b/loader.s @@ -38,6 +38,13 @@ gdt_flush: flush2: ret +global idt_load +extern idtp + +idt_load: + lidt [idtp] + ret + section .bss align 4 kernel_stack: diff --git a/makefile b/makefile index 2f40e62..f663857 100644 --- a/makefile +++ b/makefile @@ -1,4 +1,4 @@ -OBJECTS = loader.o kmain.o stdio.o io.o string.o serial.o gdt.o +OBJECTS = loader.o kmain.o stdio.o io.o string.o serial.o gdt.o idt.o system.o CC = gcc CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra -c LDFLAGS = -T link.ld -melf_i386 diff --git a/os.iso b/os.iso index 33455f4..b19cf32 100644 Binary files a/os.iso and b/os.iso differ diff --git a/system.c b/system.c new file mode 100644 index 0000000..9ac43db --- /dev/null +++ b/system.c @@ -0,0 +1,8 @@ +#include "system.h" + +void *memset(void *dest, char val, size_t count) +{ + char *temp = (char *)dest; + for(; count != 0; count--) *temp++ = val; + return dest; +} diff --git a/system.h b/system.h new file mode 100644 index 0000000..5a9118e --- /dev/null +++ b/system.h @@ -0,0 +1,8 @@ +#ifndef SYSTEM_H +#define SYSTEM_H + +typedef int size_t; + +void *memset(void *dest, char val, size_t count); + +#endif