/*
- * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
- * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
+ * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
- * Source License Version 1.1 (the "License"). You may not use this file
+ * Source License Version 2.0 (the "License"). You may not use this file
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
* All rights reserved.
*/
-#include "io_inline.h"
#include "libsaio.h"
-#include "kernBootStruct.h"
-
-// CMOS access ports in I/O space.
-//
-#define CMOSADDR 0x70
-#define CMOSDATA 0x71
-#define HDTYPE 0x12
+#include "bootstruct.h"
/*==========================================================================
- * Returns the number of active ATA drives since these will increment the
- * bios device numbers of SCSI drives.
+ * Initialize the structure of parameters passed to
+ * the kernel by the booter.
*/
-static int
-countIDEDisks()
-{
- int count = 0;
- unsigned short hdtype;
-#if DEBUG
- struct driveParameters param;
+boot_args *bootArgs;
+PrivateBootInfo_t *bootInfo;
+Node *gMemoryMapNode;
+
+static char platformName[64];
+
+void initKernBootStruct( int biosdev )
+{
+ Node *node;
+ int nameLen;
+ static int init_done = 0;
- printf("Reading drive parameters...\n");
- readDriveParameters(0x80, ¶m);
- printf("%d fixed disk drive(s) installed\n", param.totalDrives);
- for (count = 0; count < 256; count++)
+ if ( !init_done )
{
- if (readDriveParameters(count + 0x80, ¶m))
- break;
- else
+ bootArgs = (boot_args *)malloc(sizeof(boot_args));
+ bootInfo = (PrivateBootInfo_t *)malloc(sizeof(PrivateBootInfo_t));
+ if (bootArgs == 0 || bootInfo == 0)
+ stop("Couldn't allocate boot info\n");
+
+ bzero(bootArgs, sizeof(boot_args));
+ bzero(bootInfo, sizeof(PrivateBootInfo_t));
+
+ // Get system memory map. Also update the size of the
+ // conventional/extended memory for backwards compatibility.
+
+ bootInfo->memoryMapCount =
+ getMemoryMap( bootInfo->memoryMap, kMemoryMapCountMax,
+ (unsigned long *) &bootInfo->convmem,
+ (unsigned long *) &bootInfo->extmem );
+
+ if ( bootInfo->memoryMapCount == 0 )
{
- printf("Drive %d: %d cyls, %d heads, %d sectors\n",
- count, param.cylinders, param.heads, param.sectors);
+ // BIOS did not provide a memory map, systems with
+ // discontiguous memory or unusual memory hole locations
+ // may have problems.
+
+ bootInfo->convmem = getConventionalMemorySize();
+ bootInfo->extmem = getExtendedMemorySize();
}
- }
- outb(CMOSADDR, 0x11);
- printf("CMOS addr 0x11 = %x\n",inb(CMOSDATA));
- outb(CMOSADDR, 0x12);
- printf("CMOS addr 0x12 = %x\n",inb(CMOSDATA));
- return count;
-#endif
-
- outb( CMOSADDR, HDTYPE );
- hdtype = (unsigned short) inb( CMOSDATA );
-
- if (hdtype & 0xF0) count++;
- if (hdtype & 0x0F) count++;
- return count;
-}
-/*==========================================================================
- * Initialize the 'kernBootStruct'. A structure of parameters passed to
- * the kernel by the booter.
- */
+ bootInfo->configEnd = bootInfo->config;
+ bootArgs->Video.v_display = VGA_TEXT_MODE;
+
+ DT__Initialize();
-KERNBOOTSTRUCT * kernBootStruct = (KERNBOOTSTRUCT *) KERNSTRUCT_ADDR;
+ node = DT__FindNode("/", true);
+ if (node == 0) {
+ stop("Couldn't create root node");
+ }
+ getPlatformName(platformName);
+ nameLen = strlen(platformName) + 1;
+ DT__AddProperty(node, "compatible", nameLen, platformName);
+ DT__AddProperty(node, "model", nameLen, platformName);
-void
-initKernBootStruct()
-{
- unsigned char i;
+ gMemoryMapNode = DT__FindNode("/chosen/memory-map", true);
- bzero( (char *) kernBootStruct, sizeof(*kernBootStruct) );
-
- // Get size of conventional memory.
+ bootArgs->Version = kBootArgsVersion;
+ bootArgs->Revision = kBootArgsRevision;
- kernBootStruct->convmem = memsize(0);
+ init_done = 1;
+ }
- // Get size of extended memory.
+ // Update kernDev from biosdev.
- kernBootStruct->extmem = memsize(1);
+ bootInfo->kernDev = biosdev;
+}
- // Get number of ATA devices.
- kernBootStruct->numIDEs = countIDEDisks();
+/* Copy boot args after kernel and record address. */
- // Get disk info from BIOS.
+void
+reserveKernBootStruct(void)
+{
+ void *oldAddr = bootArgs;
+ bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args));
+ bcopy(oldAddr, bootArgs, sizeof(boot_args));
+}
- for ( i = 0; i < 4; i++ )
- {
- kernBootStruct->diskInfo[i] = get_diskinfo(0x80 + i);
+void
+finalizeBootStruct(void)
+{
+ uint32_t size;
+ void *addr;
+ int i;
+ EfiMemoryRange *memoryMap;
+ MemoryRange *range;
+ int memoryMapCount = bootInfo->memoryMapCount;
+
+ if (memoryMapCount == 0) {
+ // XXX could make a two-part map here
+ stop("Unable to convert memory map into proper format\n");
+ }
+
+ // convert memory map to boot_args memory map
+ memoryMap = (EfiMemoryRange *)AllocateKernelMemory(sizeof(EfiMemoryRange) * memoryMapCount);
+ bootArgs->MemoryMap = memoryMap;
+ bootArgs->MemoryMapSize = sizeof(EfiMemoryRange) * memoryMapCount;
+ bootArgs->MemoryMapDescriptorSize = sizeof(EfiMemoryRange);
+ bootArgs->MemoryMapDescriptorVersion = 0;
+
+ for (i=0; i<memoryMapCount; i++, memoryMap++) {
+ range = &bootInfo->memoryMap[i];
+ switch(range->type) {
+ case kMemoryRangeACPI:
+ memoryMap->Type = kEfiACPIReclaimMemory;
+ break;
+ case kMemoryRangeNVS:
+ memoryMap->Type = kEfiACPIMemoryNVS;
+ break;
+ case kMemoryRangeUsable:
+ memoryMap->Type = kEfiConventionalMemory;
+ break;
+ case kMemoryRangeReserved:
+ default:
+ memoryMap->Type = kEfiReservedMemoryType;
+ break;
+ }
+ memoryMap->PhysicalStart = range->base;
+ memoryMap->VirtualStart = range->base;
+ memoryMap->NumberOfPages = range->length >> I386_PGSHIFT;
+ memoryMap->Attribute = 0;
}
- kernBootStruct->magicCookie = KERNBOOTMAGIC;
- kernBootStruct->configEnd = kernBootStruct->config;
- kernBootStruct->graphicsMode = GRAPHICS_MODE;
+ // copy bootFile into device tree
+ // XXX
+
+ // add PCI info somehow into device tree
+ // XXX
+
+ // Flatten device tree
+ DT__FlattenDeviceTree(0, &size);
+ addr = (void *)AllocateKernelMemory(size);
+ if (addr == 0) {
+ stop("Couldn't allocate device tree\n");
+ }
+
+ DT__FlattenDeviceTree((void **)&addr, &size);
+ bootArgs->deviceTreeP = (void *)addr;
+ bootArgs->deviceTreeLength = size;
}