]> git.dujemihanovic.xyz Git - nameless-os.git/blobdiff - kernel/arch/x86/tty/tty.c
Add panic facility
[nameless-os.git] / kernel / arch / x86 / tty / tty.c
index 07d734e54fc00f1919e51e0efe624271158c2e01..c55cdd41eb8fe0c06afa792a63e9d2c0d767060f 100644 (file)
@@ -137,3 +137,76 @@ void kprintd(uint32_t dword)
        temp = dword & 0xF;
        kprintc(hex_chars[temp], VGA_COLOR_LIGHT_GRAY);
 }
+
+void kprintq(uint64_t qword)
+{
+       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);
+}
+
+int kprintdec(uint32_t num, uint8_t color)
+{
+       char buffer[11];
+       int digits = 10;
+       /* TODO: make an actual memset function to use instead of this */
+       for (int i=0; i<11; i++) {
+               buffer[i] = 0;
+       }
+
+       /* put the numbers in the buffer */
+       for (int i=9; i>0 && num>0; i--) {
+               uint8_t currdigit = num%10;
+               buffer[i] = currdigit+'0';
+               num /= 10;
+       }
+
+       /* shift the array as much as needed */
+       while (*buffer == '\0') {
+               digits--;
+               for (int i=0; i<9; i++) {
+                       buffer[i] = buffer[i+1];
+               }
+       }
+
+       /* zero out any leftovers */
+       if (digits < 10) {
+               for (int i=digits; i<10; i++) {
+                       buffer[i] = '\0';
+               }
+       }
+
+       kprint(buffer, color);
+       return digits;
+}