xref: /freebsd/sys/contrib/openzfs/module/lua/setjmp/setjmp_i386.S (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1// SPDX-License-Identifier: CDDL-1.0
2/*
3 * CDDL HEADER START
4 *
5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License (the "License").
7 * You may not use this file except in compliance with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or https://opensource.org/licenses/CDDL-1.0.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22
23/*
24 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
25 */
26
27#define	ENTRY(x) \
28	.text; \
29	.balign	8; \
30	.globl	x; \
31	.type	x, @function; \
32x:
33
34#define	SET_SIZE(x) \
35	.size	x, [.-x]
36
37/*
38 * Setjmp and longjmp implement non-local gotos using state vectors
39 * type label_t.
40 */
41#ifdef __i386__
42
43	ENTRY(setjmp)			/* save area is passed in eax */
44	movl	%ebp, 0(%eax)		/* save ebp */
45	movl	%ebx, 4(%eax)		/* save ebx */
46	movl	%esi, 8(%eax)		/* save esi */
47	movl	%edi, 12(%eax)		/* save edi */
48	movl	%esp, 16(%eax)		/* save esp */
49	movl	(%esp), %ecx		/* %eip (return address) */
50	movl	%ecx, 20(%eax)		/* save eip */
51	subl	%eax, %eax		/* return 0 */
52	ret
53	SET_SIZE(setjmp)
54
55	ENTRY(longjmp)			/* save area is passed in eax */
56	movl	0(%eax), %ebp		/* restore ebp */
57	movl	4(%eax), %ebx		/* restore ebx */
58	movl	8(%eax), %esi		/* restore esi */
59	movl	12(%eax), %edi		/* restore edi */
60	movl	16(%eax), %esp		/* restore esp */
61	movl	20(%eax), %ecx		/* %eip (return address) */
62	addl	$4, %esp		/* pop ret adr */
63	jmp	*%ecx			/* indirect jump */
64	SET_SIZE(longjmp)
65
66#ifdef __ELF__
67.section .note.GNU-stack,"",%progbits
68#endif
69
70#endif /* __i386__ */
71