@@ -14,7 +14,11 @@ class Thread extends Module {
1414 val program_pointer = Output (UInt (8 .W ));
1515 val end_of_program = Output (Bool ());
1616 val idle = Output (Bool ());
17- val debug_output = Output (UInt (8 .W ));
17+
18+ val read_requested = Output (Bool ());
19+ val read_address = Output (UInt (16 .W ));
20+ val read_ready = Input (Bool ());
21+ val read_data = Input (UInt (16 .W ));
1822 })
1923
2024 val program_pointer = Module (new ProgramPointer ())
@@ -76,13 +80,18 @@ class Thread extends Module {
7680 alu.io.rs := 0 .U (8 .W );
7781 alu.io.rt := 0 .U (8 .W );
7882
79- io.debug_output := alu.io.output;
83+ val lsu = Module (new Lsu ())
84+ lsu.io.read := false .B ;
85+ lsu.io.write := false .B
86+ lsu.io.address := 0 .U ;
87+ lsu.io.data := 0 .U ;
88+
89+ lsu.io.read_ready := io.read_ready;
90+ lsu.io.read_data := io.read_data;
91+ io.read_address := lsu.io.read_address;
92+ io.read_requested := lsu.io.read_requested;
8093
81- // val lsu = Module(new Lsu())
82- // lsu.io.read := false.B;
83- // lsu.io.write := false.B
84- // lsu.io.address := 0.U;
85- // lsu.io.data := 0.U;
94+ lsu.io.write_ready := false .B ;
8695
8796 val executing_load_write = RegInit (false .B );
8897 val load_write_operation = RegInit (Operation .NoOp );
@@ -184,65 +193,59 @@ class Thread extends Module {
184193 io.idle := false .B ;
185194 }
186195
187- // when(
188- // io.operation === Operation.Write || io.operation === Operation.Load && !executing_load_write
189- // ) {
190- // io.idle := false.B;
191- // executing_load_write := true.B;
192-
193- // val operation = WireInit(Operation.NoOp);
194- // val address = WireInit(0.U(8.W));
195- // val value = WireInit(0.U(8.W));
196-
197- // when(executing_load_write) {
198- // operation := load_write_operation;
199- // address := load_write_address;
200- // value := write_value;
201- // }.otherwise {
202- // load_write_operation := io.operation;
203- // operation := io.operation;
204-
205- // load_write_address := io.immediate;
206- // address := io.immediate;
207-
208- // switch(io.src_register) {
209- // is(Register.A) {
210- // value := register_a;
211- // write_value := register_a;
212- // }
213- // is(Register.B) {
214- // value := register_b;
215- // write_value := register_b;
216- // }
217- // is(Register.C) {
218- // value := register_c;
219- // write_value := register_c;
220- // }
221- // }
222- // }
223-
224- // lsu.io.write := operation === Operation.Write;
225- // lsu.io.read := operation === Operation.Load;
226-
227- // // when(io.operation)
228-
229- // when(executing_load_write) {}
230- // }
196+ when(
197+ io.operation === Operation .Load
198+ ) {
199+ io.idle := false .B ;
200+
201+ lsu.io.read := true .B ;
202+
203+ switch(src_register) {
204+ is(Register .A ) {
205+ lsu.io.address := register_a;
206+ }
207+ is(Register .B ) {
208+ lsu.io.address := register_b;
209+ }
210+ is(Register .C ) {
211+ lsu.io.address := register_c;
212+ }
213+ }
214+
215+ switch(dst_register) {
216+ is(Register .A ) {
217+ register_a := lsu.io.output
218+ }
219+ is(Register .B ) {
220+ register_b := lsu.io.output
221+ }
222+ is(Register .C ) {
223+ register_c := lsu.io.output
224+ }
225+ }
226+
227+ when(lsu.io.state === LsuState .Done ) {
228+ program_pointer.io.update := true .B ;
229+ program_pointer.io.branch := false .B ;
230+ }
231+ }
231232 }
232233
233234 when(true .B ) {
234235 printf(p " \t [Thread]===== " );
235- printf(p " \n\t\t io.operation = ${io. operation}" );
236- printf(p " \n\t\t io.operation_pointer = ${io. operation_pointer}" );
237- printf(p " \n\t\t io.operation_loaded = ${io. operation_loaded}" );
236+ printf(p " \n\t\t operation = ${operation}" );
237+ printf(p " \n\t\t operation_pointer = ${operation_pointer}" );
238+ printf(p " \n\t\t operation_loaded = ${operation_loaded}" );
238239 printf(p " \n\t\t program_pointer= ${program_pointer.io.pointer}" );
239240 printf(p " \n\t\t io.idle= ${io.idle}" );
240- printf(p " \n\t\t io.debug_output= ${io.debug_output}" );
241241 printf(p " \n\t\t a= ${register_a}" );
242242 printf(p " \n\t\t b= ${register_b}" );
243243 printf(p " \n\t\t c= ${register_c}" );
244244 printf(p " \n\t\t Src Register= ${io.src_register}" );
245245 printf(p " \n\t\t Dst Register= ${io.dst_register}" );
246+ printf(p " \n\t\t Read requested= ${io.read_requested}" );
247+ printf(p " \n\t\t Read ready= ${io.read_ready}" );
248+ printf(p " \n\t\t Lsu state= ${lsu.io.state}" );
246249 printf(p " \n\n " );
247250 }
248251}
0 commit comments