2024-11-01 10:54:59 +00:00
|
|
|
package instr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"git.elyanpoujol.fr/elyan/central-arch/pkg/register"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Instr uint32
|
|
|
|
type InstrFormat uint32
|
|
|
|
|
|
|
|
const (
|
2024-11-03 18:38:44 +00:00
|
|
|
A1 InstrFormat = iota
|
|
|
|
A2
|
|
|
|
B1
|
|
|
|
B2
|
2024-11-01 10:54:59 +00:00
|
|
|
C
|
|
|
|
D1
|
|
|
|
D2
|
|
|
|
E
|
|
|
|
)
|
|
|
|
|
2024-11-03 18:38:44 +00:00
|
|
|
var instrFormatNames = [...]string{
|
|
|
|
"A1",
|
|
|
|
"A2",
|
|
|
|
"B1",
|
|
|
|
"B2",
|
|
|
|
"C",
|
|
|
|
"D1",
|
|
|
|
"D2",
|
|
|
|
"E",
|
|
|
|
}
|
2024-11-01 10:54:59 +00:00
|
|
|
|
2024-11-03 18:38:44 +00:00
|
|
|
func (instrf InstrFormat) String() string {
|
|
|
|
if int(instrf) > len(instrFormatNames) {
|
|
|
|
panic("unknown instruction format")
|
2024-11-01 10:54:59 +00:00
|
|
|
}
|
|
|
|
|
2024-11-03 18:38:44 +00:00
|
|
|
return instrFormatNames[instrf]
|
2024-11-01 10:54:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Cond uint32
|
|
|
|
|
|
|
|
const (
|
|
|
|
AL Cond = iota // Always
|
|
|
|
EQ // Equal, Z==1
|
|
|
|
NEQ // Not Equal, Z==0
|
|
|
|
UGE // Unsigned Greater or Equal, C==1
|
|
|
|
CS Cond = iota - 1 // Carry Set, C==1
|
|
|
|
ULT // Unsigned Lower Than, C==0
|
|
|
|
CC Cond = iota - 2 // Carry Clear, C==0
|
|
|
|
NEG // Negative, N==1
|
|
|
|
POS // Positive, N==0
|
|
|
|
VS // oVerflow Set, V==1
|
|
|
|
VC // oVerflow Clear, V==0
|
|
|
|
UGT // Unsigned Greater Than, C==1 && Z==0
|
|
|
|
ULE // Unsigned Lower Than, C==0 && Z==1
|
|
|
|
SGE // Signed Greater or Equal, N==V
|
|
|
|
SLT // Signed Lower Than, N!=V
|
|
|
|
SGT // Signed Greater Than, Z==0 && N==V
|
|
|
|
SLE // Signed Lower or Equal, Z==1 && N!=V
|
|
|
|
)
|
|
|
|
|
2024-11-03 18:38:44 +00:00
|
|
|
var condNames = [...]string{
|
|
|
|
"al",
|
|
|
|
"eq",
|
|
|
|
"neq",
|
|
|
|
"uge",
|
|
|
|
"cs",
|
|
|
|
"ult",
|
|
|
|
"cc",
|
|
|
|
"neg",
|
|
|
|
"pos",
|
|
|
|
"vs",
|
|
|
|
"vc",
|
|
|
|
"ugt",
|
|
|
|
"ule",
|
|
|
|
"sge",
|
|
|
|
"slt",
|
|
|
|
"sgt",
|
|
|
|
"sle",
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cond Cond) String() string {
|
|
|
|
if int(cond) > len(condNames) {
|
|
|
|
panic("unknown instruction condition")
|
|
|
|
}
|
2024-11-01 10:54:59 +00:00
|
|
|
|
2024-11-03 18:38:44 +00:00
|
|
|
return condNames[cond]
|
|
|
|
}
|
|
|
|
|
|
|
|
type InstrFormatter func(*DecodedInstr) string
|
2024-11-01 10:54:59 +00:00
|
|
|
|
|
|
|
type InstrDesc struct {
|
|
|
|
VariantName string
|
|
|
|
Mnemonic string
|
|
|
|
OpCode uint32
|
|
|
|
Format InstrFormat
|
|
|
|
Formatter InstrFormatter
|
|
|
|
}
|
|
|
|
|
|
|
|
type StandardFormatFields struct {
|
|
|
|
Condition Cond
|
|
|
|
Rd register.CpuRegister
|
|
|
|
Rs1 register.CpuRegister
|
|
|
|
Rs2 register.CpuRegister
|
|
|
|
Imm uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
type SubsystemFormatFields struct {
|
|
|
|
Reg register.CpuRegister
|
|
|
|
Sid uint32
|
|
|
|
Sre uint32
|
|
|
|
Cmd uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
type DecodedInstr struct {
|
2024-11-03 18:38:44 +00:00
|
|
|
InstrDesc InstrDesc
|
2024-11-01 10:54:59 +00:00
|
|
|
// A, B, C, D1 and D2 formats fields
|
|
|
|
StandardFormatFields
|
|
|
|
// E format fields
|
|
|
|
SubsystemFormatFields
|
|
|
|
}
|