xref: /illumos-gate/usr/src/test/os-tests/tests/stackalign/stack_i386.S (revision 5d9d9091f564c198a760790b0bfa72c44e17912b)
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_i386.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+4 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	pushl	%ebp
36	movl	%esp, %ebp
37	leal	8(%ebp), %eax
38	movl	8(%ebp), %ecx
39	pushl	4(%ecx)
40	pushl	%eax
41	call	*(%ecx)
42	addl	$8, %esp
43	popl	%ebp
44	ret
45	SET_SIZE(get_stack_at_entry)
46
47/*
48 * void
49 * get_stack_at_init(void)
50 *
51 * Passes the stack pointer prior to the invoking call instruction
52 * to initarray() (defined elsewhere).
53 * Tests alignment in section .init_array.
54 */
55	ENTRY(get_stack_at_init)
56	pushl	%ebp
57	movl	%esp, %ebp
58	leal	8(%ebp), %eax
59	subl	$8, %esp
60	movl	%eax, (%esp)
61	call	initarray@PLT
62	addl	$8, %esp
63	popl	%ebp
64	ret
65	SET_SIZE(get_stack_at_init)
66
67/*
68 * Passes the stack pointer during init to initmain() (defined elsewhere).
69 * Tests alignment in section .init.
70 */
71	.section ".init"
72	movl	%esp, %eax
73	pushl	%eax
74	call	initmain@PLT
75	addl	$4, %esp
76