feat: (devfs) a new filesystem for device exposure.
[lunaix-os.git] / lunaix-os / kernel / kprintf.c
index af47a8abae297a857d19405b775c75215fb0febd..d18691ac2fd1fa6d9ccd3389dcb7058c5710408d 100644 (file)
@@ -84,4 +84,30 @@ kprint_panic(const char* fmt, ...)
     tty_put_str_at(buf, 0, 24);
 
     va_end(args);
+}
+
+void
+kprint_hex(const void* buffer, unsigned int size)
+{
+    unsigned char* data = (unsigned char*)buffer;
+    char buf[16];
+    char ch_cache[16];
+    unsigned int ptr = 0;
+    int i;
+
+    ch_cache[0] = '|';
+    ch_cache[1] = ' ';
+    while (size) {
+        snprintf(buf, 64, " %.4p: ", ptr);
+        console_write_str(buf);
+        for (i = 0; i < 8 && size; i++, size--, ptr++) {
+            unsigned char c = *(data + ptr) & 0xff;
+            ch_cache[2 + i] = (32 <= c && c < 127) ? c : '.';
+            snprintf(buf, 64, "%.2x  ", c);
+            console_write_str(buf);
+        }
+        ch_cache[2 + i] = '\0';
+        console_write_str(ch_cache);
+        console_write_char('\n');
+    }
 }
\ No newline at end of file