Root/
Source at commit 2740 created 8 years 11 months ago. By ifabio, sync with trunk. | |
---|---|
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 | /* Copy boot args after kernel and record address. */␊ |
117 | ␊ |
118 | void␊ |
119 | reserveKernBootStruct(void)␊ |
120 | {␊ |
121 | ␉if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0')␊ |
122 | ␉␉&& (gMacOSVersion[2] == '.') && (gMacOSVersion[3] == '7' || gMacOSVersion[3] == '8' || gMacOSVersion[3] == '9'))␊ |
123 | ␉{␊ |
124 | ␉␉void *oldAddr = bootArgs;␊ |
125 | ␉␉bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));␊ |
126 | ␉␉bcopy(oldAddr, bootArgs, sizeof(boot_args));␊ |
127 | ␉} else {␊ |
128 | ␉␉void *oldAddr = bootArgsPreLion;␊ |
129 | ␉␉bootArgsPreLion = (boot_args_pre_lion *)AllocateKernelMemory(sizeof(boot_args_pre_lion));␊ |
130 | ␉␉bcopy(oldAddr, bootArgsPreLion, sizeof(boot_args_pre_lion));␊ |
131 | ␉}␊ |
132 | }␊ |
133 | ␊ |
134 | //==============================================================================␊ |
135 | ␊ |
136 | void finalizeBootStruct(void)␊ |
137 | {␊ |
138 | ␉uint32_t size;␊ |
139 | ␉void *addr;␊ |
140 | ␉int i;␊ |
141 | ␉EfiMemoryRange *memoryMap;␊ |
142 | ␉MemoryRange *range;␊ |
143 | ␉int memoryMapCount = bootInfo->memoryMapCount;␊ |
144 | ␊ |
145 | ␉if (memoryMapCount == 0)␊ |
146 | ␉{␊ |
147 | ␉␉// XXX could make a two-part map here␊ |
148 | ␉␉stop("Unable to convert memory map into proper format\n");␊ |
149 | ␉}␊ |
150 | ␊ |
151 | ␉// convert memory map to boot_args memory map␊ |
152 | ␉memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);␊ |
153 | ␊ |
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 | ␉{␊ |
161 | ␉␉range = &bootInfo->memoryMap[i];␊ |
162 | ␊ |
163 | ␉␉switch(range->type)␊ |
164 | ␉␉{␊ |
165 | ␉␉␉case kMemoryRangeACPI:␊ |
166 | ␉␉␉␉memoryMap->Type = kEfiACPIReclaimMemory;␊ |
167 | ␉␉␉␉break;␊ |
168 | ␊ |
169 | ␉␉␉case kMemoryRangeNVS:␊ |
170 | ␉␉␉␉memoryMap->Type = kEfiACPIMemoryNVS;␊ |
171 | ␉␉␉␉break;␊ |
172 | ␊ |
173 | ␉␉␉case kMemoryRangeUsable:␊ |
174 | ␉␉␉␉memoryMap->Type = kEfiConventionalMemory;␊ |
175 | ␉␉␉␉break;␊ |
176 | ␊ |
177 | ␉␉␉case kMemoryRangeReserved:␊ |
178 | ␊ |
179 | ␉␉␉default:␊ |
180 | ␉␉␉␉memoryMap->Type = kEfiReservedMemoryType;␊ |
181 | ␉␉␉␉break;␊ |
182 | ␉␉}␊ |
183 | ␊ |
184 | ␉␉memoryMap->PhysicalStart␉= range->base;␊ |
185 | ␉␉memoryMap->VirtualStart␉␉= range->base;␊ |
186 | ␉␉memoryMap->NumberOfPages␉= range->length >> I386_PGSHIFT;␊ |
187 | ␉␉memoryMap->Attribute␉␉= 0;␊ |
188 | ␉}␊ |
189 | ␊ |
190 | ␉// copy bootFile into device tree␊ |
191 | ␉// XXX␊ |
192 | ␊ |
193 | ␉// add PCI info somehow into device tree␊ |
194 | ␉// XXX␊ |
195 | ␊ |
196 | ␉// Flatten device tree␊ |
197 | ␉DT__FlattenDeviceTree(0, &size);␊ |
198 | ␉addr = (void *)AllocateKernelMemory(size);␊ |
199 | ␊ |
200 | ␉if (addr == 0)␊ |
201 | ␉{␊ |
202 | ␉␉stop("Couldn't allocate device tree\n");␊ |
203 | ␉}␊ |
204 | ␊ |
205 | ␉DT__FlattenDeviceTree((void **)&addr, &size);␊ |
206 | ␉bootArgs->deviceTreeP = (uint32_t)addr;␊ |
207 | ␉bootArgs->deviceTreeLength = size;␊ |
208 | ␊ |
209 | ␉// Copy BootArgs values to older structure␊ |
210 | ␊ |
211 | ␉memcpy(&bootArgsPreLion->CommandLine, &bootArgs->CommandLine, BOOT_LINE_LENGTH);␊ |
212 | ␉memcpy(&bootArgsPreLion->Video, &bootArgs->Video, sizeof(Boot_Video));␊ |
213 | ␊ |
214 | ␉bootArgsPreLion->MemoryMap = bootArgs->MemoryMap;␊ |
215 | ␉bootArgsPreLion->MemoryMapSize = bootArgs->MemoryMapSize;␊ |
216 | ␉bootArgsPreLion->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize;␊ |
217 | ␉bootArgsPreLion->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion;␊ |
218 | ␉␊ |
219 | ␉bootArgsPreLion->deviceTreeP = bootArgs->deviceTreeP;␊ |
220 | ␉bootArgsPreLion->deviceTreeLength = bootArgs->deviceTreeLength;␊ |
221 | ␊ |
222 | ␉bootArgsPreLion->kaddr = bootArgs->kaddr;␊ |
223 | ␉bootArgsPreLion->ksize = bootArgs->ksize;␊ |
224 | ␊ |
225 | ␉bootArgsPreLion->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart;␊ |
226 | ␉bootArgsPreLion->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount;␊ |
227 | ␉bootArgsPreLion->efiSystemTable = bootArgs->efiSystemTable;␊ |
228 | ␊ |
229 | ␉bootArgsPreLion->efiMode = bootArgs->efiMode;␊ |
230 | ␊ |
231 | ␉bootArgsPreLion->performanceDataStart = bootArgs->performanceDataStart;␊ |
232 | ␉bootArgsPreLion->performanceDataSize = bootArgs->performanceDataSize;␊ |
233 | ␉bootArgsPreLion->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart;␊ |
234 | }␊ |
235 |