fix(asm): correct RISC-V frame layout and RVC encodings
Assisted-by: GLM 5.2
This commit is contained in:
@@ -40,8 +40,8 @@ DATA answer<>+0(SB)/8, $42
|
||||
t.Fatalf("AssembleFileRISCV: %v", err)
|
||||
}
|
||||
fn := img.Funcs[0]
|
||||
if fn.Size != 26 {
|
||||
t.Fatalf("function size = %d, want 26", fn.Size)
|
||||
if fn.Size != 28 {
|
||||
t.Fatalf("function size = %d, want 28", fn.Size)
|
||||
}
|
||||
if len(fn.Relocs) != 3 {
|
||||
t.Fatalf("relocs = %d, want 3", len(fn.Relocs))
|
||||
@@ -95,14 +95,15 @@ DATA answer<>+0(SB)/8, $42
|
||||
}
|
||||
|
||||
// The function code: three AUIPC+second-instruction pairs with zero
|
||||
// immediates, then the compressed return.
|
||||
// immediates, then the uncompressed JALR X0, 0(X1) the toolchain emits
|
||||
// for RET.
|
||||
code := img.Code[fn.Offset : fn.Offset+fn.Size]
|
||||
want := append(wordLE(riscvUType(riscvEnc{0x17, 0x0, 0x00}, 10, 0)), wordLE(riscvIType(riscvEnc{0x13, 0x0, 0x00}, 10, 10, 0))...)
|
||||
want = append(want, wordLE(riscvUType(riscvEnc{0x17, 0x0, 0x00}, 11, 0))...)
|
||||
want = append(want, wordLE(riscvIType(riscvEnc{0x03, 0x3, 0x00}, 11, 11, 0))...)
|
||||
want = append(want, wordLE(riscvUType(riscvEnc{0x17, 0x0, 0x00}, 31, 0))...)
|
||||
want = append(want, wordLE(riscvSType(riscvEnc{0x23, 0x3, 0x00}, 31, 12, 0))...)
|
||||
want = append(want, 0x82, 0x80) // C.JR ra
|
||||
want = append(want, 0x67, 0x80, 0x00, 0x00) // JALR X0, 0(X1)
|
||||
if !bytes.Equal(code, want) {
|
||||
t.Errorf("code = % x\nwant % x", code, want)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user