Subject: Re: FreeBSD 5/6/7 kernel emulator for NetBSD 2.x
To: None <hselasky@c2i.net>
From: Lennart Augustsson <lennart@augustsson.net>
List: tech-kern
Date: 10/26/2005 02:09:07
You'll never get a driver that looks exactly right for one
OS to work with another, even with an emulation layer.
For instance, FreeBSD doesn't have an activate method for
device drivers whereas NetBSD and OpenBSD do.
And there are examples of the reverse.  So shared drivers
will have some clutter.

Personally, I prefer the macros.

	-- Lennart

Hans Petter Selasky wrote:
> Hi,
> 
> I have made an effort on making a FreeBSD 5/6/7 kernel emulator for NetBSD 
> 2.x. Many device drivers are shared between these two operating systems, and 
> I think a lot of work can be saved when it comes to porting code and patches 
> forth and back. Currently this emulator makes my FreeBSD PCI ISDN driver load 
> and run on NetBSD. I have chosen to make FreeBSD 5+ the standard for several 
> reasons:
> 
> - all drivers are dynamically linked through use of the "section attribute" in 
> the "C" compiler.
> 
> - "/dev" is a file system that can be manipulated from the kernel, without 
> intervention from "mknod".
> 
> - All I/O resources are allocated through a single function, 
> "bus_alloc_resource()".
> 
> - And more.
> 
> 
> Here is a case in which such a kernel emulator can be used:
> 
> I think it is a good idea that FreeBSD and NetBSD shares as many USB drivers 
> as possible. But sharing USB device drivers like 
> "/usr/src/sys/dev/usb/ulpt.c", is difficult, because two quite different 
> interfaces are used to create devices in "/dev/". And it is not only this, 
> but also how USB device drivers register in the kernel so that they get 
> probed. Here one has tried to hide system differences by using macros. 
> 
> I think one should rather have some external library that hides these system 
> differences, so that there is only one branch for the USB device drivers, for 
> both NetBSD and FreeBSD, and probably the other *BSD's aswell, if possible. 
> That means a branch without "ifdefs" for every operating system it is 
> supposed to compile on. Then one has got to choose the library interface, and 
> I would say that "FreeBSD 5+ specific" is the best candidate so far. 
> 
> I see that one can move many USB drivers over to FreeBSD, merge everything 
> together, expand all the macros in "/usr/src/sys/dev/usb/usb_port.h", and 
> then copy it back to NetBSD which then must have a FreeBSD kernel emulator in 
> the kernel. When the drivers are updated later, it will be very easy to cross 
> port the changes, and at the same time the USB system is brought out of the 
> Giant lock. Also it will be easier to create portable USB kernel device 
> drivers.
> 
> 
> Anyone have any opinion about what system is better to use as a standard in 
> the kernel?
> 
> 
> 
> Main features:
> 
> - Implements FreeBSD's devfs on NetBSD.
> 
> - Support for mutexes, mtx_xxxx() and msleep()
> 
> - Support for probe/attach and general use of PCI devices
> 
> - Support for SYSINIT()
> 
> - Support for DRIVER_MODULE()
> 
> - And some other things found in FreeBSD 5/6/7
> 
> 
> Here is a tarball (only tested on i386 and compatible, NetBSD 2.x):
> 
> http://home.c2i.net/hselasky/isdn4bsd/privat/temporary/new_ihfc_1_5_5_NetBSD.tar.bz2
> 
> 
> --HPS
>