diff options
Diffstat (limited to 'py/emitinlinethumb.c')
-rw-r--r-- | py/emitinlinethumb.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c index 530bd95254..ddcd5d3947 100644 --- a/py/emitinlinethumb.c +++ b/py/emitinlinethumb.c @@ -367,12 +367,14 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a } else if (n_args == 1) { if (strcmp(op_str, "b") == 0) { int label_num = get_arg_label(emit, op_str, pn_args[0]); - // TODO check that this succeeded, ie branch was within range - asm_thumb_b_n(emit->as, label_num); + if (!asm_thumb_b_n_label(emit->as, label_num)) { + goto branch_not_in_range; + } } else if (strcmp(op_str, "bl") == 0) { int label_num = get_arg_label(emit, op_str, pn_args[0]); - // TODO check that this succeeded, ie branch was within range - asm_thumb_bl(emit->as, label_num); + if (!asm_thumb_bl_label(emit->as, label_num)) { + goto branch_not_in_range; + } } else if (strcmp(op_str, "bx") == 0) { mp_uint_t r = get_arg_reg(emit, op_str, pn_args[0], 15); asm_thumb_op16(emit->as, 0x4700 | (r << 3)); @@ -387,8 +389,9 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a goto unknown_op; } int label_num = get_arg_label(emit, op_str, pn_args[0]); - // TODO check that this succeeded, ie branch was within range - asm_thumb_bcc_n(emit->as, cc, label_num); + if (!asm_thumb_bcc_n_label(emit->as, cc, label_num)) { + goto branch_not_in_range; + } } else if (op_str[0] == 'i' && op_str[1] == 't') { const char *arg_str = get_arg_str(pn_args[0]); mp_uint_t cc = -1; @@ -608,6 +611,11 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a unknown_op: emit_inline_thumb_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, "unsupported Thumb instruction '%s' with %d arguments", op_str, n_args)); + return; + +branch_not_in_range: + emit_inline_thumb_error_msg(emit, "branch not in range"); + return; } const emit_inline_asm_method_table_t emit_inline_thumb_method_table = { |