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

Subversion Repositories ao486

[/] [ao486/] [trunk/] [rtl/] [ao486/] [pipeline/] [decode_ready.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
module decode_ready(
28
 
29
    input               enable,
30
    input               is_prefix,
31
    input       [3:0]   decoder_count,
32
 
33
    input       [95:0]  decoder,
34
 
35
    input               dec_operand_32bit,
36
    input               dec_address_32bit,
37
 
38
    input               dec_prefix_2byte,
39
    input       [2:0]   dec_modregrm_len,
40
 
41
 
42
    output              dec_ready_one,
43
    output              dec_ready_one_one,
44
    output              dec_ready_one_two,
45
    output              dec_ready_one_three,
46
    output              dec_ready_2byte_one,
47
    output              dec_ready_modregrm_one,
48
    output              dec_ready_2byte_modregrm,
49
    output              dec_ready_call_jmp_imm,
50
    output              dec_ready_one_imm,
51
    output              dec_ready_2byte_imm,
52
    output              dec_ready_mem_offset,
53
    output              dec_ready_modregrm_imm,
54
    output              dec_ready_2byte_modregrm_imm,
55
 
56
    input               consume_one,
57
    input               consume_one_one,
58
    input               consume_one_two,
59
    input               consume_one_three,
60
    input               consume_call_jmp_imm,
61
    input               consume_modregrm_one,
62
    input               consume_one_imm,
63
    input               consume_modregrm_imm,
64
    input               consume_mem_offset,
65
 
66
    output      [3:0]   consume_count_local,
67
    output              dec_is_modregrm
68
);
69
 
70
//------------------------------------------------------------------------------
71
 
72
wire [2:0] call_jmp_imm_len;
73
wire [2:0] one_imm_len;
74
wire [2:0] mem_offset_len;
75
 
76
wire [2:0] modregrm_imm_only_len;
77
wire [3:0] modregrm_imm_len;
78
 
79
//------------------------------------------------------------------------------
80
 
81
assign dec_is_modregrm = consume_modregrm_one || consume_modregrm_imm;
82
 
83
//------------------------------------------------------------------------------
84
 
85
/*
86
 * CALL imm:
87
 * (@decoder[7:0] == 8'h9A || @decoder[7:0] == 8'hE8)
88
 *      decoder[7:0] == 8'h9A && operand_32bit  --> 7
89
 *      decoder[7:0] == 8'h9A                   --> 5
90
 *      operand_32bit                           --> 5
91
 *                                              --> 3
92
 *
93
 * JMP imm:
94
 * (@decoder[7:0] == 8'hEA || @decoder[7:0] == 8'hE9 || @decoder[7:0] == 8'hEB)
95
 *      decoder[7:0] == 8'hEB                   --> 2
96
 *      decoder[7:0] == 8'hEA && operand_32bit  --> 7
97
 *      decoder[7:0] == 8'hEA                   --> 5
98
 *      operand_32bit                           --> 5
99
 *                                              --> 3
100
 */
101
assign call_jmp_imm_len =
102
    // 8'hEB
103
    (decoder[1:0] == 2'b11)?                      3'd2 :
104
    // (8'h9A or 8'hEA) and 32bit
105
    (decoder[1] == 1'b1 && dec_operand_32bit)?    3'd7 :
106
    // (8'hE8 or 8'hE9) and 16bit
107
    (decoder[1] == 1'b0 && ~(dec_operand_32bit))? 3'd3 :
108
    // else
109
                                                  3'd5;
110
 
111
/* Arithmetic:
112
 * @decoder[7:6] == 2'b00 && @decoder[2:1] == 2'b10
113
 *      decoder[0] == 1'b0                      --> 2
114
 *      operand_32bit                           --> 5
115
 *                                              --> 3
116
 *
117
 * PUSH imm:
118
 * (@decoder[7:0] == 8'h6A || @decoder[7:0] == 8'h68)
119
 *      decoder[7:0] == 8'h6A                   --> 2
120
 *      operand_32bit                           --> 5
121
 *                                              --> 3
122
 *
123
 * TEST imm:
124
 * { @decoder[7:1], 1'b0 } == 8'hA8
125
 *      decoder[0] == 1'b0                      --> 2
126
 *      operand_32bit                           --> 5
127
 *                                              --> 3
128
 * MOV imm:
129
 * @decoder[7:4] == 4'hB
130
 *      decoder[7:3] != 8'hB8                   --> 2
131
 *      operand_32bit                           --> 5
132
 *                                              --> 3
133
 * Jcc:
134
 * @decoder_ready_2byte_imm && @decoder[7:4] == 4'h8
135
 *      operand_32bit                           --> 5
136
 *                                              --> 3
137
 */
138
assign one_imm_len =
139
    (~(dec_prefix_2byte) && ({ decoder[7:3], 3'b0 } == 8'hB0 || decoder[7:0] == 8'hA8 || decoder[7:0] == 8'h6A ||
140
                             { decoder[7:6], decoder[0] } == 3'b000 ))?     3'd2 :
141
    (dec_operand_32bit)?                                                    3'd5 :
142
                                                                            3'd3;
143
 
144
assign mem_offset_len = (dec_address_32bit)? 3'd5 : 3'd3;
145
 
146
/* Arithmetic:
147
 * (@decoder[7:0] == 8'h80 || @decoder[7:0] == 8'h81 || @decoder[7:0] == 8'h83)
148
 *      decoder[7:0] == 8'h80 || decoder[7:0] == 8'h83              --> 1
149
 *      operand_32bit                                               --> 4
150
 *                                                                  --> 2
151
 *
152
 * IMUL:
153
 * (@decoder[7:0] == 8'h69 || @decoder[7:0] == 8'h6B)
154
 *      decoder[7:0] == 8'h6B                                       --> 1
155
 *      operand_32bit                                               --> 4
156
 *                                                                  --> 2
157
 *
158
 * TEST:
159
 *  { @decoder[7:1], 1'b0 } == 8'hF6 && { @decoder[13:12], 1'b0 } == 3'd0
160
 *      decoder[7:0] == 8'hF6                                       --> 1
161
 *      operand_32bit                                               --> 4
162
 *                                                                  --> 2
163
 *
164
 * MOV:
165
 *  { @decoder[7:1], 1'b0 } == 8'hC6 && @decoder[13:11] == 3'd0
166
 *      decoder[7:0] == 8'hC6                                       --> 1
167
 *      operand_32bit                                               --> 4
168
 *                                                                  --> 2
169
 *
170
 * Shift:
171
 *  { @decoder[7:1], 1'b0 } == 8'hC0                                --> 1
172
 *
173
 *
174
 * prefix_2byte                                                     --> 1
175
 */
176
assign modregrm_imm_only_len =
177
    (dec_prefix_2byte || { decoder[7:1], 1'b0 } == 8'hC0 || decoder[1:0] == 2'b00 || decoder[1:0] == 2'b10 || decoder[2:0] == 3'b011)?
178
                                                                            3'd1 :
179
    (dec_operand_32bit)?                                                    3'd4 :
180
                                                                            3'd2;
181
 
182
 
183
assign modregrm_imm_len = { 1'b0, dec_modregrm_len } + { 1'b0,  modregrm_imm_only_len };
184
 
185
 
186
//------------------------------------------------------------------------------
187
 
188
assign consume_count_local =
189
    (consume_one)?              4'd1 :
190
    (consume_one_one)?          4'd2 :
191
    (consume_one_two)?          4'd3 :
192
    (consume_one_three)?        4'd4 :
193
    (consume_call_jmp_imm)?     { 1'b0, call_jmp_imm_len } :
194
    (consume_modregrm_one)?     { 1'b0, dec_modregrm_len } :
195
    (consume_one_imm)?          { 1'b0, one_imm_len } :
196
    (consume_modregrm_imm)?     modregrm_imm_len :
197
    (consume_mem_offset)?       { 1'b0, mem_offset_len } :
198
                                4'd0;
199
 
200
//------------------------------------------------------------------------------
201
 
202
assign dec_ready_one                = enable && ~(is_prefix) && ~(dec_prefix_2byte) && decoder_count >= 4'd1;
203
 
204
assign dec_ready_one_one            = enable && ~(is_prefix) && ~(dec_prefix_2byte) && decoder_count >= 4'd2;
205
 
206
assign dec_ready_one_two            = enable && ~(is_prefix) && ~(dec_prefix_2byte) && decoder_count >= 4'd3;
207
 
208
assign dec_ready_one_three          = enable && ~(is_prefix) && ~(dec_prefix_2byte) && decoder_count >= 4'd4;
209
 
210
assign dec_ready_2byte_one          = enable && dec_prefix_2byte && decoder_count >= 4'd1;
211
 
212
assign dec_ready_modregrm_one       = enable && ~(is_prefix) && ~(dec_prefix_2byte) && decoder_count >= { 1'b0, dec_modregrm_len };
213
 
214
assign dec_ready_2byte_modregrm     = enable && dec_prefix_2byte && decoder_count >= { 1'b0, dec_modregrm_len };
215
 
216
assign dec_ready_call_jmp_imm       = enable && ~(is_prefix) && ~(dec_prefix_2byte) && decoder_count >= { 1'b0, call_jmp_imm_len };
217
 
218
assign dec_ready_one_imm            = enable && ~(is_prefix) && ~(dec_prefix_2byte) && decoder_count >= { 1'b0, one_imm_len };
219
 
220
assign dec_ready_2byte_imm          = enable && dec_prefix_2byte && decoder_count >= { 1'b0, one_imm_len };
221
 
222
assign dec_ready_mem_offset         = enable && ~(is_prefix) && ~(dec_prefix_2byte) && decoder_count >= { 1'b0, mem_offset_len };
223
 
224
assign dec_ready_modregrm_imm       = enable && ~(is_prefix) && ~(dec_prefix_2byte) && decoder_count >= modregrm_imm_len;
225
 
226
assign dec_ready_2byte_modregrm_imm = enable && dec_prefix_2byte && decoder_count >= modregrm_imm_len;
227
 
228
//------------------------------------------------------------------------------
229
 
230
//------------------------------------------------------------------------------
231
 
232
// synthesis translate_off
233
wire _unused_ok = &{ 1'b0, decoder[95:8], 1'b0 };
234
// synthesis translate_on
235
 
236
//------------------------------------------------------------------------------
237
 
238
endmodule
239
 

powered by: WebSVN 2.1.0

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