Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 816