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 */
293 _prologue (clib_calljmp)
294 /* Make sure stack is 16 byte aligned. */
299 /* Save old stack/link pointer on new stack. */
307 /* Get function pointer. */
311 /* Move argument into place. */
317 /* Switch back to old stack. */
323 /* Return to caller. */
326 #elif defined(__powerpc__)
328 #define _foreach_14_31 \
329 _ (14, 0) _ (15, 1) _ (16, 2) _ (17, 3) _ (18, 4) _ (19, 5) \
330 _ (20, 6) _ (21, 7) _ (22, 8) _ (23, 9) _ (24, 10) _ (25, 11) \
331 _ (26, 12) _ (27, 13) _ (28, 14) _ (29, 15) _ (30, 16) _ (31, 17)
333 #define _foreach_20_31 \
334 _ (20, 0) _ (21, 1) _ (22, 2) _ (23, 3) _ (24, 4) _ (25, 5) \
335 _ (26, 6) _ (27, 7) _ (28, 8) _ (29, 9) _ (30, 10) _ (31, 11)
338 #define CLIB_POWERPC_ALTIVEC_N_REGS 12
340 #define CLIB_POWERPC_ALTIVEC_N_REGS 0
345 .type clib_setjmp, @function
352 #if CLIB_POWERPC_ALTIVEC_N_REGS > 0
357 #if CLIB_POWERPC_ALTIVEC_N_REGS > 0
359 #define _(a,b) stvx a, 3, 5 ; addi 5, 5, 16 ;
362 #endif /* CLIB_POWERPC_ALTIVEC_N_REGS > 0 */
365 #define _(a,b) stw a, 4*(1*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 0*18)(3) ;
370 #define _(a,b) stfd a, 4*(2*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 1*18)(3) ;
381 .type clib_longjmp, @function
390 #if CLIB_POWERPC_ALTIVEC_N_REGS > 0
394 #if CLIB_POWERPC_ALTIVEC_N_REGS > 0
396 #define _(a,b) lvx a, 3, 5 ; addi 5, 5, 16 ;
399 #endif /* CLIB_POWERPC_ALTIVEC_N_REGS > 0 */
402 #define _(a,b) lwz a, 4*(1*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 0*18)(3) ;
407 #define _(a,b) lfd a, 4*(2*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 1*18)(3) ;
418 .type clib_calljmp, @function
420 /* Make sure stack is 16 byte aligned. */
425 /* Save old stack/link pointer on new stack. */
430 /* account for (sp, lr) tuple, and keep aligned */
436 /* Move argument into place. */
443 /* back to our synthetic frame */
446 /* Switch back to old stack. */
452 /* Return to caller. */
455 #elif defined(__arm__)
459 .type clib_setjmp, %function
461 mov ip, r0 /* jmp buffer */
463 /* Save integer registers */
464 stmia ip!, {v1-v6, sl, fp, sp, lr}
467 /* Save the call-preserved iWMMXt registers. */
476 /* Give back user's return value. */
482 .type clib_longjmp, %function
484 mov ip, r0 /* jmp buffer */
486 /* Restore integer registers. */
487 ldmia ip!, {v1-v6, sl, fp, sp, lr}
490 /* Save the call-preserved iWMMXt registers. */
499 /* Give back user's return value. */
505 .type clib_calljmp, %function
507 /* Make sure stack is 8 byte aligned. */
510 /* Allocate space for stack/link pointer on new stack. */
513 /* Save old stack/link pointer on new stack. */
520 /* Save function to call. */
523 /* Move argument into place. */
529 /* Switch back to old stack. */
534 /* Return to caller. */
537 #elif defined(__xtensa__)
539 /* FIXME implement if needed. */
542 .type clib_setjmp, %function
548 .type clib_longjmp, @function
554 .type clib_calljmp, %function
558 #elif defined(__TMS320C6X__)
560 /* FIXME implement if needed. */
563 .type clib_setjmp, %function
569 .type clib_longjmp, @function
575 .type clib_calljmp, %function
580 #error "unknown machine"
583 .section .note.GNU-stack,"",%progbits