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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [fpga/] [xilinx_diligent_s3board/] [rtl/] [verilog/] [openmsp430/] [omsp_dbg.v] - Blame information for rev 91

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

Line No. Rev Author Line
1 2 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 34 olivier.gi
// *File Name: omsp_dbg.v
26 2 olivier.gi
// 
27
// *Module Description:
28
//                       Debug interface
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 17 olivier.gi
// $Rev: 85 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2011-01-28 22:05:37 +0100 (Fri, 28 Jan 2011) $
37
//----------------------------------------------------------------------------
38 23 olivier.gi
`include "timescale.v"
39
`include "openMSP430_defines.v"
40 2 olivier.gi
 
41 34 olivier.gi
module  omsp_dbg (
42 2 olivier.gi
 
43
// OUTPUTs
44
    dbg_freeze,                     // Freeze peripherals
45
    dbg_halt_cmd,                   // Halt CPU command
46
    dbg_mem_addr,                   // Debug address for rd/wr access
47
    dbg_mem_dout,                   // Debug unit data output
48
    dbg_mem_en,                     // Debug unit memory enable
49
    dbg_mem_wr,                     // Debug unit memory write
50
    dbg_reg_wr,                     // Debug unit CPU register write
51
    dbg_reset,                      // Reset CPU from debug interface
52
    dbg_uart_txd,                   // Debug interface: UART TXD
53
 
54
// INPUTs
55
    dbg_halt_st,                    // Halt/Run status from CPU
56
    dbg_mem_din,                    // Debug unit Memory data input
57
    dbg_reg_din,                    // Debug unit CPU register data input
58
    dbg_uart_rxd,                   // Debug interface: UART RXD
59 54 olivier.gi
    decode_noirq,                   // Frontend decode instruction
60 2 olivier.gi
    eu_mab,                         // Execution-Unit Memory address bus
61
    eu_mb_en,                       // Execution-Unit Memory bus enable
62
    eu_mb_wr,                       // Execution-Unit Memory bus write transfer
63
    eu_mdb_in,                      // Memory data bus input
64
    eu_mdb_out,                     // Memory data bus output
65
    exec_done,                      // Execution completed
66
    fe_mb_en,                       // Frontend Memory bus enable
67
    fe_mdb_in,                      // Frontend Memory data bus input
68
    mclk,                           // Main system clock
69
    pc,                             // Program counter
70
    por,                            // Power on reset
71
    puc                             // Main system reset
72
);
73
 
74
// OUTPUTs
75
//=========
76
output              dbg_freeze;     // Freeze peripherals
77
output              dbg_halt_cmd;   // Halt CPU command
78
output       [15:0] dbg_mem_addr;   // Debug address for rd/wr access
79
output       [15:0] dbg_mem_dout;   // Debug unit data output
80
output              dbg_mem_en;     // Debug unit memory enable
81
output        [1:0] dbg_mem_wr;     // Debug unit memory write
82
output              dbg_reg_wr;     // Debug unit CPU register write
83
output              dbg_reset;      // Reset CPU from debug interface
84
output              dbg_uart_txd;   // Debug interface: UART TXD
85
 
86
// INPUTs
87
//=========
88
input               dbg_halt_st;    // Halt/Run status from CPU
89
input        [15:0] dbg_mem_din;    // Debug unit Memory data input
90
input        [15:0] dbg_reg_din;    // Debug unit CPU register data input
91
input               dbg_uart_rxd;   // Debug interface: UART RXD
92 54 olivier.gi
input               decode_noirq;   // Frontend decode instruction
93 2 olivier.gi
input        [15:0] eu_mab;         // Execution-Unit Memory address bus
94
input               eu_mb_en;       // Execution-Unit Memory bus enable
95
input         [1:0] eu_mb_wr;       // Execution-Unit Memory bus write transfer
96
input        [15:0] eu_mdb_in;      // Memory data bus input
97
input        [15:0] eu_mdb_out;     // Memory data bus output
98
input               exec_done;      // Execution completed
99
input               fe_mb_en;       // Frontend Memory bus enable
100
input        [15:0] fe_mdb_in;      // Frontend Memory data bus input
101
input               mclk;           // Main system clock
102
input        [15:0] pc;             // Program counter
103
input               por;            // Power on reset
104
input               puc;            // Main system reset
105
 
106
 
107
//=============================================================================
108
// 1)  WIRE & PARAMETER DECLARATION
109
//=============================================================================
110
 
111
// Diverse wires and registers
112
wire  [5:0] dbg_addr;
113
wire [15:0] dbg_din;
114
wire        dbg_wr;
115
reg         mem_burst;
116
wire        dbg_reg_rd;
117
wire        dbg_mem_rd;
118
reg         dbg_mem_rd_dly;
119
wire        dbg_swbrk;
120
wire        dbg_rd;
121
reg         dbg_rd_rdy;
122
wire        mem_burst_rd;
123
wire        mem_burst_wr;
124
wire        brk0_halt;
125
wire        brk0_pnd;
126
wire [15:0] brk0_dout;
127
wire        brk1_halt;
128
wire        brk1_pnd;
129
wire [15:0] brk1_dout;
130
wire        brk2_halt;
131
wire        brk2_pnd;
132
wire [15:0] brk2_dout;
133
wire        brk3_halt;
134
wire        brk3_pnd;
135
wire [15:0] brk3_dout;
136
 
