pulp-platform / pulp-riscv-gnu-toolchain

Other
68 stars 50 forks source link

Potential GP_REG t6 (x31) prologue/epilogue save to stack issue in pulp-riscv-gcc/gcc/config/riscv/riscv.c #32

Open JamInJar opened 2 years ago

JamInJar commented 2 years ago

Hi, There might be a minor issue related to prologue and epilogue GP registers saving:

Context

I was trying to remove the limitation related to the ISRs regarding functions calls, that is to say allowing such calls at my own risk. I reasoned that I should save all caller-saved regs instead on simply the ones used by the ISR. I managed to do so but was a bit puzzled as t6 (x31) did not appear as part of the regs saved to the stack during my ISR prologue (and respectively retrieved from it during the epilogue).

Issue

I found at lines 4233 (riscv_for_each_saved_reg), 4365 (riscv_adjust_lib_call_cfi_prologue) and 4506 (riscv_adjust_lib_call_cfi_epilogue) a "for" loop that might contain a typo: for (int regno = GP_REG_FIRST; regno <= GP_REG_LAST-1; regno++)

Trial

I did not know if it was done purposefully but anyway made the following modification: for (int regno = GP_REG_FIRST; regno <= GP_REG_LAST; regno++) This time t6 was saved on the stack.

Thank you !