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