Index: branches/iFabio/Chameleon/i386/libsaio/asm.s =================================================================== --- branches/iFabio/Chameleon/i386/libsaio/asm.s (revision 300) +++ branches/iFabio/Chameleon/i386/libsaio/asm.s (revision 301) @@ -338,6 +338,31 @@ #endif jmp _halt +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +// disableIRQs() - Azi: DHP +// http://www.insanelymac.com/forum/index.php?s=&showtopic=255866&view=findpost&p=1677779 +// +// Port of original patch by: CPARM (who basically did this in boot.c) Thanks! +// +// The ACPI specification dictates that the 8259 (PC-AT compatible) vectors +// must be disabled (that is, masked) when enabling the ACPI APIC operation +// but this isn't done (apparently) on all mobo's and thus we do that here. +// +LABEL(_disableIRQs) + + push %eax // Saving register data + + movb $0x80, %al // Block NMI + outb %al, $0x70 + + movb $0xff, %al // Load mask + outb %al, $0x21 // Disable IRQ's 0-7 on Master PIC + outb %al, $0xa1 // Disable IRQ's 8-15 on Slave PIC + + popl %eax // Restore register data + + ret + #ifndef BOOT1 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // startprog(phyaddr, arg) @@ -345,10 +370,12 @@ // Passes arg to the program in %eax. // LABEL(_startprog) + call _disableIRQs // Taking care of a ACPI bug. (Azi: calling the above) + push %ebp mov %esp, %ebp - mov 0xc(%ebp), %eax // argument to program + mov 0xc(%ebp), %eax // argument to program - bootargs to mach_kernel mov 0x8(%ebp), %ecx // entry offset mov $0x28, %ebx // segment push %ebx Index: branches/iFabio/Chameleon/i386/libsaio/nvidia.c =================================================================== --- branches/iFabio/Chameleon/i386/libsaio/nvidia.c (revision 300) +++ branches/iFabio/Chameleon/i386/libsaio/nvidia.c (revision 301) @@ -569,17 +569,17 @@ { 0x10DE107F, "NVIDIA GF119-ES" }, { 0x10DE1080, "GeForce GTX 580" }, { 0x10DE1081, "GeForce GTX 570" }, - { 0x10DE1082, "D13U" }, + { 0x10DE1082, "GeForce GTX 560 Ti" }, { 0x10DE1083, "D13U" }, { 0x10DE1086, "GeForce GTX 570" }, { 0x10DE1088, "GeForce GTX 590" }, { 0x10DE1098, "D13U" }, { 0x10DE109A, "Quadro 5010M / N12E-Q5" }, + { 0x10DE10C3, "GeForce 8400 GS" }, { 0x10DE1200, "GeForce GTX 560 Ti" }, { 0x10DE1244, "GeForce GTX 550 Ti" }, { 0x10DE1245, "GeForce GTS 450" }, - { 0x10DE1251, "N12E-GS-A1" }, - { 0x10DE10C3, "GeForce 8400 GS" } + { 0x10DE1251, "N12E-GS-A1" } }; static uint16_t swap16(uint16_t x) @@ -897,6 +897,15 @@ vram_size *= REG32(NVC0_MEM_CTRLR_COUNT); } + // workaround code for GT 420/430 & 9600M GT + switch (nvda_dev->device_id) + { + case 0x0DE1: vram_size = 1024*1024*1024; break; // GT 430 + case 0x0DE2: vram_size = 1024*1024*1024; break; // GT 420 + case 0x0649: vram_size = 512*1024*1024; break; // 9600M GT + default: break; + } + return vram_size; } Index: branches/iFabio/Chameleon/i386/libsaio/cpu.c =================================================================== --- branches/iFabio/Chameleon/i386/libsaio/cpu.c (revision 300) +++ branches/iFabio/Chameleon/i386/libsaio/cpu.c (revision 301) @@ -136,7 +136,11 @@ p->CPU.Model += (p->CPU.ExtModel << 4); - if (p->CPU.Vendor == 0x756E6547 /* Intel */ && p->CPU.Family == 0x06 && p->CPU.Model >= 0x1a){ + if (p->CPU.Vendor == 0x756E6547 /* Intel */ && + p->CPU.Family == 0x06 && + p->CPU.Model >= CPUID_MODEL_PENRYN && + p->CPU.Model != CPUID_MODEL_ATOM // MSR is *NOT* available on the Intel Atom CPU + ){ msr = rdmsr64(MSR_CORE_THREAD_COUNT); // Undocumented MSR in Nehalem and newer CPUs p->CPU.NoCores = bitfield((uint32_t)msr, 31, 16); // Using undocumented MSR to get actual values p->CPU.NoThreads = bitfield((uint32_t)msr, 15, 0); // Using undocumented MSR to get actual values Index: branches/iFabio/Chameleon/i386/libsaio/cpu.h =================================================================== --- branches/iFabio/Chameleon/i386/libsaio/cpu.h (revision 300) +++ branches/iFabio/Chameleon/i386/libsaio/cpu.h (revision 301) @@ -36,6 +36,20 @@ #define CALIBRATE_TIME_MSEC 30 /* 30 msecs */ #define CALIBRATE_LATCH ((CLKNUM * CALIBRATE_TIME_MSEC + 1000/2)/1000) +// CPUID Values +#define CPUID_MODEL_YONAH 14 +#define CPUID_MODEL_MEROM 15 +#define CPUID_MODEL_PENRYN 23 +#define CPUID_MODEL_NEHALEM 26 +#define CPUID_MODEL_ATOM 28 +#define CPUID_MODEL_FIELDS 30 /* Lynnfield, Clarksfield, Jasper */ +#define CPUID_MODEL_DALES 31 /* Havendale, Auburndale */ +#define CPUID_MODEL_NEHALEM_EX 46 +#define CPUID_MODEL_DALES_32NM 37 /* Clarkdale, Arrandale */ +#define CPUID_MODEL_WESTMERE 44 /* Gulftown, Westmere-EP, Westmere-WS */ +#define CPUID_MODEL_WESTMERE_EX 47 + + static inline uint64_t rdtsc64(void) { uint64_t ret; Index: branches/iFabio/Chameleon/i386/boot1/boot1he.s =================================================================== --- branches/iFabio/Chameleon/i386/boot1/boot1he.s (revision 300) +++ branches/iFabio/Chameleon/i386/boot1/boot1he.s (revision 301) @@ -542,8 +542,6 @@ hlt jmp hang -%if VERBOSE - ;-------------------------------------------------------------------------- ; readLBA - Read sectors from a partition using LBA addressing. ; @@ -637,6 +635,8 @@ popad ret +%if VERBOSE + ;-------------------------------------------------------------------------- ; Write a string with 'boot1: ' prefix to the console. ; Index: branches/iFabio/Chameleon/i386/boot2/Makefile =================================================================== --- branches/iFabio/Chameleon/i386/boot2/Makefile (revision 300) +++ branches/iFabio/Chameleon/i386/boot2/Makefile (revision 301) @@ -126,14 +126,16 @@ @${RM} $(SYMROOT)/boot2.sys - @##size $(SYMROOT)/boot.sys - @ls -l $(SYMROOT)/boot + @( size=`ls -l $(SYMROOT)/boot | awk '{ print $$5}'` ; \ if expr "$$size" ">" "$(MAXBOOTSIZE)" > /dev/null ;\ then \ + echo "\t******* boot is $$size bytes *******"; \ echo "Booter executable larger than $(MAXBOOTSIZE) bytes" ;\ rm $(SYMROOT)/boot ;\ exit 1;\ + else \ + echo "\t******* boot is $$size bytes *******"; \ fi) Index: branches/iFabio/Chameleon/i386/boot2/boot.c =================================================================== --- branches/iFabio/Chameleon/i386/boot2/boot.c (revision 300) +++ branches/iFabio/Chameleon/i386/boot2/boot.c (revision 301) @@ -208,8 +208,8 @@ if (checkOSVersion("10.7")) { // Masking out so that Lion doesn't doublefault - outb(0x21, 0xff); /* Maskout all interrupts Pic1 */ - outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */ + // outb(0x21, 0xff); /* Maskout all interrupts Pic1 */ + // outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */ // Jump to kernel's entry point. There's no going back now. Index: branches/iFabio/Chameleon/i386/modules/MakeInc.dir =================================================================== --- branches/iFabio/Chameleon/i386/modules/MakeInc.dir (revision 300) +++ branches/iFabio/Chameleon/i386/modules/MakeInc.dir (revision 301) @@ -10,7 +10,7 @@ ifeq ($(BUILT_IN),yes) override OBJROOT = $(SRCROOT)/obj/i386/boot2_modules/$(DIR) -override SYMROOT = $(SRCROOT)/sym/i386/ +override SYMROOT = $(SRCROOT)/obj/i386/ endif include ${SRCROOT}/Make.rules @@ -51,16 +51,19 @@ LIBSAIODIR = ../../libsaio BOOT2DIR = ../../boot2 -INC = -I$(SRCROOT)/i386/modules/include/ -Iinclude/ -I$(SRCROOT)/i386/modules/module_includes/ -I$(SRCROOT)/i386/libsaio/ -I$(SRCROOT)/i386/libsa/ -I$(SRCROOT)/i386/include/ -I$(SRCROOT)/i386/boot2/ +MODULE_INCLUDES := $(foreach x,$(MODULE_DEPENDENCIES),-I$(SRCROOT)/i386/modules/$(x)/include/) + + +INC = -I$(SRCROOT)/i386/modules/include/ -Iinclude/ -I$(SRCROOT)/i386/libsaio/ -I$(SRCROOT)/i386/libsa/ -I$(SRCROOT)/i386/include/ -I$(SRCROOT)/i386/boot2/ $(MODULE_INCLUDES) DEFINES := -D__KLIBC__ $(DEFINES) -MODULE_DEPENDENCIES := $(foreach x,$(MODULE_DEPENDENCIES),-weak_library $(SYMROOT)/modules/$(x).dylib) +MODULE_DEPENDENCIES := $(wildcard $(foreach x,$(MODULE_DEPENDENCIES),$(SYMROOT)/modules/$(x).dylib)) \ + $(wildcard $(foreach x,$(MODULE_DEPENDENCIES),$(OBJROOT)/../$(x).dylib)) +MODULE_DEPENDENCIES_CMD := $(foreach x,$(MODULE_DEPENDENCIES), -weak_library $(x)) INSTALLDIR = $(DSTROOT)/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/standalone -##$(error DEFINED AS $(MODULE_DEFINITION)) - MODULE_DEFINITION := $(CONFIG_$(shell echo $(MODULE_NAME) | tr '[:lower:]' '[:upper:]')_MODULE) @@ -82,7 +85,7 @@ ifeq ($(BUILT_IN),yes) # Make this *BUILT IN* -all: ${OBJROOT} ${SYMROOT}/modules/ ${OBJROOT} $(addprefix $(OBJROOT)/, ${MODULE_OBJS}) $(SYMROOT)/boot_modules.h $(SYMROOT)/boot_modules.c +all: dylib_LINKER else # Module not selected to be built in @@ -97,10 +100,30 @@ endif endif -dylib: ${SYMROOT}/modules/ ${OBJROOT} $(addprefix $(OBJROOT)/, ${MODULE_OBJS}) $(SYMROOT)/modules/$(MODULE_NAME).dylib -$(SYMROOT)/modules/$(MODULE_NAME).dylib: +dylib_LINKER: $(SRCROOT)/sym/i386/boot_modules.c $(SRCROOT)/sym/i386/boot_modules.h dylib + +dylib: ${SYMROOT}/modules/ ${OBJROOT} $(SYMROOT)/modules/$(MODULE_NAME).dylib + + +ifeq ($(BUILT_IN),yes) + +$(SYMROOT)/modules/$(MODULE_NAME).dylib: $(addprefix $(OBJROOT)/, ${MODULE_OBJS}) $(MODULE_DEPENDENCIES) @echo "\t[LD] $(MODULE_NAME).dylib" + @ld -arch i386 -undefined dynamic_lookup \ + -dylib -read_only_relocs suppress \ + -S -x -Z -dead_strip_dylibs \ + -no_uuid \ + -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ + -final_output $(MODULE_NAME) \ + $(filter %.o,$^) \ + -macosx_version_min 10.6 \ + -o $(SYMROOT)/modules/$(MODULE_NAME).dylib + +else + +$(SYMROOT)/modules/$(MODULE_NAME).dylib: $(addprefix $(OBJROOT)/, ${MODULE_OBJS}) $(MODULE_DEPENDENCIES) $(SRCROOT)/obj/i386/boot2/Symbols_LINKER_ONLY.dylib + @echo "\t[LD] $(MODULE_NAME).dylib" @ld -arch i386 \ -alias _$(MODULE_START) start \ @@ -109,18 +132,15 @@ -no_uuid \ -current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \ -final_output $(MODULE_NAME) \ - -L$(OBJROOT)/ \ - -L$(OBJROOT)/../ \ - -L$(SYMROOT)/ \ - $(OBJROOT)/*.o \ - -weak_library $(OBJROOT)/../../boot2/Symbols_LINKER_ONLY.dylib \ - $(MODULE_DEPENDENCIES) \ + $(filter %.o,$^) \ + -weak_library $(SRCROOT)/obj/i386/boot2/Symbols_LINKER_ONLY.dylib \ + $(MODULE_DEPENDENCIES_CMD) \ -macosx_version_min 10.6 \ - -o $(SYMROOT)/modules/$(MODULE_NAME).dylib - - @cp -rf include/* ../module_includes/ &> /dev/null || true - + -o $@ + +endif + clean: @echo "\t[RM] $(SYMROOT)/modules/$(MODULE_NAME).dylib" @echo "\t[RM] $(OBJROOT)" @@ -137,14 +157,14 @@ -.PHONY: $(SYMROOT)/boot_modules.h -.PHONY: $(SYMROOT)/boot_modules.c +.PHONY: $(SRCROOT)/sym/i386/boot_modules.h +.PHONY: $(SRCROOT)/sym/i386/boot_modules.c -$(SYMROOT)/boot_modules.c: - @echo "\tstart_built_in_module(\"$(MODULE_NAME)\", &$(MODULE_START));" >> $@ +$(SRCROOT)/sym/i386/boot_modules.c: + echo "\tstart_built_in_module(\"$(MODULE_NAME)\", &$(MODULE_START));" >> $@ -$(SYMROOT)/boot_modules.h: - @echo "void $(MODULE_START)(); // $(MODULE_NAME)" >> $@ +$(SRCROOT)/sym/i386/boot_modules.h: + echo "void $(MODULE_START)(); // $(MODULE_NAME)" >> $@ #dependencies Index: branches/iFabio/Chameleon/i386/modules/Cconfig =================================================================== --- branches/iFabio/Chameleon/i386/modules/Cconfig (revision 300) +++ branches/iFabio/Chameleon/i386/modules/Cconfig (revision 301) @@ -5,7 +5,7 @@ menu "Modules" source "i386/modules/Resolution/Cconfig" source "i386/modules/klibc/Cconfig" -source "i386/modules/uClibc++/Cconfig" +source "i386/modules/uClibcxx/Cconfig" source "i386/modules/HelloWorld/Cconfig" source "i386/modules/AMDGraphicsEnabler/Cconfig" source "i386/modules/ATiGraphicsEnabler/Cconfig" Index: branches/iFabio/Chameleon/i386/modules/HelloWorld/HelloWorld.cpp =================================================================== --- branches/iFabio/Chameleon/i386/modules/HelloWorld/HelloWorld.cpp (revision 300) +++ branches/iFabio/Chameleon/i386/modules/HelloWorld/HelloWorld.cpp (revision 301) @@ -6,6 +6,12 @@ #include #include +extern "C" +{ + void HelloWorld_start(); +} + + using namespace std; class HW { Index: branches/iFabio/Chameleon/i386/modules/HelloWorld/Makefile =================================================================== --- branches/iFabio/Chameleon/i386/modules/HelloWorld/Makefile (revision 300) +++ branches/iFabio/Chameleon/i386/modules/HelloWorld/Makefile (revision 301) @@ -1,9 +1,8 @@ MODULE_NAME = HelloWorld MODULE_VERSION = "1.0.0" MODULE_COMPAT_VERSION = "1.0.0" -#MODULE_START = $(MODULE_NAME)_start -MODULE_START = __Z16HelloWorld_startv -MODULE_DEPENDENCIES = uClibc++ +MODULE_START = $(MODULE_NAME)_start +MODULE_DEPENDENCIES = uClibcxx DIR = HelloWorld Index: branches/iFabio/Chameleon/i386/modules/Makefile =================================================================== --- branches/iFabio/Chameleon/i386/modules/Makefile (revision 300) +++ branches/iFabio/Chameleon/i386/modules/Makefile (revision 301) @@ -11,7 +11,7 @@ include ${SRCROOT}/Make.rules # The order of building is important. -SUBDIRS = klibc uClibc++ Resolution HelloWorld \ +SUBDIRS = klibc uClibcxx Resolution HelloWorld \ ATiGraphicsEnabler AMDGraphicsEnabler NVIDIAGraphicsEnabler IntelGraphicsEnabler @@ -55,19 +55,19 @@ .PHONY: $(SYMROOT)/boot_modules.c objroot_dirs: - @rm -rf module_includes - @mkdir module_includes - @rm -rf "$(SYMROOT)/modules/" - @mkdir "$(SYMROOT)/modules/" + @${MKDIRS} "$(SYMROOT)/modules/" $(SYMROOT)/boot_modules.c: ${OBJROOT} ${SYMROOT}/modules/ ${OBJROOT} $(addprefix $(OBJROOT)/, ${MODULE_OBJS}) - @echo "// Autogenerated - do not modify" > $@ +ifeq ($(BUILT_IN),yes) + echo "// Autogenerated - do not modify" > $@ @echo "#include " >> $@ @echo "#include \"boot_modules.h\"" >> $@ @echo "void start_built_in_modules() {" >> $@ +endif $(SYMROOT)/boot_modules.h: ${OBJROOT} ${SYMROOT}/modules/ ${OBJROOT} $(addprefix $(OBJROOT)/, ${MODULE_OBJS}) - @echo "// Autogenerated - do not modify" > $@ +ifeq ($(BUILT_IN),yes) + echo "// Autogenerated - do not modify" > $@ @echo "void start_built_in_modules(); " > $@ - +endif Index: branches/iFabio/Chameleon/i386/Makefile =================================================================== --- branches/iFabio/Chameleon/i386/Makefile (revision 300) +++ branches/iFabio/Chameleon/i386/Makefile (revision 301) @@ -15,10 +15,28 @@ include ${SRCROOT}/Make.rules # The order of building is important. -SUBDIRS = util libsa libsaio boot0 boot1 boot2 cdboot modules +SUBDIRS_PRE = util +SUBDIRS = libsa libsaio boot0 boot1 boot2 cdboot modules all: - @cd modules; ${MAKE} BUILT_IN=yes all + @for i in ${SUBDIRS_PRE}; \ + do \ + echo ================= make $@ for $$i =================; \ + ( cd $$i; ${MAKE} \ + "OBJROOT=$(OBJROOT)/$$i" \ + "SYMROOT=$(SYMROOT)" \ + "DSTROOT=$(DSTROOT)" \ + "SRCROOT=$(SRCROOT)" \ + "RC_ARCHS=$(RC_ARCHS)" \ + "RC_KANJI=$(RC_KANJI)" \ + "JAPANESE=$(JAPANESE)" \ + "RC_CFLAGS=$(RC_CFLAGS)" $@ \ + ) || exit $$?; \ + done + + @cd modules; ${MAKE} BUILT_IN=yes $@ + + @for i in ${SUBDIRS}; \ do \ echo ================= make $@ for $$i =================; \ Index: branches/iFabio/Chameleon/i386/util/dyldsymboltool.c =================================================================== --- branches/iFabio/Chameleon/i386/util/dyldsymboltool.c (revision 300) +++ branches/iFabio/Chameleon/i386/util/dyldsymboltool.c (revision 301) @@ -45,17 +45,14 @@ int main(int argc, char *argv[]) { - if(argc != 3) + if(argc < 3) { - fprintf(stderr, "usage: dyldsymboltool bootFile loadAddr outfile\n"); + fprintf(stderr, "usage: dyldsymboltool obj1 [obj2 ...] 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; @@ -65,41 +62,58 @@ + int i; + for(i = 1; i < argc-1; i++) + { + char line[256]; + char* command = malloc(strlen(argv[1]) + sizeof("nm -g ")); + FILE *fpipe; + // Parse boot.sys (arg1) to get symtab + sprintf(command, "nm -g %s", argv[i]); // 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)) + { + if((strlen(line) < strlen(argv[i]) || + strncmp(line, argv[i], strlen(argv[i])) != 0) + && line[0] != ' ') + { + 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); + + free(command); + } + + - // 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); + + //exit(1); } + else + { + add_symbol(&symbols, START_SYMBOL, start_addr); + } - 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; @@ -135,7 +149,7 @@ - FILE* outfile = fopen(argv[2], "w"); + FILE* outfile = fopen(argv[argc-1], "w"); fwrite(&dylib, sizeof(dylib) /* Sizeof header + module name */ , 1, outfile); Index: branches/iFabio/Chameleon/i386/util/Makefile =================================================================== --- branches/iFabio/Chameleon/i386/util/Makefile (revision 300) +++ branches/iFabio/Chameleon/i386/util/Makefile (revision 301) @@ -4,7 +4,7 @@ # and install them directly, rather than generating them again. # SRCROOT = $(shell pwd)/../../ -OBJROOT = $(SRCROOT)/obj/i386 +OBJROOT = $(SRCROOT)/obj/i386/util SYMROOT = $(SRCROOT)/sym/i386 DSTROOT = $(SRCROOT)/dst/i386 DOCROOT = $(SRCROOT)/doc