From 14d53526bebfd682929d6fd54ec04a4fb03c1673 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Sun, 21 Sep 2014 17:43:17 +0800 Subject: [PATCH] libbase: use __builtin_setjmp and __builtin_longjmp --- software/include/base/setjmp.h | 8 ++- software/libbase/Makefile | 2 +- software/libbase/setjmp-lm32.S | 94 ---------------------------------- software/libbase/setjmp-or1k.S | 66 ------------------------ 4 files changed, 4 insertions(+), 166 deletions(-) delete mode 100644 software/libbase/setjmp-lm32.S delete mode 100644 software/libbase/setjmp-or1k.S diff --git a/software/include/base/setjmp.h b/software/include/base/setjmp.h index a63e846b..ff180966 100644 --- a/software/include/base/setjmp.h +++ b/software/include/base/setjmp.h @@ -5,12 +5,10 @@ extern "C" { #endif -#define _JBLEN 19 +typedef void *jmp_buf[5]; -typedef int jmp_buf[_JBLEN]; - -int setjmp(jmp_buf env); -void longjmp(jmp_buf env, int val); +#define setjmp __builtin_setjmp +#define longjmp __builtin_longjmp #ifdef __cplusplus } diff --git a/software/libbase/Makefile b/software/libbase/Makefile index 5146c330..7d19e84f 100644 --- a/software/libbase/Makefile +++ b/software/libbase/Makefile @@ -1,7 +1,7 @@ MSCDIR=../.. include $(MSCDIR)/software/common.mak -OBJECTS=setjmp-$(CPU).o exception.o libc.o errno.o crc16.o crc32.o console.o system.o id.o uart.o time.o qsort.o strtod.o +OBJECTS=exception.o libc.o errno.o crc16.o crc32.o console.o system.o id.o uart.o time.o qsort.o strtod.o all: crt0-$(CPU).o libbase.a libbase-nofloat.a diff --git a/software/libbase/setjmp-lm32.S b/software/libbase/setjmp-lm32.S deleted file mode 100644 index 666df5e3..00000000 --- a/software/libbase/setjmp-lm32.S +++ /dev/null @@ -1,94 +0,0 @@ -/* - * setjmp/longjmp for LatticeMico32. - * Contributed by Jon Beniston - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - .section .text - .align 4 - - .globl setjmp - .type setjmp,@function - .globl longjmp - .type longjmp,@function - -/* setjmp: save all callee saves into jmp_buf - r1 - Address of jmp_buf -*/ - -setjmp: - sw (r1+0), r11 - sw (r1+4), r12 - sw (r1+8), r13 - sw (r1+12), r14 - sw (r1+16), r15 - sw (r1+20), r16 - sw (r1+24), r17 - sw (r1+28), r18 - sw (r1+32), r19 - sw (r1+36), r20 - sw (r1+40), r21 - sw (r1+44), r22 - sw (r1+48), r23 - sw (r1+52), r24 - sw (r1+56), r25 - sw (r1+60), gp - sw (r1+64), fp - sw (r1+68), sp - sw (r1+72), ra - mvi r1, 0 - ret - -/* longjmp: restore all callee saves from jmp_buf - r1 - Address of jmb_buf - r2 - Value to return with -*/ - - .global longjmp - .type longjmp,@function - .align 4 - -longjmp: - lw r11, (r1+0) - lw r12, (r1+4) - lw r13, (r1+8) - lw r14, (r1+12) - lw r15, (r1+16) - lw r16, (r1+20) - lw r17, (r1+24) - lw r18, (r1+28) - lw r19, (r1+32) - lw r20, (r1+36) - lw r21, (r1+40) - lw r22, (r1+44) - lw r23, (r1+48) - lw r24, (r1+52) - lw r25, (r1+56) - lw gp, (r1+60) - lw fp, (r1+64) - lw sp, (r1+68) - lw ra, (r1+72) - mv r1, r2 - ret - - diff --git a/software/libbase/setjmp-or1k.S b/software/libbase/setjmp-or1k.S deleted file mode 100644 index 590e69a0..00000000 --- a/software/libbase/setjmp-or1k.S +++ /dev/null @@ -1,66 +0,0 @@ -/* setjmp.S. Implementation of setjmp. - - Copyright (C) 2010, Embecosm Limited - - Contributor Jeremy Bennett - - Licensed under 2-clause BSD. -*/ - -/* -------------------------------------------------------------------------- */ -/*!setjmp - - All processor state is saved in the buffer provided. We need not save r0 - (it will always be zero) and we need not save r11 (it will always be - overridden here, and in longjmp). - - @todo We should prefer to save and restore the status register, but this is - not directly possible in user code. There is some merit in code to - set the flag, since in compiled C code, that might be expected to hold - a value. We leave a space for this information for future enhancement. - - @param[out] env(r3) A buffer to save all the current processor state. - - @return zero.*/ -/* -------------------------------------------------------------------------- */ - .align 4 - .global setjmp - .type setjmp,@function -setjmp: - l.sw 4(r3),r1 /* Slot 0 saved for flag in future */ - l.sw 8(r3),r2 - l.sw 12(r3),r3 - l.sw 16(r3),r4 - l.sw 20(r3),r5 - l.sw 24(r3),r6 - l.sw 28(r3),r7 - l.sw 32(r3),r8 - l.sw 36(r3),r9 - l.sw 40(r3),r10 /* Skip r11 */ - l.sw 44(r3),r12 - l.sw 48(r3),r13 - l.sw 52(r3),r14 - l.sw 56(r3),r15 - l.sw 60(r3),r16 - l.sw 64(r3),r17 - l.sw 68(r3),r18 - l.sw 72(r3),r19 - l.sw 76(r3),r20 - l.sw 80(r3),r21 - l.sw 84(r3),r22 - l.sw 88(r3),r23 - l.sw 92(r3),r24 - l.sw 96(r3),r25 - l.sw 100(r3),r26 - l.sw 104(r3),r27 - l.sw 108(r3),r28 - l.sw 112(r3),r29 - l.sw 116(r3),r30 - l.sw 120(r3),r31 - - - l.jr r9 - l.addi r11,r0,0 /* Zero result */ - - - .size setjmp, .-setjmp -- 2.30.2