Browse Source

[prefix] Allow prefix to specify an arbitrary maximum address for relocation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
24226472b2

+ 16
- 9
src/arch/i386/core/relocate.c View File

@@ -42,7 +42,7 @@ extern char _etextdata[];
42 42
  */
43 43
 __asmcall void relocate ( struct i386_all_regs *ix86 ) {
44 44
 	struct memory_map memmap;
45
-	unsigned long start, end, size, padded_size;
45
+	unsigned long start, end, size, padded_size, max;
46 46
 	unsigned long new_start, new_end;
47 47
 	unsigned i;
48 48
 
@@ -57,6 +57,13 @@ __asmcall void relocate ( struct i386_all_regs *ix86 ) {
57 57
 	      "...need %lx bytes for %d-byte alignment\n",
58 58
 	      start, end, padded_size, max_align );
59 59
 
60
+	/* Determine maximum usable address */
61
+	max = MAX_ADDR;
62
+	if ( ix86->regs.ebp && ( ix86->regs.ebp < max ) ) {
63
+		max = ix86->regs.ebp;
64
+		DBG ( "Limiting relocation to [0,%lx)\n", max );
65
+	}
66
+
60 67
 	/* Walk through the memory map and find the highest address
61 68
 	 * below 4GB that iPXE will fit into.
62 69
 	 */
@@ -67,18 +74,18 @@ __asmcall void relocate ( struct i386_all_regs *ix86 ) {
67 74
 
68 75
 		DBG ( "Considering [%llx,%llx)\n", region->start, region->end);
69 76
 		
70
-		/* Truncate block to MAX_ADDR.  This will be less than
71
-		 * 4GB, which means that we can get away with using
72
-		 * just 32-bit arithmetic after this stage.
77
+		/* Truncate block to maximum address.  This will be
78
+		 * less than 4GB, which means that we can get away
79
+		 * with using just 32-bit arithmetic after this stage.
73 80
 		 */
74
-		if ( region->start > MAX_ADDR ) {
75
-			DBG ( "...starts after MAX_ADDR=%lx\n", MAX_ADDR );
81
+		if ( region->start > max ) {
82
+			DBG ( "...starts after max=%lx\n", max );
76 83
 			continue;
77 84
 		}
78 85
 		r_start = region->start;
79
-		if ( region->end > MAX_ADDR ) {
80
-			DBG ( "...end truncated to MAX_ADDR=%lx\n", MAX_ADDR );
81
-			r_end = MAX_ADDR;
86
+		if ( region->end > max ) {
87
+			DBG ( "...end truncated to max=%lx\n", max );
88
+			r_end = max;
82 89
 		} else {
83 90
 			r_end = region->end;
84 91
 		}

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

@@ -113,7 +113,7 @@ _exe_start:
113 113
 	call	alloc_basemem
114 114
 	xorl	%esi, %esi
115 115
 	movl	$EXE_DECOMPRESS_ADDRESS, %edi
116
-	clc
116
+	xorl	%ebp, %ebp
117 117
 	call	install_prealloc
118 118
 
119 119
 	/* Set up real-mode stack */

+ 5
- 13
src/arch/i386/prefix/libprefix.S View File

@@ -326,7 +326,6 @@ process_bytes:
326 326
 #ifndef KEEP_IT_REAL
327 327
 
328 328
 	/* Preserve registers */
329
-	pushfw
330 329
 	pushl	%eax
331 330
 	pushl	%ebp
332 331
 
@@ -397,7 +396,6 @@ process_bytes:
397 396
 	/* Restore registers and return */
398 397
 	popl	%ebp
399 398
 	popl	%eax
400
-	popfw
401 399
 	ret
402 400
 
403 401
 #else /* KEEP_IT_REAL */
@@ -614,17 +612,19 @@ install:
614 612
 	/* Preserve registers */
615 613
 	pushl	%esi
616 614
 	pushl	%edi
615
+	pushl	%ebp
617 616
 	/* Allocate space for .text16 and .data16 */
618 617
 	call	alloc_basemem
619 618
 	/* Image source = %cs:0000 */
620 619
 	xorl	%esi, %esi
621 620
 	/* Image destination = default */
622 621
 	xorl	%edi, %edi
623
-	/* Allow relocation */
624
-	clc
622
+	/* Allow arbitrary relocation */
623
+	xorl	%ebp, %ebp
625 624
 	/* Install text and data segments */
626 625
 	call	install_prealloc
627 626
 	/* Restore registers and return */
627
+	popl	%ebp
628 628
 	popl	%edi
629 629
 	popl	%esi
630 630
 	ret
@@ -640,7 +640,7 @@ install:
640 640
  *   %bx  : .data16 segment address
641 641
  *   %esi : Image source physical address (or zero for %cs:0000)
642 642
  *   %edi : Decompression temporary area physical address (or zero for default)
643
- *   CF set : Avoid relocating to top of memory
643
+ *   %ebp : Maximum end address for relocation (or zero for no maximum)
644 644
  * Corrupts:
645 645
  *   none
646 646
  ****************************************************************************
@@ -655,7 +655,6 @@ install_prealloc:
655 655
 	pushw	%ds
656 656
 	pushw	%es
657 657
 	cld			/* Sanity: clear the direction flag asap */
658
-	pushfw
659 658
 
660 659
 	/* Set up %ds for (read-only) access to .prefix */
661 660
 	pushw	%cs
@@ -791,11 +790,6 @@ payload_death_message:
791 790
 	movw	%ax, (init_librm_vector+2)
792 791
 	lcall	*init_librm_vector
793 792
 
794
-	/* Skip relocation if CF was set on entry */
795
-	popfw
796
-	pushfw
797
-	jc	skip_relocate
798
-
799 793
 	/* Call relocate() to determine target address for relocation.
800 794
 	 * relocate() will return with %esi, %edi and %ecx set up
801 795
 	 * ready for the copy to the new location.
@@ -818,7 +812,6 @@ payload_death_message:
818 812
 	/* Initialise librm at new location */
819 813
 	progress "  init_librm\n"
820 814
 	lcall	*init_librm_vector
821
-skip_relocate:
822 815
 #endif
823 816
 
824 817
 	/* Close access to payload */
@@ -827,7 +820,6 @@ skip_relocate:
827 820
 	lcall	*close_payload_vector
828 821
 
829 822
 	/* Restore registers */
830
-	popfw
831 823
 	popw	%es
832 824
 	popw	%ds
833 825
 	popal

+ 8
- 14
src/arch/i386/prefix/romprefix.S View File

@@ -414,7 +414,7 @@ no_pmm:
414 414
 	 * picked up by the initial shell prompt, and we will drop
415 415
 	 * into a shell.
416 416
 	 */
417
-	stc			/* Inhibit relocation */
417
+	movl	$0xa0000, %ebp	/* Inhibit relocation during POST */
418 418
 	pushw	%cs
419 419
 	call	exec
420 420
 2:
@@ -614,7 +614,7 @@ decompress_to:
614 614
  * Called by the PnP BIOS when it wants to boot us.
615 615
  */
616 616
 bev_entry:
617
-	clc			/* Allow relocation */
617
+	xorl	%ebp, %ebp	/* Allow relocation */
618 618
 	pushw	%cs
619 619
 	call	exec
620 620
 	lret
@@ -649,7 +649,7 @@ int19_entry:
649 649
 	/* Leave keypress in buffer and start iPXE.  The keypress will
650 650
 	 * cause the usual initial Ctrl-B prompt to be skipped.
651 651
 	 */
652
-	clc			/* Allow relocation */
652
+	xorl	%ebp, %ebp	/* Allow relocation */
653 653
 	pushw	%cs
654 654
 	call	exec
655 655
 1:	/* Try to call original INT 19 vector */
@@ -681,9 +681,6 @@ exec:	/* Set %ds = %cs */
681 681
 	pushw	%cs
682 682
 	popw	%ds
683 683
 
684
-	/* Preserve state of CF */
685
-	lahf
686
-
687 684
 	/* Print message as soon as possible */
688 685
 	movw	$prodstr, %si
689 686
 	xorw	%di, %di
@@ -693,8 +690,8 @@ exec:	/* Set %ds = %cs */
693 690
 
694 691
 	/* Store magic word on BIOS stack and remember BIOS %ss:sp */
695 692
 	pushl	$STACK_MAGIC
696
-	movw	%ss, %dx
697
-	movw	%sp, %bp
693
+	movw	%ss, %cx
694
+	movw	%sp, %dx
698 695
 
699 696
 	/* Obtain a reasonably-sized temporary stack */
700 697
 	xorw	%bx, %bx
@@ -702,10 +699,7 @@ exec:	/* Set %ds = %cs */
702 699
 	movw	$0x7c00, %sp
703 700
 
704 701
 	/* Install iPXE */
705
-	sahf
706
-	pushfw
707 702
 	call	alloc_basemem
708
-	popfw
709 703
 	movl	image_source, %esi
710 704
 	movl	decompress_to, %edi
711 705
 	call	install_prealloc
@@ -728,14 +722,14 @@ exec:	/* Set %ds = %cs */
728 722
 	pushl	$main
729 723
 	pushw	%cs
730 724
 	call	prot_call
731
-	popl	%ecx /* discard */
725
+	popl	%eax /* discard */
732 726
 
733 727
 	/* Uninstall iPXE */
734 728
 	call	uninstall
735 729
 
736 730
 	/* Restore BIOS stack */
737
-	movw	%dx, %ss
738
-	movw	%bp, %sp
731
+	movw	%cx, %ss
732
+	movw	%dx, %sp
739 733
 
740 734
 	/* Check magic word on BIOS stack */
741 735
 	popl	%eax

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

@@ -14,6 +14,7 @@ undiloader:
14 14
 	/* Save registers */
15 15
 	pushl	%esi
16 16
 	pushl	%edi
17
+	pushl	%ebp
17 18
 	pushw	%ds
18 19
 	pushw	%es
19 20
 	pushw	%bx
@@ -30,7 +31,7 @@ undiloader:
30 31
 	movw	%es:14(%di), %ax
31 32
 	movl	image_source, %esi
32 33
 	movl	decompress_to, %edi
33
-	clc			/* Allow relocation */
34
+	xorl	%ebp, %ebp		/* Allow relocation */
34 35
 	call	install_prealloc
35 36
 	popw	%di
36 37
 	/* Call UNDI loader C code */
@@ -46,6 +47,7 @@ undiloader:
46 47
 	popw	%bx
47 48
 	popw	%es
48 49
 	popw	%ds
50
+	popl	%ebp
49 51
 	popl	%edi
50 52
 	popl	%esi
51 53
 	lret

Loading…
Cancel
Save