Untitled diff

Created Diff never expires
126 removals
Words removed273
Total words303
Words removed (%)90.10
134 lines
41 additions
Words added129
Total words159
Words added (%)81.13
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 (setjmp)
.global SYM (longjmp)
.global SYM (longjmp)
SOTYPE_FUNCTION(setjmp)
SOTYPE_FUNCTION(setjmp)
SOTYPE_FUNCTION(longjmp)
SOTYPE_FUNCTION(longjmp)

SYM (setjmp):
SYM (setjmp):

movq rbx, 0 (rdi)
#ifdef __iamcu__
movq rbp, 8 (rdi)
/* Store EIP. */
movq r12, 16 (rdi)
movl 0(esp),ecx
movq r13, 24 (rdi)
movl ecx,20(eax)
movq r14, 32 (rdi)

movq r15, 40 (rdi)
movl ebx,0 (eax)
leaq 8 (rsp), rax
movl esi,4 (eax)
movq rax, 48 (rdi)
movl edi,8 (eax)
movq (rsp), rax
movl ebp,12(eax)
movq rax, 56 (rdi)

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

xorl eax,eax
#else
pushl ebp
movl esp,ebp

pushl edi
movl 8 (ebp),edi

movl eax,0 (edi)
movl ebx,4 (edi)
movl ecx,8 (edi)
movl edx,12 (edi)
movl esi,16 (edi)

movl -4 (ebp),eax
movl eax,20 (edi)

movl 0 (ebp),eax
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. */
pushl 20(eax)

movl 0(eax),ebx
movl 4(eax),esi
movl 8(eax),edi
movl 12(eax),ebp
movl edx,eax
#else
pushl ebp
movl esp,ebp

movl 8(ebp),edi /* get jmp_buf */
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
movq 8 (rdi), rbp
movl 28(edi),esp
pushl 32(edi)


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


ret
ret