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]

[libgloss/m32c] Add init/fini processing


	* m32c/crt0.S: Add support for preinit, init, and fini arrays, and
	.init and .fini processing.
	* m32c/crtn.S: Likewise.
	* m32c/exit.S: Likewise.

Index: m32c/crt0.S
===================================================================
RCS file: /cvs/src/src/libgloss/m32c/crt0.S,v
retrieving revision 1.1
diff -p -U3 -r1.1 crt0.S
--- m32c/crt0.S	10 Aug 2005 20:29:33 -0000	1.1
+++ m32c/crt0.S	14 Dec 2005 03:36:17 -0000
@@ -74,6 +74,8 @@ _start:
 	mov.w	#0,r0
 	sstr.w
 
+	jsr.a	__m32c_init
+
 	jsr.a	_main
 .LFE2:
 
@@ -85,6 +87,61 @@ _start:
 
 	jsr.a	_exit
 
+	.text
+
+	.global	_m32c_run_preinit_array
+	.type	_m32c_run_preinit_array,@function
+_m32c_run_preinit_array:
+	mov.W	#__preinit_array_start,a0
+	mov.W	#__preinit_array_end,a1
+	jmp.w	_m32c_run_inilist
+
+	.global	_m32c_run_init_array
+	.type	_m32c_run_init_array,@function
+_m32c_run_init_array:
+	mov.W	#__init_array_start,a0
+	mov.W	#__init_array_end,a1
+	jmp.w	_m32c_run_inilist
+
+	.global	_m32c_run_fini_array
+	.type	_m32c_run_fini_array,@function
+_m32c_run_fini_array:
+	mov.W	#__fini_array_start,a0
+	mov.W	#__fini_array_end,a1
+	/* fall through */
+
+_m32c_run_inilist:
+next_inilist:
+	cmp.W	a0,a1
+	jeq	done_inilist
+	pushm	a0,a1
+	mov.W	[a0],a0
+#ifdef A16
+	mov.b:s	#0,a1	/* zero extends */
+	jsri.a	a1a0
+#else
+	jsri.a	a0
+#endif
+	popm	a0,a1
+	add.W	A(#2,#4),a0
+	jmp.b	next_inilist
+done_inilist:
+	rts
+
+	.section	.init,"ax",@progbits
+
+	.global __m32c_init
+__m32c_init:
+	enter	#0
+
+	.section	.fini,"ax",@progbits
+
+	.global __m32c_fini
+__m32c_fini:
+	enter	#0
+	jsr.a	_m32c_run_fini_array
+
+
 ;;; Provide Dwarf unwinding information that will help GDB stop
 ;;; backtraces at the right place.  This is stolen from assembly
 ;;; code generated by GCC with -dA.
@@ -116,4 +173,5 @@ _start:
 	.byte 	0x30		; DW_OP_lit0
 	.p2align ALIGN
 .LEFDE0:
-.text
+
+	.text
Index: m32c/crtn.S
===================================================================
RCS file: /cvs/src/src/libgloss/m32c/crtn.S,v
retrieving revision 1.1
diff -p -U3 -r1.1 crtn.S
--- m32c/crtn.S	10 Aug 2005 20:29:33 -0000	1.1
+++ m32c/crtn.S	14 Dec 2005 03:36:17 -0000
@@ -41,5 +41,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBI
 #define W l
 #endif
 
+	.section	.init,"ax",@progbits
+	jsr.a	_m32c_run_preinit_array
+	jsr.a	_m32c_run_init_array
+	exitd
+	.global	__m32c_init_end
+__m32c_init_end:
+
+	.section	.fini,"ax",@progbits
+
+	exitd
+	.global	__m32c_fini_end
+__m32c_fini_end:
+
 	.text
 
Index: m32c/exit.S
===================================================================
RCS file: /cvs/src/src/libgloss/m32c/exit.S,v
retrieving revision 1.1
diff -p -U3 -r1.1 exit.S
--- m32c/exit.S	10 Aug 2005 20:29:33 -0000	1.1
+++ m32c/exit.S	14 Dec 2005 03:36:17 -0000
@@ -32,4 +32,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBI
 
 #include "m32csys.h"
 
-S(_exit)
+	.global	__exit
+__exit:
+	jsr.a	__m32c_fini
+	SYSCALL(SYS_exit)


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