4.2 Protected Mode Considerations

VBE services may be called directly from 32-bit  protected  mode
only. For 32-bit protected mode, 2 selector/segment  descriptors
for 32-bit code and the data segment are needed. These  will  be
allocated and initialized  by  the  caller.  The  segment  limit
fields will be set to 64k. These selectors may either be in  the
GDT or LDT, but must be valid whenever  the  VBE  is  called  in
protected mode. The caller must supply a stack large enough  for
use by VBE and by potential  interrupt  handlers.  The  caller's
stack will be active if or when interrupts are  enabled  in  the
VBE  routine,  since  the  VBE  will  not  switch  stacks   when
interrupts are enabled, including NMI interrupts. The 32-bit VBE
interface requires a 32-bit stack.
If the memory location is zero, then only I/O mapped ports  will
be used so the application does not need to do anything special.
This should be the default case for  ALL  cards  that  have  I/O
mapped registers because it provides the best performance.
If the memory location is nonzero (there can be only  one),  the
application will need to create a new 32- bit selector with  the
base address that points to the  "physical"  location  specified
with the specified limit.
When the application  needs  to  call  the  32-bit  bank  switch
function, it must then load the ES selector with  the  value  of
the new selector that has been created. The bank switching  code
can then directly access its memory mapped registers as absolute
offsets into the ES selector (i.e., mov  [es:10],eax  to  put  a
value into the register at base+10).
It is up to  the  application  code  to  save  and  restore  the
previous state of the ES selector  if  this  is  necessary  (for
example in flat model code).
When the VBE services are called, the current I/O permission bit
map must allow access to the I/O ports that the VBE may need  to
access. This can be found in the Sub-Table  (Ports  and  Memory)
returned by VBE Function 0Ah.
To summarize, it is the responsibility of the calling to  ensure
to that it has the appropriate I/O and memory privileges, and  a
large enough stack and appropriate selectors  allocated.  It  is
also the responsibility of the calling application  to  preserve
registers if necessary.
Applications must use the same registers for  the  Function  05h
and Function 09h protected mode interface that they would use in
a real mode call. This includes the AX register.

Function 07h protected mode calls have a different format.
AX = 4F07h
BL = 00hSet Display CRTC Start
   = 80hSet Display CRTC Start during Vertical Retrace
CX = Bits 0-15 of display start address
DX = Bits 16-31 of display start address

The protected mode application must  keep  track  of  the  color
depth and scan line length to calculate the new  start  address.
If a value that is out of  range  is  programmed,  unpredictable
results will occur.


4.13 Function 0Ah - Return VBE Protected Mode Interface

This required function call returns a pointer to  a  table  that
contains code for a 32-bit protected  mode  interface  that  can
either be copied into  local  32-bit  memory  space  or  can  be
executed from ROM providing the  calling  application  sets  all
required selectors  and  I/O  access  correctly.  This  function
returns a pointer (in real mode space) with offsets to the  code
fragments, and additionally returns an offset to a  table  which
contains Non-VGA Port and Memory locations which an  Application
may have to have I/O access to.

Input:
AX = 4F0Ah VBE 2.0 Protected Mode Interface
BL = 00h Return protected mode table
Output:
AX = Status
ES = Real Mode Segment of Table
DI = Offset of Table
CX = Length of Table including protected mode code in bytes (for
     copying purposes)

The format of the table is as follows:
ES:DI + 00h Word Offset in table of Protected mode code for
                        Function 5 for Set Window Call
ES:DI + 02h Word Offset in table of Protected mode code for
                        Function 7 for set Display Start
ES:DI + 04h Word Offset in table of Protected mode code for
                        Function 9 for set Primary Palette data
ES:DI + 06h Word Offset in table of Ports and Memory Locations
                        that the application may need I/O 
                        privilege for. (Optional: if 
                        unsupported this must be 0000h)
                        (See Sub-table for format)
ES:DI + ? Variable remainder of Table including Code

The format of the Sub-Table (Ports and Memory locations)
Port, Port, ... , Port,  Terminate Port List with FF FF,  Memory
locations  (4 bytes),  Length  (2 bytes),  Terminate Memory List
with FF FF.

Example 1. For Port/Index combination 3DE/Fh and Memory 
locations DE800-DEA00h (length = 200h) 
the table would look like this:
DE 03 DF 03 FF FF 00 E8 0D 00 00 02 FF FF

Example 2. For only the ports it would look like:
DE 03 DF 03 FF FF FF FF

Example 3. For only the memory locations it would look like
FF FF 00 E8 0D 00 00 02 FF FF

Note: All protected mode functions should end with  a  near  RET
(as opposed to FAR RET) to allow  the  application  software  to
CALL the code from within the ROM.

