Search
lxdream.org :: lxdream/src/aica/armdasm.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/armdasm.c
changeset 736:a02d1475ccfd
prev561:533f6b478071
next811:7ff871670e58
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (13 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
nkeynes@30
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@30
     3
 * 
nkeynes@4
     4
 * armdasm.c    21 Aug 2004  - ARM7tdmi (ARMv4) disassembler
nkeynes@4
     5
 *
nkeynes@30
     6
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@30
     7
 *
nkeynes@30
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@30
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@30
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@30
    11
 * (at your option) any later version.
nkeynes@30
    12
 *
nkeynes@30
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@30
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@30
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@30
    16
 * GNU General Public License for more details.
nkeynes@4
    17
 */
nkeynes@4
    18
nkeynes@7
    19
#include "aica/armcore.h"
nkeynes@11
    20
#include "aica/armdasm.h"
nkeynes@7
    21
#include <stdlib.h>
nkeynes@4
    22
nkeynes@4
    23
#define COND(ir) (ir>>28)
nkeynes@4
    24
#define OPCODE(ir) ((ir>>20)&0x1F)
nkeynes@4
    25
#define GRP(ir) ((ir>>26)&0x03)
nkeynes@4
    26
#define IFLAG(ir) (ir&0x02000000)
nkeynes@4
    27
#define SFLAG(ir) (ir&0x00100000)
nkeynes@4
    28
#define PFLAG(ir) (ir&0x01000000)
nkeynes@4
    29
#define UFLAG(ir) (ir&0x00800000)
nkeynes@4
    30
#define BFLAG(ir) (ir&0x00400000)
nkeynes@7
    31
#define WFLAG(ir) (ir&0x00200000)
nkeynes@4
    32
#define LFLAG(ir) SFLAG(ir)
nkeynes@4
    33
#define RN(ir) ((ir>>16)&0x0F)
nkeynes@4
    34
#define RD(ir) ((ir>>12)&0x0F)
nkeynes@4
    35
#define RS(ir) ((ir>>8)&0x0F)
nkeynes@4
    36
#define RM(ir) (ir&0x0F)
nkeynes@4
    37
nkeynes@4
    38
#define IMM8(ir) (ir&0xFF)
nkeynes@4
    39
#define IMM12(ir) (ir&0xFFF)
nkeynes@7
    40
#define SHIFTIMM(ir) ((ir>>7)&0x1F)
nkeynes@7
    41
#define IMMROT(ir) ((ir>>7)&0x1E)
nkeynes@4
    42
#define SHIFT(ir) ((ir>>4)&0x07)
nkeynes@4
    43
#define DISP24(ir) ((ir&0x00FFFFFF))
nkeynes@4
    44
#define FSXC(ir) msrFieldMask[RN(ir)]
nkeynes@4
    45
#define ROTIMM12(ir) ROTATE_RIGHT_LONG(IMM8(ir),IMMROT(ir))
nkeynes@431
    46
#define SIGNEXT24(n) (((n)&0x00800000) ? ((n)|0xFF000000) : ((n)&0x00FFFFFF))
nkeynes@13
    47
nkeynes@4
    48
nkeynes@11
    49
nkeynes@11
    50
const struct reg_desc_struct arm_reg_map[] = 
nkeynes@736
    51
{ {"R0", REG_INT, &armr.r[0]}, {"R1", REG_INT, &armr.r[1]},
nkeynes@736
    52
        {"R2", REG_INT, &armr.r[2]}, {"R3", REG_INT, &armr.r[3]},
nkeynes@736
    53
        {"R4", REG_INT, &armr.r[4]}, {"R5", REG_INT, &armr.r[5]},
nkeynes@736
    54
        {"R6", REG_INT, &armr.r[6]}, {"R7", REG_INT, &armr.r[7]},
nkeynes@736
    55
        {"R8", REG_INT, &armr.r[8]}, {"R9", REG_INT, &armr.r[9]},
nkeynes@736
    56
        {"R10",REG_INT, &armr.r[10]}, {"R11",REG_INT, &armr.r[11]},
nkeynes@736
    57
        {"R12",REG_INT, &armr.r[12]}, {"R13",REG_INT, &armr.r[13]},
nkeynes@736
    58
        {"R14",REG_INT, &armr.r[14]}, {"R15",REG_INT, &armr.r[15]},
nkeynes@736
    59
        {"CPSR", REG_INT, &armr.cpsr}, {"SPSR", REG_INT, &armr.spsr},
nkeynes@736
    60
        {NULL, 0, NULL} };
nkeynes@11
    61
nkeynes@11
    62
nkeynes@14
    63
const struct cpu_desc_struct arm_cpu_desc = 
nkeynes@736
    64
{ "ARM7", arm_disasm_instruction, arm_execute_instruction, arm_has_page,
nkeynes@736
    65
        arm_set_breakpoint, arm_clear_breakpoint, arm_get_breakpoint, 4,
nkeynes@736
    66
        (char *)&armr, sizeof(armr), arm_reg_map,
nkeynes@736
    67
        &armr.r[15] };
nkeynes@14
    68
const struct cpu_desc_struct armt_cpu_desc = 
nkeynes@736
    69
{ "ARM7T", armt_disasm_instruction, arm_execute_instruction, arm_has_page,
nkeynes@736
    70
        arm_set_breakpoint, arm_clear_breakpoint, arm_get_breakpoint, 2,
nkeynes@736
    71
        (char*)&armr, sizeof(armr), arm_reg_map,
nkeynes@736
    72
        &armr.r[15] };
nkeynes@11
    73
nkeynes@11
    74
nkeynes@11
    75
nkeynes@11
    76
nkeynes@4
    77
char *conditionNames[] = { "EQ", "NE", "CS", "CC", "MI", "PL", "VS", "VC", 
nkeynes@736
    78
        "HI", "LS", "GE", "LT", "GT", "LE", "  " /*AL*/, "NV" };
nkeynes@736
    79
nkeynes@736
    80
/* fsxc */
nkeynes@4
    81
char *msrFieldMask[] = { "", "c", "x", "xc", "s", "sc", "sx", "sxc",
nkeynes@736
    82
        "f", "fc", "fx", "fxc", "fs", "fsc", "fsx", "fsxc" };
nkeynes@7
    83
char *ldmModes[] = { "DA", "IA", "DB", "IB" };
nkeynes@4
    84
nkeynes@4
    85
#define UNIMP(ir) snprintf( buf, len, "???     " )
nkeynes@4
    86
nkeynes@7
    87
int arm_disasm_shift_operand( uint32_t ir, char *buf, int len )
nkeynes@4
    88
{
nkeynes@736
    89
    uint32_t operand, tmp;
nkeynes@736
    90
    if( IFLAG(ir) == 0 ) {
nkeynes@736
    91
        switch(SHIFT(ir)) {
nkeynes@736
    92
        case 0: /* (Rm << imm) */
nkeynes@736
    93
            tmp = SHIFTIMM(ir);
nkeynes@736
    94
            if( tmp != 0 ) {
nkeynes@736
    95
                return snprintf(buf, len, "R%d << %d", RM(ir), tmp );
nkeynes@736
    96
            } else {
nkeynes@736
    97
                return snprintf(buf, len, "R%d", RM(ir));
nkeynes@736
    98
            }
nkeynes@736
    99
        case 1: /* (Rm << Rs) */
nkeynes@736
   100
            return snprintf(buf, len, "R%d << R%d", RM(ir), RS(ir) );
nkeynes@736
   101
        case 2: /* (Rm >> imm) */
nkeynes@736
   102
            return snprintf(buf, len, "R%d >> %d", RM(ir), SHIFTIMM(ir) );
nkeynes@736
   103
        case 3: /* (Rm >> Rs) */
nkeynes@736
   104
            return snprintf(buf, len, "R%d >> R%d", RM(ir), RS(ir) );
nkeynes@736
   105
        case 4: /* (Rm >>> imm) */
nkeynes@736
   106
            return snprintf(buf, len, "R%d >>> %d", RM(ir), SHIFTIMM(ir) );
nkeynes@736
   107
        case 5: /* (Rm >>> Rs) */
nkeynes@736
   108
            return snprintf(buf, len, "R%d >>> R%d", RM(ir), RS(ir) );
nkeynes@736
   109
        case 6:
nkeynes@736
   110
            tmp = SHIFTIMM(ir);
nkeynes@736
   111
            if( tmp == 0 ) /* RRX aka rotate with carry */
nkeynes@736
   112
                return snprintf(buf, len, "R%d roc 1", RM(ir) );
nkeynes@736
   113
            else
nkeynes@736
   114
                return snprintf(buf, len, "R%d rot %d", RM(ir), SHIFTIMM(ir) );
nkeynes@736
   115
        case 7:
nkeynes@736
   116
            return snprintf(buf, len, "R%d rot R%d", RM(ir), RS(ir) );
nkeynes@736
   117
        }
nkeynes@736
   118
    } else {
nkeynes@736
   119
        operand = IMM8(ir);
nkeynes@736
   120
        tmp = IMMROT(ir);
nkeynes@736
   121
        operand = ROTATE_RIGHT_LONG(operand, tmp);
nkeynes@736
   122
        return snprintf(buf, len, "#%08Xh", operand );
nkeynes@736
   123
    }
nkeynes@736
   124
    return 0;
nkeynes@7
   125
}
nkeynes@7
   126
nkeynes@7
   127
static int arm_disasm_address_index( uint32_t ir, char *buf, int len )
nkeynes@7
   128
{
nkeynes@736
   129
    uint32_t tmp;
nkeynes@736
   130
nkeynes@736
   131
    switch(SHIFT(ir)) {
nkeynes@736
   132
    case 0: /* (Rm << imm) */
nkeynes@736
   133
        tmp = SHIFTIMM(ir);
nkeynes@736
   134
        if( tmp != 0 ) {
nkeynes@736
   135
            return snprintf( buf, len, "R%d << %d", RM(ir), tmp );
nkeynes@736
   136
        } else {
nkeynes@736
   137
            return snprintf( buf, len, "R%d", RM(ir) );
nkeynes@736
   138
        }
nkeynes@736
   139
    case 2: /* (Rm >> imm) */
nkeynes@736
   140
        return snprintf( buf, len, "R%d >> %d", RM(ir), SHIFTIMM(ir) );
nkeynes@736
   141
    case 4: /* (Rm >>> imm) */
nkeynes@736
   142
        return snprintf( buf, len, "R%d >>> %d", RM(ir), SHIFTIMM(ir) );
nkeynes@736
   143
    case 6:
nkeynes@736
   144
        tmp = SHIFTIMM(ir);
nkeynes@736
   145
        if( tmp == 0 ) /* RRX aka rotate with carry */
nkeynes@736
   146
            return snprintf( buf, len, "R%d roc 1", RM(ir) );
nkeynes@736
   147
        else
nkeynes@736
   148
            return snprintf( buf, len, "R%d rot %d", RM(ir), tmp );
nkeynes@736
   149
    default: 
nkeynes@736
   150
        return UNIMP(ir);
nkeynes@736
   151
    }
nkeynes@7
   152
}
nkeynes@7
   153
nkeynes@13
   154
static int arm_disasm_address_operand( uint32_t ir, char *buf, int len,  int pc )
nkeynes@7
   155
{
nkeynes@7
   156
    char  shift[32];
nkeynes@7
   157
nkeynes@736
   158
    char sign = UFLAG(ir) ? '+' : '-';
nkeynes@736
   159
    /* I P U . W */
nkeynes@736
   160
    switch( (ir>>21)&0x19 ) {
nkeynes@736
   161
    case 0: /* Rn -= imm offset (post-indexed) [5.2.8 A5-28] */
nkeynes@736
   162
    case 1:
nkeynes@736
   163
        return snprintf( buf, len, "[R%d], R%d %c= #%04Xh", RN(ir), RN(ir), sign, IMM12(ir) );
nkeynes@736
   164
    case 8: /* Rn - imm offset  [5.2.2 A5-20] */
nkeynes@736
   165
        if( RN(ir) == 15 ) { /* PC relative - decode here */
nkeynes@736
   166
            uint32_t addr = pc + 8 + (UFLAG(ir) ? IMM12(ir) : -IMM12(ir));
nkeynes@736
   167
            return snprintf( buf, len, "[$%08Xh] <- #%08Xh", addr,
nkeynes@736
   168
                    arm_read_long( addr ) );
nkeynes@736
   169
        } else {
nkeynes@736
   170
            return snprintf( buf, len, "[R%d %c #%04Xh]", RN(ir), sign, IMM12(ir) );
nkeynes@736
   171
        }
nkeynes@736
   172
    case 9: /* Rn -= imm offset (pre-indexed)  [5.2.5 A5-24] */
nkeynes@736
   173
        return snprintf( buf, len, "[R%d %c= #%04Xh]", RN(ir), sign, IMM12(ir) );
nkeynes@736
   174
    case 16: /* Rn -= Rm (post-indexed)  [5.2.10 A5-32 ] */
nkeynes@736
   175
    case 17:
nkeynes@736
   176
        arm_disasm_address_index( ir, shift, sizeof(shift) );
nkeynes@736
   177
        return snprintf( buf, len, "[R%d], R%d %c= %s", RN(ir), RN(ir), sign, shift );
nkeynes@736
   178
    case 24: /* Rn - Rm  [5.2.4 A5-23] */
nkeynes@736
   179
        arm_disasm_address_index( ir, shift, sizeof(shift) );
nkeynes@736
   180
        return snprintf( buf, len, "[R%d %c %s]", RN(ir), sign, shift );
nkeynes@736
   181
    case 25: /* RN -= Rm (pre-indexed)  [5.2.7 A5-26] */
nkeynes@736
   182
        arm_disasm_address_index( ir, shift, sizeof(shift) );
nkeynes@736
   183
        return snprintf( buf, len, "[R%d %c= %s]", RN(ir), sign, shift );
nkeynes@736
   184
    default:
nkeynes@736
   185
        return UNIMP(ir); /* Unreachable */
nkeynes@736
   186
    }
nkeynes@7
   187
}
nkeynes@7
   188
nkeynes@11
   189
uint32_t arm_disasm_instruction( uint32_t pc, char *buf, int len, char *opcode )
nkeynes@7
   190
{
nkeynes@48
   191
    char operand[64];
nkeynes@11
   192
    uint32_t ir = arm_read_long(pc);
nkeynes@11
   193
    int i,j;
nkeynes@736
   194
nkeynes@11
   195
    sprintf( opcode, "%02X %02X %02X %02X", ir&0xFF, (ir>>8) & 0xFF,
nkeynes@736
   196
             (ir>>16)&0xFF, (ir>>24) );
nkeynes@11
   197
nkeynes@4
   198
    if( COND(ir) == 0x0F ) {
nkeynes@736
   199
        UNIMP(ir);
nkeynes@736
   200
        return pc+4;
nkeynes@4
   201
    }
nkeynes@4
   202
    char *cond = conditionNames[COND(ir)];
nkeynes@4
   203
nkeynes@736
   204
    switch( GRP(ir) ) {
nkeynes@736
   205
    case 0:
nkeynes@736
   206
        if( (ir & 0x0D900000) == 0x01000000 ) {
nkeynes@736
   207
            /* Instructions that aren't actual data processing */
nkeynes@736
   208
            switch( ir & 0x0FF000F0 ) {
nkeynes@736
   209
            case 0x01200010: /* BXcc */
nkeynes@736
   210
                snprintf(buf, len, "BX%s     R%d", cond, RM(ir));
nkeynes@736
   211
                break;
nkeynes@736
   212
            case 0x01000000: /* MRS Rd, CPSR */
nkeynes@736
   213
                snprintf(buf, len, "MRS%s    R%d, CPSR", cond, RD(ir));
nkeynes@736
   214
                break;
nkeynes@736
   215
            case 0x01400000: /* MRS Rd, SPSR */
nkeynes@736
   216
                snprintf(buf, len, "MRS%s    R%d, SPSR", cond, RD(ir));
nkeynes@736
   217
                break;
nkeynes@736
   218
            case 0x01200000: /* MSR CPSR, Rm */
nkeynes@736
   219
                snprintf(buf, len, "MSR%s    CPSR_%s, R%d", cond, FSXC(ir), RM(ir));
nkeynes@736
   220
                break;
nkeynes@736
   221
            case 0x01600000: /* MSR SPSR, Rm */
nkeynes@736
   222
                snprintf(buf, len, "MSR%s    SPSR_%s, R%d", cond, FSXC(ir), RM(ir));
nkeynes@736
   223
                break;
nkeynes@736
   224
            case 0x03200000: /* MSR CPSR, imm */
nkeynes@736
   225
                snprintf(buf, len, "MSR%s    CPSR_%s, #%08X", cond, FSXC(ir), ROTIMM12(ir));
nkeynes@736
   226
                break;
nkeynes@736
   227
            case 0x03600000: /* MSR SPSR, imm */
nkeynes@736
   228
                snprintf(buf, len, "MSR%s    SPSR_%s, #%08X", cond, FSXC(ir), ROTIMM12(ir));
nkeynes@736
   229
                break;
nkeynes@736
   230
            default:
nkeynes@736
   231
                UNIMP();
nkeynes@736
   232
            }
nkeynes@736
   233
        } else if( (ir & 0x0E000090) == 0x00000090 ) {
nkeynes@736
   234
            /* Neither are these */
nkeynes@736
   235
            switch( (ir>>5)&0x03 ) {
nkeynes@736
   236
            case 0:
nkeynes@736
   237
                /* Arithmetic extension area */
nkeynes@736
   238
                switch(OPCODE(ir)) {
nkeynes@736
   239
                case 0: /* MUL */
nkeynes@736
   240
                    snprintf(buf,len, "MUL%s    R%d, R%d, R%d", cond, RN(ir), RM(ir), RS(ir) );
nkeynes@736
   241
                    break;
nkeynes@736
   242
                case 1: /* MULS */
nkeynes@736
   243
                    break;
nkeynes@736
   244
                case 2: /* MLA */
nkeynes@736
   245
                    snprintf(buf,len, "MLA%s    R%d, R%d, R%d, R%d", cond, RN(ir), RM(ir), RS(ir), RD(ir) );
nkeynes@736
   246
                    break;
nkeynes@736
   247
                case 3: /* MLAS */
nkeynes@736
   248
                    break;
nkeynes@736
   249
                case 8: /* UMULL */
nkeynes@736
   250
                    snprintf(buf,len, "UMULL%s  R%d, R%d, R%d, R%d", cond, RD(ir), RN(ir), RM(ir), RS(ir) );
nkeynes@736
   251
                    break;
nkeynes@736
   252
                case 9: /* UMULLS */
nkeynes@736
   253
                    break;
nkeynes@736
   254
                case 10: /* UMLAL */
nkeynes@736
   255
                    snprintf(buf,len, "UMLAL%s  R%d, R%d, R%d, R%d", cond, RD(ir), RN(ir), RM(ir), RS(ir) );
nkeynes@736
   256
                    break;
nkeynes@736
   257
                case 11: /* UMLALS */
nkeynes@736
   258
                    break;
nkeynes@736
   259
                case 12: /* SMULL */
nkeynes@736
   260
                    snprintf(buf,len, "SMULL%s  R%d, R%d, R%d, R%d", cond, RD(ir), RN(ir), RM(ir), RS(ir) );
nkeynes@736
   261
                    break;
nkeynes@736
   262
                case 13: /* SMULLS */
nkeynes@736
   263
                    break;
nkeynes@736
   264
                case 14: /* SMLAL */
nkeynes@736
   265
                    snprintf(buf,len, "SMLAL%s  R%d, R%d, R%d, R%d", cond, RD(ir), RN(ir), RM(ir), RS(ir) );
nkeynes@736
   266
                    break;
nkeynes@736
   267
                case 15: /* SMLALS */
nkeynes@4
   268
nkeynes@736
   269
                    break;
nkeynes@736
   270
                case 16: /* SWP */
nkeynes@736
   271
                    snprintf(buf,len, "SWP%s    R%d, R%d, [R%d]", cond, RD(ir), RN(ir), RM(ir) );
nkeynes@736
   272
                    break;
nkeynes@736
   273
                case 20: /* SWPB */
nkeynes@736
   274
                    snprintf(buf,len, "SWPB%s   R%d, R%d, [R%d]", cond, RD(ir), RN(ir), RM(ir) );
nkeynes@736
   275
                    break;
nkeynes@736
   276
                default:
nkeynes@736
   277
                    UNIMP(ir);
nkeynes@736
   278
                }
nkeynes@736
   279
                break;
nkeynes@736
   280
                case 1:
nkeynes@736
   281
                    if( LFLAG(ir) ) {
nkeynes@736
   282
                        /* LDRH */
nkeynes@736
   283
                    } else {
nkeynes@736
   284
                        /* STRH */
nkeynes@736
   285
                    }
nkeynes@736
   286
                    UNIMP(ir);
nkeynes@736
   287
                    break;
nkeynes@736
   288
                case 2:
nkeynes@736
   289
                    if( LFLAG(ir) ) {
nkeynes@736
   290
                        /* LDRSB */
nkeynes@736
   291
                    } else {
nkeynes@736
   292
                    }
nkeynes@736
   293
                    UNIMP(ir);
nkeynes@736
   294
                    break;
nkeynes@736
   295
                case 3:
nkeynes@736
   296
                    if( LFLAG(ir) ) {
nkeynes@736
   297
                        /* LDRSH */
nkeynes@736
   298
                    } else {
nkeynes@736
   299
                    }
nkeynes@736
   300
                    UNIMP(ir);
nkeynes@736
   301
                    break;
nkeynes@736
   302
            }
nkeynes@736
   303
        } else {
nkeynes@736
   304
            /* Data processing */
nkeynes@4
   305
nkeynes@736
   306
            switch(OPCODE(ir)) {
nkeynes@736
   307
            case 0: /* AND Rd, Rn, operand */
nkeynes@736
   308
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   309
                snprintf(buf, len, "AND%s    R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   310
                break;
nkeynes@736
   311
            case 1: /* ANDS Rd, Rn, operand */
nkeynes@736
   312
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   313
                snprintf(buf, len, "ANDS%s   R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   314
                break;
nkeynes@736
   315
            case 2: /* EOR Rd, Rn, operand */
nkeynes@736
   316
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   317
                snprintf(buf, len, "EOR%s    R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   318
                break;
nkeynes@736
   319
            case 3: /* EORS Rd, Rn, operand */
nkeynes@736
   320
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   321
                snprintf(buf, len, "EORS%s   R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   322
                break;
nkeynes@736
   323
            case 4: /* SUB Rd, Rn, operand */
nkeynes@736
   324
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   325
                snprintf(buf, len, "SUB%s    R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   326
                break;
nkeynes@736
   327
            case 5: /* SUBS Rd, Rn, operand */
nkeynes@736
   328
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   329
                snprintf(buf, len, "SUBS%s   R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   330
                break;
nkeynes@736
   331
            case 6: /* RSB Rd, Rn, operand */
nkeynes@736
   332
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   333
                snprintf(buf, len, "RSB%s    R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   334
                break;
nkeynes@736
   335
            case 7: /* RSBS Rd, Rn, operand */
nkeynes@736
   336
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   337
                snprintf(buf, len, "RSBS%s   R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   338
                break;
nkeynes@736
   339
            case 8: /* ADD Rd, Rn, operand */
nkeynes@736
   340
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   341
                snprintf(buf, len, "ADD%s    R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   342
                break;
nkeynes@736
   343
            case 9: /* ADDS Rd, Rn, operand */
nkeynes@736
   344
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   345
                snprintf(buf, len, "ADDS%s   R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   346
                break;
nkeynes@736
   347
            case 10: /* ADC Rd, Rn, operand */
nkeynes@736
   348
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   349
                snprintf(buf, len, "ADC%s    R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   350
                break;
nkeynes@736
   351
            case 11: /* ADCS Rd, Rn, operand */
nkeynes@736
   352
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   353
                snprintf(buf, len, "ADCS%s   R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   354
                break;
nkeynes@736
   355
            case 12: /* SBC Rd, Rn, operand */
nkeynes@736
   356
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   357
                snprintf(buf, len, "SBC%s    R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   358
                break;
nkeynes@736
   359
            case 13: /* SBCS Rd, Rn, operand */
nkeynes@736
   360
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   361
                snprintf(buf, len, "SBCS%s   R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   362
                break;
nkeynes@736
   363
            case 14: /* RSC Rd, Rn, operand */
nkeynes@736
   364
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   365
                snprintf(buf, len, "RSC%s    R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   366
                break;
nkeynes@736
   367
            case 15: /* RSCS Rd, Rn, operand */
nkeynes@736
   368
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   369
                snprintf(buf, len, "RSCS%s   R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   370
                break;
nkeynes@736
   371
            case 17: /* TST Rd, Rn, operand */
nkeynes@736
   372
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   373
                snprintf(buf, len, "TST%s    R%d, %s", cond, RN(ir), operand);
nkeynes@736
   374
                break;
nkeynes@736
   375
            case 19: /* TEQ Rd, Rn, operand */
nkeynes@736
   376
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   377
                snprintf(buf, len, "TEQ%s    R%d, %s", cond, RN(ir), operand);
nkeynes@736
   378
                break;
nkeynes@736
   379
            case 21: /* CMP Rd, Rn, operand */
nkeynes@736
   380
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   381
                snprintf(buf, len, "CMP%s    R%d, %s", cond, RN(ir), operand);
nkeynes@736
   382
                break;
nkeynes@736
   383
            case 23: /* CMN Rd, Rn, operand */
nkeynes@736
   384
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   385
                snprintf(buf, len, "CMN%s    R%d, %s", cond, RN(ir), operand);
nkeynes@736
   386
                break;
nkeynes@736
   387
            case 24: /* ORR Rd, Rn, operand */
nkeynes@736
   388
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   389
                snprintf(buf, len, "ORR%s    R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   390
                break;
nkeynes@736
   391
            case 25: /* ORRS Rd, Rn, operand */
nkeynes@736
   392
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   393
                snprintf(buf, len, "ORRS%s   R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   394
                break;
nkeynes@736
   395
            case 26: /* MOV Rd, operand */
nkeynes@736
   396
                if( ir == 0xE1A00000 ) {
nkeynes@736
   397
                    /* Not technically a different instruction,
nkeynes@736
   398
                     * but this one is commonly used as a NOP,
nkeynes@736
   399
                     * so... 
nkeynes@736
   400
                     */
nkeynes@736
   401
                    snprintf(buf, len, "NOP");
nkeynes@736
   402
                } else {
nkeynes@736
   403
                    arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   404
                    snprintf(buf, len, "MOV%s    R%d, %s", cond, RD(ir), operand);
nkeynes@736
   405
                }
nkeynes@736
   406
                break;
nkeynes@736
   407
            case 27: /* MOVS Rd, operand */
nkeynes@736
   408
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   409
                snprintf(buf, len, "MOVS%s   R%d, %s", cond, RD(ir), operand);
nkeynes@736
   410
                break;
nkeynes@736
   411
            case 28: /* BIC Rd, Rn, operand */
nkeynes@736
   412
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   413
                snprintf(buf, len, "BIC%s    R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   414
                break;
nkeynes@736
   415
            case 29: /* BICS Rd, Rn, operand */
nkeynes@736
   416
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   417
                snprintf(buf, len, "BICS%s   R%d, R%d, %s", cond, RD(ir), RN(ir), operand);
nkeynes@736
   418
                break;
nkeynes@736
   419
            case 30: /* MVN Rd, Rn, operand */
nkeynes@736
   420
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   421
                snprintf(buf, len, "MVN%s    R%d, %s", cond, RD(ir), operand);
nkeynes@736
   422
                break;
nkeynes@736
   423
            case 31: /* MVNS Rd, Rn, operand */
nkeynes@736
   424
                arm_disasm_shift_operand(ir, operand, sizeof(operand));
nkeynes@736
   425
                snprintf(buf, len, "MVNS%s   R%d, %s", cond, RD(ir), operand);
nkeynes@736
   426
                break;
nkeynes@736
   427
            default:
nkeynes@736
   428
                UNIMP(ir);
nkeynes@736
   429
            }
nkeynes@736
   430
        }
nkeynes@736
   431
        break;
nkeynes@736
   432
    case 1: /* Load/store */
nkeynes@736
   433
        arm_disasm_address_operand( ir, operand, sizeof(operand), pc );
nkeynes@736
   434
        switch( (ir>>20)&0x17 ) {
nkeynes@736
   435
        case 0:
nkeynes@736
   436
        case 16:
nkeynes@736
   437
        case 18:
nkeynes@736
   438
            snprintf(buf, len, "STR%s    R%d, %s", cond, RD(ir), operand );
nkeynes@736
   439
            break;
nkeynes@736
   440
        case 1:
nkeynes@736
   441
        case 17:
nkeynes@736
   442
        case 19:
nkeynes@736
   443
            snprintf(buf, len, "LDR%s    R%d, %s", cond, RD(ir), operand );
nkeynes@736
   444
            break;
nkeynes@736
   445
        case 2:
nkeynes@736
   446
            snprintf(buf, len, "STRT%s   R%d, %s", cond, RD(ir), operand );
nkeynes@736
   447
            break;
nkeynes@736
   448
        case 3:
nkeynes@736
   449
            snprintf(buf, len, "LDRT%s   R%d, %s", cond, RD(ir), operand );
nkeynes@736
   450
            break;
nkeynes@736
   451
        case 4:
nkeynes@736
   452
        case 20:
nkeynes@736
   453
        case 22:
nkeynes@736
   454
            snprintf(buf, len, "STRB%s   R%d, %s", cond, RD(ir), operand );
nkeynes@736
   455
            break;
nkeynes@736
   456
        case 5:
nkeynes@736
   457
        case 21:
nkeynes@736
   458
        case 23:
nkeynes@736
   459
            snprintf(buf, len, "LDRB%s   R%d, %s", cond, RD(ir), operand );
nkeynes@736
   460
            break;
nkeynes@736
   461
        case 6:
nkeynes@736
   462
            snprintf(buf, len, "STRBT%s  R%d, %s", cond, RD(ir), operand );
nkeynes@736
   463
            break;
nkeynes@736
   464
        case 7: 
nkeynes@736
   465
            snprintf(buf, len, "LDRBT%s  R%d, %s", cond, RD(ir), operand );
nkeynes@736
   466
            break;
nkeynes@736
   467
        }
nkeynes@736
   468
        break;
nkeynes@736
   469
        case 2: 
nkeynes@736
   470
            if( (ir & 0x02000000) == 0x02000000 ) {
nkeynes@736
   471
                int32_t offset = SIGNEXT24(ir&0x00FFFFFF) << 2;
nkeynes@736
   472
                if( (ir & 0x01000000) == 0x01000000 ) { 
nkeynes@736
   473
                    snprintf( buf, len, "BL%s     $%08Xh", cond, pc + offset + 8 );
nkeynes@736
   474
                } else {
nkeynes@736
   475
                    snprintf( buf, len, "B%s      $%08Xh", cond, pc + offset + 8 );
nkeynes@736
   476
                }
nkeynes@736
   477
            } else {
nkeynes@736
   478
                /* Load/store multiple */
nkeynes@736
   479
                j = snprintf( buf, len, LFLAG(ir) ? "LDM%s%s  R%d%c,":"STM%s%s  R%d%c,", 
nkeynes@736
   480
                        ldmModes[(ir>>23)&0x03], cond, RN(ir), WFLAG(ir)?'!':' ' );
nkeynes@736
   481
                buf += j;
nkeynes@736
   482
                len -= j;
nkeynes@736
   483
                for( i = 0; i<16 && len > 2; i++ ) {
nkeynes@736
   484
                    if( ir & (1<<i) ) {
nkeynes@736
   485
                        j = snprintf( buf, len, "R%d", i );
nkeynes@736
   486
                        buf+=j;
nkeynes@736
   487
                        len-=j;
nkeynes@736
   488
                    }
nkeynes@736
   489
                }
nkeynes@736
   490
                if( BFLAG(ir) && len > 0 ) {
nkeynes@736
   491
                    buf[0] = '^';
nkeynes@736
   492
                    buf[1] = '\0';
nkeynes@736
   493
                }
nkeynes@736
   494
            }
nkeynes@736
   495
            break;
nkeynes@736
   496
        case 3: /* Copro */
nkeynes@736
   497
            if( (ir & 0x0F000000) == 0x0F000000 ) {
nkeynes@736
   498
                snprintf( buf, len, "SWI%s    #%08Xh", cond, SIGNEXT24(ir) );
nkeynes@736
   499
            } else {
nkeynes@736
   500
                UNIMP(ir);
nkeynes@736
   501
            }
nkeynes@736
   502
            break;
nkeynes@736
   503
    }
nkeynes@736
   504
nkeynes@736
   505
nkeynes@736
   506
nkeynes@736
   507
    return pc+4;
nkeynes@4
   508
}
nkeynes@11
   509
nkeynes@11
   510
nkeynes@11
   511
uint32_t armt_disasm_instruction( uint32_t pc, char *buf, int len, char *opcode )
nkeynes@11
   512
{
nkeynes@11
   513
    uint32_t ir = arm_read_word(pc);
nkeynes@11
   514
    sprintf( opcode, "%02X %02X", ir&0xFF, (ir>>8) );
nkeynes@11
   515
    UNIMP(ir);
nkeynes@11
   516
    return pc+2;
nkeynes@11
   517
}
.