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