Help me! Memory Managment
Posted: Fri Jul 31, 2009 2:04 pm
Being fourteen and not even in high school it is quite hard for my kernel developing streak. Because of this I am having trouble with memory management.
If someone would please point me to a tutorial or help me out, by explaining in "English" terms (I understand the concept, just not how) . I have tried to
put this code together:
And it returns this as the placement address (If it is wrong it might be the putshex).
0x1068a0
Please help. (pl0x).
If someone would please point me to a tutorial or help me out, by explaining in "English" terms (I understand the concept, just not how) . I have tried to
put this code together:
Code: Select all
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// end is defined in the linker script.
extern u32int end;
u32int placement_address = (u32int)&end;
// Page direcory 'Just need some free memory (4kb) that is aligned (can be divided by: 4096 without a remainder).' 0x9C000
unsigned long *page_directory = (unsigned long *) 0x9C000;
// Page Table the page table comes right after the page directory
unsigned long *page_table = (unsigned long *) 0x9D000;
// Address holds the physical address of where a page is
unsigned long address=0;
// I is a basic counting variable for our loops
unsigned int i;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Maps the first table, then sets up other basic requirements
void MapFirstTable()
{
putshex(placement_address);
// Map the first 4MB of memory
for(i=0; i<1024; i++)
{
page_table[i] = address | 3; // attribute set to: supervisor level, read/write, present(011 in binary)
address = address + 4096; // 4096 = 4kb
};
// fill the first entry of the page directory
page_directory[0] = page_table; // attribute set to: supervisor level, read/write, present(011 in binary)
page_directory[0] = page_directory[0] | 3;
for(i=1; i<1024; i++)
{
page_directory[i] = 0 | 2; // attribute set to: supervisor level, read/write, not present(010 in binary)
};
// write_cr3, read_cr3, write_cr0, and read_cr0 all come from the assembly functions
write_cr3(page_directory); // put that page directory address into CR3
write_cr0((unsigned long)read_cr0() | 0x80000000); // set the paging bit in CR0 to 1
// PAGING IS ENABLED
}
0x1068a0
Please help. (pl0x).