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

Subversion Repositories amber

[/] [amber/] [trunk/] [hw/] [vlog/] [amber23/] [a23_execute.v] - Blame information for rev 89

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 csantifort
//////////////////////////////////////////////////////////////////
2
//                                                              //
3
//  Execute stage of Amber 2 Core                               //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Executes instructions. Instantiates the register file, ALU  //
10
//  multiplication unit and barrel shifter. This stage is       //
11
//  relitively simple. All the complex stuff is done in the     //
12
//  decode stage.                                               //
13
//                                                              //
14
//  Author(s):                                                  //
15
//      - Conor Santifort, csantifort.amber@gmail.com           //
16
//                                                              //
17
//////////////////////////////////////////////////////////////////
18
//                                                              //
19
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
20
//                                                              //
21
// This source file may be used and distributed without         //
22
// restriction provided that this copyright statement is not    //
23
// removed from the file and that any derivative work contains  //
24
// the original copyright notice and the associated disclaimer. //
25
//                                                              //
26
// This source file is free software; you can redistribute it   //
27
// and/or modify it under the terms of the GNU Lesser General   //
28
// Public License as published by the Free Software Foundation; //
29
// either version 2.1 of the License, or (at your option) any   //
30
// later version.                                               //
31
//                                                              //
32
// This source is distributed in the hope that it will be       //
33
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
34
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
35
// PURPOSE.  See the GNU Lesser General Public License for more //
36
// details.                                                     //
37
//                                                              //
38
// You should have received a copy of the GNU Lesser General    //
39
// Public License along with this source; if not, download it   //
40
// from http://www.opencores.org/lgpl.shtml                     //
41
//                                                              //
42
//////////////////////////////////////////////////////////////////
43
 
