term: Introduce quiet mode

This commit is contained in:
mintsuki 2021-11-20 21:47:51 +01:00
parent 4337ae1a32
commit a937eb4202
10 changed files with 98 additions and 14 deletions

View File

@ -82,6 +82,7 @@ Some keys take *URIs* as values; these are described in the next section.
* `EDITOR_HIGHLIGHTING` - If set to `no`, syntax highlighting in the editor will be disabled. Defaults to `yes`.
* `EDITOR_VALIDATION` - If set to `no`, the editor will not alert you about invalid keys / syntax errors. Defaults to `yes`.
* `VERBOSE` - If set to `yes`, print additional information during boot. Defaults to not verbose.
* `QUIET` - If set to `yes`, enable quiet mode, where all screen output except panics and important warnings is suppressed.
* `RANDOMISE_MEMORY` - If set to `yes`, randomise the contents of RAM at bootup in order to find bugs related to non zeroed memory or for security reasons. This option will slow down boot time significantly.
* `RANDOMIZE_MEMORY` - Alias of `RANDOMISE_MEMORY`.

View File

@ -44,6 +44,7 @@ static bool stage3_init(struct volume *part) {
stage3_found = true;
if (stage3->size != (size_t)limine_sys_size) {
term_textmode();
print("limine.sys size incorrect.\n");
return false;
}
@ -55,6 +56,7 @@ static bool stage3_init(struct volume *part) {
fclose(stage3);
if (memcmp(build_id_s2 + 16, build_id_s3 + 16, 20) != 0) {
term_textmode();
print("limine.sys build ID mismatch.\n");
return false;
}
@ -76,11 +78,11 @@ void entry(uint8_t boot_drive, int boot_from) {
if (!a20_enable())
panic("Could not enable A20 line");
term_notready();
init_e820();
init_memmap();
term_textmode();
init_idt();
disk_create_index();
@ -98,14 +100,17 @@ void entry(uint8_t boot_drive, int boot_from) {
}
);
if (!stage3_found)
if (!stage3_found) {
term_textmode();
print("\n"
"!! Stage 3 file not found!\n"
"!! Have you copied limine.sys to the root or /boot directories of\n"
"!! one of the partitions on the boot device?\n\n");
}
if (!stage3_loaded)
if (!stage3_loaded) {
panic("Failed to load stage 3.");
}
__attribute__((noreturn))
void (*stage3)(int boot_from) = (void *)stage3_addr;

View File

@ -63,6 +63,8 @@ void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable) {
print("WARNING: Failed to disable watchdog timer!\n");
}
term_notready();
init_memmap();
disk_create_index();
@ -136,6 +138,9 @@ void stage3_common(void) {
}
);
char *quiet_str = config_get_value(NULL, 0, "QUIET");
quiet = quiet_str != NULL && strcmp(quiet_str, "yes") == 0;
char *verbose_str = config_get_value(NULL, 0, "VERBOSE");
verbose = verbose_str != NULL && strcmp(verbose_str, "yes") == 0;

View File

@ -32,7 +32,7 @@ extern struct volume *boot_volume;
extern bool stage3_loaded;
#endif
extern bool verbose;
extern bool verbose, quiet;
bool parse_resolution(size_t *width, size_t *height, size_t *bpp, const char *buf);

View File

@ -4,6 +4,7 @@
#include <lib/print.h>
bool verbose = true;
bool quiet = false;
uint8_t bcd_to_int(uint8_t val) {
return (val & 0x0f) + ((val & 0xf0) >> 4) * 10;

View File

@ -15,6 +15,8 @@ __attribute__((noreturn)) void panic(const char *fmt, ...) {
va_start(args, fmt);
quiet = false;
if (term_backend == NOT_READY) {
#if bios == 1
term_textmode();

View File

@ -14,11 +14,15 @@ void term_deinit(void) {
gterm_deinit();
}
term_backend = NOT_READY;
term_notready();
}
void term_vbe(size_t width, size_t height) {
term_backend = NOT_READY;
term_notready();
if (quiet) {
return;
}
if (!gterm_init(&term_rows, &term_cols, width, height)) {
#if bios == 1

View File

@ -48,6 +48,7 @@ void term_reinit(void);
void term_deinit(void);
void term_vbe(size_t width, size_t height);
void term_textmode(void);
void term_notready(void);
void term_putchar(uint8_t c);
void term_write(uint64_t buf, uint64_t count);
@ -95,12 +96,10 @@ extern void (*term_callback)(uint64_t, uint64_t, uint64_t, uint64_t);
extern bool term_autoflush;
inline void reset_term(void) {
if (term_backend != NOT_READY) {
term_autoflush = true;
enable_cursor();
clear(true);
term_double_buffer_flush();
}
term_autoflush = true;
enable_cursor();
clear(true);
term_double_buffer_flush();
}
#endif

View File

@ -16,6 +16,66 @@ int term_backend = NOT_READY;
size_t term_rows, term_cols;
bool term_runtime = false;
static void notready_raw_putchar(uint8_t c) {
(void)c;
}
static void notready_clear(bool move) {
(void)move;
}
static void notready_void(void) {}
static void notready_set_cursor_pos(size_t x, size_t y) {
(void)x; (void)y;
}
static void notready_get_cursor_pos(size_t *x, size_t *y) {
*x = 0;
*y = 0;
}
static void notready_size_t(size_t n) {
(void)n;
}
static bool notready_disable(void) {
return false;
}
static void notready_move_character(size_t a, size_t b, size_t c, size_t d) {
(void)a; (void)b; (void)c; (void)d;
}
static uint64_t notready_context_size(void) {
return 0;
}
static void notready_uint64_t(uint64_t n) {
(void)n;
}
void term_notready(void) {
term_backend = NOT_READY;
raw_putchar = notready_raw_putchar;
clear = notready_clear;
enable_cursor = notready_void;
disable_cursor = notready_disable;
set_cursor_pos = notready_set_cursor_pos;
get_cursor_pos = notready_get_cursor_pos;
set_text_fg = notready_size_t;
set_text_bg = notready_size_t;
set_text_fg_bright = notready_size_t;
set_text_bg_bright = notready_size_t;
set_text_fg_default = notready_void;
set_text_bg_default = notready_void;
scroll_disable = notready_disable;
scroll_enable = notready_void;
term_move_character = notready_move_character;
term_scroll = notready_void;
term_swap_palette = notready_void;
term_double_buffer_flush = notready_void;
term_context_size = notready_context_size;
term_context_save = notready_uint64_t;
term_context_restore = notready_uint64_t;
term_full_refresh = notready_void;
term_rows = 100;
term_cols = 100;
}
void (*raw_putchar)(uint8_t c);
void (*clear)(bool move);
void (*enable_cursor)(void);
@ -90,11 +150,16 @@ void term_reinit(void) {
g_select = 0;
charsets[0] = CHARSET_DEFAULT;
charsets[1] = CHARSET_DEC_SPECIAL;
term_autoflush = true;
}
#if bios == 1
void term_textmode(void) {
term_backend = NOT_READY;
term_notready();
if (quiet) {
return;
}
init_vga_textmode(&term_rows, &term_cols, true);

View File

@ -456,6 +456,8 @@ failed_to_load_header_section:
struct stivale2_header_tag_terminal *terminal_hdr_tag = get_tag(&stivale2_hdr, STIVALE2_HEADER_TAG_TERMINAL_ID);
if (bits == 64 && terminal_hdr_tag != NULL) {
quiet = false;
if (bios &&
((avtag == NULL && hdrtag == NULL) || (avtag != NULL && preference == 1))) {
term_textmode();