beautypg.com

10 thunking, 1 thunking ebc to native code – Intel Extensible Firmware Interface User Manual

Page 846

background image

Extensible Firmware Interface Specification

19-72

12/01/02

Version 1.10

19.12.10 Thunking

Thunking is the process by which transitions between execution of native and EBC are handled.
The major issues that must be addressed for thunking are the handling of function arguments, how
the external function is invoked, and how return values and function returns are handled. The
following sections describe the thunking process for the possible transitions.

19.12.10.1 Thunking EBC to Native Code

By definition, all external calls from within EBC are calls to native code. The EBC

CALLEX

instructions are used to make these calls. A typical application for EBC calling native code would
be a simple “Hello World” driver. For an EFI driver, the code could be written as shown below.

EFI_STATUS EfiMain (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *ST
)
{

ST->ConOut->OutputString(ST->ConOut, L”Hello World!”);

return

EFI_SUCCESS;

}

This C code, when compiled to EBC assembly, could result in two

PUSHn

instructions to push the

parameters on the stack, some code to get the absolute address of the

OutputString()

function,

then a CALLEX instruction to jump to native code. Typical pseudo assembly code for the function
call could be something like the following:

PUSHn _HelloString
PUSHn _ConOut
MOVnw R1,

_OutputString

CALLEX64 R1

The interpreter is responsible for executing the PUSHn instructions to push the arguments on the
EBC stack when interpreting the PUSHn instructions. When the CALLEX instruction is
encountered, it must thunk to external native code. The exact thunking mechanism is native
processor dependent. For example, an IA-32 thunking implementation could simply move the
system stack pointer to point to the EBC stack, then perform a

CALL

to the absolute address

specified in VM register R1. However, the function calling convention for the Itanium processor
family calls for the first 8 function arguments being passed in registers. Therefore, the Itanium
processor family thunking mechanism requires the arguments to be copied from the EBC stack into
processor registers. Then a CALL can be performed to jump to the absolute address in VM register
R1. Note that since the interpreter is not aware of the number of arguments to the function being
called, the maximum amount of data may be copied from the EBC stack into processor registers.