forked from uACPI/uACPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopcodes.c
118 lines (106 loc) · 5.95 KB
/
opcodes.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <uacpi/internal/opcodes.h>
#define UACPI_OP(opname, opcode, ...) \
{ #opname, .decode_ops = __VA_ARGS__, .code = opcode },
#define UACPI_OUT_OF_LINE_OP(opname, opcode, out_of_line_buf, props) \
{ \
.name = #opname, \
.indirect_decode_ops = out_of_line_buf, \
.properties = props, \
.code = opcode, \
},
static const struct uacpi_op_spec opcode_table[0x100] = {
UACPI_ENUMERATE_OPCODES
};
static const struct uacpi_op_spec ext_opcode_table[] = {
UACPI_ENUMERATE_EXT_OPCODES
};
#define _(op) (op & 0x00FF)
static const uacpi_u8 ext_op_to_idx[0x100] = {
[_(UACPI_AML_OP_MutexOp)] = 1, [_(UACPI_AML_OP_EventOp)] = 2,
[_(UACPI_AML_OP_CondRefOfOp)] = 3, [_(UACPI_AML_OP_CreateFieldOp)] = 4,
[_(UACPI_AML_OP_LoadTableOp)] = 5, [_(UACPI_AML_OP_LoadOp)] = 6,
[_(UACPI_AML_OP_StallOp)] = 7, [_(UACPI_AML_OP_SleepOp)] = 8,
[_(UACPI_AML_OP_AcquireOp)] = 9, [_(UACPI_AML_OP_SignalOp)] = 10,
[_(UACPI_AML_OP_WaitOp)] = 11, [_(UACPI_AML_OP_ResetOp)] = 12,
[_(UACPI_AML_OP_ReleaseOp)] = 13, [_(UACPI_AML_OP_FromBCDOp)] = 14,
[_(UACPI_AML_OP_ToBCDOp)] = 15, [_(UACPI_AML_OP_RevisionOp)] = 16,
[_(UACPI_AML_OP_DebugOp)] = 17, [_(UACPI_AML_OP_FatalOp)] = 18,
[_(UACPI_AML_OP_TimerOp)] = 19, [_(UACPI_AML_OP_OpRegionOp)] = 20,
[_(UACPI_AML_OP_FieldOp)] = 21, [_(UACPI_AML_OP_DeviceOp)] = 22,
[_(UACPI_AML_OP_ProcessorOp)] = 23, [_(UACPI_AML_OP_PowerResOp)] = 24,
[_(UACPI_AML_OP_ThermalZoneOp)] = 25, [_(UACPI_AML_OP_IndexFieldOp)] = 26,
[_(UACPI_AML_OP_BankFieldOp)] = 27, [_(UACPI_AML_OP_DataRegionOp)] = 28,
};
const struct uacpi_op_spec *uacpi_get_op_spec(uacpi_aml_op op)
{
if (op > 0xFF)
return &ext_opcode_table[ext_op_to_idx[_(op)]];
return &opcode_table[op];
}
#define PARSE_FIELD_ELEMENTS(parse_loop_pc) \
/* Parse every field element found inside */ \
UACPI_PARSE_OP_IF_HAS_DATA, 44, \
/* Look at the first byte */ \
UACPI_PARSE_OP_LOAD_IMM, 1, \
\
/* ReservedField := 0x00 PkgLength */ \
UACPI_PARSE_OP_IF_EQUALS, 0x00, 3, \
UACPI_PARSE_OP_PKGLEN, \
UACPI_PARSE_OP_JMP, parse_loop_pc, \
\
/* AccessField := 0x01 AccessType AccessAttrib */ \
UACPI_PARSE_OP_IF_EQUALS, 0x01, 6, \
UACPI_PARSE_OP_LOAD_IMM, 1, \
UACPI_PARSE_OP_LOAD_IMM, 1, \
UACPI_PARSE_OP_JMP, parse_loop_pc, \
\
/* ConnectField := <0x02 NameString> | <0x02 BufferData> */ \
UACPI_PARSE_OP_IF_EQUALS, 0x02, 5, \
UACPI_PARSE_OP_TERM_ARG_UNWRAP_INTERNAL, \
UACPI_PARSE_OP_TYPECHECK, UACPI_OBJECT_BUFFER, \
UACPI_PARSE_OP_JMP, parse_loop_pc, \
\
/* ExtendedAccessField := 0x03 AccessType ExtendedAccessAttrib \
* AccessLength */ \
UACPI_PARSE_OP_IF_EQUALS, 0x03, 8, \
UACPI_PARSE_OP_LOAD_IMM, 1, \
UACPI_PARSE_OP_LOAD_IMM, 1, \
UACPI_PARSE_OP_LOAD_IMM, 1, \
UACPI_PARSE_OP_JMP, parse_loop_pc, \
\
/* NamedField := NameSeg PkgLength */ \
\
/* \
* Discard the immediate, as it's the first byte of the \
* nameseg. We don't need it. \
*/ \
UACPI_PARSE_OP_ITEM_POP, \
UACPI_PARSE_OP_AML_PC_DECREMENT, \
UACPI_PARSE_OP_CREATE_NAMESTRING, \
UACPI_PARSE_OP_PKGLEN, \
UACPI_PARSE_OP_OBJECT_ALLOC_TYPED, UACPI_OBJECT_FIELD_UNIT, \
UACPI_PARSE_OP_JMP, parse_loop_pc, \
\
UACPI_PARSE_OP_INVOKE_HANDLER, \
UACPI_PARSE_OP_END
uacpi_u8 uacpi_field_op_decode_ops[] = {
UACPI_PARSE_OP_TRACKED_PKGLEN,
UACPI_PARSE_OP_EXISTING_NAMESTRING,
UACPI_PARSE_OP_LOAD_IMM, 1,
PARSE_FIELD_ELEMENTS(4),
};
uacpi_u8 uacpi_bank_field_op_decode_ops[] = {
UACPI_PARSE_OP_TRACKED_PKGLEN,
UACPI_PARSE_OP_EXISTING_NAMESTRING,
UACPI_PARSE_OP_EXISTING_NAMESTRING,
UACPI_PARSE_OP_OPERAND,
UACPI_PARSE_OP_LOAD_IMM, 1,
PARSE_FIELD_ELEMENTS(6),
};
uacpi_u8 uacpi_index_field_op_decode_ops[] = {
UACPI_PARSE_OP_TRACKED_PKGLEN,
UACPI_PARSE_OP_EXISTING_NAMESTRING,
UACPI_PARSE_OP_EXISTING_NAMESTRING,
UACPI_PARSE_OP_LOAD_IMM, 1,
PARSE_FIELD_ELEMENTS(5),
};