]>
Commit | Line | Data |
---|---|---|
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 | ||
37 | boot_args *bootArgs; | |
38 | PrivateBootInfo_t *bootInfo; | |
39 | Node *gMemoryMapNode; | |
40 | ||
41 | static char platformName[64]; | |
42 | ||
43 | void initKernBootStruct( int biosdev ) | |
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 = kBootArgsRevision; | |
95 | ||
96 | init_done = 1; | |
97 | } | |
98 | ||
99 | // Update kernDev from biosdev. | |
100 | ||
101 | bootInfo->kernDev = biosdev; | |
102 | } | |
103 | ||
104 | ||
105 | /* Copy boot args after kernel and record address. */ | |
106 | ||
107 | void | |
108 | reserveKernBootStruct(void) | |
109 | { | |
110 | void *oldAddr = bootArgs; | |
111 | bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args)); | |
112 | bcopy(oldAddr, bootArgs, sizeof(boot_args)); | |
113 | } | |
114 | ||
115 | void | |
116 | finalizeBootStruct(void) | |
117 | { | |
118 | uint32_t size; | |
119 | void *addr; | |
120 | int i; | |
121 | EfiMemoryRange *memoryMap; | |
122 | MemoryRange *range; | |
123 | int memoryMapCount = bootInfo->memoryMapCount; | |
124 | ||
125 | if (memoryMapCount == 0) { | |
126 | // XXX could make a two-part map here | |
127 | stop("Unable to convert memory map into proper format\n"); | |
128 | } | |
129 | ||
130 | // convert memory map to boot_args memory map | |
131 | memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount); | |
132 | bootArgs->MemoryMap = memoryMap; | |
133 | bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount; | |
134 | bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange); | |
135 | bootArgs->MemoryMapDescriptorVersion = 0; | |
136 | ||
137 | for (i=0; i<memoryMapCount; i++, memoryMap++) { | |
138 | range = &bootInfo->memoryMap[i]; | |
139 | switch(range->type) { | |
140 | case kMemoryRangeACPI: | |
141 | memoryMap->Type = kEfiACPIReclaimMemory; | |
142 | break; | |
143 | case kMemoryRangeNVS: | |
144 | memoryMap->Type = kEfiACPIMemoryNVS; | |
145 | break; | |
146 | case kMemoryRangeUsable: | |
147 | memoryMap->Type = kEfiConventionalMemory; | |
148 | break; | |
149 | case kMemoryRangeReserved: | |
150 | default: | |
151 | memoryMap->Type = kEfiReservedMemoryType; | |
152 | break; | |
153 | } | |
154 | memoryMap->PhysicalStart = range->base; | |
155 | memoryMap->VirtualStart = range->base; | |
156 | memoryMap->NumberOfPages = range->length >> I386_PGSHIFT; | |
157 | memoryMap->Attribute = 0; | |
158 | } | |
159 | ||
160 | // copy bootFile into device tree | |
161 | // XXX | |
162 | ||
163 | // add PCI info somehow into device tree | |
164 | // XXX | |
165 | ||
166 | // Flatten device tree | |
167 | DT__FlattenDeviceTree(0, &size); | |
168 | addr = (void *)AllocateKernelMemory(size); | |
169 | if (addr == 0) { | |
170 | stop("Couldn't allocate device tree\n"); | |
171 | } | |
172 | ||
173 | DT__FlattenDeviceTree((void **)&addr, &size); | |
174 | bootArgs->deviceTreeP = (void *)addr; | |
175 | bootArgs->deviceTreeLength = size; | |
176 | } |