Browse Source

Use debug autocolourisation.

Shut down before jumping to the multiboot image.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
55e6d7b70c
1 changed files with 34 additions and 18 deletions
  1. 34
    18
      src/arch/i386/image/multiboot.c

+ 34
- 18
src/arch/i386/image/multiboot.c View File

32
 #include <gpxe/segment.h>
32
 #include <gpxe/segment.h>
33
 #include <gpxe/memmap.h>
33
 #include <gpxe/memmap.h>
34
 #include <gpxe/elf.h>
34
 #include <gpxe/elf.h>
35
+#include <gpxe/shutdown.h>
35
 
36
 
36
 struct image_type multiboot_image_type __image_type ( PROBE_MULTIBOOT );
37
 struct image_type multiboot_image_type __image_type ( PROBE_MULTIBOOT );
37
 
38
 
76
 /**
77
 /**
77
  * Build multiboot memory map
78
  * Build multiboot memory map
78
  *
79
  *
80
+ * @v image		Multiboot image
79
  * @v mbinfo		Multiboot information structure
81
  * @v mbinfo		Multiboot information structure
80
  * @v mbmemmap		Multiboot memory map
82
  * @v mbmemmap		Multiboot memory map
81
  * @v limit		Maxmimum number of memory map entries
83
  * @v limit		Maxmimum number of memory map entries
82
  */
84
  */
