cpu.pp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Florian Klaempfl
  4. This unit contains some routines to get informations about the
  5. processor
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit cpu;
  13. interface
  14. { returns true, if the processor supports the cpuid instruction }
  15. function cpuid_support : boolean;
  16. { returns true, if floating point is done by an emulator }
  17. function floating_point_emulation : boolean;
  18. { returns the contents of the cr0 register }
  19. function cr0 : longint;
  20. implementation
  21. {$ASMMODE INTEL}
  22. function cpuid_support : boolean;assembler;
  23. {
  24. Check if the ID-flag can be changed, if changed then CpuID is supported.
  25. Tested under go32v1 and Linux on c6x86 with CpuID enabled and disabled (PFV)
  26. }
  27. asm
  28. pushf
  29. pushf
  30. pop eax
  31. mov ebx,eax
  32. xor eax,200000h
  33. push eax
  34. popf
  35. pushf
  36. pop eax
  37. popf
  38. and eax,200000h
  39. and ebx,200000h
  40. cmp eax,ebx
  41. setnz al
  42. end;
  43. function cr0 : longint;assembler;
  44. asm
  45. DB 0Fh,20h,0C0h
  46. { mov eax,cr0
  47. special registers are not allowed in the assembler
  48. parsers }
  49. end;
  50. function floating_point_emulation : boolean;
  51. begin
  52. {!!!! I don't know currently the position of the EM flag }
  53. { $4 after Ralf Brown's list }
  54. floating_point_emulation:=(cr0 and $4)<>0;
  55. end;
  56. end.