OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [src_processor/] [lm32/] [verilog/] [src/] [lm32_load_store_unit.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 alirezamon
// =============================================================================
2
//                           COPYRIGHT NOTICE
3
// Copyright 2006 (c) Lattice Semiconductor Corporation
4
// ALL RIGHTS RESERVED
5
// This confidential and proprietary software may be used only as authorised by
6
// a licensing agreement from Lattice Semiconductor Corporation.
7
// The entire notice above must be reproduced on all authorized copies and
8
// copies may only be made to the extent permitted by a licensing agreement from
9
// Lattice Semiconductor Corporation.
10
//
11
// Lattice Semiconductor Corporation        TEL : 1-800-Lattice (USA and Canada)
12
// 5555 NE Moore Court                            408-826-6000 (other locations)
13
// Hillsboro, OR 97124                     web  : http://www.latticesemi.com/
14
// U.S.A                                   email: techsupport@latticesemi.com
15
// =============================================================================/
16
//                         FILE DETAILS
17
// Project          : LatticeMico32
18
// File             : lm32_load_store_unit.v
19
// Title            : Load and store unit
20
// Dependencies     : lm32_include.v
21
// Version          : 6.0.13
22
// =============================================================================
23
 
24
`include "lm32_include.v"
25
 
26
/////////////////////////////////////////////////////
27
// Module interface
28
/////////////////////////////////////////////////////
29
 
30
module lm32_load_store_unit (
31
    // ----- Inputs -------
32
    clk_i,
33
    rst_i,
34
    // From pipeline
35
    stall_a,
36
    stall_x,
37
    stall_m,
38
    kill_x,
39
    kill_m,
40
    exception_m,
41
    store_operand_x,
42
    load_store_address_x,
43
    load_store_address_m,
44
    load_store_address_w,
45
    load_q_x,
46
    load_q_m,
47
    store_q_m,
48
    sign_extend_x,
49
    size_x,
50
`ifdef CFG_DCACHE_ENABLED
51
    dflush,
52
`endif
53
    // From Wishbone
54
    d_dat_i,
55
    d_ack_i,
56
    d_err_i,
57
    d_rty_i,
58
    // ----- Outputs -------
59
    // To pipeline
60
`ifdef CFG_DCACHE_ENABLED
61
    dcache_refill_request,
62
    dcache_restart_request,
63
    dcache_stall_request,
64
    dcache_refilling,
65
`endif
66
    load_data_w,
67
    stall_wb_load,
68
    // To Wishbone
69
    d_dat_o,
70
    d_adr_o,
71
    d_cyc_o,
72
    d_sel_o,
73
    d_stb_o,
74
    d_we_o,
75
    d_cti_o,
76
    d_lock_o,
77 48 alirezamon
    d_bte_o,
78
    snoop_adr_i,
79
    d_snoop_valid
80 17 alirezamon
    );
81
 
82
/////////////////////////////////////////////////////
83
// Parameters
84
/////////////////////////////////////////////////////
85
 
86
parameter associativity = 1;                            // Associativity of the cache (Number of ways)
87
parameter sets = 512;                                   // Number of sets
88
parameter bytes_per_line = 16;                          // Number of bytes per cache line
89
parameter base_address = 0;                             // Base address of cachable memory
90
parameter limit = 0;                                    // Limit (highest address) of cachable memory
91
 
92
// For bytes_per_line == 4, we set 1 so part-select range isn't reversed, even though not really used 
93
//localparam addr_offset_width = bytes_per_line == 4 ? 1 : clogb2(bytes_per_line)-1-2;
94
localparam addr_offset_width = 2;
95
localparam addr_offset_lsb = 2;
96
localparam addr_offset_msb = (addr_offset_lsb+addr_offset_width-1);
97
 
98
/////////////////////////////////////////////////////
99
// Inputs
100
/////////////////////////////////////////////////////
101
 
102
input clk_i;                                            // Clock 
103
input rst_i;                                            // Reset
104
 
105
input stall_a;                                          // A stage stall 
106
input stall_x;                                          // X stage stall        
107
input stall_m;                                          // M stage stall
108
input kill_x;                                           // Kill instruction in X stage
109
input kill_m;                                           // Kill instruction in M stage
110
input exception_m;                                      // An exception occured in the M stage
111
 
112
input [`LM32_WORD_RNG] store_operand_x;                 // Data read from register to store
113
input [`LM32_WORD_RNG] load_store_address_x;            // X stage load/store address
114
input [`LM32_WORD_RNG] load_store_address_m;            // M stage load/store address
115
input [1:0] load_store_address_w;                       // W stage load/store address (only least two significant bits are needed)
116
input load_q_x;                                         // Load instruction in X stage
117
input load_q_m;                                         // Load instruction in M stage
118
input store_q_m;                                        // Store instruction in M stage
119
input sign_extend_x;                                    // Whether load instruction in X stage should sign extend or zero extend
120
input [`LM32_SIZE_RNG] size_x;                          // Size of load or store (byte, hword, word)
121
 
122
`ifdef CFG_DCACHE_ENABLED
123
input dflush;                                           // Flush the data cache
124
`endif
125
 
126
input [`LM32_WORD_RNG] d_dat_i;                         // Data Wishbone interface read data
127
input d_ack_i;                                          // Data Wishbone interface acknowledgement
128
input d_err_i;                                          // Data Wishbone interface error
129
input d_rty_i;                                          // Data Wishbone interface retry
130
 
