Skip to content

Commit

Permalink
i#3577 AMD opcodes: add support for AMD's monitorx and mwaitx opcodes (
Browse files Browse the repository at this point in the history
…#4012)

Adds support for AMD's monitorx and mwaitx opcodes.
Adds the opcodes, the decode table entries, the INSTR_CREATE macros, api.ir tests, and enables the corresponding disabled binutils tests.

Issue: #3577
  • Loading branch information
kmar authored and derekbruening committed Jan 13, 2020
1 parent a488718 commit af21cdc
Show file tree
Hide file tree
Showing 9 changed files with 1,216 additions and 1,177 deletions.
11 changes: 9 additions & 2 deletions core/arch/x86/decode_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1594,6 +1594,10 @@ const instr_info_t * const op_instr[] =

/* Intel PT extensions */
/* OP_ptwrite */ &prefix_extensions[188][1],

/* AMD monitor extensions */
/* OP_monitorx */ &rm_extensions[2][2],
/* OP_mwaitx */ &rm_extensions[2][3],
};


Expand Down Expand Up @@ -6547,7 +6551,8 @@ const instr_info_t rm_extensions[][8] = {
{INVALID, 0x0f0131, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
},
{ /* rm extension 1 */
{OP_monitor, 0xc80f0171, "monitor", xx, xx, eax, ecx, edx, mrm, x, END_LIST},
/* XXX i#4013: Treat address in xax as IR memref? */
{OP_monitor, 0xc80f0171, "monitor", xx, xx, axAX, ecx, edx, mrm, x, END_LIST},
{OP_mwait, 0xc90f0171, "mwait", xx, xx, eax, ecx, xx, mrm, x, END_LIST},
{INVALID, 0x0f0131, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0x0f0131, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
Expand All @@ -6559,7 +6564,9 @@ const instr_info_t rm_extensions[][8] = {
{ /* rm extension 2 */
{OP_swapgs, 0xf80f0177, "swapgs", xx, xx, xx, xx, xx, mrm|o64, x, END_LIST},
{OP_rdtscp, 0xf90f0177, "rdtscp", edx, eax, xx, xx, xx, mrm|xop, x, exop[10]},/*AMD-only*/
{INVALID, 0x0f0131, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
/* XXX i#4013: Treat address in xax as IR memref? */
{OP_monitorx, 0xfa0f0177, "monitorx", xx, xx, axAX, ecx, edx, mrm, x, END_LIST},/*AMD-only*/
{OP_mwaitx, 0xfb0f0177, "mwaitx", xx, xx, eax, ecx, xx, mrm, x, END_LIST},/*AMD-only*/
{INVALID, 0x0f0131, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0x0f0131, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
{INVALID, 0x0f0131, "(bad)", xx, xx, xx, xx, xx, no, x, NA},
Expand Down
8 changes: 7 additions & 1 deletion core/arch/x86/instr_create.h
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,9 @@
#define INSTR_CREATE_mwait(dc) \
instr_create_0dst_2src((dc), OP_mwait, opnd_create_reg(DR_REG_EAX), \
opnd_create_reg(DR_REG_ECX))
#define INSTR_CREATE_mwaitx(dc) \
instr_create_0dst_2src((dc), OP_mwaitx, opnd_create_reg(DR_REG_EAX), \
opnd_create_reg(DR_REG_ECX))
#define INSTR_CREATE_invlpga(dc) \
instr_create_0dst_2src((dc), OP_invlpga, opnd_create_reg(DR_REG_XAX), \
opnd_create_reg(DR_REG_ECX))
Expand All @@ -921,7 +924,10 @@
instr_create_0dst_3src((dc), OP_wrmsr, opnd_create_reg(DR_REG_EDX), \
opnd_create_reg(DR_REG_EAX), opnd_create_reg(DR_REG_ECX))
#define INSTR_CREATE_monitor(dc) \
instr_create_0dst_3src((dc), OP_monitor, opnd_create_reg(DR_REG_EAX), \
instr_create_0dst_3src((dc), OP_monitor, opnd_create_reg(DR_REG_XAX), \
opnd_create_reg(DR_REG_ECX), opnd_create_reg(DR_REG_EDX))
#define INSTR_CREATE_monitorx(dc) \
instr_create_0dst_3src((dc), OP_monitorx, opnd_create_reg(DR_REG_XAX), \
opnd_create_reg(DR_REG_ECX), opnd_create_reg(DR_REG_EDX))
#define INSTR_CREATE_xsetbv(dc) \
instr_create_0dst_3src((dc), OP_xsetbv, opnd_create_reg(DR_REG_ECX), \
Expand Down
4 changes: 4 additions & 0 deletions core/arch/x86/opcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,10 @@ enum {
/* Intel PT extensions */
/* 1417 */ OP_ptwrite, /**< IA-32/AMD64 PT OP_ptwrite opcode. */

/* AMD monitor extensions */
/* 1418 */ OP_monitorx, /**< AMD64 monitorx opcode. */
/* 1419 */ OP_mwaitx, /**< AMD64 mwaitx opcode. */

OP_AFTER_LAST,
OP_FIRST = OP_add, /**< First real opcode. */
OP_LAST = OP_AFTER_LAST - 1, /**< Last real opcode. */
Expand Down
2 changes: 2 additions & 0 deletions suite/tests/api/ir_x86_0args.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ OPCODE(fxam, fxam, fxam, 0)
OPCODE(sahf, sahf, sahf, 0)
OPCODE(mwait, mwait, mwait, 0)
OPCODE(monitor, monitor, monitor, 0)
OPCODE(mwaitx, mwaitx, mwaitx, 0)
OPCODE(monitorx, monitorx, monitorx, 0)
OPCODE(fucompp, fucompp, fucompp, 0)
OPCODE(fcompp, fcompp, fcompp, 0)
OPCODE(lahf, lahf, lahf, 0)
Expand Down
10 changes: 10 additions & 0 deletions suite/tests/runcmp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,15 @@ if (NOT "${cmd_out}" STREQUAL "${str}")
file(WRITE "${tmp}" "${cmd_out}")
set(tmp2 "${cmp}-expect")
file(WRITE "${tmp2}" "${str}")

set(diffcmd "diff")
execute_process(COMMAND ${diffcmd} ${tmp} ${tmp2}
RESULT_VARIABLE dcmd_result
ERROR_VARIABLE dcmd_err
OUTPUT_VARIABLE dcmd_out)

message(STATUS "diff: ${dcmd_out}")

message(FATAL_ERROR "output in ${tmp} failed to match expected output in ${tmp2}")

endif ()
Loading

0 comments on commit af21cdc

Please sign in to comment.