elfboot.c File Reference

ELF bootable image. More...

#include <errno.h>
#include <elf.h>
#include <gpxe/image.h>
#include <gpxe/elf.h>
#include <gpxe/features.h>
#include <gpxe/init.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 FEATURE (FEATURE_IMAGE,"ELF", DHCP_EB_FEATURE_ELF, 1)
struct image_type
elfboot_image_type 
__image_type (PROBE_NORMAL)
 ELF image type.
static int elfboot_exec (struct image *image)
 Execute ELF image.
static int elfboot_load (struct image *image)
 Load ELF image into memory.


Detailed Description

ELF bootable image.

Definition in file elfboot.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER   ) 

FEATURE ( FEATURE_IMAGE  ,
"ELF"  ,
DHCP_EB_FEATURE_ELF  ,
 
)

struct image_type elfboot_image_type __image_type ( PROBE_NORMAL   )  [read]

ELF image type.

static int elfboot_exec ( struct image image  )  [static]

Execute ELF image.

Parameters:
image ELF image
Return values:
rc Return status code

Definition at line 45 of file elfboot.c.

References __asm__(), DBGC, ECANCELED, entry, image::phys, PHYS_CODE, image::priv, shutdown(), and SHUTDOWN_BOOT.

00045                                                 {
00046         physaddr_t entry = image->priv.phys;
00047 
00048         /* An ELF image has no callback interface, so we need to shut
00049          * down before invoking it.
00050          */
00051         shutdown ( SHUTDOWN_BOOT );
00052 
00053         /* Jump to OS with flat physical addressing */
00054         DBGC ( image, "ELF %p starting execution at %lx\n", image, entry );
00055         __asm__ __volatile__ ( PHYS_CODE ( "call *%%edi\n\t" )
00056                                : : "D" ( entry )
00057                                : "eax", "ebx", "ecx", "edx", "esi", "ebp",
00058                                  "memory" );
00059 
00060         DBGC ( image, "ELF %p returned\n", image );
00061 
00062         /* It isn't safe to continue after calling shutdown() */
00063         while ( 1 ) {}
00064 
00065         return -ECANCELED;  /* -EIMPOSSIBLE, anyone? */
00066 }

static int elfboot_load ( struct image image  )  [static]

Load ELF image into memory.

Parameters:
image ELF file
Return values:
rc Return status code

Definition at line 74 of file elfboot.c.

References copy_from_user(), image::data, DBG, DBGC, Elf32_Ehdr::e_ident, EI_CLASS, EI_DATA, EI_MAG0, EI_MAG1, EI_MAG2, EI_MAG3, EI_VERSION, elf_load(), ELFCLASS32, ELFDATA2LSB, ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, ENOEXEC, EV_CURRENT, memcmp(), strerror(), and image::type.

00074                                                 {
00075         Elf32_Ehdr ehdr;
00076         static const uint8_t e_ident[] = {
00077                 [EI_MAG0]       = ELFMAG0,
00078                 [EI_MAG1]       = ELFMAG1,
00079                 [EI_MAG2]       = ELFMAG2,
00080                 [EI_MAG3]       = ELFMAG3,
00081                 [EI_CLASS]      = ELFCLASS32,
00082                 [EI_DATA]       = ELFDATA2LSB,
00083                 [EI_VERSION]    = EV_CURRENT,
00084         };
00085         int rc;
00086 
00087         /* Read ELF header */
00088         copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) );
00089         if ( memcmp ( ehdr.e_ident, e_ident, sizeof ( e_ident ) ) != 0 ) {
00090                 DBG ( "Invalid ELF identifier\n" );
00091                 return -ENOEXEC;
00092         }
00093 
00094         /* This is an ELF image, valid or otherwise */
00095         if ( ! image->type )
00096                 image->type = &elfboot_image_type;
00097 
00098         /* Load the image using core ELF support */
00099         if ( ( rc = elf_load ( image ) ) != 0 ) {
00100                 DBGC ( image, "ELF %p could not load: %s\n",
00101                        image, strerror ( rc ) );
00102                 return rc;
00103         }
00104 
00105         return 0;
00106 }


Generated on Tue Apr 6 20:01:12 2010 for gPXE by  doxygen 1.5.7.1