Merge pull request #22 from nfi/Java7

Fix single step (GUI) to work again. Update build to use Java 7.
This commit is contained in:
Joakim Eriksson 2013-10-20 05:52:51 -07:00
commit e1ce900b31
9 changed files with 68 additions and 77 deletions

View File

@ -2,7 +2,7 @@
# Makefile for mspsim # Makefile for mspsim
# #
# Needed stuff in the PATH: # Needed stuff in the PATH:
# java, javac (JDK 1.6 or newer) # java, javac (JDK 1.7 or newer)
# #
# Under MS-DOS/Windows # Under MS-DOS/Windows
# A GNU compatible Make (for example Cygwin's) # A GNU compatible Make (for example Cygwin's)
@ -46,7 +46,7 @@ SPACE := ${EMPTY} ${EMPTY}
LIBS := ${wildcard lib/*.jar} LIBS := ${wildcard lib/*.jar}
BUILD := build BUILD := build
CLASSPATH=${subst ${SPACE},${SEPARATOR},$(BUILD)/ ${LIBS}} CLASSPATH=${subst ${SPACE},${SEPARATOR},$(BUILD)/ ${LIBS}}
CCARGS=-deprecation -classpath ".${SEPARATOR}${CLASSPATH}" -d $(BUILD) CCARGS=-deprecation -Xlint:unchecked -source 1.7 -target 1.7 -classpath ".${SEPARATOR}${CLASSPATH}" -d $(BUILD)
JAVAARGS=-classpath "${CLASSPATH}" JAVAARGS=-classpath "${CLASSPATH}"
@ -196,3 +196,6 @@ $(BUILD)/%.class : %.java $(BUILD)
clean: clean:
-$(RM) -r $(BUILD) -$(RM) -r $(BUILD)
distclean: clean
-$(RM) -f $(JARFILE)

View File

@ -7,9 +7,8 @@ some tools for monitoring stack, setting breakpoints, and profiling.
* System requirements * System requirements
You need a recent Java to run MSPSim. Java SE 1.5 or newer is You need a recent Java to run MSPSim. Java SE 1.7 or newer is recommended.
recommended. The current version of MSPSim also requires make for The current version of MSPSim also requires make or ant for compiling.
compiling.
* Building MSPSim * Building MSPSim
@ -60,4 +59,4 @@ Run the default example on the Sky node emulator by typing:
- currently the emulator runs as if it can use all memory as RAM - currently the emulator runs as if it can use all memory as RAM
(e.g. flash writes, etc not supported) (e.g. flash writes, etc not supported)
- no DMA implementation - no DMA implementation
- timer system not 100% emulated - timer system not 100% emulated

View File

@ -8,6 +8,8 @@
<property name="lib" location="lib"/> <property name="lib" location="lib"/>
<property name="jarfile" location="mspsim.jar"/> <property name="jarfile" location="mspsim.jar"/>
<property name="javac.debug" value="true"/> <property name="javac.debug" value="true"/>
<property name="ant.build.javac.source" value="1.7"/>
<property name="ant.build.javac.target" value="1.7"/>
<path id="classpath"> <path id="classpath">
<fileset dir="${lib}" includes="**/*.jar"/> <fileset dir="${lib}" includes="**/*.jar"/>
@ -23,8 +25,12 @@
</target> </target>
<target name="compile" depends="init" description="compile the source"> <target name="compile" depends="init" description="compile the source">
<javac srcdir="${src}" destdir="${build}" classpathref="classpath" debug="${javac.debug}" <javac srcdir="${src}" destdir="${build}" classpathref="classpath"
includeantruntime="false"/> debug="${javac.debug}" includeantruntime="false">
<compilerarg value="-Xlint:unchecked"/>
<compilerarg value="-deprecation"/>
<exclude name="tests/**" />
</javac>
</target> </target>
<target name="jar" depends="compile" description="generate MSPSim jar file" > <target name="jar" depends="compile" description="generate MSPSim jar file" >

View File

@ -4,7 +4,6 @@ import java.io.PrintStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Hashtable; import java.util.Hashtable;
import se.sics.mspsim.core.EmulationException; import se.sics.mspsim.core.EmulationException;
import se.sics.mspsim.util.ActiveComponent; import se.sics.mspsim.util.ActiveComponent;
import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.ComponentRegistry;
@ -32,7 +31,7 @@ public class CommandHandler implements ActiveComponent, LineListener {
private MapTable getMapTable() { private MapTable getMapTable() {
if (mapTable == null && registry != null) { if (mapTable == null && registry != null) {
mapTable = (MapTable) registry.getComponent(MapTable.class); mapTable = registry.getComponent(MapTable.class);
} }
return mapTable; return mapTable;
} }
@ -42,6 +41,7 @@ public class CommandHandler implements ActiveComponent, LineListener {
commands.put(cmd, command); commands.put(cmd, command);
} }
@SuppressWarnings("resource")
public int executeCommand(String commandLine, CommandContext context) { public int executeCommand(String commandLine, CommandContext context) {
String[][] parts; String[][] parts;
final PrintStream cOut = context == null ? this.out : context.out; final PrintStream cOut = context == null ? this.out : context.out;

View File

@ -35,8 +35,6 @@
* Created : 17 jan 2008 * Created : 17 jan 2008
*/ */
package se.sics.mspsim.core; package se.sics.mspsim.core;
import java.io.PrintStream;
import se.sics.mspsim.core.EmulationLogger.WarningType; import se.sics.mspsim.core.EmulationLogger.WarningType;
import se.sics.mspsim.util.ArrayUtils; import se.sics.mspsim.util.ArrayUtils;
@ -63,7 +61,6 @@ public abstract class Chip implements Loggable, EventSource {
private int mode; private int mode;
private int chipState; private int chipState;
protected EmulationLogger logger; protected EmulationLogger logger;
private PrintStream log;
protected boolean DEBUG = false; protected boolean DEBUG = false;
protected int logLevel; protected int logLevel;

View File

@ -146,7 +146,8 @@ public class MSP430 extends MSP430Core {
isStopping = isBreaking = false; isStopping = isBreaking = false;
} }
public long step() throws EmulationException { /* Use stepInstructions or stepMicros instead */
@Deprecated public long step() throws EmulationException {
return stepMicros(1, 1); return stepMicros(1, 1);
} }
@ -156,16 +157,18 @@ public class MSP430 extends MSP430Core {
} }
setRunning(true); setRunning(true);
try { try {
while (count-- > 0 && !isStopping) { while (count > 0 && !isStopping) {
int pc = emulateOP(-1); int pc = emulateOP(-1);
if (pc >= 0) { if (pc >= 0) {
count--;
if (execCounter != null) { if (execCounter != null) {
execCounter[pc]++; execCounter[pc]++;
} }
if (trace != null) { if (trace != null) {
trace[tracePos++] = pc; trace[tracePos++] = pc;
if (tracePos >= trace.length) if (tracePos >= trace.length) {
tracePos = 0; tracePos = 0;
}
} }
// ------------------------------------------------------------------- // -------------------------------------------------------------------

View File

@ -324,9 +324,8 @@ public class EmuLink {
} }
} }
public void run() throws IOException { public void run() {
try { try (ServerSocket serverSocket = new ServerSocket(8000)) {
ServerSocket serverSocket = new ServerSocket(8000);
while(true) { while(true) {
@ -356,7 +355,7 @@ public class EmuLink {
} }
} }
public static void main(String[] args) throws IOException { public static void main(String[] args) {
EmuLink el = new EmuLink(); EmuLink el = new EmuLink();
el.run(); el.run();
} }

View File

@ -41,9 +41,7 @@ import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import javax.swing.JFrame; import javax.swing.JFrame;
import se.sics.mspsim.cli.CommandHandler; import se.sics.mspsim.cli.CommandHandler;
import se.sics.mspsim.cli.DebugCommands; import se.sics.mspsim.cli.DebugCommands;
import se.sics.mspsim.cli.FileCommands; import se.sics.mspsim.cli.FileCommands;
@ -54,7 +52,6 @@ import se.sics.mspsim.cli.StreamCommandHandler;
import se.sics.mspsim.cli.WindowCommands; import se.sics.mspsim.cli.WindowCommands;
import se.sics.mspsim.core.Chip; import se.sics.mspsim.core.Chip;
import se.sics.mspsim.core.EmulationException; import se.sics.mspsim.core.EmulationException;
import se.sics.mspsim.core.EmulationLogger;
import se.sics.mspsim.core.MSP430; import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.core.MSP430Config; import se.sics.mspsim.core.MSP430Config;
import se.sics.mspsim.core.MSP430Constants; import se.sics.mspsim.core.MSP430Constants;
@ -67,7 +64,6 @@ import se.sics.mspsim.ui.WindowUtils;
import se.sics.mspsim.util.ArgumentManager; import se.sics.mspsim.util.ArgumentManager;
import se.sics.mspsim.util.ComponentRegistry; import se.sics.mspsim.util.ComponentRegistry;
import se.sics.mspsim.util.ConfigManager; import se.sics.mspsim.util.ConfigManager;
import se.sics.mspsim.util.DefaultEmulationLogger;
import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.ELF;
import se.sics.mspsim.util.IHexReader; import se.sics.mspsim.util.IHexReader;
import se.sics.mspsim.util.MapTable; import se.sics.mspsim.util.MapTable;
@ -276,11 +272,9 @@ public abstract class GenericNode extends Chip implements Runnable {
public void stop() { public void stop() {
cpu.stop(); cpu.stop();
} }
public void step() throws EmulationException { public void step() throws EmulationException {
if (!cpu.isRunning()) { step(1);
cpu.step();
}
} }
// A step that will break out of breakpoints! // A step that will break out of breakpoints!

View File

@ -47,19 +47,19 @@ import javax.swing.JLabel;
import javax.swing.JList; import javax.swing.JList;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.ListCellRenderer; import javax.swing.ListCellRenderer;
import se.sics.mspsim.core.DbgInstruction;
import se.sics.mspsim.core.*; import se.sics.mspsim.core.DisAsm;
import se.sics.mspsim.core.MSP430;
import se.sics.mspsim.util.Utils; import se.sics.mspsim.util.Utils;
public class DebugUI extends JPanel { public class DebugUI extends JPanel {
private static final long serialVersionUID = 2123628878332126912L; private static final long serialVersionUID = 2123628878332126912L;
private JList disList; private JList<DbgInstruction> disList;
private DbgListModel listModel;
private JLabel[] regsLabel; private JLabel[] regsLabel;
private MSP430 cpu; private MSP430 cpu;
private DbgListModel listModel;
private int currentAddress = 0;
private DisAsm disAsm; private DisAsm disAsm;
@ -76,7 +76,8 @@ public class DebugUI extends JPanel {
this.cpu = cpu; this.cpu = cpu;
disAsm = cpu.getDisAsm(); disAsm = cpu.getDisAsm();
disList = new JList(listModel = new DbgListModel()); listModel = new DbgListModel();
disList = new JList<DbgInstruction>(listModel);
disList.setFont(new Font("courier", 0, 12)); disList.setFont(new Font("courier", 0, 12));
disList.setCellRenderer(new MyCellRenderer()); disList.setCellRenderer(new MyCellRenderer());
disList.setPreferredSize(new Dimension(500, 350)); disList.setPreferredSize(new Dimension(500, 350));
@ -102,7 +103,7 @@ public class DebugUI extends JPanel {
repaint(); repaint();
} }
private class DbgListModel extends AbstractListModel { private class DbgListModel extends AbstractListModel<DbgInstruction> {
private static final long serialVersionUID = -2856626511548201481L; private static final long serialVersionUID = -2856626511548201481L;
int startPos = -1; int startPos = -1;
@ -111,44 +112,36 @@ public class DebugUI extends JPanel {
DbgInstruction[] instructions = new DbgInstruction[size]; DbgInstruction[] instructions = new DbgInstruction[size];
// 64K Dbg instructions...
// private DbgInstruction[] instrs = new DbgInstruction[0x10000];
public void setCurrentAddress(int address) {
startPos = address;
}
// ------------------------------------------------------------------- // -------------------------------------------------------------------
// ListAPI // ListAPI
// ------------------------------------------------------------------- // -------------------------------------------------------------------
@Override
public int getSize() { public int getSize() {
return size; return size;
} }
private void checkPC() { private void checkPC() {
int pc = cpu.reg[MSP430Core.PC]; int pc = cpu.getPC();
if (pc < startPos || pc > endPos) { if (pc < startPos || pc > endPos) {
startPos = pc; startPos = pc;
// recalculate index!!! with PC at the top of the "page" // recalculate index!!! with PC at the top of the "page"
int currentPos = pc; int currentPos = pc;
DbgInstruction inst;
for (int i = 0, n = size; i < n; i++) { for (int i = 0, n = size; i < n; i++) {
if (cpu.getExecCount(currentPos) != 0 || true) { // if (cpu.getExecCount(currentPos) == 0) {
inst = disAsm.getDbgInstruction(currentPos, cpu); // inst = new DbgInstruction();
inst.setPos(currentPos); // inst.setInstruction(cpu.memory[currentPos] + (cpu.memory[currentPos + 1] << 8), 2);
currentPos += inst.getSize(); // inst.setASMLine(" " + Utils.hex(currentPos, 4) + " " +
} else { // Utils.hex8(cpu.memory[currentPos]) + " " +
inst = new DbgInstruction(); // Utils.hex8(cpu.memory[currentPos + 1]) +
inst.setASMLine(" " + Utils.hex16(currentPos) + " " + // " .word " + Utils.hex8(cpu.memory[currentPos]) +
Utils.hex8(cpu.memory[currentPos]) + " " + // Utils.hex8(cpu.memory[currentPos + 1]));
Utils.hex8(cpu.memory[currentPos + 1]) + // } else {
" .word " + Utils.hex8(cpu.memory[currentPos]) +
Utils.hex8(cpu.memory[currentPos + 1])); DbgInstruction inst = disAsm.getDbgInstruction(currentPos, cpu);
inst.setPos(currentPos); inst.setPos(currentPos);
currentPos += 2; currentPos += inst.getSize();
} instructions[i] = inst;
instructions[i] = inst;
} }
endPos = currentPos; endPos = currentPos;
} }
@ -157,13 +150,14 @@ public class DebugUI extends JPanel {
// Should cache the current 20 (or size) instructions to get a faster // Should cache the current 20 (or size) instructions to get a faster
// version of this... // version of this...
// And have a call to "update" instead... // And have a call to "update" instead...
public Object getElementAt(int index) { @Override
public DbgInstruction getElementAt(int index) {
checkPC(); checkPC();
return instructions[index]; return instructions[index];
} }
} }
class MyCellRenderer extends JLabel implements ListCellRenderer { class MyCellRenderer extends JLabel implements ListCellRenderer<DbgInstruction> {
private static final long serialVersionUID = -2633138712695105181L; private static final long serialVersionUID = -2633138712695105181L;
@ -171,36 +165,32 @@ public class DebugUI extends JPanel {
setOpaque(true); setOpaque(true);
} }
@Override
public Component getListCellRendererComponent( public Component getListCellRendererComponent(
JList list, JList<? extends DbgInstruction> list,
Object value, // value to display DbgInstruction instruction, // instruct to display
int index, // cell index int index, // cell index
boolean isSelected, // is the cell selected boolean isSelected, // is the cell selected
boolean cellHasFocus) // the list and the cell have the focus boolean cellHasFocus) // the list and the cell have the focus
{ {
String s; String s;
int pos = 0; int pos = 0;
if (value == null) { if (instruction == null) {
s = "---"; s = "---";
} else { } else {
if (value instanceof DbgInstruction) { pos = instruction.getPos();
DbgInstruction i = (DbgInstruction) value; s = instruction.getASMLine(false);
s = i.getASMLine(false);
if (i.getFunction() != null) {
s += "; " + i.getFunction();
}
pos = i.getPos();
if (cpu.hasWatchPoint(pos)) { if (cpu.hasWatchPoint(pos)) {
s = "*B " + s; s = "*B " + s;
} else { } else {
s = " " + s; s = " " + s;
} }
} else { if (instruction.getFunction() != null) {
s = value.toString(); s += "; " + instruction.getFunction();
} }
} }
setText(s); setText(s);
if (pos == cpu.reg[MSP430Core.PC]) { if (pos == cpu.getPC()) {
setBackground(Color.green); setBackground(Color.green);
} else { } else {
if (isSelected) { if (isSelected) {