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

Subversion Repositories klc32

[/] [klc32/] [trunk/] [rtl/] [verilog/] [MEMORY.v] - Diff between revs 2 and 7

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 2 Rev 7
// ============================================================================
// ============================================================================
// (C) 2011 Robert Finch
// (C) 2011 Robert Finch
// All Rights Reserved.
// All Rights Reserved.
// robfinch<remove>@opencores.org
// robfinch<remove>@opencores.org
//
//
// KLC32 - 32 bit CPU
// KLC32 - 32 bit CPU
// MEMORY.v - memory operate instructions
// MEMORY.v - memory operate instructions
//
//
// 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/>.    
//                                                                          
//                                                                          
// ============================================================================
// ============================================================================
//
//
MEMORY1:
MEMORY1:
        begin
        begin
                case(mopcode)
                case(mopcode)
                `LW:    begin
                `LW:    begin
                                fc_o <= {sf,2'b01};
                                fc_o <= {sf,2'b01};
                                cyc_o <= 1'b1;
                                cyc_o <= 1'b1;
                                stb_o <= 1'b1;
                                stb_o <= 1'b1;
                                sel_o <= 4'b1111;
                                sel_o <= 4'b1111;
                                adr_o <= ea;
                                adr_o <= ea;
                                state <= MEMORY1_ACK;
                                state <= MEMORY1_ACK;
                                end
                                end
                `LH,`LHU:
                `LH,`LHU:
                                begin
                                begin
                                fc_o <= {sf,2'b01};
                                fc_o <= {sf,2'b01};
                                cyc_o <= 1'b1;
                                cyc_o <= 1'b1;
                                stb_o <= 1'b1;
                                stb_o <= 1'b1;
                                sel_o <= ea[1] ? 4'b1100 : 4'b0011;
                                sel_o <= ea[1] ? 4'b1100 : 4'b0011;
                                adr_o <= ea;
                                adr_o <= ea;
                                state <= MEMORY1_ACK;
                                state <= MEMORY1_ACK;
                                end
                                end
                `LB,`LBU:
                `LB,`LBU:
                                begin
                                begin
                                fc_o <= {sf,2'b01};
                                fc_o <= {sf,2'b01};
                                cyc_o <= 1'b1;
                                cyc_o <= 1'b1;
                                stb_o <= 1'b1;
                                stb_o <= 1'b1;
                                case(ea[1:0])
                                case(ea[1:0])
                                2'd0:   sel_o <= 4'b0001;
                                2'd0:   sel_o <= 4'b0001;
                                2'd1:   sel_o <= 4'b0010;
                                2'd1:   sel_o <= 4'b0010;
                                2'd2:   sel_o <= 4'b0100;
                                2'd2:   sel_o <= 4'b0100;
                                2'd3:   sel_o <= 4'b1000;
                                2'd3:   sel_o <= 4'b1000;
                                endcase
                                endcase
                                adr_o <= ea;
                                adr_o <= ea;
                                state <= MEMORY1_ACK;
                                state <= MEMORY1_ACK;
                                end
                                end
                `SW:    begin
                `SW:    begin
                                fc_o <= {sf,2'b01};
                                fc_o <= {sf,2'b01};
                                cyc_o <= 1'b1;
                                cyc_o <= 1'b1;
                                stb_o <= 1'b1;
                                stb_o <= 1'b1;
                                we_o <= 1'b1;
                                we_o <= 1'b1;
                                sel_o <= 4'b1111;
                                sel_o <= 4'b1111;
                                adr_o <= ea;
                                adr_o <= ea;
                                dat_o <= b;
                                dat_o <= b;
                                state <= MEMORY1_ACK;
                                state <= MEMORY1_ACK;
                                end
                                end
                `SH:    begin
                `SH:    begin
                                fc_o <= {sf,2'b01};
                                fc_o <= {sf,2'b01};
                                cyc_o <= 1'b1;
                                cyc_o <= 1'b1;
                                stb_o <= 1'b1;
                                stb_o <= 1'b1;
                                we_o <= 1'b1;
                                we_o <= 1'b1;
                                sel_o <= ea[1] ? 4'b1100 : 4'b0011;
                                sel_o <= ea[1] ? 4'b1100 : 4'b0011;
                                adr_o <= ea;
                                adr_o <= ea;
                                dat_o <= {2{b[15:0]}};
                                dat_o <= {2{b[15:0]}};
                                state <= MEMORY1_ACK;
                                state <= MEMORY1_ACK;
                                end
                                end
                `SB:    begin
                `SB:    begin
                                fc_o <= {sf,2'b01};
                                fc_o <= {sf,2'b01};
                                cyc_o <= 1'b1;
                                cyc_o <= 1'b1;
                                stb_o <= 1'b1;
                                stb_o <= 1'b1;
                                we_o <= 1'b1;
                                we_o <= 1'b1;
                                case(ea[1:0])
                                case(ea[1:0])
                                2'd0:   sel_o <= 4'b0001;
                                2'd0:   sel_o <= 4'b0001;
                                2'd1:   sel_o <= 4'b0010;
                                2'd1:   sel_o <= 4'b0010;
                                2'd2:   sel_o <= 4'b0100;
                                2'd2:   sel_o <= 4'b0100;
                                2'd3:   sel_o <= 4'b1000;
                                2'd3:   sel_o <= 4'b1000;
                                endcase
                                endcase
                                adr_o <= ea;
                                adr_o <= ea;
                                dat_o <= {4{b[7:0]}};
                                dat_o <= {4{b[7:0]}};
                                state <= MEMORY1_ACK;
                                state <= MEMORY1_ACK;
                                end
                                end
                endcase
                endcase
        end
        end
MEMORY1_ACK:
MEMORY1_ACK:
        if (ack_i) begin
        if (ack_i) begin
                case(mopcode)
                case(mopcode)
                `LW:    begin
                `LW:    begin
                                cyc_o <= 1'b0;
                                cyc_o <= 1'b0;
                                stb_o <= 1'b0;
                                stb_o <= 1'b0;
                                sel_o <= 4'b0000;
                                sel_o <= 4'b0000;
                                res <= dat_i;
                                res <= dat_i;
                                state <= WRITEBACK;
                                state <= WRITEBACK;
                                end
                                end
                `LH:    begin
                `LH:    begin
                                cyc_o <= 1'b0;
                                cyc_o <= 1'b0;
                                stb_o <= 1'b0;
                                stb_o <= 1'b0;
                                sel_o <= 4'b0000;
                                sel_o <= 4'b0000;
                                if (sel_o==4'b0011)
                                if (sel_o==4'b0011)
                                        res <= {{16{dat_i[15]}},dat_i[15:0]};
                                        res <= {{16{dat_i[15]}},dat_i[15:0]};
                                else
                                else
                                        res <= {{16{dat_i[31]}},dat_i[31:16]};
                                        res <= {{16{dat_i[31]}},dat_i[31:16]};
                                state <= WRITEBACK;
                                state <= WRITEBACK;
                                end
                                end
                `LHU:   begin
                `LHU:   begin
                                cyc_o <= 1'b0;
                                cyc_o <= 1'b0;
                                stb_o <= 1'b0;
                                stb_o <= 1'b0;
                                sel_o <= 4'b0000;
                                sel_o <= 4'b0000;
                                if (sel_o==4'b0011)
                                if (sel_o==4'b0011)
                                        res <= {16'd0,dat_i[15:0]};
                                        res <= {16'd0,dat_i[15:0]};
                                else
                                else
                                        res <= {16'd0,dat_i[31:16]};
                                        res <= {16'd0,dat_i[31:16]};
                                state <= WRITEBACK;
                                state <= WRITEBACK;
                                end
                                end
                `LB:    begin
                `LB:    begin
                                cyc_o <= 1'b0;
                                cyc_o <= 1'b0;
                                stb_o <= 1'b0;
                                stb_o <= 1'b0;
                                sel_o <= 4'b0000;
                                sel_o <= 4'b0000;
                                case(sel_o)
                                case(sel_o)
                                4'b0001:        res <= {{24{dat_i[7]}},dat_i[7:0]};
                                4'b0001:        res <= {{24{dat_i[7]}},dat_i[7:0]};
                                4'b0010:        res <= {{24{dat_i[15]}},dat_i[15:8]};
                                4'b0010:        res <= {{24{dat_i[15]}},dat_i[15:8]};
                                4'b0100:        res <= {{24{dat_i[23]}},dat_i[23:16]};
                                4'b0100:        res <= {{24{dat_i[23]}},dat_i[23:16]};
                                4'b1000:        res <= {{24{dat_i[31]}},dat_i[31:24]};
                                4'b1000:        res <= {{24{dat_i[31]}},dat_i[31:24]};
                                endcase
                                endcase
                                state <= WRITEBACK;
                                state <= WRITEBACK;
                                end
                                end
                `LBU:   begin
                `LBU:   begin
                                cyc_o <= 1'b0;
                                cyc_o <= 1'b0;
                                stb_o <= 1'b0;
                                stb_o <= 1'b0;
                                sel_o <= 4'b0000;
                                sel_o <= 4'b0000;
                                case(sel_o)
                                case(sel_o)
                                4'b0001:        res <= {24'd0,dat_i[7:0]};
                                4'b0001:        res <= {24'd0,dat_i[7:0]};
                                4'b0010:        res <= {24'd0,dat_i[15:8]};
                                4'b0010:        res <= {24'd0,dat_i[15:8]};
                                4'b0100:        res <= {24'd0,dat_i[23:16]};
                                4'b0100:        res <= {24'd0,dat_i[23:16]};
                                4'b1000:        res <= {24'd0,dat_i[31:24]};
                                4'b1000:        res <= {24'd0,dat_i[31:24]};
                                endcase
                                endcase
                                state <= WRITEBACK;
                                state <= WRITEBACK;
                                end
                                end
                `SW,`SH,`SB:
                `SW,`SH,`SB:
                                begin
                                begin
                                cyc_o <= 1'b0;
                                cyc_o <= 1'b0;
                                stb_o <= 1'b0;
                                stb_o <= 1'b0;
                                we_o <= 1'b0;
                                we_o <= 1'b0;
                                sel_o <= 4'b0000;
                                sel_o <= 4'b0000;
                                state <= IFETCH;
                                state <= IFETCH;
                                end
                                end
                endcase
                endcase
        end
        end
        else if (err_i) begin
        else if (err_i) begin
                cyc_o <= 1'b0;
                cyc_o <= 1'b0;
                stb_o <= 1'b0;
                stb_o <= 1'b0;
                we_o <= 1'b0;
                we_o <= 1'b0;
                sel_o <= 4'b0000;
                sel_o <= 4'b0000;
                vector <= `BUS_ERR_VECTOR;
                vector <= `BUS_ERR_VECTOR;
                state <= TRAP;
                state <= TRAP;
        end
        end
 
 
TAS:
TAS:
        if (!cyc_o) begin
        if (!cyc_o) begin
                fc_o <= {sf,2'b01};
                fc_o <= {sf,2'b01};
                cyc_o <= 1'b1;
                cyc_o <= 1'b1;
                stb_o <= 1'b1;
                stb_o <= 1'b1;
                sel_o <= 4'b1111;
                sel_o <= 4'b1111;
                adr_o <= ea;
                adr_o <= ea;
        end
        end
        else if (ack_i) begin
        else if (ack_i) begin
 
                cyc_o <= ~dat_i[31];
                stb_o <= 1'b0;
                stb_o <= 1'b0;
                sel_o <= 4'b0000;
                sel_o <= 4'b0000;
                res <= dat_i;
                res <= dat_i;
                state <= TAS2;
                state <= TAS2;
        end
        end
        else if (err_i) begin
        else if (err_i) begin
                cyc_o <= 1'b0;
                cyc_o <= 1'b0;
                stb_o <= 1'b0;
                stb_o <= 1'b0;
                we_o <= 1'b0;
                we_o <= 1'b0;
                sel_o <= 4'b0000;
                sel_o <= 4'b0000;
                vector <= `BUS_ERR_VECTOR;
                vector <= `BUS_ERR_VECTOR;
                state <= TRAP;
                state <= TRAP;
        end
        end
TAS2:
TAS2:
        if (!res[31]) begin
        if (!res[31]) begin
                if (!stb_o) begin
                if (!stb_o) begin
                        fc_o <= {sf,2'b01};
                        fc_o <= {sf,2'b01};
                        cyc_o <= 1'b1;
                        cyc_o <= 1'b1;
                        stb_o <= 1'b1;
                        stb_o <= 1'b1;
                        we_o <= 1'b1;
                        we_o <= 1'b1;
                        sel_o <= 4'b1111;
                        sel_o <= 4'b1111;
                        adr_o <= ea;
                        adr_o <= ea;
                        dat_o <= {1'b1,res[30:0]};
                        dat_o <= {1'b1,res[30:0]};
                end
                end
                else if (ack_i) begin
                else if (ack_i) begin
                        cyc_o <= 1'b0;
                        cyc_o <= 1'b0;
                        stb_o <= 1'b0;
                        stb_o <= 1'b0;
                        we_o <= 1'b0;
                        we_o <= 1'b0;
                        sel_o <= 4'b0000;
                        sel_o <= 4'b0000;
                        state <= WRITEBACK;
                        state <= WRITEBACK;
                end
                end
                else if (err_i) begin
                else if (err_i) begin
                        cyc_o <= 1'b0;
                        cyc_o <= 1'b0;
                        stb_o <= 1'b0;
                        stb_o <= 1'b0;
                        we_o <= 1'b0;
                        we_o <= 1'b0;
                        sel_o <= 4'b0000;
                        sel_o <= 4'b0000;
                        vector <= `BUS_ERR_VECTOR;
                        vector <= `BUS_ERR_VECTOR;
                        state <= TRAP;
                        state <= TRAP;
                end
                end
        end
        end
        else begin
        else begin
                cyc_o <= 1'b0;
                cyc_o <= 1'b0;
                state <= WRITEBACK;
                state <= WRITEBACK;
        end
        end
 
 
 
 

powered by: WebSVN 2.1.0

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