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
117/* Copy boot args after kernel and record address. */
118
119void
120reserveKernBootStruct(void)
121{
122if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0')
123&& (gMacOSVersion[2] == '.') && (gMacOSVersion[3] == '7' || gMacOSVersion[3] == '8' || gMacOSVersion[3] == '9'))
124{
125void *oldAddr = bootArgs;
126bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));
127bcopy(oldAddr, bootArgs, sizeof(boot_args));
128} else {
129void *oldAddr = bootArgsPreLion;
130bootArgsPreLion = (boot_args_pre_lion *)AllocateKernelMemory(sizeof(boot_args_pre_lion));
131bcopy(oldAddr, bootArgsPreLion, sizeof(boot_args_pre_lion));
132}
133}
134
135void
136finalizeBootStruct(void)
137{
138uint32_t size;
139void *addr;
140int i;
141EfiMemoryRange *memoryMap;
142MemoryRange *range;
143int memoryMapCount = bootInfo->memoryMapCount;
144
145if (memoryMapCount == 0) {
146// XXX could make a two-part map here
147stop("Unable to convert memory map into proper format\n");
148}
149
150// convert memory map to boot_args memory map
151memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
152bootArgs->MemoryMap = (uint32_t)memoryMap;
153bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
154bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
155bootArgs->MemoryMapDescriptorVersion = 0;
156
157for (i = 0; i < memoryMapCount; i++, memoryMap++)
158{
159range = &bootInfo->memoryMap[i];
160switch(range->type) {
161case kMemoryRangeACPI:
162memoryMap->Type = kEfiACPIReclaimMemory;
163break;
164case kMemoryRangeNVS:
165memoryMap->Type = kEfiACPIMemoryNVS;
166break;
167case kMemoryRangeUsable:
168memoryMap->Type = kEfiConventionalMemory;
169break;
170case kMemoryRangeReserved:
171default:
172memoryMap->Type = kEfiReservedMemoryType;
173break;
174}
175memoryMap->PhysicalStart = range->base;
176memoryMap->VirtualStart = range->base;
177memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;
178memoryMap->Attribute = 0;
179}
180
181// copy bootFile into device tree
182// XXX
183
184// add PCI info somehow into device tree
185// XXX
186
187// Flatten device tree
188DT__FlattenDeviceTree(0, &size);
189addr = (void *)AllocateKernelMemory(size);
190if (addr == 0) {
191stop("Couldn't allocate device tree\n");
192}
193
194DT__FlattenDeviceTree((void **)&addr, &size);
195bootArgs->deviceTreeP = (uint32_t)addr;
196bootArgs->deviceTreeLength = size;
197
198// Copy BootArgs values to older structure
199
200memcpy(&bootArgsPreLion->CommandLine, &bootArgs->CommandLine, BOOT_LINE_LENGTH);
201memcpy(&bootArgsPreLion->Video, &bootArgs->Video, sizeof(Boot_Video));
202
203bootArgsPreLion->MemoryMap = bootArgs->MemoryMap;
204bootArgsPreLion->MemoryMapSize = bootArgs->MemoryMapSize;
205bootArgsPreLion->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize;
206bootArgsPreLion->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion;
207
208bootArgsPreLion->deviceTreeP = bootArgs->deviceTreeP;
209bootArgsPreLion->deviceTreeLength = bootArgs->deviceTreeLength;
210
211bootArgsPreLion->kaddr = bootArgs->kaddr;
212bootArgsPreLion->ksize = bootArgs->ksize;
213
214bootArgsPreLion->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart;
215bootArgsPreLion->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount;
216bootArgsPreLion->efiSystemTable = bootArgs->efiSystemTable;
217
218bootArgsPreLion->efiMode = bootArgs->efiMode;
219
220bootArgsPreLion->performanceDataStart = bootArgs->performanceDataStart;
221bootArgsPreLion->performanceDataSize = bootArgs->performanceDataSize;
222bootArgsPreLion->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart;
223}
224

Archive Download this file

Revision: 2390