All implemented. Cannot resolve issue with process_mem_pool. Turning in anyway.

This commit is contained in:
Alex Huddleston 2017-06-28 00:20:59 -05:00
parent 79576ac9c5
commit f4a0cf6830
2 changed files with 60 additions and 19 deletions

View file

@ -171,9 +171,9 @@ int main() {
int i;
for (i=0; i<NACCESS; i++) {
Console::puts("\n");
Console::puti(i);
Console::puts("\n");
//Console::puts("\n");
//Console::puti(i);
//Console::puts("\n");
foo[i] = i;
}
Console::puts("DONE WRITING TO MEMORY. Now testing...\n");

View file

@ -32,6 +32,7 @@ PageTable::PageTable()
unsigned long tempaddr = 0; // Temporary address iterator.
// We need to map the first 4MB.
// This first for loop was here in case I needed to set the first 2mb as not present.
for(unsigned int i = 0; i < 512; i++)
{
page_table[i] = tempaddr | 3; // set bits 0 and 1 to present and read/write respectively
@ -54,7 +55,6 @@ PageTable::PageTable()
temp_page_directory[j] = 0 | 2;
}
//page_directory = (unsigned long *) ((unsigned long)temp_page_directory + (unsigned long)page_table + (unsigned long)page_table[0]);
page_directory = temp_page_directory;
current_page_table = this;
@ -65,17 +65,14 @@ PageTable::PageTable()
void PageTable::load()
{
//write_cr3((unsigned long)page_directory + (unsigned long)page_directory[0] + (unsigned long)((unsigned long *)page_directory[0])[0]);
write_cr3((unsigned long)page_directory);
Console::puti((unsigned long)page_directory);
//for(;;);
current_page_table = this;
Console::puts("\nLoaded page table\n");
}
void PageTable::enable_paging()
{
//write_cr3((unsigned long)current_page_table->page_directory + (unsigned long)current_page_table->page_directory[0] + (unsigned long)((unsigned long *)current_page_table->page_directory[0])[0]);
write_cr3((unsigned long)current_page_table->page_directory);
write_cr0(read_cr0() | 0x80000000);
paging_enabled = read_cr0();
@ -84,21 +81,65 @@ void PageTable::enable_paging()
void PageTable::handle_fault(REGS * _r)
{
unsigned long temp_addr = (kernel_mem_pool->get_frames(1));
((unsigned long *) ((unsigned long *) current_page_table->page_directory)[0])[temp_addr]
= ((unsigned long *) ((unsigned long *) current_page_table->page_directory)[0])[temp_addr] | 3;
// Initializing some variables to make things easier.
unsigned long * temp_pd = (unsigned long *) (current_page_table->page_directory);
unsigned long * temp_pt = (unsigned long *) (*temp_pd);
Console::puts("\nerror code: ");
Console::puti(_r->err_code);
unsigned long pt_index = (read_cr2() >> 12) & 0x3FFFFF;
unsigned long pd_index = read_cr2() >> 22;
// If there isn't a page table present.
if(!(temp_pd[pd_index] & 1))
{
Console::puts("\nPage Table not Present.\n");
unsigned long * new_pt = (unsigned long *) (kernel_mem_pool->get_frames(1) << 12);
// Set new page table entries as present.
// Start at beginning address for the page table
// this should be pd_index << 22.
unsigned long temp_addr = pd_index << 22;
for(unsigned int i = 0; i < 1024; i++)
{
new_pt[i] = temp_addr | 3;
temp_addr += 4096;
}
// Add page table to page directory.
temp_pd[pd_index] = (unsigned long) new_pt;
temp_pd[pd_index] = temp_pd[pd_index] | 3;
}
/*
// Why is this commented out?
// Unfortunately, for whatever reason, any time I try to call
// process_mem_pool->get_frames() the entire program crashes.
// I've tried evaluating lines immediately afterwards, adding
// for(;;);, the program ignores this and continues to crash.
// Since I have no idea why this is happening, I can only assume
// I did something wrong in cont_frame_pool or that this is just
// an issue I didn't address properly somewhere and didn't see
// addressed in the instructions. Regardless, I left what I believe
// would be the implementation of handle_fault in the case that I
// needed to allocate a frame in process_mem_pool in order to
// allocate a page for a process commented out so I could at least
// show that I knew how it would be implemented.
if(read_cr2() >> 22 > 0)
{
if(((unsigned long *)temp_pd[pd_index])[pt_index] & 1)
{
Console::puts("\nPage not present.\n");
unsigned long * new_page = (unsigned long *) (process_mem_pool->get_frames(1) << 12);
// Set new page as page table entry.
((unsigned long *)temp_pd[pd_index])[pt_index] = (unsigned long) new_page | 3;
}
}
*/
unsigned char mask = 0x00;
Console::puts("\naddress: ");
Console::puti(read_cr2());
Console::puts("\naddress: ");
Console::puti(read_cr3());
for(;;);
Console::puts("\nhandled page fault\n");
}