Chameleon

Chameleon Svn Source Tree

Root/trunk/i386/libsaio/bootstruct.c

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

Archive Download this file

Revision: 2804