2007-01-11 17:04:36 +01:00
|
|
|
#ifndef _GPXE_IMAGE_H
|
|
|
|
#define _GPXE_IMAGE_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
2007-01-12 00:43:29 +01:00
|
|
|
* Executable/loadable images
|
2007-01-11 17:04:36 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gpxe/tables.h>
|
2007-01-12 00:43:29 +01:00
|
|
|
#include <gpxe/list.h>
|
|
|
|
#include <gpxe/uaccess.h>
|
|
|
|
|
|
|
|
struct image_type;
|
2007-01-11 17:04:36 +01:00
|
|
|
|
2007-01-12 06:26:19 +01:00
|
|
|
/** Maximum length of a command line */
|
|
|
|
#define CMDLINE_MAX 128
|
|
|
|
|
2007-01-11 17:04:36 +01:00
|
|
|
/** An executable or loadable image */
|
|
|
|
struct image {
|
2007-01-12 00:43:29 +01:00
|
|
|
/** Name */
|
|
|
|
char name[16];
|
|
|
|
/** List of registered images */
|
|
|
|
struct list_head list;
|
|
|
|
|
|
|
|
/** Command line to pass to image */
|
2007-01-12 06:26:19 +01:00
|
|
|
char cmdline[CMDLINE_MAX];
|
2007-01-12 00:43:29 +01:00
|
|
|
|
2007-01-11 17:04:36 +01:00
|
|
|
/** Raw file image */
|
2007-01-11 17:07:30 +01:00
|
|
|
userptr_t data;
|
2007-01-11 17:04:36 +01:00
|
|
|
/** Length of raw file image */
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
/** Entry point */
|
|
|
|
physaddr_t entry;
|
2007-01-11 22:19:29 +01:00
|
|
|
|
2007-01-12 00:43:29 +01:00
|
|
|
/** Image type, if known */
|
|
|
|
struct image_type *type;
|
2007-01-12 07:03:02 +01:00
|
|
|
|
|
|
|
/** Flags */
|
|
|
|
unsigned int flags;
|
2007-01-11 17:04:36 +01:00
|
|
|
};
|
|
|
|
|
2007-01-12 07:03:02 +01:00
|
|
|
/** Image is loaded */
|
|
|
|
#define IMAGE_LOADED 0x0001
|
|
|
|
|
2007-01-11 17:04:36 +01:00
|
|
|
/** An executable or loadable image type */
|
|
|
|
struct image_type {
|
|
|
|
/** Name of this image type */
|
|
|
|
char *name;
|
2007-01-12 00:43:29 +01:00
|
|
|
/**
|
|
|
|
* Load image into memory
|
2007-01-11 17:04:36 +01:00
|
|
|
*
|
|
|
|
* @v image Executable/loadable image
|
|
|
|
* @ret rc Return status code
|
|
|
|
*
|
|
|
|
* Load the image into memory. The file image may be
|
|
|
|
* discarded after this call; the method must preserve any
|
|
|
|
* information it may require later (e.g. the execution
|
|
|
|
* address) within the @c image structure.
|
2007-01-11 18:06:25 +01:00
|
|
|
*
|
2007-01-12 00:43:29 +01:00
|
|
|
* If the file image is in the correct format, the method must
|
|
|
|
* update @c image->type to point to its own type (unless @c
|
|
|
|
* image->type is already set). This allows the autoloading
|
|
|
|
* code to disambiguate between "this is not my image format"
|
|
|
|
* and "there is something wrong with this image". In
|
|
|
|
* particular, setting @c image->type and then returning an
|
|
|
|
* error will cause image_autoload() to abort and return an
|
|
|
|
* error, rather than continuing to the next image type.
|
2007-01-11 17:04:36 +01:00
|
|
|
*/
|
|
|
|
int ( * load ) ( struct image *image );
|
2007-01-12 00:43:29 +01:00
|
|
|
/**
|
|
|
|
* Execute loaded image
|
|
|
|
*
|
|
|
|
* @v image Loaded image
|
|
|
|
* @ret rc Return status code
|
|
|
|
*/
|
|
|
|
int ( * exec ) ( struct image *image );
|
2007-01-11 17:04:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/** An executable or loadable image type */
|
|
|
|
#define __image_type __table ( struct image_type, image_types, 01 )
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An unverifiable executable or loadable image type
|
|
|
|
*
|
|
|
|
* This should be used to mark image types for which there are no
|
|
|
|
* signature or other checks that can be used to verify the validity
|
|
|
|
* of the image (such as PXE images). These will then be tried last
|
|
|
|
* in the list of image types.
|
|
|
|
*/
|
|
|
|
#define __default_image_type __table ( struct image_type, image_types, 02 )
|
|
|
|
|
2007-01-12 00:43:29 +01:00
|
|
|
extern struct list_head images;
|
|
|
|
|
|
|
|
/** Iterate over all registered images */
|
|
|
|
#define for_each_image( image ) \
|
|
|
|
list_for_each_entry ( (image), &images, list )
|
|
|
|
|
|
|
|
extern int register_image ( struct image *image );
|
|
|
|
extern void unregister_image ( struct image *image );
|
2007-01-12 07:03:02 +01:00
|
|
|
struct image * find_image ( const char *name );
|
2007-01-12 07:26:59 +01:00
|
|
|
extern void free_image ( struct image *image );
|
2007-01-12 00:43:29 +01:00
|
|
|
extern int image_load ( struct image *image );
|
|
|
|
extern int image_autoload ( struct image *image );
|
|
|
|
extern int image_exec ( struct image *image );
|
|
|
|
|
2007-01-11 17:04:36 +01:00
|
|
|
#endif /* _GPXE_IMAGE_H */
|