]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[romprefix] Inhibit the use of relocation during POST
authorMichael Brown <mcb30@ipxe.org>
Sun, 25 Apr 2010 00:37:25 +0000 (01:37 +0100)
committerMichael Brown <mcb30@ipxe.org>
Sun, 25 Apr 2010 00:50:46 +0000 (01:50 +0100)
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>
src/arch/i386/prefix/libprefix.S
src/arch/i386/prefix/romprefix.S
src/arch/i386/prefix/undiloader.S

index f5f6691958fe8cbab9532bb8195c27dacea532af..eeed0ada322433d4a04b78633d867553fe2e63e1 100644 (file)
@@ -443,6 +443,8 @@ install:
        xorl    %esi, %esi
        /* Image destination = default */
        xorl    %edi, %edi
+       /* Allow relocation */
+       clc
        /* Install text and data segments */
        call    install_prealloc
        /* Restore registers and return */
@@ -461,6 +463,7 @@ install:
  *   %bx  : .data16 segment address
  *   %esi : Image source physical address (or zero for %cs:0000)
  *   %edi : Decompression temporary area physical address (or zero for default)
+ *   CF set : Avoid relocating to top of memory
  * Corrupts:
  *   none
  ****************************************************************************
@@ -473,9 +476,8 @@ install_prealloc:
        pushal
        pushw   %ds
        pushw   %es
-
-       /* Sanity: clear the direction flag asap */
-       cld
+       cld                     /* Sanity: clear the direction flag asap */
+       pushfw
 
        /* Copy decompression temporary area physical address to %ebp */
        movl    %edi, %ebp
@@ -570,6 +572,11 @@ a20_death_message:
        movl    %ebp, %edi
        lcall   *init_librm_vector
 
+       /* Skip relocation if CF was set on entry */
+       popfw
+       pushfw
+       jc      skip_relocate
+
        /* Call relocate() to determine target address for relocation.
         * relocate() will return with %esi, %edi and %ecx set up
         * ready for the copy to the new location.
@@ -588,9 +595,11 @@ a20_death_message:
 
        /* Initialise librm at new location */
        lcall   *init_librm_vector
+skip_relocate:
 #endif
 
        /* Restore registers */
+       popfw
        popw    %es
        popw    %ds
        popal
index 2858cb3f9227ff481b63948fd4ae87e24209592b..27eda346e4397de5c1b96aae2583bcf3aa8c13e0 100644 (file)
@@ -407,6 +407,7 @@ no_pmm:
         * picked up by the initial shell prompt, and we will drop
         * into a shell.
         */
+       stc                     /* Inhibit relocation */
        pushw   %cs
        call    exec
 2:
@@ -597,6 +598,7 @@ bbs_version:
  * Called by the PnP BIOS when it wants to boot us.
  */
 bev_entry:
+       clc                     /* Allow relocation */
        pushw   %cs
        call    exec
        lret
@@ -631,6 +633,7 @@ int19_entry:
        /* Leave keypress in buffer and start iPXE.  The keypress will
         * cause the usual initial Ctrl-B prompt to be skipped.
         */
+       clc                     /* Allow relocation */
        pushw   %cs
        call    exec
 1:     /* Try to call original INT 19 vector */
@@ -662,6 +665,9 @@ exec:       /* Set %ds = %cs */
        pushw   %cs
        popw    %ds
 
+       /* Preserve state of CF */
+       lahf
+
        /* Print message as soon as possible */
        movw    $prodstr, %si
        xorw    %di, %di
@@ -675,14 +681,17 @@ exec:     /* Set %ds = %cs */
        movw    %sp, %bp
 
        /* Obtain a reasonably-sized temporary stack */
-       xorw    %ax, %ax
-       movw    %ax, %ss
+       xorw    %bx, %bx
+       movw    %bx, %ss
        movw    $0x7c00, %sp
 
        /* Install iPXE */
+       sahf
+       pushfw
+       call    alloc_basemem
+       popfw
        movl    image_source, %esi
        movl    decompress_to, %edi
-       call    alloc_basemem
        call    install_prealloc
 
        /* Print message indicating successful installation */
index 36c1bef3726b5d4406c5bb894cd47908489dc8e1..6fab3a34dcb453629154c70e878f8d562c6c84db 100644 (file)
@@ -28,6 +28,7 @@ undiloader:
        movw    %es:14(%di), %ax
        movl    image_source, %esi
        movl    decompress_to, %edi
+       clc                     /* Allow relocation */
        call    install_prealloc
        popw    %di
        /* Call UNDI loader C code */