:: commit 569df8aca8fd4b218dd83e286ff4730ef690bfff

mintsuki <mintsuki@protonmail.com> — 2020-11-01 09:31

parents: 849d05c757

Use URIs everywhere, update config documentation. Fixes #48

diff --git a/CONFIG.md b/CONFIG.md
index 9160561b..5a4e2fd7 100644
--- a/CONFIG.md
+++ b/CONFIG.md
@@ -19,6 +19,8 @@ although usually one would put them at the beginning of the config.
 Some *local assignments* are shared between entries using any *protocol*, while other
 *local assignments* are specific to a given *protocol*.
 
+Some keys take *URIs* as values; these are described in the next section.
+
 *Globally assignable* keys are:
 * `TIMEOUT` - Specifies the timeout in seconds before the first *entry* is automatically booted.
 * `DEFAULT_ENTRY` - 0-based entry index of the entry which will be automatically selected at startup. If unspecified, it is `0`.
@@ -27,33 +29,37 @@ Some *local assignments* are shared between entries using any *protocol*, while
 * `THEME_MARGIN` - Set the amount of margin around the terminal. Ignored if `GRAPHICS` is not `yes`.
 * `THEME_MARGIN_GRADIENT` - Set the thickness in pixel for the gradient around the terminal. Ignored if `GRAPHICS` is not `yes`.
 * `BACKGROUND_DRIVE` - Drive where to find the background .BMP file. Assume boot drive if unspecified. Ignored if `GRAPHICS` is not `yes`.
-* `BACKGROUND_PARTITION` - Partition where to find the background .BMP file. Ignored if `GRAPHICS` is not `yes`.
 * `BACKGROUND_PATH` - Path where to find the background .BMP file. Ignored if `GRAPHICS` is not `yes`.
 
 *Locally assignable (non protocol specific)* keys are:
 * `PROTOCOL` - The boot protocol that will be used to boot the kernel. Valid protocols are: `linux`, `stivale`, `stivale2`, `chainload`.
-* `KERNEL_PROTO` - Alias of `PROTOCOL`.
 * `CMDLINE` - The command line string to be passed to the kernel. Can be omitted.
 * `KERNEL_CMDLINE` - Alias of `CMDLINE`.
 
 *Locally assignable (protocol specific)* keys are:
 * Linux protocol:
-  * `KERNEL_DRIVE` - The BIOS drive (in decimal) where the kernel resides (if unspecified, boot drive is assumed).
-  * `KERNEL_PARTITION` - The index (in decimal) of the partition containing the kernel.
-  * `KERNEL_PATH` - The path of the kernel in said partition, forward slashes to delimit directories.
-  * `INITRD_PARTITION` - Partition index of the initial ramdisk.
-  * `INITRD_PATH` - The path to the initial ramdisk.
+  * `KERNEL_PATH` - The URI path of the kernel.
+  * `INITRD_PATH` - The URI path to the initial ramdisk.
 * stivale and stivale2 protocols:
-  * `KERNEL_DRIVE` - The BIOS drive (in decimal) where the kernel resides (if unspecified, boot drive is assumed).
-  * `KERNEL_PARTITION` - The index (in decimal) of the partition containing the kernel.
-  * `KERNEL_PATH` - The path of the kernel in said partition, forward slashes to delimit directories.
-  * `MODULE_PARTITION` - Partition index of a module.
-  * `MODULE_PATH` - The path to a module.
+  * `KERNEL_PATH` - The URI path of the kernel.
+  * `MODULE_PATH` - The URI path to a module.
   * `MODULE_STRING` - A string to be passed to a module.
 * Chainload protocol:
-  * `DRIVE` - The BIOS drive (in decimal) to chainload.
-  * `PARTITION` - The partition index (in decimal) to chainload (if omitted, chainload the drive's bootsector).
+  * `DRIVE` - The URI to a drive to chainload.
 
   Note that one can define these 3 variable multiple times to specify multiple modules.
   The entries will be matched in order. E.g.: the 1st partition entry will be matched
   to the 1st path and the 1st string entry that appear, and so on.
+
+## URIs
+
+A URI is a path that Limine uses to locate resources in the whole system. It is
+comprised of a *resource*, a *root*, and a *path*. It takes the form of:
+```
+resource://root/path
+```
+
+The format for `root` changes depending on the resource used.
+
+A resource can be one of the following:
+* `bios` - The `root` takes the form of `drive:partition`; for example: `bios://3:1/...` would use BIOS drive 3, partition 1. Partitions and BIOS drives are both 1-based. Omitting the drive is possible; for example: `bios://:2/...`. Omitting the drive makes Limine use the boot drive.
diff --git a/limine.bin b/limine.bin
index aaee5376..2fa7e59f 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2/lib/blib.c b/stage2/lib/blib.c
index 6c8db7c6..3f48c23d 100644
--- a/stage2/lib/blib.c
+++ b/stage2/lib/blib.c
@@ -23,10 +23,14 @@ static bool parse_bios_partition(char *loc, uint8_t *drive, uint8_t *partition)
 
         if (loc[i] == ':') {
             loc[i] = 0;
-            if (*loc == 0)
+            if (*loc == 0) {
                 *drive = boot_drive;
-            else
-                *drive = strtoui(loc);
+            } else {
+                if (strtoui(loc) < 1 || strtoui(loc) > 16) {
+                    panic("BIOS drive number outside range 1-16");
+                }
+                *drive = (strtoui(loc) - 1) + 0x80;
+            }
             loc += i + 1;
             break;
         }
@@ -35,7 +39,10 @@ static bool parse_bios_partition(char *loc, uint8_t *drive, uint8_t *partition)
     if (*loc == 0)
         return false;
 
-    *partition = strtoui(loc);
+    if (strtoui(loc) < 1 || strtoui(loc) > 256) {
+        panic("BIOS partition number outside range 1-256");
+    }
+    *partition = strtoui(loc) - 1;
 
     return true;
 }
