public static void EntryPoint() { Console.SetBackground(ConsoleColor.Blue); Console.SetForground(ConsoleColor.White); Console.ClearScreen(); Console.Write("Booting..."); BootPageAllocator.Setup(); Console.Write("1..."); BootMemoryMap.Initialize(); Console.Write("3..."); BootMemoryMap.ImportPlatformMemoryMap(); Console.Write("2..."); BootMemoryMap.ImportMultibootV1MemoryMap(); BootMemoryMap.Dump(); Console.Write("4..."); PhysicalPageAllocator.Setup(); Console.Write("5..."); PageTable.Setup(); Console.Write("6..."); while (true) { } }
public static void EntryPoint() { Platform.EntryPoint(); Console.SetBackground(ConsoleColor.Blue); Console.SetForground(ConsoleColor.White); Console.ClearScreen(); Console.Write("Booting..."); BootPageAllocator.Setup(); Console.Write("1..."); BootMemoryMap.Initialize(); Console.Write("2..."); Platform.UpdateBootMemoryMap(); Console.Write("3..."); BootMemoryMap.ImportMultibootV1MemoryMap(); Console.Write("4..."); //PhysicalPageAllocator.Setup(); // TODO: PageFrameAllocator --- allocates single pages only PageTable.Setup(); Console.Write("5..."); while (true) { } }
public static void EntryPoint() { Platform.EntryPoint(); BootMemoryMap.Initialize(); Platform.UpdateBootMemoryMap(); ImportMultibootMemoryMap(); }
private static void ImportMultibootMemoryMap() { if (!Multiboot.IsAvailable) { return; } if (Multiboot.MultibootV1.MemoryMapStart.IsNull()) { return; } var memoryMapEnd = Multiboot.MultibootV1.MemoryMapStart + (int)Multiboot.MultibootV1.MemoryMapLength; var entry = new MultibootV1MemoryMapEntry(Multiboot.MultibootV1.MemoryMapStart); while (entry.IsAvailable) { BootMemoryMap.SetMemoryMap(entry.BaseAddr, entry.Length, entry.Type == 1 ? BootMemoryMapType.Available : BootMemoryMapType.Reserved); entry = entry.GetNext(memoryMapEnd); } }
public static void Setup() { BitMapIndexTable = new BitMapIndexTable(BootPageAllocator.AllocatePage()); var maximumMemoryAddress = BootMemoryMap.GetMaximumAddress(); TotalPages = (uint)(maximumMemoryAddress.ToInt64() / Page.Size); var bitMapCount = TotalPages / (Page.Size * 8); for (uint i = 0; i < bitMapCount; i++) { var bitmap = BootPageAllocator.AllocatePage(); Page.ClearPage(bitmap); BitMapIndexTable.AddBitMapEntry(i, bitmap); } var entries = BootMemoryMap.GetBootMemoryMapEntryCount(); // pass 0 - mark available pages for (uint i = 0; i < entries; i++) { var entry = BootMemoryMap.GetBootMemoryMapEntry(i); if (!entry.IsAvailable) { continue; } var start = Alignment.AlignUp(entry.StartAddress.ToInt64(), Page.Size); var end = Alignment.AlignDown(entry.EndAddress.ToInt64() + 1, Page.Size); var pages = (uint)(end - start) / Page.Size; if (pages <= 0) { continue; } var startPage = (uint)(start / Page.Shift); var endPage = startPage + pages - 1; MinimumAvailablePage = Math.Min(MinimumAvailablePage, startPage); MaximumAvailablePage = Math.Max(MaximumAvailablePage, endPage); SetPageBitMapEntry(startPage, pages, entry.IsAvailable); } // pass 1 - unmark reserved pages for (uint i = 0; i < entries; i++) { var entry = BootMemoryMap.GetBootMemoryMapEntry(i); if (entry.IsAvailable) { continue; } var start = Alignment.AlignUp(entry.StartAddress.ToInt64(), Page.Size); var end = Alignment.AlignDown(entry.EndAddress.ToInt64() + 1, Page.Size); var pages = (uint)(end - start) / Page.Size; if (pages <= 0) { continue; } var startPage = (uint)(start / Page.Shift); var endPage = startPage + pages - 1; MinimumReservedPage = Math.Min(MinimumReservedPage, startPage); MaximumReservedPage = Math.Max(MaximumReservedPage, endPage); if (MinimumAvailablePage >= startPage && MinimumAvailablePage <= endPage) { MinimumAvailablePage = endPage + 1; } if (MaximumAvailablePage >= startPage && MaximumAvailablePage <= endPage) { MaximumAvailablePage = startPage - 1; } SetPageBitMapEntry(startPage, pages, entry.IsAvailable); } SearchNextStartPage = MinimumAvailablePage; }
public static void UpdateBootMemoryMap() { // Reserve the first 1MB BootMemoryMap.SetMemoryMap(new Pointer(0), 1024 * 1024, BootMemoryMapType.Reserved); }