+ return 0;
+}
+
+int MM_int_SetPageInfo(tVAddr VAddr, tMM_PageInfo *pi)
+{
+ Uint32 *table0, *table1;
+ Uint32 *desc;
+
+ if(VAddr & 0x80000000 ) {
+ table0 = (void*)MM_TABLE0KERN; // Level 0
+ table1 = (void*)MM_TABLE1KERN; // Level 1
+ }
+ else {
+ table0 = (void*)MM_TABLE0USER;
+ table1 = (void*)MM_TABLE1USER;
+ }
+ VAddr &= 0x7FFFFFFF;
+
+ desc = &table0[ VAddr >> 20 ];
+
+ switch(pi->Size)
+ {
+ case 12: // Small Page
+ case 16: // Large Page
+ if( (*desc & 3) == 0 ) {
+ if( pi->PhysAddr == 0 ) return 0;
+ // Allocate
+ *desc = MM_AllocPhys();
+ *desc |= pi->Domain << 5;
+ *desc |= 1;
+ }
+ desc = &table1[ VAddr >> 12 ];
+ if( pi->Size == 12 )
+ {
+ // Small page
+ // - Error if overwriting a large page
+ if( (*desc & 3) == 1 ) return 1;
+ if( pi->PhysAddr == 0 ) {
+ *desc = 0;
+ return 0;
+ }
+
+ *desc = (pi->PhysAddr & 0xFFFFF000) | 2;
+ if(!pi->bExecutable) *desc |= 1; // XN
+ if(!pi->bGlobal) *desc |= 1 << 11; // NG
+ if( pi->bShared) *desc |= 1 << 10; // S
+ *desc |= (pi->AP & 3) << 4; // AP
+ *desc |= ((pi->AP >> 2) & 1) << 9; // APX
+ }
+ else
+ {
+ // Large page
+ // TODO:
+ }
+ break;
+ case 20: // Section or unmapped
+ Log_Warning("MM", "TODO: Implement sections");
+ break;
+ case 24: // Supersection
+ // Error if not aligned
+ if( VAddr & 0xFFFFFF ) {
+ return 1;
+ }
+ if( (*desc & 3) == 0 || ((*desc & 3) == 2 && (*desc & (1 << 18))) )
+ {
+ if( pi->PhysAddr == 0 ) {
+ *desc = 0;
+ // TODO: Apply to all entries
+ return 0;
+ }
+ // Apply
+ *desc = pi->PhysAddr & 0xFF000000;
+// *desc |= ((pi->PhysAddr >> 32) & 0xF) << 20;
+// *desc |= ((pi->PhysAddr >> 36) & 0x7) << 5;
+ *desc |= 2 | (1 << 18);
+ // TODO: Apply to all entries
+ return 0;
+ }
+ return 1;
+ }
+
+ return 1;