PatchworkOS
Loading...
Searching...
No Matches
convert.c
Go to the documentation of this file.
2
9#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_obj_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_obj_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_obj_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_obj_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_INFO("0x%llx\n", integer->integer.value);
232 return 0;
233}
234
242
244{
245 (void)state;
246 (void)dest;
247 LOG_INFO("[");
248 for (uint64_t i = 0; i < package->package.length; i++)
249 {
250 LOG_INFO("%s", aml_object_to_string(package->package.elements[i]));
251 if (i < package->package.length - 1)
252 {
253 LOG_INFO(", ");
254 }
255 }
256 LOG_INFO("]\n");
257 return 0;
258}
259
263
265{
266 (void)state;
267 aml_string_obj_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_obj_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_INFO("\"\"\n");
335 return 0;
336 }
337
338 LOG_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 DEREF_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 copy result '%s' to target local/arg\n", aml_type_to_string(result->type));
515 return ERR;
516 }
517 return 0;
518 }
519
520 // I am assuming that "fixed type" means not a DataRefObject, let me know if this is wrong.
521 if (!(target->type & AML_DATA_REF_OBJECTS))
522 {
523 if (aml_convert(state, result, target, target->type) == ERR)
524 {
525 LOG_ERR("failed to convert result '%s' to target '%s'\n", aml_type_to_string(result->type),
526 aml_type_to_string(target->type));
527 return ERR;
528 }
529 return 0;
530 }
531
532 if (aml_copy_data_and_type(result, target) == ERR)
533 {
534 LOG_ERR("failed to copy result '%s' to target DataRefObject\n", aml_type_to_string(result->type));
535 return ERR;
536 }
537
538 return 0;
539}
540
542{
543 if (src == NULL || dest == NULL)
544 {
545 LOG_ERR("src/dest object is NULL\n");
546 errno = EINVAL;
547 return ERR;
548 }
549
550 if (src->type == AML_UNINITIALIZED)
551 {
552 LOG_ERR("source object is uninitialized\n");
553 errno = EINVAL;
554 return ERR;
555 }
556
557 if (src->type == AML_ARG)
558 {
559 return aml_convert_source(state, src->arg.value, dest, allowedTypes);
560 }
561
562 if (src->type == AML_LOCAL)
563 {
564 return aml_convert_source(state, src->local.value, dest, allowedTypes);
565 }
566
567 if (src->type & allowedTypes)
568 {
569 if (*dest != NULL)
570 {
571 return aml_copy_data_and_type(src, *dest);
572 }
573 *dest = REF(src);
574 return 0;
575 }
576
577 if (*dest != NULL)
578 {
579 return aml_convert(state, src, *dest, allowedTypes);
580 }
581
582 *dest = aml_object_new();
583 if (*dest == NULL)
584 {
585 return ERR;
586 }
587
588 if (aml_convert(state, src, *dest, allowedTypes) == ERR)
589 {
590 DEREF(*dest);
591 *dest = NULL;
592 return ERR;
593 }
594
595 return 0;
596}
597
599{
600 if (src == NULL || dest == NULL)
601 {
602 LOG_ERR("src/dest object is NULL\n");
603 errno = EINVAL;
604 return ERR;
605 }
606
607 if (src->type == AML_UNINITIALIZED)
608 {
609 LOG_ERR("src object is uninitialized\n");
610 errno = EINVAL;
611 return ERR;
612 }
613
614 if (src->type == AML_BUFFER)
615 {
616 *dest = REF(src);
617 return 0;
618 }
619
621 if (temp == NULL)
622 {
623 return ERR;
624 }
625 DEREF_DEFER(temp);
626
627 if (src->type == AML_INTEGER)
628 {
629 if (aml_integer_to_buffer(state, src, temp) == ERR)
630 {
631 return ERR;
632 }
633 *dest = REF(temp);
634 return 0;
635 }
636 else if (src->type == AML_STRING)
637 {
638 if (aml_string_to_buffer(state, src, temp) == ERR)
639 {
640 return ERR;
641 }
642 *dest = REF(temp);
643 return 0;
644 }
645
646 LOG_ERR("cannot convert '%s' to Buffer\n", aml_type_to_string(src->type));
647 errno = EILSEQ;
648 return ERR;
649}
650
652{
653 (void)state;
654
655 if (src == NULL || dest == NULL)
656 {
657 LOG_ERR("src/dest object is NULL\n");
658 errno = EINVAL;
659 return ERR;
660 }
661
662 if (src->type == AML_UNINITIALIZED)
663 {
664 LOG_ERR("src object is uninitialized\n");
665 errno = EINVAL;
666 return ERR;
667 }
668
669 if (src->type == AML_STRING)
670 {
671 *dest = REF(src);
672 return 0;
673 }
674
676 if (temp == NULL)
677 {
678 return ERR;
679 }
680 DEREF_DEFER(temp);
681
682 if (src->type == AML_INTEGER)
683 {
684 char buffer[21]; // Max uint64_t is 20 digits + null terminator
685 int length = snprintf(buffer, sizeof(buffer), "%llu", src->integer.value);
686 if (length < 0)
687 {
688 return ERR;
689 }
690
691 if (aml_string_set_empty(temp, length) == ERR)
692 {
693 return ERR;
694 }
695 memcpy(temp->string.content, buffer, length);
696 *dest = REF(temp);
697 return 0;
698 }
699 else if (src->type == AML_BUFFER)
700 {
701 aml_buffer_obj_t* bufferData = &src->buffer;
702
703 if (bufferData->length == 0)
704 {
705 if (aml_string_set_empty(temp, 0) == ERR)
706 {
707 return ERR;
708 }
709 *dest = REF(temp);
710 return 0;
711 }
712
713 uint64_t maxLen = bufferData->length * 4; // "255," per byte worst case
714 char* buff = malloc(maxLen + 1);
715 if (buff == NULL)
716 {
717 return ERR;
718 }
719
720 char* p = buff;
721 char* end = p + maxLen;
722 for (uint64_t i = 0; i < bufferData->length; i++)
723 {
724 int written = snprintf(p, end - p, "%u", bufferData->content[i]);
725 if (written < 0 || p + written >= end)
726 {
727 free(buff);
728 errno = EILSEQ;
729 return ERR;
730 }
731 p += written;
732
733 if (i < bufferData->length - 1 && p < end - 1)
734 {
735 *p++ = ',';
736 }
737 }
738 *p = '\0';
739
740 uint64_t length = p - buff;
741 if (aml_string_prepare(temp, length) == ERR)
742 {
743 free(temp);
744 return ERR;
745 }
746 memcpy(temp->string.content, temp, length);
747 free(buff);
748 *dest = REF(temp);
749 return 0;
750 }
751
752 LOG_ERR("cannot convert '%s' to String\n", aml_type_to_string(src->type));
753 errno = EILSEQ;
754 return ERR;
755}
756
758{
759 (void)state;
760
761 if (src == NULL || dest == NULL)
762 {
763 LOG_ERR("src/dest object is NULL\n");
764 errno = EINVAL;
765 return ERR;
766 }
767
768 if (src->type == AML_UNINITIALIZED)
769 {
770 LOG_ERR("src object is uninitialized\n");
771 errno = EINVAL;
772 return ERR;
773 }
774
775 if (src->type == AML_STRING)
776 {
777 *dest = REF(src);
778 return 0;
779 }
780
782 if (temp == NULL)
783 {
784 return ERR;
785 }
786 DEREF_DEFER(temp);
787
788 if (src->type == AML_INTEGER)
789 {
790 char buffer[17]; // 16 hex digits + null terminator
791 int len = snprintf(buffer, sizeof(buffer), "%llx", (unsigned long long)src->integer.value);
792 if (len < 0)
793 {
794 return ERR;
795 }
796
797 if (aml_string_set_empty(temp, len) == ERR)
798 {
799 DEREF(temp);
800 return ERR;
801 }
802 memcpy(temp->string.content, buffer, len + 1);
803 *dest = REF(temp);
804 return 0;
805 }
806 else if (src->type == AML_BUFFER)
807 {
808 aml_buffer_obj_t* bufferData = &src->buffer;
809
810 if (bufferData->length == 0)
811 {
812 if (aml_string_set_empty(temp, 0) == ERR)
813 {
814 DEREF(temp);
815 return ERR;
816 }
817 *dest = REF(temp);
818 return 0;
819 }
820
821 uint64_t len = bufferData->length * 3 - 1; // "XX," per byte except last
822 if (aml_string_set_empty(temp, len) == ERR)
823 {
824 DEREF(temp);
825 return ERR;
826 }
827
828 char* content = temp->string.content;
829 for (uint64_t i = 0; i < bufferData->length; i++)
830 {
831 aml_byte_to_hex(bufferData->content[i], &content[i * 3]);
832 if (i < bufferData->length - 1)
833 {
834 content[i * 3 + 2] = ',';
835 }
836 }
837 content[len] = '\0';
838 *dest = REF(temp);
839 return 0;
840 }
841
842 LOG_ERR("cannot convert '%s' to String\n", aml_type_to_string(src->type));
843 errno = EILSEQ;
844 return ERR;
845}
846
848{
849 (void)state;
850
851 if (src == NULL || dest == NULL)
852 {
853 LOG_ERR("src/dest object is NULL\n");
854 errno = EINVAL;
855 return ERR;
856 }
857
858 if (src->type == AML_UNINITIALIZED)
859 {
860 LOG_ERR("src object is uninitialized\n");
861 errno = EINVAL;
862 return ERR;
863 }
864
865 if (src->type == AML_INTEGER)
866 {
867 *dest = REF(src);
868 return 0;
869 }
870
872 if (temp == NULL)
873 {
874 return ERR;
875 }
876 DEREF_DEFER(temp);
877
878 if (src->type == AML_STRING)
879 {
880 aml_string_obj_t* stringData = &src->string;
881 if (stringData->length == 0 || stringData->content == NULL)
882 {
883 errno = EILSEQ;
884 return ERR;
885 }
886
887 // Determine if hex (0x prefix) or decimal
888 bool isHex = false;
889 uint64_t i = 0;
890 if (stringData->length > 2 && stringData->content[0] == '0' &&
891 (stringData->content[1] == 'x' || stringData->content[1] == 'X'))
892 {
893 isHex = true;
894 i = 2;
895 }
896
897 // "If the value exceeds the maximum, the result is unpredictable" - ACPI Spec
898 aml_integer_t value = 0;
899 for (; i < stringData->length; i++)
900 {
901 char chr = stringData->content[i];
902
903 if (isHex)
904 {
905 uint8_t digit = aml_hex_to_byte(chr);
906 if (digit == 16) // Stop at first non-hex character
907 {
908 break;
909 }
910 value = value * 16 + digit;
911 }
912 else
913 {
914 if (chr >= '0' && chr <= '9')
915 {
916 value = value * 10 + (chr - '0');
917 }
918 else
919 {
920 break;
921 }
922 }
923 }
924
925 if (aml_integer_set(temp, value) == ERR)
926 {
927 return ERR;
928 }
929 *dest = REF(temp);
930 return 0;
931 }
932 else if (src->type == AML_BUFFER)
933 {
934 if (aml_buffer_to_integer(state, src, temp) == ERR)
935 {
936 return ERR;
937 }
938 *dest = REF(temp);
939 return 0;
940 }
941
942 LOG_ERR("cannot convert '%s' to Integer\n", aml_type_to_string(src->type));
943 errno = EILSEQ;
944 return ERR;
945}
946
948{
949 if (out == NULL)
950 {
951 errno = EINVAL;
952 return ERR;
953 }
954
955 aml_integer_t bcd = 0;
956 for (uint64_t i = 0; i < aml_integer_byte_size() * 2; i++) // 2 nibbles per byte
957 {
958 uint8_t digit = value % 10;
959 bcd |= ((aml_integer_t)digit) << (i * 4);
960 value /= 10;
961 if (value == 0)
962 break;
963 }
964
965 *out = bcd;
966 return 0;
967}
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
uint64_t aml_buffer_field_load(aml_buffer_field_obj_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_buffer_field_store(aml_buffer_field_obj_t *bufferField, aml_object_t *in)
Write a value to a BufferField.
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:651
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_integer_to_bcd(aml_integer_t value, aml_integer_t *out)
Converts an integer to its Binary-Coded Decimal (BCD) representation.
Definition convert.c:947
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:598
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:757
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:541
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:847
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_obj_t *fieldUnit, aml_object_t *out)
Read the value stored in a FieldUnit. FieldUnits include Fields, IndexFields and BankFields.
Definition field_unit.c:604
uint64_t aml_field_unit_store(aml_state_t *state, aml_field_unit_obj_t *fieldUnit, aml_object_t *in)
Write a value to a FieldUnit. FieldUnits include Fields, IndexFields and BankFields.
Definition field_unit.c:631
uint64_t aml_integer_t
AML Integer type.
Definition integer.h:20
uint8_t aml_integer_byte_size(void) PURE_FUNC
Get the byte size of an AML integer.
Definition integer.c:22
uint64_t aml_string_resize(aml_string_obj_t *string, uint64_t newLength)
Resize a string object to the new length.
Definition object.c:1005
aml_type_t
ACPI data types.
Definition object.h:57
uint64_t aml_integer_set(aml_object_t *object, aml_integer_t value)
Set a object as an integer with the given value and bit width.
Definition object.c:708
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
Definition object.c:54
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:487
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:955
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:520
@ AML_BUFFER_FIELD
Definition object.h:60
@ AML_PACKAGE
Definition object.h:79
@ AML_TYPE_AMOUNT
Not a type, just the amount of types.
Definition object.h:115
@ AML_DEBUG_OBJECT
Definition object.h:61
@ AML_STRING
Definition object.h:83
@ AML_ARG
Not in the spec, used internally to represent method arguments.
Definition object.h:88
@ AML_FIELD_UNIT
Definition object.h:64
@ AML_DATA_REF_OBJECTS
Definition object.h:103
@ AML_LOCAL
Not in the spec, used internally to represent method local variables.
Definition object.h:89
@ AML_INTEGER
Definition object.h:65
@ AML_UNINITIALIZED
Definition object.h:58
@ AML_BUFFER
Definition object.h:59
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 LOG_INFO(format,...)
Definition log.h:87
#define DEREF_DEFER(ptr)
RAII-style cleanup for scoped references.
Definition ref.h:54
#define REF(ptr)
Increment reference count.
Definition ref.h:65
#define DEREF(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
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:4
aml_object_t * value
The object that was passed as the argument.
Definition object.h:407
Data for a buffer object.
Definition object.h:211
uint64_t length
Definition object.h:214
uint8_t * content
Definition object.h:213
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:264
aml_integer_t value
Definition object.h:266
aml_object_t * value
The value of the local variable.
Definition object.h:417
ACPI object.
Definition object.h:425
aml_buffer_obj_t buffer
Definition object.h:431
aml_buffer_field_obj_t bufferField
Definition object.h:432
aml_local_obj_t local
Definition object.h:449
aml_integer_obj_t integer
Definition object.h:435
aml_field_unit_obj_t fieldUnit
Definition object.h:434
aml_package_obj_t package
Definition object.h:441
aml_string_obj_t string
Definition object.h:444
aml_arg_obj_t arg
Definition object.h:448
uint64_t length
Definition object.h:340
aml_object_t ** elements
Definition object.h:339
AML State.
Definition state.h:25
Data for a string object.
Definition object.h:368
char * content
Definition object.h:370
uint64_t length
Definition object.h:371