1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License").␉You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | /*␊ |
25 | * Copyright 1993 NeXT, Inc.␊ |
26 | * All rights reserved.␊ |
27 | */␊ |
28 | ␊ |
29 | #include "libsaio.h"␊ |
30 | #include "bootstruct.h"␊ |
31 | ␊ |
32 | #ifndef DEBUG_BOOTSTRUCT␊ |
33 | #define DEBUG_BOOTSTRUCT 0␊ |
34 | #endif␊ |
35 | ␊ |
36 | #if DEBUG_BOOTSTRUCT␊ |
37 | #define DBG(x...)␉printf(x)␊ |
38 | #else␊ |
39 | #define DBG(x...)␉msglog(x)␊ |
40 | #endif␊ |
41 | ␊ |
42 | /*==========================================================================␊ |
43 | * Initialize the structure of parameters passed to␊ |
44 | * the kernel by the booter.␊ |
45 | */␊ |
46 | ␊ |
47 | boot_args␉␉␉*bootArgs;␊ |
48 | boot_args_pre_lion␉*bootArgsPreLion;␊ |
49 | PrivateBootInfo_t␉*bootInfo;␊ |
50 | Node␉␉␉␉*gMemoryMapNode;␊ |
51 | ␊ |
52 | static char platformName[64];␊ |
53 | ␊ |
54 | void initKernBootStruct( void )␊ |
55 | {␊ |
56 | ␉Node *node;␊ |
57 | ␉int nameLen;␊ |
58 | ␉static int init_done = 0;␊ |
59 | ␉␊ |
60 | ␉if ( !init_done )␊ |
61 | ␉{␊ |
62 | ␉␉bootArgs = (boot_args *)malloc(sizeof(boot_args));␊ |
63 | ␉␉bootArgsPreLion = (boot_args_pre_lion *)malloc(sizeof(boot_args_pre_lion));␊ |
64 | ␉␉bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t));␊ |
65 | ␉␉if (bootArgs == 0 || bootArgsPreLion == 0 || bootInfo == 0)␊ |
66 | ␉␉␉stop("Couldn't allocate boot info\n");␊ |
67 | ␉␉␊ |
68 | ␉␉bzero(bootArgs, sizeof(boot_args));␊ |
69 | ␉␉bzero(bootArgsPreLion, sizeof(boot_args_pre_lion));␊ |
70 | ␉␉bzero(bootInfo, sizeof(PrivateBootInfo_t));␊ |
71 | ␉␉␊ |
72 | ␉␉// Get system memory map. Also update the size of the␊ |
73 | ␉␉// conventional/extended memory for backwards compatibility.␊ |
74 | ␉␉␊ |
75 | ␉␉bootInfo->memoryMapCount =␊ |
76 | ␉␉␉getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax,␊ |
77 | ␉␉␉␉␉␉ (unsigned long *) &bootInfo->convmem,␊ |
78 | ␉␉␉␉␉␉ (unsigned long *) &bootInfo->extmem );␊ |
79 | ␉␉␊ |
80 | ␉␉if ( bootInfo->memoryMapCount == 0 )␊ |
81 | ␉␉{␊ |
82 | ␉␉␉// BIOS did not provide a memory map, systems with␊ |
83 | ␉␉␉// discontiguous memory or unusual memory hole locations␊ |
84 | ␉␉␉// may have problems.␊ |
85 | ␉␉␉␊ |
86 | ␉␉␉bootInfo->convmem = getConventionalMemorySize();␊ |
87 | ␉␉␉bootInfo->extmem = getExtendedMemorySize();␊ |
88 | ␉␉}␊ |
89 | ␉␉␊ |
90 | ␉␉bootInfo->configEnd␉ = bootInfo->config;␊ |
91 | ␉␉bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
92 | ␉␉␊ |
93 | ␉␉DT__Initialize();␊ |
94 | ␉␉␊ |
95 | ␉␉node = DT__FindNode("/", true);␊ |
96 | ␉␉if (node == 0) {␊ |
97 | ␉␉␉stop("Couldn't create root node");␊ |
98 | ␉␉}␊ |
99 | ␉␉getPlatformName(platformName);␊ |
100 | ␉␉nameLen = strlen(platformName) + 1;␊ |
101 | ␉␉DT__AddProperty(node, "compatible", nameLen, platformName);␊ |
102 | ␉␉DT__AddProperty(node, "model", nameLen, platformName);␊ |
103 | ␉␉␊ |
104 | ␉␉gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);␊ |
105 | ␉␉␊ |
106 | ␉␉bootArgs->Version = kBootArgsVersion;␊ |
107 | ␉␉bootArgs->Revision = kBootArgsRevision;␊ |
108 | ␉␉␊ |
109 | ␉␉bootArgsPreLion->Version = kBootArgsPreLionVersion;␊ |
110 | ␉␉bootArgsPreLion->Revision = kBootArgsPreLionRevision;␊ |
111 | ␉␉␊ |
112 | ␉␉init_done = 1;␊ |
113 | ␉}␊ |
114 | }␊ |
115 | ␊ |
116 | ␊ |
117 | /* Copy boot args after kernel and record address. */␊ |
118 | ␊ |
119 | void␊ |
120 | reserveKernBootStruct(void)␊ |
121 | {␊ |
122 | ␉if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0')␊ |
123 | ␉␉&& (gMacOSVersion[2] == '.') && (gMacOSVersion[3] == '7' || gMacOSVersion[3] == '8' || gMacOSVersion[3] == '9'))␊ |
124 | ␉{␊ |
125 | ␉␉void *oldAddr = bootArgs;␊ |
126 | ␉␉bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));␊ |
127 | ␉␉bcopy(oldAddr, bootArgs, sizeof(boot_args));␊ |
128 | ␉}␊ |
129 | ␉else␊ |
130 | ␉{␊ |
131 | ␉␉void *oldAddr = bootArgsPreLion;␊ |
132 | ␉␉bootArgsPreLion = (boot_args_pre_lion *)AllocateKernelMemory(sizeof(boot_args_pre_lion));␊ |
133 | ␉␉bcopy(oldAddr, bootArgsPreLion, sizeof(boot_args_pre_lion));␊ |
134 | ␉}␊ |
135 | }␊ |
136 | ␊ |
137 | void␊ |
138 | finalizeBootStruct(void)␊ |
139 | {␊ |
140 | ␉uint32_t size;␊ |
141 | ␉void *addr;␊ |
142 | ␉int i;␊ |
143 | ␉EfiMemoryRange *memoryMap;␊ |
144 | ␉MemoryRange *range;␊ |
145 | ␉int memoryMapCount = bootInfo->memoryMapCount;␊ |
146 | ␉␊ |
147 | ␉if (memoryMapCount == 0) {␊ |
148 | ␉␉// XXX could make a two-part map here␊ |
149 | ␉␉stop("Unable to convert memory map into proper format\n");␊ |
150 | ␉}␊ |
151 | ␉␊ |
152 | ␉// convert memory map to boot_args memory map␊ |
153 | ␉memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);␊ |
154 | ␉bootArgs->MemoryMap = (uint32_t)memoryMap;␊ |
155 | ␉bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;␊ |
156 | ␉bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);␊ |
157 | ␉bootArgs->MemoryMapDescriptorVersion = 0;␊ |
158 | ␉␊ |
159 | ␉for (i = 0; i < memoryMapCount; i++, memoryMap++) {␊ |
160 | ␉␉range = &bootInfo->memoryMap[i];␊ |
161 | ␉␉switch(range->type) {␊ |
162 | ␉␉␉case kMemoryRangeACPI:␊ |
163 | ␉␉␉␉memoryMap->Type = kEfiACPIReclaimMemory;␊ |
164 | ␉␉␉␉break;␊ |
165 | ␉␉␉case kMemoryRangeNVS:␊ |
166 | ␉␉␉␉memoryMap->Type = kEfiACPIMemoryNVS;␊ |
167 | ␉␉␉␉break;␊ |
168 | ␉␉␉case kMemoryRangeUsable:␊ |
169 | ␉␉␉␉memoryMap->Type = kEfiConventionalMemory;␊ |
170 | ␉␉␉␉break;␊ |
171 | ␉␉␉case kMemoryRangeReserved:␊ |
172 | ␉␉␉default:␊ |
173 | ␉␉␉␉memoryMap->Type = kEfiReservedMemoryType;␊ |
174 | ␉␉␉␉break;␊ |
175 | ␉␉}␊ |
176 | ␉␉memoryMap->PhysicalStart = range->base;␊ |
177 | ␉␉memoryMap->VirtualStart = range->base;␊ |
178 | ␉␉memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;␊ |
179 | ␉␉memoryMap->Attribute = 0;␊ |
180 | ␉}␊ |
181 | ␉␊ |
182 | ␉// copy bootFile into device tree␊ |
183 | ␉// XXX␊ |
184 | ␉␊ |
185 | ␉// add PCI info somehow into device tree␊ |
186 | ␉// XXX␊ |
187 | ␉␊ |
188 | ␉// Flatten device tree␊ |
189 | ␉DT__FlattenDeviceTree(0, &size);␊ |
190 | ␉addr = (void *)AllocateKernelMemory(size);␊ |
191 | ␉if (addr == 0) {␊ |
192 | ␉␉stop("Couldn't allocate device tree\n");␊ |
193 | ␉}␊ |
194 | ␉␊ |
195 | ␉DT__FlattenDeviceTree((void **)&addr, &size);␊ |
196 | ␉bootArgs->deviceTreeP = (uint32_t)addr;␊ |
197 | ␉bootArgs->deviceTreeLength = size;␊ |
198 | ␊ |
199 | ␉// Copy BootArgs values to older structure␊ |
200 | ␉␊ |
201 | ␉memcpy(&bootArgsPreLion->CommandLine, &bootArgs->CommandLine, BOOT_LINE_LENGTH);␊ |
202 | ␉memcpy(&bootArgsPreLion->Video, &bootArgs->Video, sizeof(Boot_Video));␊ |
203 | ␉␊ |
204 | ␉bootArgsPreLion->MemoryMap = bootArgs->MemoryMap;␊ |
205 | ␉bootArgsPreLion->MemoryMapSize = bootArgs->MemoryMapSize;␊ |
206 | ␉bootArgsPreLion->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize;␊ |
207 | ␉bootArgsPreLion->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion;␊ |
208 | ␉␊ |
209 | ␉bootArgsPreLion->deviceTreeP = bootArgs->deviceTreeP;␊ |
210 | ␉bootArgsPreLion->deviceTreeLength = bootArgs->deviceTreeLength;␊ |
211 | ␉␊ |
212 | ␉bootArgsPreLion->kaddr = bootArgs->kaddr;␊ |
213 | ␉bootArgsPreLion->ksize = bootArgs->ksize;␊ |
214 | ␉␊ |
215 | ␉bootArgsPreLion->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart;␊ |
216 | ␉bootArgsPreLion->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount;␊ |
217 | ␉bootArgsPreLion->efiSystemTable = bootArgs->efiSystemTable;␊ |
218 | ␉␊ |
219 | ␉bootArgsPreLion->efiMode = bootArgs->efiMode;␊ |
220 | ␉␊ |
221 | ␉bootArgsPreLion->performanceDataStart = bootArgs->performanceDataStart;␊ |
222 | ␉bootArgsPreLion->performanceDataSize = bootArgs->performanceDataSize;␊ |
223 | ␉bootArgsPreLion->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart;␊ |
224 | }␊ |
225 | |