Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 765