Skip to content

Commit 63fc253

Browse files
century6Daniel Kiper
authored andcommitted
commands/acpi: Fix calculation of ACPI tables addresses when processing RSDT and XSDT
According to the ACPI specification the XSDT Entry field contains an array of 64-bit physical addresses which points to other DESCRIPTION_HEADERs. However, the entry_ptr iterator is defined as a 32-bit pointer. It means each 64-bit entry in the XSDT table is treated as two separate 32-bit entries then. Fix the issue by using correct addresses sizes when processing RSDT and XSDT tables. Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1 parent f201230 commit 63fc253

1 file changed

Lines changed: 22 additions & 11 deletions

File tree

grub-core/commands/acpi.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,12 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
490490

491491
if (rsdp)
492492
{
493-
grub_uint32_t *entry_ptr;
493+
grub_uint8_t *entry_ptr;
494494
char *exclude = 0;
495495
char *load_only = 0;
496496
char *ptr;
497-
/* RSDT consists of header and an array of 32-bit pointers. */
498-
struct grub_acpi_table_header *rsdt;
497+
grub_size_t tbl_addr_size;
498+
struct grub_acpi_table_header *table_head;
499499

500500
exclude = state[0].set ? grub_strdup (state[0].arg) : 0;
501501
if (exclude)
@@ -515,20 +515,31 @@ grub_cmd_acpi (struct grub_extcmd_context *ctxt, int argc, char **args)
515515
rev1 = ! rsdp->revision;
516516
rev2 = rsdp->revision;
517517
if (rev2 && ((struct grub_acpi_table_header *) (grub_addr_t) ((struct grub_acpi_rsdp_v20 *) rsdp)->xsdt_addr) != NULL)
518-
rsdt = (struct grub_acpi_table_header *) (grub_addr_t) ((struct grub_acpi_rsdp_v20 *) rsdp)->xsdt_addr;
518+
{
519+
/* XSDT consists of header and an array of 64-bit pointers. */
520+
table_head = (struct grub_acpi_table_header *) (grub_addr_t) ((struct grub_acpi_rsdp_v20 *) rsdp)->xsdt_addr;
521+
tbl_addr_size = sizeof (((struct grub_acpi_rsdp_v20 *) rsdp)->xsdt_addr);
522+
}
519523
else
520-
rsdt = (struct grub_acpi_table_header *) (grub_addr_t) rsdp->rsdt_addr;
524+
{
525+
/* RSDT consists of header and an array of 32-bit pointers. */
526+
table_head = (struct grub_acpi_table_header *) (grub_addr_t) rsdp->rsdt_addr;
527+
tbl_addr_size = sizeof (rsdp->rsdt_addr);
528+
}
521529

522530
/* Load host tables. */
523-
for (entry_ptr = (grub_uint32_t *) (rsdt + 1);
524-
entry_ptr < (grub_uint32_t *) (((grub_uint8_t *) rsdt)
525-
+ rsdt->length);
526-
entry_ptr++)
531+
for (entry_ptr = (grub_uint8_t *) (table_head + 1);
532+
entry_ptr < (grub_uint8_t *) (((grub_uint8_t *) table_head) + table_head->length);
533+
entry_ptr += tbl_addr_size)
527534
{
528535
char signature[5];
529536
struct efiemu_acpi_table *table;
530-
struct grub_acpi_table_header *curtable
531-
= (struct grub_acpi_table_header *) (grub_addr_t) *entry_ptr;
537+
struct grub_acpi_table_header *curtable;
538+
if (tbl_addr_size == sizeof (rsdp->rsdt_addr))
539+
curtable = (struct grub_acpi_table_header *) (grub_addr_t) *((grub_uint32_t *) entry_ptr);
540+
else
541+
curtable = (struct grub_acpi_table_header *) (grub_addr_t) *((grub_uint64_t *) entry_ptr);
542+
532543
signature[4] = 0;
533544
for (i = 0; i < 4;i++)
534545
signature[i] = grub_tolower (curtable->signature[i]);

0 commit comments

Comments
 (0)