From owner-freebsd-hackers Sat Feb 1 15:37:08 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id PAA14409 for hackers-outgoing; Sat, 1 Feb 1997 15:37:08 -0800 (PST) Received: from spoon.beta.com (root@[199.165.180.33]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id PAA14404 for ; Sat, 1 Feb 1997 15:37:04 -0800 (PST) Received: from spoon.beta.com (mcgovern@localhost [127.0.0.1]) by spoon.beta.com (8.8.4/8.6.9) with ESMTP id SAA12533 for ; Sat, 1 Feb 1997 18:36:59 -0500 (EST) Message-Id: <199702012336.SAA12533@spoon.beta.com> To: hackers@freebsd.org Subject: Device driver help needed... Date: Sat, 01 Feb 1997 18:36:59 -0500 From: "Brian J. McGovern" Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Ok. I'm sure that now I've terribly bastardized the uio structure, but at least the damn thing compiles :) Let see if I can get some comment on my interpretation of the uio stucture: struct uio { struct iovec *uio_iov; /* Pointer to IO Vector (possible array?) */ int uio_iovcnt; /* Number of IO vectors (?) */ off_t uio_offset; /* Offset in to device */ int uio_resid; /* Length of read request (?) */ enum uio_seg uio_segflg; /* I assume a segment of some kind, but I can only find reference to UIO_SYSSPACE */ enum uio_rw uio_rw; /* UIO_READ or UIO_WRITE (type of operation(?)) */ struct proc *uio_procp; /* No idea, but I've seen it set to curproc */ }; Ok, guys. Beat me up, and let me know whats incorrect. With that in mind, I've bent my device driver to look like this: ------ foo.c --------------------------------------- #define KERNEL #include #include #include #include #include #include #include #include #include #include #include #include #ifdef DEVFS #include #endif #include #include #include 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 }; fooinit() { } 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; } } #define CDEV_MAJOR 20 ------------------------------------------------- Now, I'm sure there are bugs in there. Hell, I didn't know what I was doing half the time :) But, now its time to start debugging, which means I need to get it in to the kernel. Someone mentioned using SYSINIT to get it working as a pseudo-device driver. The file above is located in /usr/src/sys/i386/addons/foo.c. Anyone care to give me a set of steps (and code changes) to get it in the kernel? Thanks. -Brian