1/*
2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2004-2005, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
4 * Distributed under the terms of the MIT License.
5 */
6
7#include "setjmp_internal.h"
8
9
10/**	This is a BeOS compatible __sigsetjmp() implementation; there,
11 *	setjmp() and sigsetjmp() are both macros to this function.
12 *
13 *	It first saves the register/stack environment of the running thread,
14 *	and then calls __setjmp_save_sigs() which will save the signal state
15 *	if it was asked to do this.
16 */
17
18/* int sigsetjmp(jmp_buf buffer, int saveMask) */
19FUNCTION(__sigsetjmp):
20FUNCTION(sigsetjmp):
21	// return address to %edx, stack pointer for return to %ecx (both are
22	// scratch registers)
23	mov		0(%esp), %edx
24	lea		4(%esp), %ecx
25
26	// buffer to %eax
27	mov		4(%esp), %eax
28
29sigsetjmp_setjmp_entry:
30	// fill __jmp_buf structure with current registers
31	mov		%ebx, JMP_REGS_EBX(%eax)
32	mov		%esi, JMP_REGS_ESI(%eax)
33	mov		%edi, JMP_REGS_EDI(%eax)
34	mov		%ebp, JMP_REGS_EBP(%eax)
35
36	// save stack and return address (because that's where we intend to jump to)
37	mov		%ecx, JMP_REGS_ESP(%eax)
38	mov		%edx, JMP_REGS_PC(%eax)
39
40	jmp		__setjmp_save_sigs
41FUNCTION_END(sigsetjmp)
42
43
44/* int setjmp(jmp_buf buffer) */
45FUNCTION(setjmp):
46FUNCTION(_setjmp):
47	// prepare %edx, %ecx, and %eax for sigsetjmp
48	mov		0(%esp), %edx
49	lea		4(%esp), %ecx
50	mov		(%ecx), %eax
51
52	// let sigsetjmp do the real work
53	pushl	$0							// saveMask
54	push	%eax						// buffer
55	call	sigsetjmp_setjmp_entry
56	add		$8, %esp
57
58	ret
59FUNCTION_END(setjmp)
60
61
62#pragma weak _setjmp=setjmp
63