def fetch(span):
bits = len(span)
- one = "UINT32_C(1)"
+ one = "UINT64_C(1)"
for (dst, origin) in enumerate(span):
src = (32 - (origin + 1))
dst = (bits - (dst + 1))
- dst = f"UINT32_C({dst})"
- src = f"UINT32_C({src})"
+ dst = f"UINT64_C({dst})"
+ src = f"UINT64_C({src})"
yield f"/* {origin:<2} */ (((insn >> {src}) & {one}) << {dst}) |"
- yield f"UINT32_C(0)"
+ yield f"UINT64_C(0)"
class Mode(enum.Enum):
@contextlib.contextmanager
def dispatch_operands(self, node):
self.emit("static inline enum opid_state")
- self.emit("opid_disassemble_operand(uint32_t insn,")
+ self.emit("opid_disassemble_operand(uint64_t insn,")
with self:
with self:
self.emit("size_t category,")
@mdis.dispatcher.Hook(DynamicOperand)
@contextlib.contextmanager
def dispatch_operand(self, node, *, path, pathcls):
- def generic_handler(span, flags="UINT32_C(0)"):
+ def generic_handler(span, flags="UINT64_C(0)"):
yield f"operand->value = ("
with self:
yield from fetch(span)
self.emit("break;")
def nonzero_handler(span):
- yield f"operand->value = (UINT32_C(1) + ("
+ yield f"operand->value = (UINT64_C(1) + ("
with self:
yield from fetch(span)
yield f"));"
self.emit("break;")
def signed_handler(span, flags="OPID_OPERAND_SIGNED"):
- mask = f"(UINT32_C(1) << (UINT32_C({len(span)}) - 1))"
+ mask = f"(UINT64_C(1) << (UINT64_C({len(span)}) - 1))"
yield "operand->value = ("
with self:
yield "("
@mdis.dispatcher.Hook(insndb.Record.Opcode.Value, insndb.Record.Opcode.Mask)
@contextlib.contextmanager
def dispatch_opcode_parts(self, node, *, path, pathcls):
- self.emit(f"{pathcls(path)} = UINT32_C(0x{node:016x}),")
+ self.emit(f"{pathcls(path)} = UINT64_C(0x{node:016x}),")
with self: yield node
@mdis.dispatcher.Hook(insndb.Record.Opcode)
(void)fprintf(stderr, FORMAT, ##__VA_ARGS__); \
} while (0)
-#define OPID_OPERAND_SIGNED (UINT32_C(1) << UINT32_C(0))
-#define OPID_OPERAND_GPR (UINT32_C(1) << UINT32_C(1))
-#define OPID_OPERAND_FPR (UINT32_C(1) << UINT32_C(2))
-#define OPID_OPERAND_PAIR (UINT32_C(1) << UINT32_C(3))
-#define OPID_OPERAND_CR3 (UINT32_C(1) << UINT32_C(4))
-#define OPID_OPERAND_CR5 (UINT32_C(1) << UINT32_C(5))
-#define OPID_OPERAND_NONZERO (UINT32_C(1) << UINT32_C(6))
-#define OPID_OPERAND_ADDRESS (UINT32_C(1) << UINT32_C(7))
-
int
main(void) {
ssize_t size;
#include "opid.h"
static inline enum opid_state
-opid_disassemble_operand(uint32_t insn,
+opid_disassemble_operand(uint64_t insn,
size_t category,
struct opid_operand *operand);
#include "opid-dis-gen.c"
static inline enum opid_state
-opid_disassemble_operands(struct opid_ctx *ctx, uint32_t insn) {
+opid_disassemble_operands(struct opid_ctx *ctx, uint64_t insn) {
for (size_t id = 0; ((id != OPID_OPERANDS) && ctx->record->operands[id]); ++id) {
enum opid_state state;
}
enum opid_state
-opid_disassemble(struct opid_ctx *ctx, uint32_t insn) {
+opid_disassemble(struct opid_ctx *ctx, uint64_t insn) {
ctx->record = opid_lookup_insn(insn);
if (ctx->record == NULL)
#include "opid-opc-gen.c"
struct opid_record const *
-opid_lookup_insn(uint32_t insn) {
+opid_lookup_insn(uint64_t insn) {
uint32_t PO = (
- /* 0 */ (((insn >> UINT32_C(31)) & UINT32_C(1)) << UINT32_C(5)) |
- /* 1 */ (((insn >> UINT32_C(30)) & UINT32_C(1)) << UINT32_C(4)) |
- /* 2 */ (((insn >> UINT32_C(29)) & UINT32_C(1)) << UINT32_C(3)) |
- /* 3 */ (((insn >> UINT32_C(28)) & UINT32_C(1)) << UINT32_C(2)) |
- /* 4 */ (((insn >> UINT32_C(27)) & UINT32_C(1)) << UINT32_C(1)) |
- /* 5 */ (((insn >> UINT32_C(26)) & UINT32_C(1)) << UINT32_C(0)) |
- UINT32_C(0)
+ /* 0 */ (((insn >> UINT64_C(31)) & UINT64_C(1)) << UINT64_C(5)) |
+ /* 1 */ (((insn >> UINT64_C(30)) & UINT64_C(1)) << UINT64_C(4)) |
+ /* 2 */ (((insn >> UINT64_C(29)) & UINT64_C(1)) << UINT64_C(3)) |
+ /* 3 */ (((insn >> UINT64_C(28)) & UINT64_C(1)) << UINT64_C(2)) |
+ /* 4 */ (((insn >> UINT64_C(27)) & UINT64_C(1)) << UINT64_C(1)) |
+ /* 5 */ (((insn >> UINT64_C(26)) & UINT64_C(1)) << UINT64_C(0)) |
+ UINT64_C(0)
);
struct opid_record const *iter = &opid_record_table[opid_opcode_table[PO][0]];
struct opid_record const *tail = &opid_record_table[opid_opcode_table[PO][1]];
#define OPID_OPERANDS 8
struct opid_opcode {
- uint32_t value;
- uint32_t mask;
+ uint64_t value;
+ uint64_t mask;
};
struct opid_record {
};
struct opid_operand {
- uint32_t value;
- uint32_t flags;
+ uint64_t value;
+ uint64_t flags;
};
-#define OPID_OPERAND_SIGNED (UINT32_C(1) << UINT32_C(0))
-#define OPID_OPERAND_GPR (UINT32_C(1) << UINT32_C(1))
-#define OPID_OPERAND_FPR (UINT32_C(1) << UINT32_C(2))
-#define OPID_OPERAND_PAIR (UINT32_C(1) << UINT32_C(3))
-#define OPID_OPERAND_CR3 (UINT32_C(1) << UINT32_C(4))
-#define OPID_OPERAND_CR5 (UINT32_C(1) << UINT32_C(5))
-#define OPID_OPERAND_NONZERO (UINT32_C(1) << UINT32_C(6))
-#define OPID_OPERAND_ADDRESS (UINT32_C(1) << UINT32_C(7))
+#define OPID_OPERAND_SIGNED (UINT64_C(1) << UINT64_C(0))
+#define OPID_OPERAND_GPR (UINT64_C(1) << UINT64_C(1))
+#define OPID_OPERAND_FPR (UINT64_C(1) << UINT64_C(2))
+#define OPID_OPERAND_PAIR (UINT64_C(1) << UINT64_C(3))
+#define OPID_OPERAND_CR3 (UINT64_C(1) << UINT64_C(4))
+#define OPID_OPERAND_CR5 (UINT64_C(1) << UINT64_C(5))
+#define OPID_OPERAND_NONZERO (UINT64_C(1) << UINT64_C(6))
+#define OPID_OPERAND_ADDRESS (UINT64_C(1) << UINT64_C(7))
struct opid_ctx {
struct opid_record const *record;
operand = &(ctx)->operands[++id])
enum opid_state
-opid_disassemble(struct opid_ctx *ctx, uint32_t insn);
+opid_disassemble(struct opid_ctx *ctx, uint64_t insn);
struct opid_record const *
-opid_lookup_insn(uint32_t insn);
+opid_lookup_insn(uint64_t insn);