From 0cfaa9d79e2b57c58cf920bf3fc971f30deccf9d Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 15 May 2012 01:19:36 +0200 Subject: [PATCH] Show full address when address is more than 16 bit --- se/sics/mspsim/chip/M25P80.java | 4 +-- se/sics/mspsim/core/DMA.java | 2 +- se/sics/mspsim/core/Flash.java | 16 +++++----- se/sics/mspsim/core/MSP430Core.java | 4 +-- se/sics/mspsim/core/Timer.java | 8 ++--- se/sics/mspsim/core/Watchdog.java | 4 +-- se/sics/mspsim/util/MapEntry.java | 2 +- se/sics/mspsim/util/SimpleProfiler.java | 39 ++++++++++++------------- 8 files changed, 39 insertions(+), 40 deletions(-) diff --git a/se/sics/mspsim/chip/M25P80.java b/se/sics/mspsim/chip/M25P80.java index 0a36e8d..0f9cb76 100644 --- a/se/sics/mspsim/chip/M25P80.java +++ b/se/sics/mspsim/chip/M25P80.java @@ -117,7 +117,7 @@ public abstract class M25P80 extends Chip implements USARTListener, PortListener switch(state) { case READ_STATUS: if (DEBUG) { - log("Read status => " + getStatus() + " from $" + Utils.hex16(cpu.getPC())); + log("Read status => " + getStatus() + " from $" + Utils.hex(cpu.getPC(), 4)); } source.byteReceived(getStatus()); return; @@ -338,7 +338,7 @@ public abstract class M25P80 extends Chip implements USARTListener, PortListener } private void programPage() { - if (writing) logw("Can not set program page while already writing... from $" + Utils.hex16(cpu.getPC())); + if (writing) logw("Can not set program page while already writing... from $" + Utils.hex(cpu.getPC(), 4)); writeStatus(PROGRAM_PAGE_MILLIS); ensureLoaded(blockWriteAddress); for (int i = 0; i < readMemory.length; i++) { diff --git a/se/sics/mspsim/core/DMA.java b/se/sics/mspsim/core/DMA.java index 57d4159..ec752c5 100644 --- a/se/sics/mspsim/core/DMA.java +++ b/se/sics/mspsim/core/DMA.java @@ -217,7 +217,7 @@ public class DMA extends IOUnit { } public void write(int address, int value, boolean word, long cycles) { - if (DEBUG) log("DMA write to: " + Utils.hex16(address) + ": " + value); + if (DEBUG) log("DMA write to: " + Utils.hex(address, 4) + ": " + value); switch (address) { case DMACTL0: /* DMA Control 0 */ diff --git a/se/sics/mspsim/core/Flash.java b/se/sics/mspsim/core/Flash.java index 52361d4..9eb5880 100644 --- a/se/sics/mspsim/core/Flash.java +++ b/se/sics/mspsim/core/Flash.java @@ -271,9 +271,9 @@ public class Flash extends IOUnit { int area_end = a_area_end[0]; if (DEBUG) { - log("Segment erase @" + Utils.hex16(address) + - ": erasing area " + Utils.hex16(area_start) + "-" + - Utils.hex16(area_end)); + log("Segment erase @" + Utils.hex(address, 4) + + ": erasing area " + Utils.hex(area_start, 4) + "-" + + Utils.hex(area_end, 4)); } for (int i = area_start; i < area_end; i++) { memory[i] = 0xff; @@ -309,7 +309,7 @@ public class Flash extends IOUnit { if (blockwriteCount == 0) { wait_time = BLOCKWRITE_FIRST_TIME; if (DEBUG) { - log("Flash write in block mode started @" + Utils.hex16(address)); + log("Flash write in block mode started @" + Utils.hex(address, 4)); } if (addressInFlash(cpu.getPC())) { logw("Oops. Block write access only allowed when executing from RAM."); @@ -331,7 +331,7 @@ public class Flash extends IOUnit { } } if (DEBUG) { - log("Writing $" + Utils.hex20(data) + " to $" + Utils.hex16(address) + " (" + dataMode.bytes + " bytes)"); + log("Writing $" + Utils.hex20(data) + " to $" + Utils.hex(address, 4) + " (" + dataMode.bytes + " bytes)"); } waitFlashProcess(wait_time); break; @@ -346,8 +346,8 @@ public class Flash extends IOUnit { if (DEBUG) { if (wait == false && currentWriteMode == WriteMode.WRITE_BLOCK) { log("Reading flash prohibited. Would read 0x3fff!!!"); - log("CPU PC=$" + Utils.hex16(cpu.getPC()) - + " read address $" + Utils.hex16(address)); + log("CPU PC=$" + Utils.hex(cpu.getPC(), 4) + + " read address $" + Utils.hex(address, 4)); } } } @@ -461,7 +461,7 @@ public class Flash extends IOUnit { } private void triggerAccessViolation(String reason) { - logw("Access violation: " + reason + ". PC=$" + Utils.hex16(cpu.getPC())); + logw("Access violation: " + reason + ". PC=$" + Utils.hex(cpu.getPC(), 4)); statusreg |= ACCVIFG; if (cpu.getSFR().isIEBitsSet(SFR.IE1, ACCVIE)) { diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index 2bc6920..828c1e3 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -204,10 +204,10 @@ public class MSP430Core extends Chip implements MSP430Constants { public void interruptServiced(int vector) { } public void write(int address, int value, boolean word, long cycles) { - logw("*** IOUnit write to non-existent IO at $" + Utils.hex16(address)); + logw("*** IOUnit write to non-existent IO at $" + Utils.hex(address, 4)); } public int read(int address, boolean word, long cycles) { - logw("*** IOUnit read from non-existent IO at $" + Utils.hex16(address)); + logw("*** IOUnit read from non-existent IO at $" + Utils.hex(address, 4)); return 0; } }; diff --git a/se/sics/mspsim/core/Timer.java b/se/sics/mspsim/core/Timer.java index 4cb47c2..8d785e5 100644 --- a/se/sics/mspsim/core/Timer.java +++ b/se/sics/mspsim/core/Timer.java @@ -483,7 +483,7 @@ public class Timer extends IOUnit { // Should handle read of byte also (currently ignores that...) public int read(int address, boolean word, long cycles) { - if (DEBUG) System.out.println(getName() + " read from: " + Utils.hex16(address)); + if (DEBUG) System.out.println(getName() + " read from: $" + Utils.hex(address, 4)); if (address == tiv) { // should clear registers for cause of interrupt (highest value)? @@ -542,11 +542,11 @@ public class Timer extends IOUnit { val = ccr[i].tccr; break; default: - logw("Not supported read, returning zero!!! addr: " + index + " addr: " + Utils.hex16(address)); + logw("Not supported read, returning zero!!! addr: " + index + " addr: $" + Utils.hex(address, 4)); } if (DEBUG) { - log("Read " + getName(address) + "(" + Utils.hex16(address) + ") => " + + log("Read " + getName(address) + "($" + Utils.hex(address, 4) + ") => $" + Utils.hex16(val) + " (" + val + ")"); } @@ -973,7 +973,7 @@ public class Timer extends IOUnit { if (reg < 0x10) return "TCTL" + (reg - 2) / 2; if (reg == 0x10) return "TR"; if (reg < 0x20) return "TCCR" + (reg - 0x12) / 2; - return " UNDEF(" + Utils.hex16(address) + ")"; + return " UNDEF(" + Utils.hex(address, 4) + ")"; } public String info() { diff --git a/se/sics/mspsim/core/Watchdog.java b/se/sics/mspsim/core/Watchdog.java index 1f6b882..11ad439 100644 --- a/se/sics/mspsim/core/Watchdog.java +++ b/se/sics/mspsim/core/Watchdog.java @@ -121,7 +121,7 @@ public class Watchdog extends IOUnit implements SFRModule { if (address == WDTCTL) { if ((value >> 8) == 0x5a) { wdtctl = value & 0xff; - if (DEBUG) log("Wrote to WDTCTL: " + Utils.hex8(wdtctl) + " from " + cpu.getPC()); + if (DEBUG) log("Wrote to WDTCTL: " + Utils.hex8(wdtctl) + " from $" + Utils.hex(cpu.getPC(), 4)); // Is it on? wdtOn = (value & 0x80) == 0; @@ -142,7 +142,7 @@ public class Watchdog extends IOUnit implements SFRModule { } } else { // Trigger reset!! - logw("illegal write to WDTCTL (" + value + ") from $" + Utils.hex16(cpu.getPC()) + logw("illegal write to WDTCTL (" + value + ") from $" + Utils.hex(cpu.getPC(), 4) + " - reset!!!!"); cpu.flagInterrupt(RESET_VECTOR, this, true); } diff --git a/se/sics/mspsim/util/MapEntry.java b/se/sics/mspsim/util/MapEntry.java index dd56ba7..e4bf02a 100644 --- a/se/sics/mspsim/util/MapEntry.java +++ b/se/sics/mspsim/util/MapEntry.java @@ -126,7 +126,7 @@ public class MapEntry { public String toString() { StringBuilder sb = new StringBuilder(); - sb.append('$').append(Utils.hex16(address)).append(' ').append(type).append(' ').append(name); + sb.append('$').append(Utils.hex(address, 4)).append(' ').append(type).append(' ').append(name); if (file != null) { sb.append(" ("); if (isLocal) sb.append("local in "); diff --git a/se/sics/mspsim/util/SimpleProfiler.java b/se/sics/mspsim/util/SimpleProfiler.java index e800913..aadc57a 100644 --- a/se/sics/mspsim/util/SimpleProfiler.java +++ b/se/sics/mspsim/util/SimpleProfiler.java @@ -98,6 +98,10 @@ public class SimpleProfiler implements Profiler, EventListener { this.cpu = cpu; } + public void setStackMonitor(StackMonitor stackMonitor) { + this.stackMonitor = stackMonitor; + } + public void setHideIRQ(boolean hide) { hideIRQ = hide; } @@ -126,7 +130,7 @@ public class SimpleProfiler implements Profiler, EventListener { if ((!hideIRQ || servicedInterrupt == -1) && hide == 0) { if (servicedInterrupt >= 0) logger.printf("[%2d] ", servicedInterrupt); printSpace(logger, (cSP - interruptLevel) * 2); - logger.println("Call to $" + Utils.hex16(entry.getAddress()) + + logger.println("Call to $" + Utils.hex(entry.getAddress(), 4) + ": " + entry.getInfo()); if (ignoreFunctions.get(entry.getName()) != null) { hide = 1; @@ -377,14 +381,14 @@ public class SimpleProfiler implements Profiler, EventListener { public void printStackTrace(PrintStream out) { int stackCount = cSP; out.println("Stack Trace: number of calls: " + stackCount - + " PC: $" + Utils.hex16(cpu.getPC())); + + " PC: $" + Utils.hex(cpu.getPC(), 4)); for (int i = 0; i < stackCount; i++) { CallEntry call = callStack[stackCount - i - 1]; out.println(" " + call.function.getInfo() - + " called from PC: $" + Utils.hex16(call.fromPC) + + " called from PC: $" + Utils.hex(call.fromPC, 4) + " (elapsed: " + (cpu.cpuCycles - call.cycles) + ')'); if (stackCount - i - 1 == interruptLevel && servicedInterrupt != -1) { - out.println(" *** Interrupt " + servicedInterrupt + " from PC: $" + Utils.hex16(interruptFrom)); + out.println(" *** Interrupt " + servicedInterrupt + " from PC: $" + Utils.hex(interruptFrom, 4)); } } } @@ -456,11 +460,15 @@ public class SimpleProfiler implements Profiler, EventListener { } private static class TagEntry implements Comparable { - String tag; + public final String tag; long cycles; long lastCycles; int calls; + public TagEntry(String tag) { + this.tag = tag; + } + public int compareTo(TagEntry o) { long diff = o.cycles - cycles; if (diff > 0) return 1; @@ -481,8 +489,7 @@ public class SimpleProfiler implements Profiler, EventListener { public void measureStart(String tag) { TagEntry tagEntry = tagProfiles.get(tag); if (tagEntry == null) { - tagEntry = new TagEntry(); - tagEntry.tag = tag; + tagEntry = new TagEntry(tag); tagProfiles.put(tag, tagEntry); } /* only the first occurrence of event will set the lastCycles */ @@ -505,9 +512,8 @@ public class SimpleProfiler implements Profiler, EventListener { public void printTagProfile(PrintStream out) { TagEntry[] entries = tagProfiles.values().toArray(new TagEntry[tagProfiles.size()]); Arrays.sort(entries); - for (int i = 0; i < entries.length; i++) { - TagEntry entry = entries[i]; - System.out.println(entry.tag + "\t" + entry.calls + "\t" + entry.cycles); + for (TagEntry entry : entries) { + out.println(entry.tag + "\t" + entry.calls + "\t" + entry.cycles); } } @@ -515,8 +521,7 @@ public class SimpleProfiler implements Profiler, EventListener { Chip chip2, String end) { System.out.println("Add profile: " + tag + " start: " + start + " end: " + end); - TagEntry tagEntry = new TagEntry(); - tagEntry.tag = tag; + TagEntry tagEntry = new TagEntry(tag); startTags.put(start, tagEntry); endTags.put(end, tagEntry); tagProfiles.put(tag, tagEntry); @@ -541,13 +546,11 @@ public class SimpleProfiler implements Profiler, EventListener { } public synchronized void addCallListener(CallListener listener) { - callListeners = (CallListener[]) - ArrayUtils.add(CallListener.class, callListeners, listener); + callListeners = ArrayUtils.add(CallListener.class, callListeners, listener); } public synchronized void removeCallListener(CallListener listener) { - callListeners = (CallListener[]) - ArrayUtils.remove(callListeners, listener); + callListeners = ArrayUtils.remove(callListeners, listener); } public String getCall(int i) { @@ -558,8 +561,4 @@ public class SimpleProfiler implements Profiler, EventListener { return callStack[cSP - i - 1].function; } - public void setStackMonitor(StackMonitor stackMonitor) { - System.out.println("Setting Stack monitor to: " + stackMonitor); - this.stackMonitor = stackMonitor; - } }