Page 1 of 2
Drivers! Main Problem for OS dev!
Posted: Tue Feb 01, 2005 12:00 am
by kan
hi,
Through my previous posts , i came to know, use of BIOS routines for communicating with hardware becomes very slow! So for interacting with hardware BIOS is of NO USE!
That means i have to write my own Drivers?
And since there are so many differents types of peripherals developed by soooooo manyyyyyy vendors , if i want to write drivers for all of them it will take me atleast a decade

And by the time i complete writing driver for one device other more advanced will come in market.
So isn't there any shortcut to this??
May be because there isn't any shortcut for this, Linux still has so many problems related to drivers!!
This may sound silly , but is there any way we can use existing drivers build for windows family?? Not the once provided by MS , but developed by other third parties for their specific hardware?
If this becomes possible i think , communicating with hardware will be a lot easier.
I know someone , somewhere must have thought abt this but still we don't see this thing happning means , there is some glitch in this!
Re: Drivers! Main Problem for OS dev!
Posted: Wed Feb 02, 2005 12:00 am
by Legend
The glitch is that you need to either
emulate (slow) a lot of windows or copy a lot of the design
of windows (which most won't do).
And things like Project UDI never really got that important.
Re: Drivers! Main Problem for OS dev!
Posted: Wed Feb 02, 2005 12:00 am
by Brendan
Hi,
kan wrote:I know someone , somewhere must have thought abt this but still we don't see this thing happning means , there is some glitch in this!
A large amount of hardware uses "generic interfaces".
For video there's the VGA standard and VBE 2 & 3, which is enough to get limited video support. With some code to set a default video mode during boot (using BIOS from real mode), a standard VGA driver and a generic VBE 3 driver you can get at least some support for all video cards.
For IDE/ATA/ATAPI/SATA controllers there's the legacy interface which works with all of them. The IDE/ATA/ATAPI devices are all standard.
Floppy drives and the floppy drive controller is standard - same on all computers with minor variations in the controller.
USB mouse, joystick, keyboard, etc all conform to a HID (Human Interface Device) standard, so a single driver can do all of them. For other USB devices a reasonable number of them use device specific interface standards (AFAIK all the common device types).
PS/2 keyboard & mouse are all standard. There's 3 different protocols for the mouse (standard, standard+scroll wheel, 5 button+scroll wheel), but its easy enough to handle this within the same driver. All keyboard code should use "keyboard mapping tables" which can be changed for internationalization - one table for US keyboards, one for French, one for German, etc but the same device driver for all of them.
Serial ports, parallel ports, CMOS/RTC, ISA DMA, PIT, PIC - all of these are standard and haven't really changed in the last 20 years.
Modems (for serial ports) all extend the "Hayes Command Set" with their own stuff. Supporting the generic commands is easy.
All printers will print standard ASCII with a minimal driver. Not sure if there's other standards for better support.
For sound cards, there's about 5 common digitized sound interfaces, 3 common MIDI interfaces and the game port is standard. Writing device drivers for all of these common interfaces will get about 60% of sound cards working enough.
For ethernet the NE2000 (or compatible) cards are common, so that's a good start. There's a few other common interfaces (e.g. RealTek). With about 4 drivers you can cover 60% of the networking cards (forget about token ring and other obsolete networking cards).
I think SCSI is all standardized (the devices are at least), but I haven't looked into SCSI controllers properly. To be honest I'm expecting trouble with SCSI controllers - there's a wide range of features (caching, RAID, etc).
Then there's buses. PCI, PCIMCIA and USB are all standard and can be scanned using common code. For USB there's actually 3 slightly different interfaces. For ISA there's the Plug&Play standard that was introduced far too late, but the number of computers with ISA cards that are too old for Plug&Play is very small, and getting smaller by the day. By the time your OS is ready you probably won't need ISA much at all.
With all of that, you'd need code to scan the buses plus about 40 device drivers. Once this is done you'd have at least generic support for most hardware and your OS will be usable on a large number of computers, Then you'll be looking at writing device specific drivers (and attracting volunteers to help).
IMHO at this stage it's best to have a well defined/documented interface between the OS and each device type, and an example driver for each device type.
Cheers,
Brendan
Re: Drivers! Main Problem for OS dev!
Posted: Thu Feb 03, 2005 12:00 am
by smiddy
Brendan wrote:A large amount of hardware uses "generic interfaces".
BIOS is a generic safe interface.
Performance means drivers have to be devloped. If they are done serially, then it would take forever. A parallel effort goes a long way in crunching the time numbers.
kan wrote:That means i have to write my own Drivers?
Yes and no. You can get a consortium together who would be willing to divide and concur the work you're needing accomplished. Or you could ask each vendor to write their own based on your design paradigm. But that would cost money...
Re: Drivers! Main Problem for OS dev!
Posted: Thu Feb 03, 2005 12:00 am
by Brendan
Hi,
smiddy wrote:Brendan wrote:A large amount of hardware uses "generic interfaces".
BIOS is a generic safe interface.
Performance means drivers have to be devloped.
Agreed - BIOS is designed for realmode single tasking, where OS's use 32 bit multi-tasking. This means the OS would need to serialize all BIOS use, which can have a far greater effect on performance than the hacks needed to make the real mode code work in a protected mode environment. An example would be copying data from hard drive to a floppy - the hardware can read from the hard drive and write to the floppy without using the CPU. Using the BIOS will consume 100% of CPU time just waiting for the floppy transfer to complete.
The BIOS should be completely avoided where possible. Exceptions to this would include APM and ACPI (and the protected mode interface for VBE 3). I wouldn't consider it a viable "generic interface" for anything else.
smiddy wrote:If they are done serially, then it would take forever. A parallel effort goes a long way in crunching the time numbers.
IMHO if 2 OS designs are close enough to allow a parallel device driver effort they should merge - common boot code, common kernel, common drivers (possibly with different file systems, GUIs, etc). Several projects with boot code and half a kernel isn't as good as a single working OS. The exception to this is projects done for educational purposes only.
In fact if I where running Microsoft I'd do everything I can to encourage people to start their own OS. If everyone is doing their own thing nothing will reach the stage where it actually works. Instead, if everyone worked together on the same project we could probably create a completely functional OS in 6 months. "Divide and conquor" if you see what I mean..
smiddy wrote:Or you could ask each vendor to write their own based on your design paradigm. But that would cost money...
Just a little money

. If you say $2000 (USD) per driver for 1000 drivers that's $2000000..
Cheers,
Brendan
Re: Drivers! Main Problem for OS dev!
Posted: Thu Feb 03, 2005 12:00 am
by [AlAdDiN]
I agree with brendan, almost all peripherals have a standard interface to do minimal things (or more) and that's enougth (IMO) to develop an OS, then if you have a good design you can easily import existing OpenSource drivers to your OS, from Linux, BSD, or other OS...
Re: Drivers! Main Problem for OS dev!
Posted: Mon Mar 14, 2005 12:00 am
by frizzz
AlAdDin is really an optimist...
In fact, it is very complicated, to port C-written drivers to an own OS, written in asm! I tried to port the floppy-driver to my own assembler OS, but gave up and searched for controller-data-sheets. I wrote a driver new from scratch. And after that work was successfully done, I could understand at least the elementary parts of the linux-driver. I found, that those cracks didn't know the write-deleted-data command, but set the skip-deleted-sector-bit ! Besides that, the most of the linux-driver depends on the UNIX-C-bureaucracy.
But You do not need every driver for every device! - Brendan is right. You will need apart from elementary things for keyboard, interrupts a.s.o.
drivers for FD,IDE,video,USB...a dozen, which could be better written using datasheets of controllers.
I started in that direction and published my own OS now. Look at my homepage:
www.rcfriz.de
Maybe,You want to cooperate - then contact me at:
[email protected]
Re: Drivers! Main Problem for OS dev!
Posted: Tue Mar 15, 2005 12:00 am
by [AlAdDiN]
I'm not an optimist but this is only my opinion ....
i'm not speakiing about porting asm drivers cause asm code is almost not reusable ...
and personally I allready ported floppy ata, vbe3, fat32, ext2 ... drivers to my OS from other projects and from OSkit library, whitout major modifications ....
again, If you have a *GOOD* design, you can easily port drivers to your OS, if your OS *NOT* in asm, coz asm is no more used to develop entire OSes, it is used to write some arch d?pendent code, and this represent less than 10% of the OS .
Re: Drivers! Main Problem for OS dev!
Posted: Tue Mar 15, 2005 12:00 am
by frizzz
I do not agree, that asm-code is hard to port...
As Brendan is right, that there are a lot of standardized device interfaces - the assemblercode to deal with that doesn't differ too much! You will have the same I/O-adresses, the same command-sets, the same error-codes, the same routines for ever. Differences are reasoned by the method to interface to the drivers (i.e.parameters in registers or an stack or in file or in memory).
Thus the discussion has to focus those methods, if You want to decide, which way would be the shorter one.
My opinion is, that *GOOD* design is NOT a sort of UNIX-design, which is needed, if You code in C/C++. The only advantage of doing this is, that You can find a lot of already done code (You mentioned this).
The question was here: Do You need Your whole lifetime, if You want to write the entire OS new from scratch.
There is to say, that You need to code in every language the same amount of commands. Only some letters could be omitted - i.e. "}" instead of "retf". But if You use a "higher" language, You will need a lot of names too to make the needed "arch dependend" code usable. If You code in assembler, this bureaucracy is omitted!
The conclusion is: C-programmers need more time to write their program - and they need more than one language (precompiler, linker...) to learn. And they need to read MBytes of documentation...
Besides that, there are things, You can't do in "higher" languages: mainly indexed adressing. Because of that You need a lot of case-selections, when indexed jumping could do the same job in some machine-cycles...
(You will find a lot of examples in my OS)
That's why I intend to write the entire OS in assembler. And I am an optimist!
Re: Drivers! Main Problem for OS dev!
Posted: Wed Mar 16, 2005 12:00 am
by Legend
Well ...
a) For porting a driver to your os, having the same things on the hardware side is the minor thing that would help. The major issue is exactly the interfacing, that you say is less important! After all, if I need to throw away the whole interface, I can rewrite the driver myself, instead of messing around with source code.
b) You don't need a unix-like design when coding with C/C++. You are mostly even free not to provide a ISO99 -C compliant C lib, but that isn't a good idea, and ISO99 doesn't imply much unix, POSIX would hurt far more.
c) I can code with much less lines in C then with ASM, already a bit more complex math becomes a long set of instructions in ASM.
d) Most of that bureaucracy is because we want the same interface for several drivers for devices of the same class (network, graphics, sound, etc.).
If you throw that "bureaucracy" away with throwing virtualisation away, you achieve close to nothing anyway.
Conclusion: Perhaps C programmers might then need more time, but they achieve far more when the comparision is like you say.
You can do good, reuseable code in asm with some care.
Index selections, hmm, I heard that some versions gcc (or with the right compile time flag) use an array of addresses when you do switch ... case.
And I use an array of function pointers in my jvm, however, I will want to get rid of the function call involved every time.
Re: Drivers! Main Problem for OS dev!
Posted: Wed Mar 16, 2005 12:00 am
by [AlAdDiN]
@frizzz : I allready developped an OS in asm (a realmod DOS like OS), it is almost fully functionnal, but when i stoped coding for 3 months and want to re read my code, it was very hard for me to understand what i did (and the code was very well commented) .
on the other hand, i started developping the pmod verion of my OS 3 years ago, i stoped coding during 8 months, and when i restarted, there was no problem for me to understand my code .
Also, my goal is not to develop an OS for myself, I want to give a free source code whitch can be reused for any purpose, and most of developpers don't like to see lot of asm code, I'm also a fan od asm coding, I already wrote lot of programs, games ...etc using asm, but for an OS project i thing a high level language is needed to make it easy to maintain in the future.
Re: Drivers! Main Problem for OS dev!
Posted: Wed Mar 16, 2005 12:00 am
by bubach
For assembly programmers C-code can be just as hard to read as asm-code for the C-programmer.
It's all about how you think/visualize.
I have never had a problem reading my own asm code, months after i wrote it...
Re: Drivers! Main Problem for OS dev!
Posted: Sat Mar 19, 2005 12:00 am
by carbonBased
Perhaps... but if you take a person that's reasonably proficient in both C and ASM, I'm sure they'd find C easier to read.
And by C, I mean well written C. We all know it's easy to make rediculously unreadable code in C. This is not what I'm talking about... a reasonably proficient programmer would not do this.
I can't imagine someone saying that seeing a simple equation (one they would've understood in highschool):
x = sqrt( (y*2) + (5*z) );
Is going to be harder to read then the assembly language equivalent?
--Jeff
Re: Drivers! Main Problem for OS dev!
Posted: Tue Mar 22, 2005 12:00 am
by frizzz
Legend told us, that in GNU-C/C++ there are pointers of labels available - he is right. You can code:
*pointer=&label // the adress of a label is the value, stored in *pointer
But I tried every possibility to code like this:
goto *pointer // jump to the adress of label, stored in *pointer
The compiler refuses compilation. And You can't goto a label outside {.}!
Using assembler, You can not only easily make arithmetic on adresses, You can do it in one command-cycle:
mov eax,[es:eax+ebx*4+displacement]
In assembler, You can store adresses of adresses in a table and refer to those with indeces in two registers:
lgs edx,[es:eax+ebx*4+displacement] ; load a FAR-pointer of a label
jmp [gs:edx+edi+displacement] ; adress with the FAR-pointer the adress of the label to jump to.
Up to 5 indices computed during runtime in 2 command-cycles! Impossible to code an aequivalent in C/C++.
Again: A C-programmer needs to code at least the same amount of commands.
But I agree, that some letters are wasted, if You code in assembler, especially if You want to do arithmetic on values, which are not adresses.
But I made the experiance, that You need less time to write than to think. Thus efficiency counts and not the amount of letters You need to get it.
I hope I posted some real evident arguments in this religious war, going on for 30 years now and caused by some people, who wanted to make big money with their compilers (once sold for up to 10000.-$)...
Re: Drivers! Main Problem for OS dev!
Posted: Tue Mar 22, 2005 12:00 am
by Legend
Ugh, always writing that lengthy, cryptic line is an argument for compilers (or something like #define in C at least)
But for interfunctional goto the best that I can think about in C at the moment is setjmp/longjmp - not really flexible and involves a function call each time.
But how do you return from such a jmp?
The features of any high level language only kick in at complex situations - for loops involving function calls everytime, long switch statements, far more variables then registers.
They are not mostly about saving commands (although a for loop mostly does take up at least some less lines, and don't forget not to mess around with the stack yourself on a function). They are about implementing those much more readable, management, the framework ... and not to forget: portability, especially with Java and C#.
ASM is for the speed-critical inner loop, today.