Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 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. |
| 14 | */ |
| 15 | /* |
| 16 | Copyright (c) 2005 Eliot Dresselhaus |
| 17 | |
| 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: |
| 25 | |
| 26 | The above copyright notice and this permission notice shall be |
| 27 | included in all copies or substantial portions of the Software. |
| 28 | |
| 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. |
| 36 | */ |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 37 | |
| 38 | #if defined(__APPLE__) |
| 39 | # define cdecl(s) _##s |
| 40 | #else |
| 41 | # define cdecl(s) s |
| 42 | #endif |
| 43 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | #if defined(__x86_64__) |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 45 | .global cdecl(clib_setjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 46 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 47 | #ifndef __APPLE__ |
| 48 | .type cdecl(clib_setjmp), @function |
| 49 | #endif |
| 50 | |
| 51 | cdecl(clib_setjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | movq %rbx, 8*0(%rdi) |
| 53 | movq %rbp, 8*1(%rdi) |
| 54 | movq %r12, 8*2(%rdi) |
| 55 | movq %r13, 8*3(%rdi) |
| 56 | movq %r14, 8*4(%rdi) |
| 57 | movq %r15, 8*5(%rdi) |
| 58 | |
| 59 | /* Save SP after return. */ |
| 60 | leaq 8(%rsp), %rdx |
| 61 | movq %rdx, 8*6(%rdi) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 62 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | /* Save PC we are returning to from stack frame. */ |
| 64 | movq 0(%rsp), %rax |
| 65 | movq %rax, 8*7(%rdi) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 66 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 67 | /* Give back user's return value. */ |
| 68 | movq %rsi, %rax |
| 69 | ret |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 70 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 71 | .global cdecl(clib_longjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 72 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 73 | #ifndef __APPLE__ |
| 74 | .type cdecl(clib_longjmp), @function |
| 75 | #endif |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 76 | cdecl(clib_longjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | /* Restore regs. */ |
| 78 | movq 8*0(%rdi), %rbx |
| 79 | movq 8*1(%rdi), %rbp |
| 80 | movq 8*2(%rdi), %r12 |
| 81 | movq 8*3(%rdi), %r13 |
| 82 | movq 8*4(%rdi), %r14 |
| 83 | movq 8*5(%rdi), %r15 |
| 84 | movq 8*6(%rdi), %rsp |
| 85 | movq 8*7(%rdi), %rdx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 86 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 87 | /* Give back user's return value. */ |
| 88 | movq %rsi, %rax |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 89 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 90 | /* Away we go. */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 91 | jmpq *%rdx |
| 92 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 93 | .global cdecl(clib_calljmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 95 | #ifndef __APPLE__ |
| 96 | .type cdecl(clib_calljmp), @function |
| 97 | #endif |
| 98 | cdecl(clib_calljmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 99 | /* Make sure stack is 16-byte aligned. */ |
| 100 | movq %rdx, %rax |
| 101 | andq $0xf, %rax |
| 102 | subq %rax, %rdx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 103 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 104 | /* Get return address. */ |
| 105 | pop %rax |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 106 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 107 | /* Switch to new stack. */ |
| 108 | xchgq %rsp, %rdx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 109 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 110 | /* Save return address on new stack. */ |
| 111 | push %rax |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 112 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | /* Save old stack pointer on new stack. */ |
| 114 | push %rdx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 115 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | /* Get function. */ |
| 117 | movq %rdi, %rdx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 118 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 119 | /* Move argument into place. */ |
| 120 | movq %rsi, %rdi |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 121 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 122 | /* Away we go. */ |
| 123 | callq *%rdx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 124 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 125 | /* Switch back to old stack. */ |
| 126 | movq 8(%rsp), %rdx |
| 127 | movq 0(%rsp), %rcx |
| 128 | xchgq %rcx, %rsp |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 129 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | /* Return to caller. */ |
| 131 | jmpq *%rdx |
| 132 | |
| 133 | #elif defined(i386) |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 134 | .global cdecl(clib_setjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 136 | .type cdecl(clib_setjmp), @function |
| 137 | cdecl(clib_setjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 138 | movl 4(%esp), %ecx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 139 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 140 | movl %ebp, 4*0(%ecx) |
| 141 | movl %ebx, 4*1(%ecx) |
| 142 | movl %edi, 4*2(%ecx) |
| 143 | movl %esi, 4*3(%ecx) |
| 144 | |
| 145 | /* Save SP after return. */ |
| 146 | leal 4(%esp), %edx |
| 147 | movl %edx, 4*4(%ecx) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 148 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | /* Save PC we are returning to from stack frame. */ |
| 150 | movl 0(%esp), %eax |
| 151 | movl %eax, 4*5(%ecx) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 152 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 153 | /* Give back user's return value. */ |
| 154 | movl 8(%esp), %eax |
| 155 | ret |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 156 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 157 | .global cdecl(clib_longjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 159 | .type cdecl(clib_longjmp), @function |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 160 | cdecl(clib_longjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 161 | movl 4(%esp), %ecx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 162 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 163 | /* Give back user's return value. */ |
| 164 | movl 8(%esp), %eax |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 165 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | /* Restore regs. */ |
| 167 | movl 4*0(%ecx), %ebp |
| 168 | movl 4*1(%ecx), %ebx |
| 169 | movl 4*2(%ecx), %edi |
| 170 | movl 4*3(%ecx), %esi |
| 171 | movl 4*4(%ecx), %esp |
| 172 | movl 4*5(%ecx), %edx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 173 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 174 | /* Away we go. */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 175 | jmp *%edx |
| 176 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 177 | .global cdecl(clib_calljmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 178 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 179 | .type cdecl(clib_calljmp), @function |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 180 | cdecl(clib_calljmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | /* Get new stack pointer. */ |
| 182 | movl 12(%esp), %edx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 183 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 184 | /* Switch stacks. */ |
| 185 | xchgl %esp, %edx |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 186 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 187 | /* Save old stack pointer on new stack. */ |
| 188 | sub $8, %esp |
| 189 | movl %edx, 4(%esp) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 190 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 191 | /* Put function argument in stack frame. */ |
| 192 | movl 8(%edx), %eax |
| 193 | movl %eax, 0(%esp) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 194 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | /* Get function. */ |
| 196 | movl 4(%edx), %eax |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 197 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 198 | /* Away we go. */ |
| 199 | call *%eax |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 200 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 201 | /* Switch back to old stack. */ |
| 202 | movl 4(%esp), %edx |
| 203 | xchgl %edx, %esp |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 204 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 205 | /* Return to caller. */ |
| 206 | ret |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 207 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 208 | #elif defined(__SPU__) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 209 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 210 | #elif defined(__powerpc64__) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 211 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 212 | .text |
| 213 | |
| 214 | #define _prologue(n) \ |
| 215 | .align 2 ; \ |
| 216 | .globl n, .##n ; \ |
| 217 | .section ".opd", "aw" ; \ |
| 218 | .align 3 ; \ |
| 219 | n: .quad .##n, .TOC.@tocbase, 0 ; \ |
| 220 | .previous ; \ |
| 221 | .size n, 24 ; \ |
| 222 | .type .##n, @function ; \ |
| 223 | .##n: |
| 224 | |
| 225 | #define _foreach_14_31 \ |
| 226 | _ (14, 0) _ (15, 1) _ (16, 2) _ (17, 3) _ (18, 4) _ (19, 5) \ |
| 227 | _ (20, 6) _ (21, 7) _ (22, 8) _ (23, 9) _ (24, 10) _ (25, 11) \ |
| 228 | _ (26, 12) _ (27, 13) _ (28, 14) _ (29, 15) _ (30, 16) _ (31, 17) |
| 229 | |
| 230 | #define _foreach_20_31 \ |
| 231 | _ (20, 0) _ (21, 1) _ (22, 2) _ (23, 3) _ (24, 4) _ (25, 5) \ |
| 232 | _ (26, 6) _ (27, 7) _ (28, 8) _ (29, 9) _ (30, 10) _ (31, 11) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 233 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 234 | #ifdef __ALTIVEC__ |
| 235 | #define CLIB_POWERPC_ALTIVEC_N_REGS 12 |
| 236 | #else |
| 237 | #define CLIB_POWERPC_ALTIVEC_N_REGS 0 |
| 238 | #endif |
| 239 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 240 | _prologue (cdecl(clib_setjmp)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 241 | mflr 0 |
| 242 | std 0, 8*0(3) |
| 243 | std 1, 8*1(3) |
| 244 | std 2, 8*2(3) |
| 245 | mfcr 0 |
| 246 | std 0, 8*3(3) |
| 247 | mfspr 0, 256 |
| 248 | stw 0, 8*4(3) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 249 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 250 | /* gprs 14 - 31 */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 251 | #define _(a,b) std a, 8*((b) + 4 + 18*0)(3) ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 252 | _foreach_14_31 |
| 253 | #undef _ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 254 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 255 | /* fprs 14 - 31 */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 256 | #define _(a,b) stfd a, 8*((b) + 4 + 18*1)(3) ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 257 | _foreach_14_31 |
| 258 | #undef _ |
| 259 | |
| 260 | #if CLIB_POWERPC_ALTIVEC_N_REGS > 0 |
| 261 | /* vrs 20 - 31 */ |
| 262 | li 5, 8*(4 + 18*2) |
| 263 | #define _(a,b) stvx a, 5, 3 ; addi 5, 5, 16 ; |
| 264 | _foreach_20_31 |
| 265 | #undef _ |
| 266 | #endif /* CLIB_POWERPC_ALTIVEC_N_REGS > 0 */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 267 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 268 | /* Return value. */ |
| 269 | mr 3, 4 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 270 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 271 | blr |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 272 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 273 | _prologue (cdecl(clib_longjmp)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 274 | ld 0, 8*0(3) |
| 275 | mtlr 0 |
| 276 | ld 1, 8*1(3) |
| 277 | ld 2, 8*2(3) |
| 278 | ld 0, 8*3(3) |
| 279 | mtcrf 0xff, 0 |
| 280 | lwz 0, 8*3(3) |
| 281 | mtspr 256, 0 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 282 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 283 | /* gprs 14 - 31 */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 284 | #define _(a,b) ld a, 8*((b) + 4 + 18*0)(3) ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 285 | _foreach_14_31 |
| 286 | #undef _ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 287 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 288 | /* fprs 14 - 31 */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 289 | #define _(a,b) lfd a, 8*((b) + 4 + 18*1)(3) ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 290 | _foreach_14_31 |
| 291 | #undef _ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 292 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 293 | #if CLIB_POWERPC_ALTIVEC_N_REGS > 0 |
| 294 | /* vrs 20 - 31 */ |
| 295 | li 5, 8*(4 + 18*2) |
| 296 | #define _(a,b) lvx a, 5, 3 ; addi 5, 5, 16 ; |
| 297 | _foreach_20_31 |
| 298 | #undef _ |
| 299 | #endif /* CLIB_POWERPC_ALTIVEC_N_REGS > 0 */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 300 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 301 | /* Return value. */ |
| 302 | mr 3, 4 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 303 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 304 | blr |
| 305 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 306 | .globl cdecl(clib_calljmp) |
Dave Barach | bfdedbd | 2016-01-20 09:11:55 -0500 | [diff] [blame] | 307 | .section ".opd","aw" |
| 308 | .align 3 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 309 | cdecl(clib_calljmp): |
| 310 | .quad .L.cdecl(clib_calljmp),.TOC.@tocbase,0 |
Dave Barach | bfdedbd | 2016-01-20 09:11:55 -0500 | [diff] [blame] | 311 | .previous |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 312 | .type cdecl(clib_calljmp), @function |
| 313 | .L.cdecl(clib_calljmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 314 | mflr 0 |
Dave Barach | bfdedbd | 2016-01-20 09:11:55 -0500 | [diff] [blame] | 315 | mr 9,3 |
| 316 | std 0,16(1) |
| 317 | stdu 1,-112(1) |
| 318 | #APP |
| 319 | std 1,-8(5) |
| 320 | addi 5,5,-256 |
| 321 | mr 1,5 |
| 322 | #NO_APP |
| 323 | ld 10,0(9) |
| 324 | std 2,40(1) |
| 325 | mr 3,4 |
| 326 | mtctr 10 |
| 327 | ld 11,16(9) |
| 328 | ld 2,8(9) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 329 | bctrl |
Dave Barach | bfdedbd | 2016-01-20 09:11:55 -0500 | [diff] [blame] | 330 | ld 2,40(1) |
| 331 | #APP |
| 332 | addi 1,1,256 |
| 333 | ld 1,-8(1) |
| 334 | #NO_APP |
| 335 | addi 1,1,112 |
| 336 | ld 0,16(1) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 337 | mtlr 0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 338 | blr |
Dave Barach | bfdedbd | 2016-01-20 09:11:55 -0500 | [diff] [blame] | 339 | .long 0 |
| 340 | .byte 0,0,0,1,128,0,0,0 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 341 | .size cdecl(clib_calljmp),.-.L.cdecl(clib_calljmp) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 342 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 343 | #elif defined(__powerpc__) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 344 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 345 | #define _foreach_14_31 \ |
| 346 | _ (14, 0) _ (15, 1) _ (16, 2) _ (17, 3) _ (18, 4) _ (19, 5) \ |
| 347 | _ (20, 6) _ (21, 7) _ (22, 8) _ (23, 9) _ (24, 10) _ (25, 11) \ |
| 348 | _ (26, 12) _ (27, 13) _ (28, 14) _ (29, 15) _ (30, 16) _ (31, 17) |
| 349 | |
| 350 | #define _foreach_20_31 \ |
| 351 | _ (20, 0) _ (21, 1) _ (22, 2) _ (23, 3) _ (24, 4) _ (25, 5) \ |
| 352 | _ (26, 6) _ (27, 7) _ (28, 8) _ (29, 9) _ (30, 10) _ (31, 11) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 353 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 354 | #ifdef __ALTIVEC__ |
| 355 | #define CLIB_POWERPC_ALTIVEC_N_REGS 12 |
| 356 | #else |
| 357 | #define CLIB_POWERPC_ALTIVEC_N_REGS 0 |
| 358 | #endif |
| 359 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 360 | .global cdecl(clib_setjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 361 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 362 | .type cdecl(clib_setjmp), @function |
| 363 | cdecl(clib_setjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 364 | mflr 0 |
| 365 | stw 0, 4*0(3) |
| 366 | stw 1, 4*1(3) |
| 367 | mfcr 0 |
| 368 | stw 0, 4*2(3) |
| 369 | #if CLIB_POWERPC_ALTIVEC_N_REGS > 0 |
| 370 | mfspr 0, 256 |
| 371 | #endif |
| 372 | stw 0, 4*3(3) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 373 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 374 | #if CLIB_POWERPC_ALTIVEC_N_REGS > 0 |
| 375 | li 5, 4*4 |
| 376 | #define _(a,b) stvx a, 3, 5 ; addi 5, 5, 16 ; |
| 377 | _foreach_20_31 |
| 378 | #undef _ |
| 379 | #endif /* CLIB_POWERPC_ALTIVEC_N_REGS > 0 */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 380 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 381 | /* gp 14 - 31 */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 382 | #define _(a,b) stw a, 4*(1*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 0*18)(3) ; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 383 | _foreach_14_31 |
| 384 | #undef _ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 385 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 386 | /* fp 14 - 31 */ |
| 387 | #define _(a,b) stfd a, 4*(2*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 1*18)(3) ; |
| 388 | _foreach_14_31 |
| 389 | #undef _ |
| 390 | |
| 391 | /* Return value. */ |
| 392 | mr 3, 4 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 393 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 394 | blr |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 395 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 396 | .global cdecl(clib_longjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 397 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 398 | .type cdecl(clib_longjmp), @function |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 399 | cdecl(clib_longjmp): |
| 400 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 401 | lwz 0, 4*0(3) |
| 402 | mtlr 0 |
| 403 | lwz 1, 4*1(3) |
| 404 | lwz 0, 4*2(3) |
| 405 | mtcr 0 |
| 406 | lwz 0, 4*3(3) |
| 407 | #if CLIB_POWERPC_ALTIVEC_N_REGS > 0 |
| 408 | mtspr 256, 0 |
| 409 | #endif |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 410 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 411 | #if CLIB_POWERPC_ALTIVEC_N_REGS > 0 |
| 412 | li 5, 4*4 |
| 413 | #define _(a,b) lvx a, 3, 5 ; addi 5, 5, 16 ; |
| 414 | _foreach_20_31 |
| 415 | #undef _ |
| 416 | #endif /* CLIB_POWERPC_ALTIVEC_N_REGS > 0 */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 417 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 418 | /* gp 14 - 31 */ |
| 419 | #define _(a,b) lwz a, 4*(1*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 0*18)(3) ; |
| 420 | _foreach_14_31 |
| 421 | #undef _ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 422 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 423 | /* fp 14 - 31 */ |
| 424 | #define _(a,b) lfd a, 4*(2*(b) + 4 + 4*CLIB_POWERPC_ALTIVEC_N_REGS + 1*18)(3) ; |
| 425 | _foreach_14_31 |
| 426 | #undef _ |
| 427 | |
| 428 | /* Return value. */ |
| 429 | mr 3, 4 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 430 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 431 | blr |
| 432 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 433 | .global cdecl(clib_calljmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 434 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 435 | .type cdecl(clib_calljmp), @function |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 436 | cdecl(clib_calljmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 437 | /* Make sure stack is 16 byte aligned. */ |
| 438 | andi. 0, 5, 0xf |
| 439 | sub 5, 5, 0 |
| 440 | addi 5, 5, -16 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 441 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 442 | /* Save old stack/link pointer on new stack. */ |
| 443 | stw 1, 0(5) |
| 444 | mflr 0 |
| 445 | stw 0, 4(5) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 446 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 447 | /* account for (sp, lr) tuple, and keep aligned */ |
| 448 | addi 5, 5, -16 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 449 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 450 | /* Switch stacks. */ |
| 451 | mr 1, 5 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 452 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 453 | /* Move argument into place. */ |
| 454 | mtctr 3 |
| 455 | mr 3, 4 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 456 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 457 | /* Away we go. */ |
| 458 | bctrl |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 459 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 460 | /* back to our synthetic frame */ |
| 461 | addi 1,1,16 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 462 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 463 | /* Switch back to old stack. */ |
| 464 | lwz 0, 4(1) |
| 465 | mtlr 0 |
| 466 | lwz 0, 0(1) |
| 467 | mr 1, 0 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 468 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 469 | /* Return to caller. */ |
| 470 | blr |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 471 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 472 | #elif defined(__arm__) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 473 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 474 | .global cdecl(clib_setjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 475 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 476 | .type cdecl(clib_setjmp), %function |
| 477 | cdecl(clib_setjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 478 | mov ip, r0 /* jmp buffer */ |
| 479 | |
| 480 | /* Save integer registers */ |
| 481 | stmia ip!, {v1-v6, sl, fp, sp, lr} |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 482 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 483 | #ifdef __IWMMXT__ |
| 484 | /* Save the call-preserved iWMMXt registers. */ |
| 485 | wstrd wr10, [ip], #8 |
| 486 | wstrd wr11, [ip], #8 |
| 487 | wstrd wr12, [ip], #8 |
| 488 | wstrd wr13, [ip], #8 |
| 489 | wstrd wr14, [ip], #8 |
| 490 | wstrd wr15, [ip], #8 |
| 491 | #endif |
| 492 | |
| 493 | /* Give back user's return value. */ |
Christophe Fontaine | fef15b4 | 2016-04-09 12:38:49 +0900 | [diff] [blame] | 494 | mov r0, r1 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 495 | bx lr |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 496 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 497 | .global cdecl(clib_longjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 498 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 499 | .type cdecl(clib_longjmp), %function |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 500 | cdecl(clib_longjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 501 | mov ip, r0 /* jmp buffer */ |
| 502 | |
| 503 | /* Restore integer registers. */ |
| 504 | ldmia ip!, {v1-v6, sl, fp, sp, lr} |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 505 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 506 | #ifdef __IWMMXT__ |
| 507 | /* Save the call-preserved iWMMXt registers. */ |
| 508 | wldrd wr10, [ip], #8 |
| 509 | wldrd wr11, [ip], #8 |
| 510 | wldrd wr12, [ip], #8 |
| 511 | wldrd wr13, [ip], #8 |
| 512 | wldrd wr14, [ip], #8 |
| 513 | wldrd wr15, [ip], #8 |
| 514 | #endif |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 515 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 516 | /* Give back user's return value. */ |
Christophe Fontaine | fef15b4 | 2016-04-09 12:38:49 +0900 | [diff] [blame] | 517 | mov r0, r1 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 518 | bx lr |
| 519 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 520 | .global cdecl(clib_calljmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 521 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 522 | .type cdecl(clib_calljmp), %function |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 523 | cdecl(clib_calljmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 524 | /* Make sure stack is 8 byte aligned. */ |
| 525 | bic r2, r2, #7 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 526 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 527 | /* Allocate space for stack/link pointer on new stack. */ |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 528 | sub r2, r2, #8 |
| 529 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 530 | /* Save old stack/link pointer on new stack. */ |
| 531 | str sp, [r2, #0] |
| 532 | str lr, [r2, #4] |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 533 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 534 | /* Switch stacks. */ |
| 535 | mov sp, r2 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 536 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 537 | /* Save function to call. */ |
| 538 | mov ip, r0 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 539 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 540 | /* Move argument into place. */ |
| 541 | mov r0, r1 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 542 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 543 | /* Away we go. */ |
| 544 | bx ip |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 545 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 546 | /* Switch back to old stack. */ |
| 547 | ldr lr, [sp, #4] |
| 548 | ldr ip, [sp, #0] |
| 549 | mov sp, ip |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 550 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 551 | /* Return to caller. */ |
| 552 | bx lr |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 553 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 554 | #elif defined(__xtensa__) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 555 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 556 | /* FIXME implement if needed. */ |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 557 | .global cdecl(clib_setjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 558 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 559 | .type cdecl(clib_setjmp), %function |
| 560 | cdecl(clib_setjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 561 | 1: j 1b |
| 562 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 563 | .global cdecl(clib_longjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 564 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 565 | .type cdecl(clib_longjmp), @function |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 566 | cdecl(clib_longjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 567 | 1: j 1b |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 568 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 569 | .global cdecl(clib_calljmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 570 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 571 | .type cdecl(clib_calljmp), %function |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 572 | cdecl(clib_calljmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 573 | 1: j 1b |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 574 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 575 | #elif defined(__TMS320C6X__) |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 576 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 577 | /* FIXME implement if needed. */ |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 578 | .global cdecl(clib_setjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 579 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 580 | .type cdecl(clib_setjmp), %function |
| 581 | cdecl(clib_setjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 582 | 1: B .S1 1b |
| 583 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 584 | .global cdecl(clib_longjmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 585 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 586 | .type cdecl(clib_longjmp), @function |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 587 | cdecl(clib_longjmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 588 | 1: B .S1 1b |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 589 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 590 | .global cdecl(clib_calljmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 591 | .align 4 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 592 | .type cdecl(clib_calljmp), %function |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 593 | cdecl(clib_calljmp): |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 594 | 1: B .S1 1b |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 595 | |
Carl Smith | 28d4271 | 2018-07-26 15:45:28 +1200 | [diff] [blame] | 596 | #elif defined(_mips) && __mips == 64 |
| 597 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 598 | .global cdecl(clib_setjmp) |
Carl Smith | 28d4271 | 2018-07-26 15:45:28 +1200 | [diff] [blame] | 599 | .align 8 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 600 | .type cdecl(clib_setjmp), %function |
| 601 | cdecl(clib_setjmp): |
Carl Smith | 28d4271 | 2018-07-26 15:45:28 +1200 | [diff] [blame] | 602 | sd $ra, 0($a0) |
| 603 | sd $sp, 8($a0) |
| 604 | sd $gp, 16($a0) |
| 605 | sd $16, 24($a0) |
| 606 | sd $17, 32($a0) |
| 607 | sd $18, 40($a0) |
| 608 | sd $19, 48($a0) |
| 609 | sd $20, 56($a0) |
| 610 | sd $21, 64($a0) |
| 611 | sd $22, 72($a0) |
| 612 | sd $23, 80($a0) |
| 613 | sd $30, 88($a0) |
| 614 | move $v0, $a1 |
| 615 | jr $ra |
| 616 | nop |
| 617 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 618 | .global cdecl(clib_longjmp) |
Carl Smith | 28d4271 | 2018-07-26 15:45:28 +1200 | [diff] [blame] | 619 | .align 8 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 620 | .type cdecl(clib_longjmp), @function |
| 621 | cdecl(clib_longjmp): |
Carl Smith | 28d4271 | 2018-07-26 15:45:28 +1200 | [diff] [blame] | 622 | move $v0, $a1 |
| 623 | bne $v0, $0, 1f |
| 624 | nop |
| 625 | daddu $v0, $v0, 1 |
| 626 | 1: |
| 627 | ld $ra, 0($a0) |
| 628 | ld $sp, 8($a0) |
| 629 | ld $gp, 16($a0) |
| 630 | ld $16, 24($a0) |
| 631 | ld $17, 32($a0) |
| 632 | ld $18, 40($a0) |
| 633 | ld $19, 48($a0) |
| 634 | ld $20, 56($a0) |
| 635 | ld $21, 64($a0) |
| 636 | ld $22, 72($a0) |
| 637 | ld $23, 80($a0) |
| 638 | ld $30, 88($a0) |
| 639 | jr $ra |
| 640 | nop |
| 641 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 642 | .global cdecl(clib_calljmp) |
Carl Smith | 28d4271 | 2018-07-26 15:45:28 +1200 | [diff] [blame] | 643 | .align 8 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 644 | .type cdecl(clib_calljmp), %function |
| 645 | cdecl(clib_calljmp): |
Carl Smith | 28d4271 | 2018-07-26 15:45:28 +1200 | [diff] [blame] | 646 | /* Force 16 byte alignment of the new stack */ |
| 647 | li $t1, -16 |
| 648 | and $t0, $a2, $t1 |
| 649 | /* Save old ra/gp/sp on new stack */ |
| 650 | daddiu $t0, $t0, (-24) |
| 651 | sd $ra, 0($t0) |
| 652 | sd $gp, 8($t0) |
| 653 | sd $sp, 16($t0) |
| 654 | /* Switch stacks */ |
| 655 | move $sp, $t0 |
| 656 | /* Away we go */ |
| 657 | move $t9, $a0 |
| 658 | move $a0, $a1 |
| 659 | jalr $t9 |
| 660 | nop |
| 661 | /* Switch back to old ra/gp/sp */ |
| 662 | move $t0, $sp |
| 663 | ld $ra, 0($t0) |
| 664 | ld $gp, 8($t0) |
| 665 | ld $sp, 16($t0) |
| 666 | /* Return to caller */ |
| 667 | jr $ra |
| 668 | nop |
| 669 | |
Dave Barach | 61efa14 | 2016-01-22 08:23:09 -0500 | [diff] [blame] | 670 | #elif defined (__aarch64__) |
| 671 | /* |
| 672 | Copyright (c) 2011, 2012 ARM Ltd |
| 673 | All rights reserved. |
| 674 | Redistribution and use in source and binary forms, with or without |
| 675 | modification, are permitted provided that the following conditions |
| 676 | are met: |
| 677 | 1. Redistributions of source code must retain the above copyright |
| 678 | notice, this list of conditions and the following disclaimer. |
| 679 | 2. Redistributions in binary form must reproduce the above copyright |
| 680 | notice, this list of conditions and the following disclaimer in the |
| 681 | documentation and/or other materials provided with the distribution. |
| 682 | 3. The name of the company may not be used to endorse or promote |
| 683 | products derived from this software without specific prior written |
| 684 | permission. |
| 685 | THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 686 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 687 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 688 | IN NO EVENT SHALL ARM LTD BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 689 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 690 | TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 691 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 692 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 693 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 694 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 695 | */ |
| 696 | #define GPR_LAYOUT \ |
| 697 | REG_PAIR (x19, x20, 0); \ |
| 698 | REG_PAIR (x21, x22, 16); \ |
| 699 | REG_PAIR (x23, x24, 32); \ |
| 700 | REG_PAIR (x25, x26, 48); \ |
| 701 | REG_PAIR (x27, x28, 64); \ |
| 702 | REG_PAIR (x29, x30, 80); \ |
| 703 | REG_ONE (x16, 96) |
| 704 | #define FPR_LAYOUT \ |
| 705 | REG_PAIR ( d8, d9, 112); \ |
| 706 | REG_PAIR (d10, d11, 128); \ |
| 707 | REG_PAIR (d12, d13, 144); \ |
| 708 | REG_PAIR (d14, d15, 160); |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 709 | // int cdecl(clib_setjmp) (jmp_buf) |
| 710 | .global cdecl(clib_setjmp) |
| 711 | .type cdecl(clib_setjmp), %function |
| 712 | cdecl(clib_setjmp): |
Dave Barach | 61efa14 | 2016-01-22 08:23:09 -0500 | [diff] [blame] | 713 | mov x16, sp |
| 714 | #define REG_PAIR(REG1, REG2, OFFS) stp REG1, REG2, [x0, OFFS] |
| 715 | #define REG_ONE(REG1, OFFS) str REG1, [x0, OFFS] |
| 716 | GPR_LAYOUT |
| 717 | FPR_LAYOUT |
| 718 | #undef REG_PAIR |
| 719 | #undef REG_ONE |
| 720 | mov x0, x1 |
| 721 | ret |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 722 | .size cdecl(clib_setjmp), .-cdecl(clib_setjmp) |
| 723 | // void cdecl(clib_longjmp) (jmp_buf, int) __attribute__ ((noreturn)) |
| 724 | .global cdecl(clib_longjmp) |
| 725 | .type cdecl(clib_longjmp), %function |
| 726 | cdecl(clib_longjmp): |
Dave Barach | 61efa14 | 2016-01-22 08:23:09 -0500 | [diff] [blame] | 727 | #define REG_PAIR(REG1, REG2, OFFS) ldp REG1, REG2, [x0, OFFS] |
| 728 | #define REG_ONE(REG1, OFFS) ldr REG1, [x0, OFFS] |
| 729 | GPR_LAYOUT |
| 730 | FPR_LAYOUT |
| 731 | #undef REG_PAIR |
| 732 | #undef REG_ONE |
| 733 | mov sp, x16 |
| 734 | mov x0, x1 |
| 735 | // cmp w1, #0 |
| 736 | // cinc w0, w1, eq |
| 737 | // use br not ret, as ret is guaranteed to mispredict |
| 738 | br x30 |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 739 | .size cdecl(clib_longjmp), .-cdecl(clib_longjmp) |
Dave Barach | 61efa14 | 2016-01-22 08:23:09 -0500 | [diff] [blame] | 740 | |
| 741 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 742 | // void cdecl(clib_calljmp) (x0=function, x1=arg, x2=new_stack) |
| 743 | .global cdecl(clib_calljmp) |
| 744 | .type cdecl(clib_calljmp), %function |
| 745 | cdecl(clib_calljmp): |
Dave Barach | 61efa14 | 2016-01-22 08:23:09 -0500 | [diff] [blame] | 746 | // save fn ptr |
| 747 | mov x3, x0 |
| 748 | // set up fn arg |
| 749 | mov x0, x1 |
| 750 | // switch stacks |
| 751 | mov x4, sp |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 752 | |
Dave Barach | 61efa14 | 2016-01-22 08:23:09 -0500 | [diff] [blame] | 753 | // space for saved sp, lr on new stack |
| 754 | sub x2, x2, #16 |
| 755 | mov sp, x2 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 756 | |
Dave Barach | 61efa14 | 2016-01-22 08:23:09 -0500 | [diff] [blame] | 757 | // save old sp and link register on new stack |
| 758 | str x4, [sp] |
| 759 | str x30,[sp,#8] |
| 760 | mov x4, sp |
| 761 | |
| 762 | // go there |
| 763 | blr x3 |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 764 | |
Dave Barach | 61efa14 | 2016-01-22 08:23:09 -0500 | [diff] [blame] | 765 | // restore old sp and link register |
| 766 | mov x4, sp |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 767 | |
Dave Barach | 61efa14 | 2016-01-22 08:23:09 -0500 | [diff] [blame] | 768 | ldr x3, [x4] |
| 769 | ldr x30,[x4, #8] |
| 770 | mov sp, x3 |
| 771 | ret |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 772 | .size cdecl(clib_calljmp), .-cdecl(clib_calljmp) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 773 | #else |
| 774 | #error "unknown machine" |
Damjan Marion | d466c0c | 2020-05-16 00:40:48 +0200 | [diff] [blame^] | 775 | #endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 776 | |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 777 | #ifndef __APPLE__ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 778 | .section .note.GNU-stack,"",%progbits |
Damjan Marion | 4dffd1c | 2018-09-03 12:30:36 +0200 | [diff] [blame] | 779 | #endif |