From 72ecb60392d4fd43bac0be3e9f8cab6bbf6c49a7 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Tue, 3 Feb 2009 18:06:37 +0000 Subject: [PATCH] qi-add-hex-sprintf-type-functions.patch We need to print hex into string buffers now, only in phase 2 Signed-off-by: Andy Green --- qiboot/include/qi.h | 4 ++++ qiboot/src/utils-phase2.c | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/qiboot/include/qi.h b/qiboot/include/qi.h index 8d46ac0..84fdc50 100644 --- a/qiboot/include/qi.h +++ b/qiboot/include/qi.h @@ -126,6 +126,10 @@ void printdec(int n); void hexdump(unsigned char *start, int len); void udelay(int n); +/* phase2 only */ +void setnybble(char *p, unsigned char n); +void set8(char *p, unsigned char n); +void set32(char *p, unsigned int u); unsigned long crc32(unsigned long crc, const unsigned char *buf, unsigned int len); diff --git a/qiboot/src/utils-phase2.c b/qiboot/src/utils-phase2.c index f02d5b1..bbbd672 100644 --- a/qiboot/src/utils-phase2.c +++ b/qiboot/src/utils-phase2.c @@ -109,3 +109,26 @@ void hexdump(unsigned char *start, int len) len -= 16; } } + +void setnybble(char *p, unsigned char n) +{ + if (n < 10) + *p = '0' + n; + else + *p = 'a' + n - 10; +} + +void set8(char *p, unsigned char n) +{ + setnybble(p, (n >> 4) & 15); + setnybble(p + 1, n & 15); +} + +void set32(char *p, unsigned int u) +{ + set8(p, u >> 24); + set8(p + 2, u >> 16); + set8(p + 4, u >> 8); + set8(p + 6, u); +} +