|  | @@ -72,6 +72,23 @@ void unregister_image ( struct image *image ) {
 | 
		
	
		
			
			| 72 | 72 |  	DBGC ( image, "IMAGE %p unregistered\n", image );
 | 
		
	
		
			
			| 73 | 73 |  }
 | 
		
	
		
			
			| 74 | 74 |  
 | 
		
	
		
			
			|  | 75 | +/**
 | 
		
	
		
			
			|  | 76 | + * Find image by name
 | 
		
	
		
			
			|  | 77 | + *
 | 
		
	
		
			
			|  | 78 | + * @v name		Image name
 | 
		
	
		
			
			|  | 79 | + * @ret image		Executable/loadable image, or NULL
 | 
		
	
		
			
			|  | 80 | + */
 | 
		
	
		
			
			|  | 81 | +struct image * find_image ( const char *name ) {
 | 
		
	
		
			
			|  | 82 | +	struct image *image;
 | 
		
	
		
			
			|  | 83 | +
 | 
		
	
		
			
			|  | 84 | +	list_for_each_entry ( image, &images, list ) {
 | 
		
	
		
			
			|  | 85 | +		if ( strcmp ( image->name, name ) == 0 )
 | 
		
	
		
			
			|  | 86 | +			return image;
 | 
		
	
		
			
			|  | 87 | +	}
 | 
		
	
		
			
			|  | 88 | +
 | 
		
	
		
			
			|  | 89 | +	return NULL;
 | 
		
	
		
			
			|  | 90 | +}
 | 
		
	
		
			
			|  | 91 | +
 | 
		
	
		
			
			| 75 | 92 |  /**
 | 
		
	
		
			
			| 76 | 93 |   * Load executable/loadable image into memory
 | 
		
	
		
			
			| 77 | 94 |   *
 | 
		
	
	
		
			
			|  | @@ -89,6 +106,7 @@ int image_load ( struct image *image ) {
 | 
		
	
		
			
			| 89 | 106 |  		return rc;
 | 
		
	
		
			
			| 90 | 107 |  	}
 | 
		
	
		
			
			| 91 | 108 |  
 | 
		
	
		
			
			|  | 109 | +	image->flags |= IMAGE_LOADED;
 | 
		
	
		
			
			| 92 | 110 |  	return 0;
 | 
		
	
		
			
			| 93 | 111 |  }
 | 
		
	
		
			
			| 94 | 112 |  
 | 
		
	
	
		
			
			|  | @@ -111,6 +129,7 @@ int image_autoload ( struct image *image ) {
 | 
		
	
		
			
			| 111 | 129 |  			       image, image->type->name, strerror ( rc ) );
 | 
		
	
		
			
			| 112 | 130 |  			return rc;
 | 
		
	
		
			
			| 113 | 131 |  		}
 | 
		
	
		
			
			|  | 132 | +		image->flags |= IMAGE_LOADED;
 | 
		
	
		
			
			| 114 | 133 |  		return 0;
 | 
		
	
		
			
			| 115 | 134 |  	}
 | 
		
	
		
			
			| 116 | 135 |  
 | 
		
	
	
		
			
			|  | @@ -127,8 +146,16 @@ int image_autoload ( struct image *image ) {
 | 
		
	
		
			
			| 127 | 146 |  int image_exec ( struct image *image ) {
 | 
		
	
		
			
			| 128 | 147 |  	int rc;
 | 
		
	
		
			
			| 129 | 148 |  
 | 
		
	
		
			
			|  | 149 | +	/* Image must be loaded first */
 | 
		
	
		
			
			|  | 150 | +	if ( ! ( image->flags & IMAGE_LOADED ) ) {
 | 
		
	
		
			
			|  | 151 | +		DBGC ( image, "IMAGE %p could not execute: not loaded\n",
 | 
		
	
		
			
			|  | 152 | +		       image );
 | 
		
	
		
			
			|  | 153 | +		return -ENOTTY;
 | 
		
	
		
			
			|  | 154 | +	}
 | 
		
	
		
			
			|  | 155 | +
 | 
		
	
		
			
			| 130 | 156 |  	assert ( image->type != NULL );
 | 
		
	
		
			
			| 131 | 157 |  
 | 
		
	
		
			
			|  | 158 | +	/* Try executing the image */
 | 
		
	
		
			
			| 132 | 159 |  	if ( ( rc = image->type->exec ( image ) ) != 0 ) {
 | 
		
	
		
			
			| 133 | 160 |  		DBGC ( image, "IMAGE %p could not execute: %s\n",
 | 
		
	
		
			
			| 134 | 161 |  		       image, strerror ( rc ) );
 |