2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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
22 * @APPLE_LICENSE_HEADER_END@
25 * Copyright 1993 NeXT, Inc.
26 * All rights reserved.
30 #include "bootstruct.h"
32 /*==========================================================================
33 * Initialize the structure of parameters passed to
34 * the kernel by the booter.
38 PrivateBootInfo_t
*bootInfo
;
41 static char platformName
[64];
43 void initKernBootStruct( int biosdev
)
47 static int init_done
= 0;
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");
56 bzero(bootArgs
, sizeof(boot_args
));
57 bzero(bootInfo
, sizeof(PrivateBootInfo_t
));
59 // Get system memory map. Also update the size of the
60 // conventional/extended memory for backwards compatibility.
62 bootInfo
->memoryMapCount
=
63 getMemoryMap( bootInfo
->memoryMap
, kMemoryMapCountMax
,
64 (unsigned long *) &bootInfo
->convmem
,
65 (unsigned long *) &bootInfo
->extmem
);
67 if ( bootInfo
->memoryMapCount
== 0 )
69 // BIOS did not provide a memory map, systems with
70 // discontiguous memory or unusual memory hole locations
73 bootInfo
->convmem
= getConventionalMemorySize();
74 bootInfo
->extmem
= getExtendedMemorySize();
77 bootInfo
->configEnd
= bootInfo
->config
;
78 bootArgs
->Video
.v_display
= VGA_TEXT_MODE
;
82 node
= DT__FindNode("/", true);
84 stop("Couldn't create root node");
86 getPlatformName(platformName
);
87 nameLen
= strlen(platformName
) + 1;
88 DT__AddProperty(node
, "compatible", nameLen
, platformName
);
89 DT__AddProperty(node
, "model", nameLen
, platformName
);
91 gMemoryMapNode
= DT__FindNode("/chosen/memory-map", true);
93 bootArgs
->Version
= kBootArgsVersion
;
94 bootArgs
->Revision
= kBootArgsRevision
;
99 // Update kernDev from biosdev.
101 bootInfo
->kernDev
= biosdev
;
105 /* Copy boot args after kernel and record address. */
108 reserveKernBootStruct(void)
110 void *oldAddr
= bootArgs
;
111 bootArgs
= (boot_args
*)AllocateKernelMemory(sizeof(boot_args
));
112 bcopy(oldAddr
, bootArgs
, sizeof(boot_args
));
116 finalizeBootStruct(void)
121 EfiMemoryRange
*memoryMap
;
123 int memoryMapCount
= bootInfo
->memoryMapCount
;
125 if (memoryMapCount
== 0) {
126 // XXX could make a two-part map here
127 stop("Unable to convert memory map into proper format\n");
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;
137 for (i
=0; i
<memoryMapCount
; i
++, memoryMap
++) {
138 range
= &bootInfo
->memoryMap
[i
];
139 switch(range
->type
) {
140 case kMemoryRangeACPI
:
141 memoryMap
->Type
= kEfiACPIReclaimMemory
;
143 case kMemoryRangeNVS
:
144 memoryMap
->Type
= kEfiACPIMemoryNVS
;
146 case kMemoryRangeUsable
:
147 memoryMap
->Type
= kEfiConventionalMemory
;
149 case kMemoryRangeReserved
:
151 memoryMap
->Type
= kEfiReservedMemoryType
;
154 memoryMap
->PhysicalStart
= range
->base
;
155 memoryMap
->VirtualStart
= range
->base
;
156 memoryMap
->NumberOfPages
= range
->length
>> I386_PGSHIFT
;
157 memoryMap
->Attribute
= 0;
160 // copy bootFile into device tree
163 // add PCI info somehow into device tree
166 // Flatten device tree
167 DT__FlattenDeviceTree(0, &size
);
168 addr
= (void *)AllocateKernelMemory(size
);
170 stop("Couldn't allocate device tree\n");
173 DT__FlattenDeviceTree((void **)&addr
, &size
);
174 bootArgs
->deviceTreeP
= (void *)addr
;
175 bootArgs
->deviceTreeLength
= size
;