3 from migen
import ClockSignal
, ResetSignal
, Signal
, Instance
, Cat
5 from litex
.soc
.interconnect
import wishbone
as wb
6 from litex
.soc
.cores
.cpu
import CPU
8 CPU_VARIANTS
= ["standard", "standard32", "standardjtag", "ls180"]
11 def make_wb_bus(prefix
, obj
, simple
=False):
13 outpins
= ['stb', 'cyc', 'we', 'adr', 'dat_w', 'sel']
15 outpins
+= ['cti', 'bte']
17 res
['o_%s__%s' % (prefix
, o
)] = getattr(obj
, o
)
18 for i
in ['ack', 'err', 'dat_r']:
19 res
['i_%s__%s' % (prefix
, i
)] = getattr(obj
, i
)
22 def make_wb_slave(prefix
, obj
):
24 for i
in ['stb', 'cyc', 'cti', 'bte', 'we', 'adr', 'dat_w', 'sel']:
25 res
['i_%s__%s' % (prefix
, i
)] = getattr(obj
, i
)
26 for o
in ['ack', 'err', 'dat_r']:
27 res
['o_%s__%s' % (prefix
, o
)] = getattr(obj
, o
)
33 human_name
= "Libre-SoC"
34 variants
= CPU_VARIANTS
36 gcc_triple
= ("powerpc64le-linux", "powerpc64le-linux-gnu")
37 linker_output_format
= "elf64-powerpcle"
39 io_regions
= {0xc0000000: 0x10000000} # origin, length
43 return {"csr": 0xc0000000}
48 flags
+= "-mabi=elfv2 "
49 flags
+= "-msoft-float "
50 flags
+= "-mno-string "
51 flags
+= "-mno-multiple "
53 flags
+= "-mno-altivec "
54 flags
+= "-mlittle-endian "
55 flags
+= "-mstrict-align "
56 flags
+= "-fno-stack-protector "
57 flags
+= "-mcmodel=small "
58 flags
+= "-D__microwatt__ "
61 def __init__(self
, platform
, variant
="standard"):
62 self
.platform
= platform
63 self
.variant
= variant
65 self
.interrupt
= Signal(16)
67 if variant
== "standard32":
69 self
.dbus
= dbus
= wb
.Interface(data_width
=32, adr_width
=30)
71 self
.dbus
= dbus
= wb
.Interface(data_width
=64, adr_width
=29)
73 self
.ibus
= ibus
= wb
.Interface(data_width
=64, adr_width
=29)
75 self
.xics_icp
= icp
= wb
.Interface(data_width
=32, adr_width
=30)
76 self
.xics_ics
= ics
= wb
.Interface(data_width
=32, adr_width
=30)
78 jtag_en
= ('jtag' in variant
) or variant
== 'ls180'
80 if variant
!= "ls180":
81 self
.simple_gpio
= gpio
= wb
.Interface(data_width
=32, adr_width
=30)
83 self
.jtag_wb
= jtag_wb
= wb
.Interface(data_width
=64, adr_width
=29)
85 self
.periph_buses
= [ibus
, dbus
]
86 self
.memory_buses
= []
89 self
.periph_buses
.append(jtag_wb
)
90 self
.jtag_tck
= Signal(1)
91 self
.jtag_tms
= Signal(1)
92 self
.jtag_tdi
= Signal(1)
93 self
.jtag_tdo
= Signal(1)
95 self
.dmi_addr
= Signal(4)
96 self
.dmi_din
= Signal(64)
97 self
.dmi_dout
= Signal(64)
98 self
.dmi_wr
= Signal(1)
99 self
.dmi_ack
= Signal(1)
100 self
.dmi_req
= Signal(1)
104 self
.cpu_params
= dict(
106 i_clk
= ClockSignal(),
107 i_rst
= ResetSignal() | self
.reset
,
109 # Monitoring / Debugging
112 i_core_bigendian_i
= 0, # Signal(),
113 o_busy_o
= Signal(), # not connected
114 o_memerr_o
= Signal(), # not connected
115 o_pc_o
= Signal(64), # not connected
118 i_int_level_i
= self
.interrupt
,
123 self
.cpu_params
.update(dict(
125 o_TAP_bus__tdo
= self
.jtag_tdo
,
126 i_TAP_bus__tdi
= self
.jtag_tdi
,
127 i_TAP_bus__tms
= self
.jtag_tms
,
128 i_TAP_bus__tck
= self
.jtag_tck
,
131 self
.cpu_params
.update(dict(
133 i_dmi_addr_i
= self
.dmi_addr
,
134 i_dmi_din
= self
.dmi_din
,
135 o_dmi_dout
= self
.dmi_dout
,
136 i_dmi_req_i
= self
.dmi_req
,
137 i_dmi_we_i
= self
.dmi_wr
,
138 o_dmi_ack_o
= self
.dmi_ack
,
141 # add wishbone buses to cpu params
142 self
.cpu_params
.update(make_wb_bus("ibus", ibus
))
143 self
.cpu_params
.update(make_wb_bus("dbus", dbus
))
144 self
.cpu_params
.update(make_wb_slave("ics_wb", ics
))
145 self
.cpu_params
.update(make_wb_slave("icp_wb", icp
))
146 if variant
!= "ls180":
147 self
.cpu_params
.update(make_wb_slave("gpio_wb", gpio
))
149 self
.cpu_params
.update(make_wb_bus("jtag_wb", jtag_wb
, simple
=True))
151 # add verilog sources
152 self
.add_sources(platform
)
154 def set_reset_address(self
, reset_address
):
155 assert not hasattr(self
, "reset_address")
156 self
.reset_address
= reset_address
157 assert reset_address
== 0x00000000
160 def add_sources(platform
):
161 cdir
= os
.path
.dirname(__file__
)
162 platform
.add_source(os
.path
.join(cdir
, "libresoc.v"))
164 def do_finalize(self
):
165 self
.specials
+= Instance("test_issuer", **self
.cpu_params
)