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

Subversion Repositories rtf8088

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 robfinch
// ============================================================================
2
//  EACALC
3
//  - calculation of effective address
4
//
5
//
6 7 robfinch
//  (C) 2009-2013  Robert Finch, Stratford
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
// - the effective address calculation may need to fetch an additional
27
//   eight or sixteen bit displacement value in order to calculate the
28
//   effective address.
29
// - the EA calc only needs to be done once as there is only ever a 
30
//   single memory operand address. Once the EA is calculated it is
31
//   used for both the fetch and the store when memory is the target.
32
// ============================================================================
33
//
34
EACALC:
35
        // Terminate an outstanding MODRM fetch cycle
36
        if (cyc_o) begin
37
                if (ack_i) begin
38 8 robfinch
                        term_code_read();
39 2 robfinch
                        mod   <= dat_i[7:6];
40
                        rrr   <= dat_i[5:3];
41
                        sreg3 <= dat_i[5:3];
42
                        TTT   <= dat_i[5:3];
43
                        rm    <= dat_i[2:0];
44
                        $display("Mod/RM=%b_%b_%b", dat_i[7:6],dat_i[5:3],dat_i[2:0]);
45
                end
46
        end
47
        else begin
48
 
49
                disp16 <= 16'h0000;
50
 
51
                case(mod)
52
 
53
                2'b00:
54
                        begin
55
                                state <= EACALC1;
56
                                // ToDo: error on stack state
57
                                case(rm)
58
                                3'd0:   offset <= bx + si;
59
                                3'd1:   offset <= bx + di;
60
                                3'd2:   offset <= bp + si;
61
                                3'd3:   offset <= bp + di;
62
                                3'd4:   offset <= si;
63
                                3'd5:   offset <= di;
64
                                3'd6:   begin
65
                                                state <= EACALC_DISP16;
66
                                                offset <= 16'h0000;
67
                                                end
68
                                3'd7:   offset <= bx;
69
                                endcase
70
                        end
71
 
72
                2'b01:
73
                        begin
74
                                state <= EACALC_DISP8;
75
                                case(rm)
76
                                3'd0:   offset <= bx + si;
77
                                3'd1:   offset <= bx + di;
78
                                3'd2:   offset <= bp + si;
79
                                3'd3:   offset <= bp + di;
80
                                3'd4:   offset <= si;
81
                                3'd5:   offset <= di;
82
                                3'd6:   offset <= bp;
83
                                3'd7:   offset <= bx;
84
                                endcase
85
                        end
86
 
87
                2'b10:
88
                        begin
89
                                state <= EACALC_DISP16;
90
                                case(rm)
91
                                3'd0:   offset <= bx + si;
92
                                3'd1:   offset <= bx + di;
93
                                3'd2:   offset <= bp + si;
94
                                3'd3:   offset <= bp + di;
95
                                3'd4:   offset <= si;
96
                                3'd5:   offset <= di;
97
                                3'd6:   offset <= bp;
98
                                3'd7:   offset <= bx;
99
                                endcase
100
                        end
101
 
102
                2'b11:
103
                        begin
104
                                state <= EXECUTE;
105
                                case(ir)
106
                                `MOV_I8M:
107
                                        begin
108
                                                rrr <= rm;
109
                                                if (rrr==3'd0) state <= FETCH_IMM8;
110
                                        end
111
                                `MOV_I16M:
112
                                        begin
113
                                                rrr <= rm;
