Skip to content

Commit

Permalink
better debug print
Browse files Browse the repository at this point in the history
  • Loading branch information
HKhademian committed Jul 29, 2020
1 parent a947706 commit d0c5d45
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 27 deletions.
25 changes: 16 additions & 9 deletions src/main/java/mipsim/Processor.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,22 @@ public void eval(final long time) {

@Override
public void writeDebug(@NotNull StringBuffer buffer) {
final var pc = BusKt.toInt(this.wbif.pc);
final var instBin = BusKt.toInt(instructionMemory.instruction);
final var instStr = ParserKt.parseBinToInstruction(instBin);

buffer.append(String.format("pc pipe: %04xH\t", pc));
buffer.append(String.format("pc inst: %04xH\t", BusKt.toInt(instructionMemory.pc)));
buffer.append(String.format("pc ifid: %04xH\n", BusKt.toInt(ifid.pc)));
buffer.append(String.format("inst read: %08xH = ' %s '\t", instBin, instStr));
buffer.append(String.format("inst ifid: %08xH\n", BusKt.toInt(ifid.instruction)));
{
final var pc = BusKt.toInt(this.wbif.pc);
buffer.append(String.format("pc in if: %04xH\n", pc));
}

{
final var instBin = BusKt.toInt(instructionMemory.instruction);
final var instStr = ParserKt.parseBinToInstruction(instBin);
buffer.append(String.format("inst in mem: %08xH = ' %s '\n", instBin, instStr));
}
{
final var instBin = BusKt.toInt(ifid.instruction);
final var instStr = ParserKt.parseBinToInstruction(instBin);
buffer.append(String.format("inst in ifid: %08xH = ' %s '\n", instBin, instStr));
}

DebugKt.writeTo(registerFile, buffer);
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/mipsim/console/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public static void runProgram() {

public static int find_DebugLevel() {
System.out.println("--- Debug Levels ---");
System.out.println("1. Easy : ");
System.out.println("2. medium : ");
System.out.println("3. advance: ");
System.out.print("1. Easy\t");
System.out.print("2. medium\t");
System.out.println("3. advance");
return Console.askInteger("please choice Debug level:", 0);
}

public static boolean find_stepShow() {
return Console.askYesNo("Do you like to see step by step of code that you Run in Cpu ?", false);
return Console.askYesNo("Do you like to see step by step of code that you Run in Cpu ?", true);
}

public static boolean find_heWantToSaveInMemory() {
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/mipsim/sim/Simulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import mipsim.Processor;
import mipsim.console.Console;
import sim.base.BusKt;
import sim.tool.DebugKt;

import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -43,16 +42,16 @@ public void loadInstructions(final File instructionsFile) {
}

public void run(int debugLevel, boolean stepByStep) {
DebugKt.println(processor.instructionMemory);
testOn(processor.dataMemory, "dataMemory");
testOn(processor.dataMemory, "dataMemory - before run");

for (var i = 0; i < 100; i++) {
if (runStep(i, debugLevel)) break;

if (stepByStep && !Console.askYesNo("Do tou want to continue?", true)) break;
}

testOn(processor.dataMemory, "dataMemory");
testOn(processor.registerFile, "registerFile - after run");
testOn(processor.dataMemory, "dataMemory - after run");
}

boolean runStep(int step, int debugLevel) {
Expand Down
21 changes: 11 additions & 10 deletions src/main/kotlin/mipsim/units/RegisterFileUnit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ class RegisterFileUnit(clock: Value) : Eval, DebugWriter {
val values = _memory.bulkRead(32)
for (i in 0..31) {
val value: Int = values[i]
buffer.append(String.format("$%d=%04xH ", i, value))
buffer.append(String.format("$%-2d=%08xH ", i, value))
if (i % 8 == 7) buffer.appendln()
}
buffer.append("\n")
buffer.append("ReadReg1: ").append(readReg1.toInt()).append("\t")
buffer.append("ReadReg2: ").append(readReg2.toInt()).append("\t")
buffer.append("WriteReg: ").append(writeReg.toInt()).append("\n")
buffer.append("RegWrite: ").append(regWrite).append("\t")
buffer.append("ReadData1: ").append(readData1.toInt()).append("\t")
buffer.append("ReadData2: ").append(readData2.toInt()).append("\t")
buffer.append("WriteData: ").append(writeData.toInt())
}
buffer.append(String.format("WriteReg: %02d\t", writeReg.toInt()))
buffer.append(String.format("WriteData: %d\t", writeData.toInt()))
buffer.append(String.format("RegWrite: %d\n", regWrite.toInt()))

buffer.append(String.format("ReadReg1: %02d\t", readReg1.toInt()))
buffer.append(String.format("ReadData1: %d\n", readData1.toInt()))

buffer.append(String.format("ReadReg2: %02d\t", readReg2.toInt()))
buffer.append(String.format("ReadData2: %d\n", readData2.toInt()))
}
}

internal fun main1() {
Expand Down

0 comments on commit d0c5d45

Please sign in to comment.