synthetic target heap

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

synthetic target heap

Bart Veer
Recent Fedora kernels such as 2.6.14-1.1637_FC4 (and possibly others)
have broken the synthetic target. This time the problem appears to be
with the brk() system call. brk() was used during the init sequence to
allocate memory for the heap past the end of BSS up to the emulated
RAM size. The system call appeared to succeed but the memory was not
actually accessible. I started looking at the brk() code, then decided
it was better to fix it via the linker script. That way it is up to
the linker and loader to ensure the memory is allocated, and not the
synthetic target run-time.

This patch adds a new linker script macro SECTIONS_HEAP() and uses it
from inside the .ldi file. It also removes the brk() invocation during
system init.

Bart

Index: arch/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/arch/current/ChangeLog,v
retrieving revision 1.31
diff -u -r1.31 ChangeLog
--- arch/current/ChangeLog 5 Nov 2005 19:43:24 -0000 1.31
+++ arch/current/ChangeLog 20 Nov 2005 16:16:43 -0000
@@ -1,3 +1,12 @@
+2005-11-19  Bart Veer  <[hidden email]>
+
+ * src/synth_entry.c (_linux_entry): brk() is no longer needed to
+ get heap memory.
+
+ * src/synth.ld: add new section to contain the heap memory rather
+ than rely on brk().
+
+
 2005-11-05  Andrew Lunn <[hidden email]>
 
  * include/hal_io.h (struct cyg_hal_sys_old_stat): Make the

Index: arch/current/src/synth.ld
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/arch/current/src/synth.ld,v
retrieving revision 1.5
diff -u -r1.5 synth.ld
--- arch/current/src/synth.ld 2 Jul 2003 03:36:38 -0000 1.5
+++ arch/current/src/synth.ld 20 Nov 2005 16:17:04 -0000
@@ -212,6 +213,11 @@
     > _region_                                                                  \
     __bss_end = .;
 
+#define SECTIONS_HEAP(_region_, _start_, _end_) \
+    .synth_heap _start_ : \
+    { FORCE_OUTPUT; . = _end_ - _start_ ; } \
+    > _region_
+
 #define SECTIONS_END . = ALIGN(4); _end = .; PROVIDE (end = .);
 
 #include <pkgconf/system.h>
Index: arch/current/src/synth_entry.c
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/arch/current/src/synth_entry.c,v
retrieving revision 1.6
diff -u -r1.6 synth_entry.c
--- arch/current/src/synth_entry.c 5 Jul 2003 23:17:29 -0000 1.6
+++ arch/current/src/synth_entry.c 20 Nov 2005 16:17:30 -0000
@@ -105,29 +105,16 @@
 
 void _linux_entry( void )
 {
-    void* new_top = (void*) 0;
-    
     // "Initialize various cpu status registers, including disabling interrupts."
     // That is a no-op for the synthetic target, in particular interrupts are
     // already disabled.
 
-    // "Set up any CPU memory controller to access ROM, RAM, and I/O devices
-    // correctly".
-    //
-    // This involves using the brk() system call to allocate the RAM used
-    // for the heaps. There are no variables mapped there so the system
-    // will not have done this for us. Note that the implementation of
-    // brk() (mm/mmap.c) differs from the documentation - the return
-    // value is the new brk value, not an error code.
-    new_top = (void*) (CYGMEM_REGION_ram + CYGMEM_REGION_ram_SIZE);
-    if (new_top != cyg_hal_sys_brk(new_top)) {
-        CYG_FAIL("Failed to initialize memory");
-        cyg_hal_sys_exit(1);
-    }
-    
-    // Again a no-op for the synthetic target. All memory is readily
-    // accessible. Arguably the auxiliary should be started up here, but
-    // instead that is left to platform initialization.
+    // "Set up any CPU memory controller to access ROM, RAM, and I/O
+    // devices correctly". The ROM and RAM are set up via the linker
+    // script and taken care of automatically during loading. There
+    // are no memory-mapped devices. Arguably the auxiliary should be
+    // started up here, but instead that is left to platform
+    // initialization.
 
     // "Enable the cache". Effectively the synthetic target has no cache,
     // anything provided by the hardware is not readily accessible.
Index: i386linux/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/i386linux/current/ChangeLog,v
retrieving revision 1.16
diff -u -r1.16 ChangeLog
--- i386linux/current/ChangeLog 5 Nov 2005 19:44:27 -0000 1.16
+++ i386linux/current/ChangeLog 20 Nov 2005 16:18:02 -0000
@@ -1,3 +1,8 @@
+2005-11-19  Bart Veer  <[hidden email]>
+
+ * include/pkgconf/mlt_synth_i386_rom.ldi: add new heap section to
+ avoid the use of brk()
+
 2005-11-05  Andrew Lunn  <[hidden email]>
 
  * src/syscall-i386-linux-1.0.S: renamed prev_?stat to old?stat to
Index: i386linux/current/include/pkgconf/mlt_synth_i386_rom.ldi
===================================================================
RCS file: /cvs/ecos/ecos/packages/hal/synth/i386linux/current/include/pkgconf/mlt_synth_i386_rom.ldi,v
retrieving revision 1.2
diff -u -r1.2 mlt_synth_i386_rom.ldi
--- i386linux/current/include/pkgconf/mlt_synth_i386_rom.ldi 20 May 2002 22:24:15 -0000 1.2
+++ i386linux/current/include/pkgconf/mlt_synth_i386_rom.ldi 20 Nov 2005 16:18:19 -0000
@@ -6,14 +6,14 @@
 
 MEMORY
 {
-    rom : ORIGIN = 0x1000000, LENGTH = 0x800000
-    ram : ORIGIN = 0x2000000, LENGTH = 0x800000
+    rom : ORIGIN = 0x01000000, LENGTH = 0x800000
+    ram : ORIGIN = 0x02000000, LENGTH = 0x800000
 }
 
 SECTIONS
 {
     SECTIONS_BEGIN
-    SECTION_vectors (rom, 0x1000000, LMA_EQ_VMA)
+    SECTION_vectors (rom, 0x01000000, LMA_EQ_VMA)
     SECTION_text (rom, ALIGN (0x4), LMA_EQ_VMA)
     SECTION_fini (rom, ALIGN (0x4), LMA_EQ_VMA)
     SECTION_rodata1 (rom, ALIGN (0x8), LMA_EQ_VMA)
@@ -23,9 +23,10 @@
     SECTION_eh_frame (rom, ALIGN (0x4), LMA_EQ_VMA)
     SECTION_rel__got (rom, ALIGN (0x1), LMA_EQ_VMA)
     SECTION_gcc_except_table (rom, ALIGN (0x1), LMA_EQ_VMA)
-    SECTION_data (ram, 0x2000000, LMA_EQ_VMA)
+    SECTION_data (ram, 0x02000000, LMA_EQ_VMA)
     SECTION_sbss (ram, ALIGN (0x4), LMA_EQ_VMA)
     SECTION_bss (ram, ALIGN (0x10), LMA_EQ_VMA)
     CYG_LABEL_DEFN(__heap1) = ALIGN (0x10);
+    SECTIONS_HEAP(ram, __heap1, 0x02800000)
     SECTIONS_END
 }