Skip to content

Commit

Permalink
[librm] Use libflat to enable A20 line on each real-to-protected tran…
Browse files Browse the repository at this point in the history
…sition

Use the shared code in libflat to perform the A20 transitions
automatically on each transition from real to protected mode.  This
allows us to remove all explicit calls to gateA20_set().

The old warnings about avoiding automatically enabling A20 are
essentially redundant; they date back to the time when we would always
start hammering the keyboard controller without first checking to see
if gate A20 was already enabled (which it almost always is).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Apr 20, 2010
1 parent 24b52ae commit 38cd203
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 227 deletions.
10 changes: 0 additions & 10 deletions src/arch/i386/drivers/net/undiload.c
Expand Up @@ -104,16 +104,6 @@ int undi_load ( struct undi_device *undi, struct undi_rom *undirom ) {
: "a" ( __from_data16 ( &undi_loader ) )
: "ebx", "ecx", "edx", "esi", "edi", "ebp" );

/* UNDI API calls may rudely change the status of A20 and not
* bother to restore it afterwards. Intel is known to be
* guilty of this.
*
* Note that we will return to this point even if A20 gets
* screwed up by the UNDI driver, because Etherboot always
* resides in an even megabyte of RAM.
*/
gateA20_set();

if ( exit != PXENV_EXIT_SUCCESS ) {
/* Clear entry point */
memset ( &undi_loader_entry, 0, sizeof ( undi_loader_entry ) );
Expand Down
176 changes: 0 additions & 176 deletions src/arch/i386/firmware/pcbios/gateA20.c

This file was deleted.

7 changes: 0 additions & 7 deletions src/arch/i386/image/nbi.c
@@ -1,7 +1,6 @@
#include <errno.h>
#include <assert.h>
#include <realmode.h>
#include <gateA20.h>
#include <memsizes.h>
#include <basemem_packet.h>
#include <ipxe/uaccess.h>
Expand Down Expand Up @@ -306,8 +305,6 @@ static int nbi_boot16 ( struct image *image, struct imgheader *imgheader ) {
imgheader->execaddr.segoff.segment,
imgheader->execaddr.segoff.offset );

gateA20_unset();

__asm__ __volatile__ (
REAL_CODE ( "pushw %%ds\n\t" /* far pointer to bootp data */
"pushw %%bx\n\t"
Expand All @@ -327,8 +324,6 @@ static int nbi_boot16 ( struct image *image, struct imgheader *imgheader ) {
"b" ( __from_data16 ( basemem_packet ) )
: "ecx", "edx", "ebp" );

gateA20_set();

return rc;
}

Expand All @@ -345,8 +340,6 @@ static int nbi_boot32 ( struct image *image, struct imgheader *imgheader ) {
DBGC ( image, "NBI %p executing 32-bit image at %lx\n",
image, imgheader->execaddr.linear );

/* no gateA20_unset for PM call */

/* Jump to OS with flat physical addressing */
__asm__ __volatile__ (
PHYS_CODE ( "pushl %%ebx\n\t" /* bootp data */
Expand Down
7 changes: 0 additions & 7 deletions src/arch/i386/include/gateA20.h

This file was deleted.

5 changes: 0 additions & 5 deletions src/arch/i386/include/librm.h
Expand Up @@ -157,11 +157,6 @@ extern uint16_t __data16 ( rm_cs );
extern uint16_t __text16 ( rm_ds );
#define rm_ds __use_text16 ( rm_ds )

/* Functions that librm expects to be able to link to. Included here
* so that the compiler will catch prototype mismatches.
*/
extern void gateA20_set ( void );

/**
* Convert segment:offset address to user buffer
*
Expand Down
10 changes: 0 additions & 10 deletions src/arch/i386/interface/pxeparent/pxeparent.c
Expand Up @@ -147,16 +147,6 @@ int pxeparent_call ( SEGOFF16_t entry, unsigned int function,
"D" ( __from_data16 ( &pxeparent_params ) )
: "ecx", "edx", "esi", "ebp" );

/* PXE API calls may rudely change the status of A20 and not
* bother to restore it afterwards. Intel is known to be
* guilty of this.
*
* Note that we will return to this point even if A20 gets
* screwed up by the parent PXE stack, because Etherboot always
* resides in an even megabyte of RAM.
*/
gateA20_set();

/* Determine return status code based on PXENV_EXIT and
* PXENV_STATUS
*/
Expand Down
1 change: 1 addition & 0 deletions src/arch/i386/transitions/libflat.S
Expand Up @@ -348,6 +348,7 @@ enable_a20_fast:
#define ENABLE_A20_RETRIES 255
.section ".text16.early", "awx", @progbits
.code16
.globl enable_a20
enable_a20:
/* Preserve registers */
pushl %ecx
Expand Down
23 changes: 11 additions & 12 deletions src/arch/i386/transitions/librm.S
Expand Up @@ -170,18 +170,26 @@ idt_init: /* Reuse the return opcode here */
.section ".text16", "ax", @progbits
.code16
real_to_prot:
/* Enable A20 line */
call enable_a20
/* A failure at this point is fatal, and there's nothing we
* can do about it other than lock the machine to make the
* problem immediately visible.
*/
1: jc 1b

/* Make sure we have our data segment available */
movw %cs:rm_ds, %ax
movw %ax, %ds

/* Add _virt_offset, _text16 and _data16 to stack to be
* copied, and also copy the return address.
*/
pushl _virt_offset
pushl _text16
pushl _data16
addw $16, %cx /* %ecx must be less than 64kB anyway */

/* Real-mode %ss:%sp => %ebp:%edx and virtual address => %esi */
xorl %ebp, %ebp
movw %ss, %bp
Expand Down Expand Up @@ -396,9 +404,6 @@ prot_call:
.section ".text", "ax", @progbits
.code32
1:
/* Set up environment expected by C code */
call gateA20_set

/* Call function */
leal PC_OFFSET_IX86(%esp), %eax
pushl %eax
Expand Down Expand Up @@ -442,13 +447,7 @@ prot_call:
* function will be passed back to the protected-mode caller. A
* result of this is that this routine cannot be called directly from
* C code, since it clobbers registers that the C ABI expects the
* callee to preserve. Gate A20 will *not* be automatically
* re-enabled. Since we always run from an even megabyte of memory,
* we are guaranteed to return successfully to the protected-mode
* code, which should then call gateA20_set() if it suspects that gate
* A20 may have been disabled. Note that enabling gate A20 is a
* potentially slow operation that may also cause keyboard input to be
* lost; this is why it is not done automatically.
* callee to preserve.
*
* librm.h defines a convenient macro REAL_CODE() for using real_call.
* See librm.h and realmode.h for details and examples.
Expand Down

0 comments on commit 38cd203

Please sign in to comment.