Implement deinit for VGA textmode driver

This commit is contained in:
mintsuki 2020-04-19 13:20:26 +02:00
parent 9beda4afed
commit 9fa35d34be
4 changed files with 34 additions and 9 deletions

View File

@ -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();

View File

@ -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);

View File

@ -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"

View File

@ -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) {