Example #1
0
		internal static void Initialize(MultibootHeader* pMultibootHeader)
		{
			int memoryMapCount = (int)(pMultibootHeader->MemoryMapsSize / sizeof(MultibootMemoryMap));
			ulong lastMemoryMapAddress = pMultibootHeader->MemoryMaps[memoryMapCount - 1].AddressLower | ((ulong)pMultibootHeader->MemoryMaps[memoryMapCount - 1].AddressUpper << 32);
			ulong lastMemoryMapLength = pMultibootHeader->MemoryMaps[memoryMapCount - 1].LengthLower | ((ulong)pMultibootHeader->MemoryMaps[memoryMapCount - 1].LengthUpper << 32);
			ulong totalMemory = lastMemoryMapAddress + lastMemoryMapLength;
			if (totalMemory < MinimumTotalMemory) Panic();
			ulong totalMemoryHighestBit = 0;
			int totalMemoryHighestBitShiftOff = 0;
			for (int bit = 63; bit >= 0; --bit)
			{
				++totalMemoryHighestBitShiftOff;
				if ((totalMemory & ((ulong)1 << bit)) != 0)
				{
					totalMemoryHighestBit = (ulong)1 << bit;
					break;
				}
			}
			if ((totalMemory << totalMemoryHighestBitShiftOff) != 0) totalMemoryHighestBit <<= 1;
			int shiftsForTotalMemory = 64 - totalMemoryHighestBitShiftOff;
			TreeLevels = (byte)((shiftsForTotalMemory - ShiftsForMinimumPageSize) + 1);
			ulong bytesRequiredForTree = ((ulong)1 << TreeLevels) >> 3;
			ulong treeStartAddress = pMultibootHeader->Modules[pMultibootHeader->ModulesCount - 1].End;
			if ((treeStartAddress & 0x03) != 0) treeStartAddress += 4 - (treeStartAddress & 0x03);
			Tree = (uint*)treeStartAddress;
			ulong treeElementCount = bytesRequiredForTree >> 2;
			for (ulong index = 0; index < treeElementCount; ++index) Tree[index] = 0;

			SetBitsInTree((byte)(TreeLevels - 1), 0, (treeStartAddress + (treeElementCount << 2)) >> ShiftsForMinimumPageSize, true);

			MultibootMemoryMap* memoryMap = null;
			ulong memoryMapAddress = 0;
			ulong memoryMapLength = 0;
			for (int memoryMapIndex = 0; memoryMapIndex < memoryMapCount; ++memoryMapIndex)
			{
				memoryMap = &pMultibootHeader->MemoryMaps[memoryMapIndex];
				if (memoryMap->Type != 1)
				{
					memoryMapAddress = memoryMap->AddressLower | ((ulong)memoryMap->AddressUpper << 32);
					memoryMapLength = memoryMap->LengthLower | ((ulong)memoryMap->LengthUpper << 32);
					SetBitsInTree((byte)(TreeLevels - 1), memoryMapAddress >> ShiftsForMinimumPageSize, memoryMapLength >> ShiftsForMinimumPageSize, true);
				}
			}

			ulong lengthOfOutOfBoundsMemory = totalMemoryHighestBit - totalMemory;
			if (lengthOfOutOfBoundsMemory > 0) SetBitsInTree((byte)(TreeLevels - 1), totalMemory >> ShiftsForMinimumPageSize, lengthOfOutOfBoundsMemory >> ShiftsForMinimumPageSize, true);
		}
Example #2
0
 internal static void Initialize(uint pMultibootMagic, MultibootHeader* pMultibootHeader)
 {
     //sUsableMemory = usableMemory;
 }