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

View File

@ -17,7 +17,11 @@ EFI_HANDLE ImageHandleIn;
#include "options.h"
/* 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 COPYRIGHT_TEXT "ToaruOS is free software under the NCSA license."
#define LINK_TEXT "https://toaruos.org - https://gitlab.com/toaruos"
@ -70,11 +74,13 @@ static char * modules[] = {
};
/* Names of the available boot modes. */
static char * boot_mode_names[] = {
"Normal Boot",
"VGA Text Mode",
"Single-User Graphical Terminal",
"Headless",
static struct bootmode boot_mode_names[] = {
{1, "normal", "Normal Boot"},
#ifndef EFI_PLATFORM
{2, "vga", "VGA Text Mode"},
#endif
{3, "single", "Single-User Graphical Terminal"},
{4, "headless", "Headless"},
};
/* 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_VID_CMDLINE);
} else if (boot_mode == 1) {
strcat(cmdline, DEFAULT_TEXT_CMDLINE);
} else if (boot_mode == 2) {
strcat(cmdline, DEFAULT_TEXT_CMDLINE);
} else if (boot_mode == 3) {
strcat(cmdline, DEFAULT_SINGLE_CMDLINE);
strcat(cmdline, DEFAULT_VID_CMDLINE);
} else if (boot_mode == 3) {
} else if (boot_mode == 4) {
strcat(cmdline, DEFAULT_HEADLESS_CMDLINE);
}

View File

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

View File

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