@@ -1127,26 +1127,37 @@ INSTR_T esp32ulp_cmd_jump_relr(Expr_Node* step, Expr_Node* thresh, int cond)
1127
1127
unsigned int local_op = I_JUMP_RELR (thresh_val , cond , step_val >>2 );
1128
1128
return conscode (gencode (local_op ), conctcode (Expr_Node_Gen_Reloc (step , BFD_RELOC_ESP32ULP_JUMPR_STEP ), Expr_Node_Gen_Reloc (thresh , BFD_RELOC_ESP32ULP_JUMPR_THRESH )));
1129
1129
}
1130
+
1131
+ // Conditions for JUMPS instructions
1132
+ #define JUMPS_EQ 3
1133
+ #define JUMPS_GT 4
1134
+ #define JUMPS_LE 2
1135
+ #define JUMPS_LT 0
1136
+ #define JUMPS_GE 1
1137
+
1138
+ // Step to reach next instruction
1139
+ #define NEXT_INSTRUCTION_STEP 4
1140
+
1130
1141
INSTR_T esp32ulp_cmd_jump_rels (Expr_Node * step , Expr_Node * thresh , int cond )
1131
1142
{
1132
1143
int step_val = EXPR_VALUE (step );
1133
1144
int thresh_val = EXPR_VALUE (thresh );
1134
1145
1135
- if ((cond == 3 ) || (cond == 4 )) // EQ == 3, GT = 4
1146
+ if ((cond == JUMPS_EQ ) || (cond == JUMPS_GT )) // EQ == 3, GT = 4
1136
1147
{
1137
-
1148
+ // Conditions for multiple instructions
1138
1149
unsigned int walk_cond = 0 ;
1139
1150
unsigned int result_cond = 0 ;
1140
1151
1141
- if (cond == 3 ) // EQ
1152
+ if (cond == JUMPS_EQ ) // EQ
1142
1153
{
1143
1154
// Jumps Next, threshold, LT
1144
1155
// Jumps step, threshold, LE
1145
1156
//Next : something
1146
1157
walk_cond = 0 ;
1147
1158
result_cond = 2 ;
1148
1159
}
1149
- if (cond == 4 ) // GT
1160
+ if (cond == JUMPS_GT ) // GT
1150
1161
{
1151
1162
// Jumps Next, threshold, LE
1152
1163
// Jumps step, threshold, GE
@@ -1155,14 +1166,21 @@ INSTR_T esp32ulp_cmd_jump_rels(Expr_Node* step, Expr_Node* thresh, int cond)
1155
1166
walk_cond = 2 ;
1156
1167
result_cond = 1 ;
1157
1168
}
1158
- unsigned int local_walk = I_JUMP_RELS (thresh_val , walk_cond , 4 >> 2 );
1169
+ // Step over next jumps
1170
+ unsigned int local_walk = I_JUMP_RELS (thresh_val , walk_cond , (NEXT_INSTRUCTION_STEP * 2 ) >> 2 );
1171
+ // In case of back jump, we have to add additional jumps instruction to the step value
1172
+ if (step_val < 0 ) step_val = step_val - 4 ;
1173
+
1174
+ // Step to the target instruction
1159
1175
unsigned int local_result = I_JUMP_RELS (thresh_val , result_cond , step_val >> 2 );
1160
1176
1177
+ // Main instruction that makes jump
1161
1178
INSTR_T result = conscode (gencode (local_result ),
1162
1179
conctcode (Expr_Node_Gen_Reloc (step , BFD_RELOC_ESP32ULP_JUMPR_STEP ),
1163
1180
Expr_Node_Gen_Reloc (thresh , BFD_RELOC_ESP32ULP_JUMPS_THRESH )
1164
1181
)
1165
1182
);
1183
+ // Additional instructiion for add additional check of the condition
1166
1184
INSTR_T walk1 = conscode (gencode (local_walk ),
1167
1185
conctcode (Expr_Node_Gen_Reloc (thresh , BFD_RELOC_ESP32ULP_JUMPS_THRESH ), NULL
1168
1186
)
0 commit comments