mem

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: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrAlign = 1 << iota // misaligned read/write
	ErrRead              // can't read this memory
	ErrWrite             // can't write this memory
	ErrExec              // can't read instructions from this memory
	ErrPage              // error with page table translation
	ErrBreak             // break on memory access
	ErrEmpty             // no memory at this physical address
)

Memory error bits.

View Source
const AttrRW = AttrR | AttrW

AttrRW = read/write

View Source
const AttrRWM = AttrR | AttrW | AttrM

AttrRWM = read/write/misaligned

View Source
const AttrRWX = AttrR | AttrW | AttrX

AttrRWX = read/write/execute

View Source
const AttrRX = AttrR | AttrX

AttrRX = read/execute

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute uint

Attribute is a bit mask of memory access attributes.

const (
	AttrR Attribute = 1 << iota // read
	AttrW                       // write
	AttrX                       // execute
	AttrM                       // misaligned access
)

Attribute values.

func AttrArg

func AttrArg(arg string) (Attribute, error)

AttrArg converts an attribute argument string to an attribute bitmap value.

func (Attribute) String

func (a Attribute) String() string

type BreakPoint

type BreakPoint struct {
	Name   string    // breakpoint name
	Addr   uint      // address for trigger
	Access Attribute // access for trigger
	// contains filtered or unexported fields
}

BreakPoint stores the information for a memory breakpoint.

func (*BreakPoint) String

func (mon *BreakPoint) String() string

type Error

type Error struct {
	Type uint      // bitmap of memory errors
	Ex   csr.ECode // exception code
	Addr uint      // memory address causing the error
	Name string    // section name for the address
}

Error is a memory acccess error.

func (*Error) Error

func (e *Error) Error() string

type Memory

type Memory struct {
	Entry uint64 // entry point from ELF
	// contains filtered or unexported fields
}

Memory is emulated target memory.

func NewMem32

func NewMem32(csr *csr.State, empty Attribute) *Memory

NewMem32 returns memory with a 32-bit address bus.

func NewMem64

func NewMem64(csr *csr.State, empty Attribute) *Memory

NewMem64 returns memory with a 64-bit address bus.

func (*Memory) Add

func (m *Memory) Add(r Region)

Add a memory region to the memory.

func (*Memory) AddBreakPoint

func (m *Memory) AddBreakPoint(name string, addr uint, attr Attribute, cond bpFunc)

AddBreakPoint adds a break point.

func (*Memory) AddBreakPointByName

func (m *Memory) AddBreakPointByName(name string, attr Attribute, cond bpFunc) error

AddBreakPointByName adds a break point by symbol name.

func (*Memory) AddSymbol

func (m *Memory) AddSymbol(s string, adr, size uint) error

AddSymbol adds a symbol to the symbol table.

func (*Memory) AddrArg

func (m *Memory) AddrArg(arg string) (uint, error)

AddrArg converts an address argument to an address value.

func (*Memory) AddrStr

func (m *Memory) AddrStr(addr uint) string

AddrStr returns a string for the address.

func (*Memory) Display

func (m *Memory) Display(adr, size, width uint, vm bool) string

Display returns a string for a contiguous region of memory.

func (*Memory) DisplayBreakPoints

func (m *Memory) DisplayBreakPoints() string

DisplayBreakPoints displays a string for the memory break points.

func (*Memory) GetBreak

func (m *Memory) GetBreak() error

GetBreak returned (and resets) any pending breakpoint.

func (*Memory) GetSectionName

func (m *Memory) GetSectionName(adr uint) string

GetSectionName returns the name of the memory section containing the address.

func (*Memory) LoadELF

func (m *Memory) LoadELF(filename string, class elf.Class) (string, error)

LoadELF loads an ELF file to memory.

func (*Memory) Map

func (m *Memory) Map() string

Map returns a memory map display string.

func (*Memory) PageTableWalk

func (m *Memory) PageTableWalk(va uint, mode csr.Mode, attr Attribute) string

PageTableWalk returns a string annotating the va->pa page table walk.

func (*Memory) Rd16

func (m *Memory) Rd16(va uint) (uint16, error)

Rd16 reads a 16-bit data value from memory.

func (*Memory) Rd16Phys

func (m *Memory) Rd16Phys(pa uint) (uint16, error)

Rd16Phys reads a 16-bit data value from memory.

func (*Memory) Rd32

func (m *Memory) Rd32(va uint) (uint32, error)

Rd32 reads a 32-bit data value from memory.

func (*Memory) Rd32Phys

func (m *Memory) Rd32Phys(pa uint) (uint32, error)

Rd32Phys reads a 32-bit data value from memory.

func (*Memory) Rd64

func (m *Memory) Rd64(va uint) (uint64, error)

Rd64 reads a 64-bit data value from memory.

func (*Memory) Rd64Phys

func (m *Memory) Rd64Phys(pa uint) (uint64, error)

Rd64Phys reads a 64-bit data value from memory.

func (*Memory) Rd8

func (m *Memory) Rd8(va uint) (uint8, error)

Rd8 reads an 8-bit data value from memory.

func (*Memory) Rd8Phys

