Subversion Repositories Kolibri OS

Rev

Rev 702 | Blame | Compare with Previous | 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:  __chk8087 and other FPU related functions.
  28. *
  29. ****************************************************************************/
  30.  
  31.  
  32. #include "variety.h"
  33. #include <stdlib.h>
  34. #include <float.h>
  35. #if defined( __OS2__ )
  36. #endif
  37. #if defined( __WINDOWS__ )
  38.   #include <i86.h>
  39. #endif
  40.  
  41. #include "rtdata.h"
  42. #include "exitwmsg.h"
  43. #include "87state.h"
  44.  
  45. extern void __GrabFP87( void );
  46.  
  47. extern unsigned short __8087cw;
  48. #pragma aux __8087cw "*";
  49.  
  50. #if defined( __DOS_086__ )
  51. extern unsigned char __dos87real;
  52. #pragma aux __dos87real "*";
  53.  
  54. extern unsigned short __dos87emucall;
  55. #pragma aux __dos87emucall "*";
  56. #endif
  57.  
  58. extern void __init_80x87( void );
  59. #if defined( __DOS_086__ )
  60. #pragma aux __init_80x87 "*" = \
  61.         ".8087" \
  62.         "cmp    __dos87real,0" \
  63.         "jz     l1" \
  64.         "finit" \
  65.         "fldcw  __8087cw" \
  66. "l1:     cmp    __dos87emucall,0" \
  67.         "jz     l2" \
  68.         "mov    ax,1" \
  69.         "call   __dos87emucall" \
  70. "l2:" ;
  71. #else
  72. #pragma aux __init_80x87 "*" = \
  73.         ".8087" \
  74.         "finit" \
  75.         "fldcw  __8087cw" ;
  76. #endif
  77.  
  78. /* 0 => no 8087; 2 => 8087,287; 3=>387 */
  79. extern unsigned char _WCI86NEAR __x87id( void );
  80. #pragma aux __x87id "*";
  81.  
  82. #if !defined( __UNIX__ ) && !defined( __OS2_386__ )
  83.  
  84. extern void __fsave( _87state * );
  85. extern void __frstor( _87state * );
  86.  
  87. #if defined( __386__ )
  88.  
  89.     #pragma aux __fsave =                                           \
  90.     0x9b 0xdd 0x30  /* fsave    [eax]   ; save the 8087 state */    \
  91.     0x9b            /* wait                                   */    \
  92.     parm routine [eax];
  93.  
  94.     #pragma aux __frstor =                                          \
  95.     0xdd 0x20       /* frstor   [eax]   ; restore the 8087 */       \
  96.     0x9b            /* wait             ; wait             */       \
  97.     parm routine [eax];
  98.  
  99. #else   /* __286__ */
  100.  
  101.   #if defined( __BIG_DATA__ )
  102.     #pragma aux __fsave =                                           \
  103.     0x53            /* push    bx                           */      \
  104.     0x1e            /* push    ds                           */      \
  105.     0x8e 0xda       /* mov     ds,dx                        */      \
  106.     0x8b 0xd8       /* mov     bx,ax                        */      \
  107.     0x9b 0xdd 0x37  /* fsave   [bx]                         */      \
  108.     0x90 0x9b       /* fwait                                */      \
  109.     0x1f            /* pop     ds                           */      \
  110.     0x5b            /* pop     bx                           */      \
  111.     parm routine [dx ax];
  112.   #else
  113.     #pragma aux __fsave =                                           \
  114.     0x53            /* push    bx                           */      \
  115.     0x8b 0xd8       /* mov     bx,ax                        */      \
  116.     0x9b 0xdd 0x37  /* fsave   [bx]                         */      \
  117.     0x90 0x9b       /* fwait                                */      \
  118.     0x5b            /* pop     bx                           */      \
  119.     parm routine [ax];
  120.   #endif
  121.  
  122.   #if defined( __BIG_DATA__ )
  123.     #pragma aux __frstor =                                          \
  124.     0x53            /* push    bx                           */      \
  125.     0x1e            /* push    ds                           */      \
  126.     0x8e 0xda       /* mov     ds,dx                        */      \
  127.     0x8b 0xd8       /* mov     bx,ax                        */      \
  128.     0x9b 0xdd 0x27  /* frstor  [bx]                         */      \
  129.     0x90 0x9b       /* fwait                                */      \
  130.     0x1f            /* pop     ds                           */      \
  131.     0x5b            /* pop     bx                           */      \
  132.     parm routine [dx ax];
  133.   #else
  134.     #pragma aux __frstor =                                          \
  135.     0x53            /* push    bx                           */      \
  136.     0x8b 0xd8       /* mov     bx,ax                        */      \
  137.     0x9b 0xdd 0x27  /* frstor  [bx]                         */      \
  138.     0x90 0x9b       /* fwait                                */      \
  139.     0x5b            /* pop     bx                           */      \
  140.     parm routine [ax];
  141.   #endif
  142.  
  143. #endif
  144.  
  145. static void __save_8087( _87state * __fs )
  146. {
  147.     __fsave( __fs );
  148. }
  149.  
  150. static void __rest_8087( _87state * __fs )
  151. {
  152.     __frstor( __fs );
  153. }
  154. #endif  /* !__UNIX__ && && !__OS2__ */
  155.  
  156. _WCRTLINK void _fpreset( void )
  157. {
  158.     if( _RWD_8087 != 0 ) {
  159.         __init_80x87();
  160.     }
  161. }
  162.  
  163. void __init_8087( void )
  164. {
  165. #if !defined( __UNIX__ ) && !defined( __OS2_386__ )
  166.     if( _RWD_real87 != 0 )
  167.     {            /* if our emulator, don't worry */
  168.         _RWD_Save8087 = __save_8087;    /* point to real save 8087 routine */
  169.         _RWD_Rest8087 = __rest_8087;    /* point to real restore 8087 routine */
  170.     }
  171. #endif
  172.     _fpreset();
  173. }
  174.  
  175. #if defined( __DOS__ ) || defined( __OS2_286__ )
  176.  
  177. void _WCI86FAR __default_sigfpe_handler( int fpe_sig )
  178. {
  179.     __fatal_runtime_error( "Floating point exception\r\n", EXIT_FAILURE );
  180. }
  181. #endif
  182.  
  183. void __chk8087( void )
  184. /********************/
  185. {
  186.     _RWD_real87 = __x87id();
  187.     _RWD_8087 = _RWD_real87;
  188.     __init_8087();
  189.     __GrabFP87();
  190. }
  191.  
  192.