mirror of
https://github.com/joncampbell123/dosbox-x.git
synced 2025-05-09 03:41:10 +08:00
Debugger disassembler: Add support for mandatory prefixes and SSE instructions
This commit is contained in:
parent
e83fcd6363
commit
7480a1bf4b
@ -69,6 +69,8 @@ Any comments/updates/bug reports to:
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include "paging.h"
|
||||
#include "logging.h"
|
||||
#include "cpu.h"
|
||||
|
||||
typedef uint8_t UINT8;
|
||||
typedef uint16_t UINT16;
|
||||
@ -103,6 +105,8 @@ INLINE UINT32 le_uint32(const void* ptr) {
|
||||
static UINT8 must_do_size; /* used with size of operand */
|
||||
static int wordop; /* dealing with word or byte operand */
|
||||
|
||||
static uint8_t last_c = 0;
|
||||
|
||||
static uint32_t instruction_offset;
|
||||
//static UINT16 instruction_segment;
|
||||
|
||||
@ -110,6 +114,7 @@ static char* ubufs; /* start of buffer */
|
||||
static char* ubufp; /* last position of buffer */
|
||||
static int invalid_opcode = 0;
|
||||
static int first_space = 1;
|
||||
static uint8_t last_prefix = MP_NONE;
|
||||
|
||||
static int prefix; /* segment override prefix byte */
|
||||
static int modrmv; /* flag for getting modrm byte */
|
||||
@ -295,7 +300,7 @@ static char const *second[] = {
|
||||
"cmovs %Gv,%Ev", "cmovns %Gv,%Ev", "cmovp %Gv,%Ev", "cmovnp %Gv,%Ev",
|
||||
"cmovl %Gv,%Ev", "cmovge %Gv,%Ev", "cmovle %Gv,%Ev", "cmovg %Gv,%Ev",
|
||||
/* 5 */
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, "%x0", 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
/* 6 */
|
||||
"punpcklbw %GM,%EM","punpcklwd %GM,%EM","punpckldq %GM,%EM","packsswb %GM,%EM",
|
||||
@ -349,6 +354,93 @@ static char const *second[] = {
|
||||
"paddb %GM,%EM", "paddw %GM,%EM", "paddd %GM,%EM", 0
|
||||
};
|
||||
|
||||
static char const *mpgroups[][256][4] = { /* mandatory prefix groups SSE instructions, then within NP, 66, F2, F3 */
|
||||
/* group 0 */
|
||||
{
|
||||
/* 0x00 */ { 0,0,0,0 }, /* 0x01 */ { 0,0,0,0 }, /* 0x02 */ { 0,0,0,0 }, /* 0x03 */ { 0,0,0,0 },
|
||||
/* 0x04 */ { 0,0,0,0 }, /* 0x05 */ { 0,0,0,0 }, /* 0x06 */ { 0,0,0,0 }, /* 0x07 */ { 0,0,0,0 },
|
||||
/* 0x08 */ { 0,0,0,0 }, /* 0x09 */ { 0,0,0,0 }, /* 0x0A */ { 0,0,0,0 }, /* 0x0B */ { 0,0,0,0 },
|
||||
/* 0x0C */ { 0,0,0,0 }, /* 0x0D */ { 0,0,0,0 }, /* 0x0E */ { 0,0,0,0 }, /* 0x0F */ { 0,0,0,0 },
|
||||
|
||||
/* 0x10 */ { 0,0,0,0 }, /* 0x11 */ { 0,0,0,0 }, /* 0x12 */ { 0,0,0,0 }, /* 0x13 */ { 0,0,0,0 },
|
||||
/* 0x14 */ { 0,0,0,0 }, /* 0x15 */ { 0,0,0,0 }, /* 0x16 */ { 0,0,0,0 }, /* 0x17 */ { 0,0,0,0 },
|
||||
/* 0x18 */ { 0,0,0,0 }, /* 0x19 */ { 0,0,0,0 }, /* 0x1A */ { 0,0,0,0 }, /* 0x1B */ { 0,0,0,0 },
|
||||
/* 0x1C */ { 0,0,0,0 }, /* 0x1D */ { 0,0,0,0 }, /* 0x1E */ { 0,0,0,0 }, /* 0x1F */ { 0,0,0,0 },
|
||||
|
||||
/* 0x20 */ { 0,0,0,0 }, /* 0x21 */ { 0,0,0,0 }, /* 0x22 */ { 0,0,0,0 }, /* 0x23 */ { 0,0,0,0 },
|
||||
/* 0x24 */ { 0,0,0,0 }, /* 0x25 */ { 0,0,0,0 }, /* 0x26 */ { 0,0,0,0 }, /* 0x27 */ { 0,0,0,0 },
|
||||
/* 0x28 */ { 0,0,0,0 }, /* 0x29 */ { 0,0,0,0 }, /* 0x2A */ { 0,0,0,0 }, /* 0x2B */ { 0,0,0,0 },
|
||||
/* 0x2C */ { 0,0,0,0 }, /* 0x2D */ { 0,0,0,0 }, /* 0x2E */ { 0,0,0,0 }, /* 0x2F */ { 0,0,0,0 },
|
||||
|
||||
/* 0x30 */ { 0,0,0,0 }, /* 0x31 */ { 0,0,0,0 }, /* 0x32 */ { 0,0,0,0 }, /* 0x33 */ { 0,0,0,0 },
|
||||
/* 0x34 */ { 0,0,0,0 }, /* 0x35 */ { 0,0,0,0 }, /* 0x36 */ { 0,0,0,0 }, /* 0x37 */ { 0,0,0,0 },
|
||||
/* 0x38 */ { 0,0,0,0 }, /* 0x39 */ { 0,0,0,0 }, /* 0x3A */ { 0,0,0,0 }, /* 0x3B */ { 0,0,0,0 },
|
||||
/* 0x3C */ { 0,0,0,0 }, /* 0x3D */ { 0,0,0,0 }, /* 0x3E */ { 0,0,0,0 }, /* 0x3F */ { 0,0,0,0 },
|
||||
|
||||
/* 0x40 */ { 0,0,0,0 }, /* 0x41 */ { 0,0,0,0 }, /* 0x42 */ { 0,0,0,0 }, /* 0x43 */ { 0,0,0,0 },
|
||||
/* 0x44 */ { 0,0,0,0 }, /* 0x45 */ { 0,0,0,0 }, /* 0x46 */ { 0,0,0,0 }, /* 0x47 */ { 0,0,0,0 },
|
||||
/* 0x48 */ { 0,0,0,0 }, /* 0x49 */ { 0,0,0,0 }, /* 0x4A */ { 0,0,0,0 }, /* 0x4B */ { 0,0,0,0 },
|
||||
/* 0x4C */ { 0,0,0,0 }, /* 0x4D */ { 0,0,0,0 }, /* 0x4E */ { 0,0,0,0 }, /* 0x4F */ { 0,0,0,0 },
|
||||
|
||||
/* 0x50 */ { 0,0,0,0 },
|
||||
/* 0x51 */ { "sqrtps %GX,%EX", "sqrtpd %GX,%EX", "sqrtsd %GX,%EX", "sqrtss %GX,%EX" },
|
||||
/* 0x52 */ { 0,0,0,0 }, /* 0x53 */ { 0,0,0,0 },
|
||||
/* 0x54 */ { 0,0,0,0 }, /* 0x55 */ { 0,0,0,0 }, /* 0x56 */ { 0,0,0,0 }, /* 0x57 */ { 0,0,0,0 },
|
||||
/* 0x58 */ { 0,0,0,0 }, /* 0x59 */ { 0,0,0,0 }, /* 0x5A */ { 0,0,0,0 }, /* 0x5B */ { 0,0,0,0 },
|
||||
/* 0x5C */ { 0,0,0,0 }, /* 0x5D */ { 0,0,0,0 }, /* 0x5E */ { 0,0,0,0 }, /* 0x5F */ { 0,0,0,0 },
|
||||
|
||||
/* 0x60 */ { 0,0,0,0 }, /* 0x61 */ { 0,0,0,0 }, /* 0x62 */ { 0,0,0,0 }, /* 0x63 */ { 0,0,0,0 },
|
||||
/* 0x64 */ { 0,0,0,0 }, /* 0x65 */ { 0,0,0,0 }, /* 0x66 */ { 0,0,0,0 }, /* 0x67 */ { 0,0,0,0 },
|
||||
/* 0x68 */ { 0,0,0,0 }, /* 0x69 */ { 0,0,0,0 }, /* 0x6A */ { 0,0,0,0 }, /* 0x6B */ { 0,0,0,0 },
|
||||
/* 0x6C */ { 0,0,0,0 }, /* 0x6D */ { 0,0,0,0 }, /* 0x6E */ { 0,0,0,0 }, /* 0x6F */ { 0,0,0,0 },
|
||||
|
||||
/* 0x70 */ { 0,0,0,0 }, /* 0x71 */ { 0,0,0,0 }, /* 0x72 */ { 0,0,0,0 }, /* 0x73 */ { 0,0,0,0 },
|
||||
/* 0x74 */ { 0,0,0,0 }, /* 0x75 */ { 0,0,0,0 }, /* 0x76 */ { 0,0,0,0 }, /* 0x77 */ { 0,0,0,0 },
|
||||
/* 0x78 */ { 0,0,0,0 }, /* 0x79 */ { 0,0,0,0 }, /* 0x7A */ { 0,0,0,0 }, /* 0x7B */ { 0,0,0,0 },
|
||||
/* 0x7C */ { 0,0,0,0 }, /* 0x7D */ { 0,0,0,0 }, /* 0x7E */ { 0,0,0,0 }, /* 0x7F */ { 0,0,0,0 },
|
||||
|
||||
/* 0x80 */ { 0,0,0,0 }, /* 0x81 */ { 0,0,0,0 }, /* 0x82 */ { 0,0,0,0 }, /* 0x83 */ { 0,0,0,0 },
|
||||
/* 0x84 */ { 0,0,0,0 }, /* 0x85 */ { 0,0,0,0 }, /* 0x86 */ { 0,0,0,0 }, /* 0x87 */ { 0,0,0,0 },
|
||||
/* 0x88 */ { 0,0,0,0 }, /* 0x89 */ { 0,0,0,0 }, /* 0x8A */ { 0,0,0,0 }, /* 0x8B */ { 0,0,0,0 },
|
||||
/* 0x8C */ { 0,0,0,0 }, /* 0x8D */ { 0,0,0,0 }, /* 0x8E */ { 0,0,0,0 }, /* 0x8F */ { 0,0,0,0 },
|
||||
|
||||
/* 0x90 */ { 0,0,0,0 }, /* 0x91 */ { 0,0,0,0 }, /* 0x92 */ { 0,0,0,0 }, /* 0x93 */ { 0,0,0,0 },
|
||||
/* 0x94 */ { 0,0,0,0 }, /* 0x95 */ { 0,0,0,0 }, /* 0x96 */ { 0,0,0,0 }, /* 0x97 */ { 0,0,0,0 },
|
||||
/* 0x98 */ { 0,0,0,0 }, /* 0x99 */ { 0,0,0,0 }, /* 0x9A */ { 0,0,0,0 }, /* 0x9B */ { 0,0,0,0 },
|
||||
/* 0x9C */ { 0,0,0,0 }, /* 0x9D */ { 0,0,0,0 }, /* 0x9E */ { 0,0,0,0 }, /* 0x9F */ { 0,0,0,0 },
|
||||
|
||||
/* 0xA0 */ { 0,0,0,0 }, /* 0xA1 */ { 0,0,0,0 }, /* 0xA2 */ { 0,0,0,0 }, /* 0xA3 */ { 0,0,0,0 },
|
||||
/* 0xA4 */ { 0,0,0,0 }, /* 0xA5 */ { 0,0,0,0 }, /* 0xA6 */ { 0,0,0,0 }, /* 0xA7 */ { 0,0,0,0 },
|
||||
/* 0xA8 */ { 0,0,0,0 }, /* 0xA9 */ { 0,0,0,0 }, /* 0xAA */ { 0,0,0,0 }, /* 0xAB */ { 0,0,0,0 },
|
||||
/* 0xAC */ { 0,0,0,0 }, /* 0xAD */ { 0,0,0,0 }, /* 0xAE */ { 0,0,0,0 }, /* 0xAF */ { 0,0,0,0 },
|
||||
|
||||
/* 0xB0 */ { 0,0,0,0 }, /* 0xB1 */ { 0,0,0,0 }, /* 0xB2 */ { 0,0,0,0 }, /* 0xB3 */ { 0,0,0,0 },
|
||||
/* 0xB4 */ { 0,0,0,0 }, /* 0xB5 */ { 0,0,0,0 }, /* 0xB6 */ { 0,0,0,0 }, /* 0xB7 */ { 0,0,0,0 },
|
||||
/* 0xB8 */ { 0,0,0,0 }, /* 0xB9 */ { 0,0,0,0 }, /* 0xBA */ { 0,0,0,0 }, /* 0xBB */ { 0,0,0,0 },
|
||||
/* 0xBC */ { 0,0,0,0 }, /* 0xBD */ { 0,0,0,0 }, /* 0xBE */ { 0,0,0,0 }, /* 0xBF */ { 0,0,0,0 },
|
||||
|
||||
/* 0xC0 */ { 0,0,0,0 }, /* 0xC1 */ { 0,0,0,0 }, /* 0xC2 */ { 0,0,0,0 }, /* 0xC3 */ { 0,0,0,0 },
|
||||
/* 0xC4 */ { 0,0,0,0 }, /* 0xC5 */ { 0,0,0,0 }, /* 0xC6 */ { 0,0,0,0 }, /* 0xC7 */ { 0,0,0,0 },
|
||||
/* 0xC8 */ { 0,0,0,0 }, /* 0xC9 */ { 0,0,0,0 }, /* 0xCA */ { 0,0,0,0 }, /* 0xCB */ { 0,0,0,0 },
|
||||
/* 0xCC */ { 0,0,0,0 }, /* 0xCD */ { 0,0,0,0 }, /* 0xCE */ { 0,0,0,0 }, /* 0xCF */ { 0,0,0,0 },
|
||||
|
||||
/* 0xD0 */ { 0,0,0,0 }, /* 0xD1 */ { 0,0,0,0 }, /* 0xD2 */ { 0,0,0,0 }, /* 0xD3 */ { 0,0,0,0 },
|
||||
/* 0xD4 */ { 0,0,0,0 }, /* 0xD5 */ { 0,0,0,0 }, /* 0xD6 */ { 0,0,0,0 }, /* 0xD7 */ { 0,0,0,0 },
|
||||
/* 0xD8 */ { 0,0,0,0 }, /* 0xD9 */ { 0,0,0,0 }, /* 0xDA */ { 0,0,0,0 }, /* 0xDB */ { 0,0,0,0 },
|
||||
/* 0xDC */ { 0,0,0,0 }, /* 0xDD */ { 0,0,0,0 }, /* 0xDE */ { 0,0,0,0 }, /* 0xDF */ { 0,0,0,0 },
|
||||
|
||||
/* 0xE0 */ { 0,0,0,0 }, /* 0xE1 */ { 0,0,0,0 }, /* 0xE2 */ { 0,0,0,0 }, /* 0xE3 */ { 0,0,0,0 },
|
||||
/* 0xE4 */ { 0,0,0,0 }, /* 0xE5 */ { 0,0,0,0 }, /* 0xE6 */ { 0,0,0,0 }, /* 0xE7 */ { 0,0,0,0 },
|
||||
/* 0xE8 */ { 0,0,0,0 }, /* 0xE9 */ { 0,0,0,0 }, /* 0xEA */ { 0,0,0,0 }, /* 0xEB */ { 0,0,0,0 },
|
||||
/* 0xEC */ { 0,0,0,0 }, /* 0xED */ { 0,0,0,0 }, /* 0xEE */ { 0,0,0,0 }, /* 0xEF */ { 0,0,0,0 },
|
||||
|
||||
/* 0xF0 */ { 0,0,0,0 }, /* 0xF1 */ { 0,0,0,0 }, /* 0xF2 */ { 0,0,0,0 }, /* 0xF3 */ { 0,0,0,0 },
|
||||
/* 0xF4 */ { 0,0,0,0 }, /* 0xF5 */ { 0,0,0,0 }, /* 0xF6 */ { 0,0,0,0 }, /* 0xF7 */ { 0,0,0,0 },
|
||||
/* 0xF8 */ { 0,0,0,0 }, /* 0xF9 */ { 0,0,0,0 }, /* 0xFA */ { 0,0,0,0 }, /* 0xFB */ { 0,0,0,0 },
|
||||
/* 0xFC */ { 0,0,0,0 }, /* 0xFD */ { 0,0,0,0 }, /* 0xFE */ { 0,0,0,0 }, /* 0xFF */ { 0,0,0,0 }
|
||||
}
|
||||
};
|
||||
|
||||
static char const *groups[][8] = { /* group 0 is group 3 for %Ev set */
|
||||
/* 0 */
|
||||
{ "add", "or", "adc", "sbb",
|
||||
@ -706,6 +798,10 @@ static void reg_name(int regnum, char size)
|
||||
uprintf("mm%d", regnum);
|
||||
return;
|
||||
}
|
||||
if (size == 'X') { /* SSE register */
|
||||
uprintf("xmm%d", regnum);
|
||||
return;
|
||||
}
|
||||
if ((((size == 'c') || (size == 'v')) && (opsize == 32)) || (size == 'd'))
|
||||
uputchar('e');
|
||||
if ((size=='q' || size == 'b' || size=='c') && !wordop) {
|
||||
@ -991,10 +1087,15 @@ static void percent(char type, char subtype)
|
||||
|
||||
case '2': /* old [pop cs]! now indexes */
|
||||
c = getbyte();
|
||||
last_c = c;
|
||||
wordop = c & 1;
|
||||
ua_str(second[c]); /* instructions in 386/486 */
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
ua_str(mpgroups[subtype-'0'][last_c][last_prefix]);
|
||||
break;
|
||||
|
||||
case 'g': /* modrm group `subtype' (0--7) */
|
||||
ua_str(groups[subtype-'0'][REG(modrm())]);
|
||||
break;
|
||||
@ -1035,6 +1136,11 @@ static void percent(char type, char subtype)
|
||||
break;
|
||||
|
||||
case 'p': /* prefix byte */
|
||||
switch (last_c) {
|
||||
case 0xF2: last_prefix = MP_F2; break;
|
||||
case 0xF3: last_prefix = MP_F3; break;
|
||||
default: last_prefix = MP_NONE; break;
|
||||
};
|
||||
switch (subtype) {
|
||||
case 'c':
|
||||
case 'd':
|
||||
@ -1044,7 +1150,8 @@ static void percent(char type, char subtype)
|
||||
case 's':
|
||||
prefix = subtype;
|
||||
c = getbyte();
|
||||
wordop = c & 1;
|
||||
last_c = c;
|
||||
wordop = c & 1;
|
||||
ua_str((*opmap1)[c]);
|
||||
break;
|
||||
case ':':
|
||||
@ -1053,6 +1160,7 @@ static void percent(char type, char subtype)
|
||||
break;
|
||||
case ' ':
|
||||
c = getbyte();
|
||||
last_c = c;
|
||||
wordop = c & 1;
|
||||
ua_str((*opmap1)[c]);
|
||||
break;
|
||||
@ -1060,10 +1168,15 @@ static void percent(char type, char subtype)
|
||||
break;
|
||||
|
||||
case 's': /* size override */
|
||||
switch (last_c) {
|
||||
case 0x66: last_prefix = MP_66; break;
|
||||
default: last_prefix = MP_NONE; break;
|
||||
};
|
||||
switch (subtype) {
|
||||
case 'a':
|
||||
addrsize = 48 - addrsize;
|
||||
c = getbyte();
|
||||
last_c = c;
|
||||
wordop = c & 1;
|
||||
ua_str((*opmap1)[c]);
|
||||
/* ua_str(opmap1[getbyte()]); */
|
||||
@ -1071,7 +1184,8 @@ static void percent(char type, char subtype)
|
||||
case 'o':
|
||||
opsize = 48 - opsize;
|
||||
c = getbyte();
|
||||
wordop = c & 1;
|
||||
last_c = c;
|
||||
wordop = c & 1;
|
||||
ua_str((*opmap1)[c]);
|
||||
/* ua_str(opmap1[getbyte()]); */
|
||||
break;
|
||||
@ -1136,9 +1250,11 @@ Bitu DasmI386(char* buffer, PhysPt pc, uint32_t cur_ip, bool bit32)
|
||||
if (bit32) opsize = addrsize = 32;
|
||||
else opsize = addrsize = 16;
|
||||
c = getbyte();
|
||||
last_c = c;
|
||||
wordop = c & 1;
|
||||
must_do_size = 1;
|
||||
invalid_opcode = 0;
|
||||
last_prefix = MP_NONE;
|
||||
opmap1=&op386map1;
|
||||
ua_str(op386map1[c]);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user