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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [actel_m1a3pl_dev_kit/] [bench/] [verilog/] [msp_debug.v] - Blame information for rev 94

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

Line No. Rev Author Line
1 80 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
// *File Name: msp_debug.v
26
// 
27
// *Module Description:
28
//                      MSP430 core debug utility signals
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34
// $Rev: 23 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2009-08-30 18:39:26 +0200 (Sun, 30 Aug 2009) $
37
//----------------------------------------------------------------------------
38
`include "timescale.v"
39
`include "openMSP430_defines.v"
40
 
41
module msp_debug (
42
 
43
// OUTPUTs
44
    e_state,                       // Execution state
45
    i_state,                       // Instruction fetch state
46
    inst_cycle,                    // Cycle number within current instruction
47
    inst_full,                     // Currently executed instruction (full version)
48
    inst_number,                   // Instruction number since last system reset
49
    inst_pc,                       // Instruction Program counter
50
    inst_short,                    // Currently executed instruction (short version)
51
 
52
// INPUTs
53
    mclk,                          // Main system clock
54
    puc                            // Main system reset
55
);
56
 
57
// OUTPUTs
58
//============
59
output  [8*32-1:0] e_state;        // Execution state
60
output  [8*32-1:0] i_state;        // Instruction fetch state
61
output      [31:0] inst_cycle;     // Cycle number within current instruction
62
output  [8*32-1:0] inst_full;      // Currently executed instruction (full version)
63
output      [31:0] inst_number;    // Instruction number since last system reset
64
output      [15:0] inst_pc;        // Instruction Program counter
65
output  [8*32-1:0] inst_short;     // Currently executed instruction (short version)
66
 
67
// INPUTs
68
//============
69
input              mclk;           // Main system clock
70
input              puc;            // Main system reset
71
 
72
 
73
//=============================================================================
74
// 1) ASCII FORMATING FUNCTIONS
75
//=============================================================================
76
 
77
// This function simply concatenates two strings together, ignorning the NULL
78
// at the end of string2.
79
// The specified number of space will be inserted between string1 and string2
80
function [64*8-1:0] myFormat;
81
 
82
  input [32*8-1:0] string1;
83
  input [32*8-1:0] string2;
84
  input      [3:0] space;
85
 
86
  integer i,j;
87
  begin
88
     myFormat = 0;
89 94 olivier.gi
`ifdef VXL                      // no +:
90
`else
91 80 olivier.gi
     j        = 0;
92
     for ( i=0; i < 32; i=i+1)                      // Copy string2
93
       begin
94
          myFormat[8*i +: 8] = string2[8*i +: 8];
95
          if ((string2[8*i +: 8] == 0) && (j == 0)) j=i;
96
       end
97
 
98
     for ( i=0; i < space; i=i+1)                   // Add spaces
99
       myFormat[8*(j+i) +: 8] = " ";
100
     j=j+space;
101
 
102
     for ( i=0; i < 32; i=i+1)                      // Copy string1
103
       myFormat[8*(j+i) +: 8] = string1[8*i +: 8];