diff --git a/stage2/main.c b/stage2/main.c
index ae754e1d..6a0107ef 100644
--- a/stage2/main.c
+++ b/stage2/main.c
@@ -60,10 +60,8 @@ void entry(uint8_t _boot_drive) {
     char *cmdline = menu(boot_drive);
 
     char proto[32];
-    if (!config_get_value(proto, 0, 32, "KERNEL_PROTO")) {
-        if (!config_get_value(proto, 0, 32, "PROTOCOL")) {
-            panic("PROTOCOL not specified");
-        }
+    if (!config_get_value(proto, 0, 32, "PROTOCOL")) {
+        panic("PROTOCOL not specified");
     }
 
     if (!strcmp(proto, "stivale")) {
diff --git a/stage2/protos/linux.c b/stage2/protos/linux.c
index d525dc74..62261882 100644
--- a/stage2/protos/linux.c
+++ b/stage2/protos/linux.c
@@ -130,19 +130,9 @@ void linux_load(char *cmdline) {
     if (!config_get_value(initrd_path, 0, 64, "INITRD_PATH"))
         panic("INITRD_PATH not specified");
 
-    int initrd_part; {
-        char buf[32];
-        if (!config_get_value(buf, 0, 32, "INITRD_PARTITION")) {
-            initrd_part = kernel->partition;
-        } else {
-            initrd_part = (int)strtoui(buf);
-        }
-    }
-
     struct file_handle initrd;
-    if (fopen(&initrd, kernel->disk, initrd_part, initrd_path)) {
-        panic("Failed to open initrd");
-    }
+    if (!uri_open(&initrd, initrd_path))
+        panic("Could not open initrd");
 
     print("Loading initrd...\n");
     memmap_alloc_range(INITRD_LOAD_ADDR, initrd.size, 0);
diff --git a/stage2/protos/stivale.c b/stage2/protos/stivale.c
index 50cbeb23..cdbd144c 100644
--- a/stage2/protos/stivale.c
+++ b/stage2/protos/stivale.c
@@ -129,19 +129,9 @@ void stivale_load(char *cmdline) {
             m->string[0] = '\0';
         }
 
-        int part; {
-            char buf[32];
-            if (!config_get_value(buf, i, 32, "MODULE_PARTITION")) {
-                part = kernel->partition;
-            } else {
-                part = (int)strtoui(buf);
-            }
-        }
-
         struct file_handle f;
-        if (fopen(&f, kernel->disk, part, module_file)) {
+        if (!uri_open(&f, module_file))
             panic("Requested module with path \"%s\" not found!\n", module_file);
-        }
 
         void *module_addr = (void *)(((uint32_t)top_used_addr & 0xfff) ?
             ((uint32_t)top_used_addr & ~((uint32_t)0xfff)) + 0x1000 :
diff --git a/stage2/protos/stivale2.c b/stage2/protos/stivale2.c
index 6aedbd05..59708522 100644
--- a/stage2/protos/stivale2.c
+++ b/stage2/protos/stivale2.c
@@ -181,19 +181,9 @@ void stivale2_load(char *cmdline) {
             m->string[0] = '\0';
         }
 
-        int part; {
-            char buf[32];
-            if (!config_get_value(buf, i, 32, "MODULE_PARTITION")) {
-                part = kernel->partition;
-            } else {
-                part = (int)strtoui(buf);
-            }
-        }
-
         struct file_handle f;
-        if (fopen(&f, kernel->disk, part, module_file)) {
+        if (uri_open(&f, module_file))
             panic("Requested module with path \"%s\" not found!\n", module_file);
-        }
 
         void *module_addr = (void *)(((uint32_t)top_used_addr & 0xfff) ?
             ((uint32_t)top_used_addr & ~((uint32_t)0xfff)) + 0x1000 :
diff --git a/test/limine.cfg b/test/limine.cfg
index 330d0549..e1d7cf7a 100644
--- a/test/limine.cfg
+++ b/test/limine.cfg
@@ -20,11 +20,11 @@ BACKGROUND_PATH=bg.bmp
 :Stivale Test
 
 PROTOCOL=stivale
-KERNEL_PATH=bios://:0/boot/test.elf
+KERNEL_PATH=bios://:1/boot/test.elf
 KERNEL_CMDLINE=Hi! This is an example!
 
 :Stivale2 Test
 
 PROTOCOL=stivale2
-KERNEL_PATH=bios://:0/boot/test.elf
+KERNEL_PATH=bios://:1/boot/test.elf
 KERNEL_CMDLINE=Woah! Another example!
tab: 248 wrap: offon