From owner-freebsd-questions@FreeBSD.ORG Tue Dec 2 17:16:16 2003 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 73D3D16A4CE for ; Tue, 2 Dec 2003 17:16:16 -0800 (PST) Received: from fw.farid-hajji.net (fw.farid-hajji.net [213.146.115.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3474C43F85 for ; Tue, 2 Dec 2003 17:16:12 -0800 (PST) (envelope-from cpghost@cordula.ws) Received: from fw.farid-hajji.net (localhost [127.0.0.1]) by fw.farid-hajji.net (8.12.10/8.12.10) with ESMTP id hB31FRaQ027935; Wed, 3 Dec 2003 02:15:28 +0100 (CET) (envelope-from cpghost@cordula.ws) Date: Wed, 3 Dec 2003 02:15:27 +0100 (CET) Message-Id: <200312030115.hB31FRaQ027935@fw.farid-hajji.net> From: "Cordula's Web" To: kitsune@gmx.co.uk In-reply-to: <20031202150109.52c9e309.kitsune@gmx.co.uk> (message from kitsune on Tue, 2 Dec 2003 15:01:09 -0600) X-Mailer: Emacs-21.3.1/FreeBSD-4.9-STABLE References: <000801c3b835$8a5f3a60$1c77fea9@dpc27> <20031202150109.52c9e309.kitsune@gmx.co.uk> cc: admin@sycos.co.uk cc: peter@sycos.co.uk cc: freebsd-questions@FreeBSD.ORG cc: cargnini@matrix.com.br Subject: Re: FreeBSD DRIVER DEVELOPMENT X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: cpghost@cordula.ws List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Dec 2003 01:16:16 -0000 > > Dear Sir/Madam, > > > > I have requirement to develop driver for the PCI based hardware interface > > using FreeBSD Unix system. Would you please advise on the following:- > > > > 1) What tools are available to develop driver for x86 machine using C? Most drivers in FreeBSD are written in C. They are compiled by gcc (2.95.4 in -STABLE, 3.x in -CURRENT), just like any other part of the system sources (see: /usr/src). > > 2) Suitable package including the operating system, tools and books etc? > > Checking out the documentation on freebsd.org would probally be a good start. Checking out some sample driver sources would be even better :) For -STABLE (RELENG_4), [PCI-]drivers are located in the kernel source tree, here: /usr/src/sys/pci (PCI drivers) /usr/src/sys/dev (mixed ISA and PCI drivers) Reading the man page pci(4) [man 4 pci] won't hurt either. As with every device driver, the recommended (or at least proved) way is to take an existing, simple driver, and modify it to suit your needs. Kernel interfaces are documented in intro(9) and related section 9 man pages (ls /usr/share/man/man9) A good introduction on writing device drivers for FreeBSD is in the Documentation. Among others: * Developers' Handbook: http://www.freebsd.org/doc/en_US.ISO8859-1/books/developers-handbook/index.html * FreeBSD Architecture Handbook (esp. Section II: Device Drivers): http://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/index.html (You may want to play with a KLD module, which exercises the PCI API: http://www.freebsd.org/doc/en_US.ISO8859-1/books/arch-handbook/pci.html) * PCI Special Interest Group (specs etc... for PCI bus) http://www.pcisig.com/ esp. this: http://www.pcisig.com/specifications/conventional > > 3) Can the driver developed for other unix operating system e.g. VxWorks > > can be imported into the FreeBSD and compiled without major code change? > > AFAIK this is something that is not really possible on any operating system. > This is becuase changes to what header files and need to be made and ect. As to > the extent of what changes are required, I guess that varies from what it is and > whatever... but I never messed with this befor so I have no clue... A device driver is always part of the kernel program. It runs in the same address space as the kernel, and must interact with both the kernel and the hardware in a very specific manner. A driver will e.g. need to call some kernel functions to report data, or send notifications. Or it may register a timer, etc... These kernel functions (in FreeBSD, look at directory /usr/share/man/man9) differ from OS to OS. FreeBSD's functions are completely different to, say, Linux' functions or Win32s/Windows API calls. That's a reason why writing device drivers is completely dependant upon a specific kernel. Ah, and don't forget to use a development machine. Coding mistakes in device drivers WILL almost always panic(9) the kernel, and under unlucky circumstances trash the filesystem with it! [Same under Linux or any other OS] Good luck and happy hacking! -- Cordula's Web. http://www.cordula.ws/