Skip to content

Commit 1bf5a02

Browse files
committed
py: Add ldrex and strex to thumb2 inline assembler.
These are useful for implementing atomic lock operations.
1 parent 91fc4a9 commit 1bf5a02

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

py/emitinlinethumb.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,14 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
397397
} else if (strcmp(op_str, "strh") == 0) {
398398
op_code = ASM_THUMB_FORMAT_10_STRH;
399399
goto op_format_9_10;
400+
} else if (strcmp(op_str, "ldrex") == 0) {
401+
mp_uint_t r_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
402+
mp_parse_node_t pn_base, pn_offset;
403+
if (get_arg_addr(emit, op_str, pn_args[1], &pn_base, &pn_offset)) {
404+
mp_uint_t r_base = get_arg_reg(emit, op_str, pn_base, 15);
405+
mp_uint_t i8 = get_arg_i(emit, op_str, pn_offset, 0xff) >> 2;
406+
asm_thumb_op32(emit->as, 0xe850 | r_base, 0x0f00 | (r_dest << 12) | i8);
407+
}
400408
} else {
401409
goto unknown_op;
402410
}
@@ -422,6 +430,15 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
422430
} else if (strcmp(op_str, "sub") == 0) {
423431
op_code = ASM_THUMB_FORMAT_2_SUB;
424432
goto op_format_2;
433+
} else if (strcmp(op_str, "strex") == 0) {
434+
mp_uint_t r_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
435+
mp_uint_t r_src = get_arg_reg(emit, op_str, pn_args[1], 15);
436+
mp_parse_node_t pn_base, pn_offset;
437+
if (get_arg_addr(emit, op_str, pn_args[2], &pn_base, &pn_offset)) {
438+
mp_uint_t r_base = get_arg_reg(emit, op_str, pn_base, 15);
439+
mp_uint_t i8 = get_arg_i(emit, op_str, pn_offset, 0xff) >> 2;
440+
asm_thumb_op32(emit->as, 0xe840 | r_base, (r_src << 12) | (r_dest << 8) | i8);
441+
}
425442
} else {
426443
goto unknown_op;
427444
}

0 commit comments

Comments
 (0)