Index: branches/Chimera/i386/libsaio/bootstruct.c =================================================================== --- branches/Chimera/i386/libsaio/bootstruct.c (revision 764) +++ branches/Chimera/i386/libsaio/bootstruct.c (revision 765) @@ -34,12 +34,18 @@ * the kernel by the booter. */ -boot_args *bootArgs; -PrivateBootInfo_t *bootInfo; -Node *gMemoryMapNode; +boot_args *bootArgs; +boot_args_pre_lion *bootArgsPreLion; +PrivateBootInfo_t *bootInfo; +Node *gMemoryMapNode; static char platformName[64]; +bool checkOSVersion(const char * version) +{ + return ((gMacOSVersion[0] == version[0]) && (gMacOSVersion[1] == version[1]) && (gMacOSVersion[2] == version[2]) && (gMacOSVersion[3] == version[3])); +} + void initKernBootStruct( void ) { Node *node; @@ -49,11 +55,13 @@ if ( !init_done ) { bootArgs = (boot_args *)malloc(sizeof(boot_args)); + bootArgsPreLion = (boot_args_pre_lion *)malloc(sizeof(boot_args_pre_lion)); 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(bootArgsPreLion, sizeof(boot_args_pre_lion)); bzero(bootInfo, sizeof(PrivateBootInfo_t)); // Get system memory map. Also update the size of the @@ -91,7 +99,10 @@ gMemoryMapNode = DT__FindNode("/chosen/memory-map", true); bootArgs->Version = kBootArgsVersion; - bootArgs->Revision = 5; + bootArgs->Revision = kBootArgsRevision; + + bootArgsPreLion->Version = kBootArgsPreLionVersion; + bootArgsPreLion->Revision = kBootArgsPreLionRevision; init_done = 1; } @@ -104,9 +115,17 @@ void reserveKernBootStruct(void) { - void *oldAddr = bootArgs; - bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args)); - bcopy(oldAddr, bootArgs, sizeof(boot_args)); + if (checkOSVersion("10.7")) + { + void *oldAddr = bootArgs; + bootArgs = (boot_args *)AllocateKernelMemory(sizeof(boot_args)); + bcopy(oldAddr, bootArgs, sizeof(boot_args)); + } + else { + void *oldAddr = bootArgsPreLion; + bootArgsPreLion = (boot_args_pre_lion *)AllocateKernelMemory(sizeof(boot_args_pre_lion)); + bcopy(oldAddr, bootArgsPreLion, sizeof(boot_args_pre_lion)); + } } void @@ -170,4 +189,31 @@ DT__FlattenDeviceTree((void **)&addr, &size); bootArgs->deviceTreeP = (uint32_t)addr; bootArgs->deviceTreeLength = size; + + // Copy BootArgs values to older structure + + memcpy(&bootArgsPreLion->CommandLine, &bootArgs->CommandLine, BOOT_LINE_LENGTH); + memcpy(&bootArgsPreLion->Video, &bootArgs->Video, sizeof(Boot_Video)); + + bootArgsPreLion->MemoryMap = bootArgs->MemoryMap; + bootArgsPreLion->MemoryMapSize = bootArgs->MemoryMapSize; + bootArgsPreLion->MemoryMapDescriptorSize = bootArgs->MemoryMapDescriptorSize; + bootArgsPreLion->MemoryMapDescriptorVersion = bootArgs->MemoryMapDescriptorVersion; + + bootArgsPreLion->deviceTreeP = bootArgs->deviceTreeP; + bootArgsPreLion->deviceTreeLength = bootArgs->deviceTreeLength; + + bootArgsPreLion->kaddr = bootArgs->kaddr; + bootArgsPreLion->ksize = bootArgs->ksize; + + bootArgsPreLion->efiRuntimeServicesPageStart = bootArgs->efiRuntimeServicesPageStart; + bootArgsPreLion->efiRuntimeServicesPageCount = bootArgs->efiRuntimeServicesPageCount; + bootArgsPreLion->efiSystemTable = bootArgs->efiSystemTable; + + bootArgsPreLion->efiMode = bootArgs->efiMode; + + bootArgsPreLion->performanceDataStart = bootArgs->performanceDataStart; + bootArgsPreLion->performanceDataSize = bootArgs->performanceDataSize; + bootArgsPreLion->efiRuntimeServicesVirtualPageStart = bootArgs->efiRuntimeServicesVirtualPageStart; + } Index: branches/Chimera/i386/libsaio/bootstruct.h =================================================================== --- branches/Chimera/i386/libsaio/bootstruct.h (revision 764) +++ branches/Chimera/i386/libsaio/bootstruct.h (revision 765) @@ -25,7 +25,7 @@ #ifndef __BOOTSTRUCT_H #define __BOOTSTRUCT_H -#include +#include "bootargs.h" #include "saio_types.h" #include "bios.h" #include "device_tree.h" @@ -34,6 +34,7 @@ Kernel boot args global also used by booter for its own data. */ extern boot_args *bootArgs; +extern boot_args_pre_lion *bootArgsPreLion; extern Node *gMemoryMapNode; #define VGA_TEXT_MODE 0 Index: branches/Chimera/i386/libsaio/bootargs.h =================================================================== --- branches/Chimera/i386/libsaio/bootargs.h (revision 0) +++ branches/Chimera/i386/libsaio/bootargs.h (revision 765) @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ + * + * 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 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ + */ +#ifndef _PEXPERT_I386_BOOT_H +#define _PEXPERT_I386_BOOT_H + +#include + +/* + * What the booter leaves behind for the kernel. + */ + +/* + * Types of boot driver that may be loaded by the booter. + */ +enum { + kBootDriverTypeInvalid = 0, + kBootDriverTypeKEXT = 1, + kBootDriverTypeMKEXT = 2 +}; + +enum { + kEfiReservedMemoryType = 0, + kEfiLoaderCode = 1, + kEfiLoaderData = 2, + kEfiBootServicesCode = 3, + kEfiBootServicesData = 4, + kEfiRuntimeServicesCode = 5, + kEfiRuntimeServicesData = 6, + kEfiConventionalMemory = 7, + kEfiUnusableMemory = 8, + kEfiACPIReclaimMemory = 9, + kEfiACPIMemoryNVS = 10, + kEfiMemoryMappedIO = 11, + kEfiMemoryMappedIOPortSpace = 12, + kEfiPalCode = 13, + kEfiMaxMemoryType = 14 +}; + +/* + * Memory range descriptor. + */ +typedef struct EfiMemoryRange { + uint32_t Type; + uint32_t Pad; + uint64_t PhysicalStart; + uint64_t VirtualStart; + uint64_t NumberOfPages; + uint64_t Attribute; +} EfiMemoryRange; + +#define BOOT_LINE_LENGTH 1024 +#define BOOT_STRING_LEN BOOT_LINE_LENGTH + +/* + * Video information.. + */ + +struct Boot_Video { + uint32_t v_baseAddr; /* Base address of video memory */ + uint32_t v_display; /* Display Code (if Applicable */ + uint32_t v_rowBytes; /* Number of bytes per pixel row */ + uint32_t v_width; /* Width */ + uint32_t v_height; /* Height */ + uint32_t v_depth; /* Pixel Depth */ +}; + +typedef struct Boot_Video Boot_Video; + +/* Values for v_display */ + +#define GRAPHICS_MODE 1 +#define FB_TEXT_MODE 2 + +/* Boot argument structure - passed into Mach kernel at boot time. + * "Revision" can be incremented for compatible changes + */ +// Lion +#define kBootArgsRevision 0 +#define kBootArgsVersion 2 + +// Snow Leopard and older +#define kBootArgsPreLionRevision 6 +#define kBootArgsPreLionVersion 1 + +/* Snapshot constants of previous revisions that are supported */ + +#define kBootArgsEfiMode32 32 +#define kBootArgsEfiMode64 64 + +typedef struct boot_args { + uint16_t Revision; /* Revision of boot_args structure */ + uint16_t Version; /* Version of boot_args structure */ + + uint8_t efiMode; /* 32 = 32-bit, 64 = 64-bit */ + uint8_t debugMode; /* Bit field with behavior changes */ + uint8_t __reserved1[2]; + + char CommandLine[BOOT_LINE_LENGTH]; /* Passed in command line */ + + uint32_t MemoryMap; /* Physical address of memory map */ + uint32_t MemoryMapSize; + uint32_t MemoryMapDescriptorSize; + uint32_t MemoryMapDescriptorVersion; + + Boot_Video Video; /* Video Information */ + + uint32_t deviceTreeP; /* Physical address of flattened device tree */ + uint32_t deviceTreeLength; /* Length of flattened tree */ + + uint32_t kaddr; /* Physical address of beginning of kernel text */ + uint32_t ksize; /* Size of combined kernel text+data+efi */ + + uint32_t efiRuntimeServicesPageStart; /* physical address of defragmented runtime pages */ + uint32_t efiRuntimeServicesPageCount; + uint64_t efiRuntimeServicesVirtualPageStart; /* virtual address of defragmented runtime pages */ + + uint32_t efiSystemTable; /* physical address of system table in runtime area */ + uint32_t __reserved2; + + uint32_t performanceDataStart; /* physical address of log */ + uint32_t performanceDataSize; + + uint32_t keyStoreDataStart; /* physical address of key store data */ + uint32_t keyStoreDataSize; + uint64_t bootMemStart; + uint64_t bootMemSize; + uint64_t PhysicalMemorySize; + uint64_t FSBFrequency; + uint32_t __reserved4[734]; + +} boot_args; + +typedef struct boot_args_pre_lion { + uint16_t Revision; /* Revision of boot_args structure */ + uint16_t Version; /* Version of boot_args structure */ + + char CommandLine[BOOT_LINE_LENGTH]; /* Passed in command line */ + + uint32_t MemoryMap; /* Physical address of memory map */ + uint32_t MemoryMapSize; + uint32_t MemoryMapDescriptorSize; + uint32_t MemoryMapDescriptorVersion; + + Boot_Video Video; /* Video Information */ + + uint32_t deviceTreeP; /* Physical address of flattened device tree */ + uint32_t deviceTreeLength; /* Length of flattened tree */ + + uint32_t kaddr; /* Physical address of beginning of kernel text */ + uint32_t ksize; /* Size of combined kernel text+data+efi */ + + uint32_t efiRuntimeServicesPageStart; /* physical address of defragmented runtime pages */ + uint32_t efiRuntimeServicesPageCount; + uint32_t efiSystemTable; /* physical address of system table in runtime area */ + + uint8_t efiMode; /* 32 = 32-bit, 64 = 64-bit */ + uint8_t __reserved1[3]; + uint32_t __reserved2[1]; + uint32_t performanceDataStart; /* physical address of log */ + uint32_t performanceDataSize; + uint64_t efiRuntimeServicesVirtualPageStart; /* virtual address of defragmented runtime pages */ + uint32_t __reserved3[2]; + +} boot_args_pre_lion; + +extern char gMacOSVersion[8]; + +#endif /* _PEXPERT_I386_BOOT_H */ Index: branches/Chimera/i386/libsaio/bios.h =================================================================== --- branches/Chimera/i386/libsaio/bios.h (revision 764) +++ branches/Chimera/i386/libsaio/bios.h (revision 765) @@ -29,7 +29,7 @@ #ifndef __LIBSAIO_BIOS_H #define __LIBSAIO_BIOS_H -#include +#include "bootargs.h" typedef union { unsigned int rx; Index: branches/Chimera/i386/libsaio/ati.c =================================================================== --- branches/Chimera/i386/libsaio/ati.c (revision 764) +++ branches/Chimera/i386/libsaio/ati.c (revision 765) @@ -85,7 +85,7 @@ /* Northern Islands */ "Barts", "Caicos", - "Cayman". + "Cayman", "Turks" }; Index: branches/Chimera/i386/libsaio/load.c =================================================================== --- branches/Chimera/i386/libsaio/load.c (revision 764) +++ branches/Chimera/i386/libsaio/load.c (revision 765) @@ -249,8 +249,7 @@ stop("Kernel overflows available space"); } - if (vmsize && (strcmp(segname, "__PRELINK") == 0)) - gHaveKernelCache = true; + if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) gHaveKernelCache = true; // Copy from file load area. if (vmsize>0 && filesize>0) Index: branches/Chimera/i386/libsaio/saio_types.h =================================================================== --- branches/Chimera/i386/libsaio/saio_types.h (revision 764) +++ branches/Chimera/i386/libsaio/saio_types.h (revision 765) @@ -30,7 +30,7 @@ #include #include "bios.h" #include "nbp_cmd.h" -#include +#include "bootargs.h" #if DEBUG #define DEBUG_DISK(x) printf x Index: branches/Chimera/i386/libsaio/fake_efi.c =================================================================== --- branches/Chimera/i386/libsaio/fake_efi.c (revision 764) +++ branches/Chimera/i386/libsaio/fake_efi.c (revision 765) @@ -76,8 +76,10 @@ */ /* Identify ourselves as the EFI firmware vendor */ -static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'C','h','i','m','e','r','a','_','1','.','1', 0}; -static EFI_UINT32 const FIRMWARE_REVISION = 132; /* FIXME: Find a constant for this. */ +static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'A','p','p','l','e'}; +static EFI_UINT32 const FIRMWARE_REVISION = 0x0001000a; +//static EFI_CHAR16 const FIRMWARE_VENDOR[] = {'C','h','i','m','e','r','a','_','1','.','1', 0}; +//static EFI_UINT32 const FIRMWARE_REVISION = 132; /* FIXME: Find a constant for this. */ /* Default platform system_id (fix by IntVar) */ static EFI_CHAR8 const SYSTEM_ID[] = "0123456789ABCDEF"; //random value gen by uuidgen @@ -437,8 +439,8 @@ static const char const SYSTEM_SERIAL_PROP[] = "SystemSerialNumber"; static const char const SYSTEM_TYPE_PROP[] = "system-type"; static const char const MODEL_PROP[] = "Model"; +static const char const BOARDID_PROP[] = "board-id"; - /* * Get an smbios option string option to convert to EFI_CHAR16 string */ @@ -621,6 +623,22 @@ } /* + * Must be called AFTER getSmbios + */ + +void setupBoardId() +{ + Node *node; + node = DT__FindNode("/", false); + if (node == 0) { + stop("Couldn't get root node"); + } + const char *boardid = getStringForKey("SMboardproduct", &bootInfo->smbiosConfig); + if (boardid) + DT__AddProperty(node, BOARDID_PROP, strlen(boardid)+1, (EFI_CHAR16*)boardid); +} + +/* * Load the smbios.plist override config file if any */ @@ -672,6 +690,8 @@ smbios_p = (EFI_PTR32)getSmbios(SMBIOS_PATCHED); addConfigurationTable(&gEfiSmbiosTableGuid, &smbios_p, NULL); + setupBoardId(); //need to be called after getSmbios + // Setup ACPI with DSDT overrides (mackerintel's patch) setupAcpi(); Index: branches/Chimera/i386/libsaio/saio_internal.h =================================================================== --- branches/Chimera/i386/libsaio/saio_internal.h (revision 764) +++ branches/Chimera/i386/libsaio/saio_internal.h (revision 765) @@ -75,6 +75,7 @@ extern void sleep(int n); /* bootstruct.c */ +extern bool checkOSVersion(const char * version); extern void initKernBootStruct(void); extern void reserveKernBootStruct(void); extern void copyKernBootStruct(void); Index: branches/Chimera/i386/boot2/boot.c =================================================================== --- branches/Chimera/i386/boot2/boot.c (revision 764) +++ branches/Chimera/i386/boot2/boot.c (revision 765) @@ -94,7 +94,9 @@ /* * Default path to kernel cache file */ -#define kDefaultCachePath "/System/Library/Caches/com.apple.kernelcaches/kernelcache" +//Slice - first one for Leopard +#define kDefaultCachePathLeo "/System/Library/Caches/com.apple.kernelcaches/" +#define kDefaultCachePathSnow "/System/Library/Caches/com.apple.kext.caches/Startup/" //========================================================================== // Zero the BSS. @@ -195,12 +197,24 @@ setupBooterLog(); - finalizeBootStruct(); - - // Jump to kernel's entry point. There's no going back now. - - startprog( kernelEntry, bootArgs ); - + finalizeBootStruct(); + + if (checkOSVersion("10.7")) { + + // Masking out so that Lion doesn't doublefault + outb(0x21, 0xff); /* Maskout all interrupts Pic1 */ + outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */ + + // Jump to kernel's entry point. There's no going back now. + + startprog( kernelEntry, bootArgs ); + } + else { + // Jump to kernel's entry point. There's no going back now. + + startprog( kernelEntry, bootArgsPreLion ); + } + // Not reached return 0; @@ -462,7 +476,35 @@ if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) { strlcpy(gBootKernelCacheFile, val, len+1); } else { - sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePath, adler32); + //Lion + if (checkOSVersion("10.7")) { + sprintf(gBootKernelCacheFile, "%skernelcache", kDefaultCachePathSnow); + } + // Snow Leopard + else if (checkOSVersion("10.6")) { + sprintf(gBootKernelCacheFile, "kernelcache_%s", (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64"); //, adler32); + int lnam = sizeof(gBootKernelCacheFile) + 9; //with adler32 + //Slice - TODO + /* + - but the name is longer .adler32 and more... + kernelcache_i386.E102928C.qSs0 + so will opendir and scan for some files + */ + char* name; + long prev_time = 0; + + struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow); + + while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0) + { + if(((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time && strstr(name, gBootKernelCacheFile) && (name[lnam] != '.')) + { + sprintf(gBootKernelCacheFile, "%s%s", kDefaultCachePathSnow, name); + prev_time = time; + } + } + } + else sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePathLeo, adler32); } // Check for cache file. @@ -502,17 +544,30 @@ break; } } while (0); - + + if (getValueForKey("-usecache", &val, &len, &bootInfo->bootConfig)) + trycache=1; + do { if (trycache) { bootFile = gBootKernelCacheFile; + verbose("Loading kernel cache %s\n", bootFile); - ret = LoadFile(bootFile); - binary = (void *)kLoadAddr; - if (ret >= 0) { + + if (checkOSVersion("10.7")) { + ret = LoadThinFatFile(bootFile, &binary); + } + else { + ret = LoadFile(bootFile); + binary = (void *)kLoadAddr; + } + + if (ret >= 0) break; - } + + verbose("Kernel cache did not loaded %s\n ", bootFile); } + bootFile = bootInfo->bootFile; // Try to load kernel image from alternate locations on boot helper partitions. @@ -534,13 +589,28 @@ } } - verbose("Loading kernel %s\n", bootFileSpec); - ret = LoadThinFatFile(bootFileSpec, &binary); - if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) + if (checkOSVersion("10.7")) { - archCpuType = CPU_TYPE_I386; - ret = LoadThinFatFile(bootFileSpec, &binary); - } + // Lion, dont load kernel if you have cache + if (!trycache) { + verbose("Loading kernel %s\n", bootFileSpec); + ret = LoadThinFatFile(bootFileSpec, &binary); + if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) { + archCpuType = CPU_TYPE_I386; + ret = LoadThinFatFile(bootFileSpec, &binary); + } + } + else ret = 1; + } + else { + // Snow Leopard or older + verbose("Loading kernel %s\n", bootFileSpec); + ret = LoadThinFatFile(bootFileSpec, &binary); + if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) { + archCpuType = CPU_TYPE_I386; + ret = LoadThinFatFile(bootFileSpec, &binary); + } + } } while (0); Index: branches/Chimera/i386/boot2/boot.h =================================================================== --- branches/Chimera/i386/boot2/boot.h (revision 764) +++ branches/Chimera/i386/boot2/boot.h (revision 765) @@ -196,6 +196,7 @@ /* * drivers.c */ +extern long LoadExtraDrivers(char * dirSpec); extern long LoadDrivers(char * dirSpec); extern long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize); Index: branches/Chimera/i386/boot2/drivers.c =================================================================== --- branches/Chimera/i386/boot2/drivers.c (revision 764) +++ branches/Chimera/i386/boot2/drivers.c (revision 765) @@ -39,7 +39,7 @@ #include "xml.h" #include "ramdisk.h" -extern char gMacOSVersion; +//extern char gMacOSVersion; struct Module { struct Module *nextModule; Index: branches/Chimera/i386/boot2/Makefile =================================================================== --- branches/Chimera/i386/boot2/Makefile (revision 764) +++ branches/Chimera/i386/boot2/Makefile (revision 765) @@ -81,7 +81,9 @@ @echo "#define I386BOOT_VERSION \"5.0.132\"" > $(SYMROOT)/vers.h @echo "#define I386BOOT_BUILDDATE \"`date \"+%Y-%m-%d %H:%M:%S\"`\"" >> $(SYMROOT)/vers.h @echo "#define I386BOOT_CHAMELEONVERSION \"`cat ../../version`\"" >> $(SYMROOT)/vers.h - @echo "#define I386BOOT_CHAMELEONREVISION \"`svnversion -n | tr -d [:alpha:]`\"" >> $(SYMROOT)/vers.h +# @echo "#define I386BOOT_CHAMELEONREVISION \"`svnversion -n | tr -d [:alpha:]`\"" >> $(SYMROOT)/vers.h +# Following is only when using git instead of svn + @echo "#define I386BOOT_CHAMELEONREVISION \"`cat ../../revision`\"" >> $(SYMROOT)/vers.h art.h: @if [ "$(PNGCRUSH)" ]; then \ Index: branches/Chimera/revision =================================================================== --- branches/Chimera/revision (revision 0) +++ branches/Chimera/revision (revision 765) @@ -0,0 +1 @@ +759 \ No newline at end of file