}
-void kprintb(uint8_t byte)
+void kprintnibble(uint8_t nibble)
{
- uint8_t temp;
- temp = byte >> 4;
- kprint("0x", VGA_COLOR_LIGHT_GRAY);
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = byte & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
+ nibble &= 0xf;
+ if (nibble < 0xa)
+ kprintc('0' + nibble, 0);
+ else kprintc('a' - 0xa + nibble, 0);
}
-void kprintw(uint16_t word)
+void kprintb(uint8_t byte, int print_delm)
{
- uint8_t temp;
- temp = word >> 12;
- kprint("0x", VGA_COLOR_LIGHT_GRAY);
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (word >> 8) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (word >> 4) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = word & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
+ if (print_delm)
+ kprint("0x", 0);
+
+ kprintnibble(byte >> 4);
+ kprintnibble(byte);
}
-void kprintd(uint32_t dword)
+void kprintw(uint16_t word, int print_delm)
{
- uint8_t temp;
- temp = dword >> 28;
- kprint("0x", VGA_COLOR_LIGHT_GRAY);
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (dword >> 24) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (dword >> 20) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (dword >> 16) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (dword >> 12) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (dword >> 8) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (dword >> 4) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = dword & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
+ if (print_delm)
+ kprint("0x", 0);
+
+ kprintb(word >> 8, 0);
+ kprintb(word, 0);
}
-void kprintq(uint64_t qword)
+void kprintd(uint32_t dword, int print_delm)
{
- uint8_t temp;
- temp = qword >> 60;
- kprint("0x", VGA_COLOR_LIGHT_GRAY);
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 56) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 52) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 48) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 44) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 40) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 36) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 32) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 28) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 24) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 20) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 16) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 12) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 8) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = (qword >> 4) & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
- temp = qword & 0xF;
- kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
+ if (print_delm)
+ kprint("0x", 0);
+
+ kprintw(dword >> 16, 0);
+ kprintw(dword, 0);
+}
+
+void kprintq(uint64_t qword, int print_delm)
+{
+ if (print_delm)
+ kprint("0x", 0);
+
+ kprintd(qword >> 32, 0);
+ kprintd(qword, 0);
}
int kprintdec(uint32_t num, uint8_t color)
kprint(" Base | Length | Type | Attrib |\n", 0);
kprint("------------------------------------------------------------\n", 0);
for (int i=0; i<mmap_size; i++) {
- kprintq(mmap[i].base);
+ kprintq(mmap[i].base, 1);
kprintc('|', 0);
- kprintq(mmap[i].length);
+ kprintq(mmap[i].length, 1);
kprintc('|', 0);
- kprintd(mmap[i].type);
+ kprintd(mmap[i].type, 1);
kprintc('|', 0);
- kprintd(mmap[i].attrib);
+ kprintd(mmap[i].attrib, 1);
kprintc('|', 0);
kprintc('\n', 0);
}
{
kprint("Double fault occurred!\n", VGA_COLOR_BRIGHT_RED);
kprint("EAX: ", 0);
- kprintd(frame->eax);
+ kprintd(frame->eax, 1);
kprintc(' ', 0);
kprint("EBX: ", 0);
- kprintd(frame->ebx);
+ kprintd(frame->ebx, 1);
kprintc(' ', 0);
kprint("ECX: ", 0);
- kprintd(frame->ecx);
+ kprintd(frame->ecx, 1);
kprintc(' ', 0);
kprint("EDX: ", 0);
- kprintd(frame->edx);
+ kprintd(frame->edx, 1);
kprintc('\n', 0);
kprint("EBP: ", 0);
- kprintd(frame->ebp);
+ kprintd(frame->ebp, 1);
kprintc(' ', 0);
kprint("ESP: ", 0);
- kprintd(frame->esp);
+ kprintd(frame->esp, 1);
kprintc('\n', 0);
kprint("ESI: ", 0);
- kprintd(frame->esi);
+ kprintd(frame->esi, 1);
kprintc(' ', 0);
kprint("EDI: ", 0);
- kprintd(frame->edi);
+ kprintd(frame->edi, 1);
kprintc('\n', 0);
kprint("EIP: ", 0);
- kprintd(frame->eip);
+ kprintd(frame->eip, 1);
kprintc(' ', 0);
kprint("EFLAGS: ", 0);
- kprintd(frame->eflags);
+ kprintd(frame->eflags, 1);
kprintc('\n', 0);
PANIC("double fault");
}