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

Subversion Repositories System09

[/] [System09/] [trunk/] [rtl/] [VHDL/] [trap.vhd] - Blame information for rev 104

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

Line No. Rev Author Line
1 99 davidgb
--===========================================================================--
2
--                                                                           --
3
--             Synthesizable Hardware Breakpoint Trap                        --
4
--                                                                           --
5
--===========================================================================--
6
--
7
--  File name      : trap.vhd
8
--
9
--  Entity name    : trap
10
--
11
--  Purpose        : Implements a 8 bit address and data hardware breakpoint comparator
12
--                   which generates an interrupt output on qualified match conditions
13
--
14
--  Dependencies   : ieee.Std_Logic_1164
15
--                   ieee.std_logic_unsigned
16
--
17
--  Author         : John E. Kent      
18
--
19
--  Email          : dilbert57@opencores.org      
20
--
21
--  Web            : http://opencores.org/project,system09
22
-- 
23
--  Description    : Register Memory Map
24
--
25
--                   Base + $00 - Address Comparitor High Byte
26
--                   Base + $01 - Address Comparitor Low byte
27
--                   Base + $02 - Data    Comparitor
28
--                   Base + $03 - Control Comparitor
29
--                   Base + $04 - Address Qualifier High Byte
30
--                   Base + $05 - Address Qualifier Low byte
31
--                   Base + $06 - Data    Qualifier
32
--                   Base + $07 - Control Qualifier
33
--
34
--                   Address, Data and Control signals 
35
--                   must match in the Comparitor registers 
36
--                   Matches are qualified by setting a bit 
37
--                   in the Qualifier registers
38
--
39
--                   Control Comparitor / Control Qualify (write)
40
--                   b0 - r/w        1=read  0=write
41
--                   b1 - vma        1=valid 0=invalid
42
--                   b7 - irq output 1=match 0=mismatch
43
--
44
--                   Control Qualifier Read
45
--                   b7 - match flag
46
--
47
--  Copyright (C) 2003 - 2010 John Kent
48
--
49
--  This program is free software: you can redistribute it and/or modify
50
--  it under the terms of the GNU General Public License as published by
51
--  the Free Software Foundation, either version 3 of the License, or
52
--  (at your option) any later version.
53
--
54
--  This program is distributed in the hope that it will be useful,
55
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
56
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
57
--  GNU General Public License for more details.
58
--
59
--  You should have received a copy of the GNU General Public License
60
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
61
--
62
--===========================================================================--
63
--                                                                           --
64
--                             Revision History                              --
65
--                                                                           --
66
--===========================================================================--
67
-- Version Author     Date        Description
68
-- 0.1     John Kent  2003-05-05  Initial version
69
-- 0.2     John kent  2010-08-09  Updated header & GPL information
70
--
71
library ieee;
72
use ieee.std_logic_1164.all;
73
use ieee.std_logic_unsigned.all;
74
 
75
entity trap is
76
        port (
77
         clk        : in  std_logic;
78
    rst        : in  std_logic;
79
    cs         : in  std_logic;
80
    rw         : in  std_logic;
81
         vma        : in  std_logic;
82
    addr       : in  std_logic_vector(15 downto 0);
83
    data_in    : in  std_logic_vector(7 downto 0);
84
         data_out   : out std_logic_vector(7 downto 0);
85
         irq        : out std_logic
86
  );
87
end;
88
 
89
architecture trap_arch of trap is
90
 
91
--
92
-- Trap registers
93
--
94
signal comp_addr_hi : std_logic_vector(7 downto 0);
95
signal comp_addr_lo : std_logic_vector(7 downto 0);
96
signal qual_addr_hi : std_logic_vector(7 downto 0);
97
signal qual_addr_lo : std_logic_vector(7 downto 0);
98
signal comp_data    : std_logic_vector(7 downto 0);
99
signal qual_data    : std_logic_vector(7 downto 0);
100
signal comp_ctrl    : std_logic_vector(7 downto 0);
101
signal qual_ctrl    : std_logic_vector(7 downto 0);
102
signal match_flag   : std_logic;
103
begin
104
 
105
 
106
--------------------------------
107
--
108
-- write control registers
109
--
110
--------------------------------
111
trap_write : process( clk, rst, cs, rw, addr, data_in,
112
                      comp_addr_hi, comp_addr_lo, comp_data, comp_ctrl,
113
                      qual_addr_hi, qual_addr_lo, qual_data, qual_ctrl )
114
begin
115
  if clk'event and clk = '0' then
116
    if rst = '1' then
117
                  comp_addr_hi <= "00000000";
118
                  comp_addr_lo <= "00000000";
119
                  comp_data    <= "00000000";
120
                  comp_ctrl    <= "00000000";
