decoder

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package decoder provides RISC-V instruction decoding methods.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bit12

type Bit12 uint32

Bit12 is part of Func4 and Funct6 fields.

const (
	// Cmv compact move
	Cmv Bit12 = iota
	// Cadd compact add
	Cadd
)
const (
	// RegGroupMid is a group of compact arithmetic register instructions
	RegGroupMid Bit12 = iota
)

type Funct2

type Funct2 uint32

Funct2 determines the operation for some compact instructions

const (
	// Csub compact subtract
	Csub Funct2 = iota
	// Cxor compact Xor
	Cxor
	// Cor compact Or
	Cor
	// Cand compact and
	Cand
)

type Funct3

type Funct3 uint32

Funct3 determines the operation for an instruction

const (
	// Atomic32 denotes a 32-bit atomic instruction.
	Atomic32 Funct3 = 2
	// Atomic64 denotes a 64-bit atomic instruction.
	Atomic64 Funct3 = 3
)
const (
	// Caddi4spn is a add immediate, scaled 4, to SP.
	Caddi4spn Funct3 = iota
	// Cfld compact load float double
	Cfld
	// Clw compact load word
	Clw
	// Cflw compact float load word
	Cflw

	// Cfsd compact float store double
	Cfsd
	// Csw compact store word
	Csw
	// Cfsw compact float store word
	Cfsw
)
const (
	// Caddi compact add immediate
	Caddi Funct3 = iota
	// Cjal compact jump and link
	Cjal
	// Cli compact load immediate.
	Cli
	// Clui compact load upper immediate
	Clui
	// Extend6 designates a funct field that extends to Funct6
	Extend6
	// Cj compact jump
	Cj
	// Cbeqz compact branch equal to zero
	Cbeqz
	// Cbnez compact branch not equal to zero
	Cbnez
)
const (
	// Cslli compact shift left logical
	Cslli Funct3 = iota
	// Cfldsp compact float load double stack pointer
	Cfldsp
	// Clwsp compact load double stack pointer
	Clwsp
	// Cflwsp compact float load word stack pointer
	Cflwsp
	// CMvAdd contains the move and add instructions
	CMvAdd
	// Cfsdsp compact float store double stack pointer
	Cfsdsp
	// Cswsp compact store word stack pointer
	Cswsp
	// Cfswsp compact float store word stack pointer
	Cfswsp
)
const (
	// Beq if equal
	Beq Funct3 = iota
	// Bne not equal
	Bne

	// Blt less than
	Blt
	// Bge greater than or equal
	Bge
	// Bltu less than unsigned
	Bltu
	// Bgeu greater than or equal unsigned
	Bgeu
)
const (
	// Addi add immediate
	Addi Funct3 = iota
	// Slli shift left logical immediate
	Slli
	// Slti set less than immediate
	Slti
	// Sltiu set less than immediate unsigned
	Sltiu
	// Xori xor immediate
	Xori
	// Sr logical and arithmetic
	Sr
	// Ori or immediate
	Ori
	// Andi and immediate
	Andi
)
const (
	// RegDiff is add and sub funct3 for reg-reg operations
	RegDiff Funct3 = iota
	// Sll shift left logical
	Sll
	// Slt set less than
	Slt
	// Sltu set less than unsigned
	Sltu
	// Xor xor
	Xor
	// RegShift denotes shift operations on reg-reg operands
	RegShift
	// Or or
	Or
	// And and
	And
)
const (
	// Lb load byte
	Lb Funct3 = iota
	// Lh load half
	Lh
	// Lw load word
	Lw
	// Ld load double
	Ld
	// Lbu Load byte unsigned
	Lbu
	// Lhu load half unsigned
	Lhu
	// Lwu load word unsigned
	Lwu
)
const (
	// Sb store byte
	Sb Funct3 = iota
	// Sh store half
	Sh
	// Sw store word
	Sw
	// Sd store double
	Sd
)
const (
	// Fence fence
	Fence Funct3 = iota
	// Fencei fencei
	Fencei
)
const (
	// Mul is a multiply instruction and sets the lower bits of the product.
	Mul Funct3 = iota
	// Mulh is a multiply instruction and sets the upper bits of the product.
	Mulh
	// Mulhsu is a multiply instruction, returns upper bits, rs1 signed, rs2
	// unsigned.
	Mulhsu
	// Mulhu is a multiply instruction, returns upper bits, both multiplicands
	// are unsigned.
	Mulhu
	// Div is a divide instruction.
	Div
	// Divu is an unsigned division instruction.
	Divu
	// Rem returns the remainder of division.
	Rem
	// Remu returns the remainder of unsigned division.
	Remu
)
const (
	// Other includes all not CSR instructions
	Other Funct3 = iota
	// Csrrw is the funct value for csrrw
	Csrrw
	// Csrrs is the funct value for csrrs
	Csrrs
	// Csrrc is the funct value for csrrc
	Csrrc

	// Csrrwi is the funct value for csrrwi
	Csrrwi
	// Csrrsi is the funct value for csrrsi
	Csrrsi
	// Csrrci is the funct value for csrrci
	Csrrci
)
const (
	FLoadStore Funct3 = 0x2
)

