# ACPI Parsing

Shelter only support the ACPI v2 and newer ACPI specifications. That mean the XSDT pointer must exists.

## Root structures parsing

The root structures parsing is defined in `shelter/lib/include/devs/acpi.h` and implemented in `shelter/lib/src/devs/acpi.c`. 

The `sh_acpi_parse_rsdp()` function takes the RSDP and completes a `sh_apci_ACPI_POINTERS_ROOT` structure that look like this:
``` C
typedef struct {
  sh_uint64 rsdt;
  sh_uint64 xsdt;
} sh_apci_ACPI_POINTERS_ROOT;
```

Then, the `sh_acpi_parse_xsdt()` function takes the XSDT pointer and parses the XSDT header. It ensures that the structure isn't corrupted, and map all the entries. At the end, it completes this structure:
``` C
typedef struct {
  sh_uint64 *entries;
  sh_uint64 entry_count;
} sh_acpi_ACPI_XSDT_BODY;
```

Finally, the `sh_acpi_parse_tables()` takes the `sh_acpi_ACPI_XSDT_BODY` structure and parses all the entries. It ensures that at least the first pages of each table is mapped. All the tables pointers are sorted in a structure that look like this:
``` C
typedef struct {
  sh_uint64 madt_physical_address;
} sh_acpi_ACPI_TABLES;
```

## Tables parsing

The parsing of ACPI tables is delegated to several functions, one for each tables. Here are the tables that are currently supported:
- MADT

All parsing functions are defined in the files inside `shelter/lib/include/devs/acpi_tables` and in the files inside `shelter/lib/src/devs/acpi_tables`.

### MADT parsing

The MADT is parsed using the `sh_acpi_madt_parse(sh_uint64 madt_ptr)`, defined in `shelter/lib/include/devs/acpi_tables/madt.h` and implemented in `shelter/lib/src/devs/acpi_tables/madt.c`. 

This function logs all the entries and register all LAPIC devices, IOAPIC devices and ISOs.
