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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [rtl/] [ao486/] [pipeline/] [microcode.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 microcode(
30
    input               clk,
31
    input               rst_n,
32
 
33
    input               micro_reset,
34
 
35
    input               exc_init,
36
    input               exc_load,
37
    input       [31:0]  exc_eip,
38
 
39
    input       [31:0]  task_eip,
40
 
41
    //command control
42
    input               real_mode,
43
    input               v8086_mode,
44
    input               protected_mode,
45
 
46
    input               io_allow_check_needed,
47
    input               exc_push_error,
48
    input               cr0_pg,
49
    input               oflag,
50
    input               ntflag,
51
    input       [1:0]   cpl,
52
 
53
    input       [31:0]  glob_param_1,
54
    input       [31:0]  glob_param_3,
55
    input       [63:0]  glob_descriptor,
56
 
57
    //decoder
58
    output              micro_busy,
59
    input               dec_ready,
60
 
61
    input       [95:0]  decoder,
62
    input       [31:0]  dec_eip,
63
    input               dec_operand_32bit,
64
    input               dec_address_32bit,
65
    input       [1:0]   dec_prefix_group_1_rep,
66
    input               dec_prefix_group_1_lock,
67
    input       [2:0]   dec_prefix_group_2_seg,
68
    input               dec_prefix_2byte,
69
    input       [3:0]   dec_consumed,
70
    input       [2:0]   dec_modregrm_len,
71
    input               dec_is_8bit,
72
    input       [6:0]   dec_cmd,
73
    input       [3:0]   dec_cmdex,
74
 
75
    input               dec_is_complex,
76
 
77
    //micro
78
    input               rd_busy,
79
    output              micro_ready,
80
 
81
    output      [87:0]  micro_decoder,
82
    output      [31:0]  micro_eip,
83
    output              micro_operand_32bit,
84
    output              micro_address_32bit,
85
    output      [1:0]   micro_prefix_group_1_rep,
86
    output              micro_prefix_group_1_lock,
87
    output      [2:0]   micro_prefix_group_2_seg,
88
    output              micro_prefix_2byte,
89
    output      [3:0]   micro_consumed,
90
    output      [2:0]   micro_modregrm_len,
91
    output              micro_is_8bit,
92
    output      [6:0]   micro_cmd,
93
    output      [3:0]   micro_cmdex
94
);
95
 
96
//------------------------------------------------------------------------------
97
 
98
wire task_start;
99
 
100
wire m_overlay;
101
wire m_load;
102
 
103
//------------------------------------------------------------------------------
104
 
105
reg         mc_operand_32bit;
106
reg         mc_address_32bit;
107
reg [1:0]   mc_prefix_group_1_rep;
108
reg         mc_prefix_group_1_lock;
109
reg [2:0]   mc_prefix_group_2_seg;
110
reg         mc_prefix_2byte;
111
reg [87:0]  mc_decoder;
112
reg [2:0]   mc_modregrm_len;
113
reg         mc_is_8bit;
114
 
115
reg [6:0]   mc_cmd;
116
reg [3:0]   mc_cmdex;
117
reg [3:0]   mc_consumed;
118
reg [31:0]  mc_eip;
119
 
120
reg [5:0]   mc_step;
121
reg [3:0]   mc_cmdex_last;
122
//------------------------------------------------------------------------------
123
 
124
assign micro_busy  = rd_busy || m_overlay;
125
 
126
assign micro_ready = ~(micro_reset) && ((~(m_overlay) && dec_ready) || (m_overlay && ~(rd_busy)));
127
 
128
assign m_load      = dec_ready && dec_is_complex;
129
 
130
assign m_overlay   = mc_cmd != `CMD_NULL;
131
 
132
assign task_start  = micro_cmd == `CMD_task_switch_4 && micro_cmdex == `CMDEX_task_switch_4_STEP_1 && micro_ready;
133
 
134
//------------------------------------------------------------------------------
135
 
136
wire [6:0]  mc_cmd_next;
137
wire [6:0]  mc_cmd_current;
138
 
139
wire [3:0]  mc_cmdex_current;
140
 
141
microcode_commands microcode_commands_inst(
142
    .clk                    (clk),
143
    .rst_n                  (rst_n),
144
 
145
    .protected_mode         (protected_mode),    //input
146
    .real_mode              (real_mode),         //input
147
    .v8086_mode             (v8086_mode),        //input
148
 
149
    .io_allow_check_needed  (io_allow_check_needed), //input
150
    .exc_push_error         (exc_push_error),        //input
151
    .cr0_pg                 (cr0_pg),                //input
152
    .oflag                  (oflag),                 //input
153
    .ntflag                 (ntflag),                //input
154
    .cpl                    (cpl),    //input [1:0]
155
 
156
    .glob_param_1           (glob_param_1),    //input [31:0]
157
    .glob_param_3           (glob_param_3),    //input [31:0]
158
    .glob_descriptor        (glob_descriptor), //input [63:0]
159
 
160
    .mc_operand_32bit       (mc_operand_32bit),   //input
161
 
162
    .mc_cmd                 (mc_cmd),     //input [6:0]
163
    .mc_decoder             (mc_decoder), //input [87:0]
164
 
165
    .mc_step                (mc_step),    //input [5:0]
166
    .mc_cmdex_last          (mc_cmdex_last),  //input [3:0]
167
 
168
 
169
    .mc_cmd_next            (mc_cmd_next),        //output [6:0]
170
    .mc_cmd_current         (mc_cmd_current),     //output [6:0]
171
    .mc_cmdex_current       (mc_cmdex_current)    //output [3:0]
172
);
173
 
174
 
175
//------------------------------------------------------------------------------
176
 
177
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) mc_operand_32bit       <= `FALSE; else if(m_load) mc_operand_32bit       <= dec_operand_32bit;       else if(exc_init) mc_operand_32bit       <= `FALSE;  end
178
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) mc_address_32bit       <= `FALSE; else if(m_load) mc_address_32bit       <= dec_address_32bit;       else if(exc_init) mc_address_32bit       <= `FALSE;  end
179
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) mc_prefix_group_1_rep  <= 2'd0;   else if(m_load) mc_prefix_group_1_rep  <= dec_prefix_group_1_rep;  else if(exc_init) mc_prefix_group_1_rep  <= 2'd0;    end
180
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) mc_prefix_group_1_lock <= `FALSE; else if(m_load) mc_prefix_group_1_lock <= dec_prefix_group_1_lock; else if(exc_init) mc_prefix_group_1_lock <= `FALSE;  end
181
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) mc_prefix_group_2_seg  <= 3'd3;   else if(m_load) mc_prefix_group_2_seg  <= dec_prefix_group_2_seg;  else if(exc_init) mc_prefix_group_2_seg  <= 3'd3;    end
182
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) mc_prefix_2byte        <= `FALSE; else if(m_load) mc_prefix_2byte        <= dec_prefix_2byte;        else if(exc_init) mc_prefix_2byte        <= `FALSE;  end
183
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) mc_decoder             <= 88'd0;  else if(m_load) mc_decoder             <= decoder[87:0];           else if(exc_init) mc_decoder             <= 88'd0;   end
184
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) mc_modregrm_len        <= 3'd0;   else if(m_load) mc_modregrm_len        <= dec_modregrm_len;        else if(exc_init) mc_modregrm_len        <= 3'd0;    end
185
always @(posedge clk or negedge rst_n) begin if(rst_n == 1'b0) mc_is_8bit             <= `FALSE; else if(m_load) mc_is_8bit             <= dec_is_8bit;             else if(exc_init) mc_is_8bit             <= `FALSE;  end
186
 
187
always @(posedge clk or negedge rst_n) begin
188
    if(rst_n == 1'b0)       mc_cmd <= `CMD_NULL;
189
    else if(exc_init)       mc_cmd <= `CMD_int;
190
    else if(micro_reset)    mc_cmd <= `CMD_NULL;
191
    else if(m_load)         mc_cmd <= dec_cmd;
192
    else if(micro_ready)    mc_cmd <= mc_cmd_next;
193
end
194
 
195
always @(posedge clk or negedge rst_n) begin
196
    if(rst_n == 1'b0)   mc_cmdex <= 4'd0;
197
    else if(m_load)     mc_cmdex <= dec_cmdex;
198
    else if(exc_init)   mc_cmdex <= `CMDEX_int_STEP_0;
199
end
200
 
201
always @(posedge clk or negedge rst_n) begin
202
    if(rst_n == 1'b0)   mc_consumed <= 4'd0;
203
    else if(m_load)     mc_consumed <= dec_consumed;
204
    else if(task_start) mc_consumed <= 4'd0;
205
    else if(exc_load)   mc_consumed <= 4'd0;
206
end
207
 
208
always @(posedge clk or negedge rst_n) begin
209
    if(rst_n == 1'b0)   mc_eip <= 32'd0;
210
    else if(m_load)     mc_eip <= dec_eip;
211
    else if(task_start) mc_eip <= task_eip;
212
    else if(exc_load)   mc_eip <= exc_eip;
213
end
214
 
215
//------------------------------------------------------------------------------
216
 
217
assign micro_operand_32bit       = (m_overlay)? mc_operand_32bit       : dec_operand_32bit;
218
assign micro_address_32bit       = (m_overlay)? mc_address_32bit       : dec_address_32bit;
219
assign micro_prefix_group_1_rep  = (m_overlay)? mc_prefix_group_1_rep  : dec_prefix_group_1_rep;
220
assign micro_prefix_group_1_lock = (m_overlay)? mc_prefix_group_1_lock : dec_prefix_group_1_lock;
221
assign micro_prefix_group_2_seg  = (m_overlay)? mc_prefix_group_2_seg  : dec_prefix_group_2_seg;
222
assign micro_prefix_2byte        = (m_overlay)? mc_prefix_2byte        : dec_prefix_2byte;
223
assign micro_decoder             = (m_overlay)? mc_decoder             : decoder[87:0];
224
assign micro_modregrm_len        = (m_overlay)? mc_modregrm_len        : dec_modregrm_len;
225
assign micro_is_8bit             = (m_overlay)? mc_is_8bit             : dec_is_8bit;
226
 
227
assign micro_cmd =
228
    (exc_load)?   mc_cmd :
229
    (m_overlay)?        mc_cmd_current :
230
                        dec_cmd;
231
 
232
assign micro_cmdex =
233
    (exc_load)?   mc_cmdex :
234
    (m_overlay)?        mc_cmdex_current :
235
                        dec_cmdex;
236
 
237
assign micro_consumed =
238
    (task_start)?       4'd0 :
239
    (exc_load)?   4'd0 :
240
    (m_overlay)?        mc_consumed :
241
                        dec_consumed;
242
 
243
assign micro_eip =
244
    (task_start)?   task_eip :
245
    (exc_load)?     exc_eip :
246
    (m_overlay)?    mc_eip :
247
                    dec_eip;
248
 
249
//------------------------------------------------------------------------------
250
 
251
always @(posedge clk or negedge rst_n) begin
252
    if(rst_n == 1'b0)       mc_step <= 6'd0;
253
    else if(m_load)         mc_step <= 6'd1;
254
    else if(micro_ready)    mc_step <= mc_step + 6'd1;
255
    else if(exc_init)       mc_step <= 6'd1;
256
end
257
 
258
 
259
always @(posedge clk or negedge rst_n) begin
260
    if(rst_n == 1'b0)       mc_cmdex_last <= 4'd0;
261
    else if(micro_ready)    mc_cmdex_last <= micro_cmdex;
262
    else if(exc_init)       mc_cmdex_last <= `CMDEX_int_STEP_0;
263
end
264
 
265
//------------------------------------------------------------------------------
266
 
267
// synthesis translate_off
268
wire _unused_ok = &{ 1'b0, decoder[95:88], 1'b0 };
269
// synthesis translate_on
270
 
271
endmodule

powered by: WebSVN 2.1.0

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