Writing Device Drivers

ProcedureHow to Build and Load the Layered Driver

  1. Compile the driver.

    Use the -D_KERNEL option to indicate that this is a kernel module.

    • If you are compiling for a SPARC architecture, use the -xarch=v9 option:


      % cc -c -D_KERNEL -xarch=v9 lyr.c
      
    • If you are compiling for a 32-bit x86 architecture, use the following command:


      % cc -c -D_KERNEL lyr.c
      
  2. Link the driver.


    % ld -r -o lyr lyr.o
    
  3. Install the configuration file.

    As user root, copy the configuration file to the kernel driver area of the machine:


    # cp lyr.conf /usr/kernel/drv
    
  4. Install the driver binary.

    • As user root, copy the driver binary to the sparcv9 driver area on a SPARC architecture:


      # cp lyr /usr/kernel/drv/sparcv9
      
    • As user root, copy the driver binary to the drv driver area on a 32-bit x86 architecture:


      # cp lyr /usr/kernel/drv
      
  5. Load the driver.

    As user root, use the add_drv(1M) command to load the driver.


    # add_drv lyr
    

    List the pseudo devices to confirm that the lyr device now exists:


    # ls /devices/pseudo | grep lyr
    lyr@1
    lyr@1:node