Skip to content

Commit 1cb0db3

Browse files
committed
fix JUMP with immediate offsets (should get converted to words)
Offsets specified as immediate values are given in bytes but the underlying machine instruction needs a word offset. Thus, we need to convert immediate values to words by dividing by 4. This commit contributes to being able to eventually assemble the esp32ulp_all.s test from binutils-esp32ulp. It addresses this line: https://github.com/espressif/binutils-esp32ulp/blob/249ec34cc2c9574a86f3f86bbb175a863f988bcf/gas/testsuite/gas/esp32ulp/esp32/esp32ulp_all.s#L109
1 parent e647bcc commit 1cb0db3

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

esp32_ulp/opcodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ def i_jump(target, condition='--'):
619619
raise ValueError("invalid flags condition")
620620
if target.type == IMM or target.type == SYM:
621621
_bx.dreg = 0
622-
_bx.addr = get_abs(target)
622+
_bx.addr = get_abs(target) if target.type == SYM else get_abs(target) >> 2 # bitwise version of "// 4"
623623
_bx.unused = 0
624624
_bx.reg = 0
625625
_bx.type = jump_type

tests/compat/jumps.S

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
entry:
66
nop
77

8+
# simple jumps
9+
jump entry
10+
jump later
11+
jump 0x120, EQ
12+
jump -288, EQ
13+
814
# jumps with labels
915
jumps entry, 42, lt
1016
jumps entry, 42, lt

0 commit comments

Comments
 (0)