From 71019aa06eea45d05e1aa2efb1835c3ac831548e Mon Sep 17 00:00:00 2001 From: Apple Date: Wed, 17 Sep 2003 23:55:31 +0000 Subject: [PATCH] BootX-55.1.tar.gz --- bootx.tproj/Makefile | 2 +- bootx.tproj/Makefile.preamble | 2 +- bootx.tproj/PB.project | 2 +- bootx.tproj/bootinfo.hdr | 2 +- bootx.tproj/fs.subproj/cache.c | 6 +- bootx.tproj/fs.subproj/ufs.c | 32 +---- bootx.tproj/fs.subproj/ufs_byteorder.c | 96 --------------- bootx.tproj/fs.subproj/ufs_byteorder.h | 5 - bootx.tproj/include.subproj/boot_args.h | 5 +- bootx.tproj/include.subproj/sl.h | 59 ++++----- bootx.tproj/libclite.subproj/zalloc.c | 4 +- bootx.tproj/sl.subproj/drivers.c | 25 +++- bootx.tproj/sl.subproj/elf.c | 17 ++- bootx.tproj/sl.subproj/macho.c | 65 ++++++---- bootx.tproj/sl.subproj/main.c | 156 ++++++++++++++++++++---- bootx.tproj/sl.subproj/netboot.h | 4 +- 16 files changed, 250 insertions(+), 232 deletions(-) diff --git a/bootx.tproj/Makefile b/bootx.tproj/Makefile index 597db30..b63380a 100644 --- a/bootx.tproj/Makefile +++ b/bootx.tproj/Makefile @@ -31,7 +31,7 @@ PROF_LIBS = $(LIBS) HEADER_PATHS = -I$(SRCROOT)/bootx.tproj/include.subproj NEXTSTEP_PB_CFLAGS = -static -NEXTSTEP_PB_LDFLAGS = -nostdlib -e _StartTVector -seg1addr 01C00000 +NEXTSTEP_PB_LDFLAGS = -nostdlib -e _StartTVector -seg1addr 05600000 NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc diff --git a/bootx.tproj/Makefile.preamble b/bootx.tproj/Makefile.preamble index adaff0b..df4d732 100644 --- a/bootx.tproj/Makefile.preamble +++ b/bootx.tproj/Makefile.preamble @@ -127,7 +127,7 @@ LIBRARY_STYLE = STATIC # To include a version string, project source must exist in a directory named # $(NAME).%d[.%d][.%d] and the following line must be uncommented. -# OTHER_GENERATED_OFILES = $(VERS_OFILE) +OTHER_GENERATED_OFILES = $(VERS_OFILE) # This definition will suppress stripping of debug symbols when an executable # is installed. By default it is YES. diff --git a/bootx.tproj/PB.project b/bootx.tproj/PB.project index d1eeb5f..68d28a5 100644 --- a/bootx.tproj/PB.project +++ b/bootx.tproj/PB.project @@ -21,7 +21,7 @@ NEXTSTEP_COMPILEROPTIONS = "-static"; NEXTSTEP_INSTALLDIR = /bin; NEXTSTEP_JAVA_COMPILER = /usr/bin/javac; - NEXTSTEP_LINKEROPTIONS = "-nostdlib -e _StartTVector -seg1addr 01C00000"; + NEXTSTEP_LINKEROPTIONS = "-nostdlib -e _StartTVector -seg1addr 05600000"; NEXTSTEP_OBJCPLUS_COMPILER = /usr/bin/cc; PDO_UNIX_BUILDTOOL = $NEXT_ROOT/Developer/bin/make; PDO_UNIX_INSTALLDIR = /bin; diff --git a/bootx.tproj/bootinfo.hdr b/bootx.tproj/bootinfo.hdr index 865b2e2..4c18cdd 100644 --- a/bootx.tproj/bootinfo.hdr +++ b/bootx.tproj/bootinfo.hdr @@ -1,6 +1,6 @@ -MacRISC MacRISC3 +MacRISC MacRISC3 MacRISC4 Boot Loader for Mac OS X. diff --git a/bootx.tproj/fs.subproj/cache.c b/bootx.tproj/fs.subproj/cache.c index e60d0a5..d3f6930 100644 --- a/bootx.tproj/fs.subproj/cache.c +++ b/bootx.tproj/fs.subproj/cache.c @@ -25,7 +25,7 @@ /* * cache.c - A simple cache for file systems meta-data. * - * Copyright (c) 2000 Apple Computer, Inc. + * Copyright (c) 2000 - 2003 Apple Computer, Inc. * * DRI: Josh de Cesare */ @@ -40,7 +40,7 @@ struct CacheEntry { }; typedef struct CacheEntry CacheEntry; -#define kCacheSize (0x80000) +#define kCacheSize (kFSCacheSize) #define kCacheMinBlockSize (0x200) #define kCacheMaxBlockSize (0x4000) #define kCacheMaxEntries (kCacheSize / kCacheMinBlockSize) @@ -50,7 +50,7 @@ static long gCacheBlockSize; static long gCacheNumEntries; static long gCacheTime; static CacheEntry gCacheEntries[kCacheMaxEntries]; -static char gCacheBuffer[kCacheSize]; +static char *gCacheBuffer = (char *)kFSCacheAddr; unsigned long gCacheHits; unsigned long gCacheMisses; diff --git a/bootx.tproj/fs.subproj/ufs.c b/bootx.tproj/fs.subproj/ufs.c index da528f2..77abab5 100644 --- a/bootx.tproj/fs.subproj/ufs.c +++ b/bootx.tproj/fs.subproj/ufs.c @@ -52,12 +52,8 @@ static char *ReadFileBlock(InodePtr fileInode, long fragNum, long blockOffset, static long ReadFile(InodePtr fileInode, long *length); -#define kDevBlockSize (0x200) // Size of each disk block. -#define kDiskLableBlock (15) // Block the DL is in. - static CICell gCurrentIH; static long long gPartitionBase; -static char gDLBuf[8192]; static char gFSBuf[SBSIZE]; static struct fs *gFS; static long gBlockSize; @@ -74,9 +70,6 @@ static Inode gFileInode; long UFSInitPartition(CICell ih) { - disk_label_t *dl; - partition_t *part; - if (ih == gCurrentIH) return 0; printf("UFSInitPartition: %x\n", ih); @@ -92,30 +85,7 @@ long UFSInitPartition(CICell ih) gFS = (struct fs *)gFSBuf; if (gFS->fs_magic != FS_MAGIC) { - // Did not find it... Look for the Disk Label. - // Look for the Disk Label - Seek(ih, 1ULL * kDevBlockSize * kDiskLableBlock); - Read(ih, (long)gDLBuf, 8192); - - dl = (disk_label_t *)gDLBuf; - byte_swap_disklabel_in(dl); - - if (dl->dl_version != DL_VERSION) { - return -1; - } - - part = &dl->dl_part[0]; - gPartitionBase = (1ULL * (dl->dl_front + part->p_base) * dl->dl_secsize) - - (1ULL * (dl->dl_label_blkno - kDiskLableBlock) * kDevBlockSize); - - // Re-read the Super Block. - Seek(ih, gPartitionBase + SBOFF); - Read(ih, (long)gFSBuf, SBSIZE); - - gFS = (struct fs *)gFSBuf; - if (gFS->fs_magic != FS_MAGIC) { - return -1; - } + return -1; } // Calculate the block size and set up the block cache. diff --git a/bootx.tproj/fs.subproj/ufs_byteorder.c b/bootx.tproj/fs.subproj/ufs_byteorder.c index e2a4a03..789e7db 100644 --- a/bootx.tproj/fs.subproj/ufs_byteorder.c +++ b/bootx.tproj/fs.subproj/ufs_byteorder.c @@ -77,102 +77,6 @@ byte_swap_superblock(struct fs *sb) } -static inline void -byte_swap_disklabel_common(disk_label_t *dl) -{ - - swapBigLongToHost(dl->dl_version); /* ditto */ - swapBigLongToHost(dl->dl_label_blkno); - swapBigLongToHost(dl->dl_size); - swapBigLongToHost(dl->dl_flags); - swapBigLongToHost(dl->dl_tag); -// swapBigShortToHost(dl->dl_checksum); -// if (dl->dl_version >= DL_V3) -// swapBigShortToHost(dl->dl_un.DL_v3_checksum); -// else -// swapBigIntsToHost(dl->dl_un.DL_bad, NBAD); - -} - - -void -byte_swap_disklabel_in(disk_label_t *dl) -{ - - byte_swap_disklabel_common(dl); - byte_swap_disktab_in(&dl->dl_dt); - -} - - -static inline void -byte_swap_disktab_common(struct disktab *dt) -{ - - register unsigned int i; - - swapBigLongToHost(dt->d_secsize); - swapBigLongToHost(dt->d_ntracks); - swapBigLongToHost(dt->d_nsectors); - swapBigLongToHost(dt->d_ncylinders); -// swapBigLongToHost(dt->d_rpm); - swapBigShortToHost(dt->d_front); - swapBigShortToHost(dt->d_back); -// swapBigShortToHost(dt->d_ngroups); -// swapBigShortToHost(dt->d_ag_size); -// swapBigShortToHost(dt->d_ag_alts); -// swapBigShortToHost(dt->d_ag_off); -// swapBigIntsToHost(dt->d_boot0_blkno, NBOOTS); - - for (i=0; i < NPART; i++) - byte_swap_partition(&dt->d_partitions[i]); - -} - -/* - * This is particularly grody. The beginning of the partition array is two - * bytes low on the 68 wrt natural alignment rules. Furthermore, each - * element of the partition table is two bytes smaller on 68k due to padding - * at the end of the struct. - */ -void -byte_swap_disktab_in(struct disktab *dt) -{ - - struct partition *pp; - int i; - - /* - * Shift each struct partition up in memory by 2 + 2 * offset bytes. - * Do it backwards so we don't overwrite anything. - */ - for (i=NPART - 1; i >=0; i--) { - struct partition temp; - pp = &dt->d_partitions[i]; - /* beware: compiler doesn't do overlapping struct assignment */ - temp = *(struct partition *)(((char *) pp) - 2 * (i + 1)); - *pp = temp; - } - - byte_swap_disktab_common(dt); - -} - - -void -byte_swap_partition(struct partition *part) -{ - - swapBigLongToHost(part->p_base); - swapBigLongToHost(part->p_size); - swapBigShortToHost(part->p_bsize); - swapBigShortToHost(part->p_fsize); - swapBigShortToHost(part->p_cpg); - swapBigShortToHost(part->p_density); - -} - - void byte_swap_inode_in(struct dinode *dc, struct dinode *ic) { diff --git a/bootx.tproj/fs.subproj/ufs_byteorder.h b/bootx.tproj/fs.subproj/ufs_byteorder.h index db20f97..56685b9 100644 --- a/bootx.tproj/fs.subproj/ufs_byteorder.h +++ b/bootx.tproj/fs.subproj/ufs_byteorder.h @@ -43,10 +43,8 @@ #include #include -#include #include #include -#include #include #include #include @@ -54,8 +52,5 @@ void byte_swap_ints(int *array, int count); void byte_swap_shorts(short *array, int count); -void byte_swap_disklabel_in(disk_label_t *dl); -void byte_swap_disktab_in(struct disktab *dt); -void byte_swap_partition(struct partition *part); void byte_swap_inode_in(struct dinode *dc, struct dinode *ic); void byte_swap_dir_block_in(char *addr, int count); diff --git a/bootx.tproj/include.subproj/boot_args.h b/bootx.tproj/include.subproj/boot_args.h index 5277f01..c206930 100644 --- a/bootx.tproj/include.subproj/boot_args.h +++ b/bootx.tproj/include.subproj/boot_args.h @@ -25,7 +25,7 @@ /* * boot_args.h - Data stuctures for the information passed to the kernel. * - * Copyright (c) 1998-2000 Apple Computer, Inc. + * Copyright (c) 1998-2003 Apple Computer, Inc. * * DRI: Josh de Cesare */ @@ -59,7 +59,8 @@ typedef struct DRAMBank DRAMBank, *DRAMBankPtr; // Boot argument structure - passed into kernel at boot time. #define kBootArgsRevision (1) -#define kBootArgsVersion (1) +#define kBootArgsVersion1 (1) +#define kBootArgsVersion2 (2) #define BOOT_LINE_LENGTH (256) diff --git a/bootx.tproj/include.subproj/sl.h b/bootx.tproj/include.subproj/sl.h index c5e4b6f..952ff4c 100644 --- a/bootx.tproj/include.subproj/sl.h +++ b/bootx.tproj/include.subproj/sl.h @@ -25,7 +25,7 @@ /* * sl.h - Headers for configuring the Secondary Loader * - * Copyright (c) 1998-2002 Apple Computer, Inc. + * Copyright (c) 1998-2003 Apple Computer, Inc. * * DRI: Josh de Cesare */ @@ -37,32 +37,25 @@ /* -Memory Map... Assumes 32 MB +Memory Map: assumes 96 MB Physical Address -Open Firmware Version 1x, 2x 3x -00000000 - 00003FFF : Exception Vectors -00004000 - 002FFFFF : Free Memory -00300000 - 004FFFFF : OF Image / Free Memory -00500000 - 01DFFFFF : Free Memory -01E00000 - 01FFFFFF : Free Memory / OF Image +Open Firmware Version 3x, 4x, ... +00000000 - 00003FFF : Exception Vectors +00004000 - 057FFFFF : Free Memory +05800000 - 05FFFFFF : OF Image Logical Address 00000000 - 00003FFF : Exception Vectors -00004000 - 013FFFFF : Kernel Image, Boot Struct and Drivers -01400000 - 01BFFFFF : File Load Area -01C00000 - 01CFFFFF : Secondary Loader Image -01D00000 - 01DFFFFF : Malloc Area -01E00000 - 01FFFFFF : Unused - -To provide a consistant Logical Memory Usage between OF 1,2 and OF 3 -the Logical Addresses 0x00300000 - 0x004FFFFF will be mapped to -Physical Address 0x01E00000 - 0x01FFFFFF and will be copied back -just before the kernel is loaded. - +00004000 - 03FFFFFF : Kernel Image, Boot Struct and Drivers +04000000 - 04FFFFFF : File Load Area +05000000 - 053FFFFF : FS Cache +05400000 - 055FFFFF : Malloc Zone +05600000 - 057FFFFF : BootX Image +05800000 - 05FFFFFF : Unused */ @@ -71,22 +64,25 @@ just before the kernel is loaded. // OF 3.x #define kImageAddr (0x00004000) -#define kImageSize (0x013FC000) +#define kImageSize (0x03FFC000) // OF 1.x 2.x #define kImageAddr0 (0x00004000) #define kImageSize0 (0x002FC000) #define kImageAddr1 (0x00300000) #define kImageSize1 (0x00200000) -#define kImageAddr1Phys (0x01E00000) +#define kImageAddr1Phys (0x05800000) #define kImageAddr2 (0x00500000) -#define kImageSize2 (0x00F00000) +#define kImageSize2 (0x03B00000) -#define kLoadAddr (0x01400000) -#define kLoadSize (0x00800000) +#define kLoadAddr (0x04000000) +#define kLoadSize (0x01000000) -#define kMallocAddr (0x01D00000) -#define kMallocSize (0x00100000) +#define kFSCacheAddr (0x05000000) +#define kFSCacheSize (0x00400000) + +#define kMallocAddr (0x05400000) +#define kMallocSize (0x00200000) // Default Output Level #define kOutputLevelOff (0) @@ -96,6 +92,7 @@ just before the kernel is loaded. #define kOFVersion1x (0x01000000) #define kOFVersion2x (0x02000000) #define kOFVersion3x (0x03000000) +#define kOFVersion4x (0x04000000) // Device Types enum { @@ -174,6 +171,9 @@ extern long gOFVersion; extern char *gKeyMap; +extern long gRootAddrCells; +extern long gRootSizeCells; + extern CICell gChosenPH; extern CICell gOptionsPH; extern CICell gScreenPH; @@ -185,6 +185,7 @@ extern CICell gMemoryIH; extern CICell gStdOutIH; extern CICell gKeyboardIH; +extern long ThinFatBinary(void **binary, unsigned long *length); extern long GetDeviceType(char *devSpec); extern long ConvertFileSpec(char *fileSpec, char *devSpec, char **filePath); extern long MatchThis(CICell phandle, char *string); @@ -194,10 +195,12 @@ extern long AllocateMemoryRange(char *rangeName, long start, long length); extern unsigned long Alder32(unsigned char *buffer, long length); // Externs for macho.c -extern long DecodeMachO(void); +extern long ThinFatBinaryMachO(void **binary, unsigned long *length); +extern long DecodeMachO(void *binary); // Externs for elf.c -extern long DecodeElf(void); +extern long ThinFatBinaryElf(void **binary, unsigned long *length); +extern long DecodeElf(void *binary); // Externs for device_tree.c extern long FlattenDeviceTree(void); diff --git a/bootx.tproj/libclite.subproj/zalloc.c b/bootx.tproj/libclite.subproj/zalloc.c index 571fec3..200b6c5 100644 --- a/bootx.tproj/libclite.subproj/zalloc.c +++ b/bootx.tproj/libclite.subproj/zalloc.c @@ -32,14 +32,14 @@ /* * zalloc.c - malloc functions. * - * Copyright (c) 1998-2000 Apple Computer, Inc. + * Copyright (c) 1998-2003 Apple Computer, Inc. * * DRI: Josh de Cesare */ #include -#define ZALLOC_NODES 384 +#define ZALLOC_NODES 768 #define ZDEBUG 0 diff --git a/bootx.tproj/sl.subproj/drivers.c b/bootx.tproj/sl.subproj/drivers.c index 71b1f6f..bfd70b6 100644 --- a/bootx.tproj/sl.subproj/drivers.c +++ b/bootx.tproj/sl.subproj/drivers.c @@ -32,6 +32,8 @@ #include +#define DRIVER_DEBUG 0 + enum { kTagTypeNone = 0, kTagTypeDict, @@ -133,7 +135,9 @@ static TagPtr NewTag(void); static void FreeTag(TagPtr tag); static char *NewSymbol(char *string); static void FreeSymbol(char *string); +#if DRIVER_DEBUG static void DumpTag(TagPtr tag, long depth); +#endif static ModulePtr gModuleHead, gModuleTail; static TagPtr gPersonalityHead, gPersonalityTail; @@ -259,12 +263,15 @@ static long NetLoadDrivers(char *dirSpec) static long LoadDriverMKext(char *fileSpec) { - long driversAddr, driversLength; + unsigned long driversAddr, driversLength, length; char segName[32]; DriversPackage *package = (DriversPackage *)kLoadAddr; // Load the MKext. - if (LoadFile(fileSpec) == -1) return -1; + length = LoadFile(fileSpec); + if (length == -1) return -1; + + ThinFatBinary((void **)&package, &length); // Verify the MKext. if ((package->signature1 != kDriverPackageSignature1) || @@ -278,7 +285,7 @@ static long LoadDriverMKext(char *fileSpec) driversAddr = AllocateKernelMemory(driversLength); // Copy the MKext. - memcpy((void *)driversAddr, (void *)kLoadAddr, driversLength); + memcpy((void *)driversAddr, (void *)package, driversLength); // Add the MKext to the memory map. sprintf(segName, "DriversPackage-%x", driversAddr); @@ -373,7 +380,8 @@ static long LoadMatchedModules(void) ModulePtr module; char *fileName, segName[32]; DriverInfoPtr driver; - long length, driverAddr, driverLength; + unsigned long length, driverAddr, driverLength; + void *driverModuleAddr; module = gModuleHead; while (module != 0) { @@ -385,6 +393,11 @@ static long LoadMatchedModules(void) length = LoadFile(gFileSpec); } else length = 0; if (length != -1) { + if (length != 0) { + driverModuleAddr = (void *)kLoadAddr; + ThinFatBinary(&driverModuleAddr, &length); + } + // Make make in the image area. driverLength = sizeof(DriverInfo) + module->plistLength + length; driverAddr = AllocateKernelMemory(driverLength); @@ -405,7 +418,7 @@ static long LoadMatchedModules(void) // Save the plist and module. strcpy(driver->plistAddr, module->plistAddr); if (length != 0) { - memcpy(driver->moduleAddr, (void *)kLoadAddr, driver->moduleLength); + memcpy(driver->moduleAddr, driverModuleAddr, driver->moduleLength); } // Add an entry to the memory map. @@ -1002,7 +1015,7 @@ static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol) return symbol; } -#if 0 +#if DRIVER_DEBUG static void DumpTagDict(TagPtr tag, long depth); static void DumpTagKey(TagPtr tag, long depth); static void DumpTagString(TagPtr tag, long depth); diff --git a/bootx.tproj/sl.subproj/elf.c b/bootx.tproj/sl.subproj/elf.c index f7f6d6a..0b8f6e1 100644 --- a/bootx.tproj/sl.subproj/elf.c +++ b/bootx.tproj/sl.subproj/elf.c @@ -36,19 +36,24 @@ // Public Functions -long DecodeElf(void) +long ThinFatBinaryElf(void **binary, unsigned long *length) +{ + return -1; +} + +long DecodeElf(void *binary) { ElfHeaderPtr ehPtr; ProgramHeaderPtr phPtr; long cnt, paddr, offset, memsz, filesz, entry, *tmp; - ehPtr = (ElfHeaderPtr)kLoadAddr; + ehPtr = (ElfHeaderPtr)binary; if (ehPtr->signature != kElfSignature) return 0; entry = ehPtr->entry & kElfAddressMask; for (cnt = 0; cnt < ehPtr->phnum; cnt++) { - phPtr = (ProgramHeaderPtr)(kLoadAddr+ehPtr->phoff+cnt*ehPtr->phentsize); + phPtr = (ProgramHeaderPtr)((unsigned long)binary + ehPtr->phoff + cnt * ehPtr->phentsize); if (phPtr->type == kElfProgramTypeLoad) { paddr = phPtr->paddr & kElfAddressMask; @@ -58,7 +63,7 @@ long DecodeElf(void) // Get the actual entry if it is in this program. if ((entry >= paddr) && (entry < (paddr + filesz))) { - tmp = (long *)(kLoadAddr + offset + entry); + tmp = (long *)((unsigned long)binary + offset + entry); if (tmp[2] == 0) entry += tmp[0]; } @@ -72,7 +77,7 @@ long DecodeElf(void) if (paddr < kImageAddr) { // Copy the Vectors out of the way. - bcopy((char *)(kLoadAddr + offset), gVectorSaveAddr, + bcopy((char *)((unsigned long)binary + offset), gVectorSaveAddr, kVectorSize - paddr); offset += kImageAddr - paddr; @@ -81,7 +86,7 @@ long DecodeElf(void) } // Move the program. - bcopy((char *)(kLoadAddr + offset), (char *)paddr, filesz); + bcopy((char *)((unsigned long)binary + offset), (char *)paddr, filesz); } } diff --git a/bootx.tproj/sl.subproj/macho.c b/bootx.tproj/sl.subproj/macho.c index 2960404..5aa36cd 100644 --- a/bootx.tproj/sl.subproj/macho.c +++ b/bootx.tproj/sl.subproj/macho.c @@ -25,7 +25,7 @@ /* * macho.c - Functions for decoding a Mach-o Kernel. * - * Copyright (c) 1998-2000 Apple Computer, Inc. + * Copyright (c) 1998-2003 Apple Computer, Inc. * * DRI: Josh de Cesare */ @@ -40,33 +40,56 @@ static long DecodeSegment(long cmdBase); static long DecodeUnixThread(long cmdBase); static long DecodeSymbolTable(long cmdBase); -static long gPPCOffset; +static unsigned long gPPCAddress; // Public Functions -long DecodeMachO(void) +long ThinFatBinaryMachO(void **binary, unsigned long *length) +{ + unsigned long nfat, swapped, size; + struct fat_header *fhp = (struct fat_header *)*binary; + struct fat_arch *fap = + (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header)); + + if (fhp->magic == FAT_MAGIC) { + nfat = fhp->nfat_arch; + swapped = 0; + } else if (fhp->magic == FAT_CIGAM) { + nfat = NXSwapInt(fhp->nfat_arch); + swapped = 1; + } else { + return -1; + } + + for (; nfat > 0; nfat--, fap++) { + if (swapped) { + fap->cputype = NXSwapInt(fap->cputype); + fap->offset = NXSwapInt(fap->offset); + fap->size = NXSwapInt(fap->size); + } + + if (fap->cputype == CPU_TYPE_POWERPC) { + *binary = (void *) ((unsigned long)*binary + fap->offset); + size = fap->size; + break; + } + } + + if (length != 0) *length = size; + + return 0; +} + +long DecodeMachO(void *binary) { - struct fat_header *fH; - struct fat_arch *fA; struct mach_header *mH; long ncmds, cmdBase, cmd, cmdsize, headerBase, headerAddr, headerSize; long cnt, ret; - // Test for a fat header. - fH = (struct fat_header *)kLoadAddr; - if (fH->magic == FAT_MAGIC) { - fA = (struct fat_arch *)(kLoadAddr + sizeof(struct fat_header)); - // see if the there is one for PPC. - for (cnt = 0; cnt < fH->nfat_arch; cnt++) { - if (fA[cnt].cputype == CPU_TYPE_POWERPC) { - gPPCOffset = fA[cnt].offset; - } - } - } + gPPCAddress = (unsigned long)binary; - // offset will be the start of the - headerBase = kLoadAddr + gPPCOffset; - cmdBase = headerBase+ sizeof(struct mach_header); + headerBase = gPPCAddress; + cmdBase = headerBase + sizeof(struct mach_header); mH = (struct mach_header *)(headerBase); if (mH->magic != MH_MAGIC) return -1; @@ -136,7 +159,7 @@ static long DecodeSegment(long cmdBase) vmaddr = (char *)segCmd->vmaddr; vmsize = segCmd->vmsize; - fileaddr = (char *)(kLoadAddr + gPPCOffset + segCmd->fileoff); + fileaddr = (char *)(gPPCAddress + segCmd->fileoff); filesize = segCmd->filesize; #if 0 @@ -231,7 +254,7 @@ static long DecodeSymbolTable(long cmdBase) symTableSave->stroff = tmpAddr + symsSize; symTableSave->strsize = symTab->strsize; - bcopy((char *)(kLoadAddr + gPPCOffset + symTab->symoff), + bcopy((char *)(gPPCAddress + symTab->symoff), (char *)tmpAddr, totalSize); return 0; diff --git a/bootx.tproj/sl.subproj/main.c b/bootx.tproj/sl.subproj/main.c index d9a6767..f4b8fae 100644 --- a/bootx.tproj/sl.subproj/main.c +++ b/bootx.tproj/sl.subproj/main.c @@ -25,7 +25,7 @@ /* * main.c - Main functions for BootX. * - * Copyright (c) 1998-2002 Apple Computer, Inc. + * Copyright (c) 1998-2003 Apple Computer, Inc. * * DRI: Josh de Cesare */ @@ -77,6 +77,9 @@ long gOFVersion; char *gKeyMap; +long gRootAddrCells; +long gRootSizeCells; + CICell gChosenPH; CICell gOptionsPH; CICell gScreenPH; @@ -88,6 +91,13 @@ CICell gMemoryIH; CICell gStdOutIH; CICell gKeyboardIH; +static char gOFVectorSave[kVectorSize]; +static unsigned long gOFMSRSave; +static unsigned long gOFSPRG0Save; +static unsigned long gOFSPRG1Save; +static unsigned long gOFSPRG2Save; +static unsigned long gOFSPRG3Save; + // Private Functions static void Start(void *unused1, void *unused2, ClientInterfacePtr ciPtr) @@ -154,6 +164,11 @@ static long InitEverything(ClientInterfacePtr ciPtr) gOFVersion = GetOFVersion(); if (gOFVersion == 0) return -1; + // Get the address and size cells for the root. + GetProp(Peer(0), "#address-cells", (char *)&gRootAddrCells, 4); + GetProp(Peer(0), "#size-cells", (char *)&gRootSizeCells, 4); + if ((gRootAddrCells > 2) || (gRootAddrCells > 2)) return -1; + // Init the SL Words package. ret = InitSLWords(); if (ret != 0) return -1; @@ -235,15 +250,20 @@ static long InitEverything(ClientInterfacePtr ciPtr) gBootMode |= kBootModeSafe; } + // Claim memory for the FS Cache. + if (Claim(kFSCacheAddr, kFSCacheSize, 0) == 0) { + printf("Claim for fs cache failed.\n"); + return -1; + } + + // Claim memory for malloc. if (Claim(kMallocAddr, kMallocSize, 0) == 0) { printf("Claim for malloc failed.\n"); return -1; } malloc_init((char *)kMallocAddr, kMallocSize); - // malloc now works. - - // Claim the memory for the Load Addr + // Claim memory for the Load Addr. mem_base = Claim(kLoadAddr, kLoadSize, 0); if (mem_base == 0) { printf("Claim for Load Area failed.\n"); @@ -304,12 +324,26 @@ static long InitEverything(ClientInterfacePtr ciPtr) } +long ThinFatBinary(void **binary, unsigned long *length) +{ + long ret; + + ret = ThinFatBinaryMachO(binary, length); + if (ret == -1) ret = ThinFatBinaryElf(binary, length); + + return ret; +} + + static long DecodeKernel(void) { + void *binary = (void *)kLoadAddr; long ret; - ret = DecodeMachO(); - if (ret == -1) ret = DecodeElf(); + ThinFatBinary(&binary, 0); + + ret = DecodeMachO(binary); + if (ret == -1) ret = DecodeElf(binary); return ret; } @@ -317,12 +351,14 @@ static long DecodeKernel(void) static long SetUpBootArgs(void) { - boot_args_ptr args; - CICell memoryPH; - long graphicsBoot = 1; - long ret, cnt, mem_size, size, dash; - long sKey, vKey, keyPos; - char ofBootArgs[128], *ofArgs, tc, keyStr[8]; + boot_args_ptr args; + CICell memoryPH; + long graphicsBoot = 1; + long ret, cnt, size, dash; + long sKey, vKey, keyPos; + char ofBootArgs[128], *ofArgs, tc, keyStr[8]; + unsigned char mem_regs[kMaxDRAMBanks*16]; + unsigned long mem_banks, bank_shift; // Save file system cache statistics. SetProp(gChosenPH, "BootXCacheHits", (char *)&gCacheHits, 4); @@ -339,7 +375,7 @@ static long SetUpBootArgs(void) args = (boot_args_ptr)gBootArgsAddr; args->Revision = kBootArgsRevision; - args->Version = kBootArgsVersion; + args->Version = kBootArgsVersion1; args->machineType = 0; // Check the Keyboard for 'cmd-s' and 'cmd-v' @@ -431,22 +467,55 @@ static long SetUpBootArgs(void) sprintf(args->CommandLine, "%s%s", keyStr, ofBootArgs); - // Get the memory info + // If the address or size cells are larger than 1, use page numbers + // and signify Boot Args Version 2. + if ((gRootAddrCells == 1) && (gRootSizeCells == 1)) bank_shift = 0; + else { + bank_shift = 12; + args->Version = kBootArgsVersion2; + } + + // Get the information about the memory banks memoryPH = FindDevice("/memory"); if (memoryPH == -1) return -1; - size = GetProp(memoryPH, "reg", (char *)(args->PhysicalDRAM), - kMaxDRAMBanks * sizeof(DRAMBank)); + size = GetProp(memoryPH, "reg", mem_regs, kMaxDRAMBanks * 16); if (size == 0) return -1; + mem_banks = size / (4 * (gRootAddrCells + gRootSizeCells)); + if (mem_banks > kMaxDRAMBanks) mem_banks = kMaxDRAMBanks; + + // Convert the reg properties to 32 bit values + for (cnt = 0; cnt < mem_banks; cnt++) { + if (gRootAddrCells == 1) { + args->PhysicalDRAM[cnt].base = + *(unsigned long *)(mem_regs + cnt * 4 * (gRootAddrCells + gRootSizeCells)) >> bank_shift; + } else { + args->PhysicalDRAM[cnt].base = + *(unsigned long long *)(mem_regs + cnt * 4 * (gRootAddrCells + gRootSizeCells)) >> bank_shift; + + } + + if (gRootSizeCells == 1) { + args->PhysicalDRAM[cnt].size = + *(unsigned long *)(mem_regs + cnt * 4 * (gRootAddrCells + gRootSizeCells) + 4 * gRootAddrCells) >> bank_shift; + } else { + args->PhysicalDRAM[cnt].size = + *(unsigned long long *)(mem_regs + cnt * 4 * (gRootAddrCells + gRootSizeCells) + 4 * gRootAddrCells) >> bank_shift; + + } + } - // This is a hack to make the memory look like its all - // in one big bank. - mem_size = 0; - for (cnt = 0; cnt < kMaxDRAMBanks; cnt++) { - mem_size += args->PhysicalDRAM[cnt].size; - args->PhysicalDRAM[cnt].base = 0; - args->PhysicalDRAM[cnt].size = 0; + // Collapse the memory banks into contiguous chunks + for (cnt = 0; cnt < mem_banks - 1; cnt++) { + if ((args->PhysicalDRAM[cnt + 1].base != 0) && + ((args->PhysicalDRAM[cnt].base + args->PhysicalDRAM[cnt].size) != + args->PhysicalDRAM[cnt + 1].base)) continue; + + args->PhysicalDRAM[cnt].size += args->PhysicalDRAM[cnt + 1].size; + bcopy(args->PhysicalDRAM + cnt + 2, args->PhysicalDRAM + cnt + 1, (mem_banks - cnt - 2) * sizeof(DRAMBank)); + mem_banks--; + cnt--; } - args->PhysicalDRAM[0].size = mem_size; + bzero(args->PhysicalDRAM + mem_banks, (kMaxDRAMBanks - mem_banks) * sizeof(DRAMBank)); // Get the video info GetMainScreenPH(&args->Video); @@ -475,17 +544,29 @@ static long SetUpBootArgs(void) static long CallKernel(void) { - long msr, cnt; + unsigned long msr, cnt; Quiesce(); printf("\nCall Kernel!\n"); + // Save SPRs for OF + __asm__ volatile("mfmsr %0" : "=r" (gOFMSRSave)); + __asm__ volatile("mfsprg %0, 0" : "=r" (gOFSPRG0Save)); + __asm__ volatile("mfsprg %0, 1" : "=r" (gOFSPRG1Save)); + __asm__ volatile("mfsprg %0, 2" : "=r" (gOFSPRG2Save)); + __asm__ volatile("mfsprg %0, 3" : "=r" (gOFSPRG3Save)); + + // Turn off translations msr = 0x00001000; + __asm__ volatile("sync"); __asm__ volatile("mtmsr %0" : : "r" (msr)); __asm__ volatile("isync"); - // Move the Execption Vectors + // Save the OF's Exceptions Vectors + bcopy(0x0, gOFVectorSave, kVectorSize); + + // Move the Exception Vectors bcopy(gVectorSaveAddr, 0x0, kVectorSize); for (cnt = 0; cnt < kVectorSize; cnt += 0x20) { __asm__ volatile("dcbf 0, %0" : : "r" (cnt)); @@ -506,8 +587,27 @@ static long CallKernel(void) __asm__ volatile("sync"); __asm__ volatile("eieio"); + // Call the Kernel's entry point (*(void (*)())gKernelEntryPoint)(gBootArgsAddr, kMacOSXSignature); + // Restore OF's Exception Vectors + bcopy(gOFVectorSave, 0x0, 0x3000); + for (cnt = 0; cnt < kVectorSize; cnt += 0x20) { + __asm__ volatile("dcbf 0, %0" : : "r" (cnt)); + __asm__ volatile("icbi 0, %0" : : "r" (cnt)); + } + + // Restore SPRs for OF + __asm__ volatile("mtsprg 0, %0" : : "r" (gOFSPRG0Save)); + __asm__ volatile("mtsprg 1, %0" : : "r" (gOFSPRG1Save)); + __asm__ volatile("mtsprg 2, %0" : : "r" (gOFSPRG2Save)); + __asm__ volatile("mtsprg 3, %0" : : "r" (gOFSPRG3Save)); + + // Restore translations + __asm__ volatile("sync"); + __asm__ volatile("mtmsr %0" : : "r" (gOFMSRSave)); + __asm__ volatile("isync"); + return -1; } @@ -578,6 +678,10 @@ static long GetOFVersion(void) vers = kOFVersion3x; break; + case '4' : + vers = kOFVersion4x; + break; + default : vers = 0; break; diff --git a/bootx.tproj/sl.subproj/netboot.h b/bootx.tproj/sl.subproj/netboot.h index 5a736be..730e2ac 100644 --- a/bootx.tproj/sl.subproj/netboot.h +++ b/bootx.tproj/sl.subproj/netboot.h @@ -37,6 +37,7 @@ #define kNetBootFPS (10) const unsigned char gNetBootPict[] = { + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x01,0x2b,0x2b,0x01,0x01,0x01,0x01,0x01,0x01,0x2b,0x2b,0x01,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x01,0x2b,0x01,0x10,0x2f,0x40,0x4c,0x54,0x54,0x4c,0x41,0x30,0x11,0x01,0x2b,0x01,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x2b,0x01,0x22,0x4f,0x63,0x66,0x63,0x5c,0x56,0x54,0x56,0x5a,0x8c,0x8c,0x4e,0x24,0x2b,0x2b,0x02,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x2b,0x0c,0x51,0x68,0x60,0x42,0x2d,0x31,0x4b,0x58,0x54,0x54,0x53,0x53,0x55,0x5a,0x5f,0x4b,0x0a,0x2b,0x01,0x01,0x01,0x01,0x01,0x01, @@ -611,6 +612,5 @@ const unsigned char gNetBootPict[] = { 0x01,0x01,0x01,0x01,0x01,0x03,0x06,0x0d,0x13,0x13,0x1b,0x2f,0x43,0x4c,0x52,0x57,0x57,0x52,0x4c,0x42,0x2e,0x19,0x11,0x10,0x0b,0xf7,0x02,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x02,0x02,0xf7,0x09,0x11,0x14,0x14,0x15,0x19,0x1c,0x1c,0x1c,0x1c,0x17,0x13,0x12,0x12,0x0d,0x08,0x04,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x03,0xf7,0x09,0x0d,0x12,0x12,0x12,0x13,0x14,0x12,0x12,0x0e,0x0a,0x07,0xf7,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, - 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x03,0x04,0x06,0x07,0x08,0x0a,0x08,0x08,0x07,0xf7,0x04,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, - 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x02,0x02,0x03,0x03,0x02,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 + 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x03,0x04,0x06,0x07,0x08,0x0a,0x08,0x08,0x07,0xf7,0x04,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01 }; -- 2.47.2