PatchworkOS
Loading...
Searching...
No Matches
compare.c
Go to the documentation of this file.
2
4#include <kernel/log/log.h>
5
7{
8 switch (operation)
9 {
10 case AML_COMPARE_AND:
11 return (a != 0) && (b != 0) ? AML_TRUE : AML_FALSE;
13 return a == b ? AML_TRUE : AML_FALSE;
15 return a > b ? AML_TRUE : AML_FALSE;
17 return a < b ? AML_TRUE : AML_FALSE;
18 case AML_COMPARE_OR:
19 return (a != 0) || (b != 0) ? AML_TRUE : AML_FALSE;
20 default:
21 return AML_FALSE;
22 }
23}
24
29
31{
32 if (a == NULL || b == NULL)
33 {
34 return AML_FALSE;
35 }
36
37 if (operation >= AML_COMPARE_INVERT_BASE)
38 {
39 return aml_compare_not(aml_compare(a, b, operation - AML_COMPARE_INVERT_BASE));
40 }
41
42 aml_type_t aType = a->type;
43 aml_type_t bType = b->type;
44
45 if (aType != bType)
46 {
47 return AML_FALSE;
48 }
49
50 if (aType == AML_INTEGER)
51 {
52 return aml_compare_integers(a->integer.value, b->integer.value, operation);
53 }
54
55 uint64_t lenA = 0;
56 uint64_t lenB = 0;
57 const uint8_t* dataA = NULL;
58 const uint8_t* dataB = NULL;
59 switch (aType)
60 {
61 case AML_STRING:
62 {
63 lenA = a->string.length;
64 lenB = b->string.length;
65 dataA = (const uint8_t*)a->string.content;
66 dataB = (const uint8_t*)b->string.content;
67 }
68 break;
69 case AML_BUFFER:
70 {
71 lenA = a->buffer.length;
72 lenB = b->buffer.length;
73 dataA = a->buffer.content;
74 dataB = b->buffer.content;
75 }
76 break;
77 default:
78 return AML_FALSE;
79 }
80
81 uint64_t minLen = (lenA < lenB) ? lenA : lenB;
82
83 switch (operation)
84 {
86 if (lenA != lenB)
87 {
88 return AML_FALSE;
89 }
90 return memcmp(dataA, dataB, lenA) == 0 ? AML_TRUE : AML_FALSE;
92 for (uint64_t i = 0; i < minLen; i++)
93 {
94 if (dataA[i] > dataB[i])
95 {
96 return AML_TRUE;
97 }
98 else if (dataA[i] < dataB[i])
99 {
100 return AML_FALSE;
101 }
102 }
103 return lenA > lenB ? AML_TRUE : AML_FALSE;
104 case AML_COMPARE_LESS:
105 for (uint64_t i = 0; i < minLen; i++)
106 {
107 if (dataA[i] < dataB[i])
108 {
109 return AML_TRUE;
110 }
111 else if (dataA[i] > dataB[i])
112 {
113 return AML_FALSE;
114 }
115 }
116 return lenA < lenB ? AML_TRUE : AML_FALSE;
117 default:
118 return AML_FALSE;
119 }
120}
static aml_integer_t aml_compare_integers(aml_integer_t a, aml_integer_t b, aml_compare_operation_t operation)
Definition compare.c:6
aml_compare_operation_t
Definition compare.h:18
aml_integer_t aml_compare_not(aml_integer_t value)
Perform a logical NOT operation on an integer value.
Definition compare.c:25
aml_integer_t aml_compare(aml_object_t *a, aml_object_t *b, aml_compare_operation_t operation)
Compare two ACPI objects.
Definition compare.c:30
@ AML_COMPARE_OR
Section 19.6.80, integer only.
Definition compare.h:23
@ AML_COMPARE_LESS
Section 19.6.73.
Definition compare.h:22
@ AML_COMPARE_GREATER
Section 19.6.71.
Definition compare.h:21
@ AML_COMPARE_EQUAL
Section 19.6.70.
Definition compare.h:20
@ AML_COMPARE_AND
Section 19.6.69, integer only.
Definition compare.h:19
@ AML_COMPARE_INVERT_BASE
All operations above this value are inverted versions of the base operations.
Definition compare.h:25
uint64_t aml_integer_t
AML Integer type.
Definition integer.h:20
#define AML_FALSE
AML Boolean false value.
Definition integer.h:30
#define AML_TRUE
AML Boolean true value.
Definition integer.h:25
aml_type_t
ACPI data types.
Definition object.h:57
@ AML_STRING
Definition object.h:83
@ AML_INTEGER
Definition object.h:65
@ AML_BUFFER
Definition object.h:59
#define NULL
Pointer error value.
Definition NULL.h:23
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
_PUBLIC int memcmp(const void *s1, const void *s2, size_t n)
Definition memcmp.c:3
uint64_t length
Definition object.h:214
uint8_t * content
Definition object.h:213
aml_integer_t value
Definition object.h:266
ACPI object.
Definition object.h:425
aml_buffer_obj_t buffer
Definition object.h:431
aml_integer_obj_t integer
Definition object.h:435
aml_string_obj_t string
Definition object.h:444
char * content
Definition object.h:370
uint64_t length
Definition object.h:371