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

Subversion Repositories darkriscv

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

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
`ifdef __THREADING__
66
    input             IREQ,  // irq req
67
`endif
68
 
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
 
85
    output [3:0]  DEBUG      // old-school osciloscope based debug! :)
86
);
87
 
88
    // dummy 32-bit words w/ all-0s and all-1s: 
89
 
90
    wire [31:0] ALL0  = 0;
91
    wire [31:0] ALL1  = -1;
92
 
93
`ifdef __THREADING__
94
    reg XMODE = 0;     // 0 = user, 1 = exception
95
`endif
96
 
97
    // pre-decode: IDATA is break apart as described in the RV32I specification
98
 
99
    reg [31:0] XIDATA;
100
 
101
    reg XLUI, XAUIPC, XJAL, XJALR, XBCC, XLCC, XSCC, XMCC, XRCC, XMAC, XRES=1; //, XFCC, XCCC;
102
 
103
    reg [31:0] XSIMM;
104
    reg [31:0] XUIMM;
105
 
106
    always@(posedge CLK)
107
    begin
108
        XIDATA <= XRES ? 0 : HLT ? XIDATA : IDATA;
109
 
110
        XLUI   <= XRES ? 0 : HLT ? XLUI   : IDATA[6:0]==`LUI;
111
        XAUIPC <= XRES ? 0 : HLT ? XAUIPC : IDATA[6:0]==`AUIPC;
112
        XJAL   <= XRES ? 0 : HLT ? XJAL   : IDATA[6:0]==`JAL;
113
        XJALR  <= XRES ? 0 : HLT ? XJALR  : IDATA[6:0]==`JALR;
114
 
115
        XBCC   <= XRES ? 0 : HLT ? XBCC   : IDATA[6:0]==`BCC;
116
        XLCC   <= XRES ? 0 : HLT ? XLCC   : IDATA[6:0]==`LCC;
117
        XSCC   <= XRES ? 0 : HLT ? XSCC   : IDATA[6:0]==`SCC;
118
        XMCC   <= XRES ? 0 : HLT ? XMCC   : IDATA[6:0]==`MCC;
119
 
120
        XRCC   <= XRES ? 0 : HLT ? XRCC   : IDATA[6:0]==`RCC;
121
        XMAC   <= XRES ? 0 : HLT ? XRCC   : IDATA[6:0]==`MAC;
122
        //XFCC   <= XRES ? 0 : HLT ? XFCC   : IDATA[6:0]==`FCC;
123
        //XCCC   <= XRES ? 0 : HLT ? XCCC   : IDATA[6:0]==`CCC;
124
 
125
        // signal extended immediate, according to the instruction type:
126
 
127
        XSIMM  <= XRES ? 0 : HLT ? XSIMM :
128
                 IDATA[6:0]==`SCC ? { IDATA[31] ? ALL1[31:12]:ALL0[31:12], IDATA[31:25],IDATA[11:7] } : // s-type
129
                 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
130
                 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
131
                 IDATA[6:0]==`LUI||
132
                 IDATA[6:0]==`AUIPC ? { IDATA[31:12], ALL0[11:0] } : // u-type
133
                                      { IDATA[31] ? ALL1[31:12]:ALL0[31:12], IDATA[31:20] }; // i-type
134
        // non-signal extended immediate, according to the instruction type:
135
 
136
        XUIMM  <= XRES ? 0: HLT ? XUIMM :
137
                 IDATA[6:0]==`SCC ? { ALL0[31:12], IDATA[31:25],IDATA[11:7] } : // s-type
138
                 IDATA[6:0]==`BCC ? { ALL0[31:13], IDATA[31],IDATA[7],IDATA[30:25],IDATA[11:8],ALL0[0] } : // b-type
139
                 IDATA[6:0]==`JAL ? { ALL0[31:21], IDATA[31], IDATA[19:12], IDATA[20], IDATA[30:21], ALL0[0] } : // j-type
140
                 IDATA[6:0]==`LUI||
141
                 IDATA[6:0]==`AUIPC ? { IDATA[31:12], ALL0[11:0] } : // u-type
142
                                      { ALL0[31:12], IDATA[31:20] }; // i-type
143
    end
144
 
145
    // decode: after XIDATA
146
`ifdef __3STAGE__
147
    reg [1:0] FLUSH = -1;  // flush instruction pipeline
148
`else
149
    reg FLUSH = -1;  // flush instruction pipeline
150
`endif
151
 
152
`ifdef __THREADING__
153
 
154
    `ifdef __RV32E__
155
 
156
        reg [4:0] RESMODE = -1;
157
 
158
        wire [4:0] DPTR   = XRES ? RESMODE : { XMODE, XIDATA[10: 7] }; // set SP_RESET when RES==1
159
        wire [4:0] S1PTR  = { XMODE, XIDATA[18:15] };
160
        wire [4:0] S2PTR  = { XMODE, XIDATA[23:20] };
161
    `else
162
        reg [5:0] RESMODE = -1;
163
 
164
        wire [5:0] DPTR   = XRES ? RESMODE : { XMODE, XIDATA[11: 7] }; // set SP_RESET when RES==1
165
        wire [5:0] S1PTR  = { XMODE, XIDATA[19:15] };
166
        wire [5:0] S2PTR  = { XMODE, XIDATA[24:20] };
167
    `endif
168
 
169
    wire [6:0] OPCODE = FLUSH ? 0 : XIDATA[6:0];
170
    wire [2:0] FCT3   = XIDATA[14:12];
171
    wire [6:0] FCT7   = XIDATA[31:25];
172
 
173
`else
174
 
175
    `ifdef __RV32E__
176
 
177
        reg [3:0] RESMODE = -1;
178
 
179
        wire [3:0] DPTR   = XRES ? RESMODE : XIDATA[10: 7]; // set SP_RESET when RES==1
180
        wire [3:0] S1PTR  = XIDATA[18:15];
181
        wire [3:0] S2PTR  = XIDATA[23:20];
182
    `else
183
        reg [4:0] RESMODE = -1;
184
 
185
        wire [4:0] DPTR   = XRES ? RESMODE : XIDATA[11: 7]; // set SP_RESET when RES==1
186
        wire [4:0] S1PTR  = XIDATA[19:15];
187
        wire [4:0] S2PTR  = XIDATA[24:20];
188
    `endif
189
 
190
    wire [6:0] OPCODE = FLUSH ? 0 : XIDATA[6:0];
191
    wire [2:0] FCT3   = XIDATA[14:12];
192
    wire [6:0] FCT7   = XIDATA[31:25];
193
 
194
`endif
195
 
196
    wire [31:0] SIMM  = XSIMM;
197
    wire [31:0] UIMM  = XUIMM;
198
 
199
    // main opcode decoder:
200
 
201
    wire    LUI = FLUSH ? 0 : XLUI;   // OPCODE==7'b0110111;
202
    wire  AUIPC = FLUSH ? 0 : XAUIPC; // OPCODE==7'b0010111;
203
    wire    JAL = FLUSH ? 0 : XJAL;   // OPCODE==7'b1101111;
204
    wire   JALR = FLUSH ? 0 : XJALR;  // OPCODE==7'b1100111;
205
 
206
    wire    BCC = FLUSH ? 0 : XBCC; // OPCODE==7'b1100011; //FCT3
207
    wire    LCC = FLUSH ? 0 : XLCC; // OPCODE==7'b0000011; //FCT3
208
    wire    SCC = FLUSH ? 0 : XSCC; // OPCODE==7'b0100011; //FCT3
209
    wire    MCC = FLUSH ? 0 : XMCC; // OPCODE==7'b0010011; //FCT3
210
 
211
    wire    RCC = FLUSH ? 0 : XRCC; // OPCODE==7'b0110011; //FCT3
212
    wire    MAC = FLUSH ? 0 : XMAC; // OPCODE==7'b0110011; //FCT3
213
    //wire    FCC = FLUSH ? 0 : XFCC; // OPCODE==7'b0001111; //FCT3
214
    //wire    CCC = FLUSH ? 0 : XCCC; // OPCODE==7'b1110011; //FCT3
215
 
216
`ifdef __THREADING__
217
`ifdef __3STAGE__
218
    reg [31:0] NXPC2 [0:1];       // 32-bit program counter t+2
219
`endif
220
    reg [31:0] NXPC;        // 32-bit program counter t+1
221
    reg [31:0] PC;                   // 32-bit program counter t+0
222
 
223
    `ifdef __RV32E__
224
        reg [31:0] REG1 [0:31];   // general-purpose 16x32-bit registers (s1)
225
        reg [31:0] REG2 [0:31];   // general-purpose 16x32-bit registers (s2)
226
    `else
227
        reg [31:0] REG1 [0:63];   // general-purpose 32x32-bit registers (s1)
228
        reg [31:0] REG2 [0:63];   // general-purpose 32x32-bit registers (s2)    
229
    `endif
230
`else
231
`ifdef __3STAGE__
232
    reg [31:0] NXPC2;       // 32-bit program counter t+2
233
`endif
234
    reg [31:0] NXPC;        // 32-bit program counter t+1
235
    reg [31:0] PC;                   // 32-bit program counter t+0
236
 
237
    `ifdef __RV32E__
238
        reg [31:0] REG1 [0:15];   // general-purpose 16x32-bit registers (s1)
239
        reg [31:0] REG2 [0:15];   // general-purpose 16x32-bit registers (s2)
240
    `else
241
        reg [31:0] REG1 [0:31];   // general-purpose 32x32-bit registers (s1)
242
        reg [31:0] REG2 [0:31];   // general-purpose 32x32-bit registers (s2)
243
    `endif
244
`endif
245
 
246
    // source-1 and source-1 register selection
247
 
248
    wire signed   [31:0] S1REG = REG1[S1PTR];
249
    wire signed   [31:0] S2REG = REG2[S2PTR];
250
 
251
    wire          [31:0] U1REG = REG1[S1PTR];
252
    wire          [31:0] U2REG = REG2[S2PTR];
253
 
254
    // L-group of instructions (OPCODE==7'b0000011)
255
 
256
`ifdef __FLEXBUZZ__
257
 
258
    wire [31:0] LDATA = FCT3[1:0]==0 ? { FCT3[2]==0&&DATAI[ 7] ? ALL1[31: 8]:ALL0[31: 8] , DATAI[ 7: 0] } :
259
                        FCT3[1:0]==1 ? { FCT3[2]==0&&DATAI[15] ? ALL1[31:16]:ALL0[31:16] , DATAI[15: 0] } :
260
                                        DATAI;
261
`else
262
    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] } :
263
                                             DADDR[1:0]==2 ? { FCT3==0&&DATAI[23] ? ALL1[31: 8]:ALL0[31: 8] , DATAI[23:16] } :
264
                                             DADDR[1:0]==1 ? { FCT3==0&&DATAI[15] ? ALL1[31: 8]:ALL0[31: 8] , DATAI[15: 8] } :
265
                                                             { FCT3==0&&DATAI[ 7] ? ALL1[31: 8]:ALL0[31: 8] , DATAI[ 7: 0] } ):
266
                        FCT3==1||FCT3==5 ? ( DADDR[1]==1   ? { FCT3==1&&DATAI[31] ? ALL1[31:16]:ALL0[31:16] , DATAI[31:16] } :
267
                                                             { FCT3==1&&DATAI[15] ? ALL1[31:16]:ALL0[31:16] , DATAI[15: 0] } ) :
268
                                             DATAI;
269
`endif
270
 
