31004e
From 1b3ac6280e2c0ec4ad4aa9aae034075bb961d21c Mon Sep 17 00:00:00 2001
a5bd9f
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
a5bd9f
Date: Tue, 9 Apr 2013 19:19:19 +0200
f74b50
Subject: [PATCH 275/482] 	Fix ia64-efi image generation on big-endian
a5bd9f
 machines. Deduplicate 	some code while on it. 	Reported by: Leif Lindholm.
a5bd9f
a5bd9f
---
a5bd9f
 ChangeLog                       |   6 ++
a5bd9f
 grub-core/kern/ia64/dl.c        | 135 ++----------------------------
a5bd9f
 grub-core/kern/ia64/dl_helper.c | 159 +++++++++++++++++++++++++++++++++--
a5bd9f
 include/grub/ia64/reloc.h       |  42 ++++++++++
a5bd9f
 util/grub-mkimage.c             |   9 +-
a5bd9f
 util/grub-mkimagexx.c           | 178 +++++++---------------------------------
a5bd9f
 6 files changed, 243 insertions(+), 286 deletions(-)
a5bd9f
 create mode 100644 include/grub/ia64/reloc.h
a5bd9f
a5bd9f
diff --git a/ChangeLog b/ChangeLog
a5bd9f
index 083d86a..e45ca35 100644
a5bd9f
--- a/ChangeLog
a5bd9f
+++ b/ChangeLog
a5bd9f
@@ -1,3 +1,9 @@
a5bd9f
+2013-04-08  Vladimir Serbinenko  <phcoder@gmail.com>
a5bd9f
+
a5bd9f
+	Fix ia64-efi image generation on big-endian machines. Deduplicate
a5bd9f
+	some code while on it.
a5bd9f
+	Reported by: Leif Lindholm.
a5bd9f
+
a5bd9f
 2013-04-08  Andrey Borzenkov <arvidjaar@gmail.com>
a5bd9f
 
a5bd9f
 	* grub-core/Makefile.core.def: Add kern/elfXX.c to elf module
a5bd9f
diff --git a/grub-core/kern/ia64/dl.c b/grub-core/kern/ia64/dl.c
a5bd9f
index 7c22b0b..957ceaa 100644
a5bd9f
--- a/grub-core/kern/ia64/dl.c
a5bd9f
+++ b/grub-core/kern/ia64/dl.c
a5bd9f
@@ -23,6 +23,9 @@
a5bd9f
 #include <grub err.h="">
a5bd9f
 #include <grub mm.h="">
a5bd9f
 #include <grub i18n.h="">
a5bd9f
+#include <grub ia64="" reloc.h="">
a5bd9f
+
a5bd9f
+#define MASK19 ((1 << 19) - 1)
a5bd9f
 
a5bd9f
 /* Check if EHDR is a valid ELF header.  */
a5bd9f
 grub_err_t
a5bd9f
@@ -41,126 +44,6 @@ grub_arch_dl_check_header (void *ehdr)
a5bd9f
 
a5bd9f
 #pragma GCC diagnostic ignored "-Wcast-align"
a5bd9f
 
