Package se.sics.mspsim.util

Examples of se.sics.mspsim.util.MapEntry


                break;
            case AM_IND_AUTOINC:
                if (register == 0) {
                    // Can this be PC and be incremented only one byte?
                    int tmp = memory[pc] + (memory[pc + 1] << 8);
                    MapEntry me;
                    if (map != null && (me = map.getEntry(tmp)) != null) {
                        adr = me.getName(); // + " = $" + Utils.hex16(tmp);
                    } else {
                        adr = "#$" + Utils.hex16(tmp);
                    }
                    size += 2;
                } else {
                    adr = "@(R" + register + "+)";
                    dstAddress = reg[register];
                }
                break;
            }

            switch(instruction & 0xff80) {
            case RRC:
                opstr = "RRC" + (word ? ".W" : ".B");
                break;
            case SWPB:
                opstr = "SWPB" + (word ? ".W" : ".B");
                break;
            case RRA:
                opstr = "RRA" + (word ? ".W" : ".B");
                break;
            case SXT:
                opstr = "RRA" + (word ? ".W" : ".B");
                break;
            case PUSH:
                opstr = "PUSH" + (word ? ".W" : ".B");
                break;
            case CALL:
                opstr = "CALL";
                break;
            case RETI:
                opstr = "RETI";
                break;
            default:
                if ((instruction & 0xf800) == 0x1800) {
                    int zc = (instruction & EXTWORD_ZC) > 0 ? 1 : 0;
                    int al = (instruction & EXTWORD_AL) > 0 ? 1 : 0;
                    int rp = (instruction & EXTWORD_REPEAT) > 0 ? 1 : 0;
                    int shi = (instruction & EXTWORD_SRC) >> 7;
                    int dhi = (instruction & EXTWORD_DST);
                    opstr = "ExtWord " + Utils.hex16(instruction) + ":ZC:" + zc + " #:" + rp +
                    " A/L:" + al + " src:" + shi + " dst:" + dhi;
                    dbg.setExtWord(true);
                } else {
                    System.out.println("Not implemented instruction: $" + Utils.hex16(instruction) +
                            " at " + Utils.hex16(startPC));
                    opstr = "<Unkown>";
                }
            }
            output += dumpMem(startPC, size, memory);
            output += opstr + " " + adr;
            regs = "R" + register + "=" + Utils.hex16(reg[register]);
            regs += " SP=" + Utils.hex16(reg[SP]);
        }
    }
    break;
    // Jump instructions
    case 2:
    case 3:
      // 10 bits for address for these => 0x00fc => remove 2 bits
      int jmpOffset = instruction & 0x3ff;
      jmpOffset = (jmpOffset & 0x200) == 0 ?
  2 * jmpOffset : -(2 * (0x200 - (jmpOffset & 0x1ff)));
      boolean jump = false;
      String opstr = "";
      switch(instruction & 0xfc00) {
      case JNE:
  opstr = "JNE";
  break;
      case JEQ:
  opstr = "JEQ";
  break;
      case JNC:
  opstr = "JNC";
  break;
      case JC:
  opstr = "JC";
  break;
      case JN:
  opstr = "JN";
  break;
      case JGE:
  opstr = "JGE";
  break;
      case JL:
  opstr = "JL";
  break;
      case JMP:
  opstr = "JMP";
  break;
      default:
  System.out.println("Not implemented instruction: " +
         Utils.binary16(instruction));
      }
      output += dumpMem(startPC, size, memory);
      output += opstr + " $" + Utils.hex16(jmpOffset);
      regs = "\tSR=" + dumpSR(reg[SR]);
      break;
    default:
      // ---------------------------------------------------------------
      // Double operand instructions!
      // ---------------------------------------------------------------
      int dstRegister = (instruction & 0xf);
      int srcRegister = (instruction >> 8) & 0xf;
      int as = (instruction >> 4) & 3;

      // AD: 0 => register direct, 1 => register index, e.g. X(Rn)
      boolean dstRegMode = ((instruction >> 7) & 1) == 0;
      int dstAddress = 0;
      int srcAddress = 0;
      int src = 0;
      int dst = 0;
      boolean write = false;
      boolean updateStatus = true;
      String srcadr = "";
      String dstadr = "";
      switch(as) {
  // Operand in register!
      case AM_REG:
  if (srcRegister == CG2) {
    srcadr = "#0";
  } else if (srcRegister == CG1) {
    srcadr = "#0";
  } else {
    srcadr = getRegName(srcRegister);
  }
  break;
      case AM_INDEX:
  // Indexed if reg != PC & CG1/CG2 - will PC be incremented?
  if (srcRegister == CG1) {
    srcAddress = memory[pc] + (memory[pc + 1] << 8);

    MapEntry me;
    if (map != null && (me = map.getEntry(srcAddress)) != null) {
      srcadr = "&" + me.getName(); // + " = $" + Utils.hex16(srcAddress);
    } else {
      srcadr = "&$" + Utils.hex16(srcAddress);
    }
    size += 2;
  } else if (srcRegister == CG2) {
    srcadr = "#1";
  } else {
    srcAddress = reg[srcRegister] + memory[pc] + (memory[pc + 1] << 8);
    srcadr = "$" + Utils.hex16(memory[pc] + (memory[pc + 1] << 8)) + "(R" + srcRegister + ")";
    size += 2;
  }
  pc += 2;
  break;
  // Indirect register
      case AM_IND_REG:
  if (srcRegister == CG2) {
    srcadr = "#2";
  } else if (srcRegister == CG1) {
    srcadr = "#4";
  } else {
    srcadr = "@" + getRegName(srcRegister);
  }
  break;
      case AM_IND_AUTOINC:
  if (srcRegister == CG2) {
    srcadr = "#$ffff";
  } else if (srcRegister == CG1) {
    srcadr = "#8";
  } else if (srcRegister == PC) {
    srcadr = "#$" + Utils.hex16(memory[pc] + (memory[pc + 1] << 8));
    pc += 2;
    size += 2;
  } else if (srcRegister == CG2) {
    srcadr = "#$ffff";
  } else {
    srcadr = "@" + getRegName(srcRegister) + "+";
    srcAddress = reg[srcRegister];
  }
  break;
      }

      if (dstRegMode) {
  dstadr = getRegName(dstRegister);
      } else {
  dstAddress = memory[pc] + (memory[pc + 1] << 8);
        MapEntry me = map != null ? map.getEntry(dstAddress) : null;
  if (dstRegister == 2) {
    if (me != null) {
            dstadr = "&" + me.getName(); // + " = $" + Utils.hex16(srcAddress);
    } else {
      dstadr = "&$" + Utils.hex16(dstAddress);
    }
  } else {
          if (me != null) {
            dstadr = me.getName() + "(R" + dstRegister + ")";
          } else {
            dstadr = "$" + Utils.hex16(dstAddress) + "(R" + dstRegister + ")";
          }
  }
  pc += 2;
View Full Code Here


      }
    }
  }

  private static String getSymOrAddr(MSP430 cpu, CommandContext context, int adr) {
    MapEntry me = context.getMapTable().getEntry(adr);
    if (me != null) {
      return me.getName();
    }
    return '$' + cpu.getAddressAsString(adr);
  }
