PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
expression.c
Go to the documentation of this file.
2
3#include <kernel/log/log.h>
22
23#include <sys/proc.h>
24
26{
27 aml_object_t* result = aml_term_arg_read(ctx, allowedTypes);
28 if (result == NULL)
29 {
30 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
31 return NULL;
32 }
33
34 return result; // Transfer ownership
35}
36
38 aml_type_t allowedTypes, aml_object_t** operand1, aml_object_t** operand2, aml_object_t** target)
39{
40 if (aml_token_expect(ctx, expectedOp) == ERR)
41 {
42 AML_DEBUG_ERROR(ctx, "Failed to read %s", aml_token_lookup(expectedOp)->name);
43 return ERR;
44 }
45
46 *operand1 = aml_operand_read(ctx, allowedTypes);
47 if (*operand1 == NULL)
48 {
49 AML_DEBUG_ERROR(ctx, "Failed to read operand1");
50 return ERR;
51 }
52
53 // Operand2 must be the same type as operand1.
54 *operand2 = aml_operand_read(ctx, (*operand1)->type);
55 if (*operand2 == NULL)
56 {
57 UNREF(*operand1);
58 AML_DEBUG_ERROR(ctx, "Failed to read operand2");
59 return ERR;
60 }
61
62 if (aml_target_read_and_resolve(ctx, target) == ERR)
63 {
64 UNREF(*operand1);
65 UNREF(*operand2);
66 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
67 return ERR;
68 }
69
70 return 0;
71}
72
74 aml_type_t allowedTypes, aml_object_t** operand1, aml_object_t** operand2)
75{
76 if (aml_token_expect(ctx, expectedOp) == ERR)
77 {
78 AML_DEBUG_ERROR(ctx, "Failed to read %s", aml_token_lookup(expectedOp)->name);
79 return ERR;
80 }
81
82 *operand1 = aml_operand_read(ctx, allowedTypes);
83 if (*operand1 == NULL)
84 {
85 AML_DEBUG_ERROR(ctx, "Failed to read operand1");
86 return ERR;
87 }
88
89 // Operand2 must be the same type as operand1.
90 *operand2 = aml_operand_read(ctx, (*operand1)->type);
91 if (*operand2 == NULL)
92 {
93 UNREF(*operand1);
94 AML_DEBUG_ERROR(ctx, "Failed to read operand2");
95 return ERR;
96 }
97
98 return 0;
99}
100
102 aml_type_t allowedTypes, aml_object_t** operand)
103{
104 if (aml_token_expect(ctx, expectedOp) == ERR)
105 {
106 AML_DEBUG_ERROR(ctx, "Failed to read %s", aml_token_lookup(expectedOp)->name);
107 return ERR;
108 }
109
110 *operand = aml_operand_read(ctx, allowedTypes);
111 if (*operand == NULL)
112 {
113 AML_DEBUG_ERROR(ctx, "Failed to read operand");
114 return ERR;
115 }
116
117 return 0;
118}
119
121 aml_type_t allowedTypes, aml_object_t** operand, aml_object_t** target)
122{
123 if (aml_token_expect(ctx, expectedOp) == ERR)
124 {
125 AML_DEBUG_ERROR(ctx, "Failed to read %s", aml_token_lookup(expectedOp)->name);
126 return ERR;
127 }
128
129 *operand = aml_operand_read(ctx, allowedTypes);
130 if (*operand == NULL)
131 {
132 AML_DEBUG_ERROR(ctx, "Failed to read operand");
133 return ERR;
134 }
135
136 if (aml_target_read_and_resolve(ctx, target) == ERR)
137 {
138 UNREF(*operand);
139 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
140 return ERR;
141 }
142
143 return 0;
144}
145
147 aml_type_t allowedTypes, aml_object_t** operand, aml_uint_t* shiftCount, aml_object_t** target)
148{
149 if (aml_token_expect(ctx, expectedOp) == ERR)
150 {
151 AML_DEBUG_ERROR(ctx, "Failed to read %s", aml_token_lookup(expectedOp)->name);
152 return ERR;
153 }
154
155 *operand = aml_operand_read(ctx, allowedTypes);
156 if (*operand == NULL)
157 {
158 AML_DEBUG_ERROR(ctx, "Failed to read operand");
159 return ERR;
160 }
161
162 if (aml_shift_count_read(ctx, shiftCount) == ERR)
163 {
164 UNREF(*operand);
165 AML_DEBUG_ERROR(ctx, "Failed to read ShiftCount");
166 return ERR;
167 }
168
169 if (aml_target_read_and_resolve(ctx, target) == ERR)
170 {
171 UNREF(*operand);
172 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
173 return ERR;
174 }
175
176 return 0;
177}
178
180 aml_object_t** data1, aml_object_t** data2, aml_object_t** target)
181{
182 if (aml_token_expect(ctx, expectedOp) == ERR)
183 {
184 AML_DEBUG_ERROR(ctx, "Failed to read %s", aml_token_lookup(expectedOp)->name);
185 return ERR;
186 }
187
188 *data1 = aml_data_read(ctx);
189 if (*data1 == NULL)
190 {
191 AML_DEBUG_ERROR(ctx, "Failed to read data1");
192 return ERR;
193 }
194
195 *data2 = aml_data_read(ctx);
196 if (*data2 == NULL)
197 {
198 UNREF(*data1);
199 AML_DEBUG_ERROR(ctx, "Failed to read data2");
200 return ERR;
201 }
202
203 if (aml_target_read_and_resolve(ctx, target) == ERR)
204 {
205 UNREF(*data1);
206 UNREF(*data2);
207 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
208 return ERR;
209 }
210
211 return 0;
212}
213
215 aml_type_t allowedTypes, aml_object_t** termarg, aml_object_t** simplename)
216{
217 if (aml_token_expect(ctx, expectedOp) == ERR)
218 {
219 AML_DEBUG_ERROR(ctx, "Failed to read %s", aml_token_lookup(expectedOp)->name);
220 return ERR;
221 }
222
223 *termarg = aml_term_arg_read(ctx, allowedTypes);
224 if (*termarg == NULL)
225 {
226 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
227 return ERR;
228 }
229
230 *simplename = aml_simple_name_read_and_resolve(ctx);
231 if (*simplename == NULL)
232 {
233 UNREF(*termarg);
234 AML_DEBUG_ERROR(ctx, "Failed to read or resolve SimpleName");
235 return ERR;
236 }
237
238 return 0;
239}
240
242 aml_object_t** supername)
243{
244 if (aml_token_expect(ctx, expectedOp) == ERR)
245 {
246 AML_DEBUG_ERROR(ctx, "Failed to read %s", aml_token_lookup(expectedOp)->name);
247 return ERR;
248 }
249
250 *supername = aml_super_name_read_and_resolve(ctx);
251 if (*supername == NULL)
252 {
253 AML_DEBUG_ERROR(ctx, "Failed to read or resolve SuperName");
254 return ERR;
255 }
256
257 return 0;
258}
259
261 aml_type_t allowedTypes, aml_object_t** termarg, aml_object_t** supername)
262{
263 if (aml_token_expect(ctx, expectedOp) == ERR)
264 {
265 AML_DEBUG_ERROR(ctx, "Failed to read %s", aml_token_lookup(expectedOp)->name);
266 return ERR;
267 }
268
269 *termarg = aml_term_arg_read(ctx, allowedTypes);
270 if (*termarg == NULL)
271 {
272 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
273 return ERR;
274 }
275
276 *supername = aml_super_name_read_and_resolve(ctx);
277 if (*supername == NULL)
278 {
279 UNREF(*termarg);
280 AML_DEBUG_ERROR(ctx, "Failed to read or resolve SuperName");
281 return ERR;
282 }
283
284 return 0;
285}
286
288{
289 if (aml_term_arg_read_integer(ctx, out) == ERR)
290 {
291 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
292 return ERR;
293 }
294 return 0;
295}
296
298{
300 {
301 AML_DEBUG_ERROR(ctx, "Failed to read BufferOp");
302 return ERR;
303 }
304
305 const uint8_t* start = ctx->current;
306
307 aml_pkg_length_t pkgLength;
308 if (aml_pkg_length_read(ctx, &pkgLength) == ERR)
309 {
310 AML_DEBUG_ERROR(ctx, "Failed to read PkgLength");
311 return ERR;
312 }
313
314 const uint8_t* end = start + pkgLength;
315
316 aml_uint_t bufferSize;
317 if (aml_buffer_size_read(ctx, &bufferSize) == ERR)
318 {
319 AML_DEBUG_ERROR(ctx, "Failed to read BufferSize");
320 return ERR;
321 }
322
323 uint64_t availableBytes = (uint64_t)(end - ctx->current);
324
325 if (aml_buffer_set(out, ctx->current, availableBytes, bufferSize) == ERR)
326 {
327 return ERR;
328 }
329
330 ctx->current = end;
331 return 0;
332}
333
335{
336 if (argCount > AML_MAX_ARGS)
337 {
338 errno = EILSEQ;
339 return ERR;
340 }
341
342 uint64_t i = 0;
343 for (; i < argCount; i++)
344 {
346 if (out->args[i] == NULL)
347 {
348 for (uint64_t j = 0; j < i; j++)
349 {
350 UNREF(out->args[j]);
351 out->args[j] = NULL;
352 }
353 return ERR;
354 }
355 }
356 out->args[i] = NULL;
357
358 return 0;
359}
360
362{
364 if (target == NULL)
365 {
366 AML_DEBUG_ERROR(ctx, "Failed to read or resolve NameString");
367 return NULL;
368 }
369 UNREF_DEFER(target);
370
371 if (target->type == AML_METHOD)
372 {
373 aml_term_arg_list_t args = {0};
374 if (aml_term_arg_list_read(ctx, target->method.methodFlags.argCount, &args) == ERR)
375 {
376 AML_DEBUG_ERROR(ctx, "Failed to read method arguments");
377 return NULL;
378 }
379
380 aml_object_t* result = aml_method_invoke(ctx->state, &target->method, args.args);
381 if (result == NULL)
382 {
383 for (uint8_t i = 0; args.args[i] != NULL; i++)
384 {
385 UNREF(args.args[i]);
386 args.args[i] = NULL;
387 }
388 AML_DEBUG_ERROR(ctx, "Failed to evaluate method '%s'", AML_NAME_TO_STRING(target->name));
389 return NULL;
390 }
391
392 for (uint8_t i = 0; args.args[i] != NULL; i++)
393 {
394 UNREF(args.args[i]);
395 args.args[i] = NULL;
396 }
397
398 aml_state_result_set(ctx->state, result);
399
400 return result; // Transfer ownership
401 }
402
403 // Note that just resolving an object does not set the implicit return value.
404 return REF(target);
405}
406
408{
410 {
411 AML_DEBUG_ERROR(ctx, "Failed to read CondRefOfOp");
412 return NULL;
413 }
414
416 if (source == NULL)
417 {
418 AML_DEBUG_ERROR(ctx, "Failed to read or resolve SuperName");
419 return NULL;
420 }
422
423 aml_object_t* result = NULL;
424 if (aml_target_read_and_resolve(ctx, &result) == ERR)
425 {
426 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
427 return NULL;
428 }
429 UNREF_DEFER(result);
430
431 aml_object_t* output = aml_object_new();
432 if (output == NULL)
433 {
434 return NULL;
435 }
436 UNREF_DEFER(output);
437
438 if (source == NULL)
439 {
440 // Return false since the source did not resolve to an object.
441 if (aml_integer_set(output, 0) == ERR)
442 {
443 AML_DEBUG_ERROR(ctx, "Failed to init false integer");
444 return NULL;
445 }
446 return REF(output);
447 }
448
449 if (result == NULL)
450 {
451 // Return true since source resolved to an object and result dident so we dont need to store anything.
452 if (aml_integer_set(output, AML_TRUE) == ERR)
453 {
454 AML_DEBUG_ERROR(ctx, "Failed to init true integer");
455 return NULL;
456 }
457 return REF(output);
458 }
459
460 // Store a reference to source in the result and return true.
461
462 if (aml_object_reference_set(result, source) == ERR)
463 {
464 AML_DEBUG_ERROR(ctx, "Failed to init ObjectReference in result");
465 return NULL;
466 }
467
468 if (aml_integer_set(output, AML_TRUE) == ERR)
469 {
470 AML_DEBUG_ERROR(ctx, "Failed to init true integer");
471 return NULL;
472 }
473
474 return REF(output);
475}
476
478{
480 aml_object_t* destination = NULL;
482 {
483 AML_DEBUG_ERROR(ctx, "Failed to read DefStore structure");
484 return NULL;
485 }
487 UNREF_DEFER(destination);
488
489 if (aml_store(ctx->state, source, destination) == ERR)
490 {
491 AML_DEBUG_ERROR(ctx, "Failed to store source '%s' in destination '%s'", AML_NAME_TO_STRING(source->name),
492 AML_NAME_TO_STRING(destination->name));
493 return NULL;
494 }
495
496 return REF(source);
497}
498
500{
501 if (aml_term_arg_read_integer(ctx, out) == ERR)
502 {
503 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
504 return ERR;
505 }
506
507 return 0;
508}
509
511{
512 if (aml_term_arg_read_integer(ctx, out) == ERR)
513 {
514 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
515 return ERR;
516 }
517
518 return 0;
519}
520
522{
523 aml_object_t* result = NULL;
524 if (aml_target_read_and_resolve(ctx, &result) == ERR)
525 {
526 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
527 return NULL;
528 }
529
530 return result; // Transfer ownership
531}
532
534{
535 aml_object_t* result = NULL;
536 if (aml_target_read_and_resolve(ctx, &result) == ERR)
537 {
538 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
539 return NULL;
540 }
541
542 return result; // Transfer ownership
543}
544
546{
547 aml_object_t* operand1 = NULL;
548 aml_object_t* operand2 = NULL;
549 aml_object_t* target = NULL;
550 if (aml_op_operand_operand_target_read(ctx, AML_ADD_OP, AML_INTEGER, &operand1, &operand2, &target) == ERR)
551 {
552 AML_DEBUG_ERROR(ctx, "Failed to read DefAdd structure");
553 return NULL;
554 }
555 UNREF_DEFER(operand1);
556 UNREF_DEFER(operand2);
557 UNREF_DEFER(target);
558
559 aml_object_t* result = aml_object_new();
560 if (result == NULL)
561 {
562 return NULL;
563 }
564 UNREF_DEFER(result);
565
566 if (aml_integer_set(result, operand1->integer.value + operand2->integer.value) ||
567 aml_store(ctx->state, result, target) == ERR)
568 {
569 return NULL;
570 }
571
572 return REF(result);
573}
574
576{
577 aml_object_t* operand1 = NULL;
578 aml_object_t* operand2 = NULL;
579 aml_object_t* target = NULL;
580 if (aml_op_operand_operand_target_read(ctx, AML_SUBTRACT_OP, AML_INTEGER, &operand1, &operand2, &target) == ERR)
581 {
582 AML_DEBUG_ERROR(ctx, "Failed to read DefSubtract structure");
583 return NULL;
584 }
585 UNREF_DEFER(operand1);
586 UNREF_DEFER(operand2);
587 UNREF_DEFER(target);
588
589 aml_object_t* result = aml_object_new();
590 if (result == NULL)
591 {
592 return NULL;
593 }
594 UNREF_DEFER(result);
595
596 if (aml_integer_set(result, operand1->integer.value - operand2->integer.value) ||
597 aml_store(ctx->state, result, target) == ERR)
598 {
599 return NULL;
600 }
601
602 return REF(result);
603}
604
606{
607 aml_object_t* operand1 = NULL;
608 aml_object_t* operand2 = NULL;
609 aml_object_t* target = NULL;
610 if (aml_op_operand_operand_target_read(ctx, AML_MULTIPLY_OP, AML_INTEGER, &operand1, &operand2, &target) == ERR)
611 {
612 AML_DEBUG_ERROR(ctx, "Failed to read DefMultiply structure");
613 return NULL;
614 }
615 UNREF_DEFER(operand1);
616 UNREF_DEFER(operand2);
617 UNREF_DEFER(target);
618
619 aml_object_t* result = aml_object_new();
620 if (result == NULL)
621 {
622 return NULL;
623 }
624 UNREF_DEFER(result);
625
626 if (aml_integer_set(result, operand1->integer.value * operand2->integer.value) ||
627 aml_store(ctx->state, result, target) == ERR)
628 {
629 return NULL;
630 }
631
632 return REF(result);
633}
634
636{
638 {
639 AML_DEBUG_ERROR(ctx, "Failed to read DivideOp");
640 return NULL;
641 }
642
643 aml_uint_t dividend;
644 if (aml_dividend_read(ctx, &dividend) == ERR)
645 {
646 AML_DEBUG_ERROR(ctx, "Failed to read Dividend");
647 return NULL;
648 }
649
650 aml_uint_t divisor;
651 if (aml_divisor_read(ctx, &divisor) == ERR)
652 {
653 AML_DEBUG_ERROR(ctx, "Failed to read Divisor");
654 return NULL;
655 }
656
657 if (divisor == 0)
658 {
659 divisor = 1;
660 }
661
662 aml_object_t* remainderDest = aml_remainder_read(ctx);
663 if (remainderDest == NULL)
664 {
665 AML_DEBUG_ERROR(ctx, "Failed to read remainder");
666 return NULL;
667 }
668 UNREF_DEFER(remainderDest);
669
670 aml_object_t* quotientDest = aml_quotient_read(ctx);
671 if (quotientDest == NULL)
672 {
673 AML_DEBUG_ERROR(ctx, "Failed to read quotient");
674 return NULL;
675 }
676 UNREF_DEFER(quotientDest);
677
678 aml_object_t* result = aml_object_new();
679 if (result == NULL)
680 {
681 return NULL;
682 }
683 UNREF_DEFER(result);
684
685 // Init with remainder.
686 if (aml_integer_set(result, dividend % divisor) == ERR || aml_store(ctx->state, result, remainderDest))
687 {
688 AML_DEBUG_ERROR(ctx, "Failed to store remainder");
689 return NULL;
690 }
691
692 // Init with quotient.
693 if (aml_integer_set(result, dividend / divisor) == ERR || aml_store(ctx->state, result, quotientDest))
694 {
695 AML_DEBUG_ERROR(ctx, "Failed to store quotient");
696 return NULL;
697 }
698
699 // Qoutient stays in result.
700 return REF(result);
701}
702
704{
705 if (aml_token_expect(ctx, AML_MOD_OP) == ERR)
706 {
707 AML_DEBUG_ERROR(ctx, "Failed to read ModOp");
708 return NULL;
709 }
710
711 aml_uint_t dividend;
712 if (aml_dividend_read(ctx, &dividend) == ERR)
713 {
714 AML_DEBUG_ERROR(ctx, "Failed to read Dividend");
715 return NULL;
716 }
717
718 aml_uint_t divisor;
719 if (aml_divisor_read(ctx, &divisor) == ERR)
720 {
721 AML_DEBUG_ERROR(ctx, "Failed to read Divisor");
722 return NULL;
723 }
724
725 aml_object_t* target = NULL;
726 if (aml_target_read_and_resolve(ctx, &target) == ERR)
727 {
728 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
729 return NULL;
730 }
731 UNREF_DEFER(target);
732
733 if (divisor == 0)
734 {
735 divisor = 1;
736 }
737
738 aml_object_t* result = aml_object_new();
739 if (result == NULL)
740 {
741 return NULL;
742 }
743 UNREF_DEFER(result);
744
745 if (aml_integer_set(result, dividend % divisor) == ERR || aml_store(ctx->state, result, target) == ERR)
746 {
747 return NULL;
748 }
749
750 return REF(result);
751}
752
754{
755 aml_object_t* operand1 = NULL;
756 aml_object_t* operand2 = NULL;
757 aml_object_t* target = NULL;
758 if (aml_op_operand_operand_target_read(ctx, AML_AND_OP, AML_INTEGER, &operand1, &operand2, &target) == ERR)
759 {
760 AML_DEBUG_ERROR(ctx, "Failed to read DefAnd structure");
761 return NULL;
762 }
763 UNREF_DEFER(operand1);
764 UNREF_DEFER(operand2);
765 UNREF_DEFER(target);
766
767 aml_object_t* result = aml_object_new();
768 if (result == NULL)
769 {
770 return NULL;
771 }
772 UNREF_DEFER(result);
773
774 if (aml_integer_set(result, operand1->integer.value & operand2->integer.value) ||
775 aml_store(ctx->state, result, target) == ERR)
776 {
777 return NULL;
778 }
779
780 return REF(result);
781}
782
784{
785 aml_object_t* operand1 = NULL;
786 aml_object_t* operand2 = NULL;
787 aml_object_t* target = NULL;
788 if (aml_op_operand_operand_target_read(ctx, AML_NAND_OP, AML_INTEGER, &operand1, &operand2, &target) == ERR)
789 {
790 AML_DEBUG_ERROR(ctx, "Failed to read DefNand structure");
791 return NULL;
792 }
793 UNREF_DEFER(operand1);
794 UNREF_DEFER(operand2);
795 UNREF_DEFER(target);
796
797 aml_object_t* result = aml_object_new();
798 if (result == NULL)
799 {
800 return NULL;
801 }
802 UNREF_DEFER(result);
803
804 if (aml_integer_set(result, ~(operand1->integer.value & operand2->integer.value)) ||
805 aml_store(ctx->state, result, target) == ERR)
806 {
807 return NULL;
808 }
809
810 return REF(result);
811}
812
814{
815 aml_object_t* operand1 = NULL;
816 aml_object_t* operand2 = NULL;
817 aml_object_t* target = NULL;
818 if (aml_op_operand_operand_target_read(ctx, AML_OR_OP, AML_INTEGER, &operand1, &operand2, &target) == ERR)
819 {
820 AML_DEBUG_ERROR(ctx, "Failed to read DefOr structure");
821 return NULL;
822 }
823 UNREF_DEFER(operand1);
824 UNREF_DEFER(operand2);
825 UNREF_DEFER(target);
826
827 aml_object_t* result = aml_object_new();
828 if (result == NULL)
829 {
830 return NULL;
831 }
832 UNREF_DEFER(result);
833
834 if (aml_integer_set(result, operand1->integer.value | operand2->integer.value) ||
835 aml_store(ctx->state, result, target) == ERR)
836 {
837 return NULL;
838 }
839
840 return REF(result);
841}
842
844{
845 aml_object_t* operand1 = NULL;
846 aml_object_t* operand2 = NULL;
847 aml_object_t* target = NULL;
848 if (aml_op_operand_operand_target_read(ctx, AML_NOR_OP, AML_INTEGER, &operand1, &operand2, &target) == ERR)
849 {
850 AML_DEBUG_ERROR(ctx, "Failed to read DefNor structure");
851 return NULL;
852 }
853 UNREF_DEFER(operand1);
854 UNREF_DEFER(operand2);
855 UNREF_DEFER(target);
856
857 aml_object_t* result = aml_object_new();
858 if (result == NULL)
859 {
860 return NULL;
861 }
862 UNREF_DEFER(result);
863
864 if (aml_integer_set(result, ~(operand1->integer.value | operand2->integer.value)) ||
865 aml_store(ctx->state, result, target) == ERR)
866 {
867 return NULL;
868 }
869
870 return REF(result);
871}
872
874{
875 aml_object_t* operand1 = NULL;
876 aml_object_t* operand2 = NULL;
877 aml_object_t* target = NULL;
878 if (aml_op_operand_operand_target_read(ctx, AML_XOR_OP, AML_INTEGER, &operand1, &operand2, &target) == ERR)
879 {
880 AML_DEBUG_ERROR(ctx, "Failed to read DefXor structure");
881 return NULL;
882 }
883 UNREF_DEFER(operand1);
884 UNREF_DEFER(operand2);
885 UNREF_DEFER(target);
886
887 aml_object_t* result = aml_object_new();
888 if (result == NULL)
889 {
890 return NULL;
891 }
892 UNREF_DEFER(result);
893
894 if (aml_integer_set(result, operand1->integer.value ^ operand2->integer.value) ||
895 aml_store(ctx->state, result, target) == ERR)
896 {
897 return NULL;
898 }
899
900 return REF(result);
901}
902
904{
905 aml_object_t* operand = NULL;
906 aml_object_t* target = NULL;
907 if (aml_op_operand_target_read(ctx, AML_NOT_OP, AML_INTEGER, &operand, &target) == ERR)
908 {
909 AML_DEBUG_ERROR(ctx, "Failed to read DefNot structure");
910 return NULL;
911 }
912 UNREF_DEFER(operand);
913 UNREF_DEFER(target);
914
915 aml_object_t* result = aml_object_new();
916 if (result == NULL)
917 {
918 return NULL;
919 }
920 UNREF_DEFER(result);
921
922 if (aml_integer_set(result, ~operand->integer.value) || aml_store(ctx->state, result, target) == ERR)
923 {
924 return NULL;
925 }
926
927 return REF(result);
928}
929
931{
932 if (aml_term_arg_read_integer(ctx, out) == ERR)
933 {
934 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
935 return ERR;
936 }
937
938 return 0;
939}
940
942{
943 aml_object_t* operand = NULL;
944 aml_object_t* target = NULL;
945 aml_uint_t shiftCount;
946 if (aml_op_operand_shiftcount_target_read(ctx, AML_SHIFT_LEFT_OP, AML_INTEGER, &operand, &shiftCount, &target) ==
947 ERR)
948 {
949 AML_DEBUG_ERROR(ctx, "Failed to read DefShiftLeft structure");
950 return NULL;
951 }
952 UNREF_DEFER(operand);
953 UNREF_DEFER(target);
954
955 aml_object_t* result = aml_object_new();
956 if (result == NULL)
957 {
958 return NULL;
959 }
960 UNREF_DEFER(result);
961
962 // C will discard the most significant bits
963 if (shiftCount >= aml_integer_bit_size())
964 {
965 if (aml_integer_set(result, 0) == ERR)
966 {
967 return NULL;
968 }
969 }
970 else
971 {
972 aml_uint_t operandValue = operand->integer.value;
973 if (aml_integer_set(result, operandValue << shiftCount) == ERR)
974 {
975 return NULL;
976 }
977 }
978
979 if (aml_store(ctx->state, result, target) == ERR)
980 {
981 return NULL;
982 }
983
984 return REF(result);
985}
986
988{
989 aml_object_t* operand = NULL;
990 aml_object_t* target = NULL;
991 aml_uint_t shiftCount;
992 if (aml_op_operand_shiftcount_target_read(ctx, AML_SHIFT_RIGHT_OP, AML_INTEGER, &operand, &shiftCount, &target) ==
993 ERR)
994 {
995 AML_DEBUG_ERROR(ctx, "Failed to read DefShiftRight structure");
996 return NULL;
997 }
998 UNREF_DEFER(operand);
999 UNREF_DEFER(target);
1000
1001 aml_object_t* result = aml_object_new();
1002 if (result == NULL)
1003 {
1004 return NULL;
1005 }
1006 UNREF_DEFER(result);
1007
1008 // C will zero the most significant bits
1009 if (shiftCount >= aml_integer_bit_size())
1010 {
1011 if (aml_integer_set(result, 0) == ERR)
1012 {
1013 return NULL;
1014 }
1015 }
1016 else
1017 {
1018 aml_uint_t operandValue = operand->integer.value;
1019 if (aml_integer_set(result, operandValue >> shiftCount) == ERR)
1020 {
1021 return NULL;
1022 }
1023 }
1024
1025 if (aml_store(ctx->state, result, target) == ERR)
1026 {
1027 return NULL;
1028 }
1029
1030 return REF(result);
1031}
1032
1034{
1035 aml_object_t* superName = NULL;
1036 if (aml_op_supername_read(ctx, AML_INCREMENT_OP, &superName) == ERR)
1037 {
1038 AML_DEBUG_ERROR(ctx, "Failed to read DefIncrement structure");
1039 return NULL;
1040 }
1041 UNREF_DEFER(superName);
1042
1044 if (aml_convert_source(ctx->state, superName, &source, AML_INTEGER) == ERR)
1045 {
1046 return NULL;
1047 }
1049
1050 aml_object_t* result = aml_object_new();
1051 if (result == NULL)
1052 {
1053 return NULL;
1054 }
1055 UNREF_DEFER(result);
1056
1057 if (aml_integer_set(result, source->integer.value + 1) == ERR ||
1058 aml_convert_result(ctx->state, result, superName) == ERR)
1059 {
1060 return NULL;
1061 }
1062
1063 return REF(result);
1064}
1065
1067{
1068 aml_object_t* superName = NULL;
1069 if (aml_op_supername_read(ctx, AML_DECREMENT_OP, &superName) == ERR)
1070 {
1071 AML_DEBUG_ERROR(ctx, "Failed to read DefDecrement structure");
1072 return NULL;
1073 }
1074 UNREF_DEFER(superName);
1075
1077 if (aml_convert_source(ctx->state, superName, &source, AML_INTEGER) == ERR)
1078 {
1079 return NULL;
1080 }
1082
1083 aml_object_t* result = aml_object_new();
1084 if (result == NULL)
1085 {
1086 return NULL;
1087 }
1088 UNREF_DEFER(result);
1089
1090 if (aml_integer_set(result, source->integer.value - 1) == ERR ||
1091 aml_convert_result(ctx->state, result, superName) == ERR)
1092 {
1093 return NULL;
1094 }
1095
1096 return REF(result);
1097}
1098
1100{
1102 if (termArg == NULL)
1103 {
1104 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
1105 return NULL;
1106 }
1107 UNREF_DEFER(termArg);
1108
1109 if (termArg->type == AML_OBJECT_REFERENCE)
1110 {
1111 return REF(termArg->objectReference.target);
1112 }
1113 else if (termArg->type == AML_STRING)
1114 {
1115 aml_object_t* target = aml_namespace_find_by_path(&ctx->state->overlay, ctx->scope, termArg->string.content);
1116 if (target == NULL)
1117 {
1118 AML_DEBUG_ERROR(ctx, "Failed to find target scope '%s'", termArg->string.content);
1119 errno = EILSEQ;
1120 return NULL;
1121 }
1122
1123 return target; // Transfer ownership
1124 }
1125
1126 // Should never happen.
1127 errno = EILSEQ;
1128 return NULL;
1129}
1130
1132{
1134 {
1135 AML_DEBUG_ERROR(ctx, "Failed to read DerefOfOp");
1136 return NULL;
1137 }
1138
1140 if (obj == NULL)
1141 {
1142 AML_DEBUG_ERROR(ctx, "Failed to read ObjReference");
1143 return NULL;
1144 }
1145
1146 return obj; // Transfer ownership
1147}
1148
1150{
1152 if (result == NULL)
1153 {
1154 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
1155 return NULL;
1156 }
1157
1158 return result; // Transfer ownership
1159}
1160
1162{
1163 if (aml_term_arg_read_integer(ctx, out) == ERR)
1164 {
1165 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
1166 return ERR;
1167 }
1168
1169 return 0;
1170}
1171
1173{
1174 if (aml_token_expect(ctx, AML_INDEX_OP) == ERR)
1175 {
1176 AML_DEBUG_ERROR(ctx, "Failed to read IndexOp");
1177 return NULL;
1178 }
1179
1180 aml_object_t* buffPkgStrObj = aml_buff_pkg_str_obj_read(ctx);
1181 if (buffPkgStrObj == NULL)
1182 {
1183 AML_DEBUG_ERROR(ctx, "Failed to read BuffPkgStrObj");
1184 return NULL;
1185 }
1186 UNREF_DEFER(buffPkgStrObj);
1187
1188 aml_uint_t index;
1189 if (aml_index_value_read(ctx, &index) == ERR)
1190 {
1191 AML_DEBUG_ERROR(ctx, "Failed to read IndexValue");
1192 return NULL;
1193 }
1194
1195 aml_object_t* target = NULL;
1196 if (aml_target_read_and_resolve(ctx, &target) == ERR)
1197 {
1198 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
1199 return NULL;
1200 }
1201 UNREF_DEFER(target);
1202
1203 aml_object_t* result = aml_object_new();
1204 if (result == NULL)
1205 {
1206 return NULL;
1207 }
1208 UNREF_DEFER(result);
1209
1210 switch (buffPkgStrObj->type)
1211 {
1212 case AML_PACKAGE: // Section 19.6.63.1
1213 {
1214 aml_package_t* package = &buffPkgStrObj->package;
1215
1216 if (index >= package->length)
1217 {
1218 AML_DEBUG_ERROR(ctx, "Index out of bounds for package (length %llu, index %llu)", package->length, index);
1219 errno = EILSEQ;
1220 return NULL;
1221 }
1222
1223 if (aml_object_reference_set(result, package->elements[index]) == ERR)
1224 {
1225 return NULL;
1226 }
1227 }
1228 break;
1229 case AML_BUFFER: // Section 19.6.63.2
1230 {
1231 if (index >= buffPkgStrObj->buffer.length)
1232 {
1233 AML_DEBUG_ERROR(ctx, "Index out of bounds for buffer (length %llu, index %llu)",
1234 buffPkgStrObj->buffer.length, index);
1235 errno = EILSEQ;
1236 return NULL;
1237 }
1238
1239 aml_object_t* byteField = aml_object_new();
1240 if (byteField == NULL)
1241 {
1242 return NULL;
1243 }
1244 UNREF_DEFER(byteField);
1245
1246 if (aml_buffer_field_set(byteField, buffPkgStrObj, index * 8, 8) == ERR)
1247 {
1248 return NULL;
1249 }
1250
1251 if (aml_object_reference_set(result, byteField) == ERR)
1252 {
1253 return NULL;
1254 }
1255 }
1256 break;
1257 case AML_STRING: // Section 19.6.63.3
1258 {
1259 if (index >= buffPkgStrObj->string.length)
1260 {
1261 AML_DEBUG_ERROR(ctx, "Index out of bounds for string (length %llu, index %llu)",
1262 buffPkgStrObj->string.length, index);
1263 errno = EILSEQ;
1264 return NULL;
1265 }
1266
1267 aml_object_t* byteField = aml_object_new();
1268 if (byteField == NULL)
1269 {
1270 return NULL;
1271 }
1272 UNREF_DEFER(byteField);
1273
1274 if (aml_buffer_field_set(byteField, buffPkgStrObj, index * 8, 8) == ERR)
1275 {
1276 return NULL;
1277 }
1278
1279 if (aml_object_reference_set(result, byteField) == ERR)
1280 {
1281 return NULL;
1282 }
1283 }
1284 break;
1285 default:
1286 AML_DEBUG_ERROR(ctx, "Invalid type, expected buffer, package or string but got '%s'",
1287 aml_type_to_string(buffPkgStrObj->type));
1288 errno = EILSEQ;
1289 return NULL;
1290 }
1291
1292 if (aml_store(ctx->state, result, target) == ERR)
1293 {
1294 return NULL;
1295 }
1296
1297 return REF(result);
1298}
1299
1301{
1302 aml_object_t* operand1 = NULL;
1303 aml_object_t* operand2 = NULL;
1304 if (aml_op_operand_operand_read(ctx, AML_LAND_OP, AML_INTEGER, &operand1, &operand2) == ERR)
1305 {
1306 AML_DEBUG_ERROR(ctx, "Failed to read DefLand structure");
1307 return NULL;
1308 }
1309 UNREF_DEFER(operand1);
1310 UNREF_DEFER(operand2);
1311
1312 aml_object_t* result = aml_object_new();
1313 if (result == NULL)
1314 {
1315 return NULL;
1316 }
1317 UNREF_DEFER(result);
1318
1319 if (aml_integer_set(result, aml_compare(operand1, operand2, AML_COMPARE_AND)) == ERR)
1320 {
1321 return NULL;
1322 }
1323
1324 return REF(result);
1325}
1326
1328{
1329 aml_object_t* operand1 = NULL;
1330 aml_object_t* operand2 = NULL;
1331 if (aml_op_operand_operand_read(ctx, AML_LEQUAL_OP, AML_INTEGER | AML_STRING | AML_BUFFER, &operand1, &operand2) ==
1332 ERR)
1333 {
1334 AML_DEBUG_ERROR(ctx, "Failed to read DefLequal structure");
1335 return NULL;
1336 }
1337 UNREF_DEFER(operand1);
1338 UNREF_DEFER(operand2);
1339
1340 aml_object_t* result = aml_object_new();
1341 if (result == NULL)
1342 {
1343 return NULL;
1344 }
1345 UNREF_DEFER(result);
1346
1347 if (aml_integer_set(result, aml_compare(operand1, operand2, AML_COMPARE_EQUAL)) == ERR)
1348 {
1349 return NULL;
1350 }
1351
1352 return REF(result);
1353}
1354
1356{
1357 aml_object_t* operand1 = NULL;
1358 aml_object_t* operand2 = NULL;
1360 &operand2) == ERR)
1361 {
1362 AML_DEBUG_ERROR(ctx, "Failed to read DefLgreater structure");
1363 return NULL;
1364 }
1365 UNREF_DEFER(operand1);
1366 UNREF_DEFER(operand2);
1367
1368 aml_object_t* result = aml_object_new();
1369 if (result == NULL)
1370 {
1371 return NULL;
1372 }
1373 UNREF_DEFER(result);
1374
1375 if (aml_integer_set(result, aml_compare(operand1, operand2, AML_COMPARE_GREATER)) == ERR)
1376 {
1377 return NULL;
1378 }
1379
1380 return REF(result);
1381}
1382
1384{
1385 aml_object_t* operand1 = NULL;
1386 aml_object_t* operand2 = NULL;
1388 &operand2) == ERR)
1389 {
1390 AML_DEBUG_ERROR(ctx, "Failed to read DefLgreaterEqual structure");
1391 return NULL;
1392 }
1393 UNREF_DEFER(operand1);
1394 UNREF_DEFER(operand2);
1395
1396 aml_object_t* result = aml_object_new();
1397 if (result == NULL)
1398 {
1399 return NULL;
1400 }
1401 UNREF_DEFER(result);
1402
1403 if (aml_integer_set(result, aml_compare(operand1, operand2, AML_COMPARE_GREATER_EQUAL)) == ERR)
1404 {
1405 return NULL;
1406 }
1407
1408 return REF(result);
1409}
1410
1412{
1413 aml_object_t* operand1 = NULL;
1414 aml_object_t* operand2 = NULL;
1415 if (aml_op_operand_operand_read(ctx, AML_LLESS_OP, AML_INTEGER | AML_STRING | AML_BUFFER, &operand1, &operand2) ==
1416 ERR)
1417 {
1418 AML_DEBUG_ERROR(ctx, "Failed to read DefLless structure");
1419 return NULL;
1420 }
1421 UNREF_DEFER(operand1);
1422 UNREF_DEFER(operand2);
1423
1424 aml_object_t* result = aml_object_new();
1425 if (result == NULL)
1426 {
1427 return NULL;
1428 }
1429 UNREF_DEFER(result);
1430
1431 if (aml_integer_set(result, aml_compare(operand1, operand2, AML_COMPARE_LESS)) == ERR)
1432 {
1433 return NULL;
1434 }
1435
1436 return REF(result);
1437}
1438
1440{
1441 aml_object_t* operand1 = NULL;
1442 aml_object_t* operand2 = NULL;
1444 &operand2) == ERR)
1445 {
1446 AML_DEBUG_ERROR(ctx, "Failed to read DefLlessEqual structure");
1447 return NULL;
1448 }
1449 UNREF_DEFER(operand1);
1450 UNREF_DEFER(operand2);
1451
1452 aml_object_t* result = aml_object_new();
1453 if (result == NULL)
1454 {
1455 return NULL;
1456 }
1457 UNREF_DEFER(result);
1458
1459 if (aml_integer_set(result, aml_compare(operand1, operand2, AML_COMPARE_LESS_EQUAL)) == ERR)
1460 {
1461 return NULL;
1462 }
1463
1464 return REF(result);
1465}
1466
1468{
1469 aml_object_t* operand = NULL;
1470 if (aml_op_operand_read(ctx, AML_LNOT_OP, AML_INTEGER, &operand) == ERR)
1471 {
1472 AML_DEBUG_ERROR(ctx, "Failed to read DefLnot structure");
1473 return NULL;
1474 }
1475 UNREF_DEFER(operand);
1476
1477 aml_object_t* result = aml_object_new();
1478 if (result == NULL)
1479 {
1480 return NULL;
1481 }
1482 UNREF_DEFER(result);
1483
1484 if (aml_integer_set(result, aml_compare_not(operand->integer.value)) == ERR)
1485 {
1486 return NULL;
1487 }
1488
1489 return REF(result);
1490}
1491
1493{
1494 aml_object_t* operand1 = NULL;
1495 aml_object_t* operand2 = NULL;
1497 &operand2) == ERR)
1498 {
1499 AML_DEBUG_ERROR(ctx, "Failed to read DefLnotEqual structure");
1500 return NULL;
1501 }
1502 UNREF_DEFER(operand1);
1503 UNREF_DEFER(operand2);
1504
1505 aml_object_t* result = aml_object_new();
1506 if (result == NULL)
1507 {
1508 return NULL;
1509 }
1510 UNREF_DEFER(result);
1511
1512 if (aml_integer_set(result, aml_compare(operand1, operand2, AML_COMPARE_NOT_EQUAL)) == ERR)
1513 {
1514 return NULL;
1515 }
1516
1517 return REF(result);
1518}
1519
1521{
1522 aml_object_t* operand1 = NULL;
1523 aml_object_t* operand2 = NULL;
1524 if (aml_op_operand_operand_read(ctx, AML_LOR_OP, AML_INTEGER, &operand1, &operand2) == ERR)
1525 {
1526 AML_DEBUG_ERROR(ctx, "Failed to read DefLor structure");
1527 return NULL;
1528 }
1529 UNREF_DEFER(operand1);
1530 UNREF_DEFER(operand2);
1531
1532 aml_object_t* result = aml_object_new();
1533 if (result == NULL)
1534 {
1535 return NULL;
1536 }
1537 UNREF_DEFER(result);
1538
1539 if (aml_integer_set(result, aml_compare(operand1, operand2, AML_COMPARE_OR)) == ERR)
1540 {
1541 return NULL;
1542 }
1543
1544 return REF(result);
1545}
1546
1548{
1550 if (result == NULL)
1551 {
1552 AML_DEBUG_ERROR(ctx, "Failed to read or resolve SuperName");
1553 return NULL;
1554 }
1555 UNREF_DEFER(result);
1556
1557 if (result->type != AML_MUTEX)
1558 {
1559 AML_DEBUG_ERROR(ctx, "Object is not a Mutex");
1560 errno = EILSEQ;
1561 return NULL;
1562 }
1563
1564 return REF(result);
1565}
1566
1568{
1569 if (aml_word_data_read(ctx, out) == ERR)
1570 {
1571 AML_DEBUG_ERROR(ctx, "Failed to read WordData");
1572 return ERR;
1573 }
1574
1575 return 0;
1576}
1577
1579{
1580 if (aml_token_expect(ctx, AML_ACQUIRE_OP) == ERR)
1581 {
1582 AML_DEBUG_ERROR(ctx, "Failed to read AcquireOp");
1583 return NULL;
1584 }
1585
1587 if (mutex == NULL)
1588 {
1589 AML_DEBUG_ERROR(ctx, "Failed to read Mutex");
1590 return NULL;
1591 }
1593
1594 assert(mutex->type == AML_MUTEX);
1595
1596 uint16_t timeout;
1597 if (aml_timeout_read(ctx, &timeout) == ERR)
1598 {
1599 AML_DEBUG_ERROR(ctx, "Failed to read Timeout");
1600 return NULL;
1601 }
1602
1603 clock_t clockTimeout = (timeout == 0xFFFF) ? CLOCKS_NEVER : (clock_t)timeout * (CLOCKS_PER_SEC / 1000);
1604 // If timedout result == 1, else result == 0.
1605 uint64_t acquireResult = aml_mutex_acquire(&mutex->mutex.mutex, mutex->mutex.syncLevel, clockTimeout);
1606 if (acquireResult == ERR)
1607 {
1608 AML_DEBUG_ERROR(ctx, "Failed to acquire mutex");
1609 return NULL;
1610 }
1611
1612 aml_object_t* result = aml_object_new();
1613 if (result == NULL)
1614 {
1615 return NULL;
1616 }
1617 UNREF_DEFER(result);
1618
1619 if (aml_integer_set(result, acquireResult) == ERR)
1620 {
1621 return NULL;
1622 }
1623
1624 return REF(result);
1625}
1626
1628{
1629 aml_object_t* operand = NULL;
1630 aml_object_t* target = NULL;
1631 if (aml_op_operand_target_read(ctx, AML_TO_BCD_OP, AML_INTEGER, &operand, &target) == ERR)
1632 {
1633 AML_DEBUG_ERROR(ctx, "Failed to read DefToBcd structure");
1634 return NULL;
1635 }
1636 UNREF_DEFER(operand);
1637 UNREF_DEFER(target);
1638
1639 aml_object_t* result = aml_object_new();
1640 if (result == NULL)
1641 {
1642 return NULL;
1643 }
1644
1645 aml_uint_t bcd;
1646 if (aml_convert_integer_to_bcd(operand->integer.value, &bcd) == ERR)
1647 {
1648 AML_DEBUG_ERROR(ctx, "Failed to convert integer to BCD");
1649 return NULL;
1650 }
1651
1652 if (aml_integer_set(result, bcd) == ERR || aml_store(ctx->state, result, target) == ERR)
1653 {
1654 UNREF(result);
1655 return NULL;
1656 }
1657
1658 return REF(result);
1659}
1660
1662{
1663 aml_object_t* operand = NULL;
1664 aml_object_t* target = NULL;
1666 ERR)
1667 {
1668 AML_DEBUG_ERROR(ctx, "Failed to read DefToBuffer structure");
1669 return NULL;
1670 }
1671 UNREF_DEFER(operand);
1672 UNREF_DEFER(target);
1673
1674 aml_object_t* result = NULL;
1675 if (aml_convert_to_buffer(ctx->state, operand, &result) == ERR)
1676 {
1677 return NULL;
1678 }
1679
1680 if (aml_store(ctx->state, result, target) == ERR)
1681 {
1682 UNREF(result);
1683 return NULL;
1684 }
1685
1686 return result; // Transfer ownership
1687}
1688
1690{
1691 aml_object_t* operand = NULL;
1692 aml_object_t* target = NULL;
1693 if (aml_op_operand_target_read(ctx, AML_TO_DECIMAL_STRING_OP, AML_INTEGER, &operand, &target) == ERR)
1694 {
1695 AML_DEBUG_ERROR(ctx, "Failed to read DefToDecimalString structure");
1696 return NULL;
1697 }
1698 UNREF_DEFER(operand);
1699 UNREF_DEFER(target);
1700
1701 aml_object_t* result = NULL;
1702 if (aml_convert_to_decimal_string(ctx->state, operand, &result) == ERR)
1703 {
1704 return NULL;
1705 }
1706
1707 if (aml_store(ctx->state, result, target) == ERR)
1708 {
1709 UNREF(result);
1710 return NULL;
1711 }
1712
1713 return result; // Transfer ownership
1714}
1715
1717{
1718 aml_object_t* operand = NULL;
1719 aml_object_t* target = NULL;
1720 if (aml_op_operand_target_read(ctx, AML_TO_HEX_STRING_OP, AML_INTEGER, &operand, &target) == ERR)
1721 {
1722 AML_DEBUG_ERROR(ctx, "Failed to read DefToHexString structure");
1723 return NULL;
1724 }
1725 UNREF_DEFER(operand);
1726 UNREF_DEFER(target);
1727
1728 aml_object_t* result = NULL;
1729 if (aml_convert_to_hex_string(ctx->state, operand, &result) == ERR)
1730 {
1731 return NULL;
1732 }
1733
1734 if (aml_store(ctx->state, result, target) == ERR)
1735 {
1736 UNREF(result);
1737 return NULL;
1738 }
1739
1740 return result; // Transfer ownership
1741}
1742
1744{
1745 aml_object_t* operand = NULL;
1746 aml_object_t* target = NULL;
1748 ERR)
1749 {
1750 AML_DEBUG_ERROR(ctx, "Failed to read DefToInteger structure");
1751 return NULL;
1752 }
1753 UNREF_DEFER(operand);
1754 UNREF_DEFER(target);
1755
1756 aml_object_t* result = NULL;
1757 if (aml_convert_to_integer(ctx->state, operand, &result) == ERR)
1758 {
1759 return NULL;
1760 }
1761
1762 if (aml_store(ctx->state, result, target) == ERR)
1763 {
1764 UNREF(result);
1765 return NULL;
1766 }
1767
1768 return result; // Transfer ownership
1769}
1770
1772{
1773 if (aml_term_arg_read_integer(ctx, out) == ERR)
1774 {
1775 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
1776 return ERR;
1777 }
1778
1779 return 0;
1780}
1781
1783{
1785 {
1786 AML_DEBUG_ERROR(ctx, "Failed to read ToStringOp");
1787 return NULL;
1788 }
1789
1791 if (source == NULL)
1792 {
1793 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
1794 return NULL;
1795 }
1797
1798 aml_uint_t length;
1799 if (aml_length_arg_read(ctx, &length) == ERR)
1800 {
1801 AML_DEBUG_ERROR(ctx, "Failed to read LengthArg");
1802 return NULL;
1803 }
1804
1805 aml_object_t* target = NULL;
1806 if (aml_target_read_and_resolve(ctx, &target) == ERR)
1807 {
1808 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
1809 return NULL;
1810 }
1811 UNREF_DEFER(target);
1812
1813 aml_object_t* result = aml_object_new();
1814 if (result == NULL)
1815 {
1816 return NULL;
1817 }
1818 UNREF_DEFER(result);
1819
1820 length = MIN(length, source->length);
1821 if (aml_string_set_empty(result, length) == ERR)
1822 {
1823 return NULL;
1824 }
1825
1826 for (uint64_t i = 0; i < length; i++)
1827 {
1828 result->string.content[i] = (char)source->content[i];
1829 }
1830
1831 if (aml_store(ctx->state, result, target) == ERR)
1832 {
1833 return NULL;
1834 }
1835
1836 return REF(result);
1837}
1838
1840{
1841 if (aml_token_expect(ctx, AML_TIMER_OP) == ERR)
1842 {
1843 AML_DEBUG_ERROR(ctx, "Failed to read TimerOp");
1844 return NULL;
1845 }
1846
1847 // The period of the timer is supposed to be 100ns.
1848 uint64_t time100ns = clock_uptime() / 100;
1849
1850 aml_object_t* result = aml_object_new();
1851 if (result == NULL)
1852 {
1853 return NULL;
1854 }
1855 UNREF_DEFER(result);
1856
1857 if (aml_integer_set(result, time100ns) == ERR)
1858 {
1859 return NULL;
1860 }
1861
1862 return REF(result);
1863}
1864
1866{
1868 aml_object_t* destination = NULL;
1870 {
1871 AML_DEBUG_ERROR(ctx, "Failed to read DefCopyObject structure");
1872 return NULL;
1873 }
1875 UNREF_DEFER(destination);
1876
1877 if (aml_copy_object(ctx->state, source, destination) == ERR)
1878 {
1879 AML_DEBUG_ERROR(ctx, "Failed to copy object");
1880 return NULL;
1881 }
1882
1883 return REF(source);
1884}
1885
1887{
1889 if (result == NULL)
1890 {
1891 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
1892 return NULL;
1893 }
1894
1895 return result; // Transfer ownership
1896}
1897
1899{
1900 aml_object_t* source1 = NULL;
1901 aml_object_t* source2 = NULL;
1902 aml_object_t* target = NULL;
1903 if (aml_op_data_data_target_read(ctx, AML_CONCAT_OP, &source1, &source2, &target) == ERR)
1904 {
1905 AML_DEBUG_ERROR(ctx, "Failed to read DefConcat structure");
1906 return NULL;
1907 }
1908 UNREF_DEFER(source1);
1909 UNREF_DEFER(source2);
1910 UNREF_DEFER(target);
1911
1912 aml_object_t* result = aml_object_new();
1913 if (result == NULL)
1914 {
1915 return NULL;
1916 }
1917 UNREF_DEFER(result);
1918
1919 if (aml_concat(ctx->state, source1, source2, result) == ERR || aml_store(ctx->state, result, target) == ERR)
1920 {
1921 return NULL;
1922 }
1923
1924 return REF(result);
1925}
1926
1928{
1929 aml_object_t* object = NULL;
1930 if (aml_op_supername_read(ctx, AML_SIZE_OF_OP, &object) == ERR)
1931 {
1932 AML_DEBUG_ERROR(ctx, "Failed to read DefSizeOf structure");
1933 return NULL;
1934 }
1935 UNREF_DEFER(object);
1936
1937 aml_object_t* result = aml_object_new();
1938 if (result == NULL)
1939 {
1940 return NULL;
1941 }
1942 UNREF_DEFER(result);
1943
1944 aml_object_t* sizeObject;
1945 switch (object->type)
1946 {
1947 case AML_ARG:
1948 sizeObject = object->arg.value;
1949 break;
1950 case AML_LOCAL:
1951 sizeObject = object->local.value;
1952 break;
1953 default:
1954 sizeObject = object;
1955 break;
1956 }
1957
1958 if (sizeObject == NULL)
1959 {
1960 errno = EINVAL;
1961 return NULL;
1962 }
1963
1964 uint64_t size;
1965 switch (sizeObject->type)
1966 {
1967 case AML_BUFFER:
1968 size = sizeObject->buffer.length;
1969 break;
1970 case AML_STRING:
1971 size = sizeObject->string.length;
1972 break;
1973 case AML_PACKAGE:
1974 size = sizeObject->package.length;
1975 break;
1976 default:
1977 errno = EINVAL;
1978 return NULL;
1979 }
1980
1981 if (aml_integer_set(result, size) == ERR)
1982 {
1983 return NULL;
1984 }
1985
1986 return REF(result);
1987}
1988
1990{
1991 aml_object_t* object = NULL;
1992 if (aml_op_supername_read(ctx, AML_REF_OF_OP, &object) == ERR)
1993 {
1994 AML_DEBUG_ERROR(ctx, "Failed to read DefRefOf structure");
1995 return NULL;
1996 }
1997 UNREF_DEFER(object);
1998
1999 aml_object_t* result = aml_object_new();
2000 if (result == NULL)
2001 {
2002 return NULL;
2003 }
2004 UNREF_DEFER(result);
2005
2006 if (aml_object_reference_set(result, object) == ERR)
2007 {
2008 return NULL;
2009 }
2010
2011 return REF(result);
2012}
2013
2015{
2017 {
2018 AML_DEBUG_ERROR(ctx, "Failed to read ObjectTypeOp");
2019 return NULL;
2020 }
2021
2022 aml_token_t token;
2023 aml_token_peek(ctx, &token);
2024
2025 aml_object_t* object;
2026 switch (token.num)
2027 {
2028 case AML_DEBUG_OP:
2029 object = aml_debug_obj_read(ctx);
2030 break;
2031 case AML_REF_OF_OP:
2032 object = aml_def_ref_of_read(ctx);
2033 break;
2034 case AML_DEREF_OF_OP:
2035 object = aml_def_deref_of_read(ctx);
2036 break;
2037 case AML_INDEX_OP:
2038 object = aml_def_index_read(ctx);
2039 break;
2040 default:
2042 break;
2043 }
2044
2045 if (object == NULL)
2046 {
2047 AML_DEBUG_ERROR(ctx, "Failed to read object from '%s'", token.props->name);
2048 return NULL;
2049 }
2050 UNREF_DEFER(object);
2051
2052 uint64_t typeNum;
2053 switch (object->type == AML_OBJECT_REFERENCE ? object->objectReference.target->type : object->type)
2054 {
2055 case AML_INTEGER:
2056 typeNum = 1;
2057 break;
2058 case AML_STRING:
2059 typeNum = 2;
2060 break;
2061 case AML_BUFFER:
2062 typeNum = 3;
2063 break;
2064 case AML_PACKAGE:
2065 typeNum = 4;
2066 break;
2067 case AML_FIELD_UNIT:
2068 typeNum = 5;
2069 break;
2070 case AML_DEVICE:
2071 typeNum = 6;
2072 break;
2073 case AML_EVENT:
2074 typeNum = 7;
2075 break;
2076 case AML_METHOD:
2077 typeNum = 8;
2078 break;
2079 case AML_MUTEX:
2080 typeNum = 9;
2081 break;
2083 typeNum = 10;
2084 break;
2085 case AML_POWER_RESOURCE:
2086 typeNum = 11;
2087 break;
2088 case AML_THERMAL_ZONE:
2089 typeNum = 13;
2090 break;
2091 case AML_BUFFER_FIELD:
2092 typeNum = 14;
2093 break;
2094 case AML_DEBUG_OBJECT:
2095 typeNum = 15;
2096 break;
2097 default:
2098 typeNum = 0;
2099 break;
2100 }
2101
2102 aml_object_t* result = aml_object_new();
2103 if (result == NULL)
2104 {
2105 return NULL;
2106 }
2107 UNREF_DEFER(result);
2108
2109 if (aml_integer_set(result, typeNum) == ERR)
2110 {
2111 return NULL;
2112 }
2113
2114 return REF(result);
2115}
2116
2118{
2119 aml_token_t op;
2120 aml_token_peek(ctx, &op);
2121
2122 aml_object_t* result = NULL;
2123 switch (op.num)
2124 {
2125 case AML_REF_OF_OP:
2126 result = aml_def_ref_of_read(ctx);
2127 break;
2128 case AML_DEREF_OF_OP:
2129 result = aml_def_deref_of_read(ctx);
2130 break;
2131 case AML_INDEX_OP:
2132 result = aml_def_index_read(ctx);
2133 break;
2134 default:
2135 AML_DEBUG_ERROR(ctx, "Invalid opcode '%s', expected RefOfOp, DerefOfOp or IndexOp", op.props->name);
2136 errno = EILSEQ;
2137 return NULL;
2138 }
2139
2140 if (result == NULL)
2141 {
2142 AML_DEBUG_ERROR(ctx, "Failed to read opcode '%s'", op.props->name);
2143 return NULL;
2144 }
2145
2146 /// I am unsure about this. But it seems that ReferenceTypeOpcodes should dereference the result if its an
2147 /// ObjectReference. Mainly this is based of the examples found in section 19.6.63.2 and 19.6.63.3 of the Index
2148 /// Operator where we can see the Store Operator storing directly to the result of an Index Operator. And this seems
2149 /// to line up with testing. I could not find any explicit mention of this in the spec though.
2150 ///
2151 /// @todo Stare at the spec some more.
2152
2153 UNREF_DEFER(result);
2154 if (result->type == AML_OBJECT_REFERENCE)
2155 {
2156 aml_object_t* target = result->objectReference.target;
2157 if (target == NULL)
2158 {
2159 AML_DEBUG_ERROR(ctx, "Object reference is NULL");
2160 errno = EILSEQ;
2161 return NULL;
2162 }
2163 return REF(target);
2164 }
2165
2166 return REF(result);
2167}
2168
2170{
2171 aml_object_t* operand = NULL;
2172 aml_object_t* target = NULL;
2173 if (aml_op_operand_target_read(ctx, AML_FIND_SET_LEFT_BIT_OP, AML_INTEGER, &operand, &target) == ERR)
2174 {
2175 AML_DEBUG_ERROR(ctx, "Failed to read DefFindSetLeftBit structure");
2176 return NULL;
2177 }
2178 UNREF_DEFER(operand);
2179 UNREF_DEFER(target);
2180
2181 aml_object_t* result = aml_object_new();
2182 if (result == NULL)
2183 {
2184 return NULL;
2185 }
2186 UNREF_DEFER(result);
2187
2188 if (operand->integer.value == 0)
2189 {
2190 if (aml_integer_set(result, 0) == ERR)
2191 {
2192 return NULL;
2193 }
2194 }
2195 else
2196 {
2197 for (uint8_t i = 0; i < aml_integer_bit_size(); i++)
2198 {
2199 if (operand->integer.value & (1ULL << (aml_integer_bit_size() - 1 - i)))
2200 {
2201 if (aml_integer_set(result, aml_integer_bit_size() - i) == ERR)
2202 {
2203 return NULL;
2204 }
2205 break;
2206 }
2207 }
2208 }
2209
2210 if (aml_store(ctx->state, result, target) == ERR)
2211 {
2212 return NULL;
2213 }
2214
2215 return REF(result);
2216}
2217
2219{
2220 aml_object_t* operand = NULL;
2221 aml_object_t* target = NULL;
2223 {
2224 AML_DEBUG_ERROR(ctx, "Failed to read DefFindSetRightBit structure");
2225 return NULL;
2226 }
2227 UNREF_DEFER(operand);
2228 UNREF_DEFER(target);
2229
2230 aml_object_t* result = aml_object_new();
2231 if (result == NULL)
2232 {
2233 return NULL;
2234 }
2235 UNREF_DEFER(result);
2236
2237 if (operand->integer.value == 0)
2238 {
2239 if (aml_integer_set(result, 0) == ERR)
2240 {
2241 return NULL;
2242 }
2243 }
2244 else
2245 {
2246 for (uint8_t i = 0; i < aml_integer_bit_size(); i++)
2247 {
2248 if (operand->integer.value & (1ULL << i))
2249 {
2250 if (aml_integer_set(result, i + 1) == ERR)
2251 {
2252 return NULL;
2253 }
2254 break;
2255 }
2256 }
2257 }
2258
2259 if (aml_store(ctx->state, result, target) == ERR)
2260 {
2261 return NULL;
2262 }
2263
2264 return REF(result);
2265}
2266
2268{
2270 if (pkg == NULL)
2271 {
2272 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
2273 return NULL;
2274 }
2275
2276 return pkg; // Transfer ownership
2277}
2278
2280{
2281 uint8_t byteData;
2282 if (aml_byte_data_read(ctx, &byteData) == ERR)
2283 {
2284 AML_DEBUG_ERROR(ctx, "Failed to read ByteData");
2285 return ERR;
2286 }
2287
2288 if (byteData > AML_MATCH_MGT)
2289 {
2290 AML_DEBUG_ERROR(ctx, "Invalid MatchOpcode value %u", byteData);
2291 errno = EILSEQ;
2292 return ERR;
2293 }
2294
2295 *out = (aml_match_opcode_t)byteData;
2296 return 0;
2297}
2298
2300{
2301 if (aml_term_arg_read_integer(ctx, out) == ERR)
2302 {
2303 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
2304 return ERR;
2305 }
2306
2307 return 0;
2308}
2309
2311{
2312 switch (op)
2313 {
2314 case AML_MATCH_MTR:
2315 return true;
2316 case AML_MATCH_MEQ:
2317 return aml_compare(obj1, obj2, AML_COMPARE_EQUAL);
2318 case AML_MATCH_MLE:
2319 return aml_compare(obj1, obj2, AML_COMPARE_LESS_EQUAL);
2320 case AML_MATCH_MLT:
2321 return aml_compare(obj1, obj2, AML_COMPARE_LESS);
2322 case AML_MATCH_MGE:
2323 return aml_compare(obj1, obj2, AML_COMPARE_GREATER_EQUAL);
2324 case AML_MATCH_MGT:
2325 return aml_compare(obj1, obj2, AML_COMPARE_GREATER);
2326 default:
2327 // This should never happen as we validate the opcode when reading it.
2328 return false;
2329 }
2330}
2331
2333{
2334 if (aml_token_expect(ctx, AML_MATCH_OP) == ERR)
2335 {
2336 AML_DEBUG_ERROR(ctx, "Failed to read MatchOp");
2337 return NULL;
2338 }
2339
2340 aml_package_t* searchPkg = aml_search_pkg_read(ctx);
2341 if (searchPkg == NULL)
2342 {
2343 AML_DEBUG_ERROR(ctx, "Failed to read SearchPkg");
2344 return NULL;
2345 }
2346 UNREF_DEFER(searchPkg);
2347
2349 if (aml_match_opcode_read(ctx, &op1) == ERR)
2350 {
2351 AML_DEBUG_ERROR(ctx, "Failed to read Op1");
2352 return NULL;
2353 }
2354
2356 if (object1 == NULL)
2357 {
2358 AML_DEBUG_ERROR(ctx, "Failed to read MatchObject1");
2359 return NULL;
2360 }
2361 UNREF_DEFER(object1);
2362
2364 if (aml_match_opcode_read(ctx, &op2) == ERR)
2365 {
2366 AML_DEBUG_ERROR(ctx, "Failed to read Op2");
2367 return NULL;
2368 }
2369
2371 if (object2 == NULL)
2372 {
2373 AML_DEBUG_ERROR(ctx, "Failed to read MatchObject2");
2374 return NULL;
2375 }
2376 UNREF_DEFER(object2);
2377
2378 aml_uint_t startIndex;
2379 if (aml_start_index_read(ctx, &startIndex) == ERR)
2380 {
2381 AML_DEBUG_ERROR(ctx, "Failed to read StartIndex");
2382 return NULL;
2383 }
2384
2385 aml_object_t* result = aml_object_new();
2386 if (result == NULL)
2387 {
2388 return NULL;
2389 }
2390 UNREF_DEFER(result);
2391
2392 for (uint64_t i = startIndex; i < searchPkg->length; i++)
2393 {
2394 aml_object_t* element = searchPkg->elements[i];
2395 if (element == NULL)
2396 {
2397 continue;
2398 }
2399
2400 if (element->type == AML_UNINITIALIZED)
2401 {
2402 continue;
2403 }
2404
2405 aml_object_t* convertedFor1 = NULL;
2406 if (aml_convert_source(ctx->state, element, &convertedFor1, object1->type) == ERR)
2407 {
2408 errno = EOK;
2409 continue;
2410 }
2411 UNREF_DEFER(convertedFor1);
2412
2413 aml_object_t* convertedFor2 = NULL;
2414 if (aml_convert_source(ctx->state, element, &convertedFor2, object2->type) == ERR)
2415 {
2416 errno = EOK;
2417 continue;
2418 }
2419 UNREF_DEFER(convertedFor2);
2420
2421 if (aml_match_compare(convertedFor1, object1, op1) && aml_match_compare(convertedFor2, object2, op2))
2422 {
2423 if (aml_integer_set(result, i) == ERR)
2424 {
2425 return NULL;
2426 }
2427 return REF(result);
2428 }
2429 }
2430
2431 if (aml_integer_set(result, aml_integer_ones()) == ERR)
2432 {
2433 return NULL;
2434 }
2435 return REF(result);
2436}
2437
2439{
2441 if (result == NULL)
2442 {
2443 AML_DEBUG_ERROR(ctx, "Failed to read TermArg");
2444 return NULL;
2445 }
2446
2447 return result; // Transfer ownership
2448}
2449
2451{
2452 if (aml_token_expect(ctx, AML_MID_OP) == ERR)
2453 {
2454 AML_DEBUG_ERROR(ctx, "Failed to read MidOp");
2455 return NULL;
2456 }
2457
2458 aml_object_t* midObj = aml_mid_obj_read(ctx);
2459 if (midObj == NULL)
2460 {
2461 AML_DEBUG_ERROR(ctx, "Failed to read MidObj");
2462 return NULL;
2463 }
2464 UNREF_DEFER(midObj);
2465
2466 aml_uint_t index;
2467 if (aml_term_arg_read_integer(ctx, &index) == ERR)
2468 {
2469 AML_DEBUG_ERROR(ctx, "Failed to read Index");
2470 return NULL;
2471 }
2472
2473 aml_uint_t length;
2474 if (aml_term_arg_read_integer(ctx, &length) == ERR)
2475 {
2476 AML_DEBUG_ERROR(ctx, "Failed to read Length");
2477 return NULL;
2478 }
2479
2480 aml_object_t* target = NULL;
2481 if (aml_target_read_and_resolve(ctx, &target) == ERR)
2482 {
2483 AML_DEBUG_ERROR(ctx, "Failed to read or resolve Target");
2484 return NULL;
2485 }
2486 UNREF_DEFER(target);
2487
2488 aml_object_t* result = aml_mid(ctx->state, midObj, index, length);
2489 if (result == NULL)
2490 {
2491 return NULL;
2492 }
2493 UNREF_DEFER(result);
2494
2495 if (aml_store(ctx->state, result, target) == ERR)
2496 {
2497 return NULL;
2498 }
2499
2500 return REF(result);
2501}
2502
2504{
2505 aml_token_t op;
2506 aml_token_peek(ctx, &op);
2507
2508 aml_object_t* result = NULL;
2509 if (op.props->type == AML_TOKEN_TYPE_NAME)
2510 {
2511 // Note that just resolving an object does not set the implicit return value.
2512 // So we only set the implicit return value if the resolved object in MethodInvocation is a method.
2513 // Or one of the other expression opcodes is used.
2514
2515 result = aml_method_invocation_read(ctx);
2516 }
2517 else
2518 {
2519 switch (op.num)
2520 {
2521 case AML_BUFFER_OP:
2522 {
2523 result = aml_object_new();
2524 if (result == NULL)
2525 {
2526 return NULL;
2527 }
2528
2529 if (aml_def_buffer_read(ctx, result) == ERR)
2530 {
2531 UNREF(result);
2532 AML_DEBUG_ERROR(ctx, "Failed to read opcode 'DefBuffer'");
2533 return NULL;
2534 }
2535 }
2536 break;
2537 case AML_PACKAGE_OP:
2538 {
2539 result = aml_object_new();
2540 if (result == NULL)
2541 {
2542 return NULL;
2543 }
2544
2545 if (aml_def_package_read(ctx, result) == ERR)
2546 {
2547 UNREF(result);
2548 AML_DEBUG_ERROR(ctx, "Failed to read opcode 'DefPackage'");
2549 return NULL;
2550 }
2551 }
2552 break;
2553 case AML_VAR_PACKAGE_OP:
2554 {
2555 result = aml_object_new();
2556 if (result == NULL)
2557 {
2558 return NULL;
2559 }
2560
2561 if (aml_def_var_package_read(ctx, result) == ERR)
2562 {
2563 UNREF(result);
2564 AML_DEBUG_ERROR(ctx, "Failed to read opcode 'DefVarPackage'");
2565 return NULL;
2566 }
2567 }
2568 break;
2569 case AML_COND_REF_OF_OP:
2570 result = aml_def_cond_ref_of_read(ctx);
2571 break;
2572 case AML_STORE_OP:
2573 result = aml_def_store_read(ctx);
2574 break;
2575 case AML_ADD_OP:
2576 result = aml_def_add_read(ctx);
2577 break;
2578 case AML_SUBTRACT_OP:
2579 result = aml_def_subtract_read(ctx);
2580 break;
2581 case AML_MULTIPLY_OP:
2582 result = aml_def_multiply_read(ctx);
2583 break;
2584 case AML_DIVIDE_OP:
2585 result = aml_def_divide_read(ctx);
2586 break;
2587 case AML_MOD_OP:
2588 result = aml_def_mod_read(ctx);
2589 break;
2590 case AML_AND_OP:
2591 result = aml_def_and_read(ctx);
2592 break;
2593 case AML_NAND_OP:
2594 result = aml_def_nand_read(ctx);
2595 break;
2596 case AML_OR_OP:
2597 result = aml_def_or_read(ctx);
2598 break;
2599 case AML_NOR_OP:
2600 result = aml_def_nor_read(ctx);
2601 break;
2602 case AML_XOR_OP:
2603 result = aml_def_xor_read(ctx);
2604 break;
2605 case AML_NOT_OP:
2606 result = aml_def_not_read(ctx);
2607 break;
2608 case AML_SHIFT_LEFT_OP:
2609 result = aml_def_shift_left_read(ctx);
2610 break;
2611 case AML_SHIFT_RIGHT_OP:
2612 result = aml_def_shift_right_read(ctx);
2613 break;
2614 case AML_INCREMENT_OP:
2615 result = aml_def_increment_read(ctx);
2616 break;
2617 case AML_DECREMENT_OP:
2618 result = aml_def_decrement_read(ctx);
2619 break;
2620 case AML_DEREF_OF_OP:
2621 result = aml_def_deref_of_read(ctx);
2622 break;
2623 case AML_INDEX_OP:
2624 result = aml_def_index_read(ctx);
2625 break;
2626 case AML_LAND_OP:
2627 result = aml_def_land_read(ctx);
2628 break;
2629 case AML_LEQUAL_OP:
2630 result = aml_def_lequal_read(ctx);
2631 break;
2632 case AML_LGREATER_OP:
2633 result = aml_def_lgreater_read(ctx);
2634 break;
2636 result = aml_def_lgreater_equal_read(ctx);
2637 break;
2638 case AML_LLESS_OP:
2639 result = aml_def_lless_read(ctx);
2640 break;
2641 case AML_LLESS_EQUAL_OP:
2642 result = aml_def_lless_equal_read(ctx);
2643 break;
2644 case AML_LNOT_OP:
2645 result = aml_def_lnot_read(ctx);
2646 break;
2647 case AML_LNOT_EQUAL_OP:
2648 result = aml_def_lnot_equal_read(ctx);
2649 break;
2650 case AML_LOR_OP:
2651 result = aml_def_lor_read(ctx);
2652 break;
2653 case AML_ACQUIRE_OP:
2654 result = aml_def_acquire_read(ctx);
2655 break;
2656 case AML_TO_BCD_OP:
2657 result = aml_def_to_bcd_read(ctx);
2658 break;
2659 case AML_TO_BUFFER_OP:
2660 result = aml_def_to_buffer_read(ctx);
2661 break;
2663 result = aml_def_to_decimal_string_read(ctx);
2664 break;
2666 result = aml_def_to_hex_string_read(ctx);
2667 break;
2668 case AML_TO_INTEGER_OP:
2669 result = aml_def_to_integer_read(ctx);
2670 break;
2671 case AML_TO_STRING_OP:
2672 result = aml_def_to_string_read(ctx);
2673 break;
2674 case AML_TIMER_OP:
2675 result = aml_def_timer_read(ctx);
2676 break;
2677 case AML_COPY_OBJECT_OP:
2678 result = aml_def_copy_object_read(ctx);
2679 break;
2680 case AML_CONCAT_OP:
2681 result = aml_def_concat_read(ctx);
2682 break;
2683 case AML_SIZE_OF_OP:
2684 result = aml_def_size_of_read(ctx);
2685 break;
2686 case AML_REF_OF_OP:
2687 result = aml_def_ref_of_read(ctx);
2688 break;
2689 case AML_OBJECT_TYPE_OP:
2690 result = aml_def_object_type_read(ctx);
2691 break;
2693 result = aml_def_find_set_left_bit_read(ctx);
2694 break;
2696 result = aml_def_find_set_right_bit_read(ctx);
2697 break;
2698 case AML_MATCH_OP:
2699 result = aml_def_match_read(ctx);
2700 break;
2701 case AML_MID_OP:
2702 result = aml_def_mid_read(ctx);
2703 break;
2704 default:
2705 AML_DEBUG_ERROR(ctx, "Unknown ExpressionOpcode '%s' (0x%04x)", op.props->name, op.num);
2706 errno = ENOSYS;
2707 return NULL;
2708 }
2709
2710 if (result != NULL)
2711 {
2712 aml_state_result_set(ctx->state, result);
2713 }
2714 }
2715
2716 if (result == NULL)
2717 {
2718 AML_DEBUG_ERROR(ctx, "Failed to read ExpressionOpcode '%s' (0x%04x)", op.props->name, op.num);
2719 return NULL;
2720 }
2721
2722 return result; // Transfer ownership
2723}
#define assert(expression)
Definition assert.h:29
#define CLOCKS_NEVER
Definition clock_t.h:16
#define CLOCKS_PER_SEC
Definition clock_t.h:15
uint64_t aml_concat(aml_state_t *state, aml_object_t *source1, aml_object_t *source2, aml_object_t *result)
Concatenates two objects according to the rules in section 19.6.12 of the ACPI specification.
Definition concat.c:283
static uint64_t aml_op_operand_read(aml_term_list_ctx_t *ctx, aml_token_num_t expectedOp, aml_type_t allowedTypes, aml_object_t **operand)
Definition expression.c:101
static uint64_t aml_op_termarg_supername_read(aml_term_list_ctx_t *ctx, aml_token_num_t expectedOp, aml_type_t allowedTypes, aml_object_t **termarg, aml_object_t **supername)
Definition expression.c:260
static uint64_t aml_op_operand_target_read(aml_term_list_ctx_t *ctx, aml_token_num_t expectedOp, aml_type_t allowedTypes, aml_object_t **operand, aml_object_t **target)
Definition expression.c:120
static uint64_t aml_op_data_data_target_read(aml_term_list_ctx_t *ctx, aml_token_num_t expectedOp, aml_object_t **data1, aml_object_t **data2, aml_object_t **target)
Definition expression.c:179
static uint64_t aml_op_termarg_simplename_read(aml_term_list_ctx_t *ctx, aml_token_num_t expectedOp, aml_type_t allowedTypes, aml_object_t **termarg, aml_object_t **simplename)
Definition expression.c:214
static uint64_t aml_op_operand_operand_read(aml_term_list_ctx_t *ctx, aml_token_num_t expectedOp, aml_type_t allowedTypes, aml_object_t **operand1, aml_object_t **operand2)
Definition expression.c:73
static uint64_t aml_op_operand_operand_target_read(aml_term_list_ctx_t *ctx, aml_token_num_t expectedOp, aml_type_t allowedTypes, aml_object_t **operand1, aml_object_t **operand2, aml_object_t **target)
Definition expression.c:37
static uint64_t aml_op_supername_read(aml_term_list_ctx_t *ctx, aml_token_num_t expectedOp, aml_object_t **supername)
Definition expression.c:241
static bool aml_match_compare(aml_object_t *obj1, aml_object_t *obj2, aml_match_opcode_t op)
static uint64_t aml_op_operand_shiftcount_target_read(aml_term_list_ctx_t *ctx, aml_token_num_t expectedOp, aml_type_t allowedTypes, aml_object_t **operand, aml_uint_t *shiftCount, aml_object_t **target)
Definition expression.c:146
clock_t clock_uptime(void)
Retrieve the time in nanoseconds since boot.
Definition clock.c:99
#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 EOK
No error.
Definition errno.h:32
#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_TYPE__ clock_t
A nanosecond time.
Definition clock_t.h:13
aml_uint_t aml_compare_not(aml_uint_t value)
Perform a logical NOT operation on an integer value.
Definition compare.c:25
aml_uint_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_NOT_EQUAL
Definition compare.h:26
@ AML_COMPARE_GREATER_EQUAL
Definition compare.h:28
@ 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_LESS_EQUAL
Definition compare.h:27
@ AML_COMPARE_AND
Section 19.6.69, integer only.
Definition compare.h:19
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_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_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
#define AML_DEBUG_ERROR(ctx, format,...)
Macro to simplify calling aml_debug_error() with the current function name.
Definition debug.h:30
#define AML_MAX_ARGS
Maximum number of arguments that can be passed to a method.
Definition arg.h:19
uint64_t aml_def_package_read(aml_term_list_ctx_t *ctx, aml_object_t *out)
Reads a DefPackage structure from the AML byte stream.
Definition data.c:407
uint64_t aml_byte_data_read(aml_term_list_ctx_t *ctx, uint8_t *out)
Read a ByteData structure from the AML stream.
Definition data.c:16
uint64_t aml_word_data_read(aml_term_list_ctx_t *ctx, uint16_t *out)
Read a WordData structure from the AML stream.
Definition data.c:30
uint64_t aml_def_var_package_read(aml_term_list_ctx_t *ctx, aml_object_t *out)
Reads a DefVarPackage structure from the AML byte stream.
Definition data.c:460
aml_object_t * aml_debug_obj_read(aml_term_list_ctx_t *ctx)
Reads a DebugObj structure from the AML byte stream.
Definition debug.c:6
uint64_t aml_def_buffer_read(aml_term_list_ctx_t *ctx, aml_object_t *out)
Reads a DefBuffer structure from the AML byte stream.
Definition expression.c:297
aml_object_t * aml_def_acquire_read(aml_term_list_ctx_t *ctx)
Reads a DefAcquire structure from the AML byte stream.
uint64_t aml_term_arg_list_read(aml_term_list_ctx_t *ctx, uint64_t argCount, aml_term_arg_list_t *out)
Reads a TermArgList structure from the AML byte stream.
Definition expression.c:334
aml_object_t * aml_def_to_string_read(aml_term_list_ctx_t *ctx)
Reads a DefToString structure from the AML byte stream.
aml_object_t * aml_def_add_read(aml_term_list_ctx_t *ctx)
Reads a DefAdd structure from the AML byte stream.
Definition expression.c:545
uint64_t aml_timeout_read(aml_term_list_ctx_t *ctx, uint16_t *out)
Reads a Timeout structure from the AML byte stream.
aml_object_t * aml_def_increment_read(aml_term_list_ctx_t *ctx)
Reads a DefIncrement structure from the AML byte stream.
uint64_t aml_start_index_read(aml_term_list_ctx_t *ctx, aml_uint_t *out)
Reads a StartIndex structure from the AML byte stream.
aml_object_t * aml_def_concat_read(aml_term_list_ctx_t *ctx)
Reads a DefConcat structure from the AML byte stream.
uint64_t aml_index_value_read(aml_term_list_ctx_t *ctx, aml_uint_t *out)
Reads an IndexValue structure from the AML byte stream.
aml_object_t * aml_def_land_read(aml_term_list_ctx_t *ctx)
Reads a DefLAnd structure from the AML byte stream.
aml_object_t * aml_def_to_hex_string_read(aml_term_list_ctx_t *ctx)
Reads a DefToHexString structure from the AML byte stream.
uint64_t aml_dividend_read(aml_term_list_ctx_t *ctx, aml_uint_t *out)
Reads a Dividend structure from the AML byte stream.
Definition expression.c:499
aml_object_t * aml_def_mid_read(aml_term_list_ctx_t *ctx)
Reads a DefMid structure from the AML byte stream.
aml_object_t * aml_mid_obj_read(aml_term_list_ctx_t *ctx)
Reads a MidObj structure from the AML byte stream.
aml_object_t * aml_def_find_set_left_bit_read(aml_term_list_ctx_t *ctx)
Reads a DefFindSetLeftBit structure from the AML byte stream.
aml_object_t * aml_def_match_read(aml_term_list_ctx_t *ctx)
Reads a DefMatch structure from the AML byte stream.
aml_object_t * aml_def_cond_ref_of_read(aml_term_list_ctx_t *ctx)
Reads a DefCondRefOf structure from the AML byte stream.
Definition expression.c:407
aml_object_t * aml_def_to_integer_read(aml_term_list_ctx_t *ctx)
Reads a DefToInteger structure from the AML byte stream.
aml_object_t * aml_mutex_object_read(aml_term_list_ctx_t *ctx)
Reads a MutexObject structure from the AML byte stream.
aml_object_t * aml_def_lgreater_equal_read(aml_term_list_ctx_t *ctx)
Reads a DefLGreaterEqual structure from the AML byte stream.
aml_object_t * aml_def_object_type_read(aml_term_list_ctx_t *ctx)
Reads a DefObjectType structure from the AML byte stream.
aml_object_t * aml_def_to_decimal_string_read(aml_term_list_ctx_t *ctx)
Reads a DefToDecimalString structure from the AML byte stream.
aml_object_t * aml_def_size_of_read(aml_term_list_ctx_t *ctx)
Reads a DefSizeOf structure from the AML byte stream.
aml_object_t * aml_def_decrement_read(aml_term_list_ctx_t *ctx)
Reads a DefDecrement structure from the AML byte stream.
aml_object_t * aml_remainder_read(aml_term_list_ctx_t *ctx)
Reads a Remainder structure from the AML byte stream.
Definition expression.c:521
aml_object_t * aml_def_lor_read(aml_term_list_ctx_t *ctx)
Reads a DefLOr structure from the AML byte stream.
aml_object_t * aml_def_copy_object_read(aml_term_list_ctx_t *ctx)
Reads a DefCopyObject structure from the AML byte stream.
uint64_t aml_buffer_size_read(aml_term_list_ctx_t *ctx, aml_uint_t *out)
Reads a BufferSize structure from the AML byte stream.
Definition expression.c:287
aml_object_t * aml_def_nor_read(aml_term_list_ctx_t *ctx)
Reads a DefNOr structure from the AML byte stream.
Definition expression.c:843
aml_object_t * aml_data_read(aml_term_list_ctx_t *ctx)
Reads a Data structure from the AML byte stream.
aml_object_t * aml_def_xor_read(aml_term_list_ctx_t *ctx)
Reads a DefXOr structure from the AML byte stream.
Definition expression.c:873
uint64_t aml_length_arg_read(aml_term_list_ctx_t *ctx, aml_uint_t *out)
Reads a LengthArg structure from the AML byte stream.
aml_object_t * aml_def_multiply_read(aml_term_list_ctx_t *ctx)
Reads a DefMultiply structure from the AML byte stream.
Definition expression.c:605
aml_object_t * aml_def_to_bcd_read(aml_term_list_ctx_t *ctx)
Reads a DefToBcd structure from the AML byte stream.
aml_object_t * aml_expression_opcode_read(aml_term_list_ctx_t *ctx)
Reads an ExpressionOpcode structure from the AML byte stream.
aml_object_t * aml_def_lnot_read(aml_term_list_ctx_t *ctx)
Reads a DefLNot structure from the AML byte stream.
aml_object_t * aml_operand_read(aml_term_list_ctx_t *ctx, aml_type_t allowedTypes)
Reads an Operand structure from the AML byte stream.
Definition expression.c:25
aml_object_t * aml_def_nand_read(aml_term_list_ctx_t *ctx)
Reads a DefNAnd structure from the AML byte stream.
Definition expression.c:783
uint64_t aml_match_opcode_read(aml_term_list_ctx_t *ctx, aml_match_opcode_t *out)
Reads a MatchOpcode structure from the AML byte stream.
aml_object_t * aml_def_store_read(aml_term_list_ctx_t *ctx)
Reads a DefStore structure from the AML byte stream.
Definition expression.c:477
aml_object_t * aml_def_shift_right_read(aml_term_list_ctx_t *ctx)
Reads a DefShiftRight structure from the AML byte stream.
Definition expression.c:987
aml_object_t * aml_def_lequal_read(aml_term_list_ctx_t *ctx)
Reads a DefLEqual structure from the AML byte stream.
aml_object_t * aml_def_shift_left_read(aml_term_list_ctx_t *ctx)
Reads a DefShiftLeft structure from the AML byte stream.
Definition expression.c:941
aml_object_t * aml_def_lless_equal_read(aml_term_list_ctx_t *ctx)
Reads a DefLLessEqual structure from the AML byte stream.
uint64_t aml_shift_count_read(aml_term_list_ctx_t *ctx, aml_uint_t *out)
Reads a ShiftCount structure from the AML byte stream.
Definition expression.c:930
aml_object_t * aml_def_lless_read(aml_term_list_ctx_t *ctx)
Reads a DefLLess structure from the AML byte stream.
aml_object_t * aml_def_subtract_read(aml_term_list_ctx_t *ctx)
Reads a DefSubtract structure from the AML byte stream.
Definition expression.c:575
aml_object_t * aml_def_timer_read(aml_term_list_ctx_t *ctx)
Reads a DefTimer structure from the AML byte stream.
aml_object_t * aml_reference_type_opcode_read(aml_term_list_ctx_t *ctx)
aml_object_t * aml_def_mod_read(aml_term_list_ctx_t *ctx)
Reads a DefMod structure from the AML byte stream.
Definition expression.c:703
aml_object_t * aml_obj_reference_read(aml_term_list_ctx_t *ctx)
Reads an ObjReference structure from the AML byte stream.
aml_object_t * aml_def_and_read(aml_term_list_ctx_t *ctx)
Reads a DefAnd structure from the AML byte stream.
Definition expression.c:753
aml_object_t * aml_quotient_read(aml_term_list_ctx_t *ctx)
Reads a Quotient structure from the AML byte stream.
Definition expression.c:533
aml_object_t * aml_def_to_buffer_read(aml_term_list_ctx_t *ctx)
Reads a DefToBuffer structure from the AML byte stream.
aml_object_t * aml_def_not_read(aml_term_list_ctx_t *ctx)
Reads a DefNot structure from the AML byte stream.
Definition expression.c:903
aml_object_t * aml_def_lgreater_read(aml_term_list_ctx_t *ctx)
Reads a DefLGreater structure from the AML byte stream.
aml_object_t * aml_method_invocation_read(aml_term_list_ctx_t *ctx)
Reads a MethodInvocation structure from the AML byte stream.
Definition expression.c:361
aml_match_opcode_t
Match opcodes for DefMatch.
Definition expression.h:796
aml_object_t * aml_def_lnot_equal_read(aml_term_list_ctx_t *ctx)
Reads a DefLNotEqual structure from the AML byte stream.
aml_object_t * aml_buff_pkg_str_obj_read(aml_term_list_ctx_t *ctx)
Reads a BuffPkgStrObj structure from the AML byte stream.
aml_object_t * aml_def_index_read(aml_term_list_ctx_t *ctx)
Reads a DefIndex structure from the AML byte stream.
aml_object_t * aml_def_divide_read(aml_term_list_ctx_t *ctx)
Reads a DefDivide structure from the AML byte stream.
Definition expression.c:635
aml_object_t * aml_def_deref_of_read(aml_term_list_ctx_t *ctx)
Reads a DefDerefOf structure from the AML byte stream.
aml_package_t * aml_search_pkg_read(aml_term_list_ctx_t *ctx)
Reads a SearchPkg structure from the AML byte stream.
aml_object_t * aml_def_or_read(aml_term_list_ctx_t *ctx)
Reads a DefOr structure from the AML byte stream.
Definition expression.c:813
aml_object_t * aml_def_find_set_right_bit_read(aml_term_list_ctx_t *ctx)
Reads a DefFindSetRightBit structure from the AML byte stream.
aml_object_t * aml_def_ref_of_read(aml_term_list_ctx_t *ctx)
Reads a DefRefOf structure from the AML byte stream.
uint64_t aml_divisor_read(aml_term_list_ctx_t *ctx, aml_uint_t *out)
Reads a Divisor structure from the AML byte stream.
Definition expression.c:510
@ AML_MATCH_MGT
Definition expression.h:802
@ AML_MATCH_MLT
Definition expression.h:800
@ AML_MATCH_MTR
Definition expression.h:797
@ AML_MATCH_MGE
Definition expression.h:801
@ AML_MATCH_MLE
Definition expression.h:799
@ AML_MATCH_MEQ
Definition expression.h:798
aml_object_t * aml_name_string_read_and_resolve(aml_term_list_ctx_t *ctx)
Reads the next data as a NameString structure from the AML bytecode stream and resolves it to a objec...
Definition name.c:227
aml_object_t * aml_simple_name_read_and_resolve(aml_term_list_ctx_t *ctx)
Reads a SimpleName structure from the AML byte stream and resolves it to a object.
Definition name.c:264
aml_object_t * aml_super_name_read_and_resolve(aml_term_list_ctx_t *ctx)
Reads a SuperName structure from the AML byte stream and resolves it to a object.
Definition name.c:296
uint64_t aml_target_read_and_resolve(aml_term_list_ctx_t *ctx, aml_object_t **out)
Reads a Target structure from the AML byte stream and resolves it to a object.
Definition name.c:330
uint32_t aml_pkg_length_t
PkgLength structure.
uint64_t aml_pkg_length_read(aml_term_list_ctx_t *ctx, aml_pkg_length_t *out)
Reads a PkgLength structure from the AML byte stream.
aml_object_t * aml_term_arg_read(aml_term_list_ctx_t *ctx, aml_type_t allowedTypes)
Reads an TermArg structure from the AML byte stream.
Definition term.c:19
uint64_t aml_term_arg_read_integer(aml_term_list_ctx_t *ctx, aml_uint_t *out)
Wrapper around aml_term_arg_read() that converts the result to an integer.
Definition term.c:70
aml_package_t * aml_term_arg_read_package(aml_term_list_ctx_t *ctx)
Wrapper around aml_term_arg_read() that converts the result to a package.
Definition term.c:114
aml_buffer_t * aml_term_arg_read_buffer(aml_term_list_ctx_t *ctx)
Wrapper around aml_term_arg_read() that converts the result to a buffer.
Definition term.c:100
uint8_t aml_integer_bit_size(void) PURE
Get the bit size of an AML integer.
Definition integer.c:27
aml_uint_t aml_integer_ones(void) PURE
Get a mask with all bits set for the current AML integer size.
Definition integer.c:32
uint64_t aml_uint_t
AML Integer type.
Definition integer.h:20
#define AML_TRUE
AML Boolean true value.
Definition integer.h:25
aml_object_t * aml_method_invoke(aml_state_t *parentState, aml_method_t *method, aml_object_t **args)
Invoke a method with the given arguments.
Definition method.c:11
aml_object_t * aml_mid(aml_state_t *state, aml_object_t *bufferString, aml_uint_t index, aml_uint_t length)
Performs a "mid" operation, extracting a portion of a buffer or string.
Definition mid.c:3
uint64_t aml_mutex_acquire(aml_mutex_id_t *mutex, aml_sync_level_t syncLevel, clock_t timeout)
Acquire a mutex, blocking until it is available or the timeout is reached.
Definition mutex.c:94
#define AML_NAME_TO_STRING(name)
Macro to convert an aml_name_t to a stack allocated string.
Definition namespace.h:129
aml_object_t * aml_namespace_find_by_path(aml_overlay_t *overlay, aml_object_t *start, const char *path)
Find an object in the namespace heirarchy by a path string.
Definition namespace.c:288
uint64_t aml_object_reference_set(aml_object_t *object, aml_object_t *target)
Set a object as an ObjectReference to the given target object.
Definition object.c:895
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_field_set(aml_object_t *object, aml_object_t *target, aml_bit_size_t bitOffset, aml_bit_size_t bitSize)
Set a object as a buffer field with the given buffer, bit offset and bit size.
Definition object.c:594
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
@ AML_METHOD
Definition object.h:77
@ AML_BUFFER_FIELD
Definition object.h:62
@ AML_PACKAGE
Definition object.h:81
@ AML_OBJECT_REFERENCE
Definition object.h:79
@ AML_OPERATION_REGION
Definition object.h:80
@ 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_THERMAL_ZONE
Definition object.h:86
@ AML_FIELD_UNIT
Definition object.h:66
@ AML_POWER_RESOURCE
Definition object.h:82
@ AML_COMPUTATIONAL_DATA_OBJECTS
Definition object.h:95
@ AML_DATA_REF_OBJECTS
Definition object.h:105
@ AML_EVENT
Definition object.h:65
@ AML_DEVICE
Definition object.h:64
@ AML_MUTEX
Definition object.h:78
@ 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
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_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
aml_token_num_t
Token numbers.
Definition token.h:35
static uint64_t aml_token_expect(aml_term_list_ctx_t *ctx, aml_token_num_t expected)
Reads a token from the AML stream and verifies it matches the expected token.
Definition token.h:353
static const aml_token_props_t * aml_token_lookup(aml_token_num_t num)
Lookup token properties.
Definition token.h:278
static void aml_token_peek(aml_term_list_ctx_t *ctx, aml_token_t *out)
Attempt to read a token from the AML stream, without advancing the instruction pointer.
Definition token.h:301
@ AML_XOR_OP
Definition token.h:125
@ AML_DEBUG_OP
Definition token.h:184
@ AML_DIVIDE_OP
Definition token.h:118
@ AML_OR_OP
Definition token.h:123
@ AML_STORE_OP
Definition token.h:110
@ AML_INCREMENT_OP
Definition token.h:115
@ AML_SHIFT_LEFT_OP
Definition token.h:119
@ AML_NAND_OP
Definition token.h:122
@ AML_CONCAT_OP
Definition token.h:113
@ AML_FIND_SET_RIGHT_BIT_OP
Definition token.h:128
@ AML_SIZE_OF_OP
Definition token.h:133
@ AML_AND_OP
Definition token.h:121
@ AML_MATCH_OP
Definition token.h:135
@ AML_TO_BUFFER_OP
Definition token.h:148
@ AML_TO_INTEGER_OP
Definition token.h:151
@ AML_ACQUIRE_OP
Definition token.h:175
@ AML_LOR_OP
Definition token.h:143
@ AML_DECREMENT_OP
Definition token.h:116
@ AML_INDEX_OP
Definition token.h:134
@ AML_ADD_OP
Definition token.h:112
@ AML_NOT_OP
Definition token.h:126
@ AML_LNOT_OP
Definition token.h:144
@ AML_TO_DECIMAL_STRING_OP
Definition token.h:149
@ AML_TO_BCD_OP
Definition token.h:181
@ AML_PACKAGE_OP
Definition token.h:49
@ AML_LEQUAL_OP
Definition token.h:145
@ AML_BUFFER_OP
Definition token.h:48
@ AML_MOD_OP
Definition token.h:131
@ AML_OBJECT_TYPE_OP
Definition token.h:140
@ AML_LAND_OP
Definition token.h:142
@ AML_TO_HEX_STRING_OP
Definition token.h:150
@ AML_DEREF_OF_OP
Definition token.h:129
@ AML_LGREATER_OP
Definition token.h:146
@ AML_TO_STRING_OP
Definition token.h:152
@ AML_SUBTRACT_OP
Definition token.h:114
@ AML_LNOT_EQUAL_OP
Definition token.h:199
@ AML_VAR_PACKAGE_OP
Definition token.h:50
@ AML_LLESS_EQUAL_OP
Definition token.h:200
@ AML_SHIFT_RIGHT_OP
Definition token.h:120
@ AML_TIMER_OP
Definition token.h:186
@ AML_LGREATER_EQUAL_OP
Definition token.h:201
@ AML_LLESS_OP
Definition token.h:147
@ AML_MID_OP
Definition token.h:154
@ AML_COPY_OBJECT_OP
Definition token.h:153
@ AML_MULTIPLY_OP
Definition token.h:117
@ AML_REF_OF_OP
Definition token.h:111
@ AML_NOR_OP
Definition token.h:124
@ AML_FIND_SET_LEFT_BIT_OP
Definition token.h:127
@ AML_COND_REF_OF_OP
Definition token.h:169
@ AML_TOKEN_TYPE_NAME
Is a Name Object (section 20.2.2).
Definition token.h:226
static clock_source_t source
Structure to describe the HPET to the sys time subsystem.
Definition hpet.c:192
static mtx_t mutex
Definition heap.c:35
static void start()
Definition main.c:542
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__UINT16_TYPE__ uint16_t
Definition stdint.h:13
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
aml_uint_t value
Definition object.h:288
aml_object_t * value
The value of the local variable.
Definition object.h:439
uint8_t argCount
Amount of arguments (0-7)
Definition named.h:143
aml_method_flags_t methodFlags
Definition object.h:313
aml_object_t * target
Definition object.h:337
ACPI object.
Definition object.h:447
aml_package_t package
Definition object.h:464
aml_integer_t integer
Definition object.h:458
aml_buffer_t buffer
Definition object.h:453
aml_method_t method
Definition object.h:460
aml_string_t string
Definition object.h:467
aml_local_t local
Definition object.h:472
aml_object_reference_t objectReference
Definition object.h:462
aml_arg_t arg
Definition object.h:471
Data for a package object.
Definition object.h:359
aml_object_t ** elements
Definition object.h:361
uint64_t length
Definition object.h:362
aml_overlay_t overlay
Holds any named objects created during parsing.
Definition state.h:30
uint64_t length
Definition object.h:393
char * content
Definition object.h:392
TermArgList structure.
Definition expression.h:25
aml_object_t * args[AML_MAX_ARGS+1]
Definition expression.h:26
Context for reading a TermList.
Definition term.h:37
aml_object_t * scope
Definition term.h:39
aml_state_t * state
Definition term.h:38
const uint8_t * current
Definition term.h:42
const char * name
Definition token.h:243
aml_token_type_t type
Definition token.h:245
Token.
Definition token.h:253
const aml_token_props_t * props
Definition token.h:256
aml_token_num_t num
Definition token.h:254
const char * name
Definition clock.h:34