This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] split up msp430 startup


To further reduce the minimum required image size, I've split up the
stuff that's usually "just there" a bit more in an effort to not link
in functionality that isn't needed, and to give the user the option of
pruning out the rest.  Committed.


	* msp430/Makefile.in (crt0-minrt.o, crtn-minrt.o): New.  Build
	from crt0.S with -DMINRT.
	(CRT_OBJS): Expand.
	(crt_%.o): New rule pattern.  Build multiple objects from crt0.S.
	* msp430/crt0.S: Further break out functionality.  Support -DMINRT
	that omits all init/fini logic.
	* msp430/crtn.S: Likewise.
	* msp430/msp430-sim.ld: Wildcard all .crt_* sections, sorted.
	* msp430/msp430.ld: Likewise.
	* msp430/msp430xl-sim.ld: Likewise.

Index: msp430/Makefile.in
===================================================================
RCS file: /cvs/src/src/libgloss/msp430/Makefile.in,v
retrieving revision 1.2
diff -p -U 5 -r1.2 Makefile.in
--- msp430/Makefile.in	18 Sep 2013 07:38:12 -0000	1.2
+++ msp430/Makefile.in	30 Jan 2014 02:26:33 -0000
@@ -59,11 +59,11 @@ OBJCOPY = `if [ -f ${objroot}/../binutil
 SCRIPTS = $(srcdir)/msp430.ld $(srcdir)/msp430-sim.ld
 SCRIPTS += $(srcdir)/msp430xl-sim.ld
 SCRIPTS += $(srcdir)/msp430F5438A-s.ld
 SCRIPTS += $(srcdir)/msp430F5438A-l.ld
 
-CRT = gcrt0.o crt0.o crtn.o
+CRT = gcrt0.o crt0.o crt0-minrt.o crtn.o crtn-minrt.o
 SIM_BSP = libsim.a
 LIBNOSYS = libnosys.a
 
 SIM_OBJS = syscalls.o \
 	cio.o \
@@ -77,21 +77,38 @@ NOSYS_OBJS = nosyscalls.o \
 
 SCRIPTS += $(srcdir)/intr_vectors.ld
 
 LIB_CRT = libcrt.a
 
-CRT_OBJS = crt_bss.o crt_movedata.o
+# Each crt_*.o is built from crt0.S using -DL*.  crt0.o is built from
+# crt0.s with -DL0 via the default rule below.
+CRT_OBJS = \
+	crt_bss.o \
+	crt_movedata.o \
+	crt_main.o \
+	crt_main_minrt.o \
+	crt_callexit.o \
+	crt_init.o
 
 #### Host specific Makefile fragment comes in here.
 @host_makefile_frag@
 
 
+all: $(CRT) $(SIM_BSP) $(LIBNOSYS) $(LIB_CRT) copy_scripts_to_objdir
+
+crt_%.o : crt0.S
+	$(CC) -DL$* -Wa,-gdwarf2 -Wa,-I$(srcdir) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $< -o $@
+
+crt0-minrt.o : crt0.S
+	$(CC) -DL0 -DMINRT -Wa,-gdwarf2 -Wa,-I$(srcdir) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $< -o $@
+
+crtn-minrt.o : crtn.S
+	$(CC) -DL0 -DMINRT -Wa,-gdwarf2 -Wa,-I$(srcdir) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $< -o $@
+
 # Override .S.o rule to pass assembler debugging flags
 .S.o:
-	$(CC) -Wa,-gdwarf2 -Wa,-I$(srcdir) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $<
-
-all: $(CRT) $(SIM_BSP) $(LIBNOSYS) $(LIB_CRT) copy_scripts_to_objdir
+	$(CC) -DL0 -Wa,-gdwarf2 -Wa,-I$(srcdir) $(CFLAGS_FOR_TARGET) $(INCLUDES) $(CFLAGS) -c $<
 
 $(SIM_BSP): $(SIM_OBJS)
 	$(AR) $(ARFLAGS) $@ $?
 	$(RANLIB) $@
 
Index: msp430/crt0.S
===================================================================
RCS file: /cvs/src/src/libgloss/msp430/crt0.S,v
retrieving revision 1.1
diff -p -U 5 -r1.1 crt0.S
--- msp430/crt0.S	13 May 2013 21:39:51 -0000	1.1
+++ msp430/crt0.S	30 Jan 2014 02:26:33 -0000
@@ -11,30 +11,57 @@
    Red Hat, Inc.
 */
 
 #include "memmodel.h"
 
+;; The linker links all .crt_* sections in asciibetical order at the
+;; same place.  So, the four digits in .crt_NNNN determine the link
+;; order, so, keep them in sequential order here.  The first two
+;; digits are set here, the second two allow users to insert code
+;; between code fragments here.
+
+#if L0
 	.section ".resetvec", "a"
 __msp430_resetvec_hook:
 	.word	__start
 
-	.section ".lowtext", "ax", @progbits
+	.section ".crt_0000init", "ax", @progbits
+	.refsym	__msp430_resetvec_hook
+#ifdef MINRT
+	.refsym	__crt0_call_just_main
+#else
+	.refsym	__crt0_call_init_then_main
+#endif
 	.global __start
 __start:
 	mov_	#__stack, R1
 
 	;; Disable watchdog timer.
 	MOV	#0x5a80, &0x15C
+#endif
 
+#if Lbss
+	.section ".crt_0100bss", "ax", @progbits
+
+	.global __crt0_init_bss
+__crt0_init_bss:	
+	
 	mov_	#__bssstart, R12
 	clr.w	R13
 	mov.w	#__bsssize, R14
 #ifdef __MSP430X_LARGE__
 	clr.w	R15		; We assume that __bsssize is never > 64M
 #endif
 	call_	#memset
+#endif
 
+#if Lmovedata
+	.section ".crt_0200movedata", "ax", @progbits
+
+	.global __crt0_movedata
+__crt0_movedata:	
+	
 	mov_	#__datastart, R12
 	mov_	#__romdatastart, R13
 
 	;;  memmove and memcpy do not currently work when src == dst
 	cmp_	R12, R13
@@ -44,21 +71,42 @@ __start:
 #ifdef __MSP430X_LARGE__
 	clr.w	R15		; We assume that __romdatacopysize is never > 64M
 #endif
 	call_	#memmove
 1:	
+#endif
+
+#if Lmain_minrt
+	.section ".crt_0300main", "ax", @progbits
+	.global	__crt0_call_just_main
+__crt0_call_just_main:
+	clr.w	R12		; Set argc == 0
+	call_	#main
+#endif
+
+#if Lmain
+	.section ".crt_0300main", "ax", @progbits
+	.global	__crt0_call_init_then_main
+__crt0_call_init_then_main:
 	call_	#__msp430_init
 
 	clr.w	R12		; Set argc == 0
 	call_	#main
+#endif
 
+#if Lcallexit
+	.section ".crt_0400main_exit", "ax", @progbits
+	.global	__crt0_call_exit
+__crt0_call_exit:
 	call_	#_exit
-
-	.word	__msp430_resetvec_hook
+#endif
 
 ;----------------------------------------
 
+#ifndef MINRT
+#if L0
+	.section ".crt_0500main_init", "ax", @progbits
 	.global	_msp430_run_init_array
 	.type	_msp430_run_init_array,@function
 _msp430_run_init_array:
 	mov_	#__init_array_start, R4
 	mov_	#__init_array_end, R5
@@ -102,5 +150,8 @@ __msp430_init:
 	.section	.fini,"ax"
 
 	.global __msp430_fini
 __msp430_fini:
 	call_	#_msp430_run_fini_array
+	
+#endif
+#endif
Index: msp430/crtn.S
===================================================================
RCS file: /cvs/src/src/libgloss/msp430/crtn.S,v
retrieving revision 1.1
diff -p -U 5 -r1.1 crtn.S
--- msp430/crtn.S	13 May 2013 21:39:51 -0000	1.1
+++ msp430/crtn.S	30 Jan 2014 02:26:33 -0000
@@ -11,10 +11,11 @@
    Red Hat, Inc.
 */
 
 #include "memmodel.h"
 
+#ifndef MINRT
 	.section	.init,"ax"
 	call_	#_msp430_run_preinit_array
 	call_	#_msp430_run_init_array
 	ret_
 	.global	__msp430_init_end
@@ -26,5 +27,6 @@ __msp430_init_end:
 	.global	__msp430_fini_end
 __msp430_fini_end:
 
 	.text
 
+#endif
Index: msp430/msp430-sim.ld
===================================================================
RCS file: /cvs/src/src/libgloss/msp430/msp430-sim.ld,v
retrieving revision 1.2
diff -p -U 5 -r1.2 msp430-sim.ld
--- msp430/msp430-sim.ld	18 Sep 2013 07:38:13 -0000	1.2
+++ msp430/msp430-sim.ld	30 Jan 2014 02:26:33 -0000
@@ -78,16 +78,12 @@ SECTIONS
 
   .text           :
   {
     . = ALIGN(2);
     PROVIDE (_start = .);
-    KEEP (*(.crt_init))
-    KEEP (*(.crt_bss))
-    KEEP (*(.crt_movedata))
-    KEEP (*(.crt_main))
-    KEEP (*(.lowtext))
-    *(.text .stub .text.* .gnu.linkonce.t.* .text:*)
+    KEEP (*(SORT(.crt_*)))
+    *(.lowtext .text .stub .text.* .gnu.linkonce.t.* .text:*)
     KEEP (*(.text.*personality*))
     /* .gnu.warning sections are handled specially by elf32.em.  */
     *(.gnu.warning)
     *(.interp .hash .dynsym .dynstr .gnu.version*)
     PROVIDE (__etext = .);
Index: msp430/msp430.ld
===================================================================
RCS file: /cvs/src/src/libgloss/msp430/msp430.ld,v
retrieving revision 1.2
diff -p -U 5 -r1.2 msp430.ld
--- msp430/msp430.ld	18 Sep 2013 07:38:13 -0000	1.2
+++ msp430/msp430.ld	30 Jan 2014 02:26:33 -0000
@@ -77,16 +77,12 @@ SECTIONS
 
   .text           :
   {
     . = ALIGN(2);
     PROVIDE (_start = .);
-    KEEP (*(.crt_init))
-    KEEP (*(.crt_bss))
-    KEEP (*(.crt_movedata))
-    KEEP (*(.crt_main))
-    KEEP (*(.lowtext))
-    *(.text .stub .text.* .gnu.linkonce.t.* .text:*)
+    KEEP (*(SORT(.crt_*)))
+    *(.lowtext .text .stub .text.* .gnu.linkonce.t.* .text:*)
     KEEP (*(.text.*personality*))
     /* .gnu.warning sections are handled specially by elf32.em.  */
     *(.gnu.warning)
     *(.interp .hash .dynsym .dynstr .gnu.version*)
     PROVIDE (__etext = .);
Index: msp430/msp430xl-sim.ld
===================================================================
RCS file: /cvs/src/src/libgloss/msp430/msp430xl-sim.ld,v
retrieving revision 1.2
diff -p -U 5 -r1.2 msp430xl-sim.ld
--- msp430/msp430xl-sim.ld	18 Sep 2013 07:38:13 -0000	1.2
+++ msp430/msp430xl-sim.ld	30 Jan 2014 02:26:33 -0000
@@ -142,14 +142,11 @@ SECTIONS
   /* This is just for crt0.S */
   .lowtext           :
   {
     PROVIDE (_start = .);
     . = ALIGN(2);
-    KEEP (*(.crt_init))
-    KEEP (*(.crt_bss))
-    KEEP (*(.crt_movedata))
-    KEEP (*(.crt_main))
+    KEEP (*(SORT(.crt_*)))
     KEEP (*(.lowtext))
   } > LOWROM
 
   .text           :
   {


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]