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 80

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

powered by: WebSVN 2.1.0

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