44 82 csantifort
`include "a23_config_defines.vh"
45 2 csantifort
 
46 15 csantifort
module a23_execute (
47 2 csantifort
 
48
input                       i_clk,
49
input       [31:0]          i_read_data,
50
input       [4:0]           i_read_data_alignment,  // 2 LSBs of address in [4:3], appended 
51
                                                    // with 3 zeros
52
input       [31:0]          i_copro_read_data,      // From Co-Processor, to either Register 
53
                                                    // or Memory
54
input                       i_data_access_exec,     // from Instruction Decode stage
55
                                                    // high means the memory access is a read 
56
                                                    // read or write, low for instruction
57
 
58
output reg  [31:0]          o_copro_write_data = 'd0,
59
output reg  [31:0]          o_write_data = 'd0,
60 89 csantifort
output wire [31:0]          o_address,
61 2 csantifort
output reg                  o_adex = 'd0,           // Address Exception
62
output reg                  o_address_valid = 'd0,  // Prevents the reset address value being a 
63
                                                    // wishbone access
64
output      [31:0]          o_address_nxt,          // un-registered version of address to the 
65
                                                    // cache rams address ports
66
output reg                  o_priviledged = 'd0,    // Priviledged access
67
output reg                  o_exclusive = 'd0,      // swap access
68
output reg                  o_write_enable = 'd0,
69
output reg  [3:0]           o_byte_enable = 'd0,
70
output reg                  o_data_access = 'd0,    // To Fetch stage. high = data fetch, 
71
                                                    // low = instruction fetch
72
output      [31:0]          o_status_bits,          // Full PC will all status bits, but PC part zero'ed out
73
output                      o_multiply_done,
74
 
75
 
76
// --------------------------------------------------
77
// Control signals from Instruction Decode stage
78
// --------------------------------------------------
79
input                       i_fetch_stall,          // stall all stages of the cpu at the same time
80
input      [1:0]            i_status_bits_mode,
81
input                       i_status_bits_irq_mask,
82
input                       i_status_bits_firq_mask,
83
input      [31:0]           i_imm32,
84
input      [4:0]            i_imm_shift_amount,
85
input                       i_shift_imm_zero,
86
input      [3:0]            i_condition,
87
input                       i_exclusive_exec,       // swap access
88 83 csantifort
input                       i_use_carry_in,         // e.g. add with carry instruction
89 2 csantifort
 
90
input      [3:0]            i_rm_sel,
91
input      [3:0]            i_rds_sel,
92
input      [3:0]            i_rn_sel,
93 71 csantifort
input      [3:0]            i_rm_sel_nxt,
94
input      [3:0]            i_rds_sel_nxt,
95
input      [3:0]            i_rn_sel_nxt,
96 2 csantifort
input      [1:0]            i_barrel_shift_amount_sel,
97
input      [1:0]            i_barrel_shift_data_sel,
98
input      [1:0]            i_barrel_shift_function,
99
input      [8:0]            i_alu_function,
100
input      [1:0]            i_multiply_function,
101
input      [2:0]            i_interrupt_vector_sel,
102
input      [3:0]            i_address_sel,
103
input      [1:0]            i_pc_sel,
104
input      [1:0]            i_byte_enable_sel,
105
input      [2:0]            i_status_bits_sel,
106
input      [2:0]            i_reg_write_sel,
107
input                       i_user_mode_regs_load,
108
input                       i_user_mode_regs_store_nxt,
109
input                       i_firq_not_user_mode,
110
 
111
input                       i_write_data_wen,
112
input                       i_base_address_wen,     // save LDM base address register, 
113
                                                    // in case of data abort
114
input                       i_pc_wen,
115
input      [14:0]           i_reg_bank_wen,
116 71 csantifort
input      [3:0]            i_reg_bank_wsel,
117 2 csantifort
input                       i_status_bits_flags_wen,
118
input                       i_status_bits_mode_wen,
119
input                       i_status_bits_irq_mask_wen,
120
input                       i_status_bits_firq_mask_wen,
121
input                       i_copro_write_data_wen
122
 
123
);
124
 
125 82 csantifort
`include "a23_localparams.vh"
126
`include "a23_functions.vh"
127 2 csantifort
 
128
// ========================================================
129
// Internal signals
130
// ========================================================
131
wire [31:0]         write_data_nxt;
132
wire [3:0]          byte_enable_nxt;
133
wire [31:0]         pc_plus4;
134
wire [31:0]         pc_minus4;
135
wire [31:0]         address_plus4;
136
wire [31:0]         alu_plus4;
137
wire [31:0]         rn_plus4;
138
wire [31:0]         alu_out;
139
wire [3:0]          alu_flags;
140
wire [31:0]         rm;
141
wire [31:0]         rs;
142
wire [31:0]         rd;
143
wire [31:0]         rn;
144
wire [31:0]         pc;
145
wire [31:0]         pc_nxt;
146
wire                write_enable_nxt;
147
wire [31:0]         interrupt_vector;
148
wire [7:0]          shift_amount;
149
wire [31:0]         barrel_shift_in;
150
wire [31:0]         barrel_shift_out;
151
wire                barrel_shift_carry;
152 88 csantifort
wire                barrel_shift_carry_alu;
153 2 csantifort
 
154
wire [3:0]          status_bits_flags_nxt;
155
reg  [3:0]          status_bits_flags = 'd0;
156
wire [1:0]          status_bits_mode_nxt;
157 71 csantifort
wire [1:0]          status_bits_mode_nr;
158 2 csantifort
reg  [1:0]          status_bits_mode = SVC;
159 71 csantifort
                    // raw rs select
160
wire [1:0]          status_bits_mode_rds_nxt;
161
wire [1:0]          status_bits_mode_rds_nr;
162
reg  [1:0]          status_bits_mode_rds;
163 2 csantifort
                    // one-hot encoded rs select
164
wire [3:0]          status_bits_mode_rds_oh_nxt;
165
reg  [3:0]          status_bits_mode_rds_oh = 1'd1 << OH_SVC;
166
wire                status_bits_mode_rds_oh_update;
167
wire                status_bits_irq_mask_nxt;
168
reg                 status_bits_irq_mask = 1'd1;
169
wire                status_bits_firq_mask_nxt;
170
reg                 status_bits_firq_mask = 1'd1;
171
 
172
wire                execute;           // high when condition execution is true
173
wire [31:0]         reg_write_nxt;
174
wire                pc_wen;
175
wire [14:0]         reg_bank_wen;
176 71 csantifort
wire [3:0]          reg_bank_wsel;
177 2 csantifort
wire [31:0]         multiply_out;
178
wire [1:0]          multiply_flags;
179
reg  [31:0]         base_address = 'd0;    // Saves base address during LDM instruction in 
180
                                           // case of data abort
181
 
182
wire                priviledged_nxt;
183
wire                priviledged_update;
184
wire                address_update;
185
wire                base_address_update;
186
wire                write_data_update;
187
wire                copro_write_data_update;
188
wire                byte_enable_update;
189
wire                data_access_update;
190
wire                write_enable_update;
191
wire                exclusive_update;
192
wire                status_bits_flags_update;
193
wire                status_bits_mode_update;
194
wire                status_bits_irq_mask_update;
195
wire                status_bits_firq_mask_update;
196 82 csantifort
wire [1:0]          status_bits_out;
197 2 csantifort
 
198
wire [31:0]         alu_out_pc_filtered;
199
wire                adex_nxt;
200
 
201 83 csantifort
wire                carry_in;
202
 
203 89 csantifort
reg  [31:0]         address_r = 32'hdead_dead;
204 83 csantifort
 
205 89 csantifort
 
206 2 csantifort
// ========================================================
207
// Status Bits in PC register
208
// ========================================================
209 82 csantifort
assign status_bits_out = (i_status_bits_mode_wen && i_status_bits_sel == 3'd1 && execute) ?
210 54 csantifort
                            alu_out[1:0] : status_bits_mode ;
211
 
212
 
213 2 csantifort
assign o_status_bits = {   status_bits_flags,           // 31:28
214
                           status_bits_irq_mask,        // 7
215
                           status_bits_firq_mask,       // 6
216
                           24'd0,
217 54 csantifort
                           status_bits_out};          // 1:0 = mode
218 2 csantifort
 
219
// ========================================================
220
// Status Bits Select
221
// ========================================================
222
assign status_bits_flags_nxt     = i_status_bits_sel == 3'd0 ? alu_flags                           :
223
                                   i_status_bits_sel == 3'd1 ? alu_out          [31:28]            :
224
                                   i_status_bits_sel == 3'd3 ? i_copro_read_data[31:28]            :
225 82 csantifort
                                   //  update flags after a multiply operation
226
                                   i_status_bits_sel == 3'd4 ? { multiply_flags, status_bits_flags[1:0] } :
227
                                   // regops that do not change the overflow flag
228
                                   i_status_bits_sel == 3'd5 ? { alu_flags[3:1], status_bits_flags[0] } :
229
                                                               4'b1111 ;
230 2 csantifort
 
231
assign status_bits_mode_nxt      = i_status_bits_sel == 3'd0 ? i_status_bits_mode       :
232 82 csantifort
                                   i_status_bits_sel == 3'd5 ? i_status_bits_mode       :
233 2 csantifort
                                   i_status_bits_sel == 3'd1 ? alu_out            [1:0] :
234
                                                               i_copro_read_data  [1:0] ;
235
 
236
 
237
// Used for the Rds output of register_bank - this special version of
238
// status_bits_mode speeds up the critical path from status_bits_mode through the
239
// register_bank, barrel_shifter and alu. It moves a mux needed for the
240
// i_user_mode_regs_store_nxt signal back into the previous stage -
241
// so its really part of the decode stage even though the logic is right here
242
// In addition the signal is one-hot encoded to further speed up the logic
243 71 csantifort
// Raw version is also kept for ram-based register bank implementation.
244 2 csantifort
 
245 72 csantifort
assign status_bits_mode_rds_nxt  = i_user_mode_regs_store_nxt ? USR                  :
246 71 csantifort
                                   status_bits_mode_update    ? status_bits_mode_nxt :
247
                                                                status_bits_mode     ;
248 2 csantifort
 
249 71 csantifort
assign status_bits_mode_rds_oh_nxt    = oh_status_bits_mode(status_bits_mode_rds_nxt);
250
 
251
 
252 2 csantifort
assign status_bits_irq_mask_nxt  = i_status_bits_sel == 3'd0 ? i_status_bits_irq_mask      :
253 82 csantifort
                                   i_status_bits_sel == 3'd5 ? i_status_bits_irq_mask      :
254 2 csantifort
                                   i_status_bits_sel == 3'd1 ? alu_out                [27] :
255
                                                               i_copro_read_data      [27] ;
256
 
257
assign status_bits_firq_mask_nxt = i_status_bits_sel == 3'd0 ? i_status_bits_firq_mask     :
258 82 csantifort
                                   i_status_bits_sel == 3'd5 ? i_status_bits_firq_mask     :
259 2 csantifort
                                   i_status_bits_sel == 3'd1 ? alu_out                [26] :
260
                                                               i_copro_read_data      [26] ;
261
 
262
 
263
 
264
// ========================================================
265
// Adders
266
// ========================================================
267
assign pc_plus4      = pc        + 32'd4;
268
assign pc_minus4     = pc        - 32'd4;
269 89 csantifort
assign address_plus4 = address_r + 32'd4;
270 2 csantifort
assign alu_plus4     = alu_out   + 32'd4;
271
assign rn_plus4      = rn        + 32'd4;
272
 
273 89 csantifort
 
274 2 csantifort
// ========================================================
275
// Barrel Shift Amount Select
276
// ========================================================
277
// An immediate shift value of 0 is translated into 32
278
assign shift_amount = i_barrel_shift_amount_sel == 2'd0 ? 8'd0                           :
279 82 csantifort
                      i_barrel_shift_amount_sel == 2'd1 ? rs[7:0]                        :
280 2 csantifort
                      i_barrel_shift_amount_sel == 2'd2 ? {3'd0, i_imm_shift_amount    } :
281
                                                          {3'd0, i_read_data_alignment } ;
282
 
283
// ========================================================
284
// Barrel Shift Data Select
285
// ========================================================
286
assign barrel_shift_in = i_barrel_shift_data_sel == 2'd0 ? i_imm32       :
287
                         i_barrel_shift_data_sel == 2'd1 ? i_read_data   :
288
                                                           rm            ;
289
 
290
// ========================================================
291
// Interrupt vector Select
292
// ========================================================
293
 
294
assign interrupt_vector = // Reset vector
295
                          (i_interrupt_vector_sel == 3'd0) ? 32'h00000000 :
296
                          // Data abort interrupt vector                 
297
                          (i_interrupt_vector_sel == 3'd1) ? 32'h00000010 :
298
                          // Fast interrupt vector  
299
                          (i_interrupt_vector_sel == 3'd2) ? 32'h0000001c :
300
                          // Regular interrupt vector
301
                          (i_interrupt_vector_sel == 3'd3) ? 32'h00000018 :
302
                          // Prefetch abort interrupt vector
303
                          (i_interrupt_vector_sel == 3'd5) ? 32'h0000000c :
304
                          // Undefined instruction interrupt vector
305
                          (i_interrupt_vector_sel == 3'd6) ? 32'h00000004 :
306
                          // Software (SWI) interrupt vector
307
                          (i_interrupt_vector_sel == 3'd7) ? 32'h00000008 :
308
                          // Default is the address exception interrupt
309
                                                             32'h00000014 ;
310
 
311
 
312
// ========================================================
313
// Address Select
314
// ========================================================
315
 
316
// If rd is the pc, then seperate the address bits from the status bits for
317
// generating the next address to fetch
318
assign alu_out_pc_filtered = pc_wen && i_pc_sel == 2'd1 ? pcf(alu_out) : alu_out;
319
 
320
// if current instruction does not execute because it does not meet the condition
321
// then address advances to next instruction
322
assign o_address_nxt = (!execute)              ? pc_plus4              :
323
                       (i_address_sel == 4'd0) ? pc_plus4              :
324
                       (i_address_sel == 4'd1) ? alu_out_pc_filtered   :
325
                       (i_address_sel == 4'd2) ? interrupt_vector      :
326
                       (i_address_sel == 4'd3) ? pc                    :
327
                       (i_address_sel == 4'd4) ? rn                    :
328
                       (i_address_sel == 4'd5) ? address_plus4         :  // MTRANS address incrementer
329
                       (i_address_sel == 4'd6) ? alu_plus4             :  // MTRANS decrement after
330
                                                 rn_plus4              ;  // MTRANS increment before
331
 
332
// Data accesses use 32-bit address space, but instruction
333
// accesses are restricted to 26 bit space
334
assign adex_nxt      = |o_address_nxt[31:26] && !i_data_access_exec;
335
 
336
// ========================================================
337
// Program Counter Select
338
// ========================================================
339
// If current instruction does not execute because it does not meet the condition
340
// then PC advances to next instruction
341
assign pc_nxt = (!execute)       ? pc_plus4              :
342
                i_pc_sel == 2'd0 ? pc_plus4              :
343
                i_pc_sel == 2'd1 ? alu_out               :
344
                                   interrupt_vector      ;
345
 
346
 
347
// ========================================================
348
// Register Write Select
349
// ========================================================
350
wire [31:0] save_int_pc;
351
wire [31:0] save_int_pc_m4;
352
 
353
assign save_int_pc    = { status_bits_flags,
354
                          status_bits_irq_mask,
355
                          status_bits_firq_mask,
356
                          pc[25:2],
357
                          status_bits_mode      };
358
 
359
 
360
assign save_int_pc_m4 = { status_bits_flags,
361
                          status_bits_irq_mask,
362
                          status_bits_firq_mask,
363
                          pc_minus4[25:2],
364
                          status_bits_mode      };
365
 
366
 
367
assign reg_write_nxt = i_reg_write_sel == 3'd0 ? alu_out               :
368
                       // save pc to lr on an interrupt                    
369
                       i_reg_write_sel == 3'd1 ? save_int_pc_m4        :
370
                       // to update Rd at the end of Multiplication
371
                       i_reg_write_sel == 3'd2 ? multiply_out          :
372
                       i_reg_write_sel == 3'd3 ? o_status_bits         :
373
                       i_reg_write_sel == 3'd5 ? i_copro_read_data     :  // mrc
374
                       i_reg_write_sel == 3'd6 ? base_address          :
375
                                                 save_int_pc           ;
376
 
377
 
378
// ========================================================
379
// Byte Enable Select
380
// ========================================================
381
assign byte_enable_nxt = i_byte_enable_sel == 2'd0  ? 4'b1111 :  // word write
382
                         i_byte_enable_sel == 2'd2  ?            // halfword write
383
                         ( o_address_nxt[1] == 1'd0 ? 4'b0011 :
384
                                                      4'b1100  ) :
385
 
386
                         o_address_nxt[1:0] == 2'd0 ? 4'b0001 :  // byte write
387
                         o_address_nxt[1:0] == 2'd1 ? 4'b0010 :
388
                         o_address_nxt[1:0] == 2'd2 ? 4'b0100 :
389
                                                      4'b1000 ;
390
 
391
 
392
// ========================================================
393
// Write Data Select
394
// ========================================================
395
assign write_data_nxt = i_byte_enable_sel == 2'd0 ? rd            :
396
                                                    {4{rd[ 7:0]}} ;
397
 
398
 
399
// ========================================================
400
// Conditional Execution
401
// ========================================================
402
assign execute = conditional_execute ( i_condition, status_bits_flags );
403
 
404
// allow the PC to increment to the next instruction when current
405
// instruction does not execute
406
assign pc_wen       = i_pc_wen || !execute;
407
 
408
// only update register bank if current instruction executes
409
assign reg_bank_wen = {{15{execute}} & i_reg_bank_wen};
410
 
411 71 csantifort
assign reg_bank_wsel = {{4{~execute}} | i_reg_bank_wsel};
412 2 csantifort
 
413 71 csantifort
 
414 2 csantifort
// ========================================================
415
// Priviledged output flag
416
// ========================================================
417
// Need to look at status_bits_mode_nxt so switch to priviledged mode
418
// at the same time as assert interrupt vector address
419
assign priviledged_nxt  = ( i_status_bits_mode_wen ? status_bits_mode_nxt : status_bits_mode ) != USR ;
420
 
421
 
422
// ========================================================
423
// Write Enable
424
// ========================================================
425
// This must be de-asserted when execute is fault
426
assign write_enable_nxt = execute && i_write_data_wen;
427
 
428
 
429
// ========================================================
430
// Register Update
431
// ========================================================
432
 
433
assign priviledged_update              = !i_fetch_stall;
434
assign data_access_update              = !i_fetch_stall && execute;
435
assign write_enable_update             = !i_fetch_stall;
436
assign write_data_update               = !i_fetch_stall && execute && i_write_data_wen;
437
assign exclusive_update                = !i_fetch_stall && execute;
438
assign address_update                  = !i_fetch_stall;
439
assign byte_enable_update              = !i_fetch_stall && execute && i_write_data_wen;
440
assign copro_write_data_update         = !i_fetch_stall && execute && i_copro_write_data_wen;
441
 
442
assign base_address_update             = !i_fetch_stall && execute && i_base_address_wen;
443
assign status_bits_flags_update        = !i_fetch_stall && execute && i_status_bits_flags_wen;
444
assign status_bits_mode_update         = !i_fetch_stall && execute && i_status_bits_mode_wen;
445
assign status_bits_mode_rds_oh_update  = !i_fetch_stall;
446
assign status_bits_irq_mask_update     = !i_fetch_stall && execute && i_status_bits_irq_mask_wen;
447
assign status_bits_firq_mask_update    = !i_fetch_stall && execute && i_status_bits_firq_mask_wen;
448
 
449 71 csantifort
assign status_bits_mode_rds_nr         =  status_bits_mode_rds_oh_update ? status_bits_mode_rds_nxt :
450
                                                                           status_bits_mode_rds     ;
451 2 csantifort
 
452 71 csantifort
assign status_bits_mode_nr             =  status_bits_mode_update        ? status_bits_mode_nxt     :
453
                                                                           status_bits_mode         ;
454
 
455 2 csantifort
always @( posedge i_clk )
456
    begin
457
    o_priviledged           <= priviledged_update             ? priviledged_nxt              : o_priviledged;
458
    o_exclusive             <= exclusive_update               ? i_exclusive_exec             : o_exclusive;
459
    o_data_access           <= data_access_update             ? i_data_access_exec           : o_data_access;
460
    o_write_enable          <= write_enable_update            ? write_enable_nxt             : o_write_enable;
461
    o_write_data            <= write_data_update              ? write_data_nxt               : o_write_data;
462 89 csantifort
    address_r               <= address_update                 ? o_address_nxt                : address_r;
463 2 csantifort
    o_adex                  <= address_update                 ? adex_nxt                     : o_adex;
464
    o_address_valid         <= address_update                 ? 1'd1                         : o_address_valid;
465
    o_byte_enable           <= byte_enable_update             ? byte_enable_nxt              : o_byte_enable;
466
    o_copro_write_data      <= copro_write_data_update        ? write_data_nxt               : o_copro_write_data;
467
 
468
    base_address            <= base_address_update            ? rn                           : base_address;
469
 
470
    status_bits_flags       <= status_bits_flags_update       ? status_bits_flags_nxt        : status_bits_flags;
471 71 csantifort
    status_bits_mode        <=  status_bits_mode_nr;
472 2 csantifort
    status_bits_mode_rds_oh <= status_bits_mode_rds_oh_update ? status_bits_mode_rds_oh_nxt  : status_bits_mode_rds_oh;
473 71 csantifort
    status_bits_mode_rds    <= status_bits_mode_rds_nr;
474 2 csantifort
    status_bits_irq_mask    <= status_bits_irq_mask_update    ? status_bits_irq_mask_nxt     : status_bits_irq_mask;
475
    status_bits_firq_mask   <= status_bits_firq_mask_update   ? status_bits_firq_mask_nxt    : status_bits_firq_mask;
476
    end
477
 
478 89 csantifort
assign o_address = address_r;
479 2 csantifort
 
480 89 csantifort
 
481 2 csantifort
// ========================================================
482
// Instantiate Barrel Shift
483
// ========================================================
484 83 csantifort
 
485
assign carry_in = i_use_carry_in ? status_bits_flags[1] : 1'd0;
486
 
487 74 csantifort
`ifndef ALTERA_FPGA
488 15 csantifort
a23_barrel_shift u_barrel_shift  (
489 74 csantifort
`else
490
a23_barrel_shift_fpga u_barrel_shift  (
491
`endif
492 2 csantifort
    .i_in             ( barrel_shift_in           ),
493 83 csantifort
    .i_carry_in       ( carry_in                  ),
494 2 csantifort
    .i_shift_amount   ( shift_amount              ),
495
    .i_shift_imm_zero ( i_shift_imm_zero          ),
496
    .i_function       ( i_barrel_shift_function   ),
497
 
498
    .o_out            ( barrel_shift_out          ),
499 88 csantifort
    .o_carry_out      ( barrel_shift_carry        ));
