:: commit ad3e17569c9886810c0a75d6e42b040b8ff74d66

mintsuki <mintsuki@protonmail.com> — 2021-11-24 11:24

parents: 5555af6641

stivale2: Implement boot volume struct tag

diff --git a/stage23/fs/file.h b/stage23/fs/file.h
index bfd3c0ee..50a61e86 100644
--- a/stage23/fs/file.h
+++ b/stage23/fs/file.h
@@ -14,6 +14,7 @@ bool fs_get_guid(struct guid *guid, struct volume *part);
 struct file_handle {
     bool       is_memfile;
     bool       readall;
+    struct volume *vol;
     void      *fd;
     void     (*read)(void *fd, void *buf, uint64_t loc, uint64_t count);
     void     (*close)(void *fd);
diff --git a/stage23/fs/file.s2.c b/stage23/fs/file.s2.c
index 0ed22641..7e70b065 100644
--- a/stage23/fs/file.s2.c
+++ b/stage23/fs/file.s2.c
@@ -30,6 +30,8 @@ struct file_handle *fopen(struct volume *part, const char *filename) {
     ret->is_memfile = false;
     ret->readall = false;
 
+    ret->vol = part;
+
 #if bios == 1
     if (part->pxe) {
         if (!tftp_open(ret, 0, 69, filename)) {
diff --git a/stage23/lib/guid.h b/stage23/lib/guid.h
index dbb514c7..a4ce1557 100644
--- a/stage23/lib/guid.h
+++ b/stage23/lib/guid.h
@@ -9,7 +9,7 @@ struct guid {
     uint16_t b;
     uint16_t c;
     uint8_t  d[8];
-} __attribute__((packed));
+};
 
 bool is_valid_guid(const char *s);
 bool string_to_guid_be(struct guid *guid, const char *s);
diff --git a/stage23/protos/stivale2.c b/stage23/protos/stivale2.c
index 5116dcba..f36be7e6 100644
--- a/stage23/protos/stivale2.c
+++ b/stage23/protos/stivale2.c
@@ -107,6 +107,8 @@ void stivale2_load(char *config, char *cmdline) {
 
     size_t kernel_file_size = kernel_file->size;
 
+    struct volume *kernel_volume = kernel_file->vol;
+
     fclose(kernel_file);
 
     if (bits == -1) {
@@ -238,6 +240,26 @@ failed_to_load_header_section:
     strcpy(stivale2_struct.bootloader_brand, "Limine");
     strcpy(stivale2_struct.bootloader_version, LIMINE_VERSION);
 
+    //////////////////////////////////////////////
+    // Create boot volume tag
+    //////////////////////////////////////////////
+    {
+    struct stivale2_struct_tag_boot_volume *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_boot_volume));
+    tag->tag.identifier = STIVALE2_STRUCT_TAG_BOOT_VOLUME_ID;
+
+    if (kernel_volume->guid_valid) {
+        tag->flags |= (1 << 0);
+        memcpy(&tag->guid, &kernel_volume->guid, sizeof(struct stivale2_guid));
+    }
+
+    if (kernel_volume->part_guid_valid) {
+        tag->flags |= (1 << 1);
+        memcpy(&tag->part_guid, &kernel_volume->part_guid, sizeof(struct stivale2_guid));
+    }
+
+    append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
+    }
+
     //////////////////////////////////////////////
     // Create kernel file struct tag
     //////////////////////////////////////////////
tab: 248 wrap: offon