libopid: expand operands and opcodes
[openpower-isa.git] / src / libopid / opid.h
1 #pragma once
2
3 #include <stddef.h>
4 #include <stdint.h>
5
6 enum opid_state {
7 OPID_SUCCESS,
8 OPID_ERROR_LOOKUP,
9 OPID_ERROR_OPERAND_0,
10 OPID_ERROR_OPERAND_1,
11 OPID_ERROR_OPERAND_2,
12 OPID_ERROR_OPERAND_3,
13 OPID_ERROR_OPERAND_4,
14 OPID_ERROR_OPERAND_5,
15 OPID_ERROR_OPERAND_6,
16 OPID_ERROR_OPERAND_7,
17 };
18
19 #define OPID_OPERANDS 8
20
21 struct opid_opcode {
22 uint64_t value;
23 uint64_t mask;
24 };
25
26 struct opid_record {
27 struct opid_opcode opcode;
28 uint8_t operands[OPID_OPERANDS];
29 char name[16];
30 };
31
32 struct opid_operand {
33 uint64_t value;
34 uint64_t flags;
35 };
36
37 #define OPID_OPERAND_SIGNED (UINT64_C(1) << UINT64_C(0))
38 #define OPID_OPERAND_GPR (UINT64_C(1) << UINT64_C(1))
39 #define OPID_OPERAND_FPR (UINT64_C(1) << UINT64_C(2))
40 #define OPID_OPERAND_PAIR (UINT64_C(1) << UINT64_C(3))
41 #define OPID_OPERAND_CR3 (UINT64_C(1) << UINT64_C(4))
42 #define OPID_OPERAND_CR5 (UINT64_C(1) << UINT64_C(5))
43 #define OPID_OPERAND_NONZERO (UINT64_C(1) << UINT64_C(6))
44 #define OPID_OPERAND_ADDRESS (UINT64_C(1) << UINT64_C(7))
45
46 struct opid_ctx {
47 struct opid_record const *record;
48 struct opid_operand operands[OPID_OPERANDS];
49 };
50
51 #define opid_foreach_operand(ctx, operand) \
52 for (size_t id = 0; \
53 (((operand = &(ctx)->operands[id]), 1) && \
54 ((id != OPID_OPERANDS) && (ctx)->record->operands[id])); \
55 operand = &(ctx)->operands[++id])
56
57 enum opid_state
58 opid_disassemble(struct opid_ctx *ctx, uint64_t insn);
59
60 struct opid_record const *
61 opid_lookup_insn(uint64_t insn);