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

Subversion Repositories openmsp430

[/] [openmsp430/] [trunk/] [core/] [rtl/] [verilog/] [omsp_dbg_hwbrk.v] - Blame information for rev 149

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

Line No. Rev Author Line
1 2 olivier.gi
//----------------------------------------------------------------------------
2 117 olivier.gi
// Copyright (C) 2009 , Olivier Girard
3 2 olivier.gi
//
4 117 olivier.gi
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions
6
// are met:
7
//     * Redistributions of source code must retain the above copyright
8
//       notice, this list of conditions and the following disclaimer.
9
//     * Redistributions in binary form must reproduce the above copyright
10
//       notice, this list of conditions and the following disclaimer in the
11
//       documentation and/or other materials provided with the distribution.
12
//     * Neither the name of the authors nor the names of its contributors
13
//       may be used to endorse or promote products derived from this software
14
//       without specific prior written permission.
15 2 olivier.gi
//
16 117 olivier.gi
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21
// OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26
// THE POSSIBILITY OF SUCH DAMAGE
27 2 olivier.gi
//
28
//----------------------------------------------------------------------------
29
//
30 34 olivier.gi
// *File Name: omsp_dbg_hwbrk.v
31 2 olivier.gi
// 
32
// *Module Description:
33
//                       Hardware Breakpoint / Watchpoint module
34
//
35
// *Author(s):
36
//              - Olivier Girard,    olgirard@gmail.com
37
//
38
//----------------------------------------------------------------------------
39 17 olivier.gi
// $Rev: 117 $
40
// $LastChangedBy: olivier.girard $
41
// $LastChangedDate: 2011-06-23 21:30:51 +0200 (Thu, 23 Jun 2011) $
42
//----------------------------------------------------------------------------
43 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
44
`else
45 23 olivier.gi
`include "openMSP430_defines.v"
46 103 olivier.gi
`endif
47 2 olivier.gi
 
48 34 olivier.gi
module  omsp_dbg_hwbrk (
49 2 olivier.gi
 
50
// OUTPUTs
51
    brk_halt,                // Hardware breakpoint command
52
    brk_pnd,                 // Hardware break/watch-point pending
53
    brk_dout,                // Hardware break/watch-point register data input
54
 
55
// INPUTs
56
    brk_reg_rd,              // Hardware break/watch-point register read select
57
    brk_reg_wr,              // Hardware break/watch-point register write select
58 106 olivier.gi
    dbg_clk,                 // Debug unit clock
59 2 olivier.gi
    dbg_din,                 // Debug register data input
60 106 olivier.gi
    dbg_rst,                 // Debug unit reset
61 2 olivier.gi
    eu_mab,                  // Execution-Unit Memory address bus
62
    eu_mb_en,                // Execution-Unit Memory bus enable
63
    eu_mb_wr,                // Execution-Unit Memory bus write transfer
64
    eu_mdb_in,               // Memory data bus input
65
    eu_mdb_out,              // Memory data bus output
66
    exec_done,               // Execution completed
67
    fe_mb_en,                // Frontend Memory bus enable
68 106 olivier.gi
    pc                       // Program counter
69 2 olivier.gi
);
70
 
71
// OUTPUTs
72
//=========
73
output         brk_halt;     // Hardware breakpoint command
74
output         brk_pnd;      // Hardware break/watch-point pending
75
output  [15:0] brk_dout;     // Hardware break/watch-point register data input
76
 
77
// INPUTs
78
//=========
79
input    [3:0] brk_reg_rd;   // Hardware break/watch-point register read select
80
input    [3:0] brk_reg_wr;   // Hardware break/watch-point register write select
81 106 olivier.gi
input          dbg_clk;      // Debug unit clock
82 2 olivier.gi
input   [15:0] dbg_din;      // Debug register data input
83 106 olivier.gi
input          dbg_rst;      // Debug unit reset
84 2 olivier.gi
input   [15:0] eu_mab;       // Execution-Unit Memory address bus
85
input          eu_mb_en;     // Execution-Unit Memory bus enable
86
input    [1:0] eu_mb_wr;     // Execution-Unit Memory bus write transfer
87
input   [15:0] eu_mdb_in;    // Memory data bus input
88
input   [15:0] eu_mdb_out;   // Memory data bus output
89
input          exec_done;    // Execution completed
90
input          fe_mb_en;     // Frontend Memory bus enable
91
input   [15:0] pc;           // Program counter
92
 
93
 
94
//=============================================================================
95
// 1)  WIRE & PARAMETER DECLARATION
96
//=============================================================================
97
 
98
wire      range_wr_set;
99
wire      range_rd_set;
100
wire      addr1_wr_set;
101
wire      addr1_rd_set;
102
wire      addr0_wr_set;
103
wire      addr0_rd_set;
104
 
105
 
106
parameter BRK_CTL   = 0,
107
          BRK_STAT  = 1,
108
          BRK_ADDR0 = 2,
109
          BRK_ADDR1 = 3;
110
 
111
 
112
//=============================================================================
113
// 2)  CONFIGURATION REGISTERS
114
//=============================================================================
115
 
116
// BRK_CTL Register
117
//-----------------------------------------------------------------------------
118
//       7   6   5        4            3          2            1  0
119
//        Reserved    RANGE_MODE    INST_EN    BREAK_EN    ACCESS_MODE
120
//
121
// ACCESS_MODE: - 00 : Disabled
122
//              - 01 : Detect read access
123
//              - 10 : Detect write access
124
//              - 11 : Detect read/write access
125
//              NOTE: '10' & '11' modes are not supported on the instruction flow
126
//
127
// BREAK_EN:    -  0 : Watchmode enable
128
//              -  1 : Break enable
129
//
130
// INST_EN:     -  0 : Checks are done on the execution unit (data flow)
131
//              -  1 : Checks are done on the frontend (instruction flow)
132
//
133
// RANGE_MODE:  -  0 : Address match on BRK_ADDR0 or BRK_ADDR1
134
//              -  1 : Address match on BRK_ADDR0->BRK_ADDR1 range
135
//
136
//-----------------------------------------------------------------------------
137
reg   [4:0] brk_ctl;
138
 
139
wire        brk_ctl_wr = brk_reg_wr[BRK_CTL];
140
 
141 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
142
  if (dbg_rst)         brk_ctl <=  5'h00;
143 57 olivier.gi
  else if (brk_ctl_wr) brk_ctl <=  {`HWBRK_RANGE & dbg_din[4], dbg_din[3:0]};