type Funct5Head

type Funct5Head uint32

Funct5Head determines the operation for an atomic instruction.

const (
	CommonAtomic Funct5Head = iota
	Amoxor
	Amoor
	Amoand
	Amomin
	Amomax
	Amominu
	Amomaxu
)

type Funct5Tail

type Funct5Tail uint32

Funct5Tail determines the operation for an atomic instruction.

const (
	ArithAtomic Funct5Tail = iota
	Amoswap
	Lr
	Sc
)

type Funct6Tail

type Funct6Tail uint32

Funct6Tail is a funct field extension for the Funct6 field

const (
	// Csrli compact shift right logical immediate
	Csrli Funct6Tail = iota
	// Csrai compact shift right arithmetic immediate
	Csrai
	// Candi compact and immediate
	Candi
	// RegGroupTail is a group of compact arithmetic register instructions
	RegGroupTail
)

type Funct7

type Funct7 uint32

Funct7 determines the operation for an R format instruction

const (
	// Add is an add reg-reg instruction
	Add Funct7 = 0
	// Sub is a sub reg-reg instruction
	Sub Funct7 = 32
	// Srl is a shift right logical reg-reg instruction
	Srl Funct7 = 0
	// Sra is a shift right arithmetic reg-reg instruction
	Sra Funct7 = 32
)
const (
	// MulDiv denotes an M extension instruction.
	MulDiv Funct7 = 1
)

type IDBuilder

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

IDBuilder generates an instruction ID and Mask.

To be used at Vemulator build time. Too slow to use during RISC-V binary emulation.

func (IDBuilder) ID

func (i IDBuilder) ID() uint32

ID returns the generated instruction ID.

func (IDBuilder) Mask

func (i IDBuilder) Mask() uint32

Mask returns the generated instruction mask used for matching instruction words.

func (IDBuilder) WithCBit12

func (i IDBuilder) WithCBit12(bit12 Bit12) IDBuilder

WithCBit12 updates the ID and mask with the specified field.

func (IDBuilder) WithCFunct2

func (i IDBuilder) WithCFunct2(funct2 Funct2) IDBuilder

WithCFunct2 updates the ID and mask with the specified field.

func (IDBuilder) WithCFunct3

func (i IDBuilder) WithCFunct3(funct3 Funct3) IDBuilder

WithCFunct3 updates the ID and mask with the specified field.

func (IDBuilder) WithCFunct6Tail

func (i IDBuilder) WithCFunct6Tail(funct6tail Funct6Tail) IDBuilder

WithCFunct6Tail updates the ID and mask with the specified field.

func (IDBuilder) WithCustom

func (i IDBuilder) WithCustom(match uint32, mask uint32) IDBuilder

WithCustom adds custom match and mask bits.

The match bits should be normalized such that the LSB is zero bit.

func (IDBuilder) WithFunct7

func (i IDBuilder) WithFunct7(funct7 Funct7) IDBuilder

WithFunct7 updates the ID and mask with the specified field.

func (IDBuilder) WithMajOp

func (i IDBuilder) WithMajOp(majOp MajorOpcode) IDBuilder

WithMajOp updates the ID and mask with the specified field.

func (IDBuilder) WithMinOp

