term/limine: Allow overriding terminal config in entry

This commit is contained in:
mintsuki 2022-08-14 15:09:57 +02:00
parent 11b56c39f0
commit 997c787c16
9 changed files with 36 additions and 27 deletions

View File

@ -117,6 +117,7 @@ Editor control options.
* `RESOLUTION` - The resolution to be used. This setting takes the form of `<width>x<height>x<bpp>`. If the resolution is not available, Limine will pick another one automatically. Omitting `<bpp>` will default to 32.
* `KASLR` - For relocatable kernels, if set to `no`, disable kernel address space layout randomisation. KASLR is enabled by default.
* `TERM_CONFIG_OVERRIDE` - If set to `yes`, override the terminal configuration for this entry. Resets all the `TERM_*` assignments to default and allows setting them anew inside the entry. Note that without this, Limine will never look for terminal configuration settings inside entries.
* Chainload protocol on BIOS:
* `DRIVE` - The 1-based drive to chainload, if omitted, assume boot drive.

View File

@ -56,7 +56,7 @@ noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
status = gBS->SetWatchdogTimer(0, 0x10000, 0, NULL);
if (status) {
term_vbe(0, 0);
term_vbe(NULL, 0, 0);
early_term = true;
print("WARNING: Failed to disable watchdog timer!\n");
}
@ -74,7 +74,7 @@ noreturn void uefi_entry(EFI_HANDLE ImageHandle, EFI_SYSTEM_TABLE *SystemTable)
EFI_HANDLE current_handle = ImageHandle;
for (;;) {
if (current_handle == NULL) {
term_vbe(0, 0);
term_vbe(NULL, 0, 0);
early_term = true;
print("WARNING: Could not meaningfully match the boot device handle with a volume.\n");

View File

@ -598,8 +598,9 @@ void gterm_putchar(uint8_t c) {
}
static bool last_serial = false;
static char *last_config = NULL;
bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
bool gterm_init(char *config, size_t *_rows, size_t *_cols, size_t width, size_t height) {
if (current_video_mode >= 0
#if bios == 1
&& current_video_mode != 0x03
@ -609,7 +610,8 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
&& height == 0
&& fbinfo.framebuffer_bpp == 32
&& !early_term
&& serial == last_serial) {
&& serial == last_serial
&& config == last_config) {
*_rows = rows;
*_cols = cols;
gterm_clear(true);
@ -624,7 +626,8 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
&& fbinfo.framebuffer_height == height
&& fbinfo.framebuffer_bpp == 32
&& !early_term
&& serial == last_serial) {
&& serial == last_serial
&& config == last_config) {
*_rows = rows;
*_cols = cols;
gterm_clear(true);
@ -655,7 +658,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
ansi_colours[6] = 0x0000aaaa; // cyan
ansi_colours[7] = 0x00aaaaaa; // grey
char *colours = config_get_value(NULL, 0, "TERM_PALETTE");
char *colours = config_get_value(config, 0, "TERM_PALETTE");
if (colours != NULL) {
const char *first = colours;
size_t i;
@ -680,7 +683,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
ansi_bright_colours[6] = 0x0055ffff; // cyan
ansi_bright_colours[7] = 0x00ffffff; // grey
char *bright_colours = config_get_value(NULL, 0, "TERM_PALETTE_BRIGHT");
char *bright_colours = config_get_value(config, 0, "TERM_PALETTE_BRIGHT");
if (bright_colours != NULL) {
const char *first = bright_colours;
size_t i;
@ -699,12 +702,12 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
default_bg = 0x00000000; // background (black)
default_fg = 0x00aaaaaa; // foreground (grey)
char *theme_background = config_get_value(NULL, 0, "TERM_BACKGROUND");
char *theme_background = config_get_value(config, 0, "TERM_BACKGROUND");
if (theme_background != NULL) {
default_bg = strtoui(theme_background, NULL, 16);
}
char *theme_foreground = config_get_value(NULL, 0, "TERM_FOREGROUND");
char *theme_foreground = config_get_value(config, 0, "TERM_FOREGROUND");
if (theme_foreground != NULL) {
default_fg = strtoui(theme_foreground, NULL, 16) & 0xffffff;
}
@ -713,7 +716,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
text_bg = 0xffffffff;
background = NULL;
char *background_path = config_get_value(NULL, 0, "TERM_WALLPAPER");
char *background_path = config_get_value(config, 0, "TERM_WALLPAPER");
if (background_path != NULL) {
struct file_handle *bg_file;
if ((bg_file = uri_open(background_path)) != NULL) {
@ -731,20 +734,20 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
}
}
char *theme_margin = config_get_value(NULL, 0, "TERM_MARGIN");
char *theme_margin = config_get_value(config, 0, "TERM_MARGIN");
if (theme_margin != NULL) {
margin = strtoui(theme_margin, NULL, 10);
}
char *theme_margin_gradient = config_get_value(NULL, 0, "TERM_MARGIN_GRADIENT");
char *theme_margin_gradient = config_get_value(config, 0, "TERM_MARGIN_GRADIENT");
if (theme_margin_gradient != NULL) {
margin_gradient = strtoui(theme_margin_gradient, NULL, 10);
}
if (background != NULL) {
char *background_layout = config_get_value(NULL, 0, "TERM_WALLPAPER_STYLE");
char *background_layout = config_get_value(config, 0, "TERM_WALLPAPER_STYLE");
if (background_layout != NULL && strcmp(background_layout, "centered") == 0) {
char *background_colour = config_get_value(NULL, 0, "TERM_BACKDROP");
char *background_colour = config_get_value(config, 0, "TERM_BACKDROP");
if (background_colour == NULL)
background_colour = "0";
uint32_t bg_col = strtoui(background_colour, NULL, 16);
@ -779,7 +782,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
size_t tmp_font_width, tmp_font_height;
char *menu_font_size = config_get_value(NULL, 0, "TERM_FONT_SIZE");
char *menu_font_size = config_get_value(config, 0, "TERM_FONT_SIZE");
if (menu_font_size != NULL) {
parse_resolution(&tmp_font_width, &tmp_font_height, NULL, menu_font_size);
@ -793,7 +796,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
font_bytes = tmp_font_bytes;
}
char *menu_font = config_get_value(NULL, 0, "TERM_FONT");
char *menu_font = config_get_value(config, 0, "TERM_FONT");
if (menu_font != NULL) {
struct file_handle *f;
if ((f = uri_open(menu_font)) == NULL) {
@ -810,7 +813,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
no_load_font:;
size_t font_spacing = 1;
char *font_spacing_str = config_get_value(NULL, 0, "TERM_FONT_SPACING");
char *font_spacing_str = config_get_value(config, 0, "TERM_FONT_SPACING");
if (font_spacing_str != NULL) {
font_spacing = strtoui(font_spacing_str, NULL, 10);
}
@ -852,7 +855,7 @@ no_load_font:;
vga_font_scale_x = 1;
vga_font_scale_y = 1;
char *menu_font_scale = config_get_value(NULL, 0, "TERM_FONT_SCALE");
char *menu_font_scale = config_get_value(config, 0, "TERM_FONT_SCALE");
if (menu_font_scale != NULL) {
parse_resolution(&vga_font_scale_x, &vga_font_scale_y, NULL, menu_font_scale);
if (vga_font_scale_x > 8 || vga_font_scale_y > 8) {

View File

@ -8,7 +8,7 @@
extern struct fb_info fbinfo;
bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height);
bool gterm_init(char *config, size_t *_rows, size_t *_cols, size_t width, size_t height);
void gterm_deinit(void);
void gterm_putchar(uint8_t c);

View File

@ -35,7 +35,7 @@ noreturn void panic(bool allow_menu, const char *fmt, ...) {
#endif
term_backend == NOT_READY) {
early_term = true;
term_vbe(0, 0);
term_vbe(NULL, 0, 0);
}
nested:

View File

@ -22,7 +22,7 @@ void term_deinit(void) {
term_notready();
}
void term_vbe(size_t width, size_t height) {
void term_vbe(char *config, size_t width, size_t height) {
if (term_backend != VBE) {
term_deinit();
}
@ -31,7 +31,7 @@ void term_vbe(size_t width, size_t height) {
return;
}
if (!gterm_init(&term_rows, &term_cols, width, height)) {
if (!gterm_init(config, &term_rows, &term_cols, width, height)) {
#if bios == 1
// Failed to set VBE properly, default to text mode
term_textmode();

View File

@ -55,7 +55,7 @@ void term_fallback(void);
void term_reinit(void);
void term_deinit(void);
void term_vbe(size_t width, size_t height);
void term_vbe(char *config, size_t width, size_t height);
void term_textmode(void);
void term_notready(void);
void term_putchar(uint8_t c);

View File

@ -644,7 +644,7 @@ static noreturn void _menu(bool timeout_enabled) {
randomise_mem_str = config_get_value(NULL, 0, "RANDOMIZE_MEMORY");
bool randomise_mem = randomise_mem_str != NULL && strcmp(randomise_mem_str, "yes") == 0;
if (randomise_mem) {
term_vbe(0, 0);
term_vbe(NULL, 0, 0);
early_term = true;
pmm_randomise_memory();
}
@ -715,7 +715,7 @@ reterm:
if (menu_resolution != NULL)
parse_resolution(&req_width, &req_height, &req_bpp, menu_resolution);
term_vbe(req_width, req_height);
term_vbe(NULL, req_width, req_height);
} else {
#if bios == 1
term_textmode();
@ -870,7 +870,7 @@ timeout_aborted:
goto refresh;
}
if (term_backend == NOT_READY) {
term_vbe(0, 0);
term_vbe(NULL, 0, 0);
#if bios == 1
if (term_backend == NOT_READY) {
term_textmode();

View File

@ -580,7 +580,12 @@ FEAT_START
quiet = false;
serial = false;
term_vbe(req_width, req_height);
char *term_conf_override_s = config_get_value(config, 0, "TERM_CONFIG_OVERRIDE");
if (term_conf_override_s != NULL && strcmp(term_conf_override_s, "yes") == 0) {
term_vbe(config, req_width, req_height);
} else {
term_vbe(NULL, req_width, req_height);
}
if (current_video_mode < 0) {
panic(true, "limine: Failed to initialise terminal");