Welcome, Guest. Please login or register.

Author Topic: How to write hardware drivers  (Read 3333 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Boot_WBTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2005
  • Posts: 1326
    • Show only replies by Boot_WB
    • http://www.hullchimneyservices.co.uk
How to write hardware drivers
« on: August 16, 2007, 11:53:52 PM »
I would like to learn to write device drivers for the Amiga, but I have no idea where to start.

Any suggestions?

A worked example, or tutorial would be useful. I've seen a few for linux, but am not sure how relevant they are to writing drivers under AmigaOS.

Aside from writing a small database program in C a couple of years ago and writing a few graph drawing programs in basic, my programming experience is fairly limited. I look forward to the giddy heights of "Hello World".

I have a specific device in mind (fairly simple, scsi i/o device), but as I'm crap at actually getting around to things I don't want to say "I am going to write a driver for ....", as it may well never happen.

Thanks
Mac Mini G4 (1.5GHz, 64MB VRam, 1GB Ram): MorphOS 3.6
Powerbook 5.8 (15", 1.67GHz, 128MB VRam, 1GB Ram): MorphOS 3.8.

Windows-free since 2011-2014 (Damn you Netflix!)
 

Offline mikrucio

  • Party Mix \'87
  • Sr. Member
  • ****
  • Join Date: Apr 2004
  • Posts: 375
    • Show only replies by mikrucio
Re: How to write hardware drivers
« Reply #1 on: August 17, 2007, 02:18:58 AM »
writing device drivers is a fairly daunting experience even for expert programmers. I don't recommend you start this.
without learning to program properly first. maybe 5 years plus experience in C. also knowing ASSEMBLY language is a good thing.

good luck
 

Offline murple

  • Hero Member
  • *****
  • Join Date: Jul 2007
  • Posts: 579
    • Show only replies by murple
    • http://www.murple.net
Re: How to write hardware drivers
« Reply #2 on: August 17, 2007, 02:38:32 AM »
A big challenge for many of these is getting the device manufacturer to give you specs on how to talk to the device. You'll also need to know something about programming for the bus its on (Zorro II for instance). Unless its a device similar enough to another device that you can just modify an existing driver, its probably going to be hard work without being a serious systems programmer.
 

Offline billt

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 910
    • Show only replies by billt
    • http://www.billtoner.net
Re: How to write hardware drivers
« Reply #3 on: August 17, 2007, 02:52:54 AM »
1. Learn to program. Assembly is good to know as part of this as well as C.
2. Get the hardware and devices RKMs if you can.
3. There's a few drivers on aminet and funet to get ideas from, see what the code looks like, etc.
4. Get the OS4 SDK, and some things may require additional seperate documentation for certain things such as the P96 API docs and kit.
5. Learn patience.
6. Find lots of time. It'll take a while to get a feel for things, and it may be a long time before there's any noticable things finally working. It may be very frustrating for a while. For example, it was a long time and a lot of work before Joshua got the first image to display on a Radeon. Would have come sooner if we'd had an AmigaOne, but we were workigin on Classic+Prometheus, and had to get the BIOS POST stuff working before we could really do any display work, when the AmigaOne Uboot x86 emulation would do most of that for us. Took a while to get the memory controller, PLL, and other things working enough to allow us to do other things, and the driver crashed the machine before we figured out the last few details of parsing the ROM. Is that crash caused by a bug in the "display driver" code, or is it because the memory controller configuration has a bit wrong somewhere and will crash no matter what you do in the display code? If the hardware was initted slightly wrong, that can be really hard to find and fix as you may not have a chance to peek registers before a crash and hardware reset to default or blank values. Be prepared to fumble with vague or blatantly wrong documentation if you have that, sometimes poorly commented Linux code (some of that has improved considerably with time though)
7. If you have lots of money, get a JTAG debug kit. Pretty darn expensive, but can be useful for tracking down weird stuff that may be very hard to track down with software debugging inside the OS4 environment. Won't be very common though due to the expense.

If you try to get docs from the chip companies, prepare to nag them for a while. Politely of course, but don't take initial lack of interest as a solid no, unless it's NVidia, they probably won't even call you back to say no. Even after you get your foot in the door, you may still have to nag. I'm waiting for NDA papers for something I was promised them for a month or two ago, I need to call and remind them but I keep forgetting until it's late and everything's closed. And try not to say "Amiga". Talk about writing drivers for an embedded OS or something like that and avoid naming names if you can. Considering some of Hyperions supposed plans, it's not an outright lie to generically talk of some nameless embedded platform...  :-D
Bill T
All Glory to the Hypnotoad!
 

Offline SamuraiCrow

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2281
  • Country: us
  • Gender: Male
    • Show only replies by SamuraiCrow
Re: How to write hardware drivers
« Reply #4 on: August 17, 2007, 04:46:18 AM »
@billt

He didn't say it was for AmigaOS version 4.  He might be developing for and on 3.x .
 

Offline billt

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 910
    • Show only replies by billt
    • http://www.billtoner.net
Re: How to write hardware drivers
« Reply #5 on: August 17, 2007, 01:31:39 PM »
Quote
He didn't say it was for AmigaOS version 4. He might be developing for and on 3.x .


s/OS4/OS3.x/g

Everything else is pretty much the same either way.
Bill T
All Glory to the Hypnotoad!
 

Offline azvareth

  • Newbie
  • *
  • Join Date: Feb 2007
  • Posts: 7
    • Show only replies by azvareth
    • http://n/a
Re: How to write hardware drivers
« Reply #6 on: September 06, 2007, 11:38:55 PM »
Hi!

My response may be out of this topic but:

Why not instead write a "wrapper" for Windows drivers (there are millions of them), Linux have done this for some "card to stick in the computer" "google:windows driver under linux", NDiswrapper also have released their source...

could such a wrapper be written for one kind of drivers why not all ?

the only problem then... is how to get the hardware in your Amiga

Azvareth
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: How to write hardware drivers
« Reply #7 on: September 07, 2007, 12:44:39 AM »
@azvareth
Quote
Why not instead write a "wrapper" for Windows drivers

Windows drivers are x86 code. The driver would need to run thru two levels of emulation: 1) x86 CPU 2) Windows API wrapper.