func (i IDBuilder) WithMinOp(minOp MinorOpcode) IDBuilder

WithMinOp updates the ID and mask with the specified field.

func (IDBuilder) WithStdFunct3

func (i IDBuilder) WithStdFunct3(funct3 Funct3) IDBuilder

WithStdFunct3 updates the ID and mask with the specified field.

func (IDBuilder) WithStdFunct5Head

func (i IDBuilder) WithStdFunct5Head(funct5Head Funct5Head) IDBuilder

WithStdFunct5Head updates the ID and mask with the specified field.

func (IDBuilder) WithStdFunct5Tail

func (i IDBuilder) WithStdFunct5Tail(funct5Tail Funct5Tail) IDBuilder

WithStdFunct5Tail updates the ID and mask with the specified field.

type Immediate

type Immediate uint32

Immediate represents an integer value in binary

type MajorOpcode

type MajorOpcode uint32

MajorOpcode determines whether the instruction is part of the G designation

const (
	// C0 designates a compact instruction in the C0 space.
	C0 MajorOpcode = iota
	// C1 designates a compact instruction in the C1 space.
	C1
	// C2 designates a compact instruction in the c2 space.
	C2
	// Std designates a full length instruction that is part of the standard ISA.
	Std
)

type MinorOpcode

type MinorOpcode uint32

MinorOpcode determines the format of the given instruction

const (
	// IntRegReg designates an integer register-register instruction
	IntRegReg MinorOpcode = 0xc
	// IntRegImm designates an integer register-immediate instruction
	IntRegImm MinorOpcode = 0x4
	// IntRegReg32 designates an integer register-register instruction in RV64 for a 32-bit operation.
	IntRegReg32 MinorOpcode = 0xe
	// IntRegImm32 designates an integer register-immediate instruction in RV64 for a 32-bit operation.
	IntRegImm32 MinorOpcode = 0x6
	// Load designates a load instruction
	Load MinorOpcode = 0x0
	// Jalr designates a JALR instruction
	Jalr MinorOpcode = 0x19
	// Store designates a store type instruction
	Store MinorOpcode = 0x8
	// Branch desigtnates a branch type instruction
	Branch MinorOpcode = 0x18
	// Lui designates an LUI instruction
	Lui MinorOpcode = 0xd
	// Auipc designates an AUIPC instruction
	Auipc MinorOpcode = 0x5
	// Jal designates a JAL instruction
	Jal MinorOpcode = 0x1b
	// FenceOp designates a fence instruction
	FenceOp MinorOpcode = 0x3
	// Sys designates a system call instruction
	Sys MinorOpcode = 0x1c
	// Atomic designates an atomic instruction
	Atomic MinorOpcode = 0xb
)
const (
	Flw MinorOpcode = 0x1
	Fsw MinorOpcode = 0x9
)

type RawInstruction

type RawInstruction struct {
	BinWord uint32
	MajOp   MajorOpcode
}

RawInstruction enables field extraction from an instruction word

func NewRawInstruction

func NewRawInstruction(bits uint32) RawInstruction

NewRawInstruction assigns the binary word to the structure.

func (RawInstruction) CADDI16Imm

func (r RawInstruction) CADDI16Imm() Immediate

CADDI16Imm returns the CADDI16SP immediate.

func (RawInstruction) CADDI4Imm

func (r RawInstruction) CADDI4Imm() Immediate

CADDI4Imm returns the CADDI4SPN immediate.

func (RawInstruction) CAFunct2

func (r RawInstruction) CAFunct2() Funct2

CAFunct2 returns the compact funct2 field for the ca-type instructions.

func (RawInstruction) CBFunct2

func (r RawInstruction) CBFunct2() Funct2

CBFunct2 returns the compact funct2 field for cb-type instructions.

func (RawInstruction) CBImm

func (r RawInstruction) CBImm() Immediate

CBImm returns the compact b-type immediate.

func (RawInstruction) CDImm

func (r RawInstruction) CDImm() Immediate

CDImm returns CLD, CFLD, CSD, and CFSD immediate.

func (RawInstruction) CFunct3

func (r RawInstruction) CFunct3() Funct3

CFunct3 returns a compact Funct3 field

func (RawInstruction) CIImm

