Implement deinit for VGA textmode driver
diff --git a/src/drivers/vga_textmode.c b/src/drivers/vga_textmode.c
index 180330d6..a09b166d 100644
--- a/src/drivers/vga_textmode.c
+++ b/src/drivers/vga_textmode.c
@@ -68,13 +68,6 @@ static void text_clear_no_move(void) {
return;
}
-void init_vga_textmode(void) {
- port_out_b(0x3d4, 0x0a);
- port_out_b(0x3d5, 0x20);
- text_clear();
- return;
-}
-
static void text_enable_cursor(void) {
cursor_status = 1;
draw_cursor();
@@ -87,6 +80,29 @@ static void text_disable_cursor(void) {
return;
}
+// VGA cursor code taken from: https://wiki.osdev.org/Text_Mode_Cursor
+
+void init_vga_textmode(void) {
+ port_out_b(0x3d4, 0x0a);
+ port_out_b(0x3d5, 0x20);
+ text_clear();
+}
+
+void deinit_vga_textmode(void) {
+ text_disable_cursor();
+ text_clear();
+
+ port_out_b(0x3d4, 0x0a);
+ port_out_b(0x3d5, (port_in_b(0x3d5) & 0xc0) | 14);
+ port_out_b(0x3d4, 0x0b);
+ port_out_b(0x3d5, (port_in_b(0x3d5) & 0xe0) | 15);
+
+ port_out_b(0x3d4, 0x0f);
+ port_out_b(0x3d5, 0x00);
+ port_out_b(0x3d4, 0x0e);
+ port_out_b(0x3d5, 0x00);
+}
+
static void text_set_cursor_palette(uint8_t c) {
cursor_palette = c;
draw_cursor();
diff --git a/src/drivers/vga_textmode.h b/src/drivers/vga_textmode.h
index 76d29e67..044da5a7 100644
--- a/src/drivers/vga_textmode.h
+++ b/src/drivers/vga_textmode.h
@@ -1,9 +1,11 @@
-#ifndef __VGA_TEXTMODE_H__
-#define __VGA_TEXTMODE_H__
+#ifndef __DRIVERS__VGA_TEXTMODE_H__
+#define __DRIVERS__VGA_TEXTMODE_H__
#include <stddef.h>
void init_vga_textmode(void);
+void deinit_vga_textmode(void);
+
void text_write(const char *, size_t);
void text_get_cursor_pos(int *x, int *y);
diff --git a/src/protos/linux.c b/src/protos/linux.c
index 91900bef..41a33b0c 100644
--- a/src/protos/linux.c
+++ b/src/protos/linux.c
@@ -4,6 +4,8 @@
#include <fs/file.h>
#include <lib/blib.h>
#include <lib/real.h>
+#include <drivers/vga_textmode.h>
+#include <lib/config.h>
void linux_load(struct file_handle *fd, char *cmdline) {
uint32_t signature;
@@ -95,6 +97,8 @@ void linux_load(struct file_handle *fd, char *cmdline) {
uint16_t real_mode_code_seg = rm_seg(real_mode_code);
uint16_t kernel_entry_seg = real_mode_code_seg + 0x20;
+ deinit_vga_textmode();
+
asm volatile (
"cli\n\t"
"cld\n\t"
diff --git a/src/protos/stivale.c b/src/protos/stivale.c
index 188e66f2..0c5ea3ef 100644
--- a/src/protos/stivale.c
+++ b/src/protos/stivale.c
@@ -7,6 +7,7 @@
#include <lib/e820.h>
#include <lib/config.h>
#include <drivers/vbe.h>
+#include <drivers/vga_textmode.h>
#include <fs/file.h>
struct stivale_header {
@@ -145,6 +146,8 @@ void stivale_load(struct file_handle *fd, char *cmdline) {
&stivale_struct.framebuffer_width,
&stivale_struct.framebuffer_height,
&stivale_struct.framebuffer_bpp);
+ } else {
+ deinit_vga_textmode();
}
if (bits == 64) {
