[ipxe-devel] ipxe/seabios: segment register initialization

Michael S. Tsirkin mst at redhat.com
Sun Feb 14 15:26:32 GMT 2016


On Sun, Feb 14, 2016 at 12:41:31PM +0000, Michael Brown wrote:
> On 14/02/16 10:52, Victor Kaplansky wrote:
> >I've created a boot-sector which works just fine when loaded
> >directly from BIOS, but doesn't work when loaded by ipxe:
> >
> >        0:       b8 ad de                mov    ax,0xdead
> >        3:       a3 10 7c                mov    ds:0x7c10,ax
> >
> >0xdead is not written to 0000:7c10.
> >The reason is that BIOS have data segment register initialized to
> >zero, while ipxe leaves it dirty before the jump to boot sector
> >code.
> >
> >After adding to boot sector some code to initialize DS register,
> >my code works well:
> >
> >        0:       b8 00 00                mov    ax,0x0
> >        3:       8e d8                   mov    ds,ax
> >        5:       b8 ad de                mov    ax,0xdead
> >        8:       a3 10 7c                mov    ds:0x7c10,ax
> >
> >Is such behaviour intentional, or it is a bug?
> >Who is responsible for segment registers initialization?
> 
> I'm not aware of any standard describing the content of %ds when jumping to
> a boot sector at 0000:7c00.  Every boot sector that I have encountered
> explicitly initialises %ds (and %es, and %ss:%sp) to known values.

Sounds reasonable wrt %ds, but  I think %ss:%sp at least is initialized by PXE, isn't it?

PXE spec says (4.4.5 Client State at Bootstrap Execution Time (Remote.0)):

On entry to the NBP:
! CS:IP must contain the value 0:7C00h.
! ES:BX must contain the address of the PXENV+ structure.
! SS:[SP+4] must contain the segment:offset address of the !PXE structure.
! EDX is no longer used.
! SS:SP is to contain the address of the beginning of the unused portion of the PXE services stack.
! There must be at least 1.5KB of free stack space for the NBP.

> 
> Your boot sector should probably do likewise.
> 
> Michael


More information about the ipxe-devel mailing list