// Load Virtual Filesystem
VFS_Init();
- *(Uint16*)(0xB8000) = 0x1F00|'G';
+ *(Uint16*)(0xB8000) = 0x1F00|'Z';
+ *(Uint16*)(0xB8002) = 0x1F00|'Z';
+ *(Uint16*)(0xB8004) = 0x1F00|'Z';
+ *(Uint16*)(0xB8006) = 0x1F00|'Z';
// Pass on to Independent Loader
Log_Log("Arch", "Starting system");
*
* Physical Memory Manager
*/
-#define DEBUG 0
+#define DEBUG 1
#include <acess.h>
#include <mboot.h>
#include <mm_virt.h>
LOG("nFree = %i = 0 (super) (0x%x)", nFree, addr);
nFree = 0;
addr += 1 << (6+6);
- addr &= (1 << (6+6)) - 1;
+ addr &= ~( (1 << (6+6)) - 1 );
continue;
}
// Check page block (64 pages)
LOG("nFree = %i = 0 (main) (0x%x)", nFree, addr);
nFree = 0;
addr += 1 << (12+6);
- addr &= (1 << (12+6)) - 1;
+ addr &= ~( (1 << (12+6)) - 1 );
continue;
}
// Check individual page
for( i = 0; i < Num; i++, addr++ )
{
gaMainBitmap[addr >> 6] |= 1 << (addr & 63);
- rangeID = MM_int_GetRangeID(addr);
+ rangeID = MM_int_GetRangeID(addr << 12);
giPhysRangeFree[ rangeID ] --;
+ if(addr << 12 == giPhysRangeFirst[ rangeID ])
+ giPhysRangeFirst[ rangeID ] += 1;
}
ret = addr; // Save the return address
else
gaMainBitmap[ page >> 6 ] &= ~(1 << (page&63));
- // TODO: Update free counts
+ // Update the free counts if the page was freed
if( !(gaMainBitmap[ page >> 6 ] & (1 << (page&63))) )
{
int rangeID;
rangeID = MM_int_GetRangeID( PAddr );
giPhysRangeFree[ rangeID ] ++;
+ if( giPhysRangeFirst[rangeID] > page )
+ giPhysRangeFirst[rangeID] = page;
+ if( giPhysRangeLast[rangeID] < page )
+ giPhysRangeLast[rangeID] = page;
}
- if(gaMainBitmap[ page >> 6 ] == 0) {
+ // If the bitmap entry is not -1, unset the bit in the super bitmap
+ if(gaMainBitmap[ page >> 6 ] != -1 ) {
gaSuperBitmap[page >> 12] &= ~(1 << ((page >> 6) & 63));
}
}
*
* Virtual Memory Manager
*/
+#define DEBUG 0
#include <acess.h>
#include <mm_virt.h>
#include <proc.h>
{
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));
PAGETABLE(VAddr >> PTAB_SHIFT) = PAddr | 3;
INVLPG( VAddr );
- Log("MM_Map: RETURN 1");
-
+
+ LEAVE('i', 1);
return 1;
}
return 0;
}
+/**
+ * \brief Allocate a new kernel stack
+ */
tVAddr MM_NewKStack(void)
{
- Log_KernelPanic("MM", "TODO: Implement MM_NewKStack");
+ 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;
}