/* * mem-phys.c * * Created on: Aug 27, 2011 * Author: Tiberiu */ #include #include "mem.h" uint32* FrameMap; uint32 TotalFrames; uint32 TotalMemory; void ConvertIndexToFrame (uint32 index, uint32* address, uint32* offset) { *address = (index >> 5); *offset = index & 0x1f; } uint32 ConvertFrameToIndex (uint32 address, uint32 offset) { return (address<<5) | offset; } void MemPhSetFrame (uint32 frame, uint8 value) { uint32 addr, off; ConvertIndexToFrame(frame, &addr, &off); if (value) FrameMap[addr] |= 1<> 5; addr++) if (FrameMap[addr] != 0xffffffff) { for (pos = 0; (FrameMap[addr] & (1<Frame != 0) return; uint32 free = MemPhFindFreeFrame(); if (!free) return; LogMem("Physical: allocated frame %u.\n", free); MemPhSetFrame(free, 1); /*page->Present = 1; page->User = (isKernel) ? 0 : 1; page->Writeable = (isWriteable) ? 1 : 0; page->Frame = free;*/ } /*void MemPhFreeFrame()//Page* page) { uint32 frame = page->Frame; if (!frame) return; MemPhSetFrame(frame, 0); page->Frame = 0; }*/ void MemPhInitialize(uint32 SystemMemoryKb) { LogMem("Starting physical memory manager...\n"); TotalFrames = SystemMemoryKb >> 2; TotalMemory = SystemMemoryKb; FrameMap = (uint32*) malloc(sizeof(uint32) * (1 + (TotalFrames>>5))); memset(FrameMap, 0, sizeof(uint32) * (1 + (TotalFrames>>5))); LogMem("Started ok!, found %ukb total_frames=%u\n", SystemMemoryKb, TotalFrames); } void MemPhReserveFrames (uint32 address, uint32 length) { address >>= 12; length = (length>>12) + ((length & 0xfff) > 0); uint32 end = address + length; for (; address < end && address < TotalFrames ; address++) MemPhSetFrame(address, 1); }