1 |
3 |
gdevic |
//==============================================================
|
2 |
|
|
// Test register control and register file blocks
|
3 |
|
|
//==============================================================
|
4 |
|
|
`timescale 100 ns/ 100 ns
|
5 |
|
|
|
6 |
|
|
module test_registers;
|
7 |
|
|
|
8 |
|
|
// ----------------- CLOCKS AND RESET -----------------
|
9 |
|
|
// Define one full T-clock cycle delay
|
10 |
|
|
`define T #2
|
11 |
|
|
bit clk = 1;
|
12 |
|
|
initial repeat (36) #1 clk = ~clk;
|
13 |
|
|
|
14 |
|
|
logic nreset = 0;
|
15 |
|
|
|
16 |
|
|
// ----------------- BUSES -----------------
|
17 |
|
|
// We have 4 Bi-directional buses that can also be 3-stated:
|
18 |
|
|
|
19 |
|
|
// On the address-side, there are high and low 8-bit buses
|
20 |
|
|
reg [7:0] db_lo_as=8'hz; // Drive it using this bus
|
21 |
|
|
wire [7:0] db_lo_as_sig; // Read it using this bus
|
22 |
|
|
|
23 |
|
|
reg [7:0] db_hi_as=8'hz; // Drive it using this bus
|
24 |
|
|
wire [7:0] db_hi_as_sig; // Read it using this bus
|
25 |
|
|
|
26 |
|
|
// On the data-side, there are high and low 8-bit buses
|
27 |
|
|
reg [7:0] db_lo_ds=8'hz; // Drive it using this bus
|
28 |
|
|
wire [7:0] db_lo_ds_sig; // Read it using this bus
|
29 |
|
|
|
30 |
|
|
reg [7:0] db_hi_ds=8'hz; // Drive it using this bus
|
31 |
|
|
wire [7:0] db_hi_ds_sig; // Read it using this bus
|
32 |
|
|
|
33 |
|
|
// ----------------- BUS SWITCHES ------------
|
34 |
|
|
logic ctl_sw_4u_sig=0; // Bus switch #4 upstream gate
|
35 |
|
|
logic ctl_sw_4d_sig=0; // Bus switch #4 downstream gate
|
36 |
|
|
|
37 |
|
|
logic ctl_reg_in_hi_sig=0; // Input to the register file high
|
38 |
|
|
logic ctl_reg_in_lo_sig=0; // Input to the register file low
|
39 |
|
|
logic ctl_reg_out_hi_sig=0; // Output from the register file high
|
40 |
|
|
logic ctl_reg_out_lo_sig=0; // Output from the register file low
|
41 |
|
|
|
42 |
|
|
// ----------------- CONTROL -----------------
|
43 |
|
|
logic [1:0] ctl_reg_gp_sel_sig=0; // Selection of a general purpose register
|
44 |
|
|
logic [1:0] ctl_reg_gp_hilo_sig=0; // Hi/Lo selector for GP registers
|
45 |
|
|
logic ctl_reg_gp_we_sig=0; // Write to a general purpose register
|
46 |
|
|
logic [1:0] ctl_reg_sys_hilo_sig=0; // Hi/Lo selector for system registers
|
47 |
|
|
logic ctl_reg_sys_we_lo_sig=0; // Write to low byte of a system register
|
48 |
|
|
logic ctl_reg_sys_we_hi_sig=0; // Write to high byte of a system register
|
49 |
|
|
logic ctl_reg_sys_we_sig=0; // Write to system register
|
50 |
|
|
logic use_ixiy_sig=0; // Use IX or IY
|
51 |
|
|
logic use_ix_sig=0; // Use IX and not IY
|
52 |
16 |
gdevic |
logic nhold_clk_wait_sig=1; // Enable transitions due to nWAIT
|
53 |
3 |
gdevic |
|
54 |
|
|
logic ctl_reg_exx_sig=0; // Exchange register banks
|
55 |
|
|
logic ctl_reg_ex_af_sig=0; // Exchange AF banks
|
56 |
|
|
logic ctl_reg_ex_de_hl_sig=0; // Exchange HL/DE banks
|
57 |
|
|
logic ctl_reg_use_sp_sig=0; // Use SP register
|
58 |
|
|
logic ctl_reg_sel_pc_sig=0; // Select PC
|
59 |
|
|
logic ctl_reg_sel_ir_sig=0; // Select IR
|
60 |
|
|
logic ctl_reg_sel_wz_sig=0; // Select WZ
|
61 |
|
|
logic ctl_reg_not_pc_sig=0; // Do not select PC
|
62 |
|
|
|
63 |
|
|
// ----------------- TEST -------------------
|
64 |
|
|
`define CHECK(arg) \
|
65 |
|
|
assert({db_hi_ds_sig,db_lo_ds_sig}===arg);
|
66 |
|
|
|
67 |
|
|
initial begin
|
68 |
|
|
`T nreset = 1;
|
69 |
|
|
|
70 |
|
|
//------------------------------------------------------------
|
71 |
|
|
// Identify each 16-bit system register and check access to it
|
72 |
|
|
`T ctl_sw_4d_sig = 1; // Use unified bus: downstream
|
73 |
|
|
ctl_sw_4u_sig = 0;
|
74 |
|
|
ctl_reg_in_hi_sig = 1;
|
75 |
|
|
ctl_reg_in_lo_sig = 1;
|
76 |
|
|
db_hi_ds = 8'h81;
|
77 |
|
|
db_lo_ds = 8'h41;
|
78 |
|
|
ctl_reg_sys_hilo_sig = 2'b11;
|
79 |
|
|
ctl_reg_sys_we_hi_sig = 1; // 16-bit access
|
80 |
|
|
ctl_reg_sys_we_lo_sig = 1; // 16-bit access
|
81 |
|
|
ctl_reg_sel_wz_sig = 1; // WZ
|
82 |
|
|
`T db_hi_ds = 8'h82;
|
83 |
|
|
db_lo_ds = 8'h42;
|
84 |
|
|
ctl_reg_sel_wz_sig = 0; // WZ off
|
85 |
|
|
ctl_reg_sel_pc_sig = 1; // PC
|
86 |
|
|
`T db_hi_ds = 8'h83;
|
87 |
|
|
db_lo_ds = 8'h43;
|
88 |
|
|
ctl_reg_sel_pc_sig = 0; // PC off
|
89 |
|
|
ctl_reg_sel_ir_sig = 1; // IR
|
90 |
|
|
`T db_hi_ds = 'z;
|
91 |
|
|
db_lo_ds = 'z;
|
92 |
|
|
ctl_reg_sel_ir_sig = 0; // IR off
|
93 |
|
|
// Read back
|
94 |
|
|
ctl_sw_4d_sig = 0;
|
95 |
|
|
ctl_sw_4u_sig = 0; // Upstream
|
96 |
|
|
ctl_reg_in_hi_sig = 0;
|
97 |
|
|
ctl_reg_in_lo_sig = 0;
|
98 |
|
|
ctl_reg_out_hi_sig = 1;
|
99 |
|
|
ctl_reg_out_lo_sig = 1;
|
100 |
|
|
ctl_reg_sys_we_hi_sig = 0;
|
101 |
|
|
ctl_reg_sys_we_lo_sig = 0;
|
102 |
|
|
ctl_reg_sel_wz_sig = 1; // WZ
|
103 |
|
|
`T `CHECK(16'h8141);
|
104 |
|
|
ctl_reg_sel_wz_sig = 0; // WZ off
|
105 |
|
|
ctl_sw_4u_sig = 1; // Upstream
|
106 |
|
|
ctl_reg_sel_pc_sig = 1; // PC
|
107 |
|
|
`T `CHECK(16'h8242);
|
108 |
|
|
ctl_reg_sel_pc_sig = 0; // PC off
|
109 |
|
|
ctl_reg_sel_ir_sig = 1; // IR
|
110 |
|
|
`T `CHECK(16'h8343);
|
111 |
|
|
ctl_reg_sel_ir_sig = 0; // IR off
|
112 |
|
|
ctl_sw_4d_sig = 0;
|
113 |
|
|
ctl_sw_4u_sig = 0;
|
114 |
|
|
ctl_reg_sys_hilo_sig = 2'b00;
|
115 |
|
|
|
116 |
|
|
//------------------------------------------------------------
|
117 |
|
|
// Identify a 16-bit system register and check access to it
|
118 |
|
|
`T ctl_reg_in_hi_sig = 1;
|
119 |
|
|
ctl_reg_in_lo_sig = 1;
|
120 |
|
|
ctl_reg_out_hi_sig = 0;
|
121 |
|
|
ctl_reg_out_lo_sig = 0;
|
122 |
|
|
ctl_reg_gp_we_sig = 1; // Write to a GP register
|
123 |
|
|
ctl_reg_gp_hilo_sig = 2'b11;// 16-bit write
|
124 |
|
|
db_hi_ds = 8'hAA;
|
125 |
|
|
db_lo_ds = 8'h55;
|
126 |
|
|
ctl_reg_gp_sel_sig = 2'b00; // AF
|
127 |
|
|
`T db_hi_ds = 8'hAB;
|
128 |
|
|
db_lo_ds = 8'h56;
|
129 |
|
|
ctl_reg_gp_sel_sig = 2'b01; // BC
|
130 |
|
|
`T db_hi_ds = 8'hAC;
|
131 |
|
|
db_lo_ds = 8'h57;
|
132 |
|
|
ctl_reg_gp_sel_sig = 2'b10; // DE
|
133 |
|
|
`T db_hi_ds = 8'hAD;
|
134 |
|
|
db_lo_ds = 8'h58;
|
135 |
|
|
ctl_reg_gp_sel_sig = 2'b11; // HL
|
136 |
|
|
`T db_hi_ds = 'z;
|
137 |
|
|
db_lo_ds = 'z;
|
138 |
|
|
// Read back
|
139 |
|
|
ctl_reg_in_hi_sig = 0;
|
140 |
|
|
ctl_reg_in_lo_sig = 0;
|
141 |
|
|
ctl_reg_out_hi_sig = 1;
|
142 |
|
|
ctl_reg_out_lo_sig = 1;
|
143 |
|
|
ctl_reg_gp_we_sig = 0;
|
144 |
|
|
ctl_reg_gp_sel_sig = 2'b00; // Check AF
|
145 |
|
|
`T `CHECK(16'hAA55);
|
146 |
|
|
ctl_reg_gp_sel_sig = 2'b01; // Check BC
|
147 |
|
|
`T `CHECK(16'hAB56);
|
148 |
|
|
ctl_reg_gp_sel_sig = 2'b10; // Check DE
|
149 |
|
|
`T `CHECK(16'hAC57);
|
150 |
|
|
ctl_reg_gp_sel_sig = 2'b11; // Check HL
|
151 |
|
|
`T `CHECK(16'hAD58);
|
152 |
|
|
|
153 |
|
|
`T $display("End of test");
|
154 |
|
|
end
|
155 |
|
|
|
156 |
|
|
// Drive 3-state bidirectional buses with these statements
|
157 |
|
|
assign db_lo_as_sig = db_lo_as;
|
158 |
|
|
assign db_hi_as_sig = db_hi_as;
|
159 |
|
|
|
160 |
|
|
assign db_lo_ds_sig = db_lo_ds;
|
161 |
|
|
assign db_hi_ds_sig = db_hi_ds;
|
162 |
|
|
|
163 |
|
|
// Instantiate register control block
|
164 |
|
|
reg_control reg_control_inst
|
165 |
|
|
(
|
166 |
|
|
.ctl_reg_gp_sel(ctl_reg_gp_sel_sig) , // input [1:0] ctl_reg_gp_sel_sig
|
167 |
|
|
.ctl_reg_sys_hilo(ctl_reg_sys_hilo_sig),// input [1:0] ctl_reg_sys_hilo_sig
|
168 |
|
|
.ctl_reg_exx(ctl_reg_exx_sig) , // input ctl_reg_exx_sig
|
169 |
|
|
.ctl_reg_ex_af(ctl_reg_ex_af_sig) , // input ctl_reg_ex_af_sig
|
170 |
|
|
.ctl_reg_ex_de_hl(ctl_reg_ex_de_hl_sig),// input ctl_reg_ex_de_hl_sig
|
171 |
|
|
.ctl_reg_use_sp(ctl_reg_use_sp_sig) , // input ctl_reg_use_sp_sig
|
172 |
|
|
.ctl_reg_gp_hilo(ctl_reg_gp_hilo_sig) , // input [1:0] ctl_reg_gp_hilo_sig
|
173 |
|
|
.nreset(nreset) , // input nreset
|
174 |
|
|
.ctl_reg_sel_pc(ctl_reg_sel_pc_sig) , // input ctl_reg_sel_pc_sig
|
175 |
|
|
.ctl_reg_sel_ir(ctl_reg_sel_ir_sig) , // input ctl_reg_sel_ir_sig
|
176 |
|
|
.ctl_reg_sel_wz(ctl_reg_sel_wz_sig) , // input ctl_reg_sel_wz_sig
|
177 |
|
|
.ctl_reg_gp_we(ctl_reg_gp_we_sig) , // input ctl_reg_gp_we_sig
|
178 |
|
|
.ctl_reg_not_pc(ctl_reg_not_pc_sig) , // input ctl_reg_not_pc_sig
|
179 |
|
|
.use_ixiy(use_ixiy_sig) , // input use_ixiy_sig
|
180 |
|
|
.use_ix(use_ix_sig) , // input use_ix_sig
|
181 |
|
|
.ctl_reg_sys_we_lo(ctl_reg_sys_we_lo_sig),// input ctl_reg_sys_we_lo_sig
|
182 |
|
|
.ctl_reg_sys_we_hi(ctl_reg_sys_we_hi_sig),// input ctl_reg_sys_we_hi_sig
|
183 |
|
|
.ctl_reg_sys_we(ctl_reg_sys_we_sig) , // input ctl_reg_sys_we_sig
|
184 |
|
|
.clk(clk) , // input clk
|
185 |
8 |
gdevic |
.ctl_sw_4d (ctl_sw_4d_sig) , // input ctl_sw_4d
|
186 |
16 |
gdevic |
.nhold_clk_wait(nhold_clk_wait_sig) , // input nhold_clk_wait_sig
|
187 |
3 |
gdevic |
.reg_sel_bc(reg_sel_bc_sig) , // output reg_sel_bc_sig
|
188 |
|
|
.reg_sel_bc2(reg_sel_bc2_sig) , // output reg_sel_bc2_sig
|
189 |
|
|
.reg_sel_ix(reg_sel_ix_sig) , // output reg_sel_ix_sig
|
190 |
|
|
.reg_sel_iy(reg_sel_iy_sig) , // output reg_sel_iy_sig
|
191 |
|
|
.reg_sel_de(reg_sel_de_sig) , // output reg_sel_de_sig
|
192 |
|
|
.reg_sel_hl(reg_sel_hl_sig) , // output reg_sel_hl_sig
|
193 |
|
|
.reg_sel_de2(reg_sel_de2_sig) , // output reg_sel_de2_sig
|
194 |
|
|
.reg_sel_hl2(reg_sel_hl2_sig) , // output reg_sel_hl2_sig
|
195 |
|
|
.reg_sel_af(reg_sel_af_sig) , // output reg_sel_af_sig
|
196 |
|
|
.reg_sel_af2(reg_sel_af2_sig) , // output reg_sel_af2_sig
|
197 |
|
|
.reg_sel_wz(reg_sel_wz_sig) , // output reg_sel_wz_sig
|
198 |
|
|
.reg_sel_pc(reg_sel_pc_sig) , // output reg_sel_pc_sig
|
199 |
|
|
.reg_sel_ir(reg_sel_ir_sig) , // output reg_sel_ir_sig
|
200 |
|
|
.reg_sel_sp(reg_sel_sp_sig) , // output reg_sel_sp_sig
|
201 |
|
|
.reg_sel_gp_hi(reg_sel_gp_hi_sig) , // output reg_sel_gp_hi_sig
|
202 |
|
|
.reg_sel_gp_lo(reg_sel_gp_lo_sig) , // output reg_sel_gp_lo_sig
|
203 |
|
|
.reg_sel_sys_lo(reg_sel_sys_lo_sig) , // output reg_sel_sys_lo_sig
|
204 |
|
|
.reg_sel_sys_hi(reg_sel_sys_hi_sig) , // output reg_sel_sys_hi_sig
|
205 |
|
|
.reg_gp_we(reg_gp_we_sig) , // output reg_gp_we_sig
|
206 |
|
|
.reg_sys_we_lo(reg_sys_we_lo_sig) , // output reg_sys_we_lo_sig
|
207 |
8 |
gdevic |
.reg_sys_we_hi(reg_sys_we_hi_sig) , // output reg_sys_we_hi_sig
|
208 |
|
|
.reg_sw_4d_lo (reg_sw_4d_lo_sig) , // output reg_sw_4d_lo_sig
|
209 |
|
|
.reg_sw_4d_hi (reg_sw_4d_hi_sig) // output reg_sw_4d_hi_sig
|
210 |
3 |
gdevic |
);
|
211 |
|
|
|
212 |
|
|
// Instantiate register file block
|
213 |
|
|
reg_file reg_file_inst
|
214 |
|
|
(
|
215 |
|
|
.reg_sel_sys_lo(reg_sel_sys_lo_sig) , // input reg_sel_sys_lo_sig
|
216 |
|
|
.reg_sel_gp_lo(reg_sel_gp_lo_sig) , // input reg_sel_gp_lo_sig
|
217 |
|
|
.reg_sel_sys_hi(reg_sel_sys_hi_sig) , // input reg_sel_sys_hi_sig
|
218 |
|
|
.reg_sel_gp_hi(reg_sel_gp_hi_sig) , // input reg_sel_gp_hi_sig
|
219 |
|
|
.reg_sel_ir(reg_sel_ir_sig) , // input reg_sel_ir_sig
|
220 |
|
|
.reg_sel_pc(reg_sel_pc_sig) , // input reg_sel_pc_sig
|
221 |
8 |
gdevic |
.reg_sw_4d_lo(reg_sw_4d_lo_sig) , // input reg_sw_4d_lo_sig
|
222 |
|
|
.reg_sw_4d_hi(reg_sw_4d_hi_sig) , // input reg_sw_4d_hi_sig
|
223 |
3 |
gdevic |
.ctl_sw_4u(ctl_sw_4u_sig) , // input ctl_sw_4u_sig
|
224 |
|
|
.reg_sel_wz(reg_sel_wz_sig) , // input reg_sel_wz_sig
|
225 |
|
|
.reg_sel_sp(reg_sel_sp_sig) , // input reg_sel_sp_sig
|
226 |
|
|
.reg_sel_iy(reg_sel_iy_sig) , // input reg_sel_iy_sig
|
227 |
|
|
.reg_sel_ix(reg_sel_ix_sig) , // input reg_sel_ix_sig
|
228 |
|
|
.reg_sel_hl2(reg_sel_hl2_sig) , // input reg_sel_hl2_sig
|
229 |
|
|
.reg_sel_hl(reg_sel_hl_sig) , // input reg_sel_hl_sig
|
230 |
|
|
.reg_sel_de2(reg_sel_de2_sig) , // input reg_sel_de2_sig
|
231 |
|
|
.reg_sel_de(reg_sel_de_sig) , // input reg_sel_de_sig
|
232 |
|
|
.reg_sel_bc2(reg_sel_bc2_sig) , // input reg_sel_bc2_sig
|
233 |
|
|
.reg_sel_bc(reg_sel_bc_sig) , // input reg_sel_bc_sig
|
234 |
|
|
.reg_sel_af2(reg_sel_af2_sig) , // input reg_sel_af2_sig
|
235 |
|
|
.reg_sel_af(reg_sel_af_sig) , // input reg_sel_af_sig
|
236 |
|
|
.reg_gp_we(reg_gp_we_sig) , // input reg_gp_we_sig
|
237 |
|
|
.reg_sys_we_lo(reg_sys_we_lo_sig) , // input reg_sys_we_lo_sig
|
238 |
|
|
.reg_sys_we_hi(reg_sys_we_hi_sig) , // input reg_sys_we_hi_sig
|
239 |
|
|
.ctl_reg_in_hi(ctl_reg_in_hi_sig) , // input ctl_reg_in_hi_sig
|
240 |
|
|
.ctl_reg_in_lo(ctl_reg_in_lo_sig) , // input ctl_reg_in_lo_sig
|
241 |
|
|
.ctl_reg_out_lo(ctl_reg_out_lo_sig) , // input ctl_reg_out_lo_sig
|
242 |
|
|
.ctl_reg_out_hi(ctl_reg_out_hi_sig) , // input ctl_reg_out_hi_sig
|
243 |
|
|
.clk(clk) , // input clk
|
244 |
|
|
.db_lo_ds(db_lo_ds_sig) , // inout [7:0] db_lo_ds_sig
|
245 |
|
|
.db_hi_ds(db_hi_ds_sig) , // inout [7:0] db_hi_ds_sig
|
246 |
|
|
.db_lo_as(db_lo_as_sig) , // inout [7:0] db_lo_as_sig
|
247 |
|
|
.db_hi_as(db_hi_as_sig) // inout [7:0] db_hi_as_sig
|
248 |
|
|
);
|
249 |
|
|
|
250 |
|
|
endmodule
|