1 package net.mograsim.plugin.launch;
3 import org.eclipse.debug.core.DebugException;
4 import org.eclipse.debug.core.ILaunch;
5 import org.eclipse.debug.core.model.IDebugTarget;
6 import org.eclipse.debug.core.model.IMemoryBlock;
8 import net.mograsim.machine.MainMemory;
9 import net.mograsim.plugin.MograsimActivator;
11 public class MainMemoryBlock implements IMemoryBlock
13 private final MachineDebugTarget debugTarget;
14 private final MainMemory mem;
15 private final long startAddress;
16 private final int length;
18 public MainMemoryBlock(MachineDebugTarget debugTarget, long startAddress, long length)
21 throw new IllegalArgumentException("Can't create a memory block of negative size");
22 if (length > Integer.MAX_VALUE)
23 throw new IllegalArgumentException("Can't create a memory block bigger than Integer.MAX_VALUE (" + Integer.MAX_VALUE + "\"");
24 if (startAddress % 2 != 0)
25 throw new IllegalArgumentException("Can't create an unaligned memory block");
27 this.debugTarget = debugTarget;
28 this.mem = debugTarget.getMachine().getMainMemory();
29 this.startAddress = startAddress;
30 this.length = (int) length;
34 public String getModelIdentifier()
36 return MograsimActivator.PLUGIN_ID;
40 public IDebugTarget getDebugTarget()
46 public ILaunch getLaunch()
48 return debugTarget.getLaunch();
52 public <T> T getAdapter(Class<T> adapter)
59 public long getStartAddress()
65 public long getLength()
71 public byte[] getBytes() throws DebugException
73 // TODO speedup. Maybe make a method for this in MainMemory?
74 byte[] bs = new byte[length];
77 for (i = 0, j = startAddress / 2; i < length; i++)
79 short word = mem.getCellAsBigInteger(j).shortValueExact();
80 bs[i + 0] = (byte) (word & 0xFF);
81 bs[i + 1] = (byte) (word >>> 8);
87 public boolean supportsValueModification()
94 public void setValue(long offset, byte[] bytes) throws DebugException