| 
				
			 | 
			
			
				
				@@ -23,6 +23,7 @@ 
			 | 
		
		
	
		
			
			| 
				23
			 | 
			
				23
			 | 
			
			
				
				 #include <errno.h> 
			 | 
		
		
	
		
			
			| 
				24
			 | 
			
				24
			 | 
			
			
				
				 #include <assert.h> 
			 | 
		
		
	
		
			
			| 
				25
			 | 
			
				25
			 | 
			
			
				
				 #include <gpxe/list.h> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				
				+#include <gpxe/umalloc.h> 
			 | 
		
		
	
		
			
			| 
				26
			 | 
			
				27
			 | 
			
			
				
				 #include <gpxe/image.h> 
			 | 
		
		
	
		
			
			| 
				27
			 | 
			
				28
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				28
			 | 
			
				29
			 | 
			
			
				
				 /** @file 
			 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			
				
				@@ -40,6 +41,35 @@ static struct image_type image_types[0] 
			 | 
		
		
	
		
			
			| 
				40
			 | 
			
				41
			 | 
			
			
				
				 static struct image_type image_types_end[0] 
			 | 
		
		
	
		
			
			| 
				41
			 | 
			
				42
			 | 
			
			
				
				 	__table_end ( struct image_type, image_types ); 
			 | 
		
		
	
		
			
			| 
				42
			 | 
			
				43
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				
				+/** 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				
				+ * Free executable/loadable image 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				
				+ * 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				
				+ * @v refcnt		Reference counter 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				
				+ */ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				
				+static void free_image ( struct refcnt *refcnt ) { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				
				+	struct image *image = container_of ( refcnt, struct image, refcnt ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				
				+	ufree ( image->data ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				
				+	free ( image ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				
				+	DBGC ( image, "IMAGE %p freed\n", image ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				
				+} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				
				+/** 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				
				+ * Allocate executable/loadable image 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				
				+ * 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				
				+ * @ret image		Executable/loadable image 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				
				+ */ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				
				+struct image * alloc_image ( void ) { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				
				+	struct image *image; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				
				+	image = malloc ( sizeof ( *image ) ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				
				+	if ( image ) { 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				
				+		memset ( image, 0, sizeof ( *image ) ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				
				+		image->refcnt.free = free_image; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				
				+	} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				
				+	return image; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				71
			 | 
			
			
				
				+} 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				72
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				43
			 | 
			
				73
			 | 
			
			
				
				 /** 
			 | 
		
		
	
		
			
			| 
				44
			 | 
			
				74
			 | 
			
			
				
				  * Register executable/loadable image 
			 | 
		
		
	
		
			
			| 
				45
			 | 
			
				75
			 | 
			
			
				
				  * 
			 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			
				
				@@ -56,6 +86,7 @@ int register_image ( struct image *image ) { 
			 | 
		
		
	
		
			
			| 
				56
			 | 
			
				86
			 | 
			
			
				
				 	} 
			 | 
		
		
	
		
			
			| 
				57
			 | 
			
				87
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				58
			 | 
			
				88
			 | 
			
			
				
				 	/* Add to image list */ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				89
			 | 
			
			
				
				+	image_get ( image ); 
			 | 
		
		
	
		
			
			| 
				59
			 | 
			
				90
			 | 
			
			
				
				 	list_add_tail ( &image->list, &images ); 
			 | 
		
		
	
		
			
			| 
				60
			 | 
			
				91
			 | 
			
			
				
				 	DBGC ( image, "IMAGE %p at [%lx,%lx) registered as %s\n", 
			 | 
		
		
	
		
			
			| 
				61
			 | 
			
				92
			 | 
			
			
				
				 	       image, user_to_phys ( image->data, 0 ), 
			 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			
				
				@@ -71,6 +102,7 @@ int register_image ( struct image *image ) { 
			 | 
		
		
	
		
			
			| 
				71
			 | 
			
				102
			 | 
			
			
				
				  */ 
			 | 
		
		
	
		
			
			| 
				72
			 | 
			
				103
			 | 
			
			
				
				 void unregister_image ( struct image *image ) { 
			 | 
		
		
	
		
			
			| 
				73
			 | 
			
				104
			 | 
			
			
				
				 	list_del ( &image->list ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				105
			 | 
			
			
				
				+	image_put ( image ); 
			 | 
		
		
	
		
			
			| 
				74
			 | 
			
				106
			 | 
			
			
				
				 	DBGC ( image, "IMAGE %p unregistered\n", image ); 
			 | 
		
		
	
		
			
			| 
				75
			 | 
			
				107
			 | 
			
			
				
				 } 
			 | 
		
		
	
		
			
			| 
				76
			 | 
			
				108
			 | 
			
			
				
				  
			 |