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

Subversion Repositories darkriscv

[/] [darkriscv/] [trunk/] [rtl/] [darkriscv.v] - Blame information for rev 4

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

Line No. Rev Author Line
1 2 marcelos
/*
2
 * Copyright (c) 2018, Marcelo Samsoniuk
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * * Redistributions of source code must retain the above copyright notice, this
9
 *   list of conditions and the following disclaimer.
10
 *
11
 * * Redistributions in binary form must reproduce the above copyright notice,
12
 *   this list of conditions and the following disclaimer in the documentation
13
 *   and/or other materials provided with the distribution.
14
 *
15
 * * Neither the name of the copyright holder nor the names of its
16
 *   contributors may be used to endorse or promote products derived from
17
 *   this software without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 */
30
 
31
`timescale 1ns / 1ps
32
 
33
// implemented opcodes:
34
 
35
`define LUI     7'b01101_11      // lui   rd,imm[31:12]
36
`define AUIPC   7'b00101_11      // auipc rd,imm[31:12]
37
`define JAL     7'b11011_11      // jal   rd,imm[xxxxx]
38
`define JALR    7'b11001_11      // jalr  rd,rs1,imm[11:0] 
39
`define BCC     7'b11000_11      // bcc   rs1,rs2,imm[12:1]
40
`define LCC     7'b00000_11      // lxx   rd,rs1,imm[11:0]
41
`define SCC     7'b01000_11      // sxx   rs1,rs2,imm[11:0]
42
`define MCC     7'b00100_11      // xxxi  rd,rs1,imm[11:0]
43
`define RCC     7'b01100_11      // xxx   rd,rs1,rs2 
44
`define MAC     7'b11111_11      // mac   rd,rs1,rs2
45
 
46
// not implemented opcodes:
47
 
48
`define FCC     7'b00011_11      // fencex
49
`define CCC     7'b11100_11      // exx, csrxx
50
 
51
// configuration file
52
 
53
`include "../rtl/config.vh"
54
 
55
module darkriscv
56
//#(
57
//    parameter [31:0] RESET_PC = 0,
58
//    parameter [31:0] RESET_SP = 4096
59
//) 
60
(
61
    input             CLK,   // clock
62
    input             RES,   // reset
63
    input             HLT,   // halt
64
 
65 4 marcelos
//`ifdef __THREADING__    
66
//    input             IREQ,  // irq req
67
//`endif    
68 2 marcelos
 
69
    input      [31:0] IDATA, // instruction data bus
70
    output     [31:0] IADDR, // instruction addr bus
71
 
72
    input      [31:0] DATAI, // data bus (input)
73
    output     [31:0] DATAO, // data bus (output)
74
    output     [31:0] DADDR, // addr bus
75
 
76
`ifdef __FLEXBUZZ__
77
    output     [ 2:0] DLEN, // data length
78
    output            RW,   // data read/write
79
`else
80
    output     [ 3:0] BE,   // byte enable
81
    output            WR,    // write enable
82
    output            RD,    // read enable 
83
`endif
84 4 marcelos
 
85
`ifdef SIMULATION
86
    input         FINISH_REQ,
87
`endif
88 2 marcelos
    output [3:0]  DEBUG      // old-school osciloscope based debug! :)
89
);
90
 
91
    // dummy 32-bit words w/ all-0s and all-1s: 
92
 
93
    wire [31:0] ALL0  = 0;
94
    wire [31:0] ALL1  = -1;
95
 
96
`ifdef __THREADING__
97 4 marcelos
    reg XMODE = 0;     // thread ptr
98 2 marcelos
`endif
99
 
100
    // pre-decode: IDATA is break apart as described in the RV32I specification
101
 
102
    reg [31:0] XIDATA;
103
 
104
    reg XLUI, XAUIPC, XJAL, XJALR, XBCC, XLCC, XSCC, XMCC, XRCC, XMAC, XRES=1; //, XFCC, XCCC;
105
 
106
    reg [31:0] XSIMM;
107
    reg [31:0] XUIMM;
108
 
109
    always@(posedge CLK)
110
    begin
111
        XIDATA <= XRES ? 0 : HLT ? XIDATA : IDATA;
112
 
113
        XLUI   <= XRES ? 0 : HLT ? XLUI   : IDATA[6:0]==`LUI;
114
        XAUIPC <= XRES ? 0 : HLT ? XAUIPC : IDATA[6:0]==`AUIPC;
115
        XJAL   <= XRES ? 0 : HLT ? XJAL   : IDATA[6:0]==`JAL;
116
        XJALR  <= XRES ? 0 : HLT ? XJALR  : IDATA[6:0]==`JALR;
117
 
118
        XBCC   <= XRES ? 0 : HLT ? XBCC   : IDATA[6:0]==`BCC;
119
        XLCC   <= XRES ? 0 : HLT ? XLCC   : IDATA[6:0]==`LCC;
120
        XSCC   <= XRES ? 0 : HLT ? XSCC   : IDATA[6:0]==`SCC;
121
        XMCC   <= XRES ? 0 : HLT ? XMCC   : IDATA[6:0]==`MCC;
122
 
123
        XRCC   <= XRES ? 0 : HLT ? XRCC   : IDATA[6:0]==`RCC;
124
        XMAC   <= XRES ? 0 : HLT ? XRCC   : IDATA[6:0]==`MAC;
125
        //XFCC   <= XRES ? 0 : HLT ? XFCC   : IDATA[6:0]==`FCC;
126
        //XCCC   <= XRES ? 0 : HLT ? XCCC   : IDATA[6:0]==`CCC;
127
 
128
        // signal extended immediate, according to the instruction type:
129
 
130
        XSIMM  <= XRES ? 0 : HLT ? XSIMM :
131
                 IDATA[6:0]==`SCC ? { IDATA[31] ? ALL1[31:12]:ALL0[31:12], IDATA[31:25],IDATA[11:7] } : // s-type
132
                 IDATA[6:0]==`BCC ? { IDATA[31] ? ALL1[31:13]:ALL0[31:13], IDATA[31],IDATA[7],IDATA[30:25],IDATA[11:8],ALL0[0] } : // b-type
133
                 IDATA[6:0]==`JAL ? { IDATA[31] ? ALL1[31:21]:ALL0[31:21], IDATA[31], IDATA[19:12], IDATA[20], IDATA[30:21], ALL0[0] } : // j-type
134
                 IDATA[6:0]==`LUI||
135
                 IDATA[6:0]==`AUIPC ? { IDATA[31:12], ALL0[11:0] } : // u-type
136
                                      { IDATA[31] ? ALL1[31:12]:ALL0[31:12], IDATA[31:20] }; // i-type
137
        // non-signal extended immediate, according to the instruction type:
138
 
139
        XUIMM  <= XRES ? 0: HLT ? XUIMM :
140
                 IDATA[6:0]==`SCC ? { ALL0[31:12], IDATA[31:25],IDATA[11:7] } : // s-type
141
                 IDATA[6:0]==`BCC ? { ALL0[31:13], IDATA[31],IDATA[7],IDATA[30:25],IDATA[11:8],ALL0[0] } : // b-type
142
                 IDATA[6:0]==`JAL ? { ALL0[31:21], IDATA[31], IDATA[19:12], IDATA[20], IDATA[30:21], ALL0[0] } : // j-type
143
                 IDATA[6:0]==`LUI||
144
                 IDATA[6:0]==`AUIPC ? { IDATA[31:12], ALL0[11:0] } : // u-type
145
                                      { ALL0[31:12], IDATA[31:20] }; // i-type
146
    end
147
 
148
    // decode: after XIDATA
149
`ifdef __3STAGE__
150
    reg [1:0] FLUSH = -1;  // flush instruction pipeline
151
`else
152
    reg FLUSH = -1;  // flush instruction pipeline
153
`endif
154
 
155
`ifdef __THREADING__
156
 
157
    `ifdef __RV32E__
158
 
159
        reg [4:0] RESMODE = -1;
160
 
161
        wire [4:0] DPTR   = XRES ? RESMODE : { XMODE, XIDATA[10: 7] }; // set SP_RESET when RES==1
162
        wire [4:0] S1PTR  = { XMODE, XIDATA[18:15] };
163
        wire [4:0] S2PTR  = { XMODE, XIDATA[23:20] };
164
    `else
165
        reg [5:0] RESMODE = -1;
166
 
167
        wire [5:0] DPTR   = XRES ? RESMODE : { XMODE, XIDATA[11: 7] }; // set SP_RESET when RES==1
168
        wire [5:0] S1PTR  = { XMODE, XIDATA[19:15] };
169
        wire [5:0] S2PTR  = { XMODE, XIDATA[24:20] };
170
    `endif
171
 
172
    wire [6:0] OPCODE = FLUSH ? 0 : XIDATA[6:0];
173
    wire [2:0] FCT3   = XIDATA[14:12];
174
    wire [6:0] FCT7   = XIDATA[31:25];
175
 
176
`else
177
 
178
    `ifdef __RV32E__
179
 
180
        reg [3:0] RESMODE = -1;
181
 
182
        wire [3:0] DPTR   = XRES ? RESMODE : XIDATA[10: 7]; // set SP_RESET when RES==1
183
        wire [3:0] S1PTR  = XIDATA[18:15];
184
        wire [3:0] S2PTR  = XIDATA[23:20];
185
    `else
186
        reg [4:0] RESMODE = -1;
187
 
188
        wire [4:0] DPTR   = XRES ? RESMODE : XIDATA[11: 7]; // set SP_RESET when RES==1
189
        wire [4:0] S1PTR  = XIDATA[19:15];
190
        wire [4:0] S2PTR  = XIDATA[24:20];
191
    `endif
192
 
193
    wire [6:0] OPCODE = FLUSH ? 0 : XIDATA[6:0];
194
    wire [2:0] FCT3   = XIDATA[14:12];
195
    wire [6:0] FCT7   = XIDATA[31:25];
196
 
197
`endif
198
 
199
    wire [31:0] SIMM  = XSIMM;
200
    wire [31:0] UIMM  = XUIMM;
201
 
202
    // main opcode decoder:
203
 
204
    wire    LUI = FLUSH ? 0 : XLUI;   // OPCODE==7'b0110111;
205
    wire  AUIPC = FLUSH ? 0 : XAUIPC; // OPCODE==7'b0010111;
206
    wire    JAL = FLUSH ? 0 : XJAL;   // OPCODE==7'b1101111;
207
    wire   JALR = FLUSH ? 0 : XJALR;  // OPCODE==7'b1100111;
208
 
209
    wire    BCC = FLUSH ? 0 : XBCC; // OPCODE==7'b1100011; //FCT3
210
    wire    LCC = FLUSH ? 0 : XLCC; // OPCODE==7'b0000011; //FCT3
211
    wire    SCC = FLUSH ? 0 : XSCC; // OPCODE==7'b0100011; //FCT3
212
    wire    MCC = FLUSH ? 0 : XMCC; // OPCODE==7'b0010011; //FCT3
213
 
214
    wire    RCC = FLUSH ? 0 : XRCC; // OPCODE==7'b0110011; //FCT3
215
    wire    MAC = FLUSH ? 0 : XMAC; // OPCODE==7'b0110011; //FCT3
216
    //wire    FCC = FLUSH ? 0 : XFCC; // OPCODE==7'b0001111; //FCT3
217
    //wire    CCC = FLUSH ? 0 : XCCC; // OPCODE==7'b1110011; //FCT3
218
 
219
`ifdef __THREADING__
220
`ifdef __3STAGE__
221
    reg [31:0] NXPC2 [0:1];       // 32-bit program counter t+2
222
`endif
223
    reg [31:0] NXPC;        // 32-bit program counter t+1
224
    reg [31:0] PC;                   // 32-bit program counter t+0
225
 
226
    `ifdef __RV32E__
227
        reg [31:0] REG1 [0:31];   // general-purpose 16x32-bit registers (s1)
228
        reg [31:0] REG2 [0:31];   // general-purpose 16x32-bit registers (s2)
229
    `else
230
        reg [31:0] REG1 [0:63];   // general-purpose 32x32-bit registers (s1)
231
        reg [31:0] REG2 [0:63];   // general-purpose 32x32-bit registers (s2)    
232
    `endif
233
`else
234
`ifdef __3STAGE__
235
    reg [31:0] NXPC2;       // 32-bit program counter t+2
236
`endif
237
    reg [31:0] NXPC;        // 32-bit program counter t+1
238
    reg [31:0] PC;                   // 32-bit program counter t+0
239
 
240
    `ifdef __RV32E__
241
        reg [31:0] REG1 [0:15];   // general-purpose 16x32-bit registers (s1)
242
        reg [31:0] REG2 [0:15];   // general-purpose 16x32-bit registers (s2)
243
    `else
244
        reg [31:0] REG1 [0:31];   // general-purpose 32x32-bit registers (s1)
245
        reg [31:0] REG2 [0:31];   // general-purpose 32x32-bit registers (s2)
246
    `endif
247
`endif
248
 
249
    // source-1 and source-1 register selection
250
 
251
    wire signed   [31:0] S1REG = REG1[S1PTR];
252
    wire signed   [31:0] S2REG = REG2[S2PTR];
253
 
254
    wire          [31:0] U1REG = REG1[S1PTR];
255
    wire          [31:0] U2REG = REG2[S2PTR];
256
 
257
    // L-group of instructions (OPCODE==7'b0000011)
258
 
259
`ifdef __FLEXBUZZ__
260
 
261
    wire [31:0] LDATA = FCT3[1:0]==0 ? { FCT3[2]==0&&DATAI[ 7] ? ALL1[31: 8]:ALL0[31: 8] , DATAI[ 7: 0] } :
262
                        FCT3[1:0]==1 ? { FCT3[2]==0&&DATAI[15] ? ALL1[31:16]:ALL0[31:16] , DATAI[15: 0] } :
263
                                        DATAI;
264
`else
265
    wire [31:0] LDATA = FCT3==0||FCT3==4 ? ( DADDR[1:0]==3 ? { FCT3==0&&DATAI[31] ? ALL1[31: 8]:ALL0[31: 8] , DATAI[31:24] } :
266
                                             DADDR[1:0]==2 ? { FCT3==0&&DATAI[23] ? ALL1[31: 8]:ALL0[31: 8] , DATAI[23:16] } :
267
                                             DADDR[1:0]==1 ? { FCT3==0&&DATAI[15] ? ALL1[31: 8]:ALL0[31: 8] , DATAI[15: 8] } :
268
                                                             { FCT3==0&&DATAI[ 7] ? ALL1[31: 8]:ALL0[31: 8] , DATAI[ 7: 0] } ):
269
                        FCT3==1||FCT3==5 ? ( DADDR[1]==1   ? { FCT3==1&&DATAI[31] ? ALL1[31:16]:ALL0[31:16] , DATAI[31:16] } :
270
                                                             { FCT3==1&&DATAI[15] ? ALL1[31:16]:ALL0[31:16] , DATAI[15: 0] } ) :
271
                                             DATAI;
272
`endif
273
 
274
    // S-group of instructions (OPCODE==7'b0100011)
275
 
276
`ifdef __FLEXBUZZ__
277
 
278
    wire [31:0] SDATA = U2REG; /* FCT3==0 ? { ALL0 [31: 8], U2REG[ 7:0] } :
279
                        FCT3==1 ? { ALL0 [31:16], U2REG[15:0] } :
280
                                    U2REG;*/
281
`else
282
    wire [31:0] SDATA = FCT3==0 ? ( DADDR[1:0]==3 ? { U2REG[ 7: 0], ALL0 [23:0] } :
283
                                    DADDR[1:0]==2 ? { ALL0 [31:24], U2REG[ 7:0], ALL0[15:0] } :
284
                                    DADDR[1:0]==1 ? { ALL0 [31:16], U2REG[ 7:0], ALL0[7:0] } :
285
                                                    { ALL0 [31: 8], U2REG[ 7:0] } ) :
286
                        FCT3==1 ? ( DADDR[1]==1   ? { U2REG[15: 0], ALL0 [15:0] } :
287
                                                    { ALL0 [31:16], U2REG[15:0] } ) :
288
                                    U2REG;
289
`endif
290
 
291
    // C-group not implemented yet!
292
 
293
    wire [31:0] CDATA = 0;        // status register istructions not implemented yet
294
 
295
    // RM-group of instructions (OPCODEs==7'b0010011/7'b0110011), merged! src=immediate(M)/register(R)
296
 
297
    wire signed [31:0] S2REGX = XMCC ? SIMM : S2REG;
298
    wire        [31:0] U2REGX = XMCC ? UIMM : U2REG;
299
 
300
    wire [31:0] RMDATA = FCT3==7 ? U1REG&S2REGX :
301
                         FCT3==6 ? U1REG|S2REGX :
302
                         FCT3==4 ? U1REG^S2REGX :
303
                         FCT3==3 ? U1REG<U2REGX?1:0 : // unsigned
304
                         FCT3==2 ? S1REG<S2REGX?1:0 : // signed
305
                         FCT3==0 ? (XRCC&&FCT7[5] ? U1REG-U2REGX : U1REG+S2REGX) :
306
                         FCT3==1 ? U1REG<<U2REGX[4:0] :
307
                         //FCT3==5 ? 
308
 
309
// maybe the $signed solves the problem for MODELSIM too! needs to be tested!
310
//`ifdef MODEL_TECH        
311
//                         FCT7[5] ? -((-U1REG)>>U2REGX[4:0]; // workaround for modelsim
312
//`else
313
                         FCT7[5] ? $signed(S1REG>>>U2REGX[4:0]) : // (FCT7[5] ? U1REG>>>U2REG[4:0] : 
314
//`endif                        
315
                                   U1REG>>U2REGX[4:0];
316
`ifdef __MAC16X16__
317
 
318
    // MAC instruction rd += s1*s2 (OPCODE==7'b1111111)
319
    // 
320
    // 0000000 01100 01011 100 01100 0110011 xor a2,a1,a2
321
    // 0000000 01010 01100 000 01010 0110011 add a0,a2,a0
322
    // 0000000 01100 01011 000 01010 1111111 mac a0,a1,a2
323
    // 
324
    // 0000 0000 1100 0101 1000 0101 0111 1111 = 00c5857F
325
 
326
    wire signed [15:0] K1TMP = S1REG[15:0];
327
    wire signed [15:0] K2TMP = S2REG[15:0];
328
    wire signed [31:0] KDATA = K1TMP*K2TMP;
329
 
330
`endif
331
 
332
    // J/B-group of instructions (OPCODE==7'b1100011)
333
 
334
    wire BMUX       = BCC==1 && (
335
                          FCT3==4 ? S1REG< S2REGX : // blt
336
                          FCT3==5 ? S1REG>=S2REG : // bge
337
                          FCT3==6 ? U1REG< U2REGX : // bltu
338
                          FCT3==7 ? U1REG>=U2REG : // bgeu
339
                          FCT3==0 ? !(U1REG^S2REGX) : //U1REG==U2REG : // beq
340
                          /*FCT3==1 ? */ U1REG^S2REGX); //U1REG!=U2REG); // bne
341
                                    //0);
342
 
343
    wire        JREQ = (JAL||JALR||BMUX);
344
    wire [31:0] JVAL = JALR ? DADDR : PC+SIMM; // SIMM + (JALR ? U1REG : PC);
345
 
346 4 marcelos
`ifdef SIMULATION
347 2 marcelos
`ifdef __PERFMETER__
348 4 marcelos
    integer clocks=0, thread0=0, thread1=0, load=0, store=0, flush=0, halt=0;
349 2 marcelos
 
350
    always@(posedge CLK)
351
    begin
352
        if(!XRES)
353
        begin
354
            clocks = clocks+1;
355
 
356 4 marcelos
            if(HLT)
357
            begin
358
                     if(SCC)    store = store+1;
359
                else if(LCC)    load  = load +1;
360
                else            halt  = halt +1;
361
            end
362
            else
363
            begin
364
                if(FLUSH)
365
                begin
366
                    flush=flush+1;
367
                end
368
                else
369
                begin
370 2 marcelos
    `ifdef __THREADING__
371
 
372 4 marcelos
                    if(XMODE==0)      thread0 = thread0+1;
373
                    if(XMODE==1)      thread1 = thread1+1;
374 2 marcelos
    `else
375 4 marcelos
                    thread0 = thread0 +1;
376 2 marcelos
    `endif
377 4 marcelos
                end
378
            end
379 2 marcelos
 
380 4 marcelos
            if(FINISH_REQ)
381 2 marcelos
            begin
382 4 marcelos
                $display("****************************************************************************");
383
                $display("DarkRISCV Pipeline Report:");
384
                $display("core0  clocks: %0d",clocks);
385
 
386
                $display("core0 running: %0d%% (%0d%% thread0, %0d%% thread1)",
387
                    100.0*(thread0+thread1)/clocks,
388
                    100.0*thread0/clocks,
389
                    100.0*thread1/clocks);
390
 
391
                $display("core0  halted: %0d%% (%0d%% load, %0d%% store, %0d%% busy)",
392
                    100.0*(load+store)/clocks,
393
                    100.0*load/clocks,
394
                    100.0*store/clocks,
395
                    100.0*halt/clocks);
396
 
397
                $display("core0 stalled: %0d%%",100.0*flush/clocks);
398
                $display("****************************************************************************");
399
                $finish();
400 2 marcelos
            end
401
        end
402
    end
403 4 marcelos
`else
404
    $finish();
405 2 marcelos
`endif
406 4 marcelos
`endif
407 2 marcelos
 
408
    always@(posedge CLK)
409
    begin
410
        RESMODE <= RES ? -1 : RESMODE ? RESMODE-1 : 0;
411
 
412
        XRES <= |RESMODE;
413
 
414
`ifdef __3STAGE__
415
            FLUSH <= XRES ? 2 : HLT ? FLUSH :        // reset and halt                              
416
                               FLUSH ? FLUSH-1 :
417
                               (JAL||JALR||BMUX) ? 2 : 0;  // flush the pipeline!
418
`else
419
        FLUSH <= XRES ? 1 : HLT ? FLUSH :        // reset and halt
420
                       (JAL||JALR||BMUX);  // flush the pipeline!
421
`endif
422
 
423
`ifdef __RV32E__
424
        REG1[DPTR] <=   XRES ? (RESMODE[3:0]==2 ? `__RESETSP__ : 0)  :        // reset sp
425
`else
426
        REG1[DPTR] <=   XRES ? (RESMODE[4:0]==2 ? `__RESETSP__ : 0)  :        // reset sp
427
`endif
428
                       HLT ? REG1[DPTR] :        // halt
429
                     !DPTR ? 0 :                // x0 = 0, always!
430
                     AUIPC ? PC+SIMM :
431
                      JAL||
432
                      JALR ? NXPC :
433
                       LUI ? SIMM :
434
                       LCC ? LDATA :
435
                  MCC||RCC ? RMDATA:
436
`ifdef __MAC16X16__
437
                       MAC ? REG2[DPTR]+KDATA :
438
`endif
439
                       //CCC ? CDATA : 
440
                             REG1[DPTR];
441
`ifdef __RV32E__
442
        REG2[DPTR] <=   XRES ? (RESMODE[3:0]==2 ? `__RESETSP__ : 0) :        // reset sp
443
`else
444
        REG2[DPTR] <=   XRES ? (RESMODE[4:0]==2 ? `__RESETSP__ : 0) :        // reset sp
445
`endif
446
                       HLT ? REG2[DPTR] :        // halt
447
                     !DPTR ? 0 :                // x0 = 0, always!
448
                     AUIPC ? PC+SIMM :
449
                      JAL||
450
                      JALR ? NXPC :
451
                       LUI ? SIMM :
452
                       LCC ? LDATA :
453
                  MCC||RCC ? RMDATA:
454
`ifdef __MAC16X16__
455
                       MAC ? REG2[DPTR]+KDATA :
456
`endif
457
                       //CCC ? CDATA : 
458
                             REG2[DPTR];
459
 
460
`ifdef __3STAGE__
461
 
462
`ifdef __THREADING__
463
 
464
        NXPC <= /*XRES ? `__RESETPC__ :*/ HLT ? NXPC : NXPC2[XMODE];
465
 
466
        NXPC2[RES ? RESMODE[0] : XMODE] <=  XRES ? `__RESETPC__ : HLT ? NXPC2[XMODE] :   // reset and halt
467
                                      JREQ ? JVAL :                            // jmp/bra
468
                                                 NXPC2[XMODE]+4;                   // normal flow
469
 
470
        XMODE <= XRES ? 0 : HLT ? XMODE :        // reset and halt
471 4 marcelos
                     XMODE==0/*&& IREQ*/&&(JAL||JALR||BMUX) ? 1 :         // wait pipeflush to switch to irq
472
                 XMODE==1/*&&!IREQ*/&&(JAL||JALR||BMUX) ? 0 : XMODE;  // wait pipeflush to return from irq
473 2 marcelos
 
474
`else
475
        NXPC <= /*XRES ? `__RESETPC__ :*/ HLT ? NXPC : NXPC2;
476
 
477
            NXPC2 <=  XRES ? `__RESETPC__ : HLT ? NXPC2 :   // reset and halt
478
                         JREQ ? JVAL :                    // jmp/bra
479
                                NXPC2+4;                   // normal flow
480
 
481
`endif
482
 
483
`else
484
        NXPC <= XRES ? `__RESETPC__ : HLT ? NXPC :   // reset and halt
485
              JREQ ? JVAL :                   // jmp/bra
486
                     NXPC+4;                   // normal flow
487
`endif
488
        PC   <= /*XRES ? `__RESETPC__ :*/ HLT ? PC : NXPC; // current program counter
489
    end
490
 
491
    // IO and memory interface
492
 
493
    assign DATAO = SDATA; // SCC ? SDATA : 0;
494
    assign DADDR = U1REG + SIMM; // (SCC||LCC) ? U1REG + SIMM : 0;
495
 
496
    // based in the Scc and Lcc   
497
 
498
`ifdef __FLEXBUZZ__
499
    assign RW      = !SCC;
500
    assign DLEN[0] = (SCC||LCC)&&FCT3[1:0]==0;
501
    assign DLEN[1] = (SCC||LCC)&&FCT3[1:0]==1;
502
    assign DLEN[2] = (SCC||LCC)&&FCT3[1:0]==2;
503
`else
504
    assign RD = LCC;
505
    assign WR = SCC;
506
    assign BE = FCT3==0||FCT3==4 ? ( DADDR[1:0]==3 ? 4'b1000 : // sb/lb
507
                                     DADDR[1:0]==2 ? 4'b0100 :
508
                                     DADDR[1:0]==1 ? 4'b0010 :
509
                                                     4'b0001 ) :
510
                FCT3==1||FCT3==5 ? ( DADDR[1]==1   ? 4'b1100 : // sh/lh
511
                                                     4'b0011 ) :
512
                                                     4'b1111; // sw/lw
513
`endif
514
 
515
`ifdef __3STAGE__
516
`ifdef __THREADING__
517
        assign IADDR = NXPC2[XMODE];
518
`else
519
    assign IADDR = NXPC2;
520
`endif
521
`else
522
    assign IADDR = NXPC;
523
`endif
524
 
525
    assign DEBUG = { XRES, |FLUSH, SCC, LCC };
526
 
527
endmodule

powered by: WebSVN 2.1.0

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