:: commit d624a35427815494e7bc46da066a1997b4ec24ce

mintsuki <mintsuki@protonmail.com> — 2020-01-21 10:42

parents: 97258c43f5

Add a .bss section to linker script

diff --git a/lib/types.h b/lib/types.h
new file mode 100644
index 00000000..b186589e
--- /dev/null
+++ b/lib/types.h
@@ -0,0 +1,6 @@
+#ifndef __LIB_TYPES_H__
+#define __LIB_TYPES_H__
+
+typedef void *symbol[];
+
+#endif
diff --git a/linker.ld b/linker.ld
index 8c5cc720..a2dd282d 100644
--- a/linker.ld
+++ b/linker.ld
@@ -3,17 +3,29 @@ ENTRY(main)
 
 SECTIONS
 {
-	. = 0x8000;
+    . = 0x8000;
 
     .text : {
         bootsect_begin = .;
         KEEP(*(.entry*))
-        KEEP(*(.text*))
+        *(.text*)
+    }
+
+    .rodata : {
+        *(.rodata*)
     }
 
     .data : {
-        KEEP(*(.data*))
-        KEEP(*(.bss*))
-        . += 31744 - (. - bootsect_begin);
+        *(.data*)
+        . += 31744 - (. - bootsect_begin);  /* Limit how big the thing can get
+                                               31744 = 32768 - (512 * 2)
+                                               32KiB of MBR gap minus 2 sectors
+                                               for stages 1 and 2 */
+    }
+
+    .bss : {
+        bss_begin = .;
+        *(.bss*)
+        bss_end = .;
     }
 }
diff --git a/main.c b/main.c
index 4b5d4aa2..35568d52 100644
--- a/main.c
+++ b/main.c
@@ -8,12 +8,21 @@ asm (
 #include <drivers/vga_textmode.h>
 #include <lib/real.h>
 #include <lib/print.h>
+#include <lib/types.h>
+
+extern symbol bss_begin;
+extern symbol bss_end;
 
 void main(int boot_drive) {
+    // Zero out .bss section
+    for (uint8_t *p = bss_begin; p < bss_end; p++)
+        *p = 0;
+
     init_vga_textmode();
     print("qLoader 2\n\n");
-    print("=> Boot drive: %x\n", boot_drive);
-    print("\n");
+
+    print("=> Boot drive: %x\n\n", boot_drive);
+
     for (;;) {
         struct rm_regs r = {0};
         rm_int(0x16, &r, &r);    // Real mode interrupt 16h
tab: 248 wrap: offon