[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH v1 05/14] xen/riscv: add early_printk_hnum() function
Add ability to print hex number. It might be useful to print register value as debug information in BUG(), WARN(), etc... Signed-off-by: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx> --- xen/arch/riscv/early_printk.c | 39 +++++++++++++++++++++++ xen/arch/riscv/include/asm/early_printk.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/xen/arch/riscv/early_printk.c b/xen/arch/riscv/early_printk.c index 6f590e712b..876d022dd6 100644 --- a/xen/arch/riscv/early_printk.c +++ b/xen/arch/riscv/early_printk.c @@ -43,3 +43,42 @@ void early_printk(const char *str) str++; } } + +static void reverse(char *s, int length) +{ + int c; + char *begin, *end, temp; + + begin = s; + end = s + length - 1; + + for ( c = 0; c < length/2; c++ ) + { + temp = *end; + *end = *begin; + *begin = temp; + + begin++; + end--; + } +} + +void early_printk_hnum(const register_t reg_val) +{ + char hex[] = "0123456789ABCDEF"; + char buf[17] = {0}; + + register_t num = reg_val; + unsigned int count = 0; + + for ( count = 0; num != 0; count++, num >>= 4 ) + buf[count] = hex[num & 0x0000000f]; + + buf[count] = '\0'; + + reverse(buf, count); + + early_printk("0x"); + early_printk(buf); + early_printk("\n"); +} diff --git a/xen/arch/riscv/include/asm/early_printk.h b/xen/arch/riscv/include/asm/early_printk.h index 05106e160d..f6d7580eb0 100644 --- a/xen/arch/riscv/include/asm/early_printk.h +++ b/xen/arch/riscv/include/asm/early_printk.h @@ -5,8 +5,10 @@ #ifdef CONFIG_EARLY_PRINTK void early_printk(const char *str); +void early_printk_hnum(const register_t reg_val); #else static inline void early_printk(const char *s) {}; +static inline void early_printk_hnum(const register_t reg_val) {}; #endif #endif /* __EARLY_PRINTK_H__ */ -- 2.39.0
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |