fpu.as 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. /* Translated from tasm to GAS by C. Sandmann */
  3. /* One comment displaced to get it compiled by as.exe directly !!! */
  4. /* by Pierre Muller */
  5. /* This routine assumes DS == SS since [ESI] coding shorter than [EBP] coding */
  6. .global __detect_80387 /* direct from the Intel manual */
  7. __detect_80387: /* returns 1 if 387 (or more), else 0 */
  8. pushl %esi
  9. pushl %eax /* Dummy work area on stack */
  10. movl %esp,%esi
  11. fninit
  12. movw $0x5a5a,(%esi)
  13. fnstsw (%esi)
  14. cmpb $0,(%esi)
  15. jne Lno_387
  16. fnstcw (%esi)
  17. movl (%esi),%eax /* Only ax significant */
  18. andl $0x103f,%eax
  19. cmpl $0x3f,%eax
  20. jne Lno_387
  21. fld1
  22. fldz
  23. /* fdiv GAS encodes this as 0xdcf1 !! BUG */
  24. .byte 0xde,0xf9
  25. fld %st
  26. fchs
  27. fcompp
  28. fstsw (%esi)
  29. movzwl (%esi),%eax /* Clears upper %eax */
  30. sahf
  31. je Lno_387
  32. fninit /* 387 present, initialize. */
  33. fnstcw (%esi)
  34. wait
  35. andw $0x0fffa,(%esi)
  36. /* enable invalid operation exception */
  37. fldcw (%esi)
  38. movw $1,%ax
  39. jmp Lexit
  40. Lno_387:
  41. xorl %eax,%eax
  42. Lexit:
  43. popl %esi /* Fix stack first */
  44. popl %esi
  45. ret