271
    // S-group of instructions (OPCODE==7'b0100011)
272
 
273
`ifdef __FLEXBUZZ__
274
 
275
    wire [31:0] SDATA = U2REG; /* FCT3==0 ? { ALL0 [31: 8], U2REG[ 7:0] } :
276
                        FCT3==1 ? { ALL0 [31:16], U2REG[15:0] } :
277
                                    U2REG;*/
278
`else
279
    wire [31:0] SDATA = FCT3==0 ? ( DADDR[1:0]==3 ? { U2REG[ 7: 0], ALL0 [23:0] } :
280
                                    DADDR[1:0]==2 ? { ALL0 [31:24], U2REG[ 7:0], ALL0[15:0] } :
281
                                    DADDR[1:0]==1 ? { ALL0 [31:16], U2REG[ 7:0], ALL0[7:0] } :
282
                                                    { ALL0 [31: 8], U2REG[ 7:0] } ) :
283
                        FCT3==1 ? ( DADDR[1]==1   ? { U2REG[15: 0], ALL0 [15:0] } :
284
                                                    { ALL0 [31:16], U2REG[15:0] } ) :
285
                                    U2REG;
286
`endif
287
 
288
    // C-group not implemented yet!
289
 
290
    wire [31:0] CDATA = 0;        // status register istructions not implemented yet
291
 
292
    // RM-group of instructions (OPCODEs==7'b0010011/7'b0110011), merged! src=immediate(M)/register(R)
293
 
294
    wire signed [31:0] S2REGX = XMCC ? SIMM : S2REG;
295
    wire        [31:0] U2REGX = XMCC ? UIMM : U2REG;
296
 
297
    wire [31:0] RMDATA = FCT3==7 ? U1REG&S2REGX :
298
                         FCT3==6 ? U1REG|S2REGX :
299
                         FCT3==4 ? U1REG^S2REGX :
300
                         FCT3==3 ? U1REG<U2REGX?1:0 : // unsigned
301
                         FCT3==2 ? S1REG<S2REGX?1:0 : // signed
302
                         FCT3==0 ? (XRCC&&FCT7[5] ? U1REG-U2REGX : U1REG+S2REGX) :
303
                         FCT3==1 ? U1REG<<U2REGX[4:0] :
304
                         //FCT3==5 ? 
305
 
306
// maybe the $signed solves the problem for MODELSIM too! needs to be tested!
307
//`ifdef MODEL_TECH        
308
//                         FCT7[5] ? -((-U1REG)>>U2REGX[4:0]; // workaround for modelsim
309
//`else
310
                         FCT7[5] ? $signed(S1REG>>>U2REGX[4:0]) : // (FCT7[5] ? U1REG>>>U2REG[4:0] : 
311
//`endif                        
312
                                   U1REG>>U2REGX[4:0];
313
`ifdef __MAC16X16__
314
 
315
    // MAC instruction rd += s1*s2 (OPCODE==7'b1111111)
316
    // 
317
    // 0000000 01100 01011 100 01100 0110011 xor a2,a1,a2
318
    // 0000000 01010 01100 000 01010 0110011 add a0,a2,a0
319
    // 0000000 01100 01011 000 01010 1111111 mac a0,a1,a2
320
    // 
321
    // 0000 0000 1100 0101 1000 0101 0111 1111 = 00c5857F
322
 
323
    wire signed [15:0] K1TMP = S1REG[15:0];
324
    wire signed [15:0] K2TMP = S2REG[15:0];
325
    wire signed [31:0] KDATA = K1TMP*K2TMP;
326
 
327
`endif
328
 
329
    // J/B-group of instructions (OPCODE==7'b1100011)
330
 
