2011-10-26 08:02:47 +02:00
|
|
|
package Top
|
|
|
|
{
|
|
|
|
|
2011-11-09 23:52:17 +01:00
|
|
|
import Chisel._;
|
2011-10-26 08:02:47 +02:00
|
|
|
import Node._;
|
|
|
|
import Constants._;
|
2011-11-10 20:26:13 +01:00
|
|
|
import scala.math._;
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
class ioDpathBTB extends Bundle()
|
|
|
|
{
|
2012-01-18 19:28:48 +01:00
|
|
|
val current_pc4 = UFix(VADDR_BITS, INPUT);
|
|
|
|
val hit = Bool(OUTPUT);
|
|
|
|
val target = UFix(VADDR_BITS, OUTPUT);
|
|
|
|
val wen = Bool(INPUT);
|
|
|
|
val clr = Bool(INPUT);
|
|
|
|
val correct_pc4 = UFix(VADDR_BITS, INPUT);
|
|
|
|
val correct_target = UFix(VADDR_BITS, INPUT);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
2011-11-10 20:26:13 +01:00
|
|
|
// basic direct-mapped branch target buffer
|
|
|
|
class rocketDpathBTB(entries: Int) extends Component
|
2011-10-26 08:02:47 +02:00
|
|
|
{
|
2011-11-10 20:26:13 +01:00
|
|
|
val io = new ioDpathBTB();
|
2011-11-10 09:50:09 +01:00
|
|
|
|
2011-11-10 20:26:13 +01:00
|
|
|
val addr_bits = ceil(log10(entries)/log10(2)).toInt;
|
|
|
|
val idxlsb = 2;
|
|
|
|
val idxmsb = idxlsb+addr_bits-1;
|
|
|
|
val tagmsb = (VADDR_BITS-idxmsb-1)+(VADDR_BITS-idxlsb)-1;
|
|
|
|
val taglsb = (VADDR_BITS-idxlsb);
|
|
|
|
|
2012-01-18 06:12:31 +01:00
|
|
|
val vb_array = Mem(entries, io.wen || io.clr, io.correct_pc4(idxmsb,idxlsb), !io.clr, resetVal = Bool(false));
|
2012-01-24 05:59:38 +01:00
|
|
|
val tag_target_array = Mem4(entries, io.wen, io.correct_pc4(idxmsb,idxlsb),
|
|
|
|
Cat(io.correct_pc4(VADDR_BITS-1,idxmsb+1), io.correct_target(VADDR_BITS-1,idxlsb)))
|
|
|
|
tag_target_array.setReadLatency(0);
|
|
|
|
tag_target_array.setTarget('inst);
|
2012-01-18 06:12:31 +01:00
|
|
|
val is_val = vb_array(io.current_pc4(idxmsb,idxlsb));
|
|
|
|
val tag_target = tag_target_array(io.current_pc4(idxmsb, idxlsb));
|
2011-11-10 20:26:13 +01:00
|
|
|
|
2012-01-18 06:12:31 +01:00
|
|
|
io.hit := is_val && (tag_target(tagmsb,taglsb) === io.current_pc4(VADDR_BITS-1, idxmsb+1));
|
2011-11-10 20:26:13 +01:00
|
|
|
io.target := Cat(tag_target(taglsb-1, 0), Bits(0,idxlsb)).toUFix;
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ioDpathPCR extends Bundle()
|
|
|
|
{
|
|
|
|
val host = new ioHost(List("from", "from_wen", "to"));
|
2011-11-10 06:54:11 +01:00
|
|
|
val debug = new ioDebug(List("error_mode", "log_control"));
|
2011-10-26 08:02:47 +02:00
|
|
|
val r = new ioReadPort();
|
|
|
|
val w = new ioWritePort();
|
|
|
|
|
2012-01-18 19:28:48 +01:00
|
|
|
val status = Bits(17, OUTPUT);
|
|
|
|
val ptbr = UFix(PADDR_BITS, OUTPUT);
|
|
|
|
val evec = UFix(VADDR_BITS, OUTPUT);
|
|
|
|
val exception = Bool(INPUT);
|
|
|
|
val cause = UFix(5, INPUT);
|
|
|
|
val badvaddr_wen = Bool(INPUT);
|
|
|
|
val pc = UFix(VADDR_BITS, INPUT);
|
|
|
|
val eret = Bool(INPUT);
|
|
|
|
val ei = Bool(INPUT);
|
|
|
|
val di = Bool(INPUT);
|
|
|
|
val ptbr_wen = Bool(OUTPUT);
|
|
|
|
val irq_timer = Bool(OUTPUT);
|
|
|
|
val irq_ipi = Bool(OUTPUT);
|
|
|
|
val console_data = Bits(8, OUTPUT);
|
|
|
|
val console_val = Bool(OUTPUT);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class rocketDpathPCR extends Component
|
|
|
|
{
|
2011-11-09 23:52:17 +01:00
|
|
|
val io = new ioDpathPCR();
|
|
|
|
|
2012-01-02 01:09:40 +01:00
|
|
|
val reg_epc = Reg() { UFix() };
|
|
|
|
val reg_badvaddr = Reg() { UFix() };
|
|
|
|
val reg_ebase = Reg() { UFix() };
|
|
|
|
val reg_count = Reg() { UFix() };
|
|
|
|
val reg_compare = Reg() { UFix() };
|
|
|
|
val reg_cause = Reg() { Bits() };
|
2012-01-04 00:09:08 +01:00
|
|
|
val reg_tohost = Reg(resetVal = Bits(0, 64));
|
|
|
|
val reg_fromhost = Reg(resetVal = Bits(0, 64));
|
2012-01-02 01:09:40 +01:00
|
|
|
val reg_k0 = Reg() { Bits() };
|
|
|
|
val reg_k1 = Reg() { Bits() };
|
|
|
|
val reg_ptbr = Reg() { UFix() };
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
val reg_error_mode = Reg(resetVal = Bool(false));
|
2011-11-09 23:52:17 +01:00
|
|
|
val reg_status_vm = Reg(resetVal = Bool(false));
|
2011-10-26 08:02:47 +02:00
|
|
|
val reg_status_im = Reg(resetVal = Bits(0,8));
|
|
|
|
val reg_status_sx = Reg(resetVal = Bool(true));
|
|
|
|
val reg_status_ux = Reg(resetVal = Bool(true));
|
2011-11-14 23:35:10 +01:00
|
|
|
val reg_status_ec = Reg(resetVal = Bool(false));
|
2011-10-26 08:02:47 +02:00
|
|
|
val reg_status_ef = Reg(resetVal = Bool(false));
|
|
|
|
val reg_status_ev = Reg(resetVal = Bool(false));
|
|
|
|
val reg_status_s = Reg(resetVal = Bool(true));
|
|
|
|
val reg_status_ps = Reg(resetVal = Bool(false));
|
|
|
|
val reg_status_et = Reg(resetVal = Bool(false));
|
|
|
|
|
2011-11-14 12:24:02 +01:00
|
|
|
val r_irq_timer = Reg(resetVal = Bool(false));
|
|
|
|
val r_irq_ipi = Reg(resetVal = Bool(false));
|
2011-11-13 09:27:57 +01:00
|
|
|
|
2011-11-14 23:35:10 +01:00
|
|
|
val reg_status = Cat(reg_status_sx, reg_status_ux, reg_status_s, reg_status_ps, reg_status_ec, reg_status_ev, reg_status_ef, reg_status_et);
|
2011-10-26 08:02:47 +02:00
|
|
|
val rdata = Wire() { Bits() };
|
|
|
|
|
2011-11-14 13:13:13 +01:00
|
|
|
io.ptbr_wen := reg_status_vm.toBool && !io.exception && io.w.en && (io.w.addr === PCR_PTBR);
|
2011-11-09 23:52:17 +01:00
|
|
|
io.status := Cat(reg_status_vm, reg_status_im, reg_status);
|
2011-11-10 09:50:09 +01:00
|
|
|
io.evec := reg_ebase;
|
2011-11-09 23:52:17 +01:00
|
|
|
io.ptbr := reg_ptbr;
|
2012-01-04 00:09:08 +01:00
|
|
|
io.host.to := Mux(io.host.from_wen, Bits(0), reg_tohost);
|
2011-10-26 08:02:47 +02:00
|
|
|
io.debug.error_mode := reg_error_mode;
|
|
|
|
io.r.data := rdata;
|
|
|
|
|
2011-12-01 07:51:59 +01:00
|
|
|
val console_wen = !io.exception && io.w.en && (io.w.addr === PCR_CONSOLE);
|
|
|
|
io.console_data := Mux(console_wen, io.w.data(7,0), Bits(0,8));
|
|
|
|
io.console_val := console_wen;
|
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
when (io.host.from_wen) {
|
2012-01-04 00:09:08 +01:00
|
|
|
reg_tohost <== Bits(0);
|
2011-10-26 08:02:47 +02:00
|
|
|
reg_fromhost <== io.host.from;
|
|
|
|
}
|
|
|
|
otherwise {
|
|
|
|
when (!io.exception && io.w.en && (io.w.addr === PCR_TOHOST)) {
|
2012-01-04 00:09:08 +01:00
|
|
|
reg_tohost <== io.w.data;
|
|
|
|
reg_fromhost <== Bits(0);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
}
|
2011-11-14 12:24:02 +01:00
|
|
|
|
2011-11-10 11:46:09 +01:00
|
|
|
when (io.badvaddr_wen) {
|
2011-11-18 08:50:45 +01:00
|
|
|
reg_badvaddr <== io.w.data.toUFix;
|
2011-11-10 11:46:09 +01:00
|
|
|
}
|
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
when (io.exception && !reg_status_et) {
|
|
|
|
reg_error_mode <== Bool(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
when (io.exception && reg_status_et) {
|
|
|
|
reg_status_s <== Bool(true);
|
|
|
|
reg_status_ps <== reg_status_s;
|
|
|
|
reg_status_et <== Bool(false);
|
|
|
|
reg_epc <== io.pc;
|
|
|
|
reg_cause <== io.cause;
|
|
|
|
}
|
2011-11-14 22:48:49 +01:00
|
|
|
|
|
|
|
when (!io.exception && io.di) {
|
|
|
|
reg_status_et <== Bool(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
when (!io.exception && io.ei) {
|
|
|
|
reg_status_et <== Bool(true);
|
|
|
|
}
|
|
|
|
|
2011-10-26 08:02:47 +02:00
|
|
|
when (!io.exception && io.eret) {
|
|
|
|
reg_status_s <== reg_status_ps;
|
|
|
|
reg_status_et <== Bool(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
when (!io.exception && !io.eret && io.w.en) {
|
|
|
|
when (io.w.addr === PCR_STATUS) {
|
2011-11-11 02:41:22 +01:00
|
|
|
reg_status_vm <== io.w.data(SR_VM).toBool;
|
2011-10-26 08:02:47 +02:00
|
|
|
reg_status_im <== io.w.data(15,8);
|
2011-11-11 02:41:22 +01:00
|
|
|
reg_status_sx <== io.w.data(SR_SX).toBool;
|
|
|
|
reg_status_ux <== io.w.data(SR_UX).toBool;
|
|
|
|
reg_status_s <== io.w.data(SR_S).toBool;
|
|
|
|
reg_status_ps <== io.w.data(SR_PS).toBool;
|
|
|
|
reg_status_ev <== HAVE_VEC && io.w.data(SR_EV).toBool;
|
|
|
|
reg_status_ef <== HAVE_FPU && io.w.data(SR_EF).toBool;
|
2011-11-14 23:35:10 +01:00
|
|
|
reg_status_ec <== HAVE_RVC && io.w.data(SR_EC).toBool;
|
2011-11-11 02:41:22 +01:00
|
|
|
reg_status_et <== io.w.data(SR_ET).toBool;
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
2011-11-10 09:50:09 +01:00
|
|
|
when (io.w.addr === PCR_EPC) { reg_epc <== io.w.data(VADDR_BITS-1,0).toUFix; }
|
|
|
|
when (io.w.addr === PCR_BADVADDR) { reg_badvaddr <== io.w.data(VADDR_BITS-1,0).toUFix; }
|
|
|
|
when (io.w.addr === PCR_EVEC) { reg_ebase <== io.w.data(VADDR_BITS-1,0).toUFix; }
|
2011-11-13 09:27:57 +01:00
|
|
|
when (io.w.addr === PCR_COUNT) { reg_count <== io.w.data(31,0).toUFix; }
|
2011-11-14 12:24:02 +01:00
|
|
|
when (io.w.addr === PCR_COMPARE) { reg_compare <== io.w.data(31,0).toUFix; r_irq_timer <== Bool(false); }
|
2011-10-26 08:02:47 +02:00
|
|
|
when (io.w.addr === PCR_CAUSE) { reg_cause <== io.w.data(4,0); }
|
2012-01-04 00:09:08 +01:00
|
|
|
when (io.w.addr === PCR_FROMHOST) { reg_fromhost <== io.w.data; }
|
2011-11-14 23:35:10 +01:00
|
|
|
when (io.w.addr === PCR_SEND_IPI) { r_irq_ipi <== Bool(true); }
|
|
|
|
when (io.w.addr === PCR_CLR_IPI) { r_irq_ipi <== Bool(false); }
|
2011-10-26 08:02:47 +02:00
|
|
|
when (io.w.addr === PCR_K0) { reg_k0 <== io.w.data; }
|
|
|
|
when (io.w.addr === PCR_K1) { reg_k1 <== io.w.data; }
|
2011-11-09 23:52:17 +01:00
|
|
|
when (io.w.addr === PCR_PTBR) { reg_ptbr <== Cat(io.w.data(PADDR_BITS-1, PGIDX_BITS), Bits(0, PGIDX_BITS)).toUFix; }
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
2011-11-13 09:27:57 +01:00
|
|
|
reg_count <== reg_count + UFix(1);
|
|
|
|
when (reg_count === reg_compare) {
|
2011-11-14 12:24:02 +01:00
|
|
|
r_irq_timer <== Bool(true);
|
2011-11-13 09:27:57 +01:00
|
|
|
}
|
2011-11-14 12:24:02 +01:00
|
|
|
io.irq_timer := r_irq_timer;
|
|
|
|
io.irq_ipi := r_irq_ipi;
|
2011-11-13 09:27:57 +01:00
|
|
|
|
2011-11-10 20:26:13 +01:00
|
|
|
when (!io.r.en) { rdata <== Bits(0,64); }
|
2011-10-26 08:02:47 +02:00
|
|
|
switch (io.r.addr) {
|
2011-11-10 20:26:13 +01:00
|
|
|
is (PCR_STATUS) { rdata <== Cat(Bits(0,47), reg_status_vm, reg_status_im, reg_status); }
|
|
|
|
is (PCR_EPC) { rdata <== Cat(Fill(64-VADDR_BITS, reg_epc(VADDR_BITS-1)), reg_epc); }
|
|
|
|
is (PCR_BADVADDR) { rdata <== Cat(Fill(64-VADDR_BITS, reg_badvaddr(VADDR_BITS-1)), reg_badvaddr); }
|
|
|
|
is (PCR_EVEC) { rdata <== Cat(Fill(64-VADDR_BITS, reg_ebase(VADDR_BITS-1)), reg_ebase); }
|
|
|
|
is (PCR_COUNT) { rdata <== Cat(Fill(32, reg_count(31)), reg_count); }
|
|
|
|
is (PCR_COMPARE) { rdata <== Cat(Fill(32, reg_compare(31)), reg_compare); }
|
|
|
|
is (PCR_CAUSE) { rdata <== Cat(Bits(0,59), reg_cause); }
|
|
|
|
is (PCR_COREID) { rdata <== Bits(COREID,64); }
|
2012-01-04 00:09:08 +01:00
|
|
|
is (PCR_FROMHOST) { rdata <== reg_fromhost; }
|
|
|
|
is (PCR_TOHOST) { rdata <== reg_tohost; }
|
2011-10-26 08:02:47 +02:00
|
|
|
is (PCR_K0) { rdata <== reg_k0; }
|
|
|
|
is (PCR_K1) { rdata <== reg_k1; }
|
2011-11-10 20:26:13 +01:00
|
|
|
is (PCR_PTBR) { rdata <== Cat(Bits(0,64-PADDR_BITS), reg_ptbr); }
|
|
|
|
otherwise { rdata <== Bits(0,64); }
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ioReadPort extends Bundle()
|
|
|
|
{
|
2012-01-18 19:28:48 +01:00
|
|
|
val addr = UFix(5, INPUT);
|
|
|
|
val en = Bool(INPUT);
|
|
|
|
val data = Bits(64, OUTPUT);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ioWritePort extends Bundle()
|
|
|
|
{
|
2012-01-18 19:28:48 +01:00
|
|
|
val addr = UFix(5, INPUT);
|
|
|
|
val en = Bool(INPUT);
|
|
|
|
val data = Bits(64, INPUT);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ioRegfile extends Bundle()
|
|
|
|
{
|
|
|
|
val r0 = new ioReadPort();
|
|
|
|
val r1 = new ioReadPort();
|
|
|
|
val w0 = new ioWritePort();
|
|
|
|
}
|
|
|
|
|
|
|
|
class rocketDpathRegfile extends Component
|
|
|
|
{
|
|
|
|
override val io = new ioRegfile();
|
2012-01-14 05:04:11 +01:00
|
|
|
|
2012-01-24 05:59:38 +01:00
|
|
|
val regfile = Mem4(32, io.w0.data);
|
|
|
|
regfile.setReadLatency(0);
|
|
|
|
regfile.setTarget('inst);
|
|
|
|
regfile.write(io.w0.addr, io.w0.data, io.w0.en);
|
|
|
|
io.r0.data := Mux((io.r0.addr === UFix(0, 5)) || !io.r0.en, Bits(0, 64), regfile(io.r0.addr));
|
|
|
|
io.r1.data := Mux((io.r1.addr === UFix(0, 5)) || !io.r1.en, Bits(0, 64), regfile(io.r1.addr));
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|