[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [SeaBIOS] [PATCH v2 1/6] output: add 64bit hex print su
From: |
Kevin O'Connor |
Subject: |
Re: [Qemu-devel] [SeaBIOS] [PATCH v2 1/6] output: add 64bit hex print support |
Date: |
Mon, 5 Mar 2012 10:23:29 -0500 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Wed, Feb 29, 2012 at 12:45:05PM +0100, Gerd Hoffmann wrote:
> ---
> src/output.c | 23 +++++++++++++++++++++--
> 1 files changed, 21 insertions(+), 2 deletions(-)
Thanks Gerd.
I think your patch missed a couple of corner cases. I played with it
a bit and came up with the below.
-Kevin
>From ab16772e7f51e5d9c8e0c44695a76320439d2c78 Mon Sep 17 00:00:00 2001
From: Kevin O'Connor <address@hidden>
Date: Mon, 5 Mar 2012 10:14:07 -0500
Subject: [PATCH] output: Add 64bit hex print support.
To: address@hidden
Based on patch by Gerd Hoffmann <address@hidden>.
Signed-off-by: Kevin O'Connor <address@hidden>
---
src/memmap.c | 6 +---
src/output.c | 68 +++++++++++++++++++++++++++++++++++-----------------------
src/post.c | 3 +-
3 files changed, 44 insertions(+), 33 deletions(-)
diff --git a/src/memmap.c b/src/memmap.c
index 20ccae0..bcec34e 100644
--- a/src/memmap.c
+++ b/src/memmap.c
@@ -63,10 +63,8 @@ dump_map(void)
for (i=0; i<e820_count; i++) {
struct e820entry *e = &e820_list[i];
u64 e_end = e->start + e->size;
- dprintf(1, " %d: %08x%08x - %08x%08x = %d %s\n", i
- , (u32)(e->start >> 32), (u32)e->start
- , (u32)(e_end >> 32), (u32)e_end
- , e->type, e820_type_name(e->type));
+ dprintf(1, " %d: %016llx - %016llx = %d %s\n", i
+ , e->start, e_end, e->type, e820_type_name(e->type));
}
}
diff --git a/src/output.c b/src/output.c
index bdde7cc..73d80e9 100644
--- a/src/output.c
+++ b/src/output.c
@@ -194,28 +194,10 @@ putsinglehex(struct putcinfo *action, u32 val)
putc(action, val);
}
-// Output an integer in hexadecimal.
+// Output an integer in hexadecimal with a specified width.
static void
-puthex(struct putcinfo *action, u32 val, int width, int spacepad)
-{
- if (!width) {
- u32 tmp = val;
- width = 1;
- 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, ' ');
- }
- }
-
+puthex(struct putcinfo *action, u32 val, int width)
+{
switch (width) {
default: putsinglehex(action, (val >> 28) & 0xf);
case 7: putsinglehex(action, (val >> 24) & 0xf);
@@ -228,6 +210,20 @@ puthex(struct putcinfo *action, u32 val, int width, int
spacepad)
}
}
+// Output an integer in hexadecimal with a minimum width.
+static void
+putprettyhex(struct putcinfo *action, u32 val, int width, int spacepad)
+{
+ u32 tmp = val;
+ int count = 1;
+ while (tmp >>= 4)
+ count++;
+ width -= count;
+ while (width-- > 0)
+ putc(action, spacepad ? ' ' : '0');
+ puthex(action, val, count);
+}
+
static inline int
isdigit(u8 c)
{
@@ -249,6 +245,7 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list
args)
const char *n = s+1;
int field_width = 0;
int spacepad = 1;
+ int is64 = 0;
for (;;) {
c = GET_GLOBAL(*(u8*)n);
if (!isdigit(c))
@@ -264,6 +261,11 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list
args)
n++;
c = GET_GLOBAL(*(u8*)n);
}
+ if (c == 'l') {
+ is64 = 1;
+ n++;
+ c = GET_GLOBAL(*(u8*)n);
+ }
s32 val;
const char *sarg;
switch (c) {
@@ -272,6 +274,8 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list
args)
break;
case 'd':
val = va_arg(args, s32);
+ if (is64)
+ va_arg(args, s32);
if (val < 0) {
putc(action, '-');
val = -val;
@@ -280,17 +284,27 @@ bvprintf(struct putcinfo *action, const char *fmt,
va_list args)
break;
case 'u':
val = va_arg(args, s32);
+ if (is64)
+ va_arg(args, s32);
putuint(action, val);
break;
case 'p':
- /* %p always has 0x prepended */
+ val = va_arg(args, s32);
putc(action, '0');
putc(action, 'x');
- field_width = 8;
- spacepad = 0;
+ puthex(action, val, 8);
+ break;
case 'x':
val = va_arg(args, s32);
- puthex(action, val, field_width, spacepad);
+ if (is64) {
+ u32 upper = va_arg(args, s32);
+ if (upper) {
+ putprettyhex(action, upper, field_width - 8, spacepad);
+ puthex(action, val, 8);
+ break;
+ }
+ }
+ putprettyhex(action, val, field_width, spacepad);
break;
case 'c':
val = va_arg(args, int);
@@ -342,7 +356,7 @@ __dprintf(const char *fmt, ...)
if (cur != &MainThread) {
// Show "thread id" for this debug message.
putc_debug(&debuginfo, '|');
- puthex(&debuginfo, (u32)cur, 8, 0);
+ puthex(&debuginfo, (u32)cur, 8);
putc_debug(&debuginfo, '|');
putc_debug(&debuginfo, ' ');
}
@@ -444,12 +458,12 @@ hexdump(const void *d, int len)
while (len > 0) {
if (count % 8 == 0) {
putc(&debuginfo, '\n');
- puthex(&debuginfo, count*4, 8, 0);
+ puthex(&debuginfo, count*4, 8);
putc(&debuginfo, ':');
} else {
putc(&debuginfo, ' ');
}
- puthex(&debuginfo, *(u32*)d, 8, 0);
+ puthex(&debuginfo, *(u32*)d, 8);
count++;
len-=4;
d+=4;
diff --git a/src/post.c b/src/post.c
index b4ad1fa..bd0b530 100644
--- a/src/post.c
+++ b/src/post.c
@@ -150,8 +150,7 @@ ram_probe(void)
add_e820(0xfffbc000, 4*4096, E820_RESERVED);
}
- dprintf(1, "Ram Size=0x%08x (0x%08x%08x high)\n"
- , RamSize, (u32)(RamSizeOver4G >> 32), (u32)RamSizeOver4G);
+ dprintf(1, "Ram Size=0x%08x (0x%016llx high)\n", RamSize, RamSizeOver4G);
}
static void
--
1.7.6.5
- Re: [Qemu-devel] [SeaBIOS] [PATCH v2 1/6] output: add 64bit hex print support,
Kevin O'Connor <=