1 1 1 1 1 1 1 1 1 1 Рейтинг 0.00 (0 Голоса(ов)

Получить идентификатор процессора (Delphi)

Код с ассемблерными вставками. Авторство не мое, нашел в интернете. Проверил, код работоспособный.

Код Delphi:
  1. type TCPUInfo = packed record
  2. IDString: array [0..11] of Char;
  3. Stepping: Integer;
  4. Model: Integer;
  5. Family: Integer;
  6. FPU: Boolean;
  7. VirtualModeExtensions: Boolean;
  8. DebuggingExtenslons: Boolean;
  9. PageSizeExtensions: Boolean;
  10. TimeStampCounter: Boolean;
  11. K86ModelSpecificRegisters: Boolean;
  12. MachineCheckExceptlon: Boolean;
  13. CMPXCHG8B: Boolean;
  14. APIC: Boolean;
  15. MemoryTypeRangeRegisters: Boolean;
  16. GlobalPagingExtension: Boolean;
  17. ConditionalMovelnstruction: Boolean;
  18. MMX: Boolean;
  19. SYSCALLandSYSRET, FPConditionalMovelnstruction, AMD3DNow: Boolean;
  20. CPUName: String;
  21. end;
  22. // ...
  23. function TForm1.ExistCPUID: Boolean;
  24. asm
  25. pushfd
  26. pop eax
  27. mov ebx, eax
  28. xor eax, 00200000h
  29. push eax
  30. popfd
  31. pushfd
  32. pop ecx
  33. mov eax, 0
  34. cmp ecx, ebx
  35. jz @NO_CPUID
  36. inc eax
  37. @NO_CPUID:
  38. end;
  39.  
  40. function TForm1.CPUIDInfo(out info: TCPUInfo): boolean;
  41. function ExistExtendedCPUIDFunctions: boolean;
  42. asm
  43. mov eax, 080000000h
  44. db $0F, $A2
  45. end;
  46. var
  47. name: array [0..47] of Char;
  48. p: Pointer;
  49. begin
  50. if ExistCPUID then
  51. asm
  52. jmp @Start
  53. @BitLoop:
  54. mov al, dl
  55. and al, 1
  56. mov [edi], al
  57. shr edx, 1
  58. inc edi
  59. loop @BitLoop
  60. ret
  61. @Start:
  62. mov edi, info
  63. mov eax, 0
  64. db $0F, $A2
  65. mov [edi],ebx
  66. mov [edi + 4], edx
  67. mov [edi + 8], ecx
  68. mov eax, 1
  69. db $0F, $A2
  70. mov ebx, eax
  71. and eax, 0fh;
  72. mov [edi + 12], eax;
  73. shr ebx, 4
  74. mov eax, ebx
  75. and eax, 0fh
  76. mov [edi + 12 + 4], eax
  77. shr ebx, 4
  78. mov eax, ebx
  79. and eax, 0fh
  80. mov [edi + 12 +8 ], eax
  81. add edi, 24
  82. mov ecx, 6
  83. call @BitLoop
  84. shr edx, 1
  85. mov ecx, 3
  86. call @BitLoop
  87. shr edx, 2
  88. mov ecx, 2
  89. call @BitLoop
  90. shr edx, 1
  91. mov ecx, 1
  92. call @BitLoop
  93. shr edx, 7
  94. mov ecx, 1
  95. call @BitLoop
  96. mov p, edi
  97. end;
  98. if (info.IDString = 'AuthenticAMD') and ExistExtendedCPUIDFunctions then
  99. begin asm
  100. mov edi, p
  101. mov eax, 080000001h
  102. db $0F, $A2
  103. mov eax, edx
  104. shr eax, 11
  105. and al, 1
  106. mov [edi], al
  107. mov eax, edx
  108. shr eax, 16
  109. and al, 1
  110. mov [edi + 1], al
  111. mov eax, edx
  112. shr eax, 31
  113. and al, 1
  114. mov [edi + 2], al
  115. lea edi, name
  116. mov eax, 0
  117. mov [edi], eax
  118. mov eax, 080000000h
  119. db $0F, $A2
  120. cmp eax, 080000004h
  121. jl @NoString
  122. mov eax, 080000002h
  123. db $0F, $A2
  124. mov [edi], eax
  125. mov [edi + 4], ebx
  126. mov [edi +8], ecx
  127. mov [edi + 12], edx
  128. add edi, 16
  129. mov eax, 080000003h
  130. db $0F, $A2
  131. mov [edi] , eax
  132. mov [edi + 4], ebx
  133. mov [edi + 8], ecx
  134. mov [edi + 12], edx
  135. add edi, 16
  136. mov eax, 080000004h
  137. db $0F, $A2
  138. mov [edi] , eax
  139. mov [edi + 4], ebx
  140. mov [edi + 8], ecx
  141. mov [edi + 12], edx
  142. @NoString:
  143. end;
  144. info.CPUName := name;
  145. end
  146. else
  147. with info do
  148. begin
  149. SYSCALLandSYSRET := False;
  150. FPConditionalMovelnstruction := False;
  151. AMD3DNow := False;
  152. CPUName := '';
  153. end;
  154. Result := ExistCPUID;
  155. end;
  156.  
  157. function TForm1.ExistMMX: Boolean;
  158. var info: TCPUInfo;
  159. begin
  160. if CPUIDInfo(info) then Result := info.MMX
  161. else Result := False;
  162. end;
  163.  
  164. function TForm1.Exist3DNow: Boolean;
  165. var info: TCPUInfo;
  166. begin
  167. if CPUIDInfo(info) then Result := info.AMD3DNow
  168. else Result := False;
  169. end;
  170.  
  171. function TForm1.ExistKNI: Boolean;
  172. begin
  173. Result := False;
  174. end;
  175.  
  176. procedure TForm1.EMMS;
  177. asm
  178. db $0F, $77
  179. end;
  180.  
  181. procedure TForm1.FEMMS;
  182. asm
  183. db $0F, $03
  184. end;
  185.  
  186. procedure TForm1.PREFETCH(p: Pointer); register;
  187. asm
  188. PREFETCH byte ptr [eax]
  189. end;

Оставьте свой комментарий

Оставить комментарий как гость

0
  • Комментариев нет
Taobao RU