83
-static void multiboot_build_memmap ( struct multiboot_info *mbinfo,
85
+static void multiboot_build_memmap ( struct image *image,
86
+				     struct multiboot_info *mbinfo,
84
 				     struct multiboot_memory_map *mbmemmap,
87
 				     struct multiboot_memory_map *mbmemmap,
85
 				     unsigned int limit ) {
88
 				     unsigned int limit ) {
86
 	struct memory_map memmap;
89
 	struct memory_map memmap;
93
 	memset ( mbmemmap, 0, sizeof ( *mbmemmap ) );
96
 	memset ( mbmemmap, 0, sizeof ( *mbmemmap ) );
94
 	for ( i = 0 ; i < memmap.count ; i++ ) {
97
 	for ( i = 0 ; i < memmap.count ; i++ ) {
95
 		if ( i >= limit ) {
98
 		if ( i >= limit ) {
96
-			DBG ( "Multiboot limit of %d memmap entries reached\n",
97
-			      limit );
99
+			DBGC ( image, "MULTIBOOT %p limit of %d memmap "
100
+			       "entries reached\n", image, limit );
98
 			break;
101
 			break;
99
 		}
102
 		}
100
 		mbmemmap[i].size = ( sizeof ( mbmemmap[i] ) -
103
 		mbmemmap[i].size = ( sizeof ( mbmemmap[i] ) -
135
 	for_each_image ( module_image ) {
138
 	for_each_image ( module_image ) {
136
 
139
 
137
 		if ( count >= limit ) {
140
 		if ( count >= limit ) {
138
-			DBG ( "Multiboot limit of %d modules reached\n",
139
-			      limit );
141
+			DBGC ( image, "MULTIBOOT %p limit of %d modules "
142
+			       "reached\n", image, limit );
140
 			break;
143
 			break;
141
 		}
144
 		}
142
 
145
 
176
 	/* Dump module configuration */
179
 	/* Dump module configuration */
177
 	if ( modules ) {
180
 	if ( modules ) {
178
 		for ( i = 0 ; i < count ; i++ ) {
181
 		for ( i = 0 ; i < count ; i++ ) {
179
-			DBG ( "Multiboot module %d is [%lx,%lx)\n", i,
180
-			      modules[i].mod_start, modules[i].mod_end );
182
+			DBGC ( image, "MULTIBOOT %p module %d is [%lx,%lx)\n",
183
+			       image, i, modules[i].mod_start,
184
+			       modules[i].mod_end );
181
 		}
185
 		}
182
 	}
186
 	}
183
 
187
 
219
 	memset ( &mbinfo, 0, sizeof ( mbinfo ) );
223
 	memset ( &mbinfo, 0, sizeof ( mbinfo ) );
220
 	mbinfo.flags = ( MBI_FLAG_LOADER | MBI_FLAG_MEM | MBI_FLAG_MMAP |
224
 	mbinfo.flags = ( MBI_FLAG_LOADER | MBI_FLAG_MEM | MBI_FLAG_MMAP |
221
 			 MBI_FLAG_CMDLINE | MBI_FLAG_MODS );
225
 			 MBI_FLAG_CMDLINE | MBI_FLAG_MODS );
222
-	multiboot_build_memmap ( &mbinfo, mbmemmap,
226
+	multiboot_build_memmap ( image, &mbinfo, mbmemmap,
223
 				 ( sizeof(mbmemmap) / sizeof(mbmemmap[0]) ) );
227
 				 ( sizeof(mbmemmap) / sizeof(mbmemmap[0]) ) );
224
 	mbinfo.cmdline = virt_to_phys ( image->cmdline );
228
 	mbinfo.cmdline = virt_to_phys ( image->cmdline );
225
 	mbinfo.mods_count = multiboot_build_module_list ( image, mbmodules,
229
 	mbinfo.mods_count = multiboot_build_module_list ( image, mbmodules,
227
 	mbinfo.mods_addr = virt_to_phys ( mbmodules );
231
 	mbinfo.mods_addr = virt_to_phys ( mbmodules );
228
 	mbinfo.mmap_addr = virt_to_phys ( mbmemmap );
232
 	mbinfo.mmap_addr = virt_to_phys ( mbmemmap );
229
 	mbinfo.boot_loader_name = virt_to_phys ( mb_bootloader_name );
233
 	mbinfo.boot_loader_name = virt_to_phys ( mb_bootloader_name );
230
-	
234
+
235
+	/* Multiboot images may not return and have no callback
236
+	 * interface, so shut everything down prior to booting the OS.
237
+	 */
238
+	shutdown();
239
+
231
 	/* Jump to OS with flat physical addressing */
240
 	/* Jump to OS with flat physical addressing */
232
 	__asm__ __volatile__ ( PHYS_CODE ( "call *%%edi\n\t" )
241
 	__asm__ __volatile__ ( PHYS_CODE ( "call *%%edi\n\t" )
233
 			       : : "a" ( MULTIBOOT_BOOTLOADER_MAGIC ),
242
 			       : : "a" ( MULTIBOOT_BOOTLOADER_MAGIC ),
235
 			           "D" ( image->entry )
244
 			           "D" ( image->entry )
236
 			       : "ecx", "edx", "esi", "ebp", "memory" );
245
 			       : "ecx", "edx", "esi", "ebp", "memory" );
237
 
246
 
238
-	return -ECANCELED;
247
+	DBGC ( image, "MULTIBOOT %p returned\n", image );
248
+
249
+	/* It isn't safe to continue after calling shutdown() */
250
+	while ( 1 ) {}
251
+
252
+	return -ECANCELED;  /* -EIMPOSSIBLE, anyone? */
239
 }
253
 }
240
 
254
 
241
 /**
255
 /**
306
 	memsz = ( hdr->mb.bss_end_addr - hdr->mb.load_addr );
320
 	memsz = ( hdr->mb.bss_end_addr - hdr->mb.load_addr );
307
 	buffer = phys_to_user ( hdr->mb.load_addr );
321
 	buffer = phys_to_user ( hdr->mb.load_addr );
308
 	if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
322
 	if ( ( rc = prep_segment ( buffer, filesz, memsz ) ) != 0 ) {
309
-		DBG ( "Multiboot could not prepare segment: %s\n",
310
-		      strerror ( rc ) );
323
+		DBGC ( image, "MULTIBOOT %p could not prepare segment: %s\n",
324
+		       image, strerror ( rc ) );
311
 		return rc;
325
 		return rc;
312
 	}
326
 	}
313
 
327
 
331
 
345
 
332
 	/* Load ELF image*/
346
 	/* Load ELF image*/
333
 	if ( ( rc = elf_load ( image ) ) != 0 ) {
347
 	if ( ( rc = elf_load ( image ) ) != 0 ) {
334
-		DBG ( "Multiboot ELF image failed to load: %s\n",
335
-		      strerror ( rc ) );
348
+		DBGC ( image, "MULTIBOOT %p ELF image failed to load: %s\n",
349
+		       image, strerror ( rc ) );
336
 		return rc;
350
 		return rc;
337
 	}
351
 	}
338
 
352
 
351
 
365
 
352
 	/* Locate multiboot header, if present */
366
 	/* Locate multiboot header, if present */
353
 	if ( ( rc = multiboot_find_header ( image, &hdr ) ) != 0 ) {
367
 	if ( ( rc = multiboot_find_header ( image, &hdr ) ) != 0 ) {
354
-		DBG ( "No multiboot header\n" );
368
+		DBGC ( image, "MULTIBOOT %p has no multiboot header\n",
369
+		       image );
355
 		return rc;
370
 		return rc;
356
 	}
371
 	}
357
-	DBG ( "Found multiboot header with flags %08lx\n", hdr.mb.flags );
372
+	DBGC ( image, "MULTIBOOT %p found header with flags %08lx\n",
373
+	       image, hdr.mb.flags );
358
 
374
 
359
 	/* This is a multiboot image, valid or otherwise */
375
 	/* This is a multiboot image, valid or otherwise */
360
 	if ( ! image->type )
376
 	if ( ! image->type )
362
 
378
 
363
 	/* Abort if we detect flags that we cannot support */
379
 	/* Abort if we detect flags that we cannot support */
364
 	if ( hdr.mb.flags & MB_UNSUPPORTED_FLAGS ) {
380
 	if ( hdr.mb.flags & MB_UNSUPPORTED_FLAGS ) {
365
-		DBG ( "Multiboot flags %08lx not supported\n",
366
-		      ( hdr.mb.flags & MB_UNSUPPORTED_FLAGS ) );
381
+		DBGC ( image, "MULTIBOOT %p flags %08lx not supported\n",
382
+		       image, ( hdr.mb.flags & MB_UNSUPPORTED_FLAGS ) );
367
 		return -ENOTSUP;
383
 		return -ENOTSUP;
368
 	}
384
 	}
369
 
385
 

Loading…
Cancel
Save