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", "ls180"]
11 def make_wb_bus(prefix
, obj
):
13 for o
in ['stb', 'cyc', 'cti', 'bte', 'we', 'adr', 'dat_w', 'sel']:
14 res
['o_%s_%s' % (prefix
, o
)] = getattr(obj
, o
)
15 for i
in ['ack', 'err', 'dat_r']:
16 res
['i_%s_%s' % (prefix
, i
)] = getattr(obj
, i
)
19 def make_wb_slave(prefix
, obj
):
21 for i
in ['stb', 'cyc', 'cti', 'bte', 'we', 'adr', 'dat_w', 'sel']:
22 res
['i_%s_%s' % (prefix
, i
)] = getattr(obj
, i
)
23 for o
in ['ack', 'err', 'dat_r']:
24 res
['o_%s_%s' % (prefix
, o
)] = getattr(obj
, o
)
30 human_name
= "Libre-SoC"
31 variants
= CPU_VARIANTS
33 gcc_triple
= ("powerpc64le-linux", "powerpc64le-linux-gnu")
34 linker_output_format
= "elf64-powerpcle"
36 io_regions
= {0xc0000000: 0x10000000} # origin, length
40 return {"csr": 0xc0000000}
45 flags
+= "-mabi=elfv2 "
46 flags
+= "-msoft-float "
47 flags
+= "-mno-string "
48 flags
+= "-mno-multiple "
50 flags
+= "-mno-altivec "
51 flags
+= "-mlittle-endian "
52 flags
+= "-mstrict-align "
53 flags
+= "-fno-stack-protector "
54 flags
+= "-mcmodel=small "
55 flags
+= "-D__microwatt__ "
58 def __init__(self
, platform
, variant
="standard"):
59 self
.platform
= platform
60 self
.variant
= variant
62 self
.interrupt
= Signal(16)
64 if variant
== "standard32":
66 self
.dbus
= dbus
= wb
.Interface(data_width
=32, adr_width
=30)
68 self
.dbus
= dbus
= wb
.Interface(data_width
=64, adr_width
=29)
70 self
.ibus
= ibus
= wb
.Interface(data_width
=64, adr_width
=29)
72 self
.xics_icp
= icp
= wb
.Interface(data_width
=32, adr_width
=30)
73 self
.xics_ics
= ics
= wb
.Interface(data_width
=32, adr_width
=30)
75 if variant
!= "ls180":
76 self
.simple_gpio
= gpio
= wb
.Interface(data_width
=32, adr_width
=30)
78 self
.periph_buses
= [ibus
, dbus
]
79 self
.memory_buses
= []
81 self
.dmi_addr
= Signal(4)
82 self
.dmi_din
= Signal(64)
83 self
.dmi_dout
= Signal(64)
84 self
.dmi_wr
= Signal(1)
85 self
.dmi_ack
= Signal(1)
86 self
.dmi_req
= Signal(1)
90 self
.cpu_params
= dict(
92 i_clk
= ClockSignal(),
93 i_rst
= ResetSignal() | self
.reset
,
95 # Monitoring / Debugging
98 i_core_bigendian_i
= 0, # Signal(),
100 o_memerr_o
= Signal(),
103 i_int_level_i
= self
.interrupt
,
106 i_dmi_addr_i
= self
.dmi_addr
,
107 i_dmi_din
= self
.dmi_din
,
108 o_dmi_dout
= self
.dmi_dout
,
109 i_dmi_req_i
= self
.dmi_req
,
110 i_dmi_we_i
= self
.dmi_wr
,
111 o_dmi_ack_o
= self
.dmi_ack
,
114 # add wishbone buses to cpu params
115 self
.cpu_params
.update(make_wb_bus("ibus_", ibus
))
116 self
.cpu_params
.update(make_wb_bus("dbus_", dbus
))
117 self
.cpu_params
.update(make_wb_slave("ics_wb_", ics
))
118 self
.cpu_params
.update(make_wb_slave("icp_wb_", icp
))
119 if variant
!= "ls180":
120 self
.cpu_params
.update(make_wb_slave("gpio_wb_", gpio
))
122 # add verilog sources
123 self
.add_sources(platform
)
125 def set_reset_address(self
, reset_address
):
126 assert not hasattr(self
, "reset_address")
127 self
.reset_address
= reset_address
128 assert reset_address
== 0x00000000
131 def add_sources(platform
):
132 cdir
= os
.path
.dirname(__file__
)
133 platform
.add_source(os
.path
.join(cdir
, "libresoc.v"))
135 def do_finalize(self
):
136 self
.specials
+= Instance("test_issuer", **self
.cpu_params
)