Skip to content

Commit

Permalink
Merge pull request #383 from HyperDbg/hwdbg-script
Browse files Browse the repository at this point in the history
Hwdbg script
  • Loading branch information
SinaKarvandi committed Jun 13, 2024
2 parents 2d793e7 + 4636be8 commit b930f57
Show file tree
Hide file tree
Showing 19 changed files with 789 additions and 414 deletions.
24 changes: 12 additions & 12 deletions hwdbg/sim/hwdbg/DebuggerModuleTestingBRAM/bram_instance_info.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Content of BRAM after emulation:

PS to PL area:
mem_0: 00000000 | Checksum
mem_0: 0000005a | Checksum
mem_1: 00000000 | Checksum
mem_2: 52444247 | Indicator
mem_3: 48595045 | Indicator
Expand Down Expand Up @@ -140,17 +140,17 @@ mem_133: 00000002 | RequestedActionOfThePacket
mem_134: 00000100 | Start of Optional Data
mem_135: 0000000a
mem_136: 00000008
mem_137: 00000003
mem_138: 00000000
mem_139: 00000200
mem_140: 00000020
mem_141: 00000002
mem_142: 01bfffd7
mem_143: 00000000
mem_144: 0000000c
mem_145: 00000014
mem_146: 00000000
mem_147: 00000000
mem_137: 00000002
mem_138: 00000001
mem_139: 00000400
mem_140: 00000000
mem_141: 00000200
mem_142: 00000020
mem_143: 00000002
mem_144: 003fffdf
mem_145: 00000000
mem_146: 0000000c
mem_147: 00000014
mem_148: 00000000
mem_149: 00000000
mem_150: 00000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import hwdbg.utils._
object InterpreterInstanceInfoEnums {
object State extends ChiselEnum {
val sIdle, sSendVersion, sSendMaximumNumberOfStages, sSendScriptVariableLength,
sSendMaximumNumberOfSupportedScriptOperators, sSendDebuggerAreaOffset, sSendDebuggeeAreaOffset,
sSendMaximumNumberOfSupportedGetScriptOperators, sSendMaximumNumberOfSupportedSetScriptOperators,
sSendSharedMemorySize, sSendDebuggerAreaOffset, sSendDebuggeeAreaOffset,
sSendNumberOfPins, sSendNumberOfPorts, sSendScriptCapabilities1, sSendScriptCapabilities2,
sSendPortsConfiguration, sDone = Value
}
Expand Down Expand Up @@ -148,16 +149,47 @@ class InterpreterInstanceInfo(
//
dataValidOutput := true.B

state := sSendMaximumNumberOfSupportedScriptOperators
state := sSendMaximumNumberOfSupportedGetScriptOperators

}
is(sSendMaximumNumberOfSupportedScriptOperators) {
is(sSendMaximumNumberOfSupportedGetScriptOperators) {

//
// Set the maximum number of supported operators by this instance of the
// Set the maximum number of supported GET operators by this instance of the
// debugger in the script engine
//
sendingData := instanceInfo.maximumNumberOfSupportedScriptOperators.U
sendingData := instanceInfo.maximumNumberOfSupportedGetScriptOperators.U

//
// The output is valid
//
dataValidOutput := true.B

state := sSendMaximumNumberOfSupportedSetScriptOperators

}
is(sSendMaximumNumberOfSupportedSetScriptOperators) {

//
// Set the maximum number of supported SET operators by this instance of the
// debugger in the script engine
//
sendingData := instanceInfo.maximumNumberOfSupportedSetScriptOperators.U

//
// The output is valid
//
dataValidOutput := true.B

state := sSendSharedMemorySize

}
is(sSendSharedMemorySize) {

//
// Set the shared memory size used by this instance of the debugger
//
sendingData := instanceInfo.sharedMemorySize.U

//
// The output is valid
Expand Down
39 changes: 30 additions & 9 deletions hwdbg/src/main/scala/hwdbg/configs/configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,13 @@ object ScriptEngineConfigurations {
//
// Maximum number of stages
//
val MAXIMUM_NUMBER_OF_SUPPORTED_OPERATORS: Int = 3 // 2 for get value and 1 for set value
val MAXIMUM_NUMBER_OF_SUPPORTED_GET_SCRIPT_OPERATORS: Int = 2 // for get values

//
// Maximum number of stages
//
val MAXIMUM_NUMBER_OF_SUPPORTED_SET_SCRIPT_OPERATORS: Int = 1 // for get value


//
// Script variable length
Expand Down Expand Up @@ -182,7 +188,9 @@ case class HwdbgInstanceInformation(
version: Int, // Target version of HyperDbg (same as hwdbg)
maximumNumberOfStages: Int, // Number of stages that this instance of hwdbg supports (NumberOfSupportedStages == 0 means script engine is disabled)
scriptVariableLength: Int, // Maximum length of variables (and other script elements)
maximumNumberOfSupportedScriptOperators: Int, // Maximum supported operators in a single func
maximumNumberOfSupportedGetScriptOperators: Int, // Maximum supported GET operators in a single func
maximumNumberOfSupportedSetScriptOperators: Int, // Maximum supported SET operators in a single func
sharedMemorySize: Int, // Size of shared memory
debuggerAreaOffset: Int, // The memory offset of debugger
debuggeeAreaOffset: Int, // The memory offset of debuggee
numberOfPins: Int, // Number of pins
Expand All @@ -192,6 +200,7 @@ case class HwdbgInstanceInformation(
)

object HwdbgScriptCapabilities {

val func_inc: Long = 1L << 0
val func_dec: Long = 1L << 1
val func_or: Long = 1L << 2
Expand Down Expand Up @@ -219,10 +228,7 @@ object HwdbgScriptCapabilities {
def allCapabilities: Seq[Long] = Seq(
func_inc, func_dec, func_or, func_xor, func_and, func_asr, func_asl, func_add, func_sub, func_mul, func_div, func_mod, func_gt, func_lt,
func_egt, func_elt, func_equal, func_neq, func_jmp, func_jz, func_jnz, func_mov, func_printf
)r
}

object HwdbgInstanceInformation {
)

//
// Utility method to create a bitmask from a sequence of capabilities
Expand All @@ -231,14 +237,27 @@ object HwdbgInstanceInformation {
capabilities.foldLeft(0L)(_ | _)
}

//
// Function to check if a capability is supported
//
def isCapabilitySupported(supportedCapabilities: Long, capability: Long): Boolean = {
(supportedCapabilities & capability) != 0
}

}

object HwdbgInstanceInformation {

//
// Function to create an instance of HwdbgInstanceInformation
//
def createInstanceInformation(
version: Int,
maximumNumberOfStages: Int,
scriptVariableLength: Int,
maximumNumberOfSupportedScriptOperators: Int,
maximumNumberOfSupportedGetScriptOperators: Int,
maximumNumberOfSupportedSetScriptOperators: Int,
sharedMemorySize: Int,
debuggerAreaOffset: Int,
debuggeeAreaOffset: Int,
numberOfPins: Int,
Expand All @@ -247,7 +266,7 @@ object HwdbgInstanceInformation {
portsConfiguration: Array[Int]
): HwdbgInstanceInformation = {

val capabilitiesMask = createCapabilitiesMask(enabledCapabilities)
val capabilitiesMask = HwdbgScriptCapabilities.createCapabilitiesMask(enabledCapabilities)

//
// Printing the versioning info
Expand All @@ -263,7 +282,9 @@ object HwdbgInstanceInformation {
version = version,
maximumNumberOfStages = maximumNumberOfStages,
scriptVariableLength = scriptVariableLength,
maximumNumberOfSupportedScriptOperators = maximumNumberOfSupportedScriptOperators,
maximumNumberOfSupportedGetScriptOperators = maximumNumberOfSupportedGetScriptOperators,
maximumNumberOfSupportedSetScriptOperators = maximumNumberOfSupportedSetScriptOperators,
sharedMemorySize = sharedMemorySize,
debuggerAreaOffset = debuggerAreaOffset,
debuggeeAreaOffset = debuggeeAreaOffset,
numberOfPins = numberOfPins,
Expand Down
16 changes: 12 additions & 4 deletions hwdbg/src/main/scala/hwdbg/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class DebuggerMain(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int,
maximumNumberOfStages: Int,
maximumNumberOfSupportedScriptOperators: Int,
maximumNumberOfSupportedGetScriptOperators: Int,
maximumNumberOfSupportedSetScriptOperators: Int,
sharedMemorySize: Int,
debuggerAreaOffset: Int,
debuggeeAreaOffset: Int,
scriptVariableLength: Int,
Expand Down Expand Up @@ -83,7 +85,9 @@ class DebuggerMain(
version = Version.getEncodedVersion,
maximumNumberOfStages = maximumNumberOfStages,
scriptVariableLength = scriptVariableLength,
maximumNumberOfSupportedScriptOperators = maximumNumberOfSupportedScriptOperators,
maximumNumberOfSupportedGetScriptOperators = maximumNumberOfSupportedGetScriptOperators,
maximumNumberOfSupportedSetScriptOperators = maximumNumberOfSupportedSetScriptOperators,
sharedMemorySize = sharedMemorySize,
debuggerAreaOffset = debuggerAreaOffset,
debuggeeAreaOffset = debuggeeAreaOffset,
numberOfPins = numberOfPins,
Expand Down Expand Up @@ -201,7 +205,9 @@ object DebuggerMain {
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int,
maximumNumberOfStages: Int,
maximumNumberOfSupportedScriptOperators: Int,
maximumNumberOfSupportedGetScriptOperators: Int,
maximumNumberOfSupportedSetScriptOperators: Int,
sharedMemorySize: Int,
debuggerAreaOffset: Int,
debuggeeAreaOffset: Int,
scriptVariableLength: Int,
Expand All @@ -221,7 +227,9 @@ object DebuggerMain {
debug,
numberOfPins,
maximumNumberOfStages,
maximumNumberOfSupportedScriptOperators,
maximumNumberOfSupportedGetScriptOperators,
maximumNumberOfSupportedSetScriptOperators,
sharedMemorySize,
debuggerAreaOffset,
debuggeeAreaOffset,
scriptVariableLength,
Expand Down
Loading

0 comments on commit b930f57

Please sign in to comment.