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