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

Archive Download this file

Revision: 2403