1/* This is file is a merger of SETJMP.S and LONGJMP.S */
2/*
3 *  This file was modified to use the __USER_LABEL_PREFIX__ and
4 *  __REGISTER_PREFIX__ macros defined by later versions of GNU cpp by
5 *  Joel Sherrill (joel@OARcorp.com)
6 *  Slight change: now includes i386mach.h for this (Werner Almesberger)
7 *
8 * Copyright (C) 1991 DJ Delorie
9 * All rights reserved.
10 *
11 * Redistribution, modification, and use in source and binary forms is permitted
12 * provided that the above copyright notice and following paragraph are
13 * duplicated in all such forms.
14 *
15 * This file is distributed WITHOUT ANY WARRANTY; without even the implied
16 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 */
18
19 /*
20 **	jmp_buf:
21 **	 eax ebx ecx edx esi edi ebp esp eip
22 **	 0   4   8   12  16  20  24  28  32
23 **
24 **	Intel MCU jmp_buf:
25 **	 ebx esi edi ebp esp eip
26 **	 0   4   8   12  16  20
27 */
28
29       #include "i386mach.h"
30
31        .global SYM (setjmp)
32        .global SYM (longjmp)
33       SOTYPE_FUNCTION(setjmp)
34       SOTYPE_FUNCTION(longjmp)
35
36SYM (setjmp):
37
38#ifdef __iamcu__
39	/* Store EIP.  */
40	movl	0(esp),ecx
41	movl	ecx,20(eax)
42
43	movl	ebx,0 (eax)
44	movl	esi,4 (eax)
45	movl	edi,8 (eax)
46	movl	ebp,12(eax)
47
48	/* Skip return address, which will be pushed onto stack in
49	   longjmp, and store SP.  */
50	leal	4(esp),ecx
51	movl	ecx,16(eax)
52
53	xorl	eax,eax
54#else
55	pushl	ebp
56	movl	esp,ebp
57
58	pushl	edi
59	movl	8 (ebp),edi
60
61	movl	eax,0 (edi)
62	movl	ebx,4 (edi)
63	movl	ecx,8 (edi)
64	movl	edx,12 (edi)
65	movl	esi,16 (edi)
66
67	movl	-4 (ebp),eax
68	movl	eax,20 (edi)
69
70	movl	0 (ebp),eax
71	movl	eax,24 (edi)
72
73	movl	esp,eax
74	addl	$12,eax
75	movl	eax,28 (edi)
76
77	movl	4 (ebp),eax
78	movl	eax,32 (edi)
79
80	popl	edi
81	movl	$0,eax
82	leave
83#endif
84	ret
85
86SYM (longjmp):
87#ifdef __iamcu__
88	/* Check retval.  */
89	testl	edx,edx
90	jne	0f
91	incl	edx
920:
93	/* Restore stack first.  */
94	movl	16(eax),esp
95
96	/* Put return address on stack.  */
97	pushl	20(eax)
98
99	movl	0(eax),ebx
100	movl	4(eax),esi
101	movl	8(eax),edi
102	movl	12(eax),ebp
103	movl	edx,eax
104#else
105	pushl	ebp
106	movl	esp,ebp
107
108	movl	8(ebp),edi	/* get jmp_buf */
109	movl	12(ebp),eax	/* store retval in j->eax */
110	testl	eax,eax
111	jne	0f
112	incl	eax
1130:
114	movl	eax,0(edi)
115
116	movl	24(edi),ebp
117
118       __CLI
119	movl	28(edi),esp
120
121	pushl	32(edi)
122
123	movl	0(edi),eax
124	movl	4(edi),ebx
125	movl	8(edi),ecx
126	movl	12(edi),edx
127	movl	16(edi),esi
128	movl	20(edi),edi
129       __STI
130#endif
131
132	ret
133
134#if defined(__linux__) && defined(__ELF__)
135.section .note.GNU-stack,"",%progbits
136#endif
137