Skip to content
Open
2 changes: 1 addition & 1 deletion se/sics/mspsim/config/MSP430f5437Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public MSP430f5437Config() {

/* configure memory */
infoMemConfig(0x1800, 128 * 4);
mainFlashConfig(0x5c00, 256 * 1024);
mainFlashConfig(0x5c00, 768 * 1024);
ramConfig(0x1c00, 16 * 1024);
ioMemSize(0x800); /* 2 KB of IO Memory */

Expand Down
12 changes: 6 additions & 6 deletions se/sics/mspsim/core/DisAsm.java
Original file line number Diff line number Diff line change
Expand Up @@ -556,16 +556,16 @@ public DbgInstruction disassemble(int pc, int[] memory, int[] reg,
output += dumpMem(startPC, size, memory);
output += opstr + " " + srcadr + ", " + dstadr;

regs = "R" + dstRegister + "=" + Utils.hex16(reg[dstRegister]) +
" R" + srcRegister + "=" + Utils.hex16(reg[srcRegister]);
regs = "R" + dstRegister + "=" + Utils.hex20(reg[dstRegister]) +
" R" + srcRegister + "=" + Utils.hex20(reg[srcRegister]);
regs += " SR=" + dumpSR(reg[SR]);
regs += " SP=" + Utils.hex16(reg[SP]);
regs += " SP=" + Utils.hex20(reg[SP]);
regs += "; as = " + as;
srcAddress &= 0xffff;
srcAddress &= 0xfffff;
if (srcAddress != -1) {
srcAddress &= 0xffff;
srcAddress &= 0xfffff;
regs += " sMem:" + Utils.hex16(memory[srcAddress] +
(memory[(srcAddress + 1) % 0xffff]
(memory[(srcAddress + 1) % 0xfffff]
<< 8));
}
}
Expand Down
13 changes: 12 additions & 1 deletion se/sics/mspsim/core/MSP430.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
package se.sics.mspsim.core;
import java.io.PrintStream;

import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.profiler.SimpleProfiler;
import se.sics.mspsim.util.ArrayUtils;
import se.sics.mspsim.util.ComponentRegistry;
Expand All @@ -48,11 +49,13 @@ public class MSP430 extends MSP430Core {
private int[] execCounter;
private int[] trace;
private int tracePos;
private int prevPc = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to initialize this one, 0 is the default value for fields of numeric types.


private boolean debug = false;
private boolean running = false;
private boolean isBreaking = false;
private double rate = 2.0;
private boolean realtime = true;

// Debug time - measure cycles
private long lastCycles = 0;
Expand All @@ -76,6 +79,10 @@ public MSP430(int type, ComponentRegistry registry, MSP430Config config) {
disAsm = new DisAsm();
}

public void setRealtime(boolean realtime) {
this.realtime = realtime;
}

public double getCPUPercent() {
return lastCPUPercent;
}
Expand All @@ -93,6 +100,9 @@ public void cpuloop() throws EmulationException {
// ??? - power-up should be executed?!
time = System.currentTimeMillis();
run();
} catch (Exception e) {
disAsm.disassemble(prevPc, memory, reg);
throw(e);
} finally {
setRunning(false);
}
Expand All @@ -106,6 +116,7 @@ private void run() throws EmulationException {
nextOut = cycles + 20000007;
}

prevPc = reg[PC];
int pc = emulateOP(-1);
if (pc >= 0) {
if (execCounter != null) {
Expand All @@ -129,7 +140,7 @@ private void run() throws EmulationException {
}

/* Just a test to see if it gets down to a reasonable speed */
if (cycles > nextSleep) {
if (realtime && cycles > nextSleep) {
try {
Thread.sleep(100);
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion se/sics/mspsim/core/MSP430Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public interface MSP430Constants {
public static final int CG2 = 3;

public static final int[][] CREG_VALUES = new int[][]{
{0, 0, 4, 8}, {0, 1, 2, 0xffff}
{0, 0, 4, 8}, {0, 1, 2, 0xfffff}
};

public static final int CARRY_B = 0;
Expand Down
47 changes: 45 additions & 2 deletions se/sics/mspsim/core/MSP430Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,15 @@ public MSP430Core(int type, ComponentRegistry registry, MSP430Config config) {
@Override
public int read(int address, AccessMode mode, AccessType type) throws EmulationException {
if (address >= MAX_MEM) {
logw(WarningType.EXECUTION, "Read out of bounds");
throw new EmulationException("Reading outside memory: 0x" + Utils.hex(address, 4));
}
return memorySegments[address >> 8].read(address, mode, type);
}
@Override
public void write(int address, int data, AccessMode mode) throws EmulationException {
if (address >= MAX_MEM) {
logw(WarningType.EXECUTION, "write out of bounds");
throw new EmulationException("Writing outside memory: 0x" + Utils.hex(address, 4));
}
memorySegments[address >> 8].write(address, data, mode);
Expand Down Expand Up @@ -454,10 +456,50 @@ public void writeRegister(int r, int value) {
* Yet, this has been observed at least once with msp430-gcc 4.6.3. */
System.out.println("Warning: tried to write odd PC, not allowed! PC=0x" + Integer.toHexString(value));
value -= 1;
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental whitespace change.


/* SR can never take values above 0xfff */
if (r == SR) {

/* semihosting by trapping and ignoring writes to SR */

/* exit (0xf000) */
if (value == 0xf000) {
int code = reg[15];
System.exit(code);
}

/* putchar (0xf001) */
if (value == 0xf001) {
int data = reg[12];
System.out.print((char) data);
return;
}

/* message and value (char *, int) (0xf002) */
if (value == 0xf002) {
int message = reg[12];
int data = reg[13];
char c;
System.out.printf("0x%x 0x%x: ", reg[0], message);
try {
int off;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the declaration of off can be in the for-header.

for (off = 0; off < 20 && (c = (char) currentSegment.read(message + off, AccessMode.BYTE, AccessType.READ)) != 0; off++)
System.out.print(c);
} catch(Exception e) {
System.out.printf("Bad message at 0x%x", reg[13]);
}
System.out.printf(" 0x%x %d\n", data, data);
return;
}

/* dump registers (0xf003) */
if (value == 0xf003) {
for (int rn = 0; rn < 15; rn++)
System.out.printf("R%02d: 0x%05x ", rn, reg[rn]);
System.out.printf("\n");
return;
}
value &= 0xfff;
}

Expand Down Expand Up @@ -2027,7 +2069,8 @@ public int emulateOP(long maxCycles) throws EmulationException {
tmpAdd = 1;
case SUBC:
// Both sub and subc does one complement (not) + 1 (or carry)
src = (src ^ 0xffff) & 0xffff;
int mask = word ? 0xffff : (wordx20 ? 0xfffff : 0xff);
src = (src ^ mask) & mask;
case ADDC: // ADDC
if (op == ADDC || op == SUBC)
tmpAdd = ((sr & CARRY) > 0) ? 1 : 0;
Expand Down
28 changes: 18 additions & 10 deletions se/sics/mspsim/platform/GenericNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public void setupArgs(ArgumentManager config) throws IOException {

setup(config);

cpu.setRealtime(config.getPropertyAsBoolean("realtime", true));

if (!config.getPropertyAsBoolean("nogui", false)) {
// Setup control and other UI components
Expand Down Expand Up @@ -183,7 +184,9 @@ public void setupArgs(ArgumentManager config) throws IOException {
if (fp.canRead()) {
CommandHandler ch = registry.getComponent(CommandHandler.class, "commandHandler");
script = script.replace('\\', '/');
System.out.println("Autoloading script: " + script);
if (!config.getPropertyAsBoolean("quiet", false)) {
System.out.println("Autoloading script: " + script);
}
config.setProperty("autoloadScript", script);
if (ch != null) {
ch.lineRead("source \"" + script + '"');
Expand All @@ -196,16 +199,19 @@ public void setupArgs(ArgumentManager config) throws IOException {
CommandHandler ch = registry.getComponent(CommandHandler.class, "commandHandler");
if (ch != null) {
for (int i = 1; i < args.length; i++) {
System.out.println("calling '" + args[i] + "'");
if (!config.getPropertyAsBoolean("quiet", false))
System.out.println("calling '" + args[i] + "'");
ch.lineRead(args[i]);
}
}
}
System.out.println("-----------------------------------------------");
System.out.println("MSPSim " + MSP430Constants.VERSION + " starting firmware: " + firmwareFile);
System.out.println("-----------------------------------------------");
System.out.print(PROMPT);
System.out.flush();
if (!config.getPropertyAsBoolean("quiet", false)) {
System.out.println("-----------------------------------------------");
System.out.println("MSPSim " + MSP430Constants.VERSION + " starting firmware: " + firmwareFile);
System.out.println("-----------------------------------------------");
System.out.print(PROMPT);
System.out.flush();
}
}

public void setup(ConfigManager config) {
Expand All @@ -231,10 +237,12 @@ public void setup(ConfigManager config) {
WindowUtils.addSaveOnShutdown(key, w);
w.setVisible(true);
console.setCommandHandler(ch);
} else {
ch = new StreamCommandHandler(System.in, System.out, System.err, PROMPT);
} else if (config.getPropertyAsBoolean("console", true)) {
ch = new StreamCommandHandler(System.in, System.out, System.err, PROMPT);
} else {
ch = new CommandHandler(System.out, System.err);
}
registry.registerComponent("commandHandler", ch);
registry.registerComponent("commandHandler", ch);
}

stats = new OperatingModeStatistics(cpu);
Expand Down
16 changes: 14 additions & 2 deletions se/sics/mspsim/platform/tyndall/TyndallNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,19 @@ public void setupNode() {
SerialMon serial = new SerialMon((USARTSource)usart, "USCI A0 Port Output");
registry.registerComponent("serialgui", serial);
}
}
} else {
// Send serial output to stdout
IOUnit usart = cpu.getIOUnit("USCI A0");
if (usart instanceof USARTSource) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can become if (usart instanceof USARTSource usartSource) { in the Cooja repository, and the line with the cast below omitted.

USARTSource usartSource = (USARTSource) usart;
USARTListener listener = new USARTListener() {
public void dataReceived(USARTSource source, int data) {
System.out.print((char) data);
}
};
usartSource.addUSARTListener(listener);
}
}
}

public void setupGUI() {
Expand All @@ -170,4 +182,4 @@ public static void main(String[] args) throws IOException {
config.handleArguments(args);
node.setupArgs(config);
}
}
}