OpenCores
URL https://opencores.org/ocsvn/klc32/klc32/trunk

Subversion Repositories klc32

[/] [klc32/] [trunk/] [bench/] [KLC32_tb.v] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 robfinch
// ============================================================================
2
// (C) 2011 Robert Finch
3
// All Rights Reserved.
4
// robfinch<remove>@opencores.org
5
//
6
// KLC32 - 32 bit CPU
7
// KLC32_tb - testbench for KLC32
8
//
9
// This source file is free software: you can redistribute it and/or modify 
10
// it under the terms of the GNU Lesser General Public License as published 
11
// by the Free Software Foundation, either version 3 of the License, or     
12
// (at your option) any later version.                                      
13
//                                                                          
14
// This source file is distributed in the hope that it will be useful,      
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
17
// GNU General Public License for more details.                             
18
//                                                                          
19
// You should have received a copy of the GNU General Public License        
20
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
21
//                                                                          
22
// ============================================================================
23
//
24
module KLC32_tb();
25
reg clk;
26
reg rst;
27
wire sys_inta;
28
wire [2:0] sys_fc;
29
wire sys_cyc;
30
wire sys_stb;
31
wire sys_we;
32
wire [3:0] sys_sel;
33
wire [31:0] sys_adr;
34
wire [31:0] sys_dbo;
35
wire [31:0] sys_dbi;
36
wire sys_rst;
37
reg [31:0] romout;
38
wire sys_ack;
39
wire [31:0] ram_dbo;
40
wire [31:0] stk_dbo;
41
reg nmi;
42
 
43
assign sys_ack = sys_stb;
44
 
45
wire ram_cs = sys_adr < 32'h0010000 || sys_adr[32:16]==16'hFFD0;
46
wire stk_cs = sys_adr[31:16]==16'hFFFE;
47
 
48
 
49
initial begin
50
        clk = 1;
51
        rst = 0;
52
        #100 rst = 1;
53
        #100 rst = 0;
54
end
55
 
56
always #6.8 clk = ~clk; //  73.529 MHz
57
 
58
always @(sys_adr)
59
casex(sys_adr & 32'hFFFFFFFC)
60
32'h00000000:   romout <= 32'hFFFE_07FC;        // initial SP   
61
32'h00000004:   romout <= 32'hFFFF_0000;        // initial PC
62
32'h0000xxxx:   romout <= ram_dbo;
63
32'hFFFF0000:   romout <= 32'h00000034;         // RST
64
32'hFFFF0004:   romout <= 32'h24018000;         // ORI R1,R0,#$FFD00000
65
32'hFFFF0008:   romout <= 32'hFFD00000;
66
32'hFFFF000C:   romout <= 32'h24020005;         // ORI R2,R0,#5
67
32'hFFFF0010:   romout <= 32'h24030020;         // ORI R3,R0,#32
68
// J1:
69
32'hFFFF0014:   romout <= 32'hE4230000;         // SH R3,(R1)
70
32'hFFFF0018:   romout <= 32'h10210002;         // ADDI R1,R1,#2
71
32'hFFFF001C:   romout <= 32'h14420001;         // SUBI R2,R2,#1
72
32'hFFFF0020:   romout <= 32'h4006FFF0;         // BNE CR0,J1
73
32'hFFFExxxx:   romout <= stk_dbo;
74
endcase
75
assign sys_dbi = romout;
76
 
77
KLC32 u1
78
(
79
        .rst_i(rst),
80
        .clk_i(clk),
81
        .halt_i(1'b0),
82
        .ipl_i(3'b000),
83
        .vpa_i(1'b0),
84
        .err_i(1'b0),
85
        .inta_o(sys_inta),
86
        .fc_o(sys_fc),
87
        .rst_o(sys_rst),
88
        .cyc_o(sys_cyc),
89
        .stb_o(sys_stb),
90
        .ack_i(sys_ack),
91
        .we_o(sys_we),
92
        .sel_o(sys_sel),
93
        .adr_o(sys_adr),
94
        .dat_i(sys_dbi),
95
        .dat_o(sys_dbo)
96
);
97
 
98
fict_ram u2 (clk, ram_cs, sys_we, sys_sel, sys_adr[17:0],sys_dbo,ram_dbo);
99
fict_ram u3 (clk, stk_cs, sys_we, sys_sel, sys_adr[17:0],sys_dbo,stk_dbo);
100
 
101
endmodule
102
 
103
module fict_ram(clk, cs, we, sel_i, adr, dat_i, dat_o);
104
input clk;
105
input cs;
106
input we;
107
input [3:0] sel_i;
108
input [17:0] adr;
109
input [31:0] dat_i;
110
output [31:0] dat_o;
111
 
112
reg [31:0] mem [65535:0];
113
 
114
always @(posedge clk)
115
begin
116
        if (cs & we) begin
117
                $display("Wrote mem[%h] with %h", adr, dat_i);
118
                if (sel_i[0]) mem[adr[17:2]][ 7: 0] <= dat_i[ 7: 0];
119
                if (sel_i[1]) mem[adr[17:2]][15: 8] <= dat_i[15: 8];
120
                if (sel_i[2]) mem[adr[17:2]][23:16] <= dat_i[23:16];
121
                if (sel_i[3]) mem[adr[17:2]][31:24] <= dat_i[31:24];
122
        end
123
end
124
 
125
assign dat_o = mem[adr[17:2]];
126
 
127
endmodule
128
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.