/// <summary>
        /// Returns raw, unmanaged Memory.
        /// Consumer: Kernel, Memory allocators
        /// Shoud be used for larger Chunks.
        /// </summary>
        internal unsafe static Addr RequestRawVirtalMemoryPages(uint pages)
        {
            Addr virt = _nextVirtAddr;
            var  head = PageFrameManager.AllocatePages(PageFrameRequestFlags.Default, pages);

            if (head == null)
            {
                return(Addr.Zero);
            }

            var p = head;

            for (var i = 0; i < pages; i++)
            {
                PageTable.MapVirtualAddressToPhysical(_nextVirtAddr, p->PhysicalAddress);
                _nextVirtAddr += 4096;
                p              = p->Next;
            }
            return(virt);
        }
예제 #2
0
        public unsafe static void Main()
        {
            BootInfo.SetupStage1();

            // Field needs to be explicit set, because InitializeAssembly is not invoked yet.
            Memory.UseKernelWriteProtection = true;
            Memory.InitialKernelProtect();

            ManagedMemoy.InitializeGCMemory();
            Mosa.Runtime.StartUp.InitializeAssembly();
            //Mosa.Runtime.StartUp.InitializeRuntimeMetadata();

            ApiContext.Current = new ApiHost();

            // Setup some pseudo devices
            Devices.InitStage1();

            //Setup Output and Debug devices
            Devices.InitStage2();

            // Write first output
            KernelMessage.WriteLine("<KERNEL:CONSOLE:BEGIN>");
            KernelMessage.WriteLine("Starting Lonos Kernel...");

            // 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 conecept code)
            NativeCalls.Setup();

            //InitialKernelProtect();

            PageFrameManager.Setup();

            KernelMessage.WriteLine("free: {0}", PageFrameManager.PagesAvailable);
            PageFrameManager.AllocatePages(PageFrameRequestFlags.Default, 10);
            KernelMessage.WriteLine("free: {0}", PageFrameManager.PagesAvailable);
            RawVirtualFrameAllocator.Setup();

            Memory.Setup();

            // Now Memory Sub System is working. At this point it's valid
            // to allocate memory dynamicly

            Devices.InitFrameBuffer();

            // Setup Programmable Interrupt Table
            PIC.Setup();

            // Setup Interrupt Descriptor Table
            // Important Note: IDT depends on GDT. Never setup IDT before GDT.
            IDTManager.Setup();

            KernelMessage.WriteLine("Initialize Runtime Metadata");
            Mosa.Runtime.StartUp.InitializeRuntimeMetadata();

            KernelMessage.WriteLine("Performing some tests");
            Tests();

            KernelMessage.WriteLine("Enter Main Loop");
            AppMain();
        }