@@ -14,16 +14,16 @@ module FISC_Core(
1414 output reg ioack_n, /* 0: CPU acknowledges IO request. 1: CPU is either serving an IRQ or is simply executing instructions in normal mode */
1515 output reg wr_a, /* 0: CPU writes to memory. 1: CPU is currently executing an instruction (channel a) */
1616 output reg rd_a, /* 0: CPU reads from memory. 1: CPU is currently executing an instruction (channel a) */
17- output reg wr_b, /* 0: CPU writes to memory. 1: CPU is currently executing an instruction (channel b) */
18- output reg rd_b, /* 0: CPU reads from memory. 1: CPU is currently executing an instruction (channel b) */
17+ output wr_b, /* 0: CPU writes to memory. 1: CPU is currently executing an instruction (channel b) */
18+ output rd_b, /* 0: CPU reads from memory. 1: CPU is currently executing an instruction (channel b) */
1919
2020 input [`FISC_INTEGER_SZ - 1 : 0 ] din_bus_a, /* Data Input Bus (channel a) */
2121 output reg [`FISC_INTEGER_SZ - 1 : 0 ] dout_bus_a, /* Data Output Bus (channel a) */
2222 output reg [`FISC_ADDRESS_BOOT_SZ - 1 : 0 ] addr_bus_a, /* Address Bus (channel a) */
2323
2424 input [`FISC_INTEGER_SZ - 1 : 0 ] din_bus_b, /* Data Input Bus (channel b) */
25- output reg [`FISC_INTEGER_SZ - 1 : 0 ] dout_bus_b, /* Data Output Bus (channel b) */
26- output reg [`FISC_ADDRESS_BOOT_SZ - 1 : 0 ] addr_bus_b, /* Address Bus (channel b) */
25+ output [`FISC_INTEGER_SZ - 1 : 0 ] dout_bus_b, /* Data Output Bus (channel b) */
26+ output [`FISC_ADDRESS_BOOT_SZ - 1 : 0 ] addr_bus_b, /* Address Bus (channel b) */
2727
2828 /* Debug wires */
2929 output dbg_init,
@@ -98,58 +98,68 @@ module FISC_Core(
9898 .dbg3 (microcode_dbg3),
9999 .dbg4 (microcode_dbg4)
100100 );
101-
101+
102+ /* Microcode control assignments */
103+ wire mcu_first_op_src = microcode_ctrl[23 ];
104+ wire mcu_reg_wr = microcode_ctrl[22 ];
105+ wire [3 : 0 ] mcu_reg_special_wr = microcode_ctrl[21 : 18 ];
106+ wire [3 : 0 ] mcu_reg_special_rd = microcode_ctrl[17 : 14 ];
107+ wire [1 : 0 ] mcu_reg_din_src = microcode_ctrl[13 : 12 ];
108+ wire [1 : 0 ] mcu_alu_src = microcode_ctrl[11 : 10 ];
109+ wire [3 : 0 ] mcu_alu_f = microcode_ctrl[9 : 6 ];
110+ wire mcu_mem_wr_b = microcode_ctrl[5 ];
111+ wire mcu_mem_rd_b = microcode_ctrl[4 ];
112+ wire mcu_branch = microcode_ctrl[3 ];
113+ wire mcu_pc_rel = microcode_ctrl[2 ];
114+ wire mcu_set_flags = microcode_ctrl[1 ];
115+
102116 /* Registers instantiation and wires */
103- reg [5 : 0 ] rd_reg ;
117+ reg [5 : 0 ] rd_reg1 ;
104118 reg [5 : 0 ] wr_reg;
105- reg wr_fromreg ;
106- reg wr_fromimm ;
107- reg [`FISC_INTEGER_SZ - 1 : 0 ] din_reg ;
108- wire [`FISC_INTEGER_SZ - 1 : 0 ] dout_reg ;
109-
119+ reg reg_wr ;
120+ reg [ `FISC_INTEGER_SZ - 1 : 0 ] din ;
121+ wire [`FISC_INTEGER_SZ - 1 : 0 ] dout1 ;
122+ wire [`FISC_INTEGER_SZ - 1 : 0 ] dout2 ;
123+
110124 Registers registers (
111125 .clk (clk),
112- .rd_reg (rd_reg),
113- .wr_reg (wr_reg),
114- .wr_fromreg (wr_fromreg),
115- .wr_fromimm (wr_fromimm),
116- .din_reg (din_reg),
117- .dout_reg (dout_reg)
126+ .rd_reg1 (microcode_sos ? rd_reg1 : (mcu_reg_special_rd > 0 ? mcu_reg_special_rd + 31 : (mcu_first_op_src ? instruction[20 : 16 ] : instruction[9 : 5 ]))),
127+ .rd_reg2 (microcode_sos ? rd_reg2 : (mcu_mem_wr_b ? instruction[4 : 0 ] : (mcu_first_op_src ? instruction[9 : 5 ] : instruction[20 : 16 ]))),
128+ .wr_reg (microcode_sos ? wr_reg : (mcu_reg_special_wr > 0 ? mcu_reg_special_wr + 31 : instruction[4 : 0 ])),
129+ .wr (microcode_sos ? reg_wr : mcu_reg_wr),
130+ .din (microcode_sos ? din : (mcu_reg_din_src == 1 ? alu_y : (mcu_reg_din_src == 2 ? din_bus_b : 'hX ))),
131+ .dout1 (dout1),
132+ .dout2 (dout2),
133+ .set_flags (mcu_set_flags),
134+ .flag_negative (alu_flag_negative),
135+ .flag_zero (alu_flag_zero),
136+ .flag_overflow (alu_flag_overflow),
137+ .flag_carry (alu_flag_carry)
118138 );
119139
120- task write_register (input [5 : 0 ] regno, input [`FISC_INTEGER_SZ - 1 : 0 ] din );
140+ task write_register (input [5 : 0 ] regno, input [`FISC_INTEGER_SZ - 1 : 0 ] din_register );
121141 /* Write immediate value into register */
122142 wr_reg <= regno;
123- din_reg <= din;
124- wr_fromimm <= 1 ;
125- endtask
126-
127- task copy_register (input [5 : 0 ] regno_src, input [5 : 0 ] regno_dst);
128- /* Write a register's value into another register */
129- wr_reg <= regno_dst;
130- rd_reg <= regno_src;
131- wr_fromreg <= 1 ;
143+ din <= din_register;
144+ reg_wr <= 1 ;
132145 endtask
133146
134147 function [`FISC_INTEGER_SZ - 1 : 0 ] read_register (input [5 : 0 ] regno);
135- rd_reg = regno;
136- return dout_reg ;
148+ rd_reg1 = regno;
149+ return dout1 ;
137150 endfunction
138151
139152 /* ALU instantiation and wires */
140- wire [`FISC_INTEGER_SZ - 1 : 0 ] alu_opA;
141- wire [`FISC_INTEGER_SZ - 1 : 0 ] alu_opB;
142- wire [`ALU_F_SZ - 1 : 0 ] alu_f;
143153 wire [`FISC_INTEGER_SZ - 1 : 0 ] alu_y;
144154 wire alu_flag_negative;
145155 wire alu_flag_zero;
146156 wire alu_flag_overflow;
147157 wire alu_flag_carry;
148158
149159 ALU alu (
150- .opA (alu_opA ),
151- .opB (alu_opB ),
152- .f (alu_f ),
160+ .opA (dout1 ),
161+ .opB (mcu_alu_src == 0 ? instruction[ 21 : 10 ] : (mcu_alu_src == 1 ? dout2 : (mcu_alu_src == 2 ? din_bus_a : 'hX )) ),
162+ .f (mcu_alu_f ),
153163 .y (alu_y),
154164 .flag_negative (alu_flag_negative),
155165 .flag_zero (alu_flag_zero),
@@ -158,43 +168,28 @@ module FISC_Core(
158168 );
159169
160170 /* Main memory controls */
161- task write_memory (logic channel, input [`FISC_ADDRESS_BOOT_SZ - 1 : 0 ] address, input [`FISC_INTEGER_SZ - 1 : 0 ] din);
162- if (! channel) begin
163- addr_bus_a <= address;
164- dout_bus_a <= din;
165- wr_a <= 1 ;
166- end else begin
167- addr_bus_b <= address;
168- dout_bus_b <= din;
169- wr_b <= 1 ;
170- end
171- endtask
171+ assign dout_bus_b = dout2;
172+ assign addr_bus_b = alu_y[10 : 0 ];
173+ assign wr_b = mcu_mem_wr_b;
174+ assign rd_b = mcu_mem_rd_b;
172175
173- task enable_read_memory (logic channel, input [`FISC_ADDRESS_BOOT_SZ - 1 : 0 ] address);
174- if (! channel) begin
176+ task enable_read_memory (input [`FISC_ADDRESS_BOOT_SZ - 1 : 0 ] address);
175177 addr_bus_a <= address;
176178 rd_a <= 1 ;
177- end else begin
178- addr_bus_b <= address;
179- rd_b <= 1 ;
180- end
181179 endtask
182180
183- function [`FISC_INTEGER_SZ - 1 : 0 ] read_memory ( logic channel) ;
184- return ! channel ? din_bus_a : din_bus_b ;
181+ function [`FISC_INTEGER_SZ - 1 : 0 ] read_memory ;
182+ return din_bus_a;
185183 endfunction
186184
187185 task reset_control_wires ;
188186 /* Memory controls */
189187 wr_a = 0 ;
190- wr_b = 0 ;
191188 rd_a = 0 ;
192- rd_b = 0 ;
193189
194190 /* Register controls */
195191 wr_reg = 0 ;
196- wr_fromimm = 0 ;
197- wr_fromreg = 0 ;
192+ reg_wr = 0 ;
198193
199194 /* Debug UART */
200195 debug_uart_stop ();
@@ -230,7 +225,7 @@ module FISC_Core(
230225 logic [`FISC_INTEGER_SZ - 1 : 0 ] current_pc = read_register (32 );
231226
232227 /* Fetch memory block by first enabling read and setting the address */
233- enable_read_memory (0 , ! current_pc ? current_pc : current_pc / 8 );
228+ enable_read_memory (! current_pc ? current_pc : current_pc / 8 );
234229
235230 cpu_state <= ST_FETCH2_INSTRUCTION ;
236231 endtask
@@ -240,7 +235,7 @@ module FISC_Core(
240235 instruction from the local memory block */
241236
242237 /* Now we can latch the memory block */
243- memory_block = read_memory (0 );
238+ memory_block = read_memory ();
244239
245240 /* Grab instruction from fetched memory block */
246241 if (fetch_word_tophalf == 0 ) begin
0 commit comments