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 Data to Buffer 33 */ 34 35Name(z043, 43) 36 37// Integer 38 39// 32-bit 40Name(p320, Package() 41{ 42 0, 43 0x81, 44 0x8232, 45 0x76543201, 46 0xf89abcde, 47 0xffffffff, 48}) 49 50Name(p321, Package() 51{ 52 Buffer(4) {0x00, 0x00, 0x00, 0x00}, 53 Buffer(4) {0x81, 0x00, 0x00, 0x00}, 54 Buffer(4) {0x32, 0x82, 0x00, 0x00}, 55 Buffer(4) {0x01, 0x32, 0x54, 0x76}, 56 Buffer(4) {0xde, 0xbc, 0x9a, 0xf8}, 57 Buffer(4) {0xff, 0xff, 0xff, 0xff}, 58}) 59 60// 64-bit 61Name(p322, Package() 62{ 63 0, 64 0x81, 65 0x8232, 66 0x76543201, 67 0x8123456789, 68 0x8cdae2376890, 69 0x76543201fabcde, 70 0xabcdef9876543201, 71 0xffffffffffffffff, 72}) 73 74Name(p323, Package() 75{ 76 Buffer(8) {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 77 Buffer(8) {0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 78 Buffer(8) {0x32, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 79 Buffer(8) {0x01, 0x32, 0x54, 0x76, 0x00, 0x00, 0x00, 0x00}, 80 Buffer(8) {0x89, 0x67, 0x45, 0x23, 0x81, 0x00, 0x00, 0x00}, 81 Buffer(8) {0x90, 0x68, 0x37, 0xe2, 0xda, 0x8c, 0x00, 0x00}, 82 Buffer(8) {0xde, 0xbc, 0xfa, 0x01, 0x32, 0x54, 0x76, 0x00}, 83 Buffer(8) {0x01, 0x32, 0x54, 0x76, 0x98, 0xef, 0xcd, 0xab}, 84 Buffer(8) {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, 85}) 86 87// Buffer 88Name(p325, Package() 89{ 90 Buffer(1) {1}, 91 Buffer(4) {1, 2, 3, 4}, 92 Buffer(8) {1, 2, 3, 4, 5, 6, 7, 8}, 93 Buffer(128) { 94 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 95 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 96 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 97 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 98 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 99 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 100 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112, 101 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128}, 102 Buffer(200) { 103 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 104 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 105 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 106 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 107 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 108 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 109 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112, 110 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, 111 129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144, 112 145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160, 113 161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176, 114 177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192, 115 193,194,195,196,197,198,199,200}, 116 Buffer(257) { 117 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 118 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 119 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 120 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 121 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 122 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 123 97, 98, 99,100,101,102,103,104,105,106,107,108,109,110,111,112, 124 113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128, 125 129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144, 126 145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160, 127 161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176, 128 177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192, 129 193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208, 130 209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224, 131 225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240, 132 241,242,243,244,245,246,247,248,249,250,251,252,253,254,255, 0, 1}, 133}) 134 135// Verify type, length of the obtained buffer 136// call to m305 to check the contents 137Method(m320, 6) // ts, buffer, len, null, err, case 138{ 139 if (LNotequal(ObjectType(arg1), 3)) { 140 err(arg0, z043, arg3, 0, 0, arg2, "Type") 141 } else { 142 if (LNotEqual(Sizeof(arg1), Add(arg2, arg3))) { 143 err(arg0, z043, arg4, 0, 0, arg2, "Sizeof") 144 } else { 145 m305(arg0, arg1, arg2, arg4, arg5) 146 } 147 } 148} 149 150// Checking strings with different lengths 151Method(m321, 1, Serialized) 152{ 153 Name(LENS, Buffer() {200, 199, 129, 128, 127, 9, 8, 7, 1, 0}) 154 155 Store(0, Local1) 156 While (LLess(Local1, 10)) { 157 158 // Prepare benchmark buffer 159 160 Store(Derefof(Index(LENS, Local1)), Local0) 161 Store(Buffer(Local0){}, Local4) 162 m303(Local4, Local0) 163 164 // Convert benchmark buffer to string 165 166 Store(ToString(Local4), Local2) 167 168 // Create the same benchmark buffer anew 169 // with null character appended 170 171 Store(Buffer(Add(Local0, 1)){}, Local5) 172 m303(Local5, Local0) 173 Store(0, Index(Local5, Local0)) 174 175 // Convert string to buffer 176 177 ToBuffer(Local2, Local3) 178 179 // Verify obtained buffer with the benchmark one 180 181 if (LNotEqual(Local3, Local5)) { 182 err(arg0, z043, 2, 0, 0, Local0, "NotEqual") 183 } 184 185 // Check the source string was not corrupted 186 187 m307(arg0, Local2, Local0, 2, "Source") 188 189 // Check both buffers state too 190 191 m320(arg0, Local3, Local0, 1, 3, "Dest") 192 m320(arg0, Local4, Local0, 0, 4, "Test") 193 194 Increment(Local1) 195 } 196} 197 198// Checking buffers with different lengths 199// (zero length in the first order). 200Method(m322, 1, Serialized) 201{ 202 Name(LENS, Package() {0, 513}) 203 204 Store(0, Local1) 205 While (LLess(Local1, 2)) { 206 207 // Prepare benchmark buffer 208 209 Store(Derefof(Index(LENS, Local1)), Local0) 210 Store(Buffer(Local0){}, Local4) 211 m303(Local4, Local0) 212 213 /* 214 * // ToBuffer caused destroying of source buffer (passed 215 * // by Data parameter), so they are duplicated below. 216 * 217 * Store(Local4, Local5) 218 */ 219 220 ToBuffer(Local4, Local3) 221 222 if (LNotEqual(Local3, Local4)) { 223 err(arg0, z043, 3, 0, 0, Local0, "NotEqual") 224 } 225 226 // Check the buffers were not corrupted 227 // (because know Data parameter was) 228 229 m320(arg0, Local3, Local0, 0, 6, "Dest") 230 m320(arg0, Local4, Local0, 0, 7, "Source") 231 232 Increment(Local1) 233 } 234} 235 236// Run-method 237Method(TOB0,, Serialized) 238{ 239 Name(ts, "TOB0") 240 241 Store("TEST: TOB0, Convert Data to Buffer", Debug) 242 243 // From integer 244 245 if (LEqual(F64, 1)) { 246 m302(ts, 9, "p322", p322, p323, 1) 247 } else { 248 m302(ts, 6, "p320", p320, p321, 1) 249 } 250 251 // From string 252 253 m321(ts) 254 255 // From buffer 256 257 m322(ts) 258 259 m302(ts, 6, "p325", p325, p325, 1) 260} 261