📄 unasmarmdlg.cpp
字号:
( (char *) (&f) ) [2] = fourbytes[2];
( (char *) (&f) ) [3] = fourbytes[3];
sprintf (temp, "LDR R%d, 0x%08x ;%02x%02x%02x%02x(%g)",
Rd, tar_addr, 0xff & fourbytes[3],
0xff & fourbytes[2], 0xff & fourbytes[1],
0xff & fourbytes[0], f);
}
}
else
{
if (m_Radio1)
{
sprintf (temp, "LDR R%d, 0x%08x ;%02x%02x%02x%02x",
Rd, tar_addr, 0xff & fourbytes[0],
0xff & fourbytes[1], 0xff & fourbytes[2],
0xff & fourbytes[3]);
}
else
{
sprintf (temp, "LDR R%d, 0x%08x ;%02x%02x%02x%02x",
Rd, tar_addr, 0xff & fourbytes[3],
0xff & fourbytes[2], 0xff & fourbytes[1],
0xff & fourbytes[0]);
}
}
}
strcat (str, temp);
regNo = -1;
break;
case 7:
LB = (byte1 & 0x0c) >> 2;
Ro = ( (byte1 & 1) << 2) | ( (byte2 & 0xc0) >> 6);
Rd = byte2 & 7;
Rb = (byte2 & 0x38) >> 3;
memcpy (temp, &op_name3[LB << 2], 4);
temp[4] = '\0';
strcat (temp, " ");
sprintf (&temp[8], "R%d, [R%d, R%d]", Rd, Rb, Ro);
strcat (str, temp);
regNo = -1;
break;
case 8:
HS = (byte1 & 0x0c) >> 2;
Ro = ( (byte1 & 1) << 2) | ( (byte2 & 0xc0) >> 6);
Rd = byte2 & 7;
Rb = (byte2 & 0x38) >> 3;
memcpy (temp, &op_name4[HS << 2], 4);
temp[4] = '\0';
strcat (temp, " ");
sprintf (&temp[8], "R%d, [R%d, R%d]", Rd, Rb, Ro);
strcat (str, temp);
regNo = -1;
break;
case 9:
LB = (byte1 & 0x18) >> 3;
offset5 = ( (byte1 & 7) << 2) | ( (byte2 & 0xc0) >> 6);
Rd = byte2 & 7;
Rb = (byte2 & 0x38) >> 3;
memcpy (temp, &op_name5[LB << 2], 4);
temp[4] = '\0';
strcat (temp, " ");
if (LB < 2)
{ // WORD
sprintf (&temp[8], "R%d, [R%d, #0x%02x]", Rd, Rb, offset5 << 2);
}
else
{
sprintf (&temp[8], "R%d, [R%d, #0x%02x]", Rd, Rb, offset5);
}
strcat (str, temp);
regNo = -1;
break;
case 10:
offset5 = ( (byte1 & 7) << 2) | ( (byte2 & 0xc0) >> 6);
Rd = byte2 & 7;
Rb = (byte2 & 0x38) >> 3;
if (byte1 & 8)
strcpy (temp, "LDRH ");
else
strcpy (temp, "STRH ");
sprintf (&temp[8], "R%d, [R%d, #0x%02x]", Rd, Rb, offset5 << 1);
strcat (str, temp);
regNo = -1;
break;
case 11:
if (byte1 & 8) // LOAD
strcpy (temp, "LDR ");
else
strcpy (temp, "STR ");
Rd = byte1 & 7;
sprintf (&temp[8], "R%d, [R13, #0x%02x]", Rd, byte2 << 2);
strcat (str, temp);
regNo = -1;
break;
case 12:
Rd = byte1 & 7;
if (byte1 & 8)
sprintf (temp, "ADD R%d, SP, #0x%02x", Rd, byte2 << 2);
else
{
sprintf (temp, "ADR R%d, 0x%08x", Rd, ( (byte2 << 2) + addr + 4) & ~3);
}
strcat (str, temp);
regNo = -1;
break;
case 13:
if (byte2 & 0x80)
{
sprintf (temp, "SUB SP, #0x%02x", (byte2 & 0x7f) << 2);
}
else
{
sprintf (temp, "ADD SP, #0x%02x", (byte2 & 0x7f) << 2);
}
strcat (str, temp);
regNo = -1;
break;
case 14:
if (byte1 & 8)
strcpy (temp, "POP {");
else
strcpy (temp, "PUSH {");
LB = strlen (temp);
if (byte2)
{
offset5 = byte2;
for (op = 0; op < 8; op++)
{
if (offset5 & 1)
{
temp[LB++] = 'R';
temp[LB++] = op + '0';
temp[LB++] = ',';
}
offset5 >>= 1;
}
LB--; // Discard ','
}
if (byte1 & 1)
{
if (byte2)
temp[LB++] = ',';
if (byte1 & 8)
{ // POP {Rlist, PC}
temp[LB++] = 'P';
temp[LB++] = 'C';
CrLf = 1;
}
else
{ // PUSH {Rlist, LR}
temp[LB++] = 'L';
temp[LB++] = 'R';
}
}
temp[LB++] = '}';
temp[LB] = '\0';
strcat (str, temp);
regNo = -1;
break;
case 15:
if (byte1 & 8)
strcpy (temp, "LDMIA ");
else
strcpy (temp, "STMIA ");
Rb = byte1 & 7;
sprintf (&temp[8], "R%d!, {", Rb);
LB = strlen (temp);
if (byte2)
{
offset5 = byte2;
for (op = 0; op < 8; op++)
{
if (offset5 & 1)
{
temp[LB++] = 'R';
temp[LB++] = op + '0';
temp[LB++] = ',';
}
offset5 >>= 1;
}
LB--; // Discard ','
}
temp[LB++] = '}';
temp[LB] = '\0';
strcat (str, temp);
regNo = -1;
break;
case 16:
Cond = (byte1 & 0x0f);
if (byte2 & 0x80)
{
offset5 = byte2;
( (unsigned char *) &offset5) [1] = 0xff;
( (unsigned char *) &offset5) [2] = 0xff;
( (unsigned char *) &offset5) [3] = 0xff;
tar_addr = addr + 4 + (offset5 << 1);
}
else
tar_addr = (byte2 << 1) + addr + 4;
memcpy (temp, &cond_name[Cond << 2], 4);
sprintf (&temp[4], " 0x%08x", tar_addr);
strcat (str, temp);
regNo = -1;
break;
case 17:
sprintf (temp, "SWI 0x%02x", byte2);
strcat (str, temp);
regNo = -1;
break;
case 18:
offset5 = ( (byte1 & 0x7) << 8) | byte2;
if (offset5 & 0x400)
{
( (unsigned char *) &offset5) [1] |= 0xf8;
( (unsigned char *) &offset5) [2] = 0xff;
( (unsigned char *) &offset5) [3] = 0xff;
}
tar_addr = (offset5 << 1) + addr + 4;
sprintf (temp, "B 0x%08x", tar_addr);
strcat (str, temp);
regNo = -1;
break;
case 19:
strcpy (temp, "?????? ; Bad statement");
strcat (str, temp);
regNo = -1;
break;
}
strcat (str, "\n");
fwrite (str, 1, strlen (str), fd_tar);
if (CrLf)
fwrite ("\n", 1, 1, fd_tar);
return 0;
}
int CUnasmARMDlg::dis_arm_one (unsigned char bin_code1,
unsigned char bin_code2,
unsigned char bin_code3,
unsigned char bin_code4)
{
unsigned uch1, uch4;
int op_type; // 1-15
uch1 = bin_code1 & 0x0f; // 0000 1111
uch4 = bin_code4 & 0xf0; // 1111 0000
if (uch1 == 1)
{
if ( (bin_code2 == 0x2f) && (bin_code3 == 0xff) && (uch4 == 0x10) )
return 5;
else
{
if ( (uch4 == 0x90) && ( (bin_code3 & 15) == 0) )
return 4;
}
}
if ( (uch1 == 0) && (uch4 == 0x90) )
{
if (bin_code2 & 0x80)
return 3;
else
return 2;
}
if ( (uch1 == 0) || (uch1 == 1) )
{
if ( (uch4 & 0x90) == 0x90)
{
if ( (bin_code2 & 0x40) == 0x40)
return 7;
else
{
if ( (bin_code3 & 15) == 0)
return 6;
}
}
}
if (uch1 < 4)
{
if ( (uch1 == 1) && ( (bin_code2 & 0xbf) == 0x0f)
&& (bin_code4 == 0) && ( (bin_code3 & 0x0f) == 0) )
return 16;
if ( (uch1 == 1) && ( (bin_code2 & 0xb0) == 0x20)
&& (bin_code3 == 0xf0) && (uch4 == 0) )
return 17;
if ( ( (uch1 & 0x0d) == 1) && ( (bin_code2 & 0xb0) == 0x20)
&& ( (bin_code3 & 0xf0) == 0xf0) )
return 18;
else
return 1;
}
if (uch1 < 8)
{
if ( ( (uch4 & 0x10) == 0x10) && ( (uch1 & 6) == 6) )
return 9;
else
return 8;
}
if (uch1 == 15)
return 15;
if (uch1 == 14)
{
if ( (uch4 & 0x10) == 0x10)
return 14;
else
return 13;
}
op_type = (uch1 >> 1) + 6;
return op_type;
}
int CUnasmARMDlg::do_dis_arm (FILE * fd_src, FILE * fd_tar, long addr, long start,
int op_type, unsigned char byte1, unsigned char byte2, unsigned char byte3, unsigned char byte4)
{
char fourbytes[4], str[128];
char temp[128];
int loc, sft_type;
int Opcode, Rn, Rd, Rm, Rs, RdLo, RdHi, CP;
unsigned int ImmValue;
int offset;
long cur_loc;
int cond;
char *cond_name = {"EQNECSCCMIPLVSVCHILSGELTGTLE"};
/* 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 */
char *op_name1 = {"AND EOR SUB RSB ADD ADC SBC RSC TST TEQ CMP CMN ORR MOV BIC MVN "};
// For LDM/STM
int LPU;
char *op_name;
char *op_name2 = {"EDEAFDFAFAFDEAED"}; // Stack
char *op_name3 = {"DAIADBIBDAIADBIB"}; // Other
// For LDRH/...
int SH;
char *op_name4 = {"LDRH LDRSB LDRSH "};
char *Sft_name = {"lsl lsr asr ror "};
if (m_Hex)
{
sprintf (str, "%08x %02X%02X%02X%02X ", addr, byte1, byte2, byte3, byte4);
}
else
{
sprintf (str, "%08x ", addr);
}
cond = byte1 >> 4;
CrLf = 0;
switch (op_type)
{
case 1:
Opcode = ( (byte1 & 1) << 3) | (byte2 >> 5);
memcpy (temp, &op_name1[Opcode << 2], 4);
temp[4] = '\0';
strcat (temp, " ");
Rn = byte2 & 15;
Rd = byte3 >> 4;
if (byte1 & 2)
{ // Operand 2 is an imm value
ImmValue = ROR (byte4, byte3 & 15);
if ( (Opcode == 13) || (Opcode == 15) )
{
sprintf (&temp[8], "%s, #0x%-x",
RegisterName[Rd], ImmValue);
}
else
{
if ( (Opcode >= 8) && (Opcode <= 11) )
{
sprintf (&temp[8], "%s, #0x%-x",
RegisterName[Rn], ImmValue);
}
else
{
sprintf (&temp[8], "%s, %s, #0x%-x",
RegisterName[Rd], RegisterName[Rn], ImmValue);
}
}
}
else
{ // Operand 2 is a register
Rm = byte4 & 15;
if ( (Opcode >= 8) && (Opcode <= 11) )
{
sprintf (&temp[8], "%s, ", RegisterName[Rn]);
}
else
{
if ( (Opcode == 13) || (Opcode == 15) )
{
sprintf (&temp[8], "%s, ", RegisterName[Rd]);
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -