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 51

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 51 Revanth
 
31 26 Revanth
module zap_predecode_coproc #(
32
        parameter PHY_REGS = 46
33
)
34
(
35
        input wire              i_clk,
36
        input wire              i_reset,
37
 
38
        // Instruction and valid qualifier.
39
        input wire [34:0]       i_instruction,
40
        input wire              i_valid,
41
 
42
        // CPSR Thumb Bit.
43
        input wire              i_cpsr_ff_t,
44
        input wire [4:0]        i_cpsr_ff_mode,
45
 
46
        // Interrupts.
47
        input wire              i_irq,
48
        input wire              i_fiq,
49
 
50
         // Clear and stall signals.
51
        input wire              i_clear_from_writeback, // | High Priority
52
        input wire              i_data_stall,           // |
53
        input wire              i_clear_from_alu,       // |
54
        input wire              i_stall_from_shifter,   // |
55
        input wire              i_stall_from_issue,     // V Low Priority
56
 
57
        // Pipeline Valid. Must become 0 when every stage of the pipeline
58
        // is invalid.
59
        input wire              i_pipeline_dav,
60
 
61
        // Coprocessor done signal.
62
        input wire              i_copro_done,
63
 
64
        // Interrupts output.
65
        output reg              o_irq,
66
        output reg              o_fiq,
67
 
68
        // Instruction and valid qualifier.
69
        output reg [34:0]       o_instruction,
70
        output reg              o_valid,
71
 
72
        // We can generate stall if coprocessor is slow. We also have
73
        // some minimal latency.
74
        output reg              o_stall_from_decode,
75
 
76
        // Are we really asking for the coprocessor ?
77
        output reg              o_copro_dav_ff,
78
 
79
        // The entire instruction is passed to the coprocessor.
80
        output reg  [31:0]      o_copro_word_ff
81
);
82
 
83
///////////////////////////////////////////////////////////////////////////////
84
 
