Chameleon

Chameleon Svn Source Tree

Root/branches/Bungo/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
94 // DeviceTree init
95//DT__Initialize();
96//node = DT__FindNode("/", true);
97 node = DT__Initialize();
98if (node == 0) {
99stop("Couldn't create root node");
100}
101
102getPlatformName(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} else {
130// for 10.7 10.8 10.9 10.10
131void *oldAddr = bootArgs;
132bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));
133bcopy(oldAddr, bootArgs, sizeof(boot_args));
134}
135}
136
137//==============================================================================
138
139void finalizeBootStruct(void)
140{
141uint32_t size;
142void *addr;
143int i;
144EfiMemoryRange *memoryMap;
145MemoryRange *range;
146int memoryMapCount = bootInfo->memoryMapCount;
147
148if (memoryMapCount == 0) {
149// XXX could make a two-part map here
150stop("Unable to convert memory map into proper format\n");
151}
152
153// convert memory map to boot_args memory map
154memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
155bootArgs->MemoryMap = (uint32_t)memoryMap;
156bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
157bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
158bootArgs->MemoryMapDescriptorVersion = 0;
159
160for (i = 0; i < memoryMapCount; i++, memoryMap++) {
161range = &bootInfo->memoryMap[i];
162switch(range->type) {
163case kMemoryRangeACPI:
164memoryMap->Type = kEfiACPIReclaimMemory;
165break;
166
167case kMemoryRangeNVS:
168memoryMap->Type = kEfiACPIMemoryNVS;
169break;
170
171case kMemoryRangeUsable:
172memoryMap->Type = kEfiConventionalMemory;
173break;
174
175case kMemoryRangeReserved:
176
177default:
178memoryMap->Type = kEfiReservedMemoryType;
179break;
180}
181
182memoryMap->PhysicalStart= range->base;
183memoryMap->VirtualStart= range->base;
184memoryMap->NumberOfPages= range->length >> I386_PGSHIFT;
185memoryMap->Attribute= 0;
186}
187
188// copy bootFile into device tree
189// XXX
190
191// add PCI info somehow into device tree
192// XXX
193
194// Flatten device tree
195DT__FlattenDeviceTree(0, &size);
196addr = (void *)AllocateKernelMemory(size);
197if (addr == 0) {
198stop("Couldn't allocate device tree\n");
199}
200
201DT__FlattenDeviceTree((void **)&addr, &size);
202bootArgs->deviceTreeP = (uint32_t)addr;
203bootArgs->deviceTreeLength = size;
204
205// Copy BootArgs values to older structure
206
207memcpy(&bootArgsPreLion->CommandLine, &bootArgs->CommandLine, BOOT_LINE_LENGTH);
208memcpy(&bootArgsPreLion->Video, &bootArgs->Video, sizeof(Boot_Video));
209
210bootArgsPreLion->MemoryMap = bootArgs->MemoryMap;
211bootArgsPreLion->MemoryMapSize = bootArgs->MemoryMapSize;
212bootArgsPreLion->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize;
213bootArgsPreLion->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion;
214
215bootArgsPreLion->deviceTreeP = bootArgs->deviceTreeP;
216bootArgsPreLion->deviceTreeLength = bootArgs->deviceTreeLength;
217
218bootArgsPreLion->kaddr = bootArgs->kaddr;
219bootArgsPreLion->ksize = bootArgs->ksize;
220
221bootArgsPreLion->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart;
222bootArgsPreLion->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount;
223bootArgsPreLion->efiSystemTable = bootArgs->efiSystemTable;
224
225bootArgsPreLion->efiMode = bootArgs->efiMode;
226
227bootArgsPreLion->performanceDataStart = bootArgs->performanceDataStart;
228bootArgsPreLion->performanceDataSize = bootArgs->performanceDataSize;
229bootArgsPreLion->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart;
230}
231

Archive Download this file

Revision: 2469