1 |
2 |
alfik |
/*
|
2 |
|
|
* Copyright (c) 2014, Aleksander Osman
|
3 |
|
|
* All rights reserved.
|
4 |
|
|
*
|
5 |
|
|
* Redistribution and use in source and binary forms, with or without
|
6 |
|
|
* modification, are permitted provided that the following conditions are met:
|
7 |
|
|
*
|
8 |
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
9 |
|
|
* list of conditions and the following disclaimer.
|
10 |
|
|
*
|
11 |
|
|
* * Redistributions in binary form must reproduce the above copyright notice,
|
12 |
|
|
* this list of conditions and the following disclaimer in the documentation
|
13 |
|
|
* and/or other materials provided with the distribution.
|
14 |
|
|
*
|
15 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
16 |
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
17 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
18 |
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
19 |
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
20 |
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
21 |
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
22 |
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
23 |
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
24 |
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
25 |
|
|
*/
|
26 |
|
|
|
27 |
|
|
`include "defines.v"
|
28 |
|
|
|
29 |
|
|
//PARSED_COMMENTS: this file contains parsed script comments
|
30 |
|
|
|
31 |
|
|
module exception(
|
32 |
|
|
input clk,
|
33 |
|
|
input rst_n,
|
34 |
|
|
|
35 |
|
|
//exception indicators
|
36 |
|
|
input dec_gp_fault,
|
37 |
|
|
input dec_ud_fault,
|
38 |
|
|
input dec_pf_fault,
|
39 |
|
|
|
40 |
|
|
input rd_seg_gp_fault,
|
41 |
|
|
input rd_descriptor_gp_fault,
|
42 |
|
|
input rd_seg_ss_fault,
|
43 |
|
|
input rd_io_allow_fault,
|
44 |
|
|
input rd_ss_esp_from_tss_fault,
|
45 |
|
|
|
46 |
|
|
input exe_div_exception,
|
47 |
|
|
input exe_trigger_gp_fault,
|
48 |
|
|
input exe_trigger_ts_fault,
|
49 |
|
|
input exe_trigger_ss_fault,
|
50 |
|
|
input exe_trigger_np_fault,
|
51 |
|
|
input exe_trigger_nm_fault,
|
52 |
|
|
input exe_trigger_db_fault,
|
53 |
|
|
input exe_trigger_pf_fault,
|
54 |
|
|
input exe_bound_fault,
|
55 |
|
|
input exe_load_seg_gp_fault,
|
56 |
|
|
input exe_load_seg_ss_fault,
|
57 |
|
|
input exe_load_seg_np_fault,
|
58 |
|
|
|
59 |
|
|
input wr_debug_init,
|
60 |
|
|
|
61 |
|
|
input wr_new_push_ss_fault,
|
62 |
|
|
input wr_string_es_fault,
|
63 |
|
|
input wr_push_ss_fault,
|
64 |
|
|
|
65 |
|
|
//from memory
|
66 |
|
|
input read_ac_fault,
|
67 |
|
|
input read_page_fault,
|
68 |
|
|
|
69 |
|
|
input write_ac_fault,
|
70 |
|
|
input write_page_fault,
|
71 |
|
|
|
72 |
|
|
input [15:0] tlb_code_pf_error_code,
|
73 |
|
|
input [15:0] tlb_check_pf_error_code,
|
74 |
|
|
input [15:0] tlb_write_pf_error_code,
|
75 |
|
|
input [15:0] tlb_read_pf_error_code,
|
76 |
|
|
|
77 |
|
|
//wr_int
|
78 |
|
|
input wr_int,
|
79 |
|
|
input wr_int_soft_int,
|
80 |
|
|
input wr_int_soft_int_ib,
|
81 |
|
|
input [7:0] wr_int_vector,
|
82 |
|
|
|
83 |
|
|
input wr_exception_external_set,
|
84 |
|
|
input wr_exception_finished,
|
85 |
|
|
|
86 |
|
|
//eip
|
87 |
|
|
input [31:0] eip,
|
88 |
|
|
input [31:0] dec_eip,
|
89 |
|
|
input [31:0] rd_eip,
|
90 |
|
|
input [31:0] exe_eip,
|
91 |
|
|
input [31:0] wr_eip,
|
92 |
|
|
|
93 |
|
|
input [3:0] rd_consumed,
|
94 |
|
|
input [3:0] exe_consumed,
|
95 |
|
|
input [3:0] wr_consumed,
|
96 |
|
|
|
97 |
|
|
//pipeline
|
98 |
|
|
input rd_dec_is_front,
|
99 |
|
|
input rd_is_front,
|
100 |
|
|
input exe_is_front,
|
101 |
|
|
input wr_is_front,
|
102 |
|
|
|
103 |
|
|
//interrupt
|
104 |
|
|
input [7:0] interrupt_vector,
|
105 |
|
|
output reg interrupt_done,
|
106 |
|
|
|
107 |
|
|
//input
|
108 |
|
|
input wr_interrupt_possible,
|
109 |
|
|
input wr_string_in_progress_final,
|
110 |
|
|
input wr_is_esp_speculative,
|
111 |
|
|
|
112 |
|
|
input real_mode,
|
113 |
|
|
|
114 |
|
|
input [15:0] rd_error_code,
|
115 |
|
|
input [15:0] exe_error_code,
|
116 |
|
|
input [15:0] wr_error_code,
|
117 |
|
|
|
118 |
|
|
//output
|
119 |
|
|
output exc_dec_reset,
|
120 |
|
|
output exc_micro_reset,
|
121 |
|
|
output exc_rd_reset,
|
122 |
|
|
output exc_exe_reset,
|
123 |
|
|
output exc_wr_reset,
|
124 |
|
|
|
125 |
|
|
output exc_restore_esp,
|
126 |
|
|
output exc_set_rflag,
|
127 |
|
|
output exc_debug_start,
|
128 |
|
|
|
129 |
|
|
output exc_init,
|
130 |
|
|
output reg exc_load,
|
131 |
|
|
output reg [31:0] exc_eip,
|
132 |
|
|
|
133 |
|
|
output [7:0] exc_vector,
|
134 |
|
|
output reg [15:0] exc_error_code,
|
135 |
|
|
output reg exc_push_error,
|
136 |
|
|
output reg exc_soft_int,
|
137 |
|
|
output reg exc_soft_int_ib,
|
138 |
|
|
|
139 |
|
|
output exc_pf_read,
|
140 |
|
|
output exc_pf_write,
|
141 |
|
|
output exc_pf_code,
|
142 |
|
|
output exc_pf_check
|
143 |
|
|
);
|
144 |
|
|
|
145 |
|
|
//------------------------------------------------------------------------------
|
146 |
|
|
|
147 |
|
|
//------------------------------------------------------------------------------
|
148 |
|
|
|
149 |
|
|
wire exception_init;
|
150 |
|
|
wire exception_start;
|
151 |
|
|
|
152 |
|
|
wire active_dec;
|
153 |
|
|
wire active_rd;
|
154 |
|
|
wire active_exe;
|
155 |
|
|
wire active_wr;
|
156 |
|
|
|
157 |
|
|
wire [31:0] exception_eip_from_wr;
|
158 |
|
|
|
159 |
|
|
//------------------------------------------------------------------------------
|
160 |
|
|
|
161 |
|
|
reg external;
|
162 |
|
|
reg [1:0] count;
|
163 |
|
|
reg [1:0] last_type;
|
164 |
|
|
|
165 |
|
|
reg [31:0] trap_eip;
|
166 |
|
|
|
167 |
|
|
reg shutdown;
|
168 |
|
|
|
169 |
|
|
reg interrupt_load;
|
170 |
|
|
reg interrupt_string_in_progress;
|
171 |
|
|
|
172 |
|
|
reg [8:0] exc_vector_full;
|
173 |
|
|
|
174 |
|
|
//------------------------------------------------------------------------------
|
175 |
|
|
|
176 |
|
|
wire [7:0] vector;
|
177 |
|
|
wire [15:0] error_code;
|
178 |
|
|
wire push_error;
|
179 |
|
|
|
180 |
|
|
wire class_trap;
|
181 |
|
|
wire class_abort;
|
182 |
|
|
|
183 |
|
|
wire [1:0] exception_type;
|
184 |
|
|
|
185 |
|
|
wire shutdown_start;
|
186 |
|
|
|
187 |
|
|
//------------------------------------------------------------------------------
|
188 |
|
|
|
189 |
|
|
assign exc_vector = exc_vector_full[7:0];
|
190 |
|
|
|
191 |
|
|
//------------------------------------------------------------------------------
|
192 |
|
|
|
193 |
|
|
assign exception_init = exc_vector_full[8];
|
194 |
|
|
|
195 |
|
|
assign exc_init = exception_init || wr_interrupt_possible || interrupt_done || wr_debug_init;
|
196 |
|
|
|
197 |
|
|
assign active_dec = (dec_gp_fault || dec_ud_fault || dec_pf_fault) &&
|
198 |
|
|
rd_dec_is_front && ~(exc_init);
|
199 |
|
|
assign active_rd = (rd_seg_gp_fault || rd_descriptor_gp_fault || rd_seg_ss_fault || rd_io_allow_fault ||
|
200 |
|
|
rd_ss_esp_from_tss_fault || read_ac_fault || read_page_fault) &&
|
201 |
|
|
rd_is_front && ~(exc_init);
|
202 |
|
|
assign active_exe = (exe_div_exception || exe_trigger_gp_fault || exe_trigger_ts_fault || exe_trigger_ss_fault ||
|
203 |
|
|
exe_trigger_np_fault || exe_trigger_nm_fault || exe_trigger_db_fault || exe_trigger_pf_fault ||
|
204 |
|
|
exe_bound_fault || exe_load_seg_gp_fault || exe_load_seg_ss_fault || exe_load_seg_np_fault) &&
|
205 |
|
|
exe_is_front && ~(exc_init);
|
206 |
|
|
assign active_wr = (wr_new_push_ss_fault || wr_string_es_fault || wr_push_ss_fault || write_ac_fault ||
|
207 |
|
|
write_page_fault || wr_int) &&
|
208 |
|
|
wr_is_front && ~(exc_init);
|
209 |
|
|
|
210 |
|
|
assign exc_pf_read = active_rd && read_page_fault;
|
211 |
|
|
assign exc_pf_write= active_wr && write_page_fault;
|
212 |
|
|
assign exc_pf_code = active_dec && dec_pf_fault;
|
213 |
|
|
assign exc_pf_check= active_exe && exe_trigger_pf_fault;
|
214 |
|
|
|
215 |
|
|
//------------------------------------------------------------------------------
|
216 |
|
|
|
217 |
|
|
always @(posedge clk or negedge rst_n) begin
|
218 |
|
|
if(rst_n == 1'b0) exc_vector_full <= 9'd0;
|
219 |
|
|
|
220 |
|
|
else if(active_wr && wr_new_push_ss_fault) exc_vector_full <= { 1'b1, `EXCEPTION_SS };
|
221 |
|
|
else if(active_wr && wr_string_es_fault) exc_vector_full <= { 1'b1, `EXCEPTION_GP };
|
222 |
|
|
else if(active_wr && wr_push_ss_fault) exc_vector_full <= { 1'b1, `EXCEPTION_SS };
|
223 |
|
|
else if(active_wr && write_ac_fault) exc_vector_full <= { 1'b1, `EXCEPTION_AC };
|
224 |
|
|
else if(active_wr && write_page_fault) exc_vector_full <= { 1'b1, `EXCEPTION_PF };
|
225 |
|
|
|
226 |
|
|
else if(active_wr && wr_int) exc_vector_full <= { 1'b0, wr_int_vector };
|
227 |
|
|
|
228 |
|
|
else if(active_exe && exe_div_exception) exc_vector_full <= { 1'b1, `EXCEPTION_DE };
|
229 |
|
|
else if(active_exe && exe_trigger_gp_fault) exc_vector_full <= { 1'b1, `EXCEPTION_GP };
|
230 |
|
|
else if(active_exe && exe_trigger_ts_fault) exc_vector_full <= { 1'b1, `EXCEPTION_TS };
|
231 |
|
|
else if(active_exe && exe_trigger_ss_fault) exc_vector_full <= { 1'b1, `EXCEPTION_SS };
|
232 |
|
|
else if(active_exe && exe_trigger_np_fault) exc_vector_full <= { 1'b1, `EXCEPTION_NP };
|
233 |
|
|
else if(active_exe && exe_trigger_nm_fault) exc_vector_full <= { 1'b1, `EXCEPTION_NM };
|
234 |
|
|
else if(active_exe && exe_trigger_db_fault) exc_vector_full <= { 1'b1, `EXCEPTION_DB };
|
235 |
|
|
else if(active_exe && exe_trigger_pf_fault) exc_vector_full <= { 1'b1, `EXCEPTION_PF };
|
236 |
|
|
else if(active_exe && exe_bound_fault) exc_vector_full <= { 1'b1, `EXCEPTION_BR };
|
237 |
|
|
else if(active_exe && exe_load_seg_gp_fault) exc_vector_full <= { 1'b1, `EXCEPTION_GP };
|
238 |
|
|
else if(active_exe && exe_load_seg_ss_fault) exc_vector_full <= { 1'b1, `EXCEPTION_SS };
|
239 |
|
|
else if(active_exe && exe_load_seg_np_fault) exc_vector_full <= { 1'b1, `EXCEPTION_NP };
|
240 |
|
|
|
241 |
|
|
else if(active_rd && rd_seg_gp_fault) exc_vector_full <= { 1'b1, `EXCEPTION_GP };
|
242 |
|
|
else if(active_rd && rd_descriptor_gp_fault) exc_vector_full <= { 1'b1, `EXCEPTION_GP };
|
243 |
|
|
else if(active_rd && rd_seg_ss_fault) exc_vector_full <= { 1'b1, `EXCEPTION_SS };
|
244 |
|
|
else if(active_rd && rd_io_allow_fault) exc_vector_full <= { 1'b1, `EXCEPTION_GP };
|
245 |
|
|
else if(active_rd && rd_ss_esp_from_tss_fault) exc_vector_full <= { 1'b1, `EXCEPTION_TS };
|
246 |
|
|
else if(active_rd && read_ac_fault) exc_vector_full <= { 1'b1, `EXCEPTION_AC };
|
247 |
|
|
else if(active_rd && read_page_fault) exc_vector_full <= { 1'b1, `EXCEPTION_PF };
|
248 |
|
|
|
249 |
|
|
else if(active_dec && dec_gp_fault) exc_vector_full <= { 1'b1, `EXCEPTION_GP };
|
250 |
|
|
else if(active_dec && dec_ud_fault) exc_vector_full <= { 1'b1, `EXCEPTION_UD };
|
251 |
|
|
else if(active_dec && dec_pf_fault) exc_vector_full <= { 1'b1, `EXCEPTION_PF };
|
252 |
|
|
|
253 |
|
|
else exc_vector_full <= exc_vector_full_to_reg; //set if(exception_init || wr_debug_init || interrupt_done)
|
254 |
|
|
end
|
255 |
|
|
|
256 |
|
|
always @(posedge clk or negedge rst_n) begin
|
257 |
|
|
if(rst_n == 1'b0) exc_error_code <= 16'd0;
|
258 |
|
|
|
259 |
|
|
else if(active_wr && write_ac_fault) exc_error_code <= 16'd0;
|
260 |
|
|
else if(active_wr && write_page_fault) exc_error_code <= tlb_write_pf_error_code;
|
261 |
|
|
else if(active_wr) exc_error_code <= wr_error_code;
|
262 |
|
|
|
263 |
|
|
else if(active_exe && exe_trigger_pf_fault) exc_error_code <= tlb_check_pf_error_code;
|
264 |
|
|
else if(active_exe) exc_error_code <= exe_error_code;
|
265 |
|
|
|
266 |
|
|
else if(active_rd && read_ac_fault) exc_error_code <= 16'd0;
|
267 |
|
|
else if(active_rd && read_page_fault) exc_error_code <= tlb_read_pf_error_code;
|
268 |
|
|
else if(active_rd) exc_error_code <= rd_error_code;
|
269 |
|
|
|
270 |
|
|
else if(active_dec && dec_pf_fault) exc_error_code <= tlb_code_pf_error_code;
|
271 |
|
|
else if(active_dec) exc_error_code <= 16'd0;
|
272 |
|
|
|
273 |
|
|
else exc_error_code <= exc_error_code_to_reg; //set if(exception_init || wr_debug_init || interrupt_done)
|
274 |
|
|
end
|
275 |
|
|
|
276 |
|
|
always @(posedge clk or negedge rst_n) begin
|
277 |
|
|
if(rst_n == 1'b0) exc_push_error <= `FALSE;
|
278 |
|
|
else if(active_wr && wr_int) exc_push_error <= `FALSE;
|
279 |
|
|
else exc_push_error <= exc_push_error_to_reg;
|
280 |
|
|
end
|
281 |
|
|
|
282 |
|
|
always @(posedge clk or negedge rst_n) begin
|
283 |
|
|
if(rst_n == 1'b0) exc_soft_int <= `FALSE;
|
284 |
|
|
else if(active_wr && wr_int) exc_soft_int <= wr_int_soft_int;
|
285 |
|
|
else exc_soft_int <= exc_soft_int_to_reg;
|
286 |
|
|
end
|
287 |
|
|
|
288 |
|
|
always @(posedge clk or negedge rst_n) begin
|
289 |
|
|
if(rst_n == 1'b0) exc_soft_int_ib <= `FALSE;
|
290 |
|
|
else if(active_wr && wr_int) exc_soft_int_ib <= wr_int_soft_int_ib;
|
291 |
|
|
else exc_soft_int_ib <= exc_soft_int_ib_to_reg;
|
292 |
|
|
end
|
293 |
|
|
|
294 |
|
|
always @(posedge clk or negedge rst_n) begin
|
295 |
|
|
if(rst_n == 1'b0) exc_load <= `FALSE;
|
296 |
|
|
else exc_load <= exception_start || interrupt_done;
|
297 |
|
|
end
|
298 |
|
|
|
299 |
|
|
//------------------------------------------------------------------------------
|
300 |
|
|
|
301 |
|
|
//------------------------------------------------------------------------------
|
302 |
|
|
|
303 |
|
|
always @(posedge clk or negedge rst_n) begin
|
304 |
|
|
if(rst_n == 1'b0) external <= 1'b0;
|
305 |
|
|
else if(wr_exception_external_set) external <= `TRUE;
|
306 |
|
|
else if(wr_exception_finished) external <= `FALSE;
|
307 |
|
|
else external <= external_to_reg;
|
308 |
|
|
end
|
309 |
|
|
|
310 |
|
|
always @(posedge clk or negedge rst_n) begin
|
311 |
|
|
if(rst_n == 1'b0) count <= 2'b0;
|
312 |
|
|
else if(wr_exception_finished) count <= 2'd0;
|
313 |
|
|
else count <= count_to_reg;
|
314 |
|
|
end
|
315 |
|
|
|
316 |
|
|
always @(posedge clk or negedge rst_n) begin
|
317 |
|
|
if(rst_n == 1'b0) last_type <= 2'b0;
|
318 |
|
|
else last_type <= last_type_to_reg;
|
319 |
|
|
end
|
320 |
|
|
|
321 |
|
|
assign exception_eip_from_wr = wr_eip - { 28'd0, wr_consumed };
|
322 |
|
|
|
323 |
|
|
always @(posedge clk or negedge rst_n) begin
|
324 |
|
|
if(rst_n == 1'b0) exc_eip <= 32'd0;
|
325 |
|
|
else if(active_wr) exc_eip <= exception_eip_from_wr;
|
326 |
|
|
else if(active_exe) exc_eip <= exe_eip - { 28'd0, exe_consumed };
|
327 |
|
|
else if(active_rd) exc_eip <= rd_eip - { 28'd0, rd_consumed };
|
328 |
|
|
else if(active_dec) exc_eip <= eip;
|
329 |
|
|
else exc_eip <= exc_eip_to_reg;
|
330 |
|
|
end
|
331 |
|
|
|
332 |
|
|
always @(posedge clk or negedge rst_n) begin
|
333 |
|
|
if(rst_n == 1'b0) trap_eip <= 32'd0;
|
334 |
|
|
else if(active_wr) trap_eip <= wr_eip;
|
335 |
|
|
else if(active_exe) trap_eip <= exe_eip;
|
336 |
|
|
else if(active_rd) trap_eip <= rd_eip;
|
337 |
|
|
else if(active_dec) trap_eip <= dec_eip;
|
338 |
|
|
end
|
339 |
|
|
|
340 |
|
|
always @(posedge clk or negedge rst_n) begin
|
341 |
|
|
if(rst_n == 1'b0) shutdown <= `FALSE;
|
342 |
|
|
else shutdown <= shutdown_to_reg;
|
343 |
|
|
end
|
344 |
|
|
|
345 |
|
|
//------------------------------------------------------------------------------
|
346 |
|
|
|
347 |
|
|
assign vector = (wr_debug_init)? `EXCEPTION_DB : exc_vector_full[7:0];
|
348 |
|
|
|
349 |
|
|
assign error_code =
|
350 |
|
|
(real_mode)? 16'd0 :
|
351 |
|
|
(vector != `EXCEPTION_PF && vector != `EXCEPTION_DF)? { exc_error_code[15:1], external } :
|
352 |
|
|
exc_error_code;
|
353 |
|
|
|
354 |
|
|
assign push_error =
|
355 |
|
|
~(real_mode) && (
|
356 |
|
|
(vector == `EXCEPTION_DF) || (vector == `EXCEPTION_TS) || (vector == `EXCEPTION_NP) ||
|
357 |
|
|
(vector == `EXCEPTION_SS) || (vector == `EXCEPTION_GP) || (vector == `EXCEPTION_PF) ||
|
358 |
|
|
(vector == `EXCEPTION_AC));
|
359 |
|
|
|
360 |
|
|
assign class_trap = (vector == `EXCEPTION_BP) || (vector == `EXCEPTION_OF);
|
361 |
|
|
|
362 |
|
|
assign class_abort = (vector == `EXCEPTION_MC);
|
363 |
|
|
|
364 |
|
|
`define EXCEPTION_TYPE_BENIGN 2'd0
|
365 |
|
|
`define EXCEPTION_TYPE_CONTRIBUTORY 2'd1
|
366 |
|
|
`define EXCEPTION_TYPE_PAGE_FAULT 2'd2
|
367 |
|
|
`define EXCEPTION_TYPE_DOUBLE_FAULT 2'd3
|
368 |
|
|
|
369 |
|
|
assign exception_type =
|
370 |
|
|
(vector == `EXCEPTION_DE) || (vector >= `EXCEPTION_TS && vector <= `EXCEPTION_GP)? `EXCEPTION_TYPE_CONTRIBUTORY :
|
371 |
|
|
(vector == `EXCEPTION_DF)? `EXCEPTION_TYPE_DOUBLE_FAULT :
|
372 |
|
|
(vector == `EXCEPTION_PF)? `EXCEPTION_TYPE_PAGE_FAULT :
|
373 |
|
|
`EXCEPTION_TYPE_BENIGN;
|
374 |
|
|
|
375 |
|
|
assign shutdown_start = count > 2'd2 || (count > 2'd0 && last_type == `EXCEPTION_TYPE_DOUBLE_FAULT);
|
376 |
|
|
|
377 |
|
|
//------------------------------------------------------------------------------
|
378 |
|
|
|
379 |
|
|
// interrupt_vector[7:0], interrupt_done;
|
380 |
|
|
|
381 |
|
|
always @(posedge clk or negedge rst_n) begin
|
382 |
|
|
if(rst_n == 1'b0) interrupt_done <= `FALSE;
|
383 |
|
|
else if(wr_interrupt_possible) interrupt_done <= `TRUE;
|
384 |
|
|
else interrupt_done <= `FALSE;
|
385 |
|
|
end
|
386 |
|
|
|
387 |
|
|
always @(posedge clk or negedge rst_n) begin
|
388 |
|
|
if(rst_n == 1'b0) interrupt_load <= `FALSE;
|
389 |
|
|
else interrupt_load <= interrupt_done;
|
390 |
|
|
end
|
391 |
|
|
|
392 |
|
|
always @(posedge clk or negedge rst_n) begin
|
393 |
|
|
if(rst_n == 1'b0) interrupt_string_in_progress <= `FALSE;
|
394 |
|
|
else if(wr_interrupt_possible && wr_string_in_progress_final) interrupt_string_in_progress <= `TRUE;
|
395 |
|
|
else if(wr_interrupt_possible) interrupt_string_in_progress <= `FALSE;
|
396 |
|
|
end
|
397 |
|
|
|
398 |
|
|
assign exc_debug_start = exc_load && vector == `EXCEPTION_DB && interrupt_load == `FALSE;
|
399 |
|
|
|
400 |
|
|
/*******************************************************************************SCRIPT
|
401 |
|
|
|
402 |
|
|
NO_ALWAYS_BLOCK(exc_eip);
|
403 |
|
|
NO_ALWAYS_BLOCK(exc_error_code);
|
404 |
|
|
NO_ALWAYS_BLOCK(exc_push_error);
|
405 |
|
|
NO_ALWAYS_BLOCK(exc_soft_int);
|
406 |
|
|
NO_ALWAYS_BLOCK(exc_soft_int_ib);
|
407 |
|
|
NO_ALWAYS_BLOCK(exc_vector_full);
|
408 |
|
|
NO_ALWAYS_BLOCK(shutdown);
|
409 |
|
|
NO_ALWAYS_BLOCK(last_type);
|
410 |
|
|
NO_ALWAYS_BLOCK(count);
|
411 |
|
|
NO_ALWAYS_BLOCK(external);
|
412 |
|
|
|
413 |
|
|
*/
|
414 |
|
|
|
415 |
|
|
/*******************************************************************************SCRIPT
|
416 |
|
|
|
417 |
|
|
IF(exception_init || wr_debug_init);
|
418 |
|
|
//NOTE: exe_reset must in same cycle as exception_init (wr waits one cycle for wr_one_cycle_wait)
|
419 |
|
|
SET(exc_dec_reset);
|
420 |
|
|
SET(exc_micro_reset);
|
421 |
|
|
SET(exc_rd_reset);
|
422 |
|
|
SET(exc_exe_reset);
|
423 |
|
|
SET(exc_wr_reset);
|
424 |
|
|
|
425 |
|
|
IF(~(class_trap) && ~(class_abort));
|
426 |
|
|
|
427 |
|
|
IF(wr_is_esp_speculative); SET(exc_restore_esp); ENDIF();
|
428 |
|
|
// eip in exc_eip
|
429 |
|
|
|
430 |
|
|
IF(vector != `EXCEPTION_DB); SET(exc_set_rflag); ENDIF();
|
431 |
|
|
ELSE();
|
432 |
|
|
// trap
|
433 |
|
|
//esp no change needed
|
434 |
|
|
SAVE(exc_eip, trap_eip);
|
435 |
|
|
ENDIF();
|
436 |
|
|
|
437 |
|
|
IF(vector == `EXCEPTION_DB);
|
438 |
|
|
IF(wr_debug_init && ~(wr_string_in_progress_final)); SAVE(exc_eip, wr_eip); ENDIF();
|
439 |
|
|
IF(wr_debug_init && wr_string_in_progress_final); SAVE(exc_eip, exception_eip_from_wr); ENDIF();
|
440 |
|
|
// if not wr_debug_init -- eip already in exc_eip
|
441 |
|
|
ENDIF();
|
442 |
|
|
|
443 |
|
|
SAVE(external, `TRUE);
|
444 |
|
|
|
445 |
|
|
IF(shutdown_start == `FALSE && count > 2'd0 && exception_type != `EXCEPTION_TYPE_DOUBLE_FAULT && (
|
446 |
|
|
(last_type == `EXCEPTION_TYPE_CONTRIBUTORY && exception_type == `EXCEPTION_TYPE_CONTRIBUTORY) ||
|
447 |
|
|
(last_type == `EXCEPTION_TYPE_PAGE_FAULT && exception_type == `EXCEPTION_TYPE_CONTRIBUTORY) ||
|
448 |
|
|
(last_type == `EXCEPTION_TYPE_PAGE_FAULT && exception_type == `EXCEPTION_TYPE_PAGE_FAULT)));
|
449 |
|
|
|
450 |
|
|
SAVE(exc_vector_full, { 1'b1, `EXCEPTION_DF });
|
451 |
|
|
SAVE(exc_error_code, 16'd0);
|
452 |
|
|
ELSE();
|
453 |
|
|
|
454 |
|
|
IF(shutdown_start == `FALSE);
|
455 |
|
|
SAVE(last_type, exception_type);
|
456 |
|
|
SAVE(count, count + 2'd1);
|
457 |
|
|
|
458 |
|
|
SAVE(exc_push_error, push_error);
|
459 |
|
|
SAVE(exc_error_code, error_code);
|
460 |
|
|
|
461 |
|
|
SAVE(exc_soft_int, `FALSE);
|
462 |
|
|
SAVE(exc_soft_int_ib, `FALSE);
|
463 |
|
|
|
464 |
|
|
// finish this state
|
465 |
|
|
SAVE(exc_vector_full, { 1'b0, vector });
|
466 |
|
|
|
467 |
|
|
SET(exception_start);
|
468 |
|
|
ENDIF();
|
469 |
|
|
ENDIF();
|
470 |
|
|
|
471 |
|
|
IF(shutdown_start);
|
472 |
|
|
// finish this state
|
473 |
|
|
SAVE(exc_vector_full, { 1'b0, vector });
|
474 |
|
|
|
475 |
|
|
SAVE(shutdown, `TRUE);
|
476 |
|
|
ENDIF();
|
477 |
|
|
|
478 |
|
|
ENDIF();
|
479 |
|
|
|
480 |
|
|
*/
|
481 |
|
|
|
482 |
|
|
/*******************************************************************************SCRIPT
|
483 |
|
|
|
484 |
|
|
IF(shutdown);
|
485 |
|
|
|
486 |
|
|
// keep pipeline reset
|
487 |
|
|
SET(exc_dec_reset);
|
488 |
|
|
SET(exc_micro_reset);
|
489 |
|
|
SET(exc_rd_reset);
|
490 |
|
|
SET(exc_exe_reset);
|
491 |
|
|
SET(exc_wr_reset);
|
492 |
|
|
ENDIF();
|
493 |
|
|
|
494 |
|
|
*/
|
495 |
|
|
|
496 |
|
|
/*******************************************************************************SCRIPT
|
497 |
|
|
|
498 |
|
|
IF(interrupt_done);
|
499 |
|
|
|
500 |
|
|
SAVE(external, `TRUE);
|
501 |
|
|
|
502 |
|
|
SAVE(exc_vector_full, { 1'b0, interrupt_vector });
|
503 |
|
|
|
504 |
|
|
SAVE(exc_push_error, `FALSE);
|
505 |
|
|
SAVE(exc_error_code, 16'd0);
|
506 |
|
|
|
507 |
|
|
SAVE(exc_eip, (interrupt_string_in_progress)? exception_eip_from_wr : wr_eip);
|
508 |
|
|
|
509 |
|
|
SAVE(exc_soft_int, `FALSE);
|
510 |
|
|
SAVE(exc_soft_int_ib, `FALSE);
|
511 |
|
|
|
512 |
|
|
SET(exc_dec_reset);
|
513 |
|
|
SET(exc_micro_reset);
|
514 |
|
|
SET(exc_rd_reset);
|
515 |
|
|
SET(exc_exe_reset);
|
516 |
|
|
SET(exc_wr_reset);
|
517 |
|
|
ENDIF();
|
518 |
|
|
|
519 |
|
|
*/
|
520 |
|
|
|
521 |
|
|
//------------------------------------------------------------------------------
|
522 |
|
|
|
523 |
|
|
`include "autogen/exception.v"
|
524 |
|
|
|
525 |
|
|
|
526 |
|
|
endmodule
|