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 115

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_hwbrk.v
26 2 olivier.gi
// 
27
// *Module Description:
28
//                       Hardware Breakpoint / Watchpoint module
29
//
30
// *Author(s):
31
//              - Olivier Girard,    olgirard@gmail.com
32
//
33
//----------------------------------------------------------------------------
34 17 olivier.gi
// $Rev: 106 $
35
// $LastChangedBy: olivier.girard $
36
// $LastChangedDate: 2011-03-25 23:01:03 +0100 (Fri, 25 Mar 2011) $
37
//----------------------------------------------------------------------------
38 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
39
`else
40 23 olivier.gi
`include "openMSP430_defines.v"
41 103 olivier.gi
`endif
42 2 olivier.gi
 
43 34 olivier.gi
module  omsp_dbg_hwbrk (
44 2 olivier.gi
 
45
// OUTPUTs
46
    brk_halt,                // Hardware breakpoint command
47
    brk_pnd,                 // Hardware break/watch-point pending
48
    brk_dout,                // Hardware break/watch-point register data input
49
 
50
// INPUTs
51
    brk_reg_rd,              // Hardware break/watch-point register read select
52
    brk_reg_wr,              // Hardware break/watch-point register write select
53 106 olivier.gi
    dbg_clk,                 // Debug unit clock
54 2 olivier.gi
    dbg_din,                 // Debug register data input
55 106 olivier.gi
    dbg_rst,                 // Debug unit reset
56 2 olivier.gi
    eu_mab,                  // Execution-Unit Memory address bus
57
    eu_mb_en,                // Execution-Unit Memory bus enable
58
    eu_mb_wr,                // Execution-Unit Memory bus write transfer
59
    eu_mdb_in,               // Memory data bus input
60
    eu_mdb_out,              // Memory data bus output
61
    exec_done,               // Execution completed
62
    fe_mb_en,                // Frontend Memory bus enable
63 106 olivier.gi
    pc                       // Program counter
64 2 olivier.gi
);
65
 
66
// OUTPUTs
67
//=========
68
output         brk_halt;     // Hardware breakpoint command
69
output         brk_pnd;      // Hardware break/watch-point pending
70
output  [15:0] brk_dout;     // Hardware break/watch-point register data input
71
 
72
// INPUTs
73
//=========
74
input    [3:0] brk_reg_rd;   // Hardware break/watch-point register read select
75
input    [3:0] brk_reg_wr;   // Hardware break/watch-point register write select
76 106 olivier.gi
input          dbg_clk;      // Debug unit clock
77 2 olivier.gi
input   [15:0] dbg_din;      // Debug register data input
78 106 olivier.gi
input          dbg_rst;      // Debug unit reset
79 2 olivier.gi
input   [15:0] eu_mab;       // Execution-Unit Memory address bus
80
input          eu_mb_en;     // Execution-Unit Memory bus enable
81
input    [1:0] eu_mb_wr;     // Execution-Unit Memory bus write transfer
82
input   [15:0] eu_mdb_in;    // Memory data bus input
83
input   [15:0] eu_mdb_out;   // Memory data bus output
84
input          exec_done;    // Execution completed
85
input          fe_mb_en;     // Frontend Memory bus enable
86
input   [15:0] pc;           // Program counter
87
 
88
 
89
//=============================================================================
90
// 1)  WIRE & PARAMETER DECLARATION
91
//=============================================================================
92
 
93
wire      range_wr_set;
94
wire      range_rd_set;
95
wire      addr1_wr_set;
96
wire      addr1_rd_set;
97
wire      addr0_wr_set;
98
wire      addr0_rd_set;
99
 
100
 
101
parameter BRK_CTL   = 0,
102
          BRK_STAT  = 1,
103
          BRK_ADDR0 = 2,
104
          BRK_ADDR1 = 3;
105
 
106
 
107
//=============================================================================
108
// 2)  CONFIGURATION REGISTERS
109
//=============================================================================
110
 
111
// BRK_CTL Register
112
//-----------------------------------------------------------------------------
113
//       7   6   5        4            3          2            1  0
114
//        Reserved    RANGE_MODE    INST_EN    BREAK_EN    ACCESS_MODE
115
//
116
// ACCESS_MODE: - 00 : Disabled
117
//              - 01 : Detect read access
118
//              - 10 : Detect write access
119
//              - 11 : Detect read/write access
120
//              NOTE: '10' & '11' modes are not supported on the instruction flow
121
//
122
// BREAK_EN:    -  0 : Watchmode enable
123
//              -  1 : Break enable
124
//
125
// INST_EN:     -  0 : Checks are done on the execution unit (data flow)
126
//              -  1 : Checks are done on the frontend (instruction flow)
127
//
128
// RANGE_MODE:  -  0 : Address match on BRK_ADDR0 or BRK_ADDR1
129
//              -  1 : Address match on BRK_ADDR0->BRK_ADDR1 range
130
//
131
//-----------------------------------------------------------------------------
132
reg   [4:0] brk_ctl;
133
 
134
wire        brk_ctl_wr = brk_reg_wr[BRK_CTL];
135
 
136 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
137
  if (dbg_rst)         brk_ctl <=  5'h00;
138 57 olivier.gi
  else if (brk_ctl_wr) brk_ctl <=  {`HWBRK_RANGE & dbg_din[4], dbg_din[3:0]};