500 2 csantifort
 
501
 
502 87 csantifort
 
503 2 csantifort
// ========================================================
504
// Instantiate ALU
505
// ========================================================
506 88 csantifort
assign barrel_shift_carry_alu =  i_barrel_shift_data_sel == 2'd0 ?
507
                                  (i_imm_shift_amount[4:1] == 0 ? status_bits_flags[1] : i_imm32[31]) :
508
                                   barrel_shift_carry;
509
 
510 15 csantifort
a23_alu u_alu (
511 88 csantifort
    .i_a_in                 ( rn                      ),
512
    .i_b_in                 ( barrel_shift_out        ),
513
    .i_barrel_shift_carry   ( barrel_shift_carry_alu  ),
514
    .i_status_bits_carry    ( status_bits_flags[1]    ),
515
    .i_function             ( i_alu_function          ),
516
 
517
    .o_out                  ( alu_out                 ),
518
    .o_flags                ( alu_flags               ));
519 2 csantifort
 
520
 
521
 
522
// ========================================================
523
// Instantiate Booth 64-bit Multiplier-Accumulator
524
// ========================================================
525 15 csantifort
a23_multiply u_multiply (
526 2 csantifort
    .i_clk          ( i_clk                 ),
527
    .i_fetch_stall  ( i_fetch_stall         ),
528
    .i_a_in         ( rs                    ),
529
    .i_b_in         ( rm                    ),
530
    .i_function     ( i_multiply_function   ),
531
    .i_execute      ( execute               ),
532
    .o_out          ( multiply_out          ),
533
    .o_flags        ( multiply_flags        ),  // [1] = N, [0] = Z
534
    .o_done         ( o_multiply_done       )
535
);
536
 
