general.sv 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package risc8_pkg;
  2. localparam word_size = 8;
  3. localparam reg_size = 4;
  4. localparam reg_addr_size = $clog2(reg_size);
  5. typedef logic [word_size-1:0] word;
  6. typedef logic [reg_addr_size-1:0] reg_addr;
  7. typedef enum logic [7:0] {
  8. // [ xxxx xx xx ] => [ inst rd rs ]
  9. // mp: Memory page
  10. // cp: Co-processor, 0x00 = RAM, 0x01 = ROM, 0x02 = FPU, 0x03 = GPIO
  11. MOVE =8'b0000_????, // &rd = &rs
  12. CPY0 =8'b0000_0000, // &rd = imm
  13. CPY1 =8'b0000_0101, // &rd = imm
  14. CPY2 =8'b0000_1010, // &rd = imm
  15. CPY3 =8'b0000_1111, // &rd = imm
  16. ADD =8'b0001_????, // &rd = &rd + &rs
  17. SUB =8'b0010_????, // &rd = &rd - &rs
  18. AND =8'b0011_????, // &rd = &rd & &rsgt
  19. OR =8'b0100_????, // &rd = &rd | &rs
  20. XOR =8'b0101_????, // &rd = &rd ^ &rs
  21. MUL =8'b0110_????, // {&ah, &rd} = &rd * &rs
  22. DIV =8'b0111_????, // &rd = &rd / &rs, &ah = &rd % &rs
  23. BR =8'b1000_????, // Conditional branch
  24. SLL =8'b1001_??00, // i9-0 shift left logical
  25. SRL =8'b1001_??01, // i9-1 shift right logical
  26. SRA =8'b1001_??10, // i9-2 shift right arithmetic
  27. SRAS =8'b1001_??11, // i9-3 shift rigth arithmetic signed
  28. LWHI =8'b1010_??00, // i10-0
  29. SWHI =8'b1010_??01, // i10-1
  30. LWLO =8'b1010_??10, // i10-2
  31. SWLO =8'b1010_??11, // i10-3
  32. INC =8'b1011_??00, // i11-0
  33. DEC =8'b1011_??01, // i11-1
  34. GETAH=8'b1011_??10, // i11-2
  35. GETIF=8'b1011_??11, // i11-3
  36. PUSH =8'b1100_??00, // i12-0
  37. POP =8'b1100_??01, // i12-1
  38. COM =8'b1100_??10, // i12-2
  39. CALL =8'b1111_0000, // i15-0
  40. RET =8'b1111_0001, // i15-1
  41. JUMP =8'b1111_0010, // i15-2
  42. RETI =8'b1111_0011, // i15-3
  43. CLC =8'b1111_0100, // i15-4
  44. SETC =8'b1111_0101, // i15-5
  45. CLS =8'b1111_0110, // i15-6
  46. SETS =8'b1111_0111, // i15-7
  47. SSETS=8'b1111_1000, // i15-8
  48. CLN =8'b1111_1001, // i15-9
  49. SETN =8'b1111_1010, // i15-10
  50. SSETN=8'b1111_1011, // i15-11
  51. RJUMP=8'b1111_1100, // i15-12
  52. RBWI =8'b1111_1101, // i15-13 Replace ALU src B with immediate
  53. i254 =8'b1111_1110, // i15-14
  54. i255 =8'b1111_1111 // i15-15
  55. } e_instr;
  56. typedef enum logic [1:0] {
  57. SB_NONE= 2'bxx,
  58. SB_REG = 2'b00,
  59. SB_0 = 2'b01,
  60. SB_1 = 2'b10,
  61. SB_IMM = 2'b11
  62. } e_selb;
  63. typedef enum logic [2:0] {
  64. SR_NONE= 3'bxxx,
  65. SR_MEML= 3'b001,
  66. SR_MEMH= 3'b010,
  67. SR_ALUL= 3'b011,
  68. SR_ALUH= 3'b100,
  69. SR_IMM = 3'b101,
  70. SR_COM = 3'b110,
  71. SR_INTR= 3'b111
  72. } e_selr;
  73. typedef enum logic [1:0] {
  74. REG0 = 2'b00,
  75. REG1 = 2'b01,
  76. REG2 = 2'b10,
  77. REG3 = 2'b11
  78. } e_reg_addr;
  79. endpackage
  80. interface risc8_cdi; // Control Datapath interface
  81. import risc8_pkg::*;
  82. import alu_pkg::*;
  83. // ALU
  84. e_alu_op alu_op;
  85. logic sign, alu_not;
  86. e_selb selb;
  87. logic [2:0] alu_comp;
  88. // Register
  89. reg_addr a1, a2, a3;
  90. logic rw_en, mem_h;
  91. e_selr selr;
  92. logic [1:0] isize; // instruction size between 1 and 4
  93. modport datapath(
  94. input alu_op, selb, sign, alu_not,
  95. output alu_comp,
  96. input a1, a2, a3, rw_en, selr, mem_h, isize
  97. );
  98. modport control(
  99. output alu_op, selb, sign, alu_not,
  100. input alu_comp,
  101. output a1, a2, a3, rw_en, selr, mem_h, isize
  102. );
  103. endinterface
  104. package risc8x_pkg;
  105. localparam word_size = 8;
  106. localparam reg_size = 4;
  107. localparam reg_addr_size = $clog2(reg_size);
  108. typedef logic [word_size-1:0] word;
  109. typedef logic [reg_addr_size-1:0] regAddr;
  110. typedef enum logic [1:0] {
  111. ra = 2'b00,
  112. rb = 2'b01,
  113. rc = 2'b10,
  114. re = 2'b11
  115. } e_reg;
  116. typedef enum logic [5:0] {
  117. // [ xxxxxx xx xx xxxxxx ] => [ inst rd rs arg ]
  118. // [ xxxxxx xx xxxxxxx ] => [ inst rd imm ]
  119. // Arithmetic
  120. ADD = 6'b0000_00, // 0
  121. ADDI = 6'b0000_01, // 1
  122. ADDU = 6'b0000_10, // 2
  123. ADDUI= 6'b0000_11, // 3
  124. SUB = 6'b0001_00, // 4
  125. SUBI = 6'b0001_01, // 5
  126. SUBU = 6'b0001_10, // 6
  127. SUBUI= 6'b0001_11, // 7
  128. INC = 6'b0010_00, // 8
  129. DEC = 6'b0010_01, // 9
  130. MUL = 6'b0010_10, // 10
  131. MULI = 6'b0010_11, // 11
  132. DIV = 6'b0011_00, // 12
  133. DIVI = 6'b0011_01, // 13
  134. MOD = 6'b0011_10, // 14
  135. MODI = 6'b0011_11, // 15
  136. // Logic
  137. AND = 6'b0100_00, // 16
  138. ANDI = 6'b0100_01, // 17
  139. OR = 6'b0100_10, // 18
  140. ORI = 6'b0100_11, // 19
  141. XOR = 6'b0101_00, // 20
  142. XORI = 6'b0101_01, // 21
  143. SLL = 6'b0101_10, // 22
  144. _I23 = 6'b0101_11, // 23
  145. SRL = 6'b0110_00, // 24
  146. _I25 = 6'b0110_01, // 25
  147. SRA = 6'b0110_10, // 26
  148. _I26 = 6'b0110_11, // 27
  149. // Branching
  150. BGT = 6'b0111_00, // 28
  151. BGE = 6'b0111_01, // 29
  152. BEQ = 6'b0111_10, // 30
  153. BLT = 6'b0111_11, // 31
  154. BLE = 6'b1000_00, // 32
  155. BNE = 6'b1000_01, // 33
  156. BGTZ = 6'b1000_10, // 34
  157. BGEZ = 6'b1000_11, // 35
  158. BEQZ = 6'b1001_00, // 36
  159. BLTZ = 6'b1001_01, // 37
  160. BLEZ = 6'b1001_10, // 38
  161. BNEZ = 6'b1001_11, // 39
  162. BGTI = 6'b1010_00, // 40
  163. BGEI = 6'b1010_01, // 41
  164. BEQI = 6'b1010_10, // 42
  165. BLTI = 6'b1010_11, // 43
  166. BLEI = 6'b1011_00, // 44
  167. BNEI = 6'b1011_01, // 45
  168. JMP = 6'b1011_10, // 46
  169. RJMP = 6'b1011_11, // 47
  170. // Data move
  171. SWLO = 6'b1100_00, // 48
  172. SWHI = 6'b1100_01, // 49
  173. LWLO = 6'b1100_10, // 50
  174. LWHI = 6'b1100_11, // 51
  175. PUSH = 6'b1101_00, // 52
  176. POP = 6'b1101_01, // 53
  177. CALL = 6'b1101_10, // 54
  178. RET = 6'b1101_11, // 55
  179. RETI = 6'b1110_00, // 56
  180. MOV = 6'b1110_01, // 57
  181. COM = 6'b1110_10, // 58
  182. COMI = 6'b1110_11, // 59
  183. IFLAG= 6'b1111_00, // 60
  184. // Special
  185. HALT = 6'b1111_01, // 61
  186. _I62 = 6'b1111_10, // 62
  187. _I63 = 6'b1111_11 // 63
  188. } e_instr;
  189. endpackage