139 2 olivier.gi
 
140
wire  [7:0] brk_ctl_full = {3'b000, brk_ctl};
141
 
142
 
143
// BRK_STAT Register
144
//-----------------------------------------------------------------------------
145
//     7    6       5         4         3         2         1         0
146
//    Reserved  RANGE_WR  RANGE_RD  ADDR1_WR  ADDR1_RD  ADDR0_WR  ADDR0_RD
147
//-----------------------------------------------------------------------------
148
reg   [5:0] brk_stat;
149
 
150
wire        brk_stat_wr  = brk_reg_wr[BRK_STAT];
151 57 olivier.gi
wire  [5:0] brk_stat_set = {range_wr_set & `HWBRK_RANGE,
152
                            range_rd_set & `HWBRK_RANGE,
153 2 olivier.gi
                            addr1_wr_set, addr1_rd_set,
154
                            addr0_wr_set, addr0_rd_set};
155
wire  [5:0] brk_stat_clr = ~dbg_din[5:0];
156
 
157 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
158
  if (dbg_rst)          brk_stat <=  6'h00;
159 2 olivier.gi
  else if (brk_stat_wr) brk_stat <= ((brk_stat & brk_stat_clr) | brk_stat_set);
160
  else                  brk_stat <=  (brk_stat                 | brk_stat_set);
161
 
162
wire  [7:0] brk_stat_full = {2'b00, brk_stat};
163
wire        brk_pnd       = |brk_stat;
164
 
165
 
166
// BRK_ADDR0 Register
167
//-----------------------------------------------------------------------------
168
reg  [15:0] brk_addr0;
169
 
170
wire        brk_addr0_wr = brk_reg_wr[BRK_ADDR0];
171
 
172 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
173
  if (dbg_rst)           brk_addr0 <=  16'h0000;
174 2 olivier.gi
  else if (brk_addr0_wr) brk_addr0 <=  dbg_din;
175
 
176
 
177
// BRK_ADDR1/DATA0 Register
178
//-----------------------------------------------------------------------------
179
reg  [15:0] brk_addr1;
180
 
181
wire        brk_addr1_wr = brk_reg_wr[BRK_ADDR1];
182
 
183 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
184
  if (dbg_rst)           brk_addr1 <=  16'h0000;
185 2 olivier.gi
  else if (brk_addr1_wr) brk_addr1 <=  dbg_din;
186
 
187
 
188
//============================================================================
189
// 3) DATA OUTPUT GENERATION
190
//============================================================================
191
 
192
wire [15:0] brk_ctl_rd   = {8'h00, brk_ctl_full}  & {16{brk_reg_rd[BRK_CTL]}};
193
wire [15:0] brk_stat_rd  = {8'h00, brk_stat_full} & {16{brk_reg_rd[BRK_STAT]}};
194
wire [15:0] brk_addr0_rd = brk_addr0              & {16{brk_reg_rd[BRK_ADDR0]}};
195
wire [15:0] brk_addr1_rd = brk_addr1              & {16{brk_reg_rd[BRK_ADDR1]}};
196
 
197
wire [15:0] brk_dout = brk_ctl_rd   |
198
                       brk_stat_rd  |
199
                       brk_addr0_rd |
200
                       brk_addr1_rd;
201
 
202
 
203
//============================================================================
204
// 4) BREAKPOINT / WATCHPOINT GENERATION
205
//============================================================================
206
 
207
// Comparators
208
//---------------------------
209
// Note: here the comparison logic is instanciated several times in order
210
//       to improve the timings, at the cost of a bit more area.
211
 
212
wire        equ_d_addr0 = eu_mb_en & (eu_mab==brk_addr0) & ~brk_ctl[`BRK_RANGE];
213
wire        equ_d_addr1 = eu_mb_en & (eu_mab==brk_addr1) & ~brk_ctl[`BRK_RANGE];
214 57 olivier.gi
wire        equ_d_range = eu_mb_en & ((eu_mab>=brk_addr0) & (eu_mab<=brk_addr1)) &
215
                          brk_ctl[`BRK_RANGE] & `HWBRK_RANGE;
216 2 olivier.gi
 
217
reg         fe_mb_en_buf;
218 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
219
  if (dbg_rst)  fe_mb_en_buf <=  1'b0;
220
  else          fe_mb_en_buf <=  fe_mb_en;
221 2 olivier.gi
 
222
wire        equ_i_addr0 = fe_mb_en_buf & (pc==brk_addr0) & ~brk_ctl[`BRK_RANGE];
223
wire        equ_i_addr1 = fe_mb_en_buf & (pc==brk_addr1) & ~brk_ctl[`BRK_RANGE];
224 57 olivier.gi
wire        equ_i_range = fe_mb_en_buf & ((pc>=brk_addr0) & (pc<=brk_addr1)) &
225
                          brk_ctl[`BRK_RANGE] & `HWBRK_RANGE;
226 2 olivier.gi
 
227
 
228
// Detect accesses
229
//---------------------------
230
 
231
// Detect Instruction read access
232
wire i_addr0_rd =  equ_i_addr0 &  brk_ctl[`BRK_I_EN];
233
wire i_addr1_rd =  equ_i_addr1 &  brk_ctl[`BRK_I_EN];
234
wire i_range_rd =  equ_i_range &  brk_ctl[`BRK_I_EN];
235
 
236
// Detect Execution-Unit write access
237
wire d_addr0_wr =  equ_d_addr0 & ~brk_ctl[`BRK_I_EN] &  |eu_mb_wr;
238
wire d_addr1_wr =  equ_d_addr1 & ~brk_ctl[`BRK_I_EN] &  |eu_mb_wr;
239
wire d_range_wr =  equ_d_range & ~brk_ctl[`BRK_I_EN] &  |eu_mb_wr;
240
 
241
// Detect DATA read access
242
// Whenever an "ADD r9. &0x200" instruction is executed, &0x200 will be read
243
// before being written back. In that case, the read flag should not be set.
244
// In general, We should here make sure no write access occures during the
245
// same instruction cycle before setting the read flag.
246
reg [2:0] d_rd_trig;
247 106 olivier.gi
always @ (posedge dbg_clk or posedge dbg_rst)
248
  if (dbg_rst)        d_rd_trig <=  3'h0;
249 2 olivier.gi
  else if (exec_done) d_rd_trig <=  3'h0;
250
  else                d_rd_trig <=  {equ_d_range & ~brk_ctl[`BRK_I_EN] & ~|eu_mb_wr,
251
                                     equ_d_addr1 & ~brk_ctl[`BRK_I_EN] & ~|eu_mb_wr,
252
                                     equ_d_addr0 & ~brk_ctl[`BRK_I_EN] & ~|eu_mb_wr};
253
 
254
wire d_addr0_rd =  d_rd_trig[0] & exec_done & ~d_addr0_wr;
255
wire d_addr1_rd =  d_rd_trig[1] & exec_done & ~d_addr1_wr;
256
wire d_range_rd =  d_rd_trig[2] & exec_done & ~d_range_wr;
257
 
258
 
259
// Set flags
260
assign addr0_rd_set = brk_ctl[`BRK_MODE_RD] & (d_addr0_rd  | i_addr0_rd);
261
assign addr0_wr_set = brk_ctl[`BRK_MODE_WR] &  d_addr0_wr;
262
assign addr1_rd_set = brk_ctl[`BRK_MODE_RD] & (d_addr1_rd  | i_addr1_rd);
263
assign addr1_wr_set = brk_ctl[`BRK_MODE_WR] &  d_addr1_wr;
264
assign range_rd_set = brk_ctl[`BRK_MODE_RD] & (d_range_rd  | i_range_rd);
265
assign range_wr_set = brk_ctl[`BRK_MODE_WR] &  d_range_wr;
266
 
267
 
268
// Break CPU
269
assign brk_halt     = brk_ctl[`BRK_EN] & |brk_stat_set;
270
 
271
 
272 34 olivier.gi
endmodule // omsp_dbg_hwbrk
273 2 olivier.gi
 
274 103 olivier.gi
`ifdef OMSP_NO_INCLUDE
275
`else
276 33 olivier.gi
`include "openMSP430_undefines.v"
277 103 olivier.gi
`endif

powered by: WebSVN 2.1.0

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