Note: The Port and Memory location Sub-table  does  not  include
the Frame  Buffer  Memory  location.  The  Frame  Buffer  Memory
location is contained within the ModeInfoBlock returned  by  VBE
Function 01h.

Note: The protected mode code is assembled  for  a  32-bit  code
segment, when copying it, the application must copy the code  to
a 32-bit code segment.

Note: It is the responsibility of the application to ensure that
the selectors and segments are set up correctly.

If the memory location is zero, then only I/O mapped ports  will
be used so the application does not need to do anything special.
This should be the default case for  ALL  cards  that  have  I/O
mapped registers because it provides the best performance.
If the memory location is nonzero (there can be only  one),  the
application will need to create a new 32- bit selector with  the
base address that points to the  "physical"  location  specified
with the specified limit.
When the application  needs  to  call  the  32-bit  bank  switch
function, it must then load the ES selector with  the  value  of
the new selector that has been created. The bank switching  code
can then directly access its memory mapped registers as absolute
offsets into the ES selector (i.e., mov  [es:10],eax  to  put  a
value into the register at base+10).
It is up to  the  application  code  to  save  and  restore  the
previous state of the ES selector  if  this  is  necessary  (for
example in flat model code).

Note: Currently undefined registers may be  destroyed  with  the
exception of ESI, EBP, DS and SS.

Note: Applications must use the same registers for the  Function
05h and Function 09h protected mode interface that it would  use
in a real mode call. This includes the AX register.

Note: Function 07h protected mode calls have a different format.
AX = 4F07h
BL = 00hSet Display CRTC Start
   = 80hSet Display CRTC Start during Vertical Retrace
CX = Bits 0-15 of display start address
DX = Bits 16-31 of display start address

The protected mode application must  keep  track  of  the  color
depth and scan line length to calculate the new  start  address.
If a value that is out of  range  is  programmed,  unpredictable
results will occur.

Note: Refer to Section 4.2 for  information  on  protected  mode
considerations.


4.8 Function 05h - Display Window Control

This  required  function  sets  or  gets  the  position  of  the
specified display window or page in the frame buffer  memory  by
adjusting the necessary hardware paging registers. To  use  this
function properly, the software should first  use  VBE  Function
01h  (Return  VBE  Mode  information)  to  determine  the  size,
location and granularity of the windows.
For performance reasons, it may be more efficient to  call  this
function directly, without incurring the INT 10h  overhead.  VBE
Function  01h  returns  the  segment:offset  of  this  windowing
function that may be called directly for this reason.
Note that a different entry point may be returned based upon the
selected mode. Therefore,  it  is  necessary  to  retrieve  this
segment:offset specifically for each desired mode.

Input:
AX = 4F05h VBE Display Window Control
BH = 00h Set memory window
   = 01h Get memory window
BL = Window number
   = 00h Window A
   = 01h Window B
DX = Window number in video memory in window
     granularity units (Set Memory Window only)
Output:
AX = VBE Return Status
DX = Window number in window granularity units
     (Get Memory Window only)

Note: In VBE 1.2 implementations, the direct  far  call  version
returns no Return Status information to the  application.  Also,
in the far call  version,  the  AX  and  DX  registers  will  be
destroyed. Therefore if AX and/or  DX  must  be  preserved,  the
application must do  so  prior  to  making  the  far  call.  The
application must still load the input arguments in BH,  BL,  and
DX (for Set Window).
In VBE 2.0 implementations, the BIOS  will  return  the  correct
Return Status, and therefore the application must assume that AX
and DX will be destroyed.

Application Developer's Note: This function is not intended  for
use  in  a  linear  frame  buffer  mode,  if  this  function  is
requested, the function call will fail with the  VBE  Completion
code AH=03h.

VBE BIOS Implementation Note: If this function is  called  while
in a linear frame buffer memory model, this function  must  fail
with completion code AH=03h.


4.1 VBE Return Status

The AX register is used to indicate the completion  status  upon
return from VBE functions. If  VBE  support  for  the  specified
function is available, the 4Fh value passed in the  AH  register
on entry is returned in the AL register.  If  the  VBE  function
completed successfully, 00h is  returned  in  the  AH  register.
Otherwise the AH register is set to indicate the nature  of  the
failure.

VBE RETURN STATUS
AL == 4Fh:Function is supported
AL != 4Fh:Function is not supported
AH == 00h:Function call successful
AH == 01h:Function call failed
AH == 02h:Function is not supported in the current hardware
          configuration
AH == 03h:Function call invalid in current video mode

Note: Applications should treat any non-zero  value  in  the  AH
register as a general failure condition as later versions of the
VBE may define additional error codes.
