eryjus wrote:A couple of observations here:
* Paging is enabled
* The address of the PD in CR3 is 0x00000000 (confirm this is correct)
* If this is a page fault, the faulting address (CR2) is 0x00000000 (confirm this address is identity mapped)
* ESI, EDI, EBP are all 0x00000000
* EIP is 00100b81, when you disassemble the object, what is happening at that address? (Are ESI, EDI, or EBP used?)
* Null pointer assignment/reference?
I was about to post that. When I checked the address of the PD (page_directory->physical_page_tables) it was 0, like wow!
Why would that be 0? I am for sure allocating it correctly so PD (page_directory_t* page_directory) returns 0x11E050 (correct, expected), but page_directory->physical_pages_tables returns 0x0.
That is soooo suspicious. Also this data was gathered with optimizations enabled and shell disabled which means no triple fault or anything.
I hope that replacing every NULL with 0 inside the LibAlloc had nothing to do with it. (but why would you do that? c++ casting errors bypass method).
Disabling the optimizations revealed: //With -O1/2/3/4/5 everything is mapped and working fine
Code: Select all
(0).[7374714438] ??? (physical address not available)
(0).[7374714439] ??? (physical address not available)
bx_dbg_read_linear: physical address not available for linear 0x0000000000100a3b
00100b81 disassembly (shell with -O2)
00100a3b disassembly (no -O2 no shell)
Edit: The only way I can get it to work without crashing is with -O2 and shell disabled. Then everything is mapped correctly but page_directory->physical_page_tables still returns 0x0.
Edit 2: -O2 enabled shell enabled -> VMM.Initialize(); commented out but it is not Paging_Enable what causes it, so it is something inside the initialization chunk that overwrites something.
Even even even stranger:
uint32_t page_directory_address = PMM.Allocate_Blocks(sizeof(page_directory_t) / 4096); ---->>>> this returns 0x11D000
then
page_directory = (page_directory_t*) page_directory_address;
so TUI.Put_Hex((uint32_t) & page_directory, 0x0E); should return 0x11D000 right? No! It returns 0x11E050. Stuff likely getting overwritten. Right?
Edit 3: So the main question is: why would paging work
perfectly with -O2 enabled and crash without -O2? Am I hunting a bug that does not exist? Likely a compiler bug?
Also this is how my page_directory looks like:
Code: Select all
typedef struct page_directory_t
{
page_directory_entry_t physical_page_tables[1024];
page_table_t* virtual_page_tables[1024];
}page_directory_t;
page_directory_t* page_directory;
This is how I allocate it:
Code: Select all
uint32_t page_directory_address = PMM.Allocate_Blocks(sizeof(page_directory_t) / 4096);
page_directory = (page_directory_t*) page_directory_address;
Then why would a damn compiler put page_directory->physical_page_tables at 0x0? Also don't worry about virtual_page_tables they are all perfectly allocated (I checked).