137
// Register addresses
138
parameter           CPU_ID_LO    = 6'h00;
139
parameter           CPU_ID_HI    = 6'h01;
140
parameter           CPU_CTL      = 6'h02;
141
parameter           CPU_STAT     = 6'h03;
142
parameter           MEM_CTL      = 6'h04;
143
parameter           MEM_ADDR     = 6'h05;
144
parameter           MEM_DATA     = 6'h06;
145
parameter           MEM_CNT      = 6'h07;
146
`ifdef DBG_HWBRK_0
147
parameter           BRK0_CTL     = 6'h08;
148
parameter           BRK0_STAT    = 6'h09;
149
parameter           BRK0_ADDR0   = 6'h0A;
150
parameter           BRK0_ADDR1   = 6'h0B;
151
`endif
152
`ifdef DBG_HWBRK_1
153
parameter           BRK1_CTL     = 6'h0C;
154
parameter           BRK1_STAT    = 6'h0D;
155
parameter           BRK1_ADDR0   = 6'h0E;
156
parameter           BRK1_ADDR1   = 6'h0F;
157
`endif
158
`ifdef DBG_HWBRK_2
159
parameter           BRK2_CTL     = 6'h10;
160
parameter           BRK2_STAT    = 6'h11;
161
parameter           BRK2_ADDR0   = 6'h12;
162
parameter           BRK2_ADDR1   = 6'h13;
163
`endif
164
`ifdef DBG_HWBRK_3
165
parameter           BRK3_CTL     = 6'h14;
166
parameter           BRK3_STAT    = 6'h15;
167
parameter           BRK3_ADDR0   = 6'h16;
168
parameter           BRK3_ADDR1   = 6'h17;
169
`endif
170
 
