1 from openpower
.simulator
.program
import Program
2 from openpower
.endian
import bigendian
3 from openpower
.consts
import MSR
4 from openpower
.test
.state
import ExpectedState
6 from openpower
.test
.common
import TestAccumulatorBase
10 class TrapTestCase(TestAccumulatorBase
):
12 def case_1_kaivb(self
):
13 # https://bugs.libre-soc.org/show_bug.cgi?id=859
14 lst
= ["mtspr 850, 1", # KAIVB
17 initial_regs
= [0] * 32
18 initial_regs
[1] = 0x129518230011feed
19 initial_sprs
= {'KAIVB': 0x12345678,
21 msr
= 0xa000000000000003
22 self
.add_case(Program(lst
, bigendian
),
23 initial_regs
, initial_sprs
,
26 def case_2_kaivb_test(self
):
27 # https://bugs.libre-soc.org/show_bug.cgi?id=859
28 # sets KAIVB to 1<<13 then deliberately causes exception.
29 # PC expected to jump to (1<<13)|0x700 *NOT* 0x700 as usual
30 lst
= ["mtspr 850, 1", # KAIVB
31 "tbegin.", # deliberately use illegal instruction
33 initial_regs
= [0] * 32
34 initial_regs
[1] = 1<<13
35 initial_sprs
= {'KAIVB': 0x12345678,
37 msr
= 0xa000000000000003
38 e
= ExpectedState(pc
=0x2700)
40 e
.msr
= 0xa000000000000003 # TODO, not actually checked
41 self
.add_case(Program(lst
, bigendian
),
42 initial_regs
, initial_sprs
,
46 def case_0_hrfid(self
):
48 initial_regs
= [0] * 32
50 initial_sprs
= {'HSRR0': 0x12345678, 'HSRR1': 0x5678}
51 self
.add_case(Program(lst
, bigendian
),
52 initial_regs
, initial_sprs
)
56 initial_regs
= [0] * 32
58 initial_sprs
= {'SRR0': 0x12345678, 'SRR1': 0x5678}
59 e
= ExpectedState(pc
=0xc00)
61 self
.add_case(Program(lst
, bigendian
),
62 initial_regs
, initial_sprs
)
64 def case_1_rfid(self
):
66 initial_regs
= [0] * 32
68 initial_sprs
= {'SRR0': 0x12345678, 'SRR1': 0x5678}
69 self
.add_case(Program(lst
, bigendian
),
70 initial_regs
, initial_sprs
)
72 def case_2_rfid(self
):
74 initial_regs
= [0] * 32
76 initial_sprs
= {'SRR0': 0x12345678, 'SRR1': 0xb000000000001033}
77 e
= ExpectedState(pc
=0x700)
79 e
.msr
= 0xb000000000001033 # TODO, not actually checked
80 self
.add_case(Program(lst
, bigendian
),
81 initial_regs
, initial_sprs
,
82 initial_msr
=0xa000000000000003,
85 def case_0_trap_eq_imm(self
):
86 insns
= ["twi", "tdi"]
88 choice
= random
.choice(insns
)
89 lst
= [f
"{choice} 4, 1, %d" % i
] # TO=4: trap equal
90 initial_regs
= [0] * 32
92 self
.add_case(Program(lst
, bigendian
), initial_regs
)
94 def case_0_trap_eq(self
):
98 lst
= [f
"{choice} 4, 1, 2"] # TO=4: trap equal
99 initial_regs
= [0] * 32
102 self
.add_case(Program(lst
, bigendian
), initial_regs
)
104 def case_3_mtmsr_0(self
):
106 initial_regs
= [0] * 32
107 initial_regs
[1] = 0xffffffffffffffff
108 self
.add_case(Program(lst
, bigendian
), initial_regs
)
110 def case_3_mtmsr_1(self
):
112 initial_regs
= [0] * 32
113 initial_regs
[1] = 0xffffffffffffffff
114 self
.add_case(Program(lst
, bigendian
), initial_regs
)
116 def case_4_mtmsrd_0_linux(self
):
118 initial_regs
= [0] * 32
119 initial_regs
[1] = 0xb000000000001033
120 self
.add_case(Program(lst
, bigendian
), initial_regs
,
121 initial_msr
=0xa000000000000003)
123 def case_4_mtmsrd_0(self
):
125 initial_regs
= [0] * 32
126 initial_regs
[1] = 0xffffffffffffffff
127 self
.add_case(Program(lst
, bigendian
), initial_regs
)
129 def case_5_mtmsrd_1(self
):
131 initial_regs
= [0] * 32
132 initial_regs
[1] = 0xffffffffffffffff
133 self
.add_case(Program(lst
, bigendian
), initial_regs
)
135 def case_6_mtmsr_priv_0(self
):
137 initial_regs
= [0] * 32
138 initial_regs
[1] = 0xffffffffffffffff
139 msr
= 1 << MSR
.PR
# set in "problem state"
140 self
.add_case(Program(lst
, bigendian
), initial_regs
,
143 def case_7_rfid_priv_0(self
):
145 initial_regs
= [0] * 32
147 initial_sprs
= {'SRR0': 0x12345678, 'SRR1': 0x5678}
148 msr
= 1 << MSR
.PR
# set in "problem state"
149 self
.add_case(Program(lst
, bigendian
),
150 initial_regs
, initial_sprs
,
153 def case_8_mfmsr(self
):
155 initial_regs
= [0] * 32
156 msr
= (~
(1 << MSR
.PR
)) & 0xffffffffffffffff
157 self
.add_case(Program(lst
, bigendian
), initial_regs
,
160 def case_9_mfmsr_priv(self
):
162 initial_regs
= [0] * 32
163 msr
= 1 << MSR
.PR
# set in "problem state"
164 self
.add_case(Program(lst
, bigendian
), initial_regs
,
167 def case_999_illegal(self
):
168 # ok, um this is a bit of a cheat: use an instruction we know
169 # is not implemented by either ISACaller or the core
171 "mtmsr 1,1"] # should not get executed
172 initial_regs
= [0] * 32
173 self
.add_case(Program(lst
, bigendian
), initial_regs
)