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); +} +