+void
+finalizeBootStruct(void)
+{
+ uint32_t size;
+ void *addr;
+ int i;
+ EfiMemoryRange *memoryMap;
+ MemoryRange *range;
+ int memoryMapCount = bootInfo->memoryMapCount;
+
+ if (memoryMapCount == 0) {
+ // XXX could make a two-part map here
+ stop("Unable to convert memory map into proper format\n");
+ }
+
+ // convert memory map to boot_args memory map
+ memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
+ bootArgs->MemoryMap = memoryMap;
+ bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
+ bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
+ bootArgs->MemoryMapDescriptorVersion = 0;
+
+ for (i=0; i<memoryMapCount; i++, memoryMap++) {
+ range = &bootInfo->memoryMap[i];
+ switch(range->type) {
+ case kMemoryRangeACPI:
+ memoryMap->Type = kEfiACPIReclaimMemory;
+ break;
+ case kMemoryRangeNVS:
+ memoryMap->Type = kEfiACPIMemoryNVS;
+ break;
+ case kMemoryRangeUsable:
+ memoryMap->Type = kEfiConventionalMemory;
+ break;
+ case kMemoryRangeReserved:
+ default:
+ memoryMap->Type = kEfiReservedMemoryType;
+ break;
+ }
+ memoryMap->PhysicalStart = range->base;
+ memoryMap->VirtualStart = range->base;
+ memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;
+ memoryMap->Attribute = 0;
+ }
+
+ // copy bootFile into device tree
+ // XXX
+
+ // add PCI info somehow into device tree
+ // XXX
+
+ // Flatten device tree
+ DT__FlattenDeviceTree(0, &size);
+ addr = (void *)AllocateKernelMemory(size);
+ if (addr == 0) {
+ stop("Couldn't allocate device tree\n");
+ }
+
+ DT__FlattenDeviceTree((void **)&addr, &size);
+ bootArgs->deviceTreeP = (void *)addr;
+ bootArgs->deviceTreeLength = size;
+}