VirtualBox

Changeset 8986 in vbox


Ignore:
Timestamp:
May 21, 2008 12:08:29 AM (17 years ago)
Author:
vboxsync
Message:

Changed the undefined opcode handling; the default now is to fail. --all-invalid got changed to --undef-op=all. --raw got changed to --undef-op=db (define byte).

Location:
trunk/src/VBox/Disassembler/testcase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Disassembler/testcase/Makefile.kmk

    r8970 r8986  
    3434        $(LIB_RUNTIME)
    3535
    36 # Tests that
     36# Tests that will be build, disassembled and re-build from disassembly.
    3737VBOX_DISAS_TESTS_BUILD = \
    3838        tstAsmLock-1.asm \
    3939
    40 # Tests that makes use of --all-invalid.
     40# Tests that only contains invalid/undefined instructions.
    4141VBOX_DISAS_TESTS_INVALID = \
    4242        tstAsmLock-2.asm \
     
    120120        $(CMP) $(@:.tst=.bin) $<
    121121        @$(APPEND) $@ "done"
     122        @$(ECHO) "PASSED:  $(<F) [re-assembled]"
    122123
    123124
     
    127128
    128129$(addprefix $(VBOX_DISAS_TEST_PATH)/, $(VBOX_DISAS_TESTS_INVALID:.asm=-16.tst)): $$(patsubst %.tst,%.bin,$$@) $$(INSTARGET_tstDisasm-2) | $$(call DIRDEP,$$(@D))
    129         @$(ECHO) "Verifying all-invalid: $(@F)"
     130        @$(ECHO) "TESTING: $(@F) [--undef-op=all]"
    130131        @$(RM) -f $@
    131         $(INSTARGET_tstDisasm-2) --all-invalid --cpumode=16 $<
     132        $(INSTARGET_tstDisasm-2) --undef-op=all --cpumode=16 $<
    132133        @$(APPEND) $@ "done"
     134        @$(ECHO) "PASSED:  $(@F) [--undef-op=all]"
    133135
    134136$(addprefix $(VBOX_DISAS_TEST_PATH)/, $(VBOX_DISAS_TESTS_INVALID:.asm=-32.tst)): $$(patsubst %.tst,%.bin,$$@) $$(INSTARGET_tstDisasm-2) | $$(call DIRDEP,$$(@D))
    135         @$(ECHO) "Verifying all-invalid: $(@F)"
     137        @$(ECHO) "TESTING: $(@F) [--undef-op=all]"
    136138        @$(RM) -f $@
    137         $(INSTARGET_tstDisasm-2) --all-invalid --cpumode=32 $<
     139        $(INSTARGET_tstDisasm-2) --undef-op=all --cpumode=32 $<
    138140        @$(APPEND) $@ "done"
     141        @$(ECHO) "PASSED:  $(@F) [--undef-op=all]"
    139142
    140143$(addprefix $(VBOX_DISAS_TEST_PATH)/, $(VBOX_DISAS_TESTS_INVALID:.asm=-64.tst)): $$(patsubst %.tst,%.bin,$$@) $$(INSTARGET_tstDisasm-2) | $$(call DIRDEP,$$(@D))
    141         @$(ECHO) "Verifying all-invalid: $(@F)"
     144        @$(ECHO) "TESTING: $(@F) [--undef-op=all]"
    142145        @$(RM) -f $@
    143         $(INSTARGET_tstDisasm-2) --all-invalid --cpumode=64 $<
     146        $(INSTARGET_tstDisasm-2) --undef-op=all --cpumode=64 $<
    144147        @$(APPEND) $@ "done"
     148        @$(ECHO) "PASSED:  $(@F) [--undef-op=all]"
    145149
    146150# Add the .tst to the clean up.
  • trunk/src/VBox/Disassembler/testcase/tstDisasm-2.cpp

    r8937 r8986  
    3636*******************************************************************************/
    3737typedef enum { kAsmStyle_Default, kAsmStyle_yasm, kAsmStyle_masm, kAsmStyle_invalid } ASMSTYLE;
     38typedef enum { kUndefOp_Fail, kUndefOp_All, kUndefOp_DefineByte, kUndefOp_End } UNDEFOPHANDLING;
    3839
    3940typedef struct MYDISSTATE
     
    4344    uint8_t        *pbInstr;            /**< The current instruction (pointer). */
    4445    uint32_t        cbInstr;            /**< The size of the current instruction. */
    45     bool            fInvalid;           /**< Whether the instruction is invalid/illegal or not. */
    46     bool            fRaw;               /**< Whether invalid instructions are printed as byte defintions or not. */
     46    bool            fUndefOp;           /**< Whether the current instruction is really an undefined opcode.*/
     47    UNDEFOPHANDLING enmUndefOp;         /**< How to treat undefined opcodes. */
    4748    int             rc;                 /**< Set if we hit EOF. */
    4849    size_t          cbLeft;             /**< The number of bytes left. (read) */
     
    135136        /*
    136137         * Jumping up the stream.
     138         * This occures when the byte sequence is added to the output string.
    137139         */
    138140        uint64_t offReq64 = uSrcAddr - pState->uAddress;
     
    210212 * @param   enmStyle    The assembly output style.
    211213 * @param   fListing    Whether to print in a listing like mode.
    212  * @param   fRaw        Whether to output byte definitions for invalid sequences.
    213  * @param   fAllInvalid Whether all instructions are expected to be invalid.
     214 * @param   enmUndefOp  How to deal with undefined opcodes.
    214215 */
    215216static int MyDisasmBlock(const char *argv0, DISCPUMODE enmCpuMode, uint64_t uAddress, uint8_t *pbFile, size_t cbFile,
    216                          ASMSTYLE enmStyle, bool fListing, bool fRaw, bool fAllInvalid)
     217                         ASMSTYLE enmStyle, bool fListing, UNDEFOPHANDLING enmUndefOp)
    217218{
    218219    /*
     
    225226    State.pbInstr = pbFile;
    226227    State.cbInstr = 0;
    227     State.fInvalid = false;
    228     State.fRaw = fRaw;
     228    State.enmUndefOp = enmUndefOp;
    229229    State.rc = VINF_SUCCESS;
    230230    State.cbLeft = cbFile;
     
    269269        if (RT_SUCCESS(rc))
    270270        {
    271             State.fInvalid = State.Cpu.pCurInstr->opcode == OP_INVALID
     271            State.fUndefOp = State.Cpu.pCurInstr->opcode == OP_INVALID
    272272                          || State.Cpu.pCurInstr->opcode == OP_ILLUD2;
    273             if (!fAllInvalid || State.fInvalid)
    274                 pfnFormatter(&State);
    275             else
     273            if (!State.fUndefOp && State.enmUndefOp == kUndefOp_All)
    276274            {
    277275                RTPrintf("%s: error at %#RX64: unexpected valid instruction (op=%d)\n", argv0, State.uAddress, State.Cpu.pCurInstr->opcode);
     
    279277                rcRet = VERR_GENERAL_FAILURE;
    280278            }
     279            else if (State.fUndefOp && State.enmUndefOp == kUndefOp_Fail)
     280            {
     281                RTPrintf("%s: error at %#RX64: undefined opcode (op=%d)\n", argv0, State.uAddress, State.Cpu.pCurInstr->opcode);
     282                pfnFormatter(&State);
     283                rcRet = VERR_GENERAL_FAILURE;
     284            }
     285            else
     286                pfnFormatter(&State);
    281287        }
    282288        else
     
    325331"  --cpumode|-c <16|32|64>\n"
    326332"    The cpu mode. Default: 32\n"
    327 "  --all-invalid|-i\n"
    328 "    When specified all instructions are expected to be invalid.\n"
    329333"  --listing|-l, --no-listing|-L\n"
    330334"    Enables or disables listing mode. Default: --no-listing\n"
    331335"  --offset|-o <offset>\n"
    332336"    The file offset at which to start disassembling. Default: 0\n"
    333 "  --raw|-r, --no-raw|-R\n"
    334 "    Whether to employ byte defines for unknown bits. Default: --no-raw\n"
    335337"  --style|-s <default|yasm|masm>\n"
    336338"    The assembly output style. Default: default\n"
     339"  --undef-op|-u <fail|all|db>\n"
     340"    How to treat undefined opcodes. Default: fail\n"
    337341             , argv0, argv0);
    338342    return 1;
     
    348352    uint64_t uAddress = 0;
    349353    ASMSTYLE enmStyle = kAsmStyle_Default;
     354    UNDEFOPHANDLING enmUndefOp = kUndefOp_Fail;
    350355    bool fListing = true;
    351     bool fRaw = false;
    352     bool fAllInvalid = false;
    353356    DISCPUMODE enmCpuMode = CPUMODE_32BIT;
    354357    RTFOFF off = 0;
     
    364367        { "--help",         'h', 0 },
    365368        { "--bytes",        'b', RTGETOPT_REQ_INT64 },
    366         { "--all-invalid",  'i', 0, },
    367369        { "--listing",      'l', 0 },
    368370        { "--no-listing",   'L', 0 },
    369371        { "--offset",       'o', RTGETOPT_REQ_INT64 },
    370         { "--raw",          'r', 0 },
    371         { "--no-raw",       'R', 0 },
    372372        { "--style",        's', RTGETOPT_REQ_STRING },
     373        { "--undef-op",     'u', RTGETOPT_REQ_STRING },
    373374    };
    374375
     
    405406                return Usage(argv0);
    406407
    407             case 'i':
    408                 fAllInvalid = true;
    409                 break;
    410 
    411408            case 'l':
    412409                fListing = true;
     
    419416            case 'o':
    420417                off = ValueUnion.i;
    421                 break;
    422 
    423             case 'r':
    424                 fRaw = true;
    425                 break;
    426 
    427             case 'R':
    428                 fRaw = false;
    429418                break;
    430419
     
    447436                break;
    448437
     438            case 'u':
     439                if (!strcmp(ValueUnion.psz, "fail"))
     440                    enmUndefOp = kUndefOp_Fail;
     441                else if (!strcmp(ValueUnion.psz, "all"))
     442                    enmUndefOp = kUndefOp_All;
     443                else if (!strcmp(ValueUnion.psz, "db"))
     444                    enmUndefOp = kUndefOp_DefineByte;
     445                else
     446                {
     447                    RTStrmPrintf(g_pStdErr, "%s: unknown undefined opcode handling method: %s\n", argv0, ValueUnion.psz);
     448                    return 1;
     449                }
     450                break;
     451
    449452            default:
    450453                RTStrmPrintf(g_pStdErr, "%s: syntax error: %Rrc\n", argv0, ch);
     
    476479         * Disassemble it.
    477480         */
    478         rc = MyDisasmBlock(argv0, enmCpuMode, uAddress, (uint8_t *)pvFile, cbFile, enmStyle, fListing, fRaw, fAllInvalid);
     481        rc = MyDisasmBlock(argv0, enmCpuMode, uAddress, (uint8_t *)pvFile, cbFile, enmStyle, fListing, enmUndefOp);
    479482        if (RT_FAILURE(rc))
    480483            break;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette