Cleanup how boot modes are tracked

This commit is contained in:
K. Lange 2018-07-07 10:56:14 +09:00
parent 555b6fa027
commit 1cd6a5cb16
4 changed files with 39 additions and 24 deletions

View File

@ -246,7 +246,7 @@ run: image.iso
.PHONY: fast .PHONY: fast
fast: image.iso fast: image.iso
qemu-system-i386 -cdrom $< ${QEMU_ARGS} \ qemu-system-i386 -cdrom $< ${QEMU_ARGS} \
-fw_cfg name=opt/org.toaruos.bootmode,string=0 -fw_cfg name=opt/org.toaruos.bootmode,string=normal
.PHONY: headless .PHONY: headless
headless: image.iso headless: image.iso
@ -255,7 +255,7 @@ headless: image.iso
@echo "=== and type 'quit' to exit." @echo "=== and type 'quit' to exit."
qemu-system-i386 -cdrom $< ${QEMU_ARGS} \ qemu-system-i386 -cdrom $< ${QEMU_ARGS} \
-nographic \ -nographic \
-fw_cfg name=opt/org.toaruos.bootmode,string=3 -fw_cfg name=opt/org.toaruos.bootmode,string=headless
.PHONY: virtualbox .PHONY: virtualbox
VMNAME=ToaruOS-NIH CD VMNAME=ToaruOS-NIH CD

View File

@ -17,7 +17,11 @@ EFI_HANDLE ImageHandleIn;
#include "options.h" #include "options.h"
/* Basic text strings */ /* Basic text strings */
#define VERSION_TEXT "ToaruOS-NIH Bootloader v1.3" #ifdef EFI_PLATFORM
#define VERSION_TEXT "ToaruOS-NIH Bootloader v1.3 (EFI, IA32)"
#else
#define VERSION_TEXT "ToaruOS-NIH Bootloader v1.3 (BIOS)"
#endif
#define HELP_TEXT "Press <Enter> or select a menu option with \030/\031/\032/\033." #define HELP_TEXT "Press <Enter> or select a menu option with \030/\031/\032/\033."
#define COPYRIGHT_TEXT "ToaruOS is free software under the NCSA license." #define COPYRIGHT_TEXT "ToaruOS is free software under the NCSA license."
#define LINK_TEXT "https://toaruos.org - https://gitlab.com/toaruos" #define LINK_TEXT "https://toaruos.org - https://gitlab.com/toaruos"
@ -70,11 +74,13 @@ static char * modules[] = {
}; };
/* Names of the available boot modes. */ /* Names of the available boot modes. */
static char * boot_mode_names[] = { static struct bootmode boot_mode_names[] = {
"Normal Boot", {1, "normal", "Normal Boot"},
"VGA Text Mode", #ifndef EFI_PLATFORM
"Single-User Graphical Terminal", {2, "vga", "VGA Text Mode"},
"Headless", #endif
{3, "single", "Single-User Graphical Terminal"},
{4, "headless", "Headless"},
}; };
/* More bootloader implementation that depends on the module config */ /* More bootloader implementation that depends on the module config */
@ -155,15 +161,15 @@ int kmain() {
} }
} }
if (boot_mode == 0) { if (boot_mode == 1) {
strcat(cmdline, DEFAULT_GRAPHICAL_CMDLINE); strcat(cmdline, DEFAULT_GRAPHICAL_CMDLINE);
strcat(cmdline, DEFAULT_VID_CMDLINE); strcat(cmdline, DEFAULT_VID_CMDLINE);
} else if (boot_mode == 1) {
strcat(cmdline, DEFAULT_TEXT_CMDLINE);
} else if (boot_mode == 2) { } else if (boot_mode == 2) {
strcat(cmdline, DEFAULT_TEXT_CMDLINE);
} else if (boot_mode == 3) {
strcat(cmdline, DEFAULT_SINGLE_CMDLINE); strcat(cmdline, DEFAULT_SINGLE_CMDLINE);
strcat(cmdline, DEFAULT_VID_CMDLINE); strcat(cmdline, DEFAULT_VID_CMDLINE);
} else if (boot_mode == 3) { } else if (boot_mode == 4) {
strcat(cmdline, DEFAULT_HEADLESS_CMDLINE); strcat(cmdline, DEFAULT_HEADLESS_CMDLINE);
} }

View File

@ -361,18 +361,20 @@ void show_menu(void) {
} }
if (bootmode_index != -1) { if (bootmode_index != -1) {
if (bootmode_size != 1) { outports(0x510, bootmode_index);
print_("org.toaruos.bootmode must be one character"); char tmp[33] = {0};
} else { for (int i = 0; i < 32 && i < bootmode_size; ++i) {
outports(0x510, bootmode_index); tmp[i] = inportb(0x511);
char bootmode = inportb(0x511); }
if (bootmode < '0' || bootmode > '9') { for (int i = 0; i < BASE_SEL+1; ++i) {
print_("org.toaruos.bootmode must be a digit"); if (!strcmp(tmp,boot_mode_names[i].key)) {
} else { boot_mode = boot_mode_names[i].index;
boot_mode = bootmode - '0';
return; return;
} }
} }
print_("fw_cfg boot mode not recognized: ");
print_(tmp);
print_("\n");
} }
} }
#endif #endif
@ -412,7 +414,7 @@ void show_menu(void) {
print_(" "); print_(" ");
char tmp[] = {'0' + (i + 1), '.', ' ', '\0'}; char tmp[] = {'0' + (i + 1), '.', ' ', '\0'};
print_(tmp); print_(tmp);
print_(boot_mode_names[i]); print_(boot_mode_names[i].title);
print_("\n"); print_("\n");
} }
@ -463,7 +465,7 @@ void show_menu(void) {
} }
} else if (s == 0x1c) { } else if (s == 0x1c) {
if (sel <= BASE_SEL) { if (sel <= BASE_SEL) {
boot_mode = sel; boot_mode = boot_mode_names[sel].index;
break; break;
} else { } else {
int index = sel - BASE_SEL - 1; int index = sel - BASE_SEL - 1;
@ -472,7 +474,7 @@ void show_menu(void) {
} else if (s >= 2 && s <= 10) { } else if (s >= 2 && s <= 10) {
int i = s - 2; int i = s - 2;
if (i <= BASE_SEL) { if (i <= BASE_SEL) {
boot_mode = i; boot_mode = boot_mode_names[i].index;
break; break;
} }
#if 0 #if 0

View File

@ -35,4 +35,11 @@ static int _boot_offset = 0;
boot_options[_boot_offset].description_2 = d2; \ boot_options[_boot_offset].description_2 = d2; \
_boot_offset++ _boot_offset++
struct bootmode {
int index;
char * key;
char * title;
};
#define BASE_SEL ((sizeof(boot_mode_names)/sizeof(*boot_mode_names))-1) #define BASE_SEL ((sizeof(boot_mode_names)/sizeof(*boot_mode_names))-1)