Device Driver Adaptation?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
leejbaxter
Member
Member
Posts: 25
Joined: Sat Jan 15, 2011 8:40 pm

Device Driver Adaptation?

Post by leejbaxter »

Hi folks,

Firstly, please forgive me for any misunderstandings; I'm really new to the world of OS development, so it may seem like I'm asking obvious questions for the time being, but I can accept constructive criticism! :mrgreen:

I'm currently dabbling with the idea of creating an OS from scratch, which will be 99.999999% automated (save diagnostic functions .etc.); here's where I've met a potential speed-bump! Obviously, when I create my OS, it won't have any device-specific drivers; this is going to be a big setback if I want my system to be fully-automated because I'll need to develop drivers for numerous devices, not to mention that this OS is planned to be run on almost any x86-based computer.

This is where I've had a lightning bolt! Windows and Linux automatically install drivers for common hardware, and there's masses of device drivers for these OSes. My question is, is it possible to develop a sort of 'adaptor' for Windows/Linux device drivers so that I can use them with my own OS? As far as I can see, it is theoretically possible (not that it would be a trivial task, by any means); what I'd be essentially doing is converting the interface for the drivers to suit my OS.

Could anybody give me advice on this, and if it isn't going to work, please could alternatives be suggested?

Thanks in advance, Lee.
Lee.J.Baxter - Designer of CHAOS (Cybernetic Hivemind Adaptive Operating System)
Xzyx987X
Posts: 21
Joined: Mon Apr 27, 2009 7:29 am

Re: Device Driver Adaptation?

Post by Xzyx987X »

Possible? Perhaps. ReactOS for instance, supports Windows drivers. Of course, it's basically a ground up reimplementation of Windows, and even then it's compatibility isn't perfect. Some hacky device drivers for instance, may use undocumented features, or even depend on specific memory structures being in a certain place in memory to work.

I think what you'll find though, is that most devices that are the highest priority for supporting, are based on open standards. And writing new drivers based on those standards, is in 99.999999% of cases the most practical approach. 3D graphics acceleration drivers are a bit problematic, mainly due to complete lack of standards or documentation, but people are working on it.

I'd like to know however, what exactly are you trying to do with this OS that couldn't be readily accomplished by hacking up an existing open source OS to suit your needs?
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Device Driver Adaptation?

Post by Kevin »

It's possible to do this in theory, although it will probably require quite some work. You basically implement the driver API of the source OS. Examples that I know where such an approach was taken in practice are NDISwrapper (running Windows network/WLAN drivers on Linux) and WinKVM (a port of KVM virtualization code to Windows by emulating the Linux kernel API; this one is scary, but they say it works - even thoug slower than just emulating with qemu...)

If you decide that it's not the way to go, there are still CDI and UDI which try to provide a driver interface that allows driver to be shared between OSes. Both of them don't have as many drivers as Linux or Windows, so you'll still need to write some drivers, but you would get at least some drivers for free (for CDI; I'm not sure about the UDI status) and I think both projects would gladly accept contributions of new drivers. ;)
Developer of tyndur - community OS of Lowlevel (German)
leejbaxter
Member
Member
Posts: 25
Joined: Sat Jan 15, 2011 8:40 pm

Re: Device Driver Adaptation?

Post by leejbaxter »

Xzyx987X wrote:Possible? Perhaps. ReactOS for instance, supports Windows drivers. Of course, it's basically a ground up reimplementation of Windows, and even then it's compatibility isn't perfect. Some hacky device drivers for instance, may use undocumented features, or even depend on specific memory structures being in a certain place in memory to work.

I think what you'll find though, is that most devices that are the highest priority for supporting, are based on open standards. And writing new drivers based on those standards, is in 99.999999% of cases the most practical approach. 3D graphics acceleration drivers are a bit problematic, mainly due to complete lack of standards or documentation, but people are working on it.

I'd like to know however, what exactly are you trying to do with this OS that couldn't be readily accomplished by hacking up an existing open source OS to suit your needs?
Thanks for the quick reply!

