28.2 Alignment Faults

The single most common issue with UEFI drivers for IPF platforms is alignment. Alignment faults cannot occur on IA32, X64, or EBC platforms, but can occur on IPF platforms. The IPF platform requires that all transactions be performed only on natural boundaries. This requirement means that a 64-bit read or write transaction must begin on an 8-byte boundary, a 32-bit read or write transaction must begin on a 4-byte boundary, and a 16-bit read or write transaction must begin on a 2-byte boundary.

In most cases, the driver writer does not need to worry about this issue because the C compiler guarantees that accessing global variables, function parameters, local variables, and fields of data structures do not cause alignment faults.

Alignment faults can be generated when:

  • C code can generate an alignment fault when a pointer is cast from one type to another or when packed data structures are used.

  • Data structures are declared to be byte packed using #pragma pack(1) or equivalent.

  • Assembly language can generate an alignment fault, but it is the assembly programmer's responsibility to ensure alignment faults are not generated. This topic is not covered further in this guide.