Deleted Added
full compact
1/******************************************************************************
2 *
3 * Module Name: exconvrt - Object conversion routines
4 * $Revision: 32 $
4 * $Revision: 37 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.

--- 100 unchanged lines hidden (view full) ---

113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117
118#define __EXCONVRT_C__
119
120#include "acpi.h"
121#include "acparser.h"
122#include "acnamesp.h"
121#include "acinterp.h"
124#include "acevents.h"
122#include "amlcode.h"
126#include "acdispat.h"
123
124
125#define _COMPONENT ACPI_EXECUTER
126 ACPI_MODULE_NAME ("exconvrt")
127
128
129/*******************************************************************************
130 *

--- 13 unchanged lines hidden (view full) ---

144AcpiExConvertToInteger (
145 ACPI_OPERAND_OBJECT *ObjDesc,
146 ACPI_OPERAND_OBJECT **ResultDesc,
147 ACPI_WALK_STATE *WalkState)
148{
149 UINT32 i;
150 ACPI_OPERAND_OBJECT *RetDesc;
151 UINT32 Count;
156 char *Pointer;
152 UINT8 *Pointer;
153 ACPI_INTEGER Result;
158 UINT32 IntegerSize = sizeof (ACPI_INTEGER);
154 ACPI_STATUS Status;
155
156
157 ACPI_FUNCTION_TRACE_PTR ("ExConvertToInteger", ObjDesc);
158
159
164 switch (ObjDesc->Common.Type)
160 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
161 {
162 case ACPI_TYPE_INTEGER:
163 *ResultDesc = ObjDesc;
164 return_ACPI_STATUS (AE_OK);
165
166 case ACPI_TYPE_STRING:
171 Pointer = ObjDesc->String.Pointer;
167 Pointer = (UINT8 *) ObjDesc->String.Pointer;
168 Count = ObjDesc->String.Length;
169 break;
170
171 case ACPI_TYPE_BUFFER:
176 Pointer = (char *) ObjDesc->Buffer.Pointer;
172 Pointer = ObjDesc->Buffer.Pointer;
173 Count = ObjDesc->Buffer.Length;
174 break;
175
176 default:
177 return_ACPI_STATUS (AE_TYPE);
178 }
179
180 /*
185 * Create a new integer
186 */
187 RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
188 if (!RetDesc)
189 {
190 return_ACPI_STATUS (AE_NO_MEMORY);
191 }
192
193 /* Handle both ACPI 1.0 and ACPI 2.0 Integer widths */
194
195 if (WalkState->MethodNode->Flags & ANOBJ_DATA_WIDTH_32)
196 {
197 /*
198 * We are running a method that exists in a 32-bit ACPI table.
199 * Truncate the value to 32 bits by zeroing out the upper 32-bit field
200 */
201 IntegerSize = sizeof (UINT32);
202 }
203
204 /*
181 * Convert the buffer/string to an integer. Note that both buffers and
182 * strings are treated as raw data - we don't convert ascii to hex for
183 * strings.
184 *
185 * There are two terminating conditions for the loop:
186 * 1) The size of an integer has been reached, or
187 * 2) The end of the buffer or string has been reached
188 */
189 Result = 0;
190
191 /* Transfer no more than an integer's worth of data */
192
217 if (Count > IntegerSize)
193 if (Count > AcpiGbl_IntegerByteWidth)
194 {
219 Count = IntegerSize;
195 Count = AcpiGbl_IntegerByteWidth;
196 }
197
198 /*
199 * String conversion is different than Buffer conversion
200 */
225 switch (ObjDesc->Common.Type)
201 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
202 {
203 case ACPI_TYPE_STRING:
204
229 /* TBD: Need to use 64-bit ACPI_STRTOUL */
230
205 /*
206 * Convert string to an integer
207 * String must be hexadecimal as per the ACPI specification
208 */
235 Result = ACPI_STRTOUL (Pointer, NULL, 16);
209 Status = AcpiUtStrtoul64 ((char *) Pointer, 16, &Result);
210 if (ACPI_FAILURE (Status))
211 {
212 return_ACPI_STATUS (Status);
213 }
214 break;
215
216
217 case ACPI_TYPE_BUFFER:
218
219 /*
220 * Buffer conversion - we simply grab enough raw data from the
221 * buffer to fill an integer
222 */
223 for (i = 0; i < Count; i++)
224 {
225 /*
226 * Get next byte and shift it into the Result.
227 * Little endian is used, meaning that the first byte of the buffer
228 * is the LSB of the integer
229 */
230 Result |= (((ACPI_INTEGER) Pointer[i]) << (i * 8));
231 }
232 break;
233
234
235 default:
236 /* No other types can get here */
237 break;
238 }
239
240 /*
241 * Create a new integer
242 */
243 RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
244 if (!RetDesc)
245 {
246 return_ACPI_STATUS (AE_NO_MEMORY);
247 }
248
249 /* Save the Result, delete original descriptor, store new descriptor */
250
251 RetDesc->Integer.Value = Result;
252
253 if (*ResultDesc == ObjDesc)
254 {
255 if (WalkState->Opcode != AML_STORE_OP)
256 {

--- 23 unchanged lines hidden (view full) ---

280ACPI_STATUS
281AcpiExConvertToBuffer (
282 ACPI_OPERAND_OBJECT *ObjDesc,
283 ACPI_OPERAND_OBJECT **ResultDesc,
284 ACPI_WALK_STATE *WalkState)
285{
286 ACPI_OPERAND_OBJECT *RetDesc;
287 UINT32 i;
296 UINT32 IntegerSize = sizeof (ACPI_INTEGER);
288 UINT8 *NewBuf;
289
290
291 ACPI_FUNCTION_TRACE_PTR ("ExConvertToBuffer", ObjDesc);
292
293
303 switch (ObjDesc->Common.Type)
294 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
295 {
296 case ACPI_TYPE_INTEGER:
297
298 /*
308 * Create a new Buffer
299 * Create a new Buffer object
300 */
301 RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
302 if (!RetDesc)
303 {
304 return_ACPI_STATUS (AE_NO_MEMORY);
305 }
306
316 /* Handle both ACPI 1.0 and ACPI 2.0 Integer widths */
317
318 if (WalkState->MethodNode->Flags & ANOBJ_DATA_WIDTH_32)
319 {
320 /*
321 * We are running a method that exists in a 32-bit ACPI table.
322 * Use only 32 bits of the Integer for conversion.
323 */
324 IntegerSize = sizeof (UINT32);
325 }
326
307 /* Need enough space for one integer */
308
329 RetDesc->Buffer.Length = IntegerSize;
330 NewBuf = ACPI_MEM_CALLOCATE (IntegerSize);
309 NewBuf = ACPI_MEM_CALLOCATE (AcpiGbl_IntegerByteWidth);
310 if (!NewBuf)
311 {
312 ACPI_REPORT_ERROR
313 (("ExConvertToBuffer: Buffer allocation failure\n"));
314 AcpiUtRemoveReference (RetDesc);
315 return_ACPI_STATUS (AE_NO_MEMORY);
316 }
317
318 /* Copy the integer to the buffer */
319
341 for (i = 0; i < IntegerSize; i++)
320 for (i = 0; i < AcpiGbl_IntegerByteWidth; i++)
321 {
322 NewBuf[i] = (UINT8) (ObjDesc->Integer.Value >> (i * 8));
323 }
324
325 /* Complete buffer object initialization */
326
327 RetDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
328 RetDesc->Buffer.Pointer = NewBuf;
329 RetDesc->Buffer.Length = AcpiGbl_IntegerByteWidth;
330
331 /* Return the new buffer descriptor */
332
333 *ResultDesc = RetDesc;
334 break;
335
336
337 case ACPI_TYPE_STRING:

--- 33 unchanged lines hidden (view full) ---

371AcpiExConvertToAscii (
372 ACPI_INTEGER Integer,
373 UINT32 Base,
374 UINT8 *String)
375{
376 UINT32 i;
377 UINT32 j;
378 UINT32 k = 0;
395 UINT8 HexDigit;
379 char HexDigit;
380 ACPI_INTEGER Digit;
381 UINT32 Remainder;
382 UINT32 Length = sizeof (ACPI_INTEGER);
383 BOOLEAN LeadingZero = TRUE;
384
385
386 ACPI_FUNCTION_ENTRY ();
387

--- 5 unchanged lines hidden (view full) ---

393 Remainder = 0;
394 for (i = ACPI_MAX_DECIMAL_DIGITS; i > 0 ; i--)
395 {
396 /* Divide by nth factor of 10 */
397
398 Digit = Integer;
399 for (j = 1; j < i; j++)
400 {
417 AcpiUtShortDivide (&Digit, 10, &Digit, &Remainder);
401 (void) AcpiUtShortDivide (&Digit, 10, &Digit, &Remainder);
402 }
403
404 /* Create the decimal digit */
405
406 if (Digit != 0)
407 {
408 LeadingZero = FALSE;
409 }

--- 16 unchanged lines hidden (view full) ---

426 HexDigit = AcpiUtHexToAsciiChar (Integer, (j * 4));
427 if (HexDigit != ACPI_ASCII_ZERO)
428 {
429 LeadingZero = FALSE;
430 }
431
432 if (!LeadingZero)
433 {
450 String[k] = HexDigit;
434 String[k] = (UINT8) HexDigit;
435 k++;
436 }
437 }
438 break;
439
440 default:
441 break;
442 }

--- 36 unchanged lines hidden (view full) ---

479 UINT32 Base,
480 UINT32 MaxLength,
481 ACPI_WALK_STATE *WalkState)
482{
483 ACPI_OPERAND_OBJECT *RetDesc;
484 UINT32 i;
485 UINT32 Index;
486 UINT32 StringLength;
503 UINT32 IntegerSize = sizeof (ACPI_INTEGER);
487 UINT8 *NewBuf;
488 UINT8 *Pointer;
489
490
491 ACPI_FUNCTION_TRACE_PTR ("ExConvertToString", ObjDesc);
492
493
511 switch (ObjDesc->Common.Type)
494 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
495 {
496 case ACPI_TYPE_INTEGER:
497
515 /* Handle both ACPI 1.0 and ACPI 2.0 Integer widths */
516
517 if (WalkState->MethodNode->Flags & ANOBJ_DATA_WIDTH_32)
518 {
519 /*
520 * We are running a method that exists in a 32-bit ACPI table.
521 * Use only 32 bits of the Integer
522 */
523 IntegerSize = sizeof (UINT32);
524 }
525
526 StringLength = IntegerSize * 2;
498 StringLength = AcpiGbl_IntegerByteWidth * 2;
499 if (Base == 10)
500 {
501 StringLength = ACPI_MAX_DECIMAL_DIGITS;
502 }
503
504 /*
505 * Create a new String
506 */
507 RetDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
508 if (!RetDesc)
509 {
510 return_ACPI_STATUS (AE_NO_MEMORY);
511 }
512
513 /* Need enough space for one ASCII integer plus null terminator */
514
543 NewBuf = ACPI_MEM_CALLOCATE (StringLength + 1);
515 NewBuf = ACPI_MEM_CALLOCATE ((ACPI_SIZE) StringLength + 1);
516 if (!NewBuf)
517 {
518 ACPI_REPORT_ERROR
519 (("ExConvertToString: Buffer allocation failure\n"));
520 AcpiUtRemoveReference (RetDesc);
521 return_ACPI_STATUS (AE_NO_MEMORY);
522 }
523
552
524 /* Convert */
525
526 i = AcpiExConvertToAscii (ObjDesc->Integer.Value, Base, NewBuf);
527
528 /* Null terminate at the correct place */
529
530 if (MaxLength < i)
531 {

--- 49 unchanged lines hidden (view full) ---

581
582 /* String length is the lesser of the Max or the actual length */
583
584 if (MaxLength < StringLength)
585 {
586 StringLength = MaxLength;
587 }
588
618 NewBuf = ACPI_MEM_CALLOCATE (StringLength + 1);
589 NewBuf = ACPI_MEM_CALLOCATE ((ACPI_SIZE) StringLength + 1);
590 if (!NewBuf)
591 {
592 ACPI_REPORT_ERROR
593 (("ExConvertToString: Buffer allocation failure\n"));
594 AcpiUtRemoveReference (RetDesc);
595 return_ACPI_STATUS (AE_NO_MEMORY);
596 }
597
598 /*
599 * Convert each byte of the buffer to two ASCII characters plus a space.
600 */
601 Pointer = ObjDesc->Buffer.Pointer;
602 Index = 0;
603 for (i = 0, Index = 0; i < ObjDesc->Buffer.Length; i++)
604 {
634 Index = AcpiExConvertToAscii (Pointer[i], Base, &NewBuf[Index]);
605 Index = AcpiExConvertToAscii ((ACPI_INTEGER) Pointer[i], Base, &NewBuf[Index]);
606
607 NewBuf[Index] = ' ';
608 Index++;
609 }
610
611 /* Null terminate */
612
613 NewBuf [Index-1] = 0;
614 RetDesc->Buffer.Pointer = NewBuf;
615 RetDesc->String.Length = ACPI_STRLEN ((char *) NewBuf);
616
646
617 /* Return the new buffer descriptor */
618
619 if (*ResultDesc == ObjDesc)
620 {
621 if (WalkState->Opcode != AML_STORE_OP)
622 {
623 AcpiUtRemoveReference (ObjDesc);
624 }

--- 74 unchanged lines hidden (view full) ---

699 /*
700 * Named field can always handle conversions
701 */
702 break;
703
704 default:
705 /* No conversion allowed for these types */
706
737 if (DestinationType != SourceDesc->Common.Type)
707 if (DestinationType != ACPI_GET_OBJECT_TYPE (SourceDesc))
708 {
709 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
710 "Target does not allow conversion of type %s to %s\n",
741 AcpiUtGetTypeName ((SourceDesc)->Common.Type),
711 AcpiUtGetObjectTypeName (SourceDesc),
712 AcpiUtGetTypeName (DestinationType)));
713 Status = AE_TYPE;
714 }
715 }
716 break;
717
718
719 case ARGI_TARGETREF:

--- 25 unchanged lines hidden (view full) ---

745 case ACPI_TYPE_BUFFER:
746
747 /*
748 * The operand must be a Buffer. We can convert an
749 * Integer or String if necessary
750 */
751 Status = AcpiExConvertToBuffer (SourceDesc, ResultDesc, WalkState);
752 break;
753
754
755 default:
756 Status = AE_AML_INTERNAL;
757 break;
758 }
759 break;
760
761
762 case ARGI_REFERENCE:
763 /*
764 * CreateXxxxField cases - we are storing the field object into the name
765 */

--- 4 unchanged lines hidden (view full) ---

770 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
771 "Unknown Target type ID 0x%X Op %s DestType %s\n",
772 GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs),
773 WalkState->OpInfo->Name, AcpiUtGetTypeName (DestinationType)));
774
775 Status = AE_AML_INTERNAL;
776 }
777
803
778 /*
779 * Source-to-Target conversion semantics:
780 *
781 * If conversion to the target type cannot be performed, then simply
782 * overwrite the target with the new object and type.
783 */
784 if (Status == AE_TYPE)
785 {
786 Status = AE_OK;
787 }
788
789 return_ACPI_STATUS (Status);
790}
791
792