diff --git a/arch/x86/console.c b/arch/x86/console.c index 81c7710d3b..4654b1a10d 100644 --- a/arch/x86/console.c +++ b/arch/x86/console.c @@ -6,14 +6,14 @@ // FIXME: we need this for varargs #include -extern int vtxprintf(void (*)(unsigned char), const char *, va_list); +extern int vtxprintf(void (*)(unsigned char, void *arg), void *arg, const char *, va_list); int console_loglevel(void) { return CONFIG_DEFAULT_CONSOLE_LOGLEVEL; } -void console_tx_byte(unsigned char byte) +void console_tx_byte(unsigned char byte, void *ignored) { if (byte == '\n') uart8250_tx_byte(TTYSx_BASE, '\r'); @@ -30,7 +30,7 @@ int printk(int msg_level, const char *fmt, ...) } va_start(args, fmt); - i = vtxprintf(console_tx_byte, fmt, args); + i = vtxprintf(console_tx_byte, (void *)0, fmt, args); va_end(args); return i; diff --git a/console/vsprintf.c b/console/vsprintf.c index f0d3c8a23a..b87fdd8367 100644 --- a/console/vsprintf.c +++ b/console/vsprintf.c @@ -26,35 +26,33 @@ #include #include +#include -int vtxprintf(void (*tx_byte) (unsigned char byte), const char *fmt, +int vtxprintf(void (*tx_byte) (unsigned char byte, void *arg), void *arg, const char *fmt, va_list args); -/* FIXME this global makes vsprintf non-reentrant */ - -static char *str_buf; -static void str_tx_byte(unsigned char byte) +/* the arg is the char ** for the buffer */ +static void str_tx_byte(unsigned char byte, void *arg) { - *str_buf = byte; - str_buf++; -} - -int vsprintf(char *buf, const char *fmt, va_list args) -{ - int i; - str_buf = buf; - i = vtxprintf(str_tx_byte, fmt, args); - *str_buf = '\0'; - return i; + unsigned char *cp = *(unsigned char **) arg; + + *cp = byte; + cp++; + /* paranoia, make sure it will be null terminated. The cost for this is small, + * the benefit large. + */ + *cp = 0; + *(unsigned char **) arg = cp; } int sprintf(char *buf, const char *fmt, ...) { va_list args; int i; - + unsigned char *cp = (unsigned char *)buf; + unsigned char **cpp = &cp; va_start(args, fmt); - i = vsprintf(buf, fmt, args); + i = vtxprintf(str_tx_byte, cpp, fmt, args); va_end(args); return i; } diff --git a/console/vtxprintf.c b/console/vtxprintf.c index 3d31da507f..498db072a7 100644 --- a/console/vtxprintf.c +++ b/console/vtxprintf.c @@ -44,7 +44,7 @@ static int skip_atoi(const char **s) #define SPECIAL 32 /* 0x */ #define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ -static int number(void (*tx_byte)(unsigned char byte), +static int number(void (*tx_byte)(unsigned char byte, void *arg), void *arg, unsigned long long num, int base, int size, int precision, int type) { char c,sign,tmp[66]; @@ -89,31 +89,31 @@ static int number(void (*tx_byte)(unsigned char byte), size -= precision; if (!(type&(ZEROPAD+LEFT))) while(size-->0) - tx_byte(' '), count++; + tx_byte(' ', arg), count++; if (sign) - tx_byte(sign), count++; + tx_byte(sign, arg), count++; if (type & SPECIAL) { if (base==8) - tx_byte('0'), count++; + tx_byte('0', arg), count++; else if (base==16) { - tx_byte('0'), count++; - tx_byte(digits[33]), count++; + tx_byte('0', arg), count++; + tx_byte(digits[33], arg), count++; } } if (!(type & LEFT)) while (size-- > 0) - tx_byte(c), count++; + tx_byte(c, arg), count++; while (i < precision--) - tx_byte('0'), count++; + tx_byte('0', arg), count++; while (i-- > 0) - tx_byte(tmp[i]), count++; + tx_byte(tmp[i], arg), count++; while (size-- > 0) - tx_byte(' '), count++; + tx_byte(' ', arg), count++; return count; } -int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args) +int vtxprintf(void (*tx_byte)(unsigned char byte, void *arg), void *arg, const char *fmt, va_list args) { int len; unsigned long long num; @@ -131,7 +131,7 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args for (count=0; *fmt ; ++fmt) { if (*fmt != '%') { - tx_byte(*fmt), count++; + tx_byte(*fmt, arg), count++; continue; } @@ -194,10 +194,10 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args case 'c': if (!(flags & LEFT)) while (--field_width > 0) - tx_byte(' '), count++; - tx_byte((unsigned char) va_arg(args, int)), count++; + tx_byte(' ', arg), count++; + tx_byte((unsigned char) va_arg(args, int), arg), count++; while (--field_width > 0) - tx_byte(' '), count++; + tx_byte(' ', arg), count++; continue; case 's': @@ -209,11 +209,11 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args if (!(flags & LEFT)) while (len < field_width--) - tx_byte(' '), count++; + tx_byte(' ', arg), count++; for (i = 0; i < len; ++i) - tx_byte(*s++), count++; + tx_byte(*s++, arg), count++; while (len < field_width--) - tx_byte(' '), count++; + tx_byte(' ', arg), count++; continue; case 'p': @@ -221,7 +221,7 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args field_width = 2*sizeof(void *); flags |= ZEROPAD; } - count += number(tx_byte, + count += number(tx_byte, arg, (unsigned long) va_arg(args, void *), 16, field_width, precision, flags); continue; @@ -241,7 +241,7 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args continue; case '%': - tx_byte('%'), count++; + tx_byte('%', arg), count++; continue; /* integer number formats - set up the flags and "break" */ @@ -262,9 +262,9 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args break; default: - tx_byte('%'), count++; + tx_byte('%', arg), count++; if (*fmt) - tx_byte(*fmt), count++; + tx_byte(*fmt, arg), count++; else --fmt; continue; @@ -282,7 +282,7 @@ int vtxprintf(void (*tx_byte)(unsigned char byte), const char *fmt, va_list args } else { num = va_arg(args, unsigned int); } - count += number(tx_byte, num, base, field_width, precision, flags); + count += number(tx_byte, arg, num, base, field_width, precision, flags); } return count; } diff --git a/device/device.c b/device/device.c index 46fd965822..b0ebf35326 100644 --- a/device/device.c +++ b/device/device.c @@ -90,8 +90,6 @@ struct device * alloc_dev(struct bus *parent, struct device_path *path) { struct device * dev, *child; int link; - static char thissucks[64]; - static int fuck = 0; // spin_lock(&dev_lock); @@ -135,15 +133,7 @@ struct device * alloc_dev(struct bus *parent, struct device_path *path) if (dev->dtsname == 0) { die("DEV: out of memory.\n"); } - sprintf(thissucks, "dynamic %s", dev_path(dev)); - printk(BIOS_INFO, "thissucks is %s dev is %p dev->dtsname is %p\n", thissucks, dev, dev->dtsname); sprintf(dev->dtsname, "dynamic %s", dev_path(dev)); - printk(BIOS_INFO, "after sprintf dtsname is %s\n", dev->dtsname); - memcpy(dev->dtsname, thissucks, strlen(thissucks)); - printk(BIOS_INFO, "after strcpy dtsname is %s\n", dev->dtsname); - /* FUCK. sprintf doesn't work. */ - dev->dtsname[0] = '0' + fuck++; - dev->dtsname[1] = 0; // spin_unlock(&dev_lock); return dev; diff --git a/device/device_util.c b/device/device_util.c index 174cd9101f..6a625b72da 100644 --- a/device/device_util.c +++ b/device/device_util.c @@ -505,7 +505,7 @@ void search_global_resources( resource_search_t search, void *gp) { struct device *curdev; - printk(BIOS_SPEW-2, "%s: mask %x type %x \n", __func__, type_mask, type); + printk(BIOS_SPEW, "%s: mask %x type %x \n", __func__, type_mask, type); for(curdev = all_devices; curdev; curdev = curdev->next) { int i; printk(BIOS_SPEW, "%s: dev %s, have_resources %d #resources %d\n", __func__, curdev->dtsname, diff --git a/device/pci_device.c b/device/pci_device.c index 469009fa60..094db6343f 100644 --- a/device/pci_device.c +++ b/device/pci_device.c @@ -129,7 +129,7 @@ unsigned pci_find_next_capability(struct device * dev, unsigned cap, unsigned la int this_cap; pos &= ~3; this_cap = pci_read_config8(dev, pos + PCI_CAP_LIST_ID); - printk(BIOS_SPEW-2,"Capability: 0x%02x @ 0x%02x\n", cap, pos); + printk(BIOS_SPEW,"Capability: 0x%02x @ 0x%02x\n", cap, pos); if (this_cap == 0xff) { break; } @@ -797,7 +797,7 @@ static void set_pci_ops(struct device *dev) (driver->device == dev->device)) { dev->ops = driver->ops; - printk(BIOS_SPEW-2,"%s [%04x/%04x] %sops\n", + printk(BIOS_SPEW,"%s [%04x/%04x] %sops\n", dev_path(dev), driver->vendor, driver->device, (driver->ops->phase3_scan?"bus ":"")); @@ -855,15 +855,15 @@ static struct device *pci_scan_get_dev(struct device **list, unsigned int devfn) { struct device *dev; dev = 0; - printk(BIOS_INFO, "%s: list is %p, *list is %p\n", __func__, list, *list); + printk(BIOS_SPEW, "%s: list is %p, *list is %p\n", __func__, list, *list); for(; *list; list = &(*list)->sibling) { - printk(BIOS_INFO, "%s: check dev %s \n", __func__, (*list)->dtsname); + printk(BIOS_SPEW, "%s: check dev %s \n", __func__, (*list)->dtsname); if ((*list)->path.type != DEVICE_PATH_PCI) { printk(BIOS_ERR,"%s: child %s(%s) not a pci device: it's type %d\n", __FUNCTION__, (*list)->dtsname, dev_path(*list), (*list)->path.type); continue; } - printk(BIOS_INFO, "%s: check dev %s it has devfn 0x%x\n", __func__, (*list)->dtsname, (*list)->path.u.pci.devfn); + printk(BIOS_SPEW, "%s: check dev %s it has devfn 0x%x\n", __func__, (*list)->dtsname, (*list)->path.u.pci.devfn); if ((*list)->path.u.pci.devfn == devfn) { /* Unlink from the list */ dev = *list; @@ -923,7 +923,7 @@ struct device * pci_probe_dev(struct device * dev, struct bus *bus, unsigned dev if ( (id == 0xffffffff) || (id == 0x00000000) || (id == 0x0000ffff) || (id == 0xffff0000)) { - printk(BIOS_SPEW-2,"PCI: devfn 0x%x, bad id 0x%x\n", devfn, id); + printk(BIOS_SPEW,"PCI: devfn 0x%x, bad id 0x%x\n", devfn, id); return NULL; } dev = alloc_dev(bus, &dummy.path); @@ -1046,23 +1046,23 @@ unsigned int pci_scan_bus(struct bus *bus, bus->children = 0; post_code(0x24); - printk(BIOS_SPEW-2,"PCI: scan devfn 0x%x to 0x%x\n", min_devfn, max_devfn); + printk(BIOS_SPEW,"PCI: scan devfn 0x%x to 0x%x\n", min_devfn, max_devfn); /* probe all devices/functions on this bus with some optimization for * non-existence and single funcion devices */ for (devfn = min_devfn; devfn <= max_devfn; devfn++) { struct device * dev; - printk(BIOS_SPEW-2,"PCI: devfn 0x%x\n", devfn); + printk(BIOS_SPEW,"PCI: devfn 0x%x\n", devfn); /* First thing setup the device structure */ dev = pci_scan_get_dev(&old_devices, devfn); - printk(BIOS_SPEW-2,"PCI: pci_scan_bus pci_scan_get_dev returns dev %s\n", dev ? dev->dtsname :"None (no dev in tree yet)"); + printk(BIOS_SPEW,"PCI: pci_scan_bus pci_scan_get_dev returns dev %s\n", dev ? dev->dtsname :"None (no dev in tree yet)"); /* See if a device is present and setup the device * structure. */ dev = pci_probe_dev(dev, bus, devfn); - printk(BIOS_SPEW-2,"PCI: pci_scan_bus pci_probe_dev returns dev %p(%s)\n", dev, dev->dtsname); + printk(BIOS_SPEW,"PCI: pci_scan_bus pci_probe_dev returns dev %p(%s)\n", dev, dev->dtsname); /* if this is not a multi function device, * or the device is not present don't waste @@ -1075,7 +1075,7 @@ unsigned int pci_scan_bus(struct bus *bus, devfn += 0x07; } } - printk(BIOS_SPEW-2,"PCI: Done for loop\n"); + printk(BIOS_SPEW,"PCI: Done for loop\n"); post_code(0x25); /* Die if any leftover Static devices are are found. @@ -1130,7 +1130,7 @@ unsigned int do_pci_scan_bridge(struct device *dev, unsigned int max, u32 buses; u16 cr; - printk(BIOS_SPEW-2,"%s for %s\n", __func__, dev_path(dev)); + printk(BIOS_SPEW,"%s for %s\n", __func__, dev_path(dev)); bus = &dev->link[0]; bus->dev = dev; @@ -1179,7 +1179,7 @@ unsigned int do_pci_scan_bridge(struct device *dev, unsigned int max, pci_write_config16(dev, PCI_COMMAND, cr); printk(BIOS_DEBUG, "%s DONE\n", __func__); - printk(BIOS_SPEW-2,"%s returns max %d\n", __func__, max); + printk(BIOS_SPEW,"%s returns max %d\n", __func__, max); return max; } @@ -1209,10 +1209,10 @@ void pci_level_irq(unsigned char intNum) { unsigned short intBits = inb(0x4d0) | (((unsigned) inb(0x4d1)) << 8); - printk(BIOS_SPEW-2,"%s: current ints are 0x%x\n", __func__, intBits); + printk(BIOS_SPEW,"%s: current ints are 0x%x\n", __func__, intBits); intBits |= (1 << intNum); - printk(BIOS_SPEW-2,"%s: try to set ints 0x%x\n", __func__, intBits); + printk(BIOS_SPEW,"%s: try to set ints 0x%x\n", __func__, intBits); // Write new values outb((unsigned char) intBits, 0x4d0);