Add boot menu
diff --git a/src/drivers/vga_textmode.c b/src/drivers/vga_textmode.c
index a09b166d..3f78705c 100644
--- a/src/drivers/vga_textmode.c
+++ b/src/drivers/vga_textmode.c
@@ -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;
diff --git a/src/drivers/vga_textmode.h b/src/drivers/vga_textmode.h
index 044da5a7..310badf0 100644
--- a/src/drivers/vga_textmode.h
+++ b/src/drivers/vga_textmode.h
@@ -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
diff --git a/src/lib/config.c b/src/lib/config.c
index f6000358..26a33ac9 100644
--- a/src/lib/config.c
+++ b/src/lib/config.c
@@ -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;
}
diff --git a/src/main.c b/src/main.c
index 4afcc2d8..b703986a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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];
- 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);
- }
+ int timeout;
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");
+ print("\n");
for (int i = timeout; i; i--) {
- print("\rBooting in %d (press any key to edit command line)...", i);
+ print("\rBooting in %d (press any key for boot menu, command line edit)...", i);
if (pit_sleep_and_quit_on_keypress(18)) {
- print("\n\n> ");
- gets(cmdline, cmdline, 128);
- break;
+ 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);
+ }
+ config_get_value(buf, 0, 32, "KERNEL_PARTITION");
+ part = (int)strtoui(buf);
+ config_get_value(path, 0, 128, "KERNEL_PATH");
+ config_get_value(proto, 0, 64, "KERNEL_PROTO");
+
fopen(&f, drive, part, path);
if (!strcmp(proto, "stivale")) {
diff --git a/test/qloader2.cfg b/test/qloader2.cfg
index 0af6b557..24dfec9f 100644
--- a/test/qloader2.cfg
+++ b/test/qloader2.cfg
@@ -1,5 +1,7 @@
TIMEOUT=3
+:Test kernel
+
KERNEL_PARTITION=1
KERNEL_PATH=/boot/test.elf
KERNEL_PROTO=stivale
