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
  */
42
  */
43
 __asmcall void relocate ( struct i386_all_regs *ix86 ) {
43
 __asmcall void relocate ( struct i386_all_regs *ix86 ) {
44
 	struct memory_map memmap;
44
 	struct memory_map memmap;
45
-	unsigned long start, end, size, padded_size;
45
+	unsigned long start, end, size, padded_size, max;
46
 	unsigned long new_start, new_end;
46
 	unsigned long new_start, new_end;
47
 	unsigned i;
47
 	unsigned i;
48
 
48
 
57
 	      "...need %lx bytes for %d-byte alignment\n",
57
 	      "...need %lx bytes for %d-byte alignment\n",
58
 	      start, end, padded_size, max_align );
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
 	/* Walk through the memory map and find the highest address
67
 	/* Walk through the memory map and find the highest address
61
 	 * below 4GB that iPXE will fit into.
68
 	 * below 4GB that iPXE will fit into.
62
 	 */
69
 	 */
67
 
74
 
68
 		DBG ( "Considering [%llx,%llx)\n", region->start, region->end);
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
 			continue;
83
 			continue;
77
 		}
84
 		}
78
 		r_start = region->start;
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
 		} else {
89
 		} else {
83
 			r_end = region->end;
90
 			r_end = region->end;
84
 		}
91
 		}

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

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

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

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

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

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

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

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

Loading…
Cancel
Save