You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.8 KiB
Python
70 lines
1.8 KiB
Python
3 years ago
|
from collections import OrderedDict
|
||
|
|
||
3 years ago
|
from amaranth import *
|
||
|
from amaranth.asserts import *
|
||
|
|
||
3 years ago
|
from .. import PowerFVCheck
|
||
|
from ... import pfv, tb
|
||
3 years ago
|
|
||
|
|
||
3 years ago
|
__all__ = ["SPRSpec", "SPRCheck"]
|
||
3 years ago
|
|
||
|
|
||
3 years ago
|
class SPRSpec(Elaboratable):
|
||
|
"""SPR consistency specification.
|
||
3 years ago
|
|
||
3 years ago
|
Checks that reads from supported SPRs are the last value that was written to
|
||
3 years ago
|
them.
|
||
|
"""
|
||
3 years ago
|
def __init__(self, post):
|
||
3 years ago
|
self.pfv = pfv.Interface()
|
||
3 years ago
|
self.post = tb.Trigger(cycle=post)
|
||
|
|
||
|
def triggers(self):
|
||
|
yield self.post
|
||
3 years ago
|
|
||
|
def elaborate(self, platform):
|
||
|
m = Module()
|
||
|
|
||
3 years ago
|
spr_map = OrderedDict()
|
||
3 years ago
|
|
||
3 years ago
|
for spr_name in ("lr", "ctr", "xer", "tar"):
|
||
|
spr = Record([
|
||
|
("written", 1),
|
||
|
("shadow", 64),
|
||
|
], name=spr_name)
|
||
|
spr_map[spr_name] = spr
|
||
|
|
||
|
spec_order = AnyConst(self.pfv.order.width)
|
||
3 years ago
|
|
||
|
with m.If(self.pfv.stb & (self.pfv.order <= spec_order)):
|
||
3 years ago
|
for spr_name, spr in spr_map.items():
|
||
|
pfv_spr = getattr(self.pfv, spr_name)
|
||
|
|
||
|
with m.If(pfv_spr.w_stb):
|
||
|
m.d.sync += [
|
||
|
spr.written.eq(1),
|
||
|
spr.shadow .eq(pfv_spr.w_data),
|
||
|
]
|
||
3 years ago
|
|
||
3 years ago
|
with m.If(self.post.stb):
|
||
3 years ago
|
m.d.sync += [
|
||
|
Assume(Past(self.pfv.stb)),
|
||
|
Assume(Past(self.pfv.order) == spec_order),
|
||
|
]
|
||
3 years ago
|
|
||
|
for spr_name, spr in spr_map.items():
|
||
|
pfv_spr = getattr(self.pfv, spr_name)
|
||
|
|
||
|
with m.If(spr.written & Past(pfv_spr.r_stb)):
|
||
|
m.d.sync += Assert(Past(spr.shadow) == Past(pfv_spr.r_data))
|
||
3 years ago
|
|
||
|
return m
|
||
3 years ago
|
|
||
|
|
||
|
class SPRCheck(PowerFVCheck, name="cons_spr"):
|
||
|
def get_testbench(self, dut, post):
|
||
|
tb_spec = SPRSpec(post)
|
||
|
tb_top = tb.Testbench(tb_spec, dut)
|
||
|
return tb_top
|