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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [rtl/] [verilog/] [omsp_execution_unit.v] - Blame information for rev 103

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

Line No. Rev Author Line
1 2 olivier.gi
//----------------------------------------------------------------------------
2
// Copyright (C) 2001 Authors
3
//
4
// This source file may be used and distributed without restriction provided
5
// that this copyright statement is not removed from the file and that any
6
// derivative work contains the original copyright notice and the associated
7
// disclaimer.
8
//
9
// This source file is free software; you can redistribute it and/or modify
10
// it under the terms of the GNU Lesser General Public License as published
11
// by the Free Software Foundation; either version 2.1 of the License, or
12
// (at your option) any later version.
13
//
14
// This source is distributed in the hope that it will be useful, but WITHOUT
15
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17
// License for more details.
18
//
19
// You should have received a copy of the GNU Lesser General Public License
20
// along with this source; if not, write to the Free Software Foundation,
21
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22
//
23
//----------------------------------------------------------------------------
24
//
25 34 olivier.gi
// *File Name: omsp_execution_unit.v
26 2 olivier.gi
// 
27
// *Module Description:
28
//                       openMSP430 Execution unit
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 17 olivier.gi
// $Rev: 103 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2011-03-05 15:44:48 +0100 (Sat, 05 Mar 2011) $
37
//----------------------------------------------------------------------------
38 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
39
`else
40 23 olivier.gi
`include "openMSP430_defines.v"
41 103 olivier.gi
`endif
42 2 olivier.gi
 
43 34 olivier.gi
module  omsp_execution_unit (
44 2 olivier.gi
 
45
// OUTPUTs
46
    cpuoff,                        // Turns off the CPU
47
    dbg_reg_din,                   // Debug unit CPU register data input
48
    gie,                           // General interrupt enable
49
    mab,                           // Memory address bus
50
    mb_en,                         // Memory bus enable
51
    mb_wr,                         // Memory bus write transfer
52
    mdb_out,                       // Memory data bus output
53
    oscoff,                        // Turns off LFXT1 clock input
54
    pc_sw,                         // Program counter software value
55
    pc_sw_wr,                      // Program counter software write
56
    scg1,                          // System clock generator 1. Turns off the SMCLK
57
 
58
// INPUTs
59
    dbg_halt_st,                   // Halt/Run status from CPU
60
    dbg_mem_dout,                  // Debug unit data output
61
    dbg_reg_wr,                    // Debug unit CPU register write
62
    e_state,                       // Execution state
63
    exec_done,                     // Execution completed
64
    inst_ad,                       // Decoded Inst: destination addressing mode
65
    inst_as,                       // Decoded Inst: source addressing mode
66
    inst_alu,                      // ALU control signals
67
    inst_bw,                       // Decoded Inst: byte width
68
    inst_dest,                     // Decoded Inst: destination (one hot)
69
    inst_dext,                     // Decoded Inst: destination extended instruction word
70
    inst_irq_rst,                  // Decoded Inst: reset interrupt
71
    inst_jmp,                      // Decoded Inst: Conditional jump
72
    inst_sext,                     // Decoded Inst: source extended instruction word
73
    inst_so,                       // Decoded Inst: Single-operand arithmetic
74
    inst_src,                      // Decoded Inst: source (one hot)
75
    inst_type,                     // Decoded Instruction type
76
    mclk,                          // Main system clock
77
    mdb_in,                        // Memory data bus input
78
    pc,                            // Program counter
79
    pc_nxt,                        // Next PC value (for CALL & IRQ)
80
    puc                            // Main system reset
81
);
82
 
83
// OUTPUTs
84
//=========
85
output              cpuoff;        // Turns off the CPU
86
output       [15:0] dbg_reg_din;   // Debug unit CPU register data input
87
output              gie;           // General interrupt enable
88
output       [15:0] mab;           // Memory address bus
89
output              mb_en;         // Memory bus enable
90
output        [1:0] mb_wr;         // Memory bus write transfer
91
output       [15:0] mdb_out;       // Memory data bus output
92
output              oscoff;        // Turns off LFXT1 clock input
93
output       [15:0] pc_sw;         // Program counter software value
94
output              pc_sw_wr;      // Program counter software write
95
output              scg1;          // System clock generator 1. Turns off the SMCLK
96
 
97
// INPUTs
98
//=========
99
input               dbg_halt_st;   // Halt/Run status from CPU
100
input        [15:0] dbg_mem_dout;  // Debug unit data output
101
input               dbg_reg_wr;    // Debug unit CPU register write
102
input         [3:0] e_state;       // Execution state
103
input               exec_done;     // Execution completed
104
input         [7:0] inst_ad;       // Decoded Inst: destination addressing mode
105
input         [7:0] inst_as;       // Decoded Inst: source addressing mode
106
input        [11:0] inst_alu;      // ALU control signals
107
input               inst_bw;       // Decoded Inst: byte width
108
input        [15:0] inst_dest;     // Decoded Inst: destination (one hot)
109
input        [15:0] inst_dext;     // Decoded Inst: destination extended instruction word
110
input               inst_irq_rst;  // Decoded Inst: reset interrupt
111
input         [7:0] inst_jmp;      // Decoded Inst: Conditional jump
112
input        [15:0] inst_sext;     // Decoded Inst: source extended instruction word
113
input         [7:0] inst_so;       // Decoded Inst: Single-operand arithmetic
114
input        [15:0] inst_src;      // Decoded Inst: source (one hot)
115
input         [2:0] inst_type;     // Decoded Instruction type
116
input               mclk;          // Main system clock
117
input        [15:0] mdb_in;        // Memory data bus input
118
input        [15:0] pc;            // Program counter
119
input        [15:0] pc_nxt;        // Next PC value (for CALL & IRQ)
120
input               puc;           // Main system reset
121
 
122
 
123
//=============================================================================
124
// 1)  INTERNAL WIRES/REGISTERS/PARAMETERS DECLARATION
125
//=============================================================================
126
 
127
wire         [15:0] alu_out;
128
wire         [15:0] alu_out_add;
129
wire          [3:0] alu_stat;
130
wire          [3:0] alu_stat_wr;
131
wire         [15:0] op_dst;
132
wire         [15:0] op_src;
133
wire         [15:0] reg_dest;
134
wire         [15:0] reg_src;
135
wire         [15:0] mdb_in_bw;
136
wire         [15:0] mdb_in_val;
137
wire          [3:0] status;
138
 
139
 
140
//=============================================================================
141
// 2)  REGISTER FILE
142
//=============================================================================
143
 
144
wire reg_dest_wr  = ((e_state==`E_EXEC) & (
145
                     (inst_type[`INST_TO] & inst_ad[`DIR] & ~inst_alu[`EXEC_NO_WR])  |
146
                     (inst_type[`INST_SO] & inst_as[`DIR] & ~(inst_so[`PUSH] | inst_so[`CALL] | inst_so[`RETI])) |
