:: commit 760e1b20c4fa9caa965964496ea61c060e411858

mintsuki <mintsuki@protonmail.com> — 2021-12-12 17:40

parents: 13974faced

misc: Unwind both .data and .bss

diff --git a/stage23/entry.s2.c b/stage23/entry.s2.c
index 5a608194..21544b05 100644
--- a/stage23/entry.s2.c
+++ b/stage23/entry.s2.c
@@ -81,16 +81,12 @@ void entry(uint8_t boot_drive, int boot_from) {
 
     term_notready();
 
-    {
     struct rm_regs r = {0};
     r.eax = 0x0003;
     rm_int(0x10, &r, &r);
 
-    current_video_mode = -1;
-
     outb(0x3d4, 0x0a);
     outb(0x3d5, 0x20);
-    }
 
     init_e820();
     init_memmap();
diff --git a/stage23/linker.ld b/stage23/linker.ld
index 9aa94f5d..348ba608 100644
--- a/stage23/linker.ld
+++ b/stage23/linker.ld
@@ -39,9 +39,10 @@ SECTIONS
     }
 
     .stage3.data : {
-        *(.data*)
         *(.rodata*)
         *(.full_map*)
+        data_begin = .;
+        *(.data*)
         limine_sys_size = . - 0x8000;
     }
 
@@ -54,6 +55,7 @@ SECTIONS
         *(COMMON)
         *(.bss*)
         bss_end = .;
+        data_end = .;
     }
 
     .symtab 0 : {
diff --git a/stage23/linker_dbg.ld b/stage23/linker_dbg.ld
index 3082dcfc..de357ff7 100644
--- a/stage23/linker_dbg.ld
+++ b/stage23/linker_dbg.ld
@@ -39,9 +39,10 @@ SECTIONS
     }
 
     .stage3.data : {
-        *(.data*)
         *(.rodata*)
         *(.full_map*)
+        data_begin = .;
+        *(.data*)
         limine_sys_size = . - 0x8000;
     }
 
@@ -54,6 +55,7 @@ SECTIONS
         *(COMMON)
         *(.bss*)
         bss_end = .;
+        data_end = .;
     }
 
     .symtab 0 : {
diff --git a/stage23/linker_nomap.ld b/stage23/linker_nomap.ld
index 17dc2115..29f663a2 100644
--- a/stage23/linker_nomap.ld
+++ b/stage23/linker_nomap.ld
@@ -39,9 +39,10 @@ SECTIONS
     }
 
     .stage3.data : {
-        *(.data*)
         *(.rodata*)
         full_map = .;
+        data_begin = .;
+        *(.data*)
         limine_sys_size = . - 0x8000;
     }
 
@@ -54,6 +55,7 @@ SECTIONS
         *(COMMON)
         *(.bss*)
         bss_end = .;
+        data_end = .;
     }
 
     .symtab 0 : {
diff --git a/stage23/linker_stage2only.ld b/stage23/linker_stage2only.ld
index f6dceda8..3ca08f4f 100644
--- a/stage23/linker_stage2only.ld
+++ b/stage23/linker_stage2only.ld
@@ -23,8 +23,9 @@ SECTIONS
     }
 
     .stage2.data : {
-        *.s2.o(.data*)
         *.s2.o(.rodata*)
+        data_begin = .;
+        *.s2.o(.data*)
         stage2_map = .;
         stage3_common = .;
         full_map = .;
@@ -49,6 +50,7 @@ SECTIONS
         *(COMMON)
         *(.bss*)
         bss_end = .;
+        data_end = .;
     }
 
     .symtab 0 : {
diff --git a/stage23/linker_uefi.ld b/stage23/linker_uefi.ld
index 20d0fbe3..fe53bcc4 100644
--- a/stage23/linker_uefi.ld
+++ b/stage23/linker_uefi.ld
@@ -38,17 +38,17 @@ SECTIONS
    *(.rodata*)
    *(.got.plt)
    *(.got)
+   data_begin = .;
    *(.data*)
    *(.sdata)
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
-   bss_begin = .;
    *(.sbss)
    *(.scommon)
    *(.dynbss)
    *(.bss)
    *(COMMON)
-   bss_end = .;
+   data_end = .;
    *(.rel.local)
    *(.full_map*)
   }
