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

Archive Download this file

Revision: 2425