Пример #1
0
        public virtual void Setup(MemoryRegion region, AddressSpaceKind addressSpaceKind)
        {
            AddressSpaceKind = addressSpaceKind;
            region.Size      = KMath.FloorToPowerOfTwo(region.Size);
            _Region          = region;
            var totalPages = region.Size >> BuddyAllocatorImplementation.BUDDY_PAGE_SHIFT;

            KernelMessage.WriteLine("Init Allocator: StartAddr: {0}, {1} Pages", region.Start, totalPages);
            // init global memory block
            // all pages area
            var pages_size = totalPages * (uint)sizeof(Page);

            KernelMessage.WriteLine("Page Array Size in bytes: {0}", pages_size);
            Pages = (Page *)AllocRawMemory(pages_size).Start;
            KernelMessage.WriteLine("Page Array Addr: {0:X8}", (uint)Pages);
            var start_addr = region.Start;

            Zone.free_area = (BuddyAllocatorImplementation.free_area *)AllocRawMemory(BuddyAllocatorImplementation.BUDDY_MAX_ORDER * (uint)sizeof(BuddyAllocatorImplementation.free_area)).Start;

            fixed(BuddyAllocatorImplementation.mem_zone *zone = &Zone)
            ZonePtr = zone;

            BuddyAllocatorImplementation.buddy_system_init(
                ZonePtr,
                Pages,
                start_addr,
                totalPages);
        }