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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [rtl/] [ao486/] [pipeline/] [write_register.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
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
module write_register(
30
    input               clk,
31
    input               rst_n,
32
 
33
 
34
 
35
    //general input
36
    input       [63:0]  glob_descriptor,
37
    input       [31:0]  glob_param_1,
38
 
39
    //wr input
40
    input               wr_is_8bit,
41
    input               wr_operand_32bit,
42
    input       [15:0]  wr_decoder,
43
    input       [2:0]   wr_modregrm_reg,
44
    input       [2:0]   wr_modregrm_rm,
45
 
46
    input               wr_clear_rflag,
47
 
48
    //segment control
49
    input       [15:0]  wr_seg_sel,
50
    input       [1:0]   wr_seg_rpl,
51
    input               wr_seg_cache_valid,
52
 
53
    input               write_seg_sel,
54
    input               write_seg_rpl,
55
    input               write_seg_cache,
56
    input               write_seg_cache_valid,
57
    input       [63:0]  wr_seg_cache_mask,
58
 
59
    input               wr_validate_seg_regs,
60
 
61
    input               write_system_touch,
62
    input               write_system_busy_tss,
63
 
64
    //exe exception write
65
    input               dr6_bd_set,
66
 
67
    //exception input
68
    input               exc_set_rflag,
69
    input               exc_debug_start,
70
    input               exc_pf_read,
71
    input               exc_pf_write,
72
    input               exc_pf_code,
73
    input               exc_pf_check,
74
    input               exc_restore_esp,
75
 
76
    input       [31:0]  wr_esp_prev,
77
 
78
    //cr2 input
79
    input       [31:0]  tlb_code_pf_cr2,
80
    input       [31:0]  tlb_write_pf_cr2,
81
    input       [31:0]  tlb_read_pf_cr2,
82
    input       [31:0]  tlb_check_pf_cr2,
83
 
84
    //debug input
85
    input       [3:0]   wr_debug_code_reg,
86
    input       [3:0]   wr_debug_write_reg,
87
    input       [3:0]   wr_debug_read_reg,
88
    input               wr_debug_step_reg,
89
    input               wr_debug_task_reg,
90
 
91
    //write reg
92
    input               write_eax,
93
    input               write_regrm,
94
 
95
    //write reg options
96
    input               wr_dst_is_rm,
97
    input               wr_dst_is_reg,
98
    input               wr_dst_is_implicit_reg,
99
    input               wr_regrm_word,
100
    input               wr_regrm_dword,
101
 
102
    //write reg data
103
    input       [31:0]  result,
104
 
105
    //output
106
    output      [1:0]   cpl,
107
 
108
    output              protected_mode,
109
    output              v8086_mode,
110
    output              real_mode,
111
 
112
    output              io_allow_check_needed,
113
 
114
    output      [2:0]   debug_len0,
115
    output      [2:0]   debug_len1,
116
    output      [2:0]   debug_len2,
117
    output      [2:0]   debug_len3,
118
 
119
    //registers input
120
 
121
    input       [31:0]  eax_to_reg,
122
    input       [31:0]  ebx_to_reg,
123
    input       [31:0]  ecx_to_reg,
124
    input       [31:0]  edx_to_reg,
125
    input       [31:0]  esi_to_reg,
126
    input       [31:0]  edi_to_reg,
127
    input       [31:0]  ebp_to_reg,
128
    input       [31:0]  esp_to_reg,
129
 
130
    input               cr0_pe_to_reg,
131
    input               cr0_mp_to_reg,
132
    input               cr0_em_to_reg,
133
    input               cr0_ts_to_reg,
134
    input               cr0_ne_to_reg,
135
    input               cr0_wp_to_reg,
136
    input               cr0_am_to_reg,
137
    input               cr0_nw_to_reg,
138
    input               cr0_cd_to_reg,
139
    input               cr0_pg_to_reg,
140
 
141
    input       [31:0]  cr2_to_reg,
142
    input       [31:0]  cr3_to_reg,
143
 
144
    input               cflag_to_reg,
145
    input               pflag_to_reg,
146
    input               aflag_to_reg,
147
    input               zflag_to_reg,
148
    input               sflag_to_reg,
149
    input               oflag_to_reg,
150
    input               tflag_to_reg,
151
    input               iflag_to_reg,
152
    input               dflag_to_reg,
153
    input       [1:0]   iopl_to_reg,
154
    input               ntflag_to_reg,
155
    input               rflag_to_reg,
156
    input               vmflag_to_reg,
157
    input               acflag_to_reg,
158
    input               idflag_to_reg,
159
 
160
    input       [31:0]  gdtr_base_to_reg,
161
    input       [15:0]  gdtr_limit_to_reg,
162
 
163
    input       [31:0]  idtr_base_to_reg,
164
    input       [15:0]  idtr_limit_to_reg,
165
 
166
    input       [31:0]  dr0_to_reg,
167
    input       [31:0]  dr1_to_reg,
168
    input       [31:0]  dr2_to_reg,
169
    input       [31:0]  dr3_to_reg,
170
    input       [3:0]   dr6_breakpoints_to_reg,
171
    input               dr6_b12_to_reg,
172
    input               dr6_bd_to_reg,
173
    input               dr6_bs_to_reg,
174
    input               dr6_bt_to_reg,
175
    input       [31:0]  dr7_to_reg,
176
 
177
    input       [15:0]  es_to_reg,
178
    input       [15:0]  ds_to_reg,
179
    input       [15:0]  ss_to_reg,
180
    input       [15:0]  fs_to_reg,
181
    input       [15:0]  gs_to_reg,
182
    input       [15:0]  cs_to_reg,
183
    input       [15:0]  ldtr_to_reg,
184
    input       [15:0]  tr_to_reg,
185
 
186
    input       [63:0]  es_cache_to_reg,
187
    input       [63:0]  ds_cache_to_reg,
188
    input       [63:0]  ss_cache_to_reg,
189
    input       [63:0]  fs_cache_to_reg,
190
    input       [63:0]  gs_cache_to_reg,
191
    input       [63:0]  cs_cache_to_reg,
192
    input       [63:0]  ldtr_cache_to_reg,
193
    input       [63:0]  tr_cache_to_reg,
194
 
195
    input               es_cache_valid_to_reg,
196
    input               ds_cache_valid_to_reg,
197
    input               ss_cache_valid_to_reg,
198
    input               fs_cache_valid_to_reg,
199
    input               gs_cache_valid_to_reg,
200
    input               cs_cache_valid_to_reg,
201
    input               ldtr_cache_valid_to_reg,
202
 
203
    input       [1:0]   es_rpl_to_reg,
204
    input       [1:0]   ds_rpl_to_reg,
205
    input       [1:0]   ss_rpl_to_reg,
206
    input       [1:0]   fs_rpl_to_reg,
207
    input       [1:0]   gs_rpl_to_reg,
208
    input       [1:0]   cs_rpl_to_reg,
209
    input       [1:0]   ldtr_rpl_to_reg,
210
    input       [1:0]   tr_rpl_to_reg,
211
 
212
    //registers output
213
    output reg  [31:0]  eax,
214
    output reg  [31:0]  ebx,
215
    output reg  [31:0]  ecx,
216
    output reg  [31:0]  edx,
217
    output reg  [31:0]  esi,
218
    output reg  [31:0]  edi,
219
    output reg  [31:0]  ebp,
220
    output reg  [31:0]  esp,
221
 
222
    output reg          cr0_pe,
223
    output reg          cr0_mp,
224
    output reg          cr0_em,
225
    output reg          cr0_ts,
226
    output reg          cr0_ne,
227
    output reg          cr0_wp,
228
    output reg          cr0_am,
229
    output reg          cr0_nw,
230
    output reg          cr0_cd,
231
    output reg          cr0_pg,
232
 
233
    output reg  [31:0]  cr2,
234
    output reg  [31:0]  cr3,
235
 
236
    output reg          cflag,
237
    output reg          pflag,
238
    output reg          aflag,
239
    output reg          zflag,
240
    output reg          sflag,
241
    output reg          oflag,
242
    output reg          tflag,
243
    output reg          iflag,
244
    output reg          dflag,
245
    output reg  [1:0]   iopl,
246
    output reg          ntflag,
247
    output reg          rflag,
248
    output reg          vmflag,
249
    output reg          acflag,
250
    output reg          idflag,
251
 
252
    output reg  [31:0]  gdtr_base,
253
    output reg  [15:0]  gdtr_limit,
254
 
255
    output reg  [31:0]  idtr_base,
256
    output reg  [15:0]  idtr_limit,
257
 
258
    output reg  [31:0]  dr0,
259
    output reg  [31:0]  dr1,
260
    output reg  [31:0]  dr2,
261
    output reg  [31:0]  dr3,
262
    output reg  [3:0]   dr6_breakpoints,
263
    output reg          dr6_b12,
264
    output reg          dr6_bd,
265
    output reg          dr6_bs,
266
    output reg          dr6_bt,
267
    output reg  [31:0]  dr7,
268
 
269
    output reg  [15:0]  es,
270
    output reg  [15:0]  ds,
271
    output reg  [15:0]  ss,
272
    output reg  [15:0]  fs,
273
    output reg  [15:0]  gs,
274
    output reg  [15:0]  cs,
275
    output reg  [15:0]  ldtr,
276
    output reg  [15:0]  tr,
277
 
278
    output reg  [63:0]  es_cache,
279
    output reg  [63:0]  ds_cache,
280
    output reg  [63:0]  ss_cache,
281
    output reg  [63:0]  fs_cache,
282
    output reg  [63:0]  gs_cache,
283
    output reg  [63:0]  cs_cache,
284
    output reg  [63:0]  ldtr_cache,
285
    output reg  [63:0]  tr_cache,
286
 
287
    output reg          es_cache_valid,
288
    output reg          ds_cache_valid,
289
    output reg          ss_cache_valid,
290
    output reg          fs_cache_valid,
291
    output reg          gs_cache_valid,
292
    output reg          cs_cache_valid,
293
    output reg          ldtr_cache_valid,
294
    output reg          tr_cache_valid,
295
 
296
    output reg  [1:0]   es_rpl,
297
    output reg  [1:0]   ds_rpl,
298
    output reg  [1:0]   ss_rpl,
299
    output reg  [1:0]   fs_rpl,
300
    output reg  [1:0]   gs_rpl,
301
    output reg  [1:0]   cs_rpl,
302
    output reg  [1:0]   ldtr_rpl,
303
    output reg  [1:0]   tr_rpl
304
);
305
 
306
//------------------------------------------------------------------------------ misc output
307
 
308
assign cpl = cs_rpl;
309
 
310
assign protected_mode = cr0_pe && ~(vmflag);
311
assign v8086_mode     = cr0_pe && vmflag;
312
assign real_mode      = ~(cr0_pe);
313
 
314
assign debug_len0 =
315
    (dr7[19:18] == 2'b00)?  3'b111 :
316
    (dr7[19:18] == 2'b01)?  3'b110 :
317
    (dr7[19:18] == 2'b10)?  3'b000 :
318
                            3'b100;
319
assign debug_len1 =
320
    (dr7[23:22] == 2'b00)?  3'b111 :
321
    (dr7[23:22] == 2'b01)?  3'b110 :
322
    (dr7[23:22] == 2'b10)?  3'b000 :
323
                            3'b100;
324
assign debug_len2 =
325
    (dr7[27:26] == 2'b00)?  3'b111 :
326
    (dr7[27:26] == 2'b01)?  3'b110 :
327
    (dr7[27:26] == 2'b10)?  3'b000 :
328
                            3'b100;
329
assign debug_len3 =
330
    (dr7[31:30] == 2'b00)?  3'b111 :
331
    (dr7[31:30] == 2'b01)?  3'b110 :
332
    (dr7[31:30] == 2'b10)?  3'b000 :
333
                            3'b100;
334
 
335
assign io_allow_check_needed = cr0_pe && (vmflag || cpl > iopl);
336
 
337
//------------------------------------------------------------------------------ general registers value
338
 
339
wire [2:0]  w_index;
340
wire        w_write_regrm;
341
wire        w_operand_32bit;
342
wire        w_operand_16bit;
343
 
344
wire [31:0] eax_value;
345
wire [31:0] ebx_value;
346
wire [31:0] ecx_value;
347
wire [31:0] edx_value;
348
wire [31:0] ebp_value;
349
wire [31:0] esp_value;
350
wire [31:0] esi_value;
351
wire [31:0] edi_value;
352
 
353
assign w_index = (wr_dst_is_rm)?             wr_modregrm_rm :
354
                 (wr_dst_is_reg)?            wr_modregrm_reg :
355
                 (wr_dst_is_implicit_reg)?   wr_decoder[2:0] :
356
                                             3'd0; //write_eax
357
 
358
assign w_write_regrm = write_eax || (write_regrm && (wr_dst_is_rm || wr_dst_is_reg || wr_dst_is_implicit_reg));
359
 
360
assign w_operand_32bit = (wr_regrm_word)?   `FALSE :
361
                         (wr_regrm_dword)?  `TRUE :
362
                                            wr_operand_32bit;
363
 
364
assign w_operand_16bit = ~(w_operand_32bit);
365
 
366
 
367
assign eax_value =
368
    (wr_is_8bit && w_index == 3'd0)?        { eax[31:8],  result[7:0] } :
369
    (wr_is_8bit && w_index == 3'd4)?        { eax[31:16], result[7:0], eax[7:0] } :
370
    (w_operand_16bit && w_index == 3'd0)?   { eax[31:16], result[15:0] } :
371
    (w_operand_32bit && w_index == 3'd0)?   result :
372
                                            eax_to_reg;
373
 
374
assign ebx_value =
375
    (wr_is_8bit && w_index == 3'd3)?        { ebx[31:8],  result[7:0] } :
376
    (wr_is_8bit && w_index == 3'd7)?        { ebx[31:16], result[7:0], ebx[7:0] } :
377
    (w_operand_16bit && w_index == 3'd3)?   { ebx[31:16], result[15:0] } :
378
    (w_operand_32bit && w_index == 3'd3)?   result :
379
                                            ebx_to_reg;
380
assign ecx_value =
381
    (wr_is_8bit && w_index == 3'd1)?        { ecx[31:8],  result[7:0] } :
382
    (wr_is_8bit && w_index == 3'd5)?        { ecx[31:16], result[7:0], ecx[7:0] } :
383
    (w_operand_16bit && w_index == 3'd1)?   { ecx[31:16], result[15:0] } :
384
    (w_operand_32bit && w_index == 3'd1)?   result :
385
                                            ecx_to_reg;
386
assign edx_value =
387
    (wr_is_8bit && w_index == 3'd2)?        { edx[31:8],  result[7:0] } :
388
    (wr_is_8bit && w_index == 3'd6)?        { edx[31:16], result[7:0], edx[7:0] } :
389
    (w_operand_16bit && w_index == 3'd2)?   { edx[31:16], result[15:0] } :
390
    (w_operand_32bit && w_index == 3'd2)?   result :
391
                                            edx_to_reg;
392
assign esi_value =
393
    (~(wr_is_8bit) && w_operand_16bit && w_index == 3'd6)?  { esi[31:16], result[15:0] } :
394
    (~(wr_is_8bit) && w_operand_32bit && w_index == 3'd6)?  result :
395
                                                            esi_to_reg;
396
assign edi_value =
397
    (~(wr_is_8bit) && w_operand_16bit && w_index == 3'd7)?  { edi[31:16], result[15:0] } :
398
    (~(wr_is_8bit) && w_operand_32bit && w_index == 3'd7)?  result :
399
                                                            edi_to_reg;
400
assign ebp_value =
401
    (~(wr_is_8bit) && w_operand_16bit && w_index == 3'd5)?  { ebp[31:16], result[15:0] } :
402
    (~(wr_is_8bit) && w_operand_32bit && w_index == 3'd5)?  result :
403
                                                            ebp_to_reg;
404
assign esp_value =
405
    (~(wr_is_8bit) && w_operand_16bit && w_index == 3'd4)?  { esp_to_reg[31:16], result[15:0] } : // possible mix: from result and esp_to_reg
406
    (~(wr_is_8bit) && w_operand_32bit && w_index == 3'd4)?  result :
407
                                                            esp_to_reg;
408
 
409
//------------------------------------------------------------------------------ general registers
410
 
411
 
412
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) eax <= `STARTUP_EAX; else if(w_write_regrm) eax <= eax_value;                                              else eax <= eax_to_reg; end
413
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) ebx <= `STARTUP_EBX; else if(w_write_regrm) ebx <= ebx_value;                                              else ebx <= ebx_to_reg; end
414
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) ecx <= `STARTUP_ECX; else if(w_write_regrm) ecx <= ecx_value;                                              else ecx <= ecx_to_reg; end
415
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) edx <= `STARTUP_EDX; else if(w_write_regrm) edx <= edx_value;                                              else edx <= edx_to_reg; end
416
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) esi <= `STARTUP_ESI; else if(w_write_regrm) esi <= esi_value;                                              else esi <= esi_to_reg; end
417
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) edi <= `STARTUP_EDI; else if(w_write_regrm) edi <= edi_value;                                              else edi <= edi_to_reg; end
418
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) ebp <= `STARTUP_EBP; else if(w_write_regrm) ebp <= ebp_value;                                              else ebp <= ebp_to_reg; end
419
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) esp <= `STARTUP_ESP; else if(w_write_regrm) esp <= esp_value; else if(exc_restore_esp) esp <= wr_esp_prev; else esp <= esp_to_reg; end
420
 
421
//------------------------------------------------------------------------------ control registers
422
 
423
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr0_pe <= `STARTUP_CR0_PE; else cr0_pe <= cr0_pe_to_reg; end
424
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr0_mp <= `STARTUP_CR0_MP; else cr0_mp <= cr0_mp_to_reg; end
425
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr0_em <= `STARTUP_CR0_EM; else cr0_em <= cr0_em_to_reg; end
426
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr0_ts <= `STARTUP_CR0_TS; else cr0_ts <= cr0_ts_to_reg; end
427
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr0_ne <= `STARTUP_CR0_NE; else cr0_ne <= cr0_ne_to_reg; end
428
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr0_wp <= `STARTUP_CR0_WP; else cr0_wp <= cr0_wp_to_reg; end
429
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr0_am <= `STARTUP_CR0_AM; else cr0_am <= cr0_am_to_reg; end
430
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr0_nw <= `STARTUP_CR0_NW; else cr0_nw <= cr0_nw_to_reg; end
431
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr0_cd <= `STARTUP_CR0_CD; else cr0_cd <= cr0_cd_to_reg; end
432
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr0_pg <= `STARTUP_CR0_PG; else cr0_pg <= cr0_pg_to_reg; end
433
 
434
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cr3    <= `STARTUP_CR3;  else cr3    <= cr3_to_reg;    end
435
 
436
always @(posedge clk or negedge rst_n) begin
437
    if(rst_n == 1'b0)       cr2 <= `STARTUP_CR2;
438
    else if(exc_pf_write)   cr2 <= tlb_write_pf_cr2;
439
    else if(exc_pf_check)   cr2 <= tlb_check_pf_cr2;
440
    else if(exc_pf_read)    cr2 <= tlb_read_pf_cr2;
441
    else if(exc_pf_code)    cr2 <= tlb_code_pf_cr2;
442
    else                    cr2 <= cr2_to_reg;
443
end
444
 
445
//------------------------------------------------------------------------------ eflags
446
 
447
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cflag  <= `STARTUP_CFLAG;  else cflag  <= cflag_to_reg;  end
448
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) pflag  <= `STARTUP_PFLAG;  else pflag  <= pflag_to_reg;  end
449
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) aflag  <= `STARTUP_AFLAG;  else aflag  <= aflag_to_reg;  end
450
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) zflag  <= `STARTUP_ZFLAG;  else zflag  <= zflag_to_reg;  end
451
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) sflag  <= `STARTUP_SFLAG;  else sflag  <= sflag_to_reg;  end
452
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) oflag  <= `STARTUP_OFLAG;  else oflag  <= oflag_to_reg;  end
453
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) tflag  <= `STARTUP_TFLAG;  else tflag  <= tflag_to_reg;  end
454
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) iflag  <= `STARTUP_IFLAG;  else iflag  <= iflag_to_reg;  end
455
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) dflag  <= `STARTUP_DFLAG;  else dflag  <= dflag_to_reg;  end
456
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) iopl   <= `STARTUP_IOPL;   else iopl   <= iopl_to_reg;   end
457
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) ntflag <= `STARTUP_NTFLAG; else ntflag <= ntflag_to_reg; end
458
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) vmflag <= `STARTUP_VMFLAG; else vmflag <= vmflag_to_reg; end
459
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) acflag <= `STARTUP_ACFLAG; else acflag <= acflag_to_reg; end
460
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) idflag <= `STARTUP_IDFLAG; else idflag <= idflag_to_reg; end
461
 
462
always @(posedge clk or negedge rst_n) begin
463
    if(rst_n == 1'b0)       rflag <= `STARTUP_RFLAG;
464
    else if(wr_clear_rflag) rflag <= `FALSE;
465
    else if(exc_set_rflag)  rflag <= `TRUE;
466
    else                    rflag <= rflag_to_reg;
467
end
468
 
469
//------------------------------------------------------------------------------ gdtr, idtr
470
 
471
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) gdtr_base  <= `STARTUP_GDTR_BASE;  else gdtr_base  <= gdtr_base_to_reg;  end
472
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) gdtr_limit <= `STARTUP_GDTR_LIMIT; else gdtr_limit <= gdtr_limit_to_reg; end
473
 
474
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) idtr_base  <= `STARTUP_IDTR_BASE;  else idtr_base  <= idtr_base_to_reg;  end
475
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) idtr_limit <= `STARTUP_IDTR_LIMIT; else idtr_limit <= idtr_limit_to_reg; end
476
 
477
 
478
//------------------------------------------------------------------------------ debug registers
479
 
480
 
481
 
482
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) dr0 <= `STARTUP_DR0; else dr0 <= dr0_to_reg; end
483
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) dr1 <= `STARTUP_DR1; else dr1 <= dr1_to_reg; end
484
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) dr2 <= `STARTUP_DR2; else dr2 <= dr2_to_reg; end
485
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) dr3 <= `STARTUP_DR3; else dr3 <= dr3_to_reg; end
486
 
487
always @(posedge clk or negedge rst_n) begin
488
    if(rst_n == 1'b0)           dr6_breakpoints <= `STARTUP_DR6_BREAKPOINTS;
489
    else if(exc_debug_start)    dr6_breakpoints <= wr_debug_read_reg | wr_debug_write_reg | wr_debug_code_reg;
490
    else                        dr6_breakpoints <= dr6_breakpoints_to_reg;
491
end
492
 
493
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) dr6_b12 <= `STARTUP_DR6_B12; else if(exc_debug_start) dr6_b12 <= `FALSE;                         else dr6_b12 <= dr6_b12_to_reg; end
494
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) dr6_bd  <= `STARTUP_DR6_BD;  else if(dr6_bd_set)      dr6_bd  <= `TRUE;                          else dr6_bd  <= dr6_bd_to_reg;  end
495
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) dr6_bs  <= `STARTUP_DR6_BS;  else if(exc_debug_start) dr6_bs <= wr_debug_step_reg;               else dr6_bs  <= dr6_bs_to_reg;  end
496
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) dr6_bt  <= `STARTUP_DR6_BT;  else if(exc_debug_start) dr6_bt <= wr_debug_task_reg;               else dr6_bt  <= dr6_bt_to_reg;  end
497
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) dr7     <= `STARTUP_DR7;     else if(exc_debug_start) dr7    <= { dr7[31:14], 1'b0, dr7[12:0] }; else dr7     <= dr7_to_reg;     end
498
 
499
 
500
//------------------------------------------------------------------------------ segment registers
501
 
502
wire [63:0] w_seg_cache;
503
wire [2:0]  wr_seg_index;
504
 
505
wire ds_invalidate;
506
wire es_invalidate;
507
wire fs_invalidate;
508
wire gs_invalidate;
509
 
510
assign wr_seg_index = glob_param_1[18:16];
511
 
512
assign w_seg_cache = (write_system_touch)?     glob_descriptor | 64'h0000010000000000 :
513
                     (write_system_busy_tss)?  glob_descriptor | 64'h0000020000000000 :
514
                                               glob_descriptor;
515
 
516
assign ds_invalidate = wr_validate_seg_regs && ds_cache[`DESC_BITS_DPL] < cpl && (ds_cache_valid == `FALSE || ds_cache[`DESC_BIT_SEG] == `FALSE || `DESC_IS_DATA(ds_cache) || `DESC_IS_CODE_NON_CONFORMING(ds_cache));
517
assign es_invalidate = wr_validate_seg_regs && es_cache[`DESC_BITS_DPL] < cpl && (es_cache_valid == `FALSE || es_cache[`DESC_BIT_SEG] == `FALSE || `DESC_IS_DATA(es_cache) || `DESC_IS_CODE_NON_CONFORMING(es_cache));
518
assign fs_invalidate = wr_validate_seg_regs && fs_cache[`DESC_BITS_DPL] < cpl && (fs_cache_valid == `FALSE || fs_cache[`DESC_BIT_SEG] == `FALSE || `DESC_IS_DATA(fs_cache) || `DESC_IS_CODE_NON_CONFORMING(fs_cache));
519
assign gs_invalidate = wr_validate_seg_regs && gs_cache[`DESC_BITS_DPL] < cpl && (gs_cache_valid == `FALSE || gs_cache[`DESC_BIT_SEG] == `FALSE || `DESC_IS_DATA(gs_cache) || `DESC_IS_CODE_NON_CONFORMING(gs_cache));
520
 
521
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) es   <= `STARTUP_ES;   else if(es_invalidate) es <= 16'd0; else if(write_seg_sel && wr_seg_index == 3'd0) es   <= wr_seg_sel; else es   <= es_to_reg;   end
522
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) ds   <= `STARTUP_DS;   else if(ds_invalidate) ds <= 16'd0; else if(write_seg_sel && wr_seg_index == 3'd3) ds   <= wr_seg_sel; else ds   <= ds_to_reg;   end
523
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) ss   <= `STARTUP_SS;                                       else if(write_seg_sel && wr_seg_index == 3'd2) ss   <= wr_seg_sel; else ss   <= ss_to_reg;   end
524
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) fs   <= `STARTUP_FS;   else if(fs_invalidate) fs <= 16'd0; else if(write_seg_sel && wr_seg_index == 3'd4) fs   <= wr_seg_sel; else fs   <= fs_to_reg;   end
525
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) gs   <= `STARTUP_GS;   else if(gs_invalidate) gs <= 16'd0; else if(write_seg_sel && wr_seg_index == 3'd5) gs   <= wr_seg_sel; else gs   <= gs_to_reg;   end
526
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cs   <= `STARTUP_CS;                                       else if(write_seg_sel && wr_seg_index == 3'd1) cs   <= wr_seg_sel; else cs   <= cs_to_reg;   end
527
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) ldtr <= `STARTUP_LDTR;                                     else if(write_seg_sel && wr_seg_index == 3'd6) ldtr <= wr_seg_sel; else ldtr <= ldtr_to_reg; end
528
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) tr   <= `STARTUP_TR;                                       else if(write_seg_sel && wr_seg_index == 3'd7) tr   <= wr_seg_sel; else tr   <= tr_to_reg;   end
529
 
530
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) es_rpl   <= `STARTUP_ES_RPL;   else if(write_seg_rpl && wr_seg_index == 3'd0)                             es_rpl   <= wr_seg_rpl; else es_rpl   <= es_rpl_to_reg;   end
531
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) ds_rpl   <= `STARTUP_DS_RPL;   else if(write_seg_rpl && wr_seg_index == 3'd3)                             ds_rpl   <= wr_seg_rpl; else ds_rpl   <= ds_rpl_to_reg;   end
532
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) ss_rpl   <= `STARTUP_SS_RPL;   else if(write_seg_rpl && wr_seg_index == 3'd2)                             ss_rpl   <= wr_seg_rpl; else ss_rpl   <= ss_rpl_to_reg;   end
533
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) fs_rpl   <= `STARTUP_FS_RPL;   else if(write_seg_rpl && wr_seg_index == 3'd4)                             fs_rpl   <= wr_seg_rpl; else fs_rpl   <= fs_rpl_to_reg;   end
534
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) gs_rpl   <= `STARTUP_GS_RPL;   else if(write_seg_rpl && wr_seg_index == 3'd5)                             gs_rpl   <= wr_seg_rpl; else gs_rpl   <= gs_rpl_to_reg;   end
535
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) cs_rpl   <= `STARTUP_CS_RPL;   else if(write_seg_rpl && wr_seg_index == 3'd1)                             cs_rpl   <= wr_seg_rpl; else cs_rpl   <= cs_rpl_to_reg;   end
536
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) ldtr_rpl <= `STARTUP_LDTR_RPL; else if(write_seg_rpl && wr_seg_index == 3'd6 && w_seg_cache[`DESC_BIT_P]) ldtr_rpl <= wr_seg_rpl; else ldtr_rpl <= ldtr_rpl_to_reg; end
537
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) tr_rpl   <= `STARTUP_TR_RPL;   else if(write_seg_rpl && wr_seg_index == 3'd7)                             tr_rpl   <= wr_seg_rpl; else tr_rpl   <= tr_rpl_to_reg;   end
538
 
539
`define ALWAYS   always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0)
540
 
541
// G=0, D/B=0, P=1, Data, Accessed, R/W
542
`define DEFAULT_SEG_CACHE       { 8'd0,  8'd0, 1'b1, 2'b0, 1'b1, 1'b0, 1'b0, 2'b11, 8'd0,  16'd0, 16'hFFFF }
543
//valid, G=0, D/B=0, P=1, Code, Accessed, R/X
544
`define DEFAULT_CS_CACHE        { 8'hFF, 8'd0, 1'b1, 2'b0, 1'b1, 1'b0, 1'b0, 2'b11, 8'hFF, 16'd0, 16'hFFFF }
545
// G=0, D/B=0, P=1, System, LDT segment
546
`define DEFAULT_LDTR_CACHE      { 8'd0,  8'd0, 1'b1, 2'b0, 1'b0,              4'd2, 8'd0,  16'd0, 16'hFFFF }
547
// G=0, D/B=0, P=1, System, TSS Busy 386
548
`define DEFAULT_TR_CACHE        { 8'd0,  8'd0, 1'b1, 2'b0, 1'b0,             4'd11, 8'd0,  16'd0, 16'hFFFF }
549
 
550
`ALWAYS es_cache   <= `STARTUP_ES_CACHE;   else if(write_seg_cache && wr_seg_index == 3'd0)                             es_cache   <= (es_cache   & wr_seg_cache_mask) | w_seg_cache; else es_cache   <= es_cache_to_reg;   end
551
`ALWAYS ds_cache   <= `STARTUP_DS_CACHE;   else if(write_seg_cache && wr_seg_index == 3'd3)                             ds_cache   <= (ds_cache   & wr_seg_cache_mask) | w_seg_cache; else ds_cache   <= ds_cache_to_reg;   end
552
`ALWAYS ss_cache   <= `STARTUP_SS_CACHE;   else if(write_seg_cache && wr_seg_index == 3'd2)                             ss_cache   <= (ss_cache   & wr_seg_cache_mask) | w_seg_cache; else ss_cache   <= ss_cache_to_reg;   end
553
`ALWAYS fs_cache   <= `STARTUP_FS_CACHE;   else if(write_seg_cache && wr_seg_index == 3'd4)                             fs_cache   <= (fs_cache   & wr_seg_cache_mask) | w_seg_cache; else fs_cache   <= fs_cache_to_reg;   end
554
`ALWAYS gs_cache   <= `STARTUP_GS_CACHE;   else if(write_seg_cache && wr_seg_index == 3'd5)                             gs_cache   <= (gs_cache   & wr_seg_cache_mask) | w_seg_cache; else gs_cache   <= gs_cache_to_reg;   end
555
`ALWAYS cs_cache   <= `STARTUP_CS_CACHE;   else if(write_seg_cache && wr_seg_index == 3'd1)                             cs_cache   <= (cs_cache   & wr_seg_cache_mask) | w_seg_cache; else cs_cache   <= cs_cache_to_reg;   end
556
`ALWAYS ldtr_cache <= `STARTUP_LDTR_CACHE; else if(write_seg_cache && wr_seg_index == 3'd6 && w_seg_cache[`DESC_BIT_P]) ldtr_cache <= (ldtr_cache & wr_seg_cache_mask) | w_seg_cache; else ldtr_cache <= ldtr_cache_to_reg; end
557
`ALWAYS tr_cache   <= `STARTUP_TR_CACHE;   else if(write_seg_cache && wr_seg_index == 3'd7)                             tr_cache   <= (tr_cache   & wr_seg_cache_mask) | w_seg_cache; else tr_cache   <= tr_cache_to_reg;   end
558
 
559
`ALWAYS es_cache_valid   <= `STARTUP_ES_VALID; else if(es_invalidate) es_cache_valid <= 1'b0; else if(write_seg_cache_valid && wr_seg_index == 3'd0) es_cache_valid   <= wr_seg_cache_valid; else es_cache_valid   <= es_cache_valid_to_reg;   end
560
`ALWAYS ds_cache_valid   <= `STARTUP_DS_VALID; else if(ds_invalidate) ds_cache_valid <= 1'b0; else if(write_seg_cache_valid && wr_seg_index == 3'd3) ds_cache_valid   <= wr_seg_cache_valid; else ds_cache_valid   <= ds_cache_valid_to_reg;   end
561
`ALWAYS ss_cache_valid   <= `STARTUP_SS_VALID;                                                else if(write_seg_cache_valid && wr_seg_index == 3'd2) ss_cache_valid   <= wr_seg_cache_valid; else ss_cache_valid   <= ss_cache_valid_to_reg;   end
562
`ALWAYS fs_cache_valid   <= `STARTUP_FS_VALID; else if(fs_invalidate) fs_cache_valid <= 1'b0; else if(write_seg_cache_valid && wr_seg_index == 3'd4) fs_cache_valid   <= wr_seg_cache_valid; else fs_cache_valid   <= fs_cache_valid_to_reg;   end
563
`ALWAYS gs_cache_valid   <= `STARTUP_GS_VALID; else if(gs_invalidate) gs_cache_valid <= 1'b0; else if(write_seg_cache_valid && wr_seg_index == 3'd5) gs_cache_valid   <= wr_seg_cache_valid; else gs_cache_valid   <= gs_cache_valid_to_reg;   end
564
`ALWAYS cs_cache_valid   <= `STARTUP_CS_VALID;                                                else if(write_seg_cache_valid && wr_seg_index == 3'd1) cs_cache_valid   <= wr_seg_cache_valid; else cs_cache_valid   <= cs_cache_valid_to_reg;   end
565
`ALWAYS ldtr_cache_valid <= `STARTUP_LDTR_VALID;                                              else if(write_seg_cache_valid && wr_seg_index == 3'd6) ldtr_cache_valid <= wr_seg_cache_valid; else ldtr_cache_valid <= ldtr_cache_valid_to_reg; end
566
`ALWAYS tr_cache_valid   <= `STARTUP_TR_VALID;                                                else if(write_seg_cache_valid && wr_seg_index == 3'd7) tr_cache_valid   <= wr_seg_cache_valid; end
567
 
568
//------------------------------------------------------------------------------
569
 
570
// synthesis translate_off
571
wire _unused_ok = &{ 1'b0, glob_param_1[31:19], glob_param_1[15:0], wr_decoder[15:3], 1'b0 };
572
// synthesis translate_on
573
 
574
//------------------------------------------------------------------------------
575
 
576
endmodule

powered by: WebSVN 2.1.0

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