![Very Happy :D](./images/smilies/icon_biggrin.gif)
Also: Page Global Enable (PGE) is a bit in the CR4 register. Just thought I might add that. However, it seems your best be is in CR2 and CR3...
No, you shouldn't. These are the physical mappings. If you read what you said before the code:Lprogster wrote:Thanks guys...
Ive hit a problem now.
This is the origional code (from the tutorial) that works fine:
If Im correct (and I probably arent!) I should be able to change the starting value of 'address' to change where pages are positioned. But when I change 'address' to something else Bochs simply restartsCode: Select all
unsigned long address=0; // holds the physical address of where a page is unsigned int i; // 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 };
.
What's up with that?
Thankyou both
Lster
In other words, the address has 4K added to it each time, for a total of 1024 times, which is 4MB.map the first 4MB of memory
Code: Select all
unsigned int *getPageEntry(unsigned int address)
{
unsigned int *pageTable = (unsigned int *) 0xffc00000;
/* 0xffc00000 is the valid address if the page directory was mapped
into the last entry of itself
*/
return &pageTable[address >> 12];
}
Ok, so here we again confuse pages and frames. The "address" is actually the address of the physical pages, which in older (and academic) literature is known as a frame. It's better get used to everyone speaking about pages all the time though, because that's how it goes, and you just have to figure out by the context whether it's a physical page (frame) or a virtual page.Lprogster wrote:Thanks guys...
Ive hit a problem now.
This is the origional code (from the tutorial) that works fine:
If Im correct (and I probably arent!) I should be able to change the starting value of 'address' to change where pages are positioned. But when I change 'address' to something else Bochs simply restartsCode: Select all
unsigned long address=0; // holds the physical address of where a page is unsigned int i; // 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 };
.
What's up with that?
Thankyou both
Lster
CR2 not set = no page fault = good thing. Good to hear you got it working, now I also understand paging a whole lot moreLprogster wrote:My page directory is at 0x9C000.
When I change the value of 'address' back to 0 (and it runs normally) these are the results:
Lster00079100000i[CPU0 ] | CR0=0x80000011 CR1=0 CR2=0x00000000
00079100000i[CPU0 ] | CR3=0x0009c000 CR4=0x00000000
Code: Select all
// get a pointer to the page directory
unsigned int *page_directory = page_directory_address;
// Get the page number
unsigned int page_number = virtual_address >> 12;
// Get the page table number
unsigned int page_table_number = ( ( page_number & 0xFFC00 ) >> 10 );
// move to the correct page directory entry
page_directory += ( virtual_address >> 12 );
// get the page table start
unsigned int *page_table = *page_directory 0xFFFFF000;
// move to the right page table entry
page_table += page_number & 0x3FF;
// get the physical address
unsigned physical_address = *page_table & 0xFFFFF000;