[Haskell-cafe] Linux device drivers

Donald Bruce Stewart dons at cse.unsw.edu.au
Sun Mar 20 20:28:18 EST 2005

> I was wondering about the possibility of using Haskell for developing
> device drivers that would be kernel modules for Linux. If nothing else,
> it would be quite an educational experience for me, as I've not yet
> experimented with either the Linux kernel or Haskell FFI, nor have I
> had to learn how to squeeze much performance out of my Haskell code.
> Clearly, this application demands special things from the compiler and
> the runtime. But, I'm not exactly sure what, nor how to achieve such
> given current compilers. Does anyone have any thoughts?

Well, it would be tricky, but fun!

We've got a few drivers written in Haskell already (but not for Linux,
as far as I know). For example check out the House network stack and

So there's heavy use of Data.Bits and Word# types - but nothing that
isn't fairly well established in GHC Haskell, anyway.
Then (for GHC, anyway) you'd have to link the kernel against libHSrts.a, much
as we do when calling Haskell from other kinds of C apps, which involves
compiling the C app with all the magic flags ghc normally sets up (ghc -v9
main.c is helpful).  Something like: ;)

egcc -v -o a.out -DDONT_WANT_WIN32_DLL_SUPPORT main.o -L/home/dons/lib/ghc-6.4 -lHStemplate-haskell -lHSCabal -lHSposix -lHSposix_cbits -lHSlang -lHSmtl -lHShaskell-src -lHSunix -lHSunix_cbits -lHShi -lHShaskell98 -lHSaltdata -lHSbase -lHSbase_cbits -lHSrts -lm -lgmp -u GHCziBase_Izh_static_info -u GHCziBase_Czh_static_info -u GHCziFloat_Fzh_static_info ...

Then, having the kernel start up the Haskell rts (at boot would be
      hs_init(&argc, &argv);
        .. do something in Haskell or C land ...

Then you'd could dyn load (via GHC's rts) your Haskell driver into the C
app, and use it, as long as you've got a nice ffi interface to pass
values back and forward.

I'm sure the fun part is in the details ;)

More information about the Haskell-Cafe mailing list