For drivers such as gfxcard, audio or input you'd also need DirectX/DirectAudio etc. Not very practical solution I'd say, and certainly very slow.

If this had been feasible solution it would have been done 10 years ago already.
 

Offline LoadWB

  • Hero Member
  • *****
  • Join Date: Jul 2006
  • Posts: 2901
  • Country: 00
    • Show only replies by LoadWB
Re: How to write hardware drivers
« Reply #8 on: September 07, 2007, 12:52:56 AM »
Quote
Piru wrote:

If this had been feasible solution it would have been done 10 years ago already.


Devil's advocate: would this be more feasible for AROS?
 

Offline azvareth

  • Newbie
  • *
  • Join Date: Feb 2007
  • Posts: 7
    • Show only replies by azvareth
    • http://n/a
Re: How to write hardware drivers
« Reply #9 on: September 07, 2007, 06:06:31 PM »
Piru::

Yes thats true, however there exists an emulator for "old?" pc's called syn68k (for an macemul engine), and what I read about it was that it "compiled" the source and created "precompiled" code (as far as it was possible) which was executed the next time the bin was executed.

No not Win API wrapper, from what I saw from NDiswrapper (but I could be wrong) did they implement (clone) [as I did understand it] parts from WinNT kernel, the source was available with the NDisWrapper and (if I am right) as a source it would be (I think) possible to compile it to native 680x0 code, or? -so yes the driver itself must be emulated, but perhaps "compiled" as much as possible. slower yes... with almost unlimited access to hardware?

Edit:
It is possible to use gfx and sfx hardware without DirectX on PC's however if you want to play a game or so, then you would need to install DirectX, however I don't belive that there exists a lot of software on the Amiga that uses DirectX.

LoadWB::

That is an good idea and perhaps more realistic then the idea above.


:: note all the statements above is only how I have understand what the authors say, it might not be true but I hope and think it is so.

Azvareth
 

Offline billt

  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 910
    • Show only replies by billt
    • http://www.billtoner.net
Re: How to write hardware drivers
« Reply #10 on: September 07, 2007, 06:27:20 PM »
Quote
Why not instead write a "wrapper" for Windows drivers (there are millions of them),


Better to do a wrapper to Linux drivers. At least many of those are open-source and can be compiled to 68K or PPC, and there's still lots more of those than for Amiga.
Bill T
All Glory to the Hypnotoad!