diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/boot.S | 9 | ||||
-rw-r--r-- | src/gdt.cc | 2 | ||||
-rw-r--r-- | src/idt.cc | 8 | ||||
-rw-r--r-- | src/idt/exception.cc | 8 | ||||
-rw-r--r-- | src/idt/stubs.S | 2 | ||||
-rw-r--r-- | src/kernel.cc | 18 | ||||
-rw-r--r-- | src/makefile | 6 | ||||
-rw-r--r-- | src/vmm.cc | 49 | ||||
-rw-r--r-- | src/vmm.h | 3 |
9 files changed, 73 insertions, 32 deletions
@@ -55,12 +55,9 @@ _start: # Physical address of boot_page_table1. movl $(boot_page_table1 - 0xC0000000), %edi # First address to map is address 0. - # TODO: Start at the first kernel page instead. Alternatively map the first - # 1 MiB as it can be generally useful, and there's no need to - # specially map the VGA buffer. - movl $0, %esi - # Map 1023 pages. The 1024th will be the VGA text buffer. - movl $1023, %ecx + movl $0, %esi + # Map 1023 pages. The 1024th will be the VGA text buffer. + movl $1023, %ecx 1: # Only map the kernel. @@ -13,7 +13,7 @@ constexpr uint32_t null_sz = 0; constexpr uint32_t kseg_start = 0; constexpr uint32_t kseg_sz = 0xffffffff; -static GDT::SegmentDescriptor segments[256]{ +__attribute__((section(".constinit"))) static GDT::SegmentDescriptor segments[256]{ [GDT::null0] = seg::make<null_sz>(0, {}), [GDT::kcode] = seg::make<kseg_sz>(kseg_start, {.r_w = true, .exe = true, .segment = true, .present = true}), [GDT::kdata] = seg::make<kseg_sz>(kseg_start, {.r_w = true, .segment = true, .present = true}), @@ -39,14 +39,6 @@ bool IDT::uninstall(uint8_t irq, InterruptHandler* h) { #define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */ #define ICW4_SFNM 0x10 /* Special fully nested (not) */ -extern "C" uint32_t handle_exception(cpu_state_t* r) { - printk("exception ", uhex{r->irq}, " error ", uhex{r->error}, '\n'); - asm volatile("cli"); - while (true) asm volatile("hlt"); - __builtin_unreachable(); - - return reinterpret_cast<uint32_t>(r); -}; extern "C" uint32_t handle_interrupt(cpu_state_t* r) { if (r->irq < irq_base) return reinterpret_cast<uint32_t>(r); diff --git a/src/idt/exception.cc b/src/idt/exception.cc new file mode 100644 index 0000000..efffd95 --- /dev/null +++ b/src/idt/exception.cc @@ -0,0 +1,8 @@ +#include <stdlib.h> +#include "cpu/registers.h" + +extern "C" void handle_exception(const cpu_state_t* r) { + printk("exception ", uhex{r->irq}, " error ", uhex{r->error}, "eip: ", uhex{r->eip}, '\n'); + + abort(); +}; diff --git a/src/idt/stubs.S b/src/idt/stubs.S index d4fb56f..568b0dc 100644 --- a/src/idt/stubs.S +++ b/src/idt/stubs.S @@ -73,7 +73,7 @@ exception_common: push %esp call handle_exception - mov %eax, %esp + add $4, %esp popa /* remove error code and irq from stack */ diff --git a/src/kernel.cc b/src/kernel.cc index 33282db..98c3a1a 100644 --- a/src/kernel.cc +++ b/src/kernel.cc @@ -13,23 +13,14 @@ #include "cga.h" #include "gdt.h" #include "idt.h" +#include "keyboard.h" #include "scheduler.h" #include "serial.h" - -#include "keyboard.h" +#include "vmm.h" #include "hardware.h" -typedef void (*constructor)(); - extern "C" { - -constructor begin_ctors; -constructor end_ctors; -void kernel_constructors() { - for (constructor* i = &begin_ctors; i != &end_ctors; ++i) (*i)(); -} - void dump_multiboot(uint32_t mb_magic, uint32_t mb_addr); void dump_gdt(); @@ -45,12 +36,13 @@ void kernel_main([[maybe_unused]] uint32_t mb_magic, [[maybe_unused]] uint32_t m printk("Hello, kernel World!\n"); - dump_multiboot(mb_magic, mb_addr + 0xc0000000); + dump_address(); + // dump_multiboot(mb_magic, mb_addr + 0xc0000000); // dump_gdt(); GDT gdt; IDT idt{gdt.descriptor(GDT::kcode)}; - Scheduler s{gdt.descriptor(GDT::kcode)}; + // Scheduler s{gdt.descriptor(GDT::kcode)}; Keyboard kb; idt.enable(); diff --git a/src/makefile b/src/makefile index ceaf5ef..47e8762 100644 --- a/src/makefile +++ b/src/makefile @@ -2,13 +2,13 @@ AS_OBJ += src/boot.o \ src/idt/stubs.o CXX_OBJ += src/kernel.o \ - src/kernel/dump_gdt.o \ - src/kernel/dump_multiboot.o \ + src/kernel/dump_gdt.o src/kernel/dump_multiboot.o \ src/memory.o \ src/gdt.o \ src/gdt/segmentdescriptor.o \ src/idt.o \ - src/idt/interruptgate.o src/idt/interrupthandler.o \ + src/idt/exception.o src/idt/interruptgate.o src/idt/interrupthandler.o \ + src/vmm.o \ src/scheduler.o src/cpu/irq.h: $(OBJ_DIR)/src/idt/stubs.o diff --git a/src/vmm.cc b/src/vmm.cc new file mode 100644 index 0000000..346e6ab --- /dev/null +++ b/src/vmm.cc @@ -0,0 +1,49 @@ +#include <stdlib.h> + +typedef void (*constructor)(); + +extern "C" { +/* .text */ +uint32_t begin_text; +uint32_t end_text; + +/* .rodata */ +uint32_t begin_rodata; +uint32_t end_rodata; + +/* .data */ +uint32_t begin_constinit; +uint32_t end_constinit; +constructor begin_ctors; +constructor end_ctors; +uint32_t begin_data; +uint32_t end_data; + +/* .bss */ +uint32_t begin_bss; +uint32_t end_bss; + +void kernel_constructors() { + for (constructor* i = &begin_ctors; i != &end_ctors; ++i) (*i)(); +} + +void dump_address() { + printk("text begin: ", uhex{reinterpret_cast<uint32_t>(&begin_text)}, + " end: ", uhex{reinterpret_cast<uint32_t>(&end_text)}, '\n'); + + printk("rodata begin: ", uhex{reinterpret_cast<uint32_t>(&begin_rodata)}, + " end: ", uhex{reinterpret_cast<uint32_t>(&end_rodata)}, '\n'); + + printk("constinit begin: ", uhex{reinterpret_cast<uint32_t>(&begin_constinit)}, + " end: ", uhex{reinterpret_cast<uint32_t>(&end_constinit)}, '\n'); + + printk("ctors begin: ", uhex{reinterpret_cast<uint32_t>(&begin_ctors)}, + " end: ", uhex{reinterpret_cast<uint32_t>(&end_ctors)}, '\n'); + + printk("data begin: ", uhex{reinterpret_cast<uint32_t>(&begin_data)}, + " end: ", uhex{reinterpret_cast<uint32_t>(&end_data)}, '\n'); + + printk("bss begin: ", uhex{reinterpret_cast<uint32_t>(&begin_bss)}, + " end: ", uhex{reinterpret_cast<uint32_t>(&end_bss)}, '\n'); +} +} // extern "C" diff --git a/src/vmm.h b/src/vmm.h new file mode 100644 index 0000000..45aa1e8 --- /dev/null +++ b/src/vmm.h @@ -0,0 +1,3 @@ +#pragma once + +extern "C" void dump_address(); |