On Sun, Jul 15, 2018 at 8:38 AM, b little <
ror...@gmail.com> wrote:
> I'm trying to rewrite the ecall with a jump instruction to run some other
> subroutine and then return back.
> I need a register to store the address of the ecall so that the subroutine
> could jump back to the position of the old ecall.
> Hence I need a register that can be overwritten, so I thought I could write
> to register a2-a6, since if they are caller saved registers then they will
> be deprecated after the ecall.
An ecall is not the same as a function call in this respect. All
registers must be saved and restored by the OS, so there are no free
caller-saved registers at this point. The only register modified by a
syscall is a0, because this is where the syscall return value is
stored. But since this is also an argument passing register, you
can't put anything in a0 before the syscall.
Depending on register allocation, there might be an available register
at this point, but you would have to disassemble the function code and
track register lifetimes to determine if there is a free register,
which might be more work than you want to do, and there is no
guarantee that there will be a free register to find.
You can perhaps allocate some stack space, store a register on the
stack, use it for the jump address, and then reload the register value
and deallocate the temp stack space when done.
Jim