121
                  qual_addr_hi <= "00000000";
122
                  qual_addr_lo <= "00000000";
123
                  qual_data    <= "00000000";
124
                  qual_ctrl    <= "00000000";
125
    elsif cs = '1' and rw = '0' then
126
           case addr(2 downto 0) is
127
                when "000" =>
128
                  comp_addr_hi <= data_in;
129
                  comp_addr_lo <= comp_addr_lo;
130
                  comp_data    <= comp_data;
131
                  comp_ctrl    <= comp_ctrl;
132
                  qual_addr_hi <= qual_addr_hi;
133
                  qual_addr_lo <= qual_addr_lo;
134
                  qual_data    <= qual_data;
135
                  qual_ctrl    <= qual_ctrl;
136
                when "001" =>
137
                  comp_addr_hi <= comp_addr_hi;
138
                  comp_addr_lo <= data_in;
139
                  comp_data    <= comp_data;
140
                  comp_ctrl    <= comp_ctrl;
141
                  qual_addr_hi <= qual_addr_hi;
142
                  qual_addr_lo <= qual_addr_lo;
143
                  qual_data    <= qual_data;
144
                  qual_ctrl    <= qual_ctrl;
145
                when "010" =>
146
                  comp_addr_hi <= comp_addr_hi;
147
                  comp_addr_lo <= comp_addr_lo;
148
                  comp_data    <= data_in;
149
                  comp_ctrl    <= comp_ctrl;
150
                  qual_addr_hi <= qual_addr_hi;
151
                  qual_addr_lo <= qual_addr_lo;
152
                  qual_data    <= qual_data;
153
                  qual_ctrl    <= qual_ctrl;
154
                when "011" =>
155
                  comp_addr_hi <= comp_addr_hi;
156
                  comp_addr_lo <= comp_addr_lo;
157
                  comp_data    <= comp_data;
158
                  comp_ctrl    <= data_in;
159
                  qual_addr_hi <= qual_addr_hi;
160
                  qual_addr_lo <= qual_addr_lo;
161
                  qual_data    <= qual_data;
162
                  qual_ctrl    <= qual_ctrl;
163
                when "100" =>
164
                  comp_addr_hi <= comp_addr_hi;
165
                  comp_addr_lo <= comp_addr_lo;
166
                  comp_data    <= comp_data;
167
                  comp_ctrl    <= comp_ctrl;
168
                  qual_addr_hi <= data_in;
169
                  qual_addr_lo <= qual_addr_lo;
170
                  qual_data    <= qual_data;
171
                  qual_ctrl    <= qual_ctrl;
172
                when "101" =>
173
                  comp_addr_hi <= comp_addr_hi;
174
                  comp_addr_lo <= comp_addr_lo;
175
                  comp_data    <= comp_data;
176
                  comp_ctrl    <= comp_ctrl;
177
                  qual_addr_hi <= qual_addr_hi;
178
                  qual_addr_lo <= data_in;
179
                  qual_data    <= qual_data;
180
                  qual_ctrl    <= qual_ctrl;
181
                when "110" =>
182
                  comp_addr_hi <= comp_addr_hi;
183
                  comp_addr_lo <= comp_addr_lo;
184
                  comp_data    <= comp_data;
185
                  comp_ctrl    <= comp_ctrl;
186
                  qual_addr_hi <= qual_addr_hi;
187
                  qual_addr_lo <= qual_addr_lo;
188
                  qual_data    <= data_in;
189
                  qual_ctrl    <= qual_ctrl;
190
--              when "111" =>
191
      when others =>
192
                  comp_addr_hi <= comp_addr_hi;
193
                  comp_addr_lo <= comp_addr_lo;
194
                  comp_data    <= comp_data;
195
                  comp_ctrl    <= comp_ctrl;
196
                  qual_addr_hi <= qual_addr_hi;
197
                  qual_addr_lo <= qual_addr_lo;
198
                  qual_data    <= qual_data;
199
                  qual_ctrl    <= data_in;
200
                end case;
201
         else
202
                  comp_addr_hi <= comp_addr_hi;
203
                  comp_addr_lo <= comp_addr_lo;
204
                  comp_data    <= comp_data;
205
                  comp_ctrl    <= comp_ctrl;
206
                  qual_addr_hi <= qual_addr_hi;
207
                  qual_addr_lo <= qual_addr_lo;
208
                  qual_data    <= qual_data;
209
                  qual_ctrl    <= qual_ctrl;
210
         end if;
211
  end if;
212
end process;
213
 
214
--
215
-- trap data output mux
216
--
217
trap_read : process( addr,
218
                     comp_addr_hi, comp_addr_lo, comp_data, comp_ctrl,
219
                     qual_addr_hi, qual_addr_lo, qual_data, qual_ctrl,
220
                                                        match_flag )
