a5bd9f6
From 15fb0e0734d438c6873c00c0ec9838764414ae98 Mon Sep 17 00:00:00 2001
a5bd9f6
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f6
Date: Fri, 1 Feb 2013 21:45:39 +0100
a5bd9f6
Subject: [PATCH 147/364] 	* grub-core/commands/lsacpi.c: Show more info.
a5bd9f6
 Hide some boring parts 	unless they have unexpected values.
a5bd9f6
a5bd9f6
---
a5bd9f6
 ChangeLog                   |  5 ++++
a5bd9f6
 grub-core/commands/lsacpi.c | 70 ++++++++++++++++++++++++++++++++++++++-------
a5bd9f6
 2 files changed, 64 insertions(+), 11 deletions(-)
a5bd9f6
a5bd9f6
diff --git a/ChangeLog b/ChangeLog
a5bd9f6
index 26702c7..4141f6a 100644
a5bd9f6
--- a/ChangeLog
a5bd9f6
+++ b/ChangeLog
a5bd9f6
@@ -1,5 +1,10 @@
a5bd9f6
 2013-02-01  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
 
a5bd9f6
+	* grub-core/commands/lsacpi.c: Show more info. Hide some boring parts
a5bd9f6
+	unless they have unexpected values.
a5bd9f6
+
a5bd9f6
+2013-02-01  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f6
+
a5bd9f6
 	* grub-core/bus/usb/usb.c (grub_usb_device_attach): Add missing
a5bd9f6
 	grub_print_error.
a5bd9f6
 
a5bd9f6
diff --git a/grub-core/commands/lsacpi.c b/grub-core/commands/lsacpi.c
a5bd9f6
index 07c3f0d..1038479 100644
a5bd9f6
--- a/grub-core/commands/lsacpi.c
a5bd9f6
+++ b/grub-core/commands/lsacpi.c
a5bd9f6
@@ -44,7 +44,8 @@ static void
a5bd9f6
 disp_acpi_table (struct grub_acpi_table_header *t)
