mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-11-01 09:13:37 +00:00
x86/boot: Add error_putdec() helper
Add a helper to print decimal numbers to early console. Suggested-by: Borislav Petkov (AMD) <bp@alien8.de> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com> Signed-off-by: Jun'ichi Nomura <junichi.nomura@nec.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/lkml/20240123112624.GBZa-iYP1l9SSYtr-V@fat_crate.local/ Link: https://lore.kernel.org/r/20240202035052.17963-1-junichi.nomura@nec.com
This commit is contained in:
parent
1567570624
commit
9ba8ec8ee6
2 changed files with 27 additions and 12 deletions
|
|
@ -164,21 +164,34 @@ void __putstr(const char *s)
|
|||
outb(0xff & (pos >> 1), vidport+1);
|
||||
}
|
||||
|
||||
static noinline void __putnum(unsigned long value, unsigned int base,
|
||||
int mindig)
|
||||
{
|
||||
char buf[8*sizeof(value)+1];
|
||||
char *p;
|
||||
|
||||
p = buf + sizeof(buf);
|
||||
*--p = '\0';
|
||||
|
||||
while (mindig-- > 0 || value) {
|
||||
unsigned char digit = value % base;
|
||||
digit += (digit >= 10) ? ('a'-10) : '0';
|
||||
*--p = digit;
|
||||
|
||||
value /= base;
|
||||
}
|
||||
|
||||
__putstr(p);
|
||||
}
|
||||
|
||||
void __puthex(unsigned long value)
|
||||
{
|
||||
char alpha[2] = "0";
|
||||
int bits;
|
||||
__putnum(value, 16, sizeof(value)*2);
|
||||
}
|
||||
|
||||
for (bits = sizeof(value) * 8 - 4; bits >= 0; bits -= 4) {
|
||||
unsigned long digit = (value >> bits) & 0xf;
|
||||
|
||||
if (digit < 0xA)
|
||||
alpha[0] = '0' + digit;
|
||||
else
|
||||
alpha[0] = 'a' + (digit - 0xA);
|
||||
|
||||
__putstr(alpha);
|
||||
}
|
||||
void __putdec(unsigned long value)
|
||||
{
|
||||
__putnum(value, 10, 1);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_X86_NEED_RELOCS
|
||||
|
|
|
|||
|
|
@ -63,8 +63,10 @@ void *malloc(int size);
|
|||
void free(void *where);
|
||||
void __putstr(const char *s);
|
||||
void __puthex(unsigned long value);
|
||||
void __putdec(unsigned long value);
|
||||
#define error_putstr(__x) __putstr(__x)
|
||||
#define error_puthex(__x) __puthex(__x)
|
||||
#define error_putdec(__x) __putdec(__x)
|
||||
|
||||
#ifdef CONFIG_X86_VERBOSE_BOOTUP
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue