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