Index: trunk/i386/libsaio/vbe.c =================================================================== --- trunk/i386/libsaio/vbe.c (revision 2343) +++ trunk/i386/libsaio/vbe.c (revision 2344) @@ -29,15 +29,19 @@ #include "libsaio.h" #include "vbe.h" -/* - * Various inline routines for video I/O - */ +// Various inline routines for video I/O + +static biosBuf_t bb; + +//============================================================================== + static inline void outi (int port, int index, int val) { outw (port, (val << 8) | index); } +//============================================================================== static inline void outib (int port, int index, int val) { @@ -45,6 +49,8 @@ outb (port + 1, val); } +//============================================================================== + static inline int ini (int port, int index) { @@ -52,17 +58,16 @@ return inb (port + 1); } +//============================================================================== + static inline void -rmwi (int port, int index, int clear, int set) +rmwi(int port, int index, int clear, int set) { outb (port, index); outb (port + 1, (inb (port + 1) & ~clear) | set); } -/* - * Globals - */ -static biosBuf_t bb; +//============================================================================== int getVBEInfo( void * infoBlock ) { @@ -74,6 +79,8 @@ return(bb.eax.r.h); } +//============================================================================== + int getVBEModeInfo( int mode, void * minfo_p ) { bb.intno = 0x10; @@ -85,6 +92,8 @@ return(bb.eax.r.h); } +//============================================================================== + int getVBEDACFormat(unsigned char *format) { bb.intno = 0x10; @@ -95,6 +104,8 @@ return(bb.eax.r.h); } +//============================================================================== + int setVBEDACFormat(unsigned char format) { bb.intno = 0x10; Index: trunk/i386/libsaio/device_tree.c =================================================================== --- trunk/i386/libsaio/device_tree.c (revision 2343) +++ trunk/i386/libsaio/device_tree.c (revision 2344) @@ -297,7 +297,7 @@ for (count = 0, prop = node->properties; prop != 0; count++, prop = prop->next) { flatProp = (DeviceTreeNodeProperty *)buffer; - strcpy(flatProp->name, prop->name); + strncpy(flatProp->name, prop->name, kPropNameLength); flatProp->length = prop->length; buffer += sizeof(DeviceTreeNodeProperty); bcopy(prop->value, buffer, prop->length); Index: trunk/i386/libsaio/device_inject.c =================================================================== --- trunk/i386/libsaio/device_inject.c (revision 2343) +++ trunk/i386/libsaio/device_inject.c (revision 2344) @@ -160,8 +160,7 @@ int i; - for(i = 0; i < numpaths; i++) - { + for(i = 0; i < numpaths; i++) { device->pci_dev_path[i].length = 0x06; device->pci_dev_path[i].type = 0x01; device->pci_dev_path[i].subtype = 0x01; @@ -197,32 +196,30 @@ } uint32_t length = ((strlen(nm) * 2) + len + (2 * sizeof(uint32_t)) + 2); uint8_t *data = (uint8_t*)malloc(length); - { - if(!data) { - return 0; - } - memset(data, 0, length); - uint32_t off= 0; - data[off+1] = ((strlen(nm) * 2) + 6) >> 8; - data[off] = ((strlen(nm) * 2) + 6) & 0x00FF; - - off += 4; - uint32_t i=0, l = strlen(nm); - for(i = 0 ; i < l ; i++, off += 2) { - data[off] = *nm++; - } + if(!data) { + return 0; + } - off += 2; - l = len; - uint32_t *datalength = (uint32_t*)&data[off]; - *datalength = (uint32_t)(l + 4); - off += 4; - for(i = 0 ; i < l ; i++, off++) - { - data[off] = *vl++; - } + memset(data, 0, length); + uint32_t off= 0; + data[off+1] = ((strlen(nm) * 2) + 6) >> 8; + data[off] = ((strlen(nm) * 2) + 6) & 0x00FF; + + off += 4; + uint32_t i=0, l = strlen(nm); + for(i = 0 ; i < l ; i++, off += 2) { + data[off] = *nm++; } + + off += 2; + l = len; + uint32_t *datalength = (uint32_t*)&data[off]; + *datalength = (uint32_t)(l + 4); + off += 4; + for(i = 0 ; i < l ; i++, off++) { + data[off] = *vl++; + } uint32_t offset = device->length - (24 + (6 * device->num_pci_devpaths)); @@ -316,12 +313,9 @@ } int i; - for(i = 0; i < string->numentries; i++) - { - if(string->entries[i]) - { - if(string->entries[i]->data) - { + for(i = 0; i < string->numentries; i++) { + if(string->entries[i]) { + if(string->entries[i]->data) { free(string->entries[i]->data); string->entries[i]->data = NULL; } @@ -347,8 +341,7 @@ int i; char buf[3]; - if (hex == NULL || bin == NULL || len <= 0 || strlen(hex) != len * 2) - { + if (hex == NULL || bin == NULL || len <= 0 || strlen(hex) != len * 2) { printf("[ERROR] bin2hex input error\n"); return -1; } @@ -356,10 +349,8 @@ buf[2] = '\0'; p = (char *) hex; - for (i = 0; i < len; i++) - { - if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) - { + for (i = 0; i < len; i++) { + if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) { printf("[ERROR] bin2hex '%s' syntax error\n", hex); return -2; } Index: trunk/i386/libsaio/device_inject.h =================================================================== --- trunk/i386/libsaio/device_inject.h (revision 2343) +++ trunk/i386/libsaio/device_inject.h (revision 2344) @@ -22,6 +22,8 @@ uint16_t length; // = 0x0c uint32_t _HID; // = 0xD041030A ? uint32_t _UID; // = 0x00000000 PCI ROOT + uint32_t _CID; // = Optional variable length + }; struct PCIDevPath { Index: trunk/i386/libsaio/hda.h =================================================================== --- trunk/i386/libsaio/hda.h (revision 2343) +++ trunk/i386/libsaio/hda.h (revision 2344) @@ -675,4 +675,240 @@ #define HDA_CODEC_INTELCL HDA_CODEC_CONSTRUCT(INTEL, 0x29fb) #define HDA_CODEC_INTELXXXX HDA_CODEC_CONSTRUCT(INTEL, 0xffff) +/**************************************************************************** + * HDA Controller Register Set + ****************************************************************************/ +#define HDAC_GCAP 0x00 /* 2 - Global Capabilities*/ +#define HDAC_VMIN 0x02 /* 1 - Minor Version */ +#define HDAC_VMAJ 0x03 /* 1 - Major Version */ +#define HDAC_OUTPAY 0x04 /* 2 - Output Payload Capability */ +#define HDAC_INPAY 0x06 /* 2 - Input Payload Capability */ +#define HDAC_GCTL 0x08 /* 4 - Global Control */ +#define HDAC_WAKEEN 0x0c /* 2 - Wake Enable */ +#define HDAC_STATESTS 0x0e /* 2 - State Change Status */ +#define HDAC_GSTS 0x10 /* 2 - Global Status */ +#define HDAC_OUTSTRMPAY 0x18 /* 2 - Output Stream Payload Capability */ +#define HDAC_INSTRMPAY 0x1a /* 2 - Input Stream Payload Capability */ +#define HDAC_INTCTL 0x20 /* 4 - Interrupt Control */ +#define HDAC_INTSTS 0x24 /* 4 - Interrupt Status */ +#define HDAC_WALCLK 0x30 /* 4 - Wall Clock Counter */ +#define HDAC_SSYNC 0x38 /* 4 - Stream Synchronization */ +#define HDAC_CORBLBASE 0x40 /* 4 - CORB Lower Base Address */ +#define HDAC_CORBUBASE 0x44 /* 4 - CORB Upper Base Address */ +#define HDAC_CORBWP 0x48 /* 2 - CORB Write Pointer */ +#define HDAC_CORBRP 0x4a /* 2 - CORB Read Pointer */ +#define HDAC_CORBCTL 0x4c /* 1 - CORB Control */ +#define HDAC_CORBSTS 0x4d /* 1 - CORB Status */ +#define HDAC_CORBSIZE 0x4e /* 1 - CORB Size */ +#define HDAC_RIRBLBASE 0x50 /* 4 - RIRB Lower Base Address */ +#define HDAC_RIRBUBASE 0x54 /* 4 - RIRB Upper Base Address */ +#define HDAC_RIRBWP 0x58 /* 2 - RIRB Write Pointer */ +#define HDAC_RINTCNT 0x5a /* 2 - Response Interrupt Count */ +#define HDAC_RIRBCTL 0x5c /* 1 - RIRB Control */ +#define HDAC_RIRBSTS 0x5d /* 1 - RIRB Status */ +#define HDAC_RIRBSIZE 0x5e /* 1 - RIRB Size */ +#define HDAC_ICOI 0x60 /* 4 - Immediate Command Output Interface */ +#define HDAC_ICII 0x64 /* 4 - Immediate Command Input Interface */ +#define HDAC_ICIS 0x68 /* 2 - Immediate Command Status */ +#define HDAC_DPIBLBASE 0x70 /* 4 - DMA Position Buffer Lower Base */ +#define HDAC_DPIBUBASE 0x74 /* 4 - DMA Position Buffer Upper Base */ +#define HDAC_SDCTL0 0x80 /* 3 - Stream Descriptor Control */ +#define HDAC_SDCTL1 0x81 /* 3 - Stream Descriptor Control */ +#define HDAC_SDCTL2 0x82 /* 3 - Stream Descriptor Control */ +#define HDAC_SDSTS 0x83 /* 1 - Stream Descriptor Status */ +#define HDAC_SDLPIB 0x84 /* 4 - Link Position in Buffer */ +#define HDAC_SDCBL 0x88 /* 4 - Cyclic Buffer Length */ +#define HDAC_SDLVI 0x8C /* 2 - Last Valid Index */ +#define HDAC_SDFIFOS 0x90 /* 2 - FIFOS */ +#define HDAC_SDFMT 0x92 /* 2 - fmt */ +#define HDAC_SDBDPL 0x98 /* 4 - Buffer Descriptor Pointer Lower Base */ +#define HDAC_SDBDPU 0x9C /* 4 - Buffer Descriptor Pointer Upper Base */ + +#define _HDAC_ISDOFFSET(n, iss, oss) (0x80 + ((n) * 0x20)) +#define _HDAC_ISDCTL(n, iss, oss) (0x00 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDSTS(n, iss, oss) (0x03 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDPICB(n, iss, oss) (0x04 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDCBL(n, iss, oss) (0x08 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDLVI(n, iss, oss) (0x0c + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDFIFOD(n, iss, oss) (0x10 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDFMT(n, iss, oss) (0x12 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDBDPL(n, iss, oss) (0x18 + _HDAC_ISDOFFSET(n, iss, oss)) +#define _HDAC_ISDBDPU(n, iss, oss) (0x1c + _HDAC_ISDOFFSET(n, iss, oss)) + +#define _HDAC_OSDOFFSET(n, iss, oss) (0x80 + ((iss) * 0x20) + ((n) * 0x20)) +#define _HDAC_OSDCTL(n, iss, oss) (0x00 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDSTS(n, iss, oss) (0x03 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDPICB(n, iss, oss) (0x04 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDCBL(n, iss, oss) (0x08 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDLVI(n, iss, oss) (0x0c + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDFIFOD(n, iss, oss) (0x10 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDFMT(n, iss, oss) (0x12 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDBDPL(n, iss, oss) (0x18 + _HDAC_OSDOFFSET(n, iss, oss)) +#define _HDAC_OSDBDPU(n, iss, oss) (0x1c + _HDAC_OSDOFFSET(n, iss, oss)) + +#define _HDAC_BSDOFFSET(n, iss, oss) (0x80 + ((iss) * 0x20) + ((oss) * 0x20) + ((n) * 0x20)) +#define _HDAC_BSDCTL(n, iss, oss) (0x00 + _HDAC_BSDOFFSET(n, iss, oss)) +#define _HDAC_BSDSTS(n, iss, oss) (0x03 + _HDAC_BSDOFFSET(n, iss, oss)) +#define _HDAC_BSDPICB(n, iss, oss) (0x04 + _HDAC_BSDOFFSET(n, iss, oss)) +#define _HDAC_BSDCBL(n, iss, oss) (0x08 + _HDAC_BSDOFFSET(n, iss, oss)) +#define _HDAC_BSDLVI(n, iss, oss) (0x0c + _HDAC_BSDOFFSET(n, iss, oss)) +#define _HDAC_BSDFIFOD(n, iss, oss) (0x10 + _HDAC_BSDOFFSET(n, iss, oss)) +#define _HDAC_BSDFMT(n, iss, oss) (0x12 + _HDAC_BSDOFFSET(n, iss, oss)) +#define _HDAC_BSDBDPL(n, iss, oss) (0x18 + _HDAC_BSDOFFSET(n, iss, oss)) +#define _HDAC_BSDBDBU(n, iss, oss) (0x1c + _HDAC_BSDOFFSET(n, iss, oss)) + +/**************************************************************************** + * HDA Controller Register Fields + ****************************************************************************/ + +/* GCAP - Global Capabilities */ +#define HDAC_GCAP_64OK 0x0001 +#define HDAC_GCAP_NSDO_MASK 0x0006 +#define HDAC_GCAP_NSDO_SHIFT 1 +#define HDAC_GCAP_BSS_MASK 0x00f8 +#define HDAC_GCAP_BSS_SHIFT 3 +#define HDAC_GCAP_ISS_MASK 0x0f00 +#define HDAC_GCAP_ISS_SHIFT 8 +#define HDAC_GCAP_OSS_MASK 0xf000 +#define HDAC_GCAP_OSS_SHIFT 12 + +#define HDAC_GCAP_NSDO_1SDO 0x00 +#define HDAC_GCAP_NSDO_2SDO 0x02 +#define HDAC_GCAP_NSDO_4SDO 0x04 + +#define HDAC_GCAP_BSS(gcap) \ +(((gcap) & HDAC_GCAP_BSS_MASK) >> HDAC_GCAP_BSS_SHIFT) +#define HDAC_GCAP_ISS(gcap) \ +(((gcap) & HDAC_GCAP_ISS_MASK) >> HDAC_GCAP_ISS_SHIFT) +#define HDAC_GCAP_OSS(gcap) \ +(((gcap) & HDAC_GCAP_OSS_MASK) >> HDAC_GCAP_OSS_SHIFT) +#define HDAC_GCAP_NSDO(gcap) \ +(((gcap) & HDAC_GCAP_NSDO_MASK) >> HDAC_GCAP_NSDO_SHIFT) + +/* GCTL - Global Control */ +#define HDAC_GCTL_CRST 0x00000001 +#define HDAC_GCTL_FCNTRL 0x00000002 +#define HDAC_GCTL_UNSOL 0x00000100 + +/* WAKEEN - Wake Enable */ +#define HDAC_WAKEEN_SDIWEN_MASK 0x7fff +#define HDAC_WAKEEN_SDIWEN_SHIFT 0 + +/* STATESTS - State Change Status */ +#define HDAC_STATESTS_SDIWAKE_MASK 0x7fff +#define HDAC_STATESTS_SDIWAKE_SHIFT 0 + +#define HDAC_STATESTS_SDIWAKE(statests, n) \ +(((((statests) & HDAC_STATESTS_SDIWAKE_MASK) >> \ +HDAC_STATESTS_SDIWAKE_SHIFT) >> (n)) & 0x0001) + +/* GSTS - Global Status */ +#define HDAC_GSTS_FSTS 0x0002 + +/* INTCTL - Interrut Control */ +#define HDAC_INTCTL_SIE_MASK 0x3fffffff +#define HDAC_INTCTL_SIE_SHIFT 0 +#define HDAC_INTCTL_CIE 0x40000000 +#define HDAC_INTCTL_GIE 0x80000000 + +/* INTSTS - Interrupt Status */ +#define HDAC_INTSTS_SIS_MASK 0x3fffffff +#define HDAC_INTSTS_SIS_SHIFT 0 +#define HDAC_INTSTS_CIS 0x40000000 +#define HDAC_INTSTS_GIS 0x80000000 + +/* SSYNC - Stream Synchronization */ +#define HDAC_SSYNC_SSYNC_MASK 0x3fffffff +#define HDAC_SSYNC_SSYNC_SHIFT 0 + +/* CORBWP - CORB Write Pointer */ +#define HDAC_CORBWP_CORBWP_MASK 0x00ff +#define HDAC_CORBWP_CORBWP_SHIFT 0 + +/* CORBRP - CORB Read Pointer */ +#define HDAC_CORBRP_CORBRP_MASK 0x00ff +#define HDAC_CORBRP_CORBRP_SHIFT 0 +#define HDAC_CORBRP_CORBRPRST 0x8000 + +/* CORBCTL - CORB Control */ +#define HDAC_CORBCTL_CMEIE 0x01 +#define HDAC_CORBCTL_CORBRUN 0x02 + +/* CORBSTS - CORB Status */ +#define HDAC_CORBSTS_CMEI 0x01 + +/* CORBSIZE - CORB Size */ +#define HDAC_CORBSIZE_CORBSIZE_MASK 0x03 +#define HDAC_CORBSIZE_CORBSIZE_SHIFT 0 +#define HDAC_CORBSIZE_CORBSZCAP_MASK 0xf0 +#define HDAC_CORBSIZE_CORBSZCAP_SHIFT 4 + +#define HDAC_CORBSIZE_CORBSIZE_2 0x00 +#define HDAC_CORBSIZE_CORBSIZE_16 0x01 +#define HDAC_CORBSIZE_CORBSIZE_256 0x02 + +#define HDAC_CORBSIZE_CORBSZCAP_2 0x10 +#define HDAC_CORBSIZE_CORBSZCAP_16 0x20 +#define HDAC_CORBSIZE_CORBSZCAP_256 0x40 + +#define HDAC_CORBSIZE_CORBSIZE(corbsize) \ +(((corbsize) & HDAC_CORBSIZE_CORBSIZE_MASK) >> HDAC_CORBSIZE_CORBSIZE_SHIFT) + +/* RIRBWP - RIRB Write Pointer */ +#define HDAC_RIRBWP_RIRBWP_MASK 0x00ff +#define HDAC_RIRBWP_RIRBWP_SHIFT 0 +#define HDAC_RIRBWP_RIRBWPRST 0x8000 + +/* RINTCTN - Response Interrupt Count */ +#define HDAC_RINTCNT_MASK 0x00ff +#define HDAC_RINTCNT_SHIFT 0 + +/* RIRBCTL - RIRB Control */ +#define HDAC_RIRBCTL_RINTCTL 0x01 +#define HDAC_RIRBCTL_RIRBDMAEN 0x02 +#define HDAC_RIRBCTL_RIRBOIC 0x04 + +/* RIRBSTS - RIRB Status */ +#define HDAC_RIRBSTS_RINTFL 0x01 +#define HDAC_RIRBSTS_RIRBOIS 0x04 + +/* RIRBSIZE - RIRB Size */ +#define HDAC_RIRBSIZE_RIRBSIZE_MASK 0x03 +#define HDAC_RIRBSIZE_RIRBSIZE_SHIFT 0 +#define HDAC_RIRBSIZE_RIRBSZCAP_MASK 0xf0 +#define HDAC_RIRBSIZE_RIRBSZCAP_SHIFT 4 + +#define HDAC_RIRBSIZE_RIRBSIZE_2 0x00 +#define HDAC_RIRBSIZE_RIRBSIZE_16 0x01 +#define HDAC_RIRBSIZE_RIRBSIZE_256 0x02 + +#define HDAC_RIRBSIZE_RIRBSZCAP_2 0x10 +#define HDAC_RIRBSIZE_RIRBSZCAP_16 0x20 +#define HDAC_RIRBSIZE_RIRBSZCAP_256 0x40 + +#define HDAC_RIRBSIZE_RIRBSIZE(rirbsize) \ +(((rirbsize) & HDAC_RIRBSIZE_RIRBSIZE_MASK) >> HDAC_RIRBSIZE_RIRBSIZE_SHIFT) + +/* DPLBASE - DMA Position Lower Base Address */ +#define HDAC_DPLBASE_DPLBASE_MASK 0xffffff80 +#define HDAC_DPLBASE_DPLBASE_SHIFT 7 +#define HDAC_DPLBASE_DPLBASE_DMAPBE 0x00000001 + +/* SDCTL - Stream Descriptor Control */ +#define HDAC_SDCTL_SRST 0x000001 +#define HDAC_SDCTL_RUN 0x000002 +#define HDAC_SDCTL_IOCE 0x000004 +#define HDAC_SDCTL_FEIE 0x000008 +#define HDAC_SDCTL_DEIE 0x000010 +#define HDAC_SDCTL2_STRIPE_MASK 0x03 +#define HDAC_SDCTL2_STRIPE_SHIFT 0 +#define HDAC_SDCTL2_TP 0x04 +#define HDAC_SDCTL2_DIR 0x08 +#define HDAC_SDCTL2_STRM_MASK 0xf0 +#define HDAC_SDCTL2_STRM_SHIFT 4 + +#define HDAC_SDSTS_DESE (1 << 4) +#define HDAC_SDSTS_FIFOE (1 << 3) +#define HDAC_SDSTS_BCIS (1 << 2) + #endif /* !__LIBSAIO_HDA_H */ Index: trunk/i386/libsaio/nvidia.c =================================================================== --- trunk/i386/libsaio/nvidia.c (revision 2343) +++ trunk/i386/libsaio/nvidia.c (revision 2344) @@ -77,6 +77,7 @@ #define WRITE_LE_SHORT(data) (((data) << 8 & 0xff00) | ((data) >> 8 & 0x00ff )) #define WRITE_LE_INT(data) (WRITE_LE_SHORT(data) << 16 | WRITE_LE_SHORT(data >> 16)) +char generic_name[128]; extern uint32_t devices_number; const char *nvidia_compatible_0[] = { "@0,compatible", "NVDA,NVMac" }; @@ -1639,7 +1640,6 @@ static char *get_nvidia_model(uint32_t device_id, uint32_t subsys_id) { int i, j; - static char name_model[128]; // First check in the plist, (for e.g this can override any hardcoded devices) cardList_t * nvcard = FindCardWithIds(device_id, subsys_id); @@ -1652,9 +1652,9 @@ // Then check the exceptions table if (subsys_id) { for (i = 0; i < (sizeof(nvidia_card_exceptions) / sizeof(nvidia_card_exceptions[0])); i++) { - if ((nvidia_card_exceptions[i].device == device_id) && (nvidia_card_exceptions[i].subdev == subsys_id)) - { + if ((nvidia_card_exceptions[i].device == device_id) && (nvidia_card_exceptions[i].subdev == subsys_id)) { return nvidia_card_exceptions[i].name; + break; } } } @@ -1665,9 +1665,9 @@ if (subsys_id) { for (j = 0; j < (sizeof(nvidia_card_vendors) / sizeof(nvidia_card_vendors[0])); j++) { if (nvidia_card_vendors[j].device == (subsys_id & 0xffff0000)) { - snprintf(name_model, sizeof(name_model), "%s %s", + snprintf(generic_name, 128, "%s %s", // sizeof(generic_name), "%s %s", nvidia_card_vendors[j].name, nvidia_card_generic[i].name); - return name_model; + return &generic_name[0]; } } } Index: trunk/i386/libsaio/nvidia.h =================================================================== --- trunk/i386/libsaio/nvidia.h (revision 2343) +++ trunk/i386/libsaio/nvidia.h (revision 2344) @@ -69,7 +69,8 @@ #define DCB_MAX_NUM_ENTRIES 16 #define DCB_MAX_NUM_I2C_ENTRIES 16 - +#define DCB_MAX_NUM_GPIO_ENTRIES 32 +#define DCB_MAX_NUM_CONNECTOR_ENTRIES 16 #define DCB_LOC_ON_CHIP 0 struct bios { @@ -87,11 +88,12 @@ #define NV_PRAMIN_OFFSET 0x00700000 #define NV_PRAMIN_SIZE 0x00100000 #define NV04_PFB_FIFO_DATA 0x0010020c -#define NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK 0xfff00000 -#define NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_SHIFT 20 -#define NVC0_MEM_CTRLR_COUNT 0x00121c74 -#define NVC0_MEM_CTRLR_RAM_AMOUNT 0x0010f20c +#define NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_MASK 0xfff00000 +#define NV10_PFB_FIFO_DATA_RAM_AMOUNT_MB_SHIFT 20 +#define NVC0_MEM_CTRLR_RAM_AMOUNT 0x0010f20c +#define NVC0_MEM_CTRLR_COUNT 0x00121c74 +#define NV_PBUS_PCI_NV_19 0x0000184C #define NV_PBUS_PCI_NV_20 0x00001850 #define NV_PBUS_PCI_NV_20_ROM_SHADOW_DISABLED (0 << 0) #define NV_PBUS_PCI_NV_20_ROM_SHADOW_ENABLED (1 << 0) @@ -108,6 +110,8 @@ #define NV_ARCH_40 0x40 #define NV_ARCH_50 0x50 #define NV_ARCH_C0 0xC0 +#define NV_ARCH_D0 0xD0 +#define NV_ARCH_E0 0xE0 #define CHIPSET_NV03 0x0010 #define CHIPSET_NV04 0x0020 Index: trunk/i386/libsaio/cpu.c =================================================================== --- trunk/i386/libsaio/cpu.c (revision 2343) +++ trunk/i386/libsaio/cpu.c (revision 2344) @@ -260,21 +260,16 @@ 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_0][0] >= 0x5) - { + if (p->CPU.CPUID[CPUID_0][0] >= 0x5) { do_cpuid(5, p->CPU.CPUID[CPUID_5]); } - if (p->CPU.CPUID[CPUID_0][0] >= 6) - { + if (p->CPU.CPUID[CPUID_0][0] >= 6) { do_cpuid(6, p->CPU.CPUID[CPUID_6]); } - if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 8) - { + if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 8) { do_cpuid(0x80000008, p->CPU.CPUID[CPUID_88]); do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]); - } - else if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) - { + } else if ((p->CPU.CPUID[CPUID_80][0] & 0x0000000f) >= 1) { do_cpuid(0x80000001, p->CPU.CPUID[CPUID_81]); } @@ -282,8 +277,7 @@ { 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]); @@ -307,11 +301,17 @@ p->CPU.Vendor = p->CPU.CPUID[CPUID_0][1]; p->CPU.Signature = p->CPU.CPUID[CPUID_1][0]; + // stepping = cpu_feat_eax & 0xF; p->CPU.Stepping = bitfield(p->CPU.CPUID[CPUID_1][0], 3, 0); + // model = (cpu_feat_eax >> 4) & 0xF; p->CPU.Model = bitfield(p->CPU.CPUID[CPUID_1][0], 7, 4); + // family = (cpu_feat_eax >> 8) & 0xF; p->CPU.Family = bitfield(p->CPU.CPUID[CPUID_1][0], 11, 8); - p->CPU.Type = bitfield(p->CPU.CPUID[CPUID_1][0], 13, 12); + // type = (cpu_feat_eax >> 12) & 0x3; + //p->CPU.Type = bitfield(p->CPU.CPUID[CPUID_1][0], 13, 12); + // ext_model = (cpu_feat_eax >> 16) & 0xF; p->CPU.ExtModel = bitfield(p->CPU.CPUID[CPUID_1][0], 19, 16); + // ext_family = (cpu_feat_eax >> 20) & 0xFF; p->CPU.ExtFamily = bitfield(p->CPU.CPUID[CPUID_1][0], 27, 20); p->CPU.Model += (p->CPU.ExtModel << 4); @@ -320,19 +320,14 @@ p->CPU.Family == 0x06 && p->CPU.Model >= CPU_MODEL_NEHALEM && p->CPU.Model != CPU_MODEL_ATOM // MSR is *NOT* available on the Intel Atom CPU - ) - { + ) { msr = rdmsr64(MSR_CORE_THREAD_COUNT); // Undocumented MSR in Nehalem and newer CPUs p->CPU.NoCores = bitfield((uint32_t)msr, 31, 16); // Using undocumented MSR to get actual values p->CPU.NoThreads = bitfield((uint32_t)msr, 15, 0); // Using undocumented MSR to get actual values - } - else if (p->CPU.Vendor == CPUID_VENDOR_AMD) - { + } else if (p->CPU.Vendor == CPUID_VENDOR_AMD) { p->CPU.NoThreads = bitfield(p->CPU.CPUID[CPUID_1][1], 23, 16); p->CPU.NoCores = bitfield(p->CPU.CPUID[CPUID_88][2], 7, 0) + 1; - } - else - { + } else { // Use previous method for Cores and Threads 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; @@ -340,8 +335,7 @@ /* get brand string (if supported) */ /* Copyright: from Apple's XNU cpuid.c */ - if (p->CPU.CPUID[CPUID_80][0] > 0x80000004) - { + if (p->CPU.CPUID[CPUID_80][0] > 0x80000004) { uint32_t reg[4]; char str[128], *s; /* @@ -354,18 +348,15 @@ bcopy((char *)reg, &str[16], 16); do_cpuid(0x80000004, reg); bcopy((char *)reg, &str[32], 16); - for (s = str; *s != '\0'; s++) - { - if (*s != ' ') - { + for (s = str; *s != '\0'; s++) { + if (*s != ' ') { break; } } strlcpy(p->CPU.BrandString, s, sizeof(p->CPU.BrandString)); - if (!strncmp(p->CPU.BrandString, CPU_STRING_UNKNOWN, MIN(sizeof(p->CPU.BrandString), strlen(CPU_STRING_UNKNOWN) + 1))) - { + if (!strncmp(p->CPU.BrandString, CPU_STRING_UNKNOWN, MIN(sizeof(p->CPU.BrandString), strlen(CPU_STRING_UNKNOWN) + 1))) { /* * This string means we have a firmware-programmable brand string, * and the firmware couldn't figure out what sort of CPU we have. @@ -375,41 +366,32 @@ } /* setup features */ - if ((bit(23) & p->CPU.CPUID[CPUID_1][3]) != 0) - { + 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) - { + 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) - { + 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) - { + 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) - { + 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) - { + 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) - { + if ((bit(29) & p->CPU.CPUID[CPUID_81][3]) != 0) { p->CPU.Features |= CPU_FEATURE_EM64T; } - if ((bit(5) & p->CPU.CPUID[CPUID_1][3]) != 0) - { + if ((bit(5) & p->CPU.CPUID[CPUID_1][3]) != 0) { p->CPU.Features |= CPU_FEATURE_MSR; } //if ((bit(28) & p->CPU.CPUID[CPUID_1][3]) != 0) { - if (p->CPU.NoThreads > p->CPU.NoCores) - { + if (p->CPU.NoThreads > p->CPU.NoCores) { p->CPU.Features |= CPU_FEATURE_HTT; } @@ -448,8 +430,7 @@ bus_ratio_min = bitfield(msr, 47, 40); //valv: not sure about this one (Remarq.1) msr = rdmsr64(MSR_FLEX_RATIO); DBG("msr(%d): flex_ratio %08x\n", __LINE__, bitfield(msr, 31, 0)); - if (bitfield(msr, 16, 16)) - { + if (bitfield(msr, 16, 16)) { flex_ratio = bitfield(msr, 15, 8); /* bcc9: at least on the gigabyte h67ma-ud2h, where the cpu multipler can't be changed to @@ -459,63 +440,47 @@ causing the system to crash since tscGranularity is inadvertently set to 0. */ - if (flex_ratio == 0) - { + if (flex_ratio == 0) { /* Clear bit 16 (evidently the presence bit) */ wrmsr64(MSR_FLEX_RATIO, (msr & 0xFFFFFFFFFFFEFFFFULL)); msr = rdmsr64(MSR_FLEX_RATIO); verbose("Unusable flex ratio detected. Patched MSR now %08x\n", bitfield(msr, 31, 0)); - } - else - { - if (bus_ratio_max > flex_ratio) - { + } else { + if (bus_ratio_max > flex_ratio) { bus_ratio_max = flex_ratio; } } } - if (bus_ratio_max) - { + if (bus_ratio_max) { fsbFrequency = (tscFrequency / bus_ratio_max); } //valv: Turbo Ratio Limit - if ((intelCPU != 0x2e) && (intelCPU != 0x2f)) - { + if ((intelCPU != 0x2e) && (intelCPU != 0x2f)) { msr = rdmsr64(MSR_TURBO_RATIO_LIMIT); cpuFrequency = bus_ratio_max * fsbFrequency; max_ratio = bus_ratio_max * 10; - } - else - { + } else { cpuFrequency = tscFrequency; } - if ((getValueForKey(kbusratio, &newratio, &len, &bootInfo->chameleonConfig)) && (len <= 4)) - { + if ((getValueForKey(kbusratio, &newratio, &len, &bootInfo->chameleonConfig)) && (len <= 4)) { max_ratio = atoi(newratio); max_ratio = (max_ratio * 10); - if (len >= 3) - { + if (len >= 3) { max_ratio = (max_ratio + 5); } verbose("Bus-Ratio: min=%d, max=%s\n", bus_ratio_min, newratio); // extreme overclockers may love 320 ;) - if ((max_ratio >= min_ratio) && (max_ratio <= 320)) - { + if ((max_ratio >= min_ratio) && (max_ratio <= 320)) { cpuFrequency = (fsbFrequency * max_ratio) / 10; - if (len >= 3) - { + if (len >= 3) { maxdiv = 1; - } - else - { + } else { maxdiv = 0; } - } - else - { + } else { max_ratio = (bus_ratio_max * 10); } } @@ -525,46 +490,36 @@ p->CPU.MinRatio = min_ratio; myfsb = fsbFrequency / 1000000; - verbose("Sticking with [BCLK: %dMhz, Bus-Ratio: %d]\n", myfsb, max_ratio/10); + verbose("Sticking with [BCLK: %dMhz, Bus-Ratio: %d]\n", myfsb, max_ratio/10); // Bungo: fixed wrong Bus-Ratio readout currcoef = bus_ratio_max; } else { msr = rdmsr64(MSR_IA32_PERF_STATUS); DBG("msr(%d): ia32_perf_stat 0x%08x\n", __LINE__, bitfield(msr, 31, 0)); - currcoef = bitfield(msr, 12, 8); + currcoef = bitfield(msr, 12, 8); // Bungo: reverted to 2263 state because of wrong old CPUs freq. calculating /* Non-integer bus ratio for the max-multi*/ maxdiv = bitfield(msr, 46, 46); /* Non-integer bus ratio for the current-multi (undocumented)*/ currdiv = bitfield(msr, 14, 14); // This will always be model >= 3 - if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f)) - { + if ((p->CPU.Family == 0x06 && p->CPU.Model >= 0x0e) || (p->CPU.Family == 0x0f)) { /* On these models, maxcoef defines TSC freq */ maxcoef = bitfield(msr, 44, 40); - } - else - { + } else { /* On lower models, currcoef defines TSC freq */ /* XXX */ maxcoef = currcoef; } - if (maxcoef) - { - if (maxdiv) - { + if (maxcoef) { + if (maxdiv) { fsbFrequency = ((tscFrequency * 2) / ((maxcoef * 2) + 1)); - } - else - { + } else { fsbFrequency = (tscFrequency / maxcoef); } - if (currdiv) - { + if (currdiv) { cpuFrequency = (fsbFrequency * ((currcoef * 2) + 1) / 2); - } - else - { + } else { cpuFrequency = (fsbFrequency * currcoef); } DBG("max: %d%s current: %d%s\n", maxcoef, maxdiv ? ".5" : "",currcoef, currdiv ? ".5" : ""); Index: trunk/i386/libsaio/platform.h =================================================================== --- trunk/i386/libsaio/platform.h (revision 2343) +++ trunk/i386/libsaio/platform.h (revision 2344) @@ -137,7 +137,7 @@ uint32_t Vendor; // Vendor uint32_t Signature; // Processor Signature uint32_t Stepping; // Stepping - uint32_t Type; // Type + //uint32_t Type; // Type uint32_t Model; // Model uint32_t ExtModel; // Extended Model uint32_t Family; // Family Index: trunk/i386/libsaio/freebsd.c =================================================================== --- trunk/i386/libsaio/freebsd.c (revision 2343) +++ trunk/i386/libsaio/freebsd.c (revision 2344) @@ -3,10 +3,11 @@ #include "freebsd.h" #define FreeBSDProbeSize 2048 +#define DISKMAGIC ((uint32_t)0x19540119) /* The disk magic number */ bool FreeBSDProbe (const void *buf) { - return (OSReadLittleInt32(buf+0xA55C,0)==0x19540119); + return (OSReadLittleInt32(buf+0xA55C,0) == DISKMAGIC); } void FreeBSDGetDescription(CICell ih, char *str, long strMaxLen) { Index: trunk/i386/libsaio/pci.c =================================================================== --- trunk/i386/libsaio/pci.c (revision 2343) +++ trunk/i386/libsaio/pci.c (revision 2344) @@ -79,7 +79,7 @@ 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 == 0xfffffffful) { continue; } new = (pci_dt_t*)malloc(sizeof(pci_dt_t)); Index: trunk/i386/libsaio/stringTable.c =================================================================== --- trunk/i386/libsaio/stringTable.c (revision 2343) +++ trunk/i386/libsaio/stringTable.c (revision 2344) @@ -135,34 +135,31 @@ return true; } -char * -newStringFromList( - char **list, - int *size -) +char *newStringFromList(char **list, int *size) { - char *begin = *list, *end; - char *newstr; - int newsize = *size; - int bufsize; + char *begin = *list, *end; + char *newstr; + int newsize = *size; + int bufsize; - while (*begin && newsize && isspace(*begin)) { - begin++; - newsize--; - } - end = begin; - while (*end && newsize && !isspace(*end)) { - end++; - newsize--; - } - if (begin == end) - return 0; - bufsize = end - begin + 1; - newstr = malloc(bufsize); - strlcpy(newstr, begin, bufsize); - *list = end; - *size = newsize; - return newstr; + while (*begin && newsize && isspace(*begin)) { + begin++; + newsize--; + } + end = begin; + while (*end && newsize && !isspace(*end)) { + end++; + newsize--; + } + if (begin == end) { + return 0; + } + bufsize = end - begin + 1; + newstr = malloc(bufsize); + strlcpy(newstr, begin, bufsize); + *list = end; + *size = newsize; + return newstr; } #endif @@ -174,16 +171,14 @@ { int ret = 0; - while (*table) - { - if (*table == '\\') - { + while (*table) { + if (*table == '\\') { table += 2; ret += 1 + (compress ? 0 : 1); - } - else - { - if (*table == '\"') return ret; + } else { + if (*table == '\"') { + return ret; + } ret++; table++; } @@ -200,8 +195,7 @@ value = XMLGetProperty(config->dictionary, key); if (value != 0) { if (value->type != kTagTypeString) { - error("Non-string tag '%s' found in config file\n", - key); + error("Non-string tag '%s' found in config file\n", key); return false; } *val = value->string; @@ -209,7 +203,7 @@ return true; } } else { - + // Legacy plist-style table } @@ -224,42 +218,38 @@ * in the string table matching 'key'. Also translates * \n escapes in the string. */ -char *newStringForStringTableKey( - char *table, - char *key, - config_file_t *config -) +char *newStringForStringTableKey(char *table, char *key, config_file_t *config) { - const char *val; - char *newstr, *p; - int size; + const char *val; + char *newstr, *p; + int size; - if (getValueForConfigTableKey(config, key, &val, &size)) { - newstr = (char *)malloc(size+1); - for (p = newstr; size; size--, p++, val++) { - if ((*p = *val) == '\\') { - switch (*++val) { - case 'r': - *p = '\r'; - break; - case 'n': - *p = '\n'; - break; - case 't': - *p = '\t'; - break; - default: - *p = *val; - break; + if (getValueForConfigTableKey(config, key, &val, &size)) { + newstr = (char *)malloc(size+1); + for (p = newstr; size; size--, p++, val++) { + if ((*p = *val) == '\\') { + switch (*++val) { + case 'r': + *p = '\r'; + break; + case 'n': + *p = '\n'; + break; + case 't': + *p = '\t'; + break; + default: + *p = *val; + break; + } + size--; + } } - size--; - } + *p = '\0'; + return newstr; + } else { + return 0; } - *p = '\0'; - return newstr; - } else { - return 0; - } } #endif @@ -267,17 +257,17 @@ char * newStringForKey(char *key, config_file_t *config) { - const char *val; - char *newstr; - int size; + const char *val; + char *newstr; + int size; - if (getValueForKey(key, &val, &size, config) && size) { - newstr = (char *)malloc(size + 1); - strlcpy(newstr, val, size + 1); - return newstr; - } else { - return 0; - } + if (getValueForKey(key, &val, &size, config) && size) { + newstr = (char *)malloc(size + 1); + strlcpy(newstr, val, size + 1); + return newstr; + } else { + return 0; + } } /* parse a command line @@ -288,64 +278,68 @@ static const char *getToken(const char *line, const char **begin, int *len) { - if (*line == '\"') { - *begin = ++line; - while (*line && *line != '\"') - line++; - *len = line++ - *begin; - } else { - *begin = line; - while (*line && !isspace(*line) && *line != '=') - line++; - *len = line - *begin; - } - return line; + if (*line == '\"') { + *begin = ++line; + while (*line && *line != '\"') { + line++; + } + *len = line++ - *begin; + } else { + *begin = line; + while (*line && !isspace(*line) && *line != '=') { + line++; + } + *len = line - *begin; + } + return line; } bool getValueForBootKey(const char *line, const char *match, const char **matchval, int *len) { - const char *key, *value; - int key_len, value_len; - bool retval = false; + const char *key, *value; + int key_len, value_len; + bool retval = false; - while (*line) { - /* look for keyword or argument */ - while (isspace(*line)) line++; + while (*line) { + /* look for keyword or argument */ + while (isspace(*line)) { + line++; + } - /* now look for '=' or whitespace */ - line = getToken(line, &key, &key_len); - /* line now points to '=' or space */ - if (*line && !isspace(*line)) { - line = getToken(++line, &value, &value_len); - } else { - value = line; - value_len = 0; - } - if ((strlen(match) == key_len) - && strncmp(match, key, key_len) == 0) { - // create a new string - char* newstr = malloc(value_len + 1); - strncpy(newstr, value, value_len); - newstr[value_len] = 0; + /* now look for '=' or whitespace */ + line = getToken(line, &key, &key_len); + /* line now points to '=' or space */ + if (*line && !isspace(*line)) { + line = getToken(++line, &value, &value_len); + } else { + value = line; + value_len = 0; + } + if ((strlen(match) == key_len) && strncmp(match, key, key_len) == 0) { + // create a new string + char* newstr = malloc(value_len + 1); + strncpy(newstr, value, value_len); + newstr[value_len] = 0; - *matchval = newstr; - *len = value_len; - retval = true; - /* Continue to look for this key; last one wins. */ + *matchval = newstr; + *len = value_len; + retval = true; + /* Continue to look for this key; last one wins. */ + } } - } - - return retval; + 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; + static const char* value =0; + int len=0; + if(!getValueForKey(key, &value, &len, config)) { + value = 0; + } + return value; } @@ -358,50 +352,47 @@ 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 = true; - } else { - *result_val = false; - } - return true; - } - return false; + if (getValueForKey(key, &key_val, &size, config)) { + if ( (size >= 1) && (key_val[0] == 'Y' || key_val[0] == 'y') ) { + *result_val = true; + } else { + *result_val = false; + } + return true; + } + return false; } bool getIntForKey( const char *key, int *value, config_file_t *config ) { - const char *val; - int size, sum; - bool negative = false; + const char *val; + int size, sum; + bool negative = false; - if (getValueForKey(key, &val, &size, config)) - { - if ( size ) - { - if (*val == '-') - { + if (getValueForKey(key, &val, &size, config)) { + if ( size ) { + if (*val == '-') { negative = true; val++; size--; } - for (sum = 0; size > 0; size--) - { - if (*val < '0' || *val > '9') + for (sum = 0; size > 0; size--) { + if (*val < '0' || *val > '9') { return false; + } sum = (sum * 10) + (*val++ - '0'); } - if (negative) + if (negative) { sum = -sum; - + } *value = sum; return true; } } - return false; + return false; } /* @@ -411,59 +402,57 @@ 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 size = 0; int sum = 0; - + bool negative = false; bool percentage = false; - - if (getValueForKey(key, &val, &size, config)) - { - if ( size ) - { - if (*val == '-') - { + + if (getValueForKey(key, &val, &size, config)) { + if ( size ) { + if (*val == '-') { negative = true; val++; size--; } - - if (val[size-1] == '%') - { + + if (val[size-1] == '%') { percentage = true; size--; } - + // convert string to integer - for (sum = 0; size > 0; size--) - { - if (*val < '0' || *val > '9') + for (sum = 0; size > 0; size--) { + if (*val < '0' || *val > '9') { return false; - + } + sum = (sum * 10) + (*val++ - '0'); } - - if (percentage) + + if (percentage) { sum = ( dimension_max * sum ) / 100; - + } + // calculate offset from opposite origin - if (negative) + if (negative) { sum = ( ( dimension_max - object_size ) - sum ); - + } + } else { - + // null value calculate center sum = ( dimension_max - object_size ) / 2; - + } - + *value = (uint16_t) sum; return true; } - + // key not found - return false; + return false; } /* @@ -472,60 +461,58 @@ bool getColorForKey( const char *key, unsigned int *value, config_file_t *config ) { - const char *val; - int size; - - if (getValueForKey(key, &val, &size, config)) + const char *val; + int size; + + if (getValueForKey(key, &val, &size, config)) { - if (*val == '#') - { - val++; + if (*val == '#') { + val++; *value = strtol(val, NULL, 16); return true; - } - } - return false; + } + } + return false; } bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config ) { - const char *overrideVal; - int overrideSize; - bool override, ret; - - if (getValueForBootKey(bootArgs->CommandLine, key, val, size)) - return true; + const char *overrideVal; + int overrideSize; + bool override, ret; - ret = getValueForConfigTableKey(config, key, val, size); + if (getValueForBootKey(bootArgs->CommandLine, key, val, size)) { + return true; + } - // Try to find alternate keys in bootInfo->chameleonConfig (if config can be overriden) - // and prefer its values with the exceptions for - // "Kernel"="mach_kernel" and "Kernel Flags"="". + ret = getValueForConfigTableKey(config, key, val, size); - if (config->canOverride) - { - if (getValueForConfigTableKey(&bootInfo->chameleonConfig, key, &overrideVal, &overrideSize)) - { - override = true; + // Try to find alternate keys in bootInfo->chameleonConfig (if config can be overriden) + // and prefer its values with the exceptions for + // "Kernel"="mach_kernel" and "Kernel Flags"="". - // NOTE: Values are defined by apple as being in com.apple.Boot.plist - // kHelperRootUUIDKey, kKernelArchKey, kMKextCacheKey, kKernelCacheKey, kKernelNameKey, kKernelFlagsKey - if (ret && (strcmp(key, kKernelNameKey) == 0) && (overrideSize == 0)) - override = false; + if (config->canOverride) { + if (getValueForConfigTableKey(&bootInfo->chameleonConfig, key, &overrideVal, &overrideSize)) { + override = true; - if (ret && (strcmp(key, kKernelFlagsKey) == 0) && (overrideSize == 0)) - override = false; + // NOTE: Values are defined by apple as being in com.apple.Boot.plist + // kHelperRootUUIDKey, kKernelArchKey, kMKextCacheKey, kKernelCacheKey, kKernelNameKey, kKernelFlagsKey + if (ret && (strcmp(key, kKernelNameKey) == 0) && (overrideSize == 0)) { + override = false; + } - if (override) - { - *val = overrideVal; - *size = overrideSize; - return true; - } - } - } + if (ret && (strcmp(key, kKernelFlagsKey) == 0) && (overrideSize == 0)) { + override = false; + } - return ret; + if (override) { + *val = overrideVal; + *size = overrideSize; + return true; + } + } + } + return ret; } @@ -533,15 +520,19 @@ void printSystemConfig(char *p1) { - char *p2 = p1, tmp; + char *p2 = p1, tmp; - while (*p1 != '\0') { - while (*p2 != '\0' && *p2 != '\n') p2++; + while (*p1 != '\0') { + while (*p2 != '\0' && *p2 != '\n') { + p2++; + } tmp = *p2; *p2 = '\0'; printf("%s\n", p1); *p2 = tmp; - if (tmp == '\0') break; + if (tmp == '\0') { + break; + } p1 = ++p2; } } @@ -558,33 +549,38 @@ // int ParseXMLFile( char * buffer, TagPtr * dict ) { - long length, pos; - TagPtr tag; - pos = 0; - char *configBuffer; + long length, pos; + TagPtr tag; + pos = 0; + char *configBuffer; - configBuffer = malloc(strlen(buffer)+1); - strcpy(configBuffer, buffer); + configBuffer = malloc(strlen(buffer)+1); + strcpy(configBuffer, buffer); - while (1) - { - length = XMLParseNextTag(configBuffer + pos, &tag); - if (length == -1) break; - - pos += length; - - if (tag == 0) continue; - if (tag->type == kTagTypeDict) break; - - XMLFreeTag(tag); - } - free(configBuffer); - if (length < 0) { - error ("Error parsing plist file\n"); - return -1; - } - *dict = tag; - return 0; + while (1) { + length = XMLParseNextTag(configBuffer + pos, &tag); + if (length == -1) { + break; + } + + pos += length; + + if (tag == 0) { + continue; + } + if (tag->type == kTagTypeDict) { + break; + } + + XMLFreeTag(tag); + } + free(configBuffer); + if (length < 0) { + error ("Error parsing plist file\n"); + return -1; + } + *dict = tag; + return 0; } /* loadConfigFile @@ -602,7 +598,7 @@ // read file count = read(fd, config->plist, IO_CONFIG_DATA_SIZE); close(fd); - + // build xml dictionary ParseXMLFile(config->plist, &config->dictionary); return 0; @@ -623,19 +619,17 @@ int i, fd, count, ret=-1; - for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) - { - if ((fd = open(dirspec[i], 0)) >= 0) - { + for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) { + if ((fd = open(dirspec[i], 0)) >= 0) { // read file count = read(fd, config->plist, IO_CONFIG_DATA_SIZE); close(fd); - + // build xml dictionary ParseXMLFile(config->plist, &config->dictionary); sysConfigValid = true; ret=0; - + break; } } @@ -667,18 +661,15 @@ int i, fd, count, ret=-1; - for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) - { - if ((fd = open(dirspec[i], 0)) >= 0) - { - // Check for depreciated file names and annoy the user about it. - if(strstr(dirspec[i], "com.apple.Boot.plist")) - { - printf("%s is depreciated.\n", dirspec[i]); - dirspec[i][strlen(dirspec[i]) - strlen("com.apple.Boot.plist")] = 0; - printf("Please use the file %sorg.chameleon.Boot.plist instead.\n", dirspec[i]); - pause(); - } + for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) { + if ((fd = open(dirspec[i], 0)) >= 0) { + // Check for depreciated file names and annoy the user about it. + if(strstr(dirspec[i], "com.apple.Boot.plist")) { + printf("%s is depreciated.\n", dirspec[i]); + dirspec[i][strlen(dirspec[i]) - strlen("com.apple.Boot.plist")] = 0; + printf("Please use the file %sorg.chameleon.Boot.plist instead.\n", dirspec[i]); + pause(); + } // read file count = read(fd, config->plist, IO_CONFIG_DATA_SIZE); close(fd); @@ -708,10 +699,8 @@ int i, fd, count, ret=-1; - for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) - { - if ((fd = open(dirspec[i], 0)) >= 0) - { + for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++) { + if ((fd = open(dirspec[i], 0)) >= 0) { // read file count = read(fd, config->plist, IO_CONFIG_DATA_SIZE); close(fd); @@ -728,10 +717,11 @@ char * newString(const char * oldString) { - if ( oldString ) - return strcpy(malloc(strlen(oldString)+1), oldString); - else - return NULL; + if ( oldString ) { + return strcpy(malloc(strlen(oldString)+1), oldString); + } else { + return NULL; + } } /* @@ -739,52 +729,50 @@ */ char * getNextArg(char ** argPtr, char * val) { - char * ptr = *argPtr; - const char * strStart; - int len = 0; - bool isQuoted = false; + char * ptr = *argPtr; + const char * strStart; + int len = 0; + bool isQuoted = false; - *val = '\0'; + *val = '\0'; - // Scan for the next non-whitespace character. - while ( *ptr && (*ptr == ' ' || *ptr == '=') ) - { - ptr++; - } + // Scan for the next non-whitespace character. + while ( *ptr && (*ptr == ' ' || *ptr == '=') ) { + ptr++; + } - strStart = ptr; + strStart = ptr; - // Skip the leading double quote character. - if (*ptr == '\"') - { - isQuoted = true; - ptr++; - strStart++; - } + // Skip the leading double quote character. + if (*ptr == '\"') { + isQuoted = true; + ptr++; + strStart++; + } - // Scan for the argument terminator character. - // This can be either a NULL character - in case we reach the end of the string, - // a double quote in case of quoted argument, - // or a whitespace character (' ' or '=') for non-quoted argument. - while (*ptr && !( (isQuoted && (*ptr == '\"')) || + // Scan for the argument terminator character. + // This can be either a NULL character - in case we reach the end of the string, + // a double quote in case of quoted argument, + // or a whitespace character (' ' or '=') for non-quoted argument. + while (*ptr && !( (isQuoted && (*ptr == '\"')) || (!isQuoted && (*ptr == ' ' || *ptr == '=')) ) - ) - { - ptr++; - } + ) { + ptr++; + } - len = ptr - strStart; + len = ptr - strStart; - // Skip the closing double quote character and adjust - // the starting pointer for the next getNextArg call. - if (*ptr && isQuoted && *ptr == '\"') - ptr++; + // Skip the closing double quote character and adjust + // the starting pointer for the next getNextArg call. + if (*ptr && isQuoted && *ptr == '\"') { + ptr++; + } - // Copy the extracted argument to val. - strncat(val, strStart, len); + // Copy the extracted argument to val. + strncat(val, strStart, len); - // Set command line pointer. - *argPtr = ptr; + // Set command line pointer. + *argPtr = ptr; - return ptr; + return ptr; } Index: trunk/i386/libsaio/convert.c =================================================================== --- trunk/i386/libsaio/convert.c (revision 2343) +++ trunk/i386/libsaio/convert.c (revision 2344) @@ -104,10 +104,11 @@ { binChar = 0; - for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) - { - if (hexNibbleIdx > 0) binChar = binChar << 4; - + for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) { + if (hexNibbleIdx > 0) { + binChar = binChar << 4; + } + if (hexByte[hexNibbleIdx] <= '9') binChar += hexByte[hexNibbleIdx] - '0'; else if (hexByte[hexNibbleIdx] <= 'F') binChar += hexByte[hexNibbleIdx] - ('A' - 10); else if (hexByte[hexNibbleIdx] <= 'f') binChar += hexByte[hexNibbleIdx] - ('a' - 10); Index: trunk/i386/libsaio/saio_types.h =================================================================== --- trunk/i386/libsaio/saio_types.h (revision 2343) +++ trunk/i386/libsaio/saio_types.h (revision 2344) @@ -157,7 +157,7 @@ char * i_buf; /* file load address */ }; -#define BPS 512 /* sector size of the device */ +#define BPS 512 /* sector size of the device */ #define F_READ 0x1 /* file opened for reading */ #define F_WRITE 0x2 /* file opened for writing */ #define F_ALLOC 0x4 /* buffer allocated */ @@ -169,7 +169,7 @@ struct dirstuff { char * dir_path; /* directory path */ long long dir_index; /* directory entry index */ - BVRef dir_bvr; /* volume reference */ + BVRef dir_bvr; /* volume reference */ }; #define BVSTRLEN 32 @@ -217,7 +217,7 @@ enum { kBIOSDevTypeFloppy = 0x00, - kBIOSDevTypeHardDrive = 0x80, + kBIOSDevTypeHardDrive = 0x80, kBIOSDevTypeNetwork = 0xE0, kBIOSDevUnitMask = 0x0F, kBIOSDevTypeMask = 0xF0, @@ -238,9 +238,8 @@ //#define BIOS_DEV_TYPE(d) ((d) & kBIOSDevTypeMask) #define BIOS_DEV_UNIT(bvr) ((bvr)->biosdev - (bvr)->type) -/* - * KernBootStruct device types. - */ +// KernBootStruct device types. + enum { DEV_SD = 0, DEV_HD = 1, @@ -271,7 +270,7 @@ }; //gBootFileType_t; enum { - kCursorTypeHidden = 0x0100, + kCursorTypeHidden = 0x0100, kCursorTypeUnderline = 0x0607 }; Index: trunk/i386/include/string.h =================================================================== --- trunk/i386/include/string.h (revision 2343) +++ trunk/i386/include/string.h (revision 2344) @@ -108,6 +108,7 @@ int strncmp(const char *, const char *, size_t); char *strncpy(char *, const char *, size_t); #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE) +char *stpncpy(char *, const char *, size_t); char *strnstr(const char *, const char *, size_t); #endif /* (!_POSIX_C_SOURCE || _DARWIN_C_SOURCE) */ char *strpbrk(const char *, const char *); Index: trunk/i386/include/mach/mach.h =================================================================== --- trunk/i386/include/mach/mach.h (revision 2343) +++ trunk/i386/include/mach/mach.h (revision 2344) @@ -49,9 +49,7 @@ * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. - */ - -/* + * * Includes all the types that a normal user * of Mach programs should need */ Index: trunk/i386/boot2/mboot.c =================================================================== --- trunk/i386/boot2/mboot.c (revision 2343) +++ trunk/i386/boot2/mboot.c (revision 2344) @@ -433,7 +433,7 @@ multiboot_skip_partition = intVal; multiboot_skip_partition_set = 1; } - } + } } if(doSelectDevice) { Index: trunk/i386/boot2/resume.c =================================================================== --- trunk/i386/boot2/resume.c (revision 2343) +++ trunk/i386/boot2/resume.c (revision 2344) @@ -22,21 +22,19 @@ static unsigned long getmemorylimit(void) { - int line; - int i; - MemoryRange *mp = bootInfo->memoryMap; + int line; + int i; + MemoryRange *mp = bootInfo->memoryMap; - // Activate and clear page 1 - line = 1; - for (i = 0; i < bootInfo->memoryMapCount; i++) - { - if((mp->type == 1) && ((unsigned long)mp->base == 0x100000)) - { - return (unsigned long)(mp->base + mp->length); - } - mp++; - } - return 0x10000000; + // Activate and clear page 1 + line = 1; + for (i = 0; i < bootInfo->memoryMapCount; i++) { + if((mp->type == 1) && ((unsigned long)mp->base == 0x100000)) { + return (unsigned long)(mp->base + mp->length); + } + mp++; + } + return 0x10000000; } static void WakeKernel(IOHibernateImageHeader * header) @@ -50,25 +48,25 @@ int32_t byteCnt; u_int32_t lowHalf, highHalf; u_int32_t sum; - + printf("\nWake Kernel!\n"); - + dst = (unsigned long *) (header->restore1CodePage << 12); count = header->restore1PageCount; proc = (header->restore1CodeOffset + ((uint32_t) dst)); newSP = header->restore1StackOffset + (header->restore1CodePage << 12); - + src = (unsigned long *) (((u_int32_t) &header->fileExtentMap[0]) + header->fileExtentMapSize); sum = 0; - + for (page = 0; page < count; page++) { compressedSize = 4096; - + lowHalf = 1; highHalf = 0; - + for (cnt = 0; cnt < compressedSize; cnt += 0x20) { dst[0] = src[0]; dst[1] = src[1]; @@ -85,14 +83,14 @@ src += 8; dst += 8; } - + lowHalf %= 65521L; highHalf %= 65521L; sum += (highHalf << 16) | lowHalf; } header->actualRestore1Sum = sum; startprog (proc, header); - + return; } @@ -103,19 +101,17 @@ IOHibernateImageHeader _header; IOHibernateImageHeader * header = &_header; long buffer; - + size = ReadFileAtOffset (image_filename, header, 0, sizeof(IOHibernateImageHeader)); printf("header read size %x\n", size); imageSize = header->image1Size; codeSize = header->restore1PageCount << 12; - if (kIOHibernateHeaderSignature != header->signature) - { + if (kIOHibernateHeaderSignature != header->signature) { printf ("Incorrect image signature\n"); return; } - if (header->encryptStart) - { + if (header->encryptStart) { printf ("Resuming from Encrypted image is unsupported.\n" "Uncheck \"Use secure virtual memory\" in \"Security\" pane on system preferences.\n" "Press any key to proceed with normal boot.\n"); @@ -128,9 +124,12 @@ uint32_t machineSignature; size = GetProp(gChosenPH, kIOHibernateMachineSignatureKey, (char *)&machineSignature, sizeof(machineSignature)); - if (size != sizeof(machineSignature)) machineSignature = 0; - if (machineSignature != header->machineSignature) + if (size != sizeof(machineSignature)) { + machineSignature = 0; + } + if (machineSignature != header->machineSignature) { break; + } } #endif @@ -139,21 +138,19 @@ mem_base = getmemorylimit() - allocSize;//TODO: lower this 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"); getchar(); return; } - + bcopy(header, (void *) mem_base, sizeof(IOHibernateImageHeader)); header = (IOHibernateImageHeader *) mem_base; imageSize -= sizeof(IOHibernateImageHeader); buffer = (long)(header + 1); - if (header->previewSize) - { + if (header->previewSize) { uint64_t preview_offset = header->fileExtentMapSize - sizeof(header->fileExtentMap) + codeSize; uint8_t progressSaveUnder[kIOHibernateProgressCount][kIOHibernateProgressSaveUnderSize]; @@ -162,10 +159,11 @@ previewTotalSectors = (imageSize-(preview_offset+header->previewSize))/512; previewLoadedSectors = 0; previewSaveunder = &(progressSaveUnder[0][0]); - if (preview_offset+header->previewSizepreviewSizepreviewSize), sizeof(IOHibernateImageHeader)+preview_offset+header->previewSize, imageSize-(preview_offset+header->previewSize)); + } previewTotalSectors = 0; previewLoadedSectors = 0; previewSaveunder = 0; @@ -177,10 +175,9 @@ remove it completely setVideoMode( VGA_TEXT_MODE, 0 ); #endif - } - else + } else { ReadFileAtOffset (image_filename, (char *)buffer, sizeof(IOHibernateImageHeader), imageSize); - + } // Depends on NVRAM #if 0 if (header->encryptStart) { @@ -210,6 +207,6 @@ bzero(&decryptkey, sizeof(decryptkey)); } #endif - + WakeKernel(header); } Index: trunk/i386/boot2/boot.h =================================================================== --- trunk/i386/boot2/boot.h (revision 2343) +++ trunk/i386/boot2/boot.h (revision 2344) @@ -144,6 +144,7 @@ /* ErmaC: added these keys */ #define kEnableDualLink "EnableDualLink" /* nvidia.c && gma.c*/ +#define kNvidiaGeneric "NvidiaGeneric" /* nvidia.c */ #define kSkipIntelGfx "SkipIntelGfx" /* pci_setup.c */ #define kSkipNvidiaGfx "SkipNvidiaGfx" /* pci_setup.c */ #define kSkipAtiGfx "SkipAtiGfx" /* pci_setup.c */ @@ -157,6 +158,10 @@ /* Karas: added these keys */ #define kMemFullInfo "ForceFullMemInfo" /* smbios.c */ +/* Bungo: added these keys */ +// mask private data or no +#define kPrivateData "PrivateData" /* smbios_decode.c */ + /* * Flags to the booter or kernel */ Index: trunk/i386/boot2/gui.c =================================================================== --- trunk/i386/boot2/gui.c (revision 2343) +++ trunk/i386/boot2/gui.c (revision 2344) @@ -36,8 +36,8 @@ * ATTENTION: the enum and the following array images[] MUST match !!! */ enum { - iBackground = 0, - iLogo, + iBackground = 0, + iLogo, iDeviceGeneric, iDeviceGeneric_o, @@ -55,6 +55,7 @@ iDeviceHFS_Leo_o, iDeviceHFS_Tiger, iDeviceHFS_Tiger_o, + iDeviceHFSRAID, iDeviceHFSRAID_o, iDeviceHFSRAID_mav, @@ -233,10 +234,8 @@ static int getImageIndexByName(const char *name) { int i; - for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) - { - if (strcmp(name, images[i].name) == 0) - { + for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) { + if (strcmp(name, images[i].name) == 0) { return i; // found the name } } @@ -256,26 +255,18 @@ // generated manualy, this *will* fail to work properly. while((result = strcmp(name, embeddedImages[compareIndex].name)) != 0) { - if (result > 0) // We need to search a HIGHER index - { - if (compareIndex != lowerLimit) - { + if (result > 0) { // We need to search a HIGHER index + if (compareIndex != lowerLimit) { lowerLimit = compareIndex; - } - else - { + } else { return -1; } compareIndex = (upperLimit + lowerLimit + 1) >> 1; // Midpoint, round up } - else // We Need to search a LOWER index - { - if (compareIndex != upperLimit) - { + else { // We Need to search a LOWER index + if (compareIndex != upperLimit) { upperLimit = compareIndex; - } - else - { + } else { return -1; } compareIndex = (upperLimit + lowerLimit) >> 1; // Midpoint, round down @@ -296,44 +287,43 @@ uint16_t height; uint8_t *imagedata; - if ((strlen(image) + strlen(theme_name) + 20) > sizeof(dirspec)) + if ((strlen(image) + strlen(theme_name) + 20) > sizeof(dirspec)) { return 1; - if ((i = getImageIndexByName(image)) < 0) + } + if ((i = getImageIndexByName(image)) < 0) { return 1; - if (!images[i].image && !(images[i].image = malloc(sizeof(pixmap_t)))) + } + if (!images[i].image && !(images[i].image = malloc(sizeof(pixmap_t)))) { return 1; - sprintf(dirspec, "/Extra/Themes/%s/%s.png", theme_name, image); - width = 0; - height = 0; - imagedata = NULL; - if ((loadPngImage(dirspec, &width, &height, &imagedata)) == 0) - { - images[i].image->width = width; - images[i].image->height = height; - images[i].image->pixels = (pixel_t *)imagedata; - flipRB(images[i].image); - return 0; - } + } + sprintf(dirspec, "/Extra/Themes/%s/%s.png", theme_name, image); + width = 0; + height = 0; + imagedata = NULL; + if ((loadPngImage(dirspec, &width, &height, &imagedata)) == 0) { + images[i].image->width = width; + images[i].image->height = height; + images[i].image->pixels = (pixel_t *)imagedata; + flipRB(images[i].image); + return 0; + } #ifdef CONFIG_EMBED_THEME - else if ((e = getEmbeddedImageIndexByName(image)) >= 0) - { - unsigned char *embed_data; - unsigned int embed_size; - embed_data = embeddedImages[e].pngdata; - embed_size = *embeddedImages[e].length; + else if ((e = getEmbeddedImageIndexByName(image)) >= 0) { + unsigned char *embed_data; + unsigned int embed_size; + embed_data = embeddedImages[e].pngdata; + embed_size = *embeddedImages[e].length; - if (loadEmbeddedPngImage(embed_data, embed_size, &width, &height, &imagedata) == 0) - { - images[i].image->width = width; - images[i].image->height = height; - images[i].image->pixels = (pixel_t *)imagedata; - flipRB(images[i].image); - return 0; + if (loadEmbeddedPngImage(embed_data, embed_size, &width, &height, &imagedata) == 0) { + images[i].image->width = width; + images[i].image->height = height; + images[i].image->pixels = (pixel_t *)imagedata; + flipRB(images[i].image); + return 0; } } #endif - else if (alt_image != IMG_REQUIRED && is_image_loaded(alt_image)) - { + else if (alt_image != IMG_REQUIRED && is_image_loaded(alt_image)) { // Using the passed alternate image for non-mandatory images. // We don't clone the already existing pixmap, but using its properties instead! images[i].image->width = images[alt_image].image->width; @@ -440,17 +430,17 @@ static int unloadGraphics(void) { - int i; + int i; - destroyFont(&font_console); - destroyFont(&font_small); - for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) - { - if (images[i].image) - { - if (images[i].image->pixels) free(images[i].image->pixels); - free (images[i].image); - images[i].image = 0; + destroyFont(&font_console); + destroyFont(&font_small); + for (i = 0; i < sizeof(images) / sizeof(images[0]); i++) { + if (images[i].image) { + if (images[i].image->pixels) { + free(images[i].image->pixels); + } + free (images[i].image); + images[i].image = 0; } } return 0; @@ -458,37 +448,34 @@ int freeBackBuffer( window_t *window ) { - if (gui.backbuffer && gui.backbuffer->pixels) - { - free(gui.backbuffer->pixels); - free(gui.backbuffer); - gui.backbuffer = 0; - return 0; - } + if (gui.backbuffer && gui.backbuffer->pixels) { + free(gui.backbuffer->pixels); + free(gui.backbuffer); + gui.backbuffer = 0; + return 0; + } - return 1; + return 1; } pixmap_t *getCroppedPixmapAtPosition( pixmap_t *from, position_t pos, uint16_t width, uint16_t height ) { - pixmap_t *cropped = malloc( sizeof( pixmap_t ) ); - if( !cropped ) + if( !cropped ) { return 0; + } cropped->pixels = malloc( width * height * 4 ); - if ( !cropped->pixels ) + if ( !cropped->pixels ) { return 0; - + } cropped->width = width; cropped->height = height; int destx = 0, desty = 0; int srcx = pos.x, srcy = pos.y; - for( ; desty < height; desty++, srcy++) - { - for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ ) - { + for( ; desty < height; desty++, srcy++) { + for( destx = 0, srcx = pos.x; destx < width; destx++, srcx++ ) { pixel( cropped, destx, desty ).value = pixel( from, srcx, srcy ).value; } } @@ -498,13 +485,11 @@ int createBackBuffer( window_t *window ) { gui.backbuffer = malloc(sizeof(pixmap_t)); - if(!gui.backbuffer) - { + if(!gui.backbuffer) { return 1; } gui.backbuffer->pixels = malloc( window->width * window->height * 4 ); - if(!gui.backbuffer->pixels) - { + if(!gui.backbuffer->pixels) { free(gui.backbuffer); gui.backbuffer = 0; return 1; @@ -519,14 +504,12 @@ int createWindowBuffer( window_t *window ) { window->pixmap = malloc(sizeof(pixmap_t)); - if(!window->pixmap) - { + if(!window->pixmap) { return 1; } window->pixmap->pixels = malloc( window->width * window->height * 4 ); - if(!window->pixmap->pixels) - { + if(!window->pixmap->pixels) { free(window->pixmap); window->pixmap = 0; return 1; @@ -540,13 +523,11 @@ int freeWindowBuffer( window_t *window ) { - if (window->pixmap && window->pixmap->pixels) - { + if (window->pixmap && window->pixmap->pixels) { free(window->pixmap->pixels); free(window->pixmap); return 0; } - return 1; } @@ -555,9 +536,11 @@ int x,y; // fill with given color AARRGGBB - for( x=0; x < pm->width; x++ ) - for( y=0; y< pm->height; y++) + for( x=0; x < pm->width; x++ ) { + for( y=0; y< pm->height; y++) { pixel(pm,x,y).value = color; + } + } } void drawBackground() @@ -574,7 +557,7 @@ // draw logo.png into background buffer if (gui.logo.draw) { - blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos); + blend( images[iLogo].image, gui.screen.pixmap, gui.logo.pos); } memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); @@ -583,16 +566,18 @@ void setupDeviceList(config_file_t *theme) { unsigned int pixel; - int alpha; // transparency level 0 (obligue) - 255 (transparent) + int alpha; // transparency level 0 (obligue) - 255 (transparent) uint32_t color; // color value formatted RRGGBB int val, len; const char *string; - if(getIntForKey("devices_max_visible", &val, theme )) + if(getIntForKey("devices_max_visible", &val, theme )) { gui.maxdevices = MIN( val, gDeviceCount ); + } - if(getIntForKey("devices_iconspacing", &val, theme )) + if(getIntForKey("devices_iconspacing", &val, theme )) { gui.devicelist.iconspacing = val; + } // check layout for horizontal or vertical gui.layout = HorizontalLayout; @@ -607,11 +592,13 @@ 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 ) ) + 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 ) ) + if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) ) { gui.devicelist.pos.y = pixel; + } break; case HorizontalLayout: @@ -619,29 +606,33 @@ 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 ) ) + if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) ) { gui.devicelist.pos.x = pixel; - else + } 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 + } else { gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2; + } break; } - if(getColorForKey("devices_bgcolor", &color, theme)) + if(getColorForKey("devices_bgcolor", &color, theme)) { gui.devicelist.bgcolor = (color & 0x00FFFFFF); + } - if(getIntForKey("devices_transparency", &alpha, theme)) + if(getIntForKey("devices_transparency", &alpha, theme)) { gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); + } - if (gui.devicelist.pixmap) - { - freeWindowBuffer(&gui.devicelist); - createWindowBuffer(&gui.devicelist); - } + if (gui.devicelist.pixmap) { + freeWindowBuffer(&gui.devicelist); + createWindowBuffer(&gui.devicelist); + } } void loadThemeValues(config_file_t *theme) @@ -649,21 +640,22 @@ 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) + int alpha; // transparency level 0 (obligue) - 255 (transparent) uint32_t color; // color value formatted RRGGBB int val; /* * Parse screen parameters */ - if(getColorForKey("screen_bgcolor", &color, theme )) + if(getColorForKey("screen_bgcolor", &color, theme )) { gui.screen.bgcolor = (color & 0x00FFFFFF); - - if(getIntForKey("screen_textmargin_h", &val, theme)) + } + if(getIntForKey("screen_textmargin_h", &val, theme)) { gui.screen.hborder = MIN( gui.screen.width , val ); - - if(getIntForKey("screen_textmargin_v", &val, theme)) + } + if(getIntForKey("screen_textmargin_v", &val, theme)) { gui.screen.vborder = MIN( gui.screen.height , val ); + } /* * Parse background parameters @@ -671,35 +663,47 @@ 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 ) ) + if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) ) { gui.background.pos.y = pixel; + } /* * Parse logo parameters */ - if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) ) + 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 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 @@ -710,92 +714,124 @@ * 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("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) ) + { gui.infobox.pos.x = pixel; - + } 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 ); - + } 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; + } 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); + } /* * Parse bootprompt parameters */ 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 ); - + } 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) @@ -811,12 +847,12 @@ sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name); if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) { #ifdef CONFIG_EMBED_THEME - config_file_t *config; + config_file_t *config; - config = &bootInfo->themeConfig; - if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) { - return 1; - } + config = &bootInfo->themeConfig; + if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) { + return 1; + } #else return 1; #endif @@ -852,7 +888,7 @@ if (createWindowBuffer(&gui.bootprompt) == 0) { if (createWindowBuffer(&gui.infobox) == 0) { if (createWindowBuffer(&gui.menu) == 0) { - gui.logo.draw = true; + gui.logo.draw = true; drawBackground(); // lets copy the screen into the back buffer memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); @@ -888,10 +924,9 @@ { int devicetype; - if( diskIsCDROM(device) ) + if( diskIsCDROM(device) ) { devicetype = iDeviceCDROM; // Use CDROM icon - else - { + } else { switch (device->part_type) { case kPartitionTypeHFS: @@ -923,7 +958,7 @@ break; - } + } case kPartitionTypeHPFS: devicetype = iDeviceNTFS; // Use HPFS / NTFS icon break; @@ -988,8 +1023,7 @@ makeRoundedCorners( gui.devicelist.pixmap); - switch (gui.layout) - { + switch (gui.layout) { case VerticalLayout: p.x = (gui.devicelist.width /2); @@ -1016,31 +1050,26 @@ } // draw visible device icons - for (i = 0; i < gui.maxdevices; i++) - { + for (i = 0; i < gui.maxdevices; i++) { BVRef param = menuItems[start + i].param; - bool isSelected = ((start + i) == selection) ? true : false; - if (isSelected) - { - if (param->flags & kBVFlagNativeBoot) - { - infoMenuNativeBoot = true; - } - else - { - infoMenuNativeBoot = false; - if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) - infoMenuSelection = 0; - } + bool isSelected = ((start + i) == selection) ? true : false; + if (isSelected) { + if (param->flags & kBVFlagNativeBoot) { + infoMenuNativeBoot = true; + } else { + infoMenuNativeBoot = false; + if(infoMenuSelection >= INFOMENU_NATIVEBOOT_START && infoMenuSelection <= INFOMENU_NATIVEBOOT_END) { + infoMenuSelection = 0; + } + } - if (gui.menu.draw) + if (gui.menu.draw) { drawInfoMenuItems(); - + } getBoolForKey(kShowInfoKey, &shoWinfo, &bootInfo->chameleonConfig); - if (shoWinfo && showBootBanner) - { + if (shoWinfo && showBootBanner) { gui.debug.cursor = pos( 10, 100); dprintf( &gui.screen, "label: %s\n", param->label ); dprintf( &gui.screen, "biosdev: 0x%x\n", param->biosdev ); @@ -1063,24 +1092,22 @@ drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected); - if (gui.layout == HorizontalLayout) - { + if (gui.layout == HorizontalLayout) { p.x += images[iSelection].image->width + gui.devicelist.iconspacing; } - if (gui.layout == VerticalLayout) - { + if (gui.layout == VerticalLayout) { p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing ); } } // draw prev indicator - if (start) + if (start) { blend( images[iDeviceScrollPrev].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollPrev].image, p_prev ) ); - + } // draw next indicator - if ( end < gDeviceCount - 1 ) + if ( end < gDeviceCount - 1 ) { blend( images[iDeviceScrollNext].image, gui.devicelist.pixmap, centeredAt( images[iDeviceScrollNext].image, p_next ) ); - + } gui.redraw = true; updateVRAM(); @@ -1094,8 +1121,7 @@ //prompt_pos=0; - if( gui.bootprompt.draw == true ) - { + if( gui.bootprompt.draw == true ) { gui.bootprompt.draw = false; gui.redraw = true; // this causes extra frames to be drawn @@ -1133,20 +1159,17 @@ static inline void vramwrite (void *data, int width, int height) { - if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) + if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) { memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height)); - else - { + } else { uint32_t r, g, b; int i, j; - for (i = 0; i < VIDEO (height); i++) - for (j = 0; j < VIDEO (width); j++) - { + for (i = 0; i < VIDEO (height); i++) { + for (j = 0; j < VIDEO (width); j++) { b = ((uint8_t *) data)[4*i*width + 4*j]; g = ((uint8_t *) data)[4*i*width + 4*j + 1]; r = ((uint8_t *) data)[4*i*width + 4*j + 2]; - switch (VIDEO (depth)) - { + switch (VIDEO (depth)) { case 32: *(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16); break; @@ -1163,30 +1186,30 @@ break; } } + } } } void updateVRAM() { - if (gui.redraw) - { - if (gui.devicelist.draw) + if (gui.redraw) { + if (gui.devicelist.draw) { blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos ); - - if (gui.bootprompt.draw) + } + if (gui.bootprompt.draw) { blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos ); - - if (gui.menu.draw) + } + if (gui.menu.draw) { blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos ); - - if (gui.infobox.draw) + } + if (gui.infobox.draw) { blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos ); + } } vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height ); - if (gui.redraw) - { + if (gui.redraw) { memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); gui.redraw = false; } @@ -1194,20 +1217,21 @@ struct putc_info //Azi: exists on console.c & printf.c { - char * str; - char * last_str; + char * str; + char * last_str; }; static int sputc(int c, struct putc_info * pi) //Azi: same as above { - if (pi->last_str) - if (pi->str == pi->last_str) { - *(pi->str) = '\0'; - return 0; - } - *(pi->str)++ = c; - return c; + if (pi->last_str) { + if (pi->str == pi->last_str) { + *(pi->str) = '\0'; + return 0; + } + } + *(pi->str)++ = c; + return c; } int gprintf( window_t * window, const char * fmt, ...) @@ -1242,44 +1266,44 @@ font_t *font = &font_console; - for( i=0; i< strlen(formattedtext); i++ ) - { + for( i=0; i< strlen(formattedtext); i++ ) { character = formattedtext[i]; character -= 32; // newline ? - if( formattedtext[i] == '\n' ) - { + if( formattedtext[i] == '\n' ) { cursor.x = window->hborder; cursor.y += font->height; - if ( cursor.y > bounds.y ) + if ( cursor.y > bounds.y ) { cursor.y = origin.y; - + } continue; } // tab ? - if( formattedtext[i] == '\t' ) + if( formattedtext[i] == '\t' ) { cursor.x += ( font->chars[0]->width * 5 ); - + } + // draw the character - if( font->chars[character]) + if( font->chars[character]) { blend(font->chars[character], window->pixmap, cursor); + } cursor.x += font->chars[character]->width; // check x pos and do newline - if ( cursor.x > bounds.x ) - { + if ( cursor.x > bounds.x ) { cursor.x = origin.x; cursor.y += font->height; } // check y pos and reset to origin.y - if ( cursor.y > bounds.y ) + if ( cursor.y > bounds.y ) { cursor.y = origin.y; + } } // update cursor postition @@ -1288,7 +1312,6 @@ free(formattedtext); return 0; - } return 1; } @@ -1327,44 +1350,42 @@ font_t *font = &font_console; - for( i=0; i< strlen(formattedtext); i++ ) - { + for( i=0; i< strlen(formattedtext); i++ ) { character = formattedtext[i]; character -= 32; // newline ? - if( formattedtext[i] == '\n' ) - { + if( formattedtext[i] == '\n' ) { cursor.x = window->hborder; cursor.y += font->height; - if ( cursor.y > bounds.y ) + if ( cursor.y > bounds.y ) { cursor.y = origin.y; - + } continue; } // tab ? - if( formattedtext[i] == '\t' ) + if( formattedtext[i] == '\t' ) { cursor.x += ( font->chars[0]->width * 5 ); - + } // draw the character - if( font->chars[character]) + if( font->chars[character]) { blend(font->chars[character], gui.backbuffer, cursor); - + } cursor.x += font->chars[character]->width; // check x pos and do newline - if ( cursor.x > bounds.x ) - { + if ( cursor.x > bounds.x ) { cursor.x = origin.x; cursor.y += font->height; } // check y pos and reset to origin.y - if ( cursor.y > bounds.y ) + if ( cursor.y > bounds.y ) { cursor.y = origin.y; + } } // update cursor postition @@ -1403,18 +1424,15 @@ bounds.y = ( window->height - ( window->vborder * 2 ) ); cursor = origin; - for( i=0; i< strlen(formattedtext); i++ ) - { + for( i=0; i< strlen(formattedtext); i++ ) { character = formattedtext[i]; character -= 32; // newline ? - if( formattedtext[i] == '\n' ) - { + if( formattedtext[i] == '\n' ) { cursor.x = window->hborder; cursor.y += font->height; - if ( cursor.y > bounds.y ) - { + if ( cursor.y > bounds.y ) { gui.redraw = true; updateVRAM(); cursor.y = window->vborder; @@ -1424,30 +1442,28 @@ } // tab ? - if( formattedtext[i] == '\t' ) - { + if( formattedtext[i] == '\t' ) { cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 ); continue; } cursor.x += font->chars[character]->width; // check x pos and do newline - if ( cursor.x > bounds.x ) - { + if ( cursor.x > bounds.x ) { cursor.x = origin.x; cursor.y += font->height; } // check y pos and reset to origin.y - if ( cursor.y > ( bounds.y + font->chars[0]->height) ) - { + if ( cursor.y > ( bounds.y + font->chars[0]->height) ) { gui.redraw = true; updateVRAM(); cursor.y = window->vborder; } // draw the character - if( font->chars[character]) + if( font->chars[character]) { blend(font->chars[character], gui.backbuffer, cursor); + } } // save cursor postition window->cursor.x = cursor.x; @@ -1460,22 +1476,21 @@ pixmap_t* charToPixmap(unsigned char ch, font_t *font) { unsigned int cha = (unsigned int)ch - 32; - if (cha >= font->count) + if (cha >= font->count) { // return ? if the font for the char doesn't exists cha = '?' - 32; - + } return font->chars[cha] ? font->chars[cha] : NULL; } position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) { pixmap_t* pm = charToPixmap(ch, font); - if (pm && ((p.x + pm->width) < blendInto->width)) - { + if (pm && ((p.x + pm->width) < blendInto->width)) { blend(pm, blendInto, p); return pos(p.x + pm->width, p.y); - } - else + } else { return p; + } } void drawStr(char *ch, font_t *font, pixmap_t *blendInto, position_t p) @@ -1483,19 +1498,16 @@ int i=0; position_t current_pos = pos(p.x, p.y); - for (i=0; i < strlen(ch); i++) - { + for (i=0; i < strlen(ch); i++) { // newline ? - if ( ch[i] == '\n' ) - { + if ( ch[i] == '\n' ) { current_pos.x = p.x; current_pos.y += font->height; continue; } // tab ? - if ( ch[i] == '\t' ) - { + if ( ch[i] == '\t' ) { current_pos.x += TAB_PIXELS_WIDTH; continue; } @@ -1513,21 +1525,20 @@ // calculate the width in pixels for (i=0; i < strlen(text); i++) { - if (text[i] == '\n') - { + if (text[i] == '\n') { width = 0; height += font->height; - } - else if (text[i] == '\t') + } else if (text[i] == '\t') { width += TAB_PIXELS_WIDTH; - else - { + } else { pixmap_t* pm = charToPixmap(text[i], font); - if (pm) + if (pm) { width += pm->width; + } } - if (width > max_width) + if (width > max_width) { max_width = width; + } } p.x = ( p.x - ( max_width / 2 ) ); @@ -1538,17 +1549,17 @@ int destroyFont(font_t *font) { - int i; - for (i = 0; i < CHARACTERS_COUNT; i++) - { - if (font->chars[i]) - { - if (font->chars[i]->pixels) free (font->chars[i]->pixels); - free (font->chars[i]); - font->chars[i] = 0; - } - } - return 0; + int i; + for (i = 0; i < CHARACTERS_COUNT; i++) { + if (font->chars[i]) { + if (font->chars[i]->pixels) { + free (font->chars[i]->pixels); + } + free (font->chars[i]); + font->chars[i] = 0; + } + } + return 0; } int initFont(font_t *font, image_t *data) @@ -1561,35 +1572,30 @@ font->height = data->image->height; - for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) - { + for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) { start = end; // if the pixel is red we've reached the end of the char - if( pixel( data->image, x, 0 ).value == 0xFFFF0000) - { + if( pixel( data->image, x, 0 ).value == 0xFFFF0000) { end = x + 1; - if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) - { + if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) { font->chars[count]->width = ( end - start) - 1; font->chars[count]->height = font->height; - if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) - { + if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) { space += ( font->chars[count]->width * data->image->height * 4 ); // we skip the first line because there are just the red pixels for the char width - for( y = 1; y< (font->height); y++) - { - for( x2 = start, x3 = 0; x2 < end; x2++, x3++) - { + for( y = 1; y< (font->height); y++) { + for( x2 = start, x3 = 0; x2 < end; x2++, x3++) { pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y ); } } // check if font is monospaced - if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) + if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) { monospaced = true; + } font->width = font->chars[count]->width; @@ -1599,11 +1605,13 @@ } } - for (x = count; x < CHARACTERS_COUNT; x++) + for (x = count; x < CHARACTERS_COUNT; x++) { font->chars[x] = NULL; + } - if(monospaced) + if(monospaced) { font->width = 0; + } font->count = count; @@ -1612,24 +1620,21 @@ void colorFont(font_t *font, uint32_t color) { - if( !color ) + if( !color ) { return; - + } + int x, y, width, height; int count = 0; pixel_t *buff; - while( font->chars[count++] ) - { + while( font->chars[count++] ) { width = font->chars[count-1]->width; height = font->chars[count-1]->height; - for( y = 0; y < height; y++ ) - { - for( x = 0; x < width; x++ ) - { + for( y = 0; y < height; y++ ) { + for( x = 0; x < width; x++ ) { buff = &(pixel( font->chars[count-1], x, y )); - if( buff->ch.a ) - { + if( buff->ch.a ) { buff->ch.r = (color & 0xFFFF0000) >> 16; buff->ch.g = (color & 0xFF00FF00) >> 8; buff->ch.b = (color & 0xFF0000FF); @@ -1662,13 +1667,10 @@ uint8_t alpha=0; - for( y=0; y<10; y++) - { - for( x=0; x<10; x++) - { + for( y=0; y<10; y++) { + for( x=0; x<10; x++) { // skip if the pixel should be visible - if(roundedCorner[y][x] != 0xFF) - { + if(roundedCorner[y][x] != 0xFF) { alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 ); // Upper left corner pixel(p, x, y).ch.a = alpha; @@ -1695,54 +1697,55 @@ int cnt=0; int offset=0; - if( !title || !text_orig ) + if( !title || !text_orig ) { return; - + } + // Create a copy so that we don't mangle the original text = malloc(strlen(text_orig) + 1); strcpy(text, text_orig); - - + position_t pos_title = pos ( gui.infobox.vborder, gui.infobox.vborder ); // calculate number of lines in the title - for ( i = 0, lines = 1; iwidth - ( gui.infobox.vborder / 2) ), pos_text.y ); // draw prev indicator - if(offset) - { + if(offset) { blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator )); } // draw next indicator - if( lines > ( currentline + visiblelines ) ) - { + if( lines > ( currentline + visiblelines ) ) { pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) ); blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) ); } @@ -1786,29 +1787,32 @@ key = getchar(); - if( key == KEY_UP ) - if( currentline > 0 ) + if( key == KEY_UP ) { + if( currentline > 0 ) { currentline--; + } + } - if( key == KEY_DOWN ) - if( lines > ( currentline + visiblelines ) ) + if( key == KEY_DOWN ) { + if( lines > ( currentline + visiblelines ) ) { currentline++; + } + } - if( key == KEY_ESC || key == 'q' || key == 'Q') - { + if( key == KEY_ESC || key == 'q' || key == 'Q') { gui.infobox.draw = false; gui.redraw = true; updateVRAM(); break; } - if(key == ' ') // spacebar = next page - { - if( lines > ( currentline + visiblelines ) ) + if(key == ' ') { // spacebar = next page + if( lines > ( currentline + visiblelines ) ) { currentline += visiblelines; - - if(lines < (currentline + visiblelines)) + } + if(lines < (currentline + visiblelines)) { currentline = lines - visiblelines; + } } } free(text); @@ -1818,8 +1822,7 @@ { int y; - if( time18() > lasttime) - { + if( time18() > lasttime) { lasttime = time18(); pixmap_t *buffBar = images[iProgressBar].image; @@ -1828,58 +1831,65 @@ memcpy( buffBar->pixels, buffBar->pixels + 1, ( (buffBar->width*buffBar->height) - 1 ) * 4 ); - for( y = buffBar->height - 1; y > 0; y--) + for( y = buffBar->height - 1; y > 0; y--) { pixel(buffBar, buffBar->width - 1, y) = pixel(buffBar, buffBar->width - 1, y - 1); - + } pixel(buffBar, buffBar->width-1, 0).value = buff; } } void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress) { - if(progress>100) + if(progress>100) { return; - + } + p.x = ( p.x - ( width / 2 ) ); int todraw = (width * progress) / 100; pixmap_t *buff = images[iProgressBar].image; pixmap_t *buffBG = images[iProgressBarBackground].image; - if(!buff || !buffBG) + if(!buff || !buffBG) { return; - + } + pixmap_t progressbar; progressbar.pixels=malloc(width * 4 * buff->height); - if(!progressbar.pixels) + if(!progressbar.pixels) { return; - + } + progressbar.width = width; progressbar.height = buff->height; int x=0,x2=0,y=0; - for(y=0; yheight; y++) - { - for(x=0; xwidth-1)) x2=0; + for(y=0; yheight; y++) { + for(x=0; xwidth-1)) { + x2=0; + } pixel(&progressbar, x,y).value = pixel(buff, x2,y).value; } x2=0; } - for(y=0; yheight; y++) - { - for(x=todraw, x2 = 0; x < width - 1; x++, x2++) - { - if(x2 == (buffBG->width -2 )) x2 = 0; + for(y=0; yheight; y++) { + for(x=todraw, x2 = 0; x < width - 1; x++, x2++) { + if(x2 == (buffBG->width -2 )) { + x2 = 0; + } pixel(&progressbar, x,y).value = pixel(buffBG, x2,y).value; } - if(progress < 100) + if(progress < 100) { pixel(&progressbar, width - 1, y).value = pixel(buffBG, buffBG->width - 1, y).value; - if(progress == 0) + } + + if(progress == 0) { pixel(&progressbar, 0, y).value = pixel(buffBG, buffBG->width - 1, y).value; + } + x2=0; } @@ -1906,21 +1916,16 @@ position = pos(0,0); - for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) - { - if (i == infoMenuSelection) - { + for ( i = 0, n = iMenuBoot; i < infoMenuItemsCount; i++, n++) { + if (i == infoMenuSelection) { blend(selection, gui.menu.pixmap, position); } pbuff = images[n].image; - if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) - { + if (offset && i >= INFOMENU_NATIVEBOOT_START && i <= INFOMENU_NATIVEBOOT_END) { blend( images[n + (iMenuHelp - iMenuBoot)].image , gui.menu.pixmap, pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2))); - } - else - { + } else { blend( pbuff, gui.menu.pixmap, pos((position.x + (gui.menu.hborder / 2)), position.y + ((selection->height - pbuff->height) / 2))); } @@ -1952,22 +1957,16 @@ { case KEY_UP: // up arrow - if (infoMenuSelection > 0) - { - if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) - { + if (infoMenuSelection > 0) { + if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_END + 1) { infoMenuSelection -= 4; - } - else - { + } else { infoMenuSelection--; } drawInfoMenuItems(); updateVRAM(); - } - else - { + } else { gui.menu.draw = false; gui.redraw = true; @@ -1979,12 +1978,13 @@ break; case KEY_DOWN: // down arrow - if (infoMenuSelection < infoMenuItemsCount - 1) - { + if (infoMenuSelection < infoMenuItemsCount - 1) { if(!infoMenuNativeBoot && infoMenuSelection == INFOMENU_NATIVEBOOT_START - 1) + { infoMenuSelection += 4; - else + } else { infoMenuSelection++; + } drawInfoMenuItems(); updateVRAM(); } @@ -1992,17 +1992,13 @@ case KEY_ENTER: key = 0; - if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) + if( infoMenuSelection == MENU_SHOW_MEMORY_INFO ) { showInfoBox( "Memory Info. Press q to quit.\n", getMemoryInfoString()); - - else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) + } else if( infoMenuSelection == MENU_SHOW_VIDEO_INFO ) { showInfoBox( getVBEInfoString(), getVBEModeInfoString() ); - - else if( infoMenuSelection == MENU_SHOW_HELP ) + } else if( infoMenuSelection == MENU_SHOW_HELP ) { showHelp(); - - else - { + } else { int buff = infoMenuSelection; infoMenuSelection = 0; return buff; @@ -2034,7 +2030,7 @@ sprintf(dirspec, "/Extra/Themes/%s/boot.png", theme_name); if (loadPngImage(dirspec, &bootImageWidth, &bootImageHeight, &bootImageData) != 0) { #ifdef CONFIG_EMBED_THEME - if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0) + if ((loadEmbeddedPngImage(__boot_png, __boot_png_len, &bootImageWidth, &bootImageHeight, &bootImageData)) != 0) #endif usePngImage = false; } @@ -2069,7 +2065,7 @@ screen_params[1] = DEFAULT_SCREEN_HEIGHT; } - // Save current screen resolution. + // Save current screen resolution. oldScreenWidth = gui.screen.width; oldScreenHeight = gui.screen.height; @@ -2079,10 +2075,8 @@ // find best matching vesa mode for our requested width & height getGraphicModeParams(screen_params); - // Set graphics mode if the booter was in text mode or the screen resolution has changed. - if (bootArgs->Video.v_display == VGA_TEXT_MODE - || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) - { + // Set graphics mode if the booter was in text mode or the screen resolution has changed. + if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) { setVideoMode(GRAPHICS_MODE, 0); } Index: trunk/i386/boot2/gui.h =================================================================== --- trunk/i386/boot2/gui.h (revision 2343) +++ trunk/i386/boot2/gui.h (revision 2344) @@ -64,7 +64,7 @@ uint16_t height; // Font Height uint16_t width; // Font Width for monospace font only pixmap_t *chars[CHARACTERS_COUNT]; - uint16_t count; // Number of chars in font + uint16_t count; // Number of chars in font } font_t; /* Index: trunk/i386/boot2/options.c =================================================================== --- trunk/i386/boot2/options.c (revision 2343) +++ trunk/i386/boot2/options.c (revision 2344) @@ -189,7 +189,6 @@ if (bootArgs->Video.v_display != VGA_TEXT_MODE) { clearGraphicBootPrompt(); } - execute_hook("ClearArgs", NULL, NULL, NULL, NULL); } @@ -228,7 +227,7 @@ } } else { if (bootArgs->Video.v_display != VGA_TEXT_MODE) { - clearGraphicBootPrompt(); + clearGraphicBootPrompt(); } else { printf("Press Enter to start up the foreign OS. "); } @@ -254,8 +253,10 @@ { x = 80; y--; } - if (x) x--; - + if (x) { + x--; + } + if( bootArgs->Video.v_display == VGA_TEXT_MODE ) { setCursorPosition( x, y, 0 ); @@ -1126,25 +1127,25 @@ int *cntRemainingP, // Output count char *foundVal, // found value int foundValSize // max found value size - ) -{ - const char *val; - int cnt; - bool found = false; + ) { + const char *val; + int cnt; + bool found = false; - if (getValueForBootKey(userString, argName, &val, &cnt)) { - // Don't copy; these values will be copied at the end of argument processing. - found = true; - } else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) { - // Don't copy; these values will be copied at the end of argument processing. - found = true; - } else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) { - copyArgument(argName, val, cnt, argP, cntRemainingP); - found = true; - } - if (found && foundVal) - strlcpy(foundVal, val, foundValSize); - return found; + if (getValueForBootKey(userString, argName, &val, &cnt)) { + // Don't copy; these values will be copied at the end of argument processing. + found = true; + } else if (getValueForBootKey(kernelFlags, argName, &val, &cnt)) { + // Don't copy; these values will be copied at the end of argument processing. + found = true; + } else if (getValueForKey(argName, &val, &cnt, &bootInfo->chameleonConfig)) { + copyArgument(argName, val, cnt, argP, cntRemainingP); + found = true; + } + if (found && foundVal) { + strlcpy(foundVal, val, foundValSize); + } + return found; } // Maximum config table value size @@ -1153,204 +1154,202 @@ int processBootOptions() { - const char *cp = gBootArgs; - const char *val = 0; - const char *kernel; - int cnt; - int userCnt; - int cntRemaining; - char *argP; - char *configKernelFlags; - char *valueBuffer; + const char *cp = gBootArgs; + const char *val = 0; + const char *kernel; + int cnt; + int userCnt; + int cntRemaining; + char *argP; + char *configKernelFlags; + char *valueBuffer; - valueBuffer = malloc(VALUE_SIZE); + valueBuffer = malloc(VALUE_SIZE); - skipblanks( &cp ); + skipblanks( &cp ); - // Update the unit and partition number. + // Update the unit and partition number. - if ( gBootVolume ) - { - if (!( gBootVolume->flags & kBVFlagNativeBoot )) - { - readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, - (void *) 0x7c00 ); + if ( gBootVolume ) { + if (!( gBootVolume->flags & kBVFlagNativeBoot )) { + readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 ); + // + // Setup edx, and signal intention to chain load the + // foreign booter. + // - // - // Setup edx, and signal intention to chain load the - // foreign booter. - // + chainbootdev = gBootVolume->biosdev; + chainbootflag = 1; - chainbootdev = gBootVolume->biosdev; - chainbootflag = 1; + return 1; + } - return 1; - } + setRootVolume(gBootVolume); - setRootVolume(gBootVolume); + } + // If no boot volume fail immediately because we're just going to fail + // trying to load the config file anyway. + else { + return -1; + } - } - // If no boot volume fail immediately because we're just going to fail - // trying to load the config file anyway. - else - return -1; + // Load config table specified by the user, or use the default. - // Load config table specified by the user, or use the default. + if (!getValueForBootKey(cp, "config", &val, &cnt)) { + val = 0; + cnt = 0; + } - if (!getValueForBootKey(cp, "config", &val, &cnt)) { - val = 0; - cnt = 0; - } + // Load com.apple.Boot.plist from the selected volume + // and use its contents to override default bootConfig. - // Load com.apple.Boot.plist from the selected volume - // and use its contents to override default bootConfig. + loadSystemConfig(&bootInfo->bootConfig); + loadChameleonConfig(&bootInfo->chameleonConfig); - loadSystemConfig(&bootInfo->bootConfig); - loadChameleonConfig(&bootInfo->chameleonConfig); + // Use the kernel name specified by the user, or fetch the name + // in the config table, or use the default if not specified. + // Specifying a kernel name on the command line, or specifying + // a non-default kernel name in the config file counts as + // overriding the kernel, which causes the kernelcache not + // to be used. - // Use the kernel name specified by the user, or fetch the name - // in the config table, or use the default if not specified. - // Specifying a kernel name on the command line, or specifying - // a non-default kernel name in the config file counts as - // overriding the kernel, which causes the kernelcache not - // to be used. - - gOverrideKernel = false; - if (( kernel = extractKernelName((char **)&cp) )) { - strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) ); - } else { - if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) { - strlcpy( bootInfo->bootFile, val, cnt+1 ); - } else { - strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) ); - } - } + gOverrideKernel = false; + if (( kernel = extractKernelName((char **)&cp) )) { + strlcpy( bootInfo->bootFile, kernel, sizeof(bootInfo->bootFile) ); + } else { + if ( getValueForKey( kKernelNameKey, &val, &cnt, &bootInfo->bootConfig ) ) { + strlcpy( bootInfo->bootFile, val, cnt+1 ); + } else { + strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) ); + } + } if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) { gOverrideKernel = true; } - cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space - argP = bootArgs->CommandLine; + cntRemaining = BOOT_STRING_LEN - 2; // save 1 for NULL, 1 for space + argP = bootArgs->CommandLine; // Get config kernel flags, if not ignored. - if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || + if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || !getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig )) { - val = ""; - cnt = 0; - } - configKernelFlags = malloc(cnt + 1); - strlcpy(configKernelFlags, val, cnt + 1); + val = ""; + cnt = 0; + } + configKernelFlags = malloc(cnt + 1); + strlcpy(configKernelFlags, val, cnt + 1); - // boot-uuid can be set either on the command-line or in the config file + // boot-uuid can be set either on the command-line or in the config file if (!processBootArgument(kBootUUIDKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gBootUUIDString, sizeof(gBootUUIDString))) { - // - // Try an alternate method for getting the root UUID on boot helper partitions. - // - if (gBootVolume->flags & kBVFlagBooter) - { + // + // Try an alternate method for getting the root UUID on boot helper partitions. + // + if (gBootVolume->flags & kBVFlagBooter) { // Load the configuration store in the boot helper partition - if (loadHelperConfig(&bootInfo->helperConfig) == 0) - { + if (loadHelperConfig(&bootInfo->helperConfig) == 0) { val = getStringForKey(kHelperRootUUIDKey, &bootInfo->helperConfig); - if (val != NULL) + if (val != NULL) { strlcpy(gBootUUIDString, val, sizeof(gBootUUIDString)); + } } - } + } - // Try to get the volume uuid string - if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) + // Try to get the volume uuid string + if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) { gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString); + } // If we have the volume uuid add it to the commandline arguments - if (strlen(gBootUUIDString)) + if (strlen(gBootUUIDString)) { copyArgument(kBootUUIDKey, gBootUUIDString, strlen(gBootUUIDString), &argP, &cntRemaining); + } } - if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, + if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE)) { - cnt = 0; - if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) { - valueBuffer[0] = '*'; - cnt++; - strlcpy(valueBuffer + 1, val, cnt); - val = valueBuffer; - } else { - if (strlen(gBootUUIDString)) { - val = "*uuid"; - cnt = 5; - } else { - // Don't set "rd=.." if there is no boot device key - // and no UUID. - val = ""; - cnt = 0; - } - } - if (cnt > 0) { - copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); - } - strlcpy( gRootDevice, val, (cnt + 1)); - } + cnt = 0; + if ( getValueForKey( kBootDeviceKey, &val, &cnt, &bootInfo->chameleonConfig)) { + valueBuffer[0] = '*'; + cnt++; + strlcpy(valueBuffer + 1, val, cnt); + val = valueBuffer; + } else { + if (strlen(gBootUUIDString)) { + val = "*uuid"; + cnt = 5; + } else { + // Don't set "rd=.." if there is no boot device key + // and no UUID. + val = ""; + cnt = 0; + } + } + if (cnt > 0) { + copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); + } + strlcpy( gRootDevice, val, (cnt + 1)); + } - /* - * Removed. We don't need this anymore. - * - if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, + /* + * Removed. We don't need this anymore. + * + if (!processBootArgument(kPlatformKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gPlatformName, sizeof(gCacheNameAdler))) { - getPlatformName(gPlatformName); - copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining); - } - */ + getPlatformName(gPlatformName); + copyArgument(kPlatformKey, gPlatformName, strlen(gPlatformName), &argP, &cntRemaining); + } + */ - if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) && + if (!getValueForBootKey(cp, kSafeModeFlag, &val, &cnt) && !getValueForBootKey(configKernelFlags, kSafeModeFlag, &val, &cnt)) { - if (gBootMode & kBootModeSafe) { - copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining); - } - } + if (gBootMode & kBootModeSafe) { + copyArgument(0, kSafeModeFlag, strlen(kSafeModeFlag), &argP, &cntRemaining); + } + } - // Store the merged kernel flags and boot args. + // Store the merged kernel flags and boot args. - cnt = strlen(configKernelFlags); - if (cnt) { - if (cnt > cntRemaining) { - error("Warning: boot arguments too long, truncating\n"); - cnt = cntRemaining; - } - strncpy(argP, configKernelFlags, cnt); - argP[cnt++] = ' '; - cntRemaining -= cnt; - } - userCnt = strlen(cp); - if (userCnt > cntRemaining) { - error("Warning: boot arguments too long, truncating\n"); - userCnt = cntRemaining; - } - strncpy(&argP[cnt], cp, userCnt); - argP[cnt+userCnt] = '\0'; + cnt = strlen(configKernelFlags); + if (cnt) { + if (cnt > cntRemaining) { + error("Warning: boot arguments too long, truncating\n"); + cnt = cntRemaining; + } + strncpy(argP, configKernelFlags, cnt); + argP[cnt++] = ' '; + cntRemaining -= cnt; + } + userCnt = strlen(cp); + if (userCnt > cntRemaining) { + error("Warning: boot arguments too long, truncating\n"); + userCnt = cntRemaining; + } + strncpy(&argP[cnt], cp, userCnt); + argP[cnt+userCnt] = '\0'; - if(!shouldboot) - { + if(!shouldboot) { gVerboseMode = getValueForKey( kVerboseModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) || getValueForKey( kSingleUserModeFlag, &val, &cnt, &bootInfo->chameleonConfig ); gBootMode = ( getValueForKey( kSafeModeFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) ? kBootModeSafe : kBootModeNormal; - if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) { - gBootMode = kBootModeSafe; - } + if ( getValueForKey( kIgnoreCachesFlag, &val, &cnt, &bootInfo->chameleonConfig ) ) { + gBootMode = kBootModeSafe; + } } - if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) ) + if ( getValueForKey( kMKextCacheKey, &val, &cnt, &bootInfo->bootConfig ) ) { strlcpy(gMKextName, val, cnt + 1); - else + } else { gMKextName[0]=0; + } - free(configKernelFlags); - free(valueBuffer); + free(configKernelFlags); + free(valueBuffer); - return 0; + return 0; } @@ -1369,11 +1368,11 @@ showInfoBox( "Press q to continue, space for next page.\n",buf_orig ); return; } + + // Create a copy so that we don't mangle the original + buf = malloc(size + 1); + memcpy(buf, buf_orig, size); - // Create a copy so that we don't mangle the original - buf = malloc(size + 1); - memcpy(buf, buf_orig, size); - bp = buf; while (size-- > 0) { Index: trunk/i386/config/lex.zconf.c =================================================================== --- trunk/i386/config/lex.zconf.c (revision 2343) +++ trunk/i386/config/lex.zconf.c (revision 2344) @@ -822,15 +822,15 @@ { int new_size = text_size + size + 1; if (new_size > text_asize) { - char* new_text = NULL; - new_size += START_STRSIZE - 1; - new_size &= -START_STRSIZE; - if (!(new_text = realloc(text, new_size))) { - return; + char* new_text = NULL; + new_size += START_STRSIZE - 1; + new_size &= -START_STRSIZE; + if (!(new_text = realloc(text, new_size))) { + return; + } + text = new_text; + text_asize = new_size; } - text = new_text; - text_asize = new_size; - } memcpy(text + text_size, str, size); text_size += size; text[text_size] = 0; Index: trunk/i386/config/nconf.h =================================================================== --- trunk/i386/config/nconf.h (revision 2343) +++ trunk/i386/config/nconf.h (revision 2344) @@ -26,16 +26,6 @@ #include "ncurses.h" -#define max(a, b) ({\ - typeof(a) _a = a;\ - typeof(b) _b = b;\ - _a > _b ? _a : _b; }) - -#define min(a, b) ({\ - typeof(a) _a = a;\ - typeof(b) _b = b;\ - _a < _b ? _a : _b; }) - typedef enum { NORMAL = 1, MAIN_HEADING, Index: trunk/i386/config/confdata.c =================================================================== --- trunk/i386/config/confdata.c (revision 2343) +++ trunk/i386/config/confdata.c (revision 2344) @@ -16,6 +16,16 @@ #define LKC_DIRECT_LINK #include "lkc.h" +#define max(a, b) ({\ + typeof(a) _a = a;\ + typeof(b) _b = b;\ + _a > _b ? _a : _b; }) + +#define min(a, b) ({\ + typeof(a) _a = a;\ + typeof(b) _b = b;\ + _a < _b ? _a : _b; }) + static void conf_warning(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); @@ -75,29 +85,47 @@ return name ? name : "auto.conf"; } +/* TODO: figure out if symbols are always null-terminated */ static char *conf_expand_value(const char *in) { - struct symbol *sym; + static char res_value[SYMBOL_MAXLENGTH + 1]; + char name[SYMBOL_MAXLENGTH]; + size_t res_rem = SYMBOL_MAXLENGTH; + char *res_ptr = res_value; const char *src; - static char res_value[SYMBOL_MAXLENGTH]; - char *dst, name[SYMBOL_MAXLENGTH]; + *res_ptr = 0; + res_ptr[SYMBOL_MAXLENGTH] = 0; + while ((src = strchr(in, '$'))) { + struct symbol *sym; + const char *symval; + char *name_ptr = name; + size_t n = min(res_rem, src - in); - res_value[0] = 0; - dst = name; - while ((src = strchr(in, '$'))) { - strncat(res_value, in, src - in); + res_ptr = stpncpy(res_ptr, in, n); + if (!(res_rem -= n)) { + return res_value; /* buffer full, quit now */ + } src++; - dst = name; - while (isalnum(*src) || *src == '_') - *dst++ = *src++; - *dst = 0; + + *name_ptr = 0; + while (isalnum(*src) || *src == '_') { + *name_ptr++ = *src++; + } + *name_ptr = 0; + sym = sym_lookup(name, 0); sym_calc_value(sym); - strcat(res_value, sym_get_string_value(sym)); + symval = sym_get_string_value(sym); + n = min(res_rem, strlen(symval)); + + res_ptr = stpncpy(res_ptr, symval, n); + if (!(res_rem -= n)) { + return res_value; /* buffer full, quit now */ + } in = src; } - strcat(res_value, in); + strncpy(res_ptr, in, res_rem + 1); return res_value; } @@ -110,7 +138,7 @@ name = conf_expand_value(conf_defname); env = getenv(SRCTREE); if (env) { - sprintf(fullname, "%s/%s", env, name); + snprintf(fullname, PATH_MAX+1, "%s/%s", env, name); if (!stat(fullname, &buf)) return fullname; } @@ -570,38 +598,41 @@ char *slash; if (!stat(name, &st) && S_ISDIR(st.st_mode)) { - strcpy(dirname, name); - strcat(dirname, "/"); + /* FIXME: add length check */ + strcpy(stpcpy(dirname, name), "/"); basename = conf_get_configname(); } else if ((slash = strrchr(name, '/'))) { - int size = slash - name + 1; + size_t size = slash - name + 1; memcpy(dirname, name, size); dirname[size] = 0; - if (slash[1]) + if (slash[1]) { basename = slash + 1; - else + } else { basename = conf_get_configname(); - } else + } + } else { basename = name; - } else + } + } else { basename = conf_get_configname(); - - sprintf(newname, "%s%s", dirname, basename); + } + snprintf(newname, PATH_MAX+1, "%s%s", dirname, basename); env = getenv("KCONFIG_OVERWRITECONFIG"); if (!env || !*env) { - sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid()); + snprintf(tmpname, PATH_MAX+1, "%s.tmpconfig.%d", dirname, (int)getpid()); out = fopen(tmpname, "w"); } else { *tmpname = 0; out = fopen(newname, "w"); } - if (!out) + if (!out) { return 1; - + } time(&now); env = getenv("KCONFIG_NOTIMESTAMP"); - if (env && *env) + if (env && *env) { use_timestamp = 0; + } fprintf(out, _("#\n" "# Automatically generated make config: don't edit\n" @@ -640,9 +671,9 @@ menu = menu->list; continue; } - if (menu->next) + if (menu->next) { menu = menu->next; - else while ((menu = menu->parent)) { + } else while ((menu = menu->parent)) { if (menu->next) { menu = menu->next; break; @@ -655,8 +686,9 @@ strcat(dirname, basename); strcat(dirname, ".old"); rename(newname, dirname); - if (rename(tmpname, newname)) + if (rename(tmpname, newname)) { return 1; + } } // conf_message(_("configuration written to %s"), newname); Index: trunk/i386/cdboot/cdboot.s =================================================================== --- trunk/i386/cdboot/cdboot.s (revision 2343) +++ trunk/i386/cdboot/cdboot.s (revision 2344) @@ -406,7 +406,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: trunk/i386/cdboot/cdboothdd.s =================================================================== --- trunk/i386/cdboot/cdboothdd.s (revision 2343) +++ trunk/i386/cdboot/cdboothdd.s (revision 2344) @@ -320,7 +320,7 @@ ; DS:SI = pointer to Disk Address Packet ; ; Returns: - ; AH = return status (sucess is 0) + ; AH = return status (success is 0) ; carry = 0 success ; 1 error ; Index: trunk/i386/libsa/libsa.h =================================================================== --- trunk/i386/libsa/libsa.h (revision 2343) +++ trunk/i386/libsa/libsa.h (revision 2344) @@ -94,7 +94,9 @@ extern int strcmp(const char * s1, const char * s2); extern int strncmp(const char * s1, const char * s2, size_t n); extern char * strcpy(char * s1, const char * s2); +extern char * stpcpy(char * s1, const char * s2); extern char * strncpy(char * s1, const char * s2, size_t n); +extern char * strpcpy(char * s1, const char * s2, size_t n); extern size_t strlcpy(char * s1, const char * s2, size_t n); extern char * strstr(const char *in, const char *str); extern int atoi(const char * str); Index: trunk/i386/libsa/string.c =================================================================== --- trunk/i386/libsa/string.c (revision 2343) +++ trunk/i386/libsa/string.c (revision 2344) @@ -110,9 +110,9 @@ size_t strlen(const char * s) { - int n = 0; - while (*s++) n++; - return(n); + const char* save = s; + while (*s++); + return (--s) - save; } /*#endif*/ @@ -138,13 +138,19 @@ return (*s1 - *s2); } -int strncmp(const char * s1, const char * s2, size_t len) +/* Derived from FreeBSD source */ +int strncmp(const char * s1, const char * s2, size_t n) { - register int n = len; - while (--n >= 0 && *s1 == *s2++) - if (*s1++ == '\0') - return(0); - return(n<0 ? 0 : *s1 - *--s2); + if (!n) + return 0; + do { + if (*s1 != *s2++) + return (*(const unsigned char *)s1 - + *(const unsigned char *)(s2 - 1)); + if (!*s1++) + break; + } while (--n); + return 0; } char * @@ -157,12 +163,20 @@ } char * +stpcpy(char * s1, const char * s2) +{ + while ((*s1++ = *s2++)) { + continue; + } + return --s1; +} + +char * strncpy(char * s1, const char * s2, size_t n) { register char *ret = s1; while (n && (*s1++ = *s2++)) - --n; - /* while (n--) *s1++ = '\0'; */ + --n; if (n > 0) { bzero(s1, n); } @@ -170,6 +184,16 @@ } char * +stpncpy(char * s1, const char * s2, size_t n) +{ + while (n && (*s1++ = *s2++)) + --n; + if (n > 0) + bzero(s1, n); + return s1; +} + +char * strstr(const char *in, const char *str) { char c; @@ -224,15 +248,17 @@ register char *ret = s1; while (*s1) s1++; - while (n-- && *s2) - *s1++ = *s2++; - *s1 = '\0'; + while (n-- && (*s1++ = *s2++)); return ret; } char *strcat(char *s1, const char *s2) { - return(strncat(s1, s2, strlen(s2))); + register char *ret = s1; + while (*s1) + s1++; + while ((*s1++ = *s2++)); + return ret; } char *strdup(const char *s1) Index: trunk/i386/libsa/strtol.c =================================================================== --- trunk/i386/libsa/strtol.c (revision 2343) +++ trunk/i386/libsa/strtol.c (revision 2344) @@ -66,7 +66,7 @@ * Added support for "0b101..." binary constants. * Commented out references to errno. */ - + #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)strtol.c 5.4 (Berkeley) 2/23/91"; #endif /* LIBC_SCCS and not lint */ @@ -103,21 +103,22 @@ if (c == '-') { neg = 1; c = *s++; - } else if (c == '+') + } else if (c == '+') { c = *s++; - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + } + + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { c = s[1]; s += 2; base = 16; - } else if ((base == 0 || base == 2) && - c == '0' && (*s == 'b' || *s == 'B')) { + } else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B')) { c = s[1]; s += 2; base = 2; } - if (base == 0) + if (base == 0) { base = c == '0' ? 8 : 10; + } /* * Compute the cutoff value between legal numbers and illegal @@ -140,17 +141,19 @@ cutlim = cutoff % (unsigned long)base; cutoff /= (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) + if (isdigit(c)) { c -= '0'; - else if (isalpha(c)) + } else if (isalpha(c)) { c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else + } else { break; - if (c >= base) + } + if (c >= base) { break; - if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + } + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) { any = -1; - else { + } else { any = 1; acc *= base; acc += c; @@ -161,8 +164,9 @@ // errno = ERANGE; } else if (neg) acc = -acc; - if (endptr != 0) + if (endptr != 0) { *endptr = (char *)(any ? s - 1 : nptr); + } return (acc); } @@ -194,35 +198,37 @@ if (c == '-') { neg = 1; c = *s++; - } else if (c == '+') + } else if (c == '+') { c = *s++; - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + } + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { c = s[1]; s += 2; base = 16; - } else if ((base == 0 || base == 2) && - c == '0' && (*s == 'b' || *s == 'B')) { + } else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B')) { c = s[1]; s += 2; base = 2; } - if (base == 0) + if (base == 0) { base = c == '0' ? 8 : 10; + } cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) + if (isdigit(c)) { c -= '0'; - else if (isalpha(c)) + } else if (isalpha(c)) { c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else + } else { break; - if (c >= base) + } + if (c >= base) { break; - if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + } + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) { any = -1; - else { + } else { any = 1; acc *= base; acc += c; @@ -231,10 +237,12 @@ if (any < 0) { acc = ULONG_MAX; // errno = ERANGE; - } else if (neg) + } else if (neg) { acc = -acc; - if (endptr != 0) + } + if (endptr != 0) { *endptr = (char *)(any ? s - 1 : nptr); + } return (acc); } @@ -268,32 +276,35 @@ c = *s++; } else { neg = 0; - if (c == '+') + if (c == '+') { c = *s++; + } } - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { + if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) { c = s[1]; s += 2; base = 16; } - if (base == 0) + if (base == 0) { base = c == '0' ? 8 : 10; + } qbase = (unsigned)base; cutoff = (unsigned long long)UQUAD_MAX / qbase; cutlim = (unsigned long long)UQUAD_MAX % qbase; for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) + if (isdigit(c)) { c -= '0'; - else if (isalpha(c)) + } else if (isalpha(c)) { c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else + } else { break; - if (c >= base) + } + if (c >= base) { break; - if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) + } + if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) { any = -1; - else { + } else { any = 1; acc *= qbase; acc += c; @@ -302,9 +313,11 @@ if (any < 0) { acc = UQUAD_MAX; // errno = ERANGE; - } else if (neg) + } else if (neg) { acc = -acc; - if (endptr != 0) + } + if (endptr != 0) { *endptr = (char *)(any ? s - 1 : nptr); + } return (acc); } Index: trunk/CHANGES =================================================================== --- trunk/CHANGES (revision 2343) +++ trunk/CHANGES (revision 2344) @@ -1,4 +1,30 @@ -- One of the changes as of rev2284 is boot option SystemId has now been deprecated. Instead use key SMsystemuuid in smbios.plist. +- bitshoveler : Optimized basic string functions strlen, strncmp, strncat, strcat +- ErmaC : Replaced sprintf with snprintf in spd.c. +- bitshoveler : Fixed inadvertent text buffer overflow in getDDRSerial +- bitshoveler : optimize get_hda_controller_name() +- Bungo : One of the changes as of rev2284 is boot option SystemId has now been deprecated. Instead use key SMsystemuuid in smbios.plist. +- bitshoveler : Defend against buffer overruns +- bitshoveler : Fix memory leak, defend against buffer overruns, add a check for malloc() failure +- bitshoveler : getMemoryInfoString: defend against buffer overruns, change O(n^2) algorithm to O(n) +- bitshoveler : Add closedir() to match opendir() call; relocate a malloc() call to fix a memory leak on error; better defense against buffer overruns +- bitshoveler : Improve robustness against buffer overruns +- bitshoveler : Add closedir() for every opendir() call, make more robust against buffer overruns +- bitshoveler : Fix memory leak +- bitshoveler : Fix cppcheck detected memory leak and error, make more robust against buffer overrun +- bitshoveler : get_pci_dev_path: get rid of tmp buffer, use snprintf, improved O(n) algorithm instead of O(n^2) (whoopee); dump_pci_dt: hack fix for printf format string vs. args mismatch +- bitshoveler : Fix memory leak; use snprintf instead of sprintf to make more robust +- bitshoveler : Fix badly formed comment inside #ifdef +- bitshoveler : setup_gma_devprop: fix memory leak +- bitshoveler : setup_nhm: fix cppcheck error +- bitshoveler : Correct cppcheck detected errors, make more robust against errors +- bitshoveler : AllocateMemoryRange: fix cppcheck detected memory leak +- bitshoveler : search_and_get_acpi_fd: fix pointer-to-temporary return problem; use snprintf instead of sprintf to prevent buffer overflows +- bitshoveler : sym_expand_string_value(): fix cppcheck errors; more to be done here +- bitshoveler : append_string(): fix cppcheck errors +- bitshoveler : conf_write_autoconf(): fix cppcheck errors +- bitshoveler : Fix memory leak for new_layout in main() +- bitshoveler : Implement snprintf(); implement missing zero-fill in strncpy() +- bitshoveler : Use original *BSD source for strlcpy() - ErmaC: Port from Enoch the support for IVY Bridge and Haswell Intel Graphics cards. http://www.insanelymac.com/forum/topic/288241-intel-hd4000-and-haswell-inject-aaplig-platform-id/ - 2255: ErmaC add Skip flag key for Intel/nVidia/ATi from Enoch - 2252: revert define processors name to match with xnu kernel name