85
`include "zap_defines.vh"
86
`include "zap_localparams.vh"
87
`include "zap_functions.vh"
88
 
89
///////////////////////////////////////////////////////////////////////////////
90
 
91
localparam IDLE = 0;
92
localparam BUSY = 1;
93
 
94
///////////////////////////////////////////////////////////////////////////////
95
 
96
// State register.
97
reg state_ff, state_nxt;
98
 
99
// Output registers.
100
reg        cp_dav_ff, cp_dav_nxt;
101
reg [31:0] cp_word_ff, cp_word_nxt;
102
 
103
///////////////////////////////////////////////////////////////////////////////
104
 
105
// Connect output registers to output.
106
always @*
107
begin
108
        o_copro_word_ff = cp_word_ff;
109
        o_copro_dav_ff  = cp_dav_ff;
110
end
111
 
112
///////////////////////////////////////////////////////////////////////////////
113
 
114
wire c1 = !i_cpsr_ff_t;
115
wire c2 = i_cpsr_ff_mode != USR;
116
wire c3 = i_instruction[11:8] == 4'b1111;
117
wire c4 = i_instruction[34:32] == 3'd0;
118
wire c5 = c1 & c2 & c3 & c4;
119 38 Revanth
reg eclass;
120
 
121 26 Revanth
// Next state logic.
122
always @*
123
begin
124
        // Default values.
125
        cp_dav_nxt              = cp_dav_ff;
126
        cp_word_nxt             = cp_word_ff;
127
        o_stall_from_decode     = 1'd0;
128
        o_instruction           = i_instruction;
129
        o_valid                 = i_valid;
130
        state_nxt               = state_ff;
131
        o_irq                   = i_irq;
132
        o_fiq                   = i_fiq;
133
 
134 43 Revanth
        eclass = 0;
135 38 Revanth
 
136 26 Revanth
        case ( state_ff )
137
        IDLE:
138
                // Activate only if no thumb, not in USER mode and CP15 access is requested.
139 38 Revanth
                casez ( (!i_cpsr_ff_t && (i_instruction[34:32] == 3'd0) && i_valid) ? i_instruction[31:0] : 35'd0 )
140 43 Revanth
                MRC, MCR, LDC, STC, CDP, MRC2, MCR2, LDC2, STC2:
141 26 Revanth
                begin
142 38 Revanth
                        if ( i_instruction[11:8] == 4'b1111 && i_cpsr_ff_mode != USR )  // CP15 and root access -- perfectly fine.
143
                        begin
144
                                // Send ANDNV R0, R0, R0 instruction.
145
                                o_instruction = {4'b1111, 28'd0};
146
                                o_valid       = 1'd0;
147
                                o_irq         = 1'd0;
148
                                o_fiq         = 1'd0;
149 26 Revanth
 
150 38 Revanth
                                // As long as there is an instruction to process...
151
                                if ( i_pipeline_dav )
152
                                begin
153
                                        // Do not impose any output. However, continue
154
                                        // to stall all before this unit in the 
155
                                        // pipeline.
156
                                        o_valid                 = 1'd0;
157
                                        o_stall_from_decode     = 1'd1;
158
                                        cp_dav_nxt              = 1'd0;
159
                                        cp_word_nxt             = 32'd0;
160
                                end
161
                                else
162
                                begin
163
                                        // Prepare to move to BUSY. Continue holding
164
                                        // stall. Send out 0s.
165
                                        o_valid                 = 1'd0;
166
                                        o_stall_from_decode     = 1'd1;
167
                                        cp_word_nxt             = i_instruction;
168
                                        cp_dav_nxt              = 1'd1;
169
                                        state_nxt               = BUSY;
170
                                end
171 26 Revanth
                        end
172 38 Revanth
                        else // Warning...
173 26 Revanth
                        begin
174 38 Revanth
 
175
                                if ( i_instruction[11:8] != 4'b1111 )
176
                                        eclass = 1;
177
                                else
178
                                        eclass = 2;
179
 
180
 
181
                                // Remain transparent since this is not a coprocessor
182
                                // instruction.
183
                                o_valid                 = i_valid;
184
                                o_instruction           = i_instruction;
185
                                o_irq                   = i_irq;
186
                                o_fiq                   = i_fiq;
187
                                cp_dav_nxt              = 0;
188
                                o_stall_from_decode     = 0;
189
                                cp_word_nxt             = {32{1'dx}}; // Don't care.
190 26 Revanth
                        end
191
                end
192
                default:
193
                begin
194
                        // Remain transparent since this is not a coprocessor
195
                        // instruction.
196
                        o_valid                 = i_valid;
197
                        o_instruction           = i_instruction;
198
                        o_irq                   = i_irq;
199
                        o_fiq                   = i_fiq;
200
                        cp_dav_nxt              = 0;
201
                        o_stall_from_decode     = 0;
202
                        cp_word_nxt             = {32{1'dx}}; // Don't care.
203
                end
204
                endcase
205
 
206
        BUSY:
207
        begin
208
                // Provide coprocessor word and valid to the coprocessor.
209
                cp_word_nxt             = cp_word_ff;
210
                cp_dav_nxt              = cp_dav_ff;
211
 
212
                // Continue holding stall.
213
                o_stall_from_decode     = 1'd1;
214
 
215
                // Send out nothing.
216
                o_valid                 = 1'd0;
217
                o_instruction           = 32'd0;
218
 
219
                // Block interrupts.
220
                o_irq = 1'd0;
221
                o_fiq = 1'd0;
222
 
223
                // If we get a response, we can move back to IDLE. Release
224
                // the stall so that processor can continue.
225
                if ( i_copro_done )
226
                begin
227
                        cp_dav_nxt              = 1'd0;
228
                        cp_word_nxt             = 32'd0;
229
                        state_nxt               = IDLE;
230
                        o_stall_from_decode     = 1'd0;
231
                end
232
        end
233
        endcase
234
end
235
 
236
always @ (posedge i_clk)
237
begin
238
        if ( i_reset )
239
        begin
240
                clear;
241
        end
242
        else if ( i_clear_from_writeback )
243
        begin
244
                clear;
245
        end
246
        else if ( i_data_stall )
247
        begin
248
                // Preserve values.
249
        end
250
        else if ( i_clear_from_alu )
251
        begin
252
                clear;
253
        end
254
        else if ( i_stall_from_shifter )
255
        begin
256
                // Preserve values.
257
        end
258
        else if ( i_stall_from_issue )
259
        begin
260
                // Preserve values.
261
        end
262
        else
263
        begin
264
                state_ff   <= state_nxt;
265
                cp_word_ff <= cp_word_nxt;
266
                cp_dav_ff  <= cp_dav_nxt;
267
        end
268
end
269
 
270
// Clear out the unit.
271
task clear;
272
begin
273
                state_ff            <= IDLE;
274
                cp_dav_ff           <= 1'd0;
275
end
276
endtask
277
 
278
endmodule
279 51 Revanth
 
280 26 Revanth
`default_nettype wire
281 51 Revanth
 
282
// ----------------------------------------------------------------------------
283
// EOF
284
// ----------------------------------------------------------------------------

powered by: WebSVN 2.1.0

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