Browse Source

[pxeprefix] Place temporary stack after iPXE binary

Some BIOSes (observed on a Supermicro system with an AMI BIOS) seem to
use the area immediately below 0x7c00 to store data related to the
boot process.  This data is currently liable to be overwritten by the
temporary stack used while decompressing and installing iPXE.

Try to avoid any such problems by placing the temporary stack
immediately after the loaded iPXE binary.  Any memory used by the
stack could then potentially have been overwritten anyway by a larger
binary.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
9e5152e095
1 changed files with 18 additions and 3 deletions
  1. 18
    3
      src/arch/i386/prefix/pxeprefix.S

+ 18
- 3
src/arch/i386/prefix/pxeprefix.S View File

@@ -19,6 +19,8 @@ FILE_LICENCE ( GPL2_OR_LATER )
19 19
 #define EB_MAGIC_1 ( 'E' + ( 't' << 8 ) + ( 'h' << 16 ) + ( 'e' << 24 ) )
20 20
 #define EB_MAGIC_2 ( 'r' + ( 'b' << 8 ) + ( 'o' << 16 ) + ( 'o' << 24 ) )
21 21
 
22
+#define PREFIX_STACK_SIZE 2048
23
+
22 24
 /*****************************************************************************
23 25
  * Entry point:	set operating context, print welcome message
24 26
  *****************************************************************************
@@ -46,10 +48,11 @@ _pxe_start:
46 48
 	movw	%ax, %ds
47 49
 	movw	$0x40, %ax		/* BIOS data segment access */
48 50
 	movw	%ax, %fs
49
-	/* Set up stack just below 0x7c00 */
50
-	xorw	%ax, %ax
51
+	/* Set up temporary stack immediately after the iPXE image */
52
+	movw	%cs, %ax
53
+	addw	image_size_pgh, %ax
51 54
 	movw	%ax, %ss
52
-	movl	$0x7c00, %esp
55
+	movl	$PREFIX_STACK_SIZE, %esp
53 56
 	/* Clear direction flag, for the sake of sanity */
54 57
 	cld
55 58
 	/* Print welcome message */
@@ -60,6 +63,18 @@ _pxe_start:
60 63
 10:	.asciz	"PXE->EB:"
61 64
 	.previous
62 65
 
66
+	/* Image size (for stack placement calculation) */
67
+	.section ".prefix.data", "aw", @progbits
68
+image_size_pgh:
69
+	.word	0
70
+	.previous
71
+	.section ".zinfo.fixup", "a", @progbits	/* Compressor fixups */
72
+	.ascii	"ADDW"
73
+	.long	image_size_pgh
74
+	.long	16
75
+	.long	0
76
+	.previous
77
+
63 78
 /*****************************************************************************
64 79
  * Find us a usable !PXE or PXENV+ entry point
65 80
  *****************************************************************************

Loading…
Cancel
Save