fpu.as 1.7 KB

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