ChorusOS 4.0.1 Simulator for the Solaris Operating Environment (SPARC Platform Edition) User's Guide

Writing a Device Driver

The architecture of the ChorusOS 4.0.1 Simulator for the Solaris Operating Environment (SPARC Platform Edition) is similar to ChorusOS 4.0.1 running on a physical target, except that direct access to hardware is not possible. Hardware can only be accessed through UNIX APIs based on UNIX file descriptors.

A typical example of a device driver would be one to emulate serial communication by using the read() and write() UNIX functions.

The success or failure of I/O operations are not signalled by interrupts as they are on a conventional target, but by a single UNIX signal, SIGIO. Instead of attaching an interrupt, drivers attach a file descriptor to the interrupt handler.

Here is the procedure for writing a device driver using file descriptors for I/O access:

  1. Retrieve the structure containing the UNIX function addresses.

  2. Attach a file descriptor to the interrupt handler by calling the intr_attach() function.

  3. Handle the interrupts by calling the appropriate UNIX functions.

Please refer to the ChorusOS 4.0 Device Driver Framework Guide for details on writing a device driver.

The following sections follow the same format as "Writing Bus Drivers" in ChorusOS 4.0 Device Driver Framework Guide. Only the differences are described.

Include the Appropriate APIs (DKI/DDI)

In addition to including the header files for the DKI and DDI APIs involved in your device driver's implementation, you must also include the appropriate header file to access UNIX function calls. See "Retrieving UNIX Function Addresses" for more details.

Register the Driver (using the main() function)

The simulator BSP is fully compliant with the standard BSP.

Write the Device Driver Class-Specific Functions

The simulator BSP is fully compliant with the standard BSP.

Write the Device Driver Registry Functions

There are two differences that you need to be aware of when writing registry functions for your device driver.

Write the Bus Event Handler Function

The simulator BSP is fully compliant with the standard BSP. However, the shutdown related events, specified by the common bus API, are not implemented: