Skip to content

Commit

Permalink
Merge pull request #396 from HyperDbg/hwdbg-script
Browse files Browse the repository at this point in the history
Hwdbg script
  • Loading branch information
SinaKarvandi committed Jun 20, 2024
2 parents 0963819 + 8c92c92 commit 8ddd213
Show file tree
Hide file tree
Showing 14 changed files with 1,019 additions and 918 deletions.
178 changes: 89 additions & 89 deletions hwdbg/sim/hwdbg/DebuggerModuleTestingBRAM/script_buffer_response.txt
Original file line number Diff line number Diff line change
@@ -1,133 +1,133 @@
Content of BRAM after emulation:

PS to PL area:
mem_0: 00000097 | Checksum
mem_0: 000000eb | Checksum
mem_1: 00000000 | Checksum
mem_2: 52444247 | Indicator
mem_3: 48595045 | Indicator
mem_4: 00000004 | TypeOfThePacket
mem_5: 00000002 | RequestedActionOfThePacket
mem_6: 00000013 | Start of Optional Data
mem_7: 00000005
mem_8: 0000001d
mem_9: 00000002
mem_10: 00000055
mem_11: 00000000
mem_6: 0000003b | Start of Optional Data
mem_7: 00000006
mem_8: 00000013
mem_9: 00000003
mem_10: 00000001
mem_11: 00000004
mem_12: 00000000
mem_13: 00000003
mem_14: 00000001
mem_15: 00000005
mem_16: 0000001d
mem_17: 00000002
mem_18: 00000000
mem_19: 00000000
mem_13: 00000007
mem_14: 00000000
mem_15: 00000006
mem_16: 00000017
mem_17: 00000003
mem_18: 0000000f
mem_19: 00000007
mem_20: 00000000
mem_21: 00000003
mem_22: 00000002
mem_23: 00000005
mem_24: 0000001d
mem_25: 00000002
mem_26: 00000000
mem_21: 00000000
mem_22: 00000000
mem_23: 00000006
mem_24: 0000001e
mem_25: 00000003
mem_26: 00000001
mem_27: 00000000
mem_28: 00000000
mem_29: 00000003
mem_29: 00000004
mem_30: 00000003
mem_31: 00000005
mem_32: 0000001d
mem_33: 00000002
mem_34: 00000000
mem_31: 00000006
mem_32: 0000001e
mem_33: 00000003
mem_34: 00000001
mem_35: 00000000
mem_36: 00000000
mem_37: 00000003
mem_38: 00000005
mem_39: 00000005
mem_40: 0000001d
mem_41: 00000002
mem_42: 00000000
mem_37: 00000004
mem_38: 00000004
mem_39: 00000006
mem_40: 00000016
mem_41: 00000003
mem_42: 0000002d
mem_43: 00000000
mem_44: 00000000
mem_45: 00000003
mem_46: 00000006
mem_47: 00000000
mem_48: 00000000
mem_49: 00000000
mem_50: 00000000
mem_51: 00000000
mem_52: 00000000
mem_53: 00000000
mem_45: 00000000
mem_46: 00000000
mem_47: 00000006
mem_48: 00000013
mem_49: 00000003
mem_50: 00000001
mem_51: 00000004
mem_52: 00000001
mem_53: 00000007
mem_54: 00000000
mem_55: 00000000
mem_56: 00000000
mem_57: 00000000
mem_58: 00000000
mem_59: 00000000
mem_55: 00000006
mem_56: 00000017
mem_57: 00000003
mem_58: 0000001b
mem_59: 00000007
mem_60: 00000000
mem_61: 00000000
mem_62: 00000000
mem_63: 00000000
mem_64: 00000000
mem_65: 00000000
mem_66: 00000000
mem_63: 00000006
mem_64: 0000001e
mem_65: 00000003
mem_66: 00000001
mem_67: 00000000
mem_68: 00000000
mem_69: 00000000
mem_70: 00000000
mem_71: 00000000
mem_72: 00000000
mem_73: 00000000
mem_74: 00000000
mem_69: 00000004
mem_70: 00000005
mem_71: 00000006
mem_72: 00000016
mem_73: 00000003
mem_74: 0000002d
mem_75: 00000000
mem_76: 00000000
mem_77: 00000000
mem_78: 00000000
mem_79: 00000000
mem_80: 00000000
mem_81: 00000000
mem_82: 00000000
mem_83: 00000000
mem_84: 00000000
mem_85: 00000000
mem_79: 00000006
mem_80: 00000013
mem_81: 00000003
mem_82: 00000001
mem_83: 00000004
mem_84: 00000002
mem_85: 00000007
mem_86: 00000000
mem_87: 00000000
mem_88: 00000000
mem_89: 00000000
mem_90: 00000000
mem_91: 00000000
mem_87: 00000006
mem_88: 00000017
mem_89: 00000003
mem_90: 0000002a
mem_91: 00000007
mem_92: 00000000
mem_93: 00000000
mem_94: 00000000
mem_95: 00000000
mem_96: 00000000
mem_97: 00000000
mem_98: 00000000
mem_95: 00000006
mem_96: 0000001e
mem_97: 00000003
mem_98: 00000001
mem_99: 00000000
mem_100: 00000000
mem_101: 00000000
mem_102: 00000000
mem_103: 00000000
mem_104: 00000000
mem_105: 00000000
mem_106: 00000000
mem_101: 00000004
mem_102: 00000007
mem_103: 00000006
mem_104: 0000001e
mem_105: 00000003
mem_106: 00000001
mem_107: 00000000
mem_108: 00000000
mem_109: 00000000
mem_110: 00000000
mem_111: 00000000
mem_112: 00000000
mem_113: 00000000
mem_114: 00000000
mem_109: 00000004
mem_110: 00000008
mem_111: 00000006
mem_112: 00000016
mem_113: 00000003
mem_114: 0000002d
mem_115: 00000000
mem_116: 00000000
mem_117: 00000000
mem_118: 00000000
mem_119: 00000000
mem_120: 00000000
mem_121: 00000000
mem_122: 00000000
mem_119: 00000006
mem_120: 0000001e
mem_121: 00000003
mem_122: 00000001
mem_123: 00000000
mem_124: 00000000
mem_125: 00000000
mem_126: 00000000
mem_125: 00000004
mem_126: 0000000a
mem_127: 00000000

