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

Subversion Repositories rtf8088

[/] [rtf8088/] [trunk/] [rtl/] [verilog/] [EACALC.v] - Diff between revs 7 and 8

Only display areas with differences | Details | Blame | View Log

Rev 7 Rev 8
// ============================================================================
// ============================================================================
//  EACALC
//  EACALC
//  - calculation of effective address
//  - calculation of effective address
//
//
//
//
//  (C) 2009-2013  Robert Finch, Stratford
//  (C) 2009-2013  Robert Finch, Stratford
//  robfinch[remove]@finitron.ca
//  robfinch[remove]@finitron.ca
//
//
//
//
// This source file is free software: you can redistribute it and/or modify 
// This source file is free software: you can redistribute it and/or modify 
// it under the terms of the GNU Lesser General Public License as published 
// it under the terms of the GNU Lesser General Public License as published 
// by the Free Software Foundation, either version 3 of the License, or     
// by the Free Software Foundation, either version 3 of the License, or     
// (at your option) any later version.                                      
// (at your option) any later version.                                      
//                                                                          
//                                                                          
// This source file is distributed in the hope that it will be useful,      
// This source file is distributed in the hope that it will be useful,      
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
// GNU General Public License for more details.                             
// GNU General Public License for more details.                             
//                                                                          
//                                                                          
// You should have received a copy of the GNU General Public License        
// You should have received a copy of the GNU General Public License        
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
//
//
//
//
//  Verilog 
//  Verilog 
//
//
// - the effective address calculation may need to fetch an additional
// - the effective address calculation may need to fetch an additional
//   eight or sixteen bit displacement value in order to calculate the
//   eight or sixteen bit displacement value in order to calculate the
//   effective address.
//   effective address.
// - the EA calc only needs to be done once as there is only ever a 
// - the EA calc only needs to be done once as there is only ever a 
//   single memory operand address. Once the EA is calculated it is
//   single memory operand address. Once the EA is calculated it is
//   used for both the fetch and the store when memory is the target.
//   used for both the fetch and the store when memory is the target.
// ============================================================================
// ============================================================================
//
//
EACALC:
EACALC:
        // Terminate an outstanding MODRM fetch cycle
        // Terminate an outstanding MODRM fetch cycle
        if (cyc_o) begin
        if (cyc_o) begin
                if (ack_i) begin
                if (ack_i) begin
                        `TERMINATE_CODE_READ
                        term_code_read();
                        mod   <= dat_i[7:6];
                        mod   <= dat_i[7:6];
                        rrr   <= dat_i[5:3];
                        rrr   <= dat_i[5:3];
                        sreg3 <= dat_i[5:3];
                        sreg3 <= dat_i[5:3];
                        TTT   <= dat_i[5:3];
                        TTT   <= dat_i[5:3];
                        rm    <= dat_i[2:0];
                        rm    <= dat_i[2:0];
                        $display("Mod/RM=%b_%b_%b", dat_i[7:6],dat_i[5:3],dat_i[2:0]);
                        $display("Mod/RM=%b_%b_%b", dat_i[7:6],dat_i[5:3],dat_i[2:0]);
                end
                end
        end
        end
        else begin
        else begin
 
 
                disp16 <= 16'h0000;
                disp16 <= 16'h0000;
 
 
                case(mod)
                case(mod)
 
 
                2'b00:
                2'b00:
                        begin
                        begin
                                state <= EACALC1;
                                state <= EACALC1;
                                // ToDo: error on stack state
                                // ToDo: error on stack state
                                case(rm)
                                case(rm)
                                3'd0:   offset <= bx + si;
                                3'd0:   offset <= bx + si;
                                3'd1:   offset <= bx + di;
                                3'd1:   offset <= bx + di;
                                3'd2:   offset <= bp + si;
                                3'd2:   offset <= bp + si;
                                3'd3:   offset <= bp + di;
                                3'd3:   offset <= bp + di;
                                3'd4:   offset <= si;
                                3'd4:   offset <= si;
                                3'd5:   offset <= di;
                                3'd5:   offset <= di;
                                3'd6:   begin
                                3'd6:   begin
                                                state <= EACALC_DISP16;
                                                state <= EACALC_DISP16;
                                                offset <= 16'h0000;
                                                offset <= 16'h0000;
                                                end
                                                end
                                3'd7:   offset <= bx;
                                3'd7:   offset <= bx;
                                endcase
                                endcase
                        end
                        end
 
 
                2'b01:
                2'b01:
                        begin
                        begin
                                state <= EACALC_DISP8;
                                state <= EACALC_DISP8;
                                case(rm)
                                case(rm)
                                3'd0:   offset <= bx + si;
                                3'd0:   offset <= bx + si;
                                3'd1:   offset <= bx + di;
                                3'd1:   offset <= bx + di;
                                3'd2:   offset <= bp + si;
                                3'd2:   offset <= bp + si;
                                3'd3:   offset <= bp + di;
                                3'd3:   offset <= bp + di;
                                3'd4:   offset <= si;
                                3'd4:   offset <= si;
                                3'd5:   offset <= di;
                                3'd5:   offset <= di;
                                3'd6:   offset <= bp;
                                3'd6:   offset <= bp;
                                3'd7:   offset <= bx;
                                3'd7:   offset <= bx;
                                endcase
                                endcase
                        end
                        end
 
 
                2'b10:
                2'b10:
                        begin
                        begin
                                state <= EACALC_DISP16;
                                state <= EACALC_DISP16;
                                case(rm)
                                case(rm)
                                3'd0:   offset <= bx + si;
                                3'd0:   offset <= bx + si;
                                3'd1:   offset <= bx + di;
                                3'd1:   offset <= bx + di;
                                3'd2:   offset <= bp + si;
                                3'd2:   offset <= bp + si;
                                3'd3:   offset <= bp + di;
                                3'd3:   offset <= bp + di;
                                3'd4:   offset <= si;
                                3'd4:   offset <= si;
                                3'd5:   offset <= di;
                                3'd5:   offset <= di;
                                3'd6:   offset <= bp;
                                3'd6:   offset <= bp;
                                3'd7:   offset <= bx;
                                3'd7:   offset <= bx;
                                endcase
                                endcase
                        end
                        end
 
 
                2'b11:
                2'b11:
                        begin
                        begin
                                state <= EXECUTE;
                                state <= EXECUTE;
                                case(ir)
                                case(ir)
                                `MOV_I8M:
                                `MOV_I8M:
                                        begin
                                        begin
                                                rrr <= rm;
                                                rrr <= rm;
                                                if (rrr==3'd0) state <= FETCH_IMM8;
                                                if (rrr==3'd0) state <= FETCH_IMM8;
                                        end
                                        end
                                `MOV_I16M:
                                `MOV_I16M:
                                        begin
                                        begin
                                                rrr <= rm;
                                                rrr <= rm;
                                                if (rrr==3'd0) state <= FETCH_IMM16;
                                                if (rrr==3'd0) state <= FETCH_IMM16;
                                        end
                                        end
                                `MOV_S2R:
                                `MOV_S2R:
                                        begin
                                        begin
                                                a <= rfso;
                                                a <= rfso;
                                                b <= rfso;
                                                b <= rfso;
                                        end
                                        end
                                `MOV_R2S:
                                `MOV_R2S:
                                        begin
                                        begin
                                                a <= rmo;
                                                a <= rmo;
                                                b <= rmo;
                                                b <= rmo;
                                        end
                                        end
                                `POP_MEM:
                                `POP_MEM:
                                        begin
                                        begin
                                                ir <= 8'h58|rm;
                                                ir <= 8'h58|rm;
                                                state <= POP;
                                                state <= POP;
                                        end
                                        end
                                `XCHG_MEM:
                                `XCHG_MEM:
                                        begin
                                        begin
                                                wrregs <= 1'b1;
                                                wrregs <= 1'b1;
                                                res <= rmo;
                                                res <= rmo;
                                                b <= rrro;
                                                b <= rrro;
                                        end
                                        end
                                // shifts and rotates
                                // shifts and rotates
                                8'hD0,8'hD1,8'hD2,8'hD3:
                                8'hD0,8'hD1,8'hD2,8'hD3:
                                        begin
                                        begin
                                                b <= rmo;
                                                b <= rmo;
                                        end
                                        end
 
                                // The TEST instruction is the only one needing to fetch an immediate value.
                                8'hF6,8'hF7:
                                8'hF6,8'hF7:
 
                                        // 000 = TEST
 
                                        // 010 = NOT
 
                                        // 011 = NEG
 
                                        // 100 = MUL
 
                                        // 101 = IMUL
 
                                        // 110 = DIV
 
                                        // 111 = IDIV
 
                                        if (rrr==3'b000) begin  // TEST
 
                                                a <= rmo;
 
                                                state <= w ? FETCH_IMM16 : FETCH_IMM8;
 
                                        end
 
                                        else
                                        b <= rmo;
                                        b <= rmo;
                                default:
                                default:
                                    begin
                                    begin
                                                if (d) begin
                                                if (d) begin
                                                        a <= rmo;
                                                        a <= rmo;
                                                        b <= rrro;
                                                        b <= rrro;
                                                end
                                                end
                                                else begin
                                                else begin
                                                        a <= rrro;
                                                        a <= rrro;
                                                        b <= rmo;
                                                        b <= rmo;
                                                end
                                                end
                                        end
                                        end
                                endcase
                                endcase
                                hasFetchedData <= 1'b1;
                                hasFetchedData <= 1'b1;
                        end
                        end
                endcase
                endcase
        end
        end
 
 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Fetch 16 bit displacement
// Fetch 16 bit displacement
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
//
EACALC_DISP16:
EACALC_DISP16:
        begin
        begin
                lock_o <= 1'b1;
                lock_o <= 1'b1;
                `INITIATE_CODE_READ
                code_read();
                state <= EACALC_DISP16_ACK;
                state <= EACALC_DISP16_ACK;
        end
        end
