]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* include/grub/types.h (grub_set_unaligned64): New function.
authorVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Thu, 7 Jun 2012 12:07:02 +0000 (14:07 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Thu, 7 Jun 2012 12:07:02 +0000 (14:07 +0200)
* util/grub-setup.c (write_rootdev): Use unaligned access functions.
(setup): Likewise.

ChangeLog
include/grub/types.h
util/grub-setup.c

index 7a8e185573e3d25d095f30273561d4c841354be2..edc0fa574c9e96dbf7f969286ec35de2c95884ed 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-06-07  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       * include/grub/types.h (grub_set_unaligned64): New function.
+       * util/grub-setup.c (write_rootdev): Use unaligned access functions.
+       (setup): Likewise.
+
 2012-06-06  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/disk/ieee1275/ofdisk.c (quiesce): New function.
index 3914f22a808cc4f84a2f7841befee4d2ca0507d5..3e677c6977dc4740c2bf38bd09fed04daaaee452 100644 (file)
@@ -290,4 +290,14 @@ static inline grub_uint64_t grub_get_unaligned64 (const void *ptr)
   return dd->d;
 }
 
+static inline void grub_set_unaligned64 (void *ptr, grub_uint64_t val)
+{
+  struct grub_unaligned_uint64_t
+  {
+    grub_uint64_t d;
+  } __attribute__ ((packed));
+  struct grub_unaligned_uint64_t *dd = (struct grub_unaligned_uint64_t *) ptr;
+  dd->d = val;
+}
+
 #endif /* ! GRUB_TYPES_HEADER */
index dad1c15f8fab53972d0759fe57aae51ae1c70611..085e8dffcfcbe9a046e03b1411e4198406c80902 100644 (file)
@@ -111,24 +111,23 @@ write_rootdev (char *core_img, grub_device_t root_dev,
 #ifdef GRUB_SETUP_BIOS
   {
     grub_uint8_t *boot_drive;
-    grub_disk_addr_t *kernel_sector;
+    void *kernel_sector;
     boot_drive = (grub_uint8_t *) (boot_img + GRUB_BOOT_MACHINE_BOOT_DRIVE);
-    kernel_sector = (grub_disk_addr_t *) (boot_img
-                                         + GRUB_BOOT_MACHINE_KERNEL_SECTOR);
+    kernel_sector = (boot_img + GRUB_BOOT_MACHINE_KERNEL_SECTOR);
 
     /* FIXME: can this be skipped?  */
     *boot_drive = 0xFF;
 
-    *kernel_sector = grub_cpu_to_le64 (first_sector);
+    grub_set_unaligned64 (kernel_sector, grub_cpu_to_le64 (first_sector));
   }
 #endif
 #ifdef GRUB_SETUP_SPARC64
   {
-    grub_disk_addr_t *kernel_byte;
-    kernel_byte = (grub_disk_addr_t *) (boot_img
-                                       + GRUB_BOOT_AOUT_HEADER_SIZE
-                                       + GRUB_BOOT_MACHINE_KERNEL_BYTE);
-    *kernel_byte = grub_cpu_to_be64 (first_sector << GRUB_DISK_SECTOR_BITS);
+    void *kernel_byte;
+    kernel_byte = (boot_img + GRUB_BOOT_AOUT_HEADER_SIZE
+                  + GRUB_BOOT_MACHINE_KERNEL_BYTE);
+    grub_set_unaligned64 (kernel_byte,
+                         grub_cpu_to_be64 (first_sector << GRUB_DISK_SECTOR_BITS));
   }
 #endif
 }
@@ -312,8 +311,8 @@ setup (const char *dir,
 
 #ifdef GRUB_SETUP_BIOS
   {
-    grub_uint16_t *boot_drive_check;
-    boot_drive_check = (grub_uint16_t *) (boot_img
+    grub_uint8_t *boot_drive_check;
+    boot_drive_check = (grub_uint8_t *) (boot_img
                                          + GRUB_BOOT_MACHINE_DRIVE_CHECK);
     /* Copy the possible DOS BPB.  */
     memcpy (boot_img + GRUB_BOOT_MACHINE_BPB_START,
@@ -324,8 +323,11 @@ setup (const char *dir,
        for buggy BIOSes which don't pass boot drive correctly. Instead,
        they pass 0x00 or 0x01 even when booted from 0x80.  */
     if (!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk))
-      /* Replace the jmp (2 bytes) with double nop's.  */
-      *boot_drive_check = 0x9090;
+      {
+       /* Replace the jmp (2 bytes) with double nop's.  */
+       boot_drive_check[0] = 0x90;
+       boot_drive_check[1] = 0x90;
+      }
   }
 #endif
 
@@ -526,13 +528,13 @@ setup (const char *dir,
                                                  - sizeof (*block));
 
     grub_size_t no_rs_length;
-    *(grub_uint32_t *) (core_img + GRUB_DISK_SECTOR_SIZE
-                       + GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY)
-      = grub_host_to_target32 (nsec * GRUB_DISK_SECTOR_SIZE - core_size);
+    grub_set_unaligned32 ((core_img + GRUB_DISK_SECTOR_SIZE
+                          + GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY),
+                         grub_host_to_target32 (nsec * GRUB_DISK_SECTOR_SIZE - core_size));
     no_rs_length = grub_target_to_host16 
-      (*(grub_uint16_t *) (core_img
-                          + GRUB_DISK_SECTOR_SIZE
-                          + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_LENGTH));
+      (grub_get_unaligned16 (core_img
+                            + GRUB_DISK_SECTOR_SIZE
+                            + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_LENGTH));
 
     if (no_rs_length == 0xffff)
       grub_util_error ("%s", _("core.img version mismatch"));