Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 01 Feb 1997 22:27:51 -0500
From:      "Brian J. McGovern" <mcgovern@spoon.beta.com>
To:        hackers@freebsd.org
Subject:   Device Driver: Almost home(?)
Message-ID:  <199702020327.WAA00333@spoon.beta.com>

next in thread | raw e-mail | index | archive | help

Ok. I've collated a half dozen responses, and merged them in to what I hope
is less of a Frankenstein. At this point, I've modified files.i386, and moved
foo.c in to /usr/src/sys/dev/foo/foo.c. I've added a "pseudo-device foo 1"
line to the config file, and see foo.h being generated with an NFOO #define'ed
to 1. I see the make depend and the make compile the chunk, so I'm fairly sure
its making it in there. However, I don't think fooinit() is being run
properly, and I'm not sure of the call I make to register the device. As 
before, if someone can sanity check me, and let me take it a step or two
further, I'd appreciate it. I think that once I can get it to where I can
tinker and debug, I should be set. 

Also, I'm getting a warning about the SYSINIT macro, stating
"warning: initialization from incompatible pointer type". If someone could
give me a lead on that as well, I'd appreciate it.

Anyhow, here is the contents of foo.c:



#include <sys/param.h>
#include <sys/systm.h>
#include <sys/reboot.h>
#include <sys/ioctl.h>
#include <sys/tty.h>
#include <sys/proc.h>
#include <sys/conf.h>
#include <sys/file.h>
#include <sys/uio.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/syslog.h>
#ifdef DEVFS
#include <sys/devfsext.h>
#endif
#include <machine/clock.h>
#include <i386/isa/isa.h>
#include <i386/isa/isa_device.h>

static char message[] = "The quick brown fox jumps over a lazy dog\n";

#define CDEV_MAJOR 20

static d_read_t fooread;

static struct cdevsw foo_cdevsw =
  {
    nxopen, nxclose, fooread, nxwrite,
    nxioctl, nxstop, nxreset, nxdevtotty,
    nxselect, nxmmap, NULL, "foo", NULL, -1
  };
    
static void fooinit(void)
  {
    dev_t dev;
    printf("Test character driver\n");
    cdevsw_add(&dev,&foo_cdevsw,NULL);
  }

static int fooread(dev,myuio, flag)
  dev_t dev;
  struct uio *myuio;
  int flag;
  {
    unsigned char *buffer_pointer;
    int toread;
    if ((myuio->uio_iovcnt != 1) || (minor(dev) != 0))
      return ENODEV;
    while(myuio->uio_resid)
      {
        buffer_pointer = (message + (myuio->uio_offset % sizeof(message)));
        toread = ((long unsigned int)(message + sizeof(message)) - (long unsigned int)buffer_pointer);
        uiomove(buffer_pointer, toread, myuio);
	myuio->uio_offset + toread;
	myuio->uio_resid = myuio->uio_resid - toread;
      }
    return 0;
  }

SYSINIT(foodev, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+CDEV_MAJOR, fooinit, NULL);



As always, thanks in advance.
	-Brian




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702020327.WAA00333>