feat(asm): encode indirect JMP and CALL on all four architectures
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -761,3 +761,24 @@ sub:
|
||||
t.Error("expected error for CALL to local label, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
// TestRISCVIndirectBranch pins the indirect branch encodings: JMP (X5) is the
|
||||
// toolchain's JALR X0, 0(X5), and the trampoline form JALR rd, offset(rs1)
|
||||
// takes its destination from the first operand (regression: the base
|
||||
// register was once read as the destination, silently jumping to X0).
|
||||
func TestRISCVIndirectBranch(t *testing.T) {
|
||||
fn := firstTextRISCV(t, `#include "textflag.h"
|
||||
TEXT ·f(SB), NOSPLIT, $0-0
|
||||
JMP (X5)
|
||||
JALR X0, 0(X6)
|
||||
JALR X28, 0(X9)
|
||||
RET
|
||||
`)
|
||||
code := assembleRISCVHelper(t, fn)
|
||||
wantWords(t, code,
|
||||
0x00028067, // jalr x0, 5(x0), 0
|
||||
0x00030067, // jalr x0, 6(x0), 0
|
||||
0x00048e67, // jalr x28, 9(x0), 0
|
||||
0x00008067, // jalr x0, 1(x0), 0 (RET)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user