What I'm attempting to do is to build an OS that runs fully automated (apart from the aforementioned diagnostics tools) so that it can intelligently control an x86-based computer system. The reason that I want to develop this as an OS from scratch is for the learning experience, so that I know every single aspect of the system's design (minus the adapted drivers, of course!), and so that only necessary subsystems/daemons are running. I'm expecting the project to take years to build, but I think that implementing it myself could save some headaches in the long run.
Lee.J.Baxter - Designer of CHAOS (Cybernetic Hivemind Adaptive Operating System)
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: Device Driver Adaptation?

Post by gravaera »

Yo
leejbaxter wrote:...

Windows and Linux automatically install drivers for common hardware, and there's masses of device drivers for these OSes. My question is, is it possible to develop a sort of 'adaptor' for Windows/Linux device drivers so that I can use them with my own OS? As far as I can see, it is theoretically possible (not that it would be a trivial task, by any means);
Yes, this is completely possible, but it would still take a bit of work (a hefty amount); but the gains forecasted to come from doing it are several orders of magnitude above the pain for the labour :)

Basically, you need to find out two main things, and then several other sub-questions will stem from there: how do windows drivers du jour provide the NT kernel with a struct of entry points into themselves? In other words, where is the driver "information block" and how is is found within an NT driver, and how is it to be parsed?

Second, does NT use the stdcall convention for its drivers? This would require some stack transformation on calling in and returning. From there, you have the MSDN knowledgebase and their extensive articles which detail how to develop drivers for NT. You could choose to adopt some already-designed driver interface like the UDI, or the CDI, or design your own. In each case the process is the same: you write a wrapping layer with the same reasoning as the "NDIS Wrapper" project which allows users to use NT NIC drivers under Linux due to the fact that MS adopted NDIS, and NDIS is an open standard, so I imagine it wasn't that much work to reverse engineer with basic information from MSDN.

--Have fun,
gravaera
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Device Driver Adaptation?

Post by Brendan »

Hi,
leejbaxter wrote:My question is, is it possible to develop a sort of 'adaptor' for Windows/Linux device drivers so that I can use them with my own OS? As far as I can see, it is theoretically possible (not that it would be a trivial task, by any means); what I'd be essentially doing is converting the interface for the drivers to suit my OS.
Essentially, what you'd be doing is modifying your OS to suit the interfaces needed for the device drivers.

For example, for Windows drivers you'd be supporting the PE file format, supporting DLLs, implementing any DLLs that drivers rely on, implementing a registry, implementing the "event log", implementing messaging, implementing the re-entrancy model (locks, etc) and emulating Windows virtual memory model. On top of that you'd be implementing most of the Windows API used by applications so that the device driver installers and utilities that come with the device drivers actually work (for a simple example, go to "control panel" and change your printer's configuration).

For example, for Linux drivers you'd be supporting the ELF file format, implementing the "/proc" filesystem and the "/dev" file system (and "udev"?) and the "/etc" directory for configuration files, implementing the "system log" stuff, implementing pipes, implementing the re-entrancy model (locks, etc) and emulating Linux virtual memory model. Then you'd be trying to find a way to install the device drivers (and maybe adopting GPL2) and fixing it each time the Linux kernel developers change anything.

My guess is that before you've got 10% of it done you'll go insane, and the police will find you unconscious and naked in a large shopping mall surrounded by spoiled pastries - maybe donuts, maybe some sort of bun containing sultanas or raisins, or maybe something French like croissants. Regardless of what sort of pastries it is, the nearest bakery will go bankrupt 6 months later because none of their customers will be able to go near their shop without being reminded of the great pastry massacre of 2011. You will be content (the medication the nurses make you take will make sure of that), until you convince the nice doctors to release you. Unfortunately you'll be hit by a truck on a busy highway soon after that (but don't blame the truck driver - there's no way he could've seen an old man kissing the white line in the middle of the road in time to avoid impact).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
leejbaxter
Member
Member
Posts: 25
Joined: Sat Jan 15, 2011 8:40 pm

