Chameleon

Chameleon Svn Source Tree

Root/branches/andyvand/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;
38PrivateBootInfo_t *bootInfo;
39Node *gMemoryMapNode;
40
41static char platformName[64];
42static char SysVolName[1] = { 0xFF }; /* AnV - volume level fix */
43
44void initKernBootStruct( void )
45{
46 Node *node;
47Node *optionnode;
48 int nameLen;
49 static int init_done = 0;
50
51 if ( !init_done )
52 {
53 bootArgs = (boot_args *)malloc(sizeof(boot_args));
54 bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t));
55 if (bootArgs == 0 || bootInfo == 0)
56 stop("Couldn't allocate boot info\n");
57
58 bzero(bootArgs, sizeof(boot_args));
59 bzero(bootInfo, sizeof(PrivateBootInfo_t));
60
61 // Get system memory map. Also update the size of the
62 // conventional/extended memory for backwards compatibility.
63
64 bootInfo->memoryMapCount =
65 getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax,
66 (unsigned long *) &bootInfo->convmem,
67 (unsigned long *) &bootInfo->extmem );
68
69 if ( bootInfo->memoryMapCount == 0 )
70 {
71 // BIOS did not provide a memory map, systems with
72 // discontiguous memory or unusual memory hole locations
73 // may have problems.
74
75 bootInfo->convmem = getConventionalMemorySize();
76 bootInfo->extmem = getExtendedMemorySize();
77 }
78
79 bootInfo->configEnd = bootInfo->config;
80 bootArgs->Video.v_display = VGA_TEXT_MODE;
81
82 DT__Initialize();
83
84 node = DT__FindNode("/", true);
85 if (node == 0) {
86 stop("Couldn't create root node");
87 }
88 getPlatformName(platformName);
89 nameLen = strlen(platformName) + 1;
90 DT__AddProperty(node, "compatible", nameLen, platformName);
91 DT__AddProperty(node, "model", nameLen, platformName);
92
93/* AnV - options node fix */
94optionnode = DT__AddChild(node, "options");
95DT__AddProperty(optionnode, "SystemAudioVolume", 1, SysVolName);
96
97 gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);
98
99 bootArgs->Version = kBootArgsVersion;
100 bootArgs->Revision = 5;
101
102 init_done = 1;
103 }
104
105}
106
107
108/* Copy boot args after kernel and record address. */
109
110void
111reserveKernBootStruct(void)
112{
113 void *oldAddr = bootArgs;
114 bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));
115 bcopy(oldAddr, bootArgs, sizeof(boot_args));
116}
117
118void
119finalizeBootStruct(void)
120{
121 uint32_t size;
122 void *addr;
123 int i;
124 EfiMemoryRange *memoryMap;
125 MemoryRange *range;
126 int memoryMapCount = bootInfo->memoryMapCount;
127
128 if (memoryMapCount == 0) {
129 // XXX could make a two-part map here
130 stop("Unable to convert memory map into proper format\n");
131 }
132
133 // convert memory map to boot_args memory map
134 memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
135 bootArgs->MemoryMap = (uint32_t)memoryMap;
136 bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
137 bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
138 bootArgs->MemoryMapDescriptorVersion = 0;
139
140 for (i=0; i<memoryMapCount; i++, memoryMap++) {
141 range = &bootInfo->memoryMap[i];
142 switch(range->type) {
143case kMemoryRangeACPI:
144memoryMap->Type = kEfiACPIReclaimMemory;
145break;
146case kMemoryRangeNVS:
147memoryMap->Type = kEfiACPIMemoryNVS;
148break;
149case kMemoryRangeUsable:
150memoryMap->Type = kEfiConventionalMemory;
151break;
152case kMemoryRangeReserved:
153default:
154memoryMap->Type = kEfiReservedMemoryType;
155break;
156 }
157 memoryMap->PhysicalStart = range->base;
158 memoryMap->VirtualStart = range->base;
159 memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;
160 memoryMap->Attribute = 0;
161 }
162
163 // copy bootFile into device tree
164 // XXX
165
166 // add PCI info somehow into device tree
167 // XXX
168
169 // Flatten device tree
170 DT__FlattenDeviceTree(0, &size);
171 addr = (void *)AllocateKernelMemory(size);
172 if (addr == 0) {
173 stop("Couldn't allocate device tree\n");
174 }
175
176 DT__FlattenDeviceTree((void **)&addr, &size);
177 bootArgs->deviceTreeP = (uint32_t)addr;
178 bootArgs->deviceTreeLength = size;
179}
180

Archive Download this file

Revision: 142