PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
convert.c
Go to the documentation of this file.
2
3#include <kernel/log/log.h>
10
11#include <errno.h>
12#include <stdio.h>
13#include <stdlib.h>
14
15#define AML_HEX_DIGITS "0123456789ABCDEF"
16
17#define AML_CONVERT_TRY_NEXT_CONVERTER 1
18
20
21// DebugObj handling is specified in section 19.6.26
22
23// Note that there is a mistake in the spec in table 19.6 where it says Buffer to BufferField conversion is not allowed,
24// since in table 19.7 it defines how to do it and the ACPICA tests clearly expect it to work, we implement it as
25// specified in table 19.7.
26
33
35{
36 aml_type_t type = obj->type;
37 if (type == AML_STRING)
38 {
39 if (aml_string_resize(&obj->string, length) == ERR)
40 {
41 return ERR;
42 }
43 }
44 else
45 {
46 if (aml_string_set_empty(obj, length) == ERR)
47 {
48 return ERR;
49 }
50 }
51
52 return 0;
53}
54
55static inline void aml_byte_to_hex(uint8_t byte, char* dest)
56{
57 dest[0] = AML_HEX_DIGITS[byte >> 4];
58 dest[1] = AML_HEX_DIGITS[byte & 0x0F];
59}
60
61static inline uint8_t aml_hex_to_byte(char chr)
62{
63 if (chr >= '0' && chr <= '9')
64 return chr - '0';
65 if (chr >= 'a' && chr <= 'f')
66 return chr - 'a' + 10;
67 if (chr >= 'A' && chr <= 'F')
68 return chr - 'A' + 10;
69 return 16;
70}
71
72// We create the arrays of converters here. The order of the list defines the priority of the converters. First ==
73// Highest Priority. Last == Lowest Priority. See section 19.3.5.7 table 19.6 for the conversion priority order.
74
76{
77 (void)state;
78 if (dest->type != AML_BUFFER_FIELD)
79 {
81 }
83}
84
86{
87 (void)state;
88 aml_buffer_t* bufferData = &buffer->buffer;
89
90 uint64_t value = 0;
91 uint64_t maxBytes = MIN(bufferData->length, aml_integer_byte_size());
92 for (uint64_t i = 0; i < maxBytes; i++)
93 {
94 value |= ((uint64_t)bufferData->content[i]) << (i * 8);
95 }
96
97 if (dest->type == AML_INTEGER)
98 {
99 dest->integer.value = value;
100 return 0;
101 }
102 return aml_integer_set(dest, value);
103}
104
106{
107 (void)state;
108 aml_buffer_t* bufferData = &buffer->buffer;
109
110 // Each byte becomes two hex chars with a space in between, except the last byte.
111 uint64_t length = bufferData->length > 0 ? bufferData->length * 3 - 1 : 0;
112
113 if (aml_string_prepare(dest, length) == ERR)
114 {
115 return ERR;
116 }
117
118 char* content = dest->string.content;
119 for (uint64_t i = 0; i < bufferData->length; i++)
120 {
121 aml_byte_to_hex(bufferData->content[i], &content[i * 3]);
122 if (i < bufferData->length - 1)
123 {
124 content[i * 3 + 2] = ' ';
125 }
126 }
127
128 return 0;
129}
130
132{
133 (void)state;
134 (void)dest;
135
136 if (buffer->buffer.length == 0)
137 {
138 LOG_INFO("[]\n");
139 return 0;
140 }
141
142 LOG_INFO("[");
143 for (uint64_t i = 0; i < buffer->buffer.length; i++)
144 {
145 LOG_INFO("%02X", buffer->buffer.content[i]);
146 if (i < buffer->buffer.length - 1)
147 {
148 LOG_INFO(", ");
149 }
150 }
151 LOG_INFO("]\n");
152 return 0;
153}
154
161
163{
164 (void)state;
165 aml_integer_t* integerData = &integer->integer;
166
167 if (dest->type == AML_BUFFER)
168 {
170 uint8_t* content = dest->buffer.content;
171
172 for (uint64_t i = 0; i < length; i++)
173 {
174 content[i] = (integerData->value >> (i * 8)) & 0xFF;
175 }
176 for (uint64_t i = aml_integer_byte_size(); i < dest->buffer.length; i++)
177 {
178 content[i] = 0;
179 }
180 return 0;
181 }
182
183 return aml_buffer_set(dest, (uint8_t*)&integerData->value, aml_integer_byte_size(), aml_integer_byte_size());
184}
185
187{
188 if (dest->type != AML_FIELD_UNIT)
189 {
191 }
192 return aml_field_unit_store(state, &dest->fieldUnit, integer);
193}
194
196{
197 (void)state;
198 if (dest->type != AML_BUFFER_FIELD)
199 {
201 }
202 return aml_buffer_field_store(&dest->bufferField, integer);
203}
204
206{
207 (void)state;
208 const uint64_t stringLength = aml_integer_byte_size() * 2; // Two hex chars per byte
209
210 if (aml_string_prepare(dest, stringLength) == ERR)
211 {
212 return ERR;
213 }
214
215 aml_integer_t* integerData = &integer->integer;
216
217 char* content = dest->string.content;
218 for (uint64_t i = 0; i < aml_integer_byte_size(); i++)
219 {
220 uint8_t byte = (integerData->value >> (i * 8)) & 0xFF;
221 aml_byte_to_hex(byte, &content[aml_integer_byte_size() * 2 - i * 2 - 2]);
222 }
223
224 return 0;
225}
226
228{
229 (void)state;
230 (void)dest;
231 log_print(LOG_LEVEL_INFO, "0x%llx\n", integer->integer.value);
232 return 0;
233}
234
242
244{
245 (void)state;
246 (void)dest;
248 for (uint64_t i = 0; i < package->package.length; i++)
249 {
251 if (i < package->package.length - 1)
252 {
254 }
255 }
257 return 0;
258}
259
263
265{
266 (void)state;
267 aml_string_t* stringData = &string->string;
268
269 uint64_t value = 0;
270 uint64_t maxChars = MIN(stringData->length, aml_integer_byte_size() * 2); // Two hex chars per byte
271
272 for (uint64_t i = 0; i < maxChars; i++)
273 {
274 uint8_t digit = aml_hex_to_byte(stringData->content[i]);
275 if (digit == 16) // Stop at first non-hex character
276 {
277 break;
278 }
279 value = value * 16 + digit;
280 }
281
282 if (dest->type == AML_INTEGER)
283 {
284 dest->integer.value = value;
285 return 0;
286 }
287 return aml_integer_set(dest, value);
288}
289
291{
292 (void)state;
293 aml_string_t* stringData = &string->string;
294
295 // Regarding zero-length strings the spec says "... the string is treated as a buffer, with each
296 // ASCII string character copied to one buffer byte, including the null
297 // terminator. A null (zero-length) string will be converted to a zero-
298 // length buffer."
299 //
300 // The problem is zero-length strings are supposed to be converted to zero-length buffers. But testing with ACPICA
301 // shows that the null terminator is always added, even for zero-length strings, so we just do what ACPICA does.
302
303 uint64_t bufferLength = 0;
304 if (dest->type == AML_BUFFER)
305 {
306 bufferLength = dest->buffer.length;
307 }
308 else
309 {
310 bufferLength = stringData->length + 1; // +1 for null terminator
311 if (aml_buffer_set_empty(dest, bufferLength) == ERR)
312 {
313 return ERR;
314 }
315 }
316
317 if (bufferLength > 0)
318 {
319 uint8_t* content = dest->buffer.content;
320 uint64_t copyLen = MIN(stringData->length, bufferLength - 1);
321 memcpy(content, stringData->content, copyLen);
322 content[bufferLength - 1] = 0;
323 }
324
325 return 0;
326}
327
329{
330 (void)state;
331 (void)dest;
332 if (string->string.length == 0)
333 {
334 log_print(LOG_LEVEL_INFO, "<empty string>\n");
335 return 0;
336 }
337
338 log_print(LOG_LEVEL_INFO, "%s\n", string->string.content);
339 return 0;
340}
341
347
349{
350 switch (srcType)
351 {
352 case AML_BUFFER:
353 return bufferConverters;
354 case AML_INTEGER:
355 return integerConverters;
356 case AML_PACKAGE:
357 return packageConverters;
358 case AML_STRING:
359 return stringConverters;
360 case AML_DEBUG_OBJECT:
361 errno = ENOSYS;
362 return NULL;
363 default:
364 errno = EINVAL;
365 return NULL;
366 }
367}
368
370{
371 if (dest == NULL || src == NULL)
372 {
373 LOG_ERR("src/dest object is NULL\n");
374 errno = EINVAL;
375 return ERR;
376 }
377
378 if (src->type == AML_UNINITIALIZED)
379 {
380 LOG_ERR("source object is uninitialized\n");
381 errno = EINVAL;
382 return ERR;
383 }
384
385 // BufferFields and FieldUnits are treated as either Buffers or Integers based on size
386 if (src->type == AML_FIELD_UNIT || src->type == AML_BUFFER_FIELD)
387 {
389 if (temp == NULL)
390 {
391 return ERR;
392 }
393 UNREF_DEFER(temp);
394
395 if (src->type == AML_FIELD_UNIT)
396 {
397 if (aml_field_unit_load(state, &src->fieldUnit, temp) == ERR)
398 {
399 LOG_ERR("failed to load FieldUnit\n");
400 return ERR;
401 }
402 }
403 else // AML_BUFFER_FIELD
404 {
405 if (aml_buffer_field_load(&src->bufferField, temp) == ERR)
406 {
407 LOG_ERR("failed to load BufferField\n");
408 return ERR;
409 }
410 }
411
412 aml_type_t tempType = temp->type;
413 if (tempType & allowedTypes)
414 {
415 if (aml_copy_data_and_type(temp, dest) == ERR)
416 {
417 LOG_ERR("failed to copy loaded field to destination\n");
418 return ERR;
419 }
420 return 0;
421 }
422
423 return aml_convert(state, temp, dest, allowedTypes);
424 }
425
426 // AML seems to prioritize copying over conversion if the types match even if its not the
427 // highest priority conversion.
428 if (src->type & allowedTypes && (src->type == dest->type || dest->type == AML_UNINITIALIZED))
429 {
430 if (aml_copy_data_and_type(src, dest) == ERR)
431 {
432 LOG_ERR("failed to copy from '%s' to '%s'\n", aml_type_to_string(src->type),
433 aml_type_to_string(dest->type));
434 return ERR;
435 }
436 return 0;
437 }
438
439 aml_convert_entry_t* converters = aml_converters_get(src->type);
440 if (converters == NULL)
441 {
442 LOG_ERR("no converters defined for source type '%s'\n", aml_type_to_string(src->type));
443 return ERR;
444 }
445
446 for (size_t i = 0; i < AML_TYPE_AMOUNT; i++)
447 {
448 aml_convert_entry_t* entry = &converters[i];
449
450 if (entry->srcType == 0) // We reached the end of the array
451 {
452 LOG_ERR("no valid converter found from '%s' to any allowed type\n", aml_type_to_string(src->type));
453 errno = EILSEQ;
454 return ERR;
455 }
456
457 if (!(allowedTypes & entry->destType))
458 {
459 continue;
460 }
461
462 if (entry->convertFunc == NULL)
463 {
464 LOG_ERR("converter from '%s' to '%s' not implemented\n", aml_type_to_string(src->type),
466 errno = ENOSYS;
467 return ERR;
468 }
469
470 uint64_t result = entry->convertFunc(state, src, dest);
471 if (result == ERR)
472 {
473 LOG_ERR("conversion from '%s' to '%s' failed\n", aml_type_to_string(src->type),
475 return ERR;
476 }
477 else if (result == AML_CONVERT_TRY_NEXT_CONVERTER)
478 {
479 continue;
480 }
481
482 return 0;
483 }
484
485 errno = EILSEQ;
486 return ERR;
487}
488
490{
491 if (result == NULL)
492 {
493 LOG_ERR("result object is NULL\n");
494 errno = EINVAL;
495 return ERR;
496 }
497
498 if (result->type == AML_UNINITIALIZED || target->type == AML_UNINITIALIZED)
499 {
500 LOG_ERR("result/target object is uninitialized\n");
501 errno = EINVAL;
502 return ERR;
503 }
504
505 if (target == NULL)
506 {
507 return 0;
508 }
509
510 if (target->type == AML_ARG || target->type == AML_LOCAL)
511 {
512 if (aml_store(state, result, target) == ERR)
513 {
514 LOG_ERR("failed to store result '%s' of type '%s' to target '%s' of type '%s'\n",
515 AML_NAME_TO_STRING(result->name), aml_type_to_string(result->type), AML_NAME_TO_STRING(target->name),
516 aml_type_to_string(target->type));
517 return ERR;
518 }
519 return 0;
520 }
521
522 // I am assuming that "fixed type" means not a DataRefObject, let me know if this is wrong.
523 if (!(target->type & AML_DATA_REF_OBJECTS))
524 {
525 if (aml_convert(state, result, target, target->type) == ERR)
526 {
527 LOG_ERR("failed to convert result '%s' of type '%s' to target '%s' of '%s'\n",
528 AML_NAME_TO_STRING(result->name), aml_type_to_string(result->type), AML_NAME_TO_STRING(target->name),
529 aml_type_to_string(target->type));
530 return ERR;
531 }
532 return 0;
533 }
534
535 if (aml_copy_data_and_type(result, target) == ERR)
536 {
537 LOG_ERR("failed to copy result '%s' of type '%s' to target '%s' of '%s'\n", AML_NAME_TO_STRING(result->name),
538 aml_type_to_string(result->type), AML_NAME_TO_STRING(target->name), aml_type_to_string(target->type));
539 return ERR;
540 }
541
542 return 0;
543}
544
546{
547 if (src == NULL || dest == NULL)
548 {
549 LOG_ERR("src/dest object is NULL\n");
550 errno = EINVAL;
551 return ERR;
552 }
553
554 if (src->type == AML_UNINITIALIZED)
555 {
556 LOG_ERR("source object is uninitialized\n");
557 errno = EINVAL;
558 return ERR;
559 }
560
561 if (src->type == AML_ARG)
562 {
563 return aml_convert_source(state, src->arg.value, dest, allowedTypes);
564 }
565
566 if (src->type == AML_LOCAL)
567 {
568 return aml_convert_source(state, src->local.value, dest, allowedTypes);
569 }
570
571 if (src->type & allowedTypes)
572 {
573 if (*dest != NULL)
574 {
575 return aml_copy_data_and_type(src, *dest);
576 }
577 *dest = REF(src);
578 return 0;
579 }
580
581 if (*dest != NULL)
582 {
583 return aml_convert(state, src, *dest, allowedTypes);
584 }
585
586 *dest = aml_object_new();
587 if (*dest == NULL)
588 {
589 return ERR;
590 }
591
592 if (aml_convert(state, src, *dest, allowedTypes) == ERR)
593 {
594 UNREF(*dest);
595 *dest = NULL;
596 return ERR;
597 }
598
599 return 0;
600}
601
603{
604 if (src == NULL || dest == NULL)
605 {
606 LOG_ERR("src/dest object is NULL\n");
607 errno = EINVAL;
608 return ERR;
609 }
610
611 if (src->type == AML_UNINITIALIZED)
612 {
613 LOG_ERR("src object is uninitialized\n");
614 errno = EINVAL;
615 return ERR;
616 }
617
618 if (src->type == AML_BUFFER)
619 {
620 *dest = REF(src);
621 return 0;
622 }
623
625 if (temp == NULL)
626 {
627 return ERR;
628 }
629 UNREF_DEFER(temp);
630
631 if (src->type == AML_INTEGER)
632 {
633 if (aml_integer_to_buffer(state, src, temp) == ERR)
634 {
635 return ERR;
636 }
637 *dest = REF(temp);
638 return 0;
639 }
640 else if (src->type == AML_STRING)
641 {
642 if (aml_string_to_buffer(state, src, temp) == ERR)
643 {
644 return ERR;
645 }
646 *dest = REF(temp);
647 return 0;
648 }
649
650 LOG_ERR("cannot convert '%s' to Buffer\n", aml_type_to_string(src->type));
651 errno = EILSEQ;
652 return ERR;
653}
654
656{
657 (void)state;
658
659 if (src == NULL || dest == NULL)
660 {
661 LOG_ERR("src/dest object is NULL\n");
662 errno = EINVAL;
663 return ERR;
664 }
665
666 if (src->type == AML_UNINITIALIZED)
667 {
668 LOG_ERR("src object is uninitialized\n");
669 errno = EINVAL;
670 return ERR;
671 }
672
673 if (src->type == AML_STRING)
674 {
675 *dest = REF(src);
676 return 0;
677 }
678
680 if (temp == NULL)
681 {
682 return ERR;
683 }
684 UNREF_DEFER(temp);
685
686 if (src->type == AML_INTEGER)
687 {
688 char buffer[21]; // Max uint64_t is 20 digits + null terminator
689 int length = snprintf(buffer, sizeof(buffer), "%llu", src->integer.value);
690 if (length < 0)
691 {
692 return ERR;
693 }
694
695 if (aml_string_set_empty(temp, length) == ERR)
696 {
697 return ERR;
698 }
699 memcpy(temp->string.content, buffer, length);
700 *dest = REF(temp);
701 return 0;
702 }
703 else if (src->type == AML_BUFFER)
704 {
705 aml_buffer_t* bufferData = &src->buffer;
706
707 if (bufferData->length == 0)
708 {
709 if (aml_string_set_empty(temp, 0) == ERR)
710 {
711 return ERR;
712 }
713 *dest = REF(temp);
714 return 0;
715 }
716
717 uint64_t maxLen = bufferData->length * 4; // "255," per byte worst case
718 char* buff = malloc(maxLen + 1);
719 if (buff == NULL)
720 {
721 return ERR;
722 }
723
724 char* p = buff;
725 char* end = p + maxLen;
726 for (uint64_t i = 0; i < bufferData->length; i++)
727 {
728 int written = snprintf(p, end - p, "%u", bufferData->content[i]);
729 if (written < 0 || p + written >= end)
730 {
731 free(buff);
732 errno = EILSEQ;
733 return ERR;
734 }
735 p += written;
736
737 if (i < bufferData->length - 1 && p < end - 1)
738 {
739 *p++ = ',';
740 }
741 }
742 *p = '\0';
743
744 uint64_t length = p - buff;
745 if (aml_string_prepare(temp, length) == ERR)
746 {
747 free(temp);
748 return ERR;
749 }
750 memcpy(temp->string.content, temp, length);
751 free(buff);
752 *dest = REF(temp);
753 return 0;
754 }
755
756 LOG_ERR("cannot convert '%s' to String\n", aml_type_to_string(src->type));
757 errno = EILSEQ;
758 return ERR;
759}
760
762{
763 (void)state;
764
765 if (src == NULL || dest == NULL)
766 {
767 LOG_ERR("src/dest object is NULL\n");
768 errno = EINVAL;
769 return ERR;
770 }
771
772 if (src->type == AML_UNINITIALIZED)
773 {
774 LOG_ERR("src object is uninitialized\n");
775 errno = EINVAL;
776 return ERR;
777 }
778
779 if (src->type == AML_STRING)
780 {
781 *dest = REF(src);
782 return 0;
783 }
784
786 if (temp == NULL)
787 {
788 return ERR;
789 }
790 UNREF_DEFER(temp);
791
792 if (src->type == AML_INTEGER)
793 {
794 char buffer[17]; // 16 hex digits + null terminator
795 int len = snprintf(buffer, sizeof(buffer), "%llx", (unsigned long long)src->integer.value);
796 if (len < 0)
797 {
798 return ERR;
799 }
800
801 if (aml_string_set_empty(temp, len) == ERR)
802 {
803 UNREF(temp);
804 return ERR;
805 }
806 memcpy(temp->string.content, buffer, len + 1);
807 *dest = REF(temp);
808 return 0;
809 }
810 else if (src->type == AML_BUFFER)
811 {
812 aml_buffer_t* bufferData = &src->buffer;
813
814 if (bufferData->length == 0)
815 {
816 if (aml_string_set_empty(temp, 0) == ERR)
817 {
818 UNREF(temp);
819 return ERR;
820 }
821 *dest = REF(temp);
822 return 0;
823 }
824
825 uint64_t len = bufferData->length * 3 - 1; // "XX," per byte except last
826 if (aml_string_set_empty(temp, len) == ERR)
827 {
828 UNREF(temp);
829 return ERR;
830 }
831
832 char* content = temp->string.content;
833 for (uint64_t i = 0; i < bufferData->length; i++)
834 {
835 aml_byte_to_hex(bufferData->content[i], &content[i * 3]);
836 if (i < bufferData->length - 1)
837 {
838 content[i * 3 + 2] = ',';
839 }
840 }
841 content[len] = '\0';
842 *dest = REF(temp);
843 return 0;
844 }
845
846 LOG_ERR("cannot convert '%s' to String\n", aml_type_to_string(src->type));
847 errno = EILSEQ;
848 return ERR;
849}
850
852{
853 (void)state;
854
855 if (src == NULL || dest == NULL)
856 {
857 LOG_ERR("src/dest object is NULL\n");
858 errno = EINVAL;
859 return ERR;
860 }
861
862 if (src->type == AML_UNINITIALIZED)
863 {
864 LOG_ERR("src object is uninitialized\n");
865 errno = EINVAL;
866 return ERR;
867 }
868
869 if (src->type == AML_INTEGER)
870 {
871 *dest = REF(src);
872 return 0;
873 }
874
876 if (temp == NULL)
877 {
878 return ERR;
879 }
880 UNREF_DEFER(temp);
881
882 if (src->type == AML_STRING)
883 {
884 aml_string_t* stringData = &src->string;
885 if (stringData->length == 0 || stringData->content == NULL)
886 {
887 errno = EILSEQ;
888 return ERR;
889 }
890
891 // Determine if hex (0x prefix) or decimal
892 bool isHex = false;
893 uint64_t i = 0;
894 if (stringData->length > 2 && stringData->content[0] == '0' &&
895 (stringData->content[1] == 'x' || stringData->content[1] == 'X'))
896 {
897 isHex = true;
898 i = 2;
899 }
900
901 // "If the value exceeds the maximum, the result is unpredictable" - ACPI Spec
902 aml_uint_t value = 0;
903 for (; i < stringData->length; i++)
904 {
905 char chr = stringData->content[i];
906
907 if (isHex)
908 {
909 uint8_t digit = aml_hex_to_byte(chr);
910 if (digit == 16) // Stop at first non-hex character
911 {
912 break;
913 }
914 value = value * 16 + digit;
915 }
916 else
917 {
918 if (chr >= '0' && chr <= '9')
919 {
920 value = value * 10 + (chr - '0');
921 }
922 else
923 {
924 break;
925 }
926 }
927 }
928
929 if (aml_integer_set(temp, value) == ERR)
930 {
931 return ERR;
932 }
933 *dest = REF(temp);
934 return 0;
935 }
936 else if (src->type == AML_BUFFER)
937 {
938 if (aml_buffer_to_integer(state, src, temp) == ERR)
939 {
940 return ERR;
941 }
942 *dest = REF(temp);
943 return 0;
944 }
945
946 LOG_ERR("cannot convert '%s' to Integer\n", aml_type_to_string(src->type));
947 errno = EILSEQ;
948 return ERR;
949}
950
952{
953 if (out == NULL)
954 {
955 errno = EINVAL;
956 return ERR;
957 }
958
959 aml_uint_t bcd = 0;
960 for (uint64_t i = 0; i < aml_integer_byte_size() * 2; i++) // 2 nibbles per byte
961 {
962 uint8_t digit = value % 10;
963 bcd |= ((aml_uint_t)digit) << (i * 4);
964 value /= 10;
965 if (value == 0)
966 break;
967 }
968
969 *out = bcd;
970 return 0;
971}
static uint64_t aml_buffer_to_string(aml_state_t *state, aml_object_t *buffer, aml_object_t *dest)
Definition convert.c:105
static uint64_t aml_string_to_integer(aml_state_t *state, aml_object_t *string, aml_object_t *dest)
Definition convert.c:264
static uint64_t aml_buffer_to_debug_object(aml_state_t *state, aml_object_t *buffer, aml_object_t *dest)
Definition convert.c:131
static uint64_t aml_string_prepare(aml_object_t *obj, uint64_t length)
Definition convert.c:34
static aml_convert_entry_t integerConverters[AML_TYPE_AMOUNT]
Definition convert.c:235
#define AML_HEX_DIGITS
Definition convert.c:15
static uint64_t aml_integer_to_buffer(aml_state_t *state, aml_object_t *integer, aml_object_t *dest)
Definition convert.c:162
static uint64_t aml_package_to_debug_object(aml_state_t *state, aml_object_t *package, aml_object_t *dest)
Definition convert.c:243
static uint8_t aml_hex_to_byte(char chr)
Definition convert.c:61
static uint64_t aml_buffer_to_integer(aml_state_t *state, aml_object_t *buffer, aml_object_t *dest)
Definition convert.c:85
static uint64_t aml_string_to_buffer(aml_state_t *state, aml_object_t *string, aml_object_t *dest)
Definition convert.c:290
#define AML_CONVERT_TRY_NEXT_CONVERTER
Definition convert.c:17
static uint64_t aml_integer_to_string(aml_state_t *state, aml_object_t *integer, aml_object_t *dest)
Definition convert.c:205
static uint64_t aml_integer_to_buffer_field(aml_state_t *state, aml_object_t *integer, aml_object_t *dest)
Definition convert.c:195
static aml_convert_entry_t * aml_converters_get(aml_type_t srcType)
Definition convert.c:348
static uint64_t aml_buffer_to_buffer_field(aml_state_t *state, aml_object_t *buffer, aml_object_t *dest)
Definition convert.c:75
static aml_convert_entry_t packageConverters[AML_TYPE_AMOUNT]
Definition convert.c:260
static aml_convert_entry_t stringConverters[AML_TYPE_AMOUNT]
Definition convert.c:342
static void aml_byte_to_hex(uint8_t byte, char *dest)
Definition convert.c:55
static aml_convert_entry_t bufferConverters[AML_TYPE_AMOUNT]
Definition convert.c:155
uint64_t(* aml_convert_func_t)(aml_state_t *state, aml_object_t *src, aml_object_t *dest)
Definition convert.c:19
static uint64_t aml_integer_to_field_unit(aml_state_t *state, aml_object_t *integer, aml_object_t *dest)
Definition convert.c:186
static uint64_t aml_integer_to_debug_object(aml_state_t *state, aml_object_t *integer, aml_object_t *dest)
Definition convert.c:227
static uint64_t aml_string_to_debug_object(aml_state_t *state, aml_object_t *string, aml_object_t *dest)
Definition convert.c:328
#define LOG_ERR(format,...)
Definition log.h:108
void log_print(log_level_t level, const char *format,...)
Print a formatted log message.
Definition log.c:191
#define LOG_INFO(format,...)
Definition log.h:106
@ LOG_LEVEL_INFO
Definition log.h:44
#define UNREF_DEFER(ptr)
RAII-style cleanup for scoped references.
Definition ref.h:54
#define REF(ptr)
Increment reference count.
Definition ref.h:65
#define UNREF(ptr)
Decrement reference count.
Definition ref.h:80
#define EINVAL
Invalid argument.
Definition errno.h:142
#define ENOSYS
Function not implemented.
Definition errno.h:222
#define errno
Error number variable.
Definition errno.h:27
#define EILSEQ
Illegal byte sequence.
Definition errno.h:447
#define MIN(x, y)
Definition math.h:16
#define NULL
Pointer error value.
Definition NULL.h:23
#define ERR
Integer error value.
Definition ERR.h:17
uint64_t aml_buffer_field_store(aml_buffer_field_t *bufferField, aml_object_t *in)
Write a value to a BufferField.
uint64_t aml_buffer_field_load(aml_buffer_field_t *bufferField, aml_object_t *out)
Read the value stored in a BufferField and store it in the out object.
Definition buffer_field.c:9
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_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_field_unit_load(aml_state_t *state, aml_field_unit_t *fieldUnit, aml_object_t *out)
Read the value stored in a FieldUnit. FieldUnits include Fields, IndexFields and BankFields.
Definition field_unit.c:612
uint64_t aml_field_unit_store(aml_state_t *state, aml_field_unit_t *fieldUnit, aml_object_t *in)
Write a value to a FieldUnit. FieldUnits include Fields, IndexFields and BankFields.
Definition field_unit.c:639
uint64_t aml_uint_t
AML Integer type.
Definition integer.h:20
uint8_t aml_integer_byte_size(void) PURE
Get the byte size of an AML integer.
Definition integer.c:22
#define AML_NAME_TO_STRING(name)
Macro to convert an aml_name_t to a stack allocated string.
Definition namespace.h:129
aml_type_t
ACPI data types.
Definition object.h:59
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
Definition object.c:62
uint64_t aml_buffer_set_empty(aml_object_t *object, uint64_t length)
Set a object as an empty buffer with the given length.
Definition object.c:533
uint64_t aml_string_set_empty(aml_object_t *object, uint64_t length)
Set a object as an empty string with the given length.
Definition object.c:1026
uint64_t aml_integer_set(aml_object_t *object, aml_uint_t value)
Set a object as an integer with the given value and bit width.
Definition object.c:772
uint64_t aml_buffer_set(aml_object_t *object, const uint8_t *buffer, uint64_t bytesToCopy, uint64_t length)
Set a object as a buffer with the given content.
Definition object.c:576
uint64_t aml_string_resize(aml_string_t *string, uint64_t newLength)
Resize a string object to the new length.
Definition object.c:1085
@ AML_BUFFER_FIELD
Definition object.h:62
@ AML_PACKAGE
Definition object.h:81
@ AML_TYPE_AMOUNT
Not a type, just the amount of types.
Definition object.h:117
@ AML_DEBUG_OBJECT
Definition object.h:63
@ AML_STRING
Definition object.h:85
@ AML_ARG
Not in the spec, used internally to represent method arguments.
Definition object.h:90
@ AML_FIELD_UNIT
Definition object.h:66
@ AML_DATA_REF_OBJECTS
Definition object.h:105
@ AML_LOCAL
Not in the spec, used internally to represent method local variables.
Definition object.h:91
@ AML_INTEGER
Definition object.h:67
@ AML_UNINITIALIZED
Definition object.h:60
@ AML_BUFFER
Definition object.h:61
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
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
Definition snprintf.c:3
_PUBLIC void * malloc(size_t size)
Definition malloc.c:5
_PUBLIC void free(void *ptr)
Definition free.c:11
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
Definition memcpy.c:61
aml_object_t * value
The object that was passed as the argument.
Definition object.h:429
Data for a buffer object.
Definition object.h:213
uint64_t length
Definition object.h:216
uint8_t * content
Definition object.h:215
Definition convert.c:28
aml_convert_func_t convertFunc
Definition convert.c:31
aml_type_t destType
Definition convert.c:30
aml_type_t srcType
Definition convert.c:29
Data for an integer object.
Definition object.h:286
aml_uint_t value
Definition object.h:288
aml_object_t * value
The value of the local variable.
Definition object.h:439
ACPI object.
Definition object.h:447
aml_package_t package
Definition object.h:464
aml_field_unit_t fieldUnit
Definition object.h:457
aml_integer_t integer
Definition object.h:458
aml_buffer_t buffer
Definition object.h:453
aml_string_t string
Definition object.h:467
aml_local_t local
Definition object.h:472
aml_buffer_field_t bufferField
Definition object.h:454
aml_arg_t arg
Definition object.h:471
aml_object_t ** elements
Definition object.h:361
uint64_t length
Definition object.h:362
AML State.
Definition state.h:25
Data for a string object.
Definition object.h:390
uint64_t length
Definition object.h:393
char * content
Definition object.h:392