* include/grub/types.h (grub_set_unaligned64): New function.

* util/grub-setup.c (write_rootdev): Use unaligned access functions.
	(setup): Likewise.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2012-06-07 14:07:02 +02:00
parent 7bc06a4995
commit 24bd8838f1
3 changed files with 37 additions and 19 deletions

View file

@ -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> 2012-06-06 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/disk/ieee1275/ofdisk.c (quiesce): New function. * grub-core/disk/ieee1275/ofdisk.c (quiesce): New function.

View file

@ -290,4 +290,14 @@ static inline grub_uint64_t grub_get_unaligned64 (const void *ptr)
return dd->d; 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 */ #endif /* ! GRUB_TYPES_HEADER */

View file

@ -111,24 +111,23 @@ write_rootdev (char *core_img, grub_device_t root_dev,
#ifdef GRUB_SETUP_BIOS #ifdef GRUB_SETUP_BIOS
{ {
grub_uint8_t *boot_drive; 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); boot_drive = (grub_uint8_t *) (boot_img + GRUB_BOOT_MACHINE_BOOT_DRIVE);
kernel_sector = (grub_disk_addr_t *) (boot_img kernel_sector = (boot_img + GRUB_BOOT_MACHINE_KERNEL_SECTOR);
+ GRUB_BOOT_MACHINE_KERNEL_SECTOR);
/* FIXME: can this be skipped? */ /* FIXME: can this be skipped? */
*boot_drive = 0xFF; *boot_drive = 0xFF;
*kernel_sector = grub_cpu_to_le64 (first_sector); grub_set_unaligned64 (kernel_sector, grub_cpu_to_le64 (first_sector));
} }
#endif #endif
#ifdef GRUB_SETUP_SPARC64 #ifdef GRUB_SETUP_SPARC64
{ {
grub_disk_addr_t *kernel_byte; void *kernel_byte;
kernel_byte = (grub_disk_addr_t *) (boot_img kernel_byte = (boot_img + GRUB_BOOT_AOUT_HEADER_SIZE
+ GRUB_BOOT_AOUT_HEADER_SIZE + GRUB_BOOT_MACHINE_KERNEL_BYTE);
+ GRUB_BOOT_MACHINE_KERNEL_BYTE); grub_set_unaligned64 (kernel_byte,
*kernel_byte = grub_cpu_to_be64 (first_sector << GRUB_DISK_SECTOR_BITS); grub_cpu_to_be64 (first_sector << GRUB_DISK_SECTOR_BITS));
} }
#endif #endif
} }
@ -312,8 +311,8 @@ setup (const char *dir,
#ifdef GRUB_SETUP_BIOS #ifdef GRUB_SETUP_BIOS
{ {
grub_uint16_t *boot_drive_check; grub_uint8_t *boot_drive_check;
boot_drive_check = (grub_uint16_t *) (boot_img boot_drive_check = (grub_uint8_t *) (boot_img
+ GRUB_BOOT_MACHINE_DRIVE_CHECK); + GRUB_BOOT_MACHINE_DRIVE_CHECK);
/* Copy the possible DOS BPB. */ /* Copy the possible DOS BPB. */
memcpy (boot_img + GRUB_BOOT_MACHINE_BPB_START, 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, for buggy BIOSes which don't pass boot drive correctly. Instead,
they pass 0x00 or 0x01 even when booted from 0x80. */ they pass 0x00 or 0x01 even when booted from 0x80. */
if (!allow_floppy && !grub_util_biosdisk_is_floppy (dest_dev->disk)) 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 #endif
@ -526,13 +528,13 @@ setup (const char *dir,
- sizeof (*block)); - sizeof (*block));
grub_size_t no_rs_length; grub_size_t no_rs_length;
*(grub_uint32_t *) (core_img + GRUB_DISK_SECTOR_SIZE grub_set_unaligned32 ((core_img + GRUB_DISK_SECTOR_SIZE
+ GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY) + GRUB_KERNEL_I386_PC_REED_SOLOMON_REDUNDANCY),
= grub_host_to_target32 (nsec * GRUB_DISK_SECTOR_SIZE - core_size); grub_host_to_target32 (nsec * GRUB_DISK_SECTOR_SIZE - core_size));
no_rs_length = grub_target_to_host16 no_rs_length = grub_target_to_host16
(*(grub_uint16_t *) (core_img (grub_get_unaligned16 (core_img
+ GRUB_DISK_SECTOR_SIZE + GRUB_DISK_SECTOR_SIZE
+ GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_LENGTH)); + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_LENGTH));
if (no_rs_length == 0xffff) if (no_rs_length == 0xffff)
grub_util_error ("%s", _("core.img version mismatch")); grub_util_error ("%s", _("core.img version mismatch"));