1//===-- orc_rt_macho_tlv.x86-64.s -------------------------------*- ASM -*-===//
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// This file is a part of the ORC runtime support library.
10//
11//===----------------------------------------------------------------------===//
12
13// The content of this file is x86_64-only
14#if defined(__x86_64__)
15.att_syntax
16
17// Save all GRPS except %rsp.
18// This value is also subtracted from %rsp below, despite the fact that %rbp
19// has already been pushed, because we need %rsp to stay 16-byte aligned.
20#define GPR_SAVE_SPACE_SIZE 15 * 8
21#define FXSAVE64_SAVE_SPACE_SIZE 512
22#define REGISTER_SAVE_SPACE_SIZE \
23 GPR_SAVE_SPACE_SIZE + FXSAVE64_SAVE_SPACE_SIZE
24
25 .text
26
27 // returns address of TLV in %rax, all other registers preserved
28 .globl __orc_rt_sysv_reenter
29__orc_rt_sysv_reenter:
30 pushq %rbp
31 movq %rsp, %rbp
32 subq $REGISTER_SAVE_SPACE_SIZE, %rsp
33 movq %rax, -8(%rbp)
34 movq %rbx, -16(%rbp)
35 movq %rcx, -24(%rbp)
36 movq %rdx, -32(%rbp)
37 movq %rsi, -40(%rbp)
38 movq %rdi, -48(%rbp)
39 movq %r8, -56(%rbp)
40 movq %r9, -64(%rbp)
41 movq %r10, -72(%rbp)
42 movq %r11, -80(%rbp)
43 movq %r12, -88(%rbp)
44 movq %r13, -96(%rbp)
45 movq %r14, -104(%rbp)
46 movq %r15, -112(%rbp)
47 fxsave64 (%rsp)
48 movq 8(%rbp), %rdi
49
50 // Load return address and subtract five from it (on the assumption
51 // that it's a call instruction).
52 subq $5, %rdi
53
54 // Call __orc_rt_resolve to look up the implementation corresponding to
55 // the calling stub, then store this in x17 (which we'll return to
56 // below).
57#if !defined(__APPLE__)
58 call __orc_rt_resolve
59#else
60 call ___orc_rt_resolve
61#endif
62 movq %rax, 8(%rbp)
63 fxrstor64 (%rsp)
64 movq -112(%rbp), %r15
65 movq -104(%rbp), %r14
66 movq -96(%rbp), %r13
67 movq -88(%rbp), %r12
68 movq -80(%rbp), %r11
69 movq -72(%rbp), %r10
70 movq -64(%rbp), %r9
71 movq -56(%rbp), %r8
72 movq -48(%rbp), %rdi
73 movq -40(%rbp), %rsi
74 movq -32(%rbp), %rdx
75 movq -24(%rbp), %rcx
76 movq -16(%rbp), %rbx
77 movq -8(%rbp), %rax
78 addq $REGISTER_SAVE_SPACE_SIZE, %rsp
79 popq %rbp
80 ret
81
82#endif // defined(__x86_64__)
83