Beyond BIOS: Implementing the Unified Extensible Firmware Interface with Intel's Framework

The Thunk module switches from a 32-bit protected mode environment into a 16-bit real mode environment. The ReverseThunk module switches from a 16-bit real mode environment to a 32-bit protected environment. Both Thunk and ReverseThunk ensure that the 8259 PIC is programmed properly for the concerned environment. Figure 17.3 shows how Thunk and ReverseThunk operate in 16-bit and 32-bit environments.
The EFI environment (32-bit mode) operates in polled mode instead of interrupt-driven mode and supports only the system timer interrupt. Therefore changing the environment from a 32-bit mode to a 16-bit mode involves supporting additional hardware and software interrupts required by the legacy environment (16-bit mode). The EfiCompatibility module uses Thunk during the transition from EFI to Compatibility16BIOS or to Option ROM. The Thunk module performs the following actions:
Handling any Interrupt Controller reprogramming.
Loading of proper GDT and IDT tables.
Changing to 16-bit mode.
Initializing IA32 registers with supplied input data.
Performing the required action FAR CALL or Software Interrupt.
Setting the output data with the values from IA32 registers.
Restoring the 32-bit interrupt environment.
Returning to EFI.
The 16-bit FAR routine returns to Thunk by executing (or simulating the execution of) a RETF instruction. The 16-bit software interrupt handler returns to Thunk by executing (or simulating the execution of) an IRET instruction.
The ReverseThunk module is similar to Thunk except it is invoked by the 16-bit code during the transition from a 16-bit mode to a 32-bit...