aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarvin Borner2020-01-21 22:10:16 +0100
committerMarvin Borner2020-01-21 22:10:16 +0100
commit3fa449276364389137a7154a9971594816d86362 (patch)
tree77ee5fa3744b9cb3f62d60ea1ca45d7555762350 /src
parent391ed256d21a6ae2e2456d1809f357e6e96e15d1 (diff)
Naming scheme and page fault improvements
Diffstat (limited to 'src')
-rw-r--r--src/kernel/graphics/vesa.c6
-rw-r--r--src/kernel/interrupts/isr.c8
-rw-r--r--src/kernel/memory/kheap.c8
-rw-r--r--src/kernel/memory/paging.c43
-rw-r--r--src/kernel/memory/paging.h12
5 files changed, 41 insertions, 36 deletions
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index d941413..15d953a 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -7,7 +7,7 @@
#include <kernel/memory/kheap.h>
#include <kernel/memory/paging.h>
-extern page_directory_t *kernel_directory;
+extern page_directory_t *current_directory;
void switch_to_vga()
{
@@ -184,9 +184,9 @@ void set_optimal_resolution()
uint32_t fb_size = vbe_width * vbe_height * vbe_bpl;
cursor_buffer = (unsigned char *) kmalloc(fb_size);
for (uint32_t z = 0; z < fb_size; z += 0x1000) {
- alloc_frame(get_page((uint32_t) fb + z, 1, kernel_directory), 0, 1);
- alloc_frame(get_page((uint32_t) cursor_buffer + z, 1, kernel_directory), 0, 1);
+ paging_alloc_frame(paging_get_page((uint32_t) fb + z, 1, current_directory), 0, 1);
}
+ serial_printf("0x%x", fb);
if (vbe_height > 1440) vesa_set_font(32);
else if (vbe_height > 720) vesa_set_font(24);
diff --git a/src/kernel/interrupts/isr.c b/src/kernel/interrupts/isr.c
index eb932b2..d89f581 100644
--- a/src/kernel/interrupts/isr.c
+++ b/src/kernel/interrupts/isr.c
@@ -3,6 +3,7 @@
#include <kernel/system.h>
#include <kernel/lib/string.h>
#include <kernel/lib/stdio.h>
+#include <kernel/graphics/vesa.h>
// Install ISRs in IDT
void isrs_install()
@@ -119,6 +120,11 @@ void fault_handler(struct regs *r)
// halt_loop(); // Idk loop?
char *message = (char *) exception_messages[r->int_no];
strcat(message, " Exception");
- panic(message);
+
+ // Show message if there wasn't an error in video memory
+ if (faulting_address != (uint32_t) fb)
+ panic(message);
+ else
+ halt_loop();
}
} \ No newline at end of file
diff --git a/src/kernel/memory/kheap.c b/src/kernel/memory/kheap.c
index def9ca2..40551bc 100644
--- a/src/kernel/memory/kheap.c
+++ b/src/kernel/memory/kheap.c
@@ -12,7 +12,7 @@ uint32_t kmalloc_int(uint32_t sz, int align, uint32_t *phys)
if (kheap != 0) {
void *addr = alloc(sz, (uint8_t) align, kheap);
if (phys != 0) {
- page_t *page = get_page((uint32_t) addr, 0, kernel_directory);
+ page_t *page = paging_get_page((uint32_t) addr, 0, kernel_directory);
*phys = page->frame * 0x1000 + ((uint32_t) addr & 0xFFF);
}
return (uint32_t) addr;
@@ -70,8 +70,8 @@ static void expand(uint32_t new_size, heap_t *heap)
uint32_t i = old_size;
while (i < new_size) {
- alloc_frame(get_page(heap->start_address + i, 1, kernel_directory),
- (heap->supervisor) ? 1 : 0, (heap->readonly) ? 0 : 1);
+ paging_alloc_frame(paging_get_page(heap->start_address + i, 1, kernel_directory),
+ (heap->supervisor) ? 1 : 0, (heap->readonly) ? 0 : 1);
i += 0x1000;
}
heap->end_address = heap->start_address + new_size;
@@ -92,7 +92,7 @@ static uint32_t contract(uint32_t new_size, heap_t *heap)
uint32_t old_size = heap->end_address - heap->start_address;
uint32_t i = old_size - 0x1000;
while (new_size < i) {
- free_frame(get_page(heap->start_address + i, 0, kernel_directory));
+ paging_free_frame(paging_get_page(heap->start_address + i, 0, kernel_directory));
i -= 0x1000;
}
diff --git a/src/kernel/memory/paging.c b/src/kernel/memory/paging.c
index e050861..ad19091 100644
--- a/src/kernel/memory/paging.c
+++ b/src/kernel/memory/paging.c
@@ -2,6 +2,7 @@
#include <kernel/memory/kheap.h>
#include <kernel/lib/lib.h>
#include <kernel/system.h>
+#include <kernel/lib/stdio.h>
int paging_enabled = 0;
@@ -19,7 +20,7 @@ extern void copy_page_physical();
#define INDEX_FROM_BIT(a) (a/(8*4))
#define OFFSET_FROM_BIT(a) (a%(8*4))
-static void set_frame(uint32_t frame_addr)
+static void paging_set_frame(uint32_t frame_addr)
{
uint32_t frame = frame_addr / 0x1000;
uint32_t idx = INDEX_FROM_BIT(frame);
@@ -27,7 +28,7 @@ static void set_frame(uint32_t frame_addr)
frames[idx] |= (0x1 << off);
}
-static void clear_frame(uint32_t frame_addr)
+static void paging_clear_frame(uint32_t frame_addr)
{
uint32_t frame = frame_addr / 0x1000;
uint32_t idx = INDEX_FROM_BIT(frame);
@@ -35,7 +36,7 @@ static void clear_frame(uint32_t frame_addr)
frames[idx] &= ~(0x1 << off);
}
-static uint32_t first_frame()
+static uint32_t paging_first_frame()
{
uint32_t i, j;
for (i = 0; i < INDEX_FROM_BIT(nframes); i++) {
@@ -51,15 +52,15 @@ static uint32_t first_frame()
return 0;
}
-void alloc_frame(page_t *page, int is_kernel, int is_writeable)
+void paging_alloc_frame(page_t *page, int is_kernel, int is_writeable)
{
if (page->frame != 0) {
return;
} else {
- uint32_t idx = first_frame();
+ uint32_t idx = paging_first_frame();
if (idx == (uint32_t) -1)
panic("No free frames!");
- set_frame(idx * 0x1000);
+ paging_set_frame(idx * 0x1000);
page->present = 1;
page->rw = (is_writeable == 1) ? 1 : 0;
page->user = (is_kernel == 1) ? 0 : 1;
@@ -67,13 +68,13 @@ void alloc_frame(page_t *page, int is_kernel, int is_writeable)
}
}
-void free_frame(page_t *page)
+void paging_free_frame(page_t *page)
{
uint32_t frame;
if (!(frame = page->frame)) {
return;
} else {
- clear_frame(frame);
+ paging_clear_frame(frame);
page->frame = 0x0;
}
}
@@ -91,27 +92,27 @@ void paging_install()
kernel_directory->physicalAddr = (uint32_t) kernel_directory->tablesPhysical;
for (uint32_t i = KHEAP_START; i < KHEAP_START + KHEAP_INITIAL_SIZE; i += 0x1000)
- get_page((uint32_t) i, 1, kernel_directory);
+ paging_get_page((uint32_t) i, 1, kernel_directory);
int i = 0;
while (i < 0x400000) {
- alloc_frame(get_page((uint32_t) i, 1, kernel_directory), 0, 0);
+ paging_alloc_frame(paging_get_page((uint32_t) i, 1, kernel_directory), 0, 0);
i += 0x1000;
}
for (i = KHEAP_START; i < (int) (KHEAP_START + KHEAP_INITIAL_SIZE); i += 0x1000)
- alloc_frame(get_page((uint32_t) i, 1, kernel_directory), 0, 0);
+ paging_alloc_frame(paging_get_page((uint32_t) i, 1, kernel_directory), 0, 0);
- switch_page_directory(kernel_directory);
+ paging_switch_directory(kernel_directory);
kheap = create_heap(KHEAP_START, KHEAP_START + KHEAP_INITIAL_SIZE, 0xCFFFF000, 0, 0);
- current_directory = clone_directory(kernel_directory);
- switch_page_directory(current_directory);
+ current_directory = paging_clone_directory(kernel_directory);
+ paging_switch_directory(current_directory);
vga_log("Installed Paging");
}
-void switch_page_directory(page_directory_t *dir)
+void paging_switch_directory(page_directory_t *dir)
{
current_directory = dir;
asm volatile("mov %0, %%cr3"::"r"(dir->physicalAddr));
@@ -123,7 +124,7 @@ void switch_page_directory(page_directory_t *dir)
void paging_enable()
{
- switch_page_directory(kernel_directory);
+ paging_switch_directory(kernel_directory);
paging_enabled = 1;
}
@@ -136,7 +137,7 @@ void paging_disable()
paging_enabled = 0;
}
-page_t *get_page(uint32_t address, int make, page_directory_t *dir)
+page_t *paging_get_page(uint32_t address, int make, page_directory_t *dir)
{
address /= 0x1000;
uint32_t table_idx = address / 1024;
@@ -154,7 +155,7 @@ page_t *get_page(uint32_t address, int make, page_directory_t *dir)
}
}
-static page_table_t *clone_table(page_table_t *src, uint32_t *physAddr)
+static page_table_t *paging_clone_table(page_table_t *src, uint32_t *physAddr)
{
page_table_t *table = (page_table_t *) kmalloc_ap(sizeof(page_table_t), physAddr);
memset(table, 0, sizeof(page_directory_t));
@@ -163,7 +164,7 @@ static page_table_t *clone_table(page_table_t *src, uint32_t *physAddr)
if (!src->pages[i].frame)
continue;
- alloc_frame(&table->pages[i], 0, 0);
+ paging_alloc_frame(&table->pages[i], 0, 0);
if (src->pages[i].present) table->pages[i].present = 1;
if (src->pages[i].rw) table->pages[i].rw = 1;
@@ -176,7 +177,7 @@ static page_table_t *clone_table(page_table_t *src, uint32_t *physAddr)
return table;
}
-page_directory_t *clone_directory(page_directory_t *src)
+page_directory_t *paging_clone_directory(page_directory_t *src)
{
uint32_t phys;
page_directory_t *dir = (page_directory_t *) kmalloc_ap(sizeof(page_directory_t), &phys);
@@ -195,7 +196,7 @@ page_directory_t *clone_directory(page_directory_t *src)
dir->tablesPhysical[i] = src->tablesPhysical[i];
} else {
uint32_t phys;
- dir->tables[i] = clone_table(src->tables[i], &phys);
+ dir->tables[i] = paging_clone_table(src->tables[i], &phys);
dir->tablesPhysical[i] = phys | 0x07;
}
}
diff --git a/src/kernel/memory/paging.h b/src/kernel/memory/paging.h
index 285cb6f..bb6ee4f 100644
--- a/src/kernel/memory/paging.h
+++ b/src/kernel/memory/paging.h
@@ -26,22 +26,20 @@ typedef struct page_directory {
int paging_enabled;
-void alloc_frame(page_t *page, int is_kernel, int is_writeable);
+void paging_alloc_frame(page_t *page, int is_kernel, int is_writeable);
-void free_frame(page_t *page);
+void paging_free_frame(page_t *page);
void paging_install();
-void switch_page_directory(page_directory_t *new);
+void paging_switch_directory(page_directory_t *dir);
void paging_enable();
void paging_disable();
-page_t *get_page(uint32_t address, int make, page_directory_t *dir);
+page_t *paging_get_page(uint32_t address, int make, page_directory_t *dir);
-void page_fault(struct regs *regs);
-
-page_directory_t *clone_directory(page_directory_t *src);
+page_directory_t *paging_clone_directory(page_directory_t *src);
#endif