video: Fix missing terminal deinitialisation before changing into final video mode
diff --git a/stage23/lib/term.c b/stage23/lib/term.c
index fbe512c1..6910a4e4 100644
--- a/stage23/lib/term.c
+++ b/stage23/lib/term.c
@@ -7,6 +7,8 @@
#include <lib/gterm.h>
void term_vbe(uint32_t *colours, int margin, int margin_gradient, struct image *background) {
+ term_backend = NOT_READY;
+
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 81cb4297..d260a339 100644
--- a/stage23/lib/term.h
+++ b/stage23/lib/term.h
@@ -21,6 +21,8 @@ void term_vbe(uint32_t *colours, int margin, int margin_gradient, struct image *
void term_textmode(void);
void term_write(const char *buf, size_t count);
+void term_deinit(void);
+
extern int term_rows, term_cols;
enum {
diff --git a/stage23/lib/term.s2.c b/stage23/lib/term.s2.c
index 3b464af9..690144e1 100644
--- a/stage23/lib/term.s2.c
+++ b/stage23/lib/term.s2.c
@@ -27,6 +27,8 @@ int term_rows, term_cols;
#if defined (bios)
void term_textmode(void) {
+ term_backend = NOT_READY;
+
init_vga_textmode(&term_rows, &term_cols, true);
raw_putchar = text_putchar;
@@ -45,6 +47,10 @@ 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/linux.c b/stage23/protos/linux.c
index db8de0e0..513197e1 100644
--- a/stage23/protos/linux.c
+++ b/stage23/protos/linux.c
@@ -482,6 +482,8 @@ 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 58e1b2d5..7a62289a 100644
--- a/stage23/protos/stivale.c
+++ b/stage23/protos/stivale.c
@@ -157,6 +157,8 @@ void stivale_load(char *config, char *cmdline) {
stivale_struct.epoch = time();
print("stivale: Current epoch: %U\n", stivale_struct.epoch);
+ term_deinit();
+
if (stivale_hdr.flags & (1 << 0)) {
int req_width = stivale_hdr.framebuffer_width;
int req_height = stivale_hdr.framebuffer_height;
diff --git a/stage23/protos/stivale2.c b/stage23/protos/stivale2.c
index 5df40a24..5d167c94 100644
--- a/stage23/protos/stivale2.c
+++ b/stage23/protos/stivale2.c
@@ -261,6 +261,8 @@ void stivale2_load(char *config, char *cmdline, bool pxe, void *efi_system_table
// Create framebuffer struct tag
//////////////////////////////////////////////
{
+ term_deinit();
+
struct stivale2_header_tag_framebuffer *hdrtag = get_tag(&stivale2_hdr, STIVALE2_HEADER_TAG_FRAMEBUFFER_ID);
if (hdrtag != NULL) {
