From 90457b0a7dfeb40c17a0052ef145626b12f69e49 Mon Sep 17 00:00:00 2001 From: Wilko Nienhaus Date: Sun, 18 Jun 2023 16:42:42 +0300 Subject: [PATCH] esp32s2ulp: fix JUMPS offset interpretation (make same as JUMPR) 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 https://github.com/espressif/binutils-gdb/pull/3 --- gas/config/tc-esp32ulp_esp32s2.c | 2 +- .../esp32s2/compare/esp32s2ulp_jump.bin | Bin 5076 -> 5076 bytes .../esp32s2/compare/esp32s2ulp_jump.lst | 14 +++++++------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gas/config/tc-esp32ulp_esp32s2.c b/gas/config/tc-esp32ulp_esp32s2.c index 9bb0d2281cdf..4c76f47fbd4c 100644 --- a/gas/config/tc-esp32ulp_esp32s2.c +++ b/gas/config/tc-esp32ulp_esp32s2.c @@ -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, diff --git a/gas/testsuite/gas/esp32ulp/esp32s2/compare/esp32s2ulp_jump.bin b/gas/testsuite/gas/esp32ulp/esp32s2/compare/esp32s2ulp_jump.bin index 39139ab8545844e1774378e17353a052398b3a8b..89c507ae969921e8832b3983061edeaa938513c0 100755 GIT binary patch delta 45 vcmcbjenox5CjnNr4i*Ns$=?N>h1t3o8d!js6^KD>_O9xQjq;mw1T&ZbR$vZF delta 45 vcmcbjenox5CjnNW4i*NX$=?N>g@w8p8U%n?5Qsr+;jZe5jq;mw1T&ZbUK|dd diff --git a/gas/testsuite/gas/esp32ulp/esp32s2/compare/esp32s2ulp_jump.lst b/gas/testsuite/gas/esp32ulp/esp32s2/compare/esp32s2ulp_jump.lst index 5e5801fe7d40..7d9fff812867 100644 --- a/gas/testsuite/gas/esp32ulp/esp32s2/compare/esp32s2ulp_jump.lst +++ b/gas/testsuite/gas/esp32ulp/esp32s2/compare/esp32s2ulp_jump.lst @@ -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 @@ -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