cpu.pp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2016 by the Free Pascal development team
  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. {$mode objfpc}
  13. {$IFNDEF FPC_DOTTEDUNITS}
  14. unit cpu;
  15. {$ENDIF FPC_DOTTEDUNITS}
  16. interface
  17. function VFPv4Support : Boolean;
  18. implementation
  19. var
  20. has_vfpv4_support,
  21. gothwcaps : boolean;
  22. hwcaps : dword;
  23. const
  24. AT_NULL = 0;
  25. AT_HWCAPS = 16;
  26. type
  27. TAuxiliaryValue = DWord;
  28. TInternalUnion = record
  29. a_val: DWord; //* Integer value */
  30. {* We use to have pointer elements added here. We cannot do that,
  31. though, since it does not work when using 32-bit definitions
  32. on 64-bit platforms and vice versa. *}
  33. end;
  34. Elf32_auxv_t = record
  35. a_type: DWord; //* Entry type */
  36. a_un: TInternalUnion;
  37. end;
  38. TElf32AuxiliaryVector = Elf32_auxv_t;
  39. PElf32AuxiliaryVector = ^TElf32AuxiliaryVector;
  40. var
  41. psysinfo: LongWord = 0;
  42. procedure InitHWCaps;
  43. var
  44. ep: PPAnsiChar;
  45. auxv: PElf32AuxiliaryVector;
  46. begin
  47. psysinfo := 0;
  48. ep := envp;
  49. while ep^ <> nil do
  50. Inc(ep);
  51. Inc(ep);
  52. auxv := PElf32AuxiliaryVector(ep);
  53. while auxv^.a_type <> AT_NULL do
  54. begin
  55. if auxv^.a_type = AT_HWCAPS then
  56. begin
  57. hwcaps := auxv^.a_un.a_val;
  58. gothwcaps := true;
  59. Break;
  60. end;
  61. Inc(auxv);
  62. end;
  63. end;
  64. function VFPv4Support : Boolean;
  65. begin
  66. Result:=has_vfpv4_support;
  67. end;
  68. begin
  69. gothwcaps:=false;
  70. InitHWCaps;
  71. has_vfpv4_support:=gothwcaps and ((hwcaps and (1 shl 16))<>0);
  72. end.