aboutsummaryrefslogtreecommitdiff
path: root/py/asmthumb.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-05-19 15:05:32 +1000
committerDamien George <damien@micropython.org>2022-05-19 17:31:56 +1000
commit56f2d3c2e5b9a9c0f0470f3850216c3191a59b67 (patch)
treec0d8fd7ee1a5ff8822e97170555cf56ce2c069ba /py/asmthumb.c
parentc70f96f1c57456031c5b3fc9bd89a564106e345b (diff)
py/asmthumb: Fix PC relative load by sign extending the constant.
PC relative offsets can be negative, in which case the movw result must be sign extended. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/asmthumb.c')
-rw-r--r--py/asmthumb.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/py/asmthumb.c b/py/asmthumb.c
index db4520ce1..04fb82330 100644
--- a/py/asmthumb.c
+++ b/py/asmthumb.c
@@ -430,8 +430,9 @@ void asm_thumb_mov_reg_pcrel(asm_thumb_t *as, uint rlo_dest, uint label) {
mp_int_t rel = dest - as->base.code_offset;
rel |= 1; // to stay in Thumb state when jumping to this address
#if MICROPY_EMIT_THUMB_ARMV7M
- rel -= 4 + 4; // adjust for mov_reg_i16 and then PC+4 prefetch of add_reg_reg
+ rel -= 6 + 4; // adjust for mov_reg_i16, sxth_rlo_rlo and then PC+4 prefetch of add_reg_reg
asm_thumb_mov_reg_i16(as, ASM_THUMB_OP_MOVW, rlo_dest, rel); // 4 bytes
+ asm_thumb_sxth_rlo_rlo(as, rlo_dest, rlo_dest); // 2 bytes
#else
rel -= 8 + 4; // adjust for four instructions and then PC+4 prefetch of add_reg_reg
// 6 bytes