Index: trunk/coding_standards.txt =================================================================== --- trunk/coding_standards.txt (revision 0) +++ trunk/coding_standards.txt (revision 23) @@ -0,0 +1,83 @@ +Coding Standard rev. 0 (First Draft) + +1. Indentation + having seen most indentation styles going from 2 to 8 spaces, I would suggest a indentation of 4 spaces. + +2. Comments +I see here two main differents cases: +function description comments and one-line code quite comments + +For functions documentation, I suggest to use this syntax +/** + * + */ +Note the use of /** that will make future html auto-documentation easier (i.e: Doxygen at least recognize this marker) + +for punctual, short code comment, let's use: +// +3) #define at top of document +4) Global vars right below #include / #define (notation: gLobal) +Note that global vars and static vars should be avoided as much as possible in favor of local variables use, get/set functions (properties). + +5) No curly brackets for single lines + +6) else +{ + .... +} + +instead of: + +else { + .... +} + +7) if +{ + .... +} +instead of: + +if { + .... +} + +8) fall through code (using indention) or bail out early (using returns)? +Using early bail out for preconditions early in the function code, +use common sense to avoid as an example more than 4 imbricated if() constructions. +In the later case, consider decomposing your function in more manageable primitives. + +9) Spaces/readability i.e. not: if (fd<0) +but: if (fd < 0) + +10. types, variables, functions, naming +non const variables should follow the (currently mostly used) CamelCase convention: +int myVariableIsFine; +instead of : +int my_variable_is_ok; + +Functions should follow the same conventions except for standard c lib related functions. +Types should share the same convention but start with a Captial letter instead of lower case. + +11. Please make sure you extensively initialize variables: +avoid as much as possible: +int myVar +... +myVar = 10; + +but use instead: +int myVar = 10; + +12. const values: +const int MY_CONST_VARIABLE=42; is also ok for me, depending on the context of use. +or +const int MyConstVariable = 42; (with a Capital first letter) + +13. macro definitions should follow this convention: +#define MY_HANDY_MACROS_PSEUDO_FUNC() ... + +14. Macros use should be limited to really special cases where they bring real value (like special optimization cases) +Most of the time inlining a function is much better than the use of macros + +15. Don't optimize your code blindly, always favor readability when in doubt. +Very often, optimization is not necessary where you think it is, think about the bubble sort algorithm, where people would code it in assembly, where a heap or quick sort algorithm would be much more efficient (n log(n) instead of quadratic complexity), as an example when values count to be sorted get high. Index: trunk/doc/BootHelp.txt =================================================================== --- trunk/doc/BootHelp.txt (revision 22) +++ trunk/doc/BootHelp.txt (revision 23) @@ -51,6 +51,9 @@ "Hide Partition" Remove unwanted partition(s) from the boot menu. =hd(x,y) [hd(m,n)] + "Rename Partition" Rename partition(s) for the boot menu. + =hd(x,y) [;hd(m,n) ...] + GUI=No Disable the GUI (enabled by default). "Boot Banner"=Yes|No Show boot banner in GUI mode (enabled by default). "Legacy Logo"=Yes|No Use the legacy grey apple logo (disabled by default). Index: trunk/CHANGES =================================================================== --- trunk/CHANGES (revision 0) +++ trunk/CHANGES (revision 23) @@ -0,0 +1,15 @@ +- Added JrCs modified convention name change to coding_standards +- Now malloc (ex. MALLOC in Asere patch) is renamed malloc(size) and is an alias + to safe_malloc(size, file, line) with _FILE_ and _LINE_ prerocessor definitions +- Added a new 'Rename Partition Feature', now permitting to rename partition + like 'System reserved' to a more meaningful name +- Added SystemID option permitting to change the System UUID to a fixed value. +- Added the PciRoot autodetection feature imported from pcefi10.5 +- Added automatic "system-id" injection from dmi bios, also compatible + with SystemID boot option and former SMUUID from smbios,plist +- Added "system-type' automatic injection (1=Desktop) plus override possibility + with the new system-type option in bootConfig +- Added SMserial and SMproductname new options for smbios.plist +- Merged with asere patch, while keeping my fake_efi.c changes, and adding a new + stringForKey() API, also changed the DT__XXXX() set of functions + to handle const char * values instead of char*. Index: trunk/i386/libsaio/memory.c =================================================================== --- trunk/i386/libsaio/memory.c (revision 22) +++ trunk/i386/libsaio/memory.c (revision 23) @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. - * - * @APPLE_LICENSE_HEADER_START@ - * - * Portions Copyright (c) 2003 Apple Computer, Inc. All Rights - * Reserved. This file contains Original Code and/or Modifications of - * Original Code as defined in and that are subject to the Apple Public - * Source License Version 2.0 (the "License"). You may not use this file - * except in compliance with the License. Please obtain a copy of the - * License at http://www.apple.com/publicsource and read it before using - * this file. - * - * The Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER - * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, - * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. - * - * @APPLE_LICENSE_HEADER_END@ - */ - -#include "sl.h" -#include "saio_internal.h" -#include "bootstruct.h" -#include "device_tree.h" - -static long gImageLastKernelAddr; - -#define kPageSize 4096 -#define RoundPage(x) ((((unsigned)(x)) + kPageSize - 1) & ~(kPageSize - 1)) - - -long -AllocateMemoryRange(char * rangeName, long start, long length, long type) -{ - char *nameBuf; - uint32_t *buffer; - - nameBuf = malloc(strlen(rangeName) + 1); - if (nameBuf == 0) return -1; - strcpy(nameBuf, rangeName); - - buffer = malloc(2 * sizeof(uint32_t)); - if (buffer == 0) return -1; - - buffer[0] = start; - buffer[1] = length; - - DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer); - - return 0; -} - -#if 0 -long -AllocateMemoryRange(char * rangeName, long start, long length, long type) -{ - if ( bootArgs->numBootDrivers < NDRIVERS ) - { - int num = bootArgs->numBootDrivers; - - bootArgs->driverConfig[num].address = start; - bootArgs->driverConfig[num].size = length; - bootArgs->driverConfig[num].type = type; - bootArgs->numBootDrivers++; - } - else - { - stop( "AllocateMemoryRange error" ); - } - return 0; -} -#endif - -long -AllocateKernelMemory( long inSize ) -{ - long addr; - - if (gImageLastKernelAddr == 0) { - gImageLastKernelAddr = RoundPage( bootArgs->kaddr + - bootArgs->ksize ); - } - addr = gImageLastKernelAddr; - gImageLastKernelAddr += RoundPage(inSize); - - if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) ) { - stop ("AllocateKernelMemory error"); - } - - bootArgs->ksize = gImageLastKernelAddr - bootArgs->kaddr; - - return addr; -} Index: trunk/i386/libsaio/freq_detect.c =================================================================== --- trunk/i386/libsaio/freq_detect.c (revision 22) +++ trunk/i386/libsaio/freq_detect.c (revision 23) @@ -1,291 +0,0 @@ -/* - * Copyright 2008 Islam Ahmed Zaid. All rights reserved. - */ - -#include "libsaio.h" -#include "freq_detect.h" - -// DFE: enable_PIT2 and disable_PIT2 come from older xnu - -/* - * Enable or disable timer 2. - * Port 0x61 controls timer 2: - * bit 0 gates the clock, - * bit 1 gates output to speaker. - */ -inline static void -enable_PIT2(void) -{ - /* Enable gate, disable speaker */ - __asm__ volatile( - " inb $0x61,%%al \n\t" - " and $0xFC,%%al \n\t" /* & ~0x03 */ - " or $1,%%al \n\t" - " outb %%al,$0x61 \n\t" - : : : "%al" ); -} - -inline static void -disable_PIT2(void) -{ - /* Disable gate and output to speaker */ - __asm__ volatile( - " inb $0x61,%%al \n\t" - " and $0xFC,%%al \n\t" /* & ~0x03 */ - " outb %%al,$0x61 \n\t" - : : : "%al" ); -} - -// DFE: set_PIT2_mode0, poll_PIT2_gate, and measure_tsc_frequency are -// roughly based on Linux code - -/* Set the 8254 channel 2 to mode 0 with the specified value. - In mode 0, the counter will initially set its gate low when the - timer expires. For this to be useful, you ought to set it high - before calling this function. The enable_PIT2 function does this. - */ -static inline void set_PIT2_mode0(uint16_t value) -{ - __asm__ volatile( - " movb $0xB0,%%al \n\t" - " outb %%al,$0x43 \n\t" - " movb %%dl,%%al \n\t" - " outb %%al,$0x42 \n\t" - " movb %%dh,%%al \n\t" - " outb %%al,$0x42" - : : "d"(value) /*: no clobber */ ); -} - -/* Returns the number of times the loop ran before the PIT2 signaled */ -static inline unsigned long poll_PIT2_gate(void) -{ - unsigned long count = 0; - unsigned char nmi_sc_val; - do { - ++count; - __asm__ volatile( - "inb $0x61,%0" - : "=q"(nmi_sc_val) /*:*/ /* no input */ /*:*/ /* no clobber */); - } while( (nmi_sc_val & 0x20) == 0); - return count; -} - -/* - * DFE: Measures the TSC frequency in Hz (64-bit) using the ACPI PM timer - */ -uint64_t measure_tsc_frequency(void) -{ - uint64_t tscStart; - uint64_t tscEnd; - uint64_t tscDelta = 0xffffffffffffffffULL; - unsigned long pollCount; - uint64_t retval = 0; - int i; - - /* Time how many TSC ticks elapse in 30 msec using the 8254 PIT - * counter 2. We run this loop 3 times to make sure the cache - * is hot and we take the minimum delta from all of the runs. - * That is to say that we're biased towards measuring the minimum - * number of TSC ticks that occur while waiting for the timer to - * expire. That theoretically helps avoid inconsistencies when - * running under a VM if the TSC is not virtualized and the host - * steals time. The TSC is normally virtualized for VMware. - */ - for(i = 0; i < 3; ++i) - { - enable_PIT2(); - set_PIT2_mode0(CALIBRATE_LATCH); - tscStart = rdtsc64(); - pollCount = poll_PIT2_gate(); - tscEnd = rdtsc64(); - /* The poll loop must have run at least a few times for accuracy */ - 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) - continue; - // tscDelta = min(tscDelta, (tscEnd - tscStart)) - if( (tscEnd - tscStart) < tscDelta ) - tscDelta = tscEnd - tscStart; - } - /* tscDelta is now the least number of TSC ticks the processor made in - * a timespan of 0.03 s (e.g. 30 milliseconds) - * Linux thus divides by 30 which gives the answer in kiloHertz because - * 1 / ms = kHz. But we're xnu and most of the rest of the code uses - * Hz so we need to convert our milliseconds to seconds. Since we're - * dividing by the milliseconds, we simply multiply by 1000. - */ - - /* Unlike linux, we're not limited to 32-bit, but we do need to take care - * that we're going to multiply by 1000 first so we do need at least some - * arithmetic headroom. For now, 32-bit should be enough. - * Also unlike Linux, our compiler can do 64-bit integer arithmetic. - */ - if(tscDelta > (1ULL<<32)) - retval = 0; - else - { - retval = tscDelta * 1000 / 30; - } - disable_PIT2(); - return retval; -} - -uint64_t tscFrequency = 0; -uint64_t fsbFrequency = 0; -uint64_t cpuFrequency = 0; - -/* - * Calculates the FSB and CPU frequencies using specific MSRs for each CPU - * - multi. is read from a specific MSR. In the case of Intel, there is: - * a max multi. (used to calculate the FSB freq.), - * and a current multi. (used to calculate the CPU freq.) - * - fsbFrequency = tscFrequency / multi - * - cpuFrequency = fsbFrequency * multi - */ - -void calculate_freq(void) -{ - uint32_t cpuid_reg[4], cpu_vendor; - uint8_t cpu_family, cpu_model, cpu_extfamily, cpu_extmodel; - uint64_t msr, flex_ratio; - uint8_t maxcoef, maxdiv, currcoef, currdiv; - - do_cpuid(0, cpuid_reg); - cpu_vendor = cpuid_reg[1]; - - do_cpuid(1, cpuid_reg); - cpu_model = bitfield(cpuid_reg[0], 7, 4); - cpu_family = bitfield(cpuid_reg[0], 11, 8); - cpu_extmodel = bitfield(cpuid_reg[0], 19, 16); - cpu_extfamily = bitfield(cpuid_reg[0], 27, 20); - - cpu_model += (cpu_extmodel << 4); - - DBG("\nCPU Model: %d - CPU Family: %d - CPU Ext. Family: %d\n", cpu_model, cpu_family, cpu_extfamily); - DBG("The booter will now attempt to read the CPU Multiplier (using RDMSR).\n"); - DBG("Press any key to continue..\n\n"); -#if DEBUG_FREQ - getc(); -#endif - - tscFrequency = measure_tsc_frequency(); - - DBG("CPU Multiplier: "); - - if((cpu_vendor == 0x756E6547 /* Intel */) && ((cpu_family == 0x06) || (cpu_family == 0x0f))) - { - if ((cpu_family == 0x06 && cpu_model >= 0x0c) || - (cpu_family == 0x0f && cpu_model >= 0x03)) - { - /* Nehalem CPU model */ - if (cpu_family == 0x06 && (cpu_model == 0x1a || cpu_model == 0x1e)) - { - msr = rdmsr64(MSR_PLATFORM_INFO); - currcoef = (msr >> 8) & 0xff; - msr = rdmsr64(MSR_FLEX_RATIO); - if ((msr >> 16) & 0x01) - { - flex_ratio = (msr >> 8) & 0xff; - if (currcoef > flex_ratio) - currcoef = flex_ratio; - } - - if (currcoef) - { - DBG("%d\n", currcoef); - fsbFrequency = (tscFrequency / currcoef); - } - cpuFrequency = tscFrequency; - } - else - { - msr = rdmsr64(IA32_PERF_STATUS); - currcoef = (msr >> 8) & 0x1f; - /* Non-integer bus ratio for the max-multi*/ - maxdiv = (msr >> 46) & 0x01; - /* Non-integer bus ratio for the current-multi (undocumented)*/ - currdiv = (msr >> 14) & 0x01; - - if ((cpu_family == 0x06 && cpu_model >= 0x0e) || - (cpu_family == 0x0f)) // This will always be model >= 3 - { - /* On these models, maxcoef defines TSC freq */ - maxcoef = (msr >> 40) & 0x1f; - } - else - { - /* On lower models, currcoef defines TSC freq */ - /* XXX */ - maxcoef = currcoef; - } - - if (maxcoef) - { - if (maxdiv) - fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1)); - else - fsbFrequency = (tscFrequency / maxcoef); - - if (currdiv) - cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2); - else - cpuFrequency = (fsbFrequency * currcoef); - DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : ""); - } - } - } - } - else if((cpu_vendor == 0x68747541 /* AMD */) && (cpu_family == 0x0f)) - { - if(cpu_extfamily == 0x00 /* K8 */) - { - msr = rdmsr64(K8_FIDVID_STATUS); - currcoef = (msr & 0x3f) / 2 + 4; - currdiv = (msr & 0x01) * 2; - } - else if(cpu_extfamily >= 0x01 /* K10+ */) - { - msr = rdmsr64(K10_COFVID_STATUS); - if(cpu_extfamily == 0x01 /* K10 */) - currcoef = (msr & 0x3f) + 0x10; - else /* K11+ */ - currcoef = (msr & 0x3f) + 0x08; - currdiv = (2 << ((msr >> 6) & 0x07)); - } - - if (currcoef) - { - if (currdiv) - { - fsbFrequency = ((tscFrequency * currdiv) / currcoef); - DBG("%d.%d\n", currcoef / currdiv, ((currcoef % currdiv) * 100) / currdiv); - } - else - { - fsbFrequency = (tscFrequency / currcoef); - DBG("%d\n", currcoef); - } - fsbFrequency = (tscFrequency / currcoef); - cpuFrequency = tscFrequency; - } - } - - if (!fsbFrequency) - { - fsbFrequency = (DEFAULT_FSB * 1000); - cpuFrequency = tscFrequency; - DBG("0 ! using the default value for FSB !\n"); - } - - DBG("TSC Frequency: %dMHz\n", tscFrequency / 1000000); - DBG("CPU Frequency: %dMHz\n", cpuFrequency / 1000000); - DBG("FSB Frequency: %dMHz\n", fsbFrequency / 1000000); - DBG("Press [Enter] to continue..\n"); -#if DEBUG_FREQ - while (getc() != 0x0d) ; -#endif -} Index: trunk/i386/libsaio/freq_detect.h =================================================================== --- trunk/i386/libsaio/freq_detect.h (revision 22) +++ trunk/i386/libsaio/freq_detect.h (revision 23) @@ -1,77 +0,0 @@ -/* - * Copyright 2008 Islam Ahmed Zaid. All rights reserved. - */ - -#ifndef __LIBSAIO_FREQ_DETECT_H -#define __LIBSAIO_FREQ_DETECT_H - -#include "libsaio.h" -#ifndef DEBUG_FREQ -#define DEBUG_FREQ 0 -#endif - -#if DEBUG_FREQ -#define DBG(x...) printf(x) -#else -#define DBG(x...) -#endif - -/* Decimal powers: */ -#define kilo (1000ULL) -#define Mega (kilo * kilo) -#define Giga (kilo * Mega) -#define Tera (kilo * Giga) -#define Peta (kilo * Tera) - -#define bit(n) (1ULL << (n)) -#define bitmask(h,l) ((bit(h)|(bit(h)-1)) & ~(bit(l)-1)) -#define bitfield(x,h,l) (((x) & bitmask(h,l)) >> l) - -#define IA32_PERF_STATUS 0x198 -#define MSR_FLEX_RATIO 0x194 -#define MSR_PLATFORM_INFO 0xCE -#define K8_FIDVID_STATUS 0xC0010042 -#define K10_COFVID_STATUS 0xC0010071 - -#define DEFAULT_FSB 100000 /* for now, hardcoding 100MHz for old CPUs */ - -// DFE: This constant comes from older xnu: -#define CLKNUM 1193182 /* formerly 1193167 */ - -// DFE: These two constants come from Linux except CLOCK_TICK_RATE replaced with CLKNUM -#define CALIBRATE_TIME_MSEC 30 /* 30 msecs */ -#define CALIBRATE_LATCH \ - ((CLKNUM * CALIBRATE_TIME_MSEC + 1000/2)/1000) - -extern uint64_t tscFrequency; -extern uint64_t fsbFrequency; -extern uint64_t cpuFrequency; - -void calculate_freq(void); - -static inline uint64_t rdtsc64(void) -{ - uint64_t ret; - __asm__ volatile("rdtsc" : "=A" (ret)); - return ret; -} - -static inline uint64_t rdmsr64(uint32_t msr) -{ - uint64_t ret; - __asm__ volatile("rdmsr" : "=A" (ret) : "c" (msr)); - return ret; -} - -static inline void do_cpuid(uint32_t selector, uint32_t *data) -{ - asm volatile ("cpuid" - : "=a" (data[0]), - "=b" (data[1]), - "=c" (data[2]), - "=d" (data[3]) - : "a" (selector) - ); -} - -#endif /* !__LIBSAIO_FREQ_DETECT_H */ Index: trunk/i386/libsaio/console.c =================================================================== --- trunk/i386/libsaio/console.c (revision 22) +++ trunk/i386/libsaio/console.c (revision 23) @@ -49,8 +49,8 @@ extern int vprf(const char * fmt, va_list ap); -BOOL gVerboseMode; -BOOL gErrors; +bool gVerboseMode; +bool gErrors; /* * write one character to console @@ -126,7 +126,7 @@ int error(const char * fmt, ...) { va_list ap; - gErrors = YES; + gErrors = true; va_start(ap, fmt); if (bootArgs->Video.v_display == VGA_TEXT_MODE) prf(fmt, ap, putchar, 0); @@ -138,15 +138,17 @@ void stop(const char * fmt, ...) { - va_list ap; - - printf("\n"); - va_start(ap, fmt); - if (bootArgs->Video.v_display == VGA_TEXT_MODE) + va_list ap; + + printf("\n"); + va_start(ap, fmt); + if (bootArgs->Video.v_display == VGA_TEXT_MODE) { prf(fmt, ap, putchar, 0); - else + } else { vprf(fmt, ap); + } va_end(ap); - printf("\n"); - halt(); + printf("\nThis is a non recoverable error! System HALTED!!!"); + halt(); + while (1); } Index: trunk/i386/libsaio/ext2fs.c =================================================================== --- trunk/i386/libsaio/ext2fs.c (revision 22) +++ trunk/i386/libsaio/ext2fs.c (revision 23) @@ -13,10 +13,11 @@ #define EX2ProbeSize 2048 -BOOL EX2Probe (const void *buf) +bool EX2Probe (const void *buf) { return (OSReadLittleInt16(buf+0x438,0)==0xEF53); } + void EX2GetDescription(CICell ih, char *str, long strMaxLen) { char * buf=malloc (EX2ProbeSize); @@ -38,4 +39,4 @@ str[strMaxLen]=0; strncpy (str, buf+0x478, min (strMaxLen, 16)); free (buf); -} \ No newline at end of file +} Index: trunk/i386/libsaio/bootstruct.h =================================================================== --- trunk/i386/libsaio/bootstruct.h (revision 22) +++ trunk/i386/libsaio/bootstruct.h (revision 23) @@ -126,7 +126,6 @@ config_file_t bootConfig; // boot.plist config_file_t overrideConfig; // additional boot.plist which can override bootConfig keys - config_file_t themeDefault; // default theme.plist config_file_t themeConfig; // theme.plist config_file_t smbiosConfig; // smbios.plist config_file_t helperConfig; // boot helper partition's boot.plist Index: trunk/i386/libsaio/device_tree.c =================================================================== --- trunk/i386/libsaio/device_tree.c (revision 22) +++ trunk/i386/libsaio/device_tree.c (revision 23) @@ -62,7 +62,7 @@ static Property *freeProperties, *allocedProperties; Property * -DT__AddProperty(Node *node, char *name, uint32_t length, void *value) +DT__AddProperty(Node *node, const char *name, uint32_t length, void *value) { Property *prop; @@ -112,7 +112,7 @@ } Node * -DT__AddChild(Node *parent, char *name) +DT__AddChild(Node *parent, const char *name) { Node *node; @@ -150,7 +150,7 @@ parent->children = node; } DTInfo.numNodes++; - DT__AddProperty(node, "name", strlen(name) + 1, name); + DT__AddProperty(node, "name", strlen(name) + 1, (void *) name); return node; } @@ -308,7 +308,7 @@ } Node * -DT__FindNode(char *path, bool createIfMissing) +DT__FindNode(const char *path, bool createIfMissing) { Node *node, *child; DTPropertyNameBuf nameBuf; Index: trunk/i386/libsaio/hfs.c =================================================================== --- trunk/i386/libsaio/hfs.c (revision 22) +++ trunk/i386/libsaio/hfs.c (revision 23) @@ -109,8 +109,7 @@ u_int16_t *uniStr2, u_int32_t len2); -static void -SwapFinderInfo(FndrFileInfo *dst, FndrFileInfo *src) +static void SwapFinderInfo(FndrFileInfo *dst, FndrFileInfo *src) { dst->fdType = SWAP_BE32(src->fdType); dst->fdCreator = SWAP_BE32(src->fdCreator); @@ -125,8 +124,7 @@ free(ih); } -BOOL -HFSProbe (const void *buf) +bool HFSProbe (const void *buf) { const HFSMasterDirectoryBlock *mdb; const HFSPlusVolumeHeader *header; @@ -134,11 +132,11 @@ header=(const HFSPlusVolumeHeader *)(((const char*)buf)+kMDBBaseOffset); if ( SWAP_BE16(mdb->drSigWord) == kHFSSigWord ) - return TRUE; + return true; if (SWAP_BE16(header->signature) != kHFSPlusSigWord && SWAP_BE16(header->signature) != kHFSXSigWord) - return FALSE; - return TRUE; + return false; + return true; } long HFSInitPartition(CICell ih) Index: trunk/i386/libsaio/ext2fs.h =================================================================== --- trunk/i386/libsaio/ext2fs.h (revision 22) +++ trunk/i386/libsaio/ext2fs.h (revision 23) @@ -7,5 +7,5 @@ * */ -extern BOOL EX2Probe (const void *buf); +extern bool EX2Probe (const void *buf); extern void EX2GetDescription(CICell ih, char *str, long strMaxLen); Index: trunk/i386/libsaio/device_tree.h =================================================================== --- trunk/i386/libsaio/device_tree.h (revision 22) +++ trunk/i386/libsaio/device_tree.h (revision 23) @@ -9,7 +9,7 @@ #include typedef struct _Property { - char * name; + const char * name; uint32_t length; void * value; @@ -27,13 +27,13 @@ extern Property * -DT__AddProperty(Node *node, char *name, uint32_t length, void *value); +DT__AddProperty(Node *node, const char *name, uint32_t length, void *value); extern Node * -DT__AddChild(Node *parent, char *name); +DT__AddChild(Node *parent, const char *name); Node * -DT__FindNode(char *path, bool createIfMissing); +DT__FindNode(const char *path, bool createIfMissing); extern void DT__FreeProperty(Property *prop); Index: trunk/i386/libsaio/allocate.c =================================================================== --- trunk/i386/libsaio/allocate.c (revision 0) +++ trunk/i386/libsaio/allocate.c (revision 23) @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Portions Copyright (c) 2003 Apple Computer, Inc. All Rights + * Reserved. This file contains Original Code and/or Modifications of + * Original Code as defined in and that are subject to the Apple Public + * Source License Version 2.0 (the "License"). You may not use this file + * except in compliance with the License. Please obtain a copy of the + * License at http://www.apple.com/publicsource and read it before using + * this file. + * + * The Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ + +#include "sl.h" +#include "saio_internal.h" +#include "bootstruct.h" +#include "device_tree.h" + +static long gImageLastKernelAddr; + +#define kPageSize 4096 +#define RoundPage(x) ((((unsigned)(x)) + kPageSize - 1) & ~(kPageSize - 1)) + + +long +AllocateMemoryRange(char * rangeName, long start, long length, long type) +{ + char *nameBuf; + uint32_t *buffer; + + nameBuf = malloc(strlen(rangeName) + 1); + if (nameBuf == 0) return -1; + strcpy(nameBuf, rangeName); + + buffer = malloc(2 * sizeof(uint32_t)); + if (buffer == 0) return -1; + + buffer[0] = start; + buffer[1] = length; + + DT__AddProperty(gMemoryMapNode, nameBuf, 2 * sizeof(uint32_t), (char *)buffer); + + return 0; +} + +long +AllocateKernelMemory( long inSize ) +{ + long addr; + + if (gImageLastKernelAddr == 0) { + gImageLastKernelAddr = RoundPage( bootArgs->kaddr + + bootArgs->ksize ); + } + addr = gImageLastKernelAddr; + gImageLastKernelAddr += RoundPage(inSize); + + if ( gImageLastKernelAddr >= (KERNEL_ADDR + KERNEL_LEN) ) { + stop ("AllocateKernelMemory error"); + } + + bootArgs->ksize = gImageLastKernelAddr - bootArgs->kaddr; + + return addr; +} Index: trunk/i386/libsaio/hfs.h =================================================================== --- trunk/i386/libsaio/hfs.h (revision 22) +++ trunk/i386/libsaio/hfs.h (revision 23) @@ -30,4 +30,4 @@ extern long HFSGetFileBlock(CICell ih, char *str, unsigned long long *firstBlock); extern long HFSGetUUID(CICell ih, char *uuidStr); extern void HFSFree(CICell ih); -extern BOOL HFSProbe (const void *buf); \ No newline at end of file +extern bool HFSProbe (const void *buf); Index: trunk/i386/libsaio/spd.c =================================================================== --- trunk/i386/libsaio/spd.c (revision 22) +++ trunk/i386/libsaio/spd.c (revision 23) @@ -1,6 +1,7 @@ /* + * Copyright 2010 AsereBLN. All rights reserved. * - * + * spd.c - obtain serial presene detect memory information */ #include "libsaio.h" @@ -18,149 +19,7 @@ #define DBG(x...) #endif -static const char *spd_memory_types[] = +void scan_spd(PlatformInfo_t *p) { - "RAM", /* 00h Undefined */ - "FPM", /* 01h FPM */ - "EDO", /* 02h EDO */ - "", /* 03h PIPELINE NIBBLE */ - "SDRAM", /* 04h SDRAM */ - "", /* 05h MULTIPLEXED ROM */ - "DDR SGRAM", /* 06h SGRAM DDR */ - "DDR SDRAM", /* 07h SDRAM DDR */ - "DDR2 SDRAM", /* 08h SDRAM DDR 2 */ - "", /* 09h Undefined */ - "", /* 0Ah Undefined */ - "DDR3 SDRAM", /* 0Bh SDRAM DDR 3 */ -}; - -#define rdtsc(low,high) \ -__asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high)) - -#define SMBHSTSTS 0 -#define SMBHSTCNT 2 -#define SMBHSTCMD 3 -#define SMBHSTADD 4 -#define SMBHSTDAT 5 - -unsigned char smb_read_byte_intel(uint32_t base, uint8_t adr, uint8_t cmd) -{ - int l1, h1, l2, h2; - unsigned long long t; - - outb(base + SMBHSTSTS, 0x1f); // reset SMBus Controller - outb(base + SMBHSTDAT, 0xff); - - while( inb(base + SMBHSTSTS) & 0x01); // wait until ready - - outb(base + SMBHSTCMD, cmd); - outb(base + SMBHSTADD, (adr << 1) | 0x01 ); - outb(base + SMBHSTCNT, 0x48 ); - - rdtsc(l1, h1); - - while (!( inb(base + SMBHSTSTS) & 0x02)) // wait til command finished - { - rdtsc(l2, h2); - t = ((h2 - h1) * 0xffffffff + (l2 - l1)) / (Platform.CPU.TSCFrequency / 40); - if (t > 10) - break; // break after 10ms - } - return inb(base + SMBHSTDAT); + /* NYI */ } - -static void read_smb_intel(pci_dt_t *smbus_dev) -{ - int i, x; - - uint8_t spd_size; - uint32_t base; - - RamSlotInfo_t *slot; - - base = pci_config_read16(smbus_dev->dev.addr, 0x20) & 0xFFFE; - - // Search MAX_RAM_SLOTS slots - for (i = 0; i < 6; i++) - { - slot = &Platform.RAM.DIMM[i]; - - spd_size = smb_read_byte_intel(base, 0x50 + i, 0); - - // Check spd is present - if (spd_size != 0xff) - { - slot->InUse = YES; - - slot->spd = malloc(spd_size); - if (slot->spd) - { - bzero(slot->spd, spd_size); - - // Copy spd data into buffer - for (x = 0; x < spd_size; x++) - slot->spd[x] = smb_read_byte_intel(base, 0x50 + i, x); - - switch (slot->spd[SPD_MEMORY_TYPE]) - { - case SPD_MEMORY_TYPE_SDRAM_DDR2: - - slot->ModuleSize = ((1 << (slot->spd[SPD_NUM_ROWS] & 0x0f) + (slot->spd[SPD_NUM_COLUMNS] & 0x0f) - 17) * - ((slot->spd[SPD_NUM_DIMM_BANKS] & 0x7) + 1) * slot->spd[SPD_NUM_BANKS_PER_SDRAM]); - break; - - case SPD_MEMORY_TYPE_SDRAM_DDR3: - - slot->ModuleSize = ((slot->spd[4] & 0x0f) + 28 ) + ((slot->spd[8] & 0x7) + 3 ); - slot->ModuleSize -= (slot->spd[7] & 0x7) + 25; - slot->ModuleSize = ((1 << slot->ModuleSize) * (((slot->spd[7] >> 3) & 0x1f) + 1)); - - break; - } - } - - verbose(" slot %d - %dMB %s SPD %d bytes at %x\n", i, slot->ModuleSize, - spd_memory_types[(uint8_t)slot->spd[SPD_MEMORY_TYPE]], - spd_size, slot->spd); - } - } - -} - -static struct smbus_controllers_t smbus_controllers[] = { - - {0x8086, 0x5032, "EP80579", read_smb_intel }, - {0x8086, 0x269B, "ESB2", read_smb_intel }, - {0x8086, 0x25A4, "6300ESB", read_smb_intel }, - {0x8086, 0x24C3, "ICH4", read_smb_intel }, - {0x8086, 0x24D3, "ICH5", read_smb_intel }, - {0x8086, 0x266A, "ICH6", read_smb_intel }, - {0x8086, 0x27DA, "ICH7", read_smb_intel }, - {0x8086, 0x283E, "ICH8", read_smb_intel }, - {0x8086, 0x2930, "ICH9", read_smb_intel }, - {0x8086, 0x3A30, "ICH10R", read_smb_intel }, - {0x8086, 0x3A60, "ICH10B", read_smb_intel }, - {0x8086, 0x3B30, "P55", read_smb_intel }, - -}; - -void scan_smbus_controller(pci_dt_t *smbus_dev) -{ - int i; - - for( i = 1; i < sizeof(smbus_controllers) / sizeof(smbus_controllers[0]); i++ ) - if (( smbus_controllers[i].vendor == smbus_dev->vendor_id) - && ( smbus_controllers[i].device == smbus_dev->device_id)) - { - verbose("%s%s SMBus Controller [%4x:%4x] at %02x:%02x.%x\n", - (smbus_dev->vendor_id == 0x8086) ? "Intel(R) " : "", - smbus_controllers[i].name, - smbus_dev->vendor_id, smbus_dev->device_id, - smbus_dev->dev.bits.bus, smbus_dev->dev.bits.dev, smbus_dev->dev.bits.func); - - smbus_controllers[i].read_smb(smbus_dev); - - } - -} - Index: trunk/i386/libsaio/spd.h =================================================================== --- trunk/i386/libsaio/spd.h (revision 22) +++ trunk/i386/libsaio/spd.h (revision 23) @@ -1,156 +1,14 @@ /* + * Copyright 2010 AsereBLN. All rights reserved. * - * + * spd.h */ #ifndef __LIBSAIO_SPD_H #define __LIBSAIO_SPD_H -#include "libsaio.h" +#include "platform.h" -void scan_smbus_controller(pci_dt_t *smbus_dev); +extern void scan_spd(PlatformInfo_t *p); -struct smbus_controllers_t { - uint32_t vendor; - uint32_t device; - char *name; - void (*read_smb)(pci_dt_t *smbus_dev); -}; - - -/* - * Serial Presence Detect (SPD) data stored on SDRAM modules. - * - * Datasheet: - * - Name: PC SDRAM Serial Presence Detect (SPD) Specification - * Revision 1.2A, December, 1997 - * - PDF: http://www.intel.com/design/chipsets/memory/spdsd12a.pdf - * - * Datasheet (alternative): - * - Name: SERIAL PRESENCE DETECT STANDARD, General Standard - * JEDEC Standard No. 21-C - * - PDF: http://www.jedec.org/download/search/4_01_02_00R9.PDF - */ - - -/* Byte numbers. */ -#define SPD_NUM_MANUFACTURER_BYTES 0 /* Number of bytes used by module manufacturer */ -#define SPD_TOTAL_SPD_MEMORY_SIZE 1 /* Total SPD memory size */ -#define SPD_MEMORY_TYPE 2 /* (Fundamental) memory type */ -#define SPD_NUM_ROWS 3 /* Number of row address bits */ -#define SPD_NUM_COLUMNS 4 /* Number of column address bits */ -#define SPD_NUM_DIMM_BANKS 5 /* Number of module rows (banks) */ -#define SPD_MODULE_DATA_WIDTH_LSB 6 /* Module data width (LSB) */ -#define SPD_MODULE_DATA_WIDTH_MSB 7 /* Module data width (MSB) */ -#define SPD_MODULE_VOLTAGE 8 /* Module interface signal levels */ -#define SPD_MIN_CYCLE_TIME_AT_CAS_MAX 9 /* SDRAM cycle time (highest CAS latency), RAS access time (tRAC) */ -#define SPD_ACCESS_TIME_FROM_CLOCK 10 /* SDRAM access time from clock (highest CAS latency), CAS access time (Tac, tCAC) */ -#define SPD_DIMM_CONFIG_TYPE 11 /* Module configuration type */ -#define SPD_REFRESH 12 /* Refresh rate/type */ -#define SPD_PRIMARY_SDRAM_WIDTH 13 /* SDRAM width (primary SDRAM) */ -#define SPD_ERROR_CHECKING_SDRAM_WIDTH 14 /* Error checking SDRAM (data) width */ -#define SPD_MIN_CLOCK_DELAY_B2B_RAND_COLUMN 15 /* SDRAM device attributes, minimum clock delay for back to back random column */ -#define SPD_SUPPORTED_BURST_LENGTHS 16 /* SDRAM device attributes, burst lengths supported */ -#define SPD_NUM_BANKS_PER_SDRAM 17 /* SDRAM device attributes, number of banks on SDRAM device */ -#define SPD_ACCEPTABLE_CAS_LATENCIES 18 /* SDRAM device attributes, CAS latency */ -#define SPD_CS_LATENCY 19 /* SDRAM device attributes, CS latency */ -#define SPD_WE_LATENCY 20 /* SDRAM device attributes, WE latency */ -#define SPD_MODULE_ATTRIBUTES 21 /* SDRAM module attributes */ -#define SPD_DEVICE_ATTRIBUTES_GENERAL 22 /* SDRAM device attributes, general */ -#define SPD_SDRAM_CYCLE_TIME_2ND 23 /* SDRAM cycle time (2nd highest CAS latency) */ -#define SPD_ACCESS_TIME_FROM_CLOCK_2ND 24 /* SDRAM access from clock (2nd highest CAS latency) */ -#define SPD_SDRAM_CYCLE_TIME_3RD 25 /* SDRAM cycle time (3rd highest CAS latency) */ -#define SPD_ACCESS_TIME_FROM_CLOCK_3RD 26 /* SDRAM access from clock (3rd highest CAS latency) */ -#define SPD_MIN_ROW_PRECHARGE_TIME 27 /* Minimum row precharge time (Trp) */ -#define SPD_MIN_ROWACTIVE_TO_ROWACTIVE 28 /* Minimum row active to row active (Trrd) */ -#define SPD_MIN_RAS_TO_CAS_DELAY 29 /* Minimum RAS to CAS delay (Trcd) */ -#define SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY 30 /* Minimum RAS pulse width (Tras) */ -#define SPD_DENSITY_OF_EACH_ROW_ON_MODULE 31 /* Density of each row on module */ -#define SPD_CMD_SIGNAL_INPUT_SETUP_TIME 32 /* Command and address signal input setup time */ -#define SPD_CMD_SIGNAL_INPUT_HOLD_TIME 33 /* Command and address signal input hold time */ -#define SPD_DATA_SIGNAL_INPUT_SETUP_TIME 34 /* Data signal input setup time */ -#define SPD_DATA_SIGNAL_INPUT_HOLD_TIME 35 /* Data signal input hold time */ -#define SPD_WRITE_RECOVERY_TIME 36 /* Write recovery time (tWR) */ -#define SPD_INT_WRITE_TO_READ_DELAY 37 /* Internal write to read command delay (tWTR) */ -#define SPD_INT_READ_TO_PRECHARGE_DELAY 38 /* Internal read to precharge command delay (tRTP) */ -#define SPD_MEM_ANALYSIS_PROBE_PARAMS 39 /* Memory analysis probe characteristics */ -#define SPD_BYTE_41_42_EXTENSION 40 /* Extension of byte 41 (tRC) and byte 42 (tRFC) */ -#define SPD_MIN_ACT_TO_ACT_AUTO_REFRESH 41 /* Minimum active to active auto refresh (tRCmin) */ -#define SPD_MIN_AUTO_REFRESH_TO_ACT 42 /* Minimum auto refresh to active/auto refresh (tRFC) */ -#define SPD_MAX_DEVICE_CYCLE_TIME 43 /* Maximum device cycle time (tCKmax) */ -#define SPD_MAX_DQS_DQ_SKEW 44 /* Maximum skew between DQS and DQ (tDQSQ) */ -#define SPD_MAX_READ_DATAHOLD_SKEW 45 /* Maximum read data-hold skew factor (tQHS) */ -#define SPD_PLL_RELOCK_TIME 46 /* PLL relock time */ -#define SPD_SPD_DATA_REVISION_CODE 62 /* SPD data revision code */ -#define SPD_CHECKSUM_FOR_BYTES_0_TO_62 63 /* Checksum for bytes 0-62 */ -#define SPD_MANUFACTURER_JEDEC_ID_CODE 64 /* Manufacturer's JEDEC ID code, per EIA/JEP106 (bytes 64-71) */ -#define SPD_MANUFACTURING_LOCATION 72 /* Manufacturing location */ -#define SPD_MANUFACTURER_PART_NUMBER 73 /* Manufacturer's part number, in 6-bit ASCII (bytes 73-90) */ -#define SPD_REVISION_CODE 91 /* Revision code (bytes 91-92) */ -#define SPD_MANUFACTURING_DATE 93 /* Manufacturing date (byte 93: year, byte 94: week) */ -#define SPD_ASSEMBLY_SERIAL_NUMBER 95 /* Assembly serial number (bytes 95-98) */ -#define SPD_MANUFACTURER_SPECIFIC_DATA 99 /* Manufacturer specific data (bytes 99-125) */ -#define SPD_INTEL_SPEC_FOR_FREQUENCY 126 /* Intel specification for frequency */ -#define SPD_INTEL_SPEC_100_MHZ 127 /* Intel specification details for 100MHz support */ - -/* DRAM specifications use the following naming conventions for SPD locations */ -#define SPD_tRP SPD_MIN_ROW_PRECHARGE_TIME -#define SPD_tRRD SPD_MIN_ROWACTIVE_TO_ROWACTIVE -#define SPD_tRCD SPD_MIN_RAS_TO_CAS_DELAY -#define SPD_tRAS SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY -#define SPD_BANK_DENSITY SPD_DENSITY_OF_EACH_ROW_ON_MODULE -#define SPD_ADDRESS_CMD_HOLD SPD_CMD_SIGNAL_INPUT_HOLD_TIME -#define SPD_tRC 41 /* SDRAM Device Minimum Active to Active/Auto Refresh Time (tRC) */ -#define SPD_tRFC 42 /* SDRAM Device Minimum Auto Refresh to Active/Auto Refresh (tRFC) */ - - -/* SPD_MEMORY_TYPE values. */ -#define SPD_MEMORY_TYPE_FPM_DRAM 1 -#define SPD_MEMORY_TYPE_EDO 2 -#define SPD_MEMORY_TYPE_PIPELINED_NIBBLE 3 -#define SPD_MEMORY_TYPE_SDRAM 4 -#define SPD_MEMORY_TYPE_MULTIPLEXED_ROM 5 -#define SPD_MEMORY_TYPE_SGRAM_DDR 6 -#define SPD_MEMORY_TYPE_SDRAM_DDR 7 -#define SPD_MEMORY_TYPE_SDRAM_DDR2 8 -#define SPD_MEMORY_TYPE_SDRAM_DDR3 0xb - -/* SPD_MODULE_VOLTAGE values. */ -#define SPD_VOLTAGE_TTL 0 /* 5.0 Volt/TTL */ -#define SPD_VOLTAGE_LVTTL 1 /* LVTTL */ -#define SPD_VOLTAGE_HSTL 2 /* HSTL 1.5 */ -#define SPD_VOLTAGE_SSTL3 3 /* SSTL 3.3 */ -#define SPD_VOLTAGE_SSTL2 4 /* SSTL 2.5 */ - -/* SPD_DIMM_CONFIG_TYPE values. */ -#define ERROR_SCHEME_NONE 0 -#define ERROR_SCHEME_PARITY 1 -#define ERROR_SCHEME_ECC 2 - -/* SPD_ACCEPTABLE_CAS_LATENCIES values. */ -// TODO: Check values. -#define SPD_CAS_LATENCY_1_0 0x01 -#define SPD_CAS_LATENCY_1_5 0x02 -#define SPD_CAS_LATENCY_2_0 0x04 -#define SPD_CAS_LATENCY_2_5 0x08 -#define SPD_CAS_LATENCY_3_0 0x10 -#define SPD_CAS_LATENCY_3_5 0x20 -#define SPD_CAS_LATENCY_4_0 0x40 - -#define SPD_CAS_LATENCY_DDR2_3 (1 << 3) -#define SPD_CAS_LATENCY_DDR2_4 (1 << 4) -#define SPD_CAS_LATENCY_DDR2_5 (1 << 5) -#define SPD_CAS_LATENCY_DDR2_6 (1 << 6) - -/* SPD_SUPPORTED_BURST_LENGTHS values. */ -#define SPD_BURST_LENGTH_1 1 -#define SPD_BURST_LENGTH_2 2 -#define SPD_BURST_LENGTH_4 4 -#define SPD_BURST_LENGTH_8 8 -#define SPD_BURST_LENGTH_PAGE (1 << 7) - -/* SPD_MODULE_ATTRIBUTES values. */ -#define MODULE_BUFFERED 1 -#define MODULE_REGISTERED 2 - #endif /* !__LIBSAIO_SPD_H */ Index: trunk/i386/libsaio/Makefile =================================================================== --- trunk/i386/libsaio/Makefile (revision 22) +++ trunk/i386/libsaio/Makefile (revision 23) @@ -4,21 +4,23 @@ UTILDIR = ../util LIBSADIR = ../libsa +BOOT2DIR = ../boot2 INSTALLDIR = $(DSTROOT)/System/Library/Frameworks/System.framework/Versions/B/PrivateHeaders/standalone #SYMROOT= OPTIM = -Os -Oz -DEBUG = NOTHING +DEBUG = -DNOTHING +#DEBUG = -DDEBUG_CPU=1 -DDEBUG_MEM=1 -DDEBUG_SPD=1 -DDEBUG_PCI=1 -DDEBUG_SMBIOS=1 CFLAGS = $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost \ -D__ARCHITECTURE__=\"i386\" -DSAIO_INTERNAL_USER \ - -DRCZ_COMPRESSED_FILE_SUPPORT -D$(DEBUG) \ + -DRCZ_COMPRESSED_FILE_SUPPORT $(DEBUG) \ -fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) \ -mpreferred-stack-boundary=2 -fno-align-functions -fno-stack-protector \ -march=pentium4 -msse2 -mfpmath=sse -msoft-float DEFINES= CONFIG = hd -INC = -I. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSADIR) +INC = -I. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSADIR) -I$(BOOT2DIR) ifneq "" "$(wildcard /bin/mkdirs)" MKDIRS = /bin/mkdirs else @@ -33,14 +35,14 @@ SAIO_OBJS = table.o asm.o bios.o biosfn.o \ disk.o sys.o cache.o bootstruct.o \ - stringTable.o load.o pci.o memory.o misc.o \ + stringTable.o load.o pci.o allocate.o misc.o \ ufs.o ufs_byteorder.o \ vbe.o nbp.o hfs.o hfs_compare.o \ xml.o ntfs.o msdos.o md5c.o device_tree.o \ - freq_detect.o platform.o dsdt_patcher.o \ + cpu.o platform.o dsdt_patcher.o \ smbios_patcher.o fake_efi.o ext2fs.o \ hpet.o spd.o usb.o pci_setup.o \ - device_inject.o nvidia.o ati.o + device_inject.o nvidia.o ati.o pci_root.o mem.o SAIO_EXTERN_OBJS = console.o Index: trunk/i386/libsaio/SMBIOS.h =================================================================== --- trunk/i386/libsaio/SMBIOS.h (revision 22) +++ trunk/i386/libsaio/SMBIOS.h (revision 23) @@ -39,6 +39,12 @@ typedef UInt32 SMBDWord; typedef UInt64 SMBQWord; +struct DMIHeader{ + SMBByte type; + SMBByte length; + SMBWord handle; +} __attribute__((packed)); + struct DMIEntryPoint { SMBByte anchor[5]; SMBByte checksum; Index: trunk/i386/libsaio/smbios_patcher.c =================================================================== --- trunk/i386/libsaio/smbios_patcher.c (revision 22) +++ trunk/i386/libsaio/smbios_patcher.c (revision 23) @@ -3,8 +3,9 @@ */ #include "libsaio.h" -#include "acpi.h" +#include "boot.h" #include "bootstruct.h" +#include "acpi.h" #include "efi_tables.h" #include "fake_efi.h" #include "platform.h" @@ -24,102 +25,103 @@ // defaults for a MacBook static char sm_macbook_defaults[][2][40]={ - {"SMbiosvendor", "Apple Inc." }, + {"SMbiosvendor", "Apple Inc." }, {"SMbiosversion", "MB41.88Z.0073.B00.0809221748" }, - {"SMbiosdate", "04/01/2008" }, - {"SMmanufacter", "Apple Inc." }, - {"SMproductname", "MacBook4,1" }, - {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, - {"SMfamily", "MacBook" }, - {"SMboardmanufacter","Apple Inc." }, - {"SMboardproduct", "Mac-F42D89C8" }, + {"SMbiosdate", "04/01/2008" }, + {"SMmanufacter", "Apple Inc." }, + {"SMproductname", "MacBook4,1" }, + {"SMsystemversion", "1.0" }, + {"SMserial", "SOMESRLNMBR" }, + {"SMfamily", "MacBook" }, + {"SMboardmanufacter", "Apple Inc." }, + {"SMboardproduct", "Mac-F42D89C8" }, { "","" } }; // defaults for a MacBook Pro static char sm_macbookpro_defaults[][2][40]={ - {"SMbiosvendor", "Apple Inc." }, + {"SMbiosvendor", "Apple Inc." }, {"SMbiosversion", "MBP41.88Z.0073.B00.0809221748" }, - {"SMbiosdate", "04/01/2008" }, - {"SMmanufacter", "Apple Inc." }, - {"SMproductname", "MacBookPro4,1" }, - {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, - {"SMfamily", "MacBookPro" }, - {"SMboardmanufacter","Apple Inc." }, - {"SMboardproduct", "Mac-F42D89C8" }, + {"SMbiosdate", "04/01/2008" }, + {"SMmanufacter", "Apple Inc." }, + {"SMproductname", "MacBookPro4,1" }, + {"SMsystemversion", "1.0" }, + {"SMserial", "SOMESRLNMBR" }, + {"SMfamily", "MacBookPro" }, + {"SMboardmanufacter", "Apple Inc." }, + {"SMboardproduct", "Mac-F42D89C8" }, { "","" } }; // defaults for a Mac mini static char sm_macmini_defaults[][2][40]={ - {"SMbiosvendor", "Apple Inc." }, + {"SMbiosvendor", "Apple Inc." }, {"SMbiosversion", "MM21.88Z.009A.B00.0706281359" }, - {"SMbiosdate", "04/01/2008" }, - {"SMmanufacter", "Apple Inc." }, - {"SMproductname", "Macmini2,1" }, - {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, - {"SMfamily", "Napa Mac" }, - {"SMboardmanufacter","Apple Inc." }, - {"SMboardproduct", "Mac-F4208EAA" }, + {"SMbiosdate", "04/01/2008" }, + {"SMmanufacter", "Apple Inc." }, + {"SMproductname", "Macmini2,1" }, + {"SMsystemversion", "1.0" }, + {"SMserial", "SOMESRLNMBR" }, + {"SMfamily", "Napa Mac" }, + {"SMboardmanufacter", "Apple Inc." }, + {"SMboardproduct", "Mac-F4208EAA" }, { "","" } }; // defaults for an iMac static char sm_imac_defaults[][2][40]={ - {"SMbiosvendor", "Apple Inc." }, + {"SMbiosvendor", "Apple Inc." }, {"SMbiosversion", "IM81.88Z.00C1.B00.0802091538" }, - {"SMbiosdate", "04/01/2008" }, - {"SMmanufacter", "Apple Inc." }, - {"SMproductname", "iMac8,1" }, - {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, - {"SMfamily", "Mac" }, - {"SMboardmanufacter","Apple Inc." }, - {"SMboardproduct", "Mac-F227BEC8" }, + {"SMbiosdate", "04/01/2008" }, + {"SMmanufacter", "Apple Inc." }, + {"SMproductname", "iMac8,1" }, + {"SMsystemversion", "1.0" }, + {"SMserial", "SOMESRLNMBR" }, + {"SMfamily", "Mac" }, + {"SMboardmanufacter", "Apple Inc." }, + {"SMboardproduct", "Mac-F227BEC8" }, { "","" } }; // defaults for a Mac Pro static char sm_macpro_defaults[][2][40]={ - {"SMbiosvendor", "Apple Computer, Inc." }, + {"SMbiosvendor", "Apple Computer, Inc." }, {"SMbiosversion", "MP31.88Z.006C.B05.0802291410" }, - {"SMbiosdate", "04/01/2008" }, - {"SMmanufacter", "Apple Computer, Inc." }, - {"SMproductname", "MacPro3,1" }, - {"SMsystemversion", "1.0" }, - {"SMserial", "SOMESRLNMBR" }, - {"SMfamily", "MacPro" }, - {"SMboardmanufacter","Apple Computer, Inc." }, - {"SMboardproduct", "Mac-F4208DC8" }, + {"SMbiosdate", "04/01/2008" }, + {"SMmanufacter", "Apple Computer, Inc." }, + {"SMproductname", "MacPro3,1" }, + {"SMsystemversion", "1.0" }, + {"SMserial", "SOMESRLNMBR" }, + {"SMfamily", "MacPro" }, + {"SMboardmanufacter", "Apple Computer, Inc." }, + {"SMboardproduct", "Mac-F4208DC8" }, { "","" } }; static char *sm_get_defstr(char *name, int table_num) { - int i; - char (*sm_defaults)[2][40]; + int i; + char (*sm_defaults)[2][40]; - if (Platform.CPU.Mobile) - if (Platform.CPU.NoCores > 1) - { + if (platformCPUFeature(CPU_FEATURE_MOBILE)) { + if (Platform.CPU.NoCores > 1) { sm_defaults=sm_macbookpro_defaults; } else { sm_defaults=sm_macbook_defaults; } - else - switch (Platform.CPU.NoCores) - { - case 1: sm_defaults=sm_macmini_defaults; break; - case 2: sm_defaults=sm_imac_defaults; break; - default: sm_defaults=sm_macpro_defaults; break; + } else { + switch (Platform.CPU.NoCores) { + case 1: sm_defaults=sm_macmini_defaults; break; + case 2: sm_defaults=sm_imac_defaults; break; + default: sm_defaults=sm_macpro_defaults; break; } + } - for (i=0;sm_defaults[i][0][0];i++) - if (!strcmp (sm_defaults[i][0],name)) + for (i=0;sm_defaults[i][0][0];i++) { + if (!strcmp (sm_defaults[i][0],name)) { return sm_defaults[i][1]; + } + } // Shouldn't happen printf ("Error: no default for '%s' known\n", name); @@ -127,61 +129,81 @@ return ""; } -static int sm_get_fsb (char *name, int table_num) +static int sm_get_fsb(char *name, int table_num) { return Platform.CPU.FSBFrequency/1000000; } static int sm_get_cpu (char *name, int table_num) { - /* round CPU frequency */ -// return round2(Platform.CPU.CPUFrequency/1000000, 10); -// return roundup2(Platform.CPU.CPUFrequency/1000000, 100); return Platform.CPU.CPUFrequency/1000000; } static int sm_get_cputype (char *name, int table_num) { - int cores = Platform.CPU.NoCores; - - if (cores == 1) + if (Platform.CPU.NoCores == 1) { return 0x0101; // <01 01> Intel Core Solo? - else if (cores == 2) + } else if (Platform.CPU.NoCores == 2) { return 0x0301; // <01 03> Intel Core 2 Duo - else if (cores >= 4) + } else if (Platform.CPU.NoCores >= 4) { return 0x0501; // <01 05> Quad-Core Intel Xeon - else + } else { return 0x0301; // Default to Core 2 Duo + } } static int sm_get_memtype (char *name, int table_num) { - if(Platform.RAM.Type) - return Platform.RAM.Type; - else - return SMB_MEM_TYPE_DDR2; + if (table_num < MAX_RAM_SLOTS && + Platform.RAM.DIMM[table_num].InUse && + Platform.RAM.DIMM[table_num].Type != 0) + { + return Platform.RAM.DIMM[table_num].Type; + } + return SMB_MEM_TYPE_DDR2; } static int sm_get_memspeed (char *name, int table_num) { - if(Platform.RAM.Type) - return round2( Platform.RAM.Frequency / 500000, 2); - else - return 667; + if (Platform.RAM.Frequency != 0) { + return Platform.RAM.Frequency/1000000; + } + return 667; } static char *sm_get_memvendor (char *name, int table_num) -{ +{ + if (table_num < MAX_RAM_SLOTS && + Platform.RAM.DIMM[table_num].InUse && + strlen(Platform.RAM.DIMM[table_num].Vendor) > 0) + { + DBG("Vendor[%d]='%s'\n", table_num, Platform.RAM.DIMM[table_num].Vendor); + return Platform.RAM.DIMM[table_num].Vendor; + } return "N/A"; } static char *sm_get_memserial (char *name, int table_num) { + if (table_num < MAX_RAM_SLOTS && + Platform.RAM.DIMM[table_num].InUse && + strlen(Platform.RAM.DIMM[table_num].SerialNo) > 0) + { + DBG("SerialNo[%d]='%s'\n", table_num, Platform.RAM.DIMM[table_num].SerialNo); + return Platform.RAM.DIMM[table_num].SerialNo; + } return "N/A"; } static char *sm_get_mempartno (char *name, int table_num) { + if (table_num < MAX_RAM_SLOTS && + Platform.RAM.DIMM[table_num].InUse && + strlen(Platform.RAM.DIMM[table_num].PartNo) > 0) + { + DBG("PartNo[%d]='%s'\n", table_num, Platform.RAM.DIMM[table_num].PartNo); + return Platform.RAM.DIMM[table_num].PartNo; + } return "N/A"; } @@ -198,22 +220,22 @@ {.name="SMmanufacter", .table_type= 1, .value_type=SMSTRING, .offset=0x04, .auto_str=sm_get_defstr }, {.name="SMproductname", .table_type= 1, .value_type=SMSTRING, .offset=0x05, .auto_str=sm_get_defstr }, {.name="SMsystemversion", .table_type= 1, .value_type=SMSTRING, .offset=0x06, .auto_str=sm_get_defstr }, - {.name="SMserial", .table_type= 1, .value_type=SMSTRING, .offset=0x07, .auto_str=sm_get_defstr }, - {.name="SMUUID", .table_type= 1, .value_type=SMOWORD, .offset=0x08, .auto_oword=0 }, - {.name="SMfamily", .table_type= 1, .value_type=SMSTRING, .offset=0x1a, .auto_str=sm_get_defstr }, + {.name="SMserial", .table_type= 1, .value_type=SMSTRING, .offset=0x07, .auto_str=sm_get_defstr }, + {.name="SMUUID", .table_type= 1, .value_type=SMOWORD, .offset=0x08, .auto_oword=0 }, + {.name="SMfamily", .table_type= 1, .value_type=SMSTRING, .offset=0x1a, .auto_str=sm_get_defstr }, {.name="SMboardmanufacter", .table_type= 2, .value_type=SMSTRING, .offset=0x04, .auto_str=sm_get_defstr }, {.name="SMboardproduct", .table_type= 2, .value_type=SMSTRING, .offset=0x05, .auto_str=sm_get_defstr }, - {.name="SMexternalclock", .table_type= 4, .value_type=SMWORD, .offset=0x12, .auto_int=sm_get_fsb }, - {.name="SMmaximalclock", .table_type= 4, .value_type=SMWORD, .offset=0x14, .auto_int=sm_get_cpu }, - {.name="SMmemdevloc", .table_type=17, .value_type=SMSTRING, .offset=0x10, .auto_str=0 }, - {.name="SMmembankloc", .table_type=17, .value_type=SMSTRING, .offset=0x11, .auto_str=0 }, - {.name="SMmemtype", .table_type=17, .value_type=SMBYTE, .offset=0x12, .auto_int=sm_get_memtype}, - {.name="SMmemspeed", .table_type=17, .value_type=SMWORD, .offset=0x15, .auto_int=sm_get_memspeed}, + {.name="SMexternalclock", .table_type= 4, .value_type=SMWORD, .offset=0x12, .auto_int=sm_get_fsb }, + {.name="SMmaximalclock", .table_type= 4, .value_type=SMWORD, .offset=0x14, .auto_int=sm_get_cpu }, + {.name="SMmemdevloc", .table_type=17, .value_type=SMSTRING, .offset=0x10, .auto_str=0 }, + {.name="SMmembankloc", .table_type=17, .value_type=SMSTRING, .offset=0x11, .auto_str=0 }, + {.name="SMmemtype", .table_type=17, .value_type=SMBYTE, .offset=0x12, .auto_int=sm_get_memtype}, + {.name="SMmemspeed", .table_type=17, .value_type=SMWORD, .offset=0x15, .auto_int=sm_get_memspeed}, {.name="SMmemmanufacter", .table_type=17, .value_type=SMSTRING, .offset=0x17, .auto_str=sm_get_memvendor}, {.name="SMmemserial", .table_type=17, .value_type=SMSTRING, .offset=0x18, .auto_str=sm_get_memserial}, - {.name="SMmempart", .table_type=17, .value_type=SMSTRING, .offset=0x1A, .auto_str=sm_get_mempartno}, - {.name="SMcputype", .table_type=131,.value_type=SMWORD, .offset=0x04, .auto_int=sm_get_cputype}, - {.name="SMbusspeed", .table_type=132,.value_type=SMWORD, .offset=0x04, .auto_str=0 } + {.name="SMmempart", .table_type=17, .value_type=SMSTRING, .offset=0x1A, .auto_str=sm_get_mempartno}, + {.name="SMcputype", .table_type=131,.value_type=SMWORD, .offset=0x04, .auto_int=sm_get_cputype}, + {.name="SMbusspeed", .table_type=132,.value_type=SMWORD, .offset=0x04, .auto_str=0 } }; struct smbios_table_description smbios_table_descriptions[]= @@ -227,169 +249,171 @@ {.type=132, .len=0x06, .numfunc=sm_one} }; -static inline struct SMBEntryPoint * getAddressOfSmbiosTable() +struct SMBEntryPoint *getAddressOfSmbiosTable(void) { /* First see if we can even find the damn SMBIOS table - * The logic here is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking - * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_"). - */ - void *smbios_addr = (void*)SMBIOS_RANGE_START; - for(; (smbios_addr <= (void*)SMBIOS_RANGE_END) && (*(uint32_t*)smbios_addr != SMBIOS_ANCHOR_UINT32_LE); smbios_addr += 16) - ; - if(smbios_addr <= (void*)SMBIOS_RANGE_END) - { - /* NOTE: The specification does not specifically state what to do in the event of finding an - * SMBIOS anchor on an invalid table. It might be better to move this code into the for loop - * so that searching can continue. - */ - uint8_t csum = checksum8(smbios_addr, sizeof(struct SMBEntryPoint)); - /* The table already contains the checksum so we merely need to see if its checksum is now zero. */ - if(csum != 0) - { - printf("Found SMBIOS anchor but bad table checksum. Assuming no SMBIOS.\n"); - sleep(5); - smbios_addr = 0; - } - } - else - { - /* If this happens, it's possible that a PnP BIOS call can be done to retrieve the address of the table. - * The latest versions of the spec state that modern programs should not even attempt to do this. */ - printf("Unable to find SMBIOS table.\n"); - sleep(5); - smbios_addr = 0; - } - return smbios_addr; + * The logic here is to start at 0xf0000 and end at 0xfffff iterating 16 bytes at a time looking + * for the SMBIOS entry-point structure anchor (literal ASCII "_SM_"). + */ + void *smbios_addr = (void*)SMBIOS_RANGE_START; + + for (; (smbios_addr<=(void*)SMBIOS_RANGE_END) && (*(uint32_t*)smbios_addr!=SMBIOS_ANCHOR_UINT32_LE); smbios_addr+=16) ; + if (smbios_addr <= (void*)SMBIOS_RANGE_END) { + /* NOTE: The specification does not specifically state what to do in the event of finding an + * SMBIOS anchor on an invalid table. It might be better to move this code into the for loop + * so that searching can continue. + */ + uint8_t csum = checksum8(smbios_addr, sizeof(struct SMBEntryPoint)); + /* The table already contains the checksum so we merely need to see if its checksum is now zero. */ + if (csum != 0) { + printf("Found SMBIOS anchor but bad table checksum. Assuming no SMBIOS.\n"); + sleep(5); + smbios_addr = 0; + } + } else { + /* If this happens, it's possible that a PnP BIOS call can be done to retrieve the address of the table. + * The latest versions of the spec state that modern programs should not even attempt to do this. + */ + printf("Unable to find SMBIOS table.\n"); + sleep(5); + smbios_addr = 0; + } + return smbios_addr; } /* Compute necessary space requirements for new smbios */ -struct SMBEntryPoint * -smbios_dry_run (struct SMBEntryPoint * origsmbios) +struct SMBEntryPoint *smbios_dry_run(struct SMBEntryPoint *origsmbios) { - struct SMBEntryPoint *ret; - char *smbiostables=0; - char *tablesptr; - int origsmbiosnum=0; - int i, j; - int tablespresent[256]; - BOOL do_auto=1; + struct SMBEntryPoint *ret; + char *smbiostables; + char *tablesptr; + int origsmbiosnum; + int i, j; + int tablespresent[256]; + bool do_auto=true; - getBoolForKey("SMBIOSdefaults",&do_auto,&bootInfo->bootConfig); + bzero(tablespresent, sizeof(tablespresent)); - for (i=0;i<256;i++) - tablespresent[i]=0; - ret=(struct SMBEntryPoint *)AllocateKernelMemory(sizeof (struct SMBEntryPoint)); - if (origsmbios) - { - smbiostables=(char *)origsmbios->dmi.tableAddress; - origsmbiosnum=origsmbios->dmi.structureCount; - } + getBoolForKey(kSMBIOSdefaults, &do_auto, &bootInfo->bootConfig); + + ret = (struct SMBEntryPoint *)AllocateKernelMemory(sizeof(struct SMBEntryPoint)); + if (origsmbios) { + smbiostables = (char *)origsmbios->dmi.tableAddress; + origsmbiosnum = origsmbios->dmi.structureCount; + } else { + smbiostables = NULL; + origsmbiosnum = 0; + } + // _SM_ - ret->anchor[0]=0x5f; - ret->anchor[1]=0x53; - ret->anchor[2]=0x4d; - ret->anchor[3]=0x5f; - ret->entryPointLength=sizeof (*ret); - ret->majorVersion=2; - ret->minorVersion=1; - ret->maxStructureSize=0; - ret->entryPointRevision=0; - for (i=0;i<5;i++) - ret->formattedArea[i]=0; + ret->anchor[0] = 0x5f; + ret->anchor[1] = 0x53; + ret->anchor[2] = 0x4d; + ret->anchor[3] = 0x5f; + ret->entryPointLength = sizeof(*ret); + ret->majorVersion = 2; + ret->minorVersion = 1; + ret->maxStructureSize = 0; + ret->entryPointRevision = 0; + for (i=0;i<5;i++) { + ret->formattedArea[i] = 0; + } //_DMI_ - ret->dmi.anchor[0]=0x5f; - ret->dmi.anchor[1]=0x44; - ret->dmi.anchor[2]=0x4d; - ret->dmi.anchor[3]=0x49; - ret->dmi.anchor[4]=0x5f; - ret->dmi.tableLength=0; - ret->dmi.tableAddress=0; - ret->dmi.structureCount=0; - ret->dmi.bcdRevision=0x21; - tablesptr=smbiostables; - if (smbiostables) - for (i=0;ilength; - stringsptr=tablesptr; - for (;tablesptr[0]!=0 || tablesptr[1]!=0;tablesptr++); - tablesptr+=2; - stringlen=tablesptr-stringsptr-1; - if (stringlen==1) - stringlen=0; - for (j=0;jtype]+1); - if (smbios_properties[j].table_type==cur->type - && smbios_properties[j].value_type==SMSTRING - && (getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig) - || getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig))) - stringlen+=size+1; - else if (smbios_properties[j].table_type==cur->type - && smbios_properties[j].value_type==SMSTRING - && do_auto && smbios_properties[j].auto_str) - stringlen+=strlen(smbios_properties[j].auto_str(smbios_properties[j].name,tablespresent[cur->type]))+1; + ret->dmi.anchor[0] = 0x5f; + ret->dmi.anchor[1] = 0x44; + ret->dmi.anchor[2] = 0x4d; + ret->dmi.anchor[3] = 0x49; + ret->dmi.anchor[4] = 0x5f; + ret->dmi.tableLength = 0; + ret->dmi.tableAddress = 0; + ret->dmi.structureCount = 0; + ret->dmi.bcdRevision = 0x21; + tablesptr = smbiostables; + if (smbiostables) { + for (i=0; ilength; + stringsptr = tablesptr; + for (; tablesptr[0]!=0 || tablesptr[1]!=0; tablesptr++); + tablesptr += 2; + stringlen = tablesptr - stringsptr - 1; + if (stringlen == 1) { + stringlen = 0; } - if (stringlen==0) - stringlen=1; + for (j=0; jtype] + 1); + if (smbios_properties[j].table_type == cur->type && + smbios_properties[j].value_type == SMSTRING && + (getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig) || + getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig))) + { + stringlen += size + 1; + } else if (smbios_properties[j].table_type == cur->type && + smbios_properties[j].value_type == SMSTRING && + do_auto && smbios_properties[j].auto_str) + { + stringlen += strlen(smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[cur->type])) + 1; + } + } + if (stringlen == 0) { + stringlen = 1; + } stringlen++; - if (ret->maxStructureSizelength+stringlen) + if (ret->maxStructureSize < cur->length+stringlen) { ret->maxStructureSize=cur->length+stringlen; - ret->dmi.tableLength+=cur->length+stringlen; + } + ret->dmi.tableLength += cur->length+stringlen; ret->dmi.structureCount++; tablespresent[cur->type]++; } - for (i=0;ismbiosConfig)) - numnec=-1; - if (numnec==-1 && do_auto && smbios_table_descriptions[i].numfunc) - numnec=smbios_table_descriptions[i].numfunc (smbios_table_descriptions[i].type); - - while (tablespresent[smbios_table_descriptions[i].type]smbiosConfig) - || getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig))) - stringlen+=size+1; - else if (smbios_properties[j].table_type - ==smbios_table_descriptions[i].type - && smbios_properties[j].value_type==SMSTRING - && do_auto && smbios_properties[j].auto_str) - stringlen+=strlen(smbios_properties[j].auto_str - (smbios_properties[j].name, - tablespresent[smbios_table_descriptions[i].type]))+1; + } + for (i=0; ismbiosConfig)) { + numnec = -1; + } + if (numnec==-1 && do_auto && smbios_table_descriptions[i].numfunc) { + numnec = smbios_table_descriptions[i].numfunc(smbios_table_descriptions[i].type); + } + while (tablespresent[smbios_table_descriptions[i].type] < numnec) { + int stringlen = 0; + for (j=0; jsmbiosConfig) || + getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig))) + { + stringlen += size + 1; + } else if (smbios_properties[j].table_type == smbios_table_descriptions[i].type && + smbios_properties[j].value_type==SMSTRING && + do_auto && smbios_properties[j].auto_str) + { + stringlen += strlen(smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[smbios_table_descriptions[i].type])) + 1; + } } - if (stringlen==0) - stringlen=1; + if (stringlen == 0) { + stringlen = 1; + } stringlen++; - if (ret->maxStructureSizemaxStructureSize=smbios_table_descriptions[i].len+stringlen; - ret->dmi.tableLength+=smbios_table_descriptions[i].len+stringlen; + if (ret->maxStructureSize < smbios_table_descriptions[i].len+stringlen) { + ret->maxStructureSize = smbios_table_descriptions[i].len + stringlen; + } + ret->dmi.tableLength += smbios_table_descriptions[i].len + stringlen; ret->dmi.structureCount++; tablespresent[smbios_table_descriptions[i].type]++; } @@ -397,306 +421,281 @@ return ret; } -void -smbios_real_run (struct SMBEntryPoint * origsmbios, - struct SMBEntryPoint * newsmbios) +void smbios_real_run(struct SMBEntryPoint * origsmbios, struct SMBEntryPoint * newsmbios) { - char *smbiostables=0; + char *smbiostables; char *tablesptr, *newtablesptr; - int origsmbiosnum=0; + int origsmbiosnum; // bitmask of used handles uint8_t handles[8192]; uint16_t nexthandle=0; int i, j; int tablespresent[256]; - BOOL do_auto=1; + bool do_auto=true; - getBoolForKey("SMBIOSdefaults",&do_auto,&bootInfo->bootConfig); + bzero(tablespresent, sizeof(tablespresent)); + bzero(handles, sizeof(handles)); + + getBoolForKey(kSMBIOSdefaults, &do_auto, &bootInfo->bootConfig); - for (i=0;i<256;i++) - tablespresent[i]=0; - - memset (handles,0,8192); - newsmbios->dmi.tableAddress=(uint32_t)AllocateKernelMemory(newsmbios->dmi.tableLength); - if (origsmbios) - { - smbiostables=(char *) origsmbios->dmi.tableAddress; - origsmbiosnum=origsmbios->dmi.structureCount; - } - tablesptr=smbiostables; - newtablesptr=(char *) newsmbios->dmi.tableAddress; - if (smbiostables) - for (i=0;ihandle)/8]|=1<<((oldcur->handle)%8); - - memcpy (newcur,oldcur, oldcur->length); - - tablesptr+=oldcur->length; - stringsptr=tablesptr; - newtablesptr+=oldcur->length; - for (;tablesptr[0]!=0 || tablesptr[1]!=0;tablesptr++) - if (tablesptr[0]==0) + newsmbios->dmi.tableAddress = (uint32_t)AllocateKernelMemory(newsmbios->dmi.tableLength); + if (origsmbios) { + smbiostables = (char *)origsmbios->dmi.tableAddress; + origsmbiosnum = origsmbios->dmi.structureCount; + } else { + smbiostables = NULL; + origsmbiosnum = 0; + } + tablesptr = smbiostables; + newtablesptr = (char *)newsmbios->dmi.tableAddress; + if (smbiostables) { + for (i=0; ihandle) / 8] |= 1 << ((oldcur->handle) % 8); + memcpy(newcur,oldcur, oldcur->length); + + tablesptr += oldcur->length; + stringsptr = tablesptr; + newtablesptr += oldcur->length; + for (;tablesptr[0]!=0 || tablesptr[1]!=0; tablesptr++) { + if (tablesptr[0] == 0) { nstrings++; - if (tablesptr!=stringsptr) + } + } + if (tablesptr != stringsptr) { nstrings++; - tablesptr+=2; - memcpy (newtablesptr,stringsptr,tablesptr-stringsptr); + } + tablesptr += 2; + memcpy(newtablesptr, stringsptr, tablesptr-stringsptr); //point to next possible space for a string - newtablesptr+=tablesptr-stringsptr-1; - if (nstrings==0) + newtablesptr += tablesptr - stringsptr - 1; + if (nstrings == 0) { newtablesptr--; - for (j=0;jtype]+1); - - if (smbios_properties[j].table_type==newcur->type) - switch (smbios_properties[j].value_type) - { + } + for (j=0; jtype] + 1); + if (smbios_properties[j].table_type == newcur->type) { + switch (smbios_properties[j].value_type) { case SMSTRING: - if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig) - ||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig)) + if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) || + getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)) { - memcpy (newtablesptr, str,size); - newtablesptr[size]=0; - newtablesptr+=size+1; - *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings; + memcpy(newtablesptr, str, size); + newtablesptr[size] = 0; + newtablesptr += size + 1; + *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings; + } else if (do_auto && smbios_properties[j].auto_str) { + str = smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]); + size = strlen(str); + memcpy(newtablesptr, str, size); + newtablesptr[size] = 0; + newtablesptr += size + 1; + *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings; } - else if (do_auto && smbios_properties[j].auto_str) - { - str=smbios_properties[j].auto_str(smbios_properties[j].name,tablespresent[newcur->type]); - size=strlen (str); - memcpy (newtablesptr, str,size); - newtablesptr[size]=0; - newtablesptr+=size+1; - *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings; - } - break; - + case SMOWORD: - if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig) - ||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig)) + if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) || + getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)) { - int k=0, t=0, kk=0; - const char *ptr=str; - memset(((char*)newcur)+smbios_properties[j].offset, 0, 16); - while (ptr-str=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) - ptr+=2; - for (;ptr-str='0' && *ptr<='9') + } + if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) { + ptr += 2; + } + for (;ptr-str='0' && *ptr<='9') { (t=(t<<4)|(*ptr-'0')),kk++; - if (*ptr>='a' && *ptr<='f') + } + if (*ptr>='a' && *ptr<='f') { (t=(t<<4)|(*ptr-'a'+10)),kk++; - if (*ptr>='A' && *ptr<='F') + } + if (*ptr>='A' && *ptr<='F') { (t=(t<<4)|(*ptr-'A'+10)),kk++; - if (kk==2) - { - *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset+k))=t; + } + if (kk == 2) { + *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset + k)) = t; k++; - kk=0; - t=0; + kk = 0; + t = 0; } } } break; - + case SMBYTE: - if (getIntForKey(altname,&num,&bootInfo->smbiosConfig) - ||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig)) - *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=num; - else if (do_auto && smbios_properties[j].auto_int) - *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset)) - =smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); + if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) || + getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig)) + { + *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = num; + } else if (do_auto && smbios_properties[j].auto_int) { + *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); + } break; - + case SMWORD: - if (getIntForKey(altname,&num,&bootInfo->smbiosConfig) - ||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig)) - *((uint16_t*)(((char*)newcur)+smbios_properties[j].offset))=num; - else if (do_auto && smbios_properties[j].auto_int) - *((uint16_t*)(((char*)newcur)+smbios_properties[j].offset)) - =smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); + if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) || + getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig)) + { + *((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = num; + } else if (do_auto && smbios_properties[j].auto_int) { + *((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); + } break; + } } } - if (nstrings==0) - { - newtablesptr[0]=0; + if (nstrings == 0) { + newtablesptr[0] = 0; newtablesptr++; } - newtablesptr[0]=0; + newtablesptr[0] = 0; newtablesptr++; tablespresent[newcur->type]++; } - for (i=0;ismbiosConfig)) - numnec=-1; - if (numnec==-1 && do_auto && smbios_table_descriptions[i].numfunc) - numnec=smbios_table_descriptions[i].numfunc (smbios_table_descriptions[i].type); - - while (tablespresent[smbios_table_descriptions[i].type]smbiosConfig)) { + numnec = -1; + } + if (numnec == -1 && do_auto && smbios_table_descriptions[i].numfunc) { + numnec = smbios_table_descriptions[i].numfunc(smbios_table_descriptions[i].type); + } + while (tablespresent[smbios_table_descriptions[i].type] < numnec) { + struct smbios_table_header *newcur = (struct smbios_table_header *) newtablesptr; + int nstrings = 0; + + memset(newcur,0, smbios_table_descriptions[i].len); + while (handles[(nexthandle)/8] & (1 << ((nexthandle) % 8))) { nexthandle++; - newcur->handle=nexthandle; - handles[nexthandle/8]|=1<<(nexthandle%8); - newcur->type=smbios_table_descriptions[i].type; - newcur->length=smbios_table_descriptions[i].len; - newtablesptr+=smbios_table_descriptions[i].len; - for (j=0;jtype]+1); - - if (smbios_properties[j].table_type==newcur->type) - switch (smbios_properties[j].value_type) - { + } + newcur->handle = nexthandle; + handles[nexthandle / 8] |= 1 << (nexthandle % 8); + newcur->type = smbios_table_descriptions[i].type; + newcur->length = smbios_table_descriptions[i].len; + newtablesptr += smbios_table_descriptions[i].len; + for (j=0; jtype] + 1); + if (smbios_properties[j].table_type == newcur->type) { + switch (smbios_properties[j].value_type) { case SMSTRING: - if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig) - ||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig)) + if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) || + getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)) { - memcpy (newtablesptr, str,size); - newtablesptr[size]=0; - newtablesptr+=size+1; - *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings; + memcpy(newtablesptr, str, size); + newtablesptr[size] = 0; + newtablesptr += size + 1; + *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings; + } else if (do_auto && smbios_properties[j].auto_str) { + str = smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]); + size = strlen(str); + memcpy(newtablesptr, str, size); + newtablesptr[size] = 0; + newtablesptr += size + 1; + *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings; } - else if (do_auto && smbios_properties[j].auto_str) - { - str=smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]); - size=strlen (str); - memcpy (newtablesptr, str,size); - newtablesptr[size]=0; - newtablesptr+=size+1; - *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings; - } break; - + case SMOWORD: - if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig) - ||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig)) + if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) || + getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)) { - int k=0, t=0, kk=0; - const char *ptr=str; - memset(((char*)newcur)+smbios_properties[j].offset, 0, 16); - while (ptr-str=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) - ptr+=2; - for (;ptr-str='0' && *ptr<='9') + } + if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) { + ptr += 2; + } + for (;ptr-str='0' && *ptr<='9') { (t=(t<<4)|(*ptr-'0')),kk++; - if (*ptr>='a' && *ptr<='f') + } + if (*ptr>='a' && *ptr<='f') { (t=(t<<4)|(*ptr-'a'+10)),kk++; - if (*ptr>='A' && *ptr<='F') + } + if (*ptr>='A' && *ptr<='F') { (t=(t<<4)|(*ptr-'A'+10)),kk++; - if (kk==2) - { - *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset+k))=t; + } + if (kk == 2) { + *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset + k)) = t; k++; - kk=0; - t=0; + kk = 0; + t = 0; } } } break; case SMBYTE: - if (getIntForKey(altname,&num,&bootInfo->smbiosConfig) - ||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig)) - *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=num; - else if (do_auto && smbios_properties[j].auto_int) - *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset)) - =smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); + if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) || + getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig)) + { + *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = num; + } else if (do_auto && smbios_properties[j].auto_int) { + *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); + } break; case SMWORD: - if (getIntForKey(altname,&num,&bootInfo->smbiosConfig) - ||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig)) - *((uint16_t*)(((char*)newcur)+smbios_properties[j].offset))=num; - else if (do_auto && smbios_properties[j].auto_int) - *((uint16_t*)(((char*)newcur)+smbios_properties[j].offset)) - =smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); + if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) || + getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig)) + { + *((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = num; + } else if (do_auto && smbios_properties[j].auto_int) { + *((uint16_t*)(((char*)newcur)+smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); + } break; + } } } - if (nstrings==0) - { - newtablesptr[0]=0; + if (nstrings == 0) { + newtablesptr[0] = 0; newtablesptr++; } - newtablesptr[0]=0; + newtablesptr[0] = 0; newtablesptr++; tablespresent[smbios_table_descriptions[i].type]++; } } - newsmbios->dmi.checksum=0; - newsmbios->dmi.checksum=256-checksum8 (&newsmbios->dmi,sizeof (newsmbios->dmi)); - newsmbios->checksum=0; - newsmbios->checksum=256-checksum8 (newsmbios,sizeof (*newsmbios)); - verbose("Patched DMI Table.\n"); + newsmbios->dmi.checksum = 0; + newsmbios->dmi.checksum = 256 - checksum8(&newsmbios->dmi, sizeof(newsmbios->dmi)); + newsmbios->checksum = 0; + newsmbios->checksum = 256 - checksum8(newsmbios, sizeof(*newsmbios)); + verbose("Patched DMI Table\n"); } -inline struct SMBEntryPoint * -getSmbios() +struct SMBEntryPoint *getSmbios(void) { - const char *smbios_filename; - char dirSpec[512]; - int len; struct SMBEntryPoint *orig_address; struct SMBEntryPoint *new_address; - orig_address=getAddressOfSmbiosTable(); - if (!getValueForKey("SMBIOS", &smbios_filename, &len, &bootInfo->bootConfig)) - smbios_filename = "smbios.plist"; - - sprintf(dirSpec, "%s", smbios_filename); - if (loadConfigFile(dirSpec, &bootInfo->smbiosConfig) == -1) - { - sprintf(dirSpec, "/Extra/%s", smbios_filename); - if (loadConfigFile(dirSpec, &bootInfo->smbiosConfig) == -1) - { - sprintf(dirSpec, "bt(0,0)/Extra/%s", smbios_filename); - if (loadConfigFile(dirSpec, &bootInfo->smbiosConfig) == -1) - { - verbose("No SMBIOS replacement found.\n"); - } - } - } - -// if( (loadConfigFile("/Extra/smbios.plist", &bootInfo->smbiosConfig)) == -1 ) -// loadConfigFile("bt(0,0)/Extra/smbios.plist", &bootInfo->smbiosConfig); // TODO: do we need this ? - + orig_address=getAddressOfSmbiosTable(); new_address = smbios_dry_run(orig_address); smbios_real_run(orig_address, new_address); return new_address; Index: trunk/i386/libsaio/smbios_patcher.h =================================================================== --- trunk/i386/libsaio/smbios_patcher.h (revision 22) +++ trunk/i386/libsaio/smbios_patcher.h (revision 23) @@ -6,6 +6,7 @@ #define __LIBSAIO_SMBIOS_PATCHER_H #include "libsaio.h" +#include "SMBIOS.h" extern EFI_GUID gEfiAcpiTableGuid; extern EFI_GUID gEfiAcpi20TableGuid; @@ -54,4 +55,6 @@ }; +extern struct SMBEntryPoint * getAddressOfSmbiosTable(void); +extern struct SMBEntryPoint * getSmbios(void); #endif /* !__LIBSAIO_SMBIOS_PATCHER_H */ Index: trunk/i386/libsaio/mem.c =================================================================== --- trunk/i386/libsaio/mem.c (revision 0) +++ trunk/i386/libsaio/mem.c (revision 23) @@ -0,0 +1,26 @@ +/* + * Copyright 2010 AsereBLN. All rights reserved. + * + * mem.c - obtain system memory information + */ + +#include "libsaio.h" +#include "pci.h" +#include "platform.h" +#include "cpu.h" +#include "mem.h" + +#ifndef DEBUG_MEM +#define DEBUG_MEM 0 +#endif + +#if DEBUG_MEM +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + +void scan_memory(PlatformInfo_t *p) +{ + /* NYI */ +} Index: trunk/i386/libsaio/pci_root.c =================================================================== --- trunk/i386/libsaio/pci_root.c (revision 0) +++ trunk/i386/libsaio/pci_root.c (revision 23) @@ -0,0 +1,118 @@ +/* + * Copyright 2009 netkas + */ + +#include "libsaio.h" +#include "boot.h" +#include "bootstruct.h" + +#ifndef DEBUG_PCIROOT +#define DEBUG_PCIROOT 0 +#endif + +#if DEBUG_PCIROOT +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + +static int rootuid = 10; //value means function wasnt ran yet + +static unsigned int findrootuid(unsigned char * dsdt, int len) +{ + int i; + for (i=0; i<64 && ibootConfig)) { + if (isdigit(val[0])) { + rootuid = val[0] - '0'; + } + goto out; + } +#if 0 + /* Chameleon compatibility */ + if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig)) { + if (isdigit(val[0])) { + rootuid = val[0] - '0'; + } + goto out; + } + + /* PCEFI compatibility */ + if (getValueForKey("-pci0", &val, &len, &bootInfo->bootConfig)) { + rootuid = 0; + goto out; + } + if (getValueForKey("-pci1", &val, &len, &bootInfo->bootConfig)) { + rootuid = 1; + goto out; + } +#endif + if (!getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->bootConfig)) { + dsdt_filename="/Extra/DSDT.aml"; + } + + if ((fd = open_bvdev("bt(0,0)", dsdt_filename, 0)) < 0) { + verbose("[WARNING] %s not found\n", dsdt_filename); + goto out; + } + fsize = file_size(fd); + + if ((new_dsdt = malloc(fsize)) == NULL) { + verbose("[ERROR] alloc DSDT memory failed\n"); + close (fd); + goto out; + } + if (read (fd, new_dsdt, fsize) != fsize) { + verbose("[ERROR] read %s failed\n", dsdt_filename); + close (fd); + goto out; + } + close (fd); + + dsdt_uid = findpciroot(new_dsdt, fsize); + free(new_dsdt); + + if (dsdt_uid >= 0 && dsdt_uid <= 9) { + rootuid = dsdt_uid; + } else { + verbose("Could not determine PCI-Root-UID value from DSDT!\n"); + } +out: + verbose("Using PCI-Root-UID value %d\n", rootuid); + return rootuid; +} Index: trunk/i386/libsaio/mem.h =================================================================== --- trunk/i386/libsaio/mem.h (revision 0) +++ trunk/i386/libsaio/mem.h (revision 23) @@ -0,0 +1,15 @@ +/* + * Copyright 2010 AsereBLN. All rights reserved. + * + * mem.h + */ + +#ifndef __LIBSAIO_MEM_H +#define __LIBSAIO_MEM_H + +#include "platform.h" + +extern void scan_memory(PlatformInfo_t *); + + +#endif /* __LIBSAIO_MEM_H */ Index: trunk/i386/libsaio/pci_root.h =================================================================== --- trunk/i386/libsaio/pci_root.h (revision 0) +++ trunk/i386/libsaio/pci_root.h (revision 23) @@ -0,0 +1,13 @@ +/* + * Copyright 2008 mackerintel + */ + +#ifndef __LIBSAIO_PCI_ROOT_H +#define __LIBSAIO_PCI_ROOT_H + +#include "libsaio.h" + + +extern int getPciRootUID(void); + +#endif /* !__LIBSAIO_DSDT_PATCHER_H */ Index: trunk/i386/libsaio/usb.c =================================================================== --- trunk/i386/libsaio/usb.c (revision 22) +++ trunk/i386/libsaio/usb.c (revision 23) @@ -8,6 +8,7 @@ */ #include "libsaio.h" +#include "boot.h" #include "bootstruct.h" #include "pci.h" @@ -23,21 +24,21 @@ int ehci_acquire (pci_dt_t *pci_dev) { - int j,k; - + int j, k; uint32_t base; uint8_t eecp; uint8_t legacy[8]; - - BOOL isOwnershipConflict; - BOOL alwaysHardBIOSReset; + bool isOwnershipConflict; + bool alwaysHardBIOSReset; - if (!getBoolForKey("EHCIhard", &alwaysHardBIOSReset, &bootInfo->bootConfig)) - alwaysHardBIOSReset = 1; - + alwaysHardBIOSReset = false; + if (!getBoolForKey(kEHCIhard, &alwaysHardBIOSReset, &bootInfo->bootConfig)) { + alwaysHardBIOSReset = true; + } + pci_config_write16(pci_dev->dev.addr, 0x04, 0x0002); base = pci_config_read32(pci_dev->dev.addr, 0x10); - + verbose("EHCI controller [%04x:%04x] at %02x:%2x.%x DMA @%x\n", pci_dev->vendor_id, pci_dev->device_id, pci_dev->dev.bits.bus, pci_dev->dev.bits.dev, pci_dev->dev.bits.func, @@ -48,9 +49,8 @@ DBG("Config space too small: no legacy implementation\n"); return 1; } - eecp=*((unsigned char*)(base + 9)); - if (!eecp) - { + eecp = *((unsigned char*)(base + 9)); + if (!eecp) { DBG("No extended capabilities: no legacy implementation\n"); return 1; } @@ -58,11 +58,10 @@ DBG("eecp=%x\n",eecp); // bad way to do it - // pci_conf_write(pci_dev->dev.addr, eecp, 4, 0x01000001); - for (j = 0; j < 8; j++) - { + // pci_conf_write(pci_dev->dev.addr, eecp, 4, 0x01000001); + for (j = 0; j < 8; j++) { legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j); - DBG("%02x ",legacy[j]); + DBG("%02x ", legacy[j]); } DBG("\n"); @@ -71,76 +70,78 @@ // Definitely needed during reboot on 10.4.6 isOwnershipConflict = ((legacy[3] & 1 != 0) && (legacy[2] & 1 != 0)); - if (!alwaysHardBIOSReset && isOwnershipConflict) - { + if (!alwaysHardBIOSReset && isOwnershipConflict) { DBG("EHCI - Ownership conflict - attempting soft reset ...\n"); DBG("EHCI - toggle OS Ownership to 0\n"); pci_config_write8(pci_dev->dev.addr, eecp + 3, 0); - for (k = 0; k < 25; k++) - { - for (j = 0; j < 8; j++) + for (k = 0; k < 25; k++) { + for (j = 0; j < 8; j++) { legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j); - if (legacy[3] == 0) + } + if (legacy[3] == 0) { break; + } delay(10); } } - + DBG("Found USBLEGSUP_ID - value %x:%x - writing OSOwned\n", legacy[3],legacy[2]); pci_config_write8(pci_dev->dev.addr, eecp + 3, 1); - + // wait for kEHCI_USBLEGSUP_BIOSOwned bit to clear - for (k = 0; k < 25; k++) - { - for (j = 0;j < 8; j++) + for (k = 0; k < 25; k++) { + for (j = 0;j < 8; j++) { legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j); + } DBG ("%x:%x,",legacy[3],legacy[2]); - if (legacy[2] == 0) + if (legacy[2] == 0) { break; + } delay(10); } - - for (j = 0;j < 8; j++) + + for (j = 0;j < 8; j++) { legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j); + } isOwnershipConflict = ((legacy[2]) != 0); - if (isOwnershipConflict) - { + if (isOwnershipConflict) { // Soft reset has failed. Assume SMI being ignored // Hard reset // Force Clear BIOS BIT - DBG("EHCI - Ownership conflict - attempting hard reset ...\n"); DBG ("%x:%x\n",legacy[3],legacy[2]); DBG("EHCI - Force BIOS Ownership to 0\n"); pci_config_write8(pci_dev->dev.addr, eecp + 2, 0); - for (k = 0; k < 25; k++) - { - for (j = 0; j < 8; j++) + for (k = 0; k < 25; k++) { + for (j = 0; j < 8; j++) { legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j); + } DBG ("%x:%x,",legacy[3],legacy[2]); - if ((legacy[2]) == 0) + if ((legacy[2]) == 0) { break; + } delay(10); } // Disable further SMI events - for (j = 4; j < 8; j++) + for (j = 4; j < 8; j++) { pci_config_write8(pci_dev->dev.addr, eecp + j, 0); + } } - - for (j = 0; j < 8; j++) + + for (j = 0; j < 8; j++) { legacy[j] = pci_config_read8(pci_dev->dev.addr, eecp + j); + } DBG ("%x:%x\n",legacy[3],legacy[2]); // Final Ownership Resolution Check... - if (legacy[2]&1) - { + if (legacy[2] & 1) { DBG("EHCI controller unable to take control from BIOS\n"); return 0; } - + DBG("EHCI Acquire OS Ownership done\n"); return 1; } Index: trunk/i386/libsaio/device_inject.c =================================================================== --- trunk/i386/libsaio/device_inject.c (revision 22) +++ trunk/i386/libsaio/device_inject.c (revision 23) @@ -6,8 +6,10 @@ */ #include "libsaio.h" +#include "boot.h" #include "bootstruct.h" #include "pci.h" +#include "pci_root.h" #include "device_inject.h" @@ -29,15 +31,15 @@ char *efi_inject_get_devprop_string(uint32_t *len) { - if(string) - { + if(string) { *len = string->length; return devprop_generate_string(string); } - printf("efi_inject_get_devprop_string NULL trying stringdata\n"); + verbose("efi_inject_get_devprop_string NULL trying stringdata\n"); return NULL; } +/* XXX AsereBLN replace by strtoul */ uint32_t ascii_hex_to_int(char *buff) { uint32_t value = 0, i, digit; @@ -129,7 +131,7 @@ /* Use the static "device-properties" boot config key contents if available, * otheriwse use the generated one. */ - if (!getValueForKey(DEVICE_PROPERTIES_PROP, &val, &cnt, &bootInfo->bootConfig) && string) + if (!getValueForKey(kDeviceProperties, &val, &cnt, &bootInfo->bootConfig) && string) { val = (const char*)string; cnt = strlength * 2; @@ -170,41 +172,29 @@ struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path) { - uint32_t PciRootID = 0; - const char *val; - int len; + struct DevPropDevice *device; + const char pciroot_string[] = "PciRoot(0x"; + const char pci_device_string[] = "Pci(0x"; - struct DevPropDevice *device = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice)); - if(!device || !string || !path) { - if(device) - free(device); + if (string == NULL || path == NULL) { return NULL; } + device = malloc(sizeof(struct DevPropDevice)); - const char pciroot_string[] = "PciRoot(0x"; - const char pci_device_string[] = "Pci(0x"; - - if (getValueForKey("PciRoot", &val, &len, &bootInfo->bootConfig)) - PciRootID = atoi(val); - - if(strncmp(path, pciroot_string, strlen(pciroot_string))) - { + if (strncmp(path, pciroot_string, strlen(pciroot_string))) { printf("ERROR parsing device path\n"); return NULL; } - + memset(device, 0, sizeof(struct DevPropDevice)); - - device->acpi_dev_path._UID = PciRootID; - + device->acpi_dev_path._UID = getPciRootUID(); + int numpaths = 0; int x, curr = 0; char buff[] = "00"; - for(x = 0; x < strlen(path); x++) - { - if(!strncmp(&path[x], pci_device_string, strlen(pci_device_string))) - { + for (x = 0; x < strlen(path); x++) { + if (!strncmp(&path[x], pci_device_string, strlen(pci_device_string))) { x+=strlen(pci_device_string); curr=x; while(path[++x] != ','); Index: trunk/i386/libsaio/device_inject.h =================================================================== --- trunk/i386/libsaio/device_inject.h (revision 22) +++ trunk/i386/libsaio/device_inject.h (revision 23) @@ -63,15 +63,12 @@ struct DevPropDevice **entries; }; -void setupEfiDevices (); - -char *efi_inject_get_devprop_string(uint32_t *len); -int devprop_add_nvidia_template(struct DevPropDevice *device); -int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id); +char *efi_inject_get_devprop_string(uint32_t *len); +int devprop_add_network_template(struct DevPropDevice *device, uint16_t vendor_id); struct DevPropString *devprop_create_string(void); struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path); -int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len); -char *devprop_generate_string(struct DevPropString *string); -void devprop_free_string(struct DevPropString *string); +int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len); +char *devprop_generate_string(struct DevPropString *string); +void devprop_free_string(struct DevPropString *string); #endif /* !__LIBSAIO_DEVICE_INJECT_H */ Index: trunk/i386/libsaio/dsdt_patcher.c =================================================================== --- trunk/i386/libsaio/dsdt_patcher.c (revision 22) +++ trunk/i386/libsaio/dsdt_patcher.c (revision 23) @@ -3,11 +3,13 @@ */ #include "libsaio.h" +#include "boot.h" #include "bootstruct.h" #include "acpi.h" #include "efi_tables.h" #include "fake_efi.h" #include "dsdt_patcher.h" +#include "platform.h" #ifndef DEBUG_DSDT #define DEBUG_DSDT 0 @@ -77,6 +79,7 @@ { // addConfigurationTable(&gEfiAcpiTableGuid, getAddressOfAcpiTable(), "ACPI"); // addConfigurationTable(&gEfiAcpi20TableGuid, getAddressOfAcpi20Table(), "ACPI_20"); + /* XXX aserebln why uint32 cast if pointer is uint64 ? */ acpi10_p = (uint32_t)getAddressOfAcpiTable(); acpi20_p = (uint32_t)getAddressOfAcpi20Table(); addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI"); @@ -85,63 +88,51 @@ } /* Setup ACPI. Replace DSDT if DSDT.aml is found */ -int setupAcpi() +int setupAcpi(void) { int fd, version; void *new_dsdt; const char *dsdt_filename; - char dirspec[512]; int len; - boolean_t drop_ssdt=NO; + bool tmp; + bool drop_ssdt; + bool fix_restart; - //DBG("Enter setupACPI\n"); + if (!getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->bootConfig)) { + dsdt_filename = "/Extra/DSDT.aml"; + } - if (!getValueForKey("DSDT", &dsdt_filename, &len, &bootInfo->bootConfig)) - dsdt_filename="DSDT.aml"; - - // Check booting partition - sprintf(dirspec,"%s",dsdt_filename); - fd=open (dirspec,0); - if (fd<0) - { // Check Extra on booting partition - sprintf(dirspec,"/Extra/%s",dsdt_filename); - fd=open (dirspec,0); - if (fd<0) - { // Fall back to booter partition - sprintf(dirspec,"bt(0,0)/Extra/%s",dsdt_filename); - fd=open (dirspec,0); - if (fd<0) - { - verbose("No DSDT replacement found. Leaving ACPI data as is\n"); - return setupAcpiNoMod(); - } - } + if ((fd = open_bvdev("bt(0,0)", dsdt_filename, 0)) < 0) { + verbose("No DSDT replacement found. Leaving ACPI data as is\n"); + return setupAcpiNoMod(); } - + // Load replacement DSDT - new_dsdt=(void*)AllocateKernelMemory(file_size (fd)); - if (!new_dsdt) - { + new_dsdt = (void*)AllocateKernelMemory(file_size (fd)); + if (!new_dsdt) { printf("Couldn't allocate memory for DSDT\n"); + close(fd); return setupAcpiNoMod(); } - if (read (fd, new_dsdt, file_size (fd))!=file_size (fd)) - { + if (read(fd, new_dsdt, file_size(fd)) != file_size(fd)) { printf("Couldn't read file\n"); + close(fd); return setupAcpiNoMod(); } - close (fd); - + close(fd); DBG("New DSDT Loaded in memory\n"); - - { - BOOL tmp; - drop_ssdt=getBoolForKey("DropSSDT",&tmp, &bootInfo->bootConfig)&&tmp; + + drop_ssdt = getBoolForKey(kDropSSDT, &tmp, &bootInfo->bootConfig) && tmp; + + if (Platform.CPU.Vendor == 0x756E6547) { /* Intel */ + fix_restart = true; + getBoolForKey(kRestartFix, &fix_restart, &bootInfo->bootConfig); + } else { + fix_restart = false; } - + // Do the same procedure for both versions of ACPI - for (version=0;version<2;version++) - { + for (version=0; version<2; version++) { struct acpi_2_rsdp *rsdp, *rsdp_mod; struct acpi_2_rsdt *rsdt, *rsdt_mod; int rsdplength; @@ -216,9 +207,26 @@ continue; } - fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length); - memcpy(fadt_mod, fadt, fadt->Length); + if (fix_restart && fadt->Length < 0x81) { + fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(0x81); + memcpy(fadt_mod, fadt, fadt->Length); + fadt_mod->Length = 0x81; + } else { + fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length); + memcpy(fadt_mod, fadt, fadt->Length); + } + if (fix_restart) { + fadt_mod->Flags |= 0x400; + fadt_mod->Reset_SpaceID = 0x01; + fadt_mod->Reset_BitWidth = 0x08; + fadt_mod->Reset_BitOffset = 0x00; + fadt_mod->Reset_AccessWidth = 0x01; + fadt_mod->Reset_Address = 0x0cf9; + fadt_mod->Reset_Value = 0x06; + verbose("FACP: Restart Fix applied\n"); + } + // Patch DSDT Address DBG("Old DSDT @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT); @@ -307,9 +315,27 @@ printf("FADT incorrect or after 4GB. Dropping XSDT\n"); goto drop_xsdt; } - fadt_mod=(struct acpi_2_fadt*)AllocateKernelMemory(fadt->Length); - memcpy(fadt_mod, fadt, fadt->Length); + if (fix_restart && fadt->Length < 0x81) { + fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(0x81); + memcpy(fadt_mod, fadt, fadt->Length); + fadt_mod->Length = 0x81; + } else { + fadt_mod = (struct acpi_2_fadt*)AllocateKernelMemory(fadt->Length); + memcpy(fadt_mod, fadt, fadt->Length); + } + + if (fix_restart) { + fadt_mod->Flags |= 0x400; + fadt_mod->Reset_SpaceID = 0x01; + fadt_mod->Reset_BitWidth = 0x08; + fadt_mod->Reset_BitOffset = 0x00; + fadt_mod->Reset_AccessWidth = 0x01; + fadt_mod->Reset_Address = 0x0cf9; + fadt_mod->Reset_Value = 0x06; + verbose("FACP: Restart Fix applied\n"); + } + // Patch DSDT Address DBG("Old DSDT @%x,%x\n",fadt_mod->DSDT,fadt_mod->X_DSDT); @@ -377,17 +403,20 @@ verbose("Patched ACPI version %d DSDT\n", version+1); if (version) { + /* XXX aserebln why uint32 cast if pointer is uint64 ? */ acpi20_p = (uint32_t)rsdp_mod; addConfigurationTable(&gEfiAcpi20TableGuid, &acpi20_p, "ACPI_20"); } else { + /* XXX aserebln why uint32 cast if pointer is uint64 ? */ acpi10_p = (uint32_t)rsdp_mod; addConfigurationTable(&gEfiAcpiTableGuid, &acpi10_p, "ACPI"); } } - #if DEBUG_DSDT +#if DEBUG_DSDT + printf("(Press a key to continue...)\n"); getc(); - #endif +#endif return 1; } Index: trunk/i386/libsaio/ntfs.c =================================================================== --- trunk/i386/libsaio/ntfs.c (revision 22) +++ trunk/i386/libsaio/ntfs.c (revision 23) @@ -295,15 +295,15 @@ return; } -BOOL NTFSProbe(const void * buffer) +bool NTFSProbe(const void * buffer) { - BOOL result = FALSE; + bool result = false; const struct bootfile * part_bootfile = buffer; // NTFS boot sector structure // Looking for NTFS signature. if (strncmp((const char *)part_bootfile->bf_sysid, NTFS_BBID, NTFS_BBIDLEN) == 0) - result = TRUE; + result = true; return result; } Index: trunk/i386/libsaio/nvidia.c =================================================================== --- trunk/i386/libsaio/nvidia.c (revision 22) +++ trunk/i386/libsaio/nvidia.c (revision 23) @@ -49,6 +49,7 @@ */ #include "libsaio.h" +#include "boot.h" #include "bootstruct.h" #include "pci.h" #include "platform.h" @@ -65,6 +66,7 @@ #define DBG(x...) #endif +#define NVIDIA_ROM_SIZE 0x10000 #define PATCH_ROM_SUCCESS 1 #define PATCH_ROM_SUCCESS_HAS_LVDS 2 #define PATCH_ROM_FAILED 0 @@ -74,63 +76,23 @@ extern uint32_t devices_number; -const char *nvidia_compatible_0[] = { "@0,compatible", "NVDA,NVMac" }; -const char *nvidia_compatible_1[] = { "@1,compatible", "NVDA,NVMac" }; -const char *nvidia_device_type_0[] = { "@0,device_type", "display" }; -const char *nvidia_device_type_1[] = { "@1,device_type", "display" }; -const char *nvidia_device_type[] = { "device_type", "NVDA,Parent" }; -const char *nvidia_name_0[] = { "@0,name", "NVDA,Display-A" }; -const char *nvidia_name_1[] = { "@1,name", "NVDA,Display-B" }; -const char *nvidia_slot_name[] = { "AAPL,slot-name", "Slot-1"}; +const char *nvidia_compatible_0[] = { "@0,compatible", "NVDA,NVMac" }; +const char *nvidia_compatible_1[] = { "@1,compatible", "NVDA,NVMac" }; +const char *nvidia_device_type_0[] = { "@0,device_type", "display" }; +const char *nvidia_device_type_1[] = { "@1,device_type", "display" }; +const char *nvidia_device_type[] = { "device_type", "NVDA,Parent" }; +const char *nvidia_name_0[] = { "@0,name", "NVDA,Display-A" }; +const char *nvidia_name_1[] = { "@1,name", "NVDA,Display-B" }; +const char *nvidia_slot_name[] = { "AAPL,slot-name", "Slot-1" }; -uint8_t default_NVCAP[]= { -0x04, 0x00, 0x00, 0x00, -0x00, 0x00, 0x0d, 0x00, -0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x0a, -0x00, 0x00, 0x00, 0x00 +static uint8_t default_NVCAP[]= { + 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x00, 0x00 }; -uint16_t swap16(uint16_t toswap) { - return (((toswap & 0x00FF) << 8) | ((toswap & 0xFF00) >> 8)); -} - -// Known cards as of 2008/08/26 static struct nv_chipsets_t NVKnownChipsets[] = { { 0x00000000, "Unknown" }, - { 0x10DE0301, "GeForce FX 5800 Ultra" }, - { 0x10DE0302, "GeForce FX 5800" }, - { 0x10DE0308, "Quadro FX 2000" }, - { 0x10DE0309, "Quadro FX 1000" }, - { 0x10DE0311, "GeForce FX 5600 Ultra" }, - { 0x10DE0312, "GeForce FX 5600" }, - { 0x10DE0314, "GeForce FX 5600XT" }, - { 0x10DE031A, "GeForce FX Go5600" }, - { 0x10DE031B, "GeForce FX Go5650" }, - { 0x10DE031C, "Quadro FX Go700" }, - { 0x10DE0324, "GeForce FX Go5200" }, - { 0x10DE0325, "GeForce FX Go5250" }, - { 0x10DE0326, "GeForce FX 5500" }, - { 0x10DE0328, "GeForce FX Go5200 32M/64M" }, - { 0x10DE032A, "Quadro NVS 55/280 PCI" }, - { 0x10DE032B, "Quadro FX 500/600 PCI" }, - { 0x10DE032C, "GeForce FX Go53xx Series" }, - { 0x10DE032D, "GeForce FX Go5100" }, - { 0x10DE0330, "GeForce FX 5900 Ultra" }, - { 0x10DE0331, "GeForce FX 5900" }, - { 0x10DE0332, "GeForce FX 5900XT" }, - { 0x10DE0333, "GeForce FX 5950 Ultra" }, - { 0x10DE0334, "GeForce FX 5900ZT" }, - { 0x10DE0338, "Quadro FX 3000" }, - { 0x10DE033F, "Quadro FX 700" }, - { 0x10DE0341, "GeForce FX 5700 Ultra" }, - { 0x10DE0342, "GeForce FX 5700" }, - { 0x10DE0343, "GeForce FX 5700LE" }, - { 0x10DE0344, "GeForce FX 5700VE" }, - { 0x10DE0347, "GeForce FX Go5700" }, - { 0x10DE0348, "GeForce FX Go5700" }, - { 0x10DE034C, "Quadro FX Go1000" }, - { 0x10DE034E, "Quadro FX 1100" }, { 0x10DE0040, "GeForce 6800 Ultra" }, { 0x10DE0041, "GeForce 6800" }, { 0x10DE0042, "GeForce 6800 LE" }, @@ -141,6 +103,14 @@ { 0x10DE0047, "GeForce 6800 GS" }, { 0x10DE0048, "GeForce 6800 XT" }, { 0x10DE004E, "Quadro FX 4000" }, + { 0x10DE0090, "GeForce 7800 GTX" }, + { 0x10DE0091, "GeForce 7800 GTX" }, + { 0x10DE0092, "GeForce 7800 GT" }, + { 0x10DE0093, "GeForce 7800 GS" }, + { 0x10DE0095, "GeForce 7800 SLI" }, + { 0x10DE0098, "GeForce Go 7800" }, + { 0x10DE0099, "GeForce Go 7800 GTX" }, + { 0x10DE009D, "Quadro FX 4500" }, { 0x10DE00C0, "GeForce 6800 GS" }, { 0x10DE00C1, "GeForce 6800" }, { 0x10DE00C2, "GeForce 6800 LE" }, @@ -175,20 +145,11 @@ { 0x10DE0168, "GeForce Go 6400" }, { 0x10DE0169, "GeForce 6250" }, { 0x10DE016A, "GeForce 7100 GS" }, - { 0x10DE0211, "GeForce 6800" }, - { 0x10DE0212, "GeForce 6800 LE" }, - { 0x10DE0215, "GeForce 6800 GT" }, - { 0x10DE0218, "GeForce 6800 XT" }, - { 0x10DE0221, "GeForce 6200" }, - { 0x10DE0222, "GeForce 6200 A-LE" }, - { 0x10DE0090, "GeForce 7800 GTX" }, - { 0x10DE0091, "GeForce 7800 GTX" }, - { 0x10DE0092, "GeForce 7800 GT" }, - { 0x10DE0093, "GeForce 7800 GS" }, - { 0x10DE0095, "GeForce 7800 SLI" }, - { 0x10DE0098, "GeForce Go 7800" }, - { 0x10DE0099, "GeForce Go 7800 GTX" }, - { 0x10DE009D, "Quadro FX 4500" }, + { 0x10DE0191, "GeForce 8800 GTX" }, + { 0x10DE0193, "GeForce 8800 GTS" }, + { 0x10DE0194, "GeForce 8800 Ultra" }, + { 0x10DE019D, "Quadro FX 5600" }, + { 0x10DE019E, "Quadro FX 4600" }, { 0x10DE01D1, "GeForce 7300 LE" }, { 0x10DE01D3, "GeForce 7300 SE" }, { 0x10DE01D6, "GeForce Go 7200" }, @@ -201,6 +162,61 @@ { 0x10DE01DD, "GeForce 7500 LE" }, { 0x10DE01DE, "Quadro FX 350" }, { 0x10DE01DF, "GeForce 7300 GS" }, + { 0x10DE0211, "GeForce 6800" }, + { 0x10DE0212, "GeForce 6800 LE" }, + { 0x10DE0215, "GeForce 6800 GT" }, + { 0x10DE0218, "GeForce 6800 XT" }, + { 0x10DE0221, "GeForce 6200" }, + { 0x10DE0222, "GeForce 6200 A-LE" }, + { 0x10DE0240, "GeForce 6150" }, + { 0x10DE0241, "GeForce 6150 LE" }, + { 0x10DE0242, "GeForce 6100" }, + { 0x10DE0244, "GeForce Go 6150" }, + { 0x10DE0247, "GeForce Go 6100" }, + { 0x10DE0290, "GeForce 7900 GTX" }, + { 0x10DE0291, "GeForce 7900 GT" }, + { 0x10DE0292, "GeForce 7900 GS" }, + { 0x10DE0298, "GeForce Go 7900 GS" }, + { 0x10DE0299, "GeForce Go 7900 GTX" }, + { 0x10DE029A, "Quadro FX 2500M" }, + { 0x10DE029B, "Quadro FX 1500M" }, + { 0x10DE029C, "Quadro FX 5500" }, + { 0x10DE029D, "Quadro FX 3500" }, + { 0x10DE029E, "Quadro FX 1500" }, + { 0x10DE029F, "Quadro FX 4500 X2" }, + { 0x10DE0301, "GeForce FX 5800 Ultra" }, + { 0x10DE0302, "GeForce FX 5800" }, + { 0x10DE0308, "Quadro FX 2000" }, + { 0x10DE0309, "Quadro FX 1000" }, + { 0x10DE0311, "GeForce FX 5600 Ultra" }, + { 0x10DE0312, "GeForce FX 5600" }, + { 0x10DE0314, "GeForce FX 5600XT" }, + { 0x10DE031A, "GeForce FX Go5600" }, + { 0x10DE031B, "GeForce FX Go5650" }, + { 0x10DE031C, "Quadro FX Go700" }, + { 0x10DE0324, "GeForce FX Go5200" }, + { 0x10DE0325, "GeForce FX Go5250" }, + { 0x10DE0326, "GeForce FX 5500" }, + { 0x10DE0328, "GeForce FX Go5200 32M/64M" }, + { 0x10DE032A, "Quadro NVS 55/280 PCI" }, + { 0x10DE032B, "Quadro FX 500/600 PCI" }, + { 0x10DE032C, "GeForce FX Go53xx Series" }, + { 0x10DE032D, "GeForce FX Go5100" }, + { 0x10DE0330, "GeForce FX 5900 Ultra" }, + { 0x10DE0331, "GeForce FX 5900" }, + { 0x10DE0332, "GeForce FX 5900XT" }, + { 0x10DE0333, "GeForce FX 5950 Ultra" }, + { 0x10DE0334, "GeForce FX 5900ZT" }, + { 0x10DE0338, "Quadro FX 3000" }, + { 0x10DE033F, "Quadro FX 700" }, + { 0x10DE0341, "GeForce FX 5700 Ultra" }, + { 0x10DE0342, "GeForce FX 5700" }, + { 0x10DE0343, "GeForce FX 5700LE" }, + { 0x10DE0344, "GeForce FX 5700VE" }, + { 0x10DE0347, "GeForce FX Go5700" }, + { 0x10DE0348, "GeForce FX Go5700" }, + { 0x10DE034C, "Quadro FX Go1000" }, + { 0x10DE034E, "Quadro FX 1100" }, { 0x10DE0391, "GeForce 7600 GT" }, { 0x10DE0392, "GeForce 7600 GS" }, { 0x10DE0393, "GeForce 7300 GT" }, @@ -213,29 +229,6 @@ { 0x10DE039B, "GeForce Go 7900 SE" }, { 0x10DE039C, "Quadro FX 550M" }, { 0x10DE039E, "Quadro FX 560" }, - { 0x10DE0290, "GeForce 7900 GTX" }, - { 0x10DE0291, "GeForce 7900 GT" }, - { 0x10DE0292, "GeForce 7900 GS" }, - { 0x10DE0298, "GeForce Go 7900 GS" }, - { 0x10DE0299, "GeForce Go 7900 GTX" }, - { 0x10DE029A, "Quadro FX 2500M" }, - { 0x10DE029B, "Quadro FX 1500M" }, - { 0x10DE029C, "Quadro FX 5500" }, - { 0x10DE029D, "Quadro FX 3500" }, - { 0x10DE029E, "Quadro FX 1500" }, - { 0x10DE029F, "Quadro FX 4500 X2" }, - { 0x10DE0240, "GeForce 6150" }, - { 0x10DE0241, "GeForce 6150 LE" }, - { 0x10DE0242, "GeForce 6100" }, - { 0x10DE0244, "GeForce Go 6150" }, - { 0x10DE0247, "GeForce Go 6100" }, - - /*************** G8x ***************/ - { 0x10DE0191, "GeForce 8800 GTX" }, - { 0x10DE0193, "GeForce 8800 GTS" }, - { 0x10DE0194, "GeForce 8800 Ultra" }, - { 0x10DE019D, "Quadro FX 5600" }, - { 0x10DE019E, "Quadro FX 4600" }, { 0x10DE0400, "GeForce 8600 GTS" }, { 0x10DE0401, "GeForce 8600 GT" }, { 0x10DE0402, "GeForce 8600 GT" }, @@ -267,8 +260,11 @@ { 0x10DE042D, "Quadro FX 360M" }, { 0x10DE042E, "GeForce 9300M G" }, { 0x10DE042F, "Quadro NVS 290" }, + { 0x10DE05E0, "GeForce GTX 295" }, { 0x10DE05E1, "GeForce GTX 280" }, { 0x10DE05E2, "GeForce GTX 260" }, + { 0x10DE05E3, "GeForce GTX 285" }, + { 0x10DE05E6, "GeForce GTX 275" }, { 0x10DE0600, "GeForce 8800 GTS 512" }, { 0x10DE0602, "GeForce 8800 GT" }, { 0x10DE0604, "GeForce 9800 GX2" }, @@ -282,15 +278,22 @@ { 0x10DE0612, "GeForce 9800 GTX" }, { 0x10DE0613, "GeForce 9800 GTX+" }, { 0x10DE0614, "GeForce 9800 GT" }, - { 0x10DE0615, "GeForce 250 GTS" }, { 0x10DE061A, "Quadro FX 3700" }, { 0x10DE061C, "Quadro FX 3600M" }, { 0x10DE0622, "GeForce 9600 GT" }, { 0x10DE0623, "GeForce 9600 GS" }, + { 0x10DE0626, "GeForce GT 130" }, + { 0x10DE0627, "GeForce GT 140" }, { 0x10DE0628, "GeForce 9800M GTS" }, { 0x10DE062A, "GeForce 9700M GTS" }, { 0x10DE062C, "GeForce 9800M GTS" }, { 0x10DE0640, "GeForce 9500 GT" }, + { 0x10DE0641, "GeForce 9400 GT" }, + { 0x10DE0642, "GeForce 8400 GS" }, + { 0x10DE0643, "GeForce 9500 GT" }, + { 0x10DE0644, "GeForce 9500 GS" }, + { 0x10DE0645, "GeForce 9500 GS" }, + { 0x10DE0646, "GeForce GT 120" }, { 0x10DE0647, "GeForce 9600M GT" }, { 0x10DE0648, "GeForce 9600M GS" }, { 0x10DE0649, "GeForce 9600M GT" }, @@ -303,34 +306,37 @@ { 0x10DE06E9, "GeForce 9300M GS" }, { 0x10DE06EA, "Quadro NVS 150M" }, { 0x10DE06EB, "Quadro NVS 160M" }, - - /*************** GT2xx *************/ - { 0x10DE05E0, "GeForce GTX 295" }, - { 0x10DE05E1, "GeForce GTX 280" }, - { 0x10DE05E2, "GeForce GTX 260" }, - { 0x10DE05E3, "GeForce GTX 285" }, - { 0x10DE05E6, "GeForce GTX 275" }, + { 0x10DE0A20, "GeForce GT220" }, + { 0x10DE0A60, "GeForce G210" }, + { 0x10DE0A65, "GeForce 210" } }; -uint32_t swap32(uint32_t toswap) { - return ((toswap & 0x000000FF) << 24) | - ((toswap & 0x0000FF00) << 8 ) | - ((toswap & 0x00FF0000) >> 8 ) | - ((toswap & 0xFF000000) >> 24); -} - -uint8_t read8(uint8_t *ptr, uint16_t offset) { - return ptr[offset]; +static uint16_t swap16(uint16_t x) +{ + return (((x & 0x00FF) << 8) | ((x & 0xFF00) >> 8)); } -uint16_t read16(uint8_t *ptr, uint16_t offset) { +static uint16_t read16(uint8_t *ptr, uint16_t offset) +{ uint8_t ret[2]; ret[0] = ptr[offset+1]; ret[1] = ptr[offset]; return *((uint16_t*)&ret); } -uint32_t read32(uint8_t *ptr, uint16_t offset) { +#if 0 +static uint32_t swap32(uint32_t x) +{ + return ((x & 0x000000FF) << 24) | ((x & 0x0000FF00) << 8 ) | ((x & 0x00FF0000) >> 8 ) | ((x & 0xFF000000) >> 24); +} + +static uint8_t read8(uint8_t *ptr, uint16_t offset) +{ + return ptr[offset]; +} + +static uint32_t read32(uint8_t *ptr, uint16_t offset) +{ uint8_t ret[4]; ret[0] = ptr[offset+3]; ret[1] = ptr[offset+2]; @@ -338,9 +344,11 @@ ret[3] = ptr[offset]; return *((uint32_t*)&ret); } - -int patch_nvidia_rom(uint8_t *rom) { - if(!rom || (rom[0] != 0x55 && rom[1] != 0xaa)) { +#endif + +static int patch_nvidia_rom(uint8_t *rom) +{ + if (!rom || (rom[0] != 0x55 && rom[1] != 0xaa)) { printf("False ROM signature: 0x%02x%02x\n", rom[0], rom[1]); return PATCH_ROM_FAILED; } @@ -515,48 +523,43 @@ return (has_lvds ? PATCH_ROM_SUCCESS_HAS_LVDS : PATCH_ROM_SUCCESS); } -char *get_nvidia_model(uint32_t id) { - int i=0; - for(i = 0; i < (sizeof(NVKnownChipsets) / sizeof(NVKnownChipsets[0])); i++) { - if(NVKnownChipsets[i].device == id) +static char *get_nvidia_model(uint32_t id) { + int i; + + for (i=1; i< (sizeof(NVKnownChipsets) / sizeof(NVKnownChipsets[0])); i++) { + if (NVKnownChipsets[i].device == id) { return NVKnownChipsets[i].name; + } } return NVKnownChipsets[0].name; } -uint32_t load_nvidia_bios_file(char *filename, char *buffer) +static uint32_t load_nvidia_bios_file(const char *filename, uint8_t *buf, int bufsize) { - int fd, size; - char dirspec[128]; + int fd; + int size; - // Check booting partition - sprintf(dirspec, "%s", filename); - fd = open(dirspec, 0); - if (fd < 0) - { - // Check Extra on booting partition - sprintf(dirspec, "/Extra/%s", filename); - fd = open(dirspec, 0); - if (fd < 0) - { - // Fall back to booter partition - sprintf(dirspec, "bt(0,0)/Extra/%s", filename); - fd=open (dirspec, 0); - if (fd < 0) - return 0; - } + if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) { + return 0; } - - size = read(fd, buffer, file_size (fd)); - close (fd); - return size; + size = file_size(fd); + if (size > bufsize) { + printf("Filesize of %s is bigger than expected! Truncating to 0x%x Bytes!\n", filename, bufsize); + size = bufsize; + } + size = read(fd, (char *)buf, size); + close(fd); + return size; } -int devprop_add_nvidia_template(struct DevPropDevice *device) +static int devprop_add_nvidia_template(struct DevPropDevice *device) { + char tmp[16]; + int len; + if(!device) return 0; - + if(!DP_ADD_TEMP_VAL(device, nvidia_compatible_0)) return 0; if(!DP_ADD_TEMP_VAL(device, nvidia_device_type_0)) @@ -571,176 +574,136 @@ return 0; if(!DP_ADD_TEMP_VAL(device, nvidia_device_type)) return 0; - - char tmp[10]; - sprintf(tmp, "Slot-%x",devices_number); - devprop_add_value(device, "AAPL,slot-name", tmp, strlen(tmp)); + len = sprintf(tmp, "Slot-%x", devices_number); + devprop_add_value(device, "AAPL,slot-name", (uint8_t *)tmp, len + 1); devices_number++; - + return 1; } - bool setup_nvidia_devprop(pci_dt_t *nvda_dev) { - int len; - char *devicepath; - uint8_t *nvRom, *rom; - volatile uint8_t *regs; - uint32_t videoRam, nvBiosOveride, nvBiosSize; - uint32_t bar[7]; - uint8_t nvPatch = 0; - - char biosVersion[32]; - char *model; - const char *nvFilename; + struct DevPropDevice *device; + char *devicepath; + struct pci_rom_pci_header_t *rom_pci_header; + volatile uint8_t *regs; + uint8_t *rom; + uint8_t *nvRom; + uint32_t videoRam; + uint32_t nvBiosOveride; + uint32_t bar[7]; + uint32_t boot_display; + int nvPatch; + char biosVersion[32]; + char nvFilename[32]; + char *model; + bool doit; devicepath = get_pci_dev_path(nvda_dev); - bar[0] = pci_config_read32(nvda_dev->dev.addr, 0x10 ); regs = (uint8_t *) (bar[0] & ~0x0f); - + // Amount of VRAM in kilobytes videoRam = (REG32(0x10020c) & 0xfff00000) >> 10; - model = get_nvidia_model((nvda_dev->vendor_id << 16) | nvda_dev->device_id); verbose("nVidia %s %dMB NV%02x [%04x:%04x] :: %s\n", - model, (videoRam / 1024), - (REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id, - devicepath); + model, (videoRam / 1024), + (REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id, + devicepath); - rom = malloc(0x10000); + rom = malloc(NVIDIA_ROM_SIZE); + sprintf(nvFilename, "/Extra/%04x_%04x.rom", (uint16_t)nvda_dev->vendor_id, (uint16_t)nvda_dev->device_id); + if (getBoolForKey(kUseNvidiaROM, &doit, &bootInfo->bootConfig) && doit) { + verbose("Looking for nvidia video bios file %s\n", nvFilename); + nvBiosOveride = load_nvidia_bios_file(nvFilename, rom, NVIDIA_ROM_SIZE); + DBG("%s Signature 0x%02x%02x %d bytes\n", nvFilename, rom[0], rom[1], nvBiosOveride); + } else { + // Otherwise read bios from card + nvBiosOveride = 0; - if(!rom) - { - verbose(" ROM malloc failed.\n"); - return 0; - } + // TODO: we should really check for the signature before copying the rom, i think. - if (!getValueForKey("VideoROM", &nvFilename, &len, &bootInfo->bootConfig)) - nvFilename="NVIDIA.ROM"; - - // Load video bios overide - nvBiosOveride = nvBiosSize = load_nvidia_bios_file((char *)nvFilename, (char *)rom); - - // Otherwise read bios from card - if (nvBiosOveride == 0) - { - // TODO: we should really check for the signature - // before copying the rom, i think. - // PRAMIN first nvRom = (uint8_t*)®s[NV_PRAMIN_OFFSET]; - bcopy((uint32_t *)nvRom, rom, 0x10000); + bcopy((uint32_t *)nvRom, rom, NVIDIA_ROM_SIZE); // Valid Signature ? - if(rom[0] != 0x55 && rom[1] != 0xaa) - { + if (rom[0] != 0x55 && rom[1] != 0xaa) { // PROM next // Enable PROM access (REG32(NV_PBUS_PCI_NV_20)) = NV_PBUS_PCI_NV_20_ROM_SHADOW_DISABLED; nvRom = (uint8_t*)®s[NV_PROM_OFFSET]; - bcopy((uint8_t *)nvRom, rom, 0x10000); + bcopy((uint8_t *)nvRom, rom, NVIDIA_ROM_SIZE); // disable PROM access (REG32(NV_PBUS_PCI_NV_20)) = NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED; // Valid Signature ? - if(rom[0] != 0x55 && rom[1] != 0xaa) - { + if (rom[0] != 0x55 && rom[1] != 0xaa) { // 0xC0000 last - bcopy((char *)0xc0000, rom, 0x10000); + bcopy((char *)0xc0000, rom, NVIDIA_ROM_SIZE); // Valid Signature ? - if(rom[0] != 0x55 && rom[1] != 0xaa) - { - verbose(" Unable to locate video bios.\n"); + if (rom[0] != 0x55 && rom[1] != 0xaa) { + verbose("Unable to locate video bios.\n"); return 0; - } - else - DBG(" ROM Address 0x%x Signature 0x%02x%02x\n", - nvRom, (uint8_t)rom[0], (uint8_t)rom[1]); + } else { + DBG("ROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]); + } + } else { + DBG("PROM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]); } - else - DBG(" PROM Address 0x%x Signature 0x%02x%02x\n", - nvRom, (uint8_t)rom[0], (uint8_t)rom[1]); + } else { + DBG("PRAM Address 0x%x Signature 0x%02x%02x\n", nvRom, rom[0], rom[1]); } - else - DBG(" PRAM Address 0x%x Signature 0x%02x%02x\n", - nvRom, (uint8_t)rom[0], (uint8_t)rom[1]); } - else - DBG(" %s Signature 0x%02x%02x %d bytes\n", - nvFilename, (uint8_t)rom[0], (uint8_t)rom[1], nvBiosOveride); - nvPatch = patch_nvidia_rom(rom); - - if(nvPatch == PATCH_ROM_FAILED) - { - printf(" ROM Patching Failed.\n"); + if ((nvPatch = patch_nvidia_rom(rom)) == PATCH_ROM_FAILED) { + printf("nVidia ROM Patching Failed!\n"); return false; } - struct pci_rom_pci_header_t *rom_pci_header; rom_pci_header = (struct pci_rom_pci_header_t*)(rom + *(uint16_t *)&rom[24]); // check for 'PCIR' sig - if (rom_pci_header->signature == 0x50434952) - if (rom_pci_header->device != nvda_dev->device_id) + if (rom_pci_header->signature == 0x50434952) { + if (rom_pci_header->device != nvda_dev->device_id) { // Get Model from the OpROM model = get_nvidia_model((rom_pci_header->vendor << 16) | rom_pci_header->device); - else - printf("incorrect PCI ROM sig: 0x%x\n", rom_pci_header->signature); + } else { + printf("nVidia incorrect PCI ROM signature: 0x%x\n", rom_pci_header->signature); + } + } - if (!string) + if (!string) { string = devprop_create_string(); - - struct DevPropDevice *device = malloc(sizeof(struct DevPropDevice)); - device = devprop_add_device(string, devicepath); - - if(!device) - { - printf("Failed initializing dev-prop string dev-entry, press any key...\n"); - free(rom); - getc(); - return false; } + device = devprop_add_device(string, devicepath); /* FIXME: for primary graphics card only */ - uint32_t boot_display = 0x00000001; + boot_display = 1; devprop_add_value(device, "@0,AAPL,boot-display", (uint8_t*)&boot_display, 4); - if(nvPatch == PATCH_ROM_SUCCESS_HAS_LVDS) - { + if(nvPatch == PATCH_ROM_SUCCESS_HAS_LVDS) { uint8_t built_in = 0x01; - devprop_add_value(device, "@0,built-in", (uint8_t*)&built_in, 1); + devprop_add_value(device, "@0,built-in", &built_in, 1); } videoRam *= 1024; - sprintf(biosVersion, "xx.xx.xx - %s", (nvBiosOveride > 0) ? nvFilename : "internal"); devprop_add_nvidia_template(device); devprop_add_value(device, "NVCAP", default_NVCAP, 20); devprop_add_value(device, "VRAM,totalsize", (uint8_t*)&videoRam, 4); - devprop_add_value(device, "model", (uint8_t*)model, (strlen(model) + 1)); - devprop_add_value(device, "rom-revision", (uint8_t*)biosVersion, (strlen(biosVersion) + 1)); - - BOOL set_vbios_prop = false; - getBoolForKey("VBIOS", &set_vbios_prop, &bootInfo->bootConfig); - if (set_vbios_prop) + devprop_add_value(device, "model", (uint8_t*)model, strlen(model) + 1); + devprop_add_value(device, "rom-revision", (uint8_t*)biosVersion, strlen(biosVersion) + 1); + if (getBoolForKey(kVBIOS, &doit, &bootInfo->bootConfig) && doit) { devprop_add_value(device, "vbios", rom, (nvBiosOveride > 0) ? nvBiosOveride : (rom[2] * 512)); + } stringdata = malloc(sizeof(uint8_t) * string->length); - if(!stringdata) - { - printf("no stringdata press a key...\n"); - getc(); - return false; - } - memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length); stringlength = string->length; Index: trunk/i386/libsaio/ati.c =================================================================== --- trunk/i386/libsaio/ati.c (revision 22) +++ trunk/i386/libsaio/ati.c (revision 23) @@ -22,6 +22,7 @@ #include "libsaio.h" +#include "boot.h" #include "bootstruct.h" #include "pci.h" #include "platform.h" @@ -44,70 +45,65 @@ extern uint32_t devices_number; -const char *ati_compatible_0[] = { "@0,compatible", "ATY,%s" }; -const char *ati_compatible_1[] = { "@1,compatible", "ATY,%s" }; -const char *ati_device_type_0[] = { "@0,device_type", "display" }; -const char *ati_device_type_1[] = { "@1,device_type", "display" }; -const char *ati_device_type[] = { "device_type", "ATY,%sParent" }; -const char *ati_name_0[] = { "@0,name", "ATY,%s" }; -const char *ati_name_1[] = { "@1,name", "ATY,%s" }; -const char *ati_name[] = { "name", "ATY,%sParent" }; -const char *ati_efidisplay_0[] = { "@0,ATY,EFIDisplay", "TMDSB" }; -struct ati_data_key ati_connector_type_0 = { 0x04, "@0,connector-type", {0x00, 0x04, 0x00, 0x00} }; -struct ati_data_key ati_connector_type_1 = { 0x04, "@1,connector-type", {0x04, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_display_con_fl_type_0 = { 0x04, "@0,display-connect-flags", {0x00, 0x00, 0x04, 0x00}}; -const char *ati_display_type_0[] = { "@0,display-type", "LCD" }; -const char *ati_display_type_1[] = { "@1,display-type", "NONE" }; -struct ati_data_key ati_aux_power_conn = { 0x04, "AAPL,aux-power-connected", {0x01, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_backlight_ctrl = { 0x04, "AAPL,backlight-control", {0x00, 0x00, 0x00, 0x00}}; -//const char *ati_slot_name[] = { "AAPL,slot-name", "Slot-1"}; -struct ati_data_key ati_aapl01_coher = { 0x04, "AAPL01,Coherency", {0x01, 0x00, 0x00, 0x00}}; -const char *ati_card_no[] = { "ATY,Card#", "109-B77101-00"}; -const char *ati_copyright[] = { "ATY,Copyright", "Copyright AMD Inc. All Rights Reserved. 2005-2009"}; -const char *ati_efi_compile_d[] = { "ATY,EFICompileDate", "Jan 26 2009"}; -struct ati_data_key ati_efi_disp_conf = { 0x08, "ATY,EFIDispConfig", {0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}; -struct ati_data_key ati_efi_drv_type = { 0x01, "ATY,EFIDriverType", {0x02}}; -struct ati_data_key ati_efi_enbl_mode = { 0x01, "ATY,EFIEnabledMode", {0x01}}; -struct ati_data_key ati_efi_init_stat = { 0x04, "ATY,EFIHWInitStatus", {0x00, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_efi_orientation = { 0x02, "ATY,EFIOrientation", {0x02, 0x00}}; -const char *ati_efi_version[] = { "ATY,EFIVersion", "01.00.318"}; -const char *ati_efi_versionB[] = { "ATY,EFIVersionB", "113-SBSJ1G04-00R-02"}; -const char *ati_efi_versionE[] = { "ATY,EFIVersionE", "113-B7710A-318"}; -struct ati_data_key ati_mclk = { 0x04, "ATY,MCLK", {0x70, 0x2e, 0x11, 0x00}}; -struct ati_data_key ati_mem_rev_id = { 0x02, "ATY,MemRevisionID", {0x03, 0x00}}; -struct ati_data_key ati_mem_vend_id = { 0x02, "ATY,MemVendorID", {0x02, 0x00}}; -const char *ati_mrt[] = { "ATY,MRT", " "}; -const char *ati_romno[] = { "ATY,Rom#", "113-B7710C-176"}; -struct ati_data_key ati_sclk = { 0x04, "ATY,SCLK", {0x28, 0xdb, 0x0b, 0x00}}; -struct ati_data_key ati_vendor_id = { 0x02, "ATY,VendorID", {0x02, 0x10}}; -struct ati_data_key ati_platform_info = { 0x80, "ATY,PlatformInfo", {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_mvad = { 0x40, "MVAD", {0x3f, 0x5c, 0x82, 0x02, 0xff, 0x90, 0x00, 0x54, 0x60, 0x00, 0xac, 0x10, 0xa0, 0x17, 0x00, 0x03, 0xb0, 0x68, 0x00, 0x0a, 0xa0, 0x0a, 0x30, 0x00, 0x20, 0x00, 0x40, 0x06, 0x6e, 0x06, 0x03, 0x00, 0x06, 0x00, 0x40, 0x06, 0x00, 0x0a, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x10, 0x06, 0x92, 0x20, 0x00, 0x03}}; -struct ati_data_key ati_saved_config = { 0x100, "saved-config", {0x3f, 0x5c, 0x82, 0x02, 0xff, 0x90, 0x00, 0x54, 0x60, 0x00, 0xac, 0x10, 0xa0, 0x17, 0x00, 0x03, 0xb0, 0x68, 0x00, 0x0a, 0xa0, 0x0a, 0x30, 0x00, 0x20, 0x00, 0x40, 0x06, 0x6e, 0x06, 0x03, 0x00, 0x06, 0x00, 0x40, 0x06, 0x00, 0x0a, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x10, 0x06, 0x92, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xee, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; +const char *ati_compatible_0[] = { "@0,compatible", "ATY,%s" }; +const char *ati_compatible_1[] = { "@1,compatible", "ATY,%s" }; +const char *ati_device_type_0[] = { "@0,device_type", "display" }; +const char *ati_device_type_1[] = { "@1,device_type", "display" }; +const char *ati_device_type[] = { "device_type", "ATY,%sParent" }; +const char *ati_name_0[] = { "@0,name", "ATY,%s" }; +const char *ati_name_1[] = { "@1,name", "ATY,%s" }; +const char *ati_name[] = { "name", "ATY,%sParent" }; +const char *ati_efidisplay_0[] = { "@0,ATY,EFIDisplay", "TMDSB" }; +struct ati_data_key ati_connector_type_0 = { 0x04, "@0,connector-type", {0x00, 0x04, 0x00, 0x00} }; +struct ati_data_key ati_connector_type_1 = { 0x04, "@1,connector-type", {0x04, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_display_con_fl_type_0 = { 0x04, "@0,display-connect-flags", {0x00, 0x00, 0x04, 0x00} }; +const char *ati_display_type_0[] = { "@0,display-type", "LCD" }; +const char *ati_display_type_1[] = { "@1,display-type", "NONE" }; +struct ati_data_key ati_aux_power_conn = { 0x04, "AAPL,aux-power-connected", {0x01, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_backlight_ctrl = { 0x04, "AAPL,backlight-control", {0x00, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_aapl01_coher = { 0x04, "AAPL01,Coherency", {0x01, 0x00, 0x00, 0x00} }; +const char *ati_card_no[] = { "ATY,Card#", "109-B77101-00" }; +const char *ati_copyright[] = { "ATY,Copyright", "Copyright AMD Inc. All Rights Reserved. 2005-2009" }; +const char *ati_efi_compile_d[] = { "ATY,EFICompileDate", "Jan 26 2009" }; +struct ati_data_key ati_efi_disp_conf = { 0x08, "ATY,EFIDispConfig", {0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01} }; +struct ati_data_key ati_efi_drv_type = { 0x01, "ATY,EFIDriverType", {0x02} }; +struct ati_data_key ati_efi_enbl_mode = { 0x01, "ATY,EFIEnabledMode", {0x01} }; +struct ati_data_key ati_efi_init_stat = { 0x04, "ATY,EFIHWInitStatus", {0x00, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_efi_orientation = { 0x02, "ATY,EFIOrientation", {0x02, 0x00} }; +const char *ati_efi_version[] = { "ATY,EFIVersion", "01.00.318" }; +const char *ati_efi_versionB[] = { "ATY,EFIVersionB", "113-SBSJ1G04-00R-02" }; +const char *ati_efi_versionE[] = { "ATY,EFIVersionE", "113-B7710A-318" }; +struct ati_data_key ati_mclk = { 0x04, "ATY,MCLK", {0x70, 0x2e, 0x11, 0x00} }; +struct ati_data_key ati_mem_rev_id = { 0x02, "ATY,MemRevisionID", {0x03, 0x00} }; +struct ati_data_key ati_mem_vend_id = { 0x02, "ATY,MemVendorID", {0x02, 0x00} }; +const char *ati_mrt[] = { "ATY,MRT", " " }; +const char *ati_romno[] = { "ATY,Rom#", "113-B7710C-176" }; +struct ati_data_key ati_sclk = { 0x04, "ATY,SCLK", {0x28, 0xdb, 0x0b, 0x00} }; +struct ati_data_key ati_vendor_id = { 0x02, "ATY,VendorID", {0x02, 0x10} }; +struct ati_data_key ati_platform_info = { 0x80, "ATY,PlatformInfo", {0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_mvad = { 0x40, "MVAD", {0x3f, 0x5c, 0x82, 0x02, 0xff, 0x90, 0x00, 0x54, 0x60, 0x00, 0xac, 0x10, 0xa0, 0x17, 0x00, 0x03, 0xb0, 0x68, 0x00, 0x0a, 0xa0, 0x0a, 0x30, 0x00, 0x20, 0x00, 0x40, 0x06, 0x6e, 0x06, 0x03, 0x00, 0x06, 0x00, 0x40, 0x06, 0x00, 0x0a, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x10, 0x06, 0x92, 0x20, 0x00, 0x03} }; +struct ati_data_key ati_saved_config = { 0x100, "saved-config", {0x3f, 0x5c, 0x82, 0x02, 0xff, 0x90, 0x00, 0x54, 0x60, 0x00, 0xac, 0x10, 0xa0, 0x17, 0x00, 0x03, 0xb0, 0x68, 0x00, 0x0a, 0xa0, 0x0a, 0x30, 0x00, 0x20, 0x00, 0x40, 0x06, 0x6e, 0x06, 0x03, 0x00, 0x06, 0x00, 0x40, 0x06, 0x00, 0x0a, 0x10, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x10, 0x06, 0x92, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xee, 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }; ///non 48xx keys -const char *ati_efidisplay_0_n4[] = { "@0,ATY,EFIDisplay", "TMDSA" }; -struct ati_data_key ati_connector_type_0_n4 = { 0x04, "@0,connector-type", {0x04, 0x00, 0x00, 0x00} }; -struct ati_data_key ati_connector_type_1_n4 = { 0x04, "@1,connector-type", {0x00, 0x02, 0x00, 0x00}}; -struct ati_data_key ati_aapl_emc_disp_list_n4 = { 0x40, "AAPL,EMC-Display-List", {0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x1b, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x1c, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_fb_offset_n4 = { 0x08, "ATY,FrameBufferOffset", {0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_hwgpio_n4 = { 0x04, "ATY,HWGPIO", {0x23, 0xa8, 0x48, 0x00}}; -struct ati_data_key ati_iospace_offset_n4 = { 0x08, "ATY,IOSpaceOffset", {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00}}; -struct ati_data_key ati_mclk_n4 = { 0x04, "ATY,MCLK", {0x00, 0x35, 0x0c, 0x00}}; -struct ati_data_key ati_sclk_n4 = { 0x04, "ATY,SCLK", {0x60, 0xae, 0x0a, 0x00}}; -struct ati_data_key ati_refclk_n4 = { 0x04, "ATY,RefCLK", {0x8c, 0x0a, 0x00, 0x00}}; -struct ati_data_key ati_regspace_offset_n4 = { 0x08, "ATY,RegisterSpaceOffset", {0x00, 0x00, 0x00, 0x00, 0x90, 0xa2, 0x00, 0x00}}; -struct ati_data_key ati_vram_memsize_0 = { 0x08, "@0,VRAM,memsize", {0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_vram_memsize_1 = { 0x08, "@1,VRAM,memsize", {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_aapl_blackscr_prefs_0_n4 = { 0x04, "AAPL00,blackscreen-preferences", {0x00, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_aapl_blackscr_prefs_1_n4 = { 0x04, "AAPL01,blackscreen-preferences", {0x00, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_swgpio_info_n4 = { 0x04, "ATY,SWGPIO Info", {0x00, 0x48, 0xa8, 0x23}}; -struct ati_data_key ati_efi_orientation_n4 = { 0x01, "ATY,EFIOrientation", {0x08}}; -struct ati_data_key ati_mvad_n4 = { 0x100, "MVAD", {0x3e, 0x5c, 0x82, 0x00, 0xff, 0x90, 0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x3c, 0x80, 0x07, 0x20, 0x08, 0x30, 0x00, 0x20, 0x00, 0xb0, 0x04, 0xd3, 0x04, 0x03, 0x00, 0x06, 0x00, 0xb0, 0x04, 0x80, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; -struct ati_data_key ati_saved_config_n4 = { 0x100, "saved-config", {0x3e, 0x5c, 0x82, 0x00, 0xff, 0x90, 0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x3c, 0x80, 0x07, 0x20, 0x08, 0x30, 0x00, 0x20, 0x00, 0xb0, 0x04, 0xd3, 0x04, 0x03, 0x00, 0x06, 0x00, 0xb0, 0x04, 0x80, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}; -//const char *ati_slot_name_n4[] = { "AAPL,slot-name", "Slot-2"}; +const char *ati_efidisplay_0_n4[] = { "@0,ATY,EFIDisplay", "TMDSA" }; +struct ati_data_key ati_connector_type_0_n4 = { 0x04, "@0,connector-type", {0x04, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_connector_type_1_n4 = { 0x04, "@1,connector-type", {0x00, 0x02, 0x00, 0x00} }; +struct ati_data_key ati_aapl_emc_disp_list_n4 = { 0x40, "AAPL,EMC-Display-List", {0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x1b, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x1c, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x10, 0x00, 0x00, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_fb_offset_n4 = { 0x08, "ATY,FrameBufferOffset", {0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_hwgpio_n4 = { 0x04, "ATY,HWGPIO", {0x23, 0xa8, 0x48, 0x00} }; +struct ati_data_key ati_iospace_offset_n4 = { 0x08, "ATY,IOSpaceOffset", {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00} }; +struct ati_data_key ati_mclk_n4 = { 0x04, "ATY,MCLK", {0x00, 0x35, 0x0c, 0x00} }; +struct ati_data_key ati_sclk_n4 = { 0x04, "ATY,SCLK", {0x60, 0xae, 0x0a, 0x00} }; +struct ati_data_key ati_refclk_n4 = { 0x04, "ATY,RefCLK", {0x8c, 0x0a, 0x00, 0x00} }; +struct ati_data_key ati_regspace_offset_n4 = { 0x08, "ATY,RegisterSpaceOffset", {0x00, 0x00, 0x00, 0x00, 0x90, 0xa2, 0x00, 0x00} }; +struct ati_data_key ati_vram_memsize_0 = { 0x08, "@0,VRAM,memsize", {0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_vram_memsize_1 = { 0x08, "@1,VRAM,memsize", {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_aapl_blackscr_prefs_0_n4= { 0x04, "AAPL00,blackscreen-preferences", {0x00, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_aapl_blackscr_prefs_1_n4= { 0x04, "AAPL01,blackscreen-preferences", {0x00, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_swgpio_info_n4 = { 0x04, "ATY,SWGPIO Info", {0x00, 0x48, 0xa8, 0x23} }; +struct ati_data_key ati_efi_orientation_n4 = { 0x01, "ATY,EFIOrientation", {0x08} }; +struct ati_data_key ati_mvad_n4 = { 0x100, "MVAD", {0x3e, 0x5c, 0x82, 0x00, 0xff, 0x90, 0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x3c, 0x80, 0x07, 0x20, 0x08, 0x30, 0x00, 0x20, 0x00, 0xb0, 0x04, 0xd3, 0x04, 0x03, 0x00, 0x06, 0x00, 0xb0, 0x04, 0x80, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }; +struct ati_data_key ati_saved_config_n4 = { 0x100, "saved-config", {0x3e, 0x5c, 0x82, 0x00, 0xff, 0x90, 0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x3c, 0x80, 0x07, 0x20, 0x08, 0x30, 0x00, 0x20, 0x00, 0xb0, 0x04, 0xd3, 0x04, 0x03, 0x00, 0x06, 0x00, 0xb0, 0x04, 0x80, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x90, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x31, 0x30, 0x50, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x32, 0x32, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} }; - - - struct pcir_s { uint32_t signature; uint16_t vid; @@ -116,231 +112,226 @@ // Known cards as of 2008/08/26 static struct ati_chipsets_t ATIKnownChipsets[] = { - { 0x00000000, "Unknown" }, - { 0x10029589, "ATI Radeon 2600 Series"} , - { 0x10029588, "ATI Radeon 2600 Series"} , - { 0x100294C3, "ATI Radeon 2400 Series"} , - { 0x100294C4, "ATI Radeon 2400 Series"} , - { 0x100294C6, "ATI Radeon 2400 Series"} , - { 0x10029400, "ATI Radeon 2900 Series"} , - { 0x10029405, "ATI Radeon 2900GT Series"} , - { 0x10029581, "ATI Radeon 2600 Series"} , - { 0x10029583, "ATI Radeon 2600 Series"} , - { 0x10029586, "ATI Radeon 2600 Series"} , - { 0x10029587, "ATI Radeon 2600 Series"} , - { 0x100294C9, "ATI Radeon 2400 Series"} , - { 0x10029501, "ATI Radeon 3800 Series"} , - { 0x10029505, "ATI Radeon 3800 Series"} , - { 0x10029515, "ATI Radeon 3800 Series"} , - { 0x10029507, "ATI Radeon 3800 Series"} , - { 0x10029500, "ATI Radeon 3800 Series"} , - { 0x1002950F, "ATI Radeon 3800X2 Series"} , - { 0x100295C5, "ATI Radeon 3400 Series"} , - { 0x100295C7, "ATI Radeon 3400 Series"} , - { 0x100295C0, "ATI Radeon 3400 Series"} , - { 0x10029596, "ATI Radeon 3600 Series"} , - { 0x10029590, "ATI Radeon 3600 Series"} , - { 0x10029599, "ATI Radeon 3600 Series"} , - { 0x10029597, "ATI Radeon 3600 Series"} , - { 0x10029598, "ATI Radeon 3600 Series"} , - { 0x10029442, "ATI Radeon 4850 Series"} , - { 0x10029440, "ATI Radeon 4870 Series"} , - { 0x1002944C, "ATI Radeon 4830 Series"} , - { 0x10029460, "ATI Radeon 4890 Series"} , - { 0x10029462, "ATI Radeon 4890 Series"} , - { 0x10029441, "ATI Radeon 4870X2 Series"} , - { 0x10029443, "ATI Radeon 4850X2 Series"} , - { 0x10029444, "ATI Radeon 4800 Series"} , - { 0x10029446, "ATI Radeon 4800 Series"} , - { 0x1002944E, "ATI Radeon 4730 Series"} , - { 0x10029450, "ATI Radeon 4800 Series"} , - { 0x10029452, "ATI Radeon 4800 Series"} , - { 0x10029456, "ATI Radeon 4800 Series"} , - { 0x1002944A, "ATI Radeon 4800 Mobility Series"} , - { 0x1002945A, "ATI Radeon 4800 Mobility Series"} , - { 0x1002945B, "ATI Radeon 4800 Mobility Series"} , - { 0x1002944B, "ATI Radeon 4800 Mobility Series"} , - { 0x10029490, "ATI Radeon 4600 Series"} , - { 0x10029498, "ATI Radeon 4600 Series"} , - { 0x1002949E, "ATI Radeon 4600 Series"} , - { 0x10029480, "ATI Radeon 4600 Series"} , - { 0x10029488, "ATI Radeon 4600 Series"} , - { 0x10029540, "ATI Radeon 4500 Series"} , - { 0x10029541, "ATI Radeon 4500 Series"} , - { 0x1002954E, "ATI Radeon 4500 Series"} , - { 0x10029552, "ATI Radeon 4300 Mobility Series"} , - { 0x10029553, "ATI Radeon 4500 Mobility Series"} , - { 0x1002954F, "ATI Radeon 4300 Series"}, + { 0x00000000, "Unknown" } , + { 0x10029589, "ATI Radeon 2600 Series"} , + { 0x10029588, "ATI Radeon 2600 Series"} , + { 0x100294C3, "ATI Radeon 2400 Series"} , + { 0x100294C4, "ATI Radeon 2400 Series"} , + { 0x100294C6, "ATI Radeon 2400 Series"} , + { 0x10029400, "ATI Radeon 2900 Series"} , + { 0x10029405, "ATI Radeon 2900GT Series"} , + { 0x10029581, "ATI Radeon 2600 Series"} , + { 0x10029583, "ATI Radeon 2600 Series"} , + { 0x10029586, "ATI Radeon 2600 Series"} , + { 0x10029587, "ATI Radeon 2600 Series"} , + { 0x100294C9, "ATI Radeon 2400 Series"} , + { 0x10029501, "ATI Radeon 3800 Series"} , + { 0x10029505, "ATI Radeon 3800 Series"} , + { 0x10029515, "ATI Radeon 3800 Series"} , + { 0x10029507, "ATI Radeon 3800 Series"} , + { 0x10029500, "ATI Radeon 3800 Series"} , + { 0x1002950F, "ATI Radeon 3800X2 Series"} , + { 0x100295C5, "ATI Radeon 3400 Series"} , + { 0x100295C7, "ATI Radeon 3400 Series"} , + { 0x100295C0, "ATI Radeon 3400 Series"} , + { 0x10029596, "ATI Radeon 3600 Series"} , + { 0x10029590, "ATI Radeon 3600 Series"} , + { 0x10029599, "ATI Radeon 3600 Series"} , + { 0x10029597, "ATI Radeon 3600 Series"} , + { 0x10029598, "ATI Radeon 3600 Series"} , + { 0x10029442, "ATI Radeon 4850 Series"} , + { 0x10029440, "ATI Radeon 4870 Series"} , + { 0x1002944C, "ATI Radeon 4830 Series"} , + { 0x10029460, "ATI Radeon 4890 Series"} , + { 0x10029462, "ATI Radeon 4890 Series"} , + { 0x10029441, "ATI Radeon 4870X2 Series"} , + { 0x10029443, "ATI Radeon 4850X2 Series"} , + { 0x10029444, "ATI Radeon 4800 Series"} , + { 0x10029446, "ATI Radeon 4800 Series"} , + { 0x1002944E, "ATI Radeon 4730 Series"} , + { 0x10029450, "ATI Radeon 4800 Series"} , + { 0x10029452, "ATI Radeon 4800 Series"} , + { 0x10029456, "ATI Radeon 4800 Series"} , + { 0x1002944A, "ATI Radeon 4800 Mobility Series"} , + { 0x1002945A, "ATI Radeon 4800 Mobility Series"} , + { 0x1002945B, "ATI Radeon 4800 Mobility Series"} , + { 0x1002944B, "ATI Radeon 4800 Mobility Series"} , + { 0x10029490, "ATI Radeon 4600 Series"} , + { 0x10029498, "ATI Radeon 4600 Series"} , + { 0x1002949E, "ATI Radeon 4600 Series"} , + { 0x10029480, "ATI Radeon 4600 Series"} , + { 0x10029488, "ATI Radeon 4600 Series"} , + { 0x10029540, "ATI Radeon 4500 Series"} , + { 0x10029541, "ATI Radeon 4500 Series"} , + { 0x1002954E, "ATI Radeon 4500 Series"} , + { 0x10029552, "ATI Radeon 4300 Mobility Series"} , + { 0x10029553, "ATI Radeon 4500 Mobility Series"} , + { 0x1002954F, "ATI Radeon 4300 Series"} }; static struct ati_chipsets_t ATIKnownFramebuffers[] = { - { 0x00000000, "Megalodon" }, - { 0x10029589, "Lamna"} , - { 0x10029588, "Lamna"} , - { 0x100294C3, "Iago"} , - { 0x100294C4, "Iago"} , - { 0x100294C6, "Iago"} , - { 0x10029400, "Franklin"} , - { 0x10029405, "Franklin"} , - { 0x10029581, "Hypoprion"} , - { 0x10029583, "Hypoprion"} , - { 0x10029586, "Hypoprion"} , - { 0x10029587, "Hypoprion"} , - { 0x100294C9, "Iago"} , - { 0x10029501, "Megalodon"} , - { 0x10029505, "Megalodon"} , - { 0x10029515, "Megalodon"} , - { 0x10029507, "Megalodon"} , - { 0x10029500, "Megalodon"} , - { 0x1002950F, "Triakis"} , - { 0x100295C5, "Iago"} , - { 0x100295C7, "Iago"} , - { 0x100295C0, "Iago"} , - { 0x10029596, "Megalodon"} , - { 0x10029590, "Megalodon"} , - { 0x10029599, "Megalodon"} , - { 0x10029597, "Megalodon"} , - { 0x10029598, "Megalodon"} , - { 0x10029442, "Motmot"} , - { 0x10029440, "Motmot"} , - { 0x1002944C, "Motmot"} , - { 0x10029460, "Motmot"} , - { 0x10029462, "Motmot"} , - { 0x10029441, "Motmot"} , - { 0x10029443, "Motmot"} , - { 0x10029444, "Motmot"} , - { 0x10029446, "Motmot"} , - { 0x1002944E, "Motmot"} , - { 0x10029450, "Motmot"} , - { 0x10029452, "Motmot"} , - { 0x10029456, "Motmot"} , - { 0x1002944A, "Motmot"} , - { 0x1002945A, "Motmot"} , - { 0x1002945B, "Motmot"} , - { 0x1002944B, "Motmot"} , - { 0x10029490, "Motmot"} , - { 0x10029498, "Motmot"} , - { 0x1002949E, "Motmot"} , - { 0x10029480, "Motmot"} , - { 0x10029488, "Motmot"} , - { 0x10029540, "Motmot"} , - { 0x10029541, "Motmot"} , - { 0x1002954E, "Motmot"} , - { 0x10029552, "Motmot"} , - { 0x10029553, "Motmot"} , - { 0x1002954F, "Motmot"} , + { 0x00000000, "Megalodon" }, + { 0x10029589, "Lamna"} , + { 0x10029588, "Lamna"} , + { 0x100294C3, "Iago"} , + { 0x100294C4, "Iago"} , + { 0x100294C6, "Iago"} , + { 0x10029400, "Franklin"} , + { 0x10029405, "Franklin"} , + { 0x10029581, "Hypoprion"} , + { 0x10029583, "Hypoprion"} , + { 0x10029586, "Hypoprion"} , + { 0x10029587, "Hypoprion"} , + { 0x100294C9, "Iago"} , + { 0x10029501, "Megalodon"} , + { 0x10029505, "Megalodon"} , + { 0x10029515, "Megalodon"} , + { 0x10029507, "Megalodon"} , + { 0x10029500, "Megalodon"} , + { 0x1002950F, "Triakis"} , + { 0x100295C5, "Iago"} , + { 0x100295C7, "Iago"} , + { 0x100295C0, "Iago"} , + { 0x10029596, "Megalodon"} , + { 0x10029590, "Megalodon"} , + { 0x10029599, "Megalodon"} , + { 0x10029597, "Megalodon"} , + { 0x10029598, "Megalodon"} , + { 0x10029442, "Motmot"} , + { 0x10029440, "Motmot"} , + { 0x1002944C, "Motmot"} , + { 0x10029460, "Motmot"} , + { 0x10029462, "Motmot"} , + { 0x10029441, "Motmot"} , + { 0x10029443, "Motmot"} , + { 0x10029444, "Motmot"} , + { 0x10029446, "Motmot"} , + { 0x1002944E, "Motmot"} , + { 0x10029450, "Motmot"} , + { 0x10029452, "Motmot"} , + { 0x10029456, "Motmot"} , + { 0x1002944A, "Motmot"} , + { 0x1002945A, "Motmot"} , + { 0x1002945B, "Motmot"} , + { 0x1002944B, "Motmot"} , + { 0x10029490, "Motmot"} , + { 0x10029498, "Motmot"} , + { 0x1002949E, "Motmot"} , + { 0x10029480, "Motmot"} , + { 0x10029488, "Motmot"} , + { 0x10029540, "Motmot"} , + { 0x10029541, "Motmot"} , + { 0x1002954E, "Motmot"} , + { 0x10029552, "Motmot"} , + { 0x10029553, "Motmot"} , + { 0x1002954F, "Motmot"} }; -unsigned int accessROM(pci_dt_t *ati_dev, unsigned int mode) +static uint32_t accessROM(pci_dt_t *ati_dev, unsigned int mode) { - uint32_t bar[7]; - volatile uint8_t *regs; + uint32_t bar[7]; + volatile uint32_t *regs; bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 ); - regs = (uint8_t *) (bar[2] & ~0x0f); + regs = (uint32_t *) (bar[2] & ~0x0f); -if(mode) -{ - if(mode != 1) return 0xe00002c7; - REG32W(0x179c, 0x00080000); - REG32W(0x1798, 0x00080721); - REG32W(0x17a0, 0x00080621); - REG32W(0x1600, 0x14030300); - REG32W(0x1798, 0x21); - REG32W(0x17a0, 0x21); - REG32W(0x179c, 0x00); - REG32W(0x17a0, 0x21); - REG32W(0x1798, 0x21); - REG32W(0x1798, 0x21); -} else { - REG32W(0x1600, 0x14030302); - REG32W(0x1798, 0x21); - REG32W(0x17a0, 0x21); - REG32W(0x179c, 0x00080000); - REG32W(0x17a0, 0x00080621); - REG32W(0x1798, 0x00080721); - REG32W(0x1798, 0x21); - REG32W(0x17a0, 0x21); - REG32W(0x179c, 0x00); - REG32W(0x1604, 0x0400e9fc); - REG32W(0x161c, 0x00); - REG32W(0x1620, 0x9f); - REG32W(0x1618, 0x00040004); - REG32W(0x161c, 0x00); - REG32W(0x1604, 0xe9fc); - REG32W(0x179c, 0x00080000); - REG32W(0x1798, 0x00080721); - REG32W(0x17a0, 0x00080621); - REG32W(0x1798, 0x21); - REG32W(0x17a0, 0x21); - REG32W(0x179c, 0x00); + if (mode) { + if (mode != 1) { + return 0xe00002c7; + } + REG32W(0x179c, 0x00080000); + REG32W(0x1798, 0x00080721); + REG32W(0x17a0, 0x00080621); + REG32W(0x1600, 0x14030300); + REG32W(0x1798, 0x21); + REG32W(0x17a0, 0x21); + REG32W(0x179c, 0x00); + REG32W(0x17a0, 0x21); + REG32W(0x1798, 0x21); + REG32W(0x1798, 0x21); + } else { + REG32W(0x1600, 0x14030302); + REG32W(0x1798, 0x21); + REG32W(0x17a0, 0x21); + REG32W(0x179c, 0x00080000); + REG32W(0x17a0, 0x00080621); + REG32W(0x1798, 0x00080721); + REG32W(0x1798, 0x21); + REG32W(0x17a0, 0x21); + REG32W(0x179c, 0x00); + REG32W(0x1604, 0x0400e9fc); + REG32W(0x161c, 0x00); + REG32W(0x1620, 0x9f); + REG32W(0x1618, 0x00040004); + REG32W(0x161c, 0x00); + REG32W(0x1604, 0xe9fc); + REG32W(0x179c, 0x00080000); + REG32W(0x1798, 0x00080721); + REG32W(0x17a0, 0x00080621); + REG32W(0x1798, 0x21); + REG32W(0x17a0, 0x21); + REG32W(0x179c, 0x00); + } + return 0; } -return 0; -} -unsigned char * readAtomBIOS(pci_dt_t *ati_dev) +static uint8_t *readAtomBIOS(pci_dt_t *ati_dev) { - uint32_t bar[7]; - unsigned int * BIOSBase = NULL; - unsigned int counter; - volatile uint8_t *regs; + uint32_t bar[7]; + uint32_t *BIOSBase; + uint32_t counter; + volatile uint32_t *regs; bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 ); - regs = (uint8_t *) (bar[2] & ~0x0f); + regs = (volatile uint32_t *) (bar[2] & ~0x0f); accessROM(ati_dev, 0); REG32W(0xa8, 0); REG32R(0xac); REG32W(0xa8, 0); REG32R(0xac); - + BIOSBase = malloc(0x10000); - if(BIOSBase) - { - REG32W(0xa8, 0); - BIOSBase[0] = REG32R(0xac); - counter = 4; - do - { - REG32W(0xa8, counter); - BIOSBase[counter/4] = REG32R(0xac); - counter +=4; - } - while(counter != 0x10000); - } + REG32W(0xa8, 0); + BIOSBase[0] = REG32R(0xac); + counter = 4; + do { + REG32W(0xa8, counter); + BIOSBase[counter/4] = REG32R(0xac); + counter +=4; + } while (counter != 0x10000); accessROM((pci_dt_t *)regs, 1); - if ((* (UInt16 *)BIOSBase) != 0xAA55) { - printf("Wrong BIOS signature: %04x\n", (* (UInt16 *)BIOSBase)); + if (*(uint16_t *)BIOSBase != 0xAA55) { + printf("Wrong BIOS signature: %04x\n", *(uint16_t *)BIOSBase); return 0; } - return (unsigned char *)BIOSBase; + return (uint8_t *)BIOSBase; } -#define R5XX_CONFIG_MEMSIZE 0x00F8 -#define R6XX_CONFIG_MEMSIZE 0x5428 +#define R5XX_CONFIG_MEMSIZE 0x00F8 +#define R6XX_CONFIG_MEMSIZE 0x5428 uint32_t getvramsizekb(pci_dt_t *ati_dev) { - uint32_t bar[7]; - volatile uint8_t *regs; - uint32_t RamSize = 0; + uint32_t bar[7]; + uint32_t size; + volatile uint32_t *regs; bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 ); - regs = (uint8_t *) (bar[2] & ~0x0f); - if (ati_dev->device_id < 0x9400) - RamSize = (REG32R(R5XX_CONFIG_MEMSIZE)) >> 10; - else - RamSize = (REG32R(R6XX_CONFIG_MEMSIZE)) >> 10; - - return RamSize; + regs = (uint32_t *) (bar[2] & ~0x0f); + if (ati_dev->device_id < 0x9400) { + size = (REG32R(R5XX_CONFIG_MEMSIZE)) >> 10; + } else { + size = (REG32R(R6XX_CONFIG_MEMSIZE)) >> 10; + } + return size; } -#define AVIVO_D1CRTC_CONTROL 0x6080 -#define AVIVO_CRTC_EN (1<<0) -#define AVIVO_D2CRTC_CONTROL 0x6880 +#define AVIVO_D1CRTC_CONTROL 0x6080 +#define AVIVO_CRTC_EN (1<<0) +#define AVIVO_D2CRTC_CONTROL 0x6880 -bool -radeon_card_posted(pci_dt_t *ati_dev) +static bool radeon_card_posted(pci_dt_t *ati_dev) { // if devid matches biosimage(from legacy) devid - posted card, fails with X2/crossfire cards. /* char *biosimage = 0xC0000; @@ -354,89 +345,91 @@ { if (rom_pci_header->device == ati_dev->device_id) { - return TRUE; + return true; printf("Card was POSTed\n"); } } } - return FALSE; + return false; printf("Card was not POSTed\n"); */ - //fails yet - uint32_t bar[7]; - volatile uint8_t *regs; + //fails yet + uint32_t bar[7]; + uint32_t val; + volatile uint32_t *regs; - bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18 ); - regs = (uint8_t *) (bar[2] & ~0x0f); - - uint32_t val; - - val = REG32R(AVIVO_D1CRTC_CONTROL) | REG32R(AVIVO_D2CRTC_CONTROL); - if (val & AVIVO_CRTC_EN) - return TRUE; + bar[2] = pci_config_read32(ati_dev->dev.addr, 0x18); + regs = (uint32_t *) (bar[2] & ~0x0f); - return FALSE; - + val = REG32R(AVIVO_D1CRTC_CONTROL) | REG32R(AVIVO_D2CRTC_CONTROL); + if (val & AVIVO_CRTC_EN) { + return true; + } else { + return false; + } } -uint32_t load_ati_bios_file(char *filename, char *buffer) +static uint32_t load_ati_bios_file(const char *filename, uint8_t *buf, int bufsize) { - int fd, size; - char dirspec[128]; + int fd; + int size; - // Check Extra on booting partition - sprintf(dirspec, "/Extra/%s", filename); - fd = open(dirspec, 0); - if (fd < 0) - { - // Fall back to booter partition - sprintf(dirspec, "bt(0,0)/Extra/%s", filename); - fd=open (dirspec, 0); - if (fd < 0) - return 0; + if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) { + return 0; } - - size = read(fd, buffer, file_size (fd)); - close (fd); - return size; + size = file_size(fd); + if (size > bufsize) { + printf("Filesize of %s is bigger than expected! Truncating to 0x%x Bytes!\n", filename, bufsize); + size = bufsize; + } + size = read(fd, (char *)buf, size); + close(fd); + return size; } -char *get_ati_model(uint32_t id) { - int i=0; - for(i = 0; i < (sizeof(ATIKnownChipsets) / sizeof(ATIKnownChipsets[0])); i++) { - if(ATIKnownChipsets[i].device == id) +static char *get_ati_model(uint32_t id) +{ + int i; + + for (i=0; i< (sizeof(ATIKnownChipsets) / sizeof(ATIKnownChipsets[0])); i++) { + if (ATIKnownChipsets[i].device == id) { return ATIKnownChipsets[i].name; + } } return ATIKnownChipsets[0].name; } -char *get_ati_fb(uint32_t id) { - int i=0; - for(i = 0; i < (sizeof(ATIKnownFramebuffers) / sizeof(ATIKnownFramebuffers[0])); i++) { - if(ATIKnownFramebuffers[i].device == id) +static char *get_ati_fb(uint32_t id) +{ + int i; + + for (i=0; i< (sizeof(ATIKnownFramebuffers) / sizeof(ATIKnownFramebuffers[0])); i++) { + if (ATIKnownFramebuffers[i].device == id) { return ATIKnownFramebuffers[i].name; + } } return ATIKnownFramebuffers[0].name; } -int devprop_add_iopciconfigspace(struct DevPropDevice *device, pci_dt_t *ati_dev) +static int devprop_add_iopciconfigspace(struct DevPropDevice *device, pci_dt_t *ati_dev) { - if(!device) + int i; + uint8_t *config_space; + + if (!device || !ati_dev) { return 0; - if(!ati_dev) - return 0; + } printf("dumping pci config space, 256 bytes\n"); - int i; - uint8_t *config_space; config_space = malloc(256); - for(i=0; i<=255; i++) + for (i=0; i<=255; i++) { config_space[i] = pci_config_read8( ati_dev->dev.addr, i); + } devprop_add_value(device, "ATY,PCIConfigSpace", config_space, 256); - free(config_space); + free (config_space); return 1; } -int devprop_add_ati_template_4xxx(struct DevPropDevice *device) +static int devprop_add_ati_template_4xxx(struct DevPropDevice *device) { if(!device) return 0; @@ -524,7 +517,7 @@ return 1; } -int devprop_add_ati_template(struct DevPropDevice *device) +static int devprop_add_ati_template(struct DevPropDevice *device) { if(!device) return 0; @@ -613,65 +606,60 @@ bool setup_ati_devprop(pci_dt_t *ati_dev) { -// int len; - char *devicepath; -// volatile uint8_t *regs; -// uint32_t bar[7]; - - char *model; - char *framebuffer; - char tmpString[64]; - char *rom=0; - uint32_t rom_size=0; - char *biosimage = 0; - uint32_t biosimage_size = 0; - uint8_t toFree = 0; - char romfilename[32]; - const char *val; - int len1; - uint32_t vram_size=0; - uint8_t cmd=0; - + struct DevPropDevice *device; + char *devicepath; + char *model; + char *framebuffer; + char tmp[64]; + uint8_t *rom = NULL; + uint32_t rom_size = 0; + uint8_t *bios; + uint32_t bios_size; + uint32_t vram_size; + uint32_t boot_display; + uint8_t cmd; + bool doit; + bool toFree; + devicepath = get_pci_dev_path(ati_dev); - cmd = pci_config_read8( ati_dev->dev.addr, 4); + cmd = pci_config_read8(ati_dev->dev.addr, 4); verbose("old pci command - %x\n", cmd); - if( cmd == 0) { - pci_config_write8(ati_dev->dev.addr, 4, 6); - cmd = pci_config_read8( ati_dev->dev.addr, 4); - verbose("new pci command - %x\n", cmd); - }; + if (cmd == 0) { + pci_config_write8(ati_dev->dev.addr, 4, 6); + cmd = pci_config_read8(ati_dev->dev.addr, 4); + verbose("new pci command - %x\n", cmd); + } model = get_ati_model((ati_dev->vendor_id << 16) | ati_dev->device_id); - framebuffer = get_ati_fb((ati_dev->vendor_id << 16) | ati_dev->device_id); - if (!string) + if (!string) { string = devprop_create_string(); - - struct DevPropDevice *device = malloc(sizeof(struct DevPropDevice)); + } device = devprop_add_device(string, devicepath); - - if(!device) - { + if (!device) { printf("Failed initializing dev-prop string dev-entry, press any key...\n"); getc(); return false; } /* FIXME: for primary graphics card only */ - uint32_t boot_display = 0x00000001; - if(radeon_card_posted(ati_dev)) boot_display=0x01; - else boot_display=0x00; + if (radeon_card_posted(ati_dev)) { + boot_display = 1; + } else { + boot_display = 0; + } verbose("boot display - %x\n", boot_display); devprop_add_value(device, "@0,AAPL,boot-display", (uint8_t*)&boot_display, 4); - if(framebuffer[0] == 'M' && framebuffer[1] == 'o' && framebuffer[2] == 't') //faster than strcmp ;) + if (framebuffer[0] == 'M' && framebuffer[1] == 'o' && framebuffer[2] == 't') { devprop_add_ati_template_4xxx(device); - else - { + } else { devprop_add_ati_template(device); vram_size = getvramsizekb(ati_dev) * 1024; - if ((vram_size > 0x80000000) || (vram_size == 0)) vram_size = 0x10000000; //vram reported wrong, defaulting to 256 mb + if ((vram_size > 0x80000000) || (vram_size == 0)) { + vram_size = 0x10000000; //vram reported wrong, defaulting to 256 mb + } devprop_add_value(device, "VRAM,totalsize", (uint8_t*)&vram_size, 4); ati_vram_memsize_0.data[6] = (vram_size >> 16) & 0xFF; //4,5 are 0x00 anyway ati_vram_memsize_0.data[7] = (vram_size >> 24) & 0xFF; @@ -683,93 +671,90 @@ } devprop_add_value(device, "model", (uint8_t*)model, (strlen(model) + 1)); devprop_add_value(device, "ATY,DeviceID", (uint8_t*)&ati_dev->device_id, 2); - //fb setup - char tmp[10]; - + //fb setup sprintf(tmp, "Slot-%x",devices_number); - devprop_add_value(device, "AAPL,slot-name", (uint8_t*)tmp, strlen(tmp)); + devprop_add_value(device, "AAPL,slot-name", (uint8_t*)tmp, strlen(tmp) + 1); devices_number++; - - sprintf(tmpString, ati_compatible_0[1], framebuffer); - devprop_add_value(device, (char *) ati_compatible_0[0], (uint8_t *)tmpString, strlen(tmpString)+1); - - sprintf(tmpString, ati_compatible_1[1], framebuffer); - devprop_add_value(device, (char *) ati_compatible_1[0], (uint8_t *)tmpString, strlen(tmpString)+1); - - sprintf(tmpString, ati_device_type[1], framebuffer); - devprop_add_value(device, (char *) ati_device_type[0], (uint8_t *)tmpString, strlen(tmpString)+1); - - sprintf(tmpString, ati_name[1], framebuffer); - devprop_add_value(device, (char *) ati_name[0], (uint8_t *)tmpString, strlen(tmpString)+1); - - sprintf(tmpString, ati_name_0[1], framebuffer); - devprop_add_value(device, (char *) ati_name_0[0], (uint8_t *)tmpString, strlen(tmpString)+1); - - sprintf(tmpString, ati_name_1[1], framebuffer); - devprop_add_value(device, (char *) ati_name_1[0], (uint8_t *)tmpString, strlen(tmpString)+1); - //code for loading bios from file, in form - rom_devid_vendif.rom - if (getValueForKey("-useatirom", &val, &len1, &bootInfo->bootConfig)) - { - sprintf(romfilename, "ati_%04x_%04x.rom", (uint16_t)ati_dev->device_id, (uint16_t)ati_dev->vendor_id); - verbose("looking for file /Extra/%s\n", romfilename); + + sprintf(tmp, ati_compatible_0[1], framebuffer); + devprop_add_value(device, (char *) ati_compatible_0[0], (uint8_t *)tmp, strlen(tmp) + 1); + + sprintf(tmp, ati_compatible_1[1], framebuffer); + devprop_add_value(device, (char *) ati_compatible_1[0], (uint8_t *)tmp, strlen(tmp) + 1); + + sprintf(tmp, ati_device_type[1], framebuffer); + devprop_add_value(device, (char *) ati_device_type[0], (uint8_t *)tmp, strlen(tmp) + 1); + + sprintf(tmp, ati_name[1], framebuffer); + devprop_add_value(device, (char *) ati_name[0], (uint8_t *)tmp, strlen(tmp) + 1); + + sprintf(tmp, ati_name_0[1], framebuffer); + devprop_add_value(device, (char *) ati_name_0[0], (uint8_t *)tmp, strlen(tmp) + 1); + + sprintf(tmp, ati_name_1[1], framebuffer); + devprop_add_value(device, (char *) ati_name_1[0], (uint8_t *)tmp, strlen(tmp) + 1); + + sprintf(tmp, "/Extra/%04x_%04x.rom", (uint16_t)ati_dev->vendor_id, (uint16_t)ati_dev->device_id); + if (getBoolForKey(kUseAtiROM, &doit, &bootInfo->bootConfig) && doit) { + verbose("looking for ati video bios file %s\n", tmp); rom = malloc(0x20000); - rom_size = load_ati_bios_file((char *)romfilename, (char *)rom); - if(rom_size > 0x10000) rom_size = 0x10000; //we dont need rest anyway; - if(rom_size == 0) printf("file not found\n"); - }; - { - if(rom_size == 0) - { - if(boot_display) // no custom rom - biosimage = 0; //try to dump from legacy space, otherwise can result in 100% fan speed - else - biosimage = (char *)readAtomBIOS(ati_dev); //readAtomBios result in bug on some cards (100% fan speed and black screen), - //not using it for posted card, rading from legacy space instead + rom_size = load_ati_bios_file(tmp, rom, 0x20000); + if (rom_size > 0x10000) { + rom_size = 0x10000; //we dont need rest anyway; + } + if (rom_size == 0) { + printf("ATI ROM File '%s' not found\n", tmp); + } + } + if (rom_size == 0) { + if (boot_display) { // no custom rom + bios = NULL; // try to dump from legacy space, otherwise can result in 100% fan speed } else { - biosimage = rom; //going custom rom way - verbose("Using rom %s\n", romfilename); + // readAtomBios result in bug on some cards (100% fan speed and black screen), + // not using it for posted card, rading from legacy space instead + bios = readAtomBIOS(ati_dev); } - if(biosimage == 0) - { - biosimage = (char *)0xC0000; - toFree = 0; - verbose("Not going to use bios image file\n"); - } else toFree = 1; + } else { + bios = rom; //going custom rom way + verbose("Using rom %s\n", tmp); + } + if (bios == NULL) { + bios = (uint8_t *)0x000C0000; + toFree = false; + verbose("Not going to use bios image file\n"); + } else { + toFree = true; + } - if ((uint8_t)biosimage[0] == 0x55 && (uint8_t)biosimage[1] == 0xaa) - { - printf("Found bios image\n"); - biosimage_size = (uint8_t)biosimage[2] * 512; - - struct pci_rom_pci_header_t *rom_pci_header; - rom_pci_header = (struct pci_rom_pci_header_t*)(biosimage + (uint8_t)biosimage[24] + (uint8_t)biosimage[25]*256); - - if (rom_pci_header->signature == 0x52494350) - { - if (rom_pci_header->device != ati_dev->device_id) - { - verbose("Bios image (%x) doesnt match card (%x), ignoring\n", rom_pci_header->device, ati_dev->device_id); + if (bios[0] == 0x55 && bios[1] == 0xaa) { + printf("Found bios image\n"); + bios_size = bios[2] * 512; + + struct pci_rom_pci_header_t *rom_pci_header; + rom_pci_header = (struct pci_rom_pci_header_t*)(bios + bios[24] + bios[25]*256); + + if (rom_pci_header->signature == 0x52494350) { + if (rom_pci_header->device != ati_dev->device_id) { + verbose("Bios image (%x) doesnt match card (%x), ignoring\n", rom_pci_header->device, ati_dev->device_id); + } else { + if (toFree) { + verbose("Adding binimage to card %x from mmio space with size %x\n", ati_dev->device_id, bios_size); } else { - if(toFree) - verbose("Adding binimage to card %x from mmio space with size %x\n", ati_dev->device_id, biosimage_size); - else - verbose("Adding binimage to card %x from legacy space with size %x\n", ati_dev->device_id, biosimage_size); - devprop_add_value(device, "ATY,bin_image", (uint8_t*) biosimage, biosimage_size); + verbose("Adding binimage to card %x from legacy space with size %x\n", ati_dev->device_id, bios_size); } - } else verbose("Wrong pci header signature %x\n", rom_pci_header->signature); - - } else verbose("Bios image not found at %x, content %x %x\n", biosimage, (uint8_t)biosimage[0], (uint8_t)biosimage[1]); - if(toFree) free(biosimage); + devprop_add_value(device, "ATY,bin_image", bios, bios_size); + } + } else { + verbose("Wrong pci header signature %x\n", rom_pci_header->signature); + } + } else { + verbose("Bios image not found at %x, content %x %x\n", bios, bios[0], bios[1]); } - stringdata = malloc(sizeof(uint8_t) * string->length); - if(!stringdata) - { - printf("no stringdata press a key...\n"); - getc(); - return false; + if (toFree) { + free(bios); } - + stringdata = malloc(sizeof(uint8_t) * string->length); memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length); stringlength = string->length; Index: trunk/i386/libsaio/sys.c =================================================================== --- trunk/i386/libsaio/sys.c (revision 22) +++ trunk/i386/libsaio/sys.c (revision 23) @@ -61,7 +61,9 @@ #include #include "libsaio.h" +#include "boot.h" #include "bootstruct.h" +#include "ramdisk.h" #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5 # include #else @@ -110,8 +112,8 @@ BVRef gBootVolume; // zef - ramdisk variables -extern BVRef gRAMDiskVolume; -extern BOOL gRAMDiskBTAliased; +//extern BVRef gRAMDiskVolume; +//extern bool gRAMDiskBTAliased; //static BVRef getBootVolumeRef( const char * path, const char ** outPath ); static BVRef newBootVolumeRef( int biosdev, int partno ); @@ -367,6 +369,24 @@ } //========================================================================== +// GetFreeFD() + +static int GetFreeFd(void) +{ + int fd; + + // Locate a free descriptor slot. + for (fd = 0; fd < NFILES; fd++) { + if (iob[fd].i_flgs == 0) { + return fd; + } + } + stop("Out of file descriptors"); + // not reached + return -1; +} + +//========================================================================== // iob_from_fdesc() // // Return a pointer to an allocated 'iob' based on the file descriptor @@ -392,15 +412,7 @@ int fdesc; struct iob * io; - // Locate a free descriptor slot. - - for (fdesc = 0; fdesc < NFILES; fdesc++) - if (iob[fdesc].i_flgs == 0) - goto gotfile; - - stop("Out of file descriptors"); - -gotfile: + fdesc = GetFreeFd(); io = &iob[fdesc]; bzero(io, sizeof(*io)); @@ -418,57 +430,107 @@ //========================================================================== // open() - Open the file specified by 'path' for reading. -int open(const char * path, int flags) +static int open_bvr(BVRef bvr, const char *filePath, int flags) { - int fdesc, i; - struct iob * io; - const char * filePath; - BVRef bvr; + struct iob *io; + int fdesc; + int i; - // Locate a free descriptor slot. + if (bvr == NULL) { + return -1; + } - for (fdesc = 0; fdesc < NFILES; fdesc++) - if (iob[fdesc].i_flgs == 0) - goto gotfile; + fdesc = GetFreeFd(); + io = &iob[fdesc]; + bzero(io, sizeof(*io)); - stop("Out of file descriptors"); + // Mark the descriptor as taken. + io->i_flgs = F_ALLOC; -gotfile: - io = &iob[fdesc]; - bzero(io, sizeof(*io)); + // Find the next available memory block in the download buffer. + io->i_buf = (char *) LOAD_ADDR; + for (i = 0; i < NFILES; i++) { + if ((iob[i].i_flgs != F_ALLOC) || (i == fdesc)) { + continue; + } + io->i_buf = max(iob[i].i_filesize + iob[i].i_buf, io->i_buf); + } - // Mark the descriptor as taken. + // Load entire file into memory. Unnecessary open() calls must be avoided. + gFSLoadAddress = io->i_buf; + io->i_filesize = bvr->fs_loadfile(bvr, (char *)filePath); + if (io->i_filesize < 0) { + close(fdesc); + return -1; + } + return fdesc; +} - io->i_flgs = F_ALLOC; +int open(const char *path, int flags) +{ + const char *filepath; + BVRef bvr; - // Resolve the boot volume from the file spec. + // Resolve the boot volume from the file spec. + if ((bvr = getBootVolumeRef(path, &filepath)) != NULL) { + return open_bvr(bvr, filepath, flags); + } + return -1; +} - if ((bvr = getBootVolumeRef(path, &filePath)) == NULL) - goto error; +int open_bvdev(const char *bvd, const char *path, int flags) +{ + const struct devsw *dp; + const char *cp; + BVRef bvr; + int i; + int len; + int unit; + int partition; - // Find the next available memory block in the download buffer. + if ((i = open(path, flags)) >= 0) { + return i; + } - io->i_buf = (char *) LOAD_ADDR; - for (i = 0; i < NFILES; i++) - { - if ((iob[i].i_flgs != F_ALLOC) || (i == fdesc)) continue; - io->i_buf = max(iob[i].i_filesize + iob[i].i_buf, io->i_buf); - } + if (bvd == NULL || (len = strlen(bvd)) < 2) { + return -1; + } - // Load entire file into memory. Unnecessary open() calls must - // be avoided. - - gFSLoadAddress = io->i_buf; - io->i_filesize = bvr->fs_loadfile(bvr, (char *)filePath); - if (io->i_filesize < 0) { - goto error; - } - - return fdesc; - -error: - close(fdesc); - return -1; + for (dp=devsw; dp->name; dp++) { + if (bvd[0] == dp->name[0] && bvd[1] == dp->name[1]) { + unit = 0; + partition = 0; + /* get optional unit and partition */ + if (len >= 5 && bvd[2] == '(') { /* min must be present xx(0) */ + cp = &bvd[3]; + i = 0; + while ((cp - path) < len && isdigit(*cp)) { + i = i * 10 + *cp++ - '0'; + unit = i; + } + if (*cp++ == ',') { + i = 0; + while ((cp - path) < len && isdigit(*cp)) { + i = i * 10 + *cp++ - '0'; + partition = i; + } + } + } + // turbo - bt(0,0) hook + if ((dp->biosdev + unit) == 0x101) { + // zef - use the ramdisk if available and the alias is active. + if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) { + bvr = gRAMDiskVolume; + } else { + bvr = gBIOSBootVolume; + } + } else { + bvr = newBootVolumeRef(dp->biosdev + unit, partition); + } + return open_bvr(bvr, path, flags); + } + } + return -1; } //========================================================================== @@ -700,11 +762,11 @@ BVRef selectBootVolume( BVRef chain ) { - BOOL filteredChain = FALSE; - BOOL foundPrimary = FALSE; + bool filteredChain = false; + bool foundPrimary = false; BVRef bvr, bvr1 = 0, bvr2 = 0; - if (chain->filtered) filteredChain = TRUE; + if (chain->filtered) filteredChain = true; if (multiboot_partition_set) for ( bvr = chain; bvr; bvr = bvr->next ) @@ -719,7 +781,7 @@ char testStr[64]; int cnt; - if (getValueForKey("Default Partition", &val, &cnt, &bootInfo->bootConfig) && cnt >= 7 && filteredChain) + if (getValueForKey(kDefaultPartition, &val, &cnt, &bootInfo->bootConfig) && cnt >= 7 && filteredChain) { for ( bvr = chain; bvr; bvr = bvr->next ) { @@ -741,7 +803,7 @@ */ for ( bvr = chain; bvr; bvr = bvr->next ) { - if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) foundPrimary = TRUE; + if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) foundPrimary = true; // zhell -- Undo a regression that was introduced from r491 to 492. // if gBIOSBootVolume is set already, no change is required if ( bvr->flags & (kBVFlagBootable|kBVFlagSystemVolume) @@ -898,7 +960,7 @@ if (biosdev == 0x101) { // zef - use the ramdisk if available and the alias is active. - if (gRAMDiskVolume != NULL && gRAMDiskBTAliased == 1) + if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) bvr = gRAMDiskVolume; else bvr = gBIOSBootVolume; Index: trunk/i386/libsaio/load.c =================================================================== --- trunk/i386/libsaio/load.c (revision 22) +++ trunk/i386/libsaio/load.c (revision 23) @@ -38,7 +38,7 @@ static unsigned long gBinaryAddress; -BOOL gHaveKernelCache; +bool gHaveKernelCache; /* XXX aserebln: uninitialized? and only set to true, never to false */ cpu_type_t archCpuType=CPU_TYPE_I386; // Public Functions @@ -250,7 +250,7 @@ } if (vmsize && (strcmp(segname, "__PRELINK") == 0)) - gHaveKernelCache = 1; + gHaveKernelCache = true; // Copy from file load area. if (vmsize>0 && filesize>0) Index: trunk/i386/libsaio/ntfs.h =================================================================== --- trunk/i386/libsaio/ntfs.h (revision 22) +++ trunk/i386/libsaio/ntfs.h (revision 23) @@ -21,5 +21,5 @@ */ extern void NTFSGetDescription(CICell ih, char *str, long strMaxLen); -extern BOOL NTFSProbe (const void *buf); +extern bool NTFSProbe (const void *buf); Index: trunk/i386/libsaio/acpi.h =================================================================== --- trunk/i386/libsaio/acpi.h (revision 22) +++ trunk/i386/libsaio/acpi.h (revision 23) @@ -72,11 +72,20 @@ uint32_t FIRMWARE_CTRL; uint32_t DSDT; /*We absolutely don't care about theese fields*/ - uint8_t notimp1[88]; - uint64_t X_FIRMWARE_CTRL; - uint64_t X_DSDT; + uint8_t notimp1[68]; + /*Reset Fix*/ + uint32_t Flags; + uint8_t Reset_SpaceID; + uint8_t Reset_BitWidth; + uint8_t Reset_BitOffset; + uint8_t Reset_AccessWidth; + uint64_t Reset_Address; + uint8_t Reset_Value; + uint8_t Reserved[3]; + uint64_t X_FIRMWARE_CTRL; + uint64_t X_DSDT; /*We absolutely don't care about theese fields*/ - uint8_t notimp2[96]; + uint8_t notimp2[96]; } __attribute__((packed)); #endif /* !__LIBSAIO_ACPI_H */ Index: trunk/i386/libsaio/ati.h =================================================================== --- trunk/i386/libsaio/ati.h (revision 22) +++ trunk/i386/libsaio/ati.h (revision 23) @@ -37,11 +37,6 @@ uint8_t data[]; }; -struct bios { - uint16_t signature; /* 0x55AA */ - uint8_t size; /* Size in multiples of 512 */ -}; - #define REG8(reg) ((volatile uint8_t *)regs)[(reg)] #define REG16(reg) ((volatile uint16_t *)regs)[(reg) >> 1] #define REG32R(reg) ((volatile uint32_t *)regs)[(reg) >> 2] Index: trunk/i386/libsaio/platform.c =================================================================== --- trunk/i386/libsaio/platform.c (revision 22) +++ trunk/i386/libsaio/platform.c (revision 23) @@ -1,15 +1,15 @@ /* * platform.c * + * AsereBLN: cleanup */ #include "libsaio.h" #include "bootstruct.h" #include "pci.h" -#include "freq_detect.h" -#include "nvidia.h" -#include "spd.h" #include "platform.h" +#include "cpu.h" +#include "mem.h" #ifndef DEBUG_PLATFORM #define DEBUG_PLATFORM 0 @@ -23,71 +23,20 @@ PlatformInfo_t Platform; -void scan_cpu_amd() +bool platformCPUFeature(uint32_t feature) { - // AMD - - // TODO: Retrieve cpu brand string - // TODO: Retrieve cpu core count - // TODO: Retrieve cpu mobile info - + if (Platform.CPU.Features & feature) { + return true; + } else { + return false; + } } -void scan_cpu_intel() +void scan_platform(void) { - uint32_t cpuid_reg[4]; - - // Get Number of cores per package - /* - Initially set the EAX register to 4 and the ECX register to 0 prior to executing the CPUID instruction. - After executing the CPUID instruction, (EAX[31:26] + 1) contains the number of cores. - */ - cpuid_reg[2]=1; - do_cpuid(4, cpuid_reg); - do_cpuid(4, cpuid_reg); // FIXME: why does this only work the 2nd time ? - Platform.CPU.NoCores = bitfield(cpuid_reg[0], 31, 26) + 1; - - // Find Number of Concurrent Threads Processed (HyperThreading) - do_cpuid(1,cpuid_reg); - if(bitfield(cpuid_reg[1], 23, 16) > 1) - Platform.CPU.NoThreads=Platform.CPU.NoCores; - else - Platform.CPU.NoThreads=Platform.CPU.NoCores * 2; - - // Mobile CPU ? - if (rdmsr64(0x17) & (1<<28)) - Platform.CPU.Mobile = 1; - else - Platform.CPU.Mobile = 0; -} - -void scan_platform() -{ - uint32_t cpuid_reg[4]; - + memset(&Platform, 0, sizeof(Platform)); build_pci_dt(); - - calculate_freq(); - - // Copy the values from calculate_freq() - Platform.CPU.TSCFrequency = tscFrequency; - Platform.CPU.FSBFrequency = fsbFrequency; - Platform.CPU.CPUFrequency = cpuFrequency; - - do_cpuid(0, cpuid_reg); - Platform.CPU.Vendor = cpuid_reg[1]; - - do_cpuid(1, cpuid_reg); - Platform.CPU.Model = bitfield(cpuid_reg[0], 7, 4); - Platform.CPU.Family = bitfield(cpuid_reg[0], 11, 8); - Platform.CPU.ExtModel = bitfield(cpuid_reg[0], 19, 16); - Platform.CPU.ExtFamily = bitfield(cpuid_reg[0], 27, 20); - - // Get vendor specific cpu data - if((Platform.CPU.Vendor == 0x756E6547 /* Intel */) && ((Platform.CPU.Family == 0x06) || (Platform.CPU.Family == 0x0f))) - scan_cpu_intel(); - else if((Platform.CPU.Vendor == 0x68747541 /* AMD */) && (Platform.CPU.Family == 0x0f)) - scan_cpu_amd(); + scan_cpu(&Platform); + scan_memory(&Platform); + scan_spd(&Platform); } - - Index: trunk/i386/libsaio/cpu.c =================================================================== --- trunk/i386/libsaio/cpu.c (revision 0) +++ trunk/i386/libsaio/cpu.c (revision 23) @@ -0,0 +1,375 @@ +/* + * Copyright 2008 Islam Ahmed Zaid. All rights reserved. + * AsereBLN: 2009: cleanup and bugfix + */ + +#include "libsaio.h" +#include "platform.h" +#include "cpu.h" + +#ifndef DEBUG_CPU +#define DEBUG_CPU 0 +#endif + +#if DEBUG_CPU +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + + +static inline uint64_t rdtsc64(void) +{ + uint64_t ret; + __asm__ volatile("rdtsc" : "=A" (ret)); + return ret; +} + +static inline uint64_t rdmsr64(uint32_t msr) +{ + uint64_t ret; + __asm__ volatile("rdmsr" : "=A" (ret) : "c" (msr)); + return ret; +} + +static inline void do_cpuid(uint32_t selector, uint32_t *data) +{ + asm volatile ("cpuid" + : "=a" (data[0]), + "=b" (data[1]), + "=c" (data[2]), + "=d" (data[3]) + : "a" (selector)); +} + +static inline void do_cpuid2(uint32_t selector, uint32_t selector2, uint32_t *data) +{ + asm volatile ("cpuid" + : "=a" (data[0]), + "=b" (data[1]), + "=c" (data[2]), + "=d" (data[3]) + : "a" (selector), "c" (selector2)); +} + +// DFE: enable_PIT2 and disable_PIT2 come from older xnu + +/* + * Enable or disable timer 2. + * Port 0x61 controls timer 2: + * bit 0 gates the clock, + * bit 1 gates output to speaker. + */ +static inline void enable_PIT2(void) +{ + /* Enable gate, disable speaker */ + __asm__ volatile( + " inb $0x61,%%al \n\t" + " and $0xFC,%%al \n\t" /* & ~0x03 */ + " or $1,%%al \n\t" + " outb %%al,$0x61 \n\t" + : : : "%al" ); +} + +static inline void disable_PIT2(void) +{ + /* Disable gate and output to speaker */ + __asm__ volatile( + " inb $0x61,%%al \n\t" + " and $0xFC,%%al \n\t" /* & ~0x03 */ + " outb %%al,$0x61 \n\t" + : : : "%al" ); +} + +// DFE: set_PIT2_mode0, poll_PIT2_gate, and measure_tsc_frequency are +// roughly based on Linux code + +/* Set the 8254 channel 2 to mode 0 with the specified value. + In mode 0, the counter will initially set its gate low when the + timer expires. For this to be useful, you ought to set it high + before calling this function. The enable_PIT2 function does this. + */ +static inline void set_PIT2_mode0(uint16_t value) +{ + __asm__ volatile( + " movb $0xB0,%%al \n\t" + " outb %%al,$0x43 \n\t" + " movb %%dl,%%al \n\t" + " outb %%al,$0x42 \n\t" + " movb %%dh,%%al \n\t" + " outb %%al,$0x42" + : : "d"(value) /*: no clobber */ ); +} + +/* Returns the number of times the loop ran before the PIT2 signaled */ +static inline unsigned long poll_PIT2_gate(void) +{ + unsigned long count = 0; + unsigned char nmi_sc_val; + do { + ++count; + __asm__ volatile( + "inb $0x61,%0" + : "=q"(nmi_sc_val) /*:*/ /* no input */ /*:*/ /* no clobber */); + } while( (nmi_sc_val & 0x20) == 0); + return count; +} + +/* + * DFE: Measures the TSC frequency in Hz (64-bit) using the ACPI PM timer + */ +static uint64_t measure_tsc_frequency(void) +{ + uint64_t tscStart; + uint64_t tscEnd; + uint64_t tscDelta = 0xffffffffffffffffULL; + unsigned long pollCount; + uint64_t retval = 0; + int i; + + /* Time how many TSC ticks elapse in 30 msec using the 8254 PIT + * counter 2. We run this loop 3 times to make sure the cache + * is hot and we take the minimum delta from all of the runs. + * That is to say that we're biased towards measuring the minimum + * number of TSC ticks that occur while waiting for the timer to + * expire. That theoretically helps avoid inconsistencies when + * running under a VM if the TSC is not virtualized and the host + * steals time. The TSC is normally virtualized for VMware. + */ + for(i = 0; i < 10; ++i) + { + enable_PIT2(); + set_PIT2_mode0(CALIBRATE_LATCH); + tscStart = rdtsc64(); + pollCount = poll_PIT2_gate(); + tscEnd = rdtsc64(); + /* The poll loop must have run at least a few times for accuracy */ + 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) + continue; + // tscDelta = min(tscDelta, (tscEnd - tscStart)) + if( (tscEnd - tscStart) < tscDelta ) + tscDelta = tscEnd - tscStart; + } + /* tscDelta is now the least number of TSC ticks the processor made in + * a timespan of 0.03 s (e.g. 30 milliseconds) + * Linux thus divides by 30 which gives the answer in kiloHertz because + * 1 / ms = kHz. But we're xnu and most of the rest of the code uses + * Hz so we need to convert our milliseconds to seconds. Since we're + * dividing by the milliseconds, we simply multiply by 1000. + */ + + /* Unlike linux, we're not limited to 32-bit, but we do need to take care + * that we're going to multiply by 1000 first so we do need at least some + * arithmetic headroom. For now, 32-bit should be enough. + * Also unlike Linux, our compiler can do 64-bit integer arithmetic. + */ + if(tscDelta > (1ULL<<32)) + retval = 0; + else + { + retval = tscDelta * 1000 / 30; + } + disable_PIT2(); + return retval; +} + +/* + * Calculates the FSB and CPU frequencies using specific MSRs for each CPU + * - multi. is read from a specific MSR. In the case of Intel, there is: + * a max multi. (used to calculate the FSB freq.), + * and a current multi. (used to calculate the CPU freq.) + * - fsbFrequency = tscFrequency / multi + * - cpuFrequency = fsbFrequency * multi + */ + +void scan_cpu(PlatformInfo_t *p) +{ + uint64_t tscFrequency, fsbFrequency, cpuFrequency; + uint64_t msr, flex_ratio; + uint8_t maxcoef, maxdiv, currcoef, currdiv; + + maxcoef = maxdiv = currcoef = currdiv = 0; + + /* get cpuid values */ + do_cpuid(0x00000000, p->CPU.CPUID[CPUID_0]); + do_cpuid(0x00000001, p->CPU.CPUID[CPUID_1]); + do_cpuid(0x00000002, p->CPU.CPUID[CPUID_2]); + do_cpuid(0x00000003, p->CPU.CPUID[CPUID_3]); + do_cpuid2(0x00000004, 0, p->CPU.CPUID[CPUID_4]); + do_cpuid(0x80000000, p->CPU.CPUID[CPUID_80]); + if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) { + do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]); + } +#if DEBUG_CPU + { + int i; + printf("CPUID Raw Values:\n"); + for (i=0; iCPU.CPUID[i][0], p->CPU.CPUID[i][1], + p->CPU.CPUID[i][2], p->CPU.CPUID[i][3]); + } + } +#endif + p->CPU.Vendor = p->CPU.CPUID[CPUID_0][1]; + p->CPU.Model = bitfield(p->CPU.CPUID[CPUID_1][0], 7, 4); + p->CPU.Family = bitfield(p->CPU.CPUID[CPUID_1][0], 11, 8); + p->CPU.ExtModel = bitfield(p->CPU.CPUID[CPUID_1][0], 19, 16); + p->CPU.ExtFamily = bitfield(p->CPU.CPUID[CPUID_1][0], 27, 20); + p->CPU.NoThreads = bitfield(p->CPU.CPUID[CPUID_1][1], 23, 16); + p->CPU.NoCores = bitfield(p->CPU.CPUID[CPUID_4][0], 31, 26) + 1; + + p->CPU.Model += (p->CPU.ExtModel << 4); + + /* setup features */ + if ((bit(23) & p->CPU.CPUID[CPUID_1][3]) != 0) { + p->CPU.Features |= CPU_FEATURE_MMX; + } + if ((bit(25) & p->CPU.CPUID[CPUID_1][3]) != 0) { + p->CPU.Features |= CPU_FEATURE_SSE; + } + if ((bit(26) & p->CPU.CPUID[CPUID_1][3]) != 0) { + p->CPU.Features |= CPU_FEATURE_SSE2; + } + if ((bit(0) & p->CPU.CPUID[CPUID_1][2]) != 0) { + p->CPU.Features |= CPU_FEATURE_SSE3; + } + if ((bit(19) & p->CPU.CPUID[CPUID_1][2]) != 0) { + p->CPU.Features |= CPU_FEATURE_SSE41; + } + if ((bit(20) & p->CPU.CPUID[CPUID_1][2]) != 0) { + p->CPU.Features |= CPU_FEATURE_SSE42; + } + if ((bit(29) & p->CPU.CPUID[CPUID_81][3]) != 0) { + p->CPU.Features |= CPU_FEATURE_EM64T; + } + //if ((bit(28) & p->CPU.CPUID[CPUID_1][3]) != 0) { + if (p->CPU.NoThreads > p->CPU.NoCores) { + p->CPU.Features |= CPU_FEATURE_HTT; + } + + tscFrequency = measure_tsc_frequency(); + fsbFrequency = 0; + cpuFrequency = 0; + + if ((p->CPU.Vendor == 0x756E6547 /* Intel */) && ((p->CPU.Family == 0x06) || (p->CPU.Family == 0x0f))) { + if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0c) || (p->CPU.Family == 0x0f && p->CPU.Model >= 0x03)) { + /* Nehalem CPU model */ + if (p->CPU.Family == 0x06 && (p->CPU.Model == 0x1a || p->CPU.Model == 0x1e)) { + msr = rdmsr64(MSR_PLATFORM_INFO); + DBG("msr(%d): platform_info %08x\n", __LINE__, msr & 0xffffffff); + currcoef = (msr >> 8) & 0xff; + msr = rdmsr64(MSR_FLEX_RATIO); + DBG("msr(%d): flex_ratio %08x\n", __LINE__, msr & 0xffffffff); + if ((msr >> 16) & 0x01) { + flex_ratio = (msr >> 8) & 0xff; + if (currcoef > flex_ratio) { + currcoef = flex_ratio; + } + } + + if (currcoef) { + fsbFrequency = (tscFrequency / currcoef); + } + cpuFrequency = tscFrequency; + } else { + msr = rdmsr64(IA32_PERF_STATUS); + DBG("msr(%d): ia32_perf_stat 0x%08x\n", __LINE__, msr & 0xffffffff); + currcoef = (msr >> 8) & 0x1f; + /* Non-integer bus ratio for the max-multi*/ + maxdiv = (msr >> 46) & 0x01; + /* Non-integer bus ratio for the current-multi (undocumented)*/ + currdiv = (msr >> 14) & 0x01; + + if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f)) // This will always be model >= 3 + { + /* On these models, maxcoef defines TSC freq */ + maxcoef = (msr >> 40) & 0x1f; + } else { + /* On lower models, currcoef defines TSC freq */ + /* XXX */ + maxcoef = currcoef; + } + + if (maxcoef) { + if (maxdiv) { + fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1)); + } else { + fsbFrequency = (tscFrequency / maxcoef); + } + if (currdiv) { + cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2); + } else { + cpuFrequency = (fsbFrequency * currcoef); + } + DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : ""); + } + } + } + /* Mobile CPU ? */ + if (rdmsr64(0x17) & (1<<28)) { + p->CPU.Features |= CPU_FEATURE_MOBILE; + } + } +#if 0 + else if((p->CPU.Vendor == 0x68747541 /* AMD */) && (p->CPU.Family == 0x0f)) { + if(p->CPU.ExtFamily == 0x00 /* K8 */) { + msr = rdmsr64(K8_FIDVID_STATUS); + currcoef = (msr & 0x3f) / 2 + 4; + currdiv = (msr & 0x01) * 2; + } else if(p->CPU.ExtFamily >= 0x01 /* K10+ */) { + msr = rdmsr64(K10_COFVID_STATUS); + if(p->CPU.ExtFamily == 0x01 /* K10 */) + currcoef = (msr & 0x3f) + 0x10; + else /* K11+ */ + currcoef = (msr & 0x3f) + 0x08; + currdiv = (2 << ((msr >> 6) & 0x07)); + } + + if (currcoef) { + if (currdiv) { + fsbFrequency = ((tscFrequency * currdiv) / currcoef); + DBG("%d.%d\n", currcoef / currdiv, ((currcoef % currdiv) * 100) / currdiv); + } else { + fsbFrequency = (tscFrequency / currcoef); + DBG("%d\n", currcoef); + } + fsbFrequency = (tscFrequency / currcoef); + cpuFrequency = tscFrequency; + } + } + + if (!fsbFrequency) { + fsbFrequency = (DEFAULT_FSB * 1000); + cpuFrequency = tscFrequency; + DBG("0 ! using the default value for FSB !\n"); + } +#endif + + p->CPU.MaxCoef = maxcoef; + p->CPU.MaxDiv = maxdiv; + p->CPU.CurrCoef = currcoef; + p->CPU.CurrDiv = currdiv; + p->CPU.TSCFrequency = tscFrequency; + p->CPU.FSBFrequency = fsbFrequency; + p->CPU.CPUFrequency = cpuFrequency; +#if DEBUG_CPU + DBG("CPU: Vendor/Model/ExtModel: 0x%x/0x%x/0x%x\n", p->CPU.Vendor, p->CPU.Model, p->CPU.ExtModel); + DBG("CPU: Family/ExtFamily: 0x%x/0x%x\n", p->CPU.Family, p->CPU.ExtFamily); + DBG("CPU: MaxCoef/CurrCoef: 0x%x/0x%x\n", p->CPU.MaxCoef, p->CPU.CurrCoef); + DBG("CPU: MaxDiv/CurrDiv: 0x%x/0x%x\n", p->CPU.MaxDiv, p->CPU.CurrDiv); + DBG("CPU: TSCFreq: %dMHz\n", p->CPU.TSCFrequency / 1000000); + DBG("CPU: FSBFreq: %dMHz\n", p->CPU.FSBFrequency / 1000000); + DBG("CPU: CPUFreq: %dMHz\n", p->CPU.CPUFrequency / 1000000); + DBG("CPU: NoCores/NoThreads: %d/%d\n", p->CPU.NoCores, p->CPU.NoThreads); + DBG("CPU: Features: 0x%08x\n", p->CPU.Features); + printf("(Press a key to continue...)\n"); + getc(); +#endif +} Index: trunk/i386/libsaio/platform.h =================================================================== --- trunk/i386/libsaio/platform.h (revision 22) +++ trunk/i386/libsaio/platform.h (revision 23) @@ -8,93 +8,102 @@ #include "libsaio.h" -#define bit(n) (1ULL << (n)) -#define bitmask(h,l) ((bit(h)|(bit(h)-1)) & ~(bit(l)-1)) -#define bitfield(x,h,l) (((x) & bitmask(h,l)) >> l) +extern bool platformCPUFeature(uint32_t); +extern void scan_platform(void); -extern void scan_platform(); +/* CPUID index into cpuid_raw */ +#define CPUID_0 0 +#define CPUID_1 1 +#define CPUID_2 2 +#define CPUID_3 3 +#define CPUID_4 4 +#define CPUID_80 5 +#define CPUID_81 6 +#define CPUID_MAX 7 +/* CPU Features */ +#define CPU_FEATURE_MMX 0x00000001 // MMX Instruction Set +#define CPU_FEATURE_SSE 0x00000002 // SSE Instruction Set +#define CPU_FEATURE_SSE2 0x00000004 // SSE2 Instruction Set +#define CPU_FEATURE_SSE3 0x00000008 // SSE3 Instruction Set +#define CPU_FEATURE_SSE41 0x00000010 // SSE41 Instruction Set +#define CPU_FEATURE_SSE42 0x00000020 // SSE42 Instruction Set +#define CPU_FEATURE_EM64T 0x00000040 // 64Bit Support +#define CPU_FEATURE_HTT 0x00000080 // HyperThreading +#define CPU_FEATURE_MOBILE 0x00000100 // Mobile CPU + /* SMBIOS Memory Types */ -#define SMB_MEM_TYPE_UNDEFINED 0 -#define SMB_MEM_TYPE_OTHER 1 -#define SMB_MEM_TYPE_UNKNOWN 2 -#define SMB_MEM_TYPE_DRAM 3 -#define SMB_MEM_TYPE_EDRAM 4 -#define SMB_MEM_TYPE_VRAM 5 -#define SMB_MEM_TYPE_SRAM 6 -#define SMB_MEM_TYPE_RAM 7 -#define SMB_MEM_TYPE_ROM 8 -#define SMB_MEM_TYPE_FLASH 9 -#define SMB_MEM_TYPE_EEPROM 10 -#define SMB_MEM_TYPE_FEPROM 11 -#define SMB_MEM_TYPE_EPROM 12 -#define SMB_MEM_TYPE_CDRAM 13 -#define SMB_MEM_TYPE_3DRAM 14 -#define SMB_MEM_TYPE_SDRAM 15 -#define SMB_MEM_TYPE_SGRAM 16 -#define SMB_MEM_TYPE_RDRAM 17 -#define SMB_MEM_TYPE_DDR 18 -#define SMB_MEM_TYPE_DDR2 19 -#define SMB_MEM_TYPE_FBDIMM 20 -#define SMB_MEM_TYPE_DDR3 24 // Supported in 10.5.6+ AppleSMBIOS +#define SMB_MEM_TYPE_UNDEFINED 0 +#define SMB_MEM_TYPE_OTHER 1 +#define SMB_MEM_TYPE_UNKNOWN 2 +#define SMB_MEM_TYPE_DRAM 3 +#define SMB_MEM_TYPE_EDRAM 4 +#define SMB_MEM_TYPE_VRAM 5 +#define SMB_MEM_TYPE_SRAM 6 +#define SMB_MEM_TYPE_RAM 7 +#define SMB_MEM_TYPE_ROM 8 +#define SMB_MEM_TYPE_FLASH 9 +#define SMB_MEM_TYPE_EEPROM 10 +#define SMB_MEM_TYPE_FEPROM 11 +#define SMB_MEM_TYPE_EPROM 12 +#define SMB_MEM_TYPE_CDRAM 13 +#define SMB_MEM_TYPE_3DRAM 14 +#define SMB_MEM_TYPE_SDRAM 15 +#define SMB_MEM_TYPE_SGRAM 16 +#define SMB_MEM_TYPE_RDRAM 17 +#define SMB_MEM_TYPE_DDR 18 +#define SMB_MEM_TYPE_DDR2 19 +#define SMB_MEM_TYPE_FBDIMM 20 +#define SMB_MEM_TYPE_DDR3 24 // Supported in 10.5.6+ AppleSMBIOS /* Memory Configuration Types */ -#define SMB_MEM_CHANNEL_UNKNOWN 0 -#define SMB_MEM_CHANNEL_SINGLE 1 -#define SMB_MEM_CHANNEL_DUAL 2 -#define SMB_MEM_CHANNEL_TRIPLE 3 +#define SMB_MEM_CHANNEL_UNKNOWN 0 +#define SMB_MEM_CHANNEL_SINGLE 1 +#define SMB_MEM_CHANNEL_DUAL 2 +#define SMB_MEM_CHANNEL_TRIPLE 3 /* Maximum number of ram slots */ -#define MAX_RAM_SLOTS 16 +#define MAX_RAM_SLOTS 8 +/* Maximum number of SPD bytes */ +#define MAX_SPD_SIZE 256 + typedef struct _RamSlotInfo_t { - bool InUse; // Module Present - uint32_t ModuleSize; // Size of Module in MB - char *spd; // SPD Dump + bool InUse; + uint8_t Type; + char Vendor[64]; + char PartNo[64]; + char SerialNo[16]; + uint8_t spd[MAX_SPD_SIZE]; } RamSlotInfo_t; typedef struct _PlatformInfo_t { - bool Mobile; // Mobile Platform - bool x86_64; // 64 Bit Capable - struct PCI { - uint8_t NoDevices; // No of PCI devices - } PCI; struct CPU { - uint32_t Vendor; // Vendor - uint32_t Model; // Model - uint32_t ExtModel; // Extended Model - uint32_t Family; // Family - uint32_t ExtFamily; // Extended Family - uint8_t NoCores; // No Cores per Package - uint8_t NoThreads; // Threads per Package - uint8_t MaxCoef; // Max Multiplier + uint32_t Features; // CPU Features like MMX, SSE2, VT, MobileCPU + uint32_t Vendor; // Vendor + uint32_t Model; // Model + uint32_t ExtModel; // Extended Model + uint32_t Family; // Family + uint32_t ExtFamily; // Extended Family + uint32_t NoCores; // No Cores per Package + uint32_t NoThreads; // Threads per Package + uint8_t MaxCoef; // Max Multiplier uint8_t MaxDiv; - uint8_t CurrCoef; // Current Multiplier + uint8_t CurrCoef; // Current Multiplier uint8_t CurrDiv; - float MaxRatio; - float CurrRatio; - uint64_t TSCFrequency; // TSC Frequency Hz - uint64_t FSBFrequency; // FSB Frequency Hz - uint64_t CPUFrequency; // CPU Frequency Hz - bool Mobile; // Mobile CPU - uint32_t BrandString[16]; // 48 Byte Branding String + uint64_t TSCFrequency; // TSC Frequency Hz + uint64_t FSBFrequency; // FSB Frequency Hz + uint64_t CPUFrequency; // CPU Frequency Hz + uint32_t BrandString[16]; // 48 Byte Branding String + uint32_t CPUID[CPUID_MAX][4]; // CPUID 0..4, 80..81 Raw Values } CPU; struct RAM { - uint64_t Frequency; // Ram Frequency - uint32_t Divider; // Memory divider - float CAS; // CAS 1/2/2.5/3/4/5/6/7 - uint8_t TRC; - uint8_t TRP; - uint8_t RAS; - uint8_t Channels; // Channel Configuration Single,Dual or Triple - uint8_t NoSlots; // Maximum no of slots available - uint8_t Type; // Standard SMBIOS v2.5 Memory Type - char *BrandString; // Branding String Memory Controller - RamSlotInfo_t DIMM[MAX_RAM_SLOTS]; // Information about each slot + RamSlotInfo_t DIMM[MAX_RAM_SLOTS]; // Information about each slot + uint64_t Frequency; // Ram Frequency + //uint8_t Type; // Standard SMBIOS v2.5 Memory Type } RAM; } PlatformInfo_t; extern PlatformInfo_t Platform; #endif /* !__LIBSAIO_PLATFORM_H */ - Index: trunk/i386/libsaio/disk.c =================================================================== --- trunk/i386/libsaio/disk.c (revision 22) +++ trunk/i386/libsaio/disk.c (revision 23) @@ -55,8 +55,9 @@ #define UFS_SUPPORT 0 #endif +#include "libsaio.h" +#include "boot.h" #include "bootstruct.h" -#include "libsaio.h" #include "fdisk.h" #if UFS_SUPPORT #include "ufs.h" @@ -218,7 +219,7 @@ // Return: // 0 on success, or an error code from INT13/F2 or INT13/F42 BIOS call. -static BOOL cache_valid = FALSE; +static bool cache_valid = false; static int Biosread( int biosdev, unsigned long long secno ) { @@ -264,7 +265,7 @@ xnsecs = N_CACHE_SECS; xsec = (secno / divisor) * divisor; - cache_valid = FALSE; + cache_valid = false; while ((rc = ebiosread(biosdev, secno / divisor, xnsecs / divisor)) && (++tries < 5)) { @@ -305,7 +306,7 @@ xhead = head; xsec = sec; xnsecs = ((unsigned int)(sec + N_CACHE_SECS) > di.di.params.phys_spt) ? (di.di.params.phys_spt - sec) : N_CACHE_SECS; - cache_valid = FALSE; + cache_valid = false; while ((rc = biosread(biosdev, cyl, head, sec, xnsecs)) && (++tries < 5)) @@ -325,7 +326,7 @@ // If the BIOS reported success, mark the sector cache as valid. if (rc == 0) { - cache_valid = TRUE; + cache_valid = true; } biosbuf = trackbuf + (secno % divisor) * BPS; xbiosdev = biosdev; @@ -1465,7 +1466,7 @@ { verbose("Resetting BIOS device %xh\n", biosdev); // Reset the biosbuf cache - cache_valid = FALSE; + cache_valid = false; if(map == gDiskBVMap) gDiskBVMap = map->next; else if(prevMap != NULL) @@ -1580,25 +1581,25 @@ * Adjust the new bvr's fields. */ newBVR->next = NULL; - newBVR->filtered = TRUE; + newBVR->filtered = true; if ( (!allowFlags || newBVR->flags & allowFlags) && (!denyFlags || !(newBVR->flags & denyFlags) ) && (newBVR->biosdev >= minBIOSDev && newBVR->biosdev <= maxBIOSDev) ) - newBVR->visible = TRUE; + newBVR->visible = true; /* * Looking for "Hide Partition" entries in "hd(x,y) hd(n,m)" format * to be able to hide foreign partitions from the boot menu. */ if ( (newBVR->flags & kBVFlagForeignBoot) - && getValueForKey("Hide Partition", &val, &len, &bootInfo->bootConfig) + && getValueForKey(kHidePartition, &val, &len, &bootInfo->bootConfig) ) { sprintf(devsw, "hd(%d,%d)", BIOS_DEV_UNIT(newBVR), newBVR->part_no); if (strstr(val, devsw) != NULL) - newBVR->visible = FALSE; + newBVR->visible = false; } /* @@ -1678,19 +1679,46 @@ //========================================================================== -void getBootVolumeDescription( BVRef bvr, char * str, long strMaxLen, BOOL verbose ) +/* If Rename Partition has defined an alias, then extract it for description purpose */ +static const char * getVolumeLabelAlias( BVRef bvr, const char * str, long strMaxLen) { + const int MAX_ALIAS_SIZE=31; + static char szAlias[MAX_ALIAS_SIZE+1]; + char *q=szAlias; + const char * szAliases = getStringForKey(kRenamePartition, &bootInfo->bootConfig); + + if (!str || !*str || !szAliases) return 0; // no renaming wanted + + const char * p = strstr(szAliases, str); + if(!p || !(*p)) return 0; // this volume must not be renamed, or option is malformed + + p+= strlen(str); // skip the "hd(n,m) " field + // multiple aliases can be found separated by a semi-column + while(*p && *p != ';' && q<(szAlias+MAX_ALIAS_SIZE)) *q++=*p++; + *q='\0'; + + return szAlias; +} + +void getBootVolumeDescription( BVRef bvr, char * str, long strMaxLen, bool verbose ) +{ unsigned char type = (unsigned char) bvr->part_type; char *p; p = str; - if (verbose) - { - sprintf( str, "hd(%d,%d) ", - BIOS_DEV_UNIT(bvr), bvr->part_no); + if (verbose) { + sprintf( str, "hd(%d,%d) ", BIOS_DEV_UNIT(bvr), bvr->part_no); for (; strMaxLen > 0 && *p != '\0'; p++, strMaxLen--); } + // See if we should get the renamed alias name for this partion: + const char * szAliasName = getVolumeLabelAlias(bvr, str, strMaxLen); + if (szAliasName && *szAliasName) + { + strncpy(bvr->label, szAliasName, strMaxLen); + return; // we're done here no need to seek for real name + } + // // Get the volume label using filesystem specific functions // or use the alternate volume label if available. @@ -1715,12 +1743,13 @@ } } + /* See if a partion rename is wanted: */ + // Set the devices label sprintf(bvr->label, p); } //========================================================================== - int readBootSector( int biosdev, unsigned int secno, void * buffer ) { struct disk_blk0 * bootSector = (struct disk_blk0 *) buffer; @@ -1815,7 +1844,7 @@ } secno += bvr->part_boff; - cache_valid = FALSE; + cache_valid = false; while (len > 0) { secs = len / BPS; @@ -1854,7 +1883,7 @@ } secno += bvr->part_boff; - cache_valid = FALSE; + cache_valid = false; while (len > 0) { secs = len / BPS; Index: trunk/i386/libsaio/pci_setup.c =================================================================== --- trunk/i386/libsaio/pci_setup.c (revision 22) +++ trunk/i386/libsaio/pci_setup.c (revision 23) @@ -1,10 +1,11 @@ #include "libsaio.h" +#include "boot.h" #include "bootstruct.h" #include "pci.h" +#include "nvidia.h" +#include "ati.h" extern void set_eth_builtin(pci_dt_t *eth_dev); -extern bool setup_nvidia_devprop(pci_dt_t *nvda_dev); -extern bool setup_ati_devprop(pci_dt_t *ati_dev); extern int ehci_acquire(pci_dt_t *pci_dev); extern int uhci_reset(pci_dt_t *pci_dev); extern void force_enable_hpet(pci_dt_t *lpc_dev); @@ -12,21 +13,20 @@ void setup_pci_devs(pci_dt_t *pci_dt) { char *devicepath; - BOOL do_eth_devprop, do_gfx_devprop, fix_ehci, fix_uhci, fix_usb, do_enable_hpet; + bool do_eth_devprop, do_gfx_devprop, fix_ehci, fix_uhci, fix_usb, do_enable_hpet; pci_dt_t *current = pci_dt; do_eth_devprop = do_gfx_devprop = fix_ehci = fix_uhci = fix_usb = do_enable_hpet = false; - getBoolForKey("EthernetBuiltIn", &do_eth_devprop, &bootInfo->bootConfig); - getBoolForKey("GraphicsEnabler", &do_gfx_devprop, &bootInfo->bootConfig); - if (getBoolForKey("USBBusFix", &fix_usb, &bootInfo->bootConfig) && fix_usb) + getBoolForKey(kEthernetBuiltIn, &do_eth_devprop, &bootInfo->bootConfig); + getBoolForKey(kGraphicsEnabler, &do_gfx_devprop, &bootInfo->bootConfig); + if (getBoolForKey(kUSBBusFix, &fix_usb, &bootInfo->bootConfig) && fix_usb) { fix_ehci = fix_uhci = true; - else - { - getBoolForKey("EHCIacquire", &fix_ehci, &bootInfo->bootConfig); - getBoolForKey("UHCIreset", &fix_uhci, &bootInfo->bootConfig); + } else { + getBoolForKey(kEHCIacquire, &fix_ehci, &bootInfo->bootConfig); + getBoolForKey(kUHCIreset, &fix_uhci, &bootInfo->bootConfig); } - getBoolForKey("ForceHPET", &do_enable_hpet, &bootInfo->bootConfig); + getBoolForKey(kForceHPET, &do_enable_hpet, &bootInfo->bootConfig); while (current) { Index: trunk/i386/libsaio/cpu.h =================================================================== --- trunk/i386/libsaio/cpu.h (revision 0) +++ trunk/i386/libsaio/cpu.h (revision 23) @@ -0,0 +1,32 @@ +/* + * Copyright 2008 Islam Ahmed Zaid. All rights reserved. + * AsereBLN: 2009: cleanup and bugfix + */ + +#ifndef __LIBSAIO_CPU_H +#define __LIBSAIO_CPU_H + +#include "libsaio.h" + +extern void scan_cpu(PlatformInfo_t *); + +#define bit(n) (1UL << (n)) +#define bitmask(h,l) ((bit(h)|(bit(h)-1)) & ~(bit(l)-1)) +#define bitfield(x,h,l) (((x) & bitmask(h,l)) >> l) + +#define IA32_PERF_STATUS 0x198 +#define MSR_FLEX_RATIO 0x194 +#define MSR_PLATFORM_INFO 0xCE +#define K8_FIDVID_STATUS 0xC0010042 +#define K10_COFVID_STATUS 0xC0010071 + +#define DEFAULT_FSB 100000 /* for now, hardcoding 100MHz for old CPUs */ + +// DFE: This constant comes from older xnu: +#define CLKNUM 1193182 /* formerly 1193167 */ + +// DFE: These two constants come from Linux except CLOCK_TICK_RATE replaced with CLKNUM +#define CALIBRATE_TIME_MSEC 30 /* 30 msecs */ +#define CALIBRATE_LATCH ((CLKNUM * CALIBRATE_TIME_MSEC + 1000/2)/1000) + +#endif /* !__LIBSAIO_CPU_H */ Index: trunk/i386/libsaio/pci.c =================================================================== --- trunk/i386/libsaio/pci.c (revision 22) +++ trunk/i386/libsaio/pci.c (revision 23) @@ -8,156 +8,148 @@ #include "bootstruct.h" #include "pci.h" -uint32_t pci_config_read(uint32_t pci_addr, uint8_t reg, uint8_t bytes) +#ifndef DEBUG_PCI +#define DEBUG_PCI 0 +#endif + +#if DEBUG_PCI +#define DBG(x...) printf(x) +#else +#define DBG(x...) +#endif + +pci_dt_t *root_pci_dev; + + +uint8_t pci_config_read8(uint32_t pci_addr, uint8_t reg) { - uint32_t data = -1; + pci_addr |= reg & ~3; + outl(PCI_ADDR_REG, pci_addr); + return inb(PCI_DATA_REG + (reg & 3)); +} +uint16_t pci_config_read16(uint32_t pci_addr, uint8_t reg) +{ pci_addr |= reg & ~3; outl(PCI_ADDR_REG, pci_addr); + return inw(PCI_DATA_REG + (reg & 2)); +} - switch (bytes) - { - case 1: - data = inb(PCI_DATA_REG + (reg & 3)); - break; - case 2: - data = inw(PCI_DATA_REG + (reg & 2)); - break; - case 4: - data = inl(PCI_DATA_REG); - break; - } +uint32_t pci_config_read32(uint32_t pci_addr, uint8_t reg) +{ + pci_addr |= reg & ~3; + outl(PCI_ADDR_REG, pci_addr); + return inl(PCI_DATA_REG); +} - return data; +void pci_config_write8(uint32_t pci_addr, uint8_t reg, uint8_t data) +{ + pci_addr |= reg & ~3; + outl(PCI_ADDR_REG, pci_addr); + outb(PCI_DATA_REG + (reg & 3), data); } -void pci_config_write(uint32_t pci_addr, uint8_t reg, uint32_t data, uint8_t bytes) +void pci_config_write16(uint32_t pci_addr, uint8_t reg, uint16_t data) { pci_addr |= reg & ~3; outl(PCI_ADDR_REG, pci_addr); + outw(PCI_DATA_REG + (reg & 2), data); +} - switch (bytes) - { - case 1: - outb(PCI_DATA_REG + (reg & 3), data); - break; - case 2: - outw(PCI_DATA_REG + (reg & 2), data); - break; - case 4: - outl(PCI_DATA_REG, data); - break; - } +void pci_config_write32(uint32_t pci_addr, uint8_t reg, uint32_t data) +{ + pci_addr |= reg & ~3; + outl(PCI_ADDR_REG, pci_addr); + outl(PCI_DATA_REG, data); } -pci_dt_t *root_pci_dev; - void scan_pci_bus(pci_dt_t *start, uint8_t bus) { - uint8_t dev, func, secondary_bus, header_type; - uint32_t id, pci_addr; - pci_dt_t *new; - pci_dt_t **current = &start->children; - - for (dev = 0; dev < 32; dev++) - for (func = 0; func < 8; func++) - { + pci_dt_t *new; + pci_dt_t **current = &start->children; + uint32_t id; + uint32_t pci_addr; + uint8_t dev; + uint8_t func; + uint8_t secondary_bus; + uint8_t header_type; + + for (dev = 0; dev < 32; dev++) { + for (func = 0; func < 8; func++) { pci_addr = PCIADDR(bus, dev, func); id = pci_config_read32(pci_addr, PCI_VENDOR_ID); - if (!id || id == 0xffffffff) + if (!id || id == 0xffffffff) { continue; - + } new = (pci_dt_t*)malloc(sizeof(pci_dt_t)); - if (!new) - return; - memset(new, 0, sizeof(pci_dt_t)); - + bzero(new, sizeof(pci_dt_t)); new->dev.addr = pci_addr; new->vendor_id = id & 0xffff; new->device_id = (id >> 16) & 0xffff; new->class_id = pci_config_read16(pci_addr, PCI_CLASS_DEVICE); - new->parent = start; + new->parent = start; header_type = pci_config_read8(pci_addr, PCI_HEADER_TYPE); - switch (header_type & 0x7f) - { - case PCI_HEADER_TYPE_BRIDGE: - case PCI_HEADER_TYPE_CARDBUS: - secondary_bus = pci_config_read8(pci_addr, PCI_SECONDARY_BUS); - if (secondary_bus != 0) - scan_pci_bus(new, secondary_bus); - break; + switch (header_type & 0x7f) { + case PCI_HEADER_TYPE_BRIDGE: + case PCI_HEADER_TYPE_CARDBUS: + secondary_bus = pci_config_read8(pci_addr, PCI_SECONDARY_BUS); + if (secondary_bus != 0) { + scan_pci_bus(new, secondary_bus); + } + break; } - *current = new; current = &new->next; - if ((func == 0) && ((header_type & 0x80) == 0)) + if ((func == 0) && ((header_type & 0x80) == 0)) { break; + } } + } } -void enable_pci_devs(void) -{ - uint16_t id; - uint32_t rcba, *fd; - - id = pci_config_read16(PCIADDR(0, 0x00, 0), 0x00); - /* make sure we're on Intel chipset */ - if (id != 0x8086) - return; - rcba = pci_config_read32(PCIADDR(0, 0x1f, 0), 0xf0) & ~1; - fd = (uint32_t *)(rcba + 0x3418); - /* set SMBus Disable (SD) to 0 */ - *fd &= ~0x8; - /* and all devices? */ - //*fd = 0x1; -} - void build_pci_dt(void) { root_pci_dev = malloc(sizeof(pci_dt_t)); - - if (!root_pci_dev) - return; - bzero(root_pci_dev, sizeof(pci_dt_t)); - enable_pci_devs(); scan_pci_bus(root_pci_dev, 0); +#if DEBUG_PCI + dump_pci_dt(root_pci_dev->children); + printf("(Press a key to continue...)\n"); + getc(); +#endif } -char dev_path[80]; - +static char dev_path[256]; char *get_pci_dev_path(pci_dt_t *pci_dt) { - pci_dt_t *current, *end; - char tmp[30]; + pci_dt_t *current; + pci_dt_t *end; + char tmp[64]; dev_path[0] = 0; end = root_pci_dev; - - while (end != pci_dt) - { + while (end != pci_dt) { current = pci_dt; - while (current->parent != end) - current = current->parent; + while (current->parent != end) { + current = current->parent; + } end = current; - sprintf(tmp, "%s/Pci(0x%x,0x%x)", (current->parent == root_pci_dev) ? "PciRoot(0x0)" : "", current->dev.bits.dev, current->dev.bits.func); strcat(dev_path, tmp); } - return dev_path; } void dump_pci_dt(pci_dt_t *pci_dt) { - pci_dt_t *current = pci_dt; + pci_dt_t *current; - while (current) - { + current = pci_dt; + while (current) { printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n", current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func, current->class_id, current->vendor_id, current->device_id, @@ -166,38 +158,3 @@ current = current->next; } } - - -void lspci(const char *booterParam) -{ - if(bootArgs->Video.v_display == VGA_TEXT_MODE) - { - setActiveDisplayPage(1); - clearScreenRows(0, 24); - setCursorPosition(0, 0, 1); - } - - dump_pci_dt(root_pci_dev->children); - - printf("(Press a key to continue...)"); - getc(); - - if(bootArgs->Video.v_display == VGA_TEXT_MODE) - setActiveDisplayPage(0); -} - -int check_vga_nvidia(pci_dt_t *pci_dt) -{ - pci_dt_t *current = pci_dt; - while (current) - { - if(current->vendor_id == PCI_CLASS_DISPLAY_VGA) - if(current->class_id == PCI_VENDOR_ID_NVIDIA) - return 1; - - check_vga_nvidia(current->children); - current = current->next; - } - return 0; -} - Index: trunk/i386/libsaio/stringTable.c =================================================================== --- trunk/i386/libsaio/stringTable.c (revision 22) +++ trunk/i386/libsaio/stringTable.c (revision 23) @@ -33,15 +33,8 @@ extern char *Language; extern char *LoadableFamilies; -int sysConfigValid; +bool sysConfigValid; -//static void eatThru(char val, const char **table_p); - -static inline int isspace(char c) -{ - return (c == ' ' || c == '\t'); -} - /* * Compare a string to a key with quoted characters */ @@ -81,14 +74,14 @@ static void eatThru(char val, const char **table_p) { register const char *table = *table_p; - register BOOL found = NO; + register bool found = false; while (*table && !found) { if (*table == '\\') table += 2; else { - if (*table == val) found = YES; + if (*table == val) found = true; table++; } } @@ -97,7 +90,7 @@ /* Remove key and its associated value from the table. */ -BOOL +bool removeKeyFromTable(const char *key, char *table) { register int len; @@ -132,13 +125,13 @@ out: free(buf); - if(len == -1) return NO; + if(len == -1) return false; while((*tab = *(tab + len))) { tab++; } - return YES; + return true; } char * @@ -198,7 +191,7 @@ } -BOOL getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size) +bool getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size) { if (config->dictionary != 0 ) { // Look up key in XML dictionary @@ -208,11 +201,11 @@ if (value->type != kTagTypeString) { error("Non-string tag '%s' found in config file\n", key); - return NO; + return false; } *val = value->string; *size = strlen(value->string); - return YES; + return true; } } else { @@ -220,7 +213,7 @@ } - return NO; + return false; } #if UNUSED @@ -308,11 +301,11 @@ return line; } -BOOL getValueForBootKey(const char *line, const char *match, const char **matchval, int *len) +bool getValueForBootKey(const char *line, const char *match, const char **matchval, int *len) { const char *key, *value; int key_len, value_len; - BOOL retval = NO; + bool retval = false; while (*line) { /* look for keyword or argument */ @@ -331,38 +324,48 @@ && strncmp(match, key, key_len) == 0) { *matchval = value; *len = value_len; - retval = YES; + retval = true; /* Continue to look for this key; last one wins. */ } } return retval; } +/* Return NULL if no option has been successfully retrieved, or the string otherwise */ +const char * getStringForKey(const char * key, config_file_t *config) +{ + static const char* value =0; + int len=0; + if(!getValueForKey(key, &value, &len, config)) value = 0; + return value; +} + + /* Returns TRUE if a value was found, FALSE otherwise. * The boolean value of the key is stored in 'val'. */ -BOOL getBoolForKey( const char *key, BOOL *result_val, config_file_t *config ) +bool getBoolForKey( const char *key, bool *result_val, config_file_t *config ) { const char *key_val; int size; if (getValueForKey(key, &key_val, &size, config)) { if ( (size >= 1) && (key_val[0] == 'Y' || key_val[0] == 'y') ) { - *result_val = YES; + *result_val = true; } else { - *result_val = NO; + *result_val = false; } - return YES; + return true; } - return NO; + return false; } -BOOL getIntForKey( const char *key, int *value, config_file_t *config ) +bool getIntForKey( const char *key, int *value, config_file_t *config ) { const char *val; int size, sum; - BOOL negative = NO; + bool negative = false; if (getValueForKey(key, &val, &size, config)) { @@ -370,7 +373,7 @@ { if (*val == '-') { - negative = YES; + negative = true; val++; size--; } @@ -378,7 +381,7 @@ for (sum = 0; size > 0; size--) { if (*val < '0' || *val > '9') - return NO; + return false; sum = (sum * 10) + (*val++ - '0'); } @@ -387,25 +390,25 @@ sum = -sum; *value = sum; - return YES; + return true; } } - return NO; + return false; } /* * */ -BOOL getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size ) +bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size ) { const char *val; int size = 0; int sum = 0; - BOOL negative = NO; - BOOL percentage = NO; + bool negative = false; + bool percentage = false; if (getValueForKey(key, &val, &size, config)) { @@ -413,14 +416,14 @@ { if (*val == '-') { - negative = YES; + negative = true; val++; size--; } if (val[size-1] == '%') { - percentage = YES; + percentage = true; size--; } @@ -428,7 +431,7 @@ for (sum = 0; size > 0; size--) { if (*val < '0' || *val > '9') - return NO; + return false; sum = (sum * 10) + (*val++ - '0'); } @@ -448,18 +451,18 @@ } *value = (uint16_t) sum; - return YES; + return true; } // key not found - return NO; + return false; } /* * get color value from plist format #RRGGBB */ -BOOL getColorForKey( const char *key, unsigned int *value, config_file_t *config ) +bool getColorForKey( const char *key, unsigned int *value, config_file_t *config ) { const char *val; int size; @@ -470,20 +473,20 @@ { val++; *value = strtol(val, NULL, 16); - return YES; + return true; } } - return NO; + return false; } -BOOL getValueForKey( const char *key, const char **val, int *size, config_file_t *config ) +bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config ) { const char *overrideVal; int overrideSize; - BOOL override, ret; + bool override, ret; if (getValueForBootKey(bootArgs->CommandLine, key, val, size)) - return YES; + return true; ret = getValueForConfigTableKey(config, key, val, size); @@ -495,19 +498,19 @@ { if (getValueForConfigTableKey(&bootInfo->overrideConfig, key, &overrideVal, &overrideSize)) { - override = YES; + override = true; if (ret && (strcmp(key, "Kernel") == 0) && (strcmp(overrideVal, "mach_kernel") == 0)) - override = NO; + override = false; if (ret && (strcmp(key, "Kernel Flags") == 0) && (overrideSize == 0)) - override = NO; + override = false; if (override) { *val = overrideVal; *size = overrideSize; - return YES; + return true; } } } @@ -543,7 +546,7 @@ // (and does not modify dict pointer). // Prints an error message if there is a parsing error. // -long ParseXMLFile( char * buffer, TagPtr * dict ) +int ParseXMLFile( char * buffer, TagPtr * dict ) { long length, pos; TagPtr tag; @@ -582,17 +585,9 @@ int loadConfigFile (const char *configFile, config_file_t *config) { int fd, count; - char dirspec[512]; - sprintf(dirspec,"%s",configFile); - fd = open(dirspec, 0); - if (fd<0) - { - dirspec[0] = '\0'; - sprintf(dirspec,"bt(0,0)%s",configFile); - fd = open(dirspec, 0); - if (fd<0) - return -1; + if ((fd = open_bvdev("bt(0,0)", configFile, 0)) < 0) { + return -1; } // read file count = read(fd, config->plist, IO_CONFIG_DATA_SIZE); @@ -632,11 +627,11 @@ // build xml dictionary ParseXMLFile(config->plist, &config->dictionary); - sysConfigValid=1; + sysConfigValid = true; ret=0; // enable canOverride flag - config->canOverride = TRUE; + config->canOverride = true; break; } @@ -672,7 +667,7 @@ // build xml dictionary ParseXMLFile(config->plist, &config->dictionary); - sysConfigValid=1; + sysConfigValid = true; ret=0; break; } @@ -705,7 +700,7 @@ // build xml dictionary ParseXMLFile(config->plist, &config->dictionary); - sysConfigValid=1; + sysConfigValid = true; ret=0; break; } @@ -729,7 +724,7 @@ char * ptr = *argPtr; const char * strStart; int len = 0; - BOOL isQuoted = FALSE; + bool isQuoted = false; *val = '\0'; @@ -744,7 +739,7 @@ // Skip the leading double quote character. if (*ptr == '\"') { - isQuoted = TRUE; + isQuoted = true; ptr++; strStart++; } Index: trunk/i386/libsaio/pci.h =================================================================== --- trunk/i386/libsaio/pci.h (revision 22) +++ trunk/i386/libsaio/pci.h (revision 23) @@ -34,51 +34,21 @@ struct pci_dt_t *next; } pci_dt_t; -#define PCIADDR(bus, dev, func) (1 << 31) | (bus << 16) | (dev << 11) | (func << 8) +#define PCIADDR(bus, dev, func) (1 << 31) | (bus << 16) | (dev << 11) | (func << 8) +#define PCI_ADDR_REG 0xcf8 +#define PCI_DATA_REG 0xcfc -#define PCI_ADDR_REG 0xcf8 -#define PCI_DATA_REG 0xcfc +extern pci_dt_t *root_pci_dev; +extern uint8_t pci_config_read8(uint32_t, uint8_t); +extern uint16_t pci_config_read16(uint32_t, uint8_t); +extern uint32_t pci_config_read32(uint32_t, uint8_t); +extern void pci_config_write8(uint32_t, uint8_t, uint8_t); +extern void pci_config_write16(uint32_t, uint8_t, uint16_t); +extern void pci_config_write32(uint32_t, uint8_t, uint32_t); +extern char *get_pci_dev_path(pci_dt_t *); +extern void build_pci_dt(void); +extern void dump_pci_dt(pci_dt_t *); -uint32_t pci_config_read(uint32_t pci_addr, uint8_t reg, uint8_t bytes); -void pci_config_write(uint32_t pci_addr, uint8_t reg, uint32_t data, uint8_t bytes); - -static inline uint8_t pci_config_read8(uint32_t pci_addr, uint8_t reg) -{ - return (uint8_t)pci_config_read(pci_addr, reg, 1); -} - -static inline uint16_t pci_config_read16(uint32_t pci_addr, uint8_t reg) -{ - return (uint16_t)pci_config_read(pci_addr, reg, 2); -} - -static inline uint32_t pci_config_read32(uint32_t pci_addr, uint8_t reg) -{ - return (uint32_t)pci_config_read(pci_addr, reg, 4); -} - - -static inline void pci_config_write8(uint32_t pci_addr, uint8_t reg, uint8_t data) -{ - pci_config_write(pci_addr, reg, data, 1); -} - -static inline void pci_config_write16(uint32_t pci_addr, uint8_t reg, uint16_t data) -{ - pci_config_write(pci_addr, reg, data, 2); -} - -static inline void pci_config_write32(uint32_t pci_addr, uint8_t reg, uint32_t data) -{ - pci_config_write(pci_addr, reg, data, 4); -} - -extern pci_dt_t *root_pci_dev; - -char *get_pci_dev_path(pci_dt_t *pci_dt); -void build_pci_dt(void); -int check_vga_nvidia(pci_dt_t *pci_dt); - //----------------------------------------------------------------------------- // added by iNDi @@ -826,7 +796,7 @@ #define PCI_CLASS_BRIDGE_HOST 0x0600 #define PCI_CLASS_BRIDGE_ISA 0x0601 #define PCI_CLASS_BRIDGE_EISA 0x0602 -#define PCI_CLASS_BRIDGE_MC 0x0603 +#define PCI_CLASS_BRIDGE_MC 0x0603 #define PCI_CLASS_BRIDGE_PCI 0x0604 #define PCI_CLASS_BRIDGE_PCMCIA 0x0605 #define PCI_CLASS_BRIDGE_NUBUS 0x0606 Index: trunk/i386/libsaio/biosfn.c =================================================================== --- trunk/i386/libsaio/biosfn.c (revision 22) +++ trunk/i386/libsaio/biosfn.c (revision 23) @@ -99,6 +99,65 @@ return time.i; } +#if 0 +static unsigned long rerangeMemoryMap(unsigned long count) +{ + int i, still_changing, newcount = count; + + MemoryRange * range = (MemoryRange *)BIOS_ADDR; + struct MemoryRange change_tmp; + + /* sort map list by memory addresses (low -> high) */ + still_changing = 1; + while (still_changing) { + still_changing = 0; + for (i=1; i > , swap */ + if (range[i].base < range[i-1].base) { + change_tmp.base = range[i].base; + change_tmp.length = range[i].length; + change_tmp.type = range[i].type; + + range[i].base = range[i-1].base; + range[i].length = range[i-1].length; + range[i].type = range[i-1].type; + + range[i-1].base = change_tmp.base; + range[i-1].length = change_tmp.length; + range[i-1].type = change_tmp.type; + + still_changing=1; + } + } + } + + /* clear overlaps */ + /* linux's arch/i386/kern/setup.c may have better algorithm */ + for (i=1; i range[i].base ) { + range[newcount].base = range[i].base + range[i].length; + range[newcount].length = range[i-1].base + range[i-1].length - range[newcount].base; + range[newcount].type = range[i-1].type; + newcount++; + + range[i-1].length = range[i].base - range[i-1].base; + } + } + + /* + * 0xb0000000 : 0x10000000 NG + * 0xc0000400 NG + * 0xf2000000 NG + */ + range[newcount].base = 0xb0000000; + range[newcount].length = 0x0f000000; + range[newcount].type = kMemoryRangeUsable; + newcount++; + + return newcount; +} +#endif + unsigned long getMemoryMap( MemoryRange * rangeArray, unsigned long maxRangeCount, unsigned long * conMemSizePtr, @@ -107,10 +166,11 @@ #define kMemoryMapSignature 'SMAP' #define kDescriptorSizeMin 20 - MemoryRange * range = (MemoryRange *)BIOS_ADDR; - unsigned long count = 0; - unsigned long long conMemSize = 0; - unsigned long long extMemSize = 0; + MemoryRange * range = (MemoryRange *)BIOS_ADDR; + unsigned long count = 0; + unsigned long rerangedCount; + unsigned long long conMemSize = 0; + unsigned long long extMemSize = 0; // Prepare for the INT15 E820h call. Each call returns a single // memory range. A continuation value is returned that must be @@ -179,6 +239,11 @@ *conMemSizePtr = conMemSize / 1024; // size in KB *extMemSizePtr = extMemSize / 1024; // size in KB +#if 0 + rerangedCount = rerangeMemoryMap(count); + range += rerangedCount - count; +#endif + // Copy out data bcopy((char *)BIOS_ADDR, rangeArray, ((char *)range - (char *)BIOS_ADDR)); @@ -770,19 +835,16 @@ #endif /* APM_SUPPORT */ #ifdef EISA_SUPPORT -BOOL -eisa_present( - void -) +bool eisa_present(void) { - static BOOL checked; - static BOOL isEISA; + static bool checked = false; + static bool isEISA; if (!checked) { if (strncmp((char *)0xfffd9, "EISA", 4) == 0) - isEISA = TRUE; + isEISA = true; - checked = TRUE; + checked = true; } return (isEISA); Index: trunk/i386/libsaio/saio_types.h =================================================================== --- trunk/i386/libsaio/saio_types.h (revision 22) +++ trunk/i386/libsaio/saio_types.h (revision 23) @@ -38,10 +38,6 @@ #define DEBUG_DISK(x) #endif -typedef char BOOL; -#define NO 0 -#define YES 1 - typedef unsigned long entry_t; typedef struct { @@ -68,7 +64,7 @@ typedef struct { char plist[4096]; // buffer for plist TagPtr dictionary; // buffer for xml dictionary - BOOL canOverride; // flag to mark a dictionary can be overriden + bool canOverride; // flag to mark a dictionary can be overriden } config_file_t; /* @@ -190,8 +186,8 @@ uint32_t modTime; char label[BVSTRLEN]; /* partition volume label */ char altlabel[BVSTRLEN]; /* partition volume label */ - BOOL filtered; /* newFilteredBVChain() will set to TRUE */ - BOOL visible; /* will shown in the device list */ + bool filtered; /* newFilteredBVChain() will set to TRUE */ + bool visible; /* will shown in the device list */ }; enum { Index: trunk/i386/libsaio/msdos.c =================================================================== --- trunk/i386/libsaio/msdos.c (revision 22) +++ trunk/i386/libsaio/msdos.c (revision 23) @@ -100,8 +100,7 @@ free(ih); } -int -MSDOSProbe(const void * buffer) +int MSDOSProbe(const void * buffer) { union bootsector *bsp; struct bpb33 *b33; @@ -118,12 +117,12 @@ /* We only work with 512, 1024, and 2048 byte sectors */ bps = OSSwapLittleToHostInt16(b33->bpbBytesPerSec); if ((bps < 0x200) || (bps & (bps - 1)) || (bps > 0x800)) - return FALSE; + return 0; /* Check to make sure valid sectors per cluster */ spc = b33->bpbSecPerClust; if ((spc == 0 ) || (spc & (spc - 1))) - return FALSE; + return 0; if (OSSwapLittleToHostInt16(b50->bpbRootDirEnts) == 0) { /* It's FAT32 */ if (!memcmp(((struct extboot *)bsp->bs710.bsExt)->exFileSysType, "FAT32 ", 8)) @@ -136,7 +135,7 @@ return 12; } - return FALSE; + return 0; } Index: trunk/i386/libsaio/fake_efi.c =================================================================== --- trunk/i386/libsaio/fake_efi.c (revision 22) +++ trunk/i386/libsaio/fake_efi.c (revision 23) @@ -1,3 +1,4 @@ + /* * Copyright 2007 David F. Elliott. All rights reserved. */ @@ -3,10 +4,11 @@ #include "libsaio.h" -#include "bootstruct.h" /* for bootArgs */ +#include "boot.h" +#include "bootstruct.h" #include "efi.h" #include "acpi.h" #include "fake_efi.h" #include "efi_tables.h" -#include "freq_detect.h" +#include "platform.h" #include "dsdt_patcher.h" #include "smbios_patcher.h" @@ -79,7 +81,7 @@ static EFI_UINT32 const FIRMWARE_REVISION = 132; /* FIXME: Find a constant for this. */ /* Default platform system_id (fix by IntVar) */ -static EFI_CHAR8 const SYSTEM_ID[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10};//random value gen by uuidgen +static EFI_CHAR8 const SYSTEM_ID[] = "0123456789ABCDEF";//random value gen by uuidgen /* Just a ret instruction */ static uint8_t const VOIDRET_INSTRUCTIONS[] = {0xc3}; @@ -273,9 +275,9 @@ */ /* These should be const but DT__AddProperty takes char* */ -static char TSC_Frequency_prop[] = "TSCFrequency"; -static char FSB_Frequency_prop[] = "FSBFrequency"; -static char CPU_Frequency_prop[] = "CPUFrequency"; +static const char const TSC_Frequency_prop[] = "TSCFrequency"; +static const char const FSB_Frequency_prop[] = "FSBFrequency"; +static const char const CPU_Frequency_prop[] = "CPUFrequency"; /*========================================================================== * SMBIOS @@ -316,24 +318,187 @@ */ /* These should be const but DT__AddProperty takes char* */ -static char FIRMWARE_REVISION_PROP[] = "firmware-revision"; -static char FIRMWARE_ABI_PROP[] = "firmware-abi"; -static char FIRMWARE_VENDOR_PROP[] = "firmware-vendor"; -static char FIRMWARE_ABI_PROP_VALUE[] = "EFI64"; -static char SYSTEM_ID_PROP[] = "system-id"; +static const char const FIRMWARE_REVISION_PROP[] = "firmware-revision"; +static const char const FIRMWARE_ABI_PROP[] = "firmware-abi"; +static const char const FIRMWARE_VENDOR_PROP[] = "firmware-vendor"; +static const char const FIRMWARE_ABI_PROP_VALUE[] = "EFI64"; +static const char const SYSTEM_ID_PROP[] = "system-id"; +static const char const SYSTEM_SERIAL_PROP[] = "SystemSerialNumber"; +static const char const SYSTEM_TYPE_PROP[] = "system-type"; +static const char const MODEL_PROP[] = "Model"; -void -setupEfiDeviceTree(void) +#define UUID_LEN 16 + +/* Get an smbios option string option to convert to EFI_CHAR16 string */ +static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len) { + const char * src= getStringForKey(key, &bootInfo->smbiosConfig); + EFI_CHAR16* dst = 0; + size_t i=0; + + if (!key || !(*key) || !len || !src) return 0; + + *len = strlen(src); + dst = (EFI_CHAR16*) malloc(((*len)+1)*2); + for (; i<*len; i++) dst[i] = src[i]; + dst[*len] = '\0'; + + return dst; +} + +#define DEBUG_SMBIOS 0 + +/* Get the SystemID from the bios dmi info */ +static EFI_CHAR8* getSmbiosUUID() +{ + struct SMBEntryPoint *smbios; + struct DMIHeader *dmihdr; + SMBByte *p; + int i, found, isZero, isOnes; + static EFI_CHAR8 uuid[UUID_LEN+1]=""; + + smbios = getAddressOfSmbiosTable(); /* checks for _SM_ anchor and table header checksum */ + if (memcmp( &smbios->dmi.anchor[0], "_DMI_", 5) != 0) { + return 0; + } +#if DEBUG_SMBIOS + verbose(">>> SMBIOSAddr=0x%08x\n", smbios); + verbose(">>> DMI: addr=0x%08x, len=0x%d, count=%d\n", smbios->dmi.tableAddress, + smbios->dmi.tableLength, smbios->dmi.structureCount); +#endif + i = 0; + found = 0; + p = (SMBByte *) smbios->dmi.tableAddress; + while (i < smbios->dmi.structureCount && p + 4 <= (SMBByte *)smbios->dmi.tableAddress + smbios->dmi.tableLength) { + dmihdr = (struct DMIHeader *) p; +#if DEBUG_SMBIOS + verbose(">>>>>> DMI(%d): type=0x%02x, len=0x%d\n",i,dmihdr->type,dmihdr->length); +#endif + if (dmihdr->length < 4 || dmihdr->type == 127 /* EOT */) break; + if (dmihdr->type == 1) /* 3.3.2 System Information */ + { + if (dmihdr->length >= 0x19) found = 1; + break; + } + p = p + dmihdr->length; + while ((p - (SMBByte *)smbios->dmi.tableAddress + 1 < smbios->dmi.tableLength) && (p[0] != 0x00 || p[1] != 0x00)) + { + p++; + } + p += 2; + i++; + } + + if (!found) return 0; + + verbose("Found SMBIOS System Information Table 1\n"); + p += 8; + + for (i=0, isZero=1, isOnes=1; i to valid UUID.\n", szUUID); + return (EFI_CHAR8*) 0; + } + return (EFI_CHAR8*) ret; // new allocated buffer containing the converted string to bin +} +*/ + +/* return a binary UUID value from the overriden SystemID and SMUUID if found, + * or from the bios if not, or from a fixed value if no bios value is found + */ +static EFI_CHAR8* getSystemID() +{ // unable to determine UUID for host. Error: 35 fix + const char * sysId = getStringForKey("SystemID", &bootInfo->bootConfig); + EFI_CHAR8* ret = getUUIDFromString(sysId); + if(!sysId || !ret) // try smbios.plist SMUUID override + ret=getUUIDFromString((sysId = getStringForKey("SMUUID",&bootInfo->smbiosConfig))); + if(!sysId || !ret) { // try bios dmi info UUID extraction + ret = getSmbiosUUID(); + sysId=0; + } + if(!ret) // no bios dmi UUID available, set a fixed value for system-id + ret=getUUIDFromString((sysId = (const char*) SYSTEM_ID)); + + verbose("Customizing SystemID with : %s\n", sysId ? sysId :"BIOS internal UUID"); + return ret; +} + +void setupEfiDeviceTree(void) +{ + EFI_CHAR16* ret16=0; + EFI_CHAR8* ret=0; + size_t len=0; Node *node; + EFI_CHAR8 SystemType=1; + const char *value; + node = DT__FindNode("/", false); - if (node == 0) { - stop("Couldn't get root node"); - } + + if (node == 0) stop("Couldn't get root node"); - /* We could also just do DT__FindNode("/efi/platform", true) - * But I think eventually we want to fill stuff in the efi node - * too so we might as well create it so we have a pointer for it too. + /* We could also just do DT__FindNode("/efi/platform", true) + * But I think eventually we want to fill stuff in the efi node + * too so we might as well create it so we have a pointer for it too. */ node = DT__AddChild(node, "efi"); @@ -348,7 +513,7 @@ Node *runtimeServicesNode = DT__AddChild(node, "runtime-services"); /* The value of the table property is the 32-bit physical address for the RuntimeServices table. - * Sice the EFI system table already has a pointer to it, we simply use the address of that pointer + * Since the EFI system table already has a pointer to it, we simply use the address of that pointer * for the pointer to the property data. Warning.. DT finalization calls free on that but we're not * the only thing to use a non-malloc'd pointer for something in the DT */ @@ -361,29 +526,57 @@ /* Now fill in the /efi/platform Node */ Node *efiPlatformNode = DT__AddChild(node, "platform"); - + /* NOTE WELL: If you do add FSB Frequency detection, make sure to store * the value in the fsbFrequency global and not an malloc'd pointer * because the DT_AddProperty function does not copy its args. */ - if(fsbFrequency != 0) - DT__AddProperty(efiPlatformNode, FSB_Frequency_prop, sizeof(uint64_t), &fsbFrequency); + if(Platform.CPU.FSBFrequency != 0) + DT__AddProperty(efiPlatformNode, FSB_Frequency_prop, sizeof(uint64_t), &Platform.CPU.FSBFrequency); + + /* Export TSC and CPU frequencies for use by the kernel or KEXTs */ + if(Platform.CPU.TSCFrequency != 0) + DT__AddProperty(efiPlatformNode, TSC_Frequency_prop, sizeof(uint64_t), &Platform.CPU.TSCFrequency); - // unable to determine UUID for host. Error: 35 fix - DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, sizeof(SYSTEM_ID), (EFI_UINT32*)&SYSTEM_ID); + if(Platform.CPU.CPUFrequency != 0) + DT__AddProperty(efiPlatformNode, CPU_Frequency_prop, sizeof(uint64_t), &Platform.CPU.CPUFrequency); - /* Export TSC and CPU frequencies for use by the kernel or KEXTs - */ - if(tscFrequency != 0) - DT__AddProperty(efiPlatformNode, TSC_Frequency_prop, sizeof(uint64_t), &tscFrequency); - if(cpuFrequency != 0) - DT__AddProperty(efiPlatformNode, CPU_Frequency_prop, sizeof(uint64_t), &cpuFrequency); + /* Export system-id. Can be disabled with system-id=No in com.apple.Boot.plist */ + if((ret=getSystemID())) + DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, (EFI_UINT32*) ret); + /* Export system-type. Allowed values are: 0x01 for desktop computer (default), 0x02 for portable computers */ + if ((value=getStringForKey("system-type", &bootInfo->bootConfig))) { + if (*value != '1' && *value != '2') + verbose("Error: system-type must be 1 (desktop) or 2 (portable). Defaulting to 1!\n"); + else + SystemType = (unsigned char) (*value-'0'); + } + DT__AddProperty(node, SYSTEM_TYPE_PROP, sizeof(EFI_CHAR8), &SystemType); + + /* Export SystemSerialNumber if present */ + if ((ret16=getSmbiosChar16("SMserial", &len))) + DT__AddProperty(efiPlatformNode, SYSTEM_SERIAL_PROP, len, ret16); + + /* Export Model if present */ + if ((ret16=getSmbiosChar16("SMproductname", &len))) + DT__AddProperty(efiPlatformNode, MODEL_PROP, len, ret16); + /* Fill /efi/device-properties node. */ setupDeviceProperties(node); } +/* Load the smbios.plist override config file if any */ +static void setupSmbiosConfigFile() +{ + const char * value = getStringForKey(kSMBIOS, &bootInfo->bootConfig); + if (!value) value = "/Extra/smbios.plist"; + if (loadConfigFile(value, &bootInfo->smbiosConfig) == -1) { + verbose("No SMBIOS replacement found\n"); + } +} + /* Installs all the needed configuration table entries */ void setupEfiConfigurationTable() { @@ -405,15 +598,19 @@ /* Entrypoint from boot.c */ void setupFakeEfi(void) { - // Generate efi device strings + // load smbios.plist file if any + setupSmbiosConfigFile(); + + // Generate efi device strings setupEfiDevices(); // Initialize the base table setupEfiTables(); - // Initialize the device tree - setupEfiDeviceTree(); + // Initialize the device tree + setupEfiDeviceTree(); - // Add configuration table entries to both the services table and the device tree - setupEfiConfigurationTable(); + // Add configuration table entries to both the services table and the device tree + setupEfiConfigurationTable(); } + Index: trunk/i386/libsaio/misc.c =================================================================== --- trunk/i386/libsaio/misc.c (revision 22) +++ trunk/i386/libsaio/misc.c (revision 23) @@ -108,61 +108,13 @@ flushKeyboardInputBuffer(); } -static inline void -do_cpuid(uint32_t selector, uint32_t *data) -{ - asm volatile ("cpuid" - : "=a" (data[0]), - "=b" (data[1]), - "=c" (data[2]), - "=d" (data[3]) - : "a"(selector)); -} - //========================================================================== -// Check to see that this is a supported hardware configuration. -// If this hardware is supported, return 0. -// If this hardware is not supported, return an error code. - -int -checkForSupportedHardware() -{ - uint32_t cpuid_result[4]; - - do_cpuid(1, cpuid_result); - if ((cpuid_result[3] & 0x04000000) == 0) { - // Missing SSE2 - return 2; - } - return 0; -} - -#ifndef BOOT1 - -cpu_type_t -detectCpuType () -{ - uint32_t cpuid_reg[4]; - do_cpuid(0, cpuid_reg); - if (!memcmp(cpuid_reg+1,"GenuntelineI",12)) - { - do_cpuid(0x80000001, cpuid_reg); - if (cpuid_reg[3]&(1<<29)) - return CPU_TYPE_X86_64; - } - - return CPU_TYPE_I386; -} - -//========================================================================== // Return the platform name for this hardware. // - +#ifndef BOOT1 void getPlatformName(char *nameBuf) { strcpy(nameBuf, "ACPI"); } - #endif - Index: trunk/i386/libsaio/saio_internal.h =================================================================== --- trunk/i386/libsaio/saio_internal.h (revision 22) +++ trunk/i386/libsaio/saio_internal.h (revision 23) @@ -39,7 +39,7 @@ /* biosfn.c */ #ifdef EISA_SUPPORT -extern BOOL eisa_present(void); +extern bool eisa_present(void); #endif extern int bgetc(void); extern int biosread(int dev, int cyl, int head, int sec, int num); @@ -86,8 +86,8 @@ long length, long cache); /* console.c */ -extern BOOL gVerboseMode; -extern BOOL gErrors; +extern bool gVerboseMode; +extern bool gErrors; extern void putchar(int ch); extern int getchar(void); extern int printf(const char *format, ...); @@ -123,7 +123,7 @@ u_int16_t *ucslen, u_int32_t bufsize, int byte_order ); /* load.c */ -extern char gHaveKernelCache; +extern bool gHaveKernelCache; extern long ThinFatFile(void **binary, unsigned long *length); extern long DecodeMachO(void *binary, entry_t *rentry, char **raddr, int *rsize); @@ -144,23 +144,24 @@ /* stringTable.c */ extern char * newStringFromList(char **list, int *size); extern int stringLength(const char *table, int compress); -extern BOOL getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size); -extern BOOL removeKeyFromTable(const char *key, char *table); +extern bool getValueForConfigTableKey(config_file_t *config, const char *key, const char **val, int *size); +extern bool removeKeyFromTable(const char *key, char *table); extern char * newStringForStringTableKey(config_file_t *config, char *key); extern char * newStringForKey(char *key, config_file_t *configBuff); -extern BOOL getValueForBootKey(const char *line, const char *match, const char **matchval, int *len); -extern BOOL getValueForKey(const char *key, const char **val, int *size, config_file_t *configBuff); -extern BOOL getBoolForKey(const char *key, BOOL *val, config_file_t *configBuff); -extern BOOL getIntForKey(const char *key, int *val, config_file_t *configBuff); -extern BOOL getColorForKey(const char *key, unsigned int *val, config_file_t *configBuff); -extern BOOL getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size ); +extern bool getValueForBootKey(const char *line, const char *match, const char **matchval, int *len); +extern bool getValueForKey(const char *key, const char **val, int *size, config_file_t *configBuff); +extern const char * getStringForKey(const char * key, config_file_t *config); +extern bool getBoolForKey(const char *key, bool *val, config_file_t *configBuff); +extern bool getIntForKey(const char *key, int *val, config_file_t *configBuff); +extern bool getColorForKey(const char *key, unsigned int *val, config_file_t *configBuff); +extern bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size ); extern int loadConfigFile(const char *configFile, config_file_t *configBuff); extern int loadSystemConfig(config_file_t *configBuff); extern int loadHelperConfig(config_file_t *configBuff); extern int loadOverrideConfig(config_file_t *configBuff); extern char * newString(const char *oldString); extern char * getNextArg(char ** ptr, char * val); -extern long ParseXMLFile( char * buffer, TagPtr * dict ); +extern int ParseXMLFile( char * buffer, TagPtr * dict ); /* sys.c */ extern BVRef getBootVolumeRef( const char * path, const char ** outPath ); @@ -177,6 +178,7 @@ extern long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr); extern int openmem(char *buf, int len); extern int open(const char *str, int how); +extern int open_bvdev(const char *bvd, const char *path, int flags); extern int close(int fdesc); extern int file_size(int fdesc); extern int read(int fdesc, char *buf, int count); @@ -193,7 +195,7 @@ extern void scanBootVolumes(int biosdev, int *count); extern void scanDisks(int biosdev, int *count); extern BVRef selectBootVolume(BVRef chain); -extern void getBootVolumeDescription(BVRef bvr, char *str, long strMaxLen, BOOL verbose); +extern void getBootVolumeDescription(BVRef bvr, char *str, long strMaxLen, bool verbose); extern void setRootVolume(BVRef volume); extern void setBootGlobals(BVRef chain); Index: trunk/i386/boot0/boot0.s =================================================================== --- trunk/i386/boot0/boot0.s (revision 22) +++ trunk/i386/boot0/boot0.s (revision 23) @@ -55,7 +55,7 @@ ; ; Set to 1 to enable verbose mode ; -VERBOSE EQU 1 +VERBOSE EQU 0 ; ; Various constants. Index: trunk/i386/boot2/ramdisk.h =================================================================== --- trunk/i386/boot2/ramdisk.h (revision 22) +++ trunk/i386/boot2/ramdisk.h (revision 23) @@ -18,11 +18,11 @@ // extern BVRef gRAMDiskVolume; -extern BOOL gRAMDiskBTAliased; +extern bool gRAMDiskBTAliased; -extern void setRAMDiskBTHook(BOOL mode); +extern void setRAMDiskBTHook(bool mode); extern int mountRAMDisk(const char * param); extern void processRAMDiskCommand(char ** argPtr, const char * cmd); extern int loadPrebootRAMDisk(); -#endif /* !__BOOT_RAMDISK_H */ \ No newline at end of file +#endif /* !__BOOT_RAMDISK_H */ Index: trunk/i386/boot2/picopng.c =================================================================== --- trunk/i386/boot2/picopng.c (revision 22) +++ trunk/i386/boot2/picopng.c (revision 23) @@ -290,7 +290,7 @@ return 0; } -int HuffmanTree_decode(const HuffmanTree *tree, boolean_t *decoded, uint32_t *result, size_t *treepos, +int HuffmanTree_decode(const HuffmanTree *tree, bool *decoded, uint32_t *result, size_t *treepos, uint32_t bit) { // Decodes a symbol from the tree const vector32_t *tree2d = tree->tree2d; @@ -339,7 +339,7 @@ uint32_t Inflator_huffmanDecodeSymbol(const uint8_t *in, size_t *bp, const HuffmanTree *codetree, size_t inlength) { // decode a single symbol from given list of bits with given code tree. returns the symbol - boolean_t decoded = FALSE; + bool decoded = false; uint32_t ct = 0; size_t treepos = 0; for (;;) { @@ -908,8 +908,8 @@ return NULL; size_t pos = 33; // first byte of the first chunk after the header vector8_t *idat = NULL; // the data from idat chunks - boolean_t IEND = FALSE, known_type = TRUE; - info->key_defined = FALSE; + bool IEND = false, known_type = true; + info->key_defined = false; // loop through the chunks, ignoring unknown chunks and stopping at IEND chunk. IDAT data is // put at the start of the in buffer while (!IEND) { @@ -941,7 +941,7 @@ pos += (4 + chunkLength); } else if (chunkType == CHUNK_IEND) { // IEND pos += 4; - IEND = TRUE; + IEND = true; } else if (chunkType == CHUNK_PLTE) { // PLTE: palette chunk pos += 4; // go after the 4 letters vector8_resize(info->palette, 4 * (chunkLength / 3)); @@ -968,7 +968,7 @@ PNG_error = 40; // error: this chunk must be 2 bytes for greyscale image return NULL; } - info->key_defined = TRUE; + info->key_defined = true; info->key_r = info->key_g = info->key_b = 256 * in[pos] + in[pos + 1]; pos += 2; } else if (info->colorType == 2) { @@ -976,7 +976,7 @@ PNG_error = 41; // error: this chunk must be 6 bytes for RGB image return NULL; } - info->key_defined = TRUE; + info->key_defined = true; info->key_r = 256 * in[pos] + in[pos + 1]; pos += 2; info->key_g = 256 * in[pos] + in[pos + 1]; @@ -994,7 +994,7 @@ return NULL; } pos += (chunkLength + 4); // skip 4 letters and uninterpreted data of unimplemented chunk - known_type = FALSE; + known_type = false; } pos += 4; // step over CRC (which is ignored) } Index: trunk/i386/boot2/resume.c =================================================================== --- trunk/i386/boot2/resume.c (revision 22) +++ trunk/i386/boot2/resume.c (revision 23) @@ -140,7 +140,7 @@ printf("mem_base %x\n", mem_base); - if (!((long long)mem_base + allocSize < 1024 * bootInfo->extmem + 0x100000)) + if (!(long long)mem_base+allocSize<1024*bootInfo->extmem+0x100000) { printf ("Not enough space to restore image. Press any key to proceed with normal boot.\n"); getc (); @@ -170,7 +170,14 @@ previewTotalSectors = 0; previewLoadedSectors = 0; previewSaveunder = 0; - if(check_vga_nvidia(root_pci_dev) ==1 ) setVideoMode( VGA_TEXT_MODE, 0 ); +#if 0 + AsereBLN: + check_vga_nvidia() didn't work as expected (recursion level > 0 & return value). + Unforutnaltely I cannot find a note why to switch back to text mode for nVidia cards only + and because it check_vga_nvidia does not work (cards normally are behind a bridge) I will + remove it completely + setVideoMode( VGA_TEXT_MODE, 0 ); +#endif } else ReadFileAtOffset (image_filename, (char *)buffer, sizeof(IOHibernateImageHeader), imageSize); @@ -206,4 +213,4 @@ #endif WakeKernel(header); -} \ No newline at end of file +} Index: trunk/i386/boot2/graphics.c =================================================================== --- trunk/i386/boot2/graphics.c (revision 22) +++ trunk/i386/boot2/graphics.c (revision 23) @@ -349,7 +349,7 @@ unsigned char value; } * bp = (struct RLEBlock *) rleData; - out = cp = (char *) malloc( outBytes ); + out = cp = malloc( outBytes ); if ( out == NULL ) return NULL; while ( rleBlocks-- ) @@ -515,7 +515,7 @@ PNG_info_t *info; int error = 0; - pngFile = open(filename, 0); + pngFile = open_bvdev("bt(0,0)", filename, 0); if (pngFile == -1) { error = -1; goto failed; @@ -587,42 +587,6 @@ return error; } -int loadPixmapFromPng(const char *filename, pixmap_t *p) -{ - uint16_t width=0,height=0; - uint8_t *imagedata = 0; - - pixmap_t *pm=malloc(sizeof(pixmap_t)); - if(!pm) return 0; - if((loadPngImage(filename, &width, &height, &imagedata))!=0) return 0; - pm->width = width; - pm->height = height; - pm->pixels = (pixel_t *)imagedata; - - flipRB(pm); - *p=*pm; - - return 1; -} - -int loadPixmapFromEmbeddedPng(uint8_t *pngData, uint32_t pngSize, pixmap_t *p) -{ - uint16_t width=0,height=0; - uint8_t *imagedata = 0; - - pixmap_t *pm=malloc(sizeof(pixmap_t)); - if(!pm) return 0; - if((loadEmbeddedPngImage(pngData, pngSize, &width, &height, &imagedata))!=0) return 0; - pm->width = width; - pm->height = height; - pm->pixels = (pixel_t *)imagedata; - - flipRB(pm); - *p=*pm; - - return 1; -} - void blendImage(uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint8_t *data) { @@ -1076,8 +1040,6 @@ char * propStr; unsigned long count = 0; -#define _isdigit(c) ((c) >= '0' && (c) <= '9') - propStr = newStringForKey( (char *) propKey , &bootInfo->bootConfig ); if ( propStr ) { @@ -1092,7 +1054,7 @@ numbers[count++] = val; p = delimiter; } - while ( ( *p != '\0' ) && !_isdigit(*p) ) + while ( ( *p != '\0' ) && !isdigit(*p) ) p++; } Index: trunk/i386/boot2/boot.c =================================================================== --- trunk/i386/boot2/boot.c (revision 22) +++ trunk/i386/boot2/boot.c (revision 23) @@ -57,17 +57,18 @@ #include "libsa.h" #include "ramdisk.h" #include "gui.h" +#include "platform.h" long gBootMode; /* defaults to 0 == kBootModeNormal */ -BOOL gOverrideKernel; +bool gOverrideKernel; static char gBootKernelCacheFile[512]; static char gCacheNameAdler[64 + 256]; char *gPlatformName = gCacheNameAdler; char gRootDevice[512]; char gMKextName[512]; char gMacOSVersion[8]; -BOOL gEnableCDROMRescan; -BOOL gScanSingleDrive; +bool gEnableCDROMRescan; +bool gScanSingleDrive; int bvCount = 0; //int menucount = 0; @@ -76,16 +77,14 @@ BVRef bvr; BVRef menuBVR; BVRef bvChain; -BOOL useGUI = TRUE; +bool useGUI; //static void selectBiosDevice(void); +static unsigned long Adler32(unsigned char *buffer, long length); -static -unsigned long Adler32(unsigned char *buffer, long length); +static bool gUnloadPXEOnExit = false; -static BOOL gUnloadPXEOnExit = 0; - /* * How long to wait (in seconds) to load the * kernel after displaying the "boot:" prompt. @@ -100,37 +99,30 @@ //========================================================================== // Zero the BSS. -static void zeroBSS() +static void zeroBSS(void) { - extern char _DATA__bss__begin, _DATA__bss__end; - extern char _DATA__common__begin, _DATA__common__end; + extern char _DATA__bss__begin, _DATA__bss__end; + extern char _DATA__common__begin, _DATA__common__end; - bzero( &_DATA__bss__begin, - (&_DATA__bss__end - &_DATA__bss__begin) ); - - bzero( &_DATA__common__begin, - (&_DATA__common__end - &_DATA__common__begin) ); + bzero(&_DATA__bss__begin, (&_DATA__bss__end - &_DATA__bss__begin)); + bzero(&_DATA__common__begin, (&_DATA__common__end - &_DATA__common__begin)); } //========================================================================== // Malloc error function -static void malloc_error(char *addr, size_t size) +static void malloc_error(char *addr, size_t size, const char *file, int line) { - printf("\nMemory allocation error (0x%x, 0x%x)\n", - (unsigned)addr, (unsigned)size); - asm volatile ("hlt"); + stop("\nMemory allocation error! Addr=0x%x, Size=0x%x, File=%s, Line=%d\n", (unsigned)addr, (unsigned)size, file, line); } -/*! - Initializes the runtime. Right now this means zeroing the BSS and initializing malloc. - */ -void initialize_runtime() +//========================================================================== +//Initializes the runtime. Right now this means zeroing the BSS and initializing malloc. +// +void initialize_runtime(void) { - zeroBSS(); - - // Initialize malloc - malloc_init(0, 0, 0, malloc_error); + zeroBSS(); + malloc_init(0, 0, 0, malloc_error); } //========================================================================== @@ -182,12 +174,10 @@ } } - BOOL dummyVal; - - if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->bootConfig) && dummyVal) - { - printf("Press any key to continue..."); - getc(); + bool dummyVal; + if (getBoolForKey(kWaitForKeypressKey, &dummyVal, &bootInfo->bootConfig) && dummyVal) { + printf("Press any key to continue..."); + getc(); } // If we were in text mode, switch to graphics mode. @@ -211,28 +201,15 @@ } //========================================================================== -// Scan and record the system's hardware information. - -static void scanHardware() -{ - extern void scan_platform(); - - scan_platform(); -} - -/*! - 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-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. void boot(int biosdev) { - initialize_runtime(); - - // Enable A20 gate before accessing memory above 1Mb. - enableA20(); - - return common_boot(biosdev); + initialize_runtime(); + // Enable A20 gate before accessing memory above 1Mb. + enableA20(); + common_boot(biosdev); } //========================================================================== @@ -246,38 +223,31 @@ // 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. - -#define DLOG(x) outb(0x80, (x)) - void common_boot(int biosdev) { int status; char *bootFile; unsigned long adler32; - BOOL quiet; - BOOL firstRun = YES; - BOOL instantMenu; - BOOL rescanPrompt; + bool quiet; + bool firstRun = true; + bool instantMenu; + bool rescanPrompt; unsigned int allowBVFlags = kBVFlagSystemVolume|kBVFlagForeignBoot; unsigned int denyBVFlags = kBVFlagEFISystem; // Set reminder to unload the PXE base code. Neglect to unload // the base code will result in a hang or kernel panic. + gUnloadPXEOnExit = true; - gUnloadPXEOnExit = 1; - // Record the device that the booter was loaded from. - gBIOSDev = biosdev & kBIOSDevMask; // Initialize boot info structure. - initKernBootStruct(); // Setup VGA text mode. // Not sure if it is safe to call setVideoMode() before the // config table has been loaded. Call video_mode() instead. - #if DEBUG printf("before video_mode\n"); #endif @@ -286,11 +256,8 @@ printf("after video_mode\n"); #endif - // Check to see that this hardware is supported. - status = checkForSupportedHardware(); - if (status != 0) { - printf("This hardware configuration is not supported by Darwin/x86. (%d)", status); - } + // Scan and record the system's hardware information. + scan_platform(); // First get info for boot volume. scanBootVolumes(gBIOSDev, 0); @@ -300,43 +267,43 @@ // Load boot.plist config file status = loadSystemConfig(&bootInfo->bootConfig); - if ( getBoolForKey( kQuietBootKey, &quiet, &bootInfo->bootConfig ) && quiet ) { + if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet) { gBootMode |= kBootModeQuiet; } // Override firstRun to get to the boot menu instantly by setting "Instant Menu"=y in system config - if ( getBoolForKey( kInsantMenuKey, &instantMenu, &bootInfo->bootConfig ) && instantMenu ) { - firstRun = FALSE; + if (getBoolForKey(kInsantMenuKey, &instantMenu, &bootInfo->bootConfig) && instantMenu) { + firstRun = false; } // Loading preboot ramdisk if exists. loadPrebootRAMDisk(); // Disable rescan option by default - gEnableCDROMRescan = FALSE; + gEnableCDROMRescan = false; // Enable it with Rescan=y in system config - if ( getBoolForKey( kRescanKey, &gEnableCDROMRescan, &bootInfo->bootConfig ) && gEnableCDROMRescan ) { - gEnableCDROMRescan = TRUE; + if (getBoolForKey(kRescanKey, &gEnableCDROMRescan, &bootInfo->bootConfig) && gEnableCDROMRescan) { + gEnableCDROMRescan = true; } // Ask the user for Rescan option by setting "Rescan Prompt"=y in system config. - rescanPrompt = FALSE; - if ( getBoolForKey( kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig ) && rescanPrompt - && biosDevIsCDROM(gBIOSDev) ) { + rescanPrompt = false; + if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->bootConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev)) { gEnableCDROMRescan = promptForRescanOption(); } // Enable touching a single BIOS device only if "Scan Single Drive"=y is set in system config. - if ( getBoolForKey( kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig ) && gScanSingleDrive ) { - gScanSingleDrive = TRUE; + if (getBoolForKey(kScanSingleDriveKey, &gScanSingleDrive, &bootInfo->bootConfig) && gScanSingleDrive) { + gScanSingleDrive = true; } // Create a list of partitions on device(s). - if (gScanSingleDrive) - scanBootVolumes( gBIOSDev, &bvCount ); - else - scanDisks( gBIOSDev, &bvCount ); + if (gScanSingleDrive) { + scanBootVolumes(gBIOSDev, &bvCount); + } else { + scanDisks(gBIOSDev, &bvCount); + } // Create a separated bvr chain using the specified filters. bvChain = newFilteredBVChain(0x80, 0xFF, allowBVFlags, denyBVFlags, &gDeviceCount); @@ -349,34 +316,27 @@ getc(); #endif - // Scan hardware configuration. - scanHardware(); - - // Check if GUI=n switch is present in config file - if ( getBoolForKey(kGUIKey, &useGUI, &bootInfo->bootConfig) && !useGUI ) - useGUI = FALSE; - - // Try initialising the GUI unless disabled - if( useGUI ) - initGUI(); - - // Load boot logo image - loadBootGraphics(); + useGUI = true; + // Override useGUI default + getBoolForKey(kGUIKey, &useGUI, &bootInfo->bootConfig); + if (useGUI) { + /* XXX AsereBLN handle error */ + initGUI(); + } setBootGlobals(bvChain); - + // Parse args, load and start kernel. - while (1) - { + while (1) { const char *val; int len; int trycache; long flags, cachetime, kerneltime, exttime, sleeptime, time; int ret = -1; void *binary = (void *)kLoadAddr; - BOOL tryresume; - BOOL tryresumedefault; - BOOL forceresume; + bool tryresume; + bool tryresumedefault; + bool forceresume; config_file_t systemVersion; // system.plist of booting partition @@ -385,11 +345,11 @@ // Initialize globals. - sysConfigValid = 0; - gErrors = 0; + sysConfigValid = false; + gErrors = false; status = getBootOptions(firstRun); - firstRun = NO; + firstRun = false; if (status == -1) continue; status = processBootOptions(); @@ -422,54 +382,58 @@ // Turn off any GUI elements if( bootArgs->Video.v_display == GRAPHICS_MODE ) { - gui.devicelist.draw = NO; - gui.bootprompt.draw = NO; - gui.menu.draw = NO; - gui.infobox.draw = NO; + gui.devicelist.draw = false; + gui.bootprompt.draw = false; + gui.menu.draw = false; + gui.infobox.draw = false; drawBackground(); updateVRAM(); } // Find out which version mac os we're booting. - if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion) ) - if (getValueForKey("ProductVersion", &val, &len, &systemVersion)) - { + if (!loadConfigFile("System/Library/CoreServices/SystemVersion.plist", &systemVersion)) { + if (getValueForKey(kProductVersion, &val, &len, &systemVersion)) { // getValueForKey uses const char for val // so copy it and trim strncpy(gMacOSVersion, val, MIN(len, 4)); gMacOSVersion[MIN(len, 4)] = '\0'; } - - archCpuType=detectCpuType (); - if (getValueForKey("arch", &val, &len, &bootInfo->bootConfig)) - { - if(strncmp(val,"x86_64",6) == 0) - archCpuType=CPU_TYPE_X86_64; - else - archCpuType=CPU_TYPE_I386; } + + if (platformCPUFeature(CPU_FEATURE_EM64T)) { + archCpuType = CPU_TYPE_X86_64; + } else { + archCpuType = CPU_TYPE_I386; + } + if (getValueForKey(karch, &val, &len, &bootInfo->bootConfig)) { + if (strncmp(val, "i386", 4) == 0) { + archCpuType = CPU_TYPE_I386; + } + } + if (getValueForKey(k32BitModeFlag, &val, &len, &bootInfo->bootConfig)) { + archCpuType = CPU_TYPE_I386; + } - if (!getBoolForKey ("Wake", &tryresume, &bootInfo->bootConfig)) - { - tryresume = TRUE; - tryresumedefault = TRUE; + if (!getBoolForKey (kWake, &tryresume, &bootInfo->bootConfig)) { + tryresume = true; + tryresumedefault = true; + } else { + tryresumedefault = false; } - else - tryresumedefault = FALSE; - if (!getBoolForKey ("ForceWake", &forceresume, &bootInfo->bootConfig)) - forceresume = FALSE; + if (!getBoolForKey (kForceWake, &forceresume, &bootInfo->bootConfig)) { + forceresume = false; + } - if (forceresume) - { - tryresume = TRUE; - tryresumedefault = FALSE; + if (forceresume) { + tryresume = true; + tryresumedefault = false; } while (tryresume) { const char *tmp; BVRef bvr; - if (!getValueForKey("WakeImage", &val, &len, &bootInfo->bootConfig)) + if (!getValueForKey(kWakeImage, &val, &len, &bootInfo->bootConfig)) val="/private/var/vm/sleepimage"; // Do this first to be sure that root volume is mounted @@ -485,8 +449,7 @@ if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeFlat)) break; - if (!forceresume && sleeptime+3modTime) - { + if (!forceresume && sleeptime+3modTime) { printf ("Hibernate image is too old by %d seconds. Use ForceWake=y to override\n",bvr->modTime-sleeptime); break; } @@ -502,7 +465,7 @@ adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler)); - if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig) == YES) { + if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) { strlcpy(gBootKernelCacheFile, val, len+1); } else { sprintf(gBootKernelCacheFile, "%s.%08lX", kDefaultCachePath, adler32); @@ -510,7 +473,7 @@ // Check for cache file. trycache = (((gBootMode & kBootModeSafe) == 0) && - (gOverrideKernel == NO) && + !gOverrideKernel && (gBootFileType == kBlockDeviceType) && (gMKextName[0] == '\0') && (gBootKernelCacheFile[0] != '\0')); @@ -593,36 +556,32 @@ sleep(8); #endif - if (ret <= 0) - { + if (ret <= 0) { printf("Can't find %s\n", bootFile); - if(gui.initialised == YES) - { + if(gui.initialised) { sleep(1); drawBackground(); - gui.devicelist.draw = YES; - gui.redraw = YES; + gui.devicelist.draw = true; + gui.redraw = true; } - - if ( gBootFileType == kNetworkDeviceType ) - { + if (gBootFileType == kNetworkDeviceType) { // Return control back to PXE. Don't unload PXE base code. - gUnloadPXEOnExit = 0; + gUnloadPXEOnExit = false; break; } - } else { /* Won't return if successful. */ ret = ExecKernel(binary); } - - } /* while(1) */ + } // chainboot - if(status==1) - if(getVideoMode() == GRAPHICS_MODE) // if we are already in graphics-mode, + if (status==1) { + if (getVideoMode() == GRAPHICS_MODE) { // if we are already in graphics-mode, setVideoMode(VGA_TEXT_MODE, 0); // switch back to text mode + } + } if ((gBootFileType == kNetworkDeviceType) && gUnloadPXEOnExit) { nbpUnloadBaseCode(); Index: trunk/i386/boot2/picopng.h =================================================================== --- trunk/i386/boot2/picopng.h (revision 22) +++ trunk/i386/boot2/picopng.h (revision 23) @@ -20,7 +20,7 @@ uint32_t colorType, bitDepth; uint32_t compressionMethod, filterMethod, interlaceMethod; uint32_t key_r, key_g, key_b; - boolean_t key_defined; // is a transparent color key given? + bool key_defined; // is a transparent color key given? vector8_t *palette; vector8_t *image; } PNG_info_t; Index: trunk/i386/boot2/graphics.h =================================================================== --- trunk/i386/boot2/graphics.h (revision 22) +++ trunk/i386/boot2/graphics.h (revision 23) @@ -19,8 +19,6 @@ #define DEFAULT_SCREEN_HEIGHT 768 int loadPngImage(const char *filename, uint16_t *width, uint16_t *height, uint8_t **imageData); -int loadPixmapFromPng(const char *filename, pixmap_t *p); -int loadPixmapFromEmbeddedPng(uint8_t *pngData, uint32_t pngSize, pixmap_t *p); unsigned long lookUpCLUTIndex( unsigned char index, unsigned char depth ); @@ -44,4 +42,4 @@ char *getVBEModeInfoString(); void getGraphicModeParams(unsigned long params[]); -#endif /* !__BOOT_GRAPHICS_H */ \ No newline at end of file +#endif /* !__BOOT_GRAPHICS_H */ Index: trunk/i386/boot2/boot.h =================================================================== --- trunk/i386/boot2/boot.h (revision 22) +++ trunk/i386/boot2/boot.h (revision 23) @@ -34,40 +34,68 @@ /* * Keys used in system Boot.plist */ -#define kGraphicsModeKey "Graphics Mode" -#define kTextModeKey "Text Mode" -#define kQuietBootKey "Quiet Boot" -#define kKernelFlagsKey "Kernel Flags" -#define kMKextCacheKey "MKext Cache" -#define kKernelNameKey "Kernel" -#define kKernelCacheKey "Kernel Cache" -#define kBootDeviceKey "Boot Device" -#define kTimeoutKey "Timeout" -#define kRootDeviceKey "rd" -#define kBootUUIDKey "boot-uuid" -#define kHelperRootUUIDKey "Root UUID" -#define kPlatformKey "platform" -#define kACPIKey "acpi" -#define kCDROMPromptKey "CD-ROM Prompt" -#define kCDROMOptionKey "CD-ROM Option Key" -#define kRescanPromptKey "Rescan Prompt" -#define kRescanKey "Rescan" -#define kScanSingleDriveKey "Scan Single Drive" -#define kInsantMenuKey "Instant Menu" -#define kDefaultKernel "mach_kernel" -#define kGUIKey "GUI" -#define kBootBannerKey "Boot Banner" -#define kWaitForKeypressKey "Wait" +#define kGraphicsModeKey "Graphics Mode" +#define kTextModeKey "Text Mode" +#define kQuietBootKey "Quiet Boot" +#define kKernelFlagsKey "Kernel Flags" +#define kMKextCacheKey "MKext Cache" +#define kKernelNameKey "Kernel" +#define kKernelCacheKey "Kernel Cache" +#define kBootDeviceKey "Boot Device" +#define kTimeoutKey "Timeout" +#define kRootDeviceKey "rd" +#define kBootUUIDKey "boot-uuid" +#define kHelperRootUUIDKey "Root UUID" +#define kPlatformKey "platform" +#define kACPIKey "acpi" +#define kCDROMPromptKey "CD-ROM Prompt" +#define kCDROMOptionKey "CD-ROM Option Key" +#define kRescanPromptKey "Rescan Prompt" +#define kRescanKey "Rescan" +#define kScanSingleDriveKey "Scan Single Drive" +#define kInsantMenuKey "Instant Menu" +#define kDefaultKernel "mach_kernel" +#define kGUIKey "GUI" +#define kBootBannerKey "Boot Banner" +#define kWaitForKeypressKey "Wait" +/* AsereBLN: added the other keys */ +#define kUseAtiROM "UseAtiROM" /* ati.c */ +#define kWake "Wake" /* boot.c */ +#define kForceWake "ForceWake" /* boot.c */ +#define kWakeImage "WakeImage" /* boot.c */ +#define kProductVersion "ProductVersion" /* boot.c */ +#define karch "arch" /* boot.c */ +#define kDSDT "DSDT" /* dsdt_patcher.c */ +#define kDropSSDT "DropSSDT" /* dsdt_patcher.c */ +#define kRestartFix "RestartFix" /* dsdt_patcher.c */ +#define kSMBIOS "SMBIOS" /* fake_efi.c */ +#define kSystemID "system-id" /* fake_efi.c */ +#define kSystemType "system-type" /* fake_efi.c */ +#define kUseNvidiaROM "UseNvidiaROM" /* nvidia.c */ +#define kVBIOS "VBIOS" /* nvidia.c */ +#define kPCIRootUID "PCIRootUID" /* pci_root.c */ +#define kEthernetBuiltIn "EthernetBuiltIn" /* pci_setup.c */ +#define kGraphicsEnabler "GraphicsEnabler" /* pci_setup.c */ +#define kUSBBusFix "USBBusFix" /* pci_setup.c */ +#define kEHCIacquire "EHCIacquire" /* pci_setup.c */ +#define kUHCIreset "UHCIreset" /* pci_setup.c */ +#define kForceHPET "ForceHPET" /* pci_setup.c */ +#define kSMBIOSdefaults "SMBIOSdefaults" /* smbios_patcher.c */ +#define kEHCIhard "EHCIhard" /* usb.c */ +#define kDefaultPartition "Default Partition" /* sys.c */ +#define kDeviceProperties "device-properties" /* device_inject.c */ +#define kHidePartition "Hide Partition" /* disk.c */ +#define kRenamePartition "Rename Partition" /* disk.c */ /* * Flags to the booter or kernel - * */ -#define kVerboseModeFlag "-v" -#define kSafeModeFlag "-x" -#define kOldSafeModeFlag "-f" -#define kIgnoreBootFileFlag "-F" -#define kSingleUserModeFlag "-s" +#define kVerboseModeFlag "-v" +#define kSafeModeFlag "-x" +#define kOldSafeModeFlag "-f" +#define kIgnoreBootFileFlag "-F" +#define kSingleUserModeFlag "-s" +#define k32BitModeFlag "-x32" /* * Booter behavior control @@ -81,18 +109,20 @@ */ extern int gBIOSDev; extern long gBootMode; -extern BOOL sysConfigValid; +extern bool sysConfigValid; extern char bootBanner[]; extern char bootPrompt[]; -extern BOOL gOverrideKernel; +extern bool gOverrideKernel; extern char *gPlatformName; extern char gMKextName[]; extern char gRootDevice[]; -extern BOOL gEnableCDROMRescan; -extern BOOL gScanSingleDrive; -extern BOOL useGUI; +extern bool gEnableCDROMRescan; +extern bool gScanSingleDrive; +extern bool useGUI; -// Boot Modes +/* + * Boot Modes + */ enum { kBootModeNormal = 0, kBootModeSafe = 1, @@ -106,7 +136,6 @@ /* * graphics.c */ - extern void printVBEModeInfo(); extern void setVideoMode(int mode, int drawgraphics); extern int getVideoMode(); @@ -148,10 +177,10 @@ /* * options.c */ -extern int getBootOptions(BOOL firstRun); +extern int getBootOptions(bool firstRun); extern int processBootOptions(); extern int selectAlternateBootDevice(int bootdevice); -extern BOOL promptForRescanOption(void); +extern bool promptForRescanOption(void); void showHelp(); void showTextFile(); @@ -184,7 +213,6 @@ void HibernateBoot(char *boot_device); /* bmdecompress.c */ -void * -DecompressData(void *srcbase, int *dw, int *dh, int *bytesPerPixel); +void * DecompressData(void *srcbase, int *dw, int *dh, int *bytesPerPixel); #endif /* !__BOOT2_BOOT_H */ Index: trunk/i386/boot2/drivers.c =================================================================== --- trunk/i386/boot2/drivers.c (revision 22) +++ trunk/i386/boot2/drivers.c (revision 23) @@ -145,11 +145,11 @@ static long InitDriverSupport( void ) { - gExtensionsSpec = (char *) malloc( 4096 ); - gDriverSpec = (char *) malloc( 4096 ); - gFileSpec = (char *) malloc( 4096 ); - gTempSpec = (char *) malloc( 4096 ); - gFileName = (char *) malloc( 4096 ); + gExtensionsSpec = malloc( 4096 ); + gDriverSpec = malloc( 4096 ); + gFileSpec = malloc( 4096 ); + gTempSpec = malloc( 4096 ); + gFileName = malloc( 4096 ); if ( !gExtensionsSpec || !gDriverSpec || !gFileSpec || !gTempSpec || !gFileName ) stop("InitDriverSupport error"); @@ -471,7 +471,7 @@ module->executablePath = tmpExecutablePath; module->bundlePath = tmpBundlePath; module->bundlePathLength = bundlePathLength; - module->plistAddr = (void *)malloc(length); + module->plistAddr = malloc(length); if ((module->executablePath == 0) || (module->bundlePath == 0) || (module->plistAddr == 0)) break; @@ -727,7 +727,7 @@ return -2; } - tmpModule = (ModulePtr)malloc(sizeof(Module)); + tmpModule = malloc(sizeof(Module)); if (tmpModule == 0) { XMLFreeTag(moduleDict); Index: trunk/i386/boot2/mboot.c =================================================================== --- trunk/i386/boot2/mboot.c (revision 22) +++ trunk/i386/boot2/mboot.c (revision 23) @@ -389,7 +389,7 @@ const char *val; int size; - if(getValueForBootKey(mi->mi_cmdline, "biosdev", &val, &size) != NO) + if(getValueForBootKey(mi->mi_cmdline, "biosdev", &val, &size)) { char *endptr; int intVal = strtol(val, &endptr, 16 /* always hex */); @@ -403,7 +403,7 @@ doSelectDevice = true; } - if(getValueForBootKey(mi->mi_cmdline, "timeout", &val, &size) != NO) + if(getValueForBootKey(mi->mi_cmdline, "timeout", &val, &size)) { char *endptr; int intVal = strtol(val, &endptr, 0); @@ -415,7 +415,7 @@ } } - if(getValueForBootKey(mi->mi_cmdline, "partno", &val, &size) != NO) + if(getValueForBootKey(mi->mi_cmdline, "partno", &val, &size)) { char *endptr; int intVal = strtol(val, &endptr, 0); @@ -466,9 +466,9 @@ return -1; struct multiboot_module *module = modules + (biosdev - 0x100); dip->biosdev = biosdev; - dip->uses_ebios = TRUE; + 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; + dip->valid = true; return 0; } Index: trunk/i386/boot2/gui.c =================================================================== --- trunk/i386/boot2/gui.c (revision 22) +++ trunk/i386/boot2/gui.c (revision 23) @@ -12,17 +12,15 @@ #include "appleboot.h" #include "vers.h" +//#define EMBED_THEME + #ifdef EMBED_THEME #include "art.h" -#define LOADPNG(img) \ - if(!loadThemeImage(#img".png")) \ - if(!loadPixmapFromEmbeddedPng(__## img ##_png, __## img ##_png_len, images[imageCnt].image)) \ - return 1; \ - imageCnt++ +#define LOADPNG(img) if (loadEmbeddedThemeImage(#img, __## img ##_png, __## img ##_png_len) != 0) { return 1; } #else -#define LOADPNG(img) \ - if(!loadThemeImage(#img".png")) \ - return 1; +#define THEME_NAME_DEFAULT "Default" +static const char *theme_name = THEME_NAME_DEFAULT; +#define LOADPNG(img) if (loadThemeImage(#img) != 0) { return 1; } #endif #define MIN(x, y) ((x) < (y) ? (x) : (y)) @@ -37,45 +35,9 @@ extern int gDeviceCount; -image_t images[] = { - - {.name = "background", .image = 0}, - {.name = "logo", .image = 0}, - - {.name = "device_generic", .image = 0}, - {.name = "device_hfsplus", .image = 0}, - {.name = "device_ext3", .image = 0}, - {.name = "device_fat16", .image = 0}, - {.name = "device_fat32", .image = 0}, - {.name = "device_ntfs", .image = 0}, - {.name = "device_cdrom", .image = 0}, - {.name = "device_selection", .image = 0}, - {.name = "device_scroll_prev", .image = 0}, - {.name = "device_scroll_next", .image = 0}, - - {.name = "menu_boot", .image = 0}, - {.name = "menu_verbose", .image = 0}, - {.name = "menu_ignore_caches", .image = 0}, - {.name = "menu_single_user", .image = 0}, - {.name = "menu_memory_info", .image = 0}, - {.name = "menu_video_info", .image = 0}, - {.name = "menu_help", .image = 0}, - {.name = "menu_verbose_disabled", .image = 0}, - {.name = "menu_ignore_caches_disabled", .image = 0}, - {.name = "menu_single_user_disabled", .image = 0}, - {.name = "menu_selection", .image = 0}, - - {.name = "progress_bar", .image = 0}, - {.name = "progress_bar_background", .image = 0}, - - {.name = "text_scroll_prev", .image = 0}, - {.name = "text_scroll_next", .image = 0}, - - {.name = "font_small", .image = 0}, - {.name = "font_console", .image = 0}, - -}; - +/* + * ATTENTION: the enum and the following array images[] MUST match !!! + */ enum { iBackground = 0, iLogo, @@ -108,11 +70,48 @@ iTextScrollPrev, iTextScrollNext, - + iFontConsole, iFontSmall, }; +image_t images[] = { + {.name = "background", .image = NULL}, + {.name = "logo", .image = NULL}, + + {.name = "device_generic", .image = NULL}, + {.name = "device_hfsplus", .image = NULL}, + {.name = "device_ext3", .image = NULL}, + {.name = "device_fat16", .image = NULL}, + {.name = "device_fat32", .image = NULL}, + {.name = "device_ntfs", .image = NULL}, + {.name = "device_cdrom", .image = NULL}, + {.name = "device_selection", .image = NULL}, + {.name = "device_scroll_prev", .image = NULL}, + {.name = "device_scroll_next", .image = NULL}, + + {.name = "menu_boot", .image = NULL}, + {.name = "menu_verbose", .image = NULL}, + {.name = "menu_ignore_caches", .image = NULL}, + {.name = "menu_single_user", .image = NULL}, + {.name = "menu_memory_info", .image = NULL}, + {.name = "menu_video_info", .image = NULL}, + {.name = "menu_help", .image = NULL}, + {.name = "menu_verbose_disabled", .image = NULL}, + {.name = "menu_ignore_caches_disabled", .image = NULL}, + {.name = "menu_single_user_disabled", .image = NULL}, + {.name = "menu_selection", .image = NULL}, + + {.name = "progress_bar", .image = NULL}, + {.name = "progress_bar_background", .image = NULL}, + + {.name = "text_scroll_prev", .image = NULL}, + {.name = "text_scroll_next", .image = NULL}, + + {.name = "font_console", .image = NULL}, + {.name = "font_small", .image = NULL}, +}; + int imageCnt = 0; extern int gDeviceCount; @@ -137,21 +136,126 @@ { .text = "Help" } }; - int initFont(font_t *font, image_t *image); void colorFont(font_t *font, uint32_t color); -int loadGraphics(); void makeRoundedCorners(pixmap_t *p); -BOOL testForQemu(); +static int infoMenuSelection = 0; +static int infoMenuItemsCount = sizeof(infoMenuItems)/sizeof(infoMenuItems[0]); -int infoMenuSelection = 0; -int infoMenuItemsCount = sizeof(infoMenuItems)/sizeof(infoMenuItems[0]); +static bool infoMenuNativeBoot = false; -BOOL infoMenuNativeBoot = 0; +static unsigned long screen_params[4] = {0, 0, 0, 0}; // here we store the used screen resolution -unsigned long screen_params[4]; // here we store the used screen resolution +#ifdef EMBED_THEME +static int loadEmbeddedThemeImage(const char *image, unsigned char *image_data, unsigned int image_size) +{ + int i; + uint16_t width; + uint16_t height; + uint8_t *imagedata; + for (i=0; i < sizeof(images) / sizeof(images[0]); i++) { + if (strcmp(image, images[i].name) == 0) { + if (images[i].image == NULL) { + images[i].image = malloc(sizeof(pixmap_t)); + } + width = 0; + height = 0; + imagedata = NULL; + if ((loadEmbeddedPngImage(image_data, image_size, &width, &height, &imagedata)) != 0) { + return 1; + } + images[i].image->width = width; + images[i].image->height = height; + images[i].image->pixels = (pixel_t *)imagedata; + flipRB(images[i].image); + return 0; + } + } + return 1; +} +#else +static int loadThemeImage(const char *image) +{ + char dirspec[256]; + int i; + uint16_t width; + uint16_t height; + uint8_t *imagedata; + + + if ((strlen(image) + strlen(theme_name) + 20 ) > sizeof(dirspec)) { + return 1; + } + for (i=0; i < sizeof(images) / sizeof(images[0]); i++) { + if (strcmp(image, images[i].name) == 0) { + if (images[i].image == NULL) { + images[i].image = malloc(sizeof(pixmap_t)); + } + sprintf(dirspec,"/Extra/Themes/%s/%s.png", theme_name, image); + width = 0; + height = 0; + imagedata = NULL; + if ((loadPngImage(dirspec, &width, &height, &imagedata)) != 0) { + printf("ERROR: GUI: could not open '%s/%s.png'!\n", theme_name, image); + sleep(5); + return 1; + } + images[i].image->width = width; + images[i].image->height = height; + images[i].image->pixels = (pixel_t *)imagedata; + flipRB(images[i].image); + return 0; + } + } + return 1; +} +#endif + +static int loadGraphics(void) +{ + LOADPNG(background); + LOADPNG(logo); + + LOADPNG(device_generic); + LOADPNG(device_hfsplus); + LOADPNG(device_ext3); + LOADPNG(device_fat16); + LOADPNG(device_fat32); + LOADPNG(device_ntfs); + LOADPNG(device_cdrom); + LOADPNG(device_selection); + LOADPNG(device_scroll_prev); + LOADPNG(device_scroll_next); + + LOADPNG(menu_boot); + LOADPNG(menu_verbose); + LOADPNG(menu_ignore_caches); + LOADPNG(menu_single_user); + LOADPNG(menu_memory_info); + LOADPNG(menu_video_info); + LOADPNG(menu_help); + LOADPNG(menu_verbose_disabled); + LOADPNG(menu_ignore_caches_disabled); + LOADPNG(menu_single_user_disabled); + LOADPNG(menu_selection); + + LOADPNG(progress_bar); + LOADPNG(progress_bar_background); + + LOADPNG(text_scroll_prev); + LOADPNG(text_scroll_next); + + LOADPNG(font_console); + LOADPNG(font_small); + + initFont( &font_console, &images[iFontConsole]); + initFont( &font_small, &images[iFontSmall]); + + return 0; +} + pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height ) { @@ -203,7 +307,7 @@ window->pixmap = malloc(sizeof(pixmap_t)); if(!window->pixmap) return 1; - + window->pixmap->pixels = malloc( window->width * window->height * 4 ); if(!window->pixmap->pixels) { @@ -245,346 +349,279 @@ memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); } -void loadThemeValues(config_file_t *theme, BOOL overide) +void loadThemeValues(config_file_t *theme, bool overide) { - BOOL themeEnabled; + unsigned int screen_width = gui.screen.width; + unsigned int screen_height = gui.screen.height; + unsigned int pixel; + int alpha; // transparency level 0 (obligue) - 255 (transparent) + uint32_t color; // color value formatted RRGGBB + int val, len; + const char *string; - if ( (getBoolForKey("Enabled", &themeEnabled, theme ) ) || ( overide ) ) - { - unsigned int screen_width = gui.screen.width; - unsigned int screen_height = gui.screen.height; - - unsigned int pixel; - - int alpha; // transparency level 0 (obligue) - 255 (transparent) - - uint32_t color; // color value formatted RRGGBB + /* + * Parse screen parameters + */ + if(getColorForKey("screen_bgcolor", &color, theme )) + gui.screen.bgcolor = (color & 0x00FFFFFF); - int val, len; - const char *string; - - /* - * Parse screen parameters - */ - - if(getColorForKey("screen_bgcolor", &color, theme )) - gui.screen.bgcolor = (color & 0x00FFFFFF); + if(getIntForKey("screen_textmargin_h", &val, theme)) + gui.screen.hborder = MIN( gui.screen.width , val ); - if(getIntForKey("screen_textmargin_h", &val, theme)) - gui.screen.hborder = MIN( gui.screen.width , val ); - - if(getIntForKey("screen_textmargin_v", &val, theme)) - gui.screen.vborder = MIN( gui.screen.height , val ); + if(getIntForKey("screen_textmargin_v", &val, theme)) + gui.screen.vborder = MIN( gui.screen.height , val ); - /* - * Parse background parameters - */ - - if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) ) - gui.background.pos.x = pixel; + /* + * Parse background parameters + */ + if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) ) + gui.background.pos.x = pixel; - if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) ) - gui.background.pos.y = pixel; - - /* - * Parse logo parameters - */ + if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) ) + gui.background.pos.y = pixel; - if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) ) - gui.logo.pos.x = pixel; - - if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) ) - gui.logo.pos.y = pixel; + /* + * Parse logo parameters + */ + if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) ) + gui.logo.pos.x = pixel; - /* - * Parse progress bar parameters - */ - - if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) ) - gui.progressbar.pos.x = pixel; - - if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) ) - gui.progressbar.pos.y = pixel; + if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) ) + gui.logo.pos.y = pixel; - /* - * Parse countdown text parameters - */ - - if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) ) - gui.countdown.pos.x = pixel; - - if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) ) - gui.countdown.pos.y = pixel; - - /* - * Parse devicelist parameters - */ - - if(getIntForKey("devices_max_visible", &val, theme )) - gui.maxdevices = MIN( val, gDeviceCount ); - - if(getIntForKey("devices_iconspacing", &val, theme )) - gui.devicelist.iconspacing = val; - - // check layout for horizontal or vertical - if(getValueForKey( "devices_layout", &string, &len, theme ) ) - if (!strcmp (string, "vertical")) - gui.layout = VerticalLayout; - else - gui.layout = HorizontalLayout; - else - gui.layout = HorizontalLayout; - - switch (gui.layout) - { - - case VerticalLayout: - gui.devicelist.height = ( ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ) * MIN( gui.maxdevices, gDeviceCount ) + ( images[iDeviceScrollPrev].image->height + images[iDeviceScrollNext].image->height ) + gui.devicelist.iconspacing ); - gui.devicelist.width = ( images[iSelection].image->width + gui.devicelist.iconspacing ); - - if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) ) - gui.devicelist.pos.x = pixel; - - if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) ) - gui.devicelist.pos.y = pixel; - - break; - - default: - - case HorizontalLayout: - - gui.devicelist.width = ( ( images[iSelection].image->width + gui.devicelist.iconspacing ) * MIN( gui.maxdevices, gDeviceCount ) + ( images[iDeviceScrollPrev].image->width + images[iDeviceScrollNext].image->width ) + gui.devicelist.iconspacing ); - gui.devicelist.height = ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); - - if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) ) - gui.devicelist.pos.x = pixel; - else - gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2; - - if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) ) - gui.devicelist.pos.y = pixel; - else - gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2; - - break; + /* + * Parse progress bar parameters + */ + if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) ) + gui.progressbar.pos.x = pixel; + + if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) ) + gui.progressbar.pos.y = pixel; + + /* + * Parse countdown text parameters + */ + if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) ) + gui.countdown.pos.x = pixel; + + if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) ) + gui.countdown.pos.y = pixel; + + /* + * Parse devicelist parameters + */ + if(getIntForKey("devices_max_visible", &val, theme )) + gui.maxdevices = MIN( val, gDeviceCount ); + + if(getIntForKey("devices_iconspacing", &val, theme )) + gui.devicelist.iconspacing = val; + + // check layout for horizontal or vertical + gui.layout = HorizontalLayout; + if(getValueForKey( "devices_layout", &string, &len, theme)) { + if (!strcmp (string, "vertical")) { + gui.layout = VerticalLayout; } + } - if(getColorForKey("devices_bgcolor", &color, theme)) - gui.devicelist.bgcolor = (color & 0x00FFFFFF); - - if(getIntForKey("devices_transparency", &alpha, theme)) - gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); + switch (gui.layout) { + case VerticalLayout: + gui.devicelist.height = ((images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->height + images[iDeviceScrollNext].image->height) + gui.devicelist.iconspacing); + gui.devicelist.width = (images[iSelection].image->width + gui.devicelist.iconspacing); - /* - * Parse infobox parameters - */ - - if(getIntForKey("infobox_width", &val, theme)) - gui.infobox.width = MIN( screen_width , val ); - - if(getIntForKey("infobox_height", &val, theme)) - gui.infobox.height = MIN( screen_height , val ); + if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) ) + gui.devicelist.pos.x = pixel; - if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) ) - gui.infobox.pos.x = pixel; + if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) ) + gui.devicelist.pos.y = pixel; + break; - if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) ) - gui.infobox.pos.y = pixel; - - if(getIntForKey("infobox_textmargin_h", &val, theme)) - gui.infobox.hborder = MIN( gui.infobox.width , val ); - - if(getIntForKey("infobox_textmargin_v", &val, theme)) - gui.infobox.vborder = MIN( gui.infobox.height , val ); + case HorizontalLayout: + default: + gui.devicelist.width = ((images[iSelection].image->width + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->width + images[iDeviceScrollNext].image->width) + gui.devicelist.iconspacing); + gui.devicelist.height = (images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing); - if(getColorForKey("infobox_bgcolor", &color, theme)) - gui.infobox.bgcolor = (color & 0x00FFFFFF); - - if(getIntForKey("infobox_transparency", &alpha, theme)) - gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); - - /* - * Parse menu parameters - */ - - if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) ) - gui.menu.width = pixel; + if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) ) + gui.devicelist.pos.x = pixel; else - gui.menu.width = images[iMenuSelection].image->width; + gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2; - if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) ) - gui.menu.height = pixel; + if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) ) + gui.devicelist.pos.y = pixel; else - gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height; - - - if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) ) - gui.menu.pos.x = pixel; - - if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) ) - gui.menu.pos.y = pixel; + gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2; + break; + } - if(getIntForKey("menu_textmargin_h", &val, theme)) - gui.menu.hborder = MIN( gui.menu.width , val ); - - if(getIntForKey("menu_textmargin_v", &val, theme)) - gui.menu.vborder = MIN( gui.menu.height , val ); + if(getColorForKey("devices_bgcolor", &color, theme)) + gui.devicelist.bgcolor = (color & 0x00FFFFFF); - if(getColorForKey("menu_bgcolor", &color, theme)) - gui.menu.bgcolor = (color & 0x00FFFFFF); - - if(getIntForKey("menu_transparency", &alpha, theme)) - gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); - - /* - * Parse bootprompt parameters - */ + if(getIntForKey("devices_transparency", &alpha, theme)) + gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); - if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) ) - gui.bootprompt.width = pixel; - - if(getIntForKey("bootprompt_height", &val, theme)) - gui.bootprompt.height = MIN( screen_height , val ); + /* + * Parse infobox parameters + */ + if(getIntForKey("infobox_width", &val, theme)) + gui.infobox.width = MIN( screen_width , val ); - if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) ) - gui.bootprompt.pos.x = pixel; - - if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) ) - gui.bootprompt.pos.y = pixel; - - if(getIntForKey("bootprompt_textmargin_h", &val, theme)) - gui.bootprompt.hborder = MIN( gui.bootprompt.width , val ); - - if(getIntForKey("bootprompt_textmargin_v", &val, theme)) - gui.bootprompt.vborder = MIN( gui.bootprompt.height , val ); + if(getIntForKey("infobox_height", &val, theme)) + gui.infobox.height = MIN( screen_height , val ); - if(getColorForKey("bootprompt_bgcolor", &color, theme)) - gui.bootprompt.bgcolor = (color & 0x00FFFFFF); - - if(getIntForKey("bootprompt_transparency", &alpha, theme)) - gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); - - if(getColorForKey("font_small_color", &color, theme)) - gui.screen.font_small_color = (color & 0x00FFFFFF); - - if(getColorForKey("font_console_color", &color, theme)) - gui.screen.font_console_color = (color & 0x00FFFFFF); - - } - -} - -/* -void freePixmap(pixmap_t *pm) -{ - if(pm) - { - if(pm->pixels) - { - free(pm->pixels); - pm->pixels=0; - } - } - pm = 0; -} -*/ + if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) ) + gui.infobox.pos.x = pixel; -const char *theme_name="Default"; + if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) ) + gui.infobox.pos.y = pixel; -int initGUI() -{ - int val, len; - char dirspec[256]; + if(getIntForKey("infobox_textmargin_h", &val, theme)) + gui.infobox.hborder = MIN( gui.infobox.width , val ); -#ifdef EMBED_THEME + if(getIntForKey("infobox_textmargin_v", &val, theme)) + gui.infobox.vborder = MIN( gui.infobox.height , val ); - config_file_t *embedded = &bootInfo->themeDefault; + if(getColorForKey("infobox_bgcolor", &color, theme)) + gui.infobox.bgcolor = (color & 0x00FFFFFF); - // build xml dictionary for embedded theme.plist - ParseXMLFile( (char *) __theme_plist, &embedded->dictionary); + if(getIntForKey("infobox_transparency", &alpha, theme)) + gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); - // parse display size parameters - if(getIntForKey("screen_width", &val, &bootInfo->themeDefault)) - screen_params[0] = val; - - if(getIntForKey("screen_height", &val, &bootInfo->themeDefault)) - screen_params[1] = val; -#else + /* + * Parse menu parameters + */ + if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) ) + gui.menu.width = pixel; + else + gui.menu.width = images[iMenuSelection].image->width; + if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) ) + gui.menu.height = pixel; + else + gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height; + + if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) ) + gui.menu.pos.x = pixel; + + if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) ) + gui.menu.pos.y = pixel; + + if(getIntForKey("menu_textmargin_h", &val, theme)) + gui.menu.hborder = MIN( gui.menu.width , val ); + + if(getIntForKey("menu_textmargin_v", &val, theme)) + gui.menu.vborder = MIN( gui.menu.height , val ); + + if(getColorForKey("menu_bgcolor", &color, theme)) + gui.menu.bgcolor = (color & 0x00FFFFFF); + + if(getIntForKey("menu_transparency", &alpha, theme)) + gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); + /* - * Return Error since GUI can't run when embedtheme is not used. + * Parse bootprompt parameters */ - - return 1; - -#endif + if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) ) + gui.bootprompt.width = pixel; - // Initalizing GUI strucutre. - bzero(&gui, sizeof(gui_t)); + if(getIntForKey("bootprompt_height", &val, theme)) + gui.bootprompt.height = MIN( screen_height , val ); + + if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) ) + gui.bootprompt.pos.x = pixel; + + if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) ) + gui.bootprompt.pos.y = pixel; + + if(getIntForKey("bootprompt_textmargin_h", &val, theme)) + gui.bootprompt.hborder = MIN( gui.bootprompt.width , val ); + + if(getIntForKey("bootprompt_textmargin_v", &val, theme)) + gui.bootprompt.vborder = MIN( gui.bootprompt.height , val ); + + if(getColorForKey("bootprompt_bgcolor", &color, theme)) + gui.bootprompt.bgcolor = (color & 0x00FFFFFF); + + if(getIntForKey("bootprompt_transparency", &alpha, theme)) + gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); + + if(getColorForKey("font_small_color", &color, theme)) + gui.screen.font_small_color = (color & 0x00FFFFFF); + + if(getColorForKey("font_console_color", &color, theme)) + gui.screen.font_console_color = (color & 0x00FFFFFF); +} + +int initGUI(void) +{ + int val; +#ifdef EMBED_THEME + config_file_t *config; - screen_params[2] = 32; - - // find theme name in boot.plist + config = &bootInfo->themeConfig; + if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) { + return 1; + } +#else + int len; + char dirspec[256]; + getValueForKey( "Theme", &theme_name, &len, &bootInfo->bootConfig ); - + if ((strlen(theme_name) + 27) > sizeof(dirspec)) { + return 1; + } sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name); - - if ( !loadConfigFile(dirspec, &bootInfo->themeConfig) ) - { - // parse display size parameters - if(getIntForKey("screen_width", &val, &bootInfo->themeConfig)) - screen_params[0] = val; - - if(getIntForKey("screen_height", &val, &bootInfo->themeConfig)) - screen_params[1] = val; + if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) { + return 1; } +#endif + // parse display size parameters + if (getIntForKey("screen_width", &val, &bootInfo->themeConfig)) { + screen_params[0] = val; + } + if (getIntForKey("screen_height", &val, &bootInfo->themeConfig)) { + screen_params[1] = val; + } + screen_params[2] = 32; + // Initalizing GUI strucutre. + bzero(&gui, sizeof(gui_t)); + // find best matching vesa mode for our requested width & height getGraphicModeParams(screen_params); // set our screen structure with the mode width & height gui.screen.width = screen_params[0]; gui.screen.height = screen_params[1]; - + // load graphics otherwise fail and return - if( !loadGraphics() ) - { - // set embedded theme.plist as defaults - loadThemeValues(&bootInfo->themeDefault, YES); - - // set user overides - loadThemeValues(&bootInfo->themeConfig, NO); - - colorFont(&font_small, gui.screen.font_small_color); + if (loadGraphics() == 0) { + loadThemeValues(&bootInfo->themeConfig, true); + colorFont(&font_small, gui.screen.font_small_color); colorFont(&font_console, gui.screen.font_console_color); - + // create the screen & window buffers - if( !createBackBuffer( &gui.screen ) ) - if( !createWindowBuffer( &gui.screen ) ) - if( !createWindowBuffer( &gui.devicelist ) ) - if( !createWindowBuffer( &gui.bootprompt ) ) - if( !createWindowBuffer( &gui.infobox ) ) - if( !createWindowBuffer( &gui.menu ) ) - { + if (createBackBuffer(&gui.screen) == 0) { + if (createWindowBuffer(&gui.screen) == 0) { + if (createWindowBuffer(&gui.devicelist) == 0) { + if (createWindowBuffer(&gui.bootprompt) == 0) { + if (createWindowBuffer(&gui.infobox) == 0) { + if (createWindowBuffer(&gui.menu) == 0) { drawBackground(); - // lets copy the screen into the back buffer memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); - setVideoMode( GRAPHICS_MODE, 0 ); - - gui.initialised = YES; - + gui.initialised = true; return 0; - } + } + } + } + } + } + } } - - // something went wrong return 1; } - void drawDeviceIcon(BVRef device, pixmap_t *buffer, position_t p) { int devicetype; @@ -680,10 +717,10 @@ if((start+i) == selection) { if(param->flags & kBVFlagNativeBoot) - infoMenuNativeBoot = YES; + infoMenuNativeBoot = true; else { - infoMenuNativeBoot = NO; + infoMenuNativeBoot = false; if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) infoMenuSelection = 0; } @@ -729,7 +766,7 @@ if( end < gDeviceCount - 1 ) blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) ); - gui.redraw = YES; + gui.redraw = true; updateVRAM(); @@ -742,10 +779,10 @@ prompt_pos=0; - if( gui.bootprompt.draw == YES ) + if( gui.bootprompt.draw == true ) { - gui.bootprompt.draw = NO; - gui.redraw = YES; + gui.bootprompt.draw = false; + gui.redraw = true; // this causes extra frames to be drawn //updateVRAM(); } @@ -784,9 +821,9 @@ drawStr( prompt+offset, &font_console, gui.bootprompt.pixmap, p_prompt); - gui.menu.draw = NO; - gui.bootprompt.draw = YES; - gui.redraw = YES; + gui.menu.draw = false; + gui.bootprompt.draw = true; + gui.redraw = true; updateVRAM(); @@ -851,7 +888,7 @@ if (gui.redraw) { memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); - gui.redraw = NO; + gui.redraw = false; } } @@ -879,8 +916,7 @@ struct putc_info pi; - if( formattedtext = (char *) malloc(1024) ) - { + if ((formattedtext = malloc(1024)) != NULL) { // format the text va_start(ap, fmt); pi.str = formattedtext; @@ -965,8 +1001,7 @@ struct putc_info pi; - if( formattedtext = (char *) malloc(1024) ) - { + if ((formattedtext = malloc(1024)) != NULL) { // format the text va_start(ap, fmt); pi.str = formattedtext; @@ -1053,8 +1088,7 @@ position_t origin, cursor, bounds; font_t *font = &font_console; - if( formattedtext = (char *) malloc(1024) ) - { + if ((formattedtext = malloc(1024)) != NULL) { // format the text pi.str = formattedtext; pi.last_str = 0; @@ -1079,7 +1113,7 @@ cursor.y += font->height; if ( cursor.y > bounds.y ) { - gui.redraw = YES; + gui.redraw = true; updateVRAM(); cursor.y = window->vborder; } @@ -1105,7 +1139,7 @@ // check y pos and reset to origin.y if ( cursor.y > ( bounds.y + font->chars[0]->height) ) { - gui.redraw = YES; + gui.redraw = true; updateVRAM(); cursor.y = window->vborder; } @@ -1191,7 +1225,7 @@ int start = 0, end = 0, count = 0, space = 0; - BOOL monospaced = NO; + bool monospaced = false; font->height = data->image->height; @@ -1223,7 +1257,7 @@ // check if font is monospaced if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) - monospaced = YES; + monospaced = true; font->width = font->chars[count]->width; @@ -1268,69 +1302,6 @@ } } -int loadThemeImage(image) -{ - char dirspec[256]; - sprintf(dirspec,"/Extra/Themes/%s/%s", theme_name, image); - if ((loadPixmapFromPng(dirspec, images[imageCnt].image)) == 1 ) - return 1; - dirspec[0] = '\0'; - sprintf(dirspec,"bt(0,0)/Extra/Themes/%s/%s", theme_name, image); - return loadPixmapFromPng(dirspec, images[imageCnt].image); -} - -int loadGraphics() -{ - int i; - - for( i=0; i < sizeof(images) / sizeof(images[0]); i++) - { - // create pixmap_t buffer for each image - images[i].image = malloc(sizeof(pixmap_t)); - } - - LOADPNG(background); - LOADPNG(logo); - - LOADPNG(device_generic); - LOADPNG(device_hfsplus); - LOADPNG(device_ext3); - LOADPNG(device_fat16); - LOADPNG(device_fat32); - LOADPNG(device_ntfs); - LOADPNG(device_cdrom); - LOADPNG(device_selection); - LOADPNG(device_scroll_prev); - LOADPNG(device_scroll_next); - - LOADPNG(menu_boot); - LOADPNG(menu_verbose); - LOADPNG(menu_ignore_caches); - LOADPNG(menu_single_user); - LOADPNG(menu_memory_info); - LOADPNG(menu_video_info); - LOADPNG(menu_help); - LOADPNG(menu_verbose_disabled); - LOADPNG(menu_ignore_caches_disabled); - LOADPNG(menu_single_user_disabled); - LOADPNG(menu_selection); - - LOADPNG(progress_bar); - LOADPNG(progress_bar_background); - - LOADPNG(text_scroll_prev); - LOADPNG(text_scroll_next); - - LOADPNG(font_console); - LOADPNG(font_small); - - initFont( &font_console, &images[iFontConsole]); - initFont( &font_small, &images[iFontSmall]); - - return 0; - -} - void makeRoundedCorners(pixmap_t *p) { int x,y; @@ -1464,9 +1435,9 @@ blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) ); } - gui.bootprompt.draw = NO; - gui.infobox.draw = YES; - gui.redraw = YES; + gui.bootprompt.draw = false; + gui.infobox.draw = true; + gui.redraw = true; updateVRAM(); @@ -1482,8 +1453,8 @@ if( key == kEscapeKey || key == 'q' || key == 'Q') { - gui.infobox.draw = NO; - gui.redraw = YES; + gui.infobox.draw = false; + gui.redraw = true; updateVRAM(); break; } @@ -1602,14 +1573,14 @@ } - gui.redraw = YES; + gui.redraw = true; } int drawInfoMenu() { drawInfoMenuItems(); - gui.menu.draw = YES; + gui.menu.draw = true; updateVRAM(); @@ -1634,8 +1605,8 @@ } else { - gui.menu.draw = NO; - gui.redraw = YES; + gui.menu.draw = false; + gui.redraw = true; updateVRAM(); @@ -1679,121 +1650,101 @@ uint16_t bootImageWidth = 0; uint16_t bootImageHeight = 0; - uint8_t *bootImageData = NULL; +static bool usePngImage = true; -BOOL usePngImage = YES; - //========================================================================== // loadBootGraphics - -void loadBootGraphics() +static void loadBootGraphics(void) { - char dirspec[256]; + if (bootImageData != NULL) { + return; + } - sprintf(dirspec,"/Extra/Themes/%s/boot.png", theme_name); - if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) - { - dirspec[0] = '\0'; - sprintf(dirspec,"bt(0,0)/Extra/Themes/%s/boot.png", theme_name); - if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) #ifdef EMBED_THEME - if((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, - &bootImageHeight, &bootImageData)) != 0) -#endif - usePngImage = NO; + if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0) { + usePngImage = false; } +#else + char dirspec[256]; + + if ((strlen(theme_name) + 24) > sizeof(dirspec)) { + usePngImage = false; + return; + } + sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name); + if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) { + usePngImage = false; + } +#endif } //========================================================================== // drawBootGraphics - -void drawBootGraphics() +void drawBootGraphics(void) { int pos; int length; const char *dummyVal; - BOOL legacy_logo; + bool legacy_logo; uint16_t x, y; - if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) - usePngImage = NO; - - else if (bootImageData == NULL) + if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->bootConfig) && legacy_logo) { + usePngImage = false; + } else if (bootImageData == NULL) { loadBootGraphics(); - + } + // parse screen size parameters - if(getIntForKey("boot_width", &pos, &bootInfo->themeConfig)) + if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig)) { screen_params[0] = pos; - else + } else { screen_params[0] = DEFAULT_SCREEN_WIDTH; - - if(getIntForKey("boot_height", &pos, &bootInfo->themeConfig)) + } + if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig)) { screen_params[1] = pos; - else + } else { screen_params[1] = DEFAULT_SCREEN_HEIGHT; - + } screen_params[2] = 32; - + gui.screen.width = screen_params[0]; gui.screen.height = screen_params[1]; - + // find best matching vesa mode for our requested width & height getGraphicModeParams(screen_params); - setVideoMode( GRAPHICS_MODE, 0 ); - - if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) - drawCheckerBoard(); - else + setVideoMode(GRAPHICS_MODE, 0); + + if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->bootConfig)) { + drawCheckerBoard(); + } else { // Fill the background to 75% grey (same as BootX). - drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01 ); - - if ( (bootImageData) && (usePngImage) ) - { - x = ( screen_params[0] - MIN( bootImageWidth, screen_params[0] ) ) / 2; - y = ( screen_params[1] - MIN( bootImageHeight, screen_params[1] ) ) / 2; - + drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01); + } + if ((bootImageData) && (usePngImage)) { + x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2; + y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2; + // Draw the image in the center of the display. blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData); - } else { - uint8_t *appleBootPict; bootImageData = NULL; bootImageWidth = kAppleBootWidth; bootImageHeight = kAppleBootHeight; - + // Prepare the data for the default Apple boot image. - appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, - bootImageWidth * bootImageHeight); - if (appleBootPict) - { + appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight); + if (appleBootPict) { convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData); - if (bootImageData) - { - x = ( screen_params[0] - MIN( kAppleBootWidth, screen_params[0] ) ) / 2; - y = ( screen_params[1] - MIN( kAppleBootHeight, screen_params[1] ) ) / 2; - - drawDataRectangle( x, y, kAppleBootWidth, kAppleBootHeight, bootImageData ); + if (bootImageData) { + x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2; + y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2; + drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData); free(bootImageData); } free(appleBootPict); } } - - return; } - -BOOL testForQemu() -{ - char *buffer = getVBEInfoString(); - char qemutext[] = "Bochs/Plex86"; - int i=0; - for(;imm_mod_end - ramdisk_module->mm_mod_start); - printf("\nalias: %s", (gRAMDiskBTAliased == 1) ? "enabled" : "disabled"); + printf("\nalias: %s", gRAMDiskBTAliased ? "enabled" : "disabled"); // Display ramdisk information if available. @@ -224,4 +221,4 @@ getc(); setActiveDisplayPage(0); } -} \ No newline at end of file +} Index: trunk/i386/boot2/options.c =================================================================== --- trunk/i386/boot2/options.c (revision 22) +++ trunk/i386/boot2/options.c (revision 23) @@ -27,11 +27,10 @@ #include "fdisk.h" #include "ramdisk.h" #include "gui.h" -#ifdef EMBED_THEME #include "embedded.h" -#endif +#include "pci.h" -int shouldboot=0; +static bool shouldboot = false; extern int multiboot_timeout; extern int multiboot_timeout_set; @@ -82,12 +81,12 @@ * characters was F8. */ -static BOOL flushKeyboardBuffer() +static bool flushKeyboardBuffer(void) { - BOOL status = FALSE; + bool status = false; while ( readKeyboardStatus() ) { - if (bgetc() == 0x4200) status = TRUE; + if (bgetc() == 0x4200) status = true; } return status; } @@ -112,7 +111,7 @@ position_t p = pos( gui.screen.width / 2 + 1 , ( gui.devicelist.pos.y + 3 ) + ( ( gui.devicelist.height - gui.devicelist.iconspacing ) / 2 ) ); char dummy[80]; - getBootVolumeDescription( gBootVolume, dummy, 80, YES ); + getBootVolumeDescription( gBootVolume, dummy, 80, true ); drawDeviceIcon( gBootVolume, gui.screen.pixmap, p ); drawStrCenteredAt( (char *) msg, &font_small, gui.screen.pixmap, gui.countdown.pos ); @@ -160,7 +159,7 @@ if( bootArgs->Video.v_display == GRAPHICS_MODE ) { drawProgressBar( gui.screen.pixmap, 100, gui.progressbar.pos , ( multi * 100 / multi_buff ) ); - gui.redraw = YES; + gui.redraw = true; updateVRAM(); } @@ -179,47 +178,45 @@ static char booterCommand[BOOT_STRING_LEN]; static char booterParam[BOOT_STRING_LEN]; -static void clearBootArgs() +static void clearBootArgs(void) { - gBootArgsPtr = gBootArgs; - memset( gBootArgs, '\0', BOOT_STRING_LEN ); + gBootArgsPtr = gBootArgs; + memset(gBootArgs, '\0', BOOT_STRING_LEN); - if( bootArgs->Video.v_display == GRAPHICS_MODE ) + if (bootArgs->Video.v_display == GRAPHICS_MODE) { clearGraphicBootPrompt(); - + } } //========================================================================== -static void showBootPrompt( int row, BOOL visible ) +static void showBootPrompt(int row, bool visible) { - extern char bootPrompt[]; - extern char bootRescanPrompt[]; + extern char bootPrompt[]; + extern char bootRescanPrompt[]; - if( bootArgs->Video.v_display == VGA_TEXT_MODE ) - { + if( bootArgs->Video.v_display == VGA_TEXT_MODE ) { changeCursor( 0, row, kCursorTypeUnderline, 0 ); clearScreenRows( row, kScreenLastRow ); - } + } - clearBootArgs(); + clearBootArgs(); - if ( visible ) - { - if( bootArgs->Video.v_display == VGA_TEXT_MODE ) - if (gEnableCDROMRescan) + if (visible) { + if (bootArgs->Video.v_display == VGA_TEXT_MODE) { + if (gEnableCDROMRescan) { printf( bootRescanPrompt ); - else + } else { printf( bootPrompt ); - } - else - { - if( bootArgs->Video.v_display == GRAPHICS_MODE ) + } + } + } else { + if (bootArgs->Video.v_display == GRAPHICS_MODE) { clearGraphicBootPrompt(); - else + } else { printf("Press Enter to start up the foreign OS. "); - - } + } + } } //========================================================================== @@ -419,37 +416,37 @@ res = updateInfoMenu(key); if ( res == CLOSE_INFO_MENU ) - gui.menu.draw = NO; + gui.menu.draw = false; else { shouldboot = ( res != DO_NOT_BOOT ); if ( shouldboot ) - gui.menu.draw = NO; + gui.menu.draw = false; switch (res) { case BOOT_NORMAL: - gVerboseMode = NO; + gVerboseMode = false; gBootMode = kBootModeNormal; break; case BOOT_VERBOSE: - gVerboseMode = YES; + gVerboseMode = true; gBootMode = kBootModeNormal; *gBootArgsPtr++ = '-'; *gBootArgsPtr++ = 'v'; break; case BOOT_IGNORECACHE: - gVerboseMode = NO; + gVerboseMode = false; gBootMode = kBootModeNormal; *gBootArgsPtr++ = '-'; *gBootArgsPtr++ = 'f'; break; case BOOT_SINGLEUSER: - gVerboseMode = YES; + gVerboseMode = true; gBootMode = kBootModeNormal; *gBootArgsPtr++ = '-'; *gBootArgsPtr++ = 's'; @@ -653,454 +650,413 @@ } //========================================================================== -extern void lspci(const char *booterParam); -int -getBootOptions(BOOL firstRun) +void lspci(void) { - int i; - int key; - int nextRow; - int timeout; - int bvCount; - BVRef bvr; - BVRef menuBVR; - BOOL showPrompt, newShowPrompt, isCDROM; + if (bootArgs->Video.v_display == VGA_TEXT_MODE) { + setActiveDisplayPage(1); + clearScreenRows(0, 24); + setCursorPosition(0, 0, 1); + } - // Initialize default menu selection entry. + dump_pci_dt(root_pci_dev->children); + + printf("(Press a key to continue...)"); + getc(); + + if (bootArgs->Video.v_display == VGA_TEXT_MODE) { + setActiveDisplayPage(0); + } +} + +//========================================================================== + +int getBootOptions(bool firstRun) +{ + int i; + int key; + int nextRow; + int timeout; + int bvCount; + BVRef bvr; + BVRef menuBVR; + bool showPrompt, newShowPrompt, isCDROM; + + // Initialize default menu selection entry. gBootVolume = menuBVR = selectBootVolume(bvChain); - if ( biosDevIsCDROM(gBIOSDev) ) - isCDROM = TRUE; - else - isCDROM = FALSE; + if (biosDevIsCDROM(gBIOSDev)) { + isCDROM = true; + } else { + isCDROM = false; + } // ensure we're in graphics mode if gui is setup - if(gui.initialised == YES) - if( bootArgs->Video.v_display == VGA_TEXT_MODE ) - setVideoMode( GRAPHICS_MODE, 0 ); - - // Allow user to override default timeout. - if (multiboot_timeout_set) - timeout=multiboot_timeout; - else if ( getIntForKey(kTimeoutKey, &timeout, &bootInfo->bootConfig) == NO ) - { - /* If there is no timeout key in the file use the default timeout - which is different for CDs vs. hard disks. However, if not booting - a CD and no config file could be loaded set the timeout - to zero which causes the menu to display immediately. - This way, if no partitions can be found, that is the disk is unpartitioned - or simply cannot be read) then an empty menu is displayed. - If some partitions are found, for example a Windows partition, then - these will be displayed in the menu as foreign partitions. - */ - if ( isCDROM ) - timeout = kCDBootTimeout; - else - timeout = sysConfigValid?kBootTimeout:0; - } - - if (timeout < 0) + if (gui.initialised) { + if (bootArgs->Video.v_display == VGA_TEXT_MODE) { + setVideoMode(GRAPHICS_MODE, 0); + } + } + + // Allow user to override default timeout. + if (multiboot_timeout_set) { + timeout = multiboot_timeout; + } else if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->bootConfig)) { + /* If there is no timeout key in the file use the default timeout + which is different for CDs vs. hard disks. However, if not booting + a CD and no config file could be loaded set the timeout + to zero which causes the menu to display immediately. + This way, if no partitions can be found, that is the disk is unpartitioned + or simply cannot be read) then an empty menu is displayed. + If some partitions are found, for example a Windows partition, then + these will be displayed in the menu as foreign partitions. + */ + if (isCDROM) { + timeout = kCDBootTimeout; + } else { + timeout = sysConfigValid ? kBootTimeout : 0; + } + } + + if (timeout < 0) { gBootMode |= kBootModeQuiet; + } - // If the user is holding down a modifier key, - // enter safe mode. - if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 ) { - gBootMode |= kBootModeSafe; - } + // If the user is holding down a modifier key, enter safe mode. + if ((readKeyboardShiftFlags() & 0x0F) != 0) { + gBootMode |= kBootModeSafe; + } - // If user typed F8, abort quiet mode, - // and display the menu. + // If user typed F8, abort quiet mode, and display the menu. { - int f8press = FALSE, spress = FALSE, vpress = FALSE, key; - while ( readKeyboardStatus() ) { + bool f8press = false, spress = false, vpress = false; + int key; + while (readKeyboardStatus()) { key = bgetc (); - if (key == 0x4200) f8press = TRUE; - if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = TRUE; - if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = TRUE; - } - if (f8press) - { + if (key == 0x4200) f8press = true; + if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true; + if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true; + } + if (f8press) { gBootMode &= ~kBootModeQuiet; timeout = 0; } - if ((gBootMode & kBootModeQuiet) && firstRun && vpress && (gBootArgsPtr + 3 < gBootArgsEnd)) - { + if ((gBootMode & kBootModeQuiet) && firstRun && vpress && (gBootArgsPtr + 3 < gBootArgsEnd)) { *(gBootArgsPtr++) = ' '; *(gBootArgsPtr++) = '-'; *(gBootArgsPtr++) = 'v'; } - if ((gBootMode & kBootModeQuiet) && firstRun && spress && (gBootArgsPtr + 3 < gBootArgsEnd)) - { + if ((gBootMode & kBootModeQuiet) && firstRun && spress && (gBootArgsPtr + 3 < gBootArgsEnd)) { *(gBootArgsPtr++) = ' '; *(gBootArgsPtr++) = '-'; - *(gBootArgsPtr++) = 's'; + *(gBootArgsPtr++) = 's'; } - } - clearBootArgs(); - if( bootArgs->Video.v_display == VGA_TEXT_MODE ) - { - setCursorPosition( 0, 0, 0 ); - clearScreenRows( 0, kScreenLastRow ); - - if ( ! ( gBootMode & kBootModeQuiet ) ) - { + if (bootArgs->Video.v_display == VGA_TEXT_MODE) { + setCursorPosition(0, 0, 0); + clearScreenRows(0, kScreenLastRow); + if (!(gBootMode & kBootModeQuiet)) { // Display banner and show hardware info. - printf( bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024 ); - printf( getVBEInfoString() ); + printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024); + printf(getVBEInfoString()); } - - changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 ); + changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0); verbose("Scanning device %x...", gBIOSDev); - } - // When booting from CD, default to hard - // drive boot when possible. - - if ( isCDROM && firstRun ) - { - const char *val; - char *prompt; + // When booting from CD, default to hard drive boot when possible. + if (isCDROM && firstRun) { + const char *val; + char *prompt; char *name; - int cnt; - int optionKey; + int cnt; + int optionKey; - if (getValueForKey( kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig )) { - cnt += 1; - prompt = malloc(cnt); - strlcpy(prompt, val, cnt); - } else { + if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->bootConfig)) { + cnt += 1; + prompt = malloc(cnt); + strlcpy(prompt, val, cnt); + } else { name = malloc(80); - getBootVolumeDescription( gBootVolume, name, 80, NO ); + getBootVolumeDescription(gBootVolume, name, 80, false); prompt = malloc(256); sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name); free(name); cnt = 0; } - if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig )) - { - // The key specified is a special key. - } else if (getValueForKey( kCDROMOptionKey, &val, &cnt, &bootInfo->bootConfig ) && cnt >= 1) { - optionKey = val[0]; - } else { - // Default to F8. - optionKey = 0x4200; - } + if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->bootConfig )) { + // The key specified is a special key. + } else if (getValueForKey( kCDROMOptionKey, &val, &cnt, &bootInfo->bootConfig ) && cnt >= 1) { + optionKey = val[0]; + } else { + // Default to F8. + optionKey = 0x4200; + } - // If the timeout is zero then it must have been set above due to the - // early catch of F8 which means the user wants to set boot options - // which we ought to interpret as meaning he wants to boot the CD. - if(timeout != 0) - key = countdown(prompt, kMenuTopRow, timeout); - else - key = optionKey; + // If the timeout is zero then it must have been set above due to the + // early catch of F8 which means the user wants to set boot options + // which we ought to interpret as meaning he wants to boot the CD. + if (timeout != 0) { + key = countdown(prompt, kMenuTopRow, timeout); + } else { + key = optionKey; + } - if (cnt) - free(prompt); - + if (cnt) { + free(prompt); + } + clearScreenRows( kMenuTopRow, kMenuTopRow + 2 ); // Hit the option key ? - if ( key == optionKey ) - { + if (key == optionKey) { gBootMode &= ~kBootModeQuiet; timeout = 0; - } else { - key = key & 0xFF; // Try booting hard disk if user pressed 'h' - if ( biosDevIsCDROM(gBIOSDev) && key == 'h' ) - { + if (biosDevIsCDROM(gBIOSDev) && key == 'h') { BVRef bvr; // Look at partitions hosting OS X other than the CD-ROM - for ( bvr = bvChain; bvr; bvr = bvr->next ) - if ( (bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev ) + for (bvr = bvChain; bvr; bvr=bvr->next) { + if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) { gBootVolume = bvr; + } + } } - goto done; } } - if ( gBootMode & kBootModeQuiet ) - { - // No input allowed from user. - goto done; - } + if (gBootMode & kBootModeQuiet) { + // No input allowed from user. + goto done; + } - if ( firstRun && ( timeout > 0 ) && - ( countdown("Press any key to enter startup options.", - kMenuTopRow, timeout) == 0 ) ) - { - // If the user is holding down a modifier key, - // enter safe mode. - if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 ) { - gBootMode |= kBootModeSafe; - } - goto done; - } + if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) { + // If the user is holding down a modifier key, + // enter safe mode. + if ((readKeyboardShiftFlags() & 0x0F) != 0) { + gBootMode |= kBootModeSafe; + } + goto done; + } - if ( gDeviceCount ) - { - // Allocate memory for an array of menu items. - menuItems = (MenuItem *) malloc( sizeof(MenuItem) * gDeviceCount ); - if ( menuItems == NULL ) goto done; + if (gDeviceCount) { + // Allocate memory for an array of menu items. + menuItems = malloc(sizeof(MenuItem) * gDeviceCount); + if (menuItems == NULL) { + goto done; + } // Associate a menu item for each BVRef. - for ( bvr = bvChain, i = gDeviceCount - 1, selectIndex = 0; - bvr; bvr = bvr->next) - if (bvr->visible) - { - getBootVolumeDescription( bvr, menuItems[i].name, 80, YES ); + for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next) { + if (bvr->visible) { + getBootVolumeDescription(bvr, menuItems[i].name, 80, true); menuItems[i].param = (void *) bvr; - if ( bvr == menuBVR ) selectIndex = i; + if (bvr == menuBVR) { + selectIndex = i; + } i--; } - + } } - if( bootArgs->Video.v_display == GRAPHICS_MODE ) - { + if (bootArgs->Video.v_display == GRAPHICS_MODE) { // redraw the background buffer drawBackground(); - gui.devicelist.draw = YES; - gui.redraw = YES; - if ( ! ( gBootMode & kBootModeQuiet ) ) + gui.devicelist.draw = true; + gui.redraw = true; + if (!(gBootMode & kBootModeQuiet)) { + bool showBootBanner = true; + + // Check if "Boot Banner"=N switch is present in config file. + getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->bootConfig); + if (showBootBanner) { + // Display banner and show hardware info. + gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024); + } - { - BOOL showBootBanner = YES; - - // Check if "Boot Banner"=N switch is present in config file. - getBoolForKey( kBootBannerKey, &showBootBanner, &bootInfo->bootConfig); - - if ( showBootBanner ) - { - // Display banner and show hardware info. - gprintf( &gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024 ); - } - // redraw background - memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); + memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4); } } else { - // Clear screen and hide the blinking cursor. - clearScreenRows( kMenuTopRow, kMenuTopRow + 2 ); - changeCursor( 0, kMenuTopRow, kCursorTypeHidden, 0 ); - } + // Clear screen and hide the blinking cursor. + clearScreenRows(kMenuTopRow, kMenuTopRow + 2); + changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0); + } - nextRow = kMenuTopRow; - showPrompt = YES; - - if ( gDeviceCount ) - { - if( bootArgs->Video.v_display == VGA_TEXT_MODE ) - printf("Use \30\31 keys to select the startup volume."); - - showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems ); - nextRow += min( gDeviceCount, kMenuMaxItems ) + 3; - } + nextRow = kMenuTopRow; + showPrompt = true; + if (gDeviceCount) { + if( bootArgs->Video.v_display == VGA_TEXT_MODE ) { + printf("Use \30\31 keys to select the startup volume."); + } + showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems ); + nextRow += min( gDeviceCount, kMenuMaxItems ) + 3; + } + // Show the boot prompt. showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); showBootPrompt( nextRow, showPrompt ); - do { - - if( bootArgs->Video.v_display == GRAPHICS_MODE ) - { - // redraw background - memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); - - // reset cursor co-ords - gui.debug.cursor = pos( gui.screen.width - 160 , 10 ); - - } - - key = getc(); + do { + if (bootArgs->Video.v_display == GRAPHICS_MODE) { + // redraw background + memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); + // reset cursor co-ords + gui.debug.cursor = pos( gui.screen.width - 160 , 10 ); + } + key = getc(); + updateMenu( key, (void **) &menuBVR ); + newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); - updateMenu( key, (void **) &menuBVR ); - - newShowPrompt = (gDeviceCount == 0) || - (menuBVR->flags & kBVFlagNativeBoot); - - if ( newShowPrompt != showPrompt ) - { - showPrompt = newShowPrompt; - showBootPrompt( nextRow, showPrompt ); - } - - if ( showPrompt ) - updateBootArgs( key ); - - switch ( key ) - { - case kReturnKey: + if (newShowPrompt != showPrompt) { + showPrompt = newShowPrompt; + showBootPrompt( nextRow, showPrompt ); + } - if ( gui.menu.draw ) - { - key=0; - break; - } + if (showPrompt) { + updateBootArgs(key); + } - if ( *gBootArgs == '?' ) - { - char * argPtr = gBootArgs; + switch (key) { + case kReturnKey: + if (gui.menu.draw) { + key=0; + break; + } + if (*gBootArgs == '?') { + char * argPtr = gBootArgs; - // Skip the leading "?" character. - argPtr++; - getNextArg(&argPtr, booterCommand); - getNextArg(&argPtr, booterParam); - - /* - * TODO: this needs to be refactored. - */ - - if ( strcmp( booterCommand, "video" ) == 0 ) - { - if( bootArgs->Video.v_display == GRAPHICS_MODE ) - showInfoBox( getVBEInfoString(), getVBEModeInfoString() ); - else - printVBEModeInfo(); - } - - else if ( strcmp( booterCommand, "memory" ) == 0 ) - if( bootArgs->Video.v_display == GRAPHICS_MODE ) - showInfoBox( "Memory Map", getMemoryInfoString() ); - else - printMemoryInfo(); - - else if ( strcmp( booterCommand, "lspci" ) == 0 ) - lspci(booterParam); - - else if ( strcmp( booterCommand, "more" ) == 0 ) - showTextFile(booterParam); + // Skip the leading "?" character. + argPtr++; + getNextArg(&argPtr, booterCommand); + getNextArg(&argPtr, booterParam); - else if ( strcmp( booterCommand, "rd" ) == 0 ) - processRAMDiskCommand(&argPtr, booterParam); + /* + * TODO: this needs to be refactored. + */ + if (strcmp( booterCommand, "video" ) == 0) { + if (bootArgs->Video.v_display == GRAPHICS_MODE) { + showInfoBox(getVBEInfoString(), getVBEModeInfoString()); + } else { + printVBEModeInfo(); + } + } else if ( strcmp( booterCommand, "memory" ) == 0) { + if (bootArgs->Video.v_display == GRAPHICS_MODE ) { + showInfoBox("Memory Map", getMemoryInfoString()); + } else { + printMemoryInfo(); + } + } else if (strcmp(booterCommand, "lspci") == 0) { + lspci(); + } else if (strcmp(booterCommand, "more") == 0) { + showTextFile(booterParam); + } else if (strcmp(booterCommand, "rd") == 0) { + processRAMDiskCommand(&argPtr, booterParam); + } else if (strcmp(booterCommand, "norescan") == 0) { + if (gEnableCDROMRescan) { + gEnableCDROMRescan = false; + break; + } + } else { + showHelp(); + } + key = 0; + showBootPrompt(nextRow, showPrompt); + break; + } + gBootVolume = menuBVR; + setRootVolume(menuBVR); + gBIOSDev = menuBVR->biosdev; + break; - else if ( strcmp( booterCommand, "norescan" ) == 0 ) - { - if (gEnableCDROMRescan) - { - gEnableCDROMRescan = FALSE; - break; - } - } + case kEscapeKey: + clearBootArgs(); + break; - else - { - showHelp(); - } + case kF5Key: + // New behavior: + // Clear gBootVolume to restart the loop + // if the user enabled rescanning the optical drive. + // Otherwise boot the default boot volume. + if (gEnableCDROMRescan) { + gBootVolume = NULL; + clearBootArgs(); + } + break; - key = 0; - showBootPrompt( nextRow, showPrompt ); - break; - } + case kF10Key: + gScanSingleDrive = false; + scanDisks(gBIOSDev, &bvCount); + gBootVolume = NULL; + clearBootArgs(); + break; - gBootVolume = menuBVR; - setRootVolume(menuBVR); - gBIOSDev = menuBVR->biosdev; - break; + case kTabKey: + // New behavior: + // Switch between text & graphic interfaces + // Only Permitted if started in graphics interface + if (useGUI) { + if (bootArgs->Video.v_display == GRAPHICS_MODE) { + setVideoMode(VGA_TEXT_MODE, 0); - case kEscapeKey: - clearBootArgs(); - break; + setCursorPosition(0, 0, 0); + clearScreenRows(0, kScreenLastRow); - case kF5Key: - // New behavior: - // Clear gBootVolume to restart the loop - // if the user enabled rescanning the optical drive. - // Otherwise boot the default boot volume. - if (gEnableCDROMRescan) - { - gBootVolume = NULL; - clearBootArgs(); - } - break; + // Display banner and show hardware info. + printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024); + printf(getVBEInfoString()); - case kF10Key: - gScanSingleDrive = FALSE; - scanDisks(gBIOSDev, &bvCount); - gBootVolume = NULL; - clearBootArgs(); - break; + clearScreenRows(kMenuTopRow, kMenuTopRow + 2); + changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0); - case kTabKey: - // New behavior: - // Switch between text & graphic interfaces - // Only Permitted if started in graphics interface - if (useGUI) - { - if (bootArgs->Video.v_display == GRAPHICS_MODE) - { - setVideoMode( VGA_TEXT_MODE, 0 ); - - setCursorPosition( 0, 0, 0 ); - clearScreenRows( 0, kScreenLastRow ); - - // Display banner and show hardware info. - printf( bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024 ); - printf( getVBEInfoString() ); - - clearScreenRows( kMenuTopRow, kMenuTopRow + 2 ); - changeCursor( 0, kMenuTopRow, kCursorTypeHidden, 0 ); - - nextRow = kMenuTopRow; - showPrompt = YES; - - if ( gDeviceCount ) - { - printf("Use \30\31 keys to select the startup volume."); - showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems ); - nextRow += min( gDeviceCount, kMenuMaxItems ) + 3; - } - - showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); - showBootPrompt( nextRow, showPrompt ); - - //changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 ); - - } - else - { - gui.redraw = YES; - setVideoMode( GRAPHICS_MODE, 0 ); - updateVRAM(); - } - } - key = 0; - break; + nextRow = kMenuTopRow; + showPrompt = true; - default: - key = 0; - } - } - while ( 0 == key ); + if (gDeviceCount) { + printf("Use \30\31 keys to select the startup volume."); + showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems); + nextRow += min(gDeviceCount, kMenuMaxItems) + 3; + } -done: - firstRun = NO; + showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); + showBootPrompt(nextRow, showPrompt); + //changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 ); + } else { + gui.redraw = true; + setVideoMode(GRAPHICS_MODE, 0); + updateVRAM(); + } + } + key = 0; + break; - if( bootArgs->Video.v_display == VGA_TEXT_MODE ) - { - clearScreenRows( kMenuTopRow, kScreenLastRow ); - changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 ); - } + default: + key = 0; + break; + } + } while (0 == key); - shouldboot = NO; - gui.menu.draw = NO; - - if ( menuItems ) +done: + if (bootArgs->Video.v_display == VGA_TEXT_MODE) { + clearScreenRows(kMenuTopRow, kScreenLastRow); + changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0); + } + shouldboot = false; + gui.menu.draw = false; + if (menuItems) { free(menuItems); - - return 0; + menuItems = NULL; + } + return 0; } //========================================================================== @@ -1108,15 +1064,14 @@ extern unsigned char chainbootdev; extern unsigned char chainbootflag; -BOOL -copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP) +bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP) { int argLen = argName ? strlen(argName) : 0; int len = argLen + cnt + 1; // +1 to account for space if (len > *cntRemainingP) { error("Warning: boot arguments too long, truncating\n"); - return NO; + return false; } if (argName) { @@ -1132,13 +1087,12 @@ (*argP)++; *cntRemainingP -= len; - return YES; + return true; } // // Returns TRUE if an argument was copied, FALSE otherwise - -BOOL +bool processBootArgument( const char *argName, // The argument to search for const char *userString, // Typed-in boot arguments @@ -1151,17 +1105,17 @@ { const char *val; int cnt; - BOOL found = NO; + bool found = false; if (getValueForBootKey(userString, argName, &val, &cnt)) { // Don't copy; these values will be copied at the end of argument processing. - found = YES; + found = true; } else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) { // Don't copy; these values will be copied at the end of argument processing. - found = YES; + found = true; } else if (getValueForKey(argName, &val, &cnt, &bootInfo->bootConfig)) { copyArgument(argName, val, cnt, argP, cntRemainingP); - found = YES; + found = true; } if (found && foundVal) { strlcpy(foundVal, val, cnt+1); @@ -1183,11 +1137,11 @@ int cntRemaining; char * argP; char uuidStr[64]; - BOOL uuidSet = NO; + bool uuidSet = false; char * configKernelFlags; char * valueBuffer; - valueBuffer = (char *)malloc(VALUE_SIZE); + valueBuffer = malloc(VALUE_SIZE); skipblanks( &cp ); @@ -1221,7 +1175,7 @@ // Load config table specified by the user, or use the default. - if (getValueForBootKey( cp, "config", &val, &cnt ) == FALSE) { + if (!getValueForBootKey(cp, "config", &val, &cnt)) { val = 0; cnt = 0; } @@ -1239,15 +1193,15 @@ // overriding the kernel, which causes the kernelcache not // to be used. - gOverrideKernel = NO; + gOverrideKernel = false; if (( kernel = extractKernelName((char **)&cp) )) { strcpy( bootInfo->bootFile, kernel ); - gOverrideKernel = YES; + gOverrideKernel = true; } else { if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) { strlcpy( bootInfo->bootFile, val, cnt+1 ); if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) { - gOverrideKernel = YES; + gOverrideKernel = true; } } else { strcpy( bootInfo->bootFile, kDefaultKernel ); @@ -1258,18 +1212,18 @@ argP = bootArgs->CommandLine; // Get config table kernel flags, if not ignored. - if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) == TRUE || - getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig ) == FALSE) { + if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || + !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) { val = ""; cnt = 0; } - configKernelFlags = (char *)malloc(cnt + 1); + configKernelFlags = malloc(cnt + 1); strlcpy(configKernelFlags, val, cnt + 1); if (processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, 0)) { // boot-uuid was set either on the command-line // or in the config file. - uuidSet = YES; + uuidSet = true; } else { // @@ -1282,14 +1236,14 @@ { getValueForKey(kHelperRootUUIDKey, &val, &cnt, &bootInfo->helperConfig); copyArgument(kBootUUIDKey, val, cnt, &argP, &cntRemaining); - uuidSet = YES; + uuidSet = true; } } if (!uuidSet && gBootVolume->fs_getuuid && gBootVolume->fs_getuuid (gBootVolume, uuidStr) == 0) { verbose("Setting boot-uuid to: %s\n", uuidStr); copyArgument(kBootUUIDKey, uuidStr, strlen(uuidStr), &argP, &cntRemaining); - uuidSet = YES; + uuidSet = true; } } @@ -1381,60 +1335,24 @@ //========================================================================== // Load the help file and display the file contents on the screen. -void showHelp() +static void showTextBuffer(char *buf, int size) { -#define BOOT_HELP_PATH "bt(0,0)/Extra/BootHelp.txt" + char *bp; + int line; + int line_offset; + int c; -#ifdef EMBED_THEME - if( bootArgs->Video.v_display == GRAPHICS_MODE ) - { - showInfoBox( "Help. Press q to quit.\n" , (char *)BootHelp_txt ); + if (bootArgs->Video.v_display == GRAPHICS_MODE) { + showInfoBox( "Press q to quit\n",buf ); return; } -#endif - showTextFile(BOOT_HELP_PATH); -} -void showTextFile(const char * filename) -{ -#define MAX_TEXT_FILE_SIZE 65536 - - int fd; - int size; - int line; - int line_offset; - int c; - char fn[1024]; - - *fn = '\0'; - strcat(fn, filename); - - if ( (fd = open(fn, 0)) >= 0 ) - { - char * buffer; - char * bp; - - size = file_size(fd); - if (size > MAX_TEXT_FILE_SIZE) - size = MAX_TEXT_FILE_SIZE; - buffer = malloc( size + 1 ); - read(fd, buffer, size); - close(fd); - - if( bootArgs->Video.v_display == GRAPHICS_MODE ) - { - showInfoBox( "Help. Press q to quit.\n" , buffer ); - return; + bp = buf; + while (size-- > 0) { + if (*bp == '\n') { + *bp = '\0'; } - - bp = buffer; - while (size > 0) { - while (*bp != '\n') { - bp++; - size--; - } - *bp++ = '\0'; - size--; + bp++; } *bp = '\1'; line_offset = 0; @@ -1442,149 +1360,152 @@ setActiveDisplayPage(1); while (1) { - clearScreenRows(0, 24); - setCursorPosition(0, 0, 1); - bp = buffer; - for (line = 0; *bp != '\1' && line < line_offset; line++) { - while (*bp != '\0') bp++; - bp++; - } - for (line = 0; *bp != '\1' && line < 23; line++) { - setCursorPosition(0, line, 1); - printf("%s\n", bp); - while (*bp != '\0') bp++; - bp++; - } + clearScreenRows(0, 24); + setCursorPosition(0, 0, 1); + bp = buf; + for (line = 0; *bp != '\1' && line < line_offset; line++) { + while (*bp != '\0') { + bp++; + } + bp++; + } + for (line = 0; *bp != '\1' && line < 23; line++) { + setCursorPosition(0, line, 1); + printf("%s\n", bp); + while (*bp != '\0') { + bp++; + } + bp++; + } - setCursorPosition(0, 23, 1); - if (*bp == '\1') { - printf("[Type %sq or space to quit viewer]", - (line_offset > 0) ? "p for previous page, " : ""); - } else { - printf("[Type %s%sq to quit viewer]", - (line_offset > 0) ? "p for previous page, " : "", - (*bp != '\1') ? "space for next page, " : ""); - } + setCursorPosition(0, 23, 1); + if (*bp == '\1') { + printf("[Type %sq or space to quit viewer]", (line_offset > 0) ? "p for previous page, " : ""); + } else { + printf("[Type %s%sq to quit viewer]", (line_offset > 0) ? "p for previous page, " : "", (*bp != '\1') ? "space for next page, " : ""); + } - c = getc(); - if (c == 'q' || c == 'Q') { - break; - } - if ((c == 'p' || c == 'P') && line_offset > 0) { - line_offset -= 23; - } - if (c == ' ') { - if (*bp == '\1') { - break; - } else { - line_offset += 23; - } - } + c = getc(); + if (c == 'q' || c == 'Q') { + break; + } + if ((c == 'p' || c == 'P') && line_offset > 0) { + line_offset -= 23; + } + if (c == ' ') { + if (*bp == '\1') { + break; + } else { + line_offset += 23; + } + } } - - free(buffer); setActiveDisplayPage(0); - } - else - { - printf("\nFile not found: %s\n", fn); - sleep(2); - } } -static inline int isHexDigit(char ch) +void showHelp(void) { - return ('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'F') || ('a' <= ch && ch <= 'f'); + if (bootArgs->Video.v_display == GRAPHICS_MODE) { + showInfoBox("Help. Press q to quit.\n", (char *)BootHelp_txt); + } else { + showTextBuffer((char *)BootHelp_txt, BootHelp_txt_len); + } } +void showTextFile(const char * filename) +{ +#define MAX_TEXT_FILE_SIZE 65536 + char *buf; + int fd; + int size; + + if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) { + printf("\nFile not found: %s\n", filename); + sleep(2); + return; + } + + size = file_size(fd); + if (size > MAX_TEXT_FILE_SIZE) { + size = MAX_TEXT_FILE_SIZE; + } + buf = malloc(size); + read(fd, buf, size); + close(fd); + showTextBuffer(buf, size); + free(buf); +} + // This is a very simplistic prompting scheme that just grabs two hex characters // Eventually we need to do something more user-friendly like display a menu // based off of the Multiboot device list int selectAlternateBootDevice(int bootdevice) { - int digitsI = 0; - char digits[3] = {0,0,0}; - - // We've already printed the current boot device so user knows what it is - printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n"); - printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice); - int key = 0; - do { - key = getc(); - switch(key & kASCIIKeyMask) - { - case kBackspaceKey: - if(digitsI > 0) - { - int x, y, t; - getCursorPositionAndType(&x, &y, &t); - // Assume x is not 0; - x--; - setCursorPosition(x,y,0); // back up one char - // Overwrite with space without moving cursor position - putca(' ', 0x07, 1); - digitsI--; - } - else - { - // TODO: Beep or something - } - break; - case kReturnKey: - if(1) - { - digits[digitsI] = '\0'; - char *end; - int newbootdevice = strtol(digits, &end, 16); - if(end == digits && *end == '\0') // User entered empty string - { - printf("\nUsing default boot device %x\n", bootdevice); - key = 0; - } - else if(end != digits && *end == '\0') - { - bootdevice = newbootdevice; - printf("\n"); - key = 0; // We gots da boot device - } - else - { - printf("\nCouldn't parse. try again: "); - digitsI = 0; - } - } - break; - default: - if( isHexDigit(key & kASCIIKeyMask) && digitsI < 2 ) - { - putc(key & kASCIIKeyMask); - digits[digitsI++] = key & kASCIIKeyMask; - } - else - { - // TODO: Beep or something - } - }; - } while(key != 0); - return bootdevice; -} + int key; + int newbootdevice; + int digitsI = 0; + char *end; + char digits[3] = {0,0,0}; - -BOOL promptForRescanOption(void) -{ - int key; - BOOL result = FALSE; + // We've already printed the current boot device so user knows what it is + printf("Typical boot devices are 80 (First HD), 81 (Second HD)\n"); + printf("Enter two-digit hexadecimal boot device [%02x]: ", bootdevice); + do { + key = getc(); + switch (key & kASCIIKeyMask) { + case kBackspaceKey: + if (digitsI > 0) { + int x, y, t; + getCursorPositionAndType(&x, &y, &t); + // Assume x is not 0; + x--; + setCursorPosition(x,y,0); // back up one char + // Overwrite with space without moving cursor position + putca(' ', 0x07, 1); + digitsI--; + } else { + // TODO: Beep or something + } + break; - printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n"); - key = getc(); + case kReturnKey: + digits[digitsI] = '\0'; + newbootdevice = strtol(digits, &end, 16); + if (end == digits && *end == '\0') { + // User entered empty string + printf("\nUsing default boot device %x\n", bootdevice); + key = 0; + } else if(end != digits && *end == '\0') { + bootdevice = newbootdevice; + printf("\n"); + key = 0; // We gots da boot device + } else { + printf("\nCouldn't parse. try again: "); + digitsI = 0; + } + break; - switch ( key ) - { - case kReturnKey: - result = TRUE; - break; - } - - return result; -} \ No newline at end of file + default: + if (isxdigit(key & kASCIIKeyMask) && digitsI < 2) { + putc(key & kASCIIKeyMask); + digits[digitsI++] = key & kASCIIKeyMask; + } else { + // TODO: Beep or something + } + break; + }; + } while (key != 0); + + return bootdevice; +} + +bool promptForRescanOption(void) +{ + printf("\nWould you like to enable media rescan option?\nPress ENTER to enable or any key to skip.\n"); + if (getc() == kReturnKey) { + return true; + } else { + return false; + } +} Index: trunk/i386/boot2/Makefile =================================================================== --- trunk/i386/boot2/Makefile (revision 22) +++ trunk/i386/boot2/Makefile (revision 23) @@ -59,9 +59,9 @@ all: $(DIRS_NEEDED) boot embedtheme: CFLAGS += -DEMBED_THEME -embedtheme: art.h embedded.h all +embedtheme: art.h all -boot: machOconv $(OBJS) $(LIBDEP) +boot: machOconv embedded.h $(OBJS) $(LIBDEP) $(LD) -static -Wl,-preload -Wl,-segaddr,__INIT,$(BOOT2ADDR) \ -nostdlib -arch i386 -Wl,-segalign,20 \ -o $(SYMROOT)/boot.sys $(filter %.o,$^) $(LIBS) -lcc_kext Index: trunk/i386/libsa/libsa.h =================================================================== --- trunk/i386/libsa/libsa.h (revision 22) +++ trunk/i386/libsa/libsa.h (revision 23) @@ -30,8 +30,43 @@ #include #include #include +#include /* + * ctype stuff (aserebln) + */ +static inline int isupper(char c) +{ + return (c >= 'A' && c <= 'Z'); +} + +static inline int islower(char c) +{ + return (c >= 'a' && c <= 'z'); +} + +static inline int isalpha(char c) +{ + return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); +} + +static inline int isspace(char c) +{ + return (c == ' ' || c == '\t' || c == '\n' || c == '\12'); +} + +static inline int isdigit(char c) +{ + return (c >= '0' && c <= '9'); +} + +static inline int isxdigit(char c) +{ + return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); +} + + +/* * string.c */ #ifndef bcopy @@ -91,8 +126,9 @@ /* * zalloc.c */ -extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t)); -extern void * malloc(size_t size); +#define malloc(size) safe_malloc(size, __FILE__, __LINE__) +extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int)); +extern void * safe_malloc(size_t size,const char *file, int line); extern void free(void * start); extern void * realloc(void * ptr, size_t size); Index: trunk/i386/libsa/efi_tables.h =================================================================== --- trunk/i386/libsa/efi_tables.h (revision 22) +++ trunk/i386/libsa/efi_tables.h (revision 23) @@ -7,11 +7,10 @@ #include "efi.h" -uint32_t -crc32(uint32_t crc, const void *buf, size_t size); +uint32_t crc32(uint32_t crc, const void *buf, size_t size); void efi_guid_unparse_upper(EFI_GUID const *pGuid, char *out); -int efi_guid_is_null(EFI_GUID const *pGuid); +bool efi_guid_is_null(EFI_GUID const *pGuid); int efi_guid_compare(EFI_GUID const *pG1, EFI_GUID const *pG2); #endif //ndef _LIBSA_EFI_TABLES_H__ Index: trunk/i386/libsa/zalloc.c =================================================================== --- trunk/i386/libsa/zalloc.c (revision 22) +++ trunk/i386/libsa/zalloc.c (revision 23) @@ -48,7 +48,7 @@ static short availableNodes, allocedNodes, totalNodes; static char * zalloc_base; static char * zalloc_end; -static void (*zerror)(char *, size_t); +static void (*zerror)(char *, size_t, const char *, int); static void zallocate(char * start,int size); static void zinsert(zmem * zp, int ndx); @@ -61,7 +61,7 @@ #define ZALLOC_NODES 16384 -static void malloc_error(char *addr, size_t size) +static void malloc_error(char *addr, size_t size, const char *file, int line) { #ifdef i386 asm volatile ("hlt"); @@ -69,7 +69,7 @@ } // define the block of memory that the allocator will use -void malloc_init(char * start, int size, int nodes, void (*malloc_err_fn)(char *, size_t)) +void malloc_init(char * start, int size, int nodes, void (*malloc_err_fn)(char *, size_t, const char *, int)) { zalloc_base = start ? start : (char *)ZALLOC_ADDR; totalNodes = nodes ? nodes : ZALLOC_NODES; @@ -86,7 +86,7 @@ #define BEST_FIT 1 -void * malloc(size_t size) +void * safe_malloc(size_t size, const char *file, int line) { int i; #if BEST_FIT @@ -104,7 +104,7 @@ size = ((size + 0xf) & ~0xf); if (size == 0) { - if (zerror) (*zerror)((char *)0xdeadbeef, 0); + if (zerror) (*zerror)((char *)0xdeadbeef, 0, file, line); } #if BEST_FIT smallestSize = 0; @@ -155,7 +155,7 @@ done: if ((ret == 0) || (ret + size >= zalloc_end)) { - if (zerror) (*zerror)(ret, size); + if (zerror) (*zerror)(ret, size, file, line); } if (ret != 0) { @@ -204,7 +204,7 @@ } } if ( !found ) { - if (zerror) (*zerror)(pointer, rp); + if (zerror) (*zerror)(pointer, rp, "free", 0); else return; } #if ZDEBUG @@ -232,7 +232,7 @@ if ((start + tsize) < zavailable[i].start) { if (++availableNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 0); + if (zerror) (*zerror)((char *)0xf000f000, 0, "free", 0); } zinsert(zavailable, i); zavailable[i].start = start; @@ -242,7 +242,7 @@ } if (++availableNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 1); + if (zerror) (*zerror)((char *)0xf000f000, 1, "free", 0); } zavailable[i].start = start; zavailable[i].size = tsize; @@ -260,7 +260,7 @@ zalloced[allocedNodes].start = start; zalloced[allocedNodes].size = size; if (++allocedNodes > totalNodes) { - if (zerror) (*zerror)((char *)0xf000f000, 2); + if (zerror) (*zerror)((char *)0xf000f000, 2, "zallocate", 0); }; } @@ -315,7 +315,7 @@ /* This is the simplest way possible. Should fix this. */ void * realloc(void * start, size_t newsize) { - void * newstart = malloc(newsize); + void * newstart = safe_malloc(newsize, __FILE__, __LINE__); bcopy(start, newstart, newsize); free(start); return newstart; Index: trunk/i386/libsa/strtol.c =================================================================== --- trunk/i386/libsa/strtol.c (revision 22) +++ trunk/i386/libsa/strtol.c (revision 23) @@ -74,37 +74,6 @@ #include "libsa.h" #include -static inline int -isupper(char c) -{ - return (c >= 'A' && c <= 'Z'); -} - -static inline int -islower(char c) -{ - return (c >= 'a' && c <= 'z'); -} - -static inline int -isalpha(char c) -{ - return ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')); -} - -static inline int -isspace(char c) -{ - return (c == ' ' || c == '\t' || c == '\n' || c == '\12'); -} - -static inline int -isdigit(char c) -{ - return (c >= '0' && c <= '9'); -} - - /* * Convert a string to a long integer. * Index: trunk/i386/libsa/efi_tables.c =================================================================== --- trunk/i386/libsa/efi_tables.c (revision 22) +++ trunk/i386/libsa/efi_tables.c (revision 23) @@ -97,8 +97,7 @@ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d }; -uint32_t -crc32(uint32_t crc, const void *buf, size_t size) +uint32_t crc32(uint32_t crc, const void *buf, size_t size) { const uint8_t *p; @@ -128,7 +127,7 @@ pGuid->Data4[6], pGuid->Data4[7]); } -int efi_guid_is_null(EFI_GUID const *pGuid) +bool efi_guid_is_null(EFI_GUID const *pGuid) { if(pGuid->Data1 == 0 && pGuid->Data2 == 0 && pGuid->Data3 == 0) { @@ -136,11 +135,11 @@ for(i=0; i<8; ++i) { if(pGuid->Data4[i] != 0) - return FALSE; + return false; } - return TRUE; + return true; } - return FALSE; + return false; } #define COMPARE_MEMBER_AND_RETURN_IF_NE(a,b,mem) \ @@ -161,4 +160,3 @@ } return 0; } - Index: trunk/i386/util/machOconv.c =================================================================== --- trunk/i386/util/machOconv.c (revision 22) +++ trunk/i386/util/machOconv.c (revision 23) @@ -23,6 +23,7 @@ */ #include #include +#include #include #include #include @@ -35,7 +36,7 @@ struct mach_header mh; void * cmds; -boolean_t swap_ends; +static bool swap_ends; static unsigned long swap( unsigned long x @@ -85,9 +86,9 @@ exit(1); } if (mh.magic == MH_MAGIC) - swap_ends = FALSE; + swap_ends = false; else if (mh.magic == MH_CIGAM) - swap_ends = TRUE; + swap_ends = true; else { fprintf(stderr, "bad magic number %lx\n", (unsigned long)mh.magic); exit(1); @@ -110,7 +111,7 @@ for ( ncmds = swap(mh.ncmds), cp = cmds; ncmds > 0; ncmds--) { - boolean_t isDATA; + bool isDATA; unsigned vmsize; #define lcp ((struct load_command *)cp) @@ -123,7 +124,7 @@ vmsize = swap(scp->filesize); else vmsize = swap(scp->vmsize); - result = vm_allocate(mach_task_self(), &data, vmsize, TRUE); + result = vm_allocate(mach_task_self(), &data, vmsize, true); if (result != KERN_SUCCESS) { mach_error("vm_allocate segment data", result); exit(1); Property changes on: trunk ___________________________________________________________________ Added: svn:mergeinfo Merged /branches/rekursor:r3-22