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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [rtl/] [ao486/] [pipeline/] [execute_commands.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
//PARSED_COMMENTS: this file contains parsed script comments
30
 
31
module execute_commands(
32
    input               clk,
33
    input               rst_n,
34
 
35
    input               exe_reset,
36
 
37
    //general input
38
    input       [31:0]  eax,
39
    input       [31:0]  ecx,
40
    input       [31:0]  edx,
41
    input       [31:0]  ebp,
42
    input       [31:0]  esp,
43
 
44
    input       [31:0]  tr_base,
45
 
46
    input       [15:0]  es,
47
    input       [15:0]  cs,
48
    input       [15:0]  ss,
49
    input       [15:0]  ds,
50
    input       [15:0]  fs,
51
    input       [15:0]  gs,
52
    input       [15:0]  ldtr,
53
    input       [15:0]  tr,
54
 
55
    input       [31:0]  cr2,
56
    input       [31:0]  cr3,
57
 
58
    input       [31:0]  dr0,
59
    input       [31:0]  dr1,
60
    input       [31:0]  dr2,
61
    input       [31:0]  dr3,
62
    input               dr6_bt,
63
    input               dr6_bs,
64
    input               dr6_bd,
65
    input               dr6_b12,
66
    input       [3:0]   dr6_breakpoints,
67
    input       [31:0]  dr7,
68
 
69
    input       [1:0]   cpl,
70
 
71
    input               real_mode,
72
    input               v8086_mode,
73
    input               protected_mode,
74
 
75
    input               idflag,
76
    input               acflag,
77
    input               vmflag,
78
    input               rflag,
79
    input               ntflag,
80
    input       [1:0]   iopl,
81
    input               oflag,
82
    input               dflag,
83
    input               iflag,
84
    input               tflag,
85
    input               sflag,
86
    input               zflag,
87
    input               aflag,
88
    input               pflag,
89
    input               cflag,
90
 
91
    input               cr0_pg,
92
    input               cr0_cd,
93
    input               cr0_nw,
94
    input               cr0_am,
95
    input               cr0_wp,
96
    input               cr0_ne,
97
    input               cr0_ts,
98
    input               cr0_em,
99
    input               cr0_mp,
100
    input               cr0_pe,
101
 
102
    input       [31:0]  cs_limit,
103
    input       [31:0]  tr_limit,
104
    input       [63:0]  tr_cache,
105
    input       [63:0]  ss_cache,
106
 
107
    input       [15:0]  idtr_limit,
108
    input       [31:0]  idtr_base,
109
 
110
    input       [15:0]  gdtr_limit,
111
    input       [31:0]  gdtr_base,
112
 
113
    //exception input
114
    input               exc_push_error,
115
    input       [15:0]  exc_error_code,
116
    input               exc_soft_int_ib,
117
    input               exc_soft_int,
118
    input       [7:0]   exc_vector,
119
 
120
    //exe input
121
    input       [10:0]  exe_mutex_current,
122
 
123
    input       [31:0]  exe_eip,
124
    input       [31:0]  exe_extra,
125
    input       [31:0]  exe_linear,
126
    input       [6:0]   exe_cmd,
127
    input       [3:0]   exe_cmdex,
128
    input       [39:0]  exe_decoder,
129
    input       [2:0]   exe_modregrm_reg,
130
    input       [31:0]  exe_address_effective,
131
    input               exe_is_8bit,
132
    input               exe_operand_16bit,
133
    input               exe_operand_32bit,
134
    input               exe_address_16bit,
135
    input       [3:0]   exe_consumed,
136
 
137
    input       [31:0]  src,
138
    input       [31:0]  dst,
139
 
140
    input       [31:0]  exe_enter_offset,
141
 
142
    input               exe_ready,
143
 
144
    //mult
145
    input               mult_busy,
146
    input       [65:0]  mult_result,
147
 
148
    //div
149
    input               div_busy,
150
    input               exe_div_exception,
151
 
152
    input       [31:0]  div_result_quotient,
153
    input       [31:0]  div_result_remainder,
154
 
155
    //shift
156
    input               e_shift_no_write,
157
    input               e_shift_oszapc_update,
158
    input               e_shift_cf_of_update,
159
    input               e_shift_oflag,
160
    input               e_shift_cflag,
161
 
162
    input       [31:0]  e_shift_result,
163
 
164
    //tlbcheck
165
    output              tlbcheck_do,
166
    input               tlbcheck_done,
167
    input               tlbcheck_page_fault,
168
 
169
    output      [31:0]  tlbcheck_address,
170
    output              tlbcheck_rw,
171
    //----
172
 
173
    //tlbflushsingle
174
    output              tlbflushsingle_do,
175
    input               tlbflushsingle_done,
176
 
177
    output      [31:0]  tlbflushsingle_address,
178
    //----
179
 
180
    //invd
181
    output              invdcode_do,
182
    input               invdcode_done,
183
 
184
    output              invddata_do,
185
    input               invddata_done,
186
 
187
    output              wbinvddata_do,
188
    input               wbinvddata_done,
189
    //---
190
 
191
    //pipeline input
192
    input       [1:0]   wr_task_rpl,
193
    input       [31:0]  wr_esp_prev,
194
 
195
    //global input
196
    input       [63:0]  glob_descriptor,
197
    input       [63:0]  glob_descriptor_2,
198
    input       [31:0]  glob_param_1,
199
    input       [31:0]  glob_param_2,
200
    input       [31:0]  glob_param_3,
201
    input       [31:0]  glob_param_5,
202
 
203
    input       [31:0]  glob_desc_base,
204
 
205
    input       [31:0]  glob_desc_limit,
206
    input       [31:0]  glob_desc_2_limit,
207
 
208
    //global set
209
    output              exe_glob_descriptor_set,
210
    output      [63:0]  exe_glob_descriptor_value,
211
 
212
    output              exe_glob_descriptor_2_set,
213
    output      [63:0]  exe_glob_descriptor_2_value,
214
 
215
    output              exe_glob_param_1_set,
216
    output      [31:0]  exe_glob_param_1_value,
217
 
218
    output              exe_glob_param_2_set,
219
    output      [31:0]  exe_glob_param_2_value,
220
 
221
    output              exe_glob_param_3_set,
222
    output      [31:0]  exe_glob_param_3_value,
223
 
224
    output              dr6_bd_set,
225
 
226
    //offset control
227
    output              offset_ret_far_se,
228
    output              offset_new_stack,
229
    output              offset_new_stack_minus,
230
    output              offset_new_stack_continue,
231
    output              offset_leave,
232
    output              offset_pop,
233
    output              offset_enter_last,
234
    output              offset_ret,
235
    output              offset_iret_glob_param_4,
236
    output              offset_iret,
237
    output              offset_ret_imm,
238
    output              offset_esp,
239
    output              offset_call,
240
    output              offset_call_keep,
241
    output              offset_call_int_same_first,
242
    output              offset_call_int_same_next,
243
    output              offset_int_real,
244
    output              offset_int_real_next,
245
    output              offset_task,
246
 
247
    //task output
248
    output      [31:0]  task_eip,
249
 
250
    //exe output
251
    output              exe_waiting,
252
 
253
    output              exe_bound_fault,
254
    output              exe_trigger_gp_fault,
255
    output              exe_trigger_ts_fault,
256
    output              exe_trigger_ss_fault,
257
    output              exe_trigger_np_fault,
258
    output              exe_trigger_pf_fault,
259
    output              exe_trigger_db_fault,
260
    output              exe_trigger_nm_fault,
261
    output              exe_load_seg_gp_fault,
262
    output              exe_load_seg_ss_fault,
263
    output              exe_load_seg_np_fault,
264
 
265
    output      [15:0]  exe_error_code,
266
 
267
    output      [31:0]  exe_result,
268
    output      [31:0]  exe_result2,
269
    output      [31:0]  exe_result_push,
270
    output      [4:0]   exe_result_signals,
271
 
272
    output      [3:0]   exe_arith_index,
273
 
274
    output              exe_arith_sub_carry,
275
    output              exe_arith_add_carry,
276
    output              exe_arith_adc_carry,
277
    output              exe_arith_sbb_carry,
278
 
279
    output reg [31:0]   exe_buffer,
280
    output reg [463:0]  exe_buffer_shifted,
281
 
282
    //output local
283
    output              exe_is_8bit_clear,
284
 
285
    output              exe_cmpxchg_switch,
286
 
287
    output              exe_task_switch_finished,
288
 
289
    output              exe_eip_from_glob_param_2,
290
    output              exe_eip_from_glob_param_2_16bit,
291
 
292
    //branch
293
    output              exe_branch,
294
    output      [31:0]  exe_branch_eip
295
);
296
 
297
//------------------------------------------------------------------------------ 
298
 
299
//------------------------------------------------------------------------------ eflags
300
 
301
wire [31:0] exe_push_eflags;
302
wire [31:0] exe_pushf_eflags;
303
 
304
assign exe_push_eflags   = { 10'b0,idflag,2'b0,acflag,vmflag,rflag,1'b0,ntflag,iopl,oflag,dflag,iflag,tflag,sflag,zflag,1'b0,aflag,1'b0,pflag,1'b1,cflag };
305
assign exe_pushf_eflags  = { 10'b0,idflag,2'b0,acflag,1'b0,  1'b0, 1'b0,ntflag,iopl,oflag,dflag,iflag,tflag,sflag,zflag,1'b0,aflag,1'b0,pflag,1'b1,cflag };
306
 
307
//------------------------------------------------------------------------------ descriptor load seg
308
 
309
wire [2:0]  exe_segment;
310
wire [15:0] exe_selector;
311
wire [63:0] exe_descriptor;
312
 
313
wire exe_privilege_not_accepted;
314
 
315
assign exe_segment    = glob_param_1[18:16];
316
assign exe_selector   = glob_param_1[15:0];
317
assign exe_descriptor = glob_descriptor;
318
 
319
//task_switch, lar,lsl,verr,verw
320
assign exe_privilege_not_accepted =
321
    exe_selector[`SELECTOR_BITS_RPL] > exe_descriptor[`DESC_BITS_DPL] || cpl > exe_descriptor[`DESC_BITS_DPL];
322
 
323
//------------------------------------------------------------------------------ exe_buffer
324
 
325
wire        exe_buffer_shift;
326
wire        exe_buffer_shift_word;
327
 
328
always @(posedge clk or negedge rst_n) begin
329
    if(rst_n == 1'b0)               exe_buffer_shifted <= 464'd0;
330
    else if(exe_buffer_shift)       exe_buffer_shifted <= { exe_buffer_shifted[431:0], exe_buffer };
331
    else if(exe_buffer_shift_word)  exe_buffer_shifted <= { exe_buffer_shifted[447:0], exe_buffer[15:0] };
332
end
333
 
334
//------------------------------------------------------------------------------ 
335
 
336
wire [32:0] exe_arith_adc;
337
wire [32:0] exe_arith_add;
338
wire [31:0] exe_arith_and;
339
wire [31:0] exe_arith_not;
340
wire [31:0] exe_arith_or;
341
wire [32:0] exe_arith_sub;
342
wire [32:0] exe_arith_sbb;
343
wire [31:0] exe_arith_xor;
344
 
345
wire        exe_cmpxchg_switch_carry;
346
 
347
assign exe_arith_adc   = src + dst + { 31'd0, cflag };
348
assign exe_arith_add   = src + dst;
349
assign exe_arith_and   = src & dst;
350
assign exe_arith_not   = ~dst;
351
assign exe_arith_or    = src | dst;
352
assign exe_arith_sub   = dst - src;
353
assign exe_arith_sbb   = dst - src - { 31'd0, cflag };
354
assign exe_arith_xor   = src ^ dst;
355
 
356
assign exe_arith_sub_carry = (exe_cmpxchg_switch)? exe_cmpxchg_switch_carry : exe_arith_sub[32];
357
assign exe_arith_add_carry = exe_arith_add[32];
358
assign exe_arith_adc_carry = exe_arith_adc[32];
359
assign exe_arith_sbb_carry = exe_arith_sbb[32];
360
 
361
//------------------------------------------------------------------------------ 
362
 
363
wire [15:0] e_seg_by_cmdex;
364
 
365
assign e_seg_by_cmdex =
366
    (exe_cmdex[2:0] == 3'd0)?   es :
367
    (exe_cmdex[2:0] == 3'd1)?   cs :
368
    (exe_cmdex[2:0] == 3'd2)?   ss :
369
    (exe_cmdex[2:0] == 3'd3)?   ds :
370
    (exe_cmdex[2:0] == 3'd4)?   fs :
371
    (exe_cmdex[2:0] == 3'd5)?   gs :
372
    (exe_cmdex[2:0] == 3'd6)?   ldtr :
373
                                tr;
374
 
375
//------------------------------------------------------------------------------ task switch
376
 
377
//exe -> microcode
378
assign task_eip   = (glob_descriptor[`DESC_BITS_TYPE] <= 4'd3)? { 16'd0, exe_buffer_shifted[415:400] } : exe_buffer_shifted[431:400];
379
 
