PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
state.h
Go to the documentation of this file.
1#pragma once
2
7
8/**
9 * @brief State
10 * @defgroup modules_acpi_aml_state State
11 * @ingroup modules_acpi_aml
12 *
13 * @{
14 */
15
16/**
17 * @brief AML State
18 * @struct aml_state_t
19 *
20 * Used to keep track of the virtual machine's state and while invoking methods or parsing DSDT/SSDT tables.
21 *
22 * Note that when a Method is evaluated a new `aml_state_t` is created for the Method's AML bytecode stream.
23 */
24typedef struct aml_state
25{
26 aml_local_t* locals[AML_MAX_LOCALS]; ///< Local variables for the method, if any, initialized lazily.
27 aml_arg_t* args[AML_MAX_ARGS]; ///< Argument variables for the method, if any.
28 aml_object_t* result; ///< The return value, see `aml_method_invoke()` for details.
29 uint64_t errorDepth; ///< The length of the error traceback, if 0 then no error has occurred.
30 aml_overlay_t overlay; ///< Holds any named objects created during parsing.
32
33/**
34 * @brief Initialize an AML state.
35 *
36 * @param state Pointer to the state to initialize.
37 * @param args Array of pointers to the objects to pass as arguments, or `NULL`. Must be null-terminated.
38 * @return On success, `0`. On failure, `ERR` and `errno` is set.
39 */
41
42/**
43 * @brief Deinitialize an AML state.
44 *
45 * @param state Pointer to the state to deinitialize.
46 */
47void aml_state_deinit(aml_state_t* state);
48
49/**
50 * @brief Get the result object of the state.
51 *
52 * If no result is available, a Integer object with value 0 is returned.
53 *
54 * @see aml_method_invoke() for more details.
55 *
56 * @param state Pointer to the state.
57 * @return On success, a copy of the result object. On failure, `NULL` and `errno` is set.
58 */
60
61/**
62 * @brief Set the result object of the state.
63 *
64 * Note that methods are supposed to return copies of objects, not references to existing objects. However, due to the
65 * behaviour of implicit returns, always returning the last evaluated object, means there is no way for the object to be
66 * modified between this function being called and the method returning. So in this case it is acceptable to store a
67 * reference to the object and only make a copy when the method actually returns.
68 *
69 * @see aml_method_invoke() for more details.
70 *
71 * @param state Pointer to the state.
72 * @param result Pointer to the result object, or `NULL` to clear the result.
73 */
75
76/** @} */
#define AML_MAX_ARGS
Maximum number of arguments that can be passed to a method.
Definition arg.h:19
#define AML_MAX_LOCALS
Maximum number of local variables that can be used in a method.
Definition local.h:21
void aml_state_result_set(aml_state_t *state, aml_object_t *result)
Set the result object of the state.
Definition state.c:120
uint64_t aml_state_init(aml_state_t *state, aml_object_t **args)
Initialize an AML state.
Definition state.c:8
aml_object_t * aml_state_result_get(aml_state_t *state)
Get the result object of the state.
Definition state.c:87
void aml_state_deinit(aml_state_t *state)
Deinitialize an AML state.
Definition state.c:68
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Data for an argument object.
Definition object.h:427
Data for a local variable object.
Definition object.h:437
ACPI object.
Definition object.h:447
Namespace overlay.
Definition namespace.h:87
AML State.
Definition state.h:25
aml_object_t * result
The return value, see aml_method_invoke() for details.
Definition state.h:28
uint64_t errorDepth
The length of the error traceback, if 0 then no error has occurred.
Definition state.h:29
aml_overlay_t overlay
Holds any named objects created during parsing.
Definition state.h:30