Browse Source

[romprefix] Inhibit the use of relocation during POST

It is common for system memory maps to be grotesquely unreliable
during POST.  Many sanity checks have been added to the memory map
reading code, but these do not catch all problems.

Skip relocation entirely if called during POST.  This should avoid the
problems typically encountered, at the cost of slightly disrupting the
memory map of an operating system booted via iPXE when iPXE was
entered during POST.  Since this is a very rare special case (used,
for example, when reflashing an experimental ROM that would otherwise
prevent the system from completing POST), this is an acceptable cost.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
5a5d8dd10a

+ 12
- 3
src/arch/i386/prefix/libprefix.S View File

443
 	xorl	%esi, %esi
443
 	xorl	%esi, %esi
444
 	/* Image destination = default */
444
 	/* Image destination = default */
445
 	xorl	%edi, %edi
445
 	xorl	%edi, %edi
446
+	/* Allow relocation */
447
+	clc
446
 	/* Install text and data segments */
448
 	/* Install text and data segments */
447
 	call	install_prealloc
449
 	call	install_prealloc
448
 	/* Restore registers and return */
450
 	/* Restore registers and return */
461
  *   %bx  : .data16 segment address
463
  *   %bx  : .data16 segment address
462
  *   %esi : Image source physical address (or zero for %cs:0000)
464
  *   %esi : Image source physical address (or zero for %cs:0000)
463
  *   %edi : Decompression temporary area physical address (or zero for default)
465
  *   %edi : Decompression temporary area physical address (or zero for default)
466
+ *   CF set : Avoid relocating to top of memory
464
  * Corrupts:
467
  * Corrupts:
465
  *   none
468
  *   none
466
  ****************************************************************************
469
  ****************************************************************************
473
 	pushal
476
 	pushal
474
 	pushw	%ds
477
 	pushw	%ds
475
 	pushw	%es
478
 	pushw	%es
476
-
477
-	/* Sanity: clear the direction flag asap */
478
-	cld
479
+	cld			/* Sanity: clear the direction flag asap */
480
+	pushfw
479
 
481
 
480
 	/* Copy decompression temporary area physical address to %ebp */
482
 	/* Copy decompression temporary area physical address to %ebp */
481
 	movl	%edi, %ebp
483
 	movl	%edi, %ebp
570
 	movl	%ebp, %edi
572
 	movl	%ebp, %edi
571
 	lcall	*init_librm_vector
573
 	lcall	*init_librm_vector
572
 
574
 
575
+	/* Skip relocation if CF was set on entry */
576
+	popfw
577
+	pushfw
578
+	jc	skip_relocate
579
+
573
 	/* Call relocate() to determine target address for relocation.
580
 	/* Call relocate() to determine target address for relocation.
574
 	 * relocate() will return with %esi, %edi and %ecx set up
581
 	 * relocate() will return with %esi, %edi and %ecx set up
575
 	 * ready for the copy to the new location.
582
 	 * ready for the copy to the new location.
588
 
595
 
589
 	/* Initialise librm at new location */
596
 	/* Initialise librm at new location */
590
 	lcall	*init_librm_vector
597
 	lcall	*init_librm_vector
598
+skip_relocate:
591
 #endif
599
 #endif
592
 
600
 
593
 	/* Restore registers */
601
 	/* Restore registers */
602
+	popfw
594
 	popw	%es
603
 	popw	%es
595
 	popw	%ds
604
 	popw	%ds
596
 	popal
605
 	popal

+ 12
- 3
src/arch/i386/prefix/romprefix.S View File

407
 	 * picked up by the initial shell prompt, and we will drop
407
 	 * picked up by the initial shell prompt, and we will drop
408
 	 * into a shell.
408
 	 * into a shell.
409
 	 */
409
 	 */
410
+	stc			/* Inhibit relocation */
410
 	pushw	%cs
411
 	pushw	%cs
411
 	call	exec
412
 	call	exec
412
 2:
413
 2:
597
  * Called by the PnP BIOS when it wants to boot us.
598
  * Called by the PnP BIOS when it wants to boot us.
598
  */
599
  */
599
 bev_entry:
600
 bev_entry:
601
+	clc			/* Allow relocation */
600
 	pushw	%cs
602
 	pushw	%cs
601
 	call	exec
603
 	call	exec
602
 	lret
604
 	lret
631
 	/* Leave keypress in buffer and start iPXE.  The keypress will
633
 	/* Leave keypress in buffer and start iPXE.  The keypress will
632
 	 * cause the usual initial Ctrl-B prompt to be skipped.
634
 	 * cause the usual initial Ctrl-B prompt to be skipped.
633
 	 */
635
 	 */
636
+	clc			/* Allow relocation */
634
 	pushw	%cs
637
 	pushw	%cs
635
 	call	exec
638
 	call	exec
636
 1:	/* Try to call original INT 19 vector */
639
 1:	/* Try to call original INT 19 vector */
662
 	pushw	%cs
665
 	pushw	%cs
663
 	popw	%ds
666
 	popw	%ds
664
 
667
 
668
+	/* Preserve state of CF */
669
+	lahf
670
+
665
 	/* Print message as soon as possible */
671
 	/* Print message as soon as possible */
666
 	movw	$prodstr, %si
672
 	movw	$prodstr, %si
667
 	xorw	%di, %di
673
 	xorw	%di, %di
675
 	movw	%sp, %bp
681
 	movw	%sp, %bp
676
 
682
 
677
 	/* Obtain a reasonably-sized temporary stack */
683
 	/* Obtain a reasonably-sized temporary stack */
678
-	xorw	%ax, %ax
679
-	movw	%ax, %ss
684
+	xorw	%bx, %bx
685
+	movw	%bx, %ss
680
 	movw	$0x7c00, %sp
686
 	movw	$0x7c00, %sp
681
 
687
 
682
 	/* Install iPXE */
688
 	/* Install iPXE */
689
+	sahf
690
+	pushfw
691
+	call	alloc_basemem
692
+	popfw
683
 	movl	image_source, %esi
693
 	movl	image_source, %esi
684
 	movl	decompress_to, %edi
694
 	movl	decompress_to, %edi
685
-	call	alloc_basemem
686
 	call	install_prealloc
695
 	call	install_prealloc
687
 
696
 
688
 	/* Print message indicating successful installation */
697
 	/* Print message indicating successful installation */

+ 1
- 0
src/arch/i386/prefix/undiloader.S View File

28
 	movw	%es:14(%di), %ax
28
 	movw	%es:14(%di), %ax
29
 	movl	image_source, %esi
29
 	movl	image_source, %esi
30
 	movl	decompress_to, %edi
30
 	movl	decompress_to, %edi
31
+	clc			/* Allow relocation */
31
 	call	install_prealloc
32
 	call	install_prealloc
32
 	popw	%di
33
 	popw	%di
33
 	/* Call UNDI loader C code */
34
 	/* Call UNDI loader C code */

Loading…
Cancel
Save