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

Subversion Repositories zap

[/] [zap/] [trunk/] [src/] [rtl/] [cpu/] [zap_predecode_coproc.v] - Blame information for rev 41

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 41 Revanth
// ---------------------------------------------------------------------------
2
// --                                                                       --
3
// --                   (C) 2016-2018 Revanth Kamaraj.                      --
4
// --                                                                       -- 
5
// -- ------------------------------------------------------------------------
6
// --                                                                       --
7
// -- This program is free software; you can redistribute it and/or         --
8
// -- modify it under the terms of the GNU General Public License           --
9
// -- as published by the Free Software Foundation; either version 2        --
10
// -- of the License, or (at your option) any later version.                --
11
// --                                                                       --
12
// -- This program is distributed in the hope that it will be useful,       --
13
// -- but WITHOUT ANY WARRANTY; without even the implied warranty of        --
14
// -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         --
15
// -- GNU General Public License for more details.                          --
16
// --                                                                       --
17
// -- You should have received a copy of the GNU General Public License     --
18
// -- along with this program; if not, write to the Free Software           --
19
// -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA         --
20
// -- 02110-1301, USA.                                                      --
21
// --                                                                       --
22
// ---------------------------------------------------------------------------
23 26 Revanth
// Implements a simple coprocessor interface for the ZAP core. The interface
24
// is low bandwidth and thus is suited only for coprocessor that do not
25
// perform large data exchanges. Note that the translate function must be
26
// present in the coprocessor to account for CPU modes.
27
// ----------------------------------------------------------------------------
28
 
29
`default_nettype none
30
module zap_predecode_coproc #(
31
        parameter PHY_REGS = 46
32
)
33
(
34
        input wire              i_clk,
35
        input wire              i_reset,
36
 
37
        // Instruction and valid qualifier.
38
        input wire [34:0]       i_instruction,
39
        input wire              i_valid,
40
 
41
        // CPSR Thumb Bit.
42
        input wire              i_cpsr_ff_t,
43
        input wire [4:0]        i_cpsr_ff_mode,
44
 
45
        // Interrupts.
46
        input wire              i_irq,
47
        input wire              i_fiq,
48
 
49
         // Clear and stall signals.
50
        input wire              i_clear_from_writeback, // | High Priority
51
        input wire              i_data_stall,           // |
52
        input wire              i_clear_from_alu,       // |
53
        input wire              i_stall_from_shifter,   // |
54
        input wire              i_stall_from_issue,     // V Low Priority
55
 
56
        // Pipeline Valid. Must become 0 when every stage of the pipeline
57
        // is invalid.
58
        input wire              i_pipeline_dav,
59
 
60
        // Coprocessor done signal.
61
        input wire              i_copro_done,
62
 
63
        // Interrupts output.
64
        output reg              o_irq,
65
        output reg              o_fiq,
66
 
67
        // Instruction and valid qualifier.
68
        output reg [34:0]       o_instruction,
69
        output reg              o_valid,
70
 
71
        // We can generate stall if coprocessor is slow. We also have
72
        // some minimal latency.
73
        output reg              o_stall_from_decode,
74
 
75
        // Are we really asking for the coprocessor ?
76
        output reg              o_copro_dav_ff,
77
 
78
        // The entire instruction is passed to the coprocessor.
79
        output reg  [31:0]      o_copro_word_ff
80
);
81
 
82
///////////////////////////////////////////////////////////////////////////////
83
 
84
`include "zap_defines.vh"
85
`include "zap_localparams.vh"
86
`include "zap_functions.vh"
87
 
88
///////////////////////////////////////////////////////////////////////////////
89
 
90
localparam IDLE = 0;
91
localparam BUSY = 1;
92
 
93
///////////////////////////////////////////////////////////////////////////////
94
 
95
// State register.
96
reg state_ff, state_nxt;
97
 
98
// Output registers.
99
reg        cp_dav_ff, cp_dav_nxt;
100
reg [31:0] cp_word_ff, cp_word_nxt;
101
 
102
///////////////////////////////////////////////////////////////////////////////
103
 
104
// Connect output registers to output.
105
always @*
106
begin
107
        o_copro_word_ff = cp_word_ff;
108
        o_copro_dav_ff  = cp_dav_ff;
109
end
110
 
111
///////////////////////////////////////////////////////////////////////////////
112
 
113
wire c1 = !i_cpsr_ff_t;
114
wire c2 = i_cpsr_ff_mode != USR;
115
wire c3 = i_instruction[11:8] == 4'b1111;
116
wire c4 = i_instruction[34:32] == 3'd0;
117
wire c5 = c1 & c2 & c3 & c4;
118
 
119 38 Revanth
`ifndef SYNTHESIS
120
 
121
reg eclass;
122
 
123
`endif
124
 
125 26 Revanth
// Next state logic.
126
always @*
127
begin
128
        // Default values.
129
        cp_dav_nxt              = cp_dav_ff;
130
        cp_word_nxt             = cp_word_ff;
131
        o_stall_from_decode     = 1'd0;
132
        o_instruction           = i_instruction;
133
        o_valid                 = i_valid;
134
        state_nxt               = state_ff;
135
        o_irq                   = i_irq;
136
        o_fiq                   = i_fiq;
137
 
