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):
46	// prepare %edx, %ecx, and %eax for sigsetjmp
47	mov		0(%esp), %edx
48	lea		4(%esp), %ecx
49	mov		(%ecx), %eax
50
51	// let sigsetjmp do the real work
52	pushl	$0							// saveMask
53	push	%eax						// buffer
54	call	sigsetjmp_setjmp_entry
55	add		$8, %esp
56
57	ret
58FUNCTION_END(setjmp)
59
60
61#pragma weak _setjmp=setjmp
62