[freenos] r415 committed - Reimplemented linker script variables, such that they dont overlap wit...

  • From: freenos@xxxxxxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Thu, 21 Oct 2010 21:42:32 +0000

Revision: 415
Author: nieklinnenbank
Date: Thu Oct 21 14:36:24 2010
Log: Reimplemented linker script variables, such that they dont overlap with segments. Previously, at least the boot_img_start and boot_img_end variables overlapped
with other segments, causing memory corruption on at least the OpenBSD gcc
compiler and Debian 5.

http://code.google.com/p/freenos/source/detail?r=415

Modified:
 /branches/scratch/system/phys_memory.c
 /branches/scratch/system/x86/pc/config/kernel.ld

=======================================
--- /branches/scratch/system/phys_memory.c      Mon Oct 18 16:59:47 2010
+++ /branches/scratch/system/phys_memory.c      Thu Oct 21 14:36:24 2010
@@ -24,10 +24,21 @@
 #include <FreeNOS/printk.h>
 #include <string.h>

+/* Private variables. */
 static spinlock_t phys_memory_lock;
 static size_t memory_size, memory_avail;
 static u8 *memory_map, *memory_map_end;
-size_t kernel_size;
+
+/* Defined in the linker script. */
+extern addr_t _kernel_start,   _kernel_end,
+             _boot_img_start, _boot_img_end;
+
+/* Begin and end addresses of the kernel and bootimg. */
+addr_t kernel_start   = (addr_t) &_kernel_start;
+addr_t kernel_end     = (addr_t) &_kernel_end;
+addr_t boot_img_start = (addr_t) &_boot_img_start;
+addr_t boot_img_end   = (addr_t) &_boot_img_end;
+size_t kernel_size    = 0;

 static int paddr_is_marked(addr_t paddr)
 {
@@ -62,10 +73,6 @@
     /* Initialize (local) variables. */
     memory_size  = arch_total_memory();
     memory_avail = memory_size;
-    kernel_start = (addr_t) &kernel_start;
-    kernel_end   = (addr_t) &kernel_end;
-    boot_img_start = (addr_t) &boot_img_start;
-    boot_img_end   = (addr_t) &boot_img_end;

     /* Allocate physical memory bitmap. */
     memory_map     = (u8 *)(kernel_end);
=======================================
--- /branches/scratch/system/x86/pc/config/kernel.ld Mon Oct 18 16:59:47 2010 +++ /branches/scratch/system/x86/pc/config/kernel.ld Thu Oct 21 14:36:24 2010
@@ -4,8 +4,7 @@
     . = 0x01000000;

     .text : {
-       kernel_start = .;
-       LONG(0)
+       _kernel_start = .;
        *(.boot)
         *(.text)
     }
@@ -17,15 +16,14 @@
     .data ALIGN (0x1000) : {
         *(.data)
         . = ALIGN(0x1000);
-        boot_img_start = .;
+        _boot_img_start = .;
         *(.binary)
-        boot_img_end = .;
+        _boot_img_end = .;
     }

     .bss : {
         *(COMMON)
         *(.bss)
-       kernel_end = .;
-        LONG(0)
+       _kernel_end = .;
     }
 }

Other related posts:

  • » [freenos] r415 committed - Reimplemented linker script variables, such that they dont overlap wit... - freenos