a5bd9f
-#define MASK20 ((1 << 20) - 1)
a5bd9f
-#define MASK19 ((1 << 19) - 1)
a5bd9f
-
a5bd9f
-struct unaligned_uint32
a5bd9f
-{
a5bd9f
-  grub_uint32_t val;
a5bd9f
-}  __attribute__ ((packed));
a5bd9f
-
a5bd9f
-static void
a5bd9f
-add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value)
a5bd9f
-{
a5bd9f
-  struct unaligned_uint32 *p;
a5bd9f
-  switch (addr & 3)
a5bd9f
-    {
a5bd9f
-    case 0:
a5bd9f
-      p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2);
a5bd9f
-      p->val = ((((((p->val >> 2) & MASK20) + value) & MASK20) << 2) 
a5bd9f
-		| (p->val & ~(MASK20 << 2)));
a5bd9f
-      break;
a5bd9f
-    case 1:
a5bd9f
-      p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7);
a5bd9f
-      p->val = ((((((p->val >> 3) & MASK20) + value) & MASK20) << 3)
a5bd9f
-		| (p->val & ~(MASK20 << 3)));
a5bd9f
-      break;
a5bd9f
-    case 2:
a5bd9f
-      p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12);
a5bd9f
-      p->val = ((((((p->val >> 4) & MASK20) + value) & MASK20) << 4)
a5bd9f
-		| (p->val & ~(MASK20 << 4)));
a5bd9f
-      break;
a5bd9f
-    }
a5bd9f
-}
a5bd9f
-
a5bd9f
-#define MASKF21 ( ((1 << 23) - 1) & ~((1 << 7) | (1 << 8)) )
a5bd9f
-
a5bd9f
-static grub_uint32_t
a5bd9f
-add_value_to_slot_21_real (grub_uint32_t a, grub_uint32_t value)
a5bd9f
-{
a5bd9f
-  grub_uint32_t high, mid, low, c;
a5bd9f
-  low  = (a & 0x00007f);
a5bd9f
-  mid  = (a & 0x7fc000) >> 7;
a5bd9f
-  high = (a & 0x003e00) << 7;
a5bd9f
-  c = (low | mid | high) + value;
a5bd9f
-  return (c & 0x7f) | ((c << 7) & 0x7fc000) | ((c >> 7) & 0x0003e00); //0x003e00
a5bd9f
-}
a5bd9f
-
a5bd9f
-static void
a5bd9f
-add_value_to_slot_21 (grub_addr_t addr, grub_uint32_t value)
a5bd9f
-{
a5bd9f
-  struct unaligned_uint32 *p;
a5bd9f
-  switch (addr & 3)
a5bd9f
-    {
a5bd9f
-    case 0:
a5bd9f
-      p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2);
a5bd9f
-      p->val = ((add_value_to_slot_21_real (((p->val >> 2) & MASKF21), value) & MASKF21) << 2) | (p->val & ~(MASKF21 << 2));
a5bd9f
-      break;
a5bd9f
-    case 1:
a5bd9f
-      p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7);
a5bd9f
-      p->val = ((add_value_to_slot_21_real (((p->val >> 3) & MASKF21), value) & MASKF21) << 3) | (p->val & ~(MASKF21 << 3));
a5bd9f
-      break;
a5bd9f
-    case 2:
a5bd9f
-      p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12);
a5bd9f
-      p->val = ((add_value_to_slot_21_real (((p->val >> 4) & MASKF21), value) & MASKF21) << 4) | (p->val & ~(MASKF21 << 4));
a5bd9f
-      break;
a5bd9f
-    }
a5bd9f
-}
a5bd9f
-
a5bd9f
-static const grub_uint8_t nopm[5] =
a5bd9f
-  {
a5bd9f
-    /* [MLX]       nop.m 0x0 */
a5bd9f
-    0x05, 0x00, 0x00, 0x00, 0x01
a5bd9f
-  };
a5bd9f
-
a5bd9f
-static const grub_uint8_t jump[0x20] =
a5bd9f
-  {
a5bd9f
-    /* ld8 r16=[r15],8 */
a5bd9f
-    0x02, 0x80, 0x20, 0x1e, 0x18, 0x14,
a5bd9f
-    /* mov r14=r1;; */
a5bd9f
-    0xe0, 0x00, 0x04, 0x00, 0x42, 0x00,
a5bd9f
-    /* nop.i 0x0 */
a5bd9f
-    0x00, 0x00, 0x04, 0x00,
a5bd9f
-    /* ld8 r1=[r15] */
a5bd9f
-    0x11, 0x08, 0x00, 0x1e, 0x18, 0x10,
a5bd9f
-    /* mov b6=r16 */
a5bd9f
-    0x60, 0x80, 0x04, 0x80, 0x03, 0x00,
a5bd9f
-    /* br.few b6;; */
a5bd9f
-    0x60, 0x00, 0x80, 0x00
a5bd9f
-  };
a5bd9f
-
a5bd9f
-struct ia64_trampoline
a5bd9f
-{
a5bd9f
-  /* nop.m */
a5bd9f
-  grub_uint8_t nop[5];
a5bd9f
-  /* movl r15 = addr*/
a5bd9f
-  grub_uint8_t addr_hi[6];
a5bd9f
-  grub_uint8_t e0;
a5bd9f
-  grub_uint8_t addr_lo[4];
a5bd9f
-  grub_uint8_t jump[0x20];
a5bd9f
-};
a5bd9f
-
a5bd9f
-static void
a5bd9f
-make_trampoline (struct ia64_trampoline *tr, grub_uint64_t addr)
a5bd9f
-{
a5bd9f
-  COMPILE_TIME_ASSERT (sizeof (struct ia64_trampoline)
a5bd9f
-		       == GRUB_IA64_DL_TRAMP_SIZE);
a5bd9f
-  grub_memcpy (tr->nop, nopm, sizeof (tr->nop));
a5bd9f
-  tr->addr_hi[0] = ((addr & 0xc00000) >> 16);
a5bd9f
-  tr->addr_hi[1] = (addr >> 24) & 0xff;
a5bd9f
-  tr->addr_hi[2] = (addr >> 32) & 0xff;
a5bd9f
-  tr->addr_hi[3] = (addr >> 40) & 0xff;
a5bd9f
-  tr->addr_hi[4] = (addr >> 48) & 0xff;
a5bd9f
-  tr->addr_hi[5] = (addr >> 56) & 0xff;
a5bd9f
-  tr->e0 = 0xe0;
a5bd9f
-  tr->addr_lo[0] = ((addr & 0x000f) << 4) | 0x01;
a5bd9f
-  tr->addr_lo[1] = (((addr & 0x0070) >> 4) | ((addr & 0x070000) >> 11)
a5bd9f
-		    | ((addr & 0x200000) >> 17));
a5bd9f
-  tr->addr_lo[2] = ((addr & 0x1f80) >> 5) | ((addr & 0x180000) >> 19);
a5bd9f
-  tr->addr_lo[3] = ((addr & 0xe000) >> 13) | 0x60;
a5bd9f
-  grub_memcpy (tr->jump, jump, sizeof (tr->jump));
a5bd9f
-}
a5bd9f
-
a5bd9f
 /* Relocate symbols.  */
a5bd9f
 grub_err_t
a5bd9f
 grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
a5bd9f
@@ -170,7 +53,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
a5bd9f
   Elf_Word entsize;
a5bd9f
   unsigned i;
a5bd9f
   grub_uint64_t *gp, *gpptr;
a5bd9f
-  struct ia64_trampoline *tr;
a5bd9f
+  struct grub_ia64_trampoline *tr;
a5bd9f
 
a5bd9f
   gp = (grub_uint64_t *) mod->base;
a5bd9f
   gpptr = (grub_uint64_t *) mod->got;
a5bd9f
@@ -230,13 +113,13 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
a5bd9f
 		  case R_IA64_PCREL21B:
a5bd9f
 		    {
a5bd9f
 		      grub_uint64_t noff;
a5bd9f
-		      make_trampoline (tr, value);
a5bd9f
+		      grub_ia64_make_trampoline (tr, value);
a5bd9f
 		      noff = ((char *) tr - (char *) (addr & ~3)) >> 4;
a5bd9f
-		      tr++;
a5bd9f
+		      tr = (struct grub_ia64_trampoline *) ((char *) tr + GRUB_IA64_DL_TRAMP_SIZE);
a5bd9f
 		      if (noff & ~MASK19)
a5bd9f
 			return grub_error (GRUB_ERR_BAD_OS,
a5bd9f
 					   "trampoline offset too big (%lx)", noff);
a5bd9f
-		      add_value_to_slot_20b (addr, noff);
a5bd9f
+		      grub_ia64_add_value_to_slot_20b (addr, noff);
a5bd9f
 		    }
a5bd9f
 		    break;
a5bd9f
 		  case R_IA64_SEGREL64LSB:
a5bd9f
@@ -250,7 +133,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
a5bd9f
 		    *(grub_uint64_t *) addr += value - addr;
a5bd9f
 		    break;
a5bd9f
 		  case R_IA64_GPREL22:
a5bd9f
-		    add_value_to_slot_21 (addr, value - (grub_addr_t) gp);
a5bd9f
+		    grub_ia64_add_value_to_slot_21 (addr, value - (grub_addr_t) gp);
a5bd9f
 		    break;
a5bd9f
 
a5bd9f
 		  case R_IA64_LTOFF22X:
a5bd9f
@@ -259,7 +142,7 @@ grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
a5bd9f
 		      value = *(grub_uint64_t *) sym->st_value + rel->r_addend;