func (m *Memory) Rd8Phys(pa uint) (uint8, error)

Rd8Phys reads an 8-bit data value from memory.

func (*Memory) RdBuf

func (m *Memory) RdBuf(addr, n, width uint, vm bool) []uint

RdBuf reads a buffer of data from memory.

func (*Memory) RdIns

func (m *Memory) RdIns(va uint) (uint, error)

RdIns reads a 32-bit instruction from memory.

func (*Memory) RdInsPhys

func (m *Memory) RdInsPhys(pa uint) (uint, error)

RdInsPhys reads a 32-bit instruction from memory.

func (*Memory) SetAttr

func (m *Memory) SetAttr(name string, attr Attribute) error

SetAttr sets the attributes of a named region.

func (*Memory) SymbolByAddress

func (m *Memory) SymbolByAddress(adr uint) *Symbol

SymbolByAddress returns a symbol for the memory address.

func (*Memory) SymbolByName

func (m *Memory) SymbolByName(s string) *Symbol

SymbolByName returns the symbol for a symbol name.

func (*Memory) SymbolGetAddress

func (m *Memory) SymbolGetAddress(s string) (uint, error)

SymbolGetAddress returns the symbol address for a symbol name.

func (*Memory) Symbols

func (m *Memory) Symbols() string

Symbols returns an address sorted string of memory symbols.

func (*Memory) Wr16

func (m *Memory) Wr16(va uint, val uint16) error

Wr16 writes a 16-bit data value to memory.

func (*Memory) Wr16Phys

func (m *Memory) Wr16Phys(pa uint, val uint16) error

Wr16Phys writes a 16-bit data value to memory.

func (*Memory) Wr32

func (m *Memory) Wr32(va uint, val uint32) error

Wr32 writes a 32-bit data value to memory.

func (*Memory) Wr32Phys

func (m *Memory) Wr32Phys(pa uint, val uint32) error

Wr32Phys writes a 32-bit data value to memory.

func (*Memory) Wr64

func (m *Memory) Wr64(va uint, val uint64) error

Wr64 writes a 64-bit data value to memory.

func (*Memory) Wr64Phys

func (m *Memory) Wr64Phys(pa uint, val uint64) error

Wr64Phys writes a 64-bit data value to memory.

func (*Memory) Wr8

func (m *Memory) Wr8(va uint, val uint8) error

Wr8 writes an 8-bit data value to memory.

func (*Memory) Wr8Phys

func (m *Memory) Wr8Phys(pa uint, val uint8) error

Wr8Phys writes an 8-bit data value to memory.

type Region

type Region interface {
	Info() *RegionInfo
	SetAttr(attr Attribute)
	RdIns(adr uint) (uint, error)
	Rd64(adr uint) (uint64, error)
	Rd32(adr uint) (uint32, error)
	Rd16(adr uint) (uint16, error)
	Rd8(adr uint) (uint8, error)
	Wr64(adr uint, val uint64) error
	Wr32(adr uint, val uint32) error
	Wr16(adr uint, val uint16) error
	Wr8(adr uint, val uint8) error
	In(adr, size uint) bool
}

Region is an interface to a region of memory.

type RegionInfo

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

RegionInfo contains information for the memory region.

type Section

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

Section is a contiguous region of real memory.

func NewSection

func NewSection(name string, start, size uint, attr Attribute) *Section

NewSection allocates and returns a memory chunk.

func (*Section) In

func (m *Section) In(adr, size uint) bool

In returns true if the adr, size is entirely within the memory chunk.

func (*Section) Info

func (m *Section) Info() *RegionInfo

Info returns the information for this region.

func (*Section) Rd16

func (m *Section) Rd16(adr uint) (uint16, error)

Rd16 reads a 16-bit data value from memory.

func (*Section) Rd32

func (m *Section) Rd32(adr uint) (uint32, error)

Rd32 reads a 32-bit data value from memory.

func (*Section) Rd64

func (m *Section) Rd64(adr uint) (uint64, error)

Rd64 reads a 64-bit data value from memory.

func (*Section) Rd8

func (m *Section) Rd8(adr uint) (uint8, error)

Rd8 reads an 8-bit data value from memory.

func (*Section) RdIns

func (m *Section) RdIns(adr uint) (uint, error)

RdIns reads a 32-bit instruction from memory.

func (*Section) SetAttr

func (m *Section) SetAttr(attr Attribute)

SetAttr sets the attributes for this memory section.

func (*Section) Wr16

func (m *Section) Wr16(adr uint, val uint16) error

Wr16 writes a 16-bit data value to memory.

func (*Section) Wr32

func (m *Section) Wr32(adr uint, val uint32) error

Wr32 writes a 32-bit data value to memory.

func (*Section) Wr64

func (m *Section) Wr64(adr uint, val uint64) error

Wr64 writes a 64-bit data value to memory.

func (*Section) Wr8

func (m *Section) Wr8(adr uint, val uint8) error

Wr8 writes an 8-bit data value to memory.

type Symbol

type Symbol struct {
	Name string
	Addr uint
	Size uint
}

Symbol is a memory symbol.

Jump to

Keyboard shortcuts

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