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