a5bd9f
 		  case R_IA64_LTOFF_FPTR22:
a5bd9f
 		    *gpptr = value;
a5bd9f
-		    add_value_to_slot_21 (addr, (grub_addr_t) gpptr - (grub_addr_t) gp);
a5bd9f
+		    grub_ia64_add_value_to_slot_21 (addr, (grub_addr_t) gpptr - (grub_addr_t) gp);
a5bd9f
 		    gpptr++;
a5bd9f
 		    break;
a5bd9f
 
a5bd9f
diff --git a/grub-core/kern/ia64/dl_helper.c b/grub-core/kern/ia64/dl_helper.c
a5bd9f
index 9394e32..e2209ca 100644
a5bd9f
--- a/grub-core/kern/ia64/dl_helper.c
a5bd9f
+++ b/grub-core/kern/ia64/dl_helper.c
a5bd9f
@@ -22,9 +22,154 @@
a5bd9f
 #include <grub misc.h="">
a5bd9f
 #include <grub err.h="">
a5bd9f
 #include <grub mm.h="">
a5bd9f
+#include <grub i18n.h="">
a5bd9f
+#include <grub ia64="" reloc.h="">
a5bd9f
 
a5bd9f
 #pragma GCC diagnostic ignored "-Wcast-align"
a5bd9f
 
a5bd9f
+#define MASK20 ((1 << 20) - 1)
a5bd9f
+#define MASK3 (~(grub_addr_t) 3)
a5bd9f
+
a5bd9f
+void
a5bd9f
+grub_ia64_add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value)
a5bd9f
+{
a5bd9f
+  grub_uint32_t val;
a5bd9f
+  switch (addr & 3)
a5bd9f
+    {
a5bd9f
+    case 0:
a5bd9f
+      val = grub_le_to_cpu32 (grub_get_unaligned32 (((grub_uint8_t *)
a5bd9f
+						     (addr & MASK3) + 2)));
a5bd9f
+      val = (((((val & MASK20) + value) & MASK20) << 2) 
a5bd9f
+	    | (val & ~(MASK20 << 2)));
a5bd9f
+      grub_set_unaligned32 (((grub_uint8_t *) (addr & MASK3) + 2),
a5bd9f
+			    grub_cpu_to_le32 (val));
a5bd9f
+      break;
a5bd9f
+    case 1:
a5bd9f
+      val = grub_le_to_cpu32 (grub_get_unaligned32 (((grub_uint8_t *)
a5bd9f
+						     (addr & MASK3) + 7)));
a5bd9f
+      val = ((((((val >> 3) & MASK20) + value) & MASK20) << 3)
a5bd9f
+	    | (val & ~(MASK20 << 3)));
a5bd9f
+      grub_set_unaligned32 (((grub_uint8_t *) (addr & MASK3) + 7),
a5bd9f
+			    grub_cpu_to_le32 (val));
a5bd9f
+      break;
a5bd9f
+    case 2:
a5bd9f
+      val = grub_le_to_cpu32 (grub_get_unaligned32 (((grub_uint8_t *)
a5bd9f
+						     (addr & MASK3) + 12)));
a5bd9f
+      val = ((((((val >> 4) & MASK20) + value) & MASK20) << 4)
a5bd9f
+	    | (val & ~(MASK20 << 4)));
a5bd9f
+      grub_set_unaligned32 (((grub_uint8_t *) (addr & MASK3) + 12),
a5bd9f
+			    grub_cpu_to_le32 (val));
a5bd9f
+      break;
a5bd9f
+    }
a5bd9f
+}
a5bd9f
+
a5bd9f
+#define MASKF21 ( ((1 << 23) - 1) & ~((1 << 7) | (1 << 8)) )
a5bd9f
+
a5bd9f
+static grub_uint32_t
a5bd9f
+add_value_to_slot_21_real (grub_uint32_t a, grub_uint32_t value)
a5bd9f
+{
a5bd9f
+  grub_uint32_t high, mid, low, c;
a5bd9f
+  low  = (a & 0x00007f);
a5bd9f
+  mid  = (a & 0x7fc000) >> 7;
a5bd9f
+  high = (a & 0x003e00) << 7;
a5bd9f
+  c = (low | mid | high) + value;
a5bd9f
+  return (c & 0x7f) | ((c << 7) & 0x7fc000) | ((c >> 7) & 0x0003e00); //0x003e00
a5bd9f
+}
a5bd9f
+
a5bd9f
+void
a5bd9f
+grub_ia64_add_value_to_slot_21 (grub_addr_t addr, grub_uint32_t value)
a5bd9f
+{
a5bd9f
+  grub_uint32_t val;
a5bd9f
+  switch (addr & 3)
a5bd9f
+    {
a5bd9f
+    case 0:
a5bd9f
+      val = grub_le_to_cpu32 (grub_get_unaligned32 (((grub_uint8_t *)
a5bd9f
+						     (addr & MASK3) + 2)));
a5bd9f
+      val = ((add_value_to_slot_21_real (((val >> 2) & MASKF21), value)
a5bd9f
+	      & MASKF21) << 2) | (val & ~(MASKF21 << 2));
a5bd9f
+      grub_set_unaligned32 (((grub_uint8_t *) (addr & MASK3) + 2),
a5bd9f
+			    grub_cpu_to_le32 (val));
a5bd9f
+      break;
a5bd9f
+    case 1:
a5bd9f
+      val = grub_le_to_cpu32 (grub_get_unaligned32 (((grub_uint8_t *)
a5bd9f
+						     (addr & MASK3) + 7)));
a5bd9f
+      val = ((add_value_to_slot_21_real (((val >> 3) & MASKF21), value)
a5bd9f
+	      & MASKF21) << 3) | (val & ~(MASKF21 << 3));
a5bd9f
+      grub_set_unaligned32 (((grub_uint8_t *) (addr & MASK3) + 7),
a5bd9f
+			    grub_cpu_to_le32 (val));
a5bd9f
+      break;
a5bd9f
+    case 2:
a5bd9f
+      val = grub_le_to_cpu32 (grub_get_unaligned32 (((grub_uint8_t *)
a5bd9f
+						     (addr & MASK3) + 12)));
a5bd9f
+      val = ((add_value_to_slot_21_real (((val >> 4) & MASKF21), value)
a5bd9f
+	      & MASKF21) << 4) | (val & ~(MASKF21 << 4));
a5bd9f
+      grub_set_unaligned32 (((grub_uint8_t *) (addr & MASK3) + 12),
a5bd9f
+			    grub_cpu_to_le32 (val));
a5bd9f
+      break;
a5bd9f
+    }
a5bd9f
+}
a5bd9f
+
a5bd9f
+static const grub_uint8_t nopm[5] =
a5bd9f
+  {
a5bd9f
+    /* [MLX]       nop.m 0x0 */
a5bd9f
+    0x05, 0x00, 0x00, 0x00, 0x01
a5bd9f
+  };
a5bd9f
+
a5bd9f
+#ifdef GRUB_UTIL
a5bd9f
+static grub_uint8_t jump[0x20] =
a5bd9f
+  {
a5bd9f
+    /* [MMI]       add r15=r15,r1;; */
a5bd9f
+    0x0b, 0x78, 0x3c, 0x02, 0x00, 0x20,
a5bd9f
+    /* ld8 r16=[r15],8 */
a5bd9f
+    0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0,
a5bd9f
+    /* mov r14=r1;; */
a5bd9f
+    0x01, 0x08, 0x00, 0x84,
a5bd9f
+    /* 	[MIB]       ld8 r1=[r15] */
a5bd9f
+    0x11, 0x08, 0x00, 0x1e, 0x18, 0x10,
a5bd9f
+    /* mov b6=r16 */
a5bd9f
+    0x60, 0x80, 0x04, 0x80, 0x03, 0x00, 
a5bd9f
+    /* br.few b6;; */
a5bd9f
+    0x60, 0x00, 0x80, 0x00       	            
a5bd9f
+  };
a5bd9f
+#else
a5bd9f
+static const grub_uint8_t jump[0x20] =
a5bd9f
+  {
a5bd9f
+    /* ld8 r16=[r15],8 */
a5bd9f
+    0x02, 0x80, 0x20, 0x1e, 0x18, 0x14,
a5bd9f
+    /* mov r14=r1;; */
a5bd9f
+    0xe0, 0x00, 0x04, 0x00, 0x42, 0x00,
a5bd9f
+    /* nop.i 0x0 */
a5bd9f
+    0x00, 0x00, 0x04, 0x00,
a5bd9f
+    /* ld8 r1=[r15] */
a5bd9f
+    0x11, 0x08, 0x00, 0x1e, 0x18, 0x10,
a5bd9f
+    /* mov b6=r16 */
a5bd9f
+    0x60, 0x80, 0x04, 0x80, 0x03, 0x00,
a5bd9f
+    /* br.few b6;; */
a5bd9f
+    0x60, 0x00, 0x80, 0x00
a5bd9f
+  };
a5bd9f
+#endif
a5bd9f
+
a5bd9f
+void
a5bd9f
+grub_ia64_make_trampoline (struct grub_ia64_trampoline *tr, grub_uint64_t addr)
a5bd9f
+{
a5bd9f
+  COMPILE_TIME_ASSERT (sizeof (struct grub_ia64_trampoline)
a5bd9f
+		       == GRUB_IA64_DL_TRAMP_SIZE);
a5bd9f
+  grub_memcpy (tr->nop, nopm, sizeof (tr->nop));
a5bd9f
+  tr->addr_hi[0] = ((addr & 0xc00000) >> 16);
a5bd9f
+  tr->addr_hi[1] = (addr >> 24) & 0xff;
a5bd9f
+  tr->addr_hi[2] = (addr >> 32) & 0xff;
a5bd9f
+  tr->addr_hi[3] = (addr >> 40) & 0xff;
a5bd9f
+  tr->addr_hi[4] = (addr >> 48) & 0xff;
a5bd9f
+  tr->addr_hi[5] = (addr >> 56) & 0xff;
a5bd9f
+  tr->e0 = 0xe0;
a5bd9f
+  tr->addr_lo[0] = ((addr & 0x000f) << 4) | 0x01;
a5bd9f
+  tr->addr_lo[1] = (((addr & 0x0070) >> 4) | ((addr & 0x070000) >> 11)
a5bd9f
+		    | ((addr & 0x200000) >> 17));
a5bd9f
+  tr->addr_lo[2] = ((addr & 0x1f80) >> 5) | ((addr & 0x180000) >> 19);
a5bd9f
+  tr->addr_lo[3] = ((addr & 0xe000) >> 13) | 0x60;
a5bd9f
+  grub_memcpy (tr->jump, jump, sizeof (tr->jump));
a5bd9f
+}
a5bd9f
+
a5bd9f
 void
