elfboot.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <errno.h>
00022 #include <elf.h>
00023 #include <gpxe/image.h>
00024 #include <gpxe/elf.h>
00025 #include <gpxe/features.h>
00026 #include <gpxe/init.h>
00027
00028
00029
00030
00031
00032
00033
00034
00035 FEATURE ( FEATURE_IMAGE, "ELF", DHCP_EB_FEATURE_ELF, 1 );
00036
00037 struct image_type elfboot_image_type __image_type ( PROBE_NORMAL );
00038
00039
00040
00041
00042
00043
00044
00045 static int elfboot_exec ( struct image *image ) {
00046 physaddr_t entry = image->priv.phys;
00047
00048
00049
00050
00051 shutdown ( SHUTDOWN_BOOT );
00052
00053
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
00063 while ( 1 ) {}
00064
00065 return -ECANCELED;
00066 }
00067
00068
00069
00070
00071
00072
00073
00074 static int elfboot_load ( struct image *image ) {
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
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
00095 if ( ! image->type )
00096 image->type = &elfboot_image_type;
00097
00098
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 }
00107
00108
00109 struct image_type elfboot_image_type __image_type ( PROBE_NORMAL ) = {
00110 .name = "ELF",
00111 .load = elfboot_load,
00112 .exec = elfboot_exec,
00113 };