Index: branches/xZen/Make.rules =================================================================== --- branches/xZen/Make.rules (revision 1266) +++ branches/xZen/Make.rules (revision 1267) @@ -44,9 +44,6 @@ @cd ${SRCROOT} && $(SYMROOT)/cconfig $(SRCROOT)/Cconfig rebuild -.PHONY: config -.PHONY: rebuild_config -.PHONY: $(SRCROOT)/auto.conf $(SYMROOT)/vers.h: @echo "#define BOOT_VERSION \"5.0.132\"" > $@ @@ -68,8 +65,10 @@ $(SRCROOT)/autoconf.h \ $(SRCROOT)/autoconf.inc + $(SRCROOT)/auto.conf $(SRCROOT)/autoconf.h $(SRCROOT)/autoconf.inc $(SRCROOT)/.config: rebuild_cofig +.PHONY: $(SRCROOT)/autoconf.h .PHONY: rebuild_config .PHONY: config .PHONY: clean Index: branches/xZen/src/modules/MakeInc.dir =================================================================== --- branches/xZen/src/modules/MakeInc.dir (revision 1266) +++ branches/xZen/src/modules/MakeInc.dir (revision 1267) @@ -12,12 +12,12 @@ ifeq ($(BUILT_IN),yes) -CFLAGS := $(RC_CFLAGS) $(OPTIM) $(MORECPP) -g -Wmost -Werror \ +CFLAGS := $(RC_CFLAGS) $(OPTIM) $(MORECPP) -static -g -Wmost -Werror \ -fno-builtin -DSAIO_INTERNAL_USER $(OMIT_FRAME_POINTER_CFLAG) \ -fno-align-functions -fno-stack-protector \ -msoft-float -nostdinc -include $(SRCROOT)/autoconf.h -CPPFLAGS := $(CPPFLAGS) -nostdinc++ -Wmost -Werror \ +CPPFLAGS := $(CPPFLAGS) -static -nostdinc++ -Wmost -Werror \ -fno-builtin -msoft-float \ -fno-rtti -fno-exceptions \ -include $(SRCROOT)/autoconf.h @@ -59,10 +59,9 @@ MODULE_DEPENDENCIES_CMD := $(foreach x,$(MODULE_DEPENDENCIES), -weak_library $(x)) -INSTALLDIR = $(DSTROOT)/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/standalone - MODULE_DEFINITION := $(CONFIG_$(shell echo $(MODULE_NAME) | tr '[:lower:]' '[:upper:]')_MODULE) + ifeq ($(MODULE_DEFINITION),m) ifneq ($(BUILT_IN),yes) Index: branches/xZen/src/modules/Makefile =================================================================== --- branches/xZen/src/modules/Makefile (revision 1266) +++ branches/xZen/src/modules/Makefile (revision 1267) @@ -9,7 +9,7 @@ include ${ROOT}/Make.rules # The order of building is important. -SUBDIRS = klibc uClibcxx HelloWorld Disk FileSystem +SUBDIRS = klibc uClibcxx Disk FileSystem # ModuleSystem CFLAGS= -O3 $(MORECPP) -g -static Index: branches/xZen/src/Makefile =================================================================== --- branches/xZen/src/Makefile (revision 1266) +++ branches/xZen/src/Makefile (revision 1267) @@ -14,8 +14,8 @@ @for i in ${SUBDIRS}; \ do \ echo ================= make $@ for $$i arch $(ARCH) =================; \ - ( ROOT=$(ROOT); \ - cd $$i; ${MAKE} ARCH=${ARCH} \ + ( \ + cd $$i; ${MAKE} ARCH=${ARCH} \ $@ \ ) || exit $$?; \ done Index: branches/xZen/src/arch/i386/libsaio/load.c =================================================================== --- branches/xZen/src/arch/i386/libsaio/load.c (revision 1266) +++ branches/xZen/src/arch/i386/libsaio/load.c (revision 1267) @@ -32,12 +32,6 @@ #include -static long DecodeSegment(long cmdBase, unsigned int*load_addr, unsigned int *load_size); -static long DecodeUnixThread(long cmdBase, unsigned int *entry); -static long DecodeSymbolTable(long cmdBase); - - -static unsigned long gBinaryAddress; bool gHaveKernelCache; /* XXX aserebln: uninitialized? and only set to true, never to false */ cpu_type_t archCpuType=CPU_TYPE_I386; Index: branches/xZen/src/arch/i386/libsaio/Makefile =================================================================== --- branches/xZen/src/arch/i386/libsaio/Makefile (revision 1266) +++ branches/xZen/src/arch/i386/libsaio/Makefile (revision 1267) @@ -10,9 +10,20 @@ LIBSADIR = ../libsa BOOT2DIR = ../boot2 +CFLAGS := $(RC_CFLAGS) $(OPTIM) $(MORECPP) -static -g -Wmost -Werror \ + -fno-builtin -DSAIO_INTERNAL_USER $(OMIT_FRAME_POINTER_CFLAG) \ + -fno-align-functions -fno-stack-protector \ + -msoft-float -nostdinc -include $(SRCROOT)/autoconf.h + +CPPFLAGS := $(CPPFLAGS) -static -nostdinc++ -Wmost -Werror \ + -fno-builtin -msoft-float \ + -fno-rtti -fno-exceptions \ + -include $(SRCROOT)/autoconf.h + + DEFINES = -DNOTHING -INC = -I. -I$(SYMROOT) -I$(LIBSADIR) -I$(BOOT2DIR) -I${SRCROOT}/i386/include +INC = -I. -I$(SYMROOT) -I$(LIBSADIR) -I$(BOOT2DIR) -I${SRCROOT}/include OBJECTS = table asm bios biosfn \ misc xml load console Index: branches/xZen/src/arch/i386/boot2/mboot.c =================================================================== --- branches/xZen/src/arch/i386/boot2/mboot.c (revision 1266) +++ branches/xZen/src/arch/i386/boot2/mboot.c (revision 1267) @@ -1,453 +0,0 @@ -/* - File added by David F. Elliott on 2007/06/26 -*/ - -#include "libsaio.h" -#include "boot.h" - -#include "mboot.h" - -int multiboot_timeout=0; -int multiboot_timeout_set=0; -int multiboot_partition=0; -int multiboot_partition_set=0; - -// Global multiboot info, if using multiboot. -struct multiboot_info *gMI; - -extern void continue_at_low_address(void); - -// prototype hi_multiboot and keep its implementation below multiboot_to_boot -// to ensure that it doesn't get inlined by the compiler -// We don't want it inlined because we specifically want the stack frame -// pointer to be as high as possible and the hi_multiboot function -// copies multiboot_info onto its stack. -uint32_t hi_multiboot(int multiboot_magic, struct multiboot_info *mi_orig); -// prototype dochainload for the same reason. -void dochainload(); - -#define OFFSET_1MEG 0x100000 -#define BAD_BOOT_DEVICE 0xffffffff - -// This assumes that the address of the first argument to the function will -// be exactly 4 bytes above the address of the return address. -// It is intended to be used as an lvalue with a statement like this -= OFFSET_1MEG; -#define RETURN_ADDRESS_USING_FIRST_ARG(arg) \ - (*(uint32_t*)((char*)&(arg) - 4)) - -#define FIX_RETURN_ADDRESS_USING_FIRST_ARG(arg) \ - RETURN_ADDRESS_USING_FIRST_ARG(arg) -= OFFSET_1MEG - -extern void jump_to_chainbooter(); -extern unsigned char chainbootdev; -extern unsigned char chainbootflag; - -void chainLoad(); -void waitThenReload(); - -/* - int multibootRamdiskReadBytes( int biosdev, unsigned int blkno, - unsigned int byteoff, - unsigned int byteCount, void * buffer ); -int multiboot_get_ramdisk_info(int biosdev, struct driveInfo *dip); -static long multiboot_LoadExtraDrivers(FileLoadDrivers_t FileLoadDrivers_p); -*/ - -// Starts off in the multiboot context 1 MB high but eventually gets into low memory -// and winds up with a bootdevice in eax which is all that boot() wants -// This lets the stack pointer remain very high. -// If we were to call boot directly from multiboot then the whole multiboot_info -// would be on the stack which would possibly be using way too much stack. -void multiboot_to_boot(int multiboot_magic, struct multiboot_info *mi_orig) -{ - uint32_t bootdevice = hi_multiboot(multiboot_magic, mi_orig); - if(bootdevice != BAD_BOOT_DEVICE) - { - // boot only returns to do a chain load. - for(;;) - { // NOTE: boot only uses the last byte (the drive number) - common_boot(bootdevice); - if(chainbootflag) - chainLoad(); - else - waitThenReload(); - } - } - // Avoid returning to high-memory address which isn't valid in the segment - // we are now in. - // Calling sleep() ensures the user ought to be able to use Ctrl+Alt+Del - // because the BIOS will have interrupts on. - for(;;) - sleep(10); - // NOTE: *IF* we needed to return we'd have to fix up our return address to - // be in low memory using the same trick as below. - // However, there doesn't seem to be any point in returning to assembly - // particularly when the remaining code merely halts the processor. -} - -void chainLoad() -{ - /* TODO: We ought to load the appropriate partition table, for example - the MBR if booting a primary partition or the particular extended - partition table if booting a logical drive. For example, the - regular MS MBR booter will relocate itself (e.g. the MBR) from - 0:7C00 to 0:0600 and will use SI as the offset when reading - the partition data from itself. Thus when it jumps to the partition - boot sector, SI will be 0x600 + 446 + i<<4 where i is the partition - table index. - - On the other hand, our code for the non-Multiboot case doesn't do - this either, although GRUB does. - */ - - const unsigned char *bootcode = (const unsigned char*)0x7c00; - if(bootcode[0x1fe] == 0x55 && bootcode[0x1ff] == 0xaa) - { - printf("Calling chainbooter\n"); - jump_to_chainbooter(); - /* NORETURN */ - } - else - { - printf("Bad chain boot sector magic: %02x%02x\n", bootcode[0x1fe], bootcode[0x1ff]); - } -} - -void waitThenReload() -{ - /* FIXME: Ctrl+Alt+Del does not work under Boot Camp */ - printf("Darwin booter exited for some reason.\n"); - printf("Please reboot (Ctrl+Alt+Del) your machine.\n"); - printf("Restarting Darwin booter in 5 seconds..."); - sleep(1); - printf("4..."); - sleep(1); - printf("3..."); - sleep(1); - printf("2..."); - sleep(1); - printf("1..."); - sleep(1); - printf("0\n"); -} - -// Declare boot2_sym as an opaque struct so it can't be converted to a pointer -// i.e. ensure the idiot programmer (me) makes sure to use address-of -// Technically it's a function but it's real mode code and we sure don't -// want to call it under any circumstances. -extern struct {} boot2_sym asm("boot2"); - -// prototype multiboot and keep its implementation below hi_multiboot to -// ensure that it doesn't get inlined by the compiler -static inline uint32_t multiboot(int multiboot_magic, struct multiboot_info *mi); - - -/*! - Returns a pointer to the first safe address we can use for stowing the multiboot info. - This might actually be a bit pedantic because mboot.c32 and GRUB both stow the multiboot - info in low memory meaning that the >= 128 MB location we choose is plenty high enough. - */ -void *determine_safe_hi_addr(int multiboot_magic, struct multiboot_info *mi_orig) -{ - // hi_addr must be at least up in 128MB+ space so it doesn't get clobbered - void *hi_addr = (void*)PREBOOT_DATA; - - // Fail if the magic isn't correct. We'll complain later. - if(multiboot_magic != MULTIBOOT_INFO_MAGIC) - return NULL; - // Make sure the command-line isn't in high memory. - if(mi_orig->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) - { - char *end = mi_orig->mi_cmdline; - if(end != NULL) - { - for(; *end != '\0'; ++end) - ; - ++end; - if( (void*)end > hi_addr) - hi_addr = end; - } - } - // Make sure the module information isn't in high memory - if(mi_orig->mi_flags & MULTIBOOT_INFO_HAS_MODS) - { - struct multiboot_module *modules = (void*)mi_orig->mi_mods_addr; - int i; - for(i=0; i < mi_orig->mi_mods_count; ++i) - { - // make sure the multiboot_module struct itself won't get clobbered - void *modinfo_end = modules+i+1; - if(modinfo_end > hi_addr) - hi_addr = modinfo_end; - // make sure the module itself won't get clobbered - modinfo_end = (void*)modules[i].mm_mod_end; - if(modinfo_end > hi_addr) - hi_addr = modinfo_end; - // make sure the module string doesn't get clobbered - char *end = modules[i].mm_string; - for(; *end != '\0'; ++end) - ; - ++end; - modinfo_end = end; - if(modinfo_end > hi_addr) - hi_addr = modinfo_end; - } - } - // TODO: Copy syms (never needed), mmap, drives, config table, loader name, apm table, VBE info - - // Round up to page size - hi_addr = (void*)(((uint32_t)hi_addr + 0xfff) & ~(uint32_t)0xfff); - return hi_addr; -} - -/*! - Like malloc but with a preceding input/output parameter which points to the next available - location for data. The original value of *hi_addr is returned and *hi_addr is incremented - by size bytes. - */ -void * _hi_malloc(void **hi_addr, size_t size) -{ - void *ret = *hi_addr; - *hi_addr += size; - return ret; -} - -/*! - Like strdup but with a preceding input/output parameter. The original value of *hi_addr is - returned and *hi_addr is incremented by the number of bytes necessary to complete the string - copy including its NUL terminator. - */ -char * _hi_strdup(void **hi_addr, char *src) -{ - char *dstStart; - char *dst = dstStart = *hi_addr; - for(; *src != '\0'; ++src, ++dst, ++(*hi_addr)) - *dst = *src; - *dst = '\0'; - ++(*hi_addr); - return dstStart; -} - -// Convenience macros -#define hi_malloc(size) _hi_malloc(&hi_addr, (size)) -#define hi_strdup(src) _hi_strdup(&hi_addr, (src)) - -/*! - Copies the Multiboot info and any associated data (e.g. various strings and any multiboot modules) - up to very high RAM (above 128 MB) to ensure it doesn't get clobbered by the booter. - */ -struct multiboot_info * copyMultibootInfo(int multiboot_magic, struct multiboot_info *mi_orig) -{ - void *hi_addr = determine_safe_hi_addr(multiboot_magic, mi_orig); - if(hi_addr == NULL) - return NULL; - - struct multiboot_info *mi_copy = hi_malloc(sizeof(*mi_copy)); - memcpy(mi_copy, mi_orig, sizeof(*mi_copy)); - - // Copy the command line - if(mi_orig->mi_flags & MULTIBOOT_INFO_HAS_CMDLINE) - { - mi_copy->mi_cmdline = hi_strdup(mi_orig->mi_cmdline); - } - // Copy the loader name - if(mi_orig->mi_flags & MULTIBOOT_INFO_HAS_LOADER_NAME) - { - mi_copy->mi_loader_name = hi_strdup(mi_orig->mi_loader_name); - } - // Copy the module info - if(mi_orig->mi_flags & MULTIBOOT_INFO_HAS_MODS) - { - struct multiboot_module *dst_modules = hi_malloc(sizeof(*dst_modules)*mi_orig->mi_mods_count); - struct multiboot_module *src_modules = (void*)mi_orig->mi_mods_addr; - mi_copy->mi_mods_addr = (uint32_t)dst_modules; - - // Copy all of the module info plus the actual module into high memory - int i; - for(i=0; i < mi_orig->mi_mods_count; ++i) - { - // Assume mod_end is 1 past the actual end (i.e. it is start + size, not really end (i.e. start + size - 1)) - // This is what GRUB and mboot.c32 do although the spec is unclear on this. - uint32_t mod_length = src_modules[i].mm_mod_end - src_modules[i].mm_mod_start; - - dst_modules[i].mm_mod_start = (uint32_t)hi_malloc(mod_length); - dst_modules[i].mm_mod_end = (uint32_t)dst_modules[i].mm_mod_start + mod_length; - memcpy((char*)dst_modules[i].mm_mod_start, (char*)src_modules[i].mm_mod_start, mod_length); - - dst_modules[i].mm_string = hi_strdup(src_modules[i].mm_string); - dst_modules[i].mm_reserved = src_modules[i].mm_reserved; - } - } - // Make sure that only stuff that didn't need to be copied or that we did deep copy is indicated in the copied struct. - mi_copy->mi_flags &= MULTIBOOT_INFO_HAS_MEMORY | MULTIBOOT_INFO_HAS_BOOT_DEVICE | MULTIBOOT_INFO_HAS_CMDLINE | MULTIBOOT_INFO_HAS_LOADER_NAME | MULTIBOOT_INFO_HAS_MODS; - - return mi_copy; -} - -// When we enter, we're actually 1 MB high. -// Fortunately, memcpy is position independent, and it's all we need -uint32_t hi_multiboot(int multiboot_magic, struct multiboot_info *mi_orig) -{ - // Copy the multiboot info out of the way. - // We can't bitch about the magic yet because printf won't work - // because it contains an absolute location of putchar which - // contains absolute locations to other things which eventually - // makes a BIOS call from real mode which of course won't work - // because we're stuck in extended memory at this point. - struct multiboot_info *mi_p = copyMultibootInfo(multiboot_magic, mi_orig); - - // Get us in to low memory so we can run everything - - // We cannot possibly be more than 447k and copying extra won't really hurt anything - // We use the address of the assembly entrypoint to get our starting location. - memcpy(&boot2_sym, (char*)&boot2_sym + OFFSET_1MEG, BOOT2_MAX_LENGTH /* 447k */); - - // This is a little assembler routine that returns to us in the correct selector - // instead of the kernel selector we're running in now and at the correct - // instruction pointer ( current minus 1 MB ). It does not fix our return - // address nor does it fix the return address of our caller. - continue_at_low_address(); - - // Now fix our return address. - FIX_RETURN_ADDRESS_USING_FIRST_ARG(multiboot_magic); - - // We can now do just about anything, including return to our caller correctly. - // However, our caller must fix his return address if he wishes to return to - // his caller and so on and so forth. - - /* Zero the BSS and initialize malloc */ - initialize_runtime(); - - gMI = mi_p; - - /* Set up a temporary bootArgs so we can call console output routines - like printf that check the v_display. Note that we purposefully - do not initialize anything else at this early stage. - - We are reasonably sure we're already in text mode if GRUB booted us. - This is the same assumption that initKernBootStruct makes. - We could check the multiboot info I guess, but why bother? - */ - boot_args temporaryBootArgsData; - bzero(&temporaryBootArgsData, sizeof(boot_args)); -// bootArgs = &temporaryBootArgsData; - // bootArgs->Video.v_display = VGA_TEXT_MODE; - - // Install ramdisk and extra driver hooks - //p_get_ramdisk_info = &multiboot_get_ramdisk_info; - //p_ramdiskReadBytes = &multibootRamdiskReadBytes; - //LoadExtraDrivers_p = &multiboot_LoadExtraDrivers; - - // Since we call multiboot ourselves, its return address will be correct. - // That is unless it's inlined in which case it does not matter. - uint32_t bootdevice = multiboot(multiboot_magic, mi_p); - // We're about to exit and temporaryBootArgs will no longer be valid - //bootArgs = NULL; - return bootdevice; -} - -// This is the meat of our implementation. It grabs the boot device from -// the multiboot_info and returns it as is. If it fails it returns -// BAD_BOOT_DEVICE. We can call an awful lot of libsa and libsaio but -// we need to take care not to call anything that requires malloc because -// it won't be initialized until boot() does it. -static inline uint32_t multiboot(int multiboot_magic, struct multiboot_info *mi) -{ - if(multiboot_magic != MULTIBOOT_INFO_MAGIC) - { - printf("Wrong Multiboot magic\n"); - sleep(2); - return BAD_BOOT_DEVICE; - } - printf("Multiboot info @0x%x\n", (uint32_t)mi); - if(mi->mi_flags & MULTIBOOT_INFO_HAS_LOADER_NAME) - printf("Loaded by %s\n", mi->mi_loader_name); - - // Multiboot puts boot device in high byte - // Normal booter wants it in low byte - int bootdevice = mi->mi_boot_device_drive; - - bool doSelectDevice = false; - if(mi->mi_flags & MULTIBOOT_INFO_HAS_BOOT_DEVICE) - { - printf("Boot device 0x%x\n", bootdevice); - } - else - { - printf("Multiboot info does not include chosen boot device\n"); - doSelectDevice = true; - bootdevice = BAD_BOOT_DEVICE; - } - - if(bootdevice == BAD_BOOT_DEVICE) - sleep(2); // pause for a second before halting - return bootdevice; -} - -/////////////////////////////////////////////////////////////////////////// -// Ramdisk and extra drivers code -#if 0 -int multibootRamdiskReadBytes( int biosdev, unsigned int blkno, - unsigned int byteoff, - unsigned int byteCount, void * buffer ) -{ - int module_count = gMI->mi_mods_count; - struct multiboot_module *modules = (void*)gMI->mi_mods_addr; - if(biosdev < 0x100) - return -1; - if(biosdev >= (0x100 + module_count)) - return -1; - struct multiboot_module *module = modules + (biosdev - 0x100); - - void *p_initrd = (void*)module->mm_mod_start; - bcopy(p_initrd + blkno*512 + byteoff, buffer, byteCount); - return 0; -} - -int multiboot_get_ramdisk_info(int biosdev, struct driveInfo *dip) -{ - int module_count = gMI->mi_mods_count; - struct multiboot_module *modules = (void*)gMI->mi_mods_addr; - if(biosdev < 0x100) - return -1; - if(biosdev >= (0x100 + module_count)) - return -1; - struct multiboot_module *module = modules + (biosdev - 0x100); - dip->biosdev = biosdev; - dip->uses_ebios = true; // XXX aserebln uses_ebios isn't a boolean at all - dip->di.params.phys_sectors = (module->mm_mod_end - module->mm_mod_start + 511) / 512; - dip->valid = true; - return 0; -} -static long multiboot_LoadExtraDrivers(FileLoadDrivers_t FileLoadDrivers_p) -{ - char extensionsSpec[1024]; - int ramdiskUnit; - for(ramdiskUnit = 0; ramdiskUnit < gMI->mi_mods_count; ++ramdiskUnit) - { - int partCount; // unused - BVRef ramdiskChain = diskScanBootVolumes(0x100 + ramdiskUnit, &partCount); - if(ramdiskChain == NULL) - { - verbose("Ramdisk contains no partitions\n"); - continue; - } - for(; ramdiskChain != NULL; ramdiskChain = ramdiskChain->next) - { - sprintf(extensionsSpec, "rd(%d,%d)/Extra/", ramdiskUnit, ramdiskChain->part_no); - struct dirstuff *extradir = opendir(extensionsSpec); - closedir(extradir); - if(extradir != NULL) - { - int ret = FileLoadDrivers_p(extensionsSpec, 0 /* this is a kext root dir, not a kext with plugins */); - if(ret != 0) - { - verbose("FileLoadDrivers failed on a ramdisk\n"); - return ret; - } - } - } - } - return 0; -} -#endif \ No newline at end of file Index: branches/xZen/src/arch/i386/boot2/mboot.h =================================================================== --- branches/xZen/src/arch/i386/boot2/mboot.h (revision 1266) +++ branches/xZen/src/arch/i386/boot2/mboot.h (revision 1267) @@ -1,21 +0,0 @@ -/* File added by David F. Elliott on 2007/06/27 */ -#include "multiboot.h" - -/* -The following DWORD tells the loader what features we require of it. -bit 0 set: Align modules on 4KB. We have no modules, we may not need this. -bit 1 set: Provide info about memory. We probably don't need this either -bit 2 : We might want this. If so we need to tell the loader to stick - us in text mode. We currently assume that the loader will put - us in text mode if we lack this because that is what GRUB does. -bit 16 set: This is not ELF, use the multiboot_header fields. - We definitely need this flag. -*/ -/* #define MULTIBOOT_HEADER_FLAGS 0x00010003 */ - -#define MULTIBOOT_HEADER_FLAGS \ - (MULTIBOOT_HEADER_HAS_ADDR|MULTIBOOT_HEADER_WANT_MEMORY|MULTIBOOT_HEADER_MODS_ALIGNED) - -#ifndef __ASSEMBLER__ -/* Put any desired prototypes or other C stuff here. */ -#endif Index: branches/xZen/src/arch/i386/boot2/boot.c =================================================================== --- branches/xZen/src/arch/i386/boot2/boot.c (revision 1266) +++ branches/xZen/src/arch/i386/boot2/boot.c (revision 1267) @@ -51,43 +51,16 @@ #include "boot.h" -#include "sl.h" -#include "libsa.h" extern void init_module_system(); extern int execute_hook(const char* name, void*, void*, void*, void*); +extern void bzero(void * dst, size_t len); +extern void stop(const char *format, ...); +extern void enableA20(void); +extern void video_mode(int mode); +extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int)); -long gBootMode; /* defaults to 0 == kBootModeNormal */ -bool gOverrideKernel; -char *gPlatformName; -char gRootDevice[512]; -char gMKextName[512]; -char gMacOSVersion[8]; -bool gEnableCDROMRescan; -bool gScanSingleDrive; - -int bvCount = 0; -int gDeviceCount = 0; - -BVRef bvr; -BVRef menuBVR; -BVRef bvChain; -bool useGUI; - -/* - * How long to wait (in seconds) to load the - * kernel after displaying the "boot:" prompt. - */ -#define kBootErrorTimeout 5 - -/* - * Default path to kernel cache file - */ -//Slice - first one for Leopard -#define kDefaultCachePathLeo "/System/Library/Caches/com.apple.kernelcaches/" -#define kDefaultCachePathSnow "/System/Library/Caches/com.apple.kext.caches/Startup/" - //========================================================================== // Zero the BSS. @@ -118,9 +91,7 @@ } //========================================================================== -// This is the entrypoint from real-mode which functions exactly as it did -// before. Multiboot does its own runtime initialization, does some of its -// own things, and then calls common_boot. +// This is the entrypoint from real. void boot(int biosdev) { initialize_runtime(); @@ -136,10 +107,6 @@ // arguments: // biosdev - Value passed from boot1/NBP to specify the device // that the booter was loaded from. -// -// If biosdev is kBIOSDevNetwork, then this function will return if -// booting was unsuccessful. This allows the PXE firmware to try the -// next boot device on its list. void common_boot(int biosdev) { video_mode( 2 ); // 80x25 mono text mode. @@ -150,6 +117,6 @@ int loopCount = 0; while(1) { - execute_hook("WorkLoop", (void*)loopCount++, NULL, NULL, NULL); // Main work loop + execute_hook("WorkLoop", (void*)loopCount++, 0, 0, 0); // Main work loop } } Index: branches/xZen/src/arch/i386/boot2/boot2.s =================================================================== --- branches/xZen/src/arch/i386/boot2/boot2.s (revision 1266) +++ branches/xZen/src/arch/i386/boot2/boot2.s (revision 1267) @@ -37,8 +37,6 @@ */ #include -#include "memory.h" -#include "mboot.h" #define data32 .byte 0x66 #define retf .byte 0xcb @@ -129,174 +127,7 @@ data32 ljmp $0, $0x7c00 # Jump to boot code already in memory - # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Multiboot support added by David F. Elliott on 2007/06/26 -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# Multiboot section -# The above is used when booting with the normal booter (boot1h/boot1u). -# The following is used when booting with a multiboot capable loader such as grub -# Unlike the normal booter which starts in real mode, we start in protected mode - -# Unforuntately, GRUB refuses to load a multiboot "kernel" below 1MB. -# This is basically due to the fact that GRUB likes to live below 1MB because -# it starts up in real mode just like we would normally be starting up if -# we weren't being Multiboot loaded by GRUB. -# Therefore, we must tell our loader to load us above 1MB. To make it easy, -# we simply specify exactly 1 MB higher than we want. -# This means of course that when we enter we are not where the assembler -# and linker expect us to be. Please remember this when modifying code. -#define OFFSET_1MEG 0x100000 - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# NOTE: While we would ideally place the header in say __TEXT,__const we -# cannot do that and have GRUB find it because GRUB only searches the first -# 8k of the binary. Since __TEXT,__const follows __TEXT,__text (the code -# section) and since the code is well over 8k long, it doesn't work. -.align 2, 0x90 # Make sure we're on a 4-byte boundary. Required by Multiboot. -_multiboot_header: - # magic (NOTE: this shows up as 02b0 ad1b in a hex dump) - .long MULTIBOOT_HEADER_MAGIC - # flags - .long MULTIBOOT_HEADER_FLAGS - # checksum - .long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS) - # header_addr - .long (_multiboot_header + OFFSET_1MEG) - # load_addr - .long (boot2 + OFFSET_1MEG) - # load_end_addr # Tell multiboot to load the whole file - .long 0 - # bss_end_addr # boot() will zero its own bss - .long 0 - # entry_addr - .long (_multiboot_entry + OFFSET_1MEG) - -# Stick a couple of nop here so that we hopefully make disassemblers realize we have instructions again - nop - nop - nop -.align 3, 0x90 # Align to 8 byte boundary which should be enough nops - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -_multiboot_entry: - # First thing's first, let's get ourselves a usable GDT. - # Multiboot specifically says that GDT is not to be considered valid - # because for all we know the loader could have erased the memory where - # the GDT was located. Even if it doesn't, it's very likely that we'll - # clobber it when we move ourselves into low memory. - - # We have a GDT at the _Gdt symbol location which is defined in - # i386/libsaio/table.c. Like all GDTs, entry 0 is unusable. The first - # entry (0x08) is the one normally used by the booter. However, it is - # specifically defined as byte-granularity to ensure the booter does not - # execute any code above 1 MB. As mentioned above, we are above 1 MB so - # we can't use the 0x08 selector. Fortunately, the booter specifies the - # 0x28 selector for the kernel init code using the typical 4K granularity - # and making all 32-bits of address space available. - - # To load a GDT with the lgdt instruction we need to have the linear - # address of a GDTR structure. The 16-bit boot code uses the _Gdtr - # variable which we will use later. However, we are still in extended - # memory so even if we added 1 MB to _Gdtr the contents of it would - # still be pointing in low memory. Therefore we have a _Gdtr_high - # which points to _Gdt + OFFSET_1MEG (see bottom of file) - # Notice that _Gdtr_high itself is located 1 MB above where the - # assembler/linker thinks it is. - lgdt _Gdtr_high + OFFSET_1MEG - - # Now that we have a GDT we want to first reload the CS register. We do - # that using a far jump to the desired selector with the desired offset. - # The desired offset in this case is exactly 1 MB higher than the - # assembler/linker thinks it is. As mentioned above, we use the kernel - # init code selector instead of the boot code selector. - jmp $0x28,$(Lpost_gdt_switch+OFFSET_1MEG) -Lpost_gdt_switch: - - # Now that we have the right code selector we also want the rest of the - # selectors to be correct. We use the same selector (0x10) as the - # __real_to_prot function in libsaio/asm.s. This is important as it - # means we won't need to do this again after the next GDT switch. - - # We have to clobber one register because segment registers can only be - # loaded from GP registers. Fortunately, only eax and ebx are provided - # by multiboot so we can clobber anything else. We choose ecx. - - movl $0x10, %ecx - movl %ecx,%ss - movl %ecx,%ds - movl %ecx,%es - movl %ecx,%fs - movl %ecx,%gs - - # Initialize our stack pointer to the one normally used by the booter - # NOTE: This is somewhat dangerous considering it seems to be a de-facto - # Multiboot standard that the area below 1 MB is for the loader (e.g. GRUB) - # We may consider later putting the stack at + 1MB just like the code - # but we'd have to eventually get it below 1 MB because until we do we can't - # run any real-mode code (e.g. BIOS functions). - # Doing it this early we potentially run the risk that our multiboot_info - # pointer in ebx is already stuck somewhere in our stack segment - # Of course, the best method would be to have a couple of choices for - # stack space and put it wherever the multiboot_info is not. - movl $ADDR32(STACK_SEG,STACK_OFS), %esp - - # Some final notes about machine state: - - # We have no IDT and thus we leave interrupts disabled. This is the same - # state that __real_to_prot leaves the machine in so it's not a problem. - - # The A20 gate is enabled (it better be, we're above 1 MB) - # It is enabled as the first thing in boot() but it won't hurt for it - # to be enabled when it already is. - - # Unlike when booting from real mode, when booting from Multiboot we have - # no stack to begin with. This means that __switch_stack must never be - # called because it is preloaded with STACK_SEG,STACK_OFS which is where - # we already are. Were it to be called it would effectively reset to the - # top of the stack which would not be good. - # We might think about adding a couple of instructions here to change - # its default values to something that could be used if necessary. - - # At this point we're good enough to run C code. I am no assembler guru - # so we won't be returning from it. - pushl %ebx - pushl %eax - call _multiboot_to_boot # NOTE: near relative call, so we stay in high mem - # NORETURN - - # NOTE: Once we get in to C, we should never return - # We let the C code take care of doing a chain boot which right now - # means to print an error message and restart the booter - -Lhltloop: - hlt # This causes Parallels to power off although a normal PC will just hang - jmp Lhltloop - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# _continue_at_low_address does some trickery to get the caller running from the low address with the right selector - .globl _continue_at_low_address - .align 2, 0x90 -_continue_at_low_address: - # Our stack frame has been set up with the return address on top - # First, fix that to be 1 MB lower - subl $OFFSET_1MEG, (%esp) - # Now load the proper low-memory GDTR from the low-memory location which - # will cause the low-memory GDT to be used. - lgdt _Gdtr - # Now jump to GDT selector 8 using the low address of this function - # This finally puts us in low memory in the right selector (0x08) - jmpl $0x08,$L_continue_at_low_address_next -L_continue_at_low_address_next: - # We don't need to set ss,ds,es,fs, or gs because they are already 0x10 - # and the old GDT had the same information for selector 0x10 as the new - # one does. - # Since we've already fixed our return pointer, simply return - # Note that our caller must fix his return pointer as well and that his - # caller must fix his return pointer and so on and so forth. - ret - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - # _jump_to_chainbooter sets up dl, switches from protected to real mode, and # jumps to 0:7C00. Unlike the usual code, the stack is not switched since # there is no stack to switch to. @@ -331,15 +162,4 @@ jmp $0xf0,$0 hlt jmp _cause_crash -#endif - -# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# _Gdtr_high is a pointer to the extended-memory loaded _Gdt -# See the comments above as to why we have OFFSET_1MEG. - //.data - .section __INIT,__data // turbo - .align 2, 0x90 -_Gdtr_high: - .word GDTLIMIT - .long vtop(_Gdt + OFFSET_1MEG) - +#endif \ No newline at end of file Index: branches/xZen/src/arch/i386/boot2/boot.h =================================================================== --- branches/xZen/src/arch/i386/boot2/boot.h (revision 1266) +++ branches/xZen/src/arch/i386/boot2/boot.h (revision 1267) @@ -29,7 +29,7 @@ #ifndef __BOOT2_BOOT_H #define __BOOT2_BOOT_H -#include "libsaio.h" +#include /* * Keys used in system Boot.plist @@ -128,123 +128,8 @@ #define kBootTimeout -1 #define kCDBootTimeout 8 -/* - * A global set by boot() to record the device that the booter - * was loaded from. - */ -extern int gBIOSDev; -extern long gBootMode; -extern bool sysConfigValid; -extern char bootBanner[]; -extern char bootPrompt[]; -extern bool gOverrideKernel; -extern char *gPlatformName; -extern char gMKextName[]; -extern char gRootDevice[]; -extern bool gEnableCDROMRescan; -extern bool gScanSingleDrive; -extern bool useGUI; - -/* - * Boot Modes - */ -enum { - kBootModeNormal = 0, - kBootModeSafe = 1, - kBootModeSecure = 2, - kBootModeQuiet = 4 -}; - extern void initialize_runtime(); extern void common_boot(int biosdev); -/* - * usb.c - */ -extern int usb_loop(); -/* - * graphics.c - */ -extern void printVBEModeInfo(); -extern void setVideoMode(int mode, int drawgraphics); -extern int getVideoMode(); -extern void spinActivityIndicator(); -extern void clearActivityIndicator(); -extern void drawColorRectangle( unsigned short x, - unsigned short y, - unsigned short width, - unsigned short height, - unsigned char colorIndex ); -extern void drawDataRectangle( unsigned short x, - unsigned short y, - unsigned short width, - unsigned short height, - unsigned char * data ); -extern int -convertImage( unsigned short width, - unsigned short height, - const unsigned char *imageData, - unsigned char **newImageData ); -extern char * decodeRLE( const void * rleData, int rleBlocks, int outBytes ); -extern void drawBootGraphics(void); -extern void drawPreview(void *src, uint8_t * saveunder); -extern int getVideoMode(void); -extern void loadImageScale (void *input, int iw, int ih, int ip, void *output, int ow, int oh, int op, int or); - -/* - * drivers.c - */ -extern long LoadExtraDrivers(char * dirSpec); -extern long LoadDrivers(char * dirSpec); -extern long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize); - -typedef long (*FileLoadDrivers_t)(char *dirSpec, long plugin); -/*! - Hookable function pointer called during the driver loading phase that - allows other code to cause additional drivers to be loaded. - */ -extern long (*LoadExtraDrivers_p)(FileLoadDrivers_t FileLoadDrivers_p); - -/* - * options.c - */ -extern int getBootOptions(bool firstRun); -extern int processBootOptions(); -extern int selectAlternateBootDevice(int bootdevice); -extern bool promptForRescanOption(void); - -void showHelp(); -void showTextFile(); -char *getMemoryInfoString(); - -typedef struct { - char name[80]; - void * param; -} MenuItem; - -/* - * lzss.c - */ -extern int decompress_lzss(u_int8_t *dst, u_int8_t *src, u_int32_t srclen); - -struct compressed_kernel_header { - u_int32_t signature; - u_int32_t compress_type; - u_int32_t adler32; - u_int32_t uncompressed_size; - u_int32_t compressed_size; - u_int32_t reserved[11]; - char platform_name[64]; - char root_path[256]; - u_int8_t data[0]; -}; -typedef struct compressed_kernel_header compressed_kernel_header; - -/* resume.c */ -void HibernateBoot(char *boot_device); - -/* bmdecompress.c */ -void * DecompressData(void *srcbase, int *dw, int *dh, int *bytesPerPixel); - #endif /* !__BOOT2_BOOT_H */ Index: branches/xZen/src/arch/i386/boot2/Makefile =================================================================== --- branches/xZen/src/arch/i386/boot2/Makefile (revision 1266) +++ branches/xZen/src/arch/i386/boot2/Makefile (revision 1267) @@ -6,24 +6,37 @@ DSTROOT = $(ROOT)/dst/usr/standalone/i386/ DOCROOT = $(ROOT)/doc -include ${ROOT}/Make.rules - OPTIM = -Oz +CFLAGS := $(RC_CFLAGS) $(OPTIM) $(MORECPP) -g -Wmost -Werror \ + -fno-builtin -DSAIO_INTERNAL_USER $(OMIT_FRAME_POINTER_CFLAG) \ + -fno-align-functions -fno-stack-protector \ + -msoft-float -nostdinc -include $(SRCROOT)/autoconf.h + +CPPFLAGS := $(CPPFLAGS) -nostdinc++ -Wmost -Werror \ + -fno-builtin -msoft-float \ + -fno-rtti -fno-exceptions \ + -include $(SRCROOT)/autoconf.h + + +#todo: ensur ecorrect arch +MACHOCONV = ${SYMROOT}/../util/machOconv.${ARCH} + LIBSADIR = ../libsa LIBSAIODIR = ../libsaio -INC = -I. -I$(SYMDIR) -I$(LIBSADIR) -I$(LIBSAIODIR) -I${SRCROOT}/i386/include +INC = -I. -I$(SYMROOT) -I$(LIBSADIR) -I$(LIBSAIODIR) -I${SRCROOT}/include -LIBS= -L$(SYMDIR) -lsaio -lsa +LIBS= -L$(SYMROOT) -lsaio -lsa LIBDEP= libsaio.a libsa.a OTHER_FILES = -OBJECTS = boot2 boot mboot boot_modules +OBJECTS = boot2 boot +#boot_modules -UTILDIR = ../util DIRS_NEEDED = $(OBJROOT) $(SYMROOT) + BOOT2ADDR = 20200 MAXBOOTSIZE = 458240 @@ -39,6 +52,9 @@ PATCH_ADDR = $(shell echo ${SYMBOL_ADDR}-${DATA_ADDR}+${DATA_OFFSET} | bc) +include ${ROOT}/Make.rules + + all: $(DIRS_NEEDED) boot @@ -48,8 +64,8 @@ @${MKDIRS} $(OBJROOT)/../boot2_modules/ @echo "\t[LD] boot.sys" @$(CC) -Wl,-segaddr,__INIT,$(BOOT2ADDR) -Wl,-segalign,20 -Wl,-preload \ - -nostdlib -arch i386 -static \ - -o $(SYMROOT)/boot.sys $(filter %.o,$^) `find $(OBJROOT)/../boot2_modules/ -name \*.o` $(LIBS) -lcc_kext + -nostdlib -arch ${ARCH} -static \ + -o $(SYMROOT)/boot.sys $(filter %.o,$^) `find $(OBJROOT)/../../boot2_modules/ -name \*.${ARCH}o` $(LIBS) ifeq (${CONFIG_MODULES}, y) @@ -61,9 +77,9 @@ @echo "\t[LD] boot.sys" @$(CC) -static -Wl,-preload -Wl,-segaddr,__INIT,$(BOOT2ADDR) \ - -nostdlib -arch i386 -Wl,-segalign,20 \ + -nostdlib -arch ${ARCH} -Wl,-segalign,20 \ -Wl,-sectcreate,__DATA,__Symbols,$(SYMROOT)/Symbols.dylib \ - -o $(SYMROOT)/boot.sys $(filter %.o,$^) `find $(OBJROOT)/../boot2_modules/ -name \*.o` $(LIBS) -lcc_kext + -o $(SYMROOT)/boot.sys $(filter %.o,$^) `find $(OBJROOT)/../../boot2_modules/ -name \*.${ARCH}o` $(LIBS) @# Second pass, fixup global var locations @${RM} $(SYMROOT)/${SYMBOLS_MODULE} @@ -75,18 +91,18 @@ @${RM} $(SYMROOT)/boot.sys @echo "\t[LD] boot.sys" @$(CC) -static -Wl,-preload -Wl,-segaddr,__INIT,$(BOOT2ADDR) \ - -nostdlib -arch i386 -Wl,-segalign,20 \ + -nostdlib -arch ${ARCH} -Wl,-segalign,20 \ -Wl,-sectcreate,__DATA,__Symbols,$(SYMROOT)/Symbols.dylib \ - -o $(SYMROOT)/boot.sys $(filter %.o,$^) `find $(OBJROOT)/../boot2_modules/ -name \*.o` $(LIBS) -lcc_kext + -o $(SYMROOT)/boot.sys $(filter %.o,$^) `find $(OBJROOT)/../../boot2_modules/ -name \*.${ARCH}o` $(LIBS) -lcc_kext @${RM} $(SYMROOT)/${SYMBOLS_MODULE} - @$(LD) -arch i386 \ + @$(LD) -arch ${ARCH} \ -undefined dynamic_lookup \ -dylib -read_only_relocs suppress \ -S -x -Z -dead_strip_dylibs \ -no_uuid \ - $(filter %.o,$^) $(LIBS) \ + $(filter %.${ARCH}o,$^) $(LIBS) \ -final_output Symbols \ -macosx_version_min 10.6 \ -o $(OBJROOT)/Symbols_LINKER_ONLY.dylib @@ -113,13 +129,13 @@ ifeq (${CONFIG_MODULES}, y) @echo ================= Embedding Symbols.dylib ================= @echo "\t[MACHOCONV] boot" - @$(SYMROOT)/machOconv $(SYMROOT)/boot2.sys $(SYMROOT)/boot &> /dev/null + @${MACHOCONV} $(SYMROOT)/boot2.sys $(SYMROOT)/boot &> /dev/null @echo "\t******* Patching at $(PATCH_ADDR) ******" @stat -f%z $(SYMROOT)/boot | perl -ane "print pack('V',@F[0]);" | dd conv=notrunc of=${SYMROOT}/boot.sys bs=1 count=4 seek=$(PATCH_ADDR) &> /dev/null endif @echo "\t[MACHOCONV] boot" - @$(SYMROOT)/machOconv $(SYMROOT)/boot.sys $(SYMROOT)/boot + @${MACHOCONV} $(SYMROOT)/boot.sys $(SYMROOT)/boot $(SYMROOT)/embedded.h: Index: branches/xZen/src/arch/i386/Make.rules =================================================================== --- branches/xZen/src/arch/i386/Make.rules (revision 1266) +++ branches/xZen/src/arch/i386/Make.rules (revision 1267) @@ -32,7 +32,7 @@ $(OBJROOT)/boot2.${ARCH}o: @echo "\t[AS:I386] boot2.s" - @$(TARGET_CC) -Wa,-n -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) boot2.s \ + @$(TARGET_CC) -Wa,-n $(CFLAGS) $(INC) -arch ${ARCH} -o $(OBJROOT)/$(@F) -c boot2.s \ -MD -dependency-file $*.d @md -u $(OBJROOT)/Makedep -f -d $*.d Index: branches/xZen/src/arch/i386/libsa/Makefile =================================================================== --- branches/xZen/src/arch/i386/libsa/Makefile (revision 1266) +++ branches/xZen/src/arch/i386/libsa/Makefile (revision 1267) @@ -8,7 +8,17 @@ LIBSAIODIR = ../libsaio +CFLAGS := $(RC_CFLAGS) $(OPTIM) $(MORECPP) -static -g -Wmost -Werror \ + -fno-builtin -DSAIO_INTERNAL_USER $(OMIT_FRAME_POINTER_CFLAG) \ + -fno-align-functions -fno-stack-protector \ + -msoft-float -nostdinc -include $(SRCROOT)/autoconf.h + +CPPFLAGS := $(CPPFLAGS) -static -nostdinc++ -Wmost -Werror \ + -fno-builtin -msoft-float \ + -fno-rtti -fno-exceptions \ + -include $(SRCROOT)/autoconf.h + INC = -I. -I$(SYMROOT) -I$(LIBSAIODIR) -I${SRCROOT}/include OBJECTS = prf printf zalloc \ Index: branches/xZen/src/arch/i386/Makefile =================================================================== --- branches/xZen/src/arch/i386/Makefile (revision 1266) +++ branches/xZen/src/arch/i386/Makefile (revision 1267) @@ -19,11 +19,11 @@ @#cd modules; ${MAKE} BUILT_IN=yes $@ - @for i in ${SUBDIRS}; \ - do \ + @for i in ${SUBDIRS}; \ + do \ echo ================= make $@ for $$i =================; \ - ( ROOT=$(ROOT); \ - cd $$i; ${MAKE} \ - $@ \ - ) || exit $$?; \ + ( \ + cd $$i; ${MAKE} \ + $@ \ + ) || exit $$?; \ done \ No newline at end of file Index: branches/xZen/src/arch/Makefile =================================================================== --- branches/xZen/src/arch/Makefile (revision 1266) +++ branches/xZen/src/arch/Makefile (revision 1267) @@ -16,11 +16,11 @@ SUBDIRS = ${ARCH} all: ${OBJROOT} ${SYMROOT} - @for i in ${SUBDIRS}; \ - do \ + @for i in ${SUBDIRS}; \ + do \ echo ================= make $@ for $$i =================; \ - ( ROOT=$(ROOT); \ - cd $$i; ${MAKE} \ - $@ \ - ) || exit $$?; \ + ( \ + cd $$i; ${MAKE} \ + $@ \ + ) || exit $$?; \ done \ No newline at end of file