Examples of DbgInstruction


Examples of se.sics.mspsim.core.DbgInstruction

            }
            // Does not yet handle signed data...
            DisAsm disAsm = cpu.getDisAsm();
            for (int i = 0; i < count; i++) {
                if (mode == Utils.DIS_ASM) {
                    DbgInstruction dbg = disAsm.disassemble(start, cpu.memory, cpu.reg, new DbgInstruction(),
                            0);
                    String fkn;
                    if ((fkn = dbg.getFunction()) != null) {
                        context.out.println("//// " + fkn);
                    }
                    context.out.println(dbg.getASMLine(false));
                    start += dbg.getSize();
                } else {
                    int data = 0;
                    data = cpu.memory[start++];
                    if (Utils.size(type) == 2) {
                        data = data  + (cpu.memory[start++] << 8);
                    }
                    context.out.print((mode != Utils.ASCII ? " " : "") +
                            Utils.toString(data, type, mode));
                }
            }
            context.out.println();
            return 0;
          }
        });

        ch.registerCommand("mset", new BasicCommand("set memory", "<address> [type] <value> [value ...]") {
          public int executeCommand(final CommandContext context) {
            int count = context.getArgumentCount();
            int adr = context.getArgumentAsAddress(0);
            String arg2 = context.getArgument(1);
            int type = Utils.BYTE;
            int mode = Utils.DEC;
            boolean typeRead = false;
            if (count > 2) {
              if ("char".equals(arg2)) {
                mode = Utils.ASCII;
                typeRead = true;
              }
              if ("word".equals(arg2)) {
                type = Utils.WORD;
                typeRead = true;
              }
            }
            for (int i = typeRead ? 2 : 1; i < count; i++) {
              if (mode == Utils.DEC) {
                int val = context.getArgumentAsInt(i);
                AccessMode accessMode = Utils.size(type) == 2 || val > 0xff ? AccessMode.WORD : AccessMode.BYTE;
                try {
                  cpu.getMemory().set(adr, val, accessMode);
                  adr += accessMode.bytes;
                } catch (EmulationException e) {
                  e.printStackTrace(context.out);
                }
              } else if (mode == Utils.ASCII) {
                String data = context.getArgument(i);
                Memory mem = cpu.getMemory();
                for (int j = 0; j < data.length(); j++) {
                  mem.set(adr++, data.charAt(j), AccessMode.BYTE);
                }
              }
            }
            return 0;
          }});

        /******************************************************
         * handle external memory (flash, etc).
         ******************************************************/
        ch.registerCommand("xmem", new BasicCommand("dump flash memory", "<start address> <num_entries> [type]") {
          public int executeCommand(final CommandContext context) {
            se.sics.mspsim.chip.Memory xmem = DebugCommands.this.registry.getComponent(se.sics.mspsim.chip.Memory.class, "xmem");
            if (xmem == null) {
              context.err.println("No xmem component registered");
              return 0;
            }
            int start = context.getArgumentAsAddress(0);
            int count = context.getArgumentAsInt(1);
            int size = 1; // unsigned byte
            boolean signed = false;
            if (context.getArgumentCount() > 2) {
              String tS = context.getArgument(2);
              if ("byte".equals(tS)) {
                signed = true;
              } else if ("word".equals(tS)) {
                signed = true;
                size = 2;
              } else if ("uword".equals(tS)) {
                size = 2;
              }
            }
            // Does not yet handle signed data...
            for (int i = 0; i < count; i++) {
              int data = 0;
              data = xmem.readByte(start++);
              if (size == 2) {
                data = data  + (xmem.readByte(start++) << 8);
              }
              context.out.print(" " + data);
            }
            context.out.println();
            return 0;
          }
        });

        ch.registerCommand("xmset", new BasicCommand("set memory", "<address> <value> [type]") {
          public int executeCommand(final CommandContext context) {
            se.sics.mspsim.chip.Memory xmem = DebugCommands.this.registry.getComponent(se.sics.mspsim.chip.Memory.class, "xmem");
            if (xmem == null) {
              context.err.println("No xmem component registered");
              return 0;
            }
            int adr = context.getArgumentAsAddress(0);
            int val = context.getArgumentAsInt(1);
            boolean word = val > 0xff;
            if (word) {
              xmem.writeByte(adr, val >> 8);
              val = val & 0xff;
              adr++;
            }
            xmem.writeByte(adr, val & 0xff);
            return 0;
          }});

        ch.registerCommand("gdbstubs", new BasicCommand("open up a gdb stubs server for GDB remote debugging", "port") {
          private GDBStubs stubs = null;
          public int executeCommand(CommandContext context) {
            if (stubs != null) {
              context.err.println("GDBStubs already open");
            } else {
              int port = context.getArgumentAsInt(0);
              stubs = new GDBStubs();
              stubs.setupServer(cpu, port);
            }
            return 0;
          }
        });

        ch.registerCommand("log", new BasicAsyncCommand("log a loggable object", "[loggable...]" ) {
            private Loggable[] logs;
            private int[] logLevels;
            private LogListener logListener;

            @Override
            public int executeCommand(final CommandContext context) {
                if (context.getArgumentCount() == 0) {
                    Loggable[] loggable = cpu.getLoggables();
                    for (Loggable unit : loggable) {
                        String id = unit.getID();
                        String name = unit.getName();
                        if (id == name) {
                            context.out.println("  " + id);
                        } else {
                            context.out.println("  " + id + " (" + name + ')');
                        }
                    }
                    context.exit(0);
                    return 0;
                }

                final Loggable[] logs = new Loggable[context.getArgumentCount()];
                for(int i = 0, n = context.getArgumentCount(); i < n; i++) {
                    logs[i] = cpu.getLoggable(context.getArgument(i));
                    if (logs[i] == null) {
                        context.err.println("Can not find loggable '" + context.getArgument(i) + '\'');
                        return 1;
                    }
                }
                logListener = new LogListener() {

                    boolean isLogging(Loggable source) {
                        for(Loggable log : logs) {
                            if (source == log) {
                                return true;
                            }
                        }
                        return false;
                    }

                    @Override
                    public void log(Loggable source, String message) {
                        if (isLogging(source)) {
                            context.out.println(source.getID() + ": " + message);
                        }
                    }

                    @Override
                    public void logw(Loggable source, WarningType type,
                            String message) throws EmulationException {
                        if (isLogging(source)) {
                            context.out.println("# " + source.getID() + "[" + type + "]: " + message);
                        }
                    }

                };
                this.logs = logs;
                cpu.getLogger().addLogListener(logListener);
                logLevels = new int[logs.length];
                int i = 0;
                for(Loggable log : logs) {
                    logLevels[i++] = log.getLogLevel();
                    log.setLogLevel(Loggable.DEBUG);
                }
                return 0;
            }

            public void stopCommand(CommandContext context) {
                if (logListener != null) {
                    cpu.getLogger().removeLogListener(logListener);
                    logListener = null;
                }
                if (logs != null) {
                    int i = 0;
                    for(Loggable log : logs) {
                        if (log.getLogLevel() == Loggable.DEBUG) {
                            log.setLogLevel(logLevels[i]);
                        }
                        i++;
                    }
                }
            }
        });

        ch.registerCommand("trace", new BasicCommand("store a trace of execution positions.", "[trace size | show]") {
            @Override
            public int executeCommand(CommandContext context) {
                if (context.getArgumentCount() > 0) {
                    if ("show".equals(context.getArgument(0))) {
                        int size = cpu.getTraceSize();
                        if (size > 0) {
                            DisAsm disAsm = cpu.getDisAsm();
                            for (int i = 0; i < size; i++) {
                                int pc = cpu.getBackTrace(size - 1 - i);
                                DbgInstruction inst = disAsm.getDbgInstruction(pc, cpu);
                                inst.setPos(pc);
                                context.out.println(inst.getASMLine(false));
                            }
                            return 0;
                        }
                    } else {
                        int newSize = context.getArgumentAsInt(0, -1);
View Full Code Here

Examples of se.sics.mspsim.core.DbgInstruction

//          Utils.hex8(cpu.memory[currentPos + 1]) +
//          "       .word " + Utils.hex8(cpu.memory[currentPos]) +
//          Utils.hex8(cpu.memory[currentPos + 1]));
//    } else {

          DbgInstruction inst = disAsm.getDbgInstruction(currentPos, cpu);
          inst.setPos(currentPos);
          currentPos += inst.getSize();
          instructions[i] = inst;
  }
  endPos = currentPos;
      }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.