147
                      inst_type[`INST_JMP])) | dbg_reg_wr;
148
 
149
wire reg_sp_wr    = (((e_state==`E_IRQ_1) | (e_state==`E_IRQ_3)) & ~inst_irq_rst) |
150 102 olivier.gi
                     ((e_state==`E_DST_RD) & ((inst_so[`PUSH] &  ~inst_as[`IDX] &
151
                                                                ~((inst_as[`INDIR] | inst_as[`INDIR_I]) & inst_src[1])) |
152
                                               inst_so[`CALL])) |
153
                     ((e_state==`E_SRC_AD) &  (inst_so[`PUSH] &  inst_as[`IDX])) |
154
                     ((e_state==`E_SRC_RD) &  (inst_so[`PUSH] &  ((inst_as[`INDIR] | inst_as[`INDIR_I]) & inst_src[1])));
155 2 olivier.gi
 
156
wire reg_sr_wr    =  (e_state==`E_DST_RD) & inst_so[`RETI];
157
 
158
wire reg_sr_clr   =  (e_state==`E_IRQ_2);
159
 
160
wire reg_pc_call  = ((e_state==`E_EXEC)   & inst_so[`CALL]) |
161
                    ((e_state==`E_DST_WR) & inst_so[`RETI]);
162
 
163
wire reg_incr     =  (exec_done          & inst_as[`INDIR_I]) |
164
                    ((e_state==`E_SRC_RD) & inst_so[`RETI])    |
165
                    ((e_state==`E_EXEC)   & inst_so[`RETI]);
166
 
167
assign dbg_reg_din = reg_dest;
168
 
