The RISC-V specification v2.2 (JAL instruction, page 15) says of the "standard calling convention":
The standard software calling convention uses x1 as the return address register and x5 as an alternate link register.
with the following design comment:
The alternate link register supports calling millicode routines (e.g., those to save and restore registers in compressed code) while preserving the regular return address register.
What is an alternative link register for?
I understand that "link register" is a register to store the pc to jump to on return, and that millicode/microcode are a lower-level instruction format below the ISA level. Is the idea that x5
is used instead of x1
for certain (microcode/millicode) instructions that surround "normal calls" to avoid register shuffling or a spill? Would you have a typical usage example?
It could be helpful to add an explanation of alternate link registers to the Wikipedia article on link registers, which is where I went looking for extra information.