Skip to content

Commit

Permalink
py/asmxtensa: Handle function entry/exit when stack use larger than 127.
Browse files Browse the repository at this point in the history
  • Loading branch information
dpgeorge committed Aug 16, 2018
1 parent 8c49995 commit f7d6108
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions py/asmxtensa.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ void asm_xtensa_entry(asm_xtensa_t *as, int num_locals) {

// adjust the stack-pointer to store a0, a12, a13, a14 and locals, 16-byte aligned
as->stack_adjust = (((4 + num_locals) * WORD_SIZE) + 15) & ~15;
asm_xtensa_op_addi(as, ASM_XTENSA_REG_A1, ASM_XTENSA_REG_A1, -as->stack_adjust);
if (SIGNED_FIT8(-as->stack_adjust)) {
asm_xtensa_op_addi(as, ASM_XTENSA_REG_A1, ASM_XTENSA_REG_A1, -as->stack_adjust);
} else {
asm_xtensa_op_movi(as, ASM_XTENSA_REG_A9, as->stack_adjust);
asm_xtensa_op_sub(as, ASM_XTENSA_REG_A1, ASM_XTENSA_REG_A1, ASM_XTENSA_REG_A9);
}

// save return value (a0) and callee-save registers (a12, a13, a14)
asm_xtensa_op_s32i_n(as, ASM_XTENSA_REG_A0, ASM_XTENSA_REG_A1, 0);
Expand All @@ -86,7 +91,13 @@ void asm_xtensa_exit(asm_xtensa_t *as) {
asm_xtensa_op_l32i_n(as, ASM_XTENSA_REG_A0, ASM_XTENSA_REG_A1, 0);

// restore stack-pointer and return
asm_xtensa_op_addi(as, ASM_XTENSA_REG_A1, ASM_XTENSA_REG_A1, as->stack_adjust);
if (SIGNED_FIT8(as->stack_adjust)) {
asm_xtensa_op_addi(as, ASM_XTENSA_REG_A1, ASM_XTENSA_REG_A1, as->stack_adjust);
} else {
asm_xtensa_op_movi(as, ASM_XTENSA_REG_A9, as->stack_adjust);
asm_xtensa_op_add(as, ASM_XTENSA_REG_A1, ASM_XTENSA_REG_A1, ASM_XTENSA_REG_A9);
}

asm_xtensa_op_ret_n(as);
}

Expand Down

0 comments on commit f7d6108

Please sign in to comment.