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,6 +443,8 @@ install:
443 443
 	xorl	%esi, %esi
444 444
 	/* Image destination = default */
445 445
 	xorl	%edi, %edi
446
+	/* Allow relocation */
447
+	clc
446 448
 	/* Install text and data segments */
447 449
 	call	install_prealloc
448 450
 	/* Restore registers and return */
@@ -461,6 +463,7 @@ install:
461 463
  *   %bx  : .data16 segment address
462 464
  *   %esi : Image source physical address (or zero for %cs:0000)
463 465
  *   %edi : Decompression temporary area physical address (or zero for default)
466
+ *   CF set : Avoid relocating to top of memory
464 467
  * Corrupts:
465 468
  *   none
466 469
  ****************************************************************************
@@ -473,9 +476,8 @@ install_prealloc:
473 476
 	pushal
474 477
 	pushw	%ds
475 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 482
 	/* Copy decompression temporary area physical address to %ebp */
481 483
 	movl	%edi, %ebp
@@ -570,6 +572,11 @@ a20_death_message:
570 572
 	movl	%ebp, %edi
571 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 580
 	/* Call relocate() to determine target address for relocation.
574 581
 	 * relocate() will return with %esi, %edi and %ecx set up
575 582
 	 * ready for the copy to the new location.
@@ -588,9 +595,11 @@ a20_death_message:
588 595
 
589 596
 	/* Initialise librm at new location */
590 597
 	lcall	*init_librm_vector
598
+skip_relocate:
591 599
 #endif
592 600
 
593 601
 	/* Restore registers */
602
+	popfw
594 603
 	popw	%es
595 604
 	popw	%ds
596 605
 	popal

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

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

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

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

Loading…
Cancel
Save