PatchworkOS
Loading...
Searching...
No Matches
store.c
Go to the documentation of this file.
2
6#include <kernel/log/log.h>
7
8#include <errno.h>
9
11{
12 if (src == NULL)
13 {
14 errno = EINVAL;
15 return ERR;
16 }
17
18 if (dest == NULL)
19 {
20 return 0;
21 }
22
23 if (dest->type == AML_ARG)
24 {
25 if (dest->arg.value == NULL) // Is uninitialized
26 {
27 aml_object_t* newValue = aml_object_new();
28 if (newValue == NULL)
29 {
30 return ERR;
31 }
32
33 dest->arg.value = newValue; // Transfer ownership
34 return aml_copy_data_and_type(src, dest->arg.value);
35 }
36
37 if (dest->arg.value->type == AML_OBJECT_REFERENCE)
38 {
39 return aml_copy_object(state, src, dest->arg.value->objectReference.target);
40 }
41 else
42 {
43 return aml_copy_data_and_type(src, dest->arg.value);
44 }
45 }
46
47 if (dest->type == AML_LOCAL)
48 {
49 return aml_copy_data_and_type(src, dest->local.value);
50 }
51
52 if (dest->type == AML_FIELD_UNIT || dest->type == AML_BUFFER_FIELD)
53 {
54 return aml_convert_result(state, src, dest);
55 }
56
57 if (dest->flags & AML_OBJECT_NAMED)
58 {
59 return aml_convert_result(state, src, dest);
60 }
61
62 if (dest->type == AML_DEBUG_OBJECT)
63 {
64 return aml_convert(state, src, dest, AML_DEBUG_OBJECT);
65 }
66
67 if (dest->type == AML_UNINITIALIZED)
68 {
69 return aml_copy_data_and_type(src, dest);
70 }
71
72 LOG_ERR("illegal store of object %s with flags '0x%x' to destination object of type '%s' with flags '0x%x'\n",
73 aml_object_to_string(src), src->flags, aml_type_to_string(dest->type), dest->flags);
74 errno = EINVAL;
75 return ERR;
76}
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_copy_data_and_type(aml_object_t *src, aml_object_t *dest)
Copies the data and type from the source object to the destination object, completly overwriting it.
Definition copy.c:11
uint64_t aml_copy_object(aml_state_t *state, aml_object_t *src, aml_object_t *dest)
Copies the data from the source object to the destination object.
Definition copy.c:93
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
Definition object.c:54
@ AML_BUFFER_FIELD
Definition object.h:60
@ AML_OBJECT_REFERENCE
Definition object.h:77
@ AML_DEBUG_OBJECT
Definition object.h:61
@ AML_ARG
Not in the spec, used internally to represent method arguments.
Definition object.h:88
@ AML_FIELD_UNIT
Definition object.h:64
@ AML_LOCAL
Not in the spec, used internally to represent method local variables.
Definition object.h:89
@ AML_UNINITIALIZED
Definition object.h:58
@ AML_OBJECT_NAMED
Appears in the namespace tree. Will be set in aml_object_add().
Definition object.h:126
uint64_t aml_store(aml_state_t *state, aml_object_t *src, aml_object_t *dest)
Store the value from the source object into the target object.
Definition store.c:10
const char * aml_type_to_string(aml_type_t type)
Convert an aml data type to a string.
Definition to_string.c:5
const char * aml_object_to_string(aml_object_t *object)
Convert an aml object to a string.
Definition to_string.c:144
#define LOG_ERR(format,...)
Definition log.h:89
#define EINVAL
Invalid argument.
Definition errno.h:142
#define errno
Error number variable.
Definition errno.h:27
#define NULL
Pointer error value.
Definition NULL.h:23
#define ERR
Integer error value.
Definition ERR.h:17
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
aml_object_t * value
The object that was passed as the argument.
Definition object.h:407
aml_object_t * value
The value of the local variable.
Definition object.h:417
aml_object_t * target
Definition object.h:315
ACPI object.
Definition object.h:425
aml_local_obj_t local
Definition object.h:449
aml_object_reference_obj_t objectReference
Definition object.h:439
aml_arg_obj_t arg
Definition object.h:448
AML State.
Definition state.h:25