updated APIs

This commit is contained in:
Joakim Eriksson 2012-03-22 19:52:24 +01:00
commit 48de0943bf
11 changed files with 161 additions and 32 deletions

View File

@ -1318,6 +1318,13 @@ public class CC2420 extends Chip implements USARTListener, RFListener, RFSource
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;

48
se/sics/mspsim/chip/Memory.java Executable file
View File

@ -0,0 +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.chip;
public interface Memory {
public int readByte(int address);
public void writeByte(int dstAddress, int dst);
}

View File

@ -40,7 +40,7 @@ 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.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,16 @@ public class DebugCommands implements CommandBundle {
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 +152,17 @@ public class DebugCommands implements CommandBundle {
}
}
}
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 +215,16 @@ public class DebugCommands implements CommandBundle {
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 +363,8 @@ public class DebugCommands implements CommandBundle {
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 +490,7 @@ public class DebugCommands implements CommandBundle {
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 +498,7 @@ public class DebugCommands implements CommandBundle {
} 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);
}
}
}

View File

@ -168,7 +168,4 @@ public class MSP430f1611Config extends MSP430Config {
return 3 + 6;
}
}

View File

@ -1690,16 +1690,29 @@ public class MSP430Core extends Chip implements MSP430Constants {
}
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 + currentSegment.read(pc, MODE_WORD, Memory.TYPE_READ)) & 0xffff;
} else {
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);

View File

@ -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;

View File

@ -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 @@ public class ContikiChecker implements CallListener, ActiveComponent {
private ComponentRegistry registry;
private CommandContext context;
private CPUMonitor monitor;
private MemoryMonitor monitor;
private MSP430 cpu;
private Profiler profiler;
@ -91,14 +91,26 @@ public class ContikiChecker implements CallListener, ActiveComponent {
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);

View File

@ -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 @@ public class CPUHeatMap extends JComponent implements CPUMonitor {
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,28 @@ public class CPUHeatMap extends JComponent implements CPUMonitor {
}
}
@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
}
}

View File

@ -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 @@ public class StackUI extends JPanel implements CPUMonitor, ServiceComponent {
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();

View File

@ -176,7 +176,7 @@ public class GDBStubs implements Runnable {
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);
}

View File

@ -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 @@ public class StackMonitor implements CPUMonitor {
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);