Skip to content

Commit 7d54785

Browse files
committed
A problem with jumps over next instruction fixed.
1 parent e99d5e1 commit 7d54785

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

gas/config/tc-esp32ulp.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,26 +1127,37 @@ INSTR_T esp32ulp_cmd_jump_relr(Expr_Node* step, Expr_Node* thresh, int cond)
11271127
unsigned int local_op = I_JUMP_RELR(thresh_val, cond, step_val>>2);
11281128
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)));
11291129
}
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+
11301141
INSTR_T esp32ulp_cmd_jump_rels(Expr_Node* step, Expr_Node* thresh, int cond)
11311142
{
11321143
int step_val = EXPR_VALUE(step);
11331144
int thresh_val = EXPR_VALUE(thresh);
11341145

1135-
if ((cond == 3) || (cond == 4)) // EQ == 3, GT = 4
1146+
if ((cond == JUMPS_EQ) || (cond == JUMPS_GT)) // EQ == 3, GT = 4
11361147
{
1137-
1148+
// Conditions for multiple instructions
11381149
unsigned int walk_cond = 0;
11391150
unsigned int result_cond = 0;
11401151

1141-
if (cond == 3) // EQ
1152+
if (cond == JUMPS_EQ) // EQ
11421153
{
11431154
// Jumps Next, threshold, LT
11441155
// Jumps step, threshold, LE
11451156
//Next : something
11461157
walk_cond = 0;
11471158
result_cond = 2;
11481159
}
1149-
if (cond == 4) // GT
1160+
if (cond == JUMPS_GT) // GT
11501161
{
11511162
// Jumps Next, threshold, LE
11521163
// Jumps step, threshold, GE
@@ -1155,14 +1166,21 @@ INSTR_T esp32ulp_cmd_jump_rels(Expr_Node* step, Expr_Node* thresh, int cond)
11551166
walk_cond = 2;
11561167
result_cond = 1;
11571168
}
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
11591175
unsigned int local_result = I_JUMP_RELS(thresh_val, result_cond, step_val >> 2);
11601176

1177+
// Main instruction that makes jump
11611178
INSTR_T result = conscode(gencode(local_result),
11621179
conctcode(Expr_Node_Gen_Reloc(step, BFD_RELOC_ESP32ULP_JUMPR_STEP),
11631180
Expr_Node_Gen_Reloc(thresh, BFD_RELOC_ESP32ULP_JUMPS_THRESH)
11641181
)
11651182
);
1183+
// Additional instructiion for add additional check of the condition
11661184
INSTR_T walk1 = conscode(gencode(local_walk),
11671185
conctcode(Expr_Node_Gen_Reloc(thresh, BFD_RELOC_ESP32ULP_JUMPS_THRESH), NULL
11681186
)

gas/testsuite/gas/esp32ulp/compare/esp32ulp_all.lst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ ESP32ULP GAS ./gas/testsuite/gas/esp32ulp/esp32ulp_all.s page 1
136136
127
137137
128 //jumps
138138
129
139-
130 00e8 14000284 JUMPS 4, 20, EQ //Jump to address “position + 16” if value in S
139+
130 00e8 14000484 JUMPS 4, 20, EQ //Jump to address “position + 16” if value in S
140140
130 14000384
141141
131 00f0 00000040 nop
142142
132 00f4 00000040 nop
@@ -168,7 +168,7 @@ ESP32ULP GAS ./gas/testsuite/gas/esp32ulp/esp32ulp_all.s page 1
168168
158 012c 00010074 STAGE_INC 16 // set stage_cnt to 16
169169
159 0130 10002074 labelsd: STAGE_DEC 1 // stage_cnt--;
170170
160 0134 00000040 NOP // do something
171-
161 0138 00000384 JUMPS labelsd,0,GT // jump to address label if stage_cnt > 0
171+
161 0138 00000584 JUMPS labelsd,0,GT // jump to address label if stage_cnt > 0
172172
161 00800685
173173
162
174174
163 // Sleep

gas/testsuite/gas/esp32ulp/compare/esp32ulp_ranges.lst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ ESP32ULP GAS ./gas/testsuite/gas/esp32ulp/esp32ulp_ranges.s page 1
7474
68 0038 00001C83 JUMPR min_jumpr2, min_thresh2, LT
7575
69 003c 00001E83 JUMPR max_jumpr2, max_thresh2, LT
7676
70
77-
71 0040 00000284 JUMPS min_jumpr2, min_threshs3, EQ
77+
71 0040 00000484 JUMPS min_jumpr2, min_threshs3, EQ
7878
71 00002385
79-
72 0048 00000284 JUMPS max_jumpr2, max_threshs3, EQ
79+
72 0048 00000484 JUMPS max_jumpr2, max_threshs3, EQ
8080
72 00002785
8181
73
82-
74 0050 00000284 JUMPS min_jumpr2, min_threshs3, EQ
82+
74 0050 00000484 JUMPS min_jumpr2, min_threshs3, EQ
8383
74 00002B85
84-
75 0058 00000284 JUMPS max_jumpr2, max_threshs3, EQ
84+
75 0058 00000484 JUMPS max_jumpr2, max_threshs3, EQ
8585
75 00002F85
8686
76
8787
77

0 commit comments

Comments
 (0)