diff --git a/libmicrokit/include/microkit.h b/libmicrokit/include/microkit.h index b31391aeb..a2efae450 100644 --- a/libmicrokit/include/microkit.h +++ b/libmicrokit/include/microkit.h @@ -91,6 +91,21 @@ 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); + +/* + * 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 94c987974..fa67316ad 100644 --- a/libmicrokit/src/dbg.c +++ b/libmicrokit/src/dbg.c @@ -52,6 +52,50 @@ 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]); +} + +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.