+ MM_DumpTables(0, -1);
+
+ __asm__ __volatile__ ("cli");
+ for( ;; )
+ HALT();
+}
+
+/**
+ * \brief Dumps the layout of the page tables
+ */
+void MM_DumpTables(tVAddr Start, tVAddr End)
+{
+ const tPAddr CHANGEABLE_BITS = 0xFF8;
+ const tPAddr MASK = ~CHANGEABLE_BITS; // Physical address and access bits
+ tVAddr rangeStart = 0;
+ tPAddr expected = CHANGEABLE_BITS; // MASK is used because it's not a vaild value
+ tVAddr curPos;
+ Uint page;
+
+ Log("Table Entries: (%p to %p)", Start, End);
+
+ End &= (1L << 48) - 1;
+
+ Start >>= 12; End >>= 12;
+
+ for(page = Start, curPos = Start<<12;
+ page < End;
+ curPos += 0x1000, page++)
+ {
+ if( curPos == 0x800000000000L )
+ curPos = 0xFFFF800000000000L;
+
+ //Debug("&PAGEMAPLVL4(%i page>>27) = %p", page>>27, &PAGEMAPLVL4(page>>27));
+ //Debug("&PAGEDIRPTR(%i page>>18) = %p", page>>18, &PAGEDIRPTR(page>>18));
+ //Debug("&PAGEDIR(%i page>>9) = %p", page>>9, &PAGEDIR(page>>9));
+ //Debug("&PAGETABLE(%i page) = %p", page, &PAGETABLE(page));
+
+ // End of a range
+ if(
+ !(PAGEMAPLVL4(page>>27) & PF_PRESENT)
+ || !(PAGEDIRPTR(page>>18) & PF_PRESENT)
+ || !(PAGEDIR(page>>9) & PF_PRESENT)
+ || !(PAGETABLE(page) & PF_PRESENT)
+ || (PAGETABLE(page) & MASK) != expected)
+ {
+ if(expected != CHANGEABLE_BITS) {
+ Log("%016x-0x%016x => %013x-%013x (%c%c%c%c)",
+ rangeStart, curPos - 1,
+ PAGETABLE(rangeStart>>12) & ~0xFFF,
+ (expected & ~0xFFF) - 1,
+ (expected & PF_PAGED ? 'p' : '-'),
+ (expected & PF_COW ? 'C' : '-'),
+ (expected & PF_USER ? 'U' : '-'),
+ (expected & PF_WRITE ? 'W' : '-')
+ );
+ expected = CHANGEABLE_BITS;
+ }
+ if( !(PAGEMAPLVL4(page>>27) & PF_PRESENT) ) {
+ page += (1 << 27) - 1;
+ curPos += (1L << 39) - 0x1000;
+ //Debug("pml4 ent unset (page = 0x%x now)", page);
+ continue;
+ }
+ if( !(PAGEDIRPTR(page>>18) & PF_PRESENT) ) {
+ page += (1 << 18) - 1;
+ curPos += (1L << 30) - 0x1000;
+ //Debug("pdp ent unset (page = 0x%x now)", page);
+ continue;
+ }
+ if( !(PAGEDIR(page>>9) & PF_PRESENT) ) {
+ page += (1 << 9) - 1;
+ curPos += (1L << 21) - 0x1000;
+ //Debug("pd ent unset (page = 0x%x now)", page);
+ continue;
+ }
+ if( !(PAGETABLE(page) & PF_PRESENT) ) continue;
+
+ expected = (PAGETABLE(page) & MASK);
+ rangeStart = curPos;
+ }
+ if(expected != CHANGEABLE_BITS)
+ expected += 0x1000;
+ }
+
+ if(expected != CHANGEABLE_BITS) {
+ Log("%016x-%016x => %013x-%013x (%s%s%s%s)",
+ rangeStart, curPos - 1,
+ PAGETABLE(rangeStart>>12) & ~0xFFF,
+ (expected & ~0xFFF) - 1,
+ (expected & PF_PAGED ? "p" : "-"),
+ (expected & PF_COW ? "C" : "-"),
+ (expected & PF_USER ? "U" : "-"),
+ (expected & PF_WRITE ? "W" : "-")
+ );
+ expected = 0;
+ }