Fix analyzed opcode size for some z80 instructions (#9984)

This bug affected instructions starting with:
  * 0xED (extended instructions)
  * 0xDD (instructions operating on IX register)
  * 0xFD (instructions operating on IY register)
This commit is contained in:
RagingCactus 2018-04-29 22:19:55 +02:00 committed by radare
parent bfff81c199
commit dd4761f792
3 changed files with 155 additions and 154 deletions

View File

@ -12,21 +12,18 @@ static void z80_op_size(const ut8 *data, int *size, int *size_prefix) {
int type;
switch(data[0]) {
case 0xed:
// type = dd[data[1]].type;
type = ed[data[1]].type;
type = ed[z80_ed_branch_index_res(data[1])].type;
break;
case 0xcb:
type = Z80_OP16;
break;
case 0xdd:
type = dd[data[1]].type;
type = dd[z80_fddd_branch_index_res(data[1])].type;
break;
case 0xfd:
// type = dd[data[1]].type;
type = fd[data[1]].type;
type = fd[z80_fddd_branch_index_res(data[1])].type;
break;
default:
// type = dd[data[0]].type;
type = z80_op[data[0]].type;
break;
}

View File

@ -8,154 +8,6 @@
#include <string.h>
#include "z80_tab.h"
static ut8 z80_fddd_branch_index_res (ut8 hex)
{
switch (hex) {
case 0x9:
return 0x0;
case 0x19:
return 0x1;
case 0x21:
case 0x22:
case 0x23:
case 0x24:
case 0x25:
case 0x26:
return hex-0x1f;
case 0x29:
case 0x2a:
case 0x2b:
case 0x2c:
case 0x2d:
case 0x2e:
return hex-0x21;
case 0x34:
case 0x35:
case 0x36:
return hex-0x26;
case 0x39:
return 0x11;
case 0x44:
case 0x45:
case 0x46:
return hex-0x32;
case 0x4c:
case 0x4d:
case 0x4e:
return hex-0x37;
case 0x54: //0x18
case 0x55:
case 0x56:
return hex-0x3c;
case 0x5c:
case 0x5d:
case 0x5e: //0x1d
return hex-0x41;
case 0x60:
case 0x61:
case 0x62:
case 0x63:
case 0x64:
case 0x65:
case 0x66:
case 0x67:
case 0x68:
case 0x69:
case 0x6a:
case 0x6b:
case 0x6c:
case 0x6d:
case 0x6e:
case 0x6f:
case 0x70:
case 0x71:
case 0x72:
case 0x73:
case 0x74:
case 0x75:
return hex-0x42;
case 0x77:
return 0x34;
case 0x7c:
case 0x7d:
case 0x7e:
return hex-0x47;
case 0x84:
case 0x85:
case 0x86:
return hex-0x4c;
case 0x8c:
case 0x8d:
case 0x8e:
return hex-0x51;
case 0x94:
case 0x95:
case 0x96:
return hex-0x56;
case 0x9c:
case 0x9d:
case 0x9e:
return hex-0x5b;
case 0xa4:
case 0xa5:
case 0xa6:
return hex-0x60;
case 0xac:
case 0xad:
case 0xae:
return hex-0x65;
case 0xb4:
case 0xb5:
case 0xb6:
return hex-0x6a;
case 0xbc:
case 0xbd:
case 0xbe:
return hex-0x6f;
case 0xcb:
return 0x50;
case 0xe1:
return 0x51;
case 0xe3:
return 0x52;
case 0xe5:
return 0x53;
case 0xe9:
return 0x54;
case 0xf9:
return 0x55;
}
return 0x56;
}
static ut8 z80_ed_branch_index_res (ut8 hex) {
if (hex > 0x3f && 0x4c > hex)
return hex-0x40;
if (hex == 0x4d)
return 0xc;
if (hex > 0x4d && 0x54 > hex)
return hex-0x42;
if (hex > 0x55 && 0x5c > hex)
return hex-0x44;
if (hex > 0x5d && 0x63 > hex)
return hex-0x46;
if (hex > 0x66 && 0x6b > hex)
return hex-0x4a;
if (hex > 0x6e && 0x74 > hex)
return hex-0x4e;
if (hex > 0x77 && 0x7c > hex)
return hex-0x52;
if (hex > 0x9f && 0xa4 > hex)
return hex-0x76;
if (hex > 0xa7 && 0xac > hex)
return hex-0x7a;
if (hex > 0xaf && 0xb4 > hex)
return hex-0x7e;
if (hex > 0xb7 && 0xbc > hex)
return hex-0x82;
return 0x3b;
}
static ut8 z80_op_24_branch_index_res (ut8 hex) {
if (hex < 0x40)
return hex;

View File

@ -1,5 +1,8 @@
/* radare - LGPL - Copyright 2014-2016 - condret */
#ifndef Z80_TAB_H
#define Z80_TAB_H
#ifdef NULL
#undef NULL
#endif
@ -22,6 +25,153 @@ typedef struct{
void *op_moar;
} z80_opcode;
static ut8 z80_fddd_branch_index_res (ut8 hex) {
switch (hex) {
case 0x9:
return 0x0;
case 0x19:
return 0x1;
case 0x21:
case 0x22:
case 0x23:
case 0x24:
case 0x25:
case 0x26:
return hex-0x1f;
case 0x29:
case 0x2a:
case 0x2b:
case 0x2c:
case 0x2d:
case 0x2e:
return hex-0x21;
case 0x34:
case 0x35:
case 0x36:
return hex-0x26;
case 0x39:
return 0x11;
case 0x44:
case 0x45:
case 0x46:
return hex-0x32;
case 0x4c:
case 0x4d:
case 0x4e:
return hex-0x37;
case 0x54: //0x18
case 0x55:
case 0x56:
return hex-0x3c;
case 0x5c:
case 0x5d:
case 0x5e: //0x1d
return hex-0x41;
case 0x60:
case 0x61:
case 0x62:
case 0x63:
case 0x64:
case 0x65:
case 0x66:
case 0x67:
case 0x68:
case 0x69:
case 0x6a:
case 0x6b:
case 0x6c:
case 0x6d:
case 0x6e:
case 0x6f:
case 0x70:
case 0x71:
case 0x72:
case 0x73:
case 0x74:
case 0x75:
return hex-0x42;
case 0x77:
return 0x34;
case 0x7c:
case 0x7d:
case 0x7e:
return hex-0x47;
case 0x84:
case 0x85:
case 0x86:
return hex-0x4c;
case 0x8c:
case 0x8d:
case 0x8e:
return hex-0x51;
case 0x94:
case 0x95:
case 0x96:
return hex-0x56;
case 0x9c:
case 0x9d:
case 0x9e:
return hex-0x5b;
case 0xa4:
case 0xa5:
case 0xa6:
return hex-0x60;
case 0xac:
case 0xad:
case 0xae:
return hex-0x65;
case 0xb4:
case 0xb5:
case 0xb6:
return hex-0x6a;
case 0xbc:
case 0xbd:
case 0xbe:
return hex-0x6f;
case 0xcb:
return 0x50;
case 0xe1:
return 0x51;
case 0xe3:
return 0x52;
case 0xe5:
return 0x53;
case 0xe9:
return 0x54;
case 0xf9:
return 0x55;
}
return 0x56;
}
static ut8 z80_ed_branch_index_res (ut8 hex) {
if (hex > 0x3f && 0x4c > hex)
return hex-0x40;
if (hex == 0x4d)
return 0xc;
if (hex > 0x4d && 0x54 > hex)
return hex-0x42;
if (hex > 0x55 && 0x5c > hex)
return hex-0x44;
if (hex > 0x5d && 0x63 > hex)
return hex-0x46;
if (hex > 0x66 && 0x6b > hex)
return hex-0x4a;
if (hex > 0x6e && 0x74 > hex)
return hex-0x4e;
if (hex > 0x77 && 0x7c > hex)
return hex-0x52;
if (hex > 0x9f && 0xa4 > hex)
return hex-0x76;
if (hex > 0xa7 && 0xac > hex)
return hex-0x7a;
if (hex > 0xaf && 0xb4 > hex)
return hex-0x7e;
if (hex > 0xb7 && 0xbc > hex)
return hex-0x82;
return 0x3b;
}
static const char *cb[] = {
"rlc b",
"rlc c",
@ -1190,3 +1340,5 @@ static z80_opcode z80_op[] = {
{"cp 0x%02x", Z80_OP8^Z80_ARG8 ,NULL},
{"rst 0x38", Z80_OP8 ,NULL},
};
#endif