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