* Debug output
****************************************************************/
-#define DEBUG_PORT PORT_SERIAL1
#define DEBUG_TIMEOUT 100000
void
return;
// setup for serial logging: 8N1
u8 oldparam, newparam = 0x03;
- oldparam = inb(DEBUG_PORT+SEROFF_LCR);
- outb(newparam, DEBUG_PORT+SEROFF_LCR);
+ oldparam = inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LCR);
+ outb(newparam, CONFIG_DEBUG_SERIAL_PORT+SEROFF_LCR);
// Disable irqs
u8 oldier, newier = 0;
- oldier = inb(DEBUG_PORT+SEROFF_IER);
- outb(newier, DEBUG_PORT+SEROFF_IER);
+ oldier = inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_IER);
+ outb(newier, CONFIG_DEBUG_SERIAL_PORT+SEROFF_IER);
if (oldparam != newparam || oldier != newier)
dprintf(1, "Changing serial settings was %x/%x now %x/%x\n"
if (!CONFIG_DEBUG_SERIAL)
return;
int timeout = DEBUG_TIMEOUT;
- while ((inb(DEBUG_PORT+SEROFF_LSR) & 0x60) != 0x60)
+ while ((inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LSR) & 0x20) != 0x20)
if (!timeout--)
// Ran out of time.
return;
- outb(c, DEBUG_PORT+SEROFF_DATA);
+ outb(c, CONFIG_DEBUG_SERIAL_PORT+SEROFF_DATA);
}
// Make sure all serial port writes have been completely sent.
if (!CONFIG_DEBUG_SERIAL)
return;
int timeout = DEBUG_TIMEOUT;
- while ((inb(DEBUG_PORT+SEROFF_LSR) & 0x40) != 0x40)
+ while ((inb(CONFIG_DEBUG_SERIAL_PORT+SEROFF_LSR) & 0x60) != 0x60)
if (!timeout--)
// Ran out of time.
return;
static void
putc_screen(struct putcinfo *action, char c)
{
- if (CONFIG_SCREEN_AND_DEBUG)
+ if (ScreenAndDebug)
putc_debug(&debuginfo, c);
if (c == '\n')
screenc('\r');
static void
puts(struct putcinfo *action, const char *s)
{
+ if (!MODESEGMENT && !s)
+ s = "(NULL)";
for (; *s; s++)
putc(action, *s);
}
// Output an integer in hexadecimal.
static void
-puthex(struct putcinfo *action, u32 val, int width)
+puthex(struct putcinfo *action, u32 val, int width, int spacepad)
{
if (!width) {
u32 tmp = val;
width = 1;
- if (tmp > 0xffff) {
- width += 4;
- tmp >>= 16;
- }
- if (tmp > 0xff) {
- width += 2;
- tmp >>= 8;
+ while (tmp >>= 4)
+ width++;
+ } else if (spacepad) {
+ u32 tmp = val;
+ u32 count = 1;
+ while (tmp >>= 4)
+ count++;
+ if (width > count) {
+ count = width - count;
+ width -= count;
+ while (count--)
+ putc(action, ' ');
}
- if (tmp > 0xf)
- width += 1;
}
switch (width) {
}
const char *n = s+1;
int field_width = 0;
+ int spacepad = 1;
for (;;) {
c = GET_GLOBAL(*(u8*)n);
if (!isdigit(c))
break;
- field_width = field_width * 10 + c - '0';
+ if (!field_width && (c == '0'))
+ spacepad = 0;
+ else
+ field_width = field_width * 10 + c - '0';
n++;
}
if (c == 'l') {
putc(action, '0');
putc(action, 'x');
field_width = 8;
+ spacepad = 0;
case 'x':
val = va_arg(args, s32);
- puthex(action, val, field_width);
+ puthex(action, val, field_width, spacepad);
break;
case 'c':
val = va_arg(args, int);
if (cur != &MainThread) {
// Show "thread id" for this debug message.
putc_debug(&debuginfo, '|');
- puthex(&debuginfo, (u32)cur, 8);
+ puthex(&debuginfo, (u32)cur, 8, 0);
putc_debug(&debuginfo, '|');
putc_debug(&debuginfo, ' ');
}
va_start(args, fmt);
bvprintf(&screeninfo, fmt, args);
va_end(args);
- if (CONFIG_SCREEN_AND_DEBUG)
+ if (ScreenAndDebug)
debug_serial_flush();
}
return end - str;
}
+// Build a formatted string - malloc'ing the memory.
+char *
+znprintf(size_t size, const char *fmt, ...)
+{
+ ASSERT32FLAT();
+ if (!size)
+ return NULL;
+ char *str = malloc_tmp(size);
+ if (!str) {
+ warn_noalloc();
+ return NULL;
+ }
+ struct snprintfinfo sinfo = { { putc_str }, str, str + size };
+ va_list args;
+ va_start(args, fmt);
+ bvprintf(&sinfo.info, fmt, args);
+ va_end(args);
+ char *end = sinfo.str;
+ if (end >= sinfo.end)
+ end = sinfo.end - 1;
+ *end = '\0';
+ return str;
+}
+
/****************************************************************
* Misc helpers
while (len > 0) {
if (count % 8 == 0) {
putc(&debuginfo, '\n');
- puthex(&debuginfo, count*4, 8);
+ puthex(&debuginfo, count*4, 8, 0);
putc(&debuginfo, ':');
} else {
putc(&debuginfo, ' ');
}
- puthex(&debuginfo, *(u32*)d, 8);
+ puthex(&debuginfo, *(u32*)d, 8, 0);
count++;
len-=4;
d+=4;