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

Subversion Repositories openmsp430

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

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

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

powered by: WebSVN 2.1.0

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