direct-io.hg

changeset 14361:7c0d7736f960

hvmloader: Avoid compile warnings char vs. unsigned char.
Avoid 'magic number' hardcoded string lengths.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Tue Mar 13 10:32:52 2007 +0000 (2007-03-13)
parents 1877857352ae
children 8cd8e9e4e1ad
files tools/firmware/hvmloader/acpi/acpi2_0.h tools/firmware/hvmloader/acpi/build.c
line diff
     1.1 --- a/tools/firmware/hvmloader/acpi/acpi2_0.h	Tue Mar 13 10:02:45 2007 +0000
     1.2 +++ b/tools/firmware/hvmloader/acpi/acpi2_0.h	Tue Mar 13 10:32:52 2007 +0000
     1.3 @@ -49,8 +49,8 @@ struct acpi_header {
     1.4      uint32_t length;
     1.5      uint8_t  revision;
     1.6      uint8_t  checksum;
     1.7 -    uint8_t  oem_id[6];
     1.8 -    uint8_t  oem_table_id[8];
     1.9 +    char     oem_id[6];
    1.10 +    char     oem_table_id[8];
    1.11      uint32_t oem_revision;
    1.12      uint32_t creator_id;
    1.13      uint32_t creator_revision;
    1.14 @@ -90,7 +90,7 @@ struct acpi_20_generic_address {
    1.15  struct acpi_10_rsdp {
    1.16      uint64_t signature;
    1.17      uint8_t  checksum;
    1.18 -    uint8_t  oem_id[6];
    1.19 +    char     oem_id[6];
    1.20      uint8_t  reserved;
    1.21      uint32_t rsdt_address;
    1.22  };
    1.23 @@ -101,7 +101,7 @@ struct acpi_10_rsdp {
    1.24  struct acpi_20_rsdp {
    1.25      uint64_t signature;
    1.26      uint8_t  checksum;
    1.27 -    uint8_t  oem_id[6];
    1.28 +    char     oem_id[6];
    1.29      uint8_t  revision;
    1.30      uint32_t rsdt_address;
    1.31      uint32_t length;
     2.1 --- a/tools/firmware/hvmloader/acpi/build.c	Tue Mar 13 10:02:45 2007 +0000
     2.2 +++ b/tools/firmware/hvmloader/acpi/build.c	Tue Mar 13 10:32:52 2007 +0000
     2.3 @@ -22,7 +22,8 @@
     2.4  #include "../util.h"
     2.5  #include <xen/hvm/e820.h>
     2.6  
     2.7 -#define align16(sz) (((sz) + 15) & ~15)
     2.8 +#define align16(sz)        (((sz) + 15) & ~15)
     2.9 +#define fixed_strcpy(d, s) strncpy((d), (s), sizeof(d))
    2.10  
    2.11  extern struct acpi_20_rsdp Rsdp;
    2.12  extern struct acpi_20_rsdt Rsdt;
    2.13 @@ -57,8 +58,8 @@ int construct_madt(struct acpi_20_madt *
    2.14      memset(madt, 0, sizeof(*madt));
    2.15      madt->header.signature    = ACPI_2_0_MADT_SIGNATURE;
    2.16      madt->header.revision     = ACPI_2_0_MADT_REVISION;
    2.17 -    strncpy(madt->header.oem_id, ACPI_OEM_ID, 6);
    2.18 -    strncpy(madt->header.oem_table_id, ACPI_OEM_TABLE_ID, 8);
    2.19 +    fixed_strcpy(madt->header.oem_id, ACPI_OEM_ID);
    2.20 +    fixed_strcpy(madt->header.oem_table_id, ACPI_OEM_TABLE_ID);
    2.21      madt->header.oem_revision = ACPI_OEM_REVISION;
    2.22      madt->header.creator_id   = ACPI_CREATOR_ID;
    2.23      madt->header.creator_revision = ACPI_CREATOR_REVISION;
    2.24 @@ -131,8 +132,8 @@ int construct_hpet(struct acpi_20_hpet *
    2.25      memset(hpet, 0, sizeof(*hpet));
    2.26      hpet->header.signature    = ACPI_2_0_HPET_SIGNATURE;
    2.27      hpet->header.revision     = ACPI_2_0_HPET_REVISION;
    2.28 -    strncpy(hpet->header.oem_id, ACPI_OEM_ID, 6);
    2.29 -    strncpy(hpet->header.oem_table_id, ACPI_OEM_TABLE_ID, 8);
    2.30 +    fixed_strcpy(hpet->header.oem_id, ACPI_OEM_ID);
    2.31 +    fixed_strcpy(hpet->header.oem_table_id, ACPI_OEM_TABLE_ID);
    2.32      hpet->header.oem_revision = ACPI_OEM_REVISION;
    2.33      hpet->header.creator_id   = ACPI_CREATOR_ID;
    2.34      hpet->header.creator_revision = ACPI_CREATOR_REVISION;
    2.35 @@ -150,6 +151,7 @@ int construct_processor_objects(uint8_t 
    2.36  {
    2.37      static const char pdat[13] = { 0x5b, 0x83, 0x0b, 0x50, 0x52 };
    2.38      static const char hex[] = "0123456789ABCDEF";
    2.39 +    static const char pr_scope[] = "\\_PR_";
    2.40      unsigned int i, length, nr_cpus = get_vcpu_nr();
    2.41      struct acpi_header *hdr;
    2.42      uint8_t *p = buf;
    2.43 @@ -161,8 +163,8 @@ int construct_processor_objects(uint8_t 
    2.44      hdr = (struct acpi_header *)p;
    2.45      hdr->signature = ASCII32('S','S','D','T');
    2.46      hdr->revision  = 2;
    2.47 -    strncpy(hdr->oem_id, ACPI_OEM_ID, 6);
    2.48 -    strncpy(hdr->oem_table_id, ACPI_OEM_TABLE_ID, 8);
    2.49 +    fixed_strcpy(hdr->oem_id, ACPI_OEM_ID);
    2.50 +    fixed_strcpy(hdr->oem_table_id, ACPI_OEM_TABLE_ID);
    2.51      hdr->oem_revision = ACPI_OEM_REVISION;
    2.52      hdr->creator_id = ACPI_CREATOR_ID;
    2.53      hdr->creator_revision = ACPI_CREATOR_REVISION;
    2.54 @@ -176,7 +178,7 @@ int construct_processor_objects(uint8_t 
    2.55      *p++ = 0x10;
    2.56  
    2.57      /* PkgLength (includes length bytes!). */
    2.58 -    length = 1 + 5 + (nr_cpus * sizeof(pdat));
    2.59 +    length = 1 + strlen(pr_scope) + (nr_cpus * sizeof(pdat));
    2.60      if ( length <= 0x3f )
    2.61      {
    2.62          *p++ = length;
    2.63 @@ -195,8 +197,8 @@ int construct_processor_objects(uint8_t 
    2.64      }
    2.65  
    2.66      /* NameString */
    2.67 -    strncpy(p, "\\_PR_", 5);
    2.68 -    p += 5;
    2.69 +    strncpy(p, pr_scope, strlen(pr_scope));
    2.70 +    p += strlen(pr_scope);
    2.71  
    2.72      /*
    2.73       * 3. Processor Objects.
    2.74 @@ -263,8 +265,8 @@ int construct_secondary_tables(uint8_t *
    2.75          tcpa->header.signature = ACPI_2_0_TCPA_SIGNATURE;
    2.76          tcpa->header.length    = sizeof(*tcpa);
    2.77          tcpa->header.revision  = ACPI_2_0_TCPA_REVISION;
    2.78 -        strncpy(tcpa->header.oem_id, ACPI_OEM_ID, 6);
    2.79 -        strncpy(tcpa->header.oem_table_id, ACPI_OEM_TABLE_ID, 8);
    2.80 +        fixed_strcpy(tcpa->header.oem_id, ACPI_OEM_ID);
    2.81 +        fixed_strcpy(tcpa->header.oem_table_id, ACPI_OEM_TABLE_ID);
    2.82          tcpa->header.oem_revision = ACPI_OEM_REVISION;
    2.83          tcpa->header.creator_id   = ACPI_CREATOR_ID;
    2.84          tcpa->header.creator_revision = ACPI_CREATOR_REVISION;