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     * Bug 63:
30     *
31     * SUMMARY
32     *
33     * String to Integer conversion contradicts new April 2005 Conversion Rules
34     *
35     * EXAMPLES
36     *
37     *    Add("0x1111", 0) returns 0x1111 but 0 is expected
38     *    Add("12345678901234560", 0x1111111111111111) causes AE_BAD_HEX_CONSTANT
39     *    Add("00000000000012345678", 0) returns 0x12345678 but 0x1234 is expected
40     *
41     * ROOT CAUSE
42     *
43     * SPECS (NEW, March 12 2005)
44     *
45     * String --> Integer
46     *
47     * If no integer object exists, a new integer is created.
48     * The integer is initialized to the value zero and the ASCII
49     * string is interpreted as a hexadecimal constant. Each string
50     * character is interpreted as a hexadecimal value (�0�-�9�, �A�-�F�, �a�-�f�),
51     * starting with the first character as the most significant digit and ending
52     * with the first non-hexadecimal character, end-of-string, or when the size
53     * of an integer is reached (8 characters for 32-bit integers and 16 characters
54     * for 64-bit integers). Note: the first non-hex character terminates the
55     * conversion without error, and a �0x� prefix is not allowed.
56     */
57    /*
58     * To be completed !!!!!!!
59     *
60     * What to do else below:
61     *
62     * 1. Set correct results in 32 and 64 bit modes (now it is not done!)
63     * 2. Change places of operands, that is use both:
64     Add("12345678", 0x11111111, Local0)
65     Add(0x11111111, "12345678", Local0)
66     * 3. Pass operators by parameters !!!!
67     * 4. Issues:
68     *    1) octal - 01232211
69     *    2) zeros at the beginning - 0000000abcdef
70     *    3) large hex image - abcdef123456789123456789
71     */
72    /*
73     Store("VVVVVVVVVVVVVVVVVVVVVVVVVV", Debug)
74     Store(0123, Debug)
75     Store(83, Debug)
76     Add(0x1234, 83, Local0)
77     Store(Local0, Debug)
78     return
79     */
80    /*
81     * All the possible attempts to confuse calculation
82     */
83    Method (MD74, 0, Serialized)
84    {
85        /* 8 decimal */
86
87        Local0 = ("12345678" + 0x11111111)
88        If ((Local0 != 0x23456789))
89        {
90            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x23456789)
91        }
92
93        /* 8 hex */
94
95        Local0 = ("abcdefab" + 0x11111111)
96        If ((Local0 != 0xBCDF00BC))
97        {
98            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xBCDF00BC)
99        }
100
101        /* 16 decimal */
102
103        Local0 = ("1234567890876543" + 0x1111111111111111)
104        If ((Local0 != 0x23456789A1987654))
105        {
106            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x23456789A1987654)
107        }
108
109        /* 16 hex */
110
111        Local0 = ("abcdefababcdfead" + 0x1111111111111111)
112        If ((Local0 != 0xBCDF00BCBCDF0FBE))
113        {
114            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xBCDF00BCBCDF0FBE)
115        }
116
117        /* 17 hex */
118
119        Local0 = ("1234567890123456z" + 0x1111111111111111)
120        If ((Local0 != 0x23456789A1234567))
121        {
122            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x23456789A1234567)
123        }
124
125        /* 17 hex (caused AE_BAD_HEX_CONSTANT, 28.09.2005) */
126
127        Local0 = ("12345678901234560" + 0x1111111111111111)
128        If ((Local0 != 0x23456789A1234567))
129        {
130            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x23456789A1234567)
131        }
132
133        /* Looks like octal, but should be treated as hex */
134
135        Local0 = ("01111" + 0x2222)
136        If ((Local0 != 0x3333))
137        {
138            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x3333)
139        }
140
141        /* The first zeros each must be put into value */
142
143        Local0 = ("000010234" + 0x00)
144        If ((Local0 != 0x00010234))
145        {
146            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x00010234)
147        }
148
149        Local0 = ("000000000000000010234" + 0x00)
150        If ((Local0 != 0x00010234))
151        {
152            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x00010234)
153        }
154
155        Local0 = ("00000000000000010234" + 0x00)
156        If ((Local0 != 0x00010234))
157        {
158            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x00010234)
159        }
160
161        Local0 = ("0000000010234" + 0x00)
162        If ((Local0 != 0x00010234))
163        {
164            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x00010234)
165        }
166
167        Local0 = ("000000010234" + 0x00)
168        If ((Local0 != 0x00010234))
169        {
170            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x00010234)
171        }
172
173        /* Non-complete 4 hex, should be extended with zeros */
174
175        Local0 = ("abcd" + 0x1111)
176        If ((Local0 != 0xBCDE))
177        {
178            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xBCDE)
179        }
180
181        /* Non-complete 5 decimal, should be extended with zeros */
182
183        Local0 = ("12345" + 0x1111)
184        If ((Local0 != 0x00013456))
185        {
186            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x00013456)
187        }
188
189        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
190        /* Too large, all hex, should be trancated */
191
192        Local0 = ("abcdef0123456789112233445566778890" + 0x00)
193        If (F64)
194        {
195            If ((Local0 != 0xABCDEF0123456789))
196            {
197                ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xABCDEF0123456789)
198            }
199        }
200        ElseIf ((Local0 != 0xABCDEF01))
201        {
202            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xABCDEF01)
203        }
204
205        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
206        /* Large, all hex, looks like octal, should be trancated */
207
208        Local0 = ("0abcdef0123456789112233445566778890" + 0x1234)
209        If (F64)
210        {
211            If ((Local0 != 0xABCDEF0123456789))
212            {
213                ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xABCDEF0123456789)
214            }
215        }
216        ElseIf ((Local0 != 0xABCDEF01))
217        {
218            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xABCDEF01)
219        }
220
221        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
222        /* Looks like usual hex, but 'x' terminates conversion */
223
224        Local0 = ("0x1111" + 0x2222)
225        If ((Local0 != 0x2222))
226        {
227            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x2222)
228        }
229
230        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
231        /* Empty string, no action - the relevant parameter of Add remains zero */
232
233        Local0 = ("" + 0xDE)
234        If ((Local0 != 0xDE))
235        {
236            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xDE)
237        }
238
239        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
240        /* Blank string, no action - the relevant parameter of Add remains zero */
241
242        Local0 = (" " + 0x0333)
243        If ((Local0 != 0x0333))
244        {
245            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x0333)
246        }
247
248        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
249        /* Blank string, no action - the relevant parameter of Add remains zero */
250
251        Local0 = ("                                " + 0x92)
252        If ((Local0 != 0x92))
253        {
254            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x92)
255        }
256
257        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
258        /* Conversion is terminated just by the first symbol (non-hex) though followed by hex-es, remains zero */
259
260        Local0 = ("k1234567" + 0x01E9)
261        If ((Local0 != 0x01E9))
262        {
263            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x01E9)
264        }
265
266        /* Conversion is terminated just by the first symbol (non-hex), single */
267
268        Local0 = ("k" + 0x000000ABCDEF0000)
269        If ((Local0 != 0x000000ABCDEF0000))
270        {
271            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x000000ABCDEF0000)
272        }
273
274        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
275        /* Looks like designation of hex (terminated by x) */
276
277        Local0 = ("0x" + 0x12345678)
278        If ((Local0 != 0x12345678))
279        {
280            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x12345678)
281        }
282
283        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
284        /* Special symbol in the hex designation (terminated by x) */
285
286        Local0 = ("x" + 0x00BC614E)
287        If ((Local0 != 0x00BC614E))
288        {
289            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x00BC614E)
290        }
291
292        /* Starts with the special symbol in the hex designation (terminated by x) */
293
294        Local0 = ("x12345" + 0x6F)
295        If ((Local0 != 0x6F))
296        {
297            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x6F)
298        }
299
300        /* No one hex, conversion is terminated just by the first symbol Z */
301
302        Local0 = ("ZZZZ" + 0x0001E240)
303        If ((Local0 != 0x0001E240))
304        {
305            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x0001E240)
306        }
307
308        /* Short <= 8, conversion is terminated by non-hex symbol Z */
309
310        Local0 = ("abcdZZZZ" + 0x11)
311        If ((Local0 != 0xABDE))
312        {
313            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xABDE)
314        }
315
316        /* Short <= 8, hex in the middle (terminated by Z) */
317
318        Local0 = ("ZQ123MMM" + 0x0001E240)
319        If ((Local0 != 0x0001E240))
320        {
321            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x0001E240)
322        }
323
324        /* Short <= 8, hex at the end (terminated by Z) */
325
326        Local0 = ("ZQMMM123" + 0x0001E240)
327        If ((Local0 != 0x0001E240))
328        {
329            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x0001E240)
330        }
331
332        /* Long exceeding 16, no one hex */
333
334        Local0 = ("zxswqrrrrrrrrrrrrrrtttttttttttttttttttttttttyyyyyyyyyyyyyyyyyyuuuuuuuuuuuuuuuuuuuuuuu" + 0x7B)
335        If ((Local0 != 0x7B))
336        {
337            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x7B)
338        }
339
340        /* Long exceeding 16, hex at the beginning */
341
342        Local0 = ("1234zxswqrrrrrrrrrrrrrrtttttttttttttttttttttttttyyyyyyyyyyyyyyyyyyuuuuuuuuuuuuuuuuuuuuuuu" + 0x53)
343        If ((Local0 != 0x1287))
344        {
345            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x1287)
346        }
347
348        /* Long exceeding 16, hex everywhere */
349
350        Local0 = ("123z4s5qr6rr7rrrrrrrrr8ttttttt9ttttttattttbttttcyyyydyyeyyyyyyyyuuuuuuuuuuuuuuuuuuuuf" + 0x53)
351        If ((Local0 != 0x0176))
352        {
353            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x0176)
354        }
355
356        /* Long exceeding 16, hex at the end */
357
358        Local0 = ("zxswqrrrrrrrrrrrrrrtttttttttttttttttttttttttyyyyyyyyyyyyyyyyyyuuuuuuuuuuuuuuuuuuuuuuu1234" + 0x14D1)
359        If ((Local0 != 0x14D1))
360        {
361            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x14D1)
362        }
363
364        /* Long exceeding 16, hex in the middle inside the possible Integer */
365
366        Local0 = ("zx1234swqrrrrrrrrrrrrrrtttttttttttttttttttttttttyyyyyyyyyyyyyyyyyyuuuuuuuuuuuuuuuuuuuuuuu" + 0x00012321)
367        If ((Local0 != 0x00012321))
368        {
369            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x00012321)
370        }
371
372        /* Long exceeding 16, hex in the middle beyond the bounds of the possible Integer */
373
374        Local0 = ("zxswqrrrrrrrrrrrrrrtttttttttttttttttttttttttyyyyyyyyyyyyyyyyyyuuuuuuuuuuuuuuuuuuuuu1234uu" + 0x3021)
375        If ((Local0 != 0x3021))
376        {
377            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x3021)
378        }
379
380        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
381        /* Only decimal, much more than 16 */
382
383        Store (("123456789012345601112223334446667788990087654" + 0x00), Local1)
384        If (F64)
385        {
386            If ((Local0 != 0x1234567890123456))
387            {
388                ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x1234567890123456)
389            }
390        }
391        ElseIf ((Local0 != 0x12345678))
392        {
393            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x12345678)
394        }
395
396        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
397        /* Only hex, much more than 16 */
398
399        Store (("abcdefabcdefabcdefabcdefabcdefabcdefabcdefabc" + 0x00), Local1)
400        If (F64)
401        {
402            If ((Local0 != 0xABCDEFABCDEFABCD))
403            {
404                ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xABCDEFABCDEFABCD)
405            }
406        }
407        ElseIf ((Local0 != 0xABCDEFAB))
408        {
409            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xABCDEFAB)
410        }
411
412        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
413        /* Only decimal, much more than 16, non-hex at the end */
414
415        Store (("123456789012345601112223334446667788990087654ZZZZ" + 0x00), Local1)
416        If (F64)
417        {
418            If ((Local0 != 0x1234567890123456))
419            {
420                ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x1234567890123456)
421            }
422        }
423        ElseIf ((Local0 != 0x12345678))
424        {
425            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0x12345678)
426        }
427
428        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
429        /* Only hex, much more than 16, non-hex at the end */
430
431        Store (("abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcZZZZ" + 0x00), Local1)
432        If (F64)
433        {
434            If ((Local0 != 0xABCDEFABCDEFABCD))
435            {
436                ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xABCDEFABCDEFABCD)
437            }
438        }
439        ElseIf ((Local0 != 0xABCDEFAB))
440        {
441            ERR (__METHOD__, ZFFF, __LINE__, 0x00, 0x00, Local0, 0xABCDEFAB)
442        }
443
444        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
445    }
446
447    Method (MD75, 0, NotSerialized)
448    {
449        /* Do here the same as md74 but store Result by Store */
450    }
451
452    Method (MD76, 0, Serialized)
453    {
454        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
455        MD74 ()
456        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
457        MD75 ()
458        CH03 (__METHOD__, ZFFF, __LINE__, 0x00, 0x00)
459    }
460