Author Topic: Instruction Set detection for 32 bit Operating Systems  (Read 45976 times)

Gunther

  • Member
  • *****
  • Posts: 3693
  • Forgive your enemies, but never forget their names
Instruction Set detection for 32 bit Operating Systems
« on: February 03, 2013, 08:24:36 AM »
I've attached the file instrset32.zip. It contains the sources and running applications for 32 bit Windows and Linux. An appropriate test program is included, too. The procedure detrects the instruction sets up to AVX2 properly. You may check the following threads, too: http://masm32.com/board/index.php?topic=1380.0 and http://masm32.com/board/index.php?topic=1405.0.

The assembly language part is written for jWasm, but it should work for masm, too. The C-source is compiled with gcc, but it should work with any other C compiler. Here is the output under Windows XP, SP3 as VM (Windows XP Mode).
Code: [Select]
Supported by Processor and installed Operating System:
------------------------------------------------------

     MMX, CMOV and FCOMI, SSE, SSE2, SSE3, SSSE3, SSE4.1,
     POPCNT, SSE4.2

     featurenumber = 13
XP doesn't support AVX; I'm not sure about the behaviour under Windows 7 (32 bit). Could anyone test that, please?

The 16 bit version is much more tricky and will be published probably as stand alone assembly language application inside the 16 bit forum.

Gunther
« Last Edit: May 03, 2014, 03:03:28 AM by Gunther »
Get your facts first, and then you can distort them.

Magnum

  • Member
  • *****
  • Posts: 2362
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #1 on: February 03, 2013, 08:33:36 AM »
Output when run on Win 7 Pro 32 bit version

Supported by Processor and installed Operating System:
------------------------------------------------------

     MMX, CMOV and FCOMI, SSE, SSE2, SSE3, SSSE3

     featurenumber = 10
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #2 on: February 03, 2013, 08:39:55 AM »
P4 prescott w/htt
Code: [Select]
     MMX, CMOV and FCOMI, SSE, SSE2, SSE3

     featurenumber = 9
it looks correct, although i don't know how to interpret the featurenumber

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 8123
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #3 on: February 03, 2013, 10:29:02 AM »
Hi Gunther,

Works fine on my dev Core2 Quad.


Supported by Processor and installed Operating System:
------------------------------------------------------

     MMX, CMOV and FCOMI, SSE, SSE2, SSE3, SSSE3, SSE4.1

     featurenumber = 11
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Gunther

  • Member
  • *****
  • Posts: 3693
  • Forgive your enemies, but never forget their names
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #4 on: February 03, 2013, 10:40:39 AM »
Thank you Steve and Andy for testing. Dave, the featurenumber is only for information. Please have a look into the C-source cpufeatures.c; that should give you enough explanation (a simple select case statement).

Gunther
Get your facts first, and then you can distort them.

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #5 on: February 03, 2013, 10:55:56 AM »
good work   :t

it's nice to know how to test for AVX when i don't have a machine to test it   :biggrin:

Magnum

  • Member
  • *****
  • Posts: 2362
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #6 on: February 03, 2013, 12:09:07 PM »
Thank you Steve and Andy for testing.

Gunther

Glad to help. I like your thorough notes about what each step does.

Have you thought about seeing if Microsoft would buy a license for it ?  :t

They really need help with identifying important things, o.s.'s in particular.  :biggrin:

Andy



Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #7 on: February 03, 2013, 12:54:00 PM »
identifying the os version is WAY easier than identifying the CPU   :P

http://www.masmforum.com/board/index.php?topic=11963.0

i can upload the attachment if you like

these registry values....

Code: [Select]
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion]
"Version"="Windows 95"
"VersionNumber"="4.00.1111"
"ProductName"="Microsoft Windows 95"
"CurrentVersion"=(Value not found)
"CurrentBuildNumber"=(Value not found)
"SubVersionNumber"=" B"
"CSDVersion"=(Value not found)
"BuildLab"=(Value not found)
"ProductId"="24264-XXX-XXXXXXX-XXXXX"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Media Center]
"Ident"=(Key not found)

OSVERSIONINFOEX Structure:

       Version.Build: 4.0.67109975
         Platform ID: Win32 on Windows 95
         CSD Version:  B

and the stuff at the end is from GetVersionEx

