You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

image.h 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _GPXE_IMAGE_H
  2. #define _GPXE_IMAGE_H
  3. /**
  4. * @file
  5. *
  6. * Executable/loadable images
  7. *
  8. */
  9. #include <gpxe/tables.h>
  10. #include <gpxe/list.h>
  11. #include <gpxe/uaccess.h>
  12. struct image_type;
  13. /** Maximum length of a command line */
  14. #define CMDLINE_MAX 128
  15. /** An executable or loadable image */
  16. struct image {
  17. /** Name */
  18. char name[16];
  19. /** List of registered images */
  20. struct list_head list;
  21. /** Flags */
  22. unsigned int flags;
  23. /** Command line to pass to image */
  24. char cmdline[CMDLINE_MAX];
  25. /** Raw file image */
  26. userptr_t data;
  27. /** Length of raw file image */
  28. size_t len;
  29. /** Image type, if known */
  30. struct image_type *type;
  31. /** Image type private data */
  32. union {
  33. physaddr_t phys;
  34. userptr_t user;
  35. unsigned long ul;
  36. } priv;
  37. };
  38. /** Image is loaded */
  39. #define IMAGE_LOADED 0x0001
  40. /** An executable or loadable image type */
  41. struct image_type {
  42. /** Name of this image type */
  43. char *name;
  44. /**
  45. * Load image into memory
  46. *
  47. * @v image Executable/loadable image
  48. * @ret rc Return status code
  49. *
  50. * Load the image into memory at the correct location as
  51. * determined by the file format.
  52. *
  53. * If the file image is in the correct format, the method must
  54. * update @c image->type to point to its own type (unless @c
  55. * image->type is already set). This allows the autoloading
  56. * code to disambiguate between "this is not my image format"
  57. * and "there is something wrong with this image". In
  58. * particular, setting @c image->type and then returning an
  59. * error will cause image_autoload() to abort and return an
  60. * error, rather than continuing to the next image type.
  61. */
  62. int ( * load ) ( struct image *image );
  63. /**
  64. * Execute loaded image
  65. *
  66. * @v image Loaded image
  67. * @ret rc Return status code
  68. */
  69. int ( * exec ) ( struct image *image );
  70. };
  71. /**
  72. * Multiboot image probe priority
  73. *
  74. * Multiboot images are also valid executables in another format
  75. * (e.g. ELF), so we must perform the multiboot probe first.
  76. */
  77. #define PROBE_MULTIBOOT 01
  78. /**
  79. * Normal image probe priority
  80. */
  81. #define PROBE_NORMAL 02
  82. /**
  83. * PXE image probe priority
  84. *
  85. * PXE images have no signature checks, so will claim all image files.
  86. * They must therefore be tried last in the probe order list.
  87. */
  88. #define PROBE_PXE 03
  89. /** An executable or loadable image type */
  90. #define __image_type( probe_order ) \
  91. __table ( struct image_type, image_types, probe_order )
  92. extern struct list_head images;
  93. /** Iterate over all registered images */
  94. #define for_each_image( image ) \
  95. list_for_each_entry ( (image), &images, list )
  96. extern int register_image ( struct image *image );
  97. extern void unregister_image ( struct image *image );
  98. extern void promote_image ( struct image *image );
  99. struct image * find_image ( const char *name );
  100. extern int image_load ( struct image *image );
  101. extern int image_autoload ( struct image *image );
  102. extern int image_exec ( struct image *image );
  103. #endif /* _GPXE_IMAGE_H */