EACALC_DISP16_ACK:
EACALC_DISP16_ACK:
        if (ack_i) begin
        if (ack_i) begin
                `TERMINATE_CODE_READ
                term_code_read();
                disp16[7:0] <= dat_i;
                disp16[7:0] <= dat_i;
                state <= EACALC_DISP16a;
                state <= EACALC_DISP16a;
        end
        end
EACALC_DISP16a:
EACALC_DISP16a:
        begin
        begin
                `INITIATE_CODE_READ
                code_read();
                state <= EACALC_DISP16a_ACK;
                state <= EACALC_DISP16a_ACK;
        end
        end
EACALC_DISP16a_ACK:
EACALC_DISP16a_ACK:
        if (ack_i) begin
        if (ack_i) begin
                `TERMINATE_CODE_READ
                term_code_read();
                lock_o <= bus_locked;
                lock_o <= bus_locked;
                disp16[15:8] <= dat_i;
                disp16[15:8] <= dat_i;
                state <= EACALC1;
                state <= EACALC1;
        end
        end
 
 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Fetch 8 bit displacement
// Fetch 8 bit displacement
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
//
EACALC_DISP8:
EACALC_DISP8:
        begin
        begin
                `INITIATE_CODE_READ
                code_read();
                state <= EACALC_DISP8_ACK;
                state <= EACALC_DISP8_ACK;
        end
        end
EACALC_DISP8_ACK:
EACALC_DISP8_ACK:
        if (ack_i) begin
        if (ack_i) begin
                `TERMINATE_CODE_READ
                term_code_read();
                disp16 <= {{8{dat_i[7]}},dat_i};
                disp16 <= {{8{dat_i[7]}},dat_i};
                state <= EACALC1;
                state <= EACALC1;
        end
        end
 
 
 
 
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Add the displacement into the effective address
// Add the displacement into the effective address
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//
//
EACALC1:
EACALC1:
        begin
        begin
                casex(ir)
                casex(ir)
                `EXTOP:
                `EXTOP:
                        casex(ir2)
                        casex(ir2)
                        8'h00:
                        8'h00:
                                begin
                                begin
                                        case(rrr)
                                        case(rrr)
                                        3'b010: state <= FETCH_DESC;    // LLDT
                                        3'b010: state <= FETCH_DESC;    // LLDT
                                        3'b011: state <= FETCH_DATA;    // LTR
                                        3'b011: state <= FETCH_DATA;    // LTR
                                        default: state <= FETCH_DATA;
                                        default: state <= FETCH_DATA;
                                        endcase
                                        endcase
                                        if (w && (offsdisp==16'hFFFF)) begin
                                        if (w && (offsdisp==16'hFFFF)) begin
                                                int_num <= 8'h0d;
                                                int_num <= 8'h0d;
                                                state <= INT;
                                                state <= INT2;
                                        end
                                        end
                                end
                                end
                        8'h01:
                        8'h01:
                                begin
                                begin
                                        case(rrr)
                                        case(rrr)
                                        3'b010: state <= FETCH_DESC;
                                        3'b010: state <= FETCH_DESC;
                                        3'b011: state <= FETCH_DESC;
                                        3'b011: state <= FETCH_DESC;
                                        default: state <= FETCH_DATA;
                                        default: state <= FETCH_DATA;
                                        endcase
                                        endcase
                                        if (w && (offsdisp==16'hFFFF)) begin
                                        if (w && (offsdisp==16'hFFFF)) begin
                                                int_num <= 8'h0d;
                                                int_num <= 8'h0d;
                                                state <= INT;
                                                state <= INT2;
                                        end
                                        end
                                end
                                end
                        8'h03:
                        8'h03:
                                if (w && (offsdisp==16'hFFFF)) begin
                                if (w && (offsdisp==16'hFFFF)) begin
                                        int_num <= 8'h0d;
                                        int_num <= 8'h0d;
                                        state <= INT;
                                        state <= INT2;
                                end
                                end
                                else
                                else
                                        state <= FETCH_DATA;
                                        state <= FETCH_DATA;
                        default:
                        default:
                                if (w && (offsdisp==16'hFFFF)) begin
                                if (w && (offsdisp==16'hFFFF)) begin
                                        int_num <= 8'h0d;
                                        int_num <= 8'h0d;
                                        state <= INT;
                                        state <= INT2;
                                end
                                end
                                else
                                else
                                        state <= FETCH_DATA;
                                        state <= FETCH_DATA;
                        endcase
                        endcase
                `MOV_I8M: state <= FETCH_IMM8;
                `MOV_I8M: state <= FETCH_IMM8;
                `MOV_I16M:
                `MOV_I16M:
                        if (ip==16'hFFFF) begin
                        if (ip==16'hFFFF) begin
                                int_num <= 8'h0d;
                                int_num <= 8'h0d;
                                state <= INT;
                                state <= INT2;
                        end
                        end
                        else
                        else
                                state <= FETCH_IMM16;
                                state <= FETCH_IMM16;
                `POP_MEM:
                `POP_MEM:
                        begin
                        begin
                                state <= POP;
                                state <= POP;
                        end
                        end
                `XCHG_MEM:
                `XCHG_MEM:
                        begin
                        begin
//                              bus_locked <= 1'b1;
//                              bus_locked <= 1'b1;
                                state <= FETCH_DATA;
                                state <= FETCH_DATA;
                        end
                        end
                8'b1000100x:    // Move to memory
                8'b1000100x:    // Move to memory
                        begin
                        begin
                                $display("EACALC1: state <= STORE_DATA");
                                $display("EACALC1: state <= STORE_DATA");
                                if (w && (offsdisp==16'hFFFF)) begin
                                if (w && (offsdisp==16'hFFFF)) begin
                                        int_num <= 8'h0d;
                                        int_num <= 8'h0d;
                                        state <= INT;
                                        state <= INT2;
                                end
                                end
                                else begin
                                else begin
                                        res <= rrro;
                                        res <= rrro;
                                        state <= STORE_DATA;
                                        state <= STORE_DATA;
                                end
                                end
                        end
                        end
                default:
                default:
                        begin
                        begin
                                $display("EACALC1: state <= FETCH_DATA");
                                $display("EACALC1: state <= FETCH_DATA");
                                if (w && (offsdisp==16'hFFFF)) begin
                                if (w && (offsdisp==16'hFFFF)) begin
                                        int_num <= 8'h0d;
                                        int_num <= 8'h0d;
                                        state <= INT;
                                        state <= INT2;
                                end
                                end
                                else
                                else
                                        state <= FETCH_DATA;
                                        state <= FETCH_DATA;
                                if (ir==8'hff) begin
                                if (ir==8'hff) begin
                                        case(rrr)
                                        case(rrr)
                                        3'b011: state <= CALLF; // CAll FAR indirect
                                        3'b011: state <= CALLF; // CAll FAR indirect
                                        3'b101: state <= JUMP_VECTOR1;  // JMP FAR indirect
                                        3'b101: state <= JUMP_VECTOR1;  // JMP FAR indirect
                                        3'b110: begin d <= 1'b0; state <= FETCH_DATA; end// for a push
                                        3'b110: begin d <= 1'b0; state <= FETCH_DATA; end// for a push
                                        default: ;
                                        default: ;
                                        endcase
                                        endcase
                                end
                                end
                        end
                        end
                endcase
                endcase
//              ea <= ea + disp16;
//              ea <= ea + disp16;
                ea <= {seg_reg,`SEG_SHIFT} + offsdisp;  // offsdisp = offset + disp16
                ea <= {seg_reg,`SEG_SHIFT} + offsdisp;  // offsdisp = offset + disp16
        end
        end
 
 

powered by: WebSVN 2.1.0

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