Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #include <gpxe/refcnt.h>
  13. struct uri;
  14. struct image_type;
  15. /** An executable or loadable image */
  16. struct image {
  17. /** Reference count */
  18. struct refcnt refcnt;
  19. /** List of registered images */
  20. struct list_head list;
  21. /** URI of image */
  22. struct uri *uri;
  23. /** Name */
  24. char name[16];
  25. /** Flags */
  26. unsigned int flags;
  27. /** Command line to pass to image */
  28. char *cmdline;
  29. /** Raw file image */
  30. userptr_t data;
  31. /** Length of raw file image */
  32. size_t len;
  33. /** Image type, if known */
  34. struct image_type *type;
  35. /** Image type private data */
  36. union {
  37. physaddr_t phys;
  38. userptr_t user;
  39. unsigned long ul;
  40. } priv;
  41. };
  42. /** Image is loaded */
  43. #define IMAGE_LOADED 0x0001
  44. /** An executable or loadable image type */
  45. struct image_type {
  46. /** Name of this image type */
  47. char *name;
  48. /**
  49. * Load image into memory
  50. *
  51. * @v image Executable/loadable image
  52. * @ret rc Return status code
  53. *
  54. * Load the image into memory at the correct location as
  55. * determined by the file format.
  56. *
  57. * If the file image is in the correct format, the method must
  58. * update @c image->type to point to its own type (unless @c
  59. * image->type is already set). This allows the autoloading
  60. * code to disambiguate between "this is not my image format"
  61. * and "there is something wrong with this image". In
  62. * particular, setting @c image->type and then returning an
  63. * error will cause image_autoload() to abort and return an
  64. * error, rather than continuing to the next image type.
  65. */
  66. int ( * load ) ( struct image *image );
  67. /**
  68. * Execute loaded image
  69. *
  70. * @v image Loaded image
  71. * @ret rc Return status code
  72. */
  73. int ( * exec ) ( struct image *image );
  74. };
  75. /**
  76. * Multiboot image probe priority
  77. *
  78. * Multiboot images are also valid executables in another format
  79. * (e.g. ELF), so we must perform the multiboot probe first.
  80. */
  81. #define PROBE_MULTIBOOT 01
  82. /**
  83. * Normal image probe priority
  84. */
  85. #define PROBE_NORMAL 02
  86. /**
  87. * PXE image probe priority
  88. *
  89. * PXE images have no signature checks, so will claim all image files.
  90. * They must therefore be tried last in the probe order list.
  91. */
  92. #define PROBE_PXE 03
  93. /** An executable or loadable image type */
  94. #define __image_type( probe_order ) \
  95. __table ( struct image_type, image_types, probe_order )
  96. extern struct list_head images;
  97. /** Iterate over all registered images */
  98. #define for_each_image( image ) \
  99. list_for_each_entry ( (image), &images, list )
  100. extern struct image * alloc_image ( void );
  101. extern int image_set_uri ( struct image *image, struct uri *uri );
  102. extern int image_set_cmdline ( struct image *image, const char *cmdline );
  103. extern int register_image ( struct image *image );
  104. extern void unregister_image ( struct image *image );
  105. extern void promote_image ( struct image *image );
  106. struct image * find_image ( const char *name );
  107. extern int image_load ( struct image *image );
  108. extern int image_autoload ( struct image *image );
  109. extern int image_exec ( struct image *image );
  110. extern int register_and_autoload_image ( struct image *image );
  111. extern int register_and_autoexec_image ( struct image *image );
  112. /**
  113. * Increment reference count on an image
  114. *
  115. * @v image Image
  116. * @ret image Image
  117. */
  118. static inline struct image * image_get ( struct image *image ) {
  119. ref_get ( &image->refcnt );
  120. return image;
  121. }
  122. /**
  123. * Decrement reference count on an image
  124. *
  125. * @v image Image
  126. */
  127. static inline void image_put ( struct image *image ) {
  128. ref_put ( &image->refcnt );
  129. }
  130. /**
  131. * Set image name
  132. *
  133. * @v image Image
  134. * @v name New image name
  135. * @ret rc Return status code
  136. */
  137. static inline int image_set_name ( struct image *image, const char *name ) {
  138. strncpy ( image->name, name, ( sizeof ( image->name ) - 1 ) );
  139. return 0;
  140. }
  141. #endif /* _GPXE_IMAGE_H */