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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [rtl/] [verilog/] [openmsp430/] [omsp_execution_unit.v] - Blame information for rev 128

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

Line No. Rev Author Line
1 80 olivier.gi
//----------------------------------------------------------------------------
2 128 olivier.gi
// Copyright (C) 2009 , Olivier Girard
3 80 olivier.gi
//
4 128 olivier.gi
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions
6
// are met:
7
//     * Redistributions of source code must retain the above copyright
8
//       notice, this list of conditions and the following disclaimer.
9
//     * Redistributions in binary form must reproduce the above copyright
10
//       notice, this list of conditions and the following disclaimer in the
11
//       documentation and/or other materials provided with the distribution.
12
//     * Neither the name of the authors nor the names of its contributors
13
//       may be used to endorse or promote products derived from this software
14
//       without specific prior written permission.
15 80 olivier.gi
//
16 128 olivier.gi
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26
// THE POSSIBILITY OF SUCH DAMAGE
27 80 olivier.gi
//
28
//----------------------------------------------------------------------------
29
//
30
// *File Name: omsp_execution_unit.v
31
// 
32
// *Module Description:
33
//                       openMSP430 Execution unit
34
//
35
// *Author(s):
36
//              - Olivier Girard,    olgirard@gmail.com
37
//
38
//----------------------------------------------------------------------------
39 128 olivier.gi
// $Rev: 117 $
40 80 olivier.gi
// $LastChangedBy: olivier.girard $
41 128 olivier.gi
// $LastChangedDate: 2011-06-23 21:30:51 +0200 (Thu, 23 Jun 2011) $
42 80 olivier.gi
//----------------------------------------------------------------------------
43 104 olivier.gi
`ifdef OMSP_NO_INCLUDE
44
`else
45 80 olivier.gi
`include "openMSP430_defines.v"
46 104 olivier.gi
`endif
47 80 olivier.gi
 
48
module  omsp_execution_unit (
49
 
50
// OUTPUTs
51
    cpuoff,                        // Turns off the CPU
52
    dbg_reg_din,                   // Debug unit CPU register data input
53
    gie,                           // General interrupt enable
54
    mab,                           // Memory address bus
55
    mb_en,                         // Memory bus enable
56
    mb_wr,                         // Memory bus write transfer
57
    mdb_out,                       // Memory data bus output
58
    oscoff,                        // Turns off LFXT1 clock input
59
    pc_sw,                         // Program counter software value
60
    pc_sw_wr,                      // Program counter software write
61
    scg1,                          // System clock generator 1. Turns off the SMCLK
62
 
63
// INPUTs
64
    dbg_halt_st,                   // Halt/Run status from CPU
65
    dbg_mem_dout,                  // Debug unit data output
66
    dbg_reg_wr,                    // Debug unit CPU register write
67
    e_state,                       // Execution state
68
    exec_done,                     // Execution completed
69
    inst_ad,                       // Decoded Inst: destination addressing mode
70
    inst_as,                       // Decoded Inst: source addressing mode
71
    inst_alu,                      // ALU control signals
72
    inst_bw,                       // Decoded Inst: byte width
73
    inst_dest,                     // Decoded Inst: destination (one hot)
74
    inst_dext,                     // Decoded Inst: destination extended instruction word
75
    inst_irq_rst,                  // Decoded Inst: reset interrupt
76
    inst_jmp,                      // Decoded Inst: Conditional jump
77 105 olivier.gi
    inst_mov,                      // Decoded Inst: mov instruction
78 80 olivier.gi
    inst_sext,                     // Decoded Inst: source extended instruction word
79
    inst_so,                       // Decoded Inst: Single-operand arithmetic
80
    inst_src,                      // Decoded Inst: source (one hot)
81
    inst_type,                     // Decoded Instruction type
82
    mclk,                          // Main system clock
83
    mdb_in,                        // Memory data bus input
84
    pc,                            // Program counter
85
    pc_nxt,                        // Next PC value (for CALL & IRQ)
86 111 olivier.gi
    puc_rst                        // Main system reset
87 80 olivier.gi
);
88
 
89
// OUTPUTs
90
//=========
91
output              cpuoff;        // Turns off the CPU
92
output       [15:0] dbg_reg_din;   // Debug unit CPU register data input
93
output              gie;           // General interrupt enable
94
output       [15:0] mab;           // Memory address bus
95
output              mb_en;         // Memory bus enable
96
output        [1:0] mb_wr;         // Memory bus write transfer
97
output       [15:0] mdb_out;       // Memory data bus output
98
output              oscoff;        // Turns off LFXT1 clock input
99
output       [15:0] pc_sw;         // Program counter software value
100
output              pc_sw_wr;      // Program counter software write
101
output              scg1;          // System clock generator 1. Turns off the SMCLK
102
 
