xref: /openbsd/regress/sys/arch/amd64/fpu/fenv.S (revision b9fcb169)
1/*	$OpenBSD: fenv.S,v 1.2 2024/04/01 18:52:34 anton Exp $	*/
2/*
3 * Copyright (c) 2018 Alexander Bluhm <bluhm@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <sys/syscall.h>
19
20#define PINSYSCALL(sysno, label)					\
21	.pushsection .openbsd.syscalls,"",%progbits;			\
22	.p2align 2;							\
23	.long label;							\
24	.long sysno;							\
25	.popsection;
26
27	.section	.note.openbsd.ident, "a"
28	.p2align	2
29	.long		8
30	.long		4
31	.long		1
32	.ascii		"OpenBSD\0"
33	.long		0
34	.previous
35
36	.data
37env:
38	.long	1	/* __control */
39	.long	1	/* __status */
40	.long	1	/* __tag */
41	.long	1	/* __others 0 */
42	.long	1	/* __others 1 */
43	.long	1	/* __others 2 */
44	.long	1	/* __others 3 */
45mxcsr:
46	.long	1	/* __mxcsr */
47env_end:
48
49	.text
50	.align	8
51	.global	_start
52_start:
53	fnstenv	env
54	stmxcsr	mxcsr
55	mov	$SYS_write,	%rax
56	mov	$1,		%rdi
57	mov	$env,		%rsi
58	mov	$(env_end-env),	%rdx
591:
60	syscall
61	PINSYSCALL(SYS_write, 1b)
62	mov	$SYS_exit,	%rax
63	mov	$0,		%rdi
642:
65	syscall
66	PINSYSCALL(SYS_exit, 2b)
67