elf.c revision a734c64bff58bda2fa48c2795453e092167b0ff7
/*
* Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
*
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/**
* @file
*
* ELF image format
*
* A "pure" ELF image is not a bootable image. There are various
* bootable formats based upon ELF (e.g. Multiboot), which share
* common ELF-related functionality.
*/
#include <errno.h>
#include <elf.h>
typedef Elf32_Ehdr Elf_Ehdr;
typedef Elf32_Phdr Elf_Phdr;
#define ELFCLASS ELFCLASS32
/**
* Load ELF segment into memory
*
* @v image ELF file
* @v phdr ELF program header
* @v ehdr ELF executable header
* @ret entry Entry point, if found
* @ret max Maximum used address
* @ret rc Return status code
*/
physaddr_t *max ) {
unsigned long e_offset;
int rc;
/* Do nothing for non-PT_LOAD segments */
return 0;
/* Check segment lies within image */
return -ENOEXEC;
}
/* Find start address: use physical address for preference,
* fall back to virtual address if no physical address
* supplied.
*/
if ( ! dest )
if ( ! dest ) {
image );
return -ENOEXEC;
}
/* Verify and prepare segment */
return rc;
}
/* Update maximum used address, if applicable */
/* Copy image to segment */
/* Set execution address, if it lies within this segment */
if ( ! *entry ) {
}
}
return 0;
}
/**
* Load ELF image into memory
*
* @v image ELF file
* @ret entry Entry point
* @ret max Maximum used address
* @ret rc Return status code
*/
};
unsigned int phnum;
int rc;
/* Read ELF header */
sizeof ( e_ident ) ) != 0 ) {
return -ENOEXEC;
}
/* Initialise maximum used address */
*max = 0;
/* Invalidate entry point */
*entry = 0;
/* Read ELF program headers */
return -ENOEXEC;
}
return rc;
}
}
/* Check for a valid execution address */
if ( ! *entry ) {
return -ENOEXEC;
}
return 0;
}