merge ia64-emu into ia64
This commit is contained in:
commit
7edf63fce6
45 changed files with 882 additions and 102 deletions
|
@ -74,6 +74,7 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/term.h
|
|||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/time.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/mm_private.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/boot.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h
|
||||
|
||||
if COND_i386_pc
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/memory.h
|
||||
|
@ -140,7 +141,6 @@ KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/font.h
|
|||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bitmap_scale.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/bufio.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/pci.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/cs5536.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/machine/pci.h
|
||||
KERNEL_HEADER_FILES += $(top_builddir)/include/grub/serial.h
|
||||
|
@ -148,11 +148,9 @@ endif
|
|||
|
||||
if COND_powerpc_ieee1275
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h
|
||||
endif
|
||||
|
||||
if COND_sparc64_ieee1275
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/libgcc.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/ieee1275/ieee1275.h
|
||||
KERNEL_HEADER_FILES += $(top_srcdir)/include/grub/sparc64/ieee1275/ieee1275.h
|
||||
endif
|
||||
|
|
|
@ -148,6 +148,7 @@ kernel = {
|
|||
mips_yeeloong = term/at_keyboard.c;
|
||||
mips_yeeloong = term/serial.c;
|
||||
mips_yeeloong = video/sm712.c;
|
||||
extra_dist = video/sm712_init.c;
|
||||
|
||||
powerpc_ieee1275 = kern/ieee1275/init.c;
|
||||
powerpc_ieee1275 = kern/powerpc/cache.S;
|
||||
|
@ -168,6 +169,7 @@ kernel = {
|
|||
emu = kern/emu/misc.c;
|
||||
emu = kern/emu/mm.c;
|
||||
emu = kern/emu/time.c;
|
||||
emu = kern/emu/cache.c;
|
||||
|
||||
videoinkernel = lib/arg.c;
|
||||
videoinkernel = term/gfxterm.c;
|
||||
|
@ -1058,6 +1060,9 @@ module = {
|
|||
powerpc = lib/powerpc/relocator_asm.S;
|
||||
powerpc = lib/powerpc/relocator.c;
|
||||
|
||||
extra_dist = lib/i386/relocator_common.S;
|
||||
extra_dist = kern/powerpc/cache_flush.S;
|
||||
|
||||
enable = mips;
|
||||
enable = powerpc;
|
||||
enable = x86;
|
||||
|
|
|
@ -185,7 +185,7 @@ real_code_2:
|
|||
call LOCAL(move_memory)
|
||||
|
||||
/* Check for multiboot signature. */
|
||||
cmpl $MULTIBOOT_HEADER_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_MACHINE_DATA_END)
|
||||
cmpl $MULTIBOOT_HEADER_MAGIC, %ss:(DATA_ADDR + GRUB_KERNEL_I386_PC_MULTIBOOT_SIGNATURE)
|
||||
jz 1f
|
||||
|
||||
movl (ramdisk_image - start), %esi
|
||||
|
|
|
@ -41,7 +41,7 @@ struct grub_pxe_disk_data
|
|||
grub_uint32_t gateway_ip;
|
||||
};
|
||||
|
||||
struct grub_pxenv *grub_pxe_pxenv;
|
||||
struct grub_pxe_bangpxe *grub_pxe_pxenv;
|
||||
static grub_uint32_t grub_pxe_your_ip;
|
||||
static grub_uint32_t grub_pxe_default_server_ip;
|
||||
static grub_uint32_t grub_pxe_default_gateway_ip;
|
||||
|
@ -58,41 +58,47 @@ struct grub_pxe_data
|
|||
|
||||
static grub_uint32_t pxe_rm_entry = 0;
|
||||
|
||||
static struct grub_pxenv *
|
||||
static struct grub_pxe_bangpxe *
|
||||
grub_pxe_scan (void)
|
||||
{
|
||||
struct grub_bios_int_registers regs;
|
||||
struct grub_pxenv *ret;
|
||||
void *pxe;
|
||||
struct grub_pxenv *pxenv;
|
||||
struct grub_pxe_bangpxe *bangpxe;
|
||||
|
||||
regs.flags = GRUB_CPU_INT_FLAGS_DEFAULT;
|
||||
|
||||
regs.ebx = 0;
|
||||
regs.ecx = 0;
|
||||
regs.eax = 0x5650;
|
||||
regs.es = 0;
|
||||
|
||||
grub_bios_interrupt (0x1a, ®s);
|
||||
|
||||
if ((regs.eax & 0xffff) != 0x564e)
|
||||
return NULL;
|
||||
ret = (struct grub_pxenv *) ((regs.es << 4) + (regs.ebx & 0xffff));
|
||||
if (grub_memcmp (ret->signature, GRUB_PXE_SIGNATURE, sizeof (ret->signature))
|
||||
|
||||
pxenv = (struct grub_pxenv *) ((regs.es << 4) + (regs.ebx & 0xffff));
|
||||
if (grub_memcmp (pxenv->signature, GRUB_PXE_SIGNATURE,
|
||||
sizeof (pxenv->signature))
|
||||
!= 0)
|
||||
return NULL;
|
||||
if (ret->version < 0x201)
|
||||
|
||||
if (pxenv->version < 0x201)
|
||||
return NULL;
|
||||
|
||||
pxe = (void *) ((((ret->pxe_ptr & 0xffff0000) >> 16) << 4)
|
||||
+ (ret->pxe_ptr & 0xffff));
|
||||
if (!pxe)
|
||||
bangpxe = (void *) ((((pxenv->pxe_ptr & 0xffff0000) >> 16) << 4)
|
||||
+ (pxenv->pxe_ptr & 0xffff));
|
||||
|
||||
if (!bangpxe)
|
||||
return NULL;
|
||||
|
||||
/* !PXE */
|
||||
if (*(grub_uint32_t *) pxe != 0x45585021)
|
||||
if (grub_memcmp (bangpxe->signature, GRUB_PXE_BANGPXE_SIGNATURE,
|
||||
sizeof (bangpxe->signature)) != 0)
|
||||
return NULL;
|
||||
|
||||
pxe_rm_entry = ret->rm_entry;
|
||||
return ret;
|
||||
pxe_rm_entry = bangpxe->rm_entry;
|
||||
|
||||
return bangpxe;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -321,7 +327,7 @@ grub_pxefs_read (grub_file_t file, char *buf, grub_size_t len)
|
|||
o.gateway_ip = disk_data->gateway_ip;
|
||||
grub_strcpy ((char *)&o.filename[0], data->filename);
|
||||
o.tftp_port = grub_cpu_to_be16 (GRUB_PXE_TFTP_PORT);
|
||||
o.packet_size = grub_pxe_blksize;
|
||||
o.packet_size = data->block_size;
|
||||
grub_pxe_call (GRUB_PXENV_TFTP_OPEN, &o, pxe_rm_entry);
|
||||
if (o.status)
|
||||
{
|
||||
|
@ -483,7 +489,7 @@ parse_dhcp_vendor (void *vend, int limit)
|
|||
static void
|
||||
grub_pxe_detect (void)
|
||||
{
|
||||
struct grub_pxenv *pxenv;
|
||||
struct grub_pxe_bangpxe *pxenv;
|
||||
struct grub_pxenv_get_cached_info ci;
|
||||
struct grub_pxenv_boot_player *bp;
|
||||
|
||||
|
|
|
@ -37,8 +37,8 @@
|
|||
#define GRUB_MODULES_MACHINE_READONLY
|
||||
#endif
|
||||
|
||||
#ifdef __ia64__
|
||||
#include <grub/machine/misc.h>
|
||||
#ifdef GRUB_MACHINE_EMU
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -229,6 +229,46 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
|
|||
{
|
||||
unsigned i;
|
||||
Elf_Shdr *s;
|
||||
grub_size_t tsize = 0, talign = 1;
|
||||
#ifdef __ia64__
|
||||
grub_size_t tramp;
|
||||
grub_size_t got;
|
||||
#endif
|
||||
char *ptr;
|
||||
|
||||
for (i = 0, s = (Elf_Shdr *)((char *) e + e->e_shoff);
|
||||
i < e->e_shnum;
|
||||
i++, s = (Elf_Shdr *)((char *) s + e->e_shentsize))
|
||||
{
|
||||
tsize += ALIGN_UP (s->sh_size, s->sh_addralign);
|
||||
if (talign < s->sh_addralign)
|
||||
talign = s->sh_addralign;
|
||||
}
|
||||
|
||||
#ifdef __ia64__
|
||||
grub_arch_dl_get_tramp_got_size (e, &tramp, &got);
|
||||
tsize += ALIGN_UP (tramp, GRUB_ARCH_DL_TRAMP_ALIGN);
|
||||
if (talign < GRUB_ARCH_DL_TRAMP_ALIGN)
|
||||
talign = GRUB_ARCH_DL_TRAMP_ALIGN;
|
||||
tsize += ALIGN_UP (got, GRUB_ARCH_DL_GOT_ALIGN);
|
||||
if (talign < GRUB_ARCH_DL_GOT_ALIGN)
|
||||
talign = GRUB_ARCH_DL_GOT_ALIGN;
|
||||
#endif
|
||||
|
||||
#ifdef GRUB_MACHINE_EMU
|
||||
if (talign < 8192 * 16)
|
||||
talign = 8192 * 16;
|
||||
tsize = ALIGN_UP (tsize, 8192 * 16);
|
||||
#endif
|
||||
|
||||
mod->base = grub_memalign (talign, tsize);
|
||||
if (!mod->base)
|
||||
return grub_errno;
|
||||
ptr = mod->base;
|
||||
|
||||
#ifdef GRUB_MACHINE_EMU
|
||||
mprotect (mod->base, tsize, PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||
#endif
|
||||
|
||||
for (i = 0, s = (Elf_Shdr *)((char *) e + e->e_shoff);
|
||||
i < e->e_shnum;
|
||||
|
@ -246,12 +286,9 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
|
|||
{
|
||||
void *addr;
|
||||
|
||||
addr = grub_memalign (s->sh_addralign, s->sh_size);
|
||||
if (! addr)
|
||||
{
|
||||
grub_free (seg);
|
||||
return grub_errno;
|
||||
}
|
||||
ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, s->sh_addralign);
|
||||
addr = ptr;
|
||||
ptr += s->sh_size;
|
||||
|
||||
switch (s->sh_type)
|
||||
{
|
||||
|
@ -274,6 +311,14 @@ grub_dl_load_segments (grub_dl_t mod, const Elf_Ehdr *e)
|
|||
mod->segment = seg;
|
||||
}
|
||||
}
|
||||
#ifdef __ia64__
|
||||
ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_TRAMP_ALIGN);
|
||||
mod->tramp = ptr;
|
||||
ptr += tramp;
|
||||
ptr = (char *) ALIGN_UP ((grub_addr_t) ptr, GRUB_ARCH_DL_GOT_ALIGN);
|
||||
mod->got = ptr;
|
||||
ptr += got;
|
||||
#endif
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
@ -342,14 +387,29 @@ grub_dl_resolve_symbols (grub_dl_t mod, Elf_Ehdr *e)
|
|||
case STT_FUNC:
|
||||
sym->st_value += (Elf_Addr) grub_dl_get_section_addr (mod,
|
||||
sym->st_shndx);
|
||||
#ifdef __ia64__
|
||||
{
|
||||
/* FIXME: free descriptor once it's not used anymore. */
|
||||
char **desc;
|
||||
desc = grub_malloc (2 * sizeof (char *));
|
||||
if (!desc)
|
||||
return grub_errno;
|
||||
desc[0] = (void *) sym->st_value;
|
||||
desc[1] = mod->base;
|
||||
if (grub_dl_register_symbol (name, (void *) desc, mod))
|
||||
return grub_errno;
|
||||
sym->st_value = (grub_addr_t) desc;
|
||||
}
|
||||
#endif
|
||||
if (bind != STB_LOCAL)
|
||||
if (grub_dl_register_symbol (name, (void *) sym->st_value, mod))
|
||||
return grub_errno;
|
||||
|
||||
{
|
||||
if (grub_dl_register_symbol (name, (void *) sym->st_value, mod))
|
||||
return grub_errno;
|
||||
}
|
||||
if (grub_strcmp (name, "grub_mod_init") == 0)
|
||||
mod->init = (void (*) (grub_dl_t)) sym->st_value;
|
||||
mod->init = sym->st_value;
|
||||
else if (grub_strcmp (name, "grub_mod_fini") == 0)
|
||||
mod->fini = (void (*) (void)) sym->st_value;
|
||||
mod->fini = sym->st_value;
|
||||
break;
|
||||
|
||||
case STT_SECTION:
|
||||
|
@ -374,7 +434,9 @@ static void
|
|||
grub_dl_call_init (grub_dl_t mod)
|
||||
{
|
||||
if (mod->init)
|
||||
(mod->init) (mod);
|
||||
{
|
||||
((void (*) (grub_dl_t)) mod->init) (mod);
|
||||
}
|
||||
}
|
||||
|
||||
static grub_err_t
|
||||
|
@ -537,7 +599,7 @@ grub_dl_load_core (void *addr, grub_size_t size)
|
|||
grub_dl_flush_cache (mod);
|
||||
|
||||
grub_dprintf ("modules", "module name: %s\n", mod->name);
|
||||
grub_dprintf ("modules", "init function: %p\n", mod->init);
|
||||
grub_dprintf ("modules", "init function: %" PRIxGRUB_ADDR "\n", mod->init);
|
||||
grub_dl_call_init (mod);
|
||||
|
||||
if (grub_dl_add (mod))
|
||||
|
@ -662,7 +724,9 @@ grub_dl_unload (grub_dl_t mod)
|
|||
return 0;
|
||||
|
||||
if (mod->fini)
|
||||
(mod->fini) ();
|
||||
{
|
||||
((void (*) (void)) mod->fini) ();
|
||||
}
|
||||
|
||||
grub_dl_remove (mod);
|
||||
grub_dl_unregister_symbols (mod);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "../mips/cache.S"
|
||||
#elif defined(__powerpc__)
|
||||
#include "../powerpc/cache.S"
|
||||
#elif defined(__ia64__)
|
||||
#else
|
||||
#error "No target cpu type is defined"
|
||||
#endif
|
||||
|
|
13
grub-core/kern/emu/cache.c
Normal file
13
grub-core/kern/emu/cache.c
Normal file
|
@ -0,0 +1,13 @@
|
|||
|
||||
#if defined(__ia64__)
|
||||
#include <grub/cache.h>
|
||||
|
||||
void __clear_cache (char *beg, char *end);
|
||||
|
||||
void
|
||||
grub_arch_sync_caches (void *address, grub_size_t len)
|
||||
{
|
||||
__clear_cache (address, (char *) address + len);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -48,3 +48,13 @@ grub_emu_init (void)
|
|||
{
|
||||
grub_no_autoload = 1;
|
||||
}
|
||||
|
||||
#ifdef __ia64__
|
||||
void grub_arch_dl_get_tramp_got_size (const void *ehdr __attribute__ ((unused)),
|
||||
grub_size_t *tramp, grub_size_t *got)
|
||||
{
|
||||
*tramp = 0;
|
||||
*got = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "../mips/dl.c"
|
||||
#elif defined(__powerpc__)
|
||||
#include "../powerpc/dl.c"
|
||||
#elif defined(__ia64__)
|
||||
#include "../ia64/dl.c"
|
||||
#else
|
||||
#error "No target cpu type is defined"
|
||||
#endif
|
||||
|
|
|
@ -51,7 +51,7 @@ VARIABLE(grub_prefix)
|
|||
* Leave some breathing room for the prefix.
|
||||
*/
|
||||
|
||||
. = _start + GRUB_KERNEL_MACHINE_DATA_END
|
||||
. = _start + GRUB_KERNEL_MACHINE_PREFIX_END
|
||||
|
||||
/*
|
||||
* Support for booting GRUB from a Multiboot boot loader (e.g. GRUB itself).
|
||||
|
|
|
@ -51,7 +51,7 @@ VARIABLE(grub_prefix)
|
|||
* Leave some breathing room for the prefix.
|
||||
*/
|
||||
|
||||
. = _start + GRUB_KERNEL_MACHINE_DATA_END
|
||||
. = _start + GRUB_KERNEL_MACHINE_PREFIX_END
|
||||
|
||||
codestart:
|
||||
movl %eax, EXT_C(grub_ieee1275_entry_fn)
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/machine/init.h>
|
||||
#include <grub/machine/memory.h>
|
||||
#include <grub/types.h>
|
||||
#include <grub/multiboot.h>
|
||||
|
|
|
@ -100,14 +100,6 @@ VARIABLE(grub_install_dos_part)
|
|||
.long 0xFFFFFFFF
|
||||
VARIABLE(grub_install_bsd_part)
|
||||
.long 0xFFFFFFFF
|
||||
VARIABLE(grub_prefix)
|
||||
/* to be filled by grub-mkimage */
|
||||
|
||||
/*
|
||||
* Leave some breathing room for the prefix.
|
||||
*/
|
||||
|
||||
. = _start + GRUB_KERNEL_MACHINE_DATA_END
|
||||
|
||||
#ifdef APPLE_CC
|
||||
bss_start:
|
||||
|
@ -450,6 +442,16 @@ gate_a20_check_state:
|
|||
*/
|
||||
. = _start + GRUB_KERNEL_MACHINE_RAW_SIZE
|
||||
|
||||
. = _start + GRUB_KERNEL_MACHINE_PREFIX
|
||||
VARIABLE(grub_prefix)
|
||||
/* to be filled by grub-mkimage */
|
||||
|
||||
/*
|
||||
* Leave some breathing room for the prefix.
|
||||
*/
|
||||
. = _start + GRUB_KERNEL_MACHINE_PREFIX_END
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* grub_exit()
|
||||
|
|
|
@ -39,7 +39,7 @@ VARIABLE(grub_prefix)
|
|||
* Leave some breathing room for the prefix.
|
||||
*/
|
||||
|
||||
. = _start + GRUB_KERNEL_MACHINE_DATA_END
|
||||
. = _start + GRUB_KERNEL_MACHINE_PREFIX_END
|
||||
|
||||
codestart:
|
||||
/* Relocate to low memory. First we figure out our location.
|
||||
|
|
318
grub-core/kern/ia64/dl.c
Normal file
318
grub-core/kern/ia64/dl.c
Normal file
|
@ -0,0 +1,318 @@
|
|||
/* dl.c - arch-dependent part of loadable module support */
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 2002,2004,2005,2007,2009 Free Software Foundation, Inc.
|
||||
*
|
||||
* GRUB is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* GRUB is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/elf.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/err.h>
|
||||
#include <grub/mm.h>
|
||||
|
||||
/* Check if EHDR is a valid ELF header. */
|
||||
grub_err_t
|
||||
grub_arch_dl_check_header (void *ehdr)
|
||||
{
|
||||
Elf_Ehdr *e = ehdr;
|
||||
|
||||
/* Check the magic numbers. */
|
||||
if (e->e_ident[EI_CLASS] != ELFCLASS64
|
||||
|| e->e_ident[EI_DATA] != ELFDATA2LSB
|
||||
|| e->e_machine != EM_IA_64)
|
||||
return grub_error (GRUB_ERR_BAD_OS, "invalid arch specific ELF magic");
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
||||
|
||||
#define MASK20 ((1 << 20) - 1)
|
||||
#define MASK19 ((1 << 19) - 1)
|
||||
|
||||
struct unaligned_uint32
|
||||
{
|
||||
grub_uint32_t val;
|
||||
} __attribute__ ((packed));
|
||||
|
||||
static void
|
||||
add_value_to_slot_20b (grub_addr_t addr, grub_uint32_t value)
|
||||
{
|
||||
struct unaligned_uint32 *p;
|
||||
switch (addr & 3)
|
||||
{
|
||||
case 0:
|
||||
p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2);
|
||||
p->val = (((((p->val >> 2) & MASK20) + value) & MASK20) << 2) | (p->val & ~(MASK20 << 2));
|
||||
break;
|
||||
case 1:
|
||||
p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7);
|
||||
p->val = (((((p->val >> 3) & MASK20) + value) & MASK20) << 3) | (p->val & ~(MASK20 << 3));
|
||||
break;
|
||||
case 2:
|
||||
p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12);
|
||||
p->val = (((((p->val >> 4) & MASK20) + value) & MASK20) << 4) | (p->val & ~(MASK20 << 4));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define MASKF21 ( ((1 << 23) - 1) & ~((1 << 7) | (1 << 8)) )
|
||||
|
||||
static grub_uint32_t
|
||||
add_value_to_slot_21_real (grub_uint32_t a, grub_uint32_t value)
|
||||
{
|
||||
grub_uint32_t high, mid, low, c;
|
||||
low = (a & 0x00007f);
|
||||
mid = (a & 0x7fc000) >> 7;
|
||||
high = (a & 0x003e00) << 7;
|
||||
c = (low | mid | high) + value;
|
||||
return (c & 0x7f) | ((c << 7) & 0x7fc000) | ((c >> 7) & 0x0003e00); //0x003e00
|
||||
}
|
||||
|
||||
static void
|
||||
add_value_to_slot_21 (grub_addr_t addr, grub_uint32_t value)
|
||||
{
|
||||
struct unaligned_uint32 *p;
|
||||
switch (addr & 3)
|
||||
{
|
||||
case 0:
|
||||
p = (struct unaligned_uint32 *) ((addr & ~3ULL) + 2);
|
||||
p->val = ((add_value_to_slot_21_real (((p->val >> 2) & MASKF21), value) & MASKF21) << 2) | (p->val & ~(MASKF21 << 2));
|
||||
break;
|
||||
case 1:
|
||||
p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 7);
|
||||
p->val = ((add_value_to_slot_21_real (((p->val >> 3) & MASKF21), value) & MASKF21) << 3) | (p->val & ~(MASKF21 << 3));
|
||||
break;
|
||||
case 2:
|
||||
p = (struct unaligned_uint32 *) ((grub_uint8_t *) (addr & ~3ULL) + 12);
|
||||
p->val = ((add_value_to_slot_21_real (((p->val >> 4) & MASKF21), value) & MASKF21) << 4) | (p->val & ~(MASKF21 << 4));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static grub_uint8_t nopm[5] =
|
||||
{
|
||||
/* [MLX] nop.m 0x0 */
|
||||
0x05, 0x00, 0x00, 0x00, 0x01
|
||||
};
|
||||
|
||||
static grub_uint8_t jump[0x20] =
|
||||
{
|
||||
/* ld8 r16=[r15],8 */
|
||||
0x02, 0x80, 0x20, 0x1e, 0x18, 0x14,
|
||||
/* mov r14=r1;; */
|
||||
0xe0, 0x00, 0x04, 0x00, 0x42, 0x00,
|
||||
/* nop.i 0x0 */
|
||||
0x00, 0x00, 0x04, 0x00,
|
||||
/* ld8 r1=[r15] */
|
||||
0x11, 0x08, 0x00, 0x1e, 0x18, 0x10,
|
||||
/* mov b6=r16 */
|
||||
0x60, 0x80, 0x04, 0x80, 0x03, 0x00,
|
||||
/* br.few b6;; */
|
||||
0x60, 0x00, 0x80, 0x00
|
||||
};
|
||||
|
||||
struct ia64_trampoline
|
||||
{
|
||||
/* nop.m */
|
||||
grub_uint8_t nop[5];
|
||||
/* movl r15 = addr*/
|
||||
grub_uint8_t addr_hi[6];
|
||||
grub_uint8_t e0;
|
||||
grub_uint8_t addr_lo[4];
|
||||
grub_uint8_t jump[0x20];
|
||||
};
|
||||
|
||||
static void
|
||||
make_trampoline (struct ia64_trampoline *tr, grub_uint64_t addr)
|
||||
{
|
||||
grub_memcpy (tr->nop, nopm, sizeof (tr->nop));
|
||||
tr->addr_hi[0] = ((addr & 0xc00000) >> 16);
|
||||
tr->addr_hi[1] = (addr >> 24) & 0xff;
|
||||
tr->addr_hi[2] = (addr >> 32) & 0xff;
|
||||
tr->addr_hi[3] = (addr >> 40) & 0xff;
|
||||
tr->addr_hi[4] = (addr >> 48) & 0xff;
|
||||
tr->addr_hi[5] = (addr >> 56) & 0xff;
|
||||
tr->e0 = 0xe0;
|
||||
tr->addr_lo[0] = ((addr & 0x000f) << 4) | 0x01;
|
||||
tr->addr_lo[1] = ((addr & 0x0070) >> 4) | ((addr & 0x070000) >> 11) | ((addr & 0x200000) >> 17);
|
||||
tr->addr_lo[2] = ((addr & 0x1f80) >> 5) | ((addr & 0x180000) >> 19);
|
||||
tr->addr_lo[3] = ((addr & 0xe000) >> 13) | 0x60;
|
||||
grub_memcpy (tr->jump, jump, sizeof (tr->jump));
|
||||
}
|
||||
|
||||
void
|
||||
grub_arch_dl_get_tramp_got_size (const void *ehdr, grub_size_t *tramp, grub_size_t *got)
|
||||
{
|
||||
const Elf_Ehdr *e = ehdr;
|
||||
grub_size_t cntt = 0, cntg = 0;;
|
||||
const Elf_Shdr *s;
|
||||
Elf_Word entsize;
|
||||
unsigned i;
|
||||
|
||||
/* Find a symbol table. */
|
||||
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
|
||||
i < e->e_shnum;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
|
||||
if (s->sh_type == SHT_SYMTAB)
|
||||
break;
|
||||
|
||||
if (i == e->e_shnum)
|
||||
return;
|
||||
|
||||
entsize = s->sh_entsize;
|
||||
|
||||
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
|
||||
i < e->e_shnum;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
|
||||
if (s->sh_type == SHT_RELA)
|
||||
{
|
||||
Elf_Rela *rel, *max;
|
||||
|
||||
for (rel = (Elf_Rela *) ((char *) e + s->sh_offset),
|
||||
max = rel + s->sh_size / s->sh_entsize;
|
||||
rel < max; rel++)
|
||||
switch (ELF_R_TYPE (rel->r_info))
|
||||
{
|
||||
case R_IA64_PCREL21B:
|
||||
cntt++;
|
||||
break;
|
||||
case R_IA64_LTOFF_FPTR22:
|
||||
case R_IA64_LTOFF22X:
|
||||
case R_IA64_LTOFF22:
|
||||
cntg++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
*tramp = cntt * sizeof (struct ia64_trampoline);
|
||||
*got = cntg * sizeof (grub_uint64_t);
|
||||
}
|
||||
|
||||
|
||||
/* Relocate symbols. */
|
||||
grub_err_t
|
||||
grub_arch_dl_relocate_symbols (grub_dl_t mod, void *ehdr)
|
||||
{
|
||||
Elf_Ehdr *e = ehdr;
|
||||
Elf_Shdr *s;
|
||||
Elf_Word entsize;
|
||||
unsigned i;
|
||||
grub_uint64_t *gp, *gpptr;
|
||||
struct ia64_trampoline *tr;
|
||||
|
||||
gp = (grub_uint64_t *) mod->base;
|
||||
gpptr = (grub_uint64_t *) mod->got;
|
||||
tr = mod->tramp;
|
||||
|
||||
/* Find a symbol table. */
|
||||
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
|
||||
i < e->e_shnum;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
|
||||
if (s->sh_type == SHT_SYMTAB)
|
||||
break;
|
||||
|
||||
if (i == e->e_shnum)
|
||||
return grub_error (GRUB_ERR_BAD_MODULE, "no symtab found");
|
||||
|
||||
entsize = s->sh_entsize;
|
||||
|
||||
for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
|
||||
i < e->e_shnum;
|
||||
i++, s = (Elf_Shdr *) ((char *) s + e->e_shentsize))
|
||||
if (s->sh_type == SHT_RELA)
|
||||
{
|
||||
grub_dl_segment_t seg;
|
||||
|
||||
/* Find the target segment. */
|
||||
for (seg = mod->segment; seg; seg = seg->next)
|
||||
if (seg->section == s->sh_info)
|
||||
break;
|
||||
|
||||
if (seg)
|
||||
{
|
||||
Elf_Rela *rel, *max;
|
||||
|
||||
for (rel = (Elf_Rela *) ((char *) e + s->sh_offset),
|
||||
max = rel + s->sh_size / s->sh_entsize;
|
||||
rel < max;
|
||||
rel++)
|
||||
{
|
||||
grub_addr_t addr;
|
||||
Elf_Sym *sym;
|
||||
grub_uint64_t value;
|
||||
|
||||
if (seg->size < (rel->r_offset & ~3))
|
||||
return grub_error (GRUB_ERR_BAD_MODULE,
|
||||
"reloc offset is out of the segment");
|
||||
|
||||
addr = (grub_addr_t) seg->addr + rel->r_offset;
|
||||
sym = (Elf_Sym *) ((char *) mod->symtab
|
||||
+ entsize * ELF_R_SYM (rel->r_info));
|
||||
|
||||
/* On the PPC the value does not have an explicit
|
||||
addend, add it. */
|
||||
value = sym->st_value + rel->r_addend;
|
||||
|
||||
switch (ELF_R_TYPE (rel->r_info))
|
||||
{
|
||||
case R_IA64_PCREL21B:
|
||||
{
|
||||
grub_uint64_t noff;
|
||||
make_trampoline (tr, value);
|
||||
noff = ((char *) tr - (char *) (addr & ~3)) >> 4;
|
||||
tr++;
|
||||
if (noff & ~MASK19)
|
||||
return grub_error (GRUB_ERR_BAD_OS,
|
||||
"trampoline offset too big (%lx)", noff);
|
||||
add_value_to_slot_20b (addr, noff);
|
||||
}
|
||||
break;
|
||||
case R_IA64_SEGREL64LSB:
|
||||
*(grub_uint64_t *) addr += value - rel->r_offset;
|
||||
break;
|
||||
case R_IA64_FPTR64LSB:
|
||||
case R_IA64_DIR64LSB:
|
||||
*(grub_uint64_t *) addr += value;
|
||||
break;
|
||||
case R_IA64_PCREL64LSB:
|
||||
*(grub_uint64_t *) addr += value - addr;
|
||||
break;
|
||||
case R_IA64_GPREL22:
|
||||
add_value_to_slot_21 (addr, value - (grub_addr_t) gp);
|
||||
break;
|
||||
|
||||
case R_IA64_LTOFF_FPTR22:
|
||||
case R_IA64_LTOFF22X:
|
||||
case R_IA64_LTOFF22:
|
||||
*gpptr = value;
|
||||
if ((addr & 0xffff) == 0x4301)
|
||||
grub_dprintf ("modules", "off = %lx\n", (grub_addr_t) gpptr - (grub_addr_t) gp);
|
||||
add_value_to_slot_21 (addr, (grub_addr_t) gpptr - (grub_addr_t) gp);
|
||||
gpptr++;
|
||||
break;
|
||||
|
||||
/* We treat LTOFF22X as LTOFF22, so we can ignore LDXMOV. */
|
||||
case R_IA64_LDXMOV:
|
||||
break;
|
||||
default:
|
||||
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
|
||||
"this relocation (0x%x) is not implemented yet",
|
||||
ELF_R_TYPE (rel->r_info));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GRUB_ERR_NONE;
|
||||
}
|
|
@ -154,7 +154,7 @@ VARIABLE(grub_prefix)
|
|||
* Leave some breathing room for the prefix.
|
||||
*/
|
||||
|
||||
. = _start + GRUB_KERNEL_MACHINE_DATA_END
|
||||
. = _start + GRUB_KERNEL_MACHINE_PREFIX_END
|
||||
#ifdef GRUB_MACHINE_MIPS_YEELOONG
|
||||
VARIABLE (grub_arch_busclock)
|
||||
.long 0
|
||||
|
|
|
@ -990,7 +990,7 @@ grub_abort (void)
|
|||
grub_exit ();
|
||||
}
|
||||
|
||||
#ifndef APPLE_CC
|
||||
#if ! defined (APPLE_CC) && !defined (GRUB_UTIL)
|
||||
/* GCC emits references to abort(). */
|
||||
void abort (void) __attribute__ ((alias ("grub_abort")));
|
||||
#endif
|
||||
|
|
|
@ -39,7 +39,7 @@ VARIABLE(grub_prefix)
|
|||
* Leave some breathing room for the prefix.
|
||||
*/
|
||||
|
||||
. = _start + GRUB_KERNEL_MACHINE_DATA_END
|
||||
. = _start + GRUB_KERNEL_MACHINE_PREFIX_END
|
||||
|
||||
codestart:
|
||||
li 2, 0
|
||||
|
|
|
@ -42,7 +42,7 @@ VARIABLE(grub_prefix)
|
|||
* Leave some breathing room for the prefix.
|
||||
*/
|
||||
|
||||
. = EXT_C(_start) + GRUB_KERNEL_MACHINE_DATA_END
|
||||
. = EXT_C(_start) + GRUB_KERNEL_MACHINE_PREFIX_END
|
||||
|
||||
codestart:
|
||||
/* Copy the modules past the end of the kernel image.
|
||||
|
|
|
@ -59,7 +59,9 @@ extern grub_uint32_t grub_relocator32_ecx;
|
|||
extern grub_uint32_t grub_relocator32_edx;
|
||||
extern grub_uint32_t grub_relocator32_eip;
|
||||
extern grub_uint32_t grub_relocator32_esp;
|
||||
extern grub_uint32_t grub_relocator32_ebp;
|
||||
extern grub_uint32_t grub_relocator32_esi;
|
||||
extern grub_uint32_t grub_relocator32_edi;
|
||||
|
||||
extern grub_uint8_t grub_relocator64_start;
|
||||
extern grub_uint8_t grub_relocator64_end;
|
||||
|
@ -165,7 +167,9 @@ grub_relocator32_boot (struct grub_relocator *rel,
|
|||
grub_relocator32_edx = state.edx;
|
||||
grub_relocator32_eip = state.eip;
|
||||
grub_relocator32_esp = state.esp;
|
||||
grub_relocator32_ebp = state.ebp;
|
||||
grub_relocator32_esi = state.esi;
|
||||
grub_relocator32_edi = state.edi;
|
||||
|
||||
grub_memmove (get_virtual_current_address (ch), &grub_relocator32_start,
|
||||
RELOCATOR_SIZEOF (32));
|
||||
|
|
|
@ -65,13 +65,27 @@ VARIABLE(grub_relocator32_esp)
|
|||
|
||||
movl %eax, %esp
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator32_ebp)
|
||||
.long 0
|
||||
|
||||
movl %eax, %ebp
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator32_esi)
|
||||
.long 0
|
||||
|
||||
movl %eax, %esi
|
||||
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator32_edi)
|
||||
.long 0
|
||||
|
||||
movl %eax, %edi
|
||||
|
||||
/* mov imm32, %eax */
|
||||
.byte 0xb8
|
||||
VARIABLE(grub_relocator32_eax)
|
||||
|
|
|
@ -746,6 +746,7 @@ grub_freebsd_boot (void)
|
|||
grub_memcpy (&stack[9], &bi, sizeof (bi));
|
||||
state.eip = entry;
|
||||
state.esp = stack_target;
|
||||
state.ebp = stack_target;
|
||||
stack[0] = entry; /* "Return" address. */
|
||||
stack[1] = bootflags | FREEBSD_RB_BOOTINFO;
|
||||
stack[2] = bootdev;
|
||||
|
@ -830,7 +831,8 @@ grub_openbsd_boot (void)
|
|||
#endif
|
||||
|
||||
state.eip = entry;
|
||||
state.esp = ((grub_uint8_t *) stack - (grub_uint8_t *) buf0) + buf_target;
|
||||
state.ebp = state.esp
|
||||
= ((grub_uint8_t *) stack - (grub_uint8_t *) buf0) + buf_target;
|
||||
stack[0] = entry;
|
||||
stack[1] = bootflags;
|
||||
stack[2] = openbsd_root;
|
||||
|
@ -1045,6 +1047,7 @@ grub_netbsd_boot (void)
|
|||
|
||||
state.eip = entry;
|
||||
state.esp = stack_target;
|
||||
state.ebp = stack_target;
|
||||
stack[0] = entry;
|
||||
stack[1] = bootflags;
|
||||
stack[2] = 0;
|
||||
|
|
|
@ -716,7 +716,7 @@ grub_linux_boot (void)
|
|||
|
||||
/* FIXME. */
|
||||
/* asm volatile ("lidt %0" : : "m" (idt_desc)); */
|
||||
state.ebx = 0;
|
||||
state.ebp = state.edi = state.ebx = 0;
|
||||
state.esi = real_mode_target;
|
||||
state.esp = real_mode_target;
|
||||
state.eip = params->code32_start;
|
||||
|
|
|
@ -836,6 +836,7 @@ grub_xnu_boot_resume (void)
|
|||
struct grub_relocator32_state state;
|
||||
|
||||
state.esp = grub_xnu_stack;
|
||||
state.ebp = grub_xnu_stack;
|
||||
state.eip = grub_xnu_entry_point;
|
||||
state.eax = grub_xnu_arg1;
|
||||
|
||||
|
@ -1114,6 +1115,7 @@ grub_xnu_boot (void)
|
|||
state.eip = grub_xnu_entry_point;
|
||||
state.eax = grub_xnu_arg1;
|
||||
state.esp = grub_xnu_stack;
|
||||
state.ebp = grub_xnu_stack;
|
||||
return grub_relocator32_boot (grub_xnu_relocator, state);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue