ELF symbol loading support is added.
This commit is contained in:
parent
49230cb103
commit
b7e8ad7e6d
5 changed files with 154 additions and 58 deletions
|
@ -1,3 +1,9 @@
|
|||
2001-07-03 OKUJI Yoshinori <okuji@gnu.org>
|
||||
|
||||
From Julien Bordet <julien.bordet@int-evry.fr>:
|
||||
* stage2/i386-elf.h (Elf32_Shdr): New type.
|
||||
* stage2/boot.c (load_image): Added ELF symbol loading support.
|
||||
|
||||
2001-06-22 OKUJI Yoshinori <okuji@gnu.org>
|
||||
|
||||
* stage2/char_io.c [STAGE1_5] (grub_strcmp): Defined, even
|
||||
|
|
1
NEWS
1
NEWS
|
@ -36,6 +36,7 @@ New in 1.0 - XXXX-XX-XX:
|
|||
`--with-configfile', so that you can load a remotely specified
|
||||
configuration file automatically, like the network boot images.
|
||||
* VSTa filesystem support is added.
|
||||
* ELF symbol loading support is added.
|
||||
|
||||
New in 0.5.96 - 2000-10-04:
|
||||
* New commands, "reboot" and "halt".
|
||||
|
|
1
THANKS
1
THANKS
|
@ -41,6 +41,7 @@ Jochen Hoenicke <jochen@gnu.org>
|
|||
Johannes Kroeger <hanne@squirrel.owl.de>
|
||||
John Tobey <spam@john-edwin-tobey.org>
|
||||
Josip Rodin <joy@cibalia.gkvk.hr>
|
||||
Julien Bordet <julien.bordet@int-evry.fr>
|
||||
Kalle Olavi Niemitalo <tosi@ees2.oulu.fi>
|
||||
Khimenko Victor <grub@khim.sch57.msk.ru>
|
||||
Klaus Reichl <klaus.reichl@alcatel.at>
|
||||
|
|
|
@ -552,13 +552,86 @@ load_image (char *kernel, char *arg, kernel_t suggested_type,
|
|||
}
|
||||
}
|
||||
|
||||
if (!errnum)
|
||||
if (! errnum)
|
||||
{
|
||||
if (!loaded)
|
||||
if (! loaded)
|
||||
errnum = ERR_EXEC_FORMAT;
|
||||
else
|
||||
{
|
||||
/* FIXME: load ELF symbols */
|
||||
/* Load ELF symbols. */
|
||||
Elf32_Shdr *shdr = NULL;
|
||||
int tab_size, sec_size;
|
||||
int symtab_err = 0;
|
||||
|
||||
mbi.syms.e.num = pu.elf->e_shnum;
|
||||
mbi.syms.e.size = pu.elf->e_shentsize;
|
||||
mbi.syms.e.shndx = pu.elf->e_shstrndx;
|
||||
|
||||
/* We should align to a 4K boundary here for good measure. */
|
||||
if (align_4k)
|
||||
cur_addr = (cur_addr + 0xFFF) & 0xFFFFF000;
|
||||
|
||||
tab_size = pu.elf->e_shentsize * pu.elf->e_shnum;
|
||||
|
||||
grub_seek (pu.elf->e_shoff);
|
||||
if (grub_read ((char *) RAW_ADDR (cur_addr), tab_size)
|
||||
== tab_size)
|
||||
{
|
||||
mbi.syms.e.addr = cur_addr;
|
||||
shdr = (Elf32_Shdr *) mbi.syms.e.addr;
|
||||
cur_addr += tab_size;
|
||||
|
||||
printf (", shtab=0x%x", cur_addr);
|
||||
|
||||
for (i = 0; i < mbi.syms.e.num; i++)
|
||||
{
|
||||
/* This section is a loaded section,
|
||||
so we don't care. */
|
||||
if (shdr[i].sh_addr != 0)
|
||||
continue;
|
||||
|
||||
/* This section is empty, so we don't care. */
|
||||
if (shdr[i].sh_size == 0)
|
||||
continue;
|
||||
|
||||
/* Align the section to a sh_addralign bits boundary. */
|
||||
cur_addr = ((cur_addr + shdr[i].sh_addralign) &
|
||||
- (int) shdr[i].sh_addralign);
|
||||
|
||||
grub_seek (shdr[i].sh_offset);
|
||||
|
||||
sec_size = shdr[i].sh_size;
|
||||
|
||||
if (! (memcheck (cur_addr, sec_size)
|
||||
&& (grub_read ((char *) RAW_ADDR (cur_addr),
|
||||
sec_size)
|
||||
== sec_size)))
|
||||
{
|
||||
symtab_err = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
shdr[i].sh_addr = cur_addr;
|
||||
cur_addr += sec_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
symtab_err = 1;
|
||||
|
||||
if (mbi.syms.e.addr < RAW_ADDR(0x10000))
|
||||
symtab_err = 1;
|
||||
|
||||
if (symtab_err)
|
||||
{
|
||||
printf ("(bad)");
|
||||
mbi.syms.e.num = 0;
|
||||
mbi.syms.e.size = 0;
|
||||
mbi.syms.e.addr = 0;
|
||||
mbi.syms.e.shndx = 0;
|
||||
cur_addr = 0;
|
||||
}
|
||||
else
|
||||
mbi.flags |= MB_INFO_ELF_SHDR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
/*
|
||||
* GRUB -- GRand Unified Bootloader
|
||||
* Copyright (C) 1996 Erich Boleyn <erich@uruk.org>
|
||||
* Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -29,7 +29,7 @@ typedef unsigned long Elf32_Word;
|
|||
|
||||
/* ELF header */
|
||||
typedef struct
|
||||
{
|
||||
{
|
||||
|
||||
#define EI_NIDENT 16
|
||||
|
||||
|
@ -84,7 +84,7 @@ typedef struct
|
|||
#define SHN_COMMON 0xfff2
|
||||
#define SHN_HIRESERVE 0xffff
|
||||
Elf32_Half e_shstrndx; /* section header table index */
|
||||
}
|
||||
}
|
||||
Elf32_Ehdr;
|
||||
|
||||
|
||||
|
@ -95,17 +95,32 @@ Elf32_Ehdr;
|
|||
& (h.e_ident[EI_VERSION] == EV_CURRENT) & (h.e_type == ET_EXEC) \
|
||||
& (h.e_machine == EM_386) & (h.e_version == EV_CURRENT))
|
||||
|
||||
/* section table - ? */
|
||||
typedef struct
|
||||
{
|
||||
Elf32_Word sh_name; /* Section name (string tbl index) */
|
||||
Elf32_Word sh_type; /* Section type */
|
||||
Elf32_Word sh_flags; /* Section flags */
|
||||
Elf32_Addr sh_addr; /* Section virtual addr at execution */
|
||||
Elf32_Off sh_offset; /* Section file offset */
|
||||
Elf32_Word sh_size; /* Section size in bytes */
|
||||
Elf32_Word sh_link; /* Link to another section */
|
||||
Elf32_Word sh_info; /* Additional section information */
|
||||
Elf32_Word sh_addralign; /* Section alignment */
|
||||
Elf32_Word sh_entsize; /* Entry size if section holds table */
|
||||
}
|
||||
Elf32_Shdr;
|
||||
|
||||
/* symbol table - page 4-25, figure 4-15 */
|
||||
typedef struct
|
||||
{
|
||||
{
|
||||
Elf32_Word st_name;
|
||||
Elf32_Addr st_value;
|
||||
Elf32_Word st_size;
|
||||
unsigned char st_info;
|
||||
unsigned char st_other;
|
||||
Elf32_Half st_shndx;
|
||||
}
|
||||
}
|
||||
Elf32_Sym;
|
||||
|
||||
/* symbol type and binding attributes - page 4-26 */
|
||||
|
@ -143,7 +158,7 @@ Elf32_Sym;
|
|||
/* program header - page 5-2, figure 5-1 */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
{
|
||||
Elf32_Word p_type;
|
||||
Elf32_Off p_offset;
|
||||
Elf32_Addr p_vaddr;
|
||||
|
@ -152,7 +167,7 @@ typedef struct
|
|||
Elf32_Word p_memsz;
|
||||
Elf32_Word p_flags;
|
||||
Elf32_Word p_align;
|
||||
}
|
||||
}
|
||||
Elf32_Phdr;
|
||||
|
||||
/* segment types - page 5-3, figure 5-2 */
|
||||
|
@ -179,7 +194,7 @@ Elf32_Phdr;
|
|||
/* dynamic structure - page 5-15, figure 5-9 */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
{
|
||||
Elf32_Sword d_tag;
|
||||
union
|
||||
{
|
||||
|
@ -187,7 +202,7 @@ typedef struct
|
|||
Elf32_Addr d_ptr;
|
||||
}
|
||||
d_un;
|
||||
}
|
||||
}
|
||||
Elf32_Dyn;
|
||||
|
||||
/* Dynamic array tags - page 5-16, figure 5-10. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue