Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /****************************************************************************
  2. *
  3. *                            Open Watcom Project
  4. *
  5. *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. *
  7. *  ========================================================================
  8. *
  9. *    This file contains Original Code and/or Modifications of Original
  10. *    Code as defined in and that are subject to the Sybase Open Watcom
  11. *    Public License version 1.0 (the 'License'). You may not use this file
  12. *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. *    provided with the Original Code and Modifications, and is also
  15. *    available at www.sybase.com/developer/opensource.
  16. *
  17. *    The Original Code and all software distributed under the License are
  18. *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. *    NON-INFRINGEMENT. Please see the License for the specific language
  23. *    governing rights and limitations under the License.
  24. *
  25. *  ========================================================================
  26. *
  27. * Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
  28. *               DESCRIBE IT HERE!
  29. *
  30. ****************************************************************************/
  31.  
  32.  
  33. #include "variety.h"
  34. #include <math.h>
  35. #include <float.h>
  36. #include "rtdata.h"
  37.  
  38. extern  void    __fstcw();
  39. extern  void    __fldcw();
  40.  
  41. #if defined(__WINDOWS__) && !defined(__WINDOWS_386__)
  42.  
  43. extern void __far _fpmath();
  44. #pragma aux _fpmath "__fpmath";
  45.  
  46. void __win87em_fldcw(unsigned int);
  47. #pragma aux __win87em_fldcw = \
  48.         "push   bx"                                     \
  49.         "mov    bx, 4h"                                 \
  50.         "call   far ptr _fpmath"                        \
  51.         "pop    bx"                                     \
  52.         parm [ax]
  53.  
  54. unsigned int __win87em_fstcw(void);
  55. #pragma aux __win87em_fstcw = \
  56.         "push   bx"                                     \
  57.         "mov    bx, 5h"                                 \
  58.         "call   far ptr _fpmath"                        \
  59.         "pop    bx"                                     \
  60.         value [ax]
  61.  
  62. #elif defined( __DOS_086__ )
  63.  
  64. extern unsigned char __dos87real;
  65. #pragma aux __dos87real "*";
  66.  
  67. extern unsigned short __dos87emucall;
  68. #pragma aux __dos87emucall "*";
  69.  
  70. void _WCI86NEAR __dos_emu_fldcw( unsigned short * );
  71. #pragma aux __dos_emu_fldcw "*" = \
  72.         "mov    ax,3" \
  73.         "call   __dos87emucall" \
  74.         parm [bx];
  75.        
  76. void _WCI86NEAR __dos_emu_fstcw( unsigned short * );
  77. #pragma aux __dos_emu_fstcw "*" = \
  78.         "mov    ax,4" \
  79.         "call   __dos87emucall" \
  80.         parm [bx];
  81.  
  82. #endif
  83.  
  84. #if defined(__386__)
  85. #pragma aux __fstcw = \
  86.         "fstcw ss:[edi]" \
  87.         "fwait"          \
  88.         parm caller [edi];
  89. #pragma aux __fldcw = \
  90.         "fldcw ss:[edi]" \
  91.         parm caller [edi];
  92. #else
  93. #pragma aux __fstcw = \
  94.         "xchg ax,bp"           \
  95.         "fstcw [bp]" \
  96.         "fwait"                \
  97.         "xchg ax,bp"           \
  98.         parm caller [ax];
  99. #pragma aux __fldcw = \
  100.         "xchg ax,bp"           \
  101.         "fldcw [bp]" \
  102.         "xchg ax,bp"           \
  103.         parm caller [ax];
  104. #endif
  105.  
  106. _WCRTLINK unsigned _control87( unsigned new, unsigned mask )
  107. /**********************************************************/
  108. {
  109.     auto short unsigned int control_word;
  110.  
  111.     control_word = 0;
  112.     if( _RWD_8087 ) {
  113. #if defined(__WINDOWS__) && !defined(__WINDOWS_386__)
  114.         __fstcw( &control_word );
  115.         control_word = __win87em_fstcw();
  116.         if( mask != 0 ) {
  117.             control_word = (control_word & ~mask) | (new & mask);
  118.             __fldcw( &control_word );
  119.             __fstcw( &control_word );               /* 17-sep-91 */
  120.             __win87em_fldcw(control_word);
  121.         }
  122. #elif defined( __DOS_086__ )
  123.         if( __dos87real ) {
  124.             __fstcw( &control_word );
  125.             if( mask != 0 ) {
  126.                 control_word = (control_word & ~mask) | (new & mask);
  127.                 __fldcw( &control_word );
  128.                 __fstcw( &control_word );
  129.             }
  130.         }
  131.         if( __dos87emucall ) {
  132.             __dos_emu_fstcw( &control_word );
  133.             if( mask != 0 ) {
  134.                 control_word = (control_word & ~mask) | (new & mask);
  135.                 __dos_emu_fldcw( &control_word );
  136.                 __dos_emu_fstcw( &control_word );
  137.             }
  138.         }
  139. #else
  140.         __fstcw( &control_word );
  141.         if( mask != 0 ) {
  142.             control_word = (control_word & ~mask) | (new & mask);
  143.             __fldcw( &control_word );
  144.             __fstcw( &control_word );               /* 17-sep-91 */
  145.         }
  146. #endif
  147.     }
  148.     return( control_word );
  149. }
  150.