4198ae26ff95a6ce25ec86f8b9c92b3249a77cad
[soc.git] / src / soc / simple / issuer_verilog.py
1 """simple core issuer verilog generator
2 """
3
4 import argparse
5 from nmigen.cli import verilog
6
7 from openpower.consts import MSR
8 from soc.config.test.test_loadstore import TestMemPspec
9 from soc.simple.issuer import TestIssuer, TestIssuerInternal
10
11
12 if __name__ == '__main__':
13 parser = argparse.ArgumentParser(description="Simple core issuer " \
14 "verilog generator")
15 parser.add_argument("output_filename")
16 parser.add_argument("--enable-xics", dest='xics', action="store_true",
17 help="Enable interrupts",
18 default=True)
19 parser.add_argument("--disable-xics", dest='xics', action="store_false",
20 help="Disable interrupts",
21 default=False)
22 parser.add_argument("--enable-lessports", dest='lessports',
23 action="store_true",
24 help="Enable less regfile ports",
25 default=True)
26 parser.add_argument("--disable-lessports", dest='lessports',
27 action="store_false",
28 help="enable more regfile ports",
29 default=False)
30 parser.add_argument("--enable-core", dest='core', action="store_true",
31 help="Enable main core",
32 default=True)
33 parser.add_argument("--disable-core", dest='core', action="store_false",
34 help="disable main core",
35 default=False)
36 parser.add_argument("--enable-mmu", dest='mmu', action="store_true",
37 help="Enable mmu",
38 default=False)
39 parser.add_argument("--disable-mmu", dest='mmu', action="store_false",
40 help="Disable mmu",
41 default=False)
42 parser.add_argument("--enable-pll", dest='pll', action="store_true",
43 help="Enable pll",
44 default=False)
45 parser.add_argument("--disable-pll", dest='pll', action="store_false",
46 help="Disable pll",
47 default=False)
48 parser.add_argument("--enable-testgpio", action="store_true",
49 help="Disable gpio pins",
50 default=False)
51 parser.add_argument("--enable-sram4x4kblock", action="store_true",
52 help="Disable sram 4x4k block",
53 default=False)
54 parser.add_argument("--debug", default="jtag", help="Select debug " \
55 "interface [jtag | dmi] [default jtag]")
56 parser.add_argument("--enable-svp64", dest='svp64', action="store_true",
57 help="Enable SVP64",
58 default=True)
59 parser.add_argument("--disable-svp64", dest='svp64', action="store_false",
60 help="disable SVP64",
61 default=False)
62 parser.add_argument("--xlen", default=64, type=int,
63 help="Set register width [default 64]")
64 # create a module that's directly compatible as a drop-in replacement
65 # in microwatt.v
66 parser.add_argument("--microwatt-compat", dest='mwcompat',
67 action="store_true",
68 help="generate microwatt-compatible interface",
69 default=False)
70 # allow overlaps in TestIssuer
71 parser.add_argument("--allow-overlap", dest='allow_overlap',
72 action="store_true",
73 help="allow overlap in TestIssuer",
74 default=False)
75
76 args = parser.parse_args()
77
78 # convenience: set some defaults
79 if args.mwcompat:
80 args.pll = False
81 args.debug = 'dmi'
82 args.core = True
83 args.xics = False
84 args.gpio = False
85 args.sram4x4kblock = False
86 args.svp64 = False
87
88 print(args)
89
90 units = {'alu': 1,
91 'cr': 1, 'branch': 1, 'trap': 1,
92 'logical': 1,
93 'spr': 1,
94 'div': 1,
95 'mul': 1,
96 'shiftrot': 1
97 }
98 if args.mmu:
99 units['mmu'] = 1 # enable MMU
100
101 # decide which memory type to configure
102 if args.mmu:
103 ldst_ifacetype = 'mmu_cache_wb'
104 imem_ifacetype = 'mmu_cache_wb'
105 else:
106 ldst_ifacetype = 'bare_wb'
107 imem_ifacetype = 'bare_wb'
108
109 # default MSR (TODO, provide option to set default PC as well)
110 msr_reset = (1<<MSR.LE) | (1<<MSR.SF) # 64-bit, little-endian default
111
112 pspec = TestMemPspec(ldst_ifacetype=ldst_ifacetype,
113 imem_ifacetype=imem_ifacetype,
114 addr_wid=64,
115 mask_wid=8,
116 # pipeline and integer register file width
117 XLEN=args.xlen,
118 # must leave at 64
119 reg_wid=64,
120 # set to 32 for instruction-memory width=32
121 imem_reg_wid=64,
122 # set to 32 to make data wishbone bus 32-bit
123 #wb_data_wid=32,
124 xics=args.xics, # XICS interrupt controller
125 nocore=not args.core, # test coriolis2 ioring
126 regreduce = args.lessports, # less regfile ports
127 use_pll=args.pll, # bypass PLL
128 gpio=args.enable_testgpio, # for test purposes
129 sram4x4kblock=args.enable_sram4x4kblock, # add SRAMs
130 debug=args.debug, # set to jtag or dmi
131 svp64=args.svp64, # enable SVP64
132 microwatt_mmu=args.mmu, # enable MMU
133 microwatt_compat=args.mwcompat, # microwatt compatible
134 allow_overlap=args.allow_overlap, # allow overlap
135 units=units,
136 msr_reset=msr_reset)
137 #if args.mwcompat:
138 # pspec.core_domain = 'sync'
139
140 print("mmu", pspec.__dict__["microwatt_mmu"])
141 print("nocore", pspec.__dict__["nocore"])
142 print("regreduce", pspec.__dict__["regreduce"])
143 print("gpio", pspec.__dict__["gpio"])
144 print("sram4x4kblock", pspec.__dict__["sram4x4kblock"])
145 print("xics", pspec.__dict__["xics"])
146 print("use_pll", pspec.__dict__["use_pll"])
147 print("debug", pspec.__dict__["debug"])
148 print("SVP64", pspec.__dict__["svp64"])
149 print("XLEN", pspec.__dict__["XLEN"])
150 print("Microwatt compatibility", pspec.__dict__["microwatt_compat"])
151
152 if args.mwcompat:
153 dut = TestIssuerInternal(pspec)
154 name = "external_core_top"
155 else:
156 dut = TestIssuer(pspec)
157 name = "test_issuer"
158
159 vl = verilog.convert(dut, ports=dut.external_ports(), name=name)
160 with open(args.output_filename, "w") as f:
161 f.write(vl)