2016-06-13 2 views
0

Это моя первая попытка создания скриптов на любом языке. Я знаю, что я хотел бы сделать, но мог бы использовать некоторую помощь в поиске того, что я ищу. Это побочный проект для моего собственного обучения и развлечения :)Типы данных PowerShell и Hashtable MCA_Decode

  1. Берет 1 аргумент (два байт шестнадцатеричных или двоичных)
  2. сравнит от ошибок маски
  3. Write-Host с объяснением

В настоящее время типы данных для всех, вероятно, являются строками. Нужно ли мне это быть int? int32? int64?

маски ошибок просто присваиваются переменным

$IO_Error = 0000111000001011 

Будет ли он более эффективно хранить их как «Hashtable»

$ErrorList = @{IO_Error, 0000111000001011; so, on; so, on;} 

Затем иметь возможность проверить, если Foreach матч?

Это хорошо работает для простых ошибок, однако, попадая в составные коды ошибок и маски, я должен иметь возможность ссылаться и проверять определенные смещения, чтобы увидеть, какие биты установлены для обеспечения точного декодирования.

<# 
# ===================== 
# 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] 
+0

Просто уточнить, переменные на самом деле все «строка» $ IO_Error.GetTypeCode() Строка – genperf

+0

Просто для уточнения, переменные в fact all "string" $ IO_Error.GetTypeCode() String Поэтому я могу легко отправить свою переменную в | gm однако для тех, кто никогда не играл с этим до определения, не является чем-то, что легко интерпретируется, например, это достаточно легко. Length Property int Length {get;} if ($ input.Length -le ​​4) {[convert ] :: ToString («$ input», 2)} ..... Я знаю, что два байтовых ввода в шестнадцатеричном формате будут содержать 4 символа, поэтому это может проверить, и если hex я могу преобразовать в двоичный файл. Непонятно, нужны ли эти значения для инц и какой – genperf

ответ

0

Хэш-таблица может помочь вам решить отдельные ошибки.

Могу ли я предложить определение значений кода ошибки в шестнадцатеричном виде, PowerShell анализирует его изначально, и его легче читать IMO.

Кроме того, если вы планируете вводить сложные ошибки, убедитесь, что каждый бит представляет собой отличную примитивную ошибку.

Вы могли бы сделать что-то вроде:

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[$_] } 
} 

Теперь вы можете разрешить ошибки по значению:

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

Спасибо за помощь. я был в состоянии получить все работает, используя помощь от этого https://technet.microsoft.com/en-us/library/ee692803.aspx

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] 
Смежные вопросы