331
    wire BMUX       = BCC==1 && (
332
                          FCT3==4 ? S1REG< S2REGX : // blt
333
                          FCT3==5 ? S1REG>=S2REG : // bge
334
                          FCT3==6 ? U1REG< U2REGX : // bltu
335
                          FCT3==7 ? U1REG>=U2REG : // bgeu
336
                          FCT3==0 ? !(U1REG^S2REGX) : //U1REG==U2REG : // beq
337
                          /*FCT3==1 ? */ U1REG^S2REGX); //U1REG!=U2REG); // bne
338
                                    //0);
339
 
340
    wire        JREQ = (JAL||JALR||BMUX);
341
    wire [31:0] JVAL = JALR ? DADDR : PC+SIMM; // SIMM + (JALR ? U1REG : PC);
342
 
343
`ifdef __PERFMETER__
344
    integer clocks=0, user=0, super=0, halt=0, flush=0;
345
 
346
    always@(posedge CLK)
347
    begin
348
        if(!XRES)
349
        begin
350
            clocks = clocks+1;
351
 
352
    `ifdef __THREADING__
353
 
354
            if(XMODE==0 && !HLT && !FLUSH)      user  = user +1;
355
            if(XMODE==1 && !HLT && !FLUSH)      super = super+1;
356
    `else
357
            if(!HLT && !FLUSH)                  user  = user +1;
358
    `endif
359
 
360
            if(HLT)             halt=halt+1;
361
            if(FLUSH)           flush=flush+1;
362
 
