Exemple #1
0
        /// <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;
                }
            }
        }
Exemple #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();
        }