@@ -4,21 +4,24 @@ import chisel3._
44import  chisel3 .util ._ 
55import  difftest ._ 
66
7- import  treecorel2 .common .ConstVal 
7+ import  treecorel2 .common .{ ConstVal ,  InstConfig } 
88
9- class  CSRReg  extends  Module  {
9+ object  CSRReg  {
10+   val  timeCause   =  " h8000_0000_0000_0007" U (64 .W )
11+   val  ecallCause  =  " h0000_0000_0000_000b" U (64 .W )
12+ }
13+ 
14+ class  CSRReg  extends  Module  with  InstConfig  {
1015  val  io  =  IO (new  Bundle  {
1116    val  globalEn    =  Input (Bool ())
12-     val  pc          =  Input (UInt (64 .W ))
13-     val  inst        =  Input (UInt (64 .W ))
14-     val  src         =  Input (UInt (64 .W ))
15-     val  data        =  Output (UInt (64 .W ))
17+     val  pc          =  Input (UInt (XLen .W ))
18+     val  inst        =  Input (UInt (XLen .W ))
19+     val  src         =  Input (UInt (XLen .W ))
20+     val  data        =  Output (UInt (XLen .W ))
1621    val  mtip        =  Input (Bool ())
1722    val  timeIntrEn  =  Output (Bool ())
1823    val  ecallEn     =  Output (Bool ())
19- 
20-     // difftest
21-     val  csrState  =  Flipped (new  DiffCSRStateIO )
24+     val  csrState    =  Flipped (new  DiffCSRStateIO )
2225  })
2326
2427  protected  val  csrrwVis   =  (io.inst ===  BitPat (" b????????????_?????_001_?????_1110011" 
@@ -30,19 +33,19 @@ class CSRReg extends Module {
3033  protected  val  csrVis     =  csrrcVis ||  csrrciVis ||  csrrsVis ||  csrrsiVis ||  csrrwVis ||  csrrwiVis
3134  protected  val  mretVis    =  (io.inst ===  BitPat (" b001100000010_00000_000_00000_1110011" 
3235  protected  val  ecallVis   =  (io.inst ===  BitPat (" b000000000000_00000_000_00000_1110011" 
33-   protected  val  zimm       =  ZeroExt (io.inst(19 , 15 ), 64 )
36+   protected  val  zimm       =  ZeroExt (io.inst(19 , 15 ), XLen )
3437  protected  val  addr       =  io.inst(31 , 20 )
3538
36-   protected  val  mcycle    =  RegInit (0 .U (64 .W ))
37-   protected  val  mstatus   =  RegInit (0 .U (64 .W ))
38-   protected  val  mtvec     =  RegInit (0 .U (64 .W ))
39-   protected  val  mcause    =  RegInit (0 .U (64 .W ))
40-   protected  val  mepc      =  RegInit (0 .U (64 .W ))
41-   protected  val  mie       =  RegInit (0 .U (64 .W ))
42-   protected  val  mip       =  RegInit (0 .U (64 .W ))
43-   protected  val  mscratch  =  RegInit (0 .U (64 .W ))
44-   protected  val  medeleg   =  RegInit (0 .U (64 .W ))
45-   protected  val  mhartid   =  RegInit (0 .U (64 .W ))
39+   protected  val  mcycle    =  RegInit (0 .U (XLen .W ))
40+   protected  val  mstatus   =  RegInit (0 .U (XLen .W ))
41+   protected  val  mtvec     =  RegInit (0 .U (XLen .W ))
42+   protected  val  mcause    =  RegInit (0 .U (XLen .W ))
43+   protected  val  mepc      =  RegInit (0 .U (XLen .W ))
44+   protected  val  mie       =  RegInit (0 .U (XLen .W ))
45+   protected  val  mip       =  RegInit (0 .U (XLen .W ))
46+   protected  val  mscratch  =  RegInit (0 .U (XLen .W ))
47+   protected  val  medeleg   =  RegInit (0 .U (XLen .W ))
48+   protected  val  mhartid   =  RegInit (0 .U (XLen .W ))
4649
4750  protected  val  mhartidVis   =  addr ===  ConstVal .mhartidAddr
4851  protected  val  mstatusVis   =  addr ===  ConstVal .mstatusAddr
@@ -117,9 +120,9 @@ class CSRReg extends Module {
117120    }
118121
119122    when(timeIntrEn) {
120-       mcause :=  " h8000_0000_0000_0007 " . U ( 64 . W ) 
123+       mcause :=  CSRReg .timeCause 
121124    }.elsewhen(ecallEn) {
122-       mcause :=  " h0000_0000_0000_000b " . U ( 64 . W ) 
125+       mcause :=  CSRReg .ecallCause 
123126    }.elsewhen(csrVis &&  mcauseVis) {
124127      mcause :=  wData
125128    }
0 commit comments