From 3fe2b722fd56c25ae8c506d5d12cafd8d80bca60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Sun, 6 Apr 2003 12:40:56 +0000 Subject: [PATCH] Added _setjmp3() and __p__iob() svn path=/trunk/; revision=4508 --- reactos/lib/msvcrt/Makefile | 5 +- reactos/lib/msvcrt/msvcrt.def | 6 +- reactos/lib/msvcrt/setjmp/.cvsignore | 3 - reactos/lib/msvcrt/setjmp/i386/.cvsignore | 2 + reactos/lib/msvcrt/setjmp/i386/setjmp.s | 111 +++++++++++++++++ reactos/lib/msvcrt/setjmp/setjmp.c | 142 ---------------------- reactos/lib/msvcrt/stdio/stdhnd.c | 6 +- 7 files changed, 123 insertions(+), 152 deletions(-) delete mode 100644 reactos/lib/msvcrt/setjmp/.cvsignore create mode 100644 reactos/lib/msvcrt/setjmp/i386/.cvsignore create mode 100644 reactos/lib/msvcrt/setjmp/i386/setjmp.s delete mode 100644 reactos/lib/msvcrt/setjmp/setjmp.c diff --git a/reactos/lib/msvcrt/Makefile b/reactos/lib/msvcrt/Makefile index e5e5c62ae2e..1aac2e5c6e1 100644 --- a/reactos/lib/msvcrt/Makefile +++ b/reactos/lib/msvcrt/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.31 2002/12/10 19:09:26 hbirr Exp $ +# $Id: Makefile,v 1.32 2003/04/06 12:40:55 gvg Exp $ PATH_TO_TOP = ../.. @@ -34,6 +34,7 @@ TARGET_CLEAN = \ process/*.o \ search/*.o \ setjmp/*.o \ + setjmp/i386/*.o \ signal/*.o \ stdio/*.o \ stdlib/*.o \ @@ -273,7 +274,7 @@ SEARCH_OBJECTS = \ search/lsearch.o SETJMP_OBJECTS = \ - setjmp/setjmp.o + setjmp/i386/setjmp.o SIGNAL_OBJECTS = \ signal/signal.o diff --git a/reactos/lib/msvcrt/msvcrt.def b/reactos/lib/msvcrt/msvcrt.def index 064c5c9e692..f4d5ce9b328 100644 --- a/reactos/lib/msvcrt/msvcrt.def +++ b/reactos/lib/msvcrt/msvcrt.def @@ -1,4 +1,4 @@ -; $Id: msvcrt.def,v 1.18 2003/02/21 21:50:04 jfilby Exp $ +; $Id: msvcrt.def,v 1.19 2003/04/06 12:40:55 gvg Exp $ ; ; ReactOS MSVCRT Compatibility Library ; @@ -124,7 +124,7 @@ __p__commode __p__environ ; __p__fileinfo __p__fmode -; __p__iob +__p__iob ; __p__mbcasemap ; __p__mbctype __p__osver @@ -436,7 +436,7 @@ _searchenv ; _set_sbh_threshold _seterrormode _setjmp -; _setjmp3 +_setjmp3 ; _setmaxstdio ; _setmbcp _setmode diff --git a/reactos/lib/msvcrt/setjmp/.cvsignore b/reactos/lib/msvcrt/setjmp/.cvsignore deleted file mode 100644 index bd0e3dfd3ef..00000000000 --- a/reactos/lib/msvcrt/setjmp/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -*.d -*.o -*.sym diff --git a/reactos/lib/msvcrt/setjmp/i386/.cvsignore b/reactos/lib/msvcrt/setjmp/i386/.cvsignore new file mode 100644 index 00000000000..2806cdcbd72 --- /dev/null +++ b/reactos/lib/msvcrt/setjmp/i386/.cvsignore @@ -0,0 +1,2 @@ +.*.d +*.o \ No newline at end of file diff --git a/reactos/lib/msvcrt/setjmp/i386/setjmp.s b/reactos/lib/msvcrt/setjmp/i386/setjmp.s new file mode 100644 index 00000000000..ccc10cd1417 --- /dev/null +++ b/reactos/lib/msvcrt/setjmp/i386/setjmp.s @@ -0,0 +1,111 @@ +/* $Id: setjmp.s,v 1.1 2003/04/06 12:40:55 gvg Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS system libraries + * PURPOSE: Implementation of _setjmp/longjmp + * FILE: lib/msvcrt/i386/setjmp.s + * PROGRAMMER: Ge van Geldorp (ge@gse.nl) + * NOTES: Implementation is not complete, see Wine source for a more + * complete implementation + */ + +#define JB_BP 0 +#define JB_BX 1 +#define JB_DI 2 +#define JB_SI 3 +#define JB_SP 4 +#define JB_IP 5 + +#define PCOFF 0 + +#define JMPBUF 4 + +/* + * int + * _setjmp(jmp_buf env); + * + * Parameters: + * [ESP+04h] - jmp_buf env + * Registers: + * None + * Returns: + * 0 + * Notes: + * Sets up the jmp_buf + */ +.globl __setjmp +__setjmp: + xorl %eax, %eax + movl JMPBUF(%esp), %edx + + /* Save registers. */ + movl %ebp, (JB_BP*4)(%edx) /* Save caller's frame pointer. */ + movl %ebx, (JB_BX*4)(%edx) + movl %edi, (JB_DI*4)(%edx) + movl %esi, (JB_SI*4)(%edx) + leal JMPBUF(%esp), %ecx /* Save SP as it will be after we return. */ + movl %ecx, (JB_SP*4)(%edx) + movl PCOFF(%esp), %ecx /* Save PC we are returning to now. */ + movl %ecx, (JB_IP*4)(%edx) + ret + +/* + * int + * _setjmp3(jmp_buf env, int nb_args, ...); + * + * Parameters: + * [ESP+04h] - jmp_buf env + * Registers: + * None + * Returns: + * 0 + * Notes: + * Sets up the jmp_buf + */ +.globl __setjmp3 +__setjmp3: + xorl %eax, %eax + movl JMPBUF(%esp), %edx + + /* Save registers. */ + movl %ebp, (JB_BP*4)(%edx) /* Save caller's frame pointer. */ + movl %ebx, (JB_BX*4)(%edx) + movl %edi, (JB_DI*4)(%edx) + movl %esi, (JB_SI*4)(%edx) + leal JMPBUF(%esp), %ecx /* Save SP as it will be after we return. */ + movl %ecx, (JB_SP*4)(%edx) + movl PCOFF(%esp), %ecx /* Save PC we are returning to now. */ + movl %ecx, (JB_IP*4)(%edx) + ret + +#define VAL 8 + +/* + * void + * longjmp(jmp_buf env, int value); + * + * Parameters: + * [ESP+04h] - jmp_buf setup by _setjmp + * [ESP+08h] - int value to return + * Registers: + * None + * Returns: + * Doesn't return + * Notes: + * Non-local goto + */ +.globl _longjmp +_longjmp: + movl JMPBUF(%esp), %ecx /* User's jmp_buf in %ecx. */ + + movl VAL(%esp), %eax /* Second argument is return value. */ + /* Save the return address now. */ + movl (JB_IP*4)(%ecx), %edx + /* Restore registers. */ + movl (JB_BP*4)(%ecx), %ebp + movl (JB_BX*4)(%ecx), %ebx + movl (JB_DI*4)(%ecx), %edi + movl (JB_SI*4)(%ecx), %esi + movl (JB_SP*4)(%ecx), %esp + /* Jump to saved PC. */ + jmp *%edx diff --git a/reactos/lib/msvcrt/setjmp/setjmp.c b/reactos/lib/msvcrt/setjmp/setjmp.c deleted file mode 100644 index 25202e216cd..00000000000 --- a/reactos/lib/msvcrt/setjmp/setjmp.c +++ /dev/null @@ -1,142 +0,0 @@ -/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ -/* modified by Boudewijn Dekker */ -/* ms uses a smaller jmp_buf structure */ -/* might do a realloc in setjmp */ - -typedef struct { - unsigned int __eax, __ebx, __ecx, __edx, __esi; - unsigned int __edi, __ebp, __esp, __eip, __eflags; - unsigned short __cs, __ds, __es, __fs, __gs, __ss; - unsigned long __sigmask; /* for POSIX signals only */ - unsigned long __signum; /* for expansion */ - unsigned long __exception_ptr; /* pointer to previous exception */ - unsigned char __fpu_state[108]; /* for future use */ -} jmp_buf[1]; - - -/* jumps back to position specified in jmp_buf */ - -int longjmp( jmp_buf env, int value ) -{ - //push ebp generated by the compiler - //mov ebp, esp - -#ifdef __GNUC__ - __asm__ __volatile__ ( - "movl 8(%ebp),%edi\n\t" /* get jmp_buf */ - "movl 12(%ebp),%eax\n\t" /* store retval in j->eax */ - "movl %eax,0(%edi)\n\t" - - "movw 46(%edi),%fs\n\t" - "movw 48(%edi),%gs\n\t" - "movl 4(%edi),%ebx\n\t" - "movl 8(%edi),%ecx\n\t" - "movl 12(%edi),%edx\n\t" - "movl 24(%edi),%ebp\n\t" - - /* Now for some uglyness. The jmp_buf structure may be ABOVE the - point on the new SS:ESP we are moving to. We don't allow overlap, - but do force that it always be valid. We will use ES:ESI for - our new stack before swapping to it. */ - - "movw 50(%edi),%es\n\t" - "movl 28(%edi),%esi\n\t" - "subl $28,%esi\n\t" /* We need 7 working longwords on stack */ - - "movl 60(%edi),%eax\n\t" - "es\n\t" - "movl %eax,(%esi)\n\t" /* Exception pointer */ - - "movzwl 42(%edi),%eax\n\t" - "es\n\t" - "movl %eax,4(%esi)\n\t" /* DS */ - - "movl 20(%edi),%eax\n\t" - "es\n\t" - "movl %eax,8(%esi)\n\t" /* EDI */ - - "movl 16(%edi),%eax\n\t" - "es\n\t" - "movl %eax,12(%esi)\n\t" /* ESI */ - - "movl 32(%edi),%eax\n\t" - "es\n\t" - "movl %eax,16(%esi)\n\t" /* EIP - start of IRET frame */ - - "movl 40(%edi),%eax\n\t" - "es\n\t" - "movl %eax,20(%esi)\n\t" /* CS */ - - "movl 36(%edi),%eax\n\t" - "es\n\t" - "movl %eax,24(%esi)\n\t" /* EFLAGS */ - - "movl 0(%edi),%eax\n\t" - "movw 44(%edi),%es\n\t" - - "movw 50(%edi),%ss\n\t" - "movl %esi,%esp\n\t" - - //"popl ___djgpp_exception_state_ptr\n\t" - "popl %edi\n\t" // dummy popl instead of djgpp_exception_state_ptr - "popl %ds\n\t" - "popl %edi\n\t" - "popl %esi\n\t" - - "iret\n\t" /* actually jump to new cs:eip loading flags */ - ); - -#else -#endif /*__GNUC__*/ - return value; // dummy return never reached -} - -#ifdef __GNUC__ - -int _setjmp( jmp_buf env ) -{ - //push ebp generated by the compiler - //mov ebp, esp - __asm__ __volatile__ ( - "pushl %edi\n\t" - "movl 8(%ebp),%edi\n\t" - - "movl %eax, (%edi)\n\t" - "movl %ebx,4(%edi)\n\t" - "movl %ecx,8(%edi)\n\t" - "movl %edx,12(%edi)\n\t" - "movl %esi,16(%edi)\n\t" - - "movl -4(%ebp),%eax\n\t" - "movl %eax,20(%edi)\n\t" - - "movl (%ebp),%eax\n\t" - "movl %eax,24(%edi)\n\t" - - "movl %esp,%eax\n\t" - "addl $12,%eax\n\t" - "movl %eax,28(%edi)\n\t" - - "movl 4(%ebp),%eax\n\t" - "movl %eax,32(%edi)\n\t" - - "pushfl\n\t" - "popl 36(%edi)\n\t" - - "movw %cs, 40(%edi)\n\t" - "movw %ds, 42(%edi)\n\t" - "movw %es, 44(%edi)\n\t" - "movw %fs, 46(%edi)\n\t" - "movw %gs, 48(%edi)\n\t" - "movw %ss, 50(%edi)\n\t" - - //movl ___djgpp_exception_state_ptr, %eax - //movl %eax, 60(%edi) - - "popl %edi\n\t" - ); - return 0; -} - -#else -#endif /*__GNUC__*/ diff --git a/reactos/lib/msvcrt/stdio/stdhnd.c b/reactos/lib/msvcrt/stdio/stdhnd.c index c4fc04df908..be272fe0e91 100644 --- a/reactos/lib/msvcrt/stdio/stdhnd.c +++ b/reactos/lib/msvcrt/stdio/stdhnd.c @@ -36,5 +36,7 @@ FILE _iob[5] = } }; - - +FILE *__p__iob(void) +{ + return &_iob[0]; +}