138 38 Revanth
        `ifndef SYNTHESIS
139
                eclass = 0;
140
        `endif
141
 
142 26 Revanth
        case ( state_ff )
143
        IDLE:
144
                // Activate only if no thumb, not in USER mode and CP15 access is requested.
145 38 Revanth
                casez ( (!i_cpsr_ff_t && (i_instruction[34:32] == 3'd0) && i_valid) ? i_instruction[31:0] : 35'd0 )
146 26 Revanth
                MRC, MCR, LDC, STC, CDP:
147
                begin
148 38 Revanth
                        if ( i_instruction[11:8] == 4'b1111 && i_cpsr_ff_mode != USR )  // CP15 and root access -- perfectly fine.
149
                        begin
150
                                // Send ANDNV R0, R0, R0 instruction.
151
                                o_instruction = {4'b1111, 28'd0};
152
                                o_valid       = 1'd0;
153
                                o_irq         = 1'd0;
154
                                o_fiq         = 1'd0;
155 26 Revanth
 
156 38 Revanth
                                // As long as there is an instruction to process...
157
                                if ( i_pipeline_dav )
158
                                begin
159
                                        // Do not impose any output. However, continue
160
                                        // to stall all before this unit in the 
161
                                        // pipeline.
162
                                        o_valid                 = 1'd0;
163
                                        o_stall_from_decode     = 1'd1;
164
                                        cp_dav_nxt              = 1'd0;
165
                                        cp_word_nxt             = 32'd0;
166
                                end
167
                                else
168
                                begin
169
                                        // Prepare to move to BUSY. Continue holding
170
                                        // stall. Send out 0s.
171
                                        o_valid                 = 1'd0;
172
                                        o_stall_from_decode     = 1'd1;
173
                                        cp_word_nxt             = i_instruction;
174
                                        cp_dav_nxt              = 1'd1;
175
                                        state_nxt               = BUSY;
176
                                end
177 26 Revanth
                        end
178 38 Revanth
                        else // Warning...
179 26 Revanth
                        begin
180 38 Revanth
                                `ifndef SYNTHESIS
181
 
182
                                if ( i_instruction[11:8] != 4'b1111 )
183
                                        eclass = 1;
184
                                else
185
                                        eclass = 2;
186
 
187
                                `endif
188
 
189
                                // Remain transparent since this is not a coprocessor
190
                                // instruction.
191
                                o_valid                 = i_valid;
192
                                o_instruction           = i_instruction;
193
                                o_irq                   = i_irq;
194
                                o_fiq                   = i_fiq;
195
                                cp_dav_nxt              = 0;
196
                                o_stall_from_decode     = 0;
197
                                cp_word_nxt             = {32{1'dx}}; // Don't care.
198 26 Revanth
                        end
199
                end
200
                default:
201
                begin
202
                        // Remain transparent since this is not a coprocessor
203
                        // instruction.
204
                        o_valid                 = i_valid;
205
                        o_instruction           = i_instruction;
206
                        o_irq                   = i_irq;
207
                        o_fiq                   = i_fiq;
208
                        cp_dav_nxt              = 0;
209
                        o_stall_from_decode     = 0;
210
                        cp_word_nxt             = {32{1'dx}}; // Don't care.
211
                end
212
                endcase
213
 
214
        BUSY:
215
        begin
216
                // Provide coprocessor word and valid to the coprocessor.
217
                cp_word_nxt             = cp_word_ff;
218
                cp_dav_nxt              = cp_dav_ff;
219
 
220
                // Continue holding stall.
221
                o_stall_from_decode     = 1'd1;
222
 
223
                // Send out nothing.
224
                o_valid                 = 1'd0;
225
                o_instruction           = 32'd0;
226
 
227
                // Block interrupts.
228
                o_irq = 1'd0;
229
                o_fiq = 1'd0;
230
 
231
                // If we get a response, we can move back to IDLE. Release
232
                // the stall so that processor can continue.
233
                if ( i_copro_done )
234
                begin
235
                        cp_dav_nxt              = 1'd0;
236
                        cp_word_nxt             = 32'd0;
237
                        state_nxt               = IDLE;
238
                        o_stall_from_decode     = 1'd0;
239
                end
240
        end
241
        endcase
242
end
243
 
244
always @ (posedge i_clk)
245
begin
246
        if ( i_reset )
247
        begin
248
                clear;
249
        end
250
        else if ( i_clear_from_writeback )
251
        begin
252
                clear;
253
        end
254
        else if ( i_data_stall )
255
        begin
256
                // Preserve values.
257
        end
258
        else if ( i_clear_from_alu )
259
        begin
260
                clear;
261
        end
262
        else if ( i_stall_from_shifter )
263
        begin
264
                // Preserve values.
265
        end
266
        else if ( i_stall_from_issue )
267
        begin
268
                // Preserve values.
269
        end
270
        else
271
        begin
272
                state_ff   <= state_nxt;
273
                cp_word_ff <= cp_word_nxt;
274
                cp_dav_ff  <= cp_dav_nxt;
275
        end
276
end
277
 
278
// Clear out the unit.
279
task clear;
280
begin
281
                state_ff            <= IDLE;
282
                cp_dav_ff           <= 1'd0;
283
end
284
endtask
285
 
286
endmodule
287
`default_nettype wire

powered by: WebSVN 2.1.0

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