flat assembler
Message board for the users of flat assembler.
Index
> Windows > IsProcessorFeaturePresent or CPUID? Goto page 1, 2 Next |
Author |
|
Mat Quasar 26 Dec 2024, 08:23
Hi, since I am learning Windows GUI programming, I want to do a Windows dialog that shows basic CPU info, including like presence of AVX, SSE....
But I found IsProcessorFeaturePresent Win32 API. Should I use CPUID to detect or that API function? (https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-isprocessorfeaturepresent) According to my understanding, even if CPUID detect presence of a processor feature, it might not be supported by the OS, so I am thinking IsProcessorFeaturePresent can detect support of processor feature by both CPU and Windows. Any advice?
Last edited by Mat Quasar on 29 Dec 2024, 10:39; edited 3 times in total |
|||||||||||
26 Dec 2024, 08:23 |
|
Mat Quasar 26 Dec 2024, 10:27
macomics wrote: IsProcessorFeaturePresent this function is just an analog of the CPUID instruction for high level languages. Thanks. I think I will use this API function, much easier. Maybe I will trace the API code after I start doing it. |
|||
26 Dec 2024, 10:27 |
|
Core i7 26 Dec 2024, 10:46
Mat Quasar wrote: Thanks. I think I will use this API function, much easier. Code: 0:000> uf IsProcessorFeaturePresent kernel32!IsProcessorFeaturePresent: 00000000`77bbcb30 83f903 cmp ecx,3 00000000`77bbcb33 7414 je kernel32!IsProcessorFeaturePresent+0x19 (00000000`77bbcb49) kernel32!IsProcessorFeaturePresent+0x5: 00000000`77bbcb35 83f907 cmp ecx,7 00000000`77bbcb38 740f je kernel32!IsProcessorFeaturePresent+0x19 (00000000`77bbcb49) kernel32!IsProcessorFeaturePresent+0xa: 00000000`77bbcb3a 83f940 cmp ecx,40h 00000000`77bbcb3d 730a jae kernel32!IsProcessorFeaturePresent+0x19 (00000000`77bbcb49) kernel32!IsProcessorFeaturePresent+0xf: 00000000`77bbcb3f 8bc1 mov eax,ecx 00000000`77bbcb41 0fb6807402fe7f movzx eax,byte ptr SharedUserData+0x274 (00000000`7ffe0274)[rax] 00000000`77bbcb48 c3 ret kernel32!IsProcessorFeaturePresent+0x19: 00000000`77bbcb49 33c0 xor eax,eax 00000000`77bbcb4b c3 ret |
|||
26 Dec 2024, 10:46 |
|
Core i7 26 Dec 2024, 11:44
The IsProcessorFeaturePresent() function is not suitable for collecting information about the processor, because it returns one thing that you specify as a parameter in the RCX register (x64 system). That is, to check all the capabilities of the CPU, you will need to call it 32 times, and each time it will read 1 byte from the KUSER_SHARED_DATA structure. Therefore, it is better to use the CPUID instruction, which returns a 32-bit mask with all the characteristics at once - you just have to move the bits through shr, checking them for 1.
|
||||||||||||||||||||
26 Dec 2024, 11:44 |
|
Mat Quasar 26 Dec 2024, 12:44
Core i7 wrote: ...That is, to check all the capabilities of the CPU, you will need to call it 32 times, and each time it will read 1 byte from the KUSER_SHARED_DATA structure. Therefore, it is better to use the CPUID instruction, which returns a 32-bit mask with all the characteristics at once. You have a valid point here. I will use CPUID then. And how lovely you are, you gave me the CPUID manual for both Intel and AMD! Thank you so much. I checked, 32-bit mask that you mentioned is in Table 5.5 (Intel manual). EDIT: Oops, maybe 2 x 32-bit masks, in Table 5.5 and Table 5.6. |
|||
26 Dec 2024, 12:44 |
|
Core i7 26 Dec 2024, 13:02
Mat Quasar wrote: EDIT: Oops, maybe 2 x 32-bit masks, in Table 5.5 and Table 5.6. Yes, that's right. I once wrote a similar program with a call CPUID, only I displayed the result on the console. You can see an example here: https://codeby.net/threads/cpuid-identifikacija-processora.78279/ |
|||
26 Dec 2024, 13:02 |
|
Mat Quasar 26 Dec 2024, 13:25
Core i7 wrote:
Nice! Can I use your code for the following functions? Quote:
I can do myself for the rest. It is best if you have code for calculating TSC frequency. My translation reads: Quote: The experiments above showed that CPUID is initially unable to return some information. For example, it does not contain data such as: core code name, operating voltage threshold, socket type, power consumption, and manufacturing process technology value. Apparently, software like CPU-Z stores all this in its tables, which programmers meticulously collect manually. Databases of this kind are written based on the "Family/Model/Stepping" values provided to us by the functionCPUID.EAX=1. So CPU-Z keeps a comprehensive database based on results returned by EAX register for EAX=1 CPUID instruction. ADD: Your CPUID example hangs on my AMD PC maybe because your program is targeted for Intel only. I read this paragraph just now: Quote: Moreover, the presented table is valid only for Intel processors, since AMD has a completely different numbering of functions.
|
||||||||||
26 Dec 2024, 13:25 |
|
Mat Quasar 26 Dec 2024, 13:53
Looks like https://codeby.net/ (InfoSec) is a very technical forum for Russians.
I like to see the atmosphere there. In comparision, my country's coding forum is less technical.
|
||||||||||
26 Dec 2024, 13:53 |
|
Core i7 26 Dec 2024, 15:02
Mat Quasar wrote: Can I use your code for the following functions? No problem! since there is nothing secret and everything is elementary. Yes, it freezes because the code is for Intel processors. To calculate the TSC value, you need to measure the clocks for 1 second, like this: Code: mov ecx,2 ; cycle @@: push rcx xor eax,eax cpuid ; clear cpu pipeline rdtsc push rax invoke Sleep,1000 ; wait 1-sec.. rdtsc pop rbx sub rax,rbx ; difference pop rcx dec rcx jnz @b ; RAX = tsc value |
|||
26 Dec 2024, 15:02 |
|
Mat Quasar 26 Dec 2024, 15:17
Thank you for your permission.
About the code to get TSC value, it is different from the CPUID table that I saw. I will confirm after I start doing it. |
|||
26 Dec 2024, 15:17 |
|
Core i7 26 Dec 2024, 15:17
Mat Quasar wrote: So CPU-Z keeps a comprehensive database based on results returned by EAX register for EAX=1 CPUID instruction. Аn example of searching for a kernel code name is here, but also for Intel processors: https://codeby.net/threads/sistemnye-tajmery-chast-6-osnovy-profilirovanija-koda.74153/ |
|||
26 Dec 2024, 15:17 |
|
Core i7 26 Dec 2024, 15:43
If you want to write a universal identification code for Intel/AMD processors, you will need to create 2 separate CPUID procedures. Then at the entrance you will need to find out the manufacturer on the current machine. Previously, there was such a method for detecting the vendor Intel/AMD - I wonder if it works on new processors now, or AMD corrected the error based on the ZF flag?
Code: format pe console include 'win32ax.inc' entry start ;//----------- .data intel db 10,' Intel',0 amd db 10,' AMD',0 ;//----------- .code start: xor edx,edx mov eax,5 mov ebx,2 div ebx mov eax,intel jz @prn mov eax,amd @prn: cinvoke printf,eax @exit: cinvoke _getch cinvoke exit, 0 ;//----------- section '.idata' import data readable library msvcrt,'msvcrt.dll' import msvcrt,printf,'printf',exit,'exit',_getch,'_getch' |
|||
26 Dec 2024, 15:43 |
|
bitRAKE 26 Dec 2024, 17:08
Mat Quasar wrote: According to my understanding, even if CPUID detect presence of a processor feature, it might not be supported by the OS, so I am thinking IsProcessorFeaturePresent can detect support of processor feature by both CPU and Windows. There are features like fastfail that have nothing to do with CPUID: Code: calminstruction __fastfail value* ; program state unknown, end process, does not return asm mov ecx,value asm int 0x29 end calminstruction _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
26 Dec 2024, 17:08 |
|
Mat Quasar 27 Dec 2024, 05:14
Very informative, bitRAKE.
|
|||
27 Dec 2024, 05:14 |
|
Mat Quasar 27 Dec 2024, 06:04
After taking into recommendation by you guys, I plan to do both CPUID instruction and IsProcessorFeaturePresent function.
(As seen in screenshot below) The KUSER_SHARED_DATA address maybe can get from TEB or PEB? I haven't fully read it. Nice to know.
|
||||||||||
27 Dec 2024, 06:04 |
|
Mat Quasar 27 Dec 2024, 06:08
Core i7 wrote: Previously, there was such a method for detecting the vendor Intel/AMD - I wonder if it works on new processors now, or AMD corrected the error based on the ZF flag? I don't know how reliable it is, but can't we get CPU brand string from EAX = 0 CPUID instruction? AuthenticAMD" or "GenuineIntel". But it is good to know we need two different procedures for each AMD and Intel. |
|||
27 Dec 2024, 06:08 |
|
macomics 27 Dec 2024, 06:27
Mat Quasar wrote: I don't know how reliable it is, but can't we get CPU brand string from EAX = 0 CPUID instruction? |
|||
27 Dec 2024, 06:27 |
|
Core i7 27 Dec 2024, 06:46
Mat Quasar wrote: The KUSER_SHARED_DATA address maybe can get from TEB or PEB? This address is the same for x64/32 and is equal to 0x7FFE0000 |
|||
27 Dec 2024, 06:46 |
|
Core i7 27 Dec 2024, 07:13
In the x64dbg debugger, you can view structures.
To do this, you need to create a *.txt script file, and select the structure name from it, specify the address. Here is my script, and the sequence of actions with the right mouse button. This way you can output many structures in a convenient form, including PEB/TEB and many others:
|
||||||||||||||||||||
27 Dec 2024, 07:13 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.