2007-09-21 01:57:56 +02:00
|
|
|
/**************************************************************************
|
2022-02-15 20:53:18 +01:00
|
|
|
* libs/libc/machine/sim/arch_setjmp_x86.S
|
2007-09-21 01:57:56 +02:00
|
|
|
*
|
2021-03-28 17:21:53 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2007-09-21 01:57:56 +02:00
|
|
|
*
|
2021-03-28 17:21:53 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-09-21 01:57:56 +02:00
|
|
|
*
|
2021-03-28 17:21:53 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2007-09-21 01:57:56 +02:00
|
|
|
*
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Included Files
|
|
|
|
**************************************************************************/
|
|
|
|
|
2021-04-05 07:01:15 +02:00
|
|
|
#include <arch/setjmp.h>
|
2007-09-21 01:57:56 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
2014-09-30 18:44:32 +02:00
|
|
|
* Pre-processor Definitions
|
2007-09-21 01:57:56 +02:00
|
|
|
**************************************************************************/
|
2014-04-14 00:22:22 +02:00
|
|
|
|
2007-09-21 02:28:48 +02:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
# define SYMBOL(s) _##s
|
2021-01-10 09:05:43 +01:00
|
|
|
#elif defined(__ELF__)
|
2007-09-21 02:28:48 +02:00
|
|
|
# define SYMBOL(s) s
|
2020-01-29 17:31:38 +01:00
|
|
|
#else
|
|
|
|
# define SYMBOL(s) _##s
|
2007-09-21 02:28:48 +02:00
|
|
|
#endif
|
2007-09-21 01:57:56 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
.text
|
2021-04-05 07:01:15 +02:00
|
|
|
.globl SYMBOL(setjmp)
|
2020-01-27 15:59:20 +01:00
|
|
|
#ifdef __ELF__
|
2021-04-05 07:01:15 +02:00
|
|
|
.type SYMBOL(setjmp), @function
|
2007-09-21 02:28:48 +02:00
|
|
|
#endif
|
2021-04-05 07:01:15 +02:00
|
|
|
SYMBOL(setjmp):
|
2007-09-21 01:57:56 +02:00
|
|
|
|
|
|
|
/* %ebx, %esi, %edi, and %ebp must be preserved.
|
|
|
|
* save %ebx, $esi, and %edi now... */
|
|
|
|
|
2007-09-21 02:28:48 +02:00
|
|
|
movl 4(%esp), %eax
|
|
|
|
movl %ebx, (JB_EBX)(%eax)
|
|
|
|
movl %esi, (JB_ESI)(%eax)
|
|
|
|
movl %edi, (JB_EDI)(%eax)
|
2007-09-21 01:57:56 +02:00
|
|
|
|
2007-09-21 02:28:48 +02:00
|
|
|
/* Save the value of SP as will be after we return */
|
2007-09-21 01:57:56 +02:00
|
|
|
|
2007-09-21 02:28:48 +02:00
|
|
|
leal 4(%esp), %ecx
|
|
|
|
movl %ecx, (JB_SP)(%eax)
|
2007-09-21 01:57:56 +02:00
|
|
|
|
2007-09-21 02:28:48 +02:00
|
|
|
/* Save the return PC */
|
2007-09-21 01:57:56 +02:00
|
|
|
|
2007-09-21 02:28:48 +02:00
|
|
|
movl 0(%esp), %ecx
|
|
|
|
movl %ecx, (JB_PC)(%eax)
|
2007-09-21 01:57:56 +02:00
|
|
|
|
2007-09-21 02:28:48 +02:00
|
|
|
/* Save the framepointer */
|
2007-09-21 01:57:56 +02:00
|
|
|
|
2012-05-02 17:36:19 +02:00
|
|
|
movl %ebp, (JB_EBP)(%eax)
|
2007-09-21 01:57:56 +02:00
|
|
|
|
|
|
|
/* And return 0 */
|
|
|
|
|
2012-05-02 17:36:19 +02:00
|
|
|
xorl %eax, %eax
|
2007-09-21 02:28:48 +02:00
|
|
|
ret
|
2020-01-27 15:59:20 +01:00
|
|
|
#ifdef __ELF__
|
2021-04-05 07:01:15 +02:00
|
|
|
.size SYMBOL(setjmp), . - SYMBOL(setjmp)
|
2007-09-21 02:28:48 +02:00
|
|
|
#endif
|
2021-04-05 07:01:15 +02:00
|
|
|
.globl SYMBOL(longjmp)
|
2020-01-27 15:59:20 +01:00
|
|
|
#ifdef __ELF__
|
2021-04-05 07:01:15 +02:00
|
|
|
.type SYMBOL(longjmp), @function
|
2007-09-21 02:28:48 +02:00
|
|
|
#endif
|
2021-04-05 07:01:15 +02:00
|
|
|
SYMBOL(longjmp):
|
2014-10-03 16:23:57 +02:00
|
|
|
movl 4(%esp), %ecx /* jmpbuf in %ecx. */
|
2007-09-21 02:28:48 +02:00
|
|
|
movl 8(%esp), %eax /* Second argument is return value. */
|
|
|
|
|
|
|
|
/* Save the return address now. */
|
|
|
|
|
2012-05-02 17:36:19 +02:00
|
|
|
movl (JB_PC)(%ecx), %edx
|
2007-09-21 02:28:48 +02:00
|
|
|
|
|
|
|
/* Restore registers. */
|
|
|
|
|
2012-05-02 17:36:19 +02:00
|
|
|
movl (JB_EBX)(%ecx), %ebx
|
|
|
|
movl (JB_ESI)(%ecx), %esi
|
|
|
|
movl (JB_EDI)(%ecx), %edi
|
|
|
|
movl (JB_EBP)(%ecx), %ebp
|
|
|
|
movl (JB_SP)(%ecx), %esp
|
2007-09-21 02:28:48 +02:00
|
|
|
|
|
|
|
/* Jump to saved PC. */
|
|
|
|
|
2012-05-02 17:36:19 +02:00
|
|
|
jmp *%edx
|
2020-01-27 15:59:20 +01:00
|
|
|
#ifdef __ELF__
|
2021-04-05 07:01:15 +02:00
|
|
|
.size SYMBOL(longjmp), . - SYMBOL(longjmp)
|
2007-09-21 02:28:48 +02:00
|
|
|
#endif
|