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 ?? doesn't seem so.␊ |
44 | static char platformName[64];␊ |
45 | ␊ |
46 | //Azi: bootargs - we can't retrive OS version at this point...␊ |
47 | void initKernBootStruct( void )␊ |
48 | {␊ |
49 | Node *node;␊ |
50 | int nameLen;␊ |
51 | static int init_done = 0;␊ |
52 | ␊ |
53 | if ( !init_done )␊ |
54 | {␊ |
55 | bootArgs = (boot_args *)malloc(sizeof(boot_args));␊ |
56 | ␉␉bootArgsPreLion = (boot_args_pre_lion *)malloc(sizeof(boot_args_pre_lion));␊ |
57 | bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t));␊ |
58 | if (bootArgs == 0 || bootInfo == 0)␊ |
59 | stop("Couldn't allocate boot info\n");␊ |
60 | ␊ |
61 | bzero(bootArgs, sizeof(boot_args));␊ |
62 | ␉␉bzero(bootArgsPreLion, sizeof(boot_args_pre_lion));␊ |
63 | bzero(bootInfo, sizeof(PrivateBootInfo_t));␊ |
64 | ␊ |
65 | // Get system memory map. Also update the size of the␊ |
66 | // conventional/extended memory for backwards compatibility.␊ |
67 | ␊ |
68 | bootInfo->memoryMapCount =␊ |
69 | getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax,␊ |
70 | (unsigned long *) &bootInfo->convmem,␊ |
71 | (unsigned long *) &bootInfo->extmem );␊ |
72 | ␊ |
73 | if ( bootInfo->memoryMapCount == 0 )␊ |
74 | {␊ |
75 | // BIOS did not provide a memory map, systems with␊ |
76 | // discontiguous memory or unusual memory hole locations␊ |
77 | // may have problems.␊ |
78 | ␊ |
79 | bootInfo->convmem = getConventionalMemorySize();␊ |
80 | bootInfo->extmem = getExtendedMemorySize();␊ |
81 | }␊ |
82 | ␊ |
83 | bootInfo->configEnd = bootInfo->config;␊ |
84 | bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
85 | ␊ |
86 | DT__Initialize();␊ |
87 | ␊ |
88 | node = DT__FindNode("/", true);␊ |
89 | if (node == 0) {␊ |
90 | stop("Couldn't create root node");␊ |
91 | }␊ |
92 | getPlatformName(platformName);␊ |
93 | nameLen = strlen(platformName) + 1;␊ |
94 | DT__AddProperty(node, "compatible", nameLen, platformName);␊ |
95 | DT__AddProperty(node, "model", nameLen, platformName);␊ |
96 | ␊ |
97 | gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);␊ |
98 | //␉␉efiPlatformNode = DT__FindNode("/efi/platform", true); //Azi: test␊ |
99 | ␊ |
100 | bootArgs->Version = kBootArgsVersion;␊ |
101 | bootArgs->Revision = kBootArgsRevision;␊ |
102 | ␉␉␊ |
103 | ␉␉bootArgsPreLion->Version = kBootArgsPreLionVersion;␊ |
104 | bootArgsPreLion->Revision = kBootArgsPreLionRevision;␊ |
105 | ␉␉␊ |
106 | init_done = 1;␊ |
107 | }␊ |
108 | ␊ |
109 | }␊ |
110 | ␊ |
111 | //Azi: ... but here we can... (done)␊ |
112 | /** Copy boot args after kernel and record address. */␊ |
113 | void␊ |
114 | reserveKernBootStruct(void)␊ |
115 | {␊ |
116 | ␉if (gMacOSVersion[3] <= '6')␊ |
117 | {␊ |
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 | ␉else {␊ |
123 | ␉␉void *oldAddr = bootArgs;␊ |
124 | ␉␉bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));␊ |
125 | ␉␉bcopy(oldAddr, bootArgs, sizeof(boot_args));␊ |
126 | ␉}␊ |
127 | ␊ |
128 | }␊ |
129 | ␊ |
130 | //Azi: ... and here too.␊ |
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 | //Azi: Ok, stuff that uses same naming for both bootargs versions... neat ;)␊ |
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 | |