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

Archive Download this file

Revision: 2428