term: Misc fixes and improvements
diff --git a/common/drivers/vga_textmode.c b/common/drivers/vga_textmode.c
index 9cabef49..e555254d 100644
--- a/common/drivers/vga_textmode.c
+++ b/common/drivers/vga_textmode.c
@@ -11,6 +11,23 @@
#include <lib/term.h>
#include <mm/pmm.h>
+struct textmode_context {
+ struct term_context term;
+
+ volatile uint8_t *video_mem;
+
+ uint8_t *back_buffer;
+ uint8_t *front_buffer;
+
+ size_t cursor_offset;
+ size_t old_cursor_offset;
+ bool cursor_status;
+ uint8_t text_palette;
+
+ uint8_t saved_state_text_palette;
+ size_t saved_state_cursor_offset;
+};
+
#define VIDEO_BOTTOM ((VD_ROWS * VD_COLS) - 1)
#define VD_COLS (80 * 2)
#define VD_ROWS 25
@@ -350,10 +367,12 @@ void vga_textmode_init(bool managed) {
term->full_refresh = text_full_refresh;
term->deinit = text_deinit;
- term_backend = TEXTMODE;
+ term->in_bootloader = true;
+
term_context_reinit(term);
+ term->full_refresh(term);
- term->in_bootloader = true;
+ term_backend = TEXTMODE;
}
#endif
diff --git a/common/drivers/vga_textmode.h b/common/drivers/vga_textmode.h
index 0f9b875c..f9355d4a 100644
--- a/common/drivers/vga_textmode.h
+++ b/common/drivers/vga_textmode.h
@@ -1,28 +1,12 @@
#ifndef __DRIVERS__VGA_TEXTMODE_H__
#define __DRIVERS__VGA_TEXTMODE_H__
-#include <stdbool.h>
-#include <stdint.h>
-#include <stddef.h>
-#include <term/term.h>
-
-struct textmode_context {
- struct term_context term;
-
- volatile uint8_t *video_mem;
-
- uint8_t *back_buffer;
- uint8_t *front_buffer;
+#if defined (BIOS)
- size_t cursor_offset;
- size_t old_cursor_offset;
- bool cursor_status;
- uint8_t text_palette;
-
- uint8_t saved_state_text_palette;
- size_t saved_state_cursor_offset;
-};
+#include <stdbool.h>
void vga_textmode_init(bool managed);
#endif
+
+#endif
diff --git a/common/lib/gterm.c b/common/lib/gterm.c
index d61ace4c..3d19cfe6 100644
--- a/common/lib/gterm.c
+++ b/common/lib/gterm.c
@@ -771,6 +771,10 @@ no_load_font:;
font_scale_x, font_scale_y,
margin);
+ if (term == NULL) {
+ return false;
+ }
+
pmm_free(font, FONT_MAX);
if (bg_canvas != NULL) {
pmm_free(bg_canvas, bg_canvas_size);
@@ -784,7 +788,6 @@ no_load_font:;
term->in_bootloader = true;
term_context_reinit(term);
-
term->full_refresh(term);
term_backend = GTERM;
diff --git a/common/menu.c b/common/menu.c
index 4dd07d41..5df24f43 100644
--- a/common/menu.c
+++ b/common/menu.c
@@ -564,7 +564,7 @@ static void menu_init_term(void) {
if (menu_resolution != NULL)
parse_resolution(&req_width, &req_height, &req_bpp, menu_resolution);
- if (!gterm_init(NULL, req_width, req_height)) {
+ if (!quiet && !gterm_init(NULL, req_width, req_height)) {
#if defined (BIOS)
vga_textmode_init(true);
#elif defined (UEFI)
@@ -851,17 +851,18 @@ timeout_aborted:
selected_menu_entry->expanded = !selected_menu_entry->expanded;
goto refresh;
}
- if (term_backend == FALLBACK) {
- gterm_init(NULL, 0, 0);
- if (term == NULL) {
+ if (!quiet) {
+ if (term_backend == FALLBACK) {
+ if (!gterm_init(NULL, 0, 0)) {
#if defined (BIOS)
- vga_textmode_init(true);
+ vga_textmode_init(true);
#elif defined (UEFI)
- panic(true, "menu: Failed to initialise terminal");
+ panic(true, "menu: Failed to initialise terminal");
#endif
+ }
+ } else {
+ reset_term();
}
- } else {
- reset_term();
}
boot(selected_menu_entry->body);
case 'e':