103
// INPUTs
104
//=========
105
input               dbg_halt_st;   // Halt/Run status from CPU
106
input        [15:0] dbg_mem_dout;  // Debug unit data output
107
input               dbg_reg_wr;    // Debug unit CPU register write
108
input         [3:0] e_state;       // Execution state
109
input               exec_done;     // Execution completed
110
input         [7:0] inst_ad;       // Decoded Inst: destination addressing mode
111
input         [7:0] inst_as;       // Decoded Inst: source addressing mode
112
input        [11:0] inst_alu;      // ALU control signals
113
input               inst_bw;       // Decoded Inst: byte width
114
input        [15:0] inst_dest;     // Decoded Inst: destination (one hot)
115
input        [15:0] inst_dext;     // Decoded Inst: destination extended instruction word
116
input               inst_irq_rst;  // Decoded Inst: reset interrupt
117
input         [7:0] inst_jmp;      // Decoded Inst: Conditional jump
118 105 olivier.gi
input               inst_mov;      // Decoded Inst: mov instruction
119 80 olivier.gi
input        [15:0] inst_sext;     // Decoded Inst: source extended instruction word
120
input         [7:0] inst_so;       // Decoded Inst: Single-operand arithmetic
121
input        [15:0] inst_src;      // Decoded Inst: source (one hot)
122
input         [2:0] inst_type;     // Decoded Instruction type
123
input               mclk;          // Main system clock
124
input        [15:0] mdb_in;        // Memory data bus input
125
input        [15:0] pc;            // Program counter
126
input        [15:0] pc_nxt;        // Next PC value (for CALL & IRQ)
127 111 olivier.gi
input               puc_rst;       // Main system reset
128 80 olivier.gi
 
129
 
130
//=============================================================================
131
// 1)  INTERNAL WIRES/REGISTERS/PARAMETERS DECLARATION
132
//=============================================================================
133
 
134
wire         [15:0] alu_out;
135
wire         [15:0] alu_out_add;
136
wire          [3:0] alu_stat;
137
wire          [3:0] alu_stat_wr;
138
wire         [15:0] op_dst;
139
wire         [15:0] op_src;
140
wire         [15:0] reg_dest;
141
wire         [15:0] reg_src;
142
wire         [15:0] mdb_in_bw;
143
wire         [15:0] mdb_in_val;
144
wire          [3:0] status;
145
 
146
 
147
//=============================================================================
148
// 2)  REGISTER FILE
149
//=============================================================================
150
 
151
wire reg_dest_wr  = ((e_state==`E_EXEC) & (
152
                     (inst_type[`INST_TO] & inst_ad[`DIR] & ~inst_alu[`EXEC_NO_WR])  |
153
                     (inst_type[`INST_SO] & inst_as[`DIR] & ~(inst_so[`PUSH] | inst_so[`CALL] | inst_so[`RETI])) |
154
                      inst_type[`INST_JMP])) | dbg_reg_wr;
155
 
156
wire reg_sp_wr    = (((e_state==`E_IRQ_1) | (e_state==`E_IRQ_3)) & ~inst_irq_rst) |
157 128 olivier.gi
                     ((e_state==`E_DST_RD) & ((inst_so[`PUSH] | inst_so[`CALL]) &  ~inst_as[`IDX] & ~((inst_as[`INDIR] | inst_as[`INDIR_I]) & inst_src[1]))) |
158
                     ((e_state==`E_SRC_AD) & ((inst_so[`PUSH] | inst_so[`CALL]) &  inst_as[`IDX])) |