PL to PS area:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@ def get_symbol_type(dut, type):
final_string_type = f'{type} : 0x{hex_string_type}' + " (bin: " + str(element_type.value) + ")"
return final_string_type

#
# Define a function to extract stage index
#
def get_stage_index(dut, stage_index):
stage_index_str = "stageRegs_" + str(stage_index) + "_stageIndex"
element_stage_index = getattr(dut.debuggerMainModule.outputPin_scriptExecutionEngineModule, stage_index_str)
hex_string_stage_index = ""
try:
int_content_stage_index = int(str(element_stage_index.value), 2)
hex_string_stage_index = f'{int_content_stage_index:x}'
except:
hex_string_stage_index = str(element_stage_index.value)

final_string_stage_index = f'{stage_index}: 0x{hex_string_stage_index}' + " (bin: " + str(element_stage_index.value) + ")"
return final_string_stage_index

#
# Define a function to extract content of stages
Expand All @@ -270,24 +285,28 @@ def extract_stage_details(dut):
#
pattern_value = re.compile(r'stageRegs_\d+_stageSymbol_Value')
pattern_type = re.compile(r'stageRegs_\d+_stageSymbol_Type')
pattern_stage_index = re.compile(r'stageRegs_\d+_stageIndex')

#
# Filter the list using the patterns
#
filtered_strings_values = [s for s in all_elements if pattern_value.match(s)]
filtered_strings_types = [s for s in all_elements if pattern_type.match(s)]
filtered_strings_stage_index = [s for s in all_elements if pattern_stage_index.match(s)]

#
# Sort the lists
#
sorted_values = sorted(filtered_strings_values, key=extract_number)
sorted_types = sorted(filtered_strings_types, key=extract_number)
sorted_stage_index = sorted(filtered_strings_stage_index, key=extract_number)

#
# Print the filtered strings
#
# print(sorted_values)
# print(sorted_types)
# print(sorted_stage_index)

for index, element in enumerate(sorted_values):

Expand All @@ -311,8 +330,20 @@ def extract_stage_details(dut):
except:
print("Unable to get stage 'value' configuration details")

try:
final_string_stage_index = get_stage_index(dut, index)

#
# Print the stage index
#
print("index: " + final_string_stage_index)

except:
print("index: " + str(index) +": This stage does not contain a 'stage index'")

print("\n")


#
# Check stage enable bit
#
Expand Down Expand Up @@ -358,21 +389,21 @@ def extract_stage_details(dut):

def set_input_pins(dut):
dut.io_inputPin_0.value = 1
dut.io_inputPin_1.value = 1
dut.io_inputPin_2.value = 1
dut.io_inputPin_3.value = 1
dut.io_inputPin_4.value = 1
dut.io_inputPin_5.value = 1
dut.io_inputPin_6.value = 1
dut.io_inputPin_7.value = 1
dut.io_inputPin_8.value = 1
dut.io_inputPin_9.value = 1
dut.io_inputPin_10.value = 1
dut.io_inputPin_11.value = 1
dut.io_inputPin_12.value = 1
dut.io_inputPin_13.value = 1
dut.io_inputPin_14.value = 1
dut.io_inputPin_15.value = 1
dut.io_inputPin_1.value = 0
dut.io_inputPin_2.value = 0
dut.io_inputPin_3.value = 0
dut.io_inputPin_4.value = 0
dut.io_inputPin_5.value = 0
dut.io_inputPin_6.value = 0
dut.io_inputPin_7.value = 0
dut.io_inputPin_8.value = 0
dut.io_inputPin_9.value = 0
dut.io_inputPin_10.value = 0
dut.io_inputPin_11.value = 0
dut.io_inputPin_12.value = 0
dut.io_inputPin_13.value = 0
dut.io_inputPin_14.value = 0
dut.io_inputPin_15.value = 0
dut.io_inputPin_16.value = 1
dut.io_inputPin_17.value = 1
dut.io_inputPin_18.value = 1
Expand Down
11 changes: 11 additions & 0 deletions hwdbg/src/main/scala/hwdbg/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ class DebuggerMain(
"err, the script variable length should not be bigger than BRAM data width."
)

//
// Ensure the maximum number of stages is not bigger than the maximum number
// that can be stored within the script variable length. This is because
// if a JUMP for conditional statements wants to set the target location,
// it cannot store its destination in a script variable.
//
require(
maximumNumberOfStages < math.pow(2, scriptVariableLength),
"err, the maximum number of stages should be less than 2 to the power of the script variable length."
)

val io = IO(new Bundle {

//
Expand Down
Loading

0 comments on commit 8ddd213

Please sign in to comment.