output: Add 64bit hex print support.

Based on patch by Gerd Hoffmann <kraxel@redhat.com>.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
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 @@
     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..37c4942 100644
--- a/src/output.c
+++ b/src/output.c
@@ -194,28 +194,10 @@
     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)
+puthex(struct putcinfo *action, u32 val, int width)
 {
-    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, ' ');
-        }
-    }
-
     switch (width) {
     default: putsinglehex(action, (val >> 28) & 0xf);
     case 7:  putsinglehex(action, (val >> 24) & 0xf);
@@ -228,6 +210,20 @@
     }
 }
 
+// Output an integer in hexadecimal with a minimum width.
+static void
+putprettyhex(struct putcinfo *action, u32 val, int width, char padchar)
+{
+    u32 tmp = val;
+    int count = 1;
+    while (tmp >>= 4)
+        count++;
+    width -= count;
+    while (width-- > 0)
+        putc(action, padchar);
+    puthex(action, val, count);
+}
+
 static inline int
 isdigit(u8 c)
 {
@@ -248,13 +244,14 @@
         }
         const char *n = s+1;
         int field_width = 0;
-        int spacepad = 1;
+        char padchar = ' ';
+        u8 is64 = 0;
         for (;;) {
             c = GET_GLOBAL(*(u8*)n);
             if (!isdigit(c))
                 break;
             if (!field_width && (c == '0'))
-                spacepad = 0;
+                padchar = '0';
             else
                 field_width = field_width * 10 + c - '0';
             n++;
@@ -264,6 +261,11 @@
             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 @@
             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 @@
             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, padchar);
+                    puthex(action, val, 8);
+                    break;
+                }
+            }
+            putprettyhex(action, val, field_width, padchar);
             break;
         case 'c':
             val = va_arg(args, int);
@@ -342,7 +356,7 @@
         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 @@
     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 @@
         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