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

Subversion Repositories rtf8088

[/] [rtf8088/] [trunk/] [rtl/] [verilog/] [CONTROL_LOGIC.v] - Blame information for rev 8

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 robfinch
// ============================================================================
2
//  CONTROL_LOGIC
3
//  - assorted control logic
4
//
5
//
6 8 robfinch
//  (C) 2009,2010,2013  Robert Finch
7
//  robfinch[remove]@finitron.ca
8 2 robfinch
//
9
//
10
// This source file is free software: you can redistribute it and/or modify 
11
// it under the terms of the GNU Lesser General Public License as published 
12
// by the Free Software Foundation, either version 3 of the License, or     
13
// (at your option) any later version.                                      
14
//                                                                          
15
// This source file is distributed in the hope that it will be useful,      
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
18
// GNU General Public License for more details.                             
19
//                                                                          
20
// You should have received a copy of the GNU General Public License        
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
22
//
23
//
24
//  Verilog 
25
//
26
// ============================================================================
27
//
28
wire [15:0] sp_dec = sp - 16'd1;
29
wire [15:0] sp_inc = sp + 16'd1;
30
wire [15:0] ip_inc = ip + 16'd1;
31
wire [15:0] ip_dec = ip - 16'd1;
32
wire [15:0] cx_dec = cx - 16'd1;
33
wire [15:0] si_dec = si - 16'd1;
34
wire [15:0] di_dec = di - 16'd1;
35
wire [15:0] si_inc = si + 16'd1;
36
wire [15:0] di_inc = di + 16'd1;
37
wire [15:0] sp_dec2 = sp - 16'd2;
38
wire [15:0] sp_inc2 = sp + 16'd2;
39
wire [15:0] ip_inc2 = ip + 16'd2;
40
wire [15:0] ip_dec2 = ip - 16'd2;
41
wire [19:0] ea_inc = ea + 20'd1;
42
wire [19:0] ea_inc2 = ea + 20'd2;
43
wire [19:0] adr_o_inc = adr_o + 20'd1;
44
wire [4:0] modrm = {mod,rm};
45
wire [15:0] offsdisp = offset + disp16;
46
 
47
wire checkForInts = (prefix1==8'h00) && (prefix2==8'h00);
48
 
49
wire doCmp = ir==8'h38 || ir==8'h39 || ir==8'h3A || ir==8'h3B || ir==8'h3C || ir==8'h3D;
50
 
51
 
52
// Detect when to fetch the mod-r/m byte
53
//
54
wire fetch_modrm =
55
        ir==8'h00 || ir==8'h01 || ir==8'h02 || ir==8'h03 || // ADD
56
        ir==8'h08 || ir==8'h09 || ir==8'h0A || ir==8'h0B || // OR
57
        ir==8'h10 || ir==8'h11 || ir==8'h12 || ir==8'h13 ||     // ADC
58
        ir==8'h18 || ir==8'h19 || ir==8'h1A || ir==8'h1B || // SBB
59
        ir==8'h20 || ir==8'h21 || ir==8'h22 || ir==8'h23 || // AND
60
        ir==8'h28 || ir==8'h29 || ir==8'h2A || ir==8'h2B || // SUB
61
        ir==8'h30 || ir==8'h31 || ir==8'h32 || ir==8'h33 || // XOR
62
        ir==8'h38 || ir==8'h39 || ir==8'h3A || ir==8'h3B || // CMP
63
        ir==8'h3C || ir==8'h3D ||                                                   // CMP
64
        ir==8'h62 ||    // BOUND
65
        ir==8'h63 ||    // ARPL
66
        ir==8'h69 || ir==8'h6B ||                                                       // IMUL
67
        ir[7:4]==4'h8 ||
