Index: branches/cparm/TODO =================================================================== --- branches/cparm/TODO (revision 1983) +++ branches/cparm/TODO (revision 1984) @@ -1,11 +1,12 @@ TODO List for Chameleon Boot Loader ==================================== +- Try to sync our prf() with the apple/mach __doprnt() (in Xnu/osfmk/kern/printf.c) to normalize the formating in our printf, sprintf, etc ..., and facilitate bug fixes (almost done !!) + - split nvidia, gma and ati code into separate modules - move device_inject, MBR (OSX works better on Guid partition theme anyway), winfs, bsdfs, ext2fs, befs, and the command lspci, memory, more and video into modules - Implement a pool allocator, so each module will run and allocate memory in there own pool, de-alloc all allocated memory by the module, will be done simply by destroying the pool -- Implement snprintf to avoid buffer overflow in some case - implement cpu topology - Backport cconfig from the trunk @@ -14,9 +15,6 @@ - update project with corehash -- Try to sync our prf() with the apple/mach __doprnt() (in Xnu/osfmk/kern/printf.c) to normalize the formating in our printf, sprintf, etc ..., and facilitate bug fixes - - NOTE: It seems that nvram variables must be set thru efiRuntimeServices->SetVariable(...), then, the /options node is filled by kernel depending on the Runtime Services. If true, this requires a more complete EFI implementation (perhaps in a module, or a kext). Index: branches/cparm/CHANGES =================================================================== --- branches/cparm/CHANGES (revision 1983) +++ branches/cparm/CHANGES (revision 1984) @@ -1,4 +1,10 @@ - security and stability fixes +- Fixed a bug where prf may return a wrong string len (for ex : in the previous versions newStringWithformat("%02x%02x%02x%02x%02x%02x",101,117,104,113,103,100) may not return the entire string) +- Fixed a bug in xml.c +- Fixed a bug in device_inject.c (inspired from the dmazar's patch) + + +- security and stability fixes - Removed useless codes in efistring modules - Fixed bugs related to device_inject.c - Fixed bugs related to device_tree.c Index: branches/cparm/i386/libsaio/xml.c =================================================================== --- branches/cparm/i386/libsaio/xml.c (revision 1983) +++ branches/cparm/i386/libsaio/xml.c (revision 1984) @@ -44,7 +44,7 @@ /// TODO: remove below static char* buffer_start = NULL; // TODO: redo the next two functions -static void SaveRefString(char* string, int id) +static int SaveRefString(char* string, int id) { //printf("Adding Ref String %d (%s)\n", id, string); string_ref* tmp = ref_strings; @@ -52,19 +52,30 @@ { if(tmp->id == id) { - tmp->string = malloc(strlen(string+1)); + tmp->string = malloc(strlen(string)+1); + if (!tmp->string) { + return -1; + } sprintf(tmp->string, "%s", string); - return; + return 0; } tmp = tmp->next; } string_ref* new_ref = malloc(sizeof(string_ref)); + if (!new_ref) { + return -1; + } new_ref->string = malloc(strlen(string)+1); + if (!new_ref->string) { + free(new_ref); + return -1; + } sprintf(new_ref->string, "%s", string); new_ref->id = id; new_ref->next = ref_strings; ref_strings = new_ref; + return 0; } static char* GetRefString(int id) @@ -249,6 +260,9 @@ configBuffer = malloc(strlen(buffer)+1); + if (!configBuffer) { + return -1; + } strcpy(configBuffer, buffer); buffer_start = configBuffer; @@ -342,7 +356,7 @@ } length = ParseTagString(buffer + pos, tag); - SaveRefString(buffer + pos, id); + if (SaveRefString(buffer + pos, id) != 0) return -1; } else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) { @@ -415,7 +429,7 @@ } length = ParseTagInteger(buffer + pos, tag); - SaveRefString((*tag)->string, id); + if (SaveRefString((*tag)->string, id) != 0) return -1; } else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) { Index: branches/cparm/i386/libsaio/console.c =================================================================== --- branches/cparm/i386/libsaio/console.c (revision 1983) +++ branches/cparm/i386/libsaio/console.c (revision 1984) @@ -52,79 +52,39 @@ #define BOOTER_LOG_SIZE (128 * 1024) #define SAFE_LOG_SIZE 134 -struct LOG { +#define LOG 1 +#define PRINT 2 + +struct log_t { char *buf; - char *cursor; + char *ptr; }; -typedef struct LOG LOG; -static LOG booterlog; +typedef struct log_t log_t; +static log_t booterlog; -struct putc_info { - char * str; - char * last_str; -}; - -void sputc(int c, struct putc_info * pi) -{ - if (pi->last_str) - if (pi->str == pi->last_str) - { - *(pi->str) = '\0'; - return; - } - *(pi->str)++ = c; -} - void initBooterLog(void) { booterlog.buf = malloc(BOOTER_LOG_SIZE); if (!booterlog.buf) { printf("Couldn't allocate buffer for booter log\n"); - booterlog.cursor = 0; + booterlog.ptr = 0; booterlog.buf = 0; return; } bzero(booterlog.buf, BOOTER_LOG_SIZE); - booterlog.cursor = booterlog.buf; + booterlog.ptr = booterlog.buf; } -char *getConsoleMsg(void) +void +debug_putc(char c) { - return booterlog.buf; + if (((booterlog.ptr-booterlog.buf) < (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) { + *booterlog.ptr=c; + booterlog.ptr++; + } } -char *getConsoleCursor(void) -{ - return booterlog.cursor; -} -void setConsoleMsg(char *p) -{ - booterlog.buf = p; -} -void setConsoleCursor(char *p) -{ - booterlog.cursor = p; -} -void msglog(const char * fmt, ...) -{ - va_list ap; - struct putc_info pi; - - if (!booterlog.buf) - return; - - if (((booterlog.cursor - booterlog.buf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) - return; - - va_start(ap, fmt); - pi.str = booterlog.cursor; - pi.last_str = 0; - prf(fmt, ap, sputc, &pi); - va_end(ap); - booterlog.cursor += strlen((char *)booterlog.cursor); -} - void setupBooterLog(void) { if (!booterlog.buf) @@ -141,7 +101,7 @@ /* * write one character to console */ -void putchar(int c) +void putchar(char c) { if ( c == '\t' ) { @@ -181,57 +141,60 @@ return (c); } +int +reallyVPrint(const char *format, va_list ap, int flag) +{ + if (flag & PRINT) prf(format, ap, putchar); + + if (flag & LOG) + { + /* Kabyl: BooterLog */ + prf(format, ap, debug_putc); + } + return 0; +} + +int localVPrintf(const char *format, va_list ap, int flag) +{ + /**/ + + reallyVPrint(format, ap, flag); + return 0; +} + int printf(const char * fmt, ...) { va_list ap; va_start(ap, fmt); - prf(fmt, ap, putchar, 0); + localVPrintf(fmt, ap, LOG | PRINT); - { - /* Kabyl: BooterLog */ - struct putc_info pi; - - if (!booterlog.buf) - return 0; - - if (((booterlog.cursor - booterlog.buf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) - return 0; - pi.str = booterlog.cursor; - pi.last_str = 0; - prf(fmt, ap, sputc, &pi); - booterlog.cursor += strlen((char *)booterlog.cursor); - } - va_end(ap); return 0; } +void msglog(const char * fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + + localVPrintf(fmt, ap, LOG); + + va_end(ap); +} + int verbose(const char * fmt, ...) { va_list ap; - + int flag = 0; va_start(ap, fmt); if (get_env(envgVerboseMode)) { - prf(fmt, ap, putchar, 0); + flag = PRINT; } - { - /* Kabyl: BooterLog */ - struct putc_info pi; - - if (!booterlog.buf) - return 0; - - if (((booterlog.cursor - booterlog.buf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) - return 0; - pi.str = booterlog.cursor; - pi.last_str = 0; - prf(fmt, ap, sputc, &pi); - booterlog.cursor += strlen((char *)booterlog.cursor); - } + localVPrintf(fmt, ap, LOG | flag); va_end(ap); @@ -241,23 +204,21 @@ int error(const char * fmt, ...) { va_list ap; - struct putc_info pi; int len; char *str = NULL; va_start(ap, fmt); - len = prf(fmt, ap, 0, 0); + + localVPrintf(fmt, ap, 0); + + + len = prf(fmt, ap, 0); if (len > 0) { str = newEmptyStringWithLength(len); if (str != NULL) - { - pi.last_str = 0; - - pi.str = str; - - prf(fmt, ap, sputc, &pi); - *pi.str = '\0'; + { + vsnprintf(str,len,fmt,ap); } } @@ -276,7 +237,7 @@ printf("\n"); va_start(ap, fmt); - prf(fmt, ap, putchar, 0); + localVPrintf(fmt, ap, PRINT); va_end(ap); printf("\nThis is a non recoverable error! System HALTED!!!"); @@ -294,23 +255,17 @@ char * newStringWithFormat(const char * fmt, ...) { va_list ap; - struct putc_info pi; int len; char *str = NULL; va_start(ap, fmt); - len = prf(fmt, ap, 0, 0); + len = prf(fmt, ap, 0); if (len > 0) { str = newEmptyStringWithLength(len); if (str != NULL) - { - pi.last_str = 0; - - pi.str = str; - - prf(fmt, ap, sputc, &pi); - *pi.str = '\0'; + { + vsnprintf(str,len,fmt,ap); } } Index: branches/cparm/i386/libsaio/xml.h =================================================================== --- branches/cparm/i386/libsaio/xml.h (revision 1983) +++ branches/cparm/i386/libsaio/xml.h (revision 1984) @@ -82,6 +82,7 @@ #define kPropIOClass ("IOClass") #define kPropIOProviderClass ("IOProviderClass") #define kPropOSBundleWorkspace ("OSBundleWorkspace") +#define kPropCFBundleLocalizations ("CFBundleLocalizations") #define DEFAULT_BOOT_CONFIG_DICT (TagPtr)0 #define DEFAULT_SYSTEM_CONFIG_DICT (TagPtr)1 Index: branches/cparm/i386/libsaio/ext2fs.c =================================================================== --- branches/cparm/i386/libsaio/ext2fs.c (revision 1983) +++ branches/cparm/i386/libsaio/ext2fs.c (revision 1984) @@ -20,9 +20,9 @@ void EX2GetDescription(CICell ih, char *str, long strMaxLen) { char * buf=malloc (EX2ProbeSize); - str[0]=0; if (!buf) return; + str[0]=0; Seek(ih, 0); Read(ih, (long)buf, EX2ProbeSize); if (!EX2Probe (buf)) Index: branches/cparm/i386/libsaio/Makefile =================================================================== --- branches/cparm/i386/libsaio/Makefile (revision 1983) +++ branches/cparm/i386/libsaio/Makefile (revision 1984) @@ -12,8 +12,8 @@ CFLAGS = $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost -fno-stack-protector \ -D__ARCHITECTURE__=\"i386\" \ $(DEBUG) \ - -fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) -march=pentium4 -msse2 -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE -mpreferred-stack-boundary=2 -fno-align-functions -mfpmath=sse - + -fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) -march=pentium4 -msse2 -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE -mpreferred-stack-boundary=2 -fno-align-functions -mfpmath=sse +GFLAGS = DEFINES= CONFIG = hd INC = -I. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSADIR) -I$(BOOT2DIR) Index: branches/cparm/i386/libsaio/modules.c =================================================================== --- branches/cparm/i386/libsaio/modules.c (revision 1983) +++ branches/cparm/i386/libsaio/modules.c (revision 1984) @@ -1425,6 +1425,9 @@ long willLoad; TagPtr dict; TagPtr personalities; +#if 0 + config_file_t *LanguageConfig; // we will use an xml file instead of pure txt file ... it's easier to parse +#endif //pool_t workspace; char *plistAddr; long plistLength; @@ -2054,9 +2057,41 @@ } - } - + } + tmpModule->willLoad = BundlePriorityNormalPriority; + +#if 0 + prop = XMLGetProperty(moduleDict, kPropCFBundleLocalizations); + if ((prop != 0) && prop->string) + { + char * path = newStringWithFormat("%s%s",module->bundlePath,prop->string); + if (path == NULL) { + break; + } + + if (loadConfigFile(path, module->LanguageConfig) != 0) + { + free(path); + path = NULL; + + const char * default_local; + if ((default_local = getStringForKey(kPropCFBundleLocalizations, DEFAULT_BOOT_CONFIG))) + { + path = newStringWithFormat("%s%s",module->bundlePath,default_local); + if (path == NULL) { + break; + } + loadConfigFile(path, module->LanguageConfig); + } + + } + + if (path) { + free(path); + } + } +#endif } while (0); Index: branches/cparm/i386/libsaio/befs.c =================================================================== --- branches/cparm/i386/libsaio/befs.c (revision 1983) +++ branches/cparm/i386/libsaio/befs.c (revision 1984) @@ -27,9 +27,9 @@ void BeFSGetDescription(CICell ih, char *str, long strMaxLen) { char * buf=malloc (BeFSProbeSize); - str[0]=0; if (!buf) return; + str[0]=0; Seek(ih, 0); Read(ih, (long)buf, BeFSProbeSize); if (!BeFSProbe (buf)) Index: branches/cparm/i386/libsaio/device_inject.c =================================================================== --- branches/cparm/i386/libsaio/device_inject.c (revision 1983) +++ branches/cparm/i386/libsaio/device_inject.c (revision 1984) @@ -88,6 +88,108 @@ return string; } +struct DevPropDevice *devprop_make_device(pci_dt_t *pci_dt) +{ + struct DevPropDevice *device; + int numpaths = 0; + + pci_dt_t *current; + pci_dt_t *end; + + end = root_pci_dev; + + device = malloc(sizeof(struct DevPropDevice)); + if (!device) { + return NULL; + } + memset(device, 0, sizeof(struct DevPropDevice)); + + device->acpi_dev_path._UID = getPciRootUID(); + while (end != pci_dt) + { + current = pci_dt; + while (current->parent != end) + current = current->parent; + end = current; + + { + device->pci_dev_path[numpaths].device = (uint8_t)current->dev.bits.dev; + device->pci_dev_path[numpaths].function = (uint8_t)current->dev.bits.func; + numpaths++; + } + + } + + if(!numpaths) + { + printf("ERROR parsing device path\n"); + free(device); + return NULL; + } + + device->numentries = 0x00; + + device->acpi_dev_path.length = 0x0c; + device->acpi_dev_path.type = 0x02; + device->acpi_dev_path.subtype = 0x01; + device->acpi_dev_path._HID = 0xd041030a; + + device->num_pci_devpaths = numpaths; + device->length = 24 + (6*numpaths); + + int 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; + } + + device->path_end.length = 0x04; + device->path_end.type = 0x7f; + device->path_end.subtype = 0xff; + + device->data = NULL; + + return device; +} + +struct DevPropDevice *devprop_add_device(struct DevPropString *string, pci_dt_t * pci_dt) +{ + struct DevPropDevice *device; + + if (string == NULL || pci_dt == NULL) { + return NULL; + } + device = devprop_make_device(pci_dt); + if (!device) { + return NULL; + } + + device->string = string; + string->length += device->length; + + if(!string->entries) + { + if((string->entries = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice) * MAX_STRING_NUM_ENTRIES))== NULL) + { + printf("ERROR parsing device path 2\n"); + + free(device); + return NULL; + } + } + struct DevPropDevice **string_entries_arrey = (struct DevPropDevice **) string->entries; + + string->numentries++; + + string_entries_arrey[string->numentries-1] = device; + + return device; +} + +#if 0 struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path) { struct DevPropDevice *device; @@ -103,7 +205,7 @@ } if (strncmp(path, pciroot_string, strlen(pciroot_string))) { free(device); - printf("ERROR parsing device path\n"); + printf("ERROR parsing device path 1\n"); return NULL; } @@ -111,49 +213,46 @@ device->acpi_dev_path._UID = getPciRootUID(); int numpaths = 0; - int x, curr = 0; - char buff[] = "00"; + int x, curr = 0, w = 0; + + char buff[16]; + for (x = 0; x < strlen(path); x++) { + if (!strncmp(&path[x], pci_device_string, strlen(pci_device_string))) { x+=strlen(pci_device_string); curr=x; while(path[++x] != ','); - if(x-curr == 2) - { - sprintf(buff, "%c%c", path[curr], path[curr+1]); - } - else if(x-curr == 1) - { - sprintf(buff, "%c", path[curr]); - } - else - { - printf("ERROR parsing device path\n"); - numpaths = 0; - break; - } + + w = x-curr; + + if ((w > 4) || /*(w > sizeof(buff)) ||*/ (w == 0)) { + printf("ERROR parsing device path 2\n"); + break; + } + + snprintf(buff, x-curr, "%s",&path[curr]); + device->pci_dev_path[numpaths].device = (uint8_t)strtoul(buff, NULL, 16); + bzero(buff, sizeof(buff)); + x += 3; // 0x curr = x; while(path[++x] != ')'); - if(x-curr == 2) - { - sprintf(buff, "%c%c", path[curr], path[curr+1]); - } - else if(x-curr == 1) - { - sprintf(buff, "%c", path[curr]); - } - else - { - printf("ERROR parsing device path\n"); - numpaths = 0; - break; - } + + w = x-curr; + + if ((w > 4) || /*(w > sizeof(buff)) ||*/ (w == 0)) { + printf("ERROR parsing device path 3\n"); + break; + } + + snprintf(buff, x-curr, "%s",&path[curr]); + device->pci_dev_path[numpaths].function = (uint8_t)strtoul(buff, NULL, 16); // TODO: find dev from char *path numpaths++; @@ -162,6 +261,7 @@ if(!numpaths) { + printf("ERROR parsing device path 4\n"); free(device); return NULL; } @@ -197,6 +297,8 @@ { if((string->entries = (struct DevPropDevice*)malloc(sizeof(struct DevPropDevice) * MAX_STRING_NUM_ENTRIES))== NULL) { + printf("ERROR parsing device path 6\n"); + free(device); return NULL; } @@ -209,6 +311,7 @@ return device; } +#endif int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len) { Index: branches/cparm/i386/libsaio/device_inject.h =================================================================== --- branches/cparm/i386/libsaio/device_inject.h (revision 1983) +++ branches/cparm/i386/libsaio/device_inject.h (revision 1984) @@ -8,6 +8,8 @@ #ifndef __LIBSAIO_DEVICE_INJECT_H #define __LIBSAIO_DEVICE_INJECT_H +#include "pci.h" + #define DP_ADD_TEMP_VAL(dev, val) devprop_add_value(dev, (char*)val[0], (uint8_t*)val[1], strlen(val[1]) + 1) #define DP_ADD_TEMP_VAL_DATA(dev, val) devprop_add_value(dev, (char*)val.name, (uint8_t*)val.data, val.size) #define MAX_PCI_DEV_PATHS 4 @@ -70,7 +72,8 @@ char *efi_inject_get_devprop_string(uint32_t *len); struct DevPropString *devprop_create_string(void); -struct DevPropDevice *devprop_add_device(struct DevPropString *string, char *path); +struct DevPropDevice *devprop_add_device(struct DevPropString *string, pci_dt_t * pci_dt); +struct DevPropDevice *devprop_make_device(pci_dt_t *pci_dt); int devprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len); char *devprop_generate_string(struct DevPropString *string); void devprop_free_string(struct DevPropString *string); Index: branches/cparm/i386/libsaio/openbsd.c =================================================================== --- branches/cparm/i386/libsaio/openbsd.c (revision 1983) +++ branches/cparm/i386/libsaio/openbsd.c (revision 1984) @@ -11,9 +11,9 @@ void OpenBSDGetDescription(CICell ih, char *str, long strMaxLen) { char * buf=malloc(OpenBSDProbeSize); - str[0]=0; if (!buf) return; + str[0]=0; Seek(ih, 0); Read(ih, (long)buf, OpenBSDProbeSize); if (!OpenBSDProbe (buf)) Index: branches/cparm/i386/libsaio/freebsd.c =================================================================== --- branches/cparm/i386/libsaio/freebsd.c (revision 1983) +++ branches/cparm/i386/libsaio/freebsd.c (revision 1984) @@ -11,9 +11,9 @@ void FreeBSDGetDescription(CICell ih, char *str, long strMaxLen) { char * buf=malloc(FreeBSDProbeSize); - str[0]=0; if (!buf) return; + str[0]=0; Seek(ih, 0); Read(ih, (long)buf, FreeBSDProbeSize); if (!FreeBSDProbe (buf)) Index: branches/cparm/i386/libsaio/pci.c =================================================================== --- branches/cparm/i386/libsaio/pci.c (revision 1983) +++ branches/cparm/i386/libsaio/pci.c (revision 1984) @@ -164,6 +164,7 @@ #endif } +#if 0 char *get_pci_dev_path(pci_dt_t *pci_dt) { char* buffer = malloc(sizeof(char) * 256); @@ -200,6 +201,7 @@ } return buffer; } +#endif void setup_pci_devs(pci_dt_t *pci_dt) { @@ -222,10 +224,9 @@ current = pci_dt; while (current) { - printf("%02x:%02x.%x [%04x] [%04x:%04x] :: %s\n", + printf("%02x:%02x.%x [%04x] [%04x:%04x] \n", current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func, - current->class_id, current->vendor_id, current->device_id, - get_pci_dev_path(current)); + current->class_id, current->vendor_id, current->device_id); dump_pci_dt(current->children); current = current->next; } Index: branches/cparm/i386/libsaio/stringTable.c =================================================================== --- branches/cparm/i386/libsaio/stringTable.c (revision 1983) +++ branches/cparm/i386/libsaio/stringTable.c (revision 1984) @@ -114,7 +114,9 @@ len = strlen(key); tab = (char *)table; buf = (char *)malloc(len + 3); - + if (!buf) { + return false; + } sprintf(buf, "\"%s\"", key); len = strlen(buf); @@ -172,6 +174,9 @@ return 0; bufsize = end - begin + 1; newstr = malloc(bufsize); + if (!newstr) { + return 0; + } strlcpy(newstr, begin, bufsize); *list = end; *size = newsize; @@ -251,6 +256,9 @@ if (getValueForConfigTableKey(config, key, &val, &size)) { newstr = (char *)malloc(size+1); + if (!newstr) { + return 0; + } for (p = newstr; size; size--, p++, val++) { if ((*p = *val) == '\\') { switch (*++val) { @@ -290,6 +298,9 @@ if (getValueForKey(key, &val, &size, config) && size) { newstr = (char *)malloc(size + 1); + if (!newstr) { + return 0; + } strlcpy(newstr, val, size + 1); return newstr; } else { Index: branches/cparm/i386/libsaio/pci.h =================================================================== --- branches/cparm/i386/libsaio/pci.h (revision 1983) +++ branches/cparm/i386/libsaio/pci.h (revision 1984) @@ -60,7 +60,7 @@ extern void pci_config_write8(uint32_t, uint8_t, uint8_t); extern void pci_config_write16(uint32_t, uint8_t, uint16_t); extern void pci_config_write32(uint32_t, uint8_t, uint32_t); -extern char *get_pci_dev_path(pci_dt_t *); +//extern char *get_pci_dev_path(pci_dt_t *); extern void build_pci_dt(void); extern void dump_pci_dt(pci_dt_t *); extern void setup_pci_devs(pci_dt_t *pci_dt); Index: branches/cparm/i386/libsaio/msdos.c =================================================================== --- branches/cparm/i386/libsaio/msdos.c (revision 1983) +++ branches/cparm/i386/libsaio/msdos.c (revision 1984) @@ -183,6 +183,10 @@ } buf=malloc (512); + if (!buf) + { + return -1; + } /* * Read the boot sector of the filesystem, and then check the * boot signature. If not a dos boot sector then error out. @@ -267,6 +271,10 @@ char *cacheBuffer; cacheBuffer = malloc(MSDOS_CACHE_BLOCKSIZE); + if (!cacheBuffer) + { + return -1; + } CacheRead(ih, cacheBuffer, sectorOffset, MSDOS_CACHE_BLOCKSIZE, true); bcopy(cacheBuffer + relOffset, buf, size); free(cacheBuffer); @@ -327,7 +335,7 @@ readOffset += ((uint64_t)*cluster * (uint64_t)msdosfatbits) / 8; /* Read one sector of the FAT */ - readSector(ih, readOffset, tmpbuf, 4); + if (readSector(ih, readOffset, tmpbuf, 4) != 0) return 0; switch (msdosfatbits) { case 32: @@ -673,9 +681,18 @@ if (!st) { st=malloc (sizeof (struct msdosdirstate)); + if (!st) + { + return -1; + } if (dirPath[0]) { uint8_t *buf=malloc(msdosclustersize); + if (!buf) + { + free (st); + return -1; + } dirp = getdirpfrompath (ih, dirPath, buf); if (!dirp || !(dirp->deAttributes & ATTR_DIRECTORY)) { @@ -708,6 +725,12 @@ int i; for (i=0;vfatname[i];i++); *name = malloc (256); + if (!*name) + { + free (st->buf); + free (st); + return -1; + } utf_encodestr(vfatname, i, (u_int8_t *)*name, 255, OSLittleEndian ); } else @@ -715,6 +738,12 @@ int i, j, k; uint16_t tmp[13]; *name = malloc (26); + if (!*name) + { + free (st->buf); + free (st); + return -1; + } for (i=7;i>=0;i--) if (dirp->deName[i]!=' ') break; @@ -770,6 +799,9 @@ if (filePath[0] == '/') filePath++; buf = malloc(msdosclustersize); + if (!buf) { + return -1; + } dirp = getdirpfrompath (ih, filePath, buf); if (!dirp || (dirp->deAttributes & ATTR_DIRECTORY)) @@ -824,6 +856,9 @@ if (filePath[0] == '/') filePath++; buf = malloc(msdosclustersize); + if (!buf) { + return -1; + } dirp = getdirpfrompath (ih, filePath, buf); if (!dirp || (dirp->deAttributes & ATTR_DIRECTORY)) { @@ -920,6 +955,9 @@ initRoot (&st); st.buf = malloc(msdosclustersize); + if (!st.buf) { + return; + } while ((dirp = getnextdirent (ih, vfatlabel, &st))) if (dirp->deAttributes & ATTR_VOLUME) { strncpy((char *)label, (char *)dirp->deName, LABEL_LENGTH); @@ -941,6 +979,9 @@ /* else look in the boot blocks */ if (!labelfound || str[0] == '\0') { char *buf = malloc (512); + if (!buf) { + return; + } union bootsector *bsp = (union bootsector *)buf; Seek(ih, 0); Read(ih, (long)buf, 512); @@ -961,6 +1002,9 @@ MSDOSGetUUID(CICell ih, char *uuidStr) { char *buf = malloc (512); + if (!buf) { + return -1; + } union bootsector *bsp = (union bootsector *)buf; if (MSDOSInitPartition (ih)<0) Index: branches/cparm/i386/libsaio/saio_internal.h =================================================================== --- branches/cparm/i386/libsaio/saio_internal.h (revision 1983) +++ branches/cparm/i386/libsaio/saio_internal.h (revision 1984) @@ -109,8 +109,11 @@ /* console.c */ extern void initBooterLog(void); extern void setupBooterLog(void); -extern void putchar(int ch); +extern void putchar(char ch); +extern void debug_putc(char c); extern int getchar(void); +extern int localVPrintf(const char *format, va_list ap, int flag); +extern int reallyVPrint(const char *format, va_list ap, int flag); extern void msglog(const char * format, ...); extern int printf(const char *format, ...); extern int error(const char *format, ...); Index: branches/cparm/i386/MakeInc.dir =================================================================== --- branches/cparm/i386/MakeInc.dir (revision 1983) +++ branches/cparm/i386/MakeInc.dir (revision 1984) @@ -40,19 +40,19 @@ .SUFFIXES: .s .i .c .o .c.o .m.o: - $(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o + $(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -no-integrated-as -c $(INC) $< -o $(OBJROOT)/$*.o $(OBJROOT)/%.o: %.c - $(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o + $(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -no-integrated-as -c $(INC) $< -o $(OBJROOT)/$*.o $(OBJROOT)/%.o: %.m - $(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $(OBJROOT)/$*.o + $(CC) $(CPPFLAGS) $(GFLAGS) $(CFLAGS) $(DEFINES) -no-integrated-as -c $(INC) $< -o $(OBJROOT)/$*.o .s.o: $(CC) $(CPPFLAGS) $(GFLAGS) -no-integrated-as -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) $< boot2.o: - $(CC) $(CPPFLAGS)$(GFLAGS) -Wa,-n -c $(INC) -no-integrated-as -arch i386 -o $(OBJROOT)/$(@F) boot2.s + $(CC) $(CPPFLAGS)$(GFLAGS) -no-integrated-as -Wa,-n -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) boot2.s $(OBJROOT)/%.o: %.s $(CC) $(CPPFLAGS) $(GFLAGS) -no-integrated-as -c $(INC) -arch i386 -o $(OBJROOT)/$(@F) $< Index: branches/cparm/i386/boot2/Makefile =================================================================== --- branches/cparm/i386/boot2/Makefile (revision 1983) +++ branches/cparm/i386/boot2/Makefile (revision 1984) @@ -29,7 +29,7 @@ -mpreferred-stack-boundary=2 -fno-align-functions \ -march=pentium4 -msse2 -mfpmath=sse -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE -GFLAGS = +GFLAGS = DEFINES= CONFIG = hd SYMDIR = $(SYMROOT) @@ -71,8 +71,8 @@ CFLAGS += -DSAFE_MALLOC -#GFLAGS += -DNO_MULTIBOOT_SUPPORT -OBJS += mboot.o +GFLAGS += -DNO_MULTIBOOT_SUPPORT +#OBJS += mboot.o # CFLAGS += -DBOOT_HELPER_SUPPORT # +992 bytes Index: branches/cparm/i386/modules/YellowIconFixer/YellowIconFixer.c =================================================================== --- branches/cparm/i386/modules/YellowIconFixer/YellowIconFixer.c (revision 1983) +++ branches/cparm/i386/modules/YellowIconFixer/YellowIconFixer.c (revision 1984) @@ -31,39 +31,32 @@ { pci_dt_t* current = arg1; struct DevPropDevice *device; - char *devicepath; struct DevPropString *string; if (current && current->class_id == PCI_CLASS_STORAGE_SATA) { - devicepath = get_pci_dev_path(current); - if (devicepath) - { - - string = (struct DevPropString *)(uint32_t)get_env(envEFIString); - - if (!string) - { - string = devprop_create_string(); - if (!string) return; - safe_set_env(envEFIString,(uint32_t)string); - } - device = devprop_add_device(string, devicepath); - if (!device) return; - + string = (struct DevPropString *)(uint32_t)get_env(envEFIString); + + if (!string) + { + string = devprop_create_string(); + if (!string) return; + safe_set_env(envEFIString,(uint32_t)string); + } + device = devprop_add_device(string, current); + if (!device) return; + #if PROOFOFCONCEPT - uint16_t vendor_id = current->vendor_id & 0xFFFF; - uint16_t device_id = current->device_id & 0xFFFF; - - devprop_add_value(device, "vendor-id", (uint8_t*)&vendor_id, 4); - devprop_add_value(device, "device-id", (uint8_t*)&device_id, 4); + uint16_t vendor_id = current->vendor_id & 0xFFFF; + uint16_t device_id = current->device_id & 0xFFFF; + + devprop_add_value(device, "vendor-id", (uint8_t*)&vendor_id, 4); + devprop_add_value(device, "device-id", (uint8_t*)&device_id, 4); #else - devprop_add_value(device, "device-id", default_SATA_ID, SATA_ID_LEN); - + devprop_add_value(device, "device-id", default_SATA_ID, SATA_ID_LEN); + #endif - verbose("SATA device : [%04x:%04x :: %04x] :: %s\n", - current->vendor_id, current->device_id,current->class_id, - devicepath); - } + verbose("SATA device : [%04x:%04x :: %04x]\n", + current->vendor_id, current->device_id,current->class_id); } } Index: branches/cparm/i386/modules/GUI/gui.c =================================================================== --- branches/cparm/i386/modules/GUI/gui.c (revision 1983) +++ branches/cparm/i386/modules/GUI/gui.c (revision 1984) @@ -69,10 +69,6 @@ #include "art.h" #endif -struct putc_info { - char * str; - char * last_str; -}; static int loadThemeImage(char *src, const char *image, int alt_image); static void loadBootGraphics(char *src); @@ -88,7 +84,6 @@ #if DEBUG_GUI static int dprintf( window_t * window, const char * fmt, ...); #endif -static void sputc(int c, struct putc_info * pi); static inline void vramwrite (void *data, int width); @@ -1750,39 +1745,48 @@ } } +struct putc_info { + char * str; + char * last_str; +}; static void -sputc(int c, struct putc_info * pi) +sputc(int c, void * pi) { - if (pi->last_str) - if (pi->str == pi->last_str) { - *(pi->str) = '\0'; - return; - } - *(pi->str)++ = c; + if (((struct putc_info*)pi)->last_str) + if (((struct putc_info*)pi)->str == ((struct putc_info*)pi)->last_str) { + *(((struct putc_info*)pi)->str) = '\0'; + return; + } + *(((struct putc_info*)pi)->str)++ = c; } int gprintf( window_t * window, const char * fmt, ...) { char *formattedtext; - + struct putc_info pi; + va_list ap; - - struct putc_info pi; - + if ((formattedtext = malloc(1024)) != NULL) { + + + position_t origin, cursor, bounds; + + int i; + int character; + + va_start(ap, fmt); + + localVPrintf(fmt, ap, 0); + // format the text - va_start(ap, fmt); pi.str = formattedtext; pi.last_str = 0; - prf(fmt, ap, sputc, &pi); + __doprnt(fmt, ap, sputc, &pi, 10); *pi.str = '\0'; + va_end(ap); - position_t origin, cursor, bounds; - - int i; - int character; - origin.x = MAX( window->cursor.x, window->hborder ); origin.y = MAX( window->cursor.y, window->vborder ); @@ -1849,25 +1853,28 @@ char *formattedtext; va_list ap; - + struct putc_info pi; + + //window = &gui.debug; - struct putc_info pi; - if ((formattedtext = malloc(1024)) != NULL) { + + position_t origin, cursor, bounds; + + int i; + int character; + + va_start(ap, fmt); + // format the text - va_start(ap, fmt); pi.str = formattedtext; pi.last_str = 0; - prf(fmt, ap, sputc, &pi); + __doprnt(fmt, ap, sputc, &pi, 10); *pi.str = '\0'; + va_end(ap); - position_t origin, cursor, bounds; - - int i; - int character; - origin.x = MAX( gui.debug.cursor.x, window->hborder ); origin.y = MAX( gui.debug.cursor.y, window->vborder ); @@ -1929,24 +1936,26 @@ return 1; } #endif + int vprf(const char * fmt, va_list ap) { int i; int character; + struct putc_info pi; char *formattedtext; window_t *window = &gui.screen; - struct putc_info pi; position_t origin, cursor, bounds; font_t *font = &font_console; - if ((formattedtext = malloc(1024)) != NULL) { + if ((formattedtext = malloc(1024)) != NULL){ + // format the text - pi.str = formattedtext; - pi.last_str = 0; - prf(fmt, ap, sputc, &pi); - *pi.str = '\0'; + pi.str = formattedtext; + pi.last_str = 0; + __doprnt(fmt, ap, sputc, &pi, 10); + *pi.str = '\0'; origin.x = MAX( window->cursor.x, window->hborder ); origin.y = MAX( window->cursor.y, window->vborder ); @@ -1954,7 +1963,7 @@ 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; Index: branches/cparm/i386/modules/GUI/GUI_module.c =================================================================== --- branches/cparm/i386/modules/GUI/GUI_module.c (revision 1983) +++ branches/cparm/i386/modules/GUI/GUI_module.c (revision 1984) @@ -93,19 +93,14 @@ static int GUI_updateMenu( int key, void ** paramPtr ); static void GUI_showHelp(void); static void GUI_showMessage(char *message); - +/* int GUI_printf(const char * fmt, ...); int GUI_verbose(const char * fmt, ...); void GUI_stop(const char * fmt, ...); +*/ +int +GUI_reallyVPrint(const char *format, va_list ap, int flag); - -/* console.c */ -struct putc_info { - char * str; - char * last_str; -}; -void sputc(int c, struct putc_info * pi); - static void (*showTextBuffer)(char *, int ) = NULL; static char *(*getMemoryInfoString)(void) = NULL; static BVRef (*getBvChain)(void) = NULL; @@ -212,7 +207,7 @@ if(!get_env(envgVerboseMode)) { // Disable outputs, they will still show in the boot log. - replace_system_function("_printf", &GUI_verbose); + replace_system_function("_printf", &verbose); //drawBootGraphics(); } @@ -241,12 +236,12 @@ replace_system_function("_addBootArg", &GUI_addBootArg); replace_system_function("_showHelp", &GUI_showHelp); - - replace_system_function("_printf", &GUI_printf); - replace_system_function("_verbose", &GUI_verbose); - replace_system_function("_stop", &GUI_stop); + + replace_system_function("_reallyVPrint", &GUI_reallyVPrint); + //replace_system_function("_printf", &GUI_printf); + //replace_system_function("_verbose", &GUI_verbose); + //replace_system_function("_stop", &GUI_stop); replace_system_function("_showMessage", &GUI_showMessage); - // Hook for the boot screen register_hook_callback("GUI_ExecKernel", &GUI_ExecKernel_hook); @@ -1200,6 +1195,36 @@ return 0; } +int +GUI_reallyVPrint(const char *format, va_list ap, int flag) +{ +#define LOG 1 +#define PRINT 2 + + if (KernelStart == false) + { + if (flag & PRINT) { + + if (getVideoMode() == VGA_TEXT_MODE) + { + prf(format, ap, putchar); + } + else + { + vprf(format, ap); + } + } + } + + if (flag & LOG) + { + /* Kabyl: BooterLog */ + prf(format, ap, debug_putc); + } + + return 0; +} +#if 0 int GUI_verbose(const char * fmt, ...) { va_list ap; @@ -1210,7 +1235,7 @@ { if (getVideoMode() == VGA_TEXT_MODE) { - prf(fmt, ap, putchar, 0); + prf(fmt, ap, putchar); } else { @@ -1218,20 +1243,11 @@ } } - /* Kabyl: BooterLog */ - struct putc_info pi; + { + /* Kabyl: BooterLog */ + prf(fmt, ap, debug_putc); + } - if (!getConsoleMsg()) - return 0; - - if (((getConsoleCursor() - getConsoleMsg()) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) - return 0; - pi.str = getConsoleCursor(); - pi.last_str = 0; - prf(fmt, ap, sputc, &pi); - setConsoleCursor(getConsoleCursor() + strlen(getConsoleCursor())); - - va_end(ap); return(0); } @@ -1245,26 +1261,18 @@ if (getVideoMode() == VGA_TEXT_MODE) { - prf(fmt, ap, putchar, 0); + prf(fmt, ap, putchar); } else { vprf(fmt, ap); } } - /* Kabyl: BooterLog */ - struct putc_info pi; - - if (!getConsoleMsg()) - return 0; - - if (((getConsoleCursor() - getConsoleMsg()) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) - return 0; - pi.str = getConsoleCursor(); - pi.last_str = 0; - prf(fmt, ap, sputc, &pi); - setConsoleCursor(getConsoleCursor() + strlen(getConsoleCursor())); - + + { + /* Kabyl: BooterLog */ + prf(fmt, ap, debug_putc); + } va_end(ap); return 0; } @@ -1278,7 +1286,7 @@ if (getVideoMode() == VGA_TEXT_MODE) { - prf(fmt, ap, putchar, 0); + prf(fmt, ap, putchar); } else { @@ -1290,7 +1298,7 @@ halt(); while (1); } - +#endif void GUI_showHelp(void) { if (getVideoMode() == GRAPHICS_MODE) { Index: branches/cparm/i386/modules/Networking/Networking.c =================================================================== --- branches/cparm/i386/modules/Networking/Networking.c (revision 1983) +++ branches/cparm/i386/modules/Networking/Networking.c (revision 1984) @@ -104,15 +104,11 @@ } static void set_eth_builtin(pci_dt_t *eth_dev) -{ - char *devicepath = get_pci_dev_path(eth_dev); - if (!devicepath) { - return ; - } +{ struct DevPropDevice *device; struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString); - verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath); + verbose("LAN Controller [%04x:%04x]\n", eth_dev->vendor_id, eth_dev->device_id); if (!string) { @@ -121,7 +117,7 @@ safe_set_env(envEFIString,(uint32_t)string); } - device = devprop_add_device(string, devicepath); + device = devprop_add_device(string, eth_dev); if(device) { verbose("Setting up lan keys\n"); @@ -148,15 +144,11 @@ static void set_wifi_airport(pci_dt_t *wlan_dev) { char tmp[16]; - - char *devicepath = get_pci_dev_path(wlan_dev); - if (!devicepath) { - return ; - } + struct DevPropDevice *device ; struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString); - verbose("Wifi Controller [%04x:%04x] :: %s\n", wlan_dev->vendor_id, wlan_dev->device_id, devicepath); + verbose("Wifi Controller [%04x:%04x]\n", wlan_dev->vendor_id, wlan_dev->device_id); if (!string) { @@ -165,7 +157,7 @@ safe_set_env(envEFIString,(uint32_t)string); } - device = devprop_add_device(string, devicepath); + device = devprop_add_device(string, wlan_dev); if(device) { sprintf(tmp, "Airport"); Index: branches/cparm/i386/modules/GraphicsEnabler/gma.c =================================================================== --- branches/cparm/i386/modules/GraphicsEnabler/gma.c (revision 1983) +++ branches/cparm/i386/modules/GraphicsEnabler/gma.c (revision 1984) @@ -90,7 +90,6 @@ bool setup_gma_devprop(pci_dt_t *gma_dev) { //int len; - char *devicepath; #if UNUSED volatile uint8_t *regs; #endif @@ -99,18 +98,14 @@ uint8_t BuiltIn = 0x00; uint8_t ClassFix[4] = { 0x00, 0x00, 0x03, 0x00 }; - devicepath = get_pci_dev_path(gma_dev); - if (!devicepath) { - return false; - } bar[0] = pci_config_read32(gma_dev->dev.addr, 0x10); #if UNUSED regs = (uint8_t *) (bar[0] & ~0x0f); #endif model = get_gma_model((gma_dev->vendor_id << 16) | gma_dev->device_id); - verbose("Intel %s [%04x:%04x] :: %s\n", - model, gma_dev->vendor_id, gma_dev->device_id, devicepath); + verbose("Intel %s [%04x:%04x]\n", + model, gma_dev->vendor_id, gma_dev->device_id); struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString); if (!string) @@ -120,7 +115,7 @@ safe_set_env(envEFIString,(uint32_t)string); } - struct DevPropDevice *device = devprop_add_device(string, devicepath); + struct DevPropDevice *device = devprop_add_device(string, gma_dev); if(!device) { Index: branches/cparm/i386/modules/GraphicsEnabler/nvidia.c =================================================================== --- branches/cparm/i386/modules/GraphicsEnabler/nvidia.c (revision 1983) +++ branches/cparm/i386/modules/GraphicsEnabler/nvidia.c (revision 1984) @@ -1280,7 +1280,6 @@ bool setup_nvidia_devprop(pci_dt_t *nvda_dev) { struct DevPropDevice *device; - char *devicepath; struct pci_rom_pci_header_t *rom_pci_header; volatile uint8_t *regs; uint8_t *rom; @@ -1310,11 +1309,7 @@ dcfg_t default_dcfg_1; bool dcfg0_set = false; bool dcfg1_set = false; - - devicepath = get_pci_dev_path(nvda_dev); - if (!devicepath) { - return false; - } + bar[0] = pci_config_read32(nvda_dev->dev.addr, 0x10 ); regs = (uint8_t *) (bar[0] & ~0x0f); @@ -1329,10 +1324,9 @@ model = get_nvidia_model((nvda_dev->vendor_id << 16) | nvda_dev->device_id); - verbose("nVidia %s %dMB NV%02x [%04x:%04x] :: %s\n", + verbose("nVidia %s %dMB NV%02x [%04x:%04x]\n", model, (uint32_t)(videoRam / 1024 / 1024), - (REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id, - devicepath); + (REG32(0) >> 20) & 0x1ff, nvda_dev->vendor_id, nvda_dev->device_id); rom = malloc(NVIDIA_ROM_SIZE); if (!rom) { @@ -1424,7 +1418,7 @@ safe_set_env(envEFIString,(uint32_t)string); } - device = devprop_add_device(string, devicepath); + device = devprop_add_device(string, nvda_dev); /* FIXME: for primary graphics card only */ boot_display = 1; @@ -1479,7 +1473,7 @@ uint8_t new_NVCAP[NVCAP_LEN]; if (hex2bin(value, new_NVCAP, NVCAP_LEN) == 0) { - verbose("Using user supplied NVCAP for %s :: %s\n", model, devicepath); + verbose("Using user supplied NVCAP for %s \n", model); memcpy(default_NVCAP, new_NVCAP, NVCAP_LEN); } } Index: branches/cparm/i386/modules/GraphicsEnabler/ati.c =================================================================== --- branches/cparm/i386/modules/GraphicsEnabler/ati.c (revision 1983) +++ branches/cparm/i386/modules/GraphicsEnabler/ati.c (revision 1984) @@ -927,7 +927,7 @@ bool load_vbios_file(const char *key, uint16_t vendor_id, uint16_t device_id, uint32_t subsys_id); void free_val(value_t *val); -void devprop_add_list(dev_prop_t devprop_list[]); +int devprop_add_list(dev_prop_t devprop_list[]); bool get_bootdisplay_val(value_t *val) { @@ -1026,15 +1026,17 @@ uint8_t *rev; if (!card->rom) return false; + + val->data = malloc(val->size); + if (!val->data) + return false; + rev = card->rom + *(uint8_t *)(card->rom + OFFSET_TO_GET_ATOMBIOS_STRINGS_START); val->type = kPtr; val->size = strlen((char *)rev); - val->data = malloc(val->size); - if (!val->data) - return false; memcpy(val->data, rev, val->size); @@ -1097,9 +1099,12 @@ bzero(val, sizeof(value_t)); } -void devprop_add_list(dev_prop_t devprop_list[]) +int devprop_add_list(dev_prop_t devprop_list[]) { value_t *val = malloc(sizeof(value_t)); + if (!val) { + return -1; + } int i, pnum; for (i = 0; devprop_list[i].name != NULL; i++) @@ -1155,6 +1160,7 @@ } free(val); + return 0; } bool validate_rom(struct pci_rom_bios_t *rom_header, pci_dt_t *pci_dev) @@ -1239,15 +1245,18 @@ if (!validate_rom(rom_addr, card->pci_dev)) return false; - + + card->rom = malloc(card->rom_size); + if (!card->rom) + return false; + card->rom_size = rom_addr->size * 512; if (!card->rom_size) + { + free(card->rom); return false; + } - card->rom = malloc(card->rom_size); - if (!card->rom) - return false; - memcpy(card->rom, (void *)rom_addr, card->rom_size); return true; @@ -1534,8 +1543,6 @@ bool setup_ati_devprop(pci_dt_t *ati_dev) { - char *devicepath; - struct DevPropString *string = (struct DevPropString *)(uint32_t)get_env(envEFIString); if (!string) { @@ -1544,16 +1551,12 @@ safe_set_env(envEFIString,(uint32_t)string); } - devicepath = get_pci_dev_path(ati_dev); - if (!devicepath) { - return false; - } - verbose("ATI VGA Controller [%04x:%04x] :: %s \n", - ati_dev->vendor_id, ati_dev->device_id, devicepath); + verbose("ATI VGA Controller [%04x:%04x] \n", + ati_dev->vendor_id, ati_dev->device_id); if (!init_card(ati_dev)) return false; - card->device = devprop_add_device(string, devicepath); + card->device = devprop_add_device(string, ati_dev); if (!card->device) return false; // ------------------------------------------------- @@ -1567,14 +1570,13 @@ devprop_add_value(card->device, "ATY,IOSpaceOffset", &io, 8); #endif - devprop_add_list(ati_devprop_list); + if (devprop_add_list(ati_devprop_list) == -1) return false; //fix me : remove all properties for this device - verbose("%s %dMB [%04x:%04x] (subsys [%04x:%04x]) (%s:%s) :: %s\n", + verbose("%s %dMB [%04x:%04x] (subsys [%04x:%04x]) (%s:%s) \n", card->info->model_name, (uint32_t)(card->vram_size / (1024 * 1024)), ati_dev->vendor_id, ati_dev->device_id, ati_dev->subsys_id.subsys.vendor_id, ati_dev->subsys_id.subsys.device_id, - chip_family_name[card->info->chip_family], card->cfg_name, - devicepath); + chip_family_name[card->info->chip_family], card->cfg_name); free(card); Index: branches/cparm/i386/modules/SMBiosGetters/smbios_decode.c =================================================================== --- branches/cparm/i386/modules/SMBiosGetters/smbios_decode.c (revision 1983) +++ branches/cparm/i386/modules/SMBiosGetters/smbios_decode.c (revision 1984) @@ -14,8 +14,12 @@ #if DEBUG_SMBIOS #define DBG(x...) printf(x) +#define DBGSMBIOS(x,y) if(y) printf(x,y) + #else #define DBG(x...) msglog(x) +#define DBGSMBIOS(x,y) if(y) msglog(x,y) + #endif @@ -66,9 +70,9 @@ static void decodeBIOSInformation(SMBBIOSInformation *structHeader) { DBG("BIOSInformation:\n"); - DBG("\tvendor: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->vendor)); - DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); - DBG("\treleaseDate: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->releaseDate)); + DBGSMBIOS("\tvendor: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->vendor)); + DBGSMBIOS("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); + DBGSMBIOS("\treleaseDate: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->releaseDate)); DBG("\n"); } @@ -78,26 +82,29 @@ static void decodeSystemInformation(SMBSystemInformation *structHeader) { DBG("SystemInformation:\n"); - DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); - DBG("\tproductName: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->productName)); - DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); - DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); + DBGSMBIOS("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); + DBGSMBIOS("\tproductName: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->productName)); + DBGSMBIOS("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); + DBGSMBIOS("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); if (minorVersion < 1 || structHeader->header.length < 25) return; uint8_t *uuid = structHeader->uuid; - DBG("\tuuid: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02x%02X-%02X%02X%02X%02X%02X%02X\n", + if (uuid) { + DBG("\tuuid: %02X%02X%02X%02X-%02X%02X-%02X%02X-%02x%02X-%02X%02X%02X%02X%02X%02X\n", uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]); - DBG("\twakeupReason: 0x%x\n", structHeader->wakeupReason); + } + + DBGSMBIOS("\twakeupReason: 0x%x\n", structHeader->wakeupReason); if (minorVersion < 4 || structHeader->header.length < 27) return; - DBG("\tskuNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->skuNumber)); - DBG("\tfamily: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->family)); + DBGSMBIOS("\tskuNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->skuNumber)); + DBGSMBIOS("\tfamily: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->family)); DBG("\n"); } @@ -107,13 +114,13 @@ static void decodeBaseBoard(SMBBaseBoard *structHeader) { DBG("BaseBoard:\n"); - DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); - DBG("\tproduct: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->product)); - DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); - DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); - DBG("\tassetTagNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber)); - DBG("\tlocationInChassis: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->locationInChassis)); - DBG("\tboardType: 0x%X\n", structHeader->boardType); + DBGSMBIOS("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); + DBGSMBIOS("\tproduct: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->product)); + DBGSMBIOS("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); + DBGSMBIOS("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); + DBGSMBIOS("\tassetTagNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber)); + DBGSMBIOS("\tlocationInChassis: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->locationInChassis)); + DBGSMBIOS("\tboardType: 0x%X\n", structHeader->boardType); DBG("\n"); } @@ -123,11 +130,11 @@ static void decodeSystemEnclosure(SMBSystemEnclosure *structHeader) { DBG("SystemEnclosure:\n"); - DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); - DBG("\ttype: %d\n", structHeader->type); - DBG("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); - DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); - DBG("\tassetTagNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber)); + DBGSMBIOS("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); + DBGSMBIOS("\ttype: %d\n", structHeader->type); + DBGSMBIOS("\tversion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->version)); + DBGSMBIOS("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); + DBGSMBIOS("\tassetTagNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTagNumber)); DBG("\n"); } @@ -137,21 +144,21 @@ static void decodeProcessorInformation(SMBProcessorInformation *structHeader) { DBG("ProcessorInformation:\n"); - DBG("\tsocketDesignation: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->socketDesignation)); - DBG("\tprocessorType: %d\n", structHeader->processorType); - DBG("\tprocessorFamily: 0x%X\n", structHeader->processorFamily); - DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); - DBG("\tprocessorID: 0x%llX\n", structHeader->processorID); - DBG("\tprocessorVersion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->processorVersion)); - DBG("\texternalClock: %dMHz\n", structHeader->externalClock); - DBG("\tmaximumClock: %dMHz\n", structHeader->maximumClock); - DBG("\tcurrentClock: %dMHz\n", structHeader->currentClock); + DBGSMBIOS("\tsocketDesignation: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->socketDesignation)); + DBGSMBIOS("\tprocessorType: %d\n", structHeader->processorType); + DBGSMBIOS("\tprocessorFamily: 0x%X\n", structHeader->processorFamily); + DBGSMBIOS("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); + DBGSMBIOS("\tprocessorID: 0x%llX\n", structHeader->processorID); + DBGSMBIOS("\tprocessorVersion: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->processorVersion)); + DBGSMBIOS("\texternalClock: %dMHz\n", structHeader->externalClock); + DBGSMBIOS("\tmaximumClock: %dMHz\n", structHeader->maximumClock); + DBGSMBIOS("\tcurrentClock: %dMHz\n", structHeader->currentClock); if (minorVersion < 3 || structHeader->header.length < 35) return; - DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); - DBG("\tassetTag: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag)); - DBG("\tpartNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber)); + DBGSMBIOS("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); + DBGSMBIOS("\tassetTag: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag)); + DBGSMBIOS("\tpartNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber)); DBG("\n"); } @@ -161,17 +168,17 @@ static void decodeMemoryDevice(SMBMemoryDevice *structHeader) { DBG("MemoryDevice:\n"); - DBG("\tdeviceLocator: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->deviceLocator)); - DBG("\tbankLocator: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->bankLocator)); - DBG("\tmemoryType: %s\n", SMBMemoryDeviceTypes[structHeader->memoryType]); + DBGSMBIOS("\tdeviceLocator: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->deviceLocator)); + DBGSMBIOS("\tbankLocator: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->bankLocator)); + DBGSMBIOS("\tmemoryType: %s\n", SMBMemoryDeviceTypes[structHeader->memoryType]); if (minorVersion < 3 || structHeader->header.length < 27) return; - DBG("\tmemorySpeed: %dMHz\n", structHeader->memorySpeed); - DBG("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); - DBG("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); - DBG("\tassetTag: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag)); - DBG("\tpartNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber)); + DBGSMBIOS("\tmemorySpeed: %dMHz\n", structHeader->memorySpeed); + DBGSMBIOS("\tmanufacturer: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->manufacturer)); + DBGSMBIOS("\tserialNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->serialNumber)); + DBGSMBIOS("\tassetTag: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->assetTag)); + DBGSMBIOS("\tpartNumber: %s\n", getSMBStringForField((SMBStructHeader *)structHeader, structHeader->partNumber)); DBG("\n"); } @@ -181,7 +188,7 @@ static void decodeOemProcessorType(SMBOemProcessorType *structHeader) { DBG("AppleProcessorType:\n"); - DBG("\tProcessorType: 0x%x\n", ((SMBOemProcessorType *)structHeader)->ProcessorType); + DBGSMBIOS("\tProcessorType: 0x%x\n", ((SMBOemProcessorType *)structHeader)->ProcessorType); DBG("\n"); } Index: branches/cparm/i386/modules/USBFix/usb.c =================================================================== --- branches/cparm/i386/modules/USBFix/usb.c (revision 1983) +++ branches/cparm/i386/modules/USBFix/usb.c (revision 1984) @@ -43,6 +43,9 @@ if(!usbList) { usbList = (struct pciList*)malloc(sizeof(struct pciList)); + if (!usbList) { + return; + } usbList->next = NULL; usbList->pciDev = pci_dev; @@ -54,6 +57,9 @@ current = current->next; } current->next = (struct pciList*)malloc(sizeof(struct pciList)); + if (!current) { + return; + } current = current->next; current->pciDev = pci_dev; Index: branches/cparm/i386/modules/Resolution/915resolution.c =================================================================== --- branches/cparm/i386/modules/Resolution/915resolution.c (revision 1983) +++ branches/cparm/i386/modules/Resolution/915resolution.c (revision 1984) @@ -247,6 +247,10 @@ { UInt32 z; vbios_map * map = malloc(sizeof(vbios_map)); + if (!map) { + return 0; + + } for(z=0; z - -#define SPACE 1 -#define ZERO 2 -#define UCASE 16 - -/* - * Scaled down version of C Library printf. - * Used to print diagnostic information directly on console tty. - * Since it is not interrupt driven, all system activities are - * suspended. - * - */ - -/* - * Printn prints a number n in base b. - * We don't use recursion to avoid deep kernel stacks. - */ -static void -printn(n, b, flag, minwidth, putfn_p, putfn_arg) -u_long n; -int b, flag, minwidth; -void (*putfn_p)(); -void *putfn_arg; -{ - char prbuf[11]; - register char *cp; - int width = 0, neg = 0; - - if (b == 10 && (int)n < 0) { - neg = 1; - n = (unsigned)(-(int)n); - } - cp = prbuf; - do { - *cp++ = "0123456789abcdef0123456789ABCDEF"[(flag & UCASE) + n%b]; - n /= b; - width++; - } while (n); - - if (neg) { - (*putfn_p)('-', putfn_arg); - width++; - } - while (width++ < minwidth) - (*putfn_p)( (flag & ZERO) ? '0' : ' ', putfn_arg); - - do - (*putfn_p)(*--cp, putfn_arg); - while (cp > prbuf); -} - -int prf( - char *fmt, - unsigned int *adx, - void (*putfn_p)(), - void *putfn_arg - ); -int prf( - char *fmt, - unsigned int *adx, - void (*putfn_p)(), - void *putfn_arg - ) -{ - int b, c, len =0; - char *s; - int flag = 0, width = 0; - int minwidth; - -loop: - while ((c = *fmt++) != '%') { - if(c == '\0') - return len; - if (putfn_p) { - (*putfn_p)(c, putfn_arg); - } - len++; - } - minwidth = 0; -again: - c = *fmt++; - switch (c) { - case 'l': - goto again; - case ' ': - flag |= SPACE; - goto again; - case '0': - if (minwidth == 0) { - /* this is a flag */ - flag |= ZERO; - goto again; - } /* fall through */ - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - minwidth *= 10; - minwidth += c - '0'; - goto again; - case 'X': - flag |= UCASE; - /* fall through */ - case 'x': - b = 16; - goto number; - case 'd': - b = 10; - goto number; - case 'o': case 'O': - b = 8; - number: - if (putfn_p) { - printn((u_long)*adx, b, flag, minwidth, putfn_p, putfn_arg); - } - len++; - break; - case 's': - s = (char *)*adx; - while ((c = *s++)) { - if (putfn_p) { - (*putfn_p)(c, putfn_arg); - } - len++; - width++; - } - while (width++ < minwidth) { - if (putfn_p) { - (*putfn_p)(' ', putfn_arg); - } - len++; - } - break; - case 'c': - if (putfn_p) { - (*putfn_p)((char)*adx, putfn_arg); - } - len++; - break; - default: - break; - } - adx++; - goto loop; -} \ No newline at end of file Index: branches/cparm/i386/libsa/libsa.h =================================================================== --- branches/cparm/i386/libsa/libsa.h (revision 1983) +++ branches/cparm/i386/libsa/libsa.h (revision 1984) @@ -112,15 +112,39 @@ /* * prf.c */ -extern int prf(const char * fmt, va_list ap, void (*putfn_p)(), - void * putfn_arg); +//extern int prf(const char * fmt, va_list ap, void (*putfn_p)(), +// void * putfn_arg); /* * printf.c */ extern int sprintf(char *s, const char * format, ...); -extern int slvprintf(char * buffer, int len, const char * fmt, va_list arg); +extern int snprintf(char *str, size_t size, const char *format, ...); +extern int vsnprintf(char *str, size_t size, const char *format, va_list ap); +extern void + _doprnt( + register const char *fmt, + va_list argp, + /* character output routine */ + void (*putc)(char), + int radix); /* default radix - for '%r' */ +extern int +prf( + const char *fmt, + va_list ap, + /* character output routine */ + void (*putc)(char)); + +extern int + __doprnt( + const char *fmt, + va_list argp, + /* character output routine */ + void (*putc)(int ch, void *arg), + void *arg, + int radix); + /* * zalloc.c */ Index: branches/cparm/i386/libsa/printf.c =================================================================== --- branches/cparm/i386/libsa/printf.c (revision 1983) +++ branches/cparm/i386/libsa/printf.c (revision 1984) @@ -1,4 +1,658 @@ /* + * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * + * @APPLE_LICENSE_HEADER_START@ + * + * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. + * + * @APPLE_LICENSE_HEADER_END@ + */ +/* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ +/*- + * Copyright (c) 1986, 1988, 1991, 1993 + * The Regents of the University of California. All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)subr_prf.c 8.4 (Berkeley) 5/4/95 + */ +/* + * @OSF_COPYRIGHT@ + */ + +/* + * Mach Operating System + * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University + * All Rights Reserved. + * + * Permission to use, copy, modify and distribute this software and its + * documentation is hereby granted, provided that both the copyright + * notice and this permission notice appear in all copies of the + * software, derivative works or modified versions, and any portions + * thereof, and that both notices appear in supporting documentation. + * + * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" + * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR + * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. + * + * Carnegie Mellon requests users of this software to return to + * + * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU + * School of Computer Science + * Carnegie Mellon University + * Pittsburgh PA 15213-3890 + * + * any improvements or extensions that they make and grant Carnegie Mellon + * the rights to redistribute these changes. + */ + + +#include "libsa.h" + +struct snprintf_arg { + char *str; + size_t remain; +}; + +static void +dummy_putc(int ch, void *arg) +{ + void (*real_putc)() = arg; + + if (real_putc) real_putc(ch); +} + +#if 0 +void +_doprnt( + register const char *fmt, + va_list argp, + /* character output routine */ + void (*putc)(), + int radix) /* default radix - for '%r' */ +{ + __doprnt(fmt, argp, dummy_putc, putc, radix); +} +#define Ctod(c) ((c) - '0') + +#define MAXBUF (sizeof(long long int) * 8) /* enough for binary */ +static char digs[] = "0123456789abcdef"; +static int +printnum( + unsigned long long int u, /* number to print */ + int base, + void (*putc)(int, void *), + void *arg) +{ + char buf[MAXBUF]; /* build number here */ + char * p = &buf[MAXBUF-1]; + int nprinted = 0; + + do { + *p-- = digs[u % base]; + u /= base; + } while (u != 0); + + while (++p != &buf[MAXBUF]) { + if (putc) (*putc)(*p, arg); + nprinted++; + } + + return nprinted; +} + +bool _doprnt_truncates = false; + +int +__doprnt( + const char *fmt, + va_list argp, + /* character output routine */ + void (*putc)(int ch, void *arg), + void *arg, + int radix) /* default radix - for '%r' */ +{ + int length; + int prec; + bool ladjust; + char padc; + long long n; + unsigned long long u; + int plus_sign; + int sign_char; + bool altfmt, truncate; + int base; + char c; + int capitals; + int long_long; + int nprinted = 0; + + while ((c = *fmt) != '\0') { + if (c != '%') { + if (putc) { + (*putc)(c, arg); + } + nprinted++; + fmt++; + continue; + } + + fmt++; + + long_long = 0; + length = 0; + prec = -1; + ladjust = false; + padc = ' '; + plus_sign = 0; + sign_char = 0; + altfmt = false; + + while (true) { + c = *fmt; + if (c == '#') { + altfmt = true; + } + else if (c == '-') { + ladjust = true; + } + else if (c == '+') { + plus_sign = '+'; + } + else if (c == ' ') { + if (plus_sign == 0) + plus_sign = ' '; + } + else + break; + fmt++; + } + + if (c == '0') { + padc = '0'; + c = *++fmt; + } + + if (isdigit(c)) { + while(isdigit(c)) { + length = 10 * length + Ctod(c); + c = *++fmt; + } + } + else if (c == '*') { + length = va_arg(argp, int); + c = *++fmt; + if (length < 0) { + ladjust = !ladjust; + length = -length; + } + } + + if (c == '.') { + c = *++fmt; + if (isdigit(c)) { + prec = 0; + while(isdigit(c)) { + prec = 10 * prec + Ctod(c); + c = *++fmt; + } + } + else if (c == '*') { + prec = va_arg(argp, int); + c = *++fmt; + } + } + + if (c == 'l') { + c = *++fmt; /* need it if sizeof(int) < sizeof(long) */ + if (sizeof(int) 32; p++) { + if (putc) (*putc)(c, arg); + nprinted++; + } + nprinted += printnum((unsigned)( (u>>(j-1)) & ((2<<(i-j))-1)), + base, putc, arg); + } + else if (u & (1<<(i-1))) { + if (any) + if (putc) (*putc)(',', arg); + else { + if (putc) (*putc)('<', arg); + any = true; + } + nprinted++; + for (; (c = *p) > 32; p++) { + if (putc) (*putc)(c, arg); + nprinted++; + } + } + else { + for (; *p > 32; p++) + continue; + } + } + if (any) { + if (putc) (*putc)('>', arg); + nprinted++; + } + break; + } + + case 'c': + c = va_arg(argp, int); + if (putc) (*putc)(c, arg); + nprinted++; + break; + + case 's': + { + register const char *p; + register const char *p2; + + if (prec == -1) + prec = 0x7fffffff; /* MAXINT */ + + p = va_arg(argp, char *); + + if (p == NULL) + p = ""; + + if (length > 0 && !ladjust) { + n = 0; + p2 = p; + + for (; *p != '\0' && n < prec; p++) + n++; + + p = p2; + + while (n < length) { + if (putc) (*putc)(' ', arg); + n++; + nprinted++; + } + } + + n = 0; + + while ((n < prec) && (!(length > 0 && n >= length))) { + if (*p == '\0') { + break; + } + if (putc) (*putc)(*p++, arg); + nprinted++; + n++; + } + + if (n < length && ladjust) { + while (n < length) { + if (putc) (*putc)(' ', arg); + n++; + nprinted++; + } + } + + break; + } + + case 'o': + truncate = _doprnt_truncates; + case 'O': + base = 8; + goto print_unsigned; + + case 'D': { + unsigned char *up; + char *q, *p; + + up = (unsigned char *)va_arg(argp, unsigned char *); + p = (char *)va_arg(argp, char *); + if (length == -1) + length = 16; + while(length--) { + if (putc) (*putc)(digs[(*up >> 4)], arg); + if (putc) (*putc)(digs[(*up & 0x0f)], arg); + nprinted += 2; + up++; + if (length) { + for (q=p;*q;q++) { + if (putc) (*putc)(*q, arg); + nprinted++; + } + } + } + break; + } + + case 'd': + truncate = _doprnt_truncates; + base = 10; + goto print_signed; + + case 'u': + truncate = _doprnt_truncates; + case 'U': + base = 10; + goto print_unsigned; + + case 'p': + altfmt = true; + if (sizeof(int)= 0) { + u = n; + sign_char = plus_sign; + } + else { + u = -n; + sign_char = '-'; + } + goto print_num; + + print_unsigned: + if (long_long) { + u = va_arg(argp, unsigned long long); + } else { + u = va_arg(argp, unsigned int); + } + goto print_num; + + print_num: + { + char buf[MAXBUF]; /* build number here */ + register char * p = &buf[MAXBUF-1]; + static char digits[] = "0123456789abcdef0123456789ABCDEF"; + const char *prefix = NULL; + + if (truncate) u = (long long)((int)(u)); + + if (u != 0 && altfmt) { + if (base == 8) + prefix = "0"; + else if (base == 16) + prefix = "0x"; + } + + do { + /* Print in the correct case */ + *p-- = digits[(u % base)+capitals]; + u /= base; + } while (u != 0); + + length -= (int)(&buf[MAXBUF-1] - p); + if (sign_char) + length--; + if (prefix) + length -= (int)strlen(prefix); + + if (padc == ' ' && !ladjust) { + /* blank padding goes before prefix */ + while (--length >= 0) { + if (putc) (*putc)(' ', arg); + nprinted++; + } + } + if (sign_char) { + if (putc) (*putc)(sign_char, arg); + nprinted++; + } + if (prefix) { + while (*prefix) { + if (putc) (*putc)(*prefix++, arg); + nprinted++; + } + } + if (padc == '0') { + /* zero padding goes after sign and prefix */ + while (--length >= 0) { + if (putc) (*putc)('0', arg); + nprinted++; + } + } + while (++p != &buf[MAXBUF]) { + (*putc)(*p, arg); + nprinted++; + } + + if (ladjust) { + while (--length >= 0) { + if (putc) (*putc)(' ', arg); + nprinted++; + } + } + break; + } + + case '\0': + fmt--; + break; + + default: + if (putc) (*putc)(c, arg); + nprinted++; + } + fmt++; + } + + return nprinted; +} +#endif + +int +prf( + const char *fmt, + va_list ap, + /* character output routine */ + void (*putc)(char)) +{ + return __doprnt(fmt, ap, dummy_putc, putc, 10); +} + + +static char *copybyte_str; + +static void +copybyte( + char byte) +{ + *copybyte_str++ = byte; + *copybyte_str = '\0'; +} + +int +sprintf(char *buf, const char *fmt, ...) +{ + va_list listp; + + va_start(listp, fmt); + copybyte_str = buf; + prf(fmt, listp, copybyte); + va_end(listp); + return strlen(buf); +} + +static void +snprintf_func(int ch, void *arg) +{ + struct snprintf_arg *const info = arg; + + if (info->remain >= 2) { + *info->str++ = ch; + info->remain--; + } +} + +/* + * Scaled down version of vsnprintf(3). + */ +int +vsnprintf(char *str, size_t size, const char *format, va_list ap) +{ + struct snprintf_arg info; + int retval; + + info.str = str; + info.remain = size; + retval = __doprnt(format, ap, snprintf_func, &info, 10); + if (info.remain >= 1) + *info.str++ = '\0'; + return retval; +} + +/* + * Scaled down version of snprintf(3). + */ +int +snprintf(char *str, size_t size, const char *format, ...) +{ + int retval; + va_list ap; + + va_start(ap, format); + retval = vsnprintf(str, size, format, ap); + va_end(ap); + return(retval); +} + +#if 1 +/* * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ @@ -21,54 +675,168 @@ * * @APPLE_LICENSE_HEADER_END@ */ +/* + * Mach Operating System + * Copyright (c) 1990 Carnegie-Mellon University + * Copyright (c) 1989 Carnegie-Mellon University + * Copyright (c) 1988 Carnegie-Mellon University + * Copyright (c) 1987 Carnegie-Mellon University + * All rights reserved. The CMU software License Agreement specifies + * the terms and conditions for use and redistribution. + */ /* - * Copyright 1993 NeXT, Inc. - * All rights reserved. + * Copyright (c) 1982, 1986 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + * + * @(#)prf.c 7.1 (Berkeley) 6/5/86 */ +#include -#include "libsa.h" +#define SPACE 1 +#define ZERO 2 +#define UCASE 16 -struct putc_info { - char * str; - char * last_str; -}; +/* + * Scaled down version of C Library printf. + * Used to print diagnostic information directly on console tty. + * Since it is not interrupt driven, all system activities are + * suspended. + * + */ -static void -sputc(int c, struct putc_info * pi); -static void -sputc(int c, struct putc_info * pi) +/* + * Printn prints a number n in base b. + * We don't use recursion to avoid deep kernel stacks. + */ +static int +printn(u_long n, int b, int flag, int minwidth, void (*putfn_p)(int ch, void *arg), void *putfn_arg) { - if (pi->last_str) - if (pi->str == pi->last_str) { - *(pi->str) = '\0'; - return; - } - *(pi->str)++ = c; + char prbuf[11]; + register char *cp; + int width = 0, neg = 0, len = 0; + + if (b == 10 && (int)n < 0) { + neg = 1; + n = (unsigned)(-(int)n); + } + cp = prbuf; + do { + *cp++ = "0123456789abcdef0123456789ABCDEF"[(flag & UCASE) + n%b]; + n /= b; + width++; + } while (n); + + if (neg) { + (*putfn_p)('-', putfn_arg); + width++; + len++; + } + while (width++ < minwidth) + { + (*putfn_p)( (flag & ZERO) ? '0' : ' ', putfn_arg); + len++; + } + + do + { + (*putfn_p)(*--cp, putfn_arg); + len++; + + } while (cp > prbuf); + + return len; } -/*VARARGS1*/ -/* now slprintf() return the length of the string as in man sprintf()*/ -int sprintf(char * str, const char * fmt, ...) +int __doprnt( + const char *fmt, + va_list argp, + void (*putfn_p)(int ch, void *arg), + void *putfn_arg, + int radix + ) { - va_list ap; - struct putc_info pi; - - va_start(ap, fmt); - pi.str = str; - pi.last_str = 0; - prf(fmt, ap, sputc, &pi); - *pi.str = '\0'; - va_end(ap); - return (pi.str - str); + int b, c, len =0; + char *s; + int flag = 0, width = 0; + int minwidth; + unsigned int *adx = (unsigned int*)argp; +loop: + while ((c = *fmt++) != '%') { + if(c == '\0') + return len; + if (putfn_p) { + (*putfn_p)(c, putfn_arg); + } + len++; + } + minwidth = 0; +again: + c = *fmt++; + switch (c) { + case 'l': + goto again; + case ' ': + flag |= SPACE; + goto again; + case '0': + if (minwidth == 0) { + /* this is a flag */ + flag |= ZERO; + goto again; + } /* fall through */ + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + minwidth *= 10; + minwidth += c - '0'; + goto again; + case 'X': + flag |= UCASE; + /* fall through */ + case 'x': + b = 16; + goto number; + case 'd': + b = 10; + goto number; + case 'o': case 'O': + b = 8; + number: + len += printn((u_long)*adx, b, flag, minwidth, putfn_p, putfn_arg); + break; + case 's': + s = (char *)*adx; + while ((c = *s++)) { + if (putfn_p) { + (*putfn_p)(c, putfn_arg); + } + len++; + width++; + } + while (width++ < minwidth) { + if (putfn_p) { + (*putfn_p)(' ', putfn_arg); + } + len++; + } + break; + case 'c': + if (putfn_p) { + (*putfn_p)((char)*adx, putfn_arg); + } + len++; + break; + default: + break; + } + adx++; + goto loop; } - -/*VARARGS1*/ -int slvprintf(char * str, int len, const char * fmt, va_list ap) -{ - struct putc_info pi; - pi.str = str; - pi.last_str = str + len - 1; - prf(fmt, ap, sputc, &pi); - *pi.str = '\0'; - return (pi.str - str); -} +#endif \ No newline at end of file Index: branches/cparm/i386/libsa/Makefile =================================================================== --- branches/cparm/i386/libsa/Makefile (revision 1983) +++ branches/cparm/i386/libsa/Makefile (revision 1984) @@ -10,8 +10,8 @@ OPTIM = -Os -Oz CFLAGS = $(RC_CFLAGS) $(OPTIM) $(MORECPP) -arch i386 -g -Wmost -Werror -fno-stack-protector \ -fno-builtin -static $(OMIT_FRAME_POINTER_CFLAG) \ - -march=pentium4 -msse2 -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE -mpreferred-stack-boundary=2 -fno-align-functions -mfpmath=sse - + -march=pentium4 -msse2 -msoft-float -Qunused-arguments -ffreestanding -DBOOT_CORE -mpreferred-stack-boundary=2 -fno-align-functions -mfpmath=sse +GFLAGS = INC = -I. -I$(SYMROOT) -I$(UTILDIR) -I$(LIBSAIODIR) ifneq "" "$(wildcard /bin/mkdirs)" MKDIRS = /bin/mkdirs @@ -25,7 +25,7 @@ VPATH = $(OBJROOT):$(SYMROOT) -SA_OBJS = qdivrem.o umoddi3.o udivdi3.o divdi3.o moddi3.o bzero.o bcopy.o prf.o printf.o zalloc.o\ +SA_OBJS = qdivrem.o umoddi3.o udivdi3.o divdi3.o moddi3.o bzero.o bcopy.o printf.o zalloc.o\ string.o strtol.o \ setjmp.o qsort.o efi_tables.o Index: branches/cparm/xcode3_sym.zip =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream