home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cl5sr386.zip / GO32 / NPX.ASM < prev    next >
Assembly Source File  |  1992-04-13  |  3KB  |  188 lines

  1. ; This is file NPX.ASM
  2. ;
  3. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  4. ;
  5. ; This file is distributed under the terms listed in the document
  6. ; "copying.dj", available from DJ Delorie at the address above.
  7. ; A copy of "copying.dj" should accompany this file; if not, a copy
  8. ; should be available from where this file was obtained.  This file
  9. ; may not be distributed without a verbatim copy of "copying.dj".
  10. ;
  11. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  12. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. ;
  14.  
  15. ;    History:69,29
  16.     title    tables
  17.     .386p
  18.  
  19.     include build.inc
  20.     include    segdefs.inc
  21.     include tss.inc
  22.     include gdt.inc
  23.     include idt.inc
  24.  
  25. son    macro
  26.     mov    al,33h
  27.     out    61h,al
  28.     endm
  29.  
  30. soff    macro
  31.     mov    al,30h
  32.     out    61h,al
  33.     endm
  34.  
  35. ;------------------------------------------------------------------------
  36.  
  37.     start_data16
  38.  
  39.     extrn    _npx:byte
  40.     extrn    ivec_number:byte
  41.  
  42.     public    _npx_stored
  43. _npx_stored    db    0        ; 0=in 387, 1=in _npx
  44.  
  45. temp87    dw    1 dup (?)
  46.  
  47.     end_data16
  48.  
  49. ;------------------------------------------------------------------------
  50.  
  51.     start_code16
  52.  
  53. ;------------------------------------------------------------------------
  54.  
  55.     public    _detect_80387        ; direct from the Intel manual
  56. _detect_80387:                ; returns 1 if 387, else 0
  57.     push    si
  58.     fninit
  59.     mov    si,offset dgroup:temp87
  60.     mov    word ptr [si],5a5ah
  61.     fnstsw    [si]
  62.     cmp    byte ptr [si],0
  63.     jne    no_387
  64.  
  65.     fnstcw    [si]
  66.     mov    ax,[si]
  67.     and    ax,103fh
  68.     cmp    ax,3fh
  69.     jne    no_387
  70.  
  71.     fld1
  72.     fldz
  73.     fdiv
  74.     fld    st
  75.     fchs
  76.     fcompp
  77.     fstsw    [si]
  78.     mov    ax,[si]
  79.     sahf
  80.     je    no_387
  81.     fninit            ; 387 present, initialize.
  82.     fnstcw    temp87
  83.     wait
  84.     and    temp87,0fffah    ; enable invalid operation exception
  85.     fldcw    temp87
  86.     mov    ax,1
  87.     pop    si
  88.     ret
  89.  
  90. no_387:
  91.     mov    ax,0
  92.     pop    si
  93.     ret
  94.  
  95. ;------------------------------------------------------------------------
  96.  
  97.     public    _ivec7
  98. _ivec7:
  99.     push    eax
  100.     mov    eax,cr0
  101.     and    eax,0FFFFFFF3h
  102.     mov    cr0,eax
  103.     pop    eax
  104.     iretd
  105.  
  106.     public    _fclex        ; for either mode
  107. _fclex:
  108.     in    al,0a0h
  109.     test    al,20h
  110.     jz    fclex_ret
  111.     or    ax,ax
  112.     out    0f0h,al
  113.     mov    al,20h
  114.     out    0a0h,al
  115.     out    20h,al
  116. fclex_ret:
  117.     ret
  118.  
  119.     public    _ivec75
  120. _ivec75:
  121.     push    ax
  122.     push    ds
  123.  
  124.     push    g_core
  125.     pop    ds
  126.     inc    word ptr ds:[0b8004h]
  127.  
  128.     push    g_rdata
  129.     pop    ds
  130.     mov    _npx_stored,1
  131.     or    ax,ax
  132.     out    0f0h,al
  133.     mov    al,20h
  134.     out    0a0h,al
  135.     out    20h,al
  136. ;    fnsave    ds:[_npx]
  137.     db    66h,67h,0ddh,35h
  138.     dd    offset _npx
  139.     fwait
  140.  
  141.     mov    ivec_number,75h
  142.     pop    ds
  143.     pop    ax
  144.     db    0eah
  145.     dw    0, g_itss
  146.  
  147. ;------------------------------------------------------------------------
  148.  
  149.     public    __do_save_npx
  150. __do_save_npx:
  151.     cmp    _npx_stored,0
  152.     jne    fpsave_ret
  153.     call    _fclex
  154.     mov    _npx_stored,1
  155. ;    fnsave    ds:[_npx]
  156.     db    66h,67h,0ddh,35h
  157.     dd    offset _npx
  158.     fwait
  159. fpsave_ret:
  160.     jmpt    g_ctss
  161.  
  162.     public    __do_load_npx        ; from *protected* mode
  163. __do_load_npx:
  164.     cmp    _npx_stored,0
  165.     je    no_load_npx
  166.     call    _fclex
  167.     mov    _npx_stored,0
  168.     mov    _npx[4],0        ; clear pending exceptions
  169. ;    frstor    [_npx]
  170.     db    66h,67h,0ddh,25h
  171.     dd    offset _npx
  172. no_load_npx:
  173.     ret
  174.  
  175. ;------------------------------------------------------------------------
  176.  
  177.     end_code16
  178.  
  179. ;------------------------------------------------------------------------
  180.  
  181.     start_code32
  182.  
  183.     end_code32
  184.  
  185. ;------------------------------------------------------------------------
  186.  
  187.     end
  188.