a5bd9f
 grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
a5bd9f
 				 grub_size_t *got)
a5bd9f
@@ -35,26 +180,26 @@ grub_ia64_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp,
a5bd9f
   unsigned i;
a5bd9f
 
a5bd9f
   /* Find a symbol table.  */
a5bd9f
-  for (i = 0, s = (Elf64_Shdr *) ((char *) e + grub_le_to_cpu32 (e->e_shoff));
a5bd9f
+  for (i = 0, s = (Elf64_Shdr *) ((char *) e + grub_le_to_cpu64 (e->e_shoff));
a5bd9f
        i < grub_le_to_cpu16 (e->e_shnum);
a5bd9f
        i++, s = (Elf64_Shdr *) ((char *) s + grub_le_to_cpu16 (e->e_shentsize)))
a5bd9f
-    if (grub_le_to_cpu32 (s->sh_type) == SHT_SYMTAB)
a5bd9f
+    if (s->sh_type == grub_cpu_to_le32_compile_time (SHT_SYMTAB))
a5bd9f
       break;
a5bd9f
 
a5bd9f
   if (i == grub_le_to_cpu16 (e->e_shnum))
a5bd9f
     return;
a5bd9f
 
a5bd9f
-  for (i = 0, s = (Elf64_Shdr *) ((char *) e + grub_le_to_cpu32 (e->e_shoff));
a5bd9f
+  for (i = 0, s = (Elf64_Shdr *) ((char *) e + grub_le_to_cpu64 (e->e_shoff));
a5bd9f
        i < grub_le_to_cpu16 (e->e_shnum);
a5bd9f
        i++, s = (Elf64_Shdr *) ((char *) s + grub_le_to_cpu16 (e->e_shentsize)))
a5bd9f
-    if (grub_le_to_cpu32 (s->sh_type) == SHT_RELA)
a5bd9f
+    if (s->sh_type == grub_cpu_to_le32_compile_time (SHT_RELA))
a5bd9f
       {
a5bd9f
 	Elf64_Rela *rel, *max;
a5bd9f
 
a5bd9f
-	for (rel = (Elf64_Rela *) ((char *) e + grub_le_to_cpu32 (s->sh_offset)),
a5bd9f
-	       max = rel + grub_le_to_cpu32 (s->sh_size) / grub_le_to_cpu16 (s->sh_entsize);
a5bd9f
+	for (rel = (Elf64_Rela *) ((char *) e + grub_le_to_cpu64 (s->sh_offset)),
a5bd9f
+	       max = rel + grub_le_to_cpu64 (s->sh_size) / grub_le_to_cpu64 (s->sh_entsize);
a5bd9f
 	     rel < max; rel++)
a5bd9f
-	  switch (ELF64_R_TYPE (grub_le_to_cpu32 (rel->r_info)))
a5bd9f
+	  switch (ELF64_R_TYPE (grub_le_to_cpu64 (rel->r_info)))
a5bd9f
 	    {
a5bd9f
 	    case R_IA64_PCREL21B:
a5bd9f
 	      cntt++;
a5bd9f
diff --git a/include/grub/ia64/reloc.h b/include/grub/ia64/reloc.h
a5bd9f
new file mode 100644
a5bd9f
index 0000000..4c02ab2
a5bd9f
--- /dev/null
a5bd9f
+++ b/include/grub/ia64/reloc.h
a5bd9f
@@ -0,0 +1,42 @@
a5bd9f
+/*
a5bd9f
+ *  GRUB  --  GRand Unified Bootloader
a5bd9f
+ *  Copyright (C) 2013  Free Software Foundation, Inc.
a5bd9f
+ *
a5bd9f
+ *  GRUB is free software: you can redistribute it and/or modify
a5bd9f
+ *  it under the terms of the GNU General Public License as published by
a5bd9f
+ *  the Free Software Foundation, either version 3 of the License, or
a5bd9f
+ *  (at your option) any later version.
a5bd9f
+ *
a5bd9f
+ *  GRUB is distributed in the hope that it will be useful,
a5bd9f
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
a5bd9f
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
a5bd9f
+ *  GNU General Public License for more details.
a5bd9f
+ *
a5bd9f
+ *  You should have received a copy of the GNU General Public License
a5bd9f
+ *  along with GRUB.  If not, see <http: www.gnu.org="" licenses=""/>.
a5bd9f
+ */
a5bd9f
+
a5bd9f
+#ifndef GRUB_IA64_RELOC_H
a5bd9f
+#define GRUB_IA64_RELOC_H 1
a5bd9f
+
a5bd9f
+struct grub_ia64_trampoline;
a5bd9f
+
a5bd9f
+void
a5bd9f
+grub_ia64_add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value);
a5bd9f
+void
a5bd9f
+grub_ia64_add_value_to_slot_21 (grub_addr_t addr, grub_uint32_t value);
a5bd9f
+void
a5bd9f
+grub_ia64_make_trampoline (struct grub_ia64_trampoline *tr, grub_uint64_t addr);
a5bd9f
+
a5bd9f
+struct grub_ia64_trampoline
a5bd9f
+{
a5bd9f
+  /* nop.m */
a5bd9f
+  grub_uint8_t nop[5];
a5bd9f
+  /* movl r15 = addr*/
a5bd9f
+  grub_uint8_t addr_hi[6];
a5bd9f
+  grub_uint8_t e0;
a5bd9f
+  grub_uint8_t addr_lo[4];
a5bd9f
+  grub_uint8_t jump[0x20];
a5bd9f
+};
a5bd9f
+
a5bd9f
+#endif
a5bd9f
diff --git a/util/grub-mkimage.c b/util/grub-mkimage.c
a5bd9f
index ecea5d4..dce2c29 100644
a5bd9f
--- a/util/grub-mkimage.c
a5bd9f
+++ b/util/grub-mkimage.c
a5bd9f
@@ -40,6 +40,7 @@
a5bd9f
 #include <stdlib.h>
a5bd9f
 #include <assert.h>
a5bd9f
 #include <grub efi="" pe32.h="">
a5bd9f
+#include <grub ia64="" reloc.h="">
a5bd9f
 
a5bd9f
 #define _GNU_SOURCE	1
a5bd9f
 #include <argp.h>
a5bd9f
@@ -1201,10 +1202,10 @@ generate_image (const char *dir, const char *prefix,
a5bd9f
 	    o->subsystem = grub_host_to_target16 (GRUB_PE32_SUBSYSTEM_EFI_APPLICATION);
a5bd9f
 
a5bd9f
 	    /* Do these really matter? */
a5bd9f
-	    o->stack_reserve_size = grub_host_to_target32 (0x10000);
a5bd9f
-	    o->stack_commit_size = grub_host_to_target32 (0x10000);
a5bd9f
-	    o->heap_reserve_size = grub_host_to_target32 (0x10000);
a5bd9f
-	    o->heap_commit_size = grub_host_to_target32 (0x10000);
a5bd9f
+	    o->stack_reserve_size = grub_host_to_target64 (0x10000);
a5bd9f
+	    o->stack_commit_size = grub_host_to_target64 (0x10000);
a5bd9f
+	    o->heap_reserve_size = grub_host_to_target64 (0x10000);
a5bd9f
+	    o->heap_commit_size = grub_host_to_target64 (0x10000);
a5bd9f
     
a5bd9f
 	    o->num_data_directories
a5bd9f
 	      = grub_host_to_target32 (GRUB_PE32_NUM_DATA_DIRECTORIES);
a5bd9f
diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c
a5bd9f
index 476d05e..b6b263d 100644
a5bd9f
--- a/util/grub-mkimagexx.c
a5bd9f
+++ b/util/grub-mkimagexx.c
a5bd9f
@@ -117,7 +117,7 @@ SUFFIX (relocate_symbols) (Elf_Ehdr *e, Elf_Shdr *sections,
a5bd9f
       if (image_target->elf_target == EM_IA_64 && ELF_ST_TYPE (sym->st_info)
a5bd9f
 	  == STT_FUNC)
a5bd9f
 	{
a5bd9f
-	  *jptr = sym->st_value;
a5bd9f
+	  *jptr = grub_host_to_target64 (sym->st_value);
a5bd9f
 	  sym->st_value = (char *) jptr - (char *) jumpers + jumpers_addr;
a5bd9f
 	  jptr++;
a5bd9f
 	  *jptr = 0;
a5bd9f
@@ -143,8 +143,8 @@ SUFFIX (get_symbol_address) (Elf_Ehdr *e, Elf_Shdr *s, Elf_Word i,
a5bd9f
   Elf_Sym *sym;
a5bd9f
 
a5bd9f
   sym = (Elf_Sym *) ((char *) e
a5bd9f
-		       + grub_target_to_host32 (s->sh_offset)
a5bd9f
-		       + i * grub_target_to_host32 (s->sh_entsize));
a5bd9f
+		       + grub_target_to_host (s->sh_offset)
a5bd9f
+		       + i * grub_target_to_host (s->sh_entsize));
a5bd9f
   return sym->st_value;
a5bd9f
 }
a5bd9f
 
a5bd9f
@@ -153,7 +153,7 @@ static Elf_Addr *
a5bd9f
 SUFFIX (get_target_address) (Elf_Ehdr *e, Elf_Shdr *s, Elf_Addr offset,
a5bd9f
 		    struct image_target_desc *image_target)
a5bd9f
 {
a5bd9f
-  return (Elf_Addr *) ((char *) e + grub_target_to_host32 (s->sh_offset) + offset);
a5bd9f
+  return (Elf_Addr *) ((char *) e + grub_target_to_host (s->sh_offset) + offset);
a5bd9f
 }
a5bd9f
 
a5bd9f
 #ifdef MKIMAGE_ELF64
a5bd9f
@@ -182,128 +182,6 @@ SUFFIX (count_funcs) (Elf_Ehdr *e, Elf_Shdr *symtab_section,
a5bd9f
 }
a5bd9f
 #endif
a5bd9f
 
a5bd9f
-#ifdef MKIMAGE_ELF64
a5bd9f
-struct unaligned_uint32
a5bd9f
-{
a5bd9f
-  grub_uint32_t val;
a5bd9f
-}  __attribute__ ((packed));
a5bd9f
-
a5bd9f
-#define MASK20 ((1 << 20) - 1)
a5bd9f
-#define MASK19 ((1 << 19) - 1)
a5bd9f
-#define MASK3 (~(grub_addr_t) 3)
a5bd9f
-
a5bd9f
-static void
a5bd9f
-add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value)
a5bd9f
-{
a5bd9f
-  struct unaligned_uint32 *p;
a5bd9f
-  switch (addr & 3)
a5bd9f
-    {
a5bd9f
-    case 0:
a5bd9f
-      p = (struct unaligned_uint32 *) ((addr & MASK3) + 2);
a5bd9f
-      p->val = ((((((p->val >> 2) & MASK20) + value) & MASK20) << 2) 
a5bd9f
-		| (p->val & ~(MASK20 << 2)));
a5bd9f
-      break;
a5bd9f
-    case 1:
a5bd9f
-      p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & MASK3) + 7);
a5bd9f
-      p->val = ((((((p->val >> 3) & MASK20) + value) & MASK20) << 3)
a5bd9f
-		| (p->val & ~(MASK20 << 3)));
a5bd9f
-      break;
a5bd9f
-    case 2:
a5bd9f
-      p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & MASK3) + 12);
a5bd9f
-      p->val = ((((((p->val >> 4) & MASK20) + value) & MASK20) << 4)
a5bd9f
-		| (p->val & ~(MASK20 << 4)));
a5bd9f
-      break;
a5bd9f
-    }
a5bd9f
-}
a5bd9f
-
a5bd9f
-#define MASKF21 ( ((1 << 23) - 1) & ~((1 << 7) | (1 << 8)) )
a5bd9f
-
a5bd9f
-static grub_uint32_t
a5bd9f
-add_value_to_slot_21_real (grub_uint32_t a, grub_uint32_t value)
a5bd9f
-{
a5bd9f
-  grub_uint32_t high, mid, low, c;
a5bd9f
-  low  = (a & 0x00007f);
a5bd9f
-  mid  = (a & 0x7fc000) >> 7;
a5bd9f
-  high = (a & 0x003e00) << 7;
a5bd9f
-  c = (low | mid | high) + value;
a5bd9f
-  return (c & 0x7f) | ((c << 7) & 0x7fc000) | ((c >> 7) & 0x0003e00); //0x003e00
a5bd9f
-}
a5bd9f
-
a5bd9f
-static void
a5bd9f
-add_value_to_slot_21 (grub_addr_t addr, grub_uint32_t value)
a5bd9f
-{
a5bd9f
-  struct unaligned_uint32 *p;
a5bd9f
-  switch (addr & 3)
a5bd9f
-    {
a5bd9f
-    case 0:
a5bd9f
-      p = (struct unaligned_uint32 *) ((addr & MASK3) + 2);
a5bd9f
-      p->val = ((add_value_to_slot_21_real (((p->val >> 2) & MASKF21), value) & MASKF21) << 2) | (p->val & ~(MASKF21 << 2));
a5bd9f
-      break;
a5bd9f
-    case 1:
a5bd9f
-      p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & MASK3) + 7);
a5bd9f
-      p->val = ((add_value_to_slot_21_real (((p->val >> 3) & MASKF21), value) & MASKF21) << 3) | (p->val & ~(MASKF21 << 3));
a5bd9f
-      break;
a5bd9f
-    case 2:
a5bd9f
-      p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & MASK3) + 12);
a5bd9f
-      p->val = ((add_value_to_slot_21_real (((p->val >> 4) & MASKF21), value) & MASKF21) << 4) | (p->val & ~(MASKF21 << 4));
a5bd9f
-      break;
a5bd9f
-    }
a5bd9f
-}
a5bd9f
-
a5bd9f
-
a5bd9f
-struct ia64_kernel_trampoline
a5bd9f
-{
a5bd9f
-  /* nop.m */
a5bd9f
-  grub_uint8_t nop[5];
a5bd9f
-  /* movl r15 = addr*/
a5bd9f
-  grub_uint8_t addr_hi[6];
a5bd9f
-  grub_uint8_t e0;
a5bd9f
-  grub_uint8_t addr_lo[4];
a5bd9f
-  grub_uint8_t jump[0x20];
a5bd9f
-};
a5bd9f
-
a5bd9f
-static grub_uint8_t nopm[5] =
a5bd9f
-  {
a5bd9f
-    /* [MLX]       nop.m 0x0 */
a5bd9f
-    0x05, 0x00, 0x00, 0x00, 0x01
a5bd9f
-  };
a5bd9f
-
a5bd9f
-static grub_uint8_t jump[0x20] =
a5bd9f
-  {
a5bd9f
-    /* [MMI]       add r15=r15,r1;; */
a5bd9f
-    0x0b, 0x78, 0x3c, 0x02, 0x00, 0x20,
a5bd9f
-    /* ld8 r16=[r15],8 */
a5bd9f
-    0x00, 0x41, 0x3c, 0x30, 0x28, 0xc0,
a5bd9f
-    /* mov r14=r1;; */
a5bd9f
-    0x01, 0x08, 0x00, 0x84,
a5bd9f
-    /* 	[MIB]       ld8 r1=[r15] */
a5bd9f
-    0x11, 0x08, 0x00, 0x1e, 0x18, 0x10,
a5bd9f
-    /* mov b6=r16 */
a5bd9f
-    0x60, 0x80, 0x04, 0x80, 0x03, 0x00, 
a5bd9f
-    /* br.few b6;; */
a5bd9f
-    0x60, 0x00, 0x80, 0x00       	            
a5bd9f
-  };
a5bd9f
-
a5bd9f
-static void
a5bd9f
-make_trampoline (struct ia64_kernel_trampoline *tr, grub_uint64_t addr)
a5bd9f
-{
a5bd9f
-  grub_memcpy (tr->nop, nopm, sizeof (tr->nop));
a5bd9f
-  tr->addr_hi[0] = ((addr & 0xc00000) >> 16);
a5bd9f
-  tr->addr_hi[1] = (addr >> 24) & 0xff;
a5bd9f
-  tr->addr_hi[2] = (addr >> 32) & 0xff;
a5bd9f
-  tr->addr_hi[3] = (addr >> 40) & 0xff;
a5bd9f
-  tr->addr_hi[4] = (addr >> 48) & 0xff;
a5bd9f
-  tr->addr_hi[5] = (addr >> 56) & 0xff;
a5bd9f
-  tr->e0 = 0xe0;
a5bd9f
-  tr->addr_lo[0] = ((addr & 0x000f) << 4) | 0x01;
a5bd9f
-  tr->addr_lo[1] = (((addr & 0x0070) >> 4) | ((addr & 0x070000) >> 11)
a5bd9f
-		    | ((addr & 0x200000) >> 17));
a5bd9f
-  tr->addr_lo[2] = ((addr & 0x1f80) >> 5) | ((addr & 0x180000) >> 19);
a5bd9f
-  tr->addr_lo[3] = ((addr & 0xe000) >> 13) | 0x60;
a5bd9f
-  grub_memcpy (tr->jump, jump, sizeof (tr->jump));
a5bd9f
-}
a5bd9f
-#endif
a5bd9f
-
a5bd9f
 /* Deal with relocation information. This function relocates addresses
a5bd9f
    within the virtual address space starting from 0. So only relative
a5bd9f
    addresses can be fully resolved. Absolute addresses must be relocated
a5bd9f
@@ -320,8 +198,9 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
a5bd9f
   Elf_Half i;
a5bd9f
   Elf_Shdr *s;
a5bd9f
 #ifdef MKIMAGE_ELF64
a5bd9f
-  struct ia64_kernel_trampoline *tr = (void *) (pe_target + tramp_off);
a5bd9f
+  struct grub_ia64_trampoline *tr = (void *) (pe_target + tramp_off);
a5bd9f
   grub_uint64_t *gpptr = (void *) (pe_target + got_off);
a5bd9f
+#define MASK19 ((1 << 19) - 1)
a5bd9f
 #endif
a5bd9f
 
a5bd9f
   for (i = 0, s = sections;
a5bd9f
@@ -352,9 +231,9 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
a5bd9f
 			strtab + grub_target_to_host32 (s->sh_name),
a5bd9f
 			strtab + grub_target_to_host32 (target_section->sh_name));
a5bd9f
 
a5bd9f
-	rtab_size = grub_target_to_host32 (s->sh_size);
a5bd9f
-	r_size = grub_target_to_host32 (s->sh_entsize);
a5bd9f
-	rtab_offset = grub_target_to_host32 (s->sh_offset);
a5bd9f
+	rtab_size = grub_target_to_host (s->sh_size);
a5bd9f
+	r_size = grub_target_to_host (s->sh_entsize);
a5bd9f
+	rtab_offset = grub_target_to_host (s->sh_offset);
a5bd9f
 	num_rs = rtab_size / r_size;
a5bd9f
 
a5bd9f
 	for (j = 0, r = (Elf_Rela *) ((char *) e + rtab_offset);
a5bd9f
@@ -375,7 +254,7 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
a5bd9f
 						    ELF_R_SYM (info), image_target);
a5bd9f
 
a5bd9f
             addend = (s->sh_type == grub_target_to_host32 (SHT_RELA)) ?
a5bd9f
-	      r->r_addend : 0;
a5bd9f
+	      grub_target_to_host (r->r_addend) : 0;
a5bd9f
 
a5bd9f
 	   switch (image_target->elf_target)
a5bd9f
 	     {
a5bd9f
@@ -461,14 +340,14 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
a5bd9f
 		case R_IA64_PCREL21B:
a5bd9f
 		  {
a5bd9f
 		    grub_uint64_t noff;
a5bd9f
-		    make_trampoline (tr, addend + sym_addr);
a5bd9f
+		    grub_ia64_make_trampoline (tr, addend + sym_addr);
a5bd9f
 		    noff = ((char *) tr - (char *) pe_target
a5bd9f
 			    - target_section_addr - (offset & ~3)) >> 4;
a5bd9f
 		    tr++;
a5bd9f
 		    if (noff & ~MASK19)
a5bd9f
 		      grub_util_error ("trampoline offset too big (%"
a5bd9f
 				       PRIxGRUB_UINT64_T ")", noff);
a5bd9f
-		    add_value_to_slot_20b ((grub_addr_t) target, noff);
a5bd9f
+		    grub_ia64_add_value_to_slot_20b ((grub_addr_t) target, noff);
a5bd9f
 		  }
a5bd9f
 		  break;
a5bd9f
 
a5bd9f
@@ -478,8 +357,8 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
a5bd9f
 		    Elf_Sym *sym;
a5bd9f
 
a5bd9f
 		    sym = (Elf_Sym *) ((char *) e
a5bd9f
-				       + grub_target_to_host32 (symtab_section->sh_offset)
a5bd9f
-				       + ELF_R_SYM (info) * grub_target_to_host32 (symtab_section->sh_entsize));
a5bd9f
+				       + grub_target_to_host (symtab_section->sh_offset)
a5bd9f
+				       + ELF_R_SYM (info) * grub_target_to_host (symtab_section->sh_entsize));
a5bd9f
 		    if (ELF_ST_TYPE (sym->st_info) == STT_FUNC)
a5bd9f
 		      sym_addr = grub_target_to_host64 (*(grub_uint64_t *) (pe_target
a5bd9f
 									    + sym->st_value
a5bd9f
@@ -487,15 +366,15 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
a5bd9f
 		  }
a5bd9f
 		case R_IA64_LTOFF_FPTR22:
a5bd9f
 		  *gpptr = grub_host_to_target64 (addend + sym_addr);
a5bd9f
-		  add_value_to_slot_21 ((grub_addr_t) target,
a5bd9f
-					(char *) gpptr - (char *) pe_target
a5bd9f
-					+ image_target->vaddr_offset);
a5bd9f
+		  grub_ia64_add_value_to_slot_21 ((grub_addr_t) target,
a5bd9f
+						  (char *) gpptr - (char *) pe_target
a5bd9f
+						  + image_target->vaddr_offset);
a5bd9f
 		  gpptr++;
a5bd9f
 		  break;
a5bd9f
 
a5bd9f
 		case R_IA64_GPREL22:
a5bd9f
-		  add_value_to_slot_21 ((grub_addr_t) target,
a5bd9f
-					addend + sym_addr);
a5bd9f
+		  grub_ia64_add_value_to_slot_21 ((grub_addr_t) target,
a5bd9f
+						  addend + sym_addr);
a5bd9f
 		  break;
a5bd9f
 		case R_IA64_PCREL64LSB:
a5bd9f
 		  *target = grub_host_to_target64 (grub_target_to_host64 (*target)
a5bd9f
@@ -514,7 +393,8 @@ SUFFIX (relocate_addresses) (Elf_Ehdr *e, Elf_Shdr *sections,
a5bd9f
 						   + addend + sym_addr);
a5bd9f
 		  grub_util_info ("relocating a direct entry to 0x%"
a5bd9f
 				  PRIxGRUB_UINT64_T " at the offset 0x%llx",
a5bd9f
-				  *target, (unsigned long long) offset);
a5bd9f
+				  grub_target_to_host64 (*target),
a5bd9f
+				  (unsigned long long) offset);
a5bd9f
 		  break;
a5bd9f
 
a5bd9f
 		  /* We treat LTOFF22X as LTOFF22, so we can ignore LDXMOV.  */