159
                     ((e_state==`E_SRC_RD) & ((inst_so[`PUSH] | inst_so[`CALL]) &  ((inst_as[`INDIR] | inst_as[`INDIR_I]) & inst_src[1])));
160 80 olivier.gi
 
161
wire reg_sr_wr    =  (e_state==`E_DST_RD) & inst_so[`RETI];
162
 
163
wire reg_sr_clr   =  (e_state==`E_IRQ_2);
164
 
165
wire reg_pc_call  = ((e_state==`E_EXEC)   & inst_so[`CALL]) |
166
                    ((e_state==`E_DST_WR) & inst_so[`RETI]);
167
 
168
wire reg_incr     =  (exec_done          & inst_as[`INDIR_I]) |
169
                    ((e_state==`E_SRC_RD) & inst_so[`RETI])    |
170
                    ((e_state==`E_EXEC)   & inst_so[`RETI]);
171
 
172
assign dbg_reg_din = reg_dest;
173
 
174
 
175
omsp_register_file register_file_0 (
176
 
177
// OUTPUTs
178
    .cpuoff       (cpuoff),       // Turns off the CPU
179
    .gie          (gie),          // General interrupt enable
180
    .oscoff       (oscoff),       // Turns off LFXT1 clock input
181
    .pc_sw        (pc_sw),        // Program counter software value
182
    .pc_sw_wr     (pc_sw_wr),     // Program counter software write
183
    .reg_dest     (reg_dest),     // Selected register destination content
184
    .reg_src      (reg_src),      // Selected register source content
185
    .scg1         (scg1),         // System clock generator 1. Turns off the SMCLK
186
    .status       (status),       // R2 Status {V,N,Z,C}
187
 
188
// INPUTs
189
    .alu_stat     (alu_stat),     // ALU Status {V,N,Z,C}
190
    .alu_stat_wr  (alu_stat_wr),  // ALU Status write {V,N,Z,C}
191
    .inst_bw      (inst_bw),      // Decoded Inst: byte width
192
    .inst_dest    (inst_dest),    // Register destination selection
193
    .inst_src     (inst_src),     // Register source selection
194
    .mclk         (mclk),         // Main system clock
195
    .pc           (pc),           // Program counter
196 111 olivier.gi
    .puc_rst      (puc_rst),      // Main system reset
197 80 olivier.gi
    .reg_dest_val (alu_out),      // Selected register destination value
198
    .reg_dest_wr  (reg_dest_wr),  // Write selected register destination
199
    .reg_pc_call  (reg_pc_call),  // Trigger PC update for a CALL instruction
200
    .reg_sp_val   (alu_out_add),  // Stack Pointer next value
201
    .reg_sp_wr    (reg_sp_wr),    // Stack Pointer write
202
    .reg_sr_clr   (reg_sr_clr),   // Status register clear for interrupts
203
    .reg_sr_wr    (reg_sr_wr),    // Status Register update for RETI instruction
204
    .reg_incr     (reg_incr)      // Increment source register
205
);
206
 
207
 
208
//=============================================================================
209
// 3)  SOURCE OPERAND MUXING
210
//=============================================================================
211
// inst_as[`DIR]    : Register direct.   -> Source is in register
212
// inst_as[`IDX]    : Register indexed.  -> Source is in memory, address is register+offset
213
// inst_as[`INDIR]  : Register indirect.
214
// inst_as[`INDIR_I]: Register indirect autoincrement.
215
// inst_as[`SYMB]   : Symbolic (operand is in memory at address PC+x).
216
// inst_as[`IMM]    : Immediate (operand is next word in the instruction stream).
217
// inst_as[`ABS]    : Absolute (operand is in memory at address x).
218
// inst_as[`CONST]  : Constant.
219
 
220
wire src_reg_src_sel    =  (e_state==`E_IRQ_0)                    |
221
                           (e_state==`E_IRQ_2)                    |
222
                          ((e_state==`E_SRC_RD) & ~inst_as[`ABS]) |
223
                          ((e_state==`E_SRC_WR) & ~inst_as[`ABS]) |
224
                          ((e_state==`E_EXEC)   &  inst_as[`DIR] & ~inst_type[`INST_JMP]);
225
 
226
wire src_reg_dest_sel   =  (e_state==`E_IRQ_1)                    |
227
                           (e_state==`E_IRQ_3)                    |
228 104 olivier.gi
                          ((e_state==`E_DST_RD) & (inst_so[`PUSH] | inst_so[`CALL])) |
229 128 olivier.gi
                          ((e_state==`E_SRC_AD) & (inst_so[`PUSH] | inst_so[`CALL]) & inst_as[`IDX]);
230 80 olivier.gi
 
231
wire src_mdb_in_val_sel = ((e_state==`E_DST_RD) &  inst_so[`RETI])                     |
232
                          ((e_state==`E_EXEC)   & (inst_as[`INDIR] | inst_as[`INDIR_I] |
233
                                                   inst_as[`IDX]   | inst_as[`SYMB]    |
234
                                                   inst_as[`ABS]));
235
 
236
wire src_inst_dext_sel =  ((e_state==`E_DST_RD) & ~(inst_so[`PUSH] | inst_so[`CALL])) |
237
                          ((e_state==`E_DST_WR) & ~(inst_so[`PUSH] | inst_so[`CALL]   |
238
                                                    inst_so[`RETI]));
239
 
240
wire src_inst_sext_sel =  ((e_state==`E_EXEC)   &  (inst_type[`INST_JMP] | inst_as[`IMM] |
241
                                                    inst_as[`CONST]      | inst_so[`RETI]));
242
 
243
 
244
assign op_src = src_reg_src_sel     ?  reg_src    :
245
                src_reg_dest_sel    ?  reg_dest   :
246
                src_mdb_in_val_sel  ?  mdb_in_val :
247
                src_inst_dext_sel   ?  inst_dext  :
248
                src_inst_sext_sel   ?  inst_sext  : 16'h0000;
249
 
250
 
251
//=============================================================================
252
// 4)  DESTINATION OPERAND MUXING
253
//=============================================================================
254
// inst_ad[`DIR]    : Register direct.
255
// inst_ad[`IDX]    : Register indexed.
256
// inst_ad[`SYMB]   : Symbolic (operand is in memory at address PC+x).
257
// inst_ad[`ABS]    : Absolute (operand is in memory at address x).
258
 
259
 
260
wire dst_inst_sext_sel  = ((e_state==`E_SRC_RD) & (inst_as[`IDX] | inst_as[`SYMB] |
261
                                                   inst_as[`ABS]))                |
262
                          ((e_state==`E_SRC_WR) & (inst_as[`IDX] | inst_as[`SYMB] |
263
                                                   inst_as[`ABS]));
