protected override MemoryRegion AllocRawMemory(uint size) { var kmap = PhysicalPageManager.AllocateRegion(size); KernelMemoryMapManager.Header->Used.Add(new KernelMemoryMap(kmap.Start, kmap.Size, BootInfoMemoryType.PageFrameAllocator, AddressSpaceKind.Virtual)); PageTable.KernelTable.Map(kmap.Start, kmap.Start, PhysicalPageManager.GetAllocatorByAddr(kmap.Start), flush: true); PageTable.KernelTable.SetWritable(kmap.Start, kmap.Size); kmap.Clear(); return(kmap); }
private static unsafe void InitControlBlock() { var p = PhysicalPageManager.AllocatePageAddr(new AllocatePageOptions { Continuous = true }); PageTable.KernelTable.Map(Address.InterruptControlBlock, p, 4096, flush: true); PageTable.KernelTable.SetWritable(Address.InterruptControlBlock, 4096); ControlBlock = (InterruptControlBlock *)Address.InterruptControlBlock; ControlBlock->KernelPageTableAddr = PageTable.KernelTable.GetPageTablePhysAddr(); }
private static uint Cmd_RequestMemory(SysCallContext *context, SystemMessage *args) { var size = args->Arg1; size = KMath.AlignValueCeil(size, 4096); var proc = Scheduler.GetCurrentThread().Process; var map = PhysicalPageManager.AllocateRegion(size); var virtAddr = proc.UserPageAllocator.AllocatePagesAddr(size / 4096); Scheduler.GetCurrentThread().Process.PageTable.Map(virtAddr, map.Start, PhysicalPageManager.GetAllocatorByAddr(map.Start)); return(virtAddr); }
internal static uint Sbrk(ref SysCallContext context, ref SystemMessage args) { var size = args.Arg1; //size = KMath.AlignValueCeil(size, 4096); var proc = Scheduler.GetCurrentThread().Process; if (proc.CurrentBrk == 0) { proc.CurrentBrk = proc.BrkBase; //size -= proc.BrkBase; //size -= 0x70000000; } KernelMessage.WriteLine("sbrk({0:X8}). Current={1:X8} New={2:X8}", size, proc.CurrentBrk, proc.CurrentBrk + size); var procTable = Scheduler.GetCurrentThread().Process.PageTable; var region = MemoryRegion.FromLocation(proc.CurrentBrk, proc.CurrentBrk + size); region = region.FitToPageFloor(); var pages = region.Size / 4096; var virtAddr = region.Start; for (var i = 0; i < pages; i++) { if (!procTable.IsMapped(virtAddr)) { KernelMessage.WriteLine("sbrk: Map {0:X8}", virtAddr); var p = PhysicalPageManager.AllocatePageAddr(); procTable.Map(virtAddr, p); } else { KernelMessage.WriteLine("sbrk: Map {0:X8}: Already mapped", virtAddr); } virtAddr += 4096; } proc.CurrentBrk += size; KernelMessage.WriteLine("new brk: {0:X8}", proc.CurrentBrk); return(proc.CurrentBrk - size); }
public static unsafe void Main() { try { ManagedMemoy.InitializeGCMemory(); StartUp.InitializeAssembly(); KMath.Init(); //Mosa.Runtime.StartUp.InitializeRuntimeMetadata(); BootInfo.SetupStage1(); Memory.InitialKernelProtect(); ApiContext.Current = new ApiHost(); Assert.Setup(AssertError); // Setup some pseudo devices DeviceManager.InitStage1(); //Setup Output and Debug devices DeviceManager.InitStage2(); // Write first output KernelMessage.WriteLine("<KERNEL:CONSOLE:BEGIN>"); PerformanceCounter.Setup(BootInfo.Header->KernelBootStartCycles); KernelMessage.WriteLine("Starting Abanu Kernel..."); KernelMessage.WriteLine("KConfig.UseKernelMemoryProtection: {0}", KConfig.UseKernelMemoryProtection); KernelMessage.WriteLine("KConfig.UsePAE: {0}", KConfig.UsePAE); KernelMessage.WriteLine("Apply PageTableType: {0}", (uint)BootInfo.Header->PageTableType); KernelMessage.WriteLine("GCInitialMemory: {0:X8}-{1:X8}", Address.GCInitialMemory, Address.GCInitialMemory + Address.GCInitialMemorySize - 1); Ulongtest1(); Ulongtest2(); InlineTest(); // Detect environment (Memory Maps, Video Mode, etc.) BootInfo.SetupStage2(); KernelMemoryMapManager.Setup(); //KernelMemoryMapManager.Allocate(0x1000 * 1000, BootInfoMemoryType.PageDirectory); // Read own ELF-Headers and Sections KernelElf.Setup(); // Initialize the embedded code (actually only a little proof of concept code) NativeCalls.Setup(); //InitialKernelProtect(); PhysicalPageManager.Setup(); KernelMessage.WriteLine("Phys free: {0}", PhysicalPageManager.FreePages); PhysicalPageManager.AllocatePages(10); KernelMessage.WriteLine("Phys free: {0}", PhysicalPageManager.FreePages); VirtualPageManager.Setup(); Memory.Setup(); // Now Memory Sub System is working. At this point it's valid // to allocate memory dynamically DeviceManager.InitFrameBuffer(); // Setup Programmable Interrupt Table PIC.Setup(); // Setup Interrupt Descriptor Table // Important Note: IDT depends on GDT. Never setup IDT before GDT. IDTManager.Setup(); InitializeUserMode(); SysCallManager.Setup(); KernelMessage.WriteLine("Initialize Runtime Metadata"); StartUp.InitializeRuntimeMetadata(); KernelMessage.WriteLine("Performing some Non-Thread Tests"); Tests(); } catch (Exception ex) { Panic.Error(ex.Message); } if (KConfig.SingleThread) { StartupStage2(); } else { ProcessManager.Setup(StartupStage2); } }
private static void KeyF3() { //PhysicalPageManager.DumpPages(); PhysicalPageManager.DumpStats(); VirtualPageManager.DumpStats(); }
public static unsafe void TestPhysicalPageAllocation() { KernelMessage.WriteLine("Phys free: {0}", PhysicalPageManager.FreePages); PhysicalPageManager.AllocatePages(10); KernelMessage.WriteLine("Phys free: {0}", PhysicalPageManager.FreePages); }