Ejemplo n.º 1
0
        public void Add(KernelMemoryMap map)
        {
            Assert.True(HasCapacity, "HasCapacity");

            Items[Count] = map;
            Count++;
        }
Ejemplo n.º 2
0
 public bool Intersects(KernelMemoryMap map)
 {
     for (var i = 0; i < Count; i++)
     {
         if (Items[i].Intersects(map))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 3
0
 public bool Contains(KernelMemoryMap map)
 {
     for (var i = 0; i < Count; i++)
     {
         if (Items[i].ContainsMap(map))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
        public static void Setup()
        {
            var addr = Initial_FindFreePage();

            KernelMessage.Path("KernelMemoryMapManager", "Initial Page: {0:X}", addr);
            PageTable.KernelTable.Map(addr, addr, flush: true);

            // 80KB should be enough
            // TODO: Check if really 80KB are available after this address.
            InitialMap = new KernelMemoryMap(addr, 0x1000 * 20, BootInfoMemoryType.KernelMemoryMap, AddressSpaceKind.Both);
            PageTable.KernelTable.Map(InitialMap.Start, InitialMap.Start, InitialMap.Size, flush: true);
            PageTable.KernelTable.SetWritable(InitialMap.Start, InitialMap.Size);

            Header = (KernelMemoryMapHeader *)InitialMap.Start;

            var arrayOffset1 = 0x1000;
            var arrayOffset2 = 0x2000;
            var arrayOffset3 = 0x3000;

            Header->SystemUsable   = new KernelMemoryMapArray((KernelMemoryMap *)(InitialMap.Start + arrayOffset1), 50);
            Header->Used           = new KernelMemoryMapArray((KernelMemoryMap *)(InitialMap.Start + arrayOffset2), 100);
            Header->KernelReserved = new KernelMemoryMapArray((KernelMemoryMap *)(InitialMap.Start + arrayOffset3), 100);

            for (uint i = 0; i < BootInfo.Header->MemoryMapLength; i++)
            {
                var map  = BootInfo.Header->MemoryMapArray[i];
                var kmap = new KernelMemoryMap(map.Start, map.Size, map.Type, map.AddressSpaceKind);
                if (kmap.Type == BootInfoMemoryType.SystemUsable)
                {
                    Header->SystemUsable.Add(kmap);
                }
                else
                {
                    if (kmap.Type == BootInfoMemoryType.KernelReserved)
                    {
                        Header->KernelReserved.Add(kmap);
                    }
                    else
                    {
                        Header->Used.Add(kmap);
                    }
                }
            }
            Header->Used.Add(InitialMap);

            KernelMessage.Path("KernelMemoryMapManager", "Filling Lists Done. SystemUsable: {0}, CustomReserved: {1}, Used: {2}", Header->SystemUsable.Count, Header->KernelReserved.Count, Header->Used.Count);
            PrintMapArrays();

            //Debug_FillAvailableMemory();
        }
Ejemplo n.º 5
0
        public static KernelMemoryMap Allocate(USize size, BootInfoMemoryType type, AddressSpaceKind addressSpaceKind)
        {
            var cnt = Header->Used.Count;

            for (uint i = 0; i < cnt; i++)
            {
                var map = Header->Used.Items[i];
                if (CheckPageIsUsableAfterMap(map, size, addressSpaceKind))
                {
                    var newMap = new KernelMemoryMap(map.Start + map.Size, size, type, addressSpaceKind);
                    Header->Used.Add(newMap);
                    KernelMessage.Path("KernelMemoryMapManager", "Allocated: at {0:X8}, size {1:X8}, type {2}", newMap.Start, size, (uint)type);
                    return(newMap);
                }
            }
            return(KernelMemoryMap.Empty);
        }
Ejemplo n.º 6
0
        private static bool CheckPageIsUsableAfterMap(KernelMemoryMap map, USize size, AddressSpaceKind addressSpaceKind)
        {
            var tryMap = new KernelMemoryMap(map.Start + map.Size, size, BootInfoMemoryType.Unknown, addressSpaceKind);

            if (Header->Used.Intersects(tryMap))
            {
                return(false);
            }

            if (Header->KernelReserved.Intersects(tryMap))
            {
                return(false);
            }

            if (!Header->SystemUsable.Contains(tryMap))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 7
0
 public bool Intersects(KernelMemoryMap map)
 {
     return(ContainsAddr(map.Start) || ContainsAddr(map.Start + map.Size));
 }
Ejemplo n.º 8
0
 public bool ContainsMap(KernelMemoryMap map)
 {
     return(Start <= map.Start && map.Start + map.Size < Start + Size);
 }