131
/////////////////////////////////////////////////////
132
// Outputs
133
/////////////////////////////////////////////////////
134
 
135
`ifdef CFG_DCACHE_ENABLED
136
output dcache_refill_request;                           // Request to refill data cache
137
wire   dcache_refill_request;
138
output dcache_restart_request;                          // Request to restart the instruction that caused a data cache miss
139
wire   dcache_restart_request;
140
output dcache_stall_request;                            // Data cache stall request
141
wire   dcache_stall_request;
142
output dcache_refilling;
143
wire   dcache_refilling;
144
`endif
145
 
146
output [`LM32_WORD_RNG] load_data_w;                    // Result of a load instruction
147
reg    [`LM32_WORD_RNG] load_data_w;
148
output stall_wb_load;                                   // Request to stall pipeline due to a load from the Wishbone interface
149
reg    stall_wb_load;
150
 
151
output [`LM32_WORD_RNG] d_dat_o;                        // Data Wishbone interface write data
152
reg    [`LM32_WORD_RNG] d_dat_o;
153
output [`LM32_WORD_RNG] d_adr_o;                        // Data Wishbone interface address
154
reg    [`LM32_WORD_RNG] d_adr_o;
155
output d_cyc_o;                                         // Data Wishbone interface cycle
156
reg    d_cyc_o;
157
output [`LM32_BYTE_SELECT_RNG] d_sel_o;                 // Data Wishbone interface byte select
158
reg    [`LM32_BYTE_SELECT_RNG] d_sel_o;
159
output d_stb_o;                                         // Data Wishbone interface strobe
160
reg    d_stb_o;
161
output d_we_o;                                          // Data Wishbone interface write enable
162
reg    d_we_o;
163
output [`LM32_CTYPE_RNG] d_cti_o;                       // Data Wishbone interface cycle type 
164
wire   [`LM32_CTYPE_RNG] d_cti_o;
165
output d_lock_o;                                        // Date Wishbone interface lock bus
166
wire   d_lock_o;
167
output [`LM32_BTYPE_RNG] d_bte_o;                       // Data Wishbone interface burst type 
168
wire   [`LM32_BTYPE_RNG] d_bte_o;
169
 
170 48 alirezamon
 
171
input [31:0]          snoop_adr_i;
172
input d_snoop_valid;
173
 
174 17 alirezamon
/////////////////////////////////////////////////////
175
// Internal nets and registers 
176
/////////////////////////////////////////////////////
177
 