537
 
538
// ========================================================
539
// Instantiate Register Bank
540
// ========================================================
541 73 csantifort
`ifndef A23_RAM_REGISTER_BANK
542 15 csantifort
a23_register_bank u_register_bank(
543 2 csantifort
    .i_clk                   ( i_clk                     ),
544
    .i_fetch_stall           ( i_fetch_stall             ),
545
    .i_rm_sel                ( i_rm_sel                  ),
546
    .i_rds_sel               ( i_rds_sel                 ),
547
    .i_rn_sel                ( i_rn_sel                  ),
548
    .i_pc_wen                ( pc_wen                    ),
549
    .i_reg_bank_wen          ( reg_bank_wen              ),
550
    .i_pc                    ( pc_nxt[25:2]              ),
551
    .i_reg                   ( reg_write_nxt             ),
552
    .i_mode_idec             ( i_status_bits_mode        ),
553
    .i_mode_exec             ( status_bits_mode          ),
554
 
555
    .i_status_bits_flags     ( status_bits_flags         ),
556
    .i_status_bits_irq_mask  ( status_bits_irq_mask      ),
557
    .i_status_bits_firq_mask ( status_bits_firq_mask     ),
558
 
559
    // pre-encoded in decode stage to speed up long path
560
    .i_firq_not_user_mode    ( i_firq_not_user_mode      ),
561
 
562
    // use one-hot version for speed, combine with i_user_mode_regs_store
563
    .i_mode_rds_exec         ( status_bits_mode_rds_oh   ),
564
 
565
    .i_user_mode_regs_load   ( i_user_mode_regs_load     ),
566
    .o_rm                    ( rm                        ),
567
    .o_rs                    ( rs                        ),
568
    .o_rd                    ( rd                        ),
569
    .o_rn                    ( rn                        ),
570
    .o_pc                    ( pc                        )
571
);
572 73 csantifort
`else
573
a23_ram_register_bank u_register_bank(
574
    .i_clk                   ( i_clk                     ),
575
    .i_fetch_stall           ( i_fetch_stall             ),
576
    .i_rm_sel                ( i_rm_sel_nxt              ),
577
    .i_rds_sel               ( i_rds_sel_nxt             ),
578
    .i_rn_sel                ( i_rn_sel_nxt              ),
579
    .i_pc_wen                ( pc_wen                    ),
580
    .i_reg_bank_wsel         ( reg_bank_wsel             ),
581
    .i_pc                    ( pc_nxt[25:2]              ),
582
    .i_reg                   ( reg_write_nxt             ),
583 2 csantifort
 
584 73 csantifort
    .i_mode_exec_nxt         ( status_bits_mode_nr       ),
585
    .i_mode_exec             ( status_bits_mode          ),
586
    .i_mode_rds_exec         ( status_bits_mode_rds_nr   ),
587
    .i_user_mode_regs_load   ( i_user_mode_regs_load     ),
588 2 csantifort
 
589 73 csantifort
    .i_status_bits_flags     ( status_bits_flags         ),
590
    .i_status_bits_irq_mask  ( status_bits_irq_mask      ),
591
    .i_status_bits_firq_mask ( status_bits_firq_mask     ),
592
 
593
    .o_rm                    ( rm                        ),
594
    .o_rs                    ( rs                        ),
595
    .o_rd                    ( rd                        ),
596
    .o_rn                    ( rn                        ),
597
    .o_pc                    ( pc                        )
598
);
599
`endif
600
 
601 2 csantifort
// ========================================================
602
// Debug - non-synthesizable code
603
// ========================================================
604
//synopsys translate_off
605
 
606
wire    [(2*8)-1:0]    xCONDITION;
607
wire    [(4*8)-1:0]    xMODE;
608
 
609
assign  xCONDITION           = i_condition == EQ ? "EQ"  :
610
                               i_condition == NE ? "NE"  :
611
                               i_condition == CS ? "CS"  :
612
                               i_condition == CC ? "CC"  :
613
                               i_condition == MI ? "MI"  :
614
                               i_condition == PL ? "PL"  :
615
                               i_condition == VS ? "VS"  :
616
                               i_condition == VC ? "VC"  :
617
                               i_condition == HI ? "HI"  :
618
                               i_condition == LS ? "LS"  :
619
                               i_condition == GE ? "GE"  :
620
                               i_condition == LT ? "LT"  :
621
                               i_condition == GT ? "GT"  :
622
                               i_condition == LE ? "LE"  :
623
                               i_condition == AL ? "AL"  :
624
                                                   "NV " ;
625
 
626
assign  xMODE  =  status_bits_mode == SVC  ? "SVC"  :
627
                  status_bits_mode == IRQ  ? "IRQ"  :
628
                  status_bits_mode == FIRQ ? "FIRQ" :
629
                  status_bits_mode == USR  ? "USR"  :
630
                                             "XXX"  ;
631
 
632
 
633
//synopsys translate_on
634
 
635
endmodule
636
 
637
 

powered by: WebSVN 2.1.0

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