Index: trunk/i386/libsaio/cpu.c =================================================================== --- trunk/i386/libsaio/cpu.c (revision 2572) +++ trunk/i386/libsaio/cpu.c (revision 2573) @@ -124,18 +124,21 @@ pollCount = poll_PIT2_gate(); tscEnd = rdtsc64(); /* The poll loop must have run at least a few times for accuracy */ - if (pollCount <= 1) { + if (pollCount <= 1) + { continue; } /* The TSC must increment at LEAST once every millisecond. * We should have waited exactly 30 msec so the TSC delta should * be >= 30. Anything less and the processor is way too slow. */ - if ((tscEnd - tscStart) <= CALIBRATE_TIME_MSEC) { + if ((tscEnd - tscStart) <= CALIBRATE_TIME_MSEC) + { continue; } // tscDelta = MIN(tscDelta, (tscEnd - tscStart)) - if ( (tscEnd - tscStart) < tscDelta ) { + if ( (tscEnd - tscStart) < tscDelta ) + { tscDelta = tscEnd - tscStart; } } @@ -152,9 +155,12 @@ * arithmetic headroom. For now, 32-bit should be enough. * Also unlike Linux, our compiler can do 64-bit integer arithmetic. */ - if (tscDelta > (1ULL<<32)) { + if (tscDelta > (1ULL<<32)) + { retval = 0; - } else { + } + else + { retval = tscDelta * 1000 / 30; } disable_PIT2(); @@ -236,28 +242,28 @@ */ void scan_cpu(PlatformInfo_t *p) { - uint64_t tscFrequency = 0; - uint64_t fsbFrequency = 0; - uint64_t cpuFrequency = 0; - uint64_t msr = 0; - uint64_t flex_ratio = 0; + uint64_t tscFrequency = 0; + uint64_t fsbFrequency = 0; + uint64_t cpuFrequency = 0; + uint64_t msr = 0; + uint64_t flex_ratio = 0; - uint32_t max_ratio = 0; - uint32_t min_ratio = 0; + uint32_t max_ratio = 0; + uint32_t min_ratio = 0; uint32_t reg[4]; - uint8_t bus_ratio_max = 0; - uint8_t bus_ratio_min = 0; - uint8_t currdiv = 0; - uint8_t currcoef = 0; - uint8_t maxdiv = 0; - uint8_t maxcoef = 0; + uint8_t bus_ratio_max = 0; + uint8_t bus_ratio_min = 0; + uint8_t currdiv = 0; + uint8_t currcoef = 0; + uint8_t maxdiv = 0; + uint8_t maxcoef = 0; const char *newratio; char str[128]; - int len = 0; - int myfsb = 0; + int len = 0; + int myfsb = 0; /* get cpuid values */ do_cpuid(0x00000000, p->CPU.CPUID[CPUID_0]); @@ -521,20 +527,20 @@ if (bitfield(msr, 16, 16)) { flex_ratio = bitfield(msr, 15, 8); - /* bcc9: at least on the gigabyte h67ma-ud2h, - where the cpu multipler can't be changed to - allow overclocking, the flex_ratio msr has unexpected (to OSX) - contents. These contents cause mach_kernel to - fail to compute the bus ratio correctly, instead - causing the system to crash since tscGranularity - is inadvertently set to 0. - */ + // bcc9: at least on the gigabyte h67ma-ud2h, + // where the cpu multipler can't be changed to + // allow overclocking, the flex_ratio msr has unexpected (to OSX) + // contents. These contents cause mach_kernel to + // fail to compute the bus ratio correctly, instead + // causing the system to crash since tscGranularity + // is inadvertently set to 0. + if (flex_ratio == 0) { - /* Clear bit 16 (evidently the presence bit) */ + // Clear bit 16 (evidently the presence bit) wrmsr64(MSR_FLEX_RATIO, (msr & 0xFFFFFFFFFFFEFFFFULL)); msr = rdmsr64(MSR_FLEX_RATIO); - DBG("Unusable flex ratio detected. Patched MSR now %08x\n", bitfield(msr, 31, 0)); + DBG("CPU: Unusable flex ratio detected. Patched MSR now %08x\n", bitfield(msr, 31, 0)); } else { @@ -592,7 +598,7 @@ } } //valv: to be uncommented if Remarq.1 didn't stick - /*if (bus_ratio_max > 0) bus_ratio = flex_ratio;*/ + //if (bus_ratio_max > 0) bus_ratio = flex_ratio; p->CPU.MaxRatio = max_ratio; p->CPU.MinRatio = min_ratio; @@ -606,9 +612,9 @@ msr = rdmsr64(MSR_IA32_PERF_STATUS); DBG("msr(%d): ia32_perf_stat 0x%08x\n", __LINE__, bitfield(msr, 31, 0)); currcoef = bitfield(msr, 12, 8); // Bungo: reverted to 2263 state because of wrong old CPUs freq. calculating - /* Non-integer bus ratio for the max-multi*/ + // Non-integer bus ratio for the max-multi maxdiv = bitfield(msr, 46, 46); - /* Non-integer bus ratio for the current-multi (undocumented)*/ + // Non-integer bus ratio for the current-multi (undocumented) currdiv = bitfield(msr, 14, 14); // This will always be model >= 3 @@ -619,8 +625,8 @@ } else { - /* On lower models, currcoef defines TSC freq */ - /* XXX */ + // On lower models, currcoef defines TSC freq + // XXX maxcoef = currcoef; } @@ -753,8 +759,8 @@ if (!fsbFrequency) { fsbFrequency = (DEFAULT_FSB * 1000); + DBG("CPU: fsbFrequency = 0! using the default value for FSB!\n"); cpuFrequency = tscFrequency; - DBG("0 ! using the default value for FSB !\n"); } DBG("cpu freq = 0x%016llxn", timeRDTSC() * 20); Index: trunk/i386/libsaio/pci_setup.c =================================================================== --- trunk/i386/libsaio/pci_setup.c (revision 2572) +++ trunk/i386/libsaio/pci_setup.c (revision 2573) @@ -44,7 +44,7 @@ } break; - case PCI_CLASS_NETWORK_ETHERNET: + case PCI_CLASS_NETWORK_ETHERNET: if (do_eth_devprop) { set_eth_builtin(current); Index: trunk/i386/libsaio/smbios_decode.c =================================================================== --- trunk/i386/libsaio/smbios_decode.c (revision 2572) +++ trunk/i386/libsaio/smbios_decode.c (revision 2573) @@ -192,8 +192,7 @@ /*===== 7.18.2 ====*/ -static const char * -SMBMemoryDeviceTypes[] = +static const char *SMBMemoryDeviceTypes[] = { "RAM", /* 00h Undefined */ "RAM", /* 01h Other */ @@ -220,7 +219,8 @@ "RAM", /* 16h unused */ "RAM", /* 17h unused */ "DDR3", /* 18h DDR3, chosen in [5776134] */ - "FBD2" /* 19h FBD2 */ + "FBD2", /* 19h FBD2 */ + "DDR4" /* 1Ah DDR4 */ }; static const int kSMBMemoryDeviceTypeCount = sizeof(SMBMemoryDeviceTypes) / sizeof(SMBMemoryDeviceTypes[0]); @@ -240,7 +240,7 @@ } return str; -}; +} void printHeader(SMBStructHeader *structHeader) { @@ -534,6 +534,9 @@ DBG("\tPart Number: %s\n", SMBStringForField(structHeader, ((SMBMemoryDevice *)structHeader)->partNumber, neverMask)); // Rank: // Configured Clock Speed: +// Minimum Voltage: +// Maximum Voltage: +// Configured Voltage: DBG("\n"); } Index: trunk/i386/libsaio/hpet.c =================================================================== --- trunk/i386/libsaio/hpet.c (revision 2572) +++ trunk/i386/libsaio/hpet.c (revision 2573) @@ -68,7 +68,9 @@ lpc_controllers[i].name, lpc_dev->vendor_id, lpc_dev->device_id, rcba); if (rcba == 0) + { printf(" RCBA disabled; cannot force enable HPET\n"); + } else { val = REG32(rcba, 0x3404); @@ -91,7 +93,9 @@ // verify if the job is done val = REG32(rcba, 0x3404); if (!(val & 0x80)) + { printf(" Failed to force enable HPET\n"); + } } break; } Index: trunk/i386/libsaio/pci.h =================================================================== --- trunk/i386/libsaio/pci.h (revision 2572) +++ trunk/i386/libsaio/pci.h (revision 2573) @@ -201,8 +201,8 @@ #define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02 /* Below 1M [obsolete] */ #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04 /* 64 bit address */ #define PCI_BASE_ADDRESS_MEM_PREFETCH 0x08 /* prefetchable? */ -#define PCI_BASE_ADDRESS_MEM_MASK (~(pciaddr_t)0x0f) -#define PCI_BASE_ADDRESS_IO_MASK (~(pciaddr_t)0x03) +#define PCI_BASE_ADDRESS_MEM_MASK (~(uint32_t)0x0f) +#define PCI_BASE_ADDRESS_IO_MASK (~(uint32_t)0x03) /* bit 1 is reserved if address_space = 1 */ /* Header type 0 (normal devices) */ @@ -211,7 +211,7 @@ #define PCI_SUBSYSTEM_ID 0x2e #define PCI_ROM_ADDRESS 0x30 /* Bits 31..11 are address, 10..1 reserved */ #define PCI_ROM_ADDRESS_ENABLE 0x01 -#define PCI_ROM_ADDRESS_MASK (~(pciaddr_t)0x7ff) +#define PCI_ROM_ADDRESS_MASK (~(uint32_t)0x7ff) #define PCI_CAPABILITY_LIST 0x34 /* Offset of first capability list entry */ Index: trunk/i386/boot2/drivers.c =================================================================== --- trunk/i386/boot2/drivers.c (revision 2572) +++ trunk/i386/boot2/drivers.c (revision 2573) @@ -159,7 +159,8 @@ gTempSpec = malloc( 4096 ); gFileName = malloc( 4096 ); - if ( !gExtensionsSpec || !gDriverSpec || !gFileSpec || !gTempSpec || !gFileName ) { + if ( !gExtensionsSpec || !gDriverSpec || !gFileSpec || !gTempSpec || !gFileName ) + { stop("InitDriverSupport error"); } @@ -499,9 +500,12 @@ do{ // Save the driver path. - if(name) { + if(name) + { snprintf(gFileSpec, 4096, "%s/%s/%s", dirSpec, name, (bundleType == kCFBundleType2) ? "Contents/MacOS/" : ""); - } else { + } + else + { snprintf(gFileSpec, 4096, "%s/%s", dirSpec, (bundleType == kCFBundleType2) ? "Contents/MacOS/" : ""); } executablePathLength = strlen(gFileSpec) + 1; @@ -512,15 +516,19 @@ } strcpy(tmpExecutablePath, gFileSpec); - if(name) { + if(name) + { snprintf(gFileSpec, 4096, "%s/%s", dirSpec, name); - } else { + } + else + { snprintf(gFileSpec, 4096, "%s", dirSpec); } bundlePathLength = strlen(gFileSpec) + 1; tmpBundlePath = malloc(bundlePathLength); - if (tmpBundlePath == 0) { + if (tmpBundlePath == 0) + { break; } @@ -528,19 +536,24 @@ // Construct the file spec to the plist, then load it. - if(name) { + if(name) + { snprintf(gFileSpec, 4096, "%s/%s/%sInfo.plist", dirSpec, name, (bundleType == kCFBundleType2) ? "Contents/" : ""); - } else { + } + else + { snprintf(gFileSpec, 4096, "%s/%sInfo.plist", dirSpec, (bundleType == kCFBundleType2) ? "Contents/" : ""); } length = LoadFile(gFileSpec); - if (length == -1) { + if (length == -1) + { break; } length = length + 1; buffer = malloc(length); - if (buffer == 0) { + if (buffer == 0) + { break; } strlcpy(buffer, (char *)kLoadAddr, length); @@ -566,7 +579,8 @@ module->bundlePathLength = bundlePathLength; module->plistAddr = malloc(length); - if ((module->executablePath == 0) || (module->bundlePath == 0) || (module->plistAddr == 0)) { + if ((module->executablePath == 0) || (module->bundlePath == 0) || (module->plistAddr == 0)) + { break; } Index: trunk/i386/boot2/modules.c =================================================================== --- trunk/i386/boot2/modules.c (revision 2572) +++ trunk/i386/boot2/modules.c (revision 2573) @@ -1,5 +1,5 @@ /* - * Copyright 2010 Evan Lojewski. All rights reserved. + * Copyright 2010-2015 Evan Lojewski. All rights reserved. * */ #include "boot.h" @@ -33,9 +33,9 @@ static UInt64 textSection = 0; /** Internal symbols, however there are accessor methods **/ -moduleHook_t* moduleCallbacks = NULL; -moduleList_t* loadedModules = NULL; -symbolList_t* moduleSymbols = NULL; +moduleHook_t *moduleCallbacks = NULL; +moduleList_t *loadedModules = NULL; +symbolList_t *moduleSymbols = NULL; unsigned int (*lookup_symbol)(const char*) = NULL; char *strrchr(const char *s, int c) @@ -142,9 +142,9 @@ return retVal; } -void start_built_in_module(const char* name, - const char* author, - const char* description, +void start_built_in_module(const char *name, + const char *author, + const char *description, UInt32 version, UInt32 compat, void(*start_function)(void)) Index: trunk/i386/boot2/modules.h =================================================================== --- trunk/i386/boot2/modules.h (revision 2572) +++ trunk/i386/boot2/modules.h (revision 2573) @@ -1,6 +1,6 @@ /* * Module Loading functionality - * Copyright 2009 Evan Lojewski. All rights reserved. + * Copyright 2009-2015 Evan Lojewski. All rights reserved. * */ @@ -14,11 +14,11 @@ #define MODULE_PATH "/Extra/modules/" -#define SYMBOLS_MODULE "Symbols.dylib" -#define SYMBOLS_AUTHOR "Chameleon" -#define SYMBOLS_DESCRIPTION "Chameleon symbols for linking" -#define SYMBOLS_VERSION 0 -#define SYMBOLS_COMPAT 0 +#define SYMBOLS_MODULE "Symbols.dylib" +#define SYMBOLS_AUTHOR "Chameleon" +#define SYMBOLS_DESCRIPTION "Chameleon symbols for linking" +#define SYMBOLS_VERSION 0 +#define SYMBOLS_COMPAT 0 #define VOID_SYMBOL "dyld_void_start" @@ -26,9 +26,9 @@ typedef struct symbolList_t { - char* symbol; - UInt64 addr; - struct symbolList_t* next; + char *symbol; + UInt64 addr; + struct symbolList_t *next; } symbolList_t; typedef struct callbackList_t @@ -46,12 +46,12 @@ typedef struct modulesList_t { - const char* name; - const char* author; - const char* description; - UInt32 version; - UInt32 compat; - struct modulesList_t* next; + const char *name; + const char *author; + const char *description; + UInt32 version; + UInt32 compat; + struct modulesList_t *next; } moduleList_t; @@ -59,11 +59,11 @@ int init_module_system(); void load_all_modules(); -void start_built_in_module(const char* name, - const char* author, - const char* description, - UInt32 version, - UInt32 compat, +void start_built_in_module(const char *name, + const char *author, + const char *description, + UInt32 version, + UInt32 compat, void(*start_function)(void)); int load_module(char* module); Index: trunk/i386/boot2/options.c =================================================================== --- trunk/i386/boot2/options.c (revision 2572) +++ trunk/i386/boot2/options.c (revision 2573) @@ -1104,8 +1104,10 @@ // New behavior: // Switch between text & graphic interfaces // Only Permitted if started in graphics interface - if (useGUI) { - if (bootArgs->Video.v_display != VGA_TEXT_MODE) { + if (useGUI) + { + if (bootArgs->Video.v_display != VGA_TEXT_MODE) + { setVideoMode(VGA_TEXT_MODE, 0); setCursorPosition(0, 0, 0); @@ -1121,7 +1123,8 @@ nextRow = kMenuTopRow; showPrompt = true; - if (gDeviceCount) { + if (gDeviceCount) + { printf("Use \30\31 keys to select the startup volume."); showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems); nextRow += MIN(gDeviceCount, kMenuMaxItems) + 3; @@ -1130,7 +1133,9 @@ showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); showBootPrompt(nextRow, showPrompt); //changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 ); - } else { + } + else + { gui.redraw = true; setVideoMode(GRAPHICS_MODE, 0); updateVRAM(); @@ -1518,7 +1523,7 @@ void showTextBuffer(char *buf_orig, int size) { char *bp; - char* buf; + char *buf; int line; int line_offset; int c; Index: trunk/i386/modules/Resolution/915resolution.c =================================================================== --- trunk/i386/modules/Resolution/915resolution.c (revision 2572) +++ trunk/i386/modules/Resolution/915resolution.c (revision 2573) @@ -17,15 +17,13 @@ void patchVideoBios() -{ +{ UInt32 x = 0, y = 0, bp = 0; verbose("Resolution:\n"); getResolution(&x, &y, &bp); - if (x != 0 && - y != 0 && - bp != 0) + if (x != 0 && y != 0 && bp != 0) { vbios_map * map; @@ -33,11 +31,11 @@ if(map) { unlock_vbios(map); - + set_mode(map, x, y, bp, 0, 0); - + relock_vbios(map); - + close_vbios(map); } } @@ -190,7 +188,7 @@ case 0x01048086: // 2nd Generation Core Processor Family DRAM Controller case 0x01088086: // Xeon E3-1200 2nd Generation Core Processor Family DRAM Controller case 0x010c8086: // Xeon E3-1200 2nd Generation Core Processor Family DRAM Controller - + case 0x01508086: // 3rd Generation Core Processor Family DRAM Controller case 0x01548086: // 3rd Generation Core Processor Family DRAM Controller case 0x01588086: // 3rd Generation Core Processor Family DRAM Controller @@ -199,7 +197,6 @@ type = CT_CORE_PROC; break; - default: if((id & 0x0000FFFF) == 0x00008086) // Intel chipset { @@ -215,6 +212,7 @@ } break; } + return type; } @@ -236,6 +234,7 @@ return ptr; } +char detect_bios_type(vbios_map * map, char modeline, int entry_size); char detect_bios_type(vbios_map * map, char modeline, int entry_size) { UInt32 i; @@ -256,8 +255,8 @@ r2 = map->mode_table[i].resolution; } } - - /*printf("r1 = %d r2 = %d\n", r1, r2);*/ + + //printf("r1 = %d r2 = %d\n", r1, r2); } return (r2-r1-6) % entry_size == 0; @@ -275,6 +274,10 @@ { UInt32 z; vbios_map * map = malloc(sizeof(vbios_map)); + if (!map) + { + return 0; + } for(z=0; zmode_table_size = std_vesa->sHeader.usStructureSize - sizeof(ATOM_COMMON_TABLE_HEADER); - if (!detect_ati_bios_type(map)) map->bios = BT_ATI_2; - - if (map->bios == BT_ATI_1) { + if (!detect_ati_bios_type(map)) + { + map->bios = BT_ATI_2; + } + + if (map->bios == BT_ATI_1) + { verbose(", BT_ATI_1\n"); } else { verbose(", BT_ATI_2\n"); } } - else { + else + { /* * check if we have NVIDIA @@ -365,7 +373,7 @@ NV_VESA_TABLE * std_vesa; int i = 0; - + while (i < 0x300) { //We don't need to look for the table in the whole bios, the 768 first bytes only if (( map->bios_ptr[i] == 0x44) @@ -400,28 +408,26 @@ } } - + /* * check if we have Intel */ - + /*if (map->chipset == CT_UNKNOWN && memmem(map->bios_ptr, VBIOS_SIZE, INTEL_SIGNATURE, strlen(INTEL_SIGNATURE))) { printf( "Intel chipset detected. However, 915resolution was unable to determine the chipset type.\n"); - + printf("Chipset Id: %x\n", map->chipset_id); - + printf("Please report this problem to stomljen@yahoo.com\n"); - + close_vbios(map); return 0; }*/ - + /* * check for others */ - - /* * Figure out where the mode table is */ @@ -443,8 +449,8 @@ p++; } - - if (map->mode_table == 0) + + if (map->mode_table == 0) { close_vbios(map); return 0; @@ -503,7 +509,7 @@ void unlock_vbios(vbios_map * map) { - + map->unlocked = TRUE; switch (map->chipset) { @@ -557,6 +563,8 @@ outb(CONFIG_MECH_ONE_DATA + 1, 0x33); outb(CONFIG_MECH_ONE_DATA + 2, 0x33); break; + default: + break; } #if DEBUG @@ -614,6 +622,7 @@ outl(CONFIG_MECH_ONE_ADDR, 0x80000080); outb(CONFIG_MECH_ONE_DATA + 1, map->b1); outb(CONFIG_MECH_ONE_DATA + 2, map->b2); + default: break; } @@ -647,7 +656,7 @@ mode->v_sync_offset = (edidInfo[65] & 0x0C) | ((edidInfo[64] & 0x0C) >> 2); mode->v_sync_width = ((edidInfo[65] & 0x3) << 2) | (edidInfo[64] & 0x03); */ - + free( edidInfo ); return 0; @@ -666,7 +675,7 @@ vfreq = vbl * freq; hbl = 16 * (int)(x * (30.0 - 300000.0 / vfreq) / + (70.0 + 300000.0 / vfreq) / 16.0 + 0.5); - + *vsyncstart = y; *vsyncend = y + 3; *vblank = vbl - 1; @@ -694,8 +703,9 @@ verbose("BT_1 patched.\n"); vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution); - if (bp) { - map->mode_table[i].bits_per_pixel = bp; + if (bp) + { + map->mode_table[i].bits_per_pixel = (uint8_t)bp; } res->x2 = (htotal?(((htotal-x) >> 8) & 0x0f) : (res->x2 & 0x0f)) | ((x >> 4) & 0xf0); @@ -704,28 +714,31 @@ res->y2 = (vtotal?(((vtotal-y) >> 8) & 0x0f) : (res->y2 & 0x0f)) | ((y >> 4) & 0xf0); res->y1 = (y & 0xff); if (htotal) + { res->x_total = ((htotal-x) & 0xff); - + } if (vtotal) + { res->y_total = ((vtotal-y) & 0xff); - + } break; } case BT_2: { vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution); - res->xchars = x / 8; - res->ychars = y / 16 - 1; + res->xchars = (uint8_t)(x / 8); + res->ychars = (uint8_t)(y / 16 - 1); xprev = res->modelines[0].x1; yprev = res->modelines[0].y1; for(j=0; j < 3; j++) { vbios_modeline_type2 * modeline = &res->modelines[j]; - if (modeline->x1 == xprev && modeline->y1 == yprev) { - modeline->x1 = modeline->x2 = x-1; - modeline->y1 = modeline->y2 = y-1; + if (modeline->x1 == xprev && modeline->y1 == yprev) + { + modeline->x1 = modeline->x2 = (uint16_t)(x-1); + modeline->y1 = modeline->y2 = (uint16_t)(y-1); gtf_timings(x, y, freqs[j], &modeline->clock, &modeline->hsyncstart, &modeline->hsyncend, @@ -733,14 +746,21 @@ &modeline->vsyncend, &modeline->vblank); if (htotal) - modeline->htotal = htotal; + { + modeline->htotal = (uint16_t)htotal; + } else + { modeline->htotal = modeline->hblank; - + } if (vtotal) - modeline->vtotal = vtotal; + { + modeline->vtotal = (uint16_t)vtotal; + } else + { modeline->vtotal = modeline->vblank; + } } } verbose("BT_1 patched.\n"); @@ -753,28 +773,37 @@ xprev = res->modelines[0].x1; yprev = res->modelines[0].y1; - for (j=0; j < 3; j++) { + for (j=0; j < 3; j++) + { vbios_modeline_type3 * modeline = &res->modelines[j]; - if (modeline->x1 == xprev && modeline->y1 == yprev) { - modeline->x1 = modeline->x2 = x-1; - modeline->y1 = modeline->y2 = y-1; + if (modeline->x1 == xprev && modeline->y1 == yprev) + { + modeline->x1 = modeline->x2 = (uint16_t)(x-1); + modeline->y1 = modeline->y2 = (uint16_t)(y-1); gtf_timings(x, y, freqs[j], &modeline->clock, &modeline->hsyncstart, &modeline->hsyncend, &modeline->hblank, &modeline->vsyncstart, &modeline->vsyncend, &modeline->vblank); if (htotal) - modeline->htotal = htotal; + { + modeline->htotal = (uint16_t)htotal; + } else + { modeline->htotal = modeline->hblank; + } if (vtotal) - modeline->vtotal = vtotal; + { + modeline->vtotal = (uint16_t)vtotal; + } else + { modeline->vtotal = modeline->vblank; - - modeline->timing_h = y-1; - modeline->timing_v = x-1; + } + modeline->timing_h = (uint16_t)(y-1); + modeline->timing_v = (uint16_t)(x-1); } } verbose("BT_3 patched.\n"); @@ -787,8 +816,9 @@ ATOM_MODE_TIMING *mode_timing = (ATOM_MODE_TIMING *) map->ati_mode_table; - //if (mode.pixel_clock && (mode.h_active == x) && (mode.v_active == y) && !force) { - if (!getMode(&mode)) { + //if (mode.pixel_clock && (mode.h_active == x) && (mode.v_active == y) && !force){ + if (!getMode(&mode)) + { verbose("\n Edid detailed timing descriptor found: %dx%d\n vbios mode 0 patched!\n", mode.h_active, mode.v_active); mode_timing->usCRTC_H_Total = mode.h_active + mode.h_blanking; mode_timing->usCRTC_H_Disp = mode.h_active; @@ -801,7 +831,9 @@ mode_timing->usCRTC_V_SyncWidth = mode.v_sync_width; mode_timing->usPixelClock = mode.pixel_clock; - } else { + } + else + { verbose(" Edid not found or invalid - vbios not patched!\n"); } /*else @@ -825,7 +857,7 @@ mode_timing->usPixelClock = modeline.clock; }*/ - + break; } case BT_ATI_2: @@ -836,7 +868,8 @@ ATOM_DTD_FORMAT *mode_timing = (ATOM_DTD_FORMAT *) map->ati_mode_table; /*if (mode.pixel_clock && (mode.h_active == x) && (mode.v_active == y) && !force) {*/ - if (!getMode(&mode)) { + if (!getMode(&mode)) + { verbose("\n Edid detailed timing descriptor found: %dx%d\n vbios mode 0 patched!\n", mode.h_active, mode.v_active); mode_timing->usHBlanking_Time = mode.h_blanking; mode_timing->usHActive = mode.h_active; @@ -849,7 +882,9 @@ mode_timing->usVSyncWidth = mode.v_sync_width; mode_timing->usPixClk = mode.pixel_clock; - } else { + } + else + { verbose(" Edid not found or invalid - vbios not patched!\n"); } /*else @@ -862,30 +897,29 @@ &modeline.vsyncend, &modeline.vblank, 0); mode_timing->usHBlanking_Time = modeline.hblank; - + mode_timing->usHActive = x; - + mode_timing->usHSyncOffset = modeline.hsyncstart - x; - + mode_timing->usHSyncWidth = modeline.hsyncend - modeline.hsyncstart; - + - + mode_timing->usVBlanking_Time = modeline.vblank; - + mode_timing->usVActive = y; - + mode_timing->usVSyncOffset = modeline.vsyncstart - y; - + mode_timing->usVSyncWidth = modeline.hsyncend - modeline.hsyncstart; - + - + mode_timing->usPixClk = modeline.clock; - + }*/ - - + mode_timing->usHActive = x; + mode_timing->usHSyncOffset = modeline.hsyncstart - x; + mode_timing->usHSyncWidth = modeline.hsyncend - modeline.hsyncstart; + + mode_timing->usVBlanking_Time = modeline.vblank; + mode_timing->usVActive = y; + mode_timing->usVSyncOffset = modeline.vsyncstart - y; + mode_timing->usVSyncWidth = modeline.hsyncend - modeline.hsyncstart; + + mode_timing->usPixClk = modeline.clock; + }*/ + break; } case BT_NVDA: { verbose("BT_NVDA"); edid_mode mode; - NV_MODELINE *mode_timing = (NV_MODELINE *) map->nv_mode_table; /*if (mode.pixel_clock && (mode.h_active == x) && (mode.v_active == y) && !force) {*/ - if (!getMode(&mode)) { + if (!getMode(&mode)) + { verbose("\n Edid detailed timing descriptor found: %dx%d\n vbios mode %d patched!\n", mode.h_active, mode.v_active, i); mode_timing[i].usH_Total = mode.h_active + mode.h_blanking; mode_timing[i].usH_Active = mode.h_active; @@ -898,28 +932,29 @@ mode_timing[i].usV_SyncEnd = mode.v_active + mode.v_sync_offset + mode.v_sync_width; mode_timing[i].usPixel_Clock = mode.pixel_clock; - } else { + } + else + { verbose(" Edid not found or invalid - vbios not patched!\n"); } /*else { vbios_modeline_type2 modeline; - cvt_timings(x, y, freqs[0], &modeline.clock, &modeline.hsyncstart, &modeline.hsyncend, &modeline.hblank, &modeline.vsyncstart, &modeline.vsyncend, &modeline.vblank, 0); - + mode_timing[i].usH_Total = x + modeline.hblank - 1; mode_timing[i].usH_Active = x; mode_timing[i].usH_SyncStart = modeline.hsyncstart - 1; mode_timing[i].usH_SyncEnd = modeline.hsyncend - 1; - + mode_timing[i].usV_Total = y + modeline.vblank - 1; mode_timing[i].usV_Active = y; mode_timing[i].usV_SyncStart = modeline.vsyncstart - 1; mode_timing[i].usV_SyncEnd = modeline.vsyncend - 1; - + mode_timing[i].usPixel_Clock = modeline.clock; }*/ break; @@ -929,9 +964,11 @@ verbose(" Unknown - vbios not patched\n"); break; } + default: + break; } // } // } } -#endif // _RESOLUTION_H_ \ No newline at end of file +#endif // _RESOLUTION_H_ Index: trunk/i386/modules/Resolution/edid.c =================================================================== --- trunk/i386/modules/Resolution/edid.c (revision 2572) +++ trunk/i386/modules/Resolution/edid.c (revision 2573) @@ -147,6 +147,10 @@ /* checksum passed, everything's good */ err = 1; } + else + { + msglog(" edid_checksum error "); + } return err; } @@ -165,6 +169,11 @@ err = 0; } + if (err == 0) + { + msglog(" edid_check_header error "); + } + return err; } //------------------------------------------------------------------------ @@ -179,11 +188,12 @@ int edid_is_timing_block(unsigned char *block) { - if ((block[0] != 0x00) || (block[1] != 0x00) || - (block[2] != 0x00) || (block[4] != 0x00)) + if ((block[0] != 0x00) || (block[1] != 0x00) || (block[2] != 0x00) || (block[4] != 0x00)) + { return 1; - else + } else { return 0; + } } //---------------------------------------------------------------------------------- @@ -191,13 +201,19 @@ { int i; unsigned char *block; + + msglog(" Parse Edid:"); + if(!verifyEDID((unsigned char *)edid)) + { + msglog(" error\n"); + return 0; + } - if(!verifyEDID((unsigned char *)edid)) return 0; - block = (unsigned char *)edid + DETAILED_TIMING_DESCRIPTIONS_START; //54 for (i = 0; i < 4; i++, block += DETAILED_TIMING_DESCRIPTION_SIZE) { if (edid_is_timing_block(block)) { + msglog(" descriptor block %d is timing descriptor ", i); var->h_active = H_ACTIVE; var->v_active = V_ACTIVE; var->h_sync_offset = H_SYNC_OFFSET; @@ -237,7 +253,7 @@ void getResolution(UInt32* x, UInt32* y, UInt32* bp) { // int val; - static UInt32 xResolution, yResolution, bpResolution; + static UInt32 xResolution, yResolution, bpResolution = 32; // assume 32bits /* if(getIntForKey(kScreenWidth, &val, &bootInfo->chameleonConfig)) { @@ -249,16 +265,15 @@ yResolution = val; } */ - bpResolution = 32; // assume 32bits - - if(!xResolution || !yResolution || !bpResolution) { - char* edidInfo = readEDID(); - if(!edidInfo) return; - + if(!edidInfo) + { + return; + } + edid_mode mode; // TODO: check *all* resolutions reported and either use the highest, or the native resolution (if there is a flag for that) //xResolution = edidInfo[56] | ((edidInfo[58] & 0xF0) << 4); @@ -270,7 +285,8 @@ xResolution = DEFAULT_SCREEN_WIDTH; yResolution = DEFAULT_SCREEN_HEIGHT; } - else { + else + { xResolution = mode.h_active; yResolution = mode.v_active; } @@ -306,6 +322,7 @@ *y = yResolution; *bp = bpResolution; + msglog("Best mode: %dx%dx%d\n", *x, *y, *bp); } char* readEDID() @@ -326,18 +343,18 @@ bzero( edidInfo, EDID_BLOCK_SIZE); status = getEDID(edidInfo, blocks_left); - + /* msglog("Buffer location: 0x%X status: %d\n", SEG(edidInfo) << 16 | OFF(edidInfo), status); - + int j, i; - for (j = 0; j < 8; j++) { + for (j = 0; j < 8; j++) + { for(i = 0; i < 16; i++) msglog(" 0x%02X", edidInfo[((i+1) * (j + 1)) - 1]); msglog("\n"); } */ - - + if(status == 0) { //if( edidInfo[0] == 0x00 || edidInfo[0] == 0xFF) @@ -346,10 +363,9 @@ { blocks_left--; int reported = edidInfo[ EDID_V1_BLOCKS_TO_GO_OFFSET ]; - + if ( reported > blocks_left ) { - msglog("EDID claims %d more blocks left\n", reported); } @@ -382,28 +398,28 @@ return 0; } } - blocks_left = 0; + blocks_left = 0; } while(blocks_left); char* ret = malloc(sizeof(edidInfo)); + if (!ret) + { + return 0; + } memcpy(ret, edidInfo, sizeof(edidInfo)); return ret; } - int getEDID( void * edidBlock, UInt8 block) { biosBuf_t bb; - bzero(&bb, sizeof(bb)); - bb.intno = 0x10; - bb.eax.rr = 0x4F15; + bb.intno = 0x10; + bb.eax.rr = 0x4F15; bb.ebx.r.l= 0x01; bb.edx.rr = block; - - bb.es = SEG( edidBlock ); - bb.edi.rr = OFF( edidBlock ); - - bios( &bb ); - return(bb.eax.r.h); + bb.es = SEG( edidBlock ); + bb.edi.rr = OFF( edidBlock ); + bios( &bb ); + return(bb.eax.r.h); } Index: trunk/i386/modules/Resolution/915resolution.h =================================================================== --- trunk/i386/modules/Resolution/915resolution.h (revision 2572) +++ trunk/i386/modules/Resolution/915resolution.h (revision 2573) @@ -124,10 +124,10 @@ typedef struct { - char *base; - ATOM_ROM_HEADER *AtomRomHeader; - unsigned short *MasterCommandTables; - unsigned short *MasterDataTables; + char *base; + ATOM_ROM_HEADER *AtomRomHeader; + unsigned short *MasterCommandTables; + unsigned short *MasterDataTables; } bios_tables_t; typedef struct { @@ -157,8 +157,8 @@ UInt16 hsyncstart; UInt16 hsyncend; UInt16 y1; - UInt16 vtotal; - UInt16 y2; + UInt16 vtotal; + UInt16 y2; UInt16 vblank; UInt16 vsyncstart; UInt16 vsyncend; @@ -198,7 +198,7 @@ typedef struct { unsigned char unknown[6]; - vbios_modeline_type3 modelines[]; + vbios_modeline_type3 modelines[]; } __attribute__((packed)) vbios_resolution_type3; typedef struct { @@ -222,8 +222,6 @@ UInt8 unlocked; } vbios_map; - - vbios_map * open_vbios(chipset_type); void close_vbios (vbios_map*); void unlock_vbios(vbios_map*); Index: trunk/i386/util/dyldsymboltool.c =================================================================== --- trunk/i386/util/dyldsymboltool.c (revision 2572) +++ trunk/i386/util/dyldsymboltool.c (revision 2573) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Evan Lojewski. All rights reserved. + * Copyright (c) 2010-2015 Evan Lojewski. All rights reserved. * * dyldsymboltool * @@ -22,18 +22,18 @@ typedef struct symbols_dylib { - struct mach_header header; + struct mach_header header; struct dylib_command dylib_info; - char module_name[sizeof(DYLIB_NAME)]; + char module_name[sizeof(DYLIB_NAME)]; struct symtab_command symtab; } symbols_dylib_t; typedef struct symbolList_t { - char* name; - uint32_t addr; - int pos; + char *name; + uint32_t addr; + int pos; struct symbolList_t* next; } symbolList_t; @@ -116,9 +116,9 @@ //exit(1); } - else - { - add_symbol(&symbols, START_SYMBOL, start_addr); + else + { + add_symbol(&symbols, START_SYMBOL, start_addr); } /* Header command info */ @@ -136,7 +136,7 @@ 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.current_version = 0; // TODO dylib.dylib_info.dylib.compatibility_version = 0; // TODO @@ -153,9 +153,8 @@ 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[argc-1], "w"); fwrite(&dylib, sizeof(dylib) /* Sizeof header + module name */ , 1, outfile); @@ -183,7 +182,7 @@ } fwrite(orig, - dylib.symtab.stroff + // Sizeof symbol nlists + dylib.symtab.stroff + // Sizeof symbol nlists dylib.symtab.strsize - sizeof(dylib) + 1 // sizeof symbol strings , 1, outfile); @@ -193,7 +192,7 @@ exit(0); } -int num_symbols(symbolList_t* list) +int num_symbols(symbolList_t *list) { int retVal = 0; while(list) @@ -204,7 +203,7 @@ return retVal; } -int string_size(symbolList_t* list) +int string_size(symbolList_t *list) { int retVal = 0; while(list) @@ -216,7 +215,7 @@ } -void add_symbol(symbolList_t** list, char* name, uint32_t addr) +void add_symbol(symbolList_t **list, char *name, uint32_t addr) { symbolList_t* entry = malloc(sizeof(symbolList_t)); entry->next = (*list);