178
// Microcode pipeline registers - See inputs for description
179
reg [`LM32_SIZE_RNG] size_m;
180
reg [`LM32_SIZE_RNG] size_w;
181
reg sign_extend_m;
182
reg sign_extend_w;
183
reg [`LM32_WORD_RNG] store_data_x;
184
reg [`LM32_WORD_RNG] store_data_m;
185
reg [`LM32_BYTE_SELECT_RNG] byte_enable_x;
186
reg [`LM32_BYTE_SELECT_RNG] byte_enable_m;
187
wire [`LM32_WORD_RNG] data_m;
188
reg [`LM32_WORD_RNG] data_w;
189
 
190
`ifdef CFG_DCACHE_ENABLED
191
wire dcache_select_x;                                   // Select data cache to load from / store to
192
reg dcache_select_m;
193
wire [`LM32_WORD_RNG] dcache_data_m;                    // Data read from cache
194
wire [`LM32_WORD_RNG] dcache_refill_address;            // Address to refill data cache from
195
reg dcache_refill_ready;                                // Indicates the next word of refill data is ready
196
wire last_word;                                         // Indicates if this is the last word in the cache line
197
wire [`LM32_WORD_RNG] first_address;                    // First cache refill address
198
`endif
199
`ifdef CFG_DRAM_ENABLED
200
wire dram_select_x;                                     // Select data RAM to load from / store to
201
reg dram_select_m;
202
wire [`LM32_WORD_RNG] dram_data_m;                      // Data read from data RAM
203
wire [`LM32_WORD_RNG] dram_store_data_m;                // Data to write to RAM
204
`endif
205
wire wb_select_x;                                       // Select Wishbone to load from / store to
206
reg wb_select_m;
207
reg [`LM32_WORD_RNG] wb_data_m;                         // Data read from Wishbone
208
reg wb_load_complete;                                   // Indicates when a Wishbone load is complete
209
 
210
/////////////////////////////////////////////////////
211
// Functions
212
/////////////////////////////////////////////////////
213
`define  INCLUDE_FUNCTION
214
`include "lm32_functions.v"
215
 
216
/////////////////////////////////////////////////////
217
// Instantiations
218
/////////////////////////////////////////////////////
219
 
220
`ifdef CFG_DRAM_ENABLED
221
// Data RAM
222
pmi_ram_dp_true #(
223
    // ----- Parameters -------
224
    .pmi_addr_depth_a       (1 << (clogb2(`CFG_DRAM_LIMIT/4-`CFG_DRAM_BASE_ADDRESS/4+1)-1)),
225
    .pmi_addr_width_a       ((clogb2(`CFG_DRAM_LIMIT/4-`CFG_DRAM_BASE_ADDRESS/4+1)-1)),
226
    .pmi_data_width_a       (`LM32_WORD_WIDTH),
227
    .pmi_addr_depth_b       (1 << (clogb2(`CFG_DRAM_LIMIT/4-`CFG_DRAM_BASE_ADDRESS/4+1)-1)),
228
    .pmi_addr_width_b       ((clogb2(`CFG_DRAM_LIMIT/4-`CFG_DRAM_BASE_ADDRESS/4+1)-1)),
229
    .pmi_data_width_b       (`LM32_WORD_WIDTH),
230
    .pmi_regmode_a          ("noreg"),
231
    .pmi_regmode_b          ("noreg"),
232
    .pmi_gsr                ("enable"),
233
    .pmi_resetmode          ("async"),
234
    .pmi_init_file          (`CFG_DRAM_INIT_FILE),
235
    .pmi_init_file_format   ("hex"),
236
    .module_type            ("pmi_ram_dp")
