blob: bbdb5ec2444a60bffc900ac9afd8fa08b031e83d [file] [log] [blame]
// SPDX-FileCopyrightText: 2020 Muhammad Hadir Khan
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0
package core
import chisel3._
class InstructionTypeDecode extends Module {
val io = IO(new Bundle {
// val enable_M_extension = Input(UInt(1.W))
val func3 = Input(UInt(3.W))
val func7 = Input(UInt(7.W))
val opcode = Input(UInt(7.W))
val r_type = Output(UInt(1.W))
val load_type = Output(UInt(1.W))
val s_type = Output(UInt(1.W))
val sb_type = Output(UInt(1.W))
val i_type = Output(UInt(1.W))
val jalr_type = Output(UInt(1.W))
val jal_type = Output(UInt(1.W))
val lui_type = Output(UInt(1.W))
val Auipc = Output(UInt(1.W))
val multiply = Output(UInt(1.W))
val csr_imm_type = Output(UInt(1.W))
val csr_type = Output(UInt(1.W))
val csr_op = Output(UInt(2.W))
})
default_signals()
when(io.opcode === "b0110011".U )
{
when(io.func7 === "b000001".U)
{
io.multiply := 1.U
io.r_type := 0.U
}
.otherwise
{
io.r_type := 1.U
}
}
.elsewhen(io.opcode === "b0000011".U) {
io.load_type := 1.U
} .elsewhen(io.opcode === "b0100011".U) {
io.s_type := 1.U
} .elsewhen(io.opcode === "b1100011".U) {
io.sb_type := 1.U
} .elsewhen(io.opcode === "b0010011".U) {
io.i_type := 1.U
} .elsewhen(io.opcode === "b1100111".U) {
io.jalr_type := 1.U
} .elsewhen(io.opcode === "b1101111".U) {
io.jal_type := 1.U
} .elsewhen(io.opcode === "b0110111".U) {
io.lui_type := 1.U
}
.elsewhen(io.opcode === "b0010111".U) {
io.Auipc := 1.U
} .elsewhen(io.opcode === "b1110011".U && io.func3 === "b001".U) {
io.csr_type := 1.U
io.csr_op := "b01".U
} .elsewhen(io.opcode === "b1110011".U && io.func3 === "b010".U) {
io.csr_type := 1.U
io.csr_op := "b10".U
} .elsewhen(io.opcode === "b1110011".U && io.func3 === "b011".U) {
io.csr_type := 1.U
io.csr_op := "b11".U
} .elsewhen(io.opcode === "b1110011".U && io.func3 === "b101".U) {
io.csr_imm_type := 1.U
io.csr_op := "b01".U
} .elsewhen(io.opcode === "b1110011".U && io.func3 === "b110".U) {
io.csr_imm_type := 1.U
io.csr_op := "b10".U
} .elsewhen(io.opcode === "b1110011".U && io.func3 === "b111".U) {
io.csr_imm_type := 1.U
io.csr_op := "b11".U
}
.otherwise
{
default_signals()
}
def default_signals(): Unit =
{
io.r_type := 0.U
io.load_type := 0.U
io.s_type := 0.U
io.sb_type := 0.U
io.i_type := 0.U
io.jalr_type := 0.U
io.jal_type := 0.U
io.lui_type := 0.U
io.Auipc := 0.U
io.multiply := 0.U
io.csr_type := 0.U
io.csr_imm_type := 0.U
io.csr_op := 0.U
}
}