Hi Dmitry,

Find attached patches for gcc and bintuils, this initializes the stack in init0 right at the start. The stack is initialized to the stack - the reserve ram attribute of the main function.

...
Basically, yes.
However, as long as main() in embedded does not accept parameters,
the hidded ctors call will not change anything.
But, if user puts his own routine in initX, he can make main accepting args.
Then this will destroy things a bit.

Initializing the stack pointer in init0 or init2 might solve this problem (?).

..
RESERVE_RAM(x) actually shifts initial stack value from user code, not from linker script.
The mentioned problem can be avoided by passing '-mstack=...' or --defsym... .

I had considered that when a user wanted to do this then they could use their own linker script and the -T option to the linker. But their are many ways to do the same thing.

Its a bit of a hack but, maybe in the main prologue we could change to the
.init2 section put the stack code in then change back to the .text
section this would get the stack pointer initialized before the
constructors are run and would allow the RESERVE_RAM to also work. Or I


how??? RESERVE_RAM(x) is an attribute and cannot not affect any library code.

Ok see the attached patches for gcc and binutils, creating a symbol in the main function __stack_reserve to save the reserve amount, init the stack in init0 (through libgcc.S/ reset_vector) with __stack_start and added to the linker script __stack_start to compute the difference between __stack and __stack_reserve as this is the time the values are known.

Maybe __stack needs renaming something else and __stack_start should be renamed __stack but ill leave this up to you.

..


Obviously, if ctors/dtors are not required, gcc will not issue a relevant code.

That is true, but if the code has destructors in it then they will be put into the embedded code and never run. This could be the case when compiling the same code for both linux and a msp430 system.

Regards,


--
Peter Jansen
STS
Australian Antarctic Division
Channel Highway
Kingston
TAS        7050
AUSTRALIA
Ph  (03) 62 323 533
Fax (03) 62 323 351

___________________________________________________________________________

   Australian Antarctic Division - Commonwealth of Australia
IMPORTANT: This transmission is intended for the addressee only. If you are
not the intended recipient, you are notified that use or dissemination of
this communication is strictly prohibited by Commonwealth law. If you have
received this transmission in error, please notify the sender immediately
by e-mail or by telephoning +61 3 6232 3209 and DELETE the message.
       Visit our web site at http://www.aad.gov.au/
___________________________________________________________________________
diff -rU 6 gcc/gcc-3.4/gcc/config/msp430/libgcc.S 
gcc-patch/gcc-3.4/gcc/config/msp430/libgcc.S
--- gcc/gcc-3.4/gcc/config/msp430/libgcc.S      2003-04-09 18:49:37.000000000 
+1000
+++ gcc-patch/gcc-3.4/gcc/config/msp430/libgcc.S        2003-04-12 
14:03:57.000000000 +1000
@@ -615,20 +615,21 @@
  *****************************************************************/
        .extern _etext
        .extern __data_start
        .extern _edata
        .extern __bss_start
        .extern __bss_end
-       .extern __stack
+       .extern __stack_start
 
        .section .init0, "ax", @progbits
 
        .global _reset_vector__
 .func _reset_vector__
 _reset_vector__:
        mov     #23168, &288    
+       mov     #(__stack_start), r1
 
        .section .init2, "ax", @progbits
        .global _copy_data_init__
        .weak   _copy_data_init__
 
 _copy_data_init__:
@@ -673,23 +674,22 @@
 
 #ifdef L_ctors
        .section .init6,"ax",@progbits
        .global __do_global_ctors
        
 __do_global_ctors:
-       mov     #__stack, r1    ; load stack... might be dangerous!!! 
        mov     #__ctors_start, r11
        mov     #__ctors_end, r10
        cmp     r10, r11
        jeq     .L__ctors_end
 .L__ctors_loop:
        call    @r11    ; call constructor
        incd    r11
        cmp     r10, r11
        jne     .L__ctors_loop
-L__ctors_end:
+.L__ctors_end:
 #endif
 
 #ifdef L_dtors
        .section .fini6,"ax",@progbits
        .global __do_global_dtors
 __do_global_dtors:
diff -rU 6 gcc/gcc-3.4/gcc/config/msp430/msp430.c 
gcc-patch/gcc-3.4/gcc/config/msp430/msp430.c
--- gcc/gcc-3.4/gcc/config/msp430/msp430.c      2003-04-09 17:42:42.000000000 
+1000
+++ gcc-patch/gcc-3.4/gcc/config/msp430/msp430.c        2003-04-12 
14:03:54.000000000 +1000
@@ -17,14 +17,12 @@
  along with GCC; see the file COPYING.  If not, write to
  the Free Software Foundation, 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.  */
 
 #include "config.h"
 #include "system.h"
