From 47b0a8bde7689760b67e872ba41bf4187ed315e5 Mon Sep 17 00:00:00 2001 From: Apple Date: Thu, 19 Jul 2001 00:53:40 +0000 Subject: [PATCH] boot-83.2.tar.gz --- Makefile | 11 +- gen/rcz/rcz_decompress_file.c | 10 +- i386/boot1/Makefile | 10 +- i386/boot1/boot1 | Bin 512 -> 0 bytes i386/boot1/boot1f | Bin 512 -> 0 bytes i386/boot2/Makefile | 4 +- i386/boot2/boot.c | 313 ++--- i386/boot2/boot.h | 41 +- i386/boot2/drivers.c | 1344 +++++++++++++++++++++ i386/boot2/graphics.c | 2 +- i386/boot2/old/Language.table | 8 - i386/boot2/old/browser.c | 388 ------ i386/boot2/old/browser.h | 68 -- i386/boot2/old/button.c | 88 -- i386/boot2/old/button.h | 50 - i386/boot2/old/questionbox.c | 120 -- i386/boot2/old/scanmemory.c | 395 ------ i386/boot2/old/scanmemory.sed | 6 - i386/boot2/old/scrollbar.c | 89 -- i386/boot2/old/scrollbar.h | 36 - i386/boot2/old/sizememory.c | 73 -- i386/boot2/old/test | Bin 50652 -> 0 bytes i386/boot2/old/test.c | 35 - i386/boot2/prompt.c | 11 +- i386/libsa/Makefile | 4 +- i386/{boot2/old/start.s => libsa/bswap.c} | 14 +- i386/libsa/kernBootStruct.h | 177 +-- i386/libsa/libsa.h | 7 +- i386/libsa/memory.h | 41 +- i386/libsa/zalloc.c | 2 +- i386/libsaio/biosfn.c | 53 +- i386/libsaio/console.c | 4 +- i386/libsaio/drivers.h | 51 - i386/libsaio/load.c | 77 +- i386/libsaio/saio_internal.h | 2 +- i386/libsaio/stringTable.c | 1 - i386/libsaio/sys.c | 22 +- i386/rcz/rcz_decompress_file.c | 8 +- i386/util/machOconv.c | 19 +- 39 files changed, 1685 insertions(+), 1899 deletions(-) delete mode 100755 i386/boot1/boot1 delete mode 100755 i386/boot1/boot1f create mode 100644 i386/boot2/drivers.c delete mode 100644 i386/boot2/old/Language.table delete mode 100644 i386/boot2/old/browser.c delete mode 100644 i386/boot2/old/browser.h delete mode 100644 i386/boot2/old/button.c delete mode 100644 i386/boot2/old/button.h delete mode 100644 i386/boot2/old/questionbox.c delete mode 100644 i386/boot2/old/scanmemory.c delete mode 100644 i386/boot2/old/scanmemory.sed delete mode 100644 i386/boot2/old/scrollbar.c delete mode 100644 i386/boot2/old/scrollbar.h delete mode 100644 i386/boot2/old/sizememory.c delete mode 100755 i386/boot2/old/test delete mode 100644 i386/boot2/old/test.c rename i386/{boot2/old/start.s => libsa/bswap.c} (84%) delete mode 100644 i386/libsaio/drivers.h diff --git a/Makefile b/Makefile index 8dd7149..0724682 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,15 @@ all tags clean debug install installhdrs: $(SYMROOT) $(OBJROOT) ( OBJROOT=$(OBJROOT)/$${i}; \ SYMROOT=$(SYMROOT)/$${i}; \ DSTROOT=$(DSTROOT); \ + XCFLAGS=$(ARCHLESS_RC_CFLAGS); \ + GENSUBDIRS="$(GENERIC_SUBDIRS)"; \ + for x in $$GENSUBDIRS; \ + do \ + if [ "$$x" == "$$i" ]; then \ + XCFLAGS="$(RC_CFLAGS)"; \ + break; \ + fi \ + done; \ echo "$$OBJROOT $$SYMROOT $$DSTROOT"; \ cd $$i; ${MAKE} \ "OBJROOT=$$OBJROOT" \ @@ -52,7 +61,7 @@ all tags clean debug install installhdrs: $(SYMROOT) $(OBJROOT) "TARGET=$$i" \ "RC_KANJI=$(RC_KANJI)" \ "JAPANESE=$(JAPANESE)" \ - "RC_CFLAGS=$(ARCHLESS_RC_CFLAGS)" $@ \ + "RC_CFLAGS=$$XCFLAGS" $@ \ ) || exit $?; \ else \ echo "========= nothing to build for $$i ========="; \ diff --git a/gen/rcz/rcz_decompress_file.c b/gen/rcz/rcz_decompress_file.c index 0d947b0..d47abbd 100644 --- a/gen/rcz/rcz_decompress_file.c +++ b/gen/rcz/rcz_decompress_file.c @@ -31,13 +31,15 @@ */ -#import "rcz_common.h" - +#include "rcz_common.h" +#include +#include static unsigned short que[QLEN]; #define REWIND -1 -extern int read(int fd, char *buf, int len); +// extern int read(int fd, char *buf, int len); +extern int b_lseek(int fdesc, unsigned int addr, int ptr); static unsigned char *buf; static int buf_count; @@ -115,7 +117,7 @@ rcz_decompress_file( { unsigned int c, j, k, jmatch, jabove; int length; - unsigned int even_length, word, token, version; + unsigned int even_length, word, token; unsigned char *outorigin = out; length = rcz_file_size(in_fd); diff --git a/i386/boot1/Makefile b/i386/boot1/Makefile index 0cd0a9f..b8f16d0 100644 --- a/i386/boot1/Makefile +++ b/i386/boot1/Makefile @@ -5,11 +5,9 @@ include ../MakePaths.dir INSTALLDIR = $(DSTROOT)/usr/standalone/i386 DIRS_NEEDED = $(OBJROOT) $(SYMROOT) -FOREIGNNEXT = boot1f - NASM = $(SYMROOT)/nasm -VERSIONED_FILES = boot1f +VERSIONED_FILES = boot1 boot1f VERS = `vers_string -f 5.0 | tr - .` NEW_VERS = Rhapsody boot1 v$(VERS) @@ -21,11 +19,15 @@ endif all: $(DIRS_NEEDED) $(VERSIONED_FILES) +boot1: boot1.s Makefile + $(NASM) -dBOOTDEV=HDISK -dVERS="'$(NEW_VERS)'" boot1.s -o $(SYMROOT)/$@ + boot1f: boot1.s Makefile $(NASM) -dBOOTDEV=FLOPPY -dVERS="'$(NEW_VERS)'" boot1.s -o $(SYMROOT)/$@ install_i386:: all $(INSTALLDIR) + cp $(SYMROOT)/boot1 $(INSTALLDIR)/ cp $(SYMROOT)/boot1f $(INSTALLDIR)/ - cd $(INSTALLDIR); chmod u+w $(FOREIGNNEXT) + cd $(INSTALLDIR); chmod u+w $(VERSIONED_FILES) include ../MakeInc.dir diff --git a/i386/boot1/boot1 b/i386/boot1/boot1 deleted file mode 100755 index e61e42f53c5c139467d41fc61b2400d9e6a81ccd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 512 zcmcIe&r1Sf5S`CV&1zln)Xgqkf~fXb6dj~nNfs^`L{W2v*^gOKE8&I zQ&h`s_*P0mKW0ScMUNNhh0z6m6tP9^eOHTZEjQ5ygda4vX7FxuIY636;f!)u&9CvT z=0SQ)xr^UP`_X%|L(IKyZf0n_`=i|q25I{vfNIkMg44RszmQ~zPK!umKB)ck;6qO4o6Y|jN}nDEN`qBw(0kFt zkQNc#$v2rHt@}or@yTw!iD2u$e+)?LKGe94N9gOJu z5YhEw6NAx#gD;r4PAr_v5WR)ztZ zJR_Aa4=8=#Ew3^FNX2Ot^cq8arwDMgan7U1}G%u h=a(2Nlto17At5eahM?5M6ou5HqWmHtXHbIBRRBySnc)Bc diff --git a/i386/boot2/Makefile b/i386/boot2/Makefile index f794d90..3374438 100644 --- a/i386/boot2/Makefile +++ b/i386/boot2/Makefile @@ -32,12 +32,12 @@ VPATH = $(OBJROOT):$(SYMROOT) # The ordering is important; # boot2.o must be first. -OBJS = boot2.o boot.o graphics.o prompt.o +OBJS = boot2.o boot.o graphics.o drivers.o prompt.o # button.o browser.o scrollbar.o == NOTYET UTILDIR = ../util SFILES = boot2.s -CFILES = boot.c graphics.c prompt.c +CFILES = boot.c graphics.c drivers.c prompt.c HFILES = boot.h OTHERFILES = Makefile ALLSRC = $(FOREIGNSRC) $(FOREIGNBIN) $(SFILES) $(CFILES) \ diff --git a/i386/boot2/boot.c b/i386/boot2/boot.c index 94aa760..72f1be5 100644 --- a/i386/boot2/boot.c +++ b/i386/boot2/boot.c @@ -54,21 +54,8 @@ #include "libsaio.h" #include "kernBootStruct.h" #include "boot.h" -#include "drivers.h" #include "nbp.h" -/* - * True if using default.table - */ -static BOOL useDefaultConfig; - -/* - * Name of the kernel image file to load. - * This is specified in the config file, or may be - * overridden by the user at the boot prompt. - */ -static char gKernelName[BOOT_STRING_LEN]; - /* * The user asked for boot graphics. */ @@ -77,42 +64,25 @@ static BOOL gWantBootGraphics = NO; /* * The device that the booter was loaded from. */ -int gBootDev; +int gBootDev; extern char * gFilename; extern BOOL sysConfigValid; -extern char bootPrompt[]; // In prompt.c +extern char bootPrompt[]; extern BOOL errors; -extern BOOL verbose_mode; +extern BOOL gVerboseMode; extern BOOL gSilentBoot; -#if MULTIPLE_DEFAULTS -char * default_names[] = { - "$LBL", -}; -#define NUM_DEFAULT_NAMES (sizeof(default_names)/sizeof(char *)) -int current_default = 0; -#else -#define DEFAULT_NAME "$LBL" -#endif - /* * Prototypes. */ static void getBootString(); /* - * Message/Error logging macros. + * How long to wait (in seconds) to load the + * kernel after displaying the "boot:" prompt. */ -#define PRINT(x) { printf x } - -#ifdef DEBUG -#define DPRINT(x) { printf x; } -#define DSPRINT(x) { printf x; sleep(2); } -#else -#define DPRINT(x) -#define DSPRINT(x) -#endif +#define kBootTimeout 10 //========================================================================== // Zero the BSS. @@ -125,91 +95,57 @@ zeroBSS() bzero( &_DATA__bss__begin, (&_DATA__bss__end - &_DATA__bss__begin) ); - + bzero( &_DATA__common__begin, (&_DATA__common__end - &_DATA__common__begin) ); } //========================================================================== -// execKernel - Load the kernel image file and jump to its entry point. +// execKernel - Load the kernel image (mach-o) and jump to its entry point. static int -execKernel(int fd, int installMode) +execKernel(int fd) { register KERNBOOTSTRUCT * kbp = kernBootStruct; - register char * src = gFilename; - register char * dst = kbp->boot_file; - char * val; static struct mach_header head; entry_t kernelEntry; - int ret, size; -#ifdef DISABLED - char * linkerPath; - int loadDrivers; -#endif - - /* Copy the space/tab delimited word pointed by src (gFilename) to - * kbp->boot_file. - */ - while (*src && (*src != ' ' && *src != '\t')) - *dst++ = *src++; - *dst = 0; - - verbose("Loading %s\n", kbp->boot_file); - - /* perform the actual load */ + int ret; + + verbose("Loading kernel %s\n", kbp->bootFile); + + // Perform the actual load. + kbp->kaddr = kbp->ksize = 0; - ret = loadprog(kbp->kernDev, - fd, - &head, - &kernelEntry, - (char **) &kbp->kaddr, - &kbp->ksize); + + ret = loadprog( kbp->kernDev, + fd, + &head, + &kernelEntry, + (char **) &kbp->kaddr, + &kbp->ksize ); close(fd); + clearActivityIndicator(); if ( ret != 0 ) return ret; - /* Clear memory that might be used for loaded drivers - * because the standalone linker doesn't zero - * memory that is used later for BSS in the drivers. - */ - { - long addr = kbp->kaddr + kbp->ksize; - bzero((char *)addr, RLD_MEM_ADDR - addr); - } + // Load boot drivers from the specifed root. + LoadDrivers("/"); clearActivityIndicator(); - printf("\n"); - - if ((getValueForKey("Kernel Flags", &val, &size)) && size) { - int oldlen, len1; - char * cp = kbp->bootString; - oldlen = len1 = strlen(cp); - - // move out the user string - for(; len1 >= 0; len1--) - cp[size + len1] = cp[len1 - 1]; - strncpy(cp,val,size); - if (oldlen) cp[strlen(cp)] = ' '; - } if (errors) { printf("Errors encountered while starting up the computer.\n"); - printf("Pausing %d seconds...\n", BOOT_TIMEOUT); - sleep(BOOT_TIMEOUT); + printf("Pausing %d seconds...\n", kBootTimeout); + sleep(kBootTimeout); } - message("Starting Darwin Intel", 0); - - if (kbp->eisaConfigFunctions) - kbp->first_addr0 = EISA_CONFIG_ADDR + - (kbp->eisaConfigFunctions * sizeof(EISA_func_info_t)); - - clearActivityIndicator(); + message("Starting Darwin/x86", 0); turnOffFloppy(); + // Connect to APM BIOS. + if ( getBoolForKey("APM") ) { if ( APMPresent() ) APMConnect32(); @@ -243,17 +179,14 @@ execKernel(int fd, int installMode) //========================================================================== // Scan and record the system's PCI bus information. -// static void scanHardware() { -extern int ReadPCIBusInfo(PCI_bus_info_t *pp); +extern int ReadPCIBusInfo(PCI_bus_info_t *); extern void PCI_Bus_Init(PCI_bus_info_t *); - - KERNBOOTSTRUCT * kbp = KERNSTRUCT_ADDR; - ReadPCIBusInfo( &kbp->pciInfo ); - PCI_Bus_Init( &kbp->pciInfo ); + ReadPCIBusInfo( &kernBootStruct->pciInfo ); + PCI_Bus_Init( &kernBootStruct->pciInfo ); } //========================================================================== @@ -275,13 +208,11 @@ void boot(int bootdev) { register KERNBOOTSTRUCT * kbp = kernBootStruct; - int fd, size; - char * val; - int installMode = 0; + int fd; zeroBSS(); - // Enable A20 gate to be able to access memory above 1 MB. + // Enable A20 gate before accessing memory above 1Mb. enableA20(); @@ -297,27 +228,13 @@ boot(int bootdev) setMode(TEXT_MODE); - // Initialize the malloc area to the top of conventional memory. - - malloc_init( (char *) ZALLOC_ADDR, - (kbp->convmem * 1024) - ZALLOC_ADDR, - ZALLOC_NODES ); - // Scan hardware configuration. scanHardware(); - // Display initial banner. + // Display boot prompt. - printf( bootPrompt, kbp->convmem, kbp->extmem ); - printf( "Darwin Intel will start up in %d seconds, or you can:\n" - " Type -v and press Return to start up Darwin Intel with " - "diagnostic messages\n" - " Type ? and press Return to learn about advanced startup " - "options\n" - " Type any other character to stop Darwin Intel from " - "starting up automatically\n", - BOOT_TIMEOUT ); + printf( bootPrompt, kbp->convmem, kbp->extmem, kBootTimeout ); // Parse args, load and start kernel. @@ -325,9 +242,8 @@ boot(int bootdev) { // Initialize globals. - sysConfigValid = 0; - useDefaultConfig = 0; - errors = 0; + sysConfigValid = 0; + errors = 0; // Make sure we are in VGA text mode. @@ -356,16 +272,6 @@ boot(int bootdev) } flushdev(); -#if 0 // XXX - $LBL -#if MULTIPLE_DEFAULTS - strcpy(gKernelName, default_names[current_default]); - if (++current_default == NUM_DEFAULT_NAMES) - current_default = 0; -#else - strcpy(gKernelName, DEFAULT_NAME); -#endif -#endif - // Display boot prompt and get user supplied boot string. getBootString(); @@ -375,47 +281,32 @@ boot(int bootdev) // To force loading config file off same device as kernel, // open kernel file to force device change if necessary. - fd = open(gKernelName, 0); - if (fd >= 0) - close(fd); + fd = open(kbp->bootFile, 0); + if (fd >= 0) close(fd); } if ( sysConfigValid == 0 ) { - val = 0; - getValueForBootKey(kbp->bootString, - "config", &val, &size); - - DSPRINT(("sys config was not valid trying alt\n")); - useDefaultConfig = loadSystemConfig(val, size); - - if ( sysConfigValid == 0 ) - { - DSPRINT(("sys config is not valid\n")); - if (kbp->kernDev == DEV_EN) - break; // return control back to PXE - else - continue; // keep looping - } + if (kbp->kernDev == DEV_EN) + break; // return control back to PXE + else + continue; // keep looping } // Found and loaded a config file. Proceed with boot. - gWantBootGraphics = getBoolForKey("Boot Graphics"); - gSilentBoot = getBoolForKey("Silent Boot"); + gWantBootGraphics = getBoolForKey( kBootGraphicsKey ); + gSilentBoot = getBoolForKey( kQuietBootKey ); - message("Loading Darwin Intel", 0); + message("Loading Darwin/x86", 0); - if ( (fd = openfile(gKernelName, 0)) >= 0 ) + if ( (fd = openfile(kbp->bootFile, 0)) >= 0 ) { - DSPRINT(("calling exec kernel\n")); - execKernel(fd, installMode); - - // If execKernel() returns, kernel load failed. + execKernel(fd); // will not return on success } else { - error("Can't find %s\n", gKernelName); + error("Can't find %s\n", kbp->bootFile); if ( bootdev == kBootDevFloppyDisk ) { @@ -447,6 +338,11 @@ skipblanks(char ** cp) static void showHelp() { +#define BOOT_DIR_DISK "/usr/standalone/i386/" +#define BOOT_DIR_NET "" +#define makeFilePath(x) \ + (gBootDev == kBootDevNetwork) ? BOOT_DIR_NET x : BOOT_DIR_DISK x + int fd; char * help = makeFilePath("BootHelp.txt"); @@ -464,14 +360,14 @@ static void showHelp() // Returns 1 if the string pointed by 'cp' contains an user-specified // kernel image file name. Used by getBootString() function. -static inline int -containsKernelName(char * cp) +static int +containsKernelName(const char * cp) { register char c; - + skipblanks(&cp); - // Convert everything to lower case. + // Convert char to lower case. c = *cp | 0x20; @@ -497,7 +393,7 @@ containsKernelName(char * cp) //========================================================================== // Display the "boot:" prompt and copies the user supplied string to // kernBootStruct->bootString. The kernel image file name is written -// to the gKernelName buffer. +// to kernBootStruct->bootFile. static void getBootString() @@ -506,37 +402,50 @@ getBootString() char * cp; char * val; int count; - static int timeout = BOOT_TIMEOUT; + static int timeout = kBootTimeout; -top: - line[0] = '\0'; - cp = &line[0]; + do { + line[0] = '\0'; + cp = &line[0]; - /* If there have been problems, don't go on. */ - if ( errors ) timeout = 0; - errors = 0; + // If there were errors, don't timeout on boot prompt since + // the same error is likely to occur again. - // Print the boot prompt and wait a few seconds for user input. + if ( errors ) timeout = 0; + errors = 0; - printf("\n"); - count = Gets(line, sizeof(line), timeout, "boot: ", ""); - flushdev(); + // Print the boot prompt and wait a few seconds for user input. - // If something was typed, don't use automatic boot again. - // The boot: prompt will not timeout and go away until - // the user hits the return key. + printf("\n"); + count = Gets(line, sizeof(line), timeout, "boot: ", ""); + flushdev(); - if ( count ) timeout = 0; + // If something was typed, don't use automatic boot again. + // The boot: prompt will not timeout and go away until + // the user hits the return key. - skipblanks(&cp); + if ( count ) timeout = 0; - // If user typed '?', then display the usage message. + skipblanks(&cp); - if ( *cp == '?' ) - { - showHelp(); - goto top; + // If user typed '?', then display the usage message. + + if ( *cp == '?' ) + { + showHelp(); + continue; + } + + // Load config table file specified by the user, or fallback + // to the default one. + + val = 0; + getValueForBootKey(cp, "config", &val, &count); + loadSystemConfig(val, count); + if ( !sysConfigValid ) + continue; } + while ( 0 ); // Did the user specify a kernel file name at the boot prompt? @@ -546,21 +455,9 @@ top: // This is fine, read the default kernel file name from the // config table. - printf("\n"); - - val = 0; - getValueForBootKey(cp, "config", &val, &count); - - useDefaultConfig = loadSystemConfig(val, count); - - if ( !sysConfigValid ) - goto top; - - // Get the kernel name from the config table file. - - if ( getValueForKey( "Kernel", &val, &count) ) + if ( getValueForKey(kKernelNameKey, &val, &count) ) { - strncpy(gKernelName, val, count); + strncpy(kernBootStruct->bootFile, val, count); } } else @@ -568,7 +465,7 @@ top: // Get the kernel name from the user-supplied boot string, // and copy the name to the buffer provided. - char * namep = gKernelName; + char * namep = kernBootStruct->bootFile; while ( *cp && !(*cp == ' ' || *cp == '\t') ) *namep++ = *cp++; @@ -578,9 +475,17 @@ top: // Verbose flag specified. - verbose_mode = getValueForBootKey(cp, "-v", &val, &count); + gVerboseMode = getValueForBootKey(cp, "-v", &val, &count); - // Save the boot string in kernBootStruct. + // Save the boot string in kernBootStruct->bootString. - strcpy(kernBootStruct->bootString, cp); + if ( getValueForKey(kKernelFlagsKey, &val, &count) && count ) + { + strncpy( kernBootStruct->bootString, val, count ); + } + if ( strlen(cp) ) + { + strcat(kernBootStruct->bootString, " "); + strcat(kernBootStruct->bootString, cp); + } } diff --git a/i386/boot2/boot.h b/i386/boot2/boot.h index 795cd85..c338591 100644 --- a/i386/boot2/boot.h +++ b/i386/boot2/boot.h @@ -29,36 +29,24 @@ #ifndef __BOOT2_BOOT_H #define __BOOT2_BOOT_H -/* - * How long to wait (in seconds) to load the - * kernel after displaying the "boot:" prompt. - */ -#define BOOT_TIMEOUT 10 /* 10 second timeout */ - /* * Keys used in system Default.table / Instance0.table */ -#define PROMPT_KEY "Prompt For Driver Disk" -#define NUM_PROMPTS_KEY "Driver Disk Prompts" -#define ASK_KEY "Ask For Drivers" -#define INSTALL_KEY "Install Mode" -#define G_MODE_KEY "Graphics Mode" +#define kGraphicsModeKey "Graphics Mode" +#define kBootGraphicsKey "Boot Graphics" +#define kQuietBootKey "Quiet Boot" +#define kKernelFlagsKey "Kernel Flags" +#define kKernelNameKey "Kernel" /* * Possible values for the bootdev argument passed to boot(). */ enum { - kBootDevHardDisk = 0, - kBootDevFloppyDisk = 1, - kBootDevNetwork = 2, + kBootDevHardDisk = 0, + kBootDevFloppyDisk, + kBootDevNetwork }; -/* - * The directory that contains the booter support files. - */ -#define BOOT_DIR_DISK "/usr/standalone/i386/" -#define BOOT_DIR_NET "" - /* * A global set by boot() to record the device that the booter * was loaded from. @@ -66,13 +54,7 @@ enum { extern int gBootDev; /* - * Create the complete path to a booter support file. - */ -#define makeFilePath(x) \ - (gBootDev == kBootDevNetwork) ? BOOT_DIR_NET x : BOOT_DIR_DISK x - -/* - * Functions defined in graphics.c. + * graphics.c */ extern void message(char * str, int centered); extern void setMode(int mode); @@ -80,4 +62,9 @@ extern int currentMode(); extern void spinActivityIndicator(); extern void clearActivityIndicator(); +/* + * drivers.c + */ +extern long LoadDrivers(char * dirSpec); + #endif /* !__BOOT2_BOOT_H */ diff --git a/i386/boot2/drivers.c b/i386/boot2/drivers.c new file mode 100644 index 0000000..e95053a --- /dev/null +++ b/i386/boot2/drivers.c @@ -0,0 +1,1344 @@ +/* + * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * "Portions Copyright (c) 1999 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.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. + * + * 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 OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License." + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* + * drivers.c - Driver Loading Functions. + * + * Copyright (c) 2000 Apple Computer, Inc. + * + * DRI: Josh de Cesare + */ + +#include "libsaio.h" +#include "memory.h" +#include "kernBootStruct.h" +#include "nbp.h" +#include "boot.h" + +enum { + kTagTypeNone = 0, + kTagTypeDict, + kTagTypeKey, + kTagTypeString, + kTagTypeInteger, + kTagTypeData, + kTagTypeDate, + kTagTypeFalse, + kTagTypeTrue, + kTagTypeArray +}; + +#define kXMLTagPList "plist " +#define kXMLTagDict "dict" +#define kXMLTagKey "key" +#define kXMLTagString "string" +#define kXMLTagInteger "integer" +#define kXMLTagData "data" +#define kXMLTagDate "date" +#define kXMLTagFalse "false/" +#define kXMLTagTrue "true/" +#define kXMLTagArray "array" + +#define kPropCFBundleIdentifier ("CFBundleIdentifier") +#define kPropCFBundleExecutable ("CFBundleExecutable") +#define kPropOSBundleRequired ("OSBundleRequired") +#define kPropOSBundleLibraries ("OSBundleLibraries") +#define kPropIOKitPersonalities ("IOKitPersonalities") +#define kPropIONameMatch ("IONameMatch") + +struct Tag { + long type; + char *string; + struct Tag *tag; + struct Tag *tagNext; +}; +typedef struct Tag Tag, *TagPtr; + +struct Module { + struct Module *nextModule; + long willLoad; + TagPtr dict; + char *plistAddr; + long plistLength; + char *driverPath; +}; +typedef struct Module Module, *ModulePtr; + +struct DriverInfo { + char *plistAddr; + long plistLength; + void *moduleAddr; + long moduleLength; +}; +typedef struct DriverInfo DriverInfo, *DriverInfoPtr; + +#define kDriverPackageSignature1 'MKXT' +#define kDriverPackageSignature2 'MOSX' + +struct DriversPackage { + unsigned long signature1; + unsigned long signature2; + unsigned long length; + unsigned long alder32; + unsigned long version; + unsigned long numDrivers; + unsigned long reserved1; + unsigned long reserved2; +}; +typedef struct DriversPackage DriversPackage; + +static long FileLoadDrivers(char *dirSpec, long plugin); +static long NetLoadDrivers(char *dirSpec); +static long LoadDriverMKext(char *fileSpec); +static long LoadDriverPList(char *dirSpec, char *name); +static long LoadMatchedModules(void); +static long MatchPersonalities(void); +static long MatchLibraries(void); +static TagPtr GetProperty(TagPtr dict, char *key); +// static ModulePtr FindModule(char *name); +static long ParseXML(char *buffer, ModulePtr *module, TagPtr *personalities); +static long ParseNextTag(char *buffer, TagPtr *tag); +static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty); +static long ParseTagKey(char *buffer, TagPtr *tag); +static long ParseTagString(char *buffer, TagPtr *tag); +static long ParseTagInteger(char *buffer, TagPtr *tag); +static long ParseTagData(char *buffer, TagPtr *tag); +static long ParseTagDate(char *buffer, TagPtr *tag); +static long ParseTagBoolean(char *buffer, TagPtr *tag, long type); +static long GetNextTag(char *buffer, char **tag, long *start); +static long FixDataMatchingTag(char *buffer, char *tag); +static TagPtr NewTag(void); +static void FreeTag(TagPtr tag); +static char *NewSymbol(char *string); +static void FreeSymbol(char *string); +// static void DumpTag(TagPtr tag, long depth); + +static ModulePtr gModuleHead, gModuleTail; +static TagPtr gPersonalityHead, gPersonalityTail; +static char * gExtensionsSpec; +static char * gDriverSpec; +static char * gFileSpec; + +//========================================================================== +// BootX shim functions. + +#include + +#define kLoadAddr TFTP_ADDR +#define kLoadSize TFTP_LEN + +#define kPageSize 4096 +#define RoundPage(x) ((((unsigned)(x)) + kPageSize - 1) & ~(kPageSize - 1)) + +static long +LoadFile( char * fileSpec ) +{ + unsigned long count = TFTP_LEN; + unsigned long addr = TFTP_ADDR; + + if ( gBootDev == kBootDevNetwork ) + { + if ( nbpTFTPReadFile(fileSpec, &count, addr) != nbpStatusSuccess ) + return -1; + } + else + { + int fd = open( fileSpec, 0 ); + if ( fd < 0 ) + return -1; + + count = read( fd, (char *) addr, count ); + close(fd); + } + return count; +} + +static long gImageFirstBootXAddr; +static long gImageLastKernelAddr; + +static void * +AllocateBootXMemory( long size ) +{ + long addr = gImageFirstBootXAddr - size; + + if ( addr < gImageLastKernelAddr ) return 0; + + bzero(addr, size); + + gImageFirstBootXAddr = addr; + + return (void *)addr; +} + +static long +AllocateKernelMemory( long inSize ) +{ + long addr = gImageLastKernelAddr; + + gImageLastKernelAddr += RoundPage(inSize); + + if ( gImageLastKernelAddr > gImageFirstBootXAddr ) + stop( "AllocateKernelMemory error" ); + + kernBootStruct->ksize = gImageLastKernelAddr - kernBootStruct->kaddr; + + return addr; +} + +static long +AllocateMemoryRange(char * rangeName, long start, long length, long type) +{ + if ( kernBootStruct->numBootDrivers < NDRIVERS ) + { + int num = kernBootStruct->numBootDrivers; + + kernBootStruct->driverConfig[num].address = start; + kernBootStruct->driverConfig[num].size = length; + kernBootStruct->driverConfig[num].type = type; + kernBootStruct->numBootDrivers++; + } + else + { + stop( "AllocateMemoryRange error" ); + } + return 0; +} + +// Map BootX file types to UFS file types defined in ufs/ufs/dir.h. + +enum { + kUnknownFileType = DT_UNKNOWN, + kFlatFileType = DT_REG, + kDirectoryFileType = DT_DIR, + kLinkFileType = DT_LNK +}; + +static long +GetFileInfo( char * dirSpec, char * name, long * flags, long * time ) +{ + struct dirstuff * dir; + struct direct * entry = 0; + + dir = opendir(dirSpec); + if ( dir ) + { + while (( entry = readdir(dir) )) + { + if ( strcmp( entry->d_name, name ) == 0 ) + { + *flags = entry->d_type; + *time = 0; + break; + } + } + closedir(dir); + } + return ( entry ) ? 0 : -1; +} + +// Map BootX types to boot counterparts. + +#define gBootFileType gBootDev +enum { + kNetworkDeviceType = kBootDevNetwork, + kBlockDeviceType = kBootDevHardDisk +}; + +static struct dirstuff * +OpenDir( char * dirSpec ) +{ + return opendir(dirSpec); +} + +static void +CloseDir( struct dirstuff * dirStuff ) +{ + closedir(dirStuff); +} + +static long +GetDirEntry( struct dirstuff * dir, long * dirIndex, char ** name, + long * flags, long * time) +{ + if ( dir ) + { + struct direct * entry = readdir(dir); + + if ( entry ) + { + *name = entry->d_name; + *flags = entry->d_type; + *time = 0; + return 0; + } + } + return (-1); +} + +static long +InitDriverSupport() +{ + gExtensionsSpec = (char *) malloc( 4096 ); + gDriverSpec = (char *) malloc( 4096 ); + gFileSpec = (char *) malloc( 4096 ); + + if ( !gExtensionsSpec || !gDriverSpec || !gFileSpec ) + stop( "InitDriverSupport error" ); + + gImageLastKernelAddr = RoundPage( kernBootStruct->kaddr + + kernBootStruct->ksize ); + + gImageFirstBootXAddr = ( KERNEL_ADDR + KERNEL_LEN ); + + return 0; +} + +static unsigned long +Alder32( unsigned char * buffer, long length ) +{ + long cnt; + unsigned long result, lowHalf, highHalf; + + lowHalf = 1; + highHalf = 0; + + for ( cnt = 0; cnt < length; cnt++ ) + { + if ((cnt % 5000) == 0) + { + lowHalf %= 65521L; + highHalf %= 65521L; + } + + lowHalf += buffer[cnt]; + highHalf += lowHalf; + } + + lowHalf %= 65521L; + highHalf %= 65521L; + + result = (highHalf << 16) | lowHalf; + + return result; +} + +//========================================================================== +// LoadDrivers + +long LoadDrivers( char * dirSpec ) +{ + if ( InitDriverSupport() != 0 ) + return 0; + + if ( gBootFileType == kNetworkDeviceType ) + { + NetLoadDrivers(dirSpec); + } + else /* if ( gBootFileType == kBlockDeviceType ) */ + { + strcpy(gExtensionsSpec, dirSpec); + strcat(gExtensionsSpec, "System/Library/"); + FileLoadDrivers(gExtensionsSpec, 0); + } +#if 0 + else + { + return 0; + } +#endif + + MatchPersonalities(); + + MatchLibraries(); + + LoadMatchedModules(); + + return 0; +} + +//========================================================================== +// FileLoadDrivers + +static long +FileLoadDrivers( char * dirSpec, long plugin ) +{ + long ret, length, index, flags, time; + char * name; + struct dirstuff * dir; + + if ( !plugin ) + { + long time2; + + ret = GetFileInfo(dirSpec, "Extensions.mkext", &flags, &time); + if ((ret == 0) && (flags == kFlatFileType)) + { + ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2); + if ((ret != 0) || (flags == kDirectoryFileType) || (time > time2)) + { + sprintf(gDriverSpec, "%sExtensions.mkext", dirSpec); + verbose("LoadDrivers: Loading from [%s]\n", gDriverSpec); + if (LoadDriverMKext(gDriverSpec) == 0) return 0; + } + } + + strcat(dirSpec, "Extensions"); + } + + verbose("LoadDrivers: Loading from [%s]\n", dirSpec); + + // INTEL addition + dir = OpenDir( dirSpec ); + + index = 0; + while (1) { + // INTEL modification + ret = GetDirEntry(dir, &index, &name, &flags, &time); + if (ret == -1) break; + + // Make sure this is a directory. + if (flags != kDirectoryFileType) continue; + + // Make sure this is a kext. + length = strlen(name); + if (strcmp(name + length - 5, ".kext")) continue; + + if (!plugin) + sprintf(gDriverSpec, "%s/%s/Contents/PlugIns", dirSpec, name); + + ret = LoadDriverPList(dirSpec, name); + if (ret != 0) + { + // printf("LoadDrivers: failed\n"); + } + + if (!plugin) + ret = FileLoadDrivers(gDriverSpec, 1); + } + + // INTEL addition + if ( dir ) CloseDir( dir ); + + return 0; +} + +//========================================================================== +// + +static long +NetLoadDrivers( char * dirSpec ) +{ + long tries; + +#if 0 + long cnt; + + // Get the name of the kernel + cnt = strlen(gBootFile); + while (cnt--) { + if ((gBootFile[cnt] == '\\') || (gBootFile[cnt] == ',')) { + cnt++; + break; + } + } +#endif + + // INTEL modification + sprintf(gDriverSpec, "%s%s.mkext", dirSpec, kernBootStruct->bootFile); + + verbose("NetLoadDrivers: Loading from [%s]\n", gDriverSpec); + + tries = 3; + while (tries--) + { + if (LoadDriverMKext(gDriverSpec) == 0) break; + } + if (tries == -1) return -1; + + return 0; +} + +//========================================================================== +// loadDriverMKext + +static long +LoadDriverMKext( char * fileSpec ) +{ + long driversAddr, driversLength; + char segName[32]; + DriversPackage * package = (DriversPackage *)kLoadAddr; + +#define GetPackageElement(e) bswap32(package-> ## e) + + // Load the MKext. + if (LoadFile(fileSpec) == -1) return -1; + + // Verify the MKext. + if (( GetPackageElement(signature1) != kDriverPackageSignature1) || + ( GetPackageElement(signature2) != kDriverPackageSignature2) || + ( GetPackageElement(length) > kLoadSize ) || + ( GetPackageElement(alder32) != + Alder32((char *)&package->version, GetPackageElement(length) - 0x10) ) ) + { + return -1; + } + + // Make space for the MKext. + driversLength = GetPackageElement(length); + driversAddr = AllocateKernelMemory(driversLength); + + // Copy the MKext. + memcpy((void *)driversAddr, (void *)kLoadAddr, driversLength); + + // Add the MKext to the memory map. + sprintf(segName, "DriversPackage-%lx", driversAddr); + AllocateMemoryRange(segName, driversAddr, driversLength, + kBootDriverTypeMKEXT); + + return 0; +} + +//========================================================================== +// LoadDriverPList + +static long +LoadDriverPList( char * dirSpec, char * name ) +{ + long length, driverPathLength; + ModulePtr module; + TagPtr personalities; + char * buffer = 0; + char * tmpDriverPath = 0; + long ret = -1; + + do { + // Save the driver path. + + sprintf(gFileSpec, "%s/%s/Contents/MacOS/", dirSpec, name); + driverPathLength = strlen(gFileSpec); + + tmpDriverPath = malloc(driverPathLength + 1); + if (tmpDriverPath == 0) break; + + strcpy(tmpDriverPath, gFileSpec); + + // Construct the file spec to the plist, then load it. + + sprintf(gFileSpec, "%s/%s/Contents/Info.plist", dirSpec, name); + + length = LoadFile(gFileSpec); + if (length == -1) break; + + buffer = malloc(length + 1); + if (buffer == 0) break; + + strncpy(buffer, (char *)kLoadAddr, length); + + // Parse the plist. + + ret = ParseXML(buffer, &module, &personalities); + if (ret != 0) break; + + // Allocate memory for the driver path and the plist. + + module->driverPath = AllocateBootXMemory(driverPathLength + 1); + module->plistAddr = AllocateBootXMemory(length + 1); + + if ((module->driverPath == 0) || (module->plistAddr == 0)) + break; + + // Save the driver path in the module. + + strcpy(module->driverPath, tmpDriverPath); + + // Add the plist to the module. + + strncpy(module->plistAddr, (char *)kLoadAddr, length); + module->plistLength = length + 1; + + // Add the module to the end of the module list. + + if (gModuleHead == 0) + gModuleHead = module; + else + gModuleTail->nextModule = module; + gModuleTail = module; + + // Add the persionalities to the personality list. + + if (personalities) personalities = personalities->tag; + while (personalities != 0) + { + if (gPersonalityHead == 0) + gPersonalityHead = personalities->tag; + else + gPersonalityTail->tagNext = personalities->tag; + + gPersonalityTail = personalities->tag; + personalities = personalities->tagNext; + } + + ret = 0; + } + while (0); + + if ( buffer ) free( buffer ); + if ( tmpDriverPath ) free( tmpDriverPath ); + + return ret; +} + +//========================================================================== +// LoadMatchedModules + +static long +LoadMatchedModules( void ) +{ + TagPtr prop; + ModulePtr module; + char *fileName, segName[32]; + DriverInfoPtr driver; + long length, driverAddr, driverLength; + + module = gModuleHead; + + while (module != 0) + { + if (module->willLoad) + { + prop = GetProperty(module->dict, kPropCFBundleExecutable); + if (prop != 0) + { + fileName = prop->string; + sprintf(gFileSpec, "%s%s", module->driverPath, fileName); + length = LoadFile(gFileSpec); + } + else + length = 0; + + if (length != -1) + { + // Make make in the image area. + driverLength = sizeof(DriverInfo) + module->plistLength + length; + driverAddr = AllocateKernelMemory(driverLength); + + // Set up the DriverInfo. + driver = (DriverInfoPtr)driverAddr; + driver->plistAddr = (char *)(driverAddr + sizeof(DriverInfo)); + driver->plistLength = module->plistLength; + if (length != 0) + { + driver->moduleAddr = (void *)(driverAddr + sizeof(DriverInfo) + + module->plistLength); + driver->moduleLength = length; + } + else + { + driver->moduleAddr = 0; + driver->moduleLength = 0; + } + + // Save the plist and module. + strcpy(driver->plistAddr, module->plistAddr); + if (length != 0) + { + memcpy(driver->moduleAddr, (void *)kLoadAddr, driver->moduleLength); + } + + // Add an entry to the memory map. + sprintf(segName, "Driver-%lx", (unsigned long)driver); + AllocateMemoryRange(segName, driverAddr, driverLength, + kBootDriverTypeKEXT); + } + } + module = module->nextModule; + } + + return 0; +} + +//========================================================================== +// MatchPersonalities + +static long +MatchPersonalities( void ) +{ +#warning IONameMatch support not implemented + return 0; +} + +//========================================================================== +// MatchLibraries + +static long +MatchLibraries( void ) +{ + TagPtr prop, prop2; + ModulePtr module, module2; + long done; + + do { + done = 1; + module = gModuleHead; + + while (module != 0) + { + if (module->willLoad == 1) + { + prop = GetProperty(module->dict, kPropOSBundleLibraries); + if (prop != 0) + { + prop = prop->tag; + while (prop != 0) + { + module2 = gModuleHead; + while (module2 != 0) + { + prop2 = GetProperty(module2->dict, kPropCFBundleIdentifier); + if ((prop2 != 0) && (!strcmp(prop->string, prop2->string))) + { + if (module2->willLoad == 0) module2->willLoad = 1; + break; + } + module2 = module2->nextModule; + } + prop = prop->tagNext; + } + } + module->willLoad = 2; + done = 0; + } + module = module->nextModule; + } + } + while (!done); + + return 0; +} + +//========================================================================== +// GetProperty + +static TagPtr +GetProperty( TagPtr dict, char * key ) +{ + TagPtr tagList, tag; + + if (dict->type != kTagTypeDict) return 0; + + tag = 0; + tagList = dict->tag; + while (tagList) + { + tag = tagList; + tagList = tag->tagNext; + + if ((tag->type != kTagTypeKey) || (tag->string == 0)) continue; + + if (!strcmp(tag->string, key)) return tag->tag; + } + + return 0; +} + +//========================================================================== +// FindModule + +#if NOTDEF +static ModulePtr +FindModule( char * name ) +{ + ModulePtr module; + TagPtr prop; + + module = gModuleHead; + + while (module != 0) + { + prop = GetProperty(module->dict, kPropCFBundleIdentifier); + if ((prop != 0) && !strcmp(name, prop->string)) break; + module = module->nextModule; + } + + return module; +} +#endif /* NOTDEF */ + +//========================================================================== +// ParseXML + +static long +ParseXML( char * buffer, ModulePtr * module, TagPtr * personalities ) +{ + long length, pos; + TagPtr moduleDict, required; + ModulePtr tmpModule; + + pos = 0; + + while (1) + { + length = ParseNextTag(buffer + pos, &moduleDict); + if (length == -1) break; + + pos += length; + + if (moduleDict == 0) continue; + if (moduleDict->type == kTagTypeDict) break; + + FreeTag(moduleDict); + } + + if (length == -1) return -1; + + required = GetProperty(moduleDict, kPropOSBundleRequired); + if ( (required == 0) || + (required->type != kTagTypeString) || + !strcmp(required->string, "Safe Boot")) + { + FreeTag(moduleDict); + return -2; + } + + tmpModule = AllocateBootXMemory(sizeof(Module)); + if (tmpModule == 0) + { + FreeTag(moduleDict); + return -1; + } + tmpModule->dict = moduleDict; + + // For now, load any module that has OSBundleRequired != "Safe Boot". + + tmpModule->willLoad = 1; + + *module = tmpModule; + + // Get the personalities. + + *personalities = GetProperty(moduleDict, kPropIOKitPersonalities); + + return 0; +} + +//========================================================================== +// ParseNextTag + +static long +ParseNextTag( char * buffer, TagPtr * tag ) +{ + long length, pos; + char * tagName; + + length = GetNextTag(buffer, &tagName, 0); + if (length == -1) return -1; + + pos = length; + if (!strncmp(tagName, kXMLTagPList, 6)) + { + length = 0; + } + else if (!strcmp(tagName, kXMLTagDict)) + { + length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0); + } + else if (!strcmp(tagName, kXMLTagDict "/")) + { + length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1); + } + else if (!strcmp(tagName, kXMLTagKey)) + { + length = ParseTagKey(buffer + pos, tag); + } + else if (!strcmp(tagName, kXMLTagString)) + { + length = ParseTagString(buffer + pos, tag); + } + else if (!strcmp(tagName, kXMLTagInteger)) + { + length = ParseTagInteger(buffer + pos, tag); + } + else if (!strcmp(tagName, kXMLTagData)) + { + length = ParseTagData(buffer + pos, tag); + } + else if (!strcmp(tagName, kXMLTagDate)) + { + length = ParseTagDate(buffer + pos, tag); + } + else if (!strcmp(tagName, kXMLTagFalse)) + { + length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse); + } + else if (!strcmp(tagName, kXMLTagTrue)) + { + length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue); + } + else if (!strcmp(tagName, kXMLTagArray)) + { + length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0); + } + else if (!strcmp(tagName, kXMLTagArray "/")) + { + length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1); + } + else + { + *tag = 0; + length = 0; + } + + if (length == -1) return -1; + + return pos + length; +} + +//========================================================================== +// ParseTagList + +static long +ParseTagList( char * buffer, TagPtr * tag, long type, long empty ) +{ + long length, pos; + TagPtr tagList, tmpTag; + + tagList = 0; + pos = 0; + + if (!empty) + { + while (1) + { + length = ParseNextTag(buffer + pos, &tmpTag); + if (length == -1) break; + + pos += length; + + if (tmpTag == 0) break; + tmpTag->tagNext = tagList; + tagList = tmpTag; + } + + if (length == -1) + { + FreeTag(tagList); + return -1; + } + } + + tmpTag = NewTag(); + if (tmpTag == 0) + { + FreeTag(tagList); + return -1; + } + + tmpTag->type = type; + tmpTag->string = 0; + tmpTag->tag = tagList; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return pos; +} + +//========================================================================== +// ParseTagKey + +static long +ParseTagKey( char * buffer, TagPtr * tag ) +{ + long length, length2; + char *string; + TagPtr tmpTag, subTag; + + length = FixDataMatchingTag(buffer, kXMLTagKey); + if (length == -1) return -1; + + length2 = ParseNextTag(buffer + length, &subTag); + if (length2 == -1) return -1; + + tmpTag = NewTag(); + if (tmpTag == 0) + { + FreeTag(subTag); + return -1; + } + + string = NewSymbol(buffer); + if (string == 0) + { + FreeTag(subTag); + FreeTag(tmpTag); + return -1; + } + + tmpTag->type = kTagTypeKey; + tmpTag->string = string; + tmpTag->tag = subTag; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return length + length2; +} + +//========================================================================== +// ParseTagString + +static long +ParseTagString( char * buffer, TagPtr * tag ) +{ + long length; + char * string; + TagPtr tmpTag; + + length = FixDataMatchingTag(buffer, kXMLTagString); + if (length == -1) return -1; + + tmpTag = NewTag(); + if (tmpTag == 0) return -1; + + string = NewSymbol(buffer); + if (string == 0) + { + FreeTag(tmpTag); + return -1; + } + + tmpTag->type = kTagTypeString; + tmpTag->string = string; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return length; +} + +//========================================================================== +// ParseTagInteger + +static long +ParseTagInteger( char * buffer, TagPtr * tag ) +{ + long length, integer; + TagPtr tmpTag; + + length = FixDataMatchingTag(buffer, kXMLTagInteger); + if (length == -1) return -1; + + tmpTag = NewTag(); + if (tmpTag == 0) return -1; + + integer = 0; + + tmpTag->type = kTagTypeInteger; + tmpTag->string = (char *)integer; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return length; +} + +//========================================================================== +// ParseTagData + +static long +ParseTagData( char * buffer, TagPtr * tag ) +{ + long length; + TagPtr tmpTag; + + length = FixDataMatchingTag(buffer, kXMLTagData); + if (length == -1) return -1; + + tmpTag = NewTag(); + if (tmpTag == 0) return -1; + + tmpTag->type = kTagTypeData; + tmpTag->string = 0; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return length; +} + +//========================================================================== +// ParseTagDate + +static long +ParseTagDate( char * buffer, TagPtr * tag ) +{ + long length; + TagPtr tmpTag; + + length = FixDataMatchingTag(buffer, kXMLTagDate); + if (length == -1) return -1; + + tmpTag = NewTag(); + if (tmpTag == 0) return -1; + + tmpTag->type = kTagTypeDate; + tmpTag->string = 0; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return length; +} + +//========================================================================== +// ParseTagBoolean + +static long +ParseTagBoolean( char * buffer, TagPtr * tag, long type ) +{ + TagPtr tmpTag; + + tmpTag = NewTag(); + if (tmpTag == 0) return -1; + + tmpTag->type = type; + tmpTag->string = 0; + tmpTag->tag = 0; + tmpTag->tagNext = 0; + + *tag = tmpTag; + + return 0; +} + +//========================================================================== +// GetNextTag + +static long +GetNextTag( char * buffer, char ** tag, long * start ) +{ + long cnt, cnt2; + + if (tag == 0) return -1; + + // Find the start of the tag. + cnt = 0; + while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++; + if (buffer[cnt] == '\0') return -1; + + // Find the end of the tag. + cnt2 = cnt + 1; + while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++; + if (buffer[cnt2] == '\0') return -1; + + // Fix the tag data. + *tag = buffer + cnt + 1; + buffer[cnt2] = '\0'; + if (start) *start = cnt; + + return cnt2 + 1; +} + +//========================================================================== +// FixDataMatchingTag + +static long +FixDataMatchingTag( char * buffer, char * tag ) +{ + long length, start, stop; + char * endTag; + + start = 0; + while (1) + { + length = GetNextTag(buffer + start, &endTag, &stop); + if (length == -1) return -1; + + if ((*endTag == '/') && !strcmp(endTag + 1, tag)) break; + start += length; + } + + buffer[start + stop] = '\0'; + + return start + length; +} + +//========================================================================== +// NewTag + +#define kTagsPerBlock (0x1000) + +static TagPtr gTagsFree; + +static TagPtr +NewTag( void ) +{ + long cnt; + TagPtr tag; + + if (gTagsFree == 0) + { + tag = (TagPtr)AllocateBootXMemory(kTagsPerBlock * sizeof(Tag)); + if (tag == 0) return 0; + + // Initalize the new tags. + for (cnt = 0; cnt < kTagsPerBlock; cnt++) + { + tag[cnt].type = kTagTypeNone; + tag[cnt].string = 0; + tag[cnt].tag = 0; + tag[cnt].tagNext = tag + cnt + 1; + } + tag[kTagsPerBlock - 1].tagNext = 0; + + gTagsFree = tag; + } + + tag = gTagsFree; + gTagsFree = tag->tagNext; + + return tag; +} + +//========================================================================== +// FreeTag + +static void +FreeTag( TagPtr tag ) +{ + return; + if (tag == 0) return; + + if (tag->string) FreeSymbol(tag->string); + + FreeTag(tag->tag); + FreeTag(tag->tagNext); + + // Clear and free the tag. + tag->type = kTagTypeNone; + tag->string = 0; + tag->tag = 0; + tag->tagNext = gTagsFree; + gTagsFree = tag; +} + +//========================================================================== +// Symbol object. + +struct Symbol +{ + long refCount; + struct Symbol *next; + char string[1]; +}; +typedef struct Symbol Symbol, *SymbolPtr; + +static SymbolPtr FindSymbol(char * string, SymbolPtr * prevSymbol); + +static SymbolPtr gSymbolsHead; + +//========================================================================== +// NewSymbol + +static char * +NewSymbol( char * string ) +{ + SymbolPtr symbol; + + // Look for string in the list of symbols. + symbol = FindSymbol(string, 0); + + // Add the new symbol. + if (symbol == 0) + { + symbol = AllocateBootXMemory(sizeof(Symbol) + strlen(string)); + if (symbol == 0) return 0; + + // Set the symbol's data. + symbol->refCount = 0; + strcpy(symbol->string, string); + + // Add the symbol to the list. + symbol->next = gSymbolsHead; + gSymbolsHead = symbol; + } + + // Update the refCount and return the string. + symbol->refCount++; + return symbol->string; +} + +//========================================================================== +// FreeSymbol + +static void +FreeSymbol( char * string ) +{ +#if 0 + SymbolPtr symbol, prev; + + // Look for string in the list of symbols. + symbol = FindSymbol(string, &prev); + if (symbol == 0) return; + + // Update the refCount. + symbol->refCount--; + + if (symbol->refCount != 0) return; + + // Remove the symbol from the list. + if (prev != 0) prev->next = symbol->next; + else gSymbolsHead = symbol->next; + + // Free the symbol's memory. + free(symbol); +#endif +} + +//========================================================================== +// FindSymbol + +static SymbolPtr +FindSymbol( char * string, SymbolPtr * prevSymbol ) +{ + SymbolPtr symbol, prev; + + symbol = gSymbolsHead; + prev = 0; + + while (symbol != 0) + { + if (!strcmp(symbol->string, string)) break; + + prev = symbol; + symbol = symbol->next; + } + + if ((symbol != 0) && (prevSymbol != 0)) *prevSymbol = prev; + + return symbol; +} diff --git a/i386/boot2/graphics.c b/i386/boot2/graphics.c index 4a2de7f..db91fe5 100644 --- a/i386/boot2/graphics.c +++ b/i386/boot2/graphics.c @@ -85,7 +85,7 @@ setMode(int mode) if ( currentMode() == mode ) return; if ( mode == GRAPHICS_MODE && - (vmode_name = newStringForKey(G_MODE_KEY)) != 0) + (vmode_name = newStringForKey(kGraphicsModeKey)) != 0) { // Set to the graphics mode specified in the config table file, // enable linear frame buffer mode, and update kernBootStruct. diff --git a/i386/boot2/old/Language.table b/i386/boot2/old/Language.table deleted file mode 100644 index 7fd4c33..0000000 --- a/i386/boot2/old/Language.table +++ /dev/null @@ -1,8 +0,0 @@ -"Languages" = "English French German Italian Spanish Swedish"; -"English" = "Type 1 to use the English language and USA keyboard while installing Rhapsody."; -"French" = "Tapez 2 pour installer Rhapsody avec un clavier et des messages francais."; -"German" = "Eingabe 3 fur Rhapsody-Installation mit deutscher Sprache und Tastatur."; -"Italian" = "Premi 4 per installare Rhapsody usando lingua italiana e tastiera italiana."; -"Spanish" = "Pulse 5 para usar el idioma y el teclado espanol en la instalacion de Rhapsody."; -"Swedish" = "Skriv 6 for att anvanda svenska/svenskt tangentbord vid installation av Rhapsody"; - diff --git a/i386/boot2/old/browser.c b/i386/boot2/old/browser.c deleted file mode 100644 index f41716e..0000000 --- a/i386/boot2/old/browser.c +++ /dev/null @@ -1,388 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 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 - * 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. - * - * 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 OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright 1993 NeXT, Inc. - * All rights reserved. - */ - -#import "libsa.h" -#import "console.h" -#import "fontio.h" -#import "graphics.h" -#import "button.h" -#import "browser.h" -#import "scrollbar.h" -#import "ns_logo.h" -#import "dot.h" -#import "hdot.h" -#import "keys.h" - -#define max(a,b) ((a) > (b) ? (a) : (b)) -#define min(a,b) ((a) < (b) ? (a) : (b)) - -browser_t * -createBrowser( - char **items, - int nitems, - char *top_message, - char *bottom_message, - char *button_string, - int type -) -{ - browser_t *bp; - register int i; - - bp = (browser_t *)zalloc(sizeof(browser_t)); - bp->items = items; - bp->nitems = nitems; - bp->bot_visible = min( MAX_ITEMS_VISIBLE - 1, nitems - 1 ); - /* bp->top_visible = 0; */ - - bp->top_message = top_message; - bp->top_h = max (strheight(bp->top_message), ns_logo_bitmap_HEIGHT); - bp->top_w = strwidth(bp->top_message) + ns_logo_bitmap_WIDTH + - BROWSER_XMARGIN; - bp->bottom_message = bottom_message; - bp->bottom_h = bottom_message ? - strheight(bottom_message) : - -BROWSER_YMARGIN; - bp->bottom_w = strwidth(bottom_message); - if (nitems) { - bp->selected = (char *)zalloc(nitems); - if (type == BROWSER_CURRENT_IS_SELECTED) - bp->selected[0] = 1; - bp->item_h = strheight(items[0]); - for(i=0; i < nitems; i++) - bp->item_w = max(bp->item_w, strwidth(items[i])); - bp->item_w += 2 * BROWSER_XMARGIN + dot_bitmap_WIDTH; - bp->item_box_w = bp->item_w + 2 * BROWSER_XMARGIN; - bp->item_box_h = bp->item_h * (bp->bot_visible - bp->top_visible + 1) - + 2 * BROWSER_YMARGIN; - initScrollbar(&bp->scrollbar, 0, 0, SB_WIDTH, - bp->item_box_h - 2 * POPUP_FRAME_MARGIN, - 0, (bp->bot_visible - bp->top_visible + 1) * 100 / bp->nitems); - bp->item_box_w += SB_WIDTH + POPUP_FRAME_MARGIN; - } else { - bp->item_box_h = -BROWSER_YMARGIN; - } - initButton(&bp->button, 0, 0, button_string, BUTTON_DRAW_RETURN); - bp->h = bp->top_h + bp->item_box_h + bp->bottom_h + - bp->button.loc.h + 5 * BROWSER_YMARGIN; - bp->w = max(bp->top_w, bp->bottom_w); - bp->w = max(bp->w, bp->item_box_w) + 2 * BROWSER_XMARGIN; - bp->x = (SCREEN_W - bp->w) / 2; - bp->y = (SCREEN_H - bp->h) / 2; - if (nitems) { - bp->item_box_x = bp->x + (bp->w - bp->item_box_w) / 2; - bp->scrollbar.loc.x = bp->item_box_x + POPUP_FRAME_MARGIN; - bp->item_box_y = bp->y + 2 * BROWSER_YMARGIN + bp->top_h; - bp->scrollbar.loc.y = bp->item_box_y + POPUP_FRAME_MARGIN; - } - bp->bottom_y = bp->y + 3 * BROWSER_YMARGIN + bp->top_h + bp->item_box_h; - bp->button.loc.x = bp->x + bp->w - bp->button.loc.w - BROWSER_XMARGIN; - bp->button.loc.y = bp->y + bp->h - bp->button.loc.h - BROWSER_YMARGIN; - - bp->type = type; - - return bp; -} - -inline void -destroyBrowser( - browser_t *bp -) -{ -/* destroyButton(bp->button); */ -/* destroyScrollbar(bp->scrollbar); */ - zfree((char *)bp); -} - -static int item_y( - browser_t *bp, - int item_num -) -{ - return ((bp)->item_box_y + BROWSER_YMARGIN + - (item_num - bp->top_visible) * (bp)->item_h + (bp)->item_h / 2); -} - -setItemHighlight(browser_t *bp, int item, int highlight) -{ - register int xpos = bp->item_box_x + POPUP_FRAME_MARGIN + - SB_WIDTH + BROWSER_XMARGIN; - if (currentMode() != GRAPHICS_MODE || - item < bp->top_visible || - item > bp->bot_visible) - return; - blit_clear(bp->item_w, xpos, item_y(bp, item), - CENTER_V, highlight ? COLOR_WHITE : TEXT_BG); - if (bp->selected[item]) - copyImage( highlight ? &hdot_bitmap : &dot_bitmap, - xpos, - item_y(bp, item) - dot_bitmap_HEIGHT/2); - xpos += BROWSER_XMARGIN + dot_bitmap_WIDTH; - blit_string(bp->items[item], xpos, item_y(bp, item), - TEXT_FG, CENTER_V); -} - -static void drawItembox(browser_t *bp) -{ - register int i; - bp->scrollbar.position = bp->top_visible * 100 / bp->nitems; - drawScrollbar(&bp->scrollbar); - for(i = bp->top_visible; i <= bp->bot_visible; i++) - setItemHighlight(bp, i, i == bp->current); -} - -static char *Separator = "----------------------------------------\n"; - -void drawBrowser(browser_t *bp) -{ - short item_y; - register int i; - - clearActivityIndicator(); - if (currentMode() == TEXT_MODE) { - printf("%s", Separator); - if (bp->top_message) { - printf("%s\n%s",bp->top_message, Separator); - } - if (bp->nitems) { - for (i = bp->top_visible; i <= bp->bot_visible; i++) { - printf("% 2d. %c %s\n",i+1, - bp->selected[i] ? '*' : ' ', - bp->items[i]); - } - if (bp->bot_visible != bp->nitems - 1) - printf("......\n"); - printf(Separator); - } - if (bp->bottom_message) { - printf("%s\n",bp->bottom_message); - } - printf(">> "); - } else { /* GRAPHICS_MODE */ - popupBox(bp->x, bp->y, bp->w, bp->h, TEXT_BG, POPUP_OUT); - copyImage(&ns_logo_bitmap, bp->x + BROWSER_XMARGIN, - bp->y + BROWSER_YMARGIN + (bp->top_h - ns_logo_bitmap_HEIGHT)/2 ); - blit_string(bp->top_message, - bp->x + ns_logo_bitmap_WIDTH + 2 * BROWSER_XMARGIN, - bp->y + (bp->top_h / 2) + BROWSER_YMARGIN, - TEXT_FG, CENTER_V); - if (bp->bottom_message) - blit_string(bp->bottom_message, - bp->x + bp->w / 2, bp->bottom_y + bp->bottom_h / 2, - TEXT_FG, CENTER_H | CENTER_V); - drawButton(&bp->button); - /* draw all items and highlight item 0 */ - if (bp->nitems) { - popupBox(bp->item_box_x, bp->item_box_y, - bp->item_box_w, bp->item_box_h, - TEXT_BG, POPUP_IN); - drawItembox(bp); - } - } -} - -clearBrowser(browser_t *bp) -{ - if (currentMode() == GRAPHICS_MODE) - clearBox(bp->x, bp->y, bp->w, bp->h); -} - - -selectItem(browser_t *bp, int item) -{ - int i; - if (bp->selected[item] == 0 && - (bp->type == BROWSER_CURRENT_IS_SELECTED)) { - for (i=0; i < bp->nitems; i++) - if (bp->selected[i]) { - bp->selected[i] = 0; - setItemHighlight(bp, i, i == bp->current); - } - } - bp->selected[item] = !bp->selected[item]; - setItemHighlight(bp, item, item == bp->current); -} - -runBrowser(browser_t *bp) -{ - int c, i; - char *s; - - if (bp->nitems == 0) { - while ((c = getc() != '\r')); - putc('\n'); - return; - } - - if (currentMode() == TEXT_MODE) { - s = zalloc(128); - for(;;) { - gets(s, 128); - if ((*s == 'f') || (*s == 'F')) { - if (currentMode() == TEXT_MODE) - if (bp->bot_visible != bp->nitems - 1) { - bp->top_visible += MAX_ITEMS_VISIBLE; - bp->bot_visible += MAX_ITEMS_VISIBLE; - bp->bot_visible = min(bp->nitems - 1, bp->bot_visible); - drawBrowser(bp); - continue; - } - } else if ((*s == 'b') || (*s == 'B')) { - if (currentMode() == TEXT_MODE) - if (bp->top_visible >= MAX_ITEMS_VISIBLE) { - bp->top_visible -= MAX_ITEMS_VISIBLE; - bp->bot_visible = bp->top_visible + - MAX_ITEMS_VISIBLE - 1; - drawBrowser(bp); - continue; - } - } - if (*s == '\0') - return; - i = atoi(s); - if (i < 1 || i > bp->nitems) { - printf("Please enter a number between 1 and %d.\n" - "Press :", - bp->nitems); - while ((c = getc()) != '\r'); - } else { - selectItem(bp, i-1); - } - drawBrowser(bp); - } - zfree(s); - return; - } - - for(;;) { - switch((c = getc())) { - case 'j': - case K_DOWN: - if (bp->current == bp->bot_visible && - bp->bot_visible != bp->nitems - 1) { - bp->top_visible++; - bp->bot_visible++; - bp->current++; - if (bp->type == BROWSER_CURRENT_IS_SELECTED) - selectItem(bp, bp->current); - drawItembox(bp); - } else if (bp->current < bp->nitems - 1) { - setItemHighlight(bp, bp->current, 0); - bp->current++; - if (bp->type == BROWSER_CURRENT_IS_SELECTED) - selectItem(bp, bp->current); - else - setItemHighlight(bp, bp->current, 1); - } - break; - case 'k': - case K_UP: - if (bp->current == bp->top_visible && - bp->top_visible != 0) { - bp->top_visible--; - bp->bot_visible--; - bp->current--; - if (bp->type == BROWSER_CURRENT_IS_SELECTED) - selectItem(bp, bp->current); - drawItembox(bp); - } else if (bp->current > 0) { - setItemHighlight(bp, bp->current, 0); - bp->current--; - if (bp->type == BROWSER_CURRENT_IS_SELECTED) - selectItem(bp, bp->current); - else - setItemHighlight(bp, bp->current, 1); - } - break; - case ' ': - if (!(bp->type == BROWSER_CURRENT_IS_SELECTED)) - selectItem(bp, bp->current); - break; - case '\r': - case '\n': - return; - } - } -} - -static browser_t *_doBrowser( - char **items, - int nitems, - char *top_message, - char *bottom_message, - char *button_string, - int type -) -{ - browser_t *bp; - - bp = createBrowser(items, nitems, - top_message, bottom_message, button_string, type); - drawBrowser(bp); - runBrowser(bp); - clearBrowser(bp); - return bp; -} - -/* - * returns an array of characters, one per item, - * that are set to 0 if the item was not selected, - * 1 if the item was selected. - */ -char * popupBrowser( - char **items, - int nitems, - char *top_message, - char *bottom_message, - char *button_string, - int type -) -{ - browser_t *bp; - register char *selected; - - bp = _doBrowser(items, nitems, - top_message, bottom_message, button_string, type); - selected = bp->selected; - destroyBrowser(bp); - return selected; -} - -void popupPanel( - char *message -) -{ - browser_t *bp; - - bp = _doBrowser(0, 0, - message, 0, "Continue", 0); - zfree(bp->selected); - destroyBrowser(bp); -} - - diff --git a/i386/boot2/old/browser.h b/i386/boot2/old/browser.h deleted file mode 100644 index 6dbd816..0000000 --- a/i386/boot2/old/browser.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 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 - * 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. - * - * 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 OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -#import "graphics.h" -#import "button.h" -#import "scrollbar.h" - -typedef struct browser { - rect_t loc; - short x,y,w,h; - char **items; - char *selected; - char *top_message; - char *bottom_message; - short nitems; - short current; - short top_visible; - short bot_visible; - short type; - short item_box_x, item_box_y; /* item box location */ - short item_box_w, item_box_h; - short item_h, item_w; /* individual item metrics */ - short top_h, top_w; /* size of top text area */ - button_t button; - scroll_t scrollbar; - short bottom_y; - short bottom_h, bottom_w; /* size of bottom text area */ -} browser_t; - -#define BROWSER_XMARGIN 8 -#define BROWSER_YMARGIN 8 - -#define MAX_ITEMS_VISIBLE 8 - -#define BROWSER_SELECT_MULTIPLE 0 -#define BROWSER_CURRENT_IS_SELECTED 1 - -#define BROWSER_NO_MESSAGE ((char *)0) -#define BROWSER_INSTRUCTIONS ((char *)1) - -extern char * popupBrowser( - char **items, - int nitems, - char *top_message, - char *bottom_message, - char *button_string, - int type -); diff --git a/i386/boot2/old/button.c b/i386/boot2/old/button.c deleted file mode 100644 index fc3a725..0000000 --- a/i386/boot2/old/button.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 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 - * 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. - * - * 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 OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright 1993 NeXT, Inc. - * All rights reserved. - */ - -#import "libsa.h" -#import "console.h" -#import "fontio.h" -#import "graphics.h" -#import "button.h" -#import "return.h" - -button_t *initButton( - button_t *bp, - int x, - int y, - char *message, - int drawReturnSign -) -{ - bp->loc.x = x; - bp->loc.y = y; - bp->loc.h = strheight(message) + 2 * BUTTON_YMARGIN; - bp->loc.w = strwidth(message) + 2 * BUTTON_XMARGIN; - if (drawReturnSign) - bp->loc.w += return_bitmap_WIDTH + BUTTON_XMARGIN; - bp->message = message; - bp->flags = drawReturnSign ? BUTTON_DRAW_RETURN : 0; - return bp; -} - -#if 0 -void destroyButton( - button_t *bp -) -{ - zfree((char *)bp); -} -#endif - -void drawButton( - button_t *bp -) -{ - popupBox(bp->loc.x, bp->loc.y, bp->loc.w, bp->loc.h, TEXT_BG, POPUP_OUT); - blit_string(bp->message, - bp->loc.x + BUTTON_XMARGIN, bp->loc.y + bp->loc.h / 2, - TEXT_FG, CENTER_V); - if (bp->flags & BUTTON_DRAW_RETURN) { - copyImage(&return_bitmap, - bp->loc.x + bp->loc.w - BUTTON_XMARGIN - return_bitmap_WIDTH, - bp->loc.y + (bp->loc.h - return_bitmap_HEIGHT) / 2); - } -} - -#if 0 -void -clearButton( - button_t *bp, - int color -) -{ - clearRect(bp->loc.x,bp->loc.y, bp->loc.w, bp->loc.h, color); -} -#endif diff --git a/i386/boot2/old/button.h b/i386/boot2/old/button.h deleted file mode 100644 index ab0a8f1..0000000 --- a/i386/boot2/old/button.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 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 - * 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. - * - * 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 OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -#import "graphics.h" - -typedef struct button { - rect_t loc; - int flags; - char *message; -} button_t; - -#define BUTTON_DRAW_RETURN 1 -#define BUTTON_XMARGIN 6 -#define BUTTON_YMARGIN 6 - -extern button_t *initButton( - button_t *bp, - int x, - int y, - char *message, - int drawReturnSign -); - -extern void destroyButton( - button_t *bp -); - -extern void drawButton( - button_t *bp -); \ No newline at end of file diff --git a/i386/boot2/old/questionbox.c b/i386/boot2/old/questionbox.c deleted file mode 100644 index 9ef62c7..0000000 --- a/i386/boot2/old/questionbox.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 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 - * 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. - * - * 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 OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright 1993 NeXT, Inc. - * All rights reserved. - */ - -#import "libsaio.h" -#import "io_inline.h" -#import "kernBootStruct.h" -#import "font.h" -#import "bitmap.h" -#import "console.h" -#import "graphics.h" -#import "ns_box.h" -#import "ns_logo.h" - -int -popupQuestionBox(char *string) -{ - int ch, answer=0; - int popup_x, popup_y, popup_w, popup_top_h, popup_h; - int popup_t_x, popup_t_y, popup_t_w; - int xpos; - int blink = 0; - int time, endtime; - char buf[64]; - - clearActivityIndicator(); - if (kernBootStruct->graphicsMode == GRAPHICS_MODE) { - popup_w = strwidth(string) + ns_logo_bitmap_WIDTH + - 3 * POPUP_XMARGIN; - popup_x = (SCREEN_W - popup_w) / 2; - popup_t_x = (popup_x + (popup_w - POPUP_T_W) / 2); - popup_top_h = max(strheight(string), ns_logo_bitmap.height) - + 2 * POPUP_YMARGIN; - popup_h = popup_top_h + POPUP_YMARGIN + POPUP_T_H; - popup_y = (SCREEN_H - popup_h) / 2; - popup_t_y = popup_y + popup_h - (POPUP_T_H + POPUP_YMARGIN); - popupBox(popup_x, popup_y, popup_w, popup_h, TEXT_BG, POPUP_OUT); - - copyImage(&ns_logo_bitmap, popup_x + POPUP_XMARGIN, - popup_y + (popup_top_h - ns_logo_bitmap_HEIGHT) / 2); - popupBox(popup_t_x, popup_t_y, - POPUP_T_W, POPUP_T_H, COLOR_WHITE, POPUP_IN); - blit_string(string, popup_x + ns_logo_bitmap_WIDTH + 2 * POPUP_XMARGIN, - popup_y + (popup_top_h - strheight(string)) / 2 - + fontp->bbx.height + fontp->bbx.yoff, - TEXT_FG, 0); - xpos = popup_t_x + POPUP_T_XMARGIN - fontp->bbx.xoff; - - for (;;) { - time = time18(); - endtime = time + 12; - - blink = ! blink; - clearRect(xpos, popup_t_y + POPUP_T_YMARGIN, 1, - POPUP_T_H - 2 * POPUP_T_YMARGIN, - blink ? COLOR_BLACK : COLOR_WHITE); - while (time18() < endtime) - if (ch = readKeyboardStatus()) - break; - if (ch) { - ch = getc(); - switch (ch) { - case '\n': - case '\r': - /* erase popup box */ - clearBox(popup_x, popup_y, popup_w, popup_h); - return answer; - case '\b': - clearRect(popup_t_x+3, popup_t_y+3, - POPUP_T_W-6, POPUP_T_H-6, COLOR_WHITE); - blink = answer = 0; - xpos = popup_t_x + POPUP_T_XMARGIN - fontp->bbx.xoff; - break; - default: - if (answer) - break; - buf[0] = answer = ch; - buf[1] = '\0'; - clearRect(xpos, popup_t_y + POPUP_T_YMARGIN, 1, - POPUP_T_H - 2 * POPUP_T_YMARGIN, COLOR_WHITE); - blink = 0; - xpos += blit_string(buf, xpos, - popup_t_y + POPUP_T_YMARGIN + fontp->bbx.height - + fontp->bbx.yoff, - COLOR_BLACK, 0); - break; - } - } - } - } else { - printf(string); - printf("\n>> "); - gets(buf,sizeof(buf)); - return buf[0]; - } -} diff --git a/i386/boot2/old/scanmemory.c b/i386/boot2/old/scanmemory.c deleted file mode 100644 index 152040b..0000000 --- a/i386/boot2/old/scanmemory.c +++ /dev/null @@ -1,395 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 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 - * 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. - * - * 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 OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -#import - -#import -#import - -/* - * Primatives for manipulating the - * cpu cache(s). - */ - -static __inline__ -void -enable_cache(void) -{ - cr0_t cr0; - - asm volatile( - "mov %%cr0,%0" - : "=r" (cr0)); - - cr0.cd = cr0.nw = 0; - - asm volatile( - "wbinvd; mov %0,%%cr0" - : - : "r" (cr0)); -} - -static __inline__ -void -flush_cache(void) -{ - asm volatile("wbinvd"); -} - -/* - * Memory sizing code. - * - * Tunable Parameters: - * SCAN_INCR Size of memory scanning segment. - * SCAN_LEN Length to actually test, per segment, - * starting at the front of the segment. - * SCAN_LIM Highest address to test for existence of memory. - * - * Assumptions: - * Primary assumption is that SCAN_INCR and SCAN_LEN are chosen - * and the stack is positioned in its segment such that the tested - * portion of the segment does not overlap with any portion of the - * stack's location in that segment. The best way to acomplish this - * is to position the stack at the high end of a segment, and to make - * the segment size large enough to prevent it from overlapping the - * test area. The stack needs to be large enough to contain the low - * memory save area as well as the code for the scan function. - */ -#define KB(x) (1024*(x)) -#define MB(x) (1024*KB(x)) - -#define SCAN_PAT0 0x76543210 -#define SCAN_PAT1 0x89abcdef - -struct test_datum { - unsigned int word0; - unsigned int word1; -}; - -vm_offset_t -scan_memory( - vm_offset_t end_of_memory, - vm_offset_t end_of_cnvmem, - unsigned int SCAN_INCR, - unsigned int SCAN_LEN, - unsigned int SCAN_LIM -) -{ - struct test_datum zero_pat = { 0, 0 }; - vm_offset_t memory; - - /* - * Make sure that the cache(s) are flushed - * and enabled. - */ - enable_cache(); - - /* - * Round the starting address to the next - * segment boundary. This is where we will - * begin testing. - */ - end_of_memory = (end_of_memory + (SCAN_INCR - 1) & ~(SCAN_INCR - 1)); - - /* - * Zero out the test area of each segent - * which is located in extended memory. - */ - memory = KB(1024); - - while (memory < end_of_memory) { - struct test_datum *memory_ptr; - - (vm_offset_t)memory_ptr = memory; - - while ((vm_offset_t)memory_ptr < memory + SCAN_LEN) - *memory_ptr++ = zero_pat; - - memory += SCAN_INCR; - } - - { - /* - * Code for segment scanning function. - */ - extern unsigned int Scan_segment_code[], - Scan_segment_code_end[]; - /* - * Location on the stack to where this - * function is copied and then executed - * from!! N.B. This code must be position - * independent. (duh) - */ - unsigned int scan_func[ - Scan_segment_code_end - - Scan_segment_code]; - - /* - * Copy the scan function onto the stack. - */ - memcpy(scan_func, Scan_segment_code, sizeof (scan_func)); - - while (end_of_memory < SCAN_LIM) { - display_kbytes(end_of_memory); - if (!((vm_offset_t (*)())scan_func)( - end_of_memory, - end_of_cnvmem, - SCAN_INCR, - SCAN_LEN)) - break; - - end_of_memory += SCAN_INCR; - } - } - - display_kbytes(end_of_memory); - - return (end_of_memory); -} - -static -void -display_kbytes( - vm_offset_t address -) -{ - unsigned int quant, dig, done = 0, mag = 1000000000; - int places = 1; - - quant = address / 1024; - - while (mag > 0) { - done *= 10; - dig = (quant / mag) - done; - done += dig; - if (done > 0 || mag == 1) { - putc(dig + '0'); - places++; - } - mag /= 10; - } - - putc('K'); - - while (places-- > 0) - putc('\b'); -} - -/* - * Memory scan function, which tests one segment of memory. - * This code is copied onto the stack and executed there to - * avoid problems when memory aliasing occurs. If it detects - * problems due to aliasing to low memory, it restores the - * low memory segments before returning. - * - * Parameters: - * end_of_memory Address to start testing at, - * this is rounded to the start of - * the next segment internally. - * end_of_cnvmem Address where conventional - * memory ends. - * SCAN_INCR Size of each segment. - * SCAN_LEN Size of per segment test area, - * located at the front of the segment. - * SCAN_LIM Address next segment after highest - * to test. - */ -static -boolean_t -scan_segment( - vm_offset_t start_of_segment, - vm_offset_t end_of_cnvmem, - unsigned int SCAN_INCR, - unsigned int SCAN_LEN -) -{ - /* - * Location on the stack where the test - * area of each segment of low memory is - * saved, appended together. The copy is - * used to detect memory aliasing and to - * restore memory on that occasion. - */ - unsigned int copy_area[ - ((KB(640) / SCAN_INCR) * SCAN_LEN) - / sizeof (unsigned int)]; - struct test_datum *test_ptr, - test_pat = { SCAN_PAT0, SCAN_PAT1 }, - zero_pat = { 0, 0 }; - vm_offset_t memory, copy; - - /* - * Copy the test area of each low memory - * segment to the save area. Low memory - * begins at zero, and runs to the end of - * conventional memory. - */ - copy = (vm_offset_t)copy_area; - memory = 0; - - while (memory < KB(640)) { - unsigned int *memory_ptr, *copy_ptr; - - if (memory <= (end_of_cnvmem - SCAN_LEN)) { - (vm_offset_t)memory_ptr = memory; - (vm_offset_t)copy_ptr = copy; - - while ((vm_offset_t)memory_ptr < memory + SCAN_LEN) - *copy_ptr++ = *memory_ptr++; - } - - memory += SCAN_INCR; copy += SCAN_LEN; - } - - /* - * Write the test pattern in the test - * area of the current segment. - */ - (vm_offset_t)test_ptr = start_of_segment; - - while ((vm_offset_t)test_ptr < start_of_segment + SCAN_LEN) - *test_ptr++ = test_pat; - - /* - * Flush the data cache to insure that the - * data actually gets written to main memory. - * This will provoke aliasing to occur if - * it is in fact present. - */ - flush_cache(); - - /* - * Compare low memory against the save - * area, breaking out immediately if - * an inconsistency is observed. - */ - copy = (vm_offset_t)copy_area; - memory = 0; - - while (memory < KB(640)) { - struct test_datum *memory_ptr, *copy_ptr; - - if (memory <= (end_of_cnvmem - SCAN_LEN)) { - (vm_offset_t)memory_ptr = memory; - (vm_offset_t)copy_ptr = copy; - - while ((vm_offset_t)memory_ptr < memory + SCAN_LEN) { - if ( memory_ptr->word0 != copy_ptr->word0 || - memory_ptr->word1 != copy_ptr->word1 ) - break; - - memory_ptr++; copy_ptr++; - } - - if ((vm_offset_t)memory_ptr < memory + SCAN_LEN) - break; - } - - memory += SCAN_INCR; copy += SCAN_LEN; - } - - /* - * If an inconsistency was found in low - * memory, restore the entire region from - * the save area and return a failure. - */ - if (memory < KB(640)) { - copy = (vm_offset_t)copy_area; - memory = 0; - - while (memory < KB(640)) { - unsigned int *memory_ptr, *copy_ptr; - - if (memory <= (end_of_cnvmem - SCAN_LEN)) { - (vm_offset_t)memory_ptr = memory; - (vm_offset_t)copy_ptr = copy; - - while ((vm_offset_t)memory_ptr < memory + SCAN_LEN) - *memory_ptr++ = *copy_ptr++; - } - - memory += SCAN_INCR; copy += SCAN_LEN; - } - - return (FALSE); - } - - /* - * Check the memory we have already scanned - * to see whether aliasing occurred there. - * The test area of each segment should contain - * zeros. - */ - memory = KB(1024); - - while (memory < start_of_segment) { - struct test_datum *memory_ptr; - - (vm_offset_t)memory_ptr = memory; - - while ((vm_offset_t)memory_ptr < memory + SCAN_LEN) { - if ( memory_ptr->word0 != zero_pat.word0 || - memory_ptr->word1 != zero_pat.word1 ) - break; - - memory_ptr++; - } - - if ((vm_offset_t)memory_ptr < memory + SCAN_LEN) - break; - - memory += SCAN_INCR; - } - - if (memory < start_of_segment) - return (FALSE); - - /* - * Now check the current segment to see - * whether the test patten was correctly - * written out. - */ - (vm_offset_t)test_ptr = start_of_segment; - - while ((vm_offset_t)test_ptr < start_of_segment + SCAN_LEN) { - if ( test_ptr->word0 != test_pat.word0 || - test_ptr->word1 != test_pat.word1 ) - break; - - test_ptr++; - } - - if ((vm_offset_t)test_ptr < start_of_segment + SCAN_LEN) - return (FALSE); - - /* - * Zero the current segment, which has now - * passed the test!! - */ - (vm_offset_t)test_ptr = start_of_segment; - - while ((vm_offset_t)test_ptr < start_of_segment + SCAN_LEN) - *test_ptr++ = zero_pat; - - return (TRUE); -} diff --git a/i386/boot2/old/scanmemory.sed b/i386/boot2/old/scanmemory.sed deleted file mode 100644 index 71a5dd6..0000000 --- a/i386/boot2/old/scanmemory.sed +++ /dev/null @@ -1,6 +0,0 @@ -s/_scan_segment/.globl _Scan_segment_code\ -_Scan_segment_code/ -$a\ -.align 2,0x90\ -.globl _Scan_segment_code_end\ -_Scan_segment_code_end: diff --git a/i386/boot2/old/scrollbar.c b/i386/boot2/old/scrollbar.c deleted file mode 100644 index 31d659e..0000000 --- a/i386/boot2/old/scrollbar.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 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 - * 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. - * - * 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 OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright 1993 NeXT, Inc. - * All rights reserved. - */ - -#import "libsa.h" -#import "console.h" -#import "fontio.h" -#import "graphics.h" -#import "scrollbar.h" - - -scroll_t *initScrollbar( - scroll_t *sp, - int x, - int y, - int w, - int h, - int position, /* 0 - 100 */ - int percent /* 0 - 100 */ -) -{ - sp->loc.x = x; - sp->loc.y = y; - sp->loc.w = w; - sp->loc.h = h; - sp->position = position; - sp->percent = percent; - return sp; -} - -#if 0 -void destroyScrollbar( - scroll_t *sp -) -{ - (void)zfree((char *)sp); -} -#endif - -void drawScrollbar( - scroll_t *sp -) -{ - clearRect(sp->loc.x, sp->loc.y, sp->loc.w, sp->loc.h, SB_BG); -// clearRect(sp->loc.x, sp->loc.y, sp->loc.w, 1, COLOR_BLACK); -// clearRect(sp->loc.x, sp->loc.y + sp->loc.h - 1, sp->loc.w, 1, COLOR_BLACK); -// clearRect(sp->loc.x, sp->loc.y, 1, sp->loc.h, COLOR_BLACK); - clearRect(sp->loc.x + sp->loc.w - 1, sp->loc.y, 1, sp->loc.h, COLOR_BLACK); - if (sp->percent < 100) - popupBox(sp->loc.x + SB_MARGIN, - sp->loc.y + (sp->position * (sp->loc.h - 2 * SB_MARGIN)) / 100, - sp->loc.w - 3 * SB_MARGIN, - (sp->loc.h - 2 * SB_MARGIN) * sp->percent / 100, - TEXT_BG, POPUP_OUT); -} - -#if 0 -void clearScrollbar( - scroll_t *sp, - int color -) -{ - clearRect(sp->loc.x, sp->loc.y, sp->loc.w, sp->loc.h, color); -} -#endif diff --git a/i386/boot2/old/scrollbar.h b/i386/boot2/old/scrollbar.h deleted file mode 100644 index 96607e5..0000000 --- a/i386/boot2/old/scrollbar.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 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 - * 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. - * - * 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 OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* scroll bar */ -#import - -typedef struct scrollbar { - rect_t loc; - unsigned char position; /* 0 - 100 */ - unsigned char percent; /* 0 - 100 */ -} scroll_t; - -#define SB_MARGIN 1 -#define SB_BG COLOR_DK_GREY - -#define SB_WIDTH 16 \ No newline at end of file diff --git a/i386/boot2/old/sizememory.c b/i386/boot2/old/sizememory.c deleted file mode 100644 index ed4e3b7..0000000 --- a/i386/boot2/old/sizememory.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 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 - * 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. - * - * 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 OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -#import - -#define KB(x) (1024*(x)) -#define MB(x) (1024*KB(x)) - -unsigned int -sizememory( - unsigned int cnvmem -) -{ - vm_offset_t end_of_memory; -#define SCAN_INCR KB(64) -#define SCAN_LEN 8 -#define SCAN_LIM MB(512) - - printf("\nSizing memory... "); - - if (readKeyboardShiftFlags() & 0x2) { /* left SHIFT key depressed */ - printf("[aborted]"); - end_of_memory = KB(memsize(1)) + MB(1); - } - else { - /* - * First scan beginning at start of - * extended memory using a reasonably - * large segment size. - */ - end_of_memory = scan_memory( - KB(1024), - KB(cnvmem), - SCAN_INCR, - SCAN_LEN, - SCAN_LIM); - - /* - * Now scan the top segment a page at - * a time to find the actual end of - * extended memory. - */ - if (end_of_memory > KB(1024)) - end_of_memory = scan_memory( - end_of_memory - SCAN_INCR, - KB(cnvmem), - KB(4), - SCAN_LEN, - end_of_memory); - } - - return (end_of_memory / 1024); -} diff --git a/i386/boot2/old/test b/i386/boot2/old/test deleted file mode 100755 index aab3b98f2926d890558a360b5d77a239163d8d0f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 50652 zcmeHQ3z!{6mG0==7!XZxgSr~XC_x@3VP^80%rI;M2_XtGLI^=1&7FJu&Rpicw(q@@ znJlP~2*iL!g*A#SAaOP7#-O11@i08xDC!C>tGkGR3u@G4bys|R?nw4Or%rX(eT445 zFhKU}`+bx8>-4FrQ>UsQ`c{?!u(XU;Vl>nqP^t0`XGg47l#cR_a*JoMF zk?(OwDp`F_AK7+hIG@Y*+u1_4($OeG9n?;PF9j2$gf%Y z!{}MNpGH`{0P+{}`C>s6>hqYg$g(EML*0H9ogg%gRsT6-`HFWgU9w#Fg^Td?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TD_aLCveuUZ`8x&<_6V&kJ`m+jGC+pikGm(9r%K?dV|>a~y7T z!$x4Jrm0&r2bv9EbNnt5bub)oaTsg{(Kpq8Z#b7-u&WCbBbztx0>|;NBL0<+QB{X- zTfhD}@I8Iht*a&PYSPA+T&B>j2w%! -#import "kernBootStruct.h" - -main() -{ - KERNBOOTSTRUCT kb; - printf("EISA info size: %d bytes\n",sizeof(EISA_slot_info_t)); - printf("reserved size: %d bytes\n",sizeof(kb._reserved)); - printf("offset of APM: %d\n",offsetof(KERNBOOTSTRUCT, apm_config)); - printf("offset of config: %d\n",offsetof(KERNBOOTSTRUCT, config)); - printf("space left at end: %d\n",65536 - (offsetof(KERNBOOTSTRUCT, config) + sizeof(kb.config))); -} diff --git a/i386/boot2/prompt.c b/i386/boot2/prompt.c index 083f9c8..4c3eb03 100644 --- a/i386/boot2/prompt.c +++ b/i386/boot2/prompt.c @@ -28,5 +28,12 @@ #include "vers.h" -char bootPrompt[] = "\n\nDarwin Intel boot v" I386BOOT_VERSION "\n" - "%dK conventional / %dK total memory\n\n"; +char bootPrompt[] = "\n\nDarwin/x86 boot v" I386BOOT_VERSION "\n" + "%dK conventional / %dK extended memory\n\n" + "Darwin/x86 will start up in %d seconds, or you can:\n" + " Type -v and press Return to start up Darwin/x86 with " + "diagnostic messages\n" + " Type ? and press Return to learn about advanced startup " + "options\n" + " Type any other character to stop Darwin/x86 from " + "starting up automatically\n"; diff --git a/i386/libsa/Makefile b/i386/libsa/Makefile index eaad0d0..fbf2c0f 100644 --- a/i386/libsa/Makefile +++ b/i386/libsa/Makefile @@ -25,12 +25,12 @@ VPATH = $(OBJROOT):$(SYMROOT) SA_OBJS = prf.o printf.o zalloc.o \ string.o strtol.o error.o \ - setjmp.o qsort.o + setjmp.o qsort.o bswap.o SFILES = setjmp.s CFILES = prf.c printf.c zalloc.c \ string.c strtol.c error.c \ - qsort.c + qsort.c bswap.c HFILES = memory.h EXPORTED_HFILES = libsa.h kernBootStruct.h memory.h INSTALLED_SA_HFILES = libsa.h diff --git a/i386/boot2/old/start.s b/i386/libsa/bswap.c similarity index 84% rename from i386/boot2/old/start.s rename to i386/libsa/bswap.c index 4ef9a99..48baf4b 100644 --- a/i386/boot2/old/start.s +++ b/i386/libsa/bswap.c @@ -22,10 +22,12 @@ * @APPLE_LICENSE_HEADER_END@ */ -#include +#include "libsa.h" - .file "start.s" -TEXT -LABEL(boot_start) - jmp _boot - . = boot_start + 0x1000 +unsigned long bswap32( unsigned long data ) +{ + __asm__ volatile("bswap %0" + : "=r" (data) + : "0" (data)); + return data; +} diff --git a/i386/libsa/kernBootStruct.h b/i386/libsa/kernBootStruct.h index e4c2403..550db5d 100644 --- a/i386/libsa/kernBootStruct.h +++ b/i386/libsa/kernBootStruct.h @@ -29,81 +29,53 @@ #ifndef __BOOT_KERNBOOTSTRUCT_H #define __BOOT_KERNBOOTSTRUCT_H -/* The config table has room for 13 drivers if their config files - * are the maximum size allowed. +/* + * Maximum number of boot drivers that can be loaded. */ -#define CONFIG_SIZE (13 * 4096) +#define NDRIVERS 500 -/* Maximum number of boot drivers supported, assuming their - * config files fit in the bootstruct. +/* + * Types of boot driver that may be loaded by the booter. */ -#define NDRIVERS 64 +enum { + kBootDriverTypeInvalid = 0, + kBootDriverTypeKEXT = 1, + kBootDriverTypeMKEXT = 2 +}; typedef struct { - char * address; // address where driver was loaded - int size; // entry point for driver + unsigned long address; // address where driver was loaded + unsigned long size; // number of bytes + unsigned long type; // driver type } driver_config_t; +/* + * APM BIOS information. + */ typedef struct { - unsigned short major_vers; // == 0 if not present - unsigned short minor_vers; - unsigned long cs32_base; - unsigned long cs16_base; - unsigned long ds_base; - unsigned long cs_length; - unsigned long ds_length; - unsigned long entry_offset; + unsigned short major_vers; // == 0 if not present + unsigned short minor_vers; + unsigned long cs32_base; + unsigned long cs16_base; + unsigned long ds_base; + unsigned long cs_length; + unsigned long ds_length; + unsigned long entry_offset; union { struct { - unsigned long mode_16 :1; - unsigned long mode_32 :1; - unsigned long idle_slows_cpu :1; - unsigned long reserved :29; + unsigned long mode_16 :1; + unsigned long mode_32 :1; + unsigned long idle_slows_cpu :1; + unsigned long reserved :29; } f; unsigned long data; } flags; - unsigned long connected; + unsigned long connected; } APM_config_t; -typedef struct _EISA_slot_info_t { - union { - struct { - unsigned char duplicateID :4; - unsigned char slotType :1; - unsigned char prodIDPresent :1; - unsigned char dupIDPresent :1; - } s; - unsigned char d; - } u_ID; - unsigned char configMajor; - unsigned char configMinor; - unsigned short checksum; - unsigned char numFunctions; - union { - struct { - unsigned char fnTypesPresent :1; - unsigned char memoryPresent :1; - unsigned char irqPresent :1; - unsigned char dmaPresent :1; - unsigned char portRangePresent :1; - unsigned char portInitPresent :1; - unsigned char freeFormPresent :1; - unsigned char reserved :1; - } s; - unsigned char d; - } u_resources; - unsigned char id[8]; -} EISA_slot_info_t; - -typedef struct _EISA_func_info_t { - unsigned char slot; - unsigned char function; - unsigned char reserved[2]; - unsigned char data[320]; -} EISA_func_info_t; - -#define NUM_EISA_SLOTS 64 - +/* + * PCI bus information. + */ typedef struct _PCI_bus_info_t { union { struct { @@ -122,68 +94,53 @@ typedef struct _PCI_bus_info_t { } PCI_bus_info_t; /* - * Video information.. + * Video information. */ struct boot_video { - unsigned long v_baseAddr; /* Base address of video memory */ - unsigned long v_display; /* Display Code (if Applicable */ - unsigned long v_rowBytes; /* Number of bytes per pixel row */ - unsigned long v_width; /* Width */ - unsigned long v_height; /* Height */ - unsigned long v_depth; /* Pixel Depth */ + unsigned long v_baseAddr; // Base address of video memory + unsigned long v_display; // Display Code (if Applicable + unsigned long v_rowBytes; // Number of bytes per pixel row + unsigned long v_width; // Width + unsigned long v_height; // Height + unsigned long v_depth; // Pixel Depth }; -typedef struct boot_video boot_video; - -#define BOOT_STRING_LEN 160 - -typedef struct { - short version; - char bootString[BOOT_STRING_LEN]; // string we booted with - int magicCookie; // KERNBOOTMAGIC if struct valid - int numIDEs; // how many IDE drives - int rootdev; // booters guess as to rootdev - int convmem; // conventional memory - int extmem; // extended memory - char boot_file[128]; // name of the kernel we booted - int first_addr0; // first address for kern convmem - int diskInfo[4]; // bios info for bios dev 80-83 - int graphicsMode; // did we boot in graphics mode? - int kernDev; // device kernel was fetched from - int numBootDrivers; // number of drivers loaded by booter - char * configEnd; // pointer to end of config files - int kaddr; // kernel load address - int ksize; // size of kernel - void * rld_entry; // entry point for standalone rld - - driver_config_t driverConfig[NDRIVERS]; - APM_config_t apm_config; - - char _reserved[7500]; +typedef struct boot_video boot_video; - boot_video video; +#define GRAPHICS_MODE 1 +#define TEXT_MODE 0 - PCI_bus_info_t pciInfo; - - int eisaConfigFunctions; - EISA_slot_info_t eisaSlotInfo[NUM_EISA_SLOTS]; +#define BOOT_STRING_LEN 160 +#define CONFIG_SIZE (12 * 4096) - char config[CONFIG_SIZE]; // the config file contents +typedef struct { + short version; + char bootString[BOOT_STRING_LEN]; // boot arguments + int magicCookie; // KERNBOOTMAGIC + int numIDEs; // number of IDE drives + int rootdev; // root device + int convmem; // conventional memory + int extmem; // extended memory + char bootFile[128]; // kernel file name + int firstAddr0; // first address for kern convmem + int diskInfo[4]; // info for bios dev 80-83 + int graphicsMode; // booted in graphics mode? + int kernDev; // device kernel was fetched from + int numBootDrivers; // number of drivers loaded + char * configEnd; // pointer to end of config files + int kaddr; // kernel load address + int ksize; // size of kernel + driver_config_t driverConfig[NDRIVERS]; + char _reserved[2052]; + boot_video video; + PCI_bus_info_t pciInfo; + APM_config_t apmConfig; + char config[CONFIG_SIZE]; } KERNBOOTSTRUCT; -#define GRAPHICS_MODE 1 -#define TEXT_MODE 0 - #define KERNSTRUCT_ADDR ((KERNBOOTSTRUCT *) 0x11000) #define KERNBOOTMAGIC 0xa7a7a7a7 -#if 0 -#ifndef EISA_CONFIG_ADDR -#define EISA_CONFIG_ADDR 0x20000 -#define EISA_CONFIG_LEN 0x10000 -#endif -#endif - #ifndef KERNEL extern KERNBOOTSTRUCT * kernBootStruct; #endif diff --git a/i386/libsa/libsa.h b/i386/libsa/libsa.h index ac42141..a88097d 100644 --- a/i386/libsa/libsa.h +++ b/i386/libsa/libsa.h @@ -94,8 +94,6 @@ extern int slvprintf(char * buffer, /* * zalloc.c */ -#define ZALLOC_NODES 384 - extern void malloc_init(char * start, int size, int nodes); extern void * malloc(size_t size); extern void free(void * start); @@ -107,4 +105,9 @@ extern void * realloc(void * ptr, size_t size); extern struct segment_command * getsegbynamefromheader(struct mach_header * mhp, char * segname); +/* + * bswap.c + */ +extern unsigned long bswap32( unsigned long data ); + #endif /* !__BOOT_LIBSA_H */ diff --git a/i386/libsa/memory.h b/i386/libsa/memory.h index 2ed3db6..ee65894 100644 --- a/i386/libsa/memory.h +++ b/i386/libsa/memory.h @@ -40,35 +40,24 @@ #define BOOTER_ADDR 0x003000 // start of booter code #define BOOTER_LEN 0x00B000 #define STACK_ADDR 0x00FFF0 -#define BOOTSTRUCT_ADDR 0x011000 -#define BOOTSTRUCT_LEN 0x00F000 // it's slightly smaller -#define EISA_CONFIG_ADDR 0x020000 -#define EISA_CONFIG_LEN 0x010000 -#define RLD_ADDR 0x030000 +#define BOOTSTRUCT_ADDR 0x011000 // it's slightly smaller +#define BOOTSTRUCT_LEN 0x00F000 +#define RLD_ADDR 0x030000 // not used #define RLD_LEN 0x070000 #define VIDEO_ADDR 0x0A0000 // unusable space #define VIDEO_LEN 0x060000 -#define KERNEL_ADDR 0x100000 -#define KERNEL_LEN 0x400000 -#define RLD_MEM_ADDR 0x500000 -#define RLD_MEM_LEN 0x100000 -#define ZALLOC_ADDR 0x600000 +#define KERNEL_ADDR 0x100000 // 14Mb kernel + drivers +#define KERNEL_LEN 0xe00000 +#define ZALLOC_ADDR 0xf00000 // 1Mb for zalloc #define ZALLOC_LEN 0x100000 -#define MODULE_ADDR 0x700000 // to be used for compression.. -#define MODULE_LEN 0x080000 -#define KSYM_ADDR 0x780000 -#define KSYM_LEN 0x080000 // 512k -#define TFTP_ADDR 0x800000 // 8MB -#define TFTP_LEN 0x400000 // 4MB buffer size +#define TFTP_ADDR 0x1000000 // 8Mb download buffer +#define TFTP_LEN 0x800000 -/* these are physical values */ +/* These are physical values */ -#define CONVENTIONAL_LEN 0x0A0000 // 640k -#define EXTENDED_ADDR 0x100000 // 1024k -#define KERNEL_BOOT_ADDR KERNEL_ADDR /* load at 1Mb */ - -#define SAIO_TABLE_POINTER (BOOTER_ADDR + SAIO_TABLE_PTR_OFFSET) -#define SAIO_TABLE_PTR_OFFSET 0x30 +#define CONVENTIONAL_LEN 0x0A0000 // 640k +#define EXTENDED_ADDR 0x100000 // 1024k +#define KERNEL_BOOT_ADDR KERNEL_ADDR // load at 1Mb #define ptov(paddr) ((paddr) - MEMBASE) #define vtop(vaddr) ((vaddr) + MEMBASE) @@ -77,7 +66,9 @@ * Limits to the size of various things... */ -/* We need a minimum of 12Mb of system memory. */ -#define MIN_SYS_MEM_KB (12 * 1024) +/* + * We need a minimum of 24Mb of system memory. + */ +#define MIN_SYS_MEM_KB (24 * 1024) #endif /* !__BOOT_MEMORY_H */ diff --git a/i386/libsa/zalloc.c b/i386/libsa/zalloc.c index be4b162..932fdec 100644 --- a/i386/libsa/zalloc.c +++ b/i386/libsa/zalloc.c @@ -54,7 +54,7 @@ static void zinsert(zmem * zp, int ndx); static void zdelete(zmem * zp, int ndx); static void zcoalesce(void); -#define ZALLOC_NODES 384 +#define ZALLOC_NODES 1024 static void malloc_error() { diff --git a/i386/libsaio/biosfn.c b/i386/libsaio/biosfn.c index 41b11d7..ff0d3a3 100644 --- a/i386/libsaio/biosfn.c +++ b/i386/libsaio/biosfn.c @@ -81,16 +81,29 @@ unsigned int time18(void) int memsize(int which) { - if (which) { - get_memsize(&bb); - return (bb.edx.rr << 16) | bb.eax.rr; + int size; + + if ( which ) + { + // Get the total system memory discovered by the + // BIOS in kilobytes. + + get_memsize(&bb); + size = (bb.edx.rr << 16) | bb.eax.rr; + + // Convert to extended memory size. + + size = ( size > 1024 ) ? size - 1024 : 0; } - else { - /* conventional memory */ + else + { + // Get amount of conventional memory available. + bb.intno = 0x12; bios(&bb); - return bb.eax.rr; + size = bb.eax.rr; } + return size; } void video_mode(int mode) @@ -298,9 +311,9 @@ APMPresent(void) (bb.ebx.r.h == 'P') && (bb.ebx.r.l == 'M')) { /* Success */ - kbp->apm_config.major_vers = bb.eax.r.h; - kbp->apm_config.minor_vers = bb.eax.r.l; - kbp->apm_config.flags.data = bb.ecx.rr; + kbp->apmConfig.major_vers = bb.eax.r.h; + kbp->apmConfig.minor_vers = bb.eax.r.l; + kbp->apmConfig.flags.data = bb.ecx.rr; return 1; } return 0; @@ -318,19 +331,19 @@ APMConnect32(void) bios(&bb); if (bb.flags.cf == 0) { /* Success */ - kbp->apm_config.cs32_base = (bb.eax.rr) << 4; - kbp->apm_config.entry_offset = bb.ebx.rx; - kbp->apm_config.cs16_base = (bb.ecx.rr) << 4; - kbp->apm_config.ds_base = (bb.edx.rr) << 4; - if (kbp->apm_config.major_vers >= 1 && - kbp->apm_config.minor_vers >= 1) { - kbp->apm_config.cs_length = bb.esi.rr; - kbp->apm_config.ds_length = bb.edi.rr; + kbp->apmConfig.cs32_base = (bb.eax.rr) << 4; + kbp->apmConfig.entry_offset = bb.ebx.rx; + kbp->apmConfig.cs16_base = (bb.ecx.rr) << 4; + kbp->apmConfig.ds_base = (bb.edx.rr) << 4; + if (kbp->apmConfig.major_vers >= 1 && + kbp->apmConfig.minor_vers >= 1) { + kbp->apmConfig.cs_length = bb.esi.rr; + kbp->apmConfig.ds_length = bb.edi.rr; } else { - kbp->apm_config.cs_length = - kbp->apm_config.ds_length = 64 * 1024; + kbp->apmConfig.cs_length = + kbp->apmConfig.ds_length = 64 * 1024; } - kbp->apm_config.connected = 1; + kbp->apmConfig.connected = 1; return 1; } return 0; diff --git a/i386/libsaio/console.c b/i386/libsaio/console.c index 1b1103c..53de5a0 100644 --- a/i386/libsaio/console.c +++ b/i386/libsaio/console.c @@ -46,7 +46,7 @@ #include "libsaio.h" -BOOL verbose_mode; +BOOL gVerboseMode; BOOL errors; /* @@ -105,7 +105,7 @@ int verbose(const char * fmt, ...) { va_list ap; - if (verbose_mode) + if (gVerboseMode) { va_start(ap, fmt); prf(fmt, ap, putchar, 0); diff --git a/i386/libsaio/drivers.h b/i386/libsaio/drivers.h deleted file mode 100644 index 0c3c204..0000000 --- a/i386/libsaio/drivers.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 1999 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 - * 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. - * - * 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 OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ -/* - * Copyright 1994 NeXT Computer, Inc. - * All rights reserved. - */ - -#ifndef __LIBSAIO_DRIVERS_H -#define __LIBSAIO_DRIVERS_H - -struct driver_info { - char *name; - char *bundle; - char *version; - char *configTable; - char *tableName; - char *locationTag; - int flags; -}; - -#define DRIVER_FLAG_NONE 0x00 -#define DRIVER_FLAG_INTERESTING 0x01 -#define DRIVER_FLAG_CONFIG_ADDED 0x02 - -#define DRIVER_NOT_FOUND 0x0 -#define DRIVER_VERSION_MISMATCH 0x1 - -extern int driverMissing; - -#endif /* !__LIBSAIO_DRIVERS_H */ diff --git a/i386/libsaio/load.c b/i386/libsaio/load.c index f12f7f8..ef39734 100644 --- a/i386/libsaio/load.c +++ b/i386/libsaio/load.c @@ -96,9 +96,6 @@ read_again: if ( head.magic == MH_MAGIC ) { -#if 0 - printf("oneway fat binary found\n"); sleep(1); -#endif 1 return loadmacho(&head, dev, fd, entry, addr, size, file_offset); } else if ( file_offset == 0 && @@ -204,32 +201,33 @@ int xread( int fd, // loadmacho int -loadmacho( - struct mach_header * head, - int dev, - int io, - entry_t * rentry, - char ** raddr, - int * rsize, - int file_offset -) +loadmacho( struct mach_header * head, + int dev, + int io, + entry_t * rentry, + char ** raddr, + int * rsize, + int file_offset ) { - int ncmds; - unsigned cmds, cp; + int ncmds; + void * cmds; + void * cp; + unsigned int entry = 0; + int vmsize = 0; + unsigned int vmaddr = ~0; + unsigned int vmend = 0; + struct xxx_thread_command { unsigned long cmd; unsigned long cmdsize; unsigned long flavor; unsigned long count; i386_thread_state_t state; - } *th; - unsigned int entry = 0; - int vmsize = 0; - unsigned int vmaddr = ~0; + } * th; // XXX should check cputype - cmds = (unsigned int) malloc(head->sizeofcmds); - b_lseek(io, sizeof (struct mach_header) + file_offset, 0); + cmds = malloc(head->sizeofcmds); + b_lseek(io, sizeof(struct mach_header) + file_offset, 0); if ( read(io, (char *) cmds, head->sizeofcmds) != head->sizeofcmds ) { @@ -249,33 +247,23 @@ loadmacho( case LC_SEGMENT: addr = (scp->vmaddr & 0x3fffffff) + (int)*raddr; if ( scp->filesize ) - { - // Is this an OK assumption? - // if the filesize is zero, it doesn't - // take up any virtual space... - // (Hopefully this only excludes PAGEZERO.) - // Also, ignore linkedit segment when - // computing size, because we will erase - // the linkedit segment later. - - if ( strncmp(scp->segname, SEG_LINKEDIT, - sizeof(scp->segname)) != 0) - vmsize += scp->vmsize; - - vmaddr = min(vmaddr, addr); + { + vmsize += scp->vmsize; + vmaddr = min(vmaddr, addr); + vmend = max(vmend, addr + scp->vmsize); // Zero any space at the end of the segment. + bzero((char *)(addr + scp->filesize), - scp->vmsize - scp->filesize); + scp->vmsize - scp->filesize); // FIXME: check to see if we overflow // the available space (should be passed in // as the size argument). #if 0 - printf("LC_SEGMENT\n"); - printf("LS;file_off %x; fos %x; fsize %x ; addr %x \n", - scp->fileoff, file_offset,scp->filesize, addr); + printf("LC: fileoff %x, filesize %x, off %x, addr %x\n", + scp->fileoff, scp->filesize, file_offset, addr); sleep(1); #endif @@ -300,20 +288,15 @@ loadmacho( kernBootStruct->rootdev = (dev & 0xffffff00) | devMajor[Dev(dev)]; - free((char *) cmds); + free(cmds); + *rentry = (entry_t)( (int) entry & 0x3fffffff ); - *rsize = vmsize; + *rsize = vmend - vmaddr; *raddr = (char *)vmaddr; -#if 0 - printf("suceesful load;vmaddr=%x; vmsize=%x;entry=%x\n", vmaddr, vmsize,entry); - sleep(5); -#endif - return 0; shread: - free((char *) cmds); - error("loadmacho: read error\n"); + free(cmds); return -1; } diff --git a/i386/libsaio/saio_internal.h b/i386/libsaio/saio_internal.h index bf9acbe..16968b4 100644 --- a/i386/libsaio/saio_internal.h +++ b/i386/libsaio/saio_internal.h @@ -59,7 +59,7 @@ extern void setCursorPosition(int x, int y); extern void initKernBootStruct(void); /* console.c */ -extern BOOL verbose_mode; +extern BOOL gVerboseMode; extern void putchar(int ch); extern int getchar(void); extern int printf(const char *format, ...); diff --git a/i386/libsaio/stringTable.c b/i386/libsaio/stringTable.c index 322832c..8fafe9b 100644 --- a/i386/libsaio/stringTable.c +++ b/i386/libsaio/stringTable.c @@ -29,7 +29,6 @@ #include "libsaio.h" #include "kernBootStruct.h" #include "stringConstants.h" -#include "drivers.h" #include "legacy/configTablePrivate.h" extern KERNBOOTSTRUCT *kernBootStruct; diff --git a/i386/libsaio/sys.c b/i386/libsaio/sys.c index dbfe96b..e8b75b4 100644 --- a/i386/libsaio/sys.c +++ b/i386/libsaio/sys.c @@ -69,10 +69,6 @@ char * gFilename; -#ifdef DISABLED -static char * deviceDirectory; -#endif - extern int ram_debug_sarld; // in load.c #define DCACHE 1 @@ -448,7 +444,6 @@ sbmap(struct iob * io, daddr_t bn) return (nb); } -#ifdef DISABLED /*========================================================================== * * @@ -490,7 +485,6 @@ disk_closedir(struct dirstuff * dirp) free((void *)dirp); return 0; } -#endif /* DISABLED */ /*========================================================================== * get next entry in a directory. @@ -894,13 +888,8 @@ disk_flushdev() #if DCACHE cacheFlush(dcache); #endif - -#ifdef DISABLED - deviceDirectory = NULL; -#endif /* DISABLED */ } - /*************************************************************************** * * Network functions. @@ -945,7 +934,6 @@ en_devopen(char * name, struct iob * io) io->i_error = 0; } - /*************************************************************************** * * Dispatch functions. @@ -1021,8 +1009,7 @@ gen_usrDevices() struct dirstuff * opendir(char * path) { - error("Unsupported function: opendir\n"); - return 0; + return disk_opendir(path); } /*========================================================================== @@ -1031,8 +1018,7 @@ opendir(char * path) int closedir(struct dirstuff * dirp) { - error("Unsupported function: closedir\n"); - return 0; + return disk_closedir(dirp); } /*========================================================================== @@ -1041,8 +1027,7 @@ closedir(struct dirstuff * dirp) struct direct * readdir(struct dirstuff * dirp) { - error("Unsupported function: readdir\n"); - return NULL; + return disk_readdir(dirp); } /*========================================================================== @@ -1129,6 +1114,7 @@ open(char * str, int how) #if CHECK_CAREFULLY /* iob[] is in BSS, so it is guaranteed to be zero. */ if (open_init == 0) { + int i; for (i = 0; i < NFILES; i++) iob[i].i_flgs = 0; open_init = 1; diff --git a/i386/rcz/rcz_decompress_file.c b/i386/rcz/rcz_decompress_file.c index 4d48b8c..d47abbd 100644 --- a/i386/rcz/rcz_decompress_file.c +++ b/i386/rcz/rcz_decompress_file.c @@ -31,13 +31,15 @@ */ -#import "rcz_common.h" -#import "unistd.h" +#include "rcz_common.h" +#include +#include static unsigned short que[QLEN]; #define REWIND -1 // extern int read(int fd, char *buf, int len); +extern int b_lseek(int fdesc, unsigned int addr, int ptr); static unsigned char *buf; static int buf_count; @@ -115,7 +117,7 @@ rcz_decompress_file( { unsigned int c, j, k, jmatch, jabove; int length; - unsigned int even_length, word, token, version; + unsigned int even_length, word, token; unsigned char *outorigin = out; length = rcz_file_size(in_fd); diff --git a/i386/util/machOconv.c b/i386/util/machOconv.c index 88464e3..78aac62 100644 --- a/i386/util/machOconv.c +++ b/i386/util/machOconv.c @@ -22,16 +22,18 @@ * @APPLE_LICENSE_HEADER_END@ */ #include - +#include #include +#include #include #include #include +#include int infile, outfile; struct mach_header mh; -unsigned cmds; +void * cmds; boolean_t swap_ends; @@ -45,14 +47,13 @@ static unsigned long swap( return x; } -main(argc, argv) -int argc; -char *argv[]; +int +main(int argc, char *argv[]) { kern_return_t result; vm_address_t data; int nc, ncmds; - unsigned cp; + char * cp; if (argc == 2) { infile = open(argv[1], O_RDONLY); @@ -88,7 +89,7 @@ usage: else if (mh.magic == MH_CIGAM) swap_ends = TRUE; else { - fprintf(stderr, "bad magic number %x\n", mh.magic); + fprintf(stderr, "bad magic number %lx\n", mh.magic); exit(1); } @@ -129,7 +130,7 @@ usage: } lseek(infile, swap(scp->fileoff), L_SET); - nc = read(infile, data, swap(scp->filesize)); + nc = read(infile, (void *)data, swap(scp->filesize)); if (nc < 0) { perror("read segment data"); exit(1); @@ -139,7 +140,7 @@ usage: exit(1); } - nc = write(outfile, data, vmsize); + nc = write(outfile, (void *)data, vmsize); if (nc < vmsize) { perror("write segment data"); exit(1); -- 2.45.2