53 def WriteCommonHeader(self):
54
55
56
57
58 self.CommonHeaderFileScala.write("""package hwdbg.script
59
60import chisel3._
61import chisel3.util._
62
63/**
64 * @brief
65 * The structure of HWDBG_SHORT_SYMBOL used in script engine of HyperDbg
66 */
67class HwdbgShortSymbol(
68 scriptVariableLength: Int
69) extends Bundle {
70
71 //
72 // Ensure that the script variable length is at least 8 bits or 1 byte
73 //
74 require(
75 scriptVariableLength >= 8,
76 f"err, the minimum script variable length is 8 bits (1 byte)."
77 )
78
79 val Type = UInt(scriptVariableLength.W) // long long unsigned is 64 bits but it can be dynamic
80 val Value = UInt(scriptVariableLength.W) // long long unsigned is 64 bits but it can be dynamic
81}
82
83/**
84 * @brief
85 * Constant values for the script engine
86 */
87object ScriptConstants {
88 val SYMBOL_MEM_VALID_CHECK_MASK = 1 << 31
89 val INVALID = 0x80000000
90 val LALR_ACCEPT = 0x7fffffff
91}
92
93/**
94 * @brief
95 * Constant type values for the script engine
96 */
97object ScriptConstantTypes {
98 object ScriptDataTypes extends ChiselEnum {
99 val symbolUndefined, symbolGlobalIdType, symbolLocalIdType, symbolNumType, symbolRegisterType, symbolPseudoRegType, symbolSemanticRuleType, symbolTempType, symbolStringType, symbolVariableCountType, symbolInvalid, symbolWstringType, symbolUserDefinedFunctionType, symbolFunctionParameterIdType, symbolReturnAddressType, symbolStackTempType, symbolFunctionParameterType = Value
100 }
101}
102
103""")
104
105
106
107 self.CommonHeaderFile.write(
108 """#pragma once
109#ifndef SCRIPT_ENGINE_COMMON_DEFINITIONS_H
110#define SCRIPT_ENGINE_COMMON_DEFINITIONS_H
111
112typedef struct SYMBOL
113{
114 long long unsigned Type;
115 long long unsigned Len;
116 long long unsigned VariableType;
117 long long unsigned Value;
118
119} SYMBOL, *PSYMBOL;
120
121typedef struct HWDBG_SHORT_SYMBOL
122{
123 long long unsigned Type;
124 long long unsigned Value;
125
126} HWDBG_SHORT_SYMBOL, *PHWDBG_SHORT_SYMBOL;
127
128typedef struct SYMBOL_BUFFER {
129 PSYMBOL Head;
130 unsigned int Pointer;
131 unsigned int Size;
132 char* Message;
133} SYMBOL_BUFFER, * PSYMBOL_BUFFER;
134
135typedef struct SYMBOL_MAP
136{
137 char* Name;
138 long long unsigned Type;
139} SYMBOL_MAP, * PSYMBOL_MAP;
140
141typedef struct ACTION_BUFFER {
142 long long unsigned Tag;
143 long long unsigned CurrentAction;
144 char ImmediatelySendTheResults;
145 long long unsigned Context;
146 char CallingStage;
147} ACTION_BUFFER, *PACTION_BUFFER;
148
149typedef struct USER_DEFINED_FUNCTION_NODE
150{
151 char * Name;
152 long long unsigned Address;
153 long long unsigned VariableType;
154 PSYMBOL_BUFFER ParameterBuffer;
155 long long unsigned ParameterNumber;
156 long long unsigned StackTempNumber;
157 struct USER_DEFINED_FUNCTION_NODE * NextNode;
158} USER_DEFINED_FUNCTION_NODE, *PUSER_DEFINED_FUNCTION_NODE;
159
160#define SYMBOL_UNDEFINED 0
161#define SYMBOL_GLOBAL_ID_TYPE 1
162#define SYMBOL_LOCAL_ID_TYPE 2
163#define SYMBOL_NUM_TYPE 3
164#define SYMBOL_REGISTER_TYPE 4
165#define SYMBOL_PSEUDO_REG_TYPE 5
166#define SYMBOL_SEMANTIC_RULE_TYPE 6
167#define SYMBOL_TEMP_TYPE 7
168#define SYMBOL_STRING_TYPE 8
169#define SYMBOL_VARIABLE_COUNT_TYPE 9
170#define SYMBOL_INVALID 10
171#define SYMBOL_WSTRING_TYPE 11
172#define SYMBOL_FUNCTION_PARAMETER_ID_TYPE 12
173#define SYMBOL_RETURN_ADDRESS_TYPE 13
174#define SYMBOL_STACK_TEMP_TYPE 14
175#define SYMBOL_FUNCTION_PARAMETER_TYPE 15
176#define SYMBOL_STACK_INDEX_TYPE 16
177#define SYMBOL_STACK_BASE_INDEX_TYPE 17
178#define SYMBOL_RETURN_VALUE_TYPE 18
179
180static const char *const SymbolTypeNames[] = {
181"SYMBOL_UNDEFINED",
182"SYMBOL_GLOBAL_ID_TYPE",
183"SYMBOL_LOCAL_ID_TYPE",
184"SYMBOL_NUM_TYPE",
185"SYMBOL_REGISTER_TYPE",
186"SYMBOL_PSEUDO_REG_TYPE",
187"SYMBOL_SEMANTIC_RULE_TYPE",
188"SYMBOL_TEMP_TYPE",
189"SYMBOL_STRING_TYPE",
190"SYMBOL_VARIABLE_COUNT_TYPE",
191"SYMBOL_INVALID",
192"SYMBOL_WSTRING_TYPE",
193"SYMBOL_FUNCTION_PARAMETER_ID_TYPE",
194"SYMBOL_RETURN_ADDRESS_TYPE",
195"SYMBOL_STACK_TEMP_TYPE",
196"SYMBOL_FUNCTION_PARAMETER_TYPE",
197"SYMBOL_STACK_INDEX_TYPE",
198"SYMBOL_STACK_BASE_INDEX_TYPE",
199"SYMBOL_RETURN_VALUE_TYPE"
200};
201
202#define SYMBOL_MEM_VALID_CHECK_MASK (1 << 31)
203#define INVALID 0x80000000
204#define LALR_ACCEPT 0x7fffffff
205
206\n\n""")
207
208
209