Kernel/armv7 - Fixed error messages having invalid addresses
[tpg/acess2.git] / Kernel / arch / armv7 / mm_virt.c
index 2555b8a..53531d3 100644 (file)
@@ -9,6 +9,8 @@
 #include <mm_virt.h>
 #include <hal_proc.h>
 
+#define TRACE_MAPS     0
+
 #define AP_KRW_ONLY    1       // Kernel page
 #define AP_KRO_ONLY    5       // Kernel RO page
 #define AP_RW_BOTH     3       // Standard RW
@@ -390,7 +392,9 @@ void MM_SetFlags(tVAddr VAddr, Uint Flags, Uint Mask)
 int MM_Map(tVAddr VAddr, tPAddr PAddr)
 {
        tMM_PageInfo    pi = {0};
-//     Log("MM_Map %P=>%p", PAddr, VAddr);
+       #if TRACE_MAPS
+       Log("MM_Map %P=>%p", PAddr, VAddr);
+       #endif
        
        pi.PhysAddr = PAddr;
        pi.Size = 12;
@@ -487,7 +491,7 @@ void MM_int_CloneTable(Uint32 *DestEnt, int Table)
 {
        tPAddr  table;
        Uint32  *tmp_map;
-       Uint32  *cur = (void*)MM_TABLE0USER;
+       Uint32  *cur = (void*)MM_TABLE1USER;
 //     Uint32  *cur = &FRACTAL(MM_TABLE1USER,0);
         int    i;
        
@@ -498,12 +502,13 @@ void MM_int_CloneTable(Uint32 *DestEnt, int Table)
        
        for( i = 0; i < 1024; i ++ )
        {
-               switch(cur[i] & 3)
+//             Log_Debug("MMVirt", "cur[%i] (%p) = %x", Table*256+i, &cur[Table*256+i], cur[Table*256+i]);
+               switch(cur[Table*256+i] & 3)
                {
                case 0: tmp_map[i] = 0; break;
                case 1:
                        tmp_map[i] = 0;
-                       Log_Error("MMVirt", "TODO: Support large pages in MM_int_CloneTable");
+                       Log_Error("MMVirt", "TODO: Support large pages in MM_int_CloneTable (%p)", (Table*256+i)*0x1000);
                        // Large page?
                        break;
                case 2:
@@ -529,6 +534,8 @@ tPAddr MM_Clone(void)
        Uint32  *new_lvl1_1, *new_lvl1_2, *cur;
        Uint32  *tmp_map;
         int    i;
+
+//     MM_DumpTables(0, KERNEL_BASE);
        
        ret = MM_AllocateRootTable();
 
@@ -538,7 +545,11 @@ tPAddr MM_Clone(void)
        tmp_map = new_lvl1_1;
        for( i = 0; i < 0x800-4; i ++ )
        {
-//             Log("i = %i", i);
+               // HACK! Ignore the original identity mapping
+               if( i == 0 && Threads_GetTID() == 0 ) {
+                       tmp_map[0] = 0;
+                       continue;
+               }
                if( i == 0x400 )
                        tmp_map = &new_lvl1_2[-0x400];
                switch( cur[i] & 3 )
@@ -682,7 +693,7 @@ tVAddr MM_MapHWPages(tPAddr PAddr, Uint NPages)
        
                // Map the pages        
                for( i = 0; i < NPages; i ++ )
-                       MM_Map(ret+i*PAGE_SIZE, PAddr+i*PAddr);
+                       MM_Map(ret+i*PAGE_SIZE, PAddr+i*PAGE_SIZE);
                // and return
                LEAVE('p', ret);
                return ret;
@@ -694,8 +705,19 @@ tVAddr MM_MapHWPages(tPAddr PAddr, Uint NPages)
 
 tVAddr MM_AllocDMA(int Pages, int MaxBits, tPAddr *PAddr)
 {
-       Log_Error("MMVirt", "TODO: Implement MM_AllocDMA");
-       return 0;
+       tPAddr  phys;
+       tVAddr  ret;
+
+       phys = MM_AllocPhysRange(Pages, MaxBits);
+       if(!phys) {
+               Log_Warning("MMVirt", "No space left for a %i page block (MM_AllocDMA)", Pages);
+               return 0;
+       }
+       
+       ret = MM_MapHWPages(phys, Pages);
+       *PAddr = phys;
+
+       return ret;
 }
 
 void MM_UnmapHWPages(tVAddr Vaddr, Uint Number)

UCC git Repository :: git.ucc.asn.au