invert numbering on CR HDLState.get_crregs
[soc.git] / src / soc / simple / test / teststate.py
1 """ Power ISA test API
2
3 This module implements the creation, inspection and comparison
4 of test states for TestIssuer HDL
5
6 """
7
8 from openpower.decoder.power_enums import XER_bits
9 from openpower.util import log
10 from openpower.test.state import (State, state_add, state_factory,
11 TestState,)
12 from soc.fu.compunits.test.test_compunit import get_l0_mem
13
14 class HDLState(State):
15 """HDLState: Obtains registers and memory from an nmigen simulator
16 object by implementing State class methods.
17 """
18 def __init__(self, core):
19 super().__init__()
20 self.core = core
21
22 def get_intregs(self):
23 self.intregs = []
24 for i in range(32):
25 if self.core.regs.int.unary:
26 rval = yield self.core.regs.int.regs[i].reg
27 else:
28 rval = yield self.core.regs.int.memory._array[i]
29 self.intregs.append(rval)
30 log("class hdl int regs", list(map(hex, self.intregs)))
31
32 def get_crregs(self):
33 self.crregs = []
34 for i in range(8):
35 rval = yield self.core.regs.cr.regs[7-i].reg
36 self.crregs.append(rval)
37 log("class hdl cr regs", list(map(hex, self.crregs)))
38
39 def get_xregs(self):
40 self.xregs = []
41 self.xr = self.core.regs.xer
42 self.so = yield self.xr.regs[self.xr.SO].reg
43 self.ov = yield self.xr.regs[self.xr.OV].reg
44 self.ca = yield self.xr.regs[self.xr.CA].reg
45 self.xregs.extend((self.so, self.ov, self.ca))
46 log("class hdl xregs", list(map(hex, self.xregs)))
47
48 def get_pc(self):
49 self.pcl = []
50 self.state = self.core.regs.state
51 self.pc = yield self.state.r_ports['cia'].o_data
52 self.pcl.append(self.pc)
53 log("class hdl pc", hex(self.pc))
54
55 def get_mem(self):
56 # get the underlying HDL-simulated memory from the L0CacheBuffer
57 hdlmem = get_l0_mem(self.core.l0)
58 self.mem = {}
59 for i in range(hdlmem.depth):
60 value = yield hdlmem._array[i] # should not really do this
61 self.mem[i*8] = value
62
63
64 # add to State Factory
65 state_add('hdl', HDLState)