From fbbcb04f9e3197976d6ab4a79c45aa0a84e39aba Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Mon, 25 Jun 2018 03:57:22 +1000 Subject: Added the header asm/interrupt.h which includes a prototype for the assembly function register_isr making it usable within the C portions of the source. Added a new file panic.s with the function panic that will print a panic message, disable interrupts and halt the system. Created the skeleton framework for paging in the new file page.s. The new function paging_init (called in kboot) will setup a simple page directory with two tables covering all addresses 0-8MB. It will also mark pages from 0-1MB as 'supervisor-only' to protect the kernel. NOTE: The function paging_init must be called before initialising the IDT as it does not disable interrupts! Modified the page fault handler to print the offending linear address along with the supplied error code. Following that, the handler will initiate a kernel panic. This function (along with panic) assumes console I/O to be operational. Modified the userspace test code to deliberately intiate a page fault by accessing an unmapped page. --- kernel/page.s | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 kernel/page.s (limited to 'kernel/page.s') diff --git a/kernel/page.s b/kernel/page.s new file mode 100644 index 0000000..4e40822 --- /dev/null +++ b/kernel/page.s @@ -0,0 +1,55 @@ +global paging_init + +align 4096 +page_dir: + times 4096 db 0 + +align 4096 +page_tables: + ; two page tables + times 4096 db 0 + times 4096 db 0 +.end: + +; here, we initialize paging. since the IDT +; has yet to be populated, we must take extra +; care as we can't afford to trigger a page +; fault. +paging_init: + push ebp + mov ebp, esp + push ebx + ; populate the page directory + mov eax, page_tables + or eax, 0x007 + mov [page_dir], eax + mov eax, (page_tables+4096) + or eax, 0x007 + mov [page_dir+4], eax + ; populate the page tables + mov ebx, page_tables + mov ecx, ((page_tables.end-page_tables)/4) + mov edx, 0 +.loop: + mov eax, edx + or eax, 0x003 + cmp edx, 0x100000 + jb .skip + or eax, 0x004 +.skip: + mov [ebx], eax + dec ecx + jz .end + add ebx, 4 + add edx, 4096 + jmp .loop +.end: + ; load the page directory and enable paging + mov eax, page_dir + mov cr3, eax + mov eax, cr0 + or eax, 0x80000000 + mov cr0, eax + pop ebx + pop ebp + ret -- cgit v1.3