/// <summary> /// Setup the physical page manager /// </summary> public void Setup() { uint physMem = BootInfo.Header->InstalledPhysicalMemory; PageCount = physMem / PageSize; kmap = KernelMemoryMapManager.Allocate(PageCount * (uint)sizeof(Page), BootInfoMemoryType.PageFrameAllocator); PageArray = (Page *)kmap.Start; lastAllocatedPage = PageArray; Memory.InitialKernelProtect_MakeWritable_BySize(kmap.Start, kmap.Size); MemoryOperation.Clear4(kmap.Start, kmap.Size); for (uint i = 0; i < PageCount; i++) { PageArray[i].PhysicalAddress = i * PageSize; if (i != 0) { PageArray[i - 1].Next = &PageArray[i]; } } SetupFreeMemory(); for (uint i = 0; i < PageCount; i++) { if (!PageArray[i].Used) { PageArray[i].Status = PageStatus.Free; } } }
/// <summary> /// allocate memory. The memory is set to zero. /// </summary> public static Addr AllocateCleared(USize n, GFP flags) { var addr = Allocate(n, flags); MemoryOperation.Clear(addr, n); return(addr); }
/// <summary> /// allocate memory for an array. The memory is set to zero. /// </summary> public static Addr AllocateArrayCleared(USize elements, USize size, GFP flags) { var total = elements * size; var addr = Allocate(total, flags); MemoryOperation.Clear(addr, total); return(addr); }
/// <summary> /// Goto the next line. /// </summary> public static void NextLine() { Column = 0; if (row >= Rows - 1) { // Copy All rows one line up // TODO: Normally, Reading from mapped ROM is much slower // than reading from normal RAM. Consider using Offscreen Buffer MemoryOperation.Copy(ScreenMemoryAddress + Columns * 2, ScreenMemoryAddress, (Rows - 1) * Columns * 2); //Blank last line for (uint c = 0; c < Columns; c++) { RawWrite(row, c, ' ', color); } } else { Row++; } UpdateCursor(); }
public static void InitializeGCMemory() { // Wipe GCMemory from Bootloader Memory.InitialKernelProtect_MakeWritable_BySize(Address.GCInitialMemory, Address.GCInitialMemorySize); MemoryOperation.Clear4(Address.GCInitialMemory, Address.GCInitialMemorySize); }
unsafe static void SetupKernelSection() { // TODO: Respect section progream header adresses. // Currently, we can make a raw copy of ELF file MemoryOperation.Copy4(Address.OriginalKernelElfSection, Address.KernelElfSection, OriginalKernelElf.TotalFileSize); }