15af32e75SAxel Dörfler/* 2ad7ff929SIngo Weinhold * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. 30c0bf02aSAxel Dörfler * Copyright 2004-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 40c0bf02aSAxel Dörfler * Distributed under the terms of the MIT License. 55af32e75SAxel Dörfler */ 65af32e75SAxel Dörfler 75af32e75SAxel Dörfler#include "setjmp_internal.h" 85af32e75SAxel Dörfler 95af32e75SAxel Dörfler 105af32e75SAxel Dörfler/** This is a BeOS compatible __sigsetjmp() implementation; there, 115af32e75SAxel Dörfler * setjmp() and sigsetjmp() are both macros to this function. 125af32e75SAxel Dörfler * 135af32e75SAxel Dörfler * It first saves the register/stack environment of the running thread, 145af32e75SAxel Dörfler * and then calls __setjmp_save_sigs() which will save the signal state 155af32e75SAxel Dörfler * if it was asked to do this. 165af32e75SAxel Dörfler */ 175af32e75SAxel Dörfler 185af32e75SAxel Dörfler/* int sigsetjmp(jmp_buf buffer, int saveMask) */ 195af32e75SAxel DörflerFUNCTION(__sigsetjmp): 205af32e75SAxel DörflerFUNCTION(sigsetjmp): 21ad7ff929SIngo Weinhold // return address to %edx, stack pointer for return to %ecx (both are 22ad7ff929SIngo Weinhold // scratch registers) 23ad7ff929SIngo Weinhold mov 0(%esp), %edx 24ad7ff929SIngo Weinhold lea 4(%esp), %ecx 25ad7ff929SIngo Weinhold 26ad7ff929SIngo Weinhold // buffer to %eax 275af32e75SAxel Dörfler mov 4(%esp), %eax 285af32e75SAxel Dörfler 29ad7ff929SIngo Weinholdsigsetjmp_setjmp_entry: 30ad7ff929SIngo Weinhold // fill __jmp_buf structure with current registers 315af32e75SAxel Dörfler mov %ebx, JMP_REGS_EBX(%eax) 325af32e75SAxel Dörfler mov %esi, JMP_REGS_ESI(%eax) 335af32e75SAxel Dörfler mov %edi, JMP_REGS_EDI(%eax) 345af32e75SAxel Dörfler mov %ebp, JMP_REGS_EBP(%eax) 355af32e75SAxel Dörfler 365af32e75SAxel Dörfler // save stack and return address (because that's where we intend to jump to) 375af32e75SAxel Dörfler mov %ecx, JMP_REGS_ESP(%eax) 38ad7ff929SIngo Weinhold mov %edx, JMP_REGS_PC(%eax) 395af32e75SAxel Dörfler 405af32e75SAxel Dörfler jmp __setjmp_save_sigs 418cc14638SIngo WeinholdFUNCTION_END(sigsetjmp) 420c0bf02aSAxel Dörfler 43ad7ff929SIngo Weinhold 44ad7ff929SIngo Weinhold/* int setjmp(jmp_buf buffer) */ 45ad7ff929SIngo WeinholdFUNCTION(setjmp): 46*c92f19c6SAdrien DestuguesFUNCTION(_setjmp): 47ad7ff929SIngo Weinhold // prepare %edx, %ecx, and %eax for sigsetjmp 48ad7ff929SIngo Weinhold mov 0(%esp), %edx 49ad7ff929SIngo Weinhold lea 4(%esp), %ecx 50ad7ff929SIngo Weinhold mov (%ecx), %eax 51ad7ff929SIngo Weinhold 52ad7ff929SIngo Weinhold // let sigsetjmp do the real work 53ad7ff929SIngo Weinhold pushl $0 // saveMask 54ad7ff929SIngo Weinhold push %eax // buffer 55ad7ff929SIngo Weinhold call sigsetjmp_setjmp_entry 56ad7ff929SIngo Weinhold add $8, %esp 57ad7ff929SIngo Weinhold 58ad7ff929SIngo Weinhold ret 598cc14638SIngo WeinholdFUNCTION_END(setjmp) 60ad7ff929SIngo Weinhold 61ad7ff929SIngo Weinhold 62ad7ff929SIngo Weinhold#pragma weak _setjmp=setjmp 63