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

Subversion Repositories zap

[/] [zap/] [trunk/] [src/] [rtl/] [cpu/] [zap_alu_main.v] - Diff between revs 43 and 51

Show entire file | Details | Blame | View Log

Rev 43 Rev 51
Line 198... Line 198...
 
 
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Localparams
// Localparams
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
 
 
/*
// Local N,Z,C,V structures.
 *  These override global N,Z,C,V definitions which are on CPSR. These params
 
 *  are localized over the 4-bit flag structure.
 
 */
 
localparam [1:0] _N  = 2'd3;
localparam [1:0] _N  = 2'd3;
localparam [1:0] _Z  = 2'd2;
localparam [1:0] _Z  = 2'd2;
localparam [1:0] _C  = 2'd1;
localparam [1:0] _C  = 2'd1;
localparam [1:0] _V  = 2'd0;
localparam [1:0] _V  = 2'd0;
 
 
Line 449... Line 446...
        o_data_wb_we_nxt  = o_data_wb_we_ff;
        o_data_wb_we_nxt  = o_data_wb_we_ff;
        o_data_wb_dat_nxt = o_data_wb_dat_ff;
        o_data_wb_dat_nxt = o_data_wb_dat_ff;
        o_data_wb_sel_nxt = o_data_wb_sel_ff;
        o_data_wb_sel_nxt = o_data_wb_sel_ff;
        o_address_nxt     = o_mem_address_ff;
        o_address_nxt     = o_mem_address_ff;
 
 
        if ( i_reset )
        if ( i_reset )  // Synchronous reset. 
        begin
        begin
                o_data_wb_cyc_nxt = 1'd0;
                o_data_wb_cyc_nxt = 1'd0;
                o_data_wb_stb_nxt = 1'd0;
                o_data_wb_stb_nxt = 1'd0;
        end
        end
        else if ( i_clear_from_writeback )
        else if ( i_clear_from_writeback )
Line 648... Line 645...
        end
        end
        else if ( i_destination_index_ff == ARCH_PC && (i_condition_code_ff != NV))
        else if ( i_destination_index_ff == ARCH_PC && (i_condition_code_ff != NV))
        begin
        begin
                if ( i_flag_update_ff && o_dav_nxt ) // PC update with S bit. Context restore. 
                if ( i_flag_update_ff && o_dav_nxt ) // PC update with S bit. Context restore. 
                begin
                begin
                        $display($time, " - %m :: Saw PC update with S bit set. Context restore initiated.");
 
 
 
                        o_destination_index_nxt = PHY_RAZ_REGISTER;
                        o_destination_index_nxt = PHY_RAZ_REGISTER;
                        o_clear_from_alu        = 1'd1;
                        o_clear_from_alu        = 1'd1;
                        o_pc_from_alu           = tmp_sum;
                        o_pc_from_alu           = tmp_sum;
                        flags_nxt               = i_mem_srcdest_value_ff;                                       // Restore CPSR from SPSR.
                        flags_nxt               = i_mem_srcdest_value_ff;                                       // Restore CPSR from SPSR.
                        flags_nxt[`CPSR_MODE]   = (flags_nxt[`CPSR_MODE] == USR) ? USR : flags_nxt[`CPSR_MODE]; // Security.
                        flags_nxt[`CPSR_MODE]   = (flags_nxt[`CPSR_MODE] == USR) ? USR : flags_nxt[`CPSR_MODE]; // Security.
Line 669... Line 664...
                                o_pc_from_alu           = tmp_sum;
                                o_pc_from_alu           = tmp_sum;
 
 
                                if ( i_switch_ff )
                                if ( i_switch_ff )
                                begin
                                begin
                                        flags_nxt[T]            = tmp_sum[0];
                                        flags_nxt[T]            = tmp_sum[0];
 
 
                                        if ( tmp_sum[0] )
 
                                                $display($time, " - %m :: Entering T state.");
 
                                        else
 
                                                $display($time, " - %m :: Entering A state.");
 
                                end
                                end
                        end
                        end
                        else    // Correctly predicted.
                        else    // Correctly predicted.
                        begin
                        begin
                                // If thumb bit changes, flush everything before
                                // If thumb bit changes, flush everything before
Line 688... Line 678...
 
 
                                        o_destination_index_nxt = PHY_RAZ_REGISTER;
                                        o_destination_index_nxt = PHY_RAZ_REGISTER;
                                        o_clear_from_alu        = 1'd1;
                                        o_clear_from_alu        = 1'd1;
                                        o_pc_from_alu           = tmp_sum; // Jump to branch target.
                                        o_pc_from_alu           = tmp_sum; // Jump to branch target.
                                        flags_nxt[T]            = tmp_sum[0];
                                        flags_nxt[T]            = tmp_sum[0];
 
 
                                        if ( tmp_sum[0] )
 
                                                $display($time, " - %m :: Entering T state.");
 
                                        else
 
                                                $display($time, " - %m :: Entering A state.");
 
                                end
                                end
                                else
                                else
                                begin
                                begin
                                        // No mode change, do not change anything.
                                        // No mode change, do not change anything.
 
 
Line 711... Line 696...
                        end
                        end
                end
                end
                else    // Branch not taken
                else    // Branch not taken
                begin
                begin
                        if ( i_taken_ff == WT || i_taken_ff == ST )
                        if ( i_taken_ff == WT || i_taken_ff == ST )
 
                        //
                        // Wrong prediction as taken. Go back to the same
                        // Wrong prediction as taken. Go back to the same
                        // branch. Non branches are always predicted as not-taken.
                        // branch. Non branches are always predicted as not-taken.
 
                        //
                        // GO BACK TO THE SAME BRANCH AND INFORM PREDICTOR OF ITS   
                        // GO BACK TO THE SAME BRANCH AND INFORM PREDICTOR OF ITS   
                        // MISTAKE - THE NEXT TIME THE PREDICTION WILL BE NOT-TAKEN.
                        // MISTAKE - THE NEXT TIME THE PREDICTION WILL BE NOT-TAKEN.
 
                        //
                        begin
                        begin
                                o_clear_from_alu = 1'd1;
                                o_clear_from_alu = 1'd1;
                                o_pc_from_alu    = i_pc_ff;
                                o_pc_from_alu    = i_pc_ff;
                        end
                        end
                        else // Correct prediction.
                        else // Correct prediction.
Line 729... Line 717...
                end
                end
        end
        end
        else if ( i_mem_srcdest_index_ff == ARCH_PC && o_dav_nxt && i_mem_load_ff)
        else if ( i_mem_srcdest_index_ff == ARCH_PC && o_dav_nxt && i_mem_load_ff)
        begin
        begin
                // Loads to PC also puts the unit to sleep.
                // Loads to PC also puts the unit to sleep.
                $display($time, " - %m :: ALU saw a load to R15. Sleeping to prevent further instructions from executing.");
 
                sleep_nxt = 1'd1;
                sleep_nxt = 1'd1;
        end
        end
 
 
        // If the current instruction is invalid, do not update flags.
        // If the current instruction is invalid, do not update flags.
        if ( o_dav_nxt == 1'd0 )
        if ( o_dav_nxt == 1'd0 )
Line 945... Line 932...
 
 
        generate_ben = x;
        generate_ben = x;
end
end
endfunction // generate_ben
endfunction // generate_ben
 
 
// assertions_start
 
 
 
        /*
        /*
         * This assertion ensures that no privilege escalation is possible.
         * This assertion ensures that no privilege escalation is possible.
         * It does so by ensuring that the flag register cannot change out
         * It does so by ensuring that the flag register cannot change out
         * of USR during normal operation.
         * of USR during normal operation.
         */
         */
Line 985... Line 970...
        RSC:begin       OPCODE = "RSC";    end
        RSC:begin       OPCODE = "RSC";    end
        CMP:begin       OPCODE = "CMP";    end
        CMP:begin       OPCODE = "CMP";    end
        CMN:begin       OPCODE = "CMN";    end
        CMN:begin       OPCODE = "CMN";    end
        endcase
        endcase
 
 
// assertions_end
 
 
 
endmodule // zap_alu_main.v
endmodule // zap_alu_main.v
 
 
`default_nettype wire
`default_nettype wire
 
 
 No newline at end of file
 No newline at end of file
 
// ----------------------------------------------------------------------------
 
// END OF FILE
 
// ----------------------------------------------------------------------------
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

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