URL
https://opencores.org/ocsvn/zipcpu/zipcpu/trunk
Subversion Repositories zipcpu
Compare Revisions
- This comparison shows the changes necessary to convert path
/zipcpu/trunk/rtl
- from Rev 69 to Rev 66
- ↔ Reverse comparison
Rev 69 → Rev 66
/zipsystem.v
60,7 → 60,7
// watchdog-timers, |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
108,6 → 108,7
// Slice LUTs ZipSystem ZipCPU |
// With Counters 3315 2432 |
// Without Counters 2796 2046 |
`define INCLUDE_ACCOUNTING_COUNTERS |
|
// |
// Now, where am I placing all of my peripherals? |
172,22 → 173,6
); |
parameter RESET_ADDRESS=24'h0100000, ADDRESS_WIDTH=24, |
LGICACHE=12, START_HALTED=1, EXTERNAL_INTERRUPTS=1, |
`ifdef OPT_MULTIPLY |
IMPLEMENT_MPY = 1, |
`else |
IMPLEMENT_MPY = 0, |
`endif |
`ifdef OPT_DIVIDE |
IMPLEMENT_DIVIDE=1, |
`else |
IMPLEMENT_DIVIDE=0, |
`endif |
`ifdef OPT_IMPLEMENT_FPU |
IMPLEMENT_FPU=0, |
`else |
IMPLEMENT_FPU=1, |
`endif |
IMPLEMENT_LOCK=1, |
// Derived parameters |
AW=ADDRESS_WIDTH; |
input i_clk, i_rst; |
215,44 → 200,6
|
wire [31:0] ext_idata; |
|
// Handle our interrupt vector generation/coordination |
wire [14:0] main_int_vector, alt_int_vector; |
wire ctri_int, tma_int, tmb_int, tmc_int, jif_int, dmac_int; |
wire mtc_int, moc_int, mpc_int, mic_int, |
utc_int, uoc_int, upc_int, uic_int; |
generate |
if (EXTERNAL_INTERRUPTS < 9) |
assign main_int_vector = { {(9-EXTERNAL_INTERRUPTS){1'b0}}, |
i_ext_int, ctri_int, |
tma_int, tmb_int, tmc_int, |
jif_int, dmac_int }; |
else |
assign main_int_vector = { i_ext_int[8:0], ctri_int, |
tma_int, tmb_int, tmc_int, |
jif_int, dmac_int }; |
endgenerate |
generate |
if (EXTERNAL_INTERRUPTS <= 9) |
`ifdef INCLUDE_ACCOUNTING_COUNTERS |
assign alt_int_vector = { 7'h00, |
mtc_int, moc_int, mpc_int, mic_int, |
utc_int, uoc_int, upc_int, uic_int }; |
`else |
assign alt_int_vector = { 15'h00 }; |
`endif |
else |
`ifdef INCLUDE_ACCOUNTING_COUNTERS |
assign alt_int_vector = { {(7-(EXTERNAL_INTERRUPTS-9)){1'b0}}, |
i_ext_int[(EXTERNAL_INTERRUPTS-1):9], |
mtc_int, moc_int, mpc_int, mic_int, |
utc_int, uoc_int, upc_int, uic_int }; |
`else |
assign alt_int_vector = { {(15-(EXTERNAL_INTERRUPTS-9)){1'b0}}, |
i_ext_int[(EXTERNAL_INTERRUPTS-1):9] }; |
`endif |
endgenerate |
|
|
// Delay the debug port by one clock, to meet timing requirements |
wire dbg_cyc, dbg_stb, dbg_we, dbg_addr, dbg_stall; |
wire [31:0] dbg_idata, dbg_odata; |
339,7 → 286,7
// Values: |
// 0x0003f -> cmd_addr mask |
// 0x00040 -> reset |
// 0x00080 -> PIC interrrupt pending |
// 0x00080 -> PIC interrrupts enabled |
// 0x00100 -> cmd_step |
// 0x00200 -> cmd_stall |
// 0x00400 -> cmd_halt |
346,21 → 293,11
// 0x00800 -> cmd_clear_pf_cache |
// 0x01000 -> cc.sleep |
// 0x02000 -> cc.gie |
// 0x04000 -> External (PIC) interrupt line is high |
// Other external interrupts follow |
generate |
if (EXTERNAL_INTERRUPTS < 16) |
assign cmd_data = { {(16-EXTERNAL_INTERRUPTS){1'b0}}, |
i_ext_int, |
cpu_dbg_cc, // 4 bits |
1'b0, cmd_halt, (~cpu_dbg_stall), 1'b0, |
pic_data[15], cpu_reset, cmd_addr }; |
else |
assign cmd_data = { i_ext_int[15:0], cpu_dbg_cc, |
1'b0, cmd_halt, (~cpu_dbg_stall), 1'b0, |
pic_data[15], cpu_reset, cmd_addr }; |
endgenerate |
|
// 0x10000 -> External interrupt line is high |
assign cmd_data = { 7'h00, {(9-EXTERNAL_INTERRUPTS){1'b0}}, i_ext_int, |
cpu_dbg_cc, |
1'b0, cmd_halt, (~cpu_dbg_stall), 1'b0, |
pic_data[15], cpu_reset, cmd_addr }; |
wire cpu_gie; |
assign cpu_gie = cpu_dbg_cc[1]; |
|
396,13 → 333,17
reg [(AW-1):0] r_wdbus_data; |
wire [31:0] wdbus_data; |
wire [14:0] wdbus_ignored_data; |
wire reset_wdbus_timer, wdbus_int; |
wire reset_wdbus_timer, wdbus_int, wdbus_ack_ignored, wdbus_stall; |
assign reset_wdbus_timer = ((o_wb_cyc)&&((o_wb_stb)||(i_wb_ack))); |
wbwatchdog #(14) watchbus(i_clk,(cpu_reset)||(reset_wdbus_timer), |
o_wb_cyc, 14'h2000, wdbus_int); |
// o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, |
// i_wb_ack, i_wb_stall, i_wb_data, i_wb_err, |
ziptimer #(15) watchbus(i_clk, (cpu_reset), o_wb_cyc, |
reset_wdbus_timer, reset_wdbus_timer, 1'b1, 15'h2000, |
wdbus_ack_ignored, wdbus_stall, wdbus_ignored_data, |
wdbus_int); |
initial r_wdbus_data = 0; |
always @(posedge i_clk) |
if ((wdbus_int)||(cpu_ext_err)) |
if (wdbus_int) |
r_wdbus_data = o_wb_addr; |
assign wdbus_data = { {(32-AW){1'b0}}, r_wdbus_data }; |
initial wdbus_ack = 1'b0; |
421,7 → 362,7
// for an overall counter. |
// |
// Master task counter |
wire mtc_ack, mtc_stall; |
wire mtc_ack, mtc_stall, mtc_int; |
wire [31:0] mtc_data; |
zipcounter mtask_ctr(i_clk, (~cpu_halt), sys_cyc, |
(sys_stb)&&(sys_addr == `MSTR_TASK_CTR), |
429,7 → 370,7
mtc_ack, mtc_stall, mtc_data, mtc_int); |
|
// Master Operand Stall counter |
wire moc_ack, moc_stall; |
wire moc_ack, moc_stall, moc_int; |
wire [31:0] moc_data; |
zipcounter mmstall_ctr(i_clk,(cpu_op_stall), sys_cyc, |
(sys_stb)&&(sys_addr == `MSTR_MSTL_CTR), |
437,7 → 378,7
moc_ack, moc_stall, moc_data, moc_int); |
|
// Master PreFetch-Stall counter |
wire mpc_ack, mpc_stall; |
wire mpc_ack, mpc_stall, mpc_int; |
wire [31:0] mpc_data; |
zipcounter mpstall_ctr(i_clk,(cpu_pf_stall), sys_cyc, |
(sys_stb)&&(sys_addr == `MSTR_PSTL_CTR), |
445,7 → 386,7
mpc_ack, mpc_stall, mpc_data, mpc_int); |
|
// Master Instruction counter |
wire mic_ack, mic_stall; |
wire mic_ack, mic_stall, mic_int; |
wire [31:0] mic_data; |
zipcounter mins_ctr(i_clk,(cpu_i_count), sys_cyc, |
(sys_stb)&&(sys_addr == `MSTR_INST_CTR), |
457,7 → 398,7
// be reset any time a task is given control of the CPU. |
// |
// User task counter |
wire utc_ack, utc_stall; |
wire utc_ack, utc_stall, utc_int; |
wire [31:0] utc_data; |
zipcounter utask_ctr(i_clk,(~cpu_halt)&&(cpu_gie), sys_cyc, |
(sys_stb)&&(sys_addr == `USER_TASK_CTR), |
465,7 → 406,7
utc_ack, utc_stall, utc_data, utc_int); |
|
// User Op-Stall counter |
wire uoc_ack, uoc_stall; |
wire uoc_ack, uoc_stall, uoc_int; |
wire [31:0] uoc_data; |
zipcounter umstall_ctr(i_clk,(cpu_op_stall)&&(cpu_gie), sys_cyc, |
(sys_stb)&&(sys_addr == `USER_MSTL_CTR), |
473,7 → 414,7
uoc_ack, uoc_stall, uoc_data, uoc_int); |
|
// User PreFetch-Stall counter |
wire upc_ack, upc_stall; |
wire upc_ack, upc_stall, upc_int; |
wire [31:0] upc_data; |
zipcounter upstall_ctr(i_clk,(cpu_pf_stall)&&(cpu_gie), sys_cyc, |
(sys_stb)&&(sys_addr == `USER_PSTL_CTR), |
481,7 → 422,7
upc_ack, upc_stall, upc_data, upc_int); |
|
// User instruction counter |
wire uic_ack, uic_stall; |
wire uic_ack, uic_stall, uic_int; |
wire [31:0] uic_data; |
zipcounter uins_ctr(i_clk,(cpu_i_count)&&(cpu_gie), sys_cyc, |
(sys_stb)&&(sys_addr == `USER_INST_CTR), |
528,7 → 469,7
// |
// The DMA Controller |
// |
wire dmac_stb, dc_err; |
wire dmac_int, dmac_stb, dc_err; |
wire [31:0] dmac_data; |
wire dmac_ack, dmac_stall; |
wire dc_cyc, dc_stb, dc_we, dc_ack, dc_stall; |
536,6 → 477,7
wire [(AW-1):0] dc_addr; |
wire cpu_gbl_cyc; |
assign dmac_stb = (sys_stb)&&(sys_addr[4]); |
`define INCLUDE_DMA_CONTROLLER |
`ifdef INCLUDE_DMA_CONTROLLER |
wbdmac #(AW) dma_controller(i_clk, |
sys_cyc, dmac_stb, sys_we, |
545,16 → 487,11
dc_cyc, dc_stb, dc_we, dc_addr, dc_data, |
dc_ack, dc_stall, ext_idata, dc_err, |
// External device interrupts |
{ 1'b0, alt_int_vector, 1'b0, |
main_int_vector[14:1], 1'b0 }, |
{ {(32-EXTERNAL_INTERRUPTS){1'b0}}, i_ext_int }, |
// DMAC interrupt, for upon completion |
dmac_int); |
// Whether or not the CPU wants the bus, and |
// thus we must kick the DMAC off. |
// However, the logic required for this |
// override never worked well, so here |
// we just don't use it. |
// cpu_gbl_cyc); |
dmac_int, |
// Whether or not the CPU wants the bus |
cpu_gbl_cyc); |
`else |
reg r_dmac_ack; |
always @(posedge i_clk) |
572,50 → 509,33
assign dmac_int = 1'b0; |
`endif |
|
wire ctri_sel; |
reg ctri_ack; |
assign ctri_sel = (sys_cyc)&&(sys_stb)&&(sys_addr == `CTRINT); |
always @(posedge i_clk) |
ctri_ack <= ctri_sel; |
|
`ifdef INCLUDE_ACCOUNTING_COUNTERS |
// |
// Counter Interrupt controller |
// |
wire ctri_stall; |
reg ctri_ack; |
wire ctri_stall, ctri_int, ctri_sel; |
wire [7:0] ctri_vector; |
wire [31:0] ctri_data; |
|
generate |
if (EXTERNAL_INTERRUPTS <= 9) |
begin |
icontrol #(8) ctri(i_clk, cpu_reset, (ctri_sel), |
sys_data, ctri_data, alt_int_vector[7:0], |
ctri_int); |
end else begin |
icontrol #(8+(EXTERNAL_INTERRUPTS-9)) |
ctri(i_clk, cpu_reset, (ctri_sel), |
sys_data, ctri_data, |
alt_int_vector[(EXTERNAL_INTERRUPTS-1):0], |
ctri_int); |
end endgenerate |
|
assign ctri_sel = (sys_cyc)&&(sys_stb)&&(sys_addr == `CTRINT); |
assign ctri_vector = { mtc_int, moc_int, mpc_int, mic_int, |
utc_int, uoc_int, upc_int, uic_int }; |
icontrol #(8) ctri(i_clk, cpu_reset, (ctri_sel)&&(sys_addr==`CTRINT), |
sys_data, ctri_data, ctri_vector, ctri_int); |
always @(posedge i_clk) |
ctri_ack <= ctri_sel; |
assign ctri_stall = 1'b0; |
`else // INCLUDE_ACCOUNTING_COUNTERS |
reg ctri_ack; |
wire ctri_stall, ctri_int; |
wire [31:0] ctri_data; |
assign ctri_stall = 1'b0; |
assign ctri_data = 32'h0000; |
assign ctri_int = 1'b0; |
|
generate |
if (EXTERNAL_INTERRUPTS <= 9) |
begin |
wire ctri_stall, ctri_int; |
wire [31:0] ctri_data; |
assign ctri_stall = 1'b0; |
assign ctri_data = 32'h0000; |
assign ctri_int = 1'b0; |
end else begin |
icontrol #(EXTERNAL_INTERRUPTS-9) |
ctri(i_clk, cpu_reset, (ctri_sel), |
sys_data, ctri_data, |
alt_int_vector[(EXTERNAL_INTERRUPTS-10):0], |
ctri_int); |
end endgenerate |
always @(posedge i_clk) |
ctri_ack <= (sys_cyc)&&(sys_stb)&&(sys_addr == `CTRINT); |
`endif // INCLUDE_ACCOUNTING_COUNTERS |
|
|
622,7 → 542,7
// |
// Timer A |
// |
wire tma_ack, tma_stall; |
wire tma_ack, tma_stall, tma_int; |
wire [31:0] tma_data; |
ziptimer timer_a(i_clk, cpu_reset, ~cmd_halt, |
sys_cyc, (sys_stb)&&(sys_addr == `TIMER_A), sys_we, |
632,7 → 552,7
// |
// Timer B |
// |
wire tmb_ack, tmb_stall; |
wire tmb_ack, tmb_stall, tmb_int; |
wire [31:0] tmb_data; |
ziptimer timer_b(i_clk, cpu_reset, ~cmd_halt, |
sys_cyc, (sys_stb)&&(sys_addr == `TIMER_B), sys_we, |
642,7 → 562,7
// |
// Timer C |
// |
wire tmc_ack, tmc_stall; |
wire tmc_ack, tmc_stall, tmc_int; |
wire [31:0] tmc_data; |
ziptimer timer_c(i_clk, cpu_reset, ~cmd_halt, |
sys_cyc, (sys_stb)&&(sys_addr == `TIMER_C), sys_we, |
652,7 → 572,7
// |
// JIFFIES |
// |
wire jif_ack, jif_stall; |
wire jif_ack, jif_stall, jif_int; |
wire [31:0] jif_data; |
zipjiffies jiffies(i_clk, ~cmd_halt, |
sys_cyc, (sys_stb)&&(sys_addr == `JIFFIES), sys_we, |
663,22 → 583,14
// The programmable interrupt controller peripheral |
// |
wire pic_interrupt; |
generate |
if (EXTERNAL_INTERRUPTS < 9) |
begin |
icontrol #(6+EXTERNAL_INTERRUPTS) pic(i_clk, cpu_reset, |
(sys_cyc)&&(sys_stb)&&(sys_we) |
&&(sys_addr==`INTCTRL), |
sys_data, pic_data, |
main_int_vector[(6+EXTERNAL_INTERRUPTS-1):0], pic_interrupt); |
end else begin |
icontrol #(15) pic(i_clk, cpu_reset, |
(sys_cyc)&&(sys_stb)&&(sys_we) |
&&(sys_addr==`INTCTRL), |
sys_data, pic_data, |
main_int_vector[14:0], pic_interrupt); |
end endgenerate |
|
wire [(5+EXTERNAL_INTERRUPTS):0] int_vector; |
assign int_vector = { i_ext_int, ctri_int, tma_int, tmb_int, tmc_int, |
jif_int, dmac_int }; |
icontrol #(6+EXTERNAL_INTERRUPTS) pic(i_clk, cpu_reset, |
(sys_cyc)&&(sys_stb)&&(sys_we) |
&&(sys_addr==`INTCTRL), |
sys_data, pic_data, |
int_vector, pic_interrupt); |
wire pic_stall; |
assign pic_stall = 1'b0; |
reg pic_ack; |
695,8 → 607,7
wire [31:0] cpu_dbg_data; |
assign cpu_dbg_we = ((dbg_cyc)&&(dbg_stb)&&(~cmd_addr[5]) |
&&(dbg_we)&&(dbg_addr)); |
zipcpu #(RESET_ADDRESS,ADDRESS_WIDTH,LGICACHE, IMPLEMENT_MPY, |
IMPLEMENT_DIVIDE, IMPLEMENT_FPU, IMPLEMENT_LOCK) |
zipcpu #(RESET_ADDRESS,ADDRESS_WIDTH,LGICACHE) |
thecpu(i_clk, cpu_reset, pic_interrupt, |
cpu_halt, cmd_clear_pf_cache, cmd_addr[4:0], cpu_dbg_we, |
dbg_idata, cpu_dbg_stall, cpu_dbg_data, |
797,7 → 708,7
|
assign sys_stall = (tma_stall | tmb_stall | tmc_stall | jif_stall |
| wdt_stall | ctri_stall | actr_stall |
| pic_stall | dmac_stall); |
| pic_stall | dmac_stall | wdbus_stall); |
assign cpu_stall = (sys_stall)|(cpu_ext_stall); |
assign sys_ack = (tmr_ack|wdt_ack|ctri_ack|actr_ack|pic_ack|dmac_ack|wdbus_ack); |
assign cpu_ack = (sys_ack)||(cpu_ext_ack); |
/zipbones.v
9,7 → 9,7
// need to be implemented off-module. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
47,7 → 47,7
`endif |
); |
parameter RESET_ADDRESS=32'h0100000, ADDRESS_WIDTH=32, |
LGICACHE=6, START_HALTED=0, |
LGICACHE=6, START_HALTED=1, |
AW=ADDRESS_WIDTH; |
input i_clk, i_rst; |
// Wishbone master |
104,7 → 104,7
always @(posedge i_clk) |
cmd_reset <= ((dbg_cmd_write)&&(i_dbg_data[6])); |
// |
initial cmd_halt = START_HALTED; |
initial cmd_halt = 1'b1; |
always @(posedge i_clk) |
if (i_rst) |
cmd_halt <= (START_HALTED == 1)? 1'b1 : 1'b0; |
/core/idecode.v
File deleted
/core/div.v
File deleted
/core/idecode_deprecated.v
File deleted
/core/pfcache.v
File deleted
/core/cpuops_deprecated.v
File deleted
/core/zipcpu.v
32,42 → 32,8
// to the spec.pdf for accurate and up to date information.) |
// |
// |
// In general, the pipelining is controlled by three pieces of logic |
// per stage: _ce, _stall, and _valid. _valid means that the stage |
// holds a valid instruction. _ce means that the instruction from the |
// previous stage is to move into this one, and _stall means that the |
// instruction from the previous stage may not move into this one. |
// The difference between these control signals allows individual stages |
// to propagate instructions independently. In general, the logic works |
// as: |
// |
// |
// assign (n)_ce = (n-1)_valid && (~(n)_stall) |
// |
// |
// always @(posedge i_clk) |
// if ((i_rst)||(clear_pipeline)) |
// (n)_valid = 0 |
// else if (n)_ce |
// (n)_valid = 1 |
// else if (n+1)_ce |
// (n)_valid = 0 |
// |
// assign (n)_stall = ( (n-1)_valid && ( pipeline hazard detection ) ) |
// || ( (n)_valid && (n+1)_stall ); |
// |
// and ... |
// |
// always @(posedge i_clk) |
// if (n)_ce |
// (n)_variable = ... whatever logic for this stage |
// |
// Note that a stage can stall even if no instruction is loaded into |
// it. |
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////////// |
// |
103,13 → 69,11
// |
`define CPU_CC_REG 4'he |
`define CPU_PC_REG 4'hf |
`define CPU_FPUERR_BIT 12 // Floating point error flag, set on error |
`define CPU_DIVERR_BIT 11 // Divide error flag, set on divide by zero |
`define CPU_BUSERR_BIT 10 // Bus error flag, set on error |
`define CPU_TRAP_BIT 9 // User TRAP has taken place |
`define CPU_ILL_BIT 8 // Illegal instruction |
`define CPU_BUSERR_BIT 10 |
`define CPU_TRAP_BIT 9 |
`define CPU_ILL_BIT 8 |
`define CPU_BREAK_BIT 7 |
`define CPU_STEP_BIT 6 // Will step one or two (VLIW) instructions |
`define CPU_STEP_BIT 6 |
`define CPU_GIE_BIT 5 |
`define CPU_SLEEP_BIT 4 |
// Compile time defines |
117,6 → 81,11
`include "cpudefs.v" |
// |
// |
// |
// `define DEBUG_SCOPE |
// |
// |
// |
module zipcpu(i_clk, i_rst, i_interrupt, |
// Debug interface |
i_halt, i_clear_pf_cache, i_dbg_reg, i_dbg_we, i_dbg_data, |
135,20 → 104,12
`endif |
); |
parameter RESET_ADDRESS=32'h0100000, ADDRESS_WIDTH=24, |
LGICACHE=6; |
LGICACHE=6, AW=ADDRESS_WIDTH; |
`ifdef OPT_MULTIPLY |
parameter IMPLEMENT_MPY = 1; |
`else |
parameter IMPLEMENT_MPY = 0; |
`endif |
parameter IMPLEMENT_DIVIDE = 1, IMPLEMENT_FPU = 0, |
IMPLEMENT_LOCK=1; |
`ifdef OPT_EARLY_BRANCHING |
parameter EARLY_BRANCHING = 1; |
`else |
parameter EARLY_BRANCHING = 0; |
`endif |
parameter AW=ADDRESS_WIDTH; |
input i_clk, i_rst, i_interrupt; |
// Debug interface -- inputs |
input i_halt, i_clear_pf_cache; |
194,7 → 155,7
// Condition codes |
// (BUS, TRAP,ILL,BREAKEN,STEP,GIE,SLEEP ), V, N, C, Z |
reg [3:0] flags, iflags; |
wire [12:0] w_uflags, w_iflags; |
wire [10:0] w_uflags, w_iflags; |
reg trap, break_en, step, gie, sleep; |
`ifdef OPT_ILLEGAL_INSTRUCTION |
reg ill_err_u, ill_err_i; |
202,9 → 163,6
wire ill_err_u, ill_err_i; |
`endif |
reg ibus_err_flag, ubus_err_flag; |
wire idiv_err_flag, udiv_err_flag; |
wire ifpu_err_flag, ufpu_err_flag; |
wire ihalt_phase, uhalt_phase; |
|
// The master chip enable |
wire master_ce; |
215,9 → 173,9
// Variable declarations |
// |
reg [(AW-1):0] pf_pc; |
reg new_pc; |
reg new_pc, op_break; |
wire clear_pipeline; |
assign clear_pipeline = new_pc || i_clear_pf_cache; |
assign clear_pipeline = new_pc || i_clear_pf_cache; // || op_break; |
|
wire dcd_stalled; |
wire pf_cyc, pf_stb, pf_we, pf_busy, pf_ack, pf_stall, pf_err; |
234,25 → 192,33
// |
// |
reg opvalid, opvalid_mem, opvalid_alu, op_wr_pc; |
reg opvalid_div, opvalid_fpu; |
wire op_stall, dcd_ce, dcd_phase; |
wire [3:0] dcdOp; |
wire [4:0] dcdA, dcdB, dcdR; |
wire dcdA_cc, dcdB_cc, dcdA_pc, dcdB_pc, dcdR_cc, dcdR_pc; |
wire [3:0] dcdF; |
wire dcdR_wr, dcdA_rd, dcdB_rd, |
dcdALU, dcdM, dcdDV, dcdFP, |
dcdF_wr, dcd_gie, dcd_break, dcd_lock; |
reg r_dcdvalid; |
wire dcdvalid; |
wire [(AW-1):0] dcd_pc; |
wire [31:0] dcdI; |
wire dcd_zI; // true if dcdI == 0 |
wire op_stall, dcd_ce; |
reg [3:0] dcdOp; |
reg [4:0] dcdA, dcdB; |
reg dcdA_cc, dcdB_cc, dcdA_pc, dcdB_pc; |
reg [3:0] dcdF; |
reg dcdA_rd, dcdA_wr, dcdB_rd, dcdvalid, |
dcdM, dcdF_wr, dcd_gie, dcd_break; |
reg [(AW-1):0] dcd_pc; |
reg [23:0] r_dcdI; |
`ifdef OPT_SINGLE_CYCLE |
reg dcd_zI; // true if dcdI == 0 |
`endif |
wire dcdA_stall, dcdB_stall, dcdF_stall; |
|
wire dcd_illegal; |
wire dcd_early_branch; |
`ifdef OPT_PRECLEAR_BUS |
reg dcd_clear_bus; |
`endif |
`ifdef OPT_ILLEGAL_INSTRUCTION |
reg dcd_illegal; |
`endif |
`ifdef OPT_EARLY_BRANCHING |
reg dcd_early_branch_stb, dcd_early_branch; |
reg [(AW-1):0] dcd_branch_pc; |
`else |
wire dcd_early_branch_stb, dcd_early_branch; |
wire [(AW-1):0] dcd_branch_pc; |
`endif |
|
|
// |
271,21 → 237,22
wire [31:0] w_opA, w_opB; |
wire [31:0] opA_nowait, opB_nowait, opA, opB; |
reg opR_wr, opR_cc, opF_wr, op_gie; |
wire [12:0] opFl; |
wire [10:0] opFl; |
reg [5:0] r_opF; |
wire [7:0] opF; |
reg [2:0] opF_cp; |
wire op_ce, op_phase; |
wire op_ce; |
// Some pipeline control wires |
`ifdef OPT_PIPELINED |
`ifdef OPT_SINGLE_CYCLE |
reg opA_alu, opA_mem; |
reg opB_alu, opB_mem; |
`endif |
`ifdef OPT_PRECLEAR_BUS |
reg op_clear_bus; |
`endif |
`ifdef OPT_ILLEGAL_INSTRUCTION |
reg op_illegal; |
`endif |
reg op_break; |
wire op_lock; |
|
|
// |
295,8 → 262,7
// |
// |
reg [(AW-1):0] alu_pc; |
reg alu_pc_valid; |
wire alu_phase; |
reg alu_pc_valid;; |
wire alu_ce, alu_stall; |
wire [31:0] alu_result; |
wire [3:0] alu_flags; |
321,23 → 287,8
wire [31:0] mem_data, mem_result; |
reg [4:0] mem_last_reg; // Last register result to go in |
|
wire div_ce, div_error, div_busy, div_valid; |
wire [31:0] div_result; |
wire [3:0] div_flags; |
|
assign div_ce = (master_ce)&&(~clear_pipeline)&&(opvalid_div) |
&&(~mem_rdbusy)&&(~div_busy)&&(~fpu_busy) |
&&(set_cond); |
|
wire fpu_ce, fpu_error, fpu_busy, fpu_valid; |
wire [31:0] fpu_result; |
wire [3:0] fpu_flags; |
|
assign fpu_ce = (master_ce)&&(~clear_pipeline)&&(opvalid_fpu) |
&&(~mem_rdbusy)&&(~div_busy)&&(~fpu_busy) |
&&(set_cond); |
|
|
// |
// |
// PIPELINE STAGE #5 :: Write-back |
367,68 → 318,37
// |
// PIPELINE STAGE #2 :: Instruction Decode |
// Calculate stall conditions |
`ifdef OPT_PIPELINED |
assign dcd_ce = ((~dcdvalid)||(~dcd_stalled))&&(~clear_pipeline); |
`else |
assign dcd_ce = 1'b1; |
`endif |
`ifdef OPT_PIPELINED |
assign dcd_stalled = (dcdvalid)&&(op_stall); |
`else |
// If not pipelined, there will be no opvalid_ anything, and the |
// op_stall will be false, dcdX_stall will be false, thus we can simply |
// do a ... |
assign dcd_stalled = 1'b0; |
`endif |
assign dcd_ce = (pf_valid)&&(~dcd_stalled)&&(~clear_pipeline); |
assign dcd_stalled = (dcdvalid)&&( |
(op_stall) |
||((dcdA_stall)||(dcdB_stall)||(dcdF_stall)) |
||((opvalid_mem)&&(op_wr_pc)) |
||((opvalid_mem)&&(opR_cc))); |
// |
// PIPELINE STAGE #3 :: Read Operands |
// Calculate stall conditions |
wire op_lock_stall; |
`ifdef OPT_PIPELINED |
assign op_stall = (opvalid)&&( // Only stall if we're loaded w/validins |
// Stall if we're stopped, and not allowed to execute |
// an instruction |
// (~master_ce) // Already captured in alu_stall |
// |
assign op_stall = ((opvalid)&&(~master_ce))||( |
// Stall if going into the ALU and the ALU is stalled |
// i.e. if the memory is busy, or we are single |
// stepping. This also includes our stalls for |
// op_break and op_lock, so we don't need to |
// include those as well here. |
((opvalid)&&(alu_stall)) |
// Stall if the divide is busy, since we can't have |
// two parallel stages writing back at the same time |
||(div_busy) |
// Same for the floating point unit |
||(fpu_busy) |
// stepping |
((opvalid_alu)&&(alu_stall)) |
// |
// ||((opvalid_alu)&&(mem_rdbusy)) // part of alu_stall |
// Stall if we are going into memory with an operation |
// that cannot be pipelined, and the memory is |
// already busy |
||((opvalid_mem)&&(mem_stalled)) |
) |
||(dcdvalid)&&( |
// Stall if we've got a read going with an |
// unknown output (known w/in the memory module) |
(mem_rdbusy) |
// Or if we need to wait for an operand A |
// to be ready to read |
||(dcdA_stall) |
// Likewise for B, also includes logic |
// regarding immediate offset (register must |
// be in register file if we need to add to |
// an immediate) |
||(dcdB_stall) |
// Or if we need to wait on flags to work on the |
// CC register |
||(dcdF_stall) |
); |
assign op_ce = (dcdvalid)&&((~opvalid)||(~op_stall))&&(~clear_pipeline); |
`ifdef OPT_PIPELINED_BUS_ACCESS |
||((opvalid_mem)&&(~op_pipe)&&(mem_busy)) |
// |
// Stall if we are going into memory with a pipeable |
// operation, but the memory unit declares it is |
// not going to accept any more pipeline operations |
||((opvalid_mem)&&( op_pipe)&&(mem_pipe_stalled)) |
`else |
assign op_stall = (opvalid)&&(~master_ce); |
assign op_ce = (dcdvalid); |
||((opvalid_mem)&&(mem_busy)) |
`endif |
); |
assign op_ce = (dcdvalid)&&((~opvalid)||(~op_stall)); |
|
// |
// PIPELINE STAGE #4 :: ALU / Memory |
443,22 → 363,12
// 4. Last case: Stall if we would otherwise move a break instruction |
// through the ALU. Break instructions are not allowed through |
// the ALU. |
`ifdef OPT_PIPELINED |
assign alu_stall = (((~master_ce)||(mem_rdbusy))&&(opvalid_alu)) //Case 1&2 |
// Old case #3--this isn't an ALU stall though ... |
||((opvalid_alu)&&(wr_reg_ce)&&(wr_reg_id[4] == op_gie) |
&&(wr_write_cc)) // Case 3 |
||((opvalid)&&(op_lock)&&(op_lock_stall)) |
||((opvalid)&&(op_break)) |
||(div_busy)||(fpu_busy); |
assign alu_ce = (master_ce)&&(opvalid_alu) |
&&(~alu_stall) |
&&(~clear_pipeline); |
`else |
assign alu_stall = ((~master_ce)&&(opvalid_alu)) |
||((opvalid_alu)&&(op_break)); |
assign alu_ce = (master_ce)&&(opvalid_alu)&&(~alu_stall); |
`endif |
||((opvalid_alu)&&(op_break)); // Case 3 |
assign alu_ce = (master_ce)&&(~mem_rdbusy)&&(opvalid_alu)&&(~alu_stall)&&(~clear_pipeline); |
// |
|
// |
465,22 → 375,12
// Note: if you change the conditions for mem_ce, you must also change |
// alu_pc_valid. |
// |
`ifdef OPT_PIPELINED |
assign mem_ce = (master_ce)&&(opvalid_mem)&&(~mem_stalled) |
&&(~clear_pipeline)&&(set_cond); |
`else |
// If we aren't pipelined, then no one will be changing what's in the |
// pipeline (i.e. clear_pipeline), while our only instruction goes |
// through the ... pipeline. |
assign mem_ce = (master_ce)&&(opvalid_mem) |
assign mem_ce = (master_ce)&&(opvalid_mem)&&(~clear_pipeline) |
&&(set_cond)&&(~mem_stalled); |
`endif |
`ifdef OPT_PIPELINED_BUS_ACCESS |
assign mem_stalled = (~master_ce)||((opvalid_mem)&&( |
(mem_pipe_stalled) |
||((~op_pipe)&&(mem_busy)) |
||(div_busy) |
||(fpu_busy) |
// Stall waiting for flags to be valid |
// Or waiting for a write to the PC register |
// Or CC register, since that can change the |
488,7 → 388,6
||((wr_reg_ce)&&(wr_reg_id[4] == op_gie) |
&&((wr_write_pc)||(wr_write_cc))))); |
`else |
`ifdef OPT_PIPELINED |
assign mem_stalled = (mem_busy)||((opvalid_mem)&&( |
(~master_ce) |
// Stall waiting for flags to be valid |
496,10 → 395,7
// Or CC register, since that can change the |
// PC as well |
||((wr_reg_ce)&&(wr_reg_id[4] == op_gie)&&((wr_write_pc)||(wr_write_cc))))); |
`else |
assign mem_stalled = (opvalid_mem)&&(~master_ce); |
`endif |
`endif |
|
|
// |
510,100 → 406,276
`ifdef OPT_SINGLE_FETCH |
wire pf_ce; |
|
assign pf_ce = (~pf_valid)&&(~dcdvalid)&&(~opvalid)&&(~alu_valid); |
assign pf_ce = (~dcd_stalled); |
prefetch #(ADDRESS_WIDTH) |
pf(i_clk, i_rst, (pf_ce), (~dcd_stalled), pf_pc, gie, |
pf(i_clk, i_rst, (pf_ce), pf_pc, gie, |
instruction, instruction_pc, instruction_gie, |
pf_valid, pf_illegal, |
pf_cyc, pf_stb, pf_we, pf_addr, pf_data, |
pf_ack, pf_stall, pf_err, i_wb_data); |
|
initial r_dcdvalid = 1'b0; |
always @(posedge i_clk) |
if (i_rst) |
r_dcdvalid <= 1'b0; |
else if (dcd_ce) |
r_dcdvalid <= (pf_valid)&&(~clear_pipeline)&&((~r_dcdvalid)||(~dcd_early_branch)); |
else if ((op_ce)||(clear_pipeline)) |
r_dcdvalid <= 1'b0; |
assign dcdvalid = r_dcdvalid; |
|
`else // Pipe fetch |
|
`ifdef OPT_TRADITIONAL_PFCACHE |
pfcache #(LGICACHE, ADDRESS_WIDTH) |
pf(i_clk, i_rst, (new_pc)||((dcd_early_branch)&&(dcdvalid)), |
i_clear_pf_cache, |
// dcd_pc, |
~dcd_stalled, |
((dcd_early_branch)&&(dcdvalid)&&(~new_pc)) |
? dcd_branch_pc:pf_pc, |
instruction, instruction_pc, pf_valid, |
pf_cyc, pf_stb, pf_we, pf_addr, pf_data, |
pf_ack, pf_stall, pf_err, i_wb_data, |
pf_illegal); |
`else |
pipefetch #(RESET_ADDRESS, LGICACHE, ADDRESS_WIDTH) |
pf(i_clk, i_rst, (new_pc)||((dcd_early_branch)&&(dcdvalid)), |
pf(i_clk, i_rst, (new_pc)|(dcd_early_branch_stb), |
i_clear_pf_cache, ~dcd_stalled, |
(new_pc)?pf_pc:dcd_branch_pc, |
instruction, instruction_pc, pf_valid, |
pf_cyc, pf_stb, pf_we, pf_addr, pf_data, |
pf_ack, pf_stall, pf_err, i_wb_data, |
//`ifdef OPT_PRECLEAR_BUS |
//((dcd_clear_bus)&&(dcdvalid)) |
//||((op_clear_bus)&&(opvalid)) |
//|| |
//`endif |
`ifdef OPT_PRECLEAR_BUS |
((dcd_clear_bus)&&(dcdvalid)) |
||((op_clear_bus)&&(opvalid)) |
|| |
`endif |
(mem_cyc_lcl)||(mem_cyc_gbl), |
pf_illegal); |
assign instruction_gie = gie; |
`endif |
assign instruction_gie = gie; |
|
initial r_dcdvalid = 1'b0; |
initial dcdvalid = 1'b0; |
always @(posedge i_clk) |
if ((i_rst)||(clear_pipeline)) |
r_dcdvalid <= 1'b0; |
if (i_rst) |
dcdvalid <= 1'b0; |
else if (dcd_ce) |
r_dcdvalid <= (pf_valid)&&(~clear_pipeline)&&((~r_dcdvalid)||(~dcd_early_branch)); |
else if (op_ce) |
r_dcdvalid <= 1'b0; |
assign dcdvalid = r_dcdvalid; |
dcdvalid <= (~clear_pipeline)&&(~dcd_early_branch_stb); |
else if ((~dcd_stalled)||(clear_pipeline)||(dcd_early_branch)) |
dcdvalid <= 1'b0; |
|
`ifdef OPT_EARLY_BRANCHING |
always @(posedge i_clk) |
if ((dcd_ce)&&(instruction[27:24]==`CPU_PC_REG)&&(master_ce)) |
begin |
dcd_early_branch <= 1'b0; |
// First case, a move to PC instruction |
if ((instruction[31:28] == 4'h2) |
// Offsets of the PC register *only* |
&&(instruction[19:16] == `CPU_PC_REG) |
&&((instruction_gie) |
||((~instruction[20])&&(~instruction[15]))) |
&&(instruction[23:21]==3'h0)) // Unconditional |
begin |
dcd_early_branch_stb <= 1'b1; |
dcd_early_branch <= 1'b1; |
// r_dcdI <= { {(17){instruction[14]}}, instruction[14:0] }; |
|
end else // Next case, an Add Imm -> PC instruction |
if ((instruction[31:28] == 4'ha) // Add |
&&(~instruction[20]) // Immediate |
&&(instruction[23:21]==3'h0)) // Always |
begin |
dcd_early_branch_stb <= 1'b1; |
dcd_early_branch <= 1'b1; |
// r_dcdI <= { {(4){instruction[19]}}, instruction[19:0] }; |
end else // Next case: load Immediate to PC |
if (instruction[31:28] == 4'h3) |
begin |
dcd_early_branch_stb <= 1'b1; |
dcd_early_branch <= 1'b1; |
// r_dcdI <= { instruction[23:0] }; |
end |
end else |
begin |
if (dcd_ce) dcd_early_branch <= 1'b0; |
dcd_early_branch_stb <= 1'b0; |
end |
generate |
if (AW == 24) |
begin |
always @(posedge i_clk) |
if (dcd_ce) |
begin |
if (instruction[31]) // Add |
begin |
dcd_branch_pc <= instruction_pc |
+ { {(AW-20){instruction[19]}}, instruction[19:0] } |
+ {{(AW-1){1'b0}},1'b1}; |
end else if (~instruction[28]) // 4'h2 = MOV |
dcd_branch_pc <= instruction_pc+{ {(AW-15){instruction[14]}}, instruction[14:0] } + {{(AW-1){1'b0}},1'b1}; |
else // if (instruction[28]) // 4'h3 = LDI |
dcd_branch_pc <= instruction_pc+{ instruction[23:0] } + {{(AW-1){1'b0}},1'b1}; |
end |
end else begin |
always @(posedge i_clk) |
if (dcd_ce) |
begin |
if (instruction[31]) // Add |
begin |
dcd_branch_pc <= instruction_pc |
+ { {(AW-20){instruction[19]}}, instruction[19:0] } |
+ {{(AW-1){1'b0}},1'b1}; |
end else if (~instruction[28]) // 4'h2 = MOV |
begin |
dcd_branch_pc <= instruction_pc+{ {(AW-15){instruction[14]}}, instruction[14:0] } + {{(AW-1){1'b0}},1'b1}; |
end else // if (instruction[28]) // 4'h3 = LDI |
begin |
dcd_branch_pc <= instruction_pc+{ {(AW-24){instruction[23]}}, instruction[23:0] } + {{(AW-1){1'b0}},1'b1}; |
end |
end |
end endgenerate |
`else // OPT_EARLY_BRANCHING |
assign dcd_early_branch_stb = 1'b0; |
assign dcd_early_branch = 1'b0; |
assign dcd_branch_pc = {(AW){1'b0}}; |
`endif // OPT_EARLY_BRANCHING |
|
always @(posedge i_clk) |
if (dcd_ce) |
begin |
dcd_pc <= instruction_pc |
+{{(AW-1){1'b0}},1'b1}; // i.e. dcd_pc+1 |
|
// Record what operation we are doing |
dcdOp <= instruction[31:28]; |
|
// Default values |
dcdA[4:0] <= { instruction_gie, instruction[27:24] }; |
dcdB[4:0] <= { instruction_gie, instruction[19:16] }; |
dcdA_cc <= (instruction[27:24] == `CPU_CC_REG); |
dcdB_cc <= (instruction[19:16] == `CPU_CC_REG); |
dcdA_pc <= (instruction[27:24] == `CPU_PC_REG); |
dcdB_pc <= (instruction[19:16] == `CPU_PC_REG); |
dcdM <= 1'b0; |
`ifdef OPT_CONDITIONAL_FLAGS |
// Don't change the flags on conditional instructions, |
// UNLESS: the conditional instruction was a CMP |
// or TST instruction. |
dcdF_wr <= ((instruction[23:21]==3'h0) |
||(instruction[31:29] == 3'h0)); |
`else |
dcdF_wr <= 1'b1; |
`endif |
`ifdef OPT_PRECLEAR_BUS |
dcd_clear_bus <= 1'b0; |
`endif |
`ifdef OPT_ILLEGAL_INSTRUCTION |
dcd_illegal <= pf_illegal; |
`endif |
|
`ifdef OPT_NEW_INSTRUCTION_SET |
idecode #(AW, IMPLEMENT_MPY, EARLY_BRANCHING, IMPLEMENT_DIVIDE, |
IMPLEMENT_FPU) |
instruction_decoder(i_clk, (i_rst)||(clear_pipeline), |
dcd_ce, dcd_stalled, instruction, instruction_gie, |
instruction_pc, pf_valid, pf_illegal, dcd_phase, |
dcd_illegal, dcd_pc, dcd_gie, |
{ dcdR_cc, dcdR_pc, dcdR }, |
{ dcdA_cc, dcdA_pc, dcdA }, |
{ dcdB_cc, dcdB_pc, dcdB }, |
dcdI, dcd_zI, dcdF, dcdF_wr, dcdOp, |
dcdALU, dcdM, dcdDV, dcdFP, dcd_break, dcd_lock, |
dcdR_wr,dcdA_rd, dcdB_rd, |
dcd_early_branch, |
dcd_branch_pc); |
// Set the condition under which we do this operation |
// The top four bits are a mask, the bottom four the |
// value the flags must equal once anded with the mask |
dcdF <= { (instruction[23:21]==3'h0), instruction[23:21] }; |
casez(instruction[31:28]) |
4'h2: begin // Move instruction |
if (~instruction_gie) |
begin |
dcdA[4] <= instruction[20]; |
dcdB[4] <= instruction[15]; |
end |
dcdA_wr <= 1'b1; |
dcdA_rd <= 1'b0; |
dcdB_rd <= 1'b1; |
r_dcdI <= { {(9){instruction[14]}}, instruction[14:0] }; |
`ifdef OPT_SINGLE_CYCLE |
dcd_zI <= (instruction[14:0] == 0); |
`endif |
dcdF_wr <= 1'b0; // Don't write flags |
end |
4'h3: begin // Load immediate |
dcdA_wr <= 1'b1; |
dcdA_rd <= 1'b0; |
dcdB_rd <= 1'b0; |
r_dcdI <= { instruction[23:0] }; |
`ifdef OPT_SINGLE_CYCLE |
dcd_zI <= (instruction[23:0] == 0); |
`endif |
dcdF_wr <= 1'b0; // Don't write flags |
dcdF <= 4'h8; // This is unconditional |
dcdOp <= 4'h2; |
end |
4'h4: begin // Multiply, LDI[HI|LO], or NOOP/BREAK |
`ifdef OPT_CONDITIONAL_FLAGS |
// Don't write flags except for multiplies |
// and then only if they are unconditional |
dcdF_wr <= ((instruction[27:25] != 3'h7) |
&&(instruction[23:21]==3'h0)); |
`else |
idecode_deprecated |
#(AW, IMPLEMENT_MPY, EARLY_BRANCHING, IMPLEMENT_DIVIDE, |
IMPLEMENT_FPU) |
instruction_decoder(i_clk, (i_rst)||(clear_pipeline), |
dcd_ce, dcd_stalled, instruction, instruction_gie, |
instruction_pc, pf_valid, pf_illegal, dcd_phase, |
dcd_illegal, dcd_pc, dcd_gie, |
{ dcdR_cc, dcdR_pc, dcdR }, |
{ dcdA_cc, dcdA_pc, dcdA }, |
{ dcdB_cc, dcdB_pc, dcdB }, |
dcdI, dcd_zI, dcdF, dcdF_wr, dcdOp, |
dcdALU, dcdM, dcdDV, dcdFP, dcd_break, dcd_lock, |
dcdR_wr,dcdA_rd, dcdB_rd, |
dcd_early_branch, |
dcd_branch_pc); |
// Don't write flags except for multiplies |
dcdF_wr <= (instruction[27:25] != 3'h7); |
`endif |
r_dcdI <= { 8'h00, instruction[15:0] }; |
`ifdef OPT_SINGLE_CYCLE |
dcd_zI <= (instruction[15:0] == 0); |
`endif |
if (instruction[27:24] == 4'he) |
begin |
// NOOP instruction |
dcdA_wr <= 1'b0; |
dcdA_rd <= 1'b0; |
dcdB_rd <= 1'b0; |
dcdOp <= 4'h2; |
// Might also be a break. Big |
// instruction set hole here. |
`ifdef OPT_ILLEGAL_INSTRUCTION |
dcd_illegal <= (pf_illegal)||(instruction[23:1] != 0); |
`endif |
end else if (instruction[27:24] == 4'hf) |
begin // Load partial immediate(s) |
dcdA_wr <= 1'b1; |
dcdA_rd <= 1'b1; |
dcdB_rd <= 1'b0; |
dcdA[4:0] <= { instruction_gie, instruction[19:16] }; |
dcdA_cc <= (instruction[19:16] == `CPU_CC_REG); |
dcdA_pc <= (instruction[19:16] == `CPU_PC_REG); |
dcdOp <= { 3'h3, instruction[20] }; |
end else begin |
// Actual multiply instruction |
r_dcdI <= { 8'h00, instruction[15:0] }; |
`ifdef OPT_SINGLE_CYCLE |
dcd_zI <= (instruction[15:0] == 0); |
`endif |
dcdA_rd <= 1'b1; |
dcdB_rd <= (instruction[19:16] != 4'hf); |
dcdOp[3:0] <= (instruction[20])? 4'h4:4'h3; |
end end |
4'b011?: begin // LOD/STO or Load/Store |
dcdF_wr <= 1'b0; // Don't write flags |
dcdA_wr <= (~instruction[28]); // Write on loads |
dcdA_rd <= (instruction[28]); // Read on stores |
dcdB_rd <= instruction[20]; |
if (instruction[20]) |
begin |
r_dcdI <= { {(8){instruction[15]}}, instruction[15:0] }; |
`ifdef OPT_SINGLE_CYCLE |
dcd_zI <= (instruction[15:0] == 0); |
`endif |
end else begin |
r_dcdI <= { {(4){instruction[19]}}, instruction[19:0] }; |
`ifdef OPT_SINGLE_CYCLE |
dcd_zI <= (instruction[19:0] == 0); |
`endif |
end |
dcdM <= 1'b1; // Memory operation |
`ifdef OPT_PRECLEAR_BUS |
dcd_clear_bus <= (instruction[23:21]==3'h0); |
`endif |
end |
default: begin |
dcdA_wr <= (instruction[31])||(instruction[31:28]==4'h5); |
dcdA_rd <= 1'b1; |
dcdB_rd <= instruction[20]; |
if (instruction[20]) |
begin |
r_dcdI <= { {(8){instruction[15]}}, instruction[15:0] }; |
`ifdef OPT_SINGLE_CYCLE |
dcd_zI <= (instruction[15:0] == 0); |
`endif |
end else begin |
r_dcdI <= { {(4){instruction[19]}}, instruction[19:0] }; |
`ifdef OPT_SINGLE_CYCLE |
dcd_zI <= (instruction[19:0] == 0); |
`endif |
end end |
endcase |
|
|
dcd_gie <= instruction_gie; |
end |
always @(posedge i_clk) |
if (dcd_ce) |
dcd_break <= (instruction[31:0] == 32'h4e000001); |
else if ((clear_pipeline)||(~dcdvalid)) // SHOULDNT THIS BE ||op_ce? |
dcd_break <= 1'b0; |
|
`ifdef OPT_PIPELINED_BUS_ACCESS |
reg [23:0] r_opI; |
reg [4:0] op_B; |
623,10 → 695,10
&&(dcdB == op_B) // Same address register |
&&((dcdF[2:0] == opF_cp) // Same condition |
||(opF_cp == 3'h0)) // or no prev condition |
&&((dcdI[23:0] == r_opI)||(dcdI[23:0]==r_opI+24'h1)); |
&&((r_dcdI == r_opI)||(r_dcdI==r_opI+24'h1)); |
always @(posedge i_clk) |
if (op_ce) // &&(dcdvalid)) |
r_opI <= dcdI[23:0]; |
r_opI <= r_dcdI; |
always @(posedge i_clk) |
if (op_ce) // &&(dcdvalid)) |
op_B <= dcdB; |
655,10 → 727,10
else if (dcdA_pc) |
r_opA <= w_pcA_v; |
else if (dcdA_cc) |
r_opA <= { w_opA[31:13], (dcdA[4])?w_uflags:w_iflags }; |
r_opA <= { w_opA[31:11], (dcd_gie)?w_uflags:w_iflags }; |
else |
r_opA <= w_opA; |
`ifdef OPT_PIPELINED |
`ifdef OPT_SINGLE_CYCLE |
end else if (opvalid) |
begin // We were going to pick these up when they became valid, |
// but for some reason we're stuck here as they became |
668,7 → 740,8
`endif |
end |
|
wire [31:0] w_opBnI, w_pcB_v; |
wire [31:0] dcdI, w_opBnI, w_pcB_v; |
assign dcdI = { {(8){r_dcdI[23]}}, r_dcdI }; |
generate |
if (AW < 32) |
assign w_pcB_v = {{(32-AW){1'b0}}, (dcdB[4] == dcd_gie)?dcd_pc:upc }; |
679,13 → 752,13
assign w_opBnI = (~dcdB_rd) ? 32'h00 |
: (((wr_reg_ce)&&(wr_reg_id == dcdB)) ? wr_reg_vl |
: ((dcdB_pc) ? w_pcB_v |
: ((dcdB_cc) ? { w_opB[31:13], (dcdB[4])?w_uflags:w_iflags} |
: ((dcdB_cc) ? { w_opB[31:11], (dcd_gie)?w_uflags:w_iflags} |
: w_opB))); |
|
always @(posedge i_clk) |
if (op_ce) // &&(dcdvalid)) |
r_opB <= w_opBnI + dcdI; |
`ifdef OPT_PIPELINED |
`ifdef OPT_SINGLE_CYCLE |
else if ((opvalid)&&( |
((opB_alu)&&(alu_wr)) |
||((opB_mem)&&(mem_valid)))) |
706,23 → 779,11
begin // Set the flag condition codes, bit order is [3:0]=VNCZ |
case(dcdF[2:0]) |
3'h0: r_opF <= 6'h00; // Always |
`ifdef OPT_NEW_INSTRUCTION_SET |
// These were remapped as part of the new instruction |
// set in order to make certain that the low order |
// two bits contained the most commonly used |
// conditions: Always, LT, Z, and NZ. |
3'h1: r_opF <= 6'h24; // LT |
3'h2: r_opF <= 6'h11; // Z |
3'h3: r_opF <= 6'h10; // NE |
3'h4: r_opF <= 6'h30; // GT (!N&!Z) |
3'h5: r_opF <= 6'h20; // GE (!N) |
`else |
3'h1: r_opF <= 6'h11; // Z |
3'h2: r_opF <= 6'h10; // NE |
3'h3: r_opF <= 6'h20; // GE (!N) |
3'h4: r_opF <= 6'h30; // GT (!N&!Z) |
3'h5: r_opF <= 6'h24; // LT |
`endif |
3'h6: r_opF <= 6'h02; // C |
3'h7: r_opF <= 6'h08; // V |
endcase |
732,8 → 793,6
if (op_ce) |
opF_cp[2:0] <= dcdF[2:0]; |
|
wire w_opvalid; |
assign w_opvalid = (~clear_pipeline)&&(dcdvalid); |
initial opvalid = 1'b0; |
initial opvalid_alu = 1'b0; |
initial opvalid_mem = 1'b0; |
753,25 → 812,19
// Hence, the test on dcd_stalled here. If we must |
// wait until our operands are valid, then we aren't |
// valid yet until then. |
opvalid<= w_opvalid; |
opvalid<= (~clear_pipeline)&&(dcdvalid)&&(~dcd_stalled); |
`ifdef OPT_ILLEGAL_INSTRUCTION |
opvalid_alu <= ((dcdALU)||(dcd_illegal))&&(w_opvalid); |
opvalid_mem <= (dcdM)&&(~dcd_illegal)&&(w_opvalid); |
opvalid_div <= (dcdDV)&&(~dcd_illegal)&&(w_opvalid); |
opvalid_fpu <= (dcdFP)&&(~dcd_illegal)&&(w_opvalid); |
opvalid_mem <= (dcdM)&&(~dcd_illegal)&&(~clear_pipeline)&&(dcdvalid)&&(~dcd_stalled); |
opvalid_alu <= ((~dcdM)||(dcd_illegal))&&(~clear_pipeline)&&(dcdvalid)&&(~dcd_stalled); |
`else |
opvalid_alu <= (dcdALU)&&(w_opvalid); |
opvalid_mem <= (dcdM)&&(w_opvalid); |
opvalid_div <= (dcdDV)&&(w_opvalid); |
opvalid_fpu <= (dcdFP)&&(w_opvalid); |
opvalid_alu <= (~dcdM)&&(~clear_pipeline)&&(dcdvalid)&&(~dcd_stalled); |
opvalid_mem <= (dcdM)&&(~clear_pipeline)&&(dcdvalid)&&(~dcd_stalled); |
`endif |
end else if ((clear_pipeline)||(alu_ce)||(mem_ce)||(div_ce)||(fpu_ce)) |
end else if ((~op_stall)||(clear_pipeline)) |
begin |
opvalid <= 1'b0; |
opvalid_alu <= 1'b0; |
opvalid_mem <= 1'b0; |
opvalid_div <= 1'b0; |
opvalid_fpu <= 1'b0; |
end |
|
// Here's part of our debug interface. When we recognize a break |
790,109 → 843,47
else if ((clear_pipeline)||(~opvalid)) |
op_break <= 1'b0; |
|
`ifdef OPT_PIPELINED |
generate |
if (IMPLEMENT_LOCK != 0) |
begin |
reg r_op_lock, r_op_lock_stall; |
|
initial r_op_lock_stall = 1'b0; |
always @(posedge i_clk) |
if (i_rst) |
r_op_lock_stall <= 1'b0; |
else |
r_op_lock_stall <= (~opvalid)||(~op_lock) |
||(~dcdvalid)||(~pf_valid); |
|
assign op_lock_stall = r_op_lock_stall; |
|
initial r_op_lock = 1'b0; |
always @(posedge i_clk) |
if (i_rst) |
r_op_lock <= 1'b0; |
else if ((op_ce)&&(dcd_lock)) |
r_op_lock <= 1'b1; |
else if ((op_ce)||(clear_pipeline)) |
r_op_lock <= 1'b0; |
assign op_lock = r_op_lock; |
|
end else begin |
assign op_lock_stall = 1'b0; |
assign op_lock = 1'b0; |
end endgenerate |
|
`else |
assign op_lock_stall = 1'b0; |
assign op_lock = 1'b0; |
`endif |
|
`ifdef OPT_ILLEGAL_INSTRUCTION |
always @(posedge i_clk) |
if(op_ce) |
`ifdef OPT_PIPELINED |
op_illegal <=(dcd_illegal)||((dcd_lock)&&(IMPLEMENT_LOCK == 0)); |
`else |
op_illegal <= (dcd_illegal)||(dcd_lock); |
op_illegal <= dcd_illegal; |
`endif |
`endif |
|
generate |
if (EARLY_BRANCHING > 0) |
begin |
always @(posedge i_clk) |
if (op_ce) |
begin |
opF_wr <= (dcdF_wr)&&((~dcdR_cc)||(~dcdR_wr))&&(~dcd_early_branch); |
opR_wr <= (dcdR_wr)&&(~dcd_early_branch); |
op_wr_pc <= ((dcdR_wr)&&(dcdR_pc) |
&&(dcdR[4] == dcd_gie)) |
&&(~dcd_early_branch); |
end |
end else begin |
always @(posedge i_clk) |
if (op_ce) |
begin |
// Will we write the flags/CC Register with |
// our result? |
opF_wr <= (dcdF_wr)&&((~dcdR_cc)||(~dcdR_wr)); |
// Will we be writing our results into a |
// register? |
opR_wr <= dcdR_wr; |
op_wr_pc <= ((dcdR_wr)&&(dcdR_pc) |
&&(dcdR[4] == dcd_gie)); |
end |
end endgenerate |
|
always @(posedge i_clk) |
if (op_ce) |
begin |
opn <= dcdOp; // Which ALU operation? |
// opM <= dcdM; // Is this a memory operation? |
`ifdef OPT_EARLY_BRANCHING |
opF_wr <= (dcdF_wr)&&((~dcdA_cc)||(~dcdA_wr))&&(~dcd_early_branch); |
opR_wr <= (dcdA_wr)&&(~dcd_early_branch); |
`else |
// Will we write the flags/CC Register with our result? |
opF_wr <= (dcdF_wr)&&((~dcdA_cc)||(~dcdA_wr)); |
// Will we be writing our results into a register? |
opR_wr <= dcdA_wr; |
`endif |
// What register will these results be written into? |
opR <= dcdR; |
opR_cc <= (dcdR_cc)&&(dcdR_wr)&&(dcdR[4]==dcd_gie); |
opR <= dcdA; |
opR_cc <= (dcdA_wr)&&(dcdA_cc)&&(dcdA[4]==dcd_gie); |
// User level (1), vs supervisor (0)/interrupts disabled |
op_gie <= dcd_gie; |
|
|
// |
`ifdef OPT_EARLY_BRANCHING |
op_wr_pc <= ((dcdA_wr)&&(dcdA_pc)&&(dcdA[4] == dcd_gie))&&(~dcd_early_branch); |
`else |
op_wr_pc <= ((dcdA_wr)&&(dcdA_pc)&&(dcdA[4] == dcd_gie)); |
`endif |
op_pc <= (dcd_early_branch)?dcd_branch_pc:dcd_pc; |
// op_pc <= dcd_pc; |
|
`ifdef OPT_PRECLEAR_BUS |
op_clear_bus <= dcd_clear_bus; |
`endif |
end |
assign opFl = (op_gie)?(w_uflags):(w_iflags); |
|
`ifdef OPT_VLIW |
reg r_op_phase; |
initial r_op_phase = 1'b0; |
always @(posedge i_clk) |
if ((i_rst)||(clear_pipeline)) |
r_op_phase <= 1'b0; |
else if (op_ce) |
r_op_phase <= dcd_phase; |
assign op_phase = r_op_phase; |
`else |
assign op_phase = 1'b0; |
`endif |
|
// This is tricky. First, the PC and Flags registers aren't kept in |
// register set but in special registers of their own. So step one |
// is to select the right register. Step to is to replace that |
905,7 → 896,7
// We'll create a flag here to start our coordination. Once we |
// define this flag to something other than just plain zero, then |
// the stalls will already be in place. |
`ifdef OPT_PIPELINED |
`ifdef OPT_SINGLE_CYCLE |
initial opA_alu = 1'b0; |
always @(posedge i_clk) |
if (op_ce) |
925,7 → 916,7
always @(posedge i_clk) |
if (mem_ce) |
mem_last_reg <= opR; |
`ifdef OPT_PIPELINED |
`ifdef OPT_SINGLE_CYCLE |
assign opA = ((opA_alu)&&(alu_wr)) ? alu_result |
: ( ((opA_mem)&&(mem_valid))?mem_result |
: r_opA ); |
933,15 → 924,20
assign opA = r_opA; |
`endif |
|
`ifdef OPT_PIPELINED |
assign dcdA_stall = (dcdvalid)&&(dcdA_rd)&&( |
`ifdef OPT_SINGLE_CYCLE |
// Skip the requirement on writing back opA |
// Stall on memory, since we'll always need to stall for a |
// memory access anyway |
((opvalid_alu)&&(opF_wr)&&(dcdA_cc))); |
`else |
// There are no pipeline hazards, if we aren't pipelined |
assign dcdA_stall = 1'b0; |
((opvalid)&&(opR_wr)&&(opR == dcdA)) |
||((opvalid_alu)&&(opF_wr)&&(dcdA_cc)) |
||((mem_rdbusy)&&(mem_last_reg == dcdA)) |
); |
`endif |
|
`ifdef OPT_PIPELINED |
`ifdef OPT_SINGLE_CYCLE |
always @(posedge i_clk) |
if (op_ce) |
opB_alu <= (opvalid_alu)&&(opR == dcdB)&&(opR_wr)&&(dcdB_rd)&&(dcd_zI); |
960,8 → 956,8
assign opB = r_opB; |
`endif |
|
`ifdef OPT_PIPELINED |
assign dcdB_stall = (dcdvalid)&&(dcdB_rd)&&( |
`ifdef OPT_SINGLE_CYCLE |
// Stall on memory ops writing to my register |
// (i.e. loads), or on any write to my |
// register if I have an immediate offset |
982,13 → 978,12
// will write to opB |
||((mem_busy)&&(~mem_we)&&(mem_last_reg==dcdB))); |
`else |
// No stalls without pipelining, 'cause how can you have a pipeline |
// hazard without the pipeline? |
assign dcdB_stall = 1'b0; |
((opvalid)&&(opR_wr)&&(opR == dcdB)) |
||((opvalid_alu)&&(opF_wr)&&(dcdB_cc)) |
||((mem_rdbusy)&&(mem_last_reg == dcdB)) |
); |
`endif |
assign dcdF_stall = (dcdvalid)&&((~dcdF[3]) |
||((dcdA_rd)&&(dcdA_cc)) |
||((dcdB_rd)&&(dcdB_cc))) |
assign dcdF_stall = (dcdvalid)&&((~dcdF[3])||(dcdA_cc)||(dcdB_cc)) |
&&(opvalid)&&(opR_cc); |
// |
// |
995,52 → 990,10
// PIPELINE STAGE #4 :: Apply Instruction |
// |
// |
`ifdef OPT_NEW_INSTRUCTION_SET |
cpuops #(IMPLEMENT_MPY) doalu(i_clk, i_rst, alu_ce, |
(opvalid_alu), opn, opA, opB, |
alu_result, alu_flags, alu_valid, alu_illegal_op); |
`else |
cpuops_deprecated #(IMPLEMENT_MPY) doalu(i_clk, i_rst, alu_ce, |
(opvalid_alu), opn, opA, opB, |
alu_result, alu_flags, alu_valid, alu_illegal_op); |
`endif |
|
generate |
if (IMPLEMENT_DIVIDE != 0) |
begin |
div thedivide(i_clk, i_rst, div_ce, opn[0], |
opA, opB, div_busy, div_valid, div_error, div_result, |
div_flags); |
end else begin |
assign div_error = 1'b1; |
assign div_busy = 1'b0; |
assign div_valid = 1'b0; |
assign div_result= 32'h00; |
assign div_flags = 4'h0; |
end endgenerate |
|
generate |
if (IMPLEMENT_FPU != 0) |
begin |
// |
// sfpu thefpu(i_clk, i_rst, fpu_ce, |
// opA, opB, fpu_busy, fpu_valid, fpu_err, fpu_result, |
// fpu_flags); |
// |
assign fpu_error = 1'b1; |
assign fpu_busy = 1'b0; |
assign fpu_valid = 1'b0; |
assign fpu_result= 32'h00; |
assign fpu_flags = 4'h0; |
end else begin |
assign fpu_error = 1'b1; |
assign fpu_busy = 1'b0; |
assign fpu_valid = 1'b0; |
assign fpu_result= 32'h00; |
assign fpu_flags = 4'h0; |
end endgenerate |
|
|
assign set_cond = ((opF[7:4]&opFl[3:0])==opF[3:0]); |
initial alF_wr = 1'b0; |
initial alu_wr = 1'b0; |
1060,26 → 1013,11
alu_wr <= (i_halt)&&(i_dbg_we); |
alF_wr <= 1'b0; |
end |
|
`ifdef OPT_VLIW |
reg r_alu_phase; |
initial r_alu_phase = 1'b0; |
always @(posedge i_clk) |
if (i_rst) |
r_alu_phase <= 1'b0; |
else if ((alu_ce)||(mem_ce)||(div_ce)||(fpu_ce)) |
r_alu_phase <= op_phase; |
assign alu_phase = r_alu_phase; |
`else |
assign alu_phase = 1'b0; |
`endif |
|
always @(posedge i_clk) |
if ((alu_ce)||(div_ce)||(fpu_ce)) |
if (alu_ce) |
alu_reg <= opR; |
else if ((i_halt)&&(i_dbg_we)) |
alu_reg <= i_dbg_reg; |
|
reg [31:0] dbg_val; |
reg dbgv; |
always @(posedge i_clk) |
1113,30 → 1051,8
alu_pc_valid <= ((alu_ce) |
||((master_ce)&&(opvalid_mem)&&(~clear_pipeline)&&(~mem_stalled))); |
|
wire bus_lock; |
`ifdef OPT_PIPELINED |
generate |
if (IMPLEMENT_LOCK != 0) |
begin |
reg r_bus_lock; |
initial r_bus_lock = 1'b0; |
always @(posedge i_clk) |
if (i_rst) |
r_bus_lock <= 1'b0; |
else if ((op_ce)&&(op_lock)) |
r_bus_lock <= 1'b1; |
else if (~opvalid_mem) |
r_bus_lock <= 1'b0; |
assign bus_lock = r_bus_lock; |
end else begin |
assign bus_lock = 1'b0; |
end endgenerate |
`else |
assign bus_lock = 1'b0; |
`endif |
|
`ifdef OPT_PIPELINED_BUS_ACCESS |
pipemem #(AW,IMPLEMENT_LOCK) domem(i_clk, i_rst, mem_ce, bus_lock, |
pipemem #(AW) domem(i_clk, i_rst, mem_ce, |
(opn[0]), opB, opA, opR, |
mem_busy, mem_pipe_stalled, |
mem_valid, bus_err, mem_wreg, mem_result, |
1146,7 → 1062,7
mem_ack, mem_stall, mem_err, i_wb_data); |
|
`else // PIPELINED_BUS_ACCESS |
memops #(AW,IMPLEMENT_LOCK) domem(i_clk, i_rst, mem_ce, bus_lock, |
memops #(AW) domem(i_clk, i_rst, mem_ce, |
(opn[0]), opB, opA, opR, |
mem_busy, |
mem_valid, bus_err, mem_wreg, mem_result, |
1190,15 → 1106,13
// Further, alu_wr includes (set_cond), so we don't need to |
// check for that here either. |
`ifdef OPT_ILLEGAL_INSTRUCTION |
assign wr_reg_ce = (~alu_illegal)&&((alu_wr)&&(~clear_pipeline))||(mem_valid)||(div_valid)||(fpu_valid); |
assign wr_reg_ce = (~alu_illegal)&&((alu_wr)&&(~clear_pipeline))||(mem_valid); |
`else |
assign wr_reg_ce = ((alu_wr)&&(~clear_pipeline))||(mem_valid)||(div_valid)||(fpu_valid); |
assign wr_reg_ce = ((alu_wr)&&(~clear_pipeline))||(mem_valid); |
`endif |
// Which register shall be written? |
// COULD SIMPLIFY THIS: by adding three bits to these registers, |
// One or PC, one for CC, and one for GIE match |
// Note that the alu_reg is the register to write on a divide or |
// FPU operation. |
assign wr_reg_id = (alu_wr)?alu_reg:mem_wreg; |
// Are we writing to the CC register? |
assign wr_write_cc = (wr_reg_id[3:0] == `CPU_CC_REG); |
1205,10 → 1119,7
// Are we writing to the PC? |
assign wr_write_pc = (wr_reg_id[3:0] == `CPU_PC_REG); |
// What value to write? |
assign wr_reg_vl = (alu_wr)?((dbgv)?dbg_val: alu_result) |
:((mem_valid) ? mem_result |
:((div_valid) ? div_result |
:fpu_result)); |
assign wr_reg_vl = (alu_wr)?((dbgv)?dbg_val: alu_result) :mem_result; |
always @(posedge i_clk) |
if (wr_reg_ce) |
regset[wr_reg_id] <= wr_reg_vl; |
1217,11 → 1128,14
// Write back to the condition codes/flags register ... |
// When shall we write to our flags register? alF_wr already |
// includes the set condition ... |
assign wr_flags_ce = ((alF_wr)||(div_valid)||(fpu_valid))&&(~clear_pipeline)&&(~alu_illegal); |
assign w_uflags = { ufpu_err_flag, udiv_err_flag, ubus_err_flag, trap, ill_err_u, 1'b0, step, 1'b1, sleep, ((wr_flags_ce)&&(alu_gie))?alu_flags:flags }; |
assign w_iflags = { ifpu_err_flag, idiv_err_flag, ibus_err_flag, trap, ill_err_i,break_en, 1'b0, 1'b0, sleep, ((wr_flags_ce)&&(~alu_gie))?alu_flags:iflags }; |
|
|
assign wr_flags_ce = (alF_wr)&&(~clear_pipeline)&&(~alu_illegal); |
`ifdef OPT_ILLEGAL_INSTRUCTION |
assign w_uflags = { ubus_err_flag, trap, ill_err_u, 1'b0, step, 1'b1, sleep, ((wr_flags_ce)&&(alu_gie))?alu_flags:flags }; |
assign w_iflags = { ibus_err_flag, trap, ill_err_i,break_en, 1'b0, 1'b0, sleep, ((wr_flags_ce)&&(~alu_gie))?alu_flags:iflags }; |
`else |
assign w_uflags = { ubus_err_flag, trap, ill_err_u, 1'b0, step, 1'b1, sleep, ((wr_flags_ce)&&(alu_gie))?alu_flags:flags }; |
assign w_iflags = { ibus_err_flag, trap, ill_err_i, break_en, 1'b0, 1'b0, sleep, ((wr_flags_ce)&&(~alu_gie))?alu_flags:iflags }; |
`endif |
// What value to write? |
always @(posedge i_clk) |
// If explicitly writing the register itself |
1229,15 → 1143,13
flags <= wr_reg_vl[3:0]; |
// Otherwise if we're setting the flags from an ALU operation |
else if ((wr_flags_ce)&&(alu_gie)) |
flags <= (div_valid)?div_flags:((fpu_valid)?fpu_flags |
: alu_flags); |
flags <= alu_flags; |
|
always @(posedge i_clk) |
if ((wr_reg_ce)&&(~wr_reg_id[4])&&(wr_write_cc)) |
iflags <= wr_reg_vl[3:0]; |
else if ((wr_flags_ce)&&(~alu_gie)) |
iflags <= (div_valid)?div_flags:((fpu_valid)?fpu_flags |
: alu_flags); |
iflags <= alu_flags; |
|
// The 'break' enable bit. This bit can only be set from supervisor |
// mode. It control what the CPU does upon encountering a break |
1263,11 → 1175,8
`ifdef OPT_ILLEGAL_INSTRUCTION |
assign o_break = ((break_en)||(~op_gie))&&(op_break) |
&&(~alu_valid)&&(~mem_valid)&&(~mem_busy) |
&&(~div_busy)&&(~fpu_busy) |
&&(~clear_pipeline) |
||((~alu_gie)&&(bus_err)) |
||((~alu_gie)&&(div_valid)&&(div_error)) |
||((~alu_gie)&&(fpu_valid)&&(fpu_error)) |
||((~alu_gie)&&(alu_valid)&&(alu_illegal)); |
`else |
assign o_break = (((break_en)||(~op_gie))&&(op_break) |
1284,19 → 1193,12
// set the sleep bit and switch to supervisor mode in the same |
// instruction: users are not allowed to halt the CPU. |
always @(posedge i_clk) |
if ((i_rst)||(w_switch_to_interrupt)) |
if ((i_rst)||((i_interrupt)&&(gie))) |
sleep <= 1'b0; |
else if ((wr_reg_ce)&&(wr_write_cc)&&(~alu_gie)) |
// In supervisor mode, we have no protections. The |
// supervisor can set the sleep bit however he wants. |
// Well ... not quite. Switching to user mode and |
// sleep mode shouold only be possible if the interrupt |
// flag isn't set. |
// Thus: if (i_interrupt)&&(wr_reg_vl[GIE]) |
// don't set the sleep bit |
// otherwise however it would o.w. be set |
sleep <= (wr_reg_vl[`CPU_SLEEP_BIT]) |
&&((~i_interrupt)||(~wr_reg_vl[`CPU_GIE_BIT])); |
sleep <= wr_reg_vl[`CPU_SLEEP_BIT]; |
else if ((wr_reg_ce)&&(wr_write_cc)&&(wr_reg_vl[`CPU_GIE_BIT])) |
// In user mode, however, you can only set the sleep |
// mode while remaining in user mode. You can't switch |
1315,20 → 1217,16
// The GIE register. Only interrupts can disable the interrupt register |
assign w_switch_to_interrupt = (gie)&&( |
// On interrupt (obviously) |
((i_interrupt)&&(~alu_phase)&&(~bus_lock)) |
(i_interrupt) |
// If we are stepping the CPU |
||((alu_pc_valid)&&(step)&&(~alu_phase)&&(~bus_lock)) |
||((alu_pc_valid)&&(step)) |
// If we encounter a break instruction, if the break |
// enable isn't set. |
||((master_ce)&&(~mem_rdbusy)&&(~div_busy)&&(~fpu_busy) |
&&(op_break)&&(~break_en)) |
||((master_ce)&&(~mem_rdbusy)&&(op_break)&&(~break_en)) |
`ifdef OPT_ILLEGAL_INSTRUCTION |
// On an illegal instruction |
||((alu_valid)&&(alu_illegal)) |
`endif |
||((div_valid)&&(div_error)) |
||((fpu_valid)&&(fpu_error)) |
||(bus_err) |
// If we write to the CC register |
||((wr_reg_ce)&&(~wr_reg_vl[`CPU_GIE_BIT]) |
&&(wr_reg_id[4])&&(wr_write_cc)) |
1350,9 → 1248,12
always @(posedge i_clk) |
if (i_rst) |
trap <= 1'b0; |
else if ((alu_gie)&&(wr_reg_ce)&&(~wr_reg_vl[`CPU_GIE_BIT]) |
&&(wr_write_cc)) // &&(wr_reg_id[4]) implied |
else if ((gie)&&(wr_reg_ce)&&(~wr_reg_vl[`CPU_GIE_BIT]) |
&&(wr_reg_id[4])&&(wr_write_cc)) |
trap <= 1'b1; |
// else if ((i_halt)&&(i_dbg_we)&&(i_dbg_reg[3:0] == `CPU_CC_REG) |
// &&(~i_dbg_data[`CPU_GIE_BIT])) |
// trap <= i_dbg_data[`CPU_TRAP_BIT]; |
else if (w_release_from_interrupt) |
trap <= 1'b0; |
|
1416,103 → 1317,6
else if ((bus_err)&&(alu_gie)) |
ubus_err_flag <= 1'b1; |
|
generate |
if (IMPLEMENT_DIVIDE != 0) |
begin |
reg r_idiv_err_flag, r_udiv_err_flag; |
|
// Supervisor/interrupt divide (by zero) error flag -- this will |
// crash the CPU if ever set. This bit is thus available for us |
// to be able to tell if/why the CPU crashed. |
initial r_idiv_err_flag = 1'b0; |
always @(posedge i_clk) |
if (i_rst) |
r_idiv_err_flag <= 1'b0; |
else if ((dbgv)&&(wr_reg_id == {1'b0, `CPU_CC_REG}) |
&&(~wr_reg_vl[`CPU_DIVERR_BIT])) |
r_idiv_err_flag <= 1'b0; |
else if ((div_error)&&(div_valid)&&(~alu_gie)) |
r_idiv_err_flag <= 1'b1; |
// User divide (by zero) error flag -- if ever set, it will |
// cause a sudden switch interrupt to supervisor mode. |
initial r_udiv_err_flag = 1'b0; |
always @(posedge i_clk) |
if (i_rst) |
r_udiv_err_flag <= 1'b0; |
else if (w_release_from_interrupt) |
r_udiv_err_flag <= 1'b0; |
else if (((~alu_gie)||(dbgv))&&(wr_reg_ce) |
&&(~wr_reg_vl[`CPU_DIVERR_BIT]) |
&&(wr_reg_id[4])&&(wr_write_cc)) |
r_udiv_err_flag <= 1'b0; |
else if ((div_error)&&(alu_gie)&&(div_valid)) |
r_udiv_err_flag <= 1'b1; |
|
assign idiv_err_flag = r_idiv_err_flag; |
assign udiv_err_flag = r_udiv_err_flag; |
end else begin |
assign idiv_err_flag = 1'b0; |
assign udiv_err_flag = 1'b0; |
end endgenerate |
|
generate |
if (IMPLEMENT_FPU !=0) |
begin |
// Supervisor/interrupt floating point error flag -- this will |
// crash the CPU if ever set. |
reg r_ifpu_err_flag, r_ufpu_err_flag; |
initial r_ifpu_err_flag = 1'b0; |
always @(posedge i_clk) |
if (i_rst) |
r_ifpu_err_flag <= 1'b0; |
else if ((dbgv)&&(wr_reg_id == {1'b0, `CPU_CC_REG}) |
&&(~wr_reg_vl[`CPU_FPUERR_BIT])) |
r_ifpu_err_flag <= 1'b0; |
else if ((fpu_error)&&(fpu_valid)&&(~alu_gie)) |
r_ifpu_err_flag <= 1'b1; |
// User floating point error flag -- if ever set, it will cause |
// a sudden switch interrupt to supervisor mode. |
initial r_ufpu_err_flag = 1'b0; |
always @(posedge i_clk) |
if (i_rst) |
r_ufpu_err_flag <= 1'b0; |
else if (w_release_from_interrupt) |
r_ufpu_err_flag <= 1'b0; |
else if (((~alu_gie)||(dbgv))&&(wr_reg_ce) |
&&(~wr_reg_vl[`CPU_FPUERR_BIT]) |
&&(wr_reg_id[4])&&(wr_write_cc)) |
r_ufpu_err_flag <= 1'b0; |
else if ((fpu_error)&&(alu_gie)&&(fpu_valid)) |
r_ufpu_err_flag <= 1'b1; |
|
assign ifpu_err_flag = r_ifpu_err_flag; |
assign ufpu_err_flag = r_ufpu_err_flag; |
end else begin |
assign ifpu_err_flag = 1'b0; |
assign ufpu_err_flag = 1'b0; |
end endgenerate |
|
`ifdef OPT_VLIW |
reg r_ihalt_phase, r_uhalt_phase; |
|
initial r_ihalt_phase = 0; |
initial r_uhalt_phase = 0; |
always @(posedge i_clk) |
if (~alu_gie) |
r_ihalt_phase <= alu_phase; |
always @(posedge i_clk) |
if (alu_gie) |
r_uhalt_phase <= alu_phase; |
else if (w_release_from_interrupt) |
r_uhalt_phase <= 1'b0; |
|
assign ihalt_phase = r_ihalt_phase; |
assign uhalt_phase = r_uhalt_phase; |
`else |
assign ihalt_phase = 1'b0; |
assign uhalt_phase = 1'b0; |
`endif |
|
// |
// Write backs to the PC register, and general increments of it |
// We support two: upc and ipc. If the instruction is normal, |
1546,15 → 1350,8
pf_pc <= upc; |
else if ((wr_reg_ce)&&(wr_reg_id[4] == gie)&&(wr_write_pc)) |
pf_pc <= wr_reg_vl[(AW-1):0]; |
`ifdef OPT_PIPELINED |
else if ((~new_pc)&&((dcd_early_branch)&&(dcdvalid))) |
pf_pc <= dcd_branch_pc + 1; |
else if ((new_pc)||((~dcd_stalled)&&(pf_valid))) |
else if (dcd_ce) |
pf_pc <= pf_pc + {{(AW-1){1'b0}},1'b1}; |
`else |
else if ((alu_pc_valid)&&(~clear_pipeline)) |
pf_pc <= alu_pc; |
`endif |
|
initial new_pc = 1'b1; |
always @(posedge i_clk) |
1581,7 → 1378,7
o_dbg_reg <= {{(32-AW){1'b0}},(i_dbg_reg[4])?upc:ipc}; |
else if (i_dbg_reg[3:0] == `CPU_CC_REG) |
begin |
o_dbg_reg[12:0] <= (i_dbg_reg[4])?w_uflags:w_iflags; |
o_dbg_reg[10:0] <= (i_dbg_reg[4])?w_uflags:w_iflags; |
o_dbg_reg[`CPU_GIE_BIT] <= gie; |
end |
end |
1593,7 → 1390,7
o_dbg_reg <= (i_dbg_reg[4])?upc:ipc; |
else if (i_dbg_reg[3:0] == `CPU_CC_REG) |
begin |
o_dbg_reg[12:0] <= (i_dbg_reg[4])?w_uflags:w_iflags; |
o_dbg_reg[10:0] <= (i_dbg_reg[4])?w_uflags:w_iflags; |
o_dbg_reg[`CPU_GIE_BIT] <= gie; |
end |
end |
1621,8 → 1418,7
`ifdef DEBUG_SCOPE |
always @(posedge i_clk) |
o_debug <= { |
/* |
pf_pc[3:0], flags, |
pf_pc[7:0], |
pf_valid, dcdvalid, opvalid, alu_valid, mem_valid, |
op_ce, alu_ce, mem_ce, |
// |
1636,13 → 1432,6
// opA[23:20], opA[3:0], |
gie, sleep, |
wr_reg_vl[5:0] |
*/ |
i_rst, master_ce, (new_pc), |
((dcd_early_branch)&&(dcdvalid)), |
pf_valid, pf_illegal, |
op_ce, dcd_ce, dcdvalid, dcd_stalled, |
pf_cyc, pf_stb, pf_we, pf_ack, pf_stall, pf_err, |
pf_pc[7:0], pf_addr[7:0] |
}; |
`endif |
|
/core/pipemem.v
13,7 → 13,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
35,7 → 35,7
// |
/////////////////////////////////////////////////////////////////////////// |
// |
module pipemem(i_clk, i_rst, i_pipe_stb, i_lock, |
module pipemem(i_clk, i_rst, i_pipe_stb, |
i_op, i_addr, i_data, i_oreg, |
o_busy, o_pipe_stalled, o_valid, o_err, o_wreg, o_result, |
o_wb_cyc_gbl, o_wb_cyc_lcl, |
42,9 → 42,9
o_wb_stb_gbl, o_wb_stb_lcl, |
o_wb_we, o_wb_addr, o_wb_data, |
i_wb_ack, i_wb_stall, i_wb_err, i_wb_data); |
parameter ADDRESS_WIDTH=24, IMPLEMENT_LOCK=0, AW=ADDRESS_WIDTH; |
parameter ADDRESS_WIDTH = 24, AW=ADDRESS_WIDTH; |
input i_clk, i_rst; |
input i_pipe_stb, i_lock; |
input i_pipe_stb; |
// CPU interface |
input i_op; |
input [31:0] i_addr; |
58,10 → 58,8
output reg [4:0] o_wreg; |
output reg [31:0] o_result; |
// Wishbone outputs |
output wire o_wb_cyc_gbl; |
output reg o_wb_stb_gbl; |
output wire o_wb_cyc_lcl; |
output reg o_wb_stb_lcl, o_wb_we; |
output reg o_wb_cyc_gbl, o_wb_stb_gbl; |
output reg o_wb_cyc_lcl, o_wb_stb_lcl, o_wb_we; |
output reg [(AW-1):0] o_wb_addr; |
output reg [31:0] o_wb_data; |
// Wishbone inputs |
68,7 → 66,6
input i_wb_ack, i_wb_stall, i_wb_err; |
input [31:0] i_wb_data; |
|
reg r_wb_cyc_gbl, r_wb_cyc_lcl; |
reg [3:0] rdaddr, wraddr; |
wire [3:0] nxt_rdaddr; |
reg [(5-1):0] fifo_oreg [0:15]; |
95,13 → 92,13
//= ((i_addr[31:8]!=24'hc00000)||(i_addr[7:5]!=3'h0)); |
|
initial cyc = 0; |
initial r_wb_cyc_lcl = 0; |
initial r_wb_cyc_gbl = 0; |
initial o_wb_cyc_lcl = 0; |
initial o_wb_cyc_gbl = 0; |
always @(posedge i_clk) |
if (i_rst) |
begin |
r_wb_cyc_gbl <= 1'b0; |
r_wb_cyc_lcl <= 1'b0; |
o_wb_cyc_gbl <= 1'b0; |
o_wb_cyc_lcl <= 1'b0; |
o_wb_stb_gbl <= 1'b0; |
o_wb_stb_lcl <= 1'b0; |
cyc <= 1'b0; |
119,14 → 116,14
|
if (((i_wb_ack)&&(nxt_rdaddr == wraddr))||(i_wb_err)) |
begin |
r_wb_cyc_gbl <= 1'b0; |
r_wb_cyc_lcl <= 1'b0; |
o_wb_cyc_gbl <= 1'b0; |
o_wb_cyc_lcl <= 1'b0; |
cyc <= 1'b0; |
end |
end else if (i_pipe_stb) // New memory operation |
begin // Grab the wishbone |
r_wb_cyc_lcl <= lcl_stb; |
r_wb_cyc_gbl <= gbl_stb; |
o_wb_cyc_lcl <= lcl_stb; |
o_wb_cyc_gbl <= gbl_stb; |
o_wb_stb_lcl <= lcl_stb; |
o_wb_stb_gbl <= gbl_stb; |
cyc <= 1'b1; |
165,26 → 162,4
|
assign o_pipe_stalled = (cyc) |
&&((i_wb_stall)||((~o_wb_stb_lcl)&&(~o_wb_stb_gbl))); |
|
generate |
if (IMPLEMENT_LOCK != 0) |
begin |
reg lock_gbl, lock_lcl; |
|
initial lock_gbl = 1'b0; |
initial lock_lcl = 1'b0; |
always @(posedge i_clk) |
begin |
lock_gbl <= (i_lock)&&((r_wb_cyc_gbl)||(lock_gbl)); |
lock_lcl <= (i_lock)&&((r_wb_cyc_lcl)||(lock_gbl)); |
end |
|
assign o_wb_cyc_gbl = (r_wb_cyc_gbl)||(lock_gbl); |
assign o_wb_cyc_lcl = (r_wb_cyc_lcl)||(lock_lcl); |
|
end else begin |
assign o_wb_cyc_gbl = (r_wb_cyc_gbl); |
assign o_wb_cyc_lcl = (r_wb_cyc_lcl); |
end endgenerate |
|
endmodule |
/core/prefetch.v
20,7 → 20,7
// can trap on it if necessary. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
47,18 → 47,18
// mode which this prefetch does not support. In non--pipelined mode, the |
// flash will require (16+6+6)*2 = 56 clocks plus 16 clocks per word read, |
// or 72 clocks to fetch one instruction. |
module prefetch(i_clk, i_rst, i_ce, i_stalled_n, i_pc, i_aux, |
module prefetch(i_clk, i_rst, i_ce, i_pc, i_aux, |
o_i, o_pc, o_aux, o_valid, o_illegal, |
o_wb_cyc, o_wb_stb, o_wb_we, o_wb_addr, o_wb_data, |
i_wb_ack, i_wb_stall, i_wb_err, i_wb_data); |
parameter ADDRESS_WIDTH=32, AUX_WIDTH = 1, AW=ADDRESS_WIDTH; |
input i_clk, i_rst, i_ce, i_stalled_n; |
input i_clk, i_rst, i_ce; |
input [(AW-1):0] i_pc; |
input [(AUX_WIDTH-1):0] i_aux; |
output reg [31:0] o_i; |
output reg [(AW-1):0] o_pc; |
output reg [(AUX_WIDTH-1):0] o_aux; |
output reg o_valid, o_illegal; |
output wire o_valid, o_illegal; |
// Wishbone outputs |
output reg o_wb_cyc, o_wb_stb; |
output wire o_wb_we; |
96,7 → 96,7
|
always @(posedge i_clk) |
if (i_rst) // Set the address to guarantee the result is invalid |
o_wb_addr <= {(AW){1'b1}}; |
o_wb_addr <= 1'b0; |
else if ((i_ce)&&(~o_wb_cyc)) |
o_wb_addr <= i_pc; |
always @(posedge i_clk) |
108,17 → 108,8
always @(posedge i_clk) |
if ((o_wb_cyc)&&(i_wb_ack)) |
o_pc <= o_wb_addr; |
initial o_valid = 1'b0; |
initial o_illegal = 1'b0; |
always @(posedge i_clk) |
if ((o_wb_cyc)&&(i_wb_ack)) |
begin |
o_valid <= (i_pc == o_wb_addr)&&(~i_wb_err); |
o_illegal <= i_wb_err; |
end else if (i_stalled_n) |
begin |
o_valid <= 1'b0; |
o_illegal <= 1'b0; |
end |
|
assign o_valid = (i_pc == o_pc)&&(i_aux == o_aux)&&(~o_wb_cyc); |
assign o_illegal = (o_wb_cyc)&&(i_wb_err); |
|
endmodule |
/core/pipefetch.v
26,7 → 26,7
// these exceptions yet. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
/core/cpuops.v
4,13 → 4,10
// |
// Project: Zip CPU -- a small, lightweight, RISC CPU soft core |
// |
// Purpose: This supports the instruction set reordering of operations |
// created by the second generation instruction set, as well as |
// the new operations of POPC (population count) and BREV (bit reversal). |
// Purpose: |
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
32,7 → 29,7
// |
/////////////////////////////////////////////////////////////////////////// |
// |
module cpuops(i_clk,i_rst, i_ce, i_valid, i_op, i_a, i_b, o_c, o_f, o_valid, |
module cpuops(i_clk, i_rst, i_ce, i_valid, i_op, i_a, i_b, o_c, o_f, o_valid, |
o_illegal); |
parameter IMPLEMENT_MPY = 1; |
input i_clk, i_rst, i_ce; |
57,36 → 54,16
assign w_lsr_result = (|i_b[31:5])? 33'h00 |
: ( { i_a, 1'b0 } >> (i_b[4:0]) );// LSR |
|
// Bit reversal pre-logic |
wire [31:0] w_brev_result; |
genvar k; |
generate |
for(k=0; k<32; k=k+1) |
assign w_brev_result[k] = i_b[31-k]; |
endgenerate |
|
// Popcount pre-logic |
wire [31:0] w_popc_result; |
assign w_popc_result[5:0]= |
({5'h0,i_b[ 0]}+{5'h0,i_b[ 1]}+{5'h0,i_b[ 2]}+{5'h0,i_b[ 3]}) |
+({5'h0,i_b[ 4]}+{5'h0,i_b[ 5]}+{5'h0,i_b[ 6]}+{5'h0,i_b[ 7]}) |
+({5'h0,i_b[ 8]}+{5'h0,i_b[ 9]}+{5'h0,i_b[10]}+{5'h0,i_b[11]}) |
+({5'h0,i_b[12]}+{5'h0,i_b[13]}+{5'h0,i_b[14]}+{5'h0,i_b[15]}) |
+({5'h0,i_b[16]}+{5'h0,i_b[17]}+{5'h0,i_b[18]}+{5'h0,i_b[19]}) |
+({5'h0,i_b[20]}+{5'h0,i_b[21]}+{5'h0,i_b[22]}+{5'h0,i_b[23]}) |
+({5'h0,i_b[24]}+{5'h0,i_b[25]}+{5'h0,i_b[26]}+{5'h0,i_b[27]}) |
+({5'h0,i_b[28]}+{5'h0,i_b[29]}+{5'h0,i_b[30]}+{5'h0,i_b[31]}); |
assign w_popc_result[31:6] = 26'h00; |
|
// Prelogic for our flags registers |
wire z, n, v; |
reg c, pre_sign, set_ovfl; |
always @(posedge i_clk) |
if (i_ce) // 1 LUT |
set_ovfl =(((i_op==4'h0)&&(i_a[31] != i_b[31]))//SUB&CMP |
||((i_op==4'h2)&&(i_a[31] == i_b[31])) // ADD |
||(i_op == 4'h6) // LSL |
||(i_op == 4'h5)); // LSR |
if (i_ce) |
set_ovfl =((((i_op==4'h0)||(i_op==4'h8)) // SUB&CMP |
&&(i_a[31] != i_b[31])) |
||((i_op==4'ha)&&(i_a[31] == i_b[31])) // ADD |
||(i_op == 4'hd) // LSL |
||(i_op == 4'hf)); // LSR |
|
|
// A 4-way multiplexer can be done in one 6-LUT. |
103,22 → 80,20
pre_sign <= (i_a[31]); |
c <= 1'b0; |
casez(i_op) |
4'b0000:{c,o_c } <= {1'b0,i_a}-{1'b0,i_b};// CMP/SUB |
4'b0001: o_c <= i_a & i_b; // BTST/And |
4'b0010:{c,o_c } <= i_a + i_b; // Add |
4'b0011: o_c <= i_a | i_b; // Or |
4'b0100: o_c <= i_a ^ i_b; // Xor |
4'b0101:{o_c,c } <= w_lsr_result[32:0]; // LSR |
4'b0110:{c,o_c } <= (|i_b[31:5])? 33'h00 : {1'b0, i_a } << i_b[4:0]; // LSL |
4'b0111:{o_c,c } <= w_asr_result[32:0]; // ASR |
4'b1000: o_c <= { i_b[15: 0], i_a[15:0] }; // LODIHI |
4'b1001: o_c <= { i_a[31:16], i_b[15:0] }; // LODILO |
// 4'h1010: The unimplemented MPYU, |
// 4'h1011: and here for the unimplemented MPYS |
4'b1100: o_c <= w_brev_result; // BREV |
4'b1101: o_c <= w_popc_result; // POPC |
4'b1110: o_c <= w_rol_result; // ROL |
default: o_c <= i_b; // MOV, LDI |
4'b?000:{c,o_c } <= {1'b0,i_a} - {1'b0,i_b};// CMP/SUB |
4'b?001: o_c <= i_a & i_b; // BTST/And |
// 4'h3: There's a hole here for the unimplemented MPYU, |
// 4'h4: and here for the unimplemented MPYS |
4'h5: o_c <= w_rol_result; // ROL |
4'h6: o_c <= { i_a[31:16], i_b[15:0] }; // LODILO |
4'h7: o_c <= { i_b[15: 0], i_a[15:0] }; // LODIHI |
4'ha: { c, o_c } <= i_a + i_b; // Add |
4'hb: o_c <= i_a | i_b; // Or |
4'hc: o_c <= i_a ^ i_b; // Xor |
4'hd: { c, o_c } <= (|i_b[31:5])? 33'h00 : {1'b0, i_a } << i_b[4:0]; // LSL |
4'he: { o_c, c } <= w_asr_result[32:0]; // ASR |
4'hf: { o_c, c } <= w_lsr_result[32:0]; // LSR |
default: o_c <= i_b; // MOV, LDI |
endcase |
end |
end else begin |
125,12 → 100,10
// |
// Multiply pre-logic |
// |
wire signed_mpy; |
assign signed_mpy = i_op[0]; |
wire signed [16:0] w_mpy_a_input, w_mpy_b_input; |
wire signed [33:0] w_mpy_result; |
assign w_mpy_a_input ={ ((i_a[15])&&(signed_mpy)), i_a[15:0] }; |
assign w_mpy_b_input ={ ((i_b[15])&&(signed_mpy)), i_b[15:0] }; |
assign w_mpy_a_input = { ((i_a[15])&&(i_op[2])), i_a[15:0] }; |
assign w_mpy_b_input = { ((i_b[15])&&(i_op[2])), i_b[15:0] }; |
assign w_mpy_result = w_mpy_a_input * w_mpy_b_input; |
|
|
143,22 → 116,20
pre_sign <= (i_a[31]); |
c <= 1'b0; |
casez(i_op) |
4'b0000:{c,o_c } <= {1'b0,i_a}-{1'b0,i_b};// CMP/SUB |
4'b0001: o_c <= i_a & i_b; // BTST/And |
4'b0010:{c,o_c } <= i_a + i_b; // Add |
4'b0011: o_c <= i_a | i_b; // Or |
4'b0100: o_c <= i_a ^ i_b; // Xor |
4'b0101:{o_c,c } <= w_lsr_result[32:0]; // LSR |
4'b0110:{c,o_c } <= (|i_b[31:5])? 33'h00 : {1'b0, i_a } << i_b[4:0]; // LSL |
4'b0111:{o_c,c } <= w_asr_result[32:0]; // ASR |
4'b1000: o_c <= { i_b[15: 0], i_a[15:0] }; // LODIHI |
4'b1001: o_c <= { i_a[31:16], i_b[15:0] }; // LODILO |
4'b1010:{c,o_c } <= {1'b0,w_mpy_result[31:0]}; // MPYU |
4'b1011:{c,o_c } <= {1'b0,w_mpy_result[31:0]}; // MPYS |
4'b1100: o_c <= w_brev_result; // BREV |
4'b1101: o_c <= w_popc_result; // POPC |
4'b1110: o_c <= w_rol_result; // ROL |
default: o_c <= i_b; // MOV, LDI |
4'b?000:{c,o_c } <= {1'b0,i_a} - {1'b0,i_b};// CMP/SUB |
4'b?001: o_c <= i_a & i_b; // BTST/And |
4'h3: { c, o_c } <= {1'b0,w_mpy_result[31:0]}; // MPYU |
4'h4: { c, o_c } <= {1'b0,w_mpy_result[31:0]}; // MPYS |
4'h5: o_c <= w_rol_result; // ROL |
4'h6: o_c <= { i_a[31:16], i_b[15:0] }; // LODILO |
4'h7: o_c <= { i_b[15: 0], i_a[15:0] }; // LODIHI |
4'ha: { c, o_c } <= i_a + i_b; // Add |
4'hb: o_c <= i_a | i_b; // Or |
4'hc: o_c <= i_a ^ i_b; // Xor |
4'hd: { c, o_c } <= (|i_b[31:5])? 33'h00 : {1'b0, i_a } << i_b[4:0]; // LSL |
4'he: { o_c, c } <= w_asr_result[32:0]; // ASR |
4'hf: { o_c, c } <= w_lsr_result[32:0]; // LSR |
default: o_c <= i_b; // MOV, LDI |
endcase |
end |
end endgenerate |
/core/memops.v
15,7 → 15,7
// error signal). |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
37,7 → 37,7
// |
/////////////////////////////////////////////////////////////////////////// |
// |
module memops(i_clk, i_rst, i_stb, i_lock, |
module memops(i_clk, i_rst, i_stb, |
i_op, i_addr, i_data, i_oreg, |
o_busy, o_valid, o_err, o_wreg, o_result, |
o_wb_cyc_gbl, o_wb_cyc_lcl, |
44,9 → 44,9
o_wb_stb_gbl, o_wb_stb_lcl, |
o_wb_we, o_wb_addr, o_wb_data, |
i_wb_ack, i_wb_stall, i_wb_err, i_wb_data); |
parameter ADDRESS_WIDTH=24, IMPLEMENT_LOCK=0, AW=ADDRESS_WIDTH; |
parameter ADDRESS_WIDTH=24, AW=ADDRESS_WIDTH; |
input i_clk, i_rst; |
input i_stb, i_lock; |
input i_stb; |
// CPU interface |
input i_op; |
input [31:0] i_addr; |
59,11 → 59,8
output reg [4:0] o_wreg; |
output reg [31:0] o_result; |
// Wishbone outputs |
output wire o_wb_cyc_gbl; |
output reg o_wb_stb_gbl; |
output wire o_wb_cyc_lcl; |
output reg o_wb_stb_lcl; |
output reg o_wb_we; |
output reg o_wb_cyc_gbl, o_wb_stb_gbl; |
output reg o_wb_cyc_lcl, o_wb_stb_lcl, o_wb_we; |
output reg [(AW-1):0] o_wb_addr; |
output reg [31:0] o_wb_data; |
// Wishbone inputs |
70,29 → 67,26
input i_wb_ack, i_wb_stall, i_wb_err; |
input [31:0] i_wb_data; |
|
reg r_wb_cyc_gbl, r_wb_cyc_lcl; |
wire gbl_stb, lcl_stb; |
assign lcl_stb = (i_stb)&&(i_addr[31:8]==24'hc00000)&&(i_addr[7:5]==3'h0); |
assign gbl_stb = (i_stb)&&((i_addr[31:8]!=24'hc00000)||(i_addr[7:5]!=3'h0)); |
|
initial r_wb_cyc_gbl = 1'b0; |
initial r_wb_cyc_lcl = 1'b0; |
always @(posedge i_clk) |
if (i_rst) |
begin |
r_wb_cyc_gbl <= 1'b0; |
r_wb_cyc_lcl <= 1'b0; |
end else if ((r_wb_cyc_gbl)||(r_wb_cyc_lcl)) |
o_wb_cyc_gbl <= 1'b0; |
o_wb_cyc_lcl <= 1'b0; |
end else if ((o_wb_cyc_gbl)||(o_wb_cyc_lcl)) |
begin |
if ((i_wb_ack)||(i_wb_err)) |
begin |
r_wb_cyc_gbl <= 1'b0; |
r_wb_cyc_lcl <= 1'b0; |
o_wb_cyc_gbl <= 1'b0; |
o_wb_cyc_lcl <= 1'b0; |
end |
end else if (i_stb) // New memory operation |
begin // Grab the wishbone |
r_wb_cyc_lcl <= lcl_stb; |
r_wb_cyc_gbl <= gbl_stb; |
o_wb_cyc_lcl <= lcl_stb; |
o_wb_cyc_gbl <= gbl_stb; |
end |
always @(posedge i_clk) |
if (o_wb_cyc_gbl) |
126,25 → 120,4
always @(posedge i_clk) |
if (i_wb_ack) |
o_result <= i_wb_data; |
|
generate |
if (IMPLEMENT_LOCK != 0) |
begin |
reg lock_gbl, lock_lcl; |
|
initial lock_gbl = 1'b0; |
initial lock_lcl = 1'b0; |
|
always @(posedge i_clk) |
begin |
lock_gbl <= (i_lock)&&((r_wb_cyc_gbl)||(lock_gbl)); |
lock_lcl <= (i_lock)&&((r_wb_cyc_lcl)||(lock_lcl)); |
end |
|
assign o_wb_cyc_gbl = (r_wb_cyc_gbl)||(lock_gbl); |
assign o_wb_cyc_lcl = (r_wb_cyc_lcl)||(lock_lcl); |
end else begin |
assign o_wb_cyc_gbl = (r_wb_cyc_gbl); |
assign o_wb_cyc_lcl = (r_wb_cyc_lcl); |
end endgenerate |
endmodule |
/cpudefs.v
24,7 → 24,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////////// |
// |
53,6 → 53,24
// it handles various instructions within the set: |
// |
// |
// OPT_CONDITIONAL_FLAGS controls whether or not a conditional instruction |
// is allowed to set flags. If conditional instructions can set flags, then |
// strings of conditional instructions will die whenever a flag setting |
// instruction is executed. If they cannot, then you can execute a string |
// of functions with no further conditions in them. Set this flag to enable |
// strings of instructions, as these can be a lot cheaper than the pipeline |
// stalls associated with a conditional branch. |
// |
// This option will likely be changed in the future so that "CMP" and "TST" |
// instructions set the flags even if they are conditional, to allow multiple |
// conditions to be tested at once. |
// |
// I recommend setting this flag |
// |
`define OPT_CONDITIONAL_FLAGS |
// |
// |
// |
// OPT_ILLEGAL_INSTRUCTION is part of a new section of code that is supposed |
// to recognize illegal instructions and interrupt the CPU whenever one such |
// instruction is encountered. The goal is to create a soft floating point |
81,54 → 99,6
// |
// |
// |
// OPT_DIVIDE controls whether or not the divide instruction is built and |
// included into the ZipCPU by default. Set this option and a parameter will |
// be set that causes the divide unit to be included. (This parameter may |
// still be overridden, as with any parameter ...) If the divide is not |
// included and OPT_ILLEGAL_INSTRUCTION is set, then the multiply will create |
// an illegal instruction exception that will send the CPU into supervisor |
// mode. |
// |
// |
`define OPT_DIVIDE |
// |
// |
// |
// OPT_IMPLEMENT_FPU will (one day) control whether or not the floating point |
// unit (once I have one) is built and included into the ZipCPU by default. |
// At that time, if this option is set then a parameter will be set that |
// causes the floating point unit to be included. (This parameter may |
// still be overridden, as with any parameter ...) If the floating point unit |
// is not included and OPT_ILLEGAL_INSTRUCTION is set, then as with the |
// multiply and divide any floating point instruction will result in an illegal |
// instruction exception that will send the CPU into supervisor mode. |
// |
// |
// `define OPT_IMPLEMENT_FPU |
// |
// |
// |
// OPT_NEW_INSTRUCTION_SET controls whether or not the new instruction set |
// is in use. The new instruction set contains space for floating point |
// operations, signed and unsigned divide instructions, as well as bit reversal |
// and ... at least two other operations yet to be defined. The decoder alone |
// uses about 70 fewer LUTs, although in practice this works out to 12 fewer |
// when all works out in the wash. Further, floating point and divide |
// instructions will cause an illegal instruction exception if they are not |
// implemented--so software capability can be built to use these instructions |
// immediately, even if the hardware is not yet ready. |
// |
// This option is likely to go away in the future, obsoleting the previous |
// instruction set, so I recommend setting this option and switching to the |
// new instruction set as soon as possible. |
// |
`define OPT_NEW_INSTRUCTION_SET |
// |
// |
// |
// |
// |
// |
// OPT_SINGLE_FETCH controls whether or not the prefetch has a cache, and |
// whether or not it can issue one instruction per clock. When set, the |
// prefetch has no cache, and only one instruction is fetched at a time. |
167,39 → 137,27
// |
// |
// |
// OPT_PIPELINED is the natural result and opposite of using the single |
// instruction fetch unit. If you are not using that unit, the ZipCPU will |
// be pipelined. The option is defined here more for readability than |
// anything else, since OPT_PIPELINED makes more sense than OPT_SINGLE_FETCH, |
// well ... that and it does a better job of explaining what is going on. |
// OPT_PRECLEAR_BUS allows an upcoming, unconditional, LOD/STO instruction |
// to kick the prefetch off the memory bus so that the LOD/STO instruction may |
// use the bus without waiting for the prefetch cycle to complete. While it |
// sounds like this should speed things up, it isn't clear that it speeds up |
// programs that much--often the bus gets precleared for the LOD/STO, only |
// to have the next instruction stall because it wasn't loaded in time. |
// |
// In other words, leave this define alone--lest you break the ZipCPU. |
// While I recommend setting this flag, that recommendation may change in the |
// future. |
// |
`define OPT_PIPELINED |
`define OPT_PRECLEAR_BUS |
// |
// |
// |
// OPT_TRADITIONAL_PFCACHE allows you to switch between one of two prefetch |
// caches. If enabled, a more traditional cache is implemented. This more |
// traditional cache (currently) uses many more LUTs, but it also reduces |
// the stall count tremendously over the alternative hacked pipeline cache. |
// (The traditional pfcache is also pipelined, whereas the pipeline cache |
// implements a windowed approach to caching.) |
// |
// If you have the fabric to support this option, I recommend including it. |
// |
`define OPT_TRADITIONAL_PFCACHE |
// |
// |
// |
// OPT_EARLY_BRANCHING is an attempt to execute a BRA statement as early |
// as possible, to avoid as many pipeline stalls on a branch as possible. |
// It's not tremendously successful yet--BRA's still suffer stalls, |
// It's not tremendously successful yet--BRA's suffer 3 stalls instead of 5, |
// but I intend to keep working on this approach until the number of stalls |
// gets down to one or (ideally) zero. (With the OPT_TRADITIONAL_PFCACHE, this |
// gets down to a single stall cycle ...) That way a "BRA" can be used as the |
// compiler's branch prediction optimizer: BRA's barely stall, while branches |
// on conditions will always suffer about 4 stall cycles or so. |
// gets down to one or (ideally) zero. That way a "BRA" can be used as the |
// compiler's branch prediction optimizer: BRA's don't stall, while branches on |
// conditions will always suffer about 5 stalls or so. |
// |
// I recommend setting this flag, so as to turn early branching on. |
// |
223,50 → 181,26
// |
// |
// |
`ifdef OPT_NEW_INSTRUCTION_SET |
// OPT_SINGLE_CYCLE controls how the Zip CPU handles operations where the |
// second of two instructions uses a register output from the first of the |
// two. If set, there will be no stalling between such a pair of instructions. |
// If not set, the CPU will insert a stall between such a pair to give the |
// result time to propagate to the second instruction. Other than the existence |
// of a stall, the CPU will still yield the same results for the same |
// instructions. |
// |
// The purpose of this is really timing: With this option defined, a logical |
// or combinatorial mux is placed prior to the input of the ALU. This mux, |
// together with whatever ALU operation is to take place, must both fit within |
// one clock cycle. If they cannot be made to fit within the one clock cycle, |
// then either the clock must be slowed down so that they can fit, or this |
// flag needs to be turned off (not set) to get rid of the mux--hence speeding |
// up the clock while slowing down some instructions. |
// |
`define OPT_SINGLE_CYCLE |
// |
// The new instruction set also defines a set of very long instruction words. |
// Well, calling them "very long" instruction words is probably a misnomer, |
// although we're going to do it. They're really 2x16-bit instructions--- |
// instruction words that pack two instructions into one word. (2x14 bit |
// really--'cause you need a bit to note the instruction is a 2x instruction, |
// and then 3-bits for the condition codes ...) Set OPT_VLIW to include these |
// double instructions as part of the new instruction set. These allow a single |
// instruction to contain two instructions within. These instructions are |
// designed to get more code density from the instruction set, and to hopefully |
// take some pain off of the performance of the pre-fetch and instruction cache. |
// |
// These new instructions, however, also necessitate a change in the Zip |
// CPU--the Zip CPU can no longer execute instructions atomically. It must |
// now execute non-VLIW instructions, or VLIW instruction pairs, atomically. |
// This logic has been added into the ZipCPU, but it has not (yet) been |
// tested thoroughly. |
// |
// Oh, and the assembler, the debugger, and the object file dumper, and the |
// simulator all need to be updated as well .... |
// |
`define OPT_VLIW |
// |
// |
`endif |
// |
// |
`endif // OPT_SINGLE_FETCH |
// |
// |
// |
// Now let's talk about peripherals for a moment. These next two defines |
// control whether the DMA controller is included in the Zip System, and |
// whether or not the 8 accounting timers are also included. Set these to |
// include the respective peripherals, comment them out not to. |
// |
`define INCLUDE_DMA_CONTROLLER |
`define INCLUDE_ACCOUNTING_COUNTERS |
// |
// |
// `define DEBUG_SCOPE |
`define NEW_PREFETCH_VERSION |
// |
`endif // CPUDEFS_H |
/aux/busdelay.v
19,7 → 19,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
/aux/wbpriarbiter.v
23,7 → 23,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
/aux/wbarbiter.v
32,7 → 32,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
/aux/wbdblpriarb.v
40,7 → 40,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
/Makefile
9,7 → 9,7
# |
# |
# Creator: Dan Gisselquist, Ph.D. |
# Gisselquist Technology, LLC |
# Gisselquist Tecnology, LLC |
# |
################################################################################ |
# |
32,7 → 32,7
################################################################################ |
# |
.PHONY: all |
all: zipsystem zipbones cpudefs.h div |
all: zipsystem zipbones cpudefs.h |
|
CORED:= core |
PRPHD:= peripherals |
41,20 → 41,16
$(PRPHD)/wbdmac.v $(PRPHD)/icontrol.v \ |
$(PRPHD)/zipcounter.v $(PRPHD)/zipjiffies.v \ |
$(PRPHD)/ziptimer.v $(PRPHD)/ziptrap.v \ |
$(CORED)/zipcpu.v $(CORED)/cpuops.v $(CORED)/idecode.v \ |
$(CORED)/zipcpu.v $(CORED)/cpuops.v \ |
$(CORED)/pipefetch.v $(CORED)/prefetch.v \ |
$(CORED)/pfcache.v \ |
$(CORED)/memops.v $(CORED)/pipemem.v \ |
$(AUXD)/busdelay.v \ |
$(AUXD)/wbdblpriarb.v $(AUXD)/wbpriarbiter.v \ |
$(CORED)/idecode.v $(CORED)/cpuops.v |
$(AUXD)/wbdblpriarb.v $(AUXD)/wbpriarbiter.v |
VZIP := zipbones.v cpudefs.v \ |
$(CORED)/zipcpu.v $(CORED)/cpuops.v $(CORED)/idecode.v \ |
$(CORED)/zipcpu.v $(CORED)/cpuops.v \ |
$(CORED)/pipefetch.v $(CORED)/prefetch.v \ |
$(CORED)/pfcache.v \ |
$(CORED)/memops.v $(CORED)/pipemem.v \ |
$(AUXD)/busdelay.v $(AUXD)/wbdblpriarb.v \ |
$(CORED)/idecode.v $(CORED)/cpuops.v |
$(AUXD)/busdelay.v $(AUXD)/wbdblpriarb.v |
|
VOBJ := obj_dir |
|
66,25 → 62,17
verilator -cc -y $(CORED) -y $(PRPHD) -y $(AUXD) zipbones.v |
$(VOBJ)/Vzipbones.h: $(VOBJ)/Vzipbones.cpp |
|
$(VOBJ)/Vdiv.cpp: $(CORED)/div.v |
verilator -cc -y $(CORED) -y $(PRPHD) -y $(AUXD) $(CORED)/div.v |
$(VOBJ)/Vdiv.h: $(VOBJ)/Vdiv.cpp |
|
$(VOBJ)/Vzipsystem__ALL.a: $(VOBJ)/Vzipsystem.cpp $(VOBJ)/Vzipsystem.h |
cd $(VOBJ); make --no-print-directory -f Vzipsystem.mk |
cd $(VOBJ); make -f Vzipsystem.mk |
|
$(VOBJ)/Vzipbones__ALL.a: $(VOBJ)/Vzipbones.cpp $(VOBJ)/Vzipbones.h |
cd $(VOBJ); make --no-print-directory -f Vzipbones.mk |
cd $(VOBJ); make -f Vzipbones.mk |
|
$(VOBJ)/Vdiv__ALL.a: $(VOBJ)/Vdiv.cpp $(VOBJ)/Vdiv.h |
cd $(VOBJ); make --no-print-directory -f Vdiv.mk |
|
cpudefs.h: cpudefs.v |
@echo "Building cpudefs.h" |
@echo "// " > $@ |
@echo "// Do not edit this file, it is automatically generated!" >> $@ |
@echo "// " >> $@ |
@grep "^\`" $^ | sed -e '{ s/^`/#/ }' >> $@ |
echo "// " > $@ |
echo "// Do not edit this file, it is automatically generated!" >> $@ |
echo "// " >> $@ |
grep "^\`" $^ | sed -e '{ s/^`/#/ }' >> $@ |
|
.PHONY: zipsystem |
zipsystem: $(VOBJ)/Vzipsystem__ALL.a |
92,9 → 80,6
.PHONY: zipbones |
zipbones: $(VOBJ)/Vzipbones__ALL.a |
|
.PHONY: div |
div: $(VOBJ)/Vdiv__ALL.a |
|
.PHONY: clean |
clean: |
rm -rf $(VOBJ) cpudefs.h |
/peripherals/wbwatchdog.v
File deleted
/peripherals/ziptimer.v
41,7 → 41,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
/peripherals/wbdmac.v
79,7 → 79,7
// register. |
// |
// Creator: Dan Gisselquist |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
// Copyright: 2015 |
// |
111,7 → 111,8
o_mwb_cyc, o_mwb_stb, o_mwb_we, o_mwb_addr, o_mwb_data, |
i_mwb_ack, i_mwb_stall, i_mwb_data, i_mwb_err, |
i_dev_ints, |
o_interrupt); |
o_interrupt, |
i_other_busmaster_requests_bus); |
parameter ADDRESS_WIDTH=32, LGMEMLEN = 10, |
DW=32, LGDV=5,AW=ADDRESS_WIDTH; |
input i_clk; |
136,13 → 137,7
// An interrupt to be set upon completion |
output reg o_interrupt; |
// Need to release the bus for a higher priority user |
// This logic had lots of problems, so it is being |
// removed. If you want to make sure the bus is available |
// for a higher priority user, adjust the transfer length |
// accordingly. |
// |
// input i_other_busmaster_requests_bus; |
// |
input i_other_busmaster_requests_bus; |
|
|
reg cfg_wp; // Write protect |
174,7 → 169,8
if ((o_mwb_stb)&&(~i_mwb_stall)) |
begin |
nwritten <= nwritten+1; |
if (nwritten == nread-1) |
if ((nwritten == nread-1) |
||(i_other_busmaster_requests_bus)) |
// Wishbone interruptus |
o_mwb_stb <= 1'b0; |
else if (cfg_incd) begin |
209,7 → 205,8
begin |
nacks <= nacks+1; |
if ((nacks == {1'b0, cfg_blocklen_sub_one}) |
||(bus_nacks <= cfg_len-1)) |
||(bus_nacks <= cfg_len-1) |
||(i_other_busmaster_requests_bus)) |
// Wishbone interruptus |
o_mwb_stb <= 1'b0; |
else if (cfg_incs) begin |
/peripherals/zipjiffies.v
41,7 → 41,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
/peripherals/flashcache.v
10,10 → 10,6
// some amount of flash to be copied into this on-chip RAM, |
// and then access it with nearly zero latency. |
// |
// Status: This file is no longer being used as an active file within |
// the ZipCPU project. It's an older file from an idea that |
// never really caught traction. |
// |
// Interface: |
// FlashCache sits on the Wishbone bus as both a slave and a master. |
// Slave requests for memory will get mapped to a local RAM, from which |
39,7 → 35,7
// less than the copy address. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
/peripherals/zipcounter.v
23,7 → 23,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
/peripherals/ziptrap.v
49,7 → 49,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
/////////////////////////////////////////////////////////////////////////// |
// |
/peripherals/icontrol.v
48,7 → 48,7
// |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// Gisselquist Tecnology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
71,7 → 71,7
//////////////////////////////////////////////////////////////////////////////// |
// |
module icontrol(i_clk, i_reset, i_wr, i_proc_bus, o_proc_bus, |
i_brd_ints, o_interrupt); |
i_brd_ints, o_interrupt_strobe); |
parameter IUSED = 15; |
input i_clk, i_reset; |
input i_wr; |
78,7 → 78,7
input [31:0] i_proc_bus; |
output wire [31:0] o_proc_bus; |
input [(IUSED-1):0] i_brd_ints; |
output wire o_interrupt; |
output reg o_interrupt_strobe; |
|
reg [(IUSED-1):0] r_int_state; |
reg [(IUSED-1):0] r_int_enable; |
127,7 → 127,6
assign o_proc_bus = { r_gie, r_int_enable, r_any, r_int_state }; |
end endgenerate |
|
/* |
reg int_condition; |
initial int_condition = 1'b0; |
initial o_interrupt_strobe = 1'b0; |
146,8 → 145,5
o_interrupt_strobe <= 1'b1; |
end else |
o_interrupt_strobe <= 1'b0; |
*/ |
|
assign o_interrupt = r_interrupt; |
|
endmodule |