• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /barrelfish-2018-10-04/lib/acpica/tests/aslts/src/runtime/collections/functional/manipulation/
1/*
2 * Some or all of this work - Copyright (c) 2006 - 2016, 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/*
30 * Data type conversion and manipulation
31 *
32 * Convert Buffer To String
33 */
34
35Name(z048, 48)
36
37Name(p330, Package()
38{
39	Buffer(8) {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
40	Buffer(200) {
41		  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
42		 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
43		 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
44		 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
45		 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
46		 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
47		 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112,
48		113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,
49		129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,
50		145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,
51		161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,
52		177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,
53		193,194,195,196,197,198,199,200},
54	Buffer(8) {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
55	Buffer(128) {
56		  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,
57		 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
58		 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
59		 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
60		 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
61		 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
62		 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112,
63		113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128},
64	Buffer(8) {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
65	Buffer(16) {1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16},
66	Buffer(8) {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
67	Buffer(8) {1,  2,  3,  4,  5,  6,  7,  8},
68	Buffer(8) {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
69	Buffer(4) {1,  2,  3,  4},
70	Buffer(8) {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
71	Buffer(1) {1},
72	Buffer(8) {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
73})
74
75Name(b330, Buffer(6) {200, 128, 16, 8, 4, 1})
76
77// Init buffer with the symbols 1-255
78Method(m303, 2)	// buf, len
79{
80	Store(0, Local0)
81	While (LLess(Local0, arg1)) {
82		Mod(Add(Local0, 1), 256, Local1)
83		Store(Local1, Index(arg0, Local0))
84		Increment(Local0)
85	}
86}
87
88// Verify the contents of result string
89Method(m305, 5)	// ts, string, len, err, case
90{
91	Store(0, Local0)
92	While (LLess(Local0, arg2)) {
93		Mod(Add(Local0, 1), 256, Local1)
94		if (LNotEqual(Derefof(Index(arg1, Local0)), Local1)) {
95			err(arg0, z048, arg3, 0, 0, Local0, arg4)
96		}
97		Increment(Local0)
98	}
99}
100
101// Verify type, length of the obtained string, call to m305
102Method(m307, 5)	// ts, string, len, ts, err, case
103{
104	if (LNotequal(ObjectType(arg1), 2)) {
105		err(arg0, z048, arg3, 0, 0, arg2, "Type")
106	} else {
107		if (LNotEqual(Sizeof(arg1), arg2)) {
108			err(arg0, z048, arg3, 0, 0, arg2, "Sizeof")
109		} else {
110			m305(arg0, arg1, arg2, arg3, arg4)
111		}
112	}
113}
114
115// Check the surrounding control buffers are safe
116Method(m309, 3)	// ts, indbuf, err
117{
118	// control buffer
119	Store(Derefof(Index(p330, arg1)), Local1)
120
121	Store(0, Local0)
122	While (LLess(Local0, 8)) {
123		if (LNotEqual(Derefof(Index(Local1, Local0)), 0xff)) {
124			err(arg0, z048, arg2, 0, 0, Local0, "buf8")
125		}
126		Increment(Local0)
127	}
128}
129
130// Check all positions of null character (0-200)
131Method(m30a, 1, Serialized)
132{
133	Name(LENS, Buffer() {200, 199, 129, 128, 127, 9, 8, 7, 1, 0})
134
135	Name(BUF0, Buffer(255){})
136
137	// Buffer (255 bytes) initialized with non-zero bytes
138
139	m303(BUF0, 255)
140
141	Store(0, Local1)
142
143	While (LLess(Local1, 10)) {
144
145		// Fill zero byte in position specified by LENS
146
147		Store(Derefof(Index(LENS, Local1)), Local0)
148		Store(Derefof(Index(BUF0, Local0)), Local5)
149		Store(0, Index(BUF0, Local0))
150
151		// The contents of buffer is not more changed in checkings below
152
153		// Checking for unspecified Length parameter
154
155		// Invoke ToString without Length
156
157		Store(ToString(BUF0), Local2)
158		m307(arg0, Local2, Local0, 1, "Omit")
159
160		// Invoke ToString with Ones
161
162		ToString(BUF0, Ones, Local2)
163		m307(arg0, Local2, Local0, 2, "Ones")
164
165		// Checking for particular values of Length parameter (0, 32, 64...)
166
167		Store(0, Local3) // Length
168		While (LLess(Local3, 401)) {
169
170			Store(Local0, Local4) // expected size
171			if (LLess(Local3, Local4)) {
172				Store(Local3, Local4)
173			}
174
175			ToString(BUF0, Local3, Local2)
176			m307(arg0, Local2, Local4, 3, "Size")
177
178			Add(Local3, 32, Local3)
179		}
180
181		// Restore position specified by LENS
182
183		Store(Local5, Index(BUF0, Local0))
184		Increment(Local1)
185	}
186}
187
188Method(m333, 1)
189{
190	Store(0, Local0)
191	Store(ToString(DerefOf(Arg0)), Local0)
192	Store(Local0, Debug)
193}
194
195// Check Buffer->Length effective condition.
196// Don't put null characters. Check the surrounding
197// control buffers are safe.
198Method(m30b, 1, Serialized)
199{
200	Name(Loc8, 0)
201
202	Store(0, Local5)	// index of control buffer 1
203
204	While (LLess(Loc8, 6)) {
205
206		// Choose the buffer from package
207
208		Store(Derefof(Index(b330, Loc8)), Local0)	// length
209		Multiply(Loc8, 2, Local1)			// index of a buffer
210		Add(Local1, 1, Local1)
211		Add(Local1, 1, Local6)				// index of control buffer 2
212		Store(Index(p330, Local1), Local4)		// ref to test buffer
213
214		// Checking for unspecified Length parameter
215
216		// Invoke ToString without Length
217
218		Store(ToString(Derefof(Local4)), Local2)
219		m307(arg0, Local2, Local0, 4, "Omit")
220		m309(arg0, Local5, 4)	// check control buffers
221		m309(arg0, Local6, 4)
222
223		// Invoke ToString with Ones
224
225		ToString(Derefof(Local4), Ones, Local2)
226		m307(arg0, Local2, Local0, 5, "Ones")
227		m309(arg0, Local5, 5)	// check control buffers
228		m309(arg0, Local6, 5)
229
230		// Checking for particular values of Length parameter
231		// exceeding (by 0, 1, 2, 3, ... 8) the actual lengths of Buffer
232
233		Add(Local0, 9, Local7) // Max. Length
234
235		Store(Local0, Local3) // Length
236		While (LLess(Local3, Local7)) {
237
238			ToString(Derefof(Local4), Local3, Local2)
239			m307(arg0, Local2, Local0, 6, "Size")
240
241			m309(arg0, Local5, 6)	// check control buffers
242			m309(arg0, Local6, 6)
243
244			Increment(Local3)
245		}
246		Store(Local6, Local5)
247
248		Increment(Loc8)
249	}
250}
251
252// Check zero length buffer, and, in passing,
253// dynamically allocated buffers.
254Method(m30c, 1, Serialized)
255{
256	Name(LENS, Buffer() {200, 199, 1, 0})
257
258	Store(0, Local1)
259	While (LLess(Local1, 4)) {
260
261
262		// Allocate buffer dynamically and initialize it,
263		// don't put null characters.
264
265		Store(Derefof(Index(LENS, Local1)), Local0)
266		Store(Buffer(Local0){}, Local4)
267		m303(Local4, Local0)
268
269		// Checking for unspecified Length parameter
270
271		// Invoke ToString without Length
272
273		Store(ToString(Local4), Local2)
274		m307(arg0, Local2, Local0, 7, "Omit")
275
276		// Invoke ToString with Ones
277
278		ToString(Local4, Ones, Local2)
279		m307(arg0, Local2, Local0, 8, "Ones")
280
281
282		// Allocate buffer of +1 size and put null characters
283		// into the last byte.
284
285		Store(Buffer(Add(Local0, 1)){}, Local4)
286		m303(Local4, Local0)
287		Store(0, Index(Local4, Local0))
288
289		// Invoke ToString without Length
290
291		Store(ToString(Local4), Local2)
292		m307(arg0, Local2, Local0, 9, "Omit")
293
294		// Invoke ToString with Ones
295
296		ToString(Local4, Ones, Local2)
297		m307(arg0, Local2, Local0, 10, "Ones")
298
299		Increment(Local1)
300	}
301}
302
303// Run-method
304Method(TOS0,, Serialized)
305{
306	Name(ts, "TOS0")
307
308	Store("TEST: TOS0, Convert Buffer To String", Debug)
309
310	m30a(ts)
311	m30b(ts)
312	m30c(ts)
313}
314
315