feat(asm): encode the riscv64 privileged instructions
Assisted-by: GLM 5.3 Flash
This commit is contained in:
1 parent
778c297214
commit
82e8919208
2 files changed
+83
-1
No files matched your search
@@ -7,6 +7,8 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -785,6 +787,50 @@ TEXT ·sys(SB), NOSPLIT, $0
|
||||
}
|
||||
}
|
||||
|
||||
// TestRISCV_privilegedWords pins the privileged ISA slice. The toolchain's
|
||||
// object table carries the encodings (its assembler accepts no mnemonic for
|
||||
// them), so the golden vectors come from the privileged and debug
|
||||
// specifications: SFENCEVMA X10, X11 is 0x12b50073, SRET 0x10200073,
|
||||
// MRET 0x30200073, WFI 0x10500073 and DRET 0x7b200073.
|
||||
func TestRISCV_privilegedWords(t *testing.T) {
|
||||
fn := firstTextRISCV(t, `#include "textflag.h"
|
||||
TEXT ·priv(SB), NOSPLIT, $0
|
||||
SFENCEVMA X10, X11
|
||||
SRET
|
||||
MRET
|
||||
WFI
|
||||
DRET
|
||||
RET
|
||||
`)
|
||||
code := assembleRISCVHelper(t, fn)
|
||||
riscvWants(t, code,
|
||||
0x12B50073, // sfence.vma x10, x11
|
||||
0x10200073, // sret
|
||||
0x30200073, // mret
|
||||
0x10500073, // wfi
|
||||
0x7B200073, // dret
|
||||
)
|
||||
}
|
||||
|
||||
// TestRISCV_privilegedAliases checks the supervisor spellings SCALL and
|
||||
// SBREAK against the toolchain: both alias ECALL and EBREAK and must come
|
||||
// out byte-identical.
|
||||
func TestRISCV_privilegedAliases(t *testing.T) {
|
||||
src := `#include "textflag.h"
|
||||
|
||||
TEXT ·alias(SB), NOSPLIT, $0
|
||||
SCALL
|
||||
SBREAK
|
||||
RET
|
||||
`
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, "alias_riscv64.s")
|
||||
if err := os.WriteFile(path, []byte(src), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assertRISCVDifferential(t, path, src, "alias")
|
||||
}
|
||||
|
||||
func TestRISCV_MOV_sym_FP(t *testing.T) {
|
||||
// MOV $sym(FP), rd lowers to the frame-adjusted ADDI against SP: the
|
||||
// toolchain's argframe spelling. A zero frame leaves the offset at the
|
||||
|
||||
Reference in new issue
Block a user