Esempio n. 1
0
        private void *mmap(uint unknown, uint flags, size_t pages)
        {
            var bytes = pages * 4096;
            var ptr   = (byte *)RawVirtualFrameAllocator.RequestRawVirtalMemoryPages(pages);

            //KernelMessage.WriteLine("mmap: Pages: {0}, Addr: {1:X8}", pages, (uint)ptr);
            for (var i = 0; i < bytes; i++)
            {
                *(ptr + i) = 0;
            }

            return(ptr);
        }
Esempio n. 2
0
        public unsafe static void Setup()
        {
            kmallocAllocator = new Allocator();

            var ptr = (byte *)RawVirtualFrameAllocator.RequestRawVirtalMemoryPages(KMath.AlignValueCeil(Allocator.headSize, 4096));

            for (var i = 0; i < Allocator.headSize; i++)
            {
                *(ptr + i) = 0;
            }
            kmallocAllocator.list_heads = (malloc_meta **)ptr;
            ManagedMemoy.useAllocator   = true;

            KernelMessage.WriteLine("Memory free: {0} MB", (PageFrameManager.PagesAvailable * 4096) / 1024 / 1024);
        }
Esempio n. 3
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();
        }