221
begin
222
   case addr(2 downto 0) is
223
        when "000" =>
224
           data_out <= comp_addr_hi;
225
        when "001" =>
226
           data_out <= comp_addr_lo;
227
        when "010" =>
228
           data_out <= comp_data;
229
        when "011" =>
230
           data_out <= comp_ctrl;
231
        when "100" =>
232
           data_out <= qual_addr_hi;
233
        when "101" =>
234
           data_out <= qual_addr_lo;
235
        when "110" =>
236
           data_out <= qual_data;
237
--      when "111" =>
238
   when others =>
239
           data_out(6 downto 0) <= qual_ctrl(6 downto 0);
240
                data_out(7) <= match_flag;
241
        end case;
242
end process;
243
 
244
 
245
--
246
-- Trap hardware
247
--
248
trap_match : process( Clk, rst, cs, rw, addr, vma, match_flag, data_in,
249
                      comp_addr_hi, comp_addr_lo, comp_data, comp_ctrl,
250
                                                         qual_addr_hi, qual_addr_lo, qual_data, qual_ctrl)
251
variable match         : std_logic;
252
variable match_addr_hi : std_logic;
253
variable match_addr_lo : std_logic;
254
variable match_data    : std_logic;
255
variable match_ctrl    : std_logic;
256
 
257
begin
258
  match_addr_hi :=
259
           ((comp_addr_hi(7) xor addr(15)  ) and qual_addr_hi(7) ) or
260
                     ((comp_addr_hi(6) xor addr(14)  ) and qual_addr_hi(6) ) or
261
                     ((comp_addr_hi(5) xor addr(13)  ) and qual_addr_hi(5) ) or
262
                     ((comp_addr_hi(4) xor addr(12)  ) and qual_addr_hi(4) ) or
263
                     ((comp_addr_hi(3) xor addr(11)  ) and qual_addr_hi(3) ) or
264
                     ((comp_addr_hi(2) xor addr(10)  ) and qual_addr_hi(2) ) or
265
                     ((comp_addr_hi(1) xor addr( 9)  ) and qual_addr_hi(1) ) or
266
                     ((comp_addr_hi(0) xor addr( 8)  ) and qual_addr_hi(0) );
267
  match_addr_lo :=
268
                     ((comp_addr_lo(7) xor addr( 7)  ) and qual_addr_lo(7) ) or
269
                     ((comp_addr_lo(6) xor addr( 6)  ) and qual_addr_lo(6) ) or
270
                     ((comp_addr_lo(5) xor addr( 5)  ) and qual_addr_lo(5) ) or
271
                     ((comp_addr_lo(4) xor addr( 4)  ) and qual_addr_lo(4) ) or
272
                     ((comp_addr_lo(3) xor addr( 3)  ) and qual_addr_lo(3) ) or
273
                     ((comp_addr_lo(2) xor addr( 2)  ) and qual_addr_lo(2) ) or
274
                     ((comp_addr_lo(1) xor addr( 1)  ) and qual_addr_lo(1) ) or
275
                     ((comp_addr_lo(0) xor addr( 0)  ) and qual_addr_lo(0) );
276
  match_data :=
277
           ((comp_data(7)    xor data_in(7)) and qual_data(7)    ) or
278
           ((comp_data(6)    xor data_in(6)) and qual_data(6)    ) or
279
           ((comp_data(5)    xor data_in(5)) and qual_data(5)    ) or
280
           ((comp_data(4)    xor data_in(4)) and qual_data(4)    ) or
281
           ((comp_data(3)    xor data_in(3)) and qual_data(3)    ) or
282
           ((comp_data(2)    xor data_in(2)) and qual_data(2)    ) or
283
           ((comp_data(1)    xor data_in(1)) and qual_data(1)    ) or
284
           ((comp_data(0)    xor data_in(0)) and qual_data(0)    );
285
  match_ctrl :=
286
           ((comp_ctrl(0)    xor rw        ) and qual_ctrl(0)    ) or
287
           ((comp_ctrl(1)    xor vma       ) and qual_ctrl(1)    );
288
 
289
  match := not ( match_addr_hi or match_addr_lo or match_data or match_ctrl);
290
 
291
         if rst = '1' then
292
                match_flag <= '0';
293
    elsif clk'event and clk = '0' then
294
      if cs = '1' and rw = '0' then
295
                  match_flag <= '0';
296
      else
297
                  if match = comp_ctrl(7) then
298
                    match_flag <= '1';
299
                  end if;
300
                end if;
301
    end if;
302
         irq <= match_flag and qual_ctrl(7);
303
  end process;
304
 
305
end trap_arch;
306
 

powered by: WebSVN 2.1.0

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