home *** CD-ROM | disk | FTP | other *** search
/ Internet MPEG Audio Archive / IMAA.mdf / util / dos / l3v100n / rsx / source / fpu.asm < prev    next >
Assembly Source File  |  1994-01-19  |  2KB  |  139 lines

  1. ;
  2. ; FPU.ASM (c) Rainer Schnitker 92,93
  3. ;
  4.  
  5. ;
  6. ; 387 utils
  7. ;
  8.  
  9.     .286
  10.         .model SMALL, C
  11.  
  12.         .data
  13.  
  14.     extrn    emu_entry:PWORD
  15.     extrn    emu_sel:WORD
  16.     havei387    dw        0
  17.  
  18.         .code
  19.  
  20. ;
  21. ; DWORD emu_init( void ) : call emu387 to get copro struct
  22. ;
  23.     public C emu_init
  24. emu_init Proc C
  25.     .386
  26.     push    gs
  27.     mov    eax,12345678H
  28.     mov    gs,emu_sel
  29.     call    pword ptr emu_entry
  30.     ; convert eax = copro-struct in dx:ax
  31.     mov    edx,eax
  32.     shr    edx,16
  33.     and    eax,dword ptr 0FFFFh
  34.     pop    gs
  35.     .286
  36.     ret
  37. emu_init endp
  38.  
  39. ;
  40. ; void emu_switch( WORD , WORD ) : call emu387, to change process status
  41. ;
  42.     public C emu_switch
  43. emu_switch PROC C \
  44.     used_math    :WORD , \
  45.     debugged    :WORD
  46.     .386
  47.     push    gs
  48.     mov    gs,emu_sel
  49.     movzx    ecx,used_math
  50.     movzx    edx,debugged
  51.     call    pword ptr emu_entry
  52.     pop    gs
  53.     .286
  54.         ret
  55. emu_switch endp
  56.  
  57. ;
  58. ; void do_fnsave( unsigned fpu_struct )
  59. ;
  60.     public C do_fnsave
  61. do_fnsave PROC C \
  62.     fpu_struct    :WORD
  63.  
  64.     .386
  65.     movzx    eax,word ptr fpu_struct
  66.     db 066H
  67.     fnsave    [eax]
  68.     fwait
  69.     .286
  70.         ret
  71. do_fnsave endp
  72.  
  73. ;
  74. ; void do_frstor( unsigned fpu_struct )
  75. ;
  76.     public C do_frstor
  77. do_frstor PROC C \
  78.     fpu_struct    :WORD
  79.  
  80.     .386
  81.     movzx    eax,word ptr fpu_struct
  82.     db 066H
  83.     frstor    [eax]
  84.     fwait
  85.     .286
  86.         ret
  87. do_frstor endp
  88.  
  89. ;
  90. ; void do_fninit(void)
  91. ;
  92.     public C do_fninit
  93. do_fninit PROC C
  94.     fninit
  95.     ret
  96. do_fninit endp
  97.  
  98.  
  99.     public C npx_installed
  100. npx_installed PROC C USES SI,
  101.  
  102.     fninit                    ; set SW,CW,..
  103.     mov    si, offset havei387
  104.     mov    word ptr [si],5a5ah
  105.     fnstsw    [si]                ; save SW
  106.     cmp    byte ptr [si],0         ; SW==0 ?
  107.         jne     no_i387
  108.  
  109.     fnstcw    [si]                ; save CW
  110.     mov    ax,[si]             ; check
  111.     and    ax,103fh            ;
  112.     cmp    ax,3fh                ; init ?
  113.         jne     no_i387
  114.  
  115.     fld1                    ; check for 387
  116.     fldz
  117.     fdiv
  118.     fld    st
  119.     fchs
  120.     fcompp
  121.     fstsw    [si]
  122.     mov    ax,[si]
  123.     sahf
  124.         je      no_i387
  125.     fninit                    ; 387 ok ,init
  126.     fnstcw    havei387
  127.     wait
  128.     and    havei387,0fffah
  129.     fldcw    havei387
  130.     mov    ax,1
  131.     jmp    short ende
  132. no_i387:
  133.     mov    ax,0
  134. ende:
  135.         ret
  136. npx_installed endp
  137.  
  138.     end
  139.