From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1035) id 4599E38493FE; Tue, 13 Dec 2022 15:52:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4599E38493FE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1670946765; bh=zY5YH5Q8iDhpaKFAHOnXaT7urV71L7nFS775xwHWqNE=; h=From:To:Subject:Date:From; b=NTon3ZDJh4+vRmxHMiBzczIXhVKcq/+r3fwJko8dlijzRWihNcqrF9esaQtl82Wkk XFac0DTGn0VQBs1bNSDFM5IiboifAIdklRkr0d2tldTdpW0AM85itLS+5wYnx5zcTU T8nQ0KSE5uWdG3uq+RaqhhEzhR7VuR2/Pf8o4R0Q= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Richard Earnshaw To: cygwin-cvs@sourceware.org, newlib-cvs@sourceware.org Subject: [newlib-cygwin] libc: arm: fix setjmp abi non-conformance X-Act-Checkin: newlib-cygwin X-Git-Author: Victor L. Do Nascimento X-Git-Refname: refs/heads/master X-Git-Oldrev: 90236c3a2cf6eb9aecb6d103612c57db3c14b066 X-Git-Newrev: 15ad816dddf836def06cd0330ec0efa9ce50e5bf Message-Id: <20221213155245.4599E38493FE@sourceware.org> Date: Tue, 13 Dec 2022 15:52:45 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D15ad816dddf= 836def06cd0330ec0efa9ce50e5bf commit 15ad816dddf836def06cd0330ec0efa9ce50e5bf Author: Victor L. Do Nascimento Date: Tue Dec 13 14:51:28 2022 +0000 libc: arm: fix setjmp abi non-conformance =20 As per the arm Procedure Call Standard for the Arm Architecture section 6.1.2 [1], VFP registers s16-s31 (d8-d15, q4-q7) must be preserved across subroutine calls. =20 The current setjmp/longjmp implementations preserve only the core registers, with the jump buffer size too small to store the required co-processor registers. =20 In accordance with the C Library ABI for the Arm Architecture section 6.11 [2], this patch sets _JBTYPE to long long adjusting _JBLEN to 20. =20 It also emits vfp load/store instructions depending on architectural support, predicated at compile time on ACLE feature-test macros. =20 [1] https://github.com/ARM-software/abi-aa/blob/main/aapcs32/aapcs32.rst [2] https://github.com/ARM-software/abi-aa/blob/main/clibabi32/clibabi3= 2.rst Diff: --- COPYING.NEWLIB | 2 +- newlib/libc/include/machine/setjmp.h | 8 +++- newlib/libc/machine/arm/setjmp.S | 74 +++++++++++++++++++-------------= ---- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/COPYING.NEWLIB b/COPYING.NEWLIB index 2d1473639..d54ed293d 100644 --- a/COPYING.NEWLIB +++ b/COPYING.NEWLIB @@ -762,7 +762,7 @@ SUCH DAMAGE. =20 (35) - Arm Ltd =20 - Copyright (c) 2009-2018 Arm Ltd + Copyright (c) 2009-2022 Arm Ltd All rights reserved. =20 Redistribution and use in source and binary forms, with or without diff --git a/newlib/libc/include/machine/setjmp.h b/newlib/libc/include/mac= hine/setjmp.h index 53878a03d..29b76cec1 100644 --- a/newlib/libc/include/machine/setjmp.h +++ b/newlib/libc/include/machine/setjmp.h @@ -12,9 +12,13 @@ _BEGIN_STD_C #if defined(__arm__) || defined(__thumb__) /* * All callee preserved registers: - * v1 - v7, fp, ip, sp, lr, f4, f5, f6, f7 + * core registers: + * r4 - r10, fp, sp, lr + * VFP registers (architectural support dependent): + * d8 - d15 */ -#define _JBLEN 23 +#define _JBLEN 20 +#define _JBTYPE long long #endif =20 #if defined(__aarch64__) diff --git a/newlib/libc/machine/arm/setjmp.S b/newlib/libc/machine/arm/set= jmp.S index 21d6ff9e7..4cf0a8e3f 100644 --- a/newlib/libc/machine/arm/setjmp.S +++ b/newlib/libc/machine/arm/setjmp.S @@ -27,34 +27,34 @@ 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=20 + 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. =20 - We know that we will never attempt to perform the BX instruction on=20 - an older processor, because that kind of processor will never be=20 - interworked, and a return address with the bottom bit set will never=20 + 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. =20 In addition, we do not actually assemble the BX instruction as this wou= ld 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. =20 + we do not want such information stored there. =20 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. =20 - Instead we just do a normal return, since we know that we cannot be=20 + 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. -=09 - Function entry is much simpler. If we are compiling for the Thumb we=20 + + 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. - =20 + For Thumb-2 do everything in Thumb mode. */ =20 .syntax unified @@ -115,15 +115,15 @@ SYM (longjmp): #else #define RET tst lr, #1; \ moveq pc, lr ; \ -.word 0xe12fff1e /* bx lr */ +.inst 0xe12fff1e /* bx lr */ #endif =20 #ifdef __thumb2__ -.macro COND where when=20 +.macro COND where when i\where \when .endm #else -.macro COND where when=20 +.macro COND where when .endm #endif =20 @@ -140,7 +140,7 @@ SYM (longjmp): .macro PROLOGUE name .code 16 bx pc - nop=09 + nop .code 32 SYM (.arm_start_of.\name): .endm @@ -149,7 +149,7 @@ SYM (.arm_start_of.\name): .macro PROLOGUE name .endm #endif -=09 + .macro FUNC_START name .text .align 2 @@ -164,61 +164,65 @@ SYM (\name): RET SIZE (\name) .endm -=09 + /* -------------------------------------------------------------------- - int setjmp (jmp_buf);=20 + int setjmp (jmp_buf); -------------------------------------------------------------------- */ -=09 + FUNC_START setjmp =20 /* Save all the callee-preserved registers into the jump buffer. */ #ifdef __thumb2__ mov ip, sp - stmea a1!, { v1-v7, fp, ip, lr } + stmia r0!, { r4-r10, fp, ip, lr } #else - stmea a1!, { v1-v7, fp, ip, sp, lr } + stmia r0!, { r4-r10, fp, sp, lr } +#endif +#if defined __ARM_FP || defined __ARM_FEATURE_MVE + vstm r0, { d8-d15 } #endif -=09 + #if 0 /* Simulator does not cope with FP instructions yet. */ #ifndef __SOFTFP__ /* Save the floating point registers. */ sfmea f4, 4, [a1] #endif -#endif =09 +#endif /* When setting up the jump buffer return 0. */ - mov a1, #0 + mov r0, #0 =20 FUNC_END setjmp -=09 + /* -------------------------------------------------------------------- volatile void longjmp (jmp_buf, int); -------------------------------------------------------------------- */ -=09 + FUNC_START longjmp =20 /* If we have stack extension code it ought to be handled here. */ -=09 + /* Restore the registers, retrieving the state when setjmp() was called. = */ #ifdef __thumb2__ - ldmfd a1!, { v1-v7, fp, ip, lr } + ldmia r0!, { r4-r10, fp, ip, lr } mov sp, ip #else - ldmfd a1!, { v1-v7, fp, ip, sp, lr } + ldmia r0!, { r4-r10, fp, sp, lr } +#endif +#if defined __ARM_FP || defined __ARM_FEATURE_MVE + vldm r0, { d8-d15 } #endif -=09 + #if 0 /* Simulator does not cope with FP instructions yet. */ #ifndef __SOFTFP__ /* Restore floating point registers as well. */ lfmfd f4, 4, [a1] #endif -#endif=09 +#endif /* Put the return value into the integer result register. - But if it is zero then return 1 instead. */=09 - movs a1, a2 -#ifdef __thumb2__ + But if it is zero then return 1 instead. */ + movs r0, r1 it eq -#endif - moveq a1, #1 + moveq r0, #1 =20 FUNC_END longjmp #endif