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 | #include "boot.h"␊ |
32 | ␊ |
33 | /*==========================================================================␊ |
34 | * Initialize the structure of parameters passed to␊ |
35 | * the kernel by the booter.␊ |
36 | */␊ |
37 | ␊ |
38 | boot_args *bootArgs;␊ |
39 | boot_args_snow *bootArgsSnow;␊ |
40 | PrivateBootInfo_t *bootInfo;␊ |
41 | Node *gMemoryMapNode;␊ |
42 | ␊ |
43 | static char platformName[64];␊ |
44 | ␊ |
45 | void initKernBootStruct( void )␊ |
46 | {␊ |
47 | Node *node;␊ |
48 | int nameLen;␊ |
49 | static int init_done = 0;␊ |
50 | ␉␊ |
51 | if ( !init_done )␊ |
52 | {␊ |
53 | bootArgs = (boot_args *)malloc(sizeof(boot_args));␊ |
54 | bootArgsSnow = (boot_args *)malloc(sizeof(boot_args_snow));␊ |
55 | bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t));␊ |
56 | if (bootArgsSnow == 0 || bootArgs == 0 || bootInfo == 0)␊ |
57 | stop("Couldn't allocate boot info\n");␊ |
58 | ␉␉␊ |
59 | bzero(bootArgs, sizeof(boot_args));␊ |
60 | bzero(bootArgsSnow, sizeof(boot_args_snow));␊ |
61 | bzero(bootInfo, sizeof(PrivateBootInfo_t));␊ |
62 | ␉␉␊ |
63 | // Get system memory map. Also update the size of the␊ |
64 | // conventional/extended memory for backwards compatibility.␊ |
65 | ␉␉␊ |
66 | bootInfo->memoryMapCount =␊ |
67 | ␉␉getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax,␊ |
68 | ␉␉␉␉␉ (unsigned long *) &bootInfo->convmem,␊ |
69 | ␉␉␉␉␉ (unsigned long *) &bootInfo->extmem );␊ |
70 | ␉␉␊ |
71 | if ( 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 | ␉␉␉␊ |
77 | bootInfo->convmem = getConventionalMemorySize();␊ |
78 | bootInfo->extmem = getExtendedMemorySize();␊ |
79 | }␊ |
80 | ␉␉␊ |
81 | bootInfo->configEnd = bootInfo->config;␊ |
82 | bootArgs->Video.v_display = VGA_TEXT_MODE;␊ |
83 | bootArgsSnow->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 | ␉␉␊ |
98 | bootArgs->Version = kBootArgsVersion;␊ |
99 | bootArgs->Revision = kBootArgsRevision;␊ |
100 | ␉␉␊ |
101 | ␉␉bootArgsSnow->Version = kBootArgsVersion_Snow;␊ |
102 | ␉␉bootArgsSnow->Revision = kBootArgsRevision1_5;␊ |
103 | ␉␉␊ |
104 | ␉␉bootArgs->performanceDataStart = 0;␊ |
105 | ␉␉bootArgs->performanceDataSize = 0;␊ |
106 | ␉␉bootArgs->keyStoreDataStart = 0;␊ |
107 | ␉␉bootArgs->keyStoreDataSize = 0;␊ |
108 | ␉␉bootArgs->bootMemStart = 0;␊ |
109 | ␉␉bootArgs->bootMemSize = 0;␊ |
110 | ␉␉bootArgs->debugMode = 0;␊ |
111 | ␉␉␊ |
112 | init_done = 1;␊ |
113 | }␊ |
114 | ␉␊ |
115 | }␊ |
116 | ␊ |
117 | ␊ |
118 | /* Copy boot args after kernel and record address. */␊ |
119 | ␊ |
120 | void␊ |
121 | reserveKernBootStruct(void)␊ |
122 | {␊ |
123 | if ((gMacOSVersion[0] == '1') && (gMacOSVersion[1] == '0') && (gMacOSVersion[2] == '.') && (gMacOSVersion[3] >= '7'))␊ |
124 | {␊ |
125 | ␉␉void *oldAddr = bootArgs;␊ |
126 | ␉␉bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));␊ |
127 | ␉␉bcopy(oldAddr, bootArgs, sizeof(boot_args));␊ |
128 | ␉} else {␊ |
129 | ␉␉void *oldAddr = bootArgsSnow;␊ |
130 | ␉␉bootArgsSnow = (boot_args_snow *)AllocateKernelMemory(sizeof(boot_args_snow));␊ |
131 | ␉␉bcopy(oldAddr, bootArgsSnow, sizeof(boot_args_snow));␊ |
132 | ␉}␊ |
133 | }␊ |
134 | ␊ |
135 | void␊ |
136 | finalizeBootStruct(void)␊ |
137 | {␊ |
138 | uint32_t size;␊ |
139 | void *addr;␊ |
140 | int i;␊ |
141 | EfiMemoryRange *memoryMap;␊ |
142 | MemoryRange *range;␊ |
143 | int memoryMapCount = bootInfo->memoryMapCount;␊ |
144 | ␉␊ |
145 | if (memoryMapCount == 0) {␊ |
146 | // XXX could make a two-part map here␊ |
147 | stop("Unable to convert memory map into proper format\n");␊ |
148 | }␊ |
149 | ␉␊ |
150 | // convert memory map to boot_args memory map␊ |
151 | memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);␊ |
152 | bootArgs->MemoryMap = (uint32_t)memoryMap;␊ |
153 | bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;␊ |
154 | bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);␊ |
155 | bootArgs->MemoryMapDescriptorVersion = 0;␊ |
156 | ␉␊ |
157 | bootArgsSnow->MemoryMap = (uint32_t)memoryMap;␊ |
158 | bootArgsSnow->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;␊ |
159 | bootArgsSnow->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);␊ |
160 | bootArgsSnow->MemoryMapDescriptorVersion = 0;␊ |
161 | ␉␊ |
162 | for (i=0; i<memoryMapCount; i++, memoryMap++) {␊ |
163 | range = &bootInfo->memoryMap[i];␊ |
164 | switch(range->type) {␊ |
165 | ␉␉␉case kMemoryRangeACPI:␊ |
166 | ␉␉␉␉memoryMap->Type = kEfiACPIReclaimMemory;␊ |
167 | ␉␉␉␉break;␊ |
168 | ␉␉␉case kMemoryRangeNVS:␊ |
169 | ␉␉␉␉memoryMap->Type = kEfiACPIMemoryNVS;␊ |
170 | ␉␉␉␉break;␊ |
171 | ␉␉␉case kMemoryRangeUsable:␊ |
172 | ␉␉␉␉memoryMap->Type = kEfiConventionalMemory;␊ |
173 | ␉␉␉␉break;␊ |
174 | ␉␉␉case kMemoryRangeReserved:␊ |
175 | ␉␉␉default:␊ |
176 | ␉␉␉␉memoryMap->Type = kEfiReservedMemoryType;␊ |
177 | ␉␉␉␉break;␊ |
178 | }␊ |
179 | memoryMap->PhysicalStart = range->base;␊ |
180 | memoryMap->VirtualStart = range->base;␊ |
181 | memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;␊ |
182 | memoryMap->Attribute = 0;␊ |
183 | }␊ |
184 | ␊ |
185 | // copy bootFile into device tree␊ |
186 | // XXX␊ |
187 | ␉␊ |
188 | // add PCI info somehow into device tree␊ |
189 | // XXX␊ |
190 | ␉␊ |
191 | // Flatten device tree␊ |
192 | DT__FlattenDeviceTree(0, &size);␊ |
193 | addr = (void *)AllocateKernelMemory(size);␊ |
194 | if (addr == 0) {␊ |
195 | stop("Couldn't allocate device tree\n");␊ |
196 | }␊ |
197 | ␊ |
198 | DT__FlattenDeviceTree((void **)&addr, &size);␊ |
199 | bootArgs->deviceTreeP = (uint32_t)addr;␊ |
200 | bootArgs->deviceTreeLength = size;␊ |
201 | ␉␊ |
202 | bootArgsSnow->deviceTreeP = (uint32_t)addr;␊ |
203 | bootArgsSnow->deviceTreeLength = size;␊ |
204 | }␊ |
205 | |