All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heinrich Schuchardt <xypron.glpk@gmx.de>
To: u-boot@lists.denx.de
Subject: [PATCH 3/4] efi_selftest: enable printing hexadecimal numbers
Date: Sat,  3 Oct 2020 13:57:15 +0200	[thread overview]
Message-ID: <20201003115716.38058-4-xypron.glpk@gmx.de> (raw)
In-Reply-To: <20201003115716.38058-1-xypron.glpk@gmx.de>

Add code to use %x in efi_st_print().

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 lib/efi_selftest/efi_selftest_console.c | 35 ++++++++++++++++---------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/lib/efi_selftest/efi_selftest_console.c b/lib/efi_selftest/efi_selftest_console.c
index 13f3ee6bc1..e3f4e39348 100644
--- a/lib/efi_selftest/efi_selftest_console.c
+++ b/lib/efi_selftest/efi_selftest_console.c
@@ -44,25 +44,28 @@ static void mac(void *pointer, u16 **buf)
 }

 /*
- * Print a pointer to an u16 string
+ * printx() - print hexadecimal number to an u16 string
  *
- * @pointer: pointer
- * @buf: pointer to buffer address
- * on return position of terminating zero word
+ * @pointer:	pointer
+ * @prec:	minimum number of digits to print
+ * @buf:	pointer to buffer address,
+ *		on return position of terminating zero word
+ * @size:	size of value to be printed in bytes
  */
-static void pointer(void *pointer, u16 **buf)
+static void printx(u64 p, int prec, u16 **buf)
 {
 	int i;
 	u16 c;
-	uintptr_t p = (uintptr_t)pointer;
 	u16 *pos = *buf;

-	for (i = 8 * sizeof(p) - 4; i >= 0; i -= 4) {
-		c = (p >> i) & 0x0f;
-		c += '0';
-		if (c > '9')
-			c += 'a' - '9' - 1;
-		*pos++ = c;
+	for (i = 2 * sizeof(p) - 1; i >= 0; --i) {
+		c = (p >> (4 * i)) & 0x0f;
+		if (c || pos != *buf || !i || i < prec) {
+			c += '0';
+			if (c > '9')
+				c += 'a' - '9' - 1;
+			*pos++ = c;
+		}
 	}
 	*pos = 0;
 	*buf = pos;
@@ -212,7 +215,9 @@ void efi_st_printc(int color, const char *fmt, ...)
 					break;
 				default:
 					--c;
-					pointer(va_arg(args, void*), &pos);
+					printx((u64)va_arg(args, void *),
+					       2 * sizeof(void *), &pos);
+					break;
 				}
 				break;
 			case 's':
@@ -223,6 +228,10 @@ void efi_st_printc(int color, const char *fmt, ...)
 			case 'u':
 				uint2dec(va_arg(args, u32), prec, &pos);
 				break;
+			case 'x':
+				printx((u64)va_arg(args, unsigned int),
+				       prec, &pos);
+				break;
 			default:
 				break;
 			}
--
2.28.0

  parent reply	other threads:[~2020-10-03 11:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-03 11:57 [PATCH 0/4] efi_loader: fix EFI_LOAD_FILE2_PROTOCOL Heinrich Schuchardt
2020-10-03 11:57 ` [PATCH 1/4] efi_loader: description EFI_LOAD_FILE2_PROTOCOL Heinrich Schuchardt
2020-10-04  5:14   ` Ilias Apalodimas
2020-10-03 11:57 ` [PATCH 2/4] efi_loader: illegal free in EFI_LOAD_FILE2_PROTOCOL Heinrich Schuchardt
2020-10-04  5:16   ` Ilias Apalodimas
2020-10-03 11:57 ` Heinrich Schuchardt [this message]
2020-10-03 11:57 ` [PATCH 4/4] efi_selftest: print CRC32 of initrd as hexadecimal Heinrich Schuchardt
2020-10-04  5:16   ` Ilias Apalodimas

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=20201003115716.38058-4-xypron.glpk@gmx.de \
    --to=xypron.glpk@gmx.de \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.