144 2 olivier.gi
 
145
wire  [7:0] brk_ctl_full = {3'b000, brk_ctl};
146
 
147
 
148
// BRK_STAT Register
149
//-----------------------------------------------------------------------------
150
//     7    6       5         4         3         2         1         0
151
//    Reserved  RANGE_WR  RANGE_RD  ADDR1_WR  ADDR1_RD  ADDR0_WR  ADDR0_RD
152
//-----------------------------------------------------------------------------
153
reg   [5:0] brk_stat;
154
 
155
wire        brk_stat_wr  = brk_reg_wr[BRK_STAT];
156 57 olivier.gi
wire  [5:0] brk_stat_set = {range_wr_set & `HWBRK_RANGE,
157
                            range_rd_set & `HWBRK_RANGE,
158 2 olivier.gi
                            addr1_wr_set, addr1_rd_set,
159
                            addr0_wr_set, addr0_rd_set};
160
wire  [5:0] brk_stat_clr = ~dbg_din[5:0];
161
 
162 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
163
  if (dbg_rst)          brk_stat <=  6'h00;
164 2 olivier.gi
  else if (brk_stat_wr) brk_stat <= ((brk_stat & brk_stat_clr) | brk_stat_set);
165
  else                  brk_stat <=  (brk_stat                 | brk_stat_set);
166
 
167
wire  [7:0] brk_stat_full = {2'b00, brk_stat};
168
wire        brk_pnd       = |brk_stat;
169
 
170
 
171
// BRK_ADDR0 Register
172
//-----------------------------------------------------------------------------
173
reg  [15:0] brk_addr0;
174
 
175
wire        brk_addr0_wr = brk_reg_wr[BRK_ADDR0];
176
 
177 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
178
  if (dbg_rst)           brk_addr0 <=  16'h0000;
179 2 olivier.gi
  else if (brk_addr0_wr) brk_addr0 <=  dbg_din;
180
 
181
 
182
// BRK_ADDR1/DATA0 Register
183
//-----------------------------------------------------------------------------
184
reg  [15:0] brk_addr1;
185
 
186
wire        brk_addr1_wr = brk_reg_wr[BRK_ADDR1];
187
 
188 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
189
  if (dbg_rst)           brk_addr1 <=  16'h0000;
190 2 olivier.gi
  else if (brk_addr1_wr) brk_addr1 <=  dbg_din;
191
 
192
 
193
//============================================================================
194
// 3) DATA OUTPUT GENERATION
195
//============================================================================
196
 
197
wire [15:0] brk_ctl_rd   = {8'h00, brk_ctl_full}  & {16{brk_reg_rd[BRK_CTL]}};
198
wire [15:0] brk_stat_rd  = {8'h00, brk_stat_full} & {16{brk_reg_rd[BRK_STAT]}};
199
wire [15:0] brk_addr0_rd = brk_addr0              & {16{brk_reg_rd[BRK_ADDR0]}};
200
wire [15:0] brk_addr1_rd = brk_addr1              & {16{brk_reg_rd[BRK_ADDR1]}};
201
 
202
wire [15:0] brk_dout = brk_ctl_rd   |
203
                       brk_stat_rd  |
204
                       brk_addr0_rd |
205
                       brk_addr1_rd;
206
 
207
 
208
//============================================================================
209
// 4) BREAKPOINT / WATCHPOINT GENERATION
210
//============================================================================
211
 
212
// Comparators
213
//---------------------------
214
// Note: here the comparison logic is instanciated several times in order
215
//       to improve the timings, at the cost of a bit more area.
216
 
217
wire        equ_d_addr0 = eu_mb_en & (eu_mab==brk_addr0) & ~brk_ctl[`BRK_RANGE];
218
wire        equ_d_addr1 = eu_mb_en & (eu_mab==brk_addr1) & ~brk_ctl[`BRK_RANGE];
219 57 olivier.gi
wire        equ_d_range = eu_mb_en & ((eu_mab>=brk_addr0) & (eu_mab<=brk_addr1)) &
220
                          brk_ctl[`BRK_RANGE] & `HWBRK_RANGE;
221 2 olivier.gi
 
222
reg         fe_mb_en_buf;
223 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
224
  if (dbg_rst)  fe_mb_en_buf <=  1'b0;
225
  else          fe_mb_en_buf <=  fe_mb_en;
226 2 olivier.gi
 
227
wire        equ_i_addr0 = fe_mb_en_buf & (pc==brk_addr0) & ~brk_ctl[`BRK_RANGE];
228
wire        equ_i_addr1 = fe_mb_en_buf & (pc==brk_addr1) & ~brk_ctl[`BRK_RANGE];
229 57 olivier.gi
wire        equ_i_range = fe_mb_en_buf & ((pc>=brk_addr0) & (pc<=brk_addr1)) &
230
                          brk_ctl[`BRK_RANGE] & `HWBRK_RANGE;
231 2 olivier.gi
 
232
 
233
// Detect accesses
234
//---------------------------
235
 
236
// Detect Instruction read access
237
wire i_addr0_rd =  equ_i_addr0 &  brk_ctl[`BRK_I_EN];
238
wire i_addr1_rd =  equ_i_addr1 &  brk_ctl[`BRK_I_EN];
239
wire i_range_rd =  equ_i_range &  brk_ctl[`BRK_I_EN];
240
 
241
// Detect Execution-Unit write access
242
wire d_addr0_wr =  equ_d_addr0 & ~brk_ctl[`BRK_I_EN] &  |eu_mb_wr;
243
wire d_addr1_wr =  equ_d_addr1 & ~brk_ctl[`BRK_I_EN] &  |eu_mb_wr;
244
wire d_range_wr =  equ_d_range & ~brk_ctl[`BRK_I_EN] &  |eu_mb_wr;
245
 
246
// Detect DATA read access
247
// Whenever an "ADD r9. &0x200" instruction is executed, &0x200 will be read
248
// before being written back. In that case, the read flag should not be set.
249
// In general, We should here make sure no write access occures during the
250
// same instruction cycle before setting the read flag.
251
reg [2:0] d_rd_trig;
252 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
253
  if (dbg_rst)        d_rd_trig <=  3'h0;
254 2 olivier.gi
  else if (exec_done) d_rd_trig <=  3'h0;
255
  else                d_rd_trig <=  {equ_d_range & ~brk_ctl[`BRK_I_EN] & ~|eu_mb_wr,
256
                                     equ_d_addr1 & ~brk_ctl[`BRK_I_EN] & ~|eu_mb_wr,
257
                                     equ_d_addr0 & ~brk_ctl[`BRK_I_EN] & ~|eu_mb_wr};
258
 
259
wire d_addr0_rd =  d_rd_trig[0] & exec_done & ~d_addr0_wr;
260
wire d_addr1_rd =  d_rd_trig[1] & exec_done & ~d_addr1_wr;
261
wire d_range_rd =  d_rd_trig[2] & exec_done & ~d_range_wr;
262
 
263
 
264
// Set flags
265
assign addr0_rd_set = brk_ctl[`BRK_MODE_RD] & (d_addr0_rd  | i_addr0_rd);
266
assign addr0_wr_set = brk_ctl[`BRK_MODE_WR] &  d_addr0_wr;
267
assign addr1_rd_set = brk_ctl[`BRK_MODE_RD] & (d_addr1_rd  | i_addr1_rd);
268
assign addr1_wr_set = brk_ctl[`BRK_MODE_WR] &  d_addr1_wr;
269
assign range_rd_set = brk_ctl[`BRK_MODE_RD] & (d_range_rd  | i_range_rd);
270
assign range_wr_set = brk_ctl[`BRK_MODE_WR] &  d_range_wr;
271
 
272
 
273
// Break CPU
274
assign brk_halt     = brk_ctl[`BRK_EN] & |brk_stat_set;
275
 
276
 
277 34 olivier.gi
endmodule // omsp_dbg_hwbrk
278 2 olivier.gi
 
279 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
280
`else
281 33 olivier.gi
`include "openMSP430_undefines.v"
282 103 olivier.gi
`endif

powered by: WebSVN 2.1.0

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