:: commit b12e8745308637bf56c3062ef670d9d6148737a5

mintsuki <mintsuki@protonmail.com> — 2020-12-28 00:04

parents: fcd3848a22

misc: Support COM1 debug output

diff --git a/CONFIG.md b/CONFIG.md
index 9ee23e3f..a98f7d1b 100644
--- a/CONFIG.md
+++ b/CONFIG.md
@@ -62,6 +62,8 @@ Some keys take *URIs* as values; these are described in the next section.
 * `THEME_MARGIN_GRADIENT` - Set the thickness in pixel for the gradient around the terminal. Ignored if `GRAPHICS` is not `yes`.
 * `BACKGROUND_PATH` - URI where to find the background .BMP file. Ignored if `GRAPHICS` is not `yes`.
 * `STAGE2_MAP` - URI where to find the stage2 symbol map file for stacktraces and symbol name resolution at runtime.
+* `E9_OUTPUT` - Output to port 0xe9 for debugging purposes.
+* `COM1_OUTPUT` - Output to COM1 for debugging purposes.
 
 *Locally assignable (non protocol specific)* keys are:
 * `PROTOCOL` - The boot protocol that will be used to boot the kernel. Valid protocols are: `linux`, `stivale`, `stivale2`, `chainload`.
diff --git a/limine-pxe.bin b/limine-pxe.bin
index ef724351..ebb54d72 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index 54053b03..f46f370f 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index dc020fa9..e492b6d2 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/lib/print.c b/stage2/lib/print.c
index 57b70699..fa6db87e 100644
--- a/stage2/lib/print.c
+++ b/stage2/lib/print.c
@@ -9,6 +9,7 @@
 #include <sys/cpu.h>
 
 static int e9_output = -1;
+static int com1_output = -1;
 
 static const char *base_digits = "0123456789abcdef";
 
@@ -123,6 +124,22 @@ void vprint(const char *fmt, va_list args) {
         e9_output = e9_output_config != NULL &&
                     !strcmp(e9_output_config, "yes");
     }
+    if (config_ready && com1_output == -1) {
+        char *com1_output_config = config_get_value(NULL, 0, "COM1_OUTPUT");
+        com1_output = com1_output_config != NULL &&
+                    !strcmp(com1_output_config, "yes");
+
+        if (com1_output == 1) {
+            // Init com1
+            outb(0x3F8 + 1, 0x00);
+            outb(0x3F8 + 3, 0x80);
+            outb(0x3F8 + 0, 0x01);
+            outb(0x3F8 + 1, 0x00);
+            outb(0x3F8 + 3, 0x03);
+            outb(0x3F8 + 2, 0xC7);
+            outb(0x3F8 + 4, 0x0B);
+        }
+    }
 
     size_t print_buf_i = 0;
 
@@ -180,8 +197,13 @@ void vprint(const char *fmt, va_list args) {
 out:
     term_write(print_buf, print_buf_i);
 
-    if (e9_output == 1) {
-        for (size_t i = 0; i < print_buf_i; i++)
+    for (size_t i = 0; i < print_buf_i; i++) {
+        if (e9_output == 1)
             outb(0xe9, print_buf[i]);
+        if (com1_output == 1) {
+            if (print_buf[i] == '\n')
+                outb(0x3f8, '\r');
+            outb(0x3f8, print_buf[i]);
+        }
     }
 }
tab: 248 wrap: offon