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

Archive Download this file

Revision: 2727