diff --git a/stage23/linker_uefi32.ld b/stage23/linker_uefi32.ld
index 38cf08c9..fce652fd 100644
--- a/stage23/linker_uefi32.ld
+++ b/stage23/linker_uefi32.ld
@@ -36,21 +36,21 @@ SECTIONS
   .data :
   {
    *(.rodata*)
+   *(.got.plt)
+   *(.got)
+   data_begin = .;
    *(.data)
    *(.data1)
    *(.data.*)
    *(.sdata)
-   *(.got.plt)
-   *(.got)
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
-   bss_begin = .;
    *(.sbss)
    *(.scommon)
    *(.dynbss)
    *(.bss)
    *(COMMON)
-   bss_end = .;
+   data_end = .;
    *(.full_map*)
   }
   .note.gnu.build-id : { *(.note.gnu.build-id) }
diff --git a/stage23/linker_uefi32_nomap.ld b/stage23/linker_uefi32_nomap.ld
index 05add6f1..6e0228e2 100644
--- a/stage23/linker_uefi32_nomap.ld
+++ b/stage23/linker_uefi32_nomap.ld
@@ -36,21 +36,21 @@ SECTIONS
   .data :
   {
    *(.rodata*)
+   *(.got.plt)
+   *(.got)
+   data_begin = .;
    *(.data)
    *(.data1)
    *(.data.*)
    *(.sdata)
-   *(.got.plt)
-   *(.got)
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
-   bss_begin = .;
    *(.sbss)
    *(.scommon)
    *(.dynbss)
    *(.bss)
    *(COMMON)
-   bss_end = .;
+   data_end = .;
    full_map = .;
   }
   .note.gnu.build-id : { *(.note.gnu.build-id) }
diff --git a/stage23/linker_uefi_nomap.ld b/stage23/linker_uefi_nomap.ld
index bb65e9c4..fcbceb2a 100644
--- a/stage23/linker_uefi_nomap.ld
+++ b/stage23/linker_uefi_nomap.ld
@@ -38,17 +38,17 @@ SECTIONS
    *(.rodata*)
    *(.got.plt)
    *(.got)
+   data_begin = .;
    *(.data*)
    *(.sdata)
    /* the EFI loader doesn't seem to like a .bss section, so we stick
       it all into .data: */
-   bss_begin = .;
    *(.sbss)
    *(.scommon)
    *(.dynbss)
    *(.bss)
    *(COMMON)
-   bss_end = .;
+   data_end = .;
    *(.rel.local)
    full_map = .;
   }
diff --git a/stage23/menu.c b/stage23/menu.c
index 5786efa5..b23caf6f 100644
--- a/stage23/menu.c
+++ b/stage23/menu.c
@@ -578,10 +578,10 @@ void menu(__attribute__((unused)) bool timeout_enabled) {
 
 static struct e820_entry_t *rewound_memmap = NULL;
 static size_t rewound_memmap_entries = 0;
-static uint8_t *rewound_bss;
+static uint8_t *rewound_data;
 
-extern symbol bss_begin;
-extern symbol bss_end;
+extern symbol data_begin;
+extern symbol data_end;
 
 bool *bad_config = NULL;
 
@@ -591,18 +591,18 @@ static void _menu(bool timeout_enabled) {
         bad_config = ext_mem_alloc(1);
     }
 
-    size_t bss_size = (uintptr_t)bss_end - (uintptr_t)bss_begin;
+    size_t data_size = (uintptr_t)data_end - (uintptr_t)data_begin;
 
     if (rewound_memmap != NULL) {
-        memcpy(bss_begin, rewound_bss, bss_size);
+        memcpy(data_begin, rewound_data, data_size);
         memcpy(memmap, rewound_memmap, rewound_memmap_entries * sizeof(struct e820_entry_t));
         memmap_entries = rewound_memmap_entries;
     } else {
-        rewound_bss = ext_mem_alloc(bss_size);
+        rewound_data = ext_mem_alloc(data_size);
         rewound_memmap = ext_mem_alloc(256 * sizeof(struct e820_entry_t));
         memcpy(rewound_memmap, memmap, memmap_entries * sizeof(struct e820_entry_t));
         rewound_memmap_entries = memmap_entries;
-        memcpy(rewound_bss, bss_begin, bss_size);
+        memcpy(rewound_data, data_begin, data_size);
     }
 
     if (*bad_config == false) {
tab: 248 wrap: offon