Re: Device Driver Adaptation?

Post by leejbaxter »

Brendan wrote:Hi,
leejbaxter wrote:My question is, is it possible to develop a sort of 'adaptor' for Windows/Linux device drivers so that I can use them with my own OS? As far as I can see, it is theoretically possible (not that it would be a trivial task, by any means); what I'd be essentially doing is converting the interface for the drivers to suit my OS.
Essentially, what you'd be doing is modifying your OS to suit the interfaces needed for the device drivers.

For example, for Windows drivers you'd be supporting the PE file format, supporting DLLs, implementing any DLLs that drivers rely on, implementing a registry, implementing the "event log", implementing messaging, implementing the re-entrancy model (locks, etc) and emulating Windows virtual memory model. On top of that you'd be implementing most of the Windows API used by applications so that the device driver installers and utilities that come with the device drivers actually work (for a simple example, go to "control panel" and change your printer's configuration).

For example, for Linux drivers you'd be supporting the ELF file format, implementing the "/proc" filesystem and the "/dev" file system (and "udev"?) and the "/etc" directory for configuration files, implementing the "system log" stuff, implementing pipes, implementing the re-entrancy model (locks, etc) and emulating Linux virtual memory model. Then you'd be trying to find a way to install the device drivers (and maybe adopting GPL2) and fixing it each time the Linux kernel developers change anything.

My guess is that before you've got 10% of it done you'll go insane, and the police will find you unconscious and naked in a large shopping mall surrounded by spoiled pastries - maybe donuts, maybe some sort of bun containing sultanas or raisins, or maybe something French like croissants. Regardless of what sort of pastries it is, the nearest bakery will go bankrupt 6 months later because none of their customers will be able to go near their shop without being reminded of the great pastry massacre of 2011. You will be content (the medication the nurses make you take will make sure of that), until you convince the nice doctors to release you. Unfortunately you'll be hit by a truck on a busy highway soon after that (but don't blame the truck driver - there's no way he could've seen an old man kissing the white line in the middle of the road in time to avoid impact).


Cheers,

Brendan
Okay...that sounds like a realistic scenario, apart from the "buns containing sultanas and raisins" part; I'm not too keen on fruit in buns! :mrgreen:
Lee.J.Baxter - Designer of CHAOS (Cybernetic Hivemind Adaptive Operating System)
leejbaxter
Member
Member
Posts: 25
Joined: Sat Jan 15, 2011 8:40 pm

Re: Device Driver Adaptation?

Post by leejbaxter »

There are actually 2 methods that I would be quite happy with implementing; either an adaptor (a sort of 'wrapper' or 'emulator' that runs a Windows/Linux driver 'as is'), or a converter (which would actually take the Windows/Linux driver and rewrite it into a form that suits CHAOS). I suppose a hybrid approach may also be a possible implementation.

Thanks to everyone who has offered suggestions so far! I must admit, this forum doesn't seem half as scary as it first seemed on the Wiki! 8)
Lee.J.Baxter - Designer of CHAOS (Cybernetic Hivemind Adaptive Operating System)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Device Driver Adaptation?

Post by Combuster »

leejbaxter wrote:This forum doesn't seem half as scary as it first seemed on the Wiki! 8)
We're still dangerous dinosaurs, but only for those who forgot to read the safety manual :wink:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Device Driver Adaptation?

Post by Solar »

Combuster wrote:
leejbaxter wrote:This forum doesn't seem half as scary as it first seemed on the Wiki! 8)
We're still dangerous dinosaurs, but only for those who forgot to read the safety manual :wink:
LOL...
How to handle an OSDever safely.

A manual written by H.R.H. Combuster and others from the Royal Household.

Chapter 1: How to approach a dinosaur.

Watch "Harry Potter and the Prisoner of Azkaban". Take special note of the hippogryph scene. Extrapolate.

Chapter 2: How to behave if you have a question

Always carry a bunch of dead rats to feed the hippogryph... erm, dinosaur.

Chapter 3: ...
Every good solution is obvious once you've found it.
Post Reply