1    /*
2     * Some or all of this work - Copyright (c) 2006 - 2021, Intel Corp.
3     * All rights reserved.
4     *
5     * Redistribution and use in source and binary forms, with or without modification,
6     * are permitted provided that the following conditions are met:
7     *
8     * Redistributions of source code must retain the above copyright notice,
9     * this list of conditions and the following disclaimer.
10     * Redistributions in binary form must reproduce the above copyright notice,
11     * this list of conditions and the following disclaimer in the documentation
12     * and/or other materials provided with the distribution.
13     * Neither the name of Intel Corporation nor the names of its contributors
14     * may be used to endorse or promote products derived from this software
15     * without specific prior written permission.
16     *
17     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20     * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22     * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23     * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25     * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27     */
28    /*
29     * The common methods of the Reference tests
30     *
31     *
32     * Methods used for to verify particular References:
33     *
34     *    m1a0, m1a1, m1a2
35     */
36    /*
37     SEE: Investigate and report all y<XXX>.
38     SEE: see everywhere "index of checking" and z0XX - through all ref files: corresponds?!!!!!!!!!
39     SEE: add into m1a6 and all m000 the checking like these:
40     Store(\i900, Debug)
41     Store(\d900.i900, Debug)
42     */
43    Name (Z076, 0x4C)
44    /* Check Boolean (CondRefOf) and the type of value */
45    /* arg0 - reference to the value of arbitrary type */
46    /* arg1 - expected type of value */
47    /* arg2 - returned Boolean */
48    /* arg3 - index of checking (inside the file) */
49    Method (M1A0, 4, NotSerialized)
50    {
51        Local7 = M1A4 (Arg2, Arg3)
52        SET0 (C081, 0x00, Arg3)
53        If (Local7)
54        {
55            Local0 = ObjectType (Arg0)
56            If ((Local0 != Arg1))
57            {
58                ERR (C080, Z076, __LINE__, 0x00, 0x00, Local0, Arg1)
59            }
60            /* if (c08b) */
61            /* ATTENTION: exactly the same in m1a0 and m1a2 */
62            Else
63            {
64                If (C089)
65                {
66                    /* Flag of Reference, object otherwise */
67
68                    If (C082)
69                    {
70                        /* Test of exceptions */
71
72                        M1A8 (Arg0, 0x00, 0x00)
73                    }
74
75                    If (C085)
76                    {
77                        /* Create the chain of references to LocalX, */
78                        /* then dereference them. */
79                        Local0 = RefOf (Arg0)
80                        Local1 = RefOf (Local0)
81                        Local2 = RefOf (Local1)
82                        Local3 = RefOf (Local2)
83                        Local4 = RefOf (Local3)
84                        Local5 = RefOf (Local4)
85                        Local6 = RefOf (Local5)
86                        Local7 = RefOf (Local6)
87                        Local6 = DerefOf (Local7)
88                        Local5 = DerefOf (Local6)
89                        Local4 = DerefOf (Local5)
90                        Local3 = DerefOf (Local4)
91                        Local2 = DerefOf (Local3)
92                        Local1 = DerefOf (Local2)
93                        Local0 = DerefOf (Local1)
94                        Local7 = DerefOf (Local0)
95                        /* Create the chain of references to LocalX, */
96                        /* then dereference them. */
97                        Local0 = M1A5 (Local7)
98                    }
99                }
100
101                /* if(c089) */
102                /* ATTENTION: exactly the same in m1a0 and m1a2 */
103                /* (but, don't replace it by call to Method) */
104                Method (M002, 1, NotSerialized)
105                {
106                    Arg0 = 0xABCD001A
107                }
108
109                /* Run verification of references (write/read) */
110
111                If ((C083 == 0x01))
112                {
113                    C08A = 0xABCD001A
114                    Arg0 = C08A /* \C08A */
115                }
116                ElseIf ((C083 == 0x02))
117                {
118                    C08A = 0xABCD001B
119                    CopyObject (C08A, Arg0)
120                }
121                ElseIf ((C083 == 0x03))
122                {
123                    C08A = 0xABCD001C
124                    Arg0 = C08A /* \C08A */
125                    C08A = 0xABCD001D
126                    CopyObject (C08A, Arg0)
127                }
128
129                Local7 = 0x00
130                If ((C08B == 0x01))
131                {
132                    Local0 = RefOf (Arg0)
133                    Local1 = ObjectType (Local0)
134                    If ((Local1 != Arg1))
135                    {
136                        ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, Arg1)
137                    }
138                    Else
139                    {
140                        Local7 = 0x01
141                    }
142                }
143                ElseIf ((C08B == 0x02))
144                {
145                    Local1 = CondRefOf (Arg0, Local0)
146                    If ((Local1 != Ones))
147                    {
148                        ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, Arg1)
149                    }
150                    Else
151                    {
152                        Local1 = ObjectType (Local0)
153                        If ((Local1 != Arg1))
154                        {
155                            ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, Arg1)
156                        }
157                        Else
158                        {
159                            Local7 = 0x01
160                        }
161                    }
162                }
163
164                If (Local7)
165                {
166                    /* Obtain RefOf_Reference to ArgX */
167
168                    Local0 = RefOf (Arg0)
169                    Local1 = ObjectType (Local0)
170                    If ((Local1 != Arg1))
171                    {
172                        ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, Arg1)
173                    }
174                    Else
175                    {
176                        /* Check DerefOf */
177
178                        Local1 = ObjectType (DerefOf (Local0))
179                        If ((Local1 != Arg1))
180                        {
181                            ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, Arg1)
182                        }
183
184                        /* Check that writing into M2-ArgX-RefOf_Reference */
185                        /* changes the original object (M1-ArgX): */
186                        M002 (Local0)
187                        Local1 = ObjectType (Arg0)
188                        If ((Local1 != C009))
189                        {
190                            ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, C009)
191                        }
192                        ElseIf ((Arg0 != 0xABCD001A))
193                        {
194                            ERR (C080, Z076, __LINE__, 0x00, 0x00, Arg0, 0xABCD001A)
195                        }
196                        Else
197                        {
198                            /* Check that M1-LocalX-RefOf_Reference remains */
199                            /* up to date after writing into M2-ArgX in M2 and */
200                            /* thus updating the contents of the object */
201                            /* referenced by M1-LocalX. */
202                            Local1 = ObjectType (Local0)
203                            If ((Local1 != C009))
204                            {
205                                ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, C009)
206                            }
207                            Else
208                            {
209                                Local1 = SizeOf (Local0)
210                                If ((Local1 != ISZ0))
211                                {
212                                    ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, ISZ0)
213                                }
214                            }
215                        }
216                    }
217                }
218            }
219        }
220
221        /* if(Local7) */
222
223        RST0 ()
224    }
225
226    /* Verifying reference to the Object nested inside Packages */
227    /* arg0 - reference to the Object (may be to Package) */
228    /* arg1 - type of the value referred by arg0 */
229    /* arg2 - nesting level of the Packages */
230    /*        (Package always is a 0-th element */
231    /*         of previous Package) */
232    /* arg3 - index of the Object inside the last Package */
233    /* arg4 - type of the Object */
234    /* arg5 - the benchmark value of Object for verification */
235    /* arg6 - index of checking (inside the file) */
236    Method (M1A2, 7, Serialized)
237    {
238        SET0 (C081, 0x00, Arg6)
239        Name (LPN0, 0x00)
240        Name (LPC0, 0x00)
241        Local0 = ObjectType (Arg0)
242        If ((Local0 != Arg1))
243        {
244            ERR (C080, Z076, __LINE__, 0x00, 0x00, Local0, Arg1)
245        }
246        /* if (c08b) */
247        /* ATTENTION: exactly the same in m1a0 and m1a2 */
248        Else
249        {
250            If (C089)
251            {
252                /* Flag of Reference, object otherwise */
253
254                If (C082)
255                {
256                    /* Test of exceptions */
257
258                    M1A8 (Arg0, 0x00, 0x00)
259                }
260
261                If (C085)
262                {
263                    /* Create the chain of references to LocalX, */
264                    /* then dereference them. */
265                    Local0 = RefOf (Arg0)
266                    Local1 = RefOf (Local0)
267                    Local2 = RefOf (Local1)
268                    Local3 = RefOf (Local2)
269                    Local4 = RefOf (Local3)
270                    Local5 = RefOf (Local4)
271                    Local6 = RefOf (Local5)
272                    Local7 = RefOf (Local6)
273                    Local6 = DerefOf (Local7)
274                    Local5 = DerefOf (Local6)
275                    Local4 = DerefOf (Local5)
276                    Local3 = DerefOf (Local4)
277                    Local2 = DerefOf (Local3)
278                    Local1 = DerefOf (Local2)
279                    Local0 = DerefOf (Local1)
280                    Local7 = DerefOf (Local0)
281                    /* Create the chain of references to LocalX, */
282                    /* then dereference them. */
283                    Local0 = M1A5 (Local7)
284                }
285                Else
286                {
287                    Local0 = Arg0
288                }
289            }
290            Else
291            {
292                Local0 = Arg0
293            }
294
295            /* if(c089) */
296
297            If (C084)
298            {
299                /* run verification of references (reading) */
300
301                If (C089)
302                {
303                    /* Flag of Reference, object otherwise */
304                    /*
305                     * 17.2.5.9.1   ArgX Objects
306                     *
307                     * 1) Read from ArgX parameters
308                     *    ObjectReference - Automatic dereference, return
309                     *                      the target of the reference.
310                     *                      Use of DeRefOf returns the same.
311                     */
312                    If (C087)
313                    {
314                        /* "Use of DeRefOf returns the same" */
315
316                        Local2 = DerefOf (Local0)
317                    }
318                    Else
319                    {
320                        /* Automatic dereference */
321
322                        Local2 = Local0
323                    }
324                }
325                Else
326                {
327                    Local2 = Local0
328                }
329
330                /* if(c089) */
331
332                LPN0 = Arg2
333                While (LPN0)
334                {
335                    If ((LPN0 == 0x01))
336                    {
337                        Store (Local2 [Arg3], Local1)
338                    }
339                    Else
340                    {
341                        Store (Local2 [0x00], Local1)
342                    }
343
344                    Local2 = DerefOf (Local1)
345                    LPN0--
346                    LPC0++
347                }
348
349                Local0 = ObjectType (Local2)
350                If ((Local0 != Arg4))
351                {
352                    ERR (C080, Z076, __LINE__, 0x00, 0x00, Local0, Arg4)
353                }
354                ElseIf ((Local2 != Arg5))
355                {
356                    ERR (C080, Z076, __LINE__, 0x00, 0x00, Local2, Arg5)
357                }
358            }
359
360            /* if(c084) */
361            /* ATTENTION: exactly the same in m1a0 and m1a2 */
362            /* (but, don't replace it by call to Method) */
363            Method (M002, 1, NotSerialized)
364            {
365                Arg0 = 0xABCD001A
366            }
367
368            /* Run verification of references (write/read) */
369
370            If ((C083 == 0x01))
371            {
372                C08A = 0xABCD001A
373                Arg0 = C08A /* \C08A */
374            }
375            ElseIf ((C083 == 0x02))
376            {
377                C08A = 0xABCD001B
378                CopyObject (C08A, Arg0)
379            }
380            ElseIf ((C083 == 0x03))
381            {
382                C08A = 0xABCD001C
383                Arg0 = C08A /* \C08A */
384                C08A = 0xABCD001D
385                CopyObject (C08A, Arg0)
386            }
387
388            Local7 = 0x00
389            If ((C08B == 0x01))
390            {
391                Local0 = RefOf (Arg0)
392                Local1 = ObjectType (Local0)
393                If ((Local1 != Arg1))
394                {
395                    ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, Arg1)
396                }
397                Else
398                {
399                    Local7 = 0x01
400                }
401            }
402            ElseIf ((C08B == 0x02))
403            {
404                Local1 = CondRefOf (Arg0, Local0)
405                If ((Local1 != Ones))
406                {
407                    ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, Arg1)
408                }
409                Else
410                {
411                    Local1 = ObjectType (Local0)
412                    If ((Local1 != Arg1))
413                    {
414                        ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, Arg1)
415                    }
416                    Else
417                    {
418                        Local7 = 0x01
419                    }
420                }
421            }
422
423            If (Local7)
424            {
425                /* Obtain RefOf_Reference to ArgX */
426
427                Local0 = RefOf (Arg0)
428                Local1 = ObjectType (Local0)
429                If ((Local1 != Arg1))
430                {
431                    ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, Arg1)
432                }
433                Else
434                {
435                    /* Check DerefOf */
436
437                    Local1 = ObjectType (DerefOf (Local0))
438                    If ((Local1 != Arg1))
439                    {
440                        ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, Arg1)
441                    }
442
443                    /* Check that writing into M2-ArgX-RefOf_Reference */
444                    /* changes the original object (M1-ArgX): */
445                    M002 (Local0)
446                    Local1 = ObjectType (Arg0)
447                    If ((Local1 != C009))
448                    {
449                        ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, C009)
450                    }
451                    ElseIf ((Arg0 != 0xABCD001A))
452                    {
453                        ERR (C080, Z076, __LINE__, 0x00, 0x00, Arg0, 0xABCD001A)
454                    }
455                    Else
456                    {
457                        /* Check that M1-LocalX-RefOf_Reference remains */
458                        /* up to date after writing into M2-ArgX in M2 and */
459                        /* thus updating the contents of the object */
460                        /* referenced by M1-LocalX. */
461                        Local1 = ObjectType (Local0)
462                        If ((Local1 != C009))
463                        {
464                            ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, C009)
465                        }
466                        Else
467                        {
468                            Local1 = SizeOf (Local0)
469                            If ((Local1 != ISZ0))
470                            {
471                                ERR (C080, Z076, __LINE__, 0x00, 0x00, Local1, ISZ0)
472                            }
473                        }
474                    }
475                }
476            }
477        }
478
479        RST0 ()
480    }
481
482    /* Check only Boolean (CondRefOf) */
483    /* arg0 - returned Boolean */
484    /* arg1 - index of checking (inside the file) */
485    Method (M1A4, 2, NotSerialized)
486    {
487        SET0 (C081, 0x00, Arg1)
488        Local7 = 0x01
489        Local0 = ObjectType (Arg0)
490        If ((Local0 != C009))
491        {
492            ERR (C080, Z076, __LINE__, 0x00, 0x00, Local0, C009)
493            Local7 = 0x00
494        }
495        ElseIf ((Arg0 != Ones))
496        {
497            ERR (C080, Z076, __LINE__, 0x00, 0x00, Arg0, Ones)
498            Local7 = 0x00
499        }
500
501        RST0 ()
502        Return (Local7)
503    }
504
505    /* Create the chain of references to LocalX, then dereference them */
506
507    Method (M1A5, 1, NotSerialized)
508    {
509        Local0 = RefOf (Arg0)
510        Local1 = RefOf (Local0)
511        Local2 = RefOf (Local1)
512        Local3 = RefOf (Local2)
513        Local4 = RefOf (Local3)
514        Local5 = RefOf (Local4)
515        Local6 = RefOf (Local5)
516        Local7 = RefOf (Local6)
517        Local6 = DerefOf (Local7)
518        Local5 = DerefOf (Local6)
519        Local4 = DerefOf (Local5)
520        Local3 = DerefOf (Local4)
521        Local2 = DerefOf (Local3)
522        Local1 = DerefOf (Local2)
523        Local0 = DerefOf (Local1)
524        Local7 = DerefOf (Local0)
525        Return (Local7)
526    }
527
528    /*
529     * Set Global variables assignment applied in the tests
530     *
531     * arg0 - c080 - name of test
532     * arg1 - c083 - run verification of references (write/read)
533     * arg2 - c084 - run verification of references (reading)
534     * arg3 - c085 - create the chain of references to LocalX, then dereference them
535     * arg4 - c087 - apply DeRefOf to ArgX-ObjectReference
536     * arg5 - c081 - absolute index of file initiating the checking
537     */
538    Method (M1AD, 6, NotSerialized)
539    {
540        Local0 = ObjectType (Arg0)
541        If ((Local0 == C00A))
542        {
543            C080 = Arg0
544        }
545
546        C083 = Arg1
547        C084 = Arg2
548        C085 = Arg3
549        C087 = Arg4
550        If (Arg5)
551        {
552            C081 = Arg5
553        }
554    }
555
556    /* Test skipped message */
557
558    Method (M1AE, 3, NotSerialized)
559    {
560        Concatenate ("Test ", Arg0, Local0)
561        Concatenate (Local0, " skipped due to the following issue:", Debug)
562        Concatenate ("   ", Arg1, Debug)
563        Local0 = ObjectType (Arg2)
564        If ((Local0 == C00A))
565        {
566            Concatenate ("   ", Arg2, Debug)
567        }
568    }
569