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

Archive Download this file

Revision: 67