7 * Executable/loadable images
11 #include <gpxe/tables.h>
12 #include <gpxe/list.h>
13 #include <gpxe/uaccess.h>
14 #include <gpxe/refcnt.h>
18 /** Maximum length of a command line */
19 #define CMDLINE_MAX 128
21 /** An executable or loadable image */
23 /** Reference count */
28 /** List of registered images */
29 struct list_head list;
33 /** Command line to pass to image */
34 char cmdline[CMDLINE_MAX];
37 /** Length of raw file image */
40 /** Image type, if known */
41 struct image_type *type;
42 /** Image type private data */
50 /** Image is loaded */
51 #define IMAGE_LOADED 0x0001
53 /** An executable or loadable image type */
55 /** Name of this image type */
58 * Load image into memory
60 * @v image Executable/loadable image
61 * @ret rc Return status code
63 * Load the image into memory at the correct location as
64 * determined by the file format.
66 * If the file image is in the correct format, the method must
67 * update @c image->type to point to its own type (unless @c
68 * image->type is already set). This allows the autoloading
69 * code to disambiguate between "this is not my image format"
70 * and "there is something wrong with this image". In
71 * particular, setting @c image->type and then returning an
72 * error will cause image_autoload() to abort and return an
73 * error, rather than continuing to the next image type.
75 int ( * load ) ( struct image *image );
77 * Execute loaded image
79 * @v image Loaded image
80 * @ret rc Return status code
82 int ( * exec ) ( struct image *image );
86 * Multiboot image probe priority
88 * Multiboot images are also valid executables in another format
89 * (e.g. ELF), so we must perform the multiboot probe first.
91 #define PROBE_MULTIBOOT 01
94 * Normal image probe priority
96 #define PROBE_NORMAL 02
99 * PXE image probe priority
101 * PXE images have no signature checks, so will claim all image files.
102 * They must therefore be tried last in the probe order list.
106 /** An executable or loadable image type */
107 #define __image_type( probe_order ) \
108 __table ( struct image_type, image_types, probe_order )
110 extern struct list_head images;
112 /** Iterate over all registered images */
113 #define for_each_image( image ) \
114 list_for_each_entry ( (image), &images, list )
116 extern int register_image ( struct image *image );
117 extern void unregister_image ( struct image *image );
118 extern void promote_image ( struct image *image );
119 struct image * find_image ( const char *name );
120 extern int image_load ( struct image *image );
121 extern int image_autoload ( struct image *image );
122 extern int image_exec ( struct image *image );
125 * Increment reference count on an image
130 static inline struct image * image_get ( struct image *image ) {
131 ref_get ( &image->refcnt );
136 * Decrement reference count on an image
140 static inline void image_put ( struct image *image ) {
141 ref_put ( &image->refcnt );
144 #endif /* _GPXE_IMAGE_H */