예제 #1
0
        public static void Setup()
        {
            NormalAllocator = CreateAllocatorStage1();
            NormalAllocator = CreateAllocatorStage2();

            var allocator2 = new VirtualInitialPageAllocator(false)
            {
                DebugName = "VirtIdentityInitial"
            };

            allocator2.Setup(new MemoryRegion(Address.IdentityMapStart, 60 * 1024 * 1024), AddressSpaceKind.Virtual);
            IdentityAllocator = allocator2;

            var allocator3 = new VirtualInitialPageAllocator(false)
            {
                DebugName = "GlobalInitial"
            };

            allocator3.Setup(new MemoryRegion(600 * 1024 * 1024, 100 * 1024 * 1024), AddressSpaceKind.Virtual);
            GlobalAllocator = allocator3;

            PhysicalPageManager.SelfTest();
            SelfTest(NormalAllocator);
            SelfTest(IdentityAllocator);
        }
예제 #2
0
        //private static Addr _startVirtAddr;
        //private static Addr _nextVirtAddr;

        //private static Addr _identityStartVirtAddr;
        //private static Addr _identityNextVirtAddr;

        public static void Setup()
        {
            //_startVirtAddr = Address.VirtMapStart;
            //_nextVirtAddr = _startVirtAddr;

            //lockObj = new object();
            //LockCount = 0;

            NormalAllocator = CreateAllocatorStage1();
            NormalAllocator = CreateAllocatorStage2();

            //_identityStartVirtAddr = Address.IdentityMapStart;
            //_identityNextVirtAddr = _identityStartVirtAddr;

            var allocator2 = new VirtualInitialPageAllocator(false)
            {
                DebugName = "VirtIdentityInitial"
            };

            allocator2.Setup(new MemoryRegion(Address.IdentityMapStart, 60 * 1024 * 1024), AddressSpaceKind.Virtual);
            IdentityAllocator = allocator2;

            var allocator3 = new VirtualInitialPageAllocator(false)
            {
                DebugName = "GlobalInitial"
            };

            allocator3.Setup(new MemoryRegion(600 * 1024 * 1024, 100 * 1024 * 1024), AddressSpaceKind.Virtual);
            GlobalAllocator = allocator3;

            PhysicalPageManager.SelfTest();
            SelfTest(NormalAllocator);
            SelfTest(IdentityAllocator);
        }
예제 #3
0
        private static unsafe void FreeAddrGlobal(Addr addr)
        {
            var physAddr = PageTable.KernelTable.GetPhysicalAddressFromVirtual(addr);

            if (AddProtectedRegions)
            {
                addr -= 4096;
            }
            GlobalAllocator.FreeAddr(addr);
            PhysicalPageManager.FreeAddr(physAddr);

            PageTable.KernelTable.UnMap(addr);
        }
예제 #4
0
        private static unsafe Addr AllocateGlobalPages(uint pages, AllocatePageOptions options = default)
        {
            if (AddProtectedRegions)
            {
                pages += 2;
            }

            //lock (lockObj)
            //{
            //    LockCount++;
            var physHead = PhysicalPageManager.AllocatePages(pages, options);

            if (physHead == null)
            {
                return(Addr.Zero);
            }
            var virtHead = GlobalAllocator.AllocatePages(pages, options);

            var p = physHead;
            var v = virtHead;

            for (var i = 0; i < pages; i++)
            {
                var map = true;
                if (AddProtectedRegions && (i == 0 || i == pages - 1))
                {
                    map = false;
                }

                if (map)
                {
                    PageTable.KernelTable.Map(GlobalAllocator.GetAddress(v), PhysicalPageManager.GetAddress(p));
                }

                p = PhysicalPageManager.NextCompoundPage(p);
                v = GlobalAllocator.NextCompoundPage(v);
            }
            PageTable.KernelTable.Flush();

            if (AddProtectedRegions)
            {
                virtHead = GlobalAllocator.NextCompoundPage(virtHead);
            }

            //LockCount--;
            return(GlobalAllocator.GetAddress(virtHead));
            //}
        }
예제 #5
0
        private static unsafe void SelfTest(IPageFrameAllocator allocator)
        {
            if (SelfTestDump)
            {
                allocator.DumpPages();
            }

            KernelMessage.WriteLine("Begin SelfTest {0}", allocator.DebugName);

            var ptrPages       = (allocator.TotalPages * 4) / 4096;
            var ptrListAddr    = AllocatePages(ptrPages); // pointers for 4GB of pages
            var ptrList        = (Addr *)ptrListAddr;
            var checkPageCount = allocator.FreePages;

            checkPageCount -= allocator.CriticalLowPages;
            uint checkPagesEach = 4;

            checkPageCount /= checkPagesEach;
            //checkPageCount = 32;
            var mapPhysAddr = PhysicalPageManager.AllocatePageAddr(checkPagesEach);

            for (var i = 0; i < checkPageCount; i++)
            {
                if (SelfTestDump)
                {
                    KernelMessage.Write(".");
                }
                var testAddr = allocator.AllocatePagesAddr(checkPagesEach);
                ptrList[i] = testAddr;
                //KernelMessage.WriteLine("{0:X8}-->{1:X8}", testAddr, mapPhysAddr);
                PageTable.KernelTable.Map(testAddr, mapPhysAddr, 4096 * checkPagesEach, true, true);
                var mapPtr = (uint *)testAddr;
                for (var pos = 0; pos < 1024 * checkPagesEach; pos++)
                {
                    *mapPtr = 0xEBFEEBFE;
                    mapPtr += 1;
                }
                PageTable.KernelTable.UnMap(testAddr, 4096 * checkPagesEach, true);
                //Default.Free(testPage);
            }
            PhysicalPageManager.FreeAddr(mapPhysAddr);

            if (SelfTestDump)
            {
                allocator.DumpPages();
            }

            KernelMessage.WriteLine("Free Pages now");
            for (var i = 0; i < checkPageCount; i++)
            {
                if (SelfTestDump)
                {
                    KernelMessage.Write(":");
                }
                var testAddr = ptrList[i];
                //KernelMessage.WriteLine("Free: {0:X8}", testAddr);

                allocator.FreeAddr(testAddr);
            }
            KernelMessage.WriteLine("Free ptrList");
            FreeAddr(ptrListAddr);

            KernelMessage.WriteLine("SelfTest Done");
            if (SelfTestDump)
            {
                allocator.DumpPages();
                KernelMessage.WriteLine("Final Dump");
            }
        }