122 lines
3.2 KiB
Go
122 lines
3.2 KiB
Go
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
|||
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
||
|
|
|
||
|
|
//go:build freebsd && riscv64
|
||
|
|
|
||
|
|
package debug
|
||
|
|
|
||
|
|
import "fmt"
|
||
|
|
|
||
|
|
func printRegs(regs *Regs, codeBase, funcOff uint64) {
|
||
|
|
fmt.Printf(" PC = %#016x (func+%#x)\n", regs.PC, regs.PC-codeBase-funcOff)
|
||
|
|
fmt.Printf(" SP = %#016x FP = %#016x\n", regs.Sp, regs.S0)
|
||
|
|
fmt.Printf(" RA = %#016x\n", regs.Ra)
|
||
|
|
fmt.Printf(" A0 = %#016x A1 = %#016x\n", regs.A0, regs.A1)
|
||
|
|
fmt.Printf(" A2 = %#016x A3 = %#016x\n", regs.A2, regs.A3)
|
||
|
|
fmt.Printf(" A4 = %#016x A5 = %#016x\n", regs.A4, regs.A5)
|
||
|
|
fmt.Printf(" A6 = %#016x A7 = %#016x\n", regs.A6, regs.A7)
|
||
|
|
fmt.Printf(" T0 = %#016x T1 = %#016x\n", regs.T0, regs.T1)
|
||
|
|
fmt.Printf(" T2 = %#016x T3 = %#016x\n", regs.T2, regs.T3)
|
||
|
|
fmt.Printf(" T4 = %#016x T5 = %#016x\n", regs.T4, regs.T5)
|
||
|
|
fmt.Printf(" T6 = %#016x\n", regs.T6)
|
||
|
|
fmt.Printf(" S1 = %#016x S2 = %#016x\n", regs.S1, regs.S2)
|
||
|
|
fmt.Printf(" S3 = %#016x S4 = %#016x\n", regs.S3, regs.S4)
|
||
|
|
fmt.Printf(" S5 = %#016x S6 = %#016x\n", regs.S5, regs.S6)
|
||
|
|
fmt.Printf(" S7 = %#016x S8 = %#016x\n", regs.S7, regs.S8)
|
||
|
|
fmt.Printf(" S9 = %#016x S10 = %#016x\n", regs.S9, regs.S10)
|
||
|
|
fmt.Printf(" S11 = %#016x\n", regs.S11)
|
||
|
|
}
|
||
|
|
|
||
|
|
func printVectorRegs(v *VectorRegs) {
|
||
|
|
fmt.Println("\n FP registers (F0-F31):")
|
||
|
|
for i := 0; i < 32; i += 2 {
|
||
|
|
fmt.Printf(" F%-2d = %#018x F%-2d = %#018x\n", i, v.F[i], i+1, v.F[i+1])
|
||
|
|
}
|
||
|
|
fmt.Printf(" FCSR = %#x\n", v.FCSR)
|
||
|
|
}
|
||
|
|
|
||
|
|
// SetReg modifies a register value in the debuggee.
|
||
|
|
func (s *Session) SetReg(name string, value uint64) error {
|
||
|
|
regs, err := s.GetRegs()
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
switch name {
|
||
|
|
case "pc":
|
||
|
|
regs.PC = value
|
||
|
|
case "ra", "x1":
|
||
|
|
regs.Ra = value
|
||
|
|
case "sp", "x2":
|
||
|
|
regs.Sp = value
|
||
|
|
case "gp", "x3":
|
||
|
|
regs.Gp = value
|
||
|
|
case "tp", "x4":
|
||
|
|
regs.Tp = value
|
||
|
|
case "t0", "x5":
|
||
|
|
regs.T0 = value
|
||
|
|
case "t1", "x6":
|
||
|
|
regs.T1 = value
|
||
|
|
case "t2", "x7":
|
||
|
|
regs.T2 = value
|
||
|
|
case "s0", "fp", "x8":
|
||
|
|
regs.S0 = value
|
||
|
|
case "s1", "x9":
|
||
|
|
regs.S1 = value
|
||
|
|
case "a0", "x10":
|
||
|
|
regs.A0 = value
|
||
|
|
case "a1", "x11":
|
||
|
|
regs.A1 = value
|
||
|
|
case "a2", "x12":
|
||
|
|
regs.A2 = value
|
||
|
|
case "a3", "x13":
|
||
|
|
regs.A3 = value
|
||
|
|
case "a4", "x14":
|
||
|
|
regs.A4 = value
|
||
|
|
case "a5", "x15":
|
||
|
|
regs.A5 = value
|
||
|
|
case "a6", "x16":
|
||
|
|
regs.A6 = value
|
||
|
|
case "a7", "x17":
|
||
|
|
regs.A7 = value
|
||
|
|
case "s2", "x18":
|
||
|
|
regs.S2 = value
|
||
|
|
case "s3", "x19":
|
||
|
|
regs.S3 = value
|
||
|
|
case "s4", "x20":
|
||
|
|
regs.S4 = value
|
||
|
|
case "s5", "x21":
|
||
|
|
regs.S5 = value
|
||
|
|
case "s6", "x22":
|
||
|
|
regs.S6 = value
|
||
|
|
case "s7", "x23":
|
||
|
|
regs.S7 = value
|
||
|
|
case "s8", "x24":
|
||
|
|
regs.S8 = value
|
||
|
|
case "s9", "x25":
|
||
|
|
regs.S9 = value
|
||
|
|
case "s10", "x26":
|
||
|
|
regs.S10 = value
|
||
|
|
case "s11", "x27":
|
||
|
|
regs.S11 = value
|
||
|
|
case "t3", "x28":
|
||
|
|
regs.T3 = value
|
||
|
|
case "t4", "x29":
|
||
|
|
regs.T4 = value
|
||
|
|
case "t5", "x30":
|
||
|
|
regs.T5 = value
|
||
|
|
case "t6", "x31":
|
||
|
|
regs.T6 = value
|
||
|
|
default:
|
||
|
|
return fmt.Errorf("debug: unknown register %q", name)
|
||
|
|
}
|
||
|
|
return s.SetRegs(®s)
|
||
|
|
}
|
||
|
|
|
||
|
|
// archReturnAddr reads the return address from RA (riscv64 convention).
|
||
|
|
func archReturnAddr(s *Session, regs *Regs) (uint64, error) {
|
||
|
|
return regs.Ra, nil
|
||
|
|
}
|
||
|
|
|
||
|
|
// archSPLabel returns the SP register name for display.
|
||
|
|
func archSPLabel() string { return "SP" }
|