about summary refs log tree commit diff stats
path: root/tools/iso/kernel.soso/debugprint.c
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-01-01 18:22:19 -0800
committerKartik Agaram <vc@akkartik.com>2020-01-01 18:42:48 -0800
commit65409d2312e702a48d3cf5b32479d25266bda3c3 (patch)
tree62a7262fce61f2302109246da4536ce6f8e9ef80 /tools/iso/kernel.soso/debugprint.c
parenta6da50ad30d2e1825575ffef497ab450a8f26e94 (diff)
downloadmu-65409d2312e702a48d3cf5b32479d25266bda3c3.tar.gz
5858
Move script to create a Soso boot image into a sub-directory.

I'm trying to streamline newcomer attention to just a couple of use cases.
Diffstat (limited to 'tools/iso/kernel.soso/debugprint.c')
-rw-r--r--tools/iso/kernel.soso/debugprint.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/tools/iso/kernel.soso/debugprint.c b/tools/iso/kernel.soso/debugprint.c
new file mode 100644
index 00000000..186bc89f
--- /dev/null
+++ b/tools/iso/kernel.soso/debugprint.c
@@ -0,0 +1,79 @@
+#include "debugprint.h"
+#include "common.h"
+#include "fs.h"
+
+static File* gFile = NULL;
+
+void Debug_initialize(const char* fileName) {
+    FileSystemNode* node = getFileSystemNode(fileName);
+
+    gFile = open_fs(node, 0);
+}
+
+void Debug_PrintF(const char *format, ...) {
+    char **arg = (char **) &format;
+    char c;
+    char buf[20];
+    char buffer[512];
+
+    int bufferIndex = 0;
+
+    //arg++;
+    __builtin_va_list vl;
+    __builtin_va_start(vl, format);
+
+    while ((c = *format++) != 0) {
+        if (bufferIndex > 510) {
+            break;
+        }
+
+        if (c != '%')
+          buffer[bufferIndex++] = c;
+        else {
+            char *p;
+
+            c = *format++;
+            switch (c) {
+              case 'x':
+                 buf[0] = '0';
+                 buf[1] = 'x';
+                 //itoa (buf + 2, c, *((int *) arg++));
+                 itoa (buf + 2, c, __builtin_va_arg(vl, int));
+                 p = buf;
+                 goto string;
+                 break;
+              case 'd':
+              case 'u':
+                //itoa (buf, c, *((int *) arg++));
+                itoa (buf, c, __builtin_va_arg(vl, int));
+                p = buf;
+                goto string;
+                break;
+
+              case 's':
+                //p = *arg++;
+                p = __builtin_va_arg(vl, char*);
+                if (! p)
+                  p = "(null)";
+
+              string:
+                while (*p)
+                  buffer[bufferIndex++] = (*p++);
+                break;
+
+              default:
+                //buffer[bufferIndex++] = (*((int *) arg++));
+                buffer[bufferIndex++] = __builtin_va_arg(vl, int);
+                break;
+              }
+          }
+      }
+
+    buffer[bufferIndex] = '\0';
+
+    if (gFile) {
+        write_fs(gFile, strlen(buffer), (uint8*)buffer);
+    }
+
+    __builtin_va_end(vl);
+}