# Parsing Bit flag data from Intel CPU MSR registers.

**URL:** <https://forums.powershell.org/t/parsing-bit-flag-data-from-intel-cpu-msr-registers/13161>\
**Category:** PowerShell Help\
**Created:** [September 19, 2019, 12:22am UTC](https://forums.powershell.org/t/parsing-bit-flag-data-from-intel-cpu-msr-registers/13161 "2019-09-19T00:22:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![naimc](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@naimc](https://forums.powershell.org/u/naimc)\
**Post date:** [September 19, 2019, 12:22am UTC](https://forums.powershell.org/t/parsing-bit-flag-data-from-intel-cpu-msr-registers/13161/1 "2019-09-19T00:22:43Z")

</div>

I am troubleshooting CPU prochot issues and using powershell to gather data when throttling occurs, using the Intel PCM tool, pcm-msr.exe to read specific registers such as : IA32\_THERM\_STATUS. 0x19c

sample command :  
psm-msc.exe 0x19c  
Read value 0x883d2800 from MSR 0x19c on core 0

I then have to look up the hex value 0x883d2800 in the bit field table listed here [https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-3b-part-2-manual.pdf](https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-vol-3b-part-2-manual.pdf) page 14.10 Vol 3B.

 ![IA32_THERM_STATUS](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/7/7a263c39ffbd3888fd83836bb8b1a9c454c6f964.jpeg)

Never having done anything like this I search for “Powershell bit field” and found one example that uses flags

Based on the example this example : [Managing Bit Flags (Part 1) - Power Tips - Power Tips - IDERA Community](https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/managing-bit-flags-part-1)

I created the following :

[Flags()]  
enum IA32\_THERM\_STATUS  
{  
Reading\_Valid = 2147483648  
Resolution\_in\_Deg\_Celsius = 2013265920  
Digital\_Readout = 4161536  
Cross\_domain\_Limit\_Log = 16384  
Cross\_domain\_Limit\_Status= 8192  
Current\_Limit\_Log = 4096  
Current\_Limit\_Status = 2048  
Power\_Limit\_Notification\_Log = 1024  
Power\_Limit\_Notification\_Status = 512  
Thermal\_Threshold\_2\_Log = 265  
Thermal\_Threshold\_2\_Status = 128  
Thermal\_Threshold\_1\_Log = 64  
Thermal\_Threshold\_1\_Status = 32  
Critical\_Temperature\_Log = 16  
Critical\_Temperature\_Status = 8  
PROCHOT\_or\_FORCEPR\_Log = 4  
PROCHOT\_or\_FORCEPR\_Event = 2  
Thermal\_Status\_Log = 1  
Thermal\_Status = 0  
}

$MSRHex = ((cmd /c C:\ProgramData\Util\PCM\pcm-msr.exe 0x19c 2\>1 $null ) -match “Read Value”).split(" “)[3]  
$MSRDec = [Convert]::ToInt64(”$MSRHex", 16)

[IA32\_THERM\_STATUS]$flags = $MSRDec  
$flags

1St problem I have is I don’t know how to define the Resolution\_in\_Deg\_Celsius and Digital\_readout , values as they cover multiple positions here is how I arrived a the values : I’m not good in math but based on the example I found I have get the number for column B and for the items that span multiple rows I add the row and take the total.

 ![bit table](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/b1520e4bbf447be8f1ae271bc9ef8fcb29da5e25.jpeg)

to run my code, you can set the $MSRHex = 0x883d2800 and see if that converts.

I get errors. Not surprising as some of the value are simple flags but digital Readout and Resolution are going to values I want to capture and convert back to dec temp readings. No clue on how I should do this ?

---

<div class="post-metadata">

**Author:** ![naimc](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@naimc](https://forums.powershell.org/u/naimc)\
**Post date:** [September 24, 2019, 1:46pm UTC](https://forums.powershell.org/t/parsing-bit-flag-data-from-intel-cpu-msr-registers/13161/2 "2019-09-24T13:46:01Z")

</div>

Testing, I have tried to update this thread 15 times in the last two days, trying a simple post. All updated never make it.

---

<div class="post-metadata">

**Author:** ![naimc](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@naimc](https://forums.powershell.org/u/naimc)\
**Post date:** [September 24, 2019, 2:22pm UTC](https://forums.powershell.org/t/parsing-bit-flag-data-from-intel-cpu-msr-registers/13161/3 "2019-09-24T14:22:08Z")

</div>

I finally was able to progress after a colleague from work wrote some C# code that was able to load in powershell, after fiddling around I was able to a pure powershell verison.

here is an example :  
step 1 build an enum C# style, that a 100% copy past from the C# code. 1st issue I had the original code was defining General\_Flag\_IA32\_therm\_status as UInt64, powershell would not accept this value I has to change to a ulong, But this means that I could not create bitmask for more than 32 bits, yet some of the intel MSR can use up to 64 bits ?

`Add-Type -TypeDefinition @“`  
`[System.Flags]`  
`public enum General_Flag_IA32_THERM_STATUS : ulong`  
`{`  
`THERMAL_STATUS = 1,`  
`THERMAL_STATUS_LOG = 1 << 1,`  
`PROCHOT_OR_FORCEPR_EVENT = 1 << 2,`  
`PROCHOT_OR_FORCEPR_LOG = 1 << 3,`  
`CRITICAL_TEMPERATURE_STATUS = 1 << 4,`  
`CRITICAL_TEMPERATURE_LOG = 1 << 5,`  
`THERMAL_THRESHOLD_1_STATUS = 1 << 6,`  
`THERMAL_THRESHOLD_1_LOG = 1 << 7,`  
`THERMAL_THRESHOLD_2_STATUS = 1 << 8,`  
`THERMAL_THRESHOLD_2_LOG = 1 << 9,`  
`POWER_LIMIT_NOTIFICATION_STATUS = 1 << 10,`  
`POWER_LIMIT_NOTIFICATION_LOG = 1 << 11,`  
`CURRENT_LIMIT_STATUS = 1 << 12,`  
`CURRENT_LIMIT_LOG = 1 << 13,`  
`CROSS_DOMAIN_LIMIT_STATUS = 1 << 14,`  
`CROSS_DOMAIN_LIMIT_LOG = 1 << 15,`  
`READING_VALID = 1ul << 31`  
`}`  
`”@`

Next : this line runs the intel PCM tool pcm-msr.exe reads MSR value for IA32\_THERM\_STATUS = 0x19c There is bunch of output in this line I just capture the hex value as a string.`$MSRstring0x19c = ((cmd /c C:\ProgramData\PCM\pcm-msr.exe 0x19c 2>1 $null ) -match “Read Value”).split(" ")[3]`

Next that string $MSRstring0x19c is still a string so

`[uint32]$MSRstring`

makes it a Uint32

My biggest headache, how do I use this enum object ?

`foreach ($i in [Enum]::GetValues(‘General_Flag_IA32_THERM_STATUS’)) {`  
`if ([uint32]$MSRstring0x19c -band $i.value__ ) {write-host “$i : 1”} else {write-host "$i : 0 "}`  
`}`

Ok took me a while to get this, we loop through the enum table, asking if on every line the bit-value is present in the number we are checking.

So when I supply hex value : 0x882d2000 the loop shows me which bits are present :

`THERMAL_STATUS : 0 `  
`THERMAL_STATUS_LOG : 0 `  
`PROCHOT_OR_FORCEPR_EVENT : 0 `  
`PROCHOT_OR_FORCEPR_LOG : 0 `  
`CRITICAL_TEMPERATURE_STATUS : 0 `  
`CRITICAL_TEMPERATURE_LOG : 0 `  
`THERMAL_THRESHOLD_1_STATUS : 0 `  
`THERMAL_THRESHOLD_1_LOG : 0 `  
`THERMAL_THRESHOLD_2_STATUS : 0 `  
`THERMAL_THRESHOLD_2_LOG : 0 `  
`POWER_LIMIT_NOTIFICATION_STATUS : 0 `  
`POWER_LIMIT_NOTIFICATION_LOG : 0 `  
`CURRENT_LIMIT_STATUS : 0 `  
`CURRENT_LIMIT_LOG : 1`  
`CROSS_DOMAIN_LIMIT_STATUS : 0 `  
`CROSS_DOMAIN_LIMIT_LOG : 0 `  
`READING_VALID : 1`

The only thing left to do is extract the temp fields out of the IA32\_THERM\_STATUS.

they are at positions 22:16 (Digital Readout ) and 30:27 (Resolution in Dgrees cel.).

extract the hex values, convert to a temperature reading, and display. No idea on how do this this part.

---

<div class="post-metadata">

**Author:** ![naimc](https://avatars.discourse-cdn.com/v4/letter/n/8e8cbc/32.png) [@naimc](https://forums.powershell.org/u/naimc)\
**Post date:** [September 24, 2019, 11:37pm UTC](https://forums.powershell.org/t/parsing-bit-flag-data-from-intel-cpu-msr-registers/13161/4 "2019-09-24T23:37:27Z")

</div>

Wow interested in Intel MSR CPU registers, this person built a very cool utility for Linux. wish this could ported to Powershell

[https://github.com/kzawad1/intel-reg-pp](https://github.com/kzawad1/intel-reg-pp)

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [September 25, 2019, 12:37am UTC](https://forums.powershell.org/t/parsing-bit-flag-data-from-intel-cpu-msr-registers/13161/5 "2019-09-25T00:37:21Z")

</div>

Really sorry for the post being hidden. Those were considered as spam, probably because of the way how the code was formatted. The best way to format code in the forums is mentioned in below post

[https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did/](https://powershell.org/forums/topic/read-me-before-posting-youll-be-glad-you-did/)

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:31pm UTC](https://forums.powershell.org/t/parsing-bit-flag-data-from-intel-cpu-msr-registers/13161/6 "2024-05-16T20:31:18Z")

</div>

Closed on May 16, 2024, 8:31pm UTC


