csr

package
v0.0.0-...-7a30345 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrTodo      = 1 << iota // csr not implemented
	ErrPrivilege             // insufficient privilege
	ErrReadOnly              // trying to write a read-only register
	ErrNoRead                // no read function (todo)
	ErrNoWrite               // no write function (todo)
)

CSR error bits.

View Source
const (
	FFLAGS  = 0x001
	FRM     = 0x002
	FCSR    = 0x003
	SSTATUS = 0x100
	SEDELEG = 0x102
	SIDELEG = 0x103
	MSTATUS = 0x300
	MEDELEG = 0x302
	MIDELEG = 0x303
	MTVEC   = 0x305
	MEPC    = 0x341
	MCAUSE  = 0x342
	MTVAL   = 0x343
)

Register numbers for specific CSRs.

View Source
const (
	IsaExtA = (1 << iota) // Atomic extension
	IsaExtB               // Tentatively reserved for Bit-Manipulation extension
	IsaExtC               // Compressed extension
	IsaExtD               // Double-precision floating-point extension
	IsaExtE               // RV32E base ISA
	IsaExtF               // Single-precision floating-point extension
	IsaExtG               // Additional standard extensions present
	IsaExtH               // Hypervisor extension
	IsaExtI               // RV32I/64I/128I base ISA
	IsaExtJ               // Tentatively reserved for Dynamically Translated Languages extension
	IsaExtK               // Reserved
	IsaExtL               // Tentatively reserved for Decimal Floating-Point extension
	IsaExtM               // Integer Multiply/Divide extension
	IsaExtN               // User-level interrupts supported
	IsaExtO               // Reserved
	IsaExtP               // Tentatively reserved for Packed-SIMD extension
	IsaExtQ               // Quad-precision floating-point extension
	IsaExtR               // Reserved
	IsaExtS               // Supervisor mode implemented
	IsaExtT               // Tentatively reserved for Transactional Memory extension
	IsaExtU               // User mode implemented
	IsaExtV               // Tentatively reserved for Vector extension
	IsaExtW               // Reserved
	IsaExtX               // Non-standard extensions present
	IsaExtY               // Reserved
	IsaExtZ               // Reserved
)

ISA Extension Bitmap

Variables

This section is empty.

Functions

func DisplaySATP

func DisplaySATP(s *State) string

DisplaySATP returns a display string for the SATP register.

func Name

func Name(reg uint) string

Name returns the name of a given CSR.

Types

type ECode

type ECode uint

ECode is a RISC-V exception code.

const (
	ExInsAddrMisaligned         ECode = 0  // Instruction address misaligned
	ExInsAccessFault            ECode = 1  // Instruction access fault
	ExInsIllegal                ECode = 2  // Illegal instruction
	ExBreakpoint                ECode = 3  // Breakpoint
	ExLoadAddrMisaligned        ECode = 4  // Load address misaligned
	ExLoadAccessFault           ECode = 5  // Load access fault
	ExStoreAddrMisaligned       ECode = 6  // Store/AMO address misaligned
	ExStoreAccessFault          ECode = 7  // Store/AMO access fault
	ExEnvCallFromUserMode       ECode = 8  // Environment call from U-mode
	ExEnvCallFromSupervisorMode ECode = 9  // Environment call from S-mode
	ExUnknown10                 ECode = 10 // unknown 10
	ExEnvCallFromMachineMode    ECode = 11 // Environment call from M-mode
	ExInsPageFault              ECode = 12 // Instruction page fault
	ExLoadPageFault             ECode = 13 // Load page fault
	ExUnknown14                 ECode = 14 // unknown 14
	ExStorePageFault            ECode = 15 // Store/AMO page fault
)

Exception Codes

func (ECode) String

func (n ECode) String() string

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error is a CSR access error.

func (*Error) Error

func (e *Error) Error() string

type ICode

type ICode uint

ICode is a RISC-V interrupt code.

const (
	IntUserSoftware       ICode = 0  // User software interrupt
	IntSupervisorSoftware ICode = 1  // Supervisor software interrupt
	IntMachineSoftware    ICode = 3  // Machine software interrupt
	IntUserTimer          ICode = 4  // User timer interrupt
	IntSupervisorTimer    ICode = 5  // Supervisor timer interrupt
	IntMachineTimer       ICode = 7  // Machine timer interrupt
	IntUserExternal       ICode = 8  // User external interrupt
	IntSupervisorExternal ICode = 9  // Supervisor external interrupt
	IntMachineExternal    ICode = 11 // Machine external interrupt
)

Interrupt Codes

func (ICode) String

func (n ICode) String() string

type Mode

type Mode uint

Mode is the processor mode (user/supervisor/machine).

const (
	ModeU Mode = 0 // user
	ModeS Mode = 1 // supervisor
	ModeM Mode = 3 // machine
)

Modes

func ModeArg

func ModeArg(arg string) (Mode, error)

ModeArg converts a mode argument string to a mode value.

func (Mode) String

func (m Mode) String() string

type State

type State struct {
	// contains filtered or unexported fields
}

State stores the CSR state for the CPU.

func NewState

func NewState(xlen, ext uint) *State

NewState returns a CSR state object.

func (*State) Display

func (s *State) Display() string

Display displays the CSR state.

func (*State) ECALL

func (s *State) ECALL(epc uint64, val uint) uint64

ECALL performs an environment call exception.

func (*State) Exception

func (s *State) Exception(epc uint64, code, val uint, isInterrupt bool) uint64

Exception performs a cpu exception.

func (*State) GetMPP

func (s *State) GetMPP() Mode

GetMPP returns the MPP bits of mstatus.

func (*State) GetMPRV

func (s *State) GetMPRV() bool

GetMPRV returns the MPRV bit of mstatus.

func (*State) GetMXR

func (s *State) GetMXR() bool

GetMXR returns the MXR bit of mstatus.

func (*State) GetMode

func (s *State) GetMode() Mode

GetMode returns the current processor mode.

func (*State) GetPPN

func (s *State) GetPPN() uint

GetPPN returns the physical page number set in the SATP.

func (*State) GetSUM

func (s *State) GetSUM() bool

GetSUM returns the sum bit of mstatus.

func (*State) GetVM

func (s *State) GetVM() VM

GetVM returns the VM mode set in the SATP.

func (*State) IncClockCycles

func (s *State) IncClockCycles(n uint)

IncClockCycles increments the CSR clock cycle counter.

func (*State) IncInstructions

func (s *State) IncInstructions()

IncInstructions increments the CSR instructions retired counter.

func (*State) IsFloatOff

func (s *State) IsFloatOff() bool

IsFloatOff returns true if the floating point has been disabled in mstatus.fs.

func (*State) MRET

func (s *State) MRET() uint

MRET returns from a machine-mode exception.

func (*State) Rd

func (s *State) Rd(reg uint) (uint64, error)

Rd reads from a CSR.

func (*State) Reset

func (s *State) Reset()

Reset resets the state of the CSR sub-system.

func (*State) SRET

func (s *State) SRET() uint

SRET returns from a supervisor-mode exception.

func (*State) URET

func (s *State) URET() uint

URET returns from a user-mode exception.

func (*State) Wr

func (s *State) Wr(reg uint, val uint64) error

Wr writes to a CSR.

type VM

type VM uint

VM is the virtual memory mode.

const (
	Bare VM = iota
	SV32
	SV39
	SV48
	SV57
	SV64
)

Virtual memory mode.

func (VM) String

func (vm VM) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL