]> git.saurik.com Git - apple/boot.git/blame - i386/libsaio/bootstruct.c
boot-132.tar.gz
[apple/boot.git] / i386 / libsaio / bootstruct.c
CommitLineData
14c7c974 1/*
57c72a9a 2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
14c7c974
A
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
57c72a9a 6 * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
4f6e3300
A
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
57c72a9a 9 * Source License Version 2.0 (the "License"). You may not use this file
4f6e3300
A
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.
14c7c974
A
13 *
14 * The Original Code and all software distributed under the License are
4f6e3300 15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14c7c974
A
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
4f6e3300
A
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.
14c7c974
A
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24/*
25 * Copyright 1993 NeXT, Inc.
26 * All rights reserved.
27 */
28
14c7c974 29#include "libsaio.h"
f083c6c3 30#include "bootstruct.h"
14c7c974 31
14c7c974 32/*==========================================================================
bba600dd 33 * Initialize the structure of parameters passed to
14c7c974
A
34 * the kernel by the booter.
35 */
36
bba600dd
A
37boot_args *bootArgs;
38PrivateBootInfo_t *bootInfo;
39Node *gMemoryMapNode;
40
41static char platformName[64];
14c7c974 42
75b89a82 43void initKernBootStruct( int biosdev )
14c7c974 44{
bba600dd
A
45 Node *node;
46 int nameLen;
75b89a82 47 static int init_done = 0;
f083c6c3 48
75b89a82
A
49 if ( !init_done )
50 {
bba600dd
A
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));
f083c6c3
A
58
59 // Get system memory map. Also update the size of the
60 // conventional/extended memory for backwards compatibility.
61
bba600dd
A
62 bootInfo->memoryMapCount =
63 getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax,
64 (unsigned long *) &bootInfo->convmem,
65 (unsigned long *) &bootInfo->extmem );
f083c6c3 66
bba600dd 67 if ( bootInfo->memoryMapCount == 0 )
f083c6c3
A
68 {
69 // BIOS did not provide a memory map, systems with
70 // discontiguous memory or unusual memory hole locations
71 // may have problems.
72
bba600dd
A
73 bootInfo->convmem = getConventionalMemorySize();
74 bootInfo->extmem = getExtendedMemorySize();
f083c6c3
A
75 }
76
bba600dd
A
77 bootInfo->configEnd = bootInfo->config;
78 bootArgs->Video.v_display = VGA_TEXT_MODE;
75b89a82 79
bba600dd 80 DT__Initialize();
f083c6c3 81
bba600dd
A
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);
14c7c974 90
bba600dd 91 gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);
14c7c974 92
bba600dd
A
93 bootArgs->Version = kBootArgsVersion;
94 bootArgs->Revision = kBootArgsRevision;
95
96 init_done = 1;
97 }
14c7c974 98
f083c6c3 99 // Update kernDev from biosdev.
14c7c974 100
bba600dd 101 bootInfo->kernDev = biosdev;
f083c6c3 102}
14c7c974 103
75b89a82 104
f083c6c3
A
105/* Copy boot args after kernel and record address. */
106
107void
108reserveKernBootStruct(void)
109{
110 void *oldAddr = bootArgs;
bba600dd
A
111 bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));
112 bcopy(oldAddr, bootArgs, sizeof(boot_args));
14c7c974 113}
f083c6c3 114
bba600dd
A
115void
116finalizeBootStruct(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}