6502: illegal/undocumented instructions

This commit is contained in:
qnix 2015-09-23 02:58:35 -07:00 committed by condret
parent 3998132e7b
commit 55146f4ab1

View File

@ -1,125 +1,163 @@
/* radare - LGPL - Copyright 2015 - condret, Ricardo Quesada, qnix */
#include <r_asm.h>
#include <r_lib.h>
#include <string.h>
#include "../snes/snesdis.c"
static struct {
ut8 op;
char *name;
size_t len;
} ops[] = {
{0x00, "brk", 1},
{0x0b, "anc #0x%02x", 2},
{0x2b, "anc #0x%02x", 2},
{0x8b, "ane #0x%02x", 2},
{0x6b, "arr #0x%02x", 2},
{0x4b, "asr #0x%02x", 2},
{0xc7, "dcp 0x%02x", 2},
{0xd7, "dcp 0x%02x,x", 2},
{0xcf, "dcp 0x%04x", 3},
{0xdf, "dcp 0x%04x,x", 3},
{0xdb, "dcp 0x%04x,y", 3},
{0xc3, "dcp (0x%02x,x)", 2},
{0xd3, "dcp (0x%02x),y", 2},
{0xe7, "isb 0x%02x", 2},
{0xf7, "isb 0x%02x,x", 2},
{0xef, "isb 0x%04x", 3},
{0xff, "isb 0x%04x,x", 3},
{0xfb, "isb 0x%04x,y", 3},
{0xe3, "isb (0x%02x,x)", 2},
{0xf3, "isb (0x%02x),y", 2},
{0x02, "hlt", 1},
{0x12, "hlt", 1},
{0x22, "hlt", 1},
{0x32, "hlt", 1},
{0x42, "hlt", 1},
{0x52, "hlt", 1},
{0x62, "hlt", 1},
{0x72, "hlt", 1},
{0x92, "hlt", 1},
{0xb2, "hlt", 1},
{0xd2, "hlt", 1},
{0xf2, "hlt", 1},
{0xbb, "lae 0x%04x,y", 3},
{0xa7, "lax 0x%02x", 2},
{0xb7, "lax 0x%02x,y", 2},
{0xaf, "lax 0x%04x", 3},
{0xbf, "lax 0x%04x,y", 3},
{0xa3, "lax (0x%02x,x)", 2},
{0xb3, "lax (0x%02x),y", 2},
{0xab, "lxa #0x%02x", 2},
{0xea, "nop", 1},
{0x1a, "nop", 1},
{0x3a, "nop", 1},
{0x5a, "nop", 1},
{0x7a, "nop", 1},
{0xda, "nop", 1},
{0xfa, "nop", 1},
{0x80, "nop #0x%02x", 2},
{0x82, "nop #0x%02x", 2},
{0x89, "nop #0x%02x", 2},
{0xc2, "nop #0x%02x", 2},
{0xe2, "nop #0x%02x", 2},
{0x04, "nop 0x%02x", 2},
{0x44, "nop 0x%02x", 2},
{0x64, "nop 0x%02x", 2},
{0x14, "nop 0x%02x,x", 2},
{0x34, "nop 0x%02x,x", 2},
{0x54, "nop 0x%02x,x", 2},
{0x74, "nop 0x%02x,x", 2},
{0xd4, "nop 0x%02x,x", 2},
{0xf4, "nop 0x%02x,x", 2},
{0x0c, "nop 0x%04x", 3},
{0x1c, "nop 0x%04x,x", 3},
{0x3c, "nop 0x%04x,x", 3},
{0x5c, "nop 0x%04x,x", 3},
{0x7c, "nop 0x%04x,x", 3},
{0xdc, "nop 0x%04x,x", 3},
{0xfc, "nop 0x%04x,x", 3},
{0x27, "rla 0x%02x", 2},
{0x37, "rla 0x%02x,x", 2},
{0x2f, "rla 0x%04x", 3},
{0x3f, "rla 0x%04x,x", 3},
{0x3b, "rla 0x%04x,y", 3},
{0x23, "rla (0x%02x,x)", 2},
{0x33, "rla (0x%02x),y", 2},
{0x67, "rra 0x%02x", 2},
{0x77, "rra 0x%02x,x", 2},
{0x6f, "rra 0x%04x", 3},
{0x7f, "rra 0x%04x,x", 3},
{0x7b, "rra 0x%04x,y", 3},
{0x63, "rra (0x%02x,x)", 2},
{0x73, "rra (0x%02x),y", 2},
{0x87, "sax 0x%02x", 2},
{0x97, "sax 0x%02x,y", 2},
{0x8f, "sax 0x%04x", 3},
{0x83, "sax (0x%02x,x)", 2},
{0xe9, "sbc #0x%02x", 2},
{0xe5, "sbc 0x%02x", 2},
{0xf5, "sbc 0x%02x,x", 2},
{0xed, "sbc 0x%04x", 3},
{0xfd, "sbc 0x%04x,x", 3},
{0xf9, "sbc 0x%04x,y", 3},
{0xe1, "sbc (0x%02x,x)", 2},
{0xf1, "sbc (0x%02x),y", 2},
{0xeb, "sbc #0x%02x", 2},
//{0xef, "sbc 0x%06x", 4},
//{0xff, "sbc 0x%06x,x", 4},
//{0xf2, "sbc (0x%02x)", 2},
//{0xe7, "sbc [0x%02x]", 2},
//{0xf7, "sbc [0x%02x],y", 2},
//{0xe3, "sbc 0x%02x,s", 2},
//{0xf3, "sbc (0x%02x,s),y", 2},
{0xcb, "sbx 0x%02x", 2},
{0x93, "sha 0x%04x,x", 3},
{0x9f, "sha 0x%04x,y", 3},
{0x9b, "shs 0x%04x,y", 3},
{0x9e, "shx 0x%04x,y", 3},
{0x9c, "shy 0x%04x,x", 3},
{0x07, "slo 0x%02x", 2},
{0x17, "slo 0x%02x,x", 2},
{0x0f, "slo 0x%04x", 3},
{0x1f, "slo 0x%04x,x", 3},
{0x1b, "slo 0x%04x,y", 3},
{0x03, "slo (0x%02x,x)", 2},
{0x13, "slo (0x%02x),y", 2},
{0x47, "sre 0x%02x", 2},
{0x57, "sre 0x%02x,x", 2},
{0x4f, "sre 0x%04x", 3},
{0x5f, "sre 0x%04x,x", 3},
{0x5b, "sre 0x%04x,y", 3},
{0x43, "sre (0x%02x,x)", 2},
{0x53, "sre (0x%02x),y", 2},
{-1, NULL, 0}};
static int _6502Disass (RAsmOp *op, const ut8 *buf, ut64 len)
{
// override snes (65816) values
switch (*buf) {
case 0x00:
// takes one byte, but pc+2 instead of pc+1
// should we report it as one byte or two?
// defaulting to one, since most Commodore disassemblers/monitors do that
sprintf(op->buf_asm,"%s","brk");
return 1;
case 0x02:
case 0x03:
case 0x04:
case 0x07:
case 0x0b:
case 0x0c:
case 0x0f:
case 0x12:
case 0x13:
case 0x14:
case 0x17:
case 0x1a:
case 0x1b:
case 0x1c:
case 0x1f:
case 0x22:
case 0x23:
case 0x27:
case 0x2b:
case 0x2f:
case 0x32:
case 0x33:
case 0x34:
case 0x37:
case 0x3a:
case 0x3b:
case 0x3c:
case 0x3f:
case 0x42:
case 0x43:
case 0x44:
case 0x47:
case 0x4b:
case 0x4f:
case 0x52:
case 0x53:
case 0x54:
case 0x57:
case 0x5a:
case 0x5b:
case 0x5c:
case 0x5f:
case 0x62:
case 0x63:
case 0x64:
case 0x67:
case 0x6b:
case 0x6f:
case 0x72:
case 0x73:
case 0x74:
case 0x77:
case 0x7a:
case 0x7b:
case 0x7c:
case 0x7f:
case 0x80:
case 0x82:
case 0x83:
case 0x87:
case 0x89:
case 0x8b:
case 0x8f:
case 0x92:
case 0x93:
case 0x97:
case 0x9b:
case 0x9c:
case 0x9e:
case 0x9f:
case 0xa3:
case 0xa7:
case 0xab:
case 0xaf:
case 0xb2:
case 0xb3:
case 0xb7:
case 0xbb:
case 0xbf:
case 0xc2:
case 0xc3:
case 0xc7:
case 0xcb:
case 0xcf:
case 0xd2:
case 0xd3:
case 0xd4:
case 0xd7:
case 0xda:
case 0xdb:
case 0xdc:
case 0xdf:
case 0xe2:
case 0xe3:
case 0xe7:
case 0xeb:
case 0xef:
case 0xf2:
case 0xf3:
case 0xf4:
case 0xf7:
case 0xfa:
case 0xfb:
case 0xfc:
case 0xff:
strcpy (op->buf_asm, "illegal");
return 1;
int i;
for (i=0;ops[i].name != NULL;i++) {
if (ops[i].op == buf[0]) {
switch (ops[i].len) {
case 1:
sprintf (op->buf_asm, "%s", ops[i].name);
break;
case 2:
sprintf (op->buf_asm, ops[i].name, buf[1]);
break;
case 3:
sprintf (op->buf_asm, ops[i].name, buf[1]+0x100*buf[2]);
break;
case 4:
sprintf (op->buf_asm, ops[i].name,
buf[1]+0x100*buf[2]+0x10000*buf[3]);
break;
default:
goto beach;
}
return ops[i].len;
}
}
beach:
return snesDisass (op, buf, len);
}