//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// OR1200's generate PC ////
|
//// OR1200's generate PC ////
|
//// ////
|
//// ////
|
//// This file is part of the OpenRISC 1200 project ////
|
//// This file is part of the OpenRISC 1200 project ////
|
//// http://www.opencores.org/cores/or1k/ ////
|
//// http://www.opencores.org/cores/or1k/ ////
|
//// ////
|
//// ////
|
//// Description ////
|
//// Description ////
|
//// PC, interface to IC. ////
|
//// PC, interface to IC. ////
|
//// ////
|
//// ////
|
//// To Do: ////
|
//// To Do: ////
|
//// - make it smaller and faster ////
|
//// - make it smaller and faster ////
|
//// ////
|
//// ////
|
//// Author(s): ////
|
//// Author(s): ////
|
//// - Damjan Lampret, lampret@opencores.org ////
|
//// - Damjan Lampret, lampret@opencores.org ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//// ////
|
//// ////
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
//// Copyright (C) 2000 Authors and OPENCORES.ORG ////
|
//// ////
|
//// ////
|
//// This source file may be used and distributed without ////
|
//// This source file may be used and distributed without ////
|
//// restriction provided that this copyright statement is not ////
|
//// restriction provided that this copyright statement is not ////
|
//// removed from the file and that any derivative work contains ////
|
//// removed from the file and that any derivative work contains ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// the original copyright notice and the associated disclaimer. ////
|
//// ////
|
//// ////
|
//// This source file is free software; you can redistribute it ////
|
//// This source file is free software; you can redistribute it ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// Public License as published by the Free Software Foundation; ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// either version 2.1 of the License, or (at your option) any ////
|
//// later version. ////
|
//// later version. ////
|
//// ////
|
//// ////
|
//// This source is distributed in the hope that it will be ////
|
//// This source is distributed in the hope that it will be ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
//// details. ////
|
//// details. ////
|
//// ////
|
//// ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// You should have received a copy of the GNU Lesser General ////
|
//// Public License along with this source; if not, download it ////
|
//// Public License along with this source; if not, download it ////
|
//// from http://www.opencores.org/lgpl.shtml ////
|
//// from http://www.opencores.org/lgpl.shtml ////
|
//// ////
|
//// ////
|
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
//
|
//
|
// CVS Revision History
|
// CVS Revision History
|
//
|
//
|
// $Log: not supported by cvs2svn $
|
// $Log: not supported by cvs2svn $
|
// Revision 1.5 2002/02/11 04:33:17 lampret
|
// Revision 1.5 2002/02/11 04:33:17 lampret
|
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
|
// Speed optimizations (removed duplicate _cyc_ and _stb_). Fixed D/IMMU cache-inhibit attr.
|
//
|
//
|
// Revision 1.4 2002/01/28 01:16:00 lampret
|
// Revision 1.4 2002/01/28 01:16:00 lampret
|
// Changed 'void' nop-ops instead of insn[0] to use insn[16]. Debug unit stalls the tick timer. Prepared new flag generation for add and and insns. Blocked DC/IC while they are turned off. Fixed I/D MMU SPRs layout except WAYs. TODO: smart IC invalidate, l.j 2 and TLB ways.
|
// Changed 'void' nop-ops instead of insn[0] to use insn[16]. Debug unit stalls the tick timer. Prepared new flag generation for add and and insns. Blocked DC/IC while they are turned off. Fixed I/D MMU SPRs layout except WAYs. TODO: smart IC invalidate, l.j 2 and TLB ways.
|
//
|
//
|
// Revision 1.3 2002/01/18 07:56:00 lampret
|
// Revision 1.3 2002/01/18 07:56:00 lampret
|
// No more low/high priority interrupts (PICPR removed). Added tick timer exception. Added exception prefix (SR[EPH]). Fixed single-step bug whenreading NPC.
|
// No more low/high priority interrupts (PICPR removed). Added tick timer exception. Added exception prefix (SR[EPH]). Fixed single-step bug whenreading NPC.
|
//
|
//
|
// Revision 1.2 2002/01/14 06:18:22 lampret
|
// Revision 1.2 2002/01/14 06:18:22 lampret
|
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
|
// Fixed mem2reg bug in FAST implementation. Updated debug unit to work with new genpc/if.
|
//
|
//
|
// Revision 1.1 2002/01/03 08:16:15 lampret
|
// Revision 1.1 2002/01/03 08:16:15 lampret
|
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
|
// New prefixes for RTL files, prefixed module names. Updated cache controllers and MMUs.
|
//
|
//
|
// Revision 1.10 2001/11/20 18:46:15 simons
|
// Revision 1.10 2001/11/20 18:46:15 simons
|
// Break point bug fixed
|
// Break point bug fixed
|
//
|
//
|
// Revision 1.9 2001/11/18 09:58:28 lampret
|
// Revision 1.9 2001/11/18 09:58:28 lampret
|
// Fixed some l.trap typos.
|
// Fixed some l.trap typos.
|
//
|
//
|
// Revision 1.8 2001/11/18 08:36:28 lampret
|
// Revision 1.8 2001/11/18 08:36:28 lampret
|
// For GDB changed single stepping and disabled trap exception.
|
// For GDB changed single stepping and disabled trap exception.
|
//
|
//
|
// Revision 1.7 2001/10/21 17:57:16 lampret
|
// Revision 1.7 2001/10/21 17:57:16 lampret
|
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
|
// Removed params from generic_XX.v. Added translate_off/on in sprs.v and id.v. Removed spr_addr from dc.v and ic.v. Fixed CR+LF.
|
//
|
//
|
// Revision 1.6 2001/10/14 13:12:09 lampret
|
// Revision 1.6 2001/10/14 13:12:09 lampret
|
// MP3 version.
|
// MP3 version.
|
//
|
//
|
// Revision 1.1.1.1 2001/10/06 10:18:36 igorm
|
// Revision 1.1.1.1 2001/10/06 10:18:36 igorm
|
// no message
|
// no message
|
//
|
//
|
// Revision 1.1 2001/08/09 13:39:33 lampret
|
// Revision 1.1 2001/08/09 13:39:33 lampret
|
// Major clean-up.
|
// Major clean-up.
|
//
|
//
|
//
|
//
|
|
|
// synopsys translate_off
|
// synopsys translate_off
|
`include "timescale.v"
|
`include "timescale.v"
|
// synopsys translate_on
|
// synopsys translate_on
|
`include "or1200_defines.v"
|
`include "or1200_defines.v"
|
|
|
module or1200_genpc(
|
module or1200_genpc(
|
// Clock and reset
|
// Clock and reset
|
clk, rst,
|
clk, rst,
|
|
|
// External i/f to IC
|
// External i/f to IC
|
icpu_adr_o, icpu_cycstb_o, icpu_sel_o, icpu_tag_o,
|
icpu_adr_o, icpu_cycstb_o, icpu_sel_o, icpu_tag_o,
|
icpu_rty_i, icpu_adr_i,
|
icpu_rty_i, icpu_adr_i,
|
|
|
// Internal i/f
|
// Internal i/f
|
branch_op, except_type, except_prefix,
|
branch_op, except_type, except_prefix,
|
branch_addrofs, lr_restor, flag, taken, except_start,
|
branch_addrofs, lr_restor, flag, taken, except_start,
|
binsn_addr, epcr, spr_dat_i, spr_pc_we, genpc_refetch,
|
binsn_addr, epcr, spr_dat_i, spr_pc_we, genpc_refetch,
|
genpc_freeze, no_more_dslot
|
genpc_freeze, no_more_dslot
|
);
|
);
|
|
|
//
|
//
|
// I/O
|
// I/O
|
//
|
//
|
|
|
//
|
//
|
// Clock and reset
|
// Clock and reset
|
//
|
//
|
input clk;
|
input clk;
|
input rst;
|
input rst;
|
|
|
//
|
//
|
// External i/f to IC
|
// External i/f to IC
|
//
|
//
|
output [31:0] icpu_adr_o;
|
output [31:0] icpu_adr_o;
|
output icpu_cycstb_o;
|
output icpu_cycstb_o;
|
output [3:0] icpu_sel_o;
|
output [3:0] icpu_sel_o;
|
output [3:0] icpu_tag_o;
|
output [3:0] icpu_tag_o;
|
input icpu_rty_i;
|
input icpu_rty_i;
|
input [31:0] icpu_adr_i;
|
input [31:0] icpu_adr_i;
|
|
|
//
|
//
|
// Internal i/f
|
// Internal i/f
|
//
|
//
|
input [`OR1200_BRANCHOP_WIDTH-1:0] branch_op;
|
input [`OR1200_BRANCHOP_WIDTH-1:0] branch_op;
|
input [`OR1200_EXCEPT_WIDTH-1:0] except_type;
|
input [`OR1200_EXCEPT_WIDTH-1:0] except_type;
|
input except_prefix;
|
input except_prefix;
|
input [31:2] branch_addrofs;
|
input [31:2] branch_addrofs;
|
input [31:0] lr_restor;
|
input [31:0] lr_restor;
|
input flag;
|
input flag;
|
output taken;
|
output taken;
|
input except_start;
|
input except_start;
|
input [31:2] binsn_addr;
|
input [31:2] binsn_addr;
|
input [31:0] epcr;
|
input [31:0] epcr;
|
input [31:0] spr_dat_i;
|
input [31:0] spr_dat_i;
|
input spr_pc_we;
|
input spr_pc_we;
|
input genpc_refetch;
|
input genpc_refetch;
|
input genpc_freeze;
|
input genpc_freeze;
|
input no_more_dslot;
|
input no_more_dslot;
|
|
|
//
|
//
|
// Internal wires and regs
|
// Internal wires and regs
|
//
|
//
|
reg [31:2] pcreg;
|
reg [31:2] pcreg;
|
reg [31:0] pc;
|
reg [31:0] pc;
|
reg taken; /* Set to in case of jump or taken branch */
|
reg taken; /* Set to in case of jump or taken branch */
|
|
|
//
|
//
|
// Address of insn to be fecthed
|
// Address of insn to be fecthed
|
//
|
//
|
assign icpu_adr_o = !no_more_dslot & !except_start & !spr_pc_we & (icpu_rty_i | genpc_refetch) ? icpu_adr_i : pc;
|
assign icpu_adr_o = !no_more_dslot & !except_start & !spr_pc_we & (icpu_rty_i | genpc_refetch) ? icpu_adr_i : pc;
|
// assign icpu_adr_o = !except_start & !spr_pc_we & (icpu_rty_i | genpc_refetch) ? icpu_adr_i : pc;
|
// assign icpu_adr_o = !except_start & !spr_pc_we & (icpu_rty_i | genpc_refetch) ? icpu_adr_i : pc;
|
|
|
//
|
//
|
// Control access to IC subsystem
|
// Control access to IC subsystem
|
//
|
//
|
// assign icpu_cycstb_o = !genpc_freeze & !no_more_dslot;
|
// assign icpu_cycstb_o = !genpc_freeze & !no_more_dslot;
|
assign icpu_cycstb_o = !genpc_freeze;
|
assign icpu_cycstb_o = !genpc_freeze;
|
assign icpu_sel_o = 4'b1111;
|
assign icpu_sel_o = 4'b1111;
|
assign icpu_tag_o = `OR1200_ITAG_NI;
|
assign icpu_tag_o = `OR1200_ITAG_NI;
|
|
|
//
|
//
|
// Async calculation of new PC value. This value is used for addressing the IC.
|
// Async calculation of new PC value. This value is used for addressing the IC.
|
//
|
//
|
always @(pcreg or branch_addrofs or binsn_addr or flag or branch_op or except_type
|
always @(pcreg or branch_addrofs or binsn_addr or flag or branch_op or except_type
|
or except_start or lr_restor or epcr or spr_pc_we or spr_dat_i or except_prefix) begin
|
or except_start or lr_restor or epcr or spr_pc_we or spr_dat_i or except_prefix) begin
|
casex ({spr_pc_we, except_start, branch_op}) // synopsys parallel_case
|
casex ({spr_pc_we, except_start, branch_op}) // synopsys parallel_case
|
{2'b00, `OR1200_BRANCHOP_NOP}: begin
|
{2'b00, `OR1200_BRANCHOP_NOP}: begin
|
pc = {pcreg + 'd1, 2'b0};
|
pc = {pcreg + 'd1, 2'b0};
|
taken = 1'b0;
|
taken = 1'b0;
|
end
|
end
|
{2'b00, `OR1200_BRANCHOP_J}: begin
|
{2'b00, `OR1200_BRANCHOP_J}: begin
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("%t: BRANCHOP_J: pc <= branch_addrofs %h", $time, branch_addrofs);
|
$display("%t: BRANCHOP_J: pc <= branch_addrofs %h", $time, branch_addrofs);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
pc = {branch_addrofs, 2'b0};
|
pc = {branch_addrofs, 2'b0};
|
taken = 1'b1;
|
taken = 1'b1;
|
end
|
end
|
{2'b00, `OR1200_BRANCHOP_JR}: begin
|
{2'b00, `OR1200_BRANCHOP_JR}: begin
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("%t: BRANCHOP_JR: pc <= lr_restor %h", $time, lr_restor);
|
$display("%t: BRANCHOP_JR: pc <= lr_restor %h", $time, lr_restor);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
pc = lr_restor;
|
pc = lr_restor;
|
taken = 1'b1;
|
taken = 1'b1;
|
end
|
end
|
{2'b00, `OR1200_BRANCHOP_BAL}: begin
|
{2'b00, `OR1200_BRANCHOP_BAL}: begin
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("%t: BRANCHOP_BAL: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
|
$display("%t: BRANCHOP_BAL: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
pc = {binsn_addr + branch_addrofs, 2'b0};
|
pc = {binsn_addr + branch_addrofs, 2'b0};
|
taken = 1'b1;
|
taken = 1'b1;
|
end
|
end
|
{2'b00, `OR1200_BRANCHOP_BF}:
|
{2'b00, `OR1200_BRANCHOP_BF}:
|
if (flag) begin
|
if (flag) begin
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("%t: BRANCHOP_BF: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
|
$display("%t: BRANCHOP_BF: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
pc = {binsn_addr + branch_addrofs, 2'b0};
|
pc = {binsn_addr + branch_addrofs, 2'b0};
|
taken = 1'b1;
|
taken = 1'b1;
|
end
|
end
|
else begin
|
else begin
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("%t: BRANCHOP_BF: not taken", $time);
|
$display("%t: BRANCHOP_BF: not taken", $time);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
pc = {pcreg + 'd1, 2'b0};
|
pc = {pcreg + 'd1, 2'b0};
|
taken = 1'b0;
|
taken = 1'b0;
|
end
|
end
|
{2'b00, `OR1200_BRANCHOP_BNF}:
|
{2'b00, `OR1200_BRANCHOP_BNF}:
|
if (flag) begin
|
if (flag) begin
|
pc = {pcreg + 'd1, 2'b0};
|
pc = {pcreg + 'd1, 2'b0};
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("%t: BRANCHOP_BNF: not taken", $time);
|
$display("%t: BRANCHOP_BNF: not taken", $time);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
taken = 1'b0;
|
taken = 1'b0;
|
end
|
end
|
else begin
|
else begin
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("%t: BRANCHOP_BNF: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
|
$display("%t: BRANCHOP_BNF: pc %h = binsn_addr %h + branch_addrofs %h", $time, binsn_addr + branch_addrofs, binsn_addr, branch_addrofs);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
pc = {binsn_addr + branch_addrofs, 2'b0};
|
pc = {binsn_addr + branch_addrofs, 2'b0};
|
taken = 1'b1;
|
taken = 1'b1;
|
end
|
end
|
{2'b00, `OR1200_BRANCHOP_RFE}: begin
|
{2'b00, `OR1200_BRANCHOP_RFE}: begin
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("%t: BRANCHOP_RFE: pc <= epcr %h", $time, epcr);
|
$display("%t: BRANCHOP_RFE: pc <= epcr %h", $time, epcr);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
pc = epcr;
|
pc = epcr;
|
taken = 1'b1;
|
taken = 1'b1;
|
end
|
end
|
{2'b01, 3'bxxx}: begin
|
{2'b01, 3'bxxx}: begin
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("Starting exception: %h.", except_type);
|
$display("Starting exception: %h.", except_type);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
pc = { {4{except_prefix}}, 16'h0000, except_type, 8'h00};
|
pc = { {4{except_prefix}}, 16'h0000, except_type, 8'h00};
|
taken = 1'b1;
|
taken = 1'b1;
|
end
|
end
|
default: begin
|
default: begin
|
`ifdef OR1200_VERBOSE
|
`ifdef OR1200_VERBOSE
|
// synopsys translate_off
|
// synopsys translate_off
|
$display("l.mtspr writing into PC: %h.", spr_dat_i);
|
$display("l.mtspr writing into PC: %h.", spr_dat_i);
|
// synopsys translate_on
|
// synopsys translate_on
|
`endif
|
`endif
|
pc = spr_dat_i;
|
pc = spr_dat_i;
|
taken = 1'b0;
|
taken = 1'b0;
|
end
|
end
|
endcase
|
endcase
|
end
|
end
|
|
|
//
|
//
|
// PC register
|
// PC register
|
//
|
//
|
always @(posedge clk or posedge rst)
|
always @(posedge clk or posedge rst)
|
if (rst)
|
if (rst)
|
pcreg <= #1 30'd63;
|
pcreg <= #1 30'd63;
|
else if (spr_pc_we)
|
else if (spr_pc_we)
|
pcreg <= #1 spr_dat_i[31:2];
|
pcreg <= #1 spr_dat_i[31:2];
|
else if (no_more_dslot | except_start | !genpc_freeze & !icpu_rty_i & !genpc_refetch)
|
else if (no_more_dslot | except_start | !genpc_freeze & !icpu_rty_i & !genpc_refetch)
|
// else if (except_start | !genpc_freeze & !icpu_rty_i & !genpc_refetch)
|
// else if (except_start | !genpc_freeze & !icpu_rty_i & !genpc_refetch)
|
pcreg <= #1 pc[31:2];
|
pcreg <= #1 pc[31:2];
|
|
|
endmodule
|
endmodule
|
|
|