Add boot menu

This commit is contained in:
mintsuki 2020-04-21 18:27:05 +02:00
parent 725a1fc186
commit 15c18d7642
5 changed files with 91 additions and 27 deletions

View File

@ -47,7 +47,7 @@ static void scroll(void) {
return;
}
static void text_clear(void) {
void text_clear(void) {
clear_cursor();
for (size_t i = 0; i < VIDEO_BOTTOM; i += 2) {
video_mem[i] = ' ';
@ -68,13 +68,13 @@ static void text_clear_no_move(void) {
return;
}
static void text_enable_cursor(void) {
void text_enable_cursor(void) {
cursor_status = 1;
draw_cursor();
return;
}
static void text_disable_cursor(void) {
void text_disable_cursor(void) {
cursor_status = 0;
clear_cursor();
return;

View File

@ -11,4 +11,8 @@ void text_write(const char *, size_t);
void text_get_cursor_pos(int *x, int *y);
void text_set_cursor_pos(int x, int y);
void text_clear(void);
void text_enable_cursor(void);
void text_disable_cursor(void);
#endif

View File

@ -61,15 +61,15 @@ int config_set_entry(size_t index) {
return -1;
p++;
}
p++;
}
p++;
config_addr = p;
while (*config_addr != ':' && *config_addr)
config_addr++;
while (*p != ':' && *p)
p++;
*config_addr = 0;
*p = 0;
return 0;
}

View File

@ -17,6 +17,59 @@ asm (
#include <protos/stivale.h>
#include <protos/linux.h>
static char cmdline[128];
void boot_menu(void) {
text_disable_cursor();
int selected_entry = 0;
refresh:
text_clear();
print("qloader2\n\n");
print("Select an entry:\n\n");
size_t max_entries;
for (max_entries = 0; ; max_entries++) {
char buf[32];
if (config_get_entry_name(buf, max_entries, 32) == -1)
break;
if (max_entries == selected_entry)
print(" -> %s\n", buf);
else
print(" %s\n", buf);
}
print("\nArrows to choose, enter to select, 'e' to edit command line.");
for (;;) {
int c = getchar();
switch (c) {
case GETCHAR_CURSOR_UP:
if (--selected_entry == -1)
selected_entry = max_entries - 1;
goto refresh;
case GETCHAR_CURSOR_DOWN:
if (++selected_entry == max_entries)
selected_entry = 0;
goto refresh;
case '\r':
config_set_entry(selected_entry);
text_enable_cursor();
text_clear();
return;
case 'e':
config_set_entry(selected_entry);
text_enable_cursor();
config_get_value(cmdline, 0, 128, "KERNEL_CMDLINE");
print("\n\n> ");
gets(cmdline, cmdline, 128);
text_clear();
return;
}
}
}
extern symbol bss_begin;
extern symbol bss_end;
@ -32,7 +85,7 @@ void main(int boot_drive) {
init_idt();
print("qLoader 2\n\n");
print("qloader2\n\n");
print("Boot drive: %x\n", boot_drive);
// Look for config file.
@ -55,37 +108,42 @@ void main(int boot_drive) {
}
}
int drive, part, timeout;
char path[128], cmdline[128], proto[64], buf[32];
int drive, part;
char path[128], proto[64], buf[32];
int timeout;
if (!config_get_value(buf, 0, 64, "TIMEOUT")) {
timeout = 5;
} else {
timeout = (int)strtoui(buf);
}
print("\n");
for (int i = timeout; i; i--) {
print("\rBooting in %d (press any key for boot menu, command line edit)...", i);
if (pit_sleep_and_quit_on_keypress(18)) {
boot_menu();
goto got_entry;
}
}
print("\n\n");
if (config_set_entry(0) == -1) {
panic("Invalid config entry.");
}
got_entry:
if (!config_get_value(buf, 0, 32, "KERNEL_DRIVE")) {
print("KERNEL_DRIVE not specified, using boot drive (%x)", boot_drive);
drive = boot_drive;
} else {
drive = (int)strtoui(buf);
}
if (!config_get_value(buf, 0, 64, "TIMEOUT")) {
timeout = 5;
} else {
timeout = (int)strtoui(buf);
}
config_get_value(buf, 0, 32, "KERNEL_PARTITION");
part = (int)strtoui(buf);
config_get_value(path, 0, 128, "KERNEL_PATH");
config_get_value(cmdline, 0, 128, "KERNEL_CMDLINE");
config_get_value(proto, 0, 64, "KERNEL_PROTO");
print("\n\n");
for (int i = timeout; i; i--) {
print("\rBooting in %d (press any key to edit command line)...", i);
if (pit_sleep_and_quit_on_keypress(18)) {
print("\n\n> ");
gets(cmdline, cmdline, 128);
break;
}
}
print("\n\n");
fopen(&f, drive, part, path);
if (!strcmp(proto, "stivale")) {

View File

@ -1,5 +1,7 @@
TIMEOUT=3
:Test kernel
KERNEL_PARTITION=1
KERNEL_PATH=/boot/test.elf
KERNEL_PROTO=stivale