Code: Select all
//our first page table comes right after the page directory
unsigned int *first_page_table = page_directory + 0x1000;
The thing is that page_directory and first_page_table are declared as pointers to integers, for example on 32-bit Intel an int is 4 bytes long, so if you advance a pointer to an integer by 1 in fact you will advance by 4 bytes in the memory region.
So, as 0x1000 = 4096, in fact it will advance in memory by 0x1000 * 4 = 4096 * 4 = 16384.
But we need to advance only by 4096 bytes (0x400 in hex) becauses the next page table is in 4096 bytes.
So the correct line should be:
Code: Select all
//our first page table comes right after the page directory (4096 bytes offset),
unsigned int *first_page_table = page_directory + 1024;
Isn't it?