15#define AML_HEX_DIGITS "0123456789ABCDEF"
17#define AML_CONVERT_TRY_NEXT_CONVERTER 1
63 if (chr >=
'0' && chr <=
'9')
65 if (chr >=
'a' && chr <=
'f')
66 return chr -
'a' + 10;
67 if (chr >=
'A' && chr <=
'F')
68 return chr -
'A' + 10;
92 for (
uint64_t i = 0; i < maxBytes; i++)
122 if (i < bufferData->length - 1)
124 content[i * 3 + 2] =
' ';
136 if (
buffer->buffer.length == 0)
146 if (i < buffer->
buffer.length - 1)
172 for (
uint64_t i = 0; i < length; i++)
174 content[i] = (integerData->
value >> (i * 8)) & 0xFF;
251 if (i < package->package.length - 1)
272 for (
uint64_t i = 0; i < maxChars; i++)
279 value = value * 16 + digit;
310 bufferLength = stringData->
length + 1;
317 if (bufferLength > 0)
322 content[bufferLength - 1] = 0;
373 LOG_ERR(
"src/dest object is NULL\n");
380 LOG_ERR(
"source object is uninitialized\n");
399 LOG_ERR(
"failed to load FieldUnit\n");
407 LOG_ERR(
"failed to load BufferField\n");
413 if (tempType & allowedTypes)
417 LOG_ERR(
"failed to copy loaded field to destination\n");
423 return aml_convert(state, temp, dest, allowedTypes);
428 if (src->type & allowedTypes && (src->type == dest->type || dest->type ==
AML_UNINITIALIZED))
440 if (converters ==
NULL)
457 if (!(allowedTypes & entry->
destType))
493 LOG_ERR(
"result object is NULL\n");
500 LOG_ERR(
"result/target object is uninitialized\n");
545 LOG_ERR(
"src/dest object is NULL\n");
552 LOG_ERR(
"source object is uninitialized\n");
567 if (src->type & allowedTypes)
579 return aml_convert(state, src, *dest, allowedTypes);
602 LOG_ERR(
"src/dest object is NULL\n");
609 LOG_ERR(
"src object is uninitialized\n");
657 LOG_ERR(
"src/dest object is NULL\n");
664 LOG_ERR(
"src object is uninitialized\n");
703 if (bufferData->
length == 0)
714 char* buff =
malloc(maxLen + 1);
721 char* end = p + maxLen;
725 if (written < 0 || p + written >= end)
733 if (i < bufferData->length - 1 && p < end - 1)
763 LOG_ERR(
"src/dest object is NULL\n");
770 LOG_ERR(
"src object is uninitialized\n");
810 if (bufferData->
length == 0)
832 if (i < bufferData->length - 1)
834 content[i * 3 + 2] =
',';
853 LOG_ERR(
"src/dest object is NULL\n");
860 LOG_ERR(
"src object is uninitialized\n");
890 if (stringData->
length > 2 && stringData->
content[0] ==
'0' &&
899 for (; i < stringData->
length; i++)
901 char chr = stringData->
content[i];
910 value = value * 16 + digit;
914 if (chr >=
'0' && chr <=
'9')
916 value = value * 10 + (chr -
'0');
static uint64_t aml_buffer_to_string(aml_state_t *state, aml_object_t *buffer, aml_object_t *dest)
static uint64_t aml_string_to_integer(aml_state_t *state, aml_object_t *string, aml_object_t *dest)
static uint64_t aml_buffer_to_debug_object(aml_state_t *state, aml_object_t *buffer, aml_object_t *dest)
static uint64_t aml_string_prepare(aml_object_t *obj, uint64_t length)
static aml_convert_entry_t integerConverters[AML_TYPE_AMOUNT]
static uint64_t aml_integer_to_buffer(aml_state_t *state, aml_object_t *integer, aml_object_t *dest)
static uint64_t aml_package_to_debug_object(aml_state_t *state, aml_object_t *package, aml_object_t *dest)
static uint8_t aml_hex_to_byte(char chr)
static uint64_t aml_buffer_to_integer(aml_state_t *state, aml_object_t *buffer, aml_object_t *dest)
static uint64_t aml_string_to_buffer(aml_state_t *state, aml_object_t *string, aml_object_t *dest)
#define AML_CONVERT_TRY_NEXT_CONVERTER
static uint64_t aml_integer_to_string(aml_state_t *state, aml_object_t *integer, aml_object_t *dest)
static uint64_t aml_integer_to_buffer_field(aml_state_t *state, aml_object_t *integer, aml_object_t *dest)
static aml_convert_entry_t * aml_converters_get(aml_type_t srcType)
static uint64_t aml_buffer_to_buffer_field(aml_state_t *state, aml_object_t *buffer, aml_object_t *dest)
static aml_convert_entry_t packageConverters[AML_TYPE_AMOUNT]
static aml_convert_entry_t stringConverters[AML_TYPE_AMOUNT]
static void aml_byte_to_hex(uint8_t byte, char *dest)
static aml_convert_entry_t bufferConverters[AML_TYPE_AMOUNT]
uint64_t(* aml_convert_func_t)(aml_state_t *state, aml_object_t *src, aml_object_t *dest)
static uint64_t aml_integer_to_field_unit(aml_state_t *state, aml_object_t *integer, aml_object_t *dest)
static uint64_t aml_integer_to_debug_object(aml_state_t *state, aml_object_t *integer, aml_object_t *dest)
static uint64_t aml_string_to_debug_object(aml_state_t *state, aml_object_t *string, aml_object_t *dest)
uint64_t aml_buffer_field_load(aml_buffer_field_obj_t *bufferField, aml_object_t *out)
Read the value stored in a BufferField and store it in the out object.
uint64_t aml_buffer_field_store(aml_buffer_field_obj_t *bufferField, aml_object_t *in)
Write a value to a BufferField.
uint64_t aml_convert_to_decimal_string(aml_state_t *state, aml_object_t *src, aml_object_t **dest)
Converts a Integer, String or Buffer source object to a String destination object in decimal format.
uint64_t aml_convert(aml_state_t *state, aml_object_t *src, aml_object_t *dest, aml_type_t allowedTypes)
Converts the data in the source object to a allowed type and stores it in the destination object.
uint64_t aml_convert_result(aml_state_t *state, aml_object_t *result, aml_object_t *target)
Performs a "Implicit Result Object Conversion" acording to the rules in section 19....
uint64_t aml_convert_integer_to_bcd(aml_integer_t value, aml_integer_t *out)
Converts an integer to its Binary-Coded Decimal (BCD) representation.
uint64_t aml_convert_to_buffer(aml_state_t *state, aml_object_t *src, aml_object_t **dest)
Converts a Integer, String or Buffer source object to a Buffer destination object.
uint64_t aml_convert_to_hex_string(aml_state_t *state, aml_object_t *src, aml_object_t **dest)
Converts a Integer, String or Buffer source object to a String destination object in hexadecimal form...
uint64_t aml_convert_source(aml_state_t *state, aml_object_t *src, aml_object_t **dest, aml_type_t allowedTypes)
Performs a "Implicit Source Operand Conversion" acording to the rules in section 19....
uint64_t aml_convert_to_integer(aml_state_t *state, aml_object_t *src, aml_object_t **dest)
Converts a Integer, String or Buffer source object to an Integer destination object.
uint64_t aml_copy_data_and_type(aml_object_t *src, aml_object_t *dest)
Copies the data and type from the source object to the destination object, completly overwriting it.
uint64_t aml_field_unit_load(aml_state_t *state, aml_field_unit_obj_t *fieldUnit, aml_object_t *out)
Read the value stored in a FieldUnit. FieldUnits include Fields, IndexFields and BankFields.
uint64_t aml_field_unit_store(aml_state_t *state, aml_field_unit_obj_t *fieldUnit, aml_object_t *in)
Write a value to a FieldUnit. FieldUnits include Fields, IndexFields and BankFields.
uint64_t aml_integer_t
AML Integer type.
uint8_t aml_integer_byte_size(void) PURE_FUNC
Get the byte size of an AML integer.
uint64_t aml_string_resize(aml_string_obj_t *string, uint64_t newLength)
Resize a string object to the new length.
aml_type_t
ACPI data types.
uint64_t aml_integer_set(aml_object_t *object, aml_integer_t value)
Set a object as an integer with the given value and bit width.
aml_object_t * aml_object_new(void)
Allocate a new ACPI object.
uint64_t aml_buffer_set_empty(aml_object_t *object, uint64_t length)
Set a object as an empty buffer with the given length.
uint64_t aml_string_set_empty(aml_object_t *object, uint64_t length)
Set a object as an empty string with the given length.
uint64_t aml_buffer_set(aml_object_t *object, const uint8_t *buffer, uint64_t bytesToCopy, uint64_t length)
Set a object as a buffer with the given content.
@ AML_TYPE_AMOUNT
Not a type, just the amount of types.
@ AML_ARG
Not in the spec, used internally to represent method arguments.
@ AML_LOCAL
Not in the spec, used internally to represent method local variables.
uint64_t aml_store(aml_state_t *state, aml_object_t *src, aml_object_t *dest)
Store the value from the source object into the target object.
const char * aml_type_to_string(aml_type_t type)
Convert an aml data type to a string.
const char * aml_object_to_string(aml_object_t *object)
Convert an aml object to a string.
#define LOG_ERR(format,...)
#define LOG_INFO(format,...)
#define DEREF_DEFER(ptr)
RAII-style cleanup for scoped references.
#define REF(ptr)
Increment reference count.
#define DEREF(ptr)
Decrement reference count.
#define EINVAL
Invalid argument.
#define ENOSYS
Function not implemented.
#define errno
Error number variable.
#define EILSEQ
Illegal byte sequence.
#define NULL
Pointer error value.
#define ERR
Integer error value.
EFI_PHYSICAL_ADDRESS buffer
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
_PUBLIC void * memcpy(void *_RESTRICT s1, const void *_RESTRICT s2, size_t n)
aml_object_t * value
The object that was passed as the argument.
Data for a buffer object.
aml_convert_func_t convertFunc
Data for an integer object.
aml_object_t * value
The value of the local variable.
aml_buffer_field_obj_t bufferField
aml_integer_obj_t integer
aml_field_unit_obj_t fieldUnit
aml_package_obj_t package
Data for a string object.