frktons

  • Member
  • ***
  • Posts: 491
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #8 on: February 03, 2013, 06:37:13 PM »
Quote
Supported by Processor and installed Operating System:
------------------------------------------------------

     MMX, CMOV and FCOMI, SSE, SSE2, SSE3, SSSE3

     featurenumber = 10

Windows 7/64 bit ultimate - Core Duo INTEL

Gunther

  • Member
  • *****
  • Posts: 3693
  • Forgive your enemies, but never forget their names
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #9 on: February 03, 2013, 09:42:09 PM »
Hi Dave,

identifying the os version is WAY easier than identifying the CPU   :P

http://www.masmforum.com/board/index.php?topic=11963.0

i can upload the attachment if you like

why not. But it's not the question of detecting the underlying operating system. We have to check if the operating system is at least SSE aware, because the xmm registers must be saved during task switches. Unfortunately, the information that can be obtained from the CPUID instruction is not sufficient for determining whether it is possible to use XMM registers. The CPU can disable the use of the XMM registers in order to prevent their use under old operating systems that do not save these registers. Operating systems that support the use of XMM registers must set bit 9 of the control register CR4 to enable the use of XMM registers and indicate its ability to save and restore these registers during task switches.

Unfortunately, the CR4 register can only be read in privileged mode. Application programs therefore have a serious problem determining whether they are allowed to use the XMM registers or not. According to official Intel documents, the only way for an application program to determine whether the operating system supports the use of XMM registers is to try to execute an XMM instruction and see if you get an invalid opcode exception. But not all operating systems, compilers and programming languages provide facilities for application programs to catch invalid opcode exceptions. A Windows application, for example, using Intel’s detection method would therefore have to be tested in all compatible operating systems, including various Windows emulators running under a number of other operating systems.

The demonstrated detection method in the procedure doesn't have this drawback. That is the point.

Gunther
Get your facts first, and then you can distort them.

Gunther

  • Member
  • *****
  • Posts: 3693
  • Forgive your enemies, but never forget their names
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #10 on: February 03, 2013, 09:45:17 PM »
Hi Andy,

Have you thought about seeing if Microsoft would buy a license for it ?  :t

no, not really. But we should help other code writers which are relatively new to assembly language. Therefore the comments and remarks.

Gunther
Get your facts first, and then you can distort them.

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #11 on: February 03, 2013, 10:57:31 PM »
Quote
Unfortunately, the CR4 register can only be read in privileged mode. Application programs therefore have a serious problem determining whether they are allowed to use the XMM registers or not. According to official Intel documents, the only way for an application program to determine whether the operating system supports the use of XMM registers is to try to execute an XMM instruction and see if you get an invalid opcode exception. But not all operating systems, compilers and programming languages provide facilities for application programs to catch invalid opcode exceptions. A Windows application, for example, using Intel’s detection method would therefore have to be tested in all compatible operating systems, including various Windows emulators running under a number of other operating systems.

The demonstrated detection method in the procedure doesn't have this drawback. That is the point.

i see - very interesting   :t

however, i think if you tested XP, Vista, Windows 7, you'd have enough info to determine support level

Gunther

  • Member
  • *****
  • Posts: 3693
  • Forgive your enemies, but never forget their names
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #12 on: February 03, 2013, 11:23:56 PM »
Hi Dave,

i see - very interesting   :t

however, i think if you tested XP, Vista, Windows 7, you'd have enough info to determine support level

that might be. I'll tell you the following story. My son (20 years old) has a Linux (64 bit) installed and he experimented with Wine (the Windows emulator). He needs a special Wine version for some older software to run. What about that? That's the next serious problem.

Gunther
Get your facts first, and then you can distort them.

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #13 on: February 03, 2013, 11:26:27 PM »
well - that could be a number of things

but - i hadn't considered os's other than windows, really
at my age, i have more than i can handle learning xp, vista, and win7 - lol

Magnum

  • Member
  • *****
  • Posts: 2362
Re: Instruction Set detection for 32 bit Operating Systems
« Reply #14 on: February 04, 2013, 12:55:46 AM »
Hi Andy,

Have you thought about seeing if Microsoft would buy a license for it ?  :t

no, not really. But we should help other code writers which are relatively new to assembly language. Therefore the comments and remarks.

Gunther

The comment was meant as humor.

I should have labeled the comment at the end.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org