From: Kevin O'Connor <kevin@koconnor.net>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: seabios@seabios.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [SeaBIOS] [PATCH v2 1/6] output: add 64bit hex print support
Date: Mon, 5 Mar 2012 10:23:29 -0500 [thread overview]
Message-ID: <20120305152328.GC9697@morn.localdomain> (raw)
In-Reply-To: <1330515910-725-2-git-send-email-kraxel@redhat.com>
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 <kevin@koconnor.net>
Date: Mon, 5 Mar 2012 10:14:07 -0500
Subject: [PATCH] output: Add 64bit hex print support.
To: seabios@seabios.org
Based on patch by Gerd Hoffmann <kraxel@redhat.com>.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
---
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
next prev parent reply other threads:[~2012-03-05 15:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-29 11:45 [Qemu-devel] [PATCH v2 0/6] pci: 64bit support Gerd Hoffmann
2012-02-29 11:45 ` [Qemu-devel] [PATCH v2 1/6] output: add 64bit hex print support Gerd Hoffmann
2012-03-05 15:23 ` Kevin O'Connor [this message]
2012-03-06 7:03 ` [Qemu-devel] [SeaBIOS] " Gerd Hoffmann
2012-02-29 11:45 ` [Qemu-devel] [PATCH v2 2/6] pci: split device discovery into multiple steps Gerd Hoffmann
2012-02-29 11:45 ` [Qemu-devel] [PATCH v2 3/6] pci: 64bit support Gerd Hoffmann
2012-02-29 11:45 ` [Qemu-devel] [PATCH v2 4/6] pci: bridges can have two regions too Gerd Hoffmann
2012-02-29 11:45 ` [Qemu-devel] [PATCH v2 5/6] pci: fix bridge ressource allocation Gerd Hoffmann
2012-02-29 11:45 ` [Qemu-devel] [PATCH v2 6/6] pci: add prefmem64 Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120305152328.GC9697@morn.localdomain \
--to=kevin@koconnor.net \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=seabios@seabios.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).