1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#if !defined(__wasm__)
10
11#include "assembly.h"
12
13#define FROM_0_TO_15 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
14#define FROM_16_TO_31 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
15
16#define FROM_0_TO_31 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
17#define FROM_32_TO_63 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63
18
19#if defined(_AIX)
20 .toc
21#elif defined(__aarch64__) && defined(__ELF__) && defined(_LIBUNWIND_EXECUTE_ONLY_CODE)
22 .section .text,"axy",@progbits,unique,0
23#else
24 .text
25#endif
26
27#if !defined(__USING_SJLJ_EXCEPTIONS__)
28
29#if defined(__i386__)
30.att_syntax
31
32DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_jumpto)
33#
34# extern "C" void __libunwind_Registers_x86_jumpto(Registers_x86 *);
35#
36# On entry:
37# + +
38# +-----------------------+
39# + thread_state pointer +
40# +-----------------------+
41# + return address +
42# +-----------------------+ <-- SP
43# + +
44
45 _LIBUNWIND_CET_ENDBR
46 movl 4(%esp), %eax
47 # set up eax and ret on new stack location
48 movl 28(%eax), %edx # edx holds new stack pointer
49 subl $8,%edx
50 movl %edx, 28(%eax)
51 movl 0(%eax), %ebx
52 movl %ebx, 0(%edx)
53 movl 40(%eax), %ebx
54 movl %ebx, 4(%edx)
55 # we now have ret and eax pushed onto where new stack will be
56 # restore all registers
57 movl 4(%eax), %ebx
58 movl 8(%eax), %ecx
59 movl 12(%eax), %edx
60 movl 16(%eax), %edi
61 movl 20(%eax), %esi
62 movl 24(%eax), %ebp
63 movl 28(%eax), %esp
64 # skip ss
65 # skip eflags
66 pop %eax # eax was already pushed on new stack
67 pop %ecx
68 jmp *%ecx
69 # skip cs
70 # skip ds
71 # skip es
72 # skip fs
73 # skip gs
74
75// Native FreeBSD restores selectors and bases together through sigreturn in
76// libunwind.cpp; its sysarch base setters also replace the segment selectors.
77#elif defined(__x86_64__) && !defined(__arm64ec__) && \
78 (!defined(__FreeBSD__) || defined(_LIBUNWIND_IS_BAREMETAL))
79.att_syntax
80
81DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_x86_64_jumpto)
82#
83# extern "C" void __libunwind_Registers_x86_64_jumpto(Registers_x86_64 *);
84#
85#if defined(_WIN64)
86# On entry, thread_state pointer is in rcx; move it into rdi
87# to share restore code below. Since this routine restores and
88# overwrites all registers, we can use the same registers for
89# pointers and temporaries as on unix even though win64 normally
90# mustn't clobber some of them.
91 movq %rcx, %rdi
92#else
93# On entry, thread_state pointer is in rdi
94#endif
95
96 _LIBUNWIND_CET_ENDBR
97 movq 56(%rdi), %rax # rax holds new stack pointer
98 subq $16, %rax
99 movq %rax, 56(%rdi)
100 movq 32(%rdi), %rbx # store new rdi on new stack
101 movq %rbx, 0(%rax)
102 movq 128(%rdi), %rbx # store new rip on new stack
103 movq %rbx, 8(%rax)
104 # restore all registers
105 movq 0(%rdi), %rax
106 movq 8(%rdi), %rbx
107 movq 16(%rdi), %rcx
108 movq 24(%rdi), %rdx
109 # restore rdi later
110 movq 40(%rdi), %rsi
111 movq 48(%rdi), %rbp
112 # restore rsp later
113 movq 64(%rdi), %r8
114 movq 72(%rdi), %r9
115 movq 80(%rdi), %r10
116 movq 88(%rdi), %r11
117 movq 96(%rdi), %r12
118 movq 104(%rdi), %r13
119# Skip reloading r14/r15 under LFI; reserved by LFI ABI.
120#if !defined(__LFI__)
121 movq 112(%rdi), %r14
122 movq 120(%rdi), %r15
123#endif
124 # skip rflags
125 # skip cs
126 # skip fs
127 # skip gs
128
129#if defined(_WIN64)
130 movdqu 176(%rdi),%xmm0
131 movdqu 192(%rdi),%xmm1
132 movdqu 208(%rdi),%xmm2
133 movdqu 224(%rdi),%xmm3
134 movdqu 240(%rdi),%xmm4
135 movdqu 256(%rdi),%xmm5
136 movdqu 272(%rdi),%xmm6
137 movdqu 288(%rdi),%xmm7
138 movdqu 304(%rdi),%xmm8
139 movdqu 320(%rdi),%xmm9
140 movdqu 336(%rdi),%xmm10
141 movdqu 352(%rdi),%xmm11
142 movdqu 368(%rdi),%xmm12
143 movdqu 384(%rdi),%xmm13
144 movdqu 400(%rdi),%xmm14
145 movdqu 416(%rdi),%xmm15
146#endif
147 movq 56(%rdi), %rsp # cut back rsp to new location
148 pop %rdi # rdi was saved here earlier
149 pop %rcx
150 jmpq *%rcx
151
152
153#elif defined(__powerpc64__)
154
155DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_ppc646jumptoEv)
156//
157// void libunwind::Registers_ppc64::jumpto()
158//
159// On entry:
160// thread_state pointer is in r3
161//
162
163// load register (GPR)
164#define PPC64_LR(n) \
165 ld n, (8 * (n + 2))(3)
166
167 // restore integral registers
168 // skip r0 for now
169 // skip r1 for now
170 PPC64_LR(2)
171 // skip r3 for now
172 // skip r4 for now
173 // skip r5 for now
174 PPC64_LR(6)
175 PPC64_LR(7)
176 PPC64_LR(8)
177 PPC64_LR(9)
178 PPC64_LR(10)
179 PPC64_LR(11)
180 PPC64_LR(12)
181 PPC64_LR(13)
182 PPC64_LR(14)
183 PPC64_LR(15)
184 PPC64_LR(16)
185 PPC64_LR(17)
186 PPC64_LR(18)
187 PPC64_LR(19)
188 PPC64_LR(20)
189 PPC64_LR(21)
190 PPC64_LR(22)
191 PPC64_LR(23)
192 PPC64_LR(24)
193 PPC64_LR(25)
194 PPC64_LR(26)
195 PPC64_LR(27)
196 PPC64_LR(28)
197 PPC64_LR(29)
198 PPC64_LR(30)
199 PPC64_LR(31)
200
201#if defined(__VSX__)
202
203 // restore VS registers
204 // (note that this also restores floating point registers and V registers,
205 // because part of VS is mapped to these registers)
206
207 addi 4, 3, PPC64_OFFS_FP
208
209// load VS register
210#ifdef __LITTLE_ENDIAN__
211// For little-endian targets, we need a swap since lxvd2x will load the register
212// in the incorrect doubleword order.
213// FIXME: when supporting targets older than Power9 on LE is no longer required,
214// this can be changed to simply `lxv n, (16 * n)(4)`.
215#define PPC64_LVS(n) \
216 lxvd2x n, 0, 4 ;\
217 xxswapd n, n ;\
218 addi 4, 4, 16
219#else
220#define PPC64_LVS(n) \
221 lxvd2x n, 0, 4 ;\
222 addi 4, 4, 16
223#endif
224
225 // restore the first 32 VS regs (and also all floating point regs)
226 PPC64_LVS(0)
227 PPC64_LVS(1)
228 PPC64_LVS(2)
229 PPC64_LVS(3)
230 PPC64_LVS(4)
231 PPC64_LVS(5)
232 PPC64_LVS(6)
233 PPC64_LVS(7)
234 PPC64_LVS(8)
235 PPC64_LVS(9)
236 PPC64_LVS(10)
237 PPC64_LVS(11)
238 PPC64_LVS(12)
239 PPC64_LVS(13)
240 PPC64_LVS(14)
241 PPC64_LVS(15)
242 PPC64_LVS(16)
243 PPC64_LVS(17)
244 PPC64_LVS(18)
245 PPC64_LVS(19)
246 PPC64_LVS(20)
247 PPC64_LVS(21)
248 PPC64_LVS(22)
249 PPC64_LVS(23)
250 PPC64_LVS(24)
251 PPC64_LVS(25)
252 PPC64_LVS(26)
253 PPC64_LVS(27)
254 PPC64_LVS(28)
255 PPC64_LVS(29)
256 PPC64_LVS(30)
257 PPC64_LVS(31)
258
259#ifdef __LITTLE_ENDIAN__
260#define PPC64_CLVS_RESTORE(n) \
261 addi 4, 3, PPC64_OFFS_FP + n * 16 ;\
262 lxvd2x n, 0, 4 ;\
263 xxswapd n, n
264#else
265#define PPC64_CLVS_RESTORE(n) \
266 addi 4, 3, PPC64_OFFS_FP + n * 16 ;\
267 lxvd2x n, 0, 4
268#endif
269
270#if !defined(_AIX)
271 // use VRSAVE to conditionally restore the remaining VS regs, that are
272 // where the V regs are mapped. In the AIX ABI, VRSAVE is not used.
273 ld 5, PPC64_OFFS_VRSAVE(3) // test VRsave
274 cmpwi 5, 0
275 beq Lnovec
276
277// conditionally load VS
278#define PPC64_CLVSl(n) \
279 andis. 0, 5, (1 PPC_LEFT_SHIFT(47-n)) ;\
280 beq Ldone##n ;\
281 PPC64_CLVS_RESTORE(n) ;\
282Ldone##n:
283
284#define PPC64_CLVSh(n) \
285 andi. 0, 5, (1 PPC_LEFT_SHIFT(63-n)) ;\
286 beq Ldone##n ;\
287 PPC64_CLVS_RESTORE(n) ;\
288Ldone##n:
289
290#else
291
292#define PPC64_CLVSl(n) PPC64_CLVS_RESTORE(n)
293#define PPC64_CLVSh(n) PPC64_CLVS_RESTORE(n)
294
295#endif // !defined(_AIX)
296
297 PPC64_CLVSl(32)
298 PPC64_CLVSl(33)
299 PPC64_CLVSl(34)
300 PPC64_CLVSl(35)
301 PPC64_CLVSl(36)
302 PPC64_CLVSl(37)
303 PPC64_CLVSl(38)
304 PPC64_CLVSl(39)
305 PPC64_CLVSl(40)
306 PPC64_CLVSl(41)
307 PPC64_CLVSl(42)
308 PPC64_CLVSl(43)
309 PPC64_CLVSl(44)
310 PPC64_CLVSl(45)
311 PPC64_CLVSl(46)
312 PPC64_CLVSl(47)
313 PPC64_CLVSh(48)
314 PPC64_CLVSh(49)
315 PPC64_CLVSh(50)
316 PPC64_CLVSh(51)
317 PPC64_CLVSh(52)
318 PPC64_CLVSh(53)
319 PPC64_CLVSh(54)
320 PPC64_CLVSh(55)
321 PPC64_CLVSh(56)
322 PPC64_CLVSh(57)
323 PPC64_CLVSh(58)
324 PPC64_CLVSh(59)
325 PPC64_CLVSh(60)
326 PPC64_CLVSh(61)
327 PPC64_CLVSh(62)
328 PPC64_CLVSh(63)
329
330#else
331
332// load FP register
333#define PPC64_LF(n) \
334 lfd n, (PPC64_OFFS_FP + n * 16)(3)
335
336 // restore float registers
337 PPC64_LF(0)
338 PPC64_LF(1)
339 PPC64_LF(2)
340 PPC64_LF(3)
341 PPC64_LF(4)
342 PPC64_LF(5)
343 PPC64_LF(6)
344 PPC64_LF(7)
345 PPC64_LF(8)
346 PPC64_LF(9)
347 PPC64_LF(10)
348 PPC64_LF(11)
349 PPC64_LF(12)
350 PPC64_LF(13)
351 PPC64_LF(14)
352 PPC64_LF(15)
353 PPC64_LF(16)
354 PPC64_LF(17)
355 PPC64_LF(18)
356 PPC64_LF(19)
357 PPC64_LF(20)
358 PPC64_LF(21)
359 PPC64_LF(22)
360 PPC64_LF(23)
361 PPC64_LF(24)
362 PPC64_LF(25)
363 PPC64_LF(26)
364 PPC64_LF(27)
365 PPC64_LF(28)
366 PPC64_LF(29)
367 PPC64_LF(30)
368 PPC64_LF(31)
369
370#if defined(__ALTIVEC__)
371
372#define PPC64_CLV_UNALIGNED_RESTORE(n) \
373 ld 0, (PPC64_OFFS_V + n * 16)(3) ;\
374 std 0, 0(4) ;\
375 ld 0, (PPC64_OFFS_V + n * 16 + 8)(3) ;\
376 std 0, 8(4) ;\
377 lvx n, 0, 4
378
379#if !defined(_AIX)
380 // restore vector registers if any are in use. In the AIX ABI, VRSAVE is
381 // not used.
382 ld 5, PPC64_OFFS_VRSAVE(3) // test VRsave
383 cmpwi 5, 0
384 beq Lnovec
385
386#define PPC64_CLV_UNALIGNEDl(n) \
387 andis. 0, 5, (1 PPC_LEFT_SHIFT(15-n)) ;\
388 beq Ldone##n ;\
389 PPC64_CLV_UNALIGNED_RESTORE(n) ;\
390Ldone ## n:
391
392#define PPC64_CLV_UNALIGNEDh(n) \
393 andi. 0, 5, (1 PPC_LEFT_SHIFT(31-n)) ;\
394 beq Ldone##n ;\
395 PPC64_CLV_UNALIGNED_RESTORE(n) ;\
396Ldone ## n:
397
398#else
399
400#define PPC64_CLV_UNALIGNEDl(n) PPC64_CLV_UNALIGNED_RESTORE(n)
401#define PPC64_CLV_UNALIGNEDh(n) PPC64_CLV_UNALIGNED_RESTORE(n)
402
403#endif // !defined(_AIX)
404
405 subi 4, 1, 16
406 // r4 is now a 16-byte aligned pointer into the red zone
407 // the _vectorScalarRegisters may not be 16-byte aligned
408 // so copy via red zone temp buffer
409
410 PPC64_CLV_UNALIGNEDl(0)
411 PPC64_CLV_UNALIGNEDl(1)
412 PPC64_CLV_UNALIGNEDl(2)
413 PPC64_CLV_UNALIGNEDl(3)
414 PPC64_CLV_UNALIGNEDl(4)
415 PPC64_CLV_UNALIGNEDl(5)
416 PPC64_CLV_UNALIGNEDl(6)
417 PPC64_CLV_UNALIGNEDl(7)
418 PPC64_CLV_UNALIGNEDl(8)
419 PPC64_CLV_UNALIGNEDl(9)
420 PPC64_CLV_UNALIGNEDl(10)
421 PPC64_CLV_UNALIGNEDl(11)
422 PPC64_CLV_UNALIGNEDl(12)
423 PPC64_CLV_UNALIGNEDl(13)
424 PPC64_CLV_UNALIGNEDl(14)
425 PPC64_CLV_UNALIGNEDl(15)
426 PPC64_CLV_UNALIGNEDh(16)
427 PPC64_CLV_UNALIGNEDh(17)
428 PPC64_CLV_UNALIGNEDh(18)
429 PPC64_CLV_UNALIGNEDh(19)
430 PPC64_CLV_UNALIGNEDh(20)
431 PPC64_CLV_UNALIGNEDh(21)
432 PPC64_CLV_UNALIGNEDh(22)
433 PPC64_CLV_UNALIGNEDh(23)
434 PPC64_CLV_UNALIGNEDh(24)
435 PPC64_CLV_UNALIGNEDh(25)
436 PPC64_CLV_UNALIGNEDh(26)
437 PPC64_CLV_UNALIGNEDh(27)
438 PPC64_CLV_UNALIGNEDh(28)
439 PPC64_CLV_UNALIGNEDh(29)
440 PPC64_CLV_UNALIGNEDh(30)
441 PPC64_CLV_UNALIGNEDh(31)
442
443#endif
444#endif
445
446Lnovec:
447 ld 0, PPC64_OFFS_CR(3)
448 mtcr 0
449 ld 0, PPC64_OFFS_SRR0(3)
450 mtctr 0
451
452#if defined(_AIX)
453 // After setting GPR1 to a higher address, AIX wipes out the original
454 // stack space below that address invalidated by the new GPR1 value. Use
455 // GPR0 to save the value of GPR3 in the context before it is wiped out.
456 // This compromises the content of GPR0 which is a volatile register.
457 ld 0, (8 * (3 + 2))(3)
458#else
459 PPC64_LR(0)
460#endif
461 PPC64_LR(5)
462 PPC64_LR(4)
463 PPC64_LR(1)
464#if defined(_AIX)
465 mr 3, 0
466#else
467 PPC64_LR(3)
468#endif
469 bctr
470
471#elif defined(__powerpc__)
472
473DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_ppc6jumptoEv)
474//
475// void libunwind::Registers_ppc::jumpto()
476//
477// On entry:
478// thread_state pointer is in r3
479//
480
481 // restore integral registers
482 // skip r0 for now
483 // skip r1 for now
484 lwz 2, 16(3)
485 // skip r3 for now
486 // skip r4 for now
487 // skip r5 for now
488 lwz 6, 32(3)
489 lwz 7, 36(3)
490 lwz 8, 40(3)
491 lwz 9, 44(3)
492 lwz 10, 48(3)
493 lwz 11, 52(3)
494 lwz 12, 56(3)
495 lwz 13, 60(3)
496 lwz 14, 64(3)
497 lwz 15, 68(3)
498 lwz 16, 72(3)
499 lwz 17, 76(3)
500 lwz 18, 80(3)
501 lwz 19, 84(3)
502 lwz 20, 88(3)
503 lwz 21, 92(3)
504 lwz 22, 96(3)
505 lwz 23,100(3)
506 lwz 24,104(3)
507 lwz 25,108(3)
508 lwz 26,112(3)
509 lwz 27,116(3)
510 lwz 28,120(3)
511 lwz 29,124(3)
512 lwz 30,128(3)
513 lwz 31,132(3)
514
515#ifndef __NO_FPRS__
516 // restore float registers
517 lfd 0, 160(3)
518 lfd 1, 168(3)
519 lfd 2, 176(3)
520 lfd 3, 184(3)
521 lfd 4, 192(3)
522 lfd 5, 200(3)
523 lfd 6, 208(3)
524 lfd 7, 216(3)
525 lfd 8, 224(3)
526 lfd 9, 232(3)
527 lfd 10,240(3)
528 lfd 11,248(3)
529 lfd 12,256(3)
530 lfd 13,264(3)
531 lfd 14,272(3)
532 lfd 15,280(3)
533 lfd 16,288(3)
534 lfd 17,296(3)
535 lfd 18,304(3)
536 lfd 19,312(3)
537 lfd 20,320(3)
538 lfd 21,328(3)
539 lfd 22,336(3)
540 lfd 23,344(3)
541 lfd 24,352(3)
542 lfd 25,360(3)
543 lfd 26,368(3)
544 lfd 27,376(3)
545 lfd 28,384(3)
546 lfd 29,392(3)
547 lfd 30,400(3)
548 lfd 31,408(3)
549#endif
550
551#if defined(__ALTIVEC__)
552
553#define LOAD_VECTOR_RESTORE(_index) \
554 lwz 0, 424+_index*16(3) SEPARATOR \
555 stw 0, 0(4) SEPARATOR \
556 lwz 0, 424+_index*16+4(3) SEPARATOR \
557 stw 0, 4(4) SEPARATOR \
558 lwz 0, 424+_index*16+8(3) SEPARATOR \
559 stw 0, 8(4) SEPARATOR \
560 lwz 0, 424+_index*16+12(3) SEPARATOR \
561 stw 0, 12(4) SEPARATOR \
562 lvx _index, 0, 4
563
564#if !defined(_AIX)
565 // restore vector registers if any are in use. In the AIX ABI, VRSAVE
566 // is not used.
567 lwz 5, 156(3) // test VRsave
568 cmpwi 5, 0
569 beq Lnovec
570
571#define LOAD_VECTOR_UNALIGNEDl(_index) \
572 andis. 0, 5, (1 PPC_LEFT_SHIFT(15-_index)) SEPARATOR \
573 beq Ldone ## _index SEPARATOR \
574 LOAD_VECTOR_RESTORE(_index) SEPARATOR \
575 Ldone ## _index:
576
577#define LOAD_VECTOR_UNALIGNEDh(_index) \
578 andi. 0, 5, (1 PPC_LEFT_SHIFT(31-_index)) SEPARATOR \
579 beq Ldone ## _index SEPARATOR \
580 LOAD_VECTOR_RESTORE(_index) SEPARATOR \
581 Ldone ## _index:
582
583#else
584
585#define LOAD_VECTOR_UNALIGNEDl(_index) LOAD_VECTOR_RESTORE(_index)
586#define LOAD_VECTOR_UNALIGNEDh(_index) LOAD_VECTOR_RESTORE(_index)
587
588#endif // !defined(_AIX)
589
590 subi 4, 1, 16
591 rlwinm 4, 4, 0, 0, 27 // mask low 4-bits
592 // r4 is now a 16-byte aligned pointer into the red zone
593 // the _vectorRegisters may not be 16-byte aligned so copy via red zone temp buffer
594
595 LOAD_VECTOR_UNALIGNEDl(0)
596 LOAD_VECTOR_UNALIGNEDl(1)
597 LOAD_VECTOR_UNALIGNEDl(2)
598 LOAD_VECTOR_UNALIGNEDl(3)
599 LOAD_VECTOR_UNALIGNEDl(4)
600 LOAD_VECTOR_UNALIGNEDl(5)
601 LOAD_VECTOR_UNALIGNEDl(6)
602 LOAD_VECTOR_UNALIGNEDl(7)
603 LOAD_VECTOR_UNALIGNEDl(8)
604 LOAD_VECTOR_UNALIGNEDl(9)
605 LOAD_VECTOR_UNALIGNEDl(10)
606 LOAD_VECTOR_UNALIGNEDl(11)
607 LOAD_VECTOR_UNALIGNEDl(12)
608 LOAD_VECTOR_UNALIGNEDl(13)
609 LOAD_VECTOR_UNALIGNEDl(14)
610 LOAD_VECTOR_UNALIGNEDl(15)
611 LOAD_VECTOR_UNALIGNEDh(16)
612 LOAD_VECTOR_UNALIGNEDh(17)
613 LOAD_VECTOR_UNALIGNEDh(18)
614 LOAD_VECTOR_UNALIGNEDh(19)
615 LOAD_VECTOR_UNALIGNEDh(20)
616 LOAD_VECTOR_UNALIGNEDh(21)
617 LOAD_VECTOR_UNALIGNEDh(22)
618 LOAD_VECTOR_UNALIGNEDh(23)
619 LOAD_VECTOR_UNALIGNEDh(24)
620 LOAD_VECTOR_UNALIGNEDh(25)
621 LOAD_VECTOR_UNALIGNEDh(26)
622 LOAD_VECTOR_UNALIGNEDh(27)
623 LOAD_VECTOR_UNALIGNEDh(28)
624 LOAD_VECTOR_UNALIGNEDh(29)
625 LOAD_VECTOR_UNALIGNEDh(30)
626 LOAD_VECTOR_UNALIGNEDh(31)
627#endif
628
629Lnovec:
630 lwz 0, 136(3) // __cr
631 mtcr 0
632 lwz 0, 148(3) // __ctr
633 mtctr 0
634 lwz 0, 0(3) // __ssr0
635 mtctr 0
636 lwz 0, 8(3) // do r0 now
637 lwz 5, 28(3) // do r5 now
638 lwz 4, 24(3) // do r4 now
639 lwz 1, 12(3) // do sp now
640 lwz 3, 20(3) // do r3 last
641 bctr
642
643#elif defined(__aarch64__)
644
645#ifndef __has_feature
646#define __has_feature(__feature) 0
647#endif
648
649#if defined(__ARM_FEATURE_GCS_DEFAULT)
650.arch_extension gcs
651#endif
652
653//
654// extern "C" void __libunwind_Registers_arm64_jumpto(Registers_arm64 *, unsigned);
655//
656// On entry:
657// thread_state pointer is in x0
658// walked_frames counter is in x1
659//
660 .p2align 2
661DEFINE_LIBUNWIND_FUNCTION(__libunwind_Registers_arm64_jumpto)
662
663 #if defined(_LIBUNWIND_TRACE_RET_INJECT)
664 cbz w1, 1f
665 0:
666 subs w1, w1, #1
667 adr x16, #8
668 ret x16
669
670 b.ne 0b
671 1:
672 #endif
673
674 // skip restore of x0,x1 for now
675 ldp x2, x3, [x0, #0x010]
676 ldp x4, x5, [x0, #0x020]
677 ldp x6, x7, [x0, #0x030]
678 ldp x8, x9, [x0, #0x040]
679 ldp x10,x11, [x0, #0x050]
680 ldp x12,x13, [x0, #0x060]
681 ldp x14,x15, [x0, #0x070]
682 // x16 and x17 were clobbered by the call into the unwinder, so no point in
683 // restoring them.
684 ldp x18,x19, [x0, #0x090]
685 ldp x20,x21, [x0, #0x0A0]
686 ldp x22,x23, [x0, #0x0B0]
687#if defined(__LFI__)
688 ldr x24, [x0, #0x0C0]
689 // Skip reloading x25-x28; reserved by LFI ABI.
690 ldr x29, [x0, #0x0E8]
691#else
692 ldp x24,x25, [x0, #0x0C0]
693 ldp x26,x27, [x0, #0x0D0]
694 ldp x28,x29, [x0, #0x0E0]
695#endif
696
697#if defined(__ARM_FP) && __ARM_FP != 0
698 ldp d0, d1, [x0, #0x110]
699 ldp d2, d3, [x0, #0x120]
700 ldp d4, d5, [x0, #0x130]
701 ldp d6, d7, [x0, #0x140]
702 ldp d8, d9, [x0, #0x150]
703 ldp d10,d11, [x0, #0x160]
704 ldp d12,d13, [x0, #0x170]
705 ldp d14,d15, [x0, #0x180]
706 ldp d16,d17, [x0, #0x190]
707 ldp d18,d19, [x0, #0x1A0]
708 ldp d20,d21, [x0, #0x1B0]
709 ldp d22,d23, [x0, #0x1C0]
710 ldp d24,d25, [x0, #0x1D0]
711 ldp d26,d27, [x0, #0x1E0]
712 ldp d28,d29, [x0, #0x1F0]
713 ldr d30, [x0, #0x200]
714 ldr d31, [x0, #0x208]
715#endif
716 // Finally, restore sp. This must be done after the last read from the
717 // context struct, because it is allocated on the stack, and an exception
718 // could clobber the de-allocated portion of the stack after sp has been
719 // restored.
720
721 ldr x16, [x0, #0x0F8] // load sp into scratch
722 ldr lr, [x0, #0x100] // restore pc into lr
723
724#if __has_feature(ptrauth_calls)
725 // The LR is signed with its address inside the register state. Time
726 // to resign to be a regular ROP protected signed pointer
727 add x1, x0, #0x100
728 autib lr, x1
729 pacib lr, x16 // signed the scratch register for sp
730#endif
731
732 ldp x0, x1, [x0, #0x000] // restore x0,x1
733 mov sp,x16 // restore sp
734#if defined(__ARM_FEATURE_GCS_DEFAULT)
735 // If GCS is enabled we need to push the address we're returning to onto the
736 // GCS stack. We can't just return using br, as there won't be a BTI landing
737 // pad instruction at the destination.
738 mov x16, #1
739 chkfeat x16
740 cbnz x16, Lnogcs
741 gcspushm x30
742Lnogcs:
743#endif
744
745#if __has_feature(ptrauth_calls)
746 retab
747#else
748 ret x30 // jump to pc
749#endif
750
751#elif defined(__arm__) && !defined(__APPLE__)
752
753#if !defined(__ARM_ARCH_ISA_ARM)
754#if (__ARM_ARCH_ISA_THUMB == 2)
755 .syntax unified
756#endif
757 .thumb
758#endif
759
760@
761@ void libunwind::Registers_arm::restoreCoreAndJumpTo()
762@
763@ On entry:
764@ thread_state pointer is in r0
765@
766 .p2align 2
767DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_arm20restoreCoreAndJumpToEv)
768#if !defined(__ARM_ARCH_ISA_ARM) && __ARM_ARCH_ISA_THUMB == 1
769 @ r8-r11: ldm into r1-r4, then mov to r8-r11
770 adds r0, #0x20
771 ldm r0!, {r1-r4}
772 subs r0, #0x30
773 mov r8, r1
774 mov r9, r2
775 mov r10, r3
776 mov r11, r4
777 @ r12 does not need loading, it it the intra-procedure-call scratch register
778 ldr r2, [r0, #0x34]
779 ldr r3, [r0, #0x3c]
780 mov sp, r2
781 mov lr, r3 @ restore pc into lr
782 ldm r0, {r0-r7}
783#else
784 @ Use lr as base so that r0 can be restored.
785 mov lr, r0
786 @ 32bit thumb-2 restrictions for ldm:
787 @ . the sp (r13) cannot be in the list
788 @ . the pc (r15) and lr (r14) cannot both be in the list in an LDM instruction
789 ldm lr, {r0-r12}
790 ldr sp, [lr, #52]
791 ldr lr, [lr, #60] @ restore pc into lr
792#endif
793#if defined(__ARM_FEATURE_BTI_DEFAULT) && !defined(__ARM_ARCH_ISA_ARM)
794 // 'bx' is not BTI setting when used with lr, therefore r12 is used instead
795 mov r12, lr
796 JMP(r12)
797#else
798 JMP(lr)
799#endif
800
801@
802@ static void libunwind::Registers_arm::restoreVFPWithFLDMD(unw_fpreg_t* values)
803@
804@ On entry:
805@ values pointer is in r0
806@
807 .p2align 2
808#if defined(__ELF__)
809 .fpu vfpv3-d16
810#endif
811DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_arm19restoreVFPWithFLDMDEPv)
812 @ VFP and iwMMX instructions are only available when compiling with the flags
813 @ that enable them. We do not want to do that in the library (because we do not
814 @ want the compiler to generate instructions that access those) but this is
815 @ only accessed if the personality routine needs these registers. Use of
816 @ these registers implies they are, actually, available on the target, so
817 @ it's ok to execute.
818 @ So, generate the instruction using the corresponding coprocessor mnemonic.
819 vldmia r0, {d0-d15}
820 JMP(lr)
821
822@
823@ static void libunwind::Registers_arm::restoreVFPWithFLDMX(unw_fpreg_t* values)
824@
825@ On entry:
826@ values pointer is in r0
827@
828 .p2align 2
829#if defined(__ELF__)
830 .fpu vfpv3-d16
831#endif
832DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_arm19restoreVFPWithFLDMXEPv)
833 vldmia r0, {d0-d15} @ fldmiax is deprecated in ARMv7+ and now behaves like vldmia
834 JMP(lr)
835
836@
837@ static void libunwind::Registers_arm::restoreVFPv3(unw_fpreg_t* values)
838@
839@ On entry:
840@ values pointer is in r0
841@
842 .p2align 2
843#if defined(__ELF__)
844 .fpu vfpv3
845#endif
846DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_arm12restoreVFPv3EPv)
847 vldmia r0, {d16-d31}
848 JMP(lr)
849
850#if defined(__ARM_WMMX)
851
852@
853@ static void libunwind::Registers_arm::restoreiWMMX(unw_fpreg_t* values)
854@
855@ On entry:
856@ values pointer is in r0
857@
858 .p2align 2
859#if defined(__ELF__)
860 .arch armv5te
861#endif
862DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_arm12restoreiWMMXEPv)
863 ldcl p1, cr0, [r0], #8 @ wldrd wR0, [r0], #8
864 ldcl p1, cr1, [r0], #8 @ wldrd wR1, [r0], #8
865 ldcl p1, cr2, [r0], #8 @ wldrd wR2, [r0], #8
866 ldcl p1, cr3, [r0], #8 @ wldrd wR3, [r0], #8
867 ldcl p1, cr4, [r0], #8 @ wldrd wR4, [r0], #8
868 ldcl p1, cr5, [r0], #8 @ wldrd wR5, [r0], #8
869 ldcl p1, cr6, [r0], #8 @ wldrd wR6, [r0], #8
870 ldcl p1, cr7, [r0], #8 @ wldrd wR7, [r0], #8
871 ldcl p1, cr8, [r0], #8 @ wldrd wR8, [r0], #8
872 ldcl p1, cr9, [r0], #8 @ wldrd wR9, [r0], #8
873 ldcl p1, cr10, [r0], #8 @ wldrd wR10, [r0], #8
874 ldcl p1, cr11, [r0], #8 @ wldrd wR11, [r0], #8
875 ldcl p1, cr12, [r0], #8 @ wldrd wR12, [r0], #8
876 ldcl p1, cr13, [r0], #8 @ wldrd wR13, [r0], #8
877 ldcl p1, cr14, [r0], #8 @ wldrd wR14, [r0], #8
878 ldcl p1, cr15, [r0], #8 @ wldrd wR15, [r0], #8
879 JMP(lr)
880
881@
882@ static void libunwind::Registers_arm::restoreiWMMXControl(unw_uint32_t* values)
883@
884@ On entry:
885@ values pointer is in r0
886@
887 .p2align 2
888#if defined(__ELF__)
889 .arch armv5te
890#endif
891DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind13Registers_arm19restoreiWMMXControlEPj)
892 ldc2 p1, cr8, [r0], #4 @ wldrw wCGR0, [r0], #4
893 ldc2 p1, cr9, [r0], #4 @ wldrw wCGR1, [r0], #4
894 ldc2 p1, cr10, [r0], #4 @ wldrw wCGR2, [r0], #4
895 ldc2 p1, cr11, [r0], #4 @ wldrw wCGR3, [r0], #4
896 JMP(lr)
897
898#endif
899
900#elif defined(__or1k__)
901
902DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind14Registers_or1k6jumptoEv)
903#
904# void libunwind::Registers_or1k::jumpto()
905#
906# On entry:
907# thread_state pointer is in r3
908#
909
910 # restore integral registers
911 l.lwz r0, 0(r3)
912 l.lwz r1, 4(r3)
913 l.lwz r2, 8(r3)
914 # skip r3 for now
915 l.lwz r4, 16(r3)
916 l.lwz r5, 20(r3)
917 l.lwz r6, 24(r3)
918 l.lwz r7, 28(r3)
919 l.lwz r8, 32(r3)
920 # skip r9
921 l.lwz r10, 40(r3)
922 l.lwz r11, 44(r3)
923 l.lwz r12, 48(r3)
924 l.lwz r13, 52(r3)
925 l.lwz r14, 56(r3)
926 l.lwz r15, 60(r3)
927 l.lwz r16, 64(r3)
928 l.lwz r17, 68(r3)
929 l.lwz r18, 72(r3)
930 l.lwz r19, 76(r3)
931 l.lwz r20, 80(r3)
932 l.lwz r21, 84(r3)
933 l.lwz r22, 88(r3)
934 l.lwz r23, 92(r3)
935 l.lwz r24, 96(r3)
936 l.lwz r25,100(r3)
937 l.lwz r26,104(r3)
938 l.lwz r27,108(r3)
939 l.lwz r28,112(r3)
940 l.lwz r29,116(r3)
941 l.lwz r30,120(r3)
942 l.lwz r31,124(r3)
943
944 # load new pc into ra
945 l.lwz r9, 128(r3)
946
947 # at last, restore r3
948 l.lwz r3, 12(r3)
949
950 # jump to pc
951 l.jr r9
952 l.nop
953
954#elif defined(__hexagon__)
955# On entry:
956# thread_state pointer is in r0
957DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind17Registers_hexagon6jumptoEv)
958#
959# void libunwind::Registers_hexagon::jumpto()
960#
961# The context layout is hexagon_thread_state_t: unsigned int __r[35]
962# __r[0..31] = r0..r31, __r[32] = predicates, __r[33] = PC.
963# Offsets: __r[n] is at byte offset n*4. r0 is the context pointer, so
964# it is restored last; r31 is loaded with the saved PC as the jumpr target.
965 r2 = memw(r0+#8)
966 r3 = memw(r0+#12)
967 r4 = memw(r0+#16)
968 r5 = memw(r0+#20)
969 r6 = memw(r0+#24)
970 r7 = memw(r0+#28)
971
972 r8 = memw(r0+#32)
973 r9 = memw(r0+#36)
974 r10 = memw(r0+#40)
975 r11 = memw(r0+#44)
976
977 r12 = memw(r0+#48)
978 r13 = memw(r0+#52)
979 r14 = memw(r0+#56)
980 r15 = memw(r0+#60)
981
982 r16 = memw(r0+#64)
983 r17 = memw(r0+#68)
984 r18 = memw(r0+#72)
985 r19 = memw(r0+#76)
986
987 r20 = memw(r0+#80)
988 r21 = memw(r0+#84)
989 r22 = memw(r0+#88)
990 r23 = memw(r0+#92)
991
992 r24 = memw(r0+#96)
993 r25 = memw(r0+#100)
994 r26 = memw(r0+#104)
995 r27 = memw(r0+#108)
996
997 r28 = memw(r0+#112)
998 r29 = memw(r0+#116)
999 r30 = memw(r0+#120)
1000 r31 = memw(r0+#132)
1001
1002 r1 = memw(r0+#128)
1003 c4 = r1 // Predicate register
1004 r1 = memw(r0+#4)
1005 r0 = memw(r0)
1006 jumpr r31
1007#elif defined(__mips__) && defined(_ABIO32) && _MIPS_SIM == _ABIO32
1008
1009//
1010// void libunwind::Registers_mips_o32::jumpto()
1011//
1012// On entry:
1013// thread state pointer is in a0 ($4)
1014//
1015DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind18Registers_mips_o326jumptoEv)
1016 .set push
1017 .set noat
1018 .set noreorder
1019 .set nomacro
1020#ifdef __mips_hard_float
1021#if defined(__mips_single_float)
1022 // See the matching comment in UnwindRegistersSave.S.
1023 lwc1 $f0, (4 * 36 + 8 * 0)($4)
1024 lwc1 $f1, (4 * 36 + 8 * 1)($4)
1025 lwc1 $f2, (4 * 36 + 8 * 2)($4)
1026 lwc1 $f3, (4 * 36 + 8 * 3)($4)
1027 lwc1 $f4, (4 * 36 + 8 * 4)($4)
1028 lwc1 $f5, (4 * 36 + 8 * 5)($4)
1029 lwc1 $f6, (4 * 36 + 8 * 6)($4)
1030 lwc1 $f7, (4 * 36 + 8 * 7)($4)
1031 lwc1 $f8, (4 * 36 + 8 * 8)($4)
1032 lwc1 $f9, (4 * 36 + 8 * 9)($4)
1033 lwc1 $f10, (4 * 36 + 8 * 10)($4)
1034 lwc1 $f11, (4 * 36 + 8 * 11)($4)
1035 lwc1 $f12, (4 * 36 + 8 * 12)($4)
1036 lwc1 $f13, (4 * 36 + 8 * 13)($4)
1037 lwc1 $f14, (4 * 36 + 8 * 14)($4)
1038 lwc1 $f15, (4 * 36 + 8 * 15)($4)
1039 lwc1 $f16, (4 * 36 + 8 * 16)($4)
1040 lwc1 $f17, (4 * 36 + 8 * 17)($4)
1041 lwc1 $f18, (4 * 36 + 8 * 18)($4)
1042 lwc1 $f19, (4 * 36 + 8 * 19)($4)
1043 lwc1 $f20, (4 * 36 + 8 * 20)($4)
1044 lwc1 $f21, (4 * 36 + 8 * 21)($4)
1045 lwc1 $f22, (4 * 36 + 8 * 22)($4)
1046 lwc1 $f23, (4 * 36 + 8 * 23)($4)
1047 lwc1 $f24, (4 * 36 + 8 * 24)($4)
1048 lwc1 $f25, (4 * 36 + 8 * 25)($4)
1049 lwc1 $f26, (4 * 36 + 8 * 26)($4)
1050 lwc1 $f27, (4 * 36 + 8 * 27)($4)
1051 lwc1 $f28, (4 * 36 + 8 * 28)($4)
1052 lwc1 $f29, (4 * 36 + 8 * 29)($4)
1053 lwc1 $f30, (4 * 36 + 8 * 30)($4)
1054 lwc1 $f31, (4 * 36 + 8 * 31)($4)
1055#elif __mips_fpr != 64
1056 ldc1 $f0, (4 * 36 + 8 * 0)($4)
1057 ldc1 $f2, (4 * 36 + 8 * 2)($4)
1058 ldc1 $f4, (4 * 36 + 8 * 4)($4)
1059 ldc1 $f6, (4 * 36 + 8 * 6)($4)
1060 ldc1 $f8, (4 * 36 + 8 * 8)($4)
1061 ldc1 $f10, (4 * 36 + 8 * 10)($4)
1062 ldc1 $f12, (4 * 36 + 8 * 12)($4)
1063 ldc1 $f14, (4 * 36 + 8 * 14)($4)
1064 ldc1 $f16, (4 * 36 + 8 * 16)($4)
1065 ldc1 $f18, (4 * 36 + 8 * 18)($4)
1066 ldc1 $f20, (4 * 36 + 8 * 20)($4)
1067 ldc1 $f22, (4 * 36 + 8 * 22)($4)
1068 ldc1 $f24, (4 * 36 + 8 * 24)($4)
1069 ldc1 $f26, (4 * 36 + 8 * 26)($4)
1070 ldc1 $f28, (4 * 36 + 8 * 28)($4)
1071 ldc1 $f30, (4 * 36 + 8 * 30)($4)
1072#else
1073 ldc1 $f0, (4 * 36 + 8 * 0)($4)
1074 ldc1 $f1, (4 * 36 + 8 * 1)($4)
1075 ldc1 $f2, (4 * 36 + 8 * 2)($4)
1076 ldc1 $f3, (4 * 36 + 8 * 3)($4)
1077 ldc1 $f4, (4 * 36 + 8 * 4)($4)
1078 ldc1 $f5, (4 * 36 + 8 * 5)($4)
1079 ldc1 $f6, (4 * 36 + 8 * 6)($4)
1080 ldc1 $f7, (4 * 36 + 8 * 7)($4)
1081 ldc1 $f8, (4 * 36 + 8 * 8)($4)
1082 ldc1 $f9, (4 * 36 + 8 * 9)($4)
1083 ldc1 $f10, (4 * 36 + 8 * 10)($4)
1084 ldc1 $f11, (4 * 36 + 8 * 11)($4)
1085 ldc1 $f12, (4 * 36 + 8 * 12)($4)
1086 ldc1 $f13, (4 * 36 + 8 * 13)($4)
1087 ldc1 $f14, (4 * 36 + 8 * 14)($4)
1088 ldc1 $f15, (4 * 36 + 8 * 15)($4)
1089 ldc1 $f16, (4 * 36 + 8 * 16)($4)
1090 ldc1 $f17, (4 * 36 + 8 * 17)($4)
1091 ldc1 $f18, (4 * 36 + 8 * 18)($4)
1092 ldc1 $f19, (4 * 36 + 8 * 19)($4)
1093 ldc1 $f20, (4 * 36 + 8 * 20)($4)
1094 ldc1 $f21, (4 * 36 + 8 * 21)($4)
1095 ldc1 $f22, (4 * 36 + 8 * 22)($4)
1096 ldc1 $f23, (4 * 36 + 8 * 23)($4)
1097 ldc1 $f24, (4 * 36 + 8 * 24)($4)
1098 ldc1 $f25, (4 * 36 + 8 * 25)($4)
1099 ldc1 $f26, (4 * 36 + 8 * 26)($4)
1100 ldc1 $f27, (4 * 36 + 8 * 27)($4)
1101 ldc1 $f28, (4 * 36 + 8 * 28)($4)
1102 ldc1 $f29, (4 * 36 + 8 * 29)($4)
1103 ldc1 $f30, (4 * 36 + 8 * 30)($4)
1104 ldc1 $f31, (4 * 36 + 8 * 31)($4)
1105#endif
1106#endif
1107#if __mips_isa_rev < 6
1108 // restore hi and lo
1109 lw $8, (4 * 33)($4)
1110 mthi $8
1111 lw $8, (4 * 34)($4)
1112 mtlo $8
1113#endif
1114 // r0 is zero
1115 lw $1, (4 * 1)($4)
1116 lw $2, (4 * 2)($4)
1117 lw $3, (4 * 3)($4)
1118 // skip a0 for now
1119 lw $5, (4 * 5)($4)
1120 lw $6, (4 * 6)($4)
1121 lw $7, (4 * 7)($4)
1122 lw $8, (4 * 8)($4)
1123 lw $9, (4 * 9)($4)
1124 lw $10, (4 * 10)($4)
1125 lw $11, (4 * 11)($4)
1126 lw $12, (4 * 12)($4)
1127 lw $13, (4 * 13)($4)
1128 lw $14, (4 * 14)($4)
1129 lw $15, (4 * 15)($4)
1130 lw $16, (4 * 16)($4)
1131 lw $17, (4 * 17)($4)
1132 lw $18, (4 * 18)($4)
1133 lw $19, (4 * 19)($4)
1134 lw $20, (4 * 20)($4)
1135 lw $21, (4 * 21)($4)
1136 lw $22, (4 * 22)($4)
1137 lw $23, (4 * 23)($4)
1138 lw $24, (4 * 24)($4)
1139 lw $25, (4 * 25)($4)
1140 lw $26, (4 * 26)($4)
1141 lw $27, (4 * 27)($4)
1142 lw $28, (4 * 28)($4)
1143 lw $29, (4 * 29)($4)
1144 // load new pc into ra
1145 lw $31, (4 * 32)($4)
1146 // MIPS 1 has load delay slot. Ensure lw $31 and jr are separated by an instruction.
1147 lw $30, (4 * 30)($4)
1148 // jump to ra, load a0 in the delay slot
1149 jr $31
1150 lw $4, (4 * 4)($4)
1151 .set pop
1152
1153#elif defined(__mips64)
1154
1155//
1156// void libunwind::Registers_mips_newabi::jumpto()
1157//
1158// On entry:
1159// thread state pointer is in a0 ($4)
1160//
1161DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind21Registers_mips_newabi6jumptoEv)
1162 .set push
1163 .set noat
1164 .set noreorder
1165 .set nomacro
1166#ifdef __mips_hard_float
1167 .irp i,FROM_0_TO_31
1168 ldc1 $f\i, (280+8*\i)($4)
1169 .endr
1170#endif
1171#if __mips_isa_rev < 6
1172 // restore hi and lo
1173 ld $8, (8 * 33)($4)
1174 mthi $8
1175 ld $8, (8 * 34)($4)
1176 mtlo $8
1177#endif
1178 // r0 is zero
1179 ld $1, (8 * 1)($4)
1180 ld $2, (8 * 2)($4)
1181 ld $3, (8 * 3)($4)
1182 // skip a0 for now
1183 .irp i,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29
1184 ld $\i, (8 * \i)($4)
1185 .endr
1186 // load new pc into ra
1187 ld $31, (8 * 32)($4)
1188 // MIPS 1 has load delay slot. Ensure lw $31 and jr are separated by an instruction.
1189 ld $30, (8 * 30)($4)
1190 // jump to ra, load a0 in the delay slot
1191 jr $31
1192 ld $4, (8 * 4)($4)
1193 .set pop
1194
1195#elif defined(__sparc__) && defined(__arch64__)
1196
1197DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind17Registers_sparc646jumptoEv)
1198//
1199// void libunwind::Registers_sparc64::jumpto()
1200//
1201// On entry:
1202// thread_state pointer is in %o0
1203//
1204 .register %g2, #scratch
1205 .register %g3, #scratch
1206 .register %g6, #scratch
1207 .register %g7, #scratch
1208 flushw
1209 ldx [%o0 + 0x08], %g1
1210 ldx [%o0 + 0x10], %g2
1211 ldx [%o0 + 0x18], %g3
1212 ldx [%o0 + 0x20], %g4
1213 ldx [%o0 + 0x28], %g5
1214 ldx [%o0 + 0x30], %g6
1215 ldx [%o0 + 0x38], %g7
1216 ldx [%o0 + 0x48], %o1
1217 ldx [%o0 + 0x50], %o2
1218 ldx [%o0 + 0x58], %o3
1219 ldx [%o0 + 0x60], %o4
1220 ldx [%o0 + 0x68], %o5
1221 ldx [%o0 + 0x70], %o6
1222 ldx [%o0 + 0x78], %o7
1223 ldx [%o0 + 0x80], %l0
1224 ldx [%o0 + 0x88], %l1
1225 ldx [%o0 + 0x90], %l2
1226 ldx [%o0 + 0x98], %l3
1227 ldx [%o0 + 0xa0], %l4
1228 ldx [%o0 + 0xa8], %l5
1229 ldx [%o0 + 0xb0], %l6
1230 ldx [%o0 + 0xb8], %l7
1231 ldx [%o0 + 0xc0], %i0
1232 ldx [%o0 + 0xc8], %i1
1233 ldx [%o0 + 0xd0], %i2
1234 ldx [%o0 + 0xd8], %i3
1235 ldx [%o0 + 0xe0], %i4
1236 ldx [%o0 + 0xe8], %i5
1237 ldx [%o0 + 0xf0], %i6
1238 ldx [%o0 + 0xf8], %i7
1239 jmp %o7
1240 ldx [%o0 + 0x40], %o0
1241
1242#elif defined(__sparc__)
1243
1244//
1245// void libunwind::Registers_sparc_o32::jumpto()
1246//
1247// On entry:
1248// thread_state pointer is in o0
1249//
1250DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_sparc6jumptoEv)
1251 ta 3
1252 ldd [%o0 + 64], %l0
1253 ldd [%o0 + 72], %l2
1254 ldd [%o0 + 80], %l4
1255 ldd [%o0 + 88], %l6
1256 ldd [%o0 + 96], %i0
1257 ldd [%o0 + 104], %i2
1258 ldd [%o0 + 112], %i4
1259 ldd [%o0 + 120], %i6
1260 ld [%o0 + 60], %o7
1261 jmp %o7
1262 nop
1263
1264#elif defined(__riscv)
1265
1266//
1267// void libunwind::Registers_riscv::jumpto()
1268//
1269// On entry:
1270// thread_state pointer is in a0
1271//
1272 .p2align 2
1273DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_riscv6jumptoEv)
1274# if defined(__riscv_flen)
1275 .irp i,FROM_0_TO_31
1276 FLOAD f\i, (RISCV_FOFFSET + RISCV_FSIZE * \i)(a0)
1277 .endr
1278# endif
1279
1280 // x0 is zero
1281 ILOAD x1, (RISCV_ISIZE * 0)(a0) // restore pc into ra
1282 .irp i,2,3,4,5,6,7,8,9
1283 ILOAD x\i, (RISCV_ISIZE * \i)(a0)
1284 .endr
1285 // skip a0 for now
1286#if defined(__riscv_32e)
1287 .irp i,11,12,13,14,15
1288#else
1289 .irp i,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
1290#endif
1291 ILOAD x\i, (RISCV_ISIZE * \i)(a0)
1292 .endr
1293 ILOAD x10, (RISCV_ISIZE * 10)(a0) // restore a0
1294
1295 ret // jump to ra
1296
1297#elif defined(__s390x__)
1298
1299DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind15Registers_s390x6jumptoEv)
1300//
1301// void libunwind::Registers_s390x::jumpto()
1302//
1303// On entry:
1304// thread_state pointer is in r2
1305//
1306
1307 // Skip PSWM, but load PSWA into r1
1308 lg %r1, 8(%r2)
1309
1310 // Restore FPRs
1311 .irp i,FROM_0_TO_15
1312 ld %f\i, (144+8*\i)(%r2)
1313 .endr
1314
1315 // Restore GPRs - skipping %r0 and %r1
1316 lmg %r2, %r15, 32(%r2)
1317
1318 // Return to PSWA (was loaded into %r1 above)
1319 br %r1
1320
1321#elif defined(__loongarch__) && __loongarch_grlen == 64
1322
1323//
1324// void libunwind::Registers_loongarch::jumpto()
1325//
1326// On entry:
1327// thread_state pointer is in $a0($r4)
1328//
1329 .p2align 2
1330DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind19Registers_loongarch6jumptoEv)
1331# if __loongarch_frlen == 64
1332 .irp i,FROM_0_TO_31
1333 fld.d $f\i, $a0, (8 * 33 + 8 * \i)
1334 .endr
1335# endif
1336
1337 // $r0 is zero
1338 .irp i,1,2,3
1339 ld.d $r\i, $a0, (8 * \i)
1340 .endr
1341 // skip $a0 for now
1342 .irp i,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31
1343 ld.d $r\i, $a0, (8 * \i)
1344 .endr
1345
1346 ld.d $ra, $a0, (8 * 32) // load new pc into $ra
1347 ld.d $a0, $a0, (8 * 4) // restore $a0 last
1348
1349 jr $ra
1350
1351#endif
1352
1353#endif /* !defined(__USING_SJLJ_EXCEPTIONS__) */
1354
1355NO_EXEC_STACK_DIRECTIVE
1356
1357#endif /* !defined(__wasm__) */
1358