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

Subversion Repositories openmsp430

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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