a5bd9f
@@ -650,8 +530,8 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
a5bd9f
 
a5bd9f
   for (i = 0, s = sections; i < num_sections;
a5bd9f
        i++, s = (Elf_Shdr *) ((char *) s + section_entsize))
a5bd9f
-    if ((s->sh_type == grub_cpu_to_le32 (SHT_REL)) ||
a5bd9f
-        (s->sh_type == grub_cpu_to_le32 (SHT_RELA)))
a5bd9f
+    if ((grub_target_to_host32 (s->sh_type) == SHT_REL) ||
a5bd9f
+        (grub_target_to_host32 (s->sh_type) == SHT_RELA))
a5bd9f
       {
a5bd9f
 	Elf_Rel *r;
a5bd9f
 	Elf_Word rtab_size, r_size, num_rs;
a5bd9f
@@ -662,9 +542,9 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
a5bd9f
 	grub_util_info ("translating the relocation section %s",
a5bd9f
 			strtab + grub_le_to_cpu32 (s->sh_name));
a5bd9f
 
a5bd9f
-	rtab_size = grub_le_to_cpu32 (s->sh_size);
a5bd9f
-	r_size = grub_le_to_cpu32 (s->sh_entsize);
a5bd9f
-	rtab_offset = grub_le_to_cpu32 (s->sh_offset);
a5bd9f
+	rtab_size = grub_target_to_host (s->sh_size);
a5bd9f
+	r_size = grub_target_to_host (s->sh_entsize);
a5bd9f
+	rtab_offset = grub_target_to_host (s->sh_offset);
a5bd9f
 	num_rs = rtab_size / r_size;
a5bd9f
 
a5bd9f
 	section_address = section_addresses[grub_le_to_cpu32 (s->sh_info)];
a5bd9f
@@ -676,8 +556,8 @@ SUFFIX (make_reloc_section) (Elf_Ehdr *e, void **out,
a5bd9f
 	    Elf_Addr info;
a5bd9f
 	    Elf_Addr offset;
a5bd9f
 
a5bd9f
-	    offset = grub_le_to_cpu32 (r->r_offset);
a5bd9f
-	    info = grub_le_to_cpu32 (r->r_info);
a5bd9f
+	    offset = grub_target_to_host (r->r_offset);
a5bd9f
+	    info = grub_target_to_host (r->r_info);
a5bd9f
 
a5bd9f
 	    /* Necessary to relocate only absolute addresses.  */
a5bd9f
 	    switch (image_target->elf_target)
a5bd9f
@@ -1027,7 +907,7 @@ SUFFIX (load_image) (const char *kernel_path, grub_size_t *exec_size,
a5bd9f
 	  *kernel_sz = ALIGN_UP (*kernel_sz, 16);
a5bd9f
 
a5bd9f
 	  grub_ia64_dl_get_tramp_got_size (e, &tramp, &got);
a5bd9f
-	  tramp *= sizeof (struct ia64_kernel_trampoline);
a5bd9f
+	  tramp *= sizeof (struct grub_ia64_trampoline);
a5bd9f
 
a5bd9f
 	  ia64_toff = *kernel_sz;
a5bd9f
 	  *kernel_sz += ALIGN_UP (tramp, 16);
a5bd9f
-- 
31004e
1.8.2.1
a5bd9f