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 43

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 38 Revanth
reg eclass;
119
 
120 26 Revanth
// Next state logic.
121
always @*
122
begin
123
        // Default values.
124
        cp_dav_nxt              = cp_dav_ff;
125
        cp_word_nxt             = cp_word_ff;
126
        o_stall_from_decode     = 1'd0;
127
        o_instruction           = i_instruction;
128
        o_valid                 = i_valid;
129
        state_nxt               = state_ff;
130
        o_irq                   = i_irq;
131
        o_fiq                   = i_fiq;
132
 
133 43 Revanth
        eclass = 0;
134 38 Revanth
 
135 26 Revanth
        case ( state_ff )
136
        IDLE:
137
                // Activate only if no thumb, not in USER mode and CP15 access is requested.
138 38 Revanth
                casez ( (!i_cpsr_ff_t && (i_instruction[34:32] == 3'd0) && i_valid) ? i_instruction[31:0] : 35'd0 )
139 43 Revanth
                MRC, MCR, LDC, STC, CDP, MRC2, MCR2, LDC2, STC2:
140 26 Revanth
                begin
141 38 Revanth
                        if ( i_instruction[11:8] == 4'b1111 && i_cpsr_ff_mode != USR )  // CP15 and root access -- perfectly fine.
142
                        begin
143
                                // Send ANDNV R0, R0, R0 instruction.
144
                                o_instruction = {4'b1111, 28'd0};
145
                                o_valid       = 1'd0;
146
                                o_irq         = 1'd0;
147
                                o_fiq         = 1'd0;
148 26 Revanth
 
149 38 Revanth
                                // As long as there is an instruction to process...
150
                                if ( i_pipeline_dav )
151
                                begin
152
                                        // Do not impose any output. However, continue
153
                                        // to stall all before this unit in the 
154
                                        // pipeline.
155
                                        o_valid                 = 1'd0;
156
                                        o_stall_from_decode     = 1'd1;
157
                                        cp_dav_nxt              = 1'd0;
158
                                        cp_word_nxt             = 32'd0;
159
                                end
160
                                else
161
                                begin
162
                                        // Prepare to move to BUSY. Continue holding
163
                                        // stall. Send out 0s.
164
                                        o_valid                 = 1'd0;
165
                                        o_stall_from_decode     = 1'd1;
166
                                        cp_word_nxt             = i_instruction;
167
                                        cp_dav_nxt              = 1'd1;
168
                                        state_nxt               = BUSY;
169
                                end
170 26 Revanth
                        end
171 38 Revanth
                        else // Warning...
172 26 Revanth
                        begin
173 38 Revanth
 
174
                                if ( i_instruction[11:8] != 4'b1111 )
175
                                        eclass = 1;
176
                                else
177
                                        eclass = 2;
178
 
179
 
180
                                // Remain transparent since this is not a coprocessor
181
                                // instruction.
182
                                o_valid                 = i_valid;
183
                                o_instruction           = i_instruction;
184
                                o_irq                   = i_irq;
185
                                o_fiq                   = i_fiq;
186
                                cp_dav_nxt              = 0;
187
                                o_stall_from_decode     = 0;
188
                                cp_word_nxt             = {32{1'dx}}; // Don't care.
189 26 Revanth
                        end
190
                end
191
                default:
192
                begin
193
                        // Remain transparent since this is not a coprocessor
194
                        // instruction.
195
                        o_valid                 = i_valid;
196
                        o_instruction           = i_instruction;
197
                        o_irq                   = i_irq;
198
                        o_fiq                   = i_fiq;
199
                        cp_dav_nxt              = 0;
200
                        o_stall_from_decode     = 0;
201
                        cp_word_nxt             = {32{1'dx}}; // Don't care.
202
                end
203
                endcase
204
 
205
        BUSY:
206
        begin
207
                // Provide coprocessor word and valid to the coprocessor.
208
                cp_word_nxt             = cp_word_ff;
209
                cp_dav_nxt              = cp_dav_ff;
210
 
211
                // Continue holding stall.
212
                o_stall_from_decode     = 1'd1;
213
 
214
                // Send out nothing.
215
                o_valid                 = 1'd0;
216
                o_instruction           = 32'd0;
217
 
218
                // Block interrupts.
219
                o_irq = 1'd0;
220
                o_fiq = 1'd0;
221
 
222
                // If we get a response, we can move back to IDLE. Release
223
                // the stall so that processor can continue.
224
                if ( i_copro_done )
225
                begin
226
                        cp_dav_nxt              = 1'd0;
227
                        cp_word_nxt             = 32'd0;
228
                        state_nxt               = IDLE;
229
                        o_stall_from_decode     = 1'd0;
230
                end
231
        end
232
        endcase
233
end
234
 
235
always @ (posedge i_clk)
236
begin
237
        if ( i_reset )
238
        begin
239
                clear;
240
        end
241
        else if ( i_clear_from_writeback )
242
        begin
243
                clear;
244
        end
245
        else if ( i_data_stall )
246
        begin
247
                // Preserve values.
248
        end
249
        else if ( i_clear_from_alu )
250
        begin
251
                clear;
252
        end
253
        else if ( i_stall_from_shifter )
254
        begin
255
                // Preserve values.
256
        end
257
        else if ( i_stall_from_issue )
258
        begin
259
                // Preserve values.
260
        end
261
        else
262
        begin
263
                state_ff   <= state_nxt;
264
                cp_word_ff <= cp_word_nxt;
265
                cp_dav_ff  <= cp_dav_nxt;
266
        end
267
end
268
 
269
// Clear out the unit.
270
task clear;
271
begin
272
                state_ff            <= IDLE;
273
                cp_dav_ff           <= 1'd0;
274
end
275
endtask
276
 
277
endmodule
278
`default_nettype wire

powered by: WebSVN 2.1.0

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