169
 
170 34 olivier.gi
omsp_register_file register_file_0 (
171 2 olivier.gi
 
172
// OUTPUTs
173
    .cpuoff       (cpuoff),       // Turns off the CPU
174
    .gie          (gie),          // General interrupt enable
175
    .oscoff       (oscoff),       // Turns off LFXT1 clock input
176
    .pc_sw        (pc_sw),        // Program counter software value
177
    .pc_sw_wr     (pc_sw_wr),     // Program counter software write
178
    .reg_dest     (reg_dest),     // Selected register destination content
179
    .reg_src      (reg_src),      // Selected register source content
180
    .scg1         (scg1),         // System clock generator 1. Turns off the SMCLK
181
    .status       (status),       // R2 Status {V,N,Z,C}
182
 
183
// INPUTs
184
    .alu_stat     (alu_stat),     // ALU Status {V,N,Z,C}
185
    .alu_stat_wr  (alu_stat_wr),  // ALU Status write {V,N,Z,C}
186
    .inst_bw      (inst_bw),      // Decoded Inst: byte width
187
    .inst_dest    (inst_dest),    // Register destination selection
188
    .inst_src     (inst_src),     // Register source selection
189
    .mclk         (mclk),         // Main system clock
190
    .pc           (pc),           // Program counter
191
    .puc          (puc),          // Main system reset
192
    .reg_dest_val (alu_out),      // Selected register destination value
193
    .reg_dest_wr  (reg_dest_wr),  // Write selected register destination
194
    .reg_pc_call  (reg_pc_call),  // Trigger PC update for a CALL instruction
195
    .reg_sp_val   (alu_out_add),  // Stack Pointer next value
196
    .reg_sp_wr    (reg_sp_wr),    // Stack Pointer write
197
    .reg_sr_clr   (reg_sr_clr),   // Status register clear for interrupts
198
    .reg_sr_wr    (reg_sr_wr),    // Status Register update for RETI instruction
199
    .reg_incr     (reg_incr)      // Increment source register
200
);
201
 
202
 
203
//=============================================================================
204
// 3)  SOURCE OPERAND MUXING
205
//=============================================================================
206
// inst_as[`DIR]    : Register direct.   -> Source is in register
207
// inst_as[`IDX]    : Register indexed.  -> Source is in memory, address is register+offset
208
// inst_as[`INDIR]  : Register indirect.
209
// inst_as[`INDIR_I]: Register indirect autoincrement.
210
// inst_as[`SYMB]   : Symbolic (operand is in memory at address PC+x).
211
// inst_as[`IMM]    : Immediate (operand is next word in the instruction stream).
212
// inst_as[`ABS]    : Absolute (operand is in memory at address x).
213
// inst_as[`CONST]  : Constant.
214
 
215
wire src_reg_src_sel    =  (e_state==`E_IRQ_0)                    |
216
                           (e_state==`E_IRQ_2)                    |
217
                          ((e_state==`E_SRC_RD) & ~inst_as[`ABS]) |
218
                          ((e_state==`E_SRC_WR) & ~inst_as[`ABS]) |
219
                          ((e_state==`E_EXEC)   &  inst_as[`DIR] & ~inst_type[`INST_JMP]);
220
 
221
wire src_reg_dest_sel   =  (e_state==`E_IRQ_1)                    |
222
                           (e_state==`E_IRQ_3)                    |
223 102 olivier.gi
                          ((e_state==`E_DST_RD) & (inst_so[`PUSH] | inst_so[`CALL])) |
224
                          ((e_state==`E_SRC_AD) &  inst_so[`PUSH] & inst_as[`IDX]);
225 2 olivier.gi
 
226
wire src_mdb_in_val_sel = ((e_state==`E_DST_RD) &  inst_so[`RETI])                     |
227
                          ((e_state==`E_EXEC)   & (inst_as[`INDIR] | inst_as[`INDIR_I] |
228
                                                   inst_as[`IDX]   | inst_as[`SYMB]    |
229
                                                   inst_as[`ABS]));
230
 
231
wire src_inst_dext_sel =  ((e_state==`E_DST_RD) & ~(inst_so[`PUSH] | inst_so[`CALL])) |
232
                          ((e_state==`E_DST_WR) & ~(inst_so[`PUSH] | inst_so[`CALL]   |
233
                                                    inst_so[`RETI]));
