aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2021-03-10 19:39:30 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2021-03-10 19:39:30 +0200
commita302ef42887a1a349d9918d5d1471bbea8f59c2b (patch)
treece655d3c31574c6cb77bc437abedf66d32ac9d90
parentMove elf and iso to builddir (diff)
downloadkernel.cpp-a302ef42887a1a349d9918d5d1471bbea8f59c2b.tar.xz
vmm: display segment map info
-rw-r--r--linker.ld16
-rw-r--r--src/boot.S9
-rw-r--r--src/gdt.cc2
-rw-r--r--src/idt.cc8
-rw-r--r--src/idt/exception.cc8
-rw-r--r--src/idt/stubs.S2
-rw-r--r--src/kernel.cc18
-rw-r--r--src/makefile6
-rw-r--r--src/vmm.cc49
-rw-r--r--src/vmm.h3
10 files changed, 85 insertions, 36 deletions
diff --git a/linker.ld b/linker.ld
index 5ff3b62..e9f1d73 100644
--- a/linker.ld
+++ b/linker.ld
@@ -20,32 +20,40 @@ SECTIONS
. = VADDR_BASE + 1M;
.text ALIGN(4K) : AT(ADDR(.text) - VADDR_BASE) {
+ begin_text = .;
*(.text*)
+ end_text = .;
}
/* Read-only data. */
.rodata ALIGN(4K) : AT(ADDR(.rodata) - VADDR_BASE) {
+ begin_rodata = .;
*(.rodata*)
+ end_rodata = .;
}
/* Read-write data (initialized) */
.data ALIGN(4K) : AT(ADDR(.data) - VADDR_BASE) {
- begin_ctors = .;
- KEEP(*(.init_array)); /* global constructors */
- end_ctors = .;
-
begin_constinit = .;
*(.constinit)
end_constinit = .;
+ begin_ctors = .;
+ KEEP(*(.init_array)); /* global constructors */
+ end_ctors = .;
+
+ begin_data = .;
*(.data)
+ end_data = .;
}
/* Read-write data (uninitialized) and stack */
.bss ALIGN(4K) : AT(ADDR(.bss) - VADDR_BASE) {
+ begin_bss = .;
*(.pages)
*(.bss)
*(.stack)
+ end_bss = .;
}
_kernel_end = .;
}
diff --git a/src/boot.S b/src/boot.S
index 635b38f..e5686c8 100644
--- a/src/boot.S
+++ b/src/boot.S
@@ -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.
diff --git a/src/gdt.cc b/src/gdt.cc
index 0712187..7b5e3df 100644
--- a/src/gdt.cc
+++ b/src/gdt.cc
@@ -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}),
diff --git a/src/idt.cc b/src/idt.cc
index edf7b37..19865f6 100644
--- a/src/idt.cc
+++ b/src/idt.cc
@@ -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();