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("Unable to convert memory map into proper format\n");
161}
162
163// convert memory map to boot_args memory map
164memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
165
166bootArgs->MemoryMap= (uint32_t)memoryMap;
167bootArgs->MemoryMapSize= sizeof(EfiMemoryRange) * memoryMapCount;
168bootArgs->MemoryMapDescriptorSize= sizeof(EfiMemoryRange);
169bootArgs->MemoryMapDescriptorVersion= 0;
170
171for (i = 0; i < memoryMapCount; i++, memoryMap++)
172{
173range = &bootInfo->memoryMap[i];
174
175switch(range->type)
176{
177case kMemoryRangeACPI:
178memoryMap->Type = kEfiACPIReclaimMemory;
179break;
180
181case kMemoryRangeNVS:
182memoryMap->Type = kEfiACPIMemoryNVS;
183break;
184
185case kMemoryRangeUsable:
186memoryMap->Type = kEfiConventionalMemory;
187break;
188
189case kMemoryRangeReserved:
190
191default:
192memoryMap->Type = kEfiReservedMemoryType;
193break;
194}
195
196memoryMap->PhysicalStart= range->base;
197memoryMap->VirtualStart= range->base;
198memoryMap->NumberOfPages= range->length >> I386_PGSHIFT;
199memoryMap->Attribute= 0;
200}
201
202// copy bootFile into device tree
203// XXX
204
205// add PCI info somehow into device tree
206// XXX
207
208// Flatten device tree
209DT__FlattenDeviceTree(0, &size);
210addr = (void *)AllocateKernelMemory(size);
211if (addr == 0)
212{
213stop("Couldn't allocate device tree\n");
214}
215
216DT__FlattenDeviceTree((void **)&addr, &size);
217if (!size)
218{
219stop("Couldn't get flatten device tree\n");
220return;
221}
222bootArgs->deviceTreeP = (uint32_t)addr;
223bootArgs->deviceTreeLength = size;
224
225// Copy BootArgs values to older structure
226
227memcpy(&bootArgsLegacy->CommandLine, &bootArgs->CommandLine, BOOT_LINE_LENGTH);
228memcpy(&bootArgsLegacy->Video, &bootArgs->Video, sizeof(Boot_Video));
229
230bootArgsLegacy->MemoryMap = bootArgs->MemoryMap;
231bootArgsLegacy->MemoryMapSize = bootArgs->MemoryMapSize;
232bootArgsLegacy->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize;
233bootArgsLegacy->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion;
234
235bootArgsLegacy->deviceTreeP = bootArgs->deviceTreeP;
236bootArgsLegacy->deviceTreeLength = bootArgs->deviceTreeLength;
237
238bootArgsLegacy->kaddr = bootArgs->kaddr;
239bootArgsLegacy->ksize = bootArgs->ksize;
240
241bootArgsLegacy->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart;
242bootArgsLegacy->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount;
243bootArgsLegacy->efiSystemTable = bootArgs->efiSystemTable;
244
245bootArgsLegacy->efiMode = bootArgs->efiMode;
246
247bootArgsLegacy->performanceDataStart = bootArgs->performanceDataStart;
248bootArgsLegacy->performanceDataSize = bootArgs->performanceDataSize;
249bootArgsLegacy->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart;
250}
251

Archive Download this file

Revision: 2783