a5bd9f6
 {
a5bd9f6
   print_field (t->signature);
a5bd9f6
-  grub_printf ("%4" PRIuGRUB_UINT32_T "B rev=%u OEM=", t->length, t->revision);
a5bd9f6
+  grub_printf ("%4" PRIuGRUB_UINT32_T "B rev=%u chksum=0x%02x (%s) OEM=", t->length, t->revision, t->checksum,
a5bd9f6
+	       grub_byte_checksum (t, t->length) == 0 ? "valid" : "invalid");
a5bd9f6
   print_field (t->oemid);
a5bd9f6
   print_field (t->oemtable);
a5bd9f6
   grub_printf ("OEMrev=%08" PRIxGRUB_UINT32_T " ", t->oemrev);
a5bd9f6
@@ -66,39 +67,81 @@ disp_madt_table (struct grub_acpi_madt *t)
a5bd9f6
   d = t->entries;
a5bd9f6
   for (;len > 0; len -= d->len, d = (void *) ((grub_uint8_t *) d + d->len))
a5bd9f6
     {
a5bd9f6
-      grub_printf ("  type=%x l=%u ", d->type, d->len);
a5bd9f6
-
a5bd9f6
       switch (d->type)
a5bd9f6
 	{
a5bd9f6
+	case GRUB_ACPI_MADT_ENTRY_TYPE_LAPIC:
a5bd9f6
+	  {
a5bd9f6
+	    struct grub_acpi_madt_entry_lapic *dt = (void *) d;
a5bd9f6
+	    grub_printf ("  LAPIC ACPI_ID=%02x APIC_ID=%02x Flags=%08x\n",
a5bd9f6
+			 dt->acpiid, dt->apicid, dt->flags);
a5bd9f6
+	    if (dt->hdr.len != sizeof (*dt))
a5bd9f6
+	      grub_printf ("   table size mismatch %d != %d\n", dt->hdr.len, sizeof (*dt));
a5bd9f6
+	    break;
a5bd9f6
+	  }
a5bd9f6
+
a5bd9f6
+	case GRUB_ACPI_MADT_ENTRY_TYPE_IOAPIC:
a5bd9f6
+	  {
a5bd9f6
+	    struct grub_acpi_madt_entry_ioapic *dt = (void *) d;
a5bd9f6
+	    grub_printf ("  IOAPIC ID=%02x address=%08x GSI=%08x\n",
a5bd9f6
+			 dt->id, dt->address, dt->global_sys_interrupt);
a5bd9f6
+	    if (dt->hdr.len != sizeof (*dt))
a5bd9f6
+	      grub_printf ("   table size mismatch %d != %d\n", dt->hdr.len, sizeof (*dt));
a5bd9f6
+	    if (dt->pad)
a5bd9f6
+	      grub_printf ("   non-zero pad: %02x\n", dt->pad);
a5bd9f6
+	    break;
a5bd9f6
+	  }
a5bd9f6
+
a5bd9f6
 	case GRUB_ACPI_MADT_ENTRY_TYPE_INTERRUPT_OVERRIDE:
a5bd9f6
 	  {
a5bd9f6
 	    struct grub_acpi_madt_entry_interrupt_override *dt = (void *) d;
a5bd9f6
-	    grub_printf ("Int Override bus=%x src=%x GSI=%08x Flags=%04x\n",
a5bd9f6
+	    grub_printf ("  Int Override bus=%x src=%x GSI=%08x Flags=%04x\n",
a5bd9f6
 			 dt->bus, dt->source, dt->global_sys_interrupt,
a5bd9f6
 			 dt->flags);
a5bd9f6
+	    if (dt->hdr.len != sizeof (*dt))
a5bd9f6
+	      grub_printf ("   table size mismatch %d != %d\n", dt->hdr.len, sizeof (*dt));
a5bd9f6
 	  }
a5bd9f6
 	  break;
a5bd9f6
+
a5bd9f6
+	case GRUB_ACPI_MADT_ENTRY_TYPE_LAPIC_NMI:
a5bd9f6
+	  {
a5bd9f6
+	    struct grub_acpi_madt_entry_lapic_nmi *dt = (void *) d;
a5bd9f6
+	    grub_printf ("  LAPIC_NMI ACPI_ID=%02x Flags=%04x lint=%02x\n",
a5bd9f6
+			 dt->acpiid, dt->flags, dt->lint);
a5bd9f6
+	    if (dt->hdr.len != sizeof (*dt))
a5bd9f6
+	      grub_printf ("   table size mismatch %d != %d\n", dt->hdr.len, sizeof (*dt));
a5bd9f6
+	    break;
a5bd9f6
+	  }
a5bd9f6
+
a5bd9f6
 	case GRUB_ACPI_MADT_ENTRY_TYPE_SAPIC:
a5bd9f6
 	  {
a5bd9f6
 	    struct grub_acpi_madt_entry_sapic *dt = (void *) d;
a5bd9f6
-	    grub_printf ("IOSAPIC Id=%02x GSI=%08x Addr=%016" PRIxGRUB_UINT64_T
a5bd9f6
+	    grub_printf ("  IOSAPIC Id=%02x GSI=%08x Addr=%016" PRIxGRUB_UINT64_T
a5bd9f6
 			 "\n",
a5bd9f6
 			 dt->id, dt->global_sys_interrupt_base,
a5bd9f6
 			 dt->addr);
a5bd9f6
+	    if (dt->hdr.len != sizeof (*dt))
a5bd9f6
+	      grub_printf ("   table size mismatch %d != %d\n", dt->hdr.len, sizeof (*dt));
a5bd9f6
+	    if (dt->pad)
a5bd9f6
+	      grub_printf ("   non-zero pad: %02x\n", dt->pad);
a5bd9f6
+
a5bd9f6
 	  }
a5bd9f6
 	  break;
a5bd9f6
 	case GRUB_ACPI_MADT_ENTRY_TYPE_LSAPIC:
a5bd9f6
 	  {
a5bd9f6
 	    struct grub_acpi_madt_entry_lsapic *dt = (void *) d;
a5bd9f6
-	    grub_printf ("LSAPIC ProcId=%02x ID=%02x EID=%02x Flags=%x",
a5bd9f6
+	    grub_printf ("  LSAPIC ProcId=%02x ID=%02x EID=%02x Flags=%x",
a5bd9f6
 			 dt->cpu_id, dt->id, dt->eid, dt->flags);
a5bd9f6
 	    if (dt->flags & GRUB_ACPI_MADT_ENTRY_SAPIC_FLAGS_ENABLED)
a5bd9f6
 	      grub_printf (" Enabled\n");
a5bd9f6
 	    else
a5bd9f6
 	      grub_printf (" Disabled\n");
a5bd9f6
 	    if (d->len > sizeof (struct grub_acpi_madt_entry_sapic))
a5bd9f6
-	      grub_printf ("    UID val=%08x, Str=%s\n", dt->cpu_uid,
a5bd9f6
+	      grub_printf ("  UID val=%08x, Str=%s\n", dt->cpu_uid,
a5bd9f6
 			   dt->cpu_uid_str);
a5bd9f6
+	    if (dt->hdr.len != sizeof (*dt) + grub_strlen ((char *) dt->cpu_uid_str) + 1)
a5bd9f6
+	      grub_printf ("   table size mismatch %d != %d\n", dt->hdr.len, sizeof (*dt));
a5bd9f6
+	    if (dt->pad[0] || dt->pad[1] || dt->pad[2])
a5bd9f6
+	      grub_printf ("   non-zero pad: %02x%02x%02x\n", dt->pad[0], dt->pad[1], dt->pad[2]);
a5bd9f6
 	  }
a5bd9f6
 	  break;
a5bd9f6
 	case GRUB_ACPI_MADT_ENTRY_TYPE_PLATFORM_INT_SOURCE:
a5bd9f6
@@ -107,17 +150,18 @@ disp_madt_table (struct grub_acpi_madt *t)
a5bd9f6
 	    static const char * const platint_type[] =
a5bd9f6
 	      {"Nul", "PMI", "INIT", "CPEI"};
a5bd9f6
 
a5bd9f6
-	    grub_printf ("Platform INT flags=%04x type=%02x (%s)"
a5bd9f6
+	    grub_printf ("  Platform INT flags=%04x type=%02x (%s)"
a5bd9f6
 			 " ID=%02x EID=%02x\n",
a5bd9f6
 			 dt->flags, dt->inttype,
a5bd9f6
 			 (dt->inttype < ARRAY_SIZE (platint_type))
a5bd9f6
 			 ? platint_type[dt->inttype] : "??", dt->cpu_id,
a5bd9f6
 			 dt->cpu_eid);
a5bd9f6
-	    grub_printf ("      IOSAPIC Vec=%02x GSI=%08x source flags=%08x\n",
a5bd9f6
+	    grub_printf ("  IOSAPIC Vec=%02x GSI=%08x source flags=%08x\n",
a5bd9f6
 			 dt->sapic_vector, dt->global_sys_int, dt->src_flags);
a5bd9f6
 	  }
a5bd9f6
 	  break;
a5bd9f6
 	default:
a5bd9f6
+	  grub_printf ("  type=%x l=%u ", d->type, d->len);
a5bd9f6
 	  grub_printf (" ??\n");
a5bd9f6
 	}
a5bd9f6
     }
a5bd9f6
@@ -182,7 +226,7 @@ static void
a5bd9f6
 disp_acpi_rsdpv1 (struct grub_acpi_rsdp_v10 *rsdp)
a5bd9f6
 {
a5bd9f6
   print_field (rsdp->signature);
a5bd9f6
-  grub_printf ("chksum:%02x, OEM-ID: ", rsdp->checksum);
a5bd9f6
+  grub_printf ("chksum:%02x (%s), OEM-ID: ", rsdp->checksum, grub_byte_checksum (rsdp, sizeof (*rsdp)) == 0 ? "valid" : "invalid");
a5bd9f6
   print_field (rsdp->oemid);
a5bd9f6
   grub_printf ("rev=%d\n", rsdp->revision);
a5bd9f6
   grub_printf ("RSDT=%08" PRIxGRUB_UINT32_T "\n", rsdp->rsdt_addr);
a5bd9f6
@@ -192,8 +236,12 @@ static void
a5bd9f6
 disp_acpi_rsdpv2 (struct grub_acpi_rsdp_v20 *rsdp)
a5bd9f6
 {
a5bd9f6
   disp_acpi_rsdpv1 (&rsdp->rsdpv1);
a5bd9f6
-  grub_printf ("len=%d XSDT=%016" PRIxGRUB_UINT64_T "\n", rsdp->length,
a5bd9f6
+  grub_printf ("len=%d chksum=%02x (%s) XSDT=%016" PRIxGRUB_UINT64_T "\n", rsdp->length, rsdp->checksum, grub_byte_checksum (rsdp, rsdp->length) == 0 ? "valid" : "invalid",
a5bd9f6
 	       rsdp->xsdt_addr);
a5bd9f6
+  if (rsdp->length != sizeof (*rsdp))
a5bd9f6
+    grub_printf (" length mismatch %d != %d\n", rsdp->length, sizeof (*rsdp));
a5bd9f6
+  if (rsdp->reserved[0] || rsdp->reserved[1] || rsdp->reserved[2])
a5bd9f6
+    grub_printf (" non-zero reserved %02x%02x%02x\n", rsdp->reserved[0], rsdp->reserved[1], rsdp->reserved[2]);
a5bd9f6
 }
a5bd9f6
 
a5bd9f6
 static const struct grub_arg_option options[] = {
a5bd9f6
-- 
a5bd9f6
1.8.1.4
a5bd9f6