From 2f8172fa261259073ff2f6bf81ee54e16ff2b1cb Mon Sep 17 00:00:00 2001 From: Thiebaud Weksteen Date: Mon, 2 Nov 2015 11:09:23 +1100 Subject: [PATCH] Move interrupts command to a class --- source/tool/chipsec/utilcmd/interrupts_cmd.py | 108 +++++++++--------- 1 file changed, 53 insertions(+), 55 deletions(-) diff --git a/source/tool/chipsec/utilcmd/interrupts_cmd.py b/source/tool/chipsec/utilcmd/interrupts_cmd.py index 0863745b..d78b31c1 100644 --- a/source/tool/chipsec/utilcmd/interrupts_cmd.py +++ b/source/tool/chipsec/utilcmd/interrupts_cmd.py @@ -23,15 +23,7 @@ __version__ = '1.0' -import os -import sys -import time - -import chipsec_util - -from chipsec.logger import * -from chipsec.file import * - +from chipsec.command import BaseCommand from chipsec.hal.interrupts import Interrupts # ################################################################### @@ -39,7 +31,7 @@ from chipsec.hal.interrupts import Interrupts # CPU Interrupts # # ################################################################### -def smi(argv): +class SMICommand(BaseCommand): """ >>> chipsec_util smi [RAX] [RBX] [RCX] [RDX] [RSI] [RDI] @@ -48,42 +40,49 @@ def smi(argv): >>> chipsec_util smi 0x0 0xDE 0x0 >>> chipsec_util smi 0x0 0xDE 0x0 0xAAAAAAAAAAAAAAAA .. """ - try: - interrupts = Interrupts( chipsec_util._cs ) - except RuntimeError, msg: - print msg - return + def requires_driver(self): + # No driver required when printing the util documentation + if len(self.argv) < 3: + return False + return True - SMI_code_port_value = 0xF - SMI_data_port_value = 0x0 - if (2 == len(argv)): - print smi.__doc__ - elif (4 < len(argv)): - thread_id = int(argv[2],16) - SMI_code_port_value = int(argv[3],16) - SMI_data_port_value = int(argv[4],16) - logger().log( "[CHIPSEC] Sending SW SMI (code: 0x%02X, data: 0x%02X).." % (SMI_code_port_value, SMI_data_port_value) ) - if (5 == len(argv)): - interrupts.send_SMI_APMC( SMI_code_port_value, SMI_data_port_value ) - elif (11 == len(argv)): - _rax = int(argv[5],16) - _rbx = int(argv[6],16) - _rcx = int(argv[7],16) - _rdx = int(argv[8],16) - _rsi = int(argv[9],16) - _rdi = int(argv[10],16) - logger().log( " RAX: 0x%016X (AX will be overwridden with values of SW SMI ports B2/B3)" % _rax ) - logger().log( " RBX: 0x%016X" % _rbx ) - logger().log( " RCX: 0x%016X" % _rcx ) - logger().log( " RDX: 0x%016X (DX will be overwridden with 0x00B2)" % _rdx ) - logger().log( " RSI: 0x%016X" % _rsi ) - logger().log( " RDI: 0x%016X" % _rdi ) - interrupts.send_SW_SMI( thread_id, SMI_code_port_value, SMI_data_port_value, _rax, _rbx, _rcx, _rdx, _rsi, _rdi ) - else: print smi.__doc__ - else: print smi.__doc__ + def run(self): + try: + interrupts = Interrupts( self.cs ) + except RuntimeError, msg: + print msg + return + + SMI_code_port_value = 0xF + SMI_data_port_value = 0x0 + if (2 == len(self.argv)): + print SMICommand.__doc__ + elif (4 < len(self.argv)): + thread_id = int(self.argv[2],16) + SMI_code_port_value = int(self.argv[3],16) + SMI_data_port_value = int(self.argv[4],16) + self.logger.log( "[CHIPSEC] Sending SW SMI (code: 0x%02X, data: 0x%02X).." % (SMI_code_port_value, SMI_data_port_value) ) + if (5 == len(self.argv)): + interrupts.send_SMI_APMC( SMI_code_port_value, SMI_data_port_value ) + elif (11 == len(self.argv)): + _rax = int(self.argv[5],16) + _rbx = int(self.argv[6],16) + _rcx = int(self.argv[7],16) + _rdx = int(self.argv[8],16) + _rsi = int(self.argv[9],16) + _rdi = int(self.argv[10],16) + self.logger.log( " RAX: 0x%016X (AX will be overwridden with values of SW SMI ports B2/B3)" % _rax ) + self.logger.log( " RBX: 0x%016X" % _rbx ) + self.logger.log( " RCX: 0x%016X" % _rcx ) + self.logger.log( " RDX: 0x%016X (DX will be overwridden with 0x00B2)" % _rdx ) + self.logger.log( " RSI: 0x%016X" % _rsi ) + self.logger.log( " RDI: 0x%016X" % _rdi ) + interrupts.send_SW_SMI( thread_id, SMI_code_port_value, SMI_data_port_value, _rax, _rbx, _rcx, _rdx, _rsi, _rdi ) + else: print SMICommand.__doc__ + else: print SMICommand.__doc__ -def nmi(argv): +class NMICommand(BaseCommand): """ >>> chipsec_util nmi @@ -91,18 +90,17 @@ def nmi(argv): >>> chipsec_util nmi """ - if 2 < len(argv): - print nmi.__doc__ + def requires_driver(self): + return True - try: - interrupts = Interrupts( chipsec_util._cs ) - except RuntimeError, msg: - print msg - return + def run(self): + try: + interrupts = Interrupts( self.cs ) + except RuntimeError, msg: + print msg + return - logger().log( "[CHIPSEC] Sending NMI#.." ) - interrupts.send_NMI() + self.logger.log( "[CHIPSEC] Sending NMI#.." ) + interrupts.send_NMI() - -chipsec_util.commands['nmi'] = {'func' : nmi, 'start_driver' : True, 'help' : nmi.__doc__ } -chipsec_util.commands['smi'] = {'func' : smi, 'start_driver' : True, 'help' : smi.__doc__ } +commands = { 'smi': SMICommand, 'nmi': NMICommand }