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
584 #error "unknown machine"
587 .section .note.GNU-stack,"",%progbits