Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 2385