234
 
235
wire src_inst_sext_sel =  ((e_state==`E_EXEC)   &  (inst_type[`INST_JMP] | inst_as[`IMM] |
236
                                                    inst_as[`CONST]      | inst_so[`RETI]));
237
 
238
 
239
assign op_src = src_reg_src_sel     ?  reg_src    :
240
                src_reg_dest_sel    ?  reg_dest   :
241
                src_mdb_in_val_sel  ?  mdb_in_val :
242
                src_inst_dext_sel   ?  inst_dext  :
243
                src_inst_sext_sel   ?  inst_sext  : 16'h0000;
244
 
245
 
246
//=============================================================================
247
// 4)  DESTINATION OPERAND MUXING
248
//=============================================================================
249
// inst_ad[`DIR]    : Register direct.
250
// inst_ad[`IDX]    : Register indexed.
251
// inst_ad[`SYMB]   : Symbolic (operand is in memory at address PC+x).
252
// inst_ad[`ABS]    : Absolute (operand is in memory at address x).
253
 
254
 
255
wire dst_inst_sext_sel  = ((e_state==`E_SRC_RD) & (inst_as[`IDX] | inst_as[`SYMB] |
256
                                                   inst_as[`ABS]))                |
257
                          ((e_state==`E_SRC_WR) & (inst_as[`IDX] | inst_as[`SYMB] |
258
                                                   inst_as[`ABS]));
259
 
260
wire dst_mdb_in_bw_sel  = ((e_state==`E_DST_WR) &   inst_so[`RETI]) |
261
                          ((e_state==`E_EXEC)   & ~(inst_ad[`DIR] | inst_type[`INST_JMP] |
262
                                                    inst_type[`INST_SO]) & ~inst_so[`RETI]);
263
 
264
wire dst_fffe_sel       =  (e_state==`E_IRQ_0)  |
265
                           (e_state==`E_IRQ_1)  |
266
                           (e_state==`E_IRQ_3)  |
267 102 olivier.gi
                          ((e_state==`E_DST_RD) & (inst_so[`PUSH] | inst_so[`CALL]) & ~inst_so[`RETI]) |
268
                          ((e_state==`E_SRC_AD) &  inst_so[`PUSH] & inst_as[`IDX]) |
269
                          ((e_state==`E_SRC_RD) &  inst_so[`PUSH] & (inst_as[`INDIR] | inst_as[`INDIR_I]) & inst_src[1]);
270 2 olivier.gi
 
271
wire dst_reg_dest_sel   = ((e_state==`E_DST_RD) & ~(inst_so[`PUSH] | inst_so[`CALL] | inst_ad[`ABS] | inst_so[`RETI])) |
272
                          ((e_state==`E_DST_WR) &  ~inst_ad[`ABS]) |
273
                          ((e_state==`E_EXEC)   &  (inst_ad[`DIR] | inst_type[`INST_JMP] |
274
                                                    inst_type[`INST_SO]) & ~inst_so[`RETI]);
275
 
276
 
277
assign op_dst = dbg_halt_st        ? dbg_mem_dout  :
278
                dst_inst_sext_sel  ? inst_sext     :
279
                dst_mdb_in_bw_sel  ? mdb_in_bw     :
280
                dst_reg_dest_sel   ? reg_dest      :
281
                dst_fffe_sel       ? 16'hfffe      : 16'h0000;
282
 
283
 
284
//=============================================================================
285
// 5)  ALU
286
//=============================================================================
287
 
288
wire exec_cycle = (e_state==`E_EXEC);
289
 
290 34 olivier.gi
omsp_alu alu_0 (
291 2 olivier.gi
 
292
// OUTPUTs
293
    .alu_out      (alu_out),      // ALU output value
294
    .alu_out_add  (alu_out_add),  // ALU adder output value
295
    .alu_stat     (alu_stat),     // ALU Status {V,N,Z,C}
296
    .alu_stat_wr  (alu_stat_wr),  // ALU Status write {V,N,Z,C}
297
 
298
// INPUTs
299
    .dbg_halt_st  (dbg_halt_st),  // Halt/Run status from CPU
300
    .exec_cycle   (exec_cycle),   // Instruction execution cycle
301
    .inst_alu     (inst_alu),     // ALU control signals
302
    .inst_bw      (inst_bw),      // Decoded Inst: byte width
303
    .inst_jmp     (inst_jmp),     // Decoded Inst: Conditional jump
304
    .inst_so      (inst_so),      // Single-operand arithmetic
305
    .op_dst       (op_dst),       // Destination operand
306
    .op_src       (op_src),       // Source operand
307
    .status       (status)        // R2 Status {V,N,Z,C}
308
);
309
 
310
 
311
//=============================================================================
312
// 6)  MEMORY INTERFACE
313
//=============================================================================
314
 
315
// Detect memory read/write access
316
assign      mb_en     = ((e_state==`E_IRQ_1)  & ~inst_irq_rst)      |
317
                        ((e_state==`E_IRQ_3)  & ~inst_irq_rst)      |
318
                        ((e_state==`E_SRC_RD) & ~inst_as[`IMM])     |
319
                         (e_state==`E_SRC_WR)                       |
320
                        ((e_state==`E_EXEC)   & inst_so[`RETI])     |
321
                         (e_state==`E_DST_RD)                       |
322
                         (e_state==`E_DST_WR);
323
 
324
wire  [1:0] mb_wr_msk =  inst_alu[`EXEC_NO_WR]  ? 2'b00 :
325
                        ~inst_bw                ? 2'b11 :
326
                         alu_out_add[0]         ? 2'b10 : 2'b01;
327
assign      mb_wr     = ({2{(e_state==`E_IRQ_1)}}  |
328
                         {2{(e_state==`E_IRQ_3)}}  |
329
                         {2{(e_state==`E_DST_WR)}} |
330
                         {2{(e_state==`E_SRC_WR)}}) & mb_wr_msk;
331
 
332
// Memory address bus
333
assign      mab       = alu_out_add[15:0];
334
 
335
// Memory data bus output
336
reg  [15:0] mdb_out_nxt;
337
always @(posedge mclk or posedge puc)
338
  if (puc)                                            mdb_out_nxt <= 16'h0000;
339
  else if (e_state==`E_DST_RD)                        mdb_out_nxt <= pc_nxt;
340
  else if ((e_state==`E_EXEC & ~inst_so[`CALL]) |
341
           (e_state==`E_IRQ_0) | (e_state==`E_IRQ_2)) mdb_out_nxt <= alu_out;
342
 
343
assign      mdb_out = inst_bw ? {2{mdb_out_nxt[7:0]}} : mdb_out_nxt;
344
 
345
// Format memory data bus input depending on BW
346
reg        mab_lsb;
347
always @(posedge mclk or posedge puc)
348
  if (puc)        mab_lsb <= 1'b0;
349
  else if (mb_en) mab_lsb <= alu_out_add[0];
350
 
351
assign mdb_in_bw  = ~inst_bw ? mdb_in :
352
                     mab_lsb ? {2{mdb_in[15:8]}} : mdb_in;
353
 
354
// Memory data bus input buffer (buffer after a source read)
355
reg         mdb_in_buf_en;
356
always @(posedge mclk or posedge puc)
357
  if (puc)  mdb_in_buf_en <= 1'b0;
358
  else      mdb_in_buf_en <= (e_state==`E_SRC_RD);
359
 
360
reg         mdb_in_buf_valid;
361
always @(posedge mclk or posedge puc)
362
  if (puc)                   mdb_in_buf_valid <= 1'b0;
363
  else if (e_state==`E_EXEC) mdb_in_buf_valid <= 1'b0;
364
  else if (mdb_in_buf_en)    mdb_in_buf_valid <= 1'b1;
365
 
366
reg  [15:0] mdb_in_buf;
367
always @(posedge mclk or posedge puc)
368
  if (puc)                mdb_in_buf <= 16'h0000;
369
  else if (mdb_in_buf_en) mdb_in_buf <= mdb_in_bw;
370
 
371
assign mdb_in_val = mdb_in_buf_valid ? mdb_in_buf : mdb_in_bw;
372
 
373
 
374 34 olivier.gi
endmodule // omsp_execution_unit
375 2 olivier.gi
 
376 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
377
`else
378 33 olivier.gi
`include "openMSP430_undefines.v"
379 103 olivier.gi
`endif

powered by: WebSVN 2.1.0

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