237
  ) ram (
238
    // ----- Inputs -------
239
    .ClockA                 (clk_i),
240
    .ClockB                 (clk_i),
241
    .ResetA                 (rst_i),
242
    .ResetB                 (rst_i),
243
    .DataInA                ({32{1'b0}}),
244
    .DataInB                (dram_store_data_m),
245
    .AddressA               (load_store_address_x[(clogb2(`CFG_DRAM_LIMIT/4-`CFG_DRAM_BASE_ADDRESS/4+1)-1)+2-1:2]),
246
    .AddressB               (load_store_address_m[(clogb2(`CFG_DRAM_LIMIT/4-`CFG_DRAM_BASE_ADDRESS/4+1)-1)+2-1:2]),
247
    .ClockEnA               (!stall_x),
248
    .ClockEnB               (!stall_m),
249
    .WrA                    (`FALSE),
250
    .WrB                    (store_q_m),
251
    // ----- Outputs -------
252
    .QA                     (dram_data_m),
253
    .QB                     ()
254
    );
255
`endif
256
 
257
`ifdef CFG_DCACHE_ENABLED
258
// Data cache
259
lm32_dcache #(
260
    .associativity          (associativity),
261
    .sets                   (sets),
262
    .bytes_per_line         (bytes_per_line),
263
    .base_address           (base_address),
264
    .limit                  (limit)
265
    ) dcache (
266
    // ----- Inputs -----
267
    .clk_i                  (clk_i),
268
    .rst_i                  (rst_i),
269
    .stall_a                (stall_a),
270
    .stall_x                (stall_x),
271
    .stall_m                (stall_m),
272
    .address_x              (load_store_address_x),
273
    .address_m              (load_store_address_m),
274
    .load_q_m               (load_q_m & dcache_select_m),
275
    .store_q_m              (store_q_m),
276
    .store_data             (store_data_m),
277
    .store_byte_select      (byte_enable_m),
278
    .refill_ready           (dcache_refill_ready),
279
    .refill_data            (wb_data_m),
280
    .dflush                 (dflush),
281
    // ----- Outputs -----
282
    .stall_request          (dcache_stall_request),
283
    .restart_request        (dcache_restart_request),
284
    .refill_request         (dcache_refill_request),
285
    .refill_address         (dcache_refill_address),
286
    .refilling              (dcache_refilling),
287 48 alirezamon
    .load_data              (dcache_data_m),
288
    .snoop_adr_i            (snoop_adr_i),
289
    .d_snoop_valid          (d_snoop_valid)
290
 
291 17 alirezamon
    );
292
`endif
293
 
294
/////////////////////////////////////////////////////
295
// Combinational Logic
296
/////////////////////////////////////////////////////
297
 
298
// Select where data should be loaded from / stored to
299
`ifdef CFG_DCACHE_ENABLED
300
assign dcache_select_x = (load_store_address_x >= `CFG_DCACHE_BASE_ADDRESS) && (load_store_address_x <= `CFG_DCACHE_LIMIT);
301
//assign dcache_select_x = (load_store_address_x >= `CFG_DCACHE_BASE_ADDRESS) && ~|load_store_address_x[`LM32_WORD_WIDTH-1:clogb2(`CFG_DCACHE_LIMIT-`CFG_DCACHE_BASE_ADDRESS)-1];
302
`endif
303
`ifdef CFG_DRAM_ENABLED
304
assign dram_select_x = (load_store_address_x >= `CFG_DRAM_BASE_ADDRESS) && (load_store_address_x <= `CFG_DRAM_LIMIT);
305
`endif
306
assign wb_select_x =    `TRUE
307
`ifdef CFG_DCACHE_ENABLED
308
                     && !dcache_select_x
309
`endif
310
`ifdef CFG_DRAM_ENABLED
311
                     && !dram_select_x
312
`endif
313
                     ;
314
 
315
// Make sure data to store is in correct byte lane
316
always @(*)
317
begin
318
    case (size_x)
319
    `LM32_SIZE_BYTE:  store_data_x = {4{store_operand_x[7:0]}};
320
    `LM32_SIZE_HWORD: store_data_x = {2{store_operand_x[15:0]}};
321
    `LM32_SIZE_WORD:  store_data_x = store_operand_x;
322
    default:          store_data_x = {`LM32_WORD_WIDTH{1'bx}};
323
    endcase
324
end
325
 
326
// Generate byte enable accoring to size of load or store and address being accessed
327
always @(*)
328
begin
329
    casez ({size_x, load_store_address_x[1:0]})
330
    {`LM32_SIZE_BYTE, 2'b11}:  byte_enable_x = 4'b0001;
331
    {`LM32_SIZE_BYTE, 2'b10}:  byte_enable_x = 4'b0010;
332
    {`LM32_SIZE_BYTE, 2'b01}:  byte_enable_x = 4'b0100;
333
    {`LM32_SIZE_BYTE, 2'b00}:  byte_enable_x = 4'b1000;
334
    {`LM32_SIZE_HWORD, 2'b1?}: byte_enable_x = 4'b0011;
335
    {`LM32_SIZE_HWORD, 2'b0?}: byte_enable_x = 4'b1100;
336
    {`LM32_SIZE_WORD, 2'b??}:  byte_enable_x = 4'b1111;
337
    default:                   byte_enable_x = 4'bxxxx;
338
    endcase
339
end
340
 
341
`ifdef CFG_DRAM_ENABLED
342
// Only replace selected bytes
343
assign dram_store_data_m[`LM32_BYTE_0_RNG] = byte_enable_m[0] ? store_data_m[`LM32_BYTE_0_RNG] : dram_data_m[`LM32_BYTE_0_RNG];
344
assign dram_store_data_m[`LM32_BYTE_1_RNG] = byte_enable_m[1] ? store_data_m[`LM32_BYTE_1_RNG] : dram_data_m[`LM32_BYTE_1_RNG];
345
assign dram_store_data_m[`LM32_BYTE_2_RNG] = byte_enable_m[2] ? store_data_m[`LM32_BYTE_2_RNG] : dram_data_m[`LM32_BYTE_2_RNG];
346
assign dram_store_data_m[`LM32_BYTE_3_RNG] = byte_enable_m[3] ? store_data_m[`LM32_BYTE_3_RNG] : dram_data_m[`LM32_BYTE_3_RNG];
347
`endif
348
 
349
// Select data from selected source
350
`ifdef CFG_DCACHE_ENABLED
351
`ifdef CFG_DRAM_ENABLED
352
assign data_m = wb_select_m == `TRUE
353
                ? wb_data_m
354
                : dram_select_m == `TRUE
355
                   ? dram_data_m
356
                   : dcache_data_m;
357
`else
358
assign data_m = wb_select_m == `TRUE ? wb_data_m : dcache_data_m;
359
`endif
360
`else
361
`ifdef CFG_DRAM_ENABLED
362
assign data_m = wb_select_m == `TRUE ? wb_data_m : dram_data_m;
363
`else
364
assign data_m = wb_data_m;
365
`endif
366
`endif
367
 
368
// Sub-word selection and sign/zero-extension for loads
369
always @(*)
370
begin
371
    casez ({size_w, load_store_address_w[1:0]})
372
    {`LM32_SIZE_BYTE, 2'b11}:  load_data_w = {{24{sign_extend_w & data_w[7]}}, data_w[7:0]};
373
    {`LM32_SIZE_BYTE, 2'b10}:  load_data_w = {{24{sign_extend_w & data_w[15]}}, data_w[15:8]};
374
    {`LM32_SIZE_BYTE, 2'b01}:  load_data_w = {{24{sign_extend_w & data_w[23]}}, data_w[23:16]};
375
    {`LM32_SIZE_BYTE, 2'b00}:  load_data_w = {{24{sign_extend_w & data_w[31]}}, data_w[31:24]};
376
    {`LM32_SIZE_HWORD, 2'b1?}: load_data_w = {{16{sign_extend_w & data_w[15]}}, data_w[15:0]};
377
    {`LM32_SIZE_HWORD, 2'b0?}: load_data_w = {{16{sign_extend_w & data_w[31]}}, data_w[31:16]};
378
    {`LM32_SIZE_WORD, 2'b??}:  load_data_w = data_w;
379
    default:                   load_data_w = {`LM32_WORD_WIDTH{1'bx}};
380
    endcase
381
end
382
 
383
// Unused Wishbone signals
384
assign d_cti_o = `LM32_CTYPE_WIDTH'd0;
385
assign d_lock_o = `FALSE;
386
assign d_bte_o = `LM32_BTYPE_WIDTH'd0;
387
 
388
`ifdef CFG_DCACHE_ENABLED
389
// Generate signal to indicate last word in cache line
390
generate
391
        if (bytes_per_line > 4)
392
        begin
393
assign first_address = {dcache_refill_address[`LM32_WORD_WIDTH-1:addr_offset_msb+1], {addr_offset_width{1'b0}}, 2'b00};
394
assign last_word = (&d_adr_o[addr_offset_msb:addr_offset_lsb]) == 1'b1;
395
        end
396
        else
397
        begin
398
assign first_address = {dcache_refill_address[`LM32_WORD_WIDTH-1:2], 2'b00};
399
assign last_word = `TRUE;
400
        end
401
endgenerate
402
`endif
403
 
404
/////////////////////////////////////////////////////
405
// Sequential Logic
406
/////////////////////////////////////////////////////
407
 
408
// Data Wishbone interface
409
always @(posedge clk_i `CFG_RESET_SENSITIVITY)
410
begin
411
    if (rst_i == `TRUE)
412
    begin
413
        d_cyc_o <= `FALSE;
414
        d_stb_o <= `FALSE;
415
        d_dat_o <= {`LM32_WORD_WIDTH{1'b0}};
416
        d_adr_o <= {`LM32_WORD_WIDTH{1'b0}};
417
        d_sel_o <= {`LM32_BYTE_SELECT_WIDTH{`FALSE}};
418
        d_we_o <= `FALSE;
419
        wb_data_m <= {`LM32_WORD_WIDTH{1'b0}};
420
        wb_load_complete <= `FALSE;
421
        stall_wb_load <= `FALSE;
422
`ifdef CFG_DCACHE_ENABLED
423
        dcache_refill_ready <= `FALSE;
424
`endif
425
    end
426
    else
427
    begin
428
`ifdef CFG_DCACHE_ENABLED
429
        // Refill ready should only be asserted for a single cycle               
430
        dcache_refill_ready <= `FALSE;
431
`endif
432
        // Is a Wishbone cycle already in progress?
433
        if (d_cyc_o == `TRUE)
434
        begin
435
            // Is the cycle complete?
436
            if ((d_ack_i == `TRUE) || (d_err_i == `TRUE))
437
            begin
438
`ifdef CFG_DCACHE_ENABLED
439
                if ((dcache_refilling == `TRUE) && (!last_word))
440
                begin
441
                    // Fetch next word of cache line    
442
                    d_adr_o[addr_offset_msb:addr_offset_lsb] <= d_adr_o[addr_offset_msb:addr_offset_lsb] + 1'b1;
443
                end
444
                else
445
`endif
446
                begin
447
                    // Refill/access complete
448
                    d_cyc_o <= `FALSE;
449
                    d_stb_o <= `FALSE;
450
                end
451
`ifdef CFG_DCACHE_ENABLED
452
                // If we are performing a refill, indicate to cache next word of data is ready            
453
                dcache_refill_ready <= dcache_refilling;
454
`endif
455
                // Register data read from Wishbone interface
456
                wb_data_m <= d_dat_i;
457
                // Don't set when stores complete - otherwise we'll deadlock if load in m stage
458
                wb_load_complete <= !d_we_o;
459
            end
460
            // synthesis translate_off            
461
            if (d_err_i == `TRUE)
462
                $display ("Data bus error. Address: %x", d_adr_o);
463
            // synthesis translate_on
464
        end
465
        else
466
        begin
467
`ifdef CFG_DCACHE_ENABLED
468
            if (dcache_refill_request == `TRUE)
469
            begin
470
                // Start cache refill
471
                d_adr_o <= first_address;
472
                d_cyc_o <= `TRUE;
473
                d_sel_o <= {`LM32_WORD_WIDTH/8{`TRUE}};
474
                d_stb_o <= `TRUE;
475
                d_we_o <= `FALSE;
476
            end
477
            else
478
`endif
479
                 if (   (store_q_m == `TRUE)
480
                     && (stall_m == `FALSE)
481
`ifdef CFG_DRAM_ENABLED
482
                     && !dram_select_m
483
`endif
484
                    )
485
            begin
486
                // Data cache is write through, so all stores go to memory
487
                d_dat_o <= store_data_m;
488
                d_adr_o <= load_store_address_m;
489
                d_cyc_o <= `TRUE;
490
                d_sel_o <= byte_enable_m;
491
                d_stb_o <= `TRUE;
492
                d_we_o <= `TRUE;
493
            end
494
            else if (   (load_q_m == `TRUE)
495
                     && (wb_select_m == `TRUE)
496
                     && (wb_load_complete == `FALSE)
497
                     /* stall_m will be TRUE, because stall_wb_load will be TRUE */
498
                    )
499
            begin
500
                // Read requested address
501
                stall_wb_load <= `FALSE;
502
                d_adr_o <= load_store_address_m;
503
                d_cyc_o <= `TRUE;
504
                d_sel_o <= byte_enable_m;
505
                d_stb_o <= `TRUE;
506
                d_we_o <= `FALSE;
507
            end
508
        end
509
        // Clear load/store complete flag when instruction leaves M stage
510
        if (stall_m == `FALSE)
511
            wb_load_complete <= `FALSE;
512
        // When a Wishbone load first enters the M stage, we need to stall it
513
        if ((load_q_x == `TRUE) && (wb_select_x == `TRUE) && (stall_x == `FALSE))
514
            stall_wb_load <= `TRUE;
515
        // Clear stall request if load instruction is killed
516
        if ((kill_m == `TRUE) || (exception_m == `TRUE))
517
            stall_wb_load <= `FALSE;
518
    end
519
end
520
 
521
// Pipeline registers  
522
 
523
// X/M stage pipeline registers
524
always @(posedge clk_i `CFG_RESET_SENSITIVITY)
525
begin
526
    if (rst_i == `TRUE)
527
    begin
528
        sign_extend_m <= `FALSE;
529
        size_m <= 2'b00;
530
        byte_enable_m <= `FALSE;
531
        store_data_m <= {`LM32_WORD_WIDTH{1'b0}};
532
`ifdef CFG_DCACHE_ENABLED
533
        dcache_select_m <= `FALSE;
534
`endif
535
`ifdef CFG_DRAM_ENABLED
536
        dram_select_m <= `FALSE;
537
`endif
538
        wb_select_m <= `FALSE;
539
    end
540
    else
541
    begin
542
        if (stall_m == `FALSE)
543
        begin
544
            sign_extend_m <= sign_extend_x;
545
            size_m <= size_x;
546
            byte_enable_m <= byte_enable_x;
547
            store_data_m <= store_data_x;
548
`ifdef CFG_DCACHE_ENABLED
549
            dcache_select_m <= dcache_select_x;
550
`endif
551
`ifdef CFG_DRAM_ENABLED
552
            dram_select_m <= dram_select_x;
553
`endif
554
            wb_select_m <= wb_select_x;
555
        end
556
    end
557
end
558
 
559
// M/W stage pipeline registers
560
always @(posedge clk_i `CFG_RESET_SENSITIVITY)
561
begin
562
    if (rst_i == `TRUE)
563
    begin
564
        size_w <= 2'b00;
565
        data_w <= {`LM32_WORD_WIDTH{1'b0}};
566
        sign_extend_w <= `FALSE;
567
    end
568
    else
569
    begin
570
        size_w <= size_m;
571
        data_w <= data_m;
572
        sign_extend_w <= sign_extend_m;
573
    end
574
end
575
 
576
/////////////////////////////////////////////////////
577
// Behavioural Logic
578
/////////////////////////////////////////////////////
579
 
580
// synthesis translate_off
581
 
582
// Check for non-aligned loads or stores
583
always @(posedge clk_i)
584
begin
585
    if (((load_q_m == `TRUE) || (store_q_m == `TRUE)) && (stall_m == `FALSE))
586
    begin
587
        if ((size_m === `LM32_SIZE_HWORD) && (load_store_address_m[0] !== 1'b0))
588
            $display ("Warning: Non-aligned halfword access. Address: 0x%0x Time: %0t.", load_store_address_m, $time);
589
        if ((size_m === `LM32_SIZE_WORD) && (load_store_address_m[1:0] !== 2'b00))
590
            $display ("Warning: Non-aligned word access. Address: 0x%0x Time: %0t.", load_store_address_m, $time);
591
    end
592
end
593
 
594
// synthesis translate_on
595
 
596
endmodule
597
 

powered by: WebSVN 2.1.0

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