114
                                                if (rrr==3'd0) state <= FETCH_IMM16;
115
                                        end
116
                                `MOV_S2R:
117
                                        begin
118
                                                a <= rfso;
119
                                                b <= rfso;
120
                                        end
121
                                `MOV_R2S:
122
                                        begin
123
                                                a <= rmo;
124
                                                b <= rmo;
125
                                        end
126
                                `POP_MEM:
127
                                        begin
128
                                                ir <= 8'h58|rm;
129
                                                state <= POP;
130
                                        end
131
                                `XCHG_MEM:
132
                                        begin
133
                                                wrregs <= 1'b1;
134
                                                res <= rmo;
135
                                                b <= rrro;
136
                                        end
137 4 robfinch
                                // shifts and rotates
138
                                8'hD0,8'hD1,8'hD2,8'hD3:
139
                                        begin
140
                                                b <= rmo;
141
                                        end
142 8 robfinch
                                // The TEST instruction is the only one needing to fetch an immediate value.
143 6 robfinch
                                8'hF6,8'hF7:
144 8 robfinch
                                        // 000 = TEST
145
                                        // 010 = NOT
146
                                        // 011 = NEG
147
                                        // 100 = MUL
148
                                        // 101 = IMUL
149
                                        // 110 = DIV
150
                                        // 111 = IDIV
151
                                        if (rrr==3'b000) begin  // TEST
152
                                                a <= rmo;
153
                                                state <= w ? FETCH_IMM16 : FETCH_IMM8;
154
                                        end
155
                                        else
156
                                                b <= rmo;
157 2 robfinch
                                default:
158
                                    begin
159
                                                if (d) begin
160
                                                        a <= rmo;
161
                                                        b <= rrro;
162
                                                end
163
                                                else begin
164
                                                        a <= rrro;
165
                                                        b <= rmo;
166
                                                end
167
                                        end
168
                                endcase
169
                                hasFetchedData <= 1'b1;
170
                        end
171
                endcase
172
        end
173
 
174
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
175
// Fetch 16 bit displacement
176
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
177
//
178
EACALC_DISP16:
179
        begin
180
                lock_o <= 1'b1;
181 8 robfinch
                code_read();
182 2 robfinch
                state <= EACALC_DISP16_ACK;
183
        end
184
EACALC_DISP16_ACK:
185
        if (ack_i) begin
186 8 robfinch
                term_code_read();
187 2 robfinch
                disp16[7:0] <= dat_i;
188
                state <= EACALC_DISP16a;
189
        end
190
EACALC_DISP16a:
191
        begin
192 8 robfinch
                code_read();
193 2 robfinch
                state <= EACALC_DISP16a_ACK;
194
        end
195
EACALC_DISP16a_ACK:
196
        if (ack_i) begin
197 8 robfinch
                term_code_read();
198 2 robfinch
                lock_o <= bus_locked;
199
                disp16[15:8] <= dat_i;
200
                state <= EACALC1;
201
        end
202
 
203
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
204
// Fetch 8 bit displacement
205
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
206
//
207
EACALC_DISP8:
208
        begin
209 8 robfinch
                code_read();
210 2 robfinch
                state <= EACALC_DISP8_ACK;
211
        end
212
EACALC_DISP8_ACK:
213
        if (ack_i) begin
214 8 robfinch
                term_code_read();
215 2 robfinch
                disp16 <= {{8{dat_i[7]}},dat_i};
216
                state <= EACALC1;
217
        end
218
 
219
 
220
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
221
// Add the displacement into the effective address
222
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
223
//
224
EACALC1:
225
        begin
226
                casex(ir)
227
                `EXTOP:
228
                        casex(ir2)
229
                        8'h00:
230
                                begin
231
                                        case(rrr)
232
                                        3'b010: state <= FETCH_DESC;    // LLDT
233
                                        3'b011: state <= FETCH_DATA;    // LTR
234
                                        default: state <= FETCH_DATA;
235
                                        endcase
236
                                        if (w && (offsdisp==16'hFFFF)) begin
237
                                                int_num <= 8'h0d;
238 8 robfinch
                                                state <= INT2;
239 2 robfinch
                                        end
240
                                end
241
                        8'h01:
242
                                begin
243
                                        case(rrr)
244
                                        3'b010: state <= FETCH_DESC;
245
                                        3'b011: state <= FETCH_DESC;
246
                                        default: state <= FETCH_DATA;
247
                                        endcase
248
                                        if (w && (offsdisp==16'hFFFF)) begin
249
                                                int_num <= 8'h0d;
250 8 robfinch
                                                state <= INT2;
251 2 robfinch
                                        end
252
                                end
253
                        8'h03:
254
                                if (w && (offsdisp==16'hFFFF)) begin
255
                                        int_num <= 8'h0d;
256 8 robfinch
                                        state <= INT2;
257 2 robfinch
                                end
258
                                else
259
                                        state <= FETCH_DATA;
260
                        default:
261
                                if (w && (offsdisp==16'hFFFF)) begin
262
                                        int_num <= 8'h0d;
263 8 robfinch
                                        state <= INT2;
264 2 robfinch
                                end
265
                                else
266
                                        state <= FETCH_DATA;
267
                        endcase
268
                `MOV_I8M: state <= FETCH_IMM8;
269
                `MOV_I16M:
270
                        if (ip==16'hFFFF) begin
271
                                int_num <= 8'h0d;
272 8 robfinch
                                state <= INT2;
273 2 robfinch
                        end
274
                        else
275
                                state <= FETCH_IMM16;
276
                `POP_MEM:
277
                        begin
278
                                state <= POP;
279
                        end
280
                `XCHG_MEM:
281
                        begin
282
//                              bus_locked <= 1'b1;
283
                                state <= FETCH_DATA;
284
                        end
285 7 robfinch
                8'b1000100x:    // Move to memory
286
                        begin
287
                                $display("EACALC1: state <= STORE_DATA");
288
                                if (w && (offsdisp==16'hFFFF)) begin
289
                                        int_num <= 8'h0d;
290 8 robfinch
                                        state <= INT2;
291 7 robfinch
                                end
292
                                else begin
293
                                        res <= rrro;
294
                                        state <= STORE_DATA;
295
                                end
296
                        end
297 2 robfinch
                default:
298
                        begin
299 7 robfinch
                                $display("EACALC1: state <= FETCH_DATA");
300 2 robfinch
                                if (w && (offsdisp==16'hFFFF)) begin
301
                                        int_num <= 8'h0d;
302 8 robfinch
                                        state <= INT2;
303 2 robfinch
                                end
304
                                else
305
                                        state <= FETCH_DATA;
306
                                if (ir==8'hff) begin
307
                                        case(rrr)
308
                                        3'b011: state <= CALLF; // CAll FAR indirect
309
                                        3'b101: state <= JUMP_VECTOR1;  // JMP FAR indirect
310
                                        3'b110: begin d <= 1'b0; state <= FETCH_DATA; end// for a push
311
                                        default: ;
312
                                        endcase
313
                                end
314
                        end
315
                endcase
316
//              ea <= ea + disp16;
317
                ea <= {seg_reg,`SEG_SHIFT} + offsdisp;  // offsdisp = offset + disp16
318
        end

powered by: WebSVN 2.1.0

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