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