func (r RawInstruction) CIImm() Immediate

CIImm returns the CLI, CADDI, CSLLI, CSRLI, CSRAI, CANDI, and CADDIW immediate.

func (RawInstruction) CJImm

func (r RawInstruction) CJImm() Immediate

CJImm returns the compact j-type immediate.

func (RawInstruction) CLDSPImm

func (r RawInstruction) CLDSPImm() Immediate

CLDSPImm returns CLDSP or CFLDSP immediate.

func (RawInstruction) CLQSPImm

func (r RawInstruction) CLQSPImm() Immediate

CLQSPImm returns CLQSPImm immediate.

func (RawInstruction) CLUIImm

func (r RawInstruction) CLUIImm() Immediate

CLUIImm returns the CLUI immediate.

func (RawInstruction) CLWSPImm

func (r RawInstruction) CLWSPImm() Immediate

CLWSPImm returns CLWSP or CFLWSP immediate.

func (RawInstruction) CQImm

func (r RawInstruction) CQImm() Immediate

CQImm returns CLQ and CSQ immediate.

func (RawInstruction) CRdRs1

func (r RawInstruction) CRdRs1() RegisterIndex

CRdRs1 returns a compact rd/rs1 field

func (RawInstruction) CRdRs1Short

func (r RawInstruction) CRdRs1Short() RegisterIndex

CRdRs1Short returns the shortened Rd'Rs1' field.

func (RawInstruction) CRdShort

func (r RawInstruction) CRdShort() RegisterIndex

CRdShort returns the compact Rd field.

func (RawInstruction) CRs1

func (r RawInstruction) CRs1() RegisterIndex

CRs1 returns the compact Rs1 field.

func (RawInstruction) CRs2

func (r RawInstruction) CRs2() RegisterIndex

CRs2 returns a compact rs2 field

func (RawInstruction) CRs2Short

func (r RawInstruction) CRs2Short() RegisterIndex

CRs2Short returns the compact short Rs2 field.

func (RawInstruction) CSDSPImm

func (r RawInstruction) CSDSPImm() Immediate

CSDSPImm returns CSDSP or CFSDSP immediate.

func (RawInstruction) CSQSPImm

func (r RawInstruction) CSQSPImm() Immediate

CSQSPImm returns CSQSP immediate.

func (RawInstruction) CSWSPImm

func (r RawInstruction) CSWSPImm() Immediate

CSWSPImm returns CSWSP or CFSWSP immediate.

func (RawInstruction) CWImm

func (r RawInstruction) CWImm() Immediate

CWImm returns CLW, CFLW, CSW, and CFSW immediate.

func (RawInstruction) GetFunct3

func (r RawInstruction) GetFunct3() Funct3

GetFunct3 returns the funct3 field

func (RawInstruction) GetFunct7

func (r RawInstruction) GetFunct7() Funct7

GetFunct7 returns the funct7 field

func (RawInstruction) GetImmediate

func (r RawInstruction) GetImmediate() Immediate

GetImmediate returns the immediate value encoded in the instruction

func (RawInstruction) GetMinorOpcode

func (r RawInstruction) GetMinorOpcode() MinorOpcode

GetMinorOpcode returns the minor opcode for the given instruction

func (RawInstruction) GetRd

func (r RawInstruction) GetRd() RegisterIndex

GetRd returns the rd field for the instruction word

func (RawInstruction) GetRs1

func (r RawInstruction) GetRs1() RegisterIndex

GetRs1 returns the rs1 field

func (RawInstruction) GetRs2

func (r RawInstruction) GetRs2() RegisterIndex

GetRs2 returns the rs2 field

func (RawInstruction) GetRs3

func (r RawInstruction) GetRs3() RegisterIndex

GetRs3 returns the rs2 field

type RegisterIndex

type RegisterIndex uint32

RegisterIndex determines the indexes the register in the register file

type TranslationRegistrationError

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

TranslationRegistrationError indicates that a problem occurred while registering instruction ID to Uop translations in the Decoder.

func NewTransRegError

func NewTransRegError(insn string, id uint32, mask uint32, duplicate bool) TranslationRegistrationError

func (TranslationRegistrationError) Error

Jump to

Keyboard shortcuts

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