From ff6938346253aaabc9d17334f941a121c1e5ccf1 Mon Sep 17 00:00:00 2001 From: Alexander Huddleston Date: Tue, 27 Jun 2017 02:35:43 -0500 Subject: [PATCH] Page enable successful. Moving on to completing page fault function. --- MP3/MP3_Sources/kernel.C | 2 ++ MP3/MP3_Sources/page_table.C | 24 ++++++++++++------------ MP3/MP3_Sources/page_table.H | 1 + 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/MP3/MP3_Sources/kernel.C b/MP3/MP3_Sources/kernel.C index 884f1f4..733cef8 100755 --- a/MP3/MP3_Sources/kernel.C +++ b/MP3/MP3_Sources/kernel.C @@ -153,9 +153,11 @@ int main() { PageTable pt; pt.load(); + PageTable::enable_paging(); + for(;;); Console::puts("WE TURNED ON PAGING!\n"); Console::puts("If we see this message, the page tables have been\n"); Console::puts("set up mostly correctly.\n"); diff --git a/MP3/MP3_Sources/page_table.C b/MP3/MP3_Sources/page_table.C index 45d1271..b901326 100644 --- a/MP3/MP3_Sources/page_table.C +++ b/MP3/MP3_Sources/page_table.C @@ -25,15 +25,13 @@ void PageTable::init_paging(ContFramePool * _kernel_mem_pool, PageTable::PageTable() { - //kernel_mem_pool->get_frames(1); // Need to take one frame for page directory. - - //page_directory = (unsigned long *) 0x32000; // Should be the starting address after 1st 2MB - page_directory = (unsigned long *) kernel_mem_pool->get_frames(1); // Should I get the address like this??? + //unsigned long * temp_page_directory = (unsigned long *) 0x32000; // Should be the starting address after 1st 2MB + unsigned long * temp_page_directory = (unsigned long *) (4096 * kernel_mem_pool->get_frames(1)); // Should I get the address like this??? //unsigned long * page_table = (unsigned long *) 0x33000; // Should be 4kb after the page directory. - unsigned long * page_table = page_directory + 0x1000; // Might be able to just do this. + unsigned long * page_table = (unsigned long *) (4096 * kernel_mem_pool->get_frames(1)); // Might be able to just do this. - unsigned long tempaddr; // Temporary address iterator. + unsigned long tempaddr = 0; // Temporary address iterator. // We need to map the first 4MB. for(unsigned int i = 0; i < 1024; i++) @@ -44,14 +42,16 @@ PageTable::PageTable() // Fill first entry of page directory. - page_directory[0] = *page_table; - page_directory[0] = page_directory[0] | 3; + temp_page_directory[0] = (unsigned long)page_table; + temp_page_directory[0] = temp_page_directory[0] | 3; for(unsigned int j = 1; j < 1024; j++) { - page_directory[j] = 0 | 2; + temp_page_directory[j] = 0 | 2; } + page_directory = temp_page_directory; + current_page_table = this; Console::puts("\nConstructed Page Table object\n"); @@ -60,16 +60,16 @@ PageTable::PageTable() void PageTable::load() { - write_cr3(*page_directory); + write_cr3((unsigned long)page_directory); current_page_table = this; Console::puts("\nLoaded page table\n"); } void PageTable::enable_paging() { - write_cr3(*current_page_table->page_directory); + write_cr3((unsigned long)current_page_table->page_directory); write_cr0(read_cr0() | 0x80000000); - paging_enabled = 1; + paging_enabled = read_cr0(); Console::puts("\nEnabled paging\n"); } diff --git a/MP3/MP3_Sources/page_table.H b/MP3/MP3_Sources/page_table.H index f89e5a1..b56d4d7 100755 --- a/MP3/MP3_Sources/page_table.H +++ b/MP3/MP3_Sources/page_table.H @@ -47,6 +47,7 @@ private: static ContFramePool * kernel_mem_pool; /* Frame pool for the kernel memory */ static ContFramePool * process_mem_pool; /* Frame pool for the process memory */ static unsigned long shared_size; /* size of shared address space */ + static PageTable a_page_table; /* DATA FOR CURRENT PAGE TABLE */ unsigned long * page_directory; /* where is page directory located? */