Skip to content

Commit 207e4d4

Browse files
authored
Merge pull request #2 from Rainmannn/main
对AUIPC指令及LUI指令译码的修改
2 parents d0a34fe + 0fe0ac3 commit 207e4d4

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

src/main/scala/rv32isc/Alu.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@ class Alu extends Module {
2727
// 用于得到操作数
2828
val oprand1 = WireDefault(0.U(DATA_WIDTH.W))
2929
val oprand2 = WireDefault(0.U(DATA_WIDTH.W))
30-
31-
oprand1 := Mux(io.bundleAluControl.ctrlJAL, io.pc, io.dataRead1)
30+
//新增 corrected
31+
when(io.bundleAluControl.ctrlJAL || io.bundleAluControl.ctrlAUIPC){
32+
oprand1 := io.pc
33+
}.elsewhen(io.bundleAluControl.ctrlLUI){
34+
oprand1 := 0.U
35+
}.otherwise{
36+
oprand1 := io.dataRead1
37+
}
38+
//oprand1 := Mux(io.bundleAluControl.ctrlJAL, io.pc, io.dataRead1) 语句有误
3239
oprand2 := Mux(io.bundleAluControl.ctrlALUSrc, io.imm, io.dataRead2)
3340

3441
// 根据bundleAluControl中的信号进行选择
@@ -97,4 +104,4 @@ class Alu extends Module {
97104

98105
io.resultAlu := resultAlu
99106
io.resultBranch := resultBranch
100-
}
107+
}

src/main/scala/rv32isc/Controller.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class Controller extends Module {
1818
// alu
1919
io.bundleAluControl.ctrlALUSrc := io.bundleControlIn.ctrlALUSrc
2020
io.bundleAluControl.ctrlJAL := io.bundleControlIn.ctrlJAL
21+
io.bundleAluControl.ctrlLUI := io.bundleControlIn.ctrlLUI //新增 corrected
22+
io.bundleAluControl.ctrlAUIPC := io.bundleControlIn.ctrlAUIPC //新增 corrected
2123
io.bundleAluControl.ctrlOP := io.bundleControlIn.ctrlOP
2224
io.bundleAluControl.ctrlSigned := io.bundleControlIn.ctrlSigned
2325
io.bundleAluControl.ctrlBranch := io.bundleControlIn.ctrlBranch
@@ -30,4 +32,4 @@ class Controller extends Module {
3032

3133
// 其他
3234
io.bundleControlOut <> io.bundleControlIn
33-
}
35+
}

src/main/scala/rv32isc/Decoder.scala

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,37 @@ class Decoder extends Module {
4343
val ctrlStore = WireDefault(false.B)
4444
val ctrlALUSrc = WireDefault(false.B)
4545
val ctrlJAL = WireDefault(false.B)
46+
val ctrlAUIPC = WireDefault(false.B)//判断指令是否为AUIPC指令,如果是,操作数1的值应当为当前PC的值 新增 corrected by rainman
47+
val ctrlLUI = WireDefault(false.B) //判断是否为LUI指令,如果是,操作数1的值应当为0 新增
4648
val ctrlOP = WireDefault(0.U(OP_TYPES_WIDTH.W))
4749
val ctrlSigned = WireDefault(true.B)
4850
val ctrlLSType = WireDefault(LS_W)
4951

5052
// 根据opcode对控制信号赋值
5153
switch (io.inst(6, 2)) {
5254
// U: LUI, AUIPC
53-
is ("b01101".U, "b00101".U) {
55+
/*is ("b01101".U, "b00101".U) {
5456
ctrlALUSrc := true.B
5557
ctrlOP := OP_ADD
5658
imm := imm_u
59+
}*/
60+
//新增 corrected
61+
//U: LUI
62+
is ("b01101".U){
63+
ctrlALUSrc := true.B
64+
ctrlOP := OP_ADD
65+
ctrlLUI :=true.B
66+
imm := imm_u
67+
}
68+
//U: AUIPC
69+
is ("b00101".U){
70+
ctrlALUSrc := true.B
71+
ctrlOP := OP_ADD
72+
ctrlAUIPC := true.B
73+
//ctrlJAL := true.B
74+
imm := imm_u
5775
}
76+
5877
// J: JAL
5978
is ("b11011".U) {
6079
ctrlALUSrc := true.B
@@ -238,6 +257,8 @@ class Decoder extends Module {
238257
io.bundleCtrl.ctrlALUSrc := ctrlALUSrc
239258
io.bundleCtrl.ctrlBranch := ctrlBranch
240259
io.bundleCtrl.ctrlJAL := ctrlJAL
260+
io.bundleCtrl.ctrlLUI := ctrlLUI //新增 corrected
261+
io.bundleCtrl.ctrlAUIPC := ctrlAUIPC //新增 corrected
241262
io.bundleCtrl.ctrlJump := ctrlJump
242263
io.bundleCtrl.ctrlLoad := ctrlLoad
243264
io.bundleCtrl.ctrlOP := ctrlOP
@@ -246,4 +267,4 @@ class Decoder extends Module {
246267
io.bundleCtrl.ctrlStore := ctrlStore
247268
io.bundleCtrl.ctrlLSType := ctrlLSType
248269
io.imm := imm
249-
}
270+
}

src/main/scala/utils/Bundles.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class BundleControl extends Bundle {
1414
val ctrlStore = Output(Bool())
1515
val ctrlALUSrc = Output(Bool())
1616
val ctrlJAL = Output(Bool())
17+
val ctrlLUI = Output(Bool()) //新增 corrected
18+
val ctrlAUIPC = Output(Bool()) //新增 corrected
1719
val ctrlOP = Output(UInt(OP_TYPES_WIDTH.W))
1820
val ctrlSigned = Output(Bool())
1921
val ctrlLSType = Output(UInt(LS_TYPE_WIDTH.W))
@@ -22,6 +24,8 @@ class BundleControl extends Bundle {
2224
class BundleAluControl extends Bundle {
2325
val ctrlALUSrc = Input(Bool())
2426
val ctrlJAL = Input(Bool())
27+
val ctrlLUI = Input(Bool()) //新增 corrected
28+
val ctrlAUIPC = Input(Bool()) //新增 corrected
2529
val ctrlOP = Input(UInt(OP_TYPES_WIDTH.W))
2630
val ctrlSigned = Input(Bool())
2731
val ctrlBranch = Input(Bool())
@@ -38,4 +42,4 @@ class BundleReg extends Bundle {
3842
val rs1 = Output(UInt(REG_NUMS_LOG.W))
3943
val rs2 = Output(UInt(REG_NUMS_LOG.W))
4044
val rd = Output(UInt(REG_NUMS_LOG.W))
41-
}
45+
}

0 commit comments

Comments
 (0)