-#include "coretypes.h"
-#include "tm.h"
 #include "rtl.h"
 #include "regs.h"
 #include "hard-reg-set.h"
 #include "real.h"
 #include "insn-config.h"
 #include "conditions.h"
@@ -786,12 +784,14 @@
       prologue_size += 1;
       fprintf (file, "\teint\t; enable nested interrupt\n");
     }
 
   if (main_p)
     {
+      fprintf(file, "\t.global\t__stack_reserve\n");
+      fprintf(file, "__stack_reserve=%d\n", stack_reserve);
       if (TARGET_NSI)
        {
          if (size || stack_reserve)
            fprintf (file, "\tsub\t#%ld, r1\t", size + stack_reserve);
          if (frame_pointer_needed)
            {
Index: src/ld/ChangeLog
===================================================================
RCS file: /cvs/src/src/ld/ChangeLog,v
retrieving revision 1.898
diff -C6 -r1.898 ChangeLog
*** src/ld/ChangeLog    9 Apr 2003 11:07:50 -0000       1.898
--- src/ld/ChangeLog    12 Apr 2003 04:19:22 -0000
***************
*** 1,6 ****
--- 1,10 ----
+ 2003-04-12   Peter Jansen <peter.jan...@aad.gov.au>
+         * scripttempl/elf32msp430.sc : Add __stack_start
+         * scripttempl/elf32msp430_3.sc : Ditto
+ 
  2003-04-09   Dmitry Diky  <di...@mail.ru>
  
        * scripttempl/elf32msp430.sc: Add initX, finiX, ctors, dtors
        sections to respect C++  constructor/destructor. Add ctors/dtors
        start/stop definitions.
        * scripttempl/elf32msp430_3.sc: Likewise.
Index: src/ld/scripttempl/elf32msp430.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf32msp430.sc,v
retrieving revision 1.3
diff -C6 -r1.3 elf32msp430.sc
*** src/ld/scripttempl/elf32msp430.sc   9 Apr 2003 11:07:51 -0000       1.3
--- src/ld/scripttempl/elf32msp430.sc   12 Apr 2003 04:19:22 -0000
***************
*** 212,223 ****
--- 212,224 ----
    .debug_frame    0 : { *(.debug_frame) }
    .debug_str      0 : { *(.debug_str) }
    .debug_loc      0 : { *(.debug_loc) }
    .debug_macinfo  0 : { *(.debug_macinfo) }
  
    PROVIDE (__stack = ${STACK}) ;
+   PROVIDE (__stack_start = ${STACK} - __stack_reserve) ;
    PROVIDE (__data_start_rom = _etext) ;
    PROVIDE (__data_end_rom   = _etext + SIZEOF (.data)) ;
    PROVIDE (__noinit_start_rom = _etext + SIZEOF (.data)) ;
    PROVIDE (__noinit_end_rom = _etext + SIZEOF (.data) + SIZEOF (.noinit)) ;
  }
  EOF
Index: src/ld/scripttempl/elf32msp430_3.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf32msp430_3.sc,v
retrieving revision 1.3
diff -C6 -r1.3 elf32msp430_3.sc
*** src/ld/scripttempl/elf32msp430_3.sc 9 Apr 2003 11:07:51 -0000       1.3
--- src/ld/scripttempl/elf32msp430_3.sc 12 Apr 2003 04:19:22 -0000
***************
*** 181,192 ****
--- 181,193 ----
    .debug_frame    0 : { *(.debug_frame) }
    .debug_str      0 : { *(.debug_str) }
    .debug_loc      0 : { *(.debug_loc) }
    .debug_macinfo  0 : { *(.debug_macinfo) }
  
    PROVIDE (__stack = ${STACK}) ;
+   PROVIDE (__stack_start = ${STACK} - __stack_reserve) ;
    PROVIDE (__data_start_rom = _etext) ;
    PROVIDE (__data_end_rom   = _etext + SIZEOF (.data)) ;
    PROVIDE (__noinit_start_rom = _etext + SIZEOF (.data)) ;
    PROVIDE (__noinit_end_rom = _etext + SIZEOF (.data) + SIZEOF (.noinit)) ;
  }
  EOF

Reply via email to