pre-Release 6:
SPECIAL 000000 |
rs |
0 00000 |
rd |
1 |
Any other legal hint value |
JALR 001001 |
6 |
5 |
5 |
5 |
1 |
4 |
6 |
Release 6:
SPECIAL 000000 |
rs |
0 00000 |
rd rd != 00000 |
1 |
Any other legal hint value |
JALR 001001 |
6 |
5 |
5 |
5 |
1 |
4 |
6 |
JALR.HB rd, rs |
MIPS32 Release 2 |
Jump and Link Register with Hazard Barrier |
Jump and Link Register with Hazard Barrier
To execute a procedure call to an instruction address in a register and clear all execution and instruction hazards
GPR[rd] = return_addr, PC = GPR[rs], clear execution and instruction hazards
Place the return address link in GPR rd. The return link is the address of the second instruction following the branch, where execution continues after a procedure call.
For processors that do not implement the MIPS16e or microMIPS ISA:
Jump to the effective target address in GPR rs. If the target address is not 4-byte aligned, an Address Error exception will occur when the target address is fetched.
For processors that do implement the MIPS16e or microMIPS ISA:
Jump to the effective target address in GPR rs. Set the ISA Mode bit to the value in GPR rs bit 0. Set bit 0 of the target address to zero. If the target ISA Mode bit is 0 and the target address is not 4-byte aligned, an Address
Error exception will occur when the target instruction is fetched.
In both cases, execute the instruction that follows the jump, in the branch delay slot, before executing the jump itself.
JALR.HB implements a software barrier that resolves all execution and instruction hazards created by Coprocessor 0 state changes (for Release 2 implementations, refer to the SYNCI instruction for additional information on resolving instruction hazards created by writing the instruction stream). The effects of this barrier are seen starting with the instruction fetch and decode of the instruction at the PC to which the JALR.HB instruction jumps. An equivalent barrier is also implemented by the ERET instruction, but that instruction is only available if access to Coprocessor 0 is enabled, whereas JALR.HB is legal in all operating modes.
This instruction clears both execution and instruction hazards. Refer to the EHB instruction description for the method of clearing execution hazards alone.
JALR.HB uses bit 10 of the instruction (the upper bit of the hint field) to denote the hazard barrier operation.
JALR.HB does not clear hazards created by any instruction that is executed in the delay slot of the JALR.HB. Only hazards created by instructions executed before the JALR.HB are cleared by the JALR.HB.
After modifying an instruction stream mapping or writing to the instruction stream, execution of those instructions has UNPREDICTABLE behavior until the instruction hazard has been cleared with JALR.HB, JR.HB, ERET, or
DERET. Further, the operation is UNPREDICTABLE if the mapping of the current instruction stream is modified.
Control Transfer Instructions (CTIs) should not be placed in branch delay slots or Release 6 forbidden slots. CTIs
include all branches and jumps, NAL, ERET, ERETNC, DERET, WAIT, and PAUSE.
Pre-Release 6: Processor operation is UNPREDICTABLE if a control transfer instruction (CTI) is placed in the delay slot of a branch or jump.
Release 6: If a control transfer instruction (CTI) is executed in the delay slot of a branch or jump, Release 6 implementations are required to signal a Reserved Instruction exception.
Jump-and-Link Restartability: Register specifiers rs and rd must not be equal, because such an instruction does not
have the same effect when re-executed. The result of executing such an instruction is UNPREDICTABLE. This restriction permits an exception handler to resume execution by re-executing the branch when an exception occurs in the delay slot.
Restrictions Related to Multiple Instruction Sets: This instruction can change the active instruction set, if more than
one instruction set is implemented.
If only one instruction set is implemented, then the effective target address must obey the alignment rules of the instruction set. If multiple instruction sets are implemented, the effective target address must obey the alignment rules of the intended instruction set of the target address as specified by the bit 0 or GPR rs.
For processors that do not implement the microMIPS32/64 ISA, the effective target address in GPR rs must be naturally-aligned. For processors that do not implement the MIPS16 ASE nor microMIPS32/64 ISA, if either of the two least-significant bits are not zero, an Address Error exception occurs when the branch target is subsequently fetched as an instruction.
For processors that do implement the MIPS16 ASE or microMIPS32/64 ISA, if bit 0 is zero and bit 1 is one, an
Address Error exception occurs when the jump target is subsequently fetched as an instruction.
Release 6 maps JR and JR.HB to JALR and JALR.HB with rd = 0:
Pre-Release 6, JR.HB and JALR.HB were distinct instructions, both with primary opcode SPECIAL, but with distinct function codes.
Release 6: JR.HB is defined to be JALR.HB with the destination register specifier rd set to 0. The primary opcode and function field are the same for JR.HB and JALR.HB. The pre-Release 6 instruction encoding for JR.HB is removed in Release 6.
Release 6 assemblers should accept the JR and JR.HB mnemonics, mapping them to the Release 6 instruction encodings.
I: temp = GPR[rs] GPR[rd] = PC + 8 I+1:if (Config3ISA = 0) and (Config1CA = 0) then PC = temp else PC = tempGPRLEN-1..1 || 0 ISAMode = temp0 endif ClearHazards()
None
This branch-and-link instruction can select a register for the return link; other link instructions use GPR 31. The default register for GPR rd, if omitted in the assembly language instruction, is GPR 31.
Release 6 JR.HB rs is implemented as JALR.HBr0,rs. For example, as JALR.HB with the destination set to the zero register, r0.
This instruction implements the final step in clearing execution and instruction hazards before execution continues. A hazard is created when a Coprocessor 0 or TLB write affects execution or the mapping of the instruction stream, or after a write to the instruction stream. When such a situation exists, software must explicitly indicate to hardware that the hazard should be cleared. Execution hazards alone can be cleared with the EHB instruction. Instruction hazards can only be cleared with a JR.HB, JALR.HB, or ERET instruction. These instructions cause hardware to clear the hazard before the instruction at the target of the jump is fetched. Note that because these instructions are encoded as jumps, the process of clearing an instruction hazard can often be included as part of a call (JALR) or return (JR) sequence, by simply replacing the original instructions with the HB equivalent.
Example: Clearing hazards due to an ASID change
/* * Code used to modify ASID and call a routine with the new * mapping established. * * a0 = New ASID to establish * a1 = Address of the routine to call */ mfc0 v0, C0_EntryHi /* Read current ASID */ li v1, ~M_EntryHiASID /* Get negative mask for field */ and v0, v0, v1 /* Clear out current ASID value */ or v0, v0, a0 /* OR in new ASID value */ mtc0 v0, C0_EntryHi /* Rewrite EntryHi with new ASID */ jalr.hb a1 /* Call routine, clearing the hazard */