Speedups to physical memory allocation, fixed a stupid error in the
[tpg/acess2.git] / Kernel / arch / x86_64 / mm_virt.c
index b4b26ec..4ec0847 100644 (file)
@@ -3,6 +3,7 @@
  * 
  * Virtual Memory Manager
  */
+#define DEBUG  0
 #include <acess.h>
 #include <mm_virt.h>
 #include <proc.h>
@@ -118,6 +119,10 @@ void MM_PageFault(tVAddr Addr, Uint ErrorCode, tRegs *Regs)
 //     Error_Backtrace(Regs->RIP, Regs->RBP);
        
        MM_DumpTables(0, -1);
+       
+       __asm__ __volatile__ ("cli");
+       for( ;; )
+               HALT();
 }
 
 /**
@@ -209,7 +214,7 @@ int MM_Map(tVAddr VAddr, tPAddr PAddr)
 {
        tPAddr  tmp;
        
-       Log("MM_Map: (VAddr=0x%x, PAddr=0x%x)", VAddr, PAddr);
+       ENTER("xVAddr xPAddr", VAddr, PAddr);
        
        // Check PML4
        //Log(" MM_Map: &PAGEMAPLVL4(%x) = %x", VAddr >> 39, &PAGEMAPLVL4(VAddr >> 39));
@@ -253,8 +258,8 @@ int MM_Map(tVAddr VAddr, tPAddr PAddr)
        PAGETABLE(VAddr >> PTAB_SHIFT) = PAddr | 3;
        
        INVLPG( VAddr );
-       Log("MM_Map: RETURN 1");
-       
+
+       LEAVE('i', 1);  
        return 1;
 }
 
@@ -283,12 +288,16 @@ tPAddr MM_Allocate(tVAddr VAddr)
        
        ENTER("xVAddr", VAddr);
        
+       // NOTE: This is hack, but I like my dumps to be neat
+       #if 1
        if( !MM_Map(VAddr, 0) ) // Make sure things are allocated
        {
                Warning("MM_Allocate: Unable to map, tables did not initialise");
                LEAVE('i', 0);
                return 0;
        }
+       MM_Unmap(VAddr);
+       #endif
        
        ret = MM_AllocPhys();
        LOG("ret = %x", ret);
@@ -484,6 +493,8 @@ tPAddr MM_Clone(void)
        ret = MM_AllocPhys();
        if(!ret)        return 0;
        
+       Log_KernelPanic("MM", "TODO: Implement MM_Clone");
+       
        // #2 Alter the fractal pointer
        // #3 Set Copy-On-Write to all user pages
        // #4 Return
@@ -545,10 +556,28 @@ void MM_ClearUser(void)
 
 tVAddr MM_NewWorkerStack(void)
 {
+       Log_KernelPanic("MM", "TODO: Implement MM_NewWorkerStack");
        return 0;
 }
 
+/**
+ * \brief Allocate a new kernel stack
+ */
 tVAddr MM_NewKStack(void)
 {
+       tVAddr  base = MM_KSTACK_BASE;
+       Uint    i;
+       for( ; base < MM_KSTACK_TOP; base += KERNEL_STACK_SIZE )
+       {
+               if(MM_GetPhysAddr(base) != 0)
+                       continue;
+               
+               Log("MM_NewKStack: Found one at %p", base + KERNEL_STACK_SIZE);
+               for( i = 0; i < KERNEL_STACK_SIZE; i += 0x1000)
+                       MM_Allocate(base+i);
+               
+               return base + KERNEL_STACK_SIZE;
+       }
+       Log_Warning("MM", "MM_NewKStack - No address space left\n");
        return 0;
 }

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