View Full Code Here

                }});
        }
    }

    public void functionCall(Profiler source, CallEntry callEntry) {
        MapEntry entry = callEntry.getFunction();
        // Check for function calls before <prefix>_init() has been called.
        String name = entry.getName();
        if (name != null && callTable.get(name) == null) {
            boolean addEntry = true;
            int index = name.indexOf('_');
            if (index > 0 && !name.endsWith("_init")) {
                int lastIndex = name.lastIndexOf('_');
View Full Code Here

        // System.err.println("SimpleProfiler: Too many returns?");
      }
      return;
    }
    CallEntry cspEntry = callStack[--cSP];
    MapEntry fkn = cspEntry.function;
//     System.out.println("Profiler: return / call stack: " + cSP + ", " + fkn);
   
    long elapsed = cycles - cspEntry.cycles;
    long exElapsed = cycles - cspEntry.exclusiveCycles;
    if (cSP != 0) {
      callStack[cSP-1].exclusiveCycles += elapsed;
    }
    int maxUsage = 0;
   
    if (cspEntry.calls >= 0) {
      CallEntry ce = profileData.get(fkn);
      if (ce == null) {
        profileData.put(fkn, ce = new CallEntry());
        ce.function = fkn;
      }
      ce.cycles += elapsed;
      ce.exclusiveCycles += exElapsed;
      ce.calls++;
     
      if (stackMonitor != null) {
          maxUsage = stackMonitor.getProfStackMax() - cspEntry.stackStart;
          ce.stackStart = cspEntry.stackStart;
          if (maxUsage > ce.currentStackMax) {
              ce.currentStackMax = maxUsage;
          }
          if (cSP != 0) {
              /* put the max for previous function back into the max profiler */
              stackMonitor.setProfStackMax(callStack[cSP-1].currentStackMax);
          }
      }

     
     
      if (cSP != 0) {
        MapEntry caller = callStack[cSP-1].function;
        HashMap<MapEntry,CallCounter> callers = ce.callers;
        CallCounter numCalls = callers.get(caller);
        if (numCalls == null) {
          numCalls = new CallCounter();
          callers.put(caller, numCalls);
View Full Code Here

    }
    throw new UnknownVariableException(varName);
  }

  public int getVariableAddress(String varName) throws UnknownVariableException {
    MapEntry entry = getMapEntry(varName);
    return entry.getAddress();
  }
View Full Code Here

  }

  /* TODO Check correct variable size in below methods */

  public int getIntValueOf(String varName) throws UnknownVariableException {
    MapEntry entry = getMapEntry(varName);

    int varAddr = entry.getAddress();
    byte[] varData = getMemorySegment(varAddr, 2);

    int retVal = 0;
    int pos = 0;
    retVal += ((varData[pos++] & 0xFF)) << 8;
View Full Code Here

    return Integer.reverseBytes(retVal) >> 16; // Crop two bytes
  }

  public void setIntValueOf(String varName, int newVal) throws UnknownVariableException {
    MapEntry entry = getMapEntry(varName);
    int varAddr = entry.getAddress();

    int newValToSet = Integer.reverseBytes(newVal);

    // Create byte array
    int pos = 0;
View Full Code Here

    setMemorySegment(varAddr, varData);
  }

  public byte getByteValueOf(String varName) throws UnknownVariableException {
    MapEntry entry = getMapEntry(varName);
    int varAddr = entry.getAddress();

    byte[] varData = getMemorySegment(varAddr, 1);

    return varData[0];
  }
View Full Code Here

    return varData[0];
  }

  public void setByteValueOf(String varName, byte newVal) throws UnknownVariableException {
    MapEntry entry = getMapEntry(varName);
    int varAddr = entry.getAddress();

    byte[] varData = new byte[1];

    varData[0] = newVal;
View Full Code Here

    setMemorySegment(varAddr, varData);
  }

  public byte[] getByteArray(String varName, int length) throws UnknownVariableException {
    MapEntry entry = getMapEntry(varName);
    int varAddr = entry.getAddress();

    // TODO Check if small/big-endian when coming from JNI?
    return getMemorySegment(varAddr, length);
  }
View Full Code Here

TOP

Related Classes of se.sics.mspsim.util.MapEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.