You can subscribe to this list here.
2007 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(12) |
Dec
(41) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2008 |
Jan
(25) |
Feb
(54) |
Mar
(63) |
Apr
(52) |
May
(17) |
Jun
(3) |
Jul
(3) |
Aug
(5) |
Sep
(49) |
Oct
(50) |
Nov
(34) |
Dec
(14) |
2009 |
Jan
(9) |
Feb
(15) |
Mar
(38) |
Apr
(12) |
May
(35) |
Jun
(20) |
Jul
(2) |
Aug
(7) |
Sep
(36) |
Oct
(24) |
Nov
(2) |
Dec
(2) |
2010 |
Jan
(14) |
Feb
(1) |
Mar
(36) |
Apr
(2) |
May
(4) |
Jun
(6) |
Jul
(35) |
Aug
(11) |
Sep
(8) |
Oct
(3) |
Nov
|
Dec
(1) |
2011 |
Jan
(11) |
Feb
(12) |
Mar
(3) |
Apr
(7) |
May
(12) |
Jun
(8) |
Jul
|
Aug
(3) |
Sep
(4) |
Oct
|
Nov
(2) |
Dec
(4) |
2012 |
Jan
(2) |
Feb
(1) |
Mar
(14) |
Apr
(5) |
May
(28) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
(4) |
Dec
(1) |
2013 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Niclas F. <ni...@us...> - 2012-05-14 23:21:13
|
The branch "master" has been updated via 351c7b6a63d598488c8bc13fc1af2279bfa33df6 (commit) from 0cfaa9d79e2b57c58cf920bf3fc971f30deccf9d (commit) Changed paths: M build.xml - Log ----------------------------------------------------------------- commit 351c7b6a63d598488c8bc13fc1af2279bfa33df6 Author: Niclas Finne <nf...@si...> Date: Tue May 15 01:20:56 2012 +0200 corrected firmware file names diff --git a/build.xml b/build.xml index 014c4d1..7b293ac 100644 --- a/build.xml +++ b/build.xml @@ -39,21 +39,21 @@ </target> <target name="runesb" depends="jar" description="run MSPSim with platform ESB"> - <property name="FIRMWAREFILE" value="firmware/esb/sensor-demo.firmware"/> + <property name="FIRMWAREFILE" value="firmware/esb/sensor-demo.esb"/> <java fork="true" classpath="${jarfile}" classname="se.sics.mspsim.platform.esb.ESBNode"> <arg value="${FIRMWAREFILE}"/> </java> </target> <target name="runsky" depends="jar" description="run MSPSim with platform Sky"> - <property name="FIRMWAREFILE" value="firmware/sky/blink.firmware"/> + <property name="FIRMWAREFILE" value="firmware/sky/blink.sky"/> <java fork="true" classpath="${jarfile}" classname="se.sics.mspsim.platform.sky.SkyNode"> <arg value="${FIRMWAREFILE}"/> </java> </target> <target name="runskyprof" depends="jar" description="run MSPSim with platform Sky for profiling"> - <property name="FIRMWAREFILE" value="firmware/sky/blink.firmware"/> + <property name="FIRMWAREFILE" value="firmware/sky/blink.sky"/> <java fork="true" classpath="${jarfile}" classname="se.sics.mspsim.platform.sky.SkyNode"> <jvmarg value="-agentlib:yjpagent" /> <arg value="${FIRMWAREFILE}"/> @@ -61,21 +61,21 @@ </target> <target name="runtelos" depends="jar" description="run MSPSim with platform Telos"> - <property name="FIRMWAREFILE" value="firmware/sky/blink.firmware"/> + <property name="FIRMWAREFILE" value="firmware/sky/blink.sky"/> <java fork="true" classpath="${jarfile}" classname="se.sics.mspsim.platform.sky.TelosNode"> <arg value="${FIRMWAREFILE}"/> </java> </target> <target name="runjcreate" depends="jar" description="run MSPSim with platform Sentilla JCreate"> - <property name="FIRMWAREFILE" value="firmware/sky/blink.firmware"/> + <property name="FIRMWAREFILE" value="firmware/sky/blink.sky"/> <java fork="true" classpath="${jarfile}" classname="se.sics.mspsim.platform.jcreate.JCreateNode"> <arg value="${FIRMWAREFILE}"/> </java> </target> <target name="runsentillausb" depends="jar" description="run MSPSim with platform Sentilla Gateway USB"> - <property name="FIRMWAREFILE" value="firmware/sky/blink.firmware"/> + <property name="FIRMWAREFILE" value="firmware/sky/blink.sky"/> <java fork="true" classpath="${jarfile}" classname="se.sics.mspsim.platform.sentillausb.SentillaUSBNode"> <arg value="${FIRMWAREFILE}"/> </java> ----------------------------------------------------------------------- Summary of changes: build.xml | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-05-14 23:20:47
|
The branch "master" has been updated via 0cfaa9d79e2b57c58cf920bf3fc971f30deccf9d (commit) via 70b8a275accaa554a4071793c896f788170b47fd (commit) from 45dc92214475d5b3cac32f7e32e049e3f640d400 (commit) Changed paths: M se/sics/mspsim/chip/M25P80.java M se/sics/mspsim/cli/DebugCommands.java M se/sics/mspsim/core/DMA.java M se/sics/mspsim/core/Flash.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/core/Timer.java M se/sics/mspsim/core/Watchdog.java M se/sics/mspsim/util/ELF.java M se/sics/mspsim/util/MapEntry.java M se/sics/mspsim/util/SimpleProfiler.java - Log ----------------------------------------------------------------- commit 0cfaa9d79e2b57c58cf920bf3fc971f30deccf9d Author: Niclas Finne <nf...@si...> Date: Tue May 15 01:19:36 2012 +0200 Show full address when address is more than 16 bit 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 void dataReceived(USARTSource source, int data) { 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 @@ private void writeStatus(double time) { } 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 void interruptServiced(int vector) { } 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 void flashWrite(int address, int data, AccessMode dataMode) { 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 void flashWrite(int address, int data, AccessMode dataMode) { 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 void flashWrite(int address, int data, AccessMode dataMode) { } } 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 void notifyRead(int address) { 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 @@ private void triggerUnlockFlash() { } 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 void set(int address, int data, AccessMode mode) { 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 void reset(int type) { // 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 int read(int address, boolean word, long cycles) { 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 String getName(int address) { 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 void write(int address, int value, boolean word, long cycles) { 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 void write(int address, int value, boolean word, long cycles) { } } 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 String getInfo() { 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 void setCPU(MSP430Core cpu) { this.cpu = cpu; } + public void setStackMonitor(StackMonitor stackMonitor) { + this.stackMonitor = stackMonitor; + } + public void setHideIRQ(boolean hide) { hideIRQ = hide; } @@ -126,7 +130,7 @@ public void profileCall(MapEntry entry, long cycles, int from) { 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 @@ private void printSpace(PrintStream out, int len) { 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 int compareTo(CallCounter o) { } private static class TagEntry implements Comparable<TagEntry> { - 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 void setLogger(PrintStream out) { 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 void measureEnd(String tag) { 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 void addProfileTag(String tag, Chip chip, String start, 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 void event(EventSource source, String event, Object data) { } 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 MapEntry getCallMapEntry(int i) { return callStack[cSP - i - 1].function; } - public void setStackMonitor(StackMonitor stackMonitor) { - System.out.println("Setting Stack monitor to: " + stackMonitor); - this.stackMonitor = stackMonitor; - } } commit 70b8a275accaa554a4071793c896f788170b47fd Author: Niclas Finne <nf...@si...> Date: Tue May 15 00:49:40 2012 +0200 do not show file name when no file information is available diff --git a/se/sics/mspsim/cli/DebugCommands.java b/se/sics/mspsim/cli/DebugCommands.java index 7865d1a..48a65b8 100644 --- a/se/sics/mspsim/cli/DebugCommands.java +++ b/se/sics/mspsim/cli/DebugCommands.java @@ -64,7 +64,7 @@ private ELF getELF() { public void setupCommands(ComponentRegistry registry, CommandHandler ch) { this.registry = registry; final MSP430 cpu = registry.getComponent(MSP430.class); - final GenericNode node = (GenericNode) registry.getComponent("node"); + final GenericNode node = registry.getComponent(GenericNode.class, "node"); if (cpu != null) { ch.registerCommand("break", new BasicAsyncCommand("add a breakpoint to a given address or symbol", "<address or symbol>") { @@ -245,11 +245,15 @@ public int executeCommand(final CommandContext context) { } else { for (MapEntry mapEntry : entries) { int address = mapEntry.getAddress(); + String file = mapEntry.getFile(); + if (file == null) { + file = "(unspecified)"; + } context.out.println(" " + mapEntry.getName() + " at $" + cpu.getAddressAsString(address) + " ($" + Utils.hex8(cpu.getMemory().get(address, AccessMode.BYTE)) + ' ' + Utils.hex8(cpu.getMemory().get(address + 1, AccessMode.BYTE)) + ") " - + mapEntry.getType() + " in file " + mapEntry.getFile()); + + mapEntry.getType() + " in file " + file); } } return 0; @@ -374,7 +378,7 @@ public int executeCommand(CommandContext context) { public int executeCommand(CommandContext context) { int register = context.getArgumentAsRegister(0); if (register >= 0) { - context.out.println(context.getArgument(0) + " = $" + Utils.hex16(cpu.getRegister(register))); + context.out.println(context.getArgument(0) + " = $" + Utils.hex(cpu.getRegister(register), 4)); return 0; } return -1; diff --git a/se/sics/mspsim/util/ELF.java b/se/sics/mspsim/util/ELF.java index 44d6100..1faddc9 100644 --- a/se/sics/mspsim/util/ELF.java +++ b/se/sics/mspsim/util/ELF.java @@ -388,7 +388,7 @@ public MapTable getMap() { int len = symTable.size; int count = len / symTable.getEntrySize(); int addr = symTable.getOffset(); - String currentFile = ""; + String currentFile = null; if (DEBUG) { System.out.println("Number of symbols:" + count); } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/M25P80.java | 4 +- se/sics/mspsim/cli/DebugCommands.java | 10 +++++-- 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/ELF.java | 2 +- se/sics/mspsim/util/MapEntry.java | 2 +- se/sics/mspsim/util/SimpleProfiler.java | 39 +++++++++++++++---------------- 10 files changed, 47 insertions(+), 44 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-14 16:03:15
|
The branch "master" has been updated via 45dc92214475d5b3cac32f7e32e049e3f640d400 (commit) from fdc856247f244f58e1937459c43a067d0be4a19a (commit) Changed paths: M se/sics/mspsim/chip/CC2520SPI.java M se/sics/mspsim/chip/SPICommand.java - Log ----------------------------------------------------------------- commit 45dc92214475d5b3cac32f7e32e049e3f640d400 Author: Joakim Eriksson <jo...@si...> Date: Mon May 14 18:02:48 2012 +0200 minor fix diff --git a/se/sics/mspsim/chip/CC2520SPI.java b/se/sics/mspsim/chip/CC2520SPI.java index f8a33ee..fff57f0 100644 --- a/se/sics/mspsim/chip/CC2520SPI.java +++ b/se/sics/mspsim/chip/CC2520SPI.java @@ -54,7 +54,7 @@ SPICommand[] commands = new SPICommand[256]; CC2520SPI() { - + /* set up the commands */ for (int i = 0; i < spiCommands.length; i++) { SPICommand c = spiCommands[i]; int maxv = 1 << (8 - c.bitCount); @@ -70,8 +70,18 @@ } } + SPICommand getCommand(int cmd) { + if (cmd < 256 && commands[cmd] != null) + return commands[cmd]; + return null; + } + + public static void main(String[] args) { - new CC2520SPI(); + CC2520SPI spi = new CC2520SPI(); + SPICommand cmd = spi.getCommand(0xff); + /* commands that take infinite number of bytes have the bitfield ... */ + System.out.println("Has ... => " + cmd.getBitField("...")); } } diff --git a/se/sics/mspsim/chip/SPICommand.java b/se/sics/mspsim/chip/SPICommand.java index d0b5640..55ebfe0 100644 --- a/se/sics/mspsim/chip/SPICommand.java +++ b/se/sics/mspsim/chip/SPICommand.java @@ -1,6 +1,7 @@ package se.sics.mspsim.chip; import java.util.ArrayList; +import java.util.Iterator; public class SPICommand { /* @@ -93,6 +94,9 @@ public int getValue(int[] spiData) { if (start != 0) { System.out.println("Bitfield: " + currentName + ": [" + start + " - " + (c - 1) + "]"); + if (bitFields == null) + bitFields = new ArrayList<SPICommand.BitField>(); + bitFields.add(new BitField(currentName, start, c - 1)); } System.out.printf("Value %x\n", value); @@ -113,11 +117,20 @@ public boolean dataReceived(int spiData) { return true; } + /* for any command that is executable (finite commands) */ public boolean executeSPICommand(int[] spiData) { System.out.println("Command " + name + " not implemented..."); return true; } + public BitField getBitField(String arg) { + for (BitField b : bitFields) { + if (b.name.equals(arg)) return b; + } + /* not existing ... */ + return null; + } + public static void main(String[] args) { SPICommand c = new SPICommand("MEMXCP 0 1 0 1 0 1 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e") { public boolean executeSPICommand(int[] spiData) { ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2520SPI.java | 14 ++++++++++++-- se/sics/mspsim/chip/SPICommand.java | 13 +++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-14 15:08:32
|
The branch "master" has been updated via fdc856247f244f58e1937459c43a067d0be4a19a (commit) from a8fd64694b02392d80a4d7f8d6e2eb8e07856417 (commit) Changed paths: M se/sics/mspsim/chip/SPICommand.java - Log ----------------------------------------------------------------- commit fdc856247f244f58e1937459c43a067d0be4a19a Author: Joakim Eriksson <jo...@si...> Date: Mon May 14 17:08:12 2012 +0200 fixed bug diff --git a/se/sics/mspsim/chip/SPICommand.java b/se/sics/mspsim/chip/SPICommand.java index d68d552..d0b5640 100644 --- a/se/sics/mspsim/chip/SPICommand.java +++ b/se/sics/mspsim/chip/SPICommand.java @@ -58,13 +58,17 @@ public int getValue(int[] spiData) { for (int i = 1; i < subs.length; i++) { /* not more than first byte */ if (subs[i].equals("1")) { + if (c < 8) { value = (value << 1) + 1; mask = (mask << 1) | 1; bitCount++; + } } else if (subs[i].equals("0")) { + if (c < 8) { value = (value << 1); mask = (mask << 1) | 1; bitCount++; + } } else if (subs[i].equals(currentName)) { /* do nothing */ } else { @@ -75,7 +79,7 @@ public int getValue(int[] spiData) { bitFields = new ArrayList<SPICommand.BitField>(); bitFields.add(new BitField(currentName, start, c - 1)); } else { - System.out.println("C: " + c); + System.out.printf("C: %d value: %x mask: %x \n", c, value, mask); if (c < 8) { value = value << (8 - c); mask = mask << (8 - c); @@ -91,8 +95,8 @@ public int getValue(int[] spiData) { start + " - " + (c - 1) + "]"); } - System.out.printf("Value %x\n",value); - System.out.printf("Mask %x\n",value); + System.out.printf("Value %x\n", value); + System.out.printf("Mask %x\n", mask); } /* return -1 if no match */ ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/SPICommand.java | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-14 14:31:35
|
The branch "master" has been updated via a8fd64694b02392d80a4d7f8d6e2eb8e07856417 (commit) from 27be1bdc7b5db82b7614245d47f9cb5d226c39b7 (commit) Changed paths: A se/sics/mspsim/chip/CC2520SPI.java - Log ----------------------------------------------------------------- commit a8fd64694b02392d80a4d7f8d6e2eb8e07856417 Author: Joakim Eriksson <jo...@si...> Date: Mon May 14 16:31:14 2012 +0200 added CC2520 SPI registers diff --git a/se/sics/mspsim/chip/CC2520SPI.java b/se/sics/mspsim/chip/CC2520SPI.java new file mode 100644 index 0000000..f8a33ee --- /dev/null +++ b/se/sics/mspsim/chip/CC2520SPI.java @@ -0,0 +1,77 @@ +package se.sics.mspsim.chip; + +public class CC2520SPI { + SPICommand[] spiCommands = { + new SPICommand("SNOP 0 0 0 0 0 0 0 0"), + new SPICommand("IBUFLD 0 0 0 0 0 0 1 0 i i i i i i i i"), + new SPICommand("SIBUFEX 0 0 0 0 0 0 1 1"), + new SPICommand("SSAMPLECCA 0 0 0 0 0 1 0 0"), + new SPICommand("SRES 0 0 0 0 1 1 1 1 - - - - - - - -"), + new SPICommand("MEMRD 0 0 0 1 a a a a a a a a a a a a - - - - - - - - ..."), + new SPICommand("MEMWR 0 0 1 0 a a a a a a a a a a a a d d d d d d d d ..."), + new SPICommand("RXBUF 0 0 1 1 0 0 0 0 - - - - - - - - ..."), + new SPICommand("RXBUFCP 0 0 1 1 1 0 0 0 0 0 0 0 a a a a a a a a a a a a - - - - - - - - ..."), + new SPICommand("RXBUFMOV 0 0 1 1 0 0 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a"), + new SPICommand("TXBUF 0 0 1 1 1 0 1 0 d d d d d d d d d d d d d d d d ..."), + new SPICommand("TXBUFCP 0 0 1 1 1 1 1 p c c c c c c c c 0 0 0 0 a a a a a a a a a a a a"), + new SPICommand("RANDOM 0 0 1 1 1 1 0 0 - - - - - - - - - - - - - - - - ..."), + new SPICommand("SXOSCON 0 1 0 0 0 0 0 0"), + new SPICommand("STXCAL 0 1 0 0 0 0 0 1"), + new SPICommand("SRXON 0 1 0 0 0 0 1 0"), + new SPICommand("STXON 0 1 0 0 0 0 1 1"), + new SPICommand("STXONCCA 0 1 0 0 0 1 0 0"), + new SPICommand("SRFOFF 0 1 0 0 0 1 0 1"), + new SPICommand("SXOSCOFF 0 1 0 0 0 1 1 0"), + new SPICommand("SFLUSHRX 0 1 0 0 0 1 1 1"), + new SPICommand("SFLUSHTX 0 1 0 0 1 0 0 0"), + new SPICommand("SACK 0 1 0 0 1 0 0 1"), + new SPICommand("SACKPEND 0 1 0 0 1 0 1 0"), + new SPICommand("SNACK 0 1 0 0 1 0 1 1"), + new SPICommand("SRXMASKBITSET 0 1 0 0 1 1 0 0"), + new SPICommand("SRXMASKBITCLR 0 1 0 0 1 1 0 1"), + new SPICommand("RXMASKAND 0 1 0 0 1 1 1 0 d d d d d d d d d d d d d d d d"), + new SPICommand("RXMASKOR 0 1 0 0 1 1 1 1 d d d d d d d d d d d d d d d d"), + new SPICommand("MEMCP 0 1 0 1 0 0 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e"), + new SPICommand("MEMCPR 0 1 0 1 0 0 1 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e"), + new SPICommand("MEMXCP 0 1 0 1 0 1 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e"), + new SPICommand("MEMXWR 0 1 0 1 0 1 1 0 0 0 0 0 a a a a a a a a a a a a d d d d d d d d ..."), + new SPICommand("BCLR 0 1 0 1 1 0 0 0 a a a a a b b b"), + new SPICommand("BSET 0 1 0 1 1 0 0 1 a a a a a b b b"), + new SPICommand("CTR/UCTR 0 1 1 0 0 0 0 p k k k k k k k k 0 c c c c c c c n n n n n n n n a a a a e e e e a a a a a a a a e e e e e e e e"), + new SPICommand("CBCMAC 0 1 1 0 0 1 0 p k k k k k k k k 0 c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e 0 0 0 0 0 mmm"), + new SPICommand("UCBCMAC 0 1 1 0 0 1 1 p k k k k k k k k 0 c c c c c c c 0 0 0 0 a a a a a a a a a a a a 0 0 0 0 0 mmm"), + new SPICommand("CCM 0 1 1 0 1 0 0 p k k k k k k k k 0 c c c c c c c n n n n n n n n a a a a e e e e a a a a a a a a e e e e e e e e 0 f f f f f f f 0 0 0 0 0 0 mm"), + new SPICommand("UCCM 0 1 1 0 1 0 1 p k k k k k k k k 0 c c c c c c c n n n n n n n n a a a a e e e e a a a a a a a a e e e e e e e e 0 f f f f f f f 0 0 0 0 0 0 mm"), + new SPICommand("ECB 0 1 1 1 0 0 0 p k k k k k k k k c c c c a a a a a a a a a a a a 0 0 0 0 e e e e e e e e e e e e"), + new SPICommand("ECBO 0 1 1 1 0 0 1 p k k k k k k k k c c c c a a a a a a a a a a a a"), + new SPICommand("ECBX 0 1 1 1 0 1 0 p k k k k k k k k c c c c a a a a a a a a a a a a 0 0 0 0 e e e e e e e e e e e e"), + new SPICommand("INC 0 1 1 1 1 0 0 p 0 0 c c a a a a a a a a a a a a"), + new SPICommand("ABORT 0 1 1 1 1 1 1 1 0 0 0 0 0 0 c c"), + new SPICommand("REGRD 1 0 a a a a a a - - - - - - - - ..."), + new SPICommand("REGWR 1 1 a a a a a a d d d d d d d d ...") + }; + + SPICommand[] commands = new SPICommand[256]; + + CC2520SPI() { + + for (int i = 0; i < spiCommands.length; i++) { + SPICommand c = spiCommands[i]; + int maxv = 1 << (8 - c.bitCount); + int v = c.value; + /* populate an array with the values for quick decoding */ + for (int j = 0; j < maxv; j++) { + System.out.printf(c.name + " => Value: %x\n", (v + j)); + if (commands[v + j] != null) { + System.out.println("ERROR: command already registered: " + commands[v + j].name); + } + commands[v + j] = c; + } + } + } + + public static void main(String[] args) { + new CC2520SPI(); + } + +} ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2520SPI.java | 77 ++++++++++++++++++++++++++++++++++++ 1 files changed, 77 insertions(+), 0 deletions(-) create mode 100644 se/sics/mspsim/chip/CC2520SPI.java hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-05-14 11:43:21
|
The branch "master" has been updated via 27be1bdc7b5db82b7614245d47f9cb5d226c39b7 (commit) from 9677af71dd40368003b721376e8fa006ce974e26 (commit) Changed paths: A se/sics/mspsim/chip/SPICommand.java - Log ----------------------------------------------------------------- commit 27be1bdc7b5db82b7614245d47f9cb5d226c39b7 Author: Joakim Eriksson <jo...@si...> Date: Mon May 14 13:42:54 2012 +0200 experimental SPI command class - for CC2520, etc. diff --git a/se/sics/mspsim/chip/SPICommand.java b/se/sics/mspsim/chip/SPICommand.java new file mode 100644 index 0000000..d68d552 --- /dev/null +++ b/se/sics/mspsim/chip/SPICommand.java @@ -0,0 +1,139 @@ +package se.sics.mspsim.chip; + +import java.util.ArrayList; + +public class SPICommand { +/* + * MEMXCP 0 1 0 1 0 1 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e + */ + String name; + int mask; + int value; + int bitCount; + int commandLen = 0; + + private class BitField { + String name; + int startBit; + int endBit; + int firstMask; + + public BitField(String currentName, int start, int c) { + name = currentName; + startBit = start; + endBit = c; + firstMask = 0xff >> (startBit & 7); + + System.out.printf("First mask %x\n", firstMask); + } + + public int getValue(int[] spiData) { + int value; + int firstByte = startBit / 8; + int lastByte = endBit / 8; + int nrBitsRoll = 7 - endBit & 7; + + value = spiData[firstByte] & firstMask; + for (int i = firstByte + 1; i < lastByte; i++) { + value = value << 8 + spiData[firstByte]; + } + value = value >> nrBitsRoll; + + return value; + } + } + + ArrayList<BitField> bitFields; + + SPICommand(String pattern) { + String[] subs = pattern.split(" "); + name = subs[0]; + System.out.println("Name:" + subs[0]); + value = 0; + mask = 0; + int c = 0; + int start = 0; + String currentName = "-"; + bitCount = 0; + for (int i = 1; i < subs.length; i++) { + /* not more than first byte */ + if (subs[i].equals("1")) { + value = (value << 1) + 1; + mask = (mask << 1) | 1; + bitCount++; + } else if (subs[i].equals("0")) { + value = (value << 1); + mask = (mask << 1) | 1; + bitCount++; + } else if (subs[i].equals(currentName)) { + /* do nothing */ + } else { + if (start != 0) { + System.out.println("Bitfield: " + currentName + ": [" + + start + " - " + (c - 1) + "]"); + if (bitFields == null) + bitFields = new ArrayList<SPICommand.BitField>(); + bitFields.add(new BitField(currentName, start, c - 1)); + } else { + System.out.println("C: " + c); + if (c < 8) { + value = value << (8 - c); + mask = mask << (8 - c); + } + } + currentName = subs[i]; + start = c; + } + c++; + } + if (start != 0) { + System.out.println("Bitfield: " + currentName + ": [" + + start + " - " + (c - 1) + "]"); + } + + System.out.printf("Value %x\n",value); + System.out.printf("Mask %x\n",value); + } + + /* return -1 if no match */ + /* or len of the rest of the arguments if any more */ + public int matchSPI(int spiData) { + if ((spiData & mask) == value) { + return commandLen; + } + return -1; + } + + /* do nothing here... - override if needed */ + public boolean dataReceived(int spiData) { + return true; + } + + public boolean executeSPICommand(int[] spiData) { + System.out.println("Command " + name + " not implemented..."); + return true; + } + + public static void main(String[] args) { + SPICommand c = new SPICommand("MEMXCP 0 1 0 1 0 1 0 p c c c c c c c c a a a a e e e e a a a a a a a a e e e e e e e e") { + public boolean executeSPICommand(int[] spiData) { + System.out.println("Yes!"); + return true; + } + }; + int[] data = new int[]{1,0x13,0xab,0xaa,0xbb}; + for (int i = 0; i < c.bitFields.size(); i++) { + System.out.printf("Data %s: %x\n", c.bitFields.get(i).name, c.bitFields.get(i).getValue(data)); + } + c.executeSPICommand(data); + + System.out.println("Bitcount:" + c.bitCount); + int maxv = 1 << (8 - c.bitCount); + int v = c.value; + + /* populate an array with the values for quick decoding */ + for (int i = 0; i < maxv; i++) { + System.out.printf("Value: %x\n", (v + i)); + } + } +} ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/SPICommand.java | 139 +++++++++++++++++++++++++++++++++++ 1 files changed, 139 insertions(+), 0 deletions(-) create mode 100644 se/sics/mspsim/chip/SPICommand.java hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-05-11 09:54:26
|
The branch "master" has been updated via 9677af71dd40368003b721376e8fa006ce974e26 (commit) from d2f2f4cea904d0a594bd64d7bc98cbcd9df32335 (commit) Changed paths: M se/sics/mspsim/chip/CC2420.java - Log ----------------------------------------------------------------- commit 9677af71dd40368003b721376e8fa006ce974e26 Author: Niclas Finne <nf...@si...> Date: Fri May 11 11:48:55 2012 +0200 Added LQI access method. Patch by Moritz Struebe. diff --git a/se/sics/mspsim/chip/CC2420.java b/se/sics/mspsim/chip/CC2420.java index 2a8d4ef..414e6f2 100644 --- a/se/sics/mspsim/chip/CC2420.java +++ b/se/sics/mspsim/chip/CC2420.java @@ -1286,6 +1286,10 @@ public void setLQI(int lqi){ corrval = lqi; } + public int getLQI() { + return corrval; + } + public void setRSSI(int power) { final int minp = -128 + RSSI_OFFSET; final int maxp = 128 + RSSI_OFFSET; ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2420.java | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) hooks/post-receive -- mspsim |
From: Fredrik Ãs. <fro...@us...> - 2012-04-27 10:46:08
|
The branch "master" has been updated via d2f2f4cea904d0a594bd64d7bc98cbcd9df32335 (commit) from b0dafb710c566994b9277641c6f83b6bc6387796 (commit) Changed paths: M se/sics/mspsim/debug/DwarfReader.java - Log ----------------------------------------------------------------- commit d2f2f4cea904d0a594bd64d7bc98cbcd9df32335 Author: Fredrik Osterlind <fr...@si...> Date: Fri Apr 27 12:45:17 2012 +0200 fixed bugs that caused incorrect address lookups: * source file registry entry was ignored in line entries * extended opcode length is a leb128 * end_sequence opcode should add new line entry, and then reset registry * implemented opcode DW_LNS_const_add_pc * getDebugInfo() incorrectly matched prologue line entries added main() to generate output comparable with that of msp430-addr2line (verified with msp430-gcc v4.5.3). diff --git a/se/sics/mspsim/debug/DwarfReader.java b/se/sics/mspsim/debug/DwarfReader.java index 38ee5d5..b7d7de7 100644 --- a/se/sics/mspsim/debug/DwarfReader.java +++ b/se/sics/mspsim/debug/DwarfReader.java @@ -39,13 +39,14 @@ package se.sics.mspsim.debug; +import java.io.File; import java.util.ArrayList; import se.sics.mspsim.util.DebugInfo; -import se.sics.mspsim.util.ELFDebug; -import se.sics.mspsim.util.Utils; import se.sics.mspsim.util.ELF; +import se.sics.mspsim.util.ELFDebug; import se.sics.mspsim.util.ELFSection; +import se.sics.mspsim.util.Utils; public class DwarfReader implements ELFDebug { @@ -63,6 +64,9 @@ public static final int DW_LNS_set_basic_block = 7; public static final int DW_LNS_const_add_pc = 8; public static final int DW_LNS_fixed_advance_pc = 9; + public static final int DW_LNS_set_prologue_end = 10; + public static final int DW_LNS_set_epilogue_begin = 11; + public static final int DW_LNS_set_isa = 12; /* Extended operands (preceded by DW_LNS_EXT + len) */ public static final int DW_LNE_end_sequence = 1; @@ -84,9 +88,11 @@ class LineEntry { int address; int line; - LineEntry(int line, int adr) { + int file; + LineEntry(int line, int adr, int file) { this.line = line; - address = adr; + this.address = adr; + this.file = file; } } /* Line number lookup data */ @@ -130,6 +136,7 @@ private void readLines(ELFSection sec) { if (DEBUG) { System.out.println("DWARF Line - ELF Section length: " + sec.getSize()); } + sec.reset(); int endPos = 0; ArrayList<LineEntry> lineData = new ArrayList<LineEntry>(); @@ -142,7 +149,7 @@ private void readLines(ELFSection sec) { int minOpLen = sec.readElf8(); int defaultIsStmt = sec.readElf8(); - int lineBase = sec.readElf8(); + int lineBase = Integer.valueOf(sec.readElf8()).byteValue(); int lineRange = sec.readElf8(); int opcodeBase = sec.readElf8(); @@ -153,9 +160,6 @@ private void readLines(ELFSection sec) { System.out.println("Line version: " + version); } - if (lineBase > 127) { - lineBase = lineBase - 256; - } if (DEBUG) { System.out.println("Line base : " + lineBase); System.out.println("Line range : " + lineRange); @@ -179,7 +183,10 @@ private void readLines(ELFSection sec) { int c; while ((c = sec.readElf8()) != 0) { sb.append((char)c); - while((c = sec.readElf8()) != 0) sb.append((char) c); + while((c = sec.readElf8()) != 0) { + sb.append((char) c); + } + if (DEBUG) System.out.println("Line: include file: " + sb.toString()); directories.add(sb.toString()); sb.setLength(0); @@ -191,7 +198,10 @@ private void readLines(ELFSection sec) { long size = 0; while ((c = sec.readElf8()) != 0) { sb.append((char)c); - while((c = sec.readElf8()) != 0) sb.append((char) c); + while((c = sec.readElf8()) != 0) { + sb.append((char) c); + } + dirIndex = sec.readLEB128(); time = sec.readLEB128(); size = sec.readLEB128(); @@ -201,6 +211,7 @@ private void readLines(ELFSection sec) { sb.setLength(0); } + /* Now we should have entered the position of the "code" for generating the * line <=> address table */ @@ -223,48 +234,55 @@ private void readLines(ELFSection sec) { lineData.clear(); while(!endSequence) { - int ins = sec.readElf8(); - if (DEBUG) System.out.print("POS: " + sec.getPosition() + " INS: " + Utils.hex8(ins) + " "); - switch(ins) { + int opCode = sec.readElf8(); + if (DEBUG) System.out.print("POS: " + sec.getPosition() + " INS: " + Utils.hex8(opCode) + " "); + switch(opCode) { case DW_LNS_EXT: - /* extended instruction */ - int len = sec.readElf8(); + /* extended opcodes */ + int len = (int) sec.readLEB128(); int extIns = sec.readElf8(); if (DEBUG) System.out.println("EXT: " + Utils.hex8(extIns)); switch(extIns) { case DW_LNE_end_sequence: endSequence = true; + lineData.add(new LineEntry(lineLine, lineAddress, lineFile)); + + lineAddress = 0; + lineFile = 1; + lineLine = 1; + lineColumn = 0; + isStatement = defaultIsStmt != 0; + isBasicBlock = false; + if (DEBUG) System.out.println("Line: End sequence executed!!!"); break; - case DW_LNE_define_file: - if (DEBUG) System.out.println("Line: Should define a file!!!!"); - break; case DW_LNE_set_address: - if (len == 2) - lineAddress = sec.readElf8(); - if (len == 3) lineAddress = sec.readElf16(); - if (len == 5) - lineAddress = sec.readElf32(); if (DEBUG) System.out.println("Line: Set address to: " + Utils.hex16(lineAddress) + " (len: " + len + ")"); break; + case DW_LNE_define_file: + /* XXX TODO Implement me */ + if (DEBUG) System.out.println("Line: Should define a file!!!!"); + break; case DW_LNE_set_discriminator: // DWARF 4.0? /* currently just read it but ignore it - TODO: use this info */ - sec.readLEB128(); + /*reg_discriminator = */sec.readElf8(); break; + default: + /* XXX TODO Implement me */ } break; case DW_LNS_copy: /* copy data to matrix... */ if (DEBUG) System.out.println("Line: copy data (" + lineLine + "," + Utils.hex16(lineAddress) + ") to matrix..."); - lineData.add(new LineEntry(lineLine, lineAddress)); + lineData.add(new LineEntry(lineLine, lineAddress, lineFile)); isBasicBlock = false; break; case DW_LNS_advance_pc: long add = sec.readLEB128(); - lineAddress += add * minOpLen; + lineAddress += minOpLen * add; if (DEBUG) System.out.println("Line: Increased address to: " + Utils.hex16(lineAddress)); break; case DW_LNS_advance_line: @@ -291,21 +309,40 @@ private void readLines(ELFSection sec) { break; case DW_LNS_const_add_pc: if (DEBUG) System.out.println("Line: *** Should add const to PC - but how much - same as FF??"); + { + int adjustedOpcode = 255 - opcodeBase; + int operationAdvance = adjustedOpcode / lineRange; + lineAddress += minOpLen * operationAdvance; + } + break; case DW_LNS_fixed_advance_pc: int incr = sec.readElf16(); lineAddress += incr; if (DEBUG) System.out.println("Line: *** Increased address to: " + Utils.hex16(lineAddress)); break; + case DW_LNS_set_prologue_end: + /*reg_prologue_end = true;*/ + break; + case DW_LNS_set_epilogue_begin: + /*reg_epilogue_begin = true;*/ + break; + case DW_LNS_set_isa: + /*reg_isa = (int) */ sec.readLEB128(); + break; default: if (DEBUG) { - System.out.println("INS: " + Utils.hex8(ins)); + System.out.println("INS: " + Utils.hex8(opCode)); } - int lineInc = lineBase + ((ins - opcodeBase) % lineRange); - int addrInc = (ins - opcodeBase) / lineRange; - lineAddress += addrInc * minOpLen; + + int adjustedOpcode = opCode - opcodeBase; + int operationAdvance = adjustedOpcode / lineRange; + + int lineInc = lineBase + (adjustedOpcode % lineRange); lineLine += lineInc; - lineData.add(new LineEntry(lineLine, lineAddress)); + + lineAddress += minOpLen * operationAdvance; + lineData.add(new LineEntry(lineLine, lineAddress, lineFile)); isBasicBlock = false; if (DEBUG) System.out.println("Line: *** Special operation => addr: " + @@ -386,10 +423,23 @@ public DebugInfo getDebugInfo(int address) { LineData data = lineInfo.get(i); int start = data.lineEntries[0].address; int end = data.lineEntries[data.lineEntries.length - 1].address; + /* XXX ignore all line entries starting on address 0 */ + if (start == 0) continue; + if (address <= end && address >= start) { for (int j = 0; j < data.lineEntries.length; j++) { - if (data.lineEntries[j].address >= address) { - return new DebugInfo(data.lineEntries[j].line, null, data.sourceFiles[0], "* not available"); + LineEntry lineEntry = data.lineEntries[j]; + int startEntry = lineEntry.address; + int endEntry; + if (j+1 < data.lineEntries.length) { + endEntry = data.lineEntries[j+1].address-1; + } else { + /* do not match prologue entries */ + continue; + } + if (address >= startEntry && + address <= endEntry) { + return new DebugInfo(lineEntry.line, null, data.sourceFiles[lineEntry.file-1], "* not available"); } } } @@ -415,4 +465,51 @@ public DebugInfo getDebugInfo(int address) { return sourceFilesArray; } + + public static void main(String[] args) throws Exception { + /* This method goes through all possible executable addresses, and + * generates an output comparable to that of msp430-addr2line. */ + + /* Example usage: + * > java se/sics/mspsim/debug/DwarfReader hello-world.sky > cmp.dwarfmspsim */ + /* Example output: + * 0x00000000 + * ??:0 + * 0x00000001 + * ??:0 + * ... */ + + /* Comparison with msp430-addr2line output example: + * > for A in {0..65535}; do printf "%x\n" $A; done > TMP + * > cat TMP | msp430-addr2line -p -a -s -e hello-world.sky > cmp.addr2line + * > rm TMP + * + * > diff -y --suppress-common-lines cmp.addr2line cmp.dwarfmspsim */ + + ELF elf = ELF.readELF(args[0]); + DwarfReader dwarfReader = new DwarfReader(elf); + dwarfReader.read(); + if (args.length > 1) { + int address = Integer.parseInt(args[1], 16); + DebugInfo debugInfo = dwarfReader.getDebugInfo(address); + if (debugInfo == null) { + System.out.println(String.format("0x%08x", address) + ": " + + "??" + ":" + "0"); + } else { + System.out.println(String.format("0x%08x", address) + ": " + + new File(debugInfo.getFile()).getName() + ":" + debugInfo.getLine()); + } + } else { + for (int address = 0; address <= 0xffff; address++) { + DebugInfo debugInfo = dwarfReader.getDebugInfo(address); + if (debugInfo == null) { + System.out.println(String.format("0x%08x", address) + ": " + + "??" + ":" + "0"); + } else { + System.out.println(String.format("0x%08x", address) + ": " + + new File(debugInfo.getFile()).getName() + ":" + debugInfo.getLine()); + } + } + } + } } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/debug/DwarfReader.java | 195 ++++++++++++++++++++++++-------- 1 files changed, 146 insertions(+), 49 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-04-20 18:43:37
|
The branch "master" has been updated via b0dafb710c566994b9277641c6f83b6bc6387796 (commit) from 3babb8ad546a22260b17924b73de9a731422ccdd (commit) Changed paths: M se/sics/mspsim/cli/DebugCommands.java C079 se/sics/mspsim/core/SimEventListener.java se/sics/mspsim/core/BreakpointException.java M se/sics/mspsim/core/MSP430.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/platform/GenericNode.java - Log ----------------------------------------------------------------- commit b0dafb710c566994b9277641c6f83b6bc6387796 Author: Niclas Finne <nf...@si...> Date: Fri Apr 20 20:42:21 2012 +0200 Updated breakpoints for new memory model diff --git a/se/sics/mspsim/cli/DebugCommands.java b/se/sics/mspsim/cli/DebugCommands.java index d49f5fc..7865d1a 100644 --- a/se/sics/mspsim/cli/DebugCommands.java +++ b/se/sics/mspsim/cli/DebugCommands.java @@ -77,10 +77,14 @@ public int executeCommand(final CommandContext context) { return 1; } monitor = new MemoryMonitor.Adapter() { + private long lastCycles = -1; @Override public void notifyReadBefore(int address, AccessMode mode, AccessType type) { + if (type == AccessType.EXECUTE && cpu.cycles != lastCycles) { context.out.println("*** Break at $" + cpu.getAddressAsString(address)); - cpu.stop(); + cpu.triggBreakpoint(); + lastCycles = cpu.cycles; + } } }; cpu.addWatchPoint(address, monitor); @@ -137,7 +141,7 @@ private void cpuAction(AccessType type, int adr, int data) { context.out.println("*** " + op + " from " + pcStr + ": " + adrStr + " = " + data); if (mode == 10) { - cpu.stop(); + cpu.triggBreakpoint(); } } else { if (length > 1) { @@ -290,6 +294,10 @@ public int executeCommand(CommandContext context) { }); ch.registerCommand("start", new BasicCommand("start the CPU", "") { public int executeCommand(CommandContext context) { + if (cpu.isRunning()) { + context.err.println("cpu already running"); + return 1; + } node.start(); return 0; } diff --git a/se/sics/mspsim/core/BreakpointException.java b/se/sics/mspsim/core/BreakpointException.java new file mode 100644 index 0000000..67f51f7 --- /dev/null +++ b/se/sics/mspsim/core/BreakpointException.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2012, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +package se.sics.mspsim.core; + +public class BreakpointException extends EmulationException { + + private static final long serialVersionUID = 49958825510873400L; + + BreakpointException() { + super("breakpoint"); + } + +} diff --git a/se/sics/mspsim/core/MSP430.java b/se/sics/mspsim/core/MSP430.java index fdfc1e1..9e2e461 100644 --- a/se/sics/mspsim/core/MSP430.java +++ b/se/sics/mspsim/core/MSP430.java @@ -51,6 +51,7 @@ private boolean debug = false; private boolean running = false; + private boolean isBreaking = false; private long sleepRate = 50000; // Debug time - measure cycles @@ -88,31 +89,25 @@ public void cpuloop() throws EmulationException { throw new IllegalStateException("already running"); } setRunning(true); + try { // ??? - power-up should be executed?! time = System.currentTimeMillis(); run(); + } finally { + setRunning(false); + } } private void run() throws EmulationException { - int pc; - while (isRunning()) { - // ------------------------------------------------------------------- - // Debug information - // ------------------------------------------------------------------- - if (debug) { - if (servicedInterrupt >= 0) { - disAsm.disassemble(reg[PC], memory, reg, servicedInterrupt); - } else { - disAsm.disassemble(reg[PC], memory, reg); - } - } + while (!isStopping) { if (cycles > nextOut && !debug) { printCPUSpeed(reg[PC]); nextOut = cycles + 20000007; } - if ((pc = emulateOP(-1)) >= 0) { + int pc = emulateOP(-1); + if (pc >= 0) { if (execCounter != null) { execCounter[pc]++; } @@ -121,6 +116,16 @@ private void run() throws EmulationException { if (tracePos >= trace.length) tracePos = 0; } + // ------------------------------------------------------------------- + // Debug information + // ------------------------------------------------------------------- + if (debug) { + if (servicedInterrupt >= 0) { + disAsm.disassemble(pc, memory, reg, servicedInterrupt); + } else { + disAsm.disassemble(pc, memory, reg); + } + } } /* Just a test to see if it gets down to a reasonable speed */ @@ -138,6 +143,7 @@ private void run() throws EmulationException { // System.out.println("Call to PC = " + reg[PC]); // } } + isStopping = isBreaking = false; } public long step() throws EmulationException { @@ -149,13 +155,8 @@ public long stepInstructions(int count) throws EmulationException { throw new IllegalStateException("step not possible when CPU is running"); } setRunning(true); - // ------------------------------------------------------------------- - // Debug information - // ------------------------------------------------------------------- - - - while (count-- > 0 && isRunning()) { - + try { + while (count-- > 0 && !isStopping) { int pc = emulateOP(-1); if (pc >= 0) { if (execCounter != null) { @@ -166,16 +167,23 @@ public long stepInstructions(int count) throws EmulationException { if (tracePos >= trace.length) tracePos = 0; } - } + + // ------------------------------------------------------------------- + // Debug information + // ------------------------------------------------------------------- if (debug) { if (servicedInterrupt >= 0) { - disAsm.disassemble(reg[PC], memory, reg, servicedInterrupt); + disAsm.disassemble(pc, memory, reg, servicedInterrupt); } else { - disAsm.disassemble(reg[PC], memory, reg); + disAsm.disassemble(pc, memory, reg); + } } } } + } finally { setRunning(false); + } + isStopping = isBreaking = false; return cycles; } @@ -264,6 +272,20 @@ public long stepMicros(long jumpMicros, long executeMicros) throws EmulationExce } } } + + if (isStopping) { + isStopping = false; + if (cycles < maxCycles || (cpuOff && (nextEventCycles < cycles))) { + // Did not complete the execution cycle + lastMicrosDelta -= jumpMicros; + } + if (isBreaking) { + isBreaking = false; + throw new BreakpointException(); + } + lastReturnedMicros = 0; + return 0; + } } if (cpuOff && !(interruptsEnabled && servicedInterrupt == -1 && interruptMax >= 0)) { @@ -283,7 +305,12 @@ public long stepMicros(long jumpMicros, long executeMicros) throws EmulationExce } public void stop() { - setRunning(false); + isStopping = true; + } + + public void triggBreakpoint() { + isBreaking = true; + stop(); } public int getDCOFrequency() { @@ -379,9 +406,13 @@ public void setMap(MapTable map) { } } - public void setRunning(boolean running) { + private void setRunning(boolean running) { if (this.running != running) { this.running = running; + if (running) { + isStopping = false; + isBreaking = false; + } SimEventListener[] listeners = this.simEventListeners; if (listeners != null) { SimEvent.Type type = running ? SimEvent.Type.START : SimEvent.Type.STOP; diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index 8be93f0..2bc6920 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -134,6 +134,7 @@ private Flash flash; boolean isFlashBusy; + boolean isStopping = false; ClockSystem bcs; @@ -998,25 +999,12 @@ public int emulateOP(long maxCycles) throws EmulationException { return -1; } - // This is quite costly... should probably be made more - // efficiently -// CPUMonitor wp = watchPoints[pc]; -// if (wp != null) { -// if (breakpointActive) { -// wp.cpuAction(CPUMonitor.EXECUTE, pc, 0); -// breakpointActive = false; -// return -1; -// } -// // Execute this instruction - this is second call... -// breakpointActive = true; -// } -// wp = globalMonitor; -// if (wp != null) { -// wp.cpuAction(CPUMonitor.EXECUTE, pc, 0); -// } - int pcBefore = pc; instruction = currentSegment.read(pc, AccessMode.WORD, AccessType.EXECUTE); + if (isStopping) { + // Signaled to stop the execution before performing the instruction + return -2; + } int ext3_0 = 0; boolean repeatsInDstReg = false; boolean wordx20 = false; diff --git a/se/sics/mspsim/platform/GenericNode.java b/se/sics/mspsim/platform/GenericNode.java index e75eee4..156ee81 100644 --- a/se/sics/mspsim/platform/GenericNode.java +++ b/se/sics/mspsim/platform/GenericNode.java @@ -279,7 +279,7 @@ public void start() { } public void stop() { - cpu.setRunning(false); + cpu.stop(); } public void step() throws EmulationException { @@ -288,6 +288,13 @@ public void step() throws EmulationException { } } + // A step that will break out of breakpoints! + public void step(int nr) throws EmulationException { + if (!cpu.isRunning()) { + cpu.stepInstructions(nr); + } + } + public ELF loadFirmware(URL url, int[] memory) throws IOException { DataInputStream inputStream = new DataInputStream(url.openStream()); ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); @@ -307,7 +314,9 @@ public ELF loadFirmware(String name, int[] memory) throws IOException { } public ELF loadFirmware(ELF elf, int[] memory) { + if (cpu.isRunning()) { stop(); + } this.elf = elf; elf.loadPrograms(memory); MapTable map = elf.getMap(); @@ -318,13 +327,6 @@ public ELF loadFirmware(ELF elf, int[] memory) { return elf; } - // A step that will break out of breakpoints! - public void step(int nr) throws EmulationException { - if (!cpu.isRunning()) { - cpu.stepInstructions(nr); - } - } - public int getConfiguration(int param) { return 0; } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/cli/DebugCommands.java | 14 ++- ...EventListener.java => BreakpointException.java} | 26 ++---- se/sics/mspsim/core/MSP430.java | 99 +++++++++++++------- se/sics/mspsim/core/MSP430Core.java | 22 +---- se/sics/mspsim/platform/GenericNode.java | 20 ++-- 5 files changed, 99 insertions(+), 82 deletions(-) copy se/sics/mspsim/core/{SimEventListener.java => BreakpointException.java} (79%) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-04-19 15:03:45
|
The branch "master" has been updated via 3babb8ad546a22260b17924b73de9a731422ccdd (commit) via b96722e61f3bcd0994939da36ef6b5bd2b22f11c (commit) from 8185d7b60c0fe3a694855f6fb7e2f0b7b0a4b502 (commit) Changed paths: M se/sics/mspsim/core/DMA.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/core/USART.java - Log ----------------------------------------------------------------- commit 3babb8ad546a22260b17924b73de9a731422ccdd Author: Niclas Finne <nf...@si...> Date: Thu Apr 19 10:41:50 2012 +0200 Fixed too early clear notification when using DMA. diff --git a/se/sics/mspsim/core/DMA.java b/se/sics/mspsim/core/DMA.java index 870a6b0..57d4159 100644 --- a/se/sics/mspsim/core/DMA.java +++ b/se/sics/mspsim/core/DMA.java @@ -134,7 +134,8 @@ public void trigger(DMATrigger trigger, int index) { if (DEBUG) log("DMA Triggered reading from: " + currentSourceAddress + " => " + data + " " + (char) data + " size:" + size + " index:" + index); - trigger.clearDMATrigger(index); + // flag already cleared by the memory read above +// trigger.clearDMATrigger(index); DMA.this.cpu.currentSegment.write(currentDestinationAddress, data, Memory.AccessMode.BYTE); currentSourceAddress += srcIncr; @@ -160,6 +161,16 @@ public void interruptServiced(int vector) { public String getName() { return "DMA Channel " + channelNo; } + + public String info() { + return getName() + (enable ? " Enabled " : " Disabled") + + " Index: " + triggerIndex + " Trigger: " + trigger + + "\n current source: 0x" + + cpu.getAddressAsString(currentSourceAddress) + + " destination: 0x" + + cpu.getAddressAsString(currentDestinationAddress) + + " size: " + (storedSize - size) + "/" + storedSize; + } } private Channel channels[] = new Channel[3]; @@ -240,4 +251,14 @@ public int read(int address, boolean word, long cycles) { return c.read(address & 7); } } + + public String info() { + StringBuilder sb = new StringBuilder(); + sb.append(" DMACTL0: 0x" + Utils.hex16(dmactl0) + " DMACTL1: 0x" + Utils.hex16(dmactl1)); + for (Channel c : channels) { + sb.append("\n ").append(c.info()); + } + return sb.toString(); + } + } diff --git a/se/sics/mspsim/core/USART.java b/se/sics/mspsim/core/USART.java index d27f621..69debad 100644 --- a/se/sics/mspsim/core/USART.java +++ b/se/sics/mspsim/core/USART.java @@ -91,6 +91,8 @@ private int nextTXByte = -1; private int txShiftReg = -1; private boolean transmitting = false; + private int nextRXByte = -1; + private boolean receiving = false; private MSP430Core cpu; private SFR sfr; @@ -111,7 +113,6 @@ /* DMA controller that needs to be called at certain times */ private DMA dma; - private int dmaIndex; private TimeEvent txTrigger = new TimeEvent(0) { public void execute(long t) { @@ -120,6 +121,12 @@ public void execute(long t) { } }; + private TimeEvent rxTrigger = new TimeEvent(0) { + public void execute(long t) { + handleReceive(); + } + }; + /** * Creates a new <code>USART</code> instance. * @@ -268,7 +275,7 @@ public void write(int address, int data, boolean word, long cycles) { updateBaudRate(); break; case UTXBUF: - if (DEBUG) log(": USART_UTXBUF:" + (char) data + " = " + data + "\n"); + if (DEBUG) log(" USART_UTXBUF: " + data + " " + (data > 32 ? (char)data : '.')); if (txEnabled || (spiMode && rxEnabled)) { // Interruptflag not set! clrBitIFG(utxifg); @@ -368,7 +375,7 @@ public void interruptServiced(int vector) { private void handleTransmit(long cycles) { if (cpu.getMode() >= MSP430Core.MODE_LPM3) { - System.out.println(getName() + " Warning: USART transmission during LPM!!! " + nextTXByte); + logw("Warning: USART transmission during LPM!!! " + nextTXByte); } if (transmitting) { @@ -390,9 +397,9 @@ private void handleTransmit(long cycles) { if (nextTXByte != -1) { txShiftReg = nextTXByte; nextTXByte = -1; + transmitting = true; /* txbuf always empty after this */ setBitIFG(utxifg); - transmitting = true; nextTXReady = cycles + tickPerByte + 1; cpu.scheduleCycleEvent(txTrigger, nextTXReady); } @@ -407,7 +414,7 @@ private void handleTransmit(long cycles) { public boolean isReceiveFlagCleared() { - return (getIFG() & urxifg) == 0; + return !receiving && (getIFG() & urxifg) == 0; } // A byte have been received! @@ -415,25 +422,35 @@ public boolean isReceiveFlagCleared() { // is ready for next byte (readyForReceive) that respects the current speed public void byteReceived(int b) { if (!rxEnabled) return; - if (DEBUG) { - log(" byteReceived: " + b + " " + (char) b); + log(" byteReceived: " + b + " " + (b > 32 ? (char)b : '.')); } - urxbuf = b & 0xff; - // Indicate interrupt also! + nextRXByte = b & 0xff; + if (!receiving) { + receiving = true; + cpu.scheduleCycleEvent(rxTrigger, cpu.cycles + 1); + } + } + + private void handleReceive() { + receiving = false; + urxbuf = nextRXByte; + + // Indicate interrupt! setBitIFG(urxifg); + if (DEBUG) { // Check if the IE flag is enabled! - same as the IFlag to indicate! if (isIEBitsSet(urxifg)) { - if (DEBUG) { log(" flagging receive interrupt "); } } } public String info() { - return "UTXIE: " + isIEBitsSet(utxifg) + " URXIE:" + isIEBitsSet(urxifg) + "\n" + - "UTXIFG: " + ((getIFG() & utxifg) > 0) + " URXIFG:" + ((getIFG() & urxifg) > 0); + return " UTXIE: " + isIEBitsSet(utxifg) + " URXIE: " + isIEBitsSet(urxifg) + "\n" + + " UTXIFG: " + ((getIFG() & utxifg) > 0) + " URXIFG: " + ((getIFG() & urxifg) > 0) + "\n" + + " Baudrate: " + baudRate + " bps Cycles per byte: " + tickPerByte; } public boolean getDMATriggerState(int index) { commit b96722e61f3bcd0994939da36ef6b5bd2b22f11c Author: Niclas Finne <nf...@si...> Date: Wed Apr 18 19:08:56 2012 +0200 Added methods to access Chip and IOUnit by type and not only name diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index eac23ee..8be93f0 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -367,15 +367,29 @@ public Chip getChip(String name) { return null; } - public Chip getChip(Class<? extends Chip> type) { + public <T extends Chip> T getChip(Class<T> type) { for(Chip chip : chips) { if (type.isInstance(chip)) { - return chip; + return type.cast(chip); + } + } + return null; + } + + public <T extends Chip> T getChip(Class<T> type, String name) { + for(Chip chip : chips) { + if (type.isInstance(chip) && + (name.equalsIgnoreCase(chip.getID()) || name.equalsIgnoreCase(chip.getName()))) { + return type.cast(chip); } } return null; } + public Chip[] getChips() { + return chips.toArray(new Chip[chips.size()]); + } + public Loggable[] getLoggables() { Loggable[] ls = new Loggable[ioUnits.size() + chips.size()]; for (int i = 0; i < ioUnits.size(); i++) { @@ -395,10 +409,6 @@ public Loggable getLoggable(String name) { return l; } - public Chip[] getChips() { - return chips.toArray(new Chip[chips.size()]); - } - public boolean hasWatchPoint(int address) { Memory mem = memorySegments[address >> 8]; if (mem instanceof WatchedMemory) { @@ -722,9 +732,29 @@ public IOUnit getIOUnit(String name) { return null; } + public <T> T getIOUnit(Class<T> type) { + for (IOUnit ioUnit : ioUnits) { + if (type.isInstance(ioUnit)) { + return type.cast(ioUnit); + } + } + return null; + } + + public <T> T getIOUnit(Class<T> type, String name) { + for (IOUnit ioUnit : ioUnits) { + if (type.isInstance(ioUnit) + && (name.equalsIgnoreCase(ioUnit.getID()) + || name.equalsIgnoreCase(ioUnit.getName()))) { + return type.cast(ioUnit); + } + } + return null; + } + private void resetIOUnits() { - for (int i = 0, n = ioUnits.size(); i < n; i++) { - ioUnits.get(i).reset(RESET_POR); + for (IOUnit ioUnit : ioUnits) { + ioUnit.reset(RESET_POR); } } @@ -1987,9 +2017,10 @@ public int emulateOP(long maxCycles) throws EmulationException { writeRegister(SR, sr); break; default: - logw("DoubleOperand not implemented: op = " + op + " at " + pc); + String address = getAddressAsString(pc); + logw("DoubleOperand not implemented: op = " + Integer.toHexString(op) + " at " + address); if (EXCEPTION_ON_BAD_OPERATION) { - EmulationException ex = new EmulationException("Bad operation: " + op + " at " + pc); + EmulationException ex = new EmulationException("Bad operation: $" + Integer.toHexString(op) + " at $" + address); ex.initCause(new Throwable("" + pc)); throw ex; } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/core/DMA.java | 23 ++++++++++++++- se/sics/mspsim/core/MSP430Core.java | 55 +++++++++++++++++++++++++++------- se/sics/mspsim/core/USART.java | 51 +++++++++++++++++++++----------- 3 files changed, 99 insertions(+), 30 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-04-16 23:30:59
|
The branch "master" has been updated via 8185d7b60c0fe3a694855f6fb7e2f0b7b0a4b502 (commit) via bc1027e494d91bb6ba0e18cd3222d6c4ed0bc838 (commit) via 6c7ccde06d232365ffa628d3097e49dad7640483 (commit) via 6ab96626869ab6f3831a66f91dbdeea8765ba265 (commit) via eb101681501f46aea9eb9d9eedb3f2ee52749a64 (commit) via 5648fd5b438c49aa96b8b3a9f4cba49eecd29422 (commit) via 9b31c5141aa32c0a530dcc71f589b6d35f3ae987 (commit) via abca9b4c39a0c50a4a39904745cb2aae80b735df (commit) via 7df8477a3f4765520e5e04d069c33157358b00cf (commit) via c527234859ffa2e880692c130a48eb9be62ea13b (commit) from ecb98b3839c5862c57a0641490f18ad1a3cbc4c5 (commit) Changed paths: M se/sics/mspsim/chip/CC2420.java C073 se/sics/mspsim/config/MSP430f149Config.java se/sics/mspsim/chip/ChannelListener.java M se/sics/mspsim/chip/Leds.java M se/sics/mspsim/chip/Memory.java M se/sics/mspsim/chip/PacketListener.java M se/sics/mspsim/chip/RFListener.java M se/sics/mspsim/chip/RFSource.java M se/sics/mspsim/chip/TR1001.java M se/sics/mspsim/cli/MiscCommands.java M se/sics/mspsim/cli/ProfilerCommands.java M se/sics/mspsim/core/Chip.java M se/sics/mspsim/core/EventListener.java M se/sics/mspsim/core/GenericUSCI.java M se/sics/mspsim/core/IOPort.java M se/sics/mspsim/core/IOUnit.java M se/sics/mspsim/core/MSP430.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/core/MemoryMonitor.java M se/sics/mspsim/core/RegisterMonitor.java M se/sics/mspsim/core/StateChangeListener.java M se/sics/mspsim/core/USART.java M se/sics/mspsim/core/USARTListener.java M se/sics/mspsim/core/USARTSource.java M se/sics/mspsim/core/USCI.java M se/sics/mspsim/platform/sky/CC2420Node.java M se/sics/mspsim/platform/sky/RadioWrapper.java M se/sics/mspsim/platform/ti/Exp5438Node.java M se/sics/mspsim/platform/tyndall/TyndallNode.java M se/sics/mspsim/platform/z1/Z1Node.java M se/sics/mspsim/ui/SerialMon.java M se/sics/mspsim/util/ELF.java M se/sics/mspsim/util/NetworkConnection.java M se/sics/mspsim/util/ProxySupport.java M se/sics/mspsim/util/SimpleProfiler.java M se/sics/mspsim/util/Test.java - Log ----------------------------------------------------------------- commit 8185d7b60c0fe3a694855f6fb7e2f0b7b0a4b502 Author: Niclas Finne <nf...@si...> Date: Mon Apr 16 14:19:24 2012 +0200 removed obsolete method diff --git a/se/sics/mspsim/core/IOUnit.java b/se/sics/mspsim/core/IOUnit.java index 7efb39c..6bfea7b 100644 --- a/se/sics/mspsim/core/IOUnit.java +++ b/se/sics/mspsim/core/IOUnit.java @@ -99,23 +99,12 @@ public void reset(int type) { // write // write a value to the IO unit - public abstract void write(int address, int value, boolean word, - long cycles); + public abstract void write(int address, int value, boolean word, long cycles); // read // read a value from the IO unit public abstract int read(int address, boolean word, long cycles); - // Utility function for converting 16 bits data to correct return - // value depending on address alignment and word/byte mode - public static int return16(int address, int data, boolean word) { - if (word) return data; - // First byte => low byte - if ((address & 1) == 0) return data & 0xff; - // Second byte => hi byte - return (data >> 8) & 0xff; - } - public String getID() { return id; } commit bc1027e494d91bb6ba0e18cd3222d6c4ed0bc838 Author: Niclas Finne <nf...@si...> Date: Fri Apr 13 19:01:37 2012 +0200 removed obsolete method diff --git a/se/sics/mspsim/core/IOPort.java b/se/sics/mspsim/core/IOPort.java index fc28261..6500a62 100644 --- a/se/sics/mspsim/core/IOPort.java +++ b/se/sics/mspsim/core/IOPort.java @@ -191,15 +191,6 @@ public synchronized void removePortListener(PortListener oldListener) { portListener = PortListenerProxy.removePortListener(portListener, oldListener); } - @Deprecated - public synchronized void setPortListener(PortListener listener) { - if (listener != null) { - addPortListener(listener); - } else { - portListener = null; - } - } - public void setTimerCapture(Timer timer, int pin) { if (DEBUG) { log("Setting timer capture for pin: " + pin); commit 6c7ccde06d232365ffa628d3097e49dad7640483 Author: Niclas Finne <nf...@si...> Date: Fri Apr 13 18:28:55 2012 +0200 Added proxy for EventListener to support multiple listeners diff --git a/se/sics/mspsim/cli/ProfilerCommands.java b/se/sics/mspsim/cli/ProfilerCommands.java index 110b4b4..edd6f25 100644 --- a/se/sics/mspsim/cli/ProfilerCommands.java +++ b/se/sics/mspsim/cli/ProfilerCommands.java @@ -164,6 +164,7 @@ public int executeCommand(CommandContext context) { ch.registerCommand("logevents", new BasicAsyncCommand("log events", "[chips...]") { Chip[] chips; + EventListener eventListener; public int executeCommand(final CommandContext context) { if (context.getArgumentCount() == 0) { context.out.println("Available chips:"); @@ -187,19 +188,19 @@ public int executeCommand(final CommandContext context) { return 1; } } - EventListener listener = new EventListener() { + eventListener = new EventListener() { public void event(EventSource source, String event, Object data) { context.out.println("Event:" + source.getName() + ":" + event); } }; for (Chip chip : chips) { - chip.setEventListener(listener); + chip.addEventListener(eventListener); } return 0; } public void stopCommand(CommandContext context) { for (Chip chip : chips) { - chip.setEventListener(null); + chip.removeEventListener(eventListener); } } }); diff --git a/se/sics/mspsim/core/Chip.java b/se/sics/mspsim/core/Chip.java index 250e78d..b22c7c9 100644 --- a/se/sics/mspsim/core/Chip.java +++ b/se/sics/mspsim/core/Chip.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2007-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,16 +27,12 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * * Chip * * Author : Joakim Eriksson * Created : 17 jan 2008 - * Updated : $Date$ - * $Revision$ */ package se.sics.mspsim.core; import java.io.PrintStream; @@ -130,15 +126,20 @@ protected void setModeNames(String[] names) { modeNames = names; } + public synchronized void addEventListener(EventListener listener) { + eventListener = EventListener.Proxy.INSTANCE.add(eventListener, listener); + sendEvents = eventListener != null; + } - public void setEventListener(EventListener e) { - eventListener = e; + public synchronized void removeEventListener(EventListener listener) { + eventListener = EventListener.Proxy.INSTANCE.add(eventListener, listener); sendEvents = eventListener != null; } protected void sendEvent(String event, Object data) { - if (eventListener != null) { - eventListener.event(this, event, data); + EventListener listener = this.eventListener; + if (listener != null) { + listener.event(this, event, data); } } diff --git a/se/sics/mspsim/core/EventListener.java b/se/sics/mspsim/core/EventListener.java index a6950a8..848bbc2 100644 --- a/se/sics/mspsim/core/EventListener.java +++ b/se/sics/mspsim/core/EventListener.java @@ -1,5 +1,21 @@ package se.sics.mspsim.core; +import se.sics.mspsim.util.ProxySupport; public interface EventListener { + public void event(EventSource source, String event, Object data); + + public static class Proxy extends ProxySupport<EventListener> implements EventListener { + public static final Proxy INSTANCE = new Proxy(); + + @Override + public void event(EventSource source, String event, Object data) { + EventListener[] listeners = this.listeners; + for(EventListener listener : listeners) { + listener.event(source, event, data); + } + } + + } + } diff --git a/se/sics/mspsim/util/SimpleProfiler.java b/se/sics/mspsim/util/SimpleProfiler.java index 07e513b..e800913 100644 --- a/se/sics/mspsim/util/SimpleProfiler.java +++ b/se/sics/mspsim/util/SimpleProfiler.java @@ -520,8 +520,8 @@ public void addProfileTag(String tag, Chip chip, String start, startTags.put(start, tagEntry); endTags.put(end, tagEntry); tagProfiles.put(tag, tagEntry); - chip.setEventListener(this); - chip2.setEventListener(this); + chip.addEventListener(this); + chip2.addEventListener(this); } public void event(EventSource source, String event, Object data) { commit 6ab96626869ab6f3831a66f91dbdeea8765ba265 Author: Niclas Finne <nf...@si...> Date: Fri Apr 13 18:28:38 2012 +0200 Added proxies for USARTListener and StateChangeListener to support multiple listeners diff --git a/se/sics/mspsim/chip/Leds.java b/se/sics/mspsim/chip/Leds.java index 0e9d1bc..8a13711 100644 --- a/se/sics/mspsim/chip/Leds.java +++ b/se/sics/mspsim/chip/Leds.java @@ -45,7 +45,6 @@ import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.MSP430Core; import se.sics.mspsim.core.StateChangeListener; -import se.sics.mspsim.util.ArrayUtils; import se.sics.mspsim.util.Utils; public class Leds extends Chip { @@ -53,7 +52,7 @@ private final int[] ledColors; private int leds; - private StateChangeListener[] stateListeners; + private StateChangeListener stateListener; public Leds(MSP430Core cpu, int[] ledColors) { super("Leds", cpu); @@ -89,20 +88,18 @@ public int getLedsCount() { } private void fireStateChanged(int oldState, int newState) { - StateChangeListener[] listeners = this.stateListeners; - if (listeners != null) { - for(StateChangeListener listener : listeners) { + StateChangeListener listener = this.stateListener; + if (listener != null) { listener.stateChanged(this, oldState, newState); } } - } - public synchronized void addStateChangeListener(StateChangeListener l) { - this.stateListeners = (StateChangeListener[]) ArrayUtils.add(StateChangeListener.class, this.stateListeners, l); + public synchronized void addStateChangeListener(StateChangeListener listener) { + stateListener = StateChangeListener.Proxy.INSTANCE.add(stateListener, listener); } - public synchronized void removeStateChangeListener(StateChangeListener l) { - this.stateListeners = (StateChangeListener[]) ArrayUtils.remove(this.stateListeners, l); + public synchronized void removeStateChangeListener(StateChangeListener listener) { + stateListener = StateChangeListener.Proxy.INSTANCE.remove(stateListener, listener); } public int getModeMax() { diff --git a/se/sics/mspsim/chip/TR1001.java b/se/sics/mspsim/chip/TR1001.java index 2ed13f3..00e5d9c 100644 --- a/se/sics/mspsim/chip/TR1001.java +++ b/se/sics/mspsim/chip/TR1001.java @@ -61,7 +61,7 @@ public TR1001(MSP430Core cpu, USART usart) { this.usart = usart; setModeNames(MODE_NAMES); setMode(MODE_TXRX_OFF); - usart.setUSARTListener(new USARTListener() { + usart.addUSARTListener(new USARTListener() { public void dataReceived(USARTSource source, int data) { RFListener listener = rfListener; diff --git a/se/sics/mspsim/core/Chip.java b/se/sics/mspsim/core/Chip.java index 857c434..250e78d 100644 --- a/se/sics/mspsim/core/Chip.java +++ b/se/sics/mspsim/core/Chip.java @@ -57,7 +57,7 @@ protected final MSP430Core cpu; private OperatingModeListener[] omListeners; - private StateChangeListener[] scListeners; + private StateChangeListener stateListener; private ConfigurationChangeListener[] ccListeners; private EventListener eventListener; @@ -86,27 +86,27 @@ public void notifyReset() { } public void addOperatingModeListener(OperatingModeListener listener) { - omListeners = (OperatingModeListener[]) ArrayUtils.add(OperatingModeListener.class, omListeners, listener); + omListeners = ArrayUtils.add(OperatingModeListener.class, omListeners, listener); } public void removeOperatingModeListener(OperatingModeListener listener) { - omListeners = (OperatingModeListener[]) ArrayUtils.remove(omListeners, listener); + omListeners = ArrayUtils.remove(omListeners, listener); } - public void addStateChangeListener(StateChangeListener listener) { - scListeners = (StateChangeListener[]) ArrayUtils.add(StateChangeListener.class, scListeners, listener); + public synchronized void addStateChangeListener(StateChangeListener listener) { + stateListener = StateChangeListener.Proxy.INSTANCE.add(stateListener, listener); } - public void removeStateChangeListener(StateChangeListener listener) { - scListeners = (StateChangeListener[]) ArrayUtils.remove(scListeners, listener); + public synchronized void removeStateChangeListener(StateChangeListener listener) { + stateListener = StateChangeListener.Proxy.INSTANCE.remove(stateListener, listener); } public void addConfigurationChangeListener(ConfigurationChangeListener listener) { - ccListeners = (ConfigurationChangeListener[]) ArrayUtils.add(ConfigurationChangeListener.class, ccListeners, listener); + ccListeners = ArrayUtils.add(ConfigurationChangeListener.class, ccListeners, listener); } public void removeConfigurationChangeListener(ConfigurationChangeListener listener) { - ccListeners = (ConfigurationChangeListener[]) ArrayUtils.remove(ccListeners, listener); + ccListeners = ArrayUtils.remove(ccListeners, listener); } @@ -172,11 +172,9 @@ protected void stateChanged(int newState) { int oldState = chipState; chipState = newState; /* inform listeners */ - StateChangeListener[] listeners = scListeners; - if (listeners != null) { - for (int i = 0, n = listeners.length; i < n; i++) { - listeners[i].stateChanged(this, oldState, chipState); - } + StateChangeListener listener = stateListener; + if (listener != null) { + listener.stateChanged(this, oldState, chipState); } } } diff --git a/se/sics/mspsim/core/GenericUSCI.java b/se/sics/mspsim/core/GenericUSCI.java index ff9c795..7c09c43 100644 --- a/se/sics/mspsim/core/GenericUSCI.java +++ b/se/sics/mspsim/core/GenericUSCI.java @@ -29,7 +29,7 @@ public static final int SWRST = 0x01; - private USARTListener listener; + private USARTListener usartListener; private int ubr0; private int ubr1; @@ -148,6 +148,7 @@ private void handleTransmit(long cycles) { if (transmitting) { /* in this case we have shifted out the last character */ + USARTListener listener = this.usartListener; if (listener != null && txShiftReg != -1) { listener.dataReceived(this, txShiftReg); } @@ -331,8 +332,14 @@ public int read(int address, boolean word, long cycles) { } /* reuse USART listener API for USCI */ - public void setUSARTListener(USARTListener listener) { - this.listener = listener; + @Override + public synchronized void addUSARTListener(USARTListener listener) { + usartListener = USARTListener.Proxy.INSTANCE.add(usartListener, listener); + } + + @Override + public synchronized void removeUSARTListener(USARTListener listener) { + usartListener = USARTListener.Proxy.INSTANCE.remove(usartListener, listener); } /* default behavior assumes UART/SPI config */ diff --git a/se/sics/mspsim/core/IOUnit.java b/se/sics/mspsim/core/IOUnit.java index 8aad85f..7efb39c 100644 --- a/se/sics/mspsim/core/IOUnit.java +++ b/se/sics/mspsim/core/IOUnit.java @@ -43,8 +43,6 @@ import java.io.PrintStream; -import se.sics.mspsim.util.ArrayUtils; - public abstract class IOUnit implements InterruptHandler, Loggable { int[] memory; @@ -53,7 +51,7 @@ protected final String id; protected final String name; - private StateChangeListener[] scListeners; + private StateChangeListener stateListener; private int ioState; protected EmulationLogger logger; @@ -72,11 +70,11 @@ public IOUnit(String id, String name, int[] memory, int offset) { } public void addStateChangeListener(StateChangeListener listener) { - scListeners = (StateChangeListener[]) ArrayUtils.add(StateChangeListener.class, scListeners, listener); + stateListener = StateChangeListener.Proxy.INSTANCE.add(stateListener, listener); } public void removeStateChangeListener(StateChangeListener listener) { - scListeners = (StateChangeListener[]) ArrayUtils.remove(scListeners, listener); + stateListener = StateChangeListener.Proxy.INSTANCE.remove(stateListener, listener); } @@ -89,11 +87,9 @@ protected void stateChanged(int newState, boolean forceCallback) { int oldState = ioState; ioState = newState; /* inform listeners */ - StateChangeListener[] listeners = scListeners; - if (listeners != null) { - for (int i = 0, n = listeners.length; i < n; i++) { - listeners[i].stateChanged(this, oldState, ioState); - } + StateChangeListener listener = stateListener; + if (listener != null) { + listener.stateChanged(this, oldState, ioState); } } } diff --git a/se/sics/mspsim/core/StateChangeListener.java b/se/sics/mspsim/core/StateChangeListener.java index ee221b3..cd43794 100644 --- a/se/sics/mspsim/core/StateChangeListener.java +++ b/se/sics/mspsim/core/StateChangeListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Swedish Institute of Computer Science. + * Copyright (c) 2010-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,19 +28,16 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * * StateChangeListener * * Authors : Joakim Eriksson, Niclas Finne * Created : 17 jul 2010 - * Updated : $Date$ - * $Revision$ */ package se.sics.mspsim.core; +import se.sics.mspsim.util.ProxySupport; /** * @@ -49,4 +46,16 @@ public void stateChanged(Object source, int oldState, int newState); + public static class Proxy extends ProxySupport<StateChangeListener> implements StateChangeListener { + public static final Proxy INSTANCE = new Proxy(); + + @Override + public void stateChanged(Object source, int oldState, int newState) { + StateChangeListener[] listeners = this.listeners; + for(StateChangeListener listener : listeners) { + listener.stateChanged(source, oldState, newState); + } + } + + } } diff --git a/se/sics/mspsim/core/USART.java b/se/sics/mspsim/core/USART.java index dfedc95..d27f621 100644 --- a/se/sics/mspsim/core/USART.java +++ b/se/sics/mspsim/core/USART.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2007-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,16 +27,12 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * * USART * * Author : Joakim Eriksson * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date$ - * $Revision$ */ package se.sics.mspsim.core; @@ -82,7 +78,7 @@ public static final int UTCTL_TXEMPTY = 0x01; public static final int UTCTL_URXSE = 0x08; - private USARTListener listener; + private USARTListener usartListener; private int utxifg; private int urxifg; @@ -208,8 +204,14 @@ private boolean isIEBitsSet(int bits) { return sfr.isIEBitsSet(uartID, bits); } - public void setUSARTListener(USARTListener listener) { - this.listener = listener; + @Override + public synchronized void addUSARTListener(USARTListener listener) { + usartListener = USARTListener.Proxy.INSTANCE.add(usartListener, listener); + } + + @Override + public synchronized void removeUSARTListener(USARTListener listener) { + usartListener = USARTListener.Proxy.INSTANCE.remove(usartListener, listener); } // Only 8 bits / read! @@ -371,6 +373,7 @@ private void handleTransmit(long cycles) { if (transmitting) { /* in this case we have shifted out the last character */ + USARTListener listener = this.usartListener; if (listener != null && txShiftReg != -1) { listener.dataReceived(this, txShiftReg); } diff --git a/se/sics/mspsim/core/USARTListener.java b/se/sics/mspsim/core/USARTListener.java index fef17d2..0d02805 100644 --- a/se/sics/mspsim/core/USARTListener.java +++ b/se/sics/mspsim/core/USARTListener.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2007-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,21 +27,33 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * * USARTListener * * Author : Joakim Eriksson * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date$ - * $Revision$ */ package se.sics.mspsim.core; +import se.sics.mspsim.util.ProxySupport; public interface USARTListener { + public static final int RXFLAG_CLEARED = 1; public void dataReceived(USARTSource source, int data); + + public static class Proxy extends ProxySupport<USARTListener> implements USARTListener { + public static final Proxy INSTANCE = new Proxy(); + + @Override + public void dataReceived(USARTSource source, int data) { + USARTListener[] listeners = this.listeners; + for(USARTListener listener : listeners) { + listener.dataReceived(source, data); + } + } + + } + } diff --git a/se/sics/mspsim/core/USARTSource.java b/se/sics/mspsim/core/USARTSource.java index a84e8f8..fd62e59 100644 --- a/se/sics/mspsim/core/USARTSource.java +++ b/se/sics/mspsim/core/USARTSource.java @@ -2,7 +2,11 @@ public interface USARTSource { - public void setUSARTListener(USARTListener listener); + public void addUSARTListener(USARTListener listener); + public void removeUSARTListener(USARTListener listener); + + public void addStateChangeListener(StateChangeListener listener); + public void removeStateChangeListener(StateChangeListener listener); /* for input into this UART */ public boolean isReceiveFlagCleared(); diff --git a/se/sics/mspsim/core/USCI.java b/se/sics/mspsim/core/USCI.java index 1faba12..03de583 100644 --- a/se/sics/mspsim/core/USCI.java +++ b/se/sics/mspsim/core/USCI.java @@ -87,7 +87,7 @@ public static final int UTCTL_URXSE = 0x08; public static final int USCI_BUSY = 0x01; - private USARTListener listener; + private USARTListener usartListener; private int utxifg; private int urxifg; @@ -235,8 +235,14 @@ private boolean isIEBitsSet(int bits) { } /* reuse USART listener API for USCI */ - public void setUSARTListener(USARTListener listener) { - this.listener = listener; + @Override + public synchronized void addUSARTListener(USARTListener listener) { + usartListener = USARTListener.Proxy.INSTANCE.add(usartListener, listener); + } + + @Override + public synchronized void removeUSARTListener(USARTListener listener) { + usartListener = USARTListener.Proxy.INSTANCE.remove(usartListener, listener); } // Only 8 bits / read! @@ -414,6 +420,7 @@ private void handleTransmit(long cycles) { if (transmitting) { /* in this case we have shifted out the last character */ + USARTListener listener = this.usartListener; if (listener != null && txShiftReg != -1) { listener.dataReceived(this, txShiftReg); } diff --git a/se/sics/mspsim/platform/sky/CC2420Node.java b/se/sics/mspsim/platform/sky/CC2420Node.java index b2a6815..22c9f9c 100644 --- a/se/sics/mspsim/platform/sky/CC2420Node.java +++ b/se/sics/mspsim/platform/sky/CC2420Node.java @@ -104,7 +104,7 @@ public void setupNodePorts() { radio.setFIFOPPort(port1, CC2420_FIFOP); radio.setFIFOPort(port1, CC2420_FIFO); - ((USART) usart0).setUSARTListener(this); + ((USART) usart0).addUSARTListener(this); if (port4 != null) { radio.setSFDPort(port4, CC2420_SFD); } diff --git a/se/sics/mspsim/platform/ti/Exp5438Node.java b/se/sics/mspsim/platform/ti/Exp5438Node.java index faad0d0..887933b 100644 --- a/se/sics/mspsim/platform/ti/Exp5438Node.java +++ b/se/sics/mspsim/platform/ti/Exp5438Node.java @@ -108,7 +108,7 @@ private void setupNodePorts() { radio.setFIFOPPort(port1, CC2420_FIFOP); radio.setFIFOPort(port1, CC2420_FIFO); - ((USARTSource) usart0).setUSARTListener(this); + ((USARTSource) usart0).addUSARTListener(this); if (port1 != null) { radio.setSFDPort(port1, CC2420_SFD); } diff --git a/se/sics/mspsim/platform/tyndall/TyndallNode.java b/se/sics/mspsim/platform/tyndall/TyndallNode.java index 21b86b7..26bac29 100644 --- a/se/sics/mspsim/platform/tyndall/TyndallNode.java +++ b/se/sics/mspsim/platform/tyndall/TyndallNode.java @@ -135,7 +135,7 @@ private void setupNodePorts() { radio.setFIFOPPort(port8, CC2420_FIFOP); radio.setFIFOPort(port8, CC2420_FIFO); - ((USARTSource) usart0).setUSARTListener(this); + ((USARTSource) usart0).addUSARTListener(this); if (port4 != null) { radio.setSFDPort(port8, CC2420_SFD); } diff --git a/se/sics/mspsim/platform/z1/Z1Node.java b/se/sics/mspsim/platform/z1/Z1Node.java index 2a52bc3..6816418 100644 --- a/se/sics/mspsim/platform/z1/Z1Node.java +++ b/se/sics/mspsim/platform/z1/Z1Node.java @@ -120,7 +120,7 @@ private void setupNodePorts() { radio.setFIFOPPort(port1, CC2420_FIFOP); radio.setFIFOPort(port1, CC2420_FIFO); - ((USARTSource) usart0).setUSARTListener(this); + ((USARTSource) usart0).addUSARTListener(this); if (port4 != null) { radio.setSFDPort(port4, CC2420_SFD); } diff --git a/se/sics/mspsim/ui/SerialMon.java b/se/sics/mspsim/ui/SerialMon.java index f61d472..1099ae7 100644 --- a/se/sics/mspsim/ui/SerialMon.java +++ b/se/sics/mspsim/ui/SerialMon.java @@ -51,7 +51,6 @@ import javax.swing.JTextArea; import javax.swing.JTextField; -import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.StateChangeListener; import se.sics.mspsim.core.USARTListener; import se.sics.mspsim.core.USARTSource; @@ -194,8 +193,8 @@ public void keyPressed(KeyEvent e) { public void start() { if (window == null) { initGUI(); - usart.setUSARTListener(this); - ((IOUnit) usart).addStateChangeListener(this); + usart.addUSARTListener(this); + usart.addStateChangeListener(this); } window.setVisible(true); status = Status.STARTED; @@ -206,6 +205,8 @@ public final void stop() { if (window != null) { window.setVisible(false); } + usart.removeUSARTListener(this); + usart.removeStateChangeListener(this); } public void dataReceived(USARTSource source, int data) { diff --git a/se/sics/mspsim/util/Test.java b/se/sics/mspsim/util/Test.java index 56ff977..eca6e36 100644 --- a/se/sics/mspsim/util/Test.java +++ b/se/sics/mspsim/util/Test.java @@ -57,7 +57,7 @@ public Test(MSP430 cpu) { this.cpu = cpu; IOUnit usart = cpu.getIOUnit("USART 1"); if (usart instanceof USART) { - ((USART) usart).setUSARTListener(this); + ((USART) usart).addUSARTListener(this); } } commit eb101681501f46aea9eb9d9eedb3f2ee52749a64 Author: Niclas Finne <nf...@si...> Date: Fri Apr 13 18:28:13 2012 +0200 Added proxies for RFListener, PacketListener, ChannelListener to support multiple listeners diff --git a/se/sics/mspsim/chip/CC2420.java b/se/sics/mspsim/chip/CC2420.java index 674a23b..2a8d4ef 100644 --- a/se/sics/mspsim/chip/CC2420.java +++ b/se/sics/mspsim/chip/CC2420.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007-2011 Swedish Institute of Computer Science. + * Copyright (c) 2007-2012 Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -309,8 +309,9 @@ public int getFSMState() { private int sfdPin; private int txCursor; - private RFListener listener; private boolean on; + private RFListener rfListener; + private ChannelListener channelListener; private TimeEvent oscillatorEvent = new TimeEvent(0, "CC2420 OSC") { public void execute(long t) { @@ -739,13 +740,18 @@ private void setReg(int address, int data) { autoCRC = (data & ADR_AUTOCRC) != 0; autoAck = (data & AUTOACK) != 0; break; - case REG_FSCTRL: - if (cl != null) { + case REG_FSCTRL: { + ChannelListener listener = this.channelListener; + if (listener != null) { + int oldChannel = activeChannel; updateActiveFrequency(); - cl.changedChannel(activeChannel); + if (oldChannel != activeChannel) { + listener.channelChanged(activeChannel); + } } break; } + } configurationChanged(address, oldValue, data); } @@ -1051,9 +1057,9 @@ private void shrNext() { stateMachine); } } else { - if (listener != null) { + if (rfListener != null) { if (DEBUG) log("transmitting byte: " + Utils.hex8(SHR[shrPos])); - listener.receivedByte(SHR[shrPos]); + rfListener.receivedByte(SHR[shrPos]); } shrPos++; cpu.scheduleTimeEventMillis(shrEvent, SYMBOL_PERIOD * 2); @@ -1074,9 +1080,9 @@ private void txNext() { if (txfifoPos > 0x7f) { logw("**** Warning - packet size too large - repeating packet bytes txfifoPos: " + txfifoPos); } - if (listener != null) { + if (rfListener != null) { if (DEBUG) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF)); - listener.receivedByte((byte)(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF)); + rfListener.receivedByte((byte)(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF)); } txfifoPos++; // Two symbol periods to send a byte... @@ -1115,10 +1121,10 @@ private void ackNext() { ackBuf[4] = txCrc.getCRCHi(); ackBuf[5] = txCrc.getCRCLow(); } - if (listener != null) { + if (rfListener != null) { if (DEBUG) log("transmitting byte: " + Utils.hex8(memory[RAM_TXFIFO + (txfifoPos & 0x7f)] & 0xFF)); - listener.receivedByte((byte)(ackBuf[ackPos] & 0xFF)); + rfListener.receivedByte((byte)(ackBuf[ackPos] & 0xFF)); } ackPos++; // Two symbol periods to send a byte... @@ -1326,17 +1332,22 @@ public int getOutputPower() { return -100; } + @Override + public synchronized void addRFListener(RFListener rf) { + rfListener = RFListener.Proxy.INSTANCE.add(rfListener, rf); + } - public void setRFListener(RFListener rf) { - listener = rf; + @Override + public synchronized void removeRFListener(RFListener rf) { + rfListener = RFListener.Proxy.INSTANCE.remove(rfListener, rf); } - public interface ChannelListener { - public void changedChannel(int channel); + public synchronized void addChannelListener(ChannelListener listener) { + channelListener = ChannelListener.Proxy.INSTANCE.add(channelListener, listener); } - private ChannelListener cl = null; - public void setChannelListener(ChannelListener cl) { - this.cl = cl; + + public synchronized void removeChannelListener(ChannelListener listener) { + channelListener = ChannelListener.Proxy.INSTANCE.remove(channelListener, listener); } public void notifyReset() { diff --git a/se/sics/mspsim/chip/PacketListener.java b/se/sics/mspsim/chip/ChannelListener.java similarity index 71% copy from se/sics/mspsim/chip/PacketListener.java copy to se/sics/mspsim/chip/ChannelListener.java index b8e4b87..f967532 100644 --- a/se/sics/mspsim/chip/PacketListener.java +++ b/se/sics/mspsim/chip/ChannelListener.java @@ -1,9 +1,10 @@ -/** - * Copyright (c) 2007, Swedish Institute of Computer Science. +/* + * Copyright (c) 2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: + * modification, are permitted provided that the following conditions + * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright @@ -27,18 +28,26 @@ * * This file is part of MSPSim. * - * $Id$ - * - * ----------------------------------------------------------------- - * - * PacketListener - * - * Author : Joakim Eriksson - * */ + package se.sics.mspsim.chip; +import se.sics.mspsim.util.ProxySupport; + +public interface ChannelListener { + + public void channelChanged(int channel); + + public static class Proxy extends ProxySupport<ChannelListener> implements ChannelListener { + public static final Proxy INSTANCE = new Proxy(); + + @Override + public void channelChanged(int channel) { + ChannelListener[] listeners = this.listeners; + for(ChannelListener listener : listeners) { + listener.channelChanged(channel); + } + } + + } -public interface PacketListener { - public void transmissionStarted(); - public void transmissionEnded(byte[] receivedData); } diff --git a/se/sics/mspsim/chip/PacketListener.java b/se/sics/mspsim/chip/PacketListener.java index b8e4b87..750be03 100644 --- a/se/sics/mspsim/chip/PacketListener.java +++ b/se/sics/mspsim/chip/PacketListener.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2007-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,8 +27,6 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * * PacketListener @@ -37,8 +35,32 @@ * */ package se.sics.mspsim.chip; +import se.sics.mspsim.util.ProxySupport; public interface PacketListener { + public void transmissionStarted(); public void transmissionEnded(byte[] receivedData); + + public static class Proxy extends ProxySupport<PacketListener> implements PacketListener { + public static final Proxy INSTANCE = new Proxy(); + + @Override + public void transmissionStarted() { + PacketListener[] listeners = this.listeners; + for(PacketListener listener : listeners) { + listener.transmissionStarted(); + } + } + + @Override + public void transmissionEnded(byte[] receivedData) { + PacketListener[] listeners = this.listeners; + for(PacketListener listener : listeners) { + listener.transmissionEnded(receivedData); + } + } + + } + } diff --git a/se/sics/mspsim/chip/RFListener.java b/se/sics/mspsim/chip/RFListener.java index 6a7623a..84b2b82 100644 --- a/se/sics/mspsim/chip/RFListener.java +++ b/se/sics/mspsim/chip/RFListener.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007,2008,2009, Swedish Institute of Computer Science. + * Copyright (c) 2007-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,19 +27,33 @@ * * This file is part of MSPSim. * - * $Id: RFListener.java 281 2008-05-13 15:18:14Z joxe$ - * * ----------------------------------------------------------------- * - * CC2420 + * RFListener * * Author : Joakim Eriksson * Created : Sep 06 22:00:00 2008 * */ package se.sics.mspsim.chip; +import se.sics.mspsim.util.ProxySupport; public interface RFListener { + // A byte has been received via the "air" public void receivedByte(byte data); + + public static class Proxy extends ProxySupport<RFListener> implements RFListener { + public static final Proxy INSTANCE = new Proxy(); + + @Override + public void receivedByte(byte data) { + RFListener[] listeners = this.listeners; + for(RFListener listener : listeners) { + listener.receivedByte(data); + } + } + + } + } diff --git a/se/sics/mspsim/chip/RFSource.java b/se/sics/mspsim/chip/RFSource.java index 991a870..041f42b 100644 --- a/se/sics/mspsim/chip/RFSource.java +++ b/se/sics/mspsim/chip/RFSource.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007,2008,2009, Swedish Institute of Computer Science. + * Copyright (c) 2007-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,8 +27,6 @@ * * This file is part of MSPSim. * - * $Id: RFListener.java 281 2008-05-13 15:18:14Z joxe$ - * * ----------------------------------------------------------------- * * RFSource @@ -40,5 +38,8 @@ package se.sics.mspsim.chip; public interface RFSource { - void setRFListener(RFListener listener); + + void addRFListener(RFListener listener); + void removeRFListener(RFListener listener); + } diff --git a/se/sics/mspsim/chip/TR1001.java b/se/sics/mspsim/chip/TR1001.java index 93c25be..2ed13f3 100644 --- a/se/sics/mspsim/chip/TR1001.java +++ b/se/sics/mspsim/chip/TR1001.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2008, Swedish Institute of Computer Science. + * Copyright (c) 2008-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,15 +27,11 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * TR1001 * * Authors : Joakim Eriksson, Niclas Finne * Created : 11 mar 2008 - * Updated : $Date$ - * $Rev$ */ package se.sics.mspsim.chip; @@ -78,9 +74,7 @@ public void dataReceived(USARTSource source, int data) { listener.receivedByte((byte) (data & 0xff)); } } - - public void stateChanged(int state) { - }}); + }); } public void setMode(int mode) { @@ -96,8 +90,14 @@ public String info() { return "Radio State: " + getModeName(getMode()); } - public void setRFListener(RFListener rfListener) { - this.rfListener = rfListener; + @Override + public synchronized void addRFListener(RFListener rf) { + rfListener = RFListener.Proxy.INSTANCE.add(rfListener, rf); + } + + @Override + public synchronized void removeRFListener(RFListener rf) { + rfListener = RFListener.Proxy.INSTANCE.remove(rfListener, rf); } /* Receive a byte from the radio medium diff --git a/se/sics/mspsim/cli/MiscCommands.java b/se/sics/mspsim/cli/MiscCommands.java index 37026fe..9ab34e3 100644 --- a/se/sics/mspsim/cli/MiscCommands.java +++ b/se/sics/mspsim/cli/MiscCommands.java @@ -103,7 +103,7 @@ public void lineRead(String line) { long startTime; public int executeCommand(CommandContext context) { - cpu = (MSP430) registry.getComponent(MSP430.class); + cpu = registry.getComponent(MSP430.class); if (cpu == null) { context.err.println("could not access the CPU."); return 1; @@ -119,7 +119,7 @@ public void lineRead(String line) { handler.registerCommand("speed", new BasicCommand("set the speed factor for the CPU", "[factor]") { public int executeCommand(CommandContext context) { - MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); + MSP430 cpu = registry.getComponent(MSP430.class); if (cpu == null) { context.err.println("could not access the CPU."); return 1; @@ -221,7 +221,7 @@ public int executeCommand(final CommandContext context) { } commandLine = context.getArgument(index); - cpu = (MSP430) registry.getComponent(MSP430.class); + cpu = registry.getComponent(MSP430.class); if (cpu == null) { context.err.println("could not access the CPU."); return 1; @@ -316,7 +316,7 @@ public int executeCommand(CommandContext context) { verbose = false; } if (context.getArgumentCount() == index) { - ServiceComponent[] sc = (ServiceComponent[]) registry.getAllComponents(ServiceComponent.class); + ServiceComponent[] sc = registry.getAllComponents(ServiceComponent.class); if (sc.length == 0) { context.out.println("No services found."); } else { @@ -365,8 +365,9 @@ public int executeCommand(CommandContext context) { handler.registerCommand("rflistener", new BasicLineCommand("an rflistener", "<input|output> <rf-chip>") { CommandContext context; + RFSource source; RFListener listener; - final MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); + final MSP430 cpu = registry.getComponent(MSP430.class); public int executeCommand(CommandContext ctx) { this.context = ctx; String inout = context.getArgument(0); @@ -377,11 +378,13 @@ public int executeCommand(CommandContext ctx) { } if ("output".equals(inout)) { if (chip instanceof RFSource) { - ((RFSource)chip).setRFListener(new RFListener() { + source = (RFSource) chip; + listener = new RFListener() { public void receivedByte(byte data) { context.out.println(Utils.hex8(data)); } - }); + }; + source.addRFListener(listener); } else { context.err.println("Error: chip is not an RF source"); return 1; @@ -395,6 +398,7 @@ public void receivedByte(byte data) { return 0; } + @Override public void lineRead(String line) { if (listener != null) { byte[] data = Utils.hexconv(line); @@ -408,6 +412,15 @@ public void lineRead(String line) { } } } + + @Override + public void stopCommand(CommandContext context) { + if (source != null) { + source.removeRFListener(listener); + } + super.stopCommand(context); + } + }); handler.registerCommand("sysinfo", new BasicCommand("show info about the MSPSim system", "[-registry] [-config]") { diff --git a/se/sics/mspsim/core/MemoryMonitor.java b/se/sics/mspsim/core/MemoryMonitor.java index 9e4e469..6cd1f03 100644 --- a/se/sics/mspsim/core/MemoryMonitor.java +++ b/se/sics/mspsim/core/MemoryMonitor.java @@ -69,16 +69,6 @@ public void notifyWriteAfter(int dstAddress, int data, Memory.AccessMode mode) { public static class Proxy extends ProxySupport<MemoryMonitor> implements MemoryMonitor { public static final Proxy INSTANCE = new Proxy(); - private Proxy() { - } - - @Override - protected MemoryMonitor create(MemoryMonitor oldListener, MemoryMonitor newListener) { - Proxy proxy = new Proxy(); - proxy.listeners = new MemoryMonitor[] { oldListener, newListener }; - return proxy; - } - @Override public void notifyReadBefore(int address, Memory.AccessMode mode, Memory.AccessType type) { MemoryMonitor[] listeners = this.listeners; diff --git a/se/sics/mspsim/core/RegisterMonitor.java b/se/sics/mspsim/core/RegisterMonitor.java index 9515248..9d44ce9 100644 --- a/se/sics/mspsim/core/RegisterMonitor.java +++ b/se/sics/mspsim/core/RegisterMonitor.java @@ -33,16 +33,6 @@ public void notifyWriteAfter(int reg, int data, int mode) { public static class Proxy extends ProxySupport<RegisterMonitor> implements RegisterMonitor { public static final Proxy INSTANCE = new Proxy(); - private Proxy() { - } - - @Override - protected RegisterMonitor create(RegisterMonitor oldListener, RegisterMonitor newListener) { - Proxy proxy = new Proxy(); - proxy.listeners = new RegisterMonitor[] { oldListener, newListener }; - return proxy; - } - @Override public void notifyReadBefore(int reg, int mode) { RegisterMonitor[] listeners = this.listeners; diff --git a/se/sics/mspsim/platform/sky/CC2420Node.java b/se/sics/mspsim/platform/sky/CC2420Node.java index ebe353c..b2a6815 100644 --- a/se/sics/mspsim/platform/sky/CC2420Node.java +++ b/se/sics/mspsim/platform/sky/CC2420Node.java @@ -160,7 +160,7 @@ public void setupNode() { if (config.getPropertyAsBoolean("enableNetwork", false)) { final NetworkConnection network = new NetworkConnection(); final RadioWrapper radioWrapper = new RadioWrapper(radio); - radioWrapper.setPacketListener(new PacketListener() { + radioWrapper.addPacketListener(new PacketListener() { public void transmissionStarted() { } public void transmissionEnded(byte[] receivedData) { diff --git a/se/sics/mspsim/platform/sky/RadioWrapper.java b/se/sics/mspsim/platform/sky/RadioWrapper.java index 78808fb..5d60b1c 100644 --- a/se/sics/mspsim/platform/sky/RadioWrapper.java +++ b/se/sics/mspsim/platform/sky/RadioWrapper.java @@ -5,19 +5,23 @@ public class RadioWrapper implements RFListener { - private CC2420 radio; - private PacketListener listener; + private final CC2420 radio; + private PacketListener packetListener; int len = 0; int pos = 0; byte[] buffer = new byte[128]; public RadioWrapper(CC2420 radio) { this.radio = radio; - radio.setRFListener(this); + radio.addRFListener(this); } - public void setPacketListener(PacketListener list) { - listener = list; + public synchronized void addPacketListener(PacketListener listener) { + packetListener = PacketListener.Proxy.INSTANCE.add(packetListener, listener); + } + + public synchronized void removePacketListener(PacketListener listener) { + packetListener = PacketListener.Proxy.INSTANCE.remove(packetListener, listener); } public void packetReceived(byte[] receivedData) { @@ -40,21 +44,26 @@ public void packetReceived(byte[] receivedData) { // NOTE: len is not in the packet for now... public void receivedByte(byte data) { + PacketListener listener = this.packetListener; // System.out.println("*** RF Data :" + data + " = $" + Utils.hex8(data) + " => " + // (char) data); if (pos == 5) { len = data; } if (pos == 0) { + if (listener != null) { listener.transmissionStarted(); } + } buffer[pos++] = data; // len + 1 = pos + 5 (preambles) if (len > 0 && len + 1 == pos - 5) { // System.out.println("***** SENDING DATA from CC2420 len = " + len); byte[] packet = new byte[len + 1]; System.arraycopy(buffer, 5, packet, 0, len + 1); + if (listener != null) { listener.transmissionEnded(packet); + } pos = 0; len = 0; } diff --git a/se/sics/mspsim/util/NetworkConnection.java b/se/sics/mspsim/util/NetworkConnection.java index 8049e07..e52e4e5 100644 --- a/se/sics/mspsim/util/NetworkConnection.java +++ b/se/sics/mspsim/util/NetworkConnection.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2007-2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,16 +27,12 @@ * * This file is part of MSPSim. * - * $Id: $ - * * ----------------------------------------------------------------- * * NetworkConnection * * Author : Joakim Eriksson * Created : 31 mar 2008 - * Updated : $Date:$ - * $Revision:$ */ package se.sics.mspsim.util; @@ -62,7 +58,7 @@ private ServerSocket serverSocket = null; private SendThread sendThread = null; private ConnectionThread[] connections = null; - private PacketListener listener; + private PacketListener packetListener; public NetworkConnection() { if (connect(DEFAULT_PORT)) { @@ -74,9 +70,12 @@ public NetworkConnection() { sendThread = new SendThread(); } - // TODO: this should handle several listeners!!! - public void addPacketListener(PacketListener pl) { - listener = pl; + public synchronized void addPacketListener(PacketListener listener) { + packetListener = PacketListener.Proxy.INSTANCE.add(packetListener, listener); + } + + public synchronized void removePacketListener(PacketListener listener) { + packetListener = PacketListener.Proxy.INSTANCE.remove(packetListener, listener); } private void setupServer(int port) { @@ -95,7 +94,7 @@ public void run() { try { Socket s = serverSocket.accept(); if (DEBUG) System.out.println("NetworkConnection: New connection from " + s.getRemoteSocketAddress()); - connections = (ConnectionThread[]) ArrayUtils.add(ConnectionThread.class, connections, new ConnectionThread(s)); + connections = ArrayUtils.add(ConnectionThread.class, connections, new ConnectionThread(s)); } catch (IOException e) { e.printStackTrace(); } @@ -105,6 +104,7 @@ public void run() { // Data incoming from the network!!! - forward to radio and if server, to // all other nodes private void dataReceived(byte[] data, ConnectionThread source) { + PacketListener listener = this.packetListener; if (listener != null) { // Send this data to the transmitter in this node! listener.transmissionStarted(); @@ -142,7 +142,7 @@ private void printPacket(String prefix, byte[] data) { private boolean connect(int port) { try { Socket socket = new Socket("127.0.0.1", port); - connections = (ConnectionThread[]) ArrayUtils.add(ConnectionThread.class, connections, new ConnectionThread(socket)); + connections = ArrayUtils.add(ConnectionThread.class, connections, new ConnectionThread(socket)); } catch (UnknownHostException e) { return false; } catch (IOException e) { @@ -185,7 +185,7 @@ private void sendPacket(SendEvent event) { if (cthr != null) { for (int i = 0; i < cthr.length; i++) { if (cthr[i].isClosed()) { - connections = (ConnectionThread[]) ArrayUtils.remove(connections, cthr[i]); + connections = ArrayUtils.remove(connections, cthr[i]); // Do not write back to the source } else if (cthr[i] != event.source){ try { diff --git a/se/sics/mspsim/util/ProxySupport.java b/se/sics/mspsim/util/ProxySupport.java index c4cd1dd..72e6517 100644 --- a/se/sics/mspsim/util/ProxySupport.java +++ b/se/sics/mspsim/util/ProxySupport.java @@ -37,15 +37,18 @@ package se.sics.mspsim.util; -public abstract class ProxySupport<T> { +public abstract class ProxySupport<T> implements Cloneable { + private final Class<T> type; protected T[] listeners; + @SuppressWarnings("unchecked") protected ProxySupport() { + Class<?>[] interfaces = getClass().getInterfaces(); + if (interfaces.length != 1) { + throw new IllegalStateException("proxy does not implement one interface"); } - - protected ProxySupport(T[] listeners) { - this.listeners = listeners; + type = (Class<T>) interfaces[0]; } @SuppressWarnings("unchecked") @@ -55,10 +58,22 @@ public T add(T oldListener, T newListener) { } if (oldListener instanceof ProxySupport<?>) { ProxySupport<T> proxy = (ProxySupport<T>) oldListener; - proxy.listeners = ArrayUtils.add((Class<T>) newListener.getClass(), proxy.listeners, newListener); + proxy.listeners = ArrayUtils.add(type, proxy.listeners, newListener); return oldListener; } - return create(oldListener, newListener); + + // A new proxy is needed + ProxySupport<T> newProxy; + try { + newProxy = (ProxySupport<T>) clone(); + } catch (CloneNotSupportedException e) { + throw new AssertionError(); + } + T[] tmp = (T[]) java.lang.reflect.Array.newInstance(type, 2); + tmp[0] = oldListener; + tmp[1] = newListener; + newProxy.listeners = tmp; + return (T) newProxy; } public T remove(T oldListener, T listener) { @@ -80,6 +95,4 @@ public T remove(T oldListener, T listener) { return oldListener; } - protected abstract T create(T oldListener, T newListener); - } commit 5648fd5b438c49aa96b8b3a9f4cba49eecd29422 Author: Niclas Finne <nf...@si...> Date: Fri Apr 13 14:53:56 2012 +0200 minor code cleanup diff --git a/se/sics/mspsim/chip/Memory.java b/se/sics/mspsim/chip/Memory.java old mode 100755 new mode 100644 diff --git a/se/sics/mspsim/core/MSP430.java b/se/sics/mspsim/core/MSP430.java index 429b2ba..fdfc1e1 100644 --- a/se/sics/mspsim/core/MSP430.java +++ b/se/sics/mspsim/core/MSP430.java @@ -27,16 +27,12 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * * MSP430 * * Author : Joakim Eriksson * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date$ - * $Revision$ */ package se.sics.mspsim.core; @@ -49,8 +45,6 @@ public class MSP430 extends MSP430Core { - public static final int RETURN = 0x4130; - private int[] execCounter; private int[] trace; private int tracePos; @@ -68,7 +62,6 @@ private double lastCPUPercent = 0d; - private long instCtr = 0; private DisAsm disAsm; private SimEventListener[] simEventListeners; @@ -120,8 +113,6 @@ private void run() throws EmulationException { } if ((pc = emulateOP(-1)) >= 0) { - instCtr++; - if (execCounter != null) { execCounter[pc]++; } @@ -207,14 +198,12 @@ protected void dcoReset() { */ long maxCycles = 0; public long stepMicros(long jumpMicros, long executeMicros) throws EmulationException { - int pc; if (isRunning()) { throw new IllegalStateException("step not possible when CPU is running"); } if (jumpMicros < 0) { - throw new IllegalArgumentException("Can not jump a negative time: " + - jumpMicros); + throw new IllegalArgumentException("Can not jump a negative time: " + jumpMicros); } /* quick hack - if microdelta == 0 => ensure that we have correct zery cycles */ @@ -253,7 +242,8 @@ public long stepMicros(long jumpMicros, long executeMicros) throws EmulationExce while (cycles < maxCycles || (cpuOff && (nextEventCycles < cycles))) { - if ((pc = emulateOP(maxCycles)) >= 0) { + int pc = emulateOP(maxCycles); + if (pc >= 0) { if (execCounter != null) { execCounter[pc]++; } @@ -416,12 +406,11 @@ public void setSleepRate(long rate) { } public synchronized void addSimEventListener(SimEventListener l) { - simEventListeners = (SimEventListener[]) ArrayUtils.add(SimEventListener.class, simEventListeners, l); + simEventListeners = ArrayUtils.add(SimEventListener.class, simEventListeners, l); } public synchronized void removeSimEventListener(SimEventListener l) { - simEventListeners = (SimEventListener[]) ArrayUtils.remove(simEventListeners, l); + simEventListeners = ArrayUtils.remove(simEventListeners, l); } - } diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index a24c0c7..eac23ee 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -61,7 +61,7 @@ public final int MAX_MEM_IO; // 16 registers of which some are "special" - PC, SP, etc. - public int[] reg = new int[16]; + public final int[] reg = new int[16]; private final RegisterMonitor[] regWriteMonitors = new RegisterMonitor[16]; private final RegisterMonitor[] regReadMonitors = new RegisterMonitor[16]; @@ -71,7 +71,7 @@ public final int memory[]; - public final Memory memorySegments[]; + private final Memory memorySegments[]; Memory currentSegment; public long cycles = 0; commit 9b31c5141aa32c0a530dcc71f589b6d35f3ae987 Author: Niclas Finne <nf...@si...> Date: Fri Apr 13 12:33:56 2012 +0200 Allow setting the LQI or rather the CORR. Patch by Moritz Struebe. diff --git a/se/sics/mspsim/chip/CC2420.java b/se/sics/mspsim/chip/CC2420.java index c717f5e..674a23b 100644 --- a/se/sics/mspsim/chip/CC2420.java +++ b/se/sics/mspsim/chip/CC2420.java @@ -261,6 +261,9 @@ public int getFSMState() { /* current CCA value */ private boolean cca = false; + /* This is the magical LQI */ + private int corrval = 37; + /* FIFOP Threshold */ private int fifopThr = 64; @@ -681,7 +684,7 @@ public void receivedByte(byte data) { } // Should take a RSSI value as input or use a set-RSSI value... rxFIFO.set(-2, registers[REG_RSSI] & 0xff); - rxFIFO.set(-1, 37 | (crcOk ? 0x80 : 0)); + rxFIFO.set(-1, (corrval & 0x7F) | (crcOk ? 0x80 : 0)); // memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 2) & 127)] = ; // // Set CRC ok and add a correlation - TODO: fix better correlation value!!! // memory[RAM_RXFIFO + ((rxfifoWritePos + 128 - 1) & 127)] = 37 | @@ -1266,6 +1269,17 @@ public int getOutputPowerIndicator() { return (registers[REG_TXCTRL] & 0x1f); } + /** + * This is actually the "CORR" value. + * @param lqi The Corr-val + * @sa CC2420 Datasheet + */ + public void setLQI(int lqi){ + if(lqi < 0) lqi = 0; + else if(lqi > 0x7f ) lqi = 0x7f; + corrval = lqi; + } + public void setRSSI(int power) { final int minp = -128 + RSSI_OFFSET; final int maxp = 128 + RSSI_OFFSET; commit abca9b4c39a0c50a4a39904745cb2aae80b735df Author: Moritz Morty' Strübe <mo...@gm...> Date: Mon Mar 19 20:42:04 2012 +0100 Fix RSSI range diff --git a/se/sics/mspsim/chip/CC2420.java b/se/sics/mspsim/chip/CC2420.java index a041818..c717f5e 100644 --- a/se/sics/mspsim/chip/CC2420.java +++ b/se/sics/mspsim/chip/CC2420.java @@ -1267,10 +1267,17 @@ public int getOutputPowerIndicator() { } public void setRSSI(int power) { - if (DEBUG) log("external setRSSI to: " + power); - if (power < -128) { - power = -128; + final int minp = -128 + RSSI_OFFSET; + final int ... [truncated message content] |
From: Niclas F. <ni...@us...> - 2012-04-12 10:06:26
|
The branch "master" has been updated via ecb98b3839c5862c57a0641490f18ad1a3cbc4c5 (commit) via 6154c1a5e6c9e1b7d3782cd8d878801bcb54eb6d (commit) from 5ba329ea7499c218b9e1cd07d3d230c2d9bef30c (commit) Changed paths: M Makefile M se/sics/mspsim/ui/WindowUtils.java M se/sics/mspsim/util/DotDiagram.java - Log ----------------------------------------------------------------- commit ecb98b3839c5862c57a0641490f18ad1a3cbc4c5 Author: Niclas Finne <nf...@si...> Date: Thu Apr 12 11:53:56 2012 +0200 Minor cleanup of file headers diff --git a/se/sics/mspsim/ui/WindowUtils.java b/se/sics/mspsim/ui/WindowUtils.java index 2d97193..1a6bcb4 100644 --- a/se/sics/mspsim/ui/WindowUtils.java +++ b/se/sics/mspsim/ui/WindowUtils.java @@ -27,16 +27,12 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * * WindowUtils * - * Author : Joakim Eriksson, Niclas Finne, Fredrik Österlind + * Author : Joakim Eriksson, Niclas Finne, Fredrik Osterlind * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date$ - * $Revision$ */ package se.sics.mspsim.ui; diff --git a/se/sics/mspsim/util/DotDiagram.java b/se/sics/mspsim/util/DotDiagram.java index 53c1ea3..4086a96 100644 --- a/se/sics/mspsim/util/DotDiagram.java +++ b/se/sics/mspsim/util/DotDiagram.java @@ -27,16 +27,12 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * * DotDiagram * - * Author : Joakim Eriksson, Niclas Finne, Fredrik Österlind + * Author : Joakim Eriksson, Niclas Finne, Fredrik Osterlind * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date$ - * $Revision$ */ package se.sics.mspsim.util; commit 6154c1a5e6c9e1b7d3782cd8d878801bcb54eb6d Author: Niclas Finne <nf...@si...> Date: Thu Apr 12 11:31:32 2012 +0200 Added missing path in classpath. Patch by Niels Moller. diff --git a/Makefile b/Makefile index 5d9dff3..33b6fb7 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ SPACE := ${EMPTY} ${EMPTY} LIBS := ${wildcard lib/*.jar} BUILD := build CLASSPATH=${subst ${SPACE},${SEPARATOR},$(BUILD)/ ${LIBS}} -CCARGS=-deprecation -classpath "${CLASSPATH}" -d $(BUILD) +CCARGS=-deprecation -classpath ".${SEPARATOR}${CLASSPATH}" -d $(BUILD) JAVAARGS=-classpath "${CLASSPATH}" ----------------------------------------------------------------------- Summary of changes: Makefile | 2 +- se/sics/mspsim/ui/WindowUtils.java | 6 +----- se/sics/mspsim/util/DotDiagram.java | 6 +----- 3 files changed, 3 insertions(+), 11 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-03-29 22:04:27
|
The branch "master" has been updated via 5ba329ea7499c218b9e1cd07d3d230c2d9bef30c (commit) via 41d14186719c606c68c9baedbdb8de13f2acd9d1 (commit) via 9004e36c1c16b8a769c37c94d2a89fbe75426273 (commit) via 65d4b8705279bcd06fdf557fa2e663315acaef5b (commit) from 2390c453502a0ba2e7d572d2c5d41a9ec3174ed1 (commit) Changed paths: M Makefile R100 firmware/esb/sensor-demo.firmware firmware/esb/sensor-demo.esb M firmware/exp5438/testcase-shift-fcf.exp5438 R100 firmware/sky/blink.firmware firmware/sky/blink.sky R100 firmware/sky/energest-demo.firmware firmware/sky/energest-demo.sky M firmware/tyndall/blink.ihex R100 firmware/tyndall/blink.firmware firmware/tyndall/blink.tyndall R100 firmware/z1/blink.firmware firmware/z1/blink.z1 M se/sics/mspsim/cli/ProfilerCommands.java M se/sics/mspsim/debug/DwarfReader.java M se/sics/mspsim/util/Utils.java - Log ----------------------------------------------------------------- commit 5ba329ea7499c218b9e1cd07d3d230c2d9bef30c Author: Niclas Finne <nf...@si...> Date: Thu Mar 29 23:56:13 2012 +0200 Disabled debug output diff --git a/se/sics/mspsim/debug/DwarfReader.java b/se/sics/mspsim/debug/DwarfReader.java index 7539a76..38ee5d5 100644 --- a/se/sics/mspsim/debug/DwarfReader.java +++ b/se/sics/mspsim/debug/DwarfReader.java @@ -49,7 +49,7 @@ public class DwarfReader implements ELFDebug { - public static final boolean DEBUG = true; //false; + public static final boolean DEBUG = false; /* Operands for lines */ public static final int DW_LNS_EXT = 0; commit 41d14186719c606c68c9baedbdb8de13f2acd9d1 Author: Niclas Finne <nf...@si...> Date: Thu Mar 29 23:38:49 2012 +0200 Removed obsolete method diff --git a/se/sics/mspsim/util/Utils.java b/se/sics/mspsim/util/Utils.java index c0dd7ea..071fa33 100644 --- a/se/sics/mspsim/util/Utils.java +++ b/se/sics/mspsim/util/Utils.java @@ -115,12 +115,6 @@ public static String hex24(int data) { return hex(data & 0xffffff, 6); } - public static void fill(byte[] array, int pos, int len, byte value) { - for (int i = 0; i < len; i++) { - array[pos++] = value; - } - } - public static int decodeInt(String value) throws NumberFormatException { int radix = 10; int index = 0; commit 9004e36c1c16b8a769c37c94d2a89fbe75426273 Author: Niclas Finne <nf...@si...> Date: Thu Mar 29 23:38:24 2012 +0200 Allow multiple functions to be specified as arguments to the profile command diff --git a/se/sics/mspsim/cli/ProfilerCommands.java b/se/sics/mspsim/cli/ProfilerCommands.java index ac1e254..110b4b4 100644 --- a/se/sics/mspsim/cli/ProfilerCommands.java +++ b/se/sics/mspsim/cli/ProfilerCommands.java @@ -58,7 +58,7 @@ public class ProfilerCommands implements CommandBundle { public void setupCommands(final ComponentRegistry registry, CommandHandler ch) { - final MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); + final MSP430 cpu = registry.getComponent(MSP430.class); if (cpu != null) { ch.registerCommand("profile", new BasicCommand("show profile information", "[-clear] [-sort column] [-showcallers] [regexp]") { @@ -71,8 +71,9 @@ public int executeCommand(final CommandContext context) { String namematch = null; String sortMode = null; String showCaller = null; + int i; - for (int i = 0; i < context.getArgumentCount(); i++) { + for (i = 0; i < context.getArgumentCount(); i++) { String value = context.getArgument(i); if ("-clear".equals(value)) { profiler.clearProfile(); @@ -88,10 +89,26 @@ public int executeCommand(final CommandContext context) { } } else if ("-showcallers".equals(value)) { showCaller = value; - } else if (namematch != null) { - context.err.println("Too many arguments. Either clear or show profile information."); + } else if ("--".equals(value)) { + /* Done with arguments */ + break; + } else if (value.startsWith("-")) { + /* Unknown option */ + context.err.println("Unknown option: " + value); + return 1; } else { - namematch = value; + break; + } + } + if (i < context.getArgumentCount()) { + namematch = context.getArgument(i++); + if (i < context.getArgumentCount()) { + // Multiple patterns + namematch = "(" + namematch; + for(; i < context.getArgumentCount(); i++) { + namematch += "|" + context.getArgument(i); + } + namematch += ')'; } } @@ -264,7 +281,7 @@ public int executeCommand(CommandContext context) { private CPUHeatMap hm; public int executeCommand(CommandContext context) { - hm = new CPUHeatMap(cpu, (WindowManager) registry.getComponent(WindowManager.class)); + hm = new CPUHeatMap(cpu, registry.getComponent(WindowManager.class)); cpu.addGlobalMonitor(hm); return 0; } commit 65d4b8705279bcd06fdf557fa2e663315acaef5b Author: Niclas Finne <nf...@si...> Date: Thu Mar 29 22:10:47 2012 +0200 Changed Makefile to use directory 'build' when compiling, added make rules to start MSPSim based on firmware name, renamed firmware files based on platform. diff --git a/Makefile b/Makefile index 260ffe5..5d9dff3 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # Makefile for mspsim # # Needed stuff in the PATH: -# java, javac (JDK 1.5 or newer) +# java, javac (JDK 1.6 or newer) # # Under MS-DOS/Windows # A GNU compatible Make (for example Cygwin's) @@ -20,23 +20,20 @@ RM=rm -f # System dependent ############################################################### -ifndef WINDIR - ifdef OS - ifneq (,$(findstring Windows,$(OS))) - WINDIR := Windows - endif +ifndef HOST_OS + ifeq ($(OS),Windows_NT) + HOST_OS := Windows + else + HOST_OS := $(shell uname) endif endif -ifndef WINDIR - # This settings are for UNIX - SEPARATOR=: - # Add "'" around filenames when removing them because UNIX expands "$" - APO='#' (last apostrophe to avoid incorrect font-lock) -else +ifeq ($(HOST_OS),Windows) # These setting are for Windows SEPARATOR=; - APO= +else + # This settings are for UNIX + SEPARATOR=: endif @@ -47,8 +44,9 @@ endif EMPTY := SPACE := ${EMPTY} ${EMPTY} LIBS := ${wildcard lib/*.jar} -CLASSPATH=${subst ${SPACE},${SEPARATOR},. ${LIBS}} -CCARGS=-deprecation -classpath "${CLASSPATH}" +BUILD := build +CLASSPATH=${subst ${SPACE},${SEPARATOR},$(BUILD)/ ${LIBS}} +CCARGS=-deprecation -classpath "${CLASSPATH}" -d $(BUILD) JAVAARGS=-classpath "${CLASSPATH}" @@ -58,10 +56,10 @@ JAVAARGS=-classpath "${CLASSPATH}" ############################################################### ifndef FIRMWAREFILE -ESBFIRMWARE = firmware/esb/sensor-demo.firmware -SKYFIRMWARE = firmware/sky/blink.firmware -Z1FIRMWARE = firmware/z1/blink.firmware -TYNDALLFIRMWARE = firmware/tyndall/blink.firmware +ESBFIRMWARE = firmware/esb/sensor-demo.esb +SKYFIRMWARE = firmware/sky/blink.sky +Z1FIRMWARE = firmware/z1/blink.z1 +TYNDALLFIRMWARE = firmware/tyndall/blink.tyndall EXP5438FIRMWARE = firmware/exp5438/testcase-bits.exp5438 else ESBFIRMWARE = ${FIRMWAREFILE} @@ -81,7 +79,7 @@ PACKAGES := se/sics/mspsim ${addprefix se/sics/mspsim/,core chip cli config debu SOURCES := ${wildcard *.java $(addsuffix /*.java,$(PACKAGES))} -OBJECTS := $(SOURCES:.java=.class) +OBJECTS := ${addprefix $(BUILD)/,$(SOURCES:.java=.class)} JARFILE := mspsim.jar @@ -95,15 +93,31 @@ all: compile compile: $(OBJECTS) -jar: compile JarManifest.txt - $(JAR) cfm $(JARFILE) JarManifest.txt ${addsuffix /*.class,$(PACKAGES)} images/*.jpg - -$(RM) JarManifest.txt +jar: $(JARFILE) + +$(JARFILE): $(OBJECTS) + -@$(RM) JarManifest.txt + @echo >>JarManifest.txt "Manifest-Version: 1.0" + @echo >>JarManifest.txt "Sealed: true" + @echo >>JarManifest.txt "Main-Class: se.sics.mspsim.Main" + @echo >>JarManifest.txt "Class-path: ${LIBS}" + $(JAR) cfm $(JARFILE) JarManifest.txt images/*.jpg -C $(BUILD) . + -@$(RM) JarManifest.txt -JarManifest.txt: - @echo >>$@ "Manifest-Version: 1.0" - @echo >>$@ "Sealed: true" - @echo >>$@ "Main-Class: se.sics.mspsim.Main" - @echo >>$@ "Class-path: ${LIBS}" +%.esb: jar + java -jar $(JARFILE) -platform=esb $(ARGS) $@ + +%.sky: jar + java -jar $(JARFILE) -platform=sky $(ARGS) $@ + +%.z1: jar + java -jar $(JARFILE) -platform=z1 $(ARGS) $@ + +%.exp5438: jar + java -jar $(JARFILE) -platform=exp5438 $(ARGS) $@ + +%.tyndall: jar + java -jar $(JARFILE) -platform=tyndall $(ARGS) $@ help: @echo "Usage: make [all,compile,clean,run,runsky,runesb]" @@ -130,7 +144,6 @@ runtyndall: compile runexp5438: compile $(JAVA) $(JAVAARGS) se.sics.mspsim.platform.ti.Exp5438Node $(ARGS) $(EXP5438FIRMWARE) $(MAPFILE) - test: cputest cputest: $(CPUTEST) @@ -161,7 +174,10 @@ source: # CLASS COMPILATION ############################################################### -%.class : %.java +$(BUILD): + @mkdir $@ + +$(BUILD)/%.class : %.java $(BUILD) $(CC) $(CCARGS) $< @@ -172,8 +188,4 @@ source: .PHONY: clean clean: -ifdef WINDIR - -$(RM) *.class ${addsuffix /*.class,$(PACKAGES)} -else - -$(RM) $(foreach f,$(wildcard *.class),$(APO)$(f)$(APO)) $(foreach dir,$(PACKAGES),$(dir)/*.class) -endif + -$(RM) -r $(BUILD) diff --git a/firmware/esb/sensor-demo.firmware b/firmware/esb/sensor-demo.esb old mode 100755 new mode 100644 similarity index 100% rename from firmware/esb/sensor-demo.firmware rename to firmware/esb/sensor-demo.esb diff --git a/firmware/exp5438/testcase-shift-fcf.exp5438 b/firmware/exp5438/testcase-shift-fcf.exp5438 old mode 100755 new mode 100644 diff --git a/firmware/sky/blink.firmware b/firmware/sky/blink.sky similarity index 100% rename from firmware/sky/blink.firmware rename to firmware/sky/blink.sky diff --git a/firmware/sky/energest-demo.firmware b/firmware/sky/energest-demo.sky similarity index 100% rename from firmware/sky/energest-demo.firmware rename to firmware/sky/energest-demo.sky diff --git a/firmware/tyndall/blink.ihex b/firmware/tyndall/blink.ihex old mode 100755 new mode 100644 diff --git a/firmware/tyndall/blink.firmware b/firmware/tyndall/blink.tyndall old mode 100755 new mode 100644 similarity index 100% rename from firmware/tyndall/blink.firmware rename to firmware/tyndall/blink.tyndall diff --git a/firmware/z1/blink.firmware b/firmware/z1/blink.z1 similarity index 100% rename from firmware/z1/blink.firmware rename to firmware/z1/blink.z1 ----------------------------------------------------------------------- Summary of changes: Makefile | 82 +++++++++++-------- .../esb/{sensor-demo.firmware => sensor-demo.esb} | Bin 285896 -> 285896 bytes firmware/exp5438/testcase-shift-fcf.exp5438 | Bin 26988 -> 26988 bytes firmware/sky/{blink.firmware => blink.sky} | Bin 270719 -> 270719 bytes .../{energest-demo.firmware => energest-demo.sky} | Bin 279163 -> 279163 bytes firmware/tyndall/blink.ihex | Bin 51270 -> 51270 bytes firmware/tyndall/{blink.firmware => blink.tyndall} | Bin 29376 -> 29376 bytes firmware/z1/{blink.firmware => blink.z1} | Bin 465002 -> 465002 bytes se/sics/mspsim/cli/ProfilerCommands.java | 31 ++++++-- se/sics/mspsim/debug/DwarfReader.java | 2 +- se/sics/mspsim/util/Utils.java | 6 -- 11 files changed, 72 insertions(+), 49 deletions(-) rename firmware/esb/{sensor-demo.firmware => sensor-demo.esb} (100%) mode change 100755 => 100644 mode change 100755 => 100644 firmware/exp5438/testcase-shift-fcf.exp5438 rename firmware/sky/{blink.firmware => blink.sky} (100%) rename firmware/sky/{energest-demo.firmware => energest-demo.sky} (100%) mode change 100755 => 100644 firmware/tyndall/blink.ihex rename firmware/tyndall/{blink.firmware => blink.tyndall} (100%) mode change 100755 => 100644 rename firmware/z1/{blink.firmware => blink.z1} (100%) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-03-28 21:42:40
|
The branch "master" has been updated via 2390c453502a0ba2e7d572d2c5d41a9ec3174ed1 (commit) via e382f5db8a420473575838d68caaabdbb0b2e029 (commit) from d662aed492417a1b5a93c1972c0e794a8884c23a (commit) Changed paths: M se/sics/mspsim/cli/DebugCommands.java M se/sics/mspsim/config/MSP430f2617Config.java M se/sics/mspsim/core/DMA.java M se/sics/mspsim/core/Flash.java M se/sics/mspsim/core/FlashSegment.java A se/sics/mspsim/core/GlobalWatchedMemory.java M se/sics/mspsim/core/IOSegment.java M se/sics/mspsim/core/MSP430Config.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/core/Memory.java M se/sics/mspsim/core/MemoryMonitor.java M se/sics/mspsim/core/NoMemSegment.java M se/sics/mspsim/core/RAMSegment.java M se/sics/mspsim/core/WatchedMemory.java M se/sics/mspsim/platform/GenericNode.java M se/sics/mspsim/plugin/ContikiChecker.java M se/sics/mspsim/ui/CPUHeatMap.java M se/sics/mspsim/ui/DebugUI.java M se/sics/mspsim/util/GDBStubs.java M se/sics/mspsim/util/IHexReader.java M se/sics/mspsim/util/Test.java - Log ----------------------------------------------------------------- commit 2390c453502a0ba2e7d572d2c5d41a9ec3174ed1 Author: Niclas Finne <nf...@si...> Date: Wed Mar 28 23:42:03 2012 +0200 Added configuration of memory setup diff --git a/se/sics/mspsim/config/MSP430f2617Config.java b/se/sics/mspsim/config/MSP430f2617Config.java index ab2637a..3a9f0ff 100644 --- a/se/sics/mspsim/config/MSP430f2617Config.java +++ b/se/sics/mspsim/config/MSP430f2617Config.java @@ -66,6 +66,11 @@ public MSP430f2617Config() { UARTConfig uA1 = new UARTConfig(16, 17, 1, 0, 6, 0xD0, "USCI A1", true); UARTConfig uB1 = new UARTConfig(16, 17, 3, 2, 6, 0xD0, "USCI B1", false); uartConfig = new UARTConfig[] {uA0, uB0, uA1, uB1}; + + /* configure memory */ + infoMemConfig(0x1000, 128 * 2); + mainFlashConfig(0x3100, 92 * 1024); + ramConfig(0x1100, 8 * 1024); } public int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits) { commit e382f5db8a420473575838d68caaabdbb0b2e029 Author: Niclas Finne <nf...@si...> Date: Wed Mar 28 23:41:07 2012 +0200 Added enum for memory access mode and type, added memory access methods get/set that do not notify watchpoints, added wrapper for handling memory segment access. Updates for new memory model. diff --git a/se/sics/mspsim/cli/DebugCommands.java b/se/sics/mspsim/cli/DebugCommands.java index f4a7b1f..d49f5fc 100644 --- a/se/sics/mspsim/cli/DebugCommands.java +++ b/se/sics/mspsim/cli/DebugCommands.java @@ -40,6 +40,8 @@ import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430Constants; import se.sics.mspsim.core.Memory; +import se.sics.mspsim.core.Memory.AccessMode; +import se.sics.mspsim.core.Memory.AccessType; import se.sics.mspsim.core.MemoryMonitor; import se.sics.mspsim.core.RegisterMonitor; import se.sics.mspsim.platform.GenericNode; @@ -76,7 +78,7 @@ public int executeCommand(final CommandContext context) { } monitor = new MemoryMonitor.Adapter() { @Override - public void notifyReadBefore(int address, int mode, Memory.AccessType type) { + public void notifyReadBefore(int address, AccessMode mode, AccessType type) { context.out.println("*** Break at $" + cpu.getAddressAsString(address)); cpu.stop(); } @@ -121,15 +123,15 @@ public int executeCommand(final CommandContext context) { return -1; } monitor = new MemoryMonitor.Adapter() { - private void cpuAction(Memory.AccessType type, int adr, int data) { + private void cpuAction(AccessType type, int adr, int data) { if (mode == 0 || mode == 10) { int pc = cpu.getPC(); String adrStr = getSymOrAddr(cpu, context, adr); String pcStr = getSymOrAddrELF(cpu, getELF(), pc); String op = "op"; - if (type == Memory.AccessType.READ) { + if (type == AccessType.READ) { op = "Read"; - } else if (type == Memory.AccessType.WRITE){ + } else if (type == AccessType.WRITE){ op = "Write"; } context.out.println("*** " + op + " from " + pcStr + @@ -139,8 +141,9 @@ private void cpuAction(Memory.AccessType type, int adr, int data) { } } else { if (length > 1) { + Memory mem = cpu.getMemory(); for (int i = address; i < address + length; i++) { - context.out.print(Utils.toString(cpu.memory[i], Utils.BYTE, mode)); + context.out.print(Utils.toString(mem.get(i, AccessMode.BYTE), Utils.BYTE, mode)); } context.out.println(); } else { @@ -150,12 +153,12 @@ private void cpuAction(Memory.AccessType type, int adr, int data) { } @Override - public void notifyReadBefore(int addr, int mode, Memory.AccessType type) { - cpuAction(Memory.AccessType.READ, addr, cpu.memory[addr]); + public void notifyReadBefore(int addr, AccessMode mode, AccessType type) { + cpuAction(AccessType.READ, addr, cpu.getMemory().get(addr, mode)); } @Override - public void notifyWriteBefore(int dstAddress, int data, int mode) { - cpuAction(Memory.AccessType.WRITE, dstAddress, data); + public void notifyWriteBefore(int dstAddress, int data, AccessMode mode) { + cpuAction(AccessType.WRITE, dstAddress, data); } }; @@ -238,10 +241,11 @@ public int executeCommand(final CommandContext context) { } else { for (MapEntry mapEntry : entries) { int address = mapEntry.getAddress(); - context.out.println(" " + mapEntry.getName() + " at $" + - cpu.getAddressAsString(address) + " (" + Utils.hex8(cpu.memory[address]) + - " " + Utils.hex8(cpu.memory[address + 1]) + ") " + mapEntry.getType() + - " in file " + mapEntry.getFile()); + context.out.println(" " + mapEntry.getName() + " at $" + + cpu.getAddressAsString(address) + " ($" + + Utils.hex8(cpu.getMemory().get(address, AccessMode.BYTE)) + + ' ' + Utils.hex8(cpu.getMemory().get(address + 1, AccessMode.BYTE)) + ") " + + mapEntry.getType() + " in file " + mapEntry.getFile()); } } return 0; @@ -472,17 +476,18 @@ public int executeCommand(final CommandContext context) { for (int i = typeRead ? 2 : 1; i < count; i++) { if (mode == Utils.DEC) { int val = context.getArgumentAsInt(i); - boolean word = Utils.size(type) == 2 | val > 0xff; + AccessMode accessMode = Utils.size(type) == 2 || val > 0xff ? AccessMode.WORD : AccessMode.BYTE; try { - cpu.currentSegment.write(adr, val, word ? MSP430Constants.MODE_WORD : MSP430Constants.MODE_BYTE); - adr += word ? 2 : 1; + cpu.getMemory().set(adr, val, accessMode); + adr += accessMode.bytes; } catch (EmulationException e) { e.printStackTrace(context.out); } } else if (mode == Utils.ASCII) { String data = context.getArgument(i); + Memory mem = cpu.getMemory(); for (int j = 0; j < data.length(); j++) { - cpu.currentSegment.write(adr++, data.charAt(j) & 0xff, MSP430Constants.MODE_WORD); + mem.set(adr++, data.charAt(j), AccessMode.BYTE); } } } diff --git a/se/sics/mspsim/core/DMA.java b/se/sics/mspsim/core/DMA.java index 8699846..870a6b0 100644 --- a/se/sics/mspsim/core/DMA.java +++ b/se/sics/mspsim/core/DMA.java @@ -130,12 +130,12 @@ public void trigger(DMATrigger trigger, int index) { /* perform memory move and possibly clear triggering flag!!! */ /* NOTE: show config byte/word also !!! */ if (enable) { - int data = cpu.currentSegment.read(currentSourceAddress, MSP430Constants.MODE_BYTE, Memory.AccessType.READ); + int data = cpu.currentSegment.read(currentSourceAddress, Memory.AccessMode.BYTE, Memory.AccessType.READ); if (DEBUG) log("DMA Triggered reading from: " + currentSourceAddress + " => " + data + " " + (char) data + " size:" + size + " index:" + index); trigger.clearDMATrigger(index); - DMA.this.cpu.currentSegment.write(currentDestinationAddress, data, MSP430Constants.MODE_BYTE); + DMA.this.cpu.currentSegment.write(currentDestinationAddress, data, Memory.AccessMode.BYTE); currentSourceAddress += srcIncr; currentDestinationAddress += dstIncr; diff --git a/se/sics/mspsim/core/Flash.java b/se/sics/mspsim/core/Flash.java index 0a3b6cc..52361d4 100644 --- a/se/sics/mspsim/core/Flash.java +++ b/se/sics/mspsim/core/Flash.java @@ -37,6 +37,7 @@ import java.util.Arrays; +import se.sics.mspsim.core.Memory.AccessMode; import se.sics.mspsim.util.Utils; public class Flash extends IOUnit { @@ -244,7 +245,7 @@ public boolean needsTick() { return false; } - public void flashWrite(int address, int data, boolean word) { + public void flashWrite(int address, int data, AccessMode dataMode) { int wait_time = -1; if (locked) { @@ -321,11 +322,16 @@ public void flashWrite(int address, int data, boolean word) { } /* Flash memory allows clearing bits only */ memory[address] &= data & 0xff; - if (word) { + if (dataMode != AccessMode.BYTE) { memory[address + 1] &= (data >> 8) & 0xff; + if (dataMode == AccessMode.WORD20) { + /* TODO should the write really write the full word? CHECK THIS */ + memory[address + 2] &= (data >> 16) & 0xff; + memory[address + 3] &= (data >> 24) & 0xff; + } } if (DEBUG) { - log("Writing " + data + " to $" + Utils.hex16(address)); + log("Writing $" + Utils.hex20(data) + " to $" + Utils.hex16(address) + " (" + dataMode.bytes + " bytes)"); } waitFlashProcess(wait_time); break; @@ -341,7 +347,7 @@ public void notifyRead(int address) { 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)); + + " read address $" + Utils.hex16(address)); } } } diff --git a/se/sics/mspsim/core/FlashSegment.java b/se/sics/mspsim/core/FlashSegment.java index b5ff812..e42b53f 100644 --- a/se/sics/mspsim/core/FlashSegment.java +++ b/se/sics/mspsim/core/FlashSegment.java @@ -4,35 +4,48 @@ private final MSP430Core core; private final int memory[]; - private final int mask; private final Flash flash; - public FlashSegment(MSP430Core core, Flash flash, int mask) { + public FlashSegment(MSP430Core core, Flash flash) { this.core = core; this.memory = core.memory; - this.mask = mask; this.flash = flash; } @Override - public int read(int address, int mode, AccessType type) throws EmulationException { - if ((address & 0xfff00) != mask) { - core.currentSegment = core.memorySegments[address >> 8]; - return core.currentSegment.read(address, mode, type); + public int read(int address, AccessMode mode, AccessType type) throws EmulationException { + if (core.isFlashBusy) { + flash.notifyRead(address); } - int val = 0; - if (core.isFlashBusy && flash.addressInFlash(address)) { - flash.notifyRead(address); + int val = memory[address] & 0xff; + if (mode != AccessMode.BYTE) { + val |= (memory[address + 1] & 0xff) << 8; + if ((address & 1) != 0) { + core.printWarning(MSP430Constants.MISALIGNED_READ, address); + } + if (mode == AccessMode.WORD20) { + /* will the read really get data from the full word? CHECK THIS */ + val |= (memory[address + 2] & 0xf) << 16; + } + } + return val; } - val = memory[address] & 0xff; - if (mode > MSP430Constants.MODE_BYTE) { + @Override + public void write(int dstAddress, int data, AccessMode mode) throws EmulationException { + flash.flashWrite(dstAddress, data, mode); + } + + @Override + public int get(int address, AccessMode mode) { + int val = memory[address] & 0xff; + if (mode != AccessMode.BYTE) { val |= (memory[address + 1] << 8); if ((address & 1) != 0) { core.printWarning(MSP430Constants.MISALIGNED_READ, address); } - if (mode == MSP430Constants.MODE_WORD20) { + if (mode == AccessMode.WORD20) { /* will the read really get data from the full word? CHECK THIS */ val |= (memory[address + 2] << 16) | (memory[address + 3] << 24); val &= 0xfffff; @@ -44,20 +57,8 @@ public int read(int address, int mode, AccessType type) throws EmulationExceptio } @Override - public void write(int dstAddress, int dst, int mode) - throws EmulationException { - if ((dstAddress & 0xfff00) != mask) { - core.currentSegment = core.memorySegments[dstAddress >> 8]; - core.currentSegment.write(dstAddress, dst, mode); - return; - } - - boolean word = mode != MSP430Constants.MODE_BYTE; - - flash.flashWrite(dstAddress, dst & 0xffff, word); - if (mode > MSP430Constants.MODE_WORD) { - flash.flashWrite(dstAddress + 2, dst >> 16, word); - } + public void set(int address, int data, AccessMode mode) { + write(address, data, mode); } } diff --git a/se/sics/mspsim/core/GlobalWatchedMemory.java b/se/sics/mspsim/core/GlobalWatchedMemory.java new file mode 100644 index 0000000..5fdc631 --- /dev/null +++ b/se/sics/mspsim/core/GlobalWatchedMemory.java @@ -0,0 +1,64 @@ +package se.sics.mspsim.core; + +public class GlobalWatchedMemory implements Memory { + + private final Memory wrappedMemory; + private MemoryMonitor monitor; + + GlobalWatchedMemory(Memory wrapped) { + this.wrappedMemory = wrapped; + } + + public Memory getWatchedMemory() { + return wrappedMemory; + } + + public boolean hasGlobalMonitor() { + return monitor != null; + } + + public synchronized void addGlobalMonitor(MemoryMonitor mon) { + monitor = MemoryMonitor.Proxy.INSTANCE.add(monitor, mon); + } + + public synchronized void removeGlobalMonitor(MemoryMonitor mon) { + monitor = MemoryMonitor.Proxy.INSTANCE.remove(monitor, mon); + } + + @Override + public int read(int address, AccessMode mode, AccessType type) throws EmulationException { + final MemoryMonitor mon = monitor; + if (mon != null) { + mon.notifyReadBefore(address, mode, type); + + int val = wrappedMemory.read(address, mode, type); + + mon.notifyReadAfter(address, mode, type); + return val; + } + return wrappedMemory.read(address, mode, type); + } + + @Override + public void write(int dstAddress, int data, AccessMode mode) throws EmulationException { + MemoryMonitor mon = monitor; + if (mon != null) { + mon.notifyWriteBefore(dstAddress, data, mode); + wrappedMemory.write(dstAddress, data, mode); + mon.notifyWriteAfter(dstAddress, data, mode); + } else { + wrappedMemory.write(dstAddress, data, mode); + } + } + + @Override + public int get(int address, AccessMode mode) { + return wrappedMemory.get(address, mode); + } + + @Override + public void set(int address, int data, AccessMode mode) { + wrappedMemory.set(address, data, mode); + } + +} diff --git a/se/sics/mspsim/core/IOSegment.java b/se/sics/mspsim/core/IOSegment.java index 142501a..8e21b0a 100644 --- a/se/sics/mspsim/core/IOSegment.java +++ b/se/sics/mspsim/core/IOSegment.java @@ -3,42 +3,41 @@ public class IOSegment implements Memory { private final MSP430Core core; - private final int mask; - IOSegment(MSP430Core core, int mask) { + IOSegment(MSP430Core core) { this.core = core; - this.mask = mask; } @Override - public int read(int address, int mode, AccessType type) throws EmulationException { - if ((address & 0xfff00) != mask) { - core.currentSegment = core.memorySegments[address >> 8]; - return core.currentSegment.read(address, mode, type); - } - boolean word = mode != MSP430Constants.MODE_BYTE; + public int read(int address, AccessMode mode, AccessType type) throws EmulationException { + boolean word = mode != AccessMode.BYTE; // Only word reads at 0x1fe which is highest address... int val = core.memIn[address].read(address, word, core.cycles); - if (mode == MSP430Constants.MODE_WORD20) { + if (mode == AccessMode.WORD20) { val |= core.memIn[address + 2].read(address, word, core.cycles) << 16; } return val; } @Override - public void write(int dstAddress, int dst, int mode) - throws EmulationException { - if ((dstAddress & 0xfff00) != mask) { - core.currentSegment = core.memorySegments[dstAddress >> 8]; - core.currentSegment.write(dstAddress, dst, mode); - return; + public void write(int dstAddress, int data, AccessMode mode) throws EmulationException { + boolean word = mode != AccessMode.BYTE; + + if (!word) data &= 0xff; + core.memOut[dstAddress].write(dstAddress, data & 0xffff, word, core.cycles); + if (mode == AccessMode.WORD20) { + core.memOut[dstAddress].write(dstAddress + 2, data >> 16, word, core.cycles); + } } - boolean word = mode != MSP430Constants.MODE_BYTE; - if (!word) dst &= 0xff; - core.memOut[dstAddress].write(dstAddress, dst & 0xffff, word, core.cycles); - if (mode > MSP430Constants.MODE_WORD) { - core.memOut[dstAddress].write(dstAddress + 2, dst >> 16, word, core.cycles); + @Override + public int get(int address, AccessMode mode) { + return read(address, mode, AccessType.READ); } + + @Override + public void set(int address, int data, AccessMode mode) { + write(address, data, mode); } + } diff --git a/se/sics/mspsim/core/MSP430Config.java b/se/sics/mspsim/core/MSP430Config.java index 3894224..6b0c80a 100644 --- a/se/sics/mspsim/core/MSP430Config.java +++ b/se/sics/mspsim/core/MSP430Config.java @@ -103,6 +103,10 @@ public boolean isFlash(int address) { return address >= mainFlashStart && address < mainFlashStart + mainFlashSize; } + public boolean isInfoMem(int address) { + return address >= infoMemStart && address < infoMemStart + infoMemSize; + } + public boolean isIO(int address) { return address < maxMemIO; } diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index f42ea25..c1eb11e 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -33,13 +33,13 @@ * * Author : Joakim Eriksson * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date$ - * $Revision$ */ package se.sics.mspsim.core; import java.io.PrintStream; import java.util.ArrayList; +import se.sics.mspsim.core.Memory.AccessMode; +import se.sics.mspsim.core.Memory.AccessType; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.MapEntry; import se.sics.mspsim.util.MapTable; @@ -63,18 +63,16 @@ // 16 registers of which some are "special" - PC, SP, etc. public int[] reg = new int[16]; - private MemoryMonitor globalMonitor; - private final RegisterMonitor[] regWriteMonitors = new RegisterMonitor[16]; private final RegisterMonitor[] regReadMonitors = new RegisterMonitor[16]; // true => breakpoints can occur! boolean breakpointActive = true; - public int memory[]; + public final int memory[]; - public Memory memorySegments[]; - public Memory currentSegment; + public final Memory memorySegments[]; + Memory currentSegment; public long cycles = 0; public long cpuCycles = 0; @@ -84,9 +82,9 @@ // Most HW needs only notify write and clocking, others need also read... // For notify write... - public IOUnit[] memOut; + public final IOUnit[] memOut; // For notify read... -> which will happen before actual read! - public IOUnit[] memIn; + public final IOUnit[] memIn; private ArrayList<IOUnit> ioUnits; private SFR sfr; @@ -168,15 +166,33 @@ public MSP430Core(int type, ComponentRegistry registry, MSP430Config config) { memorySegments = new Memory[MAX_MEM >> 8]; currentSegment = new Memory() { - /* just throw in the right segment... */ - public int read(int address, int mode, Memory.AccessType type) throws EmulationException { - currentSegment = memorySegments[address >> 8]; - return currentSegment.read(address, mode, type); + @Override + public int read(int address, AccessMode mode, AccessType type) throws EmulationException { + if (address >= MAX_MEM) { + throw new EmulationException("Reading outside memory: 0x" + MSP430Core.this.config.getAddressAsString(address)); + } + return memorySegments[address >> 8].read(address, mode, type); + } + @Override + public void write(int dstAddress, int data, AccessMode mode) throws EmulationException { + if (dstAddress >= MAX_MEM) { + throw new EmulationException("Writing outside memory: 0x" + MSP430Core.this.config.getAddressAsString(dstAddress)); + } + memorySegments[dstAddress >> 8].write(dstAddress, data, mode); } - public void write(int dstAddress, int dst, int mode) - throws EmulationException { - currentSegment = memorySegments[dstAddress >> 8]; - currentSegment.write(dstAddress, dst, mode); + @Override + public int get(int address, AccessMode mode) { + if (address >= MAX_MEM) { + throw new EmulationException("Reading outside memory: 0x" + MSP430Core.this.config.getAddressAsString(address)); + } + return memorySegments[address >> 8].get(address, mode); + } + @Override + public void set(int address, int data, AccessMode mode) { + if (address >= MAX_MEM) { + throw new EmulationException("Writing outside memory: 0x" + MSP430Core.this.config.getAddressAsString(address)); + } + memorySegments[address >> 8].set(address, data, mode); } }; @@ -275,19 +291,23 @@ public int read(int address, boolean word, long cycles) { /* setup memory segments */ int maxSeg = MAX_MEM >> 8; + Memory ramSegment = new RAMSegment(this); + Memory flashSegment = new FlashSegment(this, flash); + Memory ioSegment = new IOSegment(this); + Memory noMemorySegment = new NoMemSegment(this); for (int i = 0; i < maxSeg; i++) { if (config.isRAM(i << 8)) { - System.out.println("Setting RAM segment at: " + Utils.hex16(i << 8)); - memorySegments[i] = new RAMSegment(this, (i << 8)); - } else if (config.isFlash(i << 8)) { - System.out.println("Setting Flash segment at: " + Utils.hex16(i << 8)); - memorySegments[i] = new FlashSegment(this, flash, (i << 8)); +// System.out.println("Setting RAM segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = ramSegment; + } else if (config.isFlash(i << 8) || config.isInfoMem(i << 8)) { +// System.out.println("Setting Flash segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = flashSegment; } else if (config.isIO(i << 8)) { - System.out.println("Setting IO segment at: " + Utils.hex16(i << 8)); - memorySegments[i] = new IOSegment(this, (i << 8)); +// System.out.println("Setting IO segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = ioSegment; } else { - System.out.println("Setting NoMem segment at: " + Utils.hex16(i << 8)); - memorySegments[i] = new NoMemSegment(this, (i << 8)); +// System.out.println("Setting NoMem segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = noMemorySegment; } } @@ -305,11 +325,24 @@ public void setProfiler(Profiler prof) { } public synchronized void addGlobalMonitor(MemoryMonitor mon) { - globalMonitor = MemoryMonitor.Proxy.INSTANCE.add(globalMonitor, mon); + GlobalWatchedMemory gwm; + if (currentSegment instanceof GlobalWatchedMemory) { + gwm = (GlobalWatchedMemory)currentSegment; + } else { + currentSegment = gwm = new GlobalWatchedMemory(currentSegment); + } + gwm.addGlobalMonitor(mon); } public synchronized void removeGlobalMonitor(MemoryMonitor mon) { - globalMonitor = MemoryMonitor.Proxy.INSTANCE.remove(globalMonitor, mon); + if (currentSegment instanceof GlobalWatchedMemory) { + GlobalWatchedMemory gwm = (GlobalWatchedMemory)currentSegment; + gwm.removeGlobalMonitor(mon); + if (!gwm.hasGlobalMonitor()) { + // No more monitors - switch back to normal memory + currentSegment = gwm.getWatchedMemory(); + } + } } public ComponentRegistry getRegistry() { @@ -380,7 +413,7 @@ public synchronized void addWatchPoint(int address, MemoryMonitor mon) { if (memorySegments[seg] instanceof WatchedMemory) { wm = (WatchedMemory) memorySegments[seg]; } else { - wm = new WatchedMemory(this, address & 0xfff00, memorySegments[seg]); + wm = new WatchedMemory(address & 0xfff00, memorySegments[seg]); memorySegments[seg] = wm; } wm.addWatchPoint(address, mon); @@ -419,10 +452,6 @@ public synchronized void removeRegisterReadMonitor(int r, RegisterMonitor mon) { regReadMonitors[r] = RegisterMonitor.Proxy.INSTANCE.remove(regReadMonitors[r], mon); } - public int[] getMemory() { - return memory; - } - public void writeRegister(int r, int value) { // Before the write! // if (value >= MAX_MEM) { @@ -850,16 +879,17 @@ private int serviceInterrupt(int pc) { // Push PC and SR to stack // store on stack - always move 2 steps (W) even if B. writeRegister(SP, sp = spBefore - 2); - currentSegment.write(sp, pc, MODE_WORD); + currentSegment.write(sp, pc, AccessMode.WORD); writeRegister(SP, sp = sp - 2); - currentSegment.write(sp, (sr & 0x0fff) | ((pc & 0xf0000) >> 4), MODE_WORD); + currentSegment.write(sp, (sr & 0x0fff) | ((pc & 0xf0000) >> 4), AccessMode.WORD); } // Clear SR writeRegister(SR, 0); // sr & ~CPUOFF & ~SCG1 & ~OSCOFF); // Jump to the address specified in the interrupt vector - writeRegister(PC, pc = currentSegment.read(0xfffe - (MAX_INTERRUPT - interruptMax) * 2, MODE_WORD, Memory.AccessType.READ)); + pc = currentSegment.read(0xfffe - (MAX_INTERRUPT - interruptMax) * 2, AccessMode.WORD, AccessType.READ); + writeRegister(PC, pc); servicedInterrupt = interruptMax; servicedInterruptUnit = interruptSource[servicedInterrupt]; @@ -956,7 +986,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // } int pcBefore = pc; - instruction = currentSegment.read(pc, MODE_WORD, Memory.AccessType.EXECUTE); + instruction = currentSegment.read(pc, AccessMode.WORD, AccessType.EXECUTE); int ext3_0 = 0; boolean repeatsInDstReg = false; boolean wordx20 = false; @@ -981,7 +1011,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // that follows the extension word also has a zero bit data // length mode.) wordx20 = (instruction & 0x40) == 0; - instruction = currentSegment.read(pc, MODE_WORD, Memory.AccessType.EXECUTE); + instruction = currentSegment.read(pc, AccessMode.WORD, AccessType.EXECUTE); // System.out.println("*** Extension word!!! " + Utils.hex16(extWord) + // " read the instruction too: " + Utils.hex16(instruction) + " at " + Utils.hex16(pc - 2)); } else { @@ -1041,7 +1071,7 @@ public int emulateOP(long maxCycles) throws EmulationException { src = readRegister(srcData); // System.out.println("Reading $" + getAddressAsString(src) + // " from register: " + srcData); - dst = currentSegment.read(src, MODE_WORD20, Memory.AccessType.READ); + dst = currentSegment.read(src, AccessMode.WORD20, AccessType.READ); // System.out.println("Reading from mem: $" + getAddressAsString(dst)); writeRegister(srcData, src + 4); // System.out.println("*** Writing $" + getAddressAsString(dst) + " to reg: " + dstData); @@ -1050,11 +1080,11 @@ public int emulateOP(long maxCycles) throws EmulationException { cycles += 3; break; case MOVA_ABS2REG: - src = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); + src = currentSegment.read(pc, AccessMode.WORD, AccessType.READ); writeRegister(PC, pc += 2); dst = src + (srcData << 16); //System.out.println(Utils.hex20(pc) + " MOVA &ABS Reading from $" + getAddressAsString(dst) + " to reg: " + dstData); - dst = currentSegment.read(dst, MODE_WORD20, Memory.AccessType.READ); + dst = currentSegment.read(dst, AccessMode.WORD20, AccessType.READ); //System.out.println(" => $" + getAddressAsString(dst)); writeRegister(dstData, dst); updateStatus = false; @@ -1063,7 +1093,7 @@ public int emulateOP(long maxCycles) throws EmulationException { case MOVA_INDX2REG: /* Read data from address in memory, indexed by source * register, and place into destination register. */ - int index = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); + int index = currentSegment.read(pc, AccessMode.WORD, AccessType.READ); int indexModifier = readRegister(srcData); if(index > 0x8000) { index = -(0x10000 - index); @@ -1071,16 +1101,16 @@ public int emulateOP(long maxCycles) throws EmulationException { if(indexModifier > 0x8000) { indexModifier = -(0x10000 - indexModifier); } - writeRegister(dstData, currentSegment.read(indexModifier + index, MODE_WORD20, Memory.AccessType.READ)); + writeRegister(dstData, currentSegment.read(indexModifier + index, AccessMode.WORD20, AccessType.READ)); writeRegister(PC, pc += 2); updateStatus = false; cycles += 4; break; case MOVA_REG2ABS: - dst = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); + dst = currentSegment.read(pc, AccessMode.WORD, AccessType.READ); writeRegister(PC, pc += 2); - currentSegment.write(dst + (dstData << 16), readRegister(srcData), MODE_WORD20); + currentSegment.write(dst + (dstData << 16), readRegister(srcData), AccessMode.WORD20); updateStatus = false; cycles += 4; break; @@ -1088,7 +1118,7 @@ public int emulateOP(long maxCycles) throws EmulationException { case MOVA_REG2INDX: /* Read data from register, write to address in memory, * indexed by source register. */ - index = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); + index = currentSegment.read(pc, AccessMode.WORD, AccessType.READ); indexModifier = readRegister(dstData); if(index > 0x8000) { index = -(0x10000 - index); @@ -1096,14 +1126,14 @@ public int emulateOP(long maxCycles) throws EmulationException { if(indexModifier > 0x8000) { indexModifier = -(0x10000 - indexModifier); } - currentSegment.write(indexModifier + index, readRegister(srcData), MODE_WORD20); + currentSegment.write(indexModifier + index, readRegister(srcData), AccessMode.WORD20); writeRegister(PC, pc += 2); updateStatus = false; cycles += 4; break; case MOVA_IMM2REG: - src = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); + src = currentSegment.read(pc, AccessMode.WORD, AccessType.READ); writeRegister(PC, pc += 2); dst = src + (srcData << 16); // System.out.println("*** Writing $" + getAddressAsString(dst) + " to reg: " + dstData); @@ -1118,7 +1148,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // the data is stored in the following word (PC + 2) and // the high 4 bits in the instruction word, which we have // masked out as srcData. - int immData = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ) + (srcData << 16); + int immData = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + (srcData << 16); writeRegister(PC, pc += 2); dst = readRegister(dstData) + immData; writeRegister(dstData, dst); @@ -1133,7 +1163,7 @@ public int emulateOP(long maxCycles) throws EmulationException { operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow) */ - immData = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ) + (srcData << 16); + immData = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + (srcData << 16); writeRegister(PC, pc += 2); sr = readRegister(SR); @@ -1163,7 +1193,7 @@ public int emulateOP(long maxCycles) throws EmulationException { break; } case SUBA_IMM: - immData = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ) + (srcData << 16); + immData = currentSegment.read(pc, AccessMode.WORD, AccessType.READ) + (srcData << 16); writeRegister(PC, pc += 2); dst = readRegister(dstData) - immData; writeRegister(dstData, dst); @@ -1309,32 +1339,32 @@ public int emulateOP(long maxCycles) throws EmulationException { updateStatus = false; switch(op) { case CALLA_IMM: - dst = (dstRegister << 16) | currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); + dst = (dstRegister << 16) | currentSegment.read(pc, AccessMode.WORD, AccessType.READ); pc += 2; cycles += 5; break; case CALLA_ABS: /* read the address of where the address to call is */ - dst = (dstRegister << 16) | currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); - dst = currentSegment.read(dst, MODE_WORD20, Memory.AccessType.READ); + dst = (dstRegister << 16) | currentSegment.read(pc, AccessMode.WORD, AccessType.READ); + dst = currentSegment.read(dst, AccessMode.WORD20, AccessType.READ); pc += 2; cycles += 7; break; default: - int type = MODE_WORD; + AccessMode type = AccessMode.WORD; int size = 2; sp = readRegister(SP); /* check for PUSHM... POPM... */ switch(op & 0x1f00) { case PUSHM_A: - type = MODE_WORD20; + type = AccessMode.WORD20; size = 4; cycles += 2; case PUSHM_W: int n = 1 + ((instruction >> 4) & 0x0f); int regNo = instruction & 0x0f; -// System.out.println("PUSHM " + (type == MODE_WORD20 ? "A" : "W") + +// System.out.println("PUSHM " + (type == AccessMode.WORD20 ? "A" : "W") + // " n: " + n + " " + regNo + " at " + Utils.hex16(pcBefore)); /* decrease stack pointer and write n times */ @@ -1350,19 +1380,19 @@ public int emulateOP(long maxCycles) throws EmulationException { writeRegister(SP, sp); break; case POPM_A: - type = MODE_WORD20; + type = AccessMode.WORD20; size = 4; cycles += 2; case POPM_W: n = 1 + ((instruction >> 4) & 0x0f); regNo = instruction & 0x0f; -// System.out.println("POPM W " + (type == MODE_WORD20 ? "A" : "W") + " n: " + +// System.out.println("POPM W " + (type == AccessMode.WORD20 ? "A" : "W") + " n: " + // n + " " + regNo + " at " + Utils.hex16(pcBefore)); /* read and increase stack pointer n times */ for(int i = 0; i < n; i++) { cycles += 2; - this.reg[regNo++] = currentSegment.read(sp, type, Memory.AccessType.READ); + this.reg[regNo++] = currentSegment.read(sp, type, AccessType.READ); // System.out.println("Restored reg: " + (regNo - 1) + " to " + reg[regNo - 1]); sp += size; /* what happens if regNo is wrapped ??? */ @@ -1381,9 +1411,9 @@ public int emulateOP(long maxCycles) throws EmulationException { /* store 20 bits on stack (costs two words) */ if (dst != -1) { sp = readRegister(SP) - 2; - currentSegment.write(sp, (pc >> 16) & 0xf, MODE_WORD); + currentSegment.write(sp, (pc >> 16) & 0xf, AccessMode.WORD); sp = sp - 2; - currentSegment.write(sp, pc & 0xffff, MODE_WORD); + currentSegment.write(sp, pc & 0xffff, AccessMode.WORD); writeRegister(SP, sp); writeRegister(PC, dst); @@ -1421,9 +1451,9 @@ public int emulateOP(long maxCycles) throws EmulationException { /* Support for MSP430X and below / above 64 KB */ /* if register is pointing to <64KB then it needs to be truncated to below 64 */ if (rval < 0xffff) { - dstAddress = (rval + currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ)) & 0xffff; + dstAddress = (rval + currentSegment.read(pc, AccessMode.WORD, AccessType.READ)) & 0xffff; } else { - dstAddress = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); + dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ); if ((dstAddress & 0x8000) > 0) { dstAddress |= 0xf0000; } @@ -1479,7 +1509,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // System.out.println("*** Repeat " + repeats + " ZeroCarry: " + zeroCarry); // } } else { - dst = currentSegment.read(dstAddress, word ? MODE_WORD : MODE_BYTE, Memory.AccessType.READ); + dst = currentSegment.read(dstAddress, word ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ); } /* TODO: test add the loop here! */ @@ -1542,12 +1572,12 @@ public int emulateOP(long maxCycles) throws EmulationException { // Put lo & hi on stack! // memory[sp] = dst & 0xff; // memory[sp + 1] = dst >> 8; - currentSegment.write(sp, dst, MODE_WORD); + currentSegment.write(sp, dst, AccessMode.WORD); } else { // Byte => only lo byte // memory[sp] = dst & 0xff; // memory[sp + 1] = 0; - currentSegment.write(sp, dst & 0xff, MODE_WORD); + currentSegment.write(sp, dst & 0xff, AccessMode.WORD); } /* if REG or INDIRECT AUTOINC then add 2 cycles, otherwise 1 */ cycles += (ad == AM_REG || ad == AM_IND_AUTOINC) ? 2 : 1; @@ -1559,7 +1589,7 @@ public int emulateOP(long maxCycles) throws EmulationException { pc = readRegister(PC); // memory[sp] = pc & 0xff; // memory[sp + 1] = pc >> 8; - currentSegment.write(sp, pc, MODE_WORD); + currentSegment.write(sp, pc, AccessMode.WORD); writeRegister(PC, dst); /* Additional cycles: REG => 3, AM_IND_AUTO => 2, other => 1 */ @@ -1577,13 +1607,13 @@ public int emulateOP(long maxCycles) throws EmulationException { // Put Top of stack to Status DstRegister (TOS -> SR) servicedInterrupt = -1; /* needed before write to SR!!! */ sp = readRegister(SP); - sr = currentSegment.read(sp, MODE_WORD, Memory.AccessType.READ); + sr = currentSegment.read(sp, AccessMode.WORD, AccessType.READ); writeRegister(SR, sr & 0x0fff); sp = sp + 2; // writeRegister(SR, memory[sp++] + (memory[sp++] << 8)); // TOS -> PC // writeRegister(PC, memory[sp++] + (memory[sp++] << 8)); - writeRegister(PC, currentSegment.read(sp, MODE_WORD, Memory.AccessType.READ) | (sr & 0xf000) << 4); + writeRegister(PC, currentSegment.read(sp, AccessMode.WORD, AccessType.READ) | (sr & 0xf000) << 4); sp = sp + 2; writeRegister(SP, sp); write = false; @@ -1728,9 +1758,9 @@ public int emulateOP(long maxCycles) throws EmulationException { /* Support for MSP430X and below / above 64 KB */ /* if register is pointing to <64KB then it needs to be truncated to below 64 */ if (sval < 0xffff) { - srcAddress = (sval + currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ)) & 0xffff; + srcAddress = (sval + currentSegment.read(pc, AccessMode.WORD, AccessType.READ)) & 0xffff; } else { - srcAddress = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); + srcAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ); if ((srcAddress & 0x8000) > 0) { // Negative index srcAddress |= 0xf0000; @@ -1786,16 +1816,16 @@ public int emulateOP(long maxCycles) throws EmulationException { pc = readRegister(PC); if (dstRegister == 2) { /* absolute mode */ - dstAddress = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); //memory[pc] + (memory[pc + 1] << 8); + dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ); //memory[pc] + (memory[pc + 1] << 8); } else { // CG here - probably not!??? rval = readRegister(dstRegister); /* Support for MSP430X and below / above 64 KB */ /* if register is pointing to <64KB then it needs to be truncated to below 64 */ if (rval < 0xffff) { - dstAddress = (rval + currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ)) & 0xffff; + dstAddress = (rval + currentSegment.read(pc, AccessMode.WORD, AccessType.READ)) & 0xffff; } else { - dstAddress = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); + dstAddress = currentSegment.read(pc, AccessMode.WORD, AccessType.READ); if ((dstAddress & 0x8000) > 0) { dstAddress |= 0xf0000; } @@ -1805,7 +1835,7 @@ public int emulateOP(long maxCycles) throws EmulationException { } if (op != MOV) { - dst = currentSegment.read(dstAddress, word ? MODE_WORD : MODE_BYTE, Memory.AccessType.READ); + dst = currentSegment.read(dstAddress, word ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ); } pc += 2; incRegister(PC, 2); @@ -1819,7 +1849,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // } // srcAddress = srcAddress & 0xffff; - src = currentSegment.read(srcAddress, word ? MODE_WORD : MODE_BYTE, Memory.AccessType.READ); + src = currentSegment.read(srcAddress, word ? AccessMode.WORD : AccessMode.BYTE, AccessType.READ); // if (debug) { // System.out.println("Reading from " + getAddressAsString(srcAddress) + @@ -1993,7 +2023,7 @@ public int emulateOP(long maxCycles) throws EmulationException { writeRegister(dstRegister, dst); } else { dstAddress &= 0xffff; - currentSegment.write(dstAddress, dst, word ? MODE_WORD : MODE_BYTE); + currentSegment.write(dstAddress, dst, word ? AccessMode.WORD : AccessMode.BYTE); } } if (updateStatus) { @@ -2034,6 +2064,10 @@ MapEntry getFunction(MapTable map, int address) { return function; } + public Memory getMemory() { + return currentSegment; + } + public int getPC() { return reg[PC]; } @@ -2066,10 +2100,11 @@ public String info() { + " Time: " + (long)getTimeMillis() + " msec\n"); buf.append(" Interrupt enabled: " + interruptsEnabled + " HighestInterrupt: " + interruptMax); for (int i = 0; i < MAX_INTERRUPT; i++) { - if (currentSegment.read(0xfffe - i * 2, MODE_WORD, Memory.AccessType.READ) != 0xffff) { + int value = currentSegment.get(0xfffe - i * 2, AccessMode.WORD); + if (value != 0xffff) { buf.append(" Vector " + (MAX_INTERRUPT - i) + " at $" + Utils.hex16(0xfffe - i * 2) + " -> $" - + Utils.hex16(currentSegment.read(0xfffe - i * 2, MODE_WORD, Memory.AccessType.READ)) + "\n"); + + Utils.hex16(value) + "\n"); } } return buf.toString(); diff --git a/se/sics/mspsim/core/Memory.java b/se/sics/mspsim/core/Memory.java index fc7ac9e..ea19683 100644 --- a/se/sics/mspsim/core/Memory.java +++ b/se/sics/mspsim/core/Memory.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,21 +27,19 @@ * * This file is part of MSPSim. * - * $Id: $ - * * ----------------------------------------------------------------- * * Memory * * Author : Joakim Eriksson * Created : Sept 15 22:00:00 2008 - * Updated : $Date: 2008-03-11 16:32:12 +0100 (ti, 11 mar 2008) $ - * $Revision: 177 $ */ package se.sics.mspsim.core; public interface Memory { + public static final int SEGMENT_SIZE = 256; + public enum AccessType { READ, /* normal read */ EXECUTE, /* instruction execution read */ @@ -49,9 +47,26 @@ WRITE /* write */ }; - public static final int SEGMENT_SIZE = 256; + public enum AccessMode { + BYTE(1, 8, 0xff), + WORD(2, 16, 0xffff), + WORD20(3, 20, 0xfffff); + + public final int bytes; + public final int bitSize; + public final int mask; + + AccessMode(int bytes, int bitSize, int mask) { + this.bytes = bytes; + this.bitSize = bitSize; + this.mask = mask; + } + }; + + public int read(int address, AccessMode mode, AccessType type) throws EmulationException; + public void write(int dstAddress, int data, AccessMode mode) throws EmulationException; - public int read(int address, int mode, AccessType type) throws EmulationException; - public void write(int dstAddress, int dst, int mode) throws EmulationException; + public int get(int address, AccessMode mode); + public void set(int address, int data, AccessMode mode); } diff --git a/se/sics/mspsim/core/MemoryMonitor.java b/se/sics/mspsim/core/MemoryMonitor.java index 26dba2f..9e4e469 100644 --- a/se/sics/mspsim/core/MemoryMonitor.java +++ b/se/sics/mspsim/core/MemoryMonitor.java @@ -40,28 +40,28 @@ public interface MemoryMonitor { - public void notifyReadBefore(int addr, int mode, Memory.AccessType type); - public void notifyReadAfter(int addr, int mode, Memory.AccessType type); + public void notifyReadBefore(int addr, Memory.AccessMode mode, Memory.AccessType type); + public void notifyReadAfter(int addr, Memory.AccessMode mode, Memory.AccessType type); - public void notifyWriteBefore(int dstAddress, int data, int mode); - public void notifyWriteAfter(int dstAddress, int data, int mode); + public void notifyWriteBefore(int dstAddress, int data, Memory.AccessMode mode); + public void notifyWriteAfter(int dstAddress, int data, Memory.AccessMode mode); public static class Adapter implements MemoryMonitor { @Override - public void notifyReadBefore(int addr, int mode, Memory.AccessType type) { + public void notifyReadBefore(int addr, Memory.AccessMode mode, Memory.AccessType type) { } @Override - public void notifyReadAfter(int addr, int mode, Memory.AccessType type) { + public void notifyReadAfter(int addr, Memory.AccessMode mode, Memory.AccessType type) { } @Override - public void notifyWriteBefore(int dstAddress, int data, int mode) { + public void notifyWriteBefore(int dstAddress, int data, Memory.AccessMode mode) { } @Override - public void notifyWriteAfter(int dstAddress, int data, int mode) { + public void notifyWriteAfter(int dstAddress, int data, Memory.AccessMode mode) { } } @@ -80,7 +80,7 @@ protected MemoryMonitor create(MemoryMonitor oldListener, MemoryMonitor newListe } @Override - public void notifyReadBefore(int address, int mode, Memory.AccessType type) { + public void notifyReadBefore(int address, Memory.AccessMode mode, Memory.AccessType type) { MemoryMonitor[] listeners = this.listeners; for(MemoryMonitor listener : listeners) { listener.notifyReadBefore(address, mode, type); @@ -88,7 +88,7 @@ public void notifyReadBefore(int address, int mode, Memory.AccessType type) { } @Override - public void notifyReadAfter(int address, int mode, Memory.AccessType type) { + public void notifyReadAfter(int address, Memory.AccessMode mode, Memory.AccessType type) { MemoryMonitor[] listeners = this.listeners; for(MemoryMonitor listener : listeners) { listener.notifyReadAfter(address, mode, type); @@ -96,7 +96,7 @@ public void notifyReadAfter(int address, int mode, Memory.AccessType type) { } @Override - public void notifyWriteBefore(int dstAddress, int data, int mode) { + public void notifyWriteBefore(int dstAddress, int data, Memory.AccessMode mode) { MemoryMonitor[] listeners = this.listeners; for(MemoryMonitor listener : listeners) { listener.notifyWriteBefore(dstAddress, data, mode); @@ -104,7 +104,7 @@ public void notifyWriteBefore(int dstAddress, int data, int mode) { } @Override - public void notifyWriteAfter(int dstAddress, int data, int mode) { + public void notifyWriteAfter(int dstAddress, int data, Memory.AccessMode mode) { MemoryMonitor[] listeners = this.listeners; for(MemoryMonitor listener : listeners) { listener.notifyWriteAfter(dstAddress, data, mode); diff --git a/se/sics/mspsim/core/NoMemSegment.java b/se/sics/mspsim/core/NoMemSegment.java index d784037..c61b700 100644 --- a/se/sics/mspsim/core/NoMemSegment.java +++ b/se/sics/mspsim/core/NoMemSegment.java @@ -3,33 +3,32 @@ public class NoMemSegment implements Memory { private final MSP430Core core; - private final int mask; - NoMemSegment(MSP430Core core, int mask) { + NoMemSegment(MSP430Core core) { this.core = core; - this.mask = mask; } @Override - public int read(int address, int mode, AccessType type) throws EmulationException { - if ((address & 0xfff00) != mask) { - core.currentSegment = core.memorySegments[address >> 8]; - return core.currentSegment.read(address, mode, type); + public int read(int address, AccessMode mode, AccessType type) throws EmulationException { + throw new EmulationException("Illegal read - out of bounds at $" + core.config.getAddressAsString(address)); +// core.printWarning(MSP430Constants.ADDRESS_OUT_OF_BOUNDS_READ, address); +// return 0; } -// core.printWarning(MSP430Constants., address); - System.out.println("WARNING - no memory to read from..."); - return 0; + + @Override + public void write(int dstAddress, int dst, AccessMode mode) throws EmulationException { + throw new EmulationException("Illegal write - out of bounds at $" + core.config.getAddressAsString(dstAddress)); + // core.printWarning(MSP430Constants.ADDRESS_OUT_OF_BOUNDS_WRITE, dstAddress); } @Override - public void write(int dstAddress, int dst, int mode) - throws EmulationException { - if ((dstAddress & 0xfff00) != mask) { - core.currentSegment = core.memorySegments[dstAddress >> 8]; - core.currentSegment.write(dstAddress, dst, mode); - return; + public int get(int address, AccessMode mode) { + return read(address, mode, AccessType.READ); } - System.out.println("WARNING - no memory to write to..."); + + @Override + public void set(int address, int data, AccessMode mode) { + write(address, data, mode); } } diff --git a/se/sics/mspsim/core/RAMSegment.java b/se/sics/mspsim/core/RAMSegment.java index f7df5a7..1bef6a2 100644 --- a/se/sics/mspsim/core/RAMSegment.java +++ b/se/sics/mspsim/core/RAMSegment.java @@ -4,27 +4,21 @@ private final MSP430Core core; private final int memory[]; - private final int mask; - public RAMSegment(MSP430Core core, int mask) { + public RAMSegment(MSP430Core core) { this.core = core; - memory = core.memory; - this.mask = mask; + this.memory = core.memory; } @Override - public int read(int address, int mode, AccessType type) throws EmulationException { - if ((address & 0xfff00) != mask) { - core.currentSegment = core.memorySegments[address >> 8]; - return core.currentSegment.read(address, mode, type); - } + public int read(int address, AccessMode mode, AccessType type) throws EmulationException { int val = memory[address] & 0xff; - if (mode > MSP430Constants.MODE_BYTE) { + if (mode != AccessMode.BYTE) { val |= (memory[address + 1] << 8); if ((address & 1) != 0) { core.printWarning(MSP430Constants.MISALIGNED_READ, address); } - if (mode == MSP430Constants.MODE_WORD20) { + if (mode == AccessMode.WORD20) { /* will the read really get data from the full word? CHECK THIS */ val |= (memory[address + 2] << 16) | (memory[address + 3] << 24); val &= 0xfffff; @@ -36,25 +30,29 @@ public int read(int address, int mode, AccessType type) throws EmulationExceptio } @Override - public void write(int dstAddress, int dst, int mode) - throws EmulationException { - if ((dstAddress & 0xfff00) != mask) { - core.currentSegment = core.memorySegments[dstAddress >> 8]; - core.currentSegment.write(dstAddress, dst, mode); - return; - } + public void write(int dstAddress, int dst, AccessMode mode) throws EmulationException { // assume RAM memory[dstAddress] = dst & 0xff; - if (mode != MSP430Core.MODE_BYTE) { + if (mode != AccessMode.BYTE) { memory[dstAddress + 1] = (dst >> 8) & 0xff; if ((dstAddress & 1) != 0) { core.printWarning(MSP430Constants.MISALIGNED_WRITE, dstAddress); } - if (mode > MSP430Core.MODE_WORD) { + if (mode != AccessMode.WORD) { memory[dstAddress + 2] = (dst >> 16) & 0xff; /* should be 0x0f ?? */ memory[dstAddress + 3] = (dst >> 24) & 0xff; /* will be only zeroes*/ } } } + @Override + public int get(int address, AccessMode mode) { + return read(address, mode, AccessType.READ); + } + + @Override + public void set(int address, int data, AccessMode mode) { + write(address, data, mode); + } + } diff --git a/se/sics/mspsim/core/WatchedMemory.java b/se/sics/mspsim/core/WatchedMemory.java index ace05b0..344a3e1 100644 --- a/se/sics/mspsim/core/WatchedMemory.java +++ b/se/sics/mspsim/core/WatchedMemory.java @@ -1,36 +1,25 @@ package se.sics.mspsim.core; -import se.sics.mspsim.util.ArrayUtils; public class WatchedMemory implements Memory { - private final MSP430Core core; private final int start; private final Memory wrappedMemory; - private final MemoryMonitor watchPoints[][] = new MemoryMonitor[Memory.SEGMENT_SIZE][]; + private final MemoryMonitor watchPoints[] = new MemoryMonitor[Memory.SEGMENT_SIZE]; - WatchedMemory(MSP430Core core, int start, Memory wrapped) { - this.core = core; + WatchedMemory(int start, Memory wrapped) { this.start = start; this.wrappedMemory = wrapped; } @Override - public int read(int address, int mode, AccessType type) throws EmulationException { - if ((address & 0xfff00) != start) { - core.currentSegment = core.memorySegments[address >> 8]; - return core.currentSegment.read(address, mode, type); - } - int a = address - start; + public int read(int address, AccessMode mode, AccessType type) throws EmulationException { + final int a = address - start; int val; - MemoryMonitor mons[] = watchPoints[a]; - if (mons != null) { - for(MemoryMonitor mon : mons){ + MemoryMonitor mon = watchPoints[a]; + if (mon != null) { mon.notifyReadBefore(address, mode, type); - } val = wrappedMemory.read(address, mode, type); - for(MemoryMonitor mon : mons){ mon.notifyReadAfter(address, mode, type); - } } else { val = wrappedMemory.read(address, mode, type); } @@ -38,42 +27,41 @@ public int read(int address, int mode, AccessType type) throws EmulationExceptio } @Override - public void write(int dstAddress, int dst, int mode) throws EmulationException { - if ((dstAddress & 0xfff00) != start) { - core.currentSegment = core.memorySegments[dstAddress >> 8]; - core.currentSegment.write(dstAddress, dst, mode); - return; - } - int a = dstAddress - start; - MemoryMonitor mons[] = watchPoints[a]; - if (mons != null) { - for(MemoryMonitor mon : mons){ + public void write(int dstAddress, int dst, AccessMode mode) throws EmulationE... [truncated message content] |
From: Niclas F. <ni...@us...> - 2012-03-23 00:58:58
|
The branch "master" has been updated via d662aed492417a1b5a93c1972c0e794a8884c23a (commit) via 1c569e3697ec43306cc1ef09243b095dca516702 (commit) from 2dc61f1b0e9df5934edfeb90f59e463f94532e59 (commit) Changed paths: M se/sics/mspsim/cli/CommandContext.java C080 se/sics/mspsim/cli/CommandBundle.java se/sics/mspsim/config/MSP430f149Config.java M se/sics/mspsim/platform/esb/ESBNode.java - Log ----------------------------------------------------------------- commit d662aed492417a1b5a93c1972c0e794a8884c23a Author: Niclas Finne <nf...@si...> Date: Fri Mar 23 02:01:45 2012 +0100 Added config for MSP430f149 (for the ESB platform) diff --git a/se/sics/mspsim/config/MSP430f149Config.java b/se/sics/mspsim/config/MSP430f149Config.java new file mode 100644 index 0000000..83231d2 --- /dev/null +++ b/se/sics/mspsim/config/MSP430f149Config.java @@ -0,0 +1,46 @@ +/** + * Copyright (c) 2012, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * ----------------------------------------------------------------- + * + * Author : Joakim Eriksson, Niclas Finne + */ + +package se.sics.mspsim.config; + +public class MSP430f149Config extends MSP430f1611Config { + + public MSP430f149Config() { + /* MSP430f149 is similar to MSP430f1611 but the memory map is different */ + mainFlashConfig(0x1100, 60 * 1024); + ramConfig(0x0200, 2 * 1024); + System.out.println("*** Setting up MSP430f149"); + } + +} diff --git a/se/sics/mspsim/platform/esb/ESBNode.java b/se/sics/mspsim/platform/esb/ESBNode.java index 8efb48a..a9e1ad8 100644 --- a/se/sics/mspsim/platform/esb/ESBNode.java +++ b/se/sics/mspsim/platform/esb/ESBNode.java @@ -45,7 +45,7 @@ import se.sics.mspsim.chip.Beeper; import se.sics.mspsim.chip.Leds; import se.sics.mspsim.chip.TR1001; -import se.sics.mspsim.config.MSP430f1611Config; +import se.sics.mspsim.config.MSP430f149Config; import se.sics.mspsim.core.IOPort; import se.sics.mspsim.core.IOUnit; import se.sics.mspsim.core.MSP430; @@ -89,8 +89,7 @@ * */ public ESBNode() { - /* this should be a config for the MSP430f149 */ - super("ESB", new MSP430f1611Config()); + super("ESB", new MSP430f149Config()); } public Leds getLeds() { commit 1c569e3697ec43306cc1ef09243b095dca516702 Author: Niclas Finne <nf...@si...> Date: Fri Mar 23 01:55:06 2012 +0100 Case insensitive register matching diff --git a/se/sics/mspsim/cli/CommandContext.java b/se/sics/mspsim/cli/CommandContext.java index af800b9..d29fb61 100644 --- a/se/sics/mspsim/cli/CommandContext.java +++ b/se/sics/mspsim/cli/CommandContext.java @@ -123,7 +123,7 @@ public int getArgumentAsAddress(int index) { public int getArgumentAsRegister(int index) { String symbol = getArgument(index); for (int i = 0, n = MSP430Constants.REGISTER_NAMES.length; i < n; i++) { - if (MSP430Constants.REGISTER_NAMES[i].equals(symbol)) { + if (MSP430Constants.REGISTER_NAMES[i].equalsIgnoreCase(symbol)) { return i; } } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/cli/CommandContext.java | 2 +- .../MSP430f149Config.java} | 22 ++++++++----------- se/sics/mspsim/platform/esb/ESBNode.java | 5 +-- 3 files changed, 12 insertions(+), 17 deletions(-) copy se/sics/mspsim/{cli/CommandBundle.java => config/MSP430f149Config.java} (80%) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-03-23 00:51:32
|
The branch "master" has been updated via 2dc61f1b0e9df5934edfeb90f59e463f94532e59 (commit) from 48de0943bf6e2e2d353ebfa722823992d3082e07 (commit) Changed paths: M se/sics/mspsim/cli/DebugCommands.java D se/sics/mspsim/core/CPUMonitor.java D se/sics/mspsim/core/CPUMonitorProxy.java M se/sics/mspsim/core/DMA.java M se/sics/mspsim/core/FlashSegment.java M se/sics/mspsim/core/IOSegment.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/core/Memory.java M se/sics/mspsim/core/MemoryMonitor.java D se/sics/mspsim/core/MemoryMonitorProxy.java M se/sics/mspsim/core/NoMemSegment.java M se/sics/mspsim/core/RAMSegment.java M se/sics/mspsim/core/RegisterMonitor.java M se/sics/mspsim/core/WatchedMemory.java M se/sics/mspsim/plugin/ContikiChecker.java M se/sics/mspsim/ui/CPUHeatMap.java M se/sics/mspsim/ui/StackUI.java C053 se/sics/mspsim/cli/FileTarget.java se/sics/mspsim/util/ProxySupport.java M se/sics/mspsim/util/StackMonitor.java - Log ----------------------------------------------------------------- commit 2dc61f1b0e9df5934edfeb90f59e463f94532e59 Author: Niclas Finne <nf...@si...> Date: Fri Mar 23 01:53:42 2012 +0100 Updates for new memory model diff --git a/se/sics/mspsim/cli/DebugCommands.java b/se/sics/mspsim/cli/DebugCommands.java index 025cb23..f4a7b1f 100644 --- a/se/sics/mspsim/cli/DebugCommands.java +++ b/se/sics/mspsim/cli/DebugCommands.java @@ -33,14 +33,15 @@ * Created : Mon Feb 11 2008 */ package se.sics.mspsim.cli; -import se.sics.mspsim.core.CPUMonitor; import se.sics.mspsim.core.DbgInstruction; import se.sics.mspsim.core.DisAsm; import se.sics.mspsim.core.EmulationException; import se.sics.mspsim.core.Loggable; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430Constants; -import se.sics.mspsim.chip.Memory; +import se.sics.mspsim.core.Memory; +import se.sics.mspsim.core.MemoryMonitor; +import se.sics.mspsim.core.RegisterMonitor; import se.sics.mspsim.platform.GenericNode; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.DebugInfo; @@ -66,24 +67,19 @@ public void setupCommands(ComponentRegistry registry, CommandHandler ch) { ch.registerCommand("break", new BasicAsyncCommand("add a breakpoint to a given address or symbol", "<address or symbol>") { private int address; - private CPUMonitor monitor; + private MemoryMonitor monitor; public int executeCommand(final CommandContext context) { address = context.getArgumentAsAddress(0); if (address < 0) { context.err.println("unknown symbol: " + context.getArgument(0)); return 1; } - monitor = new CPUMonitor() { - public void notifyReadBefore(int type, int adr, int data) { - context.out.println("*** Break at $" + cpu.getAddressAsString(adr)); + monitor = new MemoryMonitor.Adapter() { + @Override + public void notifyReadBefore(int address, int mode, Memory.AccessType type) { + context.out.println("*** Break at $" + cpu.getAddressAsString(address)); cpu.stop(); } - public void notifyReadAfter(int addr, int mode, int type) { - } - public void notifyWriteBefore(int dstAddress, int data, int mode) { - } - public void notifyWriteAfter(int dstAddress, int data, int mode) { - } }; cpu.addWatchPoint(address, monitor); context.err.println("Breakpoint set at $" + cpu.getAddressAsString(address)); @@ -99,7 +95,7 @@ public void stopCommand(CommandContext context) { int mode = 0; int address = 0; int length = 1; - CPUMonitor monitor; + MemoryMonitor monitor; public int executeCommand(final CommandContext context) { address = context.getArgumentAsAddress(0); if (address < 0) { @@ -124,16 +120,16 @@ public int executeCommand(final CommandContext context) { context.err.println("please specify a length of at least one byte"); return -1; } - monitor = new CPUMonitor() { - public void cpuAction(int type, int adr, int data) { + monitor = new MemoryMonitor.Adapter() { + private void cpuAction(Memory.AccessType type, int adr, int data) { if (mode == 0 || mode == 10) { int pc = cpu.getPC(); String adrStr = getSymOrAddr(cpu, context, adr); String pcStr = getSymOrAddrELF(cpu, getELF(), pc); String op = "op"; - if (type == MEMORY_READ) { + if (type == Memory.AccessType.READ) { op = "Read"; - } else if (type == MEMORY_WRITE){ + } else if (type == Memory.AccessType.WRITE){ op = "Write"; } context.out.println("*** " + op + " from " + pcStr + @@ -153,15 +149,13 @@ public void cpuAction(int type, int adr, int data) { } } - public void notifyReadBefore(int addr, int mode, int type) { - cpuAction(CPUMonitor.MEMORY_READ, addr, 0); - } - public void notifyReadAfter(int addr, int mode, int type) { + @Override + public void notifyReadBefore(int addr, int mode, Memory.AccessType type) { + cpuAction(Memory.AccessType.READ, addr, cpu.memory[addr]); } + @Override public void notifyWriteBefore(int dstAddress, int data, int mode) { - cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, data); - } - public void notifyWriteAfter(int dstAddress, int data, int mode) { + cpuAction(Memory.AccessType.WRITE, dstAddress, data); } }; @@ -186,9 +180,9 @@ public void stopCommand(CommandContext context) { ch.registerCommand("watchreg", new BasicAsyncCommand("add a write watch to a given register", "<register> [int]") { - int mode = 0; + int watchMode = 0; int register = 0; - CPUMonitor monitor; + RegisterMonitor monitor; public int executeCommand(final CommandContext context) { register = context.getArgumentAsRegister(0); if (register < 0) { @@ -197,15 +191,16 @@ public int executeCommand(final CommandContext context) { if (context.getArgumentCount() > 1) { String modeStr = context.getArgument(1); if ("int".equals(modeStr)) { - mode = 1; + watchMode = 1; } else { context.err.println("illegal argument: " + modeStr); return -1; } } - monitor = new CPUMonitor() { - public void cpuAction(int type, int adr, int data) { - if (mode == 0) { + monitor = new RegisterMonitor.Adapter() { + @Override + public void notifyWriteBefore(int register, int data, int mode) { + if (watchMode == 0) { int pc = cpu.getPC(); String adrStr = getRegisterName(register); String pcStr = getSymOrAddrELF(cpu, getELF(), pc); @@ -215,16 +210,6 @@ public void cpuAction(int type, int adr, int data) { context.out.println(data); } } - public void notifyReadBefore(int addr, int mode, int type) { - cpuAction(CPUMonitor.MEMORY_READ, addr, 0); - } - public void notifyReadAfter(int addr, int mode, int type) { - } - public void notifyWriteBefore(int dstAddress, int data, int mode) { - cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, data); - } - public void notifyWriteAfter(int dstAddress, int data, int mode) { - } }; cpu.addRegisterWriteMonitor(register, monitor); context.err.println("Watch set for register " + getRegisterName(register)); @@ -362,12 +347,11 @@ public int executeCommand(CommandContext context) { public int executeCommand(CommandContext context) { int adr = context.getArgumentAsAddress(0); if (adr >= 0) { - try { - context.out.println(context.getArgument(0) + " = $" + - Utils.hex16(cpu.currentSegment.read(adr, adr >= 0x100 ? MSP430Constants.MODE_WORD : MSP430Constants.MODE_BYTE, 0))); - } catch (Exception e) { - e.printStackTrace(context.err); + int value = cpu.memory[adr]; + if (adr >= 0x100 && adr + 1 < cpu.MAX_MEM) { + value |= cpu.memory[adr + 1] << 8; } + context.out.println(context.getArgument(0) + " = $" + Utils.hex16(value)); return 0; } context.err.println("unknown symbol: " + context.getArgument(0)); @@ -510,7 +494,7 @@ public int executeCommand(final CommandContext context) { ******************************************************/ ch.registerCommand("xmem", new BasicCommand("dump flash memory", "<start address> <num_entries> [type]") { public int executeCommand(final CommandContext context) { - Memory xmem = (Memory) DebugCommands.this.registry.getComponent("xmem"); + se.sics.mspsim.chip.Memory xmem = DebugCommands.this.registry.getComponent(se.sics.mspsim.chip.Memory.class, "xmem"); if (xmem == null) { context.err.println("No xmem component registered"); return 0; @@ -546,7 +530,7 @@ public int executeCommand(final CommandContext context) { ch.registerCommand("xmset", new BasicCommand("set memory", "<address> <value> [type]") { public int executeCommand(final CommandContext context) { - Memory xmem = (Memory) DebugCommands.this.registry.getComponent("xmem"); + se.sics.mspsim.chip.Memory xmem = DebugCommands.this.registry.getComponent(se.sics.mspsim.chip.Memory.class, "xmem"); if (xmem == null) { context.err.println("No xmem component registered"); return 0; diff --git a/se/sics/mspsim/core/CPUMonitorProxy.java b/se/sics/mspsim/core/CPUMonitorProxy.java deleted file mode 100644 index efebd22..0000000 --- a/se/sics/mspsim/core/CPUMonitorProxy.java +++ /dev/null @@ -1,57 +0,0 @@ -package se.sics.mspsim.core; - -import se.sics.mspsim.util.ArrayUtils; - -public class CPUMonitorProxy implements CPUMonitor { - private CPUMonitor[] monitors; - - public CPUMonitorProxy(CPUMonitor mon1, CPUMonitor mon2) { - monitors = new CPUMonitor[] { mon1, mon2 }; - } - - public static CPUMonitor addCPUMonitor(CPUMonitor cpuMonitor, CPUMonitor mon) { - if (cpuMonitor == null) { - return mon; - } - if (cpuMonitor instanceof CPUMonitorProxy) { - return ((CPUMonitorProxy)cpuMonitor).add(mon); - } - return new CPUMonitorProxy(cpuMonitor, mon); - } - - public static CPUMonitor removeCPUMonitor(CPUMonitor cpuMonitor, CPUMonitor mon) { - if (cpuMonitor == mon) { - return null; - } - if (cpuMonitor instanceof CPUMonitorProxy) { - return ((CPUMonitorProxy)cpuMonitor).remove(mon); - } - return cpuMonitor; - } - - - public CPUMonitor add(CPUMonitor mon) { - monitors = (CPUMonitor[]) ArrayUtils.add(CPUMonitor.class, monitors, mon); - return this; - } - - public CPUMonitor remove(CPUMonitor mon) { - CPUMonitor[] mons = (CPUMonitor[]) ArrayUtils.remove(monitors, mon); - if (mons == null) { - return null; - } - if (mons.length == 1) { - return mons[0]; - } - monitors = mons; - return this; - } - - @Override - public void cpuAction(int type, int adr, int data) { - CPUMonitor[] mons = this.monitors; - for(CPUMonitor mon : mons) { - mon.cpuAction(type, adr, data); - } - } -} diff --git a/se/sics/mspsim/core/DMA.java b/se/sics/mspsim/core/DMA.java index 9b058b5..8699846 100644 --- a/se/sics/mspsim/core/DMA.java +++ b/se/sics/mspsim/core/DMA.java @@ -130,7 +130,7 @@ public void trigger(DMATrigger trigger, int index) { /* perform memory move and possibly clear triggering flag!!! */ /* NOTE: show config byte/word also !!! */ if (enable) { - int data = cpu.currentSegment.read(currentSourceAddress, MSP430Constants.MODE_BYTE, Memory.TYPE_READ); + int data = cpu.currentSegment.read(currentSourceAddress, MSP430Constants.MODE_BYTE, Memory.AccessType.READ); if (DEBUG) log("DMA Triggered reading from: " + currentSourceAddress + " => " + data + " " + (char) data + " size:" + size + " index:" + index); diff --git a/se/sics/mspsim/core/FlashSegment.java b/se/sics/mspsim/core/FlashSegment.java index ffbcb76..b5ff812 100644 --- a/se/sics/mspsim/core/FlashSegment.java +++ b/se/sics/mspsim/core/FlashSegment.java @@ -2,20 +2,20 @@ public class FlashSegment implements Memory { - int memory[]; - MSP430Core core; - int mask; - private Flash flash; + private final MSP430Core core; + private final int memory[]; + private final int mask; + private final Flash flash; public FlashSegment(MSP430Core core, Flash flash, int mask) { this.core = core; - memory = core.memory; + this.memory = core.memory; this.mask = mask; this.flash = flash; } @Override - public int read(int address, int mode, int type) throws EmulationException { + public int read(int address, int mode, AccessType type) throws EmulationException { if ((address & 0xfff00) != mask) { core.currentSegment = core.memorySegments[address >> 8]; return core.currentSegment.read(address, mode, type); diff --git a/se/sics/mspsim/core/IOSegment.java b/se/sics/mspsim/core/IOSegment.java index 494ffcc..142501a 100644 --- a/se/sics/mspsim/core/IOSegment.java +++ b/se/sics/mspsim/core/IOSegment.java @@ -1,21 +1,17 @@ package se.sics.mspsim.core; -import se.sics.mspsim.util.Utils; - public class IOSegment implements Memory { - int memory[]; - MSP430Core core; - int mask; + private final MSP430Core core; + private final int mask; IOSegment(MSP430Core core, int mask) { this.core = core; - memory = core.memory; this.mask = mask; } @Override - public int read(int address, int mode, int type) throws EmulationException { + public int read(int address, int mode, AccessType type) throws EmulationException { if ((address & 0xfff00) != mask) { core.currentSegment = core.memorySegments[address >> 8]; return core.currentSegment.read(address, mode, type); diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index 04df088..f42ea25 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -169,7 +169,7 @@ public MSP430Core(int type, ComponentRegistry registry, MSP430Config config) { currentSegment = new Memory() { /* just throw in the right segment... */ - public int read(int address, int mode, int type) throws EmulationException { + public int read(int address, int mode, Memory.AccessType type) throws EmulationException { currentSegment = memorySegments[address >> 8]; return currentSegment.read(address, mode, type); } @@ -180,8 +180,6 @@ public void write(int dstAddress, int dst, int mode) } }; -// watchPoints = new CPUMonitor[MAX_MEM]; - System.out.println("Set up MSP430 Core with " + MAX_MEM + " bytes memory"); /* this is for detecting writes/read to/from non-existing IO */ @@ -307,11 +305,11 @@ public void setProfiler(Profiler prof) { } public synchronized void addGlobalMonitor(MemoryMonitor mon) { - globalMonitor = MemoryMonitorProxy.addMemoryMonitor(globalMonitor, mon); + globalMonitor = MemoryMonitor.Proxy.INSTANCE.add(globalMonitor, mon); } public synchronized void removeGlobalMonitor(MemoryMonitor mon) { - globalMonitor = MemoryMonitorProxy.removeMemoryMonitor(globalMonitor, mon); + globalMonitor = MemoryMonitor.Proxy.INSTANCE.remove(globalMonitor, mon); } public ComponentRegistry getRegistry() { @@ -369,21 +367,23 @@ public Loggable getLoggable(String name) { } public boolean hasWatchPoint(int address) { - // FIX THIS! + Memory mem = memorySegments[address >> 8]; + if (mem instanceof WatchedMemory) { + return ((WatchedMemory)mem).hasWatchPoint(address); + } return false; -// return watchPoints[address] != null; } public synchronized void addWatchPoint(int address, MemoryMonitor mon) { + int seg = address >> 8; WatchedMemory wm; - if (memorySegments[address >> 8] instanceof WatchedMemory) { - wm = (WatchedMemory) memorySegments[address >> 8]; + if (memorySegments[seg] instanceof WatchedMemory) { + wm = (WatchedMemory) memorySegments[seg]; } else { - wm = new WatchedMemory(address >> 8, memorySegments[address >> 8]); - memorySegments[address >> 8] = wm; + wm = new WatchedMemory(this, address & 0xfff00, memorySegments[seg]); + memorySegments[seg] = wm; } wm.addWatchPoint(address, mon); -// watchPoints[address] = CPUMonitorProxy.addCPUMonitor(watchPoints[address], mon); } public synchronized void removeWatchPoint(int address, MemoryMonitor mon) { @@ -391,25 +391,33 @@ public synchronized void removeWatchPoint(int address, MemoryMonitor mon) { WatchedMemory wm = (WatchedMemory) memorySegments[address >> 8]; wm.removeWatchPoint(address, mon); } -// watchPoints[address] = MemoryMonitorProxy.removeMemoryMonitor(watchPoints[address], mon); } + public synchronized void addRegisterMonitor(int r, RegisterMonitor mon) { + addRegisterWriteMonitor(r, mon); + addRegisterReadMonitor(r, mon); + } -// public synchronized void addRegisterWriteMonitor(int r, CPUMonitor mon) { -// regWriteMonitors[r] = CPUMonitorProxy.addCPUMonitor(regWriteMonitors[r], mon); -// } -// -// public synchronized void removeRegisterWriteMonitor(int r, CPUMonitor mon) { -// regWriteMonitors[r] = CPUMonitorProxy.removeCPUMonitor(regWriteMonitors[r], mon); -// } -// -// public synchronized void addRegisterReadMonitor(int r, CPUMonitor mon) { -// regReadMonitors[r] = CPUMonitorProxy.addCPUMonitor(regReadMonitors[r], mon); -// } -// -// public synchronized void removeRegisterReadMonitor(int r, CPUMonitor mon) { -// regReadMonitors[r] = CPUMonitorProxy.removeCPUMonitor(regReadMonitors[r], mon); -// } + public synchronized void removeRegisterMonitor(int r, RegisterMonitor mon) { + removeRegisterWriteMonitor(r, mon); + removeRegisterReadMonitor(r, mon); + } + + public synchronized void addRegisterWriteMonitor(int r, RegisterMonitor mon) { + regWriteMonitors[r] = RegisterMonitor.Proxy.INSTANCE.add(regWriteMonitors[r], mon); + } + + public synchronized void removeRegisterWriteMonitor(int r, RegisterMonitor mon) { + regWriteMonitors[r] = RegisterMonitor.Proxy.INSTANCE.remove(regWriteMonitors[r], mon); + } + + public synchronized void addRegisterReadMonitor(int r, RegisterMonitor mon) { + regReadMonitors[r] = RegisterMonitor.Proxy.INSTANCE.add(regReadMonitors[r], mon); + } + + public synchronized void removeRegisterReadMonitor(int r, RegisterMonitor mon) { + regReadMonitors[r] = RegisterMonitor.Proxy.INSTANCE.remove(regReadMonitors[r], mon); + } public int[] getMemory() { return memory; @@ -421,12 +429,15 @@ public void writeRegister(int r, int value) { // System.out.println("Writing larger than MAX_MEM to " + r + " value:" + value); // new Throwable().printStackTrace(); // } -// TODO - add RegisterMonitor for this... - // CPUMonitor rwm = regWriteMonitors[r]; -// if (rwm != null) { -// rwm.cpuAction(CPUMonitor.REGISTER_WRITE, r, value); -// } + RegisterMonitor rwm = regWriteMonitors[r]; + if (rwm != null) { + // TODO Add register access mode + rwm.notifyWriteBefore(r, value, 0); reg[r] = value; + rwm.notifyWriteAfter(r, value, 0); + } else { + reg[r] = value; + } if (r == SR) { boolean oldCpuOff = cpuOff; if (debugInterrupts) { @@ -472,12 +483,17 @@ public void writeRegister(int r, int value) { } public int readRegister(int r) { -// Register monitor here... -// CPUMonitor rrm = regReadMonitors[r]; -// if (rrm != null) { -// rrm.cpuAction(CPUMonitor.REGISTER_READ, r, reg[r]); -// } - return reg[r]; + int value; + RegisterMonitor rrm = regReadMonitors[r]; + if (rrm != null) { + // TODO Register access mode + rrm.notifyReadBefore(r, 0); + value = reg[r]; + rrm.notifyReadAfter(r, 0); + } else { + value = reg[r]; + } + return value; } public int readRegisterCG(int r, int m) { @@ -486,23 +502,38 @@ public int readRegisterCG(int r, int m) { // No monitoring here... just return the CG values return CREG_VALUES[r - 2][m]; } -// CPUMonitor rrm = regReadMonitors[r]; -// if (rrm != null) { -// rrm.cpuAction(CPUMonitor.REGISTER_READ, r, reg[r]); -// } - return reg[r]; + int value; + RegisterMonitor rrm = regReadMonitors[r]; + if (rrm != null) { + // TODO Register access mode + rrm.notifyReadBefore(r, 0); + value = reg[r]; + rrm.notifyReadAfter(r, 0); + } else { + value = reg[r]; + } + return value; } public int incRegister(int r, int value) { -// CPUMonitor rm = regReadMonitors[r]; -// if (rm != null) { -// rm.cpuAction(CPUMonitor.REGISTER_READ, r, reg[r]); -// } -// rm = regWriteMonitors[r]; -// if (rm != null) { -// rm.cpuAction(CPUMonitor.REGISTER_WRITE, r, reg[r] + value); -// } - reg[r] += value; + int registerValue; + RegisterMonitor rm = regReadMonitors[r]; + if (rm != null) { + rm.notifyReadBefore(r, 0); + registerValue = reg[r]; + rm.notifyReadAfter(r, 0); + } else { + registerValue = reg[r]; + } + rm = regWriteMonitors[r]; + registerValue += value; + if (rm != null) { + rm.notifyWriteBefore(r, registerValue, 0); + reg[r] = registerValue; + rm.notifyWriteAfter(r, registerValue, 0); + } else { + reg[r] = registerValue; + } return reg[r]; } @@ -828,7 +859,7 @@ private int serviceInterrupt(int pc) { writeRegister(SR, 0); // sr & ~CPUOFF & ~SCG1 & ~OSCOFF); // Jump to the address specified in the interrupt vector - writeRegister(PC, pc = currentSegment.read(0xfffe - (MAX_INTERRUPT - interruptMax) * 2, MODE_WORD, Memory.TYPE_READ)); + writeRegister(PC, pc = currentSegment.read(0xfffe - (MAX_INTERRUPT - interruptMax) * 2, MODE_WORD, Memory.AccessType.READ)); servicedInterrupt = interruptMax; servicedInterruptUnit = interruptSource[servicedInterrupt]; @@ -925,7 +956,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // } int pcBefore = pc; - instruction = currentSegment.read(pc, MODE_WORD, Memory.TYPE_EXECUTE); + instruction = currentSegment.read(pc, MODE_WORD, Memory.AccessType.EXECUTE); int ext3_0 = 0; boolean repeatsInDstReg = false; boolean wordx20 = false; @@ -950,7 +981,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // that follows the extension word also has a zero bit data // length mode.) wordx20 = (instruction & 0x40) == 0; - instruction = currentSegment.read(pc, MODE_WORD, Memory.TYPE_EXECUTE); + instruction = currentSegment.read(pc, MODE_WORD, Memory.AccessType.EXECUTE); // System.out.println("*** Extension word!!! " + Utils.hex16(extWord) + // " read the instruction too: " + Utils.hex16(instruction) + " at " + Utils.hex16(pc - 2)); } else { @@ -1010,7 +1041,7 @@ public int emulateOP(long maxCycles) throws EmulationException { src = readRegister(srcData); // System.out.println("Reading $" + getAddressAsString(src) + // " from register: " + srcData); - dst = currentSegment.read(src, MODE_WORD20, Memory.TYPE_READ); + dst = currentSegment.read(src, MODE_WORD20, Memory.AccessType.READ); // System.out.println("Reading from mem: $" + getAddressAsString(dst)); writeRegister(srcData, src + 4); // System.out.println("*** Writing $" + getAddressAsString(dst) + " to reg: " + dstData); @@ -1019,11 +1050,11 @@ public int emulateOP(long maxCycles) throws EmulationException { cycles += 3; break; case MOVA_ABS2REG: - src = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + src = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); writeRegister(PC, pc += 2); dst = src + (srcData << 16); //System.out.println(Utils.hex20(pc) + " MOVA &ABS Reading from $" + getAddressAsString(dst) + " to reg: " + dstData); - dst = currentSegment.read(dst, MODE_WORD20, Memory.TYPE_READ); + dst = currentSegment.read(dst, MODE_WORD20, Memory.AccessType.READ); //System.out.println(" => $" + getAddressAsString(dst)); writeRegister(dstData, dst); updateStatus = false; @@ -1032,7 +1063,7 @@ public int emulateOP(long maxCycles) throws EmulationException { case MOVA_INDX2REG: /* Read data from address in memory, indexed by source * register, and place into destination register. */ - int index = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + int index = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); int indexModifier = readRegister(srcData); if(index > 0x8000) { index = -(0x10000 - index); @@ -1040,14 +1071,14 @@ public int emulateOP(long maxCycles) throws EmulationException { if(indexModifier > 0x8000) { indexModifier = -(0x10000 - indexModifier); } - writeRegister(dstData, currentSegment.read(indexModifier + index, MODE_WORD20, Memory.TYPE_READ)); + writeRegister(dstData, currentSegment.read(indexModifier + index, MODE_WORD20, Memory.AccessType.READ)); writeRegister(PC, pc += 2); updateStatus = false; cycles += 4; break; case MOVA_REG2ABS: - dst = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + dst = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); writeRegister(PC, pc += 2); currentSegment.write(dst + (dstData << 16), readRegister(srcData), MODE_WORD20); updateStatus = false; @@ -1057,7 +1088,7 @@ public int emulateOP(long maxCycles) throws EmulationException { case MOVA_REG2INDX: /* Read data from register, write to address in memory, * indexed by source register. */ - index = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + index = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); indexModifier = readRegister(dstData); if(index > 0x8000) { index = -(0x10000 - index); @@ -1072,7 +1103,7 @@ public int emulateOP(long maxCycles) throws EmulationException { break; case MOVA_IMM2REG: - src = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + src = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); writeRegister(PC, pc += 2); dst = src + (srcData << 16); // System.out.println("*** Writing $" + getAddressAsString(dst) + " to reg: " + dstData); @@ -1087,7 +1118,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // the data is stored in the following word (PC + 2) and // the high 4 bits in the instruction word, which we have // masked out as srcData. - int immData = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ) + (srcData << 16); + int immData = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ) + (srcData << 16); writeRegister(PC, pc += 2); dst = readRegister(dstData) + immData; writeRegister(dstData, dst); @@ -1102,7 +1133,7 @@ public int emulateOP(long maxCycles) throws EmulationException { operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow) */ - immData = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ) + (srcData << 16); + immData = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ) + (srcData << 16); writeRegister(PC, pc += 2); sr = readRegister(SR); @@ -1132,7 +1163,7 @@ public int emulateOP(long maxCycles) throws EmulationException { break; } case SUBA_IMM: - immData = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ) + (srcData << 16); + immData = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ) + (srcData << 16); writeRegister(PC, pc += 2); dst = readRegister(dstData) - immData; writeRegister(dstData, dst); @@ -1278,14 +1309,14 @@ public int emulateOP(long maxCycles) throws EmulationException { updateStatus = false; switch(op) { case CALLA_IMM: - dst = (dstRegister << 16) | currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + dst = (dstRegister << 16) | currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); pc += 2; cycles += 5; break; case CALLA_ABS: /* read the address of where the address to call is */ - dst = (dstRegister << 16) | currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); - dst = currentSegment.read(dst, MODE_WORD20, Memory.TYPE_READ); + dst = (dstRegister << 16) | currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); + dst = currentSegment.read(dst, MODE_WORD20, Memory.AccessType.READ); pc += 2; cycles += 7; break; @@ -1331,7 +1362,7 @@ public int emulateOP(long maxCycles) throws EmulationException { /* read and increase stack pointer n times */ for(int i = 0; i < n; i++) { cycles += 2; - this.reg[regNo++] = currentSegment.read(sp, type, Memory.TYPE_READ); + this.reg[regNo++] = currentSegment.read(sp, type, Memory.AccessType.READ); // System.out.println("Restored reg: " + (regNo - 1) + " to " + reg[regNo - 1]); sp += size; /* what happens if regNo is wrapped ??? */ @@ -1390,9 +1421,9 @@ public int emulateOP(long maxCycles) throws EmulationException { /* Support for MSP430X and below / above 64 KB */ /* if register is pointing to <64KB then it needs to be truncated to below 64 */ if (rval < 0xffff) { - dstAddress = (rval + currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ)) & 0xffff; + dstAddress = (rval + currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ)) & 0xffff; } else { - dstAddress = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + dstAddress = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); if ((dstAddress & 0x8000) > 0) { dstAddress |= 0xf0000; } @@ -1448,7 +1479,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // System.out.println("*** Repeat " + repeats + " ZeroCarry: " + zeroCarry); // } } else { - dst = currentSegment.read(dstAddress, word ? MODE_WORD : MODE_BYTE, Memory.TYPE_READ); + dst = currentSegment.read(dstAddress, word ? MODE_WORD : MODE_BYTE, Memory.AccessType.READ); } /* TODO: test add the loop here! */ @@ -1546,13 +1577,13 @@ public int emulateOP(long maxCycles) throws EmulationException { // Put Top of stack to Status DstRegister (TOS -> SR) servicedInterrupt = -1; /* needed before write to SR!!! */ sp = readRegister(SP); - sr = currentSegment.read(sp, MODE_WORD, Memory.TYPE_READ); + sr = currentSegment.read(sp, MODE_WORD, Memory.AccessType.READ); writeRegister(SR, sr & 0x0fff); sp = sp + 2; // writeRegister(SR, memory[sp++] + (memory[sp++] << 8)); // TOS -> PC // writeRegister(PC, memory[sp++] + (memory[sp++] << 8)); - writeRegister(PC, currentSegment.read(sp, MODE_WORD, Memory.TYPE_READ) | (sr & 0xf000) << 4); + writeRegister(PC, currentSegment.read(sp, MODE_WORD, Memory.AccessType.READ) | (sr & 0xf000) << 4); sp = sp + 2; writeRegister(SP, sp); write = false; @@ -1697,9 +1728,9 @@ public int emulateOP(long maxCycles) throws EmulationException { /* Support for MSP430X and below / above 64 KB */ /* if register is pointing to <64KB then it needs to be truncated to below 64 */ if (sval < 0xffff) { - srcAddress = (sval + currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ)) & 0xffff; + srcAddress = (sval + currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ)) & 0xffff; } else { - srcAddress = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + srcAddress = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); if ((srcAddress & 0x8000) > 0) { // Negative index srcAddress |= 0xf0000; @@ -1755,16 +1786,16 @@ public int emulateOP(long maxCycles) throws EmulationException { pc = readRegister(PC); if (dstRegister == 2) { /* absolute mode */ - dstAddress = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); //memory[pc] + (memory[pc + 1] << 8); + dstAddress = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); //memory[pc] + (memory[pc + 1] << 8); } else { // CG here - probably not!??? rval = readRegister(dstRegister); /* Support for MSP430X and below / above 64 KB */ /* if register is pointing to <64KB then it needs to be truncated to below 64 */ if (rval < 0xffff) { - dstAddress = (rval + currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ)) & 0xffff; + dstAddress = (rval + currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ)) & 0xffff; } else { - dstAddress = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + dstAddress = currentSegment.read(pc, MODE_WORD, Memory.AccessType.READ); if ((dstAddress & 0x8000) > 0) { dstAddress |= 0xf0000; } @@ -1773,8 +1804,9 @@ public int emulateOP(long maxCycles) throws EmulationException { } } - if (op != MOV) - dst = currentSegment.read(dstAddress, word ? MODE_WORD : MODE_BYTE, Memory.TYPE_READ); + if (op != MOV) { + dst = currentSegment.read(dstAddress, word ? MODE_WORD : MODE_BYTE, Memory.AccessType.READ); + } pc += 2; incRegister(PC, 2); } @@ -1787,7 +1819,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // } // srcAddress = srcAddress & 0xffff; - src = currentSegment.read(srcAddress, word ? MODE_WORD : MODE_BYTE, Memory.TYPE_READ); + src = currentSegment.read(srcAddress, word ? MODE_WORD : MODE_BYTE, Memory.AccessType.READ); // if (debug) { // System.out.println("Reading from " + getAddressAsString(srcAddress) + @@ -2034,10 +2066,10 @@ public String info() { + " Time: " + (long)getTimeMillis() + " msec\n"); buf.append(" Interrupt enabled: " + interruptsEnabled + " HighestInterrupt: " + interruptMax); for (int i = 0; i < MAX_INTERRUPT; i++) { - if (currentSegment.read(0xfffe - i * 2, MODE_WORD, Memory.TYPE_READ) != 0xffff) { + if (currentSegment.read(0xfffe - i * 2, MODE_WORD, Memory.AccessType.READ) != 0xffff) { buf.append(" Vector " + (MAX_INTERRUPT - i) + " at $" + Utils.hex16(0xfffe - i * 2) + " -> $" - + Utils.hex16(currentSegment.read(0xfffe - i * 2, MODE_WORD, Memory.TYPE_READ)) + "\n"); + + Utils.hex16(currentSegment.read(0xfffe - i * 2, MODE_WORD, Memory.AccessType.READ)) + "\n"); } } return buf.toString(); diff --git a/se/sics/mspsim/core/Memory.java b/se/sics/mspsim/core/Memory.java index df5c5fa..fc7ac9e 100644 --- a/se/sics/mspsim/core/Memory.java +++ b/se/sics/mspsim/core/Memory.java @@ -42,12 +42,16 @@ public interface Memory { - public static int SEGMENT_SIZE = 256; - public static int TYPE_READ = 1; /* normal read */ - public static int TYPE_EXECUTE = 2; /* instruction execution read */ - public static int TYPE_ARG = 3; /* arguments for execution */ + public enum AccessType { + READ, /* normal read */ + EXECUTE, /* instruction execution read */ + ARG, /* arguments for execution */ + WRITE /* write */ + }; - public int read(int address, int mode, int type) throws EmulationException; + public static final int SEGMENT_SIZE = 256; + + public int read(int address, int mode, AccessType type) throws EmulationException; public void write(int dstAddress, int dst, int mode) throws EmulationException; } diff --git a/se/sics/mspsim/core/MemoryMonitor.java b/se/sics/mspsim/core/MemoryMonitor.java index 88b9c6d..26dba2f 100644 --- a/se/sics/mspsim/core/MemoryMonitor.java +++ b/se/sics/mspsim/core/MemoryMonitor.java @@ -1,5 +1,5 @@ /** - * Copyright (c) 2007, Swedish Institute of Computer Science. + * Copyright (c) 2012, Swedish Institute of Computer Science. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -27,33 +27,90 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * - * CPUMonitor + * MemoryMonitor * * Author : Joakim Eriksson * Created : Sun Oct 21 22:00:00 2007 - * Updated : $Date$ - * $Revision$ */ package se.sics.mspsim.core; +import se.sics.mspsim.util.ProxySupport; public interface MemoryMonitor { - public static final int MEMORY_READ = 1; - public static final int MEMORY_WRITE = 2; - public static final int EXECUTE = 5; + public void notifyReadBefore(int addr, int mode, Memory.AccessType type); + public void notifyReadAfter(int addr, int mode, Memory.AccessType type); + public void notifyWriteBefore(int dstAddress, int data, int mode); + public void notifyWriteAfter(int dstAddress, int data, int mode); - //public void cpuAction(int type, int adr, int data); + public static class Adapter implements MemoryMonitor { - public void notifyReadBefore(int addr, int mode, int type); - public void notifyReadAfter(int addr, int mode, int type); + @Override + public void notifyReadBefore(int addr, int mode, Memory.AccessType type) { + } - public void notifyWriteBefore(int dstAddress, int data, int mode); - public void notifyWriteAfter(int dstAddress, int data, int mode); + @Override + public void notifyReadAfter(int addr, int mode, Memory.AccessType type) { + } + + @Override + public void notifyWriteBefore(int dstAddress, int data, int mode) { + } + + @Override + public void notifyWriteAfter(int dstAddress, int data, int mode) { + } + + } + + public static class Proxy extends ProxySupport<MemoryMonitor> implements MemoryMonitor { + public static final Proxy INSTANCE = new Proxy(); + + private Proxy() { + } + + @Override + protected MemoryMonitor create(MemoryMonitor oldListener, MemoryMonitor newListener) { + Proxy proxy = new Proxy(); + proxy.listeners = new MemoryMonitor[] { oldListener, newListener }; + return proxy; + } + + @Override + public void notifyReadBefore(int address, int mode, Memory.AccessType type) { + MemoryMonitor[] listeners = this.listeners; + for(MemoryMonitor listener : listeners) { + listener.notifyReadBefore(address, mode, type); + } + } + + @Override + public void notifyReadAfter(int address, int mode, Memory.AccessType type) { + MemoryMonitor[] listeners = this.listeners; + for(MemoryMonitor listener : listeners) { + listener.notifyReadAfter(address, mode, type); + } + } + + @Override + public void notifyWriteBefore(int dstAddress, int data, int mode) { + MemoryMonitor[] listeners = this.listeners; + for(MemoryMonitor listener : listeners) { + listener.notifyWriteBefore(dstAddress, data, mode); + } + } + + @Override + public void notifyWriteAfter(int dstAddress, int data, int mode) { + MemoryMonitor[] listeners = this.listeners; + for(MemoryMonitor listener : listeners) { + listener.notifyWriteAfter(dstAddress, data, mode); + } + } + + } } diff --git a/se/sics/mspsim/core/MemoryMonitorProxy.java b/se/sics/mspsim/core/MemoryMonitorProxy.java deleted file mode 100644 index dc0003a..0000000 --- a/se/sics/mspsim/core/MemoryMonitorProxy.java +++ /dev/null @@ -1,73 +0,0 @@ -package se.sics.mspsim.core; - -import se.sics.mspsim.util.ArrayUtils; - -public class MemoryMonitorProxy implements MemoryMonitor { - private MemoryMonitor[] monitors; - - public MemoryMonitorProxy(MemoryMonitor mon1, MemoryMonitor mon2) { - monitors = new MemoryMonitor[] { mon1, mon2 }; - } - - public static MemoryMonitor addMemoryMonitor(MemoryMonitor MemoryMonitor, MemoryMonitor mon) { - if (MemoryMonitor == null) { - return mon; - } - if (MemoryMonitor instanceof MemoryMonitorProxy) { - return ((MemoryMonitorProxy)MemoryMonitor).add(mon); - } - return new MemoryMonitorProxy(MemoryMonitor, mon); - } - - public static MemoryMonitor removeMemoryMonitor(MemoryMonitor MemoryMonitor, MemoryMonitor mon) { - if (MemoryMonitor == mon) { - return null; - } - if (MemoryMonitor instanceof MemoryMonitorProxy) { - return ((MemoryMonitorProxy)MemoryMonitor).remove(mon); - } - return MemoryMonitor; - } - - - public MemoryMonitor add(MemoryMonitor mon) { - monitors = (MemoryMonitor[]) ArrayUtils.add(MemoryMonitor.class, monitors, mon); - return this; - } - - public MemoryMonitor remove(MemoryMonitor mon) { - MemoryMonitor[] mons = (MemoryMonitor[]) ArrayUtils.remove(monitors, mon); - if (mons == null) { - return null; - } - if (mons.length == 1) { - return mons[0]; - } - monitors = mons; - return this; - } - - @Override - public void notifyReadBefore(int addr, int mode, int type) { - // TODO Auto-generated method stub - - } - - @Override - public void notifyReadAfter(int addr, int mode, int type) { - // TODO Auto-generated method stub - - } - - @Override - public void notifyWriteBefore(int dstAddress, int data, int mode) { - // TODO Auto-generated method stub - - } - - @Override - public void notifyWriteAfter(int dstAddress, int data, int mode) { - // TODO Auto-generated method stub - - } -} diff --git a/se/sics/mspsim/core/NoMemSegment.java b/se/sics/mspsim/core/NoMemSegment.java index 3b85434..d784037 100644 --- a/se/sics/mspsim/core/NoMemSegment.java +++ b/se/sics/mspsim/core/NoMemSegment.java @@ -2,18 +2,16 @@ public class NoMemSegment implements Memory { - int memory[]; - MSP430Core core; - int mask; + private final MSP430Core core; + private final int mask; NoMemSegment(MSP430Core core, int mask) { this.core = core; - memory = core.memory; this.mask = mask; } @Override - public int read(int address, int mode, int type) throws EmulationException { + public int read(int address, int mode, AccessType type) throws EmulationException { if ((address & 0xfff00) != mask) { core.currentSegment = core.memorySegments[address >> 8]; return core.currentSegment.read(address, mode, type); diff --git a/se/sics/mspsim/core/RAMSegment.java b/se/sics/mspsim/core/RAMSegment.java index 2c9daf0..f7df5a7 100644 --- a/se/sics/mspsim/core/RAMSegment.java +++ b/se/sics/mspsim/core/RAMSegment.java @@ -2,9 +2,9 @@ public class RAMSegment implements Memory { - int memory[]; - MSP430Core core; - int mask; + private final MSP430Core core; + private final int memory[]; + private final int mask; public RAMSegment(MSP430Core core, int mask) { this.core = core; @@ -13,7 +13,7 @@ public RAMSegment(MSP430Core core, int mask) { } @Override - public int read(int address, int mode, int type) throws EmulationException { + public int read(int address, int mode, AccessType type) throws EmulationException { if ((address & 0xfff00) != mask) { core.currentSegment = core.memorySegments[address >> 8]; return core.currentSegment.read(address, mode, type); diff --git a/se/sics/mspsim/core/RegisterMonitor.java b/se/sics/mspsim/core/RegisterMonitor.java index 626b365..9515248 100644 --- a/se/sics/mspsim/core/RegisterMonitor.java +++ b/se/sics/mspsim/core/RegisterMonitor.java @@ -1,5 +1,7 @@ package se.sics.mspsim.core; +import se.sics.mspsim.util.ProxySupport; + public interface RegisterMonitor { public void notifyReadBefore(int reg, int mode); @@ -8,4 +10,70 @@ public void notifyWriteBefore(int reg, int data, int mode); public void notifyWriteAfter(int reg, int data, int mode); + public static class Adapter implements RegisterMonitor { + + @Override + public void notifyReadBefore(int reg, int mode) { + } + + @Override + public void notifyReadAfter(int reg, int mode) { + } + + @Override + public void notifyWriteBefore(int reg, int data, int mode) { + } + + @Override + public void notifyWriteAfter(int reg, int data, int mode) { + } + + } + + public static class Proxy extends ProxySupport<RegisterMonitor> implements RegisterMonitor { + public static final Proxy INSTANCE = new Proxy(); + + private Proxy() { + } + + @Override + protected RegisterMonitor create(RegisterMonitor oldListener, RegisterMonitor newListener) { + Proxy proxy = new Proxy(); + proxy.listeners = new RegisterMonitor[] { oldListener, newListener }; + return proxy; + } + + @Override + public void notifyReadBefore(int reg, int mode) { + RegisterMonitor[] listeners = this.listeners; + for(RegisterMonitor listener : listeners) { + listener.notifyReadBefore(reg, mode); + } + } + + @Override + public void notifyReadAfter(int reg, int mode) { + RegisterMonitor[] listeners = this.listeners; + for(RegisterMonitor listener : listeners) { + listener.notifyReadAfter(reg, mode); + } + } + + @Override + public void notifyWriteBefore(int reg, int data, int mode) { + RegisterMonitor[] listeners = this.listeners; + for(RegisterMonitor listener : listeners) { + listener.notifyWriteBefore(reg, data, mode); + } + } + + @Override + public void notifyWriteAfter(int reg, int data, int mode) { + RegisterMonitor[] listeners = this.listeners; + for(RegisterMonitor listener : listeners) { + listener.notifyWriteAfter(reg, data, mode); + } + } + + } } diff --git a/se/sics/mspsim/core/WatchedMemory.java b/se/sics/mspsim/core/WatchedMemory.java index e79c091..ace05b0 100644 --- a/se/sics/mspsim/core/WatchedMemory.java +++ b/se/sics/mspsim/core/WatchedMemory.java @@ -1,63 +1,79 @@ package se.sics.mspsim.core; - import se.sics.mspsim.util.ArrayUtils; public class WatchedMemory implements Memory { - MemoryMonitor watchPoints[][] = new MemoryMonitor[Memory.SEGMENT_SIZE][]; - Memory wrappedMemory; - private int start = 0; + private final MSP430Core core; + private final int start; + private final Memory wrappedMemory; + private final MemoryMonitor watchPoints[][] = new MemoryMonitor[Memory.SEGMENT_SIZE][]; - WatchedMemory(int start, Memory wrapped) { + WatchedMemory(MSP430Core core, int start, Memory wrapped) { + this.core = core; this.start = start; - wrappedMemory = wrapped; + this.wrappedMemory = wrapped; } @Override - public int read(int address, int mode, int type) throws EmulationException { + public int read(int address, int mode, AccessType type) throws EmulationException { + if ((address & 0xfff00) != start) { + core.currentSegment = core.memorySegments[address >> 8]; + return core.currentSegment.read(address, mode, type); + } int a = address - start; + int val; MemoryMonitor mons[] = watchPoints[a]; if (mons != null) { - for(int i = 0; i < mons.length; i++){ - mons[i].notifyReadBefore(address, mode, type); + for(MemoryMonitor mon : mons){ + mon.notifyReadBefore(address, mode, type); } + val = wrappedMemory.read(address, mode, type); + for(MemoryMonitor mon : mons){ + mon.notifyReadAfter(address, mode, type); } - int val = wrappedMemory.read(address, mode, type); - if (mons != null) { - for(int i = 0; i < mons.length; i++){ - mons[i].notifyReadAfter(address, mode, type); - } + } else { + val = wrappedMemory.read(address, mode, type); } return val; } @Override - public void write(int dstAddress, int dst, int mode) - throws EmulationException { + public void write(int dstAddress, int dst, int mode) throws EmulationException { + if ((dstAddress & 0xfff00) != start) { + core.currentSegment = core.memorySegments[dstAddress >> 8]; + core.currentSegment.write(dstAddress, dst, mode); + return; + } int a = dstAddress - start; MemoryMonitor mons[] = watchPoints[a]; if (mons != null) { - for(int i = 0; i < mons.length; i++){ - mons[i].notifyWriteBefore(dstAddress, dst, mode); + for(MemoryMonitor mon : mons){ + mon.notifyWriteBefore(dstAddress, dst, mode); } + wrappedMemory.write(dstAddress, dst, mode); + for(MemoryMonitor mon : mons){ + mon.notifyWriteAfter(dstAddress, dst, mode); } + } else { wrappedMemory.write(dstAddress, dst, mode); - if (mons != null) { - for(int i = 0; i < mons.length; i++){ - mons[i].notifyWriteAfter(dstAddress, dst, mode); } } + + public boolean hasWatchPoint(int address) { + MemoryMonitor[] monitors = watchPoints[address - start]; + return monitors != null; } public synchronized void addWatchPoint(int address, MemoryMonitor mon) { MemoryMonitor[] monitors = watchPoints[address - start]; - monitors = (MemoryMonitor[]) ArrayUtils.add(MemoryMonitor.class, monitors, mon); + monitors = ArrayUtils.add(MemoryMonitor.class, monitors, mon); watchPoints[address - start] = monitors; } public synchronized void removeWatchPoint(int address, MemoryMonitor mon) { MemoryMonitor[] monitors = watchPoints[address - start]; - monitors = (MemoryMonitor[]) ArrayUtils.remove(monitors, mon); + monitors = ArrayUtils.remove(monitors, mon); watchPoints[address - start] = monitors; } + } diff --git a/se/sics/mspsim/plugin/ContikiChecker.java b/se/sics/mspsim/plugin/ContikiChecker.java index 76468ca..fc31209 100644 --- a/se/sics/mspsim/plugin/ContikiChecker.java +++ b/se/sics/mspsim/plugin/ContikiChecker.java @@ -40,11 +40,12 @@ package se.sics.mspsim.plugin; import java.util.Hashtable; + import se.sics.mspsim.cli.BasicAsyncCommand; import se.sics.mspsim.cli.CommandContext; import se.sics.mspsim.cli.CommandHandler; -import se.sics.mspsim.core.MemoryMonitor; import se.sics.mspsim.core.MSP430; +import se.sics.mspsim.core.MemoryMonitor; import se.sics.mspsim.core.Profiler; import se.sics.mspsim.profiler.CallListener; import se.sics.mspsim.util.ActiveComponent; @@ -81,7 +82,7 @@ public int executeCommand(final CommandContext context) { context.err.println("already running"); return 1; } - cpu = (MSP430) registry.getComponent(MSP430.class); + cpu = registry.getComponent(MSP430.class); profiler = cpu.getProfiler(); if (profiler == null) { context.err.println("no profiler available"); @@ -91,26 +92,13 @@ public int executeCommand(final CommandContext context) { profiler.addCallListener(ContikiChecker.this); context.out.println("Installing watchpoints..."); - monitor = new MemoryMonitor() { - public void cpuAction(int type, int adr, int data) { - if (type == MemoryMonitor.MEMORY_WRITE) { - context.out.println("Warning: write to " + adr + + monitor = new MemoryMonitor.Adapter() { + @Override + public void notifyWriteBefore(int dstAddress, int data, int mode) { + context.out.println("Warning: write to " + dstAddress + " from " + profiler.getCall(0)); //profiler.printStackTrace(context.out); } - } - public void notifyReadBefore(int addr, int mode, - int type) { - } - public void notifyReadAfter(int addr, int mode, int type) { - } - public void notifyWriteBefore(int dstAddress, int data, - int mode) { - cpuAction(MemoryMonitor.MEMORY_WRITE, dstAddress, data); - } - public void notifyWriteAfter(int dstAddress, int data, - int mode) { - } }; for (int i = 0; i < 0x100; i++) { cpu.addWatchPoint(i, monitor); diff --git a/se/sics/mspsim/ui/CPUHeatMap.java b/se/sics/mspsim/ui/CPUHeatMap.java index 0d8fd2b..bff9fa6 100644 --- a/se/sics/mspsim/ui/CPUHeatMap.java +++ b/se/sics/mspsim/ui/CPUHeatMap.java @@ -11,6 +11,7 @@ import javax.swing.JComponent; import javax.swing.Timer; +import se.sics.mspsim.core.Memory; import se.sics.mspsim.core.MemoryMonitor; import se.sics.mspsim.core.MSP430Core; @@ -114,18 +115,18 @@ public void paint(Graphics g) { g.drawImage(heatmap, 0, 0, getWidth(), getHeight(), this); } - public void cpuAction(int type, int adr, int data) { + private void cpuAction(int adr, Memory.AccessType type) { int val = 0; int f = 1; if (mode == 1) f = 40; switch (type) { - case MemoryMonitor.EXECUTE: + case EXECUTE: val = heatE[adr] = heatE[adr] + f; break; - case MemoryMonitor.MEMORY_READ: + case READ: val = heatR[adr] = heatR[adr] + f; break; - case MemoryMonitor.MEMORY_WRITE: + case WRITE: val = heatW[adr] = heatW[adr] + f; break; } @@ -135,27 +136,21 @@ public void cpuAction(int type, int adr, int data) { } @Override - public void notifyReadBefore(int addr, int mode, int type) { - // TODO Auto-generated method stub - + public void notifyReadBefore(int addr, int mode, Memory.AccessType type) { + cpuAction(addr, type); } @Override - public void notifyReadAfter(int addr, int mode, int type) { - // TODO Auto-generated method stub - + public void notifyReadAfter(int addr, int mode, Memory.AccessType type) { } @Override public void notifyWriteBefore(int dstAddress, int data, int mode) { - // TODO Auto-generated method stub - + cpuAction(dstAddress, Memory.AccessType.WRITE); } @Override public void notifyWriteAfter(int dstAddress, int data, int mode) { - // TODO Auto-generated method stub - } } diff --git a/se/sics/mspsim/ui/StackUI.java b/se/sics/mspsim/ui/StackUI.java index eca3fd5..c6c0200 100644 --- a/se/sics/mspsim/ui/StackUI.java +++ b/se/sics/mspsim/ui/StackUI.java @@ -43,8 +43,8 @@ import javax.swing.JPanel; -import se.sics.mspsim.core.MemoryMonitor; import se.sics.mspsim.core.MSP430; +import se.sics.mspsim.core.RegisterMonitor; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.MapTable; import se.sics.mspsim.util.ServiceComponent; @@ -56,7 +56,7 @@ private static final int STACK_FRAME = 1024; private int updateCyclePeriod = 2500; - private MSP430 cpu; + private final MSP430 cpu; private int heapStartAddress; private int stackStartAddress = 0xa00; private ChartPanel chartPanel; @@ -80,6 +80,7 @@ private ComponentRegistry registry; private ManagedWindow window; + private RegisterMonitor registerMonitor; private String name; @@ -91,7 +92,6 @@ public StackUI(MSP430 cpu, int updateCyclePeriod) { super(new BorderLayout()); this.updateCyclePeriod = updateCyclePeriod; this.cpu = cpu; -// this.cpu.addRegisterWriteMonitor(MSP430.SP, this); if (cpu.getDisAsm() != null) { MapTable mapTable = cpu.getDisAsm().getMap(); @@ -133,11 +133,36 @@ private void setup() { setSize(320, 200); setMinimumSize(new Dimension(320, 200)); - WindowManager wm = (WindowManager) registry.getComponent("windowManager"); + WindowManager wm = registry.getComponent(WindowManager.class); if (wm != null) { window = wm.createWindow("stackui"); window.add(this); } + + registerMonitor = new RegisterMonitor.Adapter() { + @Override + public void notifyWriteBefore(int type, int adr, int data) { + int size = ((stackStartAddress - data) + 0xffff) % 0xffff; + if (minData[pos] > size) { + minData[pos] = size; + } + if (m... [truncated message content] |
From: Joakim E. <jo...@us...> - 2012-03-22 18:53:58
|
The branch "master" has been updated via 48de0943bf6e2e2d353ebfa722823992d3082e07 (commit) via 5f6d1a4b259db93c8170d37ac4c0794dee7b614e (commit) from a4f2fbf314d0444069a375e182760eec40211b21 (commit) Changed paths: C088 se/sics/mspsim/core/Memory.java se/sics/mspsim/chip/Memory.java M se/sics/mspsim/cli/DebugCommands.java M se/sics/mspsim/config/MSP430f1611Config.java M se/sics/mspsim/core/DMA.java A se/sics/mspsim/core/FlashSegment.java A se/sics/mspsim/core/IOSegment.java M se/sics/mspsim/core/MSP430Config.java M se/sics/mspsim/core/MSP430Constants.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/core/Memory.java C084 se/sics/mspsim/core/CPUMonitor.java se/sics/mspsim/core/MemoryMonitor.java A se/sics/mspsim/core/MemoryMonitorProxy.java A se/sics/mspsim/core/NoMemSegment.java A se/sics/mspsim/core/RAMSegment.java A se/sics/mspsim/core/RegisterMonitor.java A se/sics/mspsim/core/WatchedMemory.java M se/sics/mspsim/debug/DwarfReader.java M se/sics/mspsim/plugin/ContikiChecker.java M se/sics/mspsim/ui/CPUHeatMap.java M se/sics/mspsim/ui/StackUI.java M se/sics/mspsim/util/GDBStubs.java M se/sics/mspsim/util/StackMonitor.java - Log ----------------------------------------------------------------- commit 48de0943bf6e2e2d353ebfa722823992d3082e07 Merge: 5f6d1a4 a4f2fbf Author: Joakim Eriksson <jo...@si...> Date: Thu Mar 22 19:52:24 2012 +0100 updated APIs diff --cc se/sics/mspsim/chip/Memory.java index 0000000,aba854f..c163273 mode 000000,100644..100755 --- a/se/sics/mspsim/chip/Memory.java +++ b/se/sics/mspsim/chip/Memory.java @@@ -1,0 -1,52 +1,48 @@@ + /** + * Copyright (c) 2007, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of MSPSim. + * + * $Id: $ + * + * ----------------------------------------------------------------- + * + * Memory + * + * Author : Joakim Eriksson + * Created : Sept 15 22:00:00 2008 + * Updated : $Date: 2008-03-11 16:32:12 +0100 (ti, 11 mar 2008) $ + * $Revision: 177 $ + */ -package se.sics.mspsim.core; ++package se.sics.mspsim.chip; + + public interface Memory { + - public int readByte(int address); - public void writeByte(int address, int data); - - /** - * getSize returns the size of memory in bytes. - */ - public int getSize(); ++ public int readByte(int address); ++ public void writeByte(int dstAddress, int dst); ++ + } diff --cc se/sics/mspsim/cli/DebugCommands.java index a3714b2,a3714b2..025cb23 --- a/se/sics/mspsim/cli/DebugCommands.java +++ b/se/sics/mspsim/cli/DebugCommands.java @@@ -40,7 -40,7 +40,7 @@@ import se.sics.mspsim.core.EmulationExc import se.sics.mspsim.core.Loggable; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430Constants; --import se.sics.mspsim.core.Memory; ++import se.sics.mspsim.chip.Memory; import se.sics.mspsim.platform.GenericNode; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.DebugInfo; @@@ -74,10 -74,10 +74,16 @@@ public class DebugCommands implements C return 1; } monitor = new CPUMonitor() { -- public void cpuAction(int type, int adr, int data) { ++ public void notifyReadBefore(int type, int adr, int data) { context.out.println("*** Break at $" + cpu.getAddressAsString(adr)); cpu.stop(); } ++ public void notifyReadAfter(int addr, int mode, int type) { ++ } ++ public void notifyWriteBefore(int dstAddress, int data, int mode) { ++ } ++ public void notifyWriteAfter(int dstAddress, int data, int mode) { ++ } }; cpu.addWatchPoint(address, monitor); context.err.println("Breakpoint set at $" + cpu.getAddressAsString(address)); @@@ -146,6 -146,6 +152,17 @@@ } } } ++ ++ public void notifyReadBefore(int addr, int mode, int type) { ++ cpuAction(CPUMonitor.MEMORY_READ, addr, 0); ++ } ++ public void notifyReadAfter(int addr, int mode, int type) { ++ } ++ public void notifyWriteBefore(int dstAddress, int data, int mode) { ++ cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, data); ++ } ++ public void notifyWriteAfter(int dstAddress, int data, int mode) { ++ } }; for (int i = 0; i < length; i++) { @@@ -198,6 -198,6 +215,16 @@@ context.out.println(data); } } ++ public void notifyReadBefore(int addr, int mode, int type) { ++ cpuAction(CPUMonitor.MEMORY_READ, addr, 0); ++ } ++ public void notifyReadAfter(int addr, int mode, int type) { ++ } ++ public void notifyWriteBefore(int dstAddress, int data, int mode) { ++ cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, data); ++ } ++ public void notifyWriteAfter(int dstAddress, int data, int mode) { ++ } }; cpu.addRegisterWriteMonitor(register, monitor); context.err.println("Watch set for register " + getRegisterName(register)); @@@ -336,7 -336,7 +363,8 @@@ int adr = context.getArgumentAsAddress(0); if (adr >= 0) { try { -- context.out.println(context.getArgument(0) + " = $" + Utils.hex16(cpu.read(adr, adr >= 0x100 ? MSP430Constants.MODE_WORD : MSP430Constants.MODE_BYTE))); ++ context.out.println(context.getArgument(0) + " = $" + ++ Utils.hex16(cpu.currentSegment.read(adr, adr >= 0x100 ? MSP430Constants.MODE_WORD : MSP430Constants.MODE_BYTE, 0))); } catch (Exception e) { e.printStackTrace(context.err); } @@@ -462,7 -462,7 +490,7 @@@ int val = context.getArgumentAsInt(i); boolean word = Utils.size(type) == 2 | val > 0xff; try { -- cpu.write(adr, val, word ? MSP430Constants.MODE_WORD : MSP430Constants.MODE_BYTE); ++ cpu.currentSegment.write(adr, val, word ? MSP430Constants.MODE_WORD : MSP430Constants.MODE_BYTE); adr += word ? 2 : 1; } catch (EmulationException e) { e.printStackTrace(context.out); @@@ -470,7 -470,7 +498,7 @@@ } else if (mode == Utils.ASCII) { String data = context.getArgument(i); for (int j = 0; j < data.length(); j++) { -- cpu.write(adr++, data.charAt(j) & 0xff, MSP430Constants.MODE_WORD); ++ cpu.currentSegment.write(adr++, data.charAt(j) & 0xff, MSP430Constants.MODE_WORD); } } } diff --cc se/sics/mspsim/config/MSP430f1611Config.java index 610a475,610a475..85a5f51 --- a/se/sics/mspsim/config/MSP430f1611Config.java +++ b/se/sics/mspsim/config/MSP430f1611Config.java @@@ -168,7 -168,7 +168,4 @@@ public class MSP430f1611Config extends return 3 + 6; } -- -- -- } diff --cc se/sics/mspsim/core/MSP430Core.java index 474ce51,f3194b2..04df088 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@@ -1690,16 -1774,30 +1690,29 @@@ public class MSP430Core extends Chip im } break; - case AM_INDEX: - // Indexed if reg != PC & CG1/CG2 - will PC be incremented? - srcAddress = readRegisterCG(srcRegister, as) + currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); - // memory[pc] + (memory[pc + 1] << 8); + case AM_INDEX: { + // Indexed if reg != PC & CG1/CG2 - will PC be incremented? + int sval = readRegisterCG(srcRegister, as); + + /* Support for MSP430X and below / above 64 KB */ + /* if register is pointing to <64KB then it needs to be truncated to below 64 */ + if (sval < 0xffff) { - srcAddress = (sval + read(pc, MODE_WORD)) & 0xffff; ++ srcAddress = (sval + currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ)) & 0xffff; + } else { - srcAddress = read(pc, MODE_WORD); ++ srcAddress = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + if ((srcAddress & 0x8000) > 0) { + // Negative index + srcAddress |= 0xf0000; + } + srcAddress += sval; + srcAddress &= 0xfffff; + } - // When is PC incremented - assuming immediately after "read"? - - - incRegister(PC, 2); + + incRegister(PC, 2); cycles += dstRegMode ? 3 : 6; break; + } // Indirect register case AM_IND_REG: srcAddress = readRegister(srcRegister); diff --cc se/sics/mspsim/debug/DwarfReader.java index 38ee5d5,38ee5d5..7539a76 --- a/se/sics/mspsim/debug/DwarfReader.java +++ b/se/sics/mspsim/debug/DwarfReader.java @@@ -49,7 -49,7 +49,7 @@@ import se.sics.mspsim.util.ELFSection public class DwarfReader implements ELFDebug { -- public static final boolean DEBUG = false; ++ public static final boolean DEBUG = true; //false; /* Operands for lines */ public static final int DW_LNS_EXT = 0; diff --cc se/sics/mspsim/plugin/ContikiChecker.java index 7dccde2,7dccde2..76468ca --- a/se/sics/mspsim/plugin/ContikiChecker.java +++ b/se/sics/mspsim/plugin/ContikiChecker.java @@@ -43,7 -43,7 +43,7 @@@ import java.util.Hashtable import se.sics.mspsim.cli.BasicAsyncCommand; import se.sics.mspsim.cli.CommandContext; import se.sics.mspsim.cli.CommandHandler; --import se.sics.mspsim.core.CPUMonitor; ++import se.sics.mspsim.core.MemoryMonitor; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.Profiler; import se.sics.mspsim.profiler.CallListener; @@@ -59,7 -59,7 +59,7 @@@ public class ContikiChecker implements private ComponentRegistry registry; private CommandContext context; -- private CPUMonitor monitor; ++ private MemoryMonitor monitor; private MSP430 cpu; private Profiler profiler; @@@ -91,14 -91,14 +91,26 @@@ profiler.addCallListener(ContikiChecker.this); context.out.println("Installing watchpoints..."); -- monitor = new CPUMonitor() { ++ monitor = new MemoryMonitor() { public void cpuAction(int type, int adr, int data) { -- if (type == CPUMonitor.MEMORY_WRITE) { ++ if (type == MemoryMonitor.MEMORY_WRITE) { context.out.println("Warning: write to " + adr + " from " + profiler.getCall(0)); //profiler.printStackTrace(context.out); } } ++ public void notifyReadBefore(int addr, int mode, ++ int type) { ++ } ++ public void notifyReadAfter(int addr, int mode, int type) { ++ } ++ public void notifyWriteBefore(int dstAddress, int data, ++ int mode) { ++ cpuAction(MemoryMonitor.MEMORY_WRITE, dstAddress, data); ++ } ++ public void notifyWriteAfter(int dstAddress, int data, ++ int mode) { ++ } }; for (int i = 0; i < 0x100; i++) { cpu.addWatchPoint(i, monitor); diff --cc se/sics/mspsim/ui/CPUHeatMap.java index cf37744,cf37744..0d8fd2b --- a/se/sics/mspsim/ui/CPUHeatMap.java +++ b/se/sics/mspsim/ui/CPUHeatMap.java @@@ -11,10 -11,10 +11,10 @@@ import java.awt.image.BufferedImage import javax.swing.JComponent; import javax.swing.Timer; --import se.sics.mspsim.core.CPUMonitor; ++import se.sics.mspsim.core.MemoryMonitor; import se.sics.mspsim.core.MSP430Core; --public class CPUHeatMap extends JComponent implements CPUMonitor { ++public class CPUHeatMap extends JComponent implements MemoryMonitor { private static final long serialVersionUID = -7964848220064713887L; @@@ -119,13 -119,13 +119,13 @@@ int f = 1; if (mode == 1) f = 40; switch (type) { -- case CPUMonitor.EXECUTE: ++ case MemoryMonitor.EXECUTE: val = heatE[adr] = heatE[adr] + f; break; -- case CPUMonitor.MEMORY_READ: ++ case MemoryMonitor.MEMORY_READ: val = heatR[adr] = heatR[adr] + f; break; -- case CPUMonitor.MEMORY_WRITE: ++ case MemoryMonitor.MEMORY_WRITE: val = heatW[adr] = heatW[adr] + f; break; } @@@ -134,4 -134,4 +134,28 @@@ } } ++ @Override ++ public void notifyReadBefore(int addr, int mode, int type) { ++ // TODO Auto-generated method stub ++ ++ } ++ ++ @Override ++ public void notifyReadAfter(int addr, int mode, int type) { ++ // TODO Auto-generated method stub ++ ++ } ++ ++ @Override ++ public void notifyWriteBefore(int dstAddress, int data, int mode) { ++ // TODO Auto-generated method stub ++ ++ } ++ ++ @Override ++ public void notifyWriteAfter(int dstAddress, int data, int mode) { ++ // TODO Auto-generated method stub ++ ++ } ++ } diff --cc se/sics/mspsim/ui/StackUI.java index 02b1442,02b1442..eca3fd5 --- a/se/sics/mspsim/ui/StackUI.java +++ b/se/sics/mspsim/ui/StackUI.java @@@ -43,13 -43,13 +43,13 @@@ import java.awt.Graphics import javax.swing.JPanel; --import se.sics.mspsim.core.CPUMonitor; ++import se.sics.mspsim.core.MemoryMonitor; import se.sics.mspsim.core.MSP430; import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.MapTable; import se.sics.mspsim.util.ServiceComponent; --public class StackUI extends JPanel implements CPUMonitor, ServiceComponent { ++public class StackUI extends JPanel implements ServiceComponent { private static final long serialVersionUID = 8648239617509299768L; @@@ -91,7 -91,7 +91,7 @@@ super(new BorderLayout()); this.updateCyclePeriod = updateCyclePeriod; this.cpu = cpu; -- this.cpu.addRegisterWriteMonitor(MSP430.SP, this); ++// this.cpu.addRegisterWriteMonitor(MSP430.SP, this); if (cpu.getDisAsm() != null) { MapTable mapTable = cpu.getDisAsm().getMap(); diff --cc se/sics/mspsim/util/GDBStubs.java index 51584c7,51584c7..d4d4900 --- a/se/sics/mspsim/util/GDBStubs.java +++ b/se/sics/mspsim/util/GDBStubs.java @@@ -176,7 -176,7 +176,7 @@@ public class GDBStubs implements Runnab for (int i = 0; i < len; i++) { System.out.println("Writing: " + cmdBytes[cPos] + " to " + addr + " cpos=" + cPos); -- cpu.write(addr++, cmdBytes[cPos++], MSP430Constants.MODE_BYTE); ++ cpu.currentSegment.write(addr++, cmdBytes[cPos++], MSP430Constants.MODE_BYTE); } sendResponse(OK); } diff --cc se/sics/mspsim/util/StackMonitor.java index 6b44eff,6b44eff..7f6617f --- a/se/sics/mspsim/util/StackMonitor.java +++ b/se/sics/mspsim/util/StackMonitor.java @@@ -1,9 -1,9 +1,9 @@@ package se.sics.mspsim.util; --import se.sics.mspsim.core.CPUMonitor; ++import se.sics.mspsim.core.MemoryMonitor; import se.sics.mspsim.core.MSP430; --public class StackMonitor implements CPUMonitor { ++public class StackMonitor {//implements CPUMonitor { private MSP430 cpu; private int heapStartAddress; @@@ -47,7 -47,7 +47,7 @@@ public StackMonitor(MSP430 cpu) { this.cpu = cpu; -- this.cpu.addRegisterWriteMonitor(MSP430.SP, this); ++// this.cpu.addRegisterWriteMonitor(MSP430.SP, this); Object p = cpu.getRegistry().getComponent("profiler"); if (p instanceof SimpleProfiler) { ((SimpleProfiler) p).setStackMonitor(this); commit 5f6d1a4b259db93c8170d37ac4c0794dee7b614e Author: Joakim Eriksson <jo...@si...> Date: Thu Mar 22 19:12:09 2012 +0100 changed memory handling diff --git a/se/sics/mspsim/core/DMA.java b/se/sics/mspsim/core/DMA.java index 79ca9e3..9b058b5 100644 --- a/se/sics/mspsim/core/DMA.java +++ b/se/sics/mspsim/core/DMA.java @@ -130,12 +130,12 @@ public void trigger(DMATrigger trigger, int index) { /* perform memory move and possibly clear triggering flag!!! */ /* NOTE: show config byte/word also !!! */ if (enable) { - int data = cpu.read(currentSourceAddress, MSP430Constants.MODE_BYTE); + int data = cpu.currentSegment.read(currentSourceAddress, MSP430Constants.MODE_BYTE, Memory.TYPE_READ); if (DEBUG) log("DMA Triggered reading from: " + currentSourceAddress + " => " + data + " " + (char) data + " size:" + size + " index:" + index); trigger.clearDMATrigger(index); - DMA.this.cpu.write(currentDestinationAddress, data, MSP430Constants.MODE_BYTE); + DMA.this.cpu.currentSegment.write(currentDestinationAddress, data, MSP430Constants.MODE_BYTE); currentSourceAddress += srcIncr; currentDestinationAddress += dstIncr; diff --git a/se/sics/mspsim/core/FlashSegment.java b/se/sics/mspsim/core/FlashSegment.java new file mode 100644 index 0000000..ffbcb76 --- /dev/null +++ b/se/sics/mspsim/core/FlashSegment.java @@ -0,0 +1,63 @@ +package se.sics.mspsim.core; + +public class FlashSegment implements Memory { + + int memory[]; + MSP430Core core; + int mask; + private Flash flash; + + public FlashSegment(MSP430Core core, Flash flash, int mask) { + this.core = core; + memory = core.memory; + this.mask = mask; + this.flash = flash; + } + + @Override + public int read(int address, int mode, int type) throws EmulationException { + if ((address & 0xfff00) != mask) { + core.currentSegment = core.memorySegments[address >> 8]; + return core.currentSegment.read(address, mode, type); + } + + int val = 0; + if (core.isFlashBusy && flash.addressInFlash(address)) { + flash.notifyRead(address); + } + + val = memory[address] & 0xff; + if (mode > MSP430Constants.MODE_BYTE) { + val |= (memory[address + 1] << 8); + if ((address & 1) != 0) { + core.printWarning(MSP430Constants.MISALIGNED_READ, address); + } + if (mode == MSP430Constants.MODE_WORD20) { + /* will the read really get data from the full word? CHECK THIS */ + val |= (memory[address + 2] << 16) | (memory[address + 3] << 24); + val &= 0xfffff; + } else { + val &= 0xffff; + } + } + return val; + } + + @Override + public void write(int dstAddress, int dst, int mode) + throws EmulationException { + if ((dstAddress & 0xfff00) != mask) { + core.currentSegment = core.memorySegments[dstAddress >> 8]; + core.currentSegment.write(dstAddress, dst, mode); + return; + } + + boolean word = mode != MSP430Constants.MODE_BYTE; + + flash.flashWrite(dstAddress, dst & 0xffff, word); + if (mode > MSP430Constants.MODE_WORD) { + flash.flashWrite(dstAddress + 2, dst >> 16, word); + } + } + +} diff --git a/se/sics/mspsim/core/IOSegment.java b/se/sics/mspsim/core/IOSegment.java new file mode 100644 index 0000000..494ffcc --- /dev/null +++ b/se/sics/mspsim/core/IOSegment.java @@ -0,0 +1,48 @@ +package se.sics.mspsim.core; + +import se.sics.mspsim.util.Utils; + +public class IOSegment implements Memory { + + int memory[]; + MSP430Core core; + int mask; + + IOSegment(MSP430Core core, int mask) { + this.core = core; + memory = core.memory; + this.mask = mask; + } + + @Override + public int read(int address, int mode, int type) throws EmulationException { + if ((address & 0xfff00) != mask) { + core.currentSegment = core.memorySegments[address >> 8]; + return core.currentSegment.read(address, mode, type); + } + boolean word = mode != MSP430Constants.MODE_BYTE; + // Only word reads at 0x1fe which is highest address... + int val = core.memIn[address].read(address, word, core.cycles); + if (mode == MSP430Constants.MODE_WORD20) { + val |= core.memIn[address + 2].read(address, word, core.cycles) << 16; + } + return val; + } + + @Override + public void write(int dstAddress, int dst, int mode) + throws EmulationException { + if ((dstAddress & 0xfff00) != mask) { + core.currentSegment = core.memorySegments[dstAddress >> 8]; + core.currentSegment.write(dstAddress, dst, mode); + return; + } + boolean word = mode != MSP430Constants.MODE_BYTE; + + if (!word) dst &= 0xff; + core.memOut[dstAddress].write(dstAddress, dst & 0xffff, word, core.cycles); + if (mode > MSP430Constants.MODE_WORD) { + core.memOut[dstAddress].write(dstAddress + 2, dst >> 16, word, core.cycles); + } + } +} diff --git a/se/sics/mspsim/core/MSP430Config.java b/se/sics/mspsim/core/MSP430Config.java index e27d26b..3894224 100644 --- a/se/sics/mspsim/core/MSP430Config.java +++ b/se/sics/mspsim/core/MSP430Config.java @@ -80,6 +80,10 @@ public UARTConfig(int txVector, int rxVector, int txBit, int rxBit, int sftAddr, public int infoMemStart = 0x0000; public int infoMemSize = 2 * 128; + public int ramStart = 0x2000; + public int ramSize = 2048; + + public int flashControllerOffset = 0x128; public boolean MSP430XArch = false; @@ -91,6 +95,18 @@ public UARTConfig(int txVector, int rxVector, int txBit, int rxBit, int sftAddr, public abstract int setup(MSP430Core cpu, ArrayList<IOUnit> ioUnits); + public boolean isRAM(int address) { + return address >= ramStart && address < ramStart + ramSize; + } + + public boolean isFlash(int address) { + return address >= mainFlashStart && address < mainFlashStart + mainFlashSize; + } + + public boolean isIO(int address) { + return address < maxMemIO; + } + public String getAddressAsString(int addr) { return Utils.hex16(addr); } @@ -111,7 +127,8 @@ public void mainFlashConfig(int start, int size) { /* ignored for now */ public void ramConfig(int start, int size) { - + ramStart = start; + ramSize = size; } public void ioMemSize(int size) { diff --git a/se/sics/mspsim/core/MSP430Constants.java b/se/sics/mspsim/core/MSP430Constants.java index 5cc958f..8097c26 100644 --- a/se/sics/mspsim/core/MSP430Constants.java +++ b/se/sics/mspsim/core/MSP430Constants.java @@ -54,6 +54,8 @@ public static final int MODE_WORD = 1; public static final int MODE_WORD20 = 2; + public static final int MODE_BIT_SIZE[] = {8, 16, 20}; + public static final int MODE_MASK[] = {0xff, 0xffff, 0xfffff}; /* memory tags - not used yet*/ diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index a419b18..474ce51 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -63,16 +63,19 @@ // 16 registers of which some are "special" - PC, SP, etc. public int[] reg = new int[16]; - private CPUMonitor globalMonitor; + private MemoryMonitor globalMonitor; - private final CPUMonitor[] regWriteMonitors = new CPUMonitor[16]; - private final CPUMonitor[] regReadMonitors = new CPUMonitor[16]; + private final RegisterMonitor[] regWriteMonitors = new RegisterMonitor[16]; + private final RegisterMonitor[] regReadMonitors = new RegisterMonitor[16]; - private CPUMonitor[] watchPoints; // true => breakpoints can occur! boolean breakpointActive = true; public int memory[]; + + public Memory memorySegments[]; + public Memory currentSegment; + public long cycles = 0; public long cpuCycles = 0; MapTable map; @@ -162,7 +165,22 @@ public MSP430Core(int type, ComponentRegistry registry, MSP430Config config) { MSP430XArch = config.MSP430XArch; memory = new int[MAX_MEM]; - watchPoints = new CPUMonitor[MAX_MEM]; + memorySegments = new Memory[MAX_MEM >> 8]; + + currentSegment = new Memory() { + /* just throw in the right segment... */ + public int read(int address, int mode, int type) throws EmulationException { + currentSegment = memorySegments[address >> 8]; + return currentSegment.read(address, mode, type); + } + public void write(int dstAddress, int dst, int mode) + throws EmulationException { + currentSegment = memorySegments[dstAddress >> 8]; + currentSegment.write(dstAddress, dst, mode); + } + }; + +// watchPoints = new CPUMonitor[MAX_MEM]; System.out.println("Set up MSP430 Core with " + MAX_MEM + " bytes memory"); @@ -257,6 +275,24 @@ public int read(int address, boolean word, long cycles) { ioUnits.add(watchdog); + /* setup memory segments */ + int maxSeg = MAX_MEM >> 8; + for (int i = 0; i < maxSeg; i++) { + if (config.isRAM(i << 8)) { + System.out.println("Setting RAM segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = new RAMSegment(this, (i << 8)); + } else if (config.isFlash(i << 8)) { + System.out.println("Setting Flash segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = new FlashSegment(this, flash, (i << 8)); + } else if (config.isIO(i << 8)) { + System.out.println("Setting IO segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = new IOSegment(this, (i << 8)); + } else { + System.out.println("Setting NoMem segment at: " + Utils.hex16(i << 8)); + memorySegments[i] = new NoMemSegment(this, (i << 8)); + } + } + bcs.reset(0); } @@ -270,17 +306,12 @@ public void setProfiler(Profiler prof) { profiler.setCPU(this); } - public synchronized void addGlobalMonitor(CPUMonitor mon) { - globalMonitor = CPUMonitorProxy.addCPUMonitor(globalMonitor, mon); + public synchronized void addGlobalMonitor(MemoryMonitor mon) { + globalMonitor = MemoryMonitorProxy.addMemoryMonitor(globalMonitor, mon); } - public synchronized void removeGlobalMonitor(CPUMonitor mon) { - globalMonitor = CPUMonitorProxy.removeCPUMonitor(globalMonitor, mon); - } - - @Deprecated - public void setGlobalMonitor(CPUMonitor mon) { - globalMonitor = mon; + public synchronized void removeGlobalMonitor(MemoryMonitor mon) { + globalMonitor = MemoryMonitorProxy.removeMemoryMonitor(globalMonitor, mon); } public ComponentRegistry getRegistry() { @@ -338,69 +369,47 @@ public Loggable getLoggable(String name) { } public boolean hasWatchPoint(int address) { - return watchPoints[address] != null; - } - - public synchronized void addWatchPoint(int address, CPUMonitor mon) { - watchPoints[address] = CPUMonitorProxy.addCPUMonitor(watchPoints[address], mon); - } - - public synchronized void removeWatchPoint(int address, CPUMonitor mon) { - watchPoints[address] = CPUMonitorProxy.removeCPUMonitor(watchPoints[address], mon); + // FIX THIS! + return false; +// return watchPoints[address] != null; } - @Deprecated - public void setBreakPoint(int address, CPUMonitor mon) { - if (mon != null) { - addWatchPoint(address, mon); + public synchronized void addWatchPoint(int address, MemoryMonitor mon) { + WatchedMemory wm; + if (memorySegments[address >> 8] instanceof WatchedMemory) { + wm = (WatchedMemory) memorySegments[address >> 8]; } else { - clearBreakPoint(address); - } - } - - @Deprecated - public boolean hasBreakPoint(int address) { - return watchPoints[address] != null; - } - - @Deprecated - public synchronized void clearBreakPoint(int address) { - watchPoints[address] = null; + wm = new WatchedMemory(address >> 8, memorySegments[address >> 8]); + memorySegments[address >> 8] = wm; } - - public synchronized void addRegisterWriteMonitor(int r, CPUMonitor mon) { - regWriteMonitors[r] = CPUMonitorProxy.addCPUMonitor(regWriteMonitors[r], mon); + wm.addWatchPoint(address, mon); +// watchPoints[address] = CPUMonitorProxy.addCPUMonitor(watchPoints[address], mon); } - public synchronized void removeRegisterWriteMonitor(int r, CPUMonitor mon) { - regWriteMonitors[r] = CPUMonitorProxy.removeCPUMonitor(regWriteMonitors[r], mon); + public synchronized void removeWatchPoint(int address, MemoryMonitor mon) { + if (memorySegments[address >> 8] instanceof WatchedMemory) { + WatchedMemory wm = (WatchedMemory) memorySegments[address >> 8]; + wm.removeWatchPoint(address, mon); } - - public synchronized void addRegisterReadMonitor(int r, CPUMonitor mon) { - regReadMonitors[r] = CPUMonitorProxy.addCPUMonitor(regReadMonitors[r], mon); +// watchPoints[address] = MemoryMonitorProxy.removeMemoryMonitor(watchPoints[address], mon); } - public synchronized void removeRegisterReadMonitor(int r, CPUMonitor mon) { - regReadMonitors[r] = CPUMonitorProxy.removeCPUMonitor(regReadMonitors[r], mon); - } - @Deprecated - public synchronized void setRegisterWriteMonitor(int r, CPUMonitor mon) { - if (mon != null) { - regWriteMonitors[r] = CPUMonitorProxy.addCPUMonitor(regWriteMonitors[r], mon); - } else { - regWriteMonitors[r] = null; - } - } - - @Deprecated - public synchronized void setRegisterReadMonitor(int r, CPUMonitor mon) { - if (mon != null) { - regReadMonitors[r] = CPUMonitorProxy.addCPUMonitor(regReadMonitors[r], mon); - } else { - regReadMonitors[r] = null; - } - } +// public synchronized void addRegisterWriteMonitor(int r, CPUMonitor mon) { +// regWriteMonitors[r] = CPUMonitorProxy.addCPUMonitor(regWriteMonitors[r], mon); +// } +// +// public synchronized void removeRegisterWriteMonitor(int r, CPUMonitor mon) { +// regWriteMonitors[r] = CPUMonitorProxy.removeCPUMonitor(regWriteMonitors[r], mon); +// } +// +// public synchronized void addRegisterReadMonitor(int r, CPUMonitor mon) { +// regReadMonitors[r] = CPUMonitorProxy.addCPUMonitor(regReadMonitors[r], mon); +// } +// +// public synchronized void removeRegisterReadMonitor(int r, CPUMonitor mon) { +// regReadMonitors[r] = CPUMonitorProxy.removeCPUMonitor(regReadMonitors[r], mon); +// } public int[] getMemory() { return memory; @@ -412,10 +421,11 @@ public void writeRegister(int r, int value) { // System.out.println("Writing larger than MAX_MEM to " + r + " value:" + value); // new Throwable().printStackTrace(); // } - CPUMonitor rwm = regWriteMonitors[r]; - if (rwm != null) { - rwm.cpuAction(CPUMonitor.REGISTER_WRITE, r, value); - } +// TODO - add RegisterMonitor for this... + // CPUMonitor rwm = regWriteMonitors[r]; +// if (rwm != null) { +// rwm.cpuAction(CPUMonitor.REGISTER_WRITE, r, value); +// } reg[r] = value; if (r == SR) { boolean oldCpuOff = cpuOff; @@ -462,10 +472,11 @@ public void writeRegister(int r, int value) { } public int readRegister(int r) { - CPUMonitor rrm = regReadMonitors[r]; - if (rrm != null) { - rrm.cpuAction(CPUMonitor.REGISTER_READ, r, reg[r]); - } +// Register monitor here... +// CPUMonitor rrm = regReadMonitors[r]; +// if (rrm != null) { +// rrm.cpuAction(CPUMonitor.REGISTER_READ, r, reg[r]); +// } return reg[r]; } @@ -475,22 +486,22 @@ public int readRegisterCG(int r, int m) { // No monitoring here... just return the CG values return CREG_VALUES[r - 2][m]; } - CPUMonitor rrm = regReadMonitors[r]; - if (rrm != null) { - rrm.cpuAction(CPUMonitor.REGISTER_READ, r, reg[r]); - } +// CPUMonitor rrm = regReadMonitors[r]; +// if (rrm != null) { +// rrm.cpuAction(CPUMonitor.REGISTER_READ, r, reg[r]); +// } return reg[r]; } public int incRegister(int r, int value) { - CPUMonitor rm = regReadMonitors[r]; - if (rm != null) { - rm.cpuAction(CPUMonitor.REGISTER_READ, r, reg[r]); - } - rm = regWriteMonitors[r]; - if (rm != null) { - rm.cpuAction(CPUMonitor.REGISTER_WRITE, r, reg[r] + value); - } +// CPUMonitor rm = regReadMonitors[r]; +// if (rm != null) { +// rm.cpuAction(CPUMonitor.REGISTER_READ, r, reg[r]); +// } +// rm = regWriteMonitors[r]; +// if (rm != null) { +// rm.cpuAction(CPUMonitor.REGISTER_WRITE, r, reg[r] + value); +// } reg[r] += value; return reg[r]; } @@ -748,101 +759,6 @@ public void handlePendingInterrupts() { servicedInterruptUnit = null; } - // Read method that handles read from IO units! - public int read(int address, int mode) throws EmulationException { - int val = 0; - if (address >= MAX_MEM) { - printWarning(ADDRESS_OUT_OF_BOUNDS_READ, address); - address %= MAX_MEM; - } - final boolean word = mode != MODE_BYTE; - // Only word reads at 0x1fe which is highest address... - if (address < MAX_MEM_IO) { - val = memIn[address].read(address, word, cycles); - if (mode == MODE_WORD20) { - val |= memIn[address + 2].read(address, word, cycles) << 16; - } - } else { - if (isFlashBusy && flash.addressInFlash(address)) { - flash.notifyRead(address); - } - - val = memory[address] & 0xff; - if (mode > MODE_BYTE) { - val |= (memory[address + 1] << 8); - if ((address & 1) != 0) { - printWarning(MISALIGNED_READ, address); - } - if (mode == MODE_WORD20) { - /* will the read really get data from the full word? CHECK THIS */ - val |= (memory[address + 2] << 16) | (memory[address + 3] << 24); - val &= 0xfffff; - } else { - val &= 0xffff; - } - } - } - CPUMonitor wp = watchPoints[address]; - if (wp != null) { - wp.cpuAction(CPUMonitor.MEMORY_READ, address, val); - } - /* is a null check as fast as a boolean check ?*/ - wp = globalMonitor; - if (wp != null) { - wp.cpuAction(CPUMonitor.MEMORY_READ, address, val); - } - return val; - } - - public void write(int dstAddress, int dst, int mode) throws EmulationException { - // TODO: optimize memory usage by tagging memory's higher bits. - // will also affect below flash write stuff!!! - if (dstAddress > MAX_MEM) { - printWarning(ADDRESS_OUT_OF_BOUNDS_WRITE, dstAddress); - dstAddress %= MAX_MEM; - } - - /* is a null check as fast as a boolean check? */ - CPUMonitor wp = watchPoints[dstAddress]; - if (wp != null) { - wp.cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, dst); - } - wp = globalMonitor; - if (wp != null) { - wp.cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, dst); - } - - final boolean word = mode != MODE_BYTE; - - // Only word writes at 0x1fe which is highest address... - if (dstAddress < MAX_MEM_IO) { - if (!word) dst &= 0xff; - memOut[dstAddress].write(dstAddress, dst & 0xffff, word, cycles); - if (mode > MODE_WORD) { - memOut[dstAddress].write(dstAddress + 2, dst >> 16, word, cycles); - } - // check for Flash - } else if (flash.addressInFlash(dstAddress)) { - flash.flashWrite(dstAddress, dst & 0xffff, word); - if (mode > MODE_WORD) { - flash.flashWrite(dstAddress + 2, dst >> 16, word); - } - } else { - // assume RAM - memory[dstAddress] = dst & 0xff; - if (word) { - memory[dstAddress + 1] = (dst >> 8) & 0xff; - if ((dstAddress & 1) != 0) { - printWarning(MISALIGNED_WRITE, dstAddress); - } - if (mode > MODE_WORD) { - memory[dstAddress + 2] = (dst >> 16) & 0xff; /* should be 0x0f ?? */ - memory[dstAddress + 3] = (dst >> 24) & 0xff; /* will be only zeroes*/ - } - } - } - } - void profileCall(int dst, int pc) { MapEntry function = map.getEntry(dst); if (function == null) { @@ -903,16 +819,16 @@ private int serviceInterrupt(int pc) { // Push PC and SR to stack // store on stack - always move 2 steps (W) even if B. writeRegister(SP, sp = spBefore - 2); - write(sp, pc, MODE_WORD); + currentSegment.write(sp, pc, MODE_WORD); writeRegister(SP, sp = sp - 2); - write(sp, (sr & 0x0fff) | ((pc & 0xf0000) >> 4), MODE_WORD); + currentSegment.write(sp, (sr & 0x0fff) | ((pc & 0xf0000) >> 4), MODE_WORD); } // Clear SR writeRegister(SR, 0); // sr & ~CPUOFF & ~SCG1 & ~OSCOFF); // Jump to the address specified in the interrupt vector - writeRegister(PC, pc = read(0xfffe - (MAX_INTERRUPT - interruptMax) * 2, MODE_WORD)); + writeRegister(PC, pc = currentSegment.read(0xfffe - (MAX_INTERRUPT - interruptMax) * 2, MODE_WORD, Memory.TYPE_READ)); servicedInterrupt = interruptMax; servicedInterruptUnit = interruptSource[servicedInterrupt]; @@ -993,23 +909,23 @@ public int emulateOP(long maxCycles) throws EmulationException { // This is quite costly... should probably be made more // efficiently - CPUMonitor wp = watchPoints[pc]; - if (wp != null) { - if (breakpointActive) { - wp.cpuAction(CPUMonitor.EXECUTE, pc, 0); - breakpointActive = false; - return -1; - } - // Execute this instruction - this is second call... - breakpointActive = true; - } - wp = globalMonitor; - if (wp != null) { - wp.cpuAction(CPUMonitor.EXECUTE, pc, 0); - } +// CPUMonitor wp = watchPoints[pc]; +// if (wp != null) { +// if (breakpointActive) { +// wp.cpuAction(CPUMonitor.EXECUTE, pc, 0); +// breakpointActive = false; +// return -1; +// } +// // Execute this instruction - this is second call... +// breakpointActive = true; +// } +// wp = globalMonitor; +// if (wp != null) { +// wp.cpuAction(CPUMonitor.EXECUTE, pc, 0); +// } int pcBefore = pc; - instruction = read(pc, MODE_WORD); + instruction = currentSegment.read(pc, MODE_WORD, Memory.TYPE_EXECUTE); int ext3_0 = 0; boolean repeatsInDstReg = false; boolean wordx20 = false; @@ -1034,7 +950,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // that follows the extension word also has a zero bit data // length mode.) wordx20 = (instruction & 0x40) == 0; - instruction = read(pc, MODE_WORD); + instruction = currentSegment.read(pc, MODE_WORD, Memory.TYPE_EXECUTE); // System.out.println("*** Extension word!!! " + Utils.hex16(extWord) + // " read the instruction too: " + Utils.hex16(instruction) + " at " + Utils.hex16(pc - 2)); } else { @@ -1094,7 +1010,7 @@ public int emulateOP(long maxCycles) throws EmulationException { src = readRegister(srcData); // System.out.println("Reading $" + getAddressAsString(src) + // " from register: " + srcData); - dst = read(src, MODE_WORD20); + dst = currentSegment.read(src, MODE_WORD20, Memory.TYPE_READ); // System.out.println("Reading from mem: $" + getAddressAsString(dst)); writeRegister(srcData, src + 4); // System.out.println("*** Writing $" + getAddressAsString(dst) + " to reg: " + dstData); @@ -1103,11 +1019,11 @@ public int emulateOP(long maxCycles) throws EmulationException { cycles += 3; break; case MOVA_ABS2REG: - src = read(pc, MODE_WORD); + src = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); writeRegister(PC, pc += 2); dst = src + (srcData << 16); //System.out.println(Utils.hex20(pc) + " MOVA &ABS Reading from $" + getAddressAsString(dst) + " to reg: " + dstData); - dst = read(dst, MODE_WORD20); + dst = currentSegment.read(dst, MODE_WORD20, Memory.TYPE_READ); //System.out.println(" => $" + getAddressAsString(dst)); writeRegister(dstData, dst); updateStatus = false; @@ -1116,7 +1032,7 @@ public int emulateOP(long maxCycles) throws EmulationException { case MOVA_INDX2REG: /* Read data from address in memory, indexed by source * register, and place into destination register. */ - int index = read(pc, MODE_WORD); + int index = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); int indexModifier = readRegister(srcData); if(index > 0x8000) { index = -(0x10000 - index); @@ -1124,16 +1040,16 @@ public int emulateOP(long maxCycles) throws EmulationException { if(indexModifier > 0x8000) { indexModifier = -(0x10000 - indexModifier); } - writeRegister(dstData, read(indexModifier + index, MODE_WORD20)); + writeRegister(dstData, currentSegment.read(indexModifier + index, MODE_WORD20, Memory.TYPE_READ)); writeRegister(PC, pc += 2); updateStatus = false; cycles += 4; break; case MOVA_REG2ABS: - dst = read(pc, MODE_WORD); + dst = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); writeRegister(PC, pc += 2); - write(dst + (dstData << 16), readRegister(srcData), MODE_WORD20); + currentSegment.write(dst + (dstData << 16), readRegister(srcData), MODE_WORD20); updateStatus = false; cycles += 4; break; @@ -1141,7 +1057,7 @@ public int emulateOP(long maxCycles) throws EmulationException { case MOVA_REG2INDX: /* Read data from register, write to address in memory, * indexed by source register. */ - index = read(pc, MODE_WORD); + index = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); indexModifier = readRegister(dstData); if(index > 0x8000) { index = -(0x10000 - index); @@ -1149,14 +1065,14 @@ public int emulateOP(long maxCycles) throws EmulationException { if(indexModifier > 0x8000) { indexModifier = -(0x10000 - indexModifier); } - write(indexModifier + index, readRegister(srcData), MODE_WORD20); + currentSegment.write(indexModifier + index, readRegister(srcData), MODE_WORD20); writeRegister(PC, pc += 2); updateStatus = false; cycles += 4; break; case MOVA_IMM2REG: - src = read(pc, MODE_WORD); + src = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); writeRegister(PC, pc += 2); dst = src + (srcData << 16); // System.out.println("*** Writing $" + getAddressAsString(dst) + " to reg: " + dstData); @@ -1171,7 +1087,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // the data is stored in the following word (PC + 2) and // the high 4 bits in the instruction word, which we have // masked out as srcData. - int immData = read(pc, MODE_WORD) + (srcData << 16); + int immData = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ) + (srcData << 16); writeRegister(PC, pc += 2); dst = readRegister(dstData) + immData; writeRegister(dstData, dst); @@ -1186,7 +1102,7 @@ public int emulateOP(long maxCycles) throws EmulationException { operand delivers a negative result, or if the subtraction of a positive source operand from a negative destination operand delivers a positive result, reset otherwise (no overflow) */ - immData = read(pc, MODE_WORD) + (srcData << 16); + immData = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ) + (srcData << 16); writeRegister(PC, pc += 2); sr = readRegister(SR); @@ -1216,7 +1132,7 @@ public int emulateOP(long maxCycles) throws EmulationException { break; } case SUBA_IMM: - immData = read(pc, MODE_WORD) + (srcData << 16); + immData = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ) + (srcData << 16); writeRegister(PC, pc += 2); dst = readRegister(dstData) - immData; writeRegister(dstData, dst); @@ -1362,14 +1278,14 @@ public int emulateOP(long maxCycles) throws EmulationException { updateStatus = false; switch(op) { case CALLA_IMM: - dst = (dstRegister << 16) | read(pc, MODE_WORD); + dst = (dstRegister << 16) | currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); pc += 2; cycles += 5; break; case CALLA_ABS: /* read the address of where the address to call is */ - dst = (dstRegister << 16) | read(pc, MODE_WORD); - dst = read(dst, MODE_WORD20); + dst = (dstRegister << 16) | currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); + dst = currentSegment.read(dst, MODE_WORD20, Memory.TYPE_READ); pc += 2; cycles += 7; break; @@ -1394,7 +1310,7 @@ public int emulateOP(long maxCycles) throws EmulationException { for(int i = 0; i < n; i++) { sp -= size; cycles += 2; - write(sp, this.reg[regNo--], type); + currentSegment.write(sp, this.reg[regNo--], type); // System.out.println("Saved reg: " + (regNo + 1) + " was " + reg[regNo + 1]); /* what happens if regNo is wrapped ??? */ @@ -1415,7 +1331,7 @@ public int emulateOP(long maxCycles) throws EmulationException { /* read and increase stack pointer n times */ for(int i = 0; i < n; i++) { cycles += 2; - this.reg[regNo++] = read(sp, type); + this.reg[regNo++] = currentSegment.read(sp, type, Memory.TYPE_READ); // System.out.println("Restored reg: " + (regNo - 1) + " to " + reg[regNo - 1]); sp += size; /* what happens if regNo is wrapped ??? */ @@ -1434,9 +1350,9 @@ public int emulateOP(long maxCycles) throws EmulationException { /* store 20 bits on stack (costs two words) */ if (dst != -1) { sp = readRegister(SP) - 2; - write(sp, (pc >> 16) & 0xf, MODE_WORD); + currentSegment.write(sp, (pc >> 16) & 0xf, MODE_WORD); sp = sp - 2; - write(sp, pc & 0xffff, MODE_WORD); + currentSegment.write(sp, pc & 0xffff, MODE_WORD); writeRegister(SP, sp); writeRegister(PC, dst); @@ -1474,9 +1390,9 @@ public int emulateOP(long maxCycles) throws EmulationException { /* Support for MSP430X and below / above 64 KB */ /* if register is pointing to <64KB then it needs to be truncated to below 64 */ if (rval < 0xffff) { - dstAddress = (rval + read(pc, MODE_WORD)) & 0xffff; + dstAddress = (rval + currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ)) & 0xffff; } else { - dstAddress = read(pc, MODE_WORD); + dstAddress = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); if ((dstAddress & 0x8000) > 0) { dstAddress |= 0xf0000; } @@ -1532,7 +1448,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // System.out.println("*** Repeat " + repeats + " ZeroCarry: " + zeroCarry); // } } else { - dst = read(dstAddress, word ? MODE_WORD : MODE_BYTE); + dst = currentSegment.read(dstAddress, word ? MODE_WORD : MODE_BYTE, Memory.TYPE_READ); } /* TODO: test add the loop here! */ @@ -1595,12 +1511,12 @@ public int emulateOP(long maxCycles) throws EmulationException { // Put lo & hi on stack! // memory[sp] = dst & 0xff; // memory[sp + 1] = dst >> 8; - write(sp, dst, MODE_WORD); + currentSegment.write(sp, dst, MODE_WORD); } else { // Byte => only lo byte // memory[sp] = dst & 0xff; // memory[sp + 1] = 0; - write(sp, dst & 0xff, MODE_WORD); + currentSegment.write(sp, dst & 0xff, MODE_WORD); } /* if REG or INDIRECT AUTOINC then add 2 cycles, otherwise 1 */ cycles += (ad == AM_REG || ad == AM_IND_AUTOINC) ? 2 : 1; @@ -1612,7 +1528,7 @@ public int emulateOP(long maxCycles) throws EmulationException { pc = readRegister(PC); // memory[sp] = pc & 0xff; // memory[sp + 1] = pc >> 8; - write(sp, pc, MODE_WORD); + currentSegment.write(sp, pc, MODE_WORD); writeRegister(PC, dst); /* Additional cycles: REG => 3, AM_IND_AUTO => 2, other => 1 */ @@ -1630,13 +1546,13 @@ public int emulateOP(long maxCycles) throws EmulationException { // Put Top of stack to Status DstRegister (TOS -> SR) servicedInterrupt = -1; /* needed before write to SR!!! */ sp = readRegister(SP); - sr = read(sp, MODE_WORD); + sr = currentSegment.read(sp, MODE_WORD, Memory.TYPE_READ); writeRegister(SR, sr & 0x0fff); sp = sp + 2; // writeRegister(SR, memory[sp++] + (memory[sp++] << 8)); // TOS -> PC // writeRegister(PC, memory[sp++] + (memory[sp++] << 8)); - writeRegister(PC, read(sp, MODE_WORD) | (sr & 0xf000) << 4); + writeRegister(PC, currentSegment.read(sp, MODE_WORD, Memory.TYPE_READ) | (sr & 0xf000) << 4); sp = sp + 2; writeRegister(SP, sp); write = false; @@ -1776,7 +1692,7 @@ public int emulateOP(long maxCycles) throws EmulationException { break; case AM_INDEX: // Indexed if reg != PC & CG1/CG2 - will PC be incremented? - srcAddress = readRegisterCG(srcRegister, as) + read(pc, MODE_WORD); + srcAddress = readRegisterCG(srcRegister, as) + currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); // memory[pc] + (memory[pc + 1] << 8); // When is PC incremented - assuming immediately after "read"? @@ -1826,16 +1742,16 @@ public int emulateOP(long maxCycles) throws EmulationException { pc = readRegister(PC); if (dstRegister == 2) { /* absolute mode */ - dstAddress = read(pc, MODE_WORD); //memory[pc] + (memory[pc + 1] << 8); + dstAddress = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); //memory[pc] + (memory[pc + 1] << 8); } else { // CG here - probably not!??? rval = readRegister(dstRegister); /* Support for MSP430X and below / above 64 KB */ /* if register is pointing to <64KB then it needs to be truncated to below 64 */ if (rval < 0xffff) { - dstAddress = (rval + read(pc, MODE_WORD)) & 0xffff; + dstAddress = (rval + currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ)) & 0xffff; } else { - dstAddress = read(pc, MODE_WORD); + dstAddress = currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ); if ((dstAddress & 0x8000) > 0) { dstAddress |= 0xf0000; } @@ -1845,7 +1761,7 @@ public int emulateOP(long maxCycles) throws EmulationException { } if (op != MOV) - dst = read(dstAddress, word ? MODE_WORD : MODE_BYTE); + dst = currentSegment.read(dstAddress, word ? MODE_WORD : MODE_BYTE, Memory.TYPE_READ); pc += 2; incRegister(PC, 2); } @@ -1858,7 +1774,7 @@ public int emulateOP(long maxCycles) throws EmulationException { // } // srcAddress = srcAddress & 0xffff; - src = read(srcAddress, word ? MODE_WORD : MODE_BYTE); + src = currentSegment.read(srcAddress, word ? MODE_WORD : MODE_BYTE, Memory.TYPE_READ); // if (debug) { // System.out.println("Reading from " + getAddressAsString(srcAddress) + @@ -2032,7 +1948,7 @@ public int emulateOP(long maxCycles) throws EmulationException { writeRegister(dstRegister, dst); } else { dstAddress &= 0xffff; - write(dstAddress, dst, word ? MODE_WORD : MODE_BYTE); + currentSegment.write(dstAddress, dst, word ? MODE_WORD : MODE_BYTE); } } if (updateStatus) { @@ -2105,10 +2021,10 @@ public String info() { + " Time: " + (long)getTimeMillis() + " msec\n"); buf.append(" Interrupt enabled: " + interruptsEnabled + " HighestInterrupt: " + interruptMax); for (int i = 0; i < MAX_INTERRUPT; i++) { - if (read(0xfffe - i * 2, MODE_WORD) != 0xffff) { + if (currentSegment.read(0xfffe - i * 2, MODE_WORD, Memory.TYPE_READ) != 0xffff) { buf.append(" Vector " + (MAX_INTERRUPT - i) + " at $" + Utils.hex16(0xfffe - i * 2) + " -> $" - + Utils.hex16(read(0xfffe - i * 2, MODE_WORD)) + "\n"); + + Utils.hex16(currentSegment.read(0xfffe - i * 2, MODE_WORD, Memory.TYPE_READ)) + "\n"); } } return buf.toString(); diff --git a/se/sics/mspsim/core/Memory.java b/se/sics/mspsim/core/Memory.java index aba854f..df5c5fa 100644 --- a/se/sics/mspsim/core/Memory.java +++ b/se/sics/mspsim/core/Memory.java @@ -42,11 +42,12 @@ public interface Memory { - public int readByte(int address); - public void writeByte(int address, int data); + public static int SEGMENT_SIZE = 256; + public static int TYPE_READ = 1; /* normal read */ + public static int TYPE_EXECUTE = 2; /* instruction execution read */ + public static int TYPE_ARG = 3; /* arguments for execution */ + + public int read(int address, int mode, int type) throws EmulationException; + public void write(int dstAddress, int dst, int mode) throws EmulationException; - /** - * getSize returns the size of memory in bytes. - */ - public int getSize(); } diff --git a/se/sics/mspsim/core/Memory.java b/se/sics/mspsim/core/MemoryMonitor.java similarity index 75% copy from se/sics/mspsim/core/Memory.java copy to se/sics/mspsim/core/MemoryMonitor.java index aba854f..88b9c6d 100644 --- a/se/sics/mspsim/core/Memory.java +++ b/se/sics/mspsim/core/MemoryMonitor.java @@ -27,26 +27,33 @@ * * This file is part of MSPSim. * - * $Id: $ + * $Id$ * * ----------------------------------------------------------------- * - * Memory + * CPUMonitor * * Author : Joakim Eriksson - * Created : Sept 15 22:00:00 2008 - * Updated : $Date: 2008-03-11 16:32:12 +0100 (ti, 11 mar 2008) $ - * $Revision: 177 $ + * Created : Sun Oct 21 22:00:00 2007 + * Updated : $Date$ + * $Revision$ */ + package se.sics.mspsim.core; -public interface Memory { +public interface MemoryMonitor { - public int readByte(int address); - public void writeByte(int address, int data); + public static final int MEMORY_READ = 1; + public static final int MEMORY_WRITE = 2; + public static final int EXECUTE = 5; + + + //public void cpuAction(int type, int adr, int data); + + public void notifyReadBefore(int addr, int mode, int type); + public void notifyReadAfter(int addr, int mode, int type); + + public void notifyWriteBefore(int dstAddress, int data, int mode); + public void notifyWriteAfter(int dstAddress, int data, int mode); - /** - * getSize returns the size of memory in bytes. - */ - public int getSize(); } diff --git a/se/sics/mspsim/core/MemoryMonitorProxy.java b/se/sics/mspsim/core/MemoryMonitorProxy.java new file mode 100644 index 0000000..dc0003a --- /dev/null +++ b/se/sics/mspsim/core/MemoryMonitorProxy.java @@ -0,0 +1,73 @@ +package se.sics.mspsim.core; + +import se.sics.mspsim.util.ArrayUtils; + +public class MemoryMonitorProxy implements MemoryMonitor { + private MemoryMonitor[] monitors; + + public MemoryMonitorProxy(MemoryMonitor mon1, MemoryMonitor mon2) { + monitors = new MemoryMonitor[] { mon1, mon2 }; + } + + public static MemoryMonitor addMemoryMonitor(MemoryMonitor MemoryMonitor, MemoryMonitor mon) { + if (MemoryMonitor == null) { + return mon; + } + if (MemoryMonitor instanceof MemoryMonitorProxy) { + return ((MemoryMonitorProxy)MemoryMonitor).add(mon); + } + return new MemoryMonitorProxy(MemoryMonitor, mon); + } + + public static MemoryMonitor removeMemoryMonitor(MemoryMonitor MemoryMonitor, MemoryMonitor mon) { + if (MemoryMonitor == mon) { + return null; + } + if (MemoryMonitor instanceof MemoryMonitorProxy) { + return ((MemoryMonitorProxy)MemoryMonitor).remove(mon); + } + return MemoryMonitor; + } + + + public MemoryMonitor add(MemoryMonitor mon) { + monitors = (MemoryMonitor[]) ArrayUtils.add(MemoryMonitor.class, monitors, mon); + return this; + } + + public MemoryMonitor remove(MemoryMonitor mon) { + MemoryMonitor[] mons = (MemoryMonitor[]) ArrayUtils.remove(monitors, mon); + if (mons == null) { + return null; + } + if (mons.length == 1) { + ... [truncated message content] |
From: Niclas F. <ni...@us...> - 2012-03-15 23:39:12
|
The branch "master" has been updated via a4f2fbf314d0444069a375e182760eec40211b21 (commit) from 2bd1a444371c0617631fd5a4f53ef0a9664ecfae (commit) Changed paths: M se/sics/mspsim/core/MSP430Core.java - Log ----------------------------------------------------------------- commit a4f2fbf314d0444069a375e182760eec40211b21 Author: Niclas Finne <nf...@si...> Date: Fri Mar 16 00:33:25 2012 +0100 Bug fix: indexed address mode overflow/underflow inspired by patch from Ben Ransford diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index a419b18..f3194b2 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -1774,16 +1774,30 @@ public int emulateOP(long maxCycles) throws EmulationException { } break; - case AM_INDEX: + case AM_INDEX: { // Indexed if reg != PC & CG1/CG2 - will PC be incremented? - srcAddress = readRegisterCG(srcRegister, as) + read(pc, MODE_WORD); -// memory[pc] + (memory[pc + 1] << 8); - // When is PC incremented - assuming immediately after "read"? + int sval = readRegisterCG(srcRegister, as); + + /* Support for MSP430X and below / above 64 KB */ + /* if register is pointing to <64KB then it needs to be truncated to below 64 */ + if (sval < 0xffff) { + srcAddress = (sval + read(pc, MODE_WORD)) & 0xffff; + } else { + srcAddress = read(pc, MODE_WORD); + if ((srcAddress & 0x8000) > 0) { + // Negative index + srcAddress |= 0xf0000; + } + srcAddress += sval; + srcAddress &= 0xfffff; + } + // When is PC incremented - assuming immediately after "read"? incRegister(PC, 2); cycles += dstRegMode ? 3 : 6; break; + } // Indirect register case AM_IND_REG: srcAddress = readRegister(srcRegister); ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/core/MSP430Core.java | 28 +++++++++++++++++++++------- 1 files changed, 21 insertions(+), 7 deletions(-) hooks/post-receive -- mspsim |
From: Fredrik Ãs. <fro...@us...> - 2012-03-12 13:42:10
|
The branch "master" has been updated via 2bd1a444371c0617631fd5a4f53ef0a9664ecfae (commit) from c86d9ee2675cee01d2214b244e10bb7d634455ae (commit) Changed paths: M se/sics/mspsim/chip/CC2420.java - Log ----------------------------------------------------------------- commit 2bd1a444371c0617631fd5a4f53ef0a9664ecfae Author: Fredrik Osterlind <fr...@si...> Date: Mon Mar 12 14:41:44 2012 +0100 turn off radio and stop transmitting at reset diff --git a/se/sics/mspsim/chip/CC2420.java b/se/sics/mspsim/chip/CC2420.java index 1b86bf1..a041818 100644 --- a/se/sics/mspsim/chip/CC2420.java +++ b/se/sics/mspsim/chip/CC2420.java @@ -1318,6 +1318,13 @@ public void setChannelListener(ChannelListener cl) { this.cl = cl; } + public void notifyReset() { + super.notifyReset(); + setChipSelect(false); + status &= ~STATUS_TX_ACTIVE; + setVRegOn(false); + } + public void setVRegOn(boolean newOn) { if(on == newOn) return; ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2420.java | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-03-09 18:47:09
|
The branch "master" has been updated via c86d9ee2675cee01d2214b244e10bb7d634455ae (commit) via 0f3cb0ea32915377e1b39177cb2b5bf9e9cdb7a1 (commit) via 4d2d4d75633dffe2c660f04998cc58a394da0ed0 (commit) via 6fb4b00df8f995f8bbbd6cd42329d4a8cb2548fa (commit) from 366e95dda14fea2689a54c6c42f6429aa44509ad (commit) Changed paths: M se/sics/mspsim/Main.java M se/sics/mspsim/cli/DebugCommands.java M se/sics/mspsim/core/Flash.java M se/sics/mspsim/core/MSP430Core.java M se/sics/mspsim/core/USART.java M se/sics/mspsim/core/USARTListener.java M se/sics/mspsim/ui/ControlUI.java - Log ----------------------------------------------------------------- commit c86d9ee2675cee01d2214b244e10bb7d634455ae Author: Niclas Finne <nf...@si...> Date: Fri Mar 9 19:44:27 2012 +0100 Reduced debug output when using DMA diff --git a/se/sics/mspsim/core/USART.java b/se/sics/mspsim/core/USART.java index 9b6238a..dfedc95 100644 --- a/se/sics/mspsim/core/USART.java +++ b/se/sics/mspsim/core/USART.java @@ -442,13 +442,17 @@ public boolean getDMATriggerState(int index) { } public void clearDMATrigger(int index) { - System.out.println("UART clearing DMA " + index); if (index == 0) { /* clear RX - might be different in different modes... */ - System.out.println("UART clearing read bit!"); + if (DEBUG) { + log("clearing DMA read bit!"); + } clrBitIFG(urxifg); stateChanged(USARTListener.RXFLAG_CLEARED, true); } else { + if (DEBUG) { + log("clearing DMA " + index); + } /* clear TX - might be different in different modes... */ clrBitIFG(utxifg); } diff --git a/se/sics/mspsim/core/USARTListener.java b/se/sics/mspsim/core/USARTListener.java index a8e16cb..fef17d2 100644 --- a/se/sics/mspsim/core/USARTListener.java +++ b/se/sics/mspsim/core/USARTListener.java @@ -42,6 +42,6 @@ package se.sics.mspsim.core; public interface USARTListener { - public static int RXFLAG_CLEARED = 1; + public static final int RXFLAG_CLEARED = 1; public void dataReceived(USARTSource source, int data); } commit 0f3cb0ea32915377e1b39177cb2b5bf9e9cdb7a1 Author: Niclas Finne <nf...@si...> Date: Fri Mar 9 19:40:56 2012 +0100 Updated to use cpu.getPC() instead of cpu.readRegister() to avoid notifying register monitors diff --git a/se/sics/mspsim/cli/DebugCommands.java b/se/sics/mspsim/cli/DebugCommands.java index 12ea446..a3714b2 100644 --- a/se/sics/mspsim/cli/DebugCommands.java +++ b/se/sics/mspsim/cli/DebugCommands.java @@ -55,12 +55,12 @@ private ComponentRegistry registry; private ELF getELF() { - return (ELF) registry.getComponent(ELF.class); + return registry.getComponent(ELF.class); } public void setupCommands(ComponentRegistry registry, CommandHandler ch) { this.registry = registry; - final MSP430 cpu = (MSP430) registry.getComponent(MSP430.class); + final MSP430 cpu = registry.getComponent(MSP430.class); final GenericNode node = (GenericNode) registry.getComponent("node"); if (cpu != null) { ch.registerCommand("break", new BasicAsyncCommand("add a breakpoint to a given address or symbol", @@ -121,7 +121,7 @@ public int executeCommand(final CommandContext context) { monitor = new CPUMonitor() { public void cpuAction(int type, int adr, int data) { if (mode == 0 || mode == 10) { - int pc = cpu.readRegister(0); + int pc = cpu.getPC(); String adrStr = getSymOrAddr(cpu, context, adr); String pcStr = getSymOrAddrELF(cpu, getELF(), pc); String op = "op"; @@ -189,7 +189,7 @@ public int executeCommand(final CommandContext context) { monitor = new CPUMonitor() { public void cpuAction(int type, int adr, int data) { if (mode == 0) { - int pc = cpu.readRegister(0); + int pc = cpu.getPC(); String adrStr = getRegisterName(register); String pcStr = getSymOrAddrELF(cpu, getELF(), pc); context.out.println("*** Write from " + pcStr + @@ -268,7 +268,7 @@ public int executeCommand(final CommandContext context) { ch.registerCommand("stop", new BasicCommand("stop the CPU", "") { public int executeCommand(CommandContext context) { node.stop(); - context.out.println("CPU stopped at: $" + cpu.getAddressAsString(cpu.readRegister(0))); + context.out.println("CPU stopped at: $" + cpu.getAddressAsString(cpu.getPC())); return 0; } }); @@ -297,7 +297,7 @@ public int executeCommand(CommandContext context) { } catch (Exception e) { e.printStackTrace(context.out); } - context.out.println("CPU stepped to: $" + cpu.getAddressAsString(cpu.readRegister(0)) + + context.out.println("CPU stepped to: $" + cpu.getAddressAsString(cpu.getPC()) + " in " + (cpu.cycles - cyc) + " cycles (" + cpu.cycles + ")"); return 0; } @@ -316,7 +316,7 @@ public int executeCommand(CommandContext context) { } catch (Exception e) { e.printStackTrace(context.out); } - context.out.println("CPU stepped to: $" + cpu.getAddressAsString(cpu.readRegister(0)) + + context.out.println("CPU stepped to: $" + cpu.getAddressAsString(cpu.getPC()) + " in " + (cpu.cycles - cyc) + " cycles (" + cpu.cycles + ") - next exec time: " + nxt); return 0; } @@ -326,7 +326,7 @@ public int executeCommand(CommandContext context) { public int executeCommand(CommandContext context) { int stackEnd = context.getMapTable().heapStartAddress; int stackStart = context.getMapTable().stackStartAddress; - int current = cpu.readRegister(MSP430Constants.SP); + int current = cpu.getSP(); context.out.println("Current stack: $" + cpu.getAddressAsString(current) + " (" + (stackStart - current) + " used of " + (stackStart - stackEnd) + ')'); return 0; } @@ -350,7 +350,7 @@ public int executeCommand(CommandContext context) { public int executeCommand(CommandContext context) { int register = context.getArgumentAsRegister(0); if (register >= 0) { - context.out.println(context.getArgument(0) + " = $" + Utils.hex16(cpu.readRegister(register))); + context.out.println(context.getArgument(0) + " = $" + Utils.hex16(cpu.getRegister(register))); return 0; } return -1; diff --git a/se/sics/mspsim/core/Flash.java b/se/sics/mspsim/core/Flash.java index 306de3b..0a3b6cc 100644 --- a/se/sics/mspsim/core/Flash.java +++ b/se/sics/mspsim/core/Flash.java @@ -99,7 +99,7 @@ private static final int FN_MASK = 0x3f; - private MSP430Core cpu; + private final MSP430Core cpu; private FlashRange main_range; private FlashRange info_range; private int[] memory; @@ -203,7 +203,7 @@ private int getFlashClockDiv() { } private void waitFlashProcess(int time) { - int instr_addr = cpu.readRegister(MSP430.PC); + int instr_addr = cpu.getPC(); int freqdiv = getFlashClockDiv(); int myfreq; double finish_msec; @@ -310,7 +310,7 @@ public void flashWrite(int address, int data, boolean word) { if (DEBUG) { log("Flash write in block mode started @" + Utils.hex16(address)); } - if (addressInFlash(cpu.readRegister(MSP430.PC))) { + if (addressInFlash(cpu.getPC())) { logw("Oops. Block write access only allowed when executing from RAM."); } } else { @@ -340,7 +340,7 @@ public void notifyRead(int address) { if (DEBUG) { if (wait == false && currentWriteMode == WriteMode.WRITE_BLOCK) { log("Reading flash prohibited. Would read 0x3fff!!!"); - log("CPU PC=" + Utils.hex16(cpu.readRegister(MSP430.PC)) + log("CPU PC=$" + Utils.hex16(cpu.getPC()) + " read address=" + Utils.hex16(address)); } } @@ -455,8 +455,7 @@ private void triggerUnlockFlash() { } private void triggerAccessViolation(String reason) { - logw("Access violation: " + reason + ". PC=$" - + Utils.hex16(cpu.readRegister(MSP430.PC))); + logw("Access violation: " + reason + ". PC=$" + Utils.hex16(cpu.getPC())); 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 42abce2..a419b18 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -2081,6 +2081,10 @@ public int getSR() { return reg[SR]; } + public int getSP() { + return reg[SP]; + } + public int getRegister(int register) { return reg[register]; } diff --git a/se/sics/mspsim/ui/ControlUI.java b/se/sics/mspsim/ui/ControlUI.java index 7c6441f..73623fa 100644 --- a/se/sics/mspsim/ui/ControlUI.java +++ b/se/sics/mspsim/ui/ControlUI.java @@ -52,7 +52,6 @@ import javax.swing.JPanel; import javax.swing.KeyStroke; import se.sics.mspsim.core.MSP430; -import se.sics.mspsim.core.MSP430Constants; import se.sics.mspsim.core.SimEvent; import se.sics.mspsim.core.SimEventListener; import se.sics.mspsim.platform.GenericNode; @@ -117,7 +116,7 @@ public void actionPerformed(ActionEvent e) { dui.repaint(); if (elfData != null && sourceViewer != null && sourceViewer.isVisible()) { - int pc = ControlUI.this.cpu.readRegister(MSP430Constants.PC); + int pc = ControlUI.this.cpu.getPC(); DebugInfo dbg = elfData.getDebugInfo(pc); if (dbg != null) { if (ControlUI.this.cpu.getDebug()) { @@ -197,7 +196,7 @@ public void actionPerformed(ActionEvent ae) { // cpu.step(); // dui.repaint(); } else if ("Show Source".equals(cmd)) { - int pc = cpu.readRegister(MSP430Constants.PC); + int pc = cpu.getPC(); if (elfData != null) { DebugInfo dbg = elfData.getDebugInfo(pc); if (dbg != null) { commit 4d2d4d75633dffe2c660f04998cc58a394da0ed0 Author: Niclas Finne <nf...@si...> Date: Fri Mar 9 19:04:38 2012 +0100 Removed multiple notification of register monitors in some operations diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index 54ae021..42abce2 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -27,8 +27,6 @@ * * This file is part of MSPSim. * - * $Id$ - * * ----------------------------------------------------------------- * * MSP430Core @@ -61,7 +59,6 @@ // Try it out with 64 k memory public final int MAX_MEM; public final int MAX_MEM_IO; - public static final int PORTS = 6; // 16 registers of which some are "special" - PC, SP, etc. public int[] reg = new int[16]; @@ -758,7 +755,7 @@ public int read(int address, int mode) throws EmulationException { printWarning(ADDRESS_OUT_OF_BOUNDS_READ, address); address %= MAX_MEM; } - boolean word = mode != MODE_BYTE; + final boolean word = mode != MODE_BYTE; // Only word reads at 0x1fe which is highest address... if (address < MAX_MEM_IO) { val = memIn[address].read(address, word, cycles); @@ -815,14 +812,14 @@ public void write(int dstAddress, int dst, int mode) throws EmulationException { wp.cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, dst); } - boolean word = mode != MODE_BYTE; + final boolean word = mode != MODE_BYTE; // Only word writes at 0x1fe which is highest address... if (dstAddress < MAX_MEM_IO) { if (!word) dst &= 0xff; - memOut[dstAddress].write(dstAddress, dst & 0xffff, mode != MODE_BYTE, cycles); + memOut[dstAddress].write(dstAddress, dst & 0xffff, word, cycles); if (mode > MODE_WORD) { - memOut[dstAddress].write(dstAddress + 2, dst >> 16, mode != MODE_BYTE, cycles); + memOut[dstAddress].write(dstAddress + 2, dst >> 16, word, cycles); } // check for Flash } else if (flash.addressInFlash(dstAddress)) { @@ -1180,7 +1177,8 @@ public int emulateOP(long maxCycles) throws EmulationException { writeRegister(dstData, dst); cycles += 3; break; - case CMPA_IMM: + + case CMPA_IMM: { /* Status Bits N: Set if result is negative (src > dst), reset if positive (src ⤠dst) Z: Set if result is zero (src = dst), reset otherwise (src â dst) C: Set if there is a carry from the MSB, reset otherwise @@ -1191,22 +1189,24 @@ public int emulateOP(long maxCycles) throws EmulationException { immData = read(pc, MODE_WORD) + (srcData << 16); writeRegister(PC, pc += 2); sr = readRegister(SR); + + int destRegValue = readRegister(dstData); sr &= ~(NEGATIVE | ZERO | CARRY | OVERFLOW); - if (readRegister(dstData) >= immData) { + if (destRegValue >= immData) { sr |= CARRY; } - if (readRegister(dstData) < immData) { + if (destRegValue < immData) { sr |= NEGATIVE; } - if (readRegister(dstData) == immData) { + if (destRegValue == immData) { sr |= ZERO; } - int cmpTmp = readRegister(dstData) - immData; + int cmpTmp = destRegValue - immData; int b = 0x80000; // CMPA always use 20 bit data length - if (((readRegister(dstData) ^ cmpTmp) & b) == 0 && - (((readRegister(dstData) ^ immData) & b) != 0)) { + if (((destRegValue ^ cmpTmp) & b) == 0 && + (((destRegValue ^ immData) & b) != 0)) { sr |= OVERFLOW; } @@ -1214,7 +1214,7 @@ public int emulateOP(long maxCycles) throws EmulationException { updateStatus = false; cycles += 3; break; - + } case SUBA_IMM: immData = read(pc, MODE_WORD) + (srcData << 16); writeRegister(PC, pc += 2); @@ -1228,24 +1228,26 @@ public int emulateOP(long maxCycles) throws EmulationException { writeRegister(dstData, readRegister(srcData)); break; - case CMPA_REG: + case CMPA_REG: { sr = readRegister(SR); sr &= ~(NEGATIVE | ZERO | CARRY | OVERFLOW); - if (readRegister(dstData) >= readRegister(srcData)) { + int destRegValue = readRegister(dstData); + int srcRegValue = readRegister(srcData); + if (destRegValue >= srcRegValue) { sr |= CARRY; } - if (readRegister(dstData) < readRegister(srcData)) { + if (destRegValue < srcRegValue) { sr |= NEGATIVE; } - if (readRegister(dstData) == readRegister(srcData)) { + if (destRegValue == srcRegValue) { sr |= ZERO; } - cmpTmp = readRegister(dstData) - readRegister(srcData); - b = 0x80000; // CMPA always use 20 bit data length + int cmpTmp = destRegValue - srcRegValue; + int b = 0x80000; // CMPA always use 20 bit data length - if (((readRegister(dstData) ^ cmpTmp) & b) == 0 && - (((readRegister(dstData) ^ readRegister(srcData)) & b) != 0)) { + if (((destRegValue ^ cmpTmp) & b) == 0 && + (((destRegValue ^ srcRegValue) & b) != 0)) { sr |= OVERFLOW; } @@ -1253,6 +1255,7 @@ public int emulateOP(long maxCycles) throws EmulationException { updateStatus = false; cycles += 1; break; + } case ADDA_REG: dst = readRegister(dstData) + readRegister(srcData); @@ -1270,8 +1273,9 @@ public int emulateOP(long maxCycles) throws EmulationException { case RRXX_WORD: int count = ((instruction >> 10) & 0x03) + 1; dst = readRegister(dstData); + sr = readRegister(SR); int nxtCarry = 0; - int carry = (readRegister(SR) & CARRY) > 0? 1: 0; + int carry = (sr & CARRY) > 0? 1: 0; if (rrword) { dst = dst & 0xffff; } @@ -1287,7 +1291,7 @@ public int emulateOP(long maxCycles) throws EmulationException { * instruction is complete. */ int dst_low = dst & ((1 << count) - 1); - /* Grab the bit that wlil be in the carry flag when instruction completes. */ + /* Grab the bit that will be in the carry flag when instruction completes. */ nxtCarry = (dst & (1 << (count + 1))) > 0? CARRY: 0; /* Rotate dst. */ @@ -1328,7 +1332,7 @@ public int emulateOP(long maxCycles) throws EmulationException { break; } /* clear overflow - set carry according to above OP */ - writeRegister(SR, (readRegister(SR) & ~(CARRY | OVERFLOW)) | nxtCarry); + writeRegister(SR, (sr & ~(CARRY | OVERFLOW)) | nxtCarry); dst = dst & (rrword ? 0xffff : 0xfffff); writeRegister(dstData, dst); break; @@ -1340,7 +1344,6 @@ public int emulateOP(long maxCycles) throws EmulationException { Utils.hex16(instruction) + " op " + Utils.hex16(op)); } - break; case 1: { @@ -2074,6 +2077,14 @@ public int getPC() { return reg[PC]; } + public int getSR() { + return reg[SR]; + } + + public int getRegister(int register) { + return reg[register]; + } + public String getAddressAsString(int addr) { return config.getAddressAsString(addr); } commit 6fb4b00df8f995f8bbbd6cd42329d4a8cb2548fa Author: Niclas Finne <nf...@si...> Date: Fri Mar 9 18:58:10 2012 +0100 Added exp5438 as platform name diff --git a/se/sics/mspsim/Main.java b/se/sics/mspsim/Main.java index 729c81f..d626a66 100644 --- a/se/sics/mspsim/Main.java +++ b/se/sics/mspsim/Main.java @@ -76,6 +76,9 @@ private static String getNodeTypeByPlatform(String platform) { if ("esb".equals(platform)) { return "se.sics.mspsim.platform.esb.ESBNode"; } + if ("exp5438".equals(platform)) { + return "se.sics.mspsim.platform.ti.Exp5438Node"; + } // Try to guess the node type. return "se.sics.mspsim.platform." + platform + '.' + Character.toUpperCase(platform.charAt(0)) ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/Main.java | 3 + se/sics/mspsim/cli/DebugCommands.java | 18 ++++---- se/sics/mspsim/core/Flash.java | 11 ++--- se/sics/mspsim/core/MSP430Core.java | 69 +++++++++++++++++++------------ se/sics/mspsim/core/USART.java | 12 ++++-- se/sics/mspsim/core/USARTListener.java | 2 +- se/sics/mspsim/ui/ControlUI.java | 5 +- 7 files changed, 70 insertions(+), 50 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-03-09 10:58:33
|
The branch "master" has been updated via 366e95dda14fea2689a54c6c42f6429aa44509ad (commit) from c3ef5d1d90c686176289b8bfcdce6b05bbfcb87a (commit) Changed paths: M se/sics/mspsim/core/MSP430Core.java - Log ----------------------------------------------------------------- commit 366e95dda14fea2689a54c6c42f6429aa44509ad Author: Joakim Eriksson <jo...@si...> Date: Fri Mar 9 11:58:10 2012 +0100 added exception when executing MSP430X instructions on non X arch diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index 3002a7c..54ae021 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -411,6 +411,10 @@ public synchronized void setRegisterReadMonitor(int r, CPUMonitor mon) { public void writeRegister(int r, int value) { // Before the write! +// if (value >= MAX_MEM) { +// System.out.println("Writing larger than MAX_MEM to " + r + " value:" + value); +// new Throwable().printStackTrace(); +// } CPUMonitor rwm = regWriteMonitors[r]; if (rwm != null) { rwm.cpuAction(CPUMonitor.REGISTER_WRITE, r, value); @@ -1066,6 +1070,8 @@ public int emulateOP(long maxCycles) throws EmulationException { case 0: // MSP430X - additional instructions op = instruction & 0xf0f0; + if (!MSP430XArch) + throw new EmulationException("Executing MSP430X instruction but MCU is not a MSP430X"); // System.out.println("Executing MSP430X instruction op:" + Utils.hex16(op) + // " ins:" + Utils.hex16(instruction) + " PC = $" + getAddressAsString(pc - 2)); int src = 0; ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/core/MSP430Core.java | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) hooks/post-receive -- mspsim |
From: Joakim E. <jo...@us...> - 2012-03-08 22:22:24
|
The branch "master" has been updated via c3ef5d1d90c686176289b8bfcdce6b05bbfcb87a (commit) via 5ec2fa765c21cd6f9f2809ef41e6ad6d5ff0af5d (commit) from f320a566aad05d9829508d6e1dc0668bf0fb23e1 (commit) Changed paths: M se/sics/mspsim/debug/DwarfReader.java - Log ----------------------------------------------------------------- commit c3ef5d1d90c686176289b8bfcdce6b05bbfcb87a Merge: 5ec2fa7 f320a56 Author: Joakim Eriksson <jo...@si...> Date: Thu Mar 8 23:21:32 2012 +0100 Merge branch 'master' of ssh://mspsim.git.sourceforge.net/gitroot/mspsim/mspsim commit 5ec2fa765c21cd6f9f2809ef41e6ad6d5ff0af5d Author: Joakim Eriksson <jo...@si...> Date: Thu Mar 8 23:20:40 2012 +0100 added support for reading dwarf file - discriminator ext operator LNS diff --git a/se/sics/mspsim/debug/DwarfReader.java b/se/sics/mspsim/debug/DwarfReader.java index 258cb09..38ee5d5 100644 --- a/se/sics/mspsim/debug/DwarfReader.java +++ b/se/sics/mspsim/debug/DwarfReader.java @@ -68,6 +68,7 @@ public static final int DW_LNE_end_sequence = 1; public static final int DW_LNE_set_address = 2; public static final int DW_LNE_define_file = 3; + public static final int DW_LNE_set_discriminator = 4; /* DWARF > 2.0 */ ELF elfFile; @@ -133,6 +134,7 @@ private void readLines(ELFSection sec) { int endPos = 0; ArrayList<LineEntry> lineData = new ArrayList<LineEntry>(); while (sec.getPosition() < sec.getSize()) { + if (DEBUG) System.out.println(" --- Reading debug info --- "); /* here starts the reading of one file's (?) debug info */ int totLen = sec.readElf32(); int version = sec.readElf16(); @@ -203,7 +205,7 @@ private void readLines(ELFSection sec) { * line <=> address table */ if (DEBUG) { - System.out.println("Line: position: " + sec.getPosition()); + System.out.println("Line: position: " + sec.getPosition() + " endPos: " + endPos); System.out.println("Line: first bytes of the machine: "); System.out.print("Line: "); } @@ -222,12 +224,13 @@ private void readLines(ELFSection sec) { while(!endSequence) { int ins = sec.readElf8(); - if (DEBUG) System.out.print(Utils.hex8(ins) + " "); + if (DEBUG) System.out.print("POS: " + sec.getPosition() + " INS: " + Utils.hex8(ins) + " "); switch(ins) { case DW_LNS_EXT: /* extended instruction */ int len = sec.readElf8(); int extIns = sec.readElf8(); + if (DEBUG) System.out.println("EXT: " + Utils.hex8(extIns)); switch(extIns) { case DW_LNE_end_sequence: endSequence = true; @@ -246,10 +249,16 @@ private void readLines(ELFSection sec) { if (DEBUG) System.out.println("Line: Set address to: " + Utils.hex16(lineAddress) + " (len: " + len + ")"); break; + case DW_LNE_set_discriminator: // DWARF 4.0? + /* currently just read it but ignore it - TODO: use this info */ + sec.readLEB128(); + break; } break; case DW_LNS_copy: /* copy data to matrix... */ + if (DEBUG) System.out.println("Line: copy data (" + lineLine + "," + + Utils.hex16(lineAddress) + ") to matrix..."); lineData.add(new LineEntry(lineLine, lineAddress)); isBasicBlock = false; break; @@ -289,6 +298,9 @@ private void readLines(ELFSection sec) { if (DEBUG) System.out.println("Line: *** Increased address to: " + Utils.hex16(lineAddress)); break; default: + if (DEBUG) { + System.out.println("INS: " + Utils.hex8(ins)); + } int lineInc = lineBase + ((ins - opcodeBase) % lineRange); int addrInc = (ins - opcodeBase) / lineRange; lineAddress += addrInc * minOpLen; @@ -300,7 +312,8 @@ private void readLines(ELFSection sec) { Utils.hex16(lineAddress) + " Line: " + lineLine + " lineInc: " + lineInc); } } - if (DEBUG) System.out.println("Line - Position " + sec.getPosition() + " totLen: " + totLen); + if (DEBUG) System.out.println("Line - Position " + sec.getPosition() + " totLen: " + totLen + + " endPos: " + endPos); if (lineData.size() > 0) { /* create a block of line-address data that can be used for lookup later.*/ ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/debug/DwarfReader.java | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-03-07 22:43:56
|
The branch "master" has been updated via f320a566aad05d9829508d6e1dc0668bf0fb23e1 (commit) via 76d76d927e264e8bc8faef484a41d859a4b0eac4 (commit) from 9eda161ee31c5839d14e3e68cc3504fc064fd1dc (commit) Changed paths: M se/sics/mspsim/chip/CC2420.java M se/sics/mspsim/util/ArrayUtils.java - Log ----------------------------------------------------------------- commit f320a566aad05d9829508d6e1dc0668bf0fb23e1 Author: Niclas Finne <nf...@si...> Date: Wed Mar 7 23:35:30 2012 +0100 * Bug fix: update pins when polarity is reconfigured * Added support for FIFO polarity * Added support for 8 MSB register writes * Renamed some variables for clarity diff --git a/se/sics/mspsim/chip/CC2420.java b/se/sics/mspsim/chip/CC2420.java index 55d81d7..1b86bf1 100644 --- a/se/sics/mspsim/chip/CC2420.java +++ b/se/sics/mspsim/chip/CC2420.java @@ -136,6 +136,7 @@ public static final int FIFOP_POLARITY = (1<<9); public static final int SFD_POLARITY = (1<<8); public static final int CCA_POLARITY = (1<<7); + public static final int POLARITY_MASK = FIFO_POLARITY | FIFOP_POLARITY | SFD_POLARITY | CCA_POLARITY; public static final int FIFOP_THR = 0x7F; // IOCFG1 Register Bit Masks @@ -240,8 +241,9 @@ public int getFSMState() { private static final int[] BC_ADDRESS = new int[] {0xff, 0xff}; private SpiState state = SpiState.WAITING; - private int pos; - private int address; + private int usartDataPos; + private int usartDataAddress; + private int usartDataValue; private int shrPos; private int txfifoPos; private boolean txfifoFlush; // TXFIFO is automatically flushed on next write @@ -296,8 +298,6 @@ public int getFSMState() { private IOPort fifopPort = null; private int fifopPin; - /* fifoP state */ - private boolean fifoP = false; private IOPort fifoPort = null; private int fifoPin; @@ -376,8 +376,10 @@ public void execute(long t) { } } }; + private boolean currentCCA; private boolean currentSFD; private boolean currentFIFO; + private boolean currentFIFOP; private boolean overflow = false; private boolean frameRejected = false; @@ -411,7 +413,7 @@ public CC2420(MSP430Core cpu) { registers[REG_TXCTRL] = 0xa0ff; setModeNames(MODE_NAMES); setMode(MODE_POWER_OFF); - fifoP = false; + currentFIFOP = false; rxFIFO.reset(); overflow = false; reset(); @@ -650,7 +652,7 @@ public void receivedByte(byte data) { /* In RX mode, FIFOP goes high when the size of the first enqueued packet exceeds * the programmable threshold and address recognition isn't ongoing */ - if(fifoP == false + if (currentFIFOP == false && rxFIFO.length() <= rxlen + 1 && !decodeAddress && !frameRejected && rxFIFO.length() > fifopThr) { @@ -713,15 +715,20 @@ private void setReg(int address, int data) { switch(address) { case REG_IOCFG0: fifopThr = data & FIFOP_THR; - if (DEBUG) log("IOCFG0: " + registers[address]); + if (DEBUG) log("IOCFG0: 0x" + Utils.hex16(oldValue) + " => 0x" + Utils.hex16(data)); + if ((oldValue & POLARITY_MASK) != (data & POLARITY_MASK)) { + // Polarity has changed - must update pins + setFIFOP(currentFIFOP); + setFIFO(currentFIFO); + setSFD(currentSFD); + setCCA(currentCCA); + } break; case REG_IOCFG1: if (DEBUG) log("IOCFG1: SFDMUX " + ((registers[address] & SFDMUX) >> SFDMUX) + " CCAMUX: " + (registers[address] & CCAMUX)); -// if( (registers[address] & CCAMUX) == CCA_CCA) -// setCCA(false); updateCCA(); break; case REG_MDMCTRL0: @@ -760,16 +767,16 @@ public void dataReceived(USARTSource source, int data) { } if ((data & FLAG_RAM) != 0) { state = SpiState.RAM_ACCESS; - address = data & 0x7f; + usartDataAddress = data & 0x7f; } else { // The register address - address = data & 0x3f; + usartDataAddress = data & 0x3f; - if (address == REG_RXFIFO) { + if (usartDataAddress == REG_RXFIFO) { // check read/write??? // log("Reading RXFIFO!!!"); state = SpiState.READ_RXFIFO; - } else if (address == REG_TXFIFO) { + } else if (usartDataAddress == REG_TXFIFO) { state = SpiState.WRITE_TXFIFO; } } @@ -777,41 +784,41 @@ public void dataReceived(USARTSource source, int data) { strobe(data); state = SpiState.WAITING; } - pos = 0; + usartDataPos = 0; // Assuming that the status always is sent back??? //source.byteReceived(status); break; case WRITE_REGISTER: - if (pos == 0) { - source.byteReceived(registers[address] >> 8); + if (usartDataPos == 0) { + source.byteReceived(registers[usartDataAddress] >> 8); // set the high bits - registers[address] = (registers[address] & 0xff) | (data << 8); - pos = 1; + usartDataValue = data << 8; + // registers[usartDataAddress] = (registers[usartDataAddress] & 0xff) | (data << 8); + usartDataPos = 1; } else { - source.byteReceived(registers[address] & 0xff); + source.byteReceived(registers[usartDataAddress] & 0xff); // set the low bits - registers[address] = (registers[address] & 0xff00) | data; + usartDataValue |= data; + // registers[usartDataAddress] = (registers[usartDataAddress] & 0xff00) | data; if (DEBUG) { - log("wrote to " + Utils.hex8(address) + " = " - + registers[address]); + log("wrote to " + Utils.hex8(usartDataAddress) + " = " + usartDataValue); } - data = registers[address]; - setReg(address, data); - /* register written - go back to wating... */ + setReg(usartDataAddress, usartDataValue); + /* register written - go back to waiting... */ state = SpiState.WAITING; } break; case READ_REGISTER: - if (pos == 0) { - source.byteReceived(registers[address] >> 8); - pos = 1; + if (usartDataPos == 0) { + source.byteReceived(registers[usartDataAddress] >> 8); + usartDataPos = 1; } else { - source.byteReceived(registers[address] & 0xff); + source.byteReceived(registers[usartDataAddress] & 0xff); if (DEBUG) { - log("read from " + Utils.hex8(address) + " = " - + registers[address]); + log("read from " + Utils.hex8(usartDataAddress) + " = " + + registers[usartDataAddress]); } state = SpiState.WAITING; } @@ -823,7 +830,7 @@ public void dataReceived(USARTSource source, int data) { source.byteReceived(fifoData); /* first check and clear FIFOP - since we now have read a byte! */ - if (fifoP && !overflow) { + if (currentFIFOP && !overflow) { /* FIFOP is lowered when rxFIFO is lower than or equal to fifopThr */ if(rxFIFO.length() <= fifopThr) { if (DEBUG) log("*** FIFOP cleared at: " + rxFIFO.stateToString()); @@ -876,32 +883,31 @@ public void dataReceived(USARTSource source, int data) { } break; case RAM_ACCESS: - if (pos == 0) { - address |= (data << 1) & 0x180; - ramRead = (data & 0x20) != 0; + if (usartDataPos == 0) { + usartDataAddress |= (data << 1) & 0x180; + ramRead = (data & FLAG_RAM_READ) != 0; if (DEBUG) { - log("Address: " + Utils.hex16(address) + - " read: " + ramRead); + log("Address: " + Utils.hex16(usartDataAddress) + " read: " + ramRead); } - pos++; + usartDataPos++; } else { if (!ramRead) { - memory[address++] = data; - if (address >= 0x180) { + memory[usartDataAddress++] = data; + if (usartDataAddress >= 0x180) { logger.warning(this, "CC2420: Warning - RAM position too big - wrapping!"); - address = 0; + usartDataAddress = 0; } - if (DEBUG && address == RAM_PANID + 2) { + if (DEBUG && usartDataAddress == RAM_PANID + 2) { log("Pan ID set to: 0x" + Utils.hex8(memory[RAM_PANID]) + Utils.hex8(memory[RAM_PANID + 1])); } } else { //log("Read RAM Addr: " + address + " Data: " + memory[address]); - source.byteReceived(memory[address++]); - if (address >= 0x180) { + source.byteReceived(memory[usartDataAddress++]); + if (usartDataAddress >= 0x180) { logger.warning(this, "CC2420: Warning - RAM position too big - wrapping!"); - address = 0; + usartDataAddress = 0; } return; } @@ -1185,21 +1191,21 @@ private void updateCCA() { } private void setInternalCCA(boolean clear) { - setCCAPin(clear); + setCCA(clear); if (DEBUG) log("Internal CCA: " + clear); } - private void setSFD(boolean sfd) { + currentSFD = sfd; if( (registers[REG_IOCFG0] & SFD_POLARITY) == SFD_POLARITY) sfdPort.setPinState(sfdPin, sfd ? 0 : 1); else sfdPort.setPinState(sfdPin, sfd ? 1 : 0); - currentSFD = sfd; if (DEBUG) log("SFD: " + sfd + " " + cpu.cycles); } - private void setCCAPin(boolean cca) { + private void setCCA(boolean cca) { + currentCCA = cca; if (DEBUG) log("Setting CCA to: " + cca); if( (registers[REG_IOCFG0] & CCA_POLARITY) == CCA_POLARITY) ccaPort.setPinState(ccaPin, cca ? 0 : 1); @@ -1208,7 +1214,7 @@ private void setCCAPin(boolean cca) { } private void setFIFOP(boolean fifop) { - fifoP = fifop; + currentFIFOP = fifop; if (DEBUG) log("Setting FIFOP to " + fifop); if( (registers[REG_IOCFG0] & FIFOP_POLARITY) == FIFOP_POLARITY) { fifopPort.setPinState(fifopPin, fifop ? 0 : 1); @@ -1218,11 +1224,14 @@ private void setFIFOP(boolean fifop) { } private void setFIFO(boolean fifo) { - if (DEBUG) log("Setting FIFO to " + fifo); currentFIFO = fifo; + if (DEBUG) log("Setting FIFO to " + fifo); + if((registers[REG_IOCFG0] & FIFO_POLARITY) == FIFO_POLARITY) { + fifoPort.setPinState(fifoPin, fifo ? 0 : 1); + } else { fifoPort.setPinState(fifoPin, fifo ? 1 : 0); } - + } private void setRxOverflow() { if (DEBUG) log("RXFIFO Overflow! Read Pos: " + rxFIFO.stateToString()); @@ -1327,6 +1336,14 @@ public void setVRegOn(boolean newOn) { public void setChipSelect(boolean select) { chipSelect = select; if (!chipSelect) { + if (state == SpiState.WRITE_REGISTER && usartDataPos == 1) { + // Register write incomplete. Do a 8 bit register write. + usartDataValue = (registers[usartDataAddress] & 0xff) | (usartDataValue & 0xff00); + if (DEBUG) { + log("wrote 8 MSB to 0x" + Utils.hex8(usartDataAddress) + " = " + usartDataValue); + } + setReg(usartDataAddress, usartDataValue); + } state = SpiState.WAITING; } @@ -1362,7 +1379,7 @@ public void setSFDPort(IOPort port, int pin) { // ------------------------------------------------------------------- // Methods for accessing and writing to registers, etc from outside - // And for receiveing data + // And for receiving data // ------------------------------------------------------------------- public int getRegister(int register) { @@ -1398,7 +1415,7 @@ public String info() { " OSC Stable: " + ((status & STATUS_XOSC16M_STABLE) > 0) + "\n RSSI Valid: " + ((status & STATUS_RSSI_VALID) > 0) + " CCA: " + cca + "\n FIFOP Polarity: " + ((registers[REG_IOCFG0] & FIFOP_POLARITY) == FIFOP_POLARITY) + - " FIFOP: " + fifoP + " FIFO: " + currentFIFO + " SFD: " + currentSFD + + " FIFOP: " + currentFIFOP + " FIFO: " + currentFIFO + " SFD: " + currentSFD + "\n " + rxFIFO.stateToString() + " expPacketLen: " + rxlen + "\n Radio State: " + stateMachine + " SPI State: " + state + "\n AutoACK: " + autoAck + " AddrDecode: " + addressDecode + " AutoCRC: " + autoCRC + commit 76d76d927e264e8bc8faef484a41d859a4b0eac4 Author: Niclas Finne <nf...@si...> Date: Fri Mar 2 21:49:15 2012 +0100 Added generics diff --git a/se/sics/mspsim/util/ArrayUtils.java b/se/sics/mspsim/util/ArrayUtils.java index 48d0b1e..f27fe34 100644 --- a/se/sics/mspsim/util/ArrayUtils.java +++ b/se/sics/mspsim/util/ArrayUtils.java @@ -2,26 +2,28 @@ public class ArrayUtils { - public static Object[] add(Class<?> componentType, Object[] array, Object value) { - Object[] tmp; + @SuppressWarnings("unchecked") + public static <T> T[] add(Class<T> componentType, T[] array, T value) { + T[] tmp; if (array == null) { - tmp = (Object[]) java.lang.reflect.Array.newInstance(componentType, 1); + tmp = (T[]) java.lang.reflect.Array.newInstance(componentType, 1); } else { - tmp = (Object[]) java.lang.reflect.Array.newInstance(componentType, array.length + 1); + tmp = (T[]) java.lang.reflect.Array.newInstance(componentType, array.length + 1); System.arraycopy(array, 0, tmp, 0, array.length); } tmp[tmp.length - 1] = value; return tmp; } - public static Object[] remove(Object[] array, Object value) { + public static <T> T[] remove(T[] array, T value) { if (array != null) { for (int index = 0, n = array.length; index < n; index++) { if (value.equals(array[index])) { if (n == 1) { return null; } - Object[] tmp = (Object[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), array.length - 1); + @SuppressWarnings("unchecked") + T[] tmp = (T[]) java.lang.reflect.Array.newInstance(array.getClass().getComponentType(), array.length - 1); if (index > 0) { System.arraycopy(array, 0, tmp, 0, index); } ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/chip/CC2420.java | 129 ++++++++++++++++++++--------------- se/sics/mspsim/util/ArrayUtils.java | 14 ++-- 2 files changed, 81 insertions(+), 62 deletions(-) hooks/post-receive -- mspsim |
From: Niclas F. <ni...@us...> - 2012-03-01 23:12:00
|
The branch "master" has been updated via 9eda161ee31c5839d14e3e68cc3504fc064fd1dc (commit) from da2da23a8035054ff4bef78c169d163fe8c8246c (commit) Changed paths: M se/sics/mspsim/core/MSP430Core.java - Log ----------------------------------------------------------------- commit 9eda161ee31c5839d14e3e68cc3504fc064fd1dc Author: Niclas Finne <nf...@si...> Date: Fri Mar 2 00:11:30 2012 +0100 Global CPU monitor should be called before the memory write is performed. diff --git a/se/sics/mspsim/core/MSP430Core.java b/se/sics/mspsim/core/MSP430Core.java index 875e9cb..3002a7c 100644 --- a/se/sics/mspsim/core/MSP430Core.java +++ b/se/sics/mspsim/core/MSP430Core.java @@ -801,10 +801,16 @@ public void write(int dstAddress, int dst, int mode) throws EmulationException { dstAddress %= MAX_MEM; } + /* is a null check as fast as a boolean check? */ CPUMonitor wp = watchPoints[dstAddress]; if (wp != null) { wp.cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, dst); } + wp = globalMonitor; + if (wp != null) { + wp.cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, dst); + } + boolean word = mode != MODE_BYTE; // Only word writes at 0x1fe which is highest address... @@ -834,11 +840,6 @@ public void write(int dstAddress, int dst, int mode) throws EmulationException { } } } - /* is a null check as fast as a boolean check */ - wp = globalMonitor; - if (wp != null) { - wp.cpuAction(CPUMonitor.MEMORY_WRITE, dstAddress, dst); - } } void profileCall(int dst, int pc) { @@ -867,7 +868,6 @@ void printWarning(int type, int address) throws EmulationException { case ADDRESS_OUT_OF_BOUNDS_WRITE: message = "**** Illegal write - out of bounds from $" + getAddressAsString(address) + " at $" + getAddressAsString(reg[PC]); - break; } if (logger != null && message != null) { ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/core/MSP430Core.java | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) hooks/post-receive -- mspsim |
From: Fredrik Ãs. <fro...@us...> - 2012-03-01 14:18:11
|
The branch "master" has been updated via da2da23a8035054ff4bef78c169d163fe8c8246c (commit) via a9cd759c8b6417dc28d5ffdfa607855c47021dfd (commit) from a6c0d2c9fe8c5bd4a15b1d0016ab2a104908d12d (commit) Changed paths: M se/sics/mspsim/cli/CommandHandler.java M se/sics/mspsim/util/SimpleProfiler.java - Log ----------------------------------------------------------------- commit da2da23a8035054ff4bef78c169d163fe8c8246c Author: Fredrik Osterlind <fr...@si...> Date: Thu Mar 1 15:17:12 2012 +0100 added method to retrieve mapentry of current stack diff --git a/se/sics/mspsim/util/SimpleProfiler.java b/se/sics/mspsim/util/SimpleProfiler.java index 9ed993e..07e513b 100644 --- a/se/sics/mspsim/util/SimpleProfiler.java +++ b/se/sics/mspsim/util/SimpleProfiler.java @@ -430,7 +430,7 @@ public int compare(CallEntry o1, CallEntry o2) { } } - private static class CallEntry { + public static class CallEntry { int fromPC; MapEntry function; long cycles; @@ -551,7 +551,11 @@ public synchronized void removeCallListener(CallListener listener) { } public String getCall(int i) { - return callStack[cSP - i].function.getInfo(); + return callStack[cSP - i - 1].function.getInfo(); + } + + public MapEntry getCallMapEntry(int i) { + return callStack[cSP - i - 1].function; } public void setStackMonitor(StackMonitor stackMonitor) { commit a9cd759c8b6417dc28d5ffdfa607855c47021dfd Author: Fredrik Osterlind <fr...@si...> Date: Thu Mar 1 15:16:23 2012 +0100 using correct command context print streams diff --git a/se/sics/mspsim/cli/CommandHandler.java b/se/sics/mspsim/cli/CommandHandler.java index 6b3f09a..22f5122 100644 --- a/se/sics/mspsim/cli/CommandHandler.java +++ b/se/sics/mspsim/cli/CommandHandler.java @@ -44,21 +44,21 @@ public void registerCommand(String cmd, Command command) { public int executeCommand(String commandLine, CommandContext context) { String[][] parts; - PrintStream out = context == null ? this.out : context.out; - PrintStream err = context == null ? this.err : context.err; + final PrintStream cOut = context == null ? this.out : context.out; + final PrintStream cErr = context == null ? this.err : context.err; try { parts = CommandParser.parseCommandLine(commandLine); } catch (Exception e) { - err.println("Error: failed to parse command:"); - e.printStackTrace(err); + cErr.println("Error: failed to parse command:"); + e.printStackTrace(cErr); return -1; } if (parts == null || parts.length == 0) { // Nothing to execute return 0; } - Command[] cmds = createCommands(parts); + Command[] cmds = createCommands(parts, cErr); if(cmds != null && cmds.length > 0) { CommandContext[] commands = new CommandContext[parts.length]; boolean error = false; @@ -73,11 +73,11 @@ public int executeCommand(String commandLine, CommandContext context) { if (i > 0) { PrintStream po = new PrintStream(new LineOutputStream((LineListener) commands[i].getCommand())); - commands[i - 1].setOutput(po, err); + commands[i - 1].setOutput(po, cErr); } // Last element also needs output! if (i == parts.length - 1) { - commands[i].setOutput(out, err); + commands[i].setOutput(cOut, cErr); } // TODO: Check if first command is also LineListener and set it up for input!! } @@ -87,14 +87,14 @@ public int executeCommand(String commandLine, CommandContext context) { for (; index >= 0; index--) { int code = commands[index].getCommand().executeCommand(commands[index]); if (code != 0) { - err.println("command '" + commands[index].getCommandName() + "' failed with error code " + code); + cErr.println("command '" + commands[index].getCommandName() + "' failed with error code " + code); error = true; break; } } } catch (Exception e) { - err.println("Error: Command failed: " + e.getMessage()); - e.printStackTrace(err); + cErr.println("Error: Command failed: " + e.getMessage()); + e.printStackTrace(cErr); error = true; if (e instanceof EmulationException) { throw (EmulationException) e; @@ -143,7 +143,7 @@ private Command getCommand(String cmd) { return null; } - private Command[] createCommands(String[][] commandList) { + private Command[] createCommands(String[][] commandList, PrintStream err) { Command[] cmds = new Command[commandList.length]; for (int i = 0; i < commandList.length; i++) { Command command = getCommand(commandList[i][0]); ----------------------------------------------------------------------- Summary of changes: se/sics/mspsim/cli/CommandHandler.java | 24 ++++++++++++------------ se/sics/mspsim/util/SimpleProfiler.java | 8 ++++++-- 2 files changed, 18 insertions(+), 14 deletions(-) hooks/post-receive -- mspsim |