264
 
265
wire dst_mdb_in_bw_sel  = ((e_state==`E_DST_WR) &   inst_so[`RETI]) |
266
                          ((e_state==`E_EXEC)   & ~(inst_ad[`DIR] | inst_type[`INST_JMP] |
267
                                                    inst_type[`INST_SO]) & ~inst_so[`RETI]);
268
 
269
wire dst_fffe_sel       =  (e_state==`E_IRQ_0)  |
270
                           (e_state==`E_IRQ_1)  |
271
                           (e_state==`E_IRQ_3)  |
272 104 olivier.gi
                          ((e_state==`E_DST_RD) & (inst_so[`PUSH] | inst_so[`CALL]) & ~inst_so[`RETI]) |
273 128 olivier.gi
                          ((e_state==`E_SRC_AD) & (inst_so[`PUSH] | inst_so[`CALL]) & inst_as[`IDX]) |
274
                          ((e_state==`E_SRC_RD) & (inst_so[`PUSH] | inst_so[`CALL]) & (inst_as[`INDIR] | inst_as[`INDIR_I]) & inst_src[1]);
275 80 olivier.gi
 
276
wire dst_reg_dest_sel   = ((e_state==`E_DST_RD) & ~(inst_so[`PUSH] | inst_so[`CALL] | inst_ad[`ABS] | inst_so[`RETI])) |
277
                          ((e_state==`E_DST_WR) &  ~inst_ad[`ABS]) |
278
                          ((e_state==`E_EXEC)   &  (inst_ad[`DIR] | inst_type[`INST_JMP] |
279
                                                    inst_type[`INST_SO]) & ~inst_so[`RETI]);
280
 
281
 
282
assign op_dst = dbg_halt_st        ? dbg_mem_dout  :
283
                dst_inst_sext_sel  ? inst_sext     :
284
                dst_mdb_in_bw_sel  ? mdb_in_bw     :
285
                dst_reg_dest_sel   ? reg_dest      :
286
                dst_fffe_sel       ? 16'hfffe      : 16'h0000;
287
 
288
 
289
//=============================================================================
290
// 5)  ALU
291
//=============================================================================
292
 
293
wire exec_cycle = (e_state==`E_EXEC);
294
 
295
omsp_alu alu_0 (
296
 
297
// OUTPUTs
298
    .alu_out      (alu_out),      // ALU output value
299
    .alu_out_add  (alu_out_add),  // ALU adder output value
300
    .alu_stat     (alu_stat),     // ALU Status {V,N,Z,C}
301
    .alu_stat_wr  (alu_stat_wr),  // ALU Status write {V,N,Z,C}
302
 
303
// INPUTs
304
    .dbg_halt_st  (dbg_halt_st),  // Halt/Run status from CPU
305
    .exec_cycle   (exec_cycle),   // Instruction execution cycle
306
    .inst_alu     (inst_alu),     // ALU control signals
307
    .inst_bw      (inst_bw),      // Decoded Inst: byte width
308
    .inst_jmp     (inst_jmp),     // Decoded Inst: Conditional jump
309
    .inst_so      (inst_so),      // Single-operand arithmetic
310
    .op_dst       (op_dst),       // Destination operand
311
    .op_src       (op_src),       // Source operand
312
    .status       (status)        // R2 Status {V,N,Z,C}
313
);
314
 
