Skip to content

Commit 249ec34

Browse files
committed
esp32s2: fix negative immediate offset handling for relative jumps (jumpr, jumps)
When providing negative immediate offset (step) values to the JUMPR and JUMPS opcodes, the resulting instruction contained an incorrect offset. This commit fixes that behaviour. This is the same issue that affected the ESP32 code. See previous commit for more technical detail on the issue.
1 parent 7010e54 commit 249ec34

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed
Binary file not shown.

gas/testsuite/gas/esp32ulp/esp32s2/compare/esp32s2ulp_jump.lst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,18 @@ ESP32ULP GAS ./gas/testsuite/gas/esp32ulp/esp32s2/esp32s2ulp_jump.s page 1
101101
83 0118 00800388 jumps 0x0, 0x00, GE
102102
84
103103
85
104+
86 //jumpr with negative offset
105+
87 011c 00000682 jumpr -0x4, 0x00, EQ
106+
88 0120 00000482 jumpr -0x4, 0x00, LT
107+
89 0124 00000582 jumpr -0x4, 0x00, GT
108+
90 0128 00000482 jumpr -0x4, 0x00, LE
109+
90 00000A82
110+
91 0130 00000582 jumpr -0x4, 0x00, GE
111+
91 00000A82
112+
92
113+
93 //jumps with negative offset
114+
94 0138 0000128A jumps -0x4, 0x00, EQ
115+
95 013c 0080108A jumps -0x4, 0x00, LT
116+
96 0140 0080118A jumps -0x4, 0x00, GT
117+
97 0144 0080128A jumps -0x4, 0x00, LE
118+
98 0148 0080138A jumps -0x4, 0x00, GE

gas/testsuite/gas/esp32ulp/esp32s2/esp32s2ulp_jump.s

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,16 @@ jmp2: nop
8383
jumps 0x0, 0x00, GE
8484

8585

86+
//jumpr with negative offset
87+
jumpr -0x4, 0x00, EQ
88+
jumpr -0x4, 0x00, LT
89+
jumpr -0x4, 0x00, GT
90+
jumpr -0x4, 0x00, LE
91+
jumpr -0x4, 0x00, GE
92+
93+
//jumps with negative offset
94+
jumps -0x4, 0x00, EQ
95+
jumps -0x4, 0x00, LT
96+
jumps -0x4, 0x00, GT
97+
jumps -0x4, 0x00, LE
98+
jumps -0x4, 0x00, GE

include/opcode/esp32ulp_esp32s2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ typedef struct {
135135
#define I_JUMP_RELR(thresh, jud, stp) { *(unsigned int*)&(jump_alu_relr ){ \
136136
.threshold = thresh, \
137137
.judge = jud, \
138-
.step = stp, \
138+
.step = ((stp < 0) ? ((-stp) | (1 << 7)) : stp) , \
139139
.sub_opcode = SUB_OPCODE_BR, \
140140
.opcode = OPCODE_BRANCH } }
141141

@@ -155,7 +155,7 @@ typedef struct {
155155
.threshold = thresh, \
156156
.unused = 0, \
157157
.judge = jud, \
158-
.step = stp, \
158+
.step = ((stp < 0) ? ((-stp) | (1 << 7)) : stp) , \
159159
.sub_opcode = SUB_OPCODE_BS, \
160160
.opcode = OPCODE_BRANCH } }
161161

0 commit comments

Comments
 (0)