de04e125d34ecf179e3c63563b0bb09ae32b1b49
12 #define error(FORMAT, ...) \
14 (void)fprintf(stderr, FORMAT, ##__VA_ARGS__); \
17 #define OPID_OPERAND_SIGNED (UINT32_C(1) << UINT32_C(0))
18 #define OPID_OPERAND_GPR (UINT32_C(1) << UINT32_C(1))
19 #define OPID_OPERAND_FPR (UINT32_C(1) << UINT32_C(2))
20 #define OPID_OPERAND_PAIR (UINT32_C(1) << UINT32_C(3))
21 #define OPID_OPERAND_CR3 (UINT32_C(1) << UINT32_C(4))
22 #define OPID_OPERAND_CR5 (UINT32_C(1) << UINT32_C(5))
23 #define OPID_OPERAND_NONZERO (UINT32_C(1) << UINT32_C(6))
24 #define OPID_OPERAND_ADDRESS (UINT32_C(1) << UINT32_C(7))
31 enum opid_state state
;
32 struct opid_operand
const *operand
;
35 size
= read(STDIN_FILENO
, &insn
, sizeof(insn
));
37 error("cannot fetch instruction: %s\n", strerror(errno
));
39 } else if (size
== sizeof(uint32_t)) {
40 state
= opid_disassemble(&ctx
, insn
);
41 if (state
!= OPID_SUCCESS
) {
42 error("invalid instruction: %08" PRIx32
"\n", insn
);
46 printf("%s [", ctx
.record
->name
);
47 opid_foreach_operand(&ctx
, operand
) {
48 printf("(%" PRIi32
" ",
49 (int32_t)operand
->value
);
50 if (operand
->flags
& OPID_OPERAND_SIGNED
)
52 if (operand
->flags
& OPID_OPERAND_GPR
)
54 if (operand
->flags
& OPID_OPERAND_FPR
)
56 if (operand
->flags
& OPID_OPERAND_PAIR
)
58 if (operand
->flags
& OPID_OPERAND_CR3
)
60 if (operand
->flags
& OPID_OPERAND_CR5
)
62 if (operand
->flags
& OPID_OPERAND_NONZERO
)
64 if (operand
->flags
& OPID_OPERAND_ADDRESS
)
69 } else if (size
!= 0) {
70 error("truncated instruction: %zu\n", (size_t)size
);