315
 
316
//=============================================================================
317
// 6)  MEMORY INTERFACE
318
//=============================================================================
319
 
320
// Detect memory read/write access
321 105 olivier.gi
assign      mb_en     = ((e_state==`E_IRQ_1)  & ~inst_irq_rst)        |
322
                        ((e_state==`E_IRQ_3)  & ~inst_irq_rst)        |
323
                        ((e_state==`E_SRC_RD) & ~inst_as[`IMM])       |
324
                         (e_state==`E_SRC_WR)                         |
325
                        ((e_state==`E_EXEC)   &  inst_so[`RETI])      |
326
                        ((e_state==`E_DST_RD) & ~inst_type[`INST_SO]
327
                                              & ~inst_mov)            |
328 80 olivier.gi
                         (e_state==`E_DST_WR);
329
 
330
wire  [1:0] mb_wr_msk =  inst_alu[`EXEC_NO_WR]  ? 2'b00 :
331
                        ~inst_bw                ? 2'b11 :
332
                         alu_out_add[0]         ? 2'b10 : 2'b01;
333
assign      mb_wr     = ({2{(e_state==`E_IRQ_1)}}  |
334
                         {2{(e_state==`E_IRQ_3)}}  |
335
                         {2{(e_state==`E_DST_WR)}} |
336
                         {2{(e_state==`E_SRC_WR)}}) & mb_wr_msk;
337
 
338
// Memory address bus
339
assign      mab       = alu_out_add[15:0];
340
 
341
// Memory data bus output
342
reg  [15:0] mdb_out_nxt;
343 111 olivier.gi
always @(posedge mclk or posedge puc_rst)
344
  if (puc_rst)                                        mdb_out_nxt <= 16'h0000;
345 80 olivier.gi
  else if (e_state==`E_DST_RD)                        mdb_out_nxt <= pc_nxt;
346
  else if ((e_state==`E_EXEC & ~inst_so[`CALL]) |
347
           (e_state==`E_IRQ_0) | (e_state==`E_IRQ_2)) mdb_out_nxt <= alu_out;
348
 
349
assign      mdb_out = inst_bw ? {2{mdb_out_nxt[7:0]}} : mdb_out_nxt;
350
 
351
// Format memory data bus input depending on BW
352
reg        mab_lsb;
353 111 olivier.gi
always @(posedge mclk or posedge puc_rst)
354
  if (puc_rst)    mab_lsb <= 1'b0;
355 80 olivier.gi
  else if (mb_en) mab_lsb <= alu_out_add[0];
356
 
357
assign mdb_in_bw  = ~inst_bw ? mdb_in :
358
                     mab_lsb ? {2{mdb_in[15:8]}} : mdb_in;
359
 
360
// Memory data bus input buffer (buffer after a source read)
361
reg         mdb_in_buf_en;
362 111 olivier.gi
always @(posedge mclk or posedge puc_rst)
363
  if (puc_rst)  mdb_in_buf_en <= 1'b0;
364
  else          mdb_in_buf_en <= (e_state==`E_SRC_RD);
365 80 olivier.gi
 
366
reg         mdb_in_buf_valid;
367 111 olivier.gi
always @(posedge mclk or posedge puc_rst)
368
  if (puc_rst)               mdb_in_buf_valid <= 1'b0;
369 80 olivier.gi
  else if (e_state==`E_EXEC) mdb_in_buf_valid <= 1'b0;
370
  else if (mdb_in_buf_en)    mdb_in_buf_valid <= 1'b1;
371
 
372
reg  [15:0] mdb_in_buf;
373 111 olivier.gi
always @(posedge mclk or posedge puc_rst)
374
  if (puc_rst)            mdb_in_buf <= 16'h0000;
375 80 olivier.gi
  else if (mdb_in_buf_en) mdb_in_buf <= mdb_in_bw;
376
 
377
assign mdb_in_val = mdb_in_buf_valid ? mdb_in_buf : mdb_in_bw;
378
 
379
 
380
endmodule // omsp_execution_unit
381
 
382 104 olivier.gi
`ifdef OMSP_NO_INCLUDE
383
`else
384 80 olivier.gi
`include "openMSP430_undefines.v"
385 104 olivier.gi
`endif

powered by: WebSVN 2.1.0

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