Skip to content

Commit

Permalink
Fix bugs related to command line interface
Browse files Browse the repository at this point in the history
ic, register logging, memory logging and dump sections were all broken by
07581f9 . The global state for the program
is now held inside of a program object instead of globally accessible, so
logging gets the zeroed memoery and registers rather than the chnaged ones.

I noticed this while working on documentation for the commandline. The fix is
to pass the program object into the logging functions so they can use local
references to the data rather than reference Globals.memory or RegisterFile.

Dump has not been fixed yet as that is going to touch more files.

Obviously #13 is related, and this also shows how to get lines executed as part
of the api. A bonus of this is that it removes the jank way ic used to be calculated.
  • Loading branch information
TheThirdOne committed Oct 7, 2019
1 parent 03542f5 commit 0703e79
Showing 1 changed file with 28 additions and 66 deletions.
94 changes: 28 additions & 66 deletions rars/Launch.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,24 @@ private Launch(String[] args) {
MemoryConfigurations.setCurrentConfiguration(MemoryConfigurations.getDefaultConfiguration());
out = System.out;
if (parseCommandArgs(args)) {
runCommand();
dumpSegments();
dumpSegments(runCommand());
}
System.exit(Globals.exitCode);
}
}

private void displayAllPostMortem() {
displayMiscellaneousPostMortem();
displayRegistersPostMortem();
displayMemoryPostMortem();
private void displayAllPostMortem(Program program) {
displayMiscellaneousPostMortem(program);
displayRegistersPostMortem(program);
displayMemoryPostMortem(program.getMemory());
}
/////////////////////////////////////////////////////////////
// Perform any specified dump operations. See "dump" option.
//

private void dumpSegments() {

if (dumpTriples == null)
private void dumpSegments(Program program) {
// TODO: make dump segments work on api.Program
if (dumpTriples == null || program == null)
return;

for (String[] triple : dumpTriples) {
Expand Down Expand Up @@ -432,9 +431,9 @@ private boolean parseCommandArgs(String[] args) {
// Carry out the rars command: assemble then optionally run
// Returns false if no simulation (run) occurs, true otherwise.

private void runCommand() {
private Program runCommand() {
if (filenameList.size() == 0) {
return;
return null;
}

File mainFile = new File(filenameList.get(0)).getAbsoluteFile();// First file is "main" file
Expand Down Expand Up @@ -474,12 +473,10 @@ private void runCommand() {
Globals.exitCode = assembleErrorExitCode;
out.println(e.errors().generateErrorAndWarningReport());
out.println("Processing terminated due to errors.");
return;
return null;
}
if (simulate) {
program.setup(programArgumentList,null);
// establish observer if specified
establishObserver();
if (Globals.debug) {
out.println("-------- SIMULATION BEGINS -----------");
}
Expand All @@ -497,19 +494,20 @@ private void runCommand() {
break;
}
assert done == Simulator.Reason.BREAKPOINT : "Internal error: All cases other than breakpoints should be handled already";
displayAllPostMortem(); // print registers if we hit a breakpoint, then continue
displayAllPostMortem(program); // print registers if we hit a breakpoint, then continue
}

} catch (SimulationException e) {
Globals.exitCode = simulateErrorExitCode;
out.println(e.error().generateReport());
out.println("Simulation terminated due to errors.");
}
displayAllPostMortem();
displayAllPostMortem(program);
}
if (Globals.debug) {
out.println("\n-------- ALL PROCESSING COMPLETE -----------");
}
return program;
}


Expand Down Expand Up @@ -538,72 +536,32 @@ private String[] checkMemoryAddressRange(String arg) throws NumberFormatExceptio
return memoryRange;
}

/////////////////////////////////////////////////////////////////
// Required for counting instructions executed, if that option is specified.
// DPS 19 July 2012
private void establishObserver() {
if (countInstructions) {
Observer instructionCounter =
new Observer() {
private int lastAddress = 0;

public void update(Observable o, Object obj) {
if (obj instanceof AccessNotice) {
AccessNotice notice = (AccessNotice) obj;
if (!notice.accessIsFromRISCV())
return;
if (notice.getAccessType() != AccessNotice.READ)
return;
MemoryAccessNotice m = (MemoryAccessNotice) notice;
int a = m.getAddress();
if (a == lastAddress)
return;
lastAddress = a;
instructionCount++;
}
}
};
try {
Globals.memory.addObserver(instructionCounter, Memory.textBaseAddress, Memory.textLimitAddress);
} catch (AddressErrorException aee) {
out.println("Internal error: Launch uses incorrect text segment address for instruction observer");
}
}
}

//////////////////////////////////////////////////////////////////////
// Displays any specified runtime properties. Initially just instruction count
// DPS 19 July 2012
private void displayMiscellaneousPostMortem() {
private void displayMiscellaneousPostMortem(Program program) {
if (countInstructions) {
out.println("\n" + instructionCount);
out.println("\n" + program.getRegisterValue("cycle"));
}
}


//////////////////////////////////////////////////////////////////////
// Displays requested register or registers

private void displayRegistersPostMortem() {
private void displayRegistersPostMortem(Program program) {
// Display requested register contents
for (String reg : registerDisplayList) {
if (RegisterFile.getRegister(reg) != null) {
// integer register
if (verbose)
out.print(reg + "\t");
out.println(formatIntForDisplay(RegisterFile.getRegister(reg).getValue()));
} else {
if(FloatingPointRegisterFile.getRegister(reg) != null){
// floating point register
float fvalue = FloatingPointRegisterFile.getFloatFromRegister(reg);
int ivalue = FloatingPointRegisterFile.getValue(reg);
int ivalue = program.getRegisterValue(reg);
float fvalue = Float.intBitsToFloat(ivalue);
if (verbose) {
out.print(reg + "\t");
}
if (displayFormat == HEXADECIMAL) {
// display float (and double, if applicable) in hex
out.println(
Binary.binaryStringToHexString(
Binary.intToBinaryString(ivalue)));
out.println(Binary.intToHexString(ivalue));

} else if (displayFormat == DECIMAL) {
// display float (and double, if applicable) in decimal
Expand All @@ -612,6 +570,10 @@ private void displayRegistersPostMortem() {
} else { // displayFormat == ASCII
out.println(Binary.intToAscii(ivalue));
}
} else { // Integer register or CSR
if (verbose)
out.print(reg + "\t");
out.println(formatIntForDisplay(RegisterFile.getRegister(reg).getValue()));
}
}
}
Expand Down Expand Up @@ -639,7 +601,7 @@ private String formatIntForDisplay(int value) {
//////////////////////////////////////////////////////////////////////
// Displays requested memory range or ranges

private void displayMemoryPostMortem() {
private void displayMemoryPostMortem(Memory memory) {
int value;
// Display requested memory range contents
Iterator<String> memIter = memoryDisplayList.iterator();
Expand All @@ -663,10 +625,10 @@ private void displayMemoryPostMortem() {
try {
// Allow display of binary text segment (machine code) DPS 14-July-2008
if (Memory.inTextSegment(addr)) {
Integer iValue = Globals.memory.getRawWordOrNull(addr);
Integer iValue = memory.getRawWordOrNull(addr);
value = (iValue == null) ? 0 : iValue;
} else {
value = Globals.memory.getWord(addr);
value = memory.getWord(addr);
}
out.print(formatIntForDisplay(value) + "\t");
} catch (AddressErrorException aee) {
Expand Down

0 comments on commit 0703e79

Please sign in to comment.