Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/iFabio/Chameleon/i386/libsaio/bootstruct.c

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

Archive Download this file

Revision: 298