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 "boot.h"␊ |
31 | #include "bootstruct.h"␊ |
32 | ␊ |
33 | #ifndef DEBUG_BOOTSTRUCT␊ |
34 | ␉#define DEBUG_BOOTSTRUCT 0␊ |
35 | #endif␊ |
36 | ␊ |
37 | #if DEBUG_BOOTSTRUCT␊ |
38 | ␉#define DBG(x...)␉printf(x)␊ |
39 | #else␊ |
40 | ␉#define DBG(x...)␉msglog(x)␊ |
41 | #endif␊ |
42 | ␊ |
43 | /*==========================================================================␊ |
44 | * Initialize the structure of parameters passed to␊ |
45 | * the kernel by the booter.␊ |
46 | */␊ |
47 | ␊ |
48 | boot_args␉␉*bootArgs␉= NULL;␊ |
49 | boot_args_legacy␉*bootArgsLegacy␉= NULL;␊ |
50 | ␊ |
51 | PrivateBootInfo_t␉*bootInfo␉= NULL;␊ |
52 | Node␉␉␉*gMemoryMapNode;␊ |
53 | ␊ |
54 | static char platformName[64];␊ |
55 | ␊ |
56 | void initKernBootStruct( void )␊ |
57 | {␊ |
58 | ␉Node *node;␊ |
59 | ␉int nameLen;␊ |
60 | ␊ |
61 | ␉static int init_done = 0;␊ |
62 | ␊ |
63 | ␉if ( !init_done )␊ |
64 | ␉{␊ |
65 | ␉␉bootArgs = (boot_args *)malloc(sizeof(boot_args));␊ |
66 | ␉␉bootArgsLegacy = (boot_args_legacy *)malloc(sizeof(boot_args_legacy));␊ |
67 | ␉␉bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t));␊ |
68 | ␊ |
69 | ␉␉if (bootArgs == 0 || bootArgsLegacy == 0 || bootInfo == 0)␊ |
70 | ␉␉{␊ |
71 | ␉␉␉stop("Couldn't allocate boot info\n");␊ |
72 | ␉␉}␊ |
73 | ␊ |
74 | ␉␉bzero(bootArgs, sizeof(boot_args));␊ |
75 | ␉␉bzero(bootArgsLegacy, sizeof(boot_args_legacy));␊ |
76 | ␉␉bzero(bootInfo, sizeof(PrivateBootInfo_t));␊ |
77 | ␊ |
78 | ␉␉// Get system memory map. Also update the size of the␊ |
79 | ␉␉// conventional/extended memory for backwards compatibility.␊ |
80 | ␊ |
81 | ␉␉bootInfo->memoryMapCount =␊ |
82 | ␉␉␉getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax,␊ |
83 | ␉␉␉␉␉␉ (unsigned long *) &bootInfo->convmem,␊ |
84 | ␉␉␉␉␉␉ (unsigned long *) &bootInfo->extmem );␊ |
85 | ␊ |
86 | ␉␉if ( bootInfo->memoryMapCount == 0 )␊ |
87 | ␉␉{␊ |
88 | ␉␉␉// BIOS did not provide a memory map, systems with␊ |
89 | ␉␉␉// discontiguous memory or unusual memory hole locations␊ |
90 | ␉␉␉// may have problems.␊ |
91 | ␊ |
92 | ␉␉␉bootInfo->convmem␉= getConventionalMemorySize();␊ |
93 | ␉␉␉bootInfo->extmem␉= getExtendedMemorySize();␊ |
94 | ␉␉}␊ |
95 | ␊ |
96 | ␉␉bootInfo->configEnd␉␉= bootInfo->config;␊ |
97 | ␉␉bootArgs->Video.v_display␉= VGA_TEXT_MODE;␊ |
98 | ␊ |
99 | ␉␉DT__Initialize();␊ |
100 | ␊ |
101 | ␉␉node = DT__FindNode("/", true);␊ |
102 | ␉␉if (node == 0)␊ |
103 | ␉␉{␊ |
104 | ␉␉␉stop("Couldn't create root node");␊ |
105 | ␉␉}␊ |
106 | ␊ |
107 | ␉␉getPlatformName(platformName, sizeof(platformName));␊ |
108 | ␊ |
109 | ␉␉nameLen = strlen(platformName) + 1;␊ |
110 | ␉␉DT__AddProperty(node, "compatible", nameLen, platformName);␊ |
111 | ␉␉DT__AddProperty(node, "model", nameLen, platformName);␊ |
112 | ␊ |
113 | ␉␉gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);␊ |
114 | ␊ |
115 | ␉␉bootArgs->Version = kBootArgsVersion;␊ |
116 | ␉␉bootArgs->Revision = kBootArgsRevision;␊ |
117 | ␊ |
118 | ␉␉bootArgsLegacy->Version = kBootArgsLegacyVersion;␊ |
119 | ␉␉bootArgsLegacy->Revision = kBootArgsLegacyRevision;␊ |
120 | ␊ |
121 | ␉␉init_done = 1;␊ |
122 | ␉}␊ |
123 | }␊ |
124 | ␊ |
125 | /* Copy boot args after kernel and record address. */␊ |
126 | ␊ |
127 | void reserveKernBootStruct(void)␊ |
128 | {␊ |
129 | ␉if ( TIGER || LEOPARD || SNOW_LEOPARD )␊ |
130 | ␉{␊ |
131 | ␉␉// for 10.4 10.5 10.6␊ |
132 | ␉␉void *oldAddr = bootArgsLegacy;␊ |
133 | ␉␉bootArgsLegacy = (boot_args_legacy *)AllocateKernelMemory(sizeof(boot_args_legacy));␊ |
134 | ␉␉bcopy(oldAddr, bootArgsLegacy, sizeof(boot_args_legacy));␊ |
135 | ␉}␊ |
136 | ␉else␊ |
137 | ␉{␊ |
138 | ␉␉// for 10.7 10.8 10.9 10.10 10.11␊ |
139 | ␉␉void *oldAddr = bootArgs;␊ |
140 | ␉␉bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));␊ |
141 | ␉␉bcopy(oldAddr, bootArgs, sizeof(boot_args));␊ |
142 | ␉}␊ |
143 | }␊ |
144 | ␊ |
145 | //==============================================================================␊ |
146 | ␊ |
147 | void finalizeBootStruct(void)␊ |
148 | {␊ |
149 | ␉uint32_t size;␊ |
150 | ␉void *addr;␊ |
151 | ␉int i;␊ |
152 | ␊ |
153 | ␉EfiMemoryRange *memoryMap␉= NULL;␊ |
154 | ␉MemoryRange *range␉␉= NULL;␊ |
155 | ␉int memoryMapCount = bootInfo->memoryMapCount;␊ |
156 | ␊ |
157 | ␉if (memoryMapCount == 0)␊ |
158 | ␉{␊ |
159 | ␉␉// XXX could make a two-part map here␊ |
160 | ␉␉stop("Unable to convert memory map into proper format\n");␊ |
161 | ␉}␊ |
162 | ␊ |
163 | ␉// convert memory map to boot_args memory map␊ |
164 | ␉memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);␊ |
165 | ␊ |
166 | ␉bootArgs->MemoryMap␉␉␉= (uint32_t)memoryMap;␊ |
167 | ␉bootArgs->MemoryMapSize␉␉␉= sizeof(EfiMemoryRange) * memoryMapCount;␊ |
168 | ␉bootArgs->MemoryMapDescriptorSize␉= sizeof(EfiMemoryRange);␊ |
169 | ␉bootArgs->MemoryMapDescriptorVersion␉= 0;␊ |
170 | ␊ |
171 | ␉for (i = 0; i < memoryMapCount; i++, memoryMap++)␊ |
172 | ␉{␊ |
173 | ␉␉range = &bootInfo->memoryMap[i];␊ |
174 | ␊ |
175 | ␉␉switch(range->type)␊ |
176 | ␉␉{␊ |
177 | ␉␉␉case kMemoryRangeACPI:␊ |
178 | ␉␉␉␉memoryMap->Type = kEfiACPIReclaimMemory;␊ |
179 | ␉␉␉␉break;␊ |
180 | ␊ |
181 | ␉␉␉case kMemoryRangeNVS:␊ |
182 | ␉␉␉␉memoryMap->Type = kEfiACPIMemoryNVS;␊ |
183 | ␉␉␉␉break;␊ |
184 | ␊ |
185 | ␉␉␉case kMemoryRangeUsable:␊ |
186 | ␉␉␉␉memoryMap->Type = kEfiConventionalMemory;␊ |
187 | ␉␉␉␉break;␊ |
188 | ␊ |
189 | ␉␉␉case kMemoryRangeReserved:␊ |
190 | ␊ |
191 | ␉␉␉default:␊ |
192 | ␉␉␉␉memoryMap->Type = kEfiReservedMemoryType;␊ |
193 | ␉␉␉␉break;␊ |
194 | ␉␉}␊ |
195 | ␊ |
196 | ␉␉memoryMap->PhysicalStart␉= range->base;␊ |
197 | ␉␉memoryMap->VirtualStart␉␉= range->base;␊ |
198 | ␉␉memoryMap->NumberOfPages␉= range->length >> I386_PGSHIFT;␊ |
199 | ␉␉memoryMap->Attribute␉␉= 0;␊ |
200 | ␉}␊ |
201 | ␊ |
202 | ␉// copy bootFile into device tree␊ |
203 | ␉// XXX␊ |
204 | ␊ |
205 | ␉// add PCI info somehow into device tree␊ |
206 | ␉// XXX␊ |
207 | ␊ |
208 | ␉// Flatten device tree␊ |
209 | ␉DT__FlattenDeviceTree(0, &size);␊ |
210 | ␉addr = (void *)AllocateKernelMemory(size);␊ |
211 | ␉if (addr == 0)␊ |
212 | ␉{␊ |
213 | ␉␉stop("Couldn't allocate device tree\n");␊ |
214 | ␉}␊ |
215 | ␊ |
216 | ␉DT__FlattenDeviceTree((void **)&addr, &size);␊ |
217 | ␉bootArgs->deviceTreeP = (uint32_t)addr;␊ |
218 | ␉bootArgs->deviceTreeLength = size;␊ |
219 | ␊ |
220 | ␉// Copy BootArgs values to older structure␊ |
221 | ␊ |
222 | ␉memcpy(&bootArgsLegacy->CommandLine, &bootArgs->CommandLine, BOOT_LINE_LENGTH);␊ |
223 | ␉memcpy(&bootArgsLegacy->Video, &bootArgs->Video, sizeof(Boot_Video));␊ |
224 | ␊ |
225 | ␉bootArgsLegacy->MemoryMap = bootArgs->MemoryMap;␊ |
226 | ␉bootArgsLegacy->MemoryMapSize = bootArgs->MemoryMapSize;␊ |
227 | ␉bootArgsLegacy->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize;␊ |
228 | ␉bootArgsLegacy->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion;␊ |
229 | ␊ |
230 | ␉bootArgsLegacy->deviceTreeP = bootArgs->deviceTreeP;␊ |
231 | ␉bootArgsLegacy->deviceTreeLength = bootArgs->deviceTreeLength;␊ |
232 | ␊ |
233 | ␉bootArgsLegacy->kaddr = bootArgs->kaddr;␊ |
234 | ␉bootArgsLegacy->ksize = bootArgs->ksize;␊ |
235 | ␊ |
236 | ␉bootArgsLegacy->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart;␊ |
237 | ␉bootArgsLegacy->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount;␊ |
238 | ␉bootArgsLegacy->efiSystemTable = bootArgs->efiSystemTable;␊ |
239 | ␊ |
240 | ␉bootArgsLegacy->efiMode = bootArgs->efiMode;␊ |
241 | ␊ |
242 | ␉bootArgsLegacy->performanceDataStart = bootArgs->performanceDataStart;␊ |
243 | ␉bootArgsLegacy->performanceDataSize = bootArgs->performanceDataSize;␊ |
244 | ␉bootArgsLegacy->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart;␊ |
245 | }␊ |
246 | |