Move decoder.py to power_major_decoder.py
[soc.git] / src / decoder / power_major_decoder.py
1 from nmigen import Module, Elaboratable, Signal
2 import csv
3 import os
4 from enum import Enum, unique
5
6 @unique
7 class Function(Enum):
8 ALU = 0
9 LDST = 1
10
11 @unique
12 class InternalOp(Enum):
13 OP_ADD = 0
14 OP_AND = 1
15 OP_B = 2
16 OP_BC = 3
17 OP_CMP = 4
18 OP_LOAD = 5
19 OP_MUL_L64 = 6
20 OP_OR = 7
21 OP_RLC = 8
22 OP_STORE = 9
23 OP_TDI = 10
24 OP_XOR = 11
25
26 def get_csv(name):
27 file_dir = os.path.dirname(os.path.realpath(__file__))
28 with open(os.path.join(file_dir, name)) as csvfile:
29 reader = csv.DictReader(csvfile)
30 return list(reader)
31
32 major_opcodes = get_csv("major.csv")
33
34 class PowerMajorDecoder(Elaboratable):
35 def __init__(self):
36 self.opcode_in = Signal(6, reset_less=True)
37
38 self.function_unit = Signal(Function, reset_less=True)
39 self.internal_op = Signal(InternalOp, reset_less=True)
40 def elaborate(self, platform):
41 m = Module()
42 comb = m.d.comb
43
44 with m.Switch(self.opcode_in):
45 for row in major_opcodes:
46 opcode = int(row['opcode'])
47 with m.Case(opcode):
48 comb += self.function_unit.eq(Function[row['unit']])
49 comb += self.internal_op.eq(InternalOp[row['internal op']])
50 return m
51
52
53
54