/// <summary> /// Get the Memory Map Information from Multiboot /// </summary> /// <returns>Returns an array of MemoryMaps containing the Multiboot Memory Map information. The array may have empty values at the end.</returns> public static unsafe MemoryMap[] GetMemoryMap() { if (!Multiboot2.MemoryMapExists()) { throw new Exception("No Memory Map was returned by Multiboot"); } var rawMap = new RawMemoryMap[64]; var baseMap = (RawMemoryMap *)((uint *)Multiboot2.MemoryMap + (uint)16); var currentMap = baseMap; uint totalSize = Multiboot2.MemoryMap->Size - 16; uint entrySize = Multiboot2.MemoryMap->EntrySize; int counter = 0; while ((uint)currentMap < ((uint)baseMap + totalSize) && counter < 64) { rawMap[counter++] = *currentMap; currentMap = (RawMemoryMap *)((uint)currentMap + entrySize); } if (counter >= 64) { throw new Exception("Memory Map returned too many segments"); } var entireMap = new MemoryMap[counter]; for (int i = 0; i < counter; i++) { var rawMemoryMap = rawMap[i]; entireMap[i] = new MemoryMap { Address = rawMemoryMap.Address, Length = rawMemoryMap.Length, Type = rawMemoryMap.Type }; } return(entireMap); }
/// <summary> /// Get the Memory Map Information from Multiboot /// </summary> /// <returns>Returns an array of MemoryMaps containing the Multiboot Memory Map information. The array may have empty values at the end.</returns> public static unsafe MemoryMap[] GetMemoryMap() { if (!MemoryMapExists()) { throw new Exception("No Memory Map was returned by Multiboot"); } var rawMap = new RawMemoryMap[64]; //var currentMap = (RawMemoryMap*)false; int counter = 0; /*while ((uint)currentMap < (Bootstrap.MultibootHeader->memMapAddress + Bootstrap.MultibootHeader->memMapLength) && counter < 64) * { * rawMap[counter++] = *currentMap; * currentMap = (RawMemoryMap*)((uint*)currentMap + ((currentMap->Size + 4 )>> 2)); //The size is in bits, not bytes * if (currentMap->Size == 0) * { * break; * } * }*/ if (counter >= 64) { throw new Exception("Memory Map returned too many segments"); } var entireMap = new MemoryMap[counter]; for (int i = 0; i < counter; i++) { var rawMemoryMap = rawMap[i]; entireMap[i] = new MemoryMap { Address = (ulong)rawMemoryMap.HighBaseAddr << 32 | rawMemoryMap.LowBaseAddr, Length = (ulong)rawMemoryMap.HighLength << 32 | rawMemoryMap.LowLength, Type = rawMemoryMap.Type }; } return(entireMap); }