2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 Copyright (c) 2005 Eliot Dresselhaus
18 Permission is hereby granted, free of charge, to any person obtaining
19 a copy of this software and associated documentation files (the
20 "Software"), to deal in the Software without restriction, including
21 without limitation the rights to use, copy, modify, merge, publish,
22 distribute, sublicense, and/or sell copies of the Software, and to
23 permit persons to whom the Software is furnished to do so, subject to
24 the following conditions:
26 The above copyright notice and this permission notice shall be
27 included in all copies or substantial portions of the Software.
29 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #if defined(__x86_64__)
41 .type clib_setjmp, @function
50 /* Save SP after return. */
54 /* Save PC we are returning to from stack frame. */
58 /* Give back user's return value. */
64 .type clib_longjmp, @function
76 /* Give back user's return value. */
84 .type clib_calljmp, @function
86 /* Make sure stack is 16-byte aligned. */
91 /* Get return address. */
94 /* Switch to new stack. */
97 /* Save return address on new stack. */
100 /* Save old stack pointer on new stack. */
106 /* Move argument into place. */
112 /* Switch back to old stack. */
117 /* Return to caller. */
123 .type clib_setjmp, @function
132 /* Save SP after return. */
136 /* Save PC we are returning to from stack frame. */
140 /* Give back user's return value. */
146 .type clib_longjmp, @function
150 /* Give back user's return value. */
166 .type clib_calljmp, @function
168 /* Get new stack pointer. */
174 /* Save old stack pointer on new stack. */
178 /* Put function argument in stack frame. */
188 /* Switch back to old stack. */
192 /* Return to caller. */
195 #elif defined(__SPU__)
197 #elif defined(__powerpc64__)
201 #define _prologue(n) \
204 .section ".opd", "aw" ; \
206 n: .quad .##n, .TOC.@tocbase, 0 ; \
209 .type .##n, @function ; \
212 #define _foreach_14_31 \
213 _ (14, 0) _ (15, 1) _ (16, 2) _ (17, 3) _ (18, 4) _ (19, 5) \
214 _ (20, 6) _ (21, 7) _ (22, 8) _ (23, 9) _ (24, 10) _ (25, 11) \
215 _ (26, 12) _ (27, 13) _ (28, 14) _ (29, 15) _ (30, 16) _ (31, 17)
217 #define _foreach_20_31 \
218 _ (20, 0) _ (21, 1) _ (22, 2) _ (23, 3) _ (24, 4) _ (25, 5) \
219 _ (26, 6) _ (27, 7) _ (28, 8) _ (29, 9) _ (30, 10) _ (31, 11)
222 #define CLIB_POWERPC_ALTIVEC_N_REGS 12
224 #define CLIB_POWERPC_ALTIVEC_N_REGS 0
227 _prologue (clib_setjmp)
238 #define _(a,b) std a, 8*((b) + 4 + 18*0)(3) ;
243 #define _(a,b) stfd a, 8*((b) + 4 + 18*1)(3) ;
247 #if CLIB_POWERPC_ALTIVEC_N_REGS > 0
250 #define _(a,b) stvx a, 5, 3 ; addi 5, 5, 16 ;
253 #endif /* CLIB_POWERPC_ALTIVEC_N_REGS > 0 */
260 _prologue (clib_longjmp)
271 #define _(a,b) ld a, 8*((b) + 4 + 18*0)(3) ;
276 #define _(a,b) lfd a, 8*((b) + 4 + 18*1)(3) ;
280 #if CLIB_POWERPC_ALTIVEC_N_REGS > 0
283 #define _(a,b) lvx a, 5, 3 ; addi 5, 5, 16 ;
286 #endif /* CLIB_POWERPC_ALTIVEC_N_REGS > 0 */
297 .quad .L.clib_calljmp,.TOC.@tocbase,0
299 .type clib_calljmp, @function
327 .byte 0,0,0,1,128,0,0,0
328 .size clib_calljmp,.-.L.clib_calljmp
330 #elif defined(__powerpc__)
332 #define _foreach_14_31 \
333 _ (14, 0) _ (15, 1) _ (16, 2) _ (17, 3) _ (18, 4) _ (19, 5) \
334 _ (20, 6) _ (21, 7) _ (22, 8) _ (23, 9) _ (24, 10) _ (25, 11) \
335 _ (26, 12) _ (27, 13) _ (28, 14) _ (29, 15) _ (30, 16) _ (31, 17)
337 #define _foreach_20_31 \
338 _ (20, 0) _ (21, 1) _ (22, 2) _ (23, 3) _ (24, 4) _ (25, 5) \
339 _ (26, 6) _ (27, 7) _ (28, 8) _ (29, 9) _ (30, 10) _ (31, 11)
342 #define CLIB_POWERPC_ALTIVEC_N_REGS 12
344 #define CLIB_POWERPC_ALTIVEC_N_REGS 0
349 .type clib_setjmp, @function
356 #if CLIB_POWERPC_ALTIVEC_N_REGS > 0
361 #if CLIB_POWERPC_ALTIVEC_N_REGS > 0
363 #define _(a,b) stvx a, 3, 5 ; addi 5, 5, 16 ;
366 #endif /* CLIB_POWERPC_ALTIVEC_N_REGS > 0 */
369 #define _(a,b) stw a, 4*(1*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 0*18)(3) ;
374 #define _(a,b) stfd a, 4*(2*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 1*18)(3) ;
385 .type clib_longjmp, @function
394 #if CLIB_POWERPC_ALTIVEC_N_REGS > 0
398 #if CLIB_POWERPC_ALTIVEC_N_REGS > 0
400 #define _(a,b) lvx a, 3, 5 ; addi 5, 5, 16 ;
403 #endif /* CLIB_POWERPC_ALTIVEC_N_REGS > 0 */
406 #define _(a,b) lwz a, 4*(1*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 0*18)(3) ;
411 #define _(a,b) lfd a, 4*(2*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 1*18)(3) ;
422 .type clib_calljmp, @function
424 /* Make sure stack is 16 byte aligned. */
429 /* Save old stack/link pointer on new stack. */
434 /* account for (sp, lr) tuple, and keep aligned */
440 /* Move argument into place. */
447 /* back to our synthetic frame */
450 /* Switch back to old stack. */
456 /* Return to caller. */
459 #elif defined(__arm__)
463 .type clib_setjmp, %function
465 mov ip, r0 /* jmp buffer */
467 /* Save integer registers */
468 stmia ip!, {v1-v6, sl, fp, sp, lr}
471 /* Save the call-preserved iWMMXt registers. */
480 /* Give back user's return value. */
486 .type clib_longjmp, %function
488 mov ip, r0 /* jmp buffer */
490 /* Restore integer registers. */
491 ldmia ip!, {v1-v6, sl, fp, sp, lr}
494 /* Save the call-preserved iWMMXt registers. */
503 /* Give back user's return value. */
509 .type clib_calljmp, %function
511 /* Make sure stack is 8 byte aligned. */
514 /* Allocate space for stack/link pointer on new stack. */
517 /* Save old stack/link pointer on new stack. */
524 /* Save function to call. */
527 /* Move argument into place. */
533 /* Switch back to old stack. */
538 /* Return to caller. */
541 #elif defined(__xtensa__)
543 /* FIXME implement if needed. */
546 .type clib_setjmp, %function
552 .type clib_longjmp, @function
558 .type clib_calljmp, %function
562 #elif defined(__TMS320C6X__)
564 /* FIXME implement if needed. */
567 .type clib_setjmp, %function
573 .type clib_longjmp, @function
579 .type clib_calljmp, %function
583 #elif defined(_mips) && __mips == 64
587 .type clib_setjmp, %function
607 .type clib_longjmp, @function
631 .type clib_calljmp, %function
633 /* Force 16 byte alignment of the new stack */
636 /* Save old ra/gp/sp on new stack */
637 daddiu $t0, $t0, (-24)
648 /* Switch back to old ra/gp/sp */
653 /* Return to caller */
657 #elif defined (__aarch64__)
659 Copyright (c) 2011, 2012 ARM Ltd
661 Redistribution and use in source and binary forms, with or without
662 modification, are permitted provided that the following conditions
664 1. Redistributions of source code must retain the above copyright
665 notice, this list of conditions and the following disclaimer.
666 2. Redistributions in binary form must reproduce the above copyright
667 notice, this list of conditions and the following disclaimer in the
668 documentation and/or other materials provided with the distribution.
669 3. The name of the company may not be used to endorse or promote
670 products derived from this software without specific prior written
672 THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED
673 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
674 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
675 IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
676 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
677 TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
678 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
679 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
680 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
681 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
684 REG_PAIR (x19, x20, 0); \
685 REG_PAIR (x21, x22, 16); \
686 REG_PAIR (x23, x24, 32); \
687 REG_PAIR (x25, x26, 48); \
688 REG_PAIR (x27, x28, 64); \
689 REG_PAIR (x29, x30, 80); \
692 REG_PAIR ( d8, d9, 112); \
693 REG_PAIR (d10, d11, 128); \
694 REG_PAIR (d12, d13, 144); \
695 REG_PAIR (d14, d15, 160);
696 // int clib_setjmp (jmp_buf)
698 .type clib_setjmp, %function
701 #define REG_PAIR(REG1, REG2, OFFS) stp REG1, REG2, [x0, OFFS]
702 #define REG_ONE(REG1, OFFS) str REG1, [x0, OFFS]
709 .size clib_setjmp, .-clib_setjmp
710 // void clib_longjmp (jmp_buf, int) __attribute__ ((noreturn))
712 .type clib_longjmp, %function
714 #define REG_PAIR(REG1, REG2, OFFS) ldp REG1, REG2, [x0, OFFS]
715 #define REG_ONE(REG1, OFFS) ldr REG1, [x0, OFFS]
724 // use br not ret, as ret is guaranteed to mispredict
726 .size clib_longjmp, .-clib_longjmp
729 // void clib_calljmp (x0=function, x1=arg, x2=new_stack)
731 .type clib_calljmp, %function
740 // space for saved sp, lr on new stack
744 // save old sp and link register on new stack
752 // restore old sp and link register
759 .size clib_calljmp, .-clib_calljmp
761 #error "unknown machine"
764 .section .note.GNU-stack,"",%progbits