:: commit 98fdd625c4b2237bacd83338afe9cbe4deffac36

mintsuki <mintsuki@protonmail.com> — 2021-04-04 02:51

parents: 49ac7572d1

video: Wire in new textmode modesetting logic; use BIOS instead of VGA ports to enable and disable hardware textmode cursor

diff --git a/stage23/drivers/vga_textmode.h b/stage23/drivers/vga_textmode.h
index cea95b73..cf22d936 100644
--- a/stage23/drivers/vga_textmode.h
+++ b/stage23/drivers/vga_textmode.h
@@ -3,7 +3,7 @@
 
 #include <stdbool.h>
 
-void init_vga_textmode(int *rows, int *cols);
+void init_vga_textmode(int *rows, int *cols, bool managed);
 
 void text_putchar(uint8_t c);
 void text_clear(bool move);
diff --git a/stage23/drivers/vga_textmode.s2.c b/stage23/drivers/vga_textmode.s2.c
index c580453b..c36b4d83 100644
--- a/stage23/drivers/vga_textmode.s2.c
+++ b/stage23/drivers/vga_textmode.s2.c
@@ -73,9 +73,7 @@ void text_disable_cursor(void) {
     return;
 }
 
-// VGA cursor code taken from: https://wiki.osdev.org/Text_Mode_Cursor
-
-void init_vga_textmode(int *_rows, int *_cols) {
+void init_vga_textmode(int *_rows, int *_cols, bool managed) {
     if (current_video_mode != -1) {
         struct rm_regs r = {0};
         r.eax = 0x0003;
@@ -84,8 +82,6 @@ void init_vga_textmode(int *_rows, int *_cols) {
         current_video_mode = -1;
     }
 
-    outb(0x3d4, 0x0a);
-    outb(0x3d5, 0x20);
 
     cursor_offset = 0;
     cursor_status = 1;
@@ -98,6 +94,24 @@ void init_vga_textmode(int *_rows, int *_cols) {
 
     *_rows = VD_ROWS;
     *_cols = VD_COLS / 2;
+
+    struct rm_regs r;
+
+    if (!managed) {
+        text_disable_cursor();
+        r = (struct rm_regs){0};
+        r.eax = 0x0200;
+        rm_int(0x10, &r, &r);
+        r = (struct rm_regs){0};
+        r.eax = 0x0100;
+        r.ecx = 0x0607;
+        rm_int(0x10, &r, &r);
+    } else {
+        r = (struct rm_regs){0};
+        r.eax = 0x0100;
+        r.ecx = 0x2706;
+        rm_int(0x10, &r, &r);
+    }
 }
 
 void text_double_buffer(bool state) {
diff --git a/stage23/lib/term.c b/stage23/lib/term.c
index dbe0d832..fbe512c1 100644
--- a/stage23/lib/term.c
+++ b/stage23/lib/term.c
@@ -7,8 +7,6 @@
 #include <lib/gterm.h>
 
 void term_vbe(uint32_t *colours, int margin, int margin_gradient, struct image *background) {
-    term_deinit();
-
     if (!gterm_init(&term_rows, &term_cols, colours, margin, margin_gradient, background)) {
 #if defined (bios)
         // Failed to set VBE properly, default to text mode
diff --git a/stage23/lib/term.h b/stage23/lib/term.h
index 03c4bebf..81cb4297 100644
--- a/stage23/lib/term.h
+++ b/stage23/lib/term.h
@@ -19,7 +19,6 @@ extern void (*term_double_buffer_flush)(void);
 
 void term_vbe(uint32_t *colours, int margin, int margin_gradient, struct image *background);
 void term_textmode(void);
-void term_deinit(void);
 void term_write(const char *buf, size_t count);
 
 extern int term_rows, term_cols;
diff --git a/stage23/lib/term.s2.c b/stage23/lib/term.s2.c
index 23b3c973..3b464af9 100644
--- a/stage23/lib/term.s2.c
+++ b/stage23/lib/term.s2.c
@@ -27,7 +27,7 @@ int term_rows, term_cols;
 
 #if defined (bios)
 void term_textmode(void) {
-    init_vga_textmode(&term_rows, &term_cols);
+    init_vga_textmode(&term_rows, &term_cols, true);
 
     raw_putchar    = text_putchar;
     clear          = text_clear;
@@ -45,10 +45,6 @@ void term_textmode(void) {
 }
 #endif
 
-void term_deinit(void) {
-    term_backend = NOT_READY;
-}
-
 static void term_putchar(uint8_t c);
 
 void term_write(const char *buf, size_t count) {
diff --git a/stage23/protos/chainload.c b/stage23/protos/chainload.c
index c68e8afc..01a57957 100644
--- a/stage23/protos/chainload.c
+++ b/stage23/protos/chainload.c
@@ -10,6 +10,7 @@
 #include <lib/term.h>
 #include <mm/mtrr.h>
 #include <sys/idt.h>
+#include <drivers/vga_textmode.h>
 
 __attribute__((noinline))
 __attribute__((section(".realmode")))
@@ -85,7 +86,8 @@ void chainload(char *config) {
         drive = (val - 1) + 0x80;
     }
 
-    term_deinit();
+    int rows, cols;
+    init_vga_textmode(&rows, &cols, false);
 
     struct volume *p = volume_get_by_coord(drive, part);
 
diff --git a/stage23/protos/linux.c b/stage23/protos/linux.c
index 513197e1..db8de0e0 100644
--- a/stage23/protos/linux.c
+++ b/stage23/protos/linux.c
@@ -482,8 +482,6 @@ void linux_load(char *config, char *cmdline) {
     // Video
     ///////////////////////////////////////
 
-    term_deinit();
-
     mtrr_restore();
 
     struct screen_info *screen_info = &boot_params->screen_info;
diff --git a/stage23/protos/stivale.c b/stage23/protos/stivale.c
index 6263c4ea..58e1b2d5 100644
--- a/stage23/protos/stivale.c
+++ b/stage23/protos/stivale.c
@@ -21,6 +21,7 @@
 #include <mm/pmm.h>
 #include <mm/mtrr.h>
 #include <stivale/stivale.h>
+#include <drivers/vga_textmode.h>
 
 struct stivale_struct stivale_struct = {0};
 
@@ -157,8 +158,6 @@ void stivale_load(char *config, char *cmdline) {
     print("stivale: Current epoch: %U\n", stivale_struct.epoch);
 
     if (stivale_hdr.flags & (1 << 0)) {
-        term_deinit();
-
         int req_width  = stivale_hdr.framebuffer_width;
         int req_height = stivale_hdr.framebuffer_height;
         int req_bpp    = stivale_hdr.framebuffer_bpp;
@@ -186,9 +185,10 @@ void stivale_load(char *config, char *cmdline) {
     } else {
 #if defined (uefi)
         panic("stivale: Cannot use text mode with UEFI.");
+#elif defined (bios)
+        int rows, cols;
+        init_vga_textmode(&rows, &cols, false);
 #endif
-
-        term_deinit();
     }
 
 #if defined (uefi)
diff --git a/stage23/protos/stivale2.c b/stage23/protos/stivale2.c
index ee76aacb..5df40a24 100644
--- a/stage23/protos/stivale2.c
+++ b/stage23/protos/stivale2.c
@@ -24,6 +24,7 @@
 #include <stivale/stivale2.h>
 #include <pxe/tftp.h>
 #include <drivers/edid.h>
+#include <drivers/vga_textmode.h>
 
 struct stivale2_struct stivale2_struct = {0};
 
@@ -263,8 +264,6 @@ void stivale2_load(char *config, char *cmdline, bool pxe, void *efi_system_table
     struct stivale2_header_tag_framebuffer *hdrtag = get_tag(&stivale2_hdr, STIVALE2_HEADER_TAG_FRAMEBUFFER_ID);
 
     if (hdrtag != NULL) {
-        term_deinit();
-
         int req_width  = hdrtag->framebuffer_width;
         int req_height = hdrtag->framebuffer_height;
         int req_bpp    = hdrtag->framebuffer_bpp;
@@ -309,9 +308,10 @@ void stivale2_load(char *config, char *cmdline, bool pxe, void *efi_system_table
     } else {
 #if defined (uefi)
         panic("stivale2: Cannot use text mode with UEFI.");
+#elif defined (bios)
+        int rows, cols;
+        init_vga_textmode(&rows, &cols, false);
 #endif
-
-        term_deinit();
     }
     }
 
tab: 248 wrap: offon