123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
-
-
- #include <errno.h>
- #include <elf.h>
- #include <gpxe/image.h>
- #include <gpxe/elf.h>
- #include <gpxe/features.h>
- #include <gpxe/init.h>
-
-
-
- FEATURE ( FEATURE_IMAGE, "ELF", DHCP_EB_FEATURE_ELF, 1 );
-
- struct image_type elfboot_image_type __image_type ( PROBE_NORMAL );
-
-
- static int elfboot_exec ( struct image *image ) {
- physaddr_t entry = image->priv.phys;
-
-
-
- shutdown();
-
-
- __asm__ __volatile__ ( PHYS_CODE ( "call *%%edi\n\t" )
- : : "D" ( entry )
- : "eax", "ebx", "ecx", "edx", "esi", "ebp",
- "memory" );
-
- DBGC ( image, "ELF %p returned\n", image );
-
-
- while ( 1 ) {}
-
- return -ECANCELED;
- }
-
-
- static int elfboot_load ( struct image *image ) {
- Elf32_Ehdr ehdr;
- static const uint8_t e_ident[] = {
- [EI_MAG0] = ELFMAG0,
- [EI_MAG1] = ELFMAG1,
- [EI_MAG2] = ELFMAG2,
- [EI_MAG3] = ELFMAG3,
- [EI_CLASS] = ELFCLASS32,
- [EI_DATA] = ELFDATA2LSB,
- [EI_VERSION] = EV_CURRENT,
- };
- int rc;
-
-
- copy_from_user ( &ehdr, image->data, 0, sizeof ( ehdr ) );
- if ( memcmp ( ehdr.e_ident, e_ident, sizeof ( e_ident ) ) != 0 ) {
- DBG ( "Invalid ELF identifier\n" );
- return -ENOEXEC;
- }
-
-
- if ( ! image->type )
- image->type = &elfboot_image_type;
-
-
- if ( ( rc = elf_load ( image ) ) != 0 ) {
- DBGC ( image, "ELF %p could not load: %s\n",
- image, strerror ( rc ) );
- return rc;
- }
-
- return 0;
- }
-
-
- struct image_type elfboot_image_type __image_type ( PROBE_NORMAL ) = {
- .name = "ELF",
- .load = elfboot_load,
- .exec = elfboot_exec,
- };
|