From owner-freebsd-hackers Sat Feb 1 19:28:00 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id TAA27052 for hackers-outgoing; Sat, 1 Feb 1997 19:28:00 -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 TAA27038 for ; Sat, 1 Feb 1997 19:27:55 -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 WAA00333 for ; Sat, 1 Feb 1997 22:27:52 -0500 (EST) Message-Id: <199702020327.WAA00333@spoon.beta.com> To: hackers@freebsd.org Subject: Device Driver: Almost home(?) Date: Sat, 01 Feb 1997 22:27:51 -0500 From: "Brian J. McGovern" Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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 #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 }; 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