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