Target Communication Framework Services - Disassembly

Disassembly Service

Version History

Version Date Change
0.1 2011-02-18 Initial contribution

Overview

Disassembly is the translation of machine language (or memory bytes), into human readable assembly language. The readable assembly language is produced from a specified Instruction Set Architecture (or ISA).

While disassembly is dependent upon a specific processor architecture, the memory from which it is derived is not. So for a given memory context, or buffer, the specified ISA used to disassemble the memory bytes is subjective to the Tool or user.

The service uses standard format for error reports, see Error Report Format.

Commands

Disassemble


C • <token> • Disassembly • disassemble • <string: context-id><int: start location><int: size><object: disassembly parameters>

The command disassembles instruction code from a specified range of memory, in a specified context.

Where context-id is the memory context in which to process the command.

Predefined properties are:

Reply:


R • <token><error report><array: disassembly output><array: disassembly output><null>
    ⇒ [ ]
    ⇒ [ <disassembly line list> ]

<disassembly line list><object: disassembly line><disassembly line list>, <object: disassembly line>

<object: disassembly line>

Disassembly line is an object containing properties. Predefined properties are:


<object: Instruction field>

Instruction field is an object containing properties. Predefined properties are:

Examples:

The following command requests disassembly at address 0x1000, for 8 bytes, in memory context "mc1", using a generic PowerPC ISA, and requesting instruction code bytes:


C <token> Disassembly disassemble "mc1" 0x1000 8 {ISA:PPC,OpcodeValue:true}

Get Capabilities


C • <token> • Disassembly • getCapabilities • <string: context ID>

The command reports disassembly service capabilities to clients so they can adjust to different implementations of the service. The exact definition of context depends on the target agent and provided topology.

Reply:


R • <token><error report><service capabilities><service capabilities><null><array: capabilities list>

Service capabilities consist of an array of lists of properties. All properties are optional. Tools and targets can define additional properties. Predefined properties are:

API

/**
 * TCF Disassembly service interface.
 */
public interface IDisassembly extends IService {

    /**
     * Service name.
     */
    static final String NAME = "Disassembly";

    static final String
        /** The name of the instruction set architecture, String */
        CAPABILITY_ISA = "ISA",

        /** If true, simplified mnemonics are supported or requested, Boolean */
        CAPABILITY_SIMPLIFIED = "Simplified",

        /** If true, pseudo-instructions are supported or requested, Boolean */
        CAPABILITY_PSEUDO = "Pseudo",

        /** If true, instruction code bytes are supported or requested, Boolean */
        CAPABILITY_OPCODE = "OpcodeValue";

    /**
     * Retrieve disassembly service capabilities a given context-id.
     * @param context_id - a context ID, usually one returned by Run Control or Memory services.
     * @param done - command result call back object.
     * @return - pending command handle.
     */
    IToken getCapabilities(String context_id, DoneGetCapabilities done);

    /**
     * Call back interface for 'getCapabilities' command.
     */
    interface DoneGetCapabilities {
        /**
         * Called when capabilities retrieval is done.
         * @param token - command handle.
         * @param error - error object or null.
         * @param capabilities - array of capabilities, see CAPABILITY_* for contents of each array element.
         */
        void doneGetCapabilities(IToken token, Throwable error, Map<String,Object>[] capabilities);
    }

    /**
     * Disassemble instruction code from a specified range of memory addresses, in a specified context.
     * @param context_id - a context ID, usually one returned by Run Control or Memory services.
     * @param addr - address of first instruction to disassemble.
     * @param size - size in bytes of the address range.
     * @param params - properties to control the disassembly output, an element of capabilities array, see getCapabilities.
     * @param done - command result call back object.
     * @return - pending command handle.
     */

    IToken disassemble(String context_id, Number addr, int size, Map<String,Object> params, DoneDisassemble done);

    /**
     * Call back interface for 'disassemble' command.
     */
    interface DoneDisassemble {
        /**
         * Called when disassembling is done.
         * @param token - command handle.
         * @param error - error object or null.
         * @param disassembly - array of disassembly lines.
         */
        void doneDisassemble(IToken token, Throwable error, IDisassemblyLine[] disassembly);
    }

    /**
     * Interface to represent a single disassembly line.
     */
    interface IDisassemblyLine {

        /**
         * @return instruction address.
         */
        Number getAddress();

        /**
         * @return instruction size in bytes.
         */
        int getSize();

        /**
         * @return instruction binary representation.
         */
        byte[] getOpcodeValue();

        /**
         * @return array of instruction fields, each field is a collection of field properties, see FIELD_*.
         */
        Map<String,Object>[] getInstruction();
    }

    /** Instruction field properties */
    static final String
        /** The type of the instruction field. See FTYPE_*, String. */
        FIELD_TYPE = "Type",

        /** Value of the field for “String” and “Register” types, String. */
        FIELD_TEXT = "Text",

        /** Value of the field for “Address,” “Displacement,” or “Immediate” types, Number. */
        FIELD_VALUE = "Value",

        /** Context ID of the address space used with “Address” types, String. */
        FIELD_ADDRESS_SPACE = "AddressSpace";

    /** Instruction field types */
    static final String
        FTYPE_STRING = "String",
        FTYPE_REGISTER = "Register",
        FTYPE_ADDRESS = "Address",
        FTYPE_DISPLACEMENT = "Displacement",
        FTYPE_IMMEDIATE = "Immediate";
}