xref: /freebsd/sys/amd64/amd64/sigtramp.S (revision 069ac184)
1/*-
2 * Copyright (c) 2003 Peter Wemm <peter@freeBSD.org>
3 * All rights reserved.
4 *
5 * Copyright (c) 2021 The FreeBSD Foundation
6 *
7 * Portions of this software were developed by Konstantin Belousov
8 * under sponsorship from the FreeBSD Foundation.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#include <sys/syscall.h>
33#include <machine/asmacros.h>
34
35#include "assym.inc"
36
37	.text
38/*
39 * Signal trampoline, mapped as vdso into shared page.
40 */
41ENTRY(__vdso_sigcode)
42	.cfi_startproc
43	.cfi_signal_frame
44	.cfi_def_cfa	%rsp, 0
45	.cfi_offset	%rdi, SIGF_UC + UC_RDI
46	.cfi_offset	%rsi, SIGF_UC + UC_RSI
47	.cfi_offset	%rdx, SIGF_UC + UC_RDX
48	.cfi_offset	%rcx, SIGF_UC + UC_RCX
49	.cfi_offset	%r8,  SIGF_UC + UC_R8
50	.cfi_offset	%r9,  SIGF_UC + UC_R9
51	.cfi_offset	%rax, SIGF_UC + UC_RAX
52	.cfi_offset	%rbx, SIGF_UC + UC_RBX
53	.cfi_offset	%rbp, SIGF_UC + UC_RBP
54	.cfi_offset	%r10, SIGF_UC + UC_R10
55	.cfi_offset	%r11, SIGF_UC + UC_R11
56	.cfi_offset	%r12, SIGF_UC + UC_R12
57	.cfi_offset	%r13, SIGF_UC + UC_R13
58	.cfi_offset	%r14, SIGF_UC + UC_R14
59	.cfi_offset	%r15, SIGF_UC + UC_R15
60#if 0
61/*
62 * Gnu as complains about %fs/%gs/%es/%ds registers offsets not being
63 * multiple of 8, but gas + ld.bfd work for %cs/%ss.
64 *
65 * Clang IAS + ld.lld combination cannot handle any of the segment
66 * registers.  Also, clang IAS does not know %rflags/%fs.base/%gs.base
67 * registers names, use dwarf registers numbers from psABI directly.
68 *
69 * LLVM libunwind from stable/13 cannot parse register numbers higher
70 * than 32.  Disable %rflags, %fs.base, and %gs.base annotations.
71 */
72	.cfi_offset	%fs,  SIGF_UC + UC_FS
73	.cfi_offset	%gs,  SIGF_UC + UC_GS
74	.cfi_offset	%es,  SIGF_UC + UC_ES
75	.cfi_offset	%ds,  SIGF_UC + UC_DS
76#endif
77	.cfi_offset	%rip, SIGF_UC + UC_RIP
78#if 0
79	.cfi_offset	%cs,  SIGF_UC + UC_CS
80	.cfi_offset	49 /* %rflags */, SIGF_UC + UC_RFLAGS
81#endif
82	.cfi_offset	%rsp, SIGF_UC + UC_RSP
83#if 0
84	.cfi_offset	%ss,  SIGF_UC + UC_SS
85	.cfi_offset	58 /* %fs.base */, SIGF_UC + UC_FSBASE
86	.cfi_offset	59 /* %gs.base */, SIGF_UC + UC_GSBASE
87#endif
88	call	*SIGF_HANDLER(%rsp)	/* call signal handler */
89	lea	SIGF_UC(%rsp),%rdi	/* get ucontext_t */
90	pushq	$0			/* junk to fake return addr. */
91	.cfi_def_cfa	%rsp, 8
92	movq	$SYS_sigreturn,%rax
93	syscall				/* enter kernel with args */
940:	hlt				/* trap priviliged instruction */
95	jmp	0b
96	.cfi_endproc
97END(__vdso_sigcode)
98
99	.section .note.GNU-stack,"",%progbits
100