@@ -3,80 +3,185 @@ package treecorel2
33import chisel3 ._
44import chisel3 .util ._
55
6- object ISADecoder {}
6+ import treecorel2 . common . InstConfig
77
8- class ISADecoder extends Module {
8+ object ISADecoder {
9+ // according to the The RISC-V Instruction Set Manual Volume I: Unprivileged ISA
10+ // Document Version: 20191213
11+ // DESC page [15-25] ABI page[130-131]
12+
13+ /* Integer Register-Immediate Instructions */
14+ // I type inst
15+ def ADDI = BitPat (" b?????????????????000?????0010011" )
16+ def ADDIW = BitPat (" b?????????????????000?????0011011" )
17+ def SLTI = BitPat (" b?????????????????010?????0010011" )
18+ def SLTIU = BitPat (" b?????????????????011?????0010011" )
19+
20+ def ANDI = BitPat (" b?????????????????111?????0010011" )
21+ def ORI = BitPat (" b?????????????????110?????0010011" )
22+ def XORI = BitPat (" b?????????????????100?????0010011" )
23+
24+ // special I type inst
25+ def SLLI = BitPat (" b000000???????????001?????0010011" )
26+ def SLLIW = BitPat (" b0000000??????????001?????0011011" )
27+ def SRLI = BitPat (" b000000???????????101?????0010011" )
28+ def SRLIW = BitPat (" b0000000??????????101?????0011011" )
29+ def SRAI = BitPat (" b010000???????????101?????0010011" )
30+ def SRAIW = BitPat (" b0100000??????????101?????0011011" )
31+ // U type inst
32+ // LUI - rd = {imm, 12b'0}
33+ def LUI = BitPat (" b?????????????????????????0110111" )
34+ // AUIPC - rd = PC + {imm, 12b'0}
35+ def AUIPC = BitPat (" b?????????????????????????0010111" )
36+
37+ /* Integer Register-Register Operations */
38+ // R type inst
39+ def ADD = BitPat (" b0000000??????????000?????0110011" )
40+ def ADDW = BitPat (" b0000000??????????000?????0111011" )
41+ def SLT = BitPat (" b0000000??????????010?????0110011" )
42+ def SLTU = BitPat (" b0000000??????????011?????0110011" )
43+
44+ def AND = BitPat (" b0000000??????????111?????0110011" )
45+ def OR = BitPat (" b0000000??????????110?????0110011" )
46+ def XOR = BitPat (" b0000000??????????100?????0110011" )
47+
48+ def SLL = BitPat (" b0000000??????????001?????0110011" )
49+ def SLLW = BitPat (" b0000000??????????001?????0111011" )
50+ def SRL = BitPat (" b0000000??????????101?????0110011" )
51+ def SRLW = BitPat (" b0000000??????????101?????0111011" )
52+
53+ def SUB = BitPat (" b0100000??????????000?????0110011" )
54+ def SUBW = BitPat (" b0100000??????????000?????0111011" )
55+ def SRA = BitPat (" b0100000??????????101?????0110011" )
56+ def SRAW = BitPat (" b0100000??????????101?????0111011" )
57+
58+ // NOP - ADDI x0, 0x00(x0)
59+ def NOP = BitPat (" b00000000000000000000000000010011" )
60+
61+ /* Control Transfer Instructions */
62+ // J type inst
63+ def JAL = BitPat (" b?????????????????????????1101111" )
64+ // I type inst
65+ def JALR = BitPat (" b?????????????????000?????1100111" )
66+ // B type inst
67+ def BEQ = BitPat (" b?????????????????000?????1100011" )
68+ def BNE = BitPat (" b?????????????????001?????1100011" )
69+ def BLT = BitPat (" b?????????????????100?????1100011" )
70+ def BLTU = BitPat (" b?????????????????110?????1100011" )
71+ def BGE = BitPat (" b?????????????????101?????1100011" )
72+ def BGEU = BitPat (" b?????????????????111?????1100011" )
73+
74+ /* Load and Store Instructions */
75+ // I type inst
76+ def LB = BitPat (" b?????????????????000?????0000011" )
77+ def LBU = BitPat (" b?????????????????100?????0000011" )
78+ def LH = BitPat (" b?????????????????001?????0000011" )
79+ def LHU = BitPat (" b?????????????????101?????0000011" )
80+ def LW = BitPat (" b?????????????????010?????0000011" )
81+ def LWU = BitPat (" b?????????????????110?????0000011" )
82+ def LD = BitPat (" b?????????????????011?????0000011" )
83+
84+ // S type inst
85+ def SB = BitPat (" b?????????????????000?????0100011" )
86+ def SH = BitPat (" b?????????????????001?????0100011" )
87+ def SW = BitPat (" b?????????????????010?????0100011" )
88+ def SD = BitPat (" b?????????????????011?????0100011" )
89+
90+ // CSR inst
91+ def CSRRW = BitPat (" b?????????????????001?????1110011" )
92+ def CSRRS = BitPat (" b?????????????????010?????1110011" )
93+ def CSRRC = BitPat (" b?????????????????011?????1110011" )
94+ def CSRRWI = BitPat (" b?????????????????101?????1110011" )
95+ def CSRRSI = BitPat (" b?????????????????110?????1110011" )
96+ def CSRRCI = BitPat (" b?????????????????111?????1110011" )
97+
98+ // system inst
99+ def ECALL = BitPat (" b00000000000000000000000001110011" )
100+ def EBREAK = BitPat (" b00000000000100000000000001110011" )
101+ def URET = BitPat (" b00000000001000000000000001110011" )
102+ def SRET = BitPat (" b00010000001000000000000001110011" )
103+ def MRET = BitPat (" b00110000001000000000000001110011" )
104+ def WFI = BitPat (" b00010000010100000000000001110011" )
105+ def SFENCE_VMA = BitPat (" b0001001??????????000000001110011" )
106+ def FENCE = BitPat (" b0000????????00000000000000001111" )
107+ def FENCE_I = BitPat (" b00000000000000000001000000001111" )
108+ // custom inst such as 0x7B
109+ def CUST = BitPat (" b0000000??????????000?????1111011" )
110+ }
111+
112+ class ISADecoder extends Module with InstConfig {
9113 val io = IO (new Bundle {
10- val inst = Input (UInt (32 .W ))
114+ val inst = Input (UInt (InstLen .W ))
11115 val isa = Output (new ISAIO )
12116 val imm = Output (new IMMIO )
13117 val csr = Output (new Bool ())
14118 val wen = Output (new Bool ())
15119 })
16120
17- io.isa.SLLI := (io.inst === BitPat (" b000000??????_?????_001_?????_0010011" ))
18- io.isa.SLLIW := (io.inst === BitPat (" b000000??????_?????_001_?????_0011011" ))
19- io.isa.SRLI := (io.inst === BitPat (" b000000??????_?????_101_?????_0010011" ))
20- io.isa.SRLIW := (io.inst === BitPat (" b000000??????_?????_101_?????_0011011" ))
21- io.isa.SRAI := (io.inst === BitPat (" b010000??????_?????_101_?????_0010011" ))
22- io.isa.SRAIW := (io.inst === BitPat (" b010000??????_?????_101_?????_0011011" ))
23- io.isa.ADDI := (io.inst === BitPat (" b????????????_?????_000_?????_0010011" ))
24- io.isa.ADDIW := (io.inst === BitPat (" b????????????_?????_000_?????_0011011" ))
25- io.isa.XORI := (io.inst === BitPat (" b????????????_?????_100_?????_0010011" ))
26- io.isa.ORI := (io.inst === BitPat (" b????????????_?????_110_?????_0010011" ))
27- io.isa.ANDI := (io.inst === BitPat (" b????????????_?????_111_?????_0010011" ))
28- io.isa.SLTI := (io.inst === BitPat (" b????????????_?????_010_?????_0010011" ))
29- io.isa.SLTIU := (io.inst === BitPat (" b????????????_?????_011_?????_0010011" ))
30- io.isa.JALR := (io.inst === BitPat (" b????????????_?????_000_?????_1100111" ))
31- io.isa.FENCE := (io.inst === BitPat (" b0000????????_00000_000_00000_0001111" ))
32- io.isa.FENCE_I := (io.inst === BitPat (" b000000000000_00000_001_00000_0001111" ))
33- io.isa.ECALL := (io.inst === BitPat (" b000000000000_00000_000_00000_1110011" ))
34- io.isa.EBREAK := (io.inst === BitPat (" b000000000001_00000_000_00000_1110011" ))
35- io.isa.CSRRW := (io.inst === BitPat (" b????????????_?????_001_?????_1110011" ))
36- io.isa.CSRRWI := (io.inst === BitPat (" b????????????_?????_101_?????_1110011" ))
37- io.isa.CSRRS := (io.inst === BitPat (" b????????????_?????_010_?????_1110011" ))
38- io.isa.CSRRSI := (io.inst === BitPat (" b????????????_?????_110_?????_1110011" ))
39- io.isa.CSRRC := (io.inst === BitPat (" b????????????_?????_011_?????_1110011" ))
40- io.isa.CSRRCI := (io.inst === BitPat (" b????????????_?????_111_?????_1110011" ))
41- io.isa.LD := (io.inst === BitPat (" b????????????_?????_011_?????_0000011" ))
42- io.isa.LW := (io.inst === BitPat (" b????????????_?????_010_?????_0000011" ))
43- io.isa.LWU := (io.inst === BitPat (" b????????????_?????_110_?????_0000011" ))
44- io.isa.LH := (io.inst === BitPat (" b????????????_?????_001_?????_0000011" ))
45- io.isa.LHU := (io.inst === BitPat (" b????????????_?????_101_?????_0000011" ))
46- io.isa.LB := (io.inst === BitPat (" b????????????_?????_000_?????_0000011" ))
47- io.isa.LBU := (io.inst === BitPat (" b????????????_?????_100_?????_0000011" ))
48- io.isa.SLL := (io.inst === BitPat (" b000000??????_?????_001_?????_0110011" ))
49- io.isa.SLLW := (io.inst === BitPat (" b000000??????_?????_001_?????_0111011" ))
50- io.isa.SRL := (io.inst === BitPat (" b000000??????_?????_101_?????_0110011" ))
51- io.isa.SRLW := (io.inst === BitPat (" b000000??????_?????_101_?????_0111011" ))
52- io.isa.SRA := (io.inst === BitPat (" b010000??????_?????_101_?????_0110011" ))
53- io.isa.SRAW := (io.inst === BitPat (" b010000??????_?????_101_?????_0111011" ))
54- io.isa.ADD := (io.inst === BitPat (" b000000??????_?????_000_?????_0110011" ))
55- io.isa.ADDW := (io.inst === BitPat (" b000000??????_?????_000_?????_0111011" ))
56- io.isa.SUB := (io.inst === BitPat (" b010000??????_?????_000_?????_0110011" ))
57- io.isa.SUBW := (io.inst === BitPat (" b010000??????_?????_000_?????_0111011" ))
58- io.isa.XOR := (io.inst === BitPat (" b000000??????_?????_100_?????_0110011" ))
59- io.isa.OR := (io.inst === BitPat (" b000000??????_?????_110_?????_0110011" ))
60- io.isa.AND := (io.inst === BitPat (" b000000??????_?????_111_?????_0110011" ))
61- io.isa.SLT := (io.inst === BitPat (" b000000??????_?????_010_?????_0110011" ))
62- io.isa.SLTU := (io.inst === BitPat (" b000000??????_?????_011_?????_0110011" ))
63- io.isa.MRET := (io.inst === BitPat (" b0011000_00010_00000_000_00000_1110011" ))
64- io.isa.SRET := (io.inst === BitPat (" b0001000_00010_00000_000_00000_1110011" ))
65- io.isa.WFI := (io.inst === BitPat (" b0001000_00101_00000_000_00000_1110011" ))
66- io.isa.SFENCE_VMA := (io.inst === BitPat (" b0001001_?????_?????_000_00000_1110011" ))
67- io.isa.BEQ := (io.inst === BitPat (" b???????_?????_?????_000_?????_1100011" ))
68- io.isa.BNE := (io.inst === BitPat (" b???????_?????_?????_001_?????_1100011" ))
69- io.isa.BLT := (io.inst === BitPat (" b???????_?????_?????_100_?????_1100011" ))
70- io.isa.BGE := (io.inst === BitPat (" b???????_?????_?????_101_?????_1100011" ))
71- io.isa.BLTU := (io.inst === BitPat (" b???????_?????_?????_110_?????_1100011" ))
72- io.isa.BGEU := (io.inst === BitPat (" b???????_?????_?????_111_?????_1100011" ))
73- io.isa.SD := (io.inst === BitPat (" b???????_?????_?????_011_?????_0100011" ))
74- io.isa.SW := (io.inst === BitPat (" b???????_?????_?????_010_?????_0100011" ))
75- io.isa.SH := (io.inst === BitPat (" b???????_?????_?????_001_?????_0100011" ))
76- io.isa.SB := (io.inst === BitPat (" b???????_?????_?????_000_?????_0100011" ))
77- io.isa.LUI := (io.inst === BitPat (" b?????????????????????_?????_0110111" ))
78- io.isa.AUIPC := (io.inst === BitPat (" b?????????????????????_?????_0010111" ))
79- io.isa.JAL := (io.inst === BitPat (" b?????????????????????_?????_1101111" ))
121+ io.isa.SLLI := (io.inst === ISADecoder .SLLI )
122+ io.isa.SLLIW := (io.inst === ISADecoder .SLLIW )
123+ io.isa.SRLI := (io.inst === ISADecoder .SRLI )
124+ io.isa.SRLIW := (io.inst === ISADecoder .SRLIW )
125+ io.isa.SRAI := (io.inst === ISADecoder .SRAI )
126+ io.isa.SRAIW := (io.inst === ISADecoder .SRAIW )
127+ io.isa.ADDI := (io.inst === ISADecoder .ADDI )
128+ io.isa.ADDIW := (io.inst === ISADecoder .ADDIW )
129+ io.isa.XORI := (io.inst === ISADecoder .XORI )
130+ io.isa.ORI := (io.inst === ISADecoder .ORI )
131+ io.isa.ANDI := (io.inst === ISADecoder .ANDI )
132+ io.isa.SLTI := (io.inst === ISADecoder .SLTI )
133+ io.isa.SLTIU := (io.inst === ISADecoder .SLTIU )
134+ io.isa.JALR := (io.inst === ISADecoder .JALR )
135+ io.isa.FENCE := (io.inst === ISADecoder .FENCE )
136+ io.isa.FENCE_I := (io.inst === ISADecoder .FENCE_I )
137+ io.isa.ECALL := (io.inst === ISADecoder .ECALL )
138+ io.isa.EBREAK := (io.inst === ISADecoder .EBREAK )
139+ io.isa.CSRRW := (io.inst === ISADecoder .CSRRW )
140+ io.isa.CSRRWI := (io.inst === ISADecoder .CSRRWI )
141+ io.isa.CSRRS := (io.inst === ISADecoder .CSRRS )
142+ io.isa.CSRRSI := (io.inst === ISADecoder .CSRRSI )
143+ io.isa.CSRRC := (io.inst === ISADecoder .CSRRC )
144+ io.isa.CSRRCI := (io.inst === ISADecoder .CSRRCI )
145+ io.isa.LD := (io.inst === ISADecoder .LD )
146+ io.isa.LW := (io.inst === ISADecoder .LW )
147+ io.isa.LWU := (io.inst === ISADecoder .LWU )
148+ io.isa.LH := (io.inst === ISADecoder .LH )
149+ io.isa.LHU := (io.inst === ISADecoder .LHU )
150+ io.isa.LB := (io.inst === ISADecoder .LB )
151+ io.isa.LBU := (io.inst === ISADecoder .LBU )
152+ io.isa.SLL := (io.inst === ISADecoder .SLL )
153+ io.isa.SLLW := (io.inst === ISADecoder .SLLW )
154+ io.isa.SRL := (io.inst === ISADecoder .SRL )
155+ io.isa.SRLW := (io.inst === ISADecoder .SRLW )
156+ io.isa.SRA := (io.inst === ISADecoder .SRA )
157+ io.isa.SRAW := (io.inst === ISADecoder .SRAW )
158+ io.isa.ADD := (io.inst === ISADecoder .ADD )
159+ io.isa.ADDW := (io.inst === ISADecoder .ADDW )
160+ io.isa.SUB := (io.inst === ISADecoder .SUB )
161+ io.isa.SUBW := (io.inst === ISADecoder .SUBW )
162+ io.isa.XOR := (io.inst === ISADecoder .XOR )
163+ io.isa.OR := (io.inst === ISADecoder .OR )
164+ io.isa.AND := (io.inst === ISADecoder .AND )
165+ io.isa.SLT := (io.inst === ISADecoder .SLT )
166+ io.isa.SLTU := (io.inst === ISADecoder .SLTU )
167+ io.isa.MRET := (io.inst === ISADecoder .MRET )
168+ io.isa.SRET := (io.inst === ISADecoder .SRET )
169+ io.isa.WFI := (io.inst === ISADecoder .WFI )
170+ io.isa.SFENCE_VMA := (io.inst === ISADecoder .SFENCE_VMA )
171+ io.isa.BEQ := (io.inst === ISADecoder .BEQ )
172+ io.isa.BNE := (io.inst === ISADecoder .BNE )
173+ io.isa.BLT := (io.inst === ISADecoder .BLT )
174+ io.isa.BGE := (io.inst === ISADecoder .BGE )
175+ io.isa.BLTU := (io.inst === ISADecoder .BLTU )
176+ io.isa.BGEU := (io.inst === ISADecoder .BGEU )
177+ io.isa.SD := (io.inst === ISADecoder .SD )
178+ io.isa.SW := (io.inst === ISADecoder .SW )
179+ io.isa.SH := (io.inst === ISADecoder .SH )
180+ io.isa.SB := (io.inst === ISADecoder .SB )
181+ io.isa.LUI := (io.inst === ISADecoder .LUI )
182+ io.isa.AUIPC := (io.inst === ISADecoder .AUIPC )
183+ io.isa.JAL := (io.inst === ISADecoder .JAL )
184+
80185 io.isa.MUL := (io.inst === BitPat (" b0000001_?????_?????_000_?????_0110011" ))
81186 io.isa.MULH := (io.inst === BitPat (" b0000001_?????_?????_001_?????_0110011" ))
82187 io.isa.MULHSU := (io.inst === BitPat (" b0000001_?????_?????_010_?????_0110011" ))
0 commit comments