central-arch/pkg/instrset/Instrset.go

130 lines
4.8 KiB
Go
Raw Permalink Normal View History

2024-11-01 10:54:59 +00:00
package instrset
import (
"fmt"
"git.elyanpoujol.fr/elyan/central-arch/pkg/instr"
)
2024-11-01 10:54:59 +00:00
var CentralInstructionSet = []instr.InstrDesc{
NOP,
SVC,
LDRIR,
LDRIRW,
LDRIOW,
LDRR,
LDRRW,
LDROW,
MOVR,
MOVI,
MOVNI,
BIO,
BAIO,
BXI,
BXR,
SSR,
SSW,
}
// Miscellaneous Instructions
var NOP = instr.InstrDesc{VariantName: "NOP", Mnemonic: "nop", OpCode: 0x0, Format: instr.D2, Formatter: nopFormatter}
var SVC = instr.InstrDesc{VariantName: "SVC", Mnemonic: "svc", OpCode: 0x7f, Format: instr.D2, Formatter: svcFormatter}
// Memory-Related Instructions
// TODO Add "str" variants
var LDRIR = instr.InstrDesc{VariantName: "LDRIR", Mnemonic: "ldr", OpCode: 0x1, Format: instr.B1, Formatter: ldrirFormatter}
var LDRIRW = instr.InstrDesc{VariantName: "LDRIRW", Mnemonic: "ldr", OpCode: 0x2, Format: instr.B1, Formatter: ldrirwFormatter}
var LDRIOW = instr.InstrDesc{VariantName: "LDRIOW", Mnemonic: "ldr", OpCode: 0x3, Format: instr.B1, Formatter: ldriowFormatter}
var LDRR = instr.InstrDesc{VariantName: "LDRR", Mnemonic: "ldr", OpCode: 0x4, Format: instr.A1, Formatter: ldrrFormatter}
var LDRRW = instr.InstrDesc{VariantName: "LDRRW", Mnemonic: "ldr", OpCode: 0x5, Format: instr.A1, Formatter: ldrrwFormatter}
var LDROW = instr.InstrDesc{VariantName: "LDROW", Mnemonic: "ldr", OpCode: 0x6, Format: instr.A1, Formatter: ldrowFormatter}
// Register Manipulation Instructions
var MOVR = instr.InstrDesc{VariantName: "MOVR", Mnemonic: "mov", OpCode: 0xd, Format: instr.B1, Formatter: movrFormatter}
var MOVI = instr.InstrDesc{VariantName: "MOVI", Mnemonic: "mov", OpCode: 0xe, Format: instr.C, Formatter: moviFormatter}
var MOVNI = instr.InstrDesc{VariantName: "MOVNI", Mnemonic: "movn", OpCode: 0x13, Format: instr.C, Formatter: movniFormatter}
// Branching Instructions
var BIO = instr.InstrDesc{VariantName: "BIO", Mnemonic: "b", OpCode: 0xf, Format: instr.D1, Formatter: bioFormatter}
var BAIO = instr.InstrDesc{VariantName: "BAIO", Mnemonic: "b", OpCode: 0x10, Format: instr.D2, Formatter: baioFormatter}
var BXI = instr.InstrDesc{VariantName: "BXI", Mnemonic: "bx", OpCode: 0x11, Format: instr.B2, Formatter: bxiFormatter}
var BXR = instr.InstrDesc{VariantName: "BXR", Mnemonic: "bx", OpCode: 0x12, Format: instr.A2, Formatter: bxrFormatter}
// Subsystems Instructions
var SSR = instr.InstrDesc{VariantName: "SSR", Mnemonic: "ssr", OpCode: 0x7d, Format: instr.E, Formatter: ssrFormatter}
var SSW = instr.InstrDesc{VariantName: "SSW", Mnemonic: "ssw", OpCode: 0x7e, Format: instr.E, Formatter: sswFormatter}
func nopFormatter(i *instr.DecodedInstr) string {
return i.InstrDesc.Mnemonic
}
func svcFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s 0x%06x", i.InstrDesc.Mnemonic, i.Imm)
}
func ldrirFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s %s, [%s, %#04x]", i.InstrDesc.Mnemonic, i.Condition, i.Rd, i.Rs1, int32(i.Imm)*4)
}
func ldrirwFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s %s, ![%s, %#04x]", i.InstrDesc.Mnemonic, i.Condition, i.Rd, i.Rs1, int32(i.Imm)*4)
}
func ldriowFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s %s, [%s, %#04x]!", i.InstrDesc.Mnemonic, i.Condition, i.Rd, i.Rs1, int32(i.Imm)*4)
}
func ldrrFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s %s, [%s, %s]", i.InstrDesc.Mnemonic, i.Condition, i.Rd, i.Rs1, i.Rs2)
}
func ldrrwFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s %s, ![%s, %s]", i.InstrDesc.Mnemonic, i.Condition, i.Rd, i.Rs1, i.Rs2)
}
func ldrowFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s %s, [%s, %s]!", i.InstrDesc.Mnemonic, i.Condition, i.Rd, i.Rs1, i.Rs2)
}
func movrFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s %s, %s", i.InstrDesc.Mnemonic, i.Condition, i.Rd, i.Rs1)
}
func moviFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s %s, %#04x", i.InstrDesc.Mnemonic, i.Condition, i.Rd, i.Imm)
}
func movniFormatter(i *instr.DecodedInstr) string {
val := int32(0xffff0000 + i.Imm&0xffff)
return fmt.Sprintf("%s.%s %s, %#04x", i.InstrDesc.Mnemonic, i.Condition, i.Rd, val)
}
func bioFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s %#06x", i.InstrDesc.Mnemonic, i.Condition, int32(i.Imm)*4)
}
func baioFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s %#06x", i.InstrDesc.Mnemonic, int32(i.Imm))
}
func bxiFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s [%s, %#06x]", i.InstrDesc.Mnemonic, i.Condition, i.Rs1, int32(i.Imm)*4)
}
func bxrFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s.%s [%s, %s]", i.InstrDesc.Mnemonic, i.Condition, i.Rs1, i.Rs2)
}
func ssrFormatter(i *instr.DecodedInstr) string {
return fmt.Sprintf("%s ss%d, %s, sr%d, %#02x", i.InstrDesc.Mnemonic, i.Sid, i.Reg, i.Sre, i.Cmd)
}
func sswFormatter(i *instr.DecodedInstr) string {
return ssrFormatter(i)
2024-11-01 10:54:59 +00:00
}