Writing Device Drivers

Kernel Programming Model

The Solaris kernel is a large collection of code that is compiled in one of two ways; it is either compiled as a 32-bit program that supports solely 32-bit applications, or as a 64-bit program that supports both 32-bit and 64-bit applications. To allow drivers and STREAMS modules to be used on both systems, you must write kernel code that is both portable between these two compilation environments and supportive of 32-bit and 64-bit applications. The resulting code must be compiled in two ways, creating two separate modules: a 32-bit module for the 32-bit kernel, and a 64-bit module for the 64-bit kernel.

Some classes of portability issues can best be solved using the standard derived types, such as size_t, off_t, time_t, and caddr_t, since these grow and shrink appropriately. To provide better support of 32-bit applications in the 64-bit kernel, fixed-width types corresponding to the sizes expected by 32-bit applications are available in <sys/types32.h>, for example, size32_t, off32_t, time32_t, and caddr32_t.

Other classes of portability problems, in particular those describing hardware registers or data sent over the wire, are best described using the size-invariant types in <sys/inttypes.h>; for example, uint16_t, and int64_t. It also includes the definition of intptr_t and uintptr_t.

See the Solaris 64-bit Developer's Guide for the full list of changes to derived types and more information on fixed-width types.