Files
gasm-sdk/disasm/arm64_naming_test.go
T
petrbalvin 0f6e008c9a feat(disasm): name the arm64 words arm64asm refuses
arm64asm rejects three exception-space words the toolchain's corpus
assembles: the hypervisor call HVC, the secure monitor call SMC and
the speculation barrier SB.  The supplementary naming table reads
the raw word in the error branch and renders the corpus spellings;
the corpus rows are pinned in the parity fixture and the boundary
test holds the unallocated neighbours on the placeholder.

Assisted-by: GLM 5.3
2026-10-07 13:49:58 +02:00

68 lines
2.1 KiB
Go

// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
// SPDX-License-Identifier: BSD-3-Clause
package disasm
import (
"testing"
"sourcedock.dev/petrbalvin/gasm-sdk/arch"
)
// TestRejectedNaming pins the supplementary arm64 naming table over the
// corpus rows whose encodings the decoder refuses: every row's bytes are
// the corpus's own expected-encoding comments (machine-checked by the
// toolchain's assembler test suite) and every text is the corpus's own
// spelling.
func TestRejectedNaming(t *testing.T) {
for _, tt := range []struct {
code []byte
text string
}{
// arm64enc.s: HVC $61428 // 82fe1dd4 and SMC $37977 // 238b12d4.
{[]byte{0x82, 0xfe, 0x1d, 0xd4}, "HVC $61428"},
{[]byte{0x23, 0x8b, 0x12, 0xd4}, "SMC $37977"},
// arm64enc.s: SB // ff3003d5.
{[]byte{0xff, 0x30, 0x03, 0xd5}, "SB"},
} {
ins, err := Decode(arch.ARM64, tt.code, 0)
if err != nil {
t.Errorf("% x: %v", tt.code, err)
continue
}
if ins.Text != tt.text || ins.Len != len(tt.code) {
t.Errorf("% x: %q (%d bytes), want %q (%d)",
tt.code, ins.Text, ins.Len, tt.text, len(tt.code))
}
}
}
// TestRejectedNamingBoundaries guards the table's edges: the exception
// space shapes the corpus does not spell keep the placeholder, and the
// neighbours the decoder names itself never reach the table.
func TestRejectedNamingBoundaries(t *testing.T) {
for _, tt := range []struct {
code []byte
text string
}{
// The unallocated corners of the same opc group (op2 00000,
// 00100 and 11000), which the corpus does not spell.
{[]byte{0x00, 0x00, 0x00, 0xd4}, "???"},
{[]byte{0x04, 0x00, 0x00, 0xd4}, "???"},
{[]byte{0x60, 0x00, 0x00, 0xd4}, "???"},
// BRK and HLT sit in the same space one opc step away and the
// decoder names them itself.
{[]byte{0x00, 0x00, 0x20, 0xd4}, "BRK $0"},
{[]byte{0x00, 0x00, 0x40, 0xd4}, "HLT $0"},
} {
ins, err := Decode(arch.ARM64, tt.code, 0)
if err != nil {
t.Errorf("% x: %v", tt.code, err)
continue
}
if ins.Text != tt.text {
t.Errorf("% x: %q, want %q", tt.code, ins.Text, tt.text)
}
}
}