:: commit 18bfa311de8265f942899a5647871bd8483ed306

mintsuki <mintsuki@protonmail.com> — 2020-12-31 02:26

parents: 366d75e740

misc: Replace conv_mem_alloc() with ext_mem_alloc() where it made sense to do so

diff --git a/limine-pxe.bin b/limine-pxe.bin
index e8f7ca08..a72994ff 100644
Binary files a/limine-pxe.bin and b/limine-pxe.bin differ
diff --git a/limine.bin b/limine.bin
index f11c5e97..5ffe91c5 100644
Binary files a/limine.bin and b/limine.bin differ
diff --git a/stage2.map b/stage2.map
index 80962933..ec71a10c 100644
Binary files a/stage2.map and b/stage2.map differ
diff --git a/stage2/fs/echfs.c b/stage2/fs/echfs.c
index ab9cadd5..e7f3c2b0 100644
--- a/stage2/fs/echfs.c
+++ b/stage2/fs/echfs.c
@@ -131,7 +131,7 @@ found:;
     // Load the allocation map.
     uint64_t file_block_count = DIV_ROUNDUP(ret->dir_entry.size, ret->block_size);
 
-    ret->alloc_map = conv_mem_alloc(file_block_count * sizeof(uint64_t));
+    ret->alloc_map = ext_mem_alloc(file_block_count * sizeof(uint64_t));
 
     ret->alloc_map[0] = ret->dir_entry.payload;
     for (uint64_t i = 1; i < file_block_count; i++) {
diff --git a/stage2/fs/ext2.c b/stage2/fs/ext2.c
index b90fc110..80f9ff81 100644
--- a/stage2/fs/ext2.c
+++ b/stage2/fs/ext2.c
@@ -356,7 +356,7 @@ static struct ext4_extent_header* ext4_find_leaf(struct ext4_extent_header* ext_
 

         uint64_t block = ((uint64_t)index[i].leaf_hi << 32) | index[i].leaf;

         if(!buf)

-            buf = conv_mem_alloc(block_size);

+            buf = ext_mem_alloc(block_size);

         part_read(part, buf, (block * block_size), block_size);

         ext_block = buf;

     }

diff --git a/stage2/fs/file.c b/stage2/fs/file.c
index cfd04e7c..22c6fadb 100644
--- a/stage2/fs/file.c
+++ b/stage2/fs/file.c
@@ -21,7 +21,7 @@ bool fs_get_guid(struct guid *guid, struct part *part) {
 
 int fopen(struct file_handle *ret, struct part *part, const char *filename) {
     if (echfs_check_signature(part)) {
-        struct echfs_file_handle *fd = conv_mem_alloc(sizeof(struct echfs_file_handle));
+        struct echfs_file_handle *fd = ext_mem_alloc(sizeof(struct echfs_file_handle));
 
         int r = echfs_open(fd, part, filename);
         if (r)
@@ -36,7 +36,7 @@ int fopen(struct file_handle *ret, struct part *part, const char *filename) {
     }
 
     if (ext2_check_signature(part)) {
-        struct ext2_file_handle *fd = conv_mem_alloc(sizeof(struct ext2_file_handle));
+        struct ext2_file_handle *fd = ext_mem_alloc(sizeof(struct ext2_file_handle));
 
         int r = ext2_open(fd, part, filename);
         if (r)
@@ -51,7 +51,7 @@ int fopen(struct file_handle *ret, struct part *part, const char *filename) {
     }
 
     if (fat32_check_signature(part)) {
-        struct fat32_file_handle *fd = conv_mem_alloc(sizeof(struct fat32_file_handle));
+        struct fat32_file_handle *fd = ext_mem_alloc(sizeof(struct fat32_file_handle));
 
         int r = fat32_open(fd, part, filename);
 
diff --git a/stage2/lib/config.c b/stage2/lib/config.c
index 456808cf..3ea37c38 100644
--- a/stage2/lib/config.c
+++ b/stage2/lib/config.c
@@ -27,7 +27,7 @@ int init_config_disk(struct part *part) {
     }
 
     size_t config_size = f.size + 1;
-    config_addr = conv_mem_alloc(config_size);
+    config_addr = ext_mem_alloc(config_size);
 
     fread(&f, config_addr, 0, f.size);
 
@@ -40,7 +40,7 @@ int init_config_pxe(void) {
      && tftp_open(&cfg, 0, 69, "tomatboot.cfg")) {
         return -1;
     }
-    config_addr = conv_mem_alloc(cfg.file_size);
+    config_addr = ext_mem_alloc(cfg.file_size);
     tftp_read(&cfg, config_addr, 0, cfg.file_size);
 
     print("\nconfig: %s\n", config_addr);
@@ -95,7 +95,7 @@ static struct menu_entry *create_menu_tree(struct menu_entry *parent,
                 break;
         }
 
-        struct menu_entry *entry = conv_mem_alloc(sizeof(struct menu_entry));
+        struct menu_entry *entry = ext_mem_alloc(sizeof(struct menu_entry));
 
         if (root == NULL)
             root = entry;
@@ -113,7 +113,7 @@ static struct menu_entry *create_menu_tree(struct menu_entry *parent,
         } else {
             size_t entry_size;
             char *config_entry = config_get_entry(&entry_size, i);
-            entry->body = conv_mem_alloc(entry_size + 1);
+            entry->body = ext_mem_alloc(entry_size + 1);
             memcpy(entry->body, config_entry, entry_size);
             entry->body[entry_size] = 0;
         }
diff --git a/stage2/lib/uri.c b/stage2/lib/uri.c
index 9e4b558f..f123253b 100644
--- a/stage2/lib/uri.c
+++ b/stage2/lib/uri.c
@@ -14,7 +14,7 @@
 // The following function splits up a URI into its componenets
 bool uri_resolve(char *uri, char **resource, char **root, char **path) {
     size_t length = strlen(uri) + 1;
-    char *buf = conv_mem_alloc(length);
+    char *buf = ext_mem_alloc(length);
     memcpy(buf, uri, length);
     uri = buf;
 
diff --git a/stage2/protos/linux.c b/stage2/protos/linux.c
index 545abbe6..8fc5ad69 100644
--- a/stage2/protos/linux.c
+++ b/stage2/protos/linux.c
@@ -62,7 +62,7 @@ void linux_load(char *config, char *cmdline) {
     char *cmdline_reloc = conv_mem_alloc(cmdline_len + 1);
     strcpy(cmdline_reloc, cmdline);
 
-    struct file_handle *kernel = conv_mem_alloc(sizeof(struct file_handle));
+    struct file_handle *kernel = ext_mem_alloc(sizeof(struct file_handle));
 
     char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
     if (kernel_path == NULL)
diff --git a/stage2/protos/stivale.c b/stage2/protos/stivale.c
index 72bf4698..ad826b46 100644
--- a/stage2/protos/stivale.c
+++ b/stage2/protos/stivale.c
@@ -30,7 +30,7 @@ void stivale_load(char *config, char *cmdline) {
     stivale_struct.flags |= (1 << 0);  // set bit 0 since we are BIOS and not UEFI
     stivale_struct.flags |= (1 << 1);  // we give colour information
 
-    struct file_handle *kernel = conv_mem_alloc(sizeof(struct file_handle));
+    struct file_handle *kernel = ext_mem_alloc(sizeof(struct file_handle));
 
     char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
     if (kernel_path == NULL)
@@ -121,7 +121,7 @@ void stivale_load(char *config, char *cmdline) {
 
         stivale_struct.module_count++;
 
-        struct stivale_module *m = conv_mem_alloc(sizeof(struct stivale_module));
+        struct stivale_module *m = ext_mem_alloc(sizeof(struct stivale_module));
 
         char *module_string = config_get_value(config, i, "MODULE_STRING");
         if (module_string == NULL) {
@@ -229,7 +229,7 @@ pagemap_t stivale_build_pagemap(bool level5pg) {
 
     size_t _memmap_entries = memmap_entries;
     struct e820_entry_t *_memmap =
-        conv_mem_alloc(_memmap_entries * sizeof(struct e820_entry_t));
+        ext_mem_alloc(_memmap_entries * sizeof(struct e820_entry_t));
     for (size_t i = 0; i < _memmap_entries; i++)
         _memmap[i] = memmap[i];
 
diff --git a/stage2/protos/stivale2.c b/stage2/protos/stivale2.c
index 624ebcae..9527564c 100644
--- a/stage2/protos/stivale2.c
+++ b/stage2/protos/stivale2.c
@@ -51,7 +51,7 @@ static void append_tag(struct stivale2_struct *s, struct stivale2_tag *tag) {
 }
 
 void stivale2_load(char *config, char *cmdline, bool pxe) {
-    struct file_handle *kernel = conv_mem_alloc(sizeof(struct file_handle));
+    struct file_handle *kernel = ext_mem_alloc(sizeof(struct file_handle));
 
     char *kernel_path = config_get_value(config, 0, "KERNEL_PATH");
     if (kernel_path == NULL)
@@ -140,7 +140,7 @@ void stivale2_load(char *config, char *cmdline, bool pxe) {
     // Create firmware struct tag
     //////////////////////////////////////////////
     {
-    struct stivale2_struct_tag_firmware *tag = conv_mem_alloc(sizeof(struct stivale2_struct_tag_firmware));
+    struct stivale2_struct_tag_firmware *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_firmware));
     tag->tag.identifier = STIVALE2_STRUCT_TAG_FIRMWARE_ID;
 
     tag->flags = 1 << 0;   // bit 0 = BIOS boot
@@ -160,8 +160,8 @@ void stivale2_load(char *config, char *cmdline, bool pxe) {
     }
 
     struct stivale2_struct_tag_modules *tag =
-        conv_mem_alloc(sizeof(struct stivale2_struct_tag_modules)
-                     + sizeof(struct stivale2_module) * module_count);
+        ext_mem_alloc(sizeof(struct stivale2_struct_tag_modules)
+                    + sizeof(struct stivale2_module) * module_count);
 
     tag->tag.identifier = STIVALE2_STRUCT_TAG_MODULES_ID;
     tag->module_count   = module_count;
@@ -214,7 +214,7 @@ void stivale2_load(char *config, char *cmdline, bool pxe) {
     // Create RSDP struct tag
     //////////////////////////////////////////////
     {
-    struct stivale2_struct_tag_rsdp *tag = conv_mem_alloc(sizeof(struct stivale2_struct_tag_rsdp));
+    struct stivale2_struct_tag_rsdp *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_rsdp));
     tag->tag.identifier = STIVALE2_STRUCT_TAG_RSDP_ID;
 
     tag->rsdp = (uint64_t)(size_t)acpi_get_rsdp();
@@ -226,7 +226,7 @@ void stivale2_load(char *config, char *cmdline, bool pxe) {
     // Create cmdline struct tag
     //////////////////////////////////////////////
     {
-    struct stivale2_struct_tag_cmdline *tag = conv_mem_alloc(sizeof(struct stivale2_struct_tag_cmdline));
+    struct stivale2_struct_tag_cmdline *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_cmdline));
     tag->tag.identifier = STIVALE2_STRUCT_TAG_CMDLINE_ID;
 
     tag->cmdline = (uint64_t)(size_t)cmdline;
@@ -238,7 +238,7 @@ void stivale2_load(char *config, char *cmdline, bool pxe) {
     // Create epoch struct tag
     //////////////////////////////////////////////
     {
-    struct stivale2_struct_tag_epoch *tag = conv_mem_alloc(sizeof(struct stivale2_struct_tag_epoch));
+    struct stivale2_struct_tag_epoch *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_epoch));
     tag->tag.identifier = STIVALE2_STRUCT_TAG_EPOCH_ID;
 
     tag->epoch = time();
@@ -266,7 +266,7 @@ void stivale2_load(char *config, char *cmdline, bool pxe) {
 
         struct vbe_framebuffer_info fbinfo;
         if (init_vbe(&fbinfo, req_width, req_height, req_bpp)) {
-            struct stivale2_struct_tag_framebuffer *tag = conv_mem_alloc(sizeof(struct stivale2_struct_tag_framebuffer));
+            struct stivale2_struct_tag_framebuffer *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_framebuffer));
             tag->tag.identifier = STIVALE2_STRUCT_TAG_FRAMEBUFFER_ID;
 
             tag->memory_model       = STIVALE2_FBUF_MMODEL_RGB;
@@ -320,14 +320,14 @@ void stivale2_load(char *config, char *cmdline, bool pxe) {
     }
     }
 
-    print("Generated tags:\n");
-    struct stivale2_tag *taglist = (void*)(size_t)stivale2_struct.tags;
-    for (size_t i = 0; ; i++) {
-        print("Tag #%u  ID: %X\n", i, taglist->identifier);
-        if (taglist->next)
-            taglist = (void*)(size_t)taglist->next;
-        else
-            break;
+    //////////////////////////////////////////////
+    // Create PXE struct tag
+    //////////////////////////////////////////////
+    if (pxe) {
+        struct stivale2_struct_tag_pxe_server_info *tag = ext_mem_alloc(sizeof(struct stivale2_struct_tag_pxe_server_info));
+        tag->tag.identifier = STIVALE2_STRUCT_TAG_PXE_SERVER_INFO;
+        tag->server_ip = get_boot_server_info();
+        append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
     }
 
     //////////////////////////////////////////////
@@ -350,13 +350,17 @@ void stivale2_load(char *config, char *cmdline, bool pxe) {
     append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
     }
 
-    {
-        if (pxe) {
-            struct stivale2_struct_tag_pxe_server_info *tag = conv_mem_alloc(sizeof(struct stivale2_struct_tag_pxe_server_info));
-            tag->tag.identifier = STIVALE2_STRUCT_TAG_PXE_SERVER_INFO;
-            tag->server_ip = get_boot_server_info();
-            append_tag(&stivale2_struct, (struct stivale2_tag *)tag);
-        }
+    //////////////////////////////////////////////
+    // List tags
+    //////////////////////////////////////////////
+    print("Generated tags:\n");
+    struct stivale2_tag *taglist = (void*)(size_t)stivale2_struct.tags;
+    for (size_t i = 0; ; i++) {
+        print("Tag #%u  ID: %X\n", i, taglist->identifier);
+        if (taglist->next)
+            taglist = (void*)(size_t)taglist->next;
+        else
+            break;
     }
 
     stivale_spinup(bits, level5pg && level5pg_requested, pagemap,
tab: 248 wrap: offon