380
//------------------------------------------------------------------------------ Jcc, JCXZ, LOOP
381
 
382
wire [31:0] e_eip_next_sum;
383
 
384
assign e_eip_next_sum =
385
    (exe_is_8bit)?          exe_eip + { {24{exe_decoder[15]}}, exe_decoder[15:8] } :
386
    (exe_operand_16bit)?    exe_eip + { {16{exe_decoder[23]}}, exe_decoder[23:8] } :
387
                            exe_eip + exe_decoder[39:8];
388
 
389
assign exe_branch_eip =
390
    (exe_operand_16bit)?    { 16'd0, e_eip_next_sum[15:0] } :
391
                            e_eip_next_sum;
392
 
393
//------------------------------------------------------------------------------ Jcc, SETcc
394
 
395
wire exe_condition;
396
 
397
condition exe_condition_inst(
398
    .oflag      (oflag), //input
399
    .cflag      (cflag), //input
400
    .sflag      (sflag), //input
401
    .zflag      (zflag), //input
402
    .pflag      (pflag), //input
403
 
404
    .index      (exe_decoder[3:0]), //input [3:0]
405
 
406
    .condition  (exe_condition)  //output
407
);
408
 
409
//------------------------------------------------------------------------------
410
 
411
// synthesis translate_off
412
wire _unused_ok = &{ 1'b0, edx[31:16], tr_cache[63:44], tr_cache[39:0], exe_mutex_current[9], exe_mutex_current[7:5], exe_mutex_current[3], exe_mutex_current[1],
413
    exe_decoder[7:4], mult_result[65:64], exe_selector[15:3], exe_descriptor[63:48], exe_descriptor[39:0], e_aaa_sum_ax[7:4], e_aas_sub_ax[7:4], 1'b0 };
414
// synthesis translate_on
415
 
416
//------------------------------------------------------------------------------
417
 
418
`include "autogen/execute_commands.v"
419
 
420
//------------------------------------------------------------------------------
421
 
422
endmodule

powered by: WebSVN 2.1.0

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