104 94 olivier.gi
`endif
105 80 olivier.gi
  end
106
endfunction
107
 
108
 
109
//=============================================================================
110
// 2) CONNECTIONS TO MSP430 CORE INTERNALS
111
//=============================================================================
112
 
113 94 olivier.gi
wire  [2:0] i_state_bin = tb_openMSP430_fpga.dut.openMSP430_0.frontend_0.i_state;
114
wire  [3:0] e_state_bin = tb_openMSP430_fpga.dut.openMSP430_0.frontend_0.e_state;
115 80 olivier.gi
 
116 94 olivier.gi
wire        decode      = tb_openMSP430_fpga.dut.openMSP430_0.frontend_0.decode;
117
wire [15:0] ir          = tb_openMSP430_fpga.dut.openMSP430_0.frontend_0.ir;
118
wire        irq_detect  = tb_openMSP430_fpga.dut.openMSP430_0.frontend_0.irq_detect;
119
wire  [3:0] irq_num     = tb_openMSP430_fpga.dut.openMSP430_0.frontend_0.irq_num;
120
wire [15:0] pc          = tb_openMSP430_fpga.dut.openMSP430_0.frontend_0.pc;
121 80 olivier.gi
 
122
 
123
//=============================================================================
124
// 3) GENERATE DEBUG SIGNALS
125
//=============================================================================
126
 
127
// Instruction fetch state
128
//=========================
129
reg [8*32-1:0] i_state;
130
 
131
always @(i_state_bin)
132
    case(i_state_bin)
133
      3'h0    : i_state =  "IRQ_FETCH";
134
      3'h1    : i_state =  "IRQ_DONE";
135
      3'h2    : i_state =  "DEC";
136
      3'h3    : i_state =  "EXT1";
137
      3'h4    : i_state =  "EXT2";
138
      3'h5    : i_state =  "IDLE";
139
      default : i_state =  "XXXXX";
140
    endcase
141
 
142
 
143
// Execution state
144
//=========================
145
 
146
reg [8*32-1:0] e_state;
147
 
148
always @(e_state_bin)
149
    case(e_state_bin)
150
      4'h0    : e_state =  "IRQ_0";
151
      4'h1    : e_state =  "IRQ_1";
152
      4'h2    : e_state =  "IRQ_2";
153
      4'h3    : e_state =  "IRQ_3";
154
      4'h4    : e_state =  "IRQ_4";
155
      4'h5    : e_state =  "SRC_AD";
156
      4'h6    : e_state =  "SRC_RD";
157
      4'h7    : e_state =  "SRC_WR";
158
      4'h8    : e_state =  "DST_AD";
159
      4'h9    : e_state =  "DST_RD";
160
      4'hA    : e_state =  "DST_WR";
161
      4'hB    : e_state =  "EXEC";
162
      4'hC    : e_state =  "JUMP";
163
      4'hD    : e_state =  "IDLE";
164
      default : e_state =  "xxxx";
165
    endcase
166
 
167
 
168
// Count instruction number & cycles
169
//====================================
170
 
171
reg [31:0]  inst_number;
172
always @(posedge mclk or posedge puc)
173
  if (puc)         inst_number  <= 0;
174
  else if (decode) inst_number  <= inst_number+1;
175
 
176
reg [31:0]  inst_cycle;
177
always @(posedge mclk or posedge puc)
178
  if (puc)         inst_cycle <= 0;
179
  else if (decode) inst_cycle <= 0;
180
  else             inst_cycle <= inst_cycle+1;
181
 
182
 
183
// Decode instruction
184
//====================================
185
 
186
// Buffer opcode
187
reg [15:0]  opcode;
188
always @(posedge mclk or posedge puc)
189
  if (puc)         opcode  <= 0;
190
  else if (decode) opcode  <= ir;
191
 
192
// Interrupts
193
reg irq;
194
always @(posedge mclk or posedge puc)
195
  if (puc)         irq     <= 1'b1;
196
  else if (decode) irq     <= irq_detect;
197
 
198
// Instruction type
199
reg [8*32-1:0] inst_type;
200
always @(opcode or irq)
201
  if (irq)
202
    inst_type =  "IRQ";
203
  else
204
    case(opcode[15:13])
205
      3'b000  : inst_type =  "SIG-OP";
206
      3'b001  : inst_type =  "JUMP";
207
      default : inst_type =  "TWO-OP";
208
    endcase
209
 
210
 
211
// Instructions name
212
reg [8*32-1:0] inst_name;
213
always @(opcode or inst_type or irq_num)
214
  if (inst_type=="IRQ")
215
    case(irq_num[3:0])
216
      4'b0000        : inst_name =  "IRQ 0";
217
      4'b0001        : inst_name =  "IRQ 1";
218
      4'b0010        : inst_name =  "IRQ 2";
219
      4'b0011        : inst_name =  "IRQ 3";
220
      4'b0100        : inst_name =  "IRQ 4";
221
      4'b0101        : inst_name =  "IRQ 5";
222
      4'b0110        : inst_name =  "IRQ 6";
223
      4'b0111        : inst_name =  "IRQ 7";
224
      4'b1000        : inst_name =  "IRQ 8";
225
      4'b1001        : inst_name =  "IRQ 9";
226
      4'b1010        : inst_name =  "IRQ 10";
227
      4'b1011        : inst_name =  "IRQ 11";
228
      4'b1100        : inst_name =  "IRQ 12";
229
      4'b1101        : inst_name =  "IRQ 13";
230
      4'b1110        : inst_name =  "NMI";
231
      default        : inst_name =  "RESET";
232
    endcase
233
  else if (inst_type=="SIG-OP")
234
    case(opcode[15:7])
235
      9'b000100_000  : inst_name =  "RRC";
236
      9'b000100_001  : inst_name =  "SWPB";
237
      9'b000100_010  : inst_name =  "RRA";
238
      9'b000100_011  : inst_name =  "SXT";
239
      9'b000100_100  : inst_name =  "PUSH";
240
      9'b000100_101  : inst_name =  "CALL";
241
      9'b000100_110  : inst_name =  "RETI";
242
      default        : inst_name =  "xxxx";
243
    endcase
244
  else if (inst_type=="JUMP")
245
    case(opcode[15:10])
246
      6'b001_000     : inst_name =  "JNE";
247
      6'b001_001     : inst_name =  "JEQ";
248
      6'b001_010     : inst_name =  "JNC";
249
      6'b001_011     : inst_name =  "JC";
250
      6'b001_100     : inst_name =  "JN";
251
      6'b001_101     : inst_name =  "JGE";
252
      6'b001_110     : inst_name =  "JL";
253
      6'b001_111     : inst_name =  "JMP";
254
      default        : inst_name =  "xxxx";
255
    endcase
256
  else if (inst_type=="TWO-OP")
257
    case(opcode[15:12])
258
      4'b0100        : inst_name =  "MOV";
259
      4'b0101        : inst_name =  "ADD";
260
      4'b0110        : inst_name =  "ADDC";
261
      4'b0111        : inst_name =  "SUBC";
262
      4'b1000        : inst_name =  "SUB";
263
      4'b1001        : inst_name =  "CMP";
264
      4'b1010        : inst_name =  "DADD";
265
      4'b1011        : inst_name =  "BIT";
266
      4'b1100        : inst_name =  "BIC";
267
      4'b1101        : inst_name =  "BIS";
268
      4'b1110        : inst_name =  "XOR";
269
      4'b1111        : inst_name =  "AND";
270
      default        : inst_name =  "xxxx";
271
    endcase
272
 
273
// Instructions byte/word mode
274
reg [8*32-1:0] inst_bw;
275
always @(opcode or inst_type)
276
  if (inst_type=="IRQ")
277
    inst_bw =  "";
278
  else if (inst_type=="SIG-OP")
279
    inst_bw =  opcode[6] ? ".B" : "";
280
  else if (inst_type=="JUMP")
281
    inst_bw =  "";
282
  else if (inst_type=="TWO-OP")
283
    inst_bw =  opcode[6] ? ".B" : "";
284
 
285
// Source register
286
reg [8*32-1:0] inst_src;
287
wire     [3:0] src_reg = (inst_type=="SIG-OP") ? opcode[3:0] : opcode[11:8];
288
 
289
always @(src_reg or inst_type)
290
  if (inst_type=="IRQ")
291
    inst_src =  "";
292
  else if (inst_type=="JUMP")
293
    inst_src =  "";
294
  else if ((inst_type=="SIG-OP") || (inst_type=="TWO-OP"))
295
    case(src_reg)
296
      4'b0000 : inst_src =  "r0";
297
      4'b0001 : inst_src =  "r1";
298
      4'b0010 : inst_src =  "r2";
299
      4'b0011 : inst_src =  "r3";
300
      4'b0100 : inst_src =  "r4";
301
      4'b0101 : inst_src =  "r5";
302
      4'b0110 : inst_src =  "r6";
303
      4'b0111 : inst_src =  "r7";
304
      4'b1000 : inst_src =  "r8";
305
      4'b1001 : inst_src =  "r9";
306
      4'b1010 : inst_src =  "r10";
307
      4'b1011 : inst_src =  "r11";
308
      4'b1100 : inst_src =  "r12";
309
      4'b1101 : inst_src =  "r13";
310
      4'b1110 : inst_src =  "r14";
311
      default : inst_src =  "r15";
312
    endcase
313
 
314
// Destination register
315
reg [8*32-1:0] inst_dst;
316
always @(opcode or inst_type)
317
  if (inst_type=="IRQ")
318
    inst_dst =  "";
319
  else if (inst_type=="SIG-OP")
320
    inst_dst =  "";
321
  else if (inst_type=="JUMP")
322
    inst_dst =  "";
323
  else if (inst_type=="TWO-OP")
324
    case(opcode[3:0])
325
      4'b0000 : inst_dst =  "r0";
326
      4'b0001 : inst_dst =  "r1";
327
      4'b0010 : inst_dst =  "r2";
328
      4'b0011 : inst_dst =  "r3";
329
      4'b0100 : inst_dst =  "r4";
330
      4'b0101 : inst_dst =  "r5";
331
      4'b0110 : inst_dst =  "r6";
332
      4'b0111 : inst_dst =  "r7";
333
      4'b1000 : inst_dst =  "r8";
334
      4'b1001 : inst_dst =  "r9";
335
      4'b1010 : inst_dst =  "r10";
336
      4'b1011 : inst_dst =  "r11";
337
      4'b1100 : inst_dst =  "r12";
338
      4'b1101 : inst_dst =  "r13";
339
      4'b1110 : inst_dst =  "r14";
340
      default : inst_dst =  "r15";
341
    endcase
342
 
343
// Source Addressing mode
344
reg [8*32-1:0] inst_as;
345
always @(inst_type or src_reg or opcode or inst_src)
346
  begin
347
  if (inst_type=="IRQ")
348
    inst_as =  "";
349
  else if (inst_type=="JUMP")
350
    inst_as =  "";
351
  else if (src_reg==4'h3) // Addressing mode using R3
352
    case (opcode[5:4])
353
      2'b11  : inst_as =  "#-1";
354
      2'b10  : inst_as =  "#2";
355
      2'b01  : inst_as =  "#1";
356
      default: inst_as =  "#0";
357
    endcase
358
  else if (src_reg==4'h2) // Addressing mode using R2
359
    case (opcode[5:4])
360
      2'b11  : inst_as =  "#8";
361
      2'b10  : inst_as =  "#4";
362
      2'b01  : inst_as =  "&EDE";
363
      default: inst_as =  inst_src;
364
    endcase
365
  else if (src_reg==4'h0) // Addressing mode using R0
366
    case (opcode[5:4])
367
      2'b11  : inst_as =  "#N";
368
      2'b10  : inst_as =  myFormat("@", inst_src, 0);
369
      2'b01  : inst_as =  "EDE";
370
      default: inst_as =  inst_src;
371
    endcase
372
  else                    // General Addressing mode
373
    case (opcode[5:4])
374
      2'b11  : begin
375
               inst_as =  myFormat("@", inst_src, 0);
376
               inst_as =  myFormat(inst_as, "+", 0);
377
               end
378
      2'b10  : inst_as =  myFormat("@", inst_src, 0);
379
      2'b01  : begin
380
               inst_as =  myFormat("x(", inst_src, 0);
381
               inst_as =  myFormat(inst_as, ")", 0);
382
               end
383
      default: inst_as =  inst_src;
384
    endcase
385
  end
386
 
387
// Destination Addressing mode
388
reg [8*32-1:0] inst_ad;
389
always @(opcode or inst_type or inst_dst)
390
  begin
391
     if (inst_type!="TWO-OP")
392
       inst_ad =  "";
393
     else if (opcode[3:0]==4'h2)   // Addressing mode using R2
394
       case (opcode[7])
395
         1'b1   : inst_ad =  "&EDE";
396
         default: inst_ad =  inst_dst;
397
       endcase
398
     else if (opcode[3:0]==4'h0)   // Addressing mode using R0
399
       case (opcode[7])
400
         2'b1   : inst_ad =  "EDE";
401
         default: inst_ad =  inst_dst;
402
       endcase
403
     else                          // General Addressing mode
404
       case (opcode[7])
405
         2'b1   : begin
406
                  inst_ad =  myFormat("x(", inst_dst, 0);
407
                  inst_ad =  myFormat(inst_ad, ")", 0);
408
                  end
409
         default: inst_ad =  inst_dst;
410
       endcase
411
  end
412
 
413
 
414
// Currently executed instruction
415
//================================
416
 
417 94 olivier.gi
wire [8*32-1:0] inst_short = inst_name;
418 80 olivier.gi
 
419 94 olivier.gi
reg  [8*32-1:0] inst_full;
420 80 olivier.gi
always @(inst_type or inst_name or inst_bw or inst_as or inst_ad)
421
  begin
422
     inst_full   = myFormat(inst_name, inst_bw, 0);
423
     inst_full   = myFormat(inst_full, inst_as, 1);
424
     if (inst_type=="TWO-OP")
425
       inst_full = myFormat(inst_full, ",",     0);
426
     inst_full   = myFormat(inst_full, inst_ad, 1);
427
     if (opcode==16'h4303)
428
       inst_full = "NOP";
429
     if (opcode==`DBG_SWBRK_OP)
430
       inst_full = "SBREAK";
431
 
432
  end
433
 
434
 
435
// Instruction program counter
436
//================================
437
 
438
reg  [15:0] inst_pc;
439
always @(posedge mclk or posedge puc)
440
  if (puc)         inst_pc  <=  16'h0000;
441
  else if (decode) inst_pc  <=  pc;
442
 
443
 
444
endmodule // msp_debug
445
 

powered by: WebSVN 2.1.0

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