-
Notifications
You must be signed in to change notification settings - Fork 12
/
wrapper.sv
155 lines (129 loc) · 3.79 KB
/
wrapper.sv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* NERV -- Naive Educational RISC-V Processor
*
* Copyright (C) 2020 Claire Xenia Wolf <claire@yosyshq.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
module rvfi_wrapper (
input clock,
input reset,
`RVFI_OUTPUTS
`RVFI_BUS_OUTPUTS
);
(* keep *) `rvformal_rand_reg stall;
(* keep *) `rvformal_rand_reg [31:0] imem_data;
(* keep *) `rvformal_rand_reg [31:0] dmem_rdata;
(* keep *) `rvformal_rand_reg [31:0] irq;
`ifdef NERV_FAULT
(* keep *) `rvformal_rand_reg imem_fault;
(* keep *) `rvformal_rand_reg dmem_fault;
`else
wire imem_fault = 0;
wire dmem_fault = 0;
`endif
(* keep *) wire trap;
(* keep *) wire [31:0] imem_addr;
(* keep *) wire dmem_valid;
(* keep *) wire [31:0] dmem_addr;
(* keep *) wire [ 3:0] dmem_wstrb;
(* keep *) wire [31:0] dmem_wdata;
nerv uut (
.clock (clock ),
.reset (reset ),
.stall (stall ),
.trap (trap ),
.imem_addr (imem_addr ),
.imem_data (imem_data ),
.dmem_valid (dmem_valid),
.dmem_addr (dmem_addr ),
.dmem_wstrb (dmem_wstrb),
.dmem_wdata (dmem_wdata),
.dmem_rdata (dmem_rdata),
`ifdef NERV_FAULT
.imem_fault (imem_fault),
.dmem_fault (dmem_fault),
`endif
.irq (irq),
`RVFI_CONN32
);
`ifdef RISCV_FORMAL_BUS
`define RISCV_FORMAL_CHANNEL_SIGNAL(channels, width, name) \
(* keep *) reg [(width) - 1:0] imem_``name; assign rvfi_``name[0 * (width) +: (width)] = imem_``name;
`RVFI_BUS_SIGNALS
`undef RISCV_FORMAL_CHANNEL_SIGNAL
`define RISCV_FORMAL_CHANNEL_SIGNAL(channels, width, name) \
(* keep *) reg [(width) - 1:0] dmem_``name; assign rvfi_``name[1 * (width) +: (width)] = dmem_``name;
`RVFI_BUS_SIGNALS
`undef RISCV_FORMAL_CHANNEL_SIGNAL
reg [31:0] imem_addr_q;
always @(posedge clock) begin
if (!stall)
imem_addr_q <= imem_addr;
end
always @* begin
imem_bus_addr = imem_addr_q;
imem_bus_insn = 1;
imem_bus_data = 0;
imem_bus_rmask = 4'b1111;
imem_bus_wmask = 4'b0000;
imem_bus_rdata = imem_data;
imem_bus_wdata = 0;
imem_bus_fault = imem_fault;
imem_bus_valid = !stall;
end;
reg dmem_valid_q;
reg [31:0] dmem_addr_q;
reg [ 3:0] dmem_wstrb_q;
reg [31:0] dmem_wdata_q;
(* keep *) `rvformal_rand_reg [31:0] next_dmem_rdata;
reg [31:0] next_dmem_rdata_q;
`ifdef NERV_FAULT
(* keep *) `rvformal_rand_reg [31:0] next_dmem_fault;
reg [31:0] next_dmem_fault_q;
`endif
always @(posedge clock) begin
if (!stall) begin
next_dmem_rdata_q <= next_dmem_rdata;
`ifdef NERV_FAULT
next_dmem_fault_q <= next_dmem_fault;
`endif
end
end
always @* begin
if (!stall) begin
assume (dmem_rdata == next_dmem_rdata_q);
`ifdef NERV_FAULT
assume (dmem_fault == next_dmem_fault_q);
`endif
end
dmem_bus_addr = dmem_addr;
dmem_bus_insn = 0;
dmem_bus_data = 1;
dmem_bus_rmask = dmem_wstrb ? 4'b0000 : 4'b1111;
dmem_bus_wmask = dmem_wstrb;
dmem_bus_rdata = next_dmem_rdata;
dmem_bus_wdata = dmem_wdata;
dmem_bus_fault = next_dmem_fault;
dmem_bus_valid = !stall && dmem_valid;
end;
`endif
`ifdef NERV_FAIRNESS
reg [2:0] stalled = 0;
always @(posedge clock) begin
stalled <= {stalled, stall};
assume (~stalled);
end
`endif
endmodule