PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
convert.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <stdint.h>
6
7/**
8 * @brief Data Type Conversion
9 * @defgroup modules_acpi_aml_convert Convert
10 * @ingroup modules_acpi_aml
11 *
12 * @see Section 19.3.5 of the ACPI specification for more details.
13 * @see Section 19.3.5.7 table 19.6 for the conversion priority order.
14 * @see Section 19.3.5.7 table 19.7 for a summary of the conversion rules.
15 *
16 * @{
17 */
18
19/**
20 * @brief Converts the data in the source object to a allowed type and stores it in the destination object.
21 *
22 * Follows the rules in table 19.6 section 19.3.5.6 of the ACPI specification.
23 *
24 * See Section 19.3.5.6 of the ACPI specification for more details.
25 *
26 * @param state Pointer to the current AML state.
27 * @param src Pointer to the source object to convert.
28 * @param dest Pointer to the destination object where the converted value will be stored, can be of type
29 * `AML_UNINITIALIZED`.
30 * @return On success, `0`. On failure, `ERR` and `errno` is set.
31 */
32uint64_t aml_convert(aml_state_t* state, aml_object_t* src, aml_object_t* dest, aml_type_t allowedTypes);
33
34/**
35 * @brief Performs a "Implicit Result Object Conversion" acording to the rules in section 19.3.5.5 of the ACPI
36 * specification.
37 *
38 * @see Section 19.3.5.5 of the ACPI specification for more details.
39 *
40 * @param state Pointer to the current AML state.
41 * @param result Pointer to the result object to convert.
42 * @param target Pointer to the target object to store the result in. For convenience this can be `NULL`, in which case
43 * this does nothing.
44 * @return On success, `0`. On failure, `ERR` and `errno` is set.
45 */
47
48/**
49 * @brief Performs a "Implicit Source Operand Conversion" acording to the rules in section 19.3.5.4 of the ACPI
50 * specification.
51 *
52 * If `dest` is `NULL` then either, a new object is allocated and assigned to `*dest`, or `*dest` will be set to a
53 * reference `src` if no conversion is needed.
54 *
55 * If `dest` is not `NULL` then the object pointed to by `*dest` will be set to the converted value or a copy of `src`
56 * if no conversion is needed.
57 *
58 * This `dest` handling is to allow for the common case where the source object does not need to be converted. In which
59 * case we can avoid a allocation and a copy buts its also just a requirement. For instance if we are implementing Index
60 * and the source in a buffer well then we need the created BufferField to point to the original buffer not a copy of
61 * it.
62 *
63 * @see Section 19.3.5.4 of the ACPI specification for more details.
64 *
65 * @param state Pointer to the current AML state.
66 * @param src Pointer to the source object to convert, if `AML_ARG` or `AML_LOCAL`, the value object will be used.
67 * @param dest Pointer to the object pointer where the converted value will be stored, see above for details.
68 * @param allowedTypes Bitmask of allowed destination types.
69 * @return On success, `0`. On failure, `ERR` and `errno` is set.
70 */
72
73/**
74 * @brief Converts a Integer, String or Buffer source object to a Buffer destination object.
75 *
76 * Note that this behaviour is different from the implicit source operand conversion and implicit result object
77 * conversion rules.
78 *
79 * @see Section 19.6.138 of the ACPI specification for more details.
80 *
81 * @param state Pointer to the current AML state.
82 * @param src Pointer to the source object to convert. Must be of type Integer, String or Buffer.
83 * @param dest Pointer to the object pointer where the converted value will be stored, see `aml_convert_source` for
84 * details.
85 * @return On success, `0`. On failure, `ERR` and `errno` is set.
86 */
88
89/**
90 * @brief Converts a Integer, String or Buffer source object to a String destination object in decimal format.
91 *
92 * Note that this behaviour is different from the implicit source operand conversion and implicit result object
93 * conversion rules.
94 *
95 * @see Section 19.6.139 of the ACPI specification for more details.
96 *
97 * @param state Pointer to the current AML state.
98 * @param src Pointer to the source object to convert. Must be of type Integer, String or Buffer.
99 * @param dest Pointer to the object pointer where the converted value will be stored, see `aml_convert_source` for
100 * details.
101 * @return On success, `0`. On failure, `ERR` and `errno` is set.
102 */
104
105/**
106 * @brief Converts a Integer, String or Buffer source object to a String destination object in hexadecimal format.
107 *
108 * Note that this behaviour is different from the implicit source operand conversion and implicit result object
109 * conversion rules.
110 *
111 * @see Section 19.6.140 of the ACPI specification for more details.
112 *
113 * @param state Pointer to the current AML state.
114 * @param src Pointer to the source object to convert. Must be of type Integer, String or Buffer.
115 * @param dest Pointer to the object pointer where the converted value will be stored, see `aml_convert_source` for
116 * details.
117 * @return On success, `0`. On failure, `ERR` and `errno` is set.
118 */
120
121/**
122 * @brief Converts a Integer, String or Buffer source object to an Integer destination object.
123 *
124 * Note that this behaviour is different from the implicit source operand conversion and implicit result object
125 * conversion rules.
126 *
127 * @see Section 19.6.141 of the ACPI specification for more details.
128 *
129 * @param state Pointer to the current AML state.
130 * @param src Pointer to the source object to convert. Must be of type Integer, String or Buffer.
131 * @param dest Pointer to the object pointer where the converted value will be stored, see `aml_convert_source` for
132 * details.
133 * @return On success, `0`. On failure, `ERR` and `errno` is set.
134 */
136
137/**
138 * @brief Converts an integer to its Binary-Coded Decimal (BCD) representation.
139 *
140 * Binary-Coded decimal (BCD) is a format where instead of each bit representing a power of two, the Integer is split
141 * into its individual decimal digits, and each digit is represented by a fixed number of bits. For example, the integer
142 * `45` would be represented in BCD as `0x45` or in binary `0100 0101`.
143 *
144 * The number of bits per digit varies and the ACPI specification does not seem to specify how many should be
145 * used, nor really anything at all about BCD. However, the most common representation seems to be 4 bits per digit,
146 * which is what this function uses. The spec also does not specify what to do if the integer is too large to fit
147 * in the BCD representation, so we just ignore it. I love ACPI.
148 *
149 * @param value The integer value to convert.
150 * @param out Pointer to the output buffer where the BCD representation will be stored.
151 * @return On success, `0`. On failure, `ERR` and `errno` is set.
152 */
154
155/** @} */
uint64_t aml_convert_to_decimal_string(aml_state_t *state, aml_object_t *src, aml_object_t **dest)
Converts a Integer, String or Buffer source object to a String destination object in decimal format.
Definition convert.c:655
uint64_t aml_convert(aml_state_t *state, aml_object_t *src, aml_object_t *dest, aml_type_t allowedTypes)
Converts the data in the source object to a allowed type and stores it in the destination object.
Definition convert.c:369
uint64_t aml_convert_result(aml_state_t *state, aml_object_t *result, aml_object_t *target)
Performs a "Implicit Result Object Conversion" acording to the rules in section 19....
Definition convert.c:489
uint64_t aml_convert_to_buffer(aml_state_t *state, aml_object_t *src, aml_object_t **dest)
Converts a Integer, String or Buffer source object to a Buffer destination object.
Definition convert.c:602
uint64_t aml_convert_to_hex_string(aml_state_t *state, aml_object_t *src, aml_object_t **dest)
Converts a Integer, String or Buffer source object to a String destination object in hexadecimal form...
Definition convert.c:761
uint64_t aml_convert_source(aml_state_t *state, aml_object_t *src, aml_object_t **dest, aml_type_t allowedTypes)
Performs a "Implicit Source Operand Conversion" acording to the rules in section 19....
Definition convert.c:545
uint64_t aml_convert_integer_to_bcd(aml_uint_t value, aml_uint_t *out)
Converts an integer to its Binary-Coded Decimal (BCD) representation.
Definition convert.c:951
uint64_t aml_convert_to_integer(aml_state_t *state, aml_object_t *src, aml_object_t **dest)
Converts a Integer, String or Buffer source object to an Integer destination object.
Definition convert.c:851
uint64_t aml_uint_t
AML Integer type.
Definition integer.h:20
aml_type_t
ACPI data types.
Definition object.h:59
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
ACPI object.
Definition object.h:447
AML State.
Definition state.h:25