Index: branches/meklort/i386/libsaio/xml.c =================================================================== --- branches/meklort/i386/libsaio/xml.c (revision 727) +++ branches/meklort/i386/libsaio/xml.c (revision 728) @@ -93,7 +93,7 @@ unsigned long signature1; unsigned long signature2; unsigned long length; - unsigned long alder32; + unsigned long adler32; unsigned long version; unsigned long numDrivers; unsigned long reserved1; Index: branches/meklort/i386/boot2/modules.c =================================================================== --- branches/meklort/i386/boot2/modules.c (revision 727) +++ branches/meklort/i386/boot2/modules.c (revision 728) @@ -77,8 +77,7 @@ } else { // The module does not have a valid start function - printf("Unable to start %s\n", SYMBOLS_MODULE); DBGPAUSE(); - getc(); + printf("Unable to start %s\n", SYMBOLS_MODULE); getc(); } return 0; } @@ -164,6 +163,9 @@ (*module_start)(); // Start the module DBG("Module %s Loaded.\n", module); DBGPAUSE(); + + //module_entry = malloc(sizeof(moduleList_t); TODO: mode to module_loaded + } else { // The module does not have a valid start function @@ -216,7 +218,6 @@ entry->next = NULL; entry->addr = (UInt32)addr; entry->symbol = symbol; - if(strcmp(symbol, "start") == 0) { return addr; @@ -239,7 +240,9 @@ new_entry->next = loadedModules; loadedModules = new_entry; - new_entry->module = (char*)name; + new_entry->name = (char*)name; + new_entry->base_addr = NULL; // TODO + // todo; symbols new_entry->version = 0; //version; new_entry->compat = 0; //compat; } @@ -250,7 +253,7 @@ moduleList_t* entry = loadedModules; while(entry) { - if(strcmp(entry->module, name) == 0) + if(strcmp(entry->name, name) == 0) { DBG("Located module %s\n", name); DBGPAUSE(); return 1; @@ -341,6 +344,9 @@ UInt32 binaryIndex = 0; UInt16 cmd = 0; + textSection = 0; + textAddress = 0; // reinitialize text location in case it doesn't exist; + // Parse through the load commands if(((struct mach_header*)binary)->magic == MH_MAGIC) { @@ -504,7 +510,7 @@ //if(!moduleName) return NULL; - // bind_macho uses the symbols. + // bind_macho uses the symbols, if the textAdd does not exist (Symbols.dylib, no code), addresses are static and not relative module_start = (void*)handle_symtable((UInt32)binary, symtabCommand, symbol_handler, is64); // Rebase the module before binding it. @@ -557,11 +563,11 @@ { // If the symbol is exported by this module if(symbolEntry->n_value && - symbol_handler(symbolString + symbolEntry->n_un.n_strx, (long long)base + symbolEntry->n_value, is64) != 0xFFFFFFFF) + symbol_handler(symbolString + symbolEntry->n_un.n_strx, textAddress ? (long long)base + symbolEntry->n_value : symbolEntry->n_value, is64) != 0xFFFFFFFF) { // Module start located. Start is an alias so don't register it - module_start = base + symbolEntry->n_value; + module_start = textAddress ? base + symbolEntry->n_value : symbolEntry->n_value; } symbolEntry++; @@ -578,11 +584,11 @@ // If the symbol is exported by this module if(symbolEntry->n_value && - symbol_handler(symbolString + symbolEntry->n_un.n_strx, (long long)base + symbolEntry->n_value, is64) != 0xFFFFFFFF) + symbol_handler(symbolString + symbolEntry->n_un.n_strx, textAddress ? (long long)base + symbolEntry->n_value : symbolEntry->n_value, is64) != 0xFFFFFFFF) { // Module start located. Start is an alias so don't register it - module_start = base + symbolEntry->n_value; + module_start = textAddress ? base + symbolEntry->n_value : symbolEntry->n_value; } symbolEntry++; Index: branches/meklort/i386/boot2/modules.h =================================================================== --- branches/meklort/i386/boot2/modules.h (revision 727) +++ branches/meklort/i386/boot2/modules.h (revision 728) @@ -31,6 +31,7 @@ extern unsigned long long textSection; + typedef struct symbolList_t { char* symbol; @@ -38,13 +39,6 @@ struct symbolList_t* next; } symbolList_t; -typedef struct moduleList_t -{ - char* module; - unsigned int version; - unsigned int compat; - struct moduleList_t* next; -} moduleList_t; typedef struct callbackList_t { @@ -59,8 +53,22 @@ struct moduleHook_t* next; } moduleHook_t; +typedef struct modulesList_t +{ + char* name; + UInt32 version; + UInt32 compat; + + void* base_addr; + symbolList_t* exported_symbols; + symbolList_t* udefined_symbols; + //moduleHook_t* defined_hooks; + struct modulesList_t* next; +} moduleList_t; + + int init_module_system(); void load_all_modules(); Index: branches/meklort/i386/boot2/drivers.c =================================================================== --- branches/meklort/i386/boot2/drivers.c (revision 727) +++ branches/meklort/i386/boot2/drivers.c (revision 728) @@ -47,7 +47,7 @@ long (*LoadExtraDrivers_p)(FileLoadDrivers_t FileLoadDrivers_p); #endif -unsigned long Mkext_Alder32( unsigned char * buffer, long length ); +unsigned long Adler32( unsigned char * buffer, long length ); long FileLoadDrivers(char *dirSpec, long plugin); #ifndef OPTION_ROM @@ -74,7 +74,7 @@ char * gFileName; unsigned long -Mkext_Alder32( unsigned char * buffer, long length ) +Adler32( unsigned char * buffer, long length ) { long cnt; unsigned long result, lowHalf, highHalf; @@ -99,7 +99,7 @@ result = (highHalf << 16) | lowHalf; - return result; + return result; } @@ -383,8 +383,8 @@ if (( GetPackageElement(signature1) != kDriverPackageSignature1) || ( GetPackageElement(signature2) != kDriverPackageSignature2) || ( GetPackageElement(length) > kLoadSize ) || - ( GetPackageElement(alder32) != - Mkext_Alder32((unsigned char *)&package->version, GetPackageElement(length) - 0x10) ) ) + ( GetPackageElement(adler32) != + Adler32((unsigned char *)&package->version, GetPackageElement(length) - 0x10) ) ) { return -1; } @@ -784,7 +784,7 @@ return -1; } if (OSSwapBigToHostInt32(kernel_header->adler32) != - Mkext_Alder32(binary, uncompressed_size)) { + Adler32(binary, uncompressed_size)) { printf("adler mismatch\n"); return -1; } Index: branches/meklort/i386/boot2/drivers.h =================================================================== --- branches/meklort/i386/boot2/drivers.h (revision 727) +++ branches/meklort/i386/boot2/drivers.h (revision 728) @@ -71,7 +71,7 @@ unsigned long signature1; unsigned long signature2; unsigned long length; - unsigned long alder32; + unsigned long adler32; unsigned long version; unsigned long numDrivers; unsigned long reserved1; Index: branches/meklort/i386/boot2/modules_support.s =================================================================== --- branches/meklort/i386/boot2/modules_support.s (revision 727) +++ branches/meklort/i386/boot2/modules_support.s (revision 728) @@ -1,4 +1,7 @@ #include LABEL(dyld_stub_binder) - jmp _dyld_stub_binder \ No newline at end of file + jmp _dyld_stub_binder + +LABEL(dyld_void_start) + ret \ No newline at end of file Index: branches/meklort/i386/boot2/Makefile =================================================================== --- branches/meklort/i386/boot2/Makefile (revision 727) +++ branches/meklort/i386/boot2/Makefile (revision 728) @@ -84,8 +84,9 @@ @cp $(SYMROOT)/boot.sys $(SYMROOT)/boot2.sys - @make Symbols.dylib - @${RM} $(SYMROOT)/boot.sys + @# Generate the Symbols.dylib file + @echo "\t[dyldsymboltool] Symbols.dylib" + @$(SYMROOT)/dyldsymboltool $(SYMROOT)/boot.sys $(SYMROOT)/Symbols.dylib @echo "\t[LD] boot.sys" @$(LD) -static -Wl,-preload -Wl,-segaddr,__INIT,$(BOOT2ADDR) \ @@ -97,8 +98,11 @@ @${RM} $(OBJROOT)/Symbols.o @${RM} $(SYMROOT)/${SYMBOLS_MODULE} @${RM} $(SYMROOT)/Symbols.h - @make Symbols.dylib + @# Generate the Symbols.dylib file + @echo "\t[dyldsymboltool] Symbols.dylib" + @$(SYMROOT)/dyldsymboltool $(SYMROOT)/boot.sys $(SYMROOT)/Symbols.dylib + @${RM} $(SYMROOT)/boot.sys @echo "\t[LD] boot.sys" @$(LD) -static -Wl,-preload -Wl,-segaddr,__INIT,$(BOOT2ADDR) \ @@ -154,48 +158,9 @@ @echo "#define I386BOOT_CHAMELEONREVISION \"`svnversion -n | tr -d [:alpha:]`\"" >> $(SYMROOT)/vers.h embedded.h: - @cd $(SYMROOT)/../../doc && xxd -i BootHelp.txt > $(SYMROOT)/embedded.h + @cd $(SYMROOT)/../../doc && xxd -i BootHelp.txt > $(SYMROOT)/embedded.h -Symbols.dylib: Symbols.o - @echo ================= Compiling ${SYMBOLS_MODULE} ================= - @echo "start" >> ${OBJROOT}/Symbols.save - @echo "_lookup_symbol" >> ${OBJROOT}/Symbols.save - @echo "\t[LD] $@" - @ld -arch i386 \ - -undefined dynamic_lookup \ - -alias _Symbols_start start \ - -dylib -read_only_relocs suppress \ - -S -x -dead_strip_dylibs \ - -no_uuid \ - -bind_at_load \ - -current_version 1.0.0 \ - -compatibility_version 1.0.0 \ - -final_output Symbols \ - -exported_symbols_list ${OBJROOT}/Symbols.save \ - ${OBJROOT}/Symbols.o \ - -macosx_version_min 10.6 \ - -o $(SYMROOT)/${SYMBOLS_MODULE} - - @##size $(SYMROOT)/${SYMBOLS_MODULE} - -Symbols.o: - @rm -rf $(SYMROOT)/Symbols.h - @echo "typedef struct {" >> $(SYMROOT)/Symbols.h - @echo " char* symbol;" >> $(SYMROOT)/Symbols.h - @echo " unsigned int addr;" >> $(SYMROOT)/Symbols.h - @echo "} symbol_t;" >> $(SYMROOT)/Symbols.h - @echo "" >> $(SYMROOT)/Symbols.h - - @nm -g $(SYMROOT)/boot.sys | tr . _ | awk '{print "static char "$$3"_string[] = \""$$3"\";"}' >> $(SYMROOT)/Symbols.h - - @echo "symbol_t symbolList[] = {" >> $(SYMROOT)/Symbols.h - @nm -g $(SYMROOT)/boot.sys | tr . _ | awk '{print " {.symbol = "$$3"_string, .addr = 0x"$$1"},";}' >> $(SYMROOT)/Symbols.h - @echo "};" >> $(SYMROOT)/Symbols.h - @echo "\t[CC] $@" - @$(CC) $(CPPFLAGS) $(CFLAGS) $(DEFINES) -c Symbols.c $(INC) -o $(OBJROOT)/Symbols.o - - install_i386:: all $(INSTALLDIR) cp $(SYMROOT)/boot $(OTHER_FILES) $(INSTALLDIR) cd $(INSTALLDIR); chmod u+w boot $(OTHER_FILES) Index: branches/meklort/i386/modules/KextPatcher/kext_patcher.c =================================================================== --- branches/meklort/i386/modules/KextPatcher/kext_patcher.c (revision 727) +++ branches/meklort/i386/modules/KextPatcher/kext_patcher.c (revision 728) @@ -20,6 +20,9 @@ #include "hex_editor.h" +unsigned long Adler32( unsigned char * buffer, long length ); + + #define kHDACodec "HDACodec" @@ -89,7 +92,6 @@ } -unsigned long Mkext_Alder32( unsigned char * buffer, long length ); void KextPatcher_hook(void* current, void* arg2, void* arg3, void* arg4); @@ -161,7 +163,7 @@ ( MKEXT_GET_SIGNATURE(package) != MKEXT_SIGN ) || ( MKEXT_GET_LENGTH(package) > kLoadSize ) || ( MKEXT_GET_CHECKSUM(package) != - Mkext_Alder32((unsigned char *)&package->version, MKEXT_GET_LENGTH(package) - 0x10) ) ) + Adler32((unsigned char *)&package->version, MKEXT_GET_LENGTH(package) - 0x10) ) ) { return; // Don't try to patch a b @@ -317,9 +319,9 @@ - // re alder32 the new mkext2 package + // re adler32 the new mkext2 package MKEXT_HDR_CAST(package)->adler32 = - MKEXT_SWAP(Mkext_Alder32((unsigned char *)&package->version, + MKEXT_SWAP(Adler32((unsigned char *)&package->version, MKEXT_GET_LENGTH(package) - 0x10)); } } Index: branches/meklort/i386/modules/USBFix/usb.c =================================================================== --- branches/meklort/i386/modules/USBFix/usb.c (revision 727) +++ branches/meklort/i386/modules/USBFix/usb.c (revision 728) @@ -49,8 +49,8 @@ int usb_loop() { int retVal = 1; - bool fix_ehci, fix_uhci, fix_usb, fix_legacy; - fix_ehci = fix_uhci = fix_usb = fix_legacy = true; + bool fix_ehci, fix_uhci, fix_usb, fix_legacy = false; + fix_ehci = fix_uhci = fix_usb = true; if (getBoolForKey(kUSBBusFix, &fix_usb, &bootInfo->bootConfig)) { Index: branches/meklort/i386/Makefile =================================================================== --- branches/meklort/i386/Makefile (revision 727) +++ branches/meklort/i386/Makefile (revision 728) @@ -27,7 +27,7 @@ # The order of building is important. SUBDIRS = util libsa libsaio boot2 boot1 boot0 cdboot modules - +#SUBDIRS=util all embedtheme optionrom tags debug install installhdrs: @for i in ${SUBDIRS}; \ do \ Index: branches/meklort/i386/util/dyldsymboltool.c =================================================================== --- branches/meklort/i386/util/dyldsymboltool.c (revision 0) +++ branches/meklort/i386/util/dyldsymboltool.c (revision 728) @@ -0,0 +1,210 @@ +/* + * Copyright (c) 2010 Evan Lojewski. All rights reserved. + * + * dyldsymboltool + * + * Generates a dylib ile for the dyld implimentation in chameleon + * to load and link. This is used to import the boot symbols into the + * module system. + */ + +#include +#include +#include +#include +#include +#include + + +#define DYLIB_NAME "Symbols" +#define VOID_SYMBOL "dyld_void_start" +#define START_SYMBOL "start" + +typedef struct symbols_dylib +{ + struct mach_header header; + struct dylib_command dylib_info; + char module_name[sizeof(DYLIB_NAME)]; + struct symtab_command symtab; +} symbols_dylib_t; + + +typedef struct symbolList_t +{ + char* name; + uint32_t addr; + int pos; + struct symbolList_t* next; +} symbolList_t; + + +int num_symbols(symbolList_t* list); +int string_size(symbolList_t* list); +void add_symbol(symbolList_t** list, char* name, uint32_t addr); + + +int main(int argc, char *argv[]) +{ + if(argc != 3) + { + fprintf(stderr, "usage: dyldsymboltool bootFile loadAddr outfile\n"); + + exit(-1); + } + + + char line[256]; + char* command = malloc(strlen(argv[1]) + sizeof("nm -g ")); + FILE *fpipe; + + symbols_dylib_t dylib; + symbolList_t* symbols = NULL; + + uint32_t start_addr = 0; + + + + + + + // Parse boot.sys (arg1) to get symtab + sprintf(command, "nm -g %s", argv[1]); // TODO: read boot.sym directly, no need for nm + + if ( !(fpipe = (FILE*)popen(command,"r")) ) + { // If fpipe is NULL + perror("Problems with pipe"); + exit(1); + } + + while ( fgets( line, sizeof line, fpipe)) + { + uint32_t address = 0; + char* addr = strtok(line, " "); + strtok(NULL, " "); + char* name = strtok(NULL, " "); + name[strlen(name)-1] = 0; // remove newline + sscanf(addr, "%x", &address); + if(strcmp(name, VOID_SYMBOL) == 0) start_addr = address; + add_symbol(&symbols, name, address); + } + + + pclose(fpipe); + + if(start_addr == 0) + { + fprintf(stderr, "Unable to locate Symbol.dylib start function\n"); + exit(1); + } + + add_symbol(&symbols, START_SYMBOL, start_addr); + + + /* Header command info */ + dylib.header.ncmds = 2; + dylib.header.sizeofcmds = sizeof(dylib) - sizeof(struct mach_header);// + dylib.symtab.nsyms * sizeof(struct nlist) + dylib.symtab.strsize; + + dylib.header.magic = MH_MAGIC; + dylib.header.cputype = CPU_TYPE_X86; + dylib.header.cpusubtype = /*CPUSUBTYPE_I386*/ 3; + dylib.header.filetype = MH_DYLIB; + dylib.header.flags = MH_NOUNDEFS | MH_DYLDLINK | MH_NO_REEXPORTED_DYLIBS; + + /* Load Commands - dylib id */ + dylib.dylib_info.cmd = LC_ID_DYLIB; + dylib.dylib_info.cmdsize = sizeof(struct dylib_command) + sizeof(dylib.module_name); // todo: verify + dylib.dylib_info.dylib.name.offset = sizeof(struct dylib_command); + dylib.dylib_info.dylib.timestamp = 0; // TODO: populate with time + dylib.dylib_info.dylib.current_version = 0; // TODO + dylib.dylib_info.dylib.compatibility_version = 0; // TODO + + + //int offset = dylib.dylib_info.cmdsize%4 ? 4 - (dylib.dylib_info.cmdsize % 4) : 0; + //dylib.dylib_info.cmdsize += offset; + //dylib.header.sizeofcmds += offset; + + sprintf(dylib.module_name, "%s", DYLIB_NAME); + + /* Load Commands - Symtable */ + dylib.symtab.cmd = LC_SYMTAB; + dylib.symtab.symoff = sizeof(dylib); + dylib.symtab.nsyms = num_symbols(symbols); + dylib.symtab.stroff = sizeof(dylib) + dylib.symtab.nsyms * sizeof(struct nlist); + dylib.symtab.strsize = string_size(symbols); + dylib.symtab.cmdsize = sizeof(struct symtab_command); + + + + FILE* outfile = fopen(argv[2], "w"); + fwrite(&dylib, sizeof(dylib) /* Sizeof header + module name */ + , 1, outfile); + + char* symtab = malloc(dylib.symtab.stroff + dylib.symtab.strsize - sizeof(dylib) + 1); // Add extra 1 for last symbol + bzero(symtab, dylib.symtab.nsyms * sizeof(struct nlist) + dylib.symtab.strsize + 1); + char* orig = symtab; + + //symtab += offset; + + + while(symbols) + { + + ((struct nlist*)symtab)->n_un.n_strx = symbols->pos; + ((struct nlist*)symtab)->n_type = 0xF; // TODO: read from boot.sys + ((struct nlist*)symtab)->n_sect = 0; + ((struct nlist*)symtab)->n_desc = REFERENCE_FLAG_DEFINED; + ((struct nlist*)symtab)->n_value = (uint32_t)symbols->addr; + symtab+= sizeof(struct nlist); + + strcpy(orig + dylib.symtab.stroff - sizeof(dylib) + symbols->pos, symbols->name); + + symbols = symbols->next; + } + + fwrite(orig, + dylib.symtab.stroff + // Sizeof symbol nlists + dylib.symtab.strsize - sizeof(dylib) + 1 // sizeof symbol strings + , 1, outfile); + + + fclose(outfile); + + exit(0); +} + +int num_symbols(symbolList_t* list) +{ + int retVal = 0; + while(list) + { + retVal++; + list = list->next; + } + return retVal; +} + +int string_size(symbolList_t* list) +{ + int retVal = 0; + while(list) + { + retVal += strlen(list->name)+1; + list = list->next; + } + return retVal; + +} + +void add_symbol(symbolList_t** list, char* name, uint32_t addr) +{ + symbolList_t* entry = malloc(sizeof(symbolList_t)); + entry->next = (*list); + + if(*list) entry->pos = (*list)->pos + strlen((*list)->name) + 1; + else entry->pos = 1; + *list = entry; + + entry->addr = addr; + entry->name = malloc(strlen(name)+1); + strcpy(entry->name, name); +} Index: branches/meklort/i386/util/Makefile =================================================================== --- branches/meklort/i386/util/Makefile (revision 727) +++ branches/meklort/i386/util/Makefile (revision 728) @@ -18,7 +18,7 @@ CFILES = machOconv.c ALLSRC = $(CFILES) $(MFILES) $(HFILES) $(EXPORT_HFILES) -PROGRAMS = machOconv bdmesg +PROGRAMS = machOconv bdmesg dyldsymboltool OUTFILES = $(PROGRAMS) @@ -26,6 +26,11 @@ all embedtheme optionrom: $(DIRS_NEEDED) $(PROGRAMS) +dyldsymboltool: dyldsymboltool.o + @echo "\t[LD] $@" + @$(CC) $(CFLAGS) $(LDFLAGS) $(DEFINES) -o $(SYMROOT)/$(@F) dyldsymboltool.o + + machOconv: machOconv.o @echo "\t[LD] $@" @$(CC) $(CFLAGS) $(LDFLAGS) $(DEFINES) -o $(SYMROOT)/$(@F) machOconv.o