171
// Register one-hot decoder
172
parameter           CPU_ID_LO_D  = (64'h1 << CPU_ID_LO);
173
parameter           CPU_ID_HI_D  = (64'h1 << CPU_ID_HI);
174
parameter           CPU_CTL_D    = (64'h1 << CPU_CTL);
175
parameter           CPU_STAT_D   = (64'h1 << CPU_STAT);
176
parameter           MEM_CTL_D    = (64'h1 << MEM_CTL);
177
parameter           MEM_ADDR_D   = (64'h1 << MEM_ADDR);
178
parameter           MEM_DATA_D   = (64'h1 << MEM_DATA);
179
parameter           MEM_CNT_D    = (64'h1 << MEM_CNT);
180
`ifdef DBG_HWBRK_0
181
parameter           BRK0_CTL_D   = (64'h1 << BRK0_CTL);
182
parameter           BRK0_STAT_D  = (64'h1 << BRK0_STAT);
183
parameter           BRK0_ADDR0_D = (64'h1 << BRK0_ADDR0);
184
parameter           BRK0_ADDR1_D = (64'h1 << BRK0_ADDR1);
185
`endif
186
`ifdef DBG_HWBRK_1
187
parameter           BRK1_CTL_D   = (64'h1 << BRK1_CTL);
188
parameter           BRK1_STAT_D  = (64'h1 << BRK1_STAT);
189
parameter           BRK1_ADDR0_D = (64'h1 << BRK1_ADDR0);
190
parameter           BRK1_ADDR1_D = (64'h1 << BRK1_ADDR1);
191
`endif
192
`ifdef DBG_HWBRK_2
193
parameter           BRK2_CTL_D   = (64'h1 << BRK2_CTL);
194
parameter           BRK2_STAT_D  = (64'h1 << BRK2_STAT);
195
parameter           BRK2_ADDR0_D = (64'h1 << BRK2_ADDR0);
196
parameter           BRK2_ADDR1_D = (64'h1 << BRK2_ADDR1);
197
`endif
198
`ifdef DBG_HWBRK_3
199
parameter           BRK3_CTL_D   = (64'h1 << BRK3_CTL);
200
parameter           BRK3_STAT_D  = (64'h1 << BRK3_STAT);
201
parameter           BRK3_ADDR0_D = (64'h1 << BRK3_ADDR0);
202
parameter           BRK3_ADDR1_D = (64'h1 << BRK3_ADDR1);
203
`endif
204
 
205 84 olivier.gi
// PUC is localy used as a data.
206
reg  [1:0] puc_sync;
207
always @ (posedge mclk or posedge por)
208
  if (por) puc_sync <=  2'b11;
209
  else     puc_sync <=  {puc_sync[0] , puc};
210
wire       puc_s     =  puc_sync[1];
211
 
212
 
213 2 olivier.gi
//============================================================================
214
// 2)  REGISTER DECODER
215
//============================================================================
216
 
217
// Select Data register during a burst
218
wire  [5:0] dbg_addr_in = mem_burst ? MEM_DATA : dbg_addr;
219
 
220
// Register address decode
221
reg  [63:0]  reg_dec;
222
always @(dbg_addr_in)
223
  case (dbg_addr_in)
224
    CPU_ID_LO :  reg_dec  =  CPU_ID_LO_D;
225
    CPU_ID_HI :  reg_dec  =  CPU_ID_HI_D;
226
    CPU_CTL   :  reg_dec  =  CPU_CTL_D;
227
    CPU_STAT  :  reg_dec  =  CPU_STAT_D;
228
    MEM_CTL   :  reg_dec  =  MEM_CTL_D;
229
    MEM_ADDR  :  reg_dec  =  MEM_ADDR_D;
230
    MEM_DATA  :  reg_dec  =  MEM_DATA_D;
231
    MEM_CNT   :  reg_dec  =  MEM_CNT_D;
232
`ifdef DBG_HWBRK_0
233
    BRK0_CTL  :  reg_dec  =  BRK0_CTL_D;
234
    BRK0_STAT :  reg_dec  =  BRK0_STAT_D;
235
    BRK0_ADDR0:  reg_dec  =  BRK0_ADDR0_D;
236
    BRK0_ADDR1:  reg_dec  =  BRK0_ADDR1_D;
237
`endif
238
`ifdef DBG_HWBRK_1
239
    BRK1_CTL  :  reg_dec  =  BRK1_CTL_D;
240
    BRK1_STAT :  reg_dec  =  BRK1_STAT_D;
241
    BRK1_ADDR0:  reg_dec  =  BRK1_ADDR0_D;
242
    BRK1_ADDR1:  reg_dec  =  BRK1_ADDR1_D;
243
`endif
244
`ifdef DBG_HWBRK_2
245
    BRK2_CTL  :  reg_dec  =  BRK2_CTL_D;
246
    BRK2_STAT :  reg_dec  =  BRK2_STAT_D;
247
    BRK2_ADDR0:  reg_dec  =  BRK2_ADDR0_D;
248
    BRK2_ADDR1:  reg_dec  =  BRK2_ADDR1_D;
249
`endif
250
`ifdef DBG_HWBRK_3
251
    BRK3_CTL  :  reg_dec  =  BRK3_CTL_D;
252
    BRK3_STAT :  reg_dec  =  BRK3_STAT_D;
253
    BRK3_ADDR0:  reg_dec  =  BRK3_ADDR0_D;
254
    BRK3_ADDR1:  reg_dec  =  BRK3_ADDR1_D;
255
`endif
256
    default:     reg_dec  =  {64{1'b0}};
257
  endcase
258
 
259
// Read/Write probes
260
wire         reg_write =  dbg_wr;
261
wire         reg_read  =  1'b1;
262
 
263
// Read/Write vectors
264 85 olivier.gi
wire  [63:0] reg_wr    = reg_dec & {64{reg_write}};
265
wire  [63:0] reg_rd    = reg_dec & {64{reg_read}};
266 2 olivier.gi
 
267
 
268
//=============================================================================
269
// 3)  REGISTER: CORE INTERFACE
270
//=============================================================================
271
 
272
// CPU_ID Register
273
//-----------------   
274
 
275 74 olivier.gi
wire [15:0] cpu_id_pmem = `PMEM_SIZE;
276
wire [15:0] cpu_id_dmem = `DMEM_SIZE;
277
wire [31:0] cpu_id      = {cpu_id_pmem, cpu_id_dmem};
278 2 olivier.gi
 
279
 
280
// CPU_CTL Register
281
//-----------------------------------------------------------------------------
282
//       7         6          5          4           3        2     1    0
283
//   Reserved   CPU_RST  RST_BRK_EN  FRZ_BRK_EN  SW_BRK_EN  ISTEP  RUN  HALT
284
//-----------------------------------------------------------------------------
285
reg   [6:3] cpu_ctl;
286
 
287
wire        cpu_ctl_wr = reg_wr[CPU_CTL];
288
 
289
always @ (posedge mclk or posedge por)
290
  if (por)             cpu_ctl <=  4'h0;
291
  else if (cpu_ctl_wr) cpu_ctl <=  dbg_din[6:3];
292
 
293
wire  [7:0] cpu_ctl_full = {1'b0, cpu_ctl, 3'b000};
294
 
295
wire        halt_cpu = cpu_ctl_wr & dbg_din[`HALT]  & ~dbg_halt_st;
296
wire        run_cpu  = cpu_ctl_wr & dbg_din[`RUN]   &  dbg_halt_st;
297
wire        istep    = cpu_ctl_wr & dbg_din[`ISTEP] &  dbg_halt_st;
298
 
299
 
300
// CPU_STAT Register
301
//------------------------------------------------------------------------------------
302
//      7           6          5           4           3         2      1       0
303
// HWBRK3_PND  HWBRK2_PND  HWBRK1_PND  HWBRK0_PND  SWBRK_PND  PUC_PND  Res.  HALT_RUN
304
//------------------------------------------------------------------------------------
305
reg   [3:2] cpu_stat;
306
 
307
wire        cpu_stat_wr  = reg_wr[CPU_STAT];
308 84 olivier.gi
wire  [3:2] cpu_stat_set = {dbg_swbrk, puc_s};
309 2 olivier.gi
wire  [3:2] cpu_stat_clr = ~dbg_din[3:2];
310
 
311
always @ (posedge mclk or posedge por)
312
  if (por)              cpu_stat <=  2'b00;
313
  else if (cpu_stat_wr) cpu_stat <= ((cpu_stat & cpu_stat_clr) | cpu_stat_set);
314
  else                  cpu_stat <=  (cpu_stat                 | cpu_stat_set);
315
 
316
wire  [7:0] cpu_stat_full = {brk3_pnd, brk2_pnd, brk1_pnd, brk0_pnd,
317
                             cpu_stat, 1'b0, dbg_halt_st};
318
 
319
 
320
//=============================================================================
321
// 4)  REGISTER: MEMORY INTERFACE
322
//=============================================================================
323
 
324
// MEM_CTL Register
325
//-----------------------------------------------------------------------------
326
//       7     6     5     4          3        2         1       0
327
//            Reserved               B/W    MEM/REG    RD/WR   START
328
//
329
// START  :  -  0 : Do nothing.
330
//           -  1 : Initiate memory transfer.
331
//
332
// RD/WR  :  -  0 : Read access.
333
//           -  1 : Write access.
334
//
335
// MEM/REG:  -  0 : Memory access.
336
//           -  1 : CPU Register access.
337
//
338
// B/W    :  -  0 : 16 bit access.
339
//           -  1 :  8 bit access (not valid for CPU Registers).
340
//
341
//-----------------------------------------------------------------------------
342
reg   [3:1] mem_ctl;
343
 
344
wire        mem_ctl_wr = reg_wr[MEM_CTL];
345
 
346
always @ (posedge mclk or posedge por)
347
  if (por)             mem_ctl <=  3'h0;
348
  else if (mem_ctl_wr) mem_ctl <=  dbg_din[3:1];
349
 
350
wire  [7:0] mem_ctl_full  = {4'b0000, mem_ctl, 1'b0};
351
 
352
reg         mem_start;
353
always @ (posedge mclk or posedge por)
354
  if (por)  mem_start <=  1'b0;
355
  else      mem_start <=  mem_ctl_wr & dbg_din[0];
356
 
357
wire        mem_bw    = mem_ctl[3];
358
 
359
// MEM_DATA Register
360
//------------------   
361
reg  [15:0] mem_data;
362
reg  [15:0] mem_addr;
363
wire        mem_access;
364
 
365
wire        mem_data_wr = reg_wr[MEM_DATA];
366
 
367
wire [15:0] dbg_mem_din_bw = ~mem_bw      ? dbg_mem_din                :
368
                              mem_addr[0] ? {8'h00, dbg_mem_din[15:8]} :
369
                                            {8'h00, dbg_mem_din[7:0]};
370
 
371
always @ (posedge mclk or posedge por)
372
  if (por)                 mem_data <=  16'h0000;
373
  else if (mem_data_wr)    mem_data <=  dbg_din;
374
  else if (dbg_reg_rd)     mem_data <=  dbg_reg_din;
375
  else if (dbg_mem_rd_dly) mem_data <=  dbg_mem_din_bw;
376
 
377
 
378
// MEM_ADDR Register
379
//------------------   
380
reg  [15:0] mem_cnt;
381
 
382
wire        mem_addr_wr  = reg_wr[MEM_ADDR];
383
wire        dbg_mem_acc  = (|dbg_mem_wr | (dbg_rd_rdy & ~mem_ctl[2]));
384
wire        dbg_reg_acc  = ( dbg_reg_wr | (dbg_rd_rdy &  mem_ctl[2]));
385
 
386
wire [15:0] mem_addr_inc = (mem_cnt==16'h0000)         ? 16'h0000 :
387
                           (dbg_mem_acc & ~mem_bw)     ? 16'h0002 :
388
                           (dbg_mem_acc | dbg_reg_acc) ? 16'h0001 : 16'h0000;
389
 
390
always @ (posedge mclk or posedge por)
391
  if (por)              mem_addr <=  16'h0000;
392
  else if (mem_addr_wr) mem_addr <=  dbg_din;
393
  else                  mem_addr <=  mem_addr + mem_addr_inc;
394
 
395
// MEM_CNT Register
396
//------------------   
397
 
398
wire        mem_cnt_wr  = reg_wr[MEM_CNT];
399
 
400
wire [15:0] mem_cnt_dec = (mem_cnt==16'h0000)         ? 16'h0000 :
401
                          (dbg_mem_acc | dbg_reg_acc) ? 16'hffff : 16'h0000;
402
 
403
always @ (posedge mclk or posedge por)
404
  if (por)             mem_cnt <=  16'h0000;
405
  else if (mem_cnt_wr) mem_cnt <=  dbg_din;
406
  else                 mem_cnt <=  mem_cnt + mem_cnt_dec;
407
 
408
 
409
//=============================================================================
410
// 5)  BREAKPOINTS / WATCHPOINTS
411
//=============================================================================
412
 
413
`ifdef DBG_HWBRK_0
414
// Hardware Breakpoint/Watchpoint Register read select
415
wire [3:0] brk0_reg_rd = {reg_rd[BRK0_ADDR1],
416
                          reg_rd[BRK0_ADDR0],
417
                          reg_rd[BRK0_STAT],
418
                          reg_rd[BRK0_CTL]};
419
 
420
// Hardware Breakpoint/Watchpoint Register write select
421
wire [3:0] brk0_reg_wr = {reg_wr[BRK0_ADDR1],
422
                          reg_wr[BRK0_ADDR0],
423
                          reg_wr[BRK0_STAT],
424
                          reg_wr[BRK0_CTL]};
425
 
426 34 olivier.gi
omsp_dbg_hwbrk dbg_hwbr_0 (
427 2 olivier.gi
 
428
// OUTPUTs
429
    .brk_halt   (brk0_halt),   // Hardware breakpoint command
430
    .brk_pnd    (brk0_pnd),    // Hardware break/watch-point pending
431
    .brk_dout   (brk0_dout),   // Hardware break/watch-point register data input
432
 
433
// INPUTs
434
    .brk_reg_rd (brk0_reg_rd), // Hardware break/watch-point register read select
435
    .brk_reg_wr (brk0_reg_wr), // Hardware break/watch-point register write select
436
    .dbg_din    (dbg_din),     // Debug register data input
437
    .eu_mab     (eu_mab),      // Execution-Unit Memory address bus
438
    .eu_mb_en   (eu_mb_en),    // Execution-Unit Memory bus enable
439
    .eu_mb_wr   (eu_mb_wr),    // Execution-Unit Memory bus write transfer
440
    .eu_mdb_in  (eu_mdb_in),   // Memory data bus input
441
    .eu_mdb_out (eu_mdb_out),  // Memory data bus output
442
    .exec_done  (exec_done),   // Execution completed
443
    .fe_mb_en   (fe_mb_en),    // Frontend Memory bus enable
444
    .mclk       (mclk),        // Main system clock
445
    .pc         (pc),          // Program counter
446
    .por        (por)          // Power on reset
447
);
448
 
449
`else
450
assign brk0_halt =  1'b0;
451
assign brk0_pnd  =  1'b0;
452
assign brk0_dout = 16'h0000;
453
`endif
454
 
455
`ifdef DBG_HWBRK_1
456
// Hardware Breakpoint/Watchpoint Register read select
457
wire [3:0] brk1_reg_rd = {reg_rd[BRK1_ADDR1],
458
                          reg_rd[BRK1_ADDR0],
459
                          reg_rd[BRK1_STAT],
460
                          reg_rd[BRK1_CTL]};
461
 
462
// Hardware Breakpoint/Watchpoint Register write select
463
wire [3:0] brk1_reg_wr = {reg_wr[BRK1_ADDR1],
464
                          reg_wr[BRK1_ADDR0],
465
                          reg_wr[BRK1_STAT],
466
                          reg_wr[BRK1_CTL]};
467
 
468 34 olivier.gi
omsp_dbg_hwbrk dbg_hwbr_1 (
469 2 olivier.gi
 
470
// OUTPUTs
471
    .brk_halt   (brk1_halt),   // Hardware breakpoint command
472
    .brk_pnd    (brk1_pnd),    // Hardware break/watch-point pending
473
    .brk_dout   (brk1_dout),   // Hardware break/watch-point register data input
474
 
475
// INPUTs
476
    .brk_reg_rd (brk1_reg_rd), // Hardware break/watch-point register read select
477
    .brk_reg_wr (brk1_reg_wr), // Hardware break/watch-point register write select
478
    .dbg_din    (dbg_din),     // Debug register data input
479
    .eu_mab     (eu_mab),      // Execution-Unit Memory address bus
480
    .eu_mb_en   (eu_mb_en),    // Execution-Unit Memory bus enable
481
    .eu_mb_wr   (eu_mb_wr),    // Execution-Unit Memory bus write transfer
482
    .eu_mdb_in  (eu_mdb_in),   // Memory data bus input
483
    .eu_mdb_out (eu_mdb_out),  // Memory data bus output
484
    .exec_done  (exec_done),   // Execution completed
485
    .fe_mb_en   (fe_mb_en),    // Frontend Memory bus enable
486
    .mclk       (mclk),        // Main system clock
487
    .pc         (pc),          // Program counter
488
    .por        (por)          // Power on reset
489
);
490
 
491
`else
492
assign brk1_halt =  1'b0;
493
assign brk1_pnd  =  1'b0;
494
assign brk1_dout = 16'h0000;
495
`endif
496
 
497
 `ifdef DBG_HWBRK_2
498
// Hardware Breakpoint/Watchpoint Register read select
499
wire [3:0] brk2_reg_rd = {reg_rd[BRK2_ADDR1],
500
                          reg_rd[BRK2_ADDR0],
501
                          reg_rd[BRK2_STAT],
502
                          reg_rd[BRK2_CTL]};
503
 
504
// Hardware Breakpoint/Watchpoint Register write select
505
wire [3:0] brk2_reg_wr = {reg_wr[BRK2_ADDR1],
506
                          reg_wr[BRK2_ADDR0],
507
                          reg_wr[BRK2_STAT],
508
                          reg_wr[BRK2_CTL]};
509
 
510 34 olivier.gi
omsp_dbg_hwbrk dbg_hwbr_2 (
511 2 olivier.gi
 
512
// OUTPUTs
513
    .brk_halt   (brk2_halt),   // Hardware breakpoint command
514
    .brk_pnd    (brk2_pnd),    // Hardware break/watch-point pending
515
    .brk_dout   (brk2_dout),   // Hardware break/watch-point register data input
516
 
517
// INPUTs
518
    .brk_reg_rd (brk2_reg_rd), // Hardware break/watch-point register read select
519
    .brk_reg_wr (brk2_reg_wr), // Hardware break/watch-point register write select
520
    .dbg_din    (dbg_din),     // Debug register data input
521
    .eu_mab     (eu_mab),      // Execution-Unit Memory address bus
522
    .eu_mb_en   (eu_mb_en),    // Execution-Unit Memory bus enable
523
    .eu_mb_wr   (eu_mb_wr),    // Execution-Unit Memory bus write transfer
524
    .eu_mdb_in  (eu_mdb_in),   // Memory data bus input
525
    .eu_mdb_out (eu_mdb_out),  // Memory data bus output
526
    .exec_done  (exec_done),   // Execution completed
527
    .fe_mb_en   (fe_mb_en),    // Frontend Memory bus enable
528
    .mclk       (mclk),        // Main system clock
529
    .pc         (pc),          // Program counter
530
    .por        (por)          // Power on reset
531
);
532
 
533
`else
534
assign brk2_halt =  1'b0;
535
assign brk2_pnd  =  1'b0;
536
assign brk2_dout = 16'h0000;
537
`endif
538
 
539
`ifdef DBG_HWBRK_3
540
// Hardware Breakpoint/Watchpoint Register read select
541
wire [3:0] brk3_reg_rd = {reg_rd[BRK3_ADDR1],
542
                          reg_rd[BRK3_ADDR0],
543
                          reg_rd[BRK3_STAT],
544
                          reg_rd[BRK3_CTL]};
545
 
546
// Hardware Breakpoint/Watchpoint Register write select
547
wire [3:0] brk3_reg_wr = {reg_wr[BRK3_ADDR1],
548
                          reg_wr[BRK3_ADDR0],
549
                          reg_wr[BRK3_STAT],
550
                          reg_wr[BRK3_CTL]};
551
 
552 34 olivier.gi
omsp_dbg_hwbrk dbg_hwbr_3 (
553 2 olivier.gi
 
554
// OUTPUTs
555
    .brk_halt   (brk3_halt),   // Hardware breakpoint command
556
    .brk_pnd    (brk3_pnd),    // Hardware break/watch-point pending
557
    .brk_dout   (brk3_dout),   // Hardware break/watch-point register data input
558
 
559
// INPUTs
560
    .brk_reg_rd (brk3_reg_rd), // Hardware break/watch-point register read select
561
    .brk_reg_wr (brk3_reg_wr), // Hardware break/watch-point register write select
562
    .dbg_din    (dbg_din),     // Debug register data input
563
    .eu_mab     (eu_mab),      // Execution-Unit Memory address bus
564
    .eu_mb_en   (eu_mb_en),    // Execution-Unit Memory bus enable
565
    .eu_mb_wr   (eu_mb_wr),    // Execution-Unit Memory bus write transfer
566
    .eu_mdb_in  (eu_mdb_in),   // Memory data bus input
567
    .eu_mdb_out (eu_mdb_out),  // Memory data bus output
568
    .exec_done  (exec_done),   // Execution completed
569
    .fe_mb_en   (fe_mb_en),    // Frontend Memory bus enable
570
    .mclk       (mclk),        // Main system clock
571
    .pc         (pc),          // Program counter
572
    .por        (por)          // Power on reset
573
);
574
 
575
`else
576
assign brk3_halt =  1'b0;
577
assign brk3_pnd  =  1'b0;
578
assign brk3_dout = 16'h0000;
579
`endif
580
 
581
 
582
//============================================================================
583
// 6) DATA OUTPUT GENERATION
584
//============================================================================
585
 
586
wire [15:0] cpu_id_lo_rd = cpu_id[15:0]           & {16{reg_rd[CPU_ID_LO]}};
587
wire [15:0] cpu_id_hi_rd = cpu_id[31:16]          & {16{reg_rd[CPU_ID_HI]}};
588
wire [15:0] cpu_ctl_rd   = {8'h00, cpu_ctl_full}  & {16{reg_rd[CPU_CTL]}};
589
wire [15:0] cpu_stat_rd  = {8'h00, cpu_stat_full} & {16{reg_rd[CPU_STAT]}};
590
wire [15:0] mem_ctl_rd   = {8'h00, mem_ctl_full}  & {16{reg_rd[MEM_CTL]}};
591
wire [15:0] mem_data_rd  = mem_data               & {16{reg_rd[MEM_DATA]}};
592
wire [15:0] mem_addr_rd  = mem_addr               & {16{reg_rd[MEM_ADDR]}};
593
wire [15:0] mem_cnt_rd   = mem_cnt                & {16{reg_rd[MEM_CNT]}};
594
 
595
wire [15:0] dbg_dout = cpu_id_lo_rd |
596
                       cpu_id_hi_rd |
597
                       cpu_ctl_rd   |
598
                       cpu_stat_rd  |
599
                       mem_ctl_rd   |
600
                       mem_data_rd  |
601
                       mem_addr_rd  |
602
                       mem_cnt_rd   |
603
                       brk0_dout    |
604
                       brk1_dout    |
605
                       brk2_dout    |
606
                       brk3_dout;
607
 
608
// Tell UART/JTAG interface that the data is ready to be read
609
always @ (posedge mclk or posedge por)
610
  if (por)                           dbg_rd_rdy  <=  1'b0;
611
  else if (mem_burst | mem_burst_rd) dbg_rd_rdy  <= (dbg_reg_rd | dbg_mem_rd_dly);
612
  else                               dbg_rd_rdy  <=  dbg_rd;
613
 
614
 
615
//============================================================================
616
// 7) CPU CONTROL
617
//============================================================================
618
 
619
// Reset CPU
620
//--------------------------
621
wire dbg_reset  = cpu_ctl[`CPU_RST];
622
 
623
 
624
// Break after reset
625
//--------------------------
626 84 olivier.gi
wire halt_rst = cpu_ctl[`RST_BRK_EN] & puc_s;
627 2 olivier.gi
 
628
 
629
// Freeze peripherals
630
//--------------------------
631
wire dbg_freeze = dbg_halt_st & cpu_ctl[`FRZ_BRK_EN];
632
 
633
 
634
// Software break
635
//--------------------------
636 54 olivier.gi
assign dbg_swbrk = (fe_mdb_in==`DBG_SWBRK_OP) & decode_noirq & cpu_ctl[`SW_BRK_EN];
637 2 olivier.gi
 
638
 
639
// Single step
640
//--------------------------
641
reg [1:0] inc_step;
642
always @(posedge mclk or posedge por)
643
  if (por)        inc_step <= 2'b00;
644
  else if (istep) inc_step <= 2'b11;
645
  else            inc_step <= {inc_step[0], 1'b0};
646
 
647
 
648
// Run / Halt
649
//--------------------------
650
reg   halt_flag;
651
 
652
wire  mem_halt_cpu;
653
wire  mem_run_cpu;
654
 
655
wire  halt_flag_clr = run_cpu   | mem_run_cpu;
656
wire  halt_flag_set = halt_cpu  | halt_rst  | dbg_swbrk | mem_halt_cpu |
657
                      brk0_halt | brk1_halt | brk2_halt | brk3_halt;
658
 
659
always @(posedge mclk or posedge por)
660
  if (por)                halt_flag <= 1'b0;
661
  else if (halt_flag_clr) halt_flag <= 1'b0;
662
  else if (halt_flag_set) halt_flag <= 1'b1;
663
 
664
wire dbg_halt_cmd = (halt_flag | halt_flag_set) & ~inc_step[1];
665
 
666
 
667
//============================================================================
668
// 8) MEMORY CONTROL
669
//============================================================================
670
 
671
// Control Memory bursts
672
//------------------------------
673
 
674
wire mem_burst_start = (mem_start             &  |mem_cnt);
675
wire mem_burst_end   = ((dbg_wr | dbg_rd_rdy) & ~|mem_cnt);
676
 
677
// Detect when burst is on going
678
always @(posedge mclk or posedge por)
679
  if (por)                  mem_burst <= 1'b0;
680
  else if (mem_burst_start) mem_burst <= 1'b1;
681
  else if (mem_burst_end)   mem_burst <= 1'b0;
682
 
683
// Control signals for UART/JTAG interface
684
assign mem_burst_rd = (mem_burst_start & ~mem_ctl[1]);
685
assign mem_burst_wr = (mem_burst_start &  mem_ctl[1]);
686
 
687
// Trigger CPU Register or memory access during a burst
688
reg        mem_startb;
689
always @(posedge mclk or posedge por)
690
  if (por) mem_startb <= 1'b0;
691
  else     mem_startb <= (mem_burst & (dbg_wr | dbg_rd)) | mem_burst_rd;
692
 
693
// Combine single and burst memory start of sequence
694
wire       mem_seq_start = ((mem_start & ~|mem_cnt) | mem_startb);
695
 
696
 
697
// Memory access state machine
698
//------------------------------
699
reg  [1:0] mem_state;
700
reg  [1:0] mem_state_nxt;
701
 
702
// State machine definition
703
parameter  M_IDLE       = 2'h0;
704
parameter  M_SET_BRK    = 2'h1;
705
parameter  M_ACCESS_BRK = 2'h2;
706
parameter  M_ACCESS     = 2'h3;
707
 
708
// State transition
709
always @(mem_state or mem_seq_start or dbg_halt_st)
710
  case (mem_state)
711
    M_IDLE       : mem_state_nxt = ~mem_seq_start ? M_IDLE       :
712
                                    dbg_halt_st   ? M_ACCESS     : M_SET_BRK;
713
    M_SET_BRK    : mem_state_nxt =  dbg_halt_st   ? M_ACCESS_BRK : M_SET_BRK;
714
    M_ACCESS_BRK : mem_state_nxt =  M_IDLE;
715
    M_ACCESS     : mem_state_nxt =  M_IDLE;
716
    default      : mem_state_nxt =  M_IDLE;
717
  endcase
718
 
719
// State machine
720
always @(posedge mclk or posedge por)
721
  if (por) mem_state <= M_IDLE;
722
  else     mem_state <= mem_state_nxt;
723
 
724
// Utility signals
725
assign mem_halt_cpu = (mem_state==M_IDLE)       & (mem_state_nxt==M_SET_BRK);
726
assign mem_run_cpu  = (mem_state==M_ACCESS_BRK) & (mem_state_nxt==M_IDLE);
727
assign mem_access   = (mem_state==M_ACCESS)     | (mem_state==M_ACCESS_BRK);
728
 
729
 
730
// Interface to CPU Registers and Memory bacbkone
731
//------------------------------------------------
732
assign      dbg_mem_addr   =  mem_addr;
733
assign      dbg_mem_dout   = ~mem_bw      ? mem_data               :
734
                              mem_addr[0] ? {mem_data[7:0], 8'h00} :
735
                                            {8'h00, mem_data[7:0]};
736
 
737
assign      dbg_reg_wr     = mem_access &  mem_ctl[1] &  mem_ctl[2];
738
assign      dbg_reg_rd     = mem_access & ~mem_ctl[1] &  mem_ctl[2];
739
 
740
assign      dbg_mem_en     = mem_access & ~mem_ctl[2];
741
assign      dbg_mem_rd     = dbg_mem_en & ~mem_ctl[1];
742
 
743
wire  [1:0] dbg_mem_wr_msk = ~mem_bw      ? 2'b11 :
744
                              mem_addr[0] ? 2'b10 : 2'b01;
745
assign      dbg_mem_wr     = {2{dbg_mem_en & mem_ctl[1]}} & dbg_mem_wr_msk;
746
 
747
 
748
// It takes one additional cycle to read from Memory as from registers
749
always @(posedge mclk or posedge por)
750
  if (por) dbg_mem_rd_dly <= 1'b0;
751
  else     dbg_mem_rd_dly <= dbg_mem_rd;
752
 
753
 
754
//=============================================================================
755
// 9)  UART COMMUNICATION
756
//=============================================================================
757
`ifdef DBG_UART
758 34 olivier.gi
omsp_dbg_uart dbg_uart_0 (
759 2 olivier.gi
 
760
// OUTPUTs
761
    .dbg_addr     (dbg_addr),      // Debug register address
762
    .dbg_din      (dbg_din),       // Debug register data input
763
    .dbg_rd       (dbg_rd),        // Debug register data read
764
    .dbg_uart_txd (dbg_uart_txd),  // Debug interface: UART TXD
765
    .dbg_wr       (dbg_wr),        // Debug register data write
766
 
767
// INPUTs
768
    .dbg_dout     (dbg_dout),      // Debug register data output
769
    .dbg_rd_rdy   (dbg_rd_rdy),    // Debug register data is ready for read
770
    .dbg_uart_rxd (dbg_uart_rxd),  // Debug interface: UART RXD
771
    .mclk         (mclk),          // Main system clock
772
    .mem_burst    (mem_burst),     // Burst on going
773
    .mem_burst_end(mem_burst_end), // End TX/RX burst
774
    .mem_burst_rd (mem_burst_rd),  // Start TX burst
775
    .mem_burst_wr (mem_burst_wr),  // Start RX burst
776
    .mem_bw       (mem_bw),        // Burst byte width
777
    .por          (por)            // Power on reset
778
);
779
 
780
`else
781
assign dbg_addr     =  6'h00;
782
assign dbg_din      = 16'h0000;
783
assign dbg_rd       =  1'b0;
784
assign dbg_uart_txd =  1'b0;
785
assign dbg_wr       =  1'b0;
786
`endif
787
 
788
 
789
//=============================================================================
790
// 10)  JTAG COMMUNICATION
791
//=============================================================================
792
`ifdef DBG_JTAG
793
JTAG INTERFACE IS NOT SUPPORTED YET
794
`else
795
`endif
796
 
797
endmodule // dbg
798
 
799 33 olivier.gi
`include "openMSP430_undefines.v"

powered by: WebSVN 2.1.0

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