/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009 Free Software Foundation, Inc.
*
* 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/>.
*/
#if defined(MULTIBOOT_LOAD_ELF32)
#elif defined(MULTIBOOT_LOAD_ELF64)
#else
#error "I'm confused"
#endif
#define CONCAT_(a,b) a ## b
/* Check if BUFFER contains ELF32 (or ELF64). */
static int
{
}
static grub_err_t
{
char *phdr_base;
int i;
/* FIXME: Should we support program headers at strange locations? */
#if defined (MULTIBOOT_LOAD_ELF64) && defined (__mips)
/* We still in 32-bit mode. */
#else
/* We still in 32-bit mode. */
#endif
/* Load every loadable segment in memory. */
{
{
void *source;
{
if (err)
{
return err;
}
}
{
== (grub_off_t) -1)
return grub_error (GRUB_ERR_BAD_OS,
"invalid offset in program header");
return grub_error (GRUB_ERR_BAD_OS,
"couldn't read segment from file");
}
}
}
{
break;
}
#if defined (__i386__) || defined (__x86_64__)
grub_multiboot_payload_eip |= 0x80000000;
#else
#endif
{
if (!shdr)
return grub_errno;
return grub_error (GRUB_ERR_BAD_OS,
"invalid offset to section headers");
return grub_error (GRUB_ERR_BAD_OS,
"couldn't read sections headers from file");
{
void *src;
/* This section is a loaded section,
so we don't care. */
continue;
/* This section is empty, so we don't care. */
continue;
{
&ch, 0,
if (err)
{
return err;
}
}
return grub_error (GRUB_ERR_BAD_OS,
"invalid offset in section header");
return grub_error (GRUB_ERR_BAD_OS,
"couldn't read segment from file");
}
}
return grub_errno;
}