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 ?? doesn't seem so.
44static char platformName[64];
45
46//Azi: bootargs - we can't retrive OS version at this point...
47void initKernBootStruct( void )
48{
49Node *node;
50int nameLen;
51static int init_done = 0;
52
53if ( !init_done )
54{
55bootArgs = (boot_args *)malloc(sizeof(boot_args));
56bootArgsPreLion = (boot_args_pre_lion *)malloc(sizeof(boot_args_pre_lion));
57bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t));
58if (bootArgs == 0 || bootInfo == 0)
59stop("Couldn't allocate boot info\n");
60
61bzero(bootArgs, sizeof(boot_args));
62bzero(bootArgsPreLion, sizeof(boot_args_pre_lion));
63bzero(bootInfo, sizeof(PrivateBootInfo_t));
64
65// Get system memory map. Also update the size of the
66// conventional/extended memory for backwards compatibility.
67
68bootInfo->memoryMapCount =
69getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax,
70 (unsigned long *) &bootInfo->convmem,
71 (unsigned long *) &bootInfo->extmem );
72
73if ( bootInfo->memoryMapCount == 0 )
74{
75// BIOS did not provide a memory map, systems with
76// discontiguous memory or unusual memory hole locations
77// may have problems.
78
79bootInfo->convmem = getConventionalMemorySize();
80bootInfo->extmem = getExtendedMemorySize();
81}
82
83bootInfo->configEnd = bootInfo->config;
84bootArgs->Video.v_display = VGA_TEXT_MODE;
85
86DT__Initialize();
87
88node = DT__FindNode("/", true);
89if (node == 0) {
90stop("Couldn't create root node");
91}
92getPlatformName(platformName);
93nameLen = strlen(platformName) + 1;
94DT__AddProperty(node, "compatible", nameLen, platformName);
95DT__AddProperty(node, "model", nameLen, platformName);
96
97gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);
98//efiPlatformNode = DT__FindNode("/efi/platform", true); //Azi: test
99
100bootArgs->Version = kBootArgsVersion;
101bootArgs->Revision = kBootArgsRevision;
102
103bootArgsPreLion->Version = kBootArgsPreLionVersion;
104bootArgsPreLion->Revision = kBootArgsPreLionRevision;
105
106init_done = 1;
107}
108}
109
110//Azi: ... but here we can... (done)
111/* Copy boot args after kernel and record address. */
112
113void
114reserveKernBootStruct(void)
115{
116if (gMacOSVersion[3] <= '6')
117{
118void *oldAddr = bootArgsPreLion;
119bootArgsPreLion = (boot_args_pre_lion *)AllocateKernelMemory(sizeof(boot_args_pre_lion));
120bcopy(oldAddr, bootArgsPreLion, sizeof(boot_args_pre_lion));
121}
122else
123{
124void *oldAddr = bootArgs;
125bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));
126bcopy(oldAddr, bootArgs, sizeof(boot_args));
127}
128}
129
130//Azi: ... and here too.
131void
132finalizeBootStruct(void)
133{
134uint32_t size;
135void *addr;
136int i;
137EfiMemoryRange *memoryMap;
138MemoryRange *range;
139int memoryMapCount = bootInfo->memoryMapCount;
140
141if (memoryMapCount == 0) {
142// XXX could make a two-part map here
143stop("Unable to convert memory map into proper format\n");
144}
145
146// convert memory map to boot_args memory map
147memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
148bootArgs->MemoryMap = (uint32_t)memoryMap;
149bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
150bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
151bootArgs->MemoryMapDescriptorVersion = 0;
152
153for (i=0; i<memoryMapCount; i++, memoryMap++) {
154range = &bootInfo->memoryMap[i];
155switch(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}
170memoryMap->PhysicalStart = range->base;
171memoryMap->VirtualStart = range->base;
172memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;
173memoryMap->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
183DT__FlattenDeviceTree(0, &size);
184addr = (void *)AllocateKernelMemory(size);
185if (addr == 0) {
186stop("Couldn't allocate device tree\n");
187}
188
189DT__FlattenDeviceTree((void **)&addr, &size);
190bootArgs->deviceTreeP = (uint32_t)addr;
191bootArgs->deviceTreeLength = size;
192
193// Copy BootArgs values to older structure
194//Azi: Ok, stuff that uses same naming for both bootargs versions... neat ;)
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

Archive Download this file

Revision: 980