Compare commits

...

2 Commits

Author SHA1 Message Date
Quinten Kock 3e3df8e724 implement human-unit printing 2020-12-04 18:52:18 +01:00
Quinten Kock 1aa7e9281a add trailing newline 2020-12-04 18:52:03 +01:00
3 changed files with 16 additions and 3 deletions

View File

@ -1,3 +1,3 @@
void breakpoint() {
asm volatile ("xchgw %bx, %bx");
}
}

View File

@ -17,7 +17,7 @@ void parse_stivale2(struct stivale2_struct *info) {
printf("Memmap (%d entries):\n", m->entries);
for (size_t i = 0; i < m->entries; i++) {
struct stivale2_mmap_entry me = m->memmap[i];
printf("\t[%x+%x] %x\n", me.base, me.length, me.type);
printf("\t[%x+%h] %x\n", me.base, me.length, me.type);
}
break;
}

View File

@ -14,6 +14,7 @@ void print(const char* c) {
}
static const char CONVERSION_TABLE[] = "0123456789abcdef";
static const char UNITS[] = "bKM";
static void printhex(size_t num) {
int i;
@ -56,6 +57,16 @@ static void printdec(size_t num) {
puts(&buf[i]);
}
static void printhuman(size_t num) {
const char *unit = UNITS;
while(num >= 2048 && *(unit+1)) {
num /= 1024;
unit++;
}
printdec(num);
putchar(*unit);
}
void printf(const char *format, ...) {
va_list argp;
va_start(argp, format);
@ -69,7 +80,9 @@ void printf(const char *format, ...) {
printdec(va_arg(argp, size_t));
} else if (*format == 's') {
puts(va_arg(argp, char*));
}
} else if (*format == 'h') {
printhuman(va_arg(argp, size_t));
}
} else {
putchar(*format);
}