xref: /illumos-gate/usr/src/test/os-tests/tests/stackalign/stack_amd64.S (revision a89c0811c892ec231725fe10817ef95dda813c06)
1/*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source.  A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12/*
13 * Copyright 2021 Tintri by DDN, Inc. All rights reserved.
14 */
15
16/*
17 * Get the stack at entry and call a function with it as an argument.
18 */
19
20	.file	"stack_amd64.s"
21
22#include <sys/asm_linkage.h>
23
24/*
25 * void
26 * get_stack_at_entry(test_ctx_t *ctx)
27 *
28 * ctx+0 is void (*)(uintptr_t stack, char *text),
29 * and ctx+8 is the 'text' argument.
30 *
31 * Passes the stack pointer prior to the invoking call instruction
32 * to the specified function.
33 */
34	ENTRY(get_stack_at_entry)
35	pushq	%rbp
36	movq	%rsp, %rbp
37	movq	%rdi, %rax
38	leaq	16(%rbp), %rdi
39	movq	8(%rax), %rsi
40	call	*(%rax)
41	popq	%rbp
42	ret
43	SET_SIZE(get_stack_at_entry)
44
45/*
46 * void
47 * get_stack_at_init(void)
48 *
49 * Passes the stack pointer prior to the invoking call instruction
50 * to initarray() (defined elsewhere).
51 * Tests alignment in section .init_array.
52 */
53	ENTRY(get_stack_at_init)
54	pushq	%rbp
55	movq	%rsp, %rbp
56	leaq	16(%rbp), %rdi
57	call	initarray@PLT
58	popq	%rbp
59	ret
60	SET_SIZE(get_stack_at_init)
61
62/*
63 * Passes the stack pointer during init to initmain() (defined elsewhere).
64 * Tests alignment in section .init.
65 */
66	.section ".init"
67	movq	%rsp, %rdi
68	call	initmain@PLT
69
70