68
        (ir[7]==1'b0 && ir[6]==1'b0 && ir[2]==1'b0) ||          // arithmetic
69
        (ir==8'h0F && ir2[7:4]==4'hA && ir2[2:1]==2'b10) ||
70
        ir==8'hC4 || ir==8'hC5 ||                                                       // LES / LDS
71
        ir==8'hC6 || ir==8'hC7 ||                                                       // MOV I
72
        ir==8'hC0 || ir==8'hC1 ||                                                       // shift / rotate
73
        ir==8'hD0 || ir==8'hD1 || ir==8'hD2 || ir==8'hD3 ||     // shift / rotate
74
        ir==8'hF6 || ir==8'hF7 ||                                                       // NOT / NEG / TEST / MUL / IMUL / DIV / IDIV
75
        ir==8'hFE || ir==8'hFF                                                          // INC / DEC / CALL
76
        ;
77
 
78
// Detect when to fetch the mod-r/m byte during a two byte opcode
79
//
80
wire fetch_modrm2 =
81
        ir2==8'h00 ||   // LLDT / LTR / STR / VERR / VERW
82
        ir2==8'h01 ||   // INVLPG / LGDT / LIDT / LMSW / SGDT / 
83
        ir2==8'h02 ||   // LAR
84
        ir2==8'h03 ||   // LSL
85
        ir2[7:4]==4'h9 ||
86
        ir2==8'hA4 || ir2==8'hAC || ir2==8'hA5 || ir2==8'hAD || // SHRD / SHLD
87
        ir2==8'hAF ||   // IMUL
88
        ir2==8'hB0 || ir2==8'hB1 ||             // CMPXCHG
89
        ir2==8'hB2 || ir2==8'hB4 || ir2==8'hB5 ||       // LSS / LFS / LGS
90
        ir2==8'hB6 || ir2==8'hB7 || ir2==8'hFE || ir2==8'hFF ||
91
        ir2==8'hA3 || ir2==8'hBA || ir2==8'hBB || ir2==8'hBC || ir2==8'hBD ||
92
        ir2==8'hC0 || ir2==8'hC1                // XADD
93
        ;
94
 
95
wire fetch_data =
96
        ir==8'h8A || ir==8'h8B ||       // memory to register
97
        ir==8'hA0 || ir==8'hA1 ||       // memory to accumulator
98
        ir==8'h8E ||                            // memory to segmenr register
99
        (ir==8'h0f && (ir2==8'hB6 || ir2==8'hB7 || ir2==8'hBE || ir2==8'hBf)) ||        // memory to register - needs more resolving.
100
        ir==`POP_AX ||
101
        ir==`POP_DX ||
102
        ir==`POP_CX ||
103
        ir==`POP_BX ||
104
        ir==`POP_SP ||
105
        ir==`POP_BP ||
106
        ir==`POP_SI ||
107
        ir==`POP_DI ||
108
        ir==8'h86 || ir==8'h87 || // exchange register with memory
109
        ir==`LDS ||
110
        ir==`LES ||
111
        (ir==`EXTOP && (ir2==`LFS || ir2==`LGS || ir2==`LSS)) ||
112
        ir==`POPF ||
113
 
114
        fetch_modrm;
115
 
116
wire store_data =
117
        (ir==8'h0F && ir2==8'h00 && rrr==3'd0 && mod!=2'b11) || // SLDT
118
        (ir==8'h0F && ir2==8'h00 && rrr==3'd1 && mod!=2'b11) || // STR
119
        (ir==8'h0F && ir2==8'h01 && rrr==3'd0 && mod!=2'b11) || // SGDT
120
        (ir==8'h0F && ir2==8'h01 && rrr==3'd1 && mod!=2'b11) || // SIDT
121
        (ir==8'h0F && ir2==8'h01 && rrr==3'd4 && mod!=2'b11) || // SMSW
122
        (ir==8'h00 && mod!=2'b11) ||    // ADD b
123
        (ir==8'h01 && mod!=2'b11) ||    // ADD w
124
        (ir==8'h08 && mod!=2'b11) ||    // OR b
125
        (ir==8'h09 && mod!=2'b11) ||    // OR w
126
        (ir==8'h10 && mod!=2'b11) ||    // ADC b
127
        (ir==8'h11 && mod!=2'b11) ||    // ADC w
128
        (ir==8'h18 && mod!=2'b11) ||    // SBB b
129
        (ir==8'h19 && mod!=2'b11) ||    // SBB w
130
        (ir==8'h20 && mod!=2'b11) ||    // AND b
131
        (ir==8'h21 && mod!=2'b11) ||    // AND w
132
        (ir==8'h28 && mod!=2'b11) ||    // SUB b
133
        (ir==8'h29 && mod!=2'b11) ||    // SUB w
134
        (ir==8'h30 && mod!=2'b11) ||    // XOR b
135
        (ir==8'h31 && mod!=2'b11) ||    // XOR w
136
        (ir==8'h63 && mod!=2'b11) ||    // ARPL
137
        (ir==8'hD0 && mod!=2'b11) ||    // byte shifts #1
138
        (ir==8'hD1 && mod!=2'b11) ||    // word shifts #1
139
        (ir==8'hD2 && mod!=2'b11) ||    // byte shifts CL
140
        (ir==8'hD3 && mod!=2'b11) ||    // word shifts CL
141
        (ir==8'hC0 && mod!=2'b11) ||    // byte shifts #n8
142
        (ir==8'hC1 && mod!=2'b11) ||    // word shifts #n8
143
        (hasFetchedModrm && (d==1'b0) && (mod!=2'b11)) ||
144
        ir==8'hA2 ||    // MOV mem8,AL
145
        ir==8'hA3 ||    // MOV mem16,AL
146
        ((ir==8'h86 || ir==8'h87) && (mod!=2'b11))      || // XCHG
147
        ((ir==8'h88 || ir==8'h89) && (mod!=2'b11))      || // MOV
148
        ((ir==8'h6B || ir==8'h69) && (mod!=2'b11))      || // IMUL
149
        ((ir==8'hC6 || ir==8'hC7) && rrr==3'd0 && (mod!=2'b11)) || // MOV mem,imm
150
        ( ir==8'h8C && rrr[2]==1'b0 && (mod!=2'b11))    || // MOV mem16,seg_reg
151
        ((ir==8'hF6 || ir==8'hF7) && rrr==3'd2 && (mod!=2'b11)) || // NOT
152
        ((ir==8'hF6 || ir==8'hF7) && rrr==3'd3 && (mod!=2'b11)) || // NEG
153
        ((ir==8'hF6 || ir==8'hF7) && rrr==3'd4 && (mod!=2'b11)) || // MUL
154
        ((ir==8'hF6 || ir==8'hF7) && rrr==3'd5 && (mod!=2'b11)) || // IMUL
155
        ((ir==8'hF6 || ir==8'hF7) && rrr==3'd6 && (mod!=2'b11)) || // DIV
156
        ((ir==8'hF6 || ir==8'hF7) && rrr==3'd7 && (mod!=2'b11)) || // IDIV
157
        ((ir==8'hFE || ir==8'hFF) && rrr==3'd0 && (mod!=2'b11)) || // INC
158
        ((ir==8'hFE || ir==8'hFF) && rrr==3'd1 && (mod!=2'b11)) ||   // DEC 
159
        ((ir==8'h80 || ir==8'h81 || ir==8'h83) && (rrr!=3'b111) && (mod!=2'b11))           // compare excluded
160
        ;
161
 
162
wire bus_locked = prefix1==`LOCK || prefix2==`LOCK ||
163
        ((ir==8'h86||ir==8'h87) && mod!=2'b11)
164
        ;
165
 
166
wire is_prefix =
167
        ir==`REPZ ||
168
        ir==`REPNZ ||
169
        ir==`LOCK ||
170
        ir==`CS ||
171
        ir==`DS ||
172
        ir==`ES ||
173
        ir==`SS
174
        ;
175
 
176
wire tgt_reg8 =
177
        ir==8'h10 ||
178
        ir==8'h12
179
 
180
        ;
181
 
182
/*
183
if (ir==8'h80 && mod==2'b11) tgt <= RM8; src <= IMM8;
184
if (ir==8'h81 && mod==2'b11) tgt <= RM16; src <= IMM16;
185
if (ir==8'h83 && mod==2'b11) tgt <= RM16; src <= IMM8;
186
if (ir==8'h80 && mod!=2'b11) tgt <= MEM8; src <= IMM8;
187
if (ir==8'h81 && mod!=2'b11) tgt <= MEM16; src <= IMM16;
188
if (ir==8'h83 && mod!=2'b11) tgt <= MEM16; src <= IMM8;
189
case(rrr)
190
3'b000: op <= `ADD;
191
3'b010: op <= `ADC;
192
3'b100: op <= `AND;
193
3'b111: op <= `CMP;
194
endcase
195
*/
196
 
197
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
198
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
199
wire lea = ir==`LEA;
200
 
201
wire hasPrefix = prefix1!=8'h00;
202
wire hasDoublePrefix = hasPrefix && prefix2!=8'h00;
203
wire repz = prefix1==`REPZ || prefix2==`REPZ;
204
wire repnz = prefix1==`REPNZ || prefix2==`REPNZ;
205
 
206 8 robfinch
// ZF is tested only for SCAS, CMPS
207 2 robfinch
wire repdone =
208
        ((repz | repnz) & cxz) ||
209 8 robfinch
        (repz && !zf && (ir==`SCASB||ir==`SCASW||ir==`CMPSB||ir==`CMPSW)) ||
210
        (repnz && zf && (ir==`SCASB||ir==`SCASW||ir==`CMPSB||ir==`CMPSW))
211 2 robfinch
        ;
212
 

powered by: WebSVN 2.1.0

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