363
            if(clocks && clocks%`__PERFMETER__==0)
364
            begin
365
                $display("%d clocks: %0d%% user, %0d%% super, %0d%% ws, %0d%% flush",
366
                    clocks,
367
                    100*user/clocks,
368
                    100*super/clocks,
369
                    100*halt/clocks,
370
                    100*flush/clocks);
371
            end
372
        end
373
    end
374
`endif
375
 
376
    always@(posedge CLK)
377
    begin
378
        RESMODE <= RES ? -1 : RESMODE ? RESMODE-1 : 0;
379
 
380
        XRES <= |RESMODE;
381
 
382
`ifdef __3STAGE__
383
            FLUSH <= XRES ? 2 : HLT ? FLUSH :        // reset and halt                              
384
                               FLUSH ? FLUSH-1 :
385
                               (JAL||JALR||BMUX) ? 2 : 0;  // flush the pipeline!
386
`else
387
        FLUSH <= XRES ? 1 : HLT ? FLUSH :        // reset and halt
388
                       (JAL||JALR||BMUX);  // flush the pipeline!
389
`endif
390
 
391
`ifdef __RV32E__
392
        REG1[DPTR] <=   XRES ? (RESMODE[3:0]==2 ? `__RESETSP__ : 0)  :        // reset sp
393
`else
394
        REG1[DPTR] <=   XRES ? (RESMODE[4:0]==2 ? `__RESETSP__ : 0)  :        // reset sp
395
`endif
396
                       HLT ? REG1[DPTR] :        // halt
397
                     !DPTR ? 0 :                // x0 = 0, always!
398
                     AUIPC ? PC+SIMM :
399
                      JAL||
400
                      JALR ? NXPC :
401
                       LUI ? SIMM :
402
                       LCC ? LDATA :
403
                  MCC||RCC ? RMDATA:
404
`ifdef __MAC16X16__
405
                       MAC ? REG2[DPTR]+KDATA :
406
`endif
407
                       //CCC ? CDATA : 
408
                             REG1[DPTR];
409
`ifdef __RV32E__
410
        REG2[DPTR] <=   XRES ? (RESMODE[3:0]==2 ? `__RESETSP__ : 0) :        // reset sp
411
`else
412
        REG2[DPTR] <=   XRES ? (RESMODE[4:0]==2 ? `__RESETSP__ : 0) :        // reset sp
413
`endif
414
                       HLT ? REG2[DPTR] :        // halt
415
                     !DPTR ? 0 :                // x0 = 0, always!
416
                     AUIPC ? PC+SIMM :
417
                      JAL||
418
                      JALR ? NXPC :
419
                       LUI ? SIMM :
420
                       LCC ? LDATA :
421
                  MCC||RCC ? RMDATA:
422
`ifdef __MAC16X16__
423
                       MAC ? REG2[DPTR]+KDATA :
424
`endif
425
                       //CCC ? CDATA : 
426
                             REG2[DPTR];
427
 
428
`ifdef __3STAGE__
429
 
430
`ifdef __THREADING__
431
 
432
        NXPC <= /*XRES ? `__RESETPC__ :*/ HLT ? NXPC : NXPC2[XMODE];
433
 
434
        NXPC2[RES ? RESMODE[0] : XMODE] <=  XRES ? `__RESETPC__ : HLT ? NXPC2[XMODE] :   // reset and halt
435
                                      JREQ ? JVAL :                            // jmp/bra
436
                                                 NXPC2[XMODE]+4;                   // normal flow
437
 
438
        XMODE <= XRES ? 0 : HLT ? XMODE :        // reset and halt
439
                     XMODE==0&& IREQ&&(JAL||JALR||BMUX) ? 1 :         // wait pipeflush to switch to irq
440
                 XMODE==1&&!IREQ&&(JAL||JALR||BMUX) ? 0 : XMODE;  // wait pipeflush to return from irq
441
 
442
`else
443
        NXPC <= /*XRES ? `__RESETPC__ :*/ HLT ? NXPC : NXPC2;
444
 
445
            NXPC2 <=  XRES ? `__RESETPC__ : HLT ? NXPC2 :   // reset and halt
446
                         JREQ ? JVAL :                    // jmp/bra
447
                                NXPC2+4;                   // normal flow
448
 
449
`endif
450
 
451
`else
452
        NXPC <= XRES ? `__RESETPC__ : HLT ? NXPC :   // reset and halt
453
              JREQ ? JVAL :                   // jmp/bra
454
                     NXPC+4;                   // normal flow
455
`endif
456
        PC   <= /*XRES ? `__RESETPC__ :*/ HLT ? PC : NXPC; // current program counter
457
    end
458
 
459
    // IO and memory interface
460
 
461
    assign DATAO = SDATA; // SCC ? SDATA : 0;
462
    assign DADDR = U1REG + SIMM; // (SCC||LCC) ? U1REG + SIMM : 0;
463
 
464
    // based in the Scc and Lcc   
465
 
466
`ifdef __FLEXBUZZ__
467
    assign RW      = !SCC;
468
    assign DLEN[0] = (SCC||LCC)&&FCT3[1:0]==0;
469
    assign DLEN[1] = (SCC||LCC)&&FCT3[1:0]==1;
470
    assign DLEN[2] = (SCC||LCC)&&FCT3[1:0]==2;
471
`else
472
    assign RD = LCC;
473
    assign WR = SCC;
474
    assign BE = FCT3==0||FCT3==4 ? ( DADDR[1:0]==3 ? 4'b1000 : // sb/lb
475
                                     DADDR[1:0]==2 ? 4'b0100 :
476
                                     DADDR[1:0]==1 ? 4'b0010 :
477
                                                     4'b0001 ) :
478
                FCT3==1||FCT3==5 ? ( DADDR[1]==1   ? 4'b1100 : // sh/lh
479
                                                     4'b0011 ) :
480
                                                     4'b1111; // sw/lw
481
`endif
482
 
483
`ifdef __3STAGE__
484
`ifdef __THREADING__
485
        assign IADDR = NXPC2[XMODE];
486
`else
487
    assign IADDR = NXPC2;
488
`endif
489
`else
490
    assign IADDR = NXPC;
491
`endif
492
 
493
    assign DEBUG = { XRES, |FLUSH, SCC, LCC };
494
 
495
endmodule

powered by: WebSVN 2.1.0

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