From e1ceb5a07c3b3222efbcf1112667533ec3a7839a Mon Sep 17 00:00:00 2001 From: Guangtao Zhu Date: Wed, 29 Jul 2026 19:31:03 +1000 Subject: [PATCH 1/2] libmicrokit: add 'microkit_dbg_put64' This commit adds microkit_dbg_put64 that helps to print out large number (e.g., vaddrs) Signed-off-by: Guangtao Zhu --- libmicrokit/include/microkit.h | 5 +++++ libmicrokit/src/dbg.c | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/libmicrokit/include/microkit.h b/libmicrokit/include/microkit.h index b31391aeb..b8eede30e 100644 --- a/libmicrokit/include/microkit.h +++ b/libmicrokit/include/microkit.h @@ -91,6 +91,11 @@ void microkit_dbg_put8(seL4_Uint8 x); */ void microkit_dbg_put32(seL4_Uint32 x); +/* + * Output the decimal representation of an 64-bit integer to the debug console. + */ +void microkit_dbg_put64(seL4_Uint64 x); + static inline void microkit_internal_crash(seL4_Error err) { /* diff --git a/libmicrokit/src/dbg.c b/libmicrokit/src/dbg.c index 94c987974..e7c5e8499 100644 --- a/libmicrokit/src/dbg.c +++ b/libmicrokit/src/dbg.c @@ -52,6 +52,19 @@ void microkit_dbg_put32(seL4_Uint32 x) microkit_dbg_puts(&tmp[i]); } +void microkit_dbg_put64(seL4_Uint64 x) +{ + char tmp[21]; + unsigned i = 20; + tmp[20] = 0; + do { + seL4_Uint8 c = x % 10; + tmp[--i] = '0' + c; + x /= 10; + } while (x); + microkit_dbg_puts(&tmp[i]); +} + /* * We have to provide an implementation for libsel4 debug asserts, make it * weak so users can override with their own libc etc. From 384704939b91dd816d4c373a09a9022937cd55b7 Mon Sep 17 00:00:00 2001 From: Guangtao Zhu Date: Thu, 30 Jul 2026 00:53:33 +1000 Subject: [PATCH 2/2] libmicrokit: add 'microkit_dbg_puthex32/64' This commit copies the reference implementation of 'puthex32' and 'puthex64' from the source code of microkit monitor. Such two new APIs avoid duplicating the implementations everywhere in the repo. Signed-off-by: Guangtao Zhu --- libmicrokit/include/microkit.h | 10 ++++++++++ libmicrokit/src/dbg.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/libmicrokit/include/microkit.h b/libmicrokit/include/microkit.h index b8eede30e..a2efae450 100644 --- a/libmicrokit/include/microkit.h +++ b/libmicrokit/include/microkit.h @@ -96,6 +96,16 @@ void microkit_dbg_put32(seL4_Uint32 x); */ void microkit_dbg_put64(seL4_Uint64 x); +/* + * Output the hexadecimal representation of an 32-bit integer to the debug console. + */ +void microkit_dbg_puthex32(seL4_Uint32 x); + +/* + * Output the hexadecimal representation of an 64-bit integer to the debug console. + */ +void microkit_dbg_puthex64(seL4_Uint64 x); + static inline void microkit_internal_crash(seL4_Error err) { /* diff --git a/libmicrokit/src/dbg.c b/libmicrokit/src/dbg.c index e7c5e8499..fa67316ad 100644 --- a/libmicrokit/src/dbg.c +++ b/libmicrokit/src/dbg.c @@ -65,6 +65,37 @@ void microkit_dbg_put64(seL4_Uint64 x) microkit_dbg_puts(&tmp[i]); } +static char hexchar(unsigned int v) +{ + return v < 10 ? '0' + v : ('a' - 10) + v; +} + +void microkit_dbg_puthex32(seL4_Uint32 val) +{ + char buffer[8 + 3]; + buffer[0] = '0'; + buffer[1] = 'x'; + buffer[8 + 3 - 1] = 0; + for (unsigned i = 8 + 1; i > 1; i--) { + buffer[i] = hexchar(val & 0xf); + val >>= 4; + } + microkit_dbg_puts(buffer); +} + +void microkit_dbg_puthex64(seL4_Uint64 val) +{ + char buffer[16 + 3]; + buffer[0] = '0'; + buffer[1] = 'x'; + buffer[16 + 3 - 1] = 0; + for (unsigned i = 16 + 1; i > 1; i--) { + buffer[i] = hexchar(val & 0xf); + val >>= 4; + } + microkit_dbg_puts(buffer); +} + /* * We have to provide an implementation for libsel4 debug asserts, make it * weak so users can override with their own libc etc.