首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PowerShell数据类型和哈希表MCA_Decode

PowerShell数据类型和哈希表MCA_Decode
EN

Stack Overflow用户
提问于 2016-06-13 21:11:38
回答 2查看 95关注 0票数 0

这是我第一次尝试用任何语言编写脚本。我知道我想做什么,但需要一些帮助才能找到我想要的。这是我自己学习和娱乐的一个附带项目:)

  1. 接受一个参数(两个字节十六进制,或二进制)
  2. 与错误掩码比较
  3. 书面-主机和解释

目前,数据类型可能都是字符串。我需要这些做int吗?int32int64

错误掩码被简单地分配给变量。

代码语言:javascript
复制
$IO_Error = 0000111000001011

将这些数据作为"Hashtable“存储会更有效吗?

代码语言:javascript
复制
$ErrorList = @{IO_Error, 0000111000001011; so, on; so, on;}

那么能不能预先检查一下是否匹配?

对于简单的错误来说,这很好,但是,进入复合错误代码和掩码,我需要能够引用和检查某些偏移量,以确定设置了哪些位以确保解码的准确性。

代码语言:javascript
复制
<#
# =====================
#  Simple Error Codes                        # Table 15-8. IA32_MCi_Status [15:0] Simple Error Code Encoding
# =====================                      # 64-ia-32-architectures-software-developer-manual-325462. Volume 3B 
#  
#
#          Error Desc                  Error Mask          Error Code Binary Encoding Meaning
# No Error                          0000 0000 0000 0000 No error has been reported to this bank of error-reporting registers.
# Unclassified                      0000 0000 0000 0001 This error has not been classified into the MCA error classes.
# Microcode ROM Parity Error        0000 0000 0000 0010 Parity error in internal microcode ROM
# External Error                    0000 0000 0000 0011 The BINIT# from another processor caused this processor to enter machine check.*1
# FRC Error                         0000 0000 0000 0100 FRC (functional redundancy check) master/slave error
# Internal Parity Error             0000 0000 0000 0101 Internal parity error.
# SMM Handler Code Access Violation 0000 0000 0000 0110 An attempt was made by the SMM Handler to execute outside the ranges specified by SMRR.
# Internal Timer Error              0000 0100 0000 0000 Internal timer error.
# I/O Error                         0000 1110 0000 1011 generic I/O error.
# Internal Unclassified             0000 01xx xxxx xxxx Internal unclassified errors. *2
#
#
# =====================
# Compound Error Codes                       # Table 15-9 IA32_MCi_Status [15:0] Compound Error Code Encounding
# =====================                      # 64-ia-32-architectures-software-developer-manual-325462. Volume 3B 
#
#
#         Error Desc                  Error Mask          Error Code Binary Encoding Meaning
# Generic Cache Hierarchy          000F 0000 0000 11LL Generic cache hierarchy error
# TLB Errors                       000F 0000 0001 TTLL {TT}TLB{LL}_ERR
# Memory Controller Errors         000F 0000 1MMM CCCC {MMM}_CHANNEL{CCCC}_ERR
# Cache Hierarchy Errors           000F 0001 RRRR TTLL {TT}CACHE{LL}_{RRRR}_ERR
# Bus and Interconnect Errors      000F 1PPT RRRR IILL BUS{LL}_{PP}_{RRRR}_{II}_{T}_ERR
#
#----------------------------------------------------------------------------------------------------------------------------------------------
#>
Function MCA_Decode
{
$No_Error = 0000000000000000
$Unclassified = 0000000000000001
$Microcode_ROM_Parity_Error = 0000000000000010
$External_Error = 0000000000000011
$FRC_Error = 0000000000000100
$Internal_Parity_Error = 0000000000000101
$SMM_Handler_Code_Access_Violation = 0000000000000110
$Internal_Timer_Error = 0000010000000000
$IO_Error = 0000111000001011
#$Internal_Unclassified = 000001xx xxxx xxxx
#
#
$input = $args[0]
if($input -eq $No_Error){
Write-Host "Error Type: No Error`nError Desc: No error has been reported to this bank of error-reporting registers." -ForegroundColor Green
}
if($input -eq $Unclassified){
Write-Host "Error Type: Unclassified`nError Desc: This error has not been classified into the MCA error classes." -ForegroundColor Green
}
if($input -eq $Microcode_ROM_Parity_Error){
Write-Host "Error Type: Microcode ROM Parity Error`nError Desc: Parity error in internal microcode ROM" -ForegroundColor Green
}
if($input -eq $External_Error){
Write-Host "Error Type: External Error`nError Desc: The BINIT# from another processor caused this processor to enter machine check." -ForegroundColor Green
}
if($input -eq $FRC_Error){
Write-Host "Error Type: FRC Error`nError Desc: FRC (functional redundancy check) master/slave error" -ForegroundColor Green
}
if($input -eq $Internal_Parity_Error){
Write-Host "Error Type: Internal Parity Error`nError Desc: Internal parity error." -ForegroundColor Green
}
if($input -eq $SMM_Handler_Code_Access_Violation){
Write-Host "Error Type: SMM Handler Code Access Violation`nError Desc: An attempt was made by the SMM Handler to execute outside the ranges specified by SMRR." -ForegroundColor Green
}
if($input -eq $Internal_Timer_Error){
Write-Host "Error Type: Internal Timer Error`Error Desc: Internal timer error." -ForegroundColor Green
}
if($input -eq $IO_Error){
Write-Host "Error Type: I/O Error`Error Desc: generic I/O error." -ForegroundColor Green
}
}
MCA_Decode $args[0]
EN

