This is the mail archive of the newlib@sources.redhat.com 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]

Re: XScale version of setjmp


Ian Lance Taylor wrote:
When configuring newlib for xscale-elf, setjmp used to come from
libc/sys/arm/setjmp.S.  However, with this patch:

2004-06-09 Toralf Lund <toralf@procaptura.com>

	* libc/sys/arm/setjmp.S, libc/sys/arm/access.c: Move
	files from libc/sys/arm to libc/machine/arm.

that file was moved to libc/machine/arm.  With that change, there is
no longer any setjmp for xscaleelf.

This patch takes the simple approach of adding
libc/machine/xscale/setjmp.S.

OK to commit?


Yes. Please do.


-- Jeff J.

Ian

2004-09-21 Ian Lance Taylor <ian@wasabisystems.com>

	* libc/machine/xscale/setjmp.S: New file, copied from
	libc/machine/arm/setjmp.S.
	* libc/machine/xscale/Makefile.am (lib_a_SOURCES): Add setjmp.S.
	* libc/machine/xscale/Makefile.in: Regenerate.

Index: Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/xscale/Makefile.am,v
retrieving revision 1.1
diff -u -r1.1 Makefile.am
--- Makefile.am 30 Nov 2000 01:57:26 -0000 1.1
+++ Makefile.am 21 Sep 2004 17:13:30 -0000
@@ -8,7 +8,7 @@
lib_a_SOURCES = \
memchr.c memcmp.c memcpy.c memmove.c memset.c \
- strchr.c strcmp.c strcpy.c strlen.c
+ strchr.c strcmp.c strcpy.c strlen.c setjmp.S
ACLOCAL_AMFLAGS = -I ../../..
CONFIG_STATUS_DEPENDENCIES = $(newlib_basedir)/configure.host
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/xscale/Makefile.in,v
retrieving revision 1.6
diff -u -r1.6 Makefile.in
--- Makefile.in 23 Jan 2004 21:37:34 -0000 1.6
+++ Makefile.in 21 Sep 2004 17:13:30 -0000
@@ -89,7 +89,9 @@
noinst_LIBRARIES = lib.a
-lib_a_SOURCES = memchr.c memcmp.c memcpy.c memmove.c memset.c strchr.c strcmp.c strcpy.c strlen.c
+lib_a_SOURCES = \
+ memchr.c memcmp.c memcpy.c memmove.c memset.c \
+ strchr.c strcmp.c strcpy.c strlen.c setjmp.S
ACLOCAL_AMFLAGS = -I ../../..
@@ -105,7 +107,7 @@
LIBS = @LIBS@
lib_a_LIBADD = lib_a_OBJECTS = memchr.o memcmp.o memcpy.o memmove.o memset.o strchr.o \
-strcmp.o strcpy.o strlen.o
+strcmp.o strcpy.o strlen.o setjmp.o
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
Index: setjmp.S
===================================================================
RCS file: setjmp.S
diff -N setjmp.S
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ setjmp.S 21 Sep 2004 17:13:30 -0000
@@ -0,0 +1,137 @@
+/* This is a simple version of setjmp and longjmp.
+
+ Nick Clifton, Cygnus Solutions, 13 June 1997. */
+
+/* ANSI concatenation macros. */
+#define CONCAT(a, b) CONCAT2(a, b)
+#define CONCAT2(a, b) a##b
+
+#ifndef __USER_LABEL_PREFIX__
+#error __USER_LABEL_PREFIX__ not defined
+#endif
+
+#define SYM(x) CONCAT (__USER_LABEL_PREFIX__, x)
+
+#ifdef __ELF__
+#define TYPE(x) .type SYM(x),function
+#define SIZE(x) .size SYM(x), . - SYM(x)
+#else
+#define TYPE(x)
+#define SIZE(x)
+#endif
+
+/* Arm/Thumb interworking support:
+
+ The interworking scheme expects functions to use a BX instruction
+ to return control to their parent. Since we need this code to work
+ in both interworked and non-interworked environments as well as with
+ older processors which do not have the BX instruction we do the + following:
+ Test the return address.
+ If the bottom bit is clear perform an "old style" function exit.
+ (We know that we are in ARM mode and returning to an ARM mode caller).
+ Otherwise use the BX instruction to perform the function exit.
+
+ We know that we will never attempt to perform the BX instruction on + an older processor, because that kind of processor will never be + interworked, and a return address with the bottom bit set will never + be generated.
+
+ In addition, we do not actually assemble the BX instruction as this would
+ require us to tell the assembler that the processor is an ARM7TDMI and
+ it would store this information in the binary. We want this binary to be
+ able to be linked with binaries compiled for older processors however, so
+ we do not want such information stored there. +
+ If we are running using the APCS-26 convention however, then we never
+ test the bottom bit, because this is part of the processor status. + Instead we just do a normal return, since we know that we cannot be + returning to a Thumb caller - the Thumb does not support APCS-26.
+
+ Function entry is much simpler. If we are compiling for the Thumb we + just switch into ARM mode and then drop through into the rest of the
+ function. The function exit code will take care of the restore to
+ Thumb mode. */
+
+#ifdef __APCS_26__
+#define RET movs pc, lr
+#else
+#define RET tst lr, #1; \
+ moveq pc, lr ; \
+.word 0xe12fff1e /* bx lr */
+#endif
+
+#ifdef __thumb__
+#define MODE .thumb_func
+.macro PROLOGUE name
+ .code 16
+ bx pc
+ nop
+ .code 32
+SYM (.arm_start_of.\name):
+.endm
+#else
+#define MODE .code 32
+.macro PROLOGUE name
+.endm
+#endif
+
+.macro FUNC_START name
+ .text
+ .align 2
+ MODE
+ .globl SYM (\name)
+ TYPE (\name)
+SYM (\name):
+ PROLOGUE \name
+.endm
+
+.macro FUNC_END name
+ RET
+ SIZE (\name)
+.endm
+
+/* --------------------------------------------------------------------
+ int setjmp (jmp_buf); + -------------------------------------------------------------------- */
+
+ FUNC_START setjmp
+
+ /* Save all the callee-preserved registers into the jump buffer. */
+ stmea a1!, { v1-v7, fp, ip, sp, lr }
+
+#if 0 /* Simulator does not cope with FP instructions yet. */
+#ifndef __SOFTFP__
+ /* Save the floating point registers. */
+ sfmea f4, 4, [a1]
+#endif
+#endif
+ /* When setting up the jump buffer return 0. */
+ mov a1, #0
+
+ FUNC_END setjmp
+
+/* --------------------------------------------------------------------
+ volatile void longjmp (jmp_buf, int);
+ -------------------------------------------------------------------- */
+
+ FUNC_START longjmp
+
+ /* If we have stack extension code it ought to be handled here. */
+
+ /* Restore the registers, retrieving the state when setjmp() was called. */
+ ldmfd a1!, { v1-v7, fp, ip, sp, lr }
+
+#if 0 /* Simulator does not cope with FP instructions yet. */
+#ifndef __SOFTFP__
+ /* Restore floating point registers as well. */
+ lfmfd f4, 4, [a1]
+#endif
+#endif
+ /* Put the return value into the integer result register.
+ But if it is zero then return 1 instead. */
+ movs a1, a2
+ moveq a1, #1
+
+ FUNC_END longjmp
+


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