1 |
2 |
vinogradov |
//////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Project Qrisc32 is risc cpu implementation, purpose is studying
|
3 |
|
|
// Digital System Design course at Kyoung Hee University during my PhD earning
|
4 |
|
|
// Copyright (C) 2010 Vinogradov Viacheslav
|
5 |
|
|
//
|
6 |
|
|
// This library is free software; you can redistribute it and/or
|
7 |
|
|
// modify it under the terms of the GNU Lesser General Public
|
8 |
|
|
// License as published by the Free Software Foundation; either
|
9 |
|
|
// version 2.1 of the License, or (at your option) any later version.
|
10 |
|
|
//
|
11 |
|
|
// This library is distributed in the hope that it will be useful,
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
|
|
// Lesser General Public License for more details.
|
15 |
|
|
//
|
16 |
|
|
// You should have received a copy of the GNU Lesser General Public
|
17 |
|
|
// License along with this library; if not, write to the Free Software
|
18 |
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
19 |
|
|
//
|
20 |
|
|
//
|
21 |
|
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
22 |
|
|
|
23 |
|
|
//-------------------------------------------------------------------------------------------
|
24 |
|
|
// Title : qrisc32
|
25 |
|
|
// Design : qrisc32
|
26 |
|
|
// Author : vinogradov@opencores.org
|
27 |
|
|
//5 stages risc cpu
|
28 |
|
|
//with 3 avalon interfaces:
|
29 |
|
|
// - Data Read Avalon interface
|
30 |
|
|
// - Data Write Avalon interface
|
31 |
|
|
// - Instruction Read Avalon interface
|
32 |
|
|
//--------------------------------------------------------------------------------------------
|
33 |
|
|
|
34 |
|
|
`timescale 1 ns / 1 ns
|
35 |
|
|
|
36 |
|
|
module qrisc32(
|
37 |
|
|
input clk,reset,
|
38 |
|
|
|
39 |
|
|
//avalon master port only for reading instructions
|
40 |
|
|
input[31:0] avm_instructions_data,
|
41 |
|
|
output[31:0] avm_instructions_addr,
|
42 |
|
|
output avm_instructions_rd,
|
43 |
|
|
input avm_instructions_wait_req,
|
44 |
|
|
|
45 |
|
|
//avalon master port only for reading data avm_data_read
|
46 |
|
|
input[31:0] avm_datar_data,
|
47 |
|
|
output[31:0] avm_datar_addr,
|
48 |
|
|
output avm_datar_rd,
|
49 |
|
|
input avm_datar_wait_req,
|
50 |
|
|
|
51 |
|
|
//avalon master port only for writing data
|
52 |
|
|
output[31:0] avm_dataw_data,
|
53 |
|
|
output[31:0] avm_dataw_addr,
|
54 |
|
|
output avm_dataw_wr,
|
55 |
|
|
input avm_dataw_wait_req,
|
56 |
|
|
|
57 |
|
|
input verbose//for simlation
|
58 |
|
|
|
59 |
|
|
);
|
60 |
|
|
|
61 |
|
|
import risc_pack::*;
|
62 |
|
|
|
63 |
|
|
avalon_port avm_instructions(),avm_data_read(),avm_data_write();
|
64 |
|
|
|
65 |
|
|
//Instruction read port
|
66 |
|
|
assign avm_instructions.data_r = avm_instructions_data;
|
67 |
|
|
assign avm_instructions_addr = avm_instructions.address_r;
|
68 |
|
|
assign avm_instructions_rd = avm_instructions.rd;
|
69 |
|
|
assign avm_instructions.wait_req = avm_instructions_wait_req;
|
70 |
|
|
|
71 |
|
|
//Data read port
|
72 |
|
|
assign avm_data_read.data_r = avm_datar_data;
|
73 |
|
|
assign avm_datar_addr = avm_data_read.address_r;
|
74 |
|
|
assign avm_datar_rd = avm_data_read.rd;
|
75 |
|
|
assign avm_data_read.wait_req = avm_datar_wait_req;
|
76 |
|
|
|
77 |
|
|
//Data write port
|
78 |
|
|
assign avm_dataw_data = avm_data_write.data_w;
|
79 |
|
|
assign avm_dataw_addr = avm_data_write.address_r;
|
80 |
|
|
assign avm_dataw_wr = avm_data_write.wr;
|
81 |
|
|
assign avm_data_write.wait_req = avm_dataw_wait_req;
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
pipe_struct // I decode - Ex - MEM access
|
85 |
|
|
pipe_id_out,pipe_ex_out,pipe_mem_out;
|
86 |
|
|
|
87 |
|
|
wire[31:0] instruction,pc;
|
88 |
|
|
wire new_address_valid_ex;
|
89 |
|
|
wire[31:0] new_address_ex;
|
90 |
|
|
|
91 |
|
|
wire new_address_valid_mem;
|
92 |
|
|
wire[31:0] new_address_mem;
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
wire pipe_stall;
|
96 |
|
|
|
97 |
|
|
qrisc32_IF qrisc32_IF(
|
98 |
|
|
.clk(clk),
|
99 |
|
|
.reset(reset),
|
100 |
|
|
.pipe_stall(pipe_stall),
|
101 |
|
|
.avm_instructions(avm_instructions),
|
102 |
|
|
.new_address_valid(new_address_valid_ex),
|
103 |
|
|
.new_address(new_address_ex),
|
104 |
|
|
|
105 |
|
|
.instruction(instruction),
|
106 |
|
|
.pc(pc)
|
107 |
|
|
);
|
108 |
|
|
|
109 |
|
|
qrisc32_ID qrisc32_ID(
|
110 |
|
|
.clk(clk),
|
111 |
|
|
.reset(reset),
|
112 |
|
|
.pipe_stall(pipe_stall),
|
113 |
|
|
.instruction(instruction),
|
114 |
|
|
.pc(pc),
|
115 |
|
|
.pipe_wb_mem(pipe_mem_out),//for memory read
|
116 |
|
|
.pipe_wb_ex(pipe_ex_out),//for R2 register and ALU operations only
|
117 |
|
|
.pipe_id_out(pipe_id_out),
|
118 |
|
|
.verbose(verbose)
|
119 |
|
|
);
|
120 |
|
|
|
121 |
|
|
qrisc32_EX qrisc32_EX(
|
122 |
|
|
.clk(clk),
|
123 |
|
|
.reset(reset),
|
124 |
|
|
.pipe_stall(pipe_stall),
|
125 |
|
|
.pipe_ex_in(pipe_id_out),
|
126 |
|
|
.pipe_ex_out(pipe_ex_out),
|
127 |
|
|
.new_address_valid(new_address_valid_ex),
|
128 |
|
|
.new_address(new_address_ex)
|
129 |
|
|
);
|
130 |
|
|
|
131 |
|
|
qrisc32_MEM qrisc32_MEM(
|
132 |
|
|
.clk(clk),
|
133 |
|
|
.reset(reset),
|
134 |
|
|
.pipe_mem_in(pipe_ex_out),
|
135 |
|
|
.avm_data_read(avm_data_read),
|
136 |
|
|
.avm_data_write(avm_data_write),
|
137 |
|
|
.pipe_mem_out(pipe_mem_out),
|
138 |
|
|
.pipe_stall(pipe_stall),
|
139 |
|
|
.verbose(verbose)
|
140 |
|
|
);
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
endmodule
|