Untitled diff

Created Diff never expires
124 removals
134 lines
44 additions
55 lines
https://github.com/Alexpux/Cygwin/blob/master/newlib/libc/machine/i386/setjmp.S
https://github.com/Alexpux/Cygwin/blob/master/newlib/libc/machine/x86_64/setjmp.S


/* This is file is a merger of SETJMP.S and LONGJMP.S */
/*
/*
* This file was modified to use the __USER_LABEL_PREFIX__ and
* ====================================================
* __REGISTER_PREFIX__ macros defined by later versions of GNU cpp by
* Copyright (C) 2007 by Ellips BV. All rights reserved.
* Joel Sherrill (joel@OARcorp.com)
* Slight change: now includes i386mach.h for this (Werner Almesberger)
*
* Copyright (C) 1991 DJ Delorie
* All rights reserved.
*
* Redistribution, modification, and use in source and binary forms is permitted
* provided that the above copyright notice and following paragraph are
* duplicated in all such forms.
*
*
* This file is distributed WITHOUT ANY WARRANTY; without even the implied
* Permission to use, copy, modify, and distribute this
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* software is freely granted, provided that this notice
* is preserved.
* ====================================================
*/
*/


/*
/*
** jmp_buf:
** jmp_buf:
** eax ebx ecx edx esi edi ebp esp eip
** rbx rbp r12 r13 r14 r15 rsp rip
** 0 4 8 12 16 20 24 28 32
** 0 8 16 24 32 40 48 56
**
** Intel MCU jmp_buf:
** ebx esi edi ebp esp eip
** 0 4 8 12 16 20
*/
*/


#include "i386mach.h"
#include "x86_64mach.h"

.global SYM (setjmp)
.global SYM (longjmp)
SOTYPE_FUNCTION(setjmp)
SOTYPE_FUNCTION(longjmp)
SYM (setjmp):

#ifdef __iamcu__
/* Store EIP. */
movl 0(esp),ecx
movl ecx,20(eax)

movl ebx,0 (eax)
movl esi,4 (eax)
movl edi,8 (eax)
movl ebp,12(eax)

/* Skip return address, which will be pushed onto stack in
longjmp, and store SP. */
leal 4(esp),ecx
movl ecx,16(eax)


xorl eax,eax
.global SYM (setjmp)
#else
.global SYM (longjmp)
pushl ebp
SOTYPE_FUNCTION(setjmp)
movl esp,ebp
SOTYPE_FUNCTION(longjmp)


pushl edi
SYM (setjmp):
movl 8 (ebp),edi
movq rbx, 0 (rdi)

movq rbp, 8 (rdi)
movl eax,0 (edi)
movq r12, 16 (rdi)
movl ebx,4 (edi)
movq r13, 24 (rdi)
movl ecx,8 (edi)
movq r14, 32 (rdi)
movl edx,12 (edi)
movq r15, 40 (rdi)
movl esi,16 (edi)
leaq 8 (rsp), rax

movq rax, 48 (rdi)
movl -4 (ebp),eax
movq (rsp), rax
movl eax,20 (edi)
movq rax, 56 (rdi)

movq $0, rax
movl 0 (ebp),eax
ret
movl eax,24 (edi)

movl esp,eax
addl $12,eax
movl eax,28 (edi)
movl 4 (ebp),eax
movl eax,32 (edi)

popl edi
movl $0,eax
leave
#endif
ret


SYM (longjmp):
SYM (longjmp):
#ifdef __iamcu__
movq rsi, rax /* Return value */
/* Check retval. */
testl edx,edx
jne 0f
incl edx
0:
/* Restore stack first. */
movl 16(eax),esp


/* Put return address on stack. */
movq 8 (rdi), rbp
pushl 20(eax)


movl 0(eax),ebx
__CLI
movl 4(eax),esi
movq 48 (rdi), rsp
movl 8(eax),edi
pushq 56 (rdi)
movl 12(eax),ebp
movq 0 (rdi), rbx
movl edx,eax
movq 16 (rdi), r12
#else
movq 24 (rdi), r13
pushl ebp
movq 32 (rdi), r14
movl esp,ebp
movq 40 (rdi), r15
__STI


movl 8(ebp),edi /* get jmp_buf */
ret
movl 12(ebp),eax /* store retval in j->eax */
testl eax,eax
jne 0f
incl eax
0:
movl eax,0(edi)

movl 24(edi),ebp

__CLI
movl 28(edi),esp
pushl 32(edi)

movl 0(edi),eax
movl 4(edi),ebx
movl 8(edi),ecx
movl 12(edi),edx
movl 16(edi),esi
movl 20(edi),edi
__STI
#endif

ret