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