Skip to content

Commit

Permalink
esp32s2ulp: fix JUMPS offset interpretation (make same as JUMPR)
Browse files Browse the repository at this point in the history
As per ESP32-S2 ULP coprocessor instruction set documentation, all
JUMP family instructions expect the address argument in 32-bit words.

For immediate values, JUMP and JUMPR do this as per documentation. In
other words an offset given in the assembly source in bytes is correctly
converted to 32-bit words (by doing >>2) when creating the binary
instruction.

With JUMPS however any value given in the assembly source file is kept
as-is when creating the binary instruction. Thus for example 4 bytes
specified in the source will stay 4 (32-bit words) in the binary
instruction, instead of 1 (32-bit word).

This commit fixes that behaviour. This also aligns the behaviour with
that of the ESP32 (not S2) assembler, where this already worked
correctly.

This change was tested on an actual ESP32-S2 with the following code:

```
.data
val: .long 0

.text
entry:
  move r3, val

  jumps 4, 42, lt

right:
  move r0, 66  # correct jump
  jump end
  nop
wrong:
  move r0, 73  # incorrect jump
  nop
end:
  st r0, r3, 0
  halt
```

Before the fix, the JUMPS instruction jumped 4 instructions forward,
and "val" was set to 73. After the fix JUMPS correctly jumped 1
instruction forward (4 bytes = 1 word), and "val" was set to 66.

Closes #3
  • Loading branch information
wnienhaus authored and Lapshin committed Jan 13, 2024
1 parent 3422296 commit 90457b0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gas/config/tc-esp32ulp_esp32s2.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ esp32ulp_cmd_jump_rels_esp32s2 (Expr_Node * step, Expr_Node * thresh,
int step_val = EXPR_VALUE (step);
int thresh_val = EXPR_VALUE (thresh);
{
unsigned int local_op = I_JUMP_RELS (thresh_val, cond, step_val);
unsigned int local_op = I_JUMP_RELS (thresh_val, cond, step_val >> 2);

INSTR_T result = conscode (gencode (local_op),
conctcode (Expr_Node_Gen_Reloc (step,
Expand Down
Binary file modified gas/testsuite/gas/esp32ulp/esp32s2/compare/esp32s2ulp_jump.bin
Binary file not shown.
14 changes: 7 additions & 7 deletions gas/testsuite/gas/esp32ulp/esp32s2/compare/esp32s2ulp_jump.lst
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ ESP32ULP GAS esp32s2ulp_jump.s page 1
69 0000DE82
70
71 // Jumps commands...
72 00f0 04001288 jumps 0x4, 0x04, EQ
73 00f4 04001288 jumps 0x04, check_thres1, EQ
72 00f0 04000688 jumps 0x4, 0x04, EQ
73 00f4 04000688 jumps 0x04, check_thres1, EQ
74 00f8 0400EA8A jumps check_jump1, check_thres1, EQ
75 00fc 0000EE8A jumps check_jump1, check_thres2, EQ
76 0100 0400F28A jumps check_jump2, check_thres1, EQ
Expand All @@ -111,8 +111,8 @@ ESP32ULP GAS esp32s2ulp_jump.s page 1
91 00000A82
92
93 //jumps with negative offset
94 0138 0000128A jumps -0x4, 0x00, EQ
95 013c 0080108A jumps -0x4, 0x00, LT
96 0140 0080118A jumps -0x4, 0x00, GT
97 0144 0080128A jumps -0x4, 0x00, LE
98 0148 0080138A jumps -0x4, 0x00, GE
94 0138 0000068A jumps -0x4, 0x00, EQ
95 013c 0080048A jumps -0x4, 0x00, LT
96 0140 0080058A jumps -0x4, 0x00, GT
97 0144 0080068A jumps -0x4, 0x00, LE
98 0148 0080078A jumps -0x4, 0x00, GE

0 comments on commit 90457b0

Please sign in to comment.