tools: add tool to decode AML files and build an ACPI namespace

This commit is contained in:
2023-07-19 19:00:27 +01:00
parent 42c6cfb697
commit f8c1a52259
16 changed files with 2446 additions and 1 deletions

72
tools/amldecode/table.c Normal file
View File

@@ -0,0 +1,72 @@
#include <stdio.h>
#include <stdlib.h>
#include "table.h"
enum loader_status acpi_table_load(const char *path, struct acpi_table **out)
{
FILE *fp = fopen(path, "rb");
if (!fp) {
return LOADER_IOERR;
}
fseek(fp, 0, SEEK_END);
size_t len = ftell(fp);
fseek(fp, 0, SEEK_SET);
unsigned char *buf = malloc(len);
if (!buf) {
fclose(fp);
return LOADER_NOMEM;
}
size_t r = fread(buf, 1, len, fp);
if (r != len) {
free(buf);
fclose(fp);
return LOADER_IOERR;
}
fclose(fp);
size_t sum = 0;
for (size_t i = 0; i < len; i++) {
sum += buf[i];
}
if ((sum % 0x100) != 0) {
free(buf);
return LOADER_BADSUM;
}
struct acpi_table *table = (struct acpi_table *)buf;
*out = table;
return LOADER_OK;
}
void acpi_table_destroy(struct acpi_table *table)
{
free(table);
}
void acpi_table_get_payload(struct acpi_table *table, void **p, size_t *len)
{
*p = (unsigned char *)table + sizeof *table;
*len = table->length;
}
#define STATUS_STRING(code) \
case code: \
return #code;
const char *loader_status_string(enum loader_status status)
{
switch (status) {
STATUS_STRING(LOADER_OK)
STATUS_STRING(LOADER_IOERR)
STATUS_STRING(LOADER_BADSUM)
STATUS_STRING(LOADER_NOMEM)
default:
return "<unknown>";
}
}