回答 2

Stack Overflow用户

发布于 2016-06-13 22:38:16

哈希表肯定可以帮助您解决单个错误。

请允许我建议用十六进制定义您的错误代码值,PowerShell对其进行本地解析,这样就更容易阅读了。

此外,如果您计划引入复合错误,请确保每个位代表一个不同的原始错误。

你可以这样做:

代码语言:javascript
复制
function Get-ErrorDescription {
    param(
        [int]$ErrorCode,
        [switch]$All
    )

    $ErrorCodes = @{
        0x0000 = 'No_Error'
        0x0001 = 'Unclassified'
        0x0002 = 'Microcode_ROM_Parity_Error'
        0x0004 = 'External_Error'
        0x0008 = 'FRC_Error'
        0x0010 = 'Internal_Parity_Error'
        0x0020 = 'SMM_Handler_Code_Access_Violation'
        0x0040 = 'Internal_Timer_Error'
        0x0080 = 'IO_Error'
        0x0100 = 'IRQ_Error'
        0x0062 = 'Compound_Error'
    }

    if(-not $All -or $ErrorCode -eq 0){
        # default, return just the exact error
        return $ErrorCodes[$ErrorCode]
    }

    # Sort keys, filter out No_Error and test the $ErrorCode against each errorcode value with binary AND, output the error description
    return $ErrorCodes.Keys |Sort-Object |Where-Object {$_ -ne 0 -and (($ErrorCode -band $_) -eq $_)}|ForEach-Object { $ErrorCodes[$_] }
}

现在您可以按值解析错误:

代码语言:javascript
复制
PS C:\> Get-ErrorDescription 0x0000
No_Error
PS C:\> Get-ErrorDescription 0x0001
Unclassified
PS C:\> Get-ErrorDescription 0x0062
Compound_Error
PS C:\> Get-ErrorDescription 0x0062
Microcode_ROM_Parity_Error
SMM_Handler_Code_Access_Violation
Internal_Timer_Error
Compound_Error
PS C:\> Get-ErrorDescription 0x0013
Unclassified
Microcode_ROM_Parity_Error
Internal_Parity_Error
票数 0
EN

Stack Overflow用户

发布于 2016-06-19 02:36:01

谢谢你的帮助。我能够利用这个https://technet.microsoft.com/en-us/library/ee692803.aspx的帮助使一切正常工作。

代码语言:javascript
复制
function Get-MCAError{
[CmdletBinding()]
[string]$Errorcode = $args[0]
$ErrorCodes = @{
    '0x0000'    =    'Verbose message here';
...5000+ lines
}#end of hash table
if ($ErrorCodes.ContainsKey($Errorcode) -eq $True){
$Decode_Message = $ErrorCodes.get_item($Errorcode)
Write-Host $Decode_Message -ForegroundColor Green
} #End of hash lookup 
else {
Write-Host "Error Not Found, or Internal Unclassified" -ForegroundColor Red
